Mercurial > hg4j
comparison 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 |
comparison
equal
deleted
inserted
replaced
341:75c452fdd76a | 342:516b817415ba |
---|---|
39 | 39 |
40 public static void main(String[] args) throws Throwable { | 40 public static void main(String[] args) throws Throwable { |
41 TestIgnore test = new TestIgnore(); | 41 TestIgnore test = new TestIgnore(); |
42 test.testGlobWithAlternatives(); | 42 test.testGlobWithAlternatives(); |
43 test.testComplexFileParse(); | 43 test.testComplexFileParse(); |
44 test.testSegmentsMatch(); | 44 test.testSegmentsGlobMatch(); |
45 test.testWildcardsDoNotMatchDirectorySeparator(); | 45 test.testWildcardsDoNotMatchDirectorySeparator(); |
46 test.errorCollector.verify(); | 46 test.errorCollector.verify(); |
47 } | 47 } |
48 | 48 |
49 @Test | 49 @Test |
72 errorCollector.assertTrue(p.toString(), hgIgnore.isIgnored(p)); | 72 errorCollector.assertTrue(p.toString(), hgIgnore.isIgnored(p)); |
73 } | 73 } |
74 } | 74 } |
75 | 75 |
76 @Test | 76 @Test |
77 public void testSegmentsMatch() throws Exception { | 77 public void testSegmentsGlobMatch() throws Exception { |
78 String s = "syntax:glob\nbin\n.*\nTEST-*.xml"; | 78 String s = "syntax:glob\nbin\n.*\nTEST-*.xml"; |
79 HgIgnore hgIgnore = HgInternals.newHgIgnore(new StringReader(s)); | 79 HgIgnore hgIgnore = HgInternals.newHgIgnore(new StringReader(s)); |
80 Path[] toCheck = new Path[] { | 80 Path[] toCheck = new Path[] { |
81 Path.create("bin/org/sample/First.class"), | 81 Path.create("bin/org/sample/First.class"), |
82 Path.create(".ignored-file"), | 82 Path.create(".ignored-file"), |
87 }; | 87 }; |
88 for (Path p : toCheck) { | 88 for (Path p : toCheck) { |
89 errorCollector.assertTrue(p.toString(), hgIgnore.isIgnored(p)); | 89 errorCollector.assertTrue(p.toString(), hgIgnore.isIgnored(p)); |
90 } | 90 } |
91 } | 91 } |
92 | 92 |
93 @Test | |
94 public void testSegmentsRegexMatch() throws Exception { | |
95 // regex patterns that don't start with explicit ^ are allowed to match anywhere in the string | |
96 String s = "syntax:regex\n/\\.git\n^abc\n"; | |
97 HgIgnore hgIgnore = HgInternals.newHgIgnore(new StringReader(s)); | |
98 Path p = Path.create(".git/aa"); | |
99 errorCollector.assertTrue(p.toString(), !hgIgnore.isIgnored(p)); | |
100 p = Path.create("dir/.git/bb"); | |
101 errorCollector.assertTrue(p.toString(), hgIgnore.isIgnored(p)); | |
102 p = Path.create("dir/abc/aa"); | |
103 errorCollector.assertTrue(p.toString(), !hgIgnore.isIgnored(p)); | |
104 p = Path.create("abc/bb"); | |
105 errorCollector.assertTrue(p.toString(), hgIgnore.isIgnored(p)); | |
106 // Mercurial (in fact, likely pyton's regex match() function) treats | |
107 // regex patterns as having .* at the end (unless there's explicit $). | |
108 // IOW, matches to the beginning of the string, not to the whole string | |
109 p = Path.create("abcde/fg"); | |
110 errorCollector.assertTrue(p.toString(), hgIgnore.isIgnored(p)); | |
111 } | |
112 | |
93 @Test | 113 @Test |
94 public void testWildcardsDoNotMatchDirectorySeparator() throws Exception { | 114 public void testWildcardsDoNotMatchDirectorySeparator() throws Exception { |
95 String s = "syntax:glob\na?b\nc*d"; | 115 String s = "syntax:glob\na?b\nc*d"; |
96 HgIgnore hgIgnore = HgInternals.newHgIgnore(new StringReader(s)); | 116 HgIgnore hgIgnore = HgInternals.newHgIgnore(new StringReader(s)); |
97 // shall not be ignored | 117 // shall not be ignored |