306
308
self.assertEqual(patterns[x],globster.match(filename))
307
309
self.assertEqual(None,globster.match('foobar.300'))
311
class TestExceptionGlobster(TestCase):
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'))
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'))
310
336
class TestOrderedGlobster(TestCase):
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'))
349
class TestNormalizePattern(TestCase):
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\\\\'))
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//'))
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/\\\\/'))