summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorMax <me@mkor.je>2025-01-09 10:49:06 +0000
committerGitHub <noreply@github.com>2025-01-09 10:49:06 +0000
commitbe6629c7cbd00b06beab2b1477c4270859906cb2 (patch)
tree66087a899b1f2c5d90d9e72145cfdb9d55486b5d /tests
parente2b37fef33a92a7086790e04fb133472413c0c0a (diff)
Better math argument parsing (#5008)
Diffstat (limited to 'tests')
-rw-r--r--tests/ref/math-call-named-args.pngbin0 -> 526 bytes
-rw-r--r--tests/ref/math-call-spread-shorthand-clash.pngbin0 -> 119 bytes
-rw-r--r--tests/ref/math-mat-gaps.pngbin489 -> 1309 bytes
-rw-r--r--tests/ref/math-mat-spread-1d.pngbin0 -> 1017 bytes
-rw-r--r--tests/ref/math-mat-spread-2d.pngbin0 -> 3391 bytes
-rw-r--r--tests/ref/math-mat-spread.pngbin0 -> 1814 bytes
-rw-r--r--tests/suite/math/call.typ134
-rw-r--r--tests/suite/math/mat.typ26
8 files changed, 160 insertions, 0 deletions
diff --git a/tests/ref/math-call-named-args.png b/tests/ref/math-call-named-args.png
new file mode 100644
index 00000000..bbe293e9
--- /dev/null
+++ b/tests/ref/math-call-named-args.png
Binary files differ
diff --git a/tests/ref/math-call-spread-shorthand-clash.png b/tests/ref/math-call-spread-shorthand-clash.png
new file mode 100644
index 00000000..4129ef5d
--- /dev/null
+++ b/tests/ref/math-call-spread-shorthand-clash.png
Binary files differ
diff --git a/tests/ref/math-mat-gaps.png b/tests/ref/math-mat-gaps.png
index 5c954766..40535877 100644
--- a/tests/ref/math-mat-gaps.png
+++ b/tests/ref/math-mat-gaps.png
Binary files differ
diff --git a/tests/ref/math-mat-spread-1d.png b/tests/ref/math-mat-spread-1d.png
new file mode 100644
index 00000000..0ac4e620
--- /dev/null
+++ b/tests/ref/math-mat-spread-1d.png
Binary files differ
diff --git a/tests/ref/math-mat-spread-2d.png b/tests/ref/math-mat-spread-2d.png
new file mode 100644
index 00000000..85cb4a6a
--- /dev/null
+++ b/tests/ref/math-mat-spread-2d.png
Binary files differ
diff --git a/tests/ref/math-mat-spread.png b/tests/ref/math-mat-spread.png
new file mode 100644
index 00000000..dc8b2bf7
--- /dev/null
+++ b/tests/ref/math-mat-spread.png
Binary files differ
diff --git a/tests/suite/math/call.typ b/tests/suite/math/call.typ
index 136be8a7..5caacfac 100644
--- a/tests/suite/math/call.typ
+++ b/tests/suite/math/call.typ
@@ -8,6 +8,112 @@ $ pi(a,) $
$ pi(a,b) $
$ pi(a,b,) $
+--- math-call-unclosed-func ---
+#let func(x) = x
+// Error: 6-7 unclosed delimiter
+$func(a$
+
+--- math-call-unclosed-non-func ---
+// Error: 5-6 unclosed delimiter
+$sin(x$
+
+--- math-call-named-args ---
+#let func1(my: none) = my
+#let func2(_my: none) = _my
+#let func3(my-body: none) = my-body
+#let func4(_my-body: none) = _my-body
+#let func5(m: none) = m
+$ func1(my: a) $
+$ func2(_my: a) $
+$ func3(my-body: a) $
+$ func4(_my-body: a) $
+$ func5(m: a) $
+$ func5(m: sigma : f) $
+$ func5(m: sigma:pi) $
+
+--- math-call-named-args-no-expr ---
+#let func(m: none) = m
+// Error: 10 expected expression
+$ func(m: ) $
+
+--- math-call-named-args-duplicate ---
+#let func(my: none) = my
+// Error: 15-17 duplicate argument: my
+$ func(my: a, my: b) $
+
+--- math-call-named-args-shorthand-clash-1 ---
+#let func(m: none) = m
+// Error: 18-21 unexpected argument
+$func(m: =) func(m:=)$
+
+--- math-call-named-args-shorthand-clash-2 ---
+#let func(m: none) = m
+// Error: 41-45 unexpected argument
+$func(m::) func(m: :=) func(m:: =) func(m::=)$
+
+--- math-call-named-single-underscore ---
+#let func(x) = x
+// Error: 8-9 expected identifier, found underscore
+$ func(_: a) $
+
+--- math-call-named-single-char-error ---
+#let func(m: none) = m
+// Error: 8-13 unexpected argument
+$ func(m : a) $
+
+--- math-call-named-args-repr ---
+#let args(..body) = body
+#let check(it, r) = test-repr(it.body.text, r)
+#check($args(_a: a)$, "arguments(_a: [a])")
+#check($args(_a-b: a)$, "arguments(_a-b: [a])")
+#check($args(a-b: a)$, "arguments(a-b: [a])")
+#check($args(a-b-c: a)$, "arguments(a-b-c: [a])")
+#check($args(a--c: a)$, "arguments(a--c: [a])")
+#check($args(a: a-b)$, "arguments(a: sequence([a], [−], [b]))")
+#check($args(a-b: a-b)$, "arguments(a-b: sequence([a], [−], [b]))")
+#check($args(a-b)$, "arguments(sequence([a], [−], [b]))")
+
+--- math-call-spread-content-error ---
+#let args(..body) = body
+// Error: 7-16 cannot spread content
+$args(..(a + b))$
+
+--- math-call-spread-multiple-exprs ---
+#let args(..body) = body
+// Error: 10 expected comma or semicolon
+$args(..a + b)$
+
+--- math-call-spread-unexpected-dots ---
+#let args(..body) = body
+// Error: 8-10 unexpected dots
+$args(#..range(1, 5).chunks(2))$
+
+--- math-call-spread-shorthand-clash ---
+#let func(body) = body
+$func(...)$
+
+--- math-call-spread-repr ---
+#let args(..body) = body
+#let check(it, r) = test-repr(it.body.text, r)
+#check($args(..#range(0, 4).chunks(2))$, "arguments((0, 1), (2, 3))")
+#check($#args(range(1, 5).chunks(2))$, "arguments(((1, 2), (3, 4)))")
+#check($#args(..range(1, 5).chunks(2))$, "arguments((1, 2), (3, 4))")
+#check($args(#(..range(2, 6).chunks(2)))$, "arguments(((2, 3), (4, 5)))")
+#let nums = range(0, 4).chunks(2)
+#check($args(..nums)$, "arguments((0, 1), (2, 3))")
+#check($args(..nums;)$, "arguments(((0, 1), (2, 3)))")
+#check($args(..nums, ..nums)$, "arguments((0, 1), (2, 3), (0, 1), (2, 3))")
+#check($args(..nums, 4, 5)$, "arguments((0, 1), (2, 3), [4], [5])")
+#check($args(..nums, ..#range(4, 6))$, "arguments((0, 1), (2, 3), 4, 5)")
+#check($args(..nums, #range(4, 6))$, "arguments((0, 1), (2, 3), (4, 5))")
+#check($args(..nums, 1, 2; 3, 4)$, "arguments(((0, 1), (2, 3), [1], [2]), ([3], [4]))")
+#check($args(1, 2; ..nums)$, "arguments(([1], [2]), ((0, 1), (2, 3)))")
+#check($args(1, 2; 3, 4)$, "arguments(([1], [2]), ([3], [4]))")
+#check($args(1, 2; 3, 4; ..#range(5, 7))$, "arguments(([1], [2]), ([3], [4]), (5, 6))")
+#check($args(1, 2; 3, 4, ..#range(5, 7))$, "arguments(([1], [2]), ([3], [4], 5, 6))")
+#check($args(1, 2; 3, 4, ..#range(5, 7);)$, "arguments(([1], [2]), ([3], [4], 5, 6))")
+#check($args(1, 2; 3, 4, ..#range(5, 7),)$, "arguments(([1], [2]), ([3], [4], 5, 6))")
+
--- math-call-repr ---
#let args(..body) = body
#let check(it, r) = test-repr(it.body.text, r)
@@ -35,6 +141,34 @@ $ mat(#"code"; "wins") $
#check($args(a,b;c)$, "arguments(([a], [b]), ([c],))")
#check($args(a,b;c,d;e,f)$, "arguments(([a], [b]), ([c], [d]), ([e], [f]))")
+--- math-call-2d-named-repr ---
+#let args(..body) = (body.pos(), body.named())
+#let check(it, r) = test-repr(it.body.text, r)
+#check($args(a: b)$, "((), (a: [b]))")
+#check($args(1, 2; 3, 4)$, "((([1], [2]), ([3], [4])), (:))")
+#check($args(a: b, 1, 2; 3, 4)$, "((([1], [2]), ([3], [4])), (a: [b]))")
+#check($args(1, a: b, 2; 3, 4)$, "(([1], ([2],), ([3], [4])), (a: [b]))")
+#check($args(1, 2, a: b; 3, 4)$, "(([1], [2], (), ([3], [4])), (a: [b]))")
+#check($args(1, 2; a: b, 3, 4)$, "((([1], [2]), ([3], [4])), (a: [b]))")
+#check($args(1, 2; 3, a: b, 4)$, "((([1], [2]), [3], ([4],)), (a: [b]))")
+#check($args(1, 2; 3, 4, a: b)$, "((([1], [2]), [3], [4]), (a: [b]))")
+#check($args(a: b, 1, 2, 3, c: d)$, "(([1], [2], [3]), (a: [b], c: [d]))")
+#check($args(1, 2, 3; a: b)$, "((([1], [2], [3]),), (a: [b]))")
+#check($args(a-b: a,, e:f;; d)$, "(([], (), ([],), ([d],)), (a-b: [a], e: [f]))")
+#check($args(a: b, ..#range(0, 4))$, "((0, 1, 2, 3), (a: [b]))")
+
+--- math-call-2d-escape-repr ---
+#let args(..body) = body
+#let check(it, r) = test-repr(it.body.text, r)
+#check($args(a\;b)$, "arguments(sequence([a], [;], [b]))")
+#check($args(a\,b;c)$, "arguments((sequence([a], [,], [b]),), ([c],))")
+#check($args(b\;c\,d;e)$, "arguments((sequence([b], [;], [c], [,], [d]),), ([e],))")
+#check($args(a\: b)$, "arguments(sequence([a], [:], [ ], [b]))")
+#check($args(a : b)$, "arguments(sequence([a], [ ], [:], [ ], [b]))")
+#check($args(\..a)$, "arguments(sequence([.], [.], [a]))")
+#check($args(.. a)$, "arguments(sequence([.], [.], [ ], [a]))")
+#check($args(a..b)$, "arguments(sequence([a], [.], [.], [b]))")
+
--- math-call-2d-repr-structure ---
#let args(..body) = body
#let check(it, r) = test-repr(it.body.text, r)
diff --git a/tests/suite/math/mat.typ b/tests/suite/math/mat.typ
index 391ff167..b7d6a687 100644
--- a/tests/suite/math/mat.typ
+++ b/tests/suite/math/mat.typ
@@ -54,6 +54,30 @@ $ a + mat(delim: #none, 1, 2; 3, 4) + b $
$ mat(1, 2; 3, 4; delim: "[") $,
)
+--- math-mat-spread ---
+// Test argument spreading in matrix.
+$ mat(..#range(1, 5).chunks(2))
+ mat(#(..range(2).map(_ => range(2)))) $
+
+#let nums = ((1,) * 5).intersperse(0).chunks(3)
+$ mat(..nums, delim: "[") $
+
+--- math-mat-spread-1d ---
+$ mat(..#range(1, 5) ; 1, ..#range(2, 5))
+ mat(..#range(1, 3), ..#range(3, 5) ; ..#range(1, 4), 4) $
+
+--- math-mat-spread-2d ---
+#let nums = range(0, 2).map(i => (i, i+1))
+$ mat(..nums, delim: "|",)
+ mat(..nums; delim: "|",) $
+$ mat(..nums) mat(..nums;) \
+ mat(..nums;,) mat(..nums,) $
+
+--- math-mat-spread-expected-array-error ---
+#let nums = range(0, 2).map(i => (i, i+1))
+// Error: 15-16 expected array, found content
+$ mat(..nums, 0, 1) $
+
--- math-mat-gap ---
#set math.mat(gap: 1em)
$ mat(1, 2; 3, 4) $
@@ -61,6 +85,8 @@ $ mat(1, 2; 3, 4) $
--- math-mat-gaps ---
#set math.mat(row-gap: 1em, column-gap: 2em)
$ mat(1, 2; 3, 4) $
+$ mat(column-gap: #1em, 1, 2; 3, 4)
+ mat(row-gap: #2em, 1, 2; 3, 4) $
--- math-mat-augment ---
// Test matrix line drawing (augmentation).