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
Labels
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
nexedi
cython
Commits
e8521032
Commit
e8521032
authored
Mar 21, 2010
by
Stefan Behnel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
tests for unicode method optimisations
parent
14e33770
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
187 additions
and
0 deletions
+187
-0
tests/run/unicodemethods.pyx
tests/run/unicodemethods.pyx
+187
-0
No files found.
tests/run/unicodemethods.pyx
0 → 100644
View file @
e8521032
# -*- coding: utf-8 -*-
cimport
cython
text
=
u'ab jd sdflk as sa sadas asdas fsdf '
sep
=
u' '
multiline_text
=
u'''
\
ab jd
sdflk as sa
sadas asdas fsdf '''
def
print_all
(
l
):
for
s
in
l
:
print
(
s
)
# unicode.split(s, [sep, [maxsplit]])
def
split
(
unicode
s
):
"""
>>> print_all( text.split() )
ab
jd
sdflk
as
sa
sadas
asdas
fsdf
>>> print_all( split(text) )
ab
jd
sdflk
as
sa
sadas
asdas
fsdf
"""
return
s
.
split
()
def
split_sep
(
unicode
s
,
sep
):
"""
>>> print_all( text.split(sep) )
ab jd
sdflk as sa
sadas asdas fsdf
>>> print_all( split_sep(text, sep) )
ab jd
sdflk as sa
sadas asdas fsdf
"""
return
s
.
split
(
sep
)
@
cython
.
test_fail_if_path_exists
(
"//CoerceToPyTypeNode"
,
"//CastNode"
,
"//TypecastNode"
)
@
cython
.
test_assert_path_exists
(
"//CoerceFromPyTypeNode"
)
def
split_sep_max
(
unicode
s
,
sep
,
max
):
"""
>>> print_all( text.split(sep, 1) )
ab jd
sdflk as sa sadas asdas fsdf
>>> print_all( split_sep_max(text, sep, 1) )
ab jd
sdflk as sa sadas asdas fsdf
"""
return
s
.
split
(
sep
,
max
)
@
cython
.
test_fail_if_path_exists
(
"//CoerceToPyTypeNode"
,
"//CoerceFromPyTypeNode"
,
"//CastNode"
,
"//TypecastNode"
)
def
split_sep_max_int
(
unicode
s
,
sep
):
"""
>>> print_all( text.split(sep, 1) )
ab jd
sdflk as sa sadas asdas fsdf
>>> print_all( split_sep_max_int(text, sep) )
ab jd
sdflk as sa sadas asdas fsdf
"""
return
s
.
split
(
sep
,
1
)
# unicode.splitlines(s, [keepends])
def
splitlines
(
unicode
s
):
"""
>>> len(multiline_text.splitlines())
3
>>> print_all( multiline_text.splitlines() )
ab jd
sdflk as sa
sadas asdas fsdf
>>> len(splitlines(multiline_text))
3
>>> print_all( splitlines(multiline_text) )
ab jd
sdflk as sa
sadas asdas fsdf
"""
return
s
.
splitlines
()
def
splitlines_keep
(
unicode
s
,
keep
):
"""
>>> len(multiline_text.splitlines(True))
3
>>> print_all( multiline_text.splitlines(True) )
ab jd
<BLANKLINE>
sdflk as sa
<BLANKLINE>
sadas asdas fsdf
>>> len(splitlines_keep(multiline_text, True))
3
>>> print_all( splitlines_keep(multiline_text, True) )
ab jd
<BLANKLINE>
sdflk as sa
<BLANKLINE>
sadas asdas fsdf
"""
return
s
.
splitlines
(
keep
)
@
cython
.
test_fail_if_path_exists
(
# boolean conversion isn't currently smart enough for this ...
# "//CoerceToPyTypeNode", "//CoerceFromPyTypeNode",
"//CastNode"
,
"//TypecastNode"
)
def
splitlines_keep_bint
(
unicode
s
):
"""
>>> len(multiline_text.splitlines(True))
3
>>> print_all( multiline_text.splitlines(True) )
ab jd
<BLANKLINE>
sdflk as sa
<BLANKLINE>
sadas asdas fsdf
>>> print_all( multiline_text.splitlines(False) )
ab jd
sdflk as sa
sadas asdas fsdf
>>> len(splitlines_keep_bint(multiline_text))
7
>>> print_all( splitlines_keep_bint(multiline_text) )
ab jd
<BLANKLINE>
sdflk as sa
<BLANKLINE>
sadas asdas fsdf
--
ab jd
sdflk as sa
sadas asdas fsdf
"""
return
s
.
splitlines
(
True
)
+
[
'--'
]
+
s
.
splitlines
(
False
)
# unicode.join(s, iterable)
pipe_sep
=
u'|'
def
join
(
unicode
sep
,
l
):
"""
>>> l = text.split()
>>> len(l)
8
>>> print( pipe_sep.join(l) )
ab|jd|sdflk|as|sa|sadas|asdas|fsdf
>>> print( join(pipe_sep, l) )
ab|jd|sdflk|as|sa|sadas|asdas|fsdf
"""
return
sep
.
join
(
l
)
def
join_sep
(
l
):
"""
>>> l = text.split()
>>> len(l)
8
>>> print( '|'.join(l) )
ab|jd|sdflk|as|sa|sadas|asdas|fsdf
>>> print( join_sep(l) )
ab|jd|sdflk|as|sa|sadas|asdas|fsdf
"""
return
u'|'
.
join
(
l
)
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