| 1 |
import unittest |
| 2 |
|
| 3 |
import silenttestrunner |
| 4 |
|
| 5 |
from mercurial import ( |
| 6 |
match as matchmod, |
| 7 |
util, |
| 8 |
) |
| 9 |
|
| 10 |
|
| 11 |
noop_auditor = lambda name: None |
| 12 |
|
| 13 |
|
| 14 |
class BaseMatcherTests(unittest.TestCase): |
| 15 |
def testVisitdir(self): |
| 16 |
m = matchmod.basematcher() |
| 17 |
self.assertTrue(m.visitdir(b'')) |
| 18 |
self.assertTrue(m.visitdir(b'dir')) |
| 19 |
|
| 20 |
def testVisitchildrenset(self): |
| 21 |
m = matchmod.basematcher() |
| 22 |
self.assertEqual(m.visitchildrenset(b''), b'this') |
| 23 |
self.assertEqual(m.visitchildrenset(b'dir'), b'this') |
| 24 |
|
| 25 |
|
| 26 |
class AlwaysMatcherTests(unittest.TestCase): |
| 27 |
def testVisitdir(self): |
| 28 |
m = matchmod.alwaysmatcher() |
| 29 |
self.assertEqual(m.visitdir(b''), b'all') |
| 30 |
self.assertEqual(m.visitdir(b'dir'), b'all') |
| 31 |
|
| 32 |
def testVisitchildrenset(self): |
| 33 |
m = matchmod.alwaysmatcher() |
| 34 |
self.assertEqual(m.visitchildrenset(b''), b'all') |
| 35 |
self.assertEqual(m.visitchildrenset(b'dir'), b'all') |
| 36 |
|
| 37 |
|
| 38 |
class NeverMatcherTests(unittest.TestCase): |
| 39 |
def testVisitdir(self): |
| 40 |
m = matchmod.nevermatcher() |
| 41 |
self.assertFalse(m.visitdir(b'')) |
| 42 |
self.assertFalse(m.visitdir(b'dir')) |
| 43 |
|
| 44 |
def testVisitchildrenset(self): |
| 45 |
m = matchmod.nevermatcher() |
| 46 |
self.assertEqual(m.visitchildrenset(b''), set()) |
| 47 |
self.assertEqual(m.visitchildrenset(b'dir'), set()) |
| 48 |
|
| 49 |
|
| 50 |
class PredicateMatcherTests(unittest.TestCase): |
| 51 |
# predicatematcher does not currently define either of these methods, so |
| 52 |
# this is equivalent to BaseMatcherTests. |
| 53 |
|
| 54 |
def testVisitdir(self): |
| 55 |
m = matchmod.predicatematcher(lambda *a: False) |
| 56 |
self.assertTrue(m.visitdir(b'')) |
| 57 |
self.assertTrue(m.visitdir(b'dir')) |
| 58 |
|
| 59 |
def testVisitchildrenset(self): |
| 60 |
m = matchmod.predicatematcher(lambda *a: False) |
| 61 |
self.assertEqual(m.visitchildrenset(b''), b'this') |
| 62 |
self.assertEqual(m.visitchildrenset(b'dir'), b'this') |
| 63 |
|
| 64 |
|
| 65 |
class PatternMatcherTests(unittest.TestCase): |
| 66 |
def testVisitdirPrefix(self): |
| 67 |
m = matchmod.match( |
| 68 |
util.localpath(b'/repo'), b'', patterns=[b'path:dir/subdir'] |
| 69 |
) |
| 70 |
assert isinstance(m, matchmod.patternmatcher) |
| 71 |
self.assertTrue(m.visitdir(b'')) |
| 72 |
self.assertTrue(m.visitdir(b'dir')) |
| 73 |
self.assertEqual(m.visitdir(b'dir/subdir'), b'all') |
| 74 |
# OPT: This should probably be 'all' if its parent is? |
| 75 |
self.assertTrue(m.visitdir(b'dir/subdir/x')) |
| 76 |
self.assertFalse(m.visitdir(b'folder')) |
| 77 |
|
| 78 |
def testVisitchildrensetPrefix(self): |
| 79 |
m = matchmod.match( |
| 80 |
util.localpath(b'/repo'), b'', patterns=[b'path:dir/subdir'] |
| 81 |
) |
| 82 |
assert isinstance(m, matchmod.patternmatcher) |
| 83 |
self.assertEqual(m.visitchildrenset(b''), b'this') |
| 84 |
self.assertEqual(m.visitchildrenset(b'dir'), b'this') |
| 85 |
self.assertEqual(m.visitchildrenset(b'dir/subdir'), b'all') |
| 86 |
# OPT: This should probably be 'all' if its parent is? |
| 87 |
self.assertEqual(m.visitchildrenset(b'dir/subdir/x'), b'this') |
| 88 |
self.assertEqual(m.visitchildrenset(b'folder'), set()) |
| 89 |
|
| 90 |
def testVisitdirRootfilesin(self): |
| 91 |
m = matchmod.match( |
| 92 |
util.localpath(b'/repo'), |
| 93 |
b'', |
| 94 |
patterns=[b'rootfilesin:dir/subdir'], |
| 95 |
) |
| 96 |
assert isinstance(m, matchmod.patternmatcher) |
| 97 |
# OPT: we shouldn't visit [x] as a directory, |
| 98 |
# but we should still visit it as a file. |
| 99 |
# Unfortunately, `visitdir` is used for both. |
| 100 |
self.assertTrue(m.visitdir(b'dir/subdir/x')) |
| 101 |
self.assertFalse(m.visitdir(b'folder')) |
| 102 |
self.assertTrue(m.visitdir(b'')) |
| 103 |
self.assertTrue(m.visitdir(b'dir')) |
| 104 |
self.assertTrue(m.visitdir(b'dir/subdir')) |
| 105 |
|
| 106 |
def testVisitchildrensetRootfilesin(self): |
| 107 |
m = matchmod.match( |
| 108 |
util.localpath(b'/repo'), |
| 109 |
b'', |
| 110 |
patterns=[b'rootfilesin:dir/subdir'], |
| 111 |
) |
| 112 |
assert isinstance(m, matchmod.patternmatcher) |
| 113 |
self.assertEqual(m.visitchildrenset(b'dir/subdir/x'), b'this') |
| 114 |
self.assertEqual(m.visitchildrenset(b'folder'), set()) |
| 115 |
# OPT: These should probably be {'dir'}, {'subdir'} and 'this', |
| 116 |
# respectively |
| 117 |
self.assertEqual(m.visitchildrenset(b''), b'this') |
| 118 |
self.assertEqual(m.visitchildrenset(b'dir'), b'this') |
| 119 |
self.assertEqual(m.visitchildrenset(b'dir/subdir'), b'this') |
| 120 |
|
| 121 |
def testVisitdirGlob(self): |
| 122 |
m = matchmod.match( |
| 123 |
util.localpath(b'/repo'), b'', patterns=[b'glob:dir/z*'] |
| 124 |
) |
| 125 |
assert isinstance(m, matchmod.patternmatcher) |
| 126 |
self.assertTrue(m.visitdir(b'')) |
| 127 |
self.assertTrue(m.visitdir(b'dir')) |
| 128 |
self.assertFalse(m.visitdir(b'folder')) |
| 129 |
# OPT: these should probably be False. |
| 130 |
self.assertTrue(m.visitdir(b'dir/subdir')) |
| 131 |
self.assertTrue(m.visitdir(b'dir/subdir/x')) |
| 132 |
|
| 133 |
def testVisitchildrensetGlob(self): |
| 134 |
m = matchmod.match( |
| 135 |
util.localpath(b'/repo'), b'', patterns=[b'glob:dir/z*'] |
| 136 |
) |
| 137 |
assert isinstance(m, matchmod.patternmatcher) |
| 138 |
self.assertEqual(m.visitchildrenset(b''), b'this') |
| 139 |
self.assertEqual(m.visitchildrenset(b'folder'), set()) |
| 140 |
self.assertEqual(m.visitchildrenset(b'dir'), b'this') |
| 141 |
# OPT: these should probably be set(). |
| 142 |
self.assertEqual(m.visitchildrenset(b'dir/subdir'), b'this') |
| 143 |
self.assertEqual(m.visitchildrenset(b'dir/subdir/x'), b'this') |
| 144 |
|
| 145 |
def testVisitdirFilepath(self): |
| 146 |
m = matchmod.match( |
| 147 |
util.localpath(b'/repo'), b'', patterns=[b'filepath:dir/z'] |
| 148 |
) |
| 149 |
assert isinstance(m, matchmod.patternmatcher) |
| 150 |
self.assertTrue(m.visitdir(b'')) |
| 151 |
self.assertTrue(m.visitdir(b'dir')) |
| 152 |
self.assertFalse(m.visitdir(b'folder')) |
| 153 |
self.assertFalse(m.visitdir(b'dir/subdir')) |
| 154 |
self.assertFalse(m.visitdir(b'dir/subdir/x')) |
| 155 |
|
| 156 |
def testVisitchildrensetFilepath(self): |
| 157 |
m = matchmod.match( |
| 158 |
util.localpath(b'/repo'), b'', patterns=[b'filepath:dir/z'] |
| 159 |
) |
| 160 |
assert isinstance(m, matchmod.patternmatcher) |
| 161 |
self.assertEqual(m.visitchildrenset(b''), b'this') |
| 162 |
self.assertEqual(m.visitchildrenset(b'folder'), set()) |
| 163 |
self.assertEqual(m.visitchildrenset(b'dir'), b'this') |
| 164 |
self.assertEqual(m.visitchildrenset(b'dir/subdir'), set()) |
| 165 |
self.assertEqual(m.visitchildrenset(b'dir/subdir/x'), set()) |
| 166 |
|
| 167 |
|
| 168 |
class IncludeMatcherTests(unittest.TestCase): |
| 169 |
def testVisitdirPrefix(self): |
| 170 |
m = matchmod.match( |
| 171 |
util.localpath(b'/repo'), b'', include=[b'path:dir/subdir'] |
| 172 |
) |
| 173 |
assert isinstance(m, matchmod.includematcher) |
| 174 |
self.assertTrue(m.visitdir(b'')) |
| 175 |
self.assertTrue(m.visitdir(b'dir')) |
| 176 |
self.assertEqual(m.visitdir(b'dir/subdir'), b'all') |
| 177 |
# OPT: This should probably be 'all' if its parent is? |
| 178 |
self.assertTrue(m.visitdir(b'dir/subdir/x')) |
| 179 |
self.assertFalse(m.visitdir(b'folder')) |
| 180 |
|
| 181 |
def testVisitchildrensetPrefix(self): |
| 182 |
m = matchmod.match( |
| 183 |
util.localpath(b'/repo'), b'', include=[b'path:dir/subdir'] |
| 184 |
) |
| 185 |
assert isinstance(m, matchmod.includematcher) |
| 186 |
self.assertEqual(m.visitchildrenset(b''), {b'dir'}) |
| 187 |
self.assertEqual(m.visitchildrenset(b'dir'), {b'subdir'}) |
| 188 |
self.assertEqual(m.visitchildrenset(b'dir/subdir'), b'all') |
| 189 |
# OPT: This should probably be 'all' if its parent is? |
| 190 |
self.assertEqual(m.visitchildrenset(b'dir/subdir/x'), b'this') |
| 191 |
self.assertEqual(m.visitchildrenset(b'folder'), set()) |
| 192 |
|
| 193 |
def testVisitdirRootfilesin(self): |
| 194 |
m = matchmod.match( |
| 195 |
util.localpath(b'/repo'), b'', include=[b'rootfilesin:dir/subdir'] |
| 196 |
) |
| 197 |
assert isinstance(m, matchmod.includematcher) |
| 198 |
self.assertTrue(m.visitdir(b'')) |
| 199 |
self.assertTrue(m.visitdir(b'dir')) |
| 200 |
self.assertTrue(m.visitdir(b'dir/subdir')) |
| 201 |
self.assertFalse(m.visitdir(b'dir/subdir/x')) |
| 202 |
self.assertFalse(m.visitdir(b'folder')) |
| 203 |
|
| 204 |
def testVisitchildrensetRootfilesin(self): |
| 205 |
m = matchmod.match( |
| 206 |
util.localpath(b'/repo'), b'', include=[b'rootfilesin:dir/subdir'] |
| 207 |
) |
| 208 |
assert isinstance(m, matchmod.includematcher) |
| 209 |
self.assertEqual(m.visitchildrenset(b''), {b'dir'}) |
| 210 |
self.assertEqual(m.visitchildrenset(b'dir'), {b'subdir'}) |
| 211 |
self.assertEqual(m.visitchildrenset(b'dir/subdir'), b'this') |
| 212 |
self.assertEqual(m.visitchildrenset(b'dir/subdir/x'), set()) |
| 213 |
self.assertEqual(m.visitchildrenset(b'folder'), set()) |
| 214 |
|
| 215 |
def testVisitdirGlob(self): |
| 216 |
m = matchmod.match( |
| 217 |
util.localpath(b'/repo'), b'', include=[b'glob:dir/z*'] |
| 218 |
) |
| 219 |
assert isinstance(m, matchmod.includematcher) |
| 220 |
self.assertTrue(m.visitdir(b'')) |
| 221 |
self.assertTrue(m.visitdir(b'dir')) |
| 222 |
self.assertFalse(m.visitdir(b'folder')) |
| 223 |
# OPT: these should probably be False. |
| 224 |
self.assertTrue(m.visitdir(b'dir/subdir')) |
| 225 |
self.assertTrue(m.visitdir(b'dir/subdir/x')) |
| 226 |
|
| 227 |
def testVisitchildrensetGlob(self): |
| 228 |
m = matchmod.match( |
| 229 |
util.localpath(b'/repo'), b'', include=[b'glob:dir/z*'] |
| 230 |
) |
| 231 |
assert isinstance(m, matchmod.includematcher) |
| 232 |
self.assertEqual(m.visitchildrenset(b''), {b'dir'}) |
| 233 |
self.assertEqual(m.visitchildrenset(b'folder'), set()) |
| 234 |
self.assertEqual(m.visitchildrenset(b'dir'), b'this') |
| 235 |
# OPT: these should probably be set(). |
| 236 |
self.assertEqual(m.visitchildrenset(b'dir/subdir'), b'this') |
| 237 |
self.assertEqual(m.visitchildrenset(b'dir/subdir/x'), b'this') |
| 238 |
|
| 239 |
def testVisitdirFilepath(self): |
| 240 |
m = matchmod.match( |
| 241 |
util.localpath(b'/repo'), b'', include=[b'filepath:dir/z'] |
| 242 |
) |
| 243 |
assert isinstance(m, matchmod.includematcher) |
| 244 |
self.assertTrue(m.visitdir(b'')) |
| 245 |
self.assertTrue(m.visitdir(b'dir')) |
| 246 |
self.assertFalse(m.visitdir(b'folder')) |
| 247 |
self.assertFalse(m.visitdir(b'dir/subdir')) |
| 248 |
self.assertFalse(m.visitdir(b'dir/subdir/x')) |
| 249 |
|
| 250 |
def testVisitchildrensetFilepath(self): |
| 251 |
m = matchmod.match( |
| 252 |
util.localpath(b'/repo'), b'', include=[b'filepath:dir/z'] |
| 253 |
) |
| 254 |
assert isinstance(m, matchmod.includematcher) |
| 255 |
self.assertEqual(m.visitchildrenset(b''), {b'dir'}) |
| 256 |
self.assertEqual(m.visitchildrenset(b'folder'), set()) |
| 257 |
self.assertEqual(m.visitchildrenset(b'dir'), {b'z'}) |
| 258 |
self.assertEqual(m.visitchildrenset(b'dir/subdir'), set()) |
| 259 |
self.assertEqual(m.visitchildrenset(b'dir/subdir/x'), set()) |
| 260 |
|
| 261 |
|
| 262 |
class ExactMatcherTests(unittest.TestCase): |
| 263 |
def testVisitdir(self): |
| 264 |
m = matchmod.exact(files=[b'dir/subdir/foo.txt']) |
| 265 |
assert isinstance(m, matchmod.exactmatcher) |
| 266 |
self.assertTrue(m.visitdir(b'')) |
| 267 |
self.assertTrue(m.visitdir(b'dir')) |
| 268 |
self.assertTrue(m.visitdir(b'dir/subdir')) |
| 269 |
self.assertFalse(m.visitdir(b'dir/subdir/foo.txt')) |
| 270 |
self.assertFalse(m.visitdir(b'dir/foo')) |
| 271 |
self.assertFalse(m.visitdir(b'dir/subdir/x')) |
| 272 |
self.assertFalse(m.visitdir(b'folder')) |
| 273 |
|
| 274 |
def testVisitchildrenset(self): |
| 275 |
m = matchmod.exact(files=[b'dir/subdir/foo.txt']) |
| 276 |
assert isinstance(m, matchmod.exactmatcher) |
| 277 |
self.assertEqual(m.visitchildrenset(b''), {b'dir'}) |
| 278 |
self.assertEqual(m.visitchildrenset(b'dir'), {b'subdir'}) |
| 279 |
self.assertEqual(m.visitchildrenset(b'dir/subdir'), {b'foo.txt'}) |
| 280 |
self.assertEqual(m.visitchildrenset(b'dir/subdir/x'), set()) |
| 281 |
self.assertEqual(m.visitchildrenset(b'dir/subdir/foo.txt'), set()) |
| 282 |
self.assertEqual(m.visitchildrenset(b'folder'), set()) |
| 283 |
|
| 284 |
def testVisitchildrensetFilesAndDirs(self): |
| 285 |
m = matchmod.exact( |
| 286 |
files=[ |
| 287 |
b'rootfile.txt', |
| 288 |
b'a/file1.txt', |
| 289 |
b'a/b/file2.txt', |
| 290 |
# no file in a/b/c |
| 291 |
b'a/b/c/d/file4.txt', |
| 292 |
] |
| 293 |
) |
| 294 |
assert isinstance(m, matchmod.exactmatcher) |
| 295 |
self.assertEqual(m.visitchildrenset(b''), {b'a', b'rootfile.txt'}) |
| 296 |
self.assertEqual(m.visitchildrenset(b'a'), {b'b', b'file1.txt'}) |
| 297 |
self.assertEqual(m.visitchildrenset(b'a/b'), {b'c', b'file2.txt'}) |
| 298 |
self.assertEqual(m.visitchildrenset(b'a/b/c'), {b'd'}) |
| 299 |
self.assertEqual(m.visitchildrenset(b'a/b/c/d'), {b'file4.txt'}) |
| 300 |
self.assertEqual(m.visitchildrenset(b'a/b/c/d/e'), set()) |
| 301 |
self.assertEqual(m.visitchildrenset(b'folder'), set()) |
| 302 |
|
| 303 |
|
| 304 |
class DifferenceMatcherTests(unittest.TestCase): |
| 305 |
def testVisitdirM2always(self): |
| 306 |
m1 = matchmod.alwaysmatcher() |
| 307 |
m2 = matchmod.alwaysmatcher() |
| 308 |
dm = matchmod.differencematcher(m1, m2) |
| 309 |
# dm should be equivalent to a nevermatcher. |
| 310 |
self.assertFalse(dm.visitdir(b'')) |
| 311 |
self.assertFalse(dm.visitdir(b'dir')) |
| 312 |
self.assertFalse(dm.visitdir(b'dir/subdir')) |
| 313 |
self.assertFalse(dm.visitdir(b'dir/subdir/z')) |
| 314 |
self.assertFalse(dm.visitdir(b'dir/foo')) |
| 315 |
self.assertFalse(dm.visitdir(b'dir/subdir/x')) |
| 316 |
self.assertFalse(dm.visitdir(b'folder')) |
| 317 |
|
| 318 |
def testVisitchildrensetM2always(self): |
| 319 |
m1 = matchmod.alwaysmatcher() |
| 320 |
m2 = matchmod.alwaysmatcher() |
| 321 |
dm = matchmod.differencematcher(m1, m2) |
| 322 |
# dm should be equivalent to a nevermatcher. |
| 323 |
self.assertEqual(dm.visitchildrenset(b''), set()) |
| 324 |
self.assertEqual(dm.visitchildrenset(b'dir'), set()) |
| 325 |
self.assertEqual(dm.visitchildrenset(b'dir/subdir'), set()) |
| 326 |
self.assertEqual(dm.visitchildrenset(b'dir/subdir/z'), set()) |
| 327 |
self.assertEqual(dm.visitchildrenset(b'dir/foo'), set()) |
| 328 |
self.assertEqual(dm.visitchildrenset(b'dir/subdir/x'), set()) |
| 329 |
self.assertEqual(dm.visitchildrenset(b'folder'), set()) |
| 330 |
|
| 331 |
def testVisitdirM2never(self): |
| 332 |
m1 = matchmod.alwaysmatcher() |
| 333 |
m2 = matchmod.nevermatcher() |
| 334 |
dm = matchmod.differencematcher(m1, m2) |
| 335 |
# dm should be equivalent to a alwaysmatcher. |
| 336 |
# |
| 337 |
# We're testing Equal-to-True instead of just 'assertTrue' since |
| 338 |
# assertTrue does NOT verify that it's a bool, just that it's truthy. |
| 339 |
# While we may want to eventually make these return 'all', they should |
| 340 |
# not currently do so. |
| 341 |
self.assertEqual(dm.visitdir(b''), b'all') |
| 342 |
self.assertEqual(dm.visitdir(b'dir'), b'all') |
| 343 |
self.assertEqual(dm.visitdir(b'dir/subdir'), b'all') |
| 344 |
self.assertEqual(dm.visitdir(b'dir/subdir/z'), b'all') |
| 345 |
self.assertEqual(dm.visitdir(b'dir/foo'), b'all') |
| 346 |
self.assertEqual(dm.visitdir(b'dir/subdir/x'), b'all') |
| 347 |
self.assertEqual(dm.visitdir(b'folder'), b'all') |
| 348 |
|
| 349 |
def testVisitchildrensetM2never(self): |
| 350 |
m1 = matchmod.alwaysmatcher() |
| 351 |
m2 = matchmod.nevermatcher() |
| 352 |
dm = matchmod.differencematcher(m1, m2) |
| 353 |
# dm should be equivalent to a alwaysmatcher. |
| 354 |
self.assertEqual(dm.visitchildrenset(b''), b'all') |
| 355 |
self.assertEqual(dm.visitchildrenset(b'dir'), b'all') |
| 356 |
self.assertEqual(dm.visitchildrenset(b'dir/subdir'), b'all') |
| 357 |
self.assertEqual(dm.visitchildrenset(b'dir/subdir/z'), b'all') |
| 358 |
self.assertEqual(dm.visitchildrenset(b'dir/foo'), b'all') |
| 359 |
self.assertEqual(dm.visitchildrenset(b'dir/subdir/x'), b'all') |
| 360 |
self.assertEqual(dm.visitchildrenset(b'folder'), b'all') |
| 361 |
|
| 362 |
def testVisitdirM2SubdirPrefix(self): |
| 363 |
m1 = matchmod.alwaysmatcher() |
| 364 |
m2 = matchmod.match( |
| 365 |
util.localpath(b'/repo'), b'', patterns=[b'path:dir/subdir'] |
| 366 |
) |
| 367 |
dm = matchmod.differencematcher(m1, m2) |
| 368 |
self.assertEqual(dm.visitdir(b''), True) |
| 369 |
self.assertEqual(dm.visitdir(b'dir'), True) |
| 370 |
self.assertFalse(dm.visitdir(b'dir/subdir')) |
| 371 |
# OPT: We should probably return False for these; we don't because |
| 372 |
# patternmatcher.visitdir() (our m2) doesn't return 'all' for subdirs of |
| 373 |
# an 'all' pattern, just True. |
| 374 |
self.assertEqual(dm.visitdir(b'dir/subdir/z'), True) |
| 375 |
self.assertEqual(dm.visitdir(b'dir/subdir/x'), True) |
| 376 |
self.assertEqual(dm.visitdir(b'dir/foo'), b'all') |
| 377 |
self.assertEqual(dm.visitdir(b'folder'), b'all') |
| 378 |
|
| 379 |
def testVisitchildrensetM2SubdirPrefix(self): |
| 380 |
m1 = matchmod.alwaysmatcher() |
| 381 |
m2 = matchmod.match( |
| 382 |
util.localpath(b'/repo'), b'', patterns=[b'path:dir/subdir'] |
| 383 |
) |
| 384 |
dm = matchmod.differencematcher(m1, m2) |
| 385 |
self.assertEqual(dm.visitchildrenset(b''), b'this') |
| 386 |
self.assertEqual(dm.visitchildrenset(b'dir'), b'this') |
| 387 |
self.assertEqual(dm.visitchildrenset(b'dir/subdir'), set()) |
| 388 |
self.assertEqual(dm.visitchildrenset(b'dir/foo'), b'all') |
| 389 |
self.assertEqual(dm.visitchildrenset(b'folder'), b'all') |
| 390 |
# OPT: We should probably return set() for these; we don't because |
| 391 |
# patternmatcher.visitdir() (our m2) doesn't return 'all' for subdirs of |
| 392 |
# an 'all' pattern, just 'this'. |
| 393 |
self.assertEqual(dm.visitchildrenset(b'dir/subdir/z'), b'this') |
| 394 |
self.assertEqual(dm.visitchildrenset(b'dir/subdir/x'), b'this') |
| 395 |
|
| 396 |
# We're using includematcher instead of patterns because it behaves slightly |
| 397 |
# better (giving narrower results) than patternmatcher. |
| 398 |
def testVisitdirIncludeInclude(self): |
| 399 |
m1 = matchmod.match( |
| 400 |
util.localpath(b'/repo'), b'', include=[b'path:dir/subdir'] |
| 401 |
) |
| 402 |
m2 = matchmod.match( |
| 403 |
util.localpath(b'/repo'), b'', include=[b'rootfilesin:dir'] |
| 404 |
) |
| 405 |
dm = matchmod.differencematcher(m1, m2) |
| 406 |
self.assertEqual(dm.visitdir(b''), True) |
| 407 |
self.assertEqual(dm.visitdir(b'dir'), True) |
| 408 |
self.assertEqual(dm.visitdir(b'dir/subdir'), b'all') |
| 409 |
self.assertFalse(dm.visitdir(b'dir/foo')) |
| 410 |
self.assertFalse(dm.visitdir(b'folder')) |
| 411 |
# OPT: We should probably return False for these; we don't because |
| 412 |
# patternmatcher.visitdir() (our m2) doesn't return 'all' for subdirs of |
| 413 |
# an 'all' pattern, just True. |
| 414 |
self.assertEqual(dm.visitdir(b'dir/subdir/z'), True) |
| 415 |
self.assertEqual(dm.visitdir(b'dir/subdir/x'), True) |
| 416 |
|
| 417 |
def testVisitchildrensetIncludeInclude(self): |
| 418 |
m1 = matchmod.match( |
| 419 |
util.localpath(b'/repo'), b'', include=[b'path:dir/subdir'] |
| 420 |
) |
| 421 |
m2 = matchmod.match( |
| 422 |
util.localpath(b'/repo'), b'', include=[b'rootfilesin:dir'] |
| 423 |
) |
| 424 |
dm = matchmod.differencematcher(m1, m2) |
| 425 |
self.assertEqual(dm.visitchildrenset(b''), {b'dir'}) |
| 426 |
self.assertEqual(dm.visitchildrenset(b'dir'), {b'subdir'}) |
| 427 |
self.assertEqual(dm.visitchildrenset(b'dir/subdir'), b'all') |
| 428 |
self.assertEqual(dm.visitchildrenset(b'dir/foo'), set()) |
| 429 |
self.assertEqual(dm.visitchildrenset(b'folder'), set()) |
| 430 |
# OPT: We should probably return set() for these; we don't because |
| 431 |
# patternmatcher.visitdir() (our m2) doesn't return 'all' for subdirs of |
| 432 |
# an 'all' pattern, just 'this'. |
| 433 |
self.assertEqual(dm.visitchildrenset(b'dir/subdir/z'), b'this') |
| 434 |
self.assertEqual(dm.visitchildrenset(b'dir/subdir/x'), b'this') |
| 435 |
|
| 436 |
|
| 437 |
class IntersectionMatcherTests(unittest.TestCase): |
| 438 |
def testVisitdirM2always(self): |
| 439 |
m1 = matchmod.alwaysmatcher() |
| 440 |
m2 = matchmod.alwaysmatcher() |
| 441 |
im = matchmod.intersectmatchers(m1, m2) |
| 442 |
# im should be equivalent to a alwaysmatcher. |
| 443 |
self.assertEqual(im.visitdir(b''), b'all') |
| 444 |
self.assertEqual(im.visitdir(b'dir'), b'all') |
| 445 |
self.assertEqual(im.visitdir(b'dir/subdir'), b'all') |
| 446 |
self.assertEqual(im.visitdir(b'dir/subdir/z'), b'all') |
| 447 |
self.assertEqual(im.visitdir(b'dir/foo'), b'all') |
| 448 |
self.assertEqual(im.visitdir(b'dir/subdir/x'), b'all') |
| 449 |
self.assertEqual(im.visitdir(b'folder'), b'all') |
| 450 |
|
| 451 |
def testVisitchildrensetM2always(self): |
| 452 |
m1 = matchmod.alwaysmatcher() |
| 453 |
m2 = matchmod.alwaysmatcher() |
| 454 |
im = matchmod.intersectmatchers(m1, m2) |
| 455 |
# im should be equivalent to a alwaysmatcher. |
| 456 |
self.assertEqual(im.visitchildrenset(b''), b'all') |
| 457 |
self.assertEqual(im.visitchildrenset(b'dir'), b'all') |
| 458 |
self.assertEqual(im.visitchildrenset(b'dir/subdir'), b'all') |
| 459 |
self.assertEqual(im.visitchildrenset(b'dir/subdir/z'), b'all') |
| 460 |
self.assertEqual(im.visitchildrenset(b'dir/foo'), b'all') |
| 461 |
self.assertEqual(im.visitchildrenset(b'dir/subdir/x'), b'all') |
| 462 |
self.assertEqual(im.visitchildrenset(b'folder'), b'all') |
| 463 |
|
| 464 |
def testVisitdirM2never(self): |
| 465 |
m1 = matchmod.alwaysmatcher() |
| 466 |
m2 = matchmod.nevermatcher() |
| 467 |
im = matchmod.intersectmatchers(m1, m2) |
| 468 |
# im should be equivalent to a nevermatcher. |
| 469 |
self.assertFalse(im.visitdir(b'')) |
| 470 |
self.assertFalse(im.visitdir(b'dir')) |
| 471 |
self.assertFalse(im.visitdir(b'dir/subdir')) |
| 472 |
self.assertFalse(im.visitdir(b'dir/subdir/z')) |
| 473 |
self.assertFalse(im.visitdir(b'dir/foo')) |
| 474 |
self.assertFalse(im.visitdir(b'dir/subdir/x')) |
| 475 |
self.assertFalse(im.visitdir(b'folder')) |
| 476 |
|
| 477 |
def testVisitchildrensetM2never(self): |
| 478 |
m1 = matchmod.alwaysmatcher() |
| 479 |
m2 = matchmod.nevermatcher() |
| 480 |
im = matchmod.intersectmatchers(m1, m2) |
| 481 |
# im should be equivalent to a nevermqtcher. |
| 482 |
self.assertEqual(im.visitchildrenset(b''), set()) |
| 483 |
self.assertEqual(im.visitchildrenset(b'dir'), set()) |
| 484 |
self.assertEqual(im.visitchildrenset(b'dir/subdir'), set()) |
| 485 |
self.assertEqual(im.visitchildrenset(b'dir/subdir/z'), set()) |
| 486 |
self.assertEqual(im.visitchildrenset(b'dir/foo'), set()) |
| 487 |
self.assertEqual(im.visitchildrenset(b'dir/subdir/x'), set()) |
| 488 |
self.assertEqual(im.visitchildrenset(b'folder'), set()) |
| 489 |
|
| 490 |
def testVisitdirM2SubdirPrefix(self): |
| 491 |
m1 = matchmod.alwaysmatcher() |
| 492 |
m2 = matchmod.match( |
| 493 |
util.localpath(b'/repo'), b'', patterns=[b'path:dir/subdir'] |
| 494 |
) |
| 495 |
im = matchmod.intersectmatchers(m1, m2) |
| 496 |
self.assertEqual(im.visitdir(b''), True) |
| 497 |
self.assertEqual(im.visitdir(b'dir'), True) |
| 498 |
self.assertEqual(im.visitdir(b'dir/subdir'), b'all') |
| 499 |
self.assertFalse(im.visitdir(b'dir/foo')) |
| 500 |
self.assertFalse(im.visitdir(b'folder')) |
| 501 |
# OPT: We should probably return 'all' for these; we don't because |
| 502 |
# patternmatcher.visitdir() (our m2) doesn't return 'all' for subdirs of |
| 503 |
# an 'all' pattern, just True. |
| 504 |
self.assertEqual(im.visitdir(b'dir/subdir/z'), True) |
| 505 |
self.assertEqual(im.visitdir(b'dir/subdir/x'), True) |
| 506 |
|
| 507 |
def testVisitchildrensetM2SubdirPrefix(self): |
| 508 |
m1 = matchmod.alwaysmatcher() |
| 509 |
m2 = matchmod.match( |
| 510 |
util.localpath(b'/repo'), b'', include=[b'path:dir/subdir'] |
| 511 |
) |
| 512 |
im = matchmod.intersectmatchers(m1, m2) |
| 513 |
self.assertEqual(im.visitchildrenset(b''), {b'dir'}) |
| 514 |
self.assertEqual(im.visitchildrenset(b'dir'), {b'subdir'}) |
| 515 |
self.assertEqual(im.visitchildrenset(b'dir/subdir'), b'all') |
| 516 |
self.assertEqual(im.visitchildrenset(b'dir/foo'), set()) |
| 517 |
self.assertEqual(im.visitchildrenset(b'folder'), set()) |
| 518 |
# OPT: We should probably return 'all' for these |
| 519 |
self.assertEqual(im.visitchildrenset(b'dir/subdir/z'), b'this') |
| 520 |
self.assertEqual(im.visitchildrenset(b'dir/subdir/x'), b'this') |
| 521 |
|
| 522 |
# We're using includematcher instead of patterns because it behaves slightly |
| 523 |
# better (giving narrower results) than patternmatcher. |
| 524 |
def testVisitdirIncludeInclude(self): |
| 525 |
m1 = matchmod.match( |
| 526 |
util.localpath(b'/repo'), b'', include=[b'path:dir/subdir'] |
| 527 |
) |
| 528 |
m2 = matchmod.match( |
| 529 |
util.localpath(b'/repo'), b'', include=[b'rootfilesin:dir'] |
| 530 |
) |
| 531 |
im = matchmod.intersectmatchers(m1, m2) |
| 532 |
self.assertEqual(im.visitdir(b''), True) |
| 533 |
self.assertEqual(im.visitdir(b'dir'), True) |
| 534 |
self.assertFalse(im.visitdir(b'dir/subdir')) |
| 535 |
self.assertFalse(im.visitdir(b'dir/foo')) |
| 536 |
self.assertFalse(im.visitdir(b'folder')) |
| 537 |
self.assertFalse(im.visitdir(b'dir/subdir/z')) |
| 538 |
self.assertFalse(im.visitdir(b'dir/subdir/x')) |
| 539 |
|
| 540 |
def testVisitchildrensetIncludeInclude(self): |
| 541 |
m1 = matchmod.match( |
| 542 |
util.localpath(b'/repo'), b'', include=[b'path:dir/subdir'] |
| 543 |
) |
| 544 |
m2 = matchmod.match( |
| 545 |
util.localpath(b'/repo'), b'', include=[b'rootfilesin:dir'] |
| 546 |
) |
| 547 |
im = matchmod.intersectmatchers(m1, m2) |
| 548 |
self.assertEqual(im.visitchildrenset(b''), {b'dir'}) |
| 549 |
self.assertEqual(im.visitchildrenset(b'dir'), b'this') |
| 550 |
self.assertEqual(im.visitchildrenset(b'dir/subdir'), set()) |
| 551 |
self.assertEqual(im.visitchildrenset(b'dir/foo'), set()) |
| 552 |
self.assertEqual(im.visitchildrenset(b'folder'), set()) |
| 553 |
self.assertEqual(im.visitchildrenset(b'dir/subdir/z'), set()) |
| 554 |
self.assertEqual(im.visitchildrenset(b'dir/subdir/x'), set()) |
| 555 |
|
| 556 |
# We're using includematcher instead of patterns because it behaves slightly |
| 557 |
# better (giving narrower results) than patternmatcher. |
| 558 |
def testVisitdirIncludeInclude2(self): |
| 559 |
m1 = matchmod.match( |
| 560 |
util.localpath(b'/repo'), b'', include=[b'path:dir/subdir'] |
| 561 |
) |
| 562 |
m2 = matchmod.match( |
| 563 |
util.localpath(b'/repo'), b'', include=[b'path:folder'] |
| 564 |
) |
| 565 |
im = matchmod.intersectmatchers(m1, m2) |
| 566 |
# FIXME: is True correct here? |
| 567 |
self.assertEqual(im.visitdir(b''), True) |
| 568 |
self.assertFalse(im.visitdir(b'dir')) |
| 569 |
self.assertFalse(im.visitdir(b'dir/subdir')) |
| 570 |
self.assertFalse(im.visitdir(b'dir/foo')) |
| 571 |
self.assertFalse(im.visitdir(b'folder')) |
| 572 |
self.assertFalse(im.visitdir(b'dir/subdir/z')) |
| 573 |
self.assertFalse(im.visitdir(b'dir/subdir/x')) |
| 574 |
|
| 575 |
def testVisitchildrensetIncludeInclude2(self): |
| 576 |
m1 = matchmod.match( |
| 577 |
util.localpath(b'/repo'), b'', include=[b'path:dir/subdir'] |
| 578 |
) |
| 579 |
m2 = matchmod.match( |
| 580 |
util.localpath(b'/repo'), b'', include=[b'path:folder'] |
| 581 |
) |
| 582 |
im = matchmod.intersectmatchers(m1, m2) |
| 583 |
# FIXME: is set() correct here? |
| 584 |
self.assertEqual(im.visitchildrenset(b''), set()) |
| 585 |
self.assertEqual(im.visitchildrenset(b'dir'), set()) |
| 586 |
self.assertEqual(im.visitchildrenset(b'dir/subdir'), set()) |
| 587 |
self.assertEqual(im.visitchildrenset(b'dir/foo'), set()) |
| 588 |
self.assertEqual(im.visitchildrenset(b'folder'), set()) |
| 589 |
self.assertEqual(im.visitchildrenset(b'dir/subdir/z'), set()) |
| 590 |
self.assertEqual(im.visitchildrenset(b'dir/subdir/x'), set()) |
| 591 |
|
| 592 |
# We're using includematcher instead of patterns because it behaves slightly |
| 593 |
# better (giving narrower results) than patternmatcher. |
| 594 |
def testVisitdirIncludeInclude3(self): |
| 595 |
m1 = matchmod.match( |
| 596 |
util.localpath(b'/repo'), b'', include=[b'path:dir/subdir/x'] |
| 597 |
) |
| 598 |
m2 = matchmod.match( |
| 599 |
util.localpath(b'/repo'), b'', include=[b'path:dir/subdir'] |
| 600 |
) |
| 601 |
im = matchmod.intersectmatchers(m1, m2) |
| 602 |
self.assertEqual(im.visitdir(b''), True) |
| 603 |
self.assertEqual(im.visitdir(b'dir'), True) |
| 604 |
self.assertEqual(im.visitdir(b'dir/subdir'), True) |
| 605 |
self.assertFalse(im.visitdir(b'dir/foo')) |
| 606 |
self.assertFalse(im.visitdir(b'folder')) |
| 607 |
self.assertFalse(im.visitdir(b'dir/subdir/z')) |
| 608 |
# OPT: this should probably be 'all' not True. |
| 609 |
self.assertEqual(im.visitdir(b'dir/subdir/x'), True) |
| 610 |
|
| 611 |
def testVisitchildrensetIncludeInclude3(self): |
| 612 |
m1 = matchmod.match( |
| 613 |
util.localpath(b'/repo'), b'', include=[b'path:dir/subdir/x'] |
| 614 |
) |
| 615 |
m2 = matchmod.match( |
| 616 |
util.localpath(b'/repo'), b'', include=[b'path:dir/subdir'] |
| 617 |
) |
| 618 |
im = matchmod.intersectmatchers(m1, m2) |
| 619 |
self.assertEqual(im.visitchildrenset(b''), {b'dir'}) |
| 620 |
self.assertEqual(im.visitchildrenset(b'dir'), {b'subdir'}) |
| 621 |
self.assertEqual(im.visitchildrenset(b'dir/subdir'), {b'x'}) |
| 622 |
self.assertEqual(im.visitchildrenset(b'dir/foo'), set()) |
| 623 |
self.assertEqual(im.visitchildrenset(b'folder'), set()) |
| 624 |
self.assertEqual(im.visitchildrenset(b'dir/subdir/z'), set()) |
| 625 |
# OPT: this should probably be 'all' not 'this'. |
| 626 |
self.assertEqual(im.visitchildrenset(b'dir/subdir/x'), b'this') |
| 627 |
|
| 628 |
# We're using includematcher instead of patterns because it behaves slightly |
| 629 |
# better (giving narrower results) than patternmatcher. |
| 630 |
def testVisitdirIncludeInclude4(self): |
| 631 |
m1 = matchmod.match( |
| 632 |
util.localpath(b'/repo'), b'', include=[b'path:dir/subdir/x'] |
| 633 |
) |
| 634 |
m2 = matchmod.match( |
| 635 |
util.localpath(b'/repo'), b'', include=[b'path:dir/subdir/z'] |
| 636 |
) |
| 637 |
im = matchmod.intersectmatchers(m1, m2) |
| 638 |
# OPT: these next three could probably be False as well. |
| 639 |
self.assertEqual(im.visitdir(b''), True) |
| 640 |
self.assertEqual(im.visitdir(b'dir'), True) |
| 641 |
self.assertEqual(im.visitdir(b'dir/subdir'), True) |
| 642 |
self.assertFalse(im.visitdir(b'dir/foo')) |
| 643 |
self.assertFalse(im.visitdir(b'folder')) |
| 644 |
self.assertFalse(im.visitdir(b'dir/subdir/z')) |
| 645 |
self.assertFalse(im.visitdir(b'dir/subdir/x')) |
| 646 |
|
| 647 |
def testVisitchildrensetIncludeInclude4(self): |
| 648 |
m1 = matchmod.match( |
| 649 |
util.localpath(b'/repo'), b'', include=[b'path:dir/subdir/x'] |
| 650 |
) |
| 651 |
m2 = matchmod.match( |
| 652 |
util.localpath(b'/repo'), b'', include=[b'path:dir/subdir/z'] |
| 653 |
) |
| 654 |
im = matchmod.intersectmatchers(m1, m2) |
| 655 |
# OPT: these next two could probably be set() as well. |
| 656 |
self.assertEqual(im.visitchildrenset(b''), {b'dir'}) |
| 657 |
self.assertEqual(im.visitchildrenset(b'dir'), {b'subdir'}) |
| 658 |
self.assertEqual(im.visitchildrenset(b'dir/subdir'), set()) |
| 659 |
self.assertEqual(im.visitchildrenset(b'dir/foo'), set()) |
| 660 |
self.assertEqual(im.visitchildrenset(b'folder'), set()) |
| 661 |
self.assertEqual(im.visitchildrenset(b'dir/subdir/z'), set()) |
| 662 |
self.assertEqual(im.visitchildrenset(b'dir/subdir/x'), set()) |
| 663 |
|
| 664 |
|
| 665 |
class UnionMatcherTests(unittest.TestCase): |
| 666 |
def testVisitdirM2always(self): |
| 667 |
m1 = matchmod.alwaysmatcher() |
| 668 |
m2 = matchmod.alwaysmatcher() |
| 669 |
um = matchmod.unionmatcher([m1, m2]) |
| 670 |
# um should be equivalent to a alwaysmatcher. |
| 671 |
self.assertEqual(um.visitdir(b''), b'all') |
| 672 |
self.assertEqual(um.visitdir(b'dir'), b'all') |
| 673 |
self.assertEqual(um.visitdir(b'dir/subdir'), b'all') |
| 674 |
self.assertEqual(um.visitdir(b'dir/subdir/z'), b'all') |
| 675 |
self.assertEqual(um.visitdir(b'dir/foo'), b'all') |
| 676 |
self.assertEqual(um.visitdir(b'dir/subdir/x'), b'all') |
| 677 |
self.assertEqual(um.visitdir(b'folder'), b'all') |
| 678 |
|
| 679 |
def testVisitchildrensetM2always(self): |
| 680 |
m1 = matchmod.alwaysmatcher() |
| 681 |
m2 = matchmod.alwaysmatcher() |
| 682 |
um = matchmod.unionmatcher([m1, m2]) |
| 683 |
# um should be equivalent to a alwaysmatcher. |
| 684 |
self.assertEqual(um.visitchildrenset(b''), b'all') |
| 685 |
self.assertEqual(um.visitchildrenset(b'dir'), b'all') |
| 686 |
self.assertEqual(um.visitchildrenset(b'dir/subdir'), b'all') |
| 687 |
self.assertEqual(um.visitchildrenset(b'dir/subdir/z'), b'all') |
| 688 |
self.assertEqual(um.visitchildrenset(b'dir/foo'), b'all') |
| 689 |
self.assertEqual(um.visitchildrenset(b'dir/subdir/x'), b'all') |
| 690 |
self.assertEqual(um.visitchildrenset(b'folder'), b'all') |
| 691 |
|
| 692 |
def testVisitdirM1never(self): |
| 693 |
m1 = matchmod.nevermatcher() |
| 694 |
m2 = matchmod.alwaysmatcher() |
| 695 |
um = matchmod.unionmatcher([m1, m2]) |
| 696 |
# um should be equivalent to a alwaysmatcher. |
| 697 |
self.assertEqual(um.visitdir(b''), b'all') |
| 698 |
self.assertEqual(um.visitdir(b'dir'), b'all') |
| 699 |
self.assertEqual(um.visitdir(b'dir/subdir'), b'all') |
| 700 |
self.assertEqual(um.visitdir(b'dir/subdir/z'), b'all') |
| 701 |
self.assertEqual(um.visitdir(b'dir/foo'), b'all') |
| 702 |
self.assertEqual(um.visitdir(b'dir/subdir/x'), b'all') |
| 703 |
self.assertEqual(um.visitdir(b'folder'), b'all') |
| 704 |
|
| 705 |
def testVisitchildrensetM1never(self): |
| 706 |
m1 = matchmod.nevermatcher() |
| 707 |
m2 = matchmod.alwaysmatcher() |
| 708 |
um = matchmod.unionmatcher([m1, m2]) |
| 709 |
# um should be equivalent to a alwaysmatcher. |
| 710 |
self.assertEqual(um.visitchildrenset(b''), b'all') |
| 711 |
self.assertEqual(um.visitchildrenset(b'dir'), b'all') |
| 712 |
self.assertEqual(um.visitchildrenset(b'dir/subdir'), b'all') |
| 713 |
self.assertEqual(um.visitchildrenset(b'dir/subdir/z'), b'all') |
| 714 |
self.assertEqual(um.visitchildrenset(b'dir/foo'), b'all') |
| 715 |
self.assertEqual(um.visitchildrenset(b'dir/subdir/x'), b'all') |
| 716 |
self.assertEqual(um.visitchildrenset(b'folder'), b'all') |
| 717 |
|
| 718 |
def testVisitdirM2never(self): |
| 719 |
m1 = matchmod.alwaysmatcher() |
| 720 |
m2 = matchmod.nevermatcher() |
| 721 |
um = matchmod.unionmatcher([m1, m2]) |
| 722 |
# um should be equivalent to a alwaysmatcher. |
| 723 |
self.assertEqual(um.visitdir(b''), b'all') |
| 724 |
self.assertEqual(um.visitdir(b'dir'), b'all') |
| 725 |
self.assertEqual(um.visitdir(b'dir/subdir'), b'all') |
| 726 |
self.assertEqual(um.visitdir(b'dir/subdir/z'), b'all') |
| 727 |
self.assertEqual(um.visitdir(b'dir/foo'), b'all') |
| 728 |
self.assertEqual(um.visitdir(b'dir/subdir/x'), b'all') |
| 729 |
self.assertEqual(um.visitdir(b'folder'), b'all') |
| 730 |
|
| 731 |
def testVisitchildrensetM2never(self): |
| 732 |
m1 = matchmod.alwaysmatcher() |
| 733 |
m2 = matchmod.nevermatcher() |
| 734 |
um = matchmod.unionmatcher([m1, m2]) |
| 735 |
# um should be equivalent to a alwaysmatcher. |
| 736 |
self.assertEqual(um.visitchildrenset(b''), b'all') |
| 737 |
self.assertEqual(um.visitchildrenset(b'dir'), b'all') |
| 738 |
self.assertEqual(um.visitchildrenset(b'dir/subdir'), b'all') |
| 739 |
self.assertEqual(um.visitchildrenset(b'dir/subdir/z'), b'all') |
| 740 |
self.assertEqual(um.visitchildrenset(b'dir/foo'), b'all') |
| 741 |
self.assertEqual(um.visitchildrenset(b'dir/subdir/x'), b'all') |
| 742 |
self.assertEqual(um.visitchildrenset(b'folder'), b'all') |
| 743 |
|
| 744 |
def testVisitdirM2SubdirPrefix(self): |
| 745 |
m1 = matchmod.alwaysmatcher() |
| 746 |
m2 = matchmod.match( |
| 747 |
util.localpath(b'/repo'), b'', patterns=[b'path:dir/subdir'] |
| 748 |
) |
| 749 |
um = matchmod.unionmatcher([m1, m2]) |
| 750 |
self.assertEqual(um.visitdir(b''), b'all') |
| 751 |
self.assertEqual(um.visitdir(b'dir'), b'all') |
| 752 |
self.assertEqual(um.visitdir(b'dir/subdir'), b'all') |
| 753 |
self.assertEqual(um.visitdir(b'dir/foo'), b'all') |
| 754 |
self.assertEqual(um.visitdir(b'folder'), b'all') |
| 755 |
self.assertEqual(um.visitdir(b'dir/subdir/z'), b'all') |
| 756 |
self.assertEqual(um.visitdir(b'dir/subdir/x'), b'all') |
| 757 |
|
| 758 |
def testVisitchildrensetM2SubdirPrefix(self): |
| 759 |
m1 = matchmod.alwaysmatcher() |
| 760 |
m2 = matchmod.match( |
| 761 |
util.localpath(b'/repo'), b'', include=[b'path:dir/subdir'] |
| 762 |
) |
| 763 |
um = matchmod.unionmatcher([m1, m2]) |
| 764 |
self.assertEqual(um.visitchildrenset(b''), b'all') |
| 765 |
self.assertEqual(um.visitchildrenset(b'dir'), b'all') |
| 766 |
self.assertEqual(um.visitchildrenset(b'dir/subdir'), b'all') |
| 767 |
self.assertEqual(um.visitchildrenset(b'dir/foo'), b'all') |
| 768 |
self.assertEqual(um.visitchildrenset(b'folder'), b'all') |
| 769 |
self.assertEqual(um.visitchildrenset(b'dir/subdir/z'), b'all') |
| 770 |
self.assertEqual(um.visitchildrenset(b'dir/subdir/x'), b'all') |
| 771 |
|
| 772 |
# We're using includematcher instead of patterns because it behaves slightly |
| 773 |
# better (giving narrower results) than patternmatcher. |
| 774 |
def testVisitdirIncludeInclude(self): |
| 775 |
m1 = matchmod.match( |
| 776 |
util.localpath(b'/repo'), b'', include=[b'path:dir/subdir'] |
| 777 |
) |
| 778 |
m2 = matchmod.match( |
| 779 |
util.localpath(b'/repo'), b'', include=[b'rootfilesin:dir'] |
| 780 |
) |
| 781 |
um = matchmod.unionmatcher([m1, m2]) |
| 782 |
self.assertEqual(um.visitdir(b''), True) |
| 783 |
self.assertEqual(um.visitdir(b'dir'), True) |
| 784 |
self.assertEqual(um.visitdir(b'dir/subdir'), b'all') |
| 785 |
self.assertFalse(um.visitdir(b'dir/foo')) |
| 786 |
self.assertFalse(um.visitdir(b'folder')) |
| 787 |
# OPT: These two should probably be 'all' not True. |
| 788 |
self.assertEqual(um.visitdir(b'dir/subdir/z'), True) |
| 789 |
self.assertEqual(um.visitdir(b'dir/subdir/x'), True) |
| 790 |
|
| 791 |
def testVisitchildrensetIncludeInclude(self): |
| 792 |
m1 = matchmod.match( |
| 793 |
util.localpath(b'/repo'), b'', include=[b'path:dir/subdir'] |
| 794 |
) |
| 795 |
m2 = matchmod.match( |
| 796 |
util.localpath(b'/repo'), b'', include=[b'rootfilesin:dir'] |
| 797 |
) |
| 798 |
um = matchmod.unionmatcher([m1, m2]) |
| 799 |
self.assertEqual(um.visitchildrenset(b''), {b'dir'}) |
| 800 |
self.assertEqual(um.visitchildrenset(b'dir'), b'this') |
| 801 |
self.assertEqual(um.visitchildrenset(b'dir/subdir'), b'all') |
| 802 |
self.assertEqual(um.visitchildrenset(b'dir/foo'), set()) |
| 803 |
self.assertEqual(um.visitchildrenset(b'folder'), set()) |
| 804 |
# OPT: These next two could be 'all' instead of 'this'. |
| 805 |
self.assertEqual(um.visitchildrenset(b'dir/subdir/z'), b'this') |
| 806 |
self.assertEqual(um.visitchildrenset(b'dir/subdir/x'), b'this') |
| 807 |
|
| 808 |
# We're using includematcher instead of patterns because it behaves slightly |
| 809 |
# better (giving narrower results) than patternmatcher. |
| 810 |
def testVisitdirIncludeInclude2(self): |
| 811 |
m1 = matchmod.match( |
| 812 |
util.localpath(b'/repo'), b'', include=[b'path:dir/subdir'] |
| 813 |
) |
| 814 |
m2 = matchmod.match( |
| 815 |
util.localpath(b'/repo'), b'', include=[b'path:folder'] |
| 816 |
) |
| 817 |
um = matchmod.unionmatcher([m1, m2]) |
| 818 |
self.assertEqual(um.visitdir(b''), True) |
| 819 |
self.assertEqual(um.visitdir(b'dir'), True) |
| 820 |
self.assertEqual(um.visitdir(b'dir/subdir'), b'all') |
| 821 |
self.assertFalse(um.visitdir(b'dir/foo')) |
| 822 |
self.assertEqual(um.visitdir(b'folder'), b'all') |
| 823 |
# OPT: These should probably be 'all' not True. |
| 824 |
self.assertEqual(um.visitdir(b'dir/subdir/z'), True) |
| 825 |
self.assertEqual(um.visitdir(b'dir/subdir/x'), True) |
| 826 |
|
| 827 |
def testVisitchildrensetIncludeInclude2(self): |
| 828 |
m1 = matchmod.match( |
| 829 |
util.localpath(b'/repo'), b'', include=[b'path:dir/subdir'] |
| 830 |
) |
| 831 |
m2 = matchmod.match( |
| 832 |
util.localpath(b'/repo'), b'', include=[b'path:folder'] |
| 833 |
) |
| 834 |
um = matchmod.unionmatcher([m1, m2]) |
| 835 |
self.assertEqual(um.visitchildrenset(b''), {b'folder', b'dir'}) |
| 836 |
self.assertEqual(um.visitchildrenset(b'dir'), {b'subdir'}) |
| 837 |
self.assertEqual(um.visitchildrenset(b'dir/subdir'), b'all') |
| 838 |
self.assertEqual(um.visitchildrenset(b'dir/foo'), set()) |
| 839 |
self.assertEqual(um.visitchildrenset(b'folder'), b'all') |
| 840 |
# OPT: These next two could be 'all' instead of 'this'. |
| 841 |
self.assertEqual(um.visitchildrenset(b'dir/subdir/z'), b'this') |
| 842 |
self.assertEqual(um.visitchildrenset(b'dir/subdir/x'), b'this') |
| 843 |
|
| 844 |
# We're using includematcher instead of patterns because it behaves slightly |
| 845 |
# better (giving narrower results) than patternmatcher. |
| 846 |
def testVisitdirIncludeInclude3(self): |
| 847 |
m1 = matchmod.match( |
| 848 |
util.localpath(b'/repo'), b'', include=[b'path:dir/subdir/x'] |
| 849 |
) |
| 850 |
m2 = matchmod.match( |
| 851 |
util.localpath(b'/repo'), b'', include=[b'path:dir/subdir'] |
| 852 |
) |
| 853 |
um = matchmod.unionmatcher([m1, m2]) |
| 854 |
self.assertEqual(um.visitdir(b''), True) |
| 855 |
self.assertEqual(um.visitdir(b'dir'), True) |
| 856 |
self.assertEqual(um.visitdir(b'dir/subdir'), b'all') |
| 857 |
self.assertFalse(um.visitdir(b'dir/foo')) |
| 858 |
self.assertFalse(um.visitdir(b'folder')) |
| 859 |
self.assertEqual(um.visitdir(b'dir/subdir/x'), b'all') |
| 860 |
# OPT: this should probably be 'all' not True. |
| 861 |
self.assertEqual(um.visitdir(b'dir/subdir/z'), True) |
| 862 |
|
| 863 |
def testVisitchildrensetIncludeInclude3(self): |
| 864 |
m1 = matchmod.match( |
| 865 |
util.localpath(b'/repo'), b'', include=[b'path:dir/subdir/x'] |
| 866 |
) |
| 867 |
m2 = matchmod.match( |
| 868 |
util.localpath(b'/repo'), b'', include=[b'path:dir/subdir'] |
| 869 |
) |
| 870 |
um = matchmod.unionmatcher([m1, m2]) |
| 871 |
self.assertEqual(um.visitchildrenset(b''), {b'dir'}) |
| 872 |
self.assertEqual(um.visitchildrenset(b'dir'), {b'subdir'}) |
| 873 |
self.assertEqual(um.visitchildrenset(b'dir/subdir'), b'all') |
| 874 |
self.assertEqual(um.visitchildrenset(b'dir/foo'), set()) |
| 875 |
self.assertEqual(um.visitchildrenset(b'folder'), set()) |
| 876 |
self.assertEqual(um.visitchildrenset(b'dir/subdir/x'), b'all') |
| 877 |
# OPT: this should probably be 'all' not 'this'. |
| 878 |
self.assertEqual(um.visitchildrenset(b'dir/subdir/z'), b'this') |
| 879 |
|
| 880 |
# We're using includematcher instead of patterns because it behaves slightly |
| 881 |
# better (giving narrower results) than patternmatcher. |
| 882 |
def testVisitdirIncludeInclude4(self): |
| 883 |
m1 = matchmod.match( |
| 884 |
util.localpath(b'/repo'), b'', include=[b'path:dir/subdir/x'] |
| 885 |
) |
| 886 |
m2 = matchmod.match( |
| 887 |
util.localpath(b'/repo'), b'', include=[b'path:dir/subdir/z'] |
| 888 |
) |
| 889 |
um = matchmod.unionmatcher([m1, m2]) |
| 890 |
# OPT: these next three could probably be False as well. |
| 891 |
self.assertEqual(um.visitdir(b''), True) |
| 892 |
self.assertEqual(um.visitdir(b'dir'), True) |
| 893 |
self.assertEqual(um.visitdir(b'dir/subdir'), True) |
| 894 |
self.assertFalse(um.visitdir(b'dir/foo')) |
| 895 |
self.assertFalse(um.visitdir(b'folder')) |
| 896 |
self.assertEqual(um.visitdir(b'dir/subdir/z'), b'all') |
| 897 |
self.assertEqual(um.visitdir(b'dir/subdir/x'), b'all') |
| 898 |
|
| 899 |
def testVisitchildrensetIncludeInclude4(self): |
| 900 |
m1 = matchmod.match( |
| 901 |
util.localpath(b'/repo'), b'', include=[b'path:dir/subdir/x'] |
| 902 |
) |
| 903 |
m2 = matchmod.match( |
| 904 |
util.localpath(b'/repo'), b'', include=[b'path:dir/subdir/z'] |
| 905 |
) |
| 906 |
um = matchmod.unionmatcher([m1, m2]) |
| 907 |
self.assertEqual(um.visitchildrenset(b''), {b'dir'}) |
| 908 |
self.assertEqual(um.visitchildrenset(b'dir'), {b'subdir'}) |
| 909 |
self.assertEqual(um.visitchildrenset(b'dir/subdir'), {b'x', b'z'}) |
| 910 |
self.assertEqual(um.visitchildrenset(b'dir/foo'), set()) |
| 911 |
self.assertEqual(um.visitchildrenset(b'folder'), set()) |
| 912 |
self.assertEqual(um.visitchildrenset(b'dir/subdir/z'), b'all') |
| 913 |
self.assertEqual(um.visitchildrenset(b'dir/subdir/x'), b'all') |
| 914 |
|
| 915 |
|
| 916 |
class SubdirMatcherTests(unittest.TestCase): |
| 917 |
def testVisitdir(self): |
| 918 |
m = matchmod.match( |
| 919 |
util.localpath(b'/repo'), b'', include=[b'path:dir/subdir'] |
| 920 |
) |
| 921 |
sm = matchmod.subdirmatcher(b'dir', m) |
| 922 |
|
| 923 |
self.assertEqual(sm.visitdir(b''), True) |
| 924 |
self.assertEqual(sm.visitdir(b'subdir'), b'all') |
| 925 |
# OPT: These next two should probably be 'all' not True. |
| 926 |
self.assertEqual(sm.visitdir(b'subdir/x'), True) |
| 927 |
self.assertEqual(sm.visitdir(b'subdir/z'), True) |
| 928 |
self.assertFalse(sm.visitdir(b'foo')) |
| 929 |
|
| 930 |
def testVisitchildrenset(self): |
| 931 |
m = matchmod.match( |
| 932 |
util.localpath(b'/repo'), b'', include=[b'path:dir/subdir'] |
| 933 |
) |
| 934 |
sm = matchmod.subdirmatcher(b'dir', m) |
| 935 |
|
| 936 |
self.assertEqual(sm.visitchildrenset(b''), {b'subdir'}) |
| 937 |
self.assertEqual(sm.visitchildrenset(b'subdir'), b'all') |
| 938 |
# OPT: These next two should probably be 'all' not 'this'. |
| 939 |
self.assertEqual(sm.visitchildrenset(b'subdir/x'), b'this') |
| 940 |
self.assertEqual(sm.visitchildrenset(b'subdir/z'), b'this') |
| 941 |
self.assertEqual(sm.visitchildrenset(b'foo'), set()) |
| 942 |
|
| 943 |
|
| 944 |
class PrefixdirMatcherTests(unittest.TestCase): |
| 945 |
def testVisitdir(self): |
| 946 |
m = matchmod.match( |
| 947 |
util.localpath(b'/root/d'), |
| 948 |
b'e/f', |
| 949 |
[b'../a.txt', b'b.txt'], |
| 950 |
auditor=noop_auditor, |
| 951 |
) |
| 952 |
pm = matchmod.prefixdirmatcher(b'd', m) |
| 953 |
|
| 954 |
# `m` elides 'd' because it's part of the root, and the rest of the |
| 955 |
# patterns are relative. |
| 956 |
self.assertEqual(bool(m(b'a.txt')), False) |
| 957 |
self.assertEqual(bool(m(b'b.txt')), False) |
| 958 |
self.assertEqual(bool(m(b'e/a.txt')), True) |
| 959 |
self.assertEqual(bool(m(b'e/b.txt')), False) |
| 960 |
self.assertEqual(bool(m(b'e/f/b.txt')), True) |
| 961 |
|
| 962 |
# The prefix matcher re-adds 'd' to the paths, so they need to be |
| 963 |
# specified when using the prefixdirmatcher. |
| 964 |
self.assertEqual(bool(pm(b'a.txt')), False) |
| 965 |
self.assertEqual(bool(pm(b'b.txt')), False) |
| 966 |
self.assertEqual(bool(pm(b'd/e/a.txt')), True) |
| 967 |
self.assertEqual(bool(pm(b'd/e/b.txt')), False) |
| 968 |
self.assertEqual(bool(pm(b'd/e/f/b.txt')), True) |
| 969 |
|
| 970 |
self.assertEqual(m.visitdir(b''), True) |
| 971 |
self.assertEqual(m.visitdir(b'e'), True) |
| 972 |
self.assertEqual(m.visitdir(b'e/f'), True) |
| 973 |
self.assertEqual(m.visitdir(b'e/f/g'), False) |
| 974 |
|
| 975 |
self.assertEqual(pm.visitdir(b''), True) |
| 976 |
self.assertEqual(pm.visitdir(b'd'), True) |
| 977 |
self.assertEqual(pm.visitdir(b'd/e'), True) |
| 978 |
self.assertEqual(pm.visitdir(b'd/e/f'), True) |
| 979 |
self.assertEqual(pm.visitdir(b'd/e/f/g'), False) |
| 980 |
|
| 981 |
def testVisitchildrenset(self): |
| 982 |
m = matchmod.match( |
| 983 |
util.localpath(b'/root/d'), |
| 984 |
b'e/f', |
| 985 |
[b'../a.txt', b'b.txt'], |
| 986 |
auditor=noop_auditor, |
| 987 |
) |
| 988 |
pm = matchmod.prefixdirmatcher(b'd', m) |
| 989 |
|
| 990 |
# OPT: visitchildrenset could possibly return {'e'} and {'f'} for these |
| 991 |
# next two, respectively; patternmatcher does not have this |
| 992 |
# optimization. |
| 993 |
self.assertEqual(m.visitchildrenset(b''), b'this') |
| 994 |
self.assertEqual(m.visitchildrenset(b'e'), b'this') |
| 995 |
self.assertEqual(m.visitchildrenset(b'e/f'), b'this') |
| 996 |
self.assertEqual(m.visitchildrenset(b'e/f/g'), set()) |
| 997 |
|
| 998 |
# OPT: visitchildrenset could possibly return {'d'}, {'e'}, and {'f'} |
| 999 |
# for these next three, respectively; patternmatcher does not have this |
| 1000 |
# optimization. |
| 1001 |
self.assertEqual(pm.visitchildrenset(b''), b'this') |
| 1002 |
self.assertEqual(pm.visitchildrenset(b'd'), b'this') |
| 1003 |
self.assertEqual(pm.visitchildrenset(b'd/e'), b'this') |
| 1004 |
self.assertEqual(pm.visitchildrenset(b'd/e/f'), b'this') |
| 1005 |
self.assertEqual(pm.visitchildrenset(b'd/e/f/g'), set()) |
| 1006 |
|
| 1007 |
|
| 1008 |
if __name__ == '__main__': |
| 1009 |
silenttestrunner.main(__name__) |