format/quoted: avoid vformat for tests

This commit is contained in:
Danny Robson 2023-11-19 09:38:41 +10:00
parent 2f2dfd1423
commit 6f17da5e59

View File

@ -2,28 +2,27 @@
#include <cruft/util/tap.hpp> #include <cruft/util/tap.hpp>
#include <fmt/format.h>
int main () int main ()
{ {
static constexpr struct { static constexpr struct {
std::string_view format;
std::string_view inner; std::string_view inner;
std::string_view result; std::string_view result;
std::string_view message; std::string_view message;
} TESTS[] = { } TESTS[] = {
{ "{}", "Foo", R"("Foo")", "Simple word" }, { "Foo", R"("Foo")", "Simple word" },
{ "{}", "F\"oo", R"("F\"oo")", "Embedded delim" }, { "F\"oo", R"("F\"oo")", "Embedded delim" },
{ "{}", "F\\oo", R"("F\\oo")", "Embedded escape" }, { "F\\oo", R"("F\\oo")", "Embedded escape" },
}; };
cruft::TAP::logger tap; cruft::TAP::logger tap;
for (auto const &t: TESTS) { for (auto const &t: TESTS) {
auto const result = fmt::vformat ( auto const result = fmt::format (
t.format, "{}",
fmt::make_format_args (
cruft::format::quoted (t.inner) cruft::format::quoted (t.inner)
)
); );
tap.expect_eq (result, t.result, "quoted format: {}", t.message); tap.expect_eq (result, t.result, "quoted format: {}", t.message);
} }