~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_globbing.py

  • Committer: Jelmer Vernooij
  • Date: 2009-01-28 18:42:55 UTC
  • mto: This revision was merged to the branch mainline in revision 3968.
  • Revision ID: jelmer@samba.org-20090128184255-bdmklkvm83ltk191
Update NEWS

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
 
18
18
from bzrlib.globbing import (
19
19
    Globster,
 
20
    _OrderedGlobster,
20
21
    )
21
22
from bzrlib.tests import (
22
23
    TestCase, 
114
115
            (u'[a-z]',
115
116
             [u'a', u'q', u'f'],
116
117
             [u'A', u'Q', u'F']),
117
 
            (ur'[^a-z]',
 
118
            (u'[^a-z]',
118
119
             [u'A', u'Q', u'F'],
119
120
             [u'a', u'q', u'f']),
120
121
            (u'[!a-z]foo',
121
122
             [u'Afoo', u'.foo'],
122
123
             [u'afoo', u'ABfoo']),
123
 
            (ur'foo[!a-z]bar',
 
124
            (u'foo[!a-z]bar',
124
125
             [u'fooAbar', u'foo.bar'],
125
126
             [u'foojbar']),
126
 
            (ur'[\x20-\x30\u8336]',
 
127
            (u'[\x20-\x30\u8336]',
127
128
             [u'\040', u'\044', u'\u8336'],
128
129
             [u'\x1f']),
129
 
            (ur'[^\x20-\x30\u8336]',
 
130
            (u'[^\x20-\x30\u8336]',
130
131
             [u'\x1f'],
131
132
             [u'\040', u'\044', u'\u8336']),
132
133
            ])
133
134
 
134
135
    def test_regex(self):
135
136
        self.assertMatch([
136
 
            (ur'RE:(a|b|c+)',
137
 
             [u'a', u'b', u'ccc'],
138
 
             [u'd', u'aa', u'c+', u'-a']),
139
 
            (ur'RE:(?:a|b|c+)',
140
 
             [u'a', u'b', u'ccc'],
141
 
             [u'd', u'aa', u'c+', u'-a']),
142
 
            (ur'RE:(?P<a>.)(?P=a)',
 
137
            (u'RE:(a|b|c+)',
 
138
             [u'a', u'b', u'ccc'],
 
139
             [u'd', u'aa', u'c+', u'-a']),
 
140
            (u'RE:(?:a|b|c+)',
 
141
             [u'a', u'b', u'ccc'],
 
142
             [u'd', u'aa', u'c+', u'-a']),
 
143
            (u'RE:(?P<a>.)(?P=a)',
143
144
             [u'a'],
144
145
             [u'ab', u'aa', u'aaa']),
 
146
            # test we can handle odd numbers of trailing backslashes
 
147
            (u'RE:a\\\\\\',
 
148
             [u'a\\'],
 
149
             [u'a', u'ab', u'aa', u'aaa']),
145
150
            ])
146
151
 
147
152
    def test_question_mark(self):
226
231
             [u'foo/bar', u'foo/.bar', u'x/foo/y']),
227
232
            ])
228
233
 
 
234
    def test_backslash(self):
 
235
        self.assertMatch([
 
236
            (u'.\\foo',
 
237
             [u'foo'],
 
238
             [u'\u8336/foo', u'barfoo', u'x/y/foo']),
 
239
            (u'.\\f*',
 
240
             [u'foo'],
 
241
             [u'foo/bar', u'foo/.bar', u'x/foo/y']),
 
242
            (u'foo\\**\\x',
 
243
             [u'foo/x', u'foo/bar/x'],
 
244
             [u'foox', u'foo/bax', u'foo/.x', u'foo/bar/bax']),
 
245
            ])
 
246
 
 
247
    def test_trailing_slash(self):
 
248
        self.assertMatch([
 
249
            (u'./foo/',
 
250
             [u'foo'],
 
251
             [u'\u8336/foo', u'barfoo', u'x/y/foo']),
 
252
            (u'.\\foo\\',
 
253
             [u'foo'],
 
254
             [u'foo/', u'\u8336/foo', u'barfoo', u'x/y/foo']),
 
255
            ])
 
256
 
229
257
    def test_leading_asterisk_dot(self):
230
258
        self.assertMatch([
231
259
            (u'*.x',
278
306
            self.assertEqual(patterns[x],globster.match(filename))
279
307
        self.assertEqual(None,globster.match('foobar.300'))
280
308
 
 
309
 
 
310
class TestOrderedGlobster(TestCase):
 
311
 
 
312
    def test_ordered_globs(self):
 
313
        """test that the first match in a list is the one found"""
 
314
        patterns = [ u'*.foo', u'bar.*']
 
315
        globster = _OrderedGlobster(patterns)
 
316
        self.assertEqual(u'*.foo', globster.match('bar.foo'))
 
317
        self.assertEqual(None, globster.match('foo.bar'))
 
318
        globster = _OrderedGlobster(reversed(patterns))
 
319
        self.assertEqual(u'bar.*', globster.match('bar.foo'))
 
320
        self.assertEqual(None, globster.match('foo.bar'))