Merge branch 'develop' into feature/sax2

This commit is contained in:
Niels Lohmann 2018-05-06 13:29:23 +02:00
commit 5ff2abb90d
No known key found for this signature in database
GPG key ID: 7F3CEA63AE251B69
52 changed files with 582 additions and 418 deletions

View file

@ -42,7 +42,8 @@ SOURCES = src/unit.cpp \
src/unit-serialization.cpp \
src/unit-testsuites.cpp \
src/unit-ubjson.cpp \
src/unit-unicode.cpp
src/unit-unicode.cpp \
src/unit-wstring.cpp
OBJECTS = $(SOURCES:.cpp=.o)

View file

@ -5,6 +5,7 @@
|_____|_____|_____|_|___| https://github.com/nlohmann/json
Licensed under the MIT License <http://opensource.org/licenses/MIT>.
SPDX-License-Identifier: MIT
Copyright (c) 2013-2018 Niels Lohmann <http://nlohmann.me>.
Permission is hereby granted, free of charge, to any person obtaining a copy

View file

@ -5,6 +5,7 @@
|_____|_____|_____|_|___| https://github.com/nlohmann/json
Licensed under the MIT License <http://opensource.org/licenses/MIT>.
SPDX-License-Identifier: MIT
Copyright (c) 2013-2018 Niels Lohmann <http://nlohmann.me>.
Permission is hereby granted, free of charge, to any person obtaining a copy
@ -175,29 +176,6 @@ TEST_CASE("controlled bad_alloc")
CHECK_THROWS_AS(my_json::json_value(v), std::bad_alloc&);
next_construct_fails = false;
}
/*
SECTION("json_value(const object_t&)")
{
next_construct_fails = false;
my_json::object_t v {{"foo", "bar"}};
CHECK_NOTHROW(my_json::json_value j(v));
next_construct_fails = true;
CHECK_THROWS_AS(my_json::json_value j(v), std::bad_alloc&);
next_construct_fails = false;
}
*/
/*
SECTION("json_value(const array_t&)")
{
next_construct_fails = false;
my_json::array_t v = {"foo", "bar", "baz"};
CHECK_NOTHROW(my_json::json_value j(v));
next_construct_fails = true;
CHECK_THROWS_AS(my_json::json_value j(v), std::bad_alloc&);
next_construct_fails = false;
}
*/
}
SECTION("class basic_json")

View file

@ -5,6 +5,7 @@
|_____|_____|_____|_|___| https://github.com/nlohmann/json
Licensed under the MIT License <http://opensource.org/licenses/MIT>.
SPDX-License-Identifier: MIT
Copyright (c) 2018 Vitaliy Manushkin <agri@akamo.info>.
Permission is hereby granted, free of charge, to any person obtaining a copy

View file

@ -5,6 +5,7 @@
|_____|_____|_____|_|___| https://github.com/nlohmann/json
Licensed under the MIT License <http://opensource.org/licenses/MIT>.
SPDX-License-Identifier: MIT
Copyright (c) 2013-2018 Niels Lohmann <http://nlohmann.me>.
Permission is hereby granted, free of charge, to any person obtaining a copy

View file

@ -5,6 +5,7 @@
|_____|_____|_____|_|___| https://github.com/nlohmann/json
Licensed under the MIT License <http://opensource.org/licenses/MIT>.
SPDX-License-Identifier: MIT
Copyright (c) 2013-2018 Niels Lohmann <http://nlohmann.me>.
Permission is hereby granted, free of charge, to any person obtaining a copy
@ -575,7 +576,6 @@ TEST_CASE("CBOR")
}
}
/*
SECTION("-32768..-129 (int 16)")
{
for (int16_t i = -32768; i <= -129; ++i)
@ -601,14 +601,13 @@ TEST_CASE("CBOR")
// check individual bytes
CHECK(result[0] == 0xd1);
int16_t restored = (result[1] << 8) + result[2];
int16_t restored = static_cast<int16_t>((result[1] << 8) + result[2]);
CHECK(restored == i);
// roundtrip
CHECK(json::from_msgpack(result) == j);
}
}
*/
}
SECTION("unsigned")
@ -1147,28 +1146,6 @@ TEST_CASE("CBOR")
CHECK(json::from_cbor(result) == j);
CHECK(json::from_cbor(result, true, false) == j);
}
/*
SECTION("array with uint64_t elements")
{
json j(4294967296, nullptr);
std::vector<uint8_t> expected(j.size() + 9, 0xf6); // all null
expected[0] = 0x9b; // array 64 bit
expected[1] = 0x00; // size (0x0000000100000000), byte 0
expected[2] = 0x00; // size (0x0000000100000000), byte 1
expected[3] = 0x00; // size (0x0000000100000000), byte 2
expected[4] = 0x01; // size (0x0000000100000000), byte 3
expected[5] = 0x00; // size (0x0000000100000000), byte 4
expected[6] = 0x00; // size (0x0000000100000000), byte 5
expected[7] = 0x00; // size (0x0000000100000000), byte 6
expected[8] = 0x00; // size (0x0000000100000000), byte 7
const auto result = json::to_cbor(j);
CHECK(result == expected);
// roundtrip
CHECK(json::from_cbor(result) == j);
}
*/
}
SECTION("object")

