mirror of
https://github.com/ziglang/zig.git
synced 2025-12-06 06:13: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.
37 lines
787 B
Zig
37 lines
787 B
Zig
const std = @import("std");
|
|
const expect = std.testing.expect;
|
|
|
|
test "truncate u0 to larger integer allowed and has comptime known result" {
|
|
var x: u0 = 0;
|
|
const y = @truncate(u8, x);
|
|
comptime try expect(y == 0);
|
|
}
|
|
|
|
test "truncate.u0.literal" {
|
|
var z = @truncate(u0, 0);
|
|
try expect(z == 0);
|
|
}
|
|
|
|
test "truncate.u0.const" {
|
|
const c0: usize = 0;
|
|
var z = @truncate(u0, c0);
|
|
try expect(z == 0);
|
|
}
|
|
|
|
test "truncate.u0.var" {
|
|
var d: u8 = 2;
|
|
var z = @truncate(u0, d);
|
|
try expect(z == 0);
|
|
}
|
|
|
|
test "truncate sign mismatch but comptime known so it works anyway" {
|
|
const x: u32 = 10;
|
|
var result = @truncate(i8, x);
|
|
try expect(result == 10);
|
|
}
|
|
|
|
test "truncate on comptime integer" {
|
|
var x = @truncate(u16, 9999);
|
|
try expect(x == 9999);
|
|
}
|