@cython.test_fail_if_path_exists('//SwitchStatNode')
+@cython.test_assert_path_exists('//IfStatNode')
def switch_simple_py(x):
"""
>>> switch_simple_py(1)
@cython.test_fail_if_path_exists('//SwitchStatNode')
+@cython.test_assert_path_exists('//IfStatNode')
def switch_py(x):
"""
>>> switch_py(1)
@cython.test_assert_path_exists('//SwitchStatNode')
+@cython.test_fail_if_path_exists('//IfStatNode')
def switch_simple_c(int x):
"""
>>> switch_simple_c(1)
@cython.test_assert_path_exists('//SwitchStatNode')
+@cython.test_fail_if_path_exists('//IfStatNode')
def switch_c(int x):
"""
>>> switch_c(1)
@cython.test_assert_path_exists('//SwitchStatNode')
+@cython.test_fail_if_path_exists('//IfStatNode')
def switch_or(int x):
"""
>>> switch_or(0)
@cython.test_assert_path_exists('//SwitchStatNode')
+@cython.test_fail_if_path_exists('//IfStatNode')
def switch_in(int X):
"""
>>> switch_in(0)
@cython.test_assert_path_exists('//SwitchStatNode')
+@cython.test_fail_if_path_exists('//IfStatNode')
def switch_short(int x):
"""
>>> switch_short(0)
@cython.test_fail_if_path_exists('//SwitchStatNode')
+@cython.test_assert_path_exists('//IfStatNode')
def switch_off(int x):
"""
>>> switch_off(0)
return -1
+
@cython.test_assert_path_exists('//SwitchStatNode')
+@cython.test_fail_if_path_exists('//IfStatNode')
def switch_pass(int x):
"""
>>> switch_pass(1)
DEF t = (1,2,3,4,5,6)
@cython.test_assert_path_exists('//SwitchStatNode')
+@cython.test_fail_if_path_exists('//IfStatNode')
def compile_time_tuple_constant(int x):
"""
>>> compile_time_tuple_constant(1)
else:
return False
+
cdef enum X:
a = 1
b
f = 100
@cython.test_assert_path_exists('//SwitchStatNode')
+@cython.test_fail_if_path_exists('//IfStatNode')
def enum_switch(X x):
"""
>>> enum_switch(1)
return 1
else:
return 2
+
+
+@cython.test_assert_path_exists('//IfStatNode')
+@cython.test_assert_path_exists('//IfStatNode//SwitchStatNode')
+def enum_duplicates(X x):
+ """
+ >>> enum_duplicates(1)
+ 0
+ >>> enum_duplicates(2) # b
+ 0
+ >>> enum_duplicates(10)
+ 1
+ >>> enum_duplicates(100)
+ 3
+ """
+ if x in [a, b, c, d]: # switch is ok here!
+ return 0
+ elif x == e:
+ return 1
+ elif x == b: # duplicate => no switch here!
+ return 2
+ else:
+ return 3
+
+
+@cython.test_assert_path_exists('//SwitchStatNode')
+@cython.test_fail_if_path_exists('//IfStatNode')
+def int_enum_switch_mix(int x):
+ """
+ >>> int_enum_switch_mix(1)
+ 0
+ >>> int_enum_switch_mix(10)
+ 1
+ >>> int_enum_switch_mix(ord('X'))
+ 2
+ >>> int_enum_switch_mix(99)
+ 3
+ >>> int_enum_switch_mix(100)
+ 4
+ """
+ if x in [a, b, c, d]:
+ return 0
+ elif x == e:
+ return 1
+ elif x == 'X': # ASCII(88)
+ return 2
+ elif x == 99:
+ return 3
+ else:
+ return 4