diff test/org/tmatesoft/hg/test/TestIgnore.java @ 339:863356c2847e

Issue 16: respect glob patterns in HgIgnore for sub-directories
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Wed, 16 Nov 2011 22:42:21 +0100
parents 7af843ecc378
children 516b817415ba
line wrap: on
line diff
--- a/test/org/tmatesoft/hg/test/TestIgnore.java	Tue Nov 15 04:47:03 2011 +0100
+++ b/test/org/tmatesoft/hg/test/TestIgnore.java	Wed Nov 16 22:42:21 2011 +0100
@@ -41,6 +41,8 @@
 		TestIgnore test = new TestIgnore();
 		test.testGlobWithAlternatives();
 		test.testComplexFileParse();
+		test.testSegmentsMatch();
+		test.testWildcardsDoNotMatchDirectorySeparator();
 		test.errorCollector.verify();
 	}
 	
@@ -71,4 +73,55 @@
 		}
 	}
 
+	@Test
+	public void testSegmentsMatch() throws Exception {
+		String s = "syntax:glob\nbin\n.*\nTEST-*.xml";
+		HgIgnore hgIgnore = HgInternals.newHgIgnore(new StringReader(s));
+		Path[] toCheck = new Path[] {
+				Path.create("bin/org/sample/First.class"),
+				Path.create(".ignored-file"),
+				Path.create("dir/.ignored-file"),
+				Path.create("dir/.ignored-dir/file"),
+				Path.create("TEST-a.xml"),
+				Path.create("dir/TEST-b.xml"),
+		};
+		for (Path p : toCheck) {
+			errorCollector.assertTrue(p.toString(), hgIgnore.isIgnored(p));
+		}
+	}
+	
+	@Test
+	public void testWildcardsDoNotMatchDirectorySeparator() throws Exception {
+		String s = "syntax:glob\na?b\nc*d";
+		HgIgnore hgIgnore = HgInternals.newHgIgnore(new StringReader(s));
+		// shall not be ignored
+		Path[] toPass = new Path[] {
+				Path.create("a/b"),
+				Path.create("a/b/x"),
+				Path.create("x/a/b"),
+				Path.create("axyb"),
+				Path.create("c/d"),
+				Path.create("c/d/x"),
+				Path.create("x/c/d"),
+		};
+		// shall be ignored
+		Path[] toIgnore = new Path[] {
+				Path.create("axb"),
+				Path.create("a3b"),
+				Path.create("a_b"),
+				Path.create("cd"),
+				Path.create("cxd"),
+				Path.create("cxyd"),
+				Path.create("x/cd"),
+				Path.create("x/cxyd"),
+				Path.create("cd/x"),
+				Path.create("cxyd/x"),
+		};
+		for (Path p : toIgnore) {
+			errorCollector.assertTrue(p.toString(), hgIgnore.isIgnored(p));
+		}
+		for (Path p : toPass) {
+			errorCollector.assertTrue(p.toString(), !hgIgnore.isIgnored(p));
+		}
+	}
 }