mirror of
https://github.com/ziglang/zig.git
synced 2024-11-30 09:02:32 +00:00
23 lines
322 B
Zig
23 lines
322 B
Zig
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
|