test-match.py
832 lines
| 40.6 KiB
| text/x-python
|
PythonLexer
/ tests / test-match.py
|
r33583 | from __future__ import absolute_import | ||
import unittest | ||||
import silenttestrunner | ||||
from mercurial import ( | ||||
match as matchmod, | ||||
|
r38988 | util, | ||
|
r33583 | ) | ||
|
r38988 | class BaseMatcherTests(unittest.TestCase): | ||
def testVisitdir(self): | ||||
|
r41824 | m = matchmod.basematcher() | ||
|
r42528 | self.assertTrue(m.visitdir(b'')) | ||
|
r38999 | self.assertTrue(m.visitdir(b'dir')) | ||
|
r38988 | |||
|
r38990 | def testVisitchildrenset(self): | ||
|
r41824 | m = matchmod.basematcher() | ||
|
r42528 | self.assertEqual(m.visitchildrenset(b''), b'this') | ||
|
r38999 | self.assertEqual(m.visitchildrenset(b'dir'), b'this') | ||
|
r38990 | |||
|
r38988 | class AlwaysMatcherTests(unittest.TestCase): | ||
def testVisitdir(self): | ||||
|
r41824 | m = matchmod.alwaysmatcher() | ||
|
r42528 | self.assertEqual(m.visitdir(b''), b'all') | ||
|
r38999 | self.assertEqual(m.visitdir(b'dir'), b'all') | ||
|
r38988 | |||
|
r38990 | def testVisitchildrenset(self): | ||
|
r41824 | m = matchmod.alwaysmatcher() | ||
|
r42528 | self.assertEqual(m.visitchildrenset(b''), b'all') | ||
|
r38999 | self.assertEqual(m.visitchildrenset(b'dir'), b'all') | ||
|
r38990 | |||
|
r33583 | class NeverMatcherTests(unittest.TestCase): | ||
def testVisitdir(self): | ||||
|
r41824 | m = matchmod.nevermatcher() | ||
|
r42528 | self.assertFalse(m.visitdir(b'')) | ||
|
r38999 | self.assertFalse(m.visitdir(b'dir')) | ||
|
r33583 | |||
|
r38990 | def testVisitchildrenset(self): | ||
|
r41824 | m = matchmod.nevermatcher() | ||
|
r42528 | self.assertEqual(m.visitchildrenset(b''), set()) | ||
|
r38999 | self.assertEqual(m.visitchildrenset(b'dir'), set()) | ||
|
r38990 | |||
|
r38988 | class PredicateMatcherTests(unittest.TestCase): | ||
# predicatematcher does not currently define either of these methods, so | ||||
# this is equivalent to BaseMatcherTests. | ||||
def testVisitdir(self): | ||||
|
r41824 | m = matchmod.predicatematcher(lambda *a: False) | ||
|
r42528 | self.assertTrue(m.visitdir(b'')) | ||
|
r38999 | self.assertTrue(m.visitdir(b'dir')) | ||
|
r38988 | |||
|
r38990 | def testVisitchildrenset(self): | ||
|
r41824 | m = matchmod.predicatematcher(lambda *a: False) | ||
|
r42528 | self.assertEqual(m.visitchildrenset(b''), b'this') | ||
|
r38999 | self.assertEqual(m.visitchildrenset(b'dir'), b'this') | ||
|
r38990 | |||
|
r38988 | class PatternMatcherTests(unittest.TestCase): | ||
def testVisitdirPrefix(self): | ||||
|
r38999 | m = matchmod.match(b'x', b'', patterns=[b'path:dir/subdir']) | ||
|
r38988 | assert isinstance(m, matchmod.patternmatcher) | ||
|
r42528 | self.assertTrue(m.visitdir(b'')) | ||
|
r38999 | self.assertTrue(m.visitdir(b'dir')) | ||
self.assertEqual(m.visitdir(b'dir/subdir'), b'all') | ||||
|
r38988 | # OPT: This should probably be 'all' if its parent is? | ||
|
r38999 | self.assertTrue(m.visitdir(b'dir/subdir/x')) | ||
self.assertFalse(m.visitdir(b'folder')) | ||||
|
r38988 | |||
|
r38990 | def testVisitchildrensetPrefix(self): | ||
|
r38999 | m = matchmod.match(b'x', b'', patterns=[b'path:dir/subdir']) | ||
|
r38990 | assert isinstance(m, matchmod.patternmatcher) | ||
|
r42528 | self.assertEqual(m.visitchildrenset(b''), b'this') | ||
|
r38999 | self.assertEqual(m.visitchildrenset(b'dir'), b'this') | ||
self.assertEqual(m.visitchildrenset(b'dir/subdir'), b'all') | ||||
|
r38990 | # OPT: This should probably be 'all' if its parent is? | ||
|
r38999 | self.assertEqual(m.visitchildrenset(b'dir/subdir/x'), b'this') | ||
self.assertEqual(m.visitchildrenset(b'folder'), set()) | ||||
|
r38990 | |||
|
r38988 | def testVisitdirRootfilesin(self): | ||
|
r38999 | m = matchmod.match(b'x', b'', patterns=[b'rootfilesin:dir/subdir']) | ||
|
r38988 | assert isinstance(m, matchmod.patternmatcher) | ||
|
r38999 | self.assertFalse(m.visitdir(b'dir/subdir/x')) | ||
self.assertFalse(m.visitdir(b'folder')) | ||||
|
r38988 | # FIXME: These should probably be True. | ||
|
r42533 | self.assertFalse(m.visitdir(b'')) | ||
|
r38999 | self.assertFalse(m.visitdir(b'dir')) | ||
self.assertFalse(m.visitdir(b'dir/subdir')) | ||||
|
r38988 | |||
|
r38990 | def testVisitchildrensetRootfilesin(self): | ||
|
r38999 | m = matchmod.match(b'x', b'', patterns=[b'rootfilesin:dir/subdir']) | ||
|
r38990 | assert isinstance(m, matchmod.patternmatcher) | ||
|
r38999 | self.assertEqual(m.visitchildrenset(b'dir/subdir/x'), set()) | ||
self.assertEqual(m.visitchildrenset(b'folder'), set()) | ||||
|
r42533 | # FIXME: These should probably be {'dir'}, {'subdir'} and 'this', | ||
# respectively, or at least 'this' for all three. | ||||
self.assertEqual(m.visitchildrenset(b''), set()) | ||||
|
r38999 | self.assertEqual(m.visitchildrenset(b'dir'), set()) | ||
self.assertEqual(m.visitchildrenset(b'dir/subdir'), set()) | ||||
|
r38990 | |||
|
r38988 | def testVisitdirGlob(self): | ||
|
r38999 | m = matchmod.match(b'x', b'', patterns=[b'glob:dir/z*']) | ||
|
r38988 | assert isinstance(m, matchmod.patternmatcher) | ||
|
r42528 | self.assertTrue(m.visitdir(b'')) | ||
|
r38999 | self.assertTrue(m.visitdir(b'dir')) | ||
self.assertFalse(m.visitdir(b'folder')) | ||||
|
r38988 | # OPT: these should probably be False. | ||
|
r38999 | self.assertTrue(m.visitdir(b'dir/subdir')) | ||
self.assertTrue(m.visitdir(b'dir/subdir/x')) | ||||
|
r38988 | |||
|
r38990 | def testVisitchildrensetGlob(self): | ||
|
r38999 | m = matchmod.match(b'x', b'', patterns=[b'glob:dir/z*']) | ||
|
r38990 | assert isinstance(m, matchmod.patternmatcher) | ||
|
r42528 | self.assertEqual(m.visitchildrenset(b''), b'this') | ||
|
r38999 | self.assertEqual(m.visitchildrenset(b'folder'), set()) | ||
self.assertEqual(m.visitchildrenset(b'dir'), b'this') | ||||
|
r38990 | # OPT: these should probably be set(). | ||
|
r38999 | self.assertEqual(m.visitchildrenset(b'dir/subdir'), b'this') | ||
self.assertEqual(m.visitchildrenset(b'dir/subdir/x'), b'this') | ||||
|
r38990 | |||
|
r38988 | class IncludeMatcherTests(unittest.TestCase): | ||
def testVisitdirPrefix(self): | ||||
|
r38999 | m = matchmod.match(b'x', b'', include=[b'path:dir/subdir']) | ||
|
r38988 | assert isinstance(m, matchmod.includematcher) | ||
|
r42528 | self.assertTrue(m.visitdir(b'')) | ||
|
r38999 | self.assertTrue(m.visitdir(b'dir')) | ||
self.assertEqual(m.visitdir(b'dir/subdir'), b'all') | ||||
|
r38988 | # OPT: This should probably be 'all' if its parent is? | ||
|
r38999 | self.assertTrue(m.visitdir(b'dir/subdir/x')) | ||
self.assertFalse(m.visitdir(b'folder')) | ||||
|
r38988 | |||
|
r38990 | def testVisitchildrensetPrefix(self): | ||
|
r38999 | m = matchmod.match(b'x', b'', include=[b'path:dir/subdir']) | ||
|
r38990 | assert isinstance(m, matchmod.includematcher) | ||
|
r42528 | self.assertEqual(m.visitchildrenset(b''), {b'dir'}) | ||
|
r38999 | self.assertEqual(m.visitchildrenset(b'dir'), {b'subdir'}) | ||
self.assertEqual(m.visitchildrenset(b'dir/subdir'), b'all') | ||||
|
r38990 | # OPT: This should probably be 'all' if its parent is? | ||
|
r38999 | self.assertEqual(m.visitchildrenset(b'dir/subdir/x'), b'this') | ||
self.assertEqual(m.visitchildrenset(b'folder'), set()) | ||||
|
r38990 | |||
|
r38988 | def testVisitdirRootfilesin(self): | ||
|
r38999 | m = matchmod.match(b'x', b'', include=[b'rootfilesin:dir/subdir']) | ||
|
r38988 | assert isinstance(m, matchmod.includematcher) | ||
|
r42528 | self.assertTrue(m.visitdir(b'')) | ||
|
r38999 | self.assertTrue(m.visitdir(b'dir')) | ||
self.assertTrue(m.visitdir(b'dir/subdir')) | ||||
self.assertFalse(m.visitdir(b'dir/subdir/x')) | ||||
self.assertFalse(m.visitdir(b'folder')) | ||||
|
r38988 | |||
|
r38990 | def testVisitchildrensetRootfilesin(self): | ||
|
r38999 | m = matchmod.match(b'x', b'', include=[b'rootfilesin:dir/subdir']) | ||
|
r38990 | assert isinstance(m, matchmod.includematcher) | ||
|
r42528 | self.assertEqual(m.visitchildrenset(b''), {b'dir'}) | ||
|
r38999 | self.assertEqual(m.visitchildrenset(b'dir'), {b'subdir'}) | ||
self.assertEqual(m.visitchildrenset(b'dir/subdir'), b'this') | ||||
self.assertEqual(m.visitchildrenset(b'dir/subdir/x'), set()) | ||||
self.assertEqual(m.visitchildrenset(b'folder'), set()) | ||||
|
r38990 | |||
|
r38988 | def testVisitdirGlob(self): | ||
|
r38999 | m = matchmod.match(b'x', b'', include=[b'glob:dir/z*']) | ||
|
r38988 | assert isinstance(m, matchmod.includematcher) | ||
|
r42528 | self.assertTrue(m.visitdir(b'')) | ||
|
r38999 | self.assertTrue(m.visitdir(b'dir')) | ||
self.assertFalse(m.visitdir(b'folder')) | ||||
|
r38988 | # OPT: these should probably be False. | ||
|
r38999 | self.assertTrue(m.visitdir(b'dir/subdir')) | ||
self.assertTrue(m.visitdir(b'dir/subdir/x')) | ||||
|
r38988 | |||
|
r38990 | def testVisitchildrensetGlob(self): | ||
|
r38999 | m = matchmod.match(b'x', b'', include=[b'glob:dir/z*']) | ||
|
r38990 | assert isinstance(m, matchmod.includematcher) | ||
|
r42528 | self.assertEqual(m.visitchildrenset(b''), {b'dir'}) | ||
|
r38999 | self.assertEqual(m.visitchildrenset(b'folder'), set()) | ||
self.assertEqual(m.visitchildrenset(b'dir'), b'this') | ||||
|
r38990 | # OPT: these should probably be set(). | ||
|
r38999 | self.assertEqual(m.visitchildrenset(b'dir/subdir'), b'this') | ||
self.assertEqual(m.visitchildrenset(b'dir/subdir/x'), b'this') | ||||
|
r38990 | |||
|
r38988 | class ExactMatcherTests(unittest.TestCase): | ||
def testVisitdir(self): | ||||
|
r41825 | m = matchmod.exact(files=[b'dir/subdir/foo.txt']) | ||
|
r38988 | assert isinstance(m, matchmod.exactmatcher) | ||
|
r42528 | self.assertTrue(m.visitdir(b'')) | ||
|
r38999 | self.assertTrue(m.visitdir(b'dir')) | ||
self.assertTrue(m.visitdir(b'dir/subdir')) | ||||
self.assertFalse(m.visitdir(b'dir/subdir/foo.txt')) | ||||
self.assertFalse(m.visitdir(b'dir/foo')) | ||||
self.assertFalse(m.visitdir(b'dir/subdir/x')) | ||||
self.assertFalse(m.visitdir(b'folder')) | ||||
|
r38988 | |||
|
r38990 | def testVisitchildrenset(self): | ||
|
r41825 | m = matchmod.exact(files=[b'dir/subdir/foo.txt']) | ||
|
r38990 | assert isinstance(m, matchmod.exactmatcher) | ||
|
r42528 | self.assertEqual(m.visitchildrenset(b''), {b'dir'}) | ||
|
r38999 | self.assertEqual(m.visitchildrenset(b'dir'), {b'subdir'}) | ||
|
r39297 | self.assertEqual(m.visitchildrenset(b'dir/subdir'), {b'foo.txt'}) | ||
|
r38999 | self.assertEqual(m.visitchildrenset(b'dir/subdir/x'), set()) | ||
self.assertEqual(m.visitchildrenset(b'dir/subdir/foo.txt'), set()) | ||||
self.assertEqual(m.visitchildrenset(b'folder'), set()) | ||||
|
r38990 | |||
|
r39297 | def testVisitchildrensetFilesAndDirs(self): | ||
|
r41825 | m = matchmod.exact(files=[b'rootfile.txt', | ||
b'a/file1.txt', | ||||
b'a/b/file2.txt', | ||||
# no file in a/b/c | ||||
b'a/b/c/d/file4.txt']) | ||||
|
r39297 | assert isinstance(m, matchmod.exactmatcher) | ||
|
r42528 | self.assertEqual(m.visitchildrenset(b''), {b'a', b'rootfile.txt'}) | ||
|
r39297 | self.assertEqual(m.visitchildrenset(b'a'), {b'b', b'file1.txt'}) | ||
self.assertEqual(m.visitchildrenset(b'a/b'), {b'c', b'file2.txt'}) | ||||
self.assertEqual(m.visitchildrenset(b'a/b/c'), {b'd'}) | ||||
self.assertEqual(m.visitchildrenset(b'a/b/c/d'), {b'file4.txt'}) | ||||
self.assertEqual(m.visitchildrenset(b'a/b/c/d/e'), set()) | ||||
self.assertEqual(m.visitchildrenset(b'folder'), set()) | ||||
|
r38988 | class DifferenceMatcherTests(unittest.TestCase): | ||
def testVisitdirM2always(self): | ||||
|
r41824 | m1 = matchmod.alwaysmatcher() | ||
m2 = matchmod.alwaysmatcher() | ||||
|
r38988 | dm = matchmod.differencematcher(m1, m2) | ||
# dm should be equivalent to a nevermatcher. | ||||
|
r42528 | self.assertFalse(dm.visitdir(b'')) | ||
|
r38999 | self.assertFalse(dm.visitdir(b'dir')) | ||
self.assertFalse(dm.visitdir(b'dir/subdir')) | ||||
self.assertFalse(dm.visitdir(b'dir/subdir/z')) | ||||
self.assertFalse(dm.visitdir(b'dir/foo')) | ||||
self.assertFalse(dm.visitdir(b'dir/subdir/x')) | ||||
self.assertFalse(dm.visitdir(b'folder')) | ||||
|
r38988 | |||
|
r38990 | def testVisitchildrensetM2always(self): | ||
|
r41824 | m1 = matchmod.alwaysmatcher() | ||
m2 = matchmod.alwaysmatcher() | ||||
|
r38990 | dm = matchmod.differencematcher(m1, m2) | ||
# dm should be equivalent to a nevermatcher. | ||||
|
r42528 | self.assertEqual(dm.visitchildrenset(b''), set()) | ||
|
r38999 | self.assertEqual(dm.visitchildrenset(b'dir'), set()) | ||
self.assertEqual(dm.visitchildrenset(b'dir/subdir'), set()) | ||||
self.assertEqual(dm.visitchildrenset(b'dir/subdir/z'), set()) | ||||
self.assertEqual(dm.visitchildrenset(b'dir/foo'), set()) | ||||
self.assertEqual(dm.visitchildrenset(b'dir/subdir/x'), set()) | ||||
self.assertEqual(dm.visitchildrenset(b'folder'), set()) | ||||
|
r38990 | |||
|
r38988 | def testVisitdirM2never(self): | ||
|
r41824 | m1 = matchmod.alwaysmatcher() | ||
m2 = matchmod.nevermatcher() | ||||
|
r38988 | dm = matchmod.differencematcher(m1, m2) | ||
|
r41669 | # dm should be equivalent to a alwaysmatcher. | ||
|
r38988 | # | ||
# We're testing Equal-to-True instead of just 'assertTrue' since | ||||
# assertTrue does NOT verify that it's a bool, just that it's truthy. | ||||
# While we may want to eventually make these return 'all', they should | ||||
# not currently do so. | ||||
|
r42528 | self.assertEqual(dm.visitdir(b''), b'all') | ||
|
r41671 | self.assertEqual(dm.visitdir(b'dir'), b'all') | ||
self.assertEqual(dm.visitdir(b'dir/subdir'), b'all') | ||||
self.assertEqual(dm.visitdir(b'dir/subdir/z'), b'all') | ||||
self.assertEqual(dm.visitdir(b'dir/foo'), b'all') | ||||
self.assertEqual(dm.visitdir(b'dir/subdir/x'), b'all') | ||||
self.assertEqual(dm.visitdir(b'folder'), b'all') | ||||
|
r38988 | |||
|
r38990 | def testVisitchildrensetM2never(self): | ||
|
r41824 | m1 = matchmod.alwaysmatcher() | ||
m2 = matchmod.nevermatcher() | ||||
|
r38990 | dm = matchmod.differencematcher(m1, m2) | ||
# dm should be equivalent to a alwaysmatcher. | ||||
|
r42528 | self.assertEqual(dm.visitchildrenset(b''), b'all') | ||
|
r38999 | self.assertEqual(dm.visitchildrenset(b'dir'), b'all') | ||
self.assertEqual(dm.visitchildrenset(b'dir/subdir'), b'all') | ||||
self.assertEqual(dm.visitchildrenset(b'dir/subdir/z'), b'all') | ||||
self.assertEqual(dm.visitchildrenset(b'dir/foo'), b'all') | ||||
self.assertEqual(dm.visitchildrenset(b'dir/subdir/x'), b'all') | ||||
self.assertEqual(dm.visitchildrenset(b'folder'), b'all') | ||||
|
r38990 | |||
|
r38988 | def testVisitdirM2SubdirPrefix(self): | ||
|
r41824 | m1 = matchmod.alwaysmatcher() | ||
|
r38999 | m2 = matchmod.match(b'', b'', patterns=[b'path:dir/subdir']) | ||
|
r38988 | dm = matchmod.differencematcher(m1, m2) | ||
|
r42528 | self.assertEqual(dm.visitdir(b''), True) | ||
|
r38999 | self.assertEqual(dm.visitdir(b'dir'), True) | ||
self.assertFalse(dm.visitdir(b'dir/subdir')) | ||||
|
r38988 | # OPT: We should probably return False for these; we don't because | ||
# patternmatcher.visitdir() (our m2) doesn't return 'all' for subdirs of | ||||
# an 'all' pattern, just True. | ||||
|
r38999 | self.assertEqual(dm.visitdir(b'dir/subdir/z'), True) | ||
self.assertEqual(dm.visitdir(b'dir/subdir/x'), True) | ||||
|
r41671 | self.assertEqual(dm.visitdir(b'dir/foo'), b'all') | ||
self.assertEqual(dm.visitdir(b'folder'), b'all') | ||||
|
r38988 | |||
|
r38990 | def testVisitchildrensetM2SubdirPrefix(self): | ||
|
r41824 | m1 = matchmod.alwaysmatcher() | ||
|
r38999 | m2 = matchmod.match(b'', b'', patterns=[b'path:dir/subdir']) | ||
|
r38990 | dm = matchmod.differencematcher(m1, m2) | ||
|
r42528 | self.assertEqual(dm.visitchildrenset(b''), b'this') | ||
|
r38999 | self.assertEqual(dm.visitchildrenset(b'dir'), b'this') | ||
self.assertEqual(dm.visitchildrenset(b'dir/subdir'), set()) | ||||
self.assertEqual(dm.visitchildrenset(b'dir/foo'), b'all') | ||||
self.assertEqual(dm.visitchildrenset(b'folder'), b'all') | ||||
|
r38990 | # OPT: We should probably return set() for these; we don't because | ||
# patternmatcher.visitdir() (our m2) doesn't return 'all' for subdirs of | ||||
# an 'all' pattern, just 'this'. | ||||
|
r38999 | self.assertEqual(dm.visitchildrenset(b'dir/subdir/z'), b'this') | ||
self.assertEqual(dm.visitchildrenset(b'dir/subdir/x'), b'this') | ||||
|
r38990 | |||
|
r38988 | # We're using includematcher instead of patterns because it behaves slightly | ||
# better (giving narrower results) than patternmatcher. | ||||
def testVisitdirIncludeIncludfe(self): | ||||
|
r38999 | m1 = matchmod.match(b'', b'', include=[b'path:dir/subdir']) | ||
m2 = matchmod.match(b'', b'', include=[b'rootfilesin:dir']) | ||||
|
r38988 | dm = matchmod.differencematcher(m1, m2) | ||
|
r42528 | self.assertEqual(dm.visitdir(b''), True) | ||
|
r38999 | self.assertEqual(dm.visitdir(b'dir'), True) | ||
|
r41671 | self.assertEqual(dm.visitdir(b'dir/subdir'), b'all') | ||
|
r38999 | self.assertFalse(dm.visitdir(b'dir/foo')) | ||
self.assertFalse(dm.visitdir(b'folder')) | ||||
|
r38988 | # OPT: We should probably return False for these; we don't because | ||
# patternmatcher.visitdir() (our m2) doesn't return 'all' for subdirs of | ||||
# an 'all' pattern, just True. | ||||
|
r38999 | self.assertEqual(dm.visitdir(b'dir/subdir/z'), True) | ||
self.assertEqual(dm.visitdir(b'dir/subdir/x'), True) | ||||
|
r38988 | |||
|
r38990 | def testVisitchildrensetIncludeInclude(self): | ||
|
r38999 | m1 = matchmod.match(b'', b'', include=[b'path:dir/subdir']) | ||
m2 = matchmod.match(b'', b'', include=[b'rootfilesin:dir']) | ||||
|
r38990 | dm = matchmod.differencematcher(m1, m2) | ||
|
r42528 | self.assertEqual(dm.visitchildrenset(b''), {b'dir'}) | ||
|
r38999 | self.assertEqual(dm.visitchildrenset(b'dir'), {b'subdir'}) | ||
self.assertEqual(dm.visitchildrenset(b'dir/subdir'), b'all') | ||||
self.assertEqual(dm.visitchildrenset(b'dir/foo'), set()) | ||||
self.assertEqual(dm.visitchildrenset(b'folder'), set()) | ||||
|
r38990 | # OPT: We should probably return set() for these; we don't because | ||
# patternmatcher.visitdir() (our m2) doesn't return 'all' for subdirs of | ||||
# an 'all' pattern, just 'this'. | ||||
|
r38999 | self.assertEqual(dm.visitchildrenset(b'dir/subdir/z'), b'this') | ||
self.assertEqual(dm.visitchildrenset(b'dir/subdir/x'), b'this') | ||||
|
r38990 | |||
|
r38988 | class IntersectionMatcherTests(unittest.TestCase): | ||
def testVisitdirM2always(self): | ||||
|
r41824 | m1 = matchmod.alwaysmatcher() | ||
m2 = matchmod.alwaysmatcher() | ||||
|
r38988 | im = matchmod.intersectmatchers(m1, m2) | ||
# im should be equivalent to a alwaysmatcher. | ||||
|
r42528 | self.assertEqual(im.visitdir(b''), b'all') | ||
|
r38999 | self.assertEqual(im.visitdir(b'dir'), b'all') | ||
self.assertEqual(im.visitdir(b'dir/subdir'), b'all') | ||||
self.assertEqual(im.visitdir(b'dir/subdir/z'), b'all') | ||||
self.assertEqual(im.visitdir(b'dir/foo'), b'all') | ||||
self.assertEqual(im.visitdir(b'dir/subdir/x'), b'all') | ||||
self.assertEqual(im.visitdir(b'folder'), b'all') | ||||
|
r38988 | |||
|
r38990 | def testVisitchildrensetM2always(self): | ||
|
r41824 | m1 = matchmod.alwaysmatcher() | ||
m2 = matchmod.alwaysmatcher() | ||||
|
r38990 | im = matchmod.intersectmatchers(m1, m2) | ||
# im should be equivalent to a alwaysmatcher. | ||||
|
r42528 | self.assertEqual(im.visitchildrenset(b''), b'all') | ||
|
r38999 | self.assertEqual(im.visitchildrenset(b'dir'), b'all') | ||
self.assertEqual(im.visitchildrenset(b'dir/subdir'), b'all') | ||||
self.assertEqual(im.visitchildrenset(b'dir/subdir/z'), b'all') | ||||
self.assertEqual(im.visitchildrenset(b'dir/foo'), b'all') | ||||
self.assertEqual(im.visitchildrenset(b'dir/subdir/x'), b'all') | ||||
self.assertEqual(im.visitchildrenset(b'folder'), b'all') | ||||
|
r38990 | |||
|
r38988 | def testVisitdirM2never(self): | ||
|
r41824 | m1 = matchmod.alwaysmatcher() | ||
m2 = matchmod.nevermatcher() | ||||
|
r38988 | im = matchmod.intersectmatchers(m1, m2) | ||
# im should be equivalent to a nevermatcher. | ||||
|
r42528 | self.assertFalse(im.visitdir(b'')) | ||
|
r38999 | self.assertFalse(im.visitdir(b'dir')) | ||
self.assertFalse(im.visitdir(b'dir/subdir')) | ||||
self.assertFalse(im.visitdir(b'dir/subdir/z')) | ||||
self.assertFalse(im.visitdir(b'dir/foo')) | ||||
self.assertFalse(im.visitdir(b'dir/subdir/x')) | ||||
self.assertFalse(im.visitdir(b'folder')) | ||||
|
r38988 | |||
|
r38990 | def testVisitchildrensetM2never(self): | ||
|
r41824 | m1 = matchmod.alwaysmatcher() | ||
m2 = matchmod.nevermatcher() | ||||
|
r38990 | im = matchmod.intersectmatchers(m1, m2) | ||
# im should be equivalent to a nevermqtcher. | ||||
|
r42528 | self.assertEqual(im.visitchildrenset(b''), set()) | ||
|
r38999 | self.assertEqual(im.visitchildrenset(b'dir'), set()) | ||
self.assertEqual(im.visitchildrenset(b'dir/subdir'), set()) | ||||
self.assertEqual(im.visitchildrenset(b'dir/subdir/z'), set()) | ||||
self.assertEqual(im.visitchildrenset(b'dir/foo'), set()) | ||||
self.assertEqual(im.visitchildrenset(b'dir/subdir/x'), set()) | ||||
self.assertEqual(im.visitchildrenset(b'folder'), set()) | ||||
|
r38990 | |||
|
r38988 | def testVisitdirM2SubdirPrefix(self): | ||
|
r41824 | m1 = matchmod.alwaysmatcher() | ||
|
r38999 | m2 = matchmod.match(b'', b'', patterns=[b'path:dir/subdir']) | ||
|
r38988 | im = matchmod.intersectmatchers(m1, m2) | ||
|
r42528 | self.assertEqual(im.visitdir(b''), True) | ||
|
r38999 | self.assertEqual(im.visitdir(b'dir'), True) | ||
self.assertEqual(im.visitdir(b'dir/subdir'), b'all') | ||||
self.assertFalse(im.visitdir(b'dir/foo')) | ||||
self.assertFalse(im.visitdir(b'folder')) | ||||
|
r38988 | # OPT: We should probably return 'all' for these; we don't because | ||
# patternmatcher.visitdir() (our m2) doesn't return 'all' for subdirs of | ||||
# an 'all' pattern, just True. | ||||
|
r38999 | self.assertEqual(im.visitdir(b'dir/subdir/z'), True) | ||
self.assertEqual(im.visitdir(b'dir/subdir/x'), True) | ||||
|
r38988 | |||
|
r38990 | def testVisitchildrensetM2SubdirPrefix(self): | ||
|
r41824 | m1 = matchmod.alwaysmatcher() | ||
|
r38999 | m2 = matchmod.match(b'', b'', include=[b'path:dir/subdir']) | ||
|
r38990 | im = matchmod.intersectmatchers(m1, m2) | ||
|
r42528 | self.assertEqual(im.visitchildrenset(b''), {b'dir'}) | ||
|
r38999 | self.assertEqual(im.visitchildrenset(b'dir'), {b'subdir'}) | ||
self.assertEqual(im.visitchildrenset(b'dir/subdir'), b'all') | ||||
self.assertEqual(im.visitchildrenset(b'dir/foo'), set()) | ||||
self.assertEqual(im.visitchildrenset(b'folder'), set()) | ||||
|
r38990 | # OPT: We should probably return 'all' for these | ||
|
r38999 | self.assertEqual(im.visitchildrenset(b'dir/subdir/z'), b'this') | ||
self.assertEqual(im.visitchildrenset(b'dir/subdir/x'), b'this') | ||||
|
r38990 | |||
|
r38988 | # We're using includematcher instead of patterns because it behaves slightly | ||
# better (giving narrower results) than patternmatcher. | ||||
def testVisitdirIncludeIncludfe(self): | ||||
|
r38999 | m1 = matchmod.match(b'', b'', include=[b'path:dir/subdir']) | ||
m2 = matchmod.match(b'', b'', include=[b'rootfilesin:dir']) | ||||
|
r38988 | im = matchmod.intersectmatchers(m1, m2) | ||
|
r42528 | self.assertEqual(im.visitdir(b''), True) | ||
|
r38999 | self.assertEqual(im.visitdir(b'dir'), True) | ||
self.assertFalse(im.visitdir(b'dir/subdir')) | ||||
self.assertFalse(im.visitdir(b'dir/foo')) | ||||
self.assertFalse(im.visitdir(b'folder')) | ||||
self.assertFalse(im.visitdir(b'dir/subdir/z')) | ||||
self.assertFalse(im.visitdir(b'dir/subdir/x')) | ||||
|
r38988 | |||
|
r38990 | def testVisitchildrensetIncludeInclude(self): | ||
|
r38999 | m1 = matchmod.match(b'', b'', include=[b'path:dir/subdir']) | ||
m2 = matchmod.match(b'', b'', include=[b'rootfilesin:dir']) | ||||
|
r38990 | im = matchmod.intersectmatchers(m1, m2) | ||
|
r42528 | self.assertEqual(im.visitchildrenset(b''), {b'dir'}) | ||
|
r38999 | self.assertEqual(im.visitchildrenset(b'dir'), b'this') | ||
self.assertEqual(im.visitchildrenset(b'dir/subdir'), set()) | ||||
self.assertEqual(im.visitchildrenset(b'dir/foo'), set()) | ||||
self.assertEqual(im.visitchildrenset(b'folder'), set()) | ||||
self.assertEqual(im.visitchildrenset(b'dir/subdir/z'), set()) | ||||
self.assertEqual(im.visitchildrenset(b'dir/subdir/x'), set()) | ||||
|
r38990 | |||
|
r38988 | # We're using includematcher instead of patterns because it behaves slightly | ||
# better (giving narrower results) than patternmatcher. | ||||
def testVisitdirIncludeInclude2(self): | ||||
|
r38999 | m1 = matchmod.match(b'', b'', include=[b'path:dir/subdir']) | ||
m2 = matchmod.match(b'', b'', include=[b'path:folder']) | ||||
|
r38988 | im = matchmod.intersectmatchers(m1, m2) | ||
# FIXME: is True correct here? | ||||
|
r42528 | self.assertEqual(im.visitdir(b''), True) | ||
|
r38999 | self.assertFalse(im.visitdir(b'dir')) | ||
self.assertFalse(im.visitdir(b'dir/subdir')) | ||||
self.assertFalse(im.visitdir(b'dir/foo')) | ||||
self.assertFalse(im.visitdir(b'folder')) | ||||
self.assertFalse(im.visitdir(b'dir/subdir/z')) | ||||
self.assertFalse(im.visitdir(b'dir/subdir/x')) | ||||
|
r38988 | |||
|
r38990 | def testVisitchildrensetIncludeInclude2(self): | ||
|
r38999 | m1 = matchmod.match(b'', b'', include=[b'path:dir/subdir']) | ||
m2 = matchmod.match(b'', b'', include=[b'path:folder']) | ||||
|
r38990 | im = matchmod.intersectmatchers(m1, m2) | ||
# FIXME: is set() correct here? | ||||
|
r42528 | self.assertEqual(im.visitchildrenset(b''), set()) | ||
|
r38999 | self.assertEqual(im.visitchildrenset(b'dir'), set()) | ||
self.assertEqual(im.visitchildrenset(b'dir/subdir'), set()) | ||||
self.assertEqual(im.visitchildrenset(b'dir/foo'), set()) | ||||
self.assertEqual(im.visitchildrenset(b'folder'), set()) | ||||
self.assertEqual(im.visitchildrenset(b'dir/subdir/z'), set()) | ||||
self.assertEqual(im.visitchildrenset(b'dir/subdir/x'), set()) | ||||
|
r38990 | |||
|
r38988 | # We're using includematcher instead of patterns because it behaves slightly | ||
# better (giving narrower results) than patternmatcher. | ||||
def testVisitdirIncludeInclude3(self): | ||||
|
r38999 | m1 = matchmod.match(b'', b'', include=[b'path:dir/subdir/x']) | ||
m2 = matchmod.match(b'', b'', include=[b'path:dir/subdir']) | ||||
|
r38988 | im = matchmod.intersectmatchers(m1, m2) | ||
|
r42528 | self.assertEqual(im.visitdir(b''), True) | ||
|
r38999 | self.assertEqual(im.visitdir(b'dir'), True) | ||
self.assertEqual(im.visitdir(b'dir/subdir'), True) | ||||
self.assertFalse(im.visitdir(b'dir/foo')) | ||||
self.assertFalse(im.visitdir(b'folder')) | ||||
self.assertFalse(im.visitdir(b'dir/subdir/z')) | ||||
|
r38988 | # OPT: this should probably be 'all' not True. | ||
|
r38999 | self.assertEqual(im.visitdir(b'dir/subdir/x'), True) | ||
|
r38988 | |||
|
r38990 | def testVisitchildrensetIncludeInclude3(self): | ||
|
r38999 | m1 = matchmod.match(b'', b'', include=[b'path:dir/subdir/x']) | ||
m2 = matchmod.match(b'', b'', include=[b'path:dir/subdir']) | ||||
|
r38990 | im = matchmod.intersectmatchers(m1, m2) | ||
|
r42528 | self.assertEqual(im.visitchildrenset(b''), {b'dir'}) | ||
|
r38999 | self.assertEqual(im.visitchildrenset(b'dir'), {b'subdir'}) | ||
self.assertEqual(im.visitchildrenset(b'dir/subdir'), {b'x'}) | ||||
self.assertEqual(im.visitchildrenset(b'dir/foo'), set()) | ||||
self.assertEqual(im.visitchildrenset(b'folder'), set()) | ||||
self.assertEqual(im.visitchildrenset(b'dir/subdir/z'), set()) | ||||
|
r38990 | # OPT: this should probably be 'all' not 'this'. | ||
|
r38999 | self.assertEqual(im.visitchildrenset(b'dir/subdir/x'), b'this') | ||
|
r38990 | |||
|
r38988 | # We're using includematcher instead of patterns because it behaves slightly | ||
# better (giving narrower results) than patternmatcher. | ||||
def testVisitdirIncludeInclude4(self): | ||||
|
r38999 | m1 = matchmod.match(b'', b'', include=[b'path:dir/subdir/x']) | ||
m2 = matchmod.match(b'', b'', include=[b'path:dir/subdir/z']) | ||||
|
r38988 | im = matchmod.intersectmatchers(m1, m2) | ||
# OPT: these next three could probably be False as well. | ||||
|
r42528 | self.assertEqual(im.visitdir(b''), True) | ||
|
r38999 | self.assertEqual(im.visitdir(b'dir'), True) | ||
self.assertEqual(im.visitdir(b'dir/subdir'), True) | ||||
self.assertFalse(im.visitdir(b'dir/foo')) | ||||
self.assertFalse(im.visitdir(b'folder')) | ||||
self.assertFalse(im.visitdir(b'dir/subdir/z')) | ||||
self.assertFalse(im.visitdir(b'dir/subdir/x')) | ||||
|
r38988 | |||
|
r38990 | def testVisitchildrensetIncludeInclude4(self): | ||
|
r38999 | m1 = matchmod.match(b'', b'', include=[b'path:dir/subdir/x']) | ||
m2 = matchmod.match(b'', b'', include=[b'path:dir/subdir/z']) | ||||
|
r38990 | im = matchmod.intersectmatchers(m1, m2) | ||
# OPT: these next two could probably be set() as well. | ||||
|
r42528 | self.assertEqual(im.visitchildrenset(b''), {b'dir'}) | ||
|
r38999 | self.assertEqual(im.visitchildrenset(b'dir'), {b'subdir'}) | ||
self.assertEqual(im.visitchildrenset(b'dir/subdir'), set()) | ||||
self.assertEqual(im.visitchildrenset(b'dir/foo'), set()) | ||||
self.assertEqual(im.visitchildrenset(b'folder'), set()) | ||||
self.assertEqual(im.visitchildrenset(b'dir/subdir/z'), set()) | ||||
self.assertEqual(im.visitchildrenset(b'dir/subdir/x'), set()) | ||||
|
r38990 | |||
|
r38988 | class UnionMatcherTests(unittest.TestCase): | ||
def testVisitdirM2always(self): | ||||
|
r41824 | m1 = matchmod.alwaysmatcher() | ||
m2 = matchmod.alwaysmatcher() | ||||
|
r38988 | um = matchmod.unionmatcher([m1, m2]) | ||
# um should be equivalent to a alwaysmatcher. | ||||
|
r42528 | self.assertEqual(um.visitdir(b''), b'all') | ||
|
r38999 | self.assertEqual(um.visitdir(b'dir'), b'all') | ||
self.assertEqual(um.visitdir(b'dir/subdir'), b'all') | ||||
self.assertEqual(um.visitdir(b'dir/subdir/z'), b'all') | ||||
self.assertEqual(um.visitdir(b'dir/foo'), b'all') | ||||
self.assertEqual(um.visitdir(b'dir/subdir/x'), b'all') | ||||
self.assertEqual(um.visitdir(b'folder'), b'all') | ||||
|
r38988 | |||
|
r38990 | def testVisitchildrensetM2always(self): | ||
|
r41824 | m1 = matchmod.alwaysmatcher() | ||
m2 = matchmod.alwaysmatcher() | ||||
|
r38990 | um = matchmod.unionmatcher([m1, m2]) | ||
# um should be equivalent to a alwaysmatcher. | ||||
|
r42528 | self.assertEqual(um.visitchildrenset(b''), b'all') | ||
|
r38999 | self.assertEqual(um.visitchildrenset(b'dir'), b'all') | ||
self.assertEqual(um.visitchildrenset(b'dir/subdir'), b'all') | ||||
self.assertEqual(um.visitchildrenset(b'dir/subdir/z'), b'all') | ||||
self.assertEqual(um.visitchildrenset(b'dir/foo'), b'all') | ||||
self.assertEqual(um.visitchildrenset(b'dir/subdir/x'), b'all') | ||||
self.assertEqual(um.visitchildrenset(b'folder'), b'all') | ||||
|
r38990 | |||
|
r38988 | def testVisitdirM1never(self): | ||
|
r41824 | m1 = matchmod.nevermatcher() | ||
m2 = matchmod.alwaysmatcher() | ||||
|
r38988 | um = matchmod.unionmatcher([m1, m2]) | ||
# um should be equivalent to a alwaysmatcher. | ||||
|
r42528 | self.assertEqual(um.visitdir(b''), b'all') | ||
|
r38999 | self.assertEqual(um.visitdir(b'dir'), b'all') | ||
self.assertEqual(um.visitdir(b'dir/subdir'), b'all') | ||||
self.assertEqual(um.visitdir(b'dir/subdir/z'), b'all') | ||||
self.assertEqual(um.visitdir(b'dir/foo'), b'all') | ||||
self.assertEqual(um.visitdir(b'dir/subdir/x'), b'all') | ||||
self.assertEqual(um.visitdir(b'folder'), b'all') | ||||
|
r38988 | |||
|
r38990 | def testVisitchildrensetM1never(self): | ||
|
r41824 | m1 = matchmod.nevermatcher() | ||
m2 = matchmod.alwaysmatcher() | ||||
|
r38990 | um = matchmod.unionmatcher([m1, m2]) | ||
# um should be equivalent to a alwaysmatcher. | ||||
|
r42528 | self.assertEqual(um.visitchildrenset(b''), b'all') | ||
|
r38999 | self.assertEqual(um.visitchildrenset(b'dir'), b'all') | ||
self.assertEqual(um.visitchildrenset(b'dir/subdir'), b'all') | ||||
self.assertEqual(um.visitchildrenset(b'dir/subdir/z'), b'all') | ||||
self.assertEqual(um.visitchildrenset(b'dir/foo'), b'all') | ||||
self.assertEqual(um.visitchildrenset(b'dir/subdir/x'), b'all') | ||||
self.assertEqual(um.visitchildrenset(b'folder'), b'all') | ||||
|
r38990 | |||
|
r38988 | def testVisitdirM2never(self): | ||
|
r41824 | m1 = matchmod.alwaysmatcher() | ||
m2 = matchmod.nevermatcher() | ||||
|
r38988 | um = matchmod.unionmatcher([m1, m2]) | ||
# um should be equivalent to a alwaysmatcher. | ||||
|
r42528 | self.assertEqual(um.visitdir(b''), b'all') | ||
|
r38999 | self.assertEqual(um.visitdir(b'dir'), b'all') | ||
self.assertEqual(um.visitdir(b'dir/subdir'), b'all') | ||||
self.assertEqual(um.visitdir(b'dir/subdir/z'), b'all') | ||||
self.assertEqual(um.visitdir(b'dir/foo'), b'all') | ||||
self.assertEqual(um.visitdir(b'dir/subdir/x'), b'all') | ||||
self.assertEqual(um.visitdir(b'folder'), b'all') | ||||
|
r38988 | |||
|
r38990 | def testVisitchildrensetM2never(self): | ||
|
r41824 | m1 = matchmod.alwaysmatcher() | ||
m2 = matchmod.nevermatcher() | ||||
|
r38990 | um = matchmod.unionmatcher([m1, m2]) | ||
# um should be equivalent to a alwaysmatcher. | ||||
|
r42528 | self.assertEqual(um.visitchildrenset(b''), b'all') | ||
|
r38999 | self.assertEqual(um.visitchildrenset(b'dir'), b'all') | ||
self.assertEqual(um.visitchildrenset(b'dir/subdir'), b'all') | ||||
self.assertEqual(um.visitchildrenset(b'dir/subdir/z'), b'all') | ||||
self.assertEqual(um.visitchildrenset(b'dir/foo'), b'all') | ||||
self.assertEqual(um.visitchildrenset(b'dir/subdir/x'), b'all') | ||||
self.assertEqual(um.visitchildrenset(b'folder'), b'all') | ||||
|
r38990 | |||
|
r38988 | def testVisitdirM2SubdirPrefix(self): | ||
|
r41824 | m1 = matchmod.alwaysmatcher() | ||
|
r38999 | m2 = matchmod.match(b'', b'', patterns=[b'path:dir/subdir']) | ||
|
r38988 | um = matchmod.unionmatcher([m1, m2]) | ||
|
r42528 | self.assertEqual(um.visitdir(b''), b'all') | ||
|
r38999 | self.assertEqual(um.visitdir(b'dir'), b'all') | ||
self.assertEqual(um.visitdir(b'dir/subdir'), b'all') | ||||
self.assertEqual(um.visitdir(b'dir/foo'), b'all') | ||||
self.assertEqual(um.visitdir(b'folder'), b'all') | ||||
self.assertEqual(um.visitdir(b'dir/subdir/z'), b'all') | ||||
self.assertEqual(um.visitdir(b'dir/subdir/x'), b'all') | ||||
|
r38988 | |||
|
r38990 | def testVisitchildrensetM2SubdirPrefix(self): | ||
|
r41824 | m1 = matchmod.alwaysmatcher() | ||
|
r38999 | m2 = matchmod.match(b'', b'', include=[b'path:dir/subdir']) | ||
|
r38990 | um = matchmod.unionmatcher([m1, m2]) | ||
|
r42528 | self.assertEqual(um.visitchildrenset(b''), b'all') | ||
|
r38999 | self.assertEqual(um.visitchildrenset(b'dir'), b'all') | ||
self.assertEqual(um.visitchildrenset(b'dir/subdir'), b'all') | ||||
self.assertEqual(um.visitchildrenset(b'dir/foo'), b'all') | ||||
self.assertEqual(um.visitchildrenset(b'folder'), b'all') | ||||
self.assertEqual(um.visitchildrenset(b'dir/subdir/z'), b'all') | ||||
self.assertEqual(um.visitchildrenset(b'dir/subdir/x'), b'all') | ||||
|
r38990 | |||
|
r38988 | # We're using includematcher instead of patterns because it behaves slightly | ||
# better (giving narrower results) than patternmatcher. | ||||
def testVisitdirIncludeIncludfe(self): | ||||
|
r38999 | m1 = matchmod.match(b'', b'', include=[b'path:dir/subdir']) | ||
m2 = matchmod.match(b'', b'', include=[b'rootfilesin:dir']) | ||||
|
r38988 | um = matchmod.unionmatcher([m1, m2]) | ||
|
r42528 | self.assertEqual(um.visitdir(b''), True) | ||
|
r38999 | self.assertEqual(um.visitdir(b'dir'), True) | ||
self.assertEqual(um.visitdir(b'dir/subdir'), b'all') | ||||
self.assertFalse(um.visitdir(b'dir/foo')) | ||||
self.assertFalse(um.visitdir(b'folder')) | ||||
|
r38988 | # OPT: These two should probably be 'all' not True. | ||
|
r38999 | self.assertEqual(um.visitdir(b'dir/subdir/z'), True) | ||
self.assertEqual(um.visitdir(b'dir/subdir/x'), True) | ||||
|
r38988 | |||
|
r38990 | def testVisitchildrensetIncludeInclude(self): | ||
|
r38999 | m1 = matchmod.match(b'', b'', include=[b'path:dir/subdir']) | ||
m2 = matchmod.match(b'', b'', include=[b'rootfilesin:dir']) | ||||
|
r38990 | um = matchmod.unionmatcher([m1, m2]) | ||
|
r42528 | self.assertEqual(um.visitchildrenset(b''), {b'dir'}) | ||
|
r38999 | self.assertEqual(um.visitchildrenset(b'dir'), b'this') | ||
self.assertEqual(um.visitchildrenset(b'dir/subdir'), b'all') | ||||
self.assertEqual(um.visitchildrenset(b'dir/foo'), set()) | ||||
self.assertEqual(um.visitchildrenset(b'folder'), set()) | ||||
|
r38990 | # OPT: These next two could be 'all' instead of 'this'. | ||
|
r38999 | self.assertEqual(um.visitchildrenset(b'dir/subdir/z'), b'this') | ||
self.assertEqual(um.visitchildrenset(b'dir/subdir/x'), b'this') | ||||
|
r38990 | |||
|
r38988 | # We're using includematcher instead of patterns because it behaves slightly | ||
# better (giving narrower results) than patternmatcher. | ||||
def testVisitdirIncludeInclude2(self): | ||||
|
r38999 | m1 = matchmod.match(b'', b'', include=[b'path:dir/subdir']) | ||
m2 = matchmod.match(b'', b'', include=[b'path:folder']) | ||||
|
r38988 | um = matchmod.unionmatcher([m1, m2]) | ||
|
r42528 | self.assertEqual(um.visitdir(b''), True) | ||
|
r38999 | self.assertEqual(um.visitdir(b'dir'), True) | ||
self.assertEqual(um.visitdir(b'dir/subdir'), b'all') | ||||
self.assertFalse(um.visitdir(b'dir/foo')) | ||||
self.assertEqual(um.visitdir(b'folder'), b'all') | ||||
|
r38988 | # OPT: These should probably be 'all' not True. | ||
|
r38999 | self.assertEqual(um.visitdir(b'dir/subdir/z'), True) | ||
self.assertEqual(um.visitdir(b'dir/subdir/x'), True) | ||||
|
r38988 | |||
|
r38990 | def testVisitchildrensetIncludeInclude2(self): | ||
|
r38999 | m1 = matchmod.match(b'', b'', include=[b'path:dir/subdir']) | ||
m2 = matchmod.match(b'', b'', include=[b'path:folder']) | ||||
|
r38990 | um = matchmod.unionmatcher([m1, m2]) | ||
|
r42528 | self.assertEqual(um.visitchildrenset(b''), {b'folder', b'dir'}) | ||
|
r38999 | self.assertEqual(um.visitchildrenset(b'dir'), {b'subdir'}) | ||
self.assertEqual(um.visitchildrenset(b'dir/subdir'), b'all') | ||||
self.assertEqual(um.visitchildrenset(b'dir/foo'), set()) | ||||
self.assertEqual(um.visitchildrenset(b'folder'), b'all') | ||||
|
r38990 | # OPT: These next two could be 'all' instead of 'this'. | ||
|
r38999 | self.assertEqual(um.visitchildrenset(b'dir/subdir/z'), b'this') | ||
self.assertEqual(um.visitchildrenset(b'dir/subdir/x'), b'this') | ||||
|
r38990 | |||
|
r38988 | # We're using includematcher instead of patterns because it behaves slightly | ||
# better (giving narrower results) than patternmatcher. | ||||
def testVisitdirIncludeInclude3(self): | ||||
|
r38999 | m1 = matchmod.match(b'', b'', include=[b'path:dir/subdir/x']) | ||
m2 = matchmod.match(b'', b'', include=[b'path:dir/subdir']) | ||||
|
r38988 | um = matchmod.unionmatcher([m1, m2]) | ||
|
r42528 | self.assertEqual(um.visitdir(b''), True) | ||
|
r38999 | self.assertEqual(um.visitdir(b'dir'), True) | ||
self.assertEqual(um.visitdir(b'dir/subdir'), b'all') | ||||
self.assertFalse(um.visitdir(b'dir/foo')) | ||||
self.assertFalse(um.visitdir(b'folder')) | ||||
self.assertEqual(um.visitdir(b'dir/subdir/x'), b'all') | ||||
|
r38988 | # OPT: this should probably be 'all' not True. | ||
|
r38999 | self.assertEqual(um.visitdir(b'dir/subdir/z'), True) | ||
|
r38988 | |||
|
r38990 | def testVisitchildrensetIncludeInclude3(self): | ||
|
r38999 | m1 = matchmod.match(b'', b'', include=[b'path:dir/subdir/x']) | ||
m2 = matchmod.match(b'', b'', include=[b'path:dir/subdir']) | ||||
|
r38990 | um = matchmod.unionmatcher([m1, m2]) | ||
|
r42528 | self.assertEqual(um.visitchildrenset(b''), {b'dir'}) | ||
|
r38999 | self.assertEqual(um.visitchildrenset(b'dir'), {b'subdir'}) | ||
self.assertEqual(um.visitchildrenset(b'dir/subdir'), b'all') | ||||
self.assertEqual(um.visitchildrenset(b'dir/foo'), set()) | ||||
self.assertEqual(um.visitchildrenset(b'folder'), set()) | ||||
self.assertEqual(um.visitchildrenset(b'dir/subdir/x'), b'all') | ||||
|
r38990 | # OPT: this should probably be 'all' not 'this'. | ||
|
r38999 | self.assertEqual(um.visitchildrenset(b'dir/subdir/z'), b'this') | ||
|
r38990 | |||
|
r38988 | # We're using includematcher instead of patterns because it behaves slightly | ||
# better (giving narrower results) than patternmatcher. | ||||
def testVisitdirIncludeInclude4(self): | ||||
|
r38999 | m1 = matchmod.match(b'', b'', include=[b'path:dir/subdir/x']) | ||
m2 = matchmod.match(b'', b'', include=[b'path:dir/subdir/z']) | ||||
|
r38988 | um = matchmod.unionmatcher([m1, m2]) | ||
# OPT: these next three could probably be False as well. | ||||
|
r42528 | self.assertEqual(um.visitdir(b''), True) | ||
|
r38999 | self.assertEqual(um.visitdir(b'dir'), True) | ||
self.assertEqual(um.visitdir(b'dir/subdir'), True) | ||||
self.assertFalse(um.visitdir(b'dir/foo')) | ||||
self.assertFalse(um.visitdir(b'folder')) | ||||
self.assertEqual(um.visitdir(b'dir/subdir/z'), b'all') | ||||
self.assertEqual(um.visitdir(b'dir/subdir/x'), b'all') | ||||
|
r38988 | |||
|
r38990 | def testVisitchildrensetIncludeInclude4(self): | ||
|
r38999 | m1 = matchmod.match(b'', b'', include=[b'path:dir/subdir/x']) | ||
m2 = matchmod.match(b'', b'', include=[b'path:dir/subdir/z']) | ||||
|
r38990 | um = matchmod.unionmatcher([m1, m2]) | ||
|
r42528 | self.assertEqual(um.visitchildrenset(b''), {b'dir'}) | ||
|
r38999 | self.assertEqual(um.visitchildrenset(b'dir'), {b'subdir'}) | ||
self.assertEqual(um.visitchildrenset(b'dir/subdir'), {b'x', b'z'}) | ||||
self.assertEqual(um.visitchildrenset(b'dir/foo'), set()) | ||||
self.assertEqual(um.visitchildrenset(b'folder'), set()) | ||||
self.assertEqual(um.visitchildrenset(b'dir/subdir/z'), b'all') | ||||
self.assertEqual(um.visitchildrenset(b'dir/subdir/x'), b'all') | ||||
|
r38990 | |||
|
r38988 | class SubdirMatcherTests(unittest.TestCase): | ||
def testVisitdir(self): | ||||
|
r38999 | m = matchmod.match(b'', b'', include=[b'path:dir/subdir']) | ||
sm = matchmod.subdirmatcher(b'dir', m) | ||||
|
r38988 | |||
|
r42528 | self.assertEqual(sm.visitdir(b''), True) | ||
|
r38999 | self.assertEqual(sm.visitdir(b'subdir'), b'all') | ||
|
r38988 | # OPT: These next two should probably be 'all' not True. | ||
|
r38999 | self.assertEqual(sm.visitdir(b'subdir/x'), True) | ||
self.assertEqual(sm.visitdir(b'subdir/z'), True) | ||||
self.assertFalse(sm.visitdir(b'foo')) | ||||
|
r38988 | |||
|
r38990 | def testVisitchildrenset(self): | ||
|
r38999 | m = matchmod.match(b'', b'', include=[b'path:dir/subdir']) | ||
sm = matchmod.subdirmatcher(b'dir', m) | ||||
|
r38990 | |||
|
r42528 | self.assertEqual(sm.visitchildrenset(b''), {b'subdir'}) | ||
|
r38999 | self.assertEqual(sm.visitchildrenset(b'subdir'), b'all') | ||
|
r38990 | # OPT: These next two should probably be 'all' not 'this'. | ||
|
r38999 | self.assertEqual(sm.visitchildrenset(b'subdir/x'), b'this') | ||
self.assertEqual(sm.visitchildrenset(b'subdir/z'), b'this') | ||||
self.assertEqual(sm.visitchildrenset(b'foo'), set()) | ||||
|
r38990 | |||
|
r38988 | class PrefixdirMatcherTests(unittest.TestCase): | ||
def testVisitdir(self): | ||||
|
r38999 | m = matchmod.match(util.localpath(b'root/d'), b'e/f', | ||
[b'../a.txt', b'b.txt']) | ||||
|
r41824 | pm = matchmod.prefixdirmatcher(b'd', m) | ||
|
r38988 | |||
# `m` elides 'd' because it's part of the root, and the rest of the | ||||
# patterns are relative. | ||||
|
r38999 | self.assertEqual(bool(m(b'a.txt')), False) | ||
self.assertEqual(bool(m(b'b.txt')), False) | ||||
self.assertEqual(bool(m(b'e/a.txt')), True) | ||||
self.assertEqual(bool(m(b'e/b.txt')), False) | ||||
self.assertEqual(bool(m(b'e/f/b.txt')), True) | ||||
|
r38988 | |||
# The prefix matcher re-adds 'd' to the paths, so they need to be | ||||
# specified when using the prefixdirmatcher. | ||||
|
r38999 | self.assertEqual(bool(pm(b'a.txt')), False) | ||
self.assertEqual(bool(pm(b'b.txt')), False) | ||||
self.assertEqual(bool(pm(b'd/e/a.txt')), True) | ||||
self.assertEqual(bool(pm(b'd/e/b.txt')), False) | ||||
self.assertEqual(bool(pm(b'd/e/f/b.txt')), True) | ||||
|
r38988 | |||
|
r42528 | self.assertEqual(m.visitdir(b''), True) | ||
|
r38999 | self.assertEqual(m.visitdir(b'e'), True) | ||
self.assertEqual(m.visitdir(b'e/f'), True) | ||||
self.assertEqual(m.visitdir(b'e/f/g'), False) | ||||
|
r38988 | |||
|
r42528 | self.assertEqual(pm.visitdir(b''), True) | ||
|
r38999 | self.assertEqual(pm.visitdir(b'd'), True) | ||
self.assertEqual(pm.visitdir(b'd/e'), True) | ||||
self.assertEqual(pm.visitdir(b'd/e/f'), True) | ||||
self.assertEqual(pm.visitdir(b'd/e/f/g'), False) | ||||
|
r38988 | |||
|
r38990 | def testVisitchildrenset(self): | ||
|
r38999 | m = matchmod.match(util.localpath(b'root/d'), b'e/f', | ||
[b'../a.txt', b'b.txt']) | ||||
|
r41824 | pm = matchmod.prefixdirmatcher(b'd', m) | ||
|
r38990 | |||
# OPT: visitchildrenset could possibly return {'e'} and {'f'} for these | ||||
# next two, respectively; patternmatcher does not have this | ||||
# optimization. | ||||
|
r42528 | self.assertEqual(m.visitchildrenset(b''), b'this') | ||
|
r38999 | self.assertEqual(m.visitchildrenset(b'e'), b'this') | ||
self.assertEqual(m.visitchildrenset(b'e/f'), b'this') | ||||
self.assertEqual(m.visitchildrenset(b'e/f/g'), set()) | ||||
|
r38990 | |||
# OPT: visitchildrenset could possibly return {'d'}, {'e'}, and {'f'} | ||||
# for these next three, respectively; patternmatcher does not have this | ||||
# optimization. | ||||
|
r42528 | self.assertEqual(pm.visitchildrenset(b''), b'this') | ||
|
r38999 | self.assertEqual(pm.visitchildrenset(b'd'), b'this') | ||
self.assertEqual(pm.visitchildrenset(b'd/e'), b'this') | ||||
self.assertEqual(pm.visitchildrenset(b'd/e/f'), b'this') | ||||
self.assertEqual(pm.visitchildrenset(b'd/e/f/g'), set()) | ||||
|
r38990 | |||
|
r33583 | if __name__ == '__main__': | ||
silenttestrunner.main(__name__) | ||||