1
0
mirror of https://github.com/nlohmann/json.git synced 2025-07-21 04:22:05 +03:00

proposal for #428

This implementation forwards the iterators to std::map::insert.
This commit is contained in:
Niels Lohmann
2017-04-07 18:29:09 +02:00
parent 90273e930c
commit 97a25de938
5 changed files with 150 additions and 1 deletions

View File

@ -594,7 +594,7 @@ TEST_CASE("modifiers")
}
}
SECTION("range")
SECTION("range for array")
{
json j_other_array = {"first", "second"};
@ -631,6 +631,40 @@ TEST_CASE("modifiers")
}
}
SECTION("range for object")
{
json j_object1 = {{"one", "eins"}, {"two", "zwei"}};
json j_object2 = {{"eleven", "elf"}, {"seventeen", "siebzehn"}};
SECTION("proper usage")
{
j_object1.insert(j_object2.begin(), j_object2.end());
CHECK(j_object1.size() == 4);
}
SECTION("empty range")
{
j_object1.insert(j_object2.begin(), j_object2.begin());
CHECK(j_object1.size() == 2);
}
SECTION("invalid iterators")
{
json j_other_array2 = {"first", "second"};
CHECK_THROWS_AS(j_array.insert(j_object2.begin(), j_object2.end()), json::type_error);
CHECK_THROWS_AS(j_object1.insert(j_object1.begin(), j_object2.end()), json::invalid_iterator);
CHECK_THROWS_AS(j_object1.insert(j_array.begin(), j_array.end()), json::invalid_iterator);
CHECK_THROWS_WITH(j_array.insert(j_object2.begin(), j_object2.end()),
"[json.exception.type_error.309] cannot use insert() with array");
CHECK_THROWS_WITH(j_object1.insert(j_object1.begin(), j_object2.end()),
"[json.exception.invalid_iterator.210] iterators do not fit");
CHECK_THROWS_WITH(j_object1.insert(j_array.begin(), j_array.end()),
"[json.exception.invalid_iterator.202] iterators first and last must point to objects");
}
}
SECTION("initializer list at position")
{
SECTION("insert before begin()")