From 8014637ad1a05914fc069213c1f5c93aa9e2da17 Mon Sep 17 00:00:00 2001 From: Niels Lohmann Date: Thu, 24 Nov 2016 21:53:41 +0100 Subject: [PATCH] :white_check_mark: added a test for EOF error (#367) --- test/src/unit-regression.cpp | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/test/src/unit-regression.cpp b/test/src/unit-regression.cpp index 661edc25..414ee71c 100644 --- a/test/src/unit-regression.cpp +++ b/test/src/unit-regression.cpp @@ -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"); + } }