Added extra tests to improve coverage.

This commit is contained in:
Anthony VH 2021-01-09 17:54:56 +01:00
parent c0a8b45bbb
commit 1b113f73c2

View File

@ -524,11 +524,19 @@ TEST_CASE("regression tests 2")
SECTION("issue #2574 - Deserialization to std::array, std::pair, and std::tuple with non-default constructable types fails") SECTION("issue #2574 - Deserialization to std::array, std::pair, and std::tuple with non-default constructable types fails")
{ {
SECTION("std::array") SECTION("std::array")
{
{ {
json j = { 7, 4 }; json j = { 7, 4 };
auto arr = j.get<std::array<NonDefaultConstructible, 2>>(); auto arr = j.get<std::array<NonDefaultConstructible, 2>>();
CHECK(arr[0].x == 7); CHECK(arr[0].x == 7);
CHECK(arr[1].x == 4); CHECK(arr[1].x == 4);
}
{
json j = 7;
CHECK_THROWS_AS((j.get<std::array<NonDefaultConstructible, 1>>()), json::type_error);
}
} }
SECTION("std::pair") SECTION("std::pair")
@ -556,6 +564,11 @@ TEST_CASE("regression tests 2")
CHECK(p.first.x == 6); CHECK(p.first.x == 6);
CHECK(p.second == 7); CHECK(p.second == 7);
} }
{
json j = 7;
CHECK_THROWS_AS((j.get<std::pair<NonDefaultConstructible, int>>()), json::type_error);
}
} }
SECTION("std::tuple") SECTION("std::tuple")
@ -573,6 +586,11 @@ TEST_CASE("regression tests 2")
CHECK(std::get<1>(t) == 8); CHECK(std::get<1>(t) == 8);
CHECK(std::get<2>(t).x == 7); CHECK(std::get<2>(t).x == 7);
} }
{
json j = 7;
CHECK_THROWS_AS((j.get<std::tuple<NonDefaultConstructible>>()), json::type_error);
}
} }
} }
} }