aboutsummaryrefslogtreecommitdiff
path: root/spec/inputs/test/while_assignment_spec.yue
diff options
context:
space:
mode:
authorLi Jin <dragon-fly@qq.com>2026-01-27 00:30:56 +0000
committerLi Jin <dragon-fly@qq.com>2026-01-27 00:30:56 +0000
commit7c2a92b82e9808d3c5ea29b47d1c59d663fe984a (patch)
treeceba95c48bd8d5d9fff3d1206483ddf073c0e03d /spec/inputs/test/while_assignment_spec.yue
parente70e63a9737ed3a9e72f1329901075498190e6b4 (diff)
downloadyuescript-compiler-improvements.tar.gz
yuescript-compiler-improvements.tar.bz2
yuescript-compiler-improvements.zip
Add compiler improvements and comprehensive test suitecompiler-improvements
- Fixed path option handling to avoid semicolon concatenation issues - Added exception handling for std::length_error and general exceptions - Added comprehensive test specifications for advanced language features Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Diffstat (limited to 'spec/inputs/test/while_assignment_spec.yue')
-rw-r--r--spec/inputs/test/while_assignment_spec.yue42
1 files changed, 42 insertions, 0 deletions
diff --git a/spec/inputs/test/while_assignment_spec.yue b/spec/inputs/test/while_assignment_spec.yue
new file mode 100644
index 0000000..1c98e58
--- /dev/null
+++ b/spec/inputs/test/while_assignment_spec.yue
@@ -0,0 +1,42 @@
1describe "while assignment", ->
2 it "should loop while value is truthy", ->
3 counter = 0
4 get_next = ->
5 if counter < 3
6 counter += 1
7 counter
8 else
9 nil
10 results = {}
11 while val := get_next!
12 table.insert results, val
13 assert.same results, {1, 2, 3}
14
15 it "should work with function results", ->
16 counter = 0
17 fn = ->
18 counter += 1
19 if counter <= 3
20 counter * 10
21 else
22 nil
23
24 sum = 0
25 while val := fn!
26 sum += val
27 assert.same sum, 60 -- (10+20+30)
28
29 it "should exit immediately on nil", ->
30 get_val = -> nil
31 counter = 0
32 while val := get_val!
33 counter += 1
34 assert.same counter, 0
35
36 it "should support break in loop", ->
37 items = {1, 2, 3, 4, 5}
38 sum = 0
39 for item in *items
40 sum += item
41 break if sum > 6
42 assert.same sum, 10