annotate tests/test-match.py @ 38955:081cc9a95b65

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