summaryrefslogtreecommitdiff
path: root/tests/suite/syntax/backtracking.typ
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/backtracking.typ
parent72dd79210602ecc799726fc096b078afbb47f299 (diff)
Better test runner (#3922)
Diffstat (limited to 'tests/suite/syntax/backtracking.typ')
-rw-r--r--tests/suite/syntax/backtracking.typ32
1 files changed, 32 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.