From dd64edd58fe25ec74ae5958128cf3f74b0692f3b Mon Sep 17 00:00:00 2001 From: Li Jin Date: Wed, 28 Jan 2026 18:43:14 +0800 Subject: Fixed compiler issues and added 800+ test cases. --- spec/outputs/test/multiline_args_spec.lua | 219 ++++++++++++++++++++++++++++++ 1 file changed, 219 insertions(+) create mode 100644 spec/outputs/test/multiline_args_spec.lua (limited to 'spec/outputs/test/multiline_args_spec.lua') diff --git a/spec/outputs/test/multiline_args_spec.lua b/spec/outputs/test/multiline_args_spec.lua new file mode 100644 index 0000000..562c571 --- /dev/null +++ b/spec/outputs/test/multiline_args_spec.lua @@ -0,0 +1,219 @@ +return describe("multiline arguments", function() + it("should split arguments across lines", function() + local sum + sum = function(a, b, c, d, e, f) + return a + b + c + d + e + f + end + local result = sum(5, 4, 3, 8, 9, 10) + return assert.same(result, 39) + end) + it("should handle nested function calls", function() + local outer + outer = function(a, b, c, d, e, f) + return a + b + c + d + e + f + end + local result = outer(5, 6, 7, 6, 2, 3) + return assert.same(result, 29) + end) + it("should work with string arguments", function() + local fn + fn = function(a, b, c, d) + return a .. b .. c .. d + end + local result = fn("hello", " ", "world", "!") + return assert.same(result, "hello world!") + end) + it("should support table arguments", function() + local fn + fn = function(a, b, c) + return { + a, + b, + c + } + end + local result = fn({ + 1, + 2 + }, { + 3, + 4 + }, { + 5, + 6 + }) + return assert.same(result, { + { + 1, + 2 + }, + { + 3, + 4 + }, + { + 5, + 6 + } + }) + end) + it("should handle mixed types", function() + local fn + fn = function(a, b, c, d) + return { + a, + b, + c, + d + } + end + local result = fn("text", 123, true, nil) + return assert.same(result, { + "text", + 123, + true, + nil + }) + end) + it("should work in table literal", function() + local fn + fn = function(a, b) + return a + b + end + local result = { + 1, + 2, + 3, + 4, + fn(4, 5, 5, 6), + 8, + 9, + 10 + } + return assert.same(result, { + 1, + 2, + 3, + 4, + 9, + 8, + 9, + 10 + }) + end) + it("should handle deeply nested indentation", function() + local fn + fn = function(a, b, c, d, e, f, g) + return a + b + c + d + e + f + g + end + local y = { + fn(1, 2, 3, 4, 5, 6, 7) + } + local result = y[1] + return assert.same(result, 28) + end) + it("should work with conditional statements", function() + local fn + fn = function(a, b, c, d, e, f) + return a + b + c + d + e + f + end + local result1 = fn(1, 2, 3, 4, 5, 6) + local result + if result1 > 20 then + result = "yes" + else + result = "no" + end + return assert.same(result, "yes") + end) + it("should support function expressions", function() + local doublePlus + doublePlus = function(x, y) + return x * 2 + y + end + local result = doublePlus(5, 10) + return assert.same(result, 20) + end) + it("should handle chained function calls", function() + local add + add = function(a, b, c, d) + return a + b + c + d + end + local multiply + multiply = function(a, b, c, d) + return a * b * c * d + end + local result = multiply(1, 2, 3, 4) + return assert.same(result, 24) + end) + it("should work with method calls", function() + local obj = { + value = 10, + add = function(self, a, b, c) + return self.value + a + b + c + end + } + local result = obj:add(5, 10, 15) + return assert.same(result, 40) + end) + it("should support many arguments", function() + local sum_many + sum_many = function(...) + local total = 0 + for i = 1, select('#', ...) do + if type(select(i, ...)) == "number" then + total = total + select(i, ...) + end + end + return total + end + local result = sum_many(1, 2, 3, 4, 5, 6, 7, 8, 9) + return assert.same(result, 45) + end) + it("should work with return statement", function() + local fn + fn = function(a, b, c) + return a + b + c + end + local get_value + get_value = function() + return fn(10, 20, 30) + end + local result = get_value() + return assert.same(result, 60) + end) + it("should handle default parameters", function() + local fn + fn = function(a, b, c) + if a == nil then + a = 1 + end + if b == nil then + b = 2 + end + if c == nil then + c = 3 + end + return a + b + c + end + local result = fn(10, 20, 30) + return assert.same(result, 60) + end) + return it("should work with varargs", function() + local collect + collect = function(...) + return { + ... + } + end + local result = collect(1, 2, 3, 4, 5, 6) + return assert.same(result, { + 1, + 2, + 3, + 4, + 5, + 6 + }) + end) +end) -- cgit v1.2.3-55-g6feb