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/reverse_index_spec.lua | 152 +++++++++++++++++++++++++++++++ 1 file changed, 152 insertions(+) create mode 100644 spec/outputs/test/reverse_index_spec.lua (limited to 'spec/outputs/test/reverse_index_spec.lua') diff --git a/spec/outputs/test/reverse_index_spec.lua b/spec/outputs/test/reverse_index_spec.lua new file mode 100644 index 0000000..396c3b9 --- /dev/null +++ b/spec/outputs/test/reverse_index_spec.lua @@ -0,0 +1,152 @@ +return describe("reverse index", function() + it("should get last element", function() + local data = { + items = { + 1, + 2, + 3, + 4, + 5 + } + } + local last + do + local _item_0 = data.items + last = _item_0[#_item_0] + end + return assert.same(last, 5) + end) + it("should get second last element", function() + local data = { + items = { + 1, + 2, + 3, + 4, + 5 + } + } + local second_last + do + local _item_0 = data.items + second_last = _item_0[#_item_0 - 1] + end + return assert.same(second_last, 4) + end) + it("should get third last element", function() + local data = { + items = { + 1, + 2, + 3, + 4, + 5 + } + } + local third_last + do + local _item_0 = data.items + third_last = _item_0[#_item_0 - 2] + end + return assert.same(third_last, 3) + end) + it("should set last element", function() + local data = { + items = { + 1, + 2, + 3, + 4, + 5 + } + } + local _obj_0 = data.items + _obj_0[#_obj_0] = 10 + return assert.same(data.items[5], 10) + end) + it("should set second last element", function() + local data = { + items = { + 1, + 2, + 3, + 4, + 5 + } + } + local _obj_0 = data.items + _obj_0[#_obj_0 - 1] = 20 + return assert.same(data.items[4], 20) + end) + it("should work with single element", function() + local tab = { + 42 + } + return assert.same(tab[#tab], 42) + end) + it("should work with empty table", function() + local tab = { } + return assert.same(tab[#tab], nil) + end) + it("should work in expressions", function() + local tab = { + 1, + 2, + 3, + 4, + 5 + } + local result = tab[#tab] + tab[#tab - 1] + return assert.same(result, 9) + end) + it("should support chaining", function() + local data = { + items = { + nested = { + 1, + 2, + 3 + } + } + } + local last + do + local _item_0 = data.items.nested + last = _item_0[#_item_0] + end + return assert.same(last, 3) + end) + it("should work with string", function() + local s = "hello" + return assert.same(s[#s], "o") + end) + it("should handle negative offsets", function() + local tab = { + 1, + 2, + 3, + 4, + 5 + } + assert.same(tab[#tab - 3], 2) + return assert.same(tab[#tab - 4], 1) + end) + return it("should work in loops", function() + local tab = { + 1, + 2, + 3, + 4, + 5 + } + local results = { } + for i = 0, 2 do + table.insert(results, tab[#tab - i]) + end + return assert.same(results, { + 5, + 4, + 3 + }) + end) +end) -- cgit v1.2.3-55-g6feb