Skip to content

Commit

Permalink
✅ added a test for EOF error (#367)
Browse files Browse the repository at this point in the history
  • Loading branch information
nlohmann committed Nov 24, 2016
1 parent dfc49e7 commit 8014637
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions test/src/unit-regression.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -495,4 +495,19 @@ TEST_CASE("regression tests")
json j = json::parse("22e2222");
CHECK(j == json());
}

SECTION("issue #367 - calling stream at EOF")
{
std::stringstream ss;
json j;
ss << "123";
CHECK_NOTHROW(j << ss);

// 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, std::invalid_argument);
CHECK_THROWS_WITH(j << ss, "parse error - unexpected end of input");
}
}

0 comments on commit 8014637

Please sign in to comment.