summary refs log tree commit diff stats
path: root/tests/whenstmt/twhen_macro.nim
diff options
context:
space:
mode:
Diffstat (limited to 'tests/whenstmt/twhen_macro.nim')
-rw-r--r--tests/whenstmt/twhen_macro.nim18
1 files changed, 18 insertions, 0 deletions
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