Skip to content

Commit 292996f

Browse files
committed
Add glob pattern unittest
1 parent 3f48497 commit 292996f

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

llvm/lib/Support/GlobPattern.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ GlobPattern::create(StringRef S, std::optional<size_t> MaxSubPatterns) {
137137
GlobPattern Pat;
138138

139139
// Store the prefix that does not contain any metacharacter.
140-
size_t PrefixSize = S.find_first_of("?*[{\\");
140+
size_t PrefixSize = S.find_first_of("?*[{\\/");
141141
Pat.Prefix = S.substr(0, PrefixSize);
142142
if (PrefixSize == std::string::npos)
143143
return Pat;

llvm/unittests/Support/GlobPatternTest.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,4 +271,13 @@ TEST_F(GlobPatternTest, Pathological) {
271271
EXPECT_FALSE(Pat->match(S));
272272
EXPECT_TRUE(Pat->match(S + 'b'));
273273
}
274+
275+
TEST_F(GlobPatternTest, SlashAgnostic) {
276+
auto Pat = GlobPattern::create("clang/*");
277+
ASSERT_TRUE((bool)Pat);
278+
EXPECT_TRUE(Pat->match("clang/foo"));
279+
EXPECT_FALSE(Pat->match(R"(clang\foo)"));
280+
EXPECT_TRUE(Pat->match("clang/foo", /*isSlashAgnostic=*/true));
281+
EXPECT_TRUE(Pat->match(R"(clang\foo)", /*isSlashAgnostic=*/true));
282+
}
274283
}

0 commit comments

Comments
 (0)