[llvm] d1d2932 - [Support][NFC] Add test documenting that empty `Regex` pattern matches nothing. (#83849)
via llvm-commits
llvm-commits at lists.llvm.org
Tue Mar 5 03:34:28 PST 2024
Author: martinboehme
Date: 2024-03-05T12:34:17+01:00
New Revision: d1d2932cb1dc24e0c8149f07b75599981ac405a7
URL: https://github.com/llvm/llvm-project/commit/d1d2932cb1dc24e0c8149f07b75599981ac405a7
DIFF: https://github.com/llvm/llvm-project/commit/d1d2932cb1dc24e0c8149f07b75599981ac405a7.diff
LOG: [Support][NFC] Add test documenting that empty `Regex` pattern matches nothing. (#83849)
I was wondering about this when I recently used `Regex`, and I thought
it would
be nice to have a test documenting this behavior.
Added:
Modified:
llvm/unittests/Support/RegexTest.cpp
Removed:
################################################################################
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
diff erent 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;
More information about the llvm-commits
mailing list