summaryrefslogtreecommitdiff
path: root/tests/suite/syntax
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2024-04-13 10:39:45 +0200
committerGitHub <noreply@github.com>2024-04-13 08:39:45 +0000
commit020294fca9a7065d4b9cf4e677f606ebaaa29b00 (patch)
treec0027ad22046e2726c22298461327823d6b88d53 /tests/suite/syntax
parent72dd79210602ecc799726fc096b078afbb47f299 (diff)
Better test runner (#3922)
Diffstat (limited to 'tests/suite/syntax')
-rw-r--r--tests/suite/syntax/backtracking.typ32
-rw-r--r--tests/suite/syntax/comment.typ43
-rw-r--r--tests/suite/syntax/embedded.typ9
-rw-r--r--tests/suite/syntax/escape.typ36
-rw-r--r--tests/suite/syntax/newlines.typ77
-rw-r--r--tests/suite/syntax/numbers.typ32
-rw-r--r--tests/suite/syntax/shorthand.typ61
7 files changed, 290 insertions, 0 deletions
diff --git a/tests/suite/syntax/backtracking.typ b/tests/suite/syntax/backtracking.typ
new file mode 100644
index 00000000..33f05770
--- /dev/null
+++ b/tests/suite/syntax/backtracking.typ
@@ -0,0 +1,32 @@
+// Ensure that parser backtracking doesn't lead to exponential time consumption.
+// If this regresses, the test suite will not terminate, which is a bit
+// unfortunate compared to a good error, but at least we know something is up.
+//
+
+--- parser-backtracking-param-default-value ---
+#{
+ let s = "(x: 1) => x"
+ let pat = "(x: {}) => 1 + x()"
+ for _ in range(50) {
+ s = pat.replace("{}", s)
+ }
+ test(eval(s)(), 51)
+}
+
+--- parser-backtracking-destructuring-assignment ---
+#{
+ let s = "(x) = 1"
+ let pat = "(x: {_}) = 1"
+ for _ in range(100) {
+ s = pat.replace("_", s)
+ }
+ // Error: 8-9 cannot destructure integer
+ eval(s)
+}
+
+--- parser-backtracking-destructuring-whitespace ---
+// Test whitespace after memoized part.
+#( (x: () => 1 ) => 1 )
+// -------
+// This is memoized and we want to ensure that whitespace after this
+// is handled correctly.
diff --git a/tests/suite/syntax/comment.typ b/tests/suite/syntax/comment.typ
new file mode 100644
index 00000000..ac3e1943
--- /dev/null
+++ b/tests/suite/syntax/comment.typ
@@ -0,0 +1,43 @@
+// Test line and block comments.
+
+--- comments ---
+// Line comment acts as spacing.
+A// you
+B
+
+// Block comment does not act as spacing, nested block comments.
+C/*
+ /* */
+*/D
+
+// Works in code.
+#test(type(/*1*/ 1) //
+, int)
+
+// End of block comment in line comment.
+// Hello */
+
+// Nested "//" doesn't count as line comment.
+/* // */
+E
+
+/*//*/
+This is a comment.
+*/*/
+
+--- comment-end-of-line ---
+// Test comments at the end of a line
+First part//
+Second part
+
+// Test comments at the end of a line with pre-spacing
+First part //
+Second part
+
+--- comment-block-unclosed ---
+// End should not appear without start.
+// Error: 7-9 unexpected end of block comment
+/* */ */
+
+// Unterminated is okay.
+/*
diff --git a/tests/suite/syntax/embedded.typ b/tests/suite/syntax/embedded.typ
new file mode 100644
index 00000000..74ce4a03
--- /dev/null
+++ b/tests/suite/syntax/embedded.typ
@@ -0,0 +1,9 @@
+// Test embedded expressions.
+
+--- markup-expr-incomplete ---
+// Error: 2-2 expected expression
+#
+
+--- markup-expr-incomplete-followed-by-text ---
+// Error: 2-2 expected expression
+# hello
diff --git a/tests/suite/syntax/escape.typ b/tests/suite/syntax/escape.typ
new file mode 100644
index 00000000..ff05aa99
--- /dev/null
+++ b/tests/suite/syntax/escape.typ
@@ -0,0 +1,36 @@
+// Test escape sequences.
+
+--- escape ---
+// Escapable symbols.
+\\ \/ \[ \] \{ \} \# \* \_ \+ \= \~ \
+\` \$ \" \' \< \> \@ \( \) \A
+
+// No need to escape.
+( ) ;
+
+// Escaped comments.
+\//
+\/\* \*\/
+\/* \*/ *
+
+// Unicode escape sequence.
+\u{1F3D5} == 🏕
+
+// Escaped escape sequence.
+\u{41} vs. \\u\{41\}
+
+// Some code stuff in text.
+let f() , ; : | + - /= == 12 "string"
+
+// Escaped dot.
+10\. May
+
+--- escape-invalid-codepoint ---
+// Unicode codepoint does not exist.
+// Error: 1-11 invalid Unicode codepoint: FFFFFF
+\u{FFFFFF}
+
+--- escape-unclosed ---
+// Unterminated.
+// Error: 1-6 unclosed Unicode escape sequence
+\u{41[*Bold*]
diff --git a/tests/suite/syntax/newlines.typ b/tests/suite/syntax/newlines.typ
new file mode 100644
index 00000000..eef45619
--- /dev/null
+++ b/tests/suite/syntax/newlines.typ
@@ -0,0 +1,77 @@
+// Test newline continuations.
+
+--- newline-continuation-code ---
+#{
+ "hello"
+ .clusters()
+ if false {
+
+ }
+ else {
+ ("1", "2")
+ }
+}
+
+--- newline-continuation-markup ---
+#"hello"
+ .codepoints()
+
+#if false {
+
+}
+else {
+ ("1", "2")
+}
+
+--- newline-continuation-method-blank ---
+#test({
+ "hi 1"
+
+ .clusters()
+}, ("h", "i", " ", "1"))
+
+--- newline-continuation-method-line-comment-after ---
+#test({
+ "hi 2"// comment
+ .clusters()
+}, ("h", "i", " ", "2"))
+
+--- newline-continuation-method-block-comment-after ---
+#test({
+ "hi 3"/* comment */
+ .clusters()
+}, ("h", "i", " ", "3"))
+
+--- newline-continuation-method-line-comment-between ---
+#test({
+ "hi 4"
+ // comment
+ .clusters()
+}, ("h", "i", " ", "4"))
+
+--- newline-continuation-method-block-comment-between ---
+#test({
+ "hi 5"
+ /*comment*/.clusters()
+}, ("h", "i", " ", "5"))
+
+--- newline-continuation-method-comments-and-blanks ---
+#test({
+ "hi 6"
+ // comment
+
+
+ /* comment */
+ .clusters()
+}, ("h", "i", " ", "6"))
+
+--- newline-continuation-if-else-comment ---
+#test({
+ let foo(x) = {
+ if x < 0 { "negative" }
+ // comment
+ else { "non-negative" }
+ }
+
+ foo(1)
+}, "non-negative")
diff --git a/tests/suite/syntax/numbers.typ b/tests/suite/syntax/numbers.typ
new file mode 100644
index 00000000..1f15ac72
--- /dev/null
+++ b/tests/suite/syntax/numbers.typ
@@ -0,0 +1,32 @@
+// Test how numbers are displayed.
+
+--- numbers ---
+// Test numbers in text mode.
+12 \
+12.0 \
+3.14 \
+1234567890 \
+0123456789 \
+0 \
+0.0 \
++0 \
++0.0 \
+-0 \
+-0.0 \
+-1 \
+-3.14 \
+-9876543210 \
+-0987654321 \
+٣٫١٤ \
+-٣٫١٤ \
+-¾ \
+#text(fractions: true)[-3/2] \
+2022 - 2023 \
+2022 -- 2023 \
+2022--2023 \
+2022-2023 \
+٢٠٢٢ - ٢٠٢٣ \
+٢٠٢٢ -- ٢٠٢٣ \
+٢٠٢٢--٢٠٢٣ \
+٢٠٢٢-٢٠٢٣ \
+-500 -- -400
diff --git a/tests/suite/syntax/shorthand.typ b/tests/suite/syntax/shorthand.typ
new file mode 100644
index 00000000..81aa6b7b
--- /dev/null
+++ b/tests/suite/syntax/shorthand.typ
@@ -0,0 +1,61 @@
+// Test shorthands for unicode codepoints.
+
+--- shorthand-nbsp-and-shy-hyphen ---
+The non-breaking space~does work, soft-?hyphen also does.
+
+--- shorthand-nbsp-width ---
+// Make sure non-breaking and normal space always
+// have the same width. Even if the font decided
+// differently.
+#set text(font: "New Computer Modern")
+a b \
+a~b
+
+--- shorthand-dashes ---
+- En dash: --
+- Em dash: ---
+
+--- shorthand-ellipsis ---
+#set text(font: "Roboto")
+A... vs #"A..."
+
+--- shorthands-math ---
+// Check all math shorthands
+$...$\
+$-$\
+$'$\
+$*$\
+$!=$\
+$:=$\
+$::=$\
+$=:$\
+$<<$\
+$<<<$\
+$>>$\
+$>>>$\
+$<=$\
+$>=$\
+$->$\
+$-->$\
+$|->$\
+$>->$\
+$->>$\
+$<-$\
+$<--$\
+$<-<$\
+$<<-$\
+$<->$\
+$<-->$\
+$~>$\
+$~~>$\
+$<~$\
+$<~~$\
+$=>$\
+$|=>$\
+$==>$\
+$<==$\
+$<=>$\
+$<==>$\
+$[|$\
+$|]$\
+$||$