mirror of
https://github.com/ziglang/zig.git
synced 2024-11-30 09:02:32 +00:00
23 lines
494 B
Zig
23 lines
494 B
Zig
const expect = @import("std").testing.expect;
|
|
|
|
test "while error union capture" {
|
|
var sum1: u32 = 0;
|
|
numbers_left = 3;
|
|
while (eventuallyErrorSequence()) |value| {
|
|
sum1 += value;
|
|
} else |err| {
|
|
try expect(err == error.ReachedZero);
|
|
}
|
|
}
|
|
|
|
var numbers_left: u32 = undefined;
|
|
|
|
fn eventuallyErrorSequence() anyerror!u32 {
|
|
return if (numbers_left == 0) error.ReachedZero else blk: {
|
|
numbers_left -= 1;
|
|
break :blk numbers_left;
|
|
};
|
|
}
|
|
|
|
// test
|