From eaa3cbaa9c2b1564a4b0db013672245a1893314a Mon Sep 17 00:00:00 2001 From: Laurenz Date: Thu, 12 Aug 2021 13:39:33 +0200 Subject: Array and dictionary indexing --- tests/typ/code/array.typ | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) (limited to 'tests/typ/code/array.typ') diff --git a/tests/typ/code/array.typ b/tests/typ/code/array.typ index fc8795c2..df37dd45 100644 --- a/tests/typ/code/array.typ +++ b/tests/typ/code/array.typ @@ -1,6 +1,9 @@ // Test arrays. +// Ref: false --- +// Ref: true + // Empty. {()} @@ -18,6 +21,39 @@ , rgb("002") ,)} +--- +// Test lvalue and rvalue access. +{ + let array = (1, 2) + array(1) += 5 + array(0) + test(array, (1, 8)) +} + +--- +// Test rvalue out of bounds. +{ + let array = (1, 2, 3) + // Error: 3-11 array index out of bounds (index: 5, len: 3) + array(5) +} + +--- +// Test lvalue out of bounds. +{ + let array = (1, 2, 3) + // Error: 3-12 array index out of bounds (index: -1, len: 3) + array(-1) = 5 +} + +--- +// Test non-collection indexing. + +{ + let x = 10pt + // Error: 3-4 expected collection, found length + x() = 1 +} + --- // Error: 3 expected closing paren {(} -- cgit v1.2.3