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