Fixes issue 388 (#394)
This commit is contained in:
parent
2bd65fa444
commit
fc6133b58f
|
@ -136,8 +136,8 @@ cat <<< '
|
|||
#include "simdjson.h"
|
||||
#include "simdjson.cpp"
|
||||
int main(int argc, char *argv[]) {
|
||||
if(argc < 3) {
|
||||
std::cerr << "Please specify filenames " << std::endl;
|
||||
if(argc < 2) {
|
||||
std::cerr << "Please specify at least one file name. " << std::endl;
|
||||
}
|
||||
const char * filename = argv[1];
|
||||
simdjson::padded_string p = simdjson::get_corpus(filename);
|
||||
|
@ -147,6 +147,9 @@ int main(int argc, char *argv[]) {
|
|||
} else {
|
||||
std::cout << "build_parsed_json valid" << std::endl;
|
||||
}
|
||||
if(argc == 2) {
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
//JsonStream
|
||||
const char * filename2 = argv[2];
|
||||
|
@ -157,7 +160,7 @@ int main(int argc, char *argv[]) {
|
|||
|
||||
while (parse_res == simdjson::SUCCESS_AND_HAS_MORE) {
|
||||
parse_res = js.json_parse(pj2);
|
||||
}
|
||||
}
|
||||
|
||||
if( ! pj2.is_valid()) {
|
||||
std::cout << "JsonStream not valid" << std::endl;
|
||||
|
|
|
@ -198,7 +198,7 @@ bool ParsedJson::print_json(std::ostream &os) const {
|
|||
memcpy(&string_length, string_buf + payload, sizeof(uint32_t));
|
||||
print_with_escapes(
|
||||
(const unsigned char *)(string_buf + payload + sizeof(uint32_t)),
|
||||
string_length);
|
||||
os, string_length);
|
||||
os << '"';
|
||||
break;
|
||||
case 'l': // we have a long int
|
||||
|
|
|
@ -168,6 +168,36 @@ bool bad_example() {
|
|||
}
|
||||
return true;
|
||||
}
|
||||
// returns true if successful
|
||||
bool stable_test() {
|
||||
std::string json = "{"
|
||||
"\"Image\":{"
|
||||
"\"Width\":800,"
|
||||
"\"Height\":600,"
|
||||
"\"Title\":\"View from 15th Floor\","
|
||||
"\"Thumbnail\":{"
|
||||
"\"Url\":\"http://www.example.com/image/481989943\","
|
||||
"\"Height\":125,"
|
||||
"\"Width\":100"
|
||||
"},"
|
||||
"\"Animated\":false,"
|
||||
"\"IDs\":[116,943.3,234,38793]"
|
||||
"}"
|
||||
"}";
|
||||
simdjson::ParsedJson pj = simdjson::build_parsed_json(json);
|
||||
std::ostringstream myStream;
|
||||
if( ! pj.print_json(myStream) ) {
|
||||
std::cout << "cannot print it out? " << std::endl;
|
||||
return false;
|
||||
}
|
||||
std::string newjson = myStream.str();
|
||||
if(json != newjson) {
|
||||
std::cout << "serialized json differs!" << std::endl;
|
||||
std::cout << json << std::endl;
|
||||
std::cout << newjson << std::endl;
|
||||
}
|
||||
return newjson == json;
|
||||
}
|
||||
|
||||
// returns true if successful
|
||||
bool navigate_test() {
|
||||
|
@ -295,6 +325,8 @@ bool skyprophet_test() {
|
|||
|
||||
int main() {
|
||||
std::cout << "Running basic tests." << std::endl;
|
||||
if(!stable_test())
|
||||
return EXIT_FAILURE;
|
||||
if(!bad_example())
|
||||
return EXIT_FAILURE;
|
||||
if(!number_test_powers_of_two())
|
||||
|
|
Loading…
Reference in New Issue