5
def test_literal_list():
7
>>> test_literal_list()
12
return (a[0], a[1], a[2], a[3], a[4])
14
def test_literal_list_multiplied():
16
>>> test_literal_list_multiplied()
21
return (a[0], a[1], a[2], a[3], a[4], a[5])
23
def test_literal_list_slice_all():
25
>>> test_literal_list_slice_all()
28
cdef int a[5] # = [5,4,3,2,1]
30
return (a[0], a[1], a[2], a[3], a[4])
32
def test_literal_list_slice_start():
34
>>> test_literal_list_slice_start()
37
cdef int a[7] # = [7,6,5,4,3,2,1]
39
return (a[2], a[3], a[4], a[5], a[6])
41
def test_literal_list_slice_end():
43
>>> test_literal_list_slice_end()
46
cdef int a[7] # = [7,6,5,4,3,2,1]
48
return (a[0], a[1], a[2], a[3], a[4])
50
def test_literal_list_slice_start_end():
52
>>> test_literal_list_slice_start_end()
55
cdef int a[9] # = [9,8,7,6,5,4,3,2,1]
57
return (a[2], a[3], a[4], a[5], a[6])
59
def test_literal_list_slice_start_param(s):
61
>>> test_literal_list_slice_start_param(4)
63
>>> test_literal_list_slice_start_param(3)
64
Traceback (most recent call last):
65
ValueError: Assignment to slice of wrong length, expected 5, got 6
66
>>> test_literal_list_slice_start_param(5)
67
Traceback (most recent call last):
68
ValueError: Assignment to slice of wrong length, expected 5, got 4
70
cdef int a[9] # = [9,8,7,6,5,4,3,2,1]
72
return (a[4], a[5], a[6], a[7], a[8])
75
def test_literal_list_slice_end_param(e):
77
>>> test_literal_list_slice_end_param(5)
79
>>> test_literal_list_slice_end_param(4)
80
Traceback (most recent call last):
81
ValueError: Assignment to slice of wrong length, expected 5, got 4
82
>>> test_literal_list_slice_end_param(6)
83
Traceback (most recent call last):
84
ValueError: Assignment to slice of wrong length, expected 5, got 6
86
cdef int a[9] # = [9,8,7,6,5,4,3,2,1]
88
return (a[0], a[1], a[2], a[3], a[4])
91
def test_literal_list_slice_start_end_param(s,e):
93
>>> test_literal_list_slice_start_end_param(2,7)
95
>>> test_literal_list_slice_start_end_param(3,7)
96
Traceback (most recent call last):
97
ValueError: Assignment to slice of wrong length, expected 5, got 4
98
>>> test_literal_list_slice_start_end_param(1,7)
99
Traceback (most recent call last):
100
ValueError: Assignment to slice of wrong length, expected 5, got 6
101
>>> test_literal_list_slice_start_end_param(2,6)
102
Traceback (most recent call last):
103
ValueError: Assignment to slice of wrong length, expected 5, got 4
104
>>> test_literal_list_slice_start_end_param(2,8)
105
Traceback (most recent call last):
106
ValueError: Assignment to slice of wrong length, expected 5, got 6
107
>>> test_literal_list_slice_start_end_param(3,6)
108
Traceback (most recent call last):
109
ValueError: Assignment to slice of wrong length, expected 5, got 3
110
>>> test_literal_list_slice_start_end_param(1,8)
111
Traceback (most recent call last):
112
ValueError: Assignment to slice of wrong length, expected 5, got 7
114
cdef int a[9] # = [9,8,7,6,5,4,3,2,1]
116
return (a[2], a[3], a[4], a[5], a[6])
119
def test_ptr_literal_list_slice_all():
121
>>> test_ptr_literal_list_slice_all()
124
cdef int *a = [6,5,4,3,2]
126
return (a[0], a[1], a[2], a[3], a[4])
128
def test_ptr_literal_list_slice_start():
130
>>> test_ptr_literal_list_slice_start()
133
cdef int *a = [6,5,4,3,2,1]
135
return (a[1], a[2], a[3], a[4], a[5])
137
def test_ptr_literal_list_slice_end():
139
>>> test_ptr_literal_list_slice_end()
142
cdef int *a = [6,5,4,3,2,1]
144
return (a[0], a[1], a[2], a[3], a[4])
147
@cython.test_assert_path_exists(
148
'//ReturnStatNode//CoerceToPyTypeNode'
150
def test_starred_from_array():
152
>>> test_starred_from_array()
165
@cython.test_fail_if_path_exists(
166
'//ParallelAssignmentNode//CoerceToPyTypeNode',
167
'//ParallelAssignmentNode//CoerceFromPyTypeNode',
169
@cython.test_assert_path_exists(
170
'//ParallelAssignmentNode',
171
'//ReturnStatNode//CoerceToPyTypeNode'
173
def test_multiple_from_array():
175
>>> test_multiple_from_array()
186
@cython.test_fail_if_path_exists(
187
'//ParallelAssignmentNode//CoerceToPyTypeNode'
189
@cython.test_assert_path_exists(
190
'//ParallelAssignmentNode',
191
'//ReturnStatNode//CoerceToPyTypeNode'
193
def test_multiple_from_array_full_slice():
195
>>> test_multiple_from_array_full_slice()
206
@cython.test_fail_if_path_exists(
207
'//ParallelAssignmentNode//CoerceToPyTypeNode'
209
@cython.test_assert_path_exists(
210
'//ParallelAssignmentNode',
211
'//ReturnStatNode//CoerceToPyTypeNode'
213
def test_multiple_from_slice():
215
>>> test_multiple_from_slice()
218
cdef int *a = [6,5,4,3,2,1]
223
def test_slice_from_multiple():
225
>>> test_slice_from_multiple()
226
(6, -1, -2, -3, 2, 1)
228
cdef int *a = [6,5,4,3,2,1]
230
return a[0], a[1], a[2], a[3], a[4], a[5]
232
def test_literal_tuple():
234
>>> test_literal_tuple()
239
return (a[0], a[1], a[2], a[3], a[4])
241
def test_list(list l):
243
>>> test_list([1, 2, 3, 4, 5])
248
return (a[0], a[1], a[2], a[3], a[4])
251
def assign_all_from_pointer():
253
>>> assign_all_from_pointer()
256
cdef int *v = [1, 2, 3, 4, 5]
259
return (a[0], a[1], a[2], a[3], a[4])
262
def assign_full_from_pointer():
264
>>> assign_full_from_pointer()
267
cdef int *v = [1, 2, 3, 4, 5]
270
return (a[0], a[1], a[2], a[3], a[4])
273
def assign_slice_end_from_pointer():
275
>>> assign_slice_end_from_pointer()
278
cdef int *v = [1, 2, 3, 4, 5]
282
return (a[0], a[1], a[2], a[3], a[4])
285
def assign_slice_start_from_pointer():
287
>>> assign_slice_start_from_pointer()
290
cdef int *v = [1, 2, 3, 4, 5]
295
return (a[0], a[1], a[2], a[3], a[4])
298
def assign_slice_start_end_from_pointer():
300
>>> assign_slice_start_end_from_pointer()
301
(123, 234, 1, 2, 345)
303
cdef int *v = [1, 2, 3, 4, 5]
309
return (a[0], a[1], a[2], a[3], a[4])
313
# FIXME: make this work:
314
def assign_slice_start_end_from_sliced_pointer():
316
>>> assign_slice_start_end_from_sliced_pointer()
317
(123, 234, 3, 4, 345)
319
cdef int *v = [1, 2, 3, 4, 5]
325
return (a[0], a[1], a[2], a[3], a[4])
328
def assign_from_longer_array_slice():
330
>>> assign_from_longer_array_slice()
348
def assign_slice_from_shorter_array():
350
>>> assign_slice_from_shorter_array()
370
ctypedef int[SIZE] int_array_dyn
373
def assign_ptr_to_unknown_csize():
375
>>> assign_ptr_to_unknown_csize()
378
cdef int* v = [1, 2, 3, 4, 5]
384
def assign_to_wrong_csize():
386
>>> assign_to_wrong_csize()
387
Traceback (most recent call last):
388
ValueError: Assignment to slice of wrong length, expected 3, got 2
399
def assign_full_array_slice_to_array():
401
>>> assign_full_array_slice_to_array()
412
cdef class ArrayOwner:
413
cdef readonly int[3] array
415
def __init__(self, a, b, c):
416
self.array = (a, b, c)
419
def assign_from_array_attribute():
421
>>> assign_from_array_attribute()
425
a = ArrayOwner(1, 2, 3)