From cf18ba2394f7813ebaf8dbc94598db859e5916bf Mon Sep 17 00:00:00 2001 From: gatopeich Date: Tue, 23 Jun 2020 17:50:51 +0100 Subject: [PATCH] Test initialization with dup keys --- test/src/unit-ordered_json.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/test/src/unit-ordered_json.cpp b/test/src/unit-ordered_json.cpp index 1a97ece6..e4ffd68a 100644 --- a/test/src/unit-ordered_json.cpp +++ b/test/src/unit-ordered_json.cpp @@ -58,4 +58,15 @@ TEST_CASE("ordered_json") CHECK(j.dump() == "{\"element2\":2,\"element3\":3}"); CHECK(oj.dump() == "{\"element3\":3,\"element2\":2}"); + + // There are no dup keys cause constructor calls emplace... + json multi {{"z", 1}, {"m", 2}, {"m", 3}, {"y", 4}, {"m", 5}}; + CHECK(multi.size() == 3); + CHECK(multi.dump() == "{\"m\":2,\"y\":4,\"z\":1}"); + + ordered_json multi_ordered {{"z", 1}, {"m", 2}, {"m", 3}, {"y", 4}, {"m", 5}}; + CHECK(multi_ordered.size() == 3); + CHECK(multi_ordered.dump() == "{\"z\":1,\"m\":2,\"y\":4}"); + CHECK(multi_ordered.erase("m") == 1); + CHECK(multi_ordered.dump() == "{\"z\":1,\"y\":4}"); }