Commit 749415a1 authored by root's avatar root

Updated test cases for reversed iteration.

parent cab1d35c
# mode: error
# tag: reversed
cdef int i, j
for i in reversed(range([], j, 2)):
pass
for i in reversed(range([], j, -2)):
pass
for i in reversed(range(j, [], 2)):
pass
for i in reversed(range(j, [], -2)):
pass
for i in reversed(range({}, j, 2)):
pass
for i in reversed(range({}, j, -2)):
pass
for i in reversed(range(j, {}, 2)):
pass
for i in reversed(range(j, {}, -2)):
pass
_ERRORS = """
5:24: Cannot coerce list to type 'long'
7:24: Cannot coerce list to type 'long'
9:27: Cannot coerce list to type 'long'
11:27: Cannot coerce list to type 'long'
13:24: Cannot interpret dict as type 'long'
15:24: Cannot interpret dict as type 'long'
17:27: Cannot interpret dict as type 'long'
19:27: Cannot interpret dict as type 'long'
"""
......@@ -133,7 +133,6 @@ def reversed_range_step_neg(int a, int b):
result.append(i)
return result, i
@cython.test_assert_path_exists('//ForFromStatNode')
@cython.test_fail_if_path_exists('//ForInStatNode')
def reversed_range_step3(int a, int b):
......@@ -152,6 +151,11 @@ def reversed_range_step3(int a, int b):
[]
>>> reversed_range_step3(5, 0)
([], 99)
>>> [ i for i in _reversed(range(1, 1, 3)) ]
[]
>>> reversed_range_step3(1, 1)
([], 99)
"""
cdef int i = 99
result = []
......@@ -159,7 +163,6 @@ def reversed_range_step3(int a, int b):
result.append(i)
return result, i
@cython.test_assert_path_exists('//ForFromStatNode')
@cython.test_fail_if_path_exists('//ForInStatNode')
def reversed_range_step3_neg(int a, int b):
......@@ -178,6 +181,11 @@ def reversed_range_step3_neg(int a, int b):
[]
>>> reversed_range_step3_neg(0, 5)
([], 99)
>>> [ i for i in _reversed(range(1, 1, -3)) ]
[]
>>> reversed_range_step3_neg(1, 1)
([], 99)
"""
cdef int i = 99
result = []
......@@ -185,8 +193,122 @@ def reversed_range_step3_neg(int a, int b):
result.append(i)
return result, i
def reversed_range_step3_py_args(a, b):
"""
>>> [ i for i in _reversed(range(-5, 0, 3)) ]
[-2, -5]
>>> reversed_range_step3_py_args(-5, 0)
([-2, -5], -5)
>>> [ i for i in _reversed(range(0, 5, 3)) ]
[3, 0]
>>> reversed_range_step3_py_args(0, 5)
([3, 0], 0)
>>> [ i for i in _reversed(range(5, 0, 3)) ]
[]
>>> reversed_range_step3_py_args(5, 0)
([], 99)
>>> [ i for i in _reversed(range(1, 1, 3)) ]
[]
>>> reversed_range_step3_py_args(1, 1)
([], 99)
>>> reversed_range_step3_py_args(set(), 1)
Traceback (most recent call last):
TypeError: range() integer start argument expected, got set.
>>> reversed_range_step3_py_args(1, set())
Traceback (most recent call last):
TypeError: range() integer end argument expected, got set.
"""
i = 99
result = []
for i in reversed(range(a, b, 3)):
result.append(i)
return result, i
def reversed_range_step3_neg_py_args(a, b):
"""
>>> [ i for i in _reversed(range(0, -5, -3)) ]
[-3, 0]
>>> reversed_range_step3_neg_py_args(0, -5)
([-3, 0], 0)
>>> [ i for i in _reversed(range(5, 0, -3)) ]
[2, 5]
>>> reversed_range_step3_neg_py_args(5, 0)
([2, 5], 5)
>>> [ i for i in _reversed(range(0, 5, -3)) ]
[]
>>> reversed_range_step3_neg_py_args(0, 5)
([], 99)
>>> [ i for i in _reversed(range(1, 1, -3)) ]
[]
>>> reversed_range_step3_neg_py_args(1, 1)
([], 99)
>>> reversed_range_step3_neg_py_args(set(), 1)
Traceback (most recent call last):
TypeError: range() integer start argument expected, got set.
>>> reversed_range_step3_neg_py_args(1, set())
Traceback (most recent call last):
TypeError: range() integer end argument expected, got set.
"""
i = 99
result = []
for i in reversed(range(a, b, -3)):
result.append(i)
return result, i
def reversed_range_step3_py_obj_left(a, int b):
"""
>>> reversed_range_step3_py_obj_left(set(), 0)
Traceback (most recent call last):
TypeError: an integer is required
"""
cdef int i
result = []
for i in reversed(range(a, b, 3)):
result.append(i)
def reversed_range_step3_py_obj_right(int a, b):
"""
>>> reversed_range_step3_py_obj_right(0, set())
Traceback (most recent call last):
TypeError: an integer is required
"""
cdef int i
result = []
for i in reversed(range(a, b, 3)):
result.append(i)
def reversed_range_step3_neg_py_obj_left(a, int b):
"""
>>> reversed_range_step3_neg_py_obj_left(set(), 0)
Traceback (most recent call last):
TypeError: an integer is required
"""
cdef int i
result = []
for i in reversed(range(a, b, -3)):
result.append(i)
def reversed_range_step3_neg_py_obj_right(int a, b):
"""
>>> reversed_range_step3_py_obj_right(0, set())
Traceback (most recent call last):
TypeError: an integer is required
"""
cdef int i
result = []
for i in reversed(range(a, b, -3)):
result.append(i)
@cython.test_assert_path_exists('//ForFromStatNode')
@cython.test_fail_if_path_exists('//ForInStatNode')
def reversed_range_constant():
"""
......@@ -202,7 +324,6 @@ def reversed_range_constant():
assert result == list(reversed(range(1, 1, 4))), result
assert i == 99
result = []
for i in reversed(range(1, 1, 1)):
result.append(i)
assert result == list(reversed(range(1, 1, 1))), result
......@@ -272,13 +393,13 @@ def reversed_range_constant():
result.append(i)
assert result == list(reversed(range(0, 12, 4))), result
i = 99
result = []
for i in reversed(range(-12, -2, 4)):
result.append(i)
assert result == list(reversed(range(-12, -2, 4))), result
return result, i
@cython.test_assert_path_exists('//ForFromStatNode')
@cython.test_fail_if_path_exists('//ForInStatNode')
def reversed_range_constant_neg():
......@@ -414,7 +535,6 @@ def reversed_range_constant_neg():
result.append(i)
assert result == list(reversed(range(-2, -12, -1))), result
unicode_string = u"abcDEF"
@cython.test_assert_path_exists('//ForFromStatNode')
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment