aboutsummaryrefslogtreecommitdiff
path: root/spec/inputs/switch.yue
diff options
context:
space:
mode:
authorLi Jin <dragon-fly@qq.com>2025-05-26 11:07:38 +0800
committerLi Jin <dragon-fly@qq.com>2025-05-26 11:07:38 +0800
commita91135ce512f907ed085d9aac147d8fcad356406 (patch)
treee53408fe0a88ef71ea33d14bcb0b6eeb3a344810 /spec/inputs/switch.yue
parent4ba4c90e711c6204aa40e38347c5a5a076d9370e (diff)
downloadyuescript-a91135ce512f907ed085d9aac147d8fcad356406.tar.gz
yuescript-a91135ce512f907ed085d9aac147d8fcad356406.tar.bz2
yuescript-a91135ce512f907ed085d9aac147d8fcad356406.zip
Added assignment expression for switch syntax.
Diffstat (limited to 'spec/inputs/switch.yue')
-rw-r--r--spec/inputs/switch.yue54
1 files changed, 53 insertions, 1 deletions
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
220 ] 220 ]
221 print "matched", sixth 221 print "matched", sixth
222 222
223nil \ No newline at end of file 223do
224 switch v := "hello"
225 when "hello"
226 print "matched hello"
227 else
228 print "not matched"
229 -- output: matched hello
230
231do
232 f = -> "ok"
233 switch val := f!
234 when "ok"
235 print "it's ok"
236 -- output: it's ok
237
238
239do
240 g = -> 42
241 switch result := g!
242 when 1, 2
243 print "small"
244 when 42
245 print "life universe everything"
246 else
247 print "other #{result}"
248 -- output: life universe everything
249
250do
251 check = ->
252 if true
253 "yes"
254 else
255 "no"
256
257 switch x := check!
258 when "yes"
259 print "affirmative"
260 else
261 print "negative"
262 -- output: affirmative
263
264do
265 t = (): tb ->
266 tb = {a: 1}
267 tb.a = 2
268
269 switch data := t!
270 when {a: 2}
271 print "matched"
272 else
273 print "not matched"
274
275nil