aboutsummaryrefslogtreecommitdiff
path: root/test/behavior/bool.zig
diff options
context:
space:
mode:
authorLoris Cro <kappaloris@gmail.com>2023-06-18 09:06:40 +0200
committerGitHub <noreply@github.com>2023-06-18 09:06:40 +0200
commit216ef10dc471e4db60a30208be178d6c59efeaaf (patch)
tree8c239dab283ae9cb3b7fe099bae240bcc53f894e /test/behavior/bool.zig
parent0fc1d396495c1ab482197021dedac8bea3f9401c (diff)
parent729a051e9e38674233190aea23c0ac8c134f2d67 (diff)
downloadzig-216ef10dc471e4db60a30208be178d6c59efeaaf.tar.gz
zig-216ef10dc471e4db60a30208be178d6c59efeaaf.zip
Merge branch 'master' into autodoc-searchkey
Diffstat (limited to 'test/behavior/bool.zig')
-rw-r--r--test/behavior/bool.zig22
1 files changed, 17 insertions, 5 deletions
diff --git a/test/behavior/bool.zig b/test/behavior/bool.zig
index a4e0ab499a..a2636ecf42 100644
--- a/test/behavior/bool.zig
+++ b/test/behavior/bool.zig
@@ -1,5 +1,7 @@
const std = @import("std");
+const builtin = @import("builtin");
const expect = std.testing.expect;
+const expectEqual = std.testing.expectEqual;
test "bool literals" {
try expect(true);
@@ -7,16 +9,26 @@ test "bool literals" {
}
test "cast bool to int" {
+ if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
+
const t = true;
const f = false;
- try expect(@boolToInt(t) == @as(u32, 1));
- try expect(@boolToInt(f) == @as(u32, 0));
+ try expectEqual(@as(u32, 1), @boolToInt(t));
+ try expectEqual(@as(u32, 0), @boolToInt(f));
+ try expectEqual(-1, @bitCast(i1, @boolToInt(t)));
+ try expectEqual(0, @bitCast(i1, @boolToInt(f)));
+ try expectEqual(u1, @TypeOf(@boolToInt(t)));
+ try expectEqual(u1, @TypeOf(@boolToInt(f)));
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));
+ try expectEqual(@as(u32, 1), @boolToInt(t));
+ try expectEqual(@as(u32, 0), @boolToInt(f));
+ try expectEqual(@as(i1, -1), @bitCast(i1, @boolToInt(t)));
+ try expectEqual(@as(i1, 0), @bitCast(i1, @boolToInt(f)));
+ try expectEqual(u1, @TypeOf(@boolToInt(t)));
+ try expectEqual(u1, @TypeOf(@boolToInt(f)));
}
test "bool cmp" {
@@ -37,7 +49,7 @@ test "compile time bool not" {
test "short circuit" {
try testShortCircuit(false, true);
- comptime try testShortCircuit(false, true);
+ try comptime testShortCircuit(false, true);
}
fn testShortCircuit(f: bool, t: bool) !void {