diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2013-10-20 10:13:31 (GMT) |
---|---|---|
committer | Serhiy Storchaka <storchaka@gmail.com> | 2013-10-20 10:13:31 (GMT) |
commit | 36af10c1f7e50b257e97854aca594ec988d85c65 (patch) | |
tree | 98a269bfdbdb50090d9e09ee0fb80020b8690ea1 /Lib/test/test_re.py | |
parent | d5fd8df22f4c94714e9fd93db80c3cc3995c44e3 (diff) | |
download | cpython-36af10c1f7e50b257e97854aca594ec988d85c65.zip cpython-36af10c1f7e50b257e97854aca594ec988d85c65.tar.gz cpython-36af10c1f7e50b257e97854aca594ec988d85c65.tar.bz2 |
Issue #17087: Improved the repr for regular expression match objects.
Diffstat (limited to 'Lib/test/test_re.py')
-rw-r--r-- | Lib/test/test_re.py | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/Lib/test/test_re.py b/Lib/test/test_re.py index 20b1a14..841d3a3 100644 --- a/Lib/test/test_re.py +++ b/Lib/test/test_re.py @@ -1104,6 +1104,28 @@ class ReTests(unittest.TestCase): self.assertEqual(re.compile(pattern, re.S).findall(b'xyz'), [b'xyz'], msg=pattern) + def test_match_repr(self): + for string in '[abracadabra]', S('[abracadabra]'): + m = re.search(r'(.+)(.*?)\1', string) + self.assertEqual(repr(m), "<%s.%s object; " + "span=(1, 12), match='abracadabra'>" % + (type(m).__module__, type(m).__qualname__)) + for string in (b'[abracadabra]', B(b'[abracadabra]'), + bytearray(b'[abracadabra]'), + memoryview(b'[abracadabra]')): + m = re.search(rb'(.+)(.*?)\1', string) + self.assertEqual(repr(m), "<%s.%s object; " + "span=(1, 12), match=b'abracadabra'>" % + (type(m).__module__, type(m).__qualname__)) + + first, second = list(re.finditer("(aa)|(bb)", "aa bb")) + self.assertEqual(repr(first), "<%s.%s object; " + "span=(0, 2), match='aa'>" % + (type(second).__module__, type(first).__qualname__)) + self.assertEqual(repr(second), "<%s.%s object; " + "span=(3, 5), match='bb'>" % + (type(second).__module__, type(second).__qualname__)) + def test_bug_2537(self): # issue 2537: empty submatches |