zig/test/behavior/alignof.zig
joachimschmidt557 d6e6162081
stage2 AArch64: unify callee-preserved regs on all targets
also enables many passing behavior tests
2022-12-27 21:17:52 +08:00

40 lines
1.0 KiB
Zig

const std = @import("std");
const expect = std.testing.expect;
const builtin = @import("builtin");
const native_arch = builtin.target.cpu.arch;
const maxInt = std.math.maxInt;
const Foo = struct {
x: u32,
y: u32,
z: u32,
};
test "@alignOf(T) before referencing T" {
comptime try expect(@alignOf(Foo) != maxInt(usize));
if (native_arch == .x86_64) {
comptime try expect(@alignOf(Foo) == 4);
}
}
test "comparison of @alignOf(T) against zero" {
{
const T = struct { x: u32 };
try expect(!(@alignOf(T) == 0));
try expect(@alignOf(T) != 0);
try expect(!(@alignOf(T) < 0));
try expect(!(@alignOf(T) <= 0));
try expect(@alignOf(T) > 0);
try expect(@alignOf(T) >= 0);
}
{
const T = struct {};
try expect(@alignOf(T) == 0);
try expect(!(@alignOf(T) != 0));
try expect(!(@alignOf(T) < 0));
try expect(@alignOf(T) <= 0);
try expect(!(@alignOf(T) > 0));
try expect(@alignOf(T) >= 0);
}
}