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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18
18
from bzrlib.globbing import (
22
24
from bzrlib.tests import (
171
173
[u'foo/x', u'foo/bax', u'foo/a.x', u'foo/.x', u'foo/.q.x'],
172
174
[u'foo/bar/bax']),
174
[u'\u8336/x', u'foo/x', u'foo/bax', u'x/a.x', u'.foo/x',
176
[u'\u8336/x', u'foo/x', u'foo/bax', u'x/a.x', u'.foo/x',
175
177
u'\u8336/.x', u'foo/.q.x'],
176
178
[u'foo/bar/bax']),
178
180
[u'foo', u'foo.bar'],
179
181
[u'.foo', u'foo/bar', u'foo/.bar']),
181
[u'bar', u'foobar', ur'foo\nbar', u'foo.bar', u'foo/bar',
183
[u'bar', u'foobar', ur'foo\nbar', u'foo.bar', u'foo/bar',
182
184
u'foo/foobar', u'foo/f.bar', u'.bar', u'foo/.bar'],
191
193
[u'foox', u'foo/bax', u'foo/.x', u'foo/bar/bax']),
193
195
[u'bar', u'foo/bar'],
194
[u'foobar', u'foo.bar', u'foo/foobar', u'foo/f.bar',
196
[u'foobar', u'foo.bar', u'foo/foobar', u'foo/f.bar',
195
197
u'.bar', u'foo/.bar']),
196
198
# check that we ignore extra *s, so *** is treated like ** not *.
199
201
[u'foox', u'foo/bax', u'foo/.x', u'foo/bar/bax']),
201
203
[u'bar', u'foo/bar'],
202
[u'foobar', u'foo.bar', u'foo/foobar', u'foo/f.bar',
204
[u'foobar', u'foo.bar', u'foo/foobar', u'foo/f.bar',
203
205
u'.bar', u'foo/.bar']),
204
206
# the remaining tests check that ** is interpreted as *
205
207
# unless it is a whole path component
216
218
[u'foo', u'foo.bar'],
217
219
[u'.foo', u'foo/bar', u'foo/.bar']),
219
[u'bar', u'foobar', ur'foo\nbar', u'foo.bar', u'foo/bar',
221
[u'bar', u'foobar', ur'foo\nbar', u'foo.bar', u'foo/bar',
220
222
u'foo/foobar', u'foo/f.bar', u'.bar', u'foo/.bar'],
257
259
def test_leading_asterisk_dot(self):
258
260
self.assertMatch([
260
[u'foo/bar/baz.x', u'\u8336/Q.x', u'foo.y.x', u'.foo.x',
262
[u'foo/bar/baz.x', u'\u8336/Q.x', u'foo.y.x', u'.foo.x',
261
263
u'bar/.foo.x', u'.x',],
293
295
def test_large_globset(self):
294
296
"""tests that the globster can handle a large set of patterns.
296
Large is defined as more than supported by python regex groups,
298
Large is defined as more than supported by python regex groups,
298
300
This test assumes the globs are broken into regexs containing 99
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/\\\\/'))