12#error JSON_TEST_SRC must point to test source directory
17static std::string
rtrim(std::string
s)
19 s.erase(
s.find_last_not_of(
" \n\r\t")+1);
23static void runtest(std::string filename,
const std::string& jdata)
25 std::string
prefix = filename.substr(0, 4);
27 bool wantPass = (
prefix ==
"pass") || (
prefix ==
"roun");
28 bool wantFail = (
prefix ==
"fail");
29 bool wantRoundTrip = (
prefix ==
"roun");
30 assert(wantPass || wantFail);
33 bool testResult = val.
read(jdata);
36 assert(testResult ==
true);
38 assert(testResult ==
false);
42 std::string odata = val.
write(0, 0);
49 std::string basename(filename_);
50 std::string filename =
srcdir +
"/" + basename;
51 FILE *f =
fopen(filename.c_str(),
"r");
58 int bread = fread(buf, 1,
sizeof(buf), f);
61 std::string
s(buf, bread);
135 testResult = val.
read(
"[\"\\u0022\"]");
137 assert(val[0].get_str() ==
"\"");
139 testResult = val.
read(
"[\"\\u0191\"]");
141 assert(val[0].get_str() ==
"\xc6\x91");
143 testResult = val.
read(
"[\"\\u2191\"]");
145 assert(val[0].get_str() ==
"\xe2\x86\x91");
147 testResult = val.
read(
"[\"\\ud834\\udd61\"]");
149 assert(val[0].get_str() ==
"\xf0\x9d\x85\xa1");
154 char buf[] =
"___[1,2,3]___";
159int 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)