Commit a485aa8d by Niels

cleanup and improvement of branch coverage

parent 463ffb21
...@@ -64,6 +64,22 @@ TEST_CASE("const_iterator class") ...@@ -64,6 +64,22 @@ TEST_CASE("const_iterator class")
json::const_iterator it2(&j); json::const_iterator it2(&j);
it2 = it; it2 = it;
} }
SECTION("copy constructor from non-const iterator")
{
SECTION("create from uninitialized iterator")
{
const json::iterator it {};
json::const_iterator cit(it);
}
SECTION("create from initialized iterator")
{
json j;
const json::iterator it = j.begin();
json::const_iterator cit(it);
}
}
} }
SECTION("initialization") SECTION("initialization")
......
...@@ -33,6 +33,8 @@ using nlohmann::json; ...@@ -33,6 +33,8 @@ using nlohmann::json;
TEST_CASE("deserialization") TEST_CASE("deserialization")
{ {
SECTION("successful deserialization")
{
SECTION("stream") SECTION("stream")
{ {
std::stringstream ss; std::stringstream ss;
...@@ -43,7 +45,7 @@ TEST_CASE("deserialization") ...@@ -43,7 +45,7 @@ TEST_CASE("deserialization")
SECTION("string") SECTION("string")
{ {
auto s = "[\"foo\",1,2,3,false,{\"one\":1}]"; json::string_t s = "[\"foo\",1,2,3,false,{\"one\":1}]";
json j = json::parse(s); json j = json::parse(s);
CHECK(j == json({"foo", 1, 2, 3, false, {{"one", 1}}})); CHECK(j == json({"foo", 1, 2, 3, false, {{"one", 1}}}));
} }
...@@ -70,4 +72,48 @@ TEST_CASE("deserialization") ...@@ -70,4 +72,48 @@ TEST_CASE("deserialization")
{ {
CHECK("[\"foo\",1,2,3,false,{\"one\":1}]"_json == json({"foo", 1, 2, 3, false, {{"one", 1}}})); CHECK("[\"foo\",1,2,3,false,{\"one\":1}]"_json == json({"foo", 1, 2, 3, false, {{"one", 1}}}));
} }
}
SECTION("successful deserialization")
{
SECTION("stream")
{
std::stringstream ss;
ss << "[\"foo\",1,2,3,false,{\"one\":1}";
CHECK_THROWS_AS(json::parse(ss), std::invalid_argument);
CHECK_THROWS_WITH(json::parse(ss), "parse error - unexpected end of input");
}
SECTION("string")
{
json::string_t s = "[\"foo\",1,2,3,false,{\"one\":1}";
CHECK_THROWS_AS(json::parse(s), std::invalid_argument);
CHECK_THROWS_WITH(json::parse(s), "parse error - unexpected end of input; expected ']'");
}
SECTION("operator<<")
{
std::stringstream ss;
ss << "[\"foo\",1,2,3,false,{\"one\":1}";
json j;
CHECK_THROWS_AS(j << ss, std::invalid_argument);
CHECK_THROWS_WITH(j << ss, "parse error - unexpected end of input");
}
SECTION("operator>>")
{
std::stringstream ss;
ss << "[\"foo\",1,2,3,false,{\"one\":1}";
json j;
CHECK_THROWS_AS(ss >> j, std::invalid_argument);
CHECK_THROWS_WITH(ss >> j, "parse error - unexpected end of input");
}
SECTION("user-defined string literal")
{
CHECK_THROWS_AS("[\"foo\",1,2,3,false,{\"one\":1}"_json, std::invalid_argument);
CHECK_THROWS_WITH("[\"foo\",1,2,3,false,{\"one\":1}"_json,
"parse error - unexpected end of input; expected ']'");
}
}
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment