diff options
| author | Laurenz <laurmaedje@gmail.com> | 2024-02-21 09:38:47 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-02-21 08:38:47 +0000 |
| commit | be49935753f0e37ae8e04fb53111e6f116c63f47 (patch) | |
| tree | 0fbc875af61bdedb0d0de42b8809bdb4aae8586f /tests/typ/bugs | |
| parent | b2e509d472634fd5dd43514dbde24eedab566abd (diff) | |
Destructuring improvements (#3463)
Diffstat (limited to 'tests/typ/bugs')
| -rw-r--r-- | tests/typ/bugs/parenthesized.typ | 86 |
1 files changed, 86 insertions, 0 deletions
diff --git a/tests/typ/bugs/parenthesized.typ b/tests/typ/bugs/parenthesized.typ new file mode 100644 index 00000000..99488a67 --- /dev/null +++ b/tests/typ/bugs/parenthesized.typ @@ -0,0 +1,86 @@ +// Ref: false +// Test bugs related to destructuring and parenthesized parsing. + +--- +// https://github.com/typst/typst/issues/1338 +#let foo = "foo" +#let bar = "bar" +// Error: 8-9 expected expression, found underscore +// Error: 16-17 expected expression, found underscore +#(foo: _, bar: _) + +--- +// https://github.com/typst/typst/issues/1342 +// Error: 5-8 expected named or keyed pair, found identifier +// Error: 10-13 expected named or keyed pair, found identifier +#(: foo, bar) + +--- +// https://github.com/typst/typst/issues/1351 +// Error: 17-22 expected pattern, found string +#let foo((test: "bar")) = {} + +--- +// https://github.com/typst/typst/issues/3014 +// Error: 8-17 expected expression, found named pair +#(box, fill: red) + +--- +// https://github.com/typst/typst/issues/3144 +#let f(a: 10) = a(1) + 1 +#test(f(a: _ => 5), 6) + +--- +// Error: 18-20 missing argument: pattern parameter +#let f(a: 10) = a() + 1 +#f(a: _ => 5) + +--- +// This wasn't allowed. +#let ((x)) = 1 +#test(x, 1) + +--- +// This also wasn't allowed. +#let ((a, b)) = (1, 2) +#test(a, 1) +#test(b, 2) + +--- +// This was unintentionally allowed ... +// Error: 9 expected equals sign +#let (a) + +--- +// ... where this wasn't. +// Error: 12 expected equals sign +#let (a, b) + +--- +// This wasn't allowed before the bug fix ... +#let f(..) = {} +#f(arg: 1) + +--- +// ... but this was. +#let f(..x) = {} +#f(arg: 1) + +--- +// Here, `best` was accessed as a variable, where it shouldn't have. +#{ + (best: _) = (best: "brr") +} + +--- +// Same here. +#{ + let array = (1, 2, 3, 4) + (test: array.at(1), best: _) = (test: "baz", best: "brr") + test(array, (1, "baz", 3, 4)) +} + +--- +// Here, `a` is not duplicate, where it was previously identified as one. +#let f((a: b), (c,), a) = (a, b, c) +#test(f((a: 1), (2,), 3), (3, 1, 2)) |
