[pypy-svn] r10017 - in pypy/dist/pypy/objspace/std: . test

jriehl at codespeak.net jriehl at codespeak.net
Mon Mar 21 21:11:06 CET 2005


Author: jriehl
Date: Mon Mar 21 21:11:06 2005
New Revision: 10017

Modified:
   pypy/dist/pypy/objspace/std/stringobject.py
   pypy/dist/pypy/objspace/std/test/test_stringobject.py
Log:
Fixed bug in splitlines() implementation for string objects.


Modified: pypy/dist/pypy/objspace/std/stringobject.py
==============================================================================
--- pypy/dist/pypy/objspace/std/stringobject.py	(original)
+++ pypy/dist/pypy/objspace/std/stringobject.py	Mon Mar 21 21:11:06 2005
@@ -721,7 +721,10 @@
                 w_item = _strip(space, w_item, W_StringObject(space,'\n'), left=0, right=1)
             L.append(w_item)
         else:
-            break    
+            if oldpos < selflen:
+                w_item = space.wrap(u_self[oldpos:])
+                L.append(w_item)
+            break
     return W_ListObject(space, L)
 
 def str_zfill__String_ANY(space, w_self, w_width):

Modified: pypy/dist/pypy/objspace/std/test/test_stringobject.py
==============================================================================
--- pypy/dist/pypy/objspace/std/test/test_stringobject.py	(original)
+++ pypy/dist/pypy/objspace/std/test/test_stringobject.py	Mon Mar 21 21:11:06 2005
@@ -317,6 +317,16 @@
 
 
     def test_splitlines(self):
+        s = ""
+        assert s.splitlines() == []
+        assert s.splitlines() == s.splitlines(1)
+        s = "a + 4"
+        assert s.splitlines() == ['a + 4']
+        # The following is true if no newline in string.
+        assert s.splitlines() == s.splitlines(1)
+        s = "a + 4\nb + 2"
+        assert s.splitlines() == ['a + 4', 'b + 2']
+        assert s.splitlines(1) == ['a + 4\n', 'b + 2']
         s="ab\nab\n \n  x\n\n\n"
         assert s.splitlines() ==['ab',    'ab',  ' ',   '  x',   '',    '']
         assert s.splitlines() ==s.splitlines(0)



More information about the Pypy-commit mailing list