diff options
author | Ezio Melotti <ezio.melotti@gmail.com> | 2012-02-29 09:40:00 (GMT) |
---|---|---|
committer | Ezio Melotti <ezio.melotti@gmail.com> | 2012-02-29 09:40:00 (GMT) |
commit | 38ae5b2392c425dd87c89820cf4672cde9de2271 (patch) | |
tree | c25da0ee70d75b6782261502484ff54cc3ece3f5 /Lib/test/test_re.py | |
parent | 0555cde98d37d3012fbed20a91f6afdacbf79523 (diff) | |
download | cpython-38ae5b2392c425dd87c89820cf4672cde9de2271.zip cpython-38ae5b2392c425dd87c89820cf4672cde9de2271.tar.gz cpython-38ae5b2392c425dd87c89820cf4672cde9de2271.tar.bz2 |
#10713: Improve documentation for \b and \B and add a few tests. Initial patch and tests by Martin Pool.
Diffstat (limited to 'Lib/test/test_re.py')
-rw-r--r-- | Lib/test/test_re.py | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/Lib/test/test_re.py b/Lib/test/test_re.py index 1f73967..b19834c 100644 --- a/Lib/test/test_re.py +++ b/Lib/test/test_re.py @@ -373,6 +373,32 @@ class ReTests(unittest.TestCase): self.assertEqual(re.search(r"\d\D\w\W\s\S", "1aa! a", re.UNICODE).group(0), "1aa! a") + def test_string_boundaries(self): + # See http://bugs.python.org/issue10713 + self.assertEqual(re.search(r"\b(abc)\b", "abc").group(1), + "abc") + # There's a word boundary at the start of a string. + self.assertTrue(re.match(r"\b", "abc")) + # A non-empty string includes a non-boundary zero-length match. + self.assertTrue(re.search(r"\B", "abc")) + # There is no non-boundary match at the start of a string. + self.assertFalse(re.match(r"\B", "abc")) + # However, an empty string contains no word boundaries, and also no + # non-boundaries. + self.assertEqual(re.search(r"\B", ""), None) + # This one is questionable and different from the perlre behaviour, + # but describes current behavior. + self.assertEqual(re.search(r"\b", ""), None) + # A single word-character string has two boundaries, but no + # non-boundary gaps. + self.assertEqual(len(re.findall(r"\b", "a")), 2) + self.assertEqual(len(re.findall(r"\B", "a")), 0) + # If there are no words, there are no boundaries + self.assertEqual(len(re.findall(r"\b", " ")), 0) + self.assertEqual(len(re.findall(r"\b", " ")), 0) + # Can match around the whitespace. + self.assertEqual(len(re.findall(r"\B", " ")), 2) + def test_bigcharset(self): self.assertEqual(re.match(u"([\u2222\u2223])", u"\u2222").group(1), u"\u2222") |