From c04275966f8e1d2aba154074ef823b5973e1cb68 Mon Sep 17 00:00:00 2001 From: Niels Date: Sat, 7 May 2016 18:33:43 +0200 Subject: [PATCH] improved test coverage --- README.md | 2 +- src/json.hpp | 3 ++- src/json.hpp.re2c | 3 ++- test/unit.cpp | 6 ++++++ 4 files changed, 11 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 1f501b73..f8cb20d6 100644 --- a/README.md +++ b/README.md @@ -449,7 +449,7 @@ $ make $ ./json_unit "*" =============================================================================== -All tests passed (5568699 assertions in 31 test cases) +All tests passed (5568703 assertions in 31 test cases) ``` For more information, have a look at the file [.travis.yml](https://github.com/nlohmann/json/blob/master/.travis.yml). diff --git a/src/json.hpp b/src/json.hpp index 6b22e89d..932ab9e5 100644 --- a/src/json.hpp +++ b/src/json.hpp @@ -9708,7 +9708,8 @@ basic_json_parser_63: default: { - throw std::domain_error("unexpected parent type " + parent.type_name()); + // if there exists a parent it cannot be primitive + assert(false); // LCOV_EXCL_LINE } } } diff --git a/src/json.hpp.re2c b/src/json.hpp.re2c index 3dab33bb..77a1eea9 100644 --- a/src/json.hpp.re2c +++ b/src/json.hpp.re2c @@ -9018,7 +9018,8 @@ class basic_json default: { - throw std::domain_error("unexpected parent type " + parent.type_name()); + // if there exists a parent it cannot be primitive + assert(false); // LCOV_EXCL_LINE } } } diff --git a/test/unit.cpp b/test/unit.cpp index 2ad28a74..de00166f 100644 --- a/test/unit.cpp +++ b/test/unit.cpp @@ -12094,6 +12094,12 @@ TEST_CASE("JSON pointers") CHECK_THROWS_AS(json::json_pointer("/~"), std::domain_error); CHECK_THROWS_WITH(json::json_pointer("/~"), "escape error: '~' must be followed with '0' or '1'"); + + json::json_pointer p; + CHECK_THROWS_AS(p.top(), std::domain_error); + CHECK_THROWS_WITH(p.top(), "JSON pointer has no parent"); + CHECK_THROWS_AS(p.pop_back(), std::domain_error); + CHECK_THROWS_WITH(p.pop_back(), "JSON pointer has no parent"); } SECTION("examples from RFC 6901")