View file

@ -5,6 +5,7 @@
|_____|_____|_____|_|___| https://github.com/nlohmann/json
Licensed under the MIT License <http://opensource.org/licenses/MIT>.
SPDX-License-Identifier: MIT
Copyright (c) 2013-2018 Niels Lohmann <http://nlohmann.me>.
Permission is hereby granted, free of charge, to any person obtaining a copy

View file

@ -5,6 +5,7 @@
|_____|_____|_____|_|___| https://github.com/nlohmann/json
Licensed under the MIT License <http://opensource.org/licenses/MIT>.
SPDX-License-Identifier: MIT
Copyright (c) 2013-2018 Niels Lohmann <http://nlohmann.me>.
Permission is hereby granted, free of charge, to any person obtaining a copy

View file

@ -5,6 +5,7 @@
|_____|_____|_____|_|___| https://github.com/nlohmann/json
Licensed under the MIT License <http://opensource.org/licenses/MIT>.
SPDX-License-Identifier: MIT
Copyright (c) 2013-2018 Niels Lohmann <http://nlohmann.me>.
Permission is hereby granted, free of charge, to any person obtaining a copy
@ -173,15 +174,4 @@ TEST_CASE("lexer class")
s += "\"";
CHECK((scan_string(s.c_str()) == json::lexer::token_type::value_string));
}
/* NOTE: to_unicode function has been removed
SECTION("to_unicode")
{
// lexer to call to_unicode on
json::lexer dummy_lexer("", 0);
CHECK(dummy_lexer.to_unicode(0x1F4A9) == "💩");
CHECK_THROWS_AS(dummy_lexer.to_unicode(0x200000), json::parse_error);
CHECK_THROWS_WITH(dummy_lexer.to_unicode(0x200000), "[json.exception.parse_error.103] parse error: code points above 0x10FFFF are invalid");
}
*/
}

View file

@ -5,6 +5,7 @@
|_____|_____|_____|_|___| https://github.com/nlohmann/json
Licensed under the MIT License <http://opensource.org/licenses/MIT>.
SPDX-License-Identifier: MIT
Copyright (c) 2013-2018 Niels Lohmann <http://nlohmann.me>.
Permission is hereby granted, free of charge, to any person obtaining a copy

View file

@ -5,6 +5,7 @@
|_____|_____|_____|_|___| https://github.com/nlohmann/json
Licensed under the MIT License <http://opensource.org/licenses/MIT>.
SPDX-License-Identifier: MIT
Copyright (c) 2013-2018 Niels Lohmann <http://nlohmann.me>.
Permission is hereby granted, free of charge, to any person obtaining a copy

View file

@ -5,6 +5,7 @@
|_____|_____|_____|_|___| https://github.com/nlohmann/json
Licensed under the MIT License <http://opensource.org/licenses/MIT>.
SPDX-License-Identifier: MIT
Copyright (c) 2013-2018 Niels Lohmann <http://nlohmann.me>.
Permission is hereby granted, free of charge, to any person obtaining a copy

View file

@ -5,6 +5,7 @@
|_____|_____|_____|_|___| https://github.com/nlohmann/json
Licensed under the MIT License <http://opensource.org/licenses/MIT>.
SPDX-License-Identifier: MIT
Copyright (c) 2013-2018 Niels Lohmann <http://nlohmann.me>.
Permission is hereby granted, free of charge, to any person obtaining a copy

View file

@ -5,6 +5,7 @@
|_____|_____|_____|_|___| https://github.com/nlohmann/json
Licensed under the MIT License <http://opensource.org/licenses/MIT>.
SPDX-License-Identifier: MIT
Copyright (c) 2013-2018 Niels Lohmann <http://nlohmann.me>.
Permission is hereby granted, free of charge, to any person obtaining a copy

View file

@ -5,6 +5,7 @@
|_____|_____|_____|_|___| https://github.com/nlohmann/json
Licensed under the MIT License <http://opensource.org/licenses/MIT>.
SPDX-License-Identifier: MIT
Copyright (c) 2013-2018 Niels Lohmann <http://nlohmann.me>.
Permission is hereby granted, free of charge, to any person obtaining a copy

View file

@ -5,6 +5,7 @@
|_____|_____|_____|_|___| https://github.com/nlohmann/json
Licensed under the MIT License <http://opensource.org/licenses/MIT>.
SPDX-License-Identifier: MIT
Copyright (c) 2013-2018 Niels Lohmann <http://nlohmann.me>.
Permission is hereby granted, free of charge, to any person obtaining a copy

View file

@ -5,6 +5,7 @@
|_____|_____|_____|_|___| https://github.com/nlohmann/json
Licensed under the MIT License <http://opensource.org/licenses/MIT>.
SPDX-License-Identifier: MIT
Copyright (c) 2013-2018 Niels Lohmann <http://nlohmann.me>.
Permission is hereby granted, free of charge, to any person obtaining a copy

