Commit 16af7712 authored by Niels Lohmann's avatar Niels Lohmann

added roundtrip test for the Big List of Naughty Strings

parent bf8fdac9
...@@ -839,7 +839,7 @@ $ make json_unit -Ctest ...@@ -839,7 +839,7 @@ $ make json_unit -Ctest
$ ./test/json_unit "*"" $ ./test/json_unit "*""
=============================================================================== ===============================================================================
All tests passed (11202052 assertions in 47 test cases) All tests passed (11202549 assertions in 47 test cases)
``` ```
Alternatively, you can use [CMake](https://cmake.org) and run Alternatively, you can use [CMake](https://cmake.org) and run
......
...@@ -816,13 +816,56 @@ TEST_CASE("nst's JSONTestSuite") ...@@ -816,13 +816,56 @@ TEST_CASE("nst's JSONTestSuite")
} }
} }
// from http://stackoverflow.com/a/25829178/266378
std::string trim(const std::string& str)
{
size_t first = str.find_first_not_of(' ');
if (std::string::npos == first)
{
return str;
}
size_t last = str.find_last_not_of(' ');
return str.substr(first, (last - first + 1));
}
TEST_CASE("Big List of Naughty Strings") TEST_CASE("Big List of Naughty Strings")
{ {
// test from https://github.com/minimaxir/big-list-of-naughty-strings // test from https://github.com/minimaxir/big-list-of-naughty-strings
SECTION("blns.json") SECTION("parsing blns.json")
{ {
std::ifstream f("test/data/big-list-of-naughty-strings/blns.json"); std::ifstream f("test/data/big-list-of-naughty-strings/blns.json");
json j; json j;
CHECK_NOTHROW(j << f); CHECK_NOTHROW(j << f);
} }
// check if parsed strings roundtrip
// https://www.reddit.com/r/cpp/comments/5qpbie/json_form_modern_c_version_210/dd12mpq/
SECTION("roundtripping")
{
std::ifstream f("test/data/big-list-of-naughty-strings/blns.json");
while (not f.eof())
{
// read line
std::string line;
getline(f, line);
// trim whitespace
line = trim(line);
// remove trailing comma
line = line.substr(0, line.find_last_of(","));
// discard lines without at least two characters (quotes)
if (line.size() < 2)
{
continue;
}
// check roundtrip
CAPTURE(line);
json j = json::parse(line);
CHECK(j.dump() == line);
}
}
} }
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