more unit tests
This commit is contained in:
parent
29a8d43d5a
commit
4cd341d4db
2 changed files with 53 additions and 2 deletions
|
@ -1315,24 +1315,28 @@ class basic_json
|
|||
{
|
||||
return "null";
|
||||
}
|
||||
|
||||
case (value_t::object):
|
||||
{
|
||||
return "object";
|
||||
}
|
||||
|
||||
case (value_t::array):
|
||||
{
|
||||
return "array";
|
||||
}
|
||||
|
||||
case (value_t::string):
|
||||
{
|
||||
return "string";
|
||||
}
|
||||
|
||||
case (value_t::boolean):
|
||||
{
|
||||
return "boolean";
|
||||
}
|
||||
case (value_t::number_integer):
|
||||
case (value_t::number_float):
|
||||
|
||||
default:
|
||||
{
|
||||
return "number";
|
||||
}
|
||||
|
|
|
@ -3821,3 +3821,50 @@ TEST_CASE("lexicographical comparison operators")
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("serialization")
|
||||
{
|
||||
SECTION("operator<<")
|
||||
{
|
||||
std::stringstream ss;
|
||||
json j = {"foo", 1, 2, 3, false, {{"one", 1}}};
|
||||
ss << j;
|
||||
CHECK(ss.str() == "[\"foo\",1,2,3,false,{\"one\":1}]");
|
||||
}
|
||||
|
||||
SECTION("operator>>")
|
||||
{
|
||||
std::stringstream ss;
|
||||
json j = {"foo", 1, 2, 3, false, {{"one", 1}}};
|
||||
j >> ss;
|
||||
CHECK(ss.str() == "[\"foo\",1,2,3,false,{\"one\":1}]");
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("deserialization")
|
||||
{
|
||||
SECTION("string")
|
||||
{
|
||||
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("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}}}));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue