summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2022-04-23 10:16:36 (GMT)
committerGitHub <noreply@github.com>2022-04-23 10:16:36 (GMT)
commitc7e6bfd1500588e5cede4590d3a721d67f915867 (patch)
tree8f35fdd2b63282b557d9d934bc48f8c67ec5605c
parent0482ed7d072c9b4d55479e719d95d6e41df7b4aa (diff)
downloadcpython-c7e6bfd1500588e5cede4590d3a721d67f915867.zip
cpython-c7e6bfd1500588e5cede4590d3a721d67f915867.tar.gz
cpython-c7e6bfd1500588e5cede4590d3a721d67f915867.tar.bz2
RE: Add more tests for inline flag "x" and re.VERBOSE (GH-91854)
(cherry picked from commit 6b45076bd62407103433daea8acf085a99e6cb7e) Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
-rw-r--r--Lib/test/test_re.py32
1 files changed, 27 insertions, 5 deletions
diff --git a/Lib/test/test_re.py b/Lib/test/test_re.py
index 3d6623b..62bfc3a 100644
--- a/Lib/test/test_re.py
+++ b/Lib/test/test_re.py
@@ -1683,11 +1683,6 @@ class ReTests(unittest.TestCase):
self.assertIsNone(re.match(r'(?i:(?-i:a)b)', 'Ab'))
self.assertTrue(re.match(r'(?i:(?-i:a)b)', 'aB'))
- self.assertTrue(re.match(r'(?x: a) b', 'a b'))
- self.assertIsNone(re.match(r'(?x: a) b', ' a b'))
- self.assertTrue(re.match(r'(?-x: a) b', ' ab', re.VERBOSE))
- self.assertIsNone(re.match(r'(?-x: a) b', 'ab', re.VERBOSE))
-
self.assertTrue(re.match(r'\w(?a:\W)\w', '\xe0\xe0\xe0'))
self.assertTrue(re.match(r'(?a:\W(?u:\w)\W)', '\xe0\xe0\xe0'))
self.assertTrue(re.match(r'\W(?u:\w)\W', '\xe0\xe0\xe0', re.ASCII))
@@ -1713,6 +1708,33 @@ class ReTests(unittest.TestCase):
self.checkPatternError(r'(?i+', 'missing -, : or )', 3)
self.checkPatternError(r'(?iz', 'unknown flag', 3)
+ def test_ignore_spaces(self):
+ for space in " \t\n\r\v\f":
+ self.assertTrue(re.fullmatch(space + 'a', 'a', re.VERBOSE))
+ for space in b" ", b"\t", b"\n", b"\r", b"\v", b"\f":
+ self.assertTrue(re.fullmatch(space + b'a', b'a', re.VERBOSE))
+ self.assertTrue(re.fullmatch('(?x) a', 'a'))
+ self.assertTrue(re.fullmatch(' (?x) a', 'a', re.VERBOSE))
+ self.assertTrue(re.fullmatch('(?x) (?x) a', 'a'))
+ self.assertTrue(re.fullmatch(' a(?x: b) c', ' ab c'))
+ self.assertTrue(re.fullmatch(' a(?-x: b) c', 'a bc', re.VERBOSE))
+ self.assertTrue(re.fullmatch('(?x) a(?-x: b) c', 'a bc'))
+ self.assertTrue(re.fullmatch('(?x) a| b', 'a'))
+ self.assertTrue(re.fullmatch('(?x) a| b', 'b'))
+
+ def test_comments(self):
+ self.assertTrue(re.fullmatch('#x\na', 'a', re.VERBOSE))
+ self.assertTrue(re.fullmatch(b'#x\na', b'a', re.VERBOSE))
+ self.assertTrue(re.fullmatch('(?x)#x\na', 'a'))
+ self.assertTrue(re.fullmatch('#x\n(?x)#y\na', 'a', re.VERBOSE))
+ self.assertTrue(re.fullmatch('(?x)#x\n(?x)#y\na', 'a'))
+ self.assertTrue(re.fullmatch('#x\na(?x:#y\nb)#z\nc', '#x\nab#z\nc'))
+ self.assertTrue(re.fullmatch('#x\na(?-x:#y\nb)#z\nc', 'a#y\nbc',
+ re.VERBOSE))
+ self.assertTrue(re.fullmatch('(?x)#x\na(?-x:#y\nb)#z\nc', 'a#y\nbc'))
+ self.assertTrue(re.fullmatch('(?x)#x\na|#y\nb', 'a'))
+ self.assertTrue(re.fullmatch('(?x)#x\na|#y\nb', 'b'))
+
def test_bug_6509(self):
# Replacement strings of both types must parse properly.
# all strings