diff options
author | Damien George <damien.p.george@gmail.com> | 2020-01-14 23:45:56 +1100 |
---|---|---|
committer | Damien George <damien.p.george@gmail.com> | 2020-01-14 23:45:56 +1100 |
commit | 3448e69c2d6f6f066907005f56bbd26fffb756e9 (patch) | |
tree | 49ff7b6e87bc5288c25ed314adaead312112b72b /ports/unix/coverage.c | |
parent | 176ab99180a95eeac8794828f2f751a696571bb5 (diff) |
tests/unix: Add coverage test for new mp_obj_int_get_uint_checked func.
Diffstat (limited to 'ports/unix/coverage.c')
-rw-r--r-- | ports/unix/coverage.c | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/ports/unix/coverage.c b/ports/unix/coverage.c index 6623cb464..6cd84dc30 100644 --- a/ports/unix/coverage.c +++ b/ports/unix/coverage.c @@ -334,6 +334,29 @@ STATIC mp_obj_t extra_coverage(void) { mp_call_function_2_protected(MP_OBJ_FROM_PTR(&mp_builtin_divmod_obj), MP_OBJ_NEW_SMALL_INT(1), MP_OBJ_NEW_SMALL_INT(1)); // call mp_call_function_2_protected with invalid args mp_call_function_2_protected(MP_OBJ_FROM_PTR(&mp_builtin_divmod_obj), mp_obj_new_str("abc", 3), mp_obj_new_str("abc", 3)); + + // mp_obj_int_get_uint_checked with non-negative small-int + mp_printf(&mp_plat_print, "%d\n", (int)mp_obj_int_get_uint_checked(MP_OBJ_NEW_SMALL_INT(1))); + + // mp_obj_int_get_uint_checked with non-negative big-int + mp_printf(&mp_plat_print, "%d\n", (int)mp_obj_int_get_uint_checked(mp_obj_new_int_from_ll(2))); + + // mp_obj_int_get_uint_checked with negative small-int (should raise exception) + nlr_buf_t nlr; + if (nlr_push(&nlr) == 0) { + mp_obj_int_get_uint_checked(MP_OBJ_NEW_SMALL_INT(-1)); + nlr_pop(); + } else { + mp_obj_print_exception(&mp_plat_print, MP_OBJ_FROM_PTR(nlr.ret_val)); + } + + // mp_obj_int_get_uint_checked with negative big-int (should raise exception) + if (nlr_push(&nlr) == 0) { + mp_obj_int_get_uint_checked(mp_obj_new_int_from_ll(-2)); + nlr_pop(); + } else { + mp_obj_print_exception(&mp_plat_print, MP_OBJ_FROM_PTR(nlr.ret_val)); + } } // warning |