Skip to content

Commit bdc560d

Browse files
committed
Add tests for private_default_tagged_enum_constructor.
1 parent b2efcc4 commit bdc560d

9 files changed

+275
-0
lines changed

tests/expectations/both/destructor-and-copy-ctor.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ typedef union Baz_i32 {
129129
enum Taz_Tag {
130130
Bar3,
131131
Taz1,
132+
Taz3,
132133
};
133134
typedef uint8_t Taz_Tag;
134135

@@ -137,9 +138,15 @@ typedef struct Taz1_Body {
137138
int32_t _0;
138139
} Taz1_Body;
139140

141+
typedef struct Taz3_Body {
142+
Taz_Tag tag;
143+
OwnedSlice_i32 _0;
144+
} Taz3_Body;
145+
140146
typedef union Taz {
141147
Taz_Tag tag;
142148
Taz1_Body taz1;
149+
Taz3_Body taz3;
143150
} Taz;
144151

145152
enum Tazz_Tag {

tests/expectations/both/destructor-and-copy-ctor.compat.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ enum Taz_Tag
151151
{
152152
Bar3,
153153
Taz1,
154+
Taz3,
154155
};
155156
#ifndef __cplusplus
156157
typedef uint8_t Taz_Tag;
@@ -161,9 +162,15 @@ typedef struct Taz1_Body {
161162
int32_t _0;
162163
} Taz1_Body;
163164

165+
typedef struct Taz3_Body {
166+
Taz_Tag tag;
167+
OwnedSlice_i32 _0;
168+
} Taz3_Body;
169+
164170
typedef union Taz {
165171
Taz_Tag tag;
166172
Taz1_Body taz1;
173+
Taz3_Body taz3;
167174
} Taz;
168175

169176
enum Tazz_Tag

tests/expectations/destructor-and-copy-ctor.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ typedef union {
129129
enum Taz_Tag {
130130
Bar3,
131131
Taz1,
132+
Taz3,
132133
};
133134
typedef uint8_t Taz_Tag;
134135

@@ -137,9 +138,15 @@ typedef struct {
137138
int32_t _0;
138139
} Taz1_Body;
139140

141+
typedef struct {
142+
Taz_Tag tag;
143+
OwnedSlice_i32 _0;
144+
} Taz3_Body;
145+
140146
typedef union {
141147
Taz_Tag tag;
142148
Taz1_Body taz1;
149+
Taz3_Body taz3;
143150
} Taz;
144151

145152
enum Tazz_Tag {

tests/expectations/destructor-and-copy-ctor.compat.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ enum Taz_Tag
151151
{
152152
Bar3,
153153
Taz1,
154+
Taz3,
154155
};
155156
#ifndef __cplusplus
156157
typedef uint8_t Taz_Tag;
@@ -161,9 +162,15 @@ typedef struct {
161162
int32_t _0;
162163
} Taz1_Body;
163164

165+
typedef struct {
166+
Taz_Tag tag;
167+
OwnedSlice_i32 _0;
168+
} Taz3_Body;
169+
164170
typedef union {
165171
Taz_Tag tag;
166172
Taz1_Body taz1;
173+
Taz3_Body taz3;
167174
} Taz;
168175

169176
enum Tazz_Tag

tests/expectations/destructor-and-copy-ctor.cpp

Lines changed: 225 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ template<typename T>
1414
struct OwnedSlice {
1515
uintptr_t len;
1616
T *ptr;
17+
~OwnedSlice() {}
1718
};
1819

1920
template<typename LengthPercentage>
@@ -64,6 +65,81 @@ struct Foo {
6465
Slice4_Body slice4;
6566
};
6667

68+
static Foo Bar() {
69+
Foo result;
70+
result.tag = Tag::Bar;
71+
return result;
72+
}
73+
74+
static Foo Polygon1(const Polygon<T> &a0) {
75+
Foo result;
76+
::new (&result.polygon1._0) (Polygon<T>)(a0);
77+
result.tag = Tag::Polygon1;
78+
return result;
79+
}
80+
81+
static Foo Slice1(const OwnedSlice<T> &a0) {
82+
Foo result;
83+
::new (&result.slice1._0) (OwnedSlice<T>)(a0);
84+
result.tag = Tag::Slice1;
85+
return result;
86+
}
87+
88+
static Foo Slice2(const OwnedSlice<int32_t> &a0) {
89+
Foo result;
90+
::new (&result.slice2._0) (OwnedSlice<int32_t>)(a0);
91+
result.tag = Tag::Slice2;
92+
return result;
93+
}
94+
95+
static Foo Slice3(const FillRule &aFill,
96+
const OwnedSlice<T> &aCoords) {
97+
Foo result;
98+
::new (&result.slice3.fill) (FillRule)(aFill);
99+
::new (&result.slice3.coords) (OwnedSlice<T>)(aCoords);
100+
result.tag = Tag::Slice3;
101+
return result;
102+
}
103+
104+
static Foo Slice4(const FillRule &aFill,
105+
const OwnedSlice<int32_t> &aCoords) {
106+
Foo result;
107+
::new (&result.slice4.fill) (FillRule)(aFill);
108+
::new (&result.slice4.coords) (OwnedSlice<int32_t>)(aCoords);
109+
result.tag = Tag::Slice4;
110+
return result;
111+
}
112+
113+
bool IsBar() const {
114+
return tag == Tag::Bar;
115+
}
116+
117+
bool IsPolygon1() const {
118+
return tag == Tag::Polygon1;
119+
}
120+
121+
bool IsSlice1() const {
122+
return tag == Tag::Slice1;
123+
}
124+
125+
bool IsSlice2() const {
126+
return tag == Tag::Slice2;
127+
}
128+
129+
bool IsSlice3() const {
130+
return tag == Tag::Slice3;
131+
}
132+
133+
bool IsSlice4() const {
134+
return tag == Tag::Slice4;
135+
}
136+
137+
private:
138+
Foo() {
139+
140+
}public:
141+
142+
67143
~Foo() {
68144
switch (tag) {
69145
case Tag::Polygon1: polygon1.~Polygon1_Body(); break;
@@ -135,6 +211,81 @@ union Baz {
135211
Slice23_Body slice23;
136212
Slice24_Body slice24;
137213

214+
static Baz Bar2() {
215+
Baz result;
216+
result.tag = Tag::Bar2;
217+
return result;
218+
}
219+
220+
static Baz Polygon21(const Polygon<T> &a0) {
221+
Baz result;
222+
::new (&result.polygon21._0) (Polygon<T>)(a0);
223+
result.tag = Tag::Polygon21;
224+
return result;
225+
}
226+
227+
static Baz Slice21(const OwnedSlice<T> &a0) {
228+
Baz result;
229+
::new (&result.slice21._0) (OwnedSlice<T>)(a0);
230+
result.tag = Tag::Slice21;
231+
return result;
232+
}
233+
234+
static Baz Slice22(const OwnedSlice<int32_t> &a0) {
235+
Baz result;
236+
::new (&result.slice22._0) (OwnedSlice<int32_t>)(a0);
237+
result.tag = Tag::Slice22;
238+
return result;
239+
}
240+
241+
static Baz Slice23(const FillRule &aFill,
242+
const OwnedSlice<T> &aCoords) {
243+
Baz result;
244+
::new (&result.slice23.fill) (FillRule)(aFill);
245+
::new (&result.slice23.coords) (OwnedSlice<T>)(aCoords);
246+
result.tag = Tag::Slice23;
247+
return result;
248+
}
249+
250+
static Baz Slice24(const FillRule &aFill,
251+
const OwnedSlice<int32_t> &aCoords) {
252+
Baz result;
253+
::new (&result.slice24.fill) (FillRule)(aFill);
254+
::new (&result.slice24.coords) (OwnedSlice<int32_t>)(aCoords);
255+
result.tag = Tag::Slice24;
256+
return result;
257+
}
258+
259+
bool IsBar2() const {
260+
return tag == Tag::Bar2;
261+
}
262+
263+
bool IsPolygon21() const {
264+
return tag == Tag::Polygon21;
265+
}
266+
267+
bool IsSlice21() const {
268+
return tag == Tag::Slice21;
269+
}
270+
271+
bool IsSlice22() const {
272+
return tag == Tag::Slice22;
273+
}
274+
275+
bool IsSlice23() const {
276+
return tag == Tag::Slice23;
277+
}
278+
279+
bool IsSlice24() const {
280+
return tag == Tag::Slice24;
281+
}
282+
283+
private:
284+
Baz() {
285+
286+
}public:
287+
288+
138289
~Baz() {
139290
switch (tag) {
140291
case Tag::Polygon21: polygon21.~Polygon21_Body(); break;
@@ -163,21 +314,67 @@ union Taz {
163314
enum class Tag : uint8_t {
164315
Bar3,
165316
Taz1,
317+
Taz3,
166318
};
167319

168320
struct Taz1_Body {
169321
Tag tag;
170322
int32_t _0;
171323
};
172324

325+
struct Taz3_Body {
326+
Tag tag;
327+
OwnedSlice<int32_t> _0;
328+
};
329+
173330
struct {
174331
Tag tag;
175332
};
176333
Taz1_Body taz1;
334+
Taz3_Body taz3;
335+
336+
static Taz Bar3() {
337+
Taz result;
338+
result.tag = Tag::Bar3;
339+
return result;
340+
}
341+
342+
static Taz Taz1(const int32_t &a0) {
343+
Taz result;
344+
::new (&result.taz1._0) (int32_t)(a0);
345+
result.tag = Tag::Taz1;
346+
return result;
347+
}
348+
349+
static Taz Taz3(const OwnedSlice<int32_t> &a0) {
350+
Taz result;
351+
::new (&result.taz3._0) (OwnedSlice<int32_t>)(a0);
352+
result.tag = Tag::Taz3;
353+
return result;
354+
}
355+
356+
bool IsBar3() const {
357+
return tag == Tag::Bar3;
358+
}
359+
360+
bool IsTaz1() const {
361+
return tag == Tag::Taz1;
362+
}
363+
364+
bool IsTaz3() const {
365+
return tag == Tag::Taz3;
366+
}
367+
368+
private:
369+
Taz() {
370+
371+
}public:
372+
177373

178374
~Taz() {
179375
switch (tag) {
180376
case Tag::Taz1: taz1.~Taz1_Body(); break;
377+
case Tag::Taz3: taz3.~Taz3_Body(); break;
181378
default: break;
182379
}
183380
}
@@ -186,6 +383,7 @@ union Taz {
186383
: tag(other.tag) {
187384
switch (tag) {
188385
case Tag::Taz1: ::new (&taz1) (Taz1_Body)(other.taz1); break;
386+
case Tag::Taz3: ::new (&taz3) (Taz3_Body)(other.taz3); break;
189387
default: break;
190388
}
191389
}
@@ -206,6 +404,33 @@ union Tazz {
206404
Tag tag;
207405
};
208406
Taz2_Body taz2;
407+
408+
static Tazz Bar4() {
409+
Tazz result;
410+
result.tag = Tag::Bar4;
411+
return result;
412+
}
413+
414+
static Tazz Taz2(const int32_t &a0) {
415+
Tazz result;
416+
::new (&result.taz2._0) (int32_t)(a0);
417+
result.tag = Tag::Taz2;
418+
return result;
419+
}
420+
421+
bool IsBar4() const {
422+
return tag == Tag::Bar4;
423+
}
424+
425+
bool IsTaz2() const {
426+
return tag == Tag::Taz2;
427+
}
428+
429+
private:
430+
Tazz() {
431+
432+
}public:
433+
209434
};
210435

211436
extern "C" {

0 commit comments

Comments
 (0)