Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(85528)

Unified Diff: Lib/test/test_re.py

Issue 12759: "(?P=)" input for Tools/scripts/redemo.py raises unnhandled exception
Patch Set: Created 7 years ago
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Lib/sre_parse.py ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
--- a/Lib/test/test_re.py Thu Nov 01 14:52:03 2012 +0200
+++ b/Lib/test/test_re.py Thu Nov 01 21:46:28 2012 +0200
@@ -161,11 +161,29 @@
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<)')
+ 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')
« no previous file with comments | « Lib/sre_parse.py ('k') | no next file » | no next file with comments »

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+