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