Merge branch 'develop' into coverity_scan

This commit is contained in:
Niels Lohmann 2017-02-25 16:38:18 +01:00
commit 03f06e1993
No known key found for this signature in database
GPG key ID: 7F3CEA63AE251B69
62 changed files with 6662 additions and 1352 deletions

View file

@ -1,24 +0,0 @@
{
"targets": {
"xenial-i386": {
"buildenv": "xenial-i386",
"builddeps": ["build-essential", "cmake"],
"buildcmd": ["mkdir cm", "cd cm", "cmake ..", "cmake --build .", "ctest --output-on-failure"]
},
"xenial-amd64": {
"buildenv": "xenial-amd64",
"builddeps": ["build-essential", "cmake"],
"buildcmd": ["mkdir cm", "cd cm", "cmake ..", "cmake --build .", "ctest --output-on-failure"]
},
"fedora24-x86_64": {
"buildenv": "fedora24-x86_64",
"builddeps": ["cmake", "make", "clang"],
"buildcmd": ["mkdir cm", "cd cm", "CXX=clang++ cmake ..", "cmake --build .", "ctest --output-on-failure"]
},
"osx": {
"buildenv": "osx",
"builddeps": ["build-essential"],
"buildcmd": ["make check"]
}
}
}

1
.gitignore vendored
View file

@ -7,6 +7,7 @@ fuzz-testing
*.gcno *.gcno
*.gcda *.gcda
build
working working
doc/xml doc/xml

View file

@ -228,6 +228,14 @@ install:
# make sure CXX is correctly set # make sure CXX is correctly set
- if [[ "${COMPILER}" != "" ]]; then export CXX=${COMPILER}; fi - if [[ "${COMPILER}" != "" ]]; then export CXX=${COMPILER}; fi
# get CMake (only for systems with brew - macOS)
- |
if [[ !(-x $(which cmake)) && (-x $(which brew)) ]]; then
brew update
brew install cmake
cmake --version
fi
# install LLVM/clang when LLVM_VERSION is set # install LLVM/clang when LLVM_VERSION is set
- | - |
if [[ "${LLVM_VERSION}" != "" ]]; then if [[ "${LLVM_VERSION}" != "" ]]; then
@ -266,7 +274,10 @@ script:
- $CXX --version - $CXX --version
# compile and execute unit tests # compile and execute unit tests
- make check - mkdir -p build && cd build
- cmake .. && cmake --build . --config Release -- -j4
- ctest -C Release -V
- cd ..
# check if homebrew works (only checks develop branch) # check if homebrew works (only checks develop branch)
- if [ `which brew` ]; then - if [ `which brew` ]; then

View file

@ -1,7 +1,7 @@
cmake_minimum_required(VERSION 3.0) cmake_minimum_required(VERSION 3.0)
# define the project # define the project
project(nlohmann_json VERSION 2.1.0 LANGUAGES CXX) project(nlohmann_json VERSION 2.1.1 LANGUAGES CXX)
enable_testing() enable_testing()
@ -16,6 +16,8 @@ set(JSON_CONFIGVERSION_FILENAME "${JSON_PACKAGE_NAME}ConfigVersion.cmake")
set(JSON_CONFIG_DESTINATION "cmake") set(JSON_CONFIG_DESTINATION "cmake")
set(JSON_INCLUDE_DESTINATION "include/nlohmann") set(JSON_INCLUDE_DESTINATION "include/nlohmann")
set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake")
# create and configure the library target # create and configure the library target
add_library(${JSON_TARGET_NAME} INTERFACE) add_library(${JSON_TARGET_NAME} INTERFACE)
target_include_directories(${JSON_TARGET_NAME} INTERFACE target_include_directories(${JSON_TARGET_NAME} INTERFACE
@ -23,7 +25,7 @@ target_include_directories(${JSON_TARGET_NAME} INTERFACE
$<INSTALL_INTERFACE:${JSON_INCLUDE_DESTINATION}>) $<INSTALL_INTERFACE:${JSON_INCLUDE_DESTINATION}>)
# create and configure the unit test target # create and configure the unit test target
if (BuildTests) if(BuildTests)
add_subdirectory(test) add_subdirectory(test)
endif() endif()
@ -39,17 +41,17 @@ write_basic_package_version_file("${CMAKE_CURRENT_BINARY_DIR}/${JSON_CONFIGVERSI
# export the library target and store build directory in package registry # export the library target and store build directory in package registry
export(TARGETS ${JSON_TARGET_NAME} export(TARGETS ${JSON_TARGET_NAME}
FILE "${CMAKE_CURRENT_BINARY_DIR}/${JSON_TARGETS_FILENAME}") FILE "${CMAKE_CURRENT_BINARY_DIR}/${JSON_TARGETS_FILENAME}")
export(PACKAGE ${JSON_PACKAGE_NAME}) export(PACKAGE ${JSON_PACKAGE_NAME})
# install library target and config files # install library target and config files
install(TARGETS ${JSON_TARGET_NAME} install(TARGETS ${JSON_TARGET_NAME}
EXPORT ${JSON_PACKAGE_NAME}) EXPORT ${JSON_PACKAGE_NAME})
install(FILES "src/json.hpp" install(FILES "src/json.hpp"
DESTINATION ${JSON_INCLUDE_DESTINATION}) DESTINATION ${JSON_INCLUDE_DESTINATION})
install(EXPORT ${JSON_PACKAGE_NAME} install(EXPORT ${JSON_PACKAGE_NAME}
FILE ${JSON_TARGETS_FILENAME} FILE ${JSON_TARGETS_FILENAME}
DESTINATION ${JSON_CONFIG_DESTINATION}) DESTINATION ${JSON_CONFIG_DESTINATION})
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/${JSON_CONFIG_FILENAME}" install(FILES "${CMAKE_CURRENT_BINARY_DIR}/${JSON_CONFIG_FILENAME}"
"${CMAKE_CURRENT_BINARY_DIR}/${JSON_CONFIGVERSION_FILENAME}" "${CMAKE_CURRENT_BINARY_DIR}/${JSON_CONFIGVERSION_FILENAME}"
DESTINATION ${JSON_CONFIG_DESTINATION}) DESTINATION ${JSON_CONFIG_DESTINATION})

View file

