diff -r af0dcd9df0c0 Lib/test/test_re.py --- a/Lib/test/test_re.py Sat Mar 12 11:18:46 2011 +0000 +++ b/Lib/test/test_re.py Sun Mar 13 02:58:05 2011 +0000 @@ -412,30 +412,31 @@ self.assertEqual(re.search("a\s", "a ").group(0), "a ") def test_re_escape(self): - p="" - self.assertEqual(re.escape(p), p) - for i in range(0, 256): - p = p + chr(i) - self.assertEqual(re.match(re.escape(chr(i)), chr(i)) is not None, - True) - self.assertEqual(re.match(re.escape(chr(i)), chr(i)).span(), (0,1)) - - pat=re.compile(re.escape(p)) - self.assertEqual(pat.match(p) is not None, True) - self.assertEqual(pat.match(p).span(), (0,256)) + for c in {'\0', '_', '!', '\t', ''}: + self.assertEqual(re.escape(c), c) + p = ''.join(chr(i) for i in range(256)) + for c in p: + m = re.match(re.escape(c), c) + self.assertTrue(m) + self.assertEqual(m.span(), (0, 1)) + + match = re.match(re.escape(p), p) + self.assertTrue(match) + self.assertEqual(match.span(), (0, 256)) def test_re_escape_byte(self): - p=b"" - self.assertEqual(re.escape(p), p) - for i in range(0, 256): + for b in {b'\0', b'_', b'!', b'\t', b''}: + self.assertEqual(re.escape(b), b) + for i in range(256): b = bytes([i]) - p += b - self.assertEqual(re.match(re.escape(b), b) is not None, True) - self.assertEqual(re.match(re.escape(b), b).span(), (0,1)) + m = re.match(re.escape(b), b) + self.assertTrue(m) + self.assertEqual(m.span(), (0, 1)) - pat=re.compile(re.escape(p)) - self.assertEqual(pat.match(p) is not None, True) - self.assertEqual(pat.match(p).span(), (0,256)) + p = bytes(range(256)) + match = re.match(re.escape(p), p) + self.assertTrue(match) + self.assertEqual(match.span(), (0, 256)) def pickle_test(self, pickle): oldpat = re.compile('a(?:b|(c|e){1,2}?|d)+?(.)')