[clang] [clang-format] Add an fnmatch-like function for .clang-format-ignore (PR #76021)
Owen Pan via cfe-commits
cfe-commits at lists.llvm.org
Fri Dec 22 13:17:52 PST 2023
================
@@ -0,0 +1,169 @@
+//===- unittest/Format/MatchFilePathTest.cpp ------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "../../lib/Format/MatchFilePath.h"
+#include "gtest/gtest.h"
+
+namespace clang {
+namespace format {
+namespace {
+
+class MatchFilePathTest : public ::testing::Test {
+protected:
+ bool match(llvm::StringRef FilePath, llvm::StringRef Pattern) {
+ return matchFilePath(Pattern, FilePath);
+ }
+};
+
+// Most of the test cases below are from:
+// https://github.com/python/cpython/blob/main/Lib/test/test_fnmatch.py
+
+TEST_F(MatchFilePathTest, Wildcard) {
+ EXPECT_TRUE(match("abc", "?*?"));
+ EXPECT_TRUE(match("abc", "???*"));
+ EXPECT_TRUE(match("abc", "*???"));
+ EXPECT_TRUE(match("abc", "???"));
+ EXPECT_TRUE(match("abc", "*"));
+ EXPECT_TRUE(match("abc", "ab[cd]"));
+ EXPECT_TRUE(match("abc", "ab[!de]"));
+ EXPECT_TRUE(!match("abc", "ab[de]"));
----------------
owenca wrote:
I used `!` instead of `EXPECT_FALSE` on purpose because it's easier for me to spot the `!` which has a different color in my editor, but I'll oblige though. :)
https://github.com/llvm/llvm-project/pull/76021
More information about the cfe-commits
mailing list