Add test witnessing unescaping bug
This commit is contained in:
24
src/test.cpp
24
src/test.cpp
@@ -3,6 +3,7 @@
|
||||
#include <cstdio>
|
||||
#include <cstring>
|
||||
|
||||
#include <limits>
|
||||
#include <string>
|
||||
|
||||
#include <doctest.h>
|
||||
@@ -208,10 +209,10 @@ TEST_CASE("parser3") {
|
||||
TEST_CASE("streaming") { testStreaming(json); }
|
||||
|
||||
void doTestUnescapingUtf8(std::string const &escaped,
|
||||
std::string const &expected, bool streaming) {
|
||||
std::string const &expected, int stride) {
|
||||
CAPTURE(escaped);
|
||||
CAPTURE(expected);
|
||||
CAPTURE(streaming);
|
||||
CAPTURE(stride);
|
||||
auto c = noopCallbacks();
|
||||
std::string result;
|
||||
c.on_string_data = +[](void *p, const char *buf, int len) {
|
||||
@@ -220,13 +221,11 @@ void doTestUnescapingUtf8(std::string const &escaped,
|
||||
};
|
||||
parser3::Parser3 parser(&c, &result);
|
||||
auto copy = escaped;
|
||||
if (streaming) {
|
||||
for (int i = 0; i < copy.size(); ++i) {
|
||||
CAPTURE(i);
|
||||
CHECK(parser.parse(copy.data() + i, 1) == parser3::S_AGAIN);
|
||||
}
|
||||
} else {
|
||||
CHECK(parser.parse(copy.data(), copy.size()) == parser3::S_AGAIN);
|
||||
for (int i = 0; i < copy.size(); i += stride) {
|
||||
CAPTURE(i);
|
||||
CHECK(
|
||||
parser.parse(copy.data() + i, std::min<int>(stride, copy.size() - i)) ==
|
||||
parser3::S_AGAIN);
|
||||
}
|
||||
CHECK(parser.parse(nullptr, 0) == parser3::S_OK);
|
||||
CHECK(result.size() == expected.size());
|
||||
@@ -235,8 +234,11 @@ void doTestUnescapingUtf8(std::string const &escaped,
|
||||
|
||||
void testUnescapingUtf8(std::string const &escaped,
|
||||
std::string const &expected) {
|
||||
doTestUnescapingUtf8(escaped, expected, false);
|
||||
doTestUnescapingUtf8(escaped, expected, true);
|
||||
for (int stride = 0; stride < 10; ++stride) {
|
||||
doTestUnescapingUtf8(escaped, expected,
|
||||
stride == 0 ? std::numeric_limits<int>::max()
|
||||
: stride);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("unescaping utf-8") {
|
||||
|
||||
Reference in New Issue
Block a user