55
49
def test_char_group_digit(self):
56
50
self.assertMatchBasenameAndFullpath([
57
51
# The definition of digit this uses includes arabic digits from
58
# non-latin scripts (arabic, indic, etc.) but neither roman
59
# numerals nor vulgar fractions. Some characters such as
60
# subscript/superscript digits may or may not match depending on
61
# the Python version used, see: <http://bugs.python.org/issue6561>
52
# non-latin scripts (arabic, indic, etc.) and subscript/superscript
53
# digits, but neither roman numerals nor vulgar fractions.
63
[u'0', u'5', u'\u0663', u'\u06f9', u'\u0f21'],
55
[u'0', u'5', u'\u0663', u'\u06f9', u'\u0f21', u'\xb9'],
64
56
[u'T', u'q', u' ', u'\u8336', u'.']),
66
58
[u'T', u'q', u' ', u'\u8336', u'.'],
67
[u'0', u'5', u'\u0663', u'\u06f9', u'\u0f21']),
59
[u'0', u'5', u'\u0663', u'\u06f9', u'\u0f21', u'\xb9']),
70
62
def test_char_group_space(self):
178
170
[u'foo/x', u'foo/bax', u'foo/a.x', u'foo/.x', u'foo/.q.x'],
179
171
[u'foo/bar/bax']),
181
[u'\u8336/x', u'foo/x', u'foo/bax', u'x/a.x', u'.foo/x',
173
[u'\u8336/x', u'foo/x', u'foo/bax', u'x/a.x', u'.foo/x',
182
174
u'\u8336/.x', u'foo/.q.x'],
183
175
[u'foo/bar/bax']),
185
177
[u'foo', u'foo.bar'],
186
178
[u'.foo', u'foo/bar', u'foo/.bar']),
188
[u'bar', u'foobar', ur'foo\nbar', u'foo.bar', u'foo/bar',
180
[u'bar', u'foobar', ur'foo\nbar', u'foo.bar', u'foo/bar',
189
181
u'foo/foobar', u'foo/f.bar', u'.bar', u'foo/.bar'],
313
305
self.assertEqual(patterns[x],globster.match(filename))
314
306
self.assertEqual(None,globster.match('foobar.300'))
316
def test_bad_pattern(self):
317
"""Ensure that globster handles bad patterns cleanly."""
318
patterns = [u'RE:[', u'/home/foo', u'RE:*.cpp']
319
g = Globster(patterns)
320
e = self.assertRaises(errors.InvalidPattern, g.match, 'filename')
321
self.assertContainsRe(e.msg,
322
"File.*ignore.*contains error.*RE:\[.*RE:\*\.cpp", flags=re.DOTALL)
325
class TestExceptionGlobster(TestCase):
327
def test_exclusion_patterns(self):
328
"""test that exception patterns are not matched"""
329
patterns = [ u'*', u'!./local', u'!./local/**/*', u'!RE:\.z.*',u'!!./.zcompdump' ]
330
globster = ExceptionGlobster(patterns)
331
self.assertEqual(u'*', globster.match('tmp/foo.txt'))
332
self.assertEqual(None, globster.match('local'))
333
self.assertEqual(None, globster.match('local/bin/wombat'))
334
self.assertEqual(None, globster.match('.zshrc'))
335
self.assertEqual(None, globster.match('.zfunctions/fiddle/flam'))
336
self.assertEqual(u'!!./.zcompdump', globster.match('.zcompdump'))
338
def test_exclusion_order(self):
339
"""test that ordering of exclusion patterns does not matter"""
340
patterns = [ u'static/**/*.html', u'!static/**/versionable.html']
341
globster = ExceptionGlobster(patterns)
342
self.assertEqual(u'static/**/*.html', globster.match('static/foo.html'))
343
self.assertEqual(None, globster.match('static/versionable.html'))
344
self.assertEqual(None, globster.match('static/bar/versionable.html'))
345
globster = ExceptionGlobster(reversed(patterns))
346
self.assertEqual(u'static/**/*.html', globster.match('static/foo.html'))
347
self.assertEqual(None, globster.match('static/versionable.html'))
348
self.assertEqual(None, globster.match('static/bar/versionable.html'))
350
class TestOrderedGlobster(TestCase):
352
def test_ordered_globs(self):
353
"""test that the first match in a list is the one found"""
354
patterns = [ u'*.foo', u'bar.*']
355
globster = _OrderedGlobster(patterns)
356
self.assertEqual(u'*.foo', globster.match('bar.foo'))
357
self.assertEqual(None, globster.match('foo.bar'))
358
globster = _OrderedGlobster(reversed(patterns))
359
self.assertEqual(u'bar.*', globster.match('bar.foo'))
360
self.assertEqual(None, globster.match('foo.bar'))
363
class TestNormalizePattern(TestCase):
365
def test_backslashes(self):
366
"""tests that backslashes are converted to forward slashes, multiple
367
backslashes are collapsed to single forward slashes and trailing
368
backslashes are removed"""
369
self.assertEqual(u'/', normalize_pattern(u'\\'))
370
self.assertEqual(u'/', normalize_pattern(u'\\\\'))
371
self.assertEqual(u'/foo/bar', normalize_pattern(u'\\foo\\bar'))
372
self.assertEqual(u'foo/bar', normalize_pattern(u'foo\\bar\\'))
373
self.assertEqual(u'/foo/bar', normalize_pattern(u'\\\\foo\\\\bar\\\\'))
375
def test_forward_slashes(self):
376
"""tests that multiple foward slashes are collapsed to single forward
377
slashes and trailing forward slashes are removed"""
378
self.assertEqual(u'/', normalize_pattern(u'/'))
379
self.assertEqual(u'/', normalize_pattern(u'//'))
380
self.assertEqual(u'/foo/bar', normalize_pattern(u'/foo/bar'))
381
self.assertEqual(u'foo/bar', normalize_pattern(u'foo/bar/'))
382
self.assertEqual(u'/foo/bar', normalize_pattern(u'//foo//bar//'))
384
def test_mixed_slashes(self):
385
"""tests that multiple mixed slashes are collapsed to single forward
386
slashes and trailing mixed slashes are removed"""
387
self.assertEqual(u'/foo/bar', normalize_pattern(u'\\/\\foo//\\///bar/\\\\/'))