summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_re.py
diff options
context:
space:
mode:
authorGeorg Brandl <georg@python.org>2013-04-14 09:40:00 (GMT)
committerGeorg Brandl <georg@python.org>2013-04-14 09:40:00 (GMT)
commit1d472b74cb21388c78e5e56c19f50b3140370863 (patch)
tree07f4d90c71d9704f6fccdb5efba460b329d8eba6 /Lib/test/test_re.py
parent991fc5736e73c9c197cbaf758127c1057d16bacd (diff)
downloadcpython-1d472b74cb21388c78e5e56c19f50b3140370863.zip
cpython-1d472b74cb21388c78e5e56c19f50b3140370863.tar.gz
cpython-1d472b74cb21388c78e5e56c19f50b3140370863.tar.bz2
Closes #14462: allow any valid Python identifier in sre group names, as documented.
Diffstat (limited to 'Lib/test/test_re.py')
-rw-r--r--Lib/test/test_re.py8
1 files changed, 8 insertions, 0 deletions
diff --git a/Lib/test/test_re.py b/Lib/test/test_re.py
index ef19164..e90c770 100644
--- a/Lib/test/test_re.py
+++ b/Lib/test/test_re.py
@@ -180,6 +180,10 @@ class ReTests(unittest.TestCase):
self.assertRaises(re.error, re.compile, '(?(a))')
self.assertRaises(re.error, re.compile, '(?(1a))')
self.assertRaises(re.error, re.compile, '(?(a.))')
+ # New valid/invalid identifiers in Python 3
+ re.compile('(?P<ยต>x)(?P=ยต)(?(ยต)y)')
+ re.compile('(?P<๐”˜๐”ซ๐”ฆ๐” ๐”ฌ๐”ก๐”ข>x)(?P=๐”˜๐”ซ๐”ฆ๐” ๐”ฌ๐”ก๐”ข)(?(๐”˜๐”ซ๐”ฆ๐” ๐”ฌ๐”ก๐”ข)y)')
+ self.assertRaises(re.error, re.compile, '(?P<ยฉ>x)')
def test_symbolic_refs(self):
self.assertRaises(re.error, re.sub, '(?P<a>x)', '\g<a', 'xx')
@@ -192,6 +196,10 @@ class ReTests(unittest.TestCase):
self.assertRaises(re.error, re.sub, '(?P<a>x)|(?P<b>y)', '\g<b>', 'xx')
self.assertRaises(re.error, re.sub, '(?P<a>x)|(?P<b>y)', '\\2', 'xx')
self.assertRaises(re.error, re.sub, '(?P<a>x)', '\g<-1>', 'xx')
+ # New valid/invalid identifiers in Python 3
+ self.assertEqual(re.sub('(?P<ยต>x)', r'\g<ยต>', 'xx'), 'xx')
+ self.assertEqual(re.sub('(?P<๐”˜๐”ซ๐”ฆ๐” ๐”ฌ๐”ก๐”ข>x)', r'\g<๐”˜๐”ซ๐”ฆ๐” ๐”ฌ๐”ก๐”ข>', 'xx'), 'xx')
+ self.assertRaises(re.error, re.sub, '(?P<a>x)', r'\g<ยฉ>', 'xx')
def test_re_subn(self):
self.assertEqual(re.subn("(?i)b+", "x", "bbbb BBBB"), ('x x', 2))