1
0
mirror of https://github.com/nlohmann/json.git synced 2026-07-29 23:23:02 +04:00

Compare commits

...

94 Commits

Author SHA1 Message Date
Niels Lohmann 9ff0cc0f02 📝 updated documentation 2017-02-25 16:43:15 +01:00
Niels Lohmann 1b5867bdcf 🔀 merge branch 'release/2.1.1' into develop 2017-02-25 16:37:28 +01:00
Niels Lohmann 27c65b860b 🔖 version 2.1.1 2017-02-25 16:34:38 +01:00
Niels Lohmann 0234e53e23 📝 added section on used third-party tools 2017-02-22 20:48:52 +01:00
Niels Lohmann b49ce351eb 💄 fixed some warnings 2017-02-22 20:48:29 +01:00
Niels Lohmann a646c9c599 🔀 merge branch 'cotire' of https://github.com/tusharpm/json into tusharpm-cotire 2017-02-22 19:45:10 +01:00
Niels Lohmann 8cec55a271 🚧 fixed more warnings 2017-02-22 18:14:29 +01:00
Niels Lohmann 345a106d73 💄 cleanup 2017-02-22 16:56:56 +01:00
Niels Lohmann 967f9144d4 🚧 overworked fix for #465 2017-02-21 19:11:34 +01:00
Niels Lohmann 7d14f167b8 🚑 fix for #465 2017-02-20 22:48:27 +01:00
Niels Lohmann b04543ecc5 🎨 fixed newlines 2017-02-20 21:56:10 +01:00
Niels Lohmann 1a6d7f5bca 🚧 try to fix some warnings in MSVC 2017-02-20 18:32:11 +01:00
Niels Lohmann f7075be93a 🐛 reverted change for #464 2017-02-20 18:15:50 +01:00
Niels Lohmann f2dfa09aec 🐛 fix for #464 2017-02-20 18:05:52 +01:00
Niels Lohmann 83a9c60dbd 🔨 refactored code to avoid using strcpy/strlen/strcat (#463) 2017-02-20 17:37:34 +01:00
Niels Lohmann 716485a965 🚧 removed decay (#448) 2017-02-20 16:27:16 +01:00
Niels Lohmann 7a4a16a7db 💄 updated header list 2017-02-20 16:20:45 +01:00
Niels Lohmann 1f72c38861 🚑 fix for #448 2017-02-19 21:26:53 +01:00
Niels Lohmann 83f1d2c81b added start index for from_cbor and from_msgpack (#462) 2017-02-19 21:17:05 +01:00
Niels Lohmann 4151f2d297 added test with thousands_sep 2017-02-19 20:08:01 +01:00
Niels Lohmann 5b53f03e7c Merge branch 'develop' into TurpentineDistillery-feature/locale_independent_num_to_str 2017-02-19 19:24:55 +01:00
Niels Lohmann 9a9d0ba3df 🚧 fixing warning C4293 (#453) 2017-02-19 17:47:20 +01:00
Tushar Maheshwari 5436407b7e 👷 Add cmake logic to Travis config
- get CMake for XCode 8.1 image
2017-02-19 13:38:08 +05:30
Tushar Maheshwari 85ce4d7b53 cmake compile time reduce using cotire
- Add prefix header
  - Include catch.hpp
  - Include json.hpp
    - Replace private with public for all json_unit files
- Move `unit.cpp` to an object library
- cotire issue: strip whitespace from CMAKE_INCLUDE_SYSTEM_FLAG_CXX
2017-02-19 13:35:54 +05:30
Niels Lohmann d1479e47bb 💄 added assertion message 2017-02-18 11:01:03 +01:00
Niels Lohmann 513eb3ab5f 🚧 clean up 2017-02-18 11:00:18 +01:00
Niels Lohmann 0200f2dc62 🚧 fixing warning C4267 (#453) 2017-02-17 19:14:21 +01:00
Niels Lohmann 6408402ad2 🔀 merge #378 (for #362 and #454) 2017-02-16 09:24:45 +01:00
Niels Lohmann 057b1e606b 🔀 merged #415 (fix for #414) 2017-02-16 08:50:20 +01:00
Niels Lohmann 2c17c1b1b2 💄 cleanup 2017-02-16 08:01:01 +01:00
Niels Lohmann 973402c11e 🚧 replaced throws (#440) and _MAX/_MIN macros (#451) 2017-02-15 22:44:18 +01:00
Niels Lohmann b9f3149451 🚑 fix for #452 2017-02-15 21:30:28 +01:00
Mihai STAN 6bf93b3d06 Merge remote-tracking branch 'upstream/develop' into develop 2017-02-15 15:00:25 +02:00
Niels Lohmann 82fb613763 📝 update after #302 2017-02-14 07:28:30 +01:00
Niels Lohmann 22b9a301d6 Merge pull request #450 from nlohmann/TurpentineDistillery-feature/locale_independent_str_to_num
TurpentineDistillery feature/locale independent str to num
2017-02-14 07:18:35 +01:00
Niels Lohmann c95ff863bf ⬆️ updated Catch to v1.7.2 2017-02-13 18:55:11 +01:00
Niels Lohmann 265c5b5207 🔨 more work on the number parser 2017-02-13 18:51:23 +01:00
Niels Lohmann b84705d557 improved test coverage 2017-02-12 20:14:43 +01:00
Niels Lohmann c8191c8172 🔨 further cleanup 2017-02-12 18:50:17 +01:00
Niels Lohmann c2d55109c1 🔨 make lexer distinguishes number types 2017-02-11 16:54:25 +01:00
Niels Lohmann 9f5dccbab5 💄 cleanup 2017-02-11 15:55:53 +01:00
Niels Lohmann 926af6d50b 🔀 merge branch 'develop' into TurpentineDistillery-feature/locale_independent_str_to_num 2017-02-11 15:17:47 +01:00
Niels Lohmann ed8516dc39 👷 added Codacy badge 2017-02-09 17:38:02 +01:00
Niels Lohmann c485d46cea 📝 screenshoots look ugly 2017-02-08 20:00:46 +01:00
Niels Lohmann 6fd77cea4a 📝 added screenshots 2017-02-08 19:22:19 +01:00
Niels Lohmann 0ffa18aab8 📝 listing projects using the library 2017-02-08 19:16:38 +01:00
Niels Lohmann 662a9b8f3c ✏️ fixed more typos 2017-02-08 18:19:41 +01:00
Niels Lohmann 4746a4c536 💄 minor change 2017-02-08 17:56:43 +01:00
Niels Lohmann 163f8397fd ✏️ fixed a typo #446 2017-02-05 17:11:26 +01:00
Niels Lohmann 8d88a1da2a 🔀 merged #379 and fixed conflicts 2017-02-05 13:13:41 +01:00
Niels Lohmann d284c86dd1 uncommented some tests 2017-02-04 21:00:41 +01:00
Niels Lohmann 922fe693e1 ⬆️ updated Catch to v1.7.0 2017-02-04 15:30:28 +01:00
Niels Lohmann 1cfdc2a753 🐛 fixed test compilation 2017-02-04 08:25:55 +01:00
Niels Lohmann 77d6f70602 📝 acknowledgments for #442 and #445 2017-02-03 18:28:22 +01:00
Niels Lohmann d6afaa8e16 📝 fixing a documentation issue #442 2017-02-03 18:15:37 +01:00
Niels Lohmann 5976caf032 improved test compilation speed #445 2017-02-03 18:09:55 +01:00
Niels Lohmann 16af771277 added roundtrip test for the Big List of Naughty Strings 2017-02-01 17:34:39 +01:00
Niels Lohmann bf8fdac99a 👷 dropped Doozer.io support 2017-02-01 16:41:05 +01:00
Niels Lohmann c75865d88c 🐛 fixed -Weffc++ warnings 2017-02-01 15:13:21 +01:00
Niels Lohmann b210f2dbf4 💄 minor refactoring 2017-01-29 21:40:37 +01:00
Niels Lohmann 0164b10e10 added missing tests found by mutate++ 2017-01-29 17:18:58 +01:00
Niels Lohmann affa3bf4e9 Merge pull request #439 from jaredgrubb/patch-2
README: adjust boost::optional example
2017-01-29 08:18:44 +01:00
Jared Grubb f2873e6d3a README: adjust boost::optional example
The "from_json" example for boost::optional is not complete and should also handle the 'none' case.
2017-01-29 02:46:58 +00:00
Mihai STAN 6198439f59 fix #414 - comparing to 0 literal
Overload comparison operators for all types that could be converted
to nullptr.
2017-01-24 22:33:37 +02:00
Alex Astashyn c236b596c9 Merge upstream/develop into feature/locale_independent_str_to_num 2017-01-04 19:20:16 -05:00
Alex Astashyn 949061079a Merge upstream/develop into feature/locale_independent_num_to_str 2017-01-04 18:55:19 -05:00
Alex Astashyn 6fba52b6da Merged upstream/develop into feature/locale_independent_str_to_num 2016-12-12 20:27:15 -05:00
Alex Astashyn 5cad2006eb Tweaked check for preserved sign; added LCOV_EXCL_LINE 2016-12-12 20:15:57 -05:00
Alex Astashyn 65b9b0c429 Disabling snprintf pre-check, since can't get locale-specific behavior to manifest in AppVeyor 2016-12-12 19:50:21 -05:00
Alex Astashyn 0f8de48ddb Disabling strtod pre-check, since can't get locale-specific behavior to manifest in AppVeyor 2016-12-12 19:48:14 -05:00
Alex Astashyn cd0b651d43 Tweaked check for preserved sign; added LCOV_EXCL_LINE 2016-12-12 19:46:47 -05:00
Alex Astashyn 01930357f7 Tweaking unit test, as digits grouping is failing to be invoked in CI 2016-12-08 22:39:38 -05:00
Alex Astashyn 343c9f9baa Addressing compiler warnings 2016-12-08 22:36:18 -05:00
Alex Astashyn 1c029b97c0 Still trying to invoke locale-specific behavior in CI 2016-12-08 22:13:05 -05:00
Alex Astashyn 38499e84fc Removed unused struct; fixed comments 2016-12-08 21:38:14 -05:00
Alex Astashyn 50f0484ad5 Added unit test for issue #378 2016-12-07 20:23:25 -05:00
Alex Astashyn 27d9740ad6 Tweaks to unit-test for issue #379 2016-12-07 19:55:07 -05:00
Alex Astashyn 0a4a6a8399 Refactored to avoid using exceptions, as there are plans to support exceptionless mode 2016-12-07 19:53:27 -05:00
Alex Astashyn 6774457733 Trying to coerce setlocale to make snprintf use commas as delimiter some more 2016-12-06 22:59:12 -05:00
Alex Astashyn d169598c6c simplified code a bit based on @gregmarr's suggestions 2016-12-06 22:20:48 -05:00
Alex Astashyn d2e9ce270a Trying to coerce setlocale to make snprintf use commas as delimiter; the behavior appears to be compiler/platform-specific 2016-12-06 22:18:20 -05:00
Alex Astashyn 6e8da7d8c4 Added unit-test for issue #379 (locale-independent str-to-num) 2016-12-06 19:45:48 -05:00
Alex Astashyn 7a081244a5 Refactored preprocessing with a lambda instead of do{...}while(0) 2016-12-06 19:41:31 -05:00
Alex Astashyn 0c87d5d6b3 Refactored preprocessing with a lambda instead of do{...}while(0) 2016-12-06 19:41:05 -05:00
Alex Astashyn d643360575 Bugfix: when working with C formatting functions we need to query C locales (localeconv) rather than std::locale 2016-12-06 00:43:12 -05:00
Alex Astashyn 738d462955 Bugfix: when working with C formatting functions we need to query C locales (localeconv) rather than std::locale 2016-12-06 00:23:58 -05:00
Alex Astashyn 82b82fd487 Addressing msvc-specific compilation issues. 2016-12-05 20:33:28 -05:00
Alex Astashyn 509447b4d5 Small bufix related to creation of fmt string for snprintf 2016-12-05 19:03:39 -05:00
Alex Astashyn e41a956782 Alternative handling of integer types relying on strto[u]ll 2016-12-04 13:23:39 -05:00
Alex Astashyn 2197856395 Fixed suffixing .0 and modified the unit tests accordingly 2016-12-04 01:38:23 -05:00
Alex Astashyn 21cae35930 Added locale-independent numtostr 2016-12-04 01:27:22 -05:00
Alex Astashyn c75efedc6e stylistic changes 2016-12-03 23:19:43 -05:00
Alex Astashyn 4eafaab816 Improved overflow detection; removed debugging output statements. 2016-12-03 22:54:36 -05:00
Alex Astashyn 6b78b5c2be Added strtonum for locale-independent number parsing 2016-12-03 19:05:09 -05:00
63 changed files with 6708 additions and 1370 deletions
-24
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
View File
@@ -7,6 +7,7 @@ fuzz-testing
*.gcno *.gcno
*.gcda *.gcda
build
working working
doc/xml doc/xml
+12 -1
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
+11 -9
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})
+36
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)
+23 -1
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
########################################################################## ##########################################################################
+55 -6
View File
@@ -2,10 +2,10 @@
[![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)
[![Try online](https://img.shields.io/badge/try-online-blue.svg)](http://melpon.org/wandbox/permlink/4NEU6ZZMoM9lpIex) [![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/nv9fOg0XVVhWmFFy)
[![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)
[![Github Releases](https://img.shields.io/github/release/nlohmann/json.svg)](https://github.com/nlohmann/json/releases) [![Github Releases](https://img.shields.io/github/release/nlohmann/json.svg)](https://github.com/nlohmann/json/releases)
@@ -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 }");
``` ```
@@ -563,7 +571,9 @@ namespace nlohmann {
} }
static void from_json(const json& j, boost::optional<T>& opt) { static void from_json(const json& j, boost::optional<T>& opt) {
if (!j.is_null()) { if (j.is_null()) {
opt = boost::none;
} else {
opt = j.get<T>(); // same as above, but with opt = j.get<T>(); // same as above, but with
// adl_serializer<T>::from_json // adl_serializer<T>::from_json
} }
@@ -800,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.
@@ -811,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).
@@ -838,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
View File
File diff suppressed because it is too large Load Diff
+1 -1
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 = .
+5 -5
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
+1 -1
View File
@@ -1 +1 @@
<a target="_blank" href="http://melpon.org/wandbox/permlink/4NEU6ZZMoM9lpIex"><b>online</b></a> <a target="_blank" href="http://melpon.org/wandbox/permlink/nv9fOg0XVVhWmFFy"><b>online</b></a>
+2 -2
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"
} }
} }
+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
BIN
View File
Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.4 MiB

After

Width:  |  Height:  |  Size: 1.4 MiB

BIN
View File
Binary file not shown.

After

Width:  |  Height:  |  Size: 204 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 MiB

+708 -402
View File
File diff suppressed because it is too large Load Diff
+503 -313
View File
File diff suppressed because it is too large Load Diff
+32 -4
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}
+2 -2
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 = ""
+1 -1
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
+1 -1
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
+1 -1
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
+1 -1
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
View File
@@ -0,0 +1,7 @@
#pragma once
#include "catch.hpp"
#define private public
#include "json.hpp"
using nlohmann::json;
+1 -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>.
+21 -37
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;
} }
} }
+1 -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>.
+7 -3
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);
} }
} }
+1 -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>.
+1 -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>.
+26 -12
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) == "']'"));
+36 -2
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");
@@ -596,6 +604,32 @@ TEST_CASE("parser class")
"missing or wrong low surrogate"); "missing or wrong low surrogate");
} }
SECTION("tests found by mutate++")
{
// test case to make sure no comma preceeds the first key
CHECK_THROWS_AS(json::parser("{,\"key\": false}").parse(), std::invalid_argument);
// test case to make sure an object is properly closed
CHECK_THROWS_AS(json::parser("[{\"key\": false true]").parse(), std::invalid_argument);
// test case to make sure the callback is properly evaluated after reading a key
{
json::parser_callback_t cb = [](int, json::parse_event_t event, json&)
{
if (event == json::parse_event_t::key)
{
return false;
}
else
{
return true;
}
};
json x = json::parse("{\"key\": false}", cb);
CHECK(x == json::object());
}
}
SECTION("callback function") SECTION("callback function")
{ {
auto s_object = R"( auto s_object = R"(
+1 -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>.
+3 -3
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()"
{ {
+2 -2
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));
+1 -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>.
+1 -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>.
+9 -9
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")
{ {
+1 -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>.
+1 -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>.
+1 -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>.
+17 -3
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")
+1 -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>.
+1 -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>.
+1 -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>.
+1 -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>.
+1 -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>.
+8 -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>.
@@ -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}
}));
} }
} }
+1 -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>.
+8 -4
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));
} }
} }
+1 -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>.
+1 -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>.
+2 -2
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;
+1 -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>.
+113 -19
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);
}
} }
+1 -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>.
+47 -2
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);
}
}
} }
+6 -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>.
@@ -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
+1 -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>.
+1 -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>.
+959 -458
View File
File diff suppressed because it is too large Load Diff