mirror of
https://github.com/ToruNiina/toml11.git
synced 2025-09-17 09:08:08 +08:00
test: add basic_value type to serialization tests
This commit is contained in:
@@ -19,15 +19,38 @@ BOOST_AUTO_TEST_CASE(test_example)
|
||||
|
||||
auto serialized = toml::parse("tmp1.toml");
|
||||
{
|
||||
auto& owner = toml::find<toml::table>(serialized, "owner");
|
||||
auto& bio = toml::get<std::string>(owner.at("bio"));
|
||||
auto& owner = toml::find(serialized, "owner");
|
||||
auto& bio = toml::find<std::string>(owner, "bio");
|
||||
const auto CR = std::find(bio.begin(), bio.end(), '\r');
|
||||
if(CR != bio.end())
|
||||
{
|
||||
bio.erase(CR);
|
||||
}
|
||||
}
|
||||
BOOST_CHECK(data == serialized);
|
||||
BOOST_TEST(data == serialized);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(test_example_map_dq)
|
||||
{
|
||||
const auto data = toml::parse<toml::discard_comments, std::map, std::deque>(
|
||||
"toml/tests/example.toml");
|
||||
{
|
||||
std::ofstream ofs("tmp1.toml");
|
||||
ofs << std::setw(80) << data;
|
||||
}
|
||||
|
||||
auto serialized = toml::parse<toml::discard_comments, std::map, std::deque>(
|
||||
"tmp1.toml");
|
||||
{
|
||||
auto& owner = toml::find(serialized, "owner");
|
||||
auto& bio = toml::find<std::string>(owner, "bio");
|
||||
const auto CR = std::find(bio.begin(), bio.end(), '\r');
|
||||
if(CR != bio.end())
|
||||
{
|
||||
bio.erase(CR);
|
||||
}
|
||||
}
|
||||
BOOST_TEST(data == serialized);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(test_example_with_comment)
|
||||
@@ -40,15 +63,42 @@ BOOST_AUTO_TEST_CASE(test_example_with_comment)
|
||||
|
||||
auto serialized = toml::parse<toml::preserve_comments>("tmp1_com.toml");
|
||||
{
|
||||
auto& owner = toml::find<typename decltype(serialized)::table_type>(serialized, "owner");
|
||||
auto& bio = toml::get<std::string>(owner.at("bio"));
|
||||
auto& owner = toml::find(serialized, "owner");
|
||||
auto& bio = toml::find<std::string>(owner, "bio");
|
||||
const auto CR = std::find(bio.begin(), bio.end(), '\r');
|
||||
if(CR != bio.end())
|
||||
{
|
||||
bio.erase(CR);
|
||||
}
|
||||
}
|
||||
BOOST_CHECK(data == serialized);
|
||||
BOOST_TEST(data == serialized);
|
||||
{
|
||||
std::ofstream ofs("tmp1_com1.toml");
|
||||
ofs << std::setw(80) << serialized;
|
||||
}
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(test_example_with_comment_map_dq)
|
||||
{
|
||||
const auto data = toml::parse<toml::preserve_comments, std::map, std::deque>(
|
||||
"toml/tests/example.toml");
|
||||
{
|
||||
std::ofstream ofs("tmp1_com.toml");
|
||||
ofs << std::setw(80) << data;
|
||||
}
|
||||
|
||||
auto serialized = toml::parse<toml::preserve_comments, std::map, std::deque>(
|
||||
"tmp1_com.toml");
|
||||
{
|
||||
auto& owner = toml::find(serialized, "owner");
|
||||
auto& bio = toml::find<std::string>(owner, "bio");
|
||||
const auto CR = std::find(bio.begin(), bio.end(), '\r');
|
||||
if(CR != bio.end())
|
||||
{
|
||||
bio.erase(CR);
|
||||
}
|
||||
}
|
||||
BOOST_TEST(data == serialized);
|
||||
{
|
||||
std::ofstream ofs("tmp1_com1.toml");
|
||||
ofs << std::setw(80) << serialized;
|
||||
@@ -63,7 +113,20 @@ BOOST_AUTO_TEST_CASE(test_fruit)
|
||||
ofs << std::setw(80) << data;
|
||||
}
|
||||
const auto serialized = toml::parse("tmp2.toml");
|
||||
BOOST_CHECK(data == serialized);
|
||||
BOOST_TEST(data == serialized);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(test_fruit_map_dq)
|
||||
{
|
||||
const auto data = toml::parse<toml::discard_comments, std::map, std::deque>(
|
||||
"toml/tests/fruit.toml");
|
||||
{
|
||||
std::ofstream ofs("tmp2.toml");
|
||||
ofs << std::setw(80) << data;
|
||||
}
|
||||
const auto serialized = toml::parse<toml::discard_comments, std::map, std::deque>(
|
||||
"tmp2.toml");
|
||||
BOOST_TEST(data == serialized);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(test_fruit_with_comments)
|
||||
@@ -74,7 +137,19 @@ BOOST_AUTO_TEST_CASE(test_fruit_with_comments)
|
||||
ofs << std::setw(80) << data;
|
||||
}
|
||||
const auto serialized = toml::parse<toml::preserve_comments>("tmp2_com.toml");
|
||||
BOOST_CHECK(data == serialized);
|
||||
BOOST_TEST(data == serialized);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(test_fruit_with_comments_map_dq)
|
||||
{
|
||||
const auto data = toml::parse<toml::preserve_comments, std::map, std::deque>(
|
||||
"toml/tests/fruit.toml");
|
||||
{
|
||||
std::ofstream ofs("tmp2_com.toml");
|
||||
ofs << std::setw(80) << data;
|
||||
}
|
||||
const auto serialized = toml::parse<toml::preserve_comments, std::map, std::deque>("tmp2_com.toml");
|
||||
BOOST_TEST(data == serialized);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(test_hard_example)
|
||||
@@ -85,20 +160,35 @@ BOOST_AUTO_TEST_CASE(test_hard_example)
|
||||
ofs << std::setw(80) << data;
|
||||
}
|
||||
const auto serialized = toml::parse("tmp3.toml");
|
||||
BOOST_CHECK(data == serialized);
|
||||
BOOST_TEST(data == serialized);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(test_hard_example_map_dq)
|
||||
{
|
||||
const auto data = toml::parse<toml::discard_comments, std::map, std::deque>(
|
||||
"toml/tests/hard_example.toml");
|
||||
{
|
||||
std::ofstream ofs("tmp3.toml");
|
||||
ofs << std::setw(80) << data;
|
||||
}
|
||||
const auto serialized = toml::parse<toml::discard_comments, std::map, std::deque>(
|
||||
"tmp3.toml");
|
||||
BOOST_TEST(data == serialized);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(test_hard_example_with_comment)
|
||||
{
|
||||
const auto data = toml::parse<toml::preserve_comments>("toml/tests/hard_example.toml");
|
||||
const auto data = toml::parse<toml::preserve_comments, std::map, std::deque>(
|
||||
"toml/tests/hard_example.toml");
|
||||
{
|
||||
std::ofstream ofs("tmp3_com.toml");
|
||||
ofs << std::setw(80) << data;
|
||||
}
|
||||
const auto serialized = toml::parse<toml::preserve_comments>("tmp3_com.toml");
|
||||
const auto serialized = toml::parse<toml::preserve_comments, std::map, std::deque>(
|
||||
"tmp3_com.toml");
|
||||
{
|
||||
std::ofstream ofs("tmp3_com1.toml");
|
||||
ofs << std::setw(80) << serialized;
|
||||
}
|
||||
BOOST_CHECK(data == serialized);
|
||||
BOOST_TEST(data == serialized);
|
||||
}
|
||||
|
Reference in New Issue
Block a user