mirror of
https://github.com/ToruNiina/toml11.git
synced 2024-11-08 13:50:06 +00:00
fix array_of_table assignments
This commit is contained in:
parent
96429e3e08
commit
f52b78010c
@ -96,11 +96,34 @@ BOOST_AUTO_TEST_CASE(test_fruit)
|
||||
}
|
||||
}
|
||||
|
||||
// BOOST_AUTO_TEST_CASE(test_hard_example)
|
||||
// {
|
||||
//
|
||||
// }
|
||||
//
|
||||
BOOST_AUTO_TEST_CASE(test_hard_example)
|
||||
{
|
||||
const auto data = toml::parse("toml/tests/hard_example.toml");
|
||||
const auto the = toml::get<toml::Table>(data.at("the"));
|
||||
BOOST_CHECK_EQUAL(toml::get<std::string>(the.at("test_string")),
|
||||
"You'll hate me after this - #");
|
||||
|
||||
const auto hard = toml::get<toml::Table>(the.at("hard"));
|
||||
const std::vector<std::string> expected_the_hard_test_array{"] ", " # "};
|
||||
BOOST_CHECK(toml::get<std::vector<std::string>>(hard.at("test_array")) ==
|
||||
expected_the_hard_test_array);
|
||||
const std::vector<std::string> expected_the_hard_test_array2{
|
||||
"Test #11 ]proved that", "Experiment #9 was a success"};
|
||||
BOOST_CHECK(toml::get<std::vector<std::string>>(hard.at("test_array2")) ==
|
||||
expected_the_hard_test_array2);
|
||||
BOOST_CHECK_EQUAL(toml::get<std::string>(hard.at("another_test_string")),
|
||||
" Same thing, but with a string #");
|
||||
BOOST_CHECK_EQUAL(toml::get<std::string>(hard.at("harder_test_string")),
|
||||
" And when \"'s are in the string, along with # \"");
|
||||
|
||||
const auto bit = toml::get<toml::Table>(hard.at("bit#"));
|
||||
BOOST_CHECK_EQUAL(toml::get<std::string>(bit.at("what?")),
|
||||
"You don't think some user won't do that?");
|
||||
const std::vector<std::string> expected_multi_line_array{"]"};
|
||||
BOOST_CHECK(toml::get<std::vector<std::string>>(bit.at("multi_line_array")) ==
|
||||
expected_multi_line_array);
|
||||
}
|
||||
|
||||
// BOOST_AUTO_TEST_CASE(test_hard_example_unicode)
|
||||
// {
|
||||
// ;
|
||||
|
@ -944,12 +944,27 @@ struct parse_data
|
||||
}
|
||||
|
||||
if(data.count(*iter) == 0)
|
||||
{
|
||||
data.emplace(*iter, toml::Table());
|
||||
else if(data[*iter].type() != value_t::Table)
|
||||
throw syntax_error("duplicate key: " + *iter);
|
||||
|
||||
return push_table(data[*iter].template cast<value_t::Table>(),
|
||||
std::move(v), std::next(iter), end);
|
||||
return push_table(data[*iter].template cast<value_t::Table>(),
|
||||
std::move(v), std::next(iter), end);
|
||||
}
|
||||
else if(data[*iter].type() == value_t::Table)
|
||||
{
|
||||
return push_table(data[*iter].template cast<value_t::Table>(),
|
||||
std::move(v), std::next(iter), end);
|
||||
}
|
||||
else if(data[*iter].type() == value_t::Array)
|
||||
{
|
||||
auto& ar = data[*iter].template cast<value_t::Array>();
|
||||
if(ar.empty()) ar.emplace_back(toml::Table{});
|
||||
if(ar.back().type() != value_t::Table)
|
||||
throw syntax_error("assign table into array having non-table type: " + *iter);
|
||||
return push_table(ar.back().template cast<value_t::Table>(),
|
||||
std::move(v), std::next(iter), end);
|
||||
}
|
||||
else
|
||||
throw syntax_error("assign table into not table: " + *iter);
|
||||
}
|
||||
|
||||
template<typename Iterator, class = typename std::enable_if<
|
||||
@ -971,12 +986,27 @@ struct parse_data
|
||||
}
|
||||
|
||||
if(data.count(*iter) == 0)
|
||||
{
|
||||
data.emplace(*iter, toml::Table());
|
||||
else if(data[*iter].type() != value_t::Table)
|
||||
throw syntax_error("duplicate key: " + *iter);
|
||||
|
||||
return push_array_of_table(data[*iter].template cast<value_t::Table>(),
|
||||
std::move(v), std::next(iter), end);
|
||||
return push_array_of_table(data[*iter].template cast<value_t::Table>(),
|
||||
std::move(v), std::next(iter), end);
|
||||
}
|
||||
else if(data[*iter].type() == value_t::Table)
|
||||
{
|
||||
return push_array_of_table(data[*iter].template cast<value_t::Table>(),
|
||||
std::move(v), std::next(iter), end);
|
||||
}
|
||||
else if(data[*iter].type() == value_t::Array)
|
||||
{
|
||||
auto& ar = data[*iter].template cast<value_t::Array>();
|
||||
if(ar.empty()) ar.emplace_back(toml::Table{});
|
||||
if(ar.back().type() != value_t::Table)
|
||||
throw syntax_error("assign table into array having non-table type: " + *iter);
|
||||
return push_array_of_table(ar.back().template cast<value_t::Table>(),
|
||||
std::move(v), std::next(iter), end);
|
||||
}
|
||||
else
|
||||
throw syntax_error("assign array of table into not table: " + *iter);
|
||||
}
|
||||
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user