Merge branch 'develop' into coverity_scan
This commit is contained in:
commit
f9fe0193d5
17 changed files with 1770 additions and 1495 deletions
2
.github/CONTRIBUTING.md
vendored
2
.github/CONTRIBUTING.md
vendored
|
@ -64,7 +64,7 @@ Please understand that I cannot accept pull requests changing only file `src/jso
|
||||||
- Specifically, I am aware of compilation problems with **Microsoft Visual Studio** (there even is an [issue label](https://github.com/nlohmann/json/issues?utf8=✓&q=label%3A%22visual+studio%22+) for these kind of bugs). I understand that even in 2016, complete C++11 support isn't there yet. But please also understand that I do not want to drop features or uglify the code just to make Microsoft's sub-standard compiler happy. The past has shown that there are ways to express the functionality such that the code compiles with the most recent MSVC - unfortunately, this is not the main objective of the project.
|
- Specifically, I am aware of compilation problems with **Microsoft Visual Studio** (there even is an [issue label](https://github.com/nlohmann/json/issues?utf8=✓&q=label%3A%22visual+studio%22+) for these kind of bugs). I understand that even in 2016, complete C++11 support isn't there yet. But please also understand that I do not want to drop features or uglify the code just to make Microsoft's sub-standard compiler happy. The past has shown that there are ways to express the functionality such that the code compiles with the most recent MSVC - unfortunately, this is not the main objective of the project.
|
||||||
- Please refrain from proposing changes that would **break [JSON](http://json.org) conformance**. If you propose a conformant extension of JSON to be supported by the library, please motivate this extension.
|
- Please refrain from proposing changes that would **break [JSON](http://json.org) conformance**. If you propose a conformant extension of JSON to be supported by the library, please motivate this extension.
|
||||||
- We shall not extend the library to **support comments**. There is quite some [controversy](https://www.reddit.com/r/programming/comments/4v6chu/why_json_doesnt_support_comments_douglas_crockford/) around this topic, and there were quite some [issues](https://github.com/nlohmann/json/issues/376) on this. We believe that JSON is fine without comments.
|
- We shall not extend the library to **support comments**. There is quite some [controversy](https://www.reddit.com/r/programming/comments/4v6chu/why_json_doesnt_support_comments_douglas_crockford/) around this topic, and there were quite some [issues](https://github.com/nlohmann/json/issues/376) on this. We believe that JSON is fine without comments.
|
||||||
- We do not preserve the **insertion order of object elements**. The [JSON standard](https://tools.ietf.org/html/rfc7159.html) defines objects as "an unordered collection of zero or more name/value pairs". To this end, this library does not preserve insertion order of name/value pairs. (In fact, keys will be traversed in alphabetical order as `std::map` with `std::less` is used by default.) Note this behavior conforms to the standard, and we shall not it to any other order.
|
- We do not preserve the **insertion order of object elements**. The [JSON standard](https://tools.ietf.org/html/rfc7159.html) defines objects as "an unordered collection of zero or more name/value pairs". To this end, this library does not preserve insertion order of name/value pairs. (In fact, keys will be traversed in alphabetical order as `std::map` with `std::less` is used by default.) Note this behavior conforms to the standard, and we shall not change it to any other order. If you do want to preserve the insertion order, you can specialize the object type with containers like [`tsl::ordered_map`](https://github.com/Tessil/ordered-map) or [`nlohmann::fifo_map`](https://github.com/nlohmann/fifo_map).
|
||||||
|
|
||||||
- Please do not open pull requests that address **multiple issues**.
|
- Please do not open pull requests that address **multiple issues**.
|
||||||
|
|
||||||
|
|
2
Makefile
2
Makefile
|
@ -49,7 +49,6 @@ doctest:
|
||||||
# -Wno-documentation-unknown-command: code uses user-defined commands like @complexity
|
# -Wno-documentation-unknown-command: code uses user-defined commands like @complexity
|
||||||
# -Wno-exit-time-destructors: warning in Catch code
|
# -Wno-exit-time-destructors: warning in Catch code
|
||||||
# -Wno-keyword-macro: unit-tests use "#define private public"
|
# -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...)"
|
# -Wno-range-loop-analysis: iterator_wrapper tests tests "for(const auto i...)"
|
||||||
pedantic:
|
pedantic:
|
||||||
$(MAKE) json_unit CXXFLAGS="\
|
$(MAKE) json_unit CXXFLAGS="\
|
||||||
|
@ -59,7 +58,6 @@ pedantic:
|
||||||
-Wno-documentation-unknown-command \
|
-Wno-documentation-unknown-command \
|
||||||
-Wno-exit-time-destructors \
|
-Wno-exit-time-destructors \
|
||||||
-Wno-keyword-macro \
|
-Wno-keyword-macro \
|
||||||
-Wno-deprecated-declarations \
|
|
||||||
-Wno-range-loop-analysis"
|
-Wno-range-loop-analysis"
|
||||||
|
|
||||||
|
|
||||||
|
|
10
README.md
10
README.md
|
@ -5,7 +5,7 @@
|
||||||
[![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&utm_medium=referral&utm_content=nlohmann/json&utm_campaign=Badge_Grade)
|
[![Codacy Badge](https://api.codacy.com/project/badge/Grade/f3732b3327e34358a0e9d1fe9f661f08)](https://www.codacy.com/app/nlohmann/json?utm_source=github.com&utm_medium=referral&utm_content=nlohmann/json&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/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)
|
||||||
|
@ -65,6 +65,8 @@ to the files you want to use JSON objects. That's it. Do not forget to set the n
|
||||||
|
|
||||||
:beer: If you are using OS X and [Homebrew](http://brew.sh), just type `brew tap nlohmann/json` and `brew install nlohmann_json` and you're set. If you want the bleeding edge rather than the latest release, use `brew install nlohmann_json --HEAD`.
|
:beer: If you are using OS X and [Homebrew](http://brew.sh), just type `brew tap nlohmann/json` and `brew install nlohmann_json` and you're set. If you want the bleeding edge rather than the latest release, use `brew install nlohmann_json --HEAD`.
|
||||||
|
|
||||||
|
:warning: [Version 3.0.0](https://github.com/nlohmann/json/wiki/Road-toward-3.0.0) is currently under development. Branch `develop` is used for the ongoing work and is probably **unstable**. Please use the `master` branch for the last stable version 2.1.1.
|
||||||
|
|
||||||
|
|
||||||
## Examples
|
## Examples
|
||||||
|
|
||||||
|
@ -823,9 +825,10 @@ I deeply appreciate the help of the following people.
|
||||||
- [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.
|
- [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.
|
- [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.
|
- [rswanson-ihi](https://github.com/rswanson-ihi) noted a typo in the README.
|
||||||
- [Mihai Stan](https://github.com/stanmihai4) fixed a bug in the comparison with `nullptr`s.
|
- [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.
|
- [Tushar Maheshwari](https://github.com/tusharpm) added [cotire](https://github.com/sakra/cotire) support to speed up the compilation.
|
||||||
|
- [TedLyngmo](https://github.com/TedLyngmo) noted a typo in the README.
|
||||||
|
|
||||||
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.
|
||||||
|
|
||||||
|
@ -876,6 +879,7 @@ The library is currently used in Apple macOS Sierra and iOS 10. I am not sure wh
|
||||||
- The strings stored in the library are UTF-8 encoded. When using the default string type (`std::string`), note that its length/size functions return the number of stored bytes rather than the number of characters or glyphs.
|
- The strings stored in the library are UTF-8 encoded. When using the default string type (`std::string`), note that its length/size functions return the number of stored bytes rather than the number of characters or glyphs.
|
||||||
- The code can be compiled without C++ **runtime type identification** features; that is, you can use the `-fno-rtti` compiler flag.
|
- The code can be compiled without C++ **runtime type identification** features; that is, you can use the `-fno-rtti` compiler flag.
|
||||||
- **Exceptions** are used widly within the library. They can, however, be switched off with either using the compiler flag `-fno-exceptions` or by defining the symbol `JSON_NOEXCEPTION`. In this case, exceptions are replaced by an `abort()` call.
|
- **Exceptions** are used widly within the library. They can, however, be switched off with either using the compiler flag `-fno-exceptions` or by defining the symbol `JSON_NOEXCEPTION`. In this case, exceptions are replaced by an `abort()` call.
|
||||||
|
- By default, the library does not preserve the **insertion order of object elements**. This is standards-compliant, as the [JSON standard](https://tools.ietf.org/html/rfc7159.html) defines objects as "an unordered collection of zero or more name/value pairs". If you do want to preserve the insertion order, you can specialize the object type with containers like [`tsl::ordered_map`](https://github.com/Tessil/ordered-map) or [`nlohmann::fifo_map`](https://github.com/nlohmann/fifo_map).
|
||||||
|
|
||||||
|
|
||||||
## Execute unit tests
|
## Execute unit tests
|
||||||
|
@ -884,7 +888,7 @@ To compile and run the tests, you need to execute
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
$ make json_unit -Ctest
|
$ make json_unit -Ctest
|
||||||
$ ./test/json_unit "*""
|
$ ./test/json_unit "*"
|
||||||
|
|
||||||
===============================================================================
|
===============================================================================
|
||||||
All tests passed (11202597 assertions in 47 test cases)
|
All tests passed (11202597 assertions in 47 test cases)
|
||||||
|
|
|
@ -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>
|
|
@ -1,57 +0,0 @@
|
||||||
#include <json.hpp>
|
|
||||||
|
|
||||||
using json = nlohmann::json;
|
|
||||||
|
|
||||||
int main()
|
|
||||||
{
|
|
||||||
// a JSON text
|
|
||||||
auto text = R"(
|
|
||||||
{
|
|
||||||
"Image": {
|
|
||||||
"Width": 800,
|
|
||||||
"Height": 600,
|
|
||||||
"Title": "View from 15th Floor",
|
|
||||||
"Thumbnail": {
|
|
||||||
"Url": "http://www.example.com/image/481989943",
|
|
||||||
"Height": 125,
|
|
||||||
"Width": 100
|
|
||||||
},
|
|
||||||
"Animated" : false,
|
|
||||||
"IDs": [116, 943, 234, 38793]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
)";
|
|
||||||
|
|
||||||
// fill a stream with JSON text
|
|
||||||
std::stringstream ss;
|
|
||||||
ss << text;
|
|
||||||
|
|
||||||
// create JSON from stream
|
|
||||||
json j_complete(ss); // deprecated!
|
|
||||||
// shall be replaced by: json j_complete = json::parse(ss);
|
|
||||||
std::cout << std::setw(4) << j_complete << "\n\n";
|
|
||||||
|
|
||||||
|
|
||||||
// define parser callback
|
|
||||||
json::parser_callback_t cb = [](int depth, json::parse_event_t event, json & parsed)
|
|
||||||
{
|
|
||||||
// skip object elements with key "Thumbnail"
|
|
||||||
if (event == json::parse_event_t::key and parsed == json("Thumbnail"))
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
// fill a stream with JSON text
|
|
||||||
ss.clear();
|
|
||||||
ss << text;
|
|
||||||
|
|
||||||
// create JSON from stream (with callback)
|
|
||||||
json j_filtered(ss, cb);
|
|
||||||
// shall be replaced by: json j_filtered = json::parse(ss, cb);
|
|
||||||
std::cout << std::setw(4) << j_filtered << '\n';
|
|
||||||
}
|
|
|
@ -1 +0,0 @@
|
||||||
<a target="_blank" href="http://melpon.org/wandbox/permlink/R6dzpKXlxrttShf7"><b>online</b></a>
|
|
|
@ -1,34 +0,0 @@
|
||||||
{
|
|
||||||
"Image": {
|
|
||||||
"Animated": false,
|
|
||||||
"Height": 600,
|
|
||||||
"IDs": [
|
|
||||||
116,
|
|
||||||
943,
|
|
||||||
234,
|
|
||||||
38793
|
|
||||||
],
|
|
||||||
"Thumbnail": {
|
|
||||||
"Height": 125,
|
|
||||||
"Url": "http://www.example.com/image/481989943",
|
|
||||||
"Width": 100
|
|
||||||
},
|
|
||||||
"Title": "View from 15th Floor",
|
|
||||||
"Width": 800
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
{
|
|
||||||
"Image": {
|
|
||||||
"Animated": false,
|
|
||||||
"Height": 600,
|
|
||||||
"IDs": [
|
|
||||||
116,
|
|
||||||
943,
|
|
||||||
234,
|
|
||||||
38793
|
|
||||||
],
|
|
||||||
"Title": "View from 15th Floor",
|
|
||||||
"Width": 800
|
|
||||||
}
|
|
||||||
}
|
|
1095
src/json.hpp
1095
src/json.hpp
File diff suppressed because it is too large
Load diff
1095
src/json.hpp.re2c
1095
src/json.hpp.re2c
File diff suppressed because it is too large
Load diff
|
@ -699,6 +699,15 @@ TEST_CASE("constructors")
|
||||||
json j(n);
|
json j(n);
|
||||||
CHECK(j.type() == json::value_t::number_float);
|
CHECK(j.type() == json::value_t::number_float);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SECTION("infinity")
|
||||||
|
{
|
||||||
|
// infinity is stored as null
|
||||||
|
// should change in the future: https://github.com/nlohmann/json/issues/388
|
||||||
|
json::number_float_t n(std::numeric_limits<json::number_float_t>::infinity());
|
||||||
|
json j(n);
|
||||||
|
CHECK(j.type() == json::value_t::null);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTION("create a floating-point number (implicit)")
|
SECTION("create a floating-point number (implicit)")
|
||||||
|
@ -1272,40 +1281,4 @@ TEST_CASE("constructors")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTION("create a JSON value from an input stream")
|
|
||||||
{
|
|
||||||
SECTION("std::stringstream")
|
|
||||||
{
|
|
||||||
std::stringstream ss;
|
|
||||||
ss << "[\"foo\",1,2,3,false,{\"one\":1}]";
|
|
||||||
json j(ss);
|
|
||||||
CHECK(j == json({"foo", 1, 2, 3, false, {{"one", 1}}}));
|
|
||||||
}
|
|
||||||
|
|
||||||
SECTION("with callback function")
|
|
||||||
{
|
|
||||||
std::stringstream ss;
|
|
||||||
ss << "[\"foo\",1,2,3,false,{\"one\":1}]";
|
|
||||||
json j(ss, [](int, json::parse_event_t, const json & val)
|
|
||||||
{
|
|
||||||
// filter all number(2) elements
|
|
||||||
if (val == json(2))
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
CHECK(j == json({"foo", 1, 3, false, {{"one", 1}}}));
|
|
||||||
}
|
|
||||||
|
|
||||||
SECTION("std::ifstream")
|
|
||||||
{
|
|
||||||
std::ifstream f("test/data/json_tests/pass1.json");
|
|
||||||
json j(f);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -49,44 +49,53 @@ TEST_CASE("convenience functions")
|
||||||
|
|
||||||
SECTION("string escape")
|
SECTION("string escape")
|
||||||
{
|
{
|
||||||
CHECK(json::escape_string("\"") == "\\\"");
|
const auto check_escaped = [](const char* original,
|
||||||
CHECK(json::escape_string("\\") == "\\\\");
|
const char* escaped)
|
||||||
CHECK(json::escape_string("\b") == "\\b");
|
{
|
||||||
CHECK(json::escape_string("\f") == "\\f");
|
std::stringstream ss;
|
||||||
CHECK(json::escape_string("\n") == "\\n");
|
json::serializer s(ss);
|
||||||
CHECK(json::escape_string("\r") == "\\r");
|
s.dump_escaped(original);
|
||||||
CHECK(json::escape_string("\t") == "\\t");
|
CHECK(ss.str() == escaped);
|
||||||
|
};
|
||||||
|
|
||||||
CHECK(json::escape_string("\x01") == "\\u0001");
|
check_escaped("\"", "\\\"");
|
||||||
CHECK(json::escape_string("\x02") == "\\u0002");
|
check_escaped("\\", "\\\\");
|
||||||
CHECK(json::escape_string("\x03") == "\\u0003");
|
check_escaped("\b", "\\b");
|
||||||
CHECK(json::escape_string("\x04") == "\\u0004");
|
check_escaped("\f", "\\f");
|
||||||
CHECK(json::escape_string("\x05") == "\\u0005");
|
check_escaped("\n", "\\n");
|
||||||
CHECK(json::escape_string("\x06") == "\\u0006");
|
check_escaped("\r", "\\r");
|
||||||
CHECK(json::escape_string("\x07") == "\\u0007");
|
check_escaped("\t", "\\t");
|
||||||
CHECK(json::escape_string("\x08") == "\\b");
|
|
||||||
CHECK(json::escape_string("\x09") == "\\t");
|
check_escaped("\x01", "\\u0001");
|
||||||
CHECK(json::escape_string("\x0a") == "\\n");
|
check_escaped("\x02", "\\u0002");
|
||||||
CHECK(json::escape_string("\x0b") == "\\u000b");
|
check_escaped("\x03", "\\u0003");
|
||||||
CHECK(json::escape_string("\x0c") == "\\f");
|
check_escaped("\x04", "\\u0004");
|
||||||
CHECK(json::escape_string("\x0d") == "\\r");
|
check_escaped("\x05", "\\u0005");
|
||||||
CHECK(json::escape_string("\x0e") == "\\u000e");
|
check_escaped("\x06", "\\u0006");
|
||||||
CHECK(json::escape_string("\x0f") == "\\u000f");
|
check_escaped("\x07", "\\u0007");
|
||||||
CHECK(json::escape_string("\x10") == "\\u0010");
|
check_escaped("\x08", "\\b");
|
||||||
CHECK(json::escape_string("\x11") == "\\u0011");
|
check_escaped("\x09", "\\t");
|
||||||
CHECK(json::escape_string("\x12") == "\\u0012");
|
check_escaped("\x0a", "\\n");
|
||||||
CHECK(json::escape_string("\x13") == "\\u0013");
|
check_escaped("\x0b", "\\u000b");
|
||||||
CHECK(json::escape_string("\x14") == "\\u0014");
|
check_escaped("\x0c", "\\f");
|
||||||
CHECK(json::escape_string("\x15") == "\\u0015");
|
check_escaped("\x0d", "\\r");
|
||||||
CHECK(json::escape_string("\x16") == "\\u0016");
|
check_escaped("\x0e", "\\u000e");
|
||||||
CHECK(json::escape_string("\x17") == "\\u0017");
|
check_escaped("\x0f", "\\u000f");
|
||||||
CHECK(json::escape_string("\x18") == "\\u0018");
|
check_escaped("\x10", "\\u0010");
|
||||||
CHECK(json::escape_string("\x19") == "\\u0019");
|
check_escaped("\x11", "\\u0011");
|
||||||
CHECK(json::escape_string("\x1a") == "\\u001a");
|
check_escaped("\x12", "\\u0012");
|
||||||
CHECK(json::escape_string("\x1b") == "\\u001b");
|
check_escaped("\x13", "\\u0013");
|
||||||
CHECK(json::escape_string("\x1c") == "\\u001c");
|
check_escaped("\x14", "\\u0014");
|
||||||
CHECK(json::escape_string("\x1d") == "\\u001d");
|
check_escaped("\x15", "\\u0015");
|
||||||
CHECK(json::escape_string("\x1e") == "\\u001e");
|
check_escaped("\x16", "\\u0016");
|
||||||
CHECK(json::escape_string("\x1f") == "\\u001f");
|
check_escaped("\x17", "\\u0017");
|
||||||
|
check_escaped("\x18", "\\u0018");
|
||||||
|
check_escaped("\x19", "\\u0019");
|
||||||
|
check_escaped("\x1a", "\\u001a");
|
||||||
|
check_escaped("\x1b", "\\u001b");
|
||||||
|
check_escaped("\x1c", "\\u001c");
|
||||||
|
check_escaped("\x1d", "\\u001d");
|
||||||
|
check_escaped("\x1e", "\\u001e");
|
||||||
|
check_escaped("\x1f", "\\u001f");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -182,6 +182,10 @@ TEST_CASE("value conversion")
|
||||||
std::vector<float> v;
|
std::vector<float> v;
|
||||||
CHECK_THROWS_AS(nlohmann::from_json(j, v), std::logic_error);
|
CHECK_THROWS_AS(nlohmann::from_json(j, v), std::logic_error);
|
||||||
CHECK(v.capacity() == j.size());
|
CHECK(v.capacity() == j.size());
|
||||||
|
|
||||||
|
// make sure all values are properly copied
|
||||||
|
std::vector<int> v2 = json({1, 2, 3, 4, 5, 6, 7, 8, 9, 10});
|
||||||
|
CHECK(v2.size() == 10);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
|
@ -213,6 +213,18 @@ TEST_CASE("object inspection")
|
||||||
"{\n \"array\": [\n 1,\n 2,\n 3,\n 4\n ],\n \"boolean\": false,\n \"null\": null,\n \"number\": 42,\n \"object\": {},\n \"string\": \"Hello world\"\n}");
|
"{\n \"array\": [\n 1,\n 2,\n 3,\n 4\n ],\n \"boolean\": false,\n \"null\": null,\n \"number\": 42,\n \"object\": {},\n \"string\": \"Hello world\"\n}");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SECTION("indent=x")
|
||||||
|
{
|
||||||
|
CHECK(j.dump().size() == 94);
|
||||||
|
CHECK(j.dump(1).size() == 127);
|
||||||
|
CHECK(j.dump(2).size() == 142);
|
||||||
|
CHECK(j.dump(512).size() == 7792);
|
||||||
|
|
||||||
|
// important test, because it yields a resize of the indent_string
|
||||||
|
// inside the dump() function
|
||||||
|
CHECK(j.dump(1024).size() == 15472);
|
||||||
|
}
|
||||||
|
|
||||||
SECTION("dump and floating-point numbers")
|
SECTION("dump and floating-point numbers")
|
||||||
{
|
{
|
||||||
auto s = json(42.23).dump();
|
auto s = json(42.23).dump();
|
||||||
|
|
|
@ -33,10 +33,14 @@ using nlohmann::json;
|
||||||
|
|
||||||
TEST_CASE("version information")
|
TEST_CASE("version information")
|
||||||
{
|
{
|
||||||
SECTION("version()")
|
SECTION("meta()")
|
||||||
{
|
{
|
||||||
CHECK(json::meta()["name"] == "JSON for Modern C++");
|
json j = json::meta();
|
||||||
CHECK(json::meta()["version"] == json(
|
|
||||||
|
CHECK(j["name"] == "JSON for Modern C++");
|
||||||
|
CHECK(j["copyright"] == "(C) 2013-2017 Niels Lohmann");
|
||||||
|
CHECK(j["url"] == "https://github.com/nlohmann/json");
|
||||||
|
CHECK(j["version"] == json(
|
||||||
{
|
{
|
||||||
{"string", "2.1.1"},
|
{"string", "2.1.1"},
|
||||||
{"major", 2},
|
{"major", 2},
|
||||||
|
|
|
@ -583,10 +583,11 @@ TEST_CASE("modifiers")
|
||||||
|
|
||||||
SECTION("insert nothing (count = 0)")
|
SECTION("insert nothing (count = 0)")
|
||||||
{
|
{
|
||||||
auto pos = j_array.end();
|
|
||||||
auto it = j_array.insert(j_array.end(), 0, 5);
|
auto it = j_array.insert(j_array.end(), 0, 5);
|
||||||
CHECK(j_array.size() == 4);
|
CHECK(j_array.size() == 4);
|
||||||
CHECK(it == pos);
|
// the returned iterator points to the first inserted element;
|
||||||
|
// there were 4 elements, so it should point to the 5th
|
||||||
|
CHECK(it == j_array.begin() + 4);
|
||||||
CHECK(j_array == json({1, 2, 3, 4}));
|
CHECK(j_array == json({1, 2, 3, 4}));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -63,7 +63,7 @@ TEST_CASE("regression tests")
|
||||||
|
|
||||||
SECTION("pull request #71 - handle enum type")
|
SECTION("pull request #71 - handle enum type")
|
||||||
{
|
{
|
||||||
enum { t = 0, u = 1};
|
enum { t = 0, u = 102};
|
||||||
json j = json::array();
|
json j = json::array();
|
||||||
j.push_back(t);
|
j.push_back(t);
|
||||||
|
|
||||||
|
@ -73,6 +73,9 @@ TEST_CASE("regression tests")
|
||||||
auto anon_enum_value = j2.get<decltype(u)>();
|
auto anon_enum_value = j2.get<decltype(u)>();
|
||||||
CHECK(u == anon_enum_value);
|
CHECK(u == anon_enum_value);
|
||||||
|
|
||||||
|
// check if the actual value was stored
|
||||||
|
CHECK(j2 == 102);
|
||||||
|
|
||||||
static_assert(std::is_same<decltype(anon_enum_value), decltype(u)>::value, "");
|
static_assert(std::is_same<decltype(anon_enum_value), decltype(u)>::value, "");
|
||||||
|
|
||||||
j.push_back(json::object(
|
j.push_back(json::object(
|
||||||
|
|
815
test/thirdparty/catch/catch.hpp
vendored
815
test/thirdparty/catch/catch.hpp
vendored
File diff suppressed because it is too large
Load diff
Loading…
Reference in a new issue