View file

@ -5,6 +5,7 @@
|_____|_____|_____|_|___| https://github.com/nlohmann/json
Licensed under the MIT License <http://opensource.org/licenses/MIT>.
SPDX-License-Identifier: MIT
Copyright (c) 2013-2018 Niels Lohmann <http://nlohmann.me>.
Permission is hereby granted, free of charge, to any person obtaining a copy

View file

@ -5,6 +5,7 @@
|_____|_____|_____|_|___| https://github.com/nlohmann/json
Licensed under the MIT License <http://opensource.org/licenses/MIT>.
SPDX-License-Identifier: MIT
Copyright (c) 2013-2018 Niels Lohmann <http://nlohmann.me>.
Permission is hereby granted, free of charge, to any person obtaining a copy

View file

@ -5,6 +5,7 @@
|_____|_____|_____|_|___| https://github.com/nlohmann/json
Licensed under the MIT License <http://opensource.org/licenses/MIT>.
SPDX-License-Identifier: MIT
Copyright (c) 2013-2018 Niels Lohmann <http://nlohmann.me>.
Permission is hereby granted, free of charge, to any person obtaining a copy

View file

@ -5,6 +5,7 @@
|_____|_____|_____|_|___| https://github.com/nlohmann/json
Licensed under the MIT License <http://opensource.org/licenses/MIT>.
SPDX-License-Identifier: MIT
Copyright (c) 2013-2018 Niels Lohmann <http://nlohmann.me>.
Permission is hereby granted, free of charge, to any person obtaining a copy

View file

@ -5,6 +5,7 @@
|_____|_____|_____|_|___| https://github.com/nlohmann/json
Licensed under the MIT License <http://opensource.org/licenses/MIT>.
SPDX-License-Identifier: MIT
Copyright (c) 2013-2018 Niels Lohmann <http://nlohmann.me>.
Permission is hereby granted, free of charge, to any person obtaining a copy

View file

@ -5,6 +5,7 @@
|_____|_____|_____|_|___| https://github.com/nlohmann/json
Licensed under the MIT License <http://opensource.org/licenses/MIT>.
SPDX-License-Identifier: MIT
Copyright (c) 2013-2018 Niels Lohmann <http://nlohmann.me>.
Permission is hereby granted, free of charge, to any person obtaining a copy

View file

@ -5,6 +5,7 @@
|_____|_____|_____|_|___| https://github.com/nlohmann/json
Licensed under the MIT License <http://opensource.org/licenses/MIT>.
SPDX-License-Identifier: MIT
Copyright (c) 2013-2018 Niels Lohmann <http://nlohmann.me>.
Permission is hereby granted, free of charge, to any person obtaining a copy

View file

@ -5,6 +5,7 @@
|_____|_____|_____|_|___| https://github.com/nlohmann/json
Licensed under the MIT License <http://opensource.org/licenses/MIT>.
SPDX-License-Identifier: MIT
Copyright (c) 2013-2018 Niels Lohmann <http://nlohmann.me>.
Permission is hereby granted, free of charge, to any person obtaining a copy

View file

@ -5,6 +5,7 @@
|_____|_____|_____|_|___| https://github.com/nlohmann/json
Licensed under the MIT License <http://opensource.org/licenses/MIT>.
SPDX-License-Identifier: MIT
Copyright (c) 2013-2018 Niels Lohmann <http://nlohmann.me>.
Permission is hereby granted, free of charge, to any person obtaining a copy

View file

@ -5,6 +5,7 @@
|_____|_____|_____|_|___| https://github.com/nlohmann/json
Licensed under the MIT License <http://opensource.org/licenses/MIT>.
SPDX-License-Identifier: MIT
Copyright (c) 2013-2018 Niels Lohmann <http://nlohmann.me>.
Permission is hereby granted, free of charge, to any person obtaining a copy

View file

@ -5,6 +5,7 @@
|_____|_____|_____|_|___| https://github.com/nlohmann/json
Licensed under the MIT License <http://opensource.org/licenses/MIT>.
SPDX-License-Identifier: MIT
Copyright (c) 2013-2018 Niels Lohmann <http://nlohmann.me>.
Permission is hereby granted, free of charge, to any person obtaining a copy

View file

@ -5,6 +5,7 @@
|_____|_____|_____|_|___| https://github.com/nlohmann/json
Licensed under the MIT License <http://opensource.org/licenses/MIT>.
SPDX-License-Identifier: MIT
Copyright (c) 2013-2018 Niels Lohmann <http://nlohmann.me>.
Permission is hereby granted, free of charge, to any person obtaining a copy

View file

@ -5,6 +5,7 @@
|_____|_____|_____|_|___| https://github.com/nlohmann/json
Licensed under the MIT License <http://opensource.org/licenses/MIT>.
SPDX-License-Identifier: MIT
Copyright (c) 2013-2018 Niels Lohmann <http://nlohmann.me>.
Permission is hereby granted, free of charge, to any person obtaining a copy

