From 7c2a92b82e9808d3c5ea29b47d1c59d663fe984a Mon Sep 17 00:00:00 2001 From: Li Jin Date: Tue, 27 Jan 2026 00:30:56 +0000 Subject: Add compiler improvements and comprehensive test suite - 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 --- spec/outputs/test/while_assignment_spec.lua | 84 +++++++++++++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100644 spec/outputs/test/while_assignment_spec.lua (limited to 'spec/outputs/test/while_assignment_spec.lua') 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 @@ +return describe("while assignment", function() + it("should loop while value is truthy", function() + local counter = 0 + local get_next + get_next = function() + if counter < 3 then + counter = counter + 1 + return counter + else + return nil + end + end + local results = { } + repeat + local val = get_next() + if val then + table.insert(results, val) + else + break + end + until false + return assert.same(results, { + 1, + 2, + 3 + }) + end) + it("should work with function results", function() + local counter = 0 + local fn + fn = function() + counter = counter + 1 + if counter <= 3 then + return counter * 10 + else + return nil + end + end + local sum = 0 + repeat + local val = fn() + if val then + sum = sum + val + else + break + end + until false + return assert.same(sum, 60) + end) + it("should exit immediately on nil", function() + local get_val + get_val = function() + return nil + end + local counter = 0 + repeat + local val = get_val() + if val then + counter = counter + 1 + else + break + end + until false + return assert.same(counter, 0) + end) + return it("should support break in loop", function() + local items = { + 1, + 2, + 3, + 4, + 5 + } + local sum = 0 + for _index_0 = 1, #items do + local item = items[_index_0] + sum = sum + item + if sum > 6 then + break + end + end + return assert.same(sum, 10) + end) +end) -- cgit v1.2.3-55-g6feb