Commit d22ebc4b authored by Stefan Behnel's avatar Stefan Behnel

extended test case

parent b629c04e
cimport cython
bytes_abc = b'abc' bytes_abc = b'abc'
bytes_ABC = b'ABC' bytes_ABC = b'ABC'
...@@ -20,6 +21,8 @@ def for_in_bytes(bytes s): ...@@ -20,6 +21,8 @@ def for_in_bytes(bytes s):
else: else:
return 'X' return 'X'
@cython.test_assert_path_exists("//ForFromStatNode")
@cython.test_fail_if_path_exists("//ForInStatNode")
def for_char_in_bytes(bytes s): def for_char_in_bytes(bytes s):
""" """
>>> for_char_in_bytes(bytes_abc) >>> for_char_in_bytes(bytes_abc)
...@@ -34,6 +37,25 @@ def for_char_in_bytes(bytes s): ...@@ -34,6 +37,25 @@ def for_char_in_bytes(bytes s):
else: else:
return 'X' return 'X'
@cython.test_assert_path_exists("//ForFromStatNode")
@cython.test_fail_if_path_exists("//ForInStatNode")
def for_char_in_enumerate_bytes(bytes s):
"""
>>> for_char_in_enumerate_bytes(bytes_abc)
'X'
>>> for_char_in_enumerate_bytes(bytes_ABC)
2
"""
cdef char c
cdef Py_ssize_t i
for i, c in enumerate(s):
if c == b'C':
return i
else:
return 'X'
@cython.test_assert_path_exists("//ForFromStatNode")
@cython.test_fail_if_path_exists("//ForInStatNode")
def for_pyunicode_in_unicode(unicode s): def for_pyunicode_in_unicode(unicode s):
""" """
>>> for_pyunicode_in_unicode(unicode_abc) >>> for_pyunicode_in_unicode(unicode_abc)
...@@ -47,3 +69,20 @@ def for_pyunicode_in_unicode(unicode s): ...@@ -47,3 +69,20 @@ def for_pyunicode_in_unicode(unicode s):
return 'C' return 'C'
else: else:
return 'X' return 'X'
@cython.test_assert_path_exists("//ForFromStatNode")
@cython.test_fail_if_path_exists("//ForInStatNode")
def for_pyunicode_in_enumerate_unicode(unicode s):
"""
>>> for_pyunicode_in_enumerate_unicode(unicode_abc)
'X'
>>> for_pyunicode_in_enumerate_unicode(unicode_ABC)
2
"""
cdef Py_UNICODE c
cdef Py_ssize_t i
for i, c in enumerate(s):
if c == u'C':
return i
else:
return 'X'
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