8000 RE: Add more tests for inline flag "x" and re.VERBOSE (GH-91854) · python/cpython@4165702 · GitHub
[go: up one dir, main page]

Skip to content

Commit 4165702

Browse files
RE: Add more tests for inline flag "x" and re.VERBOSE (GH-91854)
(cherry picked from commit 6b45076) Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
1 parent 42a158b commit 4165702

File tree

1 file changed

+27
-5
lines changed

1 file changed

+27
-5
lines changed

Lib/test/test_re.py

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1682,11 +1682,6 @@ def test_scoped_flags(self):
16821682
self.assertIsNone(re.match(r'(?i:(?-i:a)b)', 'Ab'))
16831683
self.assertTrue(re.match(r'(?i:(?-i:a)b)', 'aB'))
16841684

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-
16901685
self.assertTrue(re.match(r'\w(?a:\W)\w', '\xe0\xe0\xe0'))
16911686
self.assertTrue(re.match(r'(?a:\W(?u:\w)\W)', '\xe0\xe0\xe0'))
16921687
self.assertTrue(re.match(r'\W(?u:\w)\W', '\xe0\xe0\xe0', re.ASCII))
@@ -1712,6 +1707,33 @@ def test_scoped_flags(self):
17121707
self.checkPatternError(r'(?i+', 'missing -, : or )', 3)
17131708
self.checkPatternError(r'(?iz', 'unknown flag', 3)
17141709

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\na', 'a', re.VERBOSE))
1726+
self.assertTrue(re.fullmatch(b'#x\na', b'a', re.VERBOSE))
1727+
self.assertTrue(re.fullmatch('(?x)#x\na', 'a'))
1728+
self.assertTrue(re.fullmatch('#x\n(?x)#y\na', 'a', re.VERBOSE))
1729+
self.assertTrue(re.fullmatch('(?x)#x\n(?x)#y\na', 'a'))
1730+
self.assertTrue(re.fullmatch('#x\na(?x:#y\nb)#z\nc', '#x\nab#z\nc'))
1731+
self.assertTrue(re.fullmatch('#x\na(?-x:#y\nb)#z\nc', 'a#y\nbc',
1732+
re.VERBOSE))
1733+
self.assertTrue(re.fullmatch('(?x)#x\na(?-x:#y\nb)#z\nc', 'a#y\nbc'))
1734+
self.assertTrue(re.fullmatch('(?x)#x\na|#y\nb', 'a'))
1735+
self.assertTrue(re.fullmatch('(?x)#x\na|#y\nb', 'b'))
1736+
17151737
def test_bug_6509(self):
17161738
# Replacement strings of both types must parse properly.
17171739
# all strings

0 commit comments

Comments
 (0)
0