[pypy-svn] r59427 - in pypy/trunk/pypy/objspace/std: . test

fijal at codespeak.net fijal at codespeak.net
Sun Oct 26 21:55:47 CET 2008


Author: fijal
Date: Sun Oct 26 21:55:45 2008
New Revision: 59427

Modified:
   pypy/trunk/pypy/objspace/std/stringobject.py
   pypy/trunk/pypy/objspace/std/test/test_stringobject.py
Log:
A test and a fix. oddly enough, unicode is already correct. We should share more
code between those two


Modified: pypy/trunk/pypy/objspace/std/stringobject.py
==============================================================================
--- pypy/trunk/pypy/objspace/std/stringobject.py	(original)
+++ pypy/trunk/pypy/objspace/std/stringobject.py	Sun Oct 26 21:55:45 2008
@@ -585,7 +585,7 @@
 
     d = u_arg - len(u_self) 
     if d>0:
-        offset = d//2
+        offset = d//2 + (d & u_arg & 1)
         fillchar = fillchar[0]    # annotator hint: it's a single character
         u_centered = offset * fillchar + u_self + (d - offset) * fillchar
     else:

Modified: pypy/trunk/pypy/objspace/std/test/test_stringobject.py
==============================================================================
--- pypy/trunk/pypy/objspace/std/test/test_stringobject.py	(original)
+++ pypy/trunk/pypy/objspace/std/test/test_stringobject.py	Sun Oct 26 21:55:45 2008
@@ -301,7 +301,7 @@
         assert 'abc'.center(2) == 'abc'
         assert 'abc'.center(5, '*') == '*abc*'     # Python 2.4
         raises(TypeError, 'abc'.center, 4, 'cba')
-
+        assert ' abc'.center(7) == '   abc '
         
     def test_count(self):
         assert "".count("x") ==0



More information about the Pypy-commit mailing list