json: test deser. from plain JSON and fix typo
authorAlexis Laferrière <alexis.laf@xymus.net>
Thu, 27 Jul 2017 16:03:58 +0000 (12:03 -0400)
committerAlexis Laferrière <alexis.laf@xymus.net>
Thu, 31 Aug 2017 17:23:57 +0000 (13:23 -0400)
Signed-off-by: Alexis Laferrière <alexis.laf@xymus.net>

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

index d757542..3cb2062 100644 (file)
@@ -50,7 +50,7 @@ Deserialization Error: Wrong type on `E::a` expected `Array[Object]`, got `null`
 Deserialization Error: Doesn't know how to deserialize class "Array"
 Deserialization Error: Wrong type on `E::b` expected `Array[nullable Serializable]`, got `null`
 # Nit:
-<E: 2222>
+<F: 2222>
 
 # Json:
 {"__kind": "obj", "__id": 0, "__class": "F","n":2222}
@@ -60,7 +60,7 @@ null
 
 Deserialization Error: Doesn't know how to deserialize class "F"
 # Nit:
-<E: 33.33>
+<F: 33.33>
 
 # Json:
 {"__kind": "obj", "__id": 0, "__class": "F","n":33.33}
diff --git a/tests/sav/nitce/test_json_deserialization_alt2.res b/tests/sav/nitce/test_json_deserialization_alt2.res
new file mode 100644 (file)
index 0000000..6b18cdb
--- /dev/null
@@ -0,0 +1,79 @@
+# 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}
+
+# 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:
+{"b":false,"c":"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:
+{"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}}
+
+# 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>>
+
+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}
+
+# Back in Nit:
+<D: <B: <A: false b 123.123 2345 new line ->
+<- false p4ssw0rd> 1111        f"\r\/> false>
+
+# Nit:
+<E: a: hello, 1234, 123.4; b: hella, 2345, 234.5>
+
+# Json:
+{"a":["hello",1234,123.4],"b":["hella",2345,234.5]}
+
+# Back in Nit:
+<E: a: hello, 1234, 123.4; b: hella, 2345, 234.5>
+
+# Nit:
+<F: 2222>
+
+# Json:
+{"n":2222}
+
+# Back in Nit:
+null
+
+Deserialization Error: Doesn't know how to deserialize class "F"
+# Nit:
+<F: 33.33>
+
+# Json:
+{"n":33.33}
+
+# Back in Nit:
+null
+
+Deserialization Error: Doesn't know how to deserialize class "F"
+# 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"}}
+
+# Back in Nit:
+<G: hs: -1, 0; s: ; hm: one. 1, two. 2; am: three. 3, four. 4>
+
+Deserialization Error: Doesn't know how to deserialize class "Set[String]"
+Deserialization Error: Wrong type on `G::s` expected `Set[String]`, got `null`
index a623837..82371a6 100644 (file)
@@ -116,7 +116,7 @@ Deserialization Error: Wrong type on `E::a` expected `Array[Object]`, got `null`
 Deserialization Error: Doesn't know how to deserialize class "Array"
 Deserialization Error: Wrong type on `E::b` expected `Array[nullable Serializable]`, got `null`
 # Nit:
-<E: 2222>
+<F: 2222>
 
 # Json:
 {
@@ -129,7 +129,7 @@ null
 
 Deserialization Error: Doesn't know how to deserialize class "F"
 # Nit:
-<E: 33.33>
+<F: 33.33>
 
 # Json:
 {
diff --git a/tests/sav/nitce/test_json_deserialization_alt4.res b/tests/sav/nitce/test_json_deserialization_alt4.res
new file mode 100644 (file)
index 0000000..1546862
--- /dev/null
@@ -0,0 +1,150 @@
+# 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
+}
+
+# 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:
+{
+       "b": false,
+       "c": "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:
+{
+       "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
+       }
+}
+
+# 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>>
+
+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
+}
+
+# Back in Nit:
+<D: <B: <A: false b 123.123 2345 new line ->
+<- false p4ssw0rd> 1111        f"\r\/> false>
+
+# Nit:
+<E: a: hello, 1234, 123.4; b: hella, 2345, 234.5>
+
+# Json:
+{
+       "a": ["hello", 1234, 123.4],
+       "b": ["hella", 2345, 234.5]
+}
+
+# Back in Nit:
+<E: a: hello, 1234, 123.4; b: hella, 2345, 234.5>
+
+# Nit:
+<F: 2222>
+
+# Json:
+{
+       "n": 2222
+}
+
+# Back in Nit:
+null
+
+Deserialization Error: Doesn't know how to deserialize class "F"
+# Nit:
+<F: 33.33>
+
+# Json:
+{
+       "n": 33.33
+}
+
+# Back in Nit:
+null
+
+Deserialization Error: Doesn't know how to deserialize class "F"
+# 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"
+       }
+}
+
+# Back in Nit:
+<G: hs: -1, 0; s: ; hm: one. 1, two. 2; am: three. 3, four. 4>
+
+Deserialization Error: Doesn't know how to deserialize class "Set[String]"
+Deserialization Error: Wrong type on `G::s` expected `Set[String]`, got `null`
index 4157c19..46a95ec 100644 (file)
 <E: a: hello, 1234, 123.4; b: hella, 2345, 234.5>
 
 # Src:
-<E: 2222>
+<F: 2222>
 # Dst:
-<E: 2222>
+<F: 2222>
 
 # Src:
-<E: 33.33>
+<F: 33.33>
 # Dst:
-<E: 33.33>
+<F: 33.33>
 
 # Src:
 <G: hs: -1, 0; s: one, two; hm: one. 1, two. 2; am: three. 3, four. 4>
index 91b7df1..0b26d28 100644 (file)
 <E: a: hello, 1234, 123.4; b: hella, 2345, 234.5>
 
 # Nit:
-<E: 2222>
+<F: 2222>
 
 # Json:
 {"__kind": "obj", "__id": 0, "__class": "F[Int]","n":2222}
 
 # Back in Nit:
-<E: 2222>
+<F: 2222>
 
 # Nit:
-<E: 33.33>
+<F: 33.33>
 
 # Json:
 {"__kind": "obj", "__id": 0, "__class": "F[Float]","n":33.33}
 
 # Back in Nit:
-<E: 33.33>
+<F: 33.33>
 
 # Nit:
 <G: hs: -1, 0; s: one, two; hm: one. 1, two. 2; am: three. 3, four. 4>
index f7aaf31..896b094 100644 (file)
@@ -4,18 +4,27 @@
 # Json:
 {"b":true,"c":"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:
 {"b":false,"c":"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:
 {"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}}
 
+# 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>>
+
 Serialization warning: Cycle detected in serialized object, replacing reference with 'null'.
 # Nit:
 <D: <B: <A: false b 123.123 2345 new line ->
@@ -24,27 +33,45 @@ Serialization warning: Cycle detected in serialized object, replacing reference
 # 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}
 
+# Back in Nit:
+<D: <B: <A: false b 123.123 2345 new line ->
+<- false p4ssw0rd> 1111        f"\r\/> false>
+
 # Nit:
 <E: a: hello, 1234, 123.4; b: hella, 2345, 234.5>
 
 # Json:
 {"a":["hello",1234,123.4],"b":["hella",2345,234.5]}
 
+# Back in Nit:
+<E: a: hello, 1234, 123.4; b: hella, 2345, 234.5>
+
 # Nit:
-<E: 2222>
+<F: 2222>
 
 # Json:
 {"n":2222}
 
+# Back in Nit:
+<F: 2222>
+
 # Nit:
-<E: 33.33>
+<F: 33.33>
 
 # Json:
 {"n":33.33}
 
+# Back in Nit:
+<F: 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"}}
 
+# Back in Nit:
+<G: hs: -1, 0; s: ; hm: one. 1, two. 2; am: three. 3, four. 4>
+
+Deserialization Error: Doesn't know how to deserialize class "Set[String]"
+Deserialization Error: Wrong type on `G::s` expected `Set[String]`, got `null`
index d58b2de..ccfb302 100644 (file)
 <E: a: hello, 1234, 123.4; b: hella, 2345, 234.5>
 
 # Nit:
-<E: 2222>
+<F: 2222>
 
 # Json:
 {
 }
 
 # Back in Nit:
-<E: 2222>
+<F: 2222>
 
 # Nit:
-<E: 33.33>
+<F: 33.33>
 
 # Json:
 {
 }
 
 # Back in Nit:
-<E: 33.33>
+<F: 33.33>
 
 # Nit:
 <G: hs: -1, 0; s: one, two; hm: one. 1, two. 2; am: three. 3, four. 4>
index 3c56592..ceaeca5 100644 (file)
@@ -11,6 +11,9 @@
        "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>
 
@@ -26,6 +29,9 @@
        "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>>
 
@@ -59,6 +65,9 @@
        }
 }
 
+# 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>>
+
 Serialization warning: Cycle detected in serialized object, replacing reference with 'null'.
 # Nit:
 <D: <B: <A: false b 123.123 2345 new line ->
@@ -77,6 +86,10 @@ Serialization warning: Cycle detected in serialized object, replacing reference
        "d": null
 }
 
