Merge branch 'develop' into feature/manual_lexer

This commit is contained in:
Niels Lohmann 2017-03-29 00:57:09 +02:00
commit a690a9f2d2
No known key found for this signature in database
GPG key ID: 7F3CEA63AE251B69
5 changed files with 68 additions and 33 deletions

View file

@ -217,6 +217,7 @@ TEST_CASE("regression tests")
json a = {1, 2, 3};
json::reverse_iterator rit = ++a.rbegin();
CHECK(*rit == json(2));
CHECK(rit.value() == json(2));
}
{
json a = {1, 2, 3};
@ -541,7 +542,7 @@ TEST_CASE("regression tests")
CAPTURE(filename);
json j;
std::ifstream f(filename);
CHECK_NOTHROW(j << f);
CHECK_NOTHROW(f >> j);
}
}
@ -557,7 +558,7 @@ TEST_CASE("regression tests")
CAPTURE(filename);
json j;
std::ifstream f(filename);
CHECK_NOTHROW(j << f);
CHECK_NOTHROW(f >> j);
}
}
@ -587,15 +588,15 @@ TEST_CASE("regression tests")
std::stringstream ss;
json j;
ss << "123";
CHECK_NOTHROW(j << ss);
CHECK_NOTHROW(ss >> j);
// see https://github.com/nlohmann/json/issues/367#issuecomment-262841893:
// ss is not at EOF; this yielded an error before the fix
// (threw basic_string::append). No, it should just throw
// a parse error because of the EOF.
CHECK_THROWS_AS(j << ss, json::parse_error);
CHECK_THROWS_WITH(j << ss,
"[json.exception.parse_error.101] parse error at 1: syntax error - unexpected end of input");
CHECK_THROWS_AS(ss >> j, json::parse_error);
CHECK_THROWS_WITH(ss >> j,
"[json.exception.parse_error.101] parse error at 1: parse error - unexpected end of input");
}
SECTION("issue #389 - Integer-overflow (OSS-Fuzz issue 267)")

View file

@ -78,7 +78,8 @@ TEST_CASE("compliance tests from json.org")
{
CAPTURE(filename);
std::ifstream f(filename);
CHECK_THROWS_AS(json::parse(f), json::parse_error);
json j;
CHECK_THROWS_AS(f >> j, json::parse_error);
}
}
@ -93,7 +94,8 @@ TEST_CASE("compliance tests from json.org")
{
CAPTURE(filename);
std::ifstream f(filename);
CHECK_NOTHROW(json::parse(f));
json j;
CHECK_NOTHROW(f >> j);
}
}
}
@ -318,7 +320,7 @@ TEST_CASE("test suite from json-test-suite")
// strings in a JSON array
std::ifstream f("test/data/json_testsuite/sample.json");
json j;
CHECK_NOTHROW(j = json::parse(f));
CHECK_NOTHROW(f >> j);
// the array has 3 elements
CHECK(j.size() == 3);
@ -332,31 +334,36 @@ TEST_CASE("json.org examples")
SECTION("1.json")
{
std::ifstream f("test/data/json.org/1.json");
CHECK_NOTHROW(json::parse(f));
json j;
CHECK_NOTHROW(f >> j);
}
SECTION("2.json")
{
std::ifstream f("test/data/json.org/2.json");
CHECK_NOTHROW(json::parse(f));
json j;
CHECK_NOTHROW(f >> j);
}
SECTION("3.json")
{
std::ifstream f("test/data/json.org/3.json");
CHECK_NOTHROW(json::parse(f));
json j;
CHECK_NOTHROW(f >> j);
}
SECTION("4.json")
{
std::ifstream f("test/data/json.org/4.json");
CHECK_NOTHROW(json::parse(f));
json j;
CHECK_NOTHROW(f >> j);
}
SECTION("5.json")
{
std::ifstream f("test/data/json.org/5.json");
CHECK_NOTHROW(json::parse(f));
json j;
CHECK_NOTHROW(f >> j);
}
}
@ -538,7 +545,8 @@ TEST_CASE("nst's JSONTestSuite")
{
CAPTURE(filename);
std::ifstream f(filename);
CHECK_NOTHROW(json::parse(f));
json j;
CHECK_NOTHROW(f >> j);
}
}
@ -746,7 +754,8 @@ TEST_CASE("nst's JSONTestSuite")
{
CAPTURE(filename);
std::ifstream f(filename);
CHECK_THROWS_AS(json::parse(f), json::parse_error);
json j;
CHECK_THROWS_AS(f >> j, json::parse_error);
}
}
@ -768,7 +777,8 @@ TEST_CASE("nst's JSONTestSuite")
{
CAPTURE(filename);
std::ifstream f(filename);
CHECK_NOTHROW(json::parse(f));
json j;
CHECK_NOTHROW(f >> j);
}
}
@ -787,7 +797,8 @@ TEST_CASE("nst's JSONTestSuite")
{
CAPTURE(filename);
std::ifstream f(filename);
CHECK_THROWS_AS(json::parse(f), json::out_of_range);
json j;
CHECK_THROWS_AS(f >> j, json::out_of_range);
}
}
@ -813,7 +824,8 @@ TEST_CASE("nst's JSONTestSuite")
{
CAPTURE(filename);
std::ifstream f(filename);
CHECK_THROWS_AS(json::parse(f), json::parse_error);
json j;
CHECK_THROWS_AS(f >> j, json::parse_error);
}
}
}
@ -839,7 +851,8 @@ TEST_CASE("Big List of Naughty Strings")
SECTION("parsing blns.json")
{
std::ifstream f("test/data/big-list-of-naughty-strings/blns.json");
CHECK_NOTHROW(json::parse(f));
json j;
CHECK_NOTHROW(f >> j);
}
// check if parsed strings roundtrip

View file

@ -127,7 +127,7 @@ TEST_CASE("Unicode", "[hide]")
// strings in a JSON array
std::ifstream f("test/data/json_nlohmann_tests/all_unicode.json");
json j;
CHECK_NOTHROW(j << f);
CHECK_NOTHROW(f >> j);
// the array has 1112064 + 1 elemnts (a terminating "null" value)
// Note: 1112064 = 0x1FFFFF code points - 2048 invalid values between
@ -170,7 +170,7 @@ TEST_CASE("Unicode", "[hide]")
// read a file with a UTF-8 BOM
std::ifstream f("test/data/json_nlohmann_tests/bom.json");
json j;
CHECK_NOTHROW(j << f);
CHECK_NOTHROW(f >> j);
}
SECTION("error for incomplete/wrong BOM")