diff options
author | Andreas Rumpf <rumpf_a@web.de> | 2017-03-20 10:56:05 +0100 |
---|---|---|
committer | Andreas Rumpf <rumpf_a@web.de> | 2017-03-20 10:56:15 +0100 |
commit | ca673ab1afb149a2f137a4c3bac06f58a8142066 (patch) | |
tree | e06f109515201b148b76bd86c604736ad47b22af /tests/template | |
parent | a6b0af539be81229e4d4b659f2e831d29c7f17b5 (diff) | |
download | Nim-ca673ab1afb149a2f137a4c3bac06f58a8142066.tar.gz |
add test case for getAst regression
Diffstat (limited to 'tests/template')
-rw-r--r-- | tests/template/tgetast_typeliar.nim | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/tests/template/tgetast_typeliar.nim b/tests/template/tgetast_typeliar.nim new file mode 100644 index 000000000..c9a612582 --- /dev/null +++ b/tests/template/tgetast_typeliar.nim @@ -0,0 +1,23 @@ + +# just ensure this keeps compiling: + +import macros + +proc error(s: string) = quit s + +macro assertOrReturn*(condition: bool; message: string): typed = + var line = condition.lineInfo() + result = quote do: + block: + if not likely(`condition`): + error("Assertion failed: " & $(`message`) & "\n" & `line`) + return + +macro assertOrReturn*(condition: bool): typed = + var message = condition.toStrLit() + result = getAst assertOrReturn(condition, message) + +proc point*(size: int16): tuple[x, y: int16] = + # returns random point in square area with given `size` + + assertOrReturn size > 0 |