diff options
| author | Andrew Kelley <superjoe30@gmail.com> | 2017-12-04 02:12:13 -0500 |
|---|---|---|
| committer | Andrew Kelley <superjoe30@gmail.com> | 2017-12-04 02:12:13 -0500 |
| commit | 76f3bdfff8224144e7b57748eb8eda2001d0308d (patch) | |
| tree | 46e05c057146f2a0d781b42c6b42b8a565237b34 /test/cases/union.zig | |
| parent | dd3437d5ba30c2101719fa38a95914fae5d965dd (diff) | |
| download | zig-76f3bdfff8224144e7b57748eb8eda2001d0308d.tar.gz zig-76f3bdfff8224144e7b57748eb8eda2001d0308d.zip | |
add test for casting union to tag type of union
Diffstat (limited to 'test/cases/union.zig')
| -rw-r--r-- | test/cases/union.zig | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/test/cases/union.zig b/test/cases/union.zig index 13bc084551..1db9a1bef1 100644 --- a/test/cases/union.zig +++ b/test/cases/union.zig @@ -173,3 +173,20 @@ const ZeroBits = union { test "union with only 1 field which is void should be zero bits" { comptime assert(@sizeOf(ZeroBits) == 0); } + +const TheTag = enum {A, B, C}; +const TheUnion = union(TheTag) { A: i32, B: i32, C: i32 }; +test "union field access gives the enum values" { + assert(TheUnion.A == TheTag.A); + assert(TheUnion.B == TheTag.B); + assert(TheUnion.C == TheTag.C); +} + +test "cast union to tag type of union" { + testCastUnionToTagType(TheUnion {.B = 1234}); + comptime testCastUnionToTagType(TheUnion {.B = 1234}); +} + +fn testCastUnionToTagType(x: &const TheUnion) { + assert(TheTag(*x) == TheTag.B); +} |
