aboutsummaryrefslogtreecommitdiff
path: root/spec/inputs/test/slicing_spec.yue
diff options
context:
space:
mode:
authorLi Jin <dragon-fly@qq.com>2026-01-28 18:43:14 +0800
committerLi Jin <dragon-fly@qq.com>2026-01-28 18:43:14 +0800
commitdd64edd58fe25ec74ae5958128cf3f74b0692f3b (patch)
tree0f2de1df55897e2713977c5a53936757e14b477a /spec/inputs/test/slicing_spec.yue
parent7c2a92b82e9808d3c5ea29b47d1c59d663fe984a (diff)
downloadyuescript-dd64edd58fe25ec74ae5958128cf3f74b0692f3b.tar.gz
yuescript-dd64edd58fe25ec74ae5958128cf3f74b0692f3b.tar.bz2
yuescript-dd64edd58fe25ec74ae5958128cf3f74b0692f3b.zip
Fixed compiler issues and added 800+ test cases.
Diffstat (limited to 'spec/inputs/test/slicing_spec.yue')
-rw-r--r--spec/inputs/test/slicing_spec.yue22
1 files changed, 11 insertions, 11 deletions
diff --git a/spec/inputs/test/slicing_spec.yue b/spec/inputs/test/slicing_spec.yue
index b0a686b..2f5b1a7 100644
--- a/spec/inputs/test/slicing_spec.yue
+++ b/spec/inputs/test/slicing_spec.yue
@@ -1,27 +1,27 @@
1describe "slicing", -> 1describe "slicing", ->
2 it "should slice array with basic syntax", -> 2 it "should slice array with basic syntax", ->
3 items = [1, 2, 3, 4, 5] 3 items = [1, 2, 3, 4, 5]
4 result = items[1..3] 4 result = items[1, 3]
5 assert.same result, {1, 2, 3} 5 assert.same result, {1, 2, 3}
6 6
7 it "should slice from beginning", -> 7 it "should slice from beginning", ->
8 items = [1, 2, 3, 4, 5] 8 items = [1, 2, 3, 4, 5]
9 result = items[1..#items] 9 result = items[1, #items]
10 assert.same result, {1, 2, 3, 4, 5} 10 assert.same result, {1, 2, 3, 4, 5}
11 11
12 it "should slice to end", -> 12 it "should slice to end", ->
13 items = [1, 2, 3, 4, 5] 13 items = [1, 2, 3, 4, 5]
14 result = items[3..5] 14 result = items[3, 5]
15 assert.same result, {3, 4, 5} 15 assert.same result, {3, 4, 5}
16 16
17 it "should handle negative indices", -> 17 it "should handle negative indices", ->
18 items = [1, 2, 3, 4, 5] 18 items = [1, 2, 3, 4, 5]
19 result = items[#items-2..#items] 19 result = items[-3, -1]
20 assert.same result, {3, 4, 5} 20 assert.same result, {3, 4, 5}
21 21
22 it "should slice single element", -> 22 it "should slice single element", ->
23 items = [1, 2, 3, 4, 5] 23 items = [1, 2, 3, 4, 5]
24 result = items[2..2] 24 result = items[2, 2]
25 assert.same result, {2} 25 assert.same result, {2}
26 26
27 it "should work with strings", -> 27 it "should work with strings", ->
@@ -31,18 +31,18 @@ describe "slicing", ->
31 31
32 it "should handle out of bounds", -> 32 it "should handle out of bounds", ->
33 items = [1, 2, 3] 33 items = [1, 2, 3]
34 result = items[1..10] 34 result = items[1, 10]
35 assert.same result, {1, 2, 3} 35 assert.same result, {1, 2, 3}
36 36
37 it "should create new table", -> 37 it "should create new table", ->
38 original = [1, 2, 3, 4, 5] 38 original = [1, 2, 3, 4, 5]
39 sliced = original[2..4] 39 sliced = original[2, 4]
40 sliced[1] = 99 40 sliced[1] = 99
41 assert.same original[2], 2 -- original unchanged 41 assert.same original[2], 2 -- original unchanged
42 42
43 it "should work with nested arrays", -> 43 it "should work with nested arrays", ->
44 nested = [[1, 2], [3, 4], [5, 6]] 44 nested = [ [1, 2], [3, 4], [5, 6]]
45 result = nested[1..2] 45 result = nested[1, 2]
46 assert.same result, {{1, 2}, {3, 4}} 46 assert.same result, {{1, 2}, {3, 4}}
47 47
48 it "should slice with step simulation", -> 48 it "should slice with step simulation", ->
@@ -52,8 +52,8 @@ describe "slicing", ->
52 52
53 it "should handle empty slice range", -> 53 it "should handle empty slice range", ->
54 items = [1, 2, 3, 4, 5] 54 items = [1, 2, 3, 4, 5]
55 result = items[6..10] 55 result = items[6, 10]
56 assert.same result, nil 56 assert.same result, {}
57 57
58 it "should work with reverse indexing", -> 58 it "should work with reverse indexing", ->
59 items = [1, 2, 3, 4, 5] 59 items = [1, 2, 3, 4, 5]