Merge branch 'develop' into feature/iterator_range_parsing
This commit is contained in:
commit
ae7aaed4ac
13 changed files with 160 additions and 136 deletions
|
@ -64,6 +64,22 @@ TEST_CASE("const_iterator class")
|
|||
json::const_iterator it2(&j);
|
||||
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")
|
||||
|
|
|
@ -709,7 +709,7 @@ TEST_CASE("constructors")
|
|||
|
||||
SECTION("float")
|
||||
{
|
||||
float n = 42.23;
|
||||
float n = 42.23f;
|
||||
json j(n);
|
||||
CHECK(j.type() == json::value_t::number_float);
|
||||
CHECK(j.m_value.number_float == Approx(j_reference.m_value.number_float));
|
||||
|
|
|
@ -35,49 +35,95 @@ using nlohmann::json;
|
|||
|
||||
TEST_CASE("deserialization")
|
||||
{
|
||||
SECTION("stream")
|
||||
SECTION("successful deserialization")
|
||||
{
|
||||
std::stringstream ss;
|
||||
ss << "[\"foo\",1,2,3,false,{\"one\":1}]";
|
||||
json j = json::parse(ss);
|
||||
CHECK(j == json({"foo", 1, 2, 3, false, {{"one", 1}}}));
|
||||
SECTION("stream")
|
||||
{
|
||||
std::stringstream ss;
|
||||
ss << "[\"foo\",1,2,3,false,{\"one\":1}]";
|
||||
json j = json::parse(ss);
|
||||
CHECK(j == json({"foo", 1, 2, 3, false, {{"one", 1}}}));
|
||||
}
|
||||
|
||||
SECTION("string literal")
|
||||
{
|
||||
auto s = "[\"foo\",1,2,3,false,{\"one\":1}]";
|
||||
json j = json::parse(s);
|
||||
CHECK(j == json({"foo", 1, 2, 3, false, {{"one", 1}}}));
|
||||
}
|
||||
|
||||
SECTION("string_t")
|
||||
{
|
||||
json::string_t s = "[\"foo\",1,2,3,false,{\"one\":1}]";
|
||||
json j = json::parse(s);
|
||||
CHECK(j == json({"foo", 1, 2, 3, false, {{"one", 1}}}));
|
||||
}
|
||||
|
||||
SECTION("operator<<")
|
||||
{
|
||||
std::stringstream ss;
|
||||
ss << "[\"foo\",1,2,3,false,{\"one\":1}]";
|
||||
json j;
|
||||
j << ss;
|
||||
CHECK(j == json({"foo", 1, 2, 3, false, {{"one", 1}}}));
|
||||
}
|
||||
|
||||
SECTION("operator>>")
|
||||
{
|
||||
std::stringstream ss;
|
||||
ss << "[\"foo\",1,2,3,false,{\"one\":1}]";
|
||||
json j;
|
||||
ss >> j;
|
||||
CHECK(j == json({"foo", 1, 2, 3, false, {{"one", 1}}}));
|
||||
}
|
||||
|
||||
SECTION("user-defined string literal")
|
||||
{
|
||||
CHECK("[\"foo\",1,2,3,false,{\"one\":1}]"_json == json({"foo", 1, 2, 3, false, {{"one", 1}}}));
|
||||
}
|
||||
}
|
||||
|
||||
SECTION("string literal")
|
||||
SECTION("unsuccessful deserialization")
|
||||
{
|
||||
auto s = "[\"foo\",1,2,3,false,{\"one\":1}]";
|
||||
json j = json::parse(s);
|
||||
CHECK(j == json({"foo", 1, 2, 3, false, {{"one", 1}}}));
|
||||
}
|
||||
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_t")
|
||||
{
|
||||
json::string_t s = "[\"foo\",1,2,3,false,{\"one\":1}]";
|
||||
json j = json::parse(s);
|
||||
CHECK(j == json({"foo", 1, 2, 3, false, {{"one", 1}}}));
|
||||
}
|
||||
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;
|
||||
j << ss;
|
||||
CHECK(j == json({"foo", 1, 2, 3, false, {{"one", 1}}}));
|
||||
}
|
||||
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;
|
||||
ss >> j;
|
||||
CHECK(j == json({"foo", 1, 2, 3, false, {{"one", 1}}}));
|
||||
}
|
||||
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("[\"foo\",1,2,3,false,{\"one\":1}]"_json == json({"foo", 1, 2, 3, false, {{"one", 1}}}));
|
||||
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 ']'");
|
||||
}
|
||||
}
|
||||
|
||||
SECTION("contiguous containers")
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue