Show More
@@ -8,6 +8,7 b'' | |||
|
8 | 8 | from __future__ import absolute_import, print_function |
|
9 | 9 | |
|
10 | 10 | import copy |
|
11 | import itertools | |
|
11 | 12 | import os |
|
12 | 13 | import re |
|
13 | 14 | |
@@ -331,6 +332,38 b' class basematcher(object):' | |||
|
331 | 332 | ''' |
|
332 | 333 | return True |
|
333 | 334 | |
|
335 | def visitchildrenset(self, dir): | |
|
336 | '''Decides whether a directory should be visited based on whether it | |
|
337 | has potential matches in it or one of its subdirectories, and | |
|
338 | potentially lists which subdirectories of that directory should be | |
|
339 | visited. This is based on the match's primary, included, and excluded | |
|
340 | patterns. | |
|
341 | ||
|
342 | This function is very similar to 'visitdir', and the following mapping | |
|
343 | can be applied: | |
|
344 | ||
|
345 | visitdir | visitchildrenlist | |
|
346 | ----------+------------------- | |
|
347 | False | set() | |
|
348 | 'all' | 'all' | |
|
349 | True | 'this' OR non-empty set of subdirs to visit | |
|
350 | ||
|
351 | Example: | |
|
352 | Assume matchers ['path:foo/bar', 'rootfilesin:qux'], we would return | |
|
353 | the following values (assuming the implementation of visitchildrenset | |
|
354 | is capable of recognizing this; some implementations are not). | |
|
355 | ||
|
356 | '.' -> {'foo', 'qux'} | |
|
357 | 'baz' -> set() | |
|
358 | 'foo' -> {'bar'} | |
|
359 | # Ideally this would be 'all', but since the prefix nature of matchers | |
|
360 | # is applied to the entire matcher, we have to downgrade to this | |
|
361 | # 'this' due to the non-prefix 'rootfilesin'-kind matcher. | |
|
362 | 'foo/bar' -> 'this' | |
|
363 | 'qux' -> 'this' | |
|
364 | ''' | |
|
365 | return 'this' | |
|
366 | ||
|
334 | 367 | def always(self): |
|
335 | 368 | '''Matcher will match everything and .files() will be empty -- |
|
336 | 369 | optimization might be possible.''' |
@@ -367,6 +400,9 b' class alwaysmatcher(basematcher):' | |||
|
367 | 400 | def visitdir(self, dir): |
|
368 | 401 | return 'all' |
|
369 | 402 | |
|
403 | def visitchildrenset(self, dir): | |
|
404 | return 'all' | |
|
405 | ||
|
370 | 406 | def __repr__(self): |
|
371 | 407 | return r'<alwaysmatcher>' |
|
372 | 408 | |
@@ -390,6 +426,9 b' class nevermatcher(basematcher):' | |||
|
390 | 426 | def visitdir(self, dir): |
|
391 | 427 | return False |
|
392 | 428 | |
|
429 | def visitchildrenset(self, dir): | |
|
430 | return set() | |
|
431 | ||
|
393 | 432 | def __repr__(self): |
|
394 | 433 | return r'<nevermatcher>' |
|
395 | 434 | |
@@ -430,6 +469,15 b' class patternmatcher(basematcher):' | |||
|
430 | 469 | any(parentdir in self._fileset |
|
431 | 470 | for parentdir in util.finddirs(dir))) |
|
432 | 471 | |
|
472 | def visitchildrenset(self, dir): | |
|
473 | ret = self.visitdir(dir) | |
|
474 | if ret is True: | |
|
475 | return 'this' | |
|
476 | elif not ret: | |
|
477 | return set() | |
|
478 | assert ret == 'all' | |
|
479 | return 'all' | |
|
480 | ||
|
433 | 481 | def prefix(self): |
|
434 | 482 | return self._prefix |
|
435 | 483 | |
@@ -464,6 +512,43 b' class includematcher(basematcher):' | |||
|
464 | 512 | any(parentdir in self._roots |
|
465 | 513 | for parentdir in util.finddirs(dir))) |
|
466 | 514 | |
|
515 | def visitchildrenset(self, dir): | |
|
516 | if self._prefix and dir in self._roots: | |
|
517 | return 'all' | |
|
518 | # Note: this does *not* include the 'dir in self._parents' case from | |
|
519 | # visitdir, that's handled below. | |
|
520 | if ('.' in self._roots or | |
|
521 | dir in self._roots or | |
|
522 | dir in self._dirs or | |
|
523 | any(parentdir in self._roots | |
|
524 | for parentdir in util.finddirs(dir))): | |
|
525 | return 'this' | |
|
526 | ||
|
527 | ret = set() | |
|
528 | if dir in self._parents: | |
|
529 | # We add a '/' on to `dir` so that we don't return items that are | |
|
530 | # prefixed by `dir` but are actually siblings of `dir`. | |
|
531 | suffixeddir = dir + '/' if dir != '.' else '' | |
|
532 | # Look in all _roots, _dirs, and _parents for things that start with | |
|
533 | # 'suffixeddir'. | |
|
534 | for d in [q for q in | |
|
535 | itertools.chain(self._roots, self._dirs, self._parents) if | |
|
536 | q.startswith(suffixeddir)]: | |
|
537 | # Don't emit '.' in the response for the root directory | |
|
538 | if not suffixeddir and d == '.': | |
|
539 | continue | |
|
540 | ||
|
541 | # We return the item name without the `suffixeddir` prefix or a | |
|
542 | # slash suffix | |
|
543 | d = d[len(suffixeddir):] | |
|
544 | if '/' in d: | |
|
545 | # This is a subdirectory-of-a-subdirectory, i.e. | |
|
546 | # suffixeddir='foo/', d was 'foo/bar/baz' before removing | |
|
547 | # 'foo/'. | |
|
548 | d = d[:d.index('/')] | |
|
549 | ret.add(d) | |
|
550 | return ret | |
|
551 | ||
|
467 | 552 | @encoding.strmethod |
|
468 | 553 | def __repr__(self): |
|
469 | 554 | return ('<includematcher includes=%r>' % pycompat.bytestr(self._pats)) |
@@ -490,6 +575,25 b' class exactmatcher(basematcher):' | |||
|
490 | 575 | def visitdir(self, dir): |
|
491 | 576 | return dir in self._dirs |
|
492 | 577 | |
|
578 | def visitchildrenset(self, dir): | |
|
579 | if dir in self._dirs: | |
|
580 | candidates = self._dirs - {'.'} | |
|
581 | if dir != '.': | |
|
582 | d = dir + '/' | |
|
583 | candidates = set(c[len(d):] for c in candidates if | |
|
584 | c.startswith(d)) | |
|
585 | # self._dirs includes all of the directories, recursively, so if | |
|
586 | # we're attempting to match foo/bar/baz.txt, it'll have '.', 'foo', | |
|
587 | # 'foo/bar' in it. Thus we can safely ignore a candidate that has a | |
|
588 | # '/' in it, indicating a it's for a subdir-of-a-subdir; the | |
|
589 | # immediate subdir will be in there without a slash. | |
|
590 | ret = set(c for c in candidates if '/' not in c) | |
|
591 | # We need to emit 'this' for foo/bar, not set(), not {'baz.txt'}. | |
|
592 | if not ret: | |
|
593 | return 'this' | |
|
594 | return ret | |
|
595 | return set() | |
|
596 | ||
|
493 | 597 | def isexact(self): |
|
494 | 598 | return True |
|
495 | 599 | |
@@ -531,6 +635,31 b' class differencematcher(basematcher):' | |||
|
531 | 635 | return False |
|
532 | 636 | return bool(self._m1.visitdir(dir)) |
|
533 | 637 | |
|
638 | def visitchildrenset(self, dir): | |
|
639 | m2_set = self._m2.visitchildrenset(dir) | |
|
640 | if m2_set == 'all': | |
|
641 | return set() | |
|
642 | m1_set = self._m1.visitchildrenset(dir) | |
|
643 | # Possible values for m1: 'all', 'this', set(...), set() | |
|
644 | # Possible values for m2: 'this', set(...), set() | |
|
645 | # If m2 has nothing under here that we care about, return m1, even if | |
|
646 | # it's 'all'. This is a change in behavior from visitdir, which would | |
|
647 | # return True, not 'all', for some reason. | |
|
648 | if not m2_set: | |
|
649 | return m1_set | |
|
650 | if m1_set in ['all', 'this']: | |
|
651 | # Never return 'all' here if m2_set is any kind of non-empty (either | |
|
652 | # 'this' or set(foo)), since m2 might return set() for a | |
|
653 | # subdirectory. | |
|
654 | return 'this' | |
|
655 | # Possible values for m1: set(...), set() | |
|
656 | # Possible values for m2: 'this', set(...) | |
|
657 | # We ignore m2's set results. They're possibly incorrect: | |
|
658 | # m1 = path:dir/subdir, m2=rootfilesin:dir, visitchildrenset('.'): | |
|
659 | # m1 returns {'dir'}, m2 returns {'dir'}, if we subtracted we'd | |
|
660 | # return set(), which is *not* correct, we still need to visit 'dir'! | |
|
661 | return m1_set | |
|
662 | ||
|
534 | 663 | def isexact(self): |
|
535 | 664 | return self._m1.isexact() |
|
536 | 665 | |
@@ -595,6 +724,25 b' class intersectionmatcher(basematcher):' | |||
|
595 | 724 | # bool() because visit1=True + visit2='all' should not be 'all' |
|
596 | 725 | return bool(visit1 and self._m2.visitdir(dir)) |
|
597 | 726 | |
|
727 | def visitchildrenset(self, dir): | |
|
728 | m1_set = self._m1.visitchildrenset(dir) | |
|
729 | if not m1_set: | |
|
730 | return set() | |
|
731 | m2_set = self._m2.visitchildrenset(dir) | |
|
732 | if not m2_set: | |
|
733 | return set() | |
|
734 | ||
|
735 | if m1_set == 'all': | |
|
736 | return m2_set | |
|
737 | elif m2_set == 'all': | |
|
738 | return m1_set | |
|
739 | ||
|
740 | if m1_set == 'this' or m2_set == 'this': | |
|
741 | return 'this' | |
|
742 | ||
|
743 | assert isinstance(m1_set, set) and isinstance(m2_set, set) | |
|
744 | return m1_set.intersection(m2_set) | |
|
745 | ||
|
598 | 746 | def always(self): |
|
599 | 747 | return self._m1.always() and self._m2.always() |
|
600 | 748 | |
@@ -676,6 +824,13 b' class subdirmatcher(basematcher):' | |||
|
676 | 824 | dir = self._path + "/" + dir |
|
677 | 825 | return self._matcher.visitdir(dir) |
|
678 | 826 | |
|
827 | def visitchildrenset(self, dir): | |
|
828 | if dir == '.': | |
|
829 | dir = self._path | |
|
830 | else: | |
|
831 | dir = self._path + "/" + dir | |
|
832 | return self._matcher.visitchildrenset(dir) | |
|
833 | ||
|
679 | 834 | def always(self): |
|
680 | 835 | return self._always |
|
681 | 836 | |
@@ -748,6 +903,14 b' class prefixdirmatcher(basematcher):' | |||
|
748 | 903 | return self._matcher.visitdir(dir[len(self._pathprefix):]) |
|
749 | 904 | return dir in self._pathdirs |
|
750 | 905 | |
|
906 | def visitchildrenset(self, dir): | |
|
907 | if dir == self._path: | |
|
908 | return self._matcher.visitchildrenset('.') | |
|
909 | if dir.startswith(self._pathprefix): | |
|
910 | return self._matcher.visitchildrenset(dir[len(self._pathprefix):]) | |
|
911 | if dir in self._pathdirs: | |
|
912 | return 'this' | |
|
913 | ||
|
751 | 914 | def isexact(self): |
|
752 | 915 | return self._matcher.isexact() |
|
753 | 916 | |
@@ -788,6 +951,25 b' class unionmatcher(basematcher):' | |||
|
788 | 951 | r |= v |
|
789 | 952 | return r |
|
790 | 953 | |
|
954 | def visitchildrenset(self, dir): | |
|
955 | r = set() | |
|
956 | this = False | |
|
957 | for m in self._matchers: | |
|
958 | v = m.visitchildrenset(dir) | |
|
959 | if not v: | |
|
960 | continue | |
|
961 | if v == 'all': | |
|
962 | return v | |
|
963 | if this or v == 'this': | |
|
964 | this = True | |
|
965 | # don't break, we might have an 'all' in here. | |
|
966 | continue | |
|
967 | assert isinstance(v, set) | |
|
968 | r = r.union(v) | |
|
969 | if this: | |
|
970 | return 'this' | |
|
971 | return r | |
|
972 | ||
|
791 | 973 | @encoding.strmethod |
|
792 | 974 | def __repr__(self): |
|
793 | 975 | return ('<unionmatcher matchers=%r>' % self._matchers) |
@@ -16,6 +16,11 b' class BaseMatcherTests(unittest.TestCase' | |||
|
16 | 16 | self.assertTrue(m.visitdir('.')) |
|
17 | 17 | self.assertTrue(m.visitdir('dir')) |
|
18 | 18 | |
|
19 | def testVisitchildrenset(self): | |
|
20 | m = matchmod.basematcher('', '') | |
|
21 | self.assertEqual(m.visitchildrenset('.'), 'this') | |
|
22 | self.assertEqual(m.visitchildrenset('dir'), 'this') | |
|
23 | ||
|
19 | 24 | class AlwaysMatcherTests(unittest.TestCase): |
|
20 | 25 | |
|
21 | 26 | def testVisitdir(self): |
@@ -23,6 +28,11 b' class AlwaysMatcherTests(unittest.TestCa' | |||
|
23 | 28 | self.assertEqual(m.visitdir('.'), 'all') |
|
24 | 29 | self.assertEqual(m.visitdir('dir'), 'all') |
|
25 | 30 | |
|
31 | def testVisitchildrenset(self): | |
|
32 | m = matchmod.alwaysmatcher('', '') | |
|
33 | self.assertEqual(m.visitchildrenset('.'), 'all') | |
|
34 | self.assertEqual(m.visitchildrenset('dir'), 'all') | |
|
35 | ||
|
26 | 36 | class NeverMatcherTests(unittest.TestCase): |
|
27 | 37 | |
|
28 | 38 | def testVisitdir(self): |
@@ -30,6 +40,11 b' class NeverMatcherTests(unittest.TestCas' | |||
|
30 | 40 | self.assertFalse(m.visitdir('.')) |
|
31 | 41 | self.assertFalse(m.visitdir('dir')) |
|
32 | 42 | |
|
43 | def testVisitchildrenset(self): | |
|
44 | m = matchmod.nevermatcher('', '') | |
|
45 | self.assertEqual(m.visitchildrenset('.'), set()) | |
|
46 | self.assertEqual(m.visitchildrenset('dir'), set()) | |
|
47 | ||
|
33 | 48 | class PredicateMatcherTests(unittest.TestCase): |
|
34 | 49 | # predicatematcher does not currently define either of these methods, so |
|
35 | 50 | # this is equivalent to BaseMatcherTests. |
@@ -39,6 +54,11 b' class PredicateMatcherTests(unittest.Tes' | |||
|
39 | 54 | self.assertTrue(m.visitdir('.')) |
|
40 | 55 | self.assertTrue(m.visitdir('dir')) |
|
41 | 56 | |
|
57 | def testVisitchildrenset(self): | |
|
58 | m = matchmod.predicatematcher('', '', lambda *a: False) | |
|
59 | self.assertEqual(m.visitchildrenset('.'), 'this') | |
|
60 | self.assertEqual(m.visitchildrenset('dir'), 'this') | |
|
61 | ||
|
42 | 62 | class PatternMatcherTests(unittest.TestCase): |
|
43 | 63 | |
|
44 | 64 | def testVisitdirPrefix(self): |
@@ -51,6 +71,16 b' class PatternMatcherTests(unittest.TestC' | |||
|
51 | 71 | self.assertTrue(m.visitdir('dir/subdir/x')) |
|
52 | 72 | self.assertFalse(m.visitdir('folder')) |
|
53 | 73 | |
|
74 | def testVisitchildrensetPrefix(self): | |
|
75 | m = matchmod.match('x', '', patterns=['path:dir/subdir']) | |
|
76 | assert isinstance(m, matchmod.patternmatcher) | |
|
77 | self.assertEqual(m.visitchildrenset('.'), 'this') | |
|
78 | self.assertEqual(m.visitchildrenset('dir'), 'this') | |
|
79 | self.assertEqual(m.visitchildrenset('dir/subdir'), 'all') | |
|
80 | # OPT: This should probably be 'all' if its parent is? | |
|
81 | self.assertEqual(m.visitchildrenset('dir/subdir/x'), 'this') | |
|
82 | self.assertEqual(m.visitchildrenset('folder'), set()) | |
|
83 | ||
|
54 | 84 | def testVisitdirRootfilesin(self): |
|
55 | 85 | m = matchmod.match('x', '', patterns=['rootfilesin:dir/subdir']) |
|
56 | 86 | assert isinstance(m, matchmod.patternmatcher) |
@@ -61,6 +91,15 b' class PatternMatcherTests(unittest.TestC' | |||
|
61 | 91 | self.assertFalse(m.visitdir('dir')) |
|
62 | 92 | self.assertFalse(m.visitdir('dir/subdir')) |
|
63 | 93 | |
|
94 | def testVisitchildrensetRootfilesin(self): | |
|
95 | m = matchmod.match('x', '', patterns=['rootfilesin:dir/subdir']) | |
|
96 | assert isinstance(m, matchmod.patternmatcher) | |
|
97 | self.assertEqual(m.visitchildrenset('.'), 'this') | |
|
98 | self.assertEqual(m.visitchildrenset('dir/subdir/x'), set()) | |
|
99 | self.assertEqual(m.visitchildrenset('folder'), set()) | |
|
100 | self.assertEqual(m.visitchildrenset('dir'), set()) | |
|
101 | self.assertEqual(m.visitchildrenset('dir/subdir'), set()) | |
|
102 | ||
|
64 | 103 | def testVisitdirGlob(self): |
|
65 | 104 | m = matchmod.match('x', '', patterns=['glob:dir/z*']) |
|
66 | 105 | assert isinstance(m, matchmod.patternmatcher) |
@@ -71,6 +110,16 b' class PatternMatcherTests(unittest.TestC' | |||
|
71 | 110 | self.assertTrue(m.visitdir('dir/subdir')) |
|
72 | 111 | self.assertTrue(m.visitdir('dir/subdir/x')) |
|
73 | 112 | |
|
113 | def testVisitchildrensetGlob(self): | |
|
114 | m = matchmod.match('x', '', patterns=['glob:dir/z*']) | |
|
115 | assert isinstance(m, matchmod.patternmatcher) | |
|
116 | self.assertEqual(m.visitchildrenset('.'), 'this') | |
|
117 | self.assertEqual(m.visitchildrenset('folder'), set()) | |
|
118 | self.assertEqual(m.visitchildrenset('dir'), 'this') | |
|
119 | # OPT: these should probably be set(). | |
|
120 | self.assertEqual(m.visitchildrenset('dir/subdir'), 'this') | |
|
121 | self.assertEqual(m.visitchildrenset('dir/subdir/x'), 'this') | |
|
122 | ||
|
74 | 123 | class IncludeMatcherTests(unittest.TestCase): |
|
75 | 124 | |
|
76 | 125 | def testVisitdirPrefix(self): |
@@ -83,6 +132,16 b' class IncludeMatcherTests(unittest.TestC' | |||
|
83 | 132 | self.assertTrue(m.visitdir('dir/subdir/x')) |
|
84 | 133 | self.assertFalse(m.visitdir('folder')) |
|
85 | 134 | |
|
135 | def testVisitchildrensetPrefix(self): | |
|
136 | m = matchmod.match('x', '', include=['path:dir/subdir']) | |
|
137 | assert isinstance(m, matchmod.includematcher) | |
|
138 | self.assertEqual(m.visitchildrenset('.'), {'dir'}) | |
|
139 | self.assertEqual(m.visitchildrenset('dir'), {'subdir'}) | |
|
140 | self.assertEqual(m.visitchildrenset('dir/subdir'), 'all') | |
|
141 | # OPT: This should probably be 'all' if its parent is? | |
|
142 | self.assertEqual(m.visitchildrenset('dir/subdir/x'), 'this') | |
|
143 | self.assertEqual(m.visitchildrenset('folder'), set()) | |
|
144 | ||
|
86 | 145 | def testVisitdirRootfilesin(self): |
|
87 | 146 | m = matchmod.match('x', '', include=['rootfilesin:dir/subdir']) |
|
88 | 147 | assert isinstance(m, matchmod.includematcher) |
@@ -92,6 +151,15 b' class IncludeMatcherTests(unittest.TestC' | |||
|
92 | 151 | self.assertFalse(m.visitdir('dir/subdir/x')) |
|
93 | 152 | self.assertFalse(m.visitdir('folder')) |
|
94 | 153 | |
|
154 | def testVisitchildrensetRootfilesin(self): | |
|
155 | m = matchmod.match('x', '', include=['rootfilesin:dir/subdir']) | |
|
156 | assert isinstance(m, matchmod.includematcher) | |
|
157 | self.assertEqual(m.visitchildrenset('.'), {'dir'}) | |
|
158 | self.assertEqual(m.visitchildrenset('dir'), {'subdir'}) | |
|
159 | self.assertEqual(m.visitchildrenset('dir/subdir'), 'this') | |
|
160 | self.assertEqual(m.visitchildrenset('dir/subdir/x'), set()) | |
|
161 | self.assertEqual(m.visitchildrenset('folder'), set()) | |
|
162 | ||
|
95 | 163 | def testVisitdirGlob(self): |
|
96 | 164 | m = matchmod.match('x', '', include=['glob:dir/z*']) |
|
97 | 165 | assert isinstance(m, matchmod.includematcher) |
@@ -102,6 +170,16 b' class IncludeMatcherTests(unittest.TestC' | |||
|
102 | 170 | self.assertTrue(m.visitdir('dir/subdir')) |
|
103 | 171 | self.assertTrue(m.visitdir('dir/subdir/x')) |
|
104 | 172 | |
|
173 | def testVisitchildrensetGlob(self): | |
|
174 | m = matchmod.match('x', '', include=['glob:dir/z*']) | |
|
175 | assert isinstance(m, matchmod.includematcher) | |
|
176 | self.assertEqual(m.visitchildrenset('.'), {'dir'}) | |
|
177 | self.assertEqual(m.visitchildrenset('folder'), set()) | |
|
178 | self.assertEqual(m.visitchildrenset('dir'), 'this') | |
|
179 | # OPT: these should probably be set(). | |
|
180 | self.assertEqual(m.visitchildrenset('dir/subdir'), 'this') | |
|
181 | self.assertEqual(m.visitchildrenset('dir/subdir/x'), 'this') | |
|
182 | ||
|
105 | 183 | class ExactMatcherTests(unittest.TestCase): |
|
106 | 184 | |
|
107 | 185 | def testVisitdir(self): |
@@ -115,6 +193,16 b' class ExactMatcherTests(unittest.TestCas' | |||
|
115 | 193 | self.assertFalse(m.visitdir('dir/subdir/x')) |
|
116 | 194 | self.assertFalse(m.visitdir('folder')) |
|
117 | 195 | |
|
196 | def testVisitchildrenset(self): | |
|
197 | m = matchmod.match('x', '', patterns=['dir/subdir/foo.txt'], exact=True) | |
|
198 | assert isinstance(m, matchmod.exactmatcher) | |
|
199 | self.assertEqual(m.visitchildrenset('.'), {'dir'}) | |
|
200 | self.assertEqual(m.visitchildrenset('dir'), {'subdir'}) | |
|
201 | self.assertEqual(m.visitchildrenset('dir/subdir'), 'this') | |
|
202 | self.assertEqual(m.visitchildrenset('dir/subdir/x'), set()) | |
|
203 | self.assertEqual(m.visitchildrenset('dir/subdir/foo.txt'), set()) | |
|
204 | self.assertEqual(m.visitchildrenset('folder'), set()) | |
|
205 | ||
|
118 | 206 | class DifferenceMatcherTests(unittest.TestCase): |
|
119 | 207 | |
|
120 | 208 | def testVisitdirM2always(self): |
@@ -130,6 +218,19 b' class DifferenceMatcherTests(unittest.Te' | |||
|
130 | 218 | self.assertFalse(dm.visitdir('dir/subdir/x')) |
|
131 | 219 | self.assertFalse(dm.visitdir('folder')) |
|
132 | 220 | |
|
221 | def testVisitchildrensetM2always(self): | |
|
222 | m1 = matchmod.alwaysmatcher('', '') | |
|
223 | m2 = matchmod.alwaysmatcher('', '') | |
|
224 | dm = matchmod.differencematcher(m1, m2) | |
|
225 | # dm should be equivalent to a nevermatcher. | |
|
226 | self.assertEqual(dm.visitchildrenset('.'), set()) | |
|
227 | self.assertEqual(dm.visitchildrenset('dir'), set()) | |
|
228 | self.assertEqual(dm.visitchildrenset('dir/subdir'), set()) | |
|
229 | self.assertEqual(dm.visitchildrenset('dir/subdir/z'), set()) | |
|
230 | self.assertEqual(dm.visitchildrenset('dir/foo'), set()) | |
|
231 | self.assertEqual(dm.visitchildrenset('dir/subdir/x'), set()) | |
|
232 | self.assertEqual(dm.visitchildrenset('folder'), set()) | |
|
233 | ||
|
133 | 234 | def testVisitdirM2never(self): |
|
134 | 235 | m1 = matchmod.alwaysmatcher('', '') |
|
135 | 236 | m2 = matchmod.nevermatcher('', '') |
@@ -149,6 +250,19 b' class DifferenceMatcherTests(unittest.Te' | |||
|
149 | 250 | self.assertEqual(dm.visitdir('dir/subdir/x'), True) |
|
150 | 251 | self.assertEqual(dm.visitdir('folder'), True) |
|
151 | 252 | |
|
253 | def testVisitchildrensetM2never(self): | |
|
254 | m1 = matchmod.alwaysmatcher('', '') | |
|
255 | m2 = matchmod.nevermatcher('', '') | |
|
256 | dm = matchmod.differencematcher(m1, m2) | |
|
257 | # dm should be equivalent to a alwaysmatcher. | |
|
258 | self.assertEqual(dm.visitchildrenset('.'), 'all') | |
|
259 | self.assertEqual(dm.visitchildrenset('dir'), 'all') | |
|
260 | self.assertEqual(dm.visitchildrenset('dir/subdir'), 'all') | |
|
261 | self.assertEqual(dm.visitchildrenset('dir/subdir/z'), 'all') | |
|
262 | self.assertEqual(dm.visitchildrenset('dir/foo'), 'all') | |
|
263 | self.assertEqual(dm.visitchildrenset('dir/subdir/x'), 'all') | |
|
264 | self.assertEqual(dm.visitchildrenset('folder'), 'all') | |
|
265 | ||
|
152 | 266 | def testVisitdirM2SubdirPrefix(self): |
|
153 | 267 | m1 = matchmod.alwaysmatcher('', '') |
|
154 | 268 | m2 = matchmod.match('', '', patterns=['path:dir/subdir']) |
@@ -165,6 +279,21 b' class DifferenceMatcherTests(unittest.Te' | |||
|
165 | 279 | self.assertEqual(dm.visitdir('dir/foo'), True) |
|
166 | 280 | self.assertEqual(dm.visitdir('folder'), True) |
|
167 | 281 | |
|
282 | def testVisitchildrensetM2SubdirPrefix(self): | |
|
283 | m1 = matchmod.alwaysmatcher('', '') | |
|
284 | m2 = matchmod.match('', '', patterns=['path:dir/subdir']) | |
|
285 | dm = matchmod.differencematcher(m1, m2) | |
|
286 | self.assertEqual(dm.visitchildrenset('.'), 'this') | |
|
287 | self.assertEqual(dm.visitchildrenset('dir'), 'this') | |
|
288 | self.assertEqual(dm.visitchildrenset('dir/subdir'), set()) | |
|
289 | self.assertEqual(dm.visitchildrenset('dir/foo'), 'all') | |
|
290 | self.assertEqual(dm.visitchildrenset('folder'), 'all') | |
|
291 | # OPT: We should probably return set() for these; we don't because | |
|
292 | # patternmatcher.visitdir() (our m2) doesn't return 'all' for subdirs of | |
|
293 | # an 'all' pattern, just 'this'. | |
|
294 | self.assertEqual(dm.visitchildrenset('dir/subdir/z'), 'this') | |
|
295 | self.assertEqual(dm.visitchildrenset('dir/subdir/x'), 'this') | |
|
296 | ||
|
168 | 297 | # We're using includematcher instead of patterns because it behaves slightly |
|
169 | 298 | # better (giving narrower results) than patternmatcher. |
|
170 | 299 | def testVisitdirIncludeIncludfe(self): |
@@ -182,6 +311,21 b' class DifferenceMatcherTests(unittest.Te' | |||
|
182 | 311 | self.assertEqual(dm.visitdir('dir/subdir/z'), True) |
|
183 | 312 | self.assertEqual(dm.visitdir('dir/subdir/x'), True) |
|
184 | 313 | |
|
314 | def testVisitchildrensetIncludeInclude(self): | |
|
315 | m1 = matchmod.match('', '', include=['path:dir/subdir']) | |
|
316 | m2 = matchmod.match('', '', include=['rootfilesin:dir']) | |
|
317 | dm = matchmod.differencematcher(m1, m2) | |
|
318 | self.assertEqual(dm.visitchildrenset('.'), {'dir'}) | |
|
319 | self.assertEqual(dm.visitchildrenset('dir'), {'subdir'}) | |
|
320 | self.assertEqual(dm.visitchildrenset('dir/subdir'), 'all') | |
|
321 | self.assertEqual(dm.visitchildrenset('dir/foo'), set()) | |
|
322 | self.assertEqual(dm.visitchildrenset('folder'), set()) | |
|
323 | # OPT: We should probably return set() for these; we don't because | |
|
324 | # patternmatcher.visitdir() (our m2) doesn't return 'all' for subdirs of | |
|
325 | # an 'all' pattern, just 'this'. | |
|
326 | self.assertEqual(dm.visitchildrenset('dir/subdir/z'), 'this') | |
|
327 | self.assertEqual(dm.visitchildrenset('dir/subdir/x'), 'this') | |
|
328 | ||
|
185 | 329 | class IntersectionMatcherTests(unittest.TestCase): |
|
186 | 330 | |
|
187 | 331 | def testVisitdirM2always(self): |
@@ -197,6 +341,19 b' class IntersectionMatcherTests(unittest.' | |||
|
197 | 341 | self.assertEqual(im.visitdir('dir/subdir/x'), 'all') |
|
198 | 342 | self.assertEqual(im.visitdir('folder'), 'all') |
|
199 | 343 | |
|
344 | def testVisitchildrensetM2always(self): | |
|
345 | m1 = matchmod.alwaysmatcher('', '') | |
|
346 | m2 = matchmod.alwaysmatcher('', '') | |
|
347 | im = matchmod.intersectmatchers(m1, m2) | |
|
348 | # im should be equivalent to a alwaysmatcher. | |
|
349 | self.assertEqual(im.visitchildrenset('.'), 'all') | |
|
350 | self.assertEqual(im.visitchildrenset('dir'), 'all') | |
|
351 | self.assertEqual(im.visitchildrenset('dir/subdir'), 'all') | |
|
352 | self.assertEqual(im.visitchildrenset('dir/subdir/z'), 'all') | |
|
353 | self.assertEqual(im.visitchildrenset('dir/foo'), 'all') | |
|
354 | self.assertEqual(im.visitchildrenset('dir/subdir/x'), 'all') | |
|
355 | self.assertEqual(im.visitchildrenset('folder'), 'all') | |
|
356 | ||
|
200 | 357 | def testVisitdirM2never(self): |
|
201 | 358 | m1 = matchmod.alwaysmatcher('', '') |
|
202 | 359 | m2 = matchmod.nevermatcher('', '') |
@@ -210,6 +367,19 b' class IntersectionMatcherTests(unittest.' | |||
|
210 | 367 | self.assertFalse(im.visitdir('dir/subdir/x')) |
|
211 | 368 | self.assertFalse(im.visitdir('folder')) |
|
212 | 369 | |
|
370 | def testVisitchildrensetM2never(self): | |
|
371 | m1 = matchmod.alwaysmatcher('', '') | |
|
372 | m2 = matchmod.nevermatcher('', '') | |
|
373 | im = matchmod.intersectmatchers(m1, m2) | |
|
374 | # im should be equivalent to a nevermqtcher. | |
|
375 | self.assertEqual(im.visitchildrenset('.'), set()) | |
|
376 | self.assertEqual(im.visitchildrenset('dir'), set()) | |
|
377 | self.assertEqual(im.visitchildrenset('dir/subdir'), set()) | |
|
378 | self.assertEqual(im.visitchildrenset('dir/subdir/z'), set()) | |
|
379 | self.assertEqual(im.visitchildrenset('dir/foo'), set()) | |
|
380 | self.assertEqual(im.visitchildrenset('dir/subdir/x'), set()) | |
|
381 | self.assertEqual(im.visitchildrenset('folder'), set()) | |
|
382 | ||
|
213 | 383 | def testVisitdirM2SubdirPrefix(self): |
|
214 | 384 | m1 = matchmod.alwaysmatcher('', '') |
|
215 | 385 | m2 = matchmod.match('', '', patterns=['path:dir/subdir']) |
@@ -225,6 +395,19 b' class IntersectionMatcherTests(unittest.' | |||
|
225 | 395 | self.assertEqual(im.visitdir('dir/subdir/z'), True) |
|
226 | 396 | self.assertEqual(im.visitdir('dir/subdir/x'), True) |
|
227 | 397 | |
|
398 | def testVisitchildrensetM2SubdirPrefix(self): | |
|
399 | m1 = matchmod.alwaysmatcher('', '') | |
|
400 | m2 = matchmod.match('', '', include=['path:dir/subdir']) | |
|
401 | im = matchmod.intersectmatchers(m1, m2) | |
|
402 | self.assertEqual(im.visitchildrenset('.'), {'dir'}) | |
|
403 | self.assertEqual(im.visitchildrenset('dir'), {'subdir'}) | |
|
404 | self.assertEqual(im.visitchildrenset('dir/subdir'), 'all') | |
|
405 | self.assertEqual(im.visitchildrenset('dir/foo'), set()) | |
|
406 | self.assertEqual(im.visitchildrenset('folder'), set()) | |
|
407 | # OPT: We should probably return 'all' for these | |
|
408 | self.assertEqual(im.visitchildrenset('dir/subdir/z'), 'this') | |
|
409 | self.assertEqual(im.visitchildrenset('dir/subdir/x'), 'this') | |
|
410 | ||
|
228 | 411 | # We're using includematcher instead of patterns because it behaves slightly |
|
229 | 412 | # better (giving narrower results) than patternmatcher. |
|
230 | 413 | def testVisitdirIncludeIncludfe(self): |
@@ -239,6 +422,18 b' class IntersectionMatcherTests(unittest.' | |||
|
239 | 422 | self.assertFalse(im.visitdir('dir/subdir/z')) |
|
240 | 423 | self.assertFalse(im.visitdir('dir/subdir/x')) |
|
241 | 424 | |
|
425 | def testVisitchildrensetIncludeInclude(self): | |
|
426 | m1 = matchmod.match('', '', include=['path:dir/subdir']) | |
|
427 | m2 = matchmod.match('', '', include=['rootfilesin:dir']) | |
|
428 | im = matchmod.intersectmatchers(m1, m2) | |
|
429 | self.assertEqual(im.visitchildrenset('.'), {'dir'}) | |
|
430 | self.assertEqual(im.visitchildrenset('dir'), 'this') | |
|
431 | self.assertEqual(im.visitchildrenset('dir/subdir'), set()) | |
|
432 | self.assertEqual(im.visitchildrenset('dir/foo'), set()) | |
|
433 | self.assertEqual(im.visitchildrenset('folder'), set()) | |
|
434 | self.assertEqual(im.visitchildrenset('dir/subdir/z'), set()) | |
|
435 | self.assertEqual(im.visitchildrenset('dir/subdir/x'), set()) | |
|
436 | ||
|
242 | 437 | # We're using includematcher instead of patterns because it behaves slightly |
|
243 | 438 | # better (giving narrower results) than patternmatcher. |
|
244 | 439 | def testVisitdirIncludeInclude2(self): |
@@ -254,6 +449,19 b' class IntersectionMatcherTests(unittest.' | |||
|
254 | 449 | self.assertFalse(im.visitdir('dir/subdir/z')) |
|
255 | 450 | self.assertFalse(im.visitdir('dir/subdir/x')) |
|
256 | 451 | |
|
452 | def testVisitchildrensetIncludeInclude2(self): | |
|
453 | m1 = matchmod.match('', '', include=['path:dir/subdir']) | |
|
454 | m2 = matchmod.match('', '', include=['path:folder']) | |
|
455 | im = matchmod.intersectmatchers(m1, m2) | |
|
456 | # FIXME: is set() correct here? | |
|
457 | self.assertEqual(im.visitchildrenset('.'), set()) | |
|
458 | self.assertEqual(im.visitchildrenset('dir'), set()) | |
|
459 | self.assertEqual(im.visitchildrenset('dir/subdir'), set()) | |
|
460 | self.assertEqual(im.visitchildrenset('dir/foo'), set()) | |
|
461 | self.assertEqual(im.visitchildrenset('folder'), set()) | |
|
462 | self.assertEqual(im.visitchildrenset('dir/subdir/z'), set()) | |
|
463 | self.assertEqual(im.visitchildrenset('dir/subdir/x'), set()) | |
|
464 | ||
|
257 | 465 | # We're using includematcher instead of patterns because it behaves slightly |
|
258 | 466 | # better (giving narrower results) than patternmatcher. |
|
259 | 467 | def testVisitdirIncludeInclude3(self): |
@@ -269,6 +477,19 b' class IntersectionMatcherTests(unittest.' | |||
|
269 | 477 | # OPT: this should probably be 'all' not True. |
|
270 | 478 | self.assertEqual(im.visitdir('dir/subdir/x'), True) |
|
271 | 479 | |
|
480 | def testVisitchildrensetIncludeInclude3(self): | |
|
481 | m1 = matchmod.match('', '', include=['path:dir/subdir/x']) | |
|
482 | m2 = matchmod.match('', '', include=['path:dir/subdir']) | |
|
483 | im = matchmod.intersectmatchers(m1, m2) | |
|
484 | self.assertEqual(im.visitchildrenset('.'), {'dir'}) | |
|
485 | self.assertEqual(im.visitchildrenset('dir'), {'subdir'}) | |
|
486 | self.assertEqual(im.visitchildrenset('dir/subdir'), {'x'}) | |
|
487 | self.assertEqual(im.visitchildrenset('dir/foo'), set()) | |
|
488 | self.assertEqual(im.visitchildrenset('folder'), set()) | |
|
489 | self.assertEqual(im.visitchildrenset('dir/subdir/z'), set()) | |
|
490 | # OPT: this should probably be 'all' not 'this'. | |
|
491 | self.assertEqual(im.visitchildrenset('dir/subdir/x'), 'this') | |
|
492 | ||
|
272 | 493 | # We're using includematcher instead of patterns because it behaves slightly |
|
273 | 494 | # better (giving narrower results) than patternmatcher. |
|
274 | 495 | def testVisitdirIncludeInclude4(self): |
@@ -284,6 +505,19 b' class IntersectionMatcherTests(unittest.' | |||
|
284 | 505 | self.assertFalse(im.visitdir('dir/subdir/z')) |
|
285 | 506 | self.assertFalse(im.visitdir('dir/subdir/x')) |
|
286 | 507 | |
|
508 | def testVisitchildrensetIncludeInclude4(self): | |
|
509 | m1 = matchmod.match('', '', include=['path:dir/subdir/x']) | |
|
510 | m2 = matchmod.match('', '', include=['path:dir/subdir/z']) | |
|
511 | im = matchmod.intersectmatchers(m1, m2) | |
|
512 | # OPT: these next two could probably be set() as well. | |
|
513 | self.assertEqual(im.visitchildrenset('.'), {'dir'}) | |
|
514 | self.assertEqual(im.visitchildrenset('dir'), {'subdir'}) | |
|
515 | self.assertEqual(im.visitchildrenset('dir/subdir'), set()) | |
|
516 | self.assertEqual(im.visitchildrenset('dir/foo'), set()) | |
|
517 | self.assertEqual(im.visitchildrenset('folder'), set()) | |
|
518 | self.assertEqual(im.visitchildrenset('dir/subdir/z'), set()) | |
|
519 | self.assertEqual(im.visitchildrenset('dir/subdir/x'), set()) | |
|
520 | ||
|
287 | 521 | class UnionMatcherTests(unittest.TestCase): |
|
288 | 522 | |
|
289 | 523 | def testVisitdirM2always(self): |
@@ -299,6 +533,19 b' class UnionMatcherTests(unittest.TestCas' | |||
|
299 | 533 | self.assertEqual(um.visitdir('dir/subdir/x'), 'all') |
|
300 | 534 | self.assertEqual(um.visitdir('folder'), 'all') |
|
301 | 535 | |
|
536 | def testVisitchildrensetM2always(self): | |
|
537 | m1 = matchmod.alwaysmatcher('', '') | |
|
538 | m2 = matchmod.alwaysmatcher('', '') | |
|
539 | um = matchmod.unionmatcher([m1, m2]) | |
|
540 | # um should be equivalent to a alwaysmatcher. | |
|
541 | self.assertEqual(um.visitchildrenset('.'), 'all') | |
|
542 | self.assertEqual(um.visitchildrenset('dir'), 'all') | |
|
543 | self.assertEqual(um.visitchildrenset('dir/subdir'), 'all') | |
|
544 | self.assertEqual(um.visitchildrenset('dir/subdir/z'), 'all') | |
|
545 | self.assertEqual(um.visitchildrenset('dir/foo'), 'all') | |
|
546 | self.assertEqual(um.visitchildrenset('dir/subdir/x'), 'all') | |
|
547 | self.assertEqual(um.visitchildrenset('folder'), 'all') | |
|
548 | ||
|
302 | 549 | def testVisitdirM1never(self): |
|
303 | 550 | m1 = matchmod.nevermatcher('', '') |
|
304 | 551 | m2 = matchmod.alwaysmatcher('', '') |
@@ -312,6 +559,19 b' class UnionMatcherTests(unittest.TestCas' | |||
|
312 | 559 | self.assertEqual(um.visitdir('dir/subdir/x'), 'all') |
|
313 | 560 | self.assertEqual(um.visitdir('folder'), 'all') |
|
314 | 561 | |
|
562 | def testVisitchildrensetM1never(self): | |
|
563 | m1 = matchmod.nevermatcher('', '') | |
|
564 | m2 = matchmod.alwaysmatcher('', '') | |
|
565 | um = matchmod.unionmatcher([m1, m2]) | |
|
566 | # um should be equivalent to a alwaysmatcher. | |
|
567 | self.assertEqual(um.visitchildrenset('.'), 'all') | |
|
568 | self.assertEqual(um.visitchildrenset('dir'), 'all') | |
|
569 | self.assertEqual(um.visitchildrenset('dir/subdir'), 'all') | |
|
570 | self.assertEqual(um.visitchildrenset('dir/subdir/z'), 'all') | |
|
571 | self.assertEqual(um.visitchildrenset('dir/foo'), 'all') | |
|
572 | self.assertEqual(um.visitchildrenset('dir/subdir/x'), 'all') | |
|
573 | self.assertEqual(um.visitchildrenset('folder'), 'all') | |
|
574 | ||
|
315 | 575 | def testVisitdirM2never(self): |
|
316 | 576 | m1 = matchmod.alwaysmatcher('', '') |
|
317 | 577 | m2 = matchmod.nevermatcher('', '') |
@@ -325,6 +585,19 b' class UnionMatcherTests(unittest.TestCas' | |||
|
325 | 585 | self.assertEqual(um.visitdir('dir/subdir/x'), 'all') |
|
326 | 586 | self.assertEqual(um.visitdir('folder'), 'all') |
|
327 | 587 | |
|
588 | def testVisitchildrensetM2never(self): | |
|
589 | m1 = matchmod.alwaysmatcher('', '') | |
|
590 | m2 = matchmod.nevermatcher('', '') | |
|
591 | um = matchmod.unionmatcher([m1, m2]) | |
|
592 | # um should be equivalent to a alwaysmatcher. | |
|
593 | self.assertEqual(um.visitchildrenset('.'), 'all') | |
|
594 | self.assertEqual(um.visitchildrenset('dir'), 'all') | |
|
595 | self.assertEqual(um.visitchildrenset('dir/subdir'), 'all') | |
|
596 | self.assertEqual(um.visitchildrenset('dir/subdir/z'), 'all') | |
|
597 | self.assertEqual(um.visitchildrenset('dir/foo'), 'all') | |
|
598 | self.assertEqual(um.visitchildrenset('dir/subdir/x'), 'all') | |
|
599 | self.assertEqual(um.visitchildrenset('folder'), 'all') | |
|
600 | ||
|
328 | 601 | def testVisitdirM2SubdirPrefix(self): |
|
329 | 602 | m1 = matchmod.alwaysmatcher('', '') |
|
330 | 603 | m2 = matchmod.match('', '', patterns=['path:dir/subdir']) |
@@ -337,6 +610,18 b' class UnionMatcherTests(unittest.TestCas' | |||
|
337 | 610 | self.assertEqual(um.visitdir('dir/subdir/z'), 'all') |
|
338 | 611 | self.assertEqual(um.visitdir('dir/subdir/x'), 'all') |
|
339 | 612 | |
|
613 | def testVisitchildrensetM2SubdirPrefix(self): | |
|
614 | m1 = matchmod.alwaysmatcher('', '') | |
|
615 | m2 = matchmod.match('', '', include=['path:dir/subdir']) | |
|
616 | um = matchmod.unionmatcher([m1, m2]) | |
|
617 | self.assertEqual(um.visitchildrenset('.'), 'all') | |
|
618 | self.assertEqual(um.visitchildrenset('dir'), 'all') | |
|
619 | self.assertEqual(um.visitchildrenset('dir/subdir'), 'all') | |
|
620 | self.assertEqual(um.visitchildrenset('dir/foo'), 'all') | |
|
621 | self.assertEqual(um.visitchildrenset('folder'), 'all') | |
|
622 | self.assertEqual(um.visitchildrenset('dir/subdir/z'), 'all') | |
|
623 | self.assertEqual(um.visitchildrenset('dir/subdir/x'), 'all') | |
|
624 | ||
|
340 | 625 | # We're using includematcher instead of patterns because it behaves slightly |
|
341 | 626 | # better (giving narrower results) than patternmatcher. |
|
342 | 627 | def testVisitdirIncludeIncludfe(self): |
@@ -352,6 +637,19 b' class UnionMatcherTests(unittest.TestCas' | |||
|
352 | 637 | self.assertEqual(um.visitdir('dir/subdir/z'), True) |
|
353 | 638 | self.assertEqual(um.visitdir('dir/subdir/x'), True) |
|
354 | 639 | |
|
640 | def testVisitchildrensetIncludeInclude(self): | |
|
641 | m1 = matchmod.match('', '', include=['path:dir/subdir']) | |
|
642 | m2 = matchmod.match('', '', include=['rootfilesin:dir']) | |
|
643 | um = matchmod.unionmatcher([m1, m2]) | |
|
644 | self.assertEqual(um.visitchildrenset('.'), {'dir'}) | |
|
645 | self.assertEqual(um.visitchildrenset('dir'), 'this') | |
|
646 | self.assertEqual(um.visitchildrenset('dir/subdir'), 'all') | |
|
647 | self.assertEqual(um.visitchildrenset('dir/foo'), set()) | |
|
648 | self.assertEqual(um.visitchildrenset('folder'), set()) | |
|
649 | # OPT: These next two could be 'all' instead of 'this'. | |
|
650 | self.assertEqual(um.visitchildrenset('dir/subdir/z'), 'this') | |
|
651 | self.assertEqual(um.visitchildrenset('dir/subdir/x'), 'this') | |
|
652 | ||
|
355 | 653 | # We're using includematcher instead of patterns because it behaves slightly |
|
356 | 654 | # better (giving narrower results) than patternmatcher. |
|
357 | 655 | def testVisitdirIncludeInclude2(self): |
@@ -367,6 +665,19 b' class UnionMatcherTests(unittest.TestCas' | |||
|
367 | 665 | self.assertEqual(um.visitdir('dir/subdir/z'), True) |
|
368 | 666 | self.assertEqual(um.visitdir('dir/subdir/x'), True) |
|
369 | 667 | |
|
668 | def testVisitchildrensetIncludeInclude2(self): | |
|
669 | m1 = matchmod.match('', '', include=['path:dir/subdir']) | |
|
670 | m2 = matchmod.match('', '', include=['path:folder']) | |
|
671 | um = matchmod.unionmatcher([m1, m2]) | |
|
672 | self.assertEqual(um.visitchildrenset('.'), {'folder', 'dir'}) | |
|
673 | self.assertEqual(um.visitchildrenset('dir'), {'subdir'}) | |
|
674 | self.assertEqual(um.visitchildrenset('dir/subdir'), 'all') | |
|
675 | self.assertEqual(um.visitchildrenset('dir/foo'), set()) | |
|
676 | self.assertEqual(um.visitchildrenset('folder'), 'all') | |
|
677 | # OPT: These next two could be 'all' instead of 'this'. | |
|
678 | self.assertEqual(um.visitchildrenset('dir/subdir/z'), 'this') | |
|
679 | self.assertEqual(um.visitchildrenset('dir/subdir/x'), 'this') | |
|
680 | ||
|
370 | 681 | # We're using includematcher instead of patterns because it behaves slightly |
|
371 | 682 | # better (giving narrower results) than patternmatcher. |
|
372 | 683 | def testVisitdirIncludeInclude3(self): |
@@ -382,6 +693,19 b' class UnionMatcherTests(unittest.TestCas' | |||
|
382 | 693 | # OPT: this should probably be 'all' not True. |
|
383 | 694 | self.assertEqual(um.visitdir('dir/subdir/z'), True) |
|
384 | 695 | |
|
696 | def testVisitchildrensetIncludeInclude3(self): | |
|
697 | m1 = matchmod.match('', '', include=['path:dir/subdir/x']) | |
|
698 | m2 = matchmod.match('', '', include=['path:dir/subdir']) | |
|
699 | um = matchmod.unionmatcher([m1, m2]) | |
|
700 | self.assertEqual(um.visitchildrenset('.'), {'dir'}) | |
|
701 | self.assertEqual(um.visitchildrenset('dir'), {'subdir'}) | |
|
702 | self.assertEqual(um.visitchildrenset('dir/subdir'), 'all') | |
|
703 | self.assertEqual(um.visitchildrenset('dir/foo'), set()) | |
|
704 | self.assertEqual(um.visitchildrenset('folder'), set()) | |
|
705 | self.assertEqual(um.visitchildrenset('dir/subdir/x'), 'all') | |
|
706 | # OPT: this should probably be 'all' not 'this'. | |
|
707 | self.assertEqual(um.visitchildrenset('dir/subdir/z'), 'this') | |
|
708 | ||
|
385 | 709 | # We're using includematcher instead of patterns because it behaves slightly |
|
386 | 710 | # better (giving narrower results) than patternmatcher. |
|
387 | 711 | def testVisitdirIncludeInclude4(self): |
@@ -397,6 +721,18 b' class UnionMatcherTests(unittest.TestCas' | |||
|
397 | 721 | self.assertEqual(um.visitdir('dir/subdir/z'), 'all') |
|
398 | 722 | self.assertEqual(um.visitdir('dir/subdir/x'), 'all') |
|
399 | 723 | |
|
724 | def testVisitchildrensetIncludeInclude4(self): | |
|
725 | m1 = matchmod.match('', '', include=['path:dir/subdir/x']) | |
|
726 | m2 = matchmod.match('', '', include=['path:dir/subdir/z']) | |
|
727 | um = matchmod.unionmatcher([m1, m2]) | |
|
728 | self.assertEqual(um.visitchildrenset('.'), {'dir'}) | |
|
729 | self.assertEqual(um.visitchildrenset('dir'), {'subdir'}) | |
|
730 | self.assertEqual(um.visitchildrenset('dir/subdir'), {'x', 'z'}) | |
|
731 | self.assertEqual(um.visitchildrenset('dir/foo'), set()) | |
|
732 | self.assertEqual(um.visitchildrenset('folder'), set()) | |
|
733 | self.assertEqual(um.visitchildrenset('dir/subdir/z'), 'all') | |
|
734 | self.assertEqual(um.visitchildrenset('dir/subdir/x'), 'all') | |
|
735 | ||
|
400 | 736 | class SubdirMatcherTests(unittest.TestCase): |
|
401 | 737 | |
|
402 | 738 | def testVisitdir(self): |
@@ -410,6 +746,17 b' class SubdirMatcherTests(unittest.TestCa' | |||
|
410 | 746 | self.assertEqual(sm.visitdir('subdir/z'), True) |
|
411 | 747 | self.assertFalse(sm.visitdir('foo')) |
|
412 | 748 | |
|
749 | def testVisitchildrenset(self): | |
|
750 | m = matchmod.match('', '', include=['path:dir/subdir']) | |
|
751 | sm = matchmod.subdirmatcher('dir', m) | |
|
752 | ||
|
753 | self.assertEqual(sm.visitchildrenset('.'), {'subdir'}) | |
|
754 | self.assertEqual(sm.visitchildrenset('subdir'), 'all') | |
|
755 | # OPT: These next two should probably be 'all' not 'this'. | |
|
756 | self.assertEqual(sm.visitchildrenset('subdir/x'), 'this') | |
|
757 | self.assertEqual(sm.visitchildrenset('subdir/z'), 'this') | |
|
758 | self.assertEqual(sm.visitchildrenset('foo'), set()) | |
|
759 | ||
|
413 | 760 | class PrefixdirMatcherTests(unittest.TestCase): |
|
414 | 761 | |
|
415 | 762 | def testVisitdir(self): |
@@ -444,5 +791,27 b' class PrefixdirMatcherTests(unittest.Tes' | |||
|
444 | 791 | self.assertEqual(pm.visitdir('d/e/f'), True) |
|
445 | 792 | self.assertEqual(pm.visitdir('d/e/f/g'), False) |
|
446 | 793 | |
|
794 | def testVisitchildrenset(self): | |
|
795 | m = matchmod.match(util.localpath('root/d'), 'e/f', | |
|
796 | ['../a.txt', 'b.txt']) | |
|
797 | pm = matchmod.prefixdirmatcher('root', 'd/e/f', 'd', m) | |
|
798 | ||
|
799 | # OPT: visitchildrenset could possibly return {'e'} and {'f'} for these | |
|
800 | # next two, respectively; patternmatcher does not have this | |
|
801 | # optimization. | |
|
802 | self.assertEqual(m.visitchildrenset('.'), 'this') | |
|
803 | self.assertEqual(m.visitchildrenset('e'), 'this') | |
|
804 | self.assertEqual(m.visitchildrenset('e/f'), 'this') | |
|
805 | self.assertEqual(m.visitchildrenset('e/f/g'), set()) | |
|
806 | ||
|
807 | # OPT: visitchildrenset could possibly return {'d'}, {'e'}, and {'f'} | |
|
808 | # for these next three, respectively; patternmatcher does not have this | |
|
809 | # optimization. | |
|
810 | self.assertEqual(pm.visitchildrenset('.'), 'this') | |
|
811 | self.assertEqual(pm.visitchildrenset('d'), 'this') | |
|
812 | self.assertEqual(pm.visitchildrenset('d/e'), 'this') | |
|
813 | self.assertEqual(pm.visitchildrenset('d/e/f'), 'this') | |
|
814 | self.assertEqual(pm.visitchildrenset('d/e/f/g'), set()) | |
|
815 | ||
|
447 | 816 | if __name__ == '__main__': |
|
448 | 817 | silenttestrunner.main(__name__) |
General Comments 0
You need to be logged in to leave comments.
Login now