14
14
# You should have received a copy of the GNU General Public License
15
15
# along with this program; if not, write to the Free Software
16
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18
18
from bzrlib.globbing import (
24
22
from bzrlib.tests import (
173
171
[u'foo/x', u'foo/bax', u'foo/a.x', u'foo/.x', u'foo/.q.x'],
174
172
[u'foo/bar/bax']),
176
[u'\u8336/x', u'foo/x', u'foo/bax', u'x/a.x', u'.foo/x',
174
[u'\u8336/x', u'foo/x', u'foo/bax', u'x/a.x', u'.foo/x',
177
175
u'\u8336/.x', u'foo/.q.x'],
178
176
[u'foo/bar/bax']),
180
178
[u'foo', u'foo.bar'],
181
179
[u'.foo', u'foo/bar', u'foo/.bar']),
183
[u'bar', u'foobar', ur'foo\nbar', u'foo.bar', u'foo/bar',
181
[u'bar', u'foobar', ur'foo\nbar', u'foo.bar', u'foo/bar',
184
182
u'foo/foobar', u'foo/f.bar', u'.bar', u'foo/.bar'],
193
191
[u'foox', u'foo/bax', u'foo/.x', u'foo/bar/bax']),
195
193
[u'bar', u'foo/bar'],
196
[u'foobar', u'foo.bar', u'foo/foobar', u'foo/f.bar',
194
[u'foobar', u'foo.bar', u'foo/foobar', u'foo/f.bar',
197
195
u'.bar', u'foo/.bar']),
198
196
# check that we ignore extra *s, so *** is treated like ** not *.
201
199
[u'foox', u'foo/bax', u'foo/.x', u'foo/bar/bax']),
203
201
[u'bar', u'foo/bar'],
204
[u'foobar', u'foo.bar', u'foo/foobar', u'foo/f.bar',
202
[u'foobar', u'foo.bar', u'foo/foobar', u'foo/f.bar',
205
203
u'.bar', u'foo/.bar']),
206
204
# the remaining tests check that ** is interpreted as *
207
205
# unless it is a whole path component
218
216
[u'foo', u'foo.bar'],
219
217
[u'.foo', u'foo/bar', u'foo/.bar']),
221
[u'bar', u'foobar', ur'foo\nbar', u'foo.bar', u'foo/bar',
219
[u'bar', u'foobar', ur'foo\nbar', u'foo.bar', u'foo/bar',
222
220
u'foo/foobar', u'foo/f.bar', u'.bar', u'foo/.bar'],
259
257
def test_leading_asterisk_dot(self):
260
258
self.assertMatch([
262
[u'foo/bar/baz.x', u'\u8336/Q.x', u'foo.y.x', u'.foo.x',
260
[u'foo/bar/baz.x', u'\u8336/Q.x', u'foo.y.x', u'.foo.x',
263
261
u'bar/.foo.x', u'.x',],
295
293
def test_large_globset(self):
296
294
"""tests that the globster can handle a large set of patterns.
298
Large is defined as more than supported by python regex groups,
296
Large is defined as more than supported by python regex groups,
300
298
This test assumes the globs are broken into regexs containing 99
308
306
self.assertEqual(patterns[x],globster.match(filename))
309
307
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'))
336
310
class TestOrderedGlobster(TestCase):
344
318
globster = _OrderedGlobster(reversed(patterns))
345
319
self.assertEqual(u'bar.*', globster.match('bar.foo'))
346
320
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/\\\\/'))