[pypy-svn] r14805 - in pypy/dist/pypy/rpython: . test

ac at codespeak.net ac at codespeak.net
Wed Jul 20 12:43:09 CEST 2005


Author: ac
Date: Wed Jul 20 12:43:09 2005
New Revision: 14805

Modified:
   pypy/dist/pypy/rpython/rstr.py
   pypy/dist/pypy/rpython/test/test_rstr.py
Log:
Implement %o formatcode.

Modified: pypy/dist/pypy/rpython/rstr.py
==============================================================================
--- pypy/dist/pypy/rpython/rstr.py	(original)
+++ pypy/dist/pypy/rpython/rstr.py	Wed Jul 20 12:43:09 2005
@@ -264,7 +264,7 @@
             if curstr:
                 r.append(curstr)
             curstr = ''
-            if f not in 'xdsrf':
+            if f not in 'xdosrf':
                 raise TyperError("Unsupported formatting specifier: %r in %r" % (f, fmt))
 
             r.append((f,))
@@ -309,6 +309,10 @@
                 assert isinstance(r_arg, IntegerRepr)
                 vchunk = hop.gendirectcall(rint.ll_int2hex, vitem,
                                            inputconst(Bool, False))
+            elif code == 'o':
+                assert isinstance(r_arg, IntegerRepr)
+                vchunk = hop.gendirectcall(rint.ll_int2oct, vitem,
+                                           inputconst(Bool, False))
             else:
                 assert 0
         else:

Modified: pypy/dist/pypy/rpython/test/test_rstr.py
==============================================================================
--- pypy/dist/pypy/rpython/test/test_rstr.py	(original)
+++ pypy/dist/pypy/rpython/test/test_rstr.py	Wed Jul 20 12:43:09 2005
@@ -245,17 +245,26 @@
 
     def percentX(i):
         return "bing %x bang" % (i,)
-    
+
     res = interpret(percentX, [23])
     assert ''.join(res.chars) == 'bing 17 bang'
 
     res = interpret(percentX, [-123])
     assert ''.join(res.chars) == 'bing -7b bang'
 
-    def moreThanOne(s, d, x):
-        return "string: %s decimal: %d hex: %x" % (s, d, x)
+    def percentO(i):
+        return "bing %o bang" % (i,)
+    
+    res = interpret(percentO, [23])
+    assert ''.join(res.chars) == 'bing 27 bang'
+
+    res = interpret(percentO, [-123])
+    assert ''.join(res.chars) == 'bing -173 bang'
+
+    def moreThanOne(s, d, x, o):
+        return "string: %s decimal: %d hex: %x oct: %o" % (s, d, x, o)
 
-    args = 'a', 2, 3
+    args = 'a', 2, 3, 4
     res = interpret(moreThanOne, list(args))
     assert ''.join(res.chars) == moreThanOne(*args)
 



More information about the Pypy-commit mailing list