summary refs log tree commit diff stats
path: root/tests/macros
diff options
context:
space:
mode:
Diffstat (limited to 'tests/macros')
-rw-r--r--tests/macros/tbindsym.nim2
-rw-r--r--tests/macros/tdumpastgen.nim2
-rw-r--r--tests/macros/tdumptree.nim9
-rw-r--r--tests/macros/tgetimpl.nim36
-rw-r--r--tests/macros/tgettype.nim6
-rw-r--r--tests/macros/tgettype2.nim32
-rw-r--r--tests/macros/tgettypeinst.nim11
-rw-r--r--tests/macros/tmacrogenerics.nim8
-rw-r--r--tests/macros/tmacros_issues.nim15
-rw-r--r--tests/macros/tmacros_various.nim15
-rw-r--r--tests/macros/tmemit.nim6
-rw-r--r--tests/macros/tnewlit.nim20
-rw-r--r--tests/macros/tquotedo.nim25
-rw-r--r--tests/macros/tslice.nim38
-rw-r--r--tests/macros/tstaticparamsmacro.nim9
15 files changed, 194 insertions, 40 deletions
diff --git a/tests/macros/tbindsym.nim b/tests/macros/tbindsym.nim
index 2abcd98ce..a493d6a88 100644
--- a/tests/macros/tbindsym.nim
+++ b/tests/macros/tbindsym.nim
@@ -1,5 +1,5 @@
 discard """
-  msg: '''initApple
+  nimout: '''initApple
 deinitApple
 Coral
 enum
diff --git a/tests/macros/tdumpastgen.nim b/tests/macros/tdumpastgen.nim
index 0a1836886..0e0581f6a 100644
--- a/tests/macros/tdumpastgen.nim
+++ b/tests/macros/tdumpastgen.nim
@@ -1,5 +1,5 @@
 discard """
