summary refs log tree commit diff stats
path: root/tests/stdlib
diff options
context:
space:
mode:
authorMiran <narimiran@disroot.org>2020-03-04 10:25:59 +0100
committerGitHub <noreply@github.com>2020-03-04 10:25:59 +0100
commit9961d1f67d623bc8a4f6bbab5714d945cbe4abc0 (patch)
tree39f2739d40a826987f953846231c3594c3135670 /tests/stdlib
parent34c16f5ecae765c014335525ef518233832832db (diff)
downloadNim-9961d1f67d623bc8a4f6bbab5714d945cbe4abc0.tar.gz
fix #13531 by adding a test (#13581)
Diffstat (limited to 'tests/stdlib')
-rw-r--r--tests/stdlib/tjson_unmarshall.nim31
1 files changed, 31 insertions, 0 deletions
diff --git a/tests/stdlib/tjson_unmarshall.nim b/tests/stdlib/tjson_unmarshall.nim
new file mode 100644
index 000000000..69bed3ac9
--- /dev/null
+++ b/tests/stdlib/tjson_unmarshall.nim
@@ -0,0 +1,31 @@
+discard """
+  output: '''
+Original: (kind: P, pChildren: @[(kind: Text, textStr: "mychild"), (kind: Br)])
+jsonNode: {"kind":"P","pChildren":[{"kind":"Text","textStr":"mychild"},{"kind":"Br"}]}
+Reversed: (kind: P, pChildren: @[(kind: Text, textStr: "mychild"), (kind: Br)])
+'''
+"""
+
+import json
+
+type
+  ContentNodeKind* = enum
+    P,
+    Br,
+    Text,
+  ContentNode* = object
+    case kind*: ContentNodeKind
+    of P: pChildren*: seq[ContentNode]
+    of Br: nil
+    of Text: textStr*: string
+
+let mynode = ContentNode(kind: P, pChildren: @[
+  ContentNode(kind: Text, textStr: "mychild"),
+  ContentNode(kind: Br)
+])
+ 
+echo "Original: " & $mynode
+
+let jsonNode = %*mynode
+echo "jsonNode: " & $jsonNode
+echo "Reversed: " & $jsonNode.to(ContentNode)