From 0df642ded0031f06b3ee0ee2a164e4301630c104 Mon Sep 17 00:00:00 2001 From: Niels Date: Mon, 9 Feb 2015 19:49:09 +0100 Subject: [PATCH] more test cases --- test/unit.cpp | 92 +++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 90 insertions(+), 2 deletions(-) diff --git a/test/unit.cpp b/test/unit.cpp index 3394e9de..2b685ac7 100644 --- a/test/unit.cpp +++ b/test/unit.cpp @@ -2608,8 +2608,8 @@ TEST_CASE("iterators") SECTION("const json + begin/end") { - json::iterator it_begin = j_const.begin(); - json::iterator it_end = j_const.end(); + json::const_iterator it_begin = j_const.begin(); + json::const_iterator it_end = j_const.end(); auto it = it_begin; CHECK(it != it_end); @@ -3377,3 +3377,91 @@ TEST_CASE("capacity") } } } + +TEST_CASE("modifiers") +{ + SECTION("clear()") + { + SECTION("boolean") + { + json j = true; + + j.clear(); + CHECK(j == json(json::value_t::boolean)); + } + + SECTION("string") + { + json j = "hello world"; + + j.clear(); + CHECK(j == json(json::value_t::string)); + } + + SECTION("array") + { + SECTION("empty array") + { + json j = json::array(); + + j.clear(); + CHECK(j.empty()); + CHECK(j == json(json::value_t::array)); + } + + SECTION("filled array") + { + json j = {1, 2, 3}; + + j.clear(); + CHECK(j.empty()); + CHECK(j == json(json::value_t::array)); + } + } + + SECTION("object") + { + SECTION("empty object") + { + json j = json::object(); + + j.clear(); + CHECK(j.empty()); + CHECK(j == json(json::value_t::object)); + } + + SECTION("filled object") + { + json j = {{"one", 1}, {"two", 2}, {"three", 3}}; + + j.clear(); + CHECK(j.empty()); + CHECK(j == json(json::value_t::object)); + } + } + + SECTION("number (integer)") + { + json j = 23; + + j.clear(); + CHECK(j == json(json::value_t::number_integer)); + } + + SECTION("number (float)") + { + json j = 23.42; + + j.clear(); + CHECK(j == json(json::value_t::number_float)); + } + + SECTION("null") + { + json j = nullptr; + + j.clear(); + CHECK(j == json(json::value_t::null)); + } + } +} \ No newline at end of file