summary refs log tree commit diff stats
path: root/tests/stdlib/tjsonmacro.nim
diff options
context:
space:
mode:
authorDominik Picheta <dominikpicheta@gmail.com>2017-04-09 12:48:07 +0200
committerDominik Picheta <dominikpicheta@gmail.com>2017-04-09 12:48:07 +0200
commiteedc6fecd73e17be492bb5a7352ef27ef8bac7e6 (patch)
tree8da9d52133a067907108267c9f737ec099158792 /tests/stdlib/tjsonmacro.nim
parenta883424d0d7e5212040ef30df5fa00818e1a2c0e (diff)
downloadNim-eedc6fecd73e17be492bb5a7352ef27ef8bac7e6.tar.gz
Document `to` macro in JSON and add example.
Diffstat (limited to 'tests/stdlib/tjsonmacro.nim')
-rw-r--r--tests/stdlib/tjsonmacro.nim26
1 files changed, 26 insertions, 0 deletions
diff --git a/tests/stdlib/tjsonmacro.nim b/tests/stdlib/tjsonmacro.nim
index b5d73240e..345c5a2fc 100644
--- a/tests/stdlib/tjsonmacro.nim
+++ b/tests/stdlib/tjsonmacro.nim
@@ -91,6 +91,7 @@ when isMainModule:
     doAssert result.other == node["other"].getNum()
 
   # TODO: Test object variant with set in of branch.
+  # TODO: Should we support heterogenous arrays?
 
   # Tests that verify the error messages for invalid data.
   block:
@@ -141,3 +142,28 @@ when isMainModule:
     except:
       doAssert false
 
+  # Test the example in json module.
+  block:
+    let jsonNode = parseJson("""
+      {
+        "person": {
+          "name": "Nimmer",
+          "age": 21
+        },
+        "list": [1, 2, 3, 4]
+      }
+    """)
+
+    type
+      Person = object
+        name: string
+        age: int
+
+      Data = object
+        person: Person
+        list: seq[int]
+
+    var data = to(jsonNode, Data)
+    doAssert data.person.name == "Nimmer"
+    doAssert data.person.age == 21
+    doAssert data.list == @[1, 2, 3, 4]
\ No newline at end of file