From 3159a45de9e691ad758dcbc933446f61b7ae1940 Mon Sep 17 00:00:00 2001 From: Li Jin Date: Thu, 14 Jul 2022 02:48:49 +0800 Subject: fix table matching issue and update doc. --- spec/inputs/switch.yue | 6 +++--- spec/outputs/switch.lua | 28 ++++++++++++---------------- 2 files changed, 15 insertions(+), 19 deletions(-) (limited to 'spec') diff --git a/spec/inputs/switch.yue b/spec/inputs/switch.yue index 36f9be6..04bb02e 100644 --- a/spec/inputs/switch.yue +++ b/spec/inputs/switch.yue @@ -139,10 +139,10 @@ do "#{a + b}" when 1, 2, 3, 4, 5 "number 1 - 5" - when {:alwaysMatch = "fallback"} - alwaysMatch + when {:matchAnyTable = "fallback"} + matchAnyTable else - "should not reach here" + "should not reach here unless it is not a table" nil diff --git a/spec/outputs/switch.lua b/spec/outputs/switch.lua index 03a0d37..7b413f8 100644 --- a/spec/outputs/switch.lua +++ b/spec/outputs/switch.lua @@ -182,8 +182,8 @@ do local x = item.x local y = item.y if x ~= nil and y ~= nil then - print("Vec2 " .. tostring(x) .. ", " .. tostring(y)) _match_0 = true + print("Vec2 " .. tostring(x) .. ", " .. tostring(y)) end end if not _match_0 then @@ -192,8 +192,8 @@ do local width = item.width local height = item.height if width ~= nil and height ~= nil then - print("Size " .. tostring(width) .. ", " .. tostring(height)) _match_1 = true + print("Size " .. tostring(width) .. ", " .. tostring(height)) end end if not _match_1 then @@ -204,12 +204,12 @@ do if _tab_0 then local cls = item.__class if cls ~= nil then + _match_2 = true if ClassA == cls then print("Object A") elseif ClassB == cls then print("Object B") end - _match_2 = true end end if not _match_2 then @@ -241,9 +241,7 @@ do if b == nil then b = 2 end - if a ~= nil and b ~= nil then - print(a, b) - end + print(a, b) end end end @@ -258,8 +256,8 @@ do local x = tb.x local y = tb.y if x ~= nil and y ~= nil then - print("x: " .. tostring(x) .. " with y: " .. tostring(y)) _match_0 = true + print("x: " .. tostring(x) .. " with y: " .. tostring(y)) end end if not _match_0 then @@ -284,8 +282,8 @@ do if _tab_0 then local x = _exp_0.x if x ~= nil then - matched = x _match_0 = true + matched = x end end if not _match_0 then @@ -310,8 +308,8 @@ do local a = _exp_0.a local b = _exp_0.b if a ~= nil and b ~= nil then - return tostring(a + b) _match_0 = true + return tostring(a + b) end end if not _match_0 then @@ -319,15 +317,13 @@ do return "number 1 - 5" else if _tab_0 then - local alwaysMatch = _exp_0.alwaysMatch - if alwaysMatch == nil then - alwaysMatch = "fallback" - end - if alwaysMatch ~= nil then - return alwaysMatch + local matchAnyTable = _exp_0.matchAnyTable + if matchAnyTable == nil then + matchAnyTable = "fallback" end + return matchAnyTable else - return "should not reach here" + return "should not reach here unless it is not a table" end end end -- cgit v1.2.3-55-g6feb