improved test coverage

parent b27a142e
...@@ -38,7 +38,7 @@ TEST_CASE("capacity") ...@@ -38,7 +38,7 @@ TEST_CASE("capacity")
SECTION("boolean") SECTION("boolean")
{ {
json j = true; json j = true;
json j_const(j); const json j_const(j);
SECTION("result of empty") SECTION("result of empty")
{ {
...@@ -56,7 +56,7 @@ TEST_CASE("capacity") ...@@ -56,7 +56,7 @@ TEST_CASE("capacity")
SECTION("string") SECTION("string")
{ {
json j = "hello world"; json j = "hello world";
json j_const(j); const json j_const(j);
SECTION("result of empty") SECTION("result of empty")
{ {
...@@ -76,7 +76,7 @@ TEST_CASE("capacity") ...@@ -76,7 +76,7 @@ TEST_CASE("capacity")
SECTION("empty array") SECTION("empty array")
{ {
json j = json::array(); json j = json::array();
json j_const(j); const json j_const(j);
SECTION("result of empty") SECTION("result of empty")
{ {
...@@ -94,7 +94,7 @@ TEST_CASE("capacity") ...@@ -94,7 +94,7 @@ TEST_CASE("capacity")
SECTION("filled array") SECTION("filled array")
{ {
json j = {1, 2, 3}; json j = {1, 2, 3};
json j_const(j); const json j_const(j);
SECTION("result of empty") SECTION("result of empty")
{ {
...@@ -115,7 +115,7 @@ TEST_CASE("capacity") ...@@ -115,7 +115,7 @@ TEST_CASE("capacity")
SECTION("empty object") SECTION("empty object")
{ {
json j = json::object(); json j = json::object();
json j_const(j); const json j_const(j);
SECTION("result of empty") SECTION("result of empty")
{ {
...@@ -133,7 +133,7 @@ TEST_CASE("capacity") ...@@ -133,7 +133,7 @@ TEST_CASE("capacity")
SECTION("filled object") SECTION("filled object")
{ {
json j = {{"one", 1}, {"two", 2}, {"three", 3}}; json j = {{"one", 1}, {"two", 2}, {"three", 3}};
json j_const(j); const json j_const(j);
SECTION("result of empty") SECTION("result of empty")
{ {
...@@ -151,8 +151,8 @@ TEST_CASE("capacity") ...@@ -151,8 +151,8 @@ TEST_CASE("capacity")
SECTION("number (integer)") SECTION("number (integer)")
{ {
json j = 23; json j = -23;
json j_const(j); const json j_const(j);
SECTION("result of empty") SECTION("result of empty")
{ {
...@@ -170,7 +170,7 @@ TEST_CASE("capacity") ...@@ -170,7 +170,7 @@ TEST_CASE("capacity")
SECTION("number (unsigned)") SECTION("number (unsigned)")
{ {
json j = 23u; json j = 23u;
json j_const(j); const json j_const(j);
SECTION("result of empty") SECTION("result of empty")
{ {
...@@ -188,7 +188,7 @@ TEST_CASE("capacity") ...@@ -188,7 +188,7 @@ TEST_CASE("capacity")
SECTION("number (float)") SECTION("number (float)")
{ {
json j = 23.42; json j = 23.42;
json j_const(j); const json j_const(j);
SECTION("result of empty") SECTION("result of empty")
{ {
...@@ -206,7 +206,7 @@ TEST_CASE("capacity") ...@@ -206,7 +206,7 @@ TEST_CASE("capacity")
SECTION("null") SECTION("null")
{ {
json j = nullptr; json j = nullptr;
json j_const(j); const json j_const(j);
SECTION("result of empty") SECTION("result of empty")
{ {
...@@ -227,7 +227,7 @@ TEST_CASE("capacity") ...@@ -227,7 +227,7 @@ TEST_CASE("capacity")
SECTION("boolean") SECTION("boolean")
{ {
json j = true; json j = true;
json j_const(j); const json j_const(j);
SECTION("result of size") SECTION("result of size")
{ {
...@@ -247,7 +247,7 @@ TEST_CASE("capacity") ...@@ -247,7 +247,7 @@ TEST_CASE("capacity")
SECTION("string") SECTION("string")
{ {
json j = "hello world"; json j = "hello world";
json j_const(j); const json j_const(j);
SECTION("result of size") SECTION("result of size")
{ {
...@@ -269,7 +269,7 @@ TEST_CASE("capacity") ...@@ -269,7 +269,7 @@ TEST_CASE("capacity")
SECTION("empty array") SECTION("empty array")
{ {
json j = json::array(); json j = json::array();
json j_const(j); const json j_const(j);
SECTION("result of size") SECTION("result of size")
{ {
...@@ -289,7 +289,7 @@ TEST_CASE("capacity") ...@@ -289,7 +289,7 @@ TEST_CASE("capacity")
SECTION("filled array") SECTION("filled array")
{ {
json j = {1, 2, 3}; json j = {1, 2, 3};
json j_const(j); const json j_const(j);
SECTION("result of size") SECTION("result of size")
{ {
...@@ -312,7 +312,7 @@ TEST_CASE("capacity") ...@@ -312,7 +312,7 @@ TEST_CASE("capacity")
SECTION("empty object") SECTION("empty object")
{ {
json j = json::object(); json j = json::object();
json j_const(j); const json j_const(j);
SECTION("result of size") SECTION("result of size")
{ {
...@@ -332,7 +332,7 @@ TEST_CASE("capacity") ...@@ -332,7 +332,7 @@ TEST_CASE("capacity")
SECTION("filled object") SECTION("filled object")
{ {
json j = {{"one", 1}, {"two", 2}, {"three", 3}}; json j = {{"one", 1}, {"two", 2}, {"three", 3}};
json j_const(j); const json j_const(j);
SECTION("result of size") SECTION("result of size")
{ {
...@@ -352,8 +352,8 @@ TEST_CASE("capacity") ...@@ -352,8 +352,8 @@ TEST_CASE("capacity")
SECTION("number (integer)") SECTION("number (integer)")
{ {
json j = 23; json j = -23;
json j_const(j); const json j_const(j);
SECTION("result of size") SECTION("result of size")
{ {
...@@ -373,7 +373,7 @@ TEST_CASE("capacity") ...@@ -373,7 +373,7 @@ TEST_CASE("capacity")
SECTION("number (unsigned)") SECTION("number (unsigned)")
{ {
json j = 23u; json j = 23u;
json j_const(j); const json j_const(j);
SECTION("result of size") SECTION("result of size")
{ {
...@@ -393,7 +393,7 @@ TEST_CASE("capacity") ...@@ -393,7 +393,7 @@ TEST_CASE("capacity")
SECTION("number (float)") SECTION("number (float)")
{ {
json j = 23.42; json j = 23.42;
json j_const(j); const json j_const(j);
SECTION("result of size") SECTION("result of size")
{ {
...@@ -413,7 +413,7 @@ TEST_CASE("capacity") ...@@ -413,7 +413,7 @@ TEST_CASE("capacity")
SECTION("null") SECTION("null")
{ {
json j = nullptr; json j = nullptr;
json j_const(j); const json j_const(j);
SECTION("result of size") SECTION("result of size")
{ {
...@@ -436,7 +436,7 @@ TEST_CASE("capacity") ...@@ -436,7 +436,7 @@ TEST_CASE("capacity")
SECTION("boolean") SECTION("boolean")
{ {
json j = true; json j = true;
json j_const(j); const json j_const(j);
SECTION("result of max_size") SECTION("result of max_size")
{ {
...@@ -448,7 +448,7 @@ TEST_CASE("capacity") ...@@ -448,7 +448,7 @@ TEST_CASE("capacity")
SECTION("string") SECTION("string")
{ {
json j = "hello world"; json j = "hello world";
json j_const(j); const json j_const(j);
SECTION("result of max_size") SECTION("result of max_size")
{ {
...@@ -462,7 +462,7 @@ TEST_CASE("capacity") ...@@ -462,7 +462,7 @@ TEST_CASE("capacity")
SECTION("empty array") SECTION("empty array")
{ {
json j = json::array(); json j = json::array();
json j_const(j); const json j_const(j);
SECTION("result of max_size") SECTION("result of max_size")
{ {
...@@ -474,7 +474,7 @@ TEST_CASE("capacity") ...@@ -474,7 +474,7 @@ TEST_CASE("capacity")
SECTION("filled array") SECTION("filled array")
{ {
json j = {1, 2, 3}; json j = {1, 2, 3};
json j_const(j); const json j_const(j);
SECTION("result of max_size") SECTION("result of max_size")
{ {
...@@ -489,7 +489,7 @@ TEST_CASE("capacity") ...@@ -489,7 +489,7 @@ TEST_CASE("capacity")
SECTION("empty object") SECTION("empty object")
{ {
json j = json::object(); json j = json::object();
json j_const(j); const json j_const(j);
SECTION("result of max_size") SECTION("result of max_size")
{ {
...@@ -501,7 +501,7 @@ TEST_CASE("capacity") ...@@ -501,7 +501,7 @@ TEST_CASE("capacity")
SECTION("filled object") SECTION("filled object")
{ {
json j = {{"one", 1}, {"two", 2}, {"three", 3}}; json j = {{"one", 1}, {"two", 2}, {"three", 3}};
json j_const(j); const json j_const(j);
SECTION("result of max_size") SECTION("result of max_size")
{ {
...@@ -513,8 +513,8 @@ TEST_CASE("capacity") ...@@ -513,8 +513,8 @@ TEST_CASE("capacity")
SECTION("number (integer)") SECTION("number (integer)")
{ {
json j = 23; json j = -23;
json j_const(j); const json j_const(j);
SECTION("result of max_size") SECTION("result of max_size")
{ {
...@@ -526,7 +526,7 @@ TEST_CASE("capacity") ...@@ -526,7 +526,7 @@ TEST_CASE("capacity")
SECTION("number (unsigned)") SECTION("number (unsigned)")
{ {
json j = 23u; json j = 23u;
json j_const(j); const json j_const(j);
SECTION("result of max_size") SECTION("result of max_size")
{ {
...@@ -538,7 +538,7 @@ TEST_CASE("capacity") ...@@ -538,7 +538,7 @@ TEST_CASE("capacity")
SECTION("number (float)") SECTION("number (float)")
{ {
json j = 23.42; json j = 23.42;
json j_const(j); const json j_const(j);
SECTION("result of max_size") SECTION("result of max_size")
{ {
...@@ -550,7 +550,7 @@ TEST_CASE("capacity") ...@@ -550,7 +550,7 @@ TEST_CASE("capacity")
SECTION("null") SECTION("null")
{ {
json j = nullptr; json j = nullptr;
json j_const(j); const json j_const(j);
SECTION("result of max_size") SECTION("result of max_size")
{ {
......
...@@ -88,7 +88,7 @@ TEST_CASE("lexicographical comparison operators") ...@@ -88,7 +88,7 @@ TEST_CASE("lexicographical comparison operators")
json j_values = json j_values =
{ {
nullptr, nullptr, nullptr, nullptr,
17, 42, -17, 42,
8u, 13u, 8u, 13u,
3.14159, 23.42, 3.14159, 23.42,
"foo", "bar", "foo", "bar",
...@@ -125,6 +125,8 @@ TEST_CASE("lexicographical comparison operators") ...@@ -125,6 +125,8 @@ TEST_CASE("lexicographical comparison operators")
{ {
CAPTURE(i); CAPTURE(i);
CAPTURE(j); CAPTURE(j);
CAPTURE(j_values[i]);
CAPTURE(j_values[j]);
// check precomputed values // check precomputed values
CHECK( (j_values[i] == j_values[j]) == expected[i][j] ); CHECK( (j_values[i] == j_values[j]) == expected[i][j] );
} }
...@@ -172,11 +174,11 @@ TEST_CASE("lexicographical comparison operators") ...@@ -172,11 +174,11 @@ TEST_CASE("lexicographical comparison operators")
{ {
{false, false, true, true, true, true, true, true, true, true, true, true, true, true, true, true}, {false, false, true, true, true, true, true, true, true, true, true, true, true, true, true, true},
{false, false, true, true, true, true, true, true, true, true, true, true, true, true, true, true}, {false, false, true, true, true, true, true, true, true, true, true, true, true, true, true, true},
{false, false, false, true, false, false, false, true, true, true, false, false, true, true, true, true}, {false, false, false, true, true, true, true, true, true, true, false, false, true, true, true, true},
{false, false, false, false, false, false, false, false, true, true, false, false, true, true, true, true}, {false, false, false, false, false, false, false, false, true, true, false, false, true, true, true, true},
{false, false, true, true, false, true, false, true, true, true, false, false, true, true, true, true}, {false, false, false, true, false, true, false, true, true, true, false, false, true, true, true, true},
{false, false, true, true, false, false, false, true, true, true, false, false, true, true, true, true}, {false, false, false, true, false, false, false, true, true, true, false, false, true, true, true, true},
{false, false, true, true, true, true, false, true, true, true, false, false, true, true, true, true}, {false, false, false, true, true, true, false, true, true, true, false, false, true, true, true, true},
{false, false, false, true, false, false, false, false, true, true, false, false, true, true, true, true}, {false, false, false, true, false, false, false, false, true, true, false, false, true, true, true, true},
{false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false}, {false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false},
{false, false, false, false, false, false, false, false, true, false, false, false, false, false, false, false}, {false, false, false, false, false, false, false, false, true, false, false, false, false, false, false, false},
...@@ -194,6 +196,8 @@ TEST_CASE("lexicographical comparison operators") ...@@ -194,6 +196,8 @@ TEST_CASE("lexicographical comparison operators")
{ {
CAPTURE(i); CAPTURE(i);
CAPTURE(j); CAPTURE(j);
CAPTURE(j_values[i]);
CAPTURE(j_values[j]);
// check precomputed values // check precomputed values
CHECK( (j_values[i] < j_values[j]) == expected[i][j] ); CHECK( (j_values[i] < j_values[j]) == expected[i][j] );
} }
......
...@@ -77,6 +77,7 @@ TEST_CASE("constructors") ...@@ -77,6 +77,7 @@ TEST_CASE("constructors")
auto t = json::value_t::boolean; auto t = json::value_t::boolean;
json j(t); json j(t);
CHECK(j.type() == t); CHECK(j.type() == t);
CHECK(j == false);
} }
SECTION("string") SECTION("string")
...@@ -84,6 +85,7 @@ TEST_CASE("constructors") ...@@ -84,6 +85,7 @@ TEST_CASE("constructors")
auto t = json::value_t::string; auto t = json::value_t::string;
json j(t); json j(t);
CHECK(j.type() == t); CHECK(j.type() == t);
CHECK(j == "");
} }
SECTION("number_integer") SECTION("number_integer")
...@@ -91,6 +93,7 @@ TEST_CASE("constructors") ...@@ -91,6 +93,7 @@ TEST_CASE("constructors")
auto t = json::value_t::number_integer; auto t = json::value_t::number_integer;
json j(t); json j(t);
CHECK(j.type() == t); CHECK(j.type() == t);
CHECK(j == 0);
} }
SECTION("number_unsigned") SECTION("number_unsigned")
...@@ -98,6 +101,7 @@ TEST_CASE("constructors") ...@@ -98,6 +101,7 @@ TEST_CASE("constructors")
auto t = json::value_t::number_unsigned; auto t = json::value_t::number_unsigned;
json j(t); json j(t);
CHECK(j.type() == t); CHECK(j.type() == t);
CHECK(j == 0);
} }
SECTION("number_float") SECTION("number_float")
...@@ -105,6 +109,7 @@ TEST_CASE("constructors") ...@@ -105,6 +109,7 @@ TEST_CASE("constructors")
auto t = json::value_t::number_float; auto t = json::value_t::number_float;
json j(t); json j(t);
CHECK(j.type() == t); CHECK(j.type() == t);
CHECK(j == 0.0);
} }
} }
......
...@@ -47,5 +47,10 @@ TEST_CASE("version information") ...@@ -47,5 +47,10 @@ TEST_CASE("version information")
{"minor", 1}, {"minor", 1},
{"patch", 1} {"patch", 1}
})); }));
CHECK(j.find("platform") != j.end());
CHECK(j.at("compiler").find("family") != j.at("compiler").end());
CHECK(j.at("compiler").find("version") != j.at("compiler").end());
CHECK(j.at("compiler").find("c++") != j.at("compiler").end());
} }
} }
...@@ -271,9 +271,13 @@ TEST_CASE("modifiers") ...@@ -271,9 +271,13 @@ TEST_CASE("modifiers")
j.push_back({"key2", "bar"}); j.push_back({"key2", "bar"});
CHECK(j == json({{"key1", 1}, {"key2", "bar"}})); CHECK(j == json({{"key1", 1}, {"key2", "bar"}}));
json k = {{"key1", 1}}; // invalid values (no string/val pair)
CHECK_THROWS_AS(k.push_back({1, 2, 3, 4}), json::type_error&); CHECK_THROWS_AS(j.push_back({1}), json::type_error&);
CHECK_THROWS_WITH(k.push_back({1, 2, 3, 4}), "[json.exception.type_error.308] cannot use push_back() with object"); CHECK_THROWS_WITH(j.push_back({1}), "[json.exception.type_error.308] cannot use push_back() with object");
CHECK_THROWS_AS(j.push_back({1,2}), json::type_error&);
CHECK_THROWS_WITH(j.push_back({1, 2}), "[json.exception.type_error.308] cannot use push_back() with object");
CHECK_THROWS_AS(j.push_back({1, 2, 3, 4}), json::type_error&);
CHECK_THROWS_WITH(j.push_back({1, 2, 3, 4}), "[json.exception.type_error.308] cannot use push_back() with object");
} }
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment