summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2018-01-04 09:06:13 (GMT)
committerGitHub <noreply@github.com>2018-01-04 09:06:13 (GMT)
commitfbb490fd2f38bd817d99c20c05121ad0168a38ee (patch)
tree417d39bc824e6e62503f94033dbd2b37a8b5545b /Lib
parent0cc99c8cd70d422e4b345837a907db30e9180ab9 (diff)
downloadcpython-fbb490fd2f38bd817d99c20c05121ad0168a38ee.zip
cpython-fbb490fd2f38bd817d99c20c05121ad0168a38ee.tar.gz
cpython-fbb490fd2f38bd817d99c20c05121ad0168a38ee.tar.bz2
bpo-32308: Replace empty matches adjacent to a previous non-empty match in re.sub(). (#4846)
Diffstat (limited to 'Lib')
-rw-r--r--Lib/test/test_re.py23
1 files changed, 9 insertions, 14 deletions
diff --git a/Lib/test/test_re.py b/Lib/test/test_re.py
index aaed3d8..9fed4be 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'(?P<a>x)(?P=a)(?(a)y)')
re.compile(r'(?P<a1>x)(?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"(?<!\w)(?=\w)|:+", "a::bc"), ['', 'a', 'bc'])
+ self.assertEqual(re.split(r"\b|:+", "a::bc"), ['', 'a', '', '', 'bc', ''])
+ self.assertEqual(re.split(r"(?<!\w)(?=\w)|:+", "a::bc"), ['', 'a', '', 'bc'])
self.assertEqual(re.split(r"(?<=\w)(?!\w)|:+", "a::bc"), ['a', '', 'bc', ''])
self.assertEqual(re.sub(r"\b", "-", "a::bc"), '-a-::-bc-')
- self.assertEqual(re.sub(r"\b|:+", "-", "a::bc"), '-a--bc-')
- self.assertEqual(re.sub(r"(\b|:+)", r"[\1]", "a::bc"), '[]a[][::]bc[]')
+ self.assertEqual(re.sub(r"\b|:+", "-", "a::bc"), '-a---bc-')
+ self.assertEqual(re.sub(r"(\b|:+)", r"[\1]", "a::bc"), '[]a[][::][]bc[]')
self.assertEqual(re.findall(r"\b|:+", "a::bc"), ['', '', '::', '', ''])
self.assertEqual(re.findall(r"\b|\w+", "a::bc"),