diff --git a/tests/test_extended_conversions.cpp b/tests/test_extended_conversions.cpp index 428f477..0ad09c3 100644 --- a/tests/test_extended_conversions.cpp +++ b/tests/test_extended_conversions.cpp @@ -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(v); + BOOST_TEST(foo.a == 42); + BOOST_TEST(foo.b == "baz"); + + const toml::value v2(foo); + BOOST_TEST(v2 == v); + } + { + const toml::basic_value v{ + {"a", 42}, {"b", "baz"} + }; + + const auto foo = toml::get(v); + BOOST_TEST(foo.a == 42); + BOOST_TEST(foo.b == "baz"); + + const toml::basic_value 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(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 v{ + {"a", 42}, + {"b", "bar.b"}, + {"f", toml::table{{"a", 42}, {"b", "foo.b"}}} + }; + + const auto bar = toml::get(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 v2(bar); + BOOST_TEST(v2 == v); + } +}