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