@ -44,12 +44,14 @@
package org.eclipse.jgit.fnmatch ;
import org.eclipse.jgit.errors.InvalidPatternException ;
import org.eclipse.jgit.fnmatch.FileNameMatcher ;
import static org.junit.Assert.assertEquals ;
import static org.junit.Assert.assertTrue ;
import static org.junit.Assert.fail ;
import junit.framework.TestCase ;
import org.eclipse.jgit.errors.InvalidPatternException ;
import org.junit.Test ;
public class FileNameMatcherTest extends TestCase {
public class FileNameMatcherTest {
private void assertMatch ( final String pattern , final String input ,
final boolean matchExpected , final boolean appendCanMatchExpected )
@ -71,178 +73,222 @@ public class FileNameMatcherTest extends TestCase {
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 ) ;
}
@ -254,383 +300,476 @@ public class FileNameMatcherTest extends TestCase {
* @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 ) ;
@ -640,6 +779,7 @@ public class FileNameMatcherTest extends TestCase {
}
}
@Test
public void testUnsupportedGroupCase0 ( ) throws Exception {
try {
assertMatch ( "[[=a=]]" , "b" , false , false ) ;
@ -649,6 +789,7 @@ public class FileNameMatcherTest extends TestCase {
}
}
@Test
public void testUnsupportedGroupCase1 ( ) throws Exception {
try {
assertMatch ( "[[.a.]]" , "b" , false , false ) ;
@ -658,26 +799,32 @@ public class FileNameMatcherTest extends TestCase {
}
}
@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 ) ;
@ -700,6 +847,7 @@ public class FileNameMatcherTest extends TestCase {
assertEquals ( false , matcher . canAppendMatch ( ) ) ;
}
@Test
public void testCreateMatcherForSuffix ( ) throws Exception {
final String pattern = "helloworld" ;
final FileNameMatcher matcher = new FileNameMatcher ( pattern , null ) ;
@ -731,6 +879,7 @@ public class FileNameMatcherTest extends TestCase {
assertEquals ( false , childMatcher . canAppendMatch ( ) ) ;
}
@Test
public void testCopyConstructor ( ) throws Exception {
final String pattern = "helloworld" ;
final FileNameMatcher matcher = new FileNameMatcher ( pattern , null ) ;