aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorAndrew Kelley <superjoe30@gmail.com>2017-12-03 22:36:01 -0500
committerAndrew Kelley <superjoe30@gmail.com>2017-12-03 22:36:01 -0500
commit5a8367e8924e809b1390796eb656633ea5e34a86 (patch)
tree1eb50935a4dfb147349975875d5b00d391b75fcb /test
parent0ad1239522c70418990dc7b9da4e128da7cdd1d5 (diff)
downloadzig-5a8367e8924e809b1390796eb656633ea5e34a86.tar.gz
zig-5a8367e8924e809b1390796eb656633ea5e34a86.zip
rename @EnumTagType to @TagType. add tests for union-enums
See #618
Diffstat (limited to 'test')
-rw-r--r--test/cases/enum.zig4
-rw-r--r--test/cases/union.zig33
2 files changed, 35 insertions, 2 deletions
diff --git a/test/cases/enum.zig b/test/cases/enum.zig
index f3240045df..ec900511eb 100644
--- a/test/cases/enum.zig
+++ b/test/cases/enum.zig
@@ -204,12 +204,12 @@ test "set enum tag type" {
{
var x = Small.One;
x = Small.Two;
- comptime assert(@EnumTagType(Small) == u2);
+ comptime assert(@TagType(Small) == u2);
}
{
var x = Small2.One;
x = Small2.Two;
- comptime assert(@EnumTagType(Small2) == u2);
+ comptime assert(@TagType(Small2) == u2);
}
}
diff --git a/test/cases/union.zig b/test/cases/union.zig
index ec050a20d5..c4767fd649 100644
--- a/test/cases/union.zig
+++ b/test/cases/union.zig
@@ -104,3 +104,36 @@ fn bar(value: &const Payload) -> i32 {
Payload.C => |x| if (x) i32(30) else 31,
};
}
+
+const MultipleChoice2 = union(enum(u32)) {
+ Unspecified1: i32,
+ A: f32 = 20,
+ Unspecified2: void,
+ B: bool = 40,
+ Unspecified3: i32,
+ C: i8 = 60,
+ Unspecified4: void,
+ D: void = 1000,
+ Unspecified5: i32,
+};
+
+test "union(enum(u32)) with specified and unspecified tag values" {
+ comptime assert(@TagType(@TagType(MultipleChoice2)) == u32);
+ testEnumWithSpecifiedAndUnspecifiedTagValues(MultipleChoice2 {.C = 123});
+ comptime testEnumWithSpecifiedAndUnspecifiedTagValues(MultipleChoice2 { .C = 123} );
+}
+
+fn testEnumWithSpecifiedAndUnspecifiedTagValues(x: &const MultipleChoice2) {
+ assert(u32(@TagType(MultipleChoice2)(*x)) == 60);
+ assert(1123 == switch (*x) {
+ MultipleChoice2.A => 1,
+ MultipleChoice2.B => 2,
+ MultipleChoice2.C => |v| i32(1000) + v,
+ MultipleChoice2.D => 4,
+ MultipleChoice2.Unspecified1 => 5,
+ MultipleChoice2.Unspecified2 => 6,
+ MultipleChoice2.Unspecified3 => 7,
+ MultipleChoice2.Unspecified4 => 8,
+ MultipleChoice2.Unspecified5 => 9,
+ });
+}