@@ -1682,11 +1682,6 @@ def test_scoped_flags(self):
1682
1682
self .assertIsNone (re .match (r'(?i:(?-i:a)b)' , 'Ab' ))
1683
1683
self .assertTrue (re .match (r'(?i:(?-i:a)b)' , 'aB' ))
1684
1684
1685
- self .assertTrue (re .match (r'(?x: a) b' , 'a b' ))
1686
- self .assertIsNone (re .match (r'(?x: a) b' , ' a b' ))
1687
- self .assertTrue (re .match (r'(?-x: a) b' , ' ab' , re .VERBOSE ))
1688
- self .assertIsNone (re .match (r'(?-x: a) b' , 'ab' , re .VERBOSE ))
1689
-
1690
1685
self .assertTrue (re .match (r'\w(?a:\W)\w' , '\xe0 \xe0 \xe0 ' ))
1691
1686
self .assertTrue (re .match (r'(?a:\W(?u:\w)\W)' , '\xe0 \xe0 \xe0 ' ))
1692
1687
self .assertTrue (re .match (r'\W(?u:\w)\W' , '\xe0 \xe0 \xe0 ' , re .ASCII ))
@@ -1712,6 +1707,33 @@ def test_scoped_flags(self):
1712
1707
self .checkPatternError (r'(?i+' , 'missing -, : or )' , 3 )
1713
1708
self .checkPatternError (r'(?iz' , 'unknown flag' , 3 )
1714
1709
1710
+ def test_ignore_spaces (self ):
1711
+ for space in " \t \n \r \v \f " :
1712
+ self .assertTrue (re .fullmatch (space + 'a' , 'a' , re .VERBOSE ))
1713
+ for space in b" " , b"\t " , b"\n " , b"\r " , b"\v " , b"\f " :
1714
+ self .assertTrue (re .fullmatch (space + b'a' , b'a' , re .VERBOSE ))
1715
+ self .assertTrue (re .fullmatch ('(?x) a' , 'a' ))
1716
+ self .assertTrue (re .fullmatch (' (?x) a' , 'a' , re .VERBOSE ))
1717
+ self .assertTrue (re .fullmatch ('(?x) (?x) a' , 'a' ))
1718
+ self .assertTrue (re .fullmatch (' a(?x: b) c' , ' ab c' ))
1719
+ self .assertTrue (re .fullmatch (' a(?-x: b) c' , 'a bc' , re .VERBOSE ))
1720
+ self .assertTrue (re .fullmatch ('(?x) a(?-x: b) c' , 'a bc' ))
1721
+ self .assertTrue (re .fullmatch ('(?x) a| b' , 'a' ))
1722
+ self .assertTrue (re .fullmatch ('(?x) a| b' , 'b' ))
1723
+
1724
+ def test_comments (self ):
1725
+ self .assertTrue (re .fullmatch ('#x\n a' , 'a' , re .VERBOSE ))
1726
+ self .assertTrue (re .fullmatch (b'#x\n a' , b'a' , re .VERBOSE ))
1727
+ self .assertTrue (re .fullmatch ('(?x)#x\n a' , 'a' ))
1728
+ self .assertTrue (re .fullmatch ('#x\n (?x)#y\n a' , 'a' , re .VERBOSE ))
1729
+ self .assertTrue (re .fullmatch ('(?x)#x\n (?x)#y\n a' , 'a' ))
1730
+ self .assertTrue (re .fullmatch ('#x\n a(?x:#y\n b)#z\n c' , '#x\n ab#z\n c' ))
1731
+ self .assertTrue (re .fullmatch ('#x\n a(?-x:#y\n b)#z\n c' , 'a#y\n bc' ,
1732
+ re .VERBOSE ))
1733
+ self .assertTrue (re .fullmatch ('(?x)#x\n a(?-x:#y\n b)#z\n c' , 'a#y\n bc' ))
1734
+ self .assertTrue (re .fullmatch ('(?x)#x\n a|#y\n b' , 'a' ))
1735
+ self .assertTrue (re .fullmatch ('(?x)#x\n a|#y\n b' , 'b' ))
1736
+
1715
1737
def test_bug_6509 (self ):
1716
1738
# Replacement strings of both types must parse properly.
1717
1739
# all strings
0 commit comments