From 572232614d697291fb4f39d9794ebcebcf23f795 Mon Sep 17 00:00:00 2001 From: Niels Date: Sun, 8 Feb 2015 16:37:21 +0100 Subject: [PATCH] more test cases --- test/unit.cpp | 93 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 93 insertions(+) diff --git a/test/unit.cpp b/test/unit.cpp index 3996611f..49a5473b 100644 --- a/test/unit.cpp +++ b/test/unit.cpp @@ -1326,4 +1326,97 @@ TEST_CASE("value conversion") CHECK(json(a) == j); } } + + SECTION("get a string (explicit)") + { + json::string_t s_reference {"Hello world"}; + json j(s_reference); + + SECTION("string_t") + { + json::string_t s = j.get(); + CHECK(json(s) == j); + } + + SECTION("std::string") + { + std::string s = j.get(); + CHECK(json(s) == j); + } + + SECTION("exception in case of a non-string type") + { + CHECK_THROWS_AS(json(json::value_t::null).get(), std::logic_error); + CHECK_THROWS_AS(json(json::value_t::object).get(), std::logic_error); + CHECK_THROWS_AS(json(json::value_t::array).get(), std::logic_error); + CHECK_THROWS_AS(json(json::value_t::boolean).get(), std::logic_error); + CHECK_THROWS_AS(json(json::value_t::number_integer).get(), std::logic_error); + CHECK_THROWS_AS(json(json::value_t::number_float).get(), std::logic_error); + } + } + + SECTION("get a string (implicit)") + { + json::string_t s_reference {"Hello world"}; + json j(s_reference); + + SECTION("string_t") + { + json::string_t s = j; + CHECK(json(s) == j); + } + + SECTION("std::string") + { + std::string s = j; + CHECK(json(s) == j); + } + } + + SECTION("get a boolean (explicit)") + { + json::boolean_t b_reference {true}; + json j(b_reference); + + SECTION("boolean_t") + { + json::boolean_t b = j.get(); + CHECK(json(b) == j); + } + + SECTION("bool") + { + bool b = j.get(); + CHECK(json(b) == j); + } + + SECTION("exception in case of a non-string type") + { + CHECK_THROWS_AS(json(json::value_t::null).get(), std::logic_error); + CHECK_THROWS_AS(json(json::value_t::object).get(), std::logic_error); + CHECK_THROWS_AS(json(json::value_t::array).get(), std::logic_error); + CHECK_THROWS_AS(json(json::value_t::string).get(), std::logic_error); + CHECK_THROWS_AS(json(json::value_t::number_integer).get(), std::logic_error); + CHECK_THROWS_AS(json(json::value_t::number_float).get(), std::logic_error); + } + } + + SECTION("get a boolean (implicit)") + { + json::boolean_t b_reference {true}; + json j(b_reference); + + SECTION("boolean_t") + { + json::boolean_t b = j; + CHECK(json(b) == j); + } + + SECTION("bool") + { + bool b = j; + CHECK(json(b) == j); + } + } + }