mirror of
https://github.com/red0124/ssp.git
synced 2025-12-14 21:59:55 +01:00
write tests for converting std::optional and std::variant
This commit is contained in:
@@ -57,6 +57,14 @@ TEST_CASE("testing valid conversions") {
|
||||
REQUIRE(c.valid());
|
||||
CHECK(tup == 5);
|
||||
}
|
||||
{
|
||||
auto tup =
|
||||
c.convert<void, void, std::optional<int>>("junk\tjunk\t5",
|
||||
"\t");
|
||||
REQUIRE(c.valid());
|
||||
REQUIRE(tup.has_value());
|
||||
CHECK(tup == 5);
|
||||
}
|
||||
{
|
||||
auto tup = c.convert<int, double, void>("5,6.6,junk");
|
||||
REQUIRE(c.valid());
|
||||
@@ -72,6 +80,36 @@ TEST_CASE("testing valid conversions") {
|
||||
REQUIRE(c.valid());
|
||||
CHECK(tup == std::tuple{5, 6.6});
|
||||
}
|
||||
{
|
||||
auto tup =
|
||||
c.convert<void, std::optional<int>, double>("junk;5;6.6",
|
||||
";");
|
||||
REQUIRE(c.valid());
|
||||
REQUIRE(std::get<0>(tup).has_value());
|
||||
CHECK(tup == std::tuple{5, 6.6});
|
||||
}
|
||||
{
|
||||
auto tup =
|
||||
c.convert<void, std::optional<int>, double>("junk;5.4;6.6",
|
||||
";");
|
||||
REQUIRE(c.valid());
|
||||
REQUIRE(!std::get<0>(tup).has_value());
|
||||
CHECK(tup == std::tuple{std::nullopt, 6.6});
|
||||
}
|
||||
{
|
||||
auto tup = c.convert<void, std::variant<int, double>,
|
||||
double>("junk;5;6.6", ";");
|
||||
REQUIRE(c.valid());
|
||||
REQUIRE(std::holds_alternative<int>(std::get<0>(tup)));
|
||||
CHECK(tup == std::tuple{std::variant<int, double>{5}, 6.6});
|
||||
}
|
||||
{
|
||||
auto tup = c.convert<void, std::variant<int, double>,
|
||||
double>("junk;5.5;6.6", ";");
|
||||
REQUIRE(c.valid());
|
||||
REQUIRE(std::holds_alternative<double>(std::get<0>(tup)));
|
||||
CHECK(tup == std::tuple{std::variant<int, double>{5.5}, 6.6});
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("testing invalid conversions") {
|
||||
@@ -100,6 +138,9 @@ TEST_CASE("testing invalid conversions") {
|
||||
|
||||
c.convert<void, int>("junk,x");
|
||||
REQUIRE(!c.valid());
|
||||
|
||||
c.convert<void, std::variant<int, double>, double>("junk;.5.5;6", ";");
|
||||
REQUIRE(!c.valid());
|
||||
}
|
||||
|
||||
TEST_CASE("testing ss:ax restriction (all except)") {
|
||||
@@ -276,7 +317,8 @@ TEST_CASE("testing ss:ne restriction (not empty)") {
|
||||
CHECK(tup == "s");
|
||||
}
|
||||
{
|
||||
auto tup = c.convert<int, ss::ne<std::string>>("1,s");
|
||||
auto tup =
|
||||
c.convert<std::optional<int>, ss::ne<std::string>>("1,s");
|
||||
REQUIRE(c.valid());
|
||||
CHECK(tup == std::tuple{1, "s"});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user