mirror of
https://github.com/ToruNiina/toml11.git
synced 2024-11-22 04:20:06 +00:00
test: add test for auto-generated conversion
This commit is contained in:
parent
88882b523f
commit
bfae1ab86c
@ -545,3 +545,84 @@ BOOST_AUTO_TEST_CASE(test_recursive_conversion)
|
||||
|
||||
}
|
||||
|
||||
// ===========================================================================
|
||||
|
||||
namespace extlib3
|
||||
{
|
||||
struct foo
|
||||
{
|
||||
int a;
|
||||
std::string b;
|
||||
};
|
||||
struct bar
|
||||
{
|
||||
int a;
|
||||
std::string b;
|
||||
foo f;
|
||||
};
|
||||
|
||||
} // extlib3
|
||||
|
||||
TOML11_DEFINE_CONVERSION_NON_INTRUSIVE(extlib3::foo, a, b)
|
||||
TOML11_DEFINE_CONVERSION_NON_INTRUSIVE(extlib3::bar, a, b, f)
|
||||
|
||||
BOOST_AUTO_TEST_CASE(test_conversion_via_macro)
|
||||
{
|
||||
{
|
||||
const toml::value v{{"a", 42}, {"b", "baz"}};
|
||||
|
||||
const auto foo = toml::get<extlib3::foo>(v);
|
||||
BOOST_TEST(foo.a == 42);
|
||||
BOOST_TEST(foo.b == "baz");
|
||||
|
||||
const toml::value v2(foo);
|
||||
BOOST_TEST(v2 == v);
|
||||
}
|
||||
{
|
||||
const toml::basic_value<toml::discard_comments, std::map, std::deque> v{
|
||||
{"a", 42}, {"b", "baz"}
|
||||
};
|
||||
|
||||
const auto foo = toml::get<extlib3::foo>(v);
|
||||
BOOST_TEST(foo.a == 42);
|
||||
BOOST_TEST(foo.b == "baz");
|
||||
|
||||
const toml::basic_value<toml::discard_comments, std::map, std::deque> v2(foo);
|
||||
BOOST_TEST(v2 == v);
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
|
||||
{
|
||||
const toml::value v{
|
||||
{"a", 42},
|
||||
{"b", "bar.b"},
|
||||
{"f", toml::table{{"a", 42}, {"b", "foo.b"}}}
|
||||
};
|
||||
|
||||
const auto bar = toml::get<extlib3::bar>(v);
|
||||
BOOST_TEST(bar.a == 42);
|
||||
BOOST_TEST(bar.b == "bar.b");
|
||||
BOOST_TEST(bar.f.a == 42);
|
||||
BOOST_TEST(bar.f.b == "foo.b");
|
||||
|
||||
const toml::value v2(bar);
|
||||
BOOST_TEST(v2 == v);
|
||||
}
|
||||
{
|
||||
const toml::basic_value<toml::discard_comments, std::map, std::deque> v{
|
||||
{"a", 42},
|
||||
{"b", "bar.b"},
|
||||
{"f", toml::table{{"a", 42}, {"b", "foo.b"}}}
|
||||
};
|
||||
|
||||
const auto bar = toml::get<extlib3::bar>(v);
|
||||
BOOST_TEST(bar.a == 42);
|
||||
BOOST_TEST(bar.b == "bar.b");
|
||||
BOOST_TEST(bar.f.a == 42);
|
||||
BOOST_TEST(bar.f.b == "foo.b");
|
||||
|
||||
const toml::basic_value<toml::discard_comments, std::map, std::deque> v2(bar);
|
||||
BOOST_TEST(v2 == v);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user