[llvm] [Support][NFC] Add test documenting that empty `Regex` pattern matches nothing. (PR #83849)
via llvm-commits
llvm-commits at lists.llvm.org
Mon Mar 4 06:02:07 PST 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-llvm-support
Author: None (martinboehme)
<details>
<summary>Changes</summary>
I was wondering about this when I recently used `Regex`, and I thought it would
be nice to have a test documenting this behavior.
---
Full diff: https://github.com/llvm/llvm-project/pull/83849.diff
1 Files Affected:
- (modified) llvm/unittests/Support/RegexTest.cpp (+8)
``````````diff
diff --git a/llvm/unittests/Support/RegexTest.cpp b/llvm/unittests/Support/RegexTest.cpp
index 09f674bb209c07..c6ac42591d1fc7 100644
--- a/llvm/unittests/Support/RegexTest.cpp
+++ b/llvm/unittests/Support/RegexTest.cpp
@@ -60,6 +60,14 @@ TEST_F(RegexTest, Basics) {
EXPECT_TRUE(r5.match(String));
}
+TEST_F(RegexTest, EmptyPattern) {
+ // The empty pattern doesn't match anything -- not even the empty string.
+ // (This is different from some other regex implementations.)
+ Regex r("");
+ EXPECT_FALSE(r.match("123"));
+ EXPECT_FALSE(r.match(""));
+}
+
TEST_F(RegexTest, Backreferences) {
Regex r1("([a-z]+)_\\1");
SmallVector<StringRef, 4> Matches;
``````````
</details>
https://github.com/llvm/llvm-project/pull/83849
More information about the llvm-commits
mailing list