diff options
Diffstat (limited to 'tests/macros')
-rw-r--r-- | tests/macros/tdebugstmt.nim | 29 | ||||
-rw-r--r-- | tests/macros/tdumpast.nim | 2 | ||||
-rw-r--r-- | tests/macros/tdumpast2.nim | 2 | ||||
-rw-r--r-- | tests/macros/tmacrogenerics.nim | 6 | ||||
-rw-r--r-- | tests/macros/tmacrotypes.nim | 4 | ||||
-rw-r--r-- | tests/macros/tmemit.nim | 2 | ||||
-rw-r--r-- | tests/macros/tstringinterp.nim | 6 |
7 files changed, 41 insertions, 10 deletions
diff --git a/tests/macros/tdebugstmt.nim b/tests/macros/tdebugstmt.nim new file mode 100644 index 000000000..865dc436a --- /dev/null +++ b/tests/macros/tdebugstmt.nim @@ -0,0 +1,29 @@ +discard """ + output: '''a[0]: 42 +a[1]: 45 +x: some string''' +""" + +import macros + +macro debug(n: varargs[expr]): stmt = + # `n` is a Nimrod AST that contains the whole macro invocation + # this macro returns a list of statements: + result = newNimNode(nnkStmtList, n) + # iterate over any argument that is passed to this macro: + for i in 0..n.len-1: + # add a call to the statement list that writes the expression; + # `toStrLit` converts an AST to its string representation: + add(result, newCall("write", newIdentNode("stdout"), toStrLit(n[i]))) + # add a call to the statement list that writes ": " + add(result, newCall("write", newIdentNode("stdout"), newStrLitNode(": "))) + # add a call to the statement list that writes the expressions value: + add(result, newCall("writeln", newIdentNode("stdout"), n[i])) + +var + a: array [0..10, int] + x = "some string" +a[0] = 42 +a[1] = 45 + +debug(a[0], a[1], x) diff --git a/tests/macros/tdumpast.nim b/tests/macros/tdumpast.nim index 55a964327..160e4e194 100644 --- a/tests/macros/tdumpast.nim +++ b/tests/macros/tdumpast.nim @@ -2,7 +2,7 @@ import macros -template plus(a, b: expr): expr = +template plus(a, b: expr): expr {.dirty} = a + b macro call(e: expr): expr = diff --git a/tests/macros/tdumpast2.nim b/tests/macros/tdumpast2.nim index c6eab39a9..2a7024a01 100644 --- a/tests/macros/tdumpast2.nim +++ b/tests/macros/tdumpast2.nim @@ -7,7 +7,7 @@ proc dumpit(n: PNimrodNode): string {.compileTime.} = result = $n.kind add(result, "(") case n.kind - of nnkEmpty: nil # same as nil node in this representation + of nnkEmpty: discard # same as nil node in this representation of nnkNilLit: add(result, "nil") of nnkCharLit..nnkInt64Lit: add(result, $n.intVal) of nnkFloatLit..nnkFloat64Lit: add(result, $n.floatVal) diff --git a/tests/macros/tmacrogenerics.nim b/tests/macros/tmacrogenerics.nim index 5ae59e0da..b886f4fa5 100644 --- a/tests/macros/tmacrogenerics.nim +++ b/tests/macros/tmacrogenerics.nim @@ -1,10 +1,8 @@ discard """ file: "tmacrogenerics.nim" msg: ''' -instantiation 1 with int and float -instantiation 2 with float and string -instantiation 3 with string and string -counter: 3 +instantiation 1 with typedesc and typedesc +counter: 1 ''' output: "int\nfloat\nint\nstring" """ diff --git a/tests/macros/tmacrotypes.nim b/tests/macros/tmacrotypes.nim index 7697dba27..f19aa2ddb 100644 --- a/tests/macros/tmacrotypes.nim +++ b/tests/macros/tmacrotypes.nim @@ -1,3 +1,7 @@ +discard """ + disabled: true +""" + import macros, typetraits macro checkType(ex, expected: expr): stmt {.immediate.} = diff --git a/tests/macros/tmemit.nim b/tests/macros/tmemit.nim index e4bb2daed..6fb2f3b65 100644 --- a/tests/macros/tmemit.nim +++ b/tests/macros/tmemit.nim @@ -1,5 +1,5 @@ discard """ - out: '''HELLO WORLD''' + output: '''HELLO WORLD''' """ import macros, strutils diff --git a/tests/macros/tstringinterp.nim b/tests/macros/tstringinterp.nim index f030213e0..a500ed56e 100644 --- a/tests/macros/tstringinterp.nim +++ b/tests/macros/tstringinterp.nim @@ -9,7 +9,7 @@ proc concat(strings: varargs[string]): string = result = newString(0) for s in items(strings): result.add(s) -template ProcessInterpolations(e: expr) = +template processInterpolations(e: expr) = var s = e[1].strVal for f in interpolatedFragments(s): case f.kind @@ -35,7 +35,7 @@ macro formatStyleInterpolation(e: expr): expr = proc addDollar() = formatString.add("$$") - ProcessInterpolations(e) + processInterpolations(e) result = parseExpr("\"x\" % [y]") result[1].strVal = formatString @@ -50,7 +50,7 @@ macro concatStyleInterpolation(e: expr): expr = proc addExpr(e: PNimrodNode) = args.add(e) proc addDollar() = args.add(newStrLitNode"$") - ProcessInterpolations(e) + processInterpolations(e) result = newCall("concat", args) |