Mercurial > hg
comparison tests/test-match.py @ 41675:ddbebce94665
match: delete unused root and cwd arguments to constructors (API)
Most matchers no longer need the root and cwd
arguments. patternmatcher and includematcher still need the root
argument for subincludes.
Differential Revision: https://phab.mercurial-scm.org/D5929
author | Martin von Zweigbergk <martinvonz@google.com> |
---|---|
date | Sun, 10 Feb 2019 14:35:36 -0800 |
parents | 0dc3ed4e712c |
children | 0531dff73d0b |
comparison
equal
deleted
inserted
replaced
41674:e178b131906a | 41675:ddbebce94665 |
---|---|
10 ) | 10 ) |
11 | 11 |
12 class BaseMatcherTests(unittest.TestCase): | 12 class BaseMatcherTests(unittest.TestCase): |
13 | 13 |
14 def testVisitdir(self): | 14 def testVisitdir(self): |
15 m = matchmod.basematcher(b'', b'') | 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(b'', b'') | 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 class AlwaysMatcherTests(unittest.TestCase): | 24 class AlwaysMatcherTests(unittest.TestCase): |
25 | 25 |
26 def testVisitdir(self): | 26 def testVisitdir(self): |
27 m = matchmod.alwaysmatcher(b'', b'') | 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(b'', b'') | 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 class NeverMatcherTests(unittest.TestCase): | 36 class NeverMatcherTests(unittest.TestCase): |
37 | 37 |
38 def testVisitdir(self): | 38 def testVisitdir(self): |
39 m = matchmod.nevermatcher(b'', b'') | 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(b'', b'') | 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 class PredicateMatcherTests(unittest.TestCase): | 48 class PredicateMatcherTests(unittest.TestCase): |
49 # predicatematcher does not currently define either of these methods, so | 49 # predicatematcher does not currently define either of these methods, so |
50 # this is equivalent to BaseMatcherTests. | 50 # this is equivalent to BaseMatcherTests. |
51 | 51 |
52 def testVisitdir(self): | 52 def testVisitdir(self): |
53 m = matchmod.predicatematcher(b'', b'', lambda *a: False) | 53 m = matchmod.predicatematcher(lambda *a: False) |
54 self.assertTrue(m.visitdir(b'.')) | 54 self.assertTrue(m.visitdir(b'.')) |
55 self.assertTrue(m.visitdir(b'dir')) | 55 self.assertTrue(m.visitdir(b'dir')) |
56 | 56 |
57 def testVisitchildrenset(self): | 57 def testVisitchildrenset(self): |
58 m = matchmod.predicatematcher(b'', b'', lambda *a: False) | 58 m = matchmod.predicatematcher(lambda *a: False) |
59 self.assertEqual(m.visitchildrenset(b'.'), b'this') | 59 self.assertEqual(m.visitchildrenset(b'.'), b'this') |
60 self.assertEqual(m.visitchildrenset(b'dir'), b'this') | 60 self.assertEqual(m.visitchildrenset(b'dir'), b'this') |
61 | 61 |
62 class PatternMatcherTests(unittest.TestCase): | 62 class PatternMatcherTests(unittest.TestCase): |
63 | 63 |
221 self.assertEqual(m.visitchildrenset(b'folder'), set()) | 221 self.assertEqual(m.visitchildrenset(b'folder'), set()) |
222 | 222 |
223 class DifferenceMatcherTests(unittest.TestCase): | 223 class DifferenceMatcherTests(unittest.TestCase): |
224 | 224 |
225 def testVisitdirM2always(self): | 225 def testVisitdirM2always(self): |
226 m1 = matchmod.alwaysmatcher(b'', b'') | 226 m1 = matchmod.alwaysmatcher() |
227 m2 = matchmod.alwaysmatcher(b'', b'') | 227 m2 = matchmod.alwaysmatcher() |
228 dm = matchmod.differencematcher(m1, m2) | 228 dm = matchmod.differencematcher(m1, m2) |
229 # dm should be equivalent to a nevermatcher. | 229 # dm should be equivalent to a nevermatcher. |
230 self.assertFalse(dm.visitdir(b'.')) | 230 self.assertFalse(dm.visitdir(b'.')) |
231 self.assertFalse(dm.visitdir(b'dir')) | 231 self.assertFalse(dm.visitdir(b'dir')) |
232 self.assertFalse(dm.visitdir(b'dir/subdir')) | 232 self.assertFalse(dm.visitdir(b'dir/subdir')) |
234 self.assertFalse(dm.visitdir(b'dir/foo')) | 234 self.assertFalse(dm.visitdir(b'dir/foo')) |
235 self.assertFalse(dm.visitdir(b'dir/subdir/x')) | 235 self.assertFalse(dm.visitdir(b'dir/subdir/x')) |
236 self.assertFalse(dm.visitdir(b'folder')) | 236 self.assertFalse(dm.visitdir(b'folder')) |
237 | 237 |
238 def testVisitchildrensetM2always(self): | 238 def testVisitchildrensetM2always(self): |
239 m1 = matchmod.alwaysmatcher(b'', b'') | 239 m1 = matchmod.alwaysmatcher() |
240 m2 = matchmod.alwaysmatcher(b'', b'') | 240 m2 = matchmod.alwaysmatcher() |
241 dm = matchmod.differencematcher(m1, m2) | 241 dm = matchmod.differencematcher(m1, m2) |
242 # dm should be equivalent to a nevermatcher. | 242 # dm should be equivalent to a nevermatcher. |
243 self.assertEqual(dm.visitchildrenset(b'.'), set()) | 243 self.assertEqual(dm.visitchildrenset(b'.'), set()) |
244 self.assertEqual(dm.visitchildrenset(b'dir'), set()) | 244 self.assertEqual(dm.visitchildrenset(b'dir'), set()) |
245 self.assertEqual(dm.visitchildrenset(b'dir/subdir'), set()) | 245 self.assertEqual(dm.visitchildrenset(b'dir/subdir'), set()) |
247 self.assertEqual(dm.visitchildrenset(b'dir/foo'), set()) | 247 self.assertEqual(dm.visitchildrenset(b'dir/foo'), set()) |
248 self.assertEqual(dm.visitchildrenset(b'dir/subdir/x'), set()) | 248 self.assertEqual(dm.visitchildrenset(b'dir/subdir/x'), set()) |
249 self.assertEqual(dm.visitchildrenset(b'folder'), set()) | 249 self.assertEqual(dm.visitchildrenset(b'folder'), set()) |
250 | 250 |
251 def testVisitdirM2never(self): | 251 def testVisitdirM2never(self): |
252 m1 = matchmod.alwaysmatcher(b'', b'') | 252 m1 = matchmod.alwaysmatcher() |
253 m2 = matchmod.nevermatcher(b'', b'') | 253 m2 = matchmod.nevermatcher() |
254 dm = matchmod.differencematcher(m1, m2) | 254 dm = matchmod.differencematcher(m1, m2) |
255 # dm should be equivalent to a alwaysmatcher. | 255 # dm should be equivalent to a alwaysmatcher. |
256 # | 256 # |
257 # We're testing Equal-to-True instead of just 'assertTrue' since | 257 # We're testing Equal-to-True instead of just 'assertTrue' since |
258 # assertTrue does NOT verify that it's a bool, just that it's truthy. | 258 # assertTrue does NOT verify that it's a bool, just that it's truthy. |
265 self.assertEqual(dm.visitdir(b'dir/foo'), b'all') | 265 self.assertEqual(dm.visitdir(b'dir/foo'), b'all') |
266 self.assertEqual(dm.visitdir(b'dir/subdir/x'), b'all') | 266 self.assertEqual(dm.visitdir(b'dir/subdir/x'), b'all') |
267 self.assertEqual(dm.visitdir(b'folder'), b'all') | 267 self.assertEqual(dm.visitdir(b'folder'), b'all') |
268 | 268 |
269 def testVisitchildrensetM2never(self): | 269 def testVisitchildrensetM2never(self): |
270 m1 = matchmod.alwaysmatcher(b'', b'') | 270 m1 = matchmod.alwaysmatcher() |
271 m2 = matchmod.nevermatcher(b'', b'') | 271 m2 = matchmod.nevermatcher() |
272 dm = matchmod.differencematcher(m1, m2) | 272 dm = matchmod.differencematcher(m1, m2) |
273 # dm should be equivalent to a alwaysmatcher. | 273 # dm should be equivalent to a alwaysmatcher. |
274 self.assertEqual(dm.visitchildrenset(b'.'), b'all') | 274 self.assertEqual(dm.visitchildrenset(b'.'), b'all') |
275 self.assertEqual(dm.visitchildrenset(b'dir'), b'all') | 275 self.assertEqual(dm.visitchildrenset(b'dir'), b'all') |
276 self.assertEqual(dm.visitchildrenset(b'dir/subdir'), b'all') | 276 self.assertEqual(dm.visitchildrenset(b'dir/subdir'), b'all') |
278 self.assertEqual(dm.visitchildrenset(b'dir/foo'), b'all') | 278 self.assertEqual(dm.visitchildrenset(b'dir/foo'), b'all') |
279 self.assertEqual(dm.visitchildrenset(b'dir/subdir/x'), b'all') | 279 self.assertEqual(dm.visitchildrenset(b'dir/subdir/x'), b'all') |
280 self.assertEqual(dm.visitchildrenset(b'folder'), b'all') | 280 self.assertEqual(dm.visitchildrenset(b'folder'), b'all') |
281 | 281 |
282 def testVisitdirM2SubdirPrefix(self): | 282 def testVisitdirM2SubdirPrefix(self): |
283 m1 = matchmod.alwaysmatcher(b'', b'') | 283 m1 = matchmod.alwaysmatcher() |
284 m2 = matchmod.match(b'', b'', patterns=[b'path:dir/subdir']) | 284 m2 = matchmod.match(b'', b'', patterns=[b'path:dir/subdir']) |
285 dm = matchmod.differencematcher(m1, m2) | 285 dm = matchmod.differencematcher(m1, m2) |
286 self.assertEqual(dm.visitdir(b'.'), True) | 286 self.assertEqual(dm.visitdir(b'.'), True) |
287 self.assertEqual(dm.visitdir(b'dir'), True) | 287 self.assertEqual(dm.visitdir(b'dir'), True) |
288 self.assertFalse(dm.visitdir(b'dir/subdir')) | 288 self.assertFalse(dm.visitdir(b'dir/subdir')) |
293 self.assertEqual(dm.visitdir(b'dir/subdir/x'), True) | 293 self.assertEqual(dm.visitdir(b'dir/subdir/x'), True) |
294 self.assertEqual(dm.visitdir(b'dir/foo'), b'all') | 294 self.assertEqual(dm.visitdir(b'dir/foo'), b'all') |
295 self.assertEqual(dm.visitdir(b'folder'), b'all') | 295 self.assertEqual(dm.visitdir(b'folder'), b'all') |
296 | 296 |
297 def testVisitchildrensetM2SubdirPrefix(self): | 297 def testVisitchildrensetM2SubdirPrefix(self): |
298 m1 = matchmod.alwaysmatcher(b'', b'') | 298 m1 = matchmod.alwaysmatcher() |
299 m2 = matchmod.match(b'', b'', patterns=[b'path:dir/subdir']) | 299 m2 = matchmod.match(b'', b'', patterns=[b'path:dir/subdir']) |
300 dm = matchmod.differencematcher(m1, m2) | 300 dm = matchmod.differencematcher(m1, m2) |
301 self.assertEqual(dm.visitchildrenset(b'.'), b'this') | 301 self.assertEqual(dm.visitchildrenset(b'.'), b'this') |
302 self.assertEqual(dm.visitchildrenset(b'dir'), b'this') | 302 self.assertEqual(dm.visitchildrenset(b'dir'), b'this') |
303 self.assertEqual(dm.visitchildrenset(b'dir/subdir'), set()) | 303 self.assertEqual(dm.visitchildrenset(b'dir/subdir'), set()) |
342 self.assertEqual(dm.visitchildrenset(b'dir/subdir/x'), b'this') | 342 self.assertEqual(dm.visitchildrenset(b'dir/subdir/x'), b'this') |
343 | 343 |
344 class IntersectionMatcherTests(unittest.TestCase): | 344 class IntersectionMatcherTests(unittest.TestCase): |
345 | 345 |
346 def testVisitdirM2always(self): | 346 def testVisitdirM2always(self): |
347 m1 = matchmod.alwaysmatcher(b'', b'') | 347 m1 = matchmod.alwaysmatcher() |
348 m2 = matchmod.alwaysmatcher(b'', b'') | 348 m2 = matchmod.alwaysmatcher() |
349 im = matchmod.intersectmatchers(m1, m2) | 349 im = matchmod.intersectmatchers(m1, m2) |
350 # im should be equivalent to a alwaysmatcher. | 350 # im should be equivalent to a alwaysmatcher. |
351 self.assertEqual(im.visitdir(b'.'), b'all') | 351 self.assertEqual(im.visitdir(b'.'), b'all') |
352 self.assertEqual(im.visitdir(b'dir'), b'all') | 352 self.assertEqual(im.visitdir(b'dir'), b'all') |
353 self.assertEqual(im.visitdir(b'dir/subdir'), b'all') | 353 self.assertEqual(im.visitdir(b'dir/subdir'), b'all') |
355 self.assertEqual(im.visitdir(b'dir/foo'), b'all') | 355 self.assertEqual(im.visitdir(b'dir/foo'), b'all') |
356 self.assertEqual(im.visitdir(b'dir/subdir/x'), b'all') | 356 self.assertEqual(im.visitdir(b'dir/subdir/x'), b'all') |
357 self.assertEqual(im.visitdir(b'folder'), b'all') | 357 self.assertEqual(im.visitdir(b'folder'), b'all') |
358 | 358 |
359 def testVisitchildrensetM2always(self): | 359 def testVisitchildrensetM2always(self): |
360 m1 = matchmod.alwaysmatcher(b'', b'') | 360 m1 = matchmod.alwaysmatcher() |
361 m2 = matchmod.alwaysmatcher(b'', b'') | 361 m2 = matchmod.alwaysmatcher() |
362 im = matchmod.intersectmatchers(m1, m2) | 362 im = matchmod.intersectmatchers(m1, m2) |
363 # im should be equivalent to a alwaysmatcher. | 363 # im should be equivalent to a alwaysmatcher. |
364 self.assertEqual(im.visitchildrenset(b'.'), b'all') | 364 self.assertEqual(im.visitchildrenset(b'.'), b'all') |
365 self.assertEqual(im.visitchildrenset(b'dir'), b'all') | 365 self.assertEqual(im.visitchildrenset(b'dir'), b'all') |
366 self.assertEqual(im.visitchildrenset(b'dir/subdir'), b'all') | 366 self.assertEqual(im.visitchildrenset(b'dir/subdir'), b'all') |
368 self.assertEqual(im.visitchildrenset(b'dir/foo'), b'all') | 368 self.assertEqual(im.visitchildrenset(b'dir/foo'), b'all') |
369 self.assertEqual(im.visitchildrenset(b'dir/subdir/x'), b'all') | 369 self.assertEqual(im.visitchildrenset(b'dir/subdir/x'), b'all') |
370 self.assertEqual(im.visitchildrenset(b'folder'), b'all') | 370 self.assertEqual(im.visitchildrenset(b'folder'), b'all') |
371 | 371 |
372 def testVisitdirM2never(self): | 372 def testVisitdirM2never(self): |
373 m1 = matchmod.alwaysmatcher(b'', b'') | 373 m1 = matchmod.alwaysmatcher() |
374 m2 = matchmod.nevermatcher(b'', b'') | 374 m2 = matchmod.nevermatcher() |
375 im = matchmod.intersectmatchers(m1, m2) | 375 im = matchmod.intersectmatchers(m1, m2) |
376 # im should be equivalent to a nevermatcher. | 376 # im should be equivalent to a nevermatcher. |
377 self.assertFalse(im.visitdir(b'.')) | 377 self.assertFalse(im.visitdir(b'.')) |
378 self.assertFalse(im.visitdir(b'dir')) | 378 self.assertFalse(im.visitdir(b'dir')) |
379 self.assertFalse(im.visitdir(b'dir/subdir')) | 379 self.assertFalse(im.visitdir(b'dir/subdir')) |
381 self.assertFalse(im.visitdir(b'dir/foo')) | 381 self.assertFalse(im.visitdir(b'dir/foo')) |
382 self.assertFalse(im.visitdir(b'dir/subdir/x')) | 382 self.assertFalse(im.visitdir(b'dir/subdir/x')) |
383 self.assertFalse(im.visitdir(b'folder')) | 383 self.assertFalse(im.visitdir(b'folder')) |
384 | 384 |
385 def testVisitchildrensetM2never(self): | 385 def testVisitchildrensetM2never(self): |
386 m1 = matchmod.alwaysmatcher(b'', b'') | 386 m1 = matchmod.alwaysmatcher() |
387 m2 = matchmod.nevermatcher(b'', b'') | 387 m2 = matchmod.nevermatcher() |
388 im = matchmod.intersectmatchers(m1, m2) | 388 im = matchmod.intersectmatchers(m1, m2) |
389 # im should be equivalent to a nevermqtcher. | 389 # im should be equivalent to a nevermqtcher. |
390 self.assertEqual(im.visitchildrenset(b'.'), set()) | 390 self.assertEqual(im.visitchildrenset(b'.'), set()) |
391 self.assertEqual(im.visitchildrenset(b'dir'), set()) | 391 self.assertEqual(im.visitchildrenset(b'dir'), set()) |
392 self.assertEqual(im.visitchildrenset(b'dir/subdir'), set()) | 392 self.assertEqual(im.visitchildrenset(b'dir/subdir'), set()) |
394 self.assertEqual(im.visitchildrenset(b'dir/foo'), set()) | 394 self.assertEqual(im.visitchildrenset(b'dir/foo'), set()) |
395 self.assertEqual(im.visitchildrenset(b'dir/subdir/x'), set()) | 395 self.assertEqual(im.visitchildrenset(b'dir/subdir/x'), set()) |
396 self.assertEqual(im.visitchildrenset(b'folder'), set()) | 396 self.assertEqual(im.visitchildrenset(b'folder'), set()) |
397 | 397 |
398 def testVisitdirM2SubdirPrefix(self): | 398 def testVisitdirM2SubdirPrefix(self): |
399 m1 = matchmod.alwaysmatcher(b'', b'') | 399 m1 = matchmod.alwaysmatcher() |
400 m2 = matchmod.match(b'', b'', patterns=[b'path:dir/subdir']) | 400 m2 = matchmod.match(b'', b'', patterns=[b'path:dir/subdir']) |
401 im = matchmod.intersectmatchers(m1, m2) | 401 im = matchmod.intersectmatchers(m1, m2) |
402 self.assertEqual(im.visitdir(b'.'), True) | 402 self.assertEqual(im.visitdir(b'.'), True) |
403 self.assertEqual(im.visitdir(b'dir'), True) | 403 self.assertEqual(im.visitdir(b'dir'), True) |
404 self.assertEqual(im.visitdir(b'dir/subdir'), b'all') | 404 self.assertEqual(im.visitdir(b'dir/subdir'), b'all') |
409 # an 'all' pattern, just True. | 409 # an 'all' pattern, just True. |
410 self.assertEqual(im.visitdir(b'dir/subdir/z'), True) | 410 self.assertEqual(im.visitdir(b'dir/subdir/z'), True) |
411 self.assertEqual(im.visitdir(b'dir/subdir/x'), True) | 411 self.assertEqual(im.visitdir(b'dir/subdir/x'), True) |
412 | 412 |
413 def testVisitchildrensetM2SubdirPrefix(self): | 413 def testVisitchildrensetM2SubdirPrefix(self): |
414 m1 = matchmod.alwaysmatcher(b'', b'') | 414 m1 = matchmod.alwaysmatcher() |
415 m2 = matchmod.match(b'', b'', include=[b'path:dir/subdir']) | 415 m2 = matchmod.match(b'', b'', include=[b'path:dir/subdir']) |
416 im = matchmod.intersectmatchers(m1, m2) | 416 im = matchmod.intersectmatchers(m1, m2) |
417 self.assertEqual(im.visitchildrenset(b'.'), {b'dir'}) | 417 self.assertEqual(im.visitchildrenset(b'.'), {b'dir'}) |
418 self.assertEqual(im.visitchildrenset(b'dir'), {b'subdir'}) | 418 self.assertEqual(im.visitchildrenset(b'dir'), {b'subdir'}) |
419 self.assertEqual(im.visitchildrenset(b'dir/subdir'), b'all') | 419 self.assertEqual(im.visitchildrenset(b'dir/subdir'), b'all') |
534 self.assertEqual(im.visitchildrenset(b'dir/subdir/x'), set()) | 534 self.assertEqual(im.visitchildrenset(b'dir/subdir/x'), set()) |
535 | 535 |
536 class UnionMatcherTests(unittest.TestCase): | 536 class UnionMatcherTests(unittest.TestCase): |
537 | 537 |
538 def testVisitdirM2always(self): | 538 def testVisitdirM2always(self): |
539 m1 = matchmod.alwaysmatcher(b'', b'') | 539 m1 = matchmod.alwaysmatcher() |
540 m2 = matchmod.alwaysmatcher(b'', b'') | 540 m2 = matchmod.alwaysmatcher() |
541 um = matchmod.unionmatcher([m1, m2]) | 541 um = matchmod.unionmatcher([m1, m2]) |
542 # um should be equivalent to a alwaysmatcher. | 542 # um should be equivalent to a alwaysmatcher. |
543 self.assertEqual(um.visitdir(b'.'), b'all') | 543 self.assertEqual(um.visitdir(b'.'), b'all') |
544 self.assertEqual(um.visitdir(b'dir'), b'all') | 544 self.assertEqual(um.visitdir(b'dir'), b'all') |
545 self.assertEqual(um.visitdir(b'dir/subdir'), b'all') | 545 self.assertEqual(um.visitdir(b'dir/subdir'), b'all') |
547 self.assertEqual(um.visitdir(b'dir/foo'), b'all') | 547 self.assertEqual(um.visitdir(b'dir/foo'), b'all') |
548 self.assertEqual(um.visitdir(b'dir/subdir/x'), b'all') | 548 self.assertEqual(um.visitdir(b'dir/subdir/x'), b'all') |
549 self.assertEqual(um.visitdir(b'folder'), b'all') | 549 self.assertEqual(um.visitdir(b'folder'), b'all') |
550 | 550 |
551 def testVisitchildrensetM2always(self): | 551 def testVisitchildrensetM2always(self): |
552 m1 = matchmod.alwaysmatcher(b'', b'') | 552 m1 = matchmod.alwaysmatcher() |
553 m2 = matchmod.alwaysmatcher(b'', b'') | 553 m2 = matchmod.alwaysmatcher() |
554 um = matchmod.unionmatcher([m1, m2]) | 554 um = matchmod.unionmatcher([m1, m2]) |
555 # um should be equivalent to a alwaysmatcher. | 555 # um should be equivalent to a alwaysmatcher. |
556 self.assertEqual(um.visitchildrenset(b'.'), b'all') | 556 self.assertEqual(um.visitchildrenset(b'.'), b'all') |
557 self.assertEqual(um.visitchildrenset(b'dir'), b'all') | 557 self.assertEqual(um.visitchildrenset(b'dir'), b'all') |
558 self.assertEqual(um.visitchildrenset(b'dir/subdir'), b'all') | 558 self.assertEqual(um.visitchildrenset(b'dir/subdir'), b'all') |
560 self.assertEqual(um.visitchildrenset(b'dir/foo'), b'all') | 560 self.assertEqual(um.visitchildrenset(b'dir/foo'), b'all') |
561 self.assertEqual(um.visitchildrenset(b'dir/subdir/x'), b'all') | 561 self.assertEqual(um.visitchildrenset(b'dir/subdir/x'), b'all') |
562 self.assertEqual(um.visitchildrenset(b'folder'), b'all') | 562 self.assertEqual(um.visitchildrenset(b'folder'), b'all') |
563 | 563 |
564 def testVisitdirM1never(self): | 564 def testVisitdirM1never(self): |
565 m1 = matchmod.nevermatcher(b'', b'') | 565 m1 = matchmod.nevermatcher() |
566 m2 = matchmod.alwaysmatcher(b'', b'') | 566 m2 = matchmod.alwaysmatcher() |
567 um = matchmod.unionmatcher([m1, m2]) | 567 um = matchmod.unionmatcher([m1, m2]) |
568 # um should be equivalent to a alwaysmatcher. | 568 # um should be equivalent to a alwaysmatcher. |
569 self.assertEqual(um.visitdir(b'.'), b'all') | 569 self.assertEqual(um.visitdir(b'.'), b'all') |
570 self.assertEqual(um.visitdir(b'dir'), b'all') | 570 self.assertEqual(um.visitdir(b'dir'), b'all') |
571 self.assertEqual(um.visitdir(b'dir/subdir'), b'all') | 571 self.assertEqual(um.visitdir(b'dir/subdir'), b'all') |
573 self.assertEqual(um.visitdir(b'dir/foo'), b'all') | 573 self.assertEqual(um.visitdir(b'dir/foo'), b'all') |
574 self.assertEqual(um.visitdir(b'dir/subdir/x'), b'all') | 574 self.assertEqual(um.visitdir(b'dir/subdir/x'), b'all') |
575 self.assertEqual(um.visitdir(b'folder'), b'all') | 575 self.assertEqual(um.visitdir(b'folder'), b'all') |
576 | 576 |
577 def testVisitchildrensetM1never(self): | 577 def testVisitchildrensetM1never(self): |
578 m1 = matchmod.nevermatcher(b'', b'') | 578 m1 = matchmod.nevermatcher() |
579 m2 = matchmod.alwaysmatcher(b'', b'') | 579 m2 = matchmod.alwaysmatcher() |
580 um = matchmod.unionmatcher([m1, m2]) | 580 um = matchmod.unionmatcher([m1, m2]) |
581 # um should be equivalent to a alwaysmatcher. | 581 # um should be equivalent to a alwaysmatcher. |
582 self.assertEqual(um.visitchildrenset(b'.'), b'all') | 582 self.assertEqual(um.visitchildrenset(b'.'), b'all') |
583 self.assertEqual(um.visitchildrenset(b'dir'), b'all') | 583 self.assertEqual(um.visitchildrenset(b'dir'), b'all') |
584 self.assertEqual(um.visitchildrenset(b'dir/subdir'), b'all') | 584 self.assertEqual(um.visitchildrenset(b'dir/subdir'), b'all') |
586 self.assertEqual(um.visitchildrenset(b'dir/foo'), b'all') | 586 self.assertEqual(um.visitchildrenset(b'dir/foo'), b'all') |
587 self.assertEqual(um.visitchildrenset(b'dir/subdir/x'), b'all') | 587 self.assertEqual(um.visitchildrenset(b'dir/subdir/x'), b'all') |
588 self.assertEqual(um.visitchildrenset(b'folder'), b'all') | 588 self.assertEqual(um.visitchildrenset(b'folder'), b'all') |
589 | 589 |
590 def testVisitdirM2never(self): | 590 def testVisitdirM2never(self): |
591 m1 = matchmod.alwaysmatcher(b'', b'') | 591 m1 = matchmod.alwaysmatcher() |
592 m2 = matchmod.nevermatcher(b'', b'') | 592 m2 = matchmod.nevermatcher() |
593 um = matchmod.unionmatcher([m1, m2]) | 593 um = matchmod.unionmatcher([m1, m2]) |
594 # um should be equivalent to a alwaysmatcher. | 594 # um should be equivalent to a alwaysmatcher. |
595 self.assertEqual(um.visitdir(b'.'), b'all') | 595 self.assertEqual(um.visitdir(b'.'), b'all') |
596 self.assertEqual(um.visitdir(b'dir'), b'all') | 596 self.assertEqual(um.visitdir(b'dir'), b'all') |
597 self.assertEqual(um.visitdir(b'dir/subdir'), b'all') | 597 self.assertEqual(um.visitdir(b'dir/subdir'), b'all') |
599 self.assertEqual(um.visitdir(b'dir/foo'), b'all') | 599 self.assertEqual(um.visitdir(b'dir/foo'), b'all') |
600 self.assertEqual(um.visitdir(b'dir/subdir/x'), b'all') | 600 self.assertEqual(um.visitdir(b'dir/subdir/x'), b'all') |
601 self.assertEqual(um.visitdir(b'folder'), b'all') | 601 self.assertEqual(um.visitdir(b'folder'), b'all') |
602 | 602 |
603 def testVisitchildrensetM2never(self): | 603 def testVisitchildrensetM2never(self): |
604 m1 = matchmod.alwaysmatcher(b'', b'') | 604 m1 = matchmod.alwaysmatcher() |
605 m2 = matchmod.nevermatcher(b'', b'') | 605 m2 = matchmod.nevermatcher() |
606 um = matchmod.unionmatcher([m1, m2]) | 606 um = matchmod.unionmatcher([m1, m2]) |
607 # um should be equivalent to a alwaysmatcher. | 607 # um should be equivalent to a alwaysmatcher. |
608 self.assertEqual(um.visitchildrenset(b'.'), b'all') | 608 self.assertEqual(um.visitchildrenset(b'.'), b'all') |
609 self.assertEqual(um.visitchildrenset(b'dir'), b'all') | 609 self.assertEqual(um.visitchildrenset(b'dir'), b'all') |
610 self.assertEqual(um.visitchildrenset(b'dir/subdir'), b'all') | 610 self.assertEqual(um.visitchildrenset(b'dir/subdir'), b'all') |
612 self.assertEqual(um.visitchildrenset(b'dir/foo'), b'all') | 612 self.assertEqual(um.visitchildrenset(b'dir/foo'), b'all') |
613 self.assertEqual(um.visitchildrenset(b'dir/subdir/x'), b'all') | 613 self.assertEqual(um.visitchildrenset(b'dir/subdir/x'), b'all') |
614 self.assertEqual(um.visitchildrenset(b'folder'), b'all') | 614 self.assertEqual(um.visitchildrenset(b'folder'), b'all') |
615 | 615 |
616 def testVisitdirM2SubdirPrefix(self): | 616 def testVisitdirM2SubdirPrefix(self): |
617 m1 = matchmod.alwaysmatcher(b'', b'') | 617 m1 = matchmod.alwaysmatcher() |
618 m2 = matchmod.match(b'', b'', patterns=[b'path:dir/subdir']) | 618 m2 = matchmod.match(b'', b'', patterns=[b'path:dir/subdir']) |
619 um = matchmod.unionmatcher([m1, m2]) | 619 um = matchmod.unionmatcher([m1, m2]) |
620 self.assertEqual(um.visitdir(b'.'), b'all') | 620 self.assertEqual(um.visitdir(b'.'), b'all') |
621 self.assertEqual(um.visitdir(b'dir'), b'all') | 621 self.assertEqual(um.visitdir(b'dir'), b'all') |
622 self.assertEqual(um.visitdir(b'dir/subdir'), b'all') | 622 self.assertEqual(um.visitdir(b'dir/subdir'), b'all') |
624 self.assertEqual(um.visitdir(b'folder'), b'all') | 624 self.assertEqual(um.visitdir(b'folder'), b'all') |
625 self.assertEqual(um.visitdir(b'dir/subdir/z'), b'all') | 625 self.assertEqual(um.visitdir(b'dir/subdir/z'), b'all') |
626 self.assertEqual(um.visitdir(b'dir/subdir/x'), b'all') | 626 self.assertEqual(um.visitdir(b'dir/subdir/x'), b'all') |
627 | 627 |
628 def testVisitchildrensetM2SubdirPrefix(self): | 628 def testVisitchildrensetM2SubdirPrefix(self): |
629 m1 = matchmod.alwaysmatcher(b'', b'') | 629 m1 = matchmod.alwaysmatcher() |
630 m2 = matchmod.match(b'', b'', include=[b'path:dir/subdir']) | 630 m2 = matchmod.match(b'', b'', include=[b'path:dir/subdir']) |
631 um = matchmod.unionmatcher([m1, m2]) | 631 um = matchmod.unionmatcher([m1, m2]) |
632 self.assertEqual(um.visitchildrenset(b'.'), b'all') | 632 self.assertEqual(um.visitchildrenset(b'.'), b'all') |
633 self.assertEqual(um.visitchildrenset(b'dir'), b'all') | 633 self.assertEqual(um.visitchildrenset(b'dir'), b'all') |
634 self.assertEqual(um.visitchildrenset(b'dir/subdir'), b'all') | 634 self.assertEqual(um.visitchildrenset(b'dir/subdir'), b'all') |
775 class PrefixdirMatcherTests(unittest.TestCase): | 775 class PrefixdirMatcherTests(unittest.TestCase): |
776 | 776 |
777 def testVisitdir(self): | 777 def testVisitdir(self): |
778 m = matchmod.match(util.localpath(b'root/d'), b'e/f', | 778 m = matchmod.match(util.localpath(b'root/d'), b'e/f', |
779 [b'../a.txt', b'b.txt']) | 779 [b'../a.txt', b'b.txt']) |
780 pm = matchmod.prefixdirmatcher(b'root', b'd/e/f', b'd', m) | 780 pm = matchmod.prefixdirmatcher(b'd', m) |
781 | 781 |
782 # `m` elides 'd' because it's part of the root, and the rest of the | 782 # `m` elides 'd' because it's part of the root, and the rest of the |
783 # patterns are relative. | 783 # patterns are relative. |
784 self.assertEqual(bool(m(b'a.txt')), False) | 784 self.assertEqual(bool(m(b'a.txt')), False) |
785 self.assertEqual(bool(m(b'b.txt')), False) | 785 self.assertEqual(bool(m(b'b.txt')), False) |
807 self.assertEqual(pm.visitdir(b'd/e/f/g'), False) | 807 self.assertEqual(pm.visitdir(b'd/e/f/g'), False) |
808 | 808 |
809 def testVisitchildrenset(self): | 809 def testVisitchildrenset(self): |
810 m = matchmod.match(util.localpath(b'root/d'), b'e/f', | 810 m = matchmod.match(util.localpath(b'root/d'), b'e/f', |
811 [b'../a.txt', b'b.txt']) | 811 [b'../a.txt', b'b.txt']) |
812 pm = matchmod.prefixdirmatcher(b'root', b'd/e/f', b'd', m) | 812 pm = matchmod.prefixdirmatcher(b'd', m) |
813 | 813 |
814 # OPT: visitchildrenset could possibly return {'e'} and {'f'} for these | 814 # OPT: visitchildrenset could possibly return {'e'} and {'f'} for these |
815 # next two, respectively; patternmatcher does not have this | 815 # next two, respectively; patternmatcher does not have this |
816 # optimization. | 816 # optimization. |
817 self.assertEqual(m.visitchildrenset(b'.'), b'this') | 817 self.assertEqual(m.visitchildrenset(b'.'), b'this') |