summaryrefslogtreecommitdiffstats
path: root/Lib/test
diff options
context:
space:
mode:
authorEzio Melotti <ezio.melotti@gmail.com>2011-03-25 12:09:33 (GMT)
committerEzio Melotti <ezio.melotti@gmail.com>2011-03-25 12:09:33 (GMT)
commit7b9e97b48765780ec71db330022bc68ba73a4b19 (patch)
treeb5971d90a4c208f84a796c34e3d5f2e214a27729 /Lib/test
parentd2114ebd970ec2b9b704dfd6b665b3b2940209b7 (diff)
downloadcpython-7b9e97b48765780ec71db330022bc68ba73a4b19.zip
cpython-7b9e97b48765780ec71db330022bc68ba73a4b19.tar.gz
cpython-7b9e97b48765780ec71db330022bc68ba73a4b19.tar.bz2
#2650: Add tests with non-ascii chars for re.escape.
Diffstat (limited to 'Lib/test')
-rw-r--r--Lib/test/test_re.py16
1 files changed, 16 insertions, 0 deletions
diff --git a/Lib/test/test_re.py b/Lib/test/test_re.py
index 86eda54..5ad44dd 100644
--- a/Lib/test/test_re.py
+++ b/Lib/test/test_re.py
@@ -455,6 +455,22 @@ class ReTests(unittest.TestCase):
self.assertMatch(re.escape(b), b)
self.assertMatch(re.escape(p), p)
+ def test_re_escape_non_ascii(self):
+ s = 'xxx\u2620\u2620\u2620xxx'
+ s_escaped = re.escape(s)
+ self.assertEqual(s_escaped, 'xxx\\\u2620\\\u2620\\\u2620xxx')
+ self.assertMatch(s_escaped, s)
+ self.assertMatch('.%s+.' % re.escape('\u2620'), s,
+ 'x\u2620\u2620\u2620x', (2, 7), re.search)
+
+ def test_re_escape_non_ascii_bytes(self):
+ b = 'y\u2620y\u2620y'.encode('utf-8')
+ b_escaped = re.escape(b)
+ self.assertEqual(b_escaped, b'y\\\xe2\\\x98\\\xa0y\\\xe2\\\x98\\\xa0y')
+ self.assertMatch(b_escaped, b)
+ res = re.findall(re.escape('\u2620'.encode('utf-8')), b)
+ self.assertEqual(len(res), 2)
+
def pickle_test(self, pickle):
oldpat = re.compile('a(?:b|(c|e){1,2}?|d)+?(.)')
s = pickle.dumps(oldpat)