123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955 |
- /*
- * Copyright (C) 2008, Florian Koeberle <florianskarten@web.de>
- * Copyright (C) 2008, Florian Köberle <florianskarten@web.de>
- * and other copyright owners as documented in the project's IP log.
- *
- * This program and the accompanying materials are made available
- * under the terms of the Eclipse Distribution License v1.0 which
- * accompanies this distribution, is reproduced below, and is
- * available at http://www.eclipse.org/org/documents/edl-v10.php
- *
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or
- * without modification, are permitted provided that the following
- * conditions are met:
- *
- * - Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * - Redistributions in binary form must reproduce the above
- * copyright notice, this list of conditions and the following
- * disclaimer in the documentation and/or other materials provided
- * with the distribution.
- *
- * - Neither the name of the Eclipse Foundation, Inc. nor the
- * names of its contributors may be used to endorse or promote
- * products derived from this software without specific prior
- * written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
- * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
- * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
- * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
- * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
- * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
- package org.eclipse.jgit.fnmatch;
-
- import static org.eclipse.jgit.junit.Assert.assertEquals;
- import static org.junit.Assert.assertFalse;
- import static org.junit.Assert.assertTrue;
- import static org.junit.Assert.fail;
-
- import org.eclipse.jgit.errors.InvalidPatternException;
- import org.junit.Test;
-
- public class FileNameMatcherTest {
-
- private static void assertMatch(final String pattern, final String input,
- final boolean matchExpected, final boolean appendCanMatchExpected)
- throws InvalidPatternException {
- final FileNameMatcher matcher = new FileNameMatcher(pattern, null);
- matcher.append(input);
- assertEquals(matchExpected, matcher.isMatch());
- assertEquals(appendCanMatchExpected, matcher.canAppendMatch());
- }
-
- private static void assertFileNameMatch(final String pattern,
- final String input,
- final char excludedCharacter, final boolean matchExpected,
- final boolean appendCanMatchExpected)
- throws InvalidPatternException {
- final FileNameMatcher matcher = new FileNameMatcher(pattern,
- new Character(excludedCharacter));
- matcher.append(input);
- assertEquals(matchExpected, matcher.isMatch());
- assertEquals(appendCanMatchExpected, matcher.canAppendMatch());
- }
-
- @Test
- public void testVerySimplePatternCase0() throws Exception {
- assertMatch("", "", true, false);
- }
-
- @Test
- public void testVerySimplePatternCase1() throws Exception {
- assertMatch("ab", "a", false, true);
- }
-
- @Test
- public void testVerySimplePatternCase2() throws Exception {
- assertMatch("ab", "ab", true, false);
- }
-
- @Test
- public void testVerySimplePatternCase3() throws Exception {
- assertMatch("ab", "ac", false, false);
- }
-
- @Test
- public void testVerySimplePatternCase4() throws Exception {
- assertMatch("ab", "abc", false, false);
- }
-
- @Test
- public void testVerySimpleWirdcardCase0() throws Exception {
- assertMatch("?", "a", true, false);
- }
-
- @Test
- public void testVerySimpleWildCardCase1() throws Exception {
- assertMatch("??", "a", false, true);
- }
-
- @Test
- public void testVerySimpleWildCardCase2() throws Exception {
- assertMatch("??", "ab", true, false);
- }
-
- @Test
- public void testVerySimpleWildCardCase3() throws Exception {
- assertMatch("??", "abc", false, false);
- }
-
- @Test
- public void testVerySimpleStarCase0() throws Exception {
- assertMatch("*", "", true, true);
- }
-
- @Test
- public void testVerySimpleStarCase1() throws Exception {
- assertMatch("*", "a", true, true);
- }
-
- @Test
- public void testVerySimpleStarCase2() throws Exception {
- assertMatch("*", "ab", true, true);
- }
-
- @Test
- public void testSimpleStarCase0() throws Exception {
- assertMatch("a*b", "a", false, true);
- }
-
- @Test
- public void testSimpleStarCase1() throws Exception {
- assertMatch("a*c", "ac", true, true);
- }
-
- @Test
- public void testSimpleStarCase2() throws Exception {
- assertMatch("a*c", "ab", false, true);
- }
-
- @Test
- public void testSimpleStarCase3() throws Exception {
- assertMatch("a*c", "abc", true, true);
- }
-
- @Test
- public void testManySolutionsCase0() throws Exception {
- assertMatch("a*a*a", "aaa", true, true);
- }
-
- @Test
- public void testManySolutionsCase1() throws Exception {
- assertMatch("a*a*a", "aaaa", true, true);
- }
-
- @Test
- public void testManySolutionsCase2() throws Exception {
- assertMatch("a*a*a", "ababa", true, true);
- }
-
- @Test
- public void testManySolutionsCase3() throws Exception {
- assertMatch("a*a*a", "aaaaaaaa", true, true);
- }
-
- @Test
- public void testManySolutionsCase4() throws Exception {
- assertMatch("a*a*a", "aaaaaaab", false, true);
- }
-
- @Test
- public void testVerySimpleGroupCase0() throws Exception {
- assertMatch("[ab]", "a", true, false);
- }
-
- @Test
- public void testVerySimpleGroupCase1() throws Exception {
- assertMatch("[ab]", "b", true, false);
- }
-
- @Test
- public void testVerySimpleGroupCase2() throws Exception {
- assertMatch("[ab]", "ab", false, false);
- }
-
- @Test
- public void testVerySimpleGroupRangeCase0() throws Exception {
- assertMatch("[b-d]", "a", false, false);
- }
-
- @Test
- public void testVerySimpleGroupRangeCase1() throws Exception {
- assertMatch("[b-d]", "b", true, false);
- }
-
- @Test
- public void testVerySimpleGroupRangeCase2() throws Exception {
- assertMatch("[b-d]", "c", true, false);
- }
-
- @Test
- public void testVerySimpleGroupRangeCase3() throws Exception {
- assertMatch("[b-d]", "d", true, false);
- }
-
- @Test
- public void testVerySimpleGroupRangeCase4() throws Exception {
- assertMatch("[b-d]", "e", false, false);
- }
-
- @Test
- public void testVerySimpleGroupRangeCase5() throws Exception {
- assertMatch("[b-d]", "-", false, false);
- }
-
- @Test
- public void testTwoGroupsCase0() throws Exception {
- assertMatch("[b-d][ab]", "bb", true, false);
- }
-
- @Test
- public void testTwoGroupsCase1() throws Exception {
- assertMatch("[b-d][ab]", "ca", true, false);
- }
-
- @Test
- public void testTwoGroupsCase2() throws Exception {
- assertMatch("[b-d][ab]", "fa", false, false);
- }
-
- @Test
- public void testTwoGroupsCase3() throws Exception {
- assertMatch("[b-d][ab]", "bc", false, false);
- }
-
- @Test
- public void testTwoRangesInOneGroupCase0() throws Exception {
- assertMatch("[b-ce-e]", "a", false, false);
- }
-
- @Test
- public void testTwoRangesInOneGroupCase1() throws Exception {
- assertMatch("[b-ce-e]", "b", true, false);
- }
-
- @Test
- public void testTwoRangesInOneGroupCase2() throws Exception {
- assertMatch("[b-ce-e]", "c", true, false);
- }
-
- @Test
- public void testTwoRangesInOneGroupCase3() throws Exception {
- assertMatch("[b-ce-e]", "d", false, false);
- }
-
- @Test
- public void testTwoRangesInOneGroupCase4() throws Exception {
- assertMatch("[b-ce-e]", "e", true, false);
- }
-
- @Test
- public void testTwoRangesInOneGroupCase5() throws Exception {
- assertMatch("[b-ce-e]", "f", false, false);
- }
-
- @Test
- public void testIncompleteRangesInOneGroupCase0() throws Exception {
- assertMatch("a[b-]", "ab", true, false);
- }
-
- @Test
- public void testIncompleteRangesInOneGroupCase1() throws Exception {
- assertMatch("a[b-]", "ac", false, false);
- }
-
- @Test
- public void testIncompleteRangesInOneGroupCase2() throws Exception {
- assertMatch("a[b-]", "a-", true, false);
- }
-
- @Test
- public void testCombinedRangesInOneGroupCase0() throws Exception {
- assertMatch("[a-c-e]", "b", true, false);
- }
-
- /**
- * The c belongs to the range a-c. "-e" is no valid range so d should not
- * match.
- *
- * @throws Exception
- * for some reasons
- */
- @Test
- public void testCombinedRangesInOneGroupCase1() throws Exception {
- assertMatch("[a-c-e]", "d", false, false);
- }
-
- @Test
- public void testCombinedRangesInOneGroupCase2() throws Exception {
- assertMatch("[a-c-e]", "e", true, false);
- }
-
- @Test
- public void testInversedGroupCase0() throws Exception {
- assertMatch("[!b-c]", "a", true, false);
- }
-
- @Test
- public void testInversedGroupCase1() throws Exception {
- assertMatch("[!b-c]", "b", false, false);
- }
-
- @Test
- public void testInversedGroupCase2() throws Exception {
- assertMatch("[!b-c]", "c", false, false);
- }
-
- @Test
- public void testInversedGroupCase3() throws Exception {
- assertMatch("[!b-c]", "d", true, false);
- }
-
- @Test
- public void testAlphaGroupCase0() throws Exception {
- assertMatch("[[:alpha:]]", "d", true, false);
- }
-
- @Test
- public void testAlphaGroupCase1() throws Exception {
- assertMatch("[[:alpha:]]", ":", false, false);
- }
-
- @Test
- public void testAlphaGroupCase2() throws Exception {
- // \u00f6 = 'o' with dots on it
- assertMatch("[[:alpha:]]", "\u00f6", true, false);
- }
-
- @Test
- public void test2AlphaGroupsCase0() throws Exception {
- // \u00f6 = 'o' with dots on it
- assertMatch("[[:alpha:]][[:alpha:]]", "a\u00f6", true, false);
- assertMatch("[[:alpha:]][[:alpha:]]", "a1", false, false);
- }
-
- @Test
- public void testAlnumGroupCase0() throws Exception {
- assertMatch("[[:alnum:]]", "a", true, false);
- }
-
- @Test
- public void testAlnumGroupCase1() throws Exception {
- assertMatch("[[:alnum:]]", "1", true, false);
- }
-
- @Test
- public void testAlnumGroupCase2() throws Exception {
- assertMatch("[[:alnum:]]", ":", false, false);
- }
-
- @Test
- public void testBlankGroupCase0() throws Exception {
- assertMatch("[[:blank:]]", " ", true, false);
- }
-
- @Test
- public void testBlankGroupCase1() throws Exception {
- assertMatch("[[:blank:]]", "\t", true, false);
- }
-
- @Test
- public void testBlankGroupCase2() throws Exception {
- assertMatch("[[:blank:]]", "\r", false, false);
- }
-
- @Test
- public void testBlankGroupCase3() throws Exception {
- assertMatch("[[:blank:]]", "\n", false, false);
- }
-
- @Test
- public void testBlankGroupCase4() throws Exception {
- assertMatch("[[:blank:]]", "a", false, false);
- }
-
- @Test
- public void testCntrlGroupCase0() throws Exception {
- assertMatch("[[:cntrl:]]", "a", false, false);
- }
-
- @Test
- public void testCntrlGroupCase1() throws Exception {
- assertMatch("[[:cntrl:]]", String.valueOf((char) 7), true, false);
- }
-
- @Test
- public void testDigitGroupCase0() throws Exception {
- assertMatch("[[:digit:]]", "0", true, false);
- }
-
- @Test
- public void testDigitGroupCase1() throws Exception {
- assertMatch("[[:digit:]]", "5", true, false);
- }
-
- @Test
- public void testDigitGroupCase2() throws Exception {
- assertMatch("[[:digit:]]", "9", true, false);
- }
-
- @Test
- public void testDigitGroupCase3() throws Exception {
- // \u06f9 = EXTENDED ARABIC-INDIC DIGIT NINE
- assertMatch("[[:digit:]]", "\u06f9", true, false);
- }
-
- @Test
- public void testDigitGroupCase4() throws Exception {
- assertMatch("[[:digit:]]", "a", false, false);
- }
-
- @Test
- public void testDigitGroupCase5() throws Exception {
- assertMatch("[[:digit:]]", "]", false, false);
- }
-
- @Test
- public void testGraphGroupCase0() throws Exception {
- assertMatch("[[:graph:]]", "]", true, false);
- }
-
- @Test
- public void testGraphGroupCase1() throws Exception {
- assertMatch("[[:graph:]]", "a", true, false);
- }
-
- @Test
- public void testGraphGroupCase2() throws Exception {
- assertMatch("[[:graph:]]", ".", true, false);
- }
-
- @Test
- public void testGraphGroupCase3() throws Exception {
- assertMatch("[[:graph:]]", "0", true, false);
- }
-
- @Test
- public void testGraphGroupCase4() throws Exception {
- assertMatch("[[:graph:]]", " ", false, false);
- }
-
- @Test
- public void testGraphGroupCase5() throws Exception {
- // \u00f6 = 'o' with dots on it
- assertMatch("[[:graph:]]", "\u00f6", true, false);
- }
-
- @Test
- public void testLowerGroupCase0() throws Exception {
- assertMatch("[[:lower:]]", "a", true, false);
- }
-
- @Test
- public void testLowerGroupCase1() throws Exception {
- assertMatch("[[:lower:]]", "h", true, false);
- }
-
- @Test
- public void testLowerGroupCase2() throws Exception {
- assertMatch("[[:lower:]]", "A", false, false);
- }
-
- @Test
- public void testLowerGroupCase3() throws Exception {
- assertMatch("[[:lower:]]", "H", false, false);
- }
-
- @Test
- public void testLowerGroupCase4() throws Exception {
- // \u00e4 = small 'a' with dots on it
- assertMatch("[[:lower:]]", "\u00e4", true, false);
- }
-
- @Test
- public void testLowerGroupCase5() throws Exception {
- assertMatch("[[:lower:]]", ".", false, false);
- }
-
- @Test
- public void testPrintGroupCase0() throws Exception {
- assertMatch("[[:print:]]", "]", true, false);
- }
-
- @Test
- public void testPrintGroupCase1() throws Exception {
- assertMatch("[[:print:]]", "a", true, false);
- }
-
- @Test
- public void testPrintGroupCase2() throws Exception {
- assertMatch("[[:print:]]", ".", true, false);
- }
-
- @Test
- public void testPrintGroupCase3() throws Exception {
- assertMatch("[[:print:]]", "0", true, false);
- }
-
- @Test
- public void testPrintGroupCase4() throws Exception {
- assertMatch("[[:print:]]", " ", true, false);
- }
-
- @Test
- public void testPrintGroupCase5() throws Exception {
- // \u00f6 = 'o' with dots on it
- assertMatch("[[:print:]]", "\u00f6", true, false);
- }
-
- @Test
- public void testPunctGroupCase0() throws Exception {
- assertMatch("[[:punct:]]", ".", true, false);
- }
-
- @Test
- public void testPunctGroupCase1() throws Exception {
- assertMatch("[[:punct:]]", "@", true, false);
- }
-
- @Test
- public void testPunctGroupCase2() throws Exception {
- assertMatch("[[:punct:]]", " ", false, false);
- }
-
- @Test
- public void testPunctGroupCase3() throws Exception {
- assertMatch("[[:punct:]]", "a", false, false);
- }
-
- @Test
- public void testSpaceGroupCase0() throws Exception {
- assertMatch("[[:space:]]", " ", true, false);
- }
-
- @Test
- public void testSpaceGroupCase1() throws Exception {
- assertMatch("[[:space:]]", "\t", true, false);
- }
-
- @Test
- public void testSpaceGroupCase2() throws Exception {
- assertMatch("[[:space:]]", "\r", true, false);
- }
-
- @Test
- public void testSpaceGroupCase3() throws Exception {
- assertMatch("[[:space:]]", "\n", true, false);
- }
-
- @Test
- public void testSpaceGroupCase4() throws Exception {
- assertMatch("[[:space:]]", "a", false, false);
- }
-
- @Test
- public void testUpperGroupCase0() throws Exception {
- assertMatch("[[:upper:]]", "a", false, false);
- }
-
- @Test
- public void testUpperGroupCase1() throws Exception {
- assertMatch("[[:upper:]]", "h", false, false);
- }
-
- @Test
- public void testUpperGroupCase2() throws Exception {
- assertMatch("[[:upper:]]", "A", true, false);
- }
-
- @Test
- public void testUpperGroupCase3() throws Exception {
- assertMatch("[[:upper:]]", "H", true, false);
- }
-
- @Test
- public void testUpperGroupCase4() throws Exception {
- // \u00c4 = 'A' with dots on it
- assertMatch("[[:upper:]]", "\u00c4", true, false);
- }
-
- @Test
- public void testUpperGroupCase5() throws Exception {
- assertMatch("[[:upper:]]", ".", false, false);
- }
-
- @Test
- public void testXDigitGroupCase0() throws Exception {
- assertMatch("[[:xdigit:]]", "a", true, false);
- }
-
- @Test
- public void testXDigitGroupCase1() throws Exception {
- assertMatch("[[:xdigit:]]", "d", true, false);
- }
-
- @Test
- public void testXDigitGroupCase2() throws Exception {
- assertMatch("[[:xdigit:]]", "f", true, false);
- }
-
- @Test
- public void testXDigitGroupCase3() throws Exception {
- assertMatch("[[:xdigit:]]", "0", true, false);
- }
-
- @Test
- public void testXDigitGroupCase4() throws Exception {
- assertMatch("[[:xdigit:]]", "5", true, false);
- }
-
- @Test
- public void testXDigitGroupCase5() throws Exception {
- assertMatch("[[:xdigit:]]", "9", true, false);
- }
-
- @Test
- public void testXDigitGroupCase6() throws Exception {
- assertMatch("[[:xdigit:]]", "۹", false, false);
- }
-
- @Test
- public void testXDigitGroupCase7() throws Exception {
- assertMatch("[[:xdigit:]]", ".", false, false);
- }
-
- @Test
- public void testWordroupCase0() throws Exception {
- assertMatch("[[:word:]]", "g", true, false);
- }
-
- @Test
- public void testWordroupCase1() throws Exception {
- // \u00f6 = 'o' with dots on it
- assertMatch("[[:word:]]", "\u00f6", true, false);
- }
-
- @Test
- public void testWordroupCase2() throws Exception {
- assertMatch("[[:word:]]", "5", true, false);
- }
-
- @Test
- public void testWordroupCase3() throws Exception {
- assertMatch("[[:word:]]", "_", true, false);
- }
-
- @Test
- public void testWordroupCase4() throws Exception {
- assertMatch("[[:word:]]", " ", false, false);
- }
-
- @Test
- public void testWordroupCase5() throws Exception {
- assertMatch("[[:word:]]", ".", false, false);
- }
-
- @Test
- public void testMixedGroupCase0() throws Exception {
- assertMatch("[A[:lower:]C3-5]", "A", true, false);
- }
-
- @Test
- public void testMixedGroupCase1() throws Exception {
- assertMatch("[A[:lower:]C3-5]", "C", true, false);
- }
-
- @Test
- public void testMixedGroupCase2() throws Exception {
- assertMatch("[A[:lower:]C3-5]", "e", true, false);
- }
-
- @Test
- public void testMixedGroupCase3() throws Exception {
- assertMatch("[A[:lower:]C3-5]", "3", true, false);
- }
-
- @Test
- public void testMixedGroupCase4() throws Exception {
- assertMatch("[A[:lower:]C3-5]", "4", true, false);
- }
-
- @Test
- public void testMixedGroupCase5() throws Exception {
- assertMatch("[A[:lower:]C3-5]", "5", true, false);
- }
-
- @Test
- public void testMixedGroupCase6() throws Exception {
- assertMatch("[A[:lower:]C3-5]", "B", false, false);
- }
-
- @Test
- public void testMixedGroupCase7() throws Exception {
- assertMatch("[A[:lower:]C3-5]", "2", false, false);
- }
-
- @Test
- public void testMixedGroupCase8() throws Exception {
- assertMatch("[A[:lower:]C3-5]", "6", false, false);
- }
-
- @Test
- public void testMixedGroupCase9() throws Exception {
- assertMatch("[A[:lower:]C3-5]", ".", false, false);
- }
-
- @Test
- public void testSpecialGroupCase0() throws Exception {
- assertMatch("[[]", "[", true, false);
- }
-
- @Test
- public void testSpecialGroupCase1() throws Exception {
- assertMatch("[]]", "]", true, false);
- }
-
- @Test
- public void testSpecialGroupCase2() throws Exception {
- assertMatch("[]a]", "]", true, false);
- }
-
- @Test
- public void testSpecialGroupCase3() throws Exception {
- assertMatch("[a[]", "[", true, false);
- }
-
- @Test
- public void testSpecialGroupCase4() throws Exception {
- assertMatch("[a[]", "a", true, false);
- }
-
- @Test
- public void testSpecialGroupCase5() throws Exception {
- assertMatch("[!]]", "]", false, false);
- }
-
- @Test
- public void testSpecialGroupCase6() throws Exception {
- assertMatch("[!]]", "x", true, false);
- }
-
- @Test
- public void testSpecialGroupCase7() throws Exception {
- assertMatch("[:]]", ":]", true, false);
- }
-
- @Test
- public void testSpecialGroupCase8() throws Exception {
- assertMatch("[:]]", ":", false, true);
- }
-
- @Test
- public void testSpecialGroupCase9() throws Exception {
- try {
- assertMatch("[[:]", ":", true, true);
- fail("InvalidPatternException expected");
- } catch (InvalidPatternException e) {
- // expected
- }
- }
-
- @Test
- public void testUnsupportedGroupCase0() throws Exception {
- try {
- assertMatch("[[=a=]]", "b", false, false);
- fail("InvalidPatternException expected");
- } catch (InvalidPatternException e) {
- assertTrue(e.getMessage().contains("[=a=]"));
- }
- }
-
- @Test
- public void testUnsupportedGroupCase1() throws Exception {
- try {
- assertMatch("[[.a.]]", "b", false, false);
- fail("InvalidPatternException expected");
- } catch (InvalidPatternException e) {
- assertTrue(e.getMessage().contains("[.a.]"));
- }
- }
-
- @Test
- public void testEscapedBracket1() throws Exception {
- assertMatch("\\[", "[", true, false);
- }
-
- @Test
- public void testEscapedBracket2() throws Exception {
- assertMatch("\\[[a]", "[", false, true);
- }
-
- @Test
- public void testEscapedBracket3() throws Exception {
- assertMatch("\\[[a]", "a", false, false);
- }
-
- @Test
- public void testEscapedBracket4() throws Exception {
- assertMatch("\\[[a]", "[a", true, false);
- }
-
- @Test
- public void testEscapedBracket5() throws Exception {
- assertMatch("[a\\]]", "]", true, false);
- }
-
- @Test
- public void testEscapedBracket6() throws Exception {
- assertMatch("[a\\]]", "a", true, false);
- }
-
- @Test
- public void testEscapedBackslash() throws Exception {
- assertMatch("a\\\\b", "a\\b", true, false);
- }
-
- @Test
- public void testMultipleEscapedCharacters1() throws Exception {
- assertMatch("\\]a?c\\*\\[d\\?\\]", "]abc*[d?]", true, false);
- }
-
- @Test
- public void testFilePathSimpleCase() throws Exception {
- assertFileNameMatch("a/b", "a/b", '/', true, false);
- }
-
- @Test
- public void testFilePathCase0() throws Exception {
- assertFileNameMatch("a*b", "a/b", '/', false, false);
- }
-
- @Test
- public void testFilePathCase1() throws Exception {
- assertFileNameMatch("a?b", "a/b", '/', false, false);
- }
-
- @Test
- public void testFilePathCase2() throws Exception {
- assertFileNameMatch("a*b", "a\\b", '\\', false, false);
- }
-
- @Test
- public void testFilePathCase3() throws Exception {
- assertFileNameMatch("a?b", "a\\b", '\\', false, false);
- }
-
- @Test
- public void testReset() throws Exception {
- final String pattern = "helloworld";
- final FileNameMatcher matcher = new FileNameMatcher(pattern, null);
- matcher.append("helloworld");
- assertTrue(matcher.isMatch());
- assertFalse(matcher.canAppendMatch());
- matcher.reset();
- matcher.append("hello");
- assertFalse(matcher.isMatch());
- assertTrue(matcher.canAppendMatch());
- matcher.append("world");
- assertTrue(matcher.isMatch());
- assertFalse(matcher.canAppendMatch());
- matcher.append("to much");
- assertFalse(matcher.isMatch());
- assertFalse(matcher.canAppendMatch());
- matcher.reset();
- matcher.append("helloworld");
- assertTrue(matcher.isMatch());
- assertFalse(matcher.canAppendMatch());
- }
-
- @Test
- public void testCreateMatcherForSuffix() throws Exception {
- final String pattern = "helloworld";
- final FileNameMatcher matcher = new FileNameMatcher(pattern, null);
- matcher.append("hello");
- final FileNameMatcher childMatcher = matcher.createMatcherForSuffix();
- assertFalse(matcher.isMatch());
- assertTrue(matcher.canAppendMatch());
- assertFalse(childMatcher.isMatch());
- assertTrue(childMatcher.canAppendMatch());
- matcher.append("world");
- assertTrue(matcher.isMatch());
- assertFalse(matcher.canAppendMatch());
- assertFalse(childMatcher.isMatch());
- assertTrue(childMatcher.canAppendMatch());
- childMatcher.append("world");
- assertTrue(matcher.isMatch());
- assertFalse(matcher.canAppendMatch());
- assertTrue(childMatcher.isMatch());
- assertFalse(childMatcher.canAppendMatch());
- childMatcher.reset();
- assertTrue(matcher.isMatch());
- assertFalse(matcher.canAppendMatch());
- assertFalse(childMatcher.isMatch());
- assertTrue(childMatcher.canAppendMatch());
- childMatcher.append("world");
- assertTrue(matcher.isMatch());
- assertFalse(matcher.canAppendMatch());
- assertTrue(childMatcher.isMatch());
- assertFalse(childMatcher.canAppendMatch());
- }
-
- @Test
- public void testCopyConstructor() throws Exception {
- final String pattern = "helloworld";
- final FileNameMatcher matcher = new FileNameMatcher(pattern, null);
- matcher.append("hello");
- final FileNameMatcher copy = new FileNameMatcher(matcher);
- assertFalse(matcher.isMatch());
- assertTrue(matcher.canAppendMatch());
- assertFalse(copy.isMatch());
- assertTrue(copy.canAppendMatch());
- matcher.append("world");
- assertTrue(matcher.isMatch());
- assertFalse(matcher.canAppendMatch());
- assertFalse(copy.isMatch());
- assertTrue(copy.canAppendMatch());
- copy.append("world");
- assertTrue(matcher.isMatch());
- assertFalse(matcher.canAppendMatch());
- assertTrue(copy.isMatch());
- assertFalse(copy.canAppendMatch());
- copy.reset();
- assertTrue(matcher.isMatch());
- assertFalse(matcher.canAppendMatch());
- assertFalse(copy.isMatch());
- assertTrue(copy.canAppendMatch());
- copy.append("helloworld");
- assertTrue(matcher.isMatch());
- assertFalse(matcher.canAppendMatch());
- assertTrue(copy.isMatch());
- assertFalse(copy.canAppendMatch());
- }
- }
|