diff --git a/CMakeLists.txt b/CMakeLists.txt index 2c2612a7..b35b50ea 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,7 +1,7 @@ cmake_minimum_required(VERSION 3.0) # define the project -project(nlohmann_json VERSION 2.0.5 LANGUAGES CXX) +project(nlohmann_json VERSION 2.0.6 LANGUAGES CXX) enable_testing() @@ -31,7 +31,8 @@ endif() include(CMakePackageConfigHelpers) configure_package_config_file("cmake/config.cmake.in" "${CMAKE_CURRENT_BINARY_DIR}/${JSON_CONFIG_FILENAME}" - INSTALL_DESTINATION ${JSON_CONFIG_DESTINATION}) + INSTALL_DESTINATION ${JSON_CONFIG_DESTINATION} + PATH_VARS JSON_INCLUDE_DESTINATION) write_basic_package_version_file("${CMAKE_CURRENT_BINARY_DIR}/${JSON_CONFIGVERSION_FILENAME}" VERSION ${PROJECT_VERSION} COMPATIBILITY SameMajorVersion) diff --git a/ChangeLog.md b/ChangeLog.md index 041d3839..cfe72666 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -1,13 +1,24 @@ # Change Log All notable changes to this project will be documented in this file. This project adheres to [Semantic Versioning](http://semver.org/). +## [v2.0.6](https://github.com/nlohmann/json/releases/tag/v2.0.6) (2016-10-15) +[Full Changelog](https://github.com/nlohmann/json/compare/v2.0.5...v2.0.6) + +- Add nested object capability to pointers [\#323](https://github.com/nlohmann/json/issues/323) +- make has\_mapped\_type struct friendly [\#324](https://github.com/nlohmann/json/pull/324) ([vpetrigo](https://github.com/vpetrigo)) + +- Fix usage examples' comments for std::multiset [\#322](https://github.com/nlohmann/json/issues/322) +- json\_unit runs forever when executed in build directory [\#319](https://github.com/nlohmann/json/issues/319) + +- Fix usage examples' comments for std::multiset [\#321](https://github.com/nlohmann/json/pull/321) ([vasild](https://github.com/vasild)) +- Include dir relocation [\#318](https://github.com/nlohmann/json/pull/318) ([ChristophJud](https://github.com/ChristophJud)) +- trivial documentation fix [\#313](https://github.com/nlohmann/json/pull/313) ([5tefan](https://github.com/5tefan)) + ## [v2.0.5](https://github.com/nlohmann/json/releases/tag/v2.0.5) (2016-09-14) [Full Changelog](https://github.com/nlohmann/json/compare/v2.0.4...v2.0.5) - make json\_benchmarks no longer working in 2.0.4 [\#310](https://github.com/nlohmann/json/issues/310) -- \[feature request\]: schema validator and comments [\#311](https://github.com/nlohmann/json/issues/311) - ## [v2.0.4](https://github.com/nlohmann/json/releases/tag/v2.0.4) (2016-09-11) [Full Changelog](https://github.com/nlohmann/json/compare/v2.0.3...v2.0.4) diff --git a/README.md b/README.md index 5f434e7c..aa698c76 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ [![Build Status](https://travis-ci.org/nlohmann/json.svg?branch=master)](https://travis-ci.org/nlohmann/json) [![Build Status](https://ci.appveyor.com/api/projects/status/1acb366xfyg3qybk/branch/develop?svg=true)](https://ci.appveyor.com/project/nlohmann/json) [![Coverage Status](https://img.shields.io/coveralls/nlohmann/json.svg)](https://coveralls.io/r/nlohmann/json) -[![Try online](https://img.shields.io/badge/try-online-blue.svg)](http://melpon.org/wandbox/permlink/r3wa3rI5yxgQQcrm) +[![Try online](https://img.shields.io/badge/try-online-blue.svg)](http://melpon.org/wandbox/permlink/3BIhBw91FUVuHE1D) [![Documentation](https://img.shields.io/badge/docs-doxygen-blue.svg)](http://nlohmann.github.io/json) [![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg)](https://raw.githubusercontent.com/nlohmann/json/master/LICENSE.MIT) [![Github Releases](https://img.shields.io/github/release/nlohmann/json.svg)](https://github.com/nlohmann/json/releases) @@ -283,8 +283,8 @@ json j_uset(c_uset); // only one entry for "one" is used // maybe ["two", "three", "four", "one"] std::multiset c_mset {"one", "two", "one", "four"}; -json j_mset(c_mset); // only one entry for "one" is used -// maybe ["one", "two", "four"] +json j_mset(c_mset); // both entries for "one" are used +// maybe ["one", "two", "one", "four"] std::unordered_multiset c_umset {"one", "two", "one", "four"}; json j_umset(c_umset); // both entries for "one" are used @@ -494,6 +494,10 @@ I deeply appreciate the help of the following people. - [Damien](https://github.com/dtoma) fixed one of the last conversion warnings. - [Thomas Braun](https://github.com/t-b) fixed a warning in a test case. - [Théo DELRIEU](https://github.com/theodelrieu) patiently and constructively oversaw the long way toward [iterator-range parsing](https://github.com/nlohmann/json/issues/290). +- [Stefan](https://github.com/5tefan) fixed a minor issue in the documentation. +- [Vasil Dimov](https://github.com/vasild) fixed the documentation regarding conversions from `std::multiset`. +- [ChristophJud](https://github.com/ChristophJud) overworked the CMake files to ease project inclusion. +- [Vladimir Petrigo](https://github.com/vpetrigo) made a SFINAE hack more readable. Thanks a lot for helping out! @@ -512,7 +516,17 @@ To compile and run the tests, you need to execute $ make check =============================================================================== -All tests passed (8905161 assertions in 35 test cases) +All tests passed (8905168 assertions in 35 test cases) +``` + +Alternatively, you can use [https://cmake.org](CMake) and run + +```sh +$ mkdir build +$ cd build +$ cmake .. +$ make +$ ctest ``` For more information, have a look at the file [.travis.yml](https://github.com/nlohmann/json/blob/master/.travis.yml). diff --git a/cmake/config.cmake.in b/cmake/config.cmake.in index 3ff97add..a1e9488d 100644 --- a/cmake/config.cmake.in +++ b/cmake/config.cmake.in @@ -1,6 +1,7 @@ @PACKAGE_INIT@ +set_and_check(JSON_INCLUDE_DIR "@PACKAGE_JSON_INCLUDE_DESTINATION@") cmake_policy(PUSH) cmake_policy(SET CMP0024 OLD) include(${CMAKE_CURRENT_LIST_DIR}/@JSON_TARGETS_FILENAME@) -cmake_policy(POP) \ No newline at end of file +cmake_policy(POP) diff --git a/doc/Doxyfile b/doc/Doxyfile index 3d96c417..ce1134ea 100644 --- a/doc/Doxyfile +++ b/doc/Doxyfile @@ -5,7 +5,7 @@ #--------------------------------------------------------------------------- DOXYFILE_ENCODING = UTF-8 PROJECT_NAME = "JSON for Modern C++" -PROJECT_NUMBER = 2.0.5 +PROJECT_NUMBER = 2.0.6 PROJECT_BRIEF = PROJECT_LOGO = OUTPUT_DIRECTORY = . diff --git a/doc/examples/README.link b/doc/examples/README.link index 10c8ad40..ac4a894d 100644 --- a/doc/examples/README.link +++ b/doc/examples/README.link @@ -1 +1 @@ -online \ No newline at end of file +online \ No newline at end of file diff --git a/doc/examples/basic_json__CompatibleArrayType.cpp b/doc/examples/basic_json__CompatibleArrayType.cpp index bbbf5970..26a1a101 100644 --- a/doc/examples/basic_json__CompatibleArrayType.cpp +++ b/doc/examples/basic_json__CompatibleArrayType.cpp @@ -39,7 +39,7 @@ int main() // create an array from std::multiset std::multiset c_mset {"one", "two", "one", "four"}; - json j_mset(c_mset); // only one entry for "one" is used + json j_mset(c_mset); // both entries for "one" are used // create an array from std::unordered_multiset std::unordered_multiset c_umset {"one", "two", "one", "four"}; diff --git a/doc/examples/basic_json__CompatibleArrayType.link b/doc/examples/basic_json__CompatibleArrayType.link index 85f64862..95ecb050 100644 --- a/doc/examples/basic_json__CompatibleArrayType.link +++ b/doc/examples/basic_json__CompatibleArrayType.link @@ -1 +1 @@ -online \ No newline at end of file +online \ No newline at end of file diff --git a/doc/examples/operatorjson_pointer.cpp b/doc/examples/operatorjson_pointer.cpp index 18e41c1f..d7e8faff 100644 --- a/doc/examples/operatorjson_pointer.cpp +++ b/doc/examples/operatorjson_pointer.cpp @@ -40,7 +40,7 @@ int main() // output the changed array std::cout << j["array"] << '\n'; - // "change" the arry element past the end + // "change" the array element past the end j["/array/-"_json_pointer] = 55; // output the changed array std::cout << j["array"] << '\n'; diff --git a/doc/examples/operatorjson_pointer.link b/doc/examples/operatorjson_pointer.link index 3a60e8a6..debbdedb 100644 --- a/doc/examples/operatorjson_pointer.link +++ b/doc/examples/operatorjson_pointer.link @@ -1 +1 @@ -online \ No newline at end of file +online \ No newline at end of file diff --git a/doc/index.md b/doc/index.md index be845e0f..53465552 100644 --- a/doc/index.md +++ b/doc/index.md @@ -268,4 +268,4 @@ The container functions known from STL have been extended to support the differe @author [Niels Lohmann](http://nlohmann.me) @see https://github.com/nlohmann/json to download the source code -@version 2.0.5 +@version 2.0.6 diff --git a/doc/json.gif b/doc/json.gif index f49cf02f..2770cfb3 100644 Binary files a/doc/json.gif and b/doc/json.gif differ diff --git a/src/json.hpp b/src/json.hpp index 8469a499..9c0df9d4 100644 --- a/src/json.hpp +++ b/src/json.hpp @@ -1,7 +1,7 @@ /* __ _____ _____ _____ __| | __| | | | JSON for Modern C++ -| | |__ | | | | | | version 2.0.5 +| | |__ | | | | | | version 2.0.6 |_____|_____|_____|_|___| https://github.com/nlohmann/json Licensed under the MIT License . @@ -32,6 +32,7 @@ SOFTWARE. #include #include #include +#include #include #include #include @@ -106,16 +107,19 @@ such as sequence containers. For instance, `std::map` passes the test as it contains a `mapped_type`, whereas `std::vector` fails the test. @sa http://stackoverflow.com/a/7728728/266378 -@since version 1.0.0 +@since version 1.0.0, overworked in version 2.0.6 */ template struct has_mapped_type { private: - template static char test(typename C::mapped_type*); - template static char (&test(...))[2]; + template + static int detect(U&&); + + static void detect(...); public: - static constexpr bool value = sizeof(test(0)) == 1; + static constexpr bool value = + std::is_integral()))>::value; }; /*! @@ -9436,6 +9440,12 @@ basic_json_parser_63: /*! @brief return a reference to the pointed to value + @note This version does not throw if a value is not present, but tries + to create nested values instead. For instance, calling this function + with pointer `"/this/that"` on a null value is equivalent to calling + `operator[]("this").operator[]("that")` on that value, effectively + changing the null value to an object. + @param[in] ptr a JSON value @return reference to the JSON value pointed to by the JSON pointer @@ -9450,6 +9460,29 @@ basic_json_parser_63: { for (const auto& reference_token : reference_tokens) { + // convert null values to arrays or objects before continuing + if (ptr->m_type == value_t::null) + { + // check if reference token is a number + const bool nums = std::all_of(reference_token.begin(), + reference_token.end(), + [](const char x) + { + return std::isdigit(x); + }); + + // change value to array for numbers or "-" or to object + // otherwise + if (nums or reference_token == "-") + { + *ptr = value_t::array; + } + else + { + *ptr = value_t::object; + } + } + switch (ptr->m_type) { case value_t::object: @@ -10570,7 +10603,7 @@ inline nlohmann::json operator "" _json(const char* s, std::size_t) @brief user-defined string literal for JSON pointer This operator implements a user-defined string literal for JSON Pointers. It -can be used by adding `"_json"` to a string literal and returns a JSON pointer +can be used by adding `"_json_pointer"` to a string literal and returns a JSON pointer object if no parse error occurred. @param[in] s a string representation of a JSON Pointer diff --git a/src/json.hpp.re2c b/src/json.hpp.re2c index 892c48a4..656e13b3 100644 --- a/src/json.hpp.re2c +++ b/src/json.hpp.re2c @@ -1,7 +1,7 @@ /* __ _____ _____ _____ __| | __| | | | JSON for Modern C++ -| | |__ | | | | | | version 2.0.5 +| | |__ | | | | | | version 2.0.6 |_____|_____|_____|_|___| https://github.com/nlohmann/json Licensed under the MIT License . @@ -32,6 +32,7 @@ SOFTWARE. #include #include #include +#include #include #include #include @@ -106,16 +107,19 @@ such as sequence containers. For instance, `std::map` passes the test as it contains a `mapped_type`, whereas `std::vector` fails the test. @sa http://stackoverflow.com/a/7728728/266378 -@since version 1.0.0 +@since version 1.0.0, overworked in version 2.0.6 */ template struct has_mapped_type { private: - template static char test(typename C::mapped_type*); - template static char (&test(...))[2]; + template + static int detect(U&&); + + static void detect(...); public: - static constexpr bool value = sizeof(test(0)) == 1; + static constexpr bool value = + std::is_integral()))>::value; }; /*! @@ -8733,6 +8737,12 @@ class basic_json /*! @brief return a reference to the pointed to value + @note This version does not throw if a value is not present, but tries + to create nested values instead. For instance, calling this function + with pointer `"/this/that"` on a null value is equivalent to calling + `operator[]("this").operator[]("that")` on that value, effectively + changing the null value to an object. + @param[in] ptr a JSON value @return reference to the JSON value pointed to by the JSON pointer @@ -8747,6 +8757,29 @@ class basic_json { for (const auto& reference_token : reference_tokens) { + // convert null values to arrays or objects before continuing + if (ptr->m_type == value_t::null) + { + // check if reference token is a number + const bool nums = std::all_of(reference_token.begin(), + reference_token.end(), + [](const char x) + { + return std::isdigit(x); + }); + + // change value to array for numbers or "-" or to object + // otherwise + if (nums or reference_token == "-") + { + *ptr = value_t::array; + } + else + { + *ptr = value_t::object; + } + } + switch (ptr->m_type) { case value_t::object: @@ -9867,7 +9900,7 @@ inline nlohmann::json operator "" _json(const char* s, std::size_t) @brief user-defined string literal for JSON pointer This operator implements a user-defined string literal for JSON Pointers. It -can be used by adding `"_json"` to a string literal and returns a JSON pointer +can be used by adding `"_json_pointer"` to a string literal and returns a JSON pointer object if no parse error occurred. @param[in] s a string representation of a JSON Pointer diff --git a/test/reports/2016-10-02-fuzz/exec_speed.png b/test/reports/2016-10-02-fuzz/exec_speed.png new file mode 100644 index 00000000..16515e8b Binary files /dev/null and b/test/reports/2016-10-02-fuzz/exec_speed.png differ diff --git a/test/reports/2016-10-02-fuzz/fuzz.tiff b/test/reports/2016-10-02-fuzz/fuzz.tiff new file mode 100644 index 00000000..eba3db5d Binary files /dev/null and b/test/reports/2016-10-02-fuzz/fuzz.tiff differ diff --git a/test/reports/2016-10-02-fuzz/high_freq.png b/test/reports/2016-10-02-fuzz/high_freq.png new file mode 100644 index 00000000..90b763b8 Binary files /dev/null and b/test/reports/2016-10-02-fuzz/high_freq.png differ diff --git a/test/reports/2016-10-02-fuzz/index.html b/test/reports/2016-10-02-fuzz/index.html new file mode 100644 index 00000000..d792a092 --- /dev/null +++ b/test/reports/2016-10-02-fuzz/index.html @@ -0,0 +1,10 @@ + + + + +
Banner:fuzz
Directory:fuzz-testing/out
Generated on:Sun Oct 2 08:51:02 CEST 2016
+

