Merge branch 'develop' of https://github.com/nlohmann/json into feature/optional

 Conflicts:
	test/src/unit-conversions.cpp
This commit is contained in:
Niels Lohmann
2020-12-21 20:59:41 +01:00
173 changed files with 8659 additions and 972 deletions

View File

@@ -11,3 +11,10 @@ target_link_libraries(with_namespace_target nlohmann_json::nlohmann_json)
add_executable(without_namespace_target main.cpp)
target_link_libraries(without_namespace_target nlohmann_json)
if(NOT MSVC)
add_executable(without_exceptions main.cpp)
target_link_libraries(without_exceptions nlohmann_json::nlohmann_json)
target_compile_definitions(without_exceptions PRIVATE JSON_NOEXCEPTION)
target_compile_options(without_exceptions PRIVATE -fno-exceptions)
endif()

View File

@@ -29,10 +29,9 @@ SOFTWARE.
#include "doctest_compatibility.h"
#define private public
#define JSON_TESTS_PRIVATE
#include <nlohmann/json.hpp>
using nlohmann::json;
#undef private
namespace
{

View File

@@ -867,8 +867,9 @@ TEST_CASE("Negative size of binary value")
0x00 // end marker
};
CHECK_THROWS_AS(json::from_bson(input), json::parse_error);
CHECK_THROWS_WITH(json::from_bson(input), "[json.exception.parse_error.112] parse error at byte 15: syntax error while parsing BSON binary: byte array length cannot be negative, is -1");
json _;
CHECK_THROWS_AS(_ = json::from_bson(input), json::parse_error);
CHECK_THROWS_WITH(_ = json::from_bson(input), "[json.exception.parse_error.112] parse error at byte 15: syntax error while parsing BSON binary: byte array length cannot be negative, is -1");
}
TEST_CASE("Unsupported BSON input")

View File

