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