twhen_macro.nim 451 B

123456789101112131415161718
  1. import macros
  2. # test that when stmt works from within a macro
  3. macro output(s: string, xs: varargs[untyped]): auto =
  4. result = quote do:
  5. when compiles(`s`):
  6. "when - " & `s`
  7. elif compiles(`s`):
  8. "elif - " & `s`
  9. # should never get here so this should not break
  10. broken.xs
  11. else:
  12. "else - " & `s`
  13. # should never get here so this should not break
  14. more.broken.xs
  15. doAssert output("test") == "when - test"