zig/test/behavior/alignof.zig
Andrew Kelley 4307436b99 move behavior tests from test/stage1/ to test/
And fix test cases to make them pass. This is in preparation for
starting to pass behavior tests with self-hosted.
2021-04-29 15:54:04 -07:00

40 lines
983 B
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 expect(@alignOf(Foo) != maxInt(usize));
if (native_arch == .x86_64) {
comptime expect(@alignOf(Foo) == 4);
}
}
test "comparison of @alignOf(T) against zero" {
{
const T = struct { x: u32 };
expect(!(@alignOf(T) == 0));
expect(@alignOf(T) != 0);
expect(!(@alignOf(T) < 0));
expect(!(@alignOf(T) <= 0));
expect(@alignOf(T) > 0);
expect(@alignOf(T) >= 0);
}
{
const T = struct {};
expect(@alignOf(T) == 0);
expect(!(@alignOf(T) != 0));
expect(!(@alignOf(T) < 0));
expect(@alignOf(T) <= 0);
expect(!(@alignOf(T) > 0));
expect(@alignOf(T) >= 0);
}
}