X-Git-Url: http://git.ozlabs.org/?p=ccan;a=blobdiff_plain;f=ccan%2Fjson_escape%2Ftest%2Frun.c;fp=ccan%2Fjson_escape%2Ftest%2Frun.c;h=9d8b049c37d6bec89c8681f31f09b14a076c86f9;hp=0000000000000000000000000000000000000000;hb=45f9ce170fe09bca014d874ffaa13b900c8285ba;hpb=7623d0829a63e7f95ed6f116b7e9f2f4a023e8e7 diff --git a/ccan/json_escape/test/run.c b/ccan/json_escape/test/run.c new file mode 100644 index 00000000..9d8b049c --- /dev/null +++ b/ccan/json_escape/test/run.c @@ -0,0 +1,44 @@ +#include +/* Include the C files directly. */ +#include +#include + +int main(void) +{ + const tal_t *ctx = tal(NULL, char); + struct json_escape *e; + + /* This is how many tests you plan to run */ + plan_tests(6); + + e = json_escape(ctx, "Hello"); + ok1(!strcmp(e->s, "Hello")); + ok1(!strcmp(json_escape_unescape(ctx, e), + "Hello")); + + e = json_escape(ctx, + "\\\b\f\n\r\t\"" + "\\\\\\b\\f\\n\\r\\t\\\""); + ok1(!strcmp(e->s, + "\\\\\\b\\f\\n\\r\\t\\\"" + "\\\\\\\\\\\\b\\\\f\\\\n\\\\r\\\\t\\\\\\\"")); + ok1(!strcmp(json_escape_unescape(ctx, e), + "\\\b\f\n\r\t\"" + "\\\\\\b\\f\\n\\r\\t\\\"")); + + /* This one doesn't escape the already-escaped chars */ + e = json_partial_escape(ctx, + "\\\b\f\n\r\t\"" + "\\\\\\b\\f\\n\\r\\t\\\""); + ok1(!strcmp(e->s, + "\\\\\\b\\f\\n\\r\\t\\\"" + "\\\\\\b\\f\\n\\r\\t\\\"")); + ok1(!strcmp(json_escape_unescape(ctx, e), + "\\\b\f\n\r\t\"" + "\\\b\f\n\r\t\"")); + + tal_free(ctx); + + /* This exits depending on whether all tests passed */ + return exit_status(); +}