From 31f2903eda4dc34da01931418e66bd34bd840d7b Mon Sep 17 00:00:00 2001 From: Stefan Behnel Date: Mon, 26 Apr 2010 08:38:34 +0200 Subject: [PATCH] extended test case --- tests/run/bytes_indexing.pyx | 80 ++++++++++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) diff --git a/tests/run/bytes_indexing.pyx b/tests/run/bytes_indexing.pyx index eeba85c0..cb4ea3a1 100644 --- a/tests/run/bytes_indexing.pyx +++ b/tests/run/bytes_indexing.pyx @@ -40,6 +40,26 @@ def index_literal_char_cast(int i): return (b"12345"[i]) +@cython.test_assert_path_exists("//PythonCapiCallNode") +@cython.test_fail_if_path_exists("//IndexNode", + "//CoerceFromPyTypeNode") +def index_nonliteral_char_cast(int i): + """ + >>> index_nonliteral_char_cast(0) == ord('1') + True + >>> index_nonliteral_char_cast(-5) == ord('1') + True + >>> index_nonliteral_char_cast(2) == ord('3') + True + >>> index_nonliteral_char_cast(4) == ord('5') + True + >>> index_nonliteral_char_cast(6) + Traceback (most recent call last): + IndexError: string index out of range + """ + return (b12345[i]) + + @cython.test_assert_path_exists("//PythonCapiCallNode") @cython.test_fail_if_path_exists("//IndexNode", "//CoerceFromPyTypeNode") @@ -60,6 +80,26 @@ def index_literal_uchar_cast(int i): return (b"12345"[i]) +@cython.test_assert_path_exists("//PythonCapiCallNode") +@cython.test_fail_if_path_exists("//IndexNode", + "//CoerceFromPyTypeNode") +def index_nonliteral_uchar_cast(int i): + """ + >>> index_nonliteral_uchar_cast(0) == ord('1') + True + >>> index_nonliteral_uchar_cast(-5) == ord('1') + True + >>> index_nonliteral_uchar_cast(2) == ord('3') + True + >>> index_nonliteral_uchar_cast(4) == ord('5') + True + >>> index_nonliteral_uchar_cast(6) + Traceback (most recent call last): + IndexError: string index out of range + """ + return (b12345[i]) + + @cython.test_assert_path_exists("//PythonCapiCallNode") @cython.test_fail_if_path_exists("//IndexNode", "//CoerceFromPyTypeNode") @@ -81,6 +121,27 @@ def index_literal_char_coerce(int i): return result +@cython.test_assert_path_exists("//PythonCapiCallNode") +@cython.test_fail_if_path_exists("//IndexNode", + "//CoerceFromPyTypeNode") +def index_nonliteral_char_coerce(int i): + """ + >>> index_nonliteral_char_coerce(0) == ord('1') + True + >>> index_nonliteral_char_coerce(-5) == ord('1') + True + >>> index_nonliteral_char_coerce(2) == ord('3') + True + >>> index_nonliteral_char_coerce(4) == ord('5') + True + >>> index_nonliteral_char_coerce(6) + Traceback (most recent call last): + IndexError: string index out of range + """ + cdef char result = b12345[i] + return result + + @cython.test_assert_path_exists("//PythonCapiCallNode") @cython.test_fail_if_path_exists("//IndexNode", "//CoerceFromPyTypeNode") @@ -98,3 +159,22 @@ def index_literal_char_coerce_no_check(int i): """ cdef char result = b"12345"[i] return result + + +@cython.test_assert_path_exists("//PythonCapiCallNode") +@cython.test_fail_if_path_exists("//IndexNode", + "//CoerceFromPyTypeNode") +@cython.boundscheck(False) +def index_nonliteral_char_coerce_no_check(int i): + """ + >>> index_nonliteral_char_coerce_no_check(0) == ord('1') + True + >>> index_nonliteral_char_coerce_no_check(-5) == ord('1') + True + >>> index_nonliteral_char_coerce_no_check(2) == ord('3') + True + >>> index_nonliteral_char_coerce_no_check(4) == ord('5') + True + """ + cdef char result = b12345[i] + return result -- 2.26.2