diff --git a/.github/ISSUE_TEMPLATE.md b/.github/ISSUE_TEMPLATE/Bug_report.md similarity index 81% rename from .github/ISSUE_TEMPLATE.md rename to .github/ISSUE_TEMPLATE/Bug_report.md index a3140bc1..177a4b39 100644 --- a/.github/ISSUE_TEMPLATE.md +++ b/.github/ISSUE_TEMPLATE/Bug_report.md @@ -1,22 +1,19 @@ -**Bug Report** - -- What is the issue you have? - -- Please describe the steps to reproduce the issue. Can you provide a small but working code example? - -- What is the expected behavior? - -- And what is the actual behavior instead? - -- Which compiler and operating system are you using? Is it a [supported compiler](https://github.com/nlohmann/json#supported-compilers)? - -- Did you use a released version of the library or the version from the `develop` branch? - -- If you experience a compilation error: can you [compile and run the unit tests](https://github.com/nlohmann/json#execute-unit-tests)? - - -**Feature Request** - -- Describe the feature in as much detail as possible. - -- Include sample usage where appropriate. +--- +name: Bug report +about: Create a report to help us improve + +--- + +- What is the issue you have? + +- Please describe the steps to reproduce the issue. Can you provide a small but working code example? + +- What is the expected behavior? + +- And what is the actual behavior instead? + +- Which compiler and operating system are you using? Is it a [supported compiler](https://github.com/nlohmann/json#supported-compilers)? + +- Did you use a released version of the library or the version from the `develop` branch? + +- If you experience a compilation error: can you [compile and run the unit tests](https://github.com/nlohmann/json#execute-unit-tests)? diff --git a/.github/ISSUE_TEMPLATE/Feature_request.md b/.github/ISSUE_TEMPLATE/Feature_request.md new file mode 100644 index 00000000..f5ea57ca --- /dev/null +++ b/.github/ISSUE_TEMPLATE/Feature_request.md @@ -0,0 +1,9 @@ +--- +name: Feature request +about: Suggest an idea for this project + +--- + +- Describe the feature in as much detail as possible. + +- Include sample usage where appropriate. diff --git a/.travis.yml b/.travis.yml index 68a16db5..ecc8c362 100644 --- a/.travis.yml +++ b/.travis.yml @@ -155,6 +155,9 @@ matrix: - os: osx osx_image: xcode9.2 + - os: osx + osx_image: xcode9.3 + # Linux / GCC - os: linux diff --git a/CMakeLists.txt b/CMakeLists.txt index a490ab6b..031a66f2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -22,13 +22,15 @@ option(JSON_MultipleHeaders "Use non-amalgamated version of the library." OFF) ## CONFIGURATION ## set(NLOHMANN_JSON_TARGET_NAME ${PROJECT_NAME}) -set(NLOHMANN_JSON_CONFIG_INSTALL_DIR "lib/cmake/${PROJECT_NAME}") +set(NLOHMANN_JSON_CONFIG_INSTALL_DIR "lib/cmake/${PROJECT_NAME}" + CACHE INTERNAL "") set(NLOHMANN_JSON_INCLUDE_INSTALL_DIR "include") set(NLOHMANN_JSON_TARGETS_EXPORT_NAME "${PROJECT_NAME}Targets") set(NLOHMANN_JSON_CMAKE_CONFIG_TEMPLATE "cmake/config.cmake.in") -set(NLOHMANN_JSON_CMAKE_CONFIG_DIR "${CMAKE_CURRENT_BINARY_DIR}/cmake_config") +set(NLOHMANN_JSON_CMAKE_CONFIG_DIR "${CMAKE_CURRENT_BINARY_DIR}") set(NLOHMANN_JSON_CMAKE_VERSION_CONFIG_FILE "${NLOHMANN_JSON_CMAKE_CONFIG_DIR}/${PROJECT_NAME}ConfigVersion.cmake") set(NLOHMANN_JSON_CMAKE_PROJECT_CONFIG_FILE "${NLOHMANN_JSON_CMAKE_CONFIG_DIR}/${PROJECT_NAME}Config.cmake") +set(NLOHMANN_JSON_CMAKE_PROJECT_TARGETS_FILE "${NLOHMANN_JSON_CMAKE_CONFIG_DIR}/${PROJECT_NAME}Targets.cmake") if (JSON_MultipleHeaders) set(NLOHMANN_JSON_INCLUDE_BUILD_DIR "${PROJECT_SOURCE_DIR}/include/") @@ -43,7 +45,7 @@ endif() ## create target and add include path ## add_library(${NLOHMANN_JSON_TARGET_NAME} INTERFACE) - +add_library(${PROJECT_NAME}::${NLOHMANN_JSON_TARGET_NAME} ALIAS ${NLOHMANN_JSON_TARGET_NAME}) target_compile_features(${NLOHMANN_JSON_TARGET_NAME} INTERFACE cxx_std_11) target_include_directories( @@ -53,7 +55,7 @@ target_include_directories( $ ) -## add debug view defintion file for msvc (natvis) +## add debug view definition file for msvc (natvis) if (MSVC) set(NLOHMANN_ADD_NATVIS TRUE) set(NLOHMANN_NATVIS_FILE "nlohmann_json.natvis") @@ -104,6 +106,11 @@ if (NLOHMANN_ADD_NATVIS) DESTINATION . ) endif() +export( + TARGETS ${NLOHMANN_JSON_TARGET_NAME} + NAMESPACE ${PROJECT_NAME}:: + FILE ${NLOHMANN_JSON_CMAKE_PROJECT_TARGETS_FILE} +) install( TARGETS ${NLOHMANN_JSON_TARGET_NAME} EXPORT ${NLOHMANN_JSON_TARGETS_EXPORT_NAME} @@ -111,5 +118,6 @@ install( ) install( EXPORT ${NLOHMANN_JSON_TARGETS_EXPORT_NAME} + NAMESPACE ${PROJECT_NAME}:: DESTINATION ${NLOHMANN_JSON_CONFIG_INSTALL_DIR} ) diff --git a/README.md b/README.md index e2e180d7..74710bfe 100644 --- a/README.md +++ b/README.md @@ -834,7 +834,8 @@ The following compilers are currently used in continuous integration at [Travis] | Clang Xcode 8.3 | Darwin Kernel Version 16.5.0 (macOS 10.12.4) | Apple LLVM version 8.1.0 (clang-802.0.38) | | Clang Xcode 9.0 | Darwin Kernel Version 16.7.0 (macOS 10.12.6) | Apple LLVM version 9.0.0 (clang-900.0.37) | | Clang Xcode 9.1 | Darwin Kernel Version 16.7.0 (macOS 10.12.6) | Apple LLVM version 9.0.0 (clang-900.0.38) | -| Clang Xcode 9.2 | Darwin Kernel Version 16.7.0 (macOS 10.12.6) | Apple LLVM version 8.1.0 (clang-900.0.39.2) | +| Clang Xcode 9.2 | Darwin Kernel Version 16.7.0 (macOS 10.12.6) | Apple LLVM version 9.0.0 (clang-900.0.39.2) | +| Clang Xcode 9.3 | Darwin Kernel Version 17.4.0 (macOS 10.13.0) | Apple LLVM version 9.1.0 (clang-902.0.39.1) | Visual Studio 14 2015 | Windows Server 2012 R2 (x64) | Microsoft (R) Build Engine version 14.0.25420.1, MSVC 19.0.24215.1 | | Visual Studio 2017 | Windows Server 2016 | Microsoft (R) Build Engine version 15.5.180.51428, MSVC 19.12.25830.2 | @@ -864,6 +865,10 @@ If you have questions regarding the library, I would like to invite you to [open Only if your request would contain confidential information, please [send me an email](mailto:mail@nlohmann.me). For encrypted messages, please use [this key](https://keybase.io/nlohmann/pgp_keys.asc). +## Security + +[Commits by Niels Lohmann](https://github.com/nlohmann/json/commits) and [releases](https://github.com/nlohmann/json/releases) are signed with this [PGP Key](https://keybase.io/nlohmann/pgp_keys.asc?fingerprint=797167ae41c0a6d9232e48457f3cea63ae251b69). + ## Thanks @@ -977,14 +982,19 @@ I deeply appreciate the help of the following people. - [Paul Fultz II](https://github.com/pfultz2) added a note on the cget package manager. - [Wilson Lin](https://github.com/wla80) made the integration section of the README more concise. - [RalfBielig](https://github.com/ralfbielig) detected and fixed a memory leak in the parser callback. -- [agrianius](https://github.com/agrianius) allowed to dump JSON to an alternative string type +- [agrianius](https://github.com/agrianius) allowed to dump JSON to an alternative string type. +- [Kevin Tonon](https://github.com/ktonon) overworked the C++11 compiler checks in CMake. +- [Axel Huebl](https://github.com/ax3l) simplified a CMake check and added support for the [Spack package manager](https://spack.io). +- [Carlos O'Ryan](https://github.com/coryan) fixed a typo. +- [James Upjohn](https://github.com/jammehcow) fixed a version number in the compilers section. +- [Chuck Atkins](https://github.com/chuckatkins) adjusted the CMake files to the CMake packaging guidelines Thanks a lot for helping out! Please [let me know](mailto:mail@nlohmann.me) if I forgot someone. ## Used third-party tools -The library itself contains of a single header file licensed under the MIT license. However, it is built, tested, documented, and whatnot using a lot of third-party tools and services. Thanks a lot! +The library itself consists of a single header file licensed under the MIT license. However, it is built, tested, documented, and whatnot using a lot of third-party tools and services. Thanks a lot! - [**amalgamate.py - Amalgamate C source and header files**](https://github.com/edlund/amalgamate) to create a single header file - [**American fuzzy lop**](http://lcamtuf.coredump.cx/afl/) for fuzz testing diff --git a/cmake/config.cmake.in b/cmake/config.cmake.in index b4fd29d9..8baabf07 100644 --- a/cmake/config.cmake.in +++ b/cmake/config.cmake.in @@ -1,3 +1,5 @@ @PACKAGE_INIT@ -include("${CMAKE_CURRENT_LIST_DIR}/@NLOHMANN_JSON_TARGETS_EXPORT_NAME@.cmake") +if(NOT TARGET @PROJECT_NAME@::@NLOHMANN_JSON_TARGET_NAME@) + include("${CMAKE_CURRENT_LIST_DIR}/@NLOHMANN_JSON_TARGETS_EXPORT_NAME@.cmake") +endif() check_required_components("@PROJECT_NAME@") diff --git a/doc/avatars.png b/doc/avatars.png index 00241908..4d557d28 100644 Binary files a/doc/avatars.png and b/doc/avatars.png differ diff --git a/include/nlohmann/detail/input/input_adapters.hpp b/include/nlohmann/detail/input/input_adapters.hpp index 4c942f33..6a3ffa2b 100644 --- a/include/nlohmann/detail/input/input_adapters.hpp +++ b/include/nlohmann/detail/input/input_adapters.hpp @@ -115,6 +115,176 @@ class input_buffer_adapter : public input_adapter_protocol const char* const limit; }; +template +class wide_string_input_adapter : public input_adapter_protocol +{ + public: + wide_string_input_adapter(const WideStringType& w) : str(w) {} + + std::char_traits::int_type get_character() noexcept override + { + // unget_character() was called previously: return the last character + if (next_unget) + { + next_unget = false; + return last_char; + } + + // check if buffer needs to be filled + if (utf8_bytes_index == utf8_bytes_filled) + { + if (sizeof(typename WideStringType::value_type) == 2) + { + fill_buffer_utf16(); + } + else + { + fill_buffer_utf32(); + } + + assert(utf8_bytes_filled > 0); + assert(utf8_bytes_index == 0); + } + + // use buffer + assert(utf8_bytes_filled > 0); + assert(utf8_bytes_index < utf8_bytes_filled); + return (last_char = utf8_bytes[utf8_bytes_index++]); + } + + void unget_character() noexcept override + { + next_unget = true; + } + + private: + void fill_buffer_utf16() + { + utf8_bytes_index = 0; + + if (current_wchar == str.size()) + { + utf8_bytes[0] = std::char_traits::eof(); + utf8_bytes_filled = 1; + } + else + { + // get the current character + const int wc = static_cast(str[current_wchar++]); + + // UTF-16 to UTF-8 encoding + if (wc < 0x80) + { + utf8_bytes[0] = wc; + utf8_bytes_filled = 1; + } + else if (wc <= 0x7FF) + { + utf8_bytes[0] = 0xC0 | ((wc >> 6)); + utf8_bytes[1] = 0x80 | (wc & 0x3F); + utf8_bytes_filled = 2; + } + else if (0xD800 > wc or wc >= 0xE000) + { + utf8_bytes[0] = 0xE0 | ((wc >> 12)); + utf8_bytes[1] = 0x80 | ((wc >> 6) & 0x3F); + utf8_bytes[2] = 0x80 | (wc & 0x3F); + utf8_bytes_filled = 3; + } + else + { + if (current_wchar < str.size()) + { + const int wc2 = static_cast(str[current_wchar++]); + const int charcode = 0x10000 + (((wc & 0x3FF) << 10) | (wc2 & 0x3FF)); + utf8_bytes[0] = 0xf0 | (charcode >> 18); + utf8_bytes[1] = 0x80 | ((charcode >> 12) & 0x3F); + utf8_bytes[2] = 0x80 | ((charcode >> 6) & 0x3F); + utf8_bytes[3] = 0x80 | (charcode & 0x3F); + utf8_bytes_filled = 4; + } + else + { + // unknown character + ++current_wchar; + utf8_bytes[0] = wc; + utf8_bytes_filled = 1; + } + } + } + } + + void fill_buffer_utf32() + { + utf8_bytes_index = 0; + + if (current_wchar == str.size()) + { + utf8_bytes[0] = std::char_traits::eof(); + utf8_bytes_filled = 1; + } + else + { + // get the current character + const int wc = static_cast(str[current_wchar++]); + + // UTF-32 to UTF-8 encoding + if (wc < 0x80) + { + utf8_bytes[0] = wc; + utf8_bytes_filled = 1; + } + else if (wc <= 0x7FF) + { + utf8_bytes[0] = 0xC0 | ((wc >> 6) & 0x1F); + utf8_bytes[1] = 0x80 | (wc & 0x3F); + utf8_bytes_filled = 2; + } + else if (wc <= 0xFFFF) + { + utf8_bytes[0] = 0xE0 | ((wc >> 12) & 0x0F); + utf8_bytes[1] = 0x80 | ((wc >> 6) & 0x3F); + utf8_bytes[2] = 0x80 | (wc & 0x3F); + utf8_bytes_filled = 3; + } + else if (wc <= 0x10FFFF) + { + utf8_bytes[0] = 0xF0 | ((wc >> 18 ) & 0x07); + utf8_bytes[1] = 0x80 | ((wc >> 12) & 0x3F); + utf8_bytes[2] = 0x80 | ((wc >> 6) & 0x3F); + utf8_bytes[3] = 0x80 | (wc & 0x3F); + utf8_bytes_filled = 4; + } + else + { + // unknown character + utf8_bytes[0] = wc; + utf8_bytes_filled = 1; + } + } + } + + private: + /// the wstring to process + const WideStringType& str; + + /// index of the current wchar in str + std::size_t current_wchar = 0; + + /// a buffer for UTF-8 bytes + std::array::int_type, 4> utf8_bytes = {{0, 0, 0, 0}}; + + /// index to the utf8_codes array for the next valid byte + std::size_t utf8_bytes_index = 0; + /// number of valid bytes in the utf8_codes array + std::size_t utf8_bytes_filled = 0; + + /// the last character (returned after unget_character() is called) + std::char_traits::int_type last_char = 0; + /// whether get_character() should return last_char + bool next_unget = false; +}; + class input_adapter { public: @@ -128,6 +298,15 @@ class input_adapter input_adapter(std::istream&& i) : ia(std::make_shared(i)) {} + input_adapter(const std::wstring& ws) + : ia(std::make_shared>(ws)) {} + + input_adapter(const std::u16string& ws) + : ia(std::make_shared>(ws)) {} + + input_adapter(const std::u32string& ws) + : ia(std::make_shared>(ws)) {} + /// input adapter for buffer template. +SPDX-License-Identifier: MIT Copyright (c) 2013-2018 Niels Lohmann . Permission is hereby granted, free of charge, to any person obtaining a copy @@ -3412,7 +3413,7 @@ class basic_json @return copy of the element at key @a key or @a default_value if @a key is not found - @throw type_error.306 if the JSON value is not an objec; in that case, + @throw type_error.306 if the JSON value is not an object; in that case, using `value()` with a key makes no sense. @complexity Logarithmic in the size of the container. diff --git a/single_include/nlohmann/json.hpp b/single_include/nlohmann/json.hpp index 8558651d..fa7f585d 100644 --- a/single_include/nlohmann/json.hpp +++ b/single_include/nlohmann/json.hpp @@ -5,6 +5,7 @@ |_____|_____|_____|_|___| https://github.com/nlohmann/json Licensed under the MIT License . +SPDX-License-Identifier: MIT Copyright (c) 2013-2018 Niels Lohmann . Permission is hereby granted, free of charge, to any person obtaining a copy @@ -1688,6 +1689,176 @@ class input_buffer_adapter : public input_adapter_protocol const char* const limit; }; +template +class wide_string_input_adapter : public input_adapter_protocol +{ + public: + wide_string_input_adapter(const WideStringType& w) : str(w) {} + + std::char_traits::int_type get_character() noexcept override + { + // unget_character() was called previously: return the last character + if (next_unget) + { + next_unget = false; + return last_char; + } + + // check if buffer needs to be filled + if (utf8_bytes_index == utf8_bytes_filled) + { + if (sizeof(typename WideStringType::value_type) == 2) + { + fill_buffer_utf16(); + } + else + { + fill_buffer_utf32(); + } + + assert(utf8_bytes_filled > 0); + assert(utf8_bytes_index == 0); + } + + // use buffer + assert(utf8_bytes_filled > 0); + assert(utf8_bytes_index < utf8_bytes_filled); + return (last_char = utf8_bytes[utf8_bytes_index++]); + } + + void unget_character() noexcept override + { + next_unget = true; + } + + private: + void fill_buffer_utf16() + { + utf8_bytes_index = 0; + + if (current_wchar == str.size()) + { + utf8_bytes[0] = std::char_traits::eof(); + utf8_bytes_filled = 1; + } + else + { + // get the current character + const int wc = static_cast(str[current_wchar++]); + + // UTF-16 to UTF-8 encoding + if (wc < 0x80) + { + utf8_bytes[0] = wc; + utf8_bytes_filled = 1; + } + else if (wc <= 0x7FF) + { + utf8_bytes[0] = 0xC0 | ((wc >> 6)); + utf8_bytes[1] = 0x80 | (wc & 0x3F); + utf8_bytes_filled = 2; + } + else if (0xD800 > wc or wc >= 0xE000) + { + utf8_bytes[0] = 0xE0 | ((wc >> 12)); + utf8_bytes[1] = 0x80 | ((wc >> 6) & 0x3F); + utf8_bytes[2] = 0x80 | (wc & 0x3F); + utf8_bytes_filled = 3; + } + else + { + if (current_wchar < str.size()) + { + const int wc2 = static_cast(str[current_wchar++]); + const int charcode = 0x10000 + (((wc & 0x3FF) << 10) | (wc2 & 0x3FF)); + utf8_bytes[0] = 0xf0 | (charcode >> 18); + utf8_bytes[1] = 0x80 | ((charcode >> 12) & 0x3F); + utf8_bytes[2] = 0x80 | ((charcode >> 6) & 0x3F); + utf8_bytes[3] = 0x80 | (charcode & 0x3F); + utf8_bytes_filled = 4; + } + else + { + // unknown character + ++current_wchar; + utf8_bytes[0] = wc; + utf8_bytes_filled = 1; + } + } + } + } + + void fill_buffer_utf32() + { + utf8_bytes_index = 0; + + if (current_wchar == str.size()) + { + utf8_bytes[0] = std::char_traits::eof(); + utf8_bytes_filled = 1; + } + else + { + // get the current character + const int wc = static_cast(str[current_wchar++]); + + // UTF-32 to UTF-8 encoding + if (wc < 0x80) + { + utf8_bytes[0] = wc; + utf8_bytes_filled = 1; + } + else if (wc <= 0x7FF) + { + utf8_bytes[0] = 0xC0 | ((wc >> 6) & 0x1F); + utf8_bytes[1] = 0x80 | (wc & 0x3F); + utf8_bytes_filled = 2; + } + else if (wc <= 0xFFFF) + { + utf8_bytes[0] = 0xE0 | ((wc >> 12) & 0x0F); + utf8_bytes[1] = 0x80 | ((wc >> 6) & 0x3F); + utf8_bytes[2] = 0x80 | (wc & 0x3F); + utf8_bytes_filled = 3; + } + else if (wc <= 0x10FFFF) + { + utf8_bytes[0] = 0xF0 | ((wc >> 18 ) & 0x07); + utf8_bytes[1] = 0x80 | ((wc >> 12) & 0x3F); + utf8_bytes[2] = 0x80 | ((wc >> 6) & 0x3F); + utf8_bytes[3] = 0x80 | (wc & 0x3F); + utf8_bytes_filled = 4; + } + else + { + // unknown character + utf8_bytes[0] = wc; + utf8_bytes_filled = 1; + } + } + } + + private: + /// the wstring to process + const WideStringType& str; + + /// index of the current wchar in str + std::size_t current_wchar = 0; + + /// a buffer for UTF-8 bytes + std::array::int_type, 4> utf8_bytes = {{0, 0, 0, 0}}; + + /// index to the utf8_codes array for the next valid byte + std::size_t utf8_bytes_index = 0; + /// number of valid bytes in the utf8_codes array + std::size_t utf8_bytes_filled = 0; + + /// the last character (returned after unget_character() is called) + std::char_traits::int_type last_char = 0; + /// whether get_character() should return last_char + bool next_unget = false; +}; + class input_adapter { public: @@ -1701,6 +1872,15 @@ class input_adapter input_adapter(std::istream&& i) : ia(std::make_shared(i)) {} + input_adapter(const std::wstring& ws) + : ia(std::make_shared>(ws)) {} + + input_adapter(const std::u16string& ws) + : ia(std::make_shared>(ws)) {} + + input_adapter(const std::u32string& ws) + : ia(std::make_shared>(ws)) {} + /// input adapter for buffer template. +SPDX-License-Identifier: MIT Copyright (c) 2013-2018 Niels Lohmann . Permission is hereby granted, free of charge, to any person obtaining a copy diff --git a/test/src/unit-allocator.cpp b/test/src/unit-allocator.cpp index debe69ad..2566d298 100644 --- a/test/src/unit-allocator.cpp +++ b/test/src/unit-allocator.cpp @@ -5,6 +5,7 @@ |_____|_____|_____|_|___| https://github.com/nlohmann/json Licensed under the MIT License . +SPDX-License-Identifier: MIT Copyright (c) 2013-2018 Niels Lohmann . 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") diff --git a/test/src/unit-alt-string.cpp b/test/src/unit-alt-string.cpp index 36c8b83b..cc05039c 100644 --- a/test/src/unit-alt-string.cpp +++ b/test/src/unit-alt-string.cpp @@ -5,6 +5,7 @@ |_____|_____|_____|_|___| https://github.com/nlohmann/json Licensed under the MIT License . +SPDX-License-Identifier: MIT Copyright (c) 2018 Vitaliy Manushkin . Permission is hereby granted, free of charge, to any person obtaining a copy diff --git a/test/src/unit-capacity.cpp b/test/src/unit-capacity.cpp index 47ac03cc..3cdaed92 100644 --- a/test/src/unit-capacity.cpp +++ b/test/src/unit-capacity.cpp @@ -5,6 +5,7 @@ |_____|_____|_____|_|___| https://github.com/nlohmann/json Licensed under the MIT License . +SPDX-License-Identifier: MIT Copyright (c) 2013-2018 Niels Lohmann . Permission is hereby granted, free of charge, to any person obtaining a copy diff --git a/test/src/unit-cbor.cpp b/test/src/unit-cbor.cpp index 29879508..21235b0d 100644 --- a/test/src/unit-cbor.cpp +++ b/test/src/unit-cbor.cpp @@ -5,6 +5,7 @@ |_____|_____|_____|_|___| https://github.com/nlohmann/json Licensed under the MIT License . +SPDX-License-Identifier: MIT Copyright (c) 2013-2018 Niels Lohmann . 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((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 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") diff --git a/test/src/unit-class_const_iterator.cpp b/test/src/unit-class_const_iterator.cpp index 8319fef5..20cc7529 100644 --- a/test/src/unit-class_const_iterator.cpp +++ b/test/src/unit-class_const_iterator.cpp @@ -5,6 +5,7 @@ |_____|_____|_____|_|___| https://github.com/nlohmann/json Licensed under the MIT License . +SPDX-License-Identifier: MIT Copyright (c) 2013-2018 Niels Lohmann . Permission is hereby granted, free of charge, to any person obtaining a copy diff --git a/test/src/unit-class_iterator.cpp b/test/src/unit-class_iterator.cpp index 484a49de..07218d9f 100644 --- a/test/src/unit-class_iterator.cpp +++ b/test/src/unit-class_iterator.cpp @@ -5,6 +5,7 @@ |_____|_____|_____|_|___| https://github.com/nlohmann/json Licensed under the MIT License . +SPDX-License-Identifier: MIT Copyright (c) 2013-2018 Niels Lohmann . Permission is hereby granted, free of charge, to any person obtaining a copy diff --git a/test/src/unit-class_lexer.cpp b/test/src/unit-class_lexer.cpp index 164dc67d..35338a80 100644 --- a/test/src/unit-class_lexer.cpp +++ b/test/src/unit-class_lexer.cpp @@ -5,6 +5,7 @@ |_____|_____|_____|_|___| https://github.com/nlohmann/json Licensed under the MIT License . +SPDX-License-Identifier: MIT Copyright (c) 2013-2018 Niels Lohmann . 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"); - } - */ } diff --git a/test/src/unit-class_parser.cpp b/test/src/unit-class_parser.cpp index e4cfb536..6edb0a2e 100644 --- a/test/src/unit-class_parser.cpp +++ b/test/src/unit-class_parser.cpp @@ -5,6 +5,7 @@ |_____|_____|_____|_|___| https://github.com/nlohmann/json Licensed under the MIT License . +SPDX-License-Identifier: MIT Copyright (c) 2013-2018 Niels Lohmann . Permission is hereby granted, free of charge, to any person obtaining a copy diff --git a/test/src/unit-comparison.cpp b/test/src/unit-comparison.cpp index 0659c1db..da394407 100644 --- a/test/src/unit-comparison.cpp +++ b/test/src/unit-comparison.cpp @@ -5,6 +5,7 @@ |_____|_____|_____|_|___| https://github.com/nlohmann/json Licensed under the MIT License . +SPDX-License-Identifier: MIT Copyright (c) 2013-2018 Niels Lohmann . Permission is hereby granted, free of charge, to any person obtaining a copy diff --git a/test/src/unit-concepts.cpp b/test/src/unit-concepts.cpp index e2aac157..735ca0cb 100644 --- a/test/src/unit-concepts.cpp +++ b/test/src/unit-concepts.cpp @@ -5,6 +5,7 @@ |_____|_____|_____|_|___| https://github.com/nlohmann/json Licensed under the MIT License . +SPDX-License-Identifier: MIT Copyright (c) 2013-2018 Niels Lohmann . Permission is hereby granted, free of charge, to any person obtaining a copy diff --git a/test/src/unit-constructor1.cpp b/test/src/unit-constructor1.cpp index 35652bd8..bba24b71 100644 --- a/test/src/unit-constructor1.cpp +++ b/test/src/unit-constructor1.cpp @@ -5,6 +5,7 @@ |_____|_____|_____|_|___| https://github.com/nlohmann/json Licensed under the MIT License . +SPDX-License-Identifier: MIT Copyright (c) 2013-2018 Niels Lohmann . Permission is hereby granted, free of charge, to any person obtaining a copy diff --git a/test/src/unit-constructor2.cpp b/test/src/unit-constructor2.cpp index e36de923..120cb06b 100644 --- a/test/src/unit-constructor2.cpp +++ b/test/src/unit-constructor2.cpp @@ -5,6 +5,7 @@ |_____|_____|_____|_|___| https://github.com/nlohmann/json Licensed under the MIT License . +SPDX-License-Identifier: MIT Copyright (c) 2013-2018 Niels Lohmann . Permission is hereby granted, free of charge, to any person obtaining a copy diff --git a/test/src/unit-convenience.cpp b/test/src/unit-convenience.cpp index 15596032..6711fdd9 100644 --- a/test/src/unit-convenience.cpp +++ b/test/src/unit-convenience.cpp @@ -5,6 +5,7 @@ |_____|_____|_____|_|___| https://github.com/nlohmann/json Licensed under the MIT License . +SPDX-License-Identifier: MIT Copyright (c) 2013-2018 Niels Lohmann . Permission is hereby granted, free of charge, to any person obtaining a copy diff --git a/test/src/unit-conversions.cpp b/test/src/unit-conversions.cpp index d67f5acb..351dec8a 100644 --- a/test/src/unit-conversions.cpp +++ b/test/src/unit-conversions.cpp @@ -5,6 +5,7 @@ |_____|_____|_____|_|___| https://github.com/nlohmann/json Licensed under the MIT License . +SPDX-License-Identifier: MIT Copyright (c) 2013-2018 Niels Lohmann . Permission is hereby granted, free of charge, to any person obtaining a copy diff --git a/test/src/unit-deserialization.cpp b/test/src/unit-deserialization.cpp index d69c5983..09d5395a 100644 --- a/test/src/unit-deserialization.cpp +++ b/test/src/unit-deserialization.cpp @@ -5,6 +5,7 @@ |_____|_____|_____|_|___| https://github.com/nlohmann/json Licensed under the MIT License . +SPDX-License-Identifier: MIT Copyright (c) 2013-2018 Niels Lohmann . Permission is hereby granted, free of charge, to any person obtaining a copy diff --git a/test/src/unit-element_access1.cpp b/test/src/unit-element_access1.cpp index d06b97ca..af7818c4 100644 --- a/test/src/unit-element_access1.cpp +++ b/test/src/unit-element_access1.cpp @@ -5,6 +5,7 @@ |_____|_____|_____|_|___| https://github.com/nlohmann/json Licensed under the MIT License . +SPDX-License-Identifier: MIT Copyright (c) 2013-2018 Niels Lohmann . Permission is hereby granted, free of charge, to any person obtaining a copy diff --git a/test/src/unit-element_access2.cpp b/test/src/unit-element_access2.cpp index 5ea4b8a5..eb0d943f 100644 --- a/test/src/unit-element_access2.cpp +++ b/test/src/unit-element_access2.cpp @@ -5,6 +5,7 @@ |_____|_____|_____|_|___| https://github.com/nlohmann/json Licensed under the MIT License . +SPDX-License-Identifier: MIT Copyright (c) 2013-2018 Niels Lohmann . Permission is hereby granted, free of charge, to any person obtaining a copy diff --git a/test/src/unit-inspection.cpp b/test/src/unit-inspection.cpp index 111e6ea2..4c03cf96 100644 --- a/test/src/unit-inspection.cpp +++ b/test/src/unit-inspection.cpp @@ -5,6 +5,7 @@ |_____|_____|_____|_|___| https://github.com/nlohmann/json Licensed under the MIT License . +SPDX-License-Identifier: MIT Copyright (c) 2013-2018 Niels Lohmann . Permission is hereby granted, free of charge, to any person obtaining a copy diff --git a/test/src/unit-items.cpp b/test/src/unit-items.cpp index 8f18884d..579e1141 100644 --- a/test/src/unit-items.cpp +++ b/test/src/unit-items.cpp @@ -5,6 +5,7 @@ |_____|_____|_____|_|___| https://github.com/nlohmann/json Licensed under the MIT License . +SPDX-License-Identifier: MIT Copyright (c) 2013-2018 Niels Lohmann . Permission is hereby granted, free of charge, to any person obtaining a copy diff --git a/test/src/unit-iterators1.cpp b/test/src/unit-iterators1.cpp index c8125ce7..ef8d3185 100644 --- a/test/src/unit-iterators1.cpp +++ b/test/src/unit-iterators1.cpp @@ -5,6 +5,7 @@ |_____|_____|_____|_|___| https://github.com/nlohmann/json Licensed under the MIT License . +SPDX-License-Identifier: MIT Copyright (c) 2013-2018 Niels Lohmann . Permission is hereby granted, free of charge, to any person obtaining a copy diff --git a/test/src/unit-iterators2.cpp b/test/src/unit-iterators2.cpp index 2d369881..b3e1b820 100644 --- a/test/src/unit-iterators2.cpp +++ b/test/src/unit-iterators2.cpp @@ -5,6 +5,7 @@ |_____|_____|_____|_|___| https://github.com/nlohmann/json Licensed under the MIT License . +SPDX-License-Identifier: MIT Copyright (c) 2013-2018 Niels Lohmann . Permission is hereby granted, free of charge, to any person obtaining a copy diff --git a/test/src/unit-json_patch.cpp b/test/src/unit-json_patch.cpp index 1a71621d..d2079b4e 100644 --- a/test/src/unit-json_patch.cpp +++ b/test/src/unit-json_patch.cpp @@ -5,6 +5,7 @@ |_____|_____|_____|_|___| https://github.com/nlohmann/json Licensed under the MIT License . +SPDX-License-Identifier: MIT Copyright (c) 2013-2018 Niels Lohmann . Permission is hereby granted, free of charge, to any person obtaining a copy diff --git a/test/src/unit-json_pointer.cpp b/test/src/unit-json_pointer.cpp index c630da56..ec49e114 100644 --- a/test/src/unit-json_pointer.cpp +++ b/test/src/unit-json_pointer.cpp @@ -5,6 +5,7 @@ |_____|_____|_____|_|___| https://github.com/nlohmann/json Licensed under the MIT License . +SPDX-License-Identifier: MIT Copyright (c) 2013-2018 Niels Lohmann . Permission is hereby granted, free of charge, to any person obtaining a copy diff --git a/test/src/unit-merge_patch.cpp b/test/src/unit-merge_patch.cpp index 2daaf00f..7e36c432 100644 --- a/test/src/unit-merge_patch.cpp +++ b/test/src/unit-merge_patch.cpp @@ -5,6 +5,7 @@ |_____|_____|_____|_|___| https://github.com/nlohmann/json Licensed under the MIT License . +SPDX-License-Identifier: MIT Copyright (c) 2013-2018 Niels Lohmann . Permission is hereby granted, free of charge, to any person obtaining a copy diff --git a/test/src/unit-meta.cpp b/test/src/unit-meta.cpp index 6fc84998..db03453a 100644 --- a/test/src/unit-meta.cpp +++ b/test/src/unit-meta.cpp @@ -5,6 +5,7 @@ |_____|_____|_____|_|___| https://github.com/nlohmann/json Licensed under the MIT License . +SPDX-License-Identifier: MIT Copyright (c) 2013-2018 Niels Lohmann . Permission is hereby granted, free of charge, to any person obtaining a copy diff --git a/test/src/unit-modifiers.cpp b/test/src/unit-modifiers.cpp index ada65f20..1092dae3 100644 --- a/test/src/unit-modifiers.cpp +++ b/test/src/unit-modifiers.cpp @@ -5,6 +5,7 @@ |_____|_____|_____|_|___| https://github.com/nlohmann/json Licensed under the MIT License . +SPDX-License-Identifier: MIT Copyright (c) 2013-2018 Niels Lohmann . Permission is hereby granted, free of charge, to any person obtaining a copy diff --git a/test/src/unit-msgpack.cpp b/test/src/unit-msgpack.cpp index 7789ccb7..b10afbf4 100644 --- a/test/src/unit-msgpack.cpp +++ b/test/src/unit-msgpack.cpp @@ -5,6 +5,7 @@ |_____|_____|_____|_|___| https://github.com/nlohmann/json Licensed under the MIT License . +SPDX-License-Identifier: MIT Copyright (c) 2013-2018 Niels Lohmann . Permission is hereby granted, free of charge, to any person obtaining a copy diff --git a/test/src/unit-noexcept.cpp b/test/src/unit-noexcept.cpp index 4b3dcade..2d49b327 100644 --- a/test/src/unit-noexcept.cpp +++ b/test/src/unit-noexcept.cpp @@ -5,6 +5,7 @@ |_____|_____|_____|_|___| https://github.com/nlohmann/json Licensed under the MIT License . +SPDX-License-Identifier: MIT Copyright (c) 2013-2018 Niels Lohmann . Permission is hereby granted, free of charge, to any person obtaining a copy diff --git a/test/src/unit-pointer_access.cpp b/test/src/unit-pointer_access.cpp index 5670269a..fe56efbd 100644 --- a/test/src/unit-pointer_access.cpp +++ b/test/src/unit-pointer_access.cpp @@ -5,6 +5,7 @@ |_____|_____|_____|_|___| https://github.com/nlohmann/json Licensed under the MIT License . +SPDX-License-Identifier: MIT Copyright (c) 2013-2018 Niels Lohmann . Permission is hereby granted, free of charge, to any person obtaining a copy diff --git a/test/src/unit-readme.cpp b/test/src/unit-readme.cpp index 4c163afa..974adeaf 100644 --- a/test/src/unit-readme.cpp +++ b/test/src/unit-readme.cpp @@ -5,6 +5,7 @@ |_____|_____|_____|_|___| https://github.com/nlohmann/json Licensed under the MIT License . +SPDX-License-Identifier: MIT Copyright (c) 2013-2018 Niels Lohmann . Permission is hereby granted, free of charge, to any person obtaining a copy diff --git a/test/src/unit-reference_access.cpp b/test/src/unit-reference_access.cpp index 3c92096f..43a096a7 100644 --- a/test/src/unit-reference_access.cpp +++ b/test/src/unit-reference_access.cpp @@ -5,6 +5,7 @@ |_____|_____|_____|_|___| https://github.com/nlohmann/json Licensed under the MIT License . +SPDX-License-Identifier: MIT Copyright (c) 2013-2018 Niels Lohmann . Permission is hereby granted, free of charge, to any person obtaining a copy diff --git a/test/src/unit-regression.cpp b/test/src/unit-regression.cpp index 01e68957..8bdd2dc3 100644 --- a/test/src/unit-regression.cpp +++ b/test/src/unit-regression.cpp @@ -5,6 +5,7 @@ |_____|_____|_____|_|___| https://github.com/nlohmann/json Licensed under the MIT License . +SPDX-License-Identifier: MIT Copyright (c) 2013-2018 Niels Lohmann . 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 vec1 = {0xf9, 0xff, 0xff, 0x4a, 0x3a, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x01, 0x37, 0x02, 0x38}; diff --git a/test/src/unit-serialization.cpp b/test/src/unit-serialization.cpp index ebe64297..3abc7fb1 100644 --- a/test/src/unit-serialization.cpp +++ b/test/src/unit-serialization.cpp @@ -5,6 +5,7 @@ |_____|_____|_____|_|___| https://github.com/nlohmann/json Licensed under the MIT License . +SPDX-License-Identifier: MIT Copyright (c) 2013-2018 Niels Lohmann . Permission is hereby granted, free of charge, to any person obtaining a copy diff --git a/test/src/unit-testsuites.cpp b/test/src/unit-testsuites.cpp index 5f77a737..a668abd5 100644 --- a/test/src/unit-testsuites.cpp +++ b/test/src/unit-testsuites.cpp @@ -5,6 +5,7 @@ |_____|_____|_____|_|___| https://github.com/nlohmann/json Licensed under the MIT License . +SPDX-License-Identifier: MIT Copyright (c) 2013-2018 Niels Lohmann . Permission is hereby granted, free of charge, to any person obtaining a copy diff --git a/test/src/unit-to_chars.cpp b/test/src/unit-to_chars.cpp index 841e164b..fc86f30f 100644 --- a/test/src/unit-to_chars.cpp +++ b/test/src/unit-to_chars.cpp @@ -5,6 +5,7 @@ |_____|_____|_____|_|___| https://github.com/nlohmann/json Licensed under the MIT License . +SPDX-License-Identifier: MIT Copyright (c) 2013-2018 Niels Lohmann . Permission is hereby granted, free of charge, to any person obtaining a copy diff --git a/test/src/unit-ubjson.cpp b/test/src/unit-ubjson.cpp index 791668ff..0e15c164 100644 --- a/test/src/unit-ubjson.cpp +++ b/test/src/unit-ubjson.cpp @@ -5,6 +5,7 @@ |_____|_____|_____|_|___| https://github.com/nlohmann/json Licensed under the MIT License . +SPDX-License-Identifier: MIT Copyright (c) 2013-2018 Niels Lohmann . 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 packed((std::istreambuf_iterator(f_ubjson)), - std::istreambuf_iterator()); - 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") - { - // parse UBJSON file - std::ifstream f_ubjson(filename + ".ubj", std::ios::binary); - std::vector packed( - (std::istreambuf_iterator(f_ubjson)), - std::istreambuf_iterator()); - 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 packed( - (std::istreambuf_iterator(f_ubjson)), - std::istreambuf_iterator()); - 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") - { - // parse UBJSON file - std::ifstream f_ubjson(prefix + ".ubj", std::ios::binary); - std::vector packed( - (std::istreambuf_iterator(f_ubjson)), - std::istreambuf_iterator()); - 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 diff --git a/test/src/unit-udt.cpp b/test/src/unit-udt.cpp index 9cfc6e97..040c3e98 100644 --- a/test/src/unit-udt.cpp +++ b/test/src/unit-udt.cpp @@ -5,6 +5,7 @@ |_____|_____|_____|_|___| https://github.com/nlohmann/json Licensed under the MIT License . +SPDX-License-Identifier: MIT Copyright (c) 2013-2018 Niels Lohmann . Permission is hereby granted, free of charge, to any person obtaining a copy diff --git a/test/src/unit-unicode.cpp b/test/src/unit-unicode.cpp index 95925dee..568d1d7c 100644 --- a/test/src/unit-unicode.cpp +++ b/test/src/unit-unicode.cpp @@ -5,6 +5,7 @@ |_____|_____|_____|_|___| https://github.com/nlohmann/json Licensed under the MIT License . +SPDX-License-Identifier: MIT Copyright (c) 2013-2018 Niels Lohmann . Permission is hereby granted, free of charge, to any person obtaining a copy diff --git a/test/src/unit-wstring.cpp b/test/src/unit-wstring.cpp new file mode 100644 index 00000000..a1f4e545 --- /dev/null +++ b/test/src/unit-wstring.cpp @@ -0,0 +1,112 @@ +/* + __ _____ _____ _____ + __| | __| | | | JSON for Modern C++ (test suite) +| | |__ | | | | | | version 3.1.2 +|_____|_____|_____|_|___| https://github.com/nlohmann/json + +Licensed under the MIT License . +SPDX-License-Identifier: MIT +Copyright (c) 2013-2018 Niels Lohmann . + +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 + +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&); + } + } +} diff --git a/test/src/unit.cpp b/test/src/unit.cpp index 95659955..6380265b 100644 --- a/test/src/unit.cpp +++ b/test/src/unit.cpp @@ -5,6 +5,7 @@ |_____|_____|_____|_|___| https://github.com/nlohmann/json Licensed under the MIT License . +SPDX-License-Identifier: MIT Copyright (c) 2013-2018 Niels Lohmann . Permission is hereby granted, free of charge, to any person obtaining a copy