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

Method test_re_match

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

Source from the content-addressed store, hash-verified

506 [("a", ""),("b", "b"),("a", "")])
507
508 def test_re_match(self):
509 for string in 'a', S('a'):
510 self.assertEqual(re.match('a', string).groups(), ())
511 self.assertEqual(re.match('(a)', string).groups(), ('a',))
512 self.assertEqual(re.match('(a)', string).group(0), 'a')
513 self.assertEqual(re.match('(a)', string).group(1), 'a')
514 self.assertEqual(re.match('(a)', string).group(1, 1), ('a', 'a'))
515 for string in b'a', B(b'a'), bytearray(b'a'), memoryview(b'a'):
516 self.assertEqual(re.match(b'a', string).groups(), ())
517 self.assertEqual(re.match(b'(a)', string).groups(), (b'a',))
518 self.assertEqual(re.match(b'(a)', string).group(0), b'a')
519 self.assertEqual(re.match(b'(a)', string).group(1), b'a')
520 self.assertEqual(re.match(b'(a)', string).group(1, 1), (b'a', b'a'))
521 for a in ("\xe0", "\u0430", "\U0001d49c"):
522 self.assertEqual(re.match(a, a).groups(), ())
523 self.assertEqual(re.match('(%s)' % a, a).groups(), (a,))
524 self.assertEqual(re.match('(%s)' % a, a).group(0), a)
525 self.assertEqual(re.match('(%s)' % a, a).group(1), a)
526 self.assertEqual(re.match('(%s)' % a, a).group(1, 1), (a, a))
527
528 pat = re.compile('((a)|(b))(c)?')
529 self.assertEqual(pat.match('a').groups(), ('a', 'a', None, None))
530 self.assertEqual(pat.match('b').groups(), ('b', None, 'b', None))
531 self.assertEqual(pat.match('ac').groups(), ('a', 'a', None, 'c'))
532 self.assertEqual(pat.match('bc').groups(), ('b', None, 'b', 'c'))
533 self.assertEqual(pat.match('bc').groups(""), ('b', "", 'b', 'c'))
534
535 pat = re.compile('(?:(?P<a1>a)|(?P<b2>b))(?P<c3>c)?')
536 self.assertEqual(pat.match('a').group(1, 2, 3), ('a', None, None))
537 self.assertEqual(pat.match('b').group('a1', 'b2', 'c3'),
538 (None, 'b', None))
539 self.assertEqual(pat.match('ac').group(1, 'b2', 3), ('a', None, 'c'))
540
541 def test_group(self):
542 class Index:

Callers

nothing calls this directly

Calls 7

SClass · 0.70
BClass · 0.70
assertEqualMethod · 0.45
groupsMethod · 0.45
matchMethod · 0.45
groupMethod · 0.45
compileMethod · 0.45

Tested by

no test coverage detected