+# Back in Nit:
+<D: <B: <A: false b 123.123 2345 new line ->
+<- false p4ssw0rd> 1111        f"\r\/> false>
+
 # Nit:
 <E: a: hello, 1234, 123.4; b: hella, 2345, 234.5>
 
@@ -86,22 +99,31 @@ Serialization warning: Cycle detected in serialized object, replacing reference
        "b": ["hella", 2345, 234.5]
 }
 
+# Back in Nit:
+<E: a: hello, 1234, 123.4; b: hella, 2345, 234.5>
+
 # Nit:
-<E: 2222>
+<F: 2222>
 
 # Json:
 {
        "n": 2222
 }
 
+# Back in Nit:
+<F: 2222>
+
 # Nit:
-<E: 33.33>
+<F: 33.33>
 
 # Json:
 {
        "n": 33.33
 }
 
+# Back in Nit:
+<F: 33.33>
+
 # Nit:
 <G: hs: -1, 0; s: one, two; hm: one. 1, two. 2; am: three. 3, four. 4>
 
@@ -119,3 +141,8 @@ Serialization warning: Cycle detected in serialized object, replacing reference
        }
 }
 
+# Back in Nit:
+<G: hs: -1, 0; s: ; hm: one. 1, two. 2; am: three. 3, four. 4>
+
+Deserialization Error: Doesn't know how to deserialize class "Set[String]"
+Deserialization Error: Wrong type on `G::s` expected `Set[String]`, got `null`
index 527821b..c0f1045 100644 (file)
@@ -79,7 +79,7 @@ class F[N: Numeric]
 
        var n: N
 
-       redef fun to_s do return "<E: {n}>"
+       redef fun to_s do return "<F: {n}>"
 end
 
 # Other collections
index 6a4dfdb..62fa5eb 100644 (file)
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-import test_deserialization
 import json
-#alt1# import test_deserialization_serial
-#alt3# import test_deserialization_serial
+
+import test_deserialization
+import test_deserialization_serial
 
 var entities = new TestEntities
 
@@ -34,11 +34,13 @@ for o in tests do
        #alt4#serializer.pretty_json = true
        serializer.serialize(o)
 
-       var deserializer = new JsonDeserializer(stream.to_s)#alt2##alt4#
-       var deserialized = deserializer.deserialize#alt2##alt4#
+       var type_name: nullable String = o.class_name
+       type_name = null #alt2##alt4#
+       var deserializer = new JsonDeserializer(stream.to_s)
+       var deserialized = deserializer.deserialize(type_name)
 
        print "# Nit:\n{o}\n"
        print "# Json:\n{stream}\n"
-       print "# Back in Nit:\n{deserialized or else "null"}\n"#alt2##alt4#
-       if deserializer.errors.not_empty then print deserializer.errors.join("\n")#alt2##alt4#
+       print "# Back in Nit:\n{deserialized or else "null"}\n"
+       if deserializer.errors.not_empty then print deserializer.errors.join("\n")
 end