15
15
# along with this program; if not, write to the Free Software
16
16
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20
from bzrlib import errors
18
21
from bzrlib.globbing import (
35
37
glob = glob_prefix + glob
36
38
globster = Globster([glob])
37
39
for name in positive:
38
self.failUnless(globster.match(name), repr(
40
self.assertTrue(globster.match(name), repr(
39
41
u'name "%s" does not match glob "%s" (re=%s)' %
40
42
(name, glob, globster._regex_patterns[0][0].pattern)))
41
43
for name in negative:
42
self.failIf(globster.match(name), repr(
44
self.assertFalse(globster.match(name), repr(
43
45
u'name "%s" does match glob "%s" (re=%s)' %
44
46
(name, glob, globster._regex_patterns[0][0].pattern)))
52
54
def test_char_group_digit(self):
53
55
self.assertMatchBasenameAndFullpath([
54
56
# The definition of digit this uses includes arabic digits from
55
# non-latin scripts (arabic, indic, etc.) and subscript/superscript
56
# digits, but neither roman numerals nor vulgar fractions.
57
# non-latin scripts (arabic, indic, etc.) but neither roman
58
# numerals nor vulgar fractions. Some characters such as
59
# subscript/superscript digits may or may not match depending on
60
# the Python version used, see: <http://bugs.python.org/issue6561>
58
[u'0', u'5', u'\u0663', u'\u06f9', u'\u0f21', u'\xb9'],
62
[u'0', u'5', u'\u0663', u'\u06f9', u'\u0f21'],
59
63
[u'T', u'q', u' ', u'\u8336', u'.']),
61
65
[u'T', u'q', u' ', u'\u8336', u'.'],
62
[u'0', u'5', u'\u0663', u'\u06f9', u'\u0f21', u'\xb9']),
66
[u'0', u'5', u'\u0663', u'\u06f9', u'\u0f21']),
65
69
def test_char_group_space(self):
308
312
self.assertEqual(patterns[x],globster.match(filename))
309
313
self.assertEqual(None,globster.match('foobar.300'))
315
def test_bad_pattern(self):
316
"""Ensure that globster handles bad patterns cleanly."""
317
patterns = [u'RE:[', u'/home/foo', u'RE:*.cpp']
318
g = Globster(patterns)
319
e = self.assertRaises(errors.InvalidPattern, g.match, 'filename')
320
self.assertContainsRe(e.msg,
321
"File.*ignore.*contains error.*RE:\[.*RE:\*\.cpp", flags=re.DOTALL)
311
324
class TestExceptionGlobster(TestCase):
313
326
def test_exclusion_patterns(self):