1 2cimport cython 3 4DEF INT_VAL = 1 5 6def _not_constant_but_False(): 7 return False 8 9@cython.test_fail_if_path_exists("//PrimaryCmpNode", 10 "//IfStatNode") 11def int_bool_result(): 12 """ 13 >>> int_bool_result() 14 True 15 """ 16 if 5: 17 return True 18 else: 19 return False 20 21@cython.test_fail_if_path_exists("//IfStatNode") 22def constant_if_elif_else(): 23 """ 24 >>> constant_if_elif_else() 25 True 26 """ 27 if 0: 28 return False 29 elif 5: 30 return True 31 else: 32 return False 33 34@cython.test_fail_if_path_exists("//PrintStatNode") 35@cython.test_assert_path_exists("//IfStatNode", 36 "//IfClauseNode") 37def non_constant_if_elif_else1(): 38 """ 39 >>> non_constant_if_elif_else1() 40 True 41 """ 42 if _not_constant_but_False(): 43 return False 44 elif 5: 45 return True 46 else: 47 print(False) 48 49@cython.test_fail_if_path_exists("//PrintStatNode") 50@cython.test_assert_path_exists("//IfStatNode", 51 "//IfClauseNode") 52def non_constant_if_elif_else2(): 53 """ 54 >>> non_constant_if_elif_else2() 55 True 56 """ 57 if _not_constant_but_False(): 58 return False 59 elif 0: 60 print(False) 61 else: 62 return True 63 64@cython.test_fail_if_path_exists("//PrimaryCmpNode", 65 "//IfStatNode") 66def if_not_compare_true(): 67 """ 68 >>> if_not_compare_true() 69 False 70 """ 71 if not 0 == 0: 72 return True 73 else: 74 return False 75 76@cython.test_fail_if_path_exists("//PrimaryCmpNode", 77 "//IfStatNode") 78def if_compare_true(): 79 """ 80 >>> if_compare_true() 81 True 82 """ 83 if 0 == 0: 84 return True 85 else: 86 return False 87 88@cython.test_fail_if_path_exists("//PrimaryCmpNode", 89 "//IfStatNode") 90def if_compare_false(): 91 """ 92 >>> if_compare_false() 93 False 94 """ 95 if 0 == 1: 96 return True 97 else: 98 return False 99 100@cython.test_fail_if_path_exists("//PrimaryCmpNode", 101 "//IfStatNode") 102def if_compare_or_true(): 103 """ 104 >>> if_compare_or_true() 105 True 106 """ 107 if 0 == 1 or 1 == 1: 108 return True 109 else: 110 return False 111 112@cython.test_fail_if_path_exists("//PrimaryCmpNode", 113 "//IfStatNode") 114def if_compare_or_false(): 115 """ 116 >>> if_compare_or_false() 117 False 118 """ 119 if 0 == 1 or 1 == 0: 120 return True 121 else: 122 return False 123 124@cython.test_fail_if_path_exists("//PrimaryCmpNode", 125 "//IfStatNode") 126def if_compare_and_true(): 127 """ 128 >>> if_compare_and_true() 129 True 130 """ 131 if 0 == 0 and 1 == 1: 132 return True 133 else: 134 return False 135 136@cython.test_fail_if_path_exists("//PrimaryCmpNode", 137 "//IfStatNode") 138def if_compare_and_false(): 139 """ 140 >>> if_compare_and_false() 141 False 142 """ 143 if 1 == 1 and 1 == 0: 144 return True 145 else: 146 return False 147 148@cython.test_fail_if_path_exists("//PrimaryCmpNode", 149 "//IfStatNode") 150def if_compare_cascaded(): 151 """ 152 >>> if_compare_cascaded() 153 True 154 """ 155 if 0 < 1 < 2 < 3: 156 return True 157 else: 158 return False 159 160@cython.test_fail_if_path_exists("//CoerceToBooleanNode", 161 "//ListNode", 162 "//IfStatNode") 163def list_bool_result_true(): 164 """ 165 >>> list_bool_result_true() 166 True 167 """ 168 if [1,2,3]: 169 return True 170 else: 171 return False 172 173@cython.test_fail_if_path_exists("//CoerceToBooleanNode", 174 "//ListNode", 175 "//IfStatNode") 176def list_bool_result_false(): 177 """ 178 >>> list_bool_result_false() 179 False 180 """ 181 if []: 182 return True 183 else: 184 return False 185 186@cython.test_fail_if_path_exists("//PrimaryCmpNode", 187 "//IfStatNode") 188def compile_time_DEF_if(): 189 """ 190 >>> compile_time_DEF_if() 191 True 192 """ 193 if INT_VAL != 0: 194 return True 195 else: 196 return False 197