diff options
Diffstat (limited to 'tests/whenstmt')
-rw-r--r-- | tests/whenstmt/t12517.nim | 21 | ||||
-rw-r--r-- | tests/whenstmt/t19426.nim | 16 | ||||
-rw-r--r-- | tests/whenstmt/twhen_macro.nim | 8 |
3 files changed, 38 insertions, 7 deletions
diff --git a/tests/whenstmt/t12517.nim b/tests/whenstmt/t12517.nim new file mode 100644 index 000000000..8be0171e1 --- /dev/null +++ b/tests/whenstmt/t12517.nim @@ -0,0 +1,21 @@ +# Test based on issue #12517 + +discard """ + nimout: ''' +nimvm +both +''' + output: ''' +both +''' +""" + +proc test() = + when nimvm: + echo "nimvm" + echo "both" + +static: + test() +test() + diff --git a/tests/whenstmt/t19426.nim b/tests/whenstmt/t19426.nim new file mode 100644 index 000000000..95fb54a9e --- /dev/null +++ b/tests/whenstmt/t19426.nim @@ -0,0 +1,16 @@ +type + MyInt = object + bitWidth: int + +template toRealType*(t: MyInt): typedesc = + when t.bitWidth == 32: int32 + elif t.bitWidth == 64: int64 + else: {.error.} + +proc doFail(T: typedesc): T = default(T) + +proc test = + const myInt = MyInt(bitWidth:32) + discard doFail(toRealType(myInt)) + +test() \ No newline at end of file diff --git a/tests/whenstmt/twhen_macro.nim b/tests/whenstmt/twhen_macro.nim index b5168144e..deb1dddc9 100644 --- a/tests/whenstmt/twhen_macro.nim +++ b/tests/whenstmt/twhen_macro.nim @@ -1,11 +1,5 @@ import macros -discard """ - output: ''' -when - test -''' -""" - # test that when stmt works from within a macro macro output(s: string, xs: varargs[untyped]): auto = @@ -21,4 +15,4 @@ macro output(s: string, xs: varargs[untyped]): auto = # should never get here so this should not break more.broken.xs -echo output("test") \ No newline at end of file +doAssert output("test") == "when - test" \ No newline at end of file |