summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorIan Wrzesinski <133046678+wrzian@users.noreply.github.com>2024-04-19 10:31:45 -0400
committerGitHub <noreply@github.com>2024-04-19 14:31:45 +0000
commit45245f069570cbbc63eb4120bf5dbb778b7175ef (patch)
tree8494e581a15b668650c158399684057d8539dd7b /tests
parentd65d9d0fe648415bb61e90042c3a98d865391b95 (diff)
Fix empty 2-d math args with whitespace/trivia (#3786)
Co-authored-by: Laurenz <laurmaedje@gmail.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/ref/issue-3774-math-call-empty-2d-args.pngbin0 -> 757 bytes
-rw-r--r--tests/ref/math-call-2d-semicolon-priority.pngbin0 -> 796 bytes
-rw-r--r--tests/ref/math-call-empty-args-non-func.pngbin0 -> 630 bytes
-rw-r--r--tests/ref/math-call-pass-to-box.pngbin0 -> 2289 bytes
-rw-r--r--tests/ref/math-shorthands.png (renamed from tests/ref/math-shorthandes.png)bin1211 -> 1211 bytes
-rw-r--r--tests/suite/math/call.typ97
-rw-r--r--tests/suite/math/syntax.typ8
7 files changed, 98 insertions, 7 deletions
diff --git a/tests/ref/issue-3774-math-call-empty-2d-args.png b/tests/ref/issue-3774-math-call-empty-2d-args.png
new file mode 100644
index 00000000..ce4b4eb8
--- /dev/null
+++ b/tests/ref/issue-3774-math-call-empty-2d-args.png
Binary files differ
diff --git a/tests/ref/math-call-2d-semicolon-priority.png b/tests/ref/math-call-2d-semicolon-priority.png
new file mode 100644
index 00000000..18807e0b
--- /dev/null
+++ b/tests/ref/math-call-2d-semicolon-priority.png
Binary files differ
diff --git a/tests/ref/math-call-empty-args-non-func.png b/tests/ref/math-call-empty-args-non-func.png
new file mode 100644
index 00000000..5ca90df5
--- /dev/null
+++ b/tests/ref/math-call-empty-args-non-func.png
Binary files differ
diff --git a/tests/ref/math-call-pass-to-box.png b/tests/ref/math-call-pass-to-box.png
new file mode 100644
index 00000000..0ce1b3d0
--- /dev/null
+++ b/tests/ref/math-call-pass-to-box.png
Binary files differ
diff --git a/tests/ref/math-shorthandes.png b/tests/ref/math-shorthands.png
index ff26ce96..ff26ce96 100644
--- a/tests/ref/math-shorthandes.png
+++ b/tests/ref/math-shorthands.png
Binary files differ
diff --git a/tests/suite/math/call.typ b/tests/suite/math/call.typ
new file mode 100644
index 00000000..9eef1613
--- /dev/null
+++ b/tests/suite/math/call.typ
@@ -0,0 +1,97 @@
+// Test math function call edge cases.
+
+// Note: 2d argument calls are tested for matrices in `mat.typ`
+
+--- math-call-non-func ---
+$ pi(a) $
+$ pi(a,) $
+$ pi(a,b) $
+$ pi(a,b,) $
+
+--- math-call-repr ---
+#let args(..body) = body
+#let check(it, r) = test-repr(it.body.text, r)
+#check($args(a)$, "([a])")
+#check($args(a,)$, "([a])")
+#check($args(a,b)$, "([a], [b])")
+#check($args(a,b,)$, "([a], [b])")
+#check($args(,a,b,,,)$, "([], [a], [b], [], [])")
+
+--- math-call-2d-non-func ---
+// Error: 6-7 expected content, found array
+// Error: 8-9 expected content, found array
+$ pi(a;b) $
+
+--- math-call-2d-semicolon-priority ---
+// If the semicolon directlry follows a hash expression, it terminates that
+// instead of indicating 2d arguments.
+$ mat(#"math" ; "wins") $
+$ mat(#"code"; "wins") $
+
+--- math-call-2d-repr ---
+#let args(..body) = body
+#let check(it, r) = test-repr(it.body.text, r)
+#check($args(a;b)$, "(([a],), ([b],))")
+#check($args(a,b;c)$, "(([a], [b]), ([c],))")
+#check($args(a,b;c,d;e,f)$, "(([a], [b]), ([c], [d]), ([e], [f]))")
+
+--- math-call-2d-repr-structure ---
+#let args(..body) = body
+#let check(it, r) = test-repr(it.body.text, r)
+#check($args( a; b; )$, "(([a],), ([b],))")
+#check($args(a; ; c)$, "(([a],), ([],), ([c],))")
+#check($args(a b,/**/; b)$, "((sequence([a], [ ], [b]), []), ([b],))")
+#check($args(a/**/b, ; b)$, "((sequence([a], [b]), []), ([b],))")
+#check($args( ;/**/a/**/b/**/; )$, "(([],), (sequence([a], [b]),))")
+#check($args( ; , ; )$, "(([],), ([], []))")
+#check($args(/**/; // funky whitespace/trivia
+ , /**/ ;/**/)$, "(([],), ([], []))")
+
+--- math-call-empty-args-non-func ---
+// Trailing commas and empty args introduce blank content in math
+$ sin(,x,y,,,) $
+// with whitespace/trivia:
+$ sin( ,/**/x/**/, , /**/y, ,/**/, ) $
+
+--- math-call-empty-args-repr ---
+#let args(..body) = body
+#let check(it, r) = test-repr(it.body.text, r)
+#check($args(,x,,y,,)$, "([], [x], [], [y], [])")
+// with whitespace/trivia:
+#check($args( ,/**/x/**/, , /**/y, ,/**/, )$, "([], [x], [], [y], [], [])")
+
+--- math-call-value-non-func ---
+$ sin(1) $
+// Error: 8-9 expected content, found integer
+$ sin(#1) $
+
+--- math-call-pass-to-box ---
+// When passing to a function, we lose the italic styling if we wrap the content
+// in a non-math function unless it's already nested in some math element (lr,
+// attach, etc.)
+//
+// This is not good, so this test should fail and be updated once it is fixed.
+#let id(body) = body
+#let bx(body) = box(body, stroke: blue+0.5pt, inset: (x:2pt, y:3pt))
+#let eq(body) = math.equation(body)
+$
+ x y &&quad x (y z) &quad x y^z \
+ id(x y) &&quad id(x (y z)) &quad id(x y^z) \
+ eq(x y) &&quad eq(x (y z)) &quad eq(x y^z) \
+ bx(x y) &&quad bx(x (y z)) &quad bx(x y^z) \
+$
+
+--- issue-3774-math-call-empty-2d-args ---
+$ mat(;,) $
+// Add some whitespace/trivia:
+$ mat(; ,) $
+$ mat(;/**/,) $
+$ mat(;
+,) $
+$ mat(;// line comment
+,) $
+$ mat(
+ 1, , ;
+ ,1, ;
+ , ,1;
+) $
diff --git a/tests/suite/math/syntax.typ b/tests/suite/math/syntax.typ
index fcb8b89e..cd1124c3 100644
--- a/tests/suite/math/syntax.typ
+++ b/tests/suite/math/syntax.typ
@@ -1,16 +1,10 @@
// Test math syntax.
---- math-call-non-func ---
-$ pi(a) $
-$ pi(a,) $
-$ pi(a,b) $
-$ pi(a,b,) $
-
--- math-unicode ---
// Test Unicode math.
$ ∑_(i=0)^ℕ a ∘ b = \u{2211}_(i=0)^NN a compose b $
---- math-shorthandes ---
+--- math-shorthands ---
// Test a few shorthands.
$ underline(f' : NN -> RR) \
n |-> cases(