]> granicus.if.org Git - python/commitdiff
added finditer sanity check
authorFredrik Lundh <fredrik@pythonware.com>
Sun, 28 Oct 2001 20:15:40 +0000 (20:15 +0000)
committerFredrik Lundh <fredrik@pythonware.com>
Sun, 28 Oct 2001 20:15:40 +0000 (20:15 +0000)
Lib/sre.py
Lib/test/test_sre.py

index 88b4fabaaf31fd7712a134d29d8a2a4742b351d7..e8582b79280252e974943eee3db5a2eb0c7f4497 100644 (file)
@@ -167,9 +167,8 @@ def findall(pattern, string):
 
 if sys.hexversion >= 0x02020000:
     def finditer(pattern, string):
-        """Return an iterator over all non-overlapping matches in
-        the string.  For each match, the iterator returns a match
-        object.
+        """Return an iterator over all non-overlapping matches in the
+        string.  For each match, the iterator returns a match object.
 
         Empty matches are included in the result."""
         return _compile(pattern, 0).finditer(string)
index 75a168cb9c06413269807c955657c7a576d5d657..d1a6909f630681df82af88e22d6f6fb30218a52e 100644 (file)
@@ -184,6 +184,17 @@ test(r"""sre.findall(r"(a)|(b)", "abc")""", [("a", ""), ("", "b")])
 # bug 117612
 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:
     print "Running tests on sre.match"