🔨 working on #367

Test cases succeed as expected, but the example in #367 is not fully
realized yet.
This commit is contained in:
Niels Lohmann 2017-05-10 12:06:24 +02:00
parent 962da00171
commit 2afbd33472
No known key found for this signature in database
GPG key ID: 7F3CEA63AE251B69
2 changed files with 54 additions and 4 deletions

View file

@ -7618,7 +7618,7 @@ class basic_json
JSON_DEPRECATED JSON_DEPRECATED
friend std::istream& operator<<(basic_json& j, std::istream& i) friend std::istream& operator<<(basic_json& j, std::istream& i)
{ {
j = parser(input_adapter::create(i)).parse(true); j = parser(input_adapter::create(i)).parse(false);
return i; return i;
} }
@ -7650,7 +7650,7 @@ class basic_json
*/ */
friend std::istream& operator>>(std::istream& i, basic_json& j) friend std::istream& operator>>(std::istream& i, basic_json& j)
{ {
j = parser(input_adapter::create(i)).parse(true); j = parser(input_adapter::create(i)).parse(false);
return i; return i;
} }

View file

@ -75,11 +75,29 @@ TEST_CASE("compliance tests from json.org")
"test/data/json_tests/fail32.json", "test/data/json_tests/fail32.json",
"test/data/json_tests/fail33.json" "test/data/json_tests/fail33.json"
}) })
{
CAPTURE(filename);
std::ifstream f(filename);
CHECK_THROWS_AS(json::parse(f), json::parse_error);
}
}
SECTION("no failures with trailing literals (relaxed)")
{
// these tests fail above, because the parser does not end on EOF;
// they succeed when the operator>> is used, because it does not
// have this constraint
for (auto filename :
{
"test/data/json_tests/fail7.json",
"test/data/json_tests/fail8.json",
"test/data/json_tests/fail10.json",
})
{ {
CAPTURE(filename); CAPTURE(filename);
std::ifstream f(filename); std::ifstream f(filename);
json j; json j;
CHECK_THROWS_AS(f >> j, json::parse_error); CHECK_NOTHROW(f >> j);
} }
} }
@ -751,11 +769,43 @@ TEST_CASE("nst's JSONTestSuite")
"test/data/nst_json_testsuite/test_parsing/n_structure_whitespace_formfeed.json" "test/data/nst_json_testsuite/test_parsing/n_structure_whitespace_formfeed.json"
} }
) )
{
CAPTURE(filename);
std::ifstream f(filename);
CHECK_THROWS_AS(json::parse(f), json::parse_error);
}
}
SECTION("n -> y (relaxed)")
{
// these tests fail above, because the parser does not end on EOF;
// they succeed when the operator>> is used, because it does not
// have this constraint
for (auto filename :
{
"test/data/nst_json_testsuite/test_parsing/n_array_comma_after_close.json",
"test/data/nst_json_testsuite/test_parsing/n_array_extra_close.json",
"test/data/nst_json_testsuite/test_parsing/n_object_trailing_comment.json",
"test/data/nst_json_testsuite/test_parsing/n_object_trailing_comment_open.json",
"test/data/nst_json_testsuite/test_parsing/n_object_trailing_comment_slash_open.json",
"test/data/nst_json_testsuite/test_parsing/n_object_trailing_comment_slash_open_incomplete.json",
"test/data/nst_json_testsuite/test_parsing/n_object_with_trailing_garbage.json",
"test/data/nst_json_testsuite/test_parsing/n_string_with_trailing_garbage.json",
"test/data/nst_json_testsuite/test_parsing/n_structure_array_trailing_garbage.json",
"test/data/nst_json_testsuite/test_parsing/n_structure_array_with_extra_array_close.json",
"test/data/nst_json_testsuite/test_parsing/n_structure_close_unopened_array.json",
"test/data/nst_json_testsuite/test_parsing/n_structure_double_array.json",
"test/data/nst_json_testsuite/test_parsing/n_structure_number_with_trailing_garbage.json",
"test/data/nst_json_testsuite/test_parsing/n_structure_object_followed_by_closing_object.json",
"test/data/nst_json_testsuite/test_parsing/n_structure_object_with_trailing_garbage.json",
"test/data/nst_json_testsuite/test_parsing/n_structure_trailing_#.json"
}
)
{ {
CAPTURE(filename); CAPTURE(filename);
std::ifstream f(filename); std::ifstream f(filename);
json j; json j;
CHECK_THROWS_AS(f >> j, json::parse_error); CHECK_NOTHROW(f >> j);
} }
} }