mirror of
https://github.com/nim-lang/Nim.git
synced 2026-07-19 15:31:28 +00:00
add test case for getAst regression
This commit is contained in:
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
|
||||
Reference in New Issue
Block a user