-msg: '''nnkStmtList.newTree(
+nimout: '''nnkStmtList.newTree(
   nnkVarSection.newTree(
     nnkIdentDefs.newTree(
       newIdentNode("x"),
diff --git a/tests/macros/tdumptree.nim b/tests/macros/tdumptree.nim
index 58b011b45..f540306c4 100644
--- a/tests/macros/tdumptree.nim
+++ b/tests/macros/tdumptree.nim
@@ -1,13 +1,14 @@
 discard """
-msg: '''StmtList
+nimout: '''
+StmtList
   VarSection
     IdentDefs
-      Ident !"x"
+      Ident "x"
       Empty
       Call
         DotExpr
-          Ident !"foo"
-          Ident !"create"
+          Ident "foo"
+          Ident "create"
         IntLit 56'''
 """
 
diff --git a/tests/macros/tgetimpl.nim b/tests/macros/tgetimpl.nim
index 715c969f3..d231a4336 100644
--- a/tests/macros/tgetimpl.nim
+++ b/tests/macros/tgetimpl.nim
@@ -1,7 +1,7 @@
 discard """
-  msg: '''"muhaha"
+  nimout: '''"muhaha"
 proc poo(x, y: int) =
-  let y = x 
+  let y = x
   echo ["poo"]'''
 """
 
@@ -16,14 +16,13 @@ proc poo(x, y: int) =
 
 macro m(x: typed): untyped =
   echo repr x.getImpl
-  result = x
 
-discard m foo
-discard m poo
+m(foo)
+m(poo)
 
 #------------
 
-macro checkOwner(x: typed, check_id: static[int]): untyped = 
+macro checkOwner(x: typed, check_id: static[int]): untyped =
   let sym = case check_id:
     of 0: x
     of 1: x.getImpl.body[0][0][0]
@@ -32,11 +31,11 @@ macro checkOwner(x: typed, check_id: static[int]): untyped =
     else: x
   result = newStrLitNode($sym.owner.symKind)
 
-macro isSameOwner(x, y: typed): untyped = 
-  result = 
+macro isSameOwner(x, y: typed): untyped =
+  result =
     if x.owner == y.owner: bindSym"true"
     else: bindSym"false"
-    
+
 
 static:
   doAssert checkOwner(foo, 0) == "nskModule"
@@ -47,3 +46,22 @@ static:
   doAssert isSameOwner(foo, poo)
   doAssert isSameOwner(foo, echo) == false
   doAssert isSameOwner(poo, len) == false
+
+#---------------------------------------------------------------
+
+macro check_gen_proc(ex: typed): (bool, bool) =
+  let lenChoice = bindsym"len"
+  var is_equal = false 
+  var is_instance_of = false 
+  for child in lenChoice:
+    if not is_equal:
+      is_equal = ex[0] == child
+    if not is_instance_of:
+      is_instance_of = isInstantiationOf(ex[0], child)
+         
+  result = nnkTupleConstr.newTree(newLit(is_equal), newLit(is_instance_of))
+
+# check that len(seq[int]) is not equal to bindSym"len", but is instance of it
+let a = @[1,2,3]
+assert: check_gen_proc(len(a)) == (false, true)
+
diff --git a/tests/macros/tgettype.nim b/tests/macros/tgettype.nim
index fa02bce57..77a55471f 100644
--- a/tests/macros/tgettype.nim
+++ b/tests/macros/tgettype.nim
@@ -1,6 +1,8 @@
 discard """
-msg: '''ObjectTy(Sym(Model), RecList(Sym(name), Sym(password)))
-BracketExpr(Sym(typeDesc), Sym(User))'''
+output: '''
+(ObjectTy (Empty) (Sym "Model") (RecList (Sym "name") (Sym "password")))
+(BracketExpr (Sym "typeDesc") (Sym "User"))
+'''
 """
 import strutils, macros
 
diff --git a/tests/macros/tgettype2.nim b/tests/macros/tgettype2.nim
index f129e6e1b..c579cf6ff 100644
--- a/tests/macros/tgettype2.nim
+++ b/tests/macros/tgettype2.nim
@@ -1,3 +1,35 @@
+discard """
+output: '''
+############
+#### gt ####
+############
+gt(Foo):	typeDesc[Foo]
+gt(Bar):	typeDesc[Bar]
+gt(Baz):	typeDesc[int]
+gt(foo):	distinct[int]
+gt(bar):	distinct[int]
+gt(baz):	int, int
+gt(v):	seq[int]
+gt(vv):	seq[float]
+gt(t):	distinct[tuple[int, int]]
+gt(tt):	distinct[tuple[float, float]]
+gt(s):	distinct[tuple[int, int]]
+#############
+#### gt2 ####
+#############
+gt2(Foo): 	Foo
+gt2(Bar): 	Bar
+gt2(Baz): 	Baz
+gt2(foo): 	Foo
+gt2(bar): 	Bar
+gt2(baz): 	Baz
+gt2(v): 	seq[int]
+gt2(vv): 	seq[float]
+gt2(t): 	MyType[system.int]
+gt2(tt): 	MyType[system.float]
+gt2(s): 	MySimpleType
+'''
+"""
 
 import macros, typetraits
 
diff --git a/tests/macros/tgettypeinst.nim b/tests/macros/tgettypeinst.nim
index 6a99dc8b7..c2cde9a43 100644
--- a/tests/macros/tgettypeinst.nim
+++ b/tests/macros/tgettypeinst.nim
@@ -201,3 +201,14 @@ test(MyObj):
     _ = object {.packed,myAttr,serializationKey: "one".}
       myField: int
       myField2: float
+
+block t9600:
+  type
+    Apple = ref object of RootObj
+
+  macro mixer(x: typed): untyped =
+    let w = getType(x)
+    let v = getTypeImpl(w[1])
+
+  var z: Apple
+  mixer(z)
diff --git a/tests/macros/tmacrogenerics.nim b/tests/macros/tmacrogenerics.nim
index 919a15b46..e4acdc321 100644
--- a/tests/macros/tmacrogenerics.nim
+++ b/tests/macros/tmacrogenerics.nim
@@ -1,8 +1,10 @@
 discard """
   file: "tmacrogenerics.nim"
-  msg: '''
-instantiation 1 with typedesc and typedesc
-counter: 1
+  nimout: '''
+instantiation 1 with None and None
+instantiation 2 with None and None
+instantiation 3 with None and None
+counter: 3
 '''
   output: "int\nfloat\nint\nstring"
 """
diff --git a/tests/macros/tmacros_issues.nim b/tests/macros/tmacros_issues.nim
index ecdcd5da9..657f30fc4 100644
--- a/tests/macros/tmacros_issues.nim
+++ b/tests/macros/tmacros_issues.nim
@@ -1,13 +1,10 @@
 discard """
-  msg: '''
-proc init(foo129050: int; bar129052: typedesc[int]): int =
-  foo129050
-
+  nimout: '''
 IntLit 5
 proc (x: int): string => typeDesc[proc[string, int]]
 proc (x: int): void => typeDesc[proc[void, int]]
 proc (x: int) => typeDesc[proc[void, int]]
-x => uncheckedArray[int]
+x => UncheckedArray[int]
 a
 s
 d
@@ -43,8 +40,8 @@ block t7723:
       proc init(foo: int, bar: typedesc[int]): int =
         foo
 
-  expandMacros:
-    foo1()
+  #expandMacros:
+  foo1()
 
   doAssert init(1, int) == 1
 
@@ -144,11 +141,11 @@ block t1140:
       result.parse_template body[1].strVal
 
 
-  proc actual: string = tmpli html"""
+  proc actual: string {.used.} = tmpli html"""
       <p>Test!</p>
       """
 
-  proc another: string = tmpli html"""
+  proc another: string {.used.} = tmpli html"""
       <p>what</p>
       """
 
diff --git a/tests/macros/tmacros_various.nim b/tests/macros/tmacros_various.nim
index 15bd28a37..9eece00bd 100644
--- a/tests/macros/tmacros_various.nim
+++ b/tests/macros/tmacros_various.nim
@@ -1,9 +1,14 @@
 discard """
-  msg: '''
-range[0 .. 100]
-array[0 .. 100, int]
-10
-test
+  nimout: '''
+Infix
+  Ident "=>"
+  Call
+    Ident "name"
+    Ident "a"
+    ExprColonExpr
+      Ident "b"
+      Ident "cint"
+  NilLit
 '''
 
   output: '''
diff --git a/tests/macros/tmemit.nim b/tests/macros/tmemit.nim
index 3a3b8734b..06ab8a1e2 100644
--- a/tests/macros/tmemit.nim
+++ b/tests/macros/tmemit.nim
@@ -1,7 +1,9 @@
 discard """
-  output: '''HELLO WORLD
+  output: '''
+HELLO WORLD
 c_func
-12'''
+12
+'''
 """
 
 import macros, strutils
diff --git a/tests/macros/tnewlit.nim b/tests/macros/tnewlit.nim
index 3ba1e09e1..194f035ba 100644
--- a/tests/macros/tnewlit.nim
+++ b/tests/macros/tnewlit.nim
@@ -147,3 +147,23 @@ block:
   # x needs to be of type seq[string]
   var x = test_newLit_empty_seq_string
   x.add("xyz")
+
+type
+  MyEnum = enum
+    meA
+    meB
+
+macro test_newLit_Enum: untyped =
+  result = newLit(meA)
+
+block:
+  let tmp: MyEnum = meA
+  doAssert tmp == test_newLit_Enum
+
+macro test_newLit_set: untyped =
+  let myset = {MyEnum.low .. MyEnum.high}
+  result = newLit(myset)
+
+block:
+  let tmp: set[MyEnum] = {MyEnum.low .. MyEnum.high}
+  doAssert tmp == test_newLit_set
diff --git a/tests/macros/tquotedo.nim b/tests/macros/tquotedo.nim
new file mode 100644
index 000000000..cd1f69116
--- /dev/null
+++ b/tests/macros/tquotedo.nim
@@ -0,0 +1,25 @@
+discard """
+output: '''
+123
+Hallo Welt
+Hallo Welt
+'''
+"""
+
+import macros
+
+macro mac(): untyped =
+  quote do:
+    proc test(): int =
+      (proc(): int = result = 123)()
+
+mac()
+echo test()
+
+macro foobar(arg: untyped): untyped =
+  result = arg
+  result.add quote do:
+    `result`
+
+foobar:
+  echo "Hallo Welt"
diff --git a/tests/macros/tslice.nim b/tests/macros/tslice.nim
new file mode 100644
index 000000000..c64289ec6
--- /dev/null
+++ b/tests/macros/tslice.nim
@@ -0,0 +1,38 @@
+import macros
+
+macro test(): untyped =
+  result = nnkStmtList.newTree()
+  let n = nnkStmtList.newTree(
+    newIdentNode("one"),
+    newIdentNode("two"),
+    newIdentNode("three"),
+    newIdentNode("four"),
+    newIdentNode("five"),
+    newIdentNode("six")
+  )
+
+  var i = 1
+  for x in n[1 .. ^2]:
+    assert x == n[i]
+    i.inc
+  assert i == 5
+
+  i = 3
+  for x in n[3..^1]:
+    assert x == n[i]
+    i.inc
+  assert i == 6
+
+  i = 0
+  for x in n[0..3]:
+    assert x == n[i]
+    i.inc
+  assert i == 4
+
+  i = 0
+  for x in n[0..5]:
+    assert x == n[i]
+    i.inc
+  assert i == 6
+
+test()
diff --git a/tests/macros/tstaticparamsmacro.nim b/tests/macros/tstaticparamsmacro.nim
index ea59936e0..8bd653920 100644
--- a/tests/macros/tstaticparamsmacro.nim
+++ b/tests/macros/tstaticparamsmacro.nim
@@ -1,5 +1,6 @@
 discard """
-  msg: '''letters
+  nimout: '''
+letters
 aa
 bb
 numbers
@@ -8,7 +9,7 @@ numbers
 AST a
 [(11, 22), (33, 44)]
 AST b
-(e: [55, 66], f: [77, 88])
+([55, 66], [77, 88])
 55
 10
 20Test
@@ -44,10 +45,10 @@ const
   b : Tb = (@[55,66], @[77, 88])
 
 macro mA(data: static[Ta]): untyped =
-  echo "AST a \n", repr(data)
+  echo "AST a\n", repr(data)
 
 macro mB(data: static[Tb]): untyped =
-  echo "AST b \n", repr(data)
+  echo "AST b\n", repr(data)
   echo data.e[0]
 
 mA(a)