[clang-tools-extra] r370028 - GlobList: added a clear test for pattern priority

Dmitri Gribenko via cfe-commits cfe-commits at lists.llvm.org
Tue Aug 27 01:42:42 PDT 2019


Author: gribozavr
Date: Tue Aug 27 01:42:42 2019
New Revision: 370028

URL: http://llvm.org/viewvc/llvm-project?rev=370028&view=rev
Log:
GlobList: added a clear test for pattern priority

Summary:
The last glob that matches the string decides whether that string is
included or excluded.

Subscribers: cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D66787

Modified:
    clang-tools-extra/trunk/unittests/clang-tidy/GlobListTest.cpp

Modified: clang-tools-extra/trunk/unittests/clang-tidy/GlobListTest.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/unittests/clang-tidy/GlobListTest.cpp?rev=370028&r1=370027&r2=370028&view=diff
==============================================================================
--- clang-tools-extra/trunk/unittests/clang-tidy/GlobListTest.cpp (original)
+++ clang-tools-extra/trunk/unittests/clang-tidy/GlobListTest.cpp Tue Aug 27 01:42:42 2019
@@ -31,7 +31,7 @@ TEST(GlobList, Everything) {
   EXPECT_TRUE(Filter.contains("*"));
 }
 
-TEST(GlobList, Simple) {
+TEST(GlobList, OneSimplePattern) {
   GlobList Filter("aaa");
 
   EXPECT_TRUE(Filter.contains("aaa"));
@@ -41,6 +41,40 @@ TEST(GlobList, Simple) {
   EXPECT_FALSE(Filter.contains("bbb"));
 }
 
+TEST(GlobList, TwoSimplePatterns) {
+  GlobList Filter("aaa,bbb");
+
+  EXPECT_TRUE(Filter.contains("aaa"));
+  EXPECT_TRUE(Filter.contains("bbb"));
+  EXPECT_FALSE(Filter.contains(""));
+  EXPECT_FALSE(Filter.contains("aa"));
+  EXPECT_FALSE(Filter.contains("aaaa"));
+  EXPECT_FALSE(Filter.contains("bbbb"));
+}
+
+TEST(GlobList, PatternPriority) {
+  // The last glob that matches the string decides whether that string is
+  // included or excluded.
+  {
+    GlobList Filter("a*,-aaa");
+
+    EXPECT_FALSE(Filter.contains(""));
+    EXPECT_TRUE(Filter.contains("a"));
+    EXPECT_TRUE(Filter.contains("aa"));
+    EXPECT_FALSE(Filter.contains("aaa"));
+    EXPECT_TRUE(Filter.contains("aaaa"));
+  }
+  {
+    GlobList Filter("-aaa,a*");
+
+    EXPECT_FALSE(Filter.contains(""));
+    EXPECT_TRUE(Filter.contains("a"));
+    EXPECT_TRUE(Filter.contains("aa"));
+    EXPECT_TRUE(Filter.contains("aaa"));
+    EXPECT_TRUE(Filter.contains("aaaa"));
+  }
+}
+
 TEST(GlobList, WhitespacesAtBegin) {
   GlobList Filter("-*,   a.b.*");
 




More information about the cfe-commits mailing list