From 1101a8370f33bf31e4d9840ab8d932b8449267e8 Mon Sep 17 00:00:00 2001 From: Laurenz Date: Mon, 11 Apr 2022 16:30:34 +0200 Subject: Negative array indexing --- tests/typ/code/array.typ | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) (limited to 'tests/typ/code') 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,20 +31,32 @@ --- // 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. -- cgit v1.2.3