From 1dee40a9697dd4bc22ed6dd13ad5c928d44ff0f6 Mon Sep 17 00:00:00 2001 From: Niels Date: Sun, 17 Apr 2016 22:34:39 +0200 Subject: [PATCH] fixed test case --- src/json.hpp | 24 ++++++------------------ src/json.hpp.re2c | 24 ++++++------------------ test/unit.cpp | 2 +- 3 files changed, 13 insertions(+), 37 deletions(-) diff --git a/src/json.hpp b/src/json.hpp index 030c8f2cc..5fdba1404 100644 --- a/src/json.hpp +++ b/src/json.hpp @@ -8986,25 +8986,15 @@ basic_json_parser_63: } /* - This function is only to be called from the unflatten() - function. There, j is initially of type null. - - - In case the reference tokens are empty, a reference to - j is returned and overwritten by the desired value by - the unflatten() function. - - If there are reference tokens, the null value of j will - be changed to an object or array after reading the first - reference token. - - All subsequent tokens work on arrays or objects and will - not change the type of j. - - Consequently, the type of @a j will always be null, - object, or array. Hence, the following line is - unreachable. + The following code is only reached if there exists a + reference token _and_ the current value is primitive. In + this case, we have an error situation, because primitive + values may only occur as single value; that is, with an + empty list of reference tokens. */ default: { - break; // LCOV_EXCL_LINE + throw std::domain_error("invalid value to unflatten"); } } } @@ -9462,8 +9452,6 @@ basic_json_parser_63: @complexity Linear in the size the JSON value. - @throws std::domain_error - @liveexample{The following code shows how a flattened JSON object is unflattened into the original nested JSON object.,unflatten} diff --git a/src/json.hpp.re2c b/src/json.hpp.re2c index f5fbe65bf..95a484f86 100644 --- a/src/json.hpp.re2c +++ b/src/json.hpp.re2c @@ -8296,25 +8296,15 @@ class basic_json } /* - This function is only to be called from the unflatten() - function. There, j is initially of type null. - - - In case the reference tokens are empty, a reference to - j is returned and overwritten by the desired value by - the unflatten() function. - - If there are reference tokens, the null value of j will - be changed to an object or array after reading the first - reference token. - - All subsequent tokens work on arrays or objects and will - not change the type of j. - - Consequently, the type of @a j will always be null, - object, or array. Hence, the following line is - unreachable. + The following code is only reached if there exists a + reference token _and_ the current value is primitive. In + this case, we have an error situation, because primitive + values may only occur as single value; that is, with an + empty list of reference tokens. */ default: { - break; // LCOV_EXCL_LINE + throw std::domain_error("invalid value to unflatten"); } } } @@ -8772,8 +8762,6 @@ class basic_json @complexity Linear in the size the JSON value. - @throws std::domain_error - @liveexample{The following code shows how a flattened JSON object is unflattened into the original nested JSON object.,unflatten} diff --git a/test/unit.cpp b/test/unit.cpp index f5a6fc094..2666e1111 100644 --- a/test/unit.cpp +++ b/test/unit.cpp @@ -12368,7 +12368,7 @@ TEST_CASE("JSON pointers") // error for conflicting values json j_error = {{"", 42}, {"/foo", 17}}; CHECK_THROWS_AS(j_error.unflatten(), std::domain_error); - CHECK_THROWS_WITH(j_error.unflatten(), "unresolved reference token 'foo'"); + CHECK_THROWS_WITH(j_error.unflatten(), "invalid value to unflatten"); // explicit roundtrip check CHECK(j.flatten().unflatten() == j);