2015-05-08 00:19:56 +01:00
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
#include "py/obj.h"
|
|
|
|
#include "py/runtime.h"
|
|
|
|
#include "py/repl.h"
|
2015-10-01 18:49:37 +01:00
|
|
|
#include "py/mpz.h"
|
2015-05-08 00:19:56 +01:00
|
|
|
|
|
|
|
#if defined(MICROPY_UNIX_COVERAGE)
|
|
|
|
|
|
|
|
// function to run extra tests for things that can't be checked by scripts
|
2015-05-08 09:18:38 +01:00
|
|
|
STATIC mp_obj_t extra_coverage(void) {
|
2015-05-28 15:25:07 +01:00
|
|
|
// mp_printf (used by ports that don't have a native printf)
|
|
|
|
{
|
|
|
|
printf("# mp_printf\n");
|
|
|
|
mp_printf(&mp_plat_print, "%"); // nothing after percent
|
|
|
|
mp_printf(&mp_plat_print, "%d %+d % d\n", -123, 123, 123); // sign
|
|
|
|
mp_printf(&mp_plat_print, "%05d\n", -123); // negative number with zero padding
|
|
|
|
mp_printf(&mp_plat_print, "%ld\n", 123); // long
|
|
|
|
mp_printf(&mp_plat_print, "%X\n", 0x1abcdef); // capital hex
|
|
|
|
mp_printf(&mp_plat_print, "%.2s %.3s\n", "abc", "abc"); // fixed string precision
|
|
|
|
mp_printf(&mp_plat_print, "%.*s\n", -1, "abc"); // negative string precision
|
|
|
|
mp_printf(&mp_plat_print, "%b %b\n", 0, 1); // bools
|
|
|
|
mp_printf(&mp_plat_print, "%s\n", NULL); // null string
|
|
|
|
mp_printf(&mp_plat_print, "%t\n"); // non-format char
|
|
|
|
}
|
|
|
|
|
2015-05-12 23:34:10 +01:00
|
|
|
// vstr
|
|
|
|
{
|
|
|
|
printf("# vstr\n");
|
|
|
|
vstr_t *vstr = vstr_new_size(16);
|
|
|
|
vstr_hint_size(vstr, 32);
|
|
|
|
vstr_add_str(vstr, "ts");
|
|
|
|
vstr_ins_byte(vstr, 1, 'e');
|
|
|
|
vstr_ins_char(vstr, 3, 't');
|
|
|
|
vstr_ins_char(vstr, 10, 's');
|
|
|
|
printf("%.*s\n", (int)vstr->len, vstr->buf);
|
|
|
|
|
|
|
|
vstr_cut_head_bytes(vstr, 2);
|
|
|
|
printf("%.*s\n", (int)vstr->len, vstr->buf);
|
|
|
|
|
|
|
|
vstr_cut_tail_bytes(vstr, 10);
|
|
|
|
printf("%.*s\n", (int)vstr->len, vstr->buf);
|
|
|
|
|
|
|
|
vstr_printf(vstr, "t%cst", 'e');
|
|
|
|
printf("%.*s\n", (int)vstr->len, vstr->buf);
|
|
|
|
|
|
|
|
vstr_cut_out_bytes(vstr, 3, 10);
|
|
|
|
printf("%.*s\n", (int)vstr->len, vstr->buf);
|
|
|
|
|
|
|
|
VSTR_FIXED(fix, 4);
|
|
|
|
vstr_add_str(&fix, "large");
|
|
|
|
printf("%.*s\n", (int)fix.len, fix.buf);
|
|
|
|
}
|
|
|
|
|
2015-05-08 00:19:56 +01:00
|
|
|
// repl autocomplete
|
|
|
|
{
|
2015-05-12 23:34:10 +01:00
|
|
|
printf("# repl\n");
|
|
|
|
|
2015-05-08 00:19:56 +01:00
|
|
|
const char *str;
|
2015-05-08 09:18:38 +01:00
|
|
|
mp_uint_t len = mp_repl_autocomplete("__n", 3, &mp_plat_print, &str);
|
2015-05-08 00:19:56 +01:00
|
|
|
printf("%.*s\n", (int)len, str);
|
|
|
|
|
|
|
|
mp_store_global(MP_QSTR_sys, mp_import_name(MP_QSTR_sys, mp_const_none, MP_OBJ_NEW_SMALL_INT(0)));
|
|
|
|
mp_repl_autocomplete("sys.", 4, &mp_plat_print, &str);
|
|
|
|
len = mp_repl_autocomplete("sys.impl", 8, &mp_plat_print, &str);
|
|
|
|
printf("%.*s\n", (int)len, str);
|
|
|
|
}
|
2015-05-08 09:18:38 +01:00
|
|
|
|
2015-05-12 23:34:10 +01:00
|
|
|
// attrtuple
|
|
|
|
{
|
|
|
|
printf("# attrtuple\n");
|
|
|
|
|
|
|
|
static const qstr fields[] = {MP_QSTR_start, MP_QSTR_stop, MP_QSTR_step};
|
|
|
|
static const mp_obj_t items[] = {MP_OBJ_NEW_SMALL_INT(1), MP_OBJ_NEW_SMALL_INT(2), MP_OBJ_NEW_SMALL_INT(3)};
|
|
|
|
mp_obj_print_helper(&mp_plat_print, mp_obj_new_attrtuple(fields, 3, items), PRINT_REPR);
|
|
|
|
printf("\n");
|
|
|
|
}
|
|
|
|
|
2015-09-03 23:06:18 +01:00
|
|
|
// str
|
|
|
|
{
|
|
|
|
printf("# str\n");
|
|
|
|
|
|
|
|
// intern string
|
|
|
|
printf("%d\n", MP_OBJ_IS_QSTR(mp_obj_str_intern(mp_obj_new_str("intern me", 9, false))));
|
|
|
|
}
|
|
|
|
|
2015-10-01 18:49:37 +01:00
|
|
|
// mpz
|
|
|
|
{
|
|
|
|
printf("# mpz\n");
|
|
|
|
|
|
|
|
mp_uint_t value;
|
|
|
|
mpz_t mpz;
|
|
|
|
mpz_init_zero(&mpz);
|
|
|
|
|
|
|
|
// mpz_as_uint_checked, with success
|
|
|
|
mpz_set_from_int(&mpz, 12345678);
|
|
|
|
printf("%d\n", mpz_as_uint_checked(&mpz, &value));
|
|
|
|
printf("%d\n", (int)value);
|
|
|
|
|
|
|
|
// mpz_as_uint_checked, with negative arg
|
|
|
|
mpz_set_from_int(&mpz, -1);
|
|
|
|
printf("%d\n", mpz_as_uint_checked(&mpz, &value));
|
|
|
|
|
|
|
|
// mpz_as_uint_checked, with overflowing arg
|
|
|
|
mpz_set_from_int(&mpz, 1);
|
|
|
|
mpz_shl_inpl(&mpz, &mpz, 70);
|
|
|
|
printf("%d\n", mpz_as_uint_checked(&mpz, &value));
|
|
|
|
}
|
|
|
|
|
2015-05-08 09:18:38 +01:00
|
|
|
return mp_const_none;
|
2015-05-08 00:19:56 +01:00
|
|
|
}
|
2015-05-08 09:18:38 +01:00
|
|
|
MP_DEFINE_CONST_FUN_OBJ_0(extra_coverage_obj, extra_coverage);
|
2015-05-08 00:19:56 +01:00
|
|
|
|
|
|
|
#endif
|