tests/unix: Add coverage tests for mp_obj_is_type() and variants.

pull/5569/head
Yonatan Goldschmidt 2020-01-22 20:44:52 +01:00 zatwierdzone przez Damien George
rodzic d9433d3e94
commit 35e664d779
2 zmienionych plików z 30 dodań i 1 usunięć

Wyświetl plik

@ -16,6 +16,8 @@
#include "py/binary.h"
#include "py/bc.h"
// expected output of this file is found in extra_coverage.py.exp
#if defined(MICROPY_UNIX_COVERAGE)
// stream testing object
@ -539,7 +541,7 @@ STATIC mp_obj_t extra_coverage(void) {
ringbuf.iput = 0;
ringbuf.iget = 0;
mp_printf(&mp_plat_print, "%d\n", ringbuf_get16(&ringbuf));
// Two-byte get from ringbuf with one byte available.
ringbuf.iput = 0;
ringbuf.iget = 0;
@ -576,6 +578,25 @@ STATIC mp_obj_t extra_coverage(void) {
pairheap_test(MP_ARRAY_SIZE(t5), t5);
}
// mp_obj_is_type and derivatives
{
mp_printf(&mp_plat_print, "# mp_obj_is_type\n");
// mp_obj_is_bool accepts only booleans
mp_printf(&mp_plat_print, "%d %d\n", mp_obj_is_bool(mp_const_true), mp_obj_is_bool(mp_const_false));
mp_printf(&mp_plat_print, "%d %d\n", mp_obj_is_bool(MP_OBJ_NEW_SMALL_INT(1)), mp_obj_is_bool(mp_const_none));
// mp_obj_is_integer accepts ints and booleans
mp_printf(&mp_plat_print, "%d %d\n", mp_obj_is_integer(MP_OBJ_NEW_SMALL_INT(1)), mp_obj_is_integer(mp_obj_new_int_from_ll(1)));
mp_printf(&mp_plat_print, "%d %d\n", mp_obj_is_integer(mp_const_true), mp_obj_is_integer(mp_const_false));
mp_printf(&mp_plat_print, "%d %d\n", mp_obj_is_integer(mp_obj_new_str("1", 1)), mp_obj_is_integer(mp_const_none));
// mp_obj_is_int accepts small int and object ints
mp_printf(&mp_plat_print, "%d %d\n", mp_obj_is_int(MP_OBJ_NEW_SMALL_INT(1)), mp_obj_is_int(mp_obj_new_int_from_ll(1)));
}
mp_printf(&mp_plat_print, "# end coverage.c\n");
mp_obj_streamtest_t *s = m_new_obj(mp_obj_streamtest_t);
s->base.type = &mp_type_stest_fileio;
s->buf = NULL;

Wyświetl plik

@ -115,6 +115,14 @@ create: 1 1 1 1 1
pop all: 1 3 4
create: 3 3 3 1 1 1
pop all: 1 2 4 5
# mp_obj_is_type
1 1
0 0
1 1
1 1
0 0
1 1
# end coverage.c
0123456789 b'0123456789'
7300
7300