]> git.ozlabs.org Git - ccan/blob - ccan/cdump/test/run-multiline.c
cdump: handle multi-line preprocessor directives.
[ccan] / ccan / cdump / test / run-multiline.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(30);
14
15         /* Multi-line preprocessor statement. */
16         defs = cdump_extract(ctx,
17                              "#if \\\n"
18                              "SOME\\\n"
19                              "THING\n"
20                              "enum foo { BAR };", &problems);
21         ok1(defs);
22         ok1(tal_parent(defs) == ctx);
23
24         ok1(strmap_empty(&defs->structs));
25         ok1(strmap_empty(&defs->unions));
26         t = strmap_get(&defs->enums, "foo");
27         ok1(t);
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);
33
34         defs = cdump_extract(ctx,
35                              "enum foo {\n"
36                              "#if \\\n"
37                              "SOME\\\n"
38                              "THING\n"
39                              " BAR };", &problems);
40         ok1(defs);
41         ok1(tal_parent(defs) == ctx);
42
43         ok1(strmap_empty(&defs->structs));
44         ok1(strmap_empty(&defs->unions));
45         t = strmap_get(&defs->enums, "foo");
46         ok1(t);
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);
52
53         /* Multi-line "one-line" comment. */
54         defs = cdump_extract(ctx,
55                              "enum foo {\n"
56                              "// Comment \\\n"
57                              "SOME\\\n"
58                              "THING\n"
59                              " BAR };", &problems);
60         ok1(defs);
61         ok1(tal_parent(defs) == ctx);
62
63         ok1(strmap_empty(&defs->structs));
64         ok1(strmap_empty(&defs->unions));
65         t = strmap_get(&defs->enums, "foo");
66         ok1(t);
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);
72
73         /* This exits depending on whether all tests passed */
74         return exit_status();
75 }