summary refs log tree commit diff stats
path: root/tests/stdlib/tjsonmacro.nim
diff options
context:
space:
mode:
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"
/a> 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235