annotate test/org/tmatesoft/hg/test/TestIgnore.java @ 408:e732521a9eb4 smartgit3

Issue 28: support hgignore entries with syntax prefix
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Fri, 16 Mar 2012 15:06:44 +0100
parents a0864b2892cd
children 0f5696623512
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;
7af843ecc378 Respect glob pattern with alternatives {a,b}
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
28 import org.tmatesoft.hg.repo.HgIgnore;
7af843ecc378 Respect glob pattern with alternatives {a,b}
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
29 import org.tmatesoft.hg.repo.HgInternals;
7af843ecc378 Respect glob pattern with alternatives {a,b}
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
30 import org.tmatesoft.hg.util.Path;
7af843ecc378 Respect glob pattern with alternatives {a,b}
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
31
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 * @author Artem Tikhomirov
7af843ecc378 Respect glob pattern with alternatives {a,b}
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
35 * @author TMate Software Ltd.
7af843ecc378 Respect glob pattern with alternatives {a,b}
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
36 */
7af843ecc378 Respect glob pattern with alternatives {a,b}
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
37 public class TestIgnore {
7af843ecc378 Respect glob pattern with alternatives {a,b}
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
38
7af843ecc378 Respect glob pattern with alternatives {a,b}
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
39 @Rule
7af843ecc378 Respect glob pattern with alternatives {a,b}
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
40 public ErrorCollectorExt errorCollector = new ErrorCollectorExt();
7af843ecc378 Respect glob pattern with alternatives {a,b}
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
41
7af843ecc378 Respect glob pattern with alternatives {a,b}
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
42 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
43 TestIgnore test = new TestIgnore();
7af843ecc378 Respect glob pattern with alternatives {a,b}
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
44 test.testGlobWithAlternatives();
7af843ecc378 Respect glob pattern with alternatives {a,b}
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
45 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
46 test.testSegmentsGlobMatch();
339
863356c2847e Issue 16: respect glob patterns in HgIgnore for sub-directories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 269
diff changeset
47 test.testWildcardsDoNotMatchDirectorySeparator();
269
7af843ecc378 Respect glob pattern with alternatives {a,b}
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
48 test.errorCollector.verify();
7af843ecc378 Respect glob pattern with alternatives {a,b}
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
49 }
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 @Test
7af843ecc378 Respect glob pattern with alternatives {a,b}
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
52 public void testGlobWithAlternatives() throws Exception {
7af843ecc378 Respect glob pattern with alternatives {a,b}
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
53 String content = "syntax:glob\ndoc/*.[0-9].{x,ht}ml";
7af843ecc378 Respect glob pattern with alternatives {a,b}
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
54 HgIgnore hgIgnore = HgInternals.newHgIgnore(new StringReader(content));
7af843ecc378 Respect glob pattern with alternatives {a,b}
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
55 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
56 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
57 errorCollector.assertTrue(p1.toString(), hgIgnore.isIgnored(p1));
7af843ecc378 Respect glob pattern with alternatives {a,b}
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
58 errorCollector.assertTrue(p2.toString(), hgIgnore.isIgnored(p2));
7af843ecc378 Respect glob pattern with alternatives {a,b}
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
59 }
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 @Test
7af843ecc378 Respect glob pattern with alternatives {a,b}
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
62 public void testComplexFileParse() throws Exception {
7af843ecc378 Respect glob pattern with alternatives {a,b}
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
63 BufferedReader br = new BufferedReader(new FileReader(new File(Configuration.get().getTestDataDir(), "mercurial.hgignore")));
7af843ecc378 Respect glob pattern with alternatives {a,b}
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
64 HgIgnore hgIgnore = HgInternals.newHgIgnore(br);
7af843ecc378 Respect glob pattern with alternatives {a,b}
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
65 br.close();
7af843ecc378 Respect glob pattern with alternatives {a,b}
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
66 Path[] toCheck = new Path[] {
7af843ecc378 Respect glob pattern with alternatives {a,b}
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
67 Path.create("file.so"),
7af843ecc378 Respect glob pattern with alternatives {a,b}
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
68 Path.create("a/b/file.so"),
7af843ecc378 Respect glob pattern with alternatives {a,b}
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
69 Path.create("#abc#"),
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("locale/en/LC_MESSAGES/hg.mo"),
7af843ecc378 Respect glob pattern with alternatives {a,b}
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
72 };
7af843ecc378 Respect glob pattern with alternatives {a,b}
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
73 for (Path p : toCheck) {
7af843ecc378 Respect glob pattern with alternatives {a,b}
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
74 errorCollector.assertTrue(p.toString(), hgIgnore.isIgnored(p));
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 }
7af843ecc378 Respect glob pattern with alternatives {a,b}
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
77
339
863356c2847e Issue 16: respect glob patterns in HgIgnore for sub-directories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 269
diff changeset
78 @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
79 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
80 String s = "syntax:glob\nbin\n.*\nTEST-*.xml";
863356c2847e Issue 16: respect glob patterns in HgIgnore for sub-directories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 269
diff changeset
81 HgIgnore hgIgnore = HgInternals.newHgIgnore(new StringReader(s));
863356c2847e Issue 16: respect glob patterns in HgIgnore for sub-directories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 269
diff changeset
82 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
83 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
84 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
85 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
86 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
87 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
88 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
89 };
863356c2847e Issue 16: respect glob patterns in HgIgnore for sub-directories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 269
diff changeset
90 for (Path p : toCheck) {
863356c2847e Issue 16: respect glob patterns in HgIgnore for sub-directories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 269
diff changeset
91 errorCollector.assertTrue(p.toString(), hgIgnore.isIgnored(p));
863356c2847e Issue 16: respect glob patterns in HgIgnore for sub-directories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 269
diff changeset
92 }
343
58016b1b8554 HgIgnore: glob patterns not to match substring when not meant to
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 342
diff changeset
93 s = "syntax:glob\n.git";
58016b1b8554 HgIgnore: glob patterns not to match substring when not meant to
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 342
diff changeset
94 hgIgnore = HgInternals.newHgIgnore(new StringReader(s));
58016b1b8554 HgIgnore: glob patterns not to match substring when not meant to
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 342
diff changeset
95 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
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/.git/bb");
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));
58016b1b8554 HgIgnore: glob patterns not to match substring when not meant to
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 342
diff changeset
99 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
100 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
101 }
342
516b817415ba HgIgnore: regex patterns to match part of the filename do not work
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 339
diff changeset
102
516b817415ba HgIgnore: regex patterns to match part of the filename do not work
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 339
diff changeset
103 @Test
516b817415ba HgIgnore: regex patterns to match part of the filename do not work
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 339
diff changeset
104 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
105 // 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
106 String s = "syntax:regexp\n/\\.git\n^abc\n";
342
516b817415ba HgIgnore: regex patterns to match part of the filename do not work
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 339
diff changeset
107 HgIgnore hgIgnore = HgInternals.newHgIgnore(new StringReader(s));
516b817415ba HgIgnore: regex patterns to match part of the filename do not work
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 339
diff changeset
108 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
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/.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
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("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
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 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
115 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
116 // 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
117 // 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
118 // 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
119 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
120 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
121 }
516b817415ba HgIgnore: regex patterns to match part of the filename do not work
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 339
diff changeset
122
339
863356c2847e Issue 16: respect glob patterns in HgIgnore for sub-directories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 269
diff changeset
123 @Test
863356c2847e Issue 16: respect glob patterns in HgIgnore for sub-directories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 269
diff changeset
124 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
125 String s = "syntax:glob\na?b\nc*d";
863356c2847e Issue 16: respect glob patterns in HgIgnore for sub-directories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 269
diff changeset
126 HgIgnore hgIgnore = HgInternals.newHgIgnore(new StringReader(s));
863356c2847e Issue 16: respect glob patterns in HgIgnore for sub-directories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 269
diff changeset
127 // 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
128 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
129 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
130 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
131 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
132 Path.create("axyb"),
863356c2847e Issue 16: respect glob patterns in HgIgnore for sub-directories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 269
diff changeset
133 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
134 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
135 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
136 };
863356c2847e Issue 16: respect glob patterns in HgIgnore for sub-directories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 269
diff changeset
137 // shall be ignored
863356c2847e Issue 16: respect glob patterns in HgIgnore for sub-directories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 269
diff changeset
138 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
139 Path.create("axb"),
863356c2847e Issue 16: respect glob patterns in HgIgnore for sub-directories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 269
diff changeset
140 Path.create("a3b"),
863356c2847e Issue 16: respect glob patterns in HgIgnore for sub-directories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 269
diff changeset
141 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
142 Path.create("cd"),
863356c2847e Issue 16: respect glob patterns in HgIgnore for sub-directories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 269
diff changeset
143 Path.create("cxd"),
863356c2847e Issue 16: respect glob patterns in HgIgnore for sub-directories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 269
diff changeset
144 Path.create("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("x/cd"),
863356c2847e Issue 16: respect glob patterns in HgIgnore for sub-directories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 269
diff changeset
146 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
147 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
148 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
149 };
863356c2847e Issue 16: respect glob patterns in HgIgnore for sub-directories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 269
diff changeset
150 for (Path p : toIgnore) {
863356c2847e Issue 16: respect glob patterns in HgIgnore for sub-directories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 269
diff changeset
151 errorCollector.assertTrue(p.toString(), hgIgnore.isIgnored(p));
863356c2847e Issue 16: respect glob patterns in HgIgnore for sub-directories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 269
diff changeset
152 }
863356c2847e Issue 16: respect glob patterns in HgIgnore for sub-directories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 269
diff changeset
153 for (Path p : toPass) {
863356c2847e Issue 16: respect glob patterns in HgIgnore for sub-directories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 269
diff changeset
154 errorCollector.assertTrue(p.toString(), !hgIgnore.isIgnored(p));
863356c2847e Issue 16: respect glob patterns in HgIgnore for sub-directories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 269
diff changeset
155 }
863356c2847e Issue 16: respect glob patterns in HgIgnore for sub-directories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 269
diff changeset
156 }
408
e732521a9eb4 Issue 28: support hgignore entries with syntax prefix
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 348
diff changeset
157
e732521a9eb4 Issue 28: support hgignore entries with syntax prefix
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 348
diff changeset
158 @Test
e732521a9eb4 Issue 28: support hgignore entries with syntax prefix
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 348
diff changeset
159 public void testSyntaxPrefixAtLine() throws Exception {
e732521a9eb4 Issue 28: support hgignore entries with syntax prefix
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 348
diff changeset
160 String s = "glob:*.c\nregexp:.*\\.d";
e732521a9eb4 Issue 28: support hgignore entries with syntax prefix
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 348
diff changeset
161 HgIgnore hgIgnore = HgInternals.newHgIgnore(new StringReader(s));
e732521a9eb4 Issue 28: support hgignore entries with syntax prefix
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 348
diff changeset
162 Path[] toPass = new Path[] {
e732521a9eb4 Issue 28: support hgignore entries with syntax prefix
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 348
diff changeset
163 create("a/c"),
e732521a9eb4 Issue 28: support hgignore entries with syntax prefix
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 348
diff changeset
164 create("a/d"),
e732521a9eb4 Issue 28: support hgignore entries with syntax prefix
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 348
diff changeset
165 create("a/d.a"),
e732521a9eb4 Issue 28: support hgignore entries with syntax prefix
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 348
diff changeset
166 create("a/d.e"),
e732521a9eb4 Issue 28: support hgignore entries with syntax prefix
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 348
diff changeset
167 };
e732521a9eb4 Issue 28: support hgignore entries with syntax prefix
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 348
diff changeset
168 Path[] toIgnore = new Path[] {
e732521a9eb4 Issue 28: support hgignore entries with syntax prefix
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 348
diff changeset
169 create("a.c"),
e732521a9eb4 Issue 28: support hgignore entries with syntax prefix
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 348
diff changeset
170 create("a.d"),
e732521a9eb4 Issue 28: support hgignore entries with syntax prefix
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 348
diff changeset
171 create("src/a.c"),
e732521a9eb4 Issue 28: support hgignore entries with syntax prefix
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 348
diff changeset
172 create("src/a.d"),
e732521a9eb4 Issue 28: support hgignore entries with syntax prefix
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 348
diff changeset
173 };
e732521a9eb4 Issue 28: support hgignore entries with syntax prefix
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 348
diff changeset
174 for (Path p : toIgnore) {
e732521a9eb4 Issue 28: support hgignore entries with syntax prefix
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 348
diff changeset
175 errorCollector.assertTrue("Shall ignore " + p, hgIgnore.isIgnored(p));
e732521a9eb4 Issue 28: support hgignore entries with syntax prefix
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 348
diff changeset
176 }
e732521a9eb4 Issue 28: support hgignore entries with syntax prefix
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 348
diff changeset
177 for (Path p : toPass) {
e732521a9eb4 Issue 28: support hgignore entries with syntax prefix
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 348
diff changeset
178 errorCollector.assertTrue("Shall pass " + p, !hgIgnore.isIgnored(p));
e732521a9eb4 Issue 28: support hgignore entries with syntax prefix
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 348
diff changeset
179 }
e732521a9eb4 Issue 28: support hgignore entries with syntax prefix
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 348
diff changeset
180 }
269
7af843ecc378 Respect glob pattern with alternatives {a,b}
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
181 }