summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorLeedehai <18319900+Leedehai@users.noreply.github.com>2024-04-01 17:01:26 -0400
committerGitHub <noreply@github.com>2024-04-01 21:01:26 +0000
commit1e645b396429a976fa4c34dffaa578e5c8347f25 (patch)
tree26e86ef8b1f497e5b8399b1680823fcf60869340 /tests
parent092f6dc462787f05d8f7d6b515bd66fb665c2272 (diff)
Fix `str.trim(regex,at:end)` when the whole string is matched (#3730)
Diffstat (limited to 'tests')
-rw-r--r--tests/typ/compiler/string.typ22
1 files changed, 21 insertions, 1 deletions
diff --git a/tests/typ/compiler/string.typ b/tests/typ/compiler/string.typ
index ed1296a7..949a2154 100644
--- a/tests/typ/compiler/string.typ
+++ b/tests/typ/compiler/string.typ
@@ -180,17 +180,31 @@
#"123".replace("123", (1, 2, 3))
---
-// Test the `trim` method.
+// Test the `trim` method; the pattern is not provided.
#let str = "Typst, LaTeX, Word, InDesign"
#let array = ("Typst", "LaTeX", "Word", "InDesign")
#test(str.split(",").map(s => s.trim()), array)
#test("".trim(), "")
+#test(" ".trim(), "")
+#test("\t".trim(), "")
+#test("\n".trim(), "")
+#test("\t \n".trim(), "")
#test(" abc ".trim(at: start), "abc ")
+#test("\tabc ".trim(at: start), "abc ")
+#test("abc\n".trim(at: end), "abc")
#test(" abc ".trim(at: end, repeat: true), " abc")
#test(" abc".trim(at: start, repeat: false), "abc")
+
+---
+// Test the `trim` method; the pattern is a string.
#test("aabcaa".trim("a", repeat: false), "abca")
#test("aabca".trim("a", at: start), "bca")
#test("aabcaa".trim("a", at: end, repeat: false), "aabca")
+#test(" abc\n".trim("\n"), " abc")
+#test("whole".trim("whole", at: start), "")
+
+---
+// Test the `trim` method; the pattern is a regex.
#test("".trim(regex(".")), "")
#test("123abc456".trim(regex("\d")), "abc")
#test("123abc456".trim(regex("\d"), repeat: false), "23abc45")
@@ -201,6 +215,12 @@
#test("123abc456".trim(regex("\d+"), at: end, repeat: false), "123abc")
#test("123abc456".trim(regex("\d{1,2}$"), repeat: false), "123abc4")
#test("hello world".trim(regex(".")), "")
+#test("12306".trim(regex("\d"), at: start), "")
+#test("12306abc".trim(regex("\d"), at: start), "abc")
+#test("whole".trim(regex("whole"), at: start), "")
+#test("12306".trim(regex("\d"), at: end), "")
+#test("abc12306".trim(regex("\d"), at: end), "abc")
+#test("whole".trim(regex("whole"), at: end), "")
---
// Error: 17-21 expected either `start` or `end`