~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_globbing.py

  • Committer: Vincent Ladeuil
  • Date: 2010-02-05 10:27:33 UTC
  • mto: (5008.1.1 integration)
  • mto: This revision was merged to the branch mainline in revision 5009.
  • Revision ID: v.ladeuil+lp@free.fr-20100205102733-8wpjnqz6g4nvrbfu
All Conflict action method names start with 'action_' to avoid potential namespace collisions

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
 
18
18
from bzrlib.globbing import (
19
19
    Globster,
 
20
    ExceptionGlobster,
20
21
    _OrderedGlobster,
 
22
    normalize_pattern
21
23
    )
22
24
from bzrlib.tests import (
23
25
    TestCase,
306
308
            self.assertEqual(patterns[x],globster.match(filename))
307
309
        self.assertEqual(None,globster.match('foobar.300'))
308
310
 
 
311
class TestExceptionGlobster(TestCase):
 
312
 
 
313
    def test_exclusion_patterns(self):
 
314
        """test that exception patterns are not matched"""
 
315
        patterns = [ u'*', u'!./local', u'!./local/**/*', u'!RE:\.z.*',u'!!./.zcompdump' ]
 
316
        globster = ExceptionGlobster(patterns)
 
317
        self.assertEqual(u'*', globster.match('tmp/foo.txt'))
 
318
        self.assertEqual(None, globster.match('local'))
 
319
        self.assertEqual(None, globster.match('local/bin/wombat'))
 
320
        self.assertEqual(None, globster.match('.zshrc'))
 
321
        self.assertEqual(None, globster.match('.zfunctions/fiddle/flam'))
 
322
        self.assertEqual(u'!!./.zcompdump', globster.match('.zcompdump'))
 
323
 
 
324
    def test_exclusion_order(self):
 
325
        """test that ordering of exclusion patterns does not matter"""
 
326
        patterns = [ u'static/**/*.html', u'!static/**/versionable.html']
 
327
        globster = ExceptionGlobster(patterns)
 
328
        self.assertEqual(u'static/**/*.html', globster.match('static/foo.html'))
 
329
        self.assertEqual(None, globster.match('static/versionable.html'))
 
330
        self.assertEqual(None, globster.match('static/bar/versionable.html'))
 
331
        globster = ExceptionGlobster(reversed(patterns))
 
332
        self.assertEqual(u'static/**/*.html', globster.match('static/foo.html'))
 
333
        self.assertEqual(None, globster.match('static/versionable.html'))
 
334
        self.assertEqual(None, globster.match('static/bar/versionable.html'))
309
335
 
310
336
class TestOrderedGlobster(TestCase):
311
337
 
318
344
        globster = _OrderedGlobster(reversed(patterns))
319
345
        self.assertEqual(u'bar.*', globster.match('bar.foo'))
320
346
        self.assertEqual(None, globster.match('foo.bar'))
 
347
 
 
348
 
 
349
class TestNormalizePattern(TestCase):
 
350
 
 
351
    def test_backslashes(self):
 
352
        """tests that backslashes are converted to forward slashes, multiple
 
353
        backslashes are collapsed to single forward slashes and trailing
 
354
        backslashes are removed"""
 
355
        self.assertEqual(u'/', normalize_pattern(u'\\'))
 
356
        self.assertEqual(u'/', normalize_pattern(u'\\\\'))
 
357
        self.assertEqual(u'/foo/bar', normalize_pattern(u'\\foo\\bar'))
 
358
        self.assertEqual(u'foo/bar', normalize_pattern(u'foo\\bar\\'))
 
359
        self.assertEqual(u'/foo/bar', normalize_pattern(u'\\\\foo\\\\bar\\\\'))
 
360
 
 
361
    def test_forward_slashes(self):
 
362
        """tests that multiple foward slashes are collapsed to single forward
 
363
        slashes and trailing forward slashes are removed"""
 
364
        self.assertEqual(u'/', normalize_pattern(u'/'))
 
365
        self.assertEqual(u'/', normalize_pattern(u'//'))
 
366
        self.assertEqual(u'/foo/bar', normalize_pattern(u'/foo/bar'))
 
367
        self.assertEqual(u'foo/bar', normalize_pattern(u'foo/bar/'))
 
368
        self.assertEqual(u'/foo/bar', normalize_pattern(u'//foo//bar//'))
 
369
 
 
370
    def test_mixed_slashes(self):
 
371
        """tests that multiple mixed slashes are collapsed to single forward
 
372
        slashes and trailing mixed slashes are removed"""
 
373
        self.assertEqual(u'/foo/bar', normalize_pattern(u'\\/\\foo//\\///bar/\\\\/'))