zig/doc/langref/test_defer.zig

23 lines
322 B
Zig
Raw Normal View History

const std = @import("std");
const expect = std.testing.expect;
const print = std.debug.print;
fn deferExample() !usize {
var a: usize = 1;
{
defer a = 2;
a = 1;
}
try expect(a == 2);
a = 5;
return a;
}
test "defer basics" {
try expect((try deferExample()) == 5);
}
// test