~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_globbing.py

  • Committer: John Arbash Meinel
  • Date: 2007-03-02 01:27:53 UTC
  • mto: (2255.7.86 dirstate)
  • mto: This revision was merged to the branch mainline in revision 2322.
  • Revision ID: john@arbash-meinel.com-20070302012753-5jwb15csi4j2mi4w
Fix a small bug when we have a symlink that does not need to be re-read.

Show diffs side-by-side

added added

removed removed

Lines of Context:
13
13
#
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
17
17
 
18
18
from bzrlib.globbing import (
19
19
    Globster,
20
 
    _OrderedGlobster,
21
 
    normalize_pattern
22
20
    )
23
21
from bzrlib.tests import (
24
 
    TestCase,
 
22
    TestCase, 
25
23
    TestCaseInTempDir,
26
24
    )
27
25
 
116
114
            (u'[a-z]',
117
115
             [u'a', u'q', u'f'],
118
116
             [u'A', u'Q', u'F']),
119
 
            (u'[^a-z]',
 
117
            (ur'[^a-z]',
120
118
             [u'A', u'Q', u'F'],
121
119
             [u'a', u'q', u'f']),
122
120
            (u'[!a-z]foo',
123
121
             [u'Afoo', u'.foo'],
124
122
             [u'afoo', u'ABfoo']),
125
 
            (u'foo[!a-z]bar',
 
123
            (ur'foo[!a-z]bar',
126
124
             [u'fooAbar', u'foo.bar'],
127
125
             [u'foojbar']),
128
 
            (u'[\x20-\x30\u8336]',
 
126
            (ur'[\x20-\x30\u8336]',
129
127
             [u'\040', u'\044', u'\u8336'],
130
128
             [u'\x1f']),
131
 
            (u'[^\x20-\x30\u8336]',
 
129
            (ur'[^\x20-\x30\u8336]',
132
130
             [u'\x1f'],
133
131
             [u'\040', u'\044', u'\u8336']),
134
132
            ])
135
133
 
136
134
    def test_regex(self):
137
135
        self.assertMatch([
138
 
            (u'RE:(a|b|c+)',
139
 
             [u'a', u'b', u'ccc'],
140
 
             [u'd', u'aa', u'c+', u'-a']),
141
 
            (u'RE:(?:a|b|c+)',
142
 
             [u'a', u'b', u'ccc'],
143
 
             [u'd', u'aa', u'c+', u'-a']),
144
 
            (u'RE:(?P<a>.)(?P=a)',
 
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)',
145
143
             [u'a'],
146
144
             [u'ab', u'aa', u'aaa']),
147
 
            # test we can handle odd numbers of trailing backslashes
148
 
            (u'RE:a\\\\\\',
149
 
             [u'a\\'],
150
 
             [u'a', u'ab', u'aa', u'aaa']),
151
145
            ])
152
146
 
153
147
    def test_question_mark(self):
172
166
             [u'foo/x', u'foo/bax', u'foo/a.x', u'foo/.x', u'foo/.q.x'],
173
167
             [u'foo/bar/bax']),
174
168
            (u'*/*x',
175
 
             [u'\u8336/x', u'foo/x', u'foo/bax', u'x/a.x', u'.foo/x',
 
169
             [u'\u8336/x', u'foo/x', u'foo/bax', u'x/a.x', u'.foo/x', 
176
170
              u'\u8336/.x', u'foo/.q.x'],
177
171
             [u'foo/bar/bax']),
178
172
            (u'f*',
179
173
             [u'foo', u'foo.bar'],
180
174
             [u'.foo', u'foo/bar', u'foo/.bar']),
181
175
            (u'*bar',
182
 
             [u'bar', u'foobar', ur'foo\nbar', u'foo.bar', u'foo/bar',
 
176
             [u'bar', u'foobar', ur'foo\nbar', u'foo.bar', u'foo/bar', 
183
177
              u'foo/foobar', u'foo/f.bar', u'.bar', u'foo/.bar'],
184
178
             []),
185
179
            ])
192
186
             [u'foox', u'foo/bax', u'foo/.x', u'foo/bar/bax']),
193
187
            (u'**/bar',
194
188
             [u'bar', u'foo/bar'],
195
 
             [u'foobar', u'foo.bar', u'foo/foobar', u'foo/f.bar',
 
189
             [u'foobar', u'foo.bar', u'foo/foobar', u'foo/f.bar', 
196
190
              u'.bar', u'foo/.bar']),
197
191
            # check that we ignore extra *s, so *** is treated like ** not *.
198
192
            (u'foo/***/x',
200
194
             [u'foox', u'foo/bax', u'foo/.x', u'foo/bar/bax']),
201
195
            (u'***/bar',
202
196
             [u'bar', u'foo/bar'],
203
 
             [u'foobar', u'foo.bar', u'foo/foobar', u'foo/f.bar',
 
197
             [u'foobar', u'foo.bar', u'foo/foobar', u'foo/f.bar', 
204
198
              u'.bar', u'foo/.bar']),
205
199
            # the remaining tests check that ** is interpreted as *
206
200
            # unless it is a whole path component
217
211
             [u'foo', u'foo.bar'],
218
212
             [u'.foo', u'foo/bar', u'foo/.bar']),
219
213
            (u'**bar',
220
 
             [u'bar', u'foobar', ur'foo\nbar', u'foo.bar', u'foo/bar',
 
214
             [u'bar', u'foobar', ur'foo\nbar', u'foo.bar', u'foo/bar', 
221
215
              u'foo/foobar', u'foo/f.bar', u'.bar', u'foo/.bar'],
222
216
             []),
223
217
            ])
