mirror of
https://github.com/nlohmann/json.git
synced 2026-03-16 22:15:59 +00:00
📝 add documentation for JSON Lines (#3247)
This commit is contained in:
@@ -1065,6 +1065,48 @@ TEST_CASE("deserialization")
|
||||
"start_array()"
|
||||
}));
|
||||
}
|
||||
|
||||
SECTION("JSON Lines")
|
||||
{
|
||||
SECTION("Example file")
|
||||
{
|
||||
std::stringstream ss;
|
||||
ss << R"({"name": "Gilbert", "wins": [["straight", "7♣"], ["one pair", "10♥"]]}
|
||||
{"name": "Alexa", "wins": [["two pair", "4♠"], ["two pair", "9♠"]]}
|
||||
{"name": "May", "wins": []}
|
||||
{"name": "Deloise", "wins": [["three of a kind", "5♣"]]}
|
||||
)";
|
||||
|
||||
std::string line;
|
||||
int object_count = 0;
|
||||
while (std::getline(ss, line))
|
||||
{
|
||||
++object_count;
|
||||
CHECK(json::accept(line));
|
||||
}
|
||||
|
||||
CHECK(object_count == 4);
|
||||
}
|
||||
|
||||
SECTION("Example file without trailing newline")
|
||||
{
|
||||
std::stringstream ss;
|
||||
ss << R"({"name": "Gilbert", "wins": [["straight", "7♣"], ["one pair", "10♥"]]}
|
||||
{"name": "Alexa", "wins": [["two pair", "4♠"], ["two pair", "9♠"]]}
|
||||
{"name": "May", "wins": []}
|
||||
{"name": "Deloise", "wins": [["three of a kind", "5♣"]]})";
|
||||
|
||||
std::string line;
|
||||
int object_count = 0;
|
||||
while (std::getline(ss, line))
|
||||
{
|
||||
++object_count;
|
||||
CHECK(json::accept(line));
|
||||
}
|
||||
|
||||
CHECK(object_count == 4);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE_TEMPLATE("deserialization of different character types (ASCII)", T,
|
||||
|
||||
Reference in New Issue
Block a user