[clang] [clang-format] Support globstar in .clang-format-ignore (PR #121404)
Owen Pan via cfe-commits
cfe-commits at lists.llvm.org
Tue Dec 31 19:24:16 PST 2024
================
@@ -164,6 +164,41 @@ TEST_F(MatchFilePathTest, Path) {
EXPECT_FALSE(match("foo\\", R"(foo*\)"));
}
+TEST_F(MatchFilePathTest, Globstar) {
+ EXPECT_TRUE(match("/", "**"));
+ EXPECT_TRUE(match("foo", "**"));
+ EXPECT_TRUE(match("/foo", "**"));
+ EXPECT_TRUE(match("foo/", "**"));
+ EXPECT_TRUE(match("foo/bar", "**"));
+
+ EXPECT_TRUE(match("/", "**/"));
+ EXPECT_TRUE(match("foo/", "**/"));
+ EXPECT_TRUE(match("/foo/", "**/"));
+ EXPECT_TRUE(match("foo/bar/", "**/"));
+
+ EXPECT_TRUE(match("/", "/**"));
+ EXPECT_TRUE(match("/foo", "/**"));
+ EXPECT_TRUE(match("/foo/", "/**"));
+ EXPECT_TRUE(match("/foo/bar", "/**"));
+
+ EXPECT_TRUE(match("foo", "**/foo"));
+ EXPECT_TRUE(match("/foo", "**/foo"));
+ EXPECT_TRUE(match("foo/bar", "**/bar"));
+ EXPECT_TRUE(match("/foo/bar", "**/foo/bar"));
+ EXPECT_TRUE(match("foo/bar/baz", "**/bar/baz"));
+
+ EXPECT_TRUE(match("abc/foo", "abc/**"));
+ EXPECT_TRUE(match("abc/foo/", "abc/**"));
+ EXPECT_TRUE(match("abc/foo/bar", "abc/**"));
+
+ EXPECT_TRUE(match("a/b", "a/**/b"));
+ EXPECT_TRUE(match("a/x/b", "a/**/b"));
+ EXPECT_TRUE(match("a/x/y/b", "a/**/b"));
+
+ EXPECT_FALSE(match("a/x/b", "a**/b"));
+ EXPECT_FALSE(match("a/x/y/b", "a/**b"));
----------------
owenca wrote:
When `**` are not globstar, it's equivalent to `*`. So `a/**b` is the same as `a/*b`, i.e. any file in `a/` with its name ending in `b`. OTOH `a/**/*b` would match any file in the directory tree rooted at `a/` with its name ending in `b`. The following bash session illustrates the difference:
```
~$ echo $BASH_VERSION
5.2.37(1)-release
~$ shopt globstar
globstar on
~$ ls -FR a
b x/ xb
a/x:
b yb
~$ echo a/**b
a/b a/xb
~$ echo a/**/*b
a/b a/x/b a/x/yb a/xb
~$
```
https://github.com/llvm/llvm-project/pull/121404
More information about the cfe-commits
mailing list