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
21
18
from bzrlib.globbing import (
27
22
from bzrlib.tests import (
55
50
def test_char_group_digit(self):
56
51
self.assertMatchBasenameAndFullpath([
57
52
# 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>
53
# non-latin scripts (arabic, indic, etc.) and subscript/superscript
54
# digits, but neither roman numerals nor vulgar fractions.
63
[u'0', u'5', u'\u0663', u'\u06f9', u'\u0f21'],
56
[u'0', u'5', u'\u0663', u'\u06f9', u'\u0f21', u'\xb9'],
64
57
[u'T', u'q', u' ', u'\u8336', u'.']),
66
59
[u'T', u'q', u' ', u'\u8336', u'.'],
67
[u'0', u'5', u'\u0663', u'\u06f9', u'\u0f21']),
60
[u'0', u'5', u'\u0663', u'\u06f9', u'\u0f21', u'\xb9']),
70
63
def test_char_group_space(self):
313
306
self.assertEqual(patterns[x],globster.match(filename))
314
307
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
310
class TestOrderedGlobster(TestCase):
358
318
globster = _OrderedGlobster(reversed(patterns))
359
319
self.assertEqual(u'bar.*', globster.match('bar.foo'))
360
320
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/\\\\/'))