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

Method test_bug_34294

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

Source from the content-addressed store, hash-verified

2393 self.assertEqual(m2.group(), b'')
2394
2395 def test_bug_34294(self):
2396 # Issue 34294: wrong capturing groups
2397
2398 # exists since Python 2
2399 s = "a\tx"
2400 p = r"\b(?=(\t)|(x))x"
2401 self.assertEqual(re.search(p, s).groups(), (None, 'x'))
2402
2403 # introduced in Python 3.7.0
2404 s = "ab"
2405 p = r"(?=(.)(.)?)"
2406 self.assertEqual(re.findall(p, s),
2407 [('a', 'b'), ('b', '')])
2408 self.assertEqual([m.groups() for m in re.finditer(p, s)],
2409 [('a', 'b'), ('b', None)])
2410
2411 # test-cases provided by issue34294, introduced in Python 3.7.0
2412 p = r"(?=<(?P<tag>\w+)/?>(?:(?P<text>.+?)</(?P=tag)>)?)"
2413 s = "<test><foo2/></test>"
2414 self.assertEqual(re.findall(p, s),
2415 [('test', '<foo2/>'), ('foo2', '')])
2416 self.assertEqual([m.groupdict() for m in re.finditer(p, s)],
2417 [{'tag': 'test', 'text': '<foo2/>'},
2418 {'tag': 'foo2', 'text': None}])
2419 s = "<test>Hello</test><foo/>"
2420 self.assertEqual([m.groupdict() for m in re.finditer(p, s)],
2421 [{'tag': 'test', 'text': 'Hello'},
2422 {'tag': 'foo', 'text': None}])
2423 s = "<test>Hello</test><foo/><foo/>"
2424 self.assertEqual([m.groupdict() for m in re.finditer(p, s)],
2425 [{'tag': 'test', 'text': 'Hello'},
2426 {'tag': 'foo', 'text': None},
2427 {'tag': 'foo', 'text': None}])
2428
2429 def test_MARK_PUSH_macro_bug(self):
2430 # issue35859, MARK_PUSH() macro didn't protect MARK-0 if it

Callers

nothing calls this directly

Calls 4

assertEqualMethod · 0.45
groupsMethod · 0.45
searchMethod · 0.45
findallMethod · 0.45

Tested by

no test coverage detected