diff test/org/tmatesoft/hg/test/TestIgnore.java @ 342:516b817415ba

HgIgnore: regex patterns to match part of the filename do not work
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Fri, 18 Nov 2011 05:10:33 +0100
parents 863356c2847e
children 58016b1b8554
line wrap: on
line diff
--- a/test/org/tmatesoft/hg/test/TestIgnore.java	Thu Nov 17 07:04:58 2011 +0100
+++ b/test/org/tmatesoft/hg/test/TestIgnore.java	Fri Nov 18 05:10:33 2011 +0100
@@ -41,7 +41,7 @@
 		TestIgnore test = new TestIgnore();
 		test.testGlobWithAlternatives();
 		test.testComplexFileParse();
-		test.testSegmentsMatch();
+		test.testSegmentsGlobMatch();
 		test.testWildcardsDoNotMatchDirectorySeparator();
 		test.errorCollector.verify();
 	}
@@ -74,7 +74,7 @@
 	}
 
 	@Test
-	public void testSegmentsMatch() throws Exception {
+	public void testSegmentsGlobMatch() throws Exception {
 		String s = "syntax:glob\nbin\n.*\nTEST-*.xml";
 		HgIgnore hgIgnore = HgInternals.newHgIgnore(new StringReader(s));
 		Path[] toCheck = new Path[] {
@@ -89,7 +89,27 @@
 			errorCollector.assertTrue(p.toString(), hgIgnore.isIgnored(p));
 		}
 	}
-	
+
+	@Test
+	public void testSegmentsRegexMatch() throws Exception {
+		// regex patterns that don't start with explicit ^ are allowed to match anywhere in the string
+		String s = "syntax:regex\n/\\.git\n^abc\n";
+		HgIgnore hgIgnore = HgInternals.newHgIgnore(new StringReader(s));
+		Path p = Path.create(".git/aa");
+		errorCollector.assertTrue(p.toString(), !hgIgnore.isIgnored(p));
+		p = Path.create("dir/.git/bb");
+		errorCollector.assertTrue(p.toString(), hgIgnore.isIgnored(p));
+		p = Path.create("dir/abc/aa");
+		errorCollector.assertTrue(p.toString(), !hgIgnore.isIgnored(p));
+		p = Path.create("abc/bb");
+		errorCollector.assertTrue(p.toString(), hgIgnore.isIgnored(p));
+		// Mercurial (in fact, likely pyton's regex match() function) treats
+		// regex patterns as having .* at the end (unless there's explicit $). 
+		// IOW, matches to the beginning of the string, not to the whole string  
+		p = Path.create("abcde/fg"); 
+		errorCollector.assertTrue(p.toString(), hgIgnore.isIgnored(p));
+	}
+
 	@Test
 	public void testWildcardsDoNotMatchDirectorySeparator() throws Exception {
 		String s = "syntax:glob\na?b\nc*d";