aboutsummaryrefslogtreecommitdiff
path: root/test/behavior/bool.zig
diff options
context:
space:
mode:
authortison <wander4096@gmail.com>2023-05-24 08:01:48 +0800
committerGitHub <noreply@github.com>2023-05-24 00:01:48 +0000
commitbfe02ff61a8861c269524c60668a3969cb053720 (patch)
tree92c6a412b5f25101c60217e9db80a53394c223bb /test/behavior/bool.zig
parentdcc1b4fd1532ccfe028fe9f68c0d19fc28800191 (diff)
downloadzig-bfe02ff61a8861c269524c60668a3969cb053720.tar.gz
zig-bfe02ff61a8861c269524c60668a3969cb053720.zip
make `@boolToInt` always return a u1
Signed-off-by: tison <wander4096@gmail.com>
Diffstat (limited to 'test/behavior/bool.zig')
-rw-r--r--test/behavior/bool.zig17
1 files changed, 13 insertions, 4 deletions
diff --git a/test/behavior/bool.zig b/test/behavior/bool.zig
index d216d72a05..8cfd87bf21 100644
--- a/test/behavior/bool.zig
+++ b/test/behavior/bool.zig
@@ -1,6 +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);
@@ -12,14 +13,22 @@ 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 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" {