diff options
Diffstat (limited to 'tests/template/utemplates.nim')
-rw-r--r-- | tests/template/utemplates.nim | 30 |
1 files changed, 17 insertions, 13 deletions
diff --git a/tests/template/utemplates.nim b/tests/template/utemplates.nim index 8b9ae5d26..d70746578 100644 --- a/tests/template/utemplates.nim +++ b/tests/template/utemplates.nim @@ -1,32 +1,36 @@ import unittest -template t(a: int): expr = "int" -template t(a: string): expr = "string" +template t(a: int): string = "int" +template t(a: string): string = "string" -test "templates can be overloaded": +block: # templates can be overloaded check t(10) == "int" check t("test") == "string" -test "previous definitions can be further overloaded or hidden in local scopes": - template t(a: bool): expr = "bool" +block: # previous definitions can be further overloaded or hidden in local scopes + template t(a: bool): string = "bool" check t(true) == "bool" check t(10) == "int" - template t(a: int): expr = "inner int" + template t(a: int): string = "inner int" check t(10) == "inner int" check t("test") == "string" -test "templates can be redefined multiple times": - template customAssert(cond: bool, msg: string): stmt {.immediate, dirty.} = +block: # templates can be redefined multiple times + template customAssert(cond: bool, msg: string): typed {.dirty.} = if not cond: fail(msg) - template assertion_failed(body: stmt) {.immediate, dirty.} = - template fail(msg: string): stmt = body + template assertionFailed(body: untyped) {.dirty.} = + template fail(msg: string): typed {.redefine.} = + body + + assertionFailed: + check(msg == "first fail path") - assertion_failed: check msg == "first fail path" customAssert false, "first fail path" - assertion_failed: check msg == "second fail path" - customAssert false, "second fail path" + assertionFailed: + check(msg == "second fail path") + customAssert false, "second fail path" |