From 85a2da5cbbbbfb27f3b65ac67d083dd2443d223d Mon Sep 17 00:00:00 2001 From: Li Jin Date: Fri, 30 Jun 2023 18:48:20 +0800 Subject: support list table checking to in-expression for issue #140 --- spec/inputs/in_expression.yue | 17 +++++++++ spec/outputs/in_expression.lua | 85 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 102 insertions(+) (limited to 'spec') diff --git a/spec/inputs/in_expression.yue b/spec/inputs/in_expression.yue index dacf820..66a8215 100644 --- a/spec/inputs/in_expression.yue +++ b/spec/inputs/in_expression.yue @@ -24,5 +24,22 @@ switch val do return y not in (a, b) +do + exist = item in list + check item in list + +do + item = get! + exist = item in list + check item in list + +do + item = get! + list = {1, 2, 3} + exist = item in list + check item in list + check item in {1, 2, 3} + check item in {[1]: 1, [2]: 2, [3]: 3} + nil diff --git a/spec/outputs/in_expression.lua b/spec/outputs/in_expression.lua index 8b37a72..41ae87e 100644 --- a/spec/outputs/in_expression.lua +++ b/spec/outputs/in_expression.lua @@ -38,4 +38,89 @@ do local _val_0 = y return not (a < _val_0 and _val_0 < b) end +do + local exist + do + local _check_0 = list + local _val_0 = item + local _find_0 = false + for _index_0 = 1, #_check_0 do + local _item_0 = _check_0[_index_0] + if _item_0 == _val_0 then + _find_0 = true + break + end + end + exist = _find_0 + end + check((function() + local _check_0 = list + local _val_0 = item + for _index_0 = 1, #_check_0 do + if _check_0[_index_0] == _val_0 then + return true + end + end + return false + end)()) +end +do + local item = get() + local exist = (function() + local _check_0 = list + for _index_0 = 1, #_check_0 do + if _check_0[_index_0] == item then + return true + end + end + return false + end)() + check((function() + local _check_0 = list + for _index_0 = 1, #_check_0 do + if _check_0[_index_0] == item then + return true + end + end + return false + end)()) +end +do + local item = get() + local list = { + 1, + 2, + 3 + } + local exist = (#list > 0 and (function() + for _index_0 = 1, #list do + if list[_index_0] == item then + return true + end + end + return false + end)()) + check((#list > 0 and (function() + for _index_0 = 1, #list do + if list[_index_0] == item then + return true + end + end + return false + end)())) + check((1 == item or 2 == item or 3 == item)) + check((function() + local _check_0 = { + [1] = 1, + [2] = 2, + [3] = 3 + } + for _index_0 = 1, #_check_0 do + if _check_0[_index_0] == item then + return true + end + end + return false + end)()) +end return nil -- cgit v1.2.3-55-g6feb