X-Git-Url: https://git.ozlabs.org/?a=blobdiff_plain;f=ccan%2Fcdump%2Ftest%2Frun-multiline.c;fp=ccan%2Fcdump%2Ftest%2Frun-multiline.c;h=50f4e75bdb10b50493a0e5b1016d1b7614e72432;hb=3d6fe8391ab0b6e6b9da0a715a4a8308303fc72e;hp=0000000000000000000000000000000000000000;hpb=1e5f5ecc5f6e75ac28c9b03f10837a7231dbca8e;p=ccan diff --git a/ccan/cdump/test/run-multiline.c b/ccan/cdump/test/run-multiline.c new file mode 100644 index 00000000..50f4e75b --- /dev/null +++ b/ccan/cdump/test/run-multiline.c @@ -0,0 +1,75 @@ +#include +/* Include the C files directly. */ +#include +#include + +int main(void) +{ + struct cdump_definitions *defs; + const struct cdump_type *t; + char *ctx = tal(NULL, char), *problems; + + /* This is how many tests you plan to run */ + plan_tests(30); + + /* Multi-line preprocessor statement. */ + defs = cdump_extract(ctx, + "#if \\\n" + "SOME\\\n" + "THING\n" + "enum foo { BAR };", &problems); + ok1(defs); + ok1(tal_parent(defs) == ctx); + + ok1(strmap_empty(&defs->structs)); + ok1(strmap_empty(&defs->unions)); + t = strmap_get(&defs->enums, "foo"); + ok1(t); + ok1(t->kind == CDUMP_ENUM); + ok1(streq(t->name, "foo")); + ok1(tal_count(t->u.enum_vals) == 1); + ok1(streq(t->u.enum_vals[0].name, "BAR")); + ok1(!t->u.enum_vals[0].value); + + defs = cdump_extract(ctx, + "enum foo {\n" + "#if \\\n" + "SOME\\\n" + "THING\n" + " BAR };", &problems); + ok1(defs); + ok1(tal_parent(defs) == ctx); + + ok1(strmap_empty(&defs->structs)); + ok1(strmap_empty(&defs->unions)); + t = strmap_get(&defs->enums, "foo"); + ok1(t); + ok1(t->kind == CDUMP_ENUM); + ok1(streq(t->name, "foo")); + ok1(tal_count(t->u.enum_vals) == 1); + ok1(streq(t->u.enum_vals[0].name, "BAR")); + ok1(!t->u.enum_vals[0].value); + + /* Multi-line "one-line" comment. */ + defs = cdump_extract(ctx, + "enum foo {\n" + "// Comment \\\n" + "SOME\\\n" + "THING\n" + " BAR };", &problems); + ok1(defs); + ok1(tal_parent(defs) == ctx); + + ok1(strmap_empty(&defs->structs)); + ok1(strmap_empty(&defs->unions)); + t = strmap_get(&defs->enums, "foo"); + ok1(t); + ok1(t->kind == CDUMP_ENUM); + ok1(streq(t->name, "foo")); + ok1(tal_count(t->u.enum_vals) == 1); + ok1(streq(t->u.enum_vals[0].name, "BAR")); + ok1(!t->u.enum_vals[0].value); + + /* This exits depending on whether all tests passed */ + return exit_status(); +}