Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions test/behavior/align.zig
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
const std = @import("std");
const expect = std.testing.expect;
const assert = std.debug.assert;
const builtin = @import("builtin");
const native_arch = builtin.target.cpu.arch;
const assert = std.debug.assert;

var foo: u8 align(4) = 100;

Expand Down Expand Up @@ -556,7 +556,7 @@ test "function pointer @intFromPtr/@ptrFromInt roundtrip" {
const nothing_int: usize = @intFromPtr(nothing_ptr);
const nothing_ptr2: *const fn () callconv(.c) void = @ptrFromInt(nothing_int);

try std.testing.expectEqual(nothing_ptr, nothing_ptr2);
try std.testing.expect(nothing_ptr == nothing_ptr2);
}

test "function pointer align mask" {
Expand Down
26 changes: 13 additions & 13 deletions test/behavior/array.zig
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
const std = @import("std");
const builtin = @import("builtin");
const testing = std.testing;
const mem = std.mem;
const assert = std.debug.assert;
const expect = testing.expect;
const expectEqual = testing.expectEqual;
const builtin = @import("builtin");

test "array to slice" {
const a: u32 align(4) = 3;
Expand Down Expand Up @@ -745,7 +745,7 @@ test "runtime side-effects in comptime-known array init" {
},
};
try expectEqual([4]u4{ 1, 2, 4, 8 }, init);
try expectEqual(@as(u4, std.math.maxInt(u4)), side_effects);
try expect(@as(u4, std.math.maxInt(u4)) == side_effects);
}

test "slice initialized through reference to anonymous array init provides result types" {
Expand Down Expand Up @@ -791,10 +791,10 @@ test "many-item pointer initialized through reference to anonymous array init pr
@truncate(my_u32),
@truncate(my_u64),
};
try expectEqual(123, foo[0]);
try expectEqual(456, foo[1]);
try expectEqual(123, foo[2]);
try expectEqual(456, foo[3]);
try expect(123 == foo[0]);
try expect(456 == foo[1]);
try expect(123 == foo[2]);
try expect(456 == foo[3]);
}

test "many-item sentinel-terminated pointer initialized through reference to anonymous array init provides result types" {
Expand All @@ -810,11 +810,11 @@ test "many-item sentinel-terminated pointer initialized through reference to ano
@truncate(my_u32),
@truncate(my_u64),
};
try expectEqual(123, foo[0]);
try expectEqual(456, foo[1]);
try expectEqual(123, foo[2]);
try expectEqual(456, foo[3]);
try expectEqual(999, foo[4]);
try expect(123 == foo[0]);
try expect(456 == foo[1]);
try expect(123 == foo[2]);
try expect(456 == foo[3]);
try expect(999 == foo[4]);
}

test "pointer to array initialized through reference to anonymous array init provides result types" {
Expand Down Expand Up @@ -1020,10 +1020,10 @@ test "@splat array with sentinel" {
fn doTheTest(comptime T: type, x: T, comptime s: T) !void {
const arr: [10:s]T = @splat(x);
for (arr) |elem| {
try expectEqual(x, elem);
try expect(x == elem);
}
const ptr: [*]const T = &arr;
try expectEqual(s, ptr[10]); // sentinel correct
try expect(s == ptr[10]); // sentinel correct
}
};

Expand Down
7 changes: 3 additions & 4 deletions test/behavior/asm.zig
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
const std = @import("std");
const builtin = @import("builtin");
const expect = std.testing.expect;
const expectEqual = std.testing.expectEqual;
const builtin = @import("builtin");

const is_x86_64_linux = builtin.cpu.arch == .x86_64 and builtin.os.tag == .linux;

Expand Down Expand Up @@ -159,7 +158,7 @@ test "rw constraint (x86_64)" {
: [a] "+r" (res),
: [b] "r" (@as(i32, 13)),
: .{ .flags = true });
try expectEqual(@as(i32, 18), res);
try expect(@as(i32, 18) == res);
}

test "asm modifiers (AArch64)" {
Expand All @@ -173,5 +172,5 @@ test "asm modifiers (AArch64)" {
: [ret] "=r" (-> u32),
: [in] "r" (x),
);
try expectEqual(2 * x, double);
try expect(2 * x == double);
}
17 changes: 8 additions & 9 deletions test/behavior/bit_shifting.zig
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
const std = @import("std");
const expect = std.testing.expect;
const expectEqual = std.testing.expectEqual;
const builtin = @import("builtin");

