MCPcopy Index your code
hub / github.com/python/cpython / test_re_match

Method test_re_match

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

Source from the content-addressed store, hash-verified

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