2 #include "gtest/gtest.h"
7 template <typename GlobListT
> struct GlobListTest
: public ::testing::Test
{};
9 using GlobListTypes
= ::testing::Types
<GlobList
, CachedGlobList
>;
10 TYPED_TEST_SUITE(GlobListTest
, GlobListTypes
, );
12 TYPED_TEST(GlobListTest
, Empty
) {
15 EXPECT_TRUE(Filter
.contains(""));
16 EXPECT_FALSE(Filter
.contains("aaa"));
19 TYPED_TEST(GlobListTest
, Nothing
) {
20 TypeParam
Filter("-*");
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("*"));
29 TYPED_TEST(GlobListTest
, Everything
) {
30 TypeParam
Filter("*");
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("*"));
39 TYPED_TEST(GlobListTest
, OneSimplePattern
) {
40 TypeParam
Filter("aaa");
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"));
49 TYPED_TEST(GlobListTest
, TwoSimplePatterns
) {
50 TypeParam
Filter("aaa,bbb");
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"));
60 TYPED_TEST(GlobListTest
, PatternPriority
) {
61 // The last glob that matches the string decides whether that string is
62 // included or excluded.
64 TypeParam
Filter("a*,-aaa");
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"));
73 TypeParam
Filter("-aaa,a*");
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"));
83 TYPED_TEST(GlobListTest
, WhitespacesAtBegin
) {
84 TypeParam
Filter("-*, a.b.*");
86 EXPECT_TRUE(Filter
.contains("a.b.c"));
87 EXPECT_FALSE(Filter
.contains("b.c"));
90 TYPED_TEST(GlobListTest
, Complex
) {
92 "*,-a.*, -b.*, \r \n a.1.* ,-a.1.A.*,-..,-...,-..+,-*$, -*qwe* ");
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"));
107 TYPED_TEST(GlobListTest
, NewlineCharactersAsSeparators
) {
108 TypeParam
Filter("a* \n b,\n-c*,dd");
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"));