diff options
| author | Laurenz <laurmaedje@gmail.com> | 2021-02-24 21:29:32 +0100 |
|---|---|---|
| committer | Laurenz <laurmaedje@gmail.com> | 2021-02-24 21:29:32 +0100 |
| commit | f084165eabbb8ad1b8e8969078fce89070ab4d96 (patch) | |
| tree | 6003822cc646ecf0ba6a3070c87ab283503a4c3b /tests/typ/control/while.typ | |
| parent | dae3dad5407e49715736a2a3d8735e65027e6c11 (diff) | |
While loops 🔁
Diffstat (limited to 'tests/typ/control/while.typ')
| -rw-r--r-- | tests/typ/control/while.typ | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/tests/typ/control/while.typ b/tests/typ/control/while.typ new file mode 100644 index 00000000..7ad70372 --- /dev/null +++ b/tests/typ/control/while.typ @@ -0,0 +1,46 @@ +// Test while expressions. + +--- +// Should output `2 4 6 8 10`. +#let i = 0 +#while i < 10 [ + { i += 2 } + #i +] + +// Should output `Hi`. +#let iter = true +#while iter { + iter = false + "Hi." +} + +#while false { + dont-care +} + +--- +// Value of while loops. +// Ref: false +#test(type(while false {}), "template") +#test(type(while false []), "template") + +--- +// Error: 14-19 unknown variable +#let error = error + +// Condition must be boolean. +// Error: 8-14 expected boolean, found template +#while [nope] [nope] + +// Make sure that we don't complain twice. +// Error: 8-15 unknown variable +#while nothing {} + +// A single error stops iteration. +#let i = 0 +#test(error, while i < 10 { + i += 1 + if i < 5 [nope] else { error } +}) +#test(i, 5) |
