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