Commit 04ff4ecc authored by Stefan Behnel's avatar Stefan Behnel

extended unicode iteration tests

parent 923aaab7
......@@ -163,8 +163,45 @@ def count_lower_case_characters(unicode ustring):
count += 1
return count
@cython.test_assert_path_exists('//SwitchStatNode',
@cython.test_assert_path_exists('//PythonCapiCallNode',
'//ForFromStatNode')
@cython.test_fail_if_path_exists('//SimpleCallNode',
'//ForInStatNode')
def count_lower_case_characters_slice(unicode ustring):
"""
>>> count_lower_case_characters_slice(mixed_ustring)
10
>>> count_lower_case_characters_slice(lower_ustring)
14
>>> sum([ 1 for uchar in lower_ustring[1:-1] if uchar.islower() ])
14
"""
cdef Py_ssize_t count = 0
for uchar in ustring[1:-1]:
if uchar.islower():
count += 1
return count
@cython.test_assert_path_exists('//PythonCapiCallNode',
'//ForFromStatNode')
@cython.test_fail_if_path_exists('//SimpleCallNode',
'//ForInStatNode')
def count_lower_case_characters_slice_reversed(unicode ustring):
"""
>>> count_lower_case_characters_slice_reversed(mixed_ustring)
10
>>> count_lower_case_characters_slice_reversed(lower_ustring)
14
>>> sum([ 1 for uchar in lower_ustring[-2:0:-1] if uchar.islower() ])
14
"""
cdef Py_ssize_t count = 0
for uchar in ustring[-2:0:-1]:
if uchar.islower():
count += 1
return count
@cython.test_assert_path_exists('//SwitchStatNode')
@cython.test_fail_if_path_exists('//ForInStatNode')
def iter_and_in():
"""
......
......@@ -163,6 +163,23 @@ def count_lower_case_characters(unicode ustring):
count += 1
return count
@cython.test_assert_path_exists('//PythonCapiCallNode',
'//ForFromStatNode')
@cython.test_fail_if_path_exists('//SimpleCallNode',
'//ForInStatNode')
def count_lower_case_characters_slice(unicode ustring):
"""
>>> count_lower_case_characters_slice(mixed_ustring)
10
>>> count_lower_case_characters_slice(lower_ustring)
14
"""
cdef Py_ssize_t count = 0
for uchar in ustring[1:-1]:
if uchar.islower():
count += 1
return count
@cython.test_assert_path_exists('//SwitchStatNode',
'//ForFromStatNode')
@cython.test_fail_if_path_exists('//ForInStatNode')
......@@ -179,8 +196,7 @@ def iter_and_in():
if c in u'abCDefGh':
print c
@cython.test_assert_path_exists('//SwitchStatNode',
'//ForFromStatNode')
@cython.test_assert_path_exists('//SwitchStatNode')
@cython.test_fail_if_path_exists('//ForInStatNode')
def index_and_in():
"""
......
......@@ -181,11 +181,11 @@ def reversed_unicode_slice(unicode u):
return result
@cython.test_assert_path_exists('//ForFromStatNode')
def reversed_unicode_slice_step(unicode u):
def reversed_unicode_slice_neg_step(unicode u):
"""
>>> print(''.join(_reversed(unicode_string[-2:1:-1])))
cDE
>>> print(''.join(reversed_unicode_slice_step(unicode_string)))
>>> print(''.join(reversed_unicode_slice_neg_step(unicode_string)))
cDE
"""
result = []
......@@ -194,11 +194,76 @@ def reversed_unicode_slice_step(unicode u):
return result
@cython.test_assert_path_exists('//ForFromStatNode')
def reversed_unicode_slice_step_only(unicode u):
def reversed_unicode_slice_pos_step(unicode u):
"""
>>> print(''.join(_reversed(unicode_string[1:-2:1])))
Dcb
>>> print(''.join(reversed_unicode_slice_pos_step(unicode_string)))
Dcb
"""
result = []
for c in reversed(u[1:-2:1]):
result.append(c)
return result
@cython.test_assert_path_exists('//ForFromStatNode')
def reversed_unicode_slice_start_pos_step(unicode u):
"""
>>> print(''.join(_reversed(unicode_string[2::1])))
FEDc
>>> print(''.join(reversed_unicode_slice_start_pos_step(unicode_string)))
FEDc
"""
result = []
for c in reversed(u[2::1]):
result.append(c)
return result
@cython.test_assert_path_exists('//ForFromStatNode')
def reversed_unicode_slice_start_neg_step(unicode u):
"""
>>> print(''.join(_reversed(unicode_string[3::-1])))
abcD
>>> print(''.join(reversed_unicode_slice_start_neg_step(unicode_string)))
abcD
"""
result = []
for c in reversed(u[3::-1]):
result.append(c)
return result
@cython.test_assert_path_exists('//ForFromStatNode')
def reversed_unicode_slice_end_pos_step(unicode u):
"""
>>> print(''.join(_reversed(unicode_string[:-2:1])))
Dcba
>>> print(''.join(reversed_unicode_slice_end_pos_step(unicode_string)))
Dcba
"""
result = []
for c in reversed(u[:-2:1]):
result.append(c)
return result
@cython.test_assert_path_exists('//ForFromStatNode')
def reversed_unicode_slice_end_neg_step(unicode u):
"""
>>> print(''.join(_reversed(unicode_string[:-3:-1])))
EF
>>> print(''.join(reversed_unicode_slice_end_neg_step(unicode_string)))
EF
"""
result = []
for c in reversed(u[:-3:-1]):
result.append(c)
return result
@cython.test_assert_path_exists('//ForFromStatNode')
def reversed_unicode_slice_neg_step_only(unicode u):
"""
>>> print(''.join(_reversed(unicode_string[::-1])))
abcDEF
>>> print(''.join(reversed_unicode_slice_step_only(unicode_string)))
>>> print(''.join(reversed_unicode_slice_neg_step_only(unicode_string)))
abcDEF
"""
result = []
......@@ -206,6 +271,19 @@ def reversed_unicode_slice_step_only(unicode u):
result.append(c)
return result
@cython.test_assert_path_exists('//ForFromStatNode')
def reversed_unicode_slice_pos_step_only(unicode u):
"""
>>> print(''.join(_reversed(unicode_string[::1])))
FEDcba
>>> print(''.join(reversed_unicode_slice_pos_step_only(unicode_string)))
FEDcba
"""
result = []
for c in reversed(u[::1]):
result.append(c)
return result
bytes_string = b'abcDEF'
join_bytes = b''.join
......
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