authorgravatar for john.schmidt.h@gmail.comJohn Schmidt <john.schmidt.h@gmail.com> 2024-02-08 23:40:03+01:00
committergravatar for john.schmidt.h@gmail.comJohn Schmidt <john.schmidt.h@gmail.com> 2024-02-08 23:49:03+01:00
log7cb227ab678b57dd10b65c1d9c89526a3e47cc2a
tree90108180c74b258c7263f40a8e1ff1555cb0b814
parent0d1baf0c6192c2ad917311f8275cc15b5550f0ac

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

1 files changed, 7 insertions(+), 7 deletions(-)

test/behavior/switch.zig+7-7
......@@ -410,8 +410,8 @@ test "switch on integer with else capturing expr" {
410410 var x: i32 = 5;
411411 _ = &x;
412412 switch (x + 10) {
413 14 => @panic("fail"),
414 16 => @panic("fail"),
413 14 => return error.TestFailed,
414 16 => return error.TestFailed,
415415 else => |e| try expect(e == 15),
416416 }
417417 }
......@@ -522,7 +522,7 @@ test "switch with null and T peer types and inferred result location type" {
522522 else => null,
523523 }) |v| {
524524 _ = v;
525 @panic("fail");
525 return error.TestFailed;
526526 }
527527 }
528528 };
......@@ -548,12 +548,12 @@ test "switch prongs with cases with identical payload types" {
548548 fn doTheSwitch1(u: Union) !void {
549549 switch (u) {
550550 .A, .C => |e| {
551 try expect(@TypeOf(e) == usize);
551 comptime assert(@TypeOf(e) == usize);
552552 try expect(e == 8);
553553 },
554554 .B => |e| {
555555 _ = e;
556 @panic("fail");
556 return error.TestFailed;
557557 },
558558 }
559559 }
......@@ -561,10 +561,10 @@ test "switch prongs with cases with identical payload types" {
561561 switch (u) {
562562 .A, .C => |e| {
563563 _ = e;
564 @panic("fail");
564 return error.TestFailed;
565565 },
566566 .B => |e| {
567 try expect(@TypeOf(e) == isize);
567 comptime assert(@TypeOf(e) == isize);
568568 try expect(e == -8);
569569 },
570570 }