add test case for getAst regression
This commit is contained in:
parent
a6b0af539b
commit
ca673ab1af
1 changed files with 23 additions and 0 deletions
23
tests/template/tgetast_typeliar.nim
Normal file
23
tests/template/tgetast_typeliar.nim
Normal file
|
|
@ -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
|
||||||
Loading…
Add table
Add a link
Reference in a new issue