From dd64edd58fe25ec74ae5958128cf3f74b0692f3b Mon Sep 17 00:00:00 2001 From: Li Jin Date: Wed, 28 Jan 2026 18:43:14 +0800 Subject: Fixed compiler issues and added 800+ test cases. --- spec/outputs/test/in_expression_spec.lua | 180 ++++++++++++++----------------- 1 file changed, 81 insertions(+), 99 deletions(-) (limited to 'spec/outputs/test/in_expression_spec.lua') 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) end return false end -local _anon_func_4 = function(obj) - local _val_0 = "x" - for _index_0 = 1, #obj do - if obj[_index_0] == _val_0 then - return true - end - end - return false -end -local _anon_func_5 = function(obj) - local _val_0 = "y" - for _index_0 = 1, #obj do - if obj[_index_0] == _val_0 then - return true - end - end - return false -end -local _anon_func_6 = function(obj) - local _val_0 = "w" - for _index_0 = 1, #obj do - if obj[_index_0] == _val_0 then - return true - end - end - return false -end -local _anon_func_7 = function(items) +local _anon_func_4 = function(items) local _val_0 = 1 for _index_0 = 1, #items do if items[_index_0] == _val_0 then @@ -70,7 +43,7 @@ local _anon_func_7 = function(items) end return false end -local _anon_func_8 = function(items) +local _anon_func_5 = function(items) local _val_0 = "two" for _index_0 = 1, #items do if items[_index_0] == _val_0 then @@ -79,7 +52,7 @@ local _anon_func_8 = function(items) end return false end -local _anon_func_9 = function(items) +local _anon_func_6 = function(items) local _val_0 = true for _index_0 = 1, #items do if items[_index_0] == _val_0 then @@ -88,7 +61,7 @@ local _anon_func_9 = function(items) end return false end -local _anon_func_10 = function(items) +local _anon_func_7 = function(items) local _val_0 = false for _index_0 = 1, #items do if items[_index_0] == _val_0 then @@ -97,7 +70,7 @@ local _anon_func_10 = function(items) end return false end -local _anon_func_11 = function(empty) +local _anon_func_8 = function(empty) local _val_0 = 1 for _index_0 = 1, #empty do if empty[_index_0] == _val_0 then @@ -106,7 +79,7 @@ local _anon_func_11 = function(empty) end return false end -local _anon_func_12 = function(empty) +local _anon_func_9 = function(empty) local _val_0 = "test" for _index_0 = 1, #empty do if empty[_index_0] == _val_0 then @@ -115,7 +88,7 @@ local _anon_func_12 = function(empty) end return false end -local _anon_func_13 = function(items) +local _anon_func_10 = function(items) local _val_0 = 2 for _index_0 = 1, #items do if items[_index_0] == _val_0 then @@ -124,7 +97,7 @@ local _anon_func_13 = function(items) end return false end -local _anon_func_14 = function(items) +local _anon_func_11 = function(items) local _val_0 = 4 for _index_0 = 1, #items do if items[_index_0] == _val_0 then @@ -133,7 +106,7 @@ local _anon_func_14 = function(items) end return false end -local _anon_func_15 = function(items) +local _anon_func_12 = function(items) local _val_0 = 2 for _index_0 = 1, #items do if items[_index_0] == _val_0 then @@ -142,7 +115,7 @@ local _anon_func_15 = function(items) end return false end -local _anon_func_16 = function(nested) +local _anon_func_13 = function(nested) local _val_0 = { 1, 2 @@ -154,7 +127,7 @@ local _anon_func_16 = function(nested) end return false end -local _anon_func_17 = function(nested) +local _anon_func_14 = function(nested) local _val_0 = { 1, 3 @@ -166,7 +139,7 @@ local _anon_func_17 = function(nested) end return false end -local _anon_func_18 = function(bools) +local _anon_func_15 = function(bools) local _val_0 = true for _index_0 = 1, #bools do if bools[_index_0] == _val_0 then @@ -175,7 +148,7 @@ local _anon_func_18 = function(bools) end return false end -local _anon_func_19 = function(bools) +local _anon_func_16 = function(bools) local _val_0 = false for _index_0 = 1, #bools do if bools[_index_0] == _val_0 then @@ -184,7 +157,7 @@ local _anon_func_19 = function(bools) end return false end -local _anon_func_20 = function(i, items) +local _anon_func_17 = function(i, items) for _index_0 = 1, #items do if items[_index_0] == i then return true @@ -192,7 +165,7 @@ local _anon_func_20 = function(i, items) end return false end -local _anon_func_21 = function(key1, tb) +local _anon_func_18 = function(key1, tb) for _index_0 = 1, #tb do if tb[_index_0] == key1 then return true @@ -200,7 +173,7 @@ local _anon_func_21 = function(key1, tb) end return false end -local _anon_func_22 = function(key2, tb) +local _anon_func_19 = function(key2, tb) for _index_0 = 1, #tb do if tb[_index_0] == key2 then return true @@ -208,7 +181,7 @@ local _anon_func_22 = function(key2, tb) end return false end -local _anon_func_23 = function(get_items) +local _anon_func_20 = function(get_items) local _check_0 = get_items() local _val_0 = 2 for _index_0 = 1, #_check_0 do @@ -218,7 +191,7 @@ local _anon_func_23 = function(get_items) end return false end -local _anon_func_24 = function(get_items) +local _anon_func_21 = function(get_items) local _check_0 = get_items() local _val_0 = 5 for _index_0 = 1, #_check_0 do @@ -228,7 +201,7 @@ local _anon_func_24 = function(get_items) end return false end -local _anon_func_25 = function(items) +local _anon_func_22 = function(items) local _val_0 = nil for _index_0 = 1, #items do if items[_index_0] == _val_0 then @@ -237,7 +210,7 @@ local _anon_func_25 = function(items) end return false end -local _anon_func_26 = function(items) +local _anon_func_23 = function(items) local _val_0 = 1 for _index_0 = 1, #items do if items[_index_0] == _val_0 then @@ -246,7 +219,7 @@ local _anon_func_26 = function(items) end return false end -local _anon_func_27 = function(obj) +local _anon_func_24 = function(obj) local _val_0 = "name" for _index_0 = 1, #obj do if obj[_index_0] == _val_0 then @@ -255,7 +228,7 @@ local _anon_func_27 = function(obj) end return false end -local _anon_func_28 = function(obj) +local _anon_func_25 = function(obj) local _val_0 = "value" for _index_0 = 1, #obj do if obj[_index_0] == _val_0 then @@ -264,7 +237,7 @@ local _anon_func_28 = function(obj) end return false end -local _anon_func_29 = function(obj) +local _anon_func_26 = function(obj) local _val_0 = "missing" for _index_0 = 1, #obj do if obj[_index_0] == _val_0 then @@ -273,7 +246,7 @@ local _anon_func_29 = function(obj) end return false end -local _anon_func_30 = function(items) +local _anon_func_27 = function(items) local _val_0 = 2 for _index_0 = 1, #items do if items[_index_0] == _val_0 then @@ -282,7 +255,7 @@ local _anon_func_30 = function(items) end return false end -local _anon_func_31 = function(allowed, item) +local _anon_func_28 = function(allowed, item) for _index_0 = 1, #allowed do if allowed[_index_0] == item then return true @@ -311,15 +284,14 @@ return describe("in expression", function() assert.is_true(_anon_func_2(chars)) return assert.is_false(_anon_func_3(chars)) end) - it("should check keys in table", function() - local obj = { - x = 1, - y = 2, - z = 3 - } - assert.is_true(_anon_func_4(obj)) - assert.is_true(_anon_func_5(obj)) - return assert.is_false(_anon_func_6(obj)) + it("should check in table literal", function() + local x = 1 + local y = 2 + local z = 3 + local w = 4 + assert.is_true((x == x or y == x or z == x)) + assert.is_true((x == y or y == y or z == y)) + return assert.is_false((x == w or y == w or z == w)) end) it("should work with mixed types", function() local items = { @@ -328,15 +300,15 @@ return describe("in expression", function() true, nil } - assert.is_true(_anon_func_7(items)) - assert.is_true(_anon_func_8(items)) - assert.is_true(_anon_func_9(items)) - return assert.is_false(_anon_func_10(items)) + assert.is_true(_anon_func_4(items)) + assert.is_true(_anon_func_5(items)) + assert.is_true(_anon_func_6(items)) + return assert.is_false(_anon_func_7(items)) end) it("should handle empty table", function() local empty = { } - assert.is_false(_anon_func_11(empty)) - return assert.is_false(_anon_func_12(empty)) + assert.is_false(_anon_func_8(empty)) + return assert.is_false(_anon_func_9(empty)) end) it("should work in conditional", function() local items = { @@ -345,7 +317,7 @@ return describe("in expression", function() 3 } local result - if _anon_func_13(items) then + if _anon_func_10(items) then result = "found" else result = "not found" @@ -358,34 +330,44 @@ return describe("in expression", function() 2, 3 } - assert.is_true(not (_anon_func_14(items))) - return assert.is_false(not (_anon_func_15(items))) + assert.is_true(not (_anon_func_11(items))) + return assert.is_false(not (_anon_func_12(items))) end) it("should work with nested tables", function() + local eq + eq = function(self, other) + return self[1] == other[1] and self[2] == other[2] + end local nested = { - { + setmetatable({ 1, - 2 - }, - { + 2, + }, { + __eq = eq + }), + setmetatable({ 3, - 4 - }, - { + 4, + }, { + __eq = eq + }), + setmetatable({ 5, - 6 - } + 6, + }, { + __eq = eq + }) } - assert.is_true(_anon_func_16(nested)) - return assert.is_false(_anon_func_17(nested)) + assert.is_true(_anon_func_13(nested)) + return assert.is_false(_anon_func_14(nested)) end) it("should handle boolean values", function() local bools = { true, false } - assert.is_true(_anon_func_18(bools)) - return assert.is_true(_anon_func_19(bools)) + assert.is_true(_anon_func_15(bools)) + return assert.is_true(_anon_func_16(bools)) end) it("should work in loop", function() local items = { @@ -397,7 +379,7 @@ return describe("in expression", function() } local count = 0 for i = 1, 10 do - if (#items > 0 and _anon_func_20(i, items)) then + if (#items > 0 and _anon_func_17(i, items)) then count = count + 1 end end @@ -411,11 +393,11 @@ return describe("in expression", function() b = 2 } local tb = { - [key1] = "first", - [key2] = "second" + key1, + key2 } - assert.is_true((#tb > 0 and _anon_func_21(key1, tb))) - return assert.is_true((#tb > 0 and _anon_func_22(key2, tb))) + assert.is_true((#tb > 0 and _anon_func_18(key1, tb))) + return assert.is_true((#tb > 0 and _anon_func_19(key2, tb))) end) it("should work with function results", function() local get_items @@ -426,8 +408,8 @@ return describe("in expression", function() 3 } end - assert.is_true(_anon_func_23(get_items)) - return assert.is_false(_anon_func_24(get_items)) + assert.is_true(_anon_func_20(get_items)) + return assert.is_false(_anon_func_21(get_items)) end) it("should handle nil in table", function() local items = { @@ -435,17 +417,17 @@ return describe("in expression", function() nil, 3 } - assert.is_true(_anon_func_25(items)) - return assert.is_true(_anon_func_26(items)) + assert.is_true(_anon_func_22(items)) + return assert.is_true(_anon_func_23(items)) end) it("should work with string keys", function() local obj = { - name = "test", - value = 42 + "name", + "value" } - assert.is_true(_anon_func_27(obj)) - assert.is_true(_anon_func_28(obj)) - return assert.is_false(_anon_func_29(obj)) + assert.is_true(_anon_func_24(obj)) + assert.is_true(_anon_func_25(obj)) + return assert.is_false(_anon_func_26(obj)) end) it("should support complex expressions", function() local items = { @@ -453,7 +435,7 @@ return describe("in expression", function() 2, 3 } - local result = (_anon_func_30(items)) and "yes" or "no" + local result = (_anon_func_27(items)) and "yes" or "no" return assert.same(result, "yes") end) return it("should work in comprehension", function() @@ -474,7 +456,7 @@ return describe("in expression", function() local _len_0 = 1 for _index_0 = 1, #source do local item = source[_index_0] - if (#allowed > 0 and _anon_func_31(allowed, item)) then + if (#allowed > 0 and _anon_func_28(allowed, item)) then _accum_0[_len_0] = item _len_0 = _len_0 + 1 end -- cgit v1.2.3-55-g6feb