Mercurial > hg4j
comparison test/org/tmatesoft/hg/test/TestIgnore.java @ 409:0f5696623512 smartgit3
Support glob path pattern rewrite to facilitate use of globs with Windows path separator
author | Artem Tikhomirov <tikhomirov.artem@gmail.com> |
---|---|
date | Fri, 16 Mar 2012 20:14:47 +0100 |
parents | e732521a9eb4 |
children | dca70c0b1f74 |
comparison
equal
deleted
inserted
replaced
408:e732521a9eb4 | 409:0f5696623512 |
---|---|
23 import java.io.FileReader; | 23 import java.io.FileReader; |
24 import java.io.StringReader; | 24 import java.io.StringReader; |
25 | 25 |
26 import org.junit.Rule; | 26 import org.junit.Rule; |
27 import org.junit.Test; | 27 import org.junit.Test; |
28 import org.tmatesoft.hg.internal.WinToNixPathRewrite; | |
28 import org.tmatesoft.hg.repo.HgIgnore; | 29 import org.tmatesoft.hg.repo.HgIgnore; |
29 import org.tmatesoft.hg.repo.HgInternals; | 30 import org.tmatesoft.hg.repo.HgInternals; |
30 import org.tmatesoft.hg.util.Path; | 31 import org.tmatesoft.hg.util.Path; |
31 | 32 |
32 /** | 33 /** |
49 } | 50 } |
50 | 51 |
51 @Test | 52 @Test |
52 public void testGlobWithAlternatives() throws Exception { | 53 public void testGlobWithAlternatives() throws Exception { |
53 String content = "syntax:glob\ndoc/*.[0-9].{x,ht}ml"; | 54 String content = "syntax:glob\ndoc/*.[0-9].{x,ht}ml"; |
54 HgIgnore hgIgnore = HgInternals.newHgIgnore(new StringReader(content)); | 55 HgIgnore hgIgnore = HgInternals.newHgIgnore(new StringReader(content), null); |
55 final Path p1 = Path.create("doc/asd.2.xml"); | 56 final Path p1 = Path.create("doc/asd.2.xml"); |
56 final Path p2 = Path.create("doc/zxc.6.html"); | 57 final Path p2 = Path.create("doc/zxc.6.html"); |
57 errorCollector.assertTrue(p1.toString(), hgIgnore.isIgnored(p1)); | 58 errorCollector.assertTrue(p1.toString(), hgIgnore.isIgnored(p1)); |
58 errorCollector.assertTrue(p2.toString(), hgIgnore.isIgnored(p2)); | 59 errorCollector.assertTrue(p2.toString(), hgIgnore.isIgnored(p2)); |
59 } | 60 } |
60 | 61 |
61 @Test | 62 @Test |
62 public void testComplexFileParse() throws Exception { | 63 public void testComplexFileParse() throws Exception { |
63 BufferedReader br = new BufferedReader(new FileReader(new File(Configuration.get().getTestDataDir(), "mercurial.hgignore"))); | 64 BufferedReader br = new BufferedReader(new FileReader(new File(Configuration.get().getTestDataDir(), "mercurial.hgignore"))); |
64 HgIgnore hgIgnore = HgInternals.newHgIgnore(br); | 65 HgIgnore hgIgnore = HgInternals.newHgIgnore(br, null); |
65 br.close(); | 66 br.close(); |
66 Path[] toCheck = new Path[] { | 67 Path[] toCheck = new Path[] { |
67 Path.create("file.so"), | 68 Path.create("file.so"), |
68 Path.create("a/b/file.so"), | 69 Path.create("a/b/file.so"), |
69 Path.create("#abc#"), | 70 Path.create("#abc#"), |
70 Path.create(".#abc"), | 71 Path.create(".#abc"), |
71 Path.create("locale/en/LC_MESSAGES/hg.mo"), | 72 Path.create("locale/en/LC_MESSAGES/hg.mo"), |
72 }; | 73 }; |
73 for (Path p : toCheck) { | 74 doAssert(hgIgnore, toCheck, null); |
74 errorCollector.assertTrue(p.toString(), hgIgnore.isIgnored(p)); | |
75 } | |
76 } | 75 } |
77 | 76 |
78 @Test | 77 @Test |
79 public void testSegmentsGlobMatch() throws Exception { | 78 public void testSegmentsGlobMatch() throws Exception { |
80 String s = "syntax:glob\nbin\n.*\nTEST-*.xml"; | 79 String s = "syntax:glob\nbin\n.*\nTEST-*.xml"; |
81 HgIgnore hgIgnore = HgInternals.newHgIgnore(new StringReader(s)); | 80 HgIgnore hgIgnore = HgInternals.newHgIgnore(new StringReader(s), null); |
82 Path[] toCheck = new Path[] { | 81 Path[] toCheck = new Path[] { |
83 Path.create("bin/org/sample/First.class"), | 82 Path.create("bin/org/sample/First.class"), |
84 Path.create(".ignored-file"), | 83 Path.create(".ignored-file"), |
85 Path.create("dir/.ignored-file"), | 84 Path.create("dir/.ignored-file"), |
86 Path.create("dir/.ignored-dir/file"), | 85 Path.create("dir/.ignored-dir/file"), |
87 Path.create("TEST-a.xml"), | 86 Path.create("TEST-a.xml"), |
88 Path.create("dir/TEST-b.xml"), | 87 Path.create("dir/TEST-b.xml"), |
89 }; | 88 }; |
90 for (Path p : toCheck) { | 89 doAssert(hgIgnore, toCheck, null); |
91 errorCollector.assertTrue(p.toString(), hgIgnore.isIgnored(p)); | 90 // |
92 } | |
93 s = "syntax:glob\n.git"; | 91 s = "syntax:glob\n.git"; |
94 hgIgnore = HgInternals.newHgIgnore(new StringReader(s)); | 92 hgIgnore = HgInternals.newHgIgnore(new StringReader(s), null); |
95 Path p = Path.create(".git/aa"); | 93 Path p = Path.create(".git/aa"); |
96 errorCollector.assertTrue(p.toString(), hgIgnore.isIgnored(p)); | 94 errorCollector.assertTrue(p.toString(), hgIgnore.isIgnored(p)); |
97 p = Path.create("dir/.git/bb"); | 95 p = Path.create("dir/.git/bb"); |
98 errorCollector.assertTrue(p.toString(), hgIgnore.isIgnored(p)); | 96 errorCollector.assertTrue(p.toString(), hgIgnore.isIgnored(p)); |
99 p = Path.create("dir/.gittt/cc"); | 97 p = Path.create("dir/.gittt/cc"); |
102 | 100 |
103 @Test | 101 @Test |
104 public void testSegmentsRegexMatch() throws Exception { | 102 public void testSegmentsRegexMatch() throws Exception { |
105 // regex patterns that don't start with explicit ^ are allowed to match anywhere in the string | 103 // regex patterns that don't start with explicit ^ are allowed to match anywhere in the string |
106 String s = "syntax:regexp\n/\\.git\n^abc\n"; | 104 String s = "syntax:regexp\n/\\.git\n^abc\n"; |
107 HgIgnore hgIgnore = HgInternals.newHgIgnore(new StringReader(s)); | 105 HgIgnore hgIgnore = HgInternals.newHgIgnore(new StringReader(s), null); |
108 Path p = Path.create(".git/aa"); | 106 Path p = Path.create(".git/aa"); |
109 errorCollector.assertTrue(p.toString(), !hgIgnore.isIgnored(p)); | 107 errorCollector.assertTrue(p.toString(), !hgIgnore.isIgnored(p)); |
110 p = Path.create("dir/.git/bb"); | 108 p = Path.create("dir/.git/bb"); |
111 errorCollector.assertTrue(p.toString(), hgIgnore.isIgnored(p)); | 109 errorCollector.assertTrue(p.toString(), hgIgnore.isIgnored(p)); |
112 p = Path.create("dir/abc/aa"); | 110 p = Path.create("dir/abc/aa"); |
121 } | 119 } |
122 | 120 |
123 @Test | 121 @Test |
124 public void testWildcardsDoNotMatchDirectorySeparator() throws Exception { | 122 public void testWildcardsDoNotMatchDirectorySeparator() throws Exception { |
125 String s = "syntax:glob\na?b\nc*d"; | 123 String s = "syntax:glob\na?b\nc*d"; |
126 HgIgnore hgIgnore = HgInternals.newHgIgnore(new StringReader(s)); | 124 HgIgnore hgIgnore = HgInternals.newHgIgnore(new StringReader(s), null); |
127 // shall not be ignored | 125 // shall not be ignored |
128 Path[] toPass = new Path[] { | 126 Path[] toPass = new Path[] { |
129 Path.create("a/b"), | 127 Path.create("a/b"), |
130 Path.create("a/b/x"), | 128 Path.create("a/b/x"), |
131 Path.create("x/a/b"), | 129 Path.create("x/a/b"), |
145 Path.create("x/cd"), | 143 Path.create("x/cd"), |
146 Path.create("x/cxyd"), | 144 Path.create("x/cxyd"), |
147 Path.create("cd/x"), | 145 Path.create("cd/x"), |
148 Path.create("cxyd/x"), | 146 Path.create("cxyd/x"), |
149 }; | 147 }; |
150 for (Path p : toIgnore) { | 148 doAssert(hgIgnore, toIgnore, toPass); |
151 errorCollector.assertTrue(p.toString(), hgIgnore.isIgnored(p)); | |
152 } | |
153 for (Path p : toPass) { | |
154 errorCollector.assertTrue(p.toString(), !hgIgnore.isIgnored(p)); | |
155 } | |
156 } | 149 } |
157 | 150 |
158 @Test | 151 @Test |
159 public void testSyntaxPrefixAtLine() throws Exception { | 152 public void testSyntaxPrefixAtLine() throws Exception { |
160 String s = "glob:*.c\nregexp:.*\\.d"; | 153 String s = "glob:*.c\nregexp:.*\\.d"; |
161 HgIgnore hgIgnore = HgInternals.newHgIgnore(new StringReader(s)); | 154 HgIgnore hgIgnore = HgInternals.newHgIgnore(new StringReader(s), null); |
162 Path[] toPass = new Path[] { | 155 Path[] toPass = new Path[] { |
163 create("a/c"), | 156 create("a/c"), |
164 create("a/d"), | 157 create("a/d"), |
165 create("a/d.a"), | 158 create("a/d.a"), |
166 create("a/d.e"), | 159 create("a/d.e"), |
169 create("a.c"), | 162 create("a.c"), |
170 create("a.d"), | 163 create("a.d"), |
171 create("src/a.c"), | 164 create("src/a.c"), |
172 create("src/a.d"), | 165 create("src/a.d"), |
173 }; | 166 }; |
174 for (Path p : toIgnore) { | 167 doAssert(hgIgnore, toIgnore, toPass); |
175 errorCollector.assertTrue("Shall ignore " + p, hgIgnore.isIgnored(p)); | 168 } |
169 | |
170 @Test | |
171 public void testGlobWithWindowsPathSeparators() throws Exception { | |
172 String s = "syntax:glob\n" + "bin\\*\n" + "*\\dir*\\*.a\n" + "*\\_ReSharper*\\\n"; | |
173 // explicit PathRewrite for the test to run on *nix as well | |
174 HgIgnore hgIgnore = HgInternals.newHgIgnore(new StringReader(s), new WinToNixPathRewrite()); | |
175 Path[] toPass = new Path[] { | |
176 create("bind/x"), | |
177 create("dir/x.a"), | |
178 create("dir-b/x.a"), | |
179 create("a/dir-b/x.b"), | |
180 create("_ReSharper-1/file"), | |
181 }; | |
182 Path[] toIgnore = new Path[] { | |
183 // create("bin/x"), | |
184 // create("a/bin/x"), | |
185 // create("a/dir/c.a"), | |
186 // create("b/dir-c/d.a"), | |
187 create("src/_ReSharper-1/file/x"), | |
188 }; | |
189 doAssert(hgIgnore, toIgnore, toPass); | |
190 } | |
191 | |
192 private void doAssert(HgIgnore hgIgnore, Path[] toIgnore, Path[] toPass) { | |
193 if (toIgnore == null && toPass == null) { | |
194 throw new IllegalArgumentException(); | |
176 } | 195 } |
177 for (Path p : toPass) { | 196 if (toIgnore != null) { |
178 errorCollector.assertTrue("Shall pass " + p, !hgIgnore.isIgnored(p)); | 197 for (Path p : toIgnore) { |
198 errorCollector.assertTrue("Shall ignore " + p, hgIgnore.isIgnored(p)); | |
199 } | |
179 } | 200 } |
201 if (toPass != null) { | |
202 for (Path p : toPass) { | |
203 errorCollector.assertTrue("Shall pass " + p, !hgIgnore.isIgnored(p)); | |
204 } | |
205 } | |
180 } | 206 } |
181 } | 207 } |