From 5aa41b436b3fdf29f5a0046c68cb60b16fa09eb2 Mon Sep 17 00:00:00 2001 From: Li Jin Date: Fri, 30 Sep 2022 11:29:41 +0800 Subject: fix issue #81, refactor continue with gotos. --- spec/outputs/test/loops_spec.lua | 51 ++++++++++++++-------------------------- 1 file changed, 17 insertions(+), 34 deletions(-) (limited to 'spec/outputs/test') diff --git a/spec/outputs/test/loops_spec.lua b/spec/outputs/test/loops_spec.lua index 34f2e9c..9c85e1a 100644 --- a/spec/outputs/test/loops_spec.lua +++ b/spec/outputs/test/loops_spec.lua @@ -14,56 +14,39 @@ return describe("loops", function() local _len_0 = 1 for _index_0 = 1, #input do local x = input[_index_0] - local _continue_0 = false - repeat - if x % 2 == 1 then - _continue_0 = true - break - end - _accum_0[_len_0] = x - _len_0 = _len_0 + 1 - _continue_0 = true - until true - if not _continue_0 then - break + if x % 2 == 1 then + goto _continue_0 end + _accum_0[_len_0] = x + _len_0 = _len_0 + 1 + ::_continue_0:: end output = _accum_0 end - return assert.same(output, { + return assert.same({ 2, 4, 6 - }) + }, output) end) return it("continue in repeat", function() local output = { } local a = 0 repeat - local _cond_0 = false - local _continue_0 = false - repeat - a = a + 1 - if a == 3 then - _cond_0 = a == 8 - _continue_0 = true - break - end - if a == 5 then - break - end - output[#output + 1] = a - _cond_0 = a == 8 - _continue_0 = true - until true - if not _continue_0 then + a = a + 1 + if a == 3 then + goto _continue_0 + end + if a == 5 then break end - until _cond_0 - return assert.same(output, { + output[#output + 1] = a + ::_continue_0:: + until a == 8 + return assert.same({ 1, 2, 4 - }) + }, output) end) end) -- cgit v1.2.3-55-g6feb