1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44 package org.eclipse.jgit.ignore;
45
46 import static org.junit.Assert.assertEquals;
47 import static org.junit.Assume.assumeTrue;
48
49 import org.junit.Test;
50
51 @SuppressWarnings({ "boxing" })
52 public class IgnoreRuleSpecialCasesTest {
53
54 private void assertMatch(final String pattern, final String input,
55 final boolean matchExpected, Boolean... assume) {
56 boolean assumeDir = input.endsWith("/");
57 FastIgnoreRule matcher = new FastIgnoreRule(pattern);
58 if (assume.length == 0 || !assume[0].booleanValue()) {
59 assertEquals(matchExpected, matcher.isMatch(input, assumeDir));
60 } else {
61 assumeTrue(matchExpected == matcher.isMatch(input, assumeDir));
62 }
63 }
64
65 private void assertFileNameMatch(final String pattern, final String input,
66 final boolean matchExpected) {
67 boolean assumeDir = input.endsWith("/");
68 FastIgnoreRule matcher = new FastIgnoreRule(pattern);
69 assertEquals(matchExpected, matcher.isMatch(input, assumeDir));
70 }
71
72 @Test
73 public void testVerySimplePatternCase0() throws Exception {
74 assertMatch("", "", false);
75 }
76
77 @Test
78 public void testVerySimplePatternCase1() throws Exception {
79 assertMatch("ab", "a", false);
80 }
81
82 @Test
83 public void testVerySimplePatternCase2() throws Exception {
84 assertMatch("ab", "ab", true);
85 }
86
87 @Test
88 public void testVerySimplePatternCase3() throws Exception {
89 assertMatch("ab", "ac", false);
90 }
91
92 @Test
93 public void testVerySimplePatternCase4() throws Exception {
94 assertMatch("ab", "abc", false);
95 }
96
97 @Test
98 public void testVerySimpleWildcardCase0() throws Exception {
99 assertMatch("?", "a", true);
100 }
101
102 @Test
103 public void testVerySimpleWildCardCase1() throws Exception {
104 assertMatch("??", "a", false);
105 }
106
107 @Test
108 public void testVerySimpleWildCardCase2() throws Exception {
109 assertMatch("??", "ab", true);
110 }
111
112 @Test
113 public void testVerySimpleWildCardCase3() throws Exception {
114 assertMatch("??", "abc", false);
115 }
116
117 @Test
118 public void testVerySimpleStarCase0() throws Exception {
119
120 assertMatch("*", "", false);
121 }
122
123 @Test
124 public void testVerySimpleStarCase1() throws Exception {
125 assertMatch("*", "a", true);
126 }
127
128 @Test
129 public void testVerySimpleStarCase2() throws Exception {
130 assertMatch("*", "ab", true);
131 }
132
133 @Test
134 public void testSimpleStarCase0() throws Exception {
135 assertMatch("a*b", "a", false);
136 }
137
138 @Test
139 public void testSimpleStarCase1() throws Exception {
140 assertMatch("a*c", "ac", true);
141 }
142
143 @Test
144 public void testSimpleStarCase2() throws Exception {
145 assertMatch("a*c", "ab", false);
146 }
147
148 @Test
149 public void testSimpleStarCase3() throws Exception {
150 assertMatch("a*c", "abc", true);
151 }
152
153 @Test
154 public void testManySolutionsCase0() throws Exception {
155 assertMatch("a*a*a", "aaa", true);
156 }
157
158 @Test
159 public void testManySolutionsCase1() throws Exception {
160 assertMatch("a*a*a", "aaaa", true);
161 }
162
163 @Test
164 public void testManySolutionsCase2() throws Exception {
165 assertMatch("a*a*a", "ababa", true);
166 }
167
168 @Test
169 public void testManySolutionsCase3() throws Exception {
170 assertMatch("a*a*a", "aaaaaaaa", true);
171 }
172
173 @Test
174 public void testManySolutionsCase4() throws Exception {
175 assertMatch("a*a*a", "aaaaaaab", false);
176 }
177
178 @Test
179 public void testVerySimpleGroupCase0() throws Exception {
180 assertMatch("[ab]", "a", true);
181 }
182
183 @Test
184 public void testVerySimpleGroupCase1() throws Exception {
185 assertMatch("[ab]", "b", true);
186 }
187
188 @Test
189 public void testVerySimpleGroupCase2() throws Exception {
190 assertMatch("[ab]", "ab", false);
191 }
192
193 @Test
194 public void testVerySimpleGroupRangeCase0() throws Exception {
195 assertMatch("[b-d]", "a", false);
196 }
197
198 @Test
199 public void testVerySimpleGroupRangeCase1() throws Exception {
200 assertMatch("[b-d]", "b", true);
201 }
202
203 @Test
204 public void testVerySimpleGroupRangeCase2() throws Exception {
205 assertMatch("[b-d]", "c", true);
206 }
207
208 @Test
209 public void testVerySimpleGroupRangeCase3() throws Exception {
210 assertMatch("[b-d]", "d", true);
211 }
212
213 @Test
214 public void testVerySimpleGroupRangeCase4() throws Exception {
215 assertMatch("[b-d]", "e", false);
216 }
217
218 @Test
219 public void testVerySimpleGroupRangeCase5() throws Exception {
220 assertMatch("[b-d]", "-", false);
221 }
222
223 @Test
224 public void testTwoGroupsCase0() throws Exception {
225 assertMatch("[b-d][ab]", "bb", true);
226 }
227
228 @Test
229 public void testTwoGroupsCase1() throws Exception {
230 assertMatch("[b-d][ab]", "ca", true);
231 }
232
233 @Test
234 public void testTwoGroupsCase2() throws Exception {
235 assertMatch("[b-d][ab]", "fa", false);
236 }
237
238 @Test
239 public void testTwoGroupsCase3() throws Exception {
240 assertMatch("[b-d][ab]", "bc", false);
241 }
242
243 @Test
244 public void testTwoRangesInOneGroupCase0() throws Exception {
245 assertMatch("[b-ce-e]", "a", false);
246 }
247
248 @Test
249 public void testTwoRangesInOneGroupCase1() throws Exception {
250 assertMatch("[b-ce-e]", "b", true);
251 }
252
253 @Test
254 public void testTwoRangesInOneGroupCase2() throws Exception {
255 assertMatch("[b-ce-e]", "c", true);
256 }
257
258 @Test
259 public void testTwoRangesInOneGroupCase3() throws Exception {
260 assertMatch("[b-ce-e]", "d", false);
261 }
262
263 @Test
264 public void testTwoRangesInOneGroupCase4() throws Exception {
265 assertMatch("[b-ce-e]", "e", true);
266 }
267
268 @Test
269 public void testTwoRangesInOneGroupCase5() throws Exception {
270 assertMatch("[b-ce-e]", "f", false);
271 }
272
273 @Test
274 public void testIncompleteRangesInOneGroupCase0() throws Exception {
275 assertMatch("a[b-]", "ab", true);
276 }
277
278 @Test
279 public void testIncompleteRangesInOneGroupCase1() throws Exception {
280 assertMatch("a[b-]", "ac", false);
281 }
282
283 @Test
284 public void testIncompleteRangesInOneGroupCase2() throws Exception {
285 assertMatch("a[b-]", "a-", true);
286 }
287
288 @Test
289 public void testCombinedRangesInOneGroupCase0() throws Exception {
290 assertMatch("[a-c-e]", "b", true);
291 }
292
293
294
295
296
297
298
299
300 @Test
301 public void testCombinedRangesInOneGroupCase1() throws Exception {
302 assertMatch("[a-c-e]", "d", false);
303 }
304
305 @Test
306 public void testCombinedRangesInOneGroupCase2() throws Exception {
307 assertMatch("[a-c-e]", "e", true);
308 }
309
310 @Test
311 public void testInversedGroupCase0() throws Exception {
312 assertMatch("[!b-c]", "a", true);
313 }
314
315 @Test
316 public void testInversedGroupCase1() throws Exception {
317 assertMatch("[!b-c]", "b", false);
318 }
319
320 @Test
321 public void testInversedGroupCase2() throws Exception {
322 assertMatch("[!b-c]", "c", false);
323 }
324
325 @Test
326 public void testInversedGroupCase3() throws Exception {
327 assertMatch("[!b-c]", "d", true);
328 }
329
330 @Test
331 public void testAlphaGroupCase0() throws Exception {
332 assertMatch("[[:alpha:]]", "d", true);
333 }
334
335 @Test
336 public void testAlphaGroupCase1() throws Exception {
337 assertMatch("[[:alpha:]]", ":", false);
338 }
339
340 @Test
341 public void testAlphaGroupCase2() throws Exception {
342
343 assertMatch("[[:alpha:]]", "\u00f6", true);
344 }
345
346 @Test
347 public void test2AlphaGroupsCase0() throws Exception {
348
349 assertMatch("[[:alpha:]][[:alpha:]]", "a\u00f6", true);
350 assertMatch("[[:alpha:]][[:alpha:]]", "a1", false);
351 }
352
353 @Test
354 public void testAlnumGroupCase0() throws Exception {
355 assertMatch("[[:alnum:]]", "a", true);
356 }
357
358 @Test
359 public void testAlnumGroupCase1() throws Exception {
360 assertMatch("[[:alnum:]]", "1", true);
361 }
362
363 @Test
364 public void testAlnumGroupCase2() throws Exception {
365 assertMatch("[[:alnum:]]", ":", false);
366 }
367
368 @Test
369 public void testBlankGroupCase0() throws Exception {
370 assertMatch("[[:blank:]]", " ", true);
371 }
372
373 @Test
374 public void testBlankGroupCase1() throws Exception {
375 assertMatch("[[:blank:]]", "\t", true);
376 }
377
378 @Test
379 public void testBlankGroupCase2() throws Exception {
380 assertMatch("[[:blank:]]", "\r", false);
381 }
382
383 @Test
384 public void testBlankGroupCase3() throws Exception {
385 assertMatch("[[:blank:]]", "\n", false);
386 }
387
388 @Test
389 public void testBlankGroupCase4() throws Exception {
390 assertMatch("[[:blank:]]", "a", false);
391 }
392
393 @Test
394 public void testCntrlGroupCase0() throws Exception {
395 assertMatch("[[:cntrl:]]", "a", false);
396 }
397
398 @Test
399 public void testCntrlGroupCase1() throws Exception {
400 assertMatch("[[:cntrl:]]", String.valueOf((char) 7), true);
401 }
402
403 @Test
404 public void testDigitGroupCase0() throws Exception {
405 assertMatch("[[:digit:]]", "0", true);
406 }
407
408 @Test
409 public void testDigitGroupCase1() throws Exception {
410 assertMatch("[[:digit:]]", "5", true);
411 }
412
413 @Test
414 public void testDigitGroupCase2() throws Exception {
415 assertMatch("[[:digit:]]", "9", true);
416 }
417
418 @Test
419 public void testDigitGroupCase3() throws Exception {
420
421 assertMatch("[[:digit:]]", "\u06f9", true);
422 }
423
424 @Test
425 public void testDigitGroupCase4() throws Exception {
426 assertMatch("[[:digit:]]", "a", false);
427 }
428
429 @Test
430 public void testDigitGroupCase5() throws Exception {
431 assertMatch("[[:digit:]]", "]", false);
432 }
433
434 @Test
435 public void testGraphGroupCase0() throws Exception {
436 assertMatch("[[:graph:]]", "]", true);
437 }
438
439 @Test
440 public void testGraphGroupCase1() throws Exception {
441 assertMatch("[[:graph:]]", "a", true);
442 }
443
444 @Test
445 public void testGraphGroupCase2() throws Exception {
446 assertMatch("[[:graph:]]", ".", true);
447 }
448
449 @Test
450 public void testGraphGroupCase3() throws Exception {
451 assertMatch("[[:graph:]]", "0", true);
452 }
453
454 @Test
455 public void testGraphGroupCase4() throws Exception {
456 assertMatch("[[:graph:]]", " ", false);
457 }
458
459 @Test
460 public void testGraphGroupCase5() throws Exception {
461
462 assertMatch("[[:graph:]]", "\u00f6", true);
463 }
464
465 @Test
466 public void testLowerGroupCase0() throws Exception {
467 assertMatch("[[:lower:]]", "a", true);
468 }
469
470 @Test
471 public void testLowerGroupCase1() throws Exception {
472 assertMatch("[[:lower:]]", "h", true);
473 }
474
475 @Test
476 public void testLowerGroupCase2() throws Exception {
477 assertMatch("[[:lower:]]", "A", false);
478 }
479
480 @Test
481 public void testLowerGroupCase3() throws Exception {
482 assertMatch("[[:lower:]]", "H", false);
483 }
484
485 @Test
486 public void testLowerGroupCase4() throws Exception {
487
488 assertMatch("[[:lower:]]", "\u00e4", true);
489 }
490
491 @Test
492 public void testLowerGroupCase5() throws Exception {
493 assertMatch("[[:lower:]]", ".", false);
494 }
495
496 @Test
497 public void testPrintGroupCase0() throws Exception {
498 assertMatch("[[:print:]]", "]", true);
499 }
500
501 @Test
502 public void testPrintGroupCase1() throws Exception {
503 assertMatch("[[:print:]]", "a", true);
504 }
505
506 @Test
507 public void testPrintGroupCase2() throws Exception {
508 assertMatch("[[:print:]]", ".", true);
509 }
510
511 @Test
512 public void testPrintGroupCase3() throws Exception {
513 assertMatch("[[:print:]]", "0", true);
514 }
515
516 @Test
517 public void testPrintGroupCase4() throws Exception {
518 assertMatch("[[:print:]]", " ", true);
519 }
520
521 @Test
522 public void testPrintGroupCase5() throws Exception {
523
524 assertMatch("[[:print:]]", "\u00f6", true);
525 }
526
527 @Test
528 public void testPunctGroupCase0() throws Exception {
529 assertMatch("[[:punct:]]", ".", true);
530 }
531
532 @Test
533 public void testPunctGroupCase1() throws Exception {
534 assertMatch("[[:punct:]]", "@", true);
535 }
536
537 @Test
538 public void testPunctGroupCase2() throws Exception {
539 assertMatch("[[:punct:]]", " ", false);
540 }
541
542 @Test
543 public void testPunctGroupCase3() throws Exception {
544 assertMatch("[[:punct:]]", "a", false);
545 }
546
547 @Test
548 public void testSpaceGroupCase0() throws Exception {
549 assertMatch("[[:space:]]", " ", true);
550 }
551
552 @Test
553 public void testSpaceGroupCase1() throws Exception {
554 assertMatch("[[:space:]]", "\t", true);
555 }
556
557 @Test
558 public void testSpaceGroupCase2() throws Exception {
559 assertMatch("[[:space:]]", "\r", true);
560 }
561
562 @Test
563 public void testSpaceGroupCase3() throws Exception {
564 assertMatch("[[:space:]]", "\n", true);
565 }
566
567 @Test
568 public void testSpaceGroupCase4() throws Exception {
569 assertMatch("[[:space:]]", "a", false);
570 }
571
572 @Test
573 public void testUpperGroupCase0() throws Exception {
574 assertMatch("[[:upper:]]", "a", false);
575 }
576
577 @Test
578 public void testUpperGroupCase1() throws Exception {
579 assertMatch("[[:upper:]]", "h", false);
580 }
581
582 @Test
583 public void testUpperGroupCase2() throws Exception {
584 assertMatch("[[:upper:]]", "A", true);
585 }
586
587 @Test
588 public void testUpperGroupCase3() throws Exception {
589 assertMatch("[[:upper:]]", "H", true);
590 }
591
592 @Test
593 public void testUpperGroupCase4() throws Exception {
594
595 assertMatch("[[:upper:]]", "\u00c4", true);
596 }
597
598 @Test
599 public void testUpperGroupCase5() throws Exception {
600 assertMatch("[[:upper:]]", ".", false);
601 }
602
603 @Test
604 public void testXDigitGroupCase0() throws Exception {
605 assertMatch("[[:xdigit:]]", "a", true);
606 }
607
608 @Test
609 public void testXDigitGroupCase1() throws Exception {
610 assertMatch("[[:xdigit:]]", "d", true);
611 }
612
613 @Test
614 public void testXDigitGroupCase2() throws Exception {
615 assertMatch("[[:xdigit:]]", "f", true);
616 }
617
618 @Test
619 public void testXDigitGroupCase3() throws Exception {
620 assertMatch("[[:xdigit:]]", "0", true);
621 }
622
623 @Test
624 public void testXDigitGroupCase4() throws Exception {
625 assertMatch("[[:xdigit:]]", "5", true);
626 }
627
628 @Test
629 public void testXDigitGroupCase5() throws Exception {
630 assertMatch("[[:xdigit:]]", "9", true);
631 }
632
633 @Test
634 public void testXDigitGroupCase6() throws Exception {
635 assertMatch("[[:xdigit:]]", "۹", false);
636 }
637
638 @Test
639 public void testXDigitGroupCase7() throws Exception {
640 assertMatch("[[:xdigit:]]", ".", false);
641 }
642
643 @Test
644 public void testWordGroupCase0() throws Exception {
645 assertMatch("[[:word:]]", "g", true);
646 }
647
648 @Test
649 public void testWordGroupCase1() throws Exception {
650
651 assertMatch("[[:word:]]", "\u00f6", true);
652 }
653
654 @Test
655 public void testWordGroupCase2() throws Exception {
656 assertMatch("[[:word:]]", "5", true);
657 }
658
659 @Test
660 public void testWordGroupCase3() throws Exception {
661 assertMatch("[[:word:]]", "_", true);
662 }
663
664 @Test
665 public void testWordGroupCase4() throws Exception {
666 assertMatch("[[:word:]]", " ", false);
667 }
668
669 @Test
670 public void testWordGroupCase5() throws Exception {
671 assertMatch("[[:word:]]", ".", false);
672 }
673
674 @Test
675 public void testMixedGroupCase0() throws Exception {
676 assertMatch("[A[:lower:]C3-5]", "A", true);
677 }
678
679 @Test
680 public void testMixedGroupCase1() throws Exception {
681 assertMatch("[A[:lower:]C3-5]", "C", true);
682 }
683
684 @Test
685 public void testMixedGroupCase2() throws Exception {
686 assertMatch("[A[:lower:]C3-5]", "e", true);
687 }
688
689 @Test
690 public void testMixedGroupCase3() throws Exception {
691 assertMatch("[A[:lower:]C3-5]", "3", true);
692 }
693
694 @Test
695 public void testMixedGroupCase4() throws Exception {
696 assertMatch("[A[:lower:]C3-5]", "4", true);
697 }
698
699 @Test
700 public void testMixedGroupCase5() throws Exception {
701 assertMatch("[A[:lower:]C3-5]", "5", true);
702 }
703
704 @Test
705 public void testMixedGroupCase6() throws Exception {
706 assertMatch("[A[:lower:]C3-5]", "B", false);
707 }
708
709 @Test
710 public void testMixedGroupCase7() throws Exception {
711 assertMatch("[A[:lower:]C3-5]", "2", false);
712 }
713
714 @Test
715 public void testMixedGroupCase8() throws Exception {
716 assertMatch("[A[:lower:]C3-5]", "6", false);
717 }
718
719 @Test
720 public void testMixedGroupCase9() throws Exception {
721 assertMatch("[A[:lower:]C3-5]", ".", false);
722 }
723
724 @Test
725 public void testSpecialGroupCase0() throws Exception {
726 assertMatch("[[]", "[", true);
727 }
728
729 @Test
730 public void testSpecialGroupCase1() throws Exception {
731 assertMatch("[]]", "]", true);
732 }
733
734 @Test
735 public void testSpecialGroupCase2() throws Exception {
736 assertMatch("[]a]", "]", true);
737 }
738
739 @Test
740 public void testSpecialGroupCase3() throws Exception {
741 assertMatch("[a[]", "[", true);
742 }
743
744 @Test
745 public void testSpecialGroupCase4() throws Exception {
746 assertMatch("[a[]", "a", true);
747 }
748
749 @Test
750 public void testSpecialGroupCase5() throws Exception {
751 assertMatch("[!]]", "]", false);
752 }
753
754 @Test
755 public void testSpecialGroupCase6() throws Exception {
756 assertMatch("[!]]", "x", true);
757 }
758
759 @Test
760 public void testSpecialGroupCase7() throws Exception {
761 assertMatch("[:]]", ":]", true);
762 }
763
764 @Test
765 public void testSpecialGroupCase8() throws Exception {
766 assertMatch("[:]]", ":", false);
767 }
768
769 @Test
770 public void testSpecialGroupCase9() throws Exception {
771 assertMatch("][", "][", true);
772 }
773
774 @Test
775 public void testSpecialGroupCase10() throws Exception {
776
777 assertMatch("[[:]", ":", true);
778 assertMatch("[[:]", "[", true);
779 }
780
781 @Test
782 public void testUnsupportedGroupCase0() throws Exception {
783 assertMatch("[[=a=]]", "a", false);
784 assertMatch("[[=a=]]", "=", false);
785 assertMatch("[=a=]", "a", true);
786 assertMatch("[=a=]", "=", true);
787 }
788
789 @Test
790 public void testUnsupportedGroupCase01() throws Exception {
791 assertMatch("[.a.]*[.a.]", "aha", true);
792 }
793
794 @Test
795 public void testUnsupportedGroupCase1() throws Exception {
796 assertMatch("[[.a.]]", "a", false);
797 assertMatch("[[.a.]]", ".", false);
798 assertMatch("[.a.]", "a", true);
799 assertMatch("[.a.]", ".", true);
800 }
801
802 @Test
803 public void testEscapedBracket1() throws Exception {
804 assertMatch("\\[", "[", true);
805 }
806
807 @Test
808 public void testEscapedBracket2() throws Exception {
809 assertMatch("\\[[a]", "[", false);
810 }
811
812 @Test
813 public void testEscapedBracket3() throws Exception {
814 assertMatch("\\[[a]", "a", false);
815 }
816
817 @Test
818 public void testEscapedBracket4() throws Exception {
819 assertMatch("\\[[a]", "[a", true);
820 }
821
822 @Test
823 public void testEscapedBracket5() throws Exception {
824 assertMatch("[a\\]]", "]", true);
825 }
826
827 @Test
828 public void testEscapedBracket6() throws Exception {
829 assertMatch("[a\\]]", "a", true);
830 }
831
832 @Test
833 public void testEscapedBackslash() throws Exception {
834
835 assertMatch("a\\\\b", "a\\b", true);
836 }
837
838 @Test
839 public void testMultipleEscapedCharacters1() throws Exception {
840 assertMatch("\\]a?c\\*\\[d\\?\\]", "]abc*[d?]", true);
841 }
842
843 @Test
844 public void testFilePathSimpleCase() throws Exception {
845 assertFileNameMatch("a/b", "a/b", true);
846 }
847
848 @Test
849 public void testFilePathCase0() throws Exception {
850 assertFileNameMatch("a*b", "a/b", false);
851 }
852
853 @Test
854 public void testFilePathCase1() throws Exception {
855 assertFileNameMatch("a?b", "a/b", false);
856 }
857
858 @Test
859 public void testFilePathCase2() throws Exception {
860 assertFileNameMatch("a*b", "a\\b", true);
861 }
862
863 @Test
864 public void testFilePathCase3() throws Exception {
865 assertFileNameMatch("a?b", "a\\b", true);
866 }
867
868 }