diff options
| author | Michael Lohr <michael@lohr.dev> | 2023-05-03 12:34:35 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-05-03 12:34:35 +0200 |
| commit | ffad8516af0b91121dc0761c8026e0a12939a7d4 (patch) | |
| tree | ada5c6b5510b5f509997ccf5308a9cafc8618990 /tests | |
| parent | ca8462642a96ec282afeb0774b6d5daf546ac236 (diff) | |
Implement default values for at() (#995)
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/typ/compiler/array.typ | 11 | ||||
| -rw-r--r-- | tests/typ/compiler/dict.typ | 9 | ||||
| -rw-r--r-- | tests/typ/compiler/field.typ | 4 | ||||
| -rw-r--r-- | tests/typ/compiler/show-node.typ | 2 | ||||
| -rw-r--r-- | tests/typ/compiler/string.typ | 2 |
5 files changed, 19 insertions, 9 deletions
diff --git a/tests/typ/compiler/array.typ b/tests/typ/compiler/array.typ index 5d7e8b63..ef6e4b6b 100644 --- a/tests/typ/compiler/array.typ +++ b/tests/typ/compiler/array.typ @@ -47,18 +47,23 @@ --- // Test rvalue out of bounds. -// Error: 2-17 array index out of bounds (index: 5, len: 3) +// Error: 2-17 array index out of bounds (index: 5, len: 3) and no default value was specified #(1, 2, 3).at(5) --- // Test lvalue out of bounds. #{ let array = (1, 2, 3) - // Error: 3-14 array index out of bounds (index: 3, len: 3) + // Error: 3-14 array index out of bounds (index: 3, len: 3) and no default value was specified array.at(3) = 5 } --- +// Test default value. +#test((1, 2, 3).at(2, default: 5), 3) +#test((1, 2, 3).at(3, default: 5), 5) + +--- // Test bad lvalue. // Error: 2:3-2:14 cannot mutate a temporary value #let array = (1, 2, 3) @@ -243,7 +248,7 @@ #([Hi], [There]).sorted() --- -// Error: 2-18 array index out of bounds (index: -4, len: 3) +// Error: 2-18 array index out of bounds (index: -4, len: 3) and no default value was specified #(1, 2, 3).at(-4) --- diff --git a/tests/typ/compiler/dict.typ b/tests/typ/compiler/dict.typ index 6c982ed4..fd95920b 100644 --- a/tests/typ/compiler/dict.typ +++ b/tests/typ/compiler/dict.typ @@ -31,15 +31,20 @@ // Test rvalue missing key. #{ let dict = (a: 1, b: 2) - // Error: 11-23 dictionary does not contain key "c" + // Error: 11-23 dictionary does not contain key "c" and no default value was specified let x = dict.at("c") } --- +// Test default value. +#test((a: 1, b: 2).at("b", default: 3), 2) +#test((a: 1, b: 2).at("c", default: 3), 3) + +--- // Missing lvalue is not automatically none-initialized. #{ let dict = (:) - // Error: 3-9 dictionary does not contain key "b" + // Error: 3-9 dictionary does not contain key "b" and no default value was specified dict.b += 1 } diff --git a/tests/typ/compiler/field.typ b/tests/typ/compiler/field.typ index 7529cd85..d1e4a31a 100644 --- a/tests/typ/compiler/field.typ +++ b/tests/typ/compiler/field.typ @@ -23,7 +23,7 @@ - C --- -// Error: 6-13 dictionary does not contain key "invalid" +// Error: 6-13 dictionary does not contain key "invalid" and no default value was specified #(:).invalid --- @@ -31,7 +31,7 @@ #false.ok --- -// Error: 25-28 content does not contain field "fun" +// Error: 25-28 content does not contain field "fun" and no default value was specified #show heading: it => it.fun = A diff --git a/tests/typ/compiler/show-node.typ b/tests/typ/compiler/show-node.typ index 99a4364e..c69f46bd 100644 --- a/tests/typ/compiler/show-node.typ +++ b/tests/typ/compiler/show-node.typ @@ -78,7 +78,7 @@ Another text. = Heading --- -// Error: 25-29 content does not contain field "page" +// Error: 25-29 content does not contain field "page" and no default value was specified #show heading: it => it.page = Heading diff --git a/tests/typ/compiler/string.typ b/tests/typ/compiler/string.typ index cba478f7..0bc3a9be 100644 --- a/tests/typ/compiler/string.typ +++ b/tests/typ/compiler/string.typ @@ -31,7 +31,7 @@ #"🏳️🌈".at(2) --- -// Error: 2-15 string index out of bounds (index: 5, len: 5) +// Error: 2-15 no default value was specified and string index out of bounds (index: 5, len: 5) #"Hello".at(5) --- |
