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

Side by Side Diff: Lib/test/test_re.py

Issue 12759: "(?P=)" input for Tools/scripts/redemo.py raises unnhandled exception
Patch Set: Created 8 years ago
Left:
Right:
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 unified diff | Download patch
« no previous file with comments | « Lib/sre_parse.py ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 from test.support import verbose, run_unittest 1 from test.support import verbose, run_unittest
2 import re 2 import re
3 from re import Scanner 3 from re import Scanner
4 import sys 4 import sys
5 import string 5 import string
6 import traceback 6 import traceback
7 from weakref import proxy 7 from weakref import proxy
8 8
9 # Misc tests from Tim Peters' re.doc 9 # Misc tests from Tim Peters' re.doc
10 10
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
147 def test_bug_462270(self): 147 def test_bug_462270(self):
148 # Test for empty sub() behaviour, see SF bug #462270 148 # Test for empty sub() behaviour, see SF bug #462270
149 self.assertEqual(re.sub('x*', '-', 'abxd'), '-a-b-d-') 149 self.assertEqual(re.sub('x*', '-', 'abxd'), '-a-b-d-')
150 self.assertEqual(re.sub('x+', '-', 'abxd'), 'ab-d') 150 self.assertEqual(re.sub('x+', '-', 'abxd'), 'ab-d')
151 151
152 def test_symbolic_refs(self): 152 def test_symbolic_refs(self):
153 self.assertRaises(re.error, re.sub, '(?P<a>x)', '\g<a', 'xx') 153 self.assertRaises(re.error, re.sub, '(?P<a>x)', '\g<a', 'xx')
154 self.assertRaises(re.error, re.sub, '(?P<a>x)', '\g<', 'xx') 154 self.assertRaises(re.error, re.sub, '(?P<a>x)', '\g<', 'xx')
155 self.assertRaises(re.error, re.sub, '(?P<a>x)', '\g', 'xx') 155 self.assertRaises(re.error, re.sub, '(?P<a>x)', '\g', 'xx')
156 self.assertRaises(re.error, re.sub, '(?P<a>x)', '\g<a a>', 'xx') 156 self.assertRaises(re.error, re.sub, '(?P<a>x)', '\g<a a>', 'xx')
157 self.assertRaises(re.error, re.sub, '(?P=)' , '\g', 'xx')
158 self.assertRaises(re.error, re.sub, '(?P<>)' , '\g', 'xx')
157 self.assertRaises(re.error, re.sub, '(?P<a>x)', '\g<1a1>', 'xx') 159 self.assertRaises(re.error, re.sub, '(?P<a>x)', '\g<1a1>', 'xx')
158 self.assertRaises(IndexError, re.sub, '(?P<a>x)', '\g<ab>', 'xx') 160 self.assertRaises(IndexError, re.sub, '(?P<a>x)', '\g<ab>', 'xx')
159 self.assertRaises(re.error, re.sub, '(?P<a>x)|(?P<b>y)', '\g<b>', 'xx') 161 self.assertRaises(re.error, re.sub, '(?P<a>x)|(?P<b>y)', '\g<b>', 'xx')
160 self.assertRaises(re.error, re.sub, '(?P<a>x)|(?P<b>y)', '\\2', 'xx') 162 self.assertRaises(re.error, re.sub, '(?P<a>x)|(?P<b>y)', '\\2', 'xx')
161 self.assertRaises(re.error, re.sub, '(?P<a>x)', '\g<-1>', 'xx') 163 self.assertRaises(re.error, re.sub, '(?P<a>x)', '\g<-1>', 'xx')
162 164
163 def test_re_subn(self): 165 def test_re_subn(self):
164 self.assertEqual(re.subn("(?i)b+", "x", "bbbb BBBB"), ('x x', 2)) 166 self.assertEqual(re.subn("(?i)b+", "x", "bbbb BBBB"), ('x x', 2))
165 self.assertEqual(re.subn("b+", "x", "bbbb BBBB"), ('x BBBB', 1)) 167 self.assertEqual(re.subn("b+", "x", "bbbb BBBB"), ('x BBBB', 1))
166 self.assertEqual(re.subn("b+", "x", "xyz"), ('xyz', 0)) 168 self.assertEqual(re.subn("b+", "x", "xyz"), ('xyz', 0))
(...skipping 747 matching lines...) Expand 10 before | Expand all | Expand 10 after
914 if result is None: 916 if result is None:
915 print('=== Fails on unicode-sensitive match', t) 917 print('=== Fails on unicode-sensitive match', t)
916 918
917 919
918 def test_main(): 920 def test_main():
919 run_unittest(ReTests) 921 run_unittest(ReTests)
920 run_re_tests() 922 run_re_tests()
921 923
922 if __name__ == "__main__": 924 if __name__ == "__main__":
923 test_main() 925 test_main()
OLDNEW
« 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+