summary refs log tree commit diff stats
path: root/tests/template
diff options
context:
space:
mode:
authormetagn <metagngn@gmail.com>2023-08-27 12:27:47 +0300
committerGitHub <noreply@github.com>2023-08-27 11:27:47 +0200
commitc19fd69b693e0e71d8d03812a42c4b8e50c51a3e (patch)
tree878a839915a9fc3da17bd236a2e4dc111dfa2213 /tests/template
parenta108a451c5c4be7158283c08a89691d9684dc578 (diff)
downloadNim-c19fd69b693e0e71d8d03812a42c4b8e50c51a3e.tar.gz
test case haul for old generic/template/macro issues (#22564)
* test case haul for old generic/template/macro issues

closes #12582, closes #19552, closes #2465, closes #4596, closes #15246,
closes #12683, closes #7889, closes #4547, closes #12415, closes #2002,
closes #1771, closes #5121

The test for #5648 is also moved into its own test
from `types/tissues_types` due to not being joinable.

* fix template gensym test
Diffstat (limited to 'tests/template')
-rw-r--r--tests/template/mdotcall.nim32
-rw-r--r--tests/template/tdotcall.nim12
-rw-r--r--tests/template/template_various.nim36
-rw-r--r--tests/template/tobjectdeclfield.nim25
4 files changed, 97 insertions, 8 deletions
diff --git a/tests/template/mdotcall.nim b/tests/template/mdotcall.nim
index 13dcbd824..fecd8ee26 100644
--- a/tests/template/mdotcall.nim
+++ b/tests/template/mdotcall.nim
@@ -48,3 +48,35 @@ template publicTemplateObjSyntax*(o: var ObjA, arg: Natural, doStuff: untyped) =
   o.foo2()
   doStuff
   o.bar2(arg)
+
+# issue #15246
+import os
+
+template sourceBaseName*(): string =
+  bind splitFile
+  instantiationInfo().filename.splitFile().name
+
+# issue #12683
+
+import unicode
+template toRune(s: string): Rune = s.runeAt(0)
+proc heh*[T](x: Slice[T], chars: string) = discard chars.toRune
+
+# issue #7889
+
+from streams import newStringStream, readData, writeData
+
+template bindmeTemplate*(): untyped =
+  var tst = "sometext"
+  var ss = newStringStream("anothertext")
+  ss.writeData(tst[0].addr, 2)
+  discard ss.readData(tst[0].addr, 2) # <= comment this out to make compilation successful
+
+from macros import quote, newIdentNode
+
+macro bindmeQuote*(): untyped =
+  quote do:
+    var tst = "sometext"
+    var ss = newStringStream("anothertext")
+    ss.writeData(tst[0].addr, 2)
+    discard ss.readData(tst[0].addr, 2) # <= comment this out to make compilation successful
diff --git a/tests/template/tdotcall.nim b/tests/template/tdotcall.nim
index 5fc991dd2..dc97fd52e 100644
--- a/tests/template/tdotcall.nim
+++ b/tests/template/tdotcall.nim
@@ -18,3 +18,15 @@ block: # issue #11733
   var evaluated = false
   a.publicTemplateObjSyntax(42): evaluated = true
   doAssert evaluated
+
+block: # issue #15246
+  doAssert sourceBaseName() == "tdotcall"
+
+block: # issue #12683
+  heh(0..40, "|")
+
+block: # issue #7889
+  if false:
+    bindmeQuote()
+  if false:
+    bindmeTemplate()
diff --git a/tests/template/template_various.nim b/tests/template/template_various.nim
index a3b549e18..2088b1739 100644
--- a/tests/template/template_various.nim
+++ b/tests/template/template_various.nim
@@ -354,6 +354,23 @@ block gensym3:
   echo a ! b ! c ! d ! e
   echo x,y,z
 
+block: # issue #2465
+  template t() =
+    template declX(str: string) {.gensym.} =
+      var x {.inject.} : string = str
+
+  t()
+  doAssert not declared(declX)
+  doAssert not compiles(declX("a string"))
+
+  template t2() =
+    template fooGensym() {.gensym.} =
+      echo 42
+
+  t2()
+  doAssert not declared(fooGensym)
+  doAssert not compiles(fooGensym())
+
 
 block identifier_construction_with_overridden_symbol:
   # could use add, but wanna make sure it's an override no matter what
@@ -368,3 +385,22 @@ block identifier_construction_with_overridden_symbol:
     `examplefn n`()
 
   exampletempl(1)
+
+import typetraits
+
+block: # issue #4596
+  type
+    T0 = object
+    T1 = object
+
+  template printFuncsT() =
+    proc getV[A](a: typedesc[A]): string =
+      var s {. global .} = name(A)
+      return s
+
+  printFuncsT()
+
+  doAssert getV(T1) == "T1"
+  doAssert getV(T0) == "T0"
+  doAssert getV(T0) == "T0"
+  doAssert getV(T1) == "T1"
diff --git a/tests/template/tobjectdeclfield.nim b/tests/template/tobjectdeclfield.nim
index 201f076ca..afce2cae8 100644
--- a/tests/template/tobjectdeclfield.nim
+++ b/tests/template/tobjectdeclfield.nim
@@ -1,12 +1,21 @@
-var x = 0
+block: # issue #16005
+  var x = 0
 
-block:
-  type Foo = object
-    x: float # ok
-
-template main() =
   block:
     type Foo = object
-      x: float # Error: cannot use symbol of kind 'var' as a 'field'
+      x: float # ok
+
+  template main() =
+    block:
+      type Foo = object
+        x: float # Error: cannot use symbol of kind 'var' as a 'field'
+
+  main()
+
+block: # issue #19552
+  template test =
+    type
+      test2 = ref object
+        reset: int
 
-main()
+  test()