#include #include #include 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); } int main() { 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); return 0; }