libcruft-util/test/format.cpp
Danny Robson 9248c2f379 format: test invalid specifier with unused specifier
we are using '!' as a specifier now, so don't test invalid specifiers
with this value...
2016-02-03 12:02:56 +11:00

30 lines
863 B
C++

#include "format.hpp"
#include "tap.hpp"
int
main (void)
{
using namespace std::string_literals;
util::TAP::logger tap;
tap.expect_eq (util::format::render ("identity"), "identity"s, "identity literal");
tap.expect_eq (util::format::render ("%s", "identity"s), "identity"s, "identity string substitution");
tap.expect_eq (util::format::render ("%s", "identity" ), "identity"s, "identity char[] substitution");
tap.expect_throw<util::format::missing_error> ([] (void) {
util::format::render ("%s");
}, "missing value");
tap.expect_throw<util::format::format_error> ([] (void) {
util::format::render ("%<", 42);
}, "invalid specifier");
tap.expect_throw<util::format::format_error> ([] (void) {
util::format::render ("%", 42);
}, "truncated specifier");
return tap.status ();
}