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/inputs/switch.yue | 54 +++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 53 insertions(+), 1 deletion(-) (limited to 'spec/inputs/switch.yue') diff --git a/spec/inputs/switch.yue b/spec/inputs/switch.yue index 7ff3118..5097db3 100644 --- a/spec/inputs/switch.yue +++ b/spec/inputs/switch.yue @@ -220,4 +220,56 @@ do ] print "matched", sixth -nil \ No newline at end of file +do + switch v := "hello" + when "hello" + print "matched hello" + else + print "not matched" + -- output: matched hello + +do + f = -> "ok" + switch val := f! + when "ok" + print "it's ok" + -- output: it's ok + + +do + g = -> 42 + switch result := g! + when 1, 2 + print "small" + when 42 + print "life universe everything" + else + print "other #{result}" + -- output: life universe everything + +do + check = -> + if true + "yes" + else + "no" + + switch x := check! + when "yes" + print "affirmative" + else + print "negative" + -- output: affirmative + +do + t = (): tb -> + tb = {a: 1} + tb.a = 2 + + switch data := t! + when {a: 2} + print "matched" + else + print "not matched" + +nil -- cgit v1.2.3-55-g6feb