diff options
author | Li Jin <dragon-fly@qq.com> | 2022-09-30 11:29:41 +0800 |
---|---|---|
committer | Li Jin <dragon-fly@qq.com> | 2022-09-30 11:29:41 +0800 |
commit | 5aa41b436b3fdf29f5a0046c68cb60b16fa09eb2 (patch) | |
tree | 5c5c0ecdab0d19544652bc05b70d8131e1645337 /spec/outputs/5.1/test | |
parent | a6b6753fda9745f316f3236462b74794b35b85c9 (diff) | |
download | yuescript-5aa41b436b3fdf29f5a0046c68cb60b16fa09eb2.tar.gz yuescript-5aa41b436b3fdf29f5a0046c68cb60b16fa09eb2.tar.bz2 yuescript-5aa41b436b3fdf29f5a0046c68cb60b16fa09eb2.zip |
fix issue #81, refactor continue with gotos.
Diffstat (limited to 'spec/outputs/5.1/test')
-rw-r--r-- | spec/outputs/5.1/test/loops_spec.lua | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/spec/outputs/5.1/test/loops_spec.lua b/spec/outputs/5.1/test/loops_spec.lua new file mode 100644 index 0000000..bad17a6 --- /dev/null +++ b/spec/outputs/5.1/test/loops_spec.lua | |||
@@ -0,0 +1,69 @@ | |||
1 | return describe("loops", function() | ||
2 | it("should continue", function() | ||
3 | local input = { | ||
4 | 1, | ||
5 | 2, | ||
6 | 3, | ||
7 | 4, | ||
8 | 5, | ||
9 | 6 | ||
10 | } | ||
11 | local output | ||
12 | do | ||
13 | local _accum_0 = { } | ||
14 | local _len_0 = 1 | ||
15 | for _index_0 = 1, #input do | ||
16 | local x = input[_index_0] | ||
17 | local _continue_0 = false | ||
18 | repeat | ||
19 | if x % 2 == 1 then | ||
20 | _continue_0 = true | ||
21 | break | ||
22 | end | ||
23 | _accum_0[_len_0] = x | ||
24 | _len_0 = _len_0 + 1 | ||
25 | _continue_0 = true | ||
26 | until true | ||
27 | if not _continue_0 then | ||
28 | break | ||
29 | end | ||
30 | end | ||
31 | output = _accum_0 | ||
32 | end | ||
33 | return assert.same({ | ||
34 | 2, | ||
35 | 4, | ||
36 | 6 | ||
37 | }, output) | ||
38 | end) | ||
39 | return it("continue in repeat", function() | ||
40 | local output = { } | ||
41 | local a = 0 | ||
42 | repeat | ||
43 | local _cond_0 = false | ||
44 | local _continue_0 = false | ||
45 | repeat | ||
46 | a = a + 1 | ||
47 | if a == 3 then | ||
48 | _cond_0 = a == 8 | ||
49 | _continue_0 = true | ||
50 | break | ||
51 | end | ||
52 | if a == 5 then | ||
53 | break | ||
54 | end | ||
55 | output[#output + 1] = a | ||
56 | _cond_0 = a == 8 | ||
57 | _continue_0 = true | ||
58 | until true | ||
59 | if not _continue_0 then | ||
60 | break | ||
61 | end | ||
62 | until _cond_0 | ||
63 | return assert.same({ | ||
64 | 1, | ||
65 | 2, | ||
66 | 4 | ||
67 | }, output) | ||
68 | end) | ||
69 | end) | ||