From fa332b729835f70c71ee235626490697779fee87 Mon Sep 17 00:00:00 2001 From: Araq Date: Tue, 8 Mar 2011 01:59:15 +0100 Subject: fixes #13; fixes #18 --- tests/accept/run/tmacro2.nim | 27 +++++++++++++++++++++++++++ tests/accept/run/tmacro3.nim | 31 +++++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+) create mode 100644 tests/accept/run/tmacro2.nim create mode 100644 tests/accept/run/tmacro3.nim (limited to 'tests') diff --git a/tests/accept/run/tmacro2.nim b/tests/accept/run/tmacro2.nim new file mode 100644 index 000000000..6aa9bb57d --- /dev/null +++ b/tests/accept/run/tmacro2.nim @@ -0,0 +1,27 @@ +discard """ + output: "ta-da Your value sir: 'HE!!!!o Wor!!d'" +""" + +import macros, strutils + +proc testBlock(): string {.compileTime.} = + block myBlock: + while true: + echo "inner block" + break myBlock + echo "outer block" + result = "ta-da" + +macro mac(n: expr): expr = + expectKind(n, nnkCall) + expectLen(n, 2) + expectKind(n[1], nnkStrLit) + var s: string = n[1].strVal + s = s.replace("l", "!!") + result = newStrLitNode("Your value sir: '$#'" % [s]) + +const s = testBlock() +const t = mac("HEllo World") +echo s, " ", t + + diff --git a/tests/accept/run/tmacro3.nim b/tests/accept/run/tmacro3.nim new file mode 100644 index 000000000..fa2040e92 --- /dev/null +++ b/tests/accept/run/tmacro3.nim @@ -0,0 +1,31 @@ +discard """ + output: "" +""" + +import macros + +type + TA = tuple[a: int] + PA = ref TA + +macro test*(a: stmt): stmt = + var val: PA + new(val) + val.a = 4 + +test: + "hi" + +macro test2*(a: stmt): stmt = + proc testproc(recurse: int) = + echo "Thats weird" + var o : PNimrodNode = nil + echo " no its not!" + o = newNimNode(nnkNone) + if recurse > 0: + testproc(recurse - 1) + testproc(5) + +test2: + "hi" + -- cgit 1.4.1-2-gfad0