mirror of
https://github.com/nlohmann/json.git
synced 2026-03-10 19:21:26 +00:00
Refactor unit tests to use more convenient doctest assertion macros (#3393)
* Add missing check * Refactor assertions in unit-algorithms.cpp * Refactor assertions in unit-bson.cpp * Refactor assertions in unit-cbor.cpp * Refactor assertions in unit-class_const_iterator.cpp * Refactor assertions in unit-class_iterator.cpp * Refactor assertions in unit-class_parser.cpp * Refactor assertions in unit-constructor1.cpp * Refactor assertions in unit-convenience.cpp * Refactor assertions in unit-conversions.cpp * Refactor assertions in unit-deserialization.cpp * Refactor assertions in unit-element_access1.cpp * Refactor assertions in unit-element_access2.cpp * Refactor assertions in unit-iterators1.cpp * Refactor assertions in unit-iterators2.cpp * Refactor assertions in unit-json_patch.cpp * Refactor assertions in unit-json_pointer.cpp * Refactor assertions in unit-modifiers.cpp * Refactor assertions in unit-msgpack.cpp * Refactor assertions in unit-reference_access.cpp * Refactor assertions in unit-regression1.cpp * Refactor assertions in unit-serialization.cpp * Refactor assertions in unit-ubjson.cpp * Refactor assertions in unit-unicode1.cpp * Apply formatting
This commit is contained in:
committed by
GitHub
parent
ad103e5b45
commit
ce35256825
@@ -198,8 +198,7 @@ TEST_CASE("modifiers")
|
||||
SECTION("other type")
|
||||
{
|
||||
json j = 1;
|
||||
CHECK_THROWS_AS(j.push_back("Hello"), json::type_error&);
|
||||
CHECK_THROWS_WITH(j.push_back("Hello"), "[json.exception.type_error.308] cannot use push_back() with number");
|
||||
CHECK_THROWS_WITH_AS(j.push_back("Hello"), "[json.exception.type_error.308] cannot use push_back() with number", json::type_error&);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -228,8 +227,7 @@ TEST_CASE("modifiers")
|
||||
{
|
||||
json j = 1;
|
||||
json k("Hello");
|
||||
CHECK_THROWS_AS(j.push_back(k), json::type_error&);
|
||||
CHECK_THROWS_WITH(j.push_back(k), "[json.exception.type_error.308] cannot use push_back() with number");
|
||||
CHECK_THROWS_WITH_AS(j.push_back(k), "[json.exception.type_error.308] cannot use push_back() with number", json::type_error&);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -261,9 +259,7 @@ TEST_CASE("modifiers")
|
||||
{
|
||||
json j = 1;
|
||||
json k("Hello");
|
||||
CHECK_THROWS_AS(j.push_back(json::object_t::value_type({"one", 1})), json::type_error&);
|
||||
CHECK_THROWS_WITH(j.push_back(json::object_t::value_type({"one", 1})),
|
||||
"[json.exception.type_error.308] cannot use push_back() with number");
|
||||
CHECK_THROWS_WITH_AS(j.push_back(json::object_t::value_type({"one", 1})), "[json.exception.type_error.308] cannot use push_back() with number", json::type_error&);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -298,12 +294,9 @@ TEST_CASE("modifiers")
|
||||
CHECK(j == json({{"key1", 1}, {"key2", "bar"}}));
|
||||
|
||||
// invalid values (no string/val pair)
|
||||
CHECK_THROWS_AS(j.push_back({1}), json::type_error&);
|
||||
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");
|
||||
CHECK_THROWS_WITH_AS(j.push_back({1}), "[json.exception.type_error.308] cannot use push_back() with object", json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(j.push_back({1, 2}), "[json.exception.type_error.308] cannot use push_back() with object", json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(j.push_back({1, 2, 3, 4}), "[json.exception.type_error.308] cannot use push_back() with object", json::type_error&);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -345,9 +338,7 @@ TEST_CASE("modifiers")
|
||||
SECTION("other type")
|
||||
{
|
||||
json j = 1;
|
||||
CHECK_THROWS_AS(j.emplace_back("Hello"), json::type_error&);
|
||||
CHECK_THROWS_WITH(j.emplace_back("Hello"),
|
||||
"[json.exception.type_error.311] cannot use emplace_back() with number");
|
||||
CHECK_THROWS_WITH_AS(j.emplace_back("Hello"), "[json.exception.type_error.311] cannot use emplace_back() with number", json::type_error&);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -405,9 +396,7 @@ TEST_CASE("modifiers")
|
||||
SECTION("other type")
|
||||
{
|
||||
json j = 1;
|
||||
CHECK_THROWS_AS(j.emplace("foo", "bar"), json::type_error&);
|
||||
CHECK_THROWS_WITH(j.emplace("foo", "bar"),
|
||||
"[json.exception.type_error.311] cannot use emplace() with number");
|
||||
CHECK_THROWS_WITH_AS(j.emplace("foo", "bar"), "[json.exception.type_error.311] cannot use emplace() with number", json::type_error&);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -437,8 +426,7 @@ TEST_CASE("modifiers")
|
||||
SECTION("other type")
|
||||
{
|
||||
json j = 1;
|
||||
CHECK_THROWS_AS(j += "Hello", json::type_error&);
|
||||
CHECK_THROWS_WITH(j += "Hello", "[json.exception.type_error.308] cannot use push_back() with number");
|
||||
CHECK_THROWS_WITH_AS(j += "Hello", "[json.exception.type_error.308] cannot use push_back() with number", json::type_error&);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -467,8 +455,7 @@ TEST_CASE("modifiers")
|
||||
{
|
||||
json j = 1;
|
||||
json k("Hello");
|
||||
CHECK_THROWS_AS(j += k, json::type_error&);
|
||||
CHECK_THROWS_WITH(j += k, "[json.exception.type_error.308] cannot use push_back() with number");
|
||||
CHECK_THROWS_WITH_AS(j += k, "[json.exception.type_error.308] cannot use push_back() with number", json::type_error&);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -500,9 +487,7 @@ TEST_CASE("modifiers")
|
||||
{
|
||||
json j = 1;
|
||||
json k("Hello");
|
||||
CHECK_THROWS_AS(j += json::object_t::value_type({"one", 1}), json::type_error&);
|
||||
CHECK_THROWS_WITH(j += json::object_t::value_type({"one", 1}),
|
||||
"[json.exception.type_error.308] cannot use push_back() with number");
|
||||
CHECK_THROWS_WITH_AS(j += json::object_t::value_type({"one", 1}), "[json.exception.type_error.308] cannot use push_back() with number", json::type_error&);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -537,8 +522,7 @@ TEST_CASE("modifiers")
|
||||
CHECK(j == json({{"key1", 1}, {"key2", "bar"}}));
|
||||
|
||||
json k = {{"key1", 1}};
|
||||
CHECK_THROWS_AS((k += {1, 2, 3, 4}), json::type_error&);
|
||||
CHECK_THROWS_WITH((k += {1, 2, 3, 4}), "[json.exception.type_error.308] cannot use push_back() with object");
|
||||
CHECK_THROWS_WITH_AS((k += {1, 2, 3, 4}), "[json.exception.type_error.308] cannot use push_back() with object", json::type_error&);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -673,15 +657,10 @@ TEST_CASE("modifiers")
|
||||
{
|
||||
json j_other_array2 = {"first", "second"};
|
||||
|
||||
CHECK_THROWS_AS(j_array.insert(j_array.end(), j_array.begin(), j_array.end()),
|
||||
json::invalid_iterator&);
|
||||
CHECK_THROWS_AS(j_array.insert(j_array.end(), j_other_array.begin(), j_other_array2.end()),
|
||||
json::invalid_iterator&);
|
||||
|
||||
CHECK_THROWS_WITH(j_array.insert(j_array.end(), j_array.begin(), j_array.end()),
|
||||
"[json.exception.invalid_iterator.211] passed iterators may not belong to container");
|
||||
CHECK_THROWS_WITH(j_array.insert(j_array.end(), j_other_array.begin(), j_other_array2.end()),
|
||||
"[json.exception.invalid_iterator.210] iterators do not fit");
|
||||
CHECK_THROWS_WITH_AS(j_array.insert(j_array.end(), j_array.begin(), j_array.end()), "[json.exception.invalid_iterator.211] passed iterators may not belong to container",
|
||||
json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(j_array.insert(j_array.end(), j_other_array.begin(), j_other_array2.end()), "[json.exception.invalid_iterator.210] iterators do not fit",
|
||||
json::invalid_iterator&);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -706,16 +685,9 @@ TEST_CASE("modifiers")
|
||||
{
|
||||
json j_other_array2 = {"first", "second"};
|
||||
|
||||
CHECK_THROWS_AS(j_array.insert(j_object2.begin(), j_object2.end()), json::type_error&);
|
||||
CHECK_THROWS_AS(j_object1.insert(j_object1.begin(), j_object2.end()), json::invalid_iterator&);
|
||||
CHECK_THROWS_AS(j_object1.insert(j_array.begin(), j_array.end()), json::invalid_iterator&);
|
||||
|
||||
CHECK_THROWS_WITH(j_array.insert(j_object2.begin(), j_object2.end()),
|
||||
"[json.exception.type_error.309] cannot use insert() with array");
|
||||
CHECK_THROWS_WITH(j_object1.insert(j_object1.begin(), j_object2.end()),
|
||||
"[json.exception.invalid_iterator.210] iterators do not fit");
|
||||
CHECK_THROWS_WITH(j_object1.insert(j_array.begin(), j_array.end()),
|
||||
"[json.exception.invalid_iterator.202] iterators first and last must point to objects");
|
||||
CHECK_THROWS_WITH_AS(j_array.insert(j_object2.begin(), j_object2.end()), "[json.exception.type_error.309] cannot use insert() with array", json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(j_object1.insert(j_object1.begin(), j_object2.end()), "[json.exception.invalid_iterator.210] iterators do not fit", json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(j_object1.insert(j_array.begin(), j_array.end()), "[json.exception.invalid_iterator.202] iterators first and last must point to objects", json::invalid_iterator&);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -754,22 +726,11 @@ TEST_CASE("modifiers")
|
||||
// pass iterator to a different array
|
||||
json j_another_array = {1, 2};
|
||||
json j_yet_another_array = {"first", "second"};
|
||||
CHECK_THROWS_AS(j_array.insert(j_another_array.end(), 10), json::invalid_iterator&);
|
||||
CHECK_THROWS_AS(j_array.insert(j_another_array.end(), j_value), json::invalid_iterator&);
|
||||
CHECK_THROWS_AS(j_array.insert(j_another_array.end(), 10, 11), json::invalid_iterator&);
|
||||
CHECK_THROWS_AS(j_array.insert(j_another_array.end(), j_yet_another_array.begin(), j_yet_another_array.end()), json::invalid_iterator&);
|
||||
CHECK_THROWS_AS(j_array.insert(j_another_array.end(), {1, 2, 3, 4}), json::invalid_iterator&);
|
||||
|
||||
CHECK_THROWS_WITH(j_array.insert(j_another_array.end(), 10),
|
||||
"[json.exception.invalid_iterator.202] iterator does not fit current value");
|
||||
CHECK_THROWS_WITH(j_array.insert(j_another_array.end(), j_value),
|
||||
"[json.exception.invalid_iterator.202] iterator does not fit current value");
|
||||
CHECK_THROWS_WITH(j_array.insert(j_another_array.end(), 10, 11),
|
||||
"[json.exception.invalid_iterator.202] iterator does not fit current value");
|
||||
CHECK_THROWS_WITH(j_array.insert(j_another_array.end(), j_yet_another_array.begin(), j_yet_another_array.end()),
|
||||
"[json.exception.invalid_iterator.202] iterator does not fit current value");
|
||||
CHECK_THROWS_WITH(j_array.insert(j_another_array.end(), {1, 2, 3, 4}),
|
||||
"[json.exception.invalid_iterator.202] iterator does not fit current value");
|
||||
CHECK_THROWS_WITH_AS(j_array.insert(j_another_array.end(), 10), "[json.exception.invalid_iterator.202] iterator does not fit current value", json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(j_array.insert(j_another_array.end(), j_value), "[json.exception.invalid_iterator.202] iterator does not fit current value", json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(j_array.insert(j_another_array.end(), 10, 11), "[json.exception.invalid_iterator.202] iterator does not fit current value", json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(j_array.insert(j_another_array.end(), j_yet_another_array.begin(), j_yet_another_array.end()), "[json.exception.invalid_iterator.202] iterator does not fit current value", json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(j_array.insert(j_another_array.end(), {1, 2, 3, 4}), "[json.exception.invalid_iterator.202] iterator does not fit current value", json::invalid_iterator&);
|
||||
}
|
||||
|
||||
SECTION("non-array type")
|
||||
@@ -777,20 +738,11 @@ TEST_CASE("modifiers")
|
||||
// call insert on a non-array type
|
||||
json j_nonarray = 3;
|
||||
json j_yet_another_array = {"first", "second"};
|
||||
CHECK_THROWS_AS(j_nonarray.insert(j_nonarray.end(), 10), json::type_error&);
|
||||
CHECK_THROWS_AS(j_nonarray.insert(j_nonarray.end(), j_value), json::type_error&);
|
||||
CHECK_THROWS_AS(j_nonarray.insert(j_nonarray.end(), 10, 11), json::type_error&);
|
||||
CHECK_THROWS_AS(j_nonarray.insert(j_nonarray.end(), j_yet_another_array.begin(),
|
||||
j_yet_another_array.end()), json::type_error&);
|
||||
CHECK_THROWS_AS(j_nonarray.insert(j_nonarray.end(), {1, 2, 3, 4}), json::type_error&);
|
||||
|
||||
CHECK_THROWS_WITH(j_nonarray.insert(j_nonarray.end(), 10), "[json.exception.type_error.309] cannot use insert() with number");
|
||||
CHECK_THROWS_WITH(j_nonarray.insert(j_nonarray.end(), j_value), "[json.exception.type_error.309] cannot use insert() with number");
|
||||
CHECK_THROWS_WITH(j_nonarray.insert(j_nonarray.end(), 10, 11), "[json.exception.type_error.309] cannot use insert() with number");
|
||||
CHECK_THROWS_WITH(j_nonarray.insert(j_nonarray.end(), j_yet_another_array.begin(),
|
||||
j_yet_another_array.end()), "[json.exception.type_error.309] cannot use insert() with number");
|
||||
CHECK_THROWS_WITH(j_nonarray.insert(j_nonarray.end(), {1, 2, 3, 4}),
|
||||
"[json.exception.type_error.309] cannot use insert() with number");
|
||||
CHECK_THROWS_WITH_AS(j_nonarray.insert(j_nonarray.end(), 10), "[json.exception.type_error.309] cannot use insert() with number", json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(j_nonarray.insert(j_nonarray.end(), j_value), "[json.exception.type_error.309] cannot use insert() with number", json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(j_nonarray.insert(j_nonarray.end(), 10, 11), "[json.exception.type_error.309] cannot use insert() with number", json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(j_nonarray.insert(j_nonarray.end(), j_yet_another_array.begin(), j_yet_another_array.end()), "[json.exception.type_error.309] cannot use insert() with number", json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(j_nonarray.insert(j_nonarray.end(), {1, 2, 3, 4}), "[json.exception.type_error.309] cannot use insert() with number", json::type_error&);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -816,11 +768,9 @@ TEST_CASE("modifiers")
|
||||
|
||||
SECTION("wrong types")
|
||||
{
|
||||
CHECK_THROWS_AS(j_array.update(j_object1), json::type_error&);
|
||||
CHECK_THROWS_WITH(j_array.update(j_object1), "[json.exception.type_error.312] cannot use update() with array");
|
||||
CHECK_THROWS_WITH_AS(j_array.update(j_object1), "[json.exception.type_error.312] cannot use update() with array", json::type_error&);
|
||||
|
||||
CHECK_THROWS_AS(j_object1.update(j_array), json::type_error&);
|
||||
CHECK_THROWS_WITH(j_object1.update(j_array), "[json.exception.type_error.312] cannot use update() with array");
|
||||
CHECK_THROWS_WITH_AS(j_object1.update(j_array), "[json.exception.type_error.312] cannot use update() with array", json::type_error&);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -846,16 +796,9 @@ TEST_CASE("modifiers")
|
||||
{
|
||||
json j_other_array2 = {"first", "second"};
|
||||
|
||||
CHECK_THROWS_AS(j_array.update(j_object2.begin(), j_object2.end()), json::type_error&);
|
||||
CHECK_THROWS_AS(j_object1.update(j_object1.begin(), j_object2.end()), json::invalid_iterator&);
|
||||
CHECK_THROWS_AS(j_object1.update(j_array.begin(), j_array.end()), json::type_error&);
|
||||
|
||||
CHECK_THROWS_WITH(j_array.update(j_object2.begin(), j_object2.end()),
|
||||
"[json.exception.type_error.312] cannot use update() with array");
|
||||
CHECK_THROWS_WITH(j_object1.update(j_object1.begin(), j_object2.end()),
|
||||
"[json.exception.invalid_iterator.210] iterators do not fit");
|
||||
CHECK_THROWS_WITH(j_object1.update(j_array.begin(), j_array.end()),
|
||||
"[json.exception.type_error.312] cannot use update() with array");
|
||||
CHECK_THROWS_WITH_AS(j_array.update(j_object2.begin(), j_object2.end()), "[json.exception.type_error.312] cannot use update() with array", json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(j_object1.update(j_object1.begin(), j_object2.end()), "[json.exception.invalid_iterator.210] iterators do not fit", json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(j_object1.update(j_array.begin(), j_array.end()), "[json.exception.type_error.312] cannot use update() with array", json::type_error&);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -932,8 +875,7 @@ TEST_CASE("modifiers")
|
||||
json j = 17;
|
||||
json::array_t a = {"foo", "bar", "baz"};
|
||||
|
||||
CHECK_THROWS_AS(j.swap(a), json::type_error&);
|
||||
CHECK_THROWS_WITH(j.swap(a), "[json.exception.type_error.310] cannot use swap() with number");
|
||||
CHECK_THROWS_WITH_AS(j.swap(a), "[json.exception.type_error.310] cannot use swap() with number", json::type_error&);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -958,8 +900,7 @@ TEST_CASE("modifiers")
|
||||
json j = 17;
|
||||
json::object_t o = {{"cow", "Kuh"}, {"chicken", "Huhn"}};
|
||||
|
||||
CHECK_THROWS_AS(j.swap(o), json::type_error&);
|
||||
CHECK_THROWS_WITH(j.swap(o), "[json.exception.type_error.310] cannot use swap() with number");
|
||||
CHECK_THROWS_WITH_AS(j.swap(o), "[json.exception.type_error.310] cannot use swap() with number", json::type_error&);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -984,8 +925,7 @@ TEST_CASE("modifiers")
|
||||
json j = 17;
|
||||
json::string_t s = "Hallo Welt";
|
||||
|
||||
CHECK_THROWS_AS(j.swap(s), json::type_error&);
|
||||
CHECK_THROWS_WITH(j.swap(s), "[json.exception.type_error.310] cannot use swap() with number");
|
||||
CHECK_THROWS_WITH_AS(j.swap(s), "[json.exception.type_error.310] cannot use swap() with number", json::type_error&);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user