mirror of
https://github.com/fmtlib/fmt.git
synced 2024-11-14 23:11:05 +00:00
Report error on missing named argument (#1796)
This commit is contained in:
parent
d82fdcc9e2
commit
21c8b5c142
@ -1913,7 +1913,7 @@ template <typename Context> class basic_format_args {
|
||||
}
|
||||
|
||||
template <typename Char> int get_id(basic_string_view<Char> name) const {
|
||||
if (!has_named_args()) return {};
|
||||
if (!has_named_args()) return -1;
|
||||
const auto& named_args =
|
||||
(is_packed() ? values_[-1] : args_[-1].value_).named_args;
|
||||
for (size_t i = 0; i < named_args.size; ++i) {
|
||||
|
@ -543,7 +543,6 @@ TEST(FormatterTest, ManyArgs) {
|
||||
TEST(FormatterTest, NamedArg) {
|
||||
EXPECT_EQ("1/a/A", format("{_1}/{a_}/{A_}", fmt::arg("a_", 'a'),
|
||||
fmt::arg("A_", "A"), fmt::arg("_1", 1)));
|
||||
EXPECT_THROW_MSG(format("{a}"), format_error, "argument not found");
|
||||
EXPECT_EQ(" -42", format("{0:{width}}", -42, fmt::arg("width", 4)));
|
||||
EXPECT_EQ("st", format("{0:.{precision}}", "str", fmt::arg("precision", 2)));
|
||||
EXPECT_EQ("1 2", format("{} {two}", 1, fmt::arg("two", 2)));
|
||||
@ -553,6 +552,8 @@ TEST(FormatterTest, NamedArg) {
|
||||
fmt::arg("i", 0), fmt::arg("j", 0), fmt::arg("k", 0),
|
||||
fmt::arg("l", 0), fmt::arg("m", 0), fmt::arg("n", 0),
|
||||
fmt::arg("o", 0), fmt::arg("p", 0)));
|
||||
EXPECT_THROW_MSG(format("{a}"), format_error, "argument not found");
|
||||
EXPECT_THROW_MSG(format("{a}", 42), format_error, "argument not found");
|
||||
}
|
||||
|
||||
TEST(FormatterTest, AutoArgIndex) {
|
||||
|
Loading…
Reference in New Issue
Block a user