aboutsummaryrefslogtreecommitdiff
path: root/spec/outputs
diff options
context:
space:
mode:
Diffstat (limited to 'spec/outputs')
-rw-r--r--spec/outputs/5.1/test/attrib_spec.lua86
-rw-r--r--spec/outputs/5.1/test/cond_spec.lua237
-rw-r--r--spec/outputs/5.1/test/existential_spec.lua243
-rw-r--r--spec/outputs/5.1/test/export_spec.lua159
-rw-r--r--spec/outputs/5.1/test/goto_spec.lua103
-rw-r--r--spec/outputs/5.1/test/import_spec.lua196
-rw-r--r--spec/outputs/5.1/test/literals_spec.lua90
-rw-r--r--spec/outputs/5.1/test/macro_spec.lua161
-rw-r--r--spec/outputs/5.1/test/metatable_spec.lua141
-rw-r--r--spec/outputs/5.1/test/operators_spec.lua142
-rw-r--r--spec/outputs/5.1/test/return_spec.lua145
-rw-r--r--spec/outputs/5.1/test/string_spec.lua138
-rw-r--r--spec/outputs/5.1/test/switch_spec.lua743
-rw-r--r--spec/outputs/5.1/test/vararg_spec.lua164
-rw-r--r--spec/outputs/5.1/test/with_spec.lua170
15 files changed, 2918 insertions, 0 deletions
diff --git a/spec/outputs/5.1/test/attrib_spec.lua b/spec/outputs/5.1/test/attrib_spec.lua
new file mode 100644
index 0000000..6fd2287
--- /dev/null
+++ b/spec/outputs/5.1/test/attrib_spec.lua
@@ -0,0 +1,86 @@
1return describe("attrib", function() -- 1
2 it("should support const attribute", function() -- 2
3 do -- 3
4 local x <const> = 10 -- 4
5 return assert.same(x, 10) -- 5
6 end -- 3
7 end) -- 2
8 it("should support const with multiple variables", function() -- 7
9 do -- 8
10 local a <const>, b <const>, c <const> = 1, 2, 3 -- 9
11 assert.same(a, 1) -- 10
12 assert.same(b, 2) -- 11
13 return assert.same(c, 3) -- 12
14 end -- 8
15 end) -- 7
16 it("should support close attribute", function() -- 14
17 do -- 16
18 local x <close> = 1 -- 17
19 return assert.same(x, 1) -- 18
20 end -- 16
21 end) -- 14
22 it("should work with destructuring", function() -- 20
23 do -- 21
24 local a, b -- 22
25 do -- 22
26 local _obj_0 = { -- 22
27 a = 1, -- 22
28 b = 2 -- 22
29 } -- 22
30 a, b = _obj_0[1], _obj_0[2] -- 22
31 end -- 22
32 assert.same(a, 1) -- 23
33 return assert.same(b, 2) -- 24
34 end -- 21
35 end) -- 20
36 it("should work in conditional", function() -- 26
37 do -- 27
38 local flag = true -- 28
39 local x -- 29
40 if flag then -- 29
41 x = 5 -- 29
42 end -- 29
43 return assert.same(x, 5) -- 30
44 end -- 27
45 end) -- 26
46 it("should work with switch", function() -- 32
47 do -- 33
48 local y -- 34
49 do -- 34
50 local _exp_0 = 2 -- 34
51 if 2 == _exp_0 then -- 35
52 y = 100 -- 35
53 else -- 36
54 y = 0 -- 36
55 end -- 34
56 end -- 34
57 return assert.same(y, 100) -- 37
58 end -- 33
59 end) -- 32
60 it("should work with table literals", function() -- 39
61 do -- 40
62 local a, b -- 41
63 do -- 41
64 local _obj_0 = { -- 41
65 1, -- 41
66 2 -- 41
67 } -- 41
68 a, b = _obj_0[1], _obj_0[2] -- 41
69 end -- 41
70 assert.same(a, 1) -- 42
71 return assert.same(b, 2) -- 43
72 end -- 40
73 end) -- 39
74 return it("should support close in expressions", function() -- 45
75 do -- 46
76 local result -- 47
77 if true then -- 47
78 result = 42 -- 48
79 else -- 50
80 result = 0 -- 50
81 end -- 47
82 local _close_0 <close> = result -- 47
83 return assert.same(result, 42) -- 51
84 end -- 46
85 end) -- 45
86end) -- 1
diff --git a/spec/outputs/5.1/test/cond_spec.lua b/spec/outputs/5.1/test/cond_spec.lua
new file mode 100644
index 0000000..c89a1cc
--- /dev/null
+++ b/spec/outputs/5.1/test/cond_spec.lua
@@ -0,0 +1,237 @@
1local _anon_func_0 = function(flag) -- 37
2 if flag then -- 37
3 return 1 -- 37
4 else -- 37
5 return 0 -- 37
6 end -- 37
7end -- 37
8local _anon_func_1 = function() -- 85
9 if nil then -- 85
10 return true -- 85
11 else -- 85
12 return false -- 85
13 end -- 85
14end -- 85
15local _anon_func_2 = function() -- 86
16 if false then -- 86
17 return true -- 86
18 else -- 86
19 return false -- 86
20 end -- 86
21end -- 86
22local _anon_func_3 = function() -- 89
23 if 0 then -- 89
24 return true -- 89
25 else -- 89
26 return false -- 89
27 end -- 89
28end -- 89
29local _anon_func_4 = function() -- 90
30 if "" then -- 90
31 return true -- 90
32 else -- 90
33 return false -- 90
34 end -- 90
35end -- 90
36local _anon_func_5 = function() -- 91
37 if { } then -- 91
38 return true -- 91
39 else -- 91
40 return false -- 91
41 end -- 91
42end -- 91
43local _anon_func_6 = function() -- 92
44 if 1 then -- 92
45 return true -- 92
46 else -- 92
47 return false -- 92
48 end -- 92
49end -- 92
50return describe("cond", function() -- 1
51 it("should execute if branch when condition is true", function() -- 2
52 local result = nil -- 3
53 if true then -- 4
54 result = "yes" -- 5
55 end -- 4
56 return assert.same(result, "yes") -- 6
57 end) -- 2
58 it("should execute else branch when condition is false", function() -- 8
59 local result = nil -- 9
60 if false then -- 10
61 result = "yes" -- 11
62 else -- 13
63 result = "no" -- 13
64 end -- 10
65 return assert.same(result, "no") -- 14
66 end) -- 8
67 it("should support elseif chain", function() -- 16
68 local value = 2 -- 17
69 local result -- 18
70 if 1 == value then -- 19
71 result = "one" -- 19
72 elseif 2 == value then -- 20
73 result = "two" -- 20
74 else -- 21
75 result = "other" -- 21
76 end -- 18
77 return assert.same(result, "two") -- 22
78 end) -- 16
79 it("should handle nested conditions", function() -- 24
80 local result = nil -- 25
81 if true then -- 26
82 if true then -- 27
83 result = "nested" -- 28
84 end -- 27
85 end -- 26
86 return assert.same(result, "nested") -- 29
87 end) -- 24
88 it("should work as expression", function() -- 31
89 local value -- 32
90 if true then -- 32
91 value = "yes" -- 32
92 else -- 32
93 value = "no" -- 32
94 end -- 32
95 return assert.same(value, "yes") -- 33
96 end) -- 31
97 it("should work in string interpolation", function() -- 35
98 local flag = true -- 36
99 local result = "value is " .. tostring(_anon_func_0(flag)) -- 37
100 return assert.same(result, "value is 1") -- 38
101 end) -- 35
102 it("should support chained comparisons", function() -- 40
103 return assert.is_true(1 < 2 and 2 <= 2 and 2 < 3) -- 41
104 end) -- 40
105 it("should short-circuit and expression", function() -- 43
106 local count = 0 -- 44
107 local inc -- 45
108 inc = function() -- 45
109 count = count + 1 -- 46
110 return false -- 47
111 end -- 45
112 local result = inc() and inc() -- 48
113 return assert.same(count, 1) -- 49
114 end) -- 43
115 it("should short-circuit or expression", function() -- 51
116 local count = 0 -- 52
117 local inc -- 53
118 inc = function() -- 53
119 count = count + 1 -- 54
120 return true -- 55
121 end -- 53
122 local result = inc() or inc() -- 56
123 return assert.same(count, 1) -- 57
124 end) -- 51
125 it("should support unless keyword", function() -- 59
126 local result = nil -- 60
127 if not false then -- 61
128 result = "executed" -- 62
129 end -- 61
130 return assert.same(result, "executed") -- 63
131 end) -- 59
132 it("should support unless with else", function() -- 65
133 local result = nil -- 66
134 if not true then -- 67
135 result = "no" -- 68
136 else -- 70
137 result = "yes" -- 70
138 end -- 67
139 return assert.same(result, "yes") -- 71
140 end) -- 65
141 it("should handle postfix if", function() -- 73
142 local result = nil -- 74
143 if true then -- 75
144 result = "yes" -- 75
145 end -- 75
146 return assert.same(result, "yes") -- 76
147 end) -- 73
148 it("should handle postfix unless", function() -- 78
149 local result = nil -- 79
150 if not false then -- 80
151 result = "yes" -- 80
152 end -- 80
153 return assert.same(result, "yes") -- 81
154 end) -- 78
155 it("should evaluate truthiness correctly", function() -- 83
156 assert.is_false(_anon_func_1()) -- 85
157 assert.is_false(_anon_func_2()) -- 86
158 assert.is_true(_anon_func_3()) -- 89
159 assert.is_true(_anon_func_4()) -- 90
160 assert.is_true(_anon_func_5()) -- 91
161 return assert.is_true(_anon_func_6()) -- 92
162 end) -- 83
163 it("should support and/or operators", function() -- 94
164 assert.same(true and false, false) -- 95
165 assert.same(false or true, true) -- 96
166 assert.same(nil or "default", "default") -- 97
167 return assert.same("value" or "default", "value") -- 98
168 end) -- 94
169 it("should handle complex boolean expressions", function() -- 100
170 local a, b, c = true, false, true -- 101
171 local result = a and b or c -- 102
172 return assert.same(result, c) -- 103
173 end) -- 100
174 it("should support not operator", function() -- 105
175 assert.is_true(not false) -- 106
176 assert.is_true(not nil) -- 107
177 assert.is_false(not true) -- 108
178 return assert.is_false(not 1) -- 109
179 end) -- 105
180 it("should work with table as condition", function() -- 111
181 local result = nil -- 112
182 if { } then -- 113
183 result = "truthy" -- 114
184 end -- 113
185 return assert.same(result, "truthy") -- 115
186 end) -- 111
187 it("should work with string as condition", function() -- 117
188 local result = nil -- 118
189 if "" then -- 119
190 result = "truthy" -- 120
191 end -- 119
192 return assert.same(result, "truthy") -- 121
193 end) -- 117
194 it("should work with zero as condition", function() -- 123
195 local result = nil -- 124
196 if 0 then -- 125
197 result = "truthy" -- 126
198 end -- 125
199 return assert.same(result, "truthy") -- 127
200 end) -- 123
201 it("should support multiple elseif branches", function() -- 129
202 local value = 3 -- 130
203 local result -- 131
204 if value == 1 then -- 131
205 result = "one" -- 132
206 elseif value == 2 then -- 133
207 result = "two" -- 134
208 elseif value == 3 then -- 135
209 result = "three" -- 136
210 else -- 138
211 result = "other" -- 138
212 end -- 131
213 return assert.same(result, "three") -- 139
214 end) -- 129
215 it("should handle then keyword syntax", function() -- 141
216 local result -- 142
217 if true then -- 142
218 result = "yes" -- 142
219 else -- 142
220 result = "no" -- 142
221 end -- 142
222 return assert.same(result, "yes") -- 143
223 end) -- 141
224 return it("should work with function call in condition", function() -- 145
225 local return_true -- 146
226 return_true = function() -- 146
227 return true -- 146
228 end -- 146
229 local result -- 147
230 if return_true() then -- 147
231 result = "yes" -- 147
232 else -- 147
233 result = "no" -- 147
234 end -- 147
235 return assert.same(result, "yes") -- 148
236 end) -- 145
237end) -- 1
diff --git a/spec/outputs/5.1/test/existential_spec.lua b/spec/outputs/5.1/test/existential_spec.lua
new file mode 100644
index 0000000..8b8064a
--- /dev/null
+++ b/spec/outputs/5.1/test/existential_spec.lua
@@ -0,0 +1,243 @@
1local _anon_func_0 = function(obj) -- 39
2 if obj ~= nil then -- 39
3 return obj.value -- 39
4 end -- 39
5 return nil -- 39
6end -- 39
7local _anon_func_1 = function(obj) -- 45
8 if obj ~= nil then -- 45
9 return obj.value -- 45
10 end -- 45
11 return nil -- 45
12end -- 45
13local _anon_func_2 = function(obj) -- 50
14 if obj ~= nil then -- 50
15 return obj.x -- 50
16 end -- 50
17 return nil -- 50
18end -- 50
19local _anon_func_3 = function(obj) -- 50
20 if obj ~= nil then -- 50
21 return obj.y -- 50
22 end -- 50
23 return nil -- 50
24end -- 50
25return describe("existential", function() -- 1
26 it("should handle ?. with existing object", function() -- 2
27 local obj = { -- 3
28 value = 42 -- 3
29 } -- 3
30 local result -- 4
31 if obj ~= nil then -- 4
32 result = obj.value -- 4
33 end -- 4
34 return assert.same(result, 42) -- 5
35 end) -- 2
36 it("should handle ?. with nil object", function() -- 7
37 local obj = nil -- 8
38 local result -- 9
39 if obj ~= nil then -- 9
40 result = obj.value -- 9
41 end -- 9
42 return assert.same(result, nil) -- 10
43 end) -- 7
44 it("should chain ?. calls", function() -- 12
45 local obj = { -- 13
46 nested = { -- 13
47 value = 100 -- 13
48 } -- 13
49 } -- 13
50 local result -- 14
51 if obj ~= nil then -- 14
52 do -- 14
53 local _obj_0 = obj.nested -- 14
54 if _obj_0 ~= nil then -- 14
55 result = _obj_0.value -- 14
56 end -- 14
57 end -- 14
58 end -- 14
59 return assert.same(result, 100) -- 15
60 end) -- 12
61 it("should return nil in chain with nil", function() -- 17
62 local obj = nil -- 18
63 local result -- 19
64 if obj ~= nil then -- 19
65 do -- 19
66 local _obj_0 = obj.nested -- 19
67 if _obj_0 ~= nil then -- 19
68 result = _obj_0.value -- 19
69 end -- 19
70 end -- 19
71 end -- 19
72 return assert.same(result, nil) -- 20
73 end) -- 17
74 it("should handle ?. with method call", function() -- 22
75 local obj = { -- 23
76 func = function() -- 23
77 return "result" -- 23
78 end -- 23
79 } -- 23
80 local result -- 24
81 if obj ~= nil then -- 24
82 result = obj.func() -- 24
83 end -- 24
84 return assert.same(result, "result") -- 25
85 end) -- 22
86 it("should handle ? on table index", function() -- 27
87 local tb = { -- 28
88 [1] = "first" -- 28
89 } -- 28
90 local result -- 29
91 if tb ~= nil then -- 29
92 result = tb[1] -- 29
93 end -- 29
94 return assert.same(result, "first") -- 30
95 end) -- 27
96 it("should return nil for missing index", function() -- 32
97 local tb = { } -- 33
98 local result -- 34
99 if tb ~= nil then -- 34
100 result = tb[99] -- 34
101 end -- 34
102 return assert.same(result, nil) -- 35
103 end) -- 32
104 it("should work with ? in if condition", function() -- 37
105 local obj = { -- 38
106 value = 5 -- 38
107 } -- 38
108 if _anon_func_0(obj) then -- 39
109 local result = "exists" -- 40
110 end -- 39
111 return assert.same(result, "exists") -- 41
112 end) -- 37
113 it("should combine ?. with and/or", function() -- 43
114 local obj = { -- 44
115 value = 10 -- 44
116 } -- 44
117 local result = _anon_func_1(obj) and 20 or 30 -- 45
118 return assert.same(result, 20) -- 46
119 end) -- 43
120 it("should handle with? safely", function() -- 48
121 local obj = { -- 49
122 x = 1, -- 49
123 y = 2 -- 49
124 } -- 49
125 local sum = _anon_func_2(obj) + _anon_func_3(obj) -- 50
126 return assert.same(sum, 3) -- 51
127 end) -- 48
128 it("should return nil with with? on nil", function() -- 53
129 local obj = nil -- 54
130 local result -- 55
131 if obj ~= nil then -- 55
132 result = obj.x -- 55
133 end -- 55
134 return assert.same(result, nil) -- 56
135 end) -- 53
136 it("should handle false value correctly", function() -- 58
137 local obj = { -- 60
138 value = false -- 60
139 } -- 60
140 local result -- 61
141 if obj ~= nil then -- 61
142 result = obj.value -- 61
143 end -- 61
144 return assert.same(result, false) -- 62
145 end) -- 58
146 it("should handle 0 value correctly", function() -- 64
147 local obj = { -- 66
148 value = 0 -- 66
149 } -- 66
150 local result -- 67
151 if obj ~= nil then -- 67
152 result = obj.value -- 67
153 end -- 67
154 return assert.same(result, 0) -- 68
155 end) -- 64
156 it("should handle empty string correctly", function() -- 70
157 local obj = { -- 72
158 value = "" -- 72
159 } -- 72
160 local result -- 73
161 if obj ~= nil then -- 73
162 result = obj.value -- 73
163 end -- 73
164 return assert.same(result, "") -- 74
165 end) -- 70
166 it("should handle empty table correctly", function() -- 76
167 local obj = { -- 78
168 value = { } -- 78
169 } -- 78
170 local result -- 79
171 if obj ~= nil then -- 79
172 result = obj.value -- 79
173 end -- 79
174 return assert.same(type(result), "table") -- 80
175 end) -- 76
176 it("should work with deep chains", function() -- 82
177 local obj = { -- 83
178 a = { -- 83
179 b = { -- 83
180 c = { -- 83
181 d = "deep" -- 83
182 } -- 83
183 } -- 83
184 } -- 83
185 } -- 83
186 local result -- 84
187 if obj ~= nil then -- 84
188 do -- 84
189 local _obj_0 = obj.a -- 84
190 if _obj_0 ~= nil then -- 84
191 do -- 84
192 local _obj_1 = _obj_0.b -- 84
193 if _obj_1 ~= nil then -- 84
194 do -- 84
195 local _obj_2 = _obj_1.c -- 84
196 if _obj_2 ~= nil then -- 84
197 result = _obj_2.d -- 84
198 end -- 84
199 end -- 84
200 end -- 84
201 end -- 84
202 end -- 84
203 end -- 84
204 end -- 84
205 return assert.same(result, "deep") -- 85
206 end) -- 82
207 it("should break chain on first nil", function() -- 87
208 local obj = { -- 88
209 a = nil -- 88
210 } -- 88
211 local result -- 89
212 if obj ~= nil then -- 89
213 do -- 89
214 local _obj_0 = obj.a -- 89
215 if _obj_0 ~= nil then -- 89
216 do -- 89
217 local _obj_1 = _obj_0.b -- 89
218 if _obj_1 ~= nil then -- 89
219 result = _obj_1.c -- 89
220 end -- 89
221 end -- 89
222 end -- 89
223 end -- 89
224 end -- 89
225 return assert.same(result, nil) -- 90
226 end) -- 87
227 it("should handle ?. with string methods", function() -- 92
228 local s = "hello" -- 93
229 local result -- 94
230 if s ~= nil then -- 94
231 result = s:upper() -- 94
232 end -- 94
233 return assert.same(result, "HELLO") -- 95
234 end) -- 92
235 return it("should handle ?. with nil string", function() -- 97
236 local s = nil -- 98
237 local result -- 99
238 if s ~= nil then -- 99
239 result = s:upper() -- 99
240 end -- 99
241 return assert.same(result, nil) -- 100
242 end) -- 97
243end) -- 1
diff --git a/spec/outputs/5.1/test/export_spec.lua b/spec/outputs/5.1/test/export_spec.lua
new file mode 100644
index 0000000..f40a298
--- /dev/null
+++ b/spec/outputs/5.1/test/export_spec.lua
@@ -0,0 +1,159 @@
1return describe("export", function() -- 1
2 it("should export basic variables", function() -- 2
3 local a = 1 -- 3
4 local b = 2 -- 4
5 local c = 3 -- 5
6 assert.same(a, 1) -- 6
7 assert.same(b, 2) -- 7
8 return assert.same(c, 3) -- 8
9 end) -- 2
10 it("should export multiple variables at once", function() -- 10
11 local x, y, z = 10, 20, 30 -- 11
12 assert.same(x, 10) -- 12
13 assert.same(y, 20) -- 13
14 return assert.same(z, 30) -- 14
15 end) -- 10
16 it("should export class definitions", function() -- 16
17 local MyClass -- 17
18 do -- 17
19 local _class_0 -- 17
20 local _base_0 = { -- 17
21 value = 100 -- 17
22 } -- 17
23 if _base_0.__index == nil then -- 17
24 _base_0.__index = _base_0 -- 17
25 end -- 17
26 _class_0 = setmetatable({ -- 17
27 __init = function() end, -- 17
28 __base = _base_0, -- 17
29 __name = "MyClass" -- 17
30 }, { -- 17
31 __index = _base_0, -- 17
32 __call = function(cls, ...) -- 17
33 local _self_0 = setmetatable({ }, _base_0) -- 17
34 cls.__init(_self_0, ...) -- 17
35 return _self_0 -- 17
36 end -- 17
37 }) -- 17
38 _base_0.__class = _class_0 -- 17
39 MyClass = _class_0 -- 17
40 end -- 17
41 return assert.same(MyClass.value, 100) -- 19
42 end) -- 16
43 it("should export function expressions", function() -- 21
44 local my_func -- 22
45 my_func = function() -- 22
46 return 42 -- 22
47 end -- 22
48 return assert.same(my_func(), 42) -- 23
49 end) -- 21
50 it("should export conditional expressions", function() -- 25
51 local result -- 26
52 if true then -- 26
53 result = "yes" -- 27
54 else -- 29
55 result = "no" -- 29
56 end -- 26
57 return assert.same(result, "yes") -- 30
58 end) -- 25
59 it("should export switch expressions", function() -- 32
60 local value -- 33
61 do -- 33
62 local _exp_0 = 5 -- 33
63 if 5 == _exp_0 then -- 34
64 value = 100 -- 34
65 else -- 35
66 value = 0 -- 35
67 end -- 33
68 end -- 33
69 return assert.same(value, 100) -- 36
70 end) -- 32
71 it("should export with do block", function() -- 38
72 local result -- 39
73 do -- 39
74 local x = 5 -- 40
75 result = x * 2 -- 41
76 end -- 39
77 return assert.same(result, 10) -- 42
78 end) -- 38
79 it("should export comprehension", function() -- 44
80 local doubled -- 45
81 do -- 45
82 local _accum_0 = { } -- 45
83 local _len_0 = 1 -- 45
84 for i = 1, 5 do -- 45
85 _accum_0[_len_0] = i * 2 -- 45
86 _len_0 = _len_0 + 1 -- 45
87 end -- 45
88 doubled = _accum_0 -- 45
89 end -- 45
90 return assert.same(doubled, { -- 46
91 2, -- 46
92 4, -- 46
93 6, -- 46
94 8, -- 46
95 10 -- 46
96 }) -- 46
97 end) -- 44
98 it("should export with pipe operator", function() -- 48
99 local result = table.concat({ -- 49
100 1, -- 49
101 2, -- 49
102 3 -- 49
103 }) -- 49
104 return assert.same(result, "123") -- 50
105 end) -- 48
106 it("should export nil values", function() -- 52
107 local empty = nil -- 53
108 return assert.same(empty, nil) -- 54
109 end) -- 52
110 it("should export tables", function() -- 56
111 local config = { -- 58
112 key1 = "value1", -- 58
113 key2 = "value2" -- 59
114 } -- 57
115 assert.same(config.key1, "value1") -- 61
116 return assert.same(config.key2, "value2") -- 62
117 end) -- 56
118 it("should export string values", function() -- 64
119 local message = "hello world" -- 65
120 return assert.same(message, "hello world") -- 66
121 end) -- 64
122 it("should export boolean values", function() -- 68
123 local flag_true = true -- 69
124 local flag_false = false -- 70
125 assert.is_true(flag_true) -- 71
126 return assert.is_false(flag_false) -- 72
127 end) -- 68
128 it("should export number values", function() -- 74
129 local count = 42 -- 75
130 local price = 19.99 -- 76
131 assert.same(count, 42) -- 77
132 return assert.same(price, 19.99) -- 78
133 end) -- 74
134 it("should work in nested scope", function() -- 80
135 do -- 81
136 local nested = "value" -- 82
137 end -- 81
138 return assert.same(nested, "value") -- 83
139 end) -- 80
140 it("should export function with parameters", function() -- 85
141 local add -- 86
142 add = function(a, b) -- 86
143 return a + b -- 86
144 end -- 86
145 return assert.same(add(5, 3), 8) -- 87
146 end) -- 85
147 it("should maintain export order", function() -- 89
148 local first = 1 -- 90
149 local second = 2 -- 91
150 local third = 3 -- 92
151 assert.same(first, 1) -- 93
152 assert.same(second, 2) -- 94
153 return assert.same(third, 3) -- 95
154 end) -- 89
155 return it("should work with complex expressions", function() -- 97
156 local calc = (10 + 20) * 2 -- 98
157 return assert.same(calc, 60) -- 99
158 end) -- 97
159end) -- 1
diff --git a/spec/outputs/5.1/test/goto_spec.lua b/spec/outputs/5.1/test/goto_spec.lua
new file mode 100644
index 0000000..e0921c8
--- /dev/null
+++ b/spec/outputs/5.1/test/goto_spec.lua
@@ -0,0 +1,103 @@
1return describe("goto", function() -- 1
2 it("should support basic goto and label", function() -- 2
3 local a = 0 -- 3
4 ::start:: -- 4
5 a = a + 1 -- 5
6 if a < 5 then -- 6
7 goto start -- 7
8 end -- 6
9 return assert.same(a, 5) -- 8
10 end) -- 2
11 it("should support conditional goto", function() -- 10
12 local a = 0 -- 11
13 ::loop:: -- 12
14 a = a + 1 -- 13
15 if a == 3 then -- 14
16 goto done -- 14
17 end -- 14
18 goto loop -- 15
19 ::done:: -- 16
20 return assert.same(a, 3) -- 17
21 end) -- 10
22 it("should support goto in nested loops", function() -- 19
23 local count = 0 -- 20
24 for x = 1, 3 do -- 21
25 for y = 1, 3 do -- 22
26 count = count + 1 -- 23
27 if x == 2 and y == 2 then -- 24
28 goto found -- 25
29 end -- 24
30 end -- 22
31 end -- 21
32 ::found:: -- 26
33 return assert.same(count, 4) -- 27
34 end) -- 19
35 it("should support multiple labels", function() -- 29
36 local a = 0 -- 30
37 ::first:: -- 31
38 a = a + 1 -- 32
39 if a == 2 then -- 33
40 goto second -- 33
41 end -- 33
42 goto first -- 34
43 ::second:: -- 35
44 return assert.same(a, 2) -- 36
45 end) -- 29
46 it("should work with for loops", function() -- 38
47 local sum = 0 -- 39
48 for i = 1, 10 do -- 40
49 sum = sum + i -- 41
50 if i == 5 then -- 42
51 goto done -- 42
52 end -- 42
53 end -- 40
54 ::done:: -- 43
55 return assert.same(sum, 15) -- 44
56 end) -- 38
57 it("should work with while loops", function() -- 46
58 local count = 0 -- 47
59 while true do -- 48
60 count = count + 1 -- 49
61 if count == 3 then -- 50
62 goto endwhile -- 50
63 end -- 50
64 end -- 48
65 ::endwhile:: -- 51
66 return assert.same(count, 3) -- 52
67 end) -- 46
68 it("should skip rest of loop with goto", function() -- 54
69 local values = { } -- 55
70 for i = 1, 5 do -- 56
71 if i % 2 == 0 then -- 57
72 goto continue -- 57
73 end -- 57
74 table.insert(values, i) -- 58
75 ::continue:: -- 59
76 end -- 56
77 return assert.same(values, { -- 60
78 1, -- 60
79 3, -- 60
80 5 -- 60
81 }) -- 60
82 end) -- 54
83 return it("should support goto with switch", function() -- 62
84 local result = "default" -- 63
85 local value = 2 -- 64
86 if 1 == value then -- 66
87 goto case_one -- 67
88 elseif 2 == value then -- 68
89 goto case_two -- 69
90 end -- 65
91 goto default_label -- 70
92 ::case_one:: -- 71
93 result = "one" -- 72
94 goto finish -- 73
95 ::case_two:: -- 74
96 result = "two" -- 75
97 goto finish -- 76
98 ::default_label:: -- 77
99 result = "default" -- 78
100 ::finish:: -- 79
101 return assert.same(result, "two") -- 80
102 end) -- 62
103end) -- 1
diff --git a/spec/outputs/5.1/test/import_spec.lua b/spec/outputs/5.1/test/import_spec.lua
new file mode 100644
index 0000000..f77ef04
--- /dev/null
+++ b/spec/outputs/5.1/test/import_spec.lua
@@ -0,0 +1,196 @@
1return describe("import", function() -- 1
2 it("should import from table expression", function() -- 2
3 local source = { -- 3
4 hello = "world", -- 3
5 foo = "bar" -- 3
6 } -- 3
7 local hello, foo = source.hello, source.foo -- 4
8 assert.same(hello, "world") -- 5
9 return assert.same(foo, "bar") -- 6
10 end) -- 2
11 it("should import with backslash escaping", function() -- 8
12 local source = { -- 9
13 x = 1, -- 9
14 y = 2, -- 9
15 z = 3 -- 9
16 } -- 9
17 local x, y, z = source.x, (function() -- 10
18 local _base_0 = source -- 10
19 local _fn_0 = _base_0.y -- 10
20 return _fn_0 and function(...) -- 10
21 return _fn_0(_base_0, ...) -- 10
22 end -- 10
23 end)(), source.z -- 10
24 assert.same(x, 1) -- 11
25 assert.same(y, 2) -- 12
26 return assert.same(z, 3) -- 13
27 end) -- 8
28 it("should import from string module", function() -- 15
29 local format -- 17
30 do -- 17
31 local _obj_0 = require("string") -- 17
32 format = _obj_0.format -- 17
33 end -- 17
34 return assert.is_true(type(format) == "function") -- 18
35 end) -- 15
36 it("should import from table with dot path", function() -- 20
37 local sub -- 22
38 do -- 22
39 local _obj_0 = require("string") -- 22
40 sub = _obj_0.sub -- 22
41 end -- 22
42 local result = sub("hello", 1, 2) -- 23
43 return assert.same(result, "he") -- 24
44 end) -- 20
45 it("should import multiple values with table destructuring", function() -- 26
46 local source = { -- 27
47 a = 1, -- 27
48 b = 2, -- 27
49 c = 3 -- 27
50 } -- 27
51 local a, b, c = source.a, source.b, source.c -- 28
52 assert.same(a, 1) -- 29
53 assert.same(b, 2) -- 30
54 return assert.same(c, 3) -- 31
55 end) -- 26
56 it("should import with multi-line format", function() -- 33
57 local source = { -- 34
58 x = 1, -- 34
59 y = 2, -- 34
60 z = 3 -- 34
61 } -- 34
62 local x, y, z = source.x, source.y, source.z -- 35
63 assert.same(x, 1) -- 36
64 assert.same(y, 2) -- 37
65 return assert.same(z, 3) -- 38
66 end) -- 33
67 it("should import using from syntax", function() -- 40
68 local source = { -- 41
69 foo = "bar", -- 41
70 baz = "qux" -- 41
71 } -- 41
72 local foo, baz = source.foo, source.baz -- 42
73 assert.same(foo, "bar") -- 43
74 return assert.same(baz, "qux") -- 44
75 end) -- 40
76 it("should handle import with computed expressions", function() -- 46
77 local source = { -- 47
78 first = 1, -- 47
79 second = 2 -- 47
80 } -- 47
81 local target = source -- 48
82 local first, second = target.first, target.second -- 49
83 assert.same(first, 1) -- 50
84 return assert.same(second, 2) -- 51
85 end) -- 46
86 it("should import from nested table paths", function() -- 53
87 local deep = { -- 54
88 outer = { -- 54
89 inner = "value" -- 54
90 } -- 54
91 } -- 54
92 local outer = deep.outer -- 55
93 return assert.same(outer.inner, "value") -- 56
94 end) -- 53
95 it("should support importing Lua standard library functions", function() -- 58
96 local print, type -- 59
97 do -- 59
98 local _obj_0 = require("_G") -- 59
99 print, type = _obj_0.print, _obj_0.type -- 59
100 end -- 59
101 assert.is_true(type(print) == "function") -- 60
102 return assert.is_true(type(type) == "function") -- 61
103 end) -- 58
104 it("should handle empty import gracefully", function() -- 63
105 local source = { } -- 65
106 local dummy = source.dummy -- 66
107 return assert.same(dummy, nil) -- 67
108 end) -- 63
109 it("should work with table index expressions", function() -- 69
110 local source = { -- 70
111 normal = "ok" -- 70
112 } -- 70
113 local normal = source.normal -- 71
114 return assert.same(normal, "ok") -- 72
115 end) -- 69
116 it("should support chaining imports from same source", function() -- 74
117 local source = { -- 75
118 a = 1, -- 75
119 b = 2, -- 75
120 c = 3 -- 75
121 } -- 75
122 local a, b = source.a, source.b -- 76
123 local c = source.c -- 77
124 assert.same(a, 1) -- 78
125 assert.same(b, 2) -- 79
126 return assert.same(c, 3) -- 80
127 end) -- 74
128 it("should handle importing from table returned by function", function() -- 82
129 local get_table -- 83
130 get_table = function() -- 83
131 return { -- 83
132 x = 100, -- 83
133 y = 200 -- 83
134 } -- 83
135 end -- 83
136 local x, y -- 84
137 do -- 84
138 local _obj_0 = get_table() -- 84
139 x, y = _obj_0.x, _obj_0.y -- 84
140 end -- 84
141 assert.same(x, 100) -- 85
142 return assert.same(y, 200) -- 86
143 end) -- 82
144 it("should support from with multi-line import", function() -- 88
145 local source = { -- 89
146 item1 = 1, -- 89
147 item2 = 2, -- 89
148 item3 = 3 -- 89
149 } -- 89
150 local item1, item2, item3 = source.item1, source.item2, source.item3 -- 90
151 assert.same(item1, 1) -- 91
152 assert.same(item2, 2) -- 92
153 return assert.same(item3, 3) -- 93
154 end) -- 88
155 it("should work with import from string literal", function() -- 95
156 local char -- 96
157 do -- 96
158 local _obj_0 = require("string") -- 96
159 char = _obj_0.char -- 96
160 end -- 96
161 return assert.same(char(65), "A") -- 97
162 end) -- 95
163 it("should support import with table literal keys", function() -- 99
164 local source = { -- 100
165 normal_key = "value2" -- 100
166 } -- 100
167 local normal_key = source.normal_key -- 101
168 return assert.same(normal_key, "value2") -- 102
169 end) -- 99
170 it("should handle consecutive imports", function() -- 104
171 local source1 = { -- 105
172 a = 1 -- 105
173 } -- 105
174 local source2 = { -- 106
175 b = 2 -- 106
176 } -- 106
177 local a = source1.a -- 107
178 local b = source2.b -- 108
179 assert.same(a, 1) -- 109
180 return assert.same(b, 2) -- 110
181 end) -- 104
182 return it("should support importing from complex expressions", function() -- 112
183 local get_source -- 113
184 get_source = function() -- 113
185 return { -- 113
186 result = 42 -- 113
187 } -- 113
188 end -- 113
189 local result -- 114
190 do -- 114
191 local _obj_0 = get_source() -- 114
192 result = _obj_0.result -- 114
193 end -- 114
194 return assert.same(result, 42) -- 115
195 end) -- 112
196end) -- 1
diff --git a/spec/outputs/5.1/test/literals_spec.lua b/spec/outputs/5.1/test/literals_spec.lua
new file mode 100644
index 0000000..3bbfb37
--- /dev/null
+++ b/spec/outputs/5.1/test/literals_spec.lua
@@ -0,0 +1,90 @@
1return describe("literals", function() -- 1
2 it("should support integer literals", function() -- 2
3 return assert.same(123, 123) -- 3
4 end) -- 2
5 it("should support float literals", function() -- 5
6 return assert.same(1.5, 1.5) -- 6
7 end) -- 5
8 it("should support scientific notation", function() -- 8
9 return assert.same(1.5e2, 150) -- 9
10 end) -- 8
11 it("should support negative numbers", function() -- 11
12 return assert.same(-42, -42) -- 12
13 end) -- 11
14 it("should support hexadecimal literals", function() -- 14
15 return assert.same(0xff, 255) -- 15
16 end) -- 14
17 it("should support hexadecimal with uppercase", function() -- 17
18 return assert.same(0XFF, 255) -- 18
19 end) -- 17
20 it("should support binary literals", function() -- 20
21 return assert.same(5, 5) -- 21
22 end) -- 20
23 it("should support binary with uppercase", function() -- 23
24 return assert.same(5, 5) -- 24
25 end) -- 23
26 it("should support number with underscores", function() -- 26
27 return assert.same(1000000, 1000000) -- 27
28 end) -- 26
29 it("should support hex with underscores", function() -- 29
30 return assert.same(0xDEADBEEF, 0xDEADBEEF) -- 30
31 end) -- 29
32 it("should support double quote strings", function() -- 32
33 return assert.same("hello", "hello") -- 33
34 end) -- 32
35 it("should support single quote strings", function() -- 35
36 return assert.same('world', 'world') -- 36
37 end) -- 35
38 it("should support multi-line strings with [[", function() -- 38
39 local s = [[ hello
40 world
41 ]] -- 39
42 return assert.is_true(s:match("hello")) -- 43
43 end) -- 38
44 it("should support multi-line strings with [=[", function() -- 45
45 local s = [==[ test
46 ]==] -- 46
47 return assert.is_true(s:match("test")) -- 49
48 end) -- 45
49 it("should support boolean true", function() -- 51
50 return assert.same(true, true) -- 52
51 end) -- 51
52 it("should support boolean false", function() -- 54
53 return assert.same(false, false) -- 55
54 end) -- 54
55 it("should support nil", function() -- 57
56 return assert.same(nil, nil) -- 58
57 end) -- 57
58 it("should support empty table", function() -- 60
59 local t = { } -- 61
60 return assert.same(#t, 0) -- 62
61 end) -- 60
62 it("should support table with keys", function() -- 64
63 local t = { -- 65
64 a = 1, -- 65
65 b = 2 -- 65
66 } -- 65
67 assert.same(t.a, 1) -- 66
68 return assert.same(t.b, 2) -- 67
69 end) -- 64
70 it("should support array literal", function() -- 69
71 local t = { -- 70
72 1, -- 70
73 2, -- 70
74 3 -- 70
75 } -- 70
76 assert.same(t[1], 1) -- 71
77 assert.same(t[2], 2) -- 72
78 return assert.same(t[3], 3) -- 73
79 end) -- 69
80 return it("should support mixed table", function() -- 75
81 local t = { -- 77
82 1, -- 77
83 2, -- 77
84 3, -- 77
85 key = "value" -- 78
86 } -- 76
87 assert.same(t[1], 1) -- 80
88 return assert.same(t.key, "value") -- 81
89 end) -- 75
90end) -- 1
diff --git a/spec/outputs/5.1/test/macro_spec.lua b/spec/outputs/5.1/test/macro_spec.lua
new file mode 100644
index 0000000..3d60580
--- /dev/null
+++ b/spec/outputs/5.1/test/macro_spec.lua
@@ -0,0 +1,161 @@
1return describe("macro", function() -- 1
2 it("should define and call basic macro", function() -- 2
3 local result = (5 * 2) -- 4
4 return assert.same(result, 10) -- 5
5 end) -- 2
6 it("should maintain hygiene in macros", function() -- 7
7 local a = 8 -- 12
8 local result = 2 -- 13
9 return assert.same(result, 2) -- 14
10 end) -- 7
11 it("should validate AST types", function() -- 16
12 local result = { -- 18
13 123, -- 18
14 'xyz' -- 18
15 } -- 18
16 return assert.same(result, "[123, xyz]") -- 19
17 end) -- 16
18 it("should support simple code generation", function() -- 21
19 local result = (10 + 1) -- 23
20 return assert.same(result, 11) -- 24
21 end) -- 21
22 it("should support nested macro calls", function() -- 26
23 local result = 7 -- 29
24 return assert.same(result, 7) -- 30
25 end) -- 26
26 it("should respect macro scope in do blocks", function() -- 32
27 do -- 34
28 local result = inner -- 36
29 assert.same(result, "inner") -- 37
30 end -- 34
31 local result = outer -- 38
32 return assert.same(result, "outer") -- 39
33 end) -- 32
34 it("should provide $LINE macro", function() -- 41
35 local line_num = 42 -- 42
36 return assert.is_true(line_num > 0) -- 43
37 end) -- 41
38 it("should inject Lua code", function() -- 45
39 local x = 0 -- 47
40 do -- 48
41local function f(a)
42 return a + 1
43 end
44 x = x + f(3)
45 end -- 48
46 return assert.same(x, 4) -- 54
47 end) -- 45
48 it("should work in conditional compilation", function() -- 56
49 local result = "debug mode" -- 62
50 return assert.same(result, "debug mode") -- 63
51 end) -- 56
52 it("should work with class system", function() -- 65
53 local Thing -- 66
54 do -- 66
55 local _class_0 -- 66
56 local _base_0 = { -- 66
57 value = 100, -- 68
58 get_value = function(self) -- 68
59 return self.value -- 68
60 end -- 66
61 } -- 66
62 if _base_0.__index == nil then -- 66
63 _base_0.__index = _base_0 -- 66
64 end -- 66
65 _class_0 = setmetatable({ -- 66
66 __init = function() end, -- 66
67 __base = _base_0, -- 66
68 __name = "Thing" -- 66
69 }, { -- 66
70 __index = _base_0, -- 66
71 __call = function(cls, ...) -- 66
72 local _self_0 = setmetatable({ }, _base_0) -- 66
73 cls.__init(_self_0, ...) -- 66
74 return _self_0 -- 66
75 end -- 66
76 }) -- 66
77 _base_0.__class = _class_0 -- 66
78 Thing = _class_0 -- 66
79 end -- 66
80 local instance = Thing() -- 69
81 return assert.same(instance:get_value(), 100) -- 70
82 end) -- 65
83 it("should handle macro in switch expressions", function() -- 72
84 local result -- 74
85 do -- 74
86 local _exp_0 = "test" -- 74
87 if "test" == _exp_0 then -- 75
88 result = "matched" -- 76
89 else -- 78
90 result = "no match" -- 78
91 end -- 74
92 end -- 74
93 return assert.same(result, "matched") -- 79
94 end) -- 72
95 it("should support macro in expression context", function() -- 81
96 local result = 5 + (2 * 3) -- 83
97 return assert.same(result, 11) -- 84
98 end) -- 81
99 it("should handle $is_ast for type checking", function() -- 86
100 local result = 42 -- 91
101 return assert.same(result, 42) -- 92
102 end) -- 86
103 it("should work with string interpolation", function() -- 94
104 local result = { -- 96
105 ["test"] = 123 -- 96
106 } -- 96
107 return assert.same(result, "test: 123") -- 97
108 end) -- 94
109 it("should support function call syntax", function() -- 99
110 local result = (5 + 10) -- 101
111 return assert.same(result, 15) -- 102
112 end) -- 99
113 it("should handle empty macro return", function() -- 104
114 local a = 1 -- 106
115 a = 2 -- 108
116 return assert.same(a, 2) -- 109
117 end) -- 104
118 it("should work with table literals", function() -- 111
119 local point = { -- 113
120 x = 10, -- 113
121 y = 20 -- 113
122 } -- 113
123 assert.same(point.x, 10) -- 114
124 return assert.same(point.y, 20) -- 115
125 end) -- 111
126 it("should support conditional expressions in macro", function() -- 117
127 local result = (5 + 1) -- 119
128 return assert.same(result, 6) -- 120
129 end) -- 117
130 it("should work with comprehension", function() -- 122
131 local result -- 124
132 do -- 124
133 local _accum_0 = { } -- 124
134 local _len_0 = 1 -- 124
135 local _list_0 = { -- 124
136 1, -- 124
137 2, -- 124
138 3 -- 124
139 } -- 124
140 for _index_0 = 1, #_list_0 do -- 124
141 local _ = _list_0[_index_0] -- 124
142 _accum_0[_len_0] = _ * 2 -- 124
143 _len_0 = _len_0 + 1 -- 124
144 end -- 124
145 result = _accum_0 -- 124
146 end -- 124
147 return assert.same(result, { -- 125
148 2, -- 125
149 4, -- 125
150 6 -- 125
151 }) -- 125
152 end) -- 122
153 it("should support complex expression macros", function() -- 127
154 local result = (1 + 2 * 3) -- 129
155 return assert.same(result, 7) -- 130
156 end) -- 127
157 return it("should work with string literals", function() -- 132
158 local result = "Hello, " .. tostring(name) -- 134
159 return assert.same(result, "Hello, World") -- 135
160 end) -- 132
161end) -- 1
diff --git a/spec/outputs/5.1/test/metatable_spec.lua b/spec/outputs/5.1/test/metatable_spec.lua
new file mode 100644
index 0000000..8088b0c
--- /dev/null
+++ b/spec/outputs/5.1/test/metatable_spec.lua
@@ -0,0 +1,141 @@
1return describe("metatable", function() -- 1
2 it("should get metatable with <> syntax", function() -- 2
3 local obj = setmetatable({ -- 3
4 value = 42 -- 3
5 }, { -- 3
6 __index = { -- 3
7 extra = "data" -- 3
8 } -- 3
9 }) -- 3
10 local mt = getmetatable(obj) -- 4
11 return assert.is_true(mt ~= nil) -- 5
12 end) -- 2
13 it("should set metatable with <>", function() -- 7
14 local obj = { } -- 8
15 setmetatable(obj, { -- 9
16 __index = { -- 9
17 value = 100 -- 9
18 } -- 9
19 }) -- 9
20 return assert.same(obj.value, 100) -- 10
21 end) -- 7
22 it("should access metatable with <>", function() -- 12
23 local obj = setmetatable({ }, { -- 13
24 __index = { -- 13
25 value = 50 -- 13
26 } -- 13
27 }) -- 13
28 local result = getmetatable(obj).__index.value -- 14
29 return assert.same(result, 50) -- 15
30 end) -- 12
31 it("should work with <index> metamethod", function() -- 17
32 local obj = setmetatable({ }, { -- 19
33 __index = function(self, key) -- 19
34 if key == "computed" then -- 20
35 return "computed_value" -- 21
36 end -- 20
37 end -- 19
38 }) -- 18
39 return assert.same(obj.computed, "computed_value") -- 23
40 end) -- 17
41 it("should work with <newindex> metamethod", function() -- 25
42 local obj = setmetatable({ }, { -- 27
43 __newindex = function(self, key, value) -- 27
44 return rawset(self, "stored_" .. key, value) -- 28
45 end -- 27
46 }) -- 26
47 obj.test = 123 -- 30
48 return assert.same(obj.stored_test, 123) -- 31
49 end) -- 25
50 it("should work with <add> metamethod", function() -- 33
51 local obj = setmetatable({ -- 34
52 value = 10 -- 34
53 }, { -- 35
54 __add = function(a, b) -- 35
55 return a.value + b.value -- 35
56 end -- 35
57 }) -- 34
58 local obj2 = setmetatable({ -- 37
59 value = 20 -- 37
60 }, { -- 38
61 __add = function(a, b) -- 38
62 return a.value + b.value -- 38
63 end -- 38
64 }) -- 37
65 local result = obj + obj2 -- 40
66 return assert.same(result, 30) -- 41
67 end) -- 33
68 it("should work with <call> metamethod", function() -- 43
69 local obj = setmetatable({ }, { -- 45
70 __call = function(self, x) -- 45
71 return x * 2 -- 45
72 end -- 45
73 }) -- 44
74 local result = obj(5) -- 47
75 return assert.same(result, 10) -- 48
76 end) -- 43
77 it("should work with <tostring> metamethod", function() -- 50
78 local obj = setmetatable({ -- 51
79 value = 42 -- 51
80 }, { -- 52
81 __tostring = function(self) -- 52
82 return "Value: " .. tostring(self.value) -- 52
83 end -- 52
84 }) -- 51
85 local result = tostring(obj) -- 54
86 return assert.same(result, "Value: 42") -- 55
87 end) -- 50
88 it("should work with <eq> metamethod", function() -- 57
89 local obj1 = setmetatable({ -- 58
90 id = 1 -- 58
91 }, { -- 59
92 __eq = function(a, b) -- 59
93 return a.id == b.id -- 59
94 end -- 59
95 }) -- 58
96 local obj2 = setmetatable({ -- 61
97 id = 1 -- 61
98 }, { -- 62
99 __eq = function(a, b) -- 62
100 return a.id == b.id -- 62
101 end -- 62
102 }) -- 61
103 return assert.is_true(obj1 == obj2) -- 64
104 end) -- 57
105 it("should destructure metatable", function() -- 66
106 local obj = setmetatable({ }, { -- 68
107 new = function() -- 68
108 return "new result" -- 68
109 end, -- 68
110 update = function() -- 69
111 return "update result" -- 69
112 end -- 69
113 }) -- 67
114 local new, update -- 71
115 do -- 71
116 local _obj_0 = getmetatable(obj) -- 71
117 new, update = _obj_0.new, _obj_0.update -- 71
118 end -- 71
119 assert.is_true(type(new) == "function") -- 72
120 return assert.is_true(type(update) == "function") -- 73
121 end) -- 66
122 it("should check if two objects have same metatable", function() -- 75
123 local mt = { -- 76
124 value = 100 -- 76
125 } -- 76
126 local obj1 = setmetatable({ }, mt) -- 77
127 local obj2 = setmetatable({ }, mt) -- 78
128 return assert.is_true(getmetatable(obj1) == getmetatable(obj2)) -- 79
129 end) -- 75
130 return it("should work with <concat> metamethod", function() -- 81
131 local obj = setmetatable({ -- 82
132 value = "hello" -- 82
133 }, { -- 83
134 __concat = function(a, b) -- 83
135 return a.value .. b -- 83
136 end -- 83
137 }) -- 82
138 local result = obj .. " world" -- 85
139 return assert.same(result, "hello world") -- 86
140 end) -- 81
141end) -- 1
diff --git a/spec/outputs/5.1/test/operators_spec.lua b/spec/outputs/5.1/test/operators_spec.lua
new file mode 100644
index 0000000..661c422
--- /dev/null
+++ b/spec/outputs/5.1/test/operators_spec.lua
@@ -0,0 +1,142 @@
1return describe("operators", function() -- 1
2 it("should support addition", function() -- 2
3 return assert.same(1 + 2, 3) -- 3
4 end) -- 2
5 it("should support subtraction", function() -- 5
6 return assert.same(5 - 3, 2) -- 6
7 end) -- 5
8 it("should support multiplication", function() -- 8
9 return assert.same(4 * 3, 12) -- 9
10 end) -- 8
11 it("should support division", function() -- 11
12 return assert.same(10 / 2, 5) -- 12
13 end) -- 11
14 it("should support modulo", function() -- 14
15 return assert.same(10 % 3, 1) -- 15
16 end) -- 14
17 it("should support exponentiation", function() -- 17
18 return assert.same(2 ^ 3, 8) -- 18
19 end) -- 17
20 it("should support unary minus", function() -- 20
21 return assert.same(-5, -5) -- 21
22 end) -- 20
23 it("should support equality comparison", function() -- 23
24 assert.is_true(1 == 1) -- 24
25 return assert.is_false(1 == 2) -- 25
26 end) -- 23
27 it("should support inequality comparison", function() -- 27
28 assert.is_true(1 ~= 2) -- 28
29 return assert.is_false(1 ~= 1) -- 29
30 end) -- 27
31 it("should support less than", function() -- 31
32 assert.is_true(1 < 2) -- 32
33 return assert.is_false(2 < 1) -- 33
34 end) -- 31
35 it("should support greater than", function() -- 35
36 assert.is_true(2 > 1) -- 36
37 return assert.is_false(1 > 2) -- 37
38 end) -- 35
39 it("should support less than or equal", function() -- 39
40 assert.is_true(1 <= 2) -- 40
41 assert.is_true(2 <= 2) -- 41
42 return assert.is_false(3 <= 2) -- 42
43 end) -- 39
44 it("should support greater than or equal", function() -- 44
45 assert.is_true(2 >= 1) -- 45
46 assert.is_true(2 >= 2) -- 46
47 return assert.is_false(1 >= 2) -- 47
48 end) -- 44
49 it("should support logical and", function() -- 49
50 assert.same(true and false, false) -- 50
51 assert.same(true and true, true) -- 51
52 return assert.same(false and true, false) -- 52
53 end) -- 49
54 it("should support logical or", function() -- 54
55 assert.same(true or false, true) -- 55
56 assert.same(false or true, true) -- 56
57 return assert.same(false or false, false) -- 57
58 end) -- 54
59 it("should support logical not", function() -- 59
60 assert.same(not true, false) -- 60
61 assert.same(not false, true) -- 61
62 return assert.same(not nil, true) -- 62
63 end) -- 59
64 it("should support bitwise and", function() -- 64
65 return assert.same(5 & 3, 1) -- 65
66 end) -- 64
67 it("should support bitwise or", function() -- 67
68 return assert.same(5 | 3, 7) -- 68
69 end) -- 67
70 it("should support bitwise xor", function() -- 70
71 return assert.same(5 ~ 3, 6) -- 71
72 end) -- 70
73 it("should support left shift", function() -- 73
74 return assert.same(2 << 3, 16) -- 74
75 end) -- 73
76 it("should support right shift", function() -- 76
77 return assert.same(16 >> 2, 4) -- 77
78 end) -- 76
79 it("should support string concatenation", function() -- 79
80 return assert.same("hello" .. " world", "hello world") -- 80
81 end) -- 79
82 it("should support length operator", function() -- 82
83 assert.same(#"hello", 5) -- 83
84 return assert.same(#{ -- 84
85 1, -- 84
86 2, -- 84
87 3 -- 84
88 }, 3) -- 84
89 end) -- 82
90 it("should respect operator precedence", function() -- 86
91 assert.same(1 + 2 * 3, 7) -- 87
92 return assert.same((1 + 2) * 3, 9) -- 88
93 end) -- 86
94 it("should support compound assignment", function() -- 90
95 local x = 10 -- 91
96 x = x + 5 -- 92
97 return assert.same(x, 15) -- 93
98 end) -- 90
99 it("should support compound subtraction", function() -- 95
100 local x = 10 -- 96
101 x = x - 3 -- 97
102 return assert.same(x, 7) -- 98
103 end) -- 95
104 it("should support compound multiplication", function() -- 100
105 local x = 5 -- 101
106 x = x * 2 -- 102
107 return assert.same(x, 10) -- 103
108 end) -- 100
109 it("should support compound division", function() -- 105
110 local x = 20 -- 106
111 x = x / 4 -- 107
112 return assert.same(x, 5) -- 108
113 end) -- 105
114 it("should handle division by zero", function() -- 110
115 local result = pcall(function() -- 112
116 local x = 10 / 0 -- 113
117 end) -- 112
118 return assert.is_true(result) -- 115
119 end) -- 110
120 it("should handle very large numbers", function() -- 117
121 local big = 1e100 -- 118
122 return assert.is_true(big > 0) -- 119
123 end) -- 117
124 it("should handle very small numbers", function() -- 121
125 local small = 1e-100 -- 122
126 return assert.is_true(small > 0) -- 123
127 end) -- 121
128 it("should support negation", function() -- 125
129 assert.same(-10, -10) -- 126
130 return assert.same -- 127
131 end) -- 125
132 it("should work with complex expressions", function() -- 129
133 local result = (1 + 2) * (3 + 4) / 2 -- 130
134 return assert.same(result, 10.5) -- 131
135 end) -- 129
136 it("should support power with decimal", function() -- 133
137 return assert.same(4 ^ 0.5, 2) -- 134
138 end) -- 133
139 return it("should handle modulo with negative numbers", function() -- 136
140 return assert.same(-10 % 3, 2) -- 137
141 end) -- 136
142end) -- 1
diff --git a/spec/outputs/5.1/test/return_spec.lua b/spec/outputs/5.1/test/return_spec.lua
new file mode 100644
index 0000000..4e6580f
--- /dev/null
+++ b/spec/outputs/5.1/test/return_spec.lua
@@ -0,0 +1,145 @@
1return describe("return", function() -- 1
2 it("should return from comprehension", function() -- 2
3 local fn -- 3
4 fn = function() -- 3
5 local _accum_0 = { } -- 4
6 local _len_0 = 1 -- 4
7 for x = 1, 5 do -- 4
8 _accum_0[_len_0] = x * 2 -- 4
9 _len_0 = _len_0 + 1 -- 4
10 end -- 4
11 return _accum_0 -- 4
12 end -- 3
13 local result = fn() -- 5
14 return assert.same(result, { -- 6
15 2, -- 6
16 4, -- 6
17 6, -- 6
18 8, -- 6
19 10 -- 6
20 }) -- 6
21 end) -- 2
22 it("should return from table comprehension", function() -- 8
23 local fn -- 9
24 fn = function() -- 9
25 local _tbl_0 = { } -- 10
26 for k, v in pairs({ -- 10
27 a = 1, -- 10
28 b = 2 -- 10
29 }) do -- 10
30 _tbl_0[k] = v -- 10
31 end -- 10
32 return _tbl_0 -- 10
33 end -- 9
34 local result = fn() -- 11
35 return assert.same(type(result), "table") -- 12
36 end) -- 8
37 it("should return from nested if", function() -- 14
38 local fn -- 15
39 fn = function(a, b) -- 15
40 if a then -- 16
41 if b then -- 17
42 return "both" -- 18
43 else -- 20
44 return "only a" -- 20
45 end -- 17
46 else -- 22
47 return "neither" -- 22
48 end -- 16
49 end -- 15
50 assert.same(fn(true, true), "both") -- 23
51 assert.same(fn(true, false), "only a") -- 24
52 return assert.same(fn(false, false), "neither") -- 25
53 end) -- 14
54 it("should return from switch", function() -- 27
55 local fn -- 28
56 fn = function(value) -- 28
57 if 1 == value then -- 30
58 return "one" -- 30
59 elseif 2 == value then -- 31
60 return "two" -- 31
61 else -- 32
62 return "other" -- 32
63 end -- 29
64 end -- 28
65 assert.same(fn(1), "one") -- 33
66 assert.same(fn(2), "two") -- 34
67 return assert.same(fn(3), "other") -- 35
68 end) -- 27
69 it("should return table literal", function() -- 37
70 local fn -- 38
71 fn = function() -- 38
72 return { -- 40
73 value = 42, -- 40
74 name = "test" -- 41
75 } -- 39
76 end -- 38
77 local result = fn() -- 42
78 assert.same(result.value, 42) -- 43
79 return assert.same(result.name, "test") -- 44
80 end) -- 37
81 it("should return array literal", function() -- 46
82 local fn -- 47
83 fn = function() -- 47
84 return { -- 49
85 1, -- 49
86 2, -- 50
87 3 -- 51
88 } -- 48
89 end -- 47
90 local result = fn() -- 52
91 return assert.same(result, { -- 53
92 1, -- 53
93 2, -- 53
94 3 -- 53
95 }) -- 53
96 end) -- 46
97 it("should return from with statement", function() -- 55
98 local fn -- 56
99 fn = function(obj) -- 56
100 local result = obj.value -- 57
101 return result -- 58
102 end -- 56
103 return assert.same(fn({ -- 59
104 value = 100 -- 59
105 }), 100) -- 59
106 end) -- 55
107 it("should return nil implicitly", function() -- 61
108 fn(function() -- 62
109 return print("no return") -- 62
110 end) -- 62
111 return assert.same(fn(), nil) -- 63
112 end) -- 61
113 it("should return multiple values", function() -- 65
114 fn(function() -- 66
115 return 1, 2, 3 -- 66
116 end) -- 66
117 local a, b, c = fn() -- 67
118 assert.same(a, 1) -- 68
119 assert.same(b, 2) -- 69
120 return assert.same(c, 3) -- 70
121 end) -- 65
122 it("should return from function call", function() -- 72
123 local fn -- 73
124 fn = function() -- 73
125 local inner -- 74
126 inner = function() -- 74
127 return 42 -- 74
128 end -- 74
129 return inner() -- 75
130 end -- 73
131 return assert.same(fn(), 42) -- 76
132 end) -- 72
133 return it("should handle return in expression context", function() -- 78
134 local fn -- 79
135 fn = function(cond) -- 79
136 if cond then -- 80
137 return "yes" -- 81
138 else -- 83
139 return "no" -- 83
140 end -- 80
141 end -- 79
142 assert.same(fn(true), "yes") -- 84
143 return assert.same(fn(false), "no") -- 85
144 end) -- 78
145end) -- 1
diff --git a/spec/outputs/5.1/test/string_spec.lua b/spec/outputs/5.1/test/string_spec.lua
new file mode 100644
index 0000000..95eb470
--- /dev/null
+++ b/spec/outputs/5.1/test/string_spec.lua
@@ -0,0 +1,138 @@
1return describe("string", function() -- 1
2 it("should support single quote strings", function() -- 2
3 local s = 'hello' -- 3
4 return assert.same(s, "hello") -- 4
5 end) -- 2
6 it("should support double quote strings", function() -- 6
7 local s = "world" -- 7
8 return assert.same(s, "world") -- 8
9 end) -- 6
10 it("should support escape sequences", function() -- 10
11 local s = "hello\nworld" -- 11
12 return assert.is_true(s:match("\n") ~= nil) -- 12
13 end) -- 10
14 it("should support escaped quotes", function() -- 14
15 local s = "he said \"hello\"" -- 15
16 return assert.same(s, 'he said "hello"') -- 16
17 end) -- 14
18 it("should support backslash escape", function() -- 18
19 local s = "\\" -- 19
20 return assert.same(s, "\\") -- 20
21 end) -- 18
22 it("should support multi-line strings with [[ ]]", function() -- 22
23 local s = [[ hello
24 world
25 ]] -- 23
26 assert.is_true(s:match("hello") ~= nil) -- 27
27 return assert.is_true(s:match("world") ~= nil) -- 28
28 end) -- 22
29 it("should support multi-line strings with [=[ ]=]", function() -- 30
30 local s = [==[ hello
31 world
32 ]==] -- 31
33 assert.is_true(s:match("hello") ~= nil) -- 35
34 return assert.is_true(s:match("world") ~= nil) -- 36
35 end) -- 30
36 it("should support string interpolation with double quotes", function() -- 38
37 local name = "world" -- 39
38 local s = "hello " .. tostring(name) -- 40
39 return assert.same(s, "hello world") -- 41
40 end) -- 38
41 it("should support expression interpolation", function() -- 43
42 local a, b = 1, 2 -- 44
43 local s = tostring(a) .. " + " .. tostring(b) .. " = " .. tostring(a + b) -- 45
44 return assert.same(s, "1 + 2 = 3") -- 46
45 end) -- 43
46 it("should not interpolate in single quotes", function() -- 48
47 local name = "world" -- 49
48 local s = 'hello #{name}' -- 50
49 return assert.same(s, "hello " .. tostring(name)) -- 51
50 end) -- 48
51 it("should escape interpolation with \#", function() -- 53
52 local name = "world" -- 54
53 local s = "hello \\" .. tostring(name) -- 55
54 return assert.same(s, "hello " .. tostring(name)) -- 56
55 end) -- 53
56 it("should support method calls on string literals", function() -- 58
57 local result = ("hello"):upper() -- 59
58 return assert.same(result, "HELLO") -- 60
59 end) -- 58
60 it("should support chained method calls", function() -- 62
61 local result = ("hello world"):upper():match("HELLO") -- 63
62 return assert.same(result, "HELLO") -- 64
63 end) -- 62
64 it("should support YAML style strings", function() -- 66
65 local s = "hello\nworld" -- 67
66 assert.is_true(s:match("hello") ~= nil) -- 70
67 return assert.is_true(s:match("world") ~= nil) -- 71
68 end) -- 66
69 it("should support YAML style with interpolation", function() -- 73
70 local name = "test" -- 74
71 local s = "hello " .. tostring(name) -- 75
72 return assert.same(s, "hello test\n") -- 77
73 end) -- 73
74 it("should support string concatenation", function() -- 79
75 local s = "hello" .. " " .. "world" -- 80
76 return assert.same(s, "hello world") -- 81
77 end) -- 79
78 it("should handle empty strings", function() -- 83
79 local s = "" -- 84
80 return assert.same(s, "") -- 85
81 end) -- 83
82 it("should support Unicode characters", function() -- 87
83 local s = "hello 世界" -- 88
84 return assert.is_true(s:match("世界") ~= nil) -- 89
85 end) -- 87
86 it("should support string length", function() -- 91
87 local s = "hello" -- 92
88 return assert.same(#s, 5) -- 93
89 end) -- 91
90 it("should support multi-line YAML with complex content", function() -- 95
91 local config = "key1: value1\nkey2: value2\nkey3: value3" -- 96
92 return assert.is_true(config:match("key1") ~= nil) -- 100
93 end) -- 95
94 it("should support interpolation in YAML strings", function() -- 102
95 local x, y = 10, 20 -- 103
96 local s = "point:\n\tx: " .. tostring(x) .. "\n\ty: " .. tostring(y) -- 104
97 assert.is_true(s:match("x: 10") ~= nil) -- 108
98 return assert.is_true(s:match("y: 20") ~= nil) -- 109
99 end) -- 102
100 it("should support function call in interpolation", function() -- 111
101 local s = "result: " .. tostring(function() -- 112
102 return 42 -- 112
103 end) -- 112
104 return assert.same(s, "result: 42") -- 113
105 end) -- 111
106 it("should support table indexing in interpolation", function() -- 115
107 local t = { -- 116
108 value = 100 -- 116
109 } -- 116
110 local s = "value: " .. tostring(t.value) -- 117
111 return assert.same(s, "value: 100") -- 118
112 end) -- 115
113 it("should handle escaped characters correctly", function() -- 120
114 local s = "tab:\t, newline:\n, return:\r" -- 121
115 assert.is_true(s:match("\t") ~= nil) -- 122
116 return assert.is_true(s:match("\n") ~= nil) -- 123
117 end) -- 120
118 it("should support string methods with colon syntax", function() -- 125
119 local s = "hello" -- 126
120 return assert.same(s:sub(1, 2), "he") -- 127
121 end) -- 125
122 it("should work in expressions", function() -- 129
123 local result = "hello" .. " world" -- 130
124 return assert.same(result, "hello world") -- 131
125 end) -- 129
126 it("should support octal escape", function() -- 133
127 local s = "\65" -- 134
128 return assert.same(s, "A") -- 135
129 end) -- 133
130 it("should support hex escape", function() -- 137
131 local s = "\x41" -- 138
132 return assert.same(s, "A") -- 139
133 end) -- 137
134 return it("should support unicode escape", function() -- 141
135 local s = "\u{4e16}" -- 142
136 return assert.same(s, "世") -- 143
137 end) -- 141
138end) -- 1
diff --git a/spec/outputs/5.1/test/switch_spec.lua b/spec/outputs/5.1/test/switch_spec.lua
new file mode 100644
index 0000000..5b13970
--- /dev/null
+++ b/spec/outputs/5.1/test/switch_spec.lua
@@ -0,0 +1,743 @@
1return describe("switch", function() -- 1
2 it("should match single value", function() -- 2
3 local value = "cool" -- 3
4 local result -- 4
5 if "cool" == value then -- 5
6 result = "matched" -- 6
7 else -- 8
8 result = "not matched" -- 8
9 end -- 4
10 return assert.same(result, "matched") -- 9
11 end) -- 2
12 it("should match multiple values with or", function() -- 11
13 local hi = "world" -- 12
14 local matched = false -- 13
15 if "one" == hi or "two" == hi then -- 15
16 matched = true -- 16
17 end -- 14
18 assert.is_false(matched) -- 17
19 hi = "one" -- 19
20 if "one" == hi or "two" == hi then -- 21
21 matched = true -- 22
22 end -- 20
23 return assert.is_true(matched) -- 23
24 end) -- 11
25 it("should execute else branch when no match", function() -- 25
26 local value = "other" -- 26
27 local result -- 27
28 if "cool" == value then -- 28
29 result = "matched cool" -- 29
30 elseif "yeah" == value then -- 30
31 result = "matched yeah" -- 31
32 else -- 33
33 result = "else branch" -- 33
34 end -- 27
35 return assert.same(result, "else branch") -- 34
36 end) -- 25
37 it("should destructure table with single key", function() -- 36
38 local tb = { -- 37
39 x = 100 -- 37
40 } -- 37
41 local result -- 38
42 do -- 39
43 local _type_0 = type(tb) -- 39
44 local _tab_0 = "table" == _type_0 or "userdata" == _type_0 -- 39
45 local _match_0 = false -- 39
46 if _tab_0 then -- 39
47 local x = tb.x -- 39
48 if x ~= nil then -- 39
49 _match_0 = true -- 39
50 result = x -- 40
51 end -- 39
52 end -- 39
53 if not _match_0 then -- 39
54 result = "no match" -- 42
55 end -- 38
56 end -- 38
57 return assert.same(result, 100) -- 43
58 end) -- 36
59 it("should destructure table with multiple keys", function() -- 45
60 local tb = { -- 46
61 x = 100, -- 46
62 y = 200 -- 46
63 } -- 46
64 local result -- 47
65 do -- 48
66 local _type_0 = type(tb) -- 48
67 local _tab_0 = "table" == _type_0 or "userdata" == _type_0 -- 48
68 local _match_0 = false -- 48
69 if _tab_0 then -- 48
70 local x = tb.x -- 48
71 local y = tb.y -- 48
72 if x ~= nil and y ~= nil then -- 48
73 _match_0 = true -- 48
74 result = x + y -- 49
75 end -- 48
76 end -- 48
77 if not _match_0 then -- 48
78 result = "no match" -- 51
79 end -- 47
80 end -- 47
81 return assert.same(result, 300) -- 52
82 end) -- 45
83 it("should destructure table with default values", function() -- 54
84 local tb = { -- 55
85 a = 1 -- 55
86 } -- 55
87 local _type_0 = type(tb) -- 57
88 local _tab_0 = "table" == _type_0 or "userdata" == _type_0 -- 57
89 if _tab_0 then -- 57
90 local a = tb.a -- 57
91 local b = tb.b -- 57
92 if a == nil then -- 57
93 a = 1 -- 57
94 end -- 57
95 if b == nil then -- 57
96 b = 2 -- 57
97 end -- 57
98 assert.same(a, 1) -- 58
99 return assert.same(b, 2) -- 59
100 end -- 56
101 end) -- 54
102 it("should destructure nested tables", function() -- 61
103 local dict = { -- 63
104 { }, -- 63
105 { -- 64
106 1, -- 64
107 2, -- 64
108 3 -- 64
109 }, -- 64
110 a = { -- 65
111 b = { -- 65
112 c = 1 -- 65
113 } -- 65
114 }, -- 65
115 x = { -- 66
116 y = { -- 66
117 z = 1 -- 66
118 } -- 66
119 } -- 66
120 } -- 62
121 local matched = false -- 68
122 do -- 70
123 local _type_0 = type(dict) -- 70
124 local _tab_0 = "table" == _type_0 or "userdata" == _type_0 -- 70
125 if _tab_0 then -- 70
126 local first = dict[1] -- 70
127 local one -- 70
128 do -- 70
129 local _obj_0 = dict[2] -- 70
130 local _type_1 = type(_obj_0) -- 70
131 if "table" == _type_1 or "userdata" == _type_1 then -- 70
132 one = _obj_0[1] -- 70
133 end -- 70
134 end -- 70
135 local two -- 70
136 do -- 70
137 local _obj_0 = dict[2] -- 70
138 local _type_1 = type(_obj_0) -- 70
139 if "table" == _type_1 or "userdata" == _type_1 then -- 70
140 two = _obj_0[2] -- 70
141 end -- 70
142 end -- 70
143 local three -- 70
144 do -- 70
145 local _obj_0 = dict[2] -- 70
146 local _type_1 = type(_obj_0) -- 70
147 if "table" == _type_1 or "userdata" == _type_1 then -- 70
148 three = _obj_0[3] -- 70
149 end -- 70
150 end -- 70
151 local c -- 70
152 do -- 70
153 local _obj_0 = dict.a -- 70
154 local _type_1 = type(_obj_0) -- 70
155 if "table" == _type_1 or "userdata" == _type_1 then -- 70
156 do -- 70
157 local _obj_1 = _obj_0.b -- 70
158 local _type_2 = type(_obj_1) -- 70
159 if "table" == _type_2 or "userdata" == _type_2 then -- 70
160 c = _obj_1.c -- 70
161 end -- 70
162 end -- 70
163 end -- 70
164 end -- 70
165 local z -- 70
166 do -- 70
167 local _obj_0 = dict.x -- 70
168 local _type_1 = type(_obj_0) -- 70
169 if "table" == _type_1 or "userdata" == _type_1 then -- 70
170 do -- 70
171 local _obj_1 = _obj_0.y -- 70
172 local _type_2 = type(_obj_1) -- 70
173 if "table" == _type_2 or "userdata" == _type_2 then -- 70
174 z = _obj_1.z -- 70
175 end -- 70
176 end -- 70
177 end -- 70
178 end -- 70
179 if first ~= nil and one ~= nil and two ~= nil and three ~= nil and c ~= nil and z ~= nil then -- 70
180 matched = first == { } and one == 1 and two == 2 and three == 3 and c == 1 and z == 1 -- 76
181 end -- 70
182 end -- 69
183 end -- 69
184 return assert.is_true(matched) -- 77
185 end) -- 61
186 it("should destructure arrays with exact match", function() -- 79
187 local tb = { -- 80
188 1, -- 80
189 2, -- 80
190 3 -- 80
191 } -- 80
192 local result -- 81
193 do -- 82
194 local _type_0 = type(tb) -- 82
195 local _tab_0 = "table" == _type_0 or "userdata" == _type_0 -- 82
196 local _match_0 = false -- 82
197 if _tab_0 then -- 82
198 if 1 == tb[1] and 2 == tb[2] and 3 == tb[3] then -- 82
199 _match_0 = true -- 82
200 result = "exact match" -- 83
201 end -- 82
202 end -- 82
203 if not _match_0 then -- 82
204 result = "no match" -- 85
205 end -- 81
206 end -- 81
207 return assert.same(result, "exact match") -- 86
208 end) -- 79
209 it("should destructure arrays with variables", function() -- 88
210 local tb = { -- 89
211 1, -- 89
212 "b", -- 89
213 3 -- 89
214 } -- 89
215 local result -- 90
216 do -- 91
217 local _type_0 = type(tb) -- 91
218 local _tab_0 = "table" == _type_0 or "userdata" == _type_0 -- 91
219 local _match_0 = false -- 91
220 if _tab_0 then -- 91
221 local b = tb[2] -- 91
222 if 1 == tb[1] and b ~= nil and 3 == tb[3] then -- 91
223 _match_0 = true -- 91
224 result = b -- 92
225 end -- 91
226 end -- 91
227 if not _match_0 then -- 91
228 result = "no match" -- 94
229 end -- 90
230 end -- 90
231 return assert.same(result, "b") -- 95
232 end) -- 88
233 it("should destructure arrays with defaults", function() -- 97
234 local tb = { -- 98
235 1, -- 98
236 2 -- 98
237 } -- 98
238 local result -- 99
239 do -- 100
240 local _type_0 = type(tb) -- 100
241 local _tab_0 = "table" == _type_0 or "userdata" == _type_0 -- 100
242 local _match_0 = false -- 100
243 if _tab_0 then -- 100
244 local b = tb[3] -- 100
245 if b == nil then -- 100
246 b = 3 -- 100
247 end -- 100
248 if 1 == tb[1] and 2 == tb[2] then -- 100
249 _match_0 = true -- 100
250 result = b -- 101
251 end -- 100
252 end -- 100
253 if not _match_0 then -- 100
254 result = "no match" -- 103
255 end -- 99
256 end -- 99
257 return assert.same(result, 3) -- 104
258 end) -- 97
259 it("should match pattern with __class", function() -- 106
260 local ClassA -- 107
261 do -- 107
262 local _class_0 -- 107
263 local _base_0 = { } -- 107
264 if _base_0.__index == nil then -- 107
265 _base_0.__index = _base_0 -- 107
266 end -- 107
267 _class_0 = setmetatable({ -- 107
268 __init = function() end, -- 107
269 __base = _base_0, -- 107
270 __name = "ClassA" -- 107
271 }, { -- 107
272 __index = _base_0, -- 107
273 __call = function(cls, ...) -- 107
274 local _self_0 = setmetatable({ }, _base_0) -- 107
275 cls.__init(_self_0, ...) -- 107
276 return _self_0 -- 107
277 end -- 107
278 }) -- 107
279 _base_0.__class = _class_0 -- 107
280 ClassA = _class_0 -- 107
281 end -- 107
282 local ClassB -- 108
283 do -- 108
284 local _class_0 -- 108
285 local _base_0 = { } -- 108
286 if _base_0.__index == nil then -- 108
287 _base_0.__index = _base_0 -- 108
288 end -- 108
289 _class_0 = setmetatable({ -- 108
290 __init = function() end, -- 108
291 __base = _base_0, -- 108
292 __name = "ClassB" -- 108
293 }, { -- 108
294 __index = _base_0, -- 108
295 __call = function(cls, ...) -- 108
296 local _self_0 = setmetatable({ }, _base_0) -- 108
297 cls.__init(_self_0, ...) -- 108
298 return _self_0 -- 108
299 end -- 108
300 }) -- 108
301 _base_0.__class = _class_0 -- 108
302 ClassB = _class_0 -- 108
303 end -- 108
304 local item = ClassA() -- 109
305 local result -- 110
306 do -- 111
307 local _type_0 = type(item) -- 111
308 local _tab_0 = "table" == _type_0 or "userdata" == _type_0 -- 111
309 local _match_0 = false -- 111
310 if _tab_0 then -- 111
311 ClassA = item.__class -- 111
312 if ClassA ~= nil then -- 111
313 _match_0 = true -- 111
314 result = "Object A" -- 112
315 end -- 111
316 end -- 111
317 if not _match_0 then -- 111
318 local _match_1 = false -- 113
319 if _tab_0 then -- 113
320 ClassB = item.__class -- 113
321 if ClassB ~= nil then -- 113
322 _match_1 = true -- 113
323 result = "Object B" -- 114
324 end -- 113
325 end -- 113
326 if not _match_1 then -- 113
327 result = "unknown" -- 116
328 end -- 110
329 end -- 110
330 end -- 110
331 return assert.same(result, "Object A") -- 117
332 end) -- 106
333 it("should match pattern with metatable", function() -- 119
334 local tb = setmetatable({ }, { -- 120
335 __mode = "v" -- 120
336 }) -- 120
337 local metatable_matched = false -- 121
338 do -- 123
339 local _type_0 = type(tb) -- 123
340 local _tab_0 = "table" == _type_0 or "userdata" == _type_0 -- 123
341 if _tab_0 then -- 123
342 local mt = getmetatable(tb) -- 123
343 if mt ~= nil then -- 123
344 metatable_matched = mt ~= nil -- 124
345 end -- 123
346 end -- 122
347 end -- 122
348 return assert.is_true(metatable_matched) -- 125
349 end) -- 119
350 it("should use switch as expression in assignment", function() -- 127
351 local tb = { -- 128
352 x = "abc" -- 128
353 } -- 128
354 local matched -- 129
355 if 1 == tb then -- 130
356 matched = "1" -- 131
357 else -- 132
358 do -- 132
359 local _type_0 = type(tb) -- 132
360 local _tab_0 = "table" == _type_0 or "userdata" == _type_0 -- 132
361 local _match_0 = false -- 132
362 if _tab_0 then -- 132
363 local x = tb.x -- 132
364 if x ~= nil then -- 132
365 _match_0 = true -- 132
366 matched = x -- 133
367 end -- 132
368 end -- 132
369 if not _match_0 then -- 132
370 if false == tb then -- 134
371 matched = "false" -- 135
372 else -- 137
373 matched = nil -- 137
374 end -- 129
375 end -- 129
376 end -- 129
377 end -- 129
378 return assert.same(matched, "abc") -- 138
379 end) -- 127
380 it("should use switch in return statement", function() -- 140
381 local fn -- 141
382 fn = function(tb) -- 141
383 if nil == tb then -- 143
384 return "invalid" -- 144
385 else -- 145
386 local _type_0 = type(tb) -- 145
387 local _tab_0 = "table" == _type_0 or "userdata" == _type_0 -- 145
388 local _match_0 = false -- 145
389 if _tab_0 then -- 145
390 local a = tb.a -- 145
391 local b = tb.b -- 145
392 if a ~= nil and b ~= nil then -- 145
393 _match_0 = true -- 145
394 return tostring(a + b) -- 146
395 end -- 145
396 end -- 145
397 if not _match_0 then -- 145
398 if 1 == tb or 2 == tb or 3 == tb or 4 == tb or 5 == tb then -- 147
399 return "number 1 - 5" -- 148
400 else -- 150
401 return "should not reach here" -- 150
402 end -- 142
403 end -- 142
404 end -- 142
405 end -- 141
406 assert.same(fn({ -- 151
407 a = 1, -- 151
408 b = 2 -- 151
409 }), "3") -- 151
410 assert.same(fn(3), "number 1 - 5") -- 152
411 return assert.same(fn(nil), "invalid") -- 153
412 end) -- 140
413 it("should support pattern matching assignment with :=", function() -- 155
414 local v = "hello" -- 156
415 local matched = false -- 157
416 do -- 158
417 v = "hello" -- 158
418 if "hello" == v then -- 159
419 matched = true -- 160
420 else -- 162
421 matched = false -- 162
422 end -- 158
423 end -- 158
424 assert.is_true(matched) -- 163
425 return assert.same(v, "hello") -- 164
426 end) -- 155
427 it("should match with computed expressions", function() -- 166
428 local hi = 4 -- 167
429 local matched = false -- 168
430 if (3 + 1) == hi or (function() -- 170
431 return 4 -- 170
432 end)() == hi or (5 - 1) == hi then -- 170
433 matched = true -- 171
434 end -- 169
435 return assert.is_true(matched) -- 172
436 end) -- 166
437 it("should handle nested array destructuring", function() -- 174
438 local tb = { -- 176
439 { -- 176
440 a = 1, -- 176
441 b = 2 -- 176
442 }, -- 176
443 { -- 177
444 a = 3, -- 177
445 b = 4 -- 177
446 }, -- 177
447 { -- 178
448 a = 5, -- 178
449 b = 6 -- 178
450 }, -- 178
451 "fourth" -- 179
452 } -- 175
453 local result -- 181
454 do -- 182
455 local _type_0 = type(tb) -- 182
456 local _tab_0 = "table" == _type_0 or "userdata" == _type_0 -- 182
457 local _match_0 = false -- 182
458 if _tab_0 then -- 182
459 local fourth = tb[4] -- 182
460 local _val_0 -- 182
461 do -- 182
462 local _obj_0 = tb[1] -- 182
463 if _obj_0 ~= nil then -- 182
464 _val_0 = _obj_0.a -- 182
465 end -- 182
466 end -- 182
467 local _val_1 -- 182
468 do -- 182
469 local _obj_0 = tb[1] -- 182
470 if _obj_0 ~= nil then -- 182
471 _val_1 = _obj_0.b -- 182
472 end -- 182
473 end -- 182
474 local _val_2 -- 182
475 do -- 182
476 local _obj_0 = tb[2] -- 182
477 if _obj_0 ~= nil then -- 182
478 _val_2 = _obj_0.a -- 182
479 end -- 182
480 end -- 182
481 local _val_3 -- 182
482 do -- 182
483 local _obj_0 = tb[2] -- 182
484 if _obj_0 ~= nil then -- 182
485 _val_3 = _obj_0.b -- 182
486 end -- 182
487 end -- 182
488 local _val_4 -- 182
489 do -- 182
490 local _obj_0 = tb[3] -- 182
491 if _obj_0 ~= nil then -- 182
492 _val_4 = _obj_0.a -- 182
493 end -- 182
494 end -- 182
495 local _val_5 -- 182
496 do -- 182
497 local _obj_0 = tb[3] -- 182
498 if _obj_0 ~= nil then -- 182
499 _val_5 = _obj_0.b -- 182
500 end -- 182
501 end -- 182
502 if 1 == _val_0 and 2 == _val_1 and 3 == _val_2 and 4 == _val_3 and 5 == _val_4 and 6 == _val_5 and fourth ~= nil then -- 182
503 _match_0 = true -- 182
504 result = fourth -- 188
505 end -- 182
506 end -- 182
507 if not _match_0 then -- 182
508 result = "no match" -- 190
509 end -- 181
510 end -- 181
511 return assert.same(result, "fourth") -- 191
512 end) -- 174
513 it("should match combined patterns", function() -- 193
514 local tb = { -- 194
515 success = true, -- 194
516 result = "data" -- 194
517 } -- 194
518 local result -- 195
519 do -- 196
520 local _type_0 = type(tb) -- 196
521 local _tab_0 = "table" == _type_0 or "userdata" == _type_0 -- 196
522 local _match_0 = false -- 196
523 if _tab_0 then -- 196
524 result = tb.result -- 196
525 if true == tb.success and result ~= nil then -- 196
526 _match_0 = true -- 196
527 result = { -- 197
528 "success", -- 197
529 result -- 197
530 } -- 197
531 end -- 196
532 end -- 196
533 if not _match_0 then -- 196
534 local _match_1 = false -- 198
535 if _tab_0 then -- 198
536 if false == tb.success then -- 198
537 _match_1 = true -- 198
538 result = { -- 199
539 "failed", -- 199
540 result -- 199
541 } -- 199
542 end -- 198
543 end -- 198
544 if not _match_1 then -- 198
545 result = { -- 201
546 "invalid" -- 201
547 } -- 201
548 end -- 195
549 end -- 195
550 end -- 195
551 return assert.same(result, { -- 202
552 "success", -- 202
553 "data" -- 202
554 }) -- 202
555 end) -- 193
556 it("should match type discriminated patterns", function() -- 204
557 local tb = { -- 205
558 type = "success", -- 205
559 content = "data" -- 205
560 } -- 205
561 local result -- 206
562 do -- 207
563 local _type_0 = type(tb) -- 207
564 local _tab_0 = "table" == _type_0 or "userdata" == _type_0 -- 207
565 local _match_0 = false -- 207
566 if _tab_0 then -- 207
567 local content = tb.content -- 207
568 if "success" == tb.type and content ~= nil then -- 207
569 _match_0 = true -- 207
570 result = { -- 208
571 "success", -- 208
572 content -- 208
573 } -- 208
574 end -- 207
575 end -- 207
576 if not _match_0 then -- 207
577 local _match_1 = false -- 209
578 if _tab_0 then -- 209
579 local content = tb.content -- 209
580 if "error" == tb.type and content ~= nil then -- 209
581 _match_1 = true -- 209
582 result = { -- 210
583 "error", -- 210
584 content -- 210
585 } -- 210
586 end -- 209
587 end -- 209
588 if not _match_1 then -- 209
589 result = { -- 212
590 "invalid" -- 212
591 } -- 212
592 end -- 206
593 end -- 206
594 end -- 206
595 return assert.same(result, { -- 213
596 "success", -- 213
597 "data" -- 213
598 }) -- 213
599 end) -- 204
600 it("should match with wildcard array capture", function() -- 215
601 local clientData = { -- 216
602 "Meta", -- 216
603 "CUST_1001", -- 216
604 "CHK123" -- 216
605 } -- 216
606 local metadata = nil -- 217
607 local customerId = nil -- 218
608 local checksum = nil -- 219
609 do -- 221
610 local _type_0 = type(clientData) -- 221
611 local _tab_0 = "table" == _type_0 or "userdata" == _type_0 -- 221
612 if _tab_0 then -- 221
613 local capturedMetadata -- 221
614 do -- 221
615 local _accum_0 = { } -- 221
616 local _len_0 = 1 -- 221
617 local _max_0 = #clientData + -3 + 1 -- 221
618 for _index_0 = 1, _max_0 do -- 221
619 local _item_0 = clientData[_index_0] -- 221
620 _accum_0[_len_0] = _item_0 -- 221
621 _len_0 = _len_0 + 1 -- 221
622 end -- 221
623 capturedMetadata = _accum_0 -- 221
624 end -- 221
625 customerId = clientData[#clientData - 1] -- 221
626 checksum = clientData[#clientData] -- 221
627 if customerId ~= nil and checksum ~= nil then -- 221
628 metadata = capturedMetadata -- 222
629 end -- 221
630 end -- 220
631 end -- 220
632 assert.same(metadata, { -- 223
633 "Meta" -- 223
634 }) -- 223
635 assert.same(customerId, "CUST_1001") -- 224
636 return assert.same(checksum, "CHK123") -- 225
637 end) -- 215
638 it("should work with complex tuple patterns", function() -- 227
639 local handlePath -- 228
640 handlePath = function(segments) -- 228
641 local _type_0 = type(segments) -- 230
642 local _tab_0 = "table" == _type_0 or "userdata" == _type_0 -- 230
643 local _match_0 = false -- 230
644 if _tab_0 then -- 230
645 local resource = segments[#segments - 1] -- 230
646 local action = segments[#segments] -- 230
647 if resource ~= nil and action ~= nil then -- 230
648 _match_0 = true -- 230
649 return { -- 231
650 "Resource: " .. tostring(resource), -- 231
651 "Action: " .. tostring(action) -- 231
652 } -- 231
653 end -- 230
654 end -- 230
655 if not _match_0 then -- 230
656 return { -- 233
657 "no match" -- 233
658 } -- 233
659 end -- 229
660 end -- 228
661 local result = handlePath({ -- 234
662 "admin", -- 234
663 "logs", -- 234
664 "view" -- 234
665 }) -- 234
666 return assert.same(result, { -- 235
667 "Resource: logs", -- 235
668 "Action: view" -- 235
669 }) -- 235
670 end) -- 227
671 it("should match boolean false correctly", function() -- 237
672 local items = { -- 239
673 { -- 239
674 x = 100, -- 239
675 y = 200 -- 239
676 }, -- 239
677 { -- 240
678 width = 300, -- 240
679 height = 400 -- 240
680 }, -- 240
681 false -- 241
682 } -- 238
683 local results = { } -- 243
684 for _index_0 = 1, #items do -- 244
685 local item = items[_index_0] -- 244
686 local _type_0 = type(item) -- 246
687 local _tab_0 = "table" == _type_0 or "userdata" == _type_0 -- 246
688 local _match_0 = false -- 246
689 if _tab_0 then -- 246
690 local x = item.x -- 246
691 local y = item.y -- 246
692 if x ~= nil and y ~= nil then -- 246
693 _match_0 = true -- 246
694 table.insert(results, "Vec2") -- 247
695 end -- 246
696 end -- 246
697 if not _match_0 then -- 246
698 local _match_1 = false -- 248
699 if _tab_0 then -- 248
700 local width = item.width -- 248
701 local height = item.height -- 248
702 if width ~= nil and height ~= nil then -- 248
703 _match_1 = true -- 248
704 table.insert(results, "Size") -- 249
705 end -- 248
706 end -- 248
707 if not _match_1 then -- 248
708 if false == item then -- 250
709 table.insert(results, "None") -- 251
710 end -- 245
711 end -- 245
712 end -- 245
713 end -- 244
714 return assert.same(results, { -- 252
715 "Vec2", -- 252
716 "Size", -- 252
717 "None" -- 252
718 }) -- 252
719 end) -- 237
720 it("should handle switch with then syntax", function() -- 254
721 local value = "cool" -- 255
722 local result -- 256
723 if "cool" == value then -- 257
724 result = "matched cool" -- 257
725 else -- 258
726 result = "else branch" -- 258
727 end -- 256
728 return assert.same(result, "matched cool") -- 259
729 end) -- 254
730 return it("should handle switch in function call", function() -- 261
731 local getValue -- 262
732 getValue = function() -- 262
733 local _exp_0 = something -- 263
734 if 1 == _exp_0 then -- 264
735 return "yes" -- 264
736 else -- 265
737 return "no" -- 265
738 end -- 263
739 end -- 262
740 local something = 1 -- 266
741 return assert.same(getValue(), "yes") -- 267
742 end) -- 261
743end) -- 1
diff --git a/spec/outputs/5.1/test/vararg_spec.lua b/spec/outputs/5.1/test/vararg_spec.lua
new file mode 100644
index 0000000..a95e64e
--- /dev/null
+++ b/spec/outputs/5.1/test/vararg_spec.lua
@@ -0,0 +1,164 @@
1return describe("vararg", function() -- 1
2 it("should pass varargs to function", function() -- 2
3 local sum -- 3
4 sum = function(...) -- 3
5 local total = 0 -- 4
6 for i = 1, select("#", ...) do -- 5
7 if type(select(i, ...)) == "number" then -- 6
8 total = total + select(i, ...) -- 7
9 end -- 6
10 end -- 5
11 return total -- 8
12 end -- 3
13 local result = sum(1, 2, 3, 4, 5) -- 9
14 return assert.same(result, 15) -- 10
15 end) -- 2
16 it("should handle empty varargs", function() -- 12
17 local fn -- 13
18 fn = function(...) -- 13
19 return select("#", ...) -- 13
20 end -- 13
21 local result = fn() -- 14
22 return assert.same(result, 0) -- 15
23 end) -- 12
24 it("should spread varargs in function call", function() -- 17
25 local receiver -- 18
26 receiver = function(a, b, c) -- 18
27 return { -- 18
28 a, -- 18
29 b, -- 18
30 c -- 18
31 } -- 18
32 end -- 18
33 local source -- 19
34 source = function() -- 19
35 return 1, 2, 3 -- 19
36 end -- 19
37 local result = receiver(source()) -- 20
38 return assert.same(result, { -- 21
39 1, -- 21
40 2, -- 21
41 3 -- 21
42 }) -- 21
43 end) -- 17
44 it("should use varargs in table", function() -- 23
45 local fn -- 24
46 fn = function(...) -- 24
47 return { -- 24
48 ... -- 24
49 } -- 24
50 end -- 24
51 local result = fn(1, 2, 3) -- 25
52 return assert.same(result, { -- 26
53 1, -- 26
54 2, -- 26
55 3 -- 26
56 }) -- 26
57 end) -- 23
58 it("should forward varargs", function() -- 28
59 local middle -- 29
60 middle = function(fn, ...) -- 29
61 return fn(...) -- 29
62 end -- 29
63 local inner -- 30
64 inner = function(a, b, c) -- 30
65 return a + b + c -- 30
66 end -- 30
67 local result = middle(inner, 1, 2, 3) -- 31
68 return assert.same(result, 6) -- 32
69 end) -- 28
70 it("should count varargs with select", function() -- 34
71 local fn -- 35
72 fn = function(...) -- 35
73 return select("#", ...) -- 35
74 end -- 35
75 assert.same(fn(1, 2, 3), 3) -- 36
76 assert.same(fn("a", "b"), 2) -- 37
77 return assert.same(fn(), 0) -- 38
78 end) -- 34
79 it("should select from varargs", function() -- 40
80 local fn -- 41
81 fn = function(...) -- 41
82 return select(2, ...) -- 41
83 end -- 41
84 local result = fn(1, 2, 3) -- 42
85 return assert.same(result, 2) -- 43
86 end) -- 40
87 it("should work with named parameters and varargs", function() -- 45
88 local fn -- 46
89 fn = function(first, ...) -- 46
90 return { -- 47
91 first, -- 47
92 select("#", ...) -- 47
93 } -- 47
94 end -- 46
95 local result = fn("first", "second", "third") -- 48
96 return assert.same(result, { -- 49
97 "first", -- 49
98 2 -- 49
99 }) -- 49
100 end) -- 45
101 it("should handle nil in varargs", function() -- 51
102 local fn -- 52
103 fn = function(...) -- 52
104 local count = select("#", ...) -- 53
105 local has_nil = false -- 54
106 for i = 1, count do -- 55
107 if select(i, ...) == nil then -- 56
108 has_nil = true -- 56
109 end -- 56
110 end -- 55
111 return { -- 57
112 count, -- 57
113 has_nil -- 57
114 } -- 57
115 end -- 52
116 local result = fn(1, nil, 3) -- 58
117 return assert.same(result, { -- 59
118 3, -- 59
119 true -- 59
120 }) -- 59
121 end) -- 51
122 it("should work with table unpack", function() -- 61
123 local fn -- 62
124 fn = function(...) -- 62
125 return { -- 62
126 ... -- 62
127 } -- 62
128 end -- 62
129 local result = fn(table.unpack({ -- 63
130 1, -- 63
131 2, -- 63
132 3 -- 63
133 })) -- 63
134 return assert.same(result, { -- 64
135 1, -- 64
136 2, -- 64
137 3 -- 64
138 }) -- 64
139 end) -- 61
140 return it("should work with varargs in comprehension", function() -- 66
141 local fn -- 67
142 fn = function(...) -- 67
143 local _accum_0 = { } -- 67
144 local _len_0 = 1 -- 67
145 local _list_0 = { -- 67
146 ... -- 67
147 } -- 67
148 for _index_0 = 1, #_list_0 do -- 67
149 local x = _list_0[_index_0] -- 67
150 _accum_0[_len_0] = x * 2 -- 67
151 _len_0 = _len_0 + 1 -- 67
152 end -- 67
153 return _accum_0 -- 67
154 end -- 67
155 local result = fn(1, 2, 3, 4, 5) -- 68
156 return assert.same(result, { -- 69
157 2, -- 69
158 4, -- 69
159 6, -- 69
160 8, -- 69
161 10 -- 69
162 }) -- 69
163 end) -- 66
164end) -- 1
diff --git a/spec/outputs/5.1/test/with_spec.lua b/spec/outputs/5.1/test/with_spec.lua
new file mode 100644
index 0000000..f3f10e3
--- /dev/null
+++ b/spec/outputs/5.1/test/with_spec.lua
@@ -0,0 +1,170 @@
1return describe("with", function() -- 1
2 it("should access property with . syntax", function() -- 2
3 local obj = { -- 3
4 value = 42 -- 3
5 } -- 3
6 do -- 4
7 local result = obj.value -- 5
8 end -- 4
9 return assert.same(result, 42) -- 6
10 end) -- 2
11 it("should call method with : syntax", function() -- 8
12 local obj = { -- 9
13 func = function() -- 9
14 return "result" -- 9
15 end -- 9
16 } -- 9
17 do -- 10
18 local result = obj:func() -- 11
19 end -- 10
20 return assert.same(result, "result") -- 12
21 end) -- 8
22 it("should work as statement", function() -- 14
23 local obj = { -- 15
24 x = 10, -- 15
25 y = 20 -- 15
26 } -- 15
27 obj.sum = obj.x + obj.y -- 17
28 return assert.same(obj.sum, 30) -- 18
29 end) -- 14
30 it("should support nested with", function() -- 20
31 local outer = { -- 21
32 inner = { -- 21
33 value = 100 -- 21
34 } -- 21
35 } -- 21
36 do -- 22
37 local _with_0 = outer.inner -- 22
38 local result = _with_0.value -- 23
39 end -- 22
40 return assert.same(result, 100) -- 24
41 end) -- 20
42 it("should work with? safely", function() -- 26
43 local obj = { -- 27
44 x = 5 -- 27
45 } -- 27
46 do -- 28
47 local result = obj.x -- 29
48 end -- 28
49 return assert.same(result, 5) -- 30
50 end) -- 26
51 it("should work with if inside with", function() -- 32
52 local obj = { -- 33
53 x = 10, -- 33
54 y = 20 -- 33
55 } -- 33
56 if obj.x > 5 then -- 35
57 local result = obj.x + obj.y -- 36
58 end -- 35
59 return assert.same(result, 30) -- 37
60 end) -- 32
61 it("should work with switch inside with", function() -- 39
62 local obj = { -- 40
63 type = "add", -- 40
64 a = 5, -- 40
65 b = 3 -- 40
66 } -- 40
67 do -- 41
68 local result -- 42
69 local _exp_0 = obj.type -- 42
70 if "add" == _exp_0 then -- 43
71 result = obj.a + obj.b -- 43
72 else -- 44
73 result = 0 -- 44
74 end -- 42
75 end -- 41
76 return assert.same(result, 8) -- 45
77 end) -- 39
78 it("should work with loop inside with", function() -- 47
79 local obj = { -- 48
80 items = { -- 48
81 1, -- 48
82 2, -- 48
83 3 -- 48
84 } -- 48
85 } -- 48
86 local sum = 0 -- 49
87 local _list_0 = obj.items -- 51
88 for _index_0 = 1, #_list_0 do -- 51
89 local item = _list_0[_index_0] -- 51
90 sum = sum + item -- 52
91 end -- 51
92 return assert.same(sum, 6) -- 53
93 end) -- 47
94 it("should work with destructure", function() -- 55
95 local obj = { -- 56
96 x = 1, -- 56
97 y = 2, -- 56
98 z = 3 -- 56
99 } -- 56
100 do -- 57
101 local x, y, z = obj[1], obj[2], obj[3] -- 58
102 end -- 57
103 assert.same(x, 1) -- 59
104 assert.same(y, 2) -- 60
105 return assert.same(z, 3) -- 61
106 end) -- 55
107 it("should handle simple with body", function() -- 63
108 local obj = { -- 64
109 value = 42 -- 64
110 } -- 64
111 obj.value2 = 100 -- 66
112 return assert.same(obj.value2, 100) -- 67
113 end) -- 63
114 it("should work with return inside", function() -- 69
115 local obj = { -- 70
116 value = 100 -- 70
117 } -- 70
118 local fn -- 71
119 fn = function() -- 71
120 return obj.value -- 73
121 end -- 71
122 return assert.same(fn(), 100) -- 74
123 end) -- 69
124 it("should work with break inside", function() -- 76
125 local sum = 0 -- 77
126 for i = 1, 5 do -- 78
127 local obj = { -- 79
128 value = i -- 79
129 } -- 79
130 if obj.value == 3 then -- 81
131 break -- 82
132 end -- 81
133 sum = sum + obj.value -- 83
134 end -- 78
135 return assert.same(sum, 3) -- 84
136 end) -- 76
137 it("should chain property access", function() -- 86
138 local obj = { -- 87
139 a = { -- 87
140 b = { -- 87
141 c = 42 -- 87
142 } -- 87
143 } -- 87
144 } -- 87
145 do -- 88
146 local _with_0 = obj.a.b -- 88
147 local result = _with_0.c -- 89
148 end -- 88
149 return assert.same(result, 42) -- 90
150 end) -- 86
151 it("should work with multiple statements", function() -- 92
152 local obj = { -- 93
153 x = 1, -- 93
154 y = 2 -- 93
155 } -- 93
156 local sum = 0 -- 94
157 do -- 95
158 sum = sum + obj.x -- 96
159 sum = sum + obj.y -- 97
160 end -- 95
161 return assert.same(sum, 3) -- 98
162 end) -- 92
163 return it("should preserve object reference", function() -- 100
164 local obj = { -- 101
165 value = 42 -- 101
166 } -- 101
167 obj.value = 100 -- 103
168 return assert.same(obj.value, 100) -- 104
169 end) -- 100
170end) -- 1