From b0eb34394c19e6d59d1aa47d97319de847ea5f5e Mon Sep 17 00:00:00 2001 From: Niels Date: Thu, 6 Aug 2015 22:36:08 +0200 Subject: [PATCH] added test cases for #83 --- test/unit.cpp | 63 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) diff --git a/test/unit.cpp b/test/unit.cpp index 735fbd24..a44103f2 100644 --- a/test/unit.cpp +++ b/test/unit.cpp @@ -9260,6 +9260,69 @@ TEST_CASE("concepts") } } +TEST_CASE("iterator_wrapper") +{ + SECTION("object") + { + json j = {{"A", 1}, {"B", 2}}; + int counter = 1; + + for (auto i : json::iterator_wrapper(j)) + { + switch (counter++) + { + case 1: + { + CHECK(i.key() == "A"); + CHECK(i.value() == json(1)); + CHECK(i.first == "A"); + CHECK(i.second == json(1)); + break; + } + + case 2: + { + CHECK(i.key() == "B"); + CHECK(i.value() == json(2)); + CHECK(i.first == "B"); + CHECK(i.second == json(2)); + break; + } + } + } + } + + SECTION("array") + { + json j = {"A", "B"}; + int counter = 1; + + for (auto i : json::iterator_wrapper(j)) + { + switch (counter++) + { + case 1: + { + CHECK(i.key() == "0"); + CHECK(i.value() == "A"); + CHECK(i.first == "0"); + CHECK(i.second == "A"); + break; + } + + case 2: + { + CHECK(i.key() == "1"); + CHECK(i.value() == "B"); + CHECK(i.first == "1"); + CHECK(i.second == "B"); + break; + } + } + } + } +} + TEST_CASE("compliance tests from json.org") { // test cases are from http://json.org/JSON_checker/