12#error JSON_TEST_SRC must point to test source directory
17static std::string
rtrim(std::string s) {
18 s.erase(s.find_last_not_of(
" \n\r\t") + 1);
22static void runtest(std::string filename,
const std::string &jdata) {
23 std::string
prefix = filename.substr(0, 4);
25 bool wantPass = (
prefix ==
"pass") || (
prefix ==
"roun");
26 bool wantFail = (
prefix ==
"fail");
27 bool wantRoundTrip = (
prefix ==
"roun");
28 assert(wantPass || wantFail);
31 bool testResult = val.
read(jdata);
34 assert(testResult ==
true);
36 assert(testResult ==
false);
40 std::string odata = val.
write(0, 0);
46 std::string basename(filename_);
47 std::string filename =
srcdir +
"/" + basename;
48 FILE *f =
fopen(filename.c_str(),
"r");
55 int bread = fread(buf, 1,
sizeof(buf), f);
58 std::string s(buf, bread);
69 "fail10.json",
"fail11.json",
"fail12.json",
"fail13.json",
"fail14.json",
70 "fail15.json",
"fail16.json",
"fail17.json",
72 "fail19.json",
"fail1.json",
"fail20.json",
"fail21.json",
"fail22.json",
73 "fail23.json",
"fail24.json",
"fail25.json",
"fail26.json",
"fail27.json",
74 "fail28.json",
"fail29.json",
"fail2.json",
"fail30.json",
"fail31.json",
75 "fail32.json",
"fail33.json",
"fail34.json",
"fail35.json",
"fail36.json",
86 "fail5.json",
"fail6.json",
"fail7.json",
"fail8.json",
88 "pass1.json",
"pass2.json",
"pass3.json",
"pass4.json",
103 testResult = val.
read(
"[\"\\u0022\"]");
105 assert(val[0].get_str() ==
"\"");
107 testResult = val.
read(
"[\"\\u0191\"]");
109 assert(val[0].get_str() ==
"\xc6\x91");
111 testResult = val.
read(
"[\"\\u2191\"]");
113 assert(val[0].get_str() ==
"\xe2\x86\x91");
115 testResult = val.
read(
"[\"\\ud834\\udd61\"]");
117 assert(val[0].get_str() ==
"\xf0\x9d\x85\xa1");
121 char buf[] =
"___[1,2,3]___";
126int main(
int argc,
char *argv[]) {
std::string write(unsigned int prettyIndent=0, unsigned int indentLevel=0) const
bool read(std::string_view raw)
FILE * fopen(const fs::path &p, const char *mode)
int main(int argc, char *argv[])
static const char * filenames[]
static std::string rtrim(std::string s)
void unescape_unicode_test()
static void runtest(std::string filename, const std::string &jdata)
static void runtest_file(const char *filename_)
std::string srcdir(JSON_TEST_SRC)