diff --git a/ports/unix/coverage.c b/ports/unix/coverage.c index e4d2d68fc9..1b6132cddd 100644 --- a/ports/unix/coverage.c +++ b/ports/unix/coverage.c @@ -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; diff --git a/tests/unix/extra_coverage.py.exp b/tests/unix/extra_coverage.py.exp index 9c3b036b93..6130a06511 100644 --- a/tests/unix/extra_coverage.py.exp +++ b/tests/unix/extra_coverage.py.exp @@ -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