summary refs log tree commit diff stats
path: root/tests/macros
diff options
context:
space:
mode:
authorAndreas Rumpf <rumpf_a@web.de>2016-07-06 16:52:41 +0200
committerAndreas Rumpf <rumpf_a@web.de>2016-07-06 16:52:41 +0200
commit389f500226495c335881c846c39ff938f93e693a (patch)
treefbe0729382eec20efff71f567754e94215d86417 /tests/macros
parent17d97462cfff97881610b10bee2a985d64d8a005 (diff)
downloadNim-389f500226495c335881c846c39ff938f93e693a.tar.gz
added test case for #537
Diffstat (limited to 'tests/macros')
-rw-r--r--tests/macros/tcomplexecho.nim42
1 files changed, 42 insertions, 0 deletions
diff --git a/tests/macros/tcomplexecho.nim b/tests/macros/tcomplexecho.nim
new file mode 100644
index 000000000..f7f933c1c
--- /dev/null
+++ b/tests/macros/tcomplexecho.nim
@@ -0,0 +1,42 @@
+discard """
+  output: '''3
+OK
+56
+123
+56
+61'''
+"""
+
+import macros
+
+# Bug from the forum
+macro addEcho1(s: untyped): stmt =
+  s.body.add(newCall("echo", newStrLitNode("OK")))
+  result = s
+
+proc f1() {.addEcho1.} =
+  let i = 1+2
+  echo i
+
+f1()
+
+# bug #537
+proc test(): seq[NimNode] {.compiletime.} =
+  result = @[]
+  result.add parseExpr("echo 56")
+  result.add parseExpr("echo 123")
+  result.add parseExpr("echo 56")
+
+proc foo(): seq[NimNode] {.compiletime.} =
+  result = @[]
+  result.add test()
+  result.add parseExpr("echo(5+56)")
+
+macro bar(): stmt =
+  result = newNimNode(nnkStmtList)
+  let x = foo()
+  for xx in x:
+    result.add xx
+  echo treeRepr(result)
+
+bar()