From 8c3d786157ec7fef3072feac55c2d5450800568b Mon Sep 17 00:00:00 2001 From: Li Jin Date: Fri, 30 Jan 2026 18:16:45 +0800 Subject: Added more tests. --- spec/outputs/test/using_spec.lua | 50 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 spec/outputs/test/using_spec.lua (limited to 'spec/outputs/test/using_spec.lua') diff --git a/spec/outputs/test/using_spec.lua b/spec/outputs/test/using_spec.lua new file mode 100644 index 0000000..5c2f357 --- /dev/null +++ b/spec/outputs/test/using_spec.lua @@ -0,0 +1,50 @@ +return describe("using", function() + it("should prevent variable shadowing in assignment", function() + local tmp = 100 + local i, k = 100, 50 + local process + process = function(add) + local tmp = tmp + add + i = i + tmp + k = k + tmp + end + process(22) + assert.same(i, 222) + assert.same(k, 172) + return assert.same(tmp, 100) + end) + it("should handle multiple variable names", function() + local a, b, c = 1, 2, 3 + local process + process = function(sum) + a = a + 1 + b = b + 2 + local c = sum + 100 + end + process(10) + assert.same(a, 2) + assert.same(b, 4) + return assert.same(c, 3) + end) + it("should work with nil value", function() + local x = 1 + local fn + fn = function(val) + if val ~= nil then + x = val + end + end + fn(100) + assert.same(x, 100) + return assert.is_true(x ~= 1) + end) + return it("should work with function calls", function() + local count = 0 + local fn + fn = function(n) + count = count + n + end + fn(5) + return assert.same(count, 5) + end) +end) -- cgit v1.2.3-55-g6feb