From 1554baa01d58499e3d06806d59955d38b35c224d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20DELRIEU?= Date: Sat, 14 Jan 2017 01:26:06 +0100 Subject: [PATCH] attempting to fix coverage. testing that reserve is called --- test/src/unit-conversions.cpp | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/test/src/unit-conversions.cpp b/test/src/unit-conversions.cpp index 2b570533..73b686d8 100644 --- a/test/src/unit-conversions.cpp +++ b/test/src/unit-conversions.cpp @@ -160,12 +160,28 @@ TEST_CASE("value conversion") { std::forward_list a = j.get>(); CHECK(json(a) == j); + + CHECK_THROWS_AS(json(json::value_t::null).get>(), std::logic_error); + CHECK_THROWS_WITH(json(json::value_t::null).get>(), + "type must be array, but is null"); } SECTION("std::vector") { std::vector a = j.get>(); CHECK(json(a) == j); + + CHECK_THROWS_AS(json(json::value_t::null).get>(), std::logic_error); + CHECK_THROWS_WITH(json(json::value_t::null).get>(), + "type must be array, but is null"); + + SECTION("reserve is called on containers that supports it") + { + // making the call to from_json throw in order to check capacity + std::vector v; + CHECK_THROWS_AS(nlohmann::from_json(j, v), std::logic_error); + CHECK(v.capacity() == j.size()); + } } SECTION("std::deque") @@ -184,6 +200,8 @@ TEST_CASE("value conversion") CHECK_THROWS_AS(json(json::value_t::number_unsigned).get(), std::logic_error); CHECK_THROWS_AS(json(json::value_t::number_float).get(), std::logic_error); + CHECK_THROWS_WITH(json(json::value_t::object).get>(), + "type must be array, but is object"); CHECK_THROWS_WITH(json(json::value_t::null).get(), "type must be array, but is null"); CHECK_THROWS_WITH(json(json::value_t::object).get(),