🚧 move to Catch2
This commit is contained in:
parent
3fedcbb46f
commit
942b8affbe
@ -95,7 +95,7 @@ foreach(file ${files})
|
||||
)
|
||||
else()
|
||||
add_test(NAME "${testcase}_cpp17"
|
||||
COMMAND ${testcase}_cpp17 ${DOCTEST_TEST_FILTER} --no-skip
|
||||
COMMAND ${testcase}_cpp17 ${DOCTEST_TEST_FILTER} "*"
|
||||
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
|
||||
)
|
||||
endif()
|
||||
@ -110,7 +110,7 @@ foreach(file ${files})
|
||||
)
|
||||
else()
|
||||
add_test(NAME "${testcase}"
|
||||
COMMAND ${testcase} ${DOCTEST_TEST_FILTER} --no-skip
|
||||
COMMAND ${testcase} ${DOCTEST_TEST_FILTER} "*"
|
||||
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
|
||||
)
|
||||
endif()
|
||||
|
||||
@ -61,7 +61,7 @@ TEST_CASE("JSON_ASSERT(x)")
|
||||
CHECK_THROWS_WITH(json(it, j.end()), "[json.exception.invalid_iterator.201] iterators are not compatible");
|
||||
|
||||
// check that assertion actually happened
|
||||
CHECK(assert_counter == 1);
|
||||
CHECK(assert_counter == 2);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
@ -450,7 +450,7 @@ TEST_CASE("CBOR")
|
||||
{
|
||||
for (size_t i = 24; i <= 255; ++i)
|
||||
{
|
||||
CAPTURE(i)
|
||||
CAPTURE(i);
|
||||
|
||||
// create JSON value with integer number
|
||||
json j = -1;
|
||||
@ -521,7 +521,7 @@ TEST_CASE("CBOR")
|
||||
65536u, 77777u, 1048576u
|
||||
})
|
||||
{
|
||||
CAPTURE(i)
|
||||
CAPTURE(i);
|
||||
|
||||
// create JSON value with integer number
|
||||
json j = -1;
|
||||
@ -648,7 +648,7 @@ TEST_CASE("CBOR")
|
||||
{
|
||||
for (size_t i = 0; i <= 23; ++i)
|
||||
{
|
||||
CAPTURE(i)
|
||||
CAPTURE(i);
|
||||
|
||||
// create JSON value with unsigned integer number
|
||||
json j = i;
|
||||
@ -711,7 +711,7 @@ TEST_CASE("CBOR")
|
||||
{
|
||||
for (size_t i = 256; i <= 65535; ++i)
|
||||
{
|
||||
CAPTURE(i)
|
||||
CAPTURE(i);
|
||||
|
||||
// create JSON value with unsigned integer number
|
||||
json j = i;
|
||||
@ -1097,7 +1097,7 @@ TEST_CASE("CBOR")
|
||||
{
|
||||
for (size_t N = 0; N <= 0x17; ++N)
|
||||
{
|
||||
CAPTURE(N)
|
||||
CAPTURE(N);
|
||||
|
||||
// create JSON value with string containing of N * 'x'
|
||||
const auto s = std::string(N, 'x');
|
||||
@ -1131,7 +1131,7 @@ TEST_CASE("CBOR")
|
||||
{
|
||||
for (size_t N = 24; N <= 255; ++N)
|
||||
{
|
||||
CAPTURE(N)
|
||||
CAPTURE(N);
|
||||
|
||||
// create JSON value with string containing of N * 'x'
|
||||
const auto s = std::string(N, 'x');
|
||||
@ -1166,7 +1166,7 @@ TEST_CASE("CBOR")
|
||||
256u, 999u, 1025u, 3333u, 2048u, 65535u
|
||||
})
|
||||
{
|
||||
CAPTURE(N)
|
||||
CAPTURE(N);
|
||||
|
||||
// create JSON value with string containing of N * 'x'
|
||||
const auto s = std::string(N, 'x');
|
||||
@ -1199,7 +1199,7 @@ TEST_CASE("CBOR")
|
||||
65536u, 77777u, 1048576u
|
||||
})
|
||||
{
|
||||
CAPTURE(N)
|
||||
CAPTURE(N);
|
||||
|
||||
// create JSON value with string containing of N * 'x'
|
||||
const auto s = std::string(N, 'x');
|
||||
@ -1446,7 +1446,7 @@ TEST_CASE("CBOR")
|
||||
{
|
||||
for (size_t N = 0; N <= 0x17; ++N)
|
||||
{
|
||||
CAPTURE(N)
|
||||
CAPTURE(N);
|
||||
|
||||
// create JSON value with byte array containing of N * 'x'
|
||||
const auto s = std::vector<uint8_t>(N, 'x');
|
||||
@ -1480,7 +1480,7 @@ TEST_CASE("CBOR")
|
||||
{
|
||||
for (size_t N = 24; N <= 255; ++N)
|
||||
{
|
||||
CAPTURE(N)
|
||||
CAPTURE(N);
|
||||
|
||||
// create JSON value with string containing of N * 'x'
|
||||
const auto s = std::vector<uint8_t>(N, 'x');
|
||||
@ -1515,7 +1515,7 @@ TEST_CASE("CBOR")
|
||||
256u, 999u, 1025u, 3333u, 2048u, 65535u
|
||||
})
|
||||
{
|
||||
CAPTURE(N)
|
||||
CAPTURE(N);
|
||||
|
||||
// create JSON value with string containing of N * 'x'
|
||||
const auto s = std::vector<uint8_t>(N, 'x');
|
||||
@ -1548,7 +1548,7 @@ TEST_CASE("CBOR")
|
||||
65536u, 77777u, 1048576u
|
||||
})
|
||||
{
|
||||
CAPTURE(N)
|
||||
CAPTURE(N);
|
||||
|
||||
// create JSON value with string containing of N * 'x'
|
||||
const auto s = std::vector<uint8_t>(N, 'x');
|
||||
@ -1582,7 +1582,7 @@ TEST_CASE("CBOR")
|
||||
auto j = json::from_cbor(input);
|
||||
CHECK(j.is_binary());
|
||||
auto k = json::binary({0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff, 0x99});
|
||||
CAPTURE(j.dump(0, ' ', false, json::error_handler_t::strict))
|
||||
CAPTURE(j.dump(0, ' ', false, json::error_handler_t::strict));
|
||||
CHECK(j == k);
|
||||
}
|
||||
|
||||
@ -1989,7 +1989,7 @@ TEST_CASE("CBOR regressions")
|
||||
TEST_DATA_DIRECTORY "/cbor_regression/test21"
|
||||
})
|
||||
{
|
||||
CAPTURE(filename)
|
||||
CAPTURE(filename);
|
||||
|
||||
try
|
||||
{
|
||||
@ -2023,7 +2023,7 @@ TEST_CASE("CBOR regressions")
|
||||
}
|
||||
#endif
|
||||
|
||||
TEST_CASE("CBOR roundtrips" * doctest::skip())
|
||||
TEST_CASE("CBOR roundtrips", "[.]")
|
||||
{
|
||||
SECTION("input from flynn")
|
||||
{
|
||||
@ -2190,10 +2190,10 @@ TEST_CASE("CBOR roundtrips" * doctest::skip())
|
||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_structure_whitespace_array.json"
|
||||
})
|
||||
{
|
||||
CAPTURE(filename)
|
||||
CAPTURE(filename);
|
||||
|
||||
{
|
||||
INFO_WITH_TEMP(filename + ": std::vector<uint8_t>");
|
||||
CAPTURE(filename + ": std::vector<uint8_t>");
|
||||
// parse JSON file
|
||||
std::ifstream f_json(filename);
|
||||
json j1 = json::parse(f_json);
|
||||
@ -2208,7 +2208,7 @@ TEST_CASE("CBOR roundtrips" * doctest::skip())
|
||||
}
|
||||
|
||||
{
|
||||
INFO_WITH_TEMP(filename + ": std::ifstream");
|
||||
CAPTURE(filename + ": std::ifstream");
|
||||
// parse JSON file
|
||||
std::ifstream f_json(filename);
|
||||
json j1 = json::parse(f_json);
|
||||
@ -2223,7 +2223,7 @@ TEST_CASE("CBOR roundtrips" * doctest::skip())
|
||||
}
|
||||
|
||||
{
|
||||
INFO_WITH_TEMP(filename + ": uint8_t* and size");
|
||||
CAPTURE(filename + ": uint8_t* and size");
|
||||
// parse JSON file
|
||||
std::ifstream f_json(filename);
|
||||
json j1 = json::parse(f_json);
|
||||
@ -2238,7 +2238,7 @@ TEST_CASE("CBOR roundtrips" * doctest::skip())
|
||||
}
|
||||
|
||||
{
|
||||
INFO_WITH_TEMP(filename + ": output to output adapters");
|
||||
CAPTURE(filename + ": output to output adapters");
|
||||
// parse JSON file
|
||||
std::ifstream f_json(filename);
|
||||
json j1 = json::parse(f_json);
|
||||
@ -2249,7 +2249,7 @@ TEST_CASE("CBOR roundtrips" * doctest::skip())
|
||||
if (exclude_packed.count(filename) == 0u)
|
||||
{
|
||||
{
|
||||
INFO_WITH_TEMP(filename + ": output adapters: std::vector<uint8_t>");
|
||||
CAPTURE(filename + ": output adapters: std::vector<uint8_t>");
|
||||
std::vector<uint8_t> vec;
|
||||
json::to_cbor(j1, vec);
|
||||
CHECK(vec == packed);
|
||||
@ -2319,7 +2319,7 @@ TEST_CASE("all CBOR first bytes")
|
||||
{
|
||||
// check that parse_error.112 is only thrown if the
|
||||
// first byte is in the unsupported set
|
||||
INFO_WITH_TEMP(e.what());
|
||||
CAPTURE(e.what());
|
||||
if (unsupported.find(byte) != unsupported.end())
|
||||
{
|
||||
CHECK(e.id == 112);
|
||||
|
||||
@ -1173,7 +1173,7 @@ TEST_CASE("parser class")
|
||||
if (c > 0x1f)
|
||||
{
|
||||
CHECK_THROWS_WITH(parser_helper(s),
|
||||
"[json.exception.parse_error.101] parse error at line 1, column 3: syntax error while parsing value - invalid string: forbidden character after backslash; last read: '\"\\" + std::string(1, static_cast<char>(c)) + "'");
|
||||
"[json.exception.parse_error.101] parse error at line 1, column 3: syntax error while parsing value - invalid string: forbidden character after backslash; last read: '\"\\" + std::string(1, static_cast<char>(c)) + "'");
|
||||
}
|
||||
break;
|
||||
}
|
||||
@ -1249,7 +1249,7 @@ TEST_CASE("parser class")
|
||||
if (c > 0x1f)
|
||||
{
|
||||
CHECK_THROWS_WITH(parser_helper(s1),
|
||||
"[json.exception.parse_error.101] parse error at line 1, column 7: syntax error while parsing value - invalid string: '\\u' must be followed by 4 hex digits; last read: '" + s1.substr(0, 7) + "'");
|
||||
"[json.exception.parse_error.101] parse error at line 1, column 7: syntax error while parsing value - invalid string: '\\u' must be followed by 4 hex digits; last read: '" + s1.substr(0, 7) + "'");
|
||||
}
|
||||
|
||||
CAPTURE(s2);
|
||||
@ -1258,7 +1258,7 @@ TEST_CASE("parser class")
|
||||
if (c > 0x1f)
|
||||
{
|
||||
CHECK_THROWS_WITH(parser_helper(s2),
|
||||
"[json.exception.parse_error.101] parse error at line 1, column 6: syntax error while parsing value - invalid string: '\\u' must be followed by 4 hex digits; last read: '" + s2.substr(0, 6) + "'");
|
||||
"[json.exception.parse_error.101] parse error at line 1, column 6: syntax error while parsing value - invalid string: '\\u' must be followed by 4 hex digits; last read: '" + s2.substr(0, 6) + "'");
|
||||
}
|
||||
|
||||
CAPTURE(s3);
|
||||
@ -1267,7 +1267,7 @@ TEST_CASE("parser class")
|
||||
if (c > 0x1f)
|
||||
{
|
||||
CHECK_THROWS_WITH(parser_helper(s3),
|
||||
"[json.exception.parse_error.101] parse error at line 1, column 5: syntax error while parsing value - invalid string: '\\u' must be followed by 4 hex digits; last read: '" + s3.substr(0, 5) + "'");
|
||||
"[json.exception.parse_error.101] parse error at line 1, column 5: syntax error while parsing value - invalid string: '\\u' must be followed by 4 hex digits; last read: '" + s3.substr(0, 5) + "'");
|
||||
}
|
||||
|
||||
CAPTURE(s4);
|
||||
@ -1276,7 +1276,7 @@ TEST_CASE("parser class")
|
||||
if (c > 0x1f)
|
||||
{
|
||||
CHECK_THROWS_WITH(parser_helper(s4),
|
||||
"[json.exception.parse_error.101] parse error at line 1, column 4: syntax error while parsing value - invalid string: '\\u' must be followed by 4 hex digits; last read: '" + s4.substr(0, 4) + "'");
|
||||
"[json.exception.parse_error.101] parse error at line 1, column 4: syntax error while parsing value - invalid string: '\\u' must be followed by 4 hex digits; last read: '" + s4.substr(0, 4) + "'");
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1827,7 +1827,9 @@ TEST_CASE("parser class")
|
||||
SECTION("error messages for comments")
|
||||
{
|
||||
json _;
|
||||
CHECK_THROWS_WITH_AS(_ = json::parse("/a", nullptr, true, true), "[json.exception.parse_error.101] parse error at line 1, column 2: syntax error while parsing value - invalid comment; expecting '/' or '*' after '/'; last read: '/a'", json::parse_error);
|
||||
CHECK_THROWS_WITH_AS(_ = json::parse("/*", nullptr, true, true), "[json.exception.parse_error.101] parse error at line 1, column 3: syntax error while parsing value - invalid comment; missing closing '*/'; last read: '/*<U+0000>'", json::parse_error);
|
||||
CHECK_THROWS_WITH(_ = json::parse("/a", nullptr, true, true), "[json.exception.parse_error.101] parse error at line 1, column 2: syntax error while parsing value - invalid comment; expecting '/' or '*' after '/'; last read: '/a'");
|
||||
CHECK_THROWS_AS(_ = json::parse("/a", nullptr, true, true), json::parse_error);
|
||||
CHECK_THROWS_WITH(_ = json::parse("/*", nullptr, true, true), "[json.exception.parse_error.101] parse error at line 1, column 3: syntax error while parsing value - invalid comment; missing closing '*/'; last read: '/*<U+0000>'");
|
||||
CHECK_THROWS_AS(_ = json::parse("/*", nullptr, true, true), json::parse_error);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1310,69 +1310,89 @@ TEST_CASE("value conversion")
|
||||
const json j_string_const(json::value_t::string);
|
||||
const json j_boolean_const(json::value_t::boolean);
|
||||
|
||||
CHECK_THROWS_WITH_AS(j_null.get<json::binary_t>(),
|
||||
"[json.exception.type_error.302] type must be binary, but is null",
|
||||
json::type_error);
|
||||
CHECK_THROWS_WITH_AS(j_object.get<json::binary_t>(),
|
||||
"[json.exception.type_error.302] type must be binary, but is object",
|
||||
json::type_error);
|
||||
CHECK_THROWS_WITH_AS(j_array.get<json::binary_t>(),
|
||||
"[json.exception.type_error.302] type must be binary, but is array",
|
||||
json::type_error);
|
||||
CHECK_THROWS_WITH_AS(j_string.get<json::binary_t>(),
|
||||
"[json.exception.type_error.302] type must be binary, but is string",
|
||||
json::type_error);
|
||||
CHECK_THROWS_WITH_AS(j_boolean.get<json::binary_t>(),
|
||||
"[json.exception.type_error.302] type must be binary, but is boolean",
|
||||
json::type_error);
|
||||
CHECK_THROWS_WITH(j_null.get<json::binary_t>(),
|
||||
"[json.exception.type_error.302] type must be binary, but is null");
|
||||
CHECK_THROWS_AS(j_null.get<json::binary_t>(),
|
||||
json::type_error);
|
||||
CHECK_THROWS_WITH(j_object.get<json::binary_t>(),
|
||||
"[json.exception.type_error.302] type must be binary, but is object");
|
||||
CHECK_THROWS_AS(j_object.get<json::binary_t>(),
|
||||
json::type_error);
|
||||
CHECK_THROWS_WITH(j_array.get<json::binary_t>(),
|
||||
"[json.exception.type_error.302] type must be binary, but is array");
|
||||
CHECK_THROWS_AS(j_array.get<json::binary_t>(),
|
||||
json::type_error);
|
||||
CHECK_THROWS_WITH(j_string.get<json::binary_t>(),
|
||||
"[json.exception.type_error.302] type must be binary, but is string");
|
||||
CHECK_THROWS_AS(j_string.get<json::binary_t>(),
|
||||
json::type_error);
|
||||
CHECK_THROWS_WITH(j_boolean.get<json::binary_t>(),
|
||||
"[json.exception.type_error.302] type must be binary, but is boolean");
|
||||
CHECK_THROWS_AS(j_boolean.get<json::binary_t>(),
|
||||
json::type_error);
|
||||
|
||||
CHECK_THROWS_WITH_AS(j_null_const.get<json::binary_t>(),
|
||||
"[json.exception.type_error.302] type must be binary, but is null",
|
||||
json::type_error);
|
||||
CHECK_THROWS_WITH_AS(j_object_const.get<json::binary_t>(),
|
||||
"[json.exception.type_error.302] type must be binary, but is object",
|
||||
json::type_error);
|
||||
CHECK_THROWS_WITH_AS(j_array_const.get<json::binary_t>(),
|
||||
"[json.exception.type_error.302] type must be binary, but is array",
|
||||
json::type_error);
|
||||
CHECK_THROWS_WITH_AS(j_string_const.get<json::binary_t>(),
|
||||
"[json.exception.type_error.302] type must be binary, but is string",
|
||||
json::type_error);
|
||||
CHECK_THROWS_WITH_AS(j_boolean_const.get<json::binary_t>(),
|
||||
"[json.exception.type_error.302] type must be binary, but is boolean",
|
||||
json::type_error);
|
||||
CHECK_THROWS_WITH(j_null_const.get<json::binary_t>(),
|
||||
"[json.exception.type_error.302] type must be binary, but is null");
|
||||
CHECK_THROWS_AS(j_null_const.get<json::binary_t>(),
|
||||
json::type_error);
|
||||
CHECK_THROWS_WITH(j_object_const.get<json::binary_t>(),
|
||||
"[json.exception.type_error.302] type must be binary, but is object");
|
||||
CHECK_THROWS_AS(j_object_const.get<json::binary_t>(),
|
||||
json::type_error);
|
||||
CHECK_THROWS_WITH(j_array_const.get<json::binary_t>(),
|
||||
"[json.exception.type_error.302] type must be binary, but is array");
|
||||
CHECK_THROWS_AS(j_array_const.get<json::binary_t>(),
|
||||
json::type_error);
|
||||
CHECK_THROWS_WITH(j_string_const.get<json::binary_t>(),
|
||||
"[json.exception.type_error.302] type must be binary, but is string");
|
||||
CHECK_THROWS_AS(j_string_const.get<json::binary_t>(),
|
||||
json::type_error);
|
||||
CHECK_THROWS_WITH(j_boolean_const.get<json::binary_t>(),
|
||||
"[json.exception.type_error.302] type must be binary, but is boolean");
|
||||
CHECK_THROWS_AS(j_boolean_const.get<json::binary_t>(),
|
||||
json::type_error);
|
||||
|
||||
CHECK_THROWS_WITH_AS(j_null.get_binary(),
|
||||
"[json.exception.type_error.302] type must be binary, but is null",
|
||||
json::type_error);
|
||||
CHECK_THROWS_WITH_AS(j_object.get_binary(),
|
||||
"[json.exception.type_error.302] type must be binary, but is object",
|
||||
json::type_error);
|
||||
CHECK_THROWS_WITH_AS(j_array.get_binary(),
|
||||
"[json.exception.type_error.302] type must be binary, but is array",
|
||||
json::type_error);
|
||||
CHECK_THROWS_WITH_AS(j_string.get_binary(),
|
||||
"[json.exception.type_error.302] type must be binary, but is string",
|
||||
json::type_error);
|
||||
CHECK_THROWS_WITH_AS(j_boolean.get_binary(),
|
||||
"[json.exception.type_error.302] type must be binary, but is boolean",
|
||||
json::type_error);
|
||||
CHECK_THROWS_WITH(j_null.get_binary(),
|
||||
"[json.exception.type_error.302] type must be binary, but is null");
|
||||
CHECK_THROWS_AS(j_null.get_binary(),
|
||||
json::type_error);
|
||||
CHECK_THROWS_WITH(j_object.get_binary(),
|
||||
"[json.exception.type_error.302] type must be binary, but is object");
|
||||
CHECK_THROWS_AS(j_object.get_binary(),
|
||||
json::type_error);
|
||||
CHECK_THROWS_WITH(j_array.get_binary(),
|
||||
"[json.exception.type_error.302] type must be binary, but is array");
|
||||
CHECK_THROWS_AS(j_array.get_binary(),
|
||||
json::type_error);
|
||||
CHECK_THROWS_WITH(j_string.get_binary(),
|
||||
"[json.exception.type_error.302] type must be binary, but is string");
|
||||
CHECK_THROWS_AS(j_string.get_binary(),
|
||||
json::type_error);
|
||||
CHECK_THROWS_WITH(j_boolean.get_binary(),
|
||||
"[json.exception.type_error.302] type must be binary, but is boolean");
|
||||
CHECK_THROWS_AS(j_boolean.get_binary(),
|
||||
json::type_error);
|
||||
|
||||
CHECK_THROWS_WITH_AS(j_null_const.get_binary(),
|
||||
"[json.exception.type_error.302] type must be binary, but is null",
|
||||
json::type_error);
|
||||
CHECK_THROWS_WITH_AS(j_object_const.get_binary(),
|
||||
"[json.exception.type_error.302] type must be binary, but is object",
|
||||
json::type_error);
|
||||
CHECK_THROWS_WITH_AS(j_array_const.get_binary(),
|
||||
"[json.exception.type_error.302] type must be binary, but is array",
|
||||
json::type_error);
|
||||
CHECK_THROWS_WITH_AS(j_string_const.get_binary(),
|
||||
"[json.exception.type_error.302] type must be binary, but is string",
|
||||
json::type_error);
|
||||
CHECK_THROWS_WITH_AS(j_boolean_const.get_binary(),
|
||||
"[json.exception.type_error.302] type must be binary, but is boolean",
|
||||
json::type_error);
|
||||
CHECK_THROWS_WITH(j_null_const.get_binary(),
|
||||
"[json.exception.type_error.302] type must be binary, but is null");
|
||||
CHECK_THROWS_AS(j_null_const.get_binary(),
|
||||
json::type_error);
|
||||
CHECK_THROWS_WITH(j_object_const.get_binary(),
|
||||
"[json.exception.type_error.302] type must be binary, but is object");
|
||||
CHECK_THROWS_AS(j_object_const.get_binary(),
|
||||
json::type_error);
|
||||
CHECK_THROWS_WITH(j_array_const.get_binary(),
|
||||
"[json.exception.type_error.302] type must be binary, but is array");
|
||||
CHECK_THROWS_AS(j_array_const.get_binary(),
|
||||
json::type_error);
|
||||
CHECK_THROWS_WITH(j_string_const.get_binary(),
|
||||
"[json.exception.type_error.302] type must be binary, but is string");
|
||||
CHECK_THROWS_AS(j_string_const.get_binary(),
|
||||
json::type_error);
|
||||
CHECK_THROWS_WITH(j_boolean_const.get_binary(),
|
||||
"[json.exception.type_error.302] type must be binary, but is boolean");
|
||||
CHECK_THROWS_AS(j_boolean_const.get_binary(),
|
||||
json::type_error);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1717,4 +1737,4 @@ TEST_CASE("JSON to enum mapping")
|
||||
#undef JSON_HAS_CPP_14
|
||||
#endif
|
||||
|
||||
DOCTEST_CLANG_SUPPRESS_WARNING_POP
|
||||
//DOCTEST_CLANG_SUPPRESS_WARNING_POP
|
||||
|
||||
@ -110,8 +110,10 @@ TEST_CASE("Better diagnostics")
|
||||
json j = {{"foo", "bar"}};
|
||||
json k = {{"bla", 1}};
|
||||
|
||||
CHECK_THROWS_WITH_AS(j.update(k["bla"].begin(), k["bla"].end()), "[json.exception.type_error.312] (/bla) cannot use update() with number", json::type_error);
|
||||
CHECK_THROWS_WITH_AS(j.update(k["bla"]), "[json.exception.type_error.312] (/bla) cannot use update() with number", json::type_error);
|
||||
CHECK_THROWS_WITH(j.update(k["bla"].begin(), k["bla"].end()), "[json.exception.type_error.312] (/bla) cannot use update() with number");
|
||||
CHECK_THROWS_AS(j.update(k["bla"].begin(), k["bla"].end()), json::type_error);
|
||||
CHECK_THROWS_WITH(j.update(k["bla"]), "[json.exception.type_error.312] (/bla) cannot use update() with number");
|
||||
CHECK_THROWS_AS(j.update(k["bla"]), json::type_error);
|
||||
}
|
||||
}
|
||||
|
||||
@ -119,15 +121,18 @@ TEST_CASE("Regression tests for extended diagnostics")
|
||||
{
|
||||
SECTION("Regression test for https://github.com/nlohmann/json/pull/2562#pullrequestreview-574858448")
|
||||
{
|
||||
CHECK_THROWS_WITH_AS(json({"0", "0"})[1].get<int>(), "[json.exception.type_error.302] (/1) type must be number, but is string", json::type_error);
|
||||
CHECK_THROWS_WITH_AS(json({"0", "1"})[1].get<int>(), "[json.exception.type_error.302] (/1) type must be number, but is string", json::type_error);
|
||||
CHECK_THROWS_WITH(json({"0", "0"})[1].get<int>(), "[json.exception.type_error.302] (/1) type must be number, but is string");
|
||||
CHECK_THROWS_AS(json({"0", "0"})[1].get<int>(), json::type_error);
|
||||
CHECK_THROWS_WITH(json({"0", "1"})[1].get<int>(), "[json.exception.type_error.302] (/1) type must be number, but is string");
|
||||
CHECK_THROWS_AS(json({"0", "1"})[1].get<int>(), json::type_error);
|
||||
}
|
||||
|
||||
SECTION("Regression test for https://github.com/nlohmann/json/pull/2562/files/380a613f2b5d32425021129cd1f371ddcfd54ddf#r563259793")
|
||||
{
|
||||
json j;
|
||||
j["/foo"] = {1, 2, 3};
|
||||
CHECK_THROWS_WITH_AS(j.unflatten(), "[json.exception.type_error.315] (/~1foo) values in object must be primitive", json::type_error);
|
||||
CHECK_THROWS_WITH(j.unflatten(), "[json.exception.type_error.315] (/~1foo) values in object must be primitive");
|
||||
CHECK_THROWS_AS(j.unflatten(), json::type_error);
|
||||
}
|
||||
|
||||
SECTION("Regression test for issue #2838 - Assertion failure when inserting into arrays with JSON_DIAGNOSTICS set")
|
||||
@ -220,7 +225,8 @@ TEST_CASE("Regression tests for extended diagnostics")
|
||||
|
||||
// Must call operator[] on const element, otherwise m_parent gets updated.
|
||||
auto const& constJ = j;
|
||||
CHECK_THROWS_WITH_AS(constJ["one"].at(0), "[json.exception.type_error.304] (/one) cannot use at() with number", json::type_error);
|
||||
CHECK_THROWS_WITH(constJ["one"].at(0), "[json.exception.type_error.304] (/one) cannot use at() with number");
|
||||
CHECK_THROWS_AS(constJ["one"].at(0), json::type_error);
|
||||
}
|
||||
|
||||
// void update(const_iterator first, const_iterator last)
|
||||
@ -236,7 +242,8 @@ TEST_CASE("Regression tests for extended diagnostics")
|
||||
|
||||
// Must call operator[] on const element, otherwise m_parent gets updated.
|
||||
auto const& constJ = j;
|
||||
CHECK_THROWS_WITH_AS(constJ["one"].at(0), "[json.exception.type_error.304] (/one) cannot use at() with number", json::type_error);
|
||||
CHECK_THROWS_WITH(constJ["one"].at(0), "[json.exception.type_error.304] (/one) cannot use at() with number");
|
||||
CHECK_THROWS_AS(constJ["one"].at(0), json::type_error);
|
||||
}
|
||||
|
||||
// Code from #3007 triggering unwanted assertion without fix to update().
|
||||
|
||||
@ -359,8 +359,8 @@ TEST_CASE("JSON pointers")
|
||||
}
|
||||
|
||||
// on some machines, the check below is not constant
|
||||
DOCTEST_MSVC_SUPPRESS_WARNING_PUSH
|
||||
DOCTEST_MSVC_SUPPRESS_WARNING(4127)
|
||||
//DOCTEST_MSVC_SUPPRESS_WARNING_PUSH
|
||||
//DOCTEST_MSVC_SUPPRESS_WARNING(4127)
|
||||
|
||||
if (sizeof(typename json::size_type) < sizeof(unsigned long long))
|
||||
{
|
||||
@ -375,7 +375,7 @@ TEST_CASE("JSON pointers")
|
||||
CHECK_THROWS_WITH(j_const[jp] == 1, throw_msg.c_str());
|
||||
}
|
||||
|
||||
DOCTEST_MSVC_SUPPRESS_WARNING_POP
|
||||
//DOCTEST_MSVC_SUPPRESS_WARNING_POP
|
||||
|
||||
CHECK_THROWS_AS(j.at("/one"_json_pointer) = 1, json::parse_error);
|
||||
CHECK_THROWS_WITH(j.at("/one"_json_pointer) = 1,
|
||||
|
||||
@ -1025,8 +1025,10 @@ TEST_CASE("modifiers")
|
||||
json::binary_t s1 = {{1, 2, 3, 4}};
|
||||
std::vector<std::uint8_t> s2 = {{5, 6, 7, 8}};
|
||||
|
||||
CHECK_THROWS_WITH_AS(j.swap(s1), "[json.exception.type_error.310] cannot use swap() with number", json::type_error);
|
||||
CHECK_THROWS_WITH_AS(j.swap(s2), "[json.exception.type_error.310] cannot use swap() with number", json::type_error);
|
||||
CHECK_THROWS_WITH(j.swap(s1), "[json.exception.type_error.310] cannot use swap() with number");
|
||||
CHECK_THROWS_AS(j.swap(s1), json::type_error);
|
||||
CHECK_THROWS_WITH(j.swap(s2), "[json.exception.type_error.310] cannot use swap() with number");
|
||||
CHECK_THROWS_AS(j.swap(s2), json::type_error);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1642,7 +1642,7 @@ TEST_CASE("single MessagePack roundtrip")
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("MessagePack roundtrips" * doctest::skip())
|
||||
TEST_CASE("MessagePack roundtrips", "[.]")
|
||||
{
|
||||
SECTION("input from msgpack-python")
|
||||
{
|
||||
|
||||
@ -1588,7 +1588,7 @@ TEST_CASE("regression tests, exceptions dependent")
|
||||
json j;
|
||||
s >> j;
|
||||
s >> j;
|
||||
CHECK_THROWS_AS(s >> j, json::parse_error const);
|
||||
CHECK_THROWS_AS(s >> j, json::parse_error);
|
||||
CHECK(s.eof());
|
||||
}
|
||||
}
|
||||
|
||||
@ -807,7 +807,8 @@ TEST_CASE("regression tests 2")
|
||||
const auto j_path = j.get<nlohmann::detail::std_fs::path>();
|
||||
CHECK(j_path == text_path);
|
||||
|
||||
CHECK_THROWS_WITH_AS(nlohmann::detail::std_fs::path(json(1)), "[json.exception.type_error.302] type must be string, but is number", json::type_error);
|
||||
CHECK_THROWS_WITH(nlohmann::detail::std_fs::path(json(1)), "[json.exception.type_error.302] type must be string, but is number");
|
||||
CHECK_THROWS_AS(nlohmann::detail::std_fs::path(json(1)), json::type_error);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
@ -807,11 +807,14 @@ TEST_CASE("UBJSON")
|
||||
|
||||
json _;
|
||||
std::vector<uint8_t> vec2 = {'H', 'i', 2, '1', 'A', '3'};
|
||||
CHECK_THROWS_WITH_AS(_ = json::from_ubjson(vec2), "[json.exception.parse_error.115] parse error at byte 5: syntax error while parsing UBJSON high-precision number: invalid number text: 1A", json::parse_error);
|
||||
CHECK_THROWS_WITH(_ = json::from_ubjson(vec2), "[json.exception.parse_error.115] parse error at byte 5: syntax error while parsing UBJSON high-precision number: invalid number text: 1A");
|
||||
CHECK_THROWS_AS(_ = json::from_ubjson(vec2), json::parse_error);
|
||||
std::vector<uint8_t> vec3 = {'H', 'i', 2, '1', '.'};
|
||||
CHECK_THROWS_WITH_AS(_ = json::from_ubjson(vec3), "[json.exception.parse_error.115] parse error at byte 5: syntax error while parsing UBJSON high-precision number: invalid number text: 1.", json::parse_error);
|
||||
CHECK_THROWS_WITH(_ = json::from_ubjson(vec3), "[json.exception.parse_error.115] parse error at byte 5: syntax error while parsing UBJSON high-precision number: invalid number text: 1.");
|
||||
CHECK_THROWS_AS(_ = json::from_ubjson(vec3), json::parse_error);
|
||||
std::vector<uint8_t> vec4 = {'H', 2, '1', '0'};
|
||||
CHECK_THROWS_WITH_AS(_ = json::from_ubjson(vec4), "[json.exception.parse_error.113] parse error at byte 2: syntax error while parsing UBJSON size: expected length type specification (U, i, I, l, L) after '#'; last byte: 0x02", json::parse_error);
|
||||
CHECK_THROWS_WITH(_ = json::from_ubjson(vec4), "[json.exception.parse_error.113] parse error at byte 2: syntax error while parsing UBJSON size: expected length type specification (U, i, I, l, L) after '#'; last byte: 0x02");
|
||||
CHECK_THROWS_AS(_ = json::from_ubjson(vec4), json::parse_error);
|
||||
}
|
||||
|
||||
SECTION("serialization")
|
||||
@ -2428,7 +2431,7 @@ TEST_CASE("all UBJSON first bytes")
|
||||
for (auto i = 0; i < 256; ++i)
|
||||
{
|
||||
const auto byte = static_cast<uint8_t>(i);
|
||||
CAPTURE(byte)
|
||||
CAPTURE(byte);
|
||||
|
||||
try
|
||||
{
|
||||
@ -2438,7 +2441,7 @@ TEST_CASE("all UBJSON first bytes")
|
||||
{
|
||||
// check that parse_error.112 is only thrown if the
|
||||
// first byte is not in the supported set
|
||||
INFO_WITH_TEMP(e.what());
|
||||
CAPTURE(e.what());
|
||||
if (supported.find(byte) == supported.end())
|
||||
{
|
||||
CHECK(e.id == 112);
|
||||
@ -2452,7 +2455,7 @@ TEST_CASE("all UBJSON first bytes")
|
||||
}
|
||||
#endif
|
||||
|
||||
TEST_CASE("UBJSON roundtrips" * doctest::skip())
|
||||
TEST_CASE("UBJSON roundtrips", "[.]")
|
||||
{
|
||||
SECTION("input from self-generated UBJSON files")
|
||||
{
|
||||
@ -2505,7 +2508,7 @@ TEST_CASE("UBJSON roundtrips" * doctest::skip())
|
||||
CAPTURE(filename);
|
||||
|
||||
{
|
||||
INFO_WITH_TEMP(filename + ": std::vector<uint8_t>");
|
||||
CAPTURE(filename + ": std::vector<uint8_t>");
|
||||
// parse JSON file
|
||||
std::ifstream f_json(filename);
|
||||
json j1 = json::parse(f_json);
|
||||
@ -2520,7 +2523,7 @@ TEST_CASE("UBJSON roundtrips" * doctest::skip())
|
||||
}
|
||||
|
||||
{
|
||||
INFO_WITH_TEMP(filename + ": std::ifstream");
|
||||
CAPTURE(filename + ": std::ifstream");
|
||||
// parse JSON file
|
||||
std::ifstream f_json(filename);
|
||||
json j1 = json::parse(f_json);
|
||||
@ -2535,7 +2538,7 @@ TEST_CASE("UBJSON roundtrips" * doctest::skip())
|
||||
}
|
||||
|
||||
{
|
||||
INFO_WITH_TEMP(filename + ": uint8_t* and size");
|
||||
CAPTURE(filename + ": uint8_t* and size");
|
||||
// parse JSON file
|
||||
std::ifstream f_json(filename);
|
||||
json j1 = json::parse(f_json);
|
||||
@ -2550,7 +2553,7 @@ TEST_CASE("UBJSON roundtrips" * doctest::skip())
|
||||
}
|
||||
|
||||
{
|
||||
INFO_WITH_TEMP(filename + ": output to output adapters");
|
||||
CAPTURE(filename + ": output to output adapters");
|
||||
// parse JSON file
|
||||
std::ifstream f_json(filename);
|
||||
json j1 = json::parse(f_json);
|
||||
@ -2559,7 +2562,7 @@ TEST_CASE("UBJSON roundtrips" * doctest::skip())
|
||||
auto packed = utils::read_binary_file(filename + ".ubjson");
|
||||
|
||||
{
|
||||
INFO_WITH_TEMP(filename + ": output adapters: std::vector<uint8_t>");
|
||||
CAPTURE(filename + ": output adapters: std::vector<uint8_t>");
|
||||
std::vector<uint8_t> vec;
|
||||
json::to_ubjson(j1, vec);
|
||||
CHECK(vec == packed);
|
||||
|
||||
@ -253,7 +253,8 @@ TEMPLATE_TEST_CASE("Serialization/deserialization via NLOHMANN_DEFINE_TYPE_INTRU
|
||||
// check exception in case of missing field
|
||||
json j = json(p1);
|
||||
j.erase("age");
|
||||
CHECK_THROWS_WITH_AS(j.get<TestType>(), "[json.exception.out_of_range.403] key 'age' not found", json::out_of_range);
|
||||
CHECK_THROWS_WITH(j.get<TestType>(), "[json.exception.out_of_range.403] key 'age' not found");
|
||||
CHECK_THROWS_AS(j.get<TestType>(), json::out_of_range);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user