Show More
@@ -1,840 +1,840 b'' | |||||
1 | from __future__ import absolute_import |
|
1 | from __future__ import absolute_import | |
2 |
|
2 | |||
3 | import unittest |
|
3 | import unittest | |
4 |
|
4 | |||
5 | import silenttestrunner |
|
5 | import silenttestrunner | |
6 |
|
6 | |||
7 | from mercurial import ( |
|
7 | from mercurial import ( | |
8 | match as matchmod, |
|
8 | match as matchmod, | |
9 | util, |
|
9 | util, | |
10 | ) |
|
10 | ) | |
11 |
|
11 | |||
12 |
|
12 | |||
13 | class BaseMatcherTests(unittest.TestCase): |
|
13 | class BaseMatcherTests(unittest.TestCase): | |
14 | def testVisitdir(self): |
|
14 | def testVisitdir(self): | |
15 | m = matchmod.basematcher() |
|
15 | m = matchmod.basematcher() | |
16 | self.assertTrue(m.visitdir(b'')) |
|
16 | self.assertTrue(m.visitdir(b'')) | |
17 | self.assertTrue(m.visitdir(b'dir')) |
|
17 | self.assertTrue(m.visitdir(b'dir')) | |
18 |
|
18 | |||
19 | def testVisitchildrenset(self): |
|
19 | def testVisitchildrenset(self): | |
20 | m = matchmod.basematcher() |
|
20 | m = matchmod.basematcher() | |
21 | self.assertEqual(m.visitchildrenset(b''), b'this') |
|
21 | self.assertEqual(m.visitchildrenset(b''), b'this') | |
22 | self.assertEqual(m.visitchildrenset(b'dir'), b'this') |
|
22 | self.assertEqual(m.visitchildrenset(b'dir'), b'this') | |
23 |
|
23 | |||
24 |
|
24 | |||
25 | class AlwaysMatcherTests(unittest.TestCase): |
|
25 | class AlwaysMatcherTests(unittest.TestCase): | |
26 | def testVisitdir(self): |
|
26 | def testVisitdir(self): | |
27 | m = matchmod.alwaysmatcher() |
|
27 | m = matchmod.alwaysmatcher() | |
28 | self.assertEqual(m.visitdir(b''), b'all') |
|
28 | self.assertEqual(m.visitdir(b''), b'all') | |
29 | self.assertEqual(m.visitdir(b'dir'), b'all') |
|
29 | self.assertEqual(m.visitdir(b'dir'), b'all') | |
30 |
|
30 | |||
31 | def testVisitchildrenset(self): |
|
31 | def testVisitchildrenset(self): | |
32 | m = matchmod.alwaysmatcher() |
|
32 | m = matchmod.alwaysmatcher() | |
33 | self.assertEqual(m.visitchildrenset(b''), b'all') |
|
33 | self.assertEqual(m.visitchildrenset(b''), b'all') | |
34 | self.assertEqual(m.visitchildrenset(b'dir'), b'all') |
|
34 | self.assertEqual(m.visitchildrenset(b'dir'), b'all') | |
35 |
|
35 | |||
36 |
|
36 | |||
37 | class NeverMatcherTests(unittest.TestCase): |
|
37 | class NeverMatcherTests(unittest.TestCase): | |
38 | def testVisitdir(self): |
|
38 | def testVisitdir(self): | |
39 | m = matchmod.nevermatcher() |
|
39 | m = matchmod.nevermatcher() | |
40 | self.assertFalse(m.visitdir(b'')) |
|
40 | self.assertFalse(m.visitdir(b'')) | |
41 | self.assertFalse(m.visitdir(b'dir')) |
|
41 | self.assertFalse(m.visitdir(b'dir')) | |
42 |
|
42 | |||
43 | def testVisitchildrenset(self): |
|
43 | def testVisitchildrenset(self): | |
44 | m = matchmod.nevermatcher() |
|
44 | m = matchmod.nevermatcher() | |
45 | self.assertEqual(m.visitchildrenset(b''), set()) |
|
45 | self.assertEqual(m.visitchildrenset(b''), set()) | |
46 | self.assertEqual(m.visitchildrenset(b'dir'), set()) |
|
46 | self.assertEqual(m.visitchildrenset(b'dir'), set()) | |
47 |
|
47 | |||
48 |
|
48 | |||
49 | class PredicateMatcherTests(unittest.TestCase): |
|
49 | class PredicateMatcherTests(unittest.TestCase): | |
50 | # predicatematcher does not currently define either of these methods, so |
|
50 | # predicatematcher does not currently define either of these methods, so | |
51 | # this is equivalent to BaseMatcherTests. |
|
51 | # this is equivalent to BaseMatcherTests. | |
52 |
|
52 | |||
53 | def testVisitdir(self): |
|
53 | def testVisitdir(self): | |
54 | m = matchmod.predicatematcher(lambda *a: False) |
|
54 | m = matchmod.predicatematcher(lambda *a: False) | |
55 | self.assertTrue(m.visitdir(b'')) |
|
55 | self.assertTrue(m.visitdir(b'')) | |
56 | self.assertTrue(m.visitdir(b'dir')) |
|
56 | self.assertTrue(m.visitdir(b'dir')) | |
57 |
|
57 | |||
58 | def testVisitchildrenset(self): |
|
58 | def testVisitchildrenset(self): | |
59 | m = matchmod.predicatematcher(lambda *a: False) |
|
59 | m = matchmod.predicatematcher(lambda *a: False) | |
60 | self.assertEqual(m.visitchildrenset(b''), b'this') |
|
60 | self.assertEqual(m.visitchildrenset(b''), b'this') | |
61 | self.assertEqual(m.visitchildrenset(b'dir'), b'this') |
|
61 | self.assertEqual(m.visitchildrenset(b'dir'), b'this') | |
62 |
|
62 | |||
63 |
|
63 | |||
64 | class PatternMatcherTests(unittest.TestCase): |
|
64 | class PatternMatcherTests(unittest.TestCase): | |
65 | def testVisitdirPrefix(self): |
|
65 | def testVisitdirPrefix(self): | |
66 | m = matchmod.match(b'x', b'', patterns=[b'path:dir/subdir']) |
|
66 | m = matchmod.match(b'x', b'', patterns=[b'path:dir/subdir']) | |
67 | assert isinstance(m, matchmod.patternmatcher) |
|
67 | assert isinstance(m, matchmod.patternmatcher) | |
68 | self.assertTrue(m.visitdir(b'')) |
|
68 | self.assertTrue(m.visitdir(b'')) | |
69 | self.assertTrue(m.visitdir(b'dir')) |
|
69 | self.assertTrue(m.visitdir(b'dir')) | |
70 | self.assertEqual(m.visitdir(b'dir/subdir'), b'all') |
|
70 | self.assertEqual(m.visitdir(b'dir/subdir'), b'all') | |
71 | # OPT: This should probably be 'all' if its parent is? |
|
71 | # OPT: This should probably be 'all' if its parent is? | |
72 | self.assertTrue(m.visitdir(b'dir/subdir/x')) |
|
72 | self.assertTrue(m.visitdir(b'dir/subdir/x')) | |
73 | self.assertFalse(m.visitdir(b'folder')) |
|
73 | self.assertFalse(m.visitdir(b'folder')) | |
74 |
|
74 | |||
75 | def testVisitchildrensetPrefix(self): |
|
75 | def testVisitchildrensetPrefix(self): | |
76 | m = matchmod.match(b'x', b'', patterns=[b'path:dir/subdir']) |
|
76 | m = matchmod.match(b'x', b'', patterns=[b'path:dir/subdir']) | |
77 | assert isinstance(m, matchmod.patternmatcher) |
|
77 | assert isinstance(m, matchmod.patternmatcher) | |
78 | self.assertEqual(m.visitchildrenset(b''), b'this') |
|
78 | self.assertEqual(m.visitchildrenset(b''), b'this') | |
79 | self.assertEqual(m.visitchildrenset(b'dir'), b'this') |
|
79 | self.assertEqual(m.visitchildrenset(b'dir'), b'this') | |
80 | self.assertEqual(m.visitchildrenset(b'dir/subdir'), b'all') |
|
80 | self.assertEqual(m.visitchildrenset(b'dir/subdir'), b'all') | |
81 | # OPT: This should probably be 'all' if its parent is? |
|
81 | # OPT: This should probably be 'all' if its parent is? | |
82 | self.assertEqual(m.visitchildrenset(b'dir/subdir/x'), b'this') |
|
82 | self.assertEqual(m.visitchildrenset(b'dir/subdir/x'), b'this') | |
83 | self.assertEqual(m.visitchildrenset(b'folder'), set()) |
|
83 | self.assertEqual(m.visitchildrenset(b'folder'), set()) | |
84 |
|
84 | |||
85 | def testVisitdirRootfilesin(self): |
|
85 | def testVisitdirRootfilesin(self): | |
86 | m = matchmod.match(b'x', b'', patterns=[b'rootfilesin:dir/subdir']) |
|
86 | m = matchmod.match(b'x', b'', patterns=[b'rootfilesin:dir/subdir']) | |
87 | assert isinstance(m, matchmod.patternmatcher) |
|
87 | assert isinstance(m, matchmod.patternmatcher) | |
88 | self.assertFalse(m.visitdir(b'dir/subdir/x')) |
|
88 | self.assertFalse(m.visitdir(b'dir/subdir/x')) | |
89 | self.assertFalse(m.visitdir(b'folder')) |
|
89 | self.assertFalse(m.visitdir(b'folder')) | |
90 | # FIXME: These should probably be True. |
|
90 | # FIXME: These should probably be True. | |
91 | self.assertFalse(m.visitdir(b'')) |
|
91 | self.assertFalse(m.visitdir(b'')) | |
92 | self.assertFalse(m.visitdir(b'dir')) |
|
92 | self.assertFalse(m.visitdir(b'dir')) | |
93 | self.assertFalse(m.visitdir(b'dir/subdir')) |
|
93 | self.assertFalse(m.visitdir(b'dir/subdir')) | |
94 |
|
94 | |||
95 | def testVisitchildrensetRootfilesin(self): |
|
95 | def testVisitchildrensetRootfilesin(self): | |
96 | m = matchmod.match(b'x', b'', patterns=[b'rootfilesin:dir/subdir']) |
|
96 | m = matchmod.match(b'x', b'', patterns=[b'rootfilesin:dir/subdir']) | |
97 | assert isinstance(m, matchmod.patternmatcher) |
|
97 | assert isinstance(m, matchmod.patternmatcher) | |
98 | self.assertEqual(m.visitchildrenset(b'dir/subdir/x'), set()) |
|
98 | self.assertEqual(m.visitchildrenset(b'dir/subdir/x'), set()) | |
99 | self.assertEqual(m.visitchildrenset(b'folder'), set()) |
|
99 | self.assertEqual(m.visitchildrenset(b'folder'), set()) | |
100 | # FIXME: These should probably be {'dir'}, {'subdir'} and 'this', |
|
100 | # FIXME: These should probably be {'dir'}, {'subdir'} and 'this', | |
101 | # respectively, or at least 'this' for all three. |
|
101 | # respectively, or at least 'this' for all three. | |
102 | self.assertEqual(m.visitchildrenset(b''), set()) |
|
102 | self.assertEqual(m.visitchildrenset(b''), set()) | |
103 | self.assertEqual(m.visitchildrenset(b'dir'), set()) |
|
103 | self.assertEqual(m.visitchildrenset(b'dir'), set()) | |
104 | self.assertEqual(m.visitchildrenset(b'dir/subdir'), set()) |
|
104 | self.assertEqual(m.visitchildrenset(b'dir/subdir'), set()) | |
105 |
|
105 | |||
106 | def testVisitdirGlob(self): |
|
106 | def testVisitdirGlob(self): | |
107 | m = matchmod.match(b'x', b'', patterns=[b'glob:dir/z*']) |
|
107 | m = matchmod.match(b'x', b'', patterns=[b'glob:dir/z*']) | |
108 | assert isinstance(m, matchmod.patternmatcher) |
|
108 | assert isinstance(m, matchmod.patternmatcher) | |
109 | self.assertTrue(m.visitdir(b'')) |
|
109 | self.assertTrue(m.visitdir(b'')) | |
110 | self.assertTrue(m.visitdir(b'dir')) |
|
110 | self.assertTrue(m.visitdir(b'dir')) | |
111 | self.assertFalse(m.visitdir(b'folder')) |
|
111 | self.assertFalse(m.visitdir(b'folder')) | |
112 | # OPT: these should probably be False. |
|
112 | # OPT: these should probably be False. | |
113 | self.assertTrue(m.visitdir(b'dir/subdir')) |
|
113 | self.assertTrue(m.visitdir(b'dir/subdir')) | |
114 | self.assertTrue(m.visitdir(b'dir/subdir/x')) |
|
114 | self.assertTrue(m.visitdir(b'dir/subdir/x')) | |
115 |
|
115 | |||
116 | def testVisitchildrensetGlob(self): |
|
116 | def testVisitchildrensetGlob(self): | |
117 | m = matchmod.match(b'x', b'', patterns=[b'glob:dir/z*']) |
|
117 | m = matchmod.match(b'x', b'', patterns=[b'glob:dir/z*']) | |
118 | assert isinstance(m, matchmod.patternmatcher) |
|
118 | assert isinstance(m, matchmod.patternmatcher) | |
119 | self.assertEqual(m.visitchildrenset(b''), b'this') |
|
119 | self.assertEqual(m.visitchildrenset(b''), b'this') | |
120 | self.assertEqual(m.visitchildrenset(b'folder'), set()) |
|
120 | self.assertEqual(m.visitchildrenset(b'folder'), set()) | |
121 | self.assertEqual(m.visitchildrenset(b'dir'), b'this') |
|
121 | self.assertEqual(m.visitchildrenset(b'dir'), b'this') | |
122 | # OPT: these should probably be set(). |
|
122 | # OPT: these should probably be set(). | |
123 | self.assertEqual(m.visitchildrenset(b'dir/subdir'), b'this') |
|
123 | self.assertEqual(m.visitchildrenset(b'dir/subdir'), b'this') | |
124 | self.assertEqual(m.visitchildrenset(b'dir/subdir/x'), b'this') |
|
124 | self.assertEqual(m.visitchildrenset(b'dir/subdir/x'), b'this') | |
125 |
|
125 | |||
126 |
|
126 | |||
127 | class IncludeMatcherTests(unittest.TestCase): |
|
127 | class IncludeMatcherTests(unittest.TestCase): | |
128 | def testVisitdirPrefix(self): |
|
128 | def testVisitdirPrefix(self): | |
129 | m = matchmod.match(b'x', b'', include=[b'path:dir/subdir']) |
|
129 | m = matchmod.match(b'x', b'', include=[b'path:dir/subdir']) | |
130 | assert isinstance(m, matchmod.includematcher) |
|
130 | assert isinstance(m, matchmod.includematcher) | |
131 | self.assertTrue(m.visitdir(b'')) |
|
131 | self.assertTrue(m.visitdir(b'')) | |
132 | self.assertTrue(m.visitdir(b'dir')) |
|
132 | self.assertTrue(m.visitdir(b'dir')) | |
133 | self.assertEqual(m.visitdir(b'dir/subdir'), b'all') |
|
133 | self.assertEqual(m.visitdir(b'dir/subdir'), b'all') | |
134 | # OPT: This should probably be 'all' if its parent is? |
|
134 | # OPT: This should probably be 'all' if its parent is? | |
135 | self.assertTrue(m.visitdir(b'dir/subdir/x')) |
|
135 | self.assertTrue(m.visitdir(b'dir/subdir/x')) | |
136 | self.assertFalse(m.visitdir(b'folder')) |
|
136 | self.assertFalse(m.visitdir(b'folder')) | |
137 |
|
137 | |||
138 | def testVisitchildrensetPrefix(self): |
|
138 | def testVisitchildrensetPrefix(self): | |
139 | m = matchmod.match(b'x', b'', include=[b'path:dir/subdir']) |
|
139 | m = matchmod.match(b'x', b'', include=[b'path:dir/subdir']) | |
140 | assert isinstance(m, matchmod.includematcher) |
|
140 | assert isinstance(m, matchmod.includematcher) | |
141 | self.assertEqual(m.visitchildrenset(b''), {b'dir'}) |
|
141 | self.assertEqual(m.visitchildrenset(b''), {b'dir'}) | |
142 | self.assertEqual(m.visitchildrenset(b'dir'), {b'subdir'}) |
|
142 | self.assertEqual(m.visitchildrenset(b'dir'), {b'subdir'}) | |
143 | self.assertEqual(m.visitchildrenset(b'dir/subdir'), b'all') |
|
143 | self.assertEqual(m.visitchildrenset(b'dir/subdir'), b'all') | |
144 | # OPT: This should probably be 'all' if its parent is? |
|
144 | # OPT: This should probably be 'all' if its parent is? | |
145 | self.assertEqual(m.visitchildrenset(b'dir/subdir/x'), b'this') |
|
145 | self.assertEqual(m.visitchildrenset(b'dir/subdir/x'), b'this') | |
146 | self.assertEqual(m.visitchildrenset(b'folder'), set()) |
|
146 | self.assertEqual(m.visitchildrenset(b'folder'), set()) | |
147 |
|
147 | |||
148 | def testVisitdirRootfilesin(self): |
|
148 | def testVisitdirRootfilesin(self): | |
149 | m = matchmod.match(b'x', b'', include=[b'rootfilesin:dir/subdir']) |
|
149 | m = matchmod.match(b'x', b'', include=[b'rootfilesin:dir/subdir']) | |
150 | assert isinstance(m, matchmod.includematcher) |
|
150 | assert isinstance(m, matchmod.includematcher) | |
151 | self.assertTrue(m.visitdir(b'')) |
|
151 | self.assertTrue(m.visitdir(b'')) | |
152 | self.assertTrue(m.visitdir(b'dir')) |
|
152 | self.assertTrue(m.visitdir(b'dir')) | |
153 | self.assertTrue(m.visitdir(b'dir/subdir')) |
|
153 | self.assertTrue(m.visitdir(b'dir/subdir')) | |
154 | self.assertFalse(m.visitdir(b'dir/subdir/x')) |
|
154 | self.assertFalse(m.visitdir(b'dir/subdir/x')) | |
155 | self.assertFalse(m.visitdir(b'folder')) |
|
155 | self.assertFalse(m.visitdir(b'folder')) | |
156 |
|
156 | |||
157 | def testVisitchildrensetRootfilesin(self): |
|
157 | def testVisitchildrensetRootfilesin(self): | |
158 | m = matchmod.match(b'x', b'', include=[b'rootfilesin:dir/subdir']) |
|
158 | m = matchmod.match(b'x', b'', include=[b'rootfilesin:dir/subdir']) | |
159 | assert isinstance(m, matchmod.includematcher) |
|
159 | assert isinstance(m, matchmod.includematcher) | |
160 | self.assertEqual(m.visitchildrenset(b''), {b'dir'}) |
|
160 | self.assertEqual(m.visitchildrenset(b''), {b'dir'}) | |
161 | self.assertEqual(m.visitchildrenset(b'dir'), {b'subdir'}) |
|
161 | self.assertEqual(m.visitchildrenset(b'dir'), {b'subdir'}) | |
162 | self.assertEqual(m.visitchildrenset(b'dir/subdir'), b'this') |
|
162 | self.assertEqual(m.visitchildrenset(b'dir/subdir'), b'this') | |
163 | self.assertEqual(m.visitchildrenset(b'dir/subdir/x'), set()) |
|
163 | self.assertEqual(m.visitchildrenset(b'dir/subdir/x'), set()) | |
164 | self.assertEqual(m.visitchildrenset(b'folder'), set()) |
|
164 | self.assertEqual(m.visitchildrenset(b'folder'), set()) | |
165 |
|
165 | |||
166 | def testVisitdirGlob(self): |
|
166 | def testVisitdirGlob(self): | |
167 | m = matchmod.match(b'x', b'', include=[b'glob:dir/z*']) |
|
167 | m = matchmod.match(b'x', b'', include=[b'glob:dir/z*']) | |
168 | assert isinstance(m, matchmod.includematcher) |
|
168 | assert isinstance(m, matchmod.includematcher) | |
169 | self.assertTrue(m.visitdir(b'')) |
|
169 | self.assertTrue(m.visitdir(b'')) | |
170 | self.assertTrue(m.visitdir(b'dir')) |
|
170 | self.assertTrue(m.visitdir(b'dir')) | |
171 | self.assertFalse(m.visitdir(b'folder')) |
|
171 | self.assertFalse(m.visitdir(b'folder')) | |
172 | # OPT: these should probably be False. |
|
172 | # OPT: these should probably be False. | |
173 | self.assertTrue(m.visitdir(b'dir/subdir')) |
|
173 | self.assertTrue(m.visitdir(b'dir/subdir')) | |
174 | self.assertTrue(m.visitdir(b'dir/subdir/x')) |
|
174 | self.assertTrue(m.visitdir(b'dir/subdir/x')) | |
175 |
|
175 | |||
176 | def testVisitchildrensetGlob(self): |
|
176 | def testVisitchildrensetGlob(self): | |
177 | m = matchmod.match(b'x', b'', include=[b'glob:dir/z*']) |
|
177 | m = matchmod.match(b'x', b'', include=[b'glob:dir/z*']) | |
178 | assert isinstance(m, matchmod.includematcher) |
|
178 | assert isinstance(m, matchmod.includematcher) | |
179 | self.assertEqual(m.visitchildrenset(b''), {b'dir'}) |
|
179 | self.assertEqual(m.visitchildrenset(b''), {b'dir'}) | |
180 | self.assertEqual(m.visitchildrenset(b'folder'), set()) |
|
180 | self.assertEqual(m.visitchildrenset(b'folder'), set()) | |
181 | self.assertEqual(m.visitchildrenset(b'dir'), b'this') |
|
181 | self.assertEqual(m.visitchildrenset(b'dir'), b'this') | |
182 | # OPT: these should probably be set(). |
|
182 | # OPT: these should probably be set(). | |
183 | self.assertEqual(m.visitchildrenset(b'dir/subdir'), b'this') |
|
183 | self.assertEqual(m.visitchildrenset(b'dir/subdir'), b'this') | |
184 | self.assertEqual(m.visitchildrenset(b'dir/subdir/x'), b'this') |
|
184 | self.assertEqual(m.visitchildrenset(b'dir/subdir/x'), b'this') | |
185 |
|
185 | |||
186 |
|
186 | |||
187 | class ExactMatcherTests(unittest.TestCase): |
|
187 | class ExactMatcherTests(unittest.TestCase): | |
188 | def testVisitdir(self): |
|
188 | def testVisitdir(self): | |
189 | m = matchmod.exact(files=[b'dir/subdir/foo.txt']) |
|
189 | m = matchmod.exact(files=[b'dir/subdir/foo.txt']) | |
190 | assert isinstance(m, matchmod.exactmatcher) |
|
190 | assert isinstance(m, matchmod.exactmatcher) | |
191 | self.assertTrue(m.visitdir(b'')) |
|
191 | self.assertTrue(m.visitdir(b'')) | |
192 | self.assertTrue(m.visitdir(b'dir')) |
|
192 | self.assertTrue(m.visitdir(b'dir')) | |
193 | self.assertTrue(m.visitdir(b'dir/subdir')) |
|
193 | self.assertTrue(m.visitdir(b'dir/subdir')) | |
194 | self.assertFalse(m.visitdir(b'dir/subdir/foo.txt')) |
|
194 | self.assertFalse(m.visitdir(b'dir/subdir/foo.txt')) | |
195 | self.assertFalse(m.visitdir(b'dir/foo')) |
|
195 | self.assertFalse(m.visitdir(b'dir/foo')) | |
196 | self.assertFalse(m.visitdir(b'dir/subdir/x')) |
|
196 | self.assertFalse(m.visitdir(b'dir/subdir/x')) | |
197 | self.assertFalse(m.visitdir(b'folder')) |
|
197 | self.assertFalse(m.visitdir(b'folder')) | |
198 |
|
198 | |||
199 | def testVisitchildrenset(self): |
|
199 | def testVisitchildrenset(self): | |
200 | m = matchmod.exact(files=[b'dir/subdir/foo.txt']) |
|
200 | m = matchmod.exact(files=[b'dir/subdir/foo.txt']) | |
201 | assert isinstance(m, matchmod.exactmatcher) |
|
201 | assert isinstance(m, matchmod.exactmatcher) | |
202 | self.assertEqual(m.visitchildrenset(b''), {b'dir'}) |
|
202 | self.assertEqual(m.visitchildrenset(b''), {b'dir'}) | |
203 | self.assertEqual(m.visitchildrenset(b'dir'), {b'subdir'}) |
|
203 | self.assertEqual(m.visitchildrenset(b'dir'), {b'subdir'}) | |
204 | self.assertEqual(m.visitchildrenset(b'dir/subdir'), {b'foo.txt'}) |
|
204 | self.assertEqual(m.visitchildrenset(b'dir/subdir'), {b'foo.txt'}) | |
205 | self.assertEqual(m.visitchildrenset(b'dir/subdir/x'), set()) |
|
205 | self.assertEqual(m.visitchildrenset(b'dir/subdir/x'), set()) | |
206 | self.assertEqual(m.visitchildrenset(b'dir/subdir/foo.txt'), set()) |
|
206 | self.assertEqual(m.visitchildrenset(b'dir/subdir/foo.txt'), set()) | |
207 | self.assertEqual(m.visitchildrenset(b'folder'), set()) |
|
207 | self.assertEqual(m.visitchildrenset(b'folder'), set()) | |
208 |
|
208 | |||
209 | def testVisitchildrensetFilesAndDirs(self): |
|
209 | def testVisitchildrensetFilesAndDirs(self): | |
210 | m = matchmod.exact( |
|
210 | m = matchmod.exact( | |
211 | files=[ |
|
211 | files=[ | |
212 | b'rootfile.txt', |
|
212 | b'rootfile.txt', | |
213 | b'a/file1.txt', |
|
213 | b'a/file1.txt', | |
214 | b'a/b/file2.txt', |
|
214 | b'a/b/file2.txt', | |
215 | # no file in a/b/c |
|
215 | # no file in a/b/c | |
216 | b'a/b/c/d/file4.txt', |
|
216 | b'a/b/c/d/file4.txt', | |
217 | ] |
|
217 | ] | |
218 | ) |
|
218 | ) | |
219 | assert isinstance(m, matchmod.exactmatcher) |
|
219 | assert isinstance(m, matchmod.exactmatcher) | |
220 | self.assertEqual(m.visitchildrenset(b''), {b'a', b'rootfile.txt'}) |
|
220 | self.assertEqual(m.visitchildrenset(b''), {b'a', b'rootfile.txt'}) | |
221 | self.assertEqual(m.visitchildrenset(b'a'), {b'b', b'file1.txt'}) |
|
221 | self.assertEqual(m.visitchildrenset(b'a'), {b'b', b'file1.txt'}) | |
222 | self.assertEqual(m.visitchildrenset(b'a/b'), {b'c', b'file2.txt'}) |
|
222 | self.assertEqual(m.visitchildrenset(b'a/b'), {b'c', b'file2.txt'}) | |
223 | self.assertEqual(m.visitchildrenset(b'a/b/c'), {b'd'}) |
|
223 | self.assertEqual(m.visitchildrenset(b'a/b/c'), {b'd'}) | |
224 | self.assertEqual(m.visitchildrenset(b'a/b/c/d'), {b'file4.txt'}) |
|
224 | self.assertEqual(m.visitchildrenset(b'a/b/c/d'), {b'file4.txt'}) | |
225 | self.assertEqual(m.visitchildrenset(b'a/b/c/d/e'), set()) |
|
225 | self.assertEqual(m.visitchildrenset(b'a/b/c/d/e'), set()) | |
226 | self.assertEqual(m.visitchildrenset(b'folder'), set()) |
|
226 | self.assertEqual(m.visitchildrenset(b'folder'), set()) | |
227 |
|
227 | |||
228 |
|
228 | |||
229 | class DifferenceMatcherTests(unittest.TestCase): |
|
229 | class DifferenceMatcherTests(unittest.TestCase): | |
230 | def testVisitdirM2always(self): |
|
230 | def testVisitdirM2always(self): | |
231 | m1 = matchmod.alwaysmatcher() |
|
231 | m1 = matchmod.alwaysmatcher() | |
232 | m2 = matchmod.alwaysmatcher() |
|
232 | m2 = matchmod.alwaysmatcher() | |
233 | dm = matchmod.differencematcher(m1, m2) |
|
233 | dm = matchmod.differencematcher(m1, m2) | |
234 | # dm should be equivalent to a nevermatcher. |
|
234 | # dm should be equivalent to a nevermatcher. | |
235 | self.assertFalse(dm.visitdir(b'')) |
|
235 | self.assertFalse(dm.visitdir(b'')) | |
236 | self.assertFalse(dm.visitdir(b'dir')) |
|
236 | self.assertFalse(dm.visitdir(b'dir')) | |
237 | self.assertFalse(dm.visitdir(b'dir/subdir')) |
|
237 | self.assertFalse(dm.visitdir(b'dir/subdir')) | |
238 | self.assertFalse(dm.visitdir(b'dir/subdir/z')) |
|
238 | self.assertFalse(dm.visitdir(b'dir/subdir/z')) | |
239 | self.assertFalse(dm.visitdir(b'dir/foo')) |
|
239 | self.assertFalse(dm.visitdir(b'dir/foo')) | |
240 | self.assertFalse(dm.visitdir(b'dir/subdir/x')) |
|
240 | self.assertFalse(dm.visitdir(b'dir/subdir/x')) | |
241 | self.assertFalse(dm.visitdir(b'folder')) |
|
241 | self.assertFalse(dm.visitdir(b'folder')) | |
242 |
|
242 | |||
243 | def testVisitchildrensetM2always(self): |
|
243 | def testVisitchildrensetM2always(self): | |
244 | m1 = matchmod.alwaysmatcher() |
|
244 | m1 = matchmod.alwaysmatcher() | |
245 | m2 = matchmod.alwaysmatcher() |
|
245 | m2 = matchmod.alwaysmatcher() | |
246 | dm = matchmod.differencematcher(m1, m2) |
|
246 | dm = matchmod.differencematcher(m1, m2) | |
247 | # dm should be equivalent to a nevermatcher. |
|
247 | # dm should be equivalent to a nevermatcher. | |
248 | self.assertEqual(dm.visitchildrenset(b''), set()) |
|
248 | self.assertEqual(dm.visitchildrenset(b''), set()) | |
249 | self.assertEqual(dm.visitchildrenset(b'dir'), set()) |
|
249 | self.assertEqual(dm.visitchildrenset(b'dir'), set()) | |
250 | self.assertEqual(dm.visitchildrenset(b'dir/subdir'), set()) |
|
250 | self.assertEqual(dm.visitchildrenset(b'dir/subdir'), set()) | |
251 | self.assertEqual(dm.visitchildrenset(b'dir/subdir/z'), set()) |
|
251 | self.assertEqual(dm.visitchildrenset(b'dir/subdir/z'), set()) | |
252 | self.assertEqual(dm.visitchildrenset(b'dir/foo'), set()) |
|
252 | self.assertEqual(dm.visitchildrenset(b'dir/foo'), set()) | |
253 | self.assertEqual(dm.visitchildrenset(b'dir/subdir/x'), set()) |
|
253 | self.assertEqual(dm.visitchildrenset(b'dir/subdir/x'), set()) | |
254 | self.assertEqual(dm.visitchildrenset(b'folder'), set()) |
|
254 | self.assertEqual(dm.visitchildrenset(b'folder'), set()) | |
255 |
|
255 | |||
256 | def testVisitdirM2never(self): |
|
256 | def testVisitdirM2never(self): | |
257 | m1 = matchmod.alwaysmatcher() |
|
257 | m1 = matchmod.alwaysmatcher() | |
258 | m2 = matchmod.nevermatcher() |
|
258 | m2 = matchmod.nevermatcher() | |
259 | dm = matchmod.differencematcher(m1, m2) |
|
259 | dm = matchmod.differencematcher(m1, m2) | |
260 | # dm should be equivalent to a alwaysmatcher. |
|
260 | # dm should be equivalent to a alwaysmatcher. | |
261 | # |
|
261 | # | |
262 | # We're testing Equal-to-True instead of just 'assertTrue' since |
|
262 | # We're testing Equal-to-True instead of just 'assertTrue' since | |
263 | # assertTrue does NOT verify that it's a bool, just that it's truthy. |
|
263 | # assertTrue does NOT verify that it's a bool, just that it's truthy. | |
264 | # While we may want to eventually make these return 'all', they should |
|
264 | # While we may want to eventually make these return 'all', they should | |
265 | # not currently do so. |
|
265 | # not currently do so. | |
266 | self.assertEqual(dm.visitdir(b''), b'all') |
|
266 | self.assertEqual(dm.visitdir(b''), b'all') | |
267 | self.assertEqual(dm.visitdir(b'dir'), b'all') |
|
267 | self.assertEqual(dm.visitdir(b'dir'), b'all') | |
268 | self.assertEqual(dm.visitdir(b'dir/subdir'), b'all') |
|
268 | self.assertEqual(dm.visitdir(b'dir/subdir'), b'all') | |
269 | self.assertEqual(dm.visitdir(b'dir/subdir/z'), b'all') |
|
269 | self.assertEqual(dm.visitdir(b'dir/subdir/z'), b'all') | |
270 | self.assertEqual(dm.visitdir(b'dir/foo'), b'all') |
|
270 | self.assertEqual(dm.visitdir(b'dir/foo'), b'all') | |
271 | self.assertEqual(dm.visitdir(b'dir/subdir/x'), b'all') |
|
271 | self.assertEqual(dm.visitdir(b'dir/subdir/x'), b'all') | |
272 | self.assertEqual(dm.visitdir(b'folder'), b'all') |
|
272 | self.assertEqual(dm.visitdir(b'folder'), b'all') | |
273 |
|
273 | |||
274 | def testVisitchildrensetM2never(self): |
|
274 | def testVisitchildrensetM2never(self): | |
275 | m1 = matchmod.alwaysmatcher() |
|
275 | m1 = matchmod.alwaysmatcher() | |
276 | m2 = matchmod.nevermatcher() |
|
276 | m2 = matchmod.nevermatcher() | |
277 | dm = matchmod.differencematcher(m1, m2) |
|
277 | dm = matchmod.differencematcher(m1, m2) | |
278 | # dm should be equivalent to a alwaysmatcher. |
|
278 | # dm should be equivalent to a alwaysmatcher. | |
279 | self.assertEqual(dm.visitchildrenset(b''), b'all') |
|
279 | self.assertEqual(dm.visitchildrenset(b''), b'all') | |
280 | self.assertEqual(dm.visitchildrenset(b'dir'), b'all') |
|
280 | self.assertEqual(dm.visitchildrenset(b'dir'), b'all') | |
281 | self.assertEqual(dm.visitchildrenset(b'dir/subdir'), b'all') |
|
281 | self.assertEqual(dm.visitchildrenset(b'dir/subdir'), b'all') | |
282 | self.assertEqual(dm.visitchildrenset(b'dir/subdir/z'), b'all') |
|
282 | self.assertEqual(dm.visitchildrenset(b'dir/subdir/z'), b'all') | |
283 | self.assertEqual(dm.visitchildrenset(b'dir/foo'), b'all') |
|
283 | self.assertEqual(dm.visitchildrenset(b'dir/foo'), b'all') | |
284 | self.assertEqual(dm.visitchildrenset(b'dir/subdir/x'), b'all') |
|
284 | self.assertEqual(dm.visitchildrenset(b'dir/subdir/x'), b'all') | |
285 | self.assertEqual(dm.visitchildrenset(b'folder'), b'all') |
|
285 | self.assertEqual(dm.visitchildrenset(b'folder'), b'all') | |
286 |
|
286 | |||
287 | def testVisitdirM2SubdirPrefix(self): |
|
287 | def testVisitdirM2SubdirPrefix(self): | |
288 | m1 = matchmod.alwaysmatcher() |
|
288 | m1 = matchmod.alwaysmatcher() | |
289 | m2 = matchmod.match(b'', b'', patterns=[b'path:dir/subdir']) |
|
289 | m2 = matchmod.match(b'', b'', patterns=[b'path:dir/subdir']) | |
290 | dm = matchmod.differencematcher(m1, m2) |
|
290 | dm = matchmod.differencematcher(m1, m2) | |
291 | self.assertEqual(dm.visitdir(b''), True) |
|
291 | self.assertEqual(dm.visitdir(b''), True) | |
292 | self.assertEqual(dm.visitdir(b'dir'), True) |
|
292 | self.assertEqual(dm.visitdir(b'dir'), True) | |
293 | self.assertFalse(dm.visitdir(b'dir/subdir')) |
|
293 | self.assertFalse(dm.visitdir(b'dir/subdir')) | |
294 | # OPT: We should probably return False for these; we don't because |
|
294 | # OPT: We should probably return False for these; we don't because | |
295 | # patternmatcher.visitdir() (our m2) doesn't return 'all' for subdirs of |
|
295 | # patternmatcher.visitdir() (our m2) doesn't return 'all' for subdirs of | |
296 | # an 'all' pattern, just True. |
|
296 | # an 'all' pattern, just True. | |
297 | self.assertEqual(dm.visitdir(b'dir/subdir/z'), True) |
|
297 | self.assertEqual(dm.visitdir(b'dir/subdir/z'), True) | |
298 | self.assertEqual(dm.visitdir(b'dir/subdir/x'), True) |
|
298 | self.assertEqual(dm.visitdir(b'dir/subdir/x'), True) | |
299 | self.assertEqual(dm.visitdir(b'dir/foo'), b'all') |
|
299 | self.assertEqual(dm.visitdir(b'dir/foo'), b'all') | |
300 | self.assertEqual(dm.visitdir(b'folder'), b'all') |
|
300 | self.assertEqual(dm.visitdir(b'folder'), b'all') | |
301 |
|
301 | |||
302 | def testVisitchildrensetM2SubdirPrefix(self): |
|
302 | def testVisitchildrensetM2SubdirPrefix(self): | |
303 | m1 = matchmod.alwaysmatcher() |
|
303 | m1 = matchmod.alwaysmatcher() | |
304 | m2 = matchmod.match(b'', b'', patterns=[b'path:dir/subdir']) |
|
304 | m2 = matchmod.match(b'', b'', patterns=[b'path:dir/subdir']) | |
305 | dm = matchmod.differencematcher(m1, m2) |
|
305 | dm = matchmod.differencematcher(m1, m2) | |
306 | self.assertEqual(dm.visitchildrenset(b''), b'this') |
|
306 | self.assertEqual(dm.visitchildrenset(b''), b'this') | |
307 | self.assertEqual(dm.visitchildrenset(b'dir'), b'this') |
|
307 | self.assertEqual(dm.visitchildrenset(b'dir'), b'this') | |
308 | self.assertEqual(dm.visitchildrenset(b'dir/subdir'), set()) |
|
308 | self.assertEqual(dm.visitchildrenset(b'dir/subdir'), set()) | |
309 | self.assertEqual(dm.visitchildrenset(b'dir/foo'), b'all') |
|
309 | self.assertEqual(dm.visitchildrenset(b'dir/foo'), b'all') | |
310 | self.assertEqual(dm.visitchildrenset(b'folder'), b'all') |
|
310 | self.assertEqual(dm.visitchildrenset(b'folder'), b'all') | |
311 | # OPT: We should probably return set() for these; we don't because |
|
311 | # OPT: We should probably return set() for these; we don't because | |
312 | # patternmatcher.visitdir() (our m2) doesn't return 'all' for subdirs of |
|
312 | # patternmatcher.visitdir() (our m2) doesn't return 'all' for subdirs of | |
313 | # an 'all' pattern, just 'this'. |
|
313 | # an 'all' pattern, just 'this'. | |
314 | self.assertEqual(dm.visitchildrenset(b'dir/subdir/z'), b'this') |
|
314 | self.assertEqual(dm.visitchildrenset(b'dir/subdir/z'), b'this') | |
315 | self.assertEqual(dm.visitchildrenset(b'dir/subdir/x'), b'this') |
|
315 | self.assertEqual(dm.visitchildrenset(b'dir/subdir/x'), b'this') | |
316 |
|
316 | |||
317 | # We're using includematcher instead of patterns because it behaves slightly |
|
317 | # We're using includematcher instead of patterns because it behaves slightly | |
318 | # better (giving narrower results) than patternmatcher. |
|
318 | # better (giving narrower results) than patternmatcher. | |
319 |
def testVisitdirIncludeInclud |
|
319 | def testVisitdirIncludeInclude(self): | |
320 | m1 = matchmod.match(b'', b'', include=[b'path:dir/subdir']) |
|
320 | m1 = matchmod.match(b'', b'', include=[b'path:dir/subdir']) | |
321 | m2 = matchmod.match(b'', b'', include=[b'rootfilesin:dir']) |
|
321 | m2 = matchmod.match(b'', b'', include=[b'rootfilesin:dir']) | |
322 | dm = matchmod.differencematcher(m1, m2) |
|
322 | dm = matchmod.differencematcher(m1, m2) | |
323 | self.assertEqual(dm.visitdir(b''), True) |
|
323 | self.assertEqual(dm.visitdir(b''), True) | |
324 | self.assertEqual(dm.visitdir(b'dir'), True) |
|
324 | self.assertEqual(dm.visitdir(b'dir'), True) | |
325 | self.assertEqual(dm.visitdir(b'dir/subdir'), b'all') |
|
325 | self.assertEqual(dm.visitdir(b'dir/subdir'), b'all') | |
326 | self.assertFalse(dm.visitdir(b'dir/foo')) |
|
326 | self.assertFalse(dm.visitdir(b'dir/foo')) | |
327 | self.assertFalse(dm.visitdir(b'folder')) |
|
327 | self.assertFalse(dm.visitdir(b'folder')) | |
328 | # OPT: We should probably return False for these; we don't because |
|
328 | # OPT: We should probably return False for these; we don't because | |
329 | # patternmatcher.visitdir() (our m2) doesn't return 'all' for subdirs of |
|
329 | # patternmatcher.visitdir() (our m2) doesn't return 'all' for subdirs of | |
330 | # an 'all' pattern, just True. |
|
330 | # an 'all' pattern, just True. | |
331 | self.assertEqual(dm.visitdir(b'dir/subdir/z'), True) |
|
331 | self.assertEqual(dm.visitdir(b'dir/subdir/z'), True) | |
332 | self.assertEqual(dm.visitdir(b'dir/subdir/x'), True) |
|
332 | self.assertEqual(dm.visitdir(b'dir/subdir/x'), True) | |
333 |
|
333 | |||
334 | def testVisitchildrensetIncludeInclude(self): |
|
334 | def testVisitchildrensetIncludeInclude(self): | |
335 | m1 = matchmod.match(b'', b'', include=[b'path:dir/subdir']) |
|
335 | m1 = matchmod.match(b'', b'', include=[b'path:dir/subdir']) | |
336 | m2 = matchmod.match(b'', b'', include=[b'rootfilesin:dir']) |
|
336 | m2 = matchmod.match(b'', b'', include=[b'rootfilesin:dir']) | |
337 | dm = matchmod.differencematcher(m1, m2) |
|
337 | dm = matchmod.differencematcher(m1, m2) | |
338 | self.assertEqual(dm.visitchildrenset(b''), {b'dir'}) |
|
338 | self.assertEqual(dm.visitchildrenset(b''), {b'dir'}) | |
339 | self.assertEqual(dm.visitchildrenset(b'dir'), {b'subdir'}) |
|
339 | self.assertEqual(dm.visitchildrenset(b'dir'), {b'subdir'}) | |
340 | self.assertEqual(dm.visitchildrenset(b'dir/subdir'), b'all') |
|
340 | self.assertEqual(dm.visitchildrenset(b'dir/subdir'), b'all') | |
341 | self.assertEqual(dm.visitchildrenset(b'dir/foo'), set()) |
|
341 | self.assertEqual(dm.visitchildrenset(b'dir/foo'), set()) | |
342 | self.assertEqual(dm.visitchildrenset(b'folder'), set()) |
|
342 | self.assertEqual(dm.visitchildrenset(b'folder'), set()) | |
343 | # OPT: We should probably return set() for these; we don't because |
|
343 | # OPT: We should probably return set() for these; we don't because | |
344 | # patternmatcher.visitdir() (our m2) doesn't return 'all' for subdirs of |
|
344 | # patternmatcher.visitdir() (our m2) doesn't return 'all' for subdirs of | |
345 | # an 'all' pattern, just 'this'. |
|
345 | # an 'all' pattern, just 'this'. | |
346 | self.assertEqual(dm.visitchildrenset(b'dir/subdir/z'), b'this') |
|
346 | self.assertEqual(dm.visitchildrenset(b'dir/subdir/z'), b'this') | |
347 | self.assertEqual(dm.visitchildrenset(b'dir/subdir/x'), b'this') |
|
347 | self.assertEqual(dm.visitchildrenset(b'dir/subdir/x'), b'this') | |
348 |
|
348 | |||
349 |
|
349 | |||
350 | class IntersectionMatcherTests(unittest.TestCase): |
|
350 | class IntersectionMatcherTests(unittest.TestCase): | |
351 | def testVisitdirM2always(self): |
|
351 | def testVisitdirM2always(self): | |
352 | m1 = matchmod.alwaysmatcher() |
|
352 | m1 = matchmod.alwaysmatcher() | |
353 | m2 = matchmod.alwaysmatcher() |
|
353 | m2 = matchmod.alwaysmatcher() | |
354 | im = matchmod.intersectmatchers(m1, m2) |
|
354 | im = matchmod.intersectmatchers(m1, m2) | |
355 | # im should be equivalent to a alwaysmatcher. |
|
355 | # im should be equivalent to a alwaysmatcher. | |
356 | self.assertEqual(im.visitdir(b''), b'all') |
|
356 | self.assertEqual(im.visitdir(b''), b'all') | |
357 | self.assertEqual(im.visitdir(b'dir'), b'all') |
|
357 | self.assertEqual(im.visitdir(b'dir'), b'all') | |
358 | self.assertEqual(im.visitdir(b'dir/subdir'), b'all') |
|
358 | self.assertEqual(im.visitdir(b'dir/subdir'), b'all') | |
359 | self.assertEqual(im.visitdir(b'dir/subdir/z'), b'all') |
|
359 | self.assertEqual(im.visitdir(b'dir/subdir/z'), b'all') | |
360 | self.assertEqual(im.visitdir(b'dir/foo'), b'all') |
|
360 | self.assertEqual(im.visitdir(b'dir/foo'), b'all') | |
361 | self.assertEqual(im.visitdir(b'dir/subdir/x'), b'all') |
|
361 | self.assertEqual(im.visitdir(b'dir/subdir/x'), b'all') | |
362 | self.assertEqual(im.visitdir(b'folder'), b'all') |
|
362 | self.assertEqual(im.visitdir(b'folder'), b'all') | |
363 |
|
363 | |||
364 | def testVisitchildrensetM2always(self): |
|
364 | def testVisitchildrensetM2always(self): | |
365 | m1 = matchmod.alwaysmatcher() |
|
365 | m1 = matchmod.alwaysmatcher() | |
366 | m2 = matchmod.alwaysmatcher() |
|
366 | m2 = matchmod.alwaysmatcher() | |
367 | im = matchmod.intersectmatchers(m1, m2) |
|
367 | im = matchmod.intersectmatchers(m1, m2) | |
368 | # im should be equivalent to a alwaysmatcher. |
|
368 | # im should be equivalent to a alwaysmatcher. | |
369 | self.assertEqual(im.visitchildrenset(b''), b'all') |
|
369 | self.assertEqual(im.visitchildrenset(b''), b'all') | |
370 | self.assertEqual(im.visitchildrenset(b'dir'), b'all') |
|
370 | self.assertEqual(im.visitchildrenset(b'dir'), b'all') | |
371 | self.assertEqual(im.visitchildrenset(b'dir/subdir'), b'all') |
|
371 | self.assertEqual(im.visitchildrenset(b'dir/subdir'), b'all') | |
372 | self.assertEqual(im.visitchildrenset(b'dir/subdir/z'), b'all') |
|
372 | self.assertEqual(im.visitchildrenset(b'dir/subdir/z'), b'all') | |
373 | self.assertEqual(im.visitchildrenset(b'dir/foo'), b'all') |
|
373 | self.assertEqual(im.visitchildrenset(b'dir/foo'), b'all') | |
374 | self.assertEqual(im.visitchildrenset(b'dir/subdir/x'), b'all') |
|
374 | self.assertEqual(im.visitchildrenset(b'dir/subdir/x'), b'all') | |
375 | self.assertEqual(im.visitchildrenset(b'folder'), b'all') |
|
375 | self.assertEqual(im.visitchildrenset(b'folder'), b'all') | |
376 |
|
376 | |||
377 | def testVisitdirM2never(self): |
|
377 | def testVisitdirM2never(self): | |
378 | m1 = matchmod.alwaysmatcher() |
|
378 | m1 = matchmod.alwaysmatcher() | |
379 | m2 = matchmod.nevermatcher() |
|
379 | m2 = matchmod.nevermatcher() | |
380 | im = matchmod.intersectmatchers(m1, m2) |
|
380 | im = matchmod.intersectmatchers(m1, m2) | |
381 | # im should be equivalent to a nevermatcher. |
|
381 | # im should be equivalent to a nevermatcher. | |
382 | self.assertFalse(im.visitdir(b'')) |
|
382 | self.assertFalse(im.visitdir(b'')) | |
383 | self.assertFalse(im.visitdir(b'dir')) |
|
383 | self.assertFalse(im.visitdir(b'dir')) | |
384 | self.assertFalse(im.visitdir(b'dir/subdir')) |
|
384 | self.assertFalse(im.visitdir(b'dir/subdir')) | |
385 | self.assertFalse(im.visitdir(b'dir/subdir/z')) |
|
385 | self.assertFalse(im.visitdir(b'dir/subdir/z')) | |
386 | self.assertFalse(im.visitdir(b'dir/foo')) |
|
386 | self.assertFalse(im.visitdir(b'dir/foo')) | |
387 | self.assertFalse(im.visitdir(b'dir/subdir/x')) |
|
387 | self.assertFalse(im.visitdir(b'dir/subdir/x')) | |
388 | self.assertFalse(im.visitdir(b'folder')) |
|
388 | self.assertFalse(im.visitdir(b'folder')) | |
389 |
|
389 | |||
390 | def testVisitchildrensetM2never(self): |
|
390 | def testVisitchildrensetM2never(self): | |
391 | m1 = matchmod.alwaysmatcher() |
|
391 | m1 = matchmod.alwaysmatcher() | |
392 | m2 = matchmod.nevermatcher() |
|
392 | m2 = matchmod.nevermatcher() | |
393 | im = matchmod.intersectmatchers(m1, m2) |
|
393 | im = matchmod.intersectmatchers(m1, m2) | |
394 | # im should be equivalent to a nevermqtcher. |
|
394 | # im should be equivalent to a nevermqtcher. | |
395 | self.assertEqual(im.visitchildrenset(b''), set()) |
|
395 | self.assertEqual(im.visitchildrenset(b''), set()) | |
396 | self.assertEqual(im.visitchildrenset(b'dir'), set()) |
|
396 | self.assertEqual(im.visitchildrenset(b'dir'), set()) | |
397 | self.assertEqual(im.visitchildrenset(b'dir/subdir'), set()) |
|
397 | self.assertEqual(im.visitchildrenset(b'dir/subdir'), set()) | |
398 | self.assertEqual(im.visitchildrenset(b'dir/subdir/z'), set()) |
|
398 | self.assertEqual(im.visitchildrenset(b'dir/subdir/z'), set()) | |
399 | self.assertEqual(im.visitchildrenset(b'dir/foo'), set()) |
|
399 | self.assertEqual(im.visitchildrenset(b'dir/foo'), set()) | |
400 | self.assertEqual(im.visitchildrenset(b'dir/subdir/x'), set()) |
|
400 | self.assertEqual(im.visitchildrenset(b'dir/subdir/x'), set()) | |
401 | self.assertEqual(im.visitchildrenset(b'folder'), set()) |
|
401 | self.assertEqual(im.visitchildrenset(b'folder'), set()) | |
402 |
|
402 | |||
403 | def testVisitdirM2SubdirPrefix(self): |
|
403 | def testVisitdirM2SubdirPrefix(self): | |
404 | m1 = matchmod.alwaysmatcher() |
|
404 | m1 = matchmod.alwaysmatcher() | |
405 | m2 = matchmod.match(b'', b'', patterns=[b'path:dir/subdir']) |
|
405 | m2 = matchmod.match(b'', b'', patterns=[b'path:dir/subdir']) | |
406 | im = matchmod.intersectmatchers(m1, m2) |
|
406 | im = matchmod.intersectmatchers(m1, m2) | |
407 | self.assertEqual(im.visitdir(b''), True) |
|
407 | self.assertEqual(im.visitdir(b''), True) | |
408 | self.assertEqual(im.visitdir(b'dir'), True) |
|
408 | self.assertEqual(im.visitdir(b'dir'), True) | |
409 | self.assertEqual(im.visitdir(b'dir/subdir'), b'all') |
|
409 | self.assertEqual(im.visitdir(b'dir/subdir'), b'all') | |
410 | self.assertFalse(im.visitdir(b'dir/foo')) |
|
410 | self.assertFalse(im.visitdir(b'dir/foo')) | |
411 | self.assertFalse(im.visitdir(b'folder')) |
|
411 | self.assertFalse(im.visitdir(b'folder')) | |
412 | # OPT: We should probably return 'all' for these; we don't because |
|
412 | # OPT: We should probably return 'all' for these; we don't because | |
413 | # patternmatcher.visitdir() (our m2) doesn't return 'all' for subdirs of |
|
413 | # patternmatcher.visitdir() (our m2) doesn't return 'all' for subdirs of | |
414 | # an 'all' pattern, just True. |
|
414 | # an 'all' pattern, just True. | |
415 | self.assertEqual(im.visitdir(b'dir/subdir/z'), True) |
|
415 | self.assertEqual(im.visitdir(b'dir/subdir/z'), True) | |
416 | self.assertEqual(im.visitdir(b'dir/subdir/x'), True) |
|
416 | self.assertEqual(im.visitdir(b'dir/subdir/x'), True) | |
417 |
|
417 | |||
418 | def testVisitchildrensetM2SubdirPrefix(self): |
|
418 | def testVisitchildrensetM2SubdirPrefix(self): | |
419 | m1 = matchmod.alwaysmatcher() |
|
419 | m1 = matchmod.alwaysmatcher() | |
420 | m2 = matchmod.match(b'', b'', include=[b'path:dir/subdir']) |
|
420 | m2 = matchmod.match(b'', b'', include=[b'path:dir/subdir']) | |
421 | im = matchmod.intersectmatchers(m1, m2) |
|
421 | im = matchmod.intersectmatchers(m1, m2) | |
422 | self.assertEqual(im.visitchildrenset(b''), {b'dir'}) |
|
422 | self.assertEqual(im.visitchildrenset(b''), {b'dir'}) | |
423 | self.assertEqual(im.visitchildrenset(b'dir'), {b'subdir'}) |
|
423 | self.assertEqual(im.visitchildrenset(b'dir'), {b'subdir'}) | |
424 | self.assertEqual(im.visitchildrenset(b'dir/subdir'), b'all') |
|
424 | self.assertEqual(im.visitchildrenset(b'dir/subdir'), b'all') | |
425 | self.assertEqual(im.visitchildrenset(b'dir/foo'), set()) |
|
425 | self.assertEqual(im.visitchildrenset(b'dir/foo'), set()) | |
426 | self.assertEqual(im.visitchildrenset(b'folder'), set()) |
|
426 | self.assertEqual(im.visitchildrenset(b'folder'), set()) | |
427 | # OPT: We should probably return 'all' for these |
|
427 | # OPT: We should probably return 'all' for these | |
428 | self.assertEqual(im.visitchildrenset(b'dir/subdir/z'), b'this') |
|
428 | self.assertEqual(im.visitchildrenset(b'dir/subdir/z'), b'this') | |
429 | self.assertEqual(im.visitchildrenset(b'dir/subdir/x'), b'this') |
|
429 | self.assertEqual(im.visitchildrenset(b'dir/subdir/x'), b'this') | |
430 |
|
430 | |||
431 | # We're using includematcher instead of patterns because it behaves slightly |
|
431 | # We're using includematcher instead of patterns because it behaves slightly | |
432 | # better (giving narrower results) than patternmatcher. |
|
432 | # better (giving narrower results) than patternmatcher. | |
433 |
def testVisitdirIncludeInclud |
|
433 | def testVisitdirIncludeInclude(self): | |
434 | m1 = matchmod.match(b'', b'', include=[b'path:dir/subdir']) |
|
434 | m1 = matchmod.match(b'', b'', include=[b'path:dir/subdir']) | |
435 | m2 = matchmod.match(b'', b'', include=[b'rootfilesin:dir']) |
|
435 | m2 = matchmod.match(b'', b'', include=[b'rootfilesin:dir']) | |
436 | im = matchmod.intersectmatchers(m1, m2) |
|
436 | im = matchmod.intersectmatchers(m1, m2) | |
437 | self.assertEqual(im.visitdir(b''), True) |
|
437 | self.assertEqual(im.visitdir(b''), True) | |
438 | self.assertEqual(im.visitdir(b'dir'), True) |
|
438 | self.assertEqual(im.visitdir(b'dir'), True) | |
439 | self.assertFalse(im.visitdir(b'dir/subdir')) |
|
439 | self.assertFalse(im.visitdir(b'dir/subdir')) | |
440 | self.assertFalse(im.visitdir(b'dir/foo')) |
|
440 | self.assertFalse(im.visitdir(b'dir/foo')) | |
441 | self.assertFalse(im.visitdir(b'folder')) |
|
441 | self.assertFalse(im.visitdir(b'folder')) | |
442 | self.assertFalse(im.visitdir(b'dir/subdir/z')) |
|
442 | self.assertFalse(im.visitdir(b'dir/subdir/z')) | |
443 | self.assertFalse(im.visitdir(b'dir/subdir/x')) |
|
443 | self.assertFalse(im.visitdir(b'dir/subdir/x')) | |
444 |
|
444 | |||
445 | def testVisitchildrensetIncludeInclude(self): |
|
445 | def testVisitchildrensetIncludeInclude(self): | |
446 | m1 = matchmod.match(b'', b'', include=[b'path:dir/subdir']) |
|
446 | m1 = matchmod.match(b'', b'', include=[b'path:dir/subdir']) | |
447 | m2 = matchmod.match(b'', b'', include=[b'rootfilesin:dir']) |
|
447 | m2 = matchmod.match(b'', b'', include=[b'rootfilesin:dir']) | |
448 | im = matchmod.intersectmatchers(m1, m2) |
|
448 | im = matchmod.intersectmatchers(m1, m2) | |
449 | self.assertEqual(im.visitchildrenset(b''), {b'dir'}) |
|
449 | self.assertEqual(im.visitchildrenset(b''), {b'dir'}) | |
450 | self.assertEqual(im.visitchildrenset(b'dir'), b'this') |
|
450 | self.assertEqual(im.visitchildrenset(b'dir'), b'this') | |
451 | self.assertEqual(im.visitchildrenset(b'dir/subdir'), set()) |
|
451 | self.assertEqual(im.visitchildrenset(b'dir/subdir'), set()) | |
452 | self.assertEqual(im.visitchildrenset(b'dir/foo'), set()) |
|
452 | self.assertEqual(im.visitchildrenset(b'dir/foo'), set()) | |
453 | self.assertEqual(im.visitchildrenset(b'folder'), set()) |
|
453 | self.assertEqual(im.visitchildrenset(b'folder'), set()) | |
454 | self.assertEqual(im.visitchildrenset(b'dir/subdir/z'), set()) |
|
454 | self.assertEqual(im.visitchildrenset(b'dir/subdir/z'), set()) | |
455 | self.assertEqual(im.visitchildrenset(b'dir/subdir/x'), set()) |
|
455 | self.assertEqual(im.visitchildrenset(b'dir/subdir/x'), set()) | |
456 |
|
456 | |||
457 | # We're using includematcher instead of patterns because it behaves slightly |
|
457 | # We're using includematcher instead of patterns because it behaves slightly | |
458 | # better (giving narrower results) than patternmatcher. |
|
458 | # better (giving narrower results) than patternmatcher. | |
459 | def testVisitdirIncludeInclude2(self): |
|
459 | def testVisitdirIncludeInclude2(self): | |
460 | m1 = matchmod.match(b'', b'', include=[b'path:dir/subdir']) |
|
460 | m1 = matchmod.match(b'', b'', include=[b'path:dir/subdir']) | |
461 | m2 = matchmod.match(b'', b'', include=[b'path:folder']) |
|
461 | m2 = matchmod.match(b'', b'', include=[b'path:folder']) | |
462 | im = matchmod.intersectmatchers(m1, m2) |
|
462 | im = matchmod.intersectmatchers(m1, m2) | |
463 | # FIXME: is True correct here? |
|
463 | # FIXME: is True correct here? | |
464 | self.assertEqual(im.visitdir(b''), True) |
|
464 | self.assertEqual(im.visitdir(b''), True) | |
465 | self.assertFalse(im.visitdir(b'dir')) |
|
465 | self.assertFalse(im.visitdir(b'dir')) | |
466 | self.assertFalse(im.visitdir(b'dir/subdir')) |
|
466 | self.assertFalse(im.visitdir(b'dir/subdir')) | |
467 | self.assertFalse(im.visitdir(b'dir/foo')) |
|
467 | self.assertFalse(im.visitdir(b'dir/foo')) | |
468 | self.assertFalse(im.visitdir(b'folder')) |
|
468 | self.assertFalse(im.visitdir(b'folder')) | |
469 | self.assertFalse(im.visitdir(b'dir/subdir/z')) |
|
469 | self.assertFalse(im.visitdir(b'dir/subdir/z')) | |
470 | self.assertFalse(im.visitdir(b'dir/subdir/x')) |
|
470 | self.assertFalse(im.visitdir(b'dir/subdir/x')) | |
471 |
|
471 | |||
472 | def testVisitchildrensetIncludeInclude2(self): |
|
472 | def testVisitchildrensetIncludeInclude2(self): | |
473 | m1 = matchmod.match(b'', b'', include=[b'path:dir/subdir']) |
|
473 | m1 = matchmod.match(b'', b'', include=[b'path:dir/subdir']) | |
474 | m2 = matchmod.match(b'', b'', include=[b'path:folder']) |
|
474 | m2 = matchmod.match(b'', b'', include=[b'path:folder']) | |
475 | im = matchmod.intersectmatchers(m1, m2) |
|
475 | im = matchmod.intersectmatchers(m1, m2) | |
476 | # FIXME: is set() correct here? |
|
476 | # FIXME: is set() correct here? | |
477 | self.assertEqual(im.visitchildrenset(b''), set()) |
|
477 | self.assertEqual(im.visitchildrenset(b''), set()) | |
478 | self.assertEqual(im.visitchildrenset(b'dir'), set()) |
|
478 | self.assertEqual(im.visitchildrenset(b'dir'), set()) | |
479 | self.assertEqual(im.visitchildrenset(b'dir/subdir'), set()) |
|
479 | self.assertEqual(im.visitchildrenset(b'dir/subdir'), set()) | |
480 | self.assertEqual(im.visitchildrenset(b'dir/foo'), set()) |
|
480 | self.assertEqual(im.visitchildrenset(b'dir/foo'), set()) | |
481 | self.assertEqual(im.visitchildrenset(b'folder'), set()) |
|
481 | self.assertEqual(im.visitchildrenset(b'folder'), set()) | |
482 | self.assertEqual(im.visitchildrenset(b'dir/subdir/z'), set()) |
|
482 | self.assertEqual(im.visitchildrenset(b'dir/subdir/z'), set()) | |
483 | self.assertEqual(im.visitchildrenset(b'dir/subdir/x'), set()) |
|
483 | self.assertEqual(im.visitchildrenset(b'dir/subdir/x'), set()) | |
484 |
|
484 | |||
485 | # We're using includematcher instead of patterns because it behaves slightly |
|
485 | # We're using includematcher instead of patterns because it behaves slightly | |
486 | # better (giving narrower results) than patternmatcher. |
|
486 | # better (giving narrower results) than patternmatcher. | |
487 | def testVisitdirIncludeInclude3(self): |
|
487 | def testVisitdirIncludeInclude3(self): | |
488 | m1 = matchmod.match(b'', b'', include=[b'path:dir/subdir/x']) |
|
488 | m1 = matchmod.match(b'', b'', include=[b'path:dir/subdir/x']) | |
489 | m2 = matchmod.match(b'', b'', include=[b'path:dir/subdir']) |
|
489 | m2 = matchmod.match(b'', b'', include=[b'path:dir/subdir']) | |
490 | im = matchmod.intersectmatchers(m1, m2) |
|
490 | im = matchmod.intersectmatchers(m1, m2) | |
491 | self.assertEqual(im.visitdir(b''), True) |
|
491 | self.assertEqual(im.visitdir(b''), True) | |
492 | self.assertEqual(im.visitdir(b'dir'), True) |
|
492 | self.assertEqual(im.visitdir(b'dir'), True) | |
493 | self.assertEqual(im.visitdir(b'dir/subdir'), True) |
|
493 | self.assertEqual(im.visitdir(b'dir/subdir'), True) | |
494 | self.assertFalse(im.visitdir(b'dir/foo')) |
|
494 | self.assertFalse(im.visitdir(b'dir/foo')) | |
495 | self.assertFalse(im.visitdir(b'folder')) |
|
495 | self.assertFalse(im.visitdir(b'folder')) | |
496 | self.assertFalse(im.visitdir(b'dir/subdir/z')) |
|
496 | self.assertFalse(im.visitdir(b'dir/subdir/z')) | |
497 | # OPT: this should probably be 'all' not True. |
|
497 | # OPT: this should probably be 'all' not True. | |
498 | self.assertEqual(im.visitdir(b'dir/subdir/x'), True) |
|
498 | self.assertEqual(im.visitdir(b'dir/subdir/x'), True) | |
499 |
|
499 | |||
500 | def testVisitchildrensetIncludeInclude3(self): |
|
500 | def testVisitchildrensetIncludeInclude3(self): | |
501 | m1 = matchmod.match(b'', b'', include=[b'path:dir/subdir/x']) |
|
501 | m1 = matchmod.match(b'', b'', include=[b'path:dir/subdir/x']) | |
502 | m2 = matchmod.match(b'', b'', include=[b'path:dir/subdir']) |
|
502 | m2 = matchmod.match(b'', b'', include=[b'path:dir/subdir']) | |
503 | im = matchmod.intersectmatchers(m1, m2) |
|
503 | im = matchmod.intersectmatchers(m1, m2) | |
504 | self.assertEqual(im.visitchildrenset(b''), {b'dir'}) |
|
504 | self.assertEqual(im.visitchildrenset(b''), {b'dir'}) | |
505 | self.assertEqual(im.visitchildrenset(b'dir'), {b'subdir'}) |
|
505 | self.assertEqual(im.visitchildrenset(b'dir'), {b'subdir'}) | |
506 | self.assertEqual(im.visitchildrenset(b'dir/subdir'), {b'x'}) |
|
506 | self.assertEqual(im.visitchildrenset(b'dir/subdir'), {b'x'}) | |
507 | self.assertEqual(im.visitchildrenset(b'dir/foo'), set()) |
|
507 | self.assertEqual(im.visitchildrenset(b'dir/foo'), set()) | |
508 | self.assertEqual(im.visitchildrenset(b'folder'), set()) |
|
508 | self.assertEqual(im.visitchildrenset(b'folder'), set()) | |
509 | self.assertEqual(im.visitchildrenset(b'dir/subdir/z'), set()) |
|
509 | self.assertEqual(im.visitchildrenset(b'dir/subdir/z'), set()) | |
510 | # OPT: this should probably be 'all' not 'this'. |
|
510 | # OPT: this should probably be 'all' not 'this'. | |
511 | self.assertEqual(im.visitchildrenset(b'dir/subdir/x'), b'this') |
|
511 | self.assertEqual(im.visitchildrenset(b'dir/subdir/x'), b'this') | |
512 |
|
512 | |||
513 | # We're using includematcher instead of patterns because it behaves slightly |
|
513 | # We're using includematcher instead of patterns because it behaves slightly | |
514 | # better (giving narrower results) than patternmatcher. |
|
514 | # better (giving narrower results) than patternmatcher. | |
515 | def testVisitdirIncludeInclude4(self): |
|
515 | def testVisitdirIncludeInclude4(self): | |
516 | m1 = matchmod.match(b'', b'', include=[b'path:dir/subdir/x']) |
|
516 | m1 = matchmod.match(b'', b'', include=[b'path:dir/subdir/x']) | |
517 | m2 = matchmod.match(b'', b'', include=[b'path:dir/subdir/z']) |
|
517 | m2 = matchmod.match(b'', b'', include=[b'path:dir/subdir/z']) | |
518 | im = matchmod.intersectmatchers(m1, m2) |
|
518 | im = matchmod.intersectmatchers(m1, m2) | |
519 | # OPT: these next three could probably be False as well. |
|
519 | # OPT: these next three could probably be False as well. | |
520 | self.assertEqual(im.visitdir(b''), True) |
|
520 | self.assertEqual(im.visitdir(b''), True) | |
521 | self.assertEqual(im.visitdir(b'dir'), True) |
|
521 | self.assertEqual(im.visitdir(b'dir'), True) | |
522 | self.assertEqual(im.visitdir(b'dir/subdir'), True) |
|
522 | self.assertEqual(im.visitdir(b'dir/subdir'), True) | |
523 | self.assertFalse(im.visitdir(b'dir/foo')) |
|
523 | self.assertFalse(im.visitdir(b'dir/foo')) | |
524 | self.assertFalse(im.visitdir(b'folder')) |
|
524 | self.assertFalse(im.visitdir(b'folder')) | |
525 | self.assertFalse(im.visitdir(b'dir/subdir/z')) |
|
525 | self.assertFalse(im.visitdir(b'dir/subdir/z')) | |
526 | self.assertFalse(im.visitdir(b'dir/subdir/x')) |
|
526 | self.assertFalse(im.visitdir(b'dir/subdir/x')) | |
527 |
|
527 | |||
528 | def testVisitchildrensetIncludeInclude4(self): |
|
528 | def testVisitchildrensetIncludeInclude4(self): | |
529 | m1 = matchmod.match(b'', b'', include=[b'path:dir/subdir/x']) |
|
529 | m1 = matchmod.match(b'', b'', include=[b'path:dir/subdir/x']) | |
530 | m2 = matchmod.match(b'', b'', include=[b'path:dir/subdir/z']) |
|
530 | m2 = matchmod.match(b'', b'', include=[b'path:dir/subdir/z']) | |
531 | im = matchmod.intersectmatchers(m1, m2) |
|
531 | im = matchmod.intersectmatchers(m1, m2) | |
532 | # OPT: these next two could probably be set() as well. |
|
532 | # OPT: these next two could probably be set() as well. | |
533 | self.assertEqual(im.visitchildrenset(b''), {b'dir'}) |
|
533 | self.assertEqual(im.visitchildrenset(b''), {b'dir'}) | |
534 | self.assertEqual(im.visitchildrenset(b'dir'), {b'subdir'}) |
|
534 | self.assertEqual(im.visitchildrenset(b'dir'), {b'subdir'}) | |
535 | self.assertEqual(im.visitchildrenset(b'dir/subdir'), set()) |
|
535 | self.assertEqual(im.visitchildrenset(b'dir/subdir'), set()) | |
536 | self.assertEqual(im.visitchildrenset(b'dir/foo'), set()) |
|
536 | self.assertEqual(im.visitchildrenset(b'dir/foo'), set()) | |
537 | self.assertEqual(im.visitchildrenset(b'folder'), set()) |
|
537 | self.assertEqual(im.visitchildrenset(b'folder'), set()) | |
538 | self.assertEqual(im.visitchildrenset(b'dir/subdir/z'), set()) |
|
538 | self.assertEqual(im.visitchildrenset(b'dir/subdir/z'), set()) | |
539 | self.assertEqual(im.visitchildrenset(b'dir/subdir/x'), set()) |
|
539 | self.assertEqual(im.visitchildrenset(b'dir/subdir/x'), set()) | |
540 |
|
540 | |||
541 |
|
541 | |||
542 | class UnionMatcherTests(unittest.TestCase): |
|
542 | class UnionMatcherTests(unittest.TestCase): | |
543 | def testVisitdirM2always(self): |
|
543 | def testVisitdirM2always(self): | |
544 | m1 = matchmod.alwaysmatcher() |
|
544 | m1 = matchmod.alwaysmatcher() | |
545 | m2 = matchmod.alwaysmatcher() |
|
545 | m2 = matchmod.alwaysmatcher() | |
546 | um = matchmod.unionmatcher([m1, m2]) |
|
546 | um = matchmod.unionmatcher([m1, m2]) | |
547 | # um should be equivalent to a alwaysmatcher. |
|
547 | # um should be equivalent to a alwaysmatcher. | |
548 | self.assertEqual(um.visitdir(b''), b'all') |
|
548 | self.assertEqual(um.visitdir(b''), b'all') | |
549 | self.assertEqual(um.visitdir(b'dir'), b'all') |
|
549 | self.assertEqual(um.visitdir(b'dir'), b'all') | |
550 | self.assertEqual(um.visitdir(b'dir/subdir'), b'all') |
|
550 | self.assertEqual(um.visitdir(b'dir/subdir'), b'all') | |
551 | self.assertEqual(um.visitdir(b'dir/subdir/z'), b'all') |
|
551 | self.assertEqual(um.visitdir(b'dir/subdir/z'), b'all') | |
552 | self.assertEqual(um.visitdir(b'dir/foo'), b'all') |
|
552 | self.assertEqual(um.visitdir(b'dir/foo'), b'all') | |
553 | self.assertEqual(um.visitdir(b'dir/subdir/x'), b'all') |
|
553 | self.assertEqual(um.visitdir(b'dir/subdir/x'), b'all') | |
554 | self.assertEqual(um.visitdir(b'folder'), b'all') |
|
554 | self.assertEqual(um.visitdir(b'folder'), b'all') | |
555 |
|
555 | |||
556 | def testVisitchildrensetM2always(self): |
|
556 | def testVisitchildrensetM2always(self): | |
557 | m1 = matchmod.alwaysmatcher() |
|
557 | m1 = matchmod.alwaysmatcher() | |
558 | m2 = matchmod.alwaysmatcher() |
|
558 | m2 = matchmod.alwaysmatcher() | |
559 | um = matchmod.unionmatcher([m1, m2]) |
|
559 | um = matchmod.unionmatcher([m1, m2]) | |
560 | # um should be equivalent to a alwaysmatcher. |
|
560 | # um should be equivalent to a alwaysmatcher. | |
561 | self.assertEqual(um.visitchildrenset(b''), b'all') |
|
561 | self.assertEqual(um.visitchildrenset(b''), b'all') | |
562 | self.assertEqual(um.visitchildrenset(b'dir'), b'all') |
|
562 | self.assertEqual(um.visitchildrenset(b'dir'), b'all') | |
563 | self.assertEqual(um.visitchildrenset(b'dir/subdir'), b'all') |
|
563 | self.assertEqual(um.visitchildrenset(b'dir/subdir'), b'all') | |
564 | self.assertEqual(um.visitchildrenset(b'dir/subdir/z'), b'all') |
|
564 | self.assertEqual(um.visitchildrenset(b'dir/subdir/z'), b'all') | |
565 | self.assertEqual(um.visitchildrenset(b'dir/foo'), b'all') |
|
565 | self.assertEqual(um.visitchildrenset(b'dir/foo'), b'all') | |
566 | self.assertEqual(um.visitchildrenset(b'dir/subdir/x'), b'all') |
|
566 | self.assertEqual(um.visitchildrenset(b'dir/subdir/x'), b'all') | |
567 | self.assertEqual(um.visitchildrenset(b'folder'), b'all') |
|
567 | self.assertEqual(um.visitchildrenset(b'folder'), b'all') | |
568 |
|
568 | |||
569 | def testVisitdirM1never(self): |
|
569 | def testVisitdirM1never(self): | |
570 | m1 = matchmod.nevermatcher() |
|
570 | m1 = matchmod.nevermatcher() | |
571 | m2 = matchmod.alwaysmatcher() |
|
571 | m2 = matchmod.alwaysmatcher() | |
572 | um = matchmod.unionmatcher([m1, m2]) |
|
572 | um = matchmod.unionmatcher([m1, m2]) | |
573 | # um should be equivalent to a alwaysmatcher. |
|
573 | # um should be equivalent to a alwaysmatcher. | |
574 | self.assertEqual(um.visitdir(b''), b'all') |
|
574 | self.assertEqual(um.visitdir(b''), b'all') | |
575 | self.assertEqual(um.visitdir(b'dir'), b'all') |
|
575 | self.assertEqual(um.visitdir(b'dir'), b'all') | |
576 | self.assertEqual(um.visitdir(b'dir/subdir'), b'all') |
|
576 | self.assertEqual(um.visitdir(b'dir/subdir'), b'all') | |
577 | self.assertEqual(um.visitdir(b'dir/subdir/z'), b'all') |
|
577 | self.assertEqual(um.visitdir(b'dir/subdir/z'), b'all') | |
578 | self.assertEqual(um.visitdir(b'dir/foo'), b'all') |
|
578 | self.assertEqual(um.visitdir(b'dir/foo'), b'all') | |
579 | self.assertEqual(um.visitdir(b'dir/subdir/x'), b'all') |
|
579 | self.assertEqual(um.visitdir(b'dir/subdir/x'), b'all') | |
580 | self.assertEqual(um.visitdir(b'folder'), b'all') |
|
580 | self.assertEqual(um.visitdir(b'folder'), b'all') | |
581 |
|
581 | |||
582 | def testVisitchildrensetM1never(self): |
|
582 | def testVisitchildrensetM1never(self): | |
583 | m1 = matchmod.nevermatcher() |
|
583 | m1 = matchmod.nevermatcher() | |
584 | m2 = matchmod.alwaysmatcher() |
|
584 | m2 = matchmod.alwaysmatcher() | |
585 | um = matchmod.unionmatcher([m1, m2]) |
|
585 | um = matchmod.unionmatcher([m1, m2]) | |
586 | # um should be equivalent to a alwaysmatcher. |
|
586 | # um should be equivalent to a alwaysmatcher. | |
587 | self.assertEqual(um.visitchildrenset(b''), b'all') |
|
587 | self.assertEqual(um.visitchildrenset(b''), b'all') | |
588 | self.assertEqual(um.visitchildrenset(b'dir'), b'all') |
|
588 | self.assertEqual(um.visitchildrenset(b'dir'), b'all') | |
589 | self.assertEqual(um.visitchildrenset(b'dir/subdir'), b'all') |
|
589 | self.assertEqual(um.visitchildrenset(b'dir/subdir'), b'all') | |
590 | self.assertEqual(um.visitchildrenset(b'dir/subdir/z'), b'all') |
|
590 | self.assertEqual(um.visitchildrenset(b'dir/subdir/z'), b'all') | |
591 | self.assertEqual(um.visitchildrenset(b'dir/foo'), b'all') |
|
591 | self.assertEqual(um.visitchildrenset(b'dir/foo'), b'all') | |
592 | self.assertEqual(um.visitchildrenset(b'dir/subdir/x'), b'all') |
|
592 | self.assertEqual(um.visitchildrenset(b'dir/subdir/x'), b'all') | |
593 | self.assertEqual(um.visitchildrenset(b'folder'), b'all') |
|
593 | self.assertEqual(um.visitchildrenset(b'folder'), b'all') | |
594 |
|
594 | |||
595 | def testVisitdirM2never(self): |
|
595 | def testVisitdirM2never(self): | |
596 | m1 = matchmod.alwaysmatcher() |
|
596 | m1 = matchmod.alwaysmatcher() | |
597 | m2 = matchmod.nevermatcher() |
|
597 | m2 = matchmod.nevermatcher() | |
598 | um = matchmod.unionmatcher([m1, m2]) |
|
598 | um = matchmod.unionmatcher([m1, m2]) | |
599 | # um should be equivalent to a alwaysmatcher. |
|
599 | # um should be equivalent to a alwaysmatcher. | |
600 | self.assertEqual(um.visitdir(b''), b'all') |
|
600 | self.assertEqual(um.visitdir(b''), b'all') | |
601 | self.assertEqual(um.visitdir(b'dir'), b'all') |
|
601 | self.assertEqual(um.visitdir(b'dir'), b'all') | |
602 | self.assertEqual(um.visitdir(b'dir/subdir'), b'all') |
|
602 | self.assertEqual(um.visitdir(b'dir/subdir'), b'all') | |
603 | self.assertEqual(um.visitdir(b'dir/subdir/z'), b'all') |
|
603 | self.assertEqual(um.visitdir(b'dir/subdir/z'), b'all') | |
604 | self.assertEqual(um.visitdir(b'dir/foo'), b'all') |
|
604 | self.assertEqual(um.visitdir(b'dir/foo'), b'all') | |
605 | self.assertEqual(um.visitdir(b'dir/subdir/x'), b'all') |
|
605 | self.assertEqual(um.visitdir(b'dir/subdir/x'), b'all') | |
606 | self.assertEqual(um.visitdir(b'folder'), b'all') |
|
606 | self.assertEqual(um.visitdir(b'folder'), b'all') | |
607 |
|
607 | |||
608 | def testVisitchildrensetM2never(self): |
|
608 | def testVisitchildrensetM2never(self): | |
609 | m1 = matchmod.alwaysmatcher() |
|
609 | m1 = matchmod.alwaysmatcher() | |
610 | m2 = matchmod.nevermatcher() |
|
610 | m2 = matchmod.nevermatcher() | |
611 | um = matchmod.unionmatcher([m1, m2]) |
|
611 | um = matchmod.unionmatcher([m1, m2]) | |
612 | # um should be equivalent to a alwaysmatcher. |
|
612 | # um should be equivalent to a alwaysmatcher. | |
613 | self.assertEqual(um.visitchildrenset(b''), b'all') |
|
613 | self.assertEqual(um.visitchildrenset(b''), b'all') | |
614 | self.assertEqual(um.visitchildrenset(b'dir'), b'all') |
|
614 | self.assertEqual(um.visitchildrenset(b'dir'), b'all') | |
615 | self.assertEqual(um.visitchildrenset(b'dir/subdir'), b'all') |
|
615 | self.assertEqual(um.visitchildrenset(b'dir/subdir'), b'all') | |
616 | self.assertEqual(um.visitchildrenset(b'dir/subdir/z'), b'all') |
|
616 | self.assertEqual(um.visitchildrenset(b'dir/subdir/z'), b'all') | |
617 | self.assertEqual(um.visitchildrenset(b'dir/foo'), b'all') |
|
617 | self.assertEqual(um.visitchildrenset(b'dir/foo'), b'all') | |
618 | self.assertEqual(um.visitchildrenset(b'dir/subdir/x'), b'all') |
|
618 | self.assertEqual(um.visitchildrenset(b'dir/subdir/x'), b'all') | |
619 | self.assertEqual(um.visitchildrenset(b'folder'), b'all') |
|
619 | self.assertEqual(um.visitchildrenset(b'folder'), b'all') | |
620 |
|
620 | |||
621 | def testVisitdirM2SubdirPrefix(self): |
|
621 | def testVisitdirM2SubdirPrefix(self): | |
622 | m1 = matchmod.alwaysmatcher() |
|
622 | m1 = matchmod.alwaysmatcher() | |
623 | m2 = matchmod.match(b'', b'', patterns=[b'path:dir/subdir']) |
|
623 | m2 = matchmod.match(b'', b'', patterns=[b'path:dir/subdir']) | |
624 | um = matchmod.unionmatcher([m1, m2]) |
|
624 | um = matchmod.unionmatcher([m1, m2]) | |
625 | self.assertEqual(um.visitdir(b''), b'all') |
|
625 | self.assertEqual(um.visitdir(b''), b'all') | |
626 | self.assertEqual(um.visitdir(b'dir'), b'all') |
|
626 | self.assertEqual(um.visitdir(b'dir'), b'all') | |
627 | self.assertEqual(um.visitdir(b'dir/subdir'), b'all') |
|
627 | self.assertEqual(um.visitdir(b'dir/subdir'), b'all') | |
628 | self.assertEqual(um.visitdir(b'dir/foo'), b'all') |
|
628 | self.assertEqual(um.visitdir(b'dir/foo'), b'all') | |
629 | self.assertEqual(um.visitdir(b'folder'), b'all') |
|
629 | self.assertEqual(um.visitdir(b'folder'), b'all') | |
630 | self.assertEqual(um.visitdir(b'dir/subdir/z'), b'all') |
|
630 | self.assertEqual(um.visitdir(b'dir/subdir/z'), b'all') | |
631 | self.assertEqual(um.visitdir(b'dir/subdir/x'), b'all') |
|
631 | self.assertEqual(um.visitdir(b'dir/subdir/x'), b'all') | |
632 |
|
632 | |||
633 | def testVisitchildrensetM2SubdirPrefix(self): |
|
633 | def testVisitchildrensetM2SubdirPrefix(self): | |
634 | m1 = matchmod.alwaysmatcher() |
|
634 | m1 = matchmod.alwaysmatcher() | |
635 | m2 = matchmod.match(b'', b'', include=[b'path:dir/subdir']) |
|
635 | m2 = matchmod.match(b'', b'', include=[b'path:dir/subdir']) | |
636 | um = matchmod.unionmatcher([m1, m2]) |
|
636 | um = matchmod.unionmatcher([m1, m2]) | |
637 | self.assertEqual(um.visitchildrenset(b''), b'all') |
|
637 | self.assertEqual(um.visitchildrenset(b''), b'all') | |
638 | self.assertEqual(um.visitchildrenset(b'dir'), b'all') |
|
638 | self.assertEqual(um.visitchildrenset(b'dir'), b'all') | |
639 | self.assertEqual(um.visitchildrenset(b'dir/subdir'), b'all') |
|
639 | self.assertEqual(um.visitchildrenset(b'dir/subdir'), b'all') | |
640 | self.assertEqual(um.visitchildrenset(b'dir/foo'), b'all') |
|
640 | self.assertEqual(um.visitchildrenset(b'dir/foo'), b'all') | |
641 | self.assertEqual(um.visitchildrenset(b'folder'), b'all') |
|
641 | self.assertEqual(um.visitchildrenset(b'folder'), b'all') | |
642 | self.assertEqual(um.visitchildrenset(b'dir/subdir/z'), b'all') |
|
642 | self.assertEqual(um.visitchildrenset(b'dir/subdir/z'), b'all') | |
643 | self.assertEqual(um.visitchildrenset(b'dir/subdir/x'), b'all') |
|
643 | self.assertEqual(um.visitchildrenset(b'dir/subdir/x'), b'all') | |
644 |
|
644 | |||
645 | # We're using includematcher instead of patterns because it behaves slightly |
|
645 | # We're using includematcher instead of patterns because it behaves slightly | |
646 | # better (giving narrower results) than patternmatcher. |
|
646 | # better (giving narrower results) than patternmatcher. | |
647 |
def testVisitdirIncludeInclud |
|
647 | def testVisitdirIncludeInclude(self): | |
648 | m1 = matchmod.match(b'', b'', include=[b'path:dir/subdir']) |
|
648 | m1 = matchmod.match(b'', b'', include=[b'path:dir/subdir']) | |
649 | m2 = matchmod.match(b'', b'', include=[b'rootfilesin:dir']) |
|
649 | m2 = matchmod.match(b'', b'', include=[b'rootfilesin:dir']) | |
650 | um = matchmod.unionmatcher([m1, m2]) |
|
650 | um = matchmod.unionmatcher([m1, m2]) | |
651 | self.assertEqual(um.visitdir(b''), True) |
|
651 | self.assertEqual(um.visitdir(b''), True) | |
652 | self.assertEqual(um.visitdir(b'dir'), True) |
|
652 | self.assertEqual(um.visitdir(b'dir'), True) | |
653 | self.assertEqual(um.visitdir(b'dir/subdir'), b'all') |
|
653 | self.assertEqual(um.visitdir(b'dir/subdir'), b'all') | |
654 | self.assertFalse(um.visitdir(b'dir/foo')) |
|
654 | self.assertFalse(um.visitdir(b'dir/foo')) | |
655 | self.assertFalse(um.visitdir(b'folder')) |
|
655 | self.assertFalse(um.visitdir(b'folder')) | |
656 | # OPT: These two should probably be 'all' not True. |
|
656 | # OPT: These two should probably be 'all' not True. | |
657 | self.assertEqual(um.visitdir(b'dir/subdir/z'), True) |
|
657 | self.assertEqual(um.visitdir(b'dir/subdir/z'), True) | |
658 | self.assertEqual(um.visitdir(b'dir/subdir/x'), True) |
|
658 | self.assertEqual(um.visitdir(b'dir/subdir/x'), True) | |
659 |
|
659 | |||
660 | def testVisitchildrensetIncludeInclude(self): |
|
660 | def testVisitchildrensetIncludeInclude(self): | |
661 | m1 = matchmod.match(b'', b'', include=[b'path:dir/subdir']) |
|
661 | m1 = matchmod.match(b'', b'', include=[b'path:dir/subdir']) | |
662 | m2 = matchmod.match(b'', b'', include=[b'rootfilesin:dir']) |
|
662 | m2 = matchmod.match(b'', b'', include=[b'rootfilesin:dir']) | |
663 | um = matchmod.unionmatcher([m1, m2]) |
|
663 | um = matchmod.unionmatcher([m1, m2]) | |
664 | self.assertEqual(um.visitchildrenset(b''), {b'dir'}) |
|
664 | self.assertEqual(um.visitchildrenset(b''), {b'dir'}) | |
665 | self.assertEqual(um.visitchildrenset(b'dir'), b'this') |
|
665 | self.assertEqual(um.visitchildrenset(b'dir'), b'this') | |
666 | self.assertEqual(um.visitchildrenset(b'dir/subdir'), b'all') |
|
666 | self.assertEqual(um.visitchildrenset(b'dir/subdir'), b'all') | |
667 | self.assertEqual(um.visitchildrenset(b'dir/foo'), set()) |
|
667 | self.assertEqual(um.visitchildrenset(b'dir/foo'), set()) | |
668 | self.assertEqual(um.visitchildrenset(b'folder'), set()) |
|
668 | self.assertEqual(um.visitchildrenset(b'folder'), set()) | |
669 | # OPT: These next two could be 'all' instead of 'this'. |
|
669 | # OPT: These next two could be 'all' instead of 'this'. | |
670 | self.assertEqual(um.visitchildrenset(b'dir/subdir/z'), b'this') |
|
670 | self.assertEqual(um.visitchildrenset(b'dir/subdir/z'), b'this') | |
671 | self.assertEqual(um.visitchildrenset(b'dir/subdir/x'), b'this') |
|
671 | self.assertEqual(um.visitchildrenset(b'dir/subdir/x'), b'this') | |
672 |
|
672 | |||
673 | # We're using includematcher instead of patterns because it behaves slightly |
|
673 | # We're using includematcher instead of patterns because it behaves slightly | |
674 | # better (giving narrower results) than patternmatcher. |
|
674 | # better (giving narrower results) than patternmatcher. | |
675 | def testVisitdirIncludeInclude2(self): |
|
675 | def testVisitdirIncludeInclude2(self): | |
676 | m1 = matchmod.match(b'', b'', include=[b'path:dir/subdir']) |
|
676 | m1 = matchmod.match(b'', b'', include=[b'path:dir/subdir']) | |
677 | m2 = matchmod.match(b'', b'', include=[b'path:folder']) |
|
677 | m2 = matchmod.match(b'', b'', include=[b'path:folder']) | |
678 | um = matchmod.unionmatcher([m1, m2]) |
|
678 | um = matchmod.unionmatcher([m1, m2]) | |
679 | self.assertEqual(um.visitdir(b''), True) |
|
679 | self.assertEqual(um.visitdir(b''), True) | |
680 | self.assertEqual(um.visitdir(b'dir'), True) |
|
680 | self.assertEqual(um.visitdir(b'dir'), True) | |
681 | self.assertEqual(um.visitdir(b'dir/subdir'), b'all') |
|
681 | self.assertEqual(um.visitdir(b'dir/subdir'), b'all') | |
682 | self.assertFalse(um.visitdir(b'dir/foo')) |
|
682 | self.assertFalse(um.visitdir(b'dir/foo')) | |
683 | self.assertEqual(um.visitdir(b'folder'), b'all') |
|
683 | self.assertEqual(um.visitdir(b'folder'), b'all') | |
684 | # OPT: These should probably be 'all' not True. |
|
684 | # OPT: These should probably be 'all' not True. | |
685 | self.assertEqual(um.visitdir(b'dir/subdir/z'), True) |
|
685 | self.assertEqual(um.visitdir(b'dir/subdir/z'), True) | |
686 | self.assertEqual(um.visitdir(b'dir/subdir/x'), True) |
|
686 | self.assertEqual(um.visitdir(b'dir/subdir/x'), True) | |
687 |
|
687 | |||
688 | def testVisitchildrensetIncludeInclude2(self): |
|
688 | def testVisitchildrensetIncludeInclude2(self): | |
689 | m1 = matchmod.match(b'', b'', include=[b'path:dir/subdir']) |
|
689 | m1 = matchmod.match(b'', b'', include=[b'path:dir/subdir']) | |
690 | m2 = matchmod.match(b'', b'', include=[b'path:folder']) |
|
690 | m2 = matchmod.match(b'', b'', include=[b'path:folder']) | |
691 | um = matchmod.unionmatcher([m1, m2]) |
|
691 | um = matchmod.unionmatcher([m1, m2]) | |
692 | self.assertEqual(um.visitchildrenset(b''), {b'folder', b'dir'}) |
|
692 | self.assertEqual(um.visitchildrenset(b''), {b'folder', b'dir'}) | |
693 | self.assertEqual(um.visitchildrenset(b'dir'), {b'subdir'}) |
|
693 | self.assertEqual(um.visitchildrenset(b'dir'), {b'subdir'}) | |
694 | self.assertEqual(um.visitchildrenset(b'dir/subdir'), b'all') |
|
694 | self.assertEqual(um.visitchildrenset(b'dir/subdir'), b'all') | |
695 | self.assertEqual(um.visitchildrenset(b'dir/foo'), set()) |
|
695 | self.assertEqual(um.visitchildrenset(b'dir/foo'), set()) | |
696 | self.assertEqual(um.visitchildrenset(b'folder'), b'all') |
|
696 | self.assertEqual(um.visitchildrenset(b'folder'), b'all') | |
697 | # OPT: These next two could be 'all' instead of 'this'. |
|
697 | # OPT: These next two could be 'all' instead of 'this'. | |
698 | self.assertEqual(um.visitchildrenset(b'dir/subdir/z'), b'this') |
|
698 | self.assertEqual(um.visitchildrenset(b'dir/subdir/z'), b'this') | |
699 | self.assertEqual(um.visitchildrenset(b'dir/subdir/x'), b'this') |
|
699 | self.assertEqual(um.visitchildrenset(b'dir/subdir/x'), b'this') | |
700 |
|
700 | |||
701 | # We're using includematcher instead of patterns because it behaves slightly |
|
701 | # We're using includematcher instead of patterns because it behaves slightly | |
702 | # better (giving narrower results) than patternmatcher. |
|
702 | # better (giving narrower results) than patternmatcher. | |
703 | def testVisitdirIncludeInclude3(self): |
|
703 | def testVisitdirIncludeInclude3(self): | |
704 | m1 = matchmod.match(b'', b'', include=[b'path:dir/subdir/x']) |
|
704 | m1 = matchmod.match(b'', b'', include=[b'path:dir/subdir/x']) | |
705 | m2 = matchmod.match(b'', b'', include=[b'path:dir/subdir']) |
|
705 | m2 = matchmod.match(b'', b'', include=[b'path:dir/subdir']) | |
706 | um = matchmod.unionmatcher([m1, m2]) |
|
706 | um = matchmod.unionmatcher([m1, m2]) | |
707 | self.assertEqual(um.visitdir(b''), True) |
|
707 | self.assertEqual(um.visitdir(b''), True) | |
708 | self.assertEqual(um.visitdir(b'dir'), True) |
|
708 | self.assertEqual(um.visitdir(b'dir'), True) | |
709 | self.assertEqual(um.visitdir(b'dir/subdir'), b'all') |
|
709 | self.assertEqual(um.visitdir(b'dir/subdir'), b'all') | |
710 | self.assertFalse(um.visitdir(b'dir/foo')) |
|
710 | self.assertFalse(um.visitdir(b'dir/foo')) | |
711 | self.assertFalse(um.visitdir(b'folder')) |
|
711 | self.assertFalse(um.visitdir(b'folder')) | |
712 | self.assertEqual(um.visitdir(b'dir/subdir/x'), b'all') |
|
712 | self.assertEqual(um.visitdir(b'dir/subdir/x'), b'all') | |
713 | # OPT: this should probably be 'all' not True. |
|
713 | # OPT: this should probably be 'all' not True. | |
714 | self.assertEqual(um.visitdir(b'dir/subdir/z'), True) |
|
714 | self.assertEqual(um.visitdir(b'dir/subdir/z'), True) | |
715 |
|
715 | |||
716 | def testVisitchildrensetIncludeInclude3(self): |
|
716 | def testVisitchildrensetIncludeInclude3(self): | |
717 | m1 = matchmod.match(b'', b'', include=[b'path:dir/subdir/x']) |
|
717 | m1 = matchmod.match(b'', b'', include=[b'path:dir/subdir/x']) | |
718 | m2 = matchmod.match(b'', b'', include=[b'path:dir/subdir']) |
|
718 | m2 = matchmod.match(b'', b'', include=[b'path:dir/subdir']) | |
719 | um = matchmod.unionmatcher([m1, m2]) |
|
719 | um = matchmod.unionmatcher([m1, m2]) | |
720 | self.assertEqual(um.visitchildrenset(b''), {b'dir'}) |
|
720 | self.assertEqual(um.visitchildrenset(b''), {b'dir'}) | |
721 | self.assertEqual(um.visitchildrenset(b'dir'), {b'subdir'}) |
|
721 | self.assertEqual(um.visitchildrenset(b'dir'), {b'subdir'}) | |
722 | self.assertEqual(um.visitchildrenset(b'dir/subdir'), b'all') |
|
722 | self.assertEqual(um.visitchildrenset(b'dir/subdir'), b'all') | |
723 | self.assertEqual(um.visitchildrenset(b'dir/foo'), set()) |
|
723 | self.assertEqual(um.visitchildrenset(b'dir/foo'), set()) | |
724 | self.assertEqual(um.visitchildrenset(b'folder'), set()) |
|
724 | self.assertEqual(um.visitchildrenset(b'folder'), set()) | |
725 | self.assertEqual(um.visitchildrenset(b'dir/subdir/x'), b'all') |
|
725 | self.assertEqual(um.visitchildrenset(b'dir/subdir/x'), b'all') | |
726 | # OPT: this should probably be 'all' not 'this'. |
|
726 | # OPT: this should probably be 'all' not 'this'. | |
727 | self.assertEqual(um.visitchildrenset(b'dir/subdir/z'), b'this') |
|
727 | self.assertEqual(um.visitchildrenset(b'dir/subdir/z'), b'this') | |
728 |
|
728 | |||
729 | # We're using includematcher instead of patterns because it behaves slightly |
|
729 | # We're using includematcher instead of patterns because it behaves slightly | |
730 | # better (giving narrower results) than patternmatcher. |
|
730 | # better (giving narrower results) than patternmatcher. | |
731 | def testVisitdirIncludeInclude4(self): |
|
731 | def testVisitdirIncludeInclude4(self): | |
732 | m1 = matchmod.match(b'', b'', include=[b'path:dir/subdir/x']) |
|
732 | m1 = matchmod.match(b'', b'', include=[b'path:dir/subdir/x']) | |
733 | m2 = matchmod.match(b'', b'', include=[b'path:dir/subdir/z']) |
|
733 | m2 = matchmod.match(b'', b'', include=[b'path:dir/subdir/z']) | |
734 | um = matchmod.unionmatcher([m1, m2]) |
|
734 | um = matchmod.unionmatcher([m1, m2]) | |
735 | # OPT: these next three could probably be False as well. |
|
735 | # OPT: these next three could probably be False as well. | |
736 | self.assertEqual(um.visitdir(b''), True) |
|
736 | self.assertEqual(um.visitdir(b''), True) | |
737 | self.assertEqual(um.visitdir(b'dir'), True) |
|
737 | self.assertEqual(um.visitdir(b'dir'), True) | |
738 | self.assertEqual(um.visitdir(b'dir/subdir'), True) |
|
738 | self.assertEqual(um.visitdir(b'dir/subdir'), True) | |
739 | self.assertFalse(um.visitdir(b'dir/foo')) |
|
739 | self.assertFalse(um.visitdir(b'dir/foo')) | |
740 | self.assertFalse(um.visitdir(b'folder')) |
|
740 | self.assertFalse(um.visitdir(b'folder')) | |
741 | self.assertEqual(um.visitdir(b'dir/subdir/z'), b'all') |
|
741 | self.assertEqual(um.visitdir(b'dir/subdir/z'), b'all') | |
742 | self.assertEqual(um.visitdir(b'dir/subdir/x'), b'all') |
|
742 | self.assertEqual(um.visitdir(b'dir/subdir/x'), b'all') | |
743 |
|
743 | |||
744 | def testVisitchildrensetIncludeInclude4(self): |
|
744 | def testVisitchildrensetIncludeInclude4(self): | |
745 | m1 = matchmod.match(b'', b'', include=[b'path:dir/subdir/x']) |
|
745 | m1 = matchmod.match(b'', b'', include=[b'path:dir/subdir/x']) | |
746 | m2 = matchmod.match(b'', b'', include=[b'path:dir/subdir/z']) |
|
746 | m2 = matchmod.match(b'', b'', include=[b'path:dir/subdir/z']) | |
747 | um = matchmod.unionmatcher([m1, m2]) |
|
747 | um = matchmod.unionmatcher([m1, m2]) | |
748 | self.assertEqual(um.visitchildrenset(b''), {b'dir'}) |
|
748 | self.assertEqual(um.visitchildrenset(b''), {b'dir'}) | |
749 | self.assertEqual(um.visitchildrenset(b'dir'), {b'subdir'}) |
|
749 | self.assertEqual(um.visitchildrenset(b'dir'), {b'subdir'}) | |
750 | self.assertEqual(um.visitchildrenset(b'dir/subdir'), {b'x', b'z'}) |
|
750 | self.assertEqual(um.visitchildrenset(b'dir/subdir'), {b'x', b'z'}) | |
751 | self.assertEqual(um.visitchildrenset(b'dir/foo'), set()) |
|
751 | self.assertEqual(um.visitchildrenset(b'dir/foo'), set()) | |
752 | self.assertEqual(um.visitchildrenset(b'folder'), set()) |
|
752 | self.assertEqual(um.visitchildrenset(b'folder'), set()) | |
753 | self.assertEqual(um.visitchildrenset(b'dir/subdir/z'), b'all') |
|
753 | self.assertEqual(um.visitchildrenset(b'dir/subdir/z'), b'all') | |
754 | self.assertEqual(um.visitchildrenset(b'dir/subdir/x'), b'all') |
|
754 | self.assertEqual(um.visitchildrenset(b'dir/subdir/x'), b'all') | |
755 |
|
755 | |||
756 |
|
756 | |||
757 | class SubdirMatcherTests(unittest.TestCase): |
|
757 | class SubdirMatcherTests(unittest.TestCase): | |
758 | def testVisitdir(self): |
|
758 | def testVisitdir(self): | |
759 | m = matchmod.match(b'', b'', include=[b'path:dir/subdir']) |
|
759 | m = matchmod.match(b'', b'', include=[b'path:dir/subdir']) | |
760 | sm = matchmod.subdirmatcher(b'dir', m) |
|
760 | sm = matchmod.subdirmatcher(b'dir', m) | |
761 |
|
761 | |||
762 | self.assertEqual(sm.visitdir(b''), True) |
|
762 | self.assertEqual(sm.visitdir(b''), True) | |
763 | self.assertEqual(sm.visitdir(b'subdir'), b'all') |
|
763 | self.assertEqual(sm.visitdir(b'subdir'), b'all') | |
764 | # OPT: These next two should probably be 'all' not True. |
|
764 | # OPT: These next two should probably be 'all' not True. | |
765 | self.assertEqual(sm.visitdir(b'subdir/x'), True) |
|
765 | self.assertEqual(sm.visitdir(b'subdir/x'), True) | |
766 | self.assertEqual(sm.visitdir(b'subdir/z'), True) |
|
766 | self.assertEqual(sm.visitdir(b'subdir/z'), True) | |
767 | self.assertFalse(sm.visitdir(b'foo')) |
|
767 | self.assertFalse(sm.visitdir(b'foo')) | |
768 |
|
768 | |||
769 | def testVisitchildrenset(self): |
|
769 | def testVisitchildrenset(self): | |
770 | m = matchmod.match(b'', b'', include=[b'path:dir/subdir']) |
|
770 | m = matchmod.match(b'', b'', include=[b'path:dir/subdir']) | |
771 | sm = matchmod.subdirmatcher(b'dir', m) |
|
771 | sm = matchmod.subdirmatcher(b'dir', m) | |
772 |
|
772 | |||
773 | self.assertEqual(sm.visitchildrenset(b''), {b'subdir'}) |
|
773 | self.assertEqual(sm.visitchildrenset(b''), {b'subdir'}) | |
774 | self.assertEqual(sm.visitchildrenset(b'subdir'), b'all') |
|
774 | self.assertEqual(sm.visitchildrenset(b'subdir'), b'all') | |
775 | # OPT: These next two should probably be 'all' not 'this'. |
|
775 | # OPT: These next two should probably be 'all' not 'this'. | |
776 | self.assertEqual(sm.visitchildrenset(b'subdir/x'), b'this') |
|
776 | self.assertEqual(sm.visitchildrenset(b'subdir/x'), b'this') | |
777 | self.assertEqual(sm.visitchildrenset(b'subdir/z'), b'this') |
|
777 | self.assertEqual(sm.visitchildrenset(b'subdir/z'), b'this') | |
778 | self.assertEqual(sm.visitchildrenset(b'foo'), set()) |
|
778 | self.assertEqual(sm.visitchildrenset(b'foo'), set()) | |
779 |
|
779 | |||
780 |
|
780 | |||
781 | class PrefixdirMatcherTests(unittest.TestCase): |
|
781 | class PrefixdirMatcherTests(unittest.TestCase): | |
782 | def testVisitdir(self): |
|
782 | def testVisitdir(self): | |
783 | m = matchmod.match( |
|
783 | m = matchmod.match( | |
784 | util.localpath(b'root/d'), b'e/f', [b'../a.txt', b'b.txt'] |
|
784 | util.localpath(b'root/d'), b'e/f', [b'../a.txt', b'b.txt'] | |
785 | ) |
|
785 | ) | |
786 | pm = matchmod.prefixdirmatcher(b'd', m) |
|
786 | pm = matchmod.prefixdirmatcher(b'd', m) | |
787 |
|
787 | |||
788 | # `m` elides 'd' because it's part of the root, and the rest of the |
|
788 | # `m` elides 'd' because it's part of the root, and the rest of the | |
789 | # patterns are relative. |
|
789 | # patterns are relative. | |
790 | self.assertEqual(bool(m(b'a.txt')), False) |
|
790 | self.assertEqual(bool(m(b'a.txt')), False) | |
791 | self.assertEqual(bool(m(b'b.txt')), False) |
|
791 | self.assertEqual(bool(m(b'b.txt')), False) | |
792 | self.assertEqual(bool(m(b'e/a.txt')), True) |
|
792 | self.assertEqual(bool(m(b'e/a.txt')), True) | |
793 | self.assertEqual(bool(m(b'e/b.txt')), False) |
|
793 | self.assertEqual(bool(m(b'e/b.txt')), False) | |
794 | self.assertEqual(bool(m(b'e/f/b.txt')), True) |
|
794 | self.assertEqual(bool(m(b'e/f/b.txt')), True) | |
795 |
|
795 | |||
796 | # The prefix matcher re-adds 'd' to the paths, so they need to be |
|
796 | # The prefix matcher re-adds 'd' to the paths, so they need to be | |
797 | # specified when using the prefixdirmatcher. |
|
797 | # specified when using the prefixdirmatcher. | |
798 | self.assertEqual(bool(pm(b'a.txt')), False) |
|
798 | self.assertEqual(bool(pm(b'a.txt')), False) | |
799 | self.assertEqual(bool(pm(b'b.txt')), False) |
|
799 | self.assertEqual(bool(pm(b'b.txt')), False) | |
800 | self.assertEqual(bool(pm(b'd/e/a.txt')), True) |
|
800 | self.assertEqual(bool(pm(b'd/e/a.txt')), True) | |
801 | self.assertEqual(bool(pm(b'd/e/b.txt')), False) |
|
801 | self.assertEqual(bool(pm(b'd/e/b.txt')), False) | |
802 | self.assertEqual(bool(pm(b'd/e/f/b.txt')), True) |
|
802 | self.assertEqual(bool(pm(b'd/e/f/b.txt')), True) | |
803 |
|
803 | |||
804 | self.assertEqual(m.visitdir(b''), True) |
|
804 | self.assertEqual(m.visitdir(b''), True) | |
805 | self.assertEqual(m.visitdir(b'e'), True) |
|
805 | self.assertEqual(m.visitdir(b'e'), True) | |
806 | self.assertEqual(m.visitdir(b'e/f'), True) |
|
806 | self.assertEqual(m.visitdir(b'e/f'), True) | |
807 | self.assertEqual(m.visitdir(b'e/f/g'), False) |
|
807 | self.assertEqual(m.visitdir(b'e/f/g'), False) | |
808 |
|
808 | |||
809 | self.assertEqual(pm.visitdir(b''), True) |
|
809 | self.assertEqual(pm.visitdir(b''), True) | |
810 | self.assertEqual(pm.visitdir(b'd'), True) |
|
810 | self.assertEqual(pm.visitdir(b'd'), True) | |
811 | self.assertEqual(pm.visitdir(b'd/e'), True) |
|
811 | self.assertEqual(pm.visitdir(b'd/e'), True) | |
812 | self.assertEqual(pm.visitdir(b'd/e/f'), True) |
|
812 | self.assertEqual(pm.visitdir(b'd/e/f'), True) | |
813 | self.assertEqual(pm.visitdir(b'd/e/f/g'), False) |
|
813 | self.assertEqual(pm.visitdir(b'd/e/f/g'), False) | |
814 |
|
814 | |||
815 | def testVisitchildrenset(self): |
|
815 | def testVisitchildrenset(self): | |
816 | m = matchmod.match( |
|
816 | m = matchmod.match( | |
817 | util.localpath(b'root/d'), b'e/f', [b'../a.txt', b'b.txt'] |
|
817 | util.localpath(b'root/d'), b'e/f', [b'../a.txt', b'b.txt'] | |
818 | ) |
|
818 | ) | |
819 | pm = matchmod.prefixdirmatcher(b'd', m) |
|
819 | pm = matchmod.prefixdirmatcher(b'd', m) | |
820 |
|
820 | |||
821 | # OPT: visitchildrenset could possibly return {'e'} and {'f'} for these |
|
821 | # OPT: visitchildrenset could possibly return {'e'} and {'f'} for these | |
822 | # next two, respectively; patternmatcher does not have this |
|
822 | # next two, respectively; patternmatcher does not have this | |
823 | # optimization. |
|
823 | # optimization. | |
824 | self.assertEqual(m.visitchildrenset(b''), b'this') |
|
824 | self.assertEqual(m.visitchildrenset(b''), b'this') | |
825 | self.assertEqual(m.visitchildrenset(b'e'), b'this') |
|
825 | self.assertEqual(m.visitchildrenset(b'e'), b'this') | |
826 | self.assertEqual(m.visitchildrenset(b'e/f'), b'this') |
|
826 | self.assertEqual(m.visitchildrenset(b'e/f'), b'this') | |
827 | self.assertEqual(m.visitchildrenset(b'e/f/g'), set()) |
|
827 | self.assertEqual(m.visitchildrenset(b'e/f/g'), set()) | |
828 |
|
828 | |||
829 | # OPT: visitchildrenset could possibly return {'d'}, {'e'}, and {'f'} |
|
829 | # OPT: visitchildrenset could possibly return {'d'}, {'e'}, and {'f'} | |
830 | # for these next three, respectively; patternmatcher does not have this |
|
830 | # for these next three, respectively; patternmatcher does not have this | |
831 | # optimization. |
|
831 | # optimization. | |
832 | self.assertEqual(pm.visitchildrenset(b''), b'this') |
|
832 | self.assertEqual(pm.visitchildrenset(b''), b'this') | |
833 | self.assertEqual(pm.visitchildrenset(b'd'), b'this') |
|
833 | self.assertEqual(pm.visitchildrenset(b'd'), b'this') | |
834 | self.assertEqual(pm.visitchildrenset(b'd/e'), b'this') |
|
834 | self.assertEqual(pm.visitchildrenset(b'd/e'), b'this') | |
835 | self.assertEqual(pm.visitchildrenset(b'd/e/f'), b'this') |
|
835 | self.assertEqual(pm.visitchildrenset(b'd/e/f'), b'this') | |
836 | self.assertEqual(pm.visitchildrenset(b'd/e/f/g'), set()) |
|
836 | self.assertEqual(pm.visitchildrenset(b'd/e/f/g'), set()) | |
837 |
|
837 | |||
838 |
|
838 | |||
839 | if __name__ == '__main__': |
|
839 | if __name__ == '__main__': | |
840 | silenttestrunner.main(__name__) |
|
840 | silenttestrunner.main(__name__) |
General Comments 0
You need to be logged in to leave comments.
Login now