diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/ccgbugs/tbug1081.nim | 17 | ||||
-rw-r--r-- | tests/macros/tgentemplates.nim | 35 |
2 files changed, 52 insertions, 0 deletions
diff --git a/tests/ccgbugs/tbug1081.nim b/tests/ccgbugs/tbug1081.nim new file mode 100644 index 000000000..71628feec --- /dev/null +++ b/tests/ccgbugs/tbug1081.nim @@ -0,0 +1,17 @@ +discard """ + output: '''1 +0 +0 +0''' +""" + +proc `1/1`() = echo(1 div 1) +template `1/2`() = echo(1 div 2) +var `1/3` = 1 div 4 +`1/3` = 1 div 3 # oops, 1/3!=1/4 +let `1/4` = 1 div 4 + +`1/1`() +`1/2`() +echo `1/3` +echo `1/4` diff --git a/tests/macros/tgentemplates.nim b/tests/macros/tgentemplates.nim new file mode 100644 index 000000000..a7727c597 --- /dev/null +++ b/tests/macros/tgentemplates.nim @@ -0,0 +1,35 @@ +# bug #1140 + +import parseutils, macros + +proc parse_until_symbol(node: PNimrodNode, value: string, index: var int): bool {.compiletime.} = + var splitValue: string + var read = value.parseUntil(splitValue, '$', index) + + # when false: + if false: + var identifier: string + read = value.parseWhile(identifier, {}, index) + node.add newCall("add", ident("result"), newCall("$", ident(identifier))) + + if splitValue.len > 0: + node.insert node.len, newCall("add", ident("result"), newStrLitNode(splitValue)) + +proc parse_template(node: PNimrodNode, value: string) {.compiletime.} = + var index = 0 + while index < value.len and + parse_until_symbol(node, value, index): discard + +macro tmpli*(body: expr): stmt = + result = newStmtList() + result.add parseExpr("result = \"\"") + result.parse_template body[1].strVal + + +proc actual: string = tmpli html""" + <p>Test!</p> + """ + +proc another: string = tmpli html""" + <p>what</p> + """ |