1 #include <ccan/cdump/cdump.h>
2 /* Include the C files directly. */
3 #include <ccan/cdump/cdump.c>
4 #include <ccan/tap/tap.h>
8 struct cdump_definitions *defs;
9 const struct cdump_type *t;
10 char *ctx = tal(NULL, char), *problems;
12 /* This is how many tests you plan to run */
15 /* Multi-line preprocessor statement. */
16 defs = cdump_extract(ctx,
20 "enum foo { BAR };", &problems);
22 ok1(tal_parent(defs) == ctx);
24 ok1(strmap_empty(&defs->structs));
25 ok1(strmap_empty(&defs->unions));
26 t = strmap_get(&defs->enums, "foo");
28 ok1(t->kind == CDUMP_ENUM);
29 ok1(streq(t->name, "foo"));
30 ok1(tal_count(t->u.enum_vals) == 1);
31 ok1(streq(t->u.enum_vals[0].name, "BAR"));
32 ok1(!t->u.enum_vals[0].value);
34 defs = cdump_extract(ctx,
39 " BAR };", &problems);
41 ok1(tal_parent(defs) == ctx);
43 ok1(strmap_empty(&defs->structs));
44 ok1(strmap_empty(&defs->unions));
45 t = strmap_get(&defs->enums, "foo");
47 ok1(t->kind == CDUMP_ENUM);
48 ok1(streq(t->name, "foo"));
49 ok1(tal_count(t->u.enum_vals) == 1);
50 ok1(streq(t->u.enum_vals[0].name, "BAR"));
51 ok1(!t->u.enum_vals[0].value);
53 /* Multi-line "one-line" comment. */
54 defs = cdump_extract(ctx,
59 " BAR };", &problems);
61 ok1(tal_parent(defs) == ctx);
63 ok1(strmap_empty(&defs->structs));
64 ok1(strmap_empty(&defs->unions));
65 t = strmap_get(&defs->enums, "foo");
67 ok1(t->kind == CDUMP_ENUM);
68 ok1(streq(t->name, "foo"));
69 ok1(tal_count(t->u.enum_vals) == 1);
70 ok1(streq(t->u.enum_vals[0].name, "BAR"));
71 ok1(!t->u.enum_vals[0].value);
73 /* This exits depending on whether all tests passed */