aboutsummaryrefslogtreecommitdiff
path: root/spec/outputs/test/reverse_index_spec.lua
diff options
context:
space:
mode:
authorLi Jin <dragon-fly@qq.com>2026-01-27 00:30:56 +0000
committerLi Jin <dragon-fly@qq.com>2026-01-27 00:30:56 +0000
commit7c2a92b82e9808d3c5ea29b47d1c59d663fe984a (patch)
treeceba95c48bd8d5d9fff3d1206483ddf073c0e03d /spec/outputs/test/reverse_index_spec.lua
parente70e63a9737ed3a9e72f1329901075498190e6b4 (diff)
downloadyuescript-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 '')
-rw-r--r--spec/outputs/test/reverse_index_spec.lua152
1 files changed, 152 insertions, 0 deletions
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 @@
1return describe("reverse index", function()
2 it("should get last element", function()
3 local data = {
4 items = {
5 1,
6 2,
7 3,
8 4,
9 5
10 }
11 }
12 local last
13 do
14 local _item_0 = data.items
15 last = _item_0[#_item_0]
16 end
17 return assert.same(last, 5)
18 end)
19 it("should get second last element", function()
20 local data = {
21 items = {
22 1,
23 2,
24 3,
25 4,
26 5
27 }
28 }
29 local second_last
30 do
31 local _item_0 = data.items
32 second_last = _item_0[#_item_0 - 1]
33 end
34 return assert.same(second_last, 4)
35 end)
36 it("should get third last element", function()
37 local data = {
38 items = {
39 1,
40 2,
41 3,
42 4,
43 5
44 }
45 }
46 local third_last
47 do
48 local _item_0 = data.items
49 third_last = _item_0[#_item_0 - 2]
50 end
51 return assert.same(third_last, 3)
52 end)
53 it("should set last element", function()
54 local data = {
55 items = {
56 1,
57 2,
58 3,
59 4,
60 5
61 }
62 }
63 local _obj_0 = data.items
64 _obj_0[#_obj_0] = 10
65 return assert.same(data.items[5], 10)
66 end)
67 it("should set second last element", function()
68 local data = {
69 items = {
70 1,
71 2,
72 3,
73 4,
74 5
75 }
76 }
77 local _obj_0 = data.items
78 _obj_0[#_obj_0 - 1] = 20
79 return assert.same(data.items[4], 20)
80 end)
81 it("should work with single element", function()
82 local tab = {
83 42
84 }
85 return assert.same(tab[#tab], 42)
86 end)
87 it("should work with empty table", function()
88 local tab = { }
89 return assert.same(tab[#tab], nil)
90 end)
91 it("should work in expressions", function()
92 local tab = {
93 1,
94 2,
95 3,
96 4,
97 5
98 }
99 local result = tab[#tab] + tab[#tab - 1]
100 return assert.same(result, 9)
101 end)
102 it("should support chaining", function()
103 local data = {
104 items = {
105 nested = {
106 1,
107 2,
108 3
109 }
110 }
111 }
112 local last
113 do
114 local _item_0 = data.items.nested
115 last = _item_0[#_item_0]
116 end
117 return assert.same(last, 3)
118 end)
119 it("should work with string", function()
120 local s = "hello"
121 return assert.same(s[#s], "o")
122 end)
123 it("should handle negative offsets", function()
124 local tab = {
125 1,
126 2,
127 3,
128 4,
129 5
130 }
131 assert.same(tab[#tab - 3], 2)
132 return assert.same(tab[#tab - 4], 1)
133 end)
134 return it("should work in loops", function()
135 local tab = {
136 1,
137 2,
138 3,
139 4,
140 5
141 }
142 local results = { }
143 for i = 0, 2 do
144 table.insert(results, tab[#tab - i])
145 end
146 return assert.same(results, {
147 5,
148 4,
149 3
150 })
151 end)
152end)