2024-07-23 13:31:51 +00:00
|
|
|
#include <libjsonincpp/jsonobj.h>
|
|
|
|
#include <libjsonincpp/string_representation.h>
|
|
|
|
#include <assert.h>
|
|
|
|
|
|
|
|
using namespace json;
|
|
|
|
|
|
|
|
void prettyprint_json(const JSON& obj) {
|
|
|
|
printf("%s", generate_str(obj, print_pretty).c_str());
|
|
|
|
}
|
|
|
|
|
2024-08-09 19:50:55 +00:00
|
|
|
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-09 19:50:55 +00:00
|
|
|
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;
|
|
|
|
}
|