summary refs log tree commit diff stats
path: root/tests/stdlib/tjsonmacro.nim
diff options
context:
space:
mode:
authorArne Döring <arne.doering@gmx.net>2019-02-28 22:57:57 +0100
committerAndreas Rumpf <rumpf_a@web.de>2019-02-28 22:57:57 +0100
commit1102b8ac6e643c8f8428dd7db0994d26b0c65ea6 (patch)
treeb08388f89e7867f03e5d59be00db70a6535752dc /tests/stdlib/tjsonmacro.nim
parent728ff1004a60835c18c44b64830ea08dc805485e (diff)
downloadNim-1102b8ac6e643c8f8428dd7db0994d26b0c65ea6.tar.gz
StringStream and parseJson, parseCfg, parseSql et al for the vm (#10746)
Diffstat (limited to 'tests/stdlib/tjsonmacro.nim')
-rw-r--r--tests/stdlib/tjsonmacro.nim40
1 files changed, 40 insertions, 0 deletions
diff --git a/tests/stdlib/tjsonmacro.nim b/tests/stdlib/tjsonmacro.nim
index 2e95b4833..32493f9bc 100644
--- a/tests/stdlib/tjsonmacro.nim
+++ b/tests/stdlib/tjsonmacro.nim
@@ -520,3 +520,43 @@ when true:
     block test_tuple:
       doAssert $(%* (a1: 10, a2: "foo")) == """{"a1":10,"a2":"foo"}"""
       doAssert $(%* (10, "foo")) == """[10,"foo"]"""
+
+# TODO: when the issue with the limeted vm registers is solved, the
+# exact same test as above should be evaluated at compile time as
+# well, to ensure that the vm functionality won't diverge from the
+# runtime functionality. Until then, the following test should do it.
+
+static:
+  var t = parseJson("""
+    {
+      "name":"Bongo",
+      "email":"bongo@bingo.com",
+      "list": [11,7,15],
+      "year": 1975,
+      "dict": {"a": 1, "b": 2},
+      "arr": [1.0, 2.0, 7.0],
+      "person": {"name": "boney"},
+      "dog": {"name": "honey"},
+      "fruit": {"color": 10},
+      "distfruit": {"color": 11},
+      "emails": ["abc", "123"]
+    }
+  """)
+
+  doAssert t["name"].getStr == "Bongo"
+  doAssert t["email"].getStr == "bongo@bingo.com"
+  doAssert t["list"][0].getInt == 11
+  doAssert t["list"][1].getInt == 7
+  doAssert t["list"][2].getInt == 15
+  doAssert t["year"].getInt == 1975
+  doAssert t["dict"]["a"].getInt == 1
+  doAssert t["dict"]["b"].getInt == 2
+  doAssert t["arr"][0].getFloat == 1.0
+  doAssert t["arr"][1].getFloat == 2.0
+  doAssert t["arr"][2].getFloat == 7.0
+  doAssert t["person"]["name"].getStr == "boney"
+  doAssert t["distfruit"]["color"].getInt == 11
+  doAssert t["dog"]["name"].getStr == "honey"
+  doAssert t["fruit"]["color"].getInt == 10
+  doAssert t["emails"][0].getStr == "abc"
+  doAssert t["emails"][1].getStr == "123"