diff options
| author | Laurenz <laurmaedje@gmail.com> | 2021-05-18 00:36:11 +0200 |
|---|---|---|
| committer | Laurenz <laurmaedje@gmail.com> | 2021-05-18 00:36:11 +0200 |
| commit | 8b58171d7ca036d71b32749286c251cc91bdd10e (patch) | |
| tree | 4594ab5088edf8eec44f3bafe3fb8fecb13ac61b /tests/typ/code/if.typ | |
| parent | 8d67c0ca5eb3486dde97fd281bd4a51d535c600c (diff) | |
Reorganize test cases
Diffstat (limited to 'tests/typ/code/if.typ')
| -rw-r--r-- | tests/typ/code/if.typ | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/tests/typ/code/if.typ b/tests/typ/code/if.typ new file mode 100644 index 00000000..8d07e9b8 --- /dev/null +++ b/tests/typ/code/if.typ @@ -0,0 +1,71 @@ +// Test if-else expressions. + +--- +// Test condition evaluation. +#if 1 < 2 [ + One. +] + +#if true == false [ + {Bad}, but we {dont-care}! +] + +--- +// Braced condition. +#if {true} [ + One. +] + +// Template in condition. +#if [] != none [ + Two. +] + +// Multi-line condition with parens. +#if ( + 1 + 1 + == 1 +) [ + Nope. +] #else { + "Three." +} + +// Multiline. +#if false [ + Bad. +] #else { + let point = "." + "Four" + point +} + +--- +// Value of if expressions. +// Ref: false +{ + let x = 1 + let y = 2 + let z + + // Returns if branch. + z = if x < y { "ok" } + test(z, "ok") + + // Returns else branch. + z = if x > y { "bad" } else { "ok" } + test(z, "ok") + + // Missing else evaluates to none. + z = if x > y { "bad" } + test(z, none) +} + +--- +// Condition must be boolean. +// If it isn't, neither branch is evaluated. +// Error: 5-14 expected boolean, found string +#if "a" + "b" { nope } #else { nope } + +// Make sure that we don't complain twice. +// Error: 5-12 cannot add integer and string +#if 1 + "2" {} |
