diff options
| author | Li Jin <dragon-fly@qq.com> | 2026-01-27 00:30:56 +0000 |
|---|---|---|
| committer | Li Jin <dragon-fly@qq.com> | 2026-01-27 00:30:56 +0000 |
| commit | 7c2a92b82e9808d3c5ea29b47d1c59d663fe984a (patch) | |
| tree | ceba95c48bd8d5d9fff3d1206483ddf073c0e03d /spec/inputs/test/varargs_assignment_spec.yue | |
| parent | e70e63a9737ed3a9e72f1329901075498190e6b4 (diff) | |
| download | yuescript-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/varargs_assignment_spec.yue')
| -rw-r--r-- | spec/inputs/test/varargs_assignment_spec.yue | 96 |
1 files changed, 96 insertions, 0 deletions
diff --git a/spec/inputs/test/varargs_assignment_spec.yue b/spec/inputs/test/varargs_assignment_spec.yue new file mode 100644 index 0000000..1c3b627 --- /dev/null +++ b/spec/inputs/test/varargs_assignment_spec.yue | |||
| @@ -0,0 +1,96 @@ | |||
| 1 | describe "varargs assignment", -> | ||
| 2 | it "should assign varargs from function", -> | ||
| 3 | list = [1, 2, 3, 4, 5] | ||
| 4 | fn = (ok) -> ok, table.unpack list | ||
| 5 | ok, ... = fn true | ||
| 6 | count = select '#', ... | ||
| 7 | assert.same count, 5 | ||
| 8 | assert.same ok, true | ||
| 9 | |||
| 10 | it "should access varargs elements", -> | ||
| 11 | list = [10, 20, 30] | ||
| 12 | fn = -> table.unpack list | ||
| 13 | ... = fn! | ||
| 14 | first = select 1, ... | ||
| 15 | second = select 2, ... | ||
| 16 | third = select 3, ... | ||
| 17 | assert.same first, 10 | ||
| 18 | assert.same second, 20 | ||
| 19 | assert.same third, 30 | ||
| 20 | |||
| 21 | it "should work with pcall", -> | ||
| 22 | fn = -> 1, 2, 3 | ||
| 23 | success, ... = pcall fn | ||
| 24 | assert.is_true success | ||
| 25 | assert.same select('#', ...), 3 | ||
| 26 | |||
| 27 | it "should handle empty varargs", -> | ||
| 28 | fn = -> | ||
| 29 | ... = fn! | ||
| 30 | count = select '#', ... | ||
| 31 | assert.same count, 0 | ||
| 32 | |||
| 33 | it "should work with mixed return values", -> | ||
| 34 | fn = -> "first", nil, "third", false | ||
| 35 | a, ... = fn! | ||
| 36 | assert.same a, "first" | ||
| 37 | assert.same select('#', ...), 3 | ||
| 38 | |||
| 39 | it "should preserve nil values in varargs", -> | ||
| 40 | fn = -> 1, nil, 2, nil, 3 | ||
| 41 | ... = fn! | ||
| 42 | count = select '#', ... | ||
| 43 | assert.same count, 5 | ||
| 44 | assert.same select(1, ...), 1 | ||
| 45 | assert.same select(2, ...), nil | ||
| 46 | assert.same select(3, ...), 2 | ||
| 47 | |||
| 48 | it "should work with table.unpack", -> | ||
| 49 | tb = {a: 1, b: 2, c: 3} | ||
| 50 | fn = -> table.unpack tb | ||
| 51 | ... = fn! | ||
| 52 | count = select '#', ... | ||
| 53 | assert.same count, 3 | ||
| 54 | |||
| 55 | it "should chain varargs assignment", -> | ||
| 56 | fn1 = -> 1, 2, 3 | ||
| 57 | fn2 = -> table.unpack {4, 5, 6} | ||
| 58 | a, ... = fn1! | ||
| 59 | b, ... = fn2! | ||
| 60 | assert.same a, 1 | ||
| 61 | assert.same b, 4 | ||
| 62 | assert.same select('#', ...), 2 | ||
| 63 | |||
| 64 | it "should work in expressions", -> | ||
| 65 | sum = (...) -> | ||
| 66 | total = 0 | ||
| 67 | for i = 1, select '#', ... | ||
| 68 | total += select i, ... if type(select(i, ...)) == "number" | ||
| 69 | total | ||
| 70 | |||
| 71 | fn = -> 1, 2, 3, 4, 5 | ||
| 72 | ... = fn! | ||
| 73 | result = sum ... | ||
| 74 | assert.same result, 15 | ||
| 75 | |||
| 76 | it "should work with string.format", -> | ||
| 77 | ... = "hello", 123, true | ||
| 78 | result = string.format "str: %s, num: %d, bool: %s", ... | ||
| 79 | assert.same result, "str: hello, num: 123, bool: true" | ||
| 80 | |||
| 81 | it "should handle single return value", -> | ||
| 82 | fn = -> 42 | ||
| 83 | ... = fn! | ||
| 84 | count = select '#', ... | ||
| 85 | assert.same count, 1 | ||
| 86 | assert.same select(1, ...), 42 | ||
| 87 | |||
| 88 | it "should work with nested functions", -> | ||
| 89 | outer = -> 1, 2, 3 | ||
| 90 | inner = -> 4, 5 | ||
| 91 | a, b, ... = outer! | ||
| 92 | c, d = inner! | ||
| 93 | assert.same a, 1 | ||
| 94 | assert.same b, 2 | ||
| 95 | assert.same c, 4 | ||
| 96 | assert.same d, 5 | ||
