(self)
| 344 | self.assertEqual(re.sub(pat, r'\g<200>', 'xc8yzxc8y'), 'c8zc8') |
| 345 | |
| 346 | def test_symbolic_refs_errors(self): |
| 347 | self.checkTemplateError('(?P<a>x)', r'\g<a', 'xx', |
| 348 | 'missing >, unterminated name', 3) |
| 349 | self.checkTemplateError('(?P<a>x)', r'\g<', 'xx', |
| 350 | 'missing group name', 3) |
| 351 | self.checkTemplateError('(?P<a>x)', r'\g', 'xx', 'missing <', 2) |
| 352 | self.checkTemplateError('(?P<a>x)', r'\g<a a>', 'xx', |
| 353 | "bad character in group name 'a a'", 3) |
| 354 | self.checkTemplateError('(?P<a>x)', r'\g<>', 'xx', |
| 355 | 'missing group name', 3) |
| 356 | self.checkTemplateError('(?P<a>x)', r'\g<1a1>', 'xx', |
| 357 | "bad character in group name '1a1'", 3) |
| 358 | self.checkTemplateError('(?P<a>x)', r'\g<2>', 'xx', |
| 359 | 'invalid group reference 2', 3) |
| 360 | self.checkTemplateError('(?P<a>x)', r'\2', 'xx', |
| 361 | 'invalid group reference 2', 1) |
| 362 | with self.assertRaisesRegex(IndexError, "unknown group name 'ab'"): |
| 363 | re.sub('(?P<a>x)', r'\g<ab>', 'xx') |
| 364 | self.checkTemplateError('(?P<a>x)', r'\g<-1>', 'xx', |
| 365 | "bad character in group name '-1'", 3) |
| 366 | self.checkTemplateError('(?P<a>x)', r'\g<+1>', 'xx', |
| 367 | "bad character in group name '+1'", 3) |
| 368 | self.checkTemplateError('()'*10, r'\g<1_0>', 'xx', |
| 369 | "bad character in group name '1_0'", 3) |
| 370 | self.checkTemplateError('(?P<a>x)', r'\g< 1 >', 'xx', |
| 371 | "bad character in group name ' 1 '", 3) |
| 372 | self.checkTemplateError('(?P<a>x)', r'\g<©>', 'xx', |
| 373 | "bad character in group name '©'", 3) |
| 374 | self.checkTemplateError(b'(?P<a>x)', b'\\g<\xc2\xb5>', b'xx', |
| 375 | r"bad character in group name '\xc2\xb5'", 3) |
| 376 | self.checkTemplateError('(?P<a>x)', r'\g<㊀>', 'xx', |
| 377 | "bad character in group name '㊀'", 3) |
| 378 | self.checkTemplateError('(?P<a>x)', r'\g<¹>', 'xx', |
| 379 | "bad character in group name '¹'", 3) |
| 380 | self.checkTemplateError('(?P<a>x)', r'\g<१>', 'xx', |
| 381 | "bad character in group name '१'", 3) |
| 382 | |
| 383 | def test_re_subn(self): |
| 384 | self.assertEqual(re.subn("(?i)b+", "x", "bbbb BBBB"), ('x x', 2)) |
nothing calls this directly
no test coverage detected