@ -1,6 +1,40 @@
# Change Log # Change Log
All notable changes to this project will be documented in this file. This project adheres to [Semantic Versioning](http://semver.org/). All notable changes to this project will be documented in this file. This project adheres to [Semantic Versioning](http://semver.org/).
## [v2.1.1](https://github.com/nlohmann/json/releases/tag/v2.1.1) (2017-02-25)
[Full Changelog](https://github.com/nlohmann/json/compare/v2.1.0...v2.1.1)
- warning in the library [\#472](https://github.com/nlohmann/json/issues/472)
- How to create an array of Objects? [\#470](https://github.com/nlohmann/json/issues/470)
- \[Bug?\] Cannot get int pointer, but int64\_t works [\#468](https://github.com/nlohmann/json/issues/468)
- Illegal indirection [\#467](https://github.com/nlohmann/json/issues/467)
- in vs can't find linkageId [\#466](https://github.com/nlohmann/json/issues/466)
- Roundtrip error while parsing "1000000000000000010E5" [\#465](https://github.com/nlohmann/json/issues/465)
- C4996 error and warning with Visual Studio [\#463](https://github.com/nlohmann/json/issues/463)
- Support startIndex for from\_cbor/from\_msgpack [\#462](https://github.com/nlohmann/json/issues/462)
- question: monospace font used in feature slideshow? [\#460](https://github.com/nlohmann/json/issues/460)
- Object.keys\(\) [\#459](https://github.com/nlohmann/json/issues/459)
- Use “, “ as delimiter for json-objects. [\#457](https://github.com/nlohmann/json/issues/457)
- Enum -\> string during serialization and vice versa [\#455](https://github.com/nlohmann/json/issues/455)
- doubles are printed as integers [\#454](https://github.com/nlohmann/json/issues/454)
- Warnings with Visual Studio c++ \(VS2015 Update 3\) [\#453](https://github.com/nlohmann/json/issues/453)
- Heap-buffer-overflow \(OSS-Fuzz issue 585\) [\#452](https://github.com/nlohmann/json/issues/452)
- use of undeclared identifier 'UINT8\_MAX' [\#451](https://github.com/nlohmann/json/issues/451)
- Question on the lifetime managment of objects at the lower levels [\#449](https://github.com/nlohmann/json/issues/449)
- Json should not be constructible with 'json\*' [\#448](https://github.com/nlohmann/json/issues/448)
- Move value\_t to namespace scope [\#447](https://github.com/nlohmann/json/issues/447)
- Typo in README.md [\#446](https://github.com/nlohmann/json/issues/446)
- make check compilation is unneccesarily slow [\#445](https://github.com/nlohmann/json/issues/445)
- Problem in dump\(\) in json.h caused by ss.imbue [\#444](https://github.com/nlohmann/json/issues/444)
- I want to create Windows Application in Visual Studio 2015 c++, and i have a problem [\#443](https://github.com/nlohmann/json/issues/443)
- Implicit conversion issues [\#442](https://github.com/nlohmann/json/issues/442)
- Parsing of floats locale dependent [\#302](https://github.com/nlohmann/json/issues/302)
- Speedup CI builds using cotire [\#461](https://github.com/nlohmann/json/pull/461) ([tusharpm](https://github.com/tusharpm))
- TurpentineDistillery feature/locale independent str to num [\#450](https://github.com/nlohmann/json/pull/450) ([nlohmann](https://github.com/nlohmann))
- README: adjust boost::optional example [\#439](https://github.com/nlohmann/json/pull/439) ([jaredgrubb](https://github.com/jaredgrubb))
- fix \#414 - comparing to 0 literal [\#415](https://github.com/nlohmann/json/pull/415) ([stanmihai4](https://github.com/stanmihai4))
## [v2.1.0](https://github.com/nlohmann/json/releases/tag/v2.1.0) (2017-01-28) ## [v2.1.0](https://github.com/nlohmann/json/releases/tag/v2.1.0) (2017-01-28)
[Full Changelog](https://github.com/nlohmann/json/compare/v2.0.10...v2.1.0) [Full Changelog](https://github.com/nlohmann/json/compare/v2.0.10...v2.1.0)
@ -20,6 +54,7 @@ All notable changes to this project will be documented in this file. This projec
- size parameter for parse\(\) [\#419](https://github.com/nlohmann/json/issues/419) - size parameter for parse\(\) [\#419](https://github.com/nlohmann/json/issues/419)
- json.hpp forcibly defines GCC\_VERSION [\#417](https://github.com/nlohmann/json/issues/417) - json.hpp forcibly defines GCC\_VERSION [\#417](https://github.com/nlohmann/json/issues/417)
- Use-of-uninitialized-value \(OSS-Fuzz issue 377\) [\#416](https://github.com/nlohmann/json/issues/416) - Use-of-uninitialized-value \(OSS-Fuzz issue 377\) [\#416](https://github.com/nlohmann/json/issues/416)
- comparing to 0 literal [\#414](https://github.com/nlohmann/json/issues/414)
- Single char converted to ASCII code instead of string [\#413](https://github.com/nlohmann/json/issues/413) - Single char converted to ASCII code instead of string [\#413](https://github.com/nlohmann/json/issues/413)
- How to know if a string was parsed as utf-8? [\#406](https://github.com/nlohmann/json/issues/406) - How to know if a string was parsed as utf-8? [\#406](https://github.com/nlohmann/json/issues/406)
- Overloaded += to add objects to an array makes no sense? [\#404](https://github.com/nlohmann/json/issues/404) - Overloaded += to add objects to an array makes no sense? [\#404](https://github.com/nlohmann/json/issues/404)
@ -37,6 +72,7 @@ All notable changes to this project will be documented in this file. This projec
- conversion from/to user-defined types [\#435](https://github.com/nlohmann/json/pull/435) ([nlohmann](https://github.com/nlohmann)) - conversion from/to user-defined types [\#435](https://github.com/nlohmann/json/pull/435) ([nlohmann](https://github.com/nlohmann))
- Fix documentation error [\#430](https://github.com/nlohmann/json/pull/430) ([vjon](https://github.com/vjon)) - Fix documentation error [\#430](https://github.com/nlohmann/json/pull/430) ([vjon](https://github.com/vjon))
- locale-independent num-to-str [\#378](https://github.com/nlohmann/json/pull/378) ([TurpentineDistillery](https://github.com/TurpentineDistillery))
## [v2.0.10](https://github.com/nlohmann/json/releases/tag/v2.0.10) (2017-01-02) ## [v2.0.10](https://github.com/nlohmann/json/releases/tag/v2.0.10) (2017-01-02)
[Full Changelog](https://github.com/nlohmann/json/compare/v2.0.9...v2.0.10) [Full Changelog](https://github.com/nlohmann/json/compare/v2.0.9...v2.0.10)

View file

@ -41,6 +41,28 @@ doctest:
$(MAKE) check_output -C doc $(MAKE) check_output -C doc
##########################################################################
# warning detector
##########################################################################
# calling Clang with all warnings, except:
# -Wno-documentation-unknown-command: code uses user-defined commands like @complexity
# -Wno-exit-time-destructors: warning in Catch code
# -Wno-keyword-macro: unit-tests use "#define private public"
# -Wno-deprecated-declarations: some functions are deprecated until 3.0.0
# -Wno-range-loop-analysis: iterator_wrapper tests tests "for(const auto i...)"
pedantic:
$(MAKE) json_unit CXXFLAGS="\
-std=c++11 \
-Werror \
-Weverything \
-Wno-documentation-unknown-command \
-Wno-exit-time-destructors \
-Wno-keyword-macro \
-Wno-deprecated-declarations \
-Wno-range-loop-analysis"
########################################################################## ##########################################################################
# fuzzing # fuzzing
########################################################################## ##########################################################################
@ -94,7 +116,7 @@ cppcheck:
# run clang sanitize (we are overrding the CXXFLAGS provided by travis in order to use gcc's libstdc++) # run clang sanitize (we are overrding the CXXFLAGS provided by travis in order to use gcc's libstdc++)
clang_sanitize: clean clang_sanitize: clean
CXX=clang++ CXXFLAGS="-g -O2 -fsanitize=address -fsanitize=undefined -fno-omit-frame-pointer" $(MAKE) CXX=clang++ CXXFLAGS="-g -O2 -fsanitize=address -fsanitize=undefined -fno-omit-frame-pointer" $(MAKE) check
########################################################################## ##########################################################################

View file

@ -2,9 +2,9 @@
[![Build Status](https://travis-ci.org/nlohmann/json.svg?branch=master)](https://travis-ci.org/nlohmann/json) [![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) [![Build Status](https://ci.appveyor.com/api/projects/status/1acb366xfyg3qybk/branch/develop?svg=true)](https://ci.appveyor.com/project/nlohmann/json)
[![Build status](https://doozer.io/badge/nlohmann/json/buildstatus/develop)](https://doozer.io/user/nlohmann/json)
[![Coverage Status](https://img.shields.io/coveralls/nlohmann/json.svg)](https://coveralls.io/r/nlohmann/json) [![Coverage Status](https://img.shields.io/coveralls/nlohmann/json.svg)](https://coveralls.io/r/nlohmann/json)
[![Coverity Scan Build Status](https://scan.coverity.com/projects/5550/badge.svg)](https://scan.coverity.com/projects/nlohmann-json) [![Coverity Scan Build Status](https://scan.coverity.com/projects/5550/badge.svg)](https://scan.coverity.com/projects/nlohmann-json)
[![Codacy Badge](https://api.codacy.com/project/badge/Grade/f3732b3327e34358a0e9d1fe9f661f08)](https://www.codacy.com/app/nlohmann/json?utm_source=github.com&amp;utm_medium=referral&amp;utm_content=nlohmann/json&amp;utm_campaign=Badge_Grade)
[![Try online](https://img.shields.io/badge/try-online-blue.svg)](http://melpon.org/wandbox/permlink/4NEU6ZZMoM9lpIex) [![Try online](https://img.shields.io/badge/try-online-blue.svg)](http://melpon.org/wandbox/permlink/4NEU6ZZMoM9lpIex)
[![Documentation](https://img.shields.io/badge/docs-doxygen-blue.svg)](http://nlohmann.github.io/json) [![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 license](https://img.shields.io/badge/license-MIT-blue.svg)](https://raw.githubusercontent.com/nlohmann/json/master/LICENSE.MIT)
@ -26,6 +26,8 @@
- [Supported compilers](#supported-compilers) - [Supported compilers](#supported-compilers)
- [License](#license) - [License](#license)
- [Thanks](#thanks) - [Thanks](#thanks)
- [Used third-party tools](#used-third-party-tools)
- [Projects using JSON for Modern C++](#projects-using-json-for-modern-c)
- [Notes](#notes) - [Notes](#notes)
- [Execute unit tests](#execute-unit-tests) - [Execute unit tests](#execute-unit-tests)
@ -167,8 +169,14 @@ auto j2 = R"(
"pi": 3.141 "pi": 3.141
} }
)"_json; )"_json;
```
// or explicitly Note that without appending the `_json` suffix, the passed string literal is not parsed, but just used as JSON string value. That is, `json j = "{ \"happy\": true, \"pi\": 3.141 }"` would just store the string `"{ "happy": true, "pi": 3.141 }"` rather than parsing the actual object.
The above example can also be expressed explicitly using `json::parse()`:
```cpp
// parse explicitly
auto j3 = json::parse("{ \"happy\": true, \"pi\": 3.141 }"); auto j3 = json::parse("{ \"happy\": true, \"pi\": 3.141 }");
``` ```
@ -802,7 +810,7 @@ I deeply appreciate the help of the following people.
- [Vladimir Petrigo](https://github.com/vpetrigo) made a SFINAE hack more readable. - [Vladimir Petrigo](https://github.com/vpetrigo) made a SFINAE hack more readable.
- [Denis Andrejew](https://github.com/seeekr) fixed a grammar issue in the README file. - [Denis Andrejew](https://github.com/seeekr) fixed a grammar issue in the README file.
- [Pierre-Antoine Lacaze](https://github.com/palacaze) found a subtle bug in the `dump()` function. - [Pierre-Antoine Lacaze](https://github.com/palacaze) found a subtle bug in the `dump()` function.
- [TurpentineDistillery](https://github.com/TurpentineDistillery) pointed to [`std::locale::classic()`](http://en.cppreference.com/w/cpp/locale/locale/classic) to avoid too much locale joggling, found some nice performance improvements in the parser and improved the benchmarking code. - [TurpentineDistillery](https://github.com/TurpentineDistillery) pointed to [`std::locale::classic()`](http://en.cppreference.com/w/cpp/locale/locale/classic) to avoid too much locale joggling, found some nice performance improvements in the parser, improved the benchmarking code, and realized locale-independent number parsing and printing.
- [cgzones](https://github.com/cgzones) had an idea how to fix the Coverity scan. - [cgzones](https://github.com/cgzones) had an idea how to fix the Coverity scan.
- [Jared Grubb](https://github.com/jaredgrubb) silenced a nasty documentation warning. - [Jared Grubb](https://github.com/jaredgrubb) silenced a nasty documentation warning.
- [Yixin Zhang](https://github.com/qwename) fixed an integer overflow check. - [Yixin Zhang](https://github.com/qwename) fixed an integer overflow check.
@ -813,10 +821,49 @@ I deeply appreciate the help of the following people.
- [Alexej Harm](https://github.com/qis) helped to get the user-defined types working with Visual Studio. - [Alexej Harm](https://github.com/qis) helped to get the user-defined types working with Visual Studio.
- [Jared Grubb](https://github.com/jaredgrubb) supported the implementation of user-defined types. - [Jared Grubb](https://github.com/jaredgrubb) supported the implementation of user-defined types.
- [EnricoBilla](https://github.com/EnricoBilla) noted a typo in an example. - [EnricoBilla](https://github.com/EnricoBilla) noted a typo in an example.
- [Martin Hořeňovský](https://github.com/horenmar) found a way for a 2x speedup for the compilation time of the test suite.
- [ukhegg](https://github.com/ukhegg) found proposed an improvement for the examples section.
- [rswanson-ihi](https://github.com/rswanson-ihi) noted a type in the README.
- [Mihai Stan](https://github.com/stanmihai4) fixed a bug in the comparison with `nullptr`s.
- [Tushar Maheshwari](https://github.com/tusharpm) added [cotire](https://github.com/sakra/cotire) support to speed up the compilation.
Thanks a lot for helping out! Please [let me know](mailto:mail@nlohmann.me) if I forgot someone. 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 thirs-party tools and services. Thanks a lot!
- [**American fuzzy lop**](http://lcamtuf.coredump.cx/afl/) for fuzz testing
- [**AppVeyor**](https://www.appveyor.com) for [continuous integration](https://ci.appveyor.com/project/nlohmann/json) on Windows
- [**Artistic Style**](http://astyle.sourceforge.net) for automatic source code identation
- [**benchpress**](https://github.com/sbs-ableton/benchpress) to benchmark the code
- [**Catch**](https://github.com/philsquared/Catch) for the unit tests
- [**Clang**](http://clang.llvm.org) for compilation with code sanitizers
- [**Cmake**](https://cmake.org) for build automation
- [**Codacity**](https://www.codacy.com) for further [code analysis](https://www.codacy.com/app/nlohmann/json)
- [**cotire**](https://github.com/sakra/cotire) to speed of compilation
- [**Coveralls**](https://coveralls.io) to measure [code coverage](https://coveralls.io/github/nlohmann/json)
- [**Coverity Scan**](https://scan.coverity.com) for [static analysis](https://scan.coverity.com/projects/nlohmann-json)
- [**cppcheck**](http://cppcheck.sourceforge.net) for static analysis
- [**cxxopts**](https://github.com/jarro2783/cxxopts) to let benchpress parse command-line parameters
- [**Doxygen**](http://www.stack.nl/~dimitri/doxygen/) to generate [documentation](https://nlohmann.github.io/json/)
- [**git-update-ghpages**](https://github.com/rstacruz/git-update-ghpages) to upload the documentation to gh-pages
- [**Github Changelog Generator**](https://github.com/skywinder/github-changelog-generator) to generate the [ChangeLog](https://github.com/nlohmann/json/blob/develop/ChangeLog.md)
- [**libFuzzer**](http://llvm.org/docs/LibFuzzer.html) to implement fuzz testing for OSS-Fuzz
- [**OSS-Fuzz**](https://github.com/google/oss-fuzz) for continuous fuzz testing of the library
- [**re2c**](http://re2c.org) to generate an automaton for the lexical analysis
- [**send_to_wandbox**](https://github.com/nlohmann/json/blob/develop/doc/scripts/send_to_wandbox.py) to send code examples to [Wandbox](http://melpon.org/wandbox)
- [**Travis**](https://travis-ci.org) for [continuous integration](https://travis-ci.org/nlohmann/json) on Linux and macOS
- [**Valgrind**](http://valgrind.org) to check for correct memory management
- [**Wandbox**](http://melpon.org/wandbox) for [online examples](http://melpon.org/wandbox/permlink/4NEU6ZZMoM9lpIex)
## Projects using JSON for Modern C++
The library is currently used in Apple macOS Sierra and iOS 10. I am not sure what they are using the library for, but I am happy that it runs on so many devices.
## Notes ## Notes
- The code contains numerous debug **assertions** which can be switched off by defining the preprocessor macro `NDEBUG`, see the [documentation of `assert`](http://en.cppreference.com/w/cpp/error/assert). In particular, note [`operator[]`](https://nlohmann.github.io/json/classnlohmann_1_1basic__json_a2e26bd0b0168abb61f67ad5bcd5b9fa1.html#a2e26bd0b0168abb61f67ad5bcd5b9fa1) implements **unchecked access** for const objects: If the given key is not present, the behavior is undefined (think of a dereferenced null pointer) and yields an [assertion failure](https://github.com/nlohmann/json/issues/289) if assertions are switched on. If you are not sure whether an element in an object exists, use checked access with the [`at()` function](https://nlohmann.github.io/json/classnlohmann_1_1basic__json_a674de1ee73e6bf4843fc5dc1351fb726.html#a674de1ee73e6bf4843fc5dc1351fb726). - The code contains numerous debug **assertions** which can be switched off by defining the preprocessor macro `NDEBUG`, see the [documentation of `assert`](http://en.cppreference.com/w/cpp/error/assert). In particular, note [`operator[]`](https://nlohmann.github.io/json/classnlohmann_1_1basic__json_a2e26bd0b0168abb61f67ad5bcd5b9fa1.html#a2e26bd0b0168abb61f67ad5bcd5b9fa1) implements **unchecked access** for const objects: If the given key is not present, the behavior is undefined (think of a dereferenced null pointer) and yields an [assertion failure](https://github.com/nlohmann/json/issues/289) if assertions are switched on. If you are not sure whether an element in an object exists, use checked access with the [`at()` function](https://nlohmann.github.io/json/classnlohmann_1_1basic__json_a674de1ee73e6bf4843fc5dc1351fb726.html#a674de1ee73e6bf4843fc5dc1351fb726).
@ -840,7 +887,7 @@ $ make json_unit -Ctest
$ ./test/json_unit "*"" $ ./test/json_unit "*""
=============================================================================== ===============================================================================
All tests passed (11202052 assertions in 47 test cases) All tests passed (11202597 assertions in 47 test cases)
``` ```
Alternatively, you can use [CMake](https://cmake.org) and run Alternatively, you can use [CMake](https://cmake.org) and run

4008
cmake/cotire.cmake Normal file

File diff suppressed because it is too large Load diff

View file

@ -5,7 +5,7 @@
#--------------------------------------------------------------------------- #---------------------------------------------------------------------------
DOXYFILE_ENCODING = UTF-8 DOXYFILE_ENCODING = UTF-8
PROJECT_NAME = "JSON for Modern C++" PROJECT_NAME = "JSON for Modern C++"
PROJECT_NUMBER = 2.1.0 PROJECT_NUMBER = 2.1.1
PROJECT_BRIEF = PROJECT_BRIEF =
PROJECT_LOGO = PROJECT_LOGO =
OUTPUT_DIRECTORY = . OUTPUT_DIRECTORY = .

View file

@ -53,11 +53,11 @@ clean:
# create Doxygen documentation # create Doxygen documentation
doxygen: create_output create_links doxygen: create_output create_links
doxygen doxygen
$(SED) -i 's@&lt; ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberFloatType, AllocatorType &gt;@@g' html/*.html $(SED) -i 's@&lt; ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberFloatType, AllocatorType, JSONSerializer &gt;@@g' html/*.html
$(SED) -i 's@&lt;&#160;ObjectType,&#160;ArrayType,&#160;StringType,&#160;BooleanType,&#160;NumberIntegerType,&#160;NumberFloatType,&#160;AllocatorType&#160;&gt;@@g' html/*.html $(SED) -i 's@&lt;&#160;ObjectType,&#160;ArrayType,&#160;StringType,&#160;BooleanType,&#160;NumberIntegerType,&#160;NumberFloatType,&#160;AllocatorType&#160;JSONSerializer&#160;&gt;@@g' html/*.html
$(SED) -i 's@&lt; ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType &gt;@@g' html/*.html $(SED) -i 's@&lt; ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer &gt;@@g' html/*.html
$(SED) -i 's@< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType >@@g' html/*.html $(SED) -i 's@< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer >@@g' html/*.html
$(SED) -i 's@&lt;&#160;ObjectType,&#160;ArrayType,&#160;StringType,&#160;BooleanType,&#160;NumberIntegerType,&#160;NumberUnsignedType,&#160;NumberFloatType,&#160;AllocatorType&#160;&gt;@@g' html/*.html $(SED) -i 's@&lt;&#160;ObjectType,&#160;ArrayType,&#160;StringType,&#160;BooleanType,&#160;NumberIntegerType,&#160;NumberUnsignedType,&#160;NumberFloatType,&#160;AllocatorType&#160;JSONSerializer&#160;&gt;@@g' html/*.html
upload: clean doxygen check_output upload: clean doxygen check_output
cd html ; ../scripts/git-update-ghpages nlohmann/json cd html ; ../scripts/git-update-ghpages nlohmann/json

View file

@ -11,7 +11,7 @@
"version": { "version": {
"major": 2, "major": 2,
"minor": 1, "minor": 1,
"patch": 0, "patch": 1,
"string": "2.1.0" "string": "2.1.1"
} }
} }

View file

@ -277,4 +277,4 @@ The container functions known from STL have been extended to support the differe
@author [Niels Lohmann](http://nlohmann.me) @author [Niels Lohmann](http://nlohmann.me)
@see https://github.com/nlohmann/json to download the source code @see https://github.com/nlohmann/json to download the source code
@version 2.1.0 @version 2.1.1

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.4 MiB

After

Width:  |  Height:  |  Size: 1.4 MiB

BIN
doc/usages/ios.png Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 204 KiB

BIN
doc/usages/macos.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 MiB

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -1,8 +1,16 @@
add_library(catch_main OBJECT
"src/unit.cpp"
)
set_target_properties(catch_main PROPERTIES
CXX_STANDARD 11
CXX_STANDARD_REQUIRED ON
)
target_include_directories(catch_main PRIVATE "thirdparty/catch")
# The unit test executable. # The unit test executable.
set(JSON_UNITTEST_TARGET_NAME "json_unit") set(JSON_UNITTEST_TARGET_NAME "json_unit")
add_executable(${JSON_UNITTEST_TARGET_NAME} add_executable(${JSON_UNITTEST_TARGET_NAME}
"thirdparty/catch/catch.hpp" $<TARGET_OBJECTS:catch_main>
"src/unit.cpp"
"src/unit-algorithms.cpp" "src/unit-algorithms.cpp"
"src/unit-allocator.cpp" "src/unit-allocator.cpp"
"src/unit-capacity.cpp" "src/unit-capacity.cpp"
@ -43,13 +51,33 @@ add_executable(${JSON_UNITTEST_TARGET_NAME}
set_target_properties(${JSON_UNITTEST_TARGET_NAME} PROPERTIES set_target_properties(${JSON_UNITTEST_TARGET_NAME} PROPERTIES
CXX_STANDARD 11 CXX_STANDARD 11
CXX_STANDARD_REQUIRED ON CXX_STANDARD_REQUIRED ON
COMPILE_DEFINITIONS "$<$<CXX_COMPILER_ID:MSVC>:_SCL_SECURE_NO_WARNINGS>"
COMPILE_OPTIONS "$<$<CXX_COMPILER_ID:MSVC>:/EHsc;$<$<CONFIG:Release>:/Od>>"
) )
if(MSVC)
set_target_properties(${JSON_UNITTEST_TARGET_NAME} PROPERTIES
COMPILE_DEFINITIONS "_SCL_SECURE_NO_WARNINGS"
COMPILE_OPTIONS "/EHsc;$<$<CONFIG:Release>:/Od>"
)
endif()
target_include_directories(${JSON_UNITTEST_TARGET_NAME} PRIVATE "src" "thirdparty/catch") target_include_directories(${JSON_UNITTEST_TARGET_NAME} PRIVATE "src" "thirdparty/catch")
target_link_libraries(${JSON_UNITTEST_TARGET_NAME} ${JSON_TARGET_NAME}) target_link_libraries(${JSON_UNITTEST_TARGET_NAME} ${JSON_TARGET_NAME})
include(cotire OPTIONAL)
if(COMMAND cotire)
set_target_properties(${JSON_UNITTEST_TARGET_NAME} PROPERTIES
COTIRE_ADD_UNITY_BUILD FALSE
COTIRE_CXX_PREFIX_HEADER_INIT "src/prefix.hpp"
)
# HACK - CMAKE_INCLUDE_SYSTEM_FLAG_CXX has a trailing space, which Cotire doesn't strip
# Technically, this fix should go in cotire.cmake. TODO - submit a pull request upstream.
if (CMAKE_INCLUDE_SYSTEM_FLAG_CXX)
string (STRIP "${CMAKE_INCLUDE_SYSTEM_FLAG_CXX}" CMAKE_INCLUDE_SYSTEM_FLAG_CXX)
endif()
cotire(${JSON_UNITTEST_TARGET_NAME})
endif()
add_test(NAME "${JSON_UNITTEST_TARGET_NAME}_default" add_test(NAME "${JSON_UNITTEST_TARGET_NAME}_default"
COMMAND ${JSON_UNITTEST_TARGET_NAME} COMMAND ${JSON_UNITTEST_TARGET_NAME}
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}

View file

@ -71,9 +71,9 @@ json_unit: $(OBJECTS) ../src/json.hpp thirdparty/catch/catch.hpp
# individual test cases # individual test cases
############################################################################## ##############################################################################
test-%: src/unit-%.cpp ../src/json.hpp thirdparty/catch/catch.hpp test-%: src/unit-%.o src/unit.o ../src/json.hpp thirdparty/catch/catch.hpp
@echo "[CXXLD] $@" @echo "[CXXLD] $@"
@$(CXX) $(CXXFLAGS) $(CPPFLAGS) $(LDFLAGS) -DCATCH_CONFIG_MAIN $< -o $@ @$(CXX) $(CXXFLAGS) $(CPPFLAGS) $(LDFLAGS) $< src/unit.o -o $@
TEST_PATTERN ?= "*" TEST_PATTERN ?= "*"
TEST_PREFIX = "" TEST_PREFIX = ""

View file

@ -1,7 +1,7 @@
/* /*
__ _____ _____ _____ __ _____ _____ _____
__| | __| | | | JSON for Modern C++ (fuzz test support) __| | __| | | | JSON for Modern C++ (fuzz test support)
| | |__ | | | | | | version 2.1.0 | | |__ | | | | | | version 2.1.1
|_____|_____|_____|_|___| https://github.com/nlohmann/json |_____|_____|_____|_|___| https://github.com/nlohmann/json
This file implements a driver for American Fuzzy Lop (afl-fuzz). It relies on This file implements a driver for American Fuzzy Lop (afl-fuzz). It relies on

View file

@ -1,7 +1,7 @@
/* /*
__ _____ _____ _____ __ _____ _____ _____
__| | __| | | | JSON for Modern C++ (fuzz test support) __| | __| | | | JSON for Modern C++ (fuzz test support)
| | |__ | | | | | | version 2.1.0 | | |__ | | | | | | version 2.1.1
|_____|_____|_____|_|___| https://github.com/nlohmann/json |_____|_____|_____|_|___| https://github.com/nlohmann/json
This file implements a parser test suitable for fuzz testing. Given a byte This file implements a parser test suitable for fuzz testing. Given a byte

View file

@ -1,7 +1,7 @@
/* /*
__ _____ _____ _____ __ _____ _____ _____
__| | __| | | | JSON for Modern C++ (fuzz test support) __| | __| | | | JSON for Modern C++ (fuzz test support)
| | |__ | | | | | | version 2.1.0 | | |__ | | | | | | version 2.1.1
|_____|_____|_____|_|___| https://github.com/nlohmann/json |_____|_____|_____|_|___| https://github.com/nlohmann/json
This file implements a parser test suitable for fuzz testing. Given a byte This file implements a parser test suitable for fuzz testing. Given a byte

View file

@ -1,7 +1,7 @@
/* /*
__ _____ _____ _____ __ _____ _____ _____
__| | __| | | | JSON for Modern C++ (fuzz test support) __| | __| | | | JSON for Modern C++ (fuzz test support)
| | |__ | | | | | | version 2.1.0 | | |__ | | | | | | version 2.1.1
|_____|_____|_____|_|___| https://github.com/nlohmann/json |_____|_____|_____|_|___| https://github.com/nlohmann/json
This file implements a parser test suitable for fuzz testing. Given a byte This file implements a parser test suitable for fuzz testing. Given a byte

7
test/src/prefix.hpp Normal file
View file

@ -0,0 +1,7 @@
#pragma once
#include "catch.hpp"
#define private public
#include "json.hpp"
using nlohmann::json;

View file

@ -1,7 +1,7 @@
/* /*
__ _____ _____ _____ __ _____ _____ _____
__| | __| | | | JSON for Modern C++ (test suite) __| | __| | | | JSON for Modern C++ (test suite)
| | |__ | | | | | | version 2.1.0 | | |__ | | | | | | version 2.1.1
|_____|_____|_____|_|___| https://github.com/nlohmann/json |_____|_____|_____|_|___| https://github.com/nlohmann/json
Licensed under the MIT License <http://opensource.org/licenses/MIT>. Licensed under the MIT License <http://opensource.org/licenses/MIT>.

View file

@ -1,7 +1,7 @@
/* /*
__ _____ _____ _____ __ _____ _____ _____
__| | __| | | | JSON for Modern C++ (test suite) __| | __| | | | JSON for Modern C++ (test suite)
| | |__ | | | | | | version 2.1.0 | | |__ | | | | | | version 2.1.1
|_____|_____|_____|_|___| https://github.com/nlohmann/json |_____|_____|_____|_|___| https://github.com/nlohmann/json
Licensed under the MIT License <http://opensource.org/licenses/MIT>. Licensed under the MIT License <http://opensource.org/licenses/MIT>.
@ -59,13 +59,13 @@ TEST_CASE("bad_alloc")
bad_allocator>; bad_allocator>;
// creating an object should throw // creating an object should throw
CHECK_THROWS_AS(bad_json j(bad_json::value_t::object), std::bad_alloc); CHECK_THROWS_AS(bad_json(bad_json::value_t::object), std::bad_alloc);
} }
} }
bool next_construct_fails = false; static bool next_construct_fails = false;
bool next_destroy_fails = false; static bool next_destroy_fails = false;
bool next_deallocate_fails = false; static bool next_deallocate_fails = false;
template<class T> template<class T>
struct my_allocator : std::allocator<T> struct my_allocator : std::allocator<T>
@ -141,39 +141,27 @@ TEST_CASE("controlled bad_alloc")
{ {
next_construct_fails = false; next_construct_fails = false;
auto t = my_json::value_t::object; auto t = my_json::value_t::object;
auto clean_up = [](my_json::json_value & j) CHECK_NOTHROW(my_allocator_clean_up(my_json::json_value(t).object));
{
my_allocator_clean_up(j.object);
};
CHECK_NOTHROW(my_json::json_value j(t); clean_up(j));
next_construct_fails = true; next_construct_fails = true;
CHECK_THROWS_AS(my_json::json_value j(t), std::bad_alloc); CHECK_THROWS_AS(my_json::json_value(t), std::bad_alloc);
next_construct_fails = false; next_construct_fails = false;
} }
SECTION("array") SECTION("array")
{ {
next_construct_fails = false; next_construct_fails = false;
auto t = my_json::value_t::array; auto t = my_json::value_t::array;
auto clean_up = [](my_json::json_value & j) CHECK_NOTHROW(my_allocator_clean_up(my_json::json_value(t).array));
{
my_allocator_clean_up(j.array);
};
CHECK_NOTHROW(my_json::json_value j(t); clean_up(j));
next_construct_fails = true; next_construct_fails = true;
CHECK_THROWS_AS(my_json::json_value j(t), std::bad_alloc); CHECK_THROWS_AS(my_json::json_value(t), std::bad_alloc);
next_construct_fails = false; next_construct_fails = false;
} }
SECTION("string") SECTION("string")
{ {
next_construct_fails = false; next_construct_fails = false;
auto t = my_json::value_t::string; auto t = my_json::value_t::string;
auto clean_up = [](my_json::json_value & j) CHECK_NOTHROW(my_allocator_clean_up(my_json::json_value(t).string));
{
my_allocator_clean_up(j.string);
};
CHECK_NOTHROW(my_json::json_value j(t); clean_up(j));
next_construct_fails = true; next_construct_fails = true;
CHECK_THROWS_AS(my_json::json_value j(t), std::bad_alloc); CHECK_THROWS_AS(my_json::json_value(t), std::bad_alloc);
next_construct_fails = false; next_construct_fails = false;
} }
} }
@ -182,13 +170,9 @@ TEST_CASE("controlled bad_alloc")
{ {
next_construct_fails = false; next_construct_fails = false;
my_json::string_t v("foo"); my_json::string_t v("foo");
auto clean_up = [](my_json::json_value & j) CHECK_NOTHROW(my_allocator_clean_up(my_json::json_value(v).string));
{
my_allocator_clean_up(j.string);
};
CHECK_NOTHROW(my_json::json_value j(v); clean_up(j));
next_construct_fails = true; next_construct_fails = true;
CHECK_THROWS_AS(my_json::json_value j(v), std::bad_alloc); CHECK_THROWS_AS(my_json::json_value(v), std::bad_alloc);
next_construct_fails = false; next_construct_fails = false;
} }
@ -222,9 +206,9 @@ TEST_CASE("controlled bad_alloc")
{ {
next_construct_fails = false; next_construct_fails = false;
std::map<std::string, std::string> v {{"foo", "bar"}}; std::map<std::string, std::string> v {{"foo", "bar"}};
CHECK_NOTHROW(my_json j(v)); CHECK_NOTHROW(my_json(v));
next_construct_fails = true; next_construct_fails = true;
CHECK_THROWS_AS(my_json j(v), std::bad_alloc); CHECK_THROWS_AS(my_json(v), std::bad_alloc);
next_construct_fails = false; next_construct_fails = false;
} }
@ -232,18 +216,18 @@ TEST_CASE("controlled bad_alloc")
{ {
next_construct_fails = false; next_construct_fails = false;
std::vector<std::string> v {"foo", "bar", "baz"}; std::vector<std::string> v {"foo", "bar", "baz"};
CHECK_NOTHROW(my_json j(v)); CHECK_NOTHROW(my_json(v));
next_construct_fails = true; next_construct_fails = true;
CHECK_THROWS_AS(my_json j(v), std::bad_alloc); CHECK_THROWS_AS(my_json(v), std::bad_alloc);
next_construct_fails = false; next_construct_fails = false;
} }
SECTION("basic_json(const typename string_t::value_type*)") SECTION("basic_json(const typename string_t::value_type*)")
{ {
next_construct_fails = false; next_construct_fails = false;
CHECK_NOTHROW(my_json v("foo")); CHECK_NOTHROW(my_json("foo"));
next_construct_fails = true; next_construct_fails = true;
CHECK_THROWS_AS(my_json v("foo"), std::bad_alloc); CHECK_THROWS_AS(my_json("foo"), std::bad_alloc);
next_construct_fails = false; next_construct_fails = false;
} }
@ -251,9 +235,9 @@ TEST_CASE("controlled bad_alloc")
{ {
next_construct_fails = false; next_construct_fails = false;
std::string s("foo"); std::string s("foo");
CHECK_NOTHROW(my_json v(s)); CHECK_NOTHROW(my_json(s));
next_construct_fails = true; next_construct_fails = true;
CHECK_THROWS_AS(my_json v(s), std::bad_alloc); CHECK_THROWS_AS(my_json(s), std::bad_alloc);
next_construct_fails = false; next_construct_fails = false;
} }
} }

View file

@ -1,7 +1,7 @@
/* /*
__ _____ _____ _____ __ _____ _____ _____
__| | __| | | | JSON for Modern C++ (test suite) __| | __| | | | JSON for Modern C++ (test suite)
| | |__ | | | | | | version 2.1.0 | | |__ | | | | | | version 2.1.1
|_____|_____|_____|_|___| https://github.com/nlohmann/json |_____|_____|_____|_|___| https://github.com/nlohmann/json
Licensed under the MIT License <http://opensource.org/licenses/MIT>. Licensed under the MIT License <http://opensource.org/licenses/MIT>.

View file

@ -1,7 +1,7 @@
/* /*
__ _____ _____ _____ __ _____ _____ _____
__| | __| | | | JSON for Modern C++ (test suite) __| | __| | | | JSON for Modern C++ (test suite)
| | |__ | | | | | | version 2.1.0 | | |__ | | | | | | version 2.1.1
|_____|_____|_____|_|___| https://github.com/nlohmann/json |_____|_____|_____|_|___| https://github.com/nlohmann/json
Licensed under the MIT License <http://opensource.org/licenses/MIT>. Licensed under the MIT License <http://opensource.org/licenses/MIT>.
@ -237,7 +237,7 @@ TEST_CASE("CBOR")
const auto result = json::to_cbor(j); const auto result = json::to_cbor(j);
CHECK(result == expected); CHECK(result == expected);
int16_t restored = -1 - ((result[1] << 8) + result[2]); int16_t restored = static_cast<int16_t>(-1 - ((result[1] << 8) + result[2]));
CHECK(restored == -9263); CHECK(restored == -9263);
// roundtrip // roundtrip
@ -1184,6 +1184,10 @@ TEST_CASE("single CBOR roundtrip")
// compare parsed JSON values // compare parsed JSON values
CHECK(j1 == j2); CHECK(j1 == j2);
// check with different start index
packed.insert(packed.begin(), 5, 0xff);
CHECK(j1 == json::from_cbor(packed, 5));
} }
} }
@ -1267,7 +1271,7 @@ TEST_CASE("CBOR regressions", "[!throws]")
SECTION("improve code coverage") SECTION("improve code coverage")
{ {
// exotic edge case // exotic edge case
CHECK_THROWS_AS(json::check_length(0xffffffffffffffff, 0xfffffffffffffff0, 0xff), std::out_of_range); CHECK_THROWS_AS(json::check_length(0xffffffffffffffffull, 0xfffffffffffffff0ull, 0xff), std::out_of_range);
} }
} }

View file

@ -1,7 +1,7 @@
/* /*
__ _____ _____ _____ __ _____ _____ _____
__| | __| | | | JSON for Modern C++ (test suite) __| | __| | | | JSON for Modern C++ (test suite)
| | |__ | | | | | | version 2.1.0 | | |__ | | | | | | version 2.1.1
|_____|_____|_____|_|___| https://github.com/nlohmann/json |_____|_____|_____|_|___| https://github.com/nlohmann/json
Licensed under the MIT License <http://opensource.org/licenses/MIT>. Licensed under the MIT License <http://opensource.org/licenses/MIT>.

View file

@ -1,7 +1,7 @@
/* /*
__ _____ _____ _____ __ _____ _____ _____
__| | __| | | | JSON for Modern C++ (test suite) __| | __| | | | JSON for Modern C++ (test suite)
| | |__ | | | | | | version 2.1.0 | | |__ | | | | | | version 2.1.1
|_____|_____|_____|_|___| https://github.com/nlohmann/json |_____|_____|_____|_|___| https://github.com/nlohmann/json
Licensed under the MIT License <http://opensource.org/licenses/MIT>. Licensed under the MIT License <http://opensource.org/licenses/MIT>.

View file

@ -1,7 +1,7 @@
/* /*
__ _____ _____ _____ __ _____ _____ _____
__| | __| | | | JSON for Modern C++ (test suite) __| | __| | | | JSON for Modern C++ (test suite)
| | |__ | | | | | | version 2.1.0 | | |__ | | | | | | version 2.1.1
|_____|_____|_____|_|___| https://github.com/nlohmann/json |_____|_____|_____|_|___| https://github.com/nlohmann/json
Licensed under the MIT License <http://opensource.org/licenses/MIT>. Licensed under the MIT License <http://opensource.org/licenses/MIT>.
@ -65,25 +65,37 @@ TEST_CASE("lexer class")
SECTION("numbers") SECTION("numbers")
{ {
CHECK((json::lexer(reinterpret_cast<const json::lexer::lexer_char_t*>("0"), CHECK((json::lexer(reinterpret_cast<const json::lexer::lexer_char_t*>("0"),
1).scan() == json::lexer::token_type::value_number)); 1).scan() == json::lexer::token_type::value_unsigned));
CHECK((json::lexer(reinterpret_cast<const json::lexer::lexer_char_t*>("1"), CHECK((json::lexer(reinterpret_cast<const json::lexer::lexer_char_t*>("1"),
1).scan() == json::lexer::token_type::value_number)); 1).scan() == json::lexer::token_type::value_unsigned));
CHECK((json::lexer(reinterpret_cast<const json::lexer::lexer_char_t*>("2"), CHECK((json::lexer(reinterpret_cast<const json::lexer::lexer_char_t*>("2"),
1).scan() == json::lexer::token_type::value_number)); 1).scan() == json::lexer::token_type::value_unsigned));
CHECK((json::lexer(reinterpret_cast<const json::lexer::lexer_char_t*>("3"), CHECK((json::lexer(reinterpret_cast<const json::lexer::lexer_char_t*>("3"),
1).scan() == json::lexer::token_type::value_number)); 1).scan() == json::lexer::token_type::value_unsigned));
CHECK((json::lexer(reinterpret_cast<const json::lexer::lexer_char_t*>("4"), CHECK((json::lexer(reinterpret_cast<const json::lexer::lexer_char_t*>("4"),
1).scan() == json::lexer::token_type::value_number)); 1).scan() == json::lexer::token_type::value_unsigned));
CHECK((json::lexer(reinterpret_cast<const json::lexer::lexer_char_t*>("5"), CHECK((json::lexer(reinterpret_cast<const json::lexer::lexer_char_t*>("5"),
1).scan() == json::lexer::token_type::value_number)); 1).scan() == json::lexer::token_type::value_unsigned));
CHECK((json::lexer(reinterpret_cast<const json::lexer::lexer_char_t*>("6"), CHECK((json::lexer(reinterpret_cast<const json::lexer::lexer_char_t*>("6"),
1).scan() == json::lexer::token_type::value_number)); 1).scan() == json::lexer::token_type::value_unsigned));
CHECK((json::lexer(reinterpret_cast<const json::lexer::lexer_char_t*>("7"), CHECK((json::lexer(reinterpret_cast<const json::lexer::lexer_char_t*>("7"),
1).scan() == json::lexer::token_type::value_number)); 1).scan() == json::lexer::token_type::value_unsigned));
CHECK((json::lexer(reinterpret_cast<const json::lexer::lexer_char_t*>("8"), CHECK((json::lexer(reinterpret_cast<const json::lexer::lexer_char_t*>("8"),
1).scan() == json::lexer::token_type::value_number)); 1).scan() == json::lexer::token_type::value_unsigned));
CHECK((json::lexer(reinterpret_cast<const json::lexer::lexer_char_t*>("9"), CHECK((json::lexer(reinterpret_cast<const json::lexer::lexer_char_t*>("9"),
1).scan() == json::lexer::token_type::value_number)); 1).scan() == json::lexer::token_type::value_unsigned));
CHECK((json::lexer(reinterpret_cast<const json::lexer::lexer_char_t*>("-0"),
2).scan() == json::lexer::token_type::value_integer));
CHECK((json::lexer(reinterpret_cast<const json::lexer::lexer_char_t*>("-1"),
2).scan() == json::lexer::token_type::value_integer));
CHECK((json::lexer(reinterpret_cast<const json::lexer::lexer_char_t*>("1.1"),
3).scan() == json::lexer::token_type::value_float));
CHECK((json::lexer(reinterpret_cast<const json::lexer::lexer_char_t*>("-1.1"),
4).scan() == json::lexer::token_type::value_float));
CHECK((json::lexer(reinterpret_cast<const json::lexer::lexer_char_t*>("1E10"),
4).scan() == json::lexer::token_type::value_float));
} }
SECTION("whitespace") SECTION("whitespace")
@ -109,7 +121,9 @@ TEST_CASE("lexer class")
CHECK((json::lexer::token_type_name(json::lexer::token_type::literal_false) == "false literal")); CHECK((json::lexer::token_type_name(json::lexer::token_type::literal_false) == "false literal"));
CHECK((json::lexer::token_type_name(json::lexer::token_type::literal_null) == "null literal")); CHECK((json::lexer::token_type_name(json::lexer::token_type::literal_null) == "null literal"));
CHECK((json::lexer::token_type_name(json::lexer::token_type::value_string) == "string literal")); CHECK((json::lexer::token_type_name(json::lexer::token_type::value_string) == "string literal"));
CHECK((json::lexer::token_type_name(json::lexer::token_type::value_number) == "number literal")); CHECK((json::lexer::token_type_name(json::lexer::token_type::value_unsigned) == "number literal"));
CHECK((json::lexer::token_type_name(json::lexer::token_type::value_integer) == "number literal"));
CHECK((json::lexer::token_type_name(json::lexer::token_type::value_float) == "number literal"));
CHECK((json::lexer::token_type_name(json::lexer::token_type::begin_array) == "'['")); CHECK((json::lexer::token_type_name(json::lexer::token_type::begin_array) == "'['"));
CHECK((json::lexer::token_type_name(json::lexer::token_type::begin_object) == "'{'")); CHECK((json::lexer::token_type_name(json::lexer::token_type::begin_object) == "'{'"));
CHECK((json::lexer::token_type_name(json::lexer::token_type::end_array) == "']'")); CHECK((json::lexer::token_type_name(json::lexer::token_type::end_array) == "']'"));

View file

@ -1,7 +1,7 @@
/* /*
__ _____ _____ _____ __ _____ _____ _____
__| | __| | | | JSON for Modern C++ (test suite) __| | __| | | | JSON for Modern C++ (test suite)
| | |__ | | | | | | version 2.1.0 | | |__ | | | | | | version 2.1.1
|_____|_____|_____|_|___| https://github.com/nlohmann/json |_____|_____|_____|_|___| https://github.com/nlohmann/json
Licensed under the MIT License <http://opensource.org/licenses/MIT>. Licensed under the MIT License <http://opensource.org/licenses/MIT>.
@ -101,6 +101,7 @@ TEST_CASE("parser class")
CHECK_THROWS_WITH(json::parser("\"\b\"").parse(), "parse error - unexpected '\"'"); CHECK_THROWS_WITH(json::parser("\"\b\"").parse(), "parse error - unexpected '\"'");
// improve code coverage // improve code coverage
CHECK_THROWS_AS(json::parser("\uFF01").parse(), std::invalid_argument); CHECK_THROWS_AS(json::parser("\uFF01").parse(), std::invalid_argument);
CHECK_THROWS_AS(json::parser("[-4:1,]").parse(), std::invalid_argument);
// unescaped control characters // unescaped control characters
CHECK_THROWS_AS(json::parser("\"\x00\"").parse(), std::invalid_argument); CHECK_THROWS_AS(json::parser("\"\x00\"").parse(), std::invalid_argument);
CHECK_THROWS_AS(json::parser("\"\x01\"").parse(), std::invalid_argument); CHECK_THROWS_AS(json::parser("\"\x01\"").parse(), std::invalid_argument);
@ -269,6 +270,11 @@ TEST_CASE("parser class")
} }
} }
SECTION("overflow")
{
CHECK(json::parser("1.18973e+4932").parse() == json());
}
SECTION("invalid numbers") SECTION("invalid numbers")
{ {
CHECK_THROWS_AS(json::parser("01").parse(), std::invalid_argument); CHECK_THROWS_AS(json::parser("01").parse(), std::invalid_argument);
@ -293,7 +299,9 @@ TEST_CASE("parser class")
CHECK_THROWS_AS(json::parser("+0").parse(), std::invalid_argument); CHECK_THROWS_AS(json::parser("+0").parse(), std::invalid_argument);
CHECK_THROWS_WITH(json::parser("01").parse(), CHECK_THROWS_WITH(json::parser("01").parse(),
"parse error - unexpected number literal; expected end of input"); "parse error - unexpected '01'");
CHECK_THROWS_WITH(json::parser("-01").parse(),
"parse error - unexpected '-01'");
CHECK_THROWS_WITH(json::parser("--1").parse(), "parse error - unexpected '-'"); CHECK_THROWS_WITH(json::parser("--1").parse(), "parse error - unexpected '-'");
CHECK_THROWS_WITH(json::parser("1.").parse(), CHECK_THROWS_WITH(json::parser("1.").parse(),
"parse error - unexpected '.'; expected end of input"); "parse error - unexpected '.'; expected end of input");
@ -605,7 +613,7 @@ TEST_CASE("parser class")
// test case to make sure the callback is properly evaluated after reading a key // test case to make sure the callback is properly evaluated after reading a key
{ {
json::parser_callback_t cb = [](int depth, json::parse_event_t event, json & parsed) json::parser_callback_t cb = [](int, json::parse_event_t event, json&)
{ {
if (event == json::parse_event_t::key) if (event == json::parse_event_t::key)
{ {

View file

@ -1,7 +1,7 @@
/* /*
__ _____ _____ _____ __ _____ _____ _____
__| | __| | | | JSON for Modern C++ (test suite) __| | __| | | | JSON for Modern C++ (test suite)
| | |__ | | | | | | version 2.1.0 | | |__ | | | | | | version 2.1.1
|_____|_____|_____|_|___| https://github.com/nlohmann/json |_____|_____|_____|_|___| https://github.com/nlohmann/json
Licensed under the MIT License <http://opensource.org/licenses/MIT>. Licensed under the MIT License <http://opensource.org/licenses/MIT>.

View file

@ -1,7 +1,7 @@
/* /*
__ _____ _____ _____ __ _____ _____ _____
__| | __| | | | JSON for Modern C++ (test suite) __| | __| | | | JSON for Modern C++ (test suite)
| | |__ | | | | | | version 2.1.0 | | |__ | | | | | | version 2.1.1
|_____|_____|_____|_|___| https://github.com/nlohmann/json |_____|_____|_____|_|___| https://github.com/nlohmann/json
Licensed under the MIT License <http://opensource.org/licenses/MIT>. Licensed under the MIT License <http://opensource.org/licenses/MIT>.
@ -72,8 +72,8 @@ TEST_CASE("concepts")
// X::size_type must return an unsigned integer // X::size_type must return an unsigned integer
CHECK((std::is_unsigned<json::size_type>::value)); CHECK((std::is_unsigned<json::size_type>::value));
// X::size_type can represent any non-negative value of X::difference_type // X::size_type can represent any non-negative value of X::difference_type
CHECK(std::numeric_limits<json::difference_type>::max() <= CHECK(static_cast<size_t>(std::numeric_limits<json::difference_type>::max()) <=
std::numeric_limits<json::size_type>::max()); static_cast<size_t>(std::numeric_limits<json::size_type>::max()));
// the expression "X u" has the post-condition "u.empty()" // the expression "X u" has the post-condition "u.empty()"
{ {

View file

@ -1,7 +1,7 @@
/* /*
__ _____ _____ _____ __ _____ _____ _____
__| | __| | | | JSON for Modern C++ (test suite) __| | __| | | | JSON for Modern C++ (test suite)
| | |__ | | | | | | version 2.1.0 | | |__ | | | | | | version 2.1.1
|_____|_____|_____|_|___| https://github.com/nlohmann/json |_____|_____|_____|_|___| https://github.com/nlohmann/json
Licensed under the MIT License <http://opensource.org/licenses/MIT>. Licensed under the MIT License <http://opensource.org/licenses/MIT>.
@ -725,7 +725,7 @@ TEST_CASE("constructors")
SECTION("long double") SECTION("long double")
{ {
long double n = 42.23; long double n = 42.23l;
json j(n); json j(n);
CHECK(j.type() == json::value_t::number_float); CHECK(j.type() == json::value_t::number_float);
CHECK(j.m_value.number_float == Approx(j_reference.m_value.number_float)); CHECK(j.m_value.number_float == Approx(j_reference.m_value.number_float));

View file

@ -1,7 +1,7 @@
/* /*
__ _____ _____ _____ __ _____ _____ _____
__| | __| | | | JSON for Modern C++ (test suite) __| | __| | | | JSON for Modern C++ (test suite)
| | |__ | | | | | | version 2.1.0 | | |__ | | | | | | version 2.1.1
|_____|_____|_____|_|___| https://github.com/nlohmann/json |_____|_____|_____|_|___| https://github.com/nlohmann/json
Licensed under the MIT License <http://opensource.org/licenses/MIT>. Licensed under the MIT License <http://opensource.org/licenses/MIT>.

View file

@ -1,7 +1,7 @@
/* /*
__ _____ _____ _____ __ _____ _____ _____
__| | __| | | | JSON for Modern C++ (test suite) __| | __| | | | JSON for Modern C++ (test suite)
| | |__ | | | | | | version 2.1.0 | | |__ | | | | | | version 2.1.1
|_____|_____|_____|_|___| https://github.com/nlohmann/json |_____|_____|_____|_|___| https://github.com/nlohmann/json
Licensed under the MIT License <http://opensource.org/licenses/MIT>. Licensed under the MIT License <http://opensource.org/licenses/MIT>.

View file

@ -1,7 +1,7 @@
/* /*
__ _____ _____ _____ __ _____ _____ _____
__| | __| | | | JSON for Modern C++ (test suite) __| | __| | | | JSON for Modern C++ (test suite)
| | |__ | | | | | | version 2.1.0 | | |__ | | | | | | version 2.1.1
|_____|_____|_____|_|___| https://github.com/nlohmann/json |_____|_____|_____|_|___| https://github.com/nlohmann/json
Licensed under the MIT License <http://opensource.org/licenses/MIT>. Licensed under the MIT License <http://opensource.org/licenses/MIT>.
@ -972,14 +972,14 @@ TEST_CASE("value conversion")
auto m5 = j5.get<std::list<std::string>>(); auto m5 = j5.get<std::list<std::string>>();
} }
//SECTION("std::forward_list") SECTION("std::forward_list")
//{ {
// auto m1 = j1.get<std::forward_list<int>>(); auto m1 = j1.get<std::forward_list<int>>();
// auto m2 = j2.get<std::forward_list<unsigned int>>(); auto m2 = j2.get<std::forward_list<unsigned int>>();
// auto m3 = j3.get<std::forward_list<double>>(); auto m3 = j3.get<std::forward_list<double>>();
// auto m4 = j4.get<std::forward_list<bool>>(); auto m4 = j4.get<std::forward_list<bool>>();
// auto m5 = j5.get<std::forward_list<std::string>>(); auto m5 = j5.get<std::forward_list<std::string>>();
//} }
SECTION("std::vector") SECTION("std::vector")
{ {

View file

@ -1,7 +1,7 @@
/* /*
__ _____ _____ _____ __ _____ _____ _____
__| | __| | | | JSON for Modern C++ (test suite) __| | __| | | | JSON for Modern C++ (test suite)
| | |__ | | | | | | version 2.1.0 | | |__ | | | | | | version 2.1.1
|_____|_____|_____|_|___| https://github.com/nlohmann/json |_____|_____|_____|_|___| https://github.com/nlohmann/json
Licensed under the MIT License <http://opensource.org/licenses/MIT>. Licensed under the MIT License <http://opensource.org/licenses/MIT>.

View file

@ -1,7 +1,7 @@
/* /*
__ _____ _____ _____ __ _____ _____ _____
__| | __| | | | JSON for Modern C++ (test suite) __| | __| | | | JSON for Modern C++ (test suite)
| | |__ | | | | | | version 2.1.0 | | |__ | | | | | | version 2.1.1
|_____|_____|_____|_|___| https://github.com/nlohmann/json |_____|_____|_____|_|___| https://github.com/nlohmann/json
Licensed under the MIT License <http://opensource.org/licenses/MIT>. Licensed under the MIT License <http://opensource.org/licenses/MIT>.

View file

@ -1,7 +1,7 @@
/* /*
__ _____ _____ _____ __ _____ _____ _____
__| | __| | | | JSON for Modern C++ (test suite) __| | __| | | | JSON for Modern C++ (test suite)
| | |__ | | | | | | version 2.1.0 | | |__ | | | | | | version 2.1.1
|_____|_____|_____|_|___| https://github.com/nlohmann/json |_____|_____|_____|_|___| https://github.com/nlohmann/json
Licensed under the MIT License <http://opensource.org/licenses/MIT>. Licensed under the MIT License <http://opensource.org/licenses/MIT>.

View file

@ -1,7 +1,7 @@
/* /*
__ _____ _____ _____ __ _____ _____ _____
__| | __| | | | JSON for Modern C++ (test suite) __| | __| | | | JSON for Modern C++ (test suite)
| | |__ | | | | | | version 2.1.0 | | |__ | | | | | | version 2.1.1
|_____|_____|_____|_|___| https://github.com/nlohmann/json |_____|_____|_____|_|___| https://github.com/nlohmann/json
Licensed under the MIT License <http://opensource.org/licenses/MIT>. Licensed under the MIT License <http://opensource.org/licenses/MIT>.
@ -250,17 +250,31 @@ TEST_CASE("object inspection")
ss.str(std::string()); ss.str(std::string());
// use stringstream for JSON serialization // use stringstream for JSON serialization
json j_number = 3.141592653589793; json j_number = 3.14159265358979;
ss << j_number; ss << j_number;
// check that precision has been overridden during serialization // check that precision has been overridden during serialization
CHECK(ss.str() == "3.141592653589793"); CHECK(ss.str() == "3.14159265358979");
// check that precision has been restored // check that precision has been restored
CHECK(ss.precision() == 3); CHECK(ss.precision() == 3);
} }
} }
SECTION("round trips")
{
for (const auto& s :
{"3.141592653589793", "1000000000000000010E5"
})
{
json j1 = json::parse(s);
std::string s1 = j1.dump();
json j2 = json::parse(s1);
std::string s2 = j2.dump();
CHECK(s1 == s2);
}
}
SECTION("return the type of the object (explicit)") SECTION("return the type of the object (explicit)")
{ {
SECTION("null") SECTION("null")

View file

@ -1,7 +1,7 @@
/* /*
__ _____ _____ _____ __ _____ _____ _____
__| | __| | | | JSON for Modern C++ (test suite) __| | __| | | | JSON for Modern C++ (test suite)
| | |__ | | | | | | version 2.1.0 | | |__ | | | | | | version 2.1.1
|_____|_____|_____|_|___| https://github.com/nlohmann/json |_____|_____|_____|_|___| https://github.com/nlohmann/json
Licensed under the MIT License <http://opensource.org/licenses/MIT>. Licensed under the MIT License <http://opensource.org/licenses/MIT>.

View file

@ -1,7 +1,7 @@
/* /*
__ _____ _____ _____ __ _____ _____ _____
__| | __| | | | JSON for Modern C++ (test suite) __| | __| | | | JSON for Modern C++ (test suite)
| | |__ | | | | | | version 2.1.0 | | |__ | | | | | | version 2.1.1
|_____|_____|_____|_|___| https://github.com/nlohmann/json |_____|_____|_____|_|___| https://github.com/nlohmann/json
Licensed under the MIT License <http://opensource.org/licenses/MIT>. Licensed under the MIT License <http://opensource.org/licenses/MIT>.

View file

@ -1,7 +1,7 @@
/* /*
__ _____ _____ _____ __ _____ _____ _____
__| | __| | | | JSON for Modern C++ (test suite) __| | __| | | | JSON for Modern C++ (test suite)
| | |__ | | | | | | version 2.1.0 | | |__ | | | | | | version 2.1.1
|_____|_____|_____|_|___| https://github.com/nlohmann/json |_____|_____|_____|_|___| https://github.com/nlohmann/json
Licensed under the MIT License <http://opensource.org/licenses/MIT>. Licensed under the MIT License <http://opensource.org/licenses/MIT>.

View file

@ -1,7 +1,7 @@
/* /*
__ _____ _____ _____ __ _____ _____ _____
__| | __| | | | JSON for Modern C++ (test suite) __| | __| | | | JSON for Modern C++ (test suite)
| | |__ | | | | | | version 2.1.0 | | |__ | | | | | | version 2.1.1
|_____|_____|_____|_|___| https://github.com/nlohmann/json |_____|_____|_____|_|___| https://github.com/nlohmann/json
Licensed under the MIT License <http://opensource.org/licenses/MIT>. Licensed under the MIT License <http://opensource.org/licenses/MIT>.

View file

@ -1,7 +1,7 @@
/* /*
__ _____ _____ _____ __ _____ _____ _____
__| | __| | | | JSON for Modern C++ (test suite) __| | __| | | | JSON for Modern C++ (test suite)
| | |__ | | | | | | version 2.1.0 | | |__ | | | | | | version 2.1.1
|_____|_____|_____|_|___| https://github.com/nlohmann/json |_____|_____|_____|_|___| https://github.com/nlohmann/json
Licensed under the MIT License <http://opensource.org/licenses/MIT>. Licensed under the MIT License <http://opensource.org/licenses/MIT>.

View file

@ -1,7 +1,7 @@
/* /*
__ _____ _____ _____ __ _____ _____ _____
__| | __| | | | JSON for Modern C++ (test suite) __| | __| | | | JSON for Modern C++ (test suite)
| | |__ | | | | | | version 2.1.0 | | |__ | | | | | | version 2.1.1
|_____|_____|_____|_|___| https://github.com/nlohmann/json |_____|_____|_____|_|___| https://github.com/nlohmann/json
Licensed under the MIT License <http://opensource.org/licenses/MIT>. Licensed under the MIT License <http://opensource.org/licenses/MIT>.
@ -36,5 +36,12 @@ TEST_CASE("version information")
SECTION("version()") SECTION("version()")
{ {
CHECK(json::meta()["name"] == "JSON for Modern C++"); CHECK(json::meta()["name"] == "JSON for Modern C++");
CHECK(json::meta()["version"] == json(
{
{"string", "2.1.1"},
{"major", 2},
{"minor", 1},
{"patch", 1}
}));
} }
} }

View file

@ -1,7 +1,7 @@
/* /*
__ _____ _____ _____ __ _____ _____ _____
__| | __| | | | JSON for Modern C++ (test suite) __| | __| | | | JSON for Modern C++ (test suite)
| | |__ | | | | | | version 2.1.0 | | |__ | | | | | | version 2.1.1
|_____|_____|_____|_|___| https://github.com/nlohmann/json |_____|_____|_____|_|___| https://github.com/nlohmann/json
Licensed under the MIT License <http://opensource.org/licenses/MIT>. Licensed under the MIT License <http://opensource.org/licenses/MIT>.

View file

@ -1,7 +1,7 @@
/* /*
__ _____ _____ _____ __ _____ _____ _____
__| | __| | | | JSON for Modern C++ (test suite) __| | __| | | | JSON for Modern C++ (test suite)
| | |__ | | | | | | version 2.1.0 | | |__ | | | | | | version 2.1.1
|_____|_____|_____|_|___| https://github.com/nlohmann/json |_____|_____|_____|_|___| https://github.com/nlohmann/json
Licensed under the MIT License <http://opensource.org/licenses/MIT>. Licensed under the MIT License <http://opensource.org/licenses/MIT>.
@ -342,7 +342,7 @@ TEST_CASE("MessagePack")
const auto result = json::to_msgpack(j); const auto result = json::to_msgpack(j);
CHECK(result == expected); CHECK(result == expected);
int16_t restored = (result[1] << 8) + result[2]; int16_t restored = static_cast<int16_t>((result[1] << 8) + result[2]);
CHECK(restored == -9263); CHECK(restored == -9263);
// roundtrip // roundtrip
@ -374,7 +374,7 @@ TEST_CASE("MessagePack")
// check individual bytes // check individual bytes
CHECK(result[0] == 0xd1); 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); CHECK(restored == i);
// roundtrip // roundtrip
@ -389,7 +389,7 @@ TEST_CASE("MessagePack")
numbers.push_back(-65536); numbers.push_back(-65536);
numbers.push_back(-77777); numbers.push_back(-77777);
numbers.push_back(-1048576); numbers.push_back(-1048576);
numbers.push_back(-2147483648); numbers.push_back(-2147483648ll);
for (auto i : numbers) for (auto i : numbers)
{ {
CAPTURE(i); CAPTURE(i);
@ -1039,6 +1039,10 @@ TEST_CASE("single MessagePack roundtrip")
// compare parsed JSON values // compare parsed JSON values
CHECK(j1 == j2); CHECK(j1 == j2);
// check with different start index
packed.insert(packed.begin(), 5, 0xff);
CHECK(j1 == json::from_msgpack(packed, 5));
} }
} }

View file

@ -1,7 +1,7 @@
/* /*
__ _____ _____ _____ __ _____ _____ _____
__| | __| | | | JSON for Modern C++ (test suite) __| | __| | | | JSON for Modern C++ (test suite)
| | |__ | | | | | | version 2.1.0 | | |__ | | | | | | version 2.1.1
|_____|_____|_____|_|___| https://github.com/nlohmann/json |_____|_____|_____|_|___| https://github.com/nlohmann/json
Licensed under the MIT License <http://opensource.org/licenses/MIT>. Licensed under the MIT License <http://opensource.org/licenses/MIT>.

View file

@ -1,7 +1,7 @@
/* /*
__ _____ _____ _____ __ _____ _____ _____
__| | __| | | | JSON for Modern C++ (test suite) __| | __| | | | JSON for Modern C++ (test suite)
| | |__ | | | | | | version 2.1.0 | | |__ | | | | | | version 2.1.1
|_____|_____|_____|_|___| https://github.com/nlohmann/json |_____|_____|_____|_|___| https://github.com/nlohmann/json
Licensed under the MIT License <http://opensource.org/licenses/MIT>. Licensed under the MIT License <http://opensource.org/licenses/MIT>.

View file

@ -1,7 +1,7 @@
/* /*
__ _____ _____ _____ __ _____ _____ _____
__| | __| | | | JSON for Modern C++ (test suite) __| | __| | | | JSON for Modern C++ (test suite)
| | |__ | | | | | | version 2.1.0 | | |__ | | | | | | version 2.1.1
|_____|_____|_____|_|___| https://github.com/nlohmann/json |_____|_____|_____|_|___| https://github.com/nlohmann/json
Licensed under the MIT License <http://opensource.org/licenses/MIT>. Licensed under the MIT License <http://opensource.org/licenses/MIT>.
@ -163,7 +163,7 @@ TEST_CASE("README", "[hide]")
j.clear(); // the array is empty again j.clear(); // the array is empty again
// comparison // comparison
j == "[\"foo\", 1, true]"_json; // true bool x = (j == "[\"foo\", 1, true]"_json); // true
// create an object // create an object
json o; json o;

View file

@ -1,7 +1,7 @@
/* /*
__ _____ _____ _____ __ _____ _____ _____
__| | __| | | | JSON for Modern C++ (test suite) __| | __| | | | JSON for Modern C++ (test suite)
| | |__ | | | | | | version 2.1.0 | | |__ | | | | | | version 2.1.1
|_____|_____|_____|_|___| https://github.com/nlohmann/json |_____|_____|_____|_|___| https://github.com/nlohmann/json
Licensed under the MIT License <http://opensource.org/licenses/MIT>. Licensed under the MIT License <http://opensource.org/licenses/MIT>.

View file

@ -1,7 +1,7 @@
/* /*
__ _____ _____ _____ __ _____ _____ _____
__| | __| | | | JSON for Modern C++ (test suite) __| | __| | | | JSON for Modern C++ (test suite)
| | |__ | | | | | | version 2.1.0 | | |__ | | | | | | version 2.1.1
|_____|_____|_____|_|___| https://github.com/nlohmann/json |_____|_____|_____|_|___| https://github.com/nlohmann/json
Licensed under the MIT License <http://opensource.org/licenses/MIT>. Licensed under the MIT License <http://opensource.org/licenses/MIT>.
@ -350,8 +350,8 @@ TEST_CASE("regression tests")
// double // double
nlohmann::basic_json<std::map, std::vector, std::string, bool, int64_t, uint64_t, double> j_double = nlohmann::basic_json<std::map, std::vector, std::string, bool, int64_t, uint64_t, double> j_double =
1.23e35f; 1.23e35;
CHECK(j_double.get<double>() == 1.23e35f); CHECK(j_double.get<double>() == 1.23e35);
// long double // long double
nlohmann::basic_json<std::map, std::vector, std::string, bool, int64_t, uint64_t, long double> nlohmann::basic_json<std::map, std::vector, std::string, bool, int64_t, uint64_t, long double>
@ -361,8 +361,8 @@ TEST_CASE("regression tests")
SECTION("issue #228 - double values are serialized with commas as decimal points") SECTION("issue #228 - double values are serialized with commas as decimal points")
{ {
json j1a = 23.42; json j1a = 2312.42;
json j1b = json::parse("23.42"); json j1b = json::parse("2312.42");
json j2a = 2342e-2; json j2a = 2342e-2;
//issue #230 //issue #230
@ -380,33 +380,88 @@ TEST_CASE("regression tests")
{ {
return ','; return ',';
} }
char do_thousands_sep() const
{
return '.';
}
std::string do_grouping() const
{
return "\03";
}
}; };
// change locale to mess with decimal points // change locale to mess with decimal points
std::locale::global(std::locale(std::locale(), new CommaDecimalSeparator)); auto orig_locale = std::locale::global(std::locale(std::locale(), new CommaDecimalSeparator));
CHECK(j1a.dump() == "23.42"); CHECK(j1a.dump() == "2312.42");
CHECK(j1b.dump() == "23.42"); CHECK(j1b.dump() == "2312.42");
// check if locale is properly reset // check if locale is properly reset
std::stringstream ss; std::stringstream ss;
ss.imbue(std::locale(std::locale(), new CommaDecimalSeparator)); ss.imbue(std::locale(std::locale(), new CommaDecimalSeparator));
ss << 47.11; ss << 4712.11;
CHECK(ss.str() == "47,11"); CHECK(ss.str() == "4.712,11");
ss << j1a; ss << j1a;
CHECK(ss.str() == "47,1123.42"); CHECK(ss.str() == "4.712,112312.42");
ss << 47.11; ss << 47.11;
CHECK(ss.str() == "47,1123.4247,11"); CHECK(ss.str() == "4.712,112312.4247,11");
CHECK(j2a.dump() == "23.42"); CHECK(j2a.dump() == "23.42");
//issue #230 //issue #230
//CHECK(j2b.dump() == "23.42"); //CHECK(j2b.dump() == "23.42");
CHECK(j3a.dump() == "10000"); CHECK(j3a.dump() == "10000.0");
CHECK(j3b.dump() == "10000"); CHECK(j3b.dump() == "10000.0");
CHECK(j3c.dump() == "10000"); CHECK(j3c.dump() == "10000.0");
//CHECK(j3b.dump() == "1E04"); // roundtrip error //CHECK(j3b.dump() == "1E04"); // roundtrip error
//CHECK(j3c.dump() == "1e04"); // roundtrip error //CHECK(j3c.dump() == "1e04"); // roundtrip error
std::locale::global(orig_locale);
}
SECTION("issue #378 - locale-independent num-to-str")
{
setlocale(LC_NUMERIC, "de_DE.UTF-8");
// Verify that snprintf uses special decimal and grouping characters.
// Disabled, because can't trigger locale-specific behavior in AppVeyor
#ifndef _MSC_VER
{
std::array<char, 64> buf;
std::snprintf(buf.data(), buf.size(), "%.2f", 12345.67);
CHECK(strcmp(buf.data(), "12345,67") == 0);
}
#endif
// verify that dumped correctly with '.' and no grouping
const json j1 = 12345.67;
CHECK(json(12345.67).dump() == "12345.67");
setlocale(LC_NUMERIC, "C");
}
SECTION("issue #379 - locale-independent str-to-num")
{
setlocale(LC_NUMERIC, "de_DE.UTF-8");
// disabled, because locale-specific beharivor is not
// triggered in AppVeyor for some reason
#ifndef _MSC_VER
{
// verify that strtod now uses commas as decimal-separator
CHECK(std::strtod("3,14", nullptr) == 3.14);
// verify that strtod does not understand dots as decimal separator
CHECK(std::strtod("3.14", nullptr) == 3);
}
#endif
// verify that parsed correctly despite using strtod internally
CHECK(json::parse("3.14").get<double>() == 3.14);
// check a different code path
CHECK(json::parse("1.000000000000000000000000000000000000000000000000000000000000000000000000").get<double>() == 1.0);
} }
SECTION("issue #233 - Can't use basic_json::iterator as a base iterator for std::move_iterator") SECTION("issue #233 - Can't use basic_json::iterator as a base iterator for std::move_iterator")
@ -586,7 +641,7 @@ TEST_CASE("regression tests")
CHECK_THROWS_AS(json::from_msgpack(vec1), std::out_of_range); CHECK_THROWS_AS(json::from_msgpack(vec1), std::out_of_range);
// more test cases for MessagePack // more test cases for MessagePack
for (uint8_t b : for (auto b :
{ {
0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f, // fixmap 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f, // fixmap
0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f, // fixarray 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f, // fixarray
@ -594,12 +649,12 @@ TEST_CASE("regression tests")
0xb0, 0xb1, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7, 0xb8, 0xb9, 0xba, 0xbb, 0xbc, 0xbd, 0xbe, 0xbf 0xb0, 0xb1, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7, 0xb8, 0xb9, 0xba, 0xbb, 0xbc, 0xbd, 0xbe, 0xbf
}) })
{ {
std::vector<uint8_t> vec(1, b); std::vector<uint8_t> vec(1, static_cast<uint8_t>(b));
CHECK_THROWS_AS(json::from_msgpack(vec), std::out_of_range); CHECK_THROWS_AS(json::from_msgpack(vec), std::out_of_range);
} }
// more test cases for CBOR // more test cases for CBOR
for (uint8_t b : for (auto b :
{ {
0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f,
0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, // UTF-8 string 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, // UTF-8 string
@ -609,7 +664,7 @@ TEST_CASE("regression tests")
0xb0, 0xb1, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7 // map 0xb0, 0xb1, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7 // map
}) })
{ {
std::vector<uint8_t> vec(1, b); std::vector<uint8_t> vec(1, static_cast<uint8_t>(b));
CHECK_THROWS_AS(json::from_cbor(vec), std::out_of_range); CHECK_THROWS_AS(json::from_cbor(vec), std::out_of_range);
} }
@ -672,6 +727,24 @@ TEST_CASE("regression tests")
CHECK_THROWS_AS(json::from_cbor(vec3), std::out_of_range); CHECK_THROWS_AS(json::from_cbor(vec3), std::out_of_range);
} }
SECTION("issue #414 - compare with literal 0)")
{
#define CHECK_TYPE(v) \
CHECK((json(v) == v));\
CHECK((v == json(v)));\
CHECK_FALSE((json(v) != v));\
CHECK_FALSE((v != json(v)));
CHECK_TYPE(nullptr);
CHECK_TYPE(0);
CHECK_TYPE(0u);
CHECK_TYPE(0L);
CHECK_TYPE(0.0);
CHECK_TYPE("");
#undef CHECK_TYPE
}
SECTION("issue #416 - Use-of-uninitialized-value (OSS-Fuzz issue 377)") SECTION("issue #416 - Use-of-uninitialized-value (OSS-Fuzz issue 377)")
{ {
// original test case // original test case
@ -698,4 +771,25 @@ TEST_CASE("regression tests")
}; };
CHECK_THROWS_AS(json::from_cbor(vec2), std::out_of_range); CHECK_THROWS_AS(json::from_cbor(vec2), std::out_of_range);
} }
SECTION("issue #452 - Heap-buffer-overflow (OSS-Fuzz issue 585)")
{
std::vector<uint8_t> vec = {'-', '0', '1', '2', '2', '7', '4'};
CHECK_THROWS_AS(json::parse(vec), std::invalid_argument);
}
SECTION("issue #454 - doubles are printed as integers")
{
json j = R"({"bool_value":true,"double_value":2.0,"int_value":10,"level1":{"list_value":[3,"hi",false],"tmp":5.0},"string_value":"hello"})"_json;
CHECK(j["double_value"].is_number_float());
}
SECTION("issue #465 - roundtrip error while parsing 1000000000000000010E5")
{
json j1 = json::parse("1000000000000000010E5");
std::string s1 = j1.dump();
json j2 = json::parse(s1);
std::string s2 = j2.dump();
CHECK(s1 == s2);
}
} }

View file

@ -1,7 +1,7 @@
/* /*
__ _____ _____ _____ __ _____ _____ _____
__| | __| | | | JSON for Modern C++ (test suite) __| | __| | | | JSON for Modern C++ (test suite)
| | |__ | | | | | | version 2.1.0 | | |__ | | | | | | version 2.1.1
|_____|_____|_____|_|___| https://github.com/nlohmann/json |_____|_____|_____|_|___| https://github.com/nlohmann/json
Licensed under the MIT License <http://opensource.org/licenses/MIT>. Licensed under the MIT License <http://opensource.org/licenses/MIT>.

View file

@ -1,7 +1,7 @@
/* /*
__ _____ _____ _____ __ _____ _____ _____
__| | __| | | | JSON for Modern C++ (test suite) __| | __| | | | JSON for Modern C++ (test suite)
| | |__ | | | | | | version 2.1.0 | | |__ | | | | | | version 2.1.1
|_____|_____|_____|_|___| https://github.com/nlohmann/json |_____|_____|_____|_|___| https://github.com/nlohmann/json
Licensed under the MIT License <http://opensource.org/licenses/MIT>. Licensed under the MIT License <http://opensource.org/licenses/MIT>.
@ -816,13 +816,58 @@ TEST_CASE("nst's JSONTestSuite")
} }
} }
std::string trim(const std::string& str);
// from http://stackoverflow.com/a/25829178/266378
std::string trim(const std::string& str)
{
size_t first = str.find_first_not_of(' ');
if (std::string::npos == first)
{
return str;
}
size_t last = str.find_last_not_of(' ');
return str.substr(first, (last - first + 1));
}
TEST_CASE("Big List of Naughty Strings") TEST_CASE("Big List of Naughty Strings")
{ {
// test from https://github.com/minimaxir/big-list-of-naughty-strings // test from https://github.com/minimaxir/big-list-of-naughty-strings
SECTION("blns.json") SECTION("parsing blns.json")
{ {
std::ifstream f("test/data/big-list-of-naughty-strings/blns.json"); std::ifstream f("test/data/big-list-of-naughty-strings/blns.json");
json j; json j;
CHECK_NOTHROW(j << f); CHECK_NOTHROW(j << f);
} }
// check if parsed strings roundtrip
// https://www.reddit.com/r/cpp/comments/5qpbie/json_form_modern_c_version_210/dd12mpq/
SECTION("roundtripping")
{
std::ifstream f("test/data/big-list-of-naughty-strings/blns.json");
while (not f.eof())
{
// read line
std::string line;
getline(f, line);
// trim whitespace
line = trim(line);
// remove trailing comma
line = line.substr(0, line.find_last_of(","));
// discard lines without at least two characters (quotes)
if (line.size() < 2)
{
continue;
}
// check roundtrip
CAPTURE(line);
json j = json::parse(line);
CHECK(j.dump() == line);
}
}
} }

View file

@ -1,7 +1,7 @@
/* /*
__ _____ _____ _____ __ _____ _____ _____
__| | __| | | | JSON for Modern C++ (test suite) __| | __| | | | JSON for Modern C++ (test suite)
| | |__ | | | | | | version 2.1.0 | | |__ | | | | | | version 2.1.1
|_____|_____|_____|_|___| https://github.com/nlohmann/json |_____|_____|_____|_|___| https://github.com/nlohmann/json
Licensed under the MIT License <http://opensource.org/licenses/MIT>. Licensed under the MIT License <http://opensource.org/licenses/MIT>.
@ -26,16 +26,17 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE. SOFTWARE.
*/ */
#include <array>
#include <map>
#include <string>
#include <memory>
#include "catch.hpp" #include "catch.hpp"
#include "json.hpp" #include "json.hpp"
using nlohmann::json; using nlohmann::json;
#include <array>
#include <map>
#include <string>
#include <memory>
namespace udt namespace udt
{ {
enum class country enum class country

View file

@ -1,7 +1,7 @@
/* /*
__ _____ _____ _____ __ _____ _____ _____
__| | __| | | | JSON for Modern C++ (test suite) __| | __| | | | JSON for Modern C++ (test suite)
| | |__ | | | | | | version 2.1.0 | | |__ | | | | | | version 2.1.1
|_____|_____|_____|_|___| https://github.com/nlohmann/json |_____|_____|_____|_|___| https://github.com/nlohmann/json
Licensed under the MIT License <http://opensource.org/licenses/MIT>. Licensed under the MIT License <http://opensource.org/licenses/MIT>.

View file

@ -1,7 +1,7 @@
/* /*
__ _____ _____ _____ __ _____ _____ _____
__| | __| | | | JSON for Modern C++ (test suite) __| | __| | | | JSON for Modern C++ (test suite)
| | |__ | | | | | | version 2.1.0 | | |__ | | | | | | version 2.1.1
|_____|_____|_____|_|___| https://github.com/nlohmann/json |_____|_____|_____|_|___| https://github.com/nlohmann/json
Licensed under the MIT License <http://opensource.org/licenses/MIT>. Licensed under the MIT License <http://opensource.org/licenses/MIT>.

File diff suppressed because it is too large Load diff