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