@@ -1591,14 +1591,16 @@ TEST_CASE("CBOR")
{
// array with three empty byte strings
std::vector<std::uint8_t> input = {0x83, 0x40, 0x40, 0x40};
CHECK_NOTHROW(json::from_cbor(input));
json _;
CHECK_NOTHROW(_ = json::from_cbor(input));
}
SECTION("binary in object")
{
// object mapping "foo" to empty byte string
std::vector<std::uint8_t> input = {0xA1, 0x63, 0x66, 0x6F, 0x6F, 0x40};
CHECK_NOTHROW(json::from_cbor(input));
json _;
CHECK_NOTHROW(_ = json::from_cbor(input));
}
SECTION("SAX callback with binary")
@@ -2551,8 +2553,9 @@ TEST_CASE("Tagged values")
v_tagged.insert(v_tagged.begin(), b);
// check that parsing fails in error mode
CHECK_THROWS_AS(json::from_cbor(v_tagged), json::parse_error);
CHECK_THROWS_AS(json::from_cbor(v_tagged, true, true, json::cbor_tag_handler_t::error), json::parse_error);
json _;
CHECK_THROWS_AS(_ = json::from_cbor(v_tagged), json::parse_error);
CHECK_THROWS_AS(_ = json::from_cbor(v_tagged, true, true, json::cbor_tag_handler_t::error), json::parse_error);
// check that parsing succeeds and gets original value in ignore mode
auto j_tagged = json::from_cbor(v_tagged, true, true, json::cbor_tag_handler_t::ignore);
@@ -2570,8 +2573,9 @@ TEST_CASE("Tagged values")
v_tagged.insert(v_tagged.begin(), 0xD8); // tag
// check that parsing fails in error mode
CHECK_THROWS_AS(json::from_cbor(v_tagged), json::parse_error);
CHECK_THROWS_AS(json::from_cbor(v_tagged, true, true, json::cbor_tag_handler_t::error), json::parse_error);
json _;
CHECK_THROWS_AS(_ = json::from_cbor(v_tagged), json::parse_error);
CHECK_THROWS_AS(_ = json::from_cbor(v_tagged, true, true, json::cbor_tag_handler_t::error), json::parse_error);
// check that parsing succeeds and gets original value in ignore mode
auto j_tagged = json::from_cbor(v_tagged, true, true, json::cbor_tag_handler_t::ignore);
@@ -2585,9 +2589,10 @@ TEST_CASE("Tagged values")
v_tagged.insert(v_tagged.begin(), 0xD8); // tag
// check that parsing fails in all modes
CHECK_THROWS_AS(json::from_cbor(v_tagged), json::parse_error);
CHECK_THROWS_AS(json::from_cbor(v_tagged, true, true, json::cbor_tag_handler_t::error), json::parse_error);
CHECK_THROWS_AS(json::from_cbor(v_tagged, true, true, json::cbor_tag_handler_t::ignore), json::parse_error);
json _;
CHECK_THROWS_AS(_ = json::from_cbor(v_tagged), json::parse_error);
CHECK_THROWS_AS(_ = json::from_cbor(v_tagged, true, true, json::cbor_tag_handler_t::error), json::parse_error);
CHECK_THROWS_AS(_ = json::from_cbor(v_tagged, true, true, json::cbor_tag_handler_t::ignore), json::parse_error);
}
}
@@ -2602,8 +2607,9 @@ TEST_CASE("Tagged values")
v_tagged.insert(v_tagged.begin(), 0xD9); // tag
// check that parsing fails in error mode
CHECK_THROWS_AS(json::from_cbor(v_tagged), json::parse_error);
CHECK_THROWS_AS(json::from_cbor(v_tagged, true, true, json::cbor_tag_handler_t::error), json::parse_error);
json _;
CHECK_THROWS_AS(_ = json::from_cbor(v_tagged), json::parse_error);
CHECK_THROWS_AS(_ = json::from_cbor(v_tagged, true, true, json::cbor_tag_handler_t::error), json::parse_error);
// check that parsing succeeds and gets original value in ignore mode
auto j_tagged = json::from_cbor(v_tagged, true, true, json::cbor_tag_handler_t::ignore);
@@ -2618,9 +2624,10 @@ TEST_CASE("Tagged values")
v_tagged.insert(v_tagged.begin(), 0xD9); // tag
// check that parsing fails in all modes
CHECK_THROWS_AS(json::from_cbor(v_tagged), json::parse_error);
CHECK_THROWS_AS(json::from_cbor(v_tagged, true, true, json::cbor_tag_handler_t::error), json::parse_error);
CHECK_THROWS_AS(json::from_cbor(v_tagged, true, true, json::cbor_tag_handler_t::ignore), json::parse_error);
json _;
CHECK_THROWS_AS(_ = json::from_cbor(v_tagged), json::parse_error);
CHECK_THROWS_AS(_ = json::from_cbor(v_tagged, true, true, json::cbor_tag_handler_t::error), json::parse_error);
CHECK_THROWS_AS(_ = json::from_cbor(v_tagged, true, true, json::cbor_tag_handler_t::ignore), json::parse_error);
}
}
@@ -2637,8 +2644,9 @@ TEST_CASE("Tagged values")
v_tagged.insert(v_tagged.begin(), 0xDA); // tag
// check that parsing fails in error mode
CHECK_THROWS_AS(json::from_cbor(v_tagged), json::parse_error);
CHECK_THROWS_AS(json::from_cbor(v_tagged, true, true, json::cbor_tag_handler_t::error), json::parse_error);
json _;
CHECK_THROWS_AS(_ = json::from_cbor(v_tagged), json::parse_error);
CHECK_THROWS_AS(_ = json::from_cbor(v_tagged, true, true, json::cbor_tag_handler_t::error), json::parse_error);
// check that parsing succeeds and gets original value in ignore mode
auto j_tagged = json::from_cbor(v_tagged, true, true, json::cbor_tag_handler_t::ignore);
@@ -2655,9 +2663,10 @@ TEST_CASE("Tagged values")
v_tagged.insert(v_tagged.begin(), 0xDA); // tag
// check that parsing fails in all modes
CHECK_THROWS_AS(json::from_cbor(v_tagged), json::parse_error);
CHECK_THROWS_AS(json::from_cbor(v_tagged, true, true, json::cbor_tag_handler_t::error), json::parse_error);
CHECK_THROWS_AS(json::from_cbor(v_tagged, true, true, json::cbor_tag_handler_t::ignore), json::parse_error);
json _;
CHECK_THROWS_AS(_ = json::from_cbor(v_tagged), json::parse_error);
CHECK_THROWS_AS(_ = json::from_cbor(v_tagged, true, true, json::cbor_tag_handler_t::error), json::parse_error);
CHECK_THROWS_AS(_ = json::from_cbor(v_tagged, true, true, json::cbor_tag_handler_t::ignore), json::parse_error);
}
}
@@ -2678,8 +2687,9 @@ TEST_CASE("Tagged values")
v_tagged.insert(v_tagged.begin(), 0xDB); // tag
// check that parsing fails in error mode
CHECK_THROWS_AS(json::from_cbor(v_tagged), json::parse_error);
CHECK_THROWS_AS(json::from_cbor(v_tagged, true, true, json::cbor_tag_handler_t::error), json::parse_error);
json _;
CHECK_THROWS_AS(_ = json::from_cbor(v_tagged), json::parse_error);
CHECK_THROWS_AS(_ = json::from_cbor(v_tagged, true, true, json::cbor_tag_handler_t::error), json::parse_error);
// check that parsing succeeds and gets original value in ignore mode
auto j_tagged = json::from_cbor(v_tagged, true, true, json::cbor_tag_handler_t::ignore);
@@ -2700,9 +2710,10 @@ TEST_CASE("Tagged values")
v_tagged.insert(v_tagged.begin(), 0xDB); // tag
// check that parsing fails in all modes
CHECK_THROWS_AS(json::from_cbor(v_tagged), json::parse_error);
CHECK_THROWS_AS(json::from_cbor(v_tagged, true, true, json::cbor_tag_handler_t::error), json::parse_error);
CHECK_THROWS_AS(json::from_cbor(v_tagged, true, true, json::cbor_tag_handler_t::ignore), json::parse_error);
json _;
CHECK_THROWS_AS(_ = json::from_cbor(v_tagged), json::parse_error);
CHECK_THROWS_AS(_ = json::from_cbor(v_tagged, true, true, json::cbor_tag_handler_t::error), json::parse_error);
CHECK_THROWS_AS(_ = json::from_cbor(v_tagged, true, true, json::cbor_tag_handler_t::ignore), json::parse_error);
}
}
@@ -2717,8 +2728,9 @@ TEST_CASE("Tagged values")
CHECK(vec == std::vector<std::uint8_t> {0xA1, 0x66, 0x62, 0x69, 0x6E, 0x61, 0x72, 0x79, 0xD8, 0x2A, 0x44, 0xCA, 0xFE, 0xBA, 0xBE});
// parse error when parsing tagged value
CHECK_THROWS_AS(json::from_cbor(vec), json::parse_error);
CHECK_THROWS_WITH(json::from_cbor(vec), "[json.exception.parse_error.112] parse error at byte 9: syntax error while parsing CBOR value: invalid byte: 0xD8");
json _;
CHECK_THROWS_AS(_ = json::from_cbor(vec), json::parse_error);
CHECK_THROWS_WITH(_ = json::from_cbor(vec), "[json.exception.parse_error.112] parse error at byte 9: syntax error while parsing CBOR value: invalid byte: 0xD8");
// binary without subtype when tags are ignored
json jb = json::from_cbor(vec, true, true, json::cbor_tag_handler_t::ignore);

