Rename pj -> doc, fix a few other idioms
This commit is contained in:
parent
e3efbcddc1
commit
90a7503181
|
@ -33,19 +33,15 @@ static void parse_and_validate(const std::string src, T expected) {
|
|||
std::cout << "src: " << src << ", ";
|
||||
const padded_string pstr{src};
|
||||
simdjson::document::parser parser;
|
||||
auto [pj, error] = parser.parse(pstr);
|
||||
if(error) {
|
||||
printf("could not parse\n");
|
||||
abort();
|
||||
}
|
||||
|
||||
|
||||
bool result;
|
||||
if constexpr (std::is_same<int64_t, T>::value) {
|
||||
int64_t actual = pj.root().as_object()["key"].as_int64_t();
|
||||
auto [actual, error] = parser.parse(pstr).as_object()["key"].as_int64_t();
|
||||
if (error) { std::cerr << error << std::endl; abort(); }
|
||||
result = (expected == actual);
|
||||
} else {
|
||||
uint64_t actual = pj.root().as_object()["key"].as_uint64_t();
|
||||
auto [actual, error] = parser.parse(pstr).as_object()["key"].as_uint64_t();
|
||||
if (error) { std::cerr << error << std::endl; abort(); }
|
||||
result = (expected == actual);
|
||||
}
|
||||
std::cout << std::boolalpha << "test: " << result << std::endl;
|
||||
|
@ -59,31 +55,20 @@ static bool parse_and_check_signed(const std::string src) {
|
|||
std::cout << "src: " << src << ", expecting signed" << std::endl;
|
||||
const padded_string pstr{src};
|
||||
simdjson::document::parser parser;
|
||||
auto [pj, error] = parser.parse(pstr);
|
||||
if(error) {
|
||||
printf("could not parse\n");
|
||||
abort();
|
||||
}
|
||||
auto [v,e] = pj.root().as_object()["key"];
|
||||
return v.is_integer() && v.is_number();
|
||||
auto [value, error] = parser.parse(pstr).as_object()["key"];
|
||||
if (error) { std::cerr << error << std::endl; abort(); }
|
||||
return value.is_integer() && value.is_number();
|
||||
}
|
||||
|
||||
|
||||
static bool parse_and_check_unsigned(const std::string src) {
|
||||
std::cout << "src: " << src << ", expecting signed" << std::endl;
|
||||
const padded_string pstr{src};
|
||||
simdjson::document::parser parser;
|
||||
auto [pj, error] = parser.parse(pstr);
|
||||
if(error) {
|
||||
printf("could not parse\n");
|
||||
abort();
|
||||
}
|
||||
auto [v,e] = pj.root().as_object()["key"];
|
||||
return v.is_unsigned_integer() && v.is_number();
|
||||
auto [value, error] = parser.parse(pstr).as_object()["key"];
|
||||
if (error) { std::cerr << error << std::endl; abort(); }
|
||||
return value.is_unsigned_integer() && value.is_number();
|
||||
}
|
||||
|
||||
|
||||
|
||||
int main() {
|
||||
using std::numeric_limits;
|
||||
constexpr auto int64_max = numeric_limits<int64_t>::max();
|
||||
|
|
|
@ -70,7 +70,7 @@ bool validate(const char *dirname) {
|
|||
return EXIT_FAILURE;
|
||||
}
|
||||
simdjson::document::parser parser;
|
||||
auto [pj, errorcode] = parser.parse(p);
|
||||
auto [doc, errorcode] = parser.parse(p);
|
||||
++how_many;
|
||||
printf("%s\n", errorcode == simdjson::error_code::SUCCESS ? "ok" : "invalid");
|
||||
if (contains("EXCLUDE", name)) {
|
||||
|
|
|
@ -179,7 +179,7 @@ bool validate(const char *dirname) {
|
|||
invalid_count = 0;
|
||||
total_count += float_count + int_count + invalid_count;
|
||||
simdjson::document::parser parser;
|
||||
auto [pj, err] = parser.parse(p);
|
||||
auto [doc, err] = parser.parse(p);
|
||||
bool isok = (err == simdjson::error_code::SUCCESS);
|
||||
if (int_count + float_count + invalid_count > 0) {
|
||||
printf("File %40s %s --- integers: %10zu floats: %10zu invalid: %10zu "
|
||||
|
|
|
@ -8,12 +8,9 @@ int main() {
|
|||
const char *filename = JSON_TEST_PATH;
|
||||
padded_string p = get_corpus(filename);
|
||||
document::parser parser;
|
||||
auto [pj, errorcode] = parser.parse(p);
|
||||
if(errorcode != error_code::SUCCESS) {
|
||||
std::cerr << error_message(errorcode) << std::endl;
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
if(!pj.is_valid()) {
|
||||
auto [doc, error] = parser.parse(p);
|
||||
if(error) {
|
||||
std::cerr << error << std::endl;
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
return EXIT_SUCCESS;
|
||||
|
|
|
@ -348,7 +348,7 @@ bool validate(const char *dirname) {
|
|||
total_string_length = 0;
|
||||
empty_string = 0;
|
||||
simdjson::document::parser parser;
|
||||
auto [pj, err] = parser.parse(p);
|
||||
auto [doc, err] = parser.parse(p);
|
||||
bool isok = (err == simdjson::error_code::SUCCESS);
|
||||
free(big_buffer);
|
||||
if (good_string > 0) {
|
||||
|
|
Loading…
Reference in New Issue