mirror of
https://github.com/ziglang/zig.git
synced 2024-12-14 07:10:16 +00:00
5619ce2406
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.
36 lines
802 B
Zig
36 lines
802 B
Zig
const expect = @import("std").testing.expect;
|
|
|
|
test "bool literals" {
|
|
try expect(true);
|
|
try expect(!false);
|
|
}
|
|
|
|
test "cast bool to int" {
|
|
const t = true;
|
|
const f = false;
|
|
try expect(@boolToInt(t) == @as(u32, 1));
|
|
try expect(@boolToInt(f) == @as(u32, 0));
|
|
try nonConstCastBoolToInt(t, f);
|
|
}
|
|
|
|
fn nonConstCastBoolToInt(t: bool, f: bool) !void {
|
|
try expect(@boolToInt(t) == @as(u32, 1));
|
|
try expect(@boolToInt(f) == @as(u32, 0));
|
|
}
|
|
|
|
test "bool cmp" {
|
|
try expect(testBoolCmp(true, false) == false);
|
|
}
|
|
fn testBoolCmp(a: bool, b: bool) bool {
|
|
return a == b;
|
|
}
|
|
|
|
const global_f = false;
|
|
const global_t = true;
|
|
const not_global_f = !global_f;
|
|
const not_global_t = !global_t;
|
|
test "compile time bool not" {
|
|
try expect(not_global_f);
|
|
try expect(!not_global_t);
|
|
}
|