aboutsummaryrefslogtreecommitdiff
path: root/spec/outputs/test/continue_spec.lua
diff options
context:
space:
mode:
authorLi Jin <dragon-fly@qq.com>2026-01-30 18:16:45 +0800
committerLi Jin <dragon-fly@qq.com>2026-01-30 18:16:45 +0800
commit8c3d786157ec7fef3072feac55c2d5450800568b (patch)
tree6c44a85e02abe74e6c3ccc4d7393ba8784c49ce7 /spec/outputs/test/continue_spec.lua
parent220a10d0df3341b2bbb0beaee4f90d6480e7ae38 (diff)
downloadyuescript-8c3d786157ec7fef3072feac55c2d5450800568b.tar.gz
yuescript-8c3d786157ec7fef3072feac55c2d5450800568b.tar.bz2
yuescript-8c3d786157ec7fef3072feac55c2d5450800568b.zip
Added more tests.HEADmain
Diffstat (limited to 'spec/outputs/test/continue_spec.lua')
-rw-r--r--spec/outputs/test/continue_spec.lua104
1 files changed, 104 insertions, 0 deletions
diff --git a/spec/outputs/test/continue_spec.lua b/spec/outputs/test/continue_spec.lua
new file mode 100644
index 0000000..8c73aee
--- /dev/null
+++ b/spec/outputs/test/continue_spec.lua
@@ -0,0 +1,104 @@
1return describe("continue statement", function()
2 it("should skip odd numbers in for loop", function()
3 local numbers = {
4 1,
5 2,
6 3,
7 4,
8 5,
9 6,
10 7,
11 8,
12 9,
13 10
14 }
15 local even
16 do
17 local _accum_0 = { }
18 local _len_0 = 1
19 for _index_0 = 1, #numbers do
20 local n = numbers[_index_0]
21 if n % 2 == 1 then
22 goto _continue_0
23 end
24 _accum_0[_len_0] = n
25 _len_0 = _len_0 + 1
26 ::_continue_0::
27 end
28 even = _accum_0
29 end
30 return assert.same(even, {
31 2,
32 4,
33 6,
34 8,
35 10
36 })
37 end)
38 it("should filter values in while loop", function()
39 local i = 0
40 local result = { }
41 while i < 10 do
42 i = i + 1
43 if i % 3 == 0 then
44 goto _continue_0
45 end
46 table.insert(result, i)
47 ::_continue_0::
48 end
49 return assert.same(result, {
50 1,
51 2,
52 4,
53 5,
54 7,
55 8,
56 10
57 })
58 end)
59 it("should skip with condition in loop expression", function()
60 local items = {
61 1,
62 2,
63 3,
64 4,
65 5
66 }
67 local odds
68 do
69 local _accum_0 = { }
70 local _len_0 = 1
71 for _index_0 = 1, #items do
72 local item = items[_index_0]
73 if item % 2 == 0 then
74 goto _continue_0
75 end
76 _accum_0[_len_0] = item
77 _len_0 = _len_0 + 1
78 ::_continue_0::
79 end
80 odds = _accum_0
81 end
82 return assert.same(odds, {
83 1,
84 3,
85 5
86 })
87 end)
88 return it("should work with nested loops", function()
89 local result = { }
90 for i = 1, 5 do
91 for j = 1, 5 do
92 if i == j then
93 goto _continue_0
94 end
95 table.insert(result, {
96 i,
97 j
98 })
99 ::_continue_0::
100 end
101 end
102 return assert.same(#result, 20)
103 end)
104end)