summary refs log tree commit diff stats
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/compile/tgensym.nim12
-rw-r--r--tests/compile/ttypeclasses.nim34
-rw-r--r--tests/run/tmemoization.nim17
-rw-r--r--tests/run/ttypedesc1.nim35
-rw-r--r--tests/run/utypeclasses.nim (renamed from tests/run/uexpr.nim)0
5 files changed, 98 insertions, 0 deletions
diff --git a/tests/compile/tgensym.nim b/tests/compile/tgensym.nim
new file mode 100644
index 000000000..3c0405136
--- /dev/null
+++ b/tests/compile/tgensym.nim
@@ -0,0 +1,12 @@
+template hygienic(val: expr) =
+  var `*x` = val
+  stdout.write `*x`
+
+var x = 100
+
+hygienic 1
+hygienic 2
+hygienic 3
+
+echo x
+
diff --git a/tests/compile/ttypeclasses.nim b/tests/compile/ttypeclasses.nim
new file mode 100644
index 000000000..e22ede1dc
--- /dev/null
+++ b/tests/compile/ttypeclasses.nim
@@ -0,0 +1,34 @@
+type
+  TFoo[T] = object
+    val: T
+
+  T1 = distinct expr
+  T2 = distinct expr
+
+proc takesExpr(x, y) =
+  echo x, y
+
+proc same(x, y: T1) =
+  echo x, y
+
+proc takesFoo(x, y: TFoo) =
+  echo x.val, y.val
+
+proc takes2Types(x,y: T1, z: T2) =
+  echo x, y, z
+
+takesExpr(1, 2)
+takesExpr(1, "xxx")
+takesExpr[bool, int](true, 0)
+
+same(1, 2)
+same("test", "test")
+
+var f: TFoo[int]
+f.val = 10
+
+takesFoo(f, f)
+
+takes2Types(1, 1, "string")
+takes2Types[string, int]("test", "test", 1)
+
diff --git a/tests/run/tmemoization.nim b/tests/run/tmemoization.nim
new file mode 100644
index 000000000..10db1fcf1
--- /dev/null
+++ b/tests/run/tmemoization.nim
@@ -0,0 +1,17 @@
+discard """
+  msg:    "test 1\ntest 2"
+  output: "TEST 1\nTEST 2\nTEST 2"
+"""
+
+import strutils
+
+proc foo(s: expr{string}): string =
+  static: echo s
+
+  const R = s.toUpper
+  return R
+  
+echo foo("test 1")
+echo foo("test 2")
+echo foo("test " & $2)
+
diff --git a/tests/run/ttypedesc1.nim b/tests/run/ttypedesc1.nim
new file mode 100644
index 000000000..9c960a809
--- /dev/null
+++ b/tests/run/ttypedesc1.nim
@@ -0,0 +1,35 @@
+import unittest
+
+type 
+  TFoo[T, U] = object
+    x: T
+    y: U
+
+proc foo(T: typedesc{float}, a: expr): string =
+  result = "float " & $(a.len > 5)
+
+proc foo(T: typedesc{TFoo}, a: int): string =
+  result = "TFoo "  & $(a)
+
+proc foo(T: typedesc{int or bool}): string =
+  var a: T
+  a = 10
+  result = "int or bool " & ($a)
+
+template foo(T: typedesc{seq}): expr = "seq"
+
+test "types can be used as proc params":
+  check foo(TFoo[int, float], 1000) == "TFoo 1000"
+  
+  var f = 10.0
+  check foo(float, "long string") == "float true"
+  check foo(type(f), [1, 2, 3]) == "float false"
+  
+  check foo(int) == "int or bool 10"
+
+  check foo(seq[int]) == "seq"
+  check foo(seq[TFoo[bool, string]]) == "seq"
+
+when false:
+  proc foo(T: typedesc{seq}, s: T) = nil
+
diff --git a/tests/run/uexpr.nim b/tests/run/utypeclasses.nim
index 06bab375e..06bab375e 100644
--- a/tests/run/uexpr.nim
+++ b/tests/run/utypeclasses.nim