From a91135ce512f907ed085d9aac147d8fcad356406 Mon Sep 17 00:00:00 2001 From: Li Jin Date: Mon, 26 May 2025 11:07:38 +0800 Subject: Added assignment expression for switch syntax. --- spec/outputs/switch.lua | 71 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) (limited to 'spec/outputs/switch.lua') diff --git a/spec/outputs/switch.lua b/spec/outputs/switch.lua index 0f8bba2..204b816 100644 --- a/spec/outputs/switch.lua +++ b/spec/outputs/switch.lua @@ -656,4 +656,75 @@ do end end end +do + local v = "hello" + if "hello" == v then + print("matched hello") + else + print("not matched") + end +end +do + local f + f = function() + return "ok" + end + local val = f() + if "ok" == val then + print("it's ok") + end +end +do + local g + g = function() + return 42 + end + local result = g() + if 1 == result or 2 == result then + print("small") + elseif 42 == result then + print("life universe everything") + else + print("other " .. tostring(result)) + end +end +do + local check + check = function() + if true then + return "yes" + else + return "no" + end + end + local x = check() + if "yes" == x then + print("affirmative") + else + print("negative") + end +end +do + local t + t = function() + local tb = { + a = 1 + } + tb.a = 2 + return tb + end + local data = t() + local _type_0 = type(data) + local _tab_0 = "table" == _type_0 or "userdata" == _type_0 + local _match_0 = false + if _tab_0 then + if 2 == data.a then + _match_0 = true + print("matched") + end + end + if not _match_0 then + print("not matched") + end +end return nil -- cgit v1.2.3-55-g6feb