summary refs log tree commit diff stats
path: root/tests/run
diff options
context:
space:
mode:
Diffstat (limited to 'tests/run')
-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
3 files changed, 52 insertions, 0 deletions
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