Skip to content

Commit

Permalink
vformat_to tests
Browse files Browse the repository at this point in the history
  • Loading branch information
seanmiddleditch committed Jan 15, 2024
1 parent 7123b74 commit 8ca10e7
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion include/nanofmt/format.inl
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ namespace NANOFMT_NS {
template <std::size_t N>
char* vformat_to(char (&dest)[N], format_string format_str, format_args args) {
const detail::vformat_result result =
detail::vformat(format_context{dest, dest + (N - 1 /*NUL*/)}, format_str, args).out();
detail::vformat(dest, dest + (N - 1 /*NUL*/), format_str, args);
*result.pos = '\0';
return result.pos;
}
Expand Down
11 changes: 11 additions & 0 deletions tests/test_format.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,17 @@ TEST_CASE("nanofmt.format.append") {
CHECK(std::strcmp(buffer, "Hello, Worl") == 0);
}

TEST_CASE("nanofmt.vformat.append") {
using namespace NANOFMT_NS;

char buffer[12] = {};
vformat_to(buffer, "{} + {}", make_format_args(1, 2));
char const* const end = vformat_append_to(buffer, " = {}", make_format_args(3));

CHECK((end - buffer) == 9);
CHECK(std::strcmp(buffer, "1 + 2 = 3") == 0);
}

TEST_CASE("nanofmt.format.integers") {
using namespace NANOFMT_NS::test;

Expand Down

0 comments on commit 8ca10e7

Please sign in to comment.