mirror of
https://github.com/ToruNiina/toml11.git
synced 2025-09-17 17:58:09 +08:00
add test for template into_toml
This commit is contained in:
@@ -49,6 +49,25 @@ struct foobar
|
|||||||
int a;
|
int a;
|
||||||
std::string b;
|
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
|
} // extlib
|
||||||
|
|
||||||
namespace toml
|
namespace toml
|
||||||
@@ -215,6 +234,19 @@ TEST_CASE("test_conversion_by_member_methods")
|
|||||||
CHECK(v == v2);
|
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"}});
|
const toml::ordered_value v(toml::ordered_table{{"a", 42}, {"b", "baz"}});
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user