[pypy-svn] r53524 - in pypy/dist/pypy: rpython/test translator/cli/src translator/cli/test

antocuni at codespeak.net antocuni at codespeak.net
Mon Apr 7 14:58:42 CEST 2008


Author: antocuni
Date: Mon Apr  7 14:58:41 2008
New Revision: 53524

Modified:
   pypy/dist/pypy/rpython/test/test_rfloat.py
   pypy/dist/pypy/translator/cli/src/pypylib.cs
   pypy/dist/pypy/translator/cli/test/runtest.py
   pypy/dist/pypy/translator/cli/test/test_float.py
Log:
fix test_float2str for cli



Modified: pypy/dist/pypy/rpython/test/test_rfloat.py
==============================================================================
--- pypy/dist/pypy/rpython/test/test_rfloat.py	(original)
+++ pypy/dist/pypy/rpython/test/test_rfloat.py	Mon Apr  7 14:58:41 2008
@@ -36,7 +36,11 @@
             print 'BINARY_OPERATIONS:', opname
 
 class BaseTestRfloat(BaseRtypingTest):
-    
+
+    inf = 'inf'
+    minus_inf = '-inf'
+    nan = 'nan'
+
     def test_float2str(self):
         def fn(f):
             return str(f)
@@ -48,11 +52,11 @@
         inf = 1e200 * 1e200
         nan = inf/inf
         res = self.interpret(fn, [inf])
-        assert self.ll_to_string(res) == 'inf'
+        assert self.ll_to_string(res) == self.inf
         res = self.interpret(fn, [-inf])
-        assert self.ll_to_string(res) == '-inf'
+        assert self.ll_to_string(res) == self.minus_inf
         res = self.interpret(fn, [nan])
-        assert self.ll_to_string(res) == 'nan'
+        assert self.ll_to_string(res) == self.nan
 
     def test_string_mod_float(self):
         def fn(f):

Modified: pypy/dist/pypy/translator/cli/src/pypylib.cs
==============================================================================
--- pypy/dist/pypy/translator/cli/src/pypylib.cs	(original)
+++ pypy/dist/pypy/translator/cli/src/pypylib.cs	Mon Apr  7 14:58:41 2008
@@ -68,6 +68,20 @@
         }
     }
 
+    public class Convert {
+        public static double ToDouble(string s)
+        {
+            if (s == "inf")
+                return Double.PositiveInfinity;
+            else if (s == "-inf")
+                return Double.NegativeInfinity;
+            else if (s == "nan")
+                return Double.NaN;
+            else
+                return System.Convert.ToDouble(s);
+        }
+    }
+
     public delegate int DelegateType_int__int_1(int a);
     public delegate int DelegateType_int__int_2(int a, int b);
     public delegate int DelegateType_int__int_3(int a, int b, int c);

Modified: pypy/dist/pypy/translator/cli/test/runtest.py
==============================================================================
--- pypy/dist/pypy/translator/cli/test/runtest.py	(original)
+++ pypy/dist/pypy/translator/cli/test/runtest.py	Mon Apr  7 14:58:41 2008
@@ -70,8 +70,7 @@
             ilasm.opcode('ldc.i4 %d' % i)
             ilasm.opcode('ldelem.ref')
             arg_type, arg_var = self.cts.llvar_to_cts(arg)
-            ilasm.call('%s class [mscorlib]System.Convert::%s(string)' %
-                       (arg_type, self.__convert_method(arg_type)))
+            self.__call_convert_method(ilasm, arg_type)
 
         # call the function and convert the result to a string containing a valid python expression
         ilasm.call(self.cts.graph_to_signature(self.graph))
@@ -118,6 +117,13 @@
         ilasm.end_function()
         self.db.pending_function(self.graph)
 
+    def __call_convert_method(self, ilasm, arg_type):
+        if arg_type == CTS.types.float64:
+            ilasm.call('float64 class [pypylib]pypy.test.Convert::ToDouble(string)')
+        else:
+            ilasm.call('%s class [mscorlib]System.Convert::%s(string)' %
+                       (arg_type, self.__convert_method(arg_type)))
+
     def __convert_method(self, arg_type):
         _conv = {
             CTS.types.int32: 'ToInt32',
@@ -125,7 +131,6 @@
             CTS.types.int64: 'ToInt64',
             CTS.types.uint64: 'ToUInt64',
             CTS.types.bool: 'ToBoolean',
-            CTS.types.float64: 'ToDouble',
             CTS.types.char: 'ToChar',
             }
 

Modified: pypy/dist/pypy/translator/cli/test/test_float.py
==============================================================================
--- pypy/dist/pypy/translator/cli/test/test_float.py	(original)
+++ pypy/dist/pypy/translator/cli/test/test_float.py	Mon Apr  7 14:58:41 2008
@@ -3,6 +3,11 @@
 from pypy.rpython.test.test_rfloat import BaseTestRfloat
 
 class TestCliFloat(CliTest, BaseTestRfloat):
+
+    inf = 'Infinity'
+    minus_inf = '-Infinity'
+    nan = 'NaN'
+
     def test_parse_float(self):
         ex = ['', '    ', '0', '1', '-1.5', '1.5E2', '2.5e-1', ' 0 ', '?']
         def fn(i):



More information about the Pypy-commit mailing list