From a6f347fbb7e9d21792afe2ec8f9900ceb400ce2b Mon Sep 17 00:00:00 2001 From: Laurenz Date: Wed, 30 Aug 2023 17:19:25 +0200 Subject: [PATCH] Add test for ends-with fix --- crates/typst/src/eval/str.rs | 10 +++------- tests/typ/compiler/string.typ | 3 +++ 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/crates/typst/src/eval/str.rs b/crates/typst/src/eval/str.rs index 140f71465..636b96405 100644 --- a/crates/typst/src/eval/str.rs +++ b/crates/typst/src/eval/str.rs @@ -123,14 +123,10 @@ impl Str { } // There might still be a match overlapping this one, so - // restart at the next code point - if let Some(c) = &self[mat.start()..].chars().next() { - start_byte = mat.start() + c.len_utf8(); - } else { - break; - } + // restart at the next code point. + let Some(c) = self[mat.start()..].chars().next() else { break }; + start_byte = mat.start() + c.len_utf8(); } - false } } diff --git a/tests/typ/compiler/string.typ b/tests/typ/compiler/string.typ index b0708979f..ed1296a7a 100644 --- a/tests/typ/compiler/string.typ +++ b/tests/typ/compiler/string.typ @@ -81,6 +81,9 @@ #test("Typst".ends-with(regex("\d*")), true) #test("Typst".ends-with(regex("\d+")), false) #test("Typ12".ends-with(regex("\d+")), true) +#test("typst13".ends-with(regex("1[0-9]")), true) +#test("typst113".ends-with(regex("1[0-9]")), true) +#test("typst23".ends-with(regex("1[0-9]")), false) --- // Test the `find` and `position` methods.