summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_re.py
diff options
context:
space:
mode:
authorEzio Melotti <ezio.melotti@gmail.com>2012-11-03 18:33:38 (GMT)
committerEzio Melotti <ezio.melotti@gmail.com>2012-11-03 18:33:38 (GMT)
commit68600aff3a841c1d901758c0e4e3fb3aafc7354e (patch)
treed806de6795b875139e568664913709b24e11e4f1 /Lib/test/test_re.py
parentbefaac03bbf7bdc8e34f722072931c2e4a2408b5 (diff)
parent0941d9fc64e1429454282667d0ca47740c141943 (diff)
downloadcpython-68600aff3a841c1d901758c0e4e3fb3aafc7354e.zip
cpython-68600aff3a841c1d901758c0e4e3fb3aafc7354e.tar.gz
cpython-68600aff3a841c1d901758c0e4e3fb3aafc7354e.tar.bz2
#12759: merge with 3.2.
Diffstat (limited to 'Lib/test/test_re.py')
-rw-r--r--Lib/test/test_re.py20
1 files changed, 20 insertions, 0 deletions
diff --git a/Lib/test/test_re.py b/Lib/test/test_re.py
index 9b0aa75..e7acbe1 100644
--- a/Lib/test/test_re.py
+++ b/Lib/test/test_re.py
@@ -161,11 +161,31 @@ class ReTests(unittest.TestCase):
self.assertEqual(re.sub('x*', '-', 'abxd'), '-a-b-d-')
self.assertEqual(re.sub('x+', '-', 'abxd'), 'ab-d')
+ def test_symbolic_groups(self):
+ re.compile('(?P<a>x)(?P=a)(?(a)y)')
+ re.compile('(?P<a1>x)(?P=a1)(?(a1)y)')
+ self.assertRaises(re.error, re.compile, '(?P<a>)(?P<a>)')
+ self.assertRaises(re.error, re.compile, '(?Px)')
+ self.assertRaises(re.error, re.compile, '(?P=)')
+ self.assertRaises(re.error, re.compile, '(?P=1)')
+ self.assertRaises(re.error, re.compile, '(?P=a)')
+ self.assertRaises(re.error, re.compile, '(?P=a1)')
+ self.assertRaises(re.error, re.compile, '(?P=a.)')
+ self.assertRaises(re.error, re.compile, '(?P<)')
+ self.assertRaises(re.error, re.compile, '(?P<>)')
+ self.assertRaises(re.error, re.compile, '(?P<1>)')
+ self.assertRaises(re.error, re.compile, '(?P<a.>)')
+ self.assertRaises(re.error, re.compile, '(?())')
+ self.assertRaises(re.error, re.compile, '(?(a))')
+ self.assertRaises(re.error, re.compile, '(?(1a))')
+ self.assertRaises(re.error, re.compile, '(?(a.))')
+
def test_symbolic_refs(self):
self.assertRaises(re.error, re.sub, '(?P<a>x)', '\g<a', 'xx')
self.assertRaises(re.error, re.sub, '(?P<a>x)', '\g<', 'xx')
self.assertRaises(re.error, re.sub, '(?P<a>x)', '\g', 'xx')
self.assertRaises(re.error, re.sub, '(?P<a>x)', '\g<a a>', 'xx')
+ self.assertRaises(re.error, re.sub, '(?P<a>x)', '\g<>', 'xx')
self.assertRaises(re.error, re.sub, '(?P<a>x)', '\g<1a1>', 'xx')
self.assertRaises(IndexError, re.sub, '(?P<a>x)', '\g<ab>', 'xx')
self.assertRaises(re.error, re.sub, '(?P<a>x)|(?P<b>y)', '\g<b>', 'xx')