mirror of
https://github.com/python/cpython.git
synced 2025-08-30 21:48:47 +00:00
added finditer sanity check
This commit is contained in:
parent
ca6dfa55c5
commit
b7747e2a2d
2 changed files with 13 additions and 3 deletions
|
@ -167,9 +167,8 @@ def findall(pattern, string):
|
||||||
|
|
||||||
if sys.hexversion >= 0x02020000:
|
if sys.hexversion >= 0x02020000:
|
||||||
def finditer(pattern, string):
|
def finditer(pattern, string):
|
||||||
"""Return an iterator over all non-overlapping matches in
|
"""Return an iterator over all non-overlapping matches in the
|
||||||
the string. For each match, the iterator returns a match
|
string. For each match, the iterator returns a match object.
|
||||||
object.
|
|
||||||
|
|
||||||
Empty matches are included in the result."""
|
Empty matches are included in the result."""
|
||||||
return _compile(pattern, 0).finditer(string)
|
return _compile(pattern, 0).finditer(string)
|
||||||
|
|
|
@ -184,6 +184,17 @@ test(r"""sre.findall(r"(a)|(b)", "abc")""", [("a", ""), ("", "b")])
|
||||||
# bug 117612
|
# bug 117612
|
||||||
test(r"""sre.findall(r"(a|(b))", "aba")""", [("a", ""),("b", "b"),("a", "")])
|
test(r"""sre.findall(r"(a|(b))", "aba")""", [("a", ""),("b", "b"),("a", "")])
|
||||||
|
|
||||||
|
if sys.hexversion >= 0x02020000:
|
||||||
|
if verbose:
|
||||||
|
print "Running tests on sre.finditer"
|
||||||
|
def fixup(seq):
|
||||||
|
# convert iterator to list
|
||||||
|
if not hasattr(seq, "next") or not hasattr(seq, "__iter__"):
|
||||||
|
print "finditer returned", type(seq)
|
||||||
|
return map(lambda item: item.group(0), seq)
|
||||||
|
# sanity
|
||||||
|
test(r"""fixup(sre.finditer(r":+", "a:b::c:::d"))""", [":", "::", ":::"])
|
||||||
|
|
||||||
if verbose:
|
if verbose:
|
||||||
print "Running tests on sre.match"
|
print "Running tests on sre.match"
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue