diff options
author | Guido van Rossum <guido@python.org> | 2008-09-10 17:44:35 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 2008-09-10 17:44:35 (GMT) |
commit | 698280df7c321b9986ee000054bb9dbbb32625af (patch) | |
tree | 258427b62da42e27228b837314ace46cde063aa1 /Lib/test/test_re.py | |
parent | 92f8f3e013ccb5bb94b1c6133b9b226590587dba (diff) | |
download | cpython-698280df7c321b9986ee000054bb9dbbb32625af.zip cpython-698280df7c321b9986ee000054bb9dbbb32625af.tar.gz cpython-698280df7c321b9986ee000054bb9dbbb32625af.tar.bz2 |
Issue #3756: make re.escape() handle bytes as well as str.
Patch by Andrew McNamara, reviewed and tweaked by myself.
Diffstat (limited to 'Lib/test/test_re.py')
-rw-r--r-- | Lib/test/test_re.py | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/Lib/test/test_re.py b/Lib/test/test_re.py index 8229d4a..11fff78 100644 --- a/Lib/test/test_re.py +++ b/Lib/test/test_re.py @@ -416,6 +416,7 @@ class ReTests(unittest.TestCase): 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, @@ -426,6 +427,19 @@ class ReTests(unittest.TestCase): self.assertEqual(pat.match(p) is not None, True) self.assertEqual(pat.match(p).span(), (0,256)) + def test_re_escape_byte(self): + p=b"" + self.assertEqual(re.escape(p), p) + for i in range(0, 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)) + + pat=re.compile(re.escape(p)) + self.assertEqual(pat.match(p) is not None, True) + self.assertEqual(pat.match(p).span(), (0,256)) + def pickle_test(self, pickle): oldpat = re.compile('a(?:b|(c|e){1,2}?|d)+?(.)') s = pickle.dumps(oldpat) |