summary refs log tree commit diff stats
path: root/tests/whenstmt/twhen_macro.nim
blob: deb1dddc9c0c72c59ea3ddac42c1a99a1974cb65 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
import macros

# test that when stmt works from within a macro

macro output(s: string, xs: varargs[untyped]): auto =
  result = quote do:
    when compiles(`s`):
      "when - " & `s`
    elif compiles(`s`):
      "elif - " & `s`
      # should never get here so this should not break
      broken.xs
    else:
      "else - " & `s`
      # should never get here so this should not break
      more.broken.xs

doAssert output("test") == "when - test"