20 lines
296 B
Zig
20 lines
296 B
Zig
|
const expect = @import("std").testing.expect;
|
||
|
|
||
|
test "defer" {
|
||
|
var x: i16 = 5;
|
||
|
{
|
||
|
defer x += 2;
|
||
|
try expect(x == 5);
|
||
|
}
|
||
|
try expect(x == 7);
|
||
|
}
|
||
|
|
||
|
test "multi defer" {
|
||
|
var x: f32 = 5;
|
||
|
{
|
||
|
defer x += 2;
|
||
|
defer x /= 2;
|
||
|
}
|
||
|
try expect(x == 4.5);
|
||
|
}
|