From a5f470eb10201dc75af2ca8e8854b5d5b032c54f Mon Sep 17 00:00:00 2001 From: Victor Zverovich Date: Sun, 25 Aug 2019 06:38:41 -0700 Subject: [PATCH] Test and fix compiled format_to_n and formatted_size --- include/fmt/compile.h | 9 ++++----- test/compile-test.cc | 21 ++++++++++++--------- 2 files changed, 16 insertions(+), 14 deletions(-) diff --git a/include/fmt/compile.h b/include/fmt/compile.h index 194c86d2..6b12a50f 100644 --- a/include/fmt/compile.h +++ b/include/fmt/compile.h @@ -553,16 +553,15 @@ format_to_n_result format_to_n(OutputIt out, size_t n, const CompiledFormat& cf, const Args&... args) { auto it = - cf.format_to(internal::truncating_iterator(out, n), args...); + format_to(internal::truncating_iterator(out, n), cf, args...); return {it.base(), it.count()}; } template std::size_t formatted_size(const CompiledFormat& cf, const Args&... args) { - return cf - .format_to( - internal::counting_iterator(), - args...) + return fmt::format_to( + internal::counting_iterator(), + cf, args...) .count(); } diff --git a/test/compile-test.cc b/test/compile-test.cc index 61c57f1f..a1cc59cb 100644 --- a/test/compile-test.cc +++ b/test/compile-test.cc @@ -505,13 +505,16 @@ TEST(CompileTest, FormatToIterator) { EXPECT_EQ(L"42", ws); } -TEST(CompileTest, FormatToBackInserter) { - std::string s; - const auto prepared = fmt::compile("4{}"); - fmt::format_to(std::back_inserter(s), prepared, 2); - EXPECT_EQ("42", s); - std::wstring ws; - const auto wprepared = fmt::compile(L"4{}"); - fmt::format_to(std::back_inserter(ws), wprepared, 2); - EXPECT_EQ(L"42", ws); +TEST(CompileTest, FormatToN) { + char buf[5]; + auto f = fmt::compile("{:10}"); + auto result = fmt::format_to_n(buf, 5, f, 42); + EXPECT_EQ(result.size, 10); + EXPECT_EQ(result.out, buf + 5); + EXPECT_EQ(fmt::string_view(buf, 5), " "); +} + +TEST(CompileTest, FormattedSize) { + auto f = fmt::compile("{:10}"); + EXPECT_EQ(fmt::formatted_size(f, 42), 10); }