Skip to content

Commit fe07257

Browse files
committed
Use enums in global context
1 parent c5b86e9 commit fe07257

2 files changed

Lines changed: 54 additions & 0 deletions

File tree

tests/unit/enum_int_interop.cpp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,22 @@ typedef enum {
1515
TAG_TWO = 2,
1616
} Tag;
1717

18+
struct Entry {
19+
const char *name;
20+
Color color;
21+
Option opt;
22+
};
23+
24+
static Color global_color = GREEN;
25+
static Option global_opt = OPT_B;
26+
static Tag global_tag = TAG_TWO;
27+
28+
static Entry entries[3] = {
29+
{"first", RED, OPT_NONE},
30+
{"second", GREEN, OPT_A},
31+
{"third", BLUE, OPT_C},
32+
};
33+
1834
int as_int(Color c) { return c; }
1935

2036
int classify_option(int option) {
@@ -113,5 +129,16 @@ int main() {
113129
int extra = (int)RED + (int)GREEN + (int)BLUE;
114130
assert(extra == 0 + 1 + 2);
115131

132+
assert(global_color == GREEN);
133+
assert(global_opt == OPT_B);
134+
assert(global_tag == TAG_TWO);
135+
136+
assert(entries[0].color == RED);
137+
assert(entries[0].opt == OPT_NONE);
138+
assert(entries[1].color == GREEN);
139+
assert(entries[1].opt == OPT_A);
140+
assert(entries[2].color == BLUE);
141+
assert(entries[2].opt == OPT_C);
142+
116143
return 0;
117144
}

tests/unit/enum_int_interop_c.c

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,22 @@ typedef enum {
1515
TAG_TWO = 2,
1616
} Tag;
1717

18+
struct Entry {
19+
const char *name;
20+
enum Color color;
21+
enum Option opt;
22+
};
23+
24+
static enum Color global_color = GREEN;
25+
static enum Option global_opt = OPT_B;
26+
static Tag global_tag = TAG_TWO;
27+
28+
static struct Entry entries[3] = {
29+
{"first", RED, OPT_NONE},
30+
{"second", GREEN, OPT_A},
31+
{"third", BLUE, OPT_C},
32+
};
33+
1834
int as_int(enum Color c) { return c; }
1935

2036
int classify_option(int option) {
@@ -113,5 +129,16 @@ int main() {
113129
int extra = (int)RED + (int)GREEN + (int)BLUE;
114130
assert(extra == 0 + 1 + 2);
115131

132+
assert(global_color == GREEN);
133+
assert(global_opt == OPT_B);
134+
assert(global_tag == TAG_TWO);
135+
136+
assert(entries[0].color == RED);
137+
assert(entries[0].opt == OPT_NONE);
138+
assert(entries[1].color == GREEN);
139+
assert(entries[1].opt == OPT_A);
140+
assert(entries[2].color == BLUE);
141+
assert(entries[2].opt == OPT_C);
142+
116143
return 0;
117144
}

0 commit comments

Comments
 (0)