@@ -331,21 +331,21 @@ def test_re_split(self):
331331 ['' , 'a' , '' , '' , 'c' ])
332332
333333 for sep , expected in [
334- (':*' , ['' , 'a' , 'b' , 'c' ]),
335- ('(?::*)' , ['' , 'a' , 'b' , 'c' ]),
336- ('(:*)' , ['' , ':' , 'a' , ':' , 'b' , '::' , 'c' ]),
337- ('(:)*' , ['' , ':' , 'a' , ':' , 'b' , ':' , 'c' ]),
334+ (':*' , ['' , 'a' , 'b' , 'c' , '' ]),
335+ ('(?::*)' , ['' , 'a' , 'b' , 'c' , '' ]),
336+ ('(:*)' , ['' , ':' , 'a' , ':' , 'b' , '::' , 'c' , '' , '' ]),
337+ ('(:)*' , ['' , ':' , 'a' , ':' , 'b' , ':' , 'c' , None , '' ]),
338338 ]:
339- with self .subTest (sep = sep ), self . assertWarns ( FutureWarning ) :
339+ with self .subTest (sep = sep ):
340340 self .assertTypedEqual (re .split (sep , ':a:b::c' ), expected )
341341
342342 for sep , expected in [
343- ('' , [':a:b::c ' ]),
344- (r'\b' , [':a:b::c ' ]),
345- (r'(?=:)' , [':a:b: :c' ]),
346- (r'(?<=:)' , [':a:b:: c' ]),
343+ ('' , ['' , ':' , 'a' , ':' , 'b' , ':' , ':' , 'c' , ' ' ]),
344+ (r'\b' , [':' , 'a' , ':' , 'b' , '::' , 'c' , ' ' ]),
345+ (r'(?=:)' , ['' , ':a' , ':b' , ':' , ' :c' ]),
346+ (r'(?<=:)' , [':' , 'a:' , 'b:' , ':' , ' c' ]),
347347 ]:
348- with self .subTest (sep = sep ), self . assertRaises ( ValueError ) :
348+ with self .subTest (sep = sep ):
349349 self .assertTypedEqual (re .split (sep , ':a:b::c' ), expected )
350350
351351 def test_qualified_re_split (self ):
@@ -356,9 +356,8 @@ def test_qualified_re_split(self):
356356 ['' , ':' , 'a' , ':' , 'b::c' ])
357357 self .assertEqual (re .split ("(:+)" , ":a:b::c" , maxsplit = 2 ),
358358 ['' , ':' , 'a' , ':' , 'b::c' ])
359- with self .assertWarns (FutureWarning ):
360- self .assertEqual (re .split ("(:*)" , ":a:b::c" , maxsplit = 2 ),
361- ['' , ':' , 'a' , ':' , 'b::c' ])
359+ self .assertEqual (re .split ("(:*)" , ":a:b::c" , maxsplit = 2 ),
360+ ['' , ':' , 'a' , ':' , 'b::c' ])
362361
363362 def test_re_findall (self ):
364363 self .assertEqual (re .findall (":+" , "abc" ), [])
@@ -1751,6 +1750,25 @@ def test_match_repr(self):
17511750 "span=(3, 5), match='bb'>" %
17521751 (type (second ).__module__ , type (second ).__qualname__ ))
17531752
1753+ def test_zerowidth (self ):
1754+ # Issues 852532, 1647489, 3262, 25054.
1755+ self .assertEqual (re .split (r"\b" , "a::bc" ), ['' , 'a' , '::' , 'bc' , '' ])
1756+ self .assertEqual (re .split (r"\b|:+" , "a::bc" ), ['' , 'a' , '' , 'bc' , '' ])
1757+ self .assertEqual (re .split (r"(?<!\w)(?=\w)|:+" , "a::bc" ), ['' , 'a' , 'bc' ])
1758+ self .assertEqual (re .split (r"(?<=\w)(?!\w)|:+" , "a::bc" ), ['a' , '' , 'bc' , '' ])
1759+
1760+ self .assertEqual (re .sub (r"\b" , "-" , "a::bc" ), '-a-::-bc-' )
1761+ self .assertEqual (re .sub (r"\b|:+" , "-" , "a::bc" ), '-a--bc-' )
1762+ self .assertEqual (re .sub (r"(\b|:+)" , r"[\1]" , "a::bc" ), '[]a[][::]bc[]' )
1763+
1764+ self .assertEqual (re .findall (r"\b|:+" , "a::bc" ), ['' , '' , '::' , '' , '' ])
1765+ self .assertEqual (re .findall (r"\b|\w+" , "a::bc" ),
1766+ ['' , 'a' , '' , '' , 'bc' , '' ])
1767+
1768+ self .assertEqual ([m .span () for m in re .finditer (r"\b|:+" , "a::bc" )],
1769+ [(0 , 0 ), (1 , 1 ), (1 , 3 ), (3 , 3 ), (5 , 5 )])
1770+ self .assertEqual ([m .span () for m in re .finditer (r"\b|\w+" , "a::bc" )],
1771+ [(0 , 0 ), (0 , 1 ), (1 , 1 ), (3 , 3 ), (3 , 5 ), (5 , 5 )])
17541772
17551773 def test_bug_2537 (self ):
17561774 # issue 2537: empty submatches
0 commit comments