View file

@ -5,6 +5,7 @@
|_____|_____|_____|_|___| https://github.com/nlohmann/json
Licensed under the MIT License <http://opensource.org/licenses/MIT>.
SPDX-License-Identifier: MIT
Copyright (c) 2013-2018 Niels Lohmann <http://nlohmann.me>.
Permission is hereby granted, free of charge, to any person obtaining a copy

View file

@ -5,6 +5,7 @@
|_____|_____|_____|_|___| https://github.com/nlohmann/json
Licensed under the MIT License <http://opensource.org/licenses/MIT>.
SPDX-License-Identifier: MIT
Copyright (c) 2013-2018 Niels Lohmann <http://nlohmann.me>.
Permission is hereby granted, free of charge, to any person obtaining a copy

View file

@ -5,6 +5,7 @@
|_____|_____|_____|_|___| https://github.com/nlohmann/json
Licensed under the MIT License <http://opensource.org/licenses/MIT>.
SPDX-License-Identifier: MIT
Copyright (c) 2013-2018 Niels Lohmann <http://nlohmann.me>.
Permission is hereby granted, free of charge, to any person obtaining a copy

View file

@ -5,6 +5,7 @@
|_____|_____|_____|_|___| https://github.com/nlohmann/json
Licensed under the MIT License <http://opensource.org/licenses/MIT>.
SPDX-License-Identifier: MIT
Copyright (c) 2013-2018 Niels Lohmann <http://nlohmann.me>.
Permission is hereby granted, free of charge, to any person obtaining a copy
@ -136,19 +137,19 @@ TEST_CASE("regression tests")
SECTION("issue #70 - Handle infinity and NaN cases")
{
/*
// previously, NAN/INFINITY created a null value; now, the values are
// properly stored, but are dumped as "null"
SECTION("NAN value")
{
CHECK(json(NAN) == json());
CHECK(json(json::number_float_t(NAN)) == json());
CHECK(json(NAN).dump() == "null");
CHECK(json(json::number_float_t(NAN)).dump() == "null");
}
SECTION("infinity")
{
CHECK(json(INFINITY) == json());
CHECK(json(json::number_float_t(INFINITY)) == json());
CHECK(json(INFINITY).dump() == "null");
CHECK(json(json::number_float_t(INFINITY)).dump() == "null");
}
*/
// With 3.0.0, the semantics of this changed: NAN and infinity are
// stored properly inside the JSON value (no exception or conversion
@ -1213,41 +1214,6 @@ TEST_CASE("regression tests")
CHECK(j["bool_vector"].dump() == "[false,true,false,false]");
}
/* NOTE: m_line_buffer is not used any more
SECTION("issue #495 - fill_line_buffer incorrectly tests m_stream for eof but not fail or bad bits")
{
SECTION("setting failbit")
{
std::stringstream ss;
ss << "[1,2,3\n,4,5]";
json::lexer l(ss);
CHECK(l.m_line_buffer == "[1,2,3\n");
l.m_stream->setstate(std::ios_base::failbit);
CHECK_THROWS_AS(l.fill_line_buffer(), json::parse_error&);
CHECK_THROWS_WITH(l.fill_line_buffer(), "[json.exception.parse_error.111] parse error: bad input stream");
}
SECTION("setting badbit")
{
std::stringstream ss;
ss << "[1,2,3\n,4,5]";
json::lexer l(ss);
CHECK(l.m_line_buffer == "[1,2,3\n");
l.m_stream->setstate(std::ios_base::badbit);
CHECK_THROWS_AS(l.fill_line_buffer(), json::parse_error&);
CHECK_THROWS_WITH(l.fill_line_buffer(), "[json.exception.parse_error.111] parse error: bad input stream");
}
}
*/
SECTION("issue #504 - assertion error (OSS-Fuzz 856)")
{
std::vector<uint8_t> vec1 = {0xf9, 0xff, 0xff, 0x4a, 0x3a, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x01, 0x37, 0x02, 0x38};

View file

@ -5,6 +5,7 @@
|_____|_____|_____|_|___| https://github.com/nlohmann/json
Licensed under the MIT License <http://opensource.org/licenses/MIT>.
SPDX-License-Identifier: MIT
Copyright (c) 2013-2018 Niels Lohmann <http://nlohmann.me>.
Permission is hereby granted, free of charge, to any person obtaining a copy

View file

@ -5,6 +5,7 @@
|_____|_____|_____|_|___| https://github.com/nlohmann/json
Licensed under the MIT License <http://opensource.org/licenses/MIT>.
SPDX-License-Identifier: MIT
Copyright (c) 2013-2018 Niels Lohmann <http://nlohmann.me>.
Permission is hereby granted, free of charge, to any person obtaining a copy

View file

@ -5,6 +5,7 @@
|_____|_____|_____|_|___| https://github.com/nlohmann/json
Licensed under the MIT License <http://opensource.org/licenses/MIT>.
SPDX-License-Identifier: MIT
Copyright (c) 2013-2018 Niels Lohmann <http://nlohmann.me>.
Permission is hereby granted, free of charge, to any person obtaining a copy

View file

@ -5,6 +5,7 @@
|_____|_____|_____|_|___| https://github.com/nlohmann/json
Licensed under the MIT License <http://opensource.org/licenses/MIT>.
SPDX-License-Identifier: MIT
Copyright (c) 2013-2018 Niels Lohmann <http://nlohmann.me>.
Permission is hereby granted, free of charge, to any person obtaining a copy
@ -1803,257 +1804,6 @@ TEST_CASE("UBJSON")
}
}
/*
// use this testcase outside [hide] to run it with Valgrind
TEST_CASE("single UBJSON roundtrip")
{
SECTION("sample.json")
{
std::string filename = "test/data/json_testsuite/sample.json";
// parse JSON file
std::ifstream f_json(filename);
json j1 = json::parse(f_json);
// parse MessagePack file
std::ifstream f_ubjson(filename + ".ubj", std::ios::binary);
std::vector<uint8_t> packed((std::istreambuf_iterator<char>(f_ubjson)),
std::istreambuf_iterator<char>());
json j2;
CHECK_NOTHROW(j2 = json::from_ubjson(packed));
// compare parsed JSON values
CHECK(j1 == j2);
SECTION("roundtrips")
{
SECTION("std::ostringstream")
{
std::ostringstream ss;
json::to_ubjson(j1, ss);
json j3 = json::from_ubjson(ss.str());
CHECK(j1 == j3);
}
SECTION("std::string")
{
std::string s;
json::to_ubjson(j1, s);
json j3 = json::from_ubjson(s);
CHECK(j1 == j3);
}
}
// check with different start index
// packed.insert(packed.begin(), 5, 0xff);
// CHECK(j1 == json::from_ubjson(packed.begin() + 5, packed.end()));
}
}
*/
/*
TEST_CASE("UBJSON roundtrips", "[hide]")
{
SECTION("input from py-ubjson")
{
for (std::string filename :
{
"test/data/json_nlohmann_tests/all_unicode.json",
"test/data/json.org/1.json",
"test/data/json.org/2.json",
"test/data/json.org/3.json",
"test/data/json.org/4.json",
"test/data/json.org/5.json",
"test/data/json_roundtrip/roundtrip01.json",
"test/data/json_roundtrip/roundtrip02.json",
"test/data/json_roundtrip/roundtrip03.json",
"test/data/json_roundtrip/roundtrip04.json",
"test/data/json_roundtrip/roundtrip05.json",
"test/data/json_roundtrip/roundtrip06.json",
"test/data/json_roundtrip/roundtrip07.json",
"test/data/json_roundtrip/roundtrip08.json",
"test/data/json_roundtrip/roundtrip09.json",
"test/data/json_roundtrip/roundtrip10.json",
"test/data/json_roundtrip/roundtrip11.json",
"test/data/json_roundtrip/roundtrip12.json",
"test/data/json_roundtrip/roundtrip13.json",
"test/data/json_roundtrip/roundtrip14.json",
"test/data/json_roundtrip/roundtrip15.json",
"test/data/json_roundtrip/roundtrip16.json",
"test/data/json_roundtrip/roundtrip17.json",
"test/data/json_roundtrip/roundtrip18.json",
"test/data/json_roundtrip/roundtrip19.json",
"test/data/json_roundtrip/roundtrip20.json",
"test/data/json_roundtrip/roundtrip21.json",
"test/data/json_roundtrip/roundtrip22.json",
"test/data/json_roundtrip/roundtrip23.json",
"test/data/json_roundtrip/roundtrip24.json",
"test/data/json_roundtrip/roundtrip25.json",
"test/data/json_roundtrip/roundtrip26.json",
"test/data/json_roundtrip/roundtrip27.json",
"test/data/json_roundtrip/roundtrip28.json",
"test/data/json_roundtrip/roundtrip29.json",
"test/data/json_roundtrip/roundtrip30.json",
"test/data/json_roundtrip/roundtrip31.json",
"test/data/json_roundtrip/roundtrip32.json",
"test/data/json_testsuite/sample.json", // kills AppVeyor
"test/data/json_tests/pass1.json",
"test/data/json_tests/pass2.json",
"test/data/json_tests/pass3.json",
"test/data/regression/floats.json",
"test/data/regression/signed_ints.json",
"test/data/regression/unsigned_ints.json",
"test/data/regression/working_file.json",
"test/data/nst_json_testsuite/test_parsing/y_array_arraysWithSpaces.json",
"test/data/nst_json_testsuite/test_parsing/y_array_empty-string.json",
"test/data/nst_json_testsuite/test_parsing/y_array_empty.json",
"test/data/nst_json_testsuite/test_parsing/y_array_ending_with_newline.json",
"test/data/nst_json_testsuite/test_parsing/y_array_false.json",
"test/data/nst_json_testsuite/test_parsing/y_array_heterogeneous.json",
"test/data/nst_json_testsuite/test_parsing/y_array_null.json",
"test/data/nst_json_testsuite/test_parsing/y_array_with_1_and_newline.json",
"test/data/nst_json_testsuite/test_parsing/y_array_with_leading_space.json",
"test/data/nst_json_testsuite/test_parsing/y_array_with_several_null.json",
"test/data/nst_json_testsuite/test_parsing/y_array_with_trailing_space.json",
"test/data/nst_json_testsuite/test_parsing/y_number.json",
"test/data/nst_json_testsuite/test_parsing/y_number_0e+1.json",
"test/data/nst_json_testsuite/test_parsing/y_number_0e1.json",
"test/data/nst_json_testsuite/test_parsing/y_number_after_space.json",
"test/data/nst_json_testsuite/test_parsing/y_number_double_close_to_zero.json",
"test/data/nst_json_testsuite/test_parsing/y_number_double_huge_neg_exp.json",
//"test/data/nst_json_testsuite/test_parsing/y_number_huge_exp.json",
"test/data/nst_json_testsuite/test_parsing/y_number_int_with_exp.json",
"test/data/nst_json_testsuite/test_parsing/y_number_minus_zero.json",
"test/data/nst_json_testsuite/test_parsing/y_number_negative_int.json",
"test/data/nst_json_testsuite/test_parsing/y_number_negative_one.json",
"test/data/nst_json_testsuite/test_parsing/y_number_negative_zero.json",
"test/data/nst_json_testsuite/test_parsing/y_number_real_capital_e.json",
"test/data/nst_json_testsuite/test_parsing/y_number_real_capital_e_neg_exp.json",
"test/data/nst_json_testsuite/test_parsing/y_number_real_capital_e_pos_exp.json",
"test/data/nst_json_testsuite/test_parsing/y_number_real_exponent.json",
"test/data/nst_json_testsuite/test_parsing/y_number_real_fraction_exponent.json",
"test/data/nst_json_testsuite/test_parsing/y_number_real_neg_exp.json",
//"test/data/nst_json_testsuite/test_parsing/y_number_real_neg_overflow.json",
"test/data/nst_json_testsuite/test_parsing/y_number_real_pos_exponent.json",
//"test/data/nst_json_testsuite/test_parsing/y_number_real_pos_overflow.json",
"test/data/nst_json_testsuite/test_parsing/y_number_real_underflow.json",
"test/data/nst_json_testsuite/test_parsing/y_number_simple_int.json",
"test/data/nst_json_testsuite/test_parsing/y_number_simple_real.json",
//"test/data/nst_json_testsuite/test_parsing/y_number_too_big_neg_int.json",
//"test/data/nst_json_testsuite/test_parsing/y_number_too_big_pos_int.json",
//"test/data/nst_json_testsuite/test_parsing/y_number_very_big_negative_int.json",
"test/data/nst_json_testsuite/test_parsing/y_object.json",
"test/data/nst_json_testsuite/test_parsing/y_object_basic.json",
"test/data/nst_json_testsuite/test_parsing/y_object_duplicated_key.json",
"test/data/nst_json_testsuite/test_parsing/y_object_duplicated_key_and_value.json",
"test/data/nst_json_testsuite/test_parsing/y_object_empty.json",
"test/data/nst_json_testsuite/test_parsing/y_object_empty_key.json",
"test/data/nst_json_testsuite/test_parsing/y_object_escaped_null_in_key.json",
"test/data/nst_json_testsuite/test_parsing/y_object_extreme_numbers.json",
"test/data/nst_json_testsuite/test_parsing/y_object_long_strings.json",
"test/data/nst_json_testsuite/test_parsing/y_object_simple.json",
"test/data/nst_json_testsuite/test_parsing/y_object_string_unicode.json",
"test/data/nst_json_testsuite/test_parsing/y_object_with_newlines.json",
"test/data/nst_json_testsuite/test_parsing/y_string_1_2_3_bytes_UTF-8_sequences.json",
"test/data/nst_json_testsuite/test_parsing/y_string_UTF-16_Surrogates_U+1D11E_MUSICAL_SYMBOL_G_CLEF.json",
"test/data/nst_json_testsuite/test_parsing/y_string_accepted_surrogate_pair.json",
"test/data/nst_json_testsuite/test_parsing/y_string_accepted_surrogate_pairs.json",
"test/data/nst_json_testsuite/test_parsing/y_string_allowed_escapes.json",
"test/data/nst_json_testsuite/test_parsing/y_string_backslash_and_u_escaped_zero.json",
"test/data/nst_json_testsuite/test_parsing/y_string_backslash_doublequotes.json",
"test/data/nst_json_testsuite/test_parsing/y_string_comments.json",
"test/data/nst_json_testsuite/test_parsing/y_string_double_escape_a.json",
"test/data/nst_json_testsuite/test_parsing/y_string_double_escape_n.json",
"test/data/nst_json_testsuite/test_parsing/y_string_escaped_control_character.json",
"test/data/nst_json_testsuite/test_parsing/y_string_escaped_noncharacter.json",
"test/data/nst_json_testsuite/test_parsing/y_string_in_array.json",
"test/data/nst_json_testsuite/test_parsing/y_string_in_array_with_leading_space.json",
"test/data/nst_json_testsuite/test_parsing/y_string_last_surrogates_1_and_2.json",
"test/data/nst_json_testsuite/test_parsing/y_string_newline_uescaped.json",
"test/data/nst_json_testsuite/test_parsing/y_string_nonCharacterInUTF-8_U+10FFFF.json",
"test/data/nst_json_testsuite/test_parsing/y_string_nonCharacterInUTF-8_U+1FFFF.json",
"test/data/nst_json_testsuite/test_parsing/y_string_nonCharacterInUTF-8_U+FFFF.json",
"test/data/nst_json_testsuite/test_parsing/y_string_null_escape.json",
"test/data/nst_json_testsuite/test_parsing/y_string_one-byte-utf-8.json",
"test/data/nst_json_testsuite/test_parsing/y_string_pi.json",
"test/data/nst_json_testsuite/test_parsing/y_string_simple_ascii.json",
"test/data/nst_json_testsuite/test_parsing/y_string_space.json",
"test/data/nst_json_testsuite/test_parsing/y_string_three-byte-utf-8.json",
"test/data/nst_json_testsuite/test_parsing/y_string_two-byte-utf-8.json",
"test/data/nst_json_testsuite/test_parsing/y_string_u+2028_line_sep.json",
"test/data/nst_json_testsuite/test_parsing/y_string_u+2029_par_sep.json",
"test/data/nst_json_testsuite/test_parsing/y_string_uEscape.json",
"test/data/nst_json_testsuite/test_parsing/y_string_unescaped_char_delete.json",
"test/data/nst_json_testsuite/test_parsing/y_string_unicode.json",
"test/data/nst_json_testsuite/test_parsing/y_string_unicodeEscapedBackslash.json",
"test/data/nst_json_testsuite/test_parsing/y_string_unicode_2.json",
"test/data/nst_json_testsuite/test_parsing/y_string_unicode_U+200B_ZERO_WIDTH_SPACE.json",
"test/data/nst_json_testsuite/test_parsing/y_string_unicode_U+2064_invisible_plus.json",
"test/data/nst_json_testsuite/test_parsing/y_string_unicode_escaped_double_quote.json",
// "test/data/nst_json_testsuite/test_parsing/y_string_utf16.json",
"test/data/nst_json_testsuite/test_parsing/y_string_utf8.json",
"test/data/nst_json_testsuite/test_parsing/y_string_with_del_character.json",
"test/data/nst_json_testsuite/test_parsing/y_structure_lonely_false.json",
"test/data/nst_json_testsuite/test_parsing/y_structure_lonely_int.json",
"test/data/nst_json_testsuite/test_parsing/y_structure_lonely_negative_real.json",
"test/data/nst_json_testsuite/test_parsing/y_structure_lonely_null.json",
"test/data/nst_json_testsuite/test_parsing/y_structure_lonely_string.json",
"test/data/nst_json_testsuite/test_parsing/y_structure_lonely_true.json",
"test/data/nst_json_testsuite/test_parsing/y_structure_string_empty.json",
"test/data/nst_json_testsuite/test_parsing/y_structure_trailing_newline.json",
"test/data/nst_json_testsuite/test_parsing/y_structure_true_in_array.json",
"test/data/nst_json_testsuite/test_parsing/y_structure_whitespace_array.json"
})
{
CAPTURE(filename);
// parse JSON file
std::ifstream f_json(filename);
json j1 = json::parse(f_json);
SECTION("std::vector<uint8_t>")
{
// parse UBJSON file
std::ifstream f_ubjson(filename + ".ubj", std::ios::binary);
std::vector<uint8_t> packed(
(std::istreambuf_iterator<char>(f_ubjson)),
std::istreambuf_iterator<char>());
json j2;
CHECK_NOTHROW(j2 = json::from_ubjson(packed));
// compare parsed JSON values
CHECK(j1 == j2);
}
SECTION("std::ifstream")
{
// parse UBJSON file
std::ifstream f_ubjson(filename + ".ubj", std::ios::binary);
json j2;
CHECK_NOTHROW(j2 = json::from_ubjson(f_ubjson));
// compare parsed JSON values
CHECK(j1 == j2);
}
SECTION("uint8_t* and size")
{
// parse UBJSON file
std::ifstream f_ubjson(filename + ".ubj", std::ios::binary);
std::vector<uint8_t> packed(
(std::istreambuf_iterator<char>(f_ubjson)),
std::istreambuf_iterator<char>());
json j2;
CHECK_NOTHROW(j2 = json::from_ubjson({packed.data(), packed.size()}));
// compare parsed JSON values
CHECK(j1 == j2);
}
}
}
}
*/
TEST_CASE("Universal Binary JSON Specification Examples 1")
{
SECTION("Null Value")
@ -2363,40 +2113,6 @@ TEST_CASE("Universal Binary JSON Specification Examples 1")
}
}
/*
TEST_CASE("Universal Binary JSON Specification Examples 2")
{
for (std::string prefix :
{
"test/data/universal-binary-json-java/CouchDB4k",
"test/data/universal-binary-json-java/MediaContent",
"test/data/universal-binary-json-java/TwitterTimeline"
})
{
CAPTURE(prefix);
// parse JSON file
std::ifstream f_json(prefix + ".formatted.json");
json j1 = json::parse(f_json);
SECTION("std::vector<uint8_t>")
{
// parse UBJSON file
std::ifstream f_ubjson(prefix + ".ubj", std::ios::binary);
std::vector<uint8_t> packed(
(std::istreambuf_iterator<char>(f_ubjson)),
std::istreambuf_iterator<char>());
json j2;
CHECK_NOTHROW(j2 = json::from_ubjson(packed));
// compare parsed JSON values
CHECK(j1 == j2);
}
}
}
*/
TEST_CASE("all UBJSON first bytes", "[!throws]")
{
// these bytes will fail immediately with exception parse_error.112

View file

@ -5,6 +5,7 @@
|_____|_____|_____|_|___| https://github.com/nlohmann/json
Licensed under the MIT License <http://opensource.org/licenses/MIT>.
SPDX-License-Identifier: MIT
Copyright (c) 2013-2018 Niels Lohmann <http://nlohmann.me>.
Permission is hereby granted, free of charge, to any person obtaining a copy

View file

@ -5,6 +5,7 @@
|_____|_____|_____|_|___| https://github.com/nlohmann/json
Licensed under the MIT License <http://opensource.org/licenses/MIT>.
SPDX-License-Identifier: MIT
Copyright (c) 2013-2018 Niels Lohmann <http://nlohmann.me>.
Permission is hereby granted, free of charge, to any person obtaining a copy

112
test/src/unit-wstring.cpp Normal file
View file

@ -0,0 +1,112 @@
/*
__ _____ _____ _____
__| | __| | | | JSON for Modern C++ (test suite)
| | |__ | | | | | | version 3.1.2
|_____|_____|_____|_|___| https://github.com/nlohmann/json
Licensed under the MIT License <http://opensource.org/licenses/MIT>.
SPDX-License-Identifier: MIT
Copyright (c) 2013-2018 Niels Lohmann <http://nlohmann.me>.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
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.
*/
#include "catch.hpp"
#include <nlohmann/json.hpp>
using nlohmann::json;
bool wstring_is_utf16();
bool wstring_is_utf16()
{
return (std::wstring(L"💩") == std::wstring(L"\U0001F4A9"));
}
bool u16string_is_utf16();
bool u16string_is_utf16()
{
return (std::u16string(u"💩") == std::u16string(u"\U0001F4A9"));
}
bool u32string_is_utf32();
bool u32string_is_utf32()
{
return (std::u32string(U"💩") == std::u32string(U"\U0001F4A9"));
}
TEST_CASE("wide strings")
{
SECTION("std::wstring")
{
if (wstring_is_utf16())
{
std::wstring w = L"[12.2,\"Ⴥaäö💤🧢\"]";
json j = json::parse(w);
CHECK(j.dump() == "[12.2,\"Ⴥaäö💤🧢\"]");
}
}
SECTION("invalid std::wstring")
{
if (wstring_is_utf16())
{
std::wstring w = L"\"\xDBFF";
CHECK_THROWS_AS(json::parse(w), json::parse_error&);
}
}
SECTION("std::u16string")
{
if (u16string_is_utf16())
{
std::u16string w = u"[12.2,\"Ⴥaäö💤🧢\"]";
json j = json::parse(w);
CHECK(j.dump() == "[12.2,\"Ⴥaäö💤🧢\"]");
}
}
SECTION("invalid std::u16string")
{
if (wstring_is_utf16())
{
std::u16string w = u"\"\xDBFF";
CHECK_THROWS_AS(json::parse(w), json::parse_error&);
}
}
SECTION("std::u32string")
{
if (u32string_is_utf32())
{
std::u32string w = U"[12.2,\"Ⴥaäö💤🧢\"]";
json j = json::parse(w);
CHECK(j.dump() == "[12.2,\"Ⴥaäö💤🧢\"]");
}
}
SECTION("invalid std::u32string")
{
if (u32string_is_utf32())
{
std::u32string w = U"\"\x110000";
CHECK_THROWS_AS(json::parse(w), json::parse_error&);
}
}
}

View file

@ -5,6 +5,7 @@
|_____|_____|_____|_|___| https://github.com/nlohmann/json
Licensed under the MIT License <http://opensource.org/licenses/MIT>.
SPDX-License-Identifier: MIT
Copyright (c) 2013-2018 Niels Lohmann <http://nlohmann.me>.
Permission is hereby granted, free of charge, to any person obtaining a copy