🔨 working on #367
Test cases succeed as expected, but the example in #367 is not fully realized yet.
This commit is contained in:
parent
962da00171
commit
2afbd33472
2 changed files with 54 additions and 4 deletions
|
@ -7618,7 +7618,7 @@ class basic_json
|
|||
JSON_DEPRECATED
|
||||
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;
|
||||
}
|
||||
|
||||
|
@ -7650,7 +7650,7 @@ class basic_json
|
|||
*/
|
||||
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;
|
||||
}
|
||||
|
||||
|
|
|
@ -75,11 +75,29 @@ TEST_CASE("compliance tests from json.org")
|
|||
"test/data/json_tests/fail32.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);
|
||||
std::ifstream f(filename);
|
||||
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"
|
||||
}
|
||||
)
|
||||
{
|
||||
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);
|
||||
std::ifstream f(filename);
|
||||
json j;
|
||||
CHECK_THROWS_AS(f >> j, json::parse_error);
|
||||
CHECK_NOTHROW(f >> j);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue