]> git.ozlabs.org Git - ccan/blob - ccan/cdump/test/run-arraysize.c
cdump: handle array sizes and comments better.
[ccan] / ccan / cdump / test / run-arraysize.c
1 #include <ccan/cdump/cdump.h>
2 /* Include the C files directly. */
3 #include <ccan/cdump/cdump.c>
4 #include <ccan/tap/tap.h>
5
6 int main(void)
7 {
8         struct cdump_definitions *defs;
9         const struct cdump_type *t;
10         char *ctx = tal(NULL, char), *problems;
11
12         /* This is how many tests you plan to run */
13         plan_tests(20);
14
15         /* unions and comments. */
16         defs = cdump_extract(ctx,
17                              "struct foo {\n"
18                              "  int x[5 */* Comment */7];\n"
19                              "  int y[5// Comment\n"
20                              " * 7];\n"
21                              "  int z[5 *\n"
22                              "#ifdef FOO\n"
23                              " 7\n"
24                              "#endif\n"
25                              "];\n"
26                              "};\n", &problems);
27
28         ok1(defs);
29         ok1(tal_parent(defs) == ctx);
30         ok1(!problems);
31         t = strmap_get(&defs->structs, "foo");
32         ok1(t);
33         ok1(tal_count(t->u.members) == 3);
34         ok1(streq(t->u.members[0].name, "x"));
35         ok1(t->u.members[0].type->kind == CDUMP_ARRAY);
36         ok1(streq(t->u.members[0].type->u.arr.size, "5 * 7"));
37         ok1(t->u.members[0].type->u.arr.type->kind == CDUMP_UNKNOWN);
38         ok1(streq(t->u.members[0].type->u.arr.type->name, "int"));
39
40         ok1(streq(t->u.members[1].name, "y"));
41         ok1(t->u.members[1].type->kind == CDUMP_ARRAY);
42         ok1(streq(t->u.members[1].type->u.arr.size, "5 * 7"));
43         ok1(t->u.members[1].type->u.arr.type->kind == CDUMP_UNKNOWN);
44         ok1(streq(t->u.members[1].type->u.arr.type->name, "int"));
45
46         ok1(streq(t->u.members[2].name, "z"));
47         ok1(t->u.members[2].type->kind == CDUMP_ARRAY);
48         ok1(streq(t->u.members[2].type->u.arr.size, "5 * 7"));
49         ok1(t->u.members[2].type->u.arr.type->kind == CDUMP_UNKNOWN);
50         ok1(streq(t->u.members[2].type->u.arr.type->name, "int"));
51
52         /* This exits depending on whether all tests passed */
53         return exit_status();
54 }