MCPcopy Index your code
hub / github.com/RustPython/RustPython / test_symbolic_refs_errors

Method test_symbolic_refs_errors

Lib/test/test_re.py:343–378  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 3

checkTemplateErrorMethod · 0.95
assertRaisesRegexMethod · 0.80
subMethod · 0.45

Tested by

no test coverage detected