Mercurial > hg4j
annotate test/org/tmatesoft/hg/test/TestIgnore.java @ 450:03fd8d079e9c smartgit3
Share PhasesHelper instance among few HgChangesets (mostly affects HgChangesetTreeHandler case)
author | Artem Tikhomirov <tikhomirov.artem@gmail.com> |
---|---|
date | Thu, 07 Jun 2012 17:06:23 +0200 |
parents | 0f5696623512 |
children | dca70c0b1f74 |
rev | line source |
---|---|
269
7af843ecc378
Respect glob pattern with alternatives {a,b}
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
1 /* |
408
e732521a9eb4
Issue 28: support hgignore entries with syntax prefix
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
348
diff
changeset
|
2 * Copyright (c) 2011-2012 TMate Software Ltd |
269
7af843ecc378
Respect glob pattern with alternatives {a,b}
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
3 * |
7af843ecc378
Respect glob pattern with alternatives {a,b}
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
4 * This program is free software; you can redistribute it and/or modify |
7af843ecc378
Respect glob pattern with alternatives {a,b}
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
5 * it under the terms of the GNU General Public License as published by |
7af843ecc378
Respect glob pattern with alternatives {a,b}
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
6 * the Free Software Foundation; version 2 of the License. |
7af843ecc378
Respect glob pattern with alternatives {a,b}
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
7 * |
7af843ecc378
Respect glob pattern with alternatives {a,b}
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
8 * This program is distributed in the hope that it will be useful, |
7af843ecc378
Respect glob pattern with alternatives {a,b}
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
7af843ecc378
Respect glob pattern with alternatives {a,b}
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
7af843ecc378
Respect glob pattern with alternatives {a,b}
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
11 * GNU General Public License for more details. |
7af843ecc378
Respect glob pattern with alternatives {a,b}
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
12 * |
7af843ecc378
Respect glob pattern with alternatives {a,b}
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
13 * For information on how to redistribute this software under |
7af843ecc378
Respect glob pattern with alternatives {a,b}
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
14 * the terms of a license other than GNU General Public License |
7af843ecc378
Respect glob pattern with alternatives {a,b}
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
15 * contact TMate Software at support@hg4j.com |
7af843ecc378
Respect glob pattern with alternatives {a,b}
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
16 */ |
7af843ecc378
Respect glob pattern with alternatives {a,b}
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
17 package org.tmatesoft.hg.test; |
7af843ecc378
Respect glob pattern with alternatives {a,b}
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
18 |
408
e732521a9eb4
Issue 28: support hgignore entries with syntax prefix
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
348
diff
changeset
|
19 import static org.tmatesoft.hg.util.Path.create; |
e732521a9eb4
Issue 28: support hgignore entries with syntax prefix
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
348
diff
changeset
|
20 |
269
7af843ecc378
Respect glob pattern with alternatives {a,b}
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
21 import java.io.BufferedReader; |
7af843ecc378
Respect glob pattern with alternatives {a,b}
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
22 import java.io.File; |
7af843ecc378
Respect glob pattern with alternatives {a,b}
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
23 import java.io.FileReader; |
7af843ecc378
Respect glob pattern with alternatives {a,b}
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
24 import java.io.StringReader; |
7af843ecc378
Respect glob pattern with alternatives {a,b}
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
25 |
7af843ecc378
Respect glob pattern with alternatives {a,b}
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
26 import org.junit.Rule; |
7af843ecc378
Respect glob pattern with alternatives {a,b}
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
27 import org.junit.Test; |
409
0f5696623512
Support glob path pattern rewrite to facilitate use of globs with Windows path separator
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
408
diff
changeset
|
28 import org.tmatesoft.hg.internal.WinToNixPathRewrite; |
269
7af843ecc378
Respect glob pattern with alternatives {a,b}
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
29 import org.tmatesoft.hg.repo.HgIgnore; |
7af843ecc378
Respect glob pattern with alternatives {a,b}
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
30 import org.tmatesoft.hg.repo.HgInternals; |
7af843ecc378
Respect glob pattern with alternatives {a,b}
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
31 import org.tmatesoft.hg.util.Path; |
7af843ecc378
Respect glob pattern with alternatives {a,b}
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
32 |
7af843ecc378
Respect glob pattern with alternatives {a,b}
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
33 /** |
7af843ecc378
Respect glob pattern with alternatives {a,b}
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
34 * |
7af843ecc378
Respect glob pattern with alternatives {a,b}
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
35 * @author Artem Tikhomirov |
7af843ecc378
Respect glob pattern with alternatives {a,b}
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
36 * @author TMate Software Ltd. |
7af843ecc378
Respect glob pattern with alternatives {a,b}
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
37 */ |
7af843ecc378
Respect glob pattern with alternatives {a,b}
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
38 public class TestIgnore { |
7af843ecc378
Respect glob pattern with alternatives {a,b}
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
39 |
7af843ecc378
Respect glob pattern with alternatives {a,b}
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
40 @Rule |
7af843ecc378
Respect glob pattern with alternatives {a,b}
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
41 public ErrorCollectorExt errorCollector = new ErrorCollectorExt(); |
7af843ecc378
Respect glob pattern with alternatives {a,b}
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
42 |
7af843ecc378
Respect glob pattern with alternatives {a,b}
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
43 public static void main(String[] args) throws Throwable { |
7af843ecc378
Respect glob pattern with alternatives {a,b}
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
44 TestIgnore test = new TestIgnore(); |
7af843ecc378
Respect glob pattern with alternatives {a,b}
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
45 test.testGlobWithAlternatives(); |
7af843ecc378
Respect glob pattern with alternatives {a,b}
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
46 test.testComplexFileParse(); |
342
516b817415ba
HgIgnore: regex patterns to match part of the filename do not work
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
339
diff
changeset
|
47 test.testSegmentsGlobMatch(); |
339
863356c2847e
Issue 16: respect glob patterns in HgIgnore for sub-directories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
269
diff
changeset
|
48 test.testWildcardsDoNotMatchDirectorySeparator(); |
269
7af843ecc378
Respect glob pattern with alternatives {a,b}
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
49 test.errorCollector.verify(); |
7af843ecc378
Respect glob pattern with alternatives {a,b}
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
50 } |
7af843ecc378
Respect glob pattern with alternatives {a,b}
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
51 |
7af843ecc378
Respect glob pattern with alternatives {a,b}
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
52 @Test |
7af843ecc378
Respect glob pattern with alternatives {a,b}
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
53 public void testGlobWithAlternatives() throws Exception { |
7af843ecc378
Respect glob pattern with alternatives {a,b}
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
54 String content = "syntax:glob\ndoc/*.[0-9].{x,ht}ml"; |
409
0f5696623512
Support glob path pattern rewrite to facilitate use of globs with Windows path separator
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
408
diff
changeset
|
55 HgIgnore hgIgnore = HgInternals.newHgIgnore(new StringReader(content), null); |
269
7af843ecc378
Respect glob pattern with alternatives {a,b}
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
56 final Path p1 = Path.create("doc/asd.2.xml"); |
7af843ecc378
Respect glob pattern with alternatives {a,b}
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
57 final Path p2 = Path.create("doc/zxc.6.html"); |
7af843ecc378
Respect glob pattern with alternatives {a,b}
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
58 errorCollector.assertTrue(p1.toString(), hgIgnore.isIgnored(p1)); |
7af843ecc378
Respect glob pattern with alternatives {a,b}
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
59 errorCollector.assertTrue(p2.toString(), hgIgnore.isIgnored(p2)); |
7af843ecc378
Respect glob pattern with alternatives {a,b}
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
60 } |
7af843ecc378
Respect glob pattern with alternatives {a,b}
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
61 |
7af843ecc378
Respect glob pattern with alternatives {a,b}
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
62 @Test |
7af843ecc378
Respect glob pattern with alternatives {a,b}
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
63 public void testComplexFileParse() throws Exception { |
7af843ecc378
Respect glob pattern with alternatives {a,b}
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
64 BufferedReader br = new BufferedReader(new FileReader(new File(Configuration.get().getTestDataDir(), "mercurial.hgignore"))); |
409
0f5696623512
Support glob path pattern rewrite to facilitate use of globs with Windows path separator
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
408
diff
changeset
|
65 HgIgnore hgIgnore = HgInternals.newHgIgnore(br, null); |
269
7af843ecc378
Respect glob pattern with alternatives {a,b}
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
66 br.close(); |
7af843ecc378
Respect glob pattern with alternatives {a,b}
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
67 Path[] toCheck = new Path[] { |
7af843ecc378
Respect glob pattern with alternatives {a,b}
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
68 Path.create("file.so"), |
7af843ecc378
Respect glob pattern with alternatives {a,b}
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
69 Path.create("a/b/file.so"), |
7af843ecc378
Respect glob pattern with alternatives {a,b}
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
70 Path.create("#abc#"), |
7af843ecc378
Respect glob pattern with alternatives {a,b}
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
71 Path.create(".#abc"), |
7af843ecc378
Respect glob pattern with alternatives {a,b}
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
72 Path.create("locale/en/LC_MESSAGES/hg.mo"), |
7af843ecc378
Respect glob pattern with alternatives {a,b}
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
73 }; |
409
0f5696623512
Support glob path pattern rewrite to facilitate use of globs with Windows path separator
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
408
diff
changeset
|
74 doAssert(hgIgnore, toCheck, null); |
269
7af843ecc378
Respect glob pattern with alternatives {a,b}
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
75 } |
7af843ecc378
Respect glob pattern with alternatives {a,b}
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
76 |
339
863356c2847e
Issue 16: respect glob patterns in HgIgnore for sub-directories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
269
diff
changeset
|
77 @Test |
342
516b817415ba
HgIgnore: regex patterns to match part of the filename do not work
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
339
diff
changeset
|
78 public void testSegmentsGlobMatch() throws Exception { |
339
863356c2847e
Issue 16: respect glob patterns in HgIgnore for sub-directories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
269
diff
changeset
|
79 String s = "syntax:glob\nbin\n.*\nTEST-*.xml"; |
409
0f5696623512
Support glob path pattern rewrite to facilitate use of globs with Windows path separator
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
408
diff
changeset
|
80 HgIgnore hgIgnore = HgInternals.newHgIgnore(new StringReader(s), null); |
339
863356c2847e
Issue 16: respect glob patterns in HgIgnore for sub-directories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
269
diff
changeset
|
81 Path[] toCheck = new Path[] { |
863356c2847e
Issue 16: respect glob patterns in HgIgnore for sub-directories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
269
diff
changeset
|
82 Path.create("bin/org/sample/First.class"), |
863356c2847e
Issue 16: respect glob patterns in HgIgnore for sub-directories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
269
diff
changeset
|
83 Path.create(".ignored-file"), |
863356c2847e
Issue 16: respect glob patterns in HgIgnore for sub-directories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
269
diff
changeset
|
84 Path.create("dir/.ignored-file"), |
863356c2847e
Issue 16: respect glob patterns in HgIgnore for sub-directories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
269
diff
changeset
|
85 Path.create("dir/.ignored-dir/file"), |
863356c2847e
Issue 16: respect glob patterns in HgIgnore for sub-directories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
269
diff
changeset
|
86 Path.create("TEST-a.xml"), |
863356c2847e
Issue 16: respect glob patterns in HgIgnore for sub-directories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
269
diff
changeset
|
87 Path.create("dir/TEST-b.xml"), |
863356c2847e
Issue 16: respect glob patterns in HgIgnore for sub-directories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
269
diff
changeset
|
88 }; |
409
0f5696623512
Support glob path pattern rewrite to facilitate use of globs with Windows path separator
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
408
diff
changeset
|
89 doAssert(hgIgnore, toCheck, null); |
0f5696623512
Support glob path pattern rewrite to facilitate use of globs with Windows path separator
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
408
diff
changeset
|
90 // |
343
58016b1b8554
HgIgnore: glob patterns not to match substring when not meant to
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
342
diff
changeset
|
91 s = "syntax:glob\n.git"; |
409
0f5696623512
Support glob path pattern rewrite to facilitate use of globs with Windows path separator
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
408
diff
changeset
|
92 hgIgnore = HgInternals.newHgIgnore(new StringReader(s), null); |
343
58016b1b8554
HgIgnore: glob patterns not to match substring when not meant to
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
342
diff
changeset
|
93 Path p = Path.create(".git/aa"); |
58016b1b8554
HgIgnore: glob patterns not to match substring when not meant to
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
342
diff
changeset
|
94 errorCollector.assertTrue(p.toString(), hgIgnore.isIgnored(p)); |
58016b1b8554
HgIgnore: glob patterns not to match substring when not meant to
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
342
diff
changeset
|
95 p = Path.create("dir/.git/bb"); |
58016b1b8554
HgIgnore: glob patterns not to match substring when not meant to
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
342
diff
changeset
|
96 errorCollector.assertTrue(p.toString(), hgIgnore.isIgnored(p)); |
58016b1b8554
HgIgnore: glob patterns not to match substring when not meant to
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
342
diff
changeset
|
97 p = Path.create("dir/.gittt/cc"); |
58016b1b8554
HgIgnore: glob patterns not to match substring when not meant to
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
342
diff
changeset
|
98 errorCollector.assertTrue(p.toString(), !hgIgnore.isIgnored(p)); |
339
863356c2847e
Issue 16: respect glob patterns in HgIgnore for sub-directories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
269
diff
changeset
|
99 } |
342
516b817415ba
HgIgnore: regex patterns to match part of the filename do not work
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
339
diff
changeset
|
100 |
516b817415ba
HgIgnore: regex patterns to match part of the filename do not work
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
339
diff
changeset
|
101 @Test |
516b817415ba
HgIgnore: regex patterns to match part of the filename do not work
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
339
diff
changeset
|
102 public void testSegmentsRegexMatch() throws Exception { |
516b817415ba
HgIgnore: regex patterns to match part of the filename do not work
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
339
diff
changeset
|
103 // regex patterns that don't start with explicit ^ are allowed to match anywhere in the string |
348
a0864b2892cd
Expose errors reading mercurial control files with exception
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
343
diff
changeset
|
104 String s = "syntax:regexp\n/\\.git\n^abc\n"; |
409
0f5696623512
Support glob path pattern rewrite to facilitate use of globs with Windows path separator
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
408
diff
changeset
|
105 HgIgnore hgIgnore = HgInternals.newHgIgnore(new StringReader(s), null); |
342
516b817415ba
HgIgnore: regex patterns to match part of the filename do not work
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
339
diff
changeset
|
106 Path p = Path.create(".git/aa"); |
516b817415ba
HgIgnore: regex patterns to match part of the filename do not work
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
339
diff
changeset
|
107 errorCollector.assertTrue(p.toString(), !hgIgnore.isIgnored(p)); |
516b817415ba
HgIgnore: regex patterns to match part of the filename do not work
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
339
diff
changeset
|
108 p = Path.create("dir/.git/bb"); |
516b817415ba
HgIgnore: regex patterns to match part of the filename do not work
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
339
diff
changeset
|
109 errorCollector.assertTrue(p.toString(), hgIgnore.isIgnored(p)); |
516b817415ba
HgIgnore: regex patterns to match part of the filename do not work
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
339
diff
changeset
|
110 p = Path.create("dir/abc/aa"); |
516b817415ba
HgIgnore: regex patterns to match part of the filename do not work
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
339
diff
changeset
|
111 errorCollector.assertTrue(p.toString(), !hgIgnore.isIgnored(p)); |
516b817415ba
HgIgnore: regex patterns to match part of the filename do not work
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
339
diff
changeset
|
112 p = Path.create("abc/bb"); |
516b817415ba
HgIgnore: regex patterns to match part of the filename do not work
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
339
diff
changeset
|
113 errorCollector.assertTrue(p.toString(), hgIgnore.isIgnored(p)); |
516b817415ba
HgIgnore: regex patterns to match part of the filename do not work
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
339
diff
changeset
|
114 // Mercurial (in fact, likely pyton's regex match() function) treats |
516b817415ba
HgIgnore: regex patterns to match part of the filename do not work
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
339
diff
changeset
|
115 // regex patterns as having .* at the end (unless there's explicit $). |
516b817415ba
HgIgnore: regex patterns to match part of the filename do not work
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
339
diff
changeset
|
116 // IOW, matches to the beginning of the string, not to the whole string |
516b817415ba
HgIgnore: regex patterns to match part of the filename do not work
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
339
diff
changeset
|
117 p = Path.create("abcde/fg"); |
516b817415ba
HgIgnore: regex patterns to match part of the filename do not work
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
339
diff
changeset
|
118 errorCollector.assertTrue(p.toString(), hgIgnore.isIgnored(p)); |
516b817415ba
HgIgnore: regex patterns to match part of the filename do not work
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
339
diff
changeset
|
119 } |
516b817415ba
HgIgnore: regex patterns to match part of the filename do not work
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
339
diff
changeset
|
120 |
339
863356c2847e
Issue 16: respect glob patterns in HgIgnore for sub-directories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
269
diff
changeset
|
121 @Test |
863356c2847e
Issue 16: respect glob patterns in HgIgnore for sub-directories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
269
diff
changeset
|
122 public void testWildcardsDoNotMatchDirectorySeparator() throws Exception { |
863356c2847e
Issue 16: respect glob patterns in HgIgnore for sub-directories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
269
diff
changeset
|
123 String s = "syntax:glob\na?b\nc*d"; |
409
0f5696623512
Support glob path pattern rewrite to facilitate use of globs with Windows path separator
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
408
diff
changeset
|
124 HgIgnore hgIgnore = HgInternals.newHgIgnore(new StringReader(s), null); |
339
863356c2847e
Issue 16: respect glob patterns in HgIgnore for sub-directories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
269
diff
changeset
|
125 // shall not be ignored |
863356c2847e
Issue 16: respect glob patterns in HgIgnore for sub-directories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
269
diff
changeset
|
126 Path[] toPass = new Path[] { |
863356c2847e
Issue 16: respect glob patterns in HgIgnore for sub-directories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
269
diff
changeset
|
127 Path.create("a/b"), |
863356c2847e
Issue 16: respect glob patterns in HgIgnore for sub-directories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
269
diff
changeset
|
128 Path.create("a/b/x"), |
863356c2847e
Issue 16: respect glob patterns in HgIgnore for sub-directories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
269
diff
changeset
|
129 Path.create("x/a/b"), |
863356c2847e
Issue 16: respect glob patterns in HgIgnore for sub-directories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
269
diff
changeset
|
130 Path.create("axyb"), |
863356c2847e
Issue 16: respect glob patterns in HgIgnore for sub-directories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
269
diff
changeset
|
131 Path.create("c/d"), |
863356c2847e
Issue 16: respect glob patterns in HgIgnore for sub-directories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
269
diff
changeset
|
132 Path.create("c/d/x"), |
863356c2847e
Issue 16: respect glob patterns in HgIgnore for sub-directories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
269
diff
changeset
|
133 Path.create("x/c/d"), |
863356c2847e
Issue 16: respect glob patterns in HgIgnore for sub-directories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
269
diff
changeset
|
134 }; |
863356c2847e
Issue 16: respect glob patterns in HgIgnore for sub-directories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
269
diff
changeset
|
135 // shall be ignored |
863356c2847e
Issue 16: respect glob patterns in HgIgnore for sub-directories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
269
diff
changeset
|
136 Path[] toIgnore = new Path[] { |
863356c2847e
Issue 16: respect glob patterns in HgIgnore for sub-directories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
269
diff
changeset
|
137 Path.create("axb"), |
863356c2847e
Issue 16: respect glob patterns in HgIgnore for sub-directories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
269
diff
changeset
|
138 Path.create("a3b"), |
863356c2847e
Issue 16: respect glob patterns in HgIgnore for sub-directories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
269
diff
changeset
|
139 Path.create("a_b"), |
863356c2847e
Issue 16: respect glob patterns in HgIgnore for sub-directories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
269
diff
changeset
|
140 Path.create("cd"), |
863356c2847e
Issue 16: respect glob patterns in HgIgnore for sub-directories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
269
diff
changeset
|
141 Path.create("cxd"), |
863356c2847e
Issue 16: respect glob patterns in HgIgnore for sub-directories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
269
diff
changeset
|
142 Path.create("cxyd"), |
863356c2847e
Issue 16: respect glob patterns in HgIgnore for sub-directories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
269
diff
changeset
|
143 Path.create("x/cd"), |
863356c2847e
Issue 16: respect glob patterns in HgIgnore for sub-directories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
269
diff
changeset
|
144 Path.create("x/cxyd"), |
863356c2847e
Issue 16: respect glob patterns in HgIgnore for sub-directories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
269
diff
changeset
|
145 Path.create("cd/x"), |
863356c2847e
Issue 16: respect glob patterns in HgIgnore for sub-directories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
269
diff
changeset
|
146 Path.create("cxyd/x"), |
863356c2847e
Issue 16: respect glob patterns in HgIgnore for sub-directories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
269
diff
changeset
|
147 }; |
409
0f5696623512
Support glob path pattern rewrite to facilitate use of globs with Windows path separator
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
408
diff
changeset
|
148 doAssert(hgIgnore, toIgnore, toPass); |
339
863356c2847e
Issue 16: respect glob patterns in HgIgnore for sub-directories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
269
diff
changeset
|
149 } |
408
e732521a9eb4
Issue 28: support hgignore entries with syntax prefix
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
348
diff
changeset
|
150 |
e732521a9eb4
Issue 28: support hgignore entries with syntax prefix
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
348
diff
changeset
|
151 @Test |
e732521a9eb4
Issue 28: support hgignore entries with syntax prefix
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
348
diff
changeset
|
152 public void testSyntaxPrefixAtLine() throws Exception { |
e732521a9eb4
Issue 28: support hgignore entries with syntax prefix
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
348
diff
changeset
|
153 String s = "glob:*.c\nregexp:.*\\.d"; |
409
0f5696623512
Support glob path pattern rewrite to facilitate use of globs with Windows path separator
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
408
diff
changeset
|
154 HgIgnore hgIgnore = HgInternals.newHgIgnore(new StringReader(s), null); |
408
e732521a9eb4
Issue 28: support hgignore entries with syntax prefix
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
348
diff
changeset
|
155 Path[] toPass = new Path[] { |
e732521a9eb4
Issue 28: support hgignore entries with syntax prefix
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
348
diff
changeset
|
156 create("a/c"), |
e732521a9eb4
Issue 28: support hgignore entries with syntax prefix
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
348
diff
changeset
|
157 create("a/d"), |
e732521a9eb4
Issue 28: support hgignore entries with syntax prefix
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
348
diff
changeset
|
158 create("a/d.a"), |
e732521a9eb4
Issue 28: support hgignore entries with syntax prefix
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
348
diff
changeset
|
159 create("a/d.e"), |
e732521a9eb4
Issue 28: support hgignore entries with syntax prefix
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
348
diff
changeset
|
160 }; |
e732521a9eb4
Issue 28: support hgignore entries with syntax prefix
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
348
diff
changeset
|
161 Path[] toIgnore = new Path[] { |
e732521a9eb4
Issue 28: support hgignore entries with syntax prefix
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
348
diff
changeset
|
162 create("a.c"), |
e732521a9eb4
Issue 28: support hgignore entries with syntax prefix
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
348
diff
changeset
|
163 create("a.d"), |
e732521a9eb4
Issue 28: support hgignore entries with syntax prefix
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
348
diff
changeset
|
164 create("src/a.c"), |
e732521a9eb4
Issue 28: support hgignore entries with syntax prefix
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
348
diff
changeset
|
165 create("src/a.d"), |
e732521a9eb4
Issue 28: support hgignore entries with syntax prefix
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
348
diff
changeset
|
166 }; |
409
0f5696623512
Support glob path pattern rewrite to facilitate use of globs with Windows path separator
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
408
diff
changeset
|
167 doAssert(hgIgnore, toIgnore, toPass); |
0f5696623512
Support glob path pattern rewrite to facilitate use of globs with Windows path separator
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
408
diff
changeset
|
168 } |
0f5696623512
Support glob path pattern rewrite to facilitate use of globs with Windows path separator
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
408
diff
changeset
|
169 |
0f5696623512
Support glob path pattern rewrite to facilitate use of globs with Windows path separator
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
408
diff
changeset
|
170 @Test |
0f5696623512
Support glob path pattern rewrite to facilitate use of globs with Windows path separator
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
408
diff
changeset
|
171 public void testGlobWithWindowsPathSeparators() throws Exception { |
0f5696623512
Support glob path pattern rewrite to facilitate use of globs with Windows path separator
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
408
diff
changeset
|
172 String s = "syntax:glob\n" + "bin\\*\n" + "*\\dir*\\*.a\n" + "*\\_ReSharper*\\\n"; |
0f5696623512
Support glob path pattern rewrite to facilitate use of globs with Windows path separator
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
408
diff
changeset
|
173 // explicit PathRewrite for the test to run on *nix as well |
0f5696623512
Support glob path pattern rewrite to facilitate use of globs with Windows path separator
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
408
diff
changeset
|
174 HgIgnore hgIgnore = HgInternals.newHgIgnore(new StringReader(s), new WinToNixPathRewrite()); |
0f5696623512
Support glob path pattern rewrite to facilitate use of globs with Windows path separator
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
408
diff
changeset
|
175 Path[] toPass = new Path[] { |
0f5696623512
Support glob path pattern rewrite to facilitate use of globs with Windows path separator
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
408
diff
changeset
|
176 create("bind/x"), |
0f5696623512
Support glob path pattern rewrite to facilitate use of globs with Windows path separator
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
408
diff
changeset
|
177 create("dir/x.a"), |
0f5696623512
Support glob path pattern rewrite to facilitate use of globs with Windows path separator
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
408
diff
changeset
|
178 create("dir-b/x.a"), |
0f5696623512
Support glob path pattern rewrite to facilitate use of globs with Windows path separator
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
408
diff
changeset
|
179 create("a/dir-b/x.b"), |
0f5696623512
Support glob path pattern rewrite to facilitate use of globs with Windows path separator
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
408
diff
changeset
|
180 create("_ReSharper-1/file"), |
0f5696623512
Support glob path pattern rewrite to facilitate use of globs with Windows path separator
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
408
diff
changeset
|
181 }; |
0f5696623512
Support glob path pattern rewrite to facilitate use of globs with Windows path separator
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
408
diff
changeset
|
182 Path[] toIgnore = new Path[] { |
0f5696623512
Support glob path pattern rewrite to facilitate use of globs with Windows path separator
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
408
diff
changeset
|
183 // create("bin/x"), |
0f5696623512
Support glob path pattern rewrite to facilitate use of globs with Windows path separator
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
408
diff
changeset
|
184 // create("a/bin/x"), |
0f5696623512
Support glob path pattern rewrite to facilitate use of globs with Windows path separator
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
408
diff
changeset
|
185 // create("a/dir/c.a"), |
0f5696623512
Support glob path pattern rewrite to facilitate use of globs with Windows path separator
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
408
diff
changeset
|
186 // create("b/dir-c/d.a"), |
0f5696623512
Support glob path pattern rewrite to facilitate use of globs with Windows path separator
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
408
diff
changeset
|
187 create("src/_ReSharper-1/file/x"), |
0f5696623512
Support glob path pattern rewrite to facilitate use of globs with Windows path separator
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
408
diff
changeset
|
188 }; |
0f5696623512
Support glob path pattern rewrite to facilitate use of globs with Windows path separator
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
408
diff
changeset
|
189 doAssert(hgIgnore, toIgnore, toPass); |
0f5696623512
Support glob path pattern rewrite to facilitate use of globs with Windows path separator
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
408
diff
changeset
|
190 } |
0f5696623512
Support glob path pattern rewrite to facilitate use of globs with Windows path separator
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
408
diff
changeset
|
191 |
0f5696623512
Support glob path pattern rewrite to facilitate use of globs with Windows path separator
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
408
diff
changeset
|
192 private void doAssert(HgIgnore hgIgnore, Path[] toIgnore, Path[] toPass) { |
0f5696623512
Support glob path pattern rewrite to facilitate use of globs with Windows path separator
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
408
diff
changeset
|
193 if (toIgnore == null && toPass == null) { |
0f5696623512
Support glob path pattern rewrite to facilitate use of globs with Windows path separator
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
408
diff
changeset
|
194 throw new IllegalArgumentException(); |
408
e732521a9eb4
Issue 28: support hgignore entries with syntax prefix
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
348
diff
changeset
|
195 } |
409
0f5696623512
Support glob path pattern rewrite to facilitate use of globs with Windows path separator
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
408
diff
changeset
|
196 if (toIgnore != null) { |
0f5696623512
Support glob path pattern rewrite to facilitate use of globs with Windows path separator
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
408
diff
changeset
|
197 for (Path p : toIgnore) { |
0f5696623512
Support glob path pattern rewrite to facilitate use of globs with Windows path separator
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
408
diff
changeset
|
198 errorCollector.assertTrue("Shall ignore " + p, hgIgnore.isIgnored(p)); |
0f5696623512
Support glob path pattern rewrite to facilitate use of globs with Windows path separator
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
408
diff
changeset
|
199 } |
0f5696623512
Support glob path pattern rewrite to facilitate use of globs with Windows path separator
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
408
diff
changeset
|
200 } |
0f5696623512
Support glob path pattern rewrite to facilitate use of globs with Windows path separator
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
408
diff
changeset
|
201 if (toPass != null) { |
0f5696623512
Support glob path pattern rewrite to facilitate use of globs with Windows path separator
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
408
diff
changeset
|
202 for (Path p : toPass) { |
0f5696623512
Support glob path pattern rewrite to facilitate use of globs with Windows path separator
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
408
diff
changeset
|
203 errorCollector.assertTrue("Shall pass " + p, !hgIgnore.isIgnored(p)); |
0f5696623512
Support glob path pattern rewrite to facilitate use of globs with Windows path separator
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
408
diff
changeset
|
204 } |
408
e732521a9eb4
Issue 28: support hgignore entries with syntax prefix
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
348
diff
changeset
|
205 } |
e732521a9eb4
Issue 28: support hgignore entries with syntax prefix
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
348
diff
changeset
|
206 } |
269
7af843ecc378
Respect glob pattern with alternatives {a,b}
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
207 } |