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