Skip to content

Commit

Permalink
🔨 working on #367
Browse files Browse the repository at this point in the history
Test cases succeed as expected, but the example in #367 is not fully
realized yet.
  • Loading branch information
nlohmann committed May 10, 2017
1 parent 962da00 commit 2afbd33
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/json.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
}

Expand Down
54 changes: 52 additions & 2 deletions test/src/unit-testsuites.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down Expand Up @@ -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);
}
}

Expand Down

0 comments on commit 2afbd33

Please sign in to comment.