@@ -355,6 +355,32 @@ def test_special_escapes(self):
355
355
self .assertEqual (re .search (r"\d\D\w\W\s\S" ,
356
356
"1aa! a" , re .UNICODE ).group (0 ), "1aa! a" )
357
357
358
+ def test_string_boundaries (self ):
359
+ # See http://bugs.python.org/issue10713
360
+ self .assertEqual (re .search (r"\b(abc)\b" , "abc" ).group (1 ),
361
+ "abc" )
362
+ # There's a word boundary at the start of a string.
363
+ self .assertTrue (re .match (r"\b" , "abc" ))
364
+ # A non-empty string includes a non-boundary zero-length match.
365
+ self .assertTrue (re .search (r"\B" , "abc" ))
366
+ # There is no non-boundary match at the start of a string.
367
+ self .assertFalse (re .match (r"\B" , "abc" ))
368
+ # However, an empty string contains no word boundaries, and also no
369
+ # non-boundaries.
370
+ self .assertEqual (re .search (r"\B" , "" ), None )
371
+ # This one is questionable and different from the perlre behaviour,
372
+ # but describes current behavior.
373
+ self .assertEqual (re .search (r"\b" , "" ), None )
374
+ # A single word-character string has two boundaries, but no
375
+ # non-boundary gaps.
376
+ self .assertEqual (len (re .findall (r"\b" , "a" )), 2 )
377
+ self .assertEqual (len (re .findall (r"\B" , "a" )), 0 )
378
+ # If there are no words, there are no boundaries
379
+ self .assertEqual (len (re .findall (r"\b" , " " )), 0 )
380
+ self .assertEqual (len (re .findall (r"\b" , " " )), 0 )
381
+ # Can match around the whitespace.
382
+ self .assertEqual (len (re .findall (r"\B" , " " )), 2 )
383
+
358
384
def test_bigcharset (self ):
359
385
self .assertEqual (re .match ("([\u2222 \u2223 ])" ,
360
386
"\u2222 " ).group (1 ), "\u2222 " )
0 commit comments