[clang] [clang-format] clang-format-ignore: Add support for double asterisk patterns (PR #110560)
Ameer J via cfe-commits
cfe-commits at lists.llvm.org
Fri Oct 4 11:41:55 PDT 2024
================
@@ -164,6 +164,40 @@ TEST_F(MatchFilePathTest, Path) {
EXPECT_FALSE(match("foo\\", R"(foo*\)"));
}
+TEST_F(MatchFilePathTest, DoubleAsterisk) {
+ EXPECT_TRUE(match("a/b/c/d.cpp", "**b**"));
+ EXPECT_TRUE(match("a/b/c/d.cpp", "**/b/**"));
+ EXPECT_TRUE(match("a/b/c/d_e.cpp", "**d_*"));
+ EXPECT_TRUE(match("a/b/c/d_e.cpp", "**/d_*"));
+ EXPECT_TRUE(match("a/b/c/d_e.cpp", "**d_**"));
+ EXPECT_TRUE(match("a/b/c/d_e.cpp", "**/d_**"));
+
+ EXPECT_TRUE(match("a/b/c/d_e.cpp", "**/b/c/**"));
+
+ EXPECT_TRUE(match("a/b/c/d_e.cpp", "a/**/b/c/d_e.cpp"));
+ EXPECT_TRUE(match("a/b/c/d_e.cpp", "a/**/c/d_e.cpp"));
+ EXPECT_TRUE(match("a/b/c/d_e.cpp", "a/**/b/**/d_e.cpp"));
+ EXPECT_TRUE(match("a/b/c/d_e.cpp", "**/b/**/d_e.cpp"));
+ EXPECT_TRUE(match("a/b/c/d_e.cpp", "a/**/**/b/**"));
+
+ EXPECT_FALSE(match("a/b/c/d_e.cpp", "**/d"));
+ EXPECT_FALSE(match("a/b/c/d_e.cpp", "**/b/d"));
+ EXPECT_FALSE(match("a/b/c/d_e.cpp", "**/b/d/**"));
+ EXPECT_FALSE(match("a/b/c/d_e.cpp", "**/b/c/"));
+
+ // Multiple consecutive asterisks are treated as **
+ EXPECT_TRUE(match("a/b/c/d.cpp", "***b****"));
+ EXPECT_TRUE(match("a/b/c/d.cpp", "****/b/***"));
+ EXPECT_TRUE(match("a/b/c/d_e.cpp", "***d_**"));
+ EXPECT_TRUE(match("a/b/c/d_e.cpp", "****/d_*"));
+ EXPECT_TRUE(match("a/b/c/d_e.cpp", "***/b/c/*****"));
+
+ EXPECT_FALSE(match("a/b/c/d_e.cpp", "*****/d"));
+ EXPECT_FALSE(match("a/b/c/d_e.cpp", "***/b/d"));
+ EXPECT_FALSE(match("a/b/c/d_e.cpp", "*****/b/d/***"));
+ EXPECT_FALSE(match("a/b/c/d_e.cpp", "***/b/c"));
----------------
ameerj wrote:
> should there be some tests with repetition?
I'm not sure I understand what you are asking.
Can you provide examples of the path and the ignore pattern that you expect to be problematic?
> if we are doing this an saying "Its like .gitignore" should we support
I am only indicating that the `**` glob pattern is implemented in .gitignore, and we follow the same rules they do for this specific pattern.
I do not think the current implementation could easily support theese glob patterns the same way .gitignore does.
My understanding is that there is some "state" where a lower level `!` negates an earlier match/ignore?
I think the current implementation only considers one pattern in the file at a time, in isolation of all other lines in the .clang-format-ignore file.
@owenca may understand better and have an opinion.
https://github.com/llvm/llvm-project/pull/110560
More information about the cfe-commits
mailing list