summaryrefslogtreecommitdiff
path: root/tests/typ
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2021-08-12 13:39:33 +0200
committerLaurenz <laurmaedje@gmail.com>2021-08-12 13:56:23 +0200
commiteaa3cbaa9c2b1564a4b0db013672245a1893314a (patch)
tree616a3d0f3686793caffcef72f230f8ba79b8f3ca /tests/typ
parent8207c31aec6336b773fbf4661fdb87625c8b584e (diff)
Array and dictionary indexing
Diffstat (limited to 'tests/typ')
-rw-r--r--tests/typ/code/array.typ36
-rw-r--r--tests/typ/code/call.typ8
-rw-r--r--tests/typ/code/dict.typ28
-rw-r--r--tests/typ/code/ops-invalid.typ20
-rw-r--r--tests/typ/code/ops-prec.typ2
5 files changed, 86 insertions, 8 deletions
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.
{()}
@@ -19,6 +22,39 @@
,)}
---
+// 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
{(}
diff --git a/tests/typ/code/call.typ b/tests/typ/code/call.typ
index 118382e4..92ac17ae 100644
--- a/tests/typ/code/call.typ
+++ b/tests/typ/code/call.typ
@@ -68,25 +68,25 @@ C
}
---
-// Error: 2-6 expected function, found boolean
+// Error: 2-6 expected function or collection, found boolean
{true()}
---
#let x = "x"
-// Error: 1-3 expected function, found string
+// Error: 1-3 expected function or collection, found string
#x()
---
#let f(x) = x
-// Error: 1-6 expected function, found integer
+// Error: 1-6 expected function or collection, found integer
#f(1)(2)
---
#let f(x) = x
-// Error: 1-6 expected function, found template
+// Error: 1-6 expected function or collection, found template
#f[1](2)
---
diff --git a/tests/typ/code/dict.typ b/tests/typ/code/dict.typ
index b775f4af..b369b8b6 100644
--- a/tests/typ/code/dict.typ
+++ b/tests/typ/code/dict.typ
@@ -1,6 +1,9 @@
// Test dictionaries.
+// Ref: false
---
+// Ref: true
+
// Empty
{(:)}
@@ -8,6 +11,31 @@
{(a1: 1, a2: 2)}
---
+// Test lvalue and rvalue access.
+{
+ let dict = (a: 1, b: 1)
+ dict("b") += 1
+ dict("c") = 3
+ test(dict, (a: 1, b: 2, c: 3))
+}
+
+---
+// Test rvalue missing key.
+{
+ let dict = (a: 1, b: 2)
+ // Error: 11-20 dictionary does not contain key: "c"
+ let x = dict("c")
+}
+
+---
+// Missing lvalue is automatically none-initialized.
+{
+ let dict = (:)
+ // Error: 3-17 cannot add none and integer
+ dict("b") += 1
+}
+
+---
// Simple expression after already being identified as a dictionary.
// Error: 9-10 expected named pair, found expression
{(a: 1, b)}
diff --git a/tests/typ/code/ops-invalid.typ b/tests/typ/code/ops-invalid.typ
index 5e56ff98..e1662ddd 100644
--- a/tests/typ/code/ops-invalid.typ
+++ b/tests/typ/code/ops-invalid.typ
@@ -47,6 +47,20 @@
{3 / 12pt}
---
+// Error: 2-9 cannot repeat this string -1 times
+{-1 * ""}
+
+---
+{
+ let x = 2
+ for _ in 0..60 {
+ x *= 2
+ }
+ // Error: 4-18 cannot repeat this string 4611686018427387904 times
+ {x * "abcdefgh"}
+}
+
+---
// Error: 14-22 cannot add integer and string
{ let x = 1; x += "2" }
@@ -63,11 +77,11 @@
{ 1 .. "" }
---
-// Error: 3-6 cannot assign to this expression
+// Error: 3-6 cannot access this expression mutably
{ (x) = "" }
---
-// Error: 3-8 cannot assign to this expression
+// Error: 3-8 cannot access this expression mutably
{ 1 + 2 += 3 }
---
@@ -75,7 +89,7 @@
{ z = 1 }
---
-// Error: 3-7 cannot assign to a constant
+// Error: 3-7 cannot mutate a constant
{ rect = "hi" }
---
diff --git a/tests/typ/code/ops-prec.typ b/tests/typ/code/ops-prec.typ
index e64e583c..2cec0d04 100644
--- a/tests/typ/code/ops-prec.typ
+++ b/tests/typ/code/ops-prec.typ
@@ -13,7 +13,7 @@
#test(not "b" == "b", false)
// Assignment binds stronger than boolean operations.
-// Error: 2-7 cannot assign to this expression
+// Error: 2-7 cannot access this expression mutably
{not x = "a"}
---