summary refs log tree commit diff stats
path: root/tests/whenstmt
diff options
context:
(s: string) = + static: + compileOrRuntimeProc(s) + compileOrRuntimeProc(s) + +when compiles(1): + output("when") +elif compiles(2): + output("fail - whenElif") +else: + output("fail - whenElse") + +when compiles(nonexistent): + output("fail - when") +elif compiles(1): + output("whenElif") +else: + output("fail - whenElse") + +when compiles(nonexistent): + output("fail - when") +elif compiles(nonexistent): + output("fail - whenElif") +else: + output("whenElse") + diff --git a/tests/whenstmt/twhen_macro.nim b/tests/whenstmt/twhen_macro.nim new file mode 100644 index 000000000..deb1dddc9 --- /dev/null +++ b/tests/whenstmt/twhen_macro.nim @@ -0,0 +1,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" \ No newline at end of file