cython
1# mode: run
2# ticket: t372
3
4cimport cython
5
6@cython.test_assert_path_exists("//ForFromStatNode")
7@cython.test_fail_if_path_exists("//ForInStatNode")
8def test_modify():
9"""
10>>> test_modify()
110
121
132
143
154
16<BLANKLINE>
17(4, 0)
18"""
19cdef int i, n = 5
20for i in range(n):
21print i
22n = 0
2324return i,n
25
26
27@cython.test_assert_path_exists("//ForFromStatNode")
28@cython.test_fail_if_path_exists("//ForInStatNode")
29def test_negindex():
30"""
31>>> test_negindex()
326
335
344
353
362
37(2, 0)
38"""
39cdef int i, n = 5
40for i in range(n+1, 1, -1):
41print i
42n = 0
43return i,n
44
45
46@cython.test_assert_path_exists("//ForFromStatNode",
47"//ForFromStatNode//PrintStatNode//CoerceToPyTypeNode")
48@cython.test_fail_if_path_exists("//ForInStatNode")
49def test_negindex_inferred():
50"""
51>>> test_negindex_inferred()
525
534
543
552
56(2, 0)
57"""
58cdef int n = 5
59for i in range(n, 1, -1):
60print i
61n = 0
62return i,n
63
64
65@cython.test_assert_path_exists("//ForFromStatNode")
66@cython.test_fail_if_path_exists("//ForInStatNode")
67def test_fix():
68"""
69>>> test_fix()
700
711
722
733
744
75<BLANKLINE>
764
77"""
78cdef int i
79for i in range(5):
80print i
8182return i
83
84
85@cython.test_assert_path_exists("//ForFromStatNode")
86@cython.test_fail_if_path_exists("//ForInStatNode")
87def test_break():
88"""
89>>> test_break()
900
911
922
93<BLANKLINE>
94(2, 0)
95"""
96cdef int i, n = 5
97for i in range(n):
98print i
99n = 0
100if i == 2:
101break
102else:
103print "FAILED!"
104105return i,n
106
107
108@cython.test_assert_path_exists("//ForFromStatNode")
109@cython.test_fail_if_path_exists("//ForInStatNode")
110def test_return():
111"""
112>>> test_return()
1130
1141
1152
116(2, 0)
117"""
118cdef int i, n = 5
119for i in range(n):
120print i
121n = 0
122if i == 2:
123return i,n
124125return "FAILED!"
126
127
128ctypedef enum RangeEnum:
129EnumValue1
130EnumValue2
131EnumValue3
132
133
134@cython.test_assert_path_exists("//ForFromStatNode")
135@cython.test_fail_if_path_exists("//ForInStatNode")
136def test_enum_range():
137"""
138# NOTE: it's not entirely clear that this is the expected behaviour, but that's how it currently is.
139>>> test_enum_range()
140'RangeEnum'
141"""
142cdef RangeEnum n = EnumValue3
143for i in range(n):
144assert 0 <= <int>i < <int>n
145assert cython.typeof(i) == "RangeEnum", cython.typeof(i)
146return cython.typeof(i)
147