7#include <boost/test/unit_test.hpp>
13BOOST_AUTO_TEST_SUITE(util_string_tests)
15template <
unsigned NumArgs>
18 std::apply([&](
auto...
args) {
20 }, std::array<int, NumArgs>{});
25template <
unsigned NumArgs>
37template <
unsigned WrongNumArgs>
40 BOOST_CHECK_EXCEPTION(CheckNumFormatSpecifiers<WrongNumArgs>(wrong_fmt),
const char*,
HasReason{error});
55 PassFmt<1>(
"%1$s%1$s");
57 PassFmt<2>(
"%2$s 4$s %2$s");
58 PassFmt<129>(
"%129$s 999$s %2$s");
79 PassFmt<3>(
"%2$*3$d");
80 PassFmt<3>(
"%2$*3$.9d");
81 PassFmt<3>(
"%2$.*3$d");
82 PassFmt<3>(
"%2$9.*3$d");
83 PassFmt<3>(
"%2$+9.*3$d");
84 PassFmt<4>(
"%3$*2$.*4$f");
87 PassFmt<3>(
"'%- 0+*.*f'");
88 PassFmt<3>(
"'%1$- 0+*3$.*2$f'");
90 auto err_mix{
"Format specifiers must be all positional or all non-positional!"};
91 FailFmtWithError<1>(
"%s%1$s", err_mix);
92 FailFmtWithError<2>(
"%2$*d", err_mix);
93 FailFmtWithError<2>(
"%*2$d", err_mix);
94 FailFmtWithError<2>(
"%.*3$d", err_mix);
95 FailFmtWithError<2>(
"%2$.*d", err_mix);
97 auto err_num{
"Format specifier count must match the argument count!"};
98 FailFmtWithError<1>(
"", err_num);
99 FailFmtWithError<0>(
"%s", err_num);
100 FailFmtWithError<2>(
"%s", err_num);
101 FailFmtWithError<0>(
"%1$s", err_num);
102 FailFmtWithError<2>(
"%1$s", err_num);
103 FailFmtWithError<1>(
"%*c", err_num);
105 auto err_0_pos{
"Positional format specifier must have position of at least 1"};
106 FailFmtWithError<1>(
"%$s", err_0_pos);
107 FailFmtWithError<1>(
"%$", err_0_pos);
108 FailFmtWithError<0>(
"%0$", err_0_pos);
109 FailFmtWithError<0>(
"%0$s", err_0_pos);
110 FailFmtWithError<2>(
"%2$*$d", err_0_pos);
111 FailFmtWithError<2>(
"%2$*0$d", err_0_pos);
112 FailFmtWithError<3>(
"%3$*2$.*$f", err_0_pos);
113 FailFmtWithError<3>(
"%3$*2$.*0$f", err_0_pos);
115 auto err_term{
"Format specifier incorrectly terminated by end of string"};
116 FailFmtWithError<1>(
"%", err_term);
117 FailFmtWithError<1>(
"%9", err_term);
118 FailFmtWithError<1>(
"%9.", err_term);
119 FailFmtWithError<1>(
"%9.9", err_term);
120 FailFmtWithError<1>(
"%*", err_term);
121 FailFmtWithError<1>(
"%+*", err_term);
122 FailFmtWithError<1>(
"%.*", err_term);
123 FailFmtWithError<1>(
"%9.*", err_term);
124 FailFmtWithError<1>(
"%1$", err_term);
125 FailFmtWithError<1>(
"%1$9", err_term);
126 FailFmtWithError<2>(
"%1$*2$", err_term);
127 FailFmtWithError<2>(
"%1$.*2$", err_term);
128 FailFmtWithError<2>(
"%1$9.*2$", err_term);
133 HasReason{
"tinyformat: %n conversion spec not supported"});
135 HasReason{
"tinyformat: Cannot convert from argument type to integer for use as variable width or precision"});
137 HasReason{
"tinyformat: Cannot convert from argument type to integer for use as variable width or precision"});
144 HasReason{
"tinyformat: Not enough conversion specifiers in format string"});
146 HasReason{
"tinyformat: Too many conversion specifiers in format string"});
BOOST_CHECK_EXCEPTION predicates to check the specific validation error.
BOOST_AUTO_TEST_SUITE_END()
static constexpr void CheckNumFormatSpecifiers(const char *str)
#define BOOST_CHECK_NO_THROW(stmt)
BOOST_AUTO_TEST_CASE(ConstevalFormatString_NumSpec)
void TfmFormatZeroes(const std::string &fmt)
void PassFmt(ConstevalFormatString< NumArgs > fmt)
void FailFmtWithError(const char *wrong_fmt, std::string_view error)