diff --git a/src/core/pp.c b/src/core/pp.c index 253bb9a4..cbf19652 100644 --- a/src/core/pp.c +++ b/src/core/pp.c @@ -463,6 +463,33 @@ static int print_jdn_one(struct pretty *S, Janet x, int depth) { janet_buffer_push_u8(S->buffer, '}'); } break; +#ifdef JANET_INT_TYPES + case JANET_ABSTRACT: { + void *abst = janet_unwrap_abstract(x); + if (janet_abstract_type(abst) == &janet_s64_type) { + janet_buffer_ensure(S->buffer, S->buffer->count + BUFSIZE, 2); + int64_t s64 = janet_unwrap_s64(x); + int count = snprintf((char *)S->buffer->data + S->buffer->count, + BUFSIZE, "%" PRId64 ":s", s64); + if (count < 0) { + return 1; + } + S->buffer->count += count; + } else if (janet_abstract_type(abst) == &janet_u64_type) { + janet_buffer_ensure(S->buffer, S->buffer->count + BUFSIZE, 2); + uint64_t u64 = janet_unwrap_u64(x); + int count = snprintf((char *)S->buffer->data + S->buffer->count, + BUFSIZE, "%" PRIu64 ":u", u64); + if (count < 0) { + return 1; + } + S->buffer->count += count; + } else { + return 1; + } + } + break; +#endif default: return 1; } diff --git a/test/suite-pp.janet b/test/suite-pp.janet index a75ba482..7e84adec 100644 --- a/test/suite-pp.janet +++ b/test/suite-pp.janet @@ -50,7 +50,8 @@ # 5c364e0 (defn check-jdn [x] - (assert (deep= (parse (string/format "%j" x)) x) "round trip jdn")) + (assert (true? (first (protect (deep= (parse (string/format "%j" x)) x)))) + (string/format "round trip jdn: %n" x))) (check-jdn 0) (check-jdn nil) @@ -60,6 +61,13 @@ (check-jdn 12837192371923) (check-jdn "a string") (check-jdn @"a buffer") +# Issue 1899 +(check-jdn -258:s) +(check-jdn 3_141_592:u) + +# Issue 1899 +(assert-error "non-inttype abstract should fail" + (string/format "%j" (peg/compile 1))) # Issue 1737 (assert (deep= "@[]" (string/format "%M" @[])))