mirror of
https://codeberg.org/ziglang/zig.git
synced 2025-12-06 13:54:21 +00:00
Polish a few tests in switch.zig
- Return `error.TestFailed` instead of panicing - Use `comptime assert` for type checks so that errors surface at compile time
This commit is contained in:
parent
0d1baf0c61
commit
7cb227ab67
1 changed files with 7 additions and 7 deletions
|
|
@ -410,8 +410,8 @@ test "switch on integer with else capturing expr" {
|
|||
var x: i32 = 5;
|
||||
_ = &x;
|
||||
switch (x + 10) {
|
||||
14 => @panic("fail"),
|
||||
16 => @panic("fail"),
|
||||
14 => return error.TestFailed,
|
||||
16 => return error.TestFailed,
|
||||
else => |e| try expect(e == 15),
|
||||
}
|
||||
}
|
||||
|
|
@ -522,7 +522,7 @@ test "switch with null and T peer types and inferred result location type" {
|
|||
else => null,
|
||||
}) |v| {
|
||||
_ = v;
|
||||
@panic("fail");
|
||||
return error.TestFailed;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
@ -548,12 +548,12 @@ test "switch prongs with cases with identical payload types" {
|
|||
fn doTheSwitch1(u: Union) !void {
|
||||
switch (u) {
|
||||
.A, .C => |e| {
|
||||
try expect(@TypeOf(e) == usize);
|
||||
comptime assert(@TypeOf(e) == usize);
|
||||
try expect(e == 8);
|
||||
},
|
||||
.B => |e| {
|
||||
_ = e;
|
||||
@panic("fail");
|
||||
return error.TestFailed;
|
||||
},
|
||||
}
|
||||
}
|
||||
|
|
@ -561,10 +561,10 @@ test "switch prongs with cases with identical payload types" {
|
|||
switch (u) {
|
||||
.A, .C => |e| {
|
||||
_ = e;
|
||||
@panic("fail");
|
||||
return error.TestFailed;
|
||||
},
|
||||
.B => |e| {
|
||||
try expect(@TypeOf(e) == isize);
|
||||
comptime assert(@TypeOf(e) == isize);
|
||||
try expect(e == -8);
|
||||
},
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue