@@ -42,10 +42,10 @@ class TestPathMatch : public TestFixture {
4242#else
4343 const std::string basepath{" /test" };
4444#endif
45- const PathMatch emptyMatcher{{}, basepath};
46- const PathMatch srcMatcher{{" src/" }, basepath};
47- const PathMatch fooCppMatcher{{" foo.cpp" }, basepath};
48- const PathMatch srcFooCppMatcher{{" src/foo.cpp" }, basepath};
45+ PathMatch emptyMatcher{{}, basepath};
46+ PathMatch srcMatcher{{" src/" }, basepath};
47+ PathMatch fooCppMatcher{{" foo.cpp" }, basepath};
48+ PathMatch srcFooCppMatcher{{" src/foo.cpp" }, basepath};
4949
5050 void run () override {
5151 TEST_CASE (emptymaskemptyfile);
@@ -85,32 +85,36 @@ class TestPathMatch : public TestFixture {
8585 TEST_CASE (globstar1);
8686 TEST_CASE (globstar2);
8787 TEST_CASE (pathiterator);
88+ TEST_CASE (unmatched1);
89+ TEST_CASE (unmatched2);
90+ TEST_CASE (unmatched3);
91+ TEST_CASE (unmatched4);
8892 }
8993
9094 // Test empty PathMatch
91- void emptymaskemptyfile () const {
95+ void emptymaskemptyfile () {
9296 ASSERT (!emptyMatcher.match (" " ));
9397 }
9498
95- void emptymaskpath1 () const {
99+ void emptymaskpath1 () {
96100 ASSERT (!emptyMatcher.match (" src/" , ifdir));
97101 }
98102
99- void emptymaskpath2 () const {
103+ void emptymaskpath2 () {
100104 ASSERT (!emptyMatcher.match (" ../src/" , ifdir));
101105 }
102106
103- void emptymaskpath3 () const {
107+ void emptymaskpath3 () {
104108 ASSERT (!emptyMatcher.match (" /home/user/code/src/" , ifdir));
105109 ASSERT (!emptyMatcher.match (" d:/home/user/code/src/" , ifdir));
106110 }
107111
108112 // Test PathMatch containing "src/"
109- void onemaskemptypath () const {
113+ void onemaskemptypath () {
110114 ASSERT (!srcMatcher.match (" " ));
111115 }
112116
113- void onemasksamepath () const {
117+ void onemasksamepath () {
114118 ASSERT (srcMatcher.match (" src/" , ifdir));
115119 ASSERT (!srcMatcher.match (" src/" , ifreg));
116120 }
@@ -127,7 +131,7 @@ class TestPathMatch : public TestFixture {
127131 ASSERT (!match.match (" srC/" , ifreg));
128132 }
129133
130- void onemasksamepathwithfile () const {
134+ void onemasksamepathwithfile () {
131135 ASSERT (srcMatcher.match (" src/file.txt" ));
132136 }
133137
@@ -140,36 +144,36 @@ class TestPathMatch : public TestFixture {
140144 ASSERT (!match.match (shorterToMatch, ifdir));
141145 }
142146
143- void onemaskdifferentdir1 () const {
147+ void onemaskdifferentdir1 () {
144148 ASSERT (!srcMatcher.match (" srcfiles/file.txt" ));
145149 }
146150
147- void onemaskdifferentdir2 () const {
151+ void onemaskdifferentdir2 () {
148152 ASSERT (!srcMatcher.match (" proj/srcfiles/file.txt" ));
149153 }
150154
151- void onemaskdifferentdir3 () const {
155+ void onemaskdifferentdir3 () {
152156 ASSERT (!srcMatcher.match (" proj/mysrc/file.txt" ));
153157 }
154158
155- void onemaskdifferentdir4 () const {
159+ void onemaskdifferentdir4 () {
156160 ASSERT (!srcMatcher.match (" proj/mysrcfiles/file.txt" ));
157161 }
158162
159- void onemasklongerpath1 () const {
163+ void onemasklongerpath1 () {
160164 ASSERT (srcMatcher.match (" /tmp/src/" , ifdir));
161165 ASSERT (srcMatcher.match (" d:/tmp/src/" , ifdir));
162166 }
163167
164- void onemasklongerpath2 () const {
168+ void onemasklongerpath2 () {
165169 ASSERT (srcMatcher.match (" src/module/" , ifdir));
166170 }
167171
168- void onemasklongerpath3 () const {
172+ void onemasklongerpath3 () {
169173 ASSERT (srcMatcher.match (" project/src/module/" , ifdir));
170174 }
171175
172- void onemaskcwd () const {
176+ void onemaskcwd () {
173177 ASSERT (srcMatcher.match (" ./src" , ifdir));
174178 }
175179
@@ -197,7 +201,7 @@ class TestPathMatch : public TestFixture {
197201 }
198202
199203 // Test PathMatch containing "foo.cpp"
200- void filemask1 () const {
204+ void filemask1 () {
201205 ASSERT (fooCppMatcher.match (" foo.cpp" ));
202206 }
203207
@@ -206,32 +210,32 @@ class TestPathMatch : public TestFixture {
206210 ASSERT (match.match (" fOo.cpp" ));
207211 }
208212
209- void filemask2 () const {
213+ void filemask2 () {
210214 ASSERT (fooCppMatcher.match (" ../foo.cpp" ));
211215 }
212216
213- void filemask3 () const {
217+ void filemask3 () {
214218 ASSERT (fooCppMatcher.match (" src/foo.cpp" ));
215219 }
216220
217- void filemaskcwd () const {
221+ void filemaskcwd () {
218222 ASSERT (fooCppMatcher.match (" ./lib/foo.cpp" ));
219223 }
220224
221225 // Test PathMatch containing "src/foo.cpp"
222- void filemaskpath1 () const {
226+ void filemaskpath1 () {
223227 ASSERT (srcFooCppMatcher.match (" src/foo.cpp" ));
224228 }
225229
226- void filemaskpath2 () const {
230+ void filemaskpath2 () {
227231 ASSERT (srcFooCppMatcher.match (" proj/src/foo.cpp" ));
228232 }
229233
230- void filemaskpath3 () const {
234+ void filemaskpath3 () {
231235 ASSERT (!srcFooCppMatcher.match (" foo.cpp" ));
232236 }
233237
234- void filemaskpath4 () const {
238+ void filemaskpath4 () {
235239 ASSERT (!srcFooCppMatcher.match (" bar/foo.cpp" ));
236240 }
237241
@@ -308,6 +312,45 @@ class TestPathMatch : public TestFixture {
308312 /* The server and share should actually be considered part of the root and not be removed */
309313 ASSERT_EQUALS (" //" , PathIterator (" \\\\ Server\\ Share\\ Directory" , " ../..\\ ../.." , windows).read ());
310314 }
315+
316+ void unmatched1 () const {
317+ // nothing has been matched yet => all patterns are unmatched
318+ PathMatch match ({" src/" , " foo.cpp" });
319+ ASSERT_EQUALS (2 , match.unmatched ().size ());
320+ ASSERT_EQUALS (" src/" , match.unmatched ()[0 ]);
321+ ASSERT_EQUALS (" foo.cpp" , match.unmatched ()[1 ]);
322+ }
323+
324+ void unmatched2 () const {
325+ PathMatch match ({" src/" , " foo.cpp" });
326+ ASSERT (match.match (" src/bar.cpp" ));
327+ ASSERT_EQUALS (1 , match.unmatched ().size ());
328+ ASSERT_EQUALS (" foo.cpp" , match.unmatched ()[0 ]);
329+ ASSERT (match.match (" lib/foo.cpp" ));
330+ ASSERT_EQUALS (0 , match.unmatched ().size ());
331+ }
332+
333+ void unmatched3 () const {
334+ // failed matches does not affect the unmatched patterns
335+ PathMatch match ({" src/" , " foo.cpp" });
336+ ASSERT (!match.match (" lib/bar.cpp" ));
337+ ASSERT (!match.match (" src/" , ifreg));
338+ ASSERT_EQUALS (2 , match.unmatched ().size ());
339+ ASSERT (match.match (" src/" , ifdir));
340+ ASSERT_EQUALS (1 , match.unmatched ().size ());
341+ ASSERT_EQUALS (" foo.cpp" , match.unmatched ()[0 ]);
342+ }
343+
344+ void unmatched4 () const {
345+ // glob patterns
346+ PathMatch match ({" test*.cpp" , " src/**/foo.c" });
347+ ASSERT (match.match (" src/lib/foo/foo.c" ));
348+ ASSERT_EQUALS (1 , match.unmatched ().size ());
349+ ASSERT_EQUALS (" test*.cpp" , match.unmatched ()[0 ]);
350+ ASSERT (!match.match (" src/foo.c" ));
351+ ASSERT (match.match (" test1.cpp" ));
352+ ASSERT_EQUALS (0 , match.unmatched ().size ());
353+ }
311354};
312355
313356REGISTER_TEST (TestPathMatch)
0 commit comments