Fix issue with fuzz test
Previously an implementation could never call on_begin_number or on_end_number and still pass
This commit is contained in:
13
src/fuzz.cpp
13
src/fuzz.cpp
@@ -1,12 +1,11 @@
|
||||
#include "callbacks.h"
|
||||
#include "minify.h"
|
||||
#include "parser3.h"
|
||||
|
||||
#include <simdjson.h>
|
||||
|
||||
std::pair<std::string, parser3::Status> runStreaming(std::string copy) {
|
||||
MinifyState state;
|
||||
auto c = minifyCallbacks();
|
||||
SerializeState state;
|
||||
auto c = serializeCallbacks();
|
||||
parser3::Parser3 parser(&c, &state);
|
||||
for (int i = 0; i < copy.size(); ++i) {
|
||||
auto s = parser.parse(copy.data() + i, 1);
|
||||
@@ -22,8 +21,8 @@ std::pair<std::string, parser3::Status> runStreaming(std::string copy) {
|
||||
}
|
||||
|
||||
std::pair<std::string, parser3::Status> runBatch(std::string copy) {
|
||||
MinifyState state;
|
||||
auto c = minifyCallbacks();
|
||||
SerializeState state;
|
||||
auto c = serializeCallbacks();
|
||||
parser3::Parser3 parser(&c, &state);
|
||||
auto s = parser.parse(copy.data(), copy.size());
|
||||
if (s != parser3::S_AGAIN) {
|
||||
@@ -39,6 +38,10 @@ std::pair<std::string, parser3::Status> runBatch(std::string copy) {
|
||||
void testStreaming(std::string const &json) {
|
||||
auto streaming = runStreaming(json);
|
||||
auto batch = runBatch(json);
|
||||
if (streaming.second == parser3::S_OK) {
|
||||
printf("streaming: %s\n", streaming.first.c_str());
|
||||
printf("batch: %s\n", batch.first.c_str());
|
||||
}
|
||||
if (streaming != batch) {
|
||||
if (streaming.second == batch.second && streaming.second != parser3::S_OK) {
|
||||
// It's ok if the processed data doesn't match if parsing failed
|
||||
|
||||
Reference in New Issue
Block a user