From 897ef9efee1a7f889f088fdfec9075cecd33c3d8 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Alexis=20Laferri=C3=A8re?= Date: Fri, 22 Apr 2016 09:04:53 -0400 Subject: [PATCH] tests: test pretty JSON, with and without plain JSON MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Alexis Laferrière --- tests/sav/nitce/test_json_deserialization_alt3.res | 192 ++++++++++++++++++++ tests/sav/test_json_deserialization_alt3.res | 192 ++++++++++++++++++++ tests/sav/test_json_deserialization_alt4.res | 135 ++++++++++++++ tests/test_json_deserialization.nit | 13 +- 4 files changed, 528 insertions(+), 4 deletions(-) create mode 100644 tests/sav/nitce/test_json_deserialization_alt3.res create mode 100644 tests/sav/test_json_deserialization_alt3.res create mode 100644 tests/sav/test_json_deserialization_alt4.res diff --git a/tests/sav/nitce/test_json_deserialization_alt3.res b/tests/sav/nitce/test_json_deserialization_alt3.res new file mode 100644 index 0000000..b269caf --- /dev/null +++ b/tests/sav/nitce/test_json_deserialization_alt3.res @@ -0,0 +1,192 @@ +# Nit: + + +# 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: + + +# Nit: + 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: + 1111 qwer> + +# Nit: + 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: + 1111 qwer>> + +# Nit: + +<- false p4ssw0rd> 1111 f" \/> 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: + +<- false p4ssw0rd> 1111 f" \/> true> + +# Nit: + + +# 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: + + +# Nit: + + +# Json: +{ + "__kind": "obj", "__id": 0, "__class": "F", + "n": 2222 +} + +# Back in Nit: +null + +# Nit: + + +# Json: +{ + "__kind": "obj", "__id": 0, "__class": "F", + "n": 33.33 +} + +# Back in Nit: +null + +# Nit: + + +# 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: + + diff --git a/tests/sav/test_json_deserialization_alt3.res b/tests/sav/test_json_deserialization_alt3.res new file mode 100644 index 0000000..c49a52a --- /dev/null +++ b/tests/sav/test_json_deserialization_alt3.res @@ -0,0 +1,192 @@ +# Nit: + + +# 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: + + +# Nit: + 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: + 1111 qwer> + +# Nit: + 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: + 1111 qwer>> + +# Nit: + +<- false p4ssw0rd> 1111 f" \/> 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: + +<- false p4ssw0rd> 1111 f" \/> true> + +# Nit: + + +# 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: + + +# Nit: + + +# Json: +{ + "__kind": "obj", "__id": 0, "__class": "F[Int]", + "n": 2222 +} + +# Back in Nit: +null + +# Nit: + + +# Json: +{ + "__kind": "obj", "__id": 0, "__class": "F[Float]", + "n": 33.33 +} + +# Back in Nit: +null + +# Nit: + + +# 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: + + diff --git a/tests/sav/test_json_deserialization_alt4.res b/tests/sav/test_json_deserialization_alt4.res new file mode 100644 index 0000000..5527174 --- /dev/null +++ b/tests/sav/test_json_deserialization_alt4.res @@ -0,0 +1,135 @@ +# Nit: + + +# Json: +{ + "b": true, + "c": "a", + "f": 0.123, + "i": 1234, + "serialization_specific_name": "asdf", + "n": null +} + +# Nit: + 1111 qwer> + +# Json: +{ + "b": false, + "c": "b", + "f": 123.123, + "i": 2345, + "serialization_specific_name": "hjkl", + "n": 12, + "ii": 1111, + "ss": "qwer" +} + +# Nit: + 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: + +<- false p4ssw0rd> 1111 f" \/> 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: + + +# Json: +{ + "a": [ + "hello", + 1234, + 123.4 + ], + "b": [ + "hella", + 2345, + 234.5 + ] +} + +# Nit: + + +# Json: +{ + "n": 2222 +} + +# Nit: + + +# Json: +{ + "n": 33.33 +} + +# Nit: + + +# Json: +{ + "hs": [ + -1, + 0 + ], + "s": [ + "one", + "two" + ], + "hm": { + "one": 1, + "two": 2 + }, + "am": { + "three": "3", + "four": "4" + } +} + diff --git a/tests/test_json_deserialization.nit b/tests/test_json_deserialization.nit index 8baadb1..155a39c 100644 --- a/tests/test_json_deserialization.nit +++ b/tests/test_json_deserialization.nit @@ -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 -- 1.7.9.5