fn ShardedTable(comptime Key: type, comptime mask_bit_count: comptime_int, comptime V: type) type {
Expand Down Expand Up @@ -172,7 +171,7 @@ test "Saturating Shift Left" {
inline while (true) : (rhs += 1) {
comptime var lhs: T = std.math.minInt(T);
inline while (true) : (lhs += 1) {
try expectEqual(lhs <<| rhs, shlSat(lhs, rhs));
try expect(lhs <<| rhs == shlSat(lhs, rhs));
if (lhs == std.math.maxInt(T)) break;
}
if (rhs == @bitSizeOf(T) - 1) break;
Expand All @@ -187,12 +186,12 @@ test "Saturating Shift Left" {
try S.testType(u4);
try S.testType(i4);

try expectEqual(0xfffffffffffffff0fffffffffffffff0, S.shlSat(@as(u128, 0x0fffffffffffffff0fffffffffffffff), 4));
try expectEqual(0xffffffffffffffffffffffffffffffff, S.shlSat(@as(u128, 0x0fffffffffffffff0fffffffffffffff), 5));
try expectEqual(-0x80000000000000000000000000000000, S.shlSat(@as(i128, -0x0fffffffffffffff0fffffffffffffff), 5));
try expect(0xfffffffffffffff0fffffffffffffff0 == S.shlSat(@as(u128, 0x0fffffffffffffff0fffffffffffffff), 4));
try expect(0xffffffffffffffffffffffffffffffff == S.shlSat(@as(u128, 0x0fffffffffffffff0fffffffffffffff), 5));
try expect(-0x80000000000000000000000000000000 == S.shlSat(@as(i128, -0x0fffffffffffffff0fffffffffffffff), 5));

try expectEqual(51146728248377216718956089012931236753385031969422887335676427626502090568823039920051095192592252455482604439493126109519019633529459266458258243583, S.shlSat(@as(i495, 0x2fe6bc5448c55ce18252e2c9d44777505dfe63ff249a8027a6626c7d8dd9893fd5731e51474727be556f757facb586a4e04bbc0148c6c7ad692302f46fbd), 0x31));
try expectEqual(-57896044618658097711785492504343953926634992332820282019728792003956564819968, S.shlSat(@as(i256, -0x53d4148cee74ea43477a65b3daa7b8fdadcbf4508e793f4af113b8d8da5a7eb6), 0x91));
try expectEqual(170141183460469231731687303715884105727, S.shlSat(@as(i128, 0x2fe6bc5448c55ce18252e2c9d4477750), 0x31));
try expectEqual(0, S.shlSat(@as(i128, 0), 127));
try expect(51146728248377216718956089012931236753385031969422887335676427626502090568823039920051095192592252455482604439493126109519019633529459266458258243583 == S.shlSat(@as(i495, 0x2fe6bc5448c55ce18252e2c9d44777505dfe63ff249a8027a6626c7d8dd9893fd5731e51474727be556f757facb586a4e04bbc0148c6c7ad692302f46fbd), 0x31));
try expect(-57896044618658097711785492504343953926634992332820282019728792003956564819968 == S.shlSat(@as(i256, -0x53d4148cee74ea43477a65b3daa7b8fdadcbf4508e793f4af113b8d8da5a7eb6), 0x91));
try expect(170141183460469231731687303715884105727 == S.shlSat(@as(i128, 0x2fe6bc5448c55ce18252e2c9d4477750), 0x31));
try expect(0 == S.shlSat(@as(i128, 0), 127));
}
34 changes: 17 additions & 17 deletions test/behavior/bitcast.zig
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ test "comptime @bitCast packed struct to int and back" {
// S -> Int
var s: S = .{};
_ = &s;
try expectEqual(@as(Int, @bitCast(s)), comptime @as(Int, @bitCast(S{})));
try expect(@as(Int, @bitCast(s)) == comptime @as(Int, @bitCast(S{})));

// Int -> S
var i: Int = 0;
Expand Down Expand Up @@ -430,43 +430,43 @@ test "bitcast nan float does not modify signaling bit" {

// 16 bit
const snan_f16_const = math.snan(f16);
try expectEqual(snan_u16, @as(u16, @bitCast(snan_f16_const)));
try expectEqual(snan_u16, bitCastWrapper16(snan_f16_const));
try expect(snan_u16 == @as(u16, @bitCast(snan_f16_const)));
try expect(snan_u16 == bitCastWrapper16(snan_f16_const));

var snan_f16_var = math.snan(f16);
_ = &snan_f16_var;
try expectEqual(snan_u16, @as(u16, @bitCast(snan_f16_var)));
try expectEqual(snan_u16, bitCastWrapper16(snan_f16_var));
try expect(snan_u16 == @as(u16, @bitCast(snan_f16_var)));
try expect(snan_u16 == bitCastWrapper16(snan_f16_var));

// 32 bit
const snan_f32_const = math.snan(f32);
try expectEqual(snan_u32, @as(u32, @bitCast(snan_f32_const)));
try expectEqual(snan_u32, bitCastWrapper32(snan_f32_const));
try expect(snan_u32 == @as(u32, @bitCast(snan_f32_const)));
try expect(snan_u32 == bitCastWrapper32(snan_f32_const));

var snan_f32_var = math.snan(f32);
_ = &snan_f32_var;
try expectEqual(snan_u32, @as(u32, @bitCast(snan_f32_var)));
try expectEqual(snan_u32, bitCastWrapper32(snan_f32_var));
try expect(snan_u32 == @as(u32, @bitCast(snan_f32_var)));
try expect(snan_u32 == bitCastWrapper32(snan_f32_var));

// 64 bit
const snan_f64_const = math.snan(f64);
try expectEqual(snan_u64, @as(u64, @bitCast(snan_f64_const)));
try expectEqual(snan_u64, bitCastWrapper64(snan_f64_const));
try expect(snan_u64 == @as(u64, @bitCast(snan_f64_const)));
try expect(snan_u64 == bitCastWrapper64(snan_f64_const));

var snan_f64_var = math.snan(f64);
_ = &snan_f64_var;
try expectEqual(snan_u64, @as(u64, @bitCast(snan_f64_var)));
try expectEqual(snan_u64, bitCastWrapper64(snan_f64_var));
try expect(snan_u64 == @as(u64, @bitCast(snan_f64_var)));
try expect(snan_u64 == bitCastWrapper64(snan_f64_var));

// 128 bit
const snan_f128_const = math.snan(f128);
try expectEqual(snan_u128, @as(u128, @bitCast(snan_f128_const)));
try expectEqual(snan_u128, bitCastWrapper128(snan_f128_const));
try expect(snan_u128 == @as(u128, @bitCast(snan_f128_const)));
try expect(snan_u128 == bitCastWrapper128(snan_f128_const));

var snan_f128_var = math.snan(f128);
_ = &snan_f128_var;
try expectEqual(snan_u128, @as(u128, @bitCast(snan_f128_var)));
try expectEqual(snan_u128, bitCastWrapper128(snan_f128_var));
try expect(snan_u128 == @as(u128, @bitCast(snan_f128_var)));
try expect(snan_u128 == bitCastWrapper128(snan_f128_var));
}

test "@bitCast of packed struct of bools all true" {
Expand Down
27 changes: 13 additions & 14 deletions test/behavior/bool.zig
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
const std = @import("std");
const builtin = @import("builtin");
const expect = std.testing.expect;
const expectEqual = std.testing.expectEqual;
const builtin = @import("builtin");

test "bool literals" {
try expect(true);
Expand All @@ -14,22 +13,22 @@ test "cast bool to int" {

const t = true;
const f = false;
try expectEqual(@as(u32, 1), @intFromBool(t));
try expectEqual(@as(u32, 0), @intFromBool(f));
try expectEqual(-1, @as(i1, @bitCast(@intFromBool(t))));
try expectEqual(0, @as(i1, @bitCast(@intFromBool(f))));
try expectEqual(u1, @TypeOf(@intFromBool(t)));
try expectEqual(u1, @TypeOf(@intFromBool(f)));
try expect(@as(u32, 1) == @intFromBool(t));
try expect(@as(u32, 0) == @intFromBool(f));
try expect(-1 == @as(i1, @bitCast(@intFromBool(t))));
try expect(0 == @as(i1, @bitCast(@intFromBool(f))));
try expect(u1 == @TypeOf(@intFromBool(t)));
try expect(u1 == @TypeOf(@intFromBool(f)));
try nonConstCastIntFromBool(t, f);
}

fn nonConstCastIntFromBool(t: bool, f: bool) !void {
try expectEqual(@as(u32, 1), @intFromBool(t));
try expectEqual(@as(u32, 0), @intFromBool(f));
try expectEqual(@as(i1, -1), @as(i1, @bitCast(@intFromBool(t))));
try expectEqual(@as(i1, 0), @as(i1, @bitCast(@intFromBool(f))));
try expectEqual(u1, @TypeOf(@intFromBool(t)));
try expectEqual(u1, @TypeOf(@intFromBool(f)));
try expect(@as(u32, 1) == @intFromBool(t));
try expect(@as(u32, 0) == @intFromBool(f));
try expect(@as(i1, -1) == @as(i1, @bitCast(@intFromBool(t))));
try expect(@as(i1, 0) == @as(i1, @bitCast(@intFromBool(f))));
try expect(u1 == @TypeOf(@intFromBool(t)));
try expect(u1 == @TypeOf(@intFromBool(f)));
}

test "bool cmp" {
Expand Down
24 changes: 12 additions & 12 deletions test/behavior/builtin_functions_returning_void_or_noreturn.zig
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const std = @import("std");
const builtin = @import("builtin");
const testing = std.testing;
const builtin = @import("builtin");

var x: u8 = 1;

Expand All @@ -12,15 +12,15 @@ test {
if (builtin.zig_backend == .stage2_spirv) return error.SkipZigTest;

var val: u8 = undefined;
try testing.expectEqual({}, @atomicStore(u8, &val, 0, .unordered));
try testing.expectEqual(void, @TypeOf(@breakpoint()));
try testing.expectEqual({}, @export(&x, .{ .name = "x" }));
try testing.expectEqual({}, @memcpy(@as([*]u8, @ptrFromInt(1))[0..0], @as([*]u8, @ptrFromInt(1))[0..0]));
try testing.expectEqual({}, @memmove(@as([*]u8, @ptrFromInt(1))[0..0], @as([*]u8, @ptrFromInt(1))[0..0]));
try testing.expectEqual({}, @memset(@as([*]u8, @ptrFromInt(1))[0..0], undefined));
try testing.expectEqual(noreturn, @TypeOf(if (true) @panic("") else {}));
try testing.expectEqual({}, @prefetch(&val, .{}));
try testing.expectEqual({}, @setEvalBranchQuota(0));
try testing.expectEqual({}, @setFloatMode(.optimized));
try testing.expectEqual({}, @setRuntimeSafety(true));
try testing.expect({} == @atomicStore(u8, &val, 0, .unordered));
try testing.expect(void == @TypeOf(@breakpoint()));
try testing.expect({} == @export(&x, .{ .name = "x" }));
try testing.expect({} == @memcpy(@as([*]u8, @ptrFromInt(1))[0..0], @as([*]u8, @ptrFromInt(1))[0..0]));
try testing.expect({} == @memmove(@as([*]u8, @ptrFromInt(1))[0..0], @as([*]u8, @ptrFromInt(1))[0..0]));
try testing.expect({} == @memset(@as([*]u8, @ptrFromInt(1))[0..0], undefined));
try testing.expect(noreturn == @TypeOf(if (true) @panic("") else {}));
try testing.expect({} == @prefetch(&val, .{}));
try testing.expect({} == @setEvalBranchQuota(0));
try testing.expect({} == @setFloatMode(.optimized));
try testing.expect({} == @setRuntimeSafety(true));
}
15 changes: 7 additions & 8 deletions test/behavior/call.zig
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
const builtin = @import("builtin");
const std = @import("std");
const assert = std.debug.assert;
const expect = std.testing.expect;
const expectEqual = std.testing.expectEqual;
const builtin = @import("builtin");

test "super basic invocations" {
const foo = struct {
Expand Down Expand Up @@ -431,8 +430,8 @@ test "method call as parameter type" {
return u64;
}
};
try expectEqual(@as(u64, 123), S.foo(S{}, 123));
try expectEqual(@as(u64, 500), S.foo(S{}, 500));
try expect(@as(u64, 123) == S.foo(S{}, 123));
try expect(@as(u64, 500) == S.foo(S{}, 500));
}

test "non-anytype generic parameters provide result type" {
Expand All @@ -441,11 +440,11 @@ test "non-anytype generic parameters provide result type" {

const S = struct {
fn f(comptime T: type, y: T) !void {
try expectEqual(@as(T, 123), y);
try expect(@as(T, 123) == y);
}

fn g(x: anytype, y: @TypeOf(x)) !void {
try expectEqual(@as(@TypeOf(x), 0x222), y);
try expect(@as(@TypeOf(x), 0x222) == y);
}
};

Expand Down Expand Up @@ -605,10 +604,10 @@ test "call with union with zero sized field is not memorized incorrectly" {
}
};
const s1 = U.S(U{ .T = u32 }).tag();
try std.testing.expectEqual(u32, s1);
try std.testing.expect(u32 == s1);

const s2 = U.S(U{ .T = u64 }).tag();
try std.testing.expectEqual(u64, s2);
try std.testing.expect(u64 == s2);
}

test "function call with cast to anyopaque pointer" {
Expand Down
Loading