##// END OF EJS Templates
match: add visitchildrenset complement to visitdir...
spectral -
r38990:081cc9a9 default
parent child Browse files
Show More
@@ -8,6 +8,7 b''
8 from __future__ import absolute_import, print_function
8 from __future__ import absolute_import, print_function
9
9
10 import copy
10 import copy
11 import itertools
11 import os
12 import os
12 import re
13 import re
13
14
@@ -331,6 +332,38 b' class basematcher(object):'
331 '''
332 '''
332 return True
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 def always(self):
367 def always(self):
335 '''Matcher will match everything and .files() will be empty --
368 '''Matcher will match everything and .files() will be empty --
336 optimization might be possible.'''
369 optimization might be possible.'''
@@ -367,6 +400,9 b' class alwaysmatcher(basematcher):'
367 def visitdir(self, dir):
400 def visitdir(self, dir):
368 return 'all'
401 return 'all'
369
402
403 def visitchildrenset(self, dir):
404 return 'all'
405
370 def __repr__(self):
406 def __repr__(self):
371 return r'<alwaysmatcher>'
407 return r'<alwaysmatcher>'
372
408
@@ -390,6 +426,9 b' class nevermatcher(basematcher):'
390 def visitdir(self, dir):
426 def visitdir(self, dir):
391 return False
427 return False
392
428
429 def visitchildrenset(self, dir):
430 return set()
431
393 def __repr__(self):
432 def __repr__(self):
394 return r'<nevermatcher>'
433 return r'<nevermatcher>'
395
434
@@ -430,6 +469,15 b' class patternmatcher(basematcher):'
430 any(parentdir in self._fileset
469 any(parentdir in self._fileset
431 for parentdir in util.finddirs(dir)))
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 def prefix(self):
481 def prefix(self):
434 return self._prefix
482 return self._prefix
435
483
@@ -464,6 +512,43 b' class includematcher(basematcher):'
464 any(parentdir in self._roots
512 any(parentdir in self._roots
465 for parentdir in util.finddirs(dir)))
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 @encoding.strmethod
552 @encoding.strmethod
468 def __repr__(self):
553 def __repr__(self):
469 return ('<includematcher includes=%r>' % pycompat.bytestr(self._pats))
554 return ('<includematcher includes=%r>' % pycompat.bytestr(self._pats))
@@ -490,6 +575,25 b' class exactmatcher(basematcher):'
490 def visitdir(self, dir):
575 def visitdir(self, dir):
491 return dir in self._dirs
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 def isexact(self):
597 def isexact(self):
494 return True
598 return True
495
599
@@ -531,6 +635,31 b' class differencematcher(basematcher):'
531 return False
635 return False
532 return bool(self._m1.visitdir(dir))
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 def isexact(self):
663 def isexact(self):
535 return self._m1.isexact()
664 return self._m1.isexact()
536
665
@@ -595,6 +724,25 b' class intersectionmatcher(basematcher):'
595 # bool() because visit1=True + visit2='all' should not be 'all'
724 # bool() because visit1=True + visit2='all' should not be 'all'
596 return bool(visit1 and self._m2.visitdir(dir))
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 def always(self):
746 def always(self):
599 return self._m1.always() and self._m2.always()
747 return self._m1.always() and self._m2.always()
600
748
@@ -676,6 +824,13 b' class subdirmatcher(basematcher):'
676 dir = self._path + "/" + dir
824 dir = self._path + "/" + dir
677 return self._matcher.visitdir(dir)
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 def always(self):
834 def always(self):
680 return self._always
835 return self._always
681
836
@@ -748,6 +903,14 b' class prefixdirmatcher(basematcher):'
748 return self._matcher.visitdir(dir[len(self._pathprefix):])
903 return self._matcher.visitdir(dir[len(self._pathprefix):])
749 return dir in self._pathdirs
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 def isexact(self):
914 def isexact(self):
752 return self._matcher.isexact()
915 return self._matcher.isexact()
753
916
@@ -788,6 +951,25 b' class unionmatcher(basematcher):'
788 r |= v
951 r |= v
789 return r
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 @encoding.strmethod
973 @encoding.strmethod
792 def __repr__(self):
974 def __repr__(self):
793 return ('<unionmatcher matchers=%r>' % self._matchers)
975 return ('<unionmatcher matchers=%r>' % self._matchers)
@@ -16,6 +16,11 b' class BaseMatcherTests(unittest.TestCase'
16 self.assertTrue(m.visitdir('.'))
16 self.assertTrue(m.visitdir('.'))
17 self.assertTrue(m.visitdir('dir'))
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 class AlwaysMatcherTests(unittest.TestCase):
24 class AlwaysMatcherTests(unittest.TestCase):
20
25
21 def testVisitdir(self):
26 def testVisitdir(self):
@@ -23,6 +28,11 b' class AlwaysMatcherTests(unittest.TestCa'
23 self.assertEqual(m.visitdir('.'), 'all')
28 self.assertEqual(m.visitdir('.'), 'all')
24 self.assertEqual(m.visitdir('dir'), 'all')
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 class NeverMatcherTests(unittest.TestCase):
36 class NeverMatcherTests(unittest.TestCase):
27
37
28 def testVisitdir(self):
38 def testVisitdir(self):
@@ -30,6 +40,11 b' class NeverMatcherTests(unittest.TestCas'
30 self.assertFalse(m.visitdir('.'))
40 self.assertFalse(m.visitdir('.'))
31 self.assertFalse(m.visitdir('dir'))
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 class PredicateMatcherTests(unittest.TestCase):
48 class PredicateMatcherTests(unittest.TestCase):
34 # predicatematcher does not currently define either of these methods, so
49 # predicatematcher does not currently define either of these methods, so
35 # this is equivalent to BaseMatcherTests.
50 # this is equivalent to BaseMatcherTests.
@@ -39,6 +54,11 b' class PredicateMatcherTests(unittest.Tes'
39 self.assertTrue(m.visitdir('.'))
54 self.assertTrue(m.visitdir('.'))
40 self.assertTrue(m.visitdir('dir'))
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 class PatternMatcherTests(unittest.TestCase):
62 class PatternMatcherTests(unittest.TestCase):
43
63
44 def testVisitdirPrefix(self):
64 def testVisitdirPrefix(self):
@@ -51,6 +71,16 b' class PatternMatcherTests(unittest.TestC'
51 self.assertTrue(m.visitdir('dir/subdir/x'))
71 self.assertTrue(m.visitdir('dir/subdir/x'))
52 self.assertFalse(m.visitdir('folder'))
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 def testVisitdirRootfilesin(self):
84 def testVisitdirRootfilesin(self):
55 m = matchmod.match('x', '', patterns=['rootfilesin:dir/subdir'])
85 m = matchmod.match('x', '', patterns=['rootfilesin:dir/subdir'])
56 assert isinstance(m, matchmod.patternmatcher)
86 assert isinstance(m, matchmod.patternmatcher)
@@ -61,6 +91,15 b' class PatternMatcherTests(unittest.TestC'
61 self.assertFalse(m.visitdir('dir'))
91 self.assertFalse(m.visitdir('dir'))
62 self.assertFalse(m.visitdir('dir/subdir'))
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 def testVisitdirGlob(self):
103 def testVisitdirGlob(self):
65 m = matchmod.match('x', '', patterns=['glob:dir/z*'])
104 m = matchmod.match('x', '', patterns=['glob:dir/z*'])
66 assert isinstance(m, matchmod.patternmatcher)
105 assert isinstance(m, matchmod.patternmatcher)
@@ -71,6 +110,16 b' class PatternMatcherTests(unittest.TestC'
71 self.assertTrue(m.visitdir('dir/subdir'))
110 self.assertTrue(m.visitdir('dir/subdir'))
72 self.assertTrue(m.visitdir('dir/subdir/x'))
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 class IncludeMatcherTests(unittest.TestCase):
123 class IncludeMatcherTests(unittest.TestCase):
75
124
76 def testVisitdirPrefix(self):
125 def testVisitdirPrefix(self):
@@ -83,6 +132,16 b' class IncludeMatcherTests(unittest.TestC'
83 self.assertTrue(m.visitdir('dir/subdir/x'))
132 self.assertTrue(m.visitdir('dir/subdir/x'))
84 self.assertFalse(m.visitdir('folder'))
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 def testVisitdirRootfilesin(self):
145 def testVisitdirRootfilesin(self):
87 m = matchmod.match('x', '', include=['rootfilesin:dir/subdir'])
146 m = matchmod.match('x', '', include=['rootfilesin:dir/subdir'])
88 assert isinstance(m, matchmod.includematcher)
147 assert isinstance(m, matchmod.includematcher)
@@ -92,6 +151,15 b' class IncludeMatcherTests(unittest.TestC'
92 self.assertFalse(m.visitdir('dir/subdir/x'))
151 self.assertFalse(m.visitdir('dir/subdir/x'))
93 self.assertFalse(m.visitdir('folder'))
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 def testVisitdirGlob(self):
163 def testVisitdirGlob(self):
96 m = matchmod.match('x', '', include=['glob:dir/z*'])
164 m = matchmod.match('x', '', include=['glob:dir/z*'])
97 assert isinstance(m, matchmod.includematcher)
165 assert isinstance(m, matchmod.includematcher)
@@ -102,6 +170,16 b' class IncludeMatcherTests(unittest.TestC'
102 self.assertTrue(m.visitdir('dir/subdir'))
170 self.assertTrue(m.visitdir('dir/subdir'))
103 self.assertTrue(m.visitdir('dir/subdir/x'))
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 class ExactMatcherTests(unittest.TestCase):
183 class ExactMatcherTests(unittest.TestCase):
106
184
107 def testVisitdir(self):
185 def testVisitdir(self):
@@ -115,6 +193,16 b' class ExactMatcherTests(unittest.TestCas'
115 self.assertFalse(m.visitdir('dir/subdir/x'))
193 self.assertFalse(m.visitdir('dir/subdir/x'))
116 self.assertFalse(m.visitdir('folder'))
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 class DifferenceMatcherTests(unittest.TestCase):
206 class DifferenceMatcherTests(unittest.TestCase):
119
207
120 def testVisitdirM2always(self):
208 def testVisitdirM2always(self):
@@ -130,6 +218,19 b' class DifferenceMatcherTests(unittest.Te'
130 self.assertFalse(dm.visitdir('dir/subdir/x'))
218 self.assertFalse(dm.visitdir('dir/subdir/x'))
131 self.assertFalse(dm.visitdir('folder'))
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 def testVisitdirM2never(self):
234 def testVisitdirM2never(self):
134 m1 = matchmod.alwaysmatcher('', '')
235 m1 = matchmod.alwaysmatcher('', '')
135 m2 = matchmod.nevermatcher('', '')
236 m2 = matchmod.nevermatcher('', '')
@@ -149,6 +250,19 b' class DifferenceMatcherTests(unittest.Te'
149 self.assertEqual(dm.visitdir('dir/subdir/x'), True)
250 self.assertEqual(dm.visitdir('dir/subdir/x'), True)
150 self.assertEqual(dm.visitdir('folder'), True)
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 def testVisitdirM2SubdirPrefix(self):
266 def testVisitdirM2SubdirPrefix(self):
153 m1 = matchmod.alwaysmatcher('', '')
267 m1 = matchmod.alwaysmatcher('', '')
154 m2 = matchmod.match('', '', patterns=['path:dir/subdir'])
268 m2 = matchmod.match('', '', patterns=['path:dir/subdir'])
@@ -165,6 +279,21 b' class DifferenceMatcherTests(unittest.Te'
165 self.assertEqual(dm.visitdir('dir/foo'), True)
279 self.assertEqual(dm.visitdir('dir/foo'), True)
166 self.assertEqual(dm.visitdir('folder'), True)
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 # We're using includematcher instead of patterns because it behaves slightly
297 # We're using includematcher instead of patterns because it behaves slightly
169 # better (giving narrower results) than patternmatcher.
298 # better (giving narrower results) than patternmatcher.
170 def testVisitdirIncludeIncludfe(self):
299 def testVisitdirIncludeIncludfe(self):
@@ -182,6 +311,21 b' class DifferenceMatcherTests(unittest.Te'
182 self.assertEqual(dm.visitdir('dir/subdir/z'), True)
311 self.assertEqual(dm.visitdir('dir/subdir/z'), True)
183 self.assertEqual(dm.visitdir('dir/subdir/x'), True)
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 class IntersectionMatcherTests(unittest.TestCase):
329 class IntersectionMatcherTests(unittest.TestCase):
186
330
187 def testVisitdirM2always(self):
331 def testVisitdirM2always(self):
@@ -197,6 +341,19 b' class IntersectionMatcherTests(unittest.'
197 self.assertEqual(im.visitdir('dir/subdir/x'), 'all')
341 self.assertEqual(im.visitdir('dir/subdir/x'), 'all')
198 self.assertEqual(im.visitdir('folder'), 'all')
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 def testVisitdirM2never(self):
357 def testVisitdirM2never(self):
201 m1 = matchmod.alwaysmatcher('', '')
358 m1 = matchmod.alwaysmatcher('', '')
202 m2 = matchmod.nevermatcher('', '')
359 m2 = matchmod.nevermatcher('', '')
@@ -210,6 +367,19 b' class IntersectionMatcherTests(unittest.'
210 self.assertFalse(im.visitdir('dir/subdir/x'))
367 self.assertFalse(im.visitdir('dir/subdir/x'))
211 self.assertFalse(im.visitdir('folder'))
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 def testVisitdirM2SubdirPrefix(self):
383 def testVisitdirM2SubdirPrefix(self):
214 m1 = matchmod.alwaysmatcher('', '')
384 m1 = matchmod.alwaysmatcher('', '')
215 m2 = matchmod.match('', '', patterns=['path:dir/subdir'])
385 m2 = matchmod.match('', '', patterns=['path:dir/subdir'])
@@ -225,6 +395,19 b' class IntersectionMatcherTests(unittest.'
225 self.assertEqual(im.visitdir('dir/subdir/z'), True)
395 self.assertEqual(im.visitdir('dir/subdir/z'), True)
226 self.assertEqual(im.visitdir('dir/subdir/x'), True)
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 # We're using includematcher instead of patterns because it behaves slightly
411 # We're using includematcher instead of patterns because it behaves slightly
229 # better (giving narrower results) than patternmatcher.
412 # better (giving narrower results) than patternmatcher.
230 def testVisitdirIncludeIncludfe(self):
413 def testVisitdirIncludeIncludfe(self):
@@ -239,6 +422,18 b' class IntersectionMatcherTests(unittest.'
239 self.assertFalse(im.visitdir('dir/subdir/z'))
422 self.assertFalse(im.visitdir('dir/subdir/z'))
240 self.assertFalse(im.visitdir('dir/subdir/x'))
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 # We're using includematcher instead of patterns because it behaves slightly
437 # We're using includematcher instead of patterns because it behaves slightly
243 # better (giving narrower results) than patternmatcher.
438 # better (giving narrower results) than patternmatcher.
244 def testVisitdirIncludeInclude2(self):
439 def testVisitdirIncludeInclude2(self):
@@ -254,6 +449,19 b' class IntersectionMatcherTests(unittest.'
254 self.assertFalse(im.visitdir('dir/subdir/z'))
449 self.assertFalse(im.visitdir('dir/subdir/z'))
255 self.assertFalse(im.visitdir('dir/subdir/x'))
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 # We're using includematcher instead of patterns because it behaves slightly
465 # We're using includematcher instead of patterns because it behaves slightly
258 # better (giving narrower results) than patternmatcher.
466 # better (giving narrower results) than patternmatcher.
259 def testVisitdirIncludeInclude3(self):
467 def testVisitdirIncludeInclude3(self):
@@ -269,6 +477,19 b' class IntersectionMatcherTests(unittest.'
269 # OPT: this should probably be 'all' not True.
477 # OPT: this should probably be 'all' not True.
270 self.assertEqual(im.visitdir('dir/subdir/x'), True)
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 # We're using includematcher instead of patterns because it behaves slightly
493 # We're using includematcher instead of patterns because it behaves slightly
273 # better (giving narrower results) than patternmatcher.
494 # better (giving narrower results) than patternmatcher.
274 def testVisitdirIncludeInclude4(self):
495 def testVisitdirIncludeInclude4(self):
@@ -284,6 +505,19 b' class IntersectionMatcherTests(unittest.'
284 self.assertFalse(im.visitdir('dir/subdir/z'))
505 self.assertFalse(im.visitdir('dir/subdir/z'))
285 self.assertFalse(im.visitdir('dir/subdir/x'))
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 class UnionMatcherTests(unittest.TestCase):
521 class UnionMatcherTests(unittest.TestCase):
288
522
289 def testVisitdirM2always(self):
523 def testVisitdirM2always(self):
@@ -299,6 +533,19 b' class UnionMatcherTests(unittest.TestCas'
299 self.assertEqual(um.visitdir('dir/subdir/x'), 'all')
533 self.assertEqual(um.visitdir('dir/subdir/x'), 'all')
300 self.assertEqual(um.visitdir('folder'), 'all')
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 def testVisitdirM1never(self):
549 def testVisitdirM1never(self):
303 m1 = matchmod.nevermatcher('', '')
550 m1 = matchmod.nevermatcher('', '')
304 m2 = matchmod.alwaysmatcher('', '')
551 m2 = matchmod.alwaysmatcher('', '')
@@ -312,6 +559,19 b' class UnionMatcherTests(unittest.TestCas'
312 self.assertEqual(um.visitdir('dir/subdir/x'), 'all')
559 self.assertEqual(um.visitdir('dir/subdir/x'), 'all')
313 self.assertEqual(um.visitdir('folder'), 'all')
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 def testVisitdirM2never(self):
575 def testVisitdirM2never(self):
316 m1 = matchmod.alwaysmatcher('', '')
576 m1 = matchmod.alwaysmatcher('', '')
317 m2 = matchmod.nevermatcher('', '')
577 m2 = matchmod.nevermatcher('', '')
@@ -325,6 +585,19 b' class UnionMatcherTests(unittest.TestCas'
325 self.assertEqual(um.visitdir('dir/subdir/x'), 'all')
585 self.assertEqual(um.visitdir('dir/subdir/x'), 'all')
326 self.assertEqual(um.visitdir('folder'), 'all')
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 def testVisitdirM2SubdirPrefix(self):
601 def testVisitdirM2SubdirPrefix(self):
329 m1 = matchmod.alwaysmatcher('', '')
602 m1 = matchmod.alwaysmatcher('', '')
330 m2 = matchmod.match('', '', patterns=['path:dir/subdir'])
603 m2 = matchmod.match('', '', patterns=['path:dir/subdir'])
@@ -337,6 +610,18 b' class UnionMatcherTests(unittest.TestCas'
337 self.assertEqual(um.visitdir('dir/subdir/z'), 'all')
610 self.assertEqual(um.visitdir('dir/subdir/z'), 'all')
338 self.assertEqual(um.visitdir('dir/subdir/x'), 'all')
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 # We're using includematcher instead of patterns because it behaves slightly
625 # We're using includematcher instead of patterns because it behaves slightly
341 # better (giving narrower results) than patternmatcher.
626 # better (giving narrower results) than patternmatcher.
342 def testVisitdirIncludeIncludfe(self):
627 def testVisitdirIncludeIncludfe(self):
@@ -352,6 +637,19 b' class UnionMatcherTests(unittest.TestCas'
352 self.assertEqual(um.visitdir('dir/subdir/z'), True)
637 self.assertEqual(um.visitdir('dir/subdir/z'), True)
353 self.assertEqual(um.visitdir('dir/subdir/x'), True)
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 # We're using includematcher instead of patterns because it behaves slightly
653 # We're using includematcher instead of patterns because it behaves slightly
356 # better (giving narrower results) than patternmatcher.
654 # better (giving narrower results) than patternmatcher.
357 def testVisitdirIncludeInclude2(self):
655 def testVisitdirIncludeInclude2(self):
@@ -367,6 +665,19 b' class UnionMatcherTests(unittest.TestCas'
367 self.assertEqual(um.visitdir('dir/subdir/z'), True)
665 self.assertEqual(um.visitdir('dir/subdir/z'), True)
368 self.assertEqual(um.visitdir('dir/subdir/x'), True)
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 # We're using includematcher instead of patterns because it behaves slightly
681 # We're using includematcher instead of patterns because it behaves slightly
371 # better (giving narrower results) than patternmatcher.
682 # better (giving narrower results) than patternmatcher.
372 def testVisitdirIncludeInclude3(self):
683 def testVisitdirIncludeInclude3(self):
@@ -382,6 +693,19 b' class UnionMatcherTests(unittest.TestCas'
382 # OPT: this should probably be 'all' not True.
693 # OPT: this should probably be 'all' not True.
383 self.assertEqual(um.visitdir('dir/subdir/z'), True)
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 # We're using includematcher instead of patterns because it behaves slightly
709 # We're using includematcher instead of patterns because it behaves slightly
386 # better (giving narrower results) than patternmatcher.
710 # better (giving narrower results) than patternmatcher.
387 def testVisitdirIncludeInclude4(self):
711 def testVisitdirIncludeInclude4(self):
@@ -397,6 +721,18 b' class UnionMatcherTests(unittest.TestCas'
397 self.assertEqual(um.visitdir('dir/subdir/z'), 'all')
721 self.assertEqual(um.visitdir('dir/subdir/z'), 'all')
398 self.assertEqual(um.visitdir('dir/subdir/x'), 'all')
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 class SubdirMatcherTests(unittest.TestCase):
736 class SubdirMatcherTests(unittest.TestCase):
401
737
402 def testVisitdir(self):
738 def testVisitdir(self):
@@ -410,6 +746,17 b' class SubdirMatcherTests(unittest.TestCa'
410 self.assertEqual(sm.visitdir('subdir/z'), True)
746 self.assertEqual(sm.visitdir('subdir/z'), True)
411 self.assertFalse(sm.visitdir('foo'))
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 class PrefixdirMatcherTests(unittest.TestCase):
760 class PrefixdirMatcherTests(unittest.TestCase):
414
761
415 def testVisitdir(self):
762 def testVisitdir(self):
@@ -444,5 +791,27 b' class PrefixdirMatcherTests(unittest.Tes'
444 self.assertEqual(pm.visitdir('d/e/f'), True)
791 self.assertEqual(pm.visitdir('d/e/f'), True)
445 self.assertEqual(pm.visitdir('d/e/f/g'), False)
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 if __name__ == '__main__':
816 if __name__ == '__main__':
448 silenttestrunner.main(__name__)
817 silenttestrunner.main(__name__)
General Comments 0
You need to be logged in to leave comments. Login now