diff options
| author | Loris Cro <kappaloris@gmail.com> | 2023-06-18 09:06:40 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-06-18 09:06:40 +0200 |
| commit | 216ef10dc471e4db60a30208be178d6c59efeaaf (patch) | |
| tree | 8c239dab283ae9cb3b7fe099bae240bcc53f894e /test/behavior/bool.zig | |
| parent | 0fc1d396495c1ab482197021dedac8bea3f9401c (diff) | |
| parent | 729a051e9e38674233190aea23c0ac8c134f2d67 (diff) | |
| download | zig-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.zig | 22 |
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 { |
