diff options
| author | Laurenz <laurmaedje@gmail.com> | 2022-04-11 16:30:34 +0200 |
|---|---|---|
| committer | Laurenz <laurmaedje@gmail.com> | 2022-04-11 16:30:34 +0200 |
| commit | 1101a8370f33bf31e4d9840ab8d932b8449267e8 (patch) | |
| tree | 7e6dd4291495a248bad4d963007561cb9e70f33d /tests | |
| parent | cd62792c0aefffe8b0a5c7fc76e95dfa7b86a181 (diff) | |
Negative array indexing
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/typ/code/array.typ | 24 | ||||
| -rw-r--r-- | tests/typ/utility/collection.typ | 8 |
2 files changed, 26 insertions, 6 deletions
diff --git a/tests/typ/code/array.typ b/tests/typ/code/array.typ index df37dd45..cd163175 100644 --- a/tests/typ/code/array.typ +++ b/tests/typ/code/array.typ @@ -31,21 +31,33 @@ --- // Test rvalue out of bounds. +// Error: 2-14 array index out of bounds (index: 5, len: 3) +{(1, 2, 3)(5)} + +--- +// Test lvalue out of bounds. { let array = (1, 2, 3) - // Error: 3-11 array index out of bounds (index: 5, len: 3) - array(5) + // Error: 3-11 array index out of bounds (index: 3, len: 3) + array(3) = 5 } --- -// Test lvalue out of bounds. +// Test negative indices. { - let array = (1, 2, 3) - // Error: 3-12 array index out of bounds (index: -1, len: 3) - array(-1) = 5 + let array = (1, 2, 3, 4) + test(array(0), 1) + test(array(-1), 4) + test(array(-2), 3) + test(array(-3), 2) + test(array(-4), 1) } --- +// Error: 2-15 array index out of bounds (index: -4, len: 3) +{(1, 2, 3)(-4)} + +--- // Test non-collection indexing. { diff --git a/tests/typ/utility/collection.typ b/tests/typ/utility/collection.typ index 924200cb..3414f0a9 100644 --- a/tests/typ/utility/collection.typ +++ b/tests/typ/utility/collection.typ @@ -38,12 +38,20 @@ #test((1, 2, 3, 4).slice(2), (3, 4)) #test(range(10).slice(2, 6), (2, 3, 4, 5)) #test(range(10).slice(4, count: 3), (4, 5, 6)) +#test((1, 2, 3).slice(2, -2), ()) +#test((1, 2, 3).slice(-2, 2), (2,)) +#test((1, 2, 3).slice(-3, 2), (1, 2)) +#test("ABCD".split("").slice(1, -1).join("-"), "A-B-C-D") --- // Error: 3-31 array index out of bounds (index: 12, len: 10) { range(10).slice(9, count: 3) } --- +// Error: 3-25 array index out of bounds (index: -4, len: 3) +{ (1, 2, 3).slice(0, -4) } + +--- // Error: 2:17-2:19 missing argument: index #let numbers = () { numbers.insert() } |
