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