summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_re.py
diff options
context:
space:
mode:
authorMa Lin <animalize@users.noreply.github.com>2022-04-19 14:49:36 (GMT)
committerGitHub <noreply@github.com>2022-04-19 14:49:36 (GMT)
commite4e8895ae36b44994e3f7b018345ba203ce6b55c (patch)
tree75dfc4577b68bc470c900256e157c189a2585464 /Lib/test/test_re.py
parent061a8bf77c80036bed3ef4973fe0c99705c83fc6 (diff)
downloadcpython-e4e8895ae36b44994e3f7b018345ba203ce6b55c.zip
cpython-e4e8895ae36b44994e3f7b018345ba203ce6b55c.tar.gz
cpython-e4e8895ae36b44994e3f7b018345ba203ce6b55c.tar.bz2
gh-91616: re module, fix .fullmatch() mismatch when using Atomic Grouping or Possessive Quantifiers (GH-91681)
These jumps should use DO_JUMP0() instead of DO_JUMP(): - JUMP_POSS_REPEAT_1 - JUMP_POSS_REPEAT_2 - JUMP_ATOMIC_GROUP
Diffstat (limited to 'Lib/test/test_re.py')
-rw-r--r--Lib/test/test_re.py20
1 files changed, 20 insertions, 0 deletions
diff --git a/Lib/test/test_re.py b/Lib/test/test_re.py
index 7bb8bfa..781bfd6 100644
--- a/Lib/test/test_re.py
+++ b/Lib/test/test_re.py
@@ -2242,6 +2242,10 @@ class ReTests(unittest.TestCase):
self.assertIsNone(re.fullmatch(r'a*+', 'ab'))
self.assertIsNone(re.fullmatch(r'a?+', 'ab'))
self.assertIsNone(re.fullmatch(r'a{1,3}+', 'ab'))
+ self.assertTrue(re.fullmatch(r'a++b', 'ab'))
+ self.assertTrue(re.fullmatch(r'a*+b', 'ab'))
+ self.assertTrue(re.fullmatch(r'a?+b', 'ab'))
+ self.assertTrue(re.fullmatch(r'a{1,3}+b', 'ab'))
self.assertTrue(re.fullmatch(r'(?:ab)++', 'ab'))
self.assertTrue(re.fullmatch(r'(?:ab)*+', 'ab'))
@@ -2251,6 +2255,10 @@ class ReTests(unittest.TestCase):
self.assertIsNone(re.fullmatch(r'(?:ab)*+', 'abc'))
self.assertIsNone(re.fullmatch(r'(?:ab)?+', 'abc'))
self.assertIsNone(re.fullmatch(r'(?:ab){1,3}+', 'abc'))
+ self.assertTrue(re.fullmatch(r'(?:ab)++c', 'abc'))
+ self.assertTrue(re.fullmatch(r'(?:ab)*+c', 'abc'))
+ self.assertTrue(re.fullmatch(r'(?:ab)?+c', 'abc'))
+ self.assertTrue(re.fullmatch(r'(?:ab){1,3}+c', 'abc'))
def test_findall_possessive_quantifiers(self):
self.assertEqual(re.findall(r'a++', 'aab'), ['aa'])
@@ -2286,6 +2294,10 @@ class ReTests(unittest.TestCase):
self.assertIsNone(re.fullmatch(r'(?>a*)', 'ab'))
self.assertIsNone(re.fullmatch(r'(?>a?)', 'ab'))
self.assertIsNone(re.fullmatch(r'(?>a{1,3})', 'ab'))
+ self.assertTrue(re.fullmatch(r'(?>a+)b', 'ab'))
+ self.assertTrue(re.fullmatch(r'(?>a*)b', 'ab'))
+ self.assertTrue(re.fullmatch(r'(?>a?)b', 'ab'))
+ self.assertTrue(re.fullmatch(r'(?>a{1,3})b', 'ab'))
self.assertTrue(re.fullmatch(r'(?>(?:ab)+)', 'ab'))
self.assertTrue(re.fullmatch(r'(?>(?:ab)*)', 'ab'))
@@ -2295,6 +2307,10 @@ class ReTests(unittest.TestCase):
self.assertIsNone(re.fullmatch(r'(?>(?:ab)*)', 'abc'))
self.assertIsNone(re.fullmatch(r'(?>(?:ab)?)', 'abc'))
self.assertIsNone(re.fullmatch(r'(?>(?:ab){1,3})', 'abc'))
+ self.assertTrue(re.fullmatch(r'(?>(?:ab)+)c', 'abc'))
+ self.assertTrue(re.fullmatch(r'(?>(?:ab)*)c', 'abc'))
+ self.assertTrue(re.fullmatch(r'(?>(?:ab)?)c', 'abc'))
+ self.assertTrue(re.fullmatch(r'(?>(?:ab){1,3})c', 'abc'))
def test_findall_atomic_grouping(self):
self.assertEqual(re.findall(r'(?>a+)', 'aab'), ['aa'])
@@ -2307,6 +2323,10 @@ class ReTests(unittest.TestCase):
self.assertEqual(re.findall(r'(?>(?:ab)?)', 'ababc'), ['ab', 'ab', '', ''])
self.assertEqual(re.findall(r'(?>(?:ab){1,3})', 'ababc'), ['abab'])
+ def test_bug_gh91616(self):
+ self.assertTrue(re.fullmatch(r'(?s:(?>.*?\.).*)\Z', "a.txt")) # reproducer
+ self.assertTrue(re.fullmatch(r'(?s:(?=(?P<g0>.*?\.))(?P=g0).*)\Z', "a.txt"))
+
def get_debug_out(pat):
with captured_stdout() as out: