From 2a45650dcc87c3bf047adaf030fd392bbe9fbb5e Mon Sep 17 00:00:00 2001 From: Laurenz Date: Wed, 4 May 2022 23:04:19 +0200 Subject: Keyed pairs --- tests/ref/code/dict.png | Bin 1973 -> 4764 bytes tests/typ/code/array.typ | 4 ++++ tests/typ/code/call.typ | 3 +++ tests/typ/code/closure.typ | 12 ++++++++++++ tests/typ/code/dict.typ | 18 +++++++++++++----- tests/typ/code/field.typ | 16 ++++++++++++++++ tests/typ/code/import.typ | 4 ++++ tests/typ/code/spread.typ | 2 +- 8 files changed, 53 insertions(+), 6 deletions(-) (limited to 'tests') diff --git a/tests/ref/code/dict.png b/tests/ref/code/dict.png index 28e44999..d7ade71d 100644 Binary files a/tests/ref/code/dict.png and b/tests/ref/code/dict.png differ diff --git a/tests/typ/code/array.typ b/tests/typ/code/array.typ index 58b43ebf..1fa4d13c 100644 --- a/tests/typ/code/array.typ +++ b/tests/typ/code/array.typ @@ -92,3 +92,7 @@ // Named pair after this is already identified as an array. // Error: 6-10 expected expression, found named pair {(1, b: 2)} + +// Keyed pair after this is already identified as an array. +// Error: 6-14 expected expression, found keyed pair +{(1, "key": 2)} diff --git a/tests/typ/code/call.typ b/tests/typ/code/call.typ index 5b8b5b05..0285c8a2 100644 --- a/tests/typ/code/call.typ +++ b/tests/typ/code/call.typ @@ -86,6 +86,9 @@ // Error: 7-8 expected identifier #func(1:2) +// Error: 7-12 expected identifier +#func("abc":2) + // Error: 7-10 expected identifier {func((x):1)} diff --git a/tests/typ/code/closure.typ b/tests/typ/code/closure.typ index 29fca404..45f232ca 100644 --- a/tests/typ/code/closure.typ +++ b/tests/typ/code/closure.typ @@ -143,3 +143,15 @@ // Error: 23-35 unexpected argument test(greet("Typst", whatever: 10)) } + +--- +// Error: 6-16 expected identifier, named pair or argument sink +{(a, "named": b) => none} + +--- +// Error: 10-15 expected identifier +#let foo("key": b) = key + +--- +// Error: 10-14 expected identifier +#let foo(none: b) = key diff --git a/tests/typ/code/dict.typ b/tests/typ/code/dict.typ index 23af145f..00c78c17 100644 --- a/tests/typ/code/dict.typ +++ b/tests/typ/code/dict.typ @@ -7,8 +7,12 @@ // Empty {(:)} -// Two pairs. -{(a1: 1, a2: 2)} +// Two pairs and string key. +#let dict = (normal: 1, "spaced key": 2) +#dict + +#test(dict.normal, 1) +#test(dict("spaced key"), 2) --- // Test lvalue and rvalue access. @@ -39,14 +43,18 @@ // Error: 24-32 pair has duplicate key {(first: 1, second: 2, first: 3)} +--- +// Error: 17-23 pair has duplicate key +{(a: 1, "b": 2, "a": 3)} + --- // Simple expression after already being identified as a dictionary. -// Error: 9-10 expected named pair, found expression +// Error: 9-10 expected named or keyed pair, found expression {(a: 1, b)} // Identified as dictionary due to initial colon. -// Error: 4-5 expected named pair, found expression +// Error: 4-5 expected named or keyed pair, found expression // Error: 5 expected comma -// Error: 12-16 expected identifier +// Error: 12-16 expected identifier or string // Error: 17-18 expected expression, found colon {(:1 b:"", true::)} diff --git a/tests/typ/code/field.typ b/tests/typ/code/field.typ index abccaede..b63a8768 100644 --- a/tests/typ/code/field.typ +++ b/tests/typ/code/field.typ @@ -2,6 +2,7 @@ // Ref: false --- +// Test field on dictionary. #let dict = (nothing: "ness", hello: "world") #test(dict.nothing, "ness") { @@ -11,6 +12,16 @@ test(world, "world") } +--- +// Test field on node. +#show node: list as { + test(node.items.len(), 3) +} + +- A +- B +- C + --- // Error: 6-13 dictionary does not contain key "invalid" {(:).invalid} @@ -19,6 +30,11 @@ // Error: 2-7 cannot access field on boolean {false.ok} +--- +// Error: 29-32 unknown field "fun" +#show node: heading as node.fun += A + --- // Error: 8-12 expected identifier, found boolean {false.true} diff --git a/tests/typ/code/import.typ b/tests/typ/code/import.typ index 683bb52a..312ee676 100644 --- a/tests/typ/code/import.typ +++ b/tests/typ/code/import.typ @@ -115,3 +115,7 @@ This is never reached. // Should output `, a from "target.typ"`. // Error: 10 expected keyword `from` #import *, a from "target.typ" + +--- +// Error: 9-13 expected identifier +#import a: 1 from "" diff --git a/tests/typ/code/spread.typ b/tests/typ/code/spread.typ index c5415c42..a41e04b9 100644 --- a/tests/typ/code/spread.typ +++ b/tests/typ/code/spread.typ @@ -62,7 +62,7 @@ #min(.."nope") --- -// Error: 8-14 expected identifier +// Error: 8-14 expected identifier, named pair or argument sink #let f(..true) = none --- -- cgit v1.2.3