diff options
Diffstat (limited to 'spec/inputs/test/continue_spec.yue')
| -rw-r--r-- | spec/inputs/test/continue_spec.yue | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/spec/inputs/test/continue_spec.yue b/spec/inputs/test/continue_spec.yue new file mode 100644 index 0000000..bf4e839 --- /dev/null +++ b/spec/inputs/test/continue_spec.yue | |||
| @@ -0,0 +1,37 @@ | |||
| 1 | describe "continue statement", -> | ||
| 2 | it "should skip odd numbers in for loop", -> | ||
| 3 | numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] | ||
| 4 | even = for n in *numbers | ||
| 5 | continue if n % 2 == 1 | ||
| 6 | n | ||
| 7 | |||
| 8 | assert.same even, {2, 4, 6, 8, 10} | ||
| 9 | |||
| 10 | it "should filter values in while loop", -> | ||
| 11 | i = 0 | ||
| 12 | result = [] | ||
| 13 | |||
| 14 | while i < 10 | ||
| 15 | i += 1 | ||
| 16 | continue if i % 3 == 0 | ||
| 17 | table.insert result, i | ||
| 18 | |||
| 19 | assert.same result, {1, 2, 4, 5, 7, 8, 10} | ||
| 20 | |||
| 21 | it "should skip with condition in loop expression", -> | ||
| 22 | items = [1, 2, 3, 4, 5] | ||
| 23 | odds = for item in *items | ||
| 24 | continue if item % 2 == 0 | ||
| 25 | item | ||
| 26 | |||
| 27 | assert.same odds, {1, 3, 5} | ||
| 28 | |||
| 29 | it "should work with nested loops", -> | ||
| 30 | result = [] | ||
| 31 | |||
| 32 | for i = 1, 5 | ||
| 33 | for j = 1, 5 | ||
| 34 | continue if i == j | ||
| 35 | table.insert result, {i, j} | ||
| 36 | |||
| 37 | assert.same #result, 20 | ||
