✅ improved test coverage
This commit is contained in:
parent
b27a142ec0
commit
24b6e028a9
6 changed files with 204 additions and 72 deletions
|
@ -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")
|
||||||
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")
|
||||||
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")
|
||||||
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")
|
||||||
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")
|
||||||
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")
|
||||||
|
|
||||||
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")
|
||||||
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")
|
||||||
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")
|
||||||
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")
|
||||||
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")
|
||||||
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")
|
||||||
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")
|
||||||
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")
|
||||||
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")
|
||||||
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")
|
||||||
|
|
||||||
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")
|
||||||
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")
|
||||||
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")
|
||||||
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")
|
||||||
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")
|
||||||
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")
|
||||||
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")
|
||||||
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")
|
||||||
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")
|
||||||
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")
|
||||||
|
|
||||||
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")
|
||||||
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")
|
||||||
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")
|
||||||
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")
|
||||||
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")
|
||||||
{
|
{
|
||||||
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")
|
||||||
{
|
{
|
||||||
{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")
|
||||||
{
|
{
|
||||||
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")
|
||||||
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")
|
||||||
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")
|
||||||
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")
|
||||||
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")
|
||||||
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")
|
||||||
{"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")
|
||||||
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");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -64,11 +64,24 @@ TEST_CASE("reference access")
|
||||||
|
|
||||||
// check if mismatching references throw correctly
|
// check if mismatching references throw correctly
|
||||||
CHECK_NOTHROW(value.get_ref<json::object_t&>());
|
CHECK_NOTHROW(value.get_ref<json::object_t&>());
|
||||||
CHECK_THROWS(value.get_ref<json::array_t&>());
|
CHECK_THROWS_AS(value.get_ref<json::array_t&>(), json::type_error&);
|
||||||
CHECK_THROWS(value.get_ref<json::string_t&>());
|
CHECK_THROWS_WITH(value.get_ref<json::array_t&>(),
|
||||||
CHECK_THROWS(value.get_ref<json::boolean_t&>());
|
"[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is object");
|
||||||
CHECK_THROWS(value.get_ref<json::number_integer_t&>());
|
CHECK_THROWS_AS(value.get_ref<json::string_t&>(), json::type_error&);
|
||||||
CHECK_THROWS(value.get_ref<json::number_float_t&>());
|
CHECK_THROWS_WITH(value.get_ref<json::string_t&>(),
|
||||||
|
"[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is object");
|
||||||
|
CHECK_THROWS_AS(value.get_ref<json::boolean_t&>(), json::type_error&);
|
||||||
|
CHECK_THROWS_WITH(value.get_ref<json::boolean_t&>(),
|
||||||
|
"[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is object");
|
||||||
|
CHECK_THROWS_AS(value.get_ref<json::number_integer_t&>(), json::type_error&);
|
||||||
|
CHECK_THROWS_WITH(value.get_ref<json::number_integer_t&>(),
|
||||||
|
"[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is object");
|
||||||
|
CHECK_THROWS_AS(value.get_ref<json::number_unsigned_t&>(), json::type_error&);
|
||||||
|
CHECK_THROWS_WITH(value.get_ref<json::number_unsigned_t&>(),
|
||||||
|
"[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is object");
|
||||||
|
CHECK_THROWS_AS(value.get_ref<json::number_float_t&>(), json::type_error&);
|
||||||
|
CHECK_THROWS_WITH(value.get_ref<json::number_float_t&>(),
|
||||||
|
"[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is object");
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTION("const reference access to const object_t")
|
SECTION("const reference access to const object_t")
|
||||||
|
@ -100,12 +113,25 @@ TEST_CASE("reference access")
|
||||||
CHECK(p2 == value.get<test_type>());
|
CHECK(p2 == value.get<test_type>());
|
||||||
|
|
||||||
// check if mismatching references throw correctly
|
// check if mismatching references throw correctly
|
||||||
CHECK_THROWS(value.get_ref<json::object_t&>());
|
CHECK_THROWS_AS(value.get_ref<json::object_t&>(), json::type_error&);
|
||||||
|
CHECK_THROWS_WITH(value.get_ref<json::object_t&>(),
|
||||||
|
"[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is array");
|
||||||
CHECK_NOTHROW(value.get_ref<json::array_t&>());
|
CHECK_NOTHROW(value.get_ref<json::array_t&>());
|
||||||
CHECK_THROWS(value.get_ref<json::string_t&>());
|
CHECK_THROWS_AS(value.get_ref<json::string_t&>(), json::type_error&);
|
||||||
CHECK_THROWS(value.get_ref<json::boolean_t&>());
|
CHECK_THROWS_WITH(value.get_ref<json::string_t&>(),
|
||||||
CHECK_THROWS(value.get_ref<json::number_integer_t&>());
|
"[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is array");
|
||||||
CHECK_THROWS(value.get_ref<json::number_float_t&>());
|
CHECK_THROWS_AS(value.get_ref<json::boolean_t&>(), json::type_error&);
|
||||||
|
CHECK_THROWS_WITH(value.get_ref<json::boolean_t&>(),
|
||||||
|
"[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is array");
|
||||||
|
CHECK_THROWS_AS(value.get_ref<json::number_integer_t&>(), json::type_error&);
|
||||||
|
CHECK_THROWS_WITH(value.get_ref<json::number_integer_t&>(),
|
||||||
|
"[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is array");
|
||||||
|
CHECK_THROWS_AS(value.get_ref<json::number_unsigned_t&>(), json::type_error&);
|
||||||
|
CHECK_THROWS_WITH(value.get_ref<json::number_unsigned_t&>(),
|
||||||
|
"[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is array");
|
||||||
|
CHECK_THROWS_AS(value.get_ref<json::number_float_t&>(), json::type_error&);
|
||||||
|
CHECK_THROWS_WITH(value.get_ref<json::number_float_t&>(),
|
||||||
|
"[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is array");
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTION("reference access to string_t")
|
SECTION("reference access to string_t")
|
||||||
|
@ -123,12 +149,25 @@ TEST_CASE("reference access")
|
||||||
CHECK(p2 == value.get<test_type>());
|
CHECK(p2 == value.get<test_type>());
|
||||||
|
|
||||||
// check if mismatching references throw correctly
|
// check if mismatching references throw correctly
|
||||||
CHECK_THROWS(value.get_ref<json::object_t&>());
|
CHECK_THROWS_AS(value.get_ref<json::object_t&>(), json::type_error&);
|
||||||
CHECK_THROWS(value.get_ref<json::array_t&>());
|
CHECK_THROWS_WITH(value.get_ref<json::object_t&>(),
|
||||||
|
"[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is string");
|
||||||
|
CHECK_THROWS_AS(value.get_ref<json::array_t&>(), json::type_error&);
|
||||||
|
CHECK_THROWS_WITH(value.get_ref<json::array_t&>(),
|
||||||
|
"[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is string");
|
||||||
CHECK_NOTHROW(value.get_ref<json::string_t&>());
|
CHECK_NOTHROW(value.get_ref<json::string_t&>());
|
||||||
CHECK_THROWS(value.get_ref<json::boolean_t&>());
|
CHECK_THROWS_AS(value.get_ref<json::boolean_t&>(), json::type_error&);
|
||||||
CHECK_THROWS(value.get_ref<json::number_integer_t&>());
|
CHECK_THROWS_WITH(value.get_ref<json::boolean_t&>(),
|
||||||
CHECK_THROWS(value.get_ref<json::number_float_t&>());
|
"[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is string");
|
||||||
|
CHECK_THROWS_AS(value.get_ref<json::number_integer_t&>(), json::type_error&);
|
||||||
|
CHECK_THROWS_WITH(value.get_ref<json::number_integer_t&>(),
|
||||||
|
"[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is string");
|
||||||
|
CHECK_THROWS_AS(value.get_ref<json::number_unsigned_t&>(), json::type_error&);
|
||||||
|
CHECK_THROWS_WITH(value.get_ref<json::number_unsigned_t&>(),
|
||||||
|
"[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is string");
|
||||||
|
CHECK_THROWS_AS(value.get_ref<json::number_float_t&>(), json::type_error&);
|
||||||
|
CHECK_THROWS_WITH(value.get_ref<json::number_float_t&>(),
|
||||||
|
"[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is string");
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTION("reference access to boolean_t")
|
SECTION("reference access to boolean_t")
|
||||||
|
@ -146,18 +185,31 @@ TEST_CASE("reference access")
|
||||||
CHECK(p2 == value.get<test_type>());
|
CHECK(p2 == value.get<test_type>());
|
||||||
|
|
||||||
// check if mismatching references throw correctly
|
// check if mismatching references throw correctly
|
||||||
CHECK_THROWS(value.get_ref<json::object_t&>());
|
CHECK_THROWS_AS(value.get_ref<json::object_t&>(), json::type_error&);
|
||||||
CHECK_THROWS(value.get_ref<json::array_t&>());
|
CHECK_THROWS_WITH(value.get_ref<json::object_t&>(),
|
||||||
CHECK_THROWS(value.get_ref<json::string_t&>());
|
"[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is boolean");
|
||||||
|
CHECK_THROWS_AS(value.get_ref<json::array_t&>(), json::type_error&);
|
||||||
|
CHECK_THROWS_WITH(value.get_ref<json::array_t&>(),
|
||||||
|
"[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is boolean");
|
||||||
|
CHECK_THROWS_AS(value.get_ref<json::string_t&>(), json::type_error&);
|
||||||
|
CHECK_THROWS_WITH(value.get_ref<json::string_t&>(),
|
||||||
|
"[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is boolean");
|
||||||
CHECK_NOTHROW(value.get_ref<json::boolean_t&>());
|
CHECK_NOTHROW(value.get_ref<json::boolean_t&>());
|
||||||
CHECK_THROWS(value.get_ref<json::number_integer_t&>());
|
CHECK_THROWS_AS(value.get_ref<json::number_integer_t&>(), json::type_error&);
|
||||||
CHECK_THROWS(value.get_ref<json::number_float_t&>());
|
CHECK_THROWS_WITH(value.get_ref<json::number_integer_t&>(),
|
||||||
|
"[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is boolean");
|
||||||
|
CHECK_THROWS_AS(value.get_ref<json::number_unsigned_t&>(), json::type_error&);
|
||||||
|
CHECK_THROWS_WITH(value.get_ref<json::number_unsigned_t&>(),
|
||||||
|
"[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is boolean");
|
||||||
|
CHECK_THROWS_AS(value.get_ref<json::number_float_t&>(), json::type_error&);
|
||||||
|
CHECK_THROWS_WITH(value.get_ref<json::number_float_t&>(),
|
||||||
|
"[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is boolean");
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTION("reference access to number_integer_t")
|
SECTION("reference access to number_integer_t")
|
||||||
{
|
{
|
||||||
using test_type = json::number_integer_t;
|
using test_type = json::number_integer_t;
|
||||||
json value = 23;
|
json value = -23;
|
||||||
|
|
||||||
// check if references are returned correctly
|
// check if references are returned correctly
|
||||||
test_type& p1 = value.get_ref<test_type&>();
|
test_type& p1 = value.get_ref<test_type&>();
|
||||||
|
@ -169,12 +221,61 @@ TEST_CASE("reference access")
|
||||||
CHECK(p2 == value.get<test_type>());
|
CHECK(p2 == value.get<test_type>());
|
||||||
|
|
||||||
// check if mismatching references throw correctly
|
// check if mismatching references throw correctly
|
||||||
CHECK_THROWS(value.get_ref<json::object_t&>());
|
CHECK_THROWS_AS(value.get_ref<json::object_t&>(), json::type_error&);
|
||||||
CHECK_THROWS(value.get_ref<json::array_t&>());
|
CHECK_THROWS_WITH(value.get_ref<json::object_t&>(),
|
||||||
CHECK_THROWS(value.get_ref<json::string_t&>());
|
"[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is number");
|
||||||
CHECK_THROWS(value.get_ref<json::boolean_t&>());
|
CHECK_THROWS_AS(value.get_ref<json::array_t&>(), json::type_error&);
|
||||||
|
CHECK_THROWS_WITH(value.get_ref<json::array_t&>(),
|
||||||
|
"[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is number");
|
||||||
|
CHECK_THROWS_AS(value.get_ref<json::string_t&>(), json::type_error&);
|
||||||
|
CHECK_THROWS_WITH(value.get_ref<json::string_t&>(),
|
||||||
|
"[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is number");
|
||||||
|
CHECK_THROWS_AS(value.get_ref<json::boolean_t&>(), json::type_error&);
|
||||||
|
CHECK_THROWS_WITH(value.get_ref<json::boolean_t&>(),
|
||||||
|
"[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is number");
|
||||||
CHECK_NOTHROW(value.get_ref<json::number_integer_t&>());
|
CHECK_NOTHROW(value.get_ref<json::number_integer_t&>());
|
||||||
CHECK_THROWS(value.get_ref<json::number_float_t&>());
|
CHECK_THROWS_AS(value.get_ref<json::number_unsigned_t&>(), json::type_error&);
|
||||||
|
CHECK_THROWS_WITH(value.get_ref<json::number_unsigned_t&>(),
|
||||||
|
"[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is number");
|
||||||
|
CHECK_THROWS_AS(value.get_ref<json::number_float_t&>(), json::type_error&);
|
||||||
|
CHECK_THROWS_WITH(value.get_ref<json::number_float_t&>(),
|
||||||
|
"[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is number");
|
||||||
|
}
|
||||||
|
|
||||||
|
SECTION("reference access to number_unsigned_t")
|
||||||
|
{
|
||||||
|
using test_type = json::number_unsigned_t;
|
||||||
|
json value = 23u;
|
||||||
|
|
||||||
|
// check if references are returned correctly
|
||||||
|
test_type& p1 = value.get_ref<test_type&>();
|
||||||
|
CHECK(&p1 == value.get_ptr<test_type*>());
|
||||||
|
CHECK(p1 == value.get<test_type>());
|
||||||
|
|
||||||
|
const test_type& p2 = value.get_ref<const test_type&>();
|
||||||
|
CHECK(&p2 == value.get_ptr<const test_type*>());
|
||||||
|
CHECK(p2 == value.get<test_type>());
|
||||||
|
|
||||||
|
// check if mismatching references throw correctly
|
||||||
|
CHECK_THROWS_AS(value.get_ref<json::object_t&>(), json::type_error&);
|
||||||
|
CHECK_THROWS_WITH(value.get_ref<json::object_t&>(),
|
||||||
|
"[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is number");
|
||||||
|
CHECK_THROWS_AS(value.get_ref<json::array_t&>(), json::type_error&);
|
||||||
|
CHECK_THROWS_WITH(value.get_ref<json::array_t&>(),
|
||||||
|
"[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is number");
|
||||||
|
CHECK_THROWS_AS(value.get_ref<json::string_t&>(), json::type_error&);
|
||||||
|
CHECK_THROWS_WITH(value.get_ref<json::string_t&>(),
|
||||||
|
"[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is number");
|
||||||
|
CHECK_THROWS_AS(value.get_ref<json::boolean_t&>(), json::type_error&);
|
||||||
|
CHECK_THROWS_WITH(value.get_ref<json::boolean_t&>(),
|
||||||
|
"[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is number");
|
||||||
|
//CHECK_THROWS_AS(value.get_ref<json::number_integer_t&>(), json::type_error&);
|
||||||
|
//CHECK_THROWS_WITH(value.get_ref<json::number_integer_t&>(),
|
||||||
|
// "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is number");
|
||||||
|
CHECK_NOTHROW(value.get_ref<json::number_unsigned_t&>());
|
||||||
|
CHECK_THROWS_AS(value.get_ref<json::number_float_t&>(), json::type_error&);
|
||||||
|
CHECK_THROWS_WITH(value.get_ref<json::number_float_t&>(),
|
||||||
|
"[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is number");
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTION("reference access to number_float_t")
|
SECTION("reference access to number_float_t")
|
||||||
|
@ -192,11 +293,24 @@ TEST_CASE("reference access")
|
||||||
CHECK(p2 == value.get<test_type>());
|
CHECK(p2 == value.get<test_type>());
|
||||||
|
|
||||||
// check if mismatching references throw correctly
|
// check if mismatching references throw correctly
|
||||||
CHECK_THROWS(value.get_ref<json::object_t&>());
|
CHECK_THROWS_AS(value.get_ref<json::object_t&>(), json::type_error&);
|
||||||
CHECK_THROWS(value.get_ref<json::array_t&>());
|
CHECK_THROWS_WITH(value.get_ref<json::object_t&>(),
|
||||||
CHECK_THROWS(value.get_ref<json::string_t&>());
|
"[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is number");
|
||||||
CHECK_THROWS(value.get_ref<json::boolean_t&>());
|
CHECK_THROWS_AS(value.get_ref<json::array_t&>(), json::type_error&);
|
||||||
CHECK_THROWS(value.get_ref<json::number_integer_t&>());
|
CHECK_THROWS_WITH(value.get_ref<json::array_t&>(),
|
||||||
|
"[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is number");
|
||||||
|
CHECK_THROWS_AS(value.get_ref<json::string_t&>(), json::type_error&);
|
||||||
|
CHECK_THROWS_WITH(value.get_ref<json::string_t&>(),
|
||||||
|
"[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is number");
|
||||||
|
CHECK_THROWS_AS(value.get_ref<json::boolean_t&>(), json::type_error&);
|
||||||
|
CHECK_THROWS_WITH(value.get_ref<json::boolean_t&>(),
|
||||||
|
"[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is number");
|
||||||
|
CHECK_THROWS_AS(value.get_ref<json::number_integer_t&>(), json::type_error&);
|
||||||
|
CHECK_THROWS_WITH(value.get_ref<json::number_integer_t&>(),
|
||||||
|
"[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is number");
|
||||||
|
CHECK_THROWS_AS(value.get_ref<json::number_unsigned_t&>(), json::type_error&);
|
||||||
|
CHECK_THROWS_WITH(value.get_ref<json::number_unsigned_t&>(),
|
||||||
|
"[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is number");
|
||||||
CHECK_NOTHROW(value.get_ref<json::number_float_t&>());
|
CHECK_NOTHROW(value.get_ref<json::number_float_t&>());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue