Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
P
Pyston
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
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Boxiang Sun
Pyston
Commits
3b637401
Commit
3b637401
authored
Jun 08, 2014
by
Krzysztof Klinikowski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update chr to be compatible with CPython
parent
6acfb996
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
28 additions
and
3 deletions
+28
-3
src/runtime/builtin_modules/builtins.cpp
src/runtime/builtin_modules/builtins.cpp
+4
-3
test/tests/test_chr.py
test/tests/test_chr.py
+24
-0
No files found.
src/runtime/builtin_modules/builtins.cpp
View file @
3b637401
...
...
@@ -202,11 +202,12 @@ Box* open(Box* arg1, Box* arg2) {
extern
"C"
Box
*
chr
(
Box
*
arg
)
{
if
(
arg
->
cls
!=
int_cls
)
{
fprintf
(
stderr
,
"TypeError: coercing to Unicode: need string of buffer, %s found
\n
"
,
getTypeName
(
arg
)
->
c_str
());
raiseExcHelper
(
TypeError
,
""
);
raiseExcHelper
(
TypeError
,
"an integer is required"
);
}
i64
n
=
static_cast
<
BoxedInt
*>
(
arg
)
->
n
;
RELEASE_ASSERT
(
n
>=
0
&&
n
<
256
,
""
);
if
(
n
<
0
||
n
>=
256
)
{
raiseExcHelper
(
ValueError
,
"chr() arg not in range(256)"
);
}
return
boxString
(
std
::
string
(
1
,
(
char
)
n
));
}
...
...
test/tests/test_chr.py
0 → 100644
View file @
3b637401
assert
chr
(
0
)
==
'
\
x00
'
assert
chr
(
1
)
==
'
\
x01
'
assert
chr
(
128
)
==
'
\
x80
'
assert
chr
(
255
)
==
'
\
xff
'
try
:
chr
(
'a'
)
assert
False
except
TypeError
as
e
:
assert
e
.
message
==
'an integer is required'
try
:
chr
(
256
)
assert
'chr(256) should throw chr() arg not in range(256)'
==
False
except
ValueError
as
e
:
assert
e
.
message
==
'chr() arg not in range(256)'
try
:
chr
(
-
1
)
assert
'chr(-1) should throw chr() arg not in range(256)'
==
False
except
ValueError
as
e
:
assert
e
.
message
==
'chr() arg not in range(256)'
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