added test case for bug #1140
This commit is contained in:
parent
4055fd4376
commit
fe690a2c91
1 changed files with 35 additions and 0 deletions
35
tests/macros/tgentemplates.nim
Normal file
35
tests/macros/tgentemplates.nim
Normal file
|
|
@ -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>
|
||||
"""
|
||||
Loading…
Add table
Add a link
Reference in a new issue