mirror of
https://github.com/ziglang/zig.git
synced 2025-12-10 16:23:07 +00:00
Conflicts:
* doc/langref.html.in
* lib/std/enums.zig
* lib/std/fmt.zig
* lib/std/hash/auto_hash.zig
* lib/std/math.zig
* lib/std/mem.zig
* lib/std/meta.zig
* test/behavior/alignof.zig
* test/behavior/bitcast.zig
* test/behavior/bugs/1421.zig
* test/behavior/cast.zig
* test/behavior/ptrcast.zig
* test/behavior/type_info.zig
* test/behavior/vector.zig
Master branch added `try` to a bunch of testing function calls, and some
lines also had changed how to refer to the native architecture and other
`@import("builtin")` stuff.
27 lines
667 B
Zig
27 lines
667 B
Zig
const std = @import("std");
|
|
const expect = std.testing.expect;
|
|
|
|
test "allocation and looping over 3-byte integer" {
|
|
try expect(@sizeOf(u24) == 4);
|
|
try expect(@sizeOf([1]u24) == 4);
|
|
try expect(@alignOf(u24) == 4);
|
|
try expect(@alignOf([1]u24) == 4);
|
|
|
|
var x = try std.testing.allocator.alloc(u24, 2);
|
|
defer std.testing.allocator.free(x);
|
|
try expect(x.len == 2);
|
|
x[0] = 0xFFFFFF;
|
|
x[1] = 0xFFFFFF;
|
|
|
|
const bytes = std.mem.sliceAsBytes(x);
|
|
try expect(@TypeOf(bytes) == []align(4) u8);
|
|
try expect(bytes.len == 8);
|
|
|
|
for (bytes) |*b| {
|
|
b.* = 0x00;
|
|
}
|
|
|
|
try expect(x[0] == 0x00);
|
|
try expect(x[1] == 0x00);
|
|
}
|