Skip to content

Commit

Permalink
Issue #76: Fix printing negative and positive numbers in sequence (#77)
Browse files Browse the repository at this point in the history
* Issue #76: Add failing test

* Update test

* Attempt to fix failing test
  • Loading branch information
shreyasbharath authored May 1, 2020
1 parent 6bb53ac commit 1d095eb
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
1 change: 1 addition & 0 deletions nanoprintf.h
Original file line number Diff line number Diff line change
Expand Up @@ -850,6 +850,7 @@ int npf_vpprintf(npf_putc pc, void *pc_ctx, char const *format, va_list vlist) {
case NPF_FMT_SPEC_CONV_OCTAL: /* 'o' */
case NPF_FMT_SPEC_CONV_HEX_INT: /* 'x', 'X' */
case NPF_FMT_SPEC_CONV_UNSIGNED_INT: { /* 'u' */
sign = 0;
unsigned const base =
(fs.conv_spec == NPF_FMT_SPEC_CONV_OCTAL)
? 8
Expand Down
5 changes: 5 additions & 0 deletions unit_tests/test_snprintf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,8 @@ TEST(npf_snprintf, PrintsStringToBuf) {
TEST(npf_snprintf, ReturnsLenIfBufIsNull) {
CHECK_EQUAL(11, npf_snprintf(nullptr, 0, "hello %s", "world"));
}

TEST(npf_snprintf, PrintingPositiveAndNegativeNumbers) {
npf_snprintf(buf, sizeof(buf), "%i %u", -100, 100u);
STRCMP_EQUAL("-100 100", buf);
}

0 comments on commit 1d095eb

Please sign in to comment.