Skip to content

Commit 0d1a52c

Browse files
committed
test: add toml::find for optinal<user-defined>
1 parent 89b376b commit 0d1a52c

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

tests/test_user_defined_conversion.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -735,5 +735,27 @@ TEST_CASE("test_optional_conversion_via_macro")
735735
CHECK(v2 == v);
736736
}
737737
}
738+
739+
TEST_CASE("test_optional_conversion_via_find")
740+
{
741+
{
742+
const toml::value v(toml::table{
743+
{"foo", toml::value(toml::table{{"a", 42}}) }
744+
});
745+
746+
const auto foo = toml::find<extlib4::foo>(v, "foo");
747+
CHECK(foo.a.value() == 42);
748+
CHECK(foo.b == std::nullopt);
749+
}
750+
{
751+
const toml::ordered_value v(toml::ordered_table{
752+
{ "foo", toml::ordered_value(toml::ordered_table{{"b", "baz"}}) }
753+
});
754+
755+
const auto foo = toml::find<extlib4::foo>(v, "foo");
756+
CHECK(foo.a == std::nullopt);
757+
CHECK(foo.b.value() == "baz");
758+
}
759+
}
738760
#endif // TOML11_HAS_OPTIONAL
739761
#endif // TOML11_WITHOUT_DEFINE_NON_INTRUSIVE

0 commit comments

Comments
 (0)