zig/test/behavior/bugs/1851.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

27 lines
631 B
Zig

const std = @import("std");
const expect = std.testing.expect;
test "allocation and looping over 3-byte integer" {
expect(@sizeOf(u24) == 4);
expect(@sizeOf([1]u24) == 4);
expect(@alignOf(u24) == 4);
expect(@alignOf([1]u24) == 4);
var x = try std.testing.allocator.alloc(u24, 2);
defer std.testing.allocator.free(x);
expect(x.len == 2);
x[0] = 0xFFFFFF;
x[1] = 0xFFFFFF;
const bytes = std.mem.sliceAsBytes(x);
expect(@TypeOf(bytes) == []align(4) u8);
expect(bytes.len == 8);
for (bytes) |*b| {
b.* = 0x00;
}
expect(x[0] == 0x00);
expect(x[1] == 0x00);
}