aboutsummaryrefslogtreecommitdiff
path: root/spec/outputs/test/in_expression_spec.lua
diff options
context:
space:
mode:
authorLi Jin <dragon-fly@qq.com>2026-01-28 18:43:14 +0800
committerLi Jin <dragon-fly@qq.com>2026-01-28 18:43:14 +0800
commitdd64edd58fe25ec74ae5958128cf3f74b0692f3b (patch)
tree0f2de1df55897e2713977c5a53936757e14b477a /spec/outputs/test/in_expression_spec.lua
parent7c2a92b82e9808d3c5ea29b47d1c59d663fe984a (diff)
downloadyuescript-dd64edd58fe25ec74ae5958128cf3f74b0692f3b.tar.gz
yuescript-dd64edd58fe25ec74ae5958128cf3f74b0692f3b.tar.bz2
yuescript-dd64edd58fe25ec74ae5958128cf3f74b0692f3b.zip
Fixed compiler issues and added 800+ test cases.
Diffstat (limited to 'spec/outputs/test/in_expression_spec.lua')
-rw-r--r--spec/outputs/test/in_expression_spec.lua180
1 files changed, 81 insertions, 99 deletions
diff --git a/spec/outputs/test/in_expression_spec.lua b/spec/outputs/test/in_expression_spec.lua
index fc118c2..e5af45b 100644
--- a/spec/outputs/test/in_expression_spec.lua
+++ b/spec/outputs/test/in_expression_spec.lua
@@ -34,34 +34,7 @@ local _anon_func_3 = function(chars)
34 end 34 end
35 return false 35 return false
36end 36end
37local _anon_func_4 = function(obj) 37local _anon_func_4 = function(items)
38 local _val_0 = "x"
39 for _index_0 = 1, #obj do
40 if obj[_index_0] == _val_0 then
41 return true
42 end
43 end
44 return false
45end
46local _anon_func_5 = function(obj)
47 local _val_0 = "y"
48 for _index_0 = 1, #obj do
49 if obj[_index_0] == _val_0 then
50 return true
51 end
52 end
53 return false
54end
55local _anon_func_6 = function(obj)
56 local _val_0 = "w"
57 for _index_0 = 1, #obj do
58 if obj[_index_0] == _val_0 then
59 return true
60 end
61 end
62 return false
63end
64local _anon_func_7 = function(items)
65 local _val_0 = 1 38 local _val_0 = 1
66 for _index_0 = 1, #items do 39 for _index_0 = 1, #items do
67 if items[_index_0] == _val_0 then 40 if items[_index_0] == _val_0 then
@@ -70,7 +43,7 @@ local _anon_func_7 = function(items)
70 end 43 end
71 return false 44 return false
72end 45end
73local _anon_func_8 = function(items) 46local _anon_func_5 = function(items)
74 local _val_0 = "two" 47 local _val_0 = "two"
75 for _index_0 = 1, #items do 48 for _index_0 = 1, #items do
76 if items[_index_0] == _val_0 then 49 if items[_index_0] == _val_0 then
@@ -79,7 +52,7 @@ local _anon_func_8 = function(items)
79 end 52 end
80 return false 53 return false
81end 54end
82local _anon_func_9 = function(items) 55local _anon_func_6 = function(items)
83 local _val_0 = true 56 local _val_0 = true
84 for _index_0 = 1, #items do 57 for _index_0 = 1, #items do
85 if items[_index_0] == _val_0 then 58 if items[_index_0] == _val_0 then
@@ -88,7 +61,7 @@ local _anon_func_9 = function(items)
88 end 61 end
89 return false 62 return false
90end 63end
91local _anon_func_10 = function(items) 64local _anon_func_7 = function(items)
92 local _val_0 = false 65 local _val_0 = false
93 for _index_0 = 1, #items do 66 for _index_0 = 1, #items do
94 if items[_index_0] == _val_0 then 67 if items[_index_0] == _val_0 then
@@ -97,7 +70,7 @@ local _anon_func_10 = function(items)
97 end 70 end
98 return false 71 return false
99end 72end
100local _anon_func_11 = function(empty) 73local _anon_func_8 = function(empty)
101 local _val_0 = 1 74 local _val_0 = 1
102 for _index_0 = 1, #empty do 75 for _index_0 = 1, #empty do
103 if empty[_index_0] == _val_0 then 76 if empty[_index_0] == _val_0 then
@@ -106,7 +79,7 @@ local _anon_func_11 = function(empty)
106 end 79 end
107 return false 80 return false
108end 81end
109local _anon_func_12 = function(empty) 82local _anon_func_9 = function(empty)
110 local _val_0 = "test" 83 local _val_0 = "test"
111 for _index_0 = 1, #empty do 84 for _index_0 = 1, #empty do
112 if empty[_index_0] == _val_0 then 85 if empty[_index_0] == _val_0 then
@@ -115,7 +88,7 @@ local _anon_func_12 = function(empty)
115 end 88 end
116 return false 89 return false
117end 90end
118local _anon_func_13 = function(items) 91local _anon_func_10 = function(items)
119 local _val_0 = 2 92 local _val_0 = 2
120 for _index_0 = 1, #items do 93 for _index_0 = 1, #items do
121 if items[_index_0] == _val_0 then 94 if items[_index_0] == _val_0 then
@@ -124,7 +97,7 @@ local _anon_func_13 = function(items)
124 end 97 end
125 return false 98 return false
126end 99end
127local _anon_func_14 = function(items) 100local _anon_func_11 = function(items)
128 local _val_0 = 4 101 local _val_0 = 4
129 for _index_0 = 1, #items do 102 for _index_0 = 1, #items do
130 if items[_index_0] == _val_0 then 103 if items[_index_0] == _val_0 then
@@ -133,7 +106,7 @@ local _anon_func_14 = function(items)
133 end 106 end
134 return false 107 return false
135end 108end
136local _anon_func_15 = function(items) 109local _anon_func_12 = function(items)
137 local _val_0 = 2 110 local _val_0 = 2
138 for _index_0 = 1, #items do 111 for _index_0 = 1, #items do
139 if items[_index_0] == _val_0 then 112 if items[_index_0] == _val_0 then
@@ -142,7 +115,7 @@ local _anon_func_15 = function(items)
142 end 115 end
143 return false 116 return false
144end 117end
145local _anon_func_16 = function(nested) 118local _anon_func_13 = function(nested)
146 local _val_0 = { 119 local _val_0 = {
147 1, 120 1,
148 2 121 2
@@ -154,7 +127,7 @@ local _anon_func_16 = function(nested)
154 end 127 end
155 return false 128 return false
156end 129end
157local _anon_func_17 = function(nested) 130local _anon_func_14 = function(nested)
158 local _val_0 = { 131 local _val_0 = {
159 1, 132 1,
160 3 133 3
@@ -166,7 +139,7 @@ local _anon_func_17 = function(nested)
166 end 139 end
167 return false 140 return false
168end 141end
169local _anon_func_18 = function(bools) 142local _anon_func_15 = function(bools)
170 local _val_0 = true 143 local _val_0 = true
171 for _index_0 = 1, #bools do 144 for _index_0 = 1, #bools do
172 if bools[_index_0] == _val_0 then 145 if bools[_index_0] == _val_0 then
@@ -175,7 +148,7 @@ local _anon_func_18 = function(bools)
175 end 148 end
176 return false 149 return false
177end 150end
178local _anon_func_19 = function(bools) 151local _anon_func_16 = function(bools)
179 local _val_0 = false 152 local _val_0 = false
180 for _index_0 = 1, #bools do 153 for _index_0 = 1, #bools do
181 if bools[_index_0] == _val_0 then 154 if bools[_index_0] == _val_0 then
@@ -184,7 +157,7 @@ local _anon_func_19 = function(bools)
184 end 157 end
185 return false 158 return false
186end 159end
187local _anon_func_20 = function(i, items) 160local _anon_func_17 = function(i, items)
188 for _index_0 = 1, #items do 161 for _index_0 = 1, #items do
189 if items[_index_0] == i then 162 if items[_index_0] == i then
190 return true 163 return true
@@ -192,7 +165,7 @@ local _anon_func_20 = function(i, items)
192 end 165 end
193 return false 166 return false
194end 167end
195local _anon_func_21 = function(key1, tb) 168local _anon_func_18 = function(key1, tb)
196 for _index_0 = 1, #tb do 169 for _index_0 = 1, #tb do
197 if tb[_index_0] == key1 then 170 if tb[_index_0] == key1 then
198 return true 171 return true
@@ -200,7 +173,7 @@ local _anon_func_21 = function(key1, tb)
200 end 173 end
201 return false 174 return false
202end 175end
203local _anon_func_22 = function(key2, tb) 176local _anon_func_19 = function(key2, tb)
204 for _index_0 = 1, #tb do 177 for _index_0 = 1, #tb do
205 if tb[_index_0] == key2 then 178 if tb[_index_0] == key2 then
206 return true 179 return true
@@ -208,7 +181,7 @@ local _anon_func_22 = function(key2, tb)
208 end 181 end
209 return false 182 return false
210end 183end
211local _anon_func_23 = function(get_items) 184local _anon_func_20 = function(get_items)
212 local _check_0 = get_items() 185 local _check_0 = get_items()
213 local _val_0 = 2 186 local _val_0 = 2
214 for _index_0 = 1, #_check_0 do 187 for _index_0 = 1, #_check_0 do
@@ -218,7 +191,7 @@ local _anon_func_23 = function(get_items)
218 end 191 end
219 return false 192 return false
220end 193end
221local _anon_func_24 = function(get_items) 194local _anon_func_21 = function(get_items)
222 local _check_0 = get_items() 195 local _check_0 = get_items()
223 local _val_0 = 5 196 local _val_0 = 5
224 for _index_0 = 1, #_check_0 do 197 for _index_0 = 1, #_check_0 do
@@ -228,7 +201,7 @@ local _anon_func_24 = function(get_items)
228 end 201 end
229 return false 202 return false
230end 203end
231local _anon_func_25 = function(items) 204local _anon_func_22 = function(items)
232 local _val_0 = nil 205 local _val_0 = nil
233 for _index_0 = 1, #items do 206 for _index_0 = 1, #items do
234 if items[_index_0] == _val_0 then 207 if items[_index_0] == _val_0 then
@@ -237,7 +210,7 @@ local _anon_func_25 = function(items)
237 end 210 end
238 return false 211 return false
239end 212end
240local _anon_func_26 = function(items) 213local _anon_func_23 = function(items)
241 local _val_0 = 1 214 local _val_0 = 1
242 for _index_0 = 1, #items do 215 for _index_0 = 1, #items do
243 if items[_index_0] == _val_0 then 216 if items[_index_0] == _val_0 then
@@ -246,7 +219,7 @@ local _anon_func_26 = function(items)
246 end 219 end
247 return false 220 return false
248end 221end
249local _anon_func_27 = function(obj) 222local _anon_func_24 = function(obj)
250 local _val_0 = "name" 223 local _val_0 = "name"
251 for _index_0 = 1, #obj do 224 for _index_0 = 1, #obj do
252 if obj[_index_0] == _val_0 then 225 if obj[_index_0] == _val_0 then
@@ -255,7 +228,7 @@ local _anon_func_27 = function(obj)
255 end 228 end
256 return false 229 return false
257end 230end
258local _anon_func_28 = function(obj) 231local _anon_func_25 = function(obj)
259 local _val_0 = "value" 232 local _val_0 = "value"
260 for _index_0 = 1, #obj do 233 for _index_0 = 1, #obj do
261 if obj[_index_0] == _val_0 then 234 if obj[_index_0] == _val_0 then
@@ -264,7 +237,7 @@ local _anon_func_28 = function(obj)
264 end 237 end
265 return false 238 return false
266end 239end
267local _anon_func_29 = function(obj) 240local _anon_func_26 = function(obj)
268 local _val_0 = "missing" 241 local _val_0 = "missing"
269 for _index_0 = 1, #obj do 242 for _index_0 = 1, #obj do
270 if obj[_index_0] == _val_0 then 243 if obj[_index_0] == _val_0 then
@@ -273,7 +246,7 @@ local _anon_func_29 = function(obj)
273 end 246 end
274 return false 247 return false
275end 248end
276local _anon_func_30 = function(items) 249local _anon_func_27 = function(items)
277 local _val_0 = 2 250 local _val_0 = 2
278 for _index_0 = 1, #items do 251 for _index_0 = 1, #items do
279 if items[_index_0] == _val_0 then 252 if items[_index_0] == _val_0 then
@@ -282,7 +255,7 @@ local _anon_func_30 = function(items)
282 end 255 end
283 return false 256 return false
284end 257end
285local _anon_func_31 = function(allowed, item) 258local _anon_func_28 = function(allowed, item)
286 for _index_0 = 1, #allowed do 259 for _index_0 = 1, #allowed do
287 if allowed[_index_0] == item then 260 if allowed[_index_0] == item then
288 return true 261 return true
@@ -311,15 +284,14 @@ return describe("in expression", function()
311 assert.is_true(_anon_func_2(chars)) 284 assert.is_true(_anon_func_2(chars))
312 return assert.is_false(_anon_func_3(chars)) 285 return assert.is_false(_anon_func_3(chars))
313 end) 286 end)
314 it("should check keys in table", function() 287 it("should check in table literal", function()
315 local obj = { 288 local x = 1
316 x = 1, 289 local y = 2
317 y = 2, 290 local z = 3
318 z = 3 291 local w = 4
319 } 292 assert.is_true((x == x or y == x or z == x))
320 assert.is_true(_anon_func_4(obj)) 293 assert.is_true((x == y or y == y or z == y))
321 assert.is_true(_anon_func_5(obj)) 294 return assert.is_false((x == w or y == w or z == w))
322 return assert.is_false(_anon_func_6(obj))
323 end) 295 end)
324 it("should work with mixed types", function() 296 it("should work with mixed types", function()
325 local items = { 297 local items = {
@@ -328,15 +300,15 @@ return describe("in expression", function()
328 true, 300 true,
329 nil 301 nil
330 } 302 }
331 assert.is_true(_anon_func_7(items)) 303 assert.is_true(_anon_func_4(items))
332 assert.is_true(_anon_func_8(items)) 304 assert.is_true(_anon_func_5(items))
333 assert.is_true(_anon_func_9(items)) 305 assert.is_true(_anon_func_6(items))
334 return assert.is_false(_anon_func_10(items)) 306 return assert.is_false(_anon_func_7(items))
335 end) 307 end)
336 it("should handle empty table", function() 308 it("should handle empty table", function()
337 local empty = { } 309 local empty = { }
338 assert.is_false(_anon_func_11(empty)) 310 assert.is_false(_anon_func_8(empty))
339 return assert.is_false(_anon_func_12(empty)) 311 return assert.is_false(_anon_func_9(empty))
340 end) 312 end)
341 it("should work in conditional", function() 313 it("should work in conditional", function()
342 local items = { 314 local items = {
@@ -345,7 +317,7 @@ return describe("in expression", function()
345 3 317 3
346 } 318 }
347 local result 319 local result
348 if _anon_func_13(items) then 320 if _anon_func_10(items) then
349 result = "found" 321 result = "found"
350 else 322 else
351 result = "not found" 323 result = "not found"
@@ -358,34 +330,44 @@ return describe("in expression", function()
358 2, 330 2,
359 3 331 3
360 } 332 }
361 assert.is_true(not (_anon_func_14(items))) 333 assert.is_true(not (_anon_func_11(items)))
362 return assert.is_false(not (_anon_func_15(items))) 334 return assert.is_false(not (_anon_func_12(items)))
363 end) 335 end)
364 it("should work with nested tables", function() 336 it("should work with nested tables", function()
337 local eq
338 eq = function(self, other)
339 return self[1] == other[1] and self[2] == other[2]
340 end
365 local nested = { 341 local nested = {
366 { 342 setmetatable({
367 1, 343 1,
368 2 344 2,
369 }, 345 }, {
370 { 346 __eq = eq
347 }),
348 setmetatable({
371 3, 349 3,
372 4 350 4,
373 }, 351 }, {
374 { 352 __eq = eq
353 }),
354 setmetatable({
375 5, 355 5,
376 6 356 6,
377 } 357 }, {
358 __eq = eq
359 })
378 } 360 }
379 assert.is_true(_anon_func_16(nested)) 361 assert.is_true(_anon_func_13(nested))
380 return assert.is_false(_anon_func_17(nested)) 362 return assert.is_false(_anon_func_14(nested))
381 end) 363 end)
382 it("should handle boolean values", function() 364 it("should handle boolean values", function()
383 local bools = { 365 local bools = {
384 true, 366 true,
385 false 367 false
386 } 368 }
387 assert.is_true(_anon_func_18(bools)) 369 assert.is_true(_anon_func_15(bools))
388 return assert.is_true(_anon_func_19(bools)) 370 return assert.is_true(_anon_func_16(bools))
389 end) 371 end)
390 it("should work in loop", function() 372 it("should work in loop", function()
391 local items = { 373 local items = {
@@ -397,7 +379,7 @@ return describe("in expression", function()
397 } 379 }
398 local count = 0 380 local count = 0
399 for i = 1, 10 do 381 for i = 1, 10 do
400 if (#items > 0 and _anon_func_20(i, items)) then 382 if (#items > 0 and _anon_func_17(i, items)) then
401 count = count + 1 383 count = count + 1
402 end 384 end
403 end 385 end
@@ -411,11 +393,11 @@ return describe("in expression", function()
411 b = 2 393 b = 2
412 } 394 }
413 local tb = { 395 local tb = {
414 [key1] = "first", 396 key1,
415 [key2] = "second" 397 key2
416 } 398 }
417 assert.is_true((#tb > 0 and _anon_func_21(key1, tb))) 399 assert.is_true((#tb > 0 and _anon_func_18(key1, tb)))
418 return assert.is_true((#tb > 0 and _anon_func_22(key2, tb))) 400 return assert.is_true((#tb > 0 and _anon_func_19(key2, tb)))
419 end) 401 end)
420 it("should work with function results", function() 402 it("should work with function results", function()
421 local get_items 403 local get_items
@@ -426,8 +408,8 @@ return describe("in expression", function()
426 3 408 3
427 } 409 }
428 end 410 end
429 assert.is_true(_anon_func_23(get_items)) 411 assert.is_true(_anon_func_20(get_items))
430 return assert.is_false(_anon_func_24(get_items)) 412 return assert.is_false(_anon_func_21(get_items))
431 end) 413 end)
432 it("should handle nil in table", function() 414 it("should handle nil in table", function()
433 local items = { 415 local items = {
@@ -435,17 +417,17 @@ return describe("in expression", function()
435 nil, 417 nil,
436 3 418 3
437 } 419 }
438 assert.is_true(_anon_func_25(items)) 420 assert.is_true(_anon_func_22(items))
439 return assert.is_true(_anon_func_26(items)) 421 return assert.is_true(_anon_func_23(items))
440 end) 422 end)
441 it("should work with string keys", function() 423 it("should work with string keys", function()
442 local obj = { 424 local obj = {
443 name = "test", 425 "name",
444 value = 42 426 "value"
445 } 427 }
446 assert.is_true(_anon_func_27(obj)) 428 assert.is_true(_anon_func_24(obj))
447 assert.is_true(_anon_func_28(obj)) 429 assert.is_true(_anon_func_25(obj))
448 return assert.is_false(_anon_func_29(obj)) 430 return assert.is_false(_anon_func_26(obj))
449 end) 431 end)
450 it("should support complex expressions", function() 432 it("should support complex expressions", function()
451 local items = { 433 local items = {
@@ -453,7 +435,7 @@ return describe("in expression", function()
453 2, 435 2,
454 3 436 3
455 } 437 }
456 local result = (_anon_func_30(items)) and "yes" or "no" 438 local result = (_anon_func_27(items)) and "yes" or "no"
457 return assert.same(result, "yes") 439 return assert.same(result, "yes")
458 end) 440 end)
459 return it("should work in comprehension", function() 441 return it("should work in comprehension", function()
@@ -474,7 +456,7 @@ return describe("in expression", function()
474 local _len_0 = 1 456 local _len_0 = 1
475 for _index_0 = 1, #source do 457 for _index_0 = 1, #source do
476 local item = source[_index_0] 458 local item = source[_index_0]
477 if (#allowed > 0 and _anon_func_31(allowed, item)) then 459 if (#allowed > 0 and _anon_func_28(allowed, item)) then
478 _accum_0[_len_0] = item 460 _accum_0[_len_0] = item
479 _len_0 = _len_0 + 1 461 _len_0 = _len_0 + 1
480 end 462 end