232
226
             [u'foo/bar', u'foo/.bar', u'x/foo/y']),
233
227
            ])
234
228
 
235
 
    def test_backslash(self):
236
 
        self.assertMatch([
237
 
            (u'.\\foo',
238
 
             [u'foo'],
239
 
             [u'\u8336/foo', u'barfoo', u'x/y/foo']),
240
 
            (u'.\\f*',
241
 
             [u'foo'],
242
 
             [u'foo/bar', u'foo/.bar', u'x/foo/y']),
243
 
            (u'foo\\**\\x',
244
 
             [u'foo/x', u'foo/bar/x'],
245
 
             [u'foox', u'foo/bax', u'foo/.x', u'foo/bar/bax']),
246
 
            ])
247
 
 
248
 
    def test_trailing_slash(self):
249
 
        self.assertMatch([
250
 
            (u'./foo/',
251
 
             [u'foo'],
252
 
             [u'\u8336/foo', u'barfoo', u'x/y/foo']),
253
 
            (u'.\\foo\\',
254
 
             [u'foo'],
255
 
             [u'foo/', u'\u8336/foo', u'barfoo', u'x/y/foo']),
256
 
            ])
257
 
 
258
229
    def test_leading_asterisk_dot(self):
259
230
        self.assertMatch([
260
231
            (u'*.x',
261
 
             [u'foo/bar/baz.x', u'\u8336/Q.x', u'foo.y.x', u'.foo.x',
 
232
             [u'foo/bar/baz.x', u'\u8336/Q.x', u'foo.y.x', u'.foo.x', 
262
233
              u'bar/.foo.x', u'.x',],
263
234
             [u'foo.x.y']),
264
235
            (u'foo/*.bar',
294
265
    def test_large_globset(self):
295
266
        """tests that the globster can handle a large set of patterns.
296
267
 
297
 
        Large is defined as more than supported by python regex groups,
 
268
        Large is defined as more than supported by python regex groups, 
298
269
        i.e. 99.
299
270
        This test assumes the globs are broken into regexs containing 99
300
271
        groups.
307
278
            self.assertEqual(patterns[x],globster.match(filename))
308
279
        self.assertEqual(None,globster.match('foobar.300'))
309
280
 
310
 
 
311
 
class TestOrderedGlobster(TestCase):
312
 
 
313
 
    def test_ordered_globs(self):
314
 
        """test that the first match in a list is the one found"""
315
 
        patterns = [ u'*.foo', u'bar.*']
316
 
        globster = _OrderedGlobster(patterns)
317
 
        self.assertEqual(u'*.foo', globster.match('bar.foo'))
318
 
        self.assertEqual(None, globster.match('foo.bar'))
319
 
        globster = _OrderedGlobster(reversed(patterns))
320
 
        self.assertEqual(u'bar.*', globster.match('bar.foo'))
321
 
        self.assertEqual(None, globster.match('foo.bar'))
322
 
 
323
 
 
324
 
class TestNormalizePattern(TestCase):
325
 
 
326
 
    def test_backslashes(self):
327
 
        """tests that backslashes are converted to forward slashes, multiple
328
 
        backslashes are collapsed to single forward slashes and trailing
329
 
        backslashes are removed"""
330
 
        self.assertEqual(u'/', normalize_pattern(u'\\'))
331
 
        self.assertEqual(u'/', normalize_pattern(u'\\\\'))
332
 
        self.assertEqual(u'/foo/bar', normalize_pattern(u'\\foo\\bar'))
333
 
        self.assertEqual(u'foo/bar', normalize_pattern(u'foo\\bar\\'))
334
 
        self.assertEqual(u'/foo/bar', normalize_pattern(u'\\\\foo\\\\bar\\\\'))
335
 
 
336
 
    def test_forward_slashes(self):
337
 
        """tests that multiple foward slashes are collapsed to single forward
338
 
        slashes and trailing forward slashes are removed"""
339
 
        self.assertEqual(u'/', normalize_pattern(u'/'))
340
 
        self.assertEqual(u'/', normalize_pattern(u'//'))
341
 
        self.assertEqual(u'/foo/bar', normalize_pattern(u'/foo/bar'))
342
 
        self.assertEqual(u'foo/bar', normalize_pattern(u'foo/bar/'))
343
 
        self.assertEqual(u'/foo/bar', normalize_pattern(u'//foo//bar//'))
344
 
 
345
 
    def test_mixed_slashes(self):
346
 
        """tests that multiple mixed slashes are collapsed to single forward
347
 
        slashes and trailing mixed slashes are removed"""
348
 
        self.assertEqual(u'/foo/bar', normalize_pattern(u'\\/\\foo//\\///bar/\\\\/'))