Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cython
Commits
31f2903e
Commit
31f2903e
authored
Apr 26, 2010
by
Stefan Behnel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
extended test case
parent
26257b35
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
80 additions
and
0 deletions
+80
-0
tests/run/bytes_indexing.pyx
tests/run/bytes_indexing.pyx
+80
-0
No files found.
tests/run/bytes_indexing.pyx
View file @
31f2903e
...
@@ -40,6 +40,26 @@ def index_literal_char_cast(int i):
...
@@ -40,6 +40,26 @@ def index_literal_char_cast(int i):
return
<
char
>
(
b"12345"
[
i
])
return
<
char
>
(
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
<
char
>
(
b12345
[
i
])
@
cython
.
test_assert_path_exists
(
"//PythonCapiCallNode"
)
@
cython
.
test_assert_path_exists
(
"//PythonCapiCallNode"
)
@
cython
.
test_fail_if_path_exists
(
"//IndexNode"
,
@
cython
.
test_fail_if_path_exists
(
"//IndexNode"
,
"//CoerceFromPyTypeNode"
)
"//CoerceFromPyTypeNode"
)
...
@@ -60,6 +80,26 @@ def index_literal_uchar_cast(int i):
...
@@ -60,6 +80,26 @@ def index_literal_uchar_cast(int i):
return
<
unsigned
char
>
(
b"12345"
[
i
])
return
<
unsigned
char
>
(
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
<
unsigned
char
>
(
b12345
[
i
])
@
cython
.
test_assert_path_exists
(
"//PythonCapiCallNode"
)
@
cython
.
test_assert_path_exists
(
"//PythonCapiCallNode"
)
@
cython
.
test_fail_if_path_exists
(
"//IndexNode"
,
@
cython
.
test_fail_if_path_exists
(
"//IndexNode"
,
"//CoerceFromPyTypeNode"
)
"//CoerceFromPyTypeNode"
)
...
@@ -81,6 +121,27 @@ def index_literal_char_coerce(int i):
...
@@ -81,6 +121,27 @@ def index_literal_char_coerce(int i):
return
result
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_assert_path_exists
(
"//PythonCapiCallNode"
)
@
cython
.
test_fail_if_path_exists
(
"//IndexNode"
,
@
cython
.
test_fail_if_path_exists
(
"//IndexNode"
,
"//CoerceFromPyTypeNode"
)
"//CoerceFromPyTypeNode"
)
...
@@ -98,3 +159,22 @@ def index_literal_char_coerce_no_check(int i):
...
@@ -98,3 +159,22 @@ def index_literal_char_coerce_no_check(int i):
"""
"""
cdef
char
result
=
b"12345"
[
i
]
cdef
char
result
=
b"12345"
[
i
]
return
result
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
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment