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