199
201
class TestUnescape(TestCase):
201
def assertLiteralRe(self, regex, match):
203
def assertLiteral(self, glob, match):
203
if _unescape_re(regex) != match:
205
if _unescape_glob(glob) != match:
204
206
raise AssertionError(repr(
205
u'Pattern "%s" does not expand to literal "%s"' % (regex,
207
u'Pattern "%s" does not expand to literal "%s"' % (glob,
207
209
except ValueError:
208
210
raise AssertionError(repr(
209
u'Pattern "%s" does not represent literal"' % regex))
210
if not re.match(regex, match, re.UNICODE):
211
u'Pattern "%s" does not represent literal"' % glob))
212
if not compile(glob).match(match):
211
213
raise AssertionError(repr(
212
u'Pattern "%s" does not match it\'s expansion "%s"' % (regex,
214
u'Pattern "%s" does not match it\'s expansion "%s"' % (glob,
216
def assertNotLiteral(self, regex):
218
def assertNotLiteral(self, glob):
218
exp = _unescape_re(regex)
220
exp = _unescape_glob(glob)
219
221
raise AssertionError(repr(
220
222
u'"%s" should NOT expand to "%s" (nor anything else)'
222
224
except ValueError:
226
228
def test_literals(self):
227
self.assertLiteralRe(u'foobar', u'foobar')
228
self.assertLiteralRe(u'foo/bar', u'foo/bar')
229
self.assertLiteralRe(u'qyzzy', u'qyzzy')
230
self.assertLiteralRe(u'\u8336', u'\u8336')
229
self.assertLiteral(u'foobar', u'foobar')
230
self.assertLiteral(u'foo/bar', u'foo/bar')
231
self.assertLiteral(u'qyzzy', u'qyzzy')
232
self.assertLiteral(u'\u8336', u'\u8336')
232
234
def test_chars(self):
233
self.assertLiteralRe(ur'\u8336', u'\u8336')
234
self.assertLiteralRe(ur'\x44\t\r\n', u'\x44\t\r\n')
235
self.assertLiteralRe(ur'\$\#\*', u'$#*')
235
self.assertLiteral(ur'\u8336', u'\u8336')
236
self.assertLiteral(ur'\x44\t\r\n', u'\x44\t\r\n')
237
self.assertLiteral(ur'\$\#\*', u'$#*')
236
238
self.assertNotLiteral(ur'\b')
237
239
self.assertNotLiteral(ur'\w')
239
def test_dollar(self):
240
self.assertLiteralRe(u'foobar$', u'foobar')
241
self.assertLiteralRe(u'\u8336$', u'\u8336')
243
241
def test_specials(self):
244
self.assertNotLiteral(ur'foo(2)bar')
245
242
self.assertNotLiteral(ur'foo*')
246
self.assertNotLiteral(ur'...')
247
243
self.assertNotLiteral(ur'qyzz?y')
248
self.assertNotLiteral(ur'a+b')
249
244
self.assertNotLiteral(ur'a[bcd]')
250
245
self.assertNotLiteral(ur'\w\d\D')
246
self.assertNotLiteral(ur'RE:anything')
252
248
def test_globs(self):
253
self.assertLiteralRe(translate(u'foo.bar'), u'foo.bar')
254
self.assertLiteralRe(translate(ur'foo\*bar'), u'foo*bar')
255
self.assertLiteralRe(translate(ur'b{q}z|2'), u'b{q}z|2')
256
self.assertLiteralRe(translate(ur'(foo)'), u'(foo)')
249
self.assertLiteral(u'foo.bar', u'foo.bar')
250
self.assertLiteral(ur'foo\*bar', u'foo*bar')
251
self.assertLiteral(ur'b{q}z|2', u'b{q}z|2')
252
self.assertLiteral(ur'(foo)', u'(foo)')
259
255
class TestExpansion(TestCaseInTempDir):