aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2019-02-18 12:56:17 -0500
committerAndrew Kelley <andrew@ziglang.org>2019-02-18 13:05:26 -0500
commit7a84fe79b9d61bb3d4e21c169cc2b58722b194ce (patch)
tree1d44cdfafe00762e388d3114a0b9d44bb3bc0c4d /test
parent9b3013d2f6e416f31610f3dc94c5ff8b44836463 (diff)
downloadzig-7a84fe79b9d61bb3d4e21c169cc2b58722b194ce.tar.gz
zig-7a84fe79b9d61bb3d4e21c169cc2b58722b194ce.zip
pull request fixups
Diffstat (limited to 'test')
-rw-r--r--test/stage1/behavior/union.zig26
-rw-r--r--test/tests.zig12
2 files changed, 25 insertions, 13 deletions
diff --git a/test/stage1/behavior/union.zig b/test/stage1/behavior/union.zig
index f18cdf13ff..bbba867667 100644
--- a/test/stage1/behavior/union.zig
+++ b/test/stage1/behavior/union.zig
@@ -126,7 +126,7 @@ const MultipleChoice = union(enum(u32)) {
test "simple union(enum(u32))" {
var x = MultipleChoice.C;
expect(x == MultipleChoice.C);
- expect(@enumToInt(x) == 60);
+ expect(@enumToInt(@TagType(MultipleChoice)(x)) == 60);
}
const MultipleChoice2 = union(enum(u32)) {
@@ -148,7 +148,7 @@ test "union(enum(u32)) with specified and unspecified tag values" {
}
fn testEnumWithSpecifiedAndUnspecifiedTagValues(x: MultipleChoice2) void {
- expect(@enumToInt(x) == 60);
+ expect(@enumToInt(@TagType(MultipleChoice2)(x)) == 60);
expect(1123 == switch (x) {
MultipleChoice2.A => 1,
MultipleChoice2.B => 2,
@@ -345,7 +345,23 @@ test "union with only 1 field casted to its enum type which has enum value speci
var e = Expr{ .Literal = Literal{ .Bool = true } };
comptime expect(@TagType(Tag) == comptime_int);
- expect(Tag(e) == Expr.Literal);
- expect(@enumToInt(e) == 33);
- comptime expect(@enumToInt(e) == 33);
+ var t = Tag(e);
+ expect(t == Expr.Literal);
+ expect(@enumToInt(t) == 33);
+ comptime expect(@enumToInt(t) == 33);
+}
+
+test "@enumToInt works on unions" {
+ const Bar = union(enum) {
+ A: bool,
+ B: u8,
+ C,
+ };
+
+ const a = Bar{ .A = true };
+ var b = Bar{ .B = undefined };
+ var c = Bar.C;
+ expect(@enumToInt(a) == 0);
+ expect(@enumToInt(b) == 1);
+ expect(@enumToInt(c) == 2);
}
diff --git a/test/tests.zig b/test/tests.zig
index 656c05cb9b..f9c9207f05 100644
--- a/test/tests.zig
+++ b/test/tests.zig
@@ -572,9 +572,7 @@ pub const CompileErrorContext = struct {
const source_file = ".tmp_source.zig";
fn init(input: []const u8) ErrLineIter {
- return ErrLineIter {
- .lines = mem.separate(input, "\n"),
- };
+ return ErrLineIter{ .lines = mem.separate(input, "\n") };
}
fn next(self: *ErrLineIter) ?[]const u8 {
@@ -718,11 +716,10 @@ pub const CompileErrorContext = struct {
for (self.case.expected_errors.toSliceConst()) |expected| {
if (mem.indexOf(u8, stderr, expected) == null) {
warn(
- \\=========== Expected compile error: ============
+ \\\n=========== Expected compile error: ============
\\{}
\\
- , expected
- );
+ , expected);
ok = false;
break;
}
@@ -734,8 +731,7 @@ pub const CompileErrorContext = struct {
\\================= Full output: =================
\\{}
\\
- , stderr
- );
+ , stderr);
return error.TestFailed;
}