1#include "GlobList.h"
2#include "gtest/gtest.h"
3
4namespace clang {
5namespace tidy {
6
7template <typename GlobListT> struct GlobListTest : public ::testing::Test {};
8
9using GlobListTypes = ::testing::Types<GlobList, CachedGlobList>;
10TYPED_TEST_SUITE(GlobListTest, GlobListTypes, );
11
12TYPED_TEST(GlobListTest, Empty) {
13 TypeParam Filter("");
14
15 EXPECT_TRUE(Filter.contains(""));
16 EXPECT_FALSE(Filter.contains("aaa"));
17}
18
19TYPED_TEST(GlobListTest, Nothing) {
20 TypeParam Filter("-*");
21
22 EXPECT_FALSE(Filter.contains(""));
23 EXPECT_FALSE(Filter.contains("a"));
24 EXPECT_FALSE(Filter.contains("-*"));
25 EXPECT_FALSE(Filter.contains("-"));
26 EXPECT_FALSE(Filter.contains("*"));
27}
28
29TYPED_TEST(GlobListTest, Everything) {
30 TypeParam Filter("*");
31
32 EXPECT_TRUE(Filter.contains(""));
33 EXPECT_TRUE(Filter.contains("aaaa"));
34 EXPECT_TRUE(Filter.contains("-*"));
35 EXPECT_TRUE(Filter.contains("-"));
36 EXPECT_TRUE(Filter.contains("*"));
37}
38
39TYPED_TEST(GlobListTest, OneSimplePattern) {
40 TypeParam Filter("aaa");
41
42 EXPECT_TRUE(Filter.contains("aaa"));
43 EXPECT_FALSE(Filter.contains(""));
44 EXPECT_FALSE(Filter.contains("aa"));
45 EXPECT_FALSE(Filter.contains("aaaa"));
46 EXPECT_FALSE(Filter.contains("bbb"));
47}
48
49TYPED_TEST(GlobListTest, TwoSimplePatterns) {
50 TypeParam Filter("aaa,bbb");
51
52 EXPECT_TRUE(Filter.contains("aaa"));
53 EXPECT_TRUE(Filter.contains("bbb"));
54 EXPECT_FALSE(Filter.contains(""));
55 EXPECT_FALSE(Filter.contains("aa"));
56 EXPECT_FALSE(Filter.contains("aaaa"));
57 EXPECT_FALSE(Filter.contains("bbbb"));
58}
59
60TYPED_TEST(GlobListTest, PatternPriority) {
61 // The last glob that matches the string decides whether that string is
62 // included or excluded.
63 {
64 TypeParam Filter("a*,-aaa");
65
66 EXPECT_FALSE(Filter.contains(""));
67 EXPECT_TRUE(Filter.contains("a"));
68 EXPECT_TRUE(Filter.contains("aa"));
69 EXPECT_FALSE(Filter.contains("aaa"));
70 EXPECT_TRUE(Filter.contains("aaaa"));
71 }
72 {
73 TypeParam Filter("-aaa,a*");
74
75 EXPECT_FALSE(Filter.contains(""));
76 EXPECT_TRUE(Filter.contains("a"));
77 EXPECT_TRUE(Filter.contains("aa"));
78 EXPECT_TRUE(Filter.contains("aaa"));
79 EXPECT_TRUE(Filter.contains("aaaa"));
80 }
81}
82
83TYPED_TEST(GlobListTest, WhitespacesAtBegin) {
84 TypeParam Filter("-*, a.b.*");
85
86 EXPECT_TRUE(Filter.contains("a.b.c"));
87 EXPECT_FALSE(Filter.contains("b.c"));
88}
89
90TYPED_TEST(GlobListTest, Complex) {
91 TypeParam Filter(
92 "*,-a.*, -b.*, \r \n a.1.* ,-a.1.A.*,-..,-...,-..+,-*$, -*qwe* ");
93
94 EXPECT_TRUE(Filter.contains("aaa"));
95 EXPECT_TRUE(Filter.contains("qqq"));
96 EXPECT_FALSE(Filter.contains("a."));
97 EXPECT_FALSE(Filter.contains("a.b"));
98 EXPECT_FALSE(Filter.contains("b."));
99 EXPECT_FALSE(Filter.contains("b.b"));
100 EXPECT_TRUE(Filter.contains("a.1.b"));
101 EXPECT_FALSE(Filter.contains("a.1.A.a"));
102 EXPECT_FALSE(Filter.contains("qwe"));
103 EXPECT_FALSE(Filter.contains("asdfqweasdf"));
104 EXPECT_TRUE(Filter.contains("asdfqwEasdf"));
105}
106
107TYPED_TEST(GlobListTest, NewlineCharactersAsSeparators) {
108 TypeParam Filter("a* \n b,\n-c*,dd");
109
110 EXPECT_FALSE(Filter.contains(""));
111 EXPECT_TRUE(Filter.contains("aaa"));
112 EXPECT_TRUE(Filter.contains("b"));
113 EXPECT_FALSE(Filter.contains("c"));
114 EXPECT_FALSE(Filter.contains("ccc"));
115 EXPECT_FALSE(Filter.contains("d"));
116 EXPECT_TRUE(Filter.contains("dd"));
117 EXPECT_FALSE(Filter.contains("ddd"));
118}
119
120} // namespace tidy
121} // namespace clang
122

source code of clang-tools-extra/unittests/clang-tidy/GlobListTest.cpp