libjsonincpp/src/tests/test0.cpp

55 lines
1.9 KiB
C++
Raw Normal View History

#include <jsonincpp/jsonobj.h>
#include <jsonincpp/string_representation.h>
2024-07-23 13:31:51 +00:00
#include <assert.h>
using namespace json;
void prettyprint_json(const JSON& obj) {
printf("%s", generate_str(obj, print_pretty).c_str());
}
void test2(const JSON& A, const JSON& B, bool answer) {
if ((A == B) == answer)
printf("Test passed\n");
else {
fprintf(stderr, "Test failed");
abort();
}
}
void test(const JSON& A, const JSON& B, bool answer) {
test2(A, B, answer);
test2(B, A, answer);
}
void test_obvious(const JSON& A) {
test(A, A, true);
JSON B = A;
test(B, A, true);
/* Let's get real */
JSON big;
big[1] = A;
test(big, A, false);
big[0] = A;
test(*big[0], *big[1], true);
}
2024-07-23 13:31:51 +00:00
int main() {
2024-08-15 21:01:30 +00:00
json::JSON cba;
cba["boba"] = json::JSON("<>");
printf("%s\n", generate_str(cba["boba"].g(), print_compact).c_str());
// return 0;
test_obvious(parse_str_flawless("{ \"aaa\": true, \"2\":[true]}"));
test_obvious(parse_str_flawless("{ \"aa\": true, \"tttt\": [true, false]}"));
test_obvious(parse_str_flawless("[[[]]]"));
test_obvious(parse_str_flawless("[[[\"asdasdasdasd\", {\"aaa\" : 12311, \"\":\"\"}]]]"));
test(parse_str_flawless("1321231231231231231231231231231231"), parse_str_flawless("-132123123123123123123123123123123123"), false);
test(parse_str_flawless("1321231231231231231231231231231231"), parse_str_flawless("-132123123123123123123.123123123123123"), false);
test(parse_str_flawless("999999999999999999"), parse_str_flawless("999999999999999999"), true);
test(parse_str_flawless("9999999999999999999"), parse_str_flawless("9999999999999999999"), true);
test(parse_str_flawless("132123123123123123123123123123123123"), parse_str_flawless("132123123123123123123123123123123123"), true);
test(parse_str_flawless("{}"), parse_str_flawless("{}"), true);
test(parse_str_flawless("{}"), parse_str_flawless("true"), false);
2024-07-23 13:31:51 +00:00
return 0;
}