diff options
author | Rusty Russell <rusty@rustcorp.com.au> | 2014-11-11 15:55:54 +1030 |
---|---|---|
committer | Rusty Russell <rusty@rustcorp.com.au> | 2014-11-11 15:58:43 +1030 |
commit | 8e4b51ade59c81082e8a5db9b083e1844a07e816 (patch) | |
tree | 9f5b94e709b5ed8dc64c396746d6fc0ff6848801 | |
parent | 158691ae36fe1da78ec54dbcc0006f603398dae2 (diff) |
cdump: handle , at end of enums.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
-rw-r--r-- | ccan/cdump/cdump.c | 4 | ||||
-rw-r--r-- | ccan/cdump/test/run-enum-comma.c | 34 |
2 files changed, 38 insertions, 0 deletions
diff --git a/ccan/cdump/cdump.c b/ccan/cdump/cdump.c index 20cdb4eb..2680b4d2 100644 --- a/ccan/cdump/cdump.c +++ b/ccan/cdump/cdump.c @@ -428,6 +428,10 @@ static bool tok_take_enum(struct parse_state *ps) do { struct cdump_enum_val *v; + /* GCC extension: comma and end of enum */ + if (tok_is(&ps->toks, "}")) + break; + tal_resize(&e->u.enum_vals, n+1); v = &e->u.enum_vals[n++]; diff --git a/ccan/cdump/test/run-enum-comma.c b/ccan/cdump/test/run-enum-comma.c new file mode 100644 index 00000000..4aaea5e6 --- /dev/null +++ b/ccan/cdump/test/run-enum-comma.c @@ -0,0 +1,34 @@ +#include <ccan/cdump/cdump.h> +/* Include the C files directly. */ +#include <ccan/cdump/cdump.c> +#include <ccan/tap/tap.h> + +int main(void) +{ + struct cdump_definitions *defs; + const struct cdump_type *t; + char *problems; + + /* This is how many tests you plan to run */ + plan_tests(12); + + defs = cdump_extract(NULL, "enum foo { BAR, BAZ, };", &problems); + ok1(defs); + ok1(!problems); + + 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) == 2); + ok1(streq(t->u.enum_vals[0].name, "BAR")); + ok1(!t->u.enum_vals[0].value); + ok1(streq(t->u.enum_vals[1].name, "BAZ")); + ok1(!t->u.enum_vals[1].value); + tal_free(defs); + + /* This exits depending on whether all tests passed */ + return exit_status(); +} |