+

+

+ + diff --git a/test/reports/2016-10-02-fuzz/low_freq.png b/test/reports/2016-10-02-fuzz/low_freq.png new file mode 100644 index 00000000..fb460640 Binary files /dev/null and b/test/reports/2016-10-02-fuzz/low_freq.png differ diff --git a/test/src/fuzz.cpp b/test/src/fuzz.cpp index b93ea0ee..23c0d418 100644 --- a/test/src/fuzz.cpp +++ b/test/src/fuzz.cpp @@ -1,7 +1,7 @@ /* __ _____ _____ _____ __| | __| | | | JSON for Modern C++ (fuzz test support) -| | |__ | | | | | | version 2.0.5 +| | |__ | | | | | | version 2.0.6 |_____|_____|_____|_|___| https://github.com/nlohmann/json Run "make fuzz_testing" and follow the instructions. diff --git a/test/src/unit-algorithms.cpp b/test/src/unit-algorithms.cpp index 9f9c3861..f779ea76 100644 --- a/test/src/unit-algorithms.cpp +++ b/test/src/unit-algorithms.cpp @@ -1,7 +1,7 @@ /* __ _____ _____ _____ __| | __| | | | JSON for Modern C++ (test suite) -| | |__ | | | | | | version 2.0.5 +| | |__ | | | | | | version 2.0.6 |_____|_____|_____|_|___| https://github.com/nlohmann/json Licensed under the MIT License . diff --git a/test/src/unit-allocator.cpp b/test/src/unit-allocator.cpp index 0d6c7e34..49189c0c 100644 --- a/test/src/unit-allocator.cpp +++ b/test/src/unit-allocator.cpp @@ -1,7 +1,7 @@ /* __ _____ _____ _____ __| | __| | | | JSON for Modern C++ (test suite) -| | |__ | | | | | | version 2.0.5 +| | |__ | | | | | | version 2.0.6 |_____|_____|_____|_|___| https://github.com/nlohmann/json Licensed under the MIT License . diff --git a/test/src/unit-capacity.cpp b/test/src/unit-capacity.cpp index 1ed3c5c3..1378304f 100644 --- a/test/src/unit-capacity.cpp +++ b/test/src/unit-capacity.cpp @@ -1,7 +1,7 @@ /* __ _____ _____ _____ __| | __| | | | JSON for Modern C++ (test suite) -| | |__ | | | | | | version 2.0.5 +| | |__ | | | | | | version 2.0.6 |_____|_____|_____|_|___| https://github.com/nlohmann/json Licensed under the MIT License . diff --git a/test/src/unit-class_const_iterator.cpp b/test/src/unit-class_const_iterator.cpp index 021b757f..fa0fee50 100644 --- a/test/src/unit-class_const_iterator.cpp +++ b/test/src/unit-class_const_iterator.cpp @@ -1,7 +1,7 @@ /* __ _____ _____ _____ __| | __| | | | JSON for Modern C++ (test suite) -| | |__ | | | | | | version 2.0.5 +| | |__ | | | | | | version 2.0.6 |_____|_____|_____|_|___| https://github.com/nlohmann/json Licensed under the MIT License . diff --git a/test/src/unit-class_iterator.cpp b/test/src/unit-class_iterator.cpp index 03fa2d8f..1706120f 100644 --- a/test/src/unit-class_iterator.cpp +++ b/test/src/unit-class_iterator.cpp @@ -1,7 +1,7 @@ /* __ _____ _____ _____ __| | __| | | | JSON for Modern C++ (test suite) -| | |__ | | | | | | version 2.0.5 +| | |__ | | | | | | version 2.0.6 |_____|_____|_____|_|___| https://github.com/nlohmann/json Licensed under the MIT License . diff --git a/test/src/unit-class_lexer.cpp b/test/src/unit-class_lexer.cpp index 5565f5ef..b2c951b1 100644 --- a/test/src/unit-class_lexer.cpp +++ b/test/src/unit-class_lexer.cpp @@ -1,7 +1,7 @@ /* __ _____ _____ _____ __| | __| | | | JSON for Modern C++ (test suite) -| | |__ | | | | | | version 2.0.5 +| | |__ | | | | | | version 2.0.6 |_____|_____|_____|_|___| https://github.com/nlohmann/json Licensed under the MIT License . diff --git a/test/src/unit-class_parser.cpp b/test/src/unit-class_parser.cpp index 2762a27f..5925d628 100644 --- a/test/src/unit-class_parser.cpp +++ b/test/src/unit-class_parser.cpp @@ -1,7 +1,7 @@ /* __ _____ _____ _____ __| | __| | | | JSON for Modern C++ (test suite) -| | |__ | | | | | | version 2.0.5 +| | |__ | | | | | | version 2.0.6 |_____|_____|_____|_|___| https://github.com/nlohmann/json Licensed under the MIT License . diff --git a/test/src/unit-comparison.cpp b/test/src/unit-comparison.cpp index 650fca0d..13287fa2 100644 --- a/test/src/unit-comparison.cpp +++ b/test/src/unit-comparison.cpp @@ -1,7 +1,7 @@ /* __ _____ _____ _____ __| | __| | | | JSON for Modern C++ (test suite) -| | |__ | | | | | | version 2.0.5 +| | |__ | | | | | | version 2.0.6 |_____|_____|_____|_|___| https://github.com/nlohmann/json Licensed under the MIT License . diff --git a/test/src/unit-concepts.cpp b/test/src/unit-concepts.cpp index 7b18fa8e..0897b503 100644 --- a/test/src/unit-concepts.cpp +++ b/test/src/unit-concepts.cpp @@ -1,7 +1,7 @@ /* __ _____ _____ _____ __| | __| | | | JSON for Modern C++ (test suite) -| | |__ | | | | | | version 2.0.5 +| | |__ | | | | | | version 2.0.6 |_____|_____|_____|_|___| https://github.com/nlohmann/json Licensed under the MIT License . diff --git a/test/src/unit-constructor1.cpp b/test/src/unit-constructor1.cpp index 62cceba5..469d21d0 100644 --- a/test/src/unit-constructor1.cpp +++ b/test/src/unit-constructor1.cpp @@ -1,7 +1,7 @@ /* __ _____ _____ _____ __| | __| | | | JSON for Modern C++ (test suite) -| | |__ | | | | | | version 2.0.5 +| | |__ | | | | | | version 2.0.6 |_____|_____|_____|_|___| https://github.com/nlohmann/json Licensed under the MIT License . diff --git a/test/src/unit-constructor2.cpp b/test/src/unit-constructor2.cpp index d2d7f557..3a2cd80c 100644 --- a/test/src/unit-constructor2.cpp +++ b/test/src/unit-constructor2.cpp @@ -1,7 +1,7 @@ /* __ _____ _____ _____ __| | __| | | | JSON for Modern C++ (test suite) -| | |__ | | | | | | version 2.0.5 +| | |__ | | | | | | version 2.0.6 |_____|_____|_____|_|___| https://github.com/nlohmann/json Licensed under the MIT License . diff --git a/test/src/unit-convenience.cpp b/test/src/unit-convenience.cpp index 5bd7f6bf..7bc41f39 100644 --- a/test/src/unit-convenience.cpp +++ b/test/src/unit-convenience.cpp @@ -1,7 +1,7 @@ /* __ _____ _____ _____ __| | __| | | | JSON for Modern C++ (test suite) -| | |__ | | | | | | version 2.0.5 +| | |__ | | | | | | version 2.0.6 |_____|_____|_____|_|___| https://github.com/nlohmann/json Licensed under the MIT License . diff --git a/test/src/unit-conversions.cpp b/test/src/unit-conversions.cpp index 83488af2..c8fe6cc6 100644 --- a/test/src/unit-conversions.cpp +++ b/test/src/unit-conversions.cpp @@ -1,7 +1,7 @@ /* __ _____ _____ _____ __| | __| | | | JSON for Modern C++ (test suite) -| | |__ | | | | | | version 2.0.5 +| | |__ | | | | | | version 2.0.6 |_____|_____|_____|_|___| https://github.com/nlohmann/json Licensed under the MIT License . diff --git a/test/src/unit-deserialization.cpp b/test/src/unit-deserialization.cpp index 672f15df..c31cb8c8 100644 --- a/test/src/unit-deserialization.cpp +++ b/test/src/unit-deserialization.cpp @@ -1,7 +1,7 @@ /* __ _____ _____ _____ __| | __| | | | JSON for Modern C++ (test suite) -| | |__ | | | | | | version 2.0.5 +| | |__ | | | | | | version 2.0.6 |_____|_____|_____|_|___| https://github.com/nlohmann/json Licensed under the MIT License . @@ -238,6 +238,18 @@ TEST_CASE("deserialization") uint8_t v[] = {'\"', 'a', 'a', 'a', 'a', 'a', 'a', '\\', 'u', '1'}; CHECK_THROWS_AS(json::parse(std::begin(v), std::end(v)), std::invalid_argument); } + + 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)), std::invalid_argument); + } + + 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)), std::invalid_argument); + } } } } diff --git a/test/src/unit-element_access1.cpp b/test/src/unit-element_access1.cpp index b5b3b343..2ee28150 100644 --- a/test/src/unit-element_access1.cpp +++ b/test/src/unit-element_access1.cpp @@ -1,7 +1,7 @@ /* __ _____ _____ _____ __| | __| | | | JSON for Modern C++ (test suite) -| | |__ | | | | | | version 2.0.5 +| | |__ | | | | | | version 2.0.6 |_____|_____|_____|_|___| https://github.com/nlohmann/json Licensed under the MIT License . diff --git a/test/src/unit-element_access2.cpp b/test/src/unit-element_access2.cpp index 2831b961..cd85fc3b 100644 --- a/test/src/unit-element_access2.cpp +++ b/test/src/unit-element_access2.cpp @@ -1,7 +1,7 @@ /* __ _____ _____ _____ __| | __| | | | JSON for Modern C++ (test suite) -| | |__ | | | | | | version 2.0.5 +| | |__ | | | | | | version 2.0.6 |_____|_____|_____|_|___| https://github.com/nlohmann/json Licensed under the MIT License . diff --git a/test/src/unit-inspection.cpp b/test/src/unit-inspection.cpp index aa3f9f02..63b32ad3 100644 --- a/test/src/unit-inspection.cpp +++ b/test/src/unit-inspection.cpp @@ -1,7 +1,7 @@ /* __ _____ _____ _____ __| | __| | | | JSON for Modern C++ (test suite) -| | |__ | | | | | | version 2.0.5 +| | |__ | | | | | | version 2.0.6 |_____|_____|_____|_|___| https://github.com/nlohmann/json Licensed under the MIT License . diff --git a/test/src/unit-iterator_wrapper.cpp b/test/src/unit-iterator_wrapper.cpp index 534d2732..aa357fe1 100644 --- a/test/src/unit-iterator_wrapper.cpp +++ b/test/src/unit-iterator_wrapper.cpp @@ -1,7 +1,7 @@ /* __ _____ _____ _____ __| | __| | | | JSON for Modern C++ (test suite) -| | |__ | | | | | | version 2.0.5 +| | |__ | | | | | | version 2.0.6 |_____|_____|_____|_|___| https://github.com/nlohmann/json Licensed under the MIT License . diff --git a/test/src/unit-iterators1.cpp b/test/src/unit-iterators1.cpp index 89aa4a32..482d33e9 100644 --- a/test/src/unit-iterators1.cpp +++ b/test/src/unit-iterators1.cpp @@ -1,7 +1,7 @@ /* __ _____ _____ _____ __| | __| | | | JSON for Modern C++ (test suite) -| | |__ | | | | | | version 2.0.5 +| | |__ | | | | | | version 2.0.6 |_____|_____|_____|_|___| https://github.com/nlohmann/json Licensed under the MIT License . diff --git a/test/src/unit-iterators2.cpp b/test/src/unit-iterators2.cpp index 3e61debb..d80181ce 100644 --- a/test/src/unit-iterators2.cpp +++ b/test/src/unit-iterators2.cpp @@ -1,7 +1,7 @@ /* __ _____ _____ _____ __| | __| | | | JSON for Modern C++ (test suite) -| | |__ | | | | | | version 2.0.5 +| | |__ | | | | | | version 2.0.6 |_____|_____|_____|_|___| https://github.com/nlohmann/json Licensed under the MIT License . diff --git a/test/src/unit-json_patch.cpp b/test/src/unit-json_patch.cpp index b0e72e10..b3565684 100644 --- a/test/src/unit-json_patch.cpp +++ b/test/src/unit-json_patch.cpp @@ -1,7 +1,7 @@ /* __ _____ _____ _____ __| | __| | | | JSON for Modern C++ (test suite) -| | |__ | | | | | | version 2.0.5 +| | |__ | | | | | | version 2.0.6 |_____|_____|_____|_|___| https://github.com/nlohmann/json Licensed under the MIT License . diff --git a/test/src/unit-json_pointer.cpp b/test/src/unit-json_pointer.cpp index c7f1708c..c2ba2bae 100644 --- a/test/src/unit-json_pointer.cpp +++ b/test/src/unit-json_pointer.cpp @@ -1,7 +1,7 @@ /* __ _____ _____ _____ __| | __| | | | JSON for Modern C++ (test suite) -| | |__ | | | | | | version 2.0.5 +| | |__ | | | | | | version 2.0.6 |_____|_____|_____|_|___| https://github.com/nlohmann/json Licensed under the MIT License . @@ -109,8 +109,13 @@ TEST_CASE("JSON pointers") CHECK(j[json::json_pointer("/m~0n")] == j["m~n"]); // unescaped access - CHECK_THROWS_AS(j[json::json_pointer("/a/b")], std::out_of_range); - CHECK_THROWS_WITH(j[json::json_pointer("/a/b")], "unresolved reference token 'b'"); + // access to nonexisting values yield object creation + CHECK_NOTHROW(j[json::json_pointer("/a/b")] = 42); + CHECK(j["a"]["b"] == json(42)); + CHECK_NOTHROW(j[json::json_pointer("/a/c/1")] = 42); + CHECK(j["a"]["c"] == json({nullptr, 42})); + CHECK_NOTHROW(j[json::json_pointer("/a/d/-")] = 42); + CHECK(j["a"]["d"] == json::array({42})); // "/a/b" works for JSON {"a": {"b": 42}} CHECK(json({{"a", {{"b", 42}}}})[json::json_pointer("/a/b")] == json(42)); diff --git a/test/src/unit-modifiers.cpp b/test/src/unit-modifiers.cpp index 590505f4..7ac83967 100644 --- a/test/src/unit-modifiers.cpp +++ b/test/src/unit-modifiers.cpp @@ -1,7 +1,7 @@ /* __ _____ _____ _____ __| | __| | | | JSON for Modern C++ (test suite) -| | |__ | | | | | | version 2.0.5 +| | |__ | | | | | | version 2.0.6 |_____|_____|_____|_|___| https://github.com/nlohmann/json Licensed under the MIT License . diff --git a/test/src/unit-pointer_access.cpp b/test/src/unit-pointer_access.cpp index bcf55034..d81205bf 100644 --- a/test/src/unit-pointer_access.cpp +++ b/test/src/unit-pointer_access.cpp @@ -1,7 +1,7 @@ /* __ _____ _____ _____ __| | __| | | | JSON for Modern C++ (test suite) -| | |__ | | | | | | version 2.0.5 +| | |__ | | | | | | version 2.0.6 |_____|_____|_____|_|___| https://github.com/nlohmann/json Licensed under the MIT License . diff --git a/test/src/unit-readme.cpp b/test/src/unit-readme.cpp index 115048c4..bccd5a23 100644 --- a/test/src/unit-readme.cpp +++ b/test/src/unit-readme.cpp @@ -1,7 +1,7 @@ /* __ _____ _____ _____ __| | __| | | | JSON for Modern C++ (test suite) -| | |__ | | | | | | version 2.0.5 +| | |__ | | | | | | version 2.0.6 |_____|_____|_____|_|___| https://github.com/nlohmann/json Licensed under the MIT License . @@ -208,8 +208,8 @@ TEST_CASE("README", "[hide]") // maybe ["two", "three", "four", "one"] std::multiset c_mset {"one", "two", "one", "four"}; - json j_mset(c_mset); // only one entry for "one" is used - // maybe ["one", "two", "four"] + json j_mset(c_mset); // both entries for "one" are used + // maybe ["one", "two", "one", "four"] std::unordered_multiset c_umset {"one", "two", "one", "four"}; json j_umset(c_umset); // both entries for "one" are used diff --git a/test/src/unit-reference_access.cpp b/test/src/unit-reference_access.cpp index 51dfd790..7cfca564 100644 --- a/test/src/unit-reference_access.cpp +++ b/test/src/unit-reference_access.cpp @@ -1,7 +1,7 @@ /* __ _____ _____ _____ __| | __| | | | JSON for Modern C++ (test suite) -| | |__ | | | | | | version 2.0.5 +| | |__ | | | | | | version 2.0.6 |_____|_____|_____|_|___| https://github.com/nlohmann/json Licensed under the MIT License . diff --git a/test/src/unit-regression.cpp b/test/src/unit-regression.cpp index 34eb197f..16d9351a 100644 --- a/test/src/unit-regression.cpp +++ b/test/src/unit-regression.cpp @@ -1,7 +1,7 @@ /* __ _____ _____ _____ __| | __| | | | JSON for Modern C++ (test suite) -| | |__ | | | | | | version 2.0.5 +| | |__ | | | | | | version 2.0.6 |_____|_____|_____|_|___| https://github.com/nlohmann/json Licensed under the MIT License . @@ -482,4 +482,11 @@ TEST_CASE("regression tests") CHECK_NOTHROW(j << f); } } + + SECTION("issue #323 - add nested object capabilities to pointers") + { + json j; + j["/this/that/2"_json_pointer] = 27; + CHECK(j == json({{"this", {{"that", {nullptr, nullptr, 27}}}}})); + } } diff --git a/test/src/unit-serialization.cpp b/test/src/unit-serialization.cpp index 0175b2a0..f49f79c3 100644 --- a/test/src/unit-serialization.cpp +++ b/test/src/unit-serialization.cpp @@ -1,7 +1,7 @@ /* __ _____ _____ _____ __| | __| | | | JSON for Modern C++ (test suite) -| | |__ | | | | | | version 2.0.5 +| | |__ | | | | | | version 2.0.6 |_____|_____|_____|_|___| https://github.com/nlohmann/json Licensed under the MIT License . diff --git a/test/src/unit-testsuites.cpp b/test/src/unit-testsuites.cpp index cb88f737..f717a98a 100644 --- a/test/src/unit-testsuites.cpp +++ b/test/src/unit-testsuites.cpp @@ -1,7 +1,7 @@ /* __ _____ _____ _____ __| | __| | | | JSON for Modern C++ (test suite) -| | |__ | | | | | | version 2.0.5 +| | |__ | | | | | | version 2.0.6 |_____|_____|_____|_|___| https://github.com/nlohmann/json Licensed under the MIT License . diff --git a/test/src/unit-unicode.cpp b/test/src/unit-unicode.cpp index 7549a5c2..5ab8f524 100644 --- a/test/src/unit-unicode.cpp +++ b/test/src/unit-unicode.cpp @@ -1,7 +1,7 @@ /* __ _____ _____ _____ __| | __| | | | JSON for Modern C++ (test suite) -| | |__ | | | | | | version 2.0.5 +| | |__ | | | | | | version 2.0.6 |_____|_____|_____|_|___| https://github.com/nlohmann/json Licensed under the MIT License . diff --git a/test/src/unit.cpp b/test/src/unit.cpp index 28d56db9..1a3707c7 100644 --- a/test/src/unit.cpp +++ b/test/src/unit.cpp @@ -1,7 +1,7 @@ /* __ _____ _____ _____ __| | __| | | | JSON for Modern C++ (test suite) -| | |__ | | | | | | version 2.0.5 +| | |__ | | | | | | version 2.0.6 |_____|_____|_____|_|___| https://github.com/nlohmann/json Licensed under the MIT License .