add constant folding tests for bool values
authorStefan Behnel <stefan_ml@behnel.de>
Sat, 23 Feb 2013 10:36:26 +0000 (11:36 +0100)
committerStefan Behnel <stefan_ml@behnel.de>
Sat, 23 Feb 2013 10:36:26 +0000 (11:36 +0100)
tests/run/constant_folding.py

index f3ca3bc..7845a52 100644 (file)
@@ -11,14 +11,16 @@ import cython
 def unop_floats():
     """
     >>> unop_floats()
-    (1.0, -1.0, 1.0, -1.0, -1.0)
+    (False, 2.0, -2.0, False, 2.0, -2.0, -2.0)
     """
-    plus1  = + 1.0
-    minus1 = - 1.0
-    plus3  = +++ 1.0
-    minus3 = --- 1.0
-    mix    = +-++-- 1.0
-    return plus1, minus1, plus3, minus3, mix
+    not1   = not 2.0
+    plus1  = + 2.0
+    minus1 = - 2.0
+    not3   = not not not 2.0
+    plus3  = +++ 2.0
+    minus3 = --- 2.0
+    mix    = +-++-- 2.0
+    return not1, plus1, minus1, not3, plus3, minus3, mix
 
 
 @cython.test_fail_if_path_exists(
@@ -28,11 +30,33 @@ def unop_floats():
 def unop_ints():
     """
     >>> unop_ints()
-    (1, -1, 1, -1, -1)
+    (False, 2, -2, False, 2, -2, -2)
     """
-    plus1  = + 1
-    minus1 = - 1
-    plus3  = +++ 1
-    minus3 = --- 1
-    mix    = +-++-- 1
-    return plus1, minus1, plus3, minus3, mix
+    not1   = not 2
+    plus1  = + 2
+    minus1 = - 2
+    not3   = not not not 2
+    plus3  = +++ 2
+    minus3 = --- 2
+    mix    = +-++-- 2
+    return not1, plus1, minus1, not3, plus3, minus3, mix
+
+
+@cython.test_fail_if_path_exists(
+    "//UnaryMinusNode",
+    "//UnaryPlusNode",
+    "//NotNode",
+)
+def unop_bool():
+    """
+    >>> unop_bool()
+    (False, 1, -1, False, 1, -1, -1)
+    """
+    not1   = not True
+    plus1  = + True
+    minus1 = - True
+    not3   = not not not True
+    plus3  = +++ True
+    minus3 = --- True
+    mix    = +-++-- True
+    return not1, plus1, minus1, not3, plus3, minus3, mix