Skip to content

Commit

Permalink
added test cases for #83
Browse files Browse the repository at this point in the history
  • Loading branch information
nlohmann committed Aug 6, 2015
1 parent 11ae6da commit b0eb343
Showing 1 changed file with 63 additions and 0 deletions.
63 changes: 63 additions & 0 deletions test/unit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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/
Expand Down

0 comments on commit b0eb343

Please sign in to comment.