2016-08-04 05:24:46 +00:00
|
|
|
/*
|
|
|
|
__ _____ _____ _____
|
|
|
|
__| | __| | | | JSON for Modern C++ (test suite)
|
2017-12-29 17:31:13 +00:00
|
|
|
| | |__ | | | | | | version 3.0.1
|
2016-08-04 05:24:46 +00:00
|
|
|
|_____|_____|_____|_|___| https://github.com/nlohmann/json
|
|
|
|
|
|
|
|
Licensed under the MIT License <http://opensource.org/licenses/MIT>.
|
2017-01-02 08:40:00 +00:00
|
|
|
Copyright (c) 2013-2017 Niels Lohmann <http://nlohmann.me>.
|
2016-08-04 05:24:46 +00:00
|
|
|
|
|
|
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
of this software and associated documentation files (the "Software"), to deal
|
|
|
|
in the Software without restriction, including without limitation the rights
|
|
|
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
copies of the Software, and to permit persons to whom the Software is
|
|
|
|
furnished to do so, subject to the following conditions:
|
|
|
|
|
|
|
|
The above copyright notice and this permission notice shall be included in all
|
|
|
|
copies or substantial portions of the Software.
|
|
|
|
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
|
|
SOFTWARE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "catch.hpp"
|
2016-08-04 19:55:47 +00:00
|
|
|
|
|
|
|
#include "json.hpp"
|
|
|
|
using nlohmann::json;
|
|
|
|
|
|
|
|
TEST_CASE("serialization")
|
|
|
|
{
|
|
|
|
SECTION("operator<<")
|
|
|
|
{
|
|
|
|
SECTION("no given width")
|
|
|
|
{
|
|
|
|
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("given width")
|
|
|
|
{
|
|
|
|
std::stringstream ss;
|
|
|
|
json j = {"foo", 1, 2, 3, false, {{"one", 1}}};
|
|
|
|
ss << std::setw(4) << j;
|
|
|
|
CHECK(ss.str() ==
|
|
|
|
"[\n \"foo\",\n 1,\n 2,\n 3,\n false,\n {\n \"one\": 1\n }\n]");
|
|
|
|
}
|
2017-05-07 17:27:40 +00:00
|
|
|
|
|
|
|
SECTION("given fill")
|
|
|
|
{
|
|
|
|
std::stringstream ss;
|
|
|
|
json j = {"foo", 1, 2, 3, false, {{"one", 1}}};
|
|
|
|
ss << std::setw(1) << std::setfill('\t') << j;
|
|
|
|
CHECK(ss.str() ==
|
|
|
|
"[\n\t\"foo\",\n\t1,\n\t2,\n\t3,\n\tfalse,\n\t{\n\t\t\"one\": 1\n\t}\n]");
|
|
|
|
}
|
2016-08-04 19:55:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
SECTION("operator>>")
|
|
|
|
{
|
|
|
|
SECTION("no given width")
|
|
|
|
{
|
|
|
|
std::stringstream ss;
|
|
|
|
json j = {"foo", 1, 2, 3, false, {{"one", 1}}};
|
|
|
|
j >> ss;
|
|
|
|
CHECK(ss.str() == "[\"foo\",1,2,3,false,{\"one\":1}]");
|
|
|
|
}
|
|
|
|
|
|
|
|
SECTION("given width")
|
|
|
|
{
|
|
|
|
std::stringstream ss;
|
|
|
|
json j = {"foo", 1, 2, 3, false, {{"one", 1}}};
|
|
|
|
ss.width(4);
|
|
|
|
j >> ss;
|
|
|
|
CHECK(ss.str() ==
|
|
|
|
"[\n \"foo\",\n 1,\n 2,\n 3,\n false,\n {\n \"one\": 1\n }\n]");
|
|
|
|
}
|
2017-05-07 17:27:40 +00:00
|
|
|
|
|
|
|
SECTION("given fill")
|
|
|
|
{
|
|
|
|
std::stringstream ss;
|
|
|
|
json j = {"foo", 1, 2, 3, false, {{"one", 1}}};
|
|
|
|
ss.width(1);
|
|
|
|
ss.fill('\t');
|
|
|
|
j >> ss;
|
|
|
|
CHECK(ss.str() ==
|
|
|
|
"[\n\t\"foo\",\n\t1,\n\t2,\n\t3,\n\tfalse,\n\t{\n\t\t\"one\": 1\n\t}\n]");
|
|
|
|
}
|
2016-08-04 19:55:47 +00:00
|
|
|
}
|
|
|
|
}
|