Skip to content

Commit e9e99e6

Browse files
committed
Added corresponding test case
1 parent 8b3cb4e commit e9e99e6

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

compiler/test/compilable/imports/cstuff3.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,16 @@ int squared(int a)
44
{
55
return a * a;
66
}
7+
8+
/* test case for issue #21094 */
9+
typedef enum upng_error {
10+
UPNG_EOK = 0, /* success (no error) */
11+
UPNG_ENOMEM = 1, /* memory allocation failed */
12+
UPNG_ENOTFOUND = 2, /* resource not found (file missing) */
13+
UPNG_ENOTPNG = 3, /* image data does not have a PNG header */
14+
UPNG_EMALFORMED = 4, /* image data is not a valid PNG image */
15+
UPNG_EUNSUPPORTED = 5, /* critical PNG chunk type is not supported */
16+
UPNG_EUNINTERLACED = 6, /* image interlacing is not supported */
17+
UPNG_EUNFORMAT = 7, /* image color format is not supported */
18+
UPNG_EPARAM = 8 /* invalid parameter to method call */
19+
} upng_error;

compiler/test/compilable/testcstuff3.d

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,22 @@
22
import imports.cstuff3;
33

44
static assert(squared(4) == 16);
5+
6+
/* test case for issue #21094 */
7+
string enum_to_str(E)(E v) if (is(E == enum))
8+
{
9+
final switch (v) with(E)
10+
{
11+
static foreach (m; __traits(allMembers, E))
12+
{
13+
case mixin(m):
14+
return m;
15+
}
16+
}
17+
}
18+
19+
void testEnumSwitch()
20+
{
21+
auto str = enum_to_str(UPNG_EOK);
22+
assert(str == "UPNG_EOK");
23+
}

0 commit comments

Comments
 (0)