summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_re.py
diff options
context:
space:
mode:
authorGeorg Brandl <georg@python.org>2013-10-13 07:18:45 (GMT)
committerGeorg Brandl <georg@python.org>2013-10-13 07:18:45 (GMT)
commit4300019e1a6b20f6e2e780a36d96d795c9e71a6f (patch)
treed198489f28f652705acb40993adb686cd1ce917f /Lib/test/test_re.py
parent57841ddb5cc347884ff91c619007c43bf6a18a6b (diff)
downloadcpython-4300019e1a6b20f6e2e780a36d96d795c9e71a6f.zip
cpython-4300019e1a6b20f6e2e780a36d96d795c9e71a6f.tar.gz
cpython-4300019e1a6b20f6e2e780a36d96d795c9e71a6f.tar.bz2
Add re.fullmatch() function and regex.fullmatch() method, which anchor the
pattern at both ends of the string to match. Patch by Matthew Barnett. Closes #16203.
Diffstat (limited to 'Lib/test/test_re.py')
-rw-r--r--Lib/test/test_re.py24
1 files changed, 24 insertions, 0 deletions
diff --git a/Lib/test/test_re.py b/Lib/test/test_re.py
index 2104437..ea57d1f 100644
--- a/Lib/test/test_re.py
+++ b/Lib/test/test_re.py
@@ -1061,6 +1061,30 @@ class ReTests(unittest.TestCase):
self.assertEqual(m.group(1), "")
self.assertEqual(m.group(2), "y")
+ def test_fullmatch(self):
+ # Issue 16203: Proposal: add re.fullmatch() method.
+ self.assertEqual(re.fullmatch(r"a", "a").span(), (0, 1))
+ self.assertEqual(re.fullmatch(r"a|ab", "ab").span(), (0, 2))
+ self.assertEqual(re.fullmatch(r".*?$", "abc").span(), (0, 3))
+ self.assertEqual(re.fullmatch(r".*?", "abc").span(), (0, 3))
+ self.assertEqual(re.fullmatch(r"a.*?b", "ab").span(), (0, 2))
+ self.assertEqual(re.fullmatch(r"a.*?b", "abb").span(), (0, 3))
+ self.assertEqual(re.fullmatch(r"a.*?b", "axxb").span(), (0, 4))
+ self.assertEqual(re.fullmatch(r"abc$", "abc\n"), None)
+ self.assertEqual(re.fullmatch(r"abc\Z", "abc\n"), None)
+ self.assertEqual(re.fullmatch(r"(?m)abc$", "abc\n"), None)
+ self.assertEqual(re.fullmatch(r"ab(?=c)cd", "abcd").span(), (0, 4))
+ self.assertEqual(re.fullmatch(r"ab(?<=b)cd", "abcd").span(), (0, 4))
+ self.assertEqual(re.fullmatch(r"(?=a|ab)ab", "ab").span(), (0, 2))
+
+ self.assertEqual(
+ re.compile(r"bc").fullmatch("abcd", pos=1, endpos=3).span(), (1, 3))
+ self.assertEqual(
+ re.compile(r".*?$").fullmatch("abcd", pos=1, endpos=3).span(), (1, 3))
+ self.assertEqual(
+ re.compile(r".*?").fullmatch("abcd", pos=1, endpos=3).span(), (1, 3))
+
+
def run_re_tests():
from test.re_tests import tests, SUCCEED, FAIL, SYNTAX_ERROR
if verbose: