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

Delta Between Two Patch Sets: Lib/test/test_re.py

Issue 12759: "(?P=)" input for Tools/scripts/redemo.py raises unnhandled exception
Left Patch Set: Created 8 years ago
Right Patch Set: Created 7 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:
Right: Side by side diff | Download
« no previous file with change/comment | « Lib/sre_parse.py ('k') | no next file » | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
(no file at all)
1 from test.support import verbose, run_unittest, gc_collect 1 from test.support import verbose, run_unittest, gc_collect
2 import io 2 import io
3 import re 3 import re
4 from re import Scanner 4 from re import Scanner
5 import sys 5 import sys
6 import string 6 import string
7 import traceback 7 import traceback
8 from weakref import proxy 8 from weakref import proxy
9 9
10 # Misc tests from Tim Peters' re.doc 10 # Misc tests from Tim Peters' re.doc
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
154 154
155 def test_bug_114660(self): 155 def test_bug_114660(self):
156 self.assertEqual(re.sub(r'(\S)\s+(\S)', r'\1 \2', 'hello there'), 156 self.assertEqual(re.sub(r'(\S)\s+(\S)', r'\1 \2', 'hello there'),
157 'hello there') 157 'hello there')
158 158
159 def test_bug_462270(self): 159 def test_bug_462270(self):
160 # Test for empty sub() behaviour, see SF bug #462270 160 # Test for empty sub() behaviour, see SF bug #462270
161 self.assertEqual(re.sub('x*', '-', 'abxd'), '-a-b-d-') 161 self.assertEqual(re.sub('x*', '-', 'abxd'), '-a-b-d-')
162 self.assertEqual(re.sub('x+', '-', 'abxd'), 'ab-d') 162 self.assertEqual(re.sub('x+', '-', 'abxd'), 'ab-d')
163 163
164 def test_symbolic_groups(self):
165 re.compile('(?P<a>x)(?P=a)(?(a)y)')
166 re.compile('(?P<a1>x)(?P=a1)(?(a1)y)')
167 self.assertRaises(re.error, re.compile, '(?P<a>)(?P<a>)')
168 self.assertRaises(re.error, re.compile, '(?Px)')
169 self.assertRaises(re.error, re.compile, '(?P=)')
170 self.assertRaises(re.error, re.compile, '(?P=1)')
171 self.assertRaises(re.error, re.compile, '(?P=a.)')
172 self.assertRaises(re.error, re.compile, '(?P<)')
173 self.assertRaises(re.error, re.compile, '(?P<>)')
174 self.assertRaises(re.error, re.compile, '(?P<1>)')
175 self.assertRaises(re.error, re.compile, '(?P<a.>)')
176 self.assertRaises(re.error, re.compile, '(?())')
177 self.assertRaises(re.error, re.compile, '(?(a))')
178 self.assertRaises(re.error, re.compile, '(?(1a))')
179 self.assertRaises(re.error, re.compile, '(?(a.))')
180
164 def test_symbolic_refs(self): 181 def test_symbolic_refs(self):
165 self.assertRaises(re.error, re.sub, '(?P<a>x)', '\g<a', 'xx') 182 self.assertRaises(re.error, re.sub, '(?P<a>x)', '\g<a', 'xx')
166 self.assertRaises(re.error, re.sub, '(?P<a>x)', '\g<', 'xx') 183 self.assertRaises(re.error, re.sub, '(?P<a>x)', '\g<', 'xx')
167 self.assertRaises(re.error, re.sub, '(?P<a>x)', '\g', 'xx') 184 self.assertRaises(re.error, re.sub, '(?P<a>x)', '\g', 'xx')
168 self.assertRaises(re.error, re.sub, '(?P<a>x)', '\g<a a>', 'xx') 185 self.assertRaises(re.error, re.sub, '(?P<a>x)', '\g<a a>', 'xx')
186 self.assertRaises(re.error, re.sub, '(?P<a>x)', '\g<>', 'xx')
169 self.assertRaises(re.error, re.sub, '(?P<a>x)', '\g<1a1>', 'xx') 187 self.assertRaises(re.error, re.sub, '(?P<a>x)', '\g<1a1>', 'xx')
170 self.assertRaises(IndexError, re.sub, '(?P<a>x)', '\g<ab>', 'xx') 188 self.assertRaises(IndexError, re.sub, '(?P<a>x)', '\g<ab>', 'xx')
171 self.assertRaises(re.error, re.sub, '(?P<a>x)|(?P<b>y)', '\g<b>', 'xx') 189 self.assertRaises(re.error, re.sub, '(?P<a>x)|(?P<b>y)', '\g<b>', 'xx')
172 self.assertRaises(re.error, re.sub, '(?P<a>x)|(?P<b>y)', '\\2', 'xx') 190 self.assertRaises(re.error, re.sub, '(?P<a>x)|(?P<b>y)', '\\2', 'xx')
173 self.assertRaises(re.error, re.sub, '(?P<a>x)', '\g<-1>', 'xx') 191 self.assertRaises(re.error, re.sub, '(?P<a>x)', '\g<-1>', 'xx')
174 192
175 def test_re_subn(self): 193 def test_re_subn(self):
176 self.assertEqual(re.subn("(?i)b+", "x", "bbbb BBBB"), ('x x', 2)) 194 self.assertEqual(re.subn("(?i)b+", "x", "bbbb BBBB"), ('x x', 2))
177 self.assertEqual(re.subn("b+", "x", "bbbb BBBB"), ('x BBBB', 1)) 195 self.assertEqual(re.subn("b+", "x", "bbbb BBBB"), ('x BBBB', 1))
178 self.assertEqual(re.subn("b+", "x", "xyz"), ('xyz', 0)) 196 self.assertEqual(re.subn("b+", "x", "xyz"), ('xyz', 0))
(...skipping 871 matching lines...) Expand 10 before | Expand all | Expand 10 after
1050 if result is None: 1068 if result is None:
1051 print('=== Fails on unicode-sensitive match', t) 1069 print('=== Fails on unicode-sensitive match', t)
1052 1070
1053 1071
1054 def test_main(): 1072 def test_main():
1055 run_unittest(ReTests) 1073 run_unittest(ReTests)
1056 run_re_tests() 1074 run_re_tests()
1057 1075
1058 if __name__ == "__main__": 1076 if __name__ == "__main__":
1059 test_main() 1077 test_main()
LEFTRIGHT

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