Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
M
micropython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
xpstem
micropython
Commits
d7e16842
Commit
d7e16842
authored
Jan 05, 2017
by
Rami Ali
Committed by
Damien George
Jan 05, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
tests/unix: Improve formatfloat.c test coverage using C.
parent
64dc925c
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
25 additions
and
0 deletions
+25
-0
tests/unix/extra_coverage.py.exp
tests/unix/extra_coverage.py.exp
+4
-0
unix/coverage.c
unix/coverage.c
+21
-0
No files found.
tests/unix/extra_coverage.py.exp
View file @
d7e16842
...
...
@@ -39,6 +39,10 @@ ementation
TypeError: can't convert str to int
TypeError: unsupported types for : 'str', 'str'
Warning: test
# format float
?
+1e+00
+1e+00
('0123456789', b'0123456789')
7300
7300
...
...
unix/coverage.c
View file @
d7e16842
...
...
@@ -7,6 +7,7 @@
#include "py/mpz.h"
#include "py/builtin.h"
#include "py/emit.h"
#include "py/formatfloat.h"
#if defined(MICROPY_UNIX_COVERAGE)
...
...
@@ -136,6 +137,26 @@ STATIC mp_obj_t extra_coverage(void) {
mp_emitter_warning
(
MP_PASS_CODE_SIZE
,
"test"
);
}
// format float
{
mp_printf
(
&
mp_plat_print
,
"# format float
\n
"
);
// format with inadequate buffer size
char
buf
[
5
];
mp_format_float
(
1
,
buf
,
sizeof
(
buf
),
'g'
,
0
,
'+'
);
mp_printf
(
&
mp_plat_print
,
"%s
\n
"
,
buf
);
// format with just enough buffer so that precision must be
// set from 0 to 1 twice
char
buf2
[
8
];
mp_format_float
(
1
,
buf2
,
sizeof
(
buf2
),
'g'
,
0
,
'+'
);
mp_printf
(
&
mp_plat_print
,
"%s
\n
"
,
buf2
);
// format where precision is trimmed to avoid buffer overflow
mp_format_float
(
1
,
buf2
,
sizeof
(
buf2
),
'e'
,
0
,
'+'
);
mp_printf
(
&
mp_plat_print
,
"%s
\n
"
,
buf2
);
}
// return a tuple of data for testing on the Python side
mp_obj_t
items
[]
=
{(
mp_obj_t
)
&
str_no_hash_obj
,
(
mp_obj_t
)
&
bytes_no_hash_obj
};
return
mp_obj_new_tuple
(
MP_ARRAY_SIZE
(
items
),
items
);
...
...
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