From fcb480618f162817572947cfed96b1ba0d6c5a44 Mon Sep 17 00:00:00 2001 From: Li Jin Date: Thu, 20 Jul 2023 18:25:10 +0800 Subject: fix wrong codes generation for in-expression. --- spec/inputs/in_expression.yue | 9 ++++- spec/outputs/in_expression.lua | 74 ++++++++++++++++++++++++++++++++++-------- 2 files changed, 69 insertions(+), 14 deletions(-) (limited to 'spec') diff --git a/spec/inputs/in_expression.yue b/spec/inputs/in_expression.yue index 4080016..6e923e1 100644 --- a/spec/inputs/in_expression.yue +++ b/spec/inputs/in_expression.yue @@ -39,7 +39,14 @@ do not_exist = item not in list check item in list check item in {1, 2, 3} - check item in {[1]: 1, [2]: 2, [3]: 3} + check item(...) in {[1]: 1, [2]: 2, [3]: 3} + +do + check -> x in tb + check -> x not in tb + local x, tb + check -> return x in tb + check -> x not in tb nil diff --git a/spec/outputs/in_expression.lua b/spec/outputs/in_expression.lua index ccc5fd0..ddba69a 100644 --- a/spec/outputs/in_expression.lua +++ b/spec/outputs/in_expression.lua @@ -66,15 +66,19 @@ do end do local item = get() - local exist = (function() + local exist + do local _check_0 = list + local _find_0 = false for _index_0 = 1, #_check_0 do - if _check_0[_index_0] == item then - return true + local _item_0 = _check_0[_index_0] + if _item_0 == item then + _find_0 = true + break end end - return false - end)() + exist = _find_0 + end check((function() local _check_0 = list for _index_0 = 1, #_check_0 do @@ -92,14 +96,18 @@ do 2, 3 } - local not_exist = not (#list > 0 and (function() + local not_exist + do + local _find_0 = false for _index_0 = 1, #list do - if list[_index_0] == item then - return true + local _item_0 = list[_index_0] + if _item_0 == item then + _find_0 = true + break end end - return false - end)()) + not_exist = not _find_0 + end check((#list > 0 and (function() for _index_0 = 1, #list do if list[_index_0] == item then @@ -109,18 +117,58 @@ do return false end)())) check((1 == item or 2 == item or 3 == item)) - check((function() + check((function(...) local _check_0 = { [1] = 1, [2] = 2, [3] = 3 } + local _val_0 = item(...) for _index_0 = 1, #_check_0 do - if _check_0[_index_0] == item then + if _check_0[_index_0] == _val_0 then return true end end return false - end)()) + end)(...)) +end +do + check(function() + local _check_0 = tb + local _val_0 = x + for _index_0 = 1, #_check_0 do + if _check_0[_index_0] == _val_0 then + return true + end + end + return false + end) + check(function() + local _check_0 = tb + local _val_0 = x + for _index_0 = 1, #_check_0 do + if _check_0[_index_0] == _val_0 then + return false + end + end + return true + end) + local x, tb + check(function() + for _index_0 = 1, #tb do + if tb[_index_0] == x then + return true + end + end + return false + end) + check(function() + for _index_0 = 1, #tb do + if tb[_index_0] == x then + return false + end + end + return true + end) end return nil -- cgit v1.2.3-55-g6feb