add std::pair<CompatibleStringType, T> support

This commit is contained in:
Théo DELRIEU 2017-06-06 13:44:35 +02:00
parent 1a9d76679a
commit 85de93ba93
No known key found for this signature in database
GPG key ID: C64D5E244E08ADC6
2 changed files with 59 additions and 3 deletions

View file

@ -156,6 +156,20 @@ TEST_CASE("constructors")
CHECK(j == j_reference);
}
SECTION("std::pair<CompatibleString, T>")
{
std::pair<std::string, std::string> p{"first", "second"};
json j(p);
CHECK((j.get<decltype(p)>() == p));
std::pair<std::string, int> p2{"first", 1};
// use char const*
json j2(std::make_pair("first", 1));
CHECK((j2.get<decltype(p2)>() == p2));
}
SECTION("std::map<const char*, json>")
{
std::map<const char*, json> o {{"a", json(1)}, {"b", json(1u)}, {"c", json(2.2)}, {"d", json(false)}, {"e", json("string")}, {"f", json()}};
@ -164,6 +178,7 @@ TEST_CASE("constructors")
CHECK(j == j_reference);
}
SECTION("std::multimap<json::string_t, json>")
{
std::multimap<json::string_t, json> o {{"a", json(1)}, {"b", json(1u)}, {"c", json(2.2)}, {"d", json(false)}, {"e", json("string")}, {"f", json()}};
@ -954,6 +969,17 @@ TEST_CASE("constructors")
"[json.exception.type_error.301] cannot create object from initializer list");
}
SECTION("std::pair<CompatibleString, T> with error")
{
json j{{"too", "much"}, {"string", "fields"}};
CHECK_THROWS_AS((j.get<std::pair<std::string, std::string>>()), json::other_error);
CHECK_THROWS_WITH((j.get<std::pair<std::string, std::string>>()),
"[json.exception.other_error.502] conversion "
"to std::pair requires the object to have "
"exactly one field, but it has 2");
}
SECTION("empty array")
{
json j = json::array();