add test for template into_toml

This commit is contained in:
xep 2024-07-20 11:15:30 +08:00
parent b853860a8f
commit ce42e78e3c

View File

@ -49,6 +49,25 @@ struct foobar
int a;
std::string b;
};
struct corge
{
int a;
std::string b;
void from_toml(const toml::value& v)
{
this->a = toml::find<int>(v, "a");
this->b = toml::find<std::string>(v, "b");
return ;
}
template <typename TC>
toml::basic_value<TC> into_toml() const
{
return toml::basic_value<TC>(typename toml::basic_value<TC>::table_type{{"a", this->a}, {"b", this->b}});
}
};
} // extlib
namespace toml
@ -215,6 +234,19 @@ TEST_CASE("test_conversion_by_member_methods")
CHECK(v == v2);
}
{
const toml::value v(toml::table{{"a", 42}, {"b", "baz"}});
const auto corge = toml::get<extlib::corge>(v);
CHECK_EQ(corge.a, 42);
CHECK_EQ(corge.b, "baz");
const toml::value v2(corge);
CHECK_EQ(v, v2);
}
{
const toml::ordered_value v(toml::ordered_table{{"a", 42}, {"b", "baz"}});