✅ added roundtrip test for the Big List of Naughty Strings
This commit is contained in:
parent
bf8fdac99a
commit
16af771277
2 changed files with 45 additions and 2 deletions
|
@ -839,7 +839,7 @@ $ make json_unit -Ctest
|
|||
$ ./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
|
||||
|
|
|
@ -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 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");
|
||||
json j;
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue