From d22ebc4b0c1a6bc9e465d65551d50a730a2852ee Mon Sep 17 00:00:00 2001 From: Stefan Behnel Date: Tue, 20 Apr 2010 08:25:35 +0200 Subject: [PATCH] extended test case --- tests/run/for_in_string.pyx | 39 +++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/tests/run/for_in_string.pyx b/tests/run/for_in_string.pyx index 1ad0cfa2..a892d1a5 100644 --- a/tests/run/for_in_string.pyx +++ b/tests/run/for_in_string.pyx @@ -1,3 +1,4 @@ +cimport cython bytes_abc = b'abc' bytes_ABC = b'ABC' @@ -20,6 +21,8 @@ def for_in_bytes(bytes s): else: return 'X' +@cython.test_assert_path_exists("//ForFromStatNode") +@cython.test_fail_if_path_exists("//ForInStatNode") def for_char_in_bytes(bytes s): """ >>> for_char_in_bytes(bytes_abc) @@ -34,6 +37,25 @@ def for_char_in_bytes(bytes s): else: 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): """ >>> for_pyunicode_in_unicode(unicode_abc) @@ -47,3 +69,20 @@ def for_pyunicode_in_unicode(unicode s): return 'C' else: 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' -- 2.26.2