View File

@@ -29,10 +29,9 @@ SOFTWARE.
#include "doctest_compatibility.h"
#define private public
#define JSON_TESTS_PRIVATE
#include <nlohmann/json.hpp>
using nlohmann::json;
#undef private
TEST_CASE("const_iterator class")
{

View File

@@ -29,10 +29,9 @@ SOFTWARE.
#include "doctest_compatibility.h"
#define private public
#define JSON_TESTS_PRIVATE
#include <nlohmann/json.hpp>
using nlohmann::json;
#undef private
TEST_CASE("iterator class")
{

View File

@@ -29,10 +29,9 @@ SOFTWARE.
#include "doctest_compatibility.h"
#define private public
#define JSON_TESTS_PRIVATE
#include <nlohmann/json.hpp>
using nlohmann::json;
#undef private
namespace
{

View File

@@ -29,10 +29,9 @@ SOFTWARE.
#include "doctest_compatibility.h"
#define private public
#define JSON_TESTS_PRIVATE
#include <nlohmann/json.hpp>
using nlohmann::json;
#undef private
#include <valarray>
@@ -1880,7 +1879,8 @@ TEST_CASE("parser class")
SECTION("error messages for comments")
{
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);
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);
}
}

View File

@@ -30,10 +30,9 @@ SOFTWARE.
#include "doctest_compatibility.h"
DOCTEST_GCC_SUPPRESS_WARNING("-Wfloat-equal")
#define private public
#define JSON_TESTS_PRIVATE
#include <nlohmann/json.hpp>
using nlohmann::json;
#undef private
#include <deque>
#include <forward_list>

