aboutsummaryrefslogtreecommitdiff
path: root/spec/inputs/test/reverse_index_spec.yue
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/inputs/test/reverse_index_spec.yue
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 'spec/inputs/test/reverse_index_spec.yue')
-rw-r--r--spec/inputs/test/reverse_index_spec.yue59
1 files changed, 59 insertions, 0 deletions
diff --git a/spec/inputs/test/reverse_index_spec.yue b/spec/inputs/test/reverse_index_spec.yue
new file mode 100644
index 0000000..be67261
--- /dev/null
+++ b/spec/inputs/test/reverse_index_spec.yue
@@ -0,0 +1,59 @@
1describe "reverse index", ->
2 it "should get last element", ->
3 data = {items: [1, 2, 3, 4, 5]}
4 last = data.items[#]
5 assert.same last, 5
6
7 it "should get second last element", ->
8 data = {items: [1, 2, 3, 4, 5]}
9 second_last = data.items[#-1]
10 assert.same second_last, 4
11
12 it "should get third last element", ->
13 data = {items: [1, 2, 3, 4, 5]}
14 third_last = data.items[#-2]
15 assert.same third_last, 3
16
17 it "should set last element", ->
18 data = {items: [1, 2, 3, 4, 5]}
19 data.items[#] = 10
20 assert.same data.items[5], 10
21
22 it "should set second last element", ->
23 data = {items: [1, 2, 3, 4, 5]}
24 data.items[#-1] = 20
25 assert.same data.items[4], 20
26
27 it "should work with single element", ->
28 tab = {42}
29 assert.same tab[#], 42
30
31 it "should work with empty table", ->
32 tab = []
33 assert.same tab[#], nil
34
35 it "should work in expressions", ->
36 tab = [1, 2, 3, 4, 5]
37 result = tab[#] + tab[#-1]
38 assert.same result, 9
39
40 it "should support chaining", ->
41 data = {items: {nested: [1, 2, 3]}}
42 last = data.items.nested[#]
43 assert.same last, 3
44
45 it "should work with string", ->
46 s = "hello"
47 assert.same s[#], "o"
48
49 it "should handle negative offsets", ->
50 tab = [1, 2, 3, 4, 5]
51 assert.same tab[#-3], 2
52 assert.same tab[#-4], 1
53
54 it "should work in loops", ->
55 tab = [1, 2, 3, 4, 5]
56 results = []
57 for i = 0, 2
58 table.insert results, tab[#-i]
59 assert.same results, {5, 4, 3}