tests: test pretty JSON, with and without plain JSON
authorAlexis Laferrière <alexis.laf@xymus.net>
Fri, 22 Apr 2016 13:04:53 +0000 (09:04 -0400)
committerAlexis Laferrière <alexis.laf@xymus.net>
Fri, 22 Apr 2016 19:36:14 +0000 (15:36 -0400)
Signed-off-by: Alexis Laferrière <alexis.laf@xymus.net>

tests/sav/nitce/test_json_deserialization_alt3.res [new file with mode: 0644]
tests/sav/test_json_deserialization_alt3.res [new file with mode: 0644]
tests/sav/test_json_deserialization_alt4.res [new file with mode: 0644]
tests/test_json_deserialization.nit

diff --git a/tests/sav/nitce/test_json_deserialization_alt3.res b/tests/sav/nitce/test_json_deserialization_alt3.res
new file mode 100644 (file)
index 0000000..b269caf
--- /dev/null
@@ -0,0 +1,192 @@
+# Nit:
+<A: true a 0.123 1234 asdf false p4ssw0rd>
+
+# Json:
+{
+       "__kind": "obj", "__id": 0, "__class": "A",
+       "b": true,
+       "c": {"__kind": "char", "__val": "a"},
+       "f": 0.123,
+       "i": 1234,
+       "serialization_specific_name": "asdf",
+       "n": null
+}
+
+# Back in Nit:
+<A: true a 0.123 1234 asdf false p4ssw0rd>
+
+# Nit:
+<B: <A: false b 123.123 2345 hjkl true p4ssw0rd> 1111 qwer>
+
+# Json:
+{
+       "__kind": "obj", "__id": 0, "__class": "B",
+       "b": false,
+       "c": {"__kind": "char", "__val": "b"},
+       "f": 123.123,
+       "i": 2345,
+       "serialization_specific_name": "hjkl",
+       "n": 12,
+       "ii": 1111,
+       "ss": "qwer"
+}
+
+# Back in Nit:
+<B: <A: false b 123.123 2345 hjkl true p4ssw0rd> 1111 qwer>
+
+# Nit:
+<C: <A: true a 0.123 1234 asdf false p4ssw0rd> <B: <A: false b 123.123 2345 hjkl true p4ssw0rd> 1111 qwer>>
+
+# Json:
+{
+       "__kind": "obj", "__id": 0, "__class": "C",
+       "a": {
+               "__kind": "obj", "__id": 1, "__class": "A",
+               "b": true,
+               "c": {"__kind": "char", "__val": "a"},
+               "f": 0.123,
+               "i": 1234,
+               "serialization_specific_name": "asdf",
+               "n": null
+       },
+       "b": {
+               "__kind": "obj", "__id": 2, "__class": "B",
+               "b": false,
+               "c": {"__kind": "char", "__val": "b"},
+               "f": 123.123,
+               "i": 2345,
+               "serialization_specific_name": "hjkl",
+               "n": 12,
+               "ii": 1111,
+               "ss": "qwer"
+       },
+       "aa": {
+               "__kind": "ref", "__id": 1
+       }
+}
+
+# Back in Nit:
+<C: <A: true a 0.123 1234 asdf false p4ssw0rd> <B: <A: false b 123.123 2345 hjkl true p4ssw0rd> 1111 qwer>>
+
+# Nit:
+<D: <B: <A: false b 123.123 2345 new line ->
+<- false p4ssw0rd> 1111        f"\r\/> true>
+
+# Json:
+{
+       "__kind": "obj", "__id": 0, "__class": "D",
+       "b": false,
+       "c": {"__kind": "char", "__val": "b"},
+       "f": 123.123,
+       "i": 2345,
+       "serialization_specific_name": "new line ->\n<-",
+       "n": null,
+       "ii": 1111,
+       "ss": "\tf\"\r\\/",
+       "d": {
+               "__kind": "ref", "__id": 0
+       }
+}
+
+# Back in Nit:
+<D: <B: <A: false b 123.123 2345 new line ->
+<- false p4ssw0rd> 1111        f"\r\/> true>
+
+# Nit:
+<E: a: hello, 1234, 123.4; b: hella, 2345, 234.5>
+
+# Json:
+{
+       "__kind": "obj", "__id": 0, "__class": "E",
+       "a": {
+               "__kind": "obj", "__id": 1, "__class": "Array",
+               "__items": [
+                       "hello",
+                       1234,
+                       123.4
+               ]
+       },
+       "b": {
+               "__kind": "obj", "__id": 2, "__class": "Array",
+               "__items": [
+                       "hella",
+                       2345,
+                       234.5
+               ]
+       }
+}
+
+# Back in Nit:
+<E: a: hello, 1234, 123.4; b: hella, 2345, 234.5>
+
+# Nit:
+<E: 2222>
+
+# Json:
+{
+       "__kind": "obj", "__id": 0, "__class": "F",
+       "n": 2222
+}
+
+# Back in Nit:
+null
+
+# Nit:
+<E: 33.33>
+
+# Json:
+{
+       "__kind": "obj", "__id": 0, "__class": "F",
+       "n": 33.33
+}
+
+# Back in Nit:
+null
+
+# Nit:
+<G: hs: -1, 0; s: one, two; hm: one. 1, two. 2; am: three. 3, four. 4>
+
+# Json:
+{
+       "__kind": "obj", "__id": 0, "__class": "G",
+       "hs": {
+               "__kind": "obj", "__id": 1, "__class": "HashSet",
+               "__items": [
+                       -1,
+                       0
+               ]
+       },
+       "s": {
+               "__kind": "obj", "__id": 2, "__class": "ArraySet",
+               "__items": [
+                       "one",
+                       "two"
+               ]
+       },
+       "hm": {
+               "__kind": "obj", "__id": 3, "__class": "HashMap", "__length": 2,
+               "__keys": [
+                       "one",
+                       "two"
+               ],
+               "__values": [
+                       1,
+                       2
+               ]
+       },
+       "am": {
+               "__kind": "obj", "__id": 4, "__class": "ArrayMap", "__length": 2,
+               "__keys": [
+                       "three",
+                       "four"
+               ],
+               "__values": [
+                       "3",
+                       "4"
+               ]
+       }
+}
+
+# Back in Nit:
+<G: hs: ; s: ; hm: ; am: >
+
diff --git a/tests/sav/test_json_deserialization_alt3.res b/tests/sav/test_json_deserialization_alt3.res
new file mode 100644 (file)
index 0000000..c49a52a
--- /dev/null
@@ -0,0 +1,192 @@
+# Nit:
+<A: true a 0.123 1234 asdf false p4ssw0rd>
+
+# Json:
+{
+       "__kind": "obj", "__id": 0, "__class": "A",
+       "b": true,
+       "c": {"__kind": "char", "__val": "a"},
+       "f": 0.123,
+       "i": 1234,
+       "serialization_specific_name": "asdf",
+       "n": null
+}
+
+# Back in Nit:
+<A: true a 0.123 1234 asdf false p4ssw0rd>
+
+# Nit:
+<B: <A: false b 123.123 2345 hjkl true p4ssw0rd> 1111 qwer>
+
+# Json:
+{
+       "__kind": "obj", "__id": 0, "__class": "B",
+       "b": false,
+       "c": {"__kind": "char", "__val": "b"},
+       "f": 123.123,
+       "i": 2345,
+       "serialization_specific_name": "hjkl",
+       "n": 12,
+       "ii": 1111,
+       "ss": "qwer"
+}
+
+# Back in Nit:
+<B: <A: false b 123.123 2345 hjkl true p4ssw0rd> 1111 qwer>
+
+# Nit:
+<C: <A: true a 0.123 1234 asdf false p4ssw0rd> <B: <A: false b 123.123 2345 hjkl true p4ssw0rd> 1111 qwer>>
+
+# Json:
+{
+       "__kind": "obj", "__id": 0, "__class": "C",
+       "a": {
+               "__kind": "obj", "__id": 1, "__class": "A",
+               "b": true,
+               "c": {"__kind": "char", "__val": "a"},
+               "f": 0.123,
+               "i": 1234,
+               "serialization_specific_name": "asdf",
+               "n": null
+       },
+       "b": {
+               "__kind": "obj", "__id": 2, "__class": "B",
+               "b": false,
+               "c": {"__kind": "char", "__val": "b"},
+               "f": 123.123,
+               "i": 2345,
+               "serialization_specific_name": "hjkl",
+               "n": 12,
+               "ii": 1111,
+               "ss": "qwer"
+       },
+       "aa": {
+               "__kind": "ref", "__id": 1
+       }
+}
+
+# Back in Nit:
+<C: <A: true a 0.123 1234 asdf false p4ssw0rd> <B: <A: false b 123.123 2345 hjkl true p4ssw0rd> 1111 qwer>>
+
+# Nit:
+<D: <B: <A: false b 123.123 2345 new line ->
+<- false p4ssw0rd> 1111        f"\r\/> true>
+
+# Json:
+{
+       "__kind": "obj", "__id": 0, "__class": "D",
+       "b": false,
+       "c": {"__kind": "char", "__val": "b"},
+       "f": 123.123,
+       "i": 2345,
+       "serialization_specific_name": "new line ->\n<-",
+       "n": null,
+       "ii": 1111,
+       "ss": "\tf\"\r\\/",
+       "d": {
+               "__kind": "ref", "__id": 0
+       }
+}
+
+# Back in Nit:
+<D: <B: <A: false b 123.123 2345 new line ->
+<- false p4ssw0rd> 1111        f"\r\/> true>
+
+# Nit:
+<E: a: hello, 1234, 123.4; b: hella, 2345, 234.5>
+
+# Json:
+{
+       "__kind": "obj", "__id": 0, "__class": "E",
+       "a": {
+               "__kind": "obj", "__id": 1, "__class": "Array[Object]",
+               "__items": [
+                       "hello",
+                       1234,
+                       123.4
+               ]
+       },
+       "b": {
+               "__kind": "obj", "__id": 2, "__class": "Array[nullable Serializable]",
+               "__items": [
+                       "hella",
+                       2345,
+                       234.5
+               ]
+       }
+}
+
+# Back in Nit:
+<E: a: hello, 1234, 123.4; b: hella, 2345, 234.5>
+
+# Nit:
+<E: 2222>
+
+# Json:
+{
+       "__kind": "obj", "__id": 0, "__class": "F[Int]",
+       "n": 2222
+}
+
+# Back in Nit:
+null
+
+# Nit:
+<E: 33.33>
+
+# Json:
+{
+       "__kind": "obj", "__id": 0, "__class": "F[Float]",
+       "n": 33.33
+}
+
+# Back in Nit:
+null
+
+# Nit:
+<G: hs: -1, 0; s: one, two; hm: one. 1, two. 2; am: three. 3, four. 4>
+
+# Json:
+{
+       "__kind": "obj", "__id": 0, "__class": "G",
+       "hs": {
+               "__kind": "obj", "__id": 1, "__class": "HashSet[Int]",
+               "__items": [
+                       -1,
+                       0
+               ]
+       },
+       "s": {
+               "__kind": "obj", "__id": 2, "__class": "ArraySet[String]",
+               "__items": [
+                       "one",
+                       "two"
+               ]
+       },
+       "hm": {
+               "__kind": "obj", "__id": 3, "__class": "HashMap[String, Int]", "__length": 2,
+               "__keys": [
+                       "one",
+                       "two"
+               ],
+               "__values": [
+                       1,
+                       2
+               ]
+       },
+       "am": {
+               "__kind": "obj", "__id": 4, "__class": "ArrayMap[String, String]", "__length": 2,
+               "__keys": [
+                       "three",
+                       "four"
+               ],
+               "__values": [
+                       "3",
+                       "4"
+               ]
+       }
+}
+
+# Back in Nit:
+<G: hs: ; s: ; hm: ; am: >
+
diff --git a/tests/sav/test_json_deserialization_alt4.res b/tests/sav/test_json_deserialization_alt4.res
new file mode 100644 (file)
index 0000000..5527174
--- /dev/null
@@ -0,0 +1,135 @@
+# Nit:
+<A: true a 0.123 1234 asdf false p4ssw0rd>
+
+# Json:
+{
+       "b": true,
+       "c": "a",
+       "f": 0.123,
+       "i": 1234,
+       "serialization_specific_name": "asdf",
+       "n": null
+}
+
+# Nit:
+<B: <A: false b 123.123 2345 hjkl true p4ssw0rd> 1111 qwer>
+
+# Json:
+{
+       "b": false,
+       "c": "b",
+       "f": 123.123,
+       "i": 2345,
+       "serialization_specific_name": "hjkl",
+       "n": 12,
+       "ii": 1111,
+       "ss": "qwer"
+}
+
+# Nit:
+<C: <A: true a 0.123 1234 asdf false p4ssw0rd> <B: <A: false b 123.123 2345 hjkl true p4ssw0rd> 1111 qwer>>
+
+# Json:
+{
+       "a": {
+               "b": true,
+               "c": "a",
+               "f": 0.123,
+               "i": 1234,
+               "serialization_specific_name": "asdf",
+               "n": null
+       },
+       "b": {
+               "b": false,
+               "c": "b",
+               "f": 123.123,
+               "i": 2345,
+               "serialization_specific_name": "hjkl",
+               "n": 12,
+               "ii": 1111,
+               "ss": "qwer"
+       },
+       "aa": {
+               "b": true,
+               "c": "a",
+               "f": 0.123,
+               "i": 1234,
+               "serialization_specific_name": "asdf",
+               "n": null
+       }
+}
+
+Serialization warning: Cycle detected in serialized object, replacing reference with 'null'.
+# Nit:
+<D: <B: <A: false b 123.123 2345 new line ->
+<- false p4ssw0rd> 1111        f"\r\/> true>
+
+# Json:
+{
+       "b": false,
+       "c": "b",
+       "f": 123.123,
+       "i": 2345,
+       "serialization_specific_name": "new line ->\n<-",
+       "n": null,
+       "ii": 1111,
+       "ss": "\tf\"\r\\/",
+       "d": null
+}
+
+# Nit:
+<E: a: hello, 1234, 123.4; b: hella, 2345, 234.5>
+
+# Json:
+{
+       "a": [
+               "hello",
+               1234,
+               123.4
+       ],
+       "b": [
+               "hella",
+               2345,
+               234.5
+       ]
+}
+
+# Nit:
+<E: 2222>
+
+# Json:
+{
+       "n": 2222
+}
+
+# Nit:
+<E: 33.33>
+
+# Json:
+{
+       "n": 33.33
+}
+
+# Nit:
+<G: hs: -1, 0; s: one, two; hm: one. 1, two. 2; am: three. 3, four. 4>
+
+# Json:
+{
+       "hs": [
+               -1,
+               0
+       ],
+       "s": [
+               "one",
+               "two"
+       ],
+       "hm": {
+               "one": 1,
+               "two": 2
+       },
+       "am": {
+               "three": "3",
+               "four": "4"
+       }
+}
+
index 8baadb1..155a39c 100644 (file)
@@ -18,20 +18,25 @@ import json::serialization
 
 var entities = new TestEntities
 
-var tests = entities.without_generics#alt1##alt2#
+var tests = entities.without_generics#alt1##alt2##alt3##alt4#
 #alt1#var tests = entities.with_generics
 #alt2#var tests = entities.with_generics
+#alt3#var tests = entities.with_generics
+#alt4#var tests = entities.with_generics
 
 for o in tests do
        var stream = new StringWriter
        var serializer = new JsonSerializer(stream)
        #alt2#serializer.plain_json = true
+       #alt3#serializer.pretty_json = true
+       #alt4#serializer.plain_json = true
+       #alt4#serializer.pretty_json = true
        serializer.serialize(o)
 
-       var deserializer = new JsonDeserializer(stream.to_s)#alt2#
-       var deserialized = deserializer.deserialize#alt2#
+       var deserializer = new JsonDeserializer(stream.to_s)#alt2##alt4#
+       var deserialized = deserializer.deserialize#alt2##alt4#
 
        print "# Nit:\n{o}\n"
        print "# Json:\n{stream}\n"
-       print "# Back in Nit:\n{deserialized or else "null"}\n"#alt2#
+       print "# Back in Nit:\n{deserialized or else "null"}\n"#alt2##alt4#
 end