Author: Armin Rigo <[email protected]>
Branch: 
Changeset: r78624:530d71942802
Date: 2015-07-21 13:27 +0200
http://bitbucket.org/pypy/pypy/changeset/530d71942802/

Log:    More tests, one fix for cast_primitive(Bool, r_longlong())

diff --git a/rpython/rtyper/rbuiltin.py b/rpython/rtyper/rbuiltin.py
--- a/rpython/rtyper/rbuiltin.py
+++ b/rpython/rtyper/rbuiltin.py
@@ -480,7 +480,8 @@
     }
 _cast_from_Signed = {
     lltype.Signed:         None,
-    lltype.Bool:           'int_is_true',
+    #lltype.Bool:           'int_is_true', ---disabled, see test_cast_to_bool_1
+    #                                      in translator/c/test/test_lltyped.py
     lltype.Char:           'cast_int_to_char',
     lltype.UniChar:        'cast_int_to_unichar',
     lltype.Float:          'cast_int_to_float',
diff --git a/rpython/translator/c/test/test_lltyped.py 
b/rpython/translator/c/test/test_lltyped.py
--- a/rpython/translator/c/test/test_lltyped.py
+++ b/rpython/translator/c/test/test_lltyped.py
@@ -982,7 +982,27 @@
         assert fn(10) == 42
         assert fn(100) == -10
 
-    def test_cast_to_bool(self):
+    def test_cast_to_bool_1(self):
+        def f(n):
+            return cast_primitive(Bool, n)
+
+        fn = self.getcompiled(f, [int])
+        assert fn(0) == False
+        assert fn(1) == True
+        assert fn(256) == True
+        assert fn(-2**24) == True
+
+    def test_cast_to_bool_1_longlong(self):
+        def f(n):
+            return cast_primitive(Bool, n)
+
+        fn = self.getcompiled(f, [r_longlong])
+        assert fn(r_longlong(0)) == False
+        assert fn(r_longlong(1)) == True
+        assert fn(r_longlong(256)) == True
+        assert fn(r_longlong(2**32)) == True
+
+    def test_cast_to_bool_2(self):
         def f(n):
             return rffi.cast(Bool, n)
 
@@ -991,3 +1011,13 @@
         assert fn(1) == True
         assert fn(256) == True
         assert fn(-2**24) == True
+
+    def test_cast_to_bool_2_longlong(self):
+        def f(n):
+            return rffi.cast(Bool, n)
+
+        fn = self.getcompiled(f, [r_longlong])
+        assert fn(r_longlong(0)) == False
+        assert fn(r_longlong(1)) == True
+        assert fn(r_longlong(256)) == True
+        assert fn(r_longlong(2**32)) == True
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to