aboutsummaryrefslogtreecommitdiff
path: root/spec/outputs/test/continue_spec.lua
blob: 8c73aee1bd7e81ba0126dd9404dafc9dc0ecfcad (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
return describe("continue statement", function()
	it("should skip odd numbers in for loop", function()
		local numbers = {
			1,
			2,
			3,
			4,
			5,
			6,
			7,
			8,
			9,
			10
		}
		local even
		do
			local _accum_0 = { }
			local _len_0 = 1
			for _index_0 = 1, #numbers do
				local n = numbers[_index_0]
				if n % 2 == 1 then
					goto _continue_0
				end
				_accum_0[_len_0] = n
				_len_0 = _len_0 + 1
				::_continue_0::
			end
			even = _accum_0
		end
		return assert.same(even, {
			2,
			4,
			6,
			8,
			10
		})
	end)
	it("should filter values in while loop", function()
		local i = 0
		local result = { }
		while i < 10 do
			i = i + 1
			if i % 3 == 0 then
				goto _continue_0
			end
			table.insert(result, i)
			::_continue_0::
		end
		return assert.same(result, {
			1,
			2,
			4,
			5,
			7,
			8,
			10
		})
	end)
	it("should skip with condition in loop expression", function()
		local items = {
			1,
			2,
			3,
			4,
			5
		}
		local odds
		do
			local _accum_0 = { }
			local _len_0 = 1
			for _index_0 = 1, #items do
				local item = items[_index_0]
				if item % 2 == 0 then
					goto _continue_0
				end
				_accum_0[_len_0] = item
				_len_0 = _len_0 + 1
				::_continue_0::
			end
			odds = _accum_0
		end
		return assert.same(odds, {
			1,
			3,
			5
		})
	end)
	return it("should work with nested loops", function()
		local result = { }
		for i = 1, 5 do
			for j = 1, 5 do
				if i == j then
					goto _continue_0
				end
				table.insert(result, {
					i,
					j
				})
				::_continue_0::
			end
		end
		return assert.same(#result, 20)
	end)
end)