summary refs log tree commit diff stats
path: root/tests
diff options
context:
space:
mode:
authorArne Döring <arne.doering@gmx.net>2019-10-17 09:55:41 +0200
committerAndreas Rumpf <rumpf_a@web.de>2019-10-17 09:55:41 +0200
commit21cbfd72ec9fce04fab98326376651806c8adf0b (patch)
treebbdfd560551627b11a292c2f5913fae7d1104c98 /tests
parent5ba932e43c9c971555d8fdc9e25e2edcdcdd70b4 (diff)
downloadNim-21cbfd72ec9fce04fab98326376651806c8adf0b.tar.gz
Refactor json macro (#12391)
* closes #12316
* make tjsonmacro work at js target
* closes #12289
* closes #11988
* also fixed gdb related stuff
Diffstat (limited to 'tests')
-rw-r--r--tests/generics/tforwardgenericconstrained.nim73
-rw-r--r--tests/stdlib/tjsonmacro.nim42
-rw-r--r--tests/stdlib/tjsonmacro_reject2.nim21
-rw-r--r--tests/untestable/gdb/gdb_pretty_printer_test_output.txt2
4 files changed, 115 insertions, 23 deletions
diff --git a/tests/generics/tforwardgenericconstrained.nim b/tests/generics/tforwardgenericconstrained.nim
new file mode 100644
index 000000000..6163ea1a8
--- /dev/null
+++ b/tests/generics/tforwardgenericconstrained.nim
@@ -0,0 +1,73 @@
+discard """
+output: '''
+hello some integer
+hello range
+hello tuple
+hello seq
+hello object
+hello distinct
+hello enum
+'''
+"""
+
+
+
+# SomeInteger
+
+proc foo[T : SomeInteger](arg: T)
+proc foo[T : SomeInteger](arg: T) =
+  echo "hello some integer"
+foo(123)
+
+# range
+
+proc foo2[T : range[0..100]](arg: T)
+proc foo2[T : range[0..100]](arg: T) =
+  echo "hello range"
+foo2(7)
+
+# tuple
+
+proc foo3[T : tuple](arg: T)
+proc foo3[T : tuple](arg: T) =
+  echo "hello tuple"
+
+foo3((a:123,b:321))
+
+# seq
+
+proc foo4[T: seq](arg: T)
+proc foo4[T: seq](arg: T) =
+  echo "hello seq"
+
+foo4(@[1,2,3])
+
+# object
+
+proc foo5[T : object](arg: T)
+proc foo5[T : object](arg: T) =
+  echo "hello object"
+
+type MyType = object
+var mt: MyType
+foo5(mt)
+
+# distinct
+
+proc foo6[T : distinct](arg: T)
+proc foo6[T : distinct](arg: T) =
+  echo "hello distinct"
+
+type MyDistinct = distinct string
+var md: MyDistinct
+foo6(md)
+
+# enum
+
+proc foo7[T : enum](arg: T)
+proc foo7[T : enum](arg: T) =
+  echo "hello enum"
+
+type MyEnum = enum
+  ValueA
+foo7(ValueA)
diff --git a/tests/stdlib/tjsonmacro.nim b/tests/stdlib/tjsonmacro.nim
index 8dc5a32d2..c2a4ed406 100644
--- a/tests/stdlib/tjsonmacro.nim
+++ b/tests/stdlib/tjsonmacro.nim
@@ -1,6 +1,8 @@
 discard """
   output: ""
+  targets: "c js"
 """
+
 import json, strutils, options, tables
 
 when true:
@@ -18,6 +20,11 @@ when true:
       case kind*: ReplayEventKind
       of FoodAppeared, FoodEaten:
         foodPos*: Point[float]
+        case subKind*: bool
+        of true:
+          it: int
+        of false:
+          ot: float
       of DirectionChanged:
         playerPos*: float
 
@@ -33,7 +40,9 @@ when true:
       ReplayEvent(
         time: 1.2345,
         kind: FoodEaten,
-        foodPos: Point[float](x: 5.0, y: 1.0)
+        foodPos: Point[float](x: 5.0, y: 1.0),
+        subKind: true,
+        it: 7
       )
     ],
     test: 18827361,
@@ -592,3 +601,34 @@ static:
   doAssert t["fruit"]["color"].getInt == 10
   doAssert t["emails"][0].getStr == "abc"
   doAssert t["emails"][1].getStr == "123"
+
+block:
+  # ref objects with cycles.
+  type
+    Misdirection = object
+      cycle: Cycle
+
+    Cycle = ref object
+      foo: string
+      cycle: Misdirection
+
+  let data = """
+    {"cycle": null}
+  """
+
+  let dataParsed = parseJson(data)
+  let dataDeser = to(dataParsed, Misdirection)
+
+block:
+  # ref object from #12316
+  type
+    Foo = ref Bar
+    Bar = object
+
+  discard "null".parseJson.to Foo
+
+block:
+  # named array #12289
+  type Vec = array[2, int]
+  let arr = "[1,2]".parseJson.to Vec
+  doAssert arr == [1,2]
diff --git a/tests/stdlib/tjsonmacro_reject2.nim b/tests/stdlib/tjsonmacro_reject2.nim
deleted file mode 100644
index e13dad307..000000000
--- a/tests/stdlib/tjsonmacro_reject2.nim
+++ /dev/null
@@ -1,21 +0,0 @@
-discard """
-  errormsg: "The `to` macro does not support ref objects with cycles."
-  file: "tjsonmacro_reject2.nim"
-  line: 10
-"""
-import json
-
-type
-  Misdirection = object
-    cycle: Cycle
-
-  Cycle = ref object
-    foo: string
-    cycle: Misdirection
-
-let data = """
-  {"cycle": null}
-"""
-
-let dataParsed = parseJson(data)
-let dataDeser = to(dataParsed, Cycle)
diff --git a/tests/untestable/gdb/gdb_pretty_printer_test_output.txt b/tests/untestable/gdb/gdb_pretty_printer_test_output.txt
index cbc9bde8d..73d26016f 100644
--- a/tests/untestable/gdb/gdb_pretty_printer_test_output.txt
+++ b/tests/untestable/gdb/gdb_pretty_printer_test_output.txt
@@ -1,3 +1,3 @@
 Loading Nim Runtime support.
-NimEnumPrinter: lookup global symbol 'NTI_z9cu80OJCfNgw9bUdzn5ZEzw_ failed for tyEnum_MyOtherEnum_z9cu80OJCfNgw9bUdzn5ZEzw.
+NimEnumPrinter: lookup global symbol 'NTI__z9cu80OJCfNgw9bUdzn5ZEzw_ failed for tyEnum_MyOtherEnum__z9cu80OJCfNgw9bUdzn5ZEzw.
 8