From fbb490fd2f38bd817d99c20c05121ad0168a38ee Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Thu, 4 Jan 2018 11:06:13 +0200 Subject: bpo-32308: Replace empty matches adjacent to a previous non-empty match in re.sub(). (#4846) --- Lib/test/test_re.py | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-) (limited to 'Lib/test') diff --git a/Lib/test/test_re.py b/Lib/test/test_re.py index aaed3d893a..9fed4bef88 100644 --- a/Lib/test/test_re.py +++ b/Lib/test/test_re.py @@ -213,11 +213,6 @@ class ReTests(unittest.TestCase): self.assertEqual(re.sub(r'(\S)\s+(\S)', r'\1 \2', 'hello there'), 'hello there') - def test_bug_462270(self): - # Test for empty sub() behaviour, see SF bug #462270 - self.assertEqual(re.sub('x*', '-', 'abxd'), '-a-b-d-') - self.assertEqual(re.sub('x+', '-', 'abxd'), 'ab-d') - def test_symbolic_groups(self): re.compile(r'(?Px)(?P=a)(?(a)y)') re.compile(r'(?Px)(?P=a1)(?(a1)y)') @@ -331,10 +326,10 @@ class ReTests(unittest.TestCase): ['', 'a', '', '', 'c']) for sep, expected in [ - (':*', ['', 'a', 'b', 'c', '']), - ('(?::*)', ['', 'a', 'b', 'c', '']), - ('(:*)', ['', ':', 'a', ':', 'b', '::', 'c', '', '']), - ('(:)*', ['', ':', 'a', ':', 'b', ':', 'c', None, '']), + (':*', ['', '', 'a', '', 'b', '', 'c', '']), + ('(?::*)', ['', '', 'a', '', 'b', '', 'c', '']), + ('(:*)', ['', ':', '', '', 'a', ':', '', '', 'b', '::', '', '', 'c', '', '']), + ('(:)*', ['', ':', '', None, 'a', ':', '', None, 'b', ':', '', None, 'c', None, '']), ]: with self.subTest(sep=sep): self.assertTypedEqual(re.split(sep, ':a:b::c'), expected) @@ -357,7 +352,7 @@ class ReTests(unittest.TestCase): self.assertEqual(re.split("(:+)", ":a:b::c", maxsplit=2), ['', ':', 'a', ':', 'b::c']) self.assertEqual(re.split("(:*)", ":a:b::c", maxsplit=2), - ['', ':', 'a', ':', 'b::c']) + ['', ':', '', '', 'a:b::c']) def test_re_findall(self): self.assertEqual(re.findall(":+", "abc"), []) @@ -1753,13 +1748,13 @@ class ReTests(unittest.TestCase): def test_zerowidth(self): # Issues 852532, 1647489, 3262, 25054. self.assertEqual(re.split(r"\b", "a::bc"), ['', 'a', '::', 'bc', '']) - self.assertEqual(re.split(r"\b|:+", "a::bc"), ['', 'a', '', 'bc', '']) - self.assertEqual(re.split(r"(?