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.nim61
1 files changed, 40 insertions, 21 deletions
diff --git a/tests/stdlib/tjsonmacro.nim b/tests/stdlib/tjsonmacro.nim
index 7dbbf6b51..806cbadc6 100644
--- a/tests/stdlib/tjsonmacro.nim
+++ b/tests/stdlib/tjsonmacro.nim
@@ -1,3 +1,7 @@
+discard """
+  file: "tjsonmacro.nim"
+  output: ""
+"""
 import json, macros, strutils
 
 type
@@ -17,24 +21,39 @@ type
 
   Replay* = ref object
     events*: seq[ReplayEvent]
-
-var x = Replay(
-  events: @[
-    ReplayEvent(
-      time: 1.2345,
-      kind: FoodEaten,
-      foodPos: Point[float](x: 5.0, y: 1.0)
-    )
-  ]
-)
-
-let node = %x
-
-echo(node)
-
-let y = to(node, Replay)
-doAssert y.events[0].time == 1.2345
-doAssert y.events[0].kind == FoodEaten
-doAssert y.events[0].foodPos.x == 5.0
-doAssert y.events[0].foodPos.y == 1.0
-echo(y.repr)
\ No newline at end of file
+    test: int
+    test2: string
+    test3: bool
+    testNil: string
+
+when isMainModule:
+  # Tests inspired by own use case (with some additional tests).
+  # This should succeed.
+  var x = Replay(
+    events: @[
+      ReplayEvent(
+        time: 1.2345,
+        kind: FoodEaten,
+        foodPos: Point[float](x: 5.0, y: 1.0)
+      )
+    ],
+    test: 18827361,
+    test2: "hello world",
+    test3: true,
+    testNil: nil
+  )
+
+  let node = %x
+
+  let y = to(node, Replay)
+  doAssert y.events[0].time == 1.2345
+  doAssert y.events[0].kind == FoodEaten
+  doAssert y.events[0].foodPos.x == 5.0
+  doAssert y.events[0].foodPos.y == 1.0
+  doAssert y.test == 18827361
+  doAssert y.test2 == "hello world"
+  doAssert y.test3
+  doAssert y.testNil == nil
+
+  # Tests that verify the error messages for invalid data.
+  # TODO:
\ No newline at end of file