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/outputs/test/while_assignment_spec.lua | |
| 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/outputs/test/while_assignment_spec.lua')
| -rw-r--r-- | spec/outputs/test/while_assignment_spec.lua | 84 |
1 files changed, 84 insertions, 0 deletions
diff --git a/spec/outputs/test/while_assignment_spec.lua b/spec/outputs/test/while_assignment_spec.lua new file mode 100644 index 0000000..289e16e --- /dev/null +++ b/spec/outputs/test/while_assignment_spec.lua | |||
| @@ -0,0 +1,84 @@ | |||
| 1 | return describe("while assignment", function() | ||
| 2 | it("should loop while value is truthy", function() | ||
| 3 | local counter = 0 | ||
| 4 | local get_next | ||
| 5 | get_next = function() | ||
| 6 | if counter < 3 then | ||
| 7 | counter = counter + 1 | ||
| 8 | return counter | ||
| 9 | else | ||
| 10 | return nil | ||
| 11 | end | ||
| 12 | end | ||
| 13 | local results = { } | ||
| 14 | repeat | ||
| 15 | local val = get_next() | ||
| 16 | if val then | ||
| 17 | table.insert(results, val) | ||
| 18 | else | ||
| 19 | break | ||
| 20 | end | ||
| 21 | until false | ||
| 22 | return assert.same(results, { | ||
| 23 | 1, | ||
| 24 | 2, | ||
| 25 | 3 | ||
| 26 | }) | ||
| 27 | end) | ||
| 28 | it("should work with function results", function() | ||
| 29 | local counter = 0 | ||
| 30 | local fn | ||
| 31 | fn = function() | ||
| 32 | counter = counter + 1 | ||
| 33 | if counter <= 3 then | ||
| 34 | return counter * 10 | ||
| 35 | else | ||
| 36 | return nil | ||
| 37 | end | ||
| 38 | end | ||
| 39 | local sum = 0 | ||
| 40 | repeat | ||
| 41 | local val = fn() | ||
| 42 | if val then | ||
| 43 | sum = sum + val | ||
| 44 | else | ||
| 45 | break | ||
| 46 | end | ||
| 47 | until false | ||
| 48 | return assert.same(sum, 60) | ||
| 49 | end) | ||
| 50 | it("should exit immediately on nil", function() | ||
| 51 | local get_val | ||
| 52 | get_val = function() | ||
| 53 | return nil | ||
| 54 | end | ||
| 55 | local counter = 0 | ||
| 56 | repeat | ||
| 57 | local val = get_val() | ||
| 58 | if val then | ||
| 59 | counter = counter + 1 | ||
| 60 | else | ||
| 61 | break | ||
| 62 | end | ||
| 63 | until false | ||
| 64 | return assert.same(counter, 0) | ||
| 65 | end) | ||
| 66 | return it("should support break in loop", function() | ||
| 67 | local items = { | ||
| 68 | 1, | ||
| 69 | 2, | ||
| 70 | 3, | ||
| 71 | 4, | ||
| 72 | 5 | ||
| 73 | } | ||
| 74 | local sum = 0 | ||
| 75 | for _index_0 = 1, #items do | ||
| 76 | local item = items[_index_0] | ||
| 77 | sum = sum + item | ||
| 78 | if sum > 6 then | ||
| 79 | break | ||
| 80 | end | ||
| 81 | end | ||
| 82 | return assert.same(sum, 10) | ||
| 83 | end) | ||
| 84 | end) | ||