View File

@@ -29,10 +29,9 @@ SOFTWARE.
#include "doctest_compatibility.h"
#define private public
#define JSON_TESTS_PRIVATE
#include <nlohmann/json.hpp>
using nlohmann::json;
#undef private
#include <sstream>

View File

@@ -29,10 +29,9 @@ SOFTWARE.
#include "doctest_compatibility.h"
#define private public
#define JSON_TESTS_PRIVATE
#include <nlohmann/json.hpp>
using nlohmann::json;
#undef private
#include <deque>
#include <forward_list>
@@ -49,18 +48,6 @@ using nlohmann::json;
#define JSON_HAS_CPP_14
#endif
#ifdef JSON_HAS_CPP_17
#if __has_include(<optional>)
#include <optional>
#elif __has_include(<experimental/optional>)
#include <experimental/optional>
#endif
#endif
#if defined(JSON_HAS_CPP_17)
#include <string_view>
#endif
TEST_CASE("value conversion")
{
SECTION("get an object (explicit)")

View File

@@ -537,7 +537,8 @@ TEST_CASE("deserialization")
SECTION("with empty range")
{
std::vector<uint8_t> v;
CHECK_THROWS_AS(json::parse(std::begin(v), std::end(v)), json::parse_error&);
json _;
CHECK_THROWS_AS(_ = json::parse(std::begin(v), std::end(v)), json::parse_error&);
CHECK(!json::accept(std::begin(v), std::end(v)));
SaxEventLogger l;
@@ -553,7 +554,8 @@ TEST_CASE("deserialization")
SECTION("case 1")
{
uint8_t v[] = {'\"', 'a', 'a', 'a', 'a', 'a', 'a', '\\', 'u'};
CHECK_THROWS_AS(json::parse(std::begin(v), std::end(v)), json::parse_error&);
json _;
CHECK_THROWS_AS(_ = json::parse(std::begin(v), std::end(v)), json::parse_error&);
CHECK(!json::accept(std::begin(v), std::end(v)));
json j_error;
@@ -569,7 +571,8 @@ TEST_CASE("deserialization")
SECTION("case 2")
{
uint8_t v[] = {'\"', 'a', 'a', 'a', 'a', 'a', 'a', '\\', 'u', '1'};
CHECK_THROWS_AS(json::parse(std::begin(v), std::end(v)), json::parse_error&);
json _;
CHECK_THROWS_AS(_ = json::parse(std::begin(v), std::end(v)), json::parse_error&);
CHECK(!json::accept(std::begin(v), std::end(v)));
json j_error;
@@ -585,7 +588,8 @@ TEST_CASE("deserialization")
SECTION("case 3")
{
uint8_t v[] = {'\"', 'a', 'a', 'a', 'a', 'a', 'a', '\\', 'u', '1', '1', '1', '1', '1', '1', '1', '1'};
CHECK_THROWS_AS(json::parse(std::begin(v), std::end(v)), json::parse_error&);
json _;
CHECK_THROWS_AS(_ = json::parse(std::begin(v), std::end(v)), json::parse_error&);
CHECK(!json::accept(std::begin(v), std::end(v)));
json j_error;
@@ -601,7 +605,8 @@ TEST_CASE("deserialization")
SECTION("case 4")
{
uint8_t v[] = {'\"', 'a', 'a', 'a', 'a', 'a', 'a', 'u', '1', '1', '1', '1', '1', '1', '1', '1', '\\'};
CHECK_THROWS_AS(json::parse(std::begin(v), std::end(v)), json::parse_error&);
json _;
CHECK_THROWS_AS(_ = json::parse(std::begin(v), std::end(v)), json::parse_error&);
CHECK(!json::accept(std::begin(v), std::end(v)));
json j_error;
@@ -617,7 +622,8 @@ TEST_CASE("deserialization")
SECTION("case 5")
{
uint8_t v[] = {'\"', 0x7F, 0xC1};
CHECK_THROWS_AS(json::parse(std::begin(v), std::end(v)), json::parse_error&);
json _;
CHECK_THROWS_AS(_ = json::parse(std::begin(v), std::end(v)), json::parse_error&);
CHECK(!json::accept(std::begin(v), std::end(v)));
json j_error;
@@ -652,7 +658,8 @@ TEST_CASE("deserialization")
SECTION("case 7")
{
uint8_t v[] = {'\"', 0x7F, 0xDF, 0xC0};
CHECK_THROWS_AS(json::parse(std::begin(v), std::end(v)), json::parse_error&);
json _;
CHECK_THROWS_AS(_ = json::parse(std::begin(v), std::end(v)), json::parse_error&);
CHECK(!json::accept(std::begin(v), std::end(v)));
json j_error;
@@ -668,7 +675,8 @@ TEST_CASE("deserialization")
SECTION("case 8")
{
uint8_t v[] = {'\"', 0x7F, 0xE0, 0x9F};
CHECK_THROWS_AS(json::parse(std::begin(v), std::end(v)), json::parse_error&);
json _;
CHECK_THROWS_AS(_ = json::parse(std::begin(v), std::end(v)), json::parse_error&);
CHECK(!json::accept(std::begin(v), std::end(v)));
json j_error;
@@ -684,7 +692,8 @@ TEST_CASE("deserialization")
SECTION("case 9")
{
uint8_t v[] = {'\"', 0x7F, 0xEF, 0xC0};
CHECK_THROWS_AS(json::parse(std::begin(v), std::end(v)), json::parse_error&);
json _;
CHECK_THROWS_AS(_ = json::parse(std::begin(v), std::end(v)), json::parse_error&);
CHECK(!json::accept(std::begin(v), std::end(v)));
json j_error;
@@ -700,7 +709,8 @@ TEST_CASE("deserialization")
SECTION("case 10")
{
uint8_t v[] = {'\"', 0x7F, 0xED, 0x7F};
CHECK_THROWS_AS(json::parse(std::begin(v), std::end(v)), json::parse_error&);
json _;
CHECK_THROWS_AS(_ = json::parse(std::begin(v), std::end(v)), json::parse_error&);
CHECK(!json::accept(std::begin(v), std::end(v)));
json j_error;
@@ -716,7 +726,8 @@ TEST_CASE("deserialization")
SECTION("case 11")
{
uint8_t v[] = {'\"', 0x7F, 0xF0, 0x8F};
CHECK_THROWS_AS(json::parse(std::begin(v), std::end(v)), json::parse_error&);
json _;
CHECK_THROWS_AS(_ = json::parse(std::begin(v), std::end(v)), json::parse_error&);
CHECK(!json::accept(std::begin(v), std::end(v)));
json j_error;
@@ -732,7 +743,8 @@ TEST_CASE("deserialization")
SECTION("case 12")
{
uint8_t v[] = {'\"', 0x7F, 0xF0, 0xC0};
CHECK_THROWS_AS(json::parse(std::begin(v), std::end(v)), json::parse_error&);
json _;
CHECK_THROWS_AS(_ = json::parse(std::begin(v), std::end(v)), json::parse_error&);
CHECK(!json::accept(std::begin(v), std::end(v)));
json j_error;
@@ -748,7 +760,8 @@ TEST_CASE("deserialization")
SECTION("case 13")
{
uint8_t v[] = {'\"', 0x7F, 0xF3, 0x7F};
CHECK_THROWS_AS(json::parse(std::begin(v), std::end(v)), json::parse_error&);
json _;
CHECK_THROWS_AS(_ = json::parse(std::begin(v), std::end(v)), json::parse_error&);
CHECK(!json::accept(std::begin(v), std::end(v)));
json j_error;
@@ -764,7 +777,8 @@ TEST_CASE("deserialization")
SECTION("case 14")
{
uint8_t v[] = {'\"', 0x7F, 0xF3, 0xC0};
CHECK_THROWS_AS(json::parse(std::begin(v), std::end(v)), json::parse_error&);
json _;
CHECK_THROWS_AS(_ = json::parse(std::begin(v), std::end(v)), json::parse_error&);
CHECK(!json::accept(std::begin(v), std::end(v)));
json j_error;
@@ -780,7 +794,8 @@ TEST_CASE("deserialization")
SECTION("case 15")
{
uint8_t v[] = {'\"', 0x7F, 0xF4, 0x7F};
CHECK_THROWS_AS(json::parse(std::begin(v), std::end(v)), json::parse_error&);
json _;
CHECK_THROWS_AS(_ = json::parse(std::begin(v), std::end(v)), json::parse_error&);
CHECK(!json::accept(std::begin(v), std::end(v)));
json j_error;
@@ -796,7 +811,8 @@ TEST_CASE("deserialization")
SECTION("case 16")
{
uint8_t v[] = {'{', '\"', '\"', ':', '1', '1'};
CHECK_THROWS_AS(json::parse(std::begin(v), std::end(v)), json::parse_error&);
json _;
CHECK_THROWS_AS(_ = json::parse(std::begin(v), std::end(v)), json::parse_error&);
CHECK(!json::accept(std::begin(v), std::end(v)));
json j_error;

View File

@@ -29,10 +29,9 @@ SOFTWARE.
#include "doctest_compatibility.h"
#define private public
#define JSON_TESTS_PRIVATE
#include <nlohmann/json.hpp>
using nlohmann::json;
#undef private
TEST_CASE("iterators 1")
{

View File

@@ -29,10 +29,9 @@ SOFTWARE.
#include "doctest_compatibility.h"
#define private public
#define JSON_TESTS_PRIVATE
#include <nlohmann/json.hpp>
using nlohmann::json;
#undef private
TEST_CASE("JSON pointers")
{

View File

@@ -76,4 +76,18 @@ TEST_CASE("ordered_json")
CHECK(multi_ordered.dump() == "{\"z\":1,\"m\":2,\"y\":4}");
CHECK(multi_ordered.erase("m") == 1);
CHECK(multi_ordered.dump() == "{\"z\":1,\"y\":4}");
// Ranged insert test.
// It seems that values shouldn't be overwritten. Only new values are added
json j1 {{"c", 1}, {"b", 2}, {"a", 3}};
const json j2 {{"c", 77}, {"d", 42}, {"a", 4}};
j1.insert( j2.cbegin(), j2.cend() );
CHECK(j1.size() == 4);
CHECK(j1.dump() == "{\"a\":3,\"b\":2,\"c\":1,\"d\":42}");
ordered_json oj1 {{"c", 1}, {"b", 2}, {"a", 3}};
const ordered_json oj2 {{"c", 77}, {"d", 42}, {"a", 4}};
oj1.insert( oj2.cbegin(), oj2.cend() );
CHECK(oj1.size() == 4);
CHECK(oj1.dump() == "{\"c\":1,\"b\":2,\"a\":3,\"d\":42}");
}

View File

@@ -33,10 +33,9 @@ DOCTEST_GCC_SUPPRESS_WARNING("-Wfloat-equal")
// for some reason including this after the json header leads to linker errors with VS 2017...
#include <locale>
#define private public
#define JSON_TESTS_PRIVATE
#include <nlohmann/json.hpp>
using nlohmann::json;
#undef private
#include <fstream>
#include <sstream>

View File

@@ -33,10 +33,9 @@ DOCTEST_GCC_SUPPRESS_WARNING("-Wfloat-equal")
// for some reason including this after the json header leads to linker errors with VS 2017...
#include <locale>
#define private public
#define JSON_TESTS_PRIVATE
#include <nlohmann/json.hpp>
using nlohmann::json;
#undef private
#include <fstream>
#include <sstream>

View File

@@ -805,12 +805,13 @@ TEST_CASE("UBJSON")
std::vector<uint8_t> vec1 = {'H', 'i', '1'};
CHECK(json::from_ubjson(vec1, true, false).is_discarded());
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_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);
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_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);
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_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);
}
SECTION("serialization")

View File

@@ -32,10 +32,9 @@ SOFTWARE.
// for some reason including this after the json header leads to linker errors with VS 2017...
#include <locale>
#define private public
#define JSON_TESTS_PRIVATE
#include <nlohmann/json.hpp>
using nlohmann::json;
#undef private
#include <fstream>
#include <sstream>
@@ -1202,7 +1201,8 @@ TEST_CASE("Unicode" * doctest::skip())
SECTION("with an iterator")
{
std::string i = "\xef\xbb\xbf{\n \"foo\": true\n}";
CHECK_NOTHROW(json::parse(i.begin(), i.end()));
json _;
CHECK_NOTHROW(_ = json::parse(i.begin(), i.end()));
}
}

View File

@@ -1,6 +1,6 @@
The MIT License (MIT)
Copyright (c) 2016-2019 Viktor Kirilov
Copyright (c) 2016-2020 Viktor Kirilov
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
@@ -18,4 +18,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
SOFTWARE.

998
test/thirdparty/doctest/doctest.h vendored Executable file → Normal file

File diff suppressed because it is too large Load Diff