diff --git a/doc/langref/error_union_parsing_u64.zig b/doc/langref/error_union_parsing_u64.zig index 9e55e247f2..b710d159ac 100644 --- a/doc/langref/error_union_parsing_u64.zig +++ b/doc/langref/error_union_parsing_u64.zig @@ -35,7 +35,7 @@ fn charToDigit(c: u8) u8 { test "parse u64" { const result = try parseU64("1234", 10); - try std.testing.expect(result == 1234); + try std.testing.expectEqual(1234, result); } // test diff --git a/doc/langref/result_location_interfering_with_swap.zig b/doc/langref/result_location_interfering_with_swap.zig index 6182d4818a..7442d2fa33 100644 --- a/doc/langref/result_location_interfering_with_swap.zig +++ b/doc/langref/result_location_interfering_with_swap.zig @@ -1,4 +1,4 @@ -const expect = @import("std").testing.expect; +const expectEqual = @import("std").testing.expectEqual; test "attempt to swap array elements with array initializer" { var arr: [2]u32 = .{ 1, 2 }; arr = .{ arr[1], arr[0] }; @@ -6,8 +6,8 @@ test "attempt to swap array elements with array initializer" { // arr[0] = arr[1]; // arr[1] = arr[0]; // So this fails! - try expect(arr[0] == 2); // succeeds - try expect(arr[1] == 1); // fails + try expectEqual(2, arr[0]); // succeeds + try expectEqual(1, arr[1]); // fails } // test_error= diff --git a/doc/langref/test_TypeOf_builtin.zig b/doc/langref/test_TypeOf_builtin.zig index 2c833363fd..6ce5f09844 100644 --- a/doc/langref/test_TypeOf_builtin.zig +++ b/doc/langref/test_TypeOf_builtin.zig @@ -1,11 +1,11 @@ const std = @import("std"); -const expect = std.testing.expect; +const expectEqual = std.testing.expectEqual; test "no runtime side effects" { var data: i32 = 0; const T = @TypeOf(foo(i32, &data)); - try comptime expect(T == i32); - try expect(data == 0); + try comptime expectEqual(i32, T); + try expectEqual(0, data); } fn foo(comptime T: type, ptr: *T) T { diff --git a/doc/langref/test_allocator.zig b/doc/langref/test_allocator.zig index ff0e18a507..35e1bd701f 100644 --- a/doc/langref/test_allocator.zig +++ b/doc/langref/test_allocator.zig @@ -1,13 +1,13 @@ const std = @import("std"); const Allocator = std.mem.Allocator; -const expect = std.testing.expect; +const expectEqualStrings = std.testing.expectEqualStrings; test "using an allocator" { var buffer: [100]u8 = undefined; var fba = std.heap.FixedBufferAllocator.init(&buffer); const allocator = fba.allocator(); const result = try concat(allocator, "foo", "bar"); - try expect(std.mem.eql(u8, "foobar", result)); + try expectEqualStrings("foobar", result); } fn concat(allocator: Allocator, a: []const u8, b: []const u8) ![]u8 { diff --git a/doc/langref/test_allowzero.zig b/doc/langref/test_allowzero.zig index 0798322bb0..a5002f7d8c 100644 --- a/doc/langref/test_allowzero.zig +++ b/doc/langref/test_allowzero.zig @@ -1,11 +1,11 @@ const std = @import("std"); -const expect = std.testing.expect; +const expectEqual = std.testing.expectEqual; test "allowzero" { var zero: usize = 0; // var to make to runtime-known _ = &zero; // suppress 'var is never mutated' error const ptr: *allowzero i32 = @ptrFromInt(zero); - try expect(@intFromPtr(ptr) == 0); + try expectEqual(0, @intFromPtr(ptr)); } // test diff --git a/doc/langref/test_anonymous_struct.zig b/doc/langref/test_anonymous_struct.zig index 82d4f62203..037ca1dd48 100644 --- a/doc/langref/test_anonymous_struct.zig +++ b/doc/langref/test_anonymous_struct.zig @@ -1,5 +1,6 @@ const std = @import("std"); const expect = std.testing.expect; +const expectEqual = std.testing.expectEqual; test "fully anonymous struct" { try check(.{ @@ -11,11 +12,11 @@ test "fully anonymous struct" { } fn check(args: anytype) !void { - try expect(args.int == 1234); - try expect(args.float == 12.34); + try expectEqual(1234, args.int); + try expectEqual(12.34, args.float); try expect(args.b); - try expect(args.s[0] == 'h'); - try expect(args.s[1] == 'i'); + try expectEqual('h', args.s[0]); + try expectEqual('i', args.s[1]); } // test diff --git a/doc/langref/test_anonymous_union.zig b/doc/langref/test_anonymous_union.zig index bb8311d5eb..f0ce2980fa 100644 --- a/doc/langref/test_anonymous_union.zig +++ b/doc/langref/test_anonymous_union.zig @@ -1,5 +1,5 @@ const std = @import("std"); -const expect = std.testing.expect; +const expectEqual = std.testing.expectEqual; const Number = union { int: i32, @@ -9,8 +9,8 @@ const Number = union { test "anonymous union literal syntax" { const i: Number = .{ .int = 42 }; const f = makeNumber(); - try expect(i.int == 42); - try expect(f.float == 12.34); + try expectEqual(42, i.int); + try expectEqual(12.34, f.float); } fn makeNumber() Number { diff --git a/doc/langref/test_arrays.zig b/doc/langref/test_arrays.zig index 0c479dbce1..fa8d2ed3d3 100644 --- a/doc/langref/test_arrays.zig +++ b/doc/langref/test_arrays.zig @@ -1,4 +1,4 @@ -const expect = @import("std").testing.expect; +const expectEqual = @import("std").testing.expectEqual; const assert = @import("std").debug.assert; const mem = @import("std").mem; @@ -29,7 +29,7 @@ test "iterate over an array" { for (message) |byte| { sum += byte; } - try expect(sum == 'h' + 'e' + 'l' * 2 + 'o'); + try expectEqual('h' + 'e' + 'l' * 2 + 'o', sum); } // modifiable array @@ -39,8 +39,8 @@ test "modify an array" { for (&some_integers, 0..) |*item, i| { item.* = @intCast(i); } - try expect(some_integers[10] == 10); - try expect(some_integers[99] == 99); + try expectEqual(10, some_integers[10]); + try expectEqual(99, some_integers[99]); } // array concatenation works if the values are known @@ -91,8 +91,8 @@ const Point = struct { }; test "compile-time array initialization" { - try expect(fancy_array[4].x == 4); - try expect(fancy_array[4].y == 8); + try expectEqual(4, fancy_array[4].x); + try expectEqual(8, fancy_array[4].y); } // call a function to initialize an array @@ -104,9 +104,9 @@ fn makePoint(x: i32) Point { }; } test "array initialization with function calls" { - try expect(more_points[4].x == 3); - try expect(more_points[4].y == 6); - try expect(more_points.len == 10); + try expectEqual(3, more_points[4].x); + try expectEqual(6, more_points[4].y); + try expectEqual(10, more_points.len); } // test diff --git a/doc/langref/test_basic_slices.zig b/doc/langref/test_basic_slices.zig index 3d3c7c6d7c..2801314835 100644 --- a/doc/langref/test_basic_slices.zig +++ b/doc/langref/test_basic_slices.zig @@ -1,4 +1,4 @@ -const expect = @import("std").testing.expect; +const expectEqual = @import("std").testing.expectEqual; const expectEqualSlices = @import("std").testing.expectEqualSlices; test "basic slices" { @@ -12,14 +12,14 @@ test "basic slices" { try expectEqualSlices(i32, slice, alt_slice); - try expect(@TypeOf(slice) == []i32); - try expect(&slice[0] == &array[0]); - try expect(slice.len == array.len); + try expectEqual([]i32, @TypeOf(slice)); + try expectEqual(&array[0], &slice[0]); + try expectEqual(array.len, slice.len); // If you slice with comptime-known start and end positions, the result is // a pointer to an array, rather than a slice. const array_ptr = array[0..array.len]; - try expect(@TypeOf(array_ptr) == *[array.len]i32); + try expectEqual(*[array.len]i32, @TypeOf(array_ptr)); // You can perform a slice-by-length by slicing twice. This allows the compiler // to perform some optimisations like recognising a comptime-known length when @@ -28,13 +28,13 @@ test "basic slices" { _ = &runtime_start; const length = 2; const array_ptr_len = array[runtime_start..][0..length]; - try expect(@TypeOf(array_ptr_len) == *[length]i32); + try expectEqual(*[length]i32, @TypeOf(array_ptr_len)); // Using the address-of operator on a slice gives a single-item pointer. - try expect(@TypeOf(&slice[0]) == *i32); + try expectEqual(*i32, @TypeOf(&slice[0])); // Using the `ptr` field gives a many-item pointer. - try expect(@TypeOf(slice.ptr) == [*]i32); - try expect(@intFromPtr(slice.ptr) == @intFromPtr(&slice[0])); + try expectEqual([*]i32, @TypeOf(slice.ptr)); + try expectEqual(@intFromPtr(slice.ptr), @intFromPtr(&slice[0])); // Slices have array bounds checking. If you try to access something out // of bounds, you'll get a safety check failure: @@ -47,8 +47,8 @@ test "basic slices" { const empty1 = &[0]u8{}; // If the type is known you can use this short hand: const empty2: []u8 = &.{}; - try expect(empty1.len == 0); - try expect(empty2.len == 0); + try expectEqual(0, empty1.len); + try expectEqual(0, empty2.len); // A zero-length initialization can always be used to create an empty slice, even if the slice is mutable. // This is because the pointed-to data is zero bits long, so its immutability is irrelevant. diff --git a/doc/langref/test_bitOffsetOf_offsetOf.zig b/doc/langref/test_bitOffsetOf_offsetOf.zig index ed4faebf5f..e2eb49f8a3 100644 --- a/doc/langref/test_bitOffsetOf_offsetOf.zig +++ b/doc/langref/test_bitOffsetOf_offsetOf.zig @@ -1,5 +1,5 @@ const std = @import("std"); -const expect = std.testing.expect; +const expectEqual = std.testing.expectEqual; const BitField = packed struct { a: u3, @@ -9,13 +9,13 @@ const BitField = packed struct { test "offsets of non-byte-aligned fields" { comptime { - try expect(@bitOffsetOf(BitField, "a") == 0); - try expect(@bitOffsetOf(BitField, "b") == 3); - try expect(@bitOffsetOf(BitField, "c") == 6); + try expectEqual(0, @bitOffsetOf(BitField, "a")); + try expectEqual(3, @bitOffsetOf(BitField, "b")); + try expectEqual(6, @bitOffsetOf(BitField, "c")); - try expect(@offsetOf(BitField, "a") == 0); - try expect(@offsetOf(BitField, "b") == 0); - try expect(@offsetOf(BitField, "c") == 0); + try expectEqual(0, @offsetOf(BitField, "a")); + try expectEqual(0, @offsetOf(BitField, "b")); + try expectEqual(0, @offsetOf(BitField, "c")); } } diff --git a/doc/langref/test_call_builtin.zig b/doc/langref/test_call_builtin.zig index 8caecf73c4..cc465f2e45 100644 --- a/doc/langref/test_call_builtin.zig +++ b/doc/langref/test_call_builtin.zig @@ -1,7 +1,7 @@ -const expect = @import("std").testing.expect; +const expectEqual = @import("std").testing.expectEqual; test "noinline function call" { - try expect(@call(.auto, add, .{ 3, 9 }) == 12); + try expectEqual(12, @call(.auto, add, .{ 3, 9 })); } fn add(a: i32, b: i32) i32 { diff --git a/doc/langref/test_coerce_error_subset_to_superset.zig b/doc/langref/test_coerce_error_subset_to_superset.zig index d46c761e4e..58279a1323 100644 --- a/doc/langref/test_coerce_error_subset_to_superset.zig +++ b/doc/langref/test_coerce_error_subset_to_superset.zig @@ -12,7 +12,7 @@ const AllocationError = error{ test "coerce subset to superset" { const err = foo(AllocationError.OutOfMemory); - try std.testing.expect(err == FileOpenError.OutOfMemory); + try std.testing.expectEqual(FileOpenError.OutOfMemory, err); } fn foo(err: AllocationError) FileOpenError { diff --git a/doc/langref/test_coerce_large_to_small.zig b/doc/langref/test_coerce_large_to_small.zig index 62111af979..2c7b390e66 100644 --- a/doc/langref/test_coerce_large_to_small.zig +++ b/doc/langref/test_coerce_large_to_small.zig @@ -1,10 +1,10 @@ const std = @import("std"); -const expect = std.testing.expect; +const expectEqual = std.testing.expectEqual; test "coercing large integer type to smaller one when value is comptime-known to fit" { const x: u64 = 255; const y: u8 = x; - try expect(y == 255); + try expectEqual(255, y); } // test diff --git a/doc/langref/test_coerce_optional_wrapped_error_union.zig b/doc/langref/test_coerce_optional_wrapped_error_union.zig index c41dd0b1d0..bddd2e1acd 100644 --- a/doc/langref/test_coerce_optional_wrapped_error_union.zig +++ b/doc/langref/test_coerce_optional_wrapped_error_union.zig @@ -1,12 +1,12 @@ const std = @import("std"); -const expect = std.testing.expect; +const expectEqual = std.testing.expectEqual; test "coerce to optionals wrapped in error union" { const x: anyerror!?i32 = 1234; const y: anyerror!?i32 = null; - try expect((try x).? == 1234); - try expect((try y) == null); + try expectEqual(1234, (try x).?); + try expectEqual(null, (try y)); } // test diff --git a/doc/langref/test_coerce_optionals.zig b/doc/langref/test_coerce_optionals.zig index 415bb2344b..2698f35cf0 100644 --- a/doc/langref/test_coerce_optionals.zig +++ b/doc/langref/test_coerce_optionals.zig @@ -1,12 +1,12 @@ const std = @import("std"); -const expect = std.testing.expect; +const expectEqual = std.testing.expectEqual; test "coerce to optionals" { const x: ?i32 = 1234; const y: ?i32 = null; - try expect(x.? == 1234); - try expect(y == null); + try expectEqual(1234, x.?); + try expectEqual(null, y); } // test diff --git a/doc/langref/test_coerce_slices_arrays_and_pointers.zig b/doc/langref/test_coerce_slices_arrays_and_pointers.zig index 67b2687163..f79fb8f767 100644 --- a/doc/langref/test_coerce_slices_arrays_and_pointers.zig +++ b/doc/langref/test_coerce_slices_arrays_and_pointers.zig @@ -1,5 +1,7 @@ const std = @import("std"); -const expect = std.testing.expect; +const expectEqual = std.testing.expectEqual; +const expectEqualStrings = std.testing.expectEqualStrings; +const expectEqualSlices = std.testing.expectEqualSlices; // You can assign constant pointers to arrays to a slice with // const modifier on the element type. Useful in particular for @@ -7,48 +9,48 @@ const expect = std.testing.expect; test "*const [N]T to []const T" { const x1: []const u8 = "hello"; const x2: []const u8 = &[5]u8{ 'h', 'e', 'l', 'l', 111 }; - try expect(std.mem.eql(u8, x1, x2)); + try expectEqualStrings(x1, x2); const y: []const f32 = &[2]f32{ 1.2, 3.4 }; - try expect(y[0] == 1.2); + try expectEqual(1.2, y[0]); } // Likewise, it works when the destination type is an error union. test "*const [N]T to E![]const T" { const x1: anyerror![]const u8 = "hello"; const x2: anyerror![]const u8 = &[5]u8{ 'h', 'e', 'l', 'l', 111 }; - try expect(std.mem.eql(u8, try x1, try x2)); + try expectEqualStrings(try x1, try x2); const y: anyerror![]const f32 = &[2]f32{ 1.2, 3.4 }; - try expect((try y)[0] == 1.2); + try expectEqual(1.2, (try y)[0]); } // Likewise, it works when the destination type is an optional. test "*const [N]T to ?[]const T" { const x1: ?[]const u8 = "hello"; const x2: ?[]const u8 = &[5]u8{ 'h', 'e', 'l', 'l', 111 }; - try expect(std.mem.eql(u8, x1.?, x2.?)); + try expectEqualStrings(x1.?, x2.?); const y: ?[]const f32 = &[2]f32{ 1.2, 3.4 }; - try expect(y.?[0] == 1.2); + try expectEqual(1.2, y.?[0]); } // In this cast, the array length becomes the slice length. test "*[N]T to []T" { var buf: [5]u8 = "hello".*; const x: []u8 = &buf; - try expect(std.mem.eql(u8, x, "hello")); + try expectEqualStrings("hello", x); const buf2 = [2]f32{ 1.2, 3.4 }; const x2: []const f32 = &buf2; - try expect(std.mem.eql(f32, x2, &[2]f32{ 1.2, 3.4 })); + try expectEqualSlices(f32, &[2]f32{ 1.2, 3.4 }, x2); } // Single-item pointers to arrays can be coerced to many-item pointers. test "*[N]T to [*]T" { var buf: [5]u8 = "hello".*; const x: [*]u8 = &buf; - try expect(x[4] == 'o'); + try expectEqual('o', x[4]); // x[5] would be an uncaught out of bounds pointer dereference! } @@ -56,7 +58,7 @@ test "*[N]T to [*]T" { test "*[N]T to ?[*]T" { var buf: [5]u8 = "hello".*; const x: ?[*]u8 = &buf; - try expect(x.?[4] == 'o'); + try expectEqual('o', x.?[4]); } // Single-item pointers can be cast to len-1 single-item arrays. @@ -64,14 +66,14 @@ test "*T to *[1]T" { var x: i32 = 1234; const y: *[1]i32 = &x; const z: [*]i32 = y; - try expect(z[0] == 1234); + try expectEqual(1234, z[0]); } // Sentinel-terminated slices can be coerced into sentinel-terminated pointers test "[:x]T to [*:x]T" { const buf: [:0]const u8 = "hello"; const buf2: [*:0]const u8 = buf; - try expect(buf2[4] == 'o'); + try expectEqual('o', buf2[4]); } // test diff --git a/doc/langref/test_coerce_to_error_union.zig b/doc/langref/test_coerce_to_error_union.zig index 2789a92198..4c42e24afb 100644 --- a/doc/langref/test_coerce_to_error_union.zig +++ b/doc/langref/test_coerce_to_error_union.zig @@ -1,11 +1,11 @@ const std = @import("std"); -const expect = std.testing.expect; +const expectEqual = std.testing.expectEqual; test "coercion to error unions" { const x: anyerror!i32 = 1234; const y: anyerror!i32 = error.Failure; - try expect((try x) == 1234); + try expectEqual(1234, (try x)); try std.testing.expectError(error.Failure, y); } diff --git a/doc/langref/test_coerce_tuples_arrays.zig b/doc/langref/test_coerce_tuples_arrays.zig index 6d0e63e15c..0005d33e8b 100644 --- a/doc/langref/test_coerce_tuples_arrays.zig +++ b/doc/langref/test_coerce_tuples_arrays.zig @@ -1,5 +1,5 @@ const std = @import("std"); -const expect = std.testing.expect; +const expectEqual = std.testing.expectEqual; const Tuple = struct { u8, u8 }; test "coercion from homogeneous tuple to array" { diff --git a/doc/langref/test_coerce_unions_enums.zig b/doc/langref/test_coerce_unions_enums.zig index 0a782b4c54..94655c2e9d 100644 --- a/doc/langref/test_coerce_unions_enums.zig +++ b/doc/langref/test_coerce_unions_enums.zig @@ -1,5 +1,5 @@ const std = @import("std"); -const expect = std.testing.expect; +const expectEqual = std.testing.expectEqual; const E = enum { one, @@ -28,22 +28,22 @@ const U2 = union(enum) { test "coercion between unions and enums" { const u = U{ .two = 12.34 }; const e: E = u; // coerce union to enum - try expect(e == E.two); + try expectEqual(E.two, e); const three = E.three; const u_2: U = three; // coerce enum to union - try expect(u_2 == E.three); + try expectEqual(E.three, u_2); const u_3: U = .three; // coerce enum literal to union - try expect(u_3 == E.three); + try expectEqual(E.three, u_3); const u_4: U2 = .a; // coerce enum literal to union with inferred enum tag type. - try expect(u_4.tag() == 1); + try expectEqual(1, u_4.tag()); // The following example is invalid. // error: coercion from enum '@EnumLiteral()' to union 'test_coerce_unions_enum.U2' must initialize 'f32' field 'b' //var u_5: U2 = .b; - //try expect(u_5.tag() == 2); + //try expectEqual(2, u_5.tag()); } // test diff --git a/doc/langref/test_comptime_evaluation.zig b/doc/langref/test_comptime_evaluation.zig index 832814e595..521aa14edd 100644 --- a/doc/langref/test_comptime_evaluation.zig +++ b/doc/langref/test_comptime_evaluation.zig @@ -1,4 +1,4 @@ -const expect = @import("std").testing.expect; +const expectEqual = @import("std").testing.expectEqual; const CmdFn = struct { name: []const u8, @@ -32,9 +32,9 @@ fn performFn(comptime prefix_char: u8, start_value: i32) i32 { } test "perform fn" { - try expect(performFn('t', 1) == 6); - try expect(performFn('o', 0) == 1); - try expect(performFn('w', 99) == 99); + try expectEqual(6, performFn('t', 1)); + try expectEqual(1, performFn('o', 0)); + try expectEqual(99, performFn('w', 99)); } // test diff --git a/doc/langref/test_comptime_max_with_bool.zig b/doc/langref/test_comptime_max_with_bool.zig index 4d05cbbff0..2bcd16cb39 100644 --- a/doc/langref/test_comptime_max_with_bool.zig +++ b/doc/langref/test_comptime_max_with_bool.zig @@ -8,7 +8,7 @@ fn max(comptime T: type, a: T, b: T) T { } } test "try to compare bools" { - try @import("std").testing.expect(max(bool, false, true) == true); + try @import("std").testing.expectEqual(true, max(bool, false, true)); } // test diff --git a/doc/langref/test_comptime_pointer_conversion.zig b/doc/langref/test_comptime_pointer_conversion.zig index 6151e992c0..0c8e5a44eb 100644 --- a/doc/langref/test_comptime_pointer_conversion.zig +++ b/doc/langref/test_comptime_pointer_conversion.zig @@ -1,4 +1,4 @@ -const expect = @import("std").testing.expect; +const expectEqual = @import("std").testing.expectEqual; test "comptime @ptrFromInt" { comptime { @@ -6,8 +6,8 @@ test "comptime @ptrFromInt" { // ptr is never dereferenced. const ptr: *i32 = @ptrFromInt(0xdeadbee0); const addr = @intFromPtr(ptr); - try expect(@TypeOf(addr) == usize); - try expect(addr == 0xdeadbee0); + try expectEqual(usize, @TypeOf(addr)); + try expectEqual(0xdeadbee0, addr); } } diff --git a/doc/langref/test_comptime_pointers.zig b/doc/langref/test_comptime_pointers.zig index 784ddfd9f5..9c3b219c07 100644 --- a/doc/langref/test_comptime_pointers.zig +++ b/doc/langref/test_comptime_pointers.zig @@ -1,4 +1,4 @@ -const expect = @import("std").testing.expect; +const expectEqual = @import("std").testing.expectEqual; test "comptime pointers" { comptime { @@ -6,7 +6,7 @@ test "comptime pointers" { const ptr = &x; ptr.* += 1; x += 1; - try expect(ptr.* == 3); + try expectEqual(3, ptr.*); } } diff --git a/doc/langref/test_comptime_variables.zig b/doc/langref/test_comptime_variables.zig index 49d92ea025..b551590d17 100644 --- a/doc/langref/test_comptime_variables.zig +++ b/doc/langref/test_comptime_variables.zig @@ -1,5 +1,5 @@ const std = @import("std"); -const expect = std.testing.expect; +const expectEqual = std.testing.expectEqual; test "comptime vars" { var x: i32 = 1; @@ -8,8 +8,8 @@ test "comptime vars" { x += 1; y += 1; - try expect(x == 2); - try expect(y == 2); + try expectEqual(2, x); + try expectEqual(2, y); if (y != 2) { // This compile error never triggers because y is a comptime variable, diff --git a/doc/langref/test_container-level_comptime_expressions.zig b/doc/langref/test_container-level_comptime_expressions.zig index 8f324a3553..78d5cb4cbb 100644 --- a/doc/langref/test_container-level_comptime_expressions.zig +++ b/doc/langref/test_container-level_comptime_expressions.zig @@ -31,7 +31,7 @@ fn sum(numbers: []const i32) i32 { } test "variable values" { - try @import("std").testing.expect(sum_of_first_25_primes == 1060); + try @import("std").testing.expectEqual(1060, sum_of_first_25_primes); } // test diff --git a/doc/langref/test_container_level_variables.zig b/doc/langref/test_container_level_variables.zig index ade379ec79..372fda1863 100644 --- a/doc/langref/test_container_level_variables.zig +++ b/doc/langref/test_container_level_variables.zig @@ -2,8 +2,8 @@ var y: i32 = add(10, x); const x: i32 = add(12, 34); test "container level variables" { - try expect(x == 46); - try expect(y == 56); + try expectEqual(46, x); + try expectEqual(56, y); } fn add(a: i32, b: i32) i32 { @@ -11,6 +11,6 @@ fn add(a: i32, b: i32) i32 { } const std = @import("std"); -const expect = std.testing.expect; +const expectEqual = std.testing.expectEqual; // test diff --git a/doc/langref/test_defer.zig b/doc/langref/test_defer.zig index 80aebc9d66..8c674f3aaf 100644 --- a/doc/langref/test_defer.zig +++ b/doc/langref/test_defer.zig @@ -1,5 +1,5 @@ const std = @import("std"); -const expect = std.testing.expect; +const expectEqual = std.testing.expectEqual; const print = std.debug.print; fn deferExample() !usize { @@ -9,14 +9,14 @@ fn deferExample() !usize { defer a = 2; a = 1; } - try expect(a == 2); + try expectEqual(2, a); a = 5; return a; } test "defer basics" { - try expect((try deferExample()) == 5); + try expectEqual(5, (try deferExample())); } // test diff --git a/doc/langref/test_empty_block.zig b/doc/langref/test_empty_block.zig index cab1b03767..c12f9baefb 100644 --- a/doc/langref/test_empty_block.zig +++ b/doc/langref/test_empty_block.zig @@ -1,12 +1,12 @@ const std = @import("std"); -const expect = std.testing.expect; +const expectEqual = std.testing.expectEqual; test { const a = {}; const b = void{}; - try expect(@TypeOf(a) == void); - try expect(@TypeOf(b) == void); - try expect(a == b); + try expectEqual(void, @TypeOf(a)); + try expectEqual(void, @TypeOf(b)); + try expectEqual(a, b); } // test diff --git a/doc/langref/test_enum_literals.zig b/doc/langref/test_enum_literals.zig index 6acf858c30..e28c1d0d49 100644 --- a/doc/langref/test_enum_literals.zig +++ b/doc/langref/test_enum_literals.zig @@ -1,5 +1,6 @@ const std = @import("std"); const expect = std.testing.expect; +const expectEqual = std.testing.expectEqual; const Color = enum { auto, @@ -10,7 +11,7 @@ const Color = enum { test "enum literals" { const color1: Color = .auto; const color2 = Color.auto; - try expect(color1 == color2); + try expectEqual(color1, color2); } test "switch using enum literals" { diff --git a/doc/langref/test_enums.zig b/doc/langref/test_enums.zig index 4e0b3896f2..55a4f87d3b 100644 --- a/doc/langref/test_enums.zig +++ b/doc/langref/test_enums.zig @@ -1,4 +1,6 @@ const expect = @import("std").testing.expect; +const expectEqual = @import("std").testing.expectEqual; +const expectEqualStrings = @import("std").testing.expectEqualStrings; const mem = @import("std").mem; // Declare an enum. @@ -20,9 +22,9 @@ const Value = enum(u2) { // Now you can cast between u2 and Value. // The ordinal value starts from 0, counting up by 1 from the previous member. test "enum ordinal value" { - try expect(@intFromEnum(Value.zero) == 0); - try expect(@intFromEnum(Value.one) == 1); - try expect(@intFromEnum(Value.two) == 2); + try expectEqual(0, @intFromEnum(Value.zero)); + try expectEqual(1, @intFromEnum(Value.one)); + try expectEqual(2, @intFromEnum(Value.two)); } // You can override the ordinal value for an enum. @@ -32,9 +34,9 @@ const Value2 = enum(u32) { million = 1000000, }; test "set enum ordinal value" { - try expect(@intFromEnum(Value2.hundred) == 100); - try expect(@intFromEnum(Value2.thousand) == 1000); - try expect(@intFromEnum(Value2.million) == 1000000); + try expectEqual(100, @intFromEnum(Value2.hundred)); + try expectEqual(1000, @intFromEnum(Value2.thousand)); + try expectEqual(1000000, @intFromEnum(Value2.million)); } // You can also override only some values. @@ -46,11 +48,11 @@ const Value3 = enum(u4) { e, }; test "enum implicit ordinal values and overridden values" { - try expect(@intFromEnum(Value3.a) == 0); - try expect(@intFromEnum(Value3.b) == 8); - try expect(@intFromEnum(Value3.c) == 9); - try expect(@intFromEnum(Value3.d) == 4); - try expect(@intFromEnum(Value3.e) == 5); + try expectEqual(0, @intFromEnum(Value3.a)); + try expectEqual(8, @intFromEnum(Value3.b)); + try expectEqual(9, @intFromEnum(Value3.c)); + try expectEqual(4, @intFromEnum(Value3.d)); + try expectEqual(5, @intFromEnum(Value3.e)); } // Enums can have methods, the same as structs and unions. @@ -84,7 +86,7 @@ test "enum switch" { Foo.number => "this is a number", Foo.none => "this is a none", }; - try expect(mem.eql(u8, what_is_it, "this is a number")); + try expectEqualStrings(what_is_it, "this is a number"); } // @typeInfo can be used to access the integer tag type of an enum. @@ -95,18 +97,18 @@ const Small = enum { four, }; test "std.meta.Tag" { - try expect(@typeInfo(Small).@"enum".tag_type == u2); + try expectEqual(u2, @typeInfo(Small).@"enum".tag_type); } // @typeInfo tells us the field count and the fields names: test "@typeInfo" { - try expect(@typeInfo(Small).@"enum".fields.len == 4); - try expect(mem.eql(u8, @typeInfo(Small).@"enum".fields[1].name, "two")); + try expectEqual(4, @typeInfo(Small).@"enum".fields.len); + try expectEqualStrings(@typeInfo(Small).@"enum".fields[1].name, "two"); } // @tagName gives a [:0]const u8 representation of an enum value: test "@tagName" { - try expect(mem.eql(u8, @tagName(Small.three), "three")); + try expectEqualStrings(@tagName(Small.three), "three"); } // test diff --git a/doc/langref/test_error_union.zig b/doc/langref/test_error_union.zig index 0cc01ec4a4..41ff85339b 100644 --- a/doc/langref/test_error_union.zig +++ b/doc/langref/test_error_union.zig @@ -1,4 +1,4 @@ -const expect = @import("std").testing.expect; +const expectEqual = @import("std").testing.expectEqual; test "error union" { var foo: anyerror!i32 = undefined; @@ -10,10 +10,10 @@ test "error union" { foo = error.SomeError; // Use compile-time reflection to access the payload type of an error union: - try comptime expect(@typeInfo(@TypeOf(foo)).error_union.payload == i32); + try comptime expectEqual(i32, @typeInfo(@TypeOf(foo)).error_union.payload); // Use compile-time reflection to access the error set type of an error union: - try comptime expect(@typeInfo(@TypeOf(foo)).error_union.error_set == anyerror); + try comptime expectEqual(anyerror, @typeInfo(@TypeOf(foo)).error_union.error_set); } // test diff --git a/doc/langref/test_fibonacci_comptime_overflow.zig b/doc/langref/test_fibonacci_comptime_overflow.zig index f06b37feed..1621e5884f 100644 --- a/doc/langref/test_fibonacci_comptime_overflow.zig +++ b/doc/langref/test_fibonacci_comptime_overflow.zig @@ -1,4 +1,4 @@ -const expect = @import("std").testing.expect; +const expectEqual = @import("std").testing.expectEqual; fn fibonacci(index: u32) u32 { //if (index < 2) return index; @@ -6,7 +6,7 @@ fn fibonacci(index: u32) u32 { } test "fibonacci" { - try comptime expect(fibonacci(7) == 13); + try comptime expectEqual(13, fibonacci(7)); } // test_error=overflow of integer type diff --git a/doc/langref/test_fibonacci_recursion.zig b/doc/langref/test_fibonacci_recursion.zig index ba0b809fcc..3a366fbbd2 100644 --- a/doc/langref/test_fibonacci_recursion.zig +++ b/doc/langref/test_fibonacci_recursion.zig @@ -1,4 +1,4 @@ -const expect = @import("std").testing.expect; +const expectEqual = @import("std").testing.expectEqual; fn fibonacci(index: u32) u32 { if (index < 2) return index; @@ -7,10 +7,10 @@ fn fibonacci(index: u32) u32 { test "fibonacci" { // test fibonacci at run-time - try expect(fibonacci(7) == 13); + try expectEqual(13, fibonacci(7)); // test fibonacci at compile-time - try comptime expect(fibonacci(7) == 13); + try comptime expectEqual(13, fibonacci(7)); } // test diff --git a/doc/langref/test_field_builtin.zig b/doc/langref/test_field_builtin.zig index 52ce702c72..feca7c9298 100644 --- a/doc/langref/test_field_builtin.zig +++ b/doc/langref/test_field_builtin.zig @@ -1,4 +1,5 @@ const std = @import("std"); +const expectEqual = std.testing.expectEqual; const Point = struct { x: u32, @@ -8,23 +9,20 @@ const Point = struct { }; test "field access by string" { - const expect = std.testing.expect; var p = Point{ .x = 0, .y = 0 }; @field(p, "x") = 4; @field(p, "y") = @field(p, "x") + 1; - try expect(@field(p, "x") == 4); - try expect(@field(p, "y") == 5); + try expectEqual(4, @field(p, "x")); + try expectEqual(5, @field(p, "y")); } test "decl access by string" { - const expect = std.testing.expect; - - try expect(@field(Point, "z") == 1); + try expectEqual(1, @field(Point, "z")); @field(Point, "z") = 2; - try expect(@field(Point, "z") == 2); + try expectEqual(2, @field(Point, "z")); } // test diff --git a/doc/langref/test_fn_reflection.zig b/doc/langref/test_fn_reflection.zig index cc4dd50b33..7c462bbfc5 100644 --- a/doc/langref/test_fn_reflection.zig +++ b/doc/langref/test_fn_reflection.zig @@ -3,8 +3,8 @@ const math = std.math; const testing = std.testing; test "fn reflection" { - try testing.expect(@typeInfo(@TypeOf(testing.expect)).@"fn".params[0].type.? == bool); - try testing.expect(@typeInfo(@TypeOf(testing.tmpDir)).@"fn".return_type.? == testing.TmpDir); + try testing.expectEqual(bool, @typeInfo(@TypeOf(testing.expect)).@"fn".params[0].type.?); + try testing.expectEqual(testing.TmpDir, @typeInfo(@TypeOf(testing.tmpDir)).@"fn".return_type.?); try testing.expect(@typeInfo(@TypeOf(math.Log2Int)).@"fn".is_generic); } diff --git a/doc/langref/test_fn_type_inference.zig b/doc/langref/test_fn_type_inference.zig index 494fdea482..227a402ec4 100644 --- a/doc/langref/test_fn_type_inference.zig +++ b/doc/langref/test_fn_type_inference.zig @@ -1,15 +1,15 @@ -const expect = @import("std").testing.expect; +const expectEqual = @import("std").testing.expectEqual; fn addFortyTwo(x: anytype) @TypeOf(x) { return x + 42; } test "fn type inference" { - try expect(addFortyTwo(1) == 43); - try expect(@TypeOf(addFortyTwo(1)) == comptime_int); + try expectEqual(43, addFortyTwo(1)); + try expectEqual(comptime_int, @TypeOf(addFortyTwo(1))); const y: i64 = 2; - try expect(addFortyTwo(y) == 44); - try expect(@TypeOf(addFortyTwo(y)) == i64); + try expectEqual(44, addFortyTwo(y)); + try expectEqual(i64, @TypeOf(addFortyTwo(y))); } // test diff --git a/doc/langref/test_for.zig b/doc/langref/test_for.zig index 62751f9fbc..d2d40db58f 100644 --- a/doc/langref/test_for.zig +++ b/doc/langref/test_for.zig @@ -1,4 +1,4 @@ -const expect = @import("std").testing.expect; +const expectEqual = @import("std").testing.expectEqual; test "for basics" { const items = [_]i32{ 4, 5, 3, 4, 0 }; @@ -12,22 +12,22 @@ test "for basics" { } sum += value; } - try expect(sum == 16); + try expectEqual(16, sum); // To iterate over a portion of a slice, reslice. for (items[0..1]) |value| { sum += value; } - try expect(sum == 20); + try expectEqual(20, sum); // To access the index of iteration, specify a second condition as well // as a second capture value. var sum2: i32 = 0; for (items, 0..) |_, i| { - try expect(@TypeOf(i) == usize); + try expectEqual(usize, @TypeOf(i)); sum2 += @as(i32, @intCast(i)); } - try expect(sum2 == 10); + try expectEqual(10, sum2); // To iterate over consecutive integers, use the range syntax. // Unbounded range is always a compile error. @@ -35,7 +35,7 @@ test "for basics" { for (0..5) |i| { sum3 += i; } - try expect(sum3 == 10); + try expectEqual(10, sum3); } test "multi object for" { @@ -50,7 +50,7 @@ test "multi object for" { count += i + j; } - try expect(count == 21); + try expectEqual(21, count); } test "for reference" { @@ -62,9 +62,9 @@ test "for reference" { value.* += 1; } - try expect(items[0] == 4); - try expect(items[1] == 5); - try expect(items[2] == 3); + try expectEqual(4, items[0]); + try expectEqual(5, items[1]); + try expectEqual(3, items[2]); } test "for else" { @@ -79,10 +79,10 @@ test "for else" { sum += value.?; } } else blk: { - try expect(sum == 12); + try expectEqual(12, sum); break :blk sum; }; - try expect(result == 12); + try expectEqual(12, result); } // test diff --git a/doc/langref/test_for_nested_break.zig b/doc/langref/test_for_nested_break.zig index 301facbcfe..38fed8900a 100644 --- a/doc/langref/test_for_nested_break.zig +++ b/doc/langref/test_for_nested_break.zig @@ -1,5 +1,5 @@ const std = @import("std"); -const expect = std.testing.expect; +const expectEqual = std.testing.expectEqual; test "nested break" { var count: usize = 0; @@ -9,7 +9,7 @@ test "nested break" { break :outer; } } - try expect(count == 1); + try expectEqual(1, count); } test "nested continue" { @@ -21,7 +21,7 @@ test "nested continue" { } } - try expect(count == 8); + try expectEqual(8, count); } // test diff --git a/doc/langref/test_functions.zig b/doc/langref/test_functions.zig index 7b70961ab3..e86183ad50 100644 --- a/doc/langref/test_functions.zig +++ b/doc/langref/test_functions.zig @@ -1,7 +1,7 @@ const std = @import("std"); const builtin = @import("builtin"); const native_arch = builtin.cpu.arch; -const expect = std.testing.expect; +const expectEqual = std.testing.expectEqual; // Functions are declared like this fn add(a: i8, b: i8) i8 { @@ -57,8 +57,8 @@ fn doOp(fnCall: Call2Op, op1: i8, op2: i8) i8 { } test "function" { - try expect(doOp(add, 5, 6) == 11); - try expect(doOp(sub2, 5, 6) == -1); + try expectEqual(11, doOp(add, 5, 6)); + try expectEqual(-1, doOp(sub2, 5, 6)); } // test diff --git a/doc/langref/test_global_assembly.zig b/doc/langref/test_global_assembly.zig index a5d5f3ca5f..b7cc6d466b 100644 --- a/doc/langref/test_global_assembly.zig +++ b/doc/langref/test_global_assembly.zig @@ -1,5 +1,5 @@ const std = @import("std"); -const expect = std.testing.expect; +const expectEqual = std.testing.expectEqual; comptime { asm ( @@ -14,7 +14,7 @@ comptime { extern fn my_func(a: i32, b: i32) i32; test "global assembly" { - try expect(my_func(12, 34) == 46); + try expectEqual(46, my_func(12, 34)); } // test diff --git a/doc/langref/test_if.zig b/doc/langref/test_if.zig index 4ea6e66377..61dfcaa04d 100644 --- a/doc/langref/test_if.zig +++ b/doc/langref/test_if.zig @@ -4,13 +4,14 @@ // * anyerror!T const expect = @import("std").testing.expect; +const expectEqual = @import("std").testing.expectEqual; test "if expression" { // If expressions are used instead of a ternary expression. const a: u32 = 5; const b: u32 = 4; const result = if (a != b) 47 else 3089; - try expect(result == 47); + try expectEqual(result, 47); } test "if boolean" { @@ -32,7 +33,7 @@ test "if error union" { const a: anyerror!u32 = 0; if (a) |value| { - try expect(value == 0); + try expectEqual(value, 0); } else |err| { _ = err; unreachable; @@ -43,17 +44,17 @@ test "if error union" { _ = value; unreachable; } else |err| { - try expect(err == error.BadValue); + try expectEqual(err, error.BadValue); } // The else and |err| capture is strictly required. if (a) |value| { - try expect(value == 0); + try expectEqual(value, 0); } else |_| {} // To check only the error value, use an empty block expression. if (b) |_| {} else |err| { - try expect(err == error.BadValue); + try expectEqual(err, error.BadValue); } // Access the value by reference using a pointer capture. @@ -65,7 +66,7 @@ test "if error union" { } if (c) |value| { - try expect(value == 9); + try expectEqual(value, 9); } else |_| { unreachable; } diff --git a/doc/langref/test_if_optionals.zig b/doc/langref/test_if_optionals.zig index e19d181c78..fef9ae3b62 100644 --- a/doc/langref/test_if_optionals.zig +++ b/doc/langref/test_if_optionals.zig @@ -1,11 +1,12 @@ const expect = @import("std").testing.expect; +const expectEqual = @import("std").testing.expectEqual; test "if optional" { // If expressions test for null. const a: ?u32 = 0; if (a) |value| { - try expect(value == 0); + try expectEqual(0, value); } else { unreachable; } @@ -19,7 +20,7 @@ test "if optional" { // The else is not required. if (a) |value| { - try expect(value == 0); + try expectEqual(0, value); } // To test against null only, use the binary equality operator. @@ -34,7 +35,7 @@ test "if optional" { } if (c) |value| { - try expect(value == 2); + try expectEqual(2, value); } else { unreachable; } @@ -46,7 +47,7 @@ test "if error union with optional" { const a: anyerror!?u32 = 0; if (a) |optional_value| { - try expect(optional_value.? == 0); + try expectEqual(0, optional_value.?); } else |err| { _ = err; unreachable; @@ -54,7 +55,7 @@ test "if error union with optional" { const b: anyerror!?u32 = null; if (b) |optional_value| { - try expect(optional_value == null); + try expectEqual(null, optional_value); } else |_| { unreachable; } @@ -64,7 +65,7 @@ test "if error union with optional" { _ = optional_value; unreachable; } else |err| { - try expect(err == error.BadValue); + try expectEqual(error.BadValue, err); } // Access the value by reference by using a pointer capture each time. @@ -78,7 +79,7 @@ test "if error union with optional" { } if (d) |optional_value| { - try expect(optional_value.? == 9); + try expectEqual(9, optional_value.?); } else |_| { unreachable; } diff --git a/doc/langref/test_incorrect_pointer_alignment.zig b/doc/langref/test_incorrect_pointer_alignment.zig index d404b330fb..daa583e6ba 100644 --- a/doc/langref/test_incorrect_pointer_alignment.zig +++ b/doc/langref/test_incorrect_pointer_alignment.zig @@ -3,7 +3,7 @@ const std = @import("std"); test "pointer alignment safety" { var array align(4) = [_]u32{ 0x11111111, 0x11111111 }; const bytes = std.mem.sliceAsBytes(array[0..]); - try std.testing.expect(foo(bytes) == 0x11111111); + try std.testing.expectEqual(0x11111111, foo(bytes)); } fn foo(bytes: []u8) u32 { const slice4 = bytes[1..5]; diff --git a/doc/langref/test_inline_else.zig b/doc/langref/test_inline_else.zig index e535115935..8972bd8c6b 100644 --- a/doc/langref/test_inline_else.zig +++ b/doc/langref/test_inline_else.zig @@ -1,5 +1,5 @@ const std = @import("std"); -const expect = std.testing.expect; +const expectEqual = std.testing.expectEqual; const SliceTypeA = extern struct { len: usize, @@ -42,8 +42,8 @@ fn withSwitch(any: AnySlice) usize { test "inline for and inline else similarity" { const any = AnySlice{ .c = "hello" }; - try expect(withFor(any) == 5); - try expect(withSwitch(any) == 5); + try expectEqual(5, withFor(any)); + try expectEqual(5, withSwitch(any)); } // test diff --git a/doc/langref/test_inline_for.zig b/doc/langref/test_inline_for.zig index fbf75de2ea..4bc35b8043 100644 --- a/doc/langref/test_inline_for.zig +++ b/doc/langref/test_inline_for.zig @@ -1,4 +1,4 @@ -const expect = @import("std").testing.expect; +const expectEqual = @import("std").testing.expectEqual; test "inline for loop" { const nums = [_]i32{ 2, 4, 6 }; @@ -12,7 +12,7 @@ test "inline for loop" { }; sum += typeNameLength(T); } - try expect(sum == 9); + try expectEqual(9, sum); } fn typeNameLength(comptime T: type) usize { diff --git a/doc/langref/test_inline_switch_union_tag.zig b/doc/langref/test_inline_switch_union_tag.zig index dcefd4b0a1..4fe0147c81 100644 --- a/doc/langref/test_inline_switch_union_tag.zig +++ b/doc/langref/test_inline_switch_union_tag.zig @@ -1,5 +1,5 @@ const std = @import("std"); -const expect = std.testing.expect; +const expectEqual = std.testing.expectEqual; const U = union(enum) { a: u32, @@ -21,7 +21,7 @@ fn getNum(u: U) u32 { test "test" { const u = U{ .b = 42 }; - try expect(getNum(u) == 42); + try expectEqual(42, getNum(u)); } // test diff --git a/doc/langref/test_inline_while.zig b/doc/langref/test_inline_while.zig index 3422b647e9..5cc7166529 100644 --- a/doc/langref/test_inline_while.zig +++ b/doc/langref/test_inline_while.zig @@ -1,4 +1,4 @@ -const expect = @import("std").testing.expect; +const expectEqual = @import("std").testing.expectEqual; test "inline while loop" { comptime var i = 0; @@ -12,7 +12,7 @@ test "inline while loop" { }; sum += typeNameLength(T); } - try expect(sum == 9); + try expectEqual(9, sum); } fn typeNameLength(comptime T: type) usize { diff --git a/doc/langref/test_integer_pointer_conversion.zig b/doc/langref/test_integer_pointer_conversion.zig index 98653cc7e2..f2c67f8719 100644 --- a/doc/langref/test_integer_pointer_conversion.zig +++ b/doc/langref/test_integer_pointer_conversion.zig @@ -1,10 +1,10 @@ -const expect = @import("std").testing.expect; +const expectEqual = @import("std").testing.expectEqual; test "@intFromPtr and @ptrFromInt" { const ptr: *i32 = @ptrFromInt(0xdeadbee0); const addr = @intFromPtr(ptr); - try expect(@TypeOf(addr) == usize); - try expect(addr == 0xdeadbee0); + try expectEqual(usize, @TypeOf(addr)); + try expectEqual(0xdeadbee0, addr); } // test diff --git a/doc/langref/test_integer_widening.zig b/doc/langref/test_integer_widening.zig index 8b5b5fdb88..08627d999f 100644 --- a/doc/langref/test_integer_widening.zig +++ b/doc/langref/test_integer_widening.zig @@ -1,6 +1,6 @@ const std = @import("std"); const builtin = @import("builtin"); -const expect = std.testing.expect; +const expectEqual = std.testing.expectEqual; const mem = std.mem; test "integer widening" { @@ -10,13 +10,13 @@ test "integer widening" { const d: u64 = c; const e: u64 = d; const f: u128 = e; - try expect(f == a); + try expectEqual(f, a); } test "implicit unsigned integer to signed integer" { const a: u8 = 250; const b: i16 = a; - try expect(b == 250); + try expectEqual(250, b); } test "float widening" { @@ -24,7 +24,7 @@ test "float widening" { const b: f32 = a; const c: f64 = b; const d: f128 = c; - try expect(d == a); + try expectEqual(d, a); } // test diff --git a/doc/langref/test_labeled_break.zig b/doc/langref/test_labeled_break.zig index 0310b997e3..52a902d358 100644 --- a/doc/langref/test_labeled_break.zig +++ b/doc/langref/test_labeled_break.zig @@ -1,5 +1,5 @@ const std = @import("std"); -const expect = std.testing.expect; +const expectEqual = std.testing.expectEqual; test "labeled break from labeled block expression" { var y: i32 = 123; @@ -8,8 +8,8 @@ test "labeled break from labeled block expression" { y += 1; break :blk y; }; - try expect(x == 124); - try expect(y == 124); + try expectEqual(124, x); + try expectEqual(124, y); } // test diff --git a/doc/langref/test_misaligned_pointer.zig b/doc/langref/test_misaligned_pointer.zig index 11795ce090..b635d87c59 100644 --- a/doc/langref/test_misaligned_pointer.zig +++ b/doc/langref/test_misaligned_pointer.zig @@ -1,5 +1,5 @@ const std = @import("std"); -const expect = std.testing.expect; +const expectEqual = std.testing.expectEqual; const BitField = packed struct { a: u3, @@ -14,7 +14,7 @@ var bit_field = BitField{ }; test "pointer to non-byte-aligned field" { - try expect(bar(&bit_field.b) == 2); + try expectEqual(2, bar(&bit_field.b)); } fn bar(x: *const u3) u3 { diff --git a/doc/langref/test_multidimensional_arrays.zig b/doc/langref/test_multidimensional_arrays.zig index c88e8cb16a..6c7fefcaea 100644 --- a/doc/langref/test_multidimensional_arrays.zig +++ b/doc/langref/test_multidimensional_arrays.zig @@ -1,5 +1,4 @@ const std = @import("std"); -const expect = std.testing.expect; const expectEqual = std.testing.expectEqual; const mat4x5 = [4][5]f32{ @@ -13,20 +12,20 @@ test "multidimensional arrays" { try expectEqual(mat4x5[1], [_]f32{ 0.0, 1.0, 0.0, 1.0, 0.0 }); // Access the 2D array by indexing the outer array, and then the inner array. - try expect(mat4x5[3][4] == 9.9); + try expectEqual(9.9, mat4x5[3][4]); // Here we iterate with for loops. for (mat4x5, 0..) |row, row_index| { for (row, 0..) |cell, column_index| { if (row_index == column_index) { - try expect(cell == 1.0); + try expectEqual(1.0, cell); } } } // Initialize a multidimensional array to zeros. const all_zero: [4][5]f32 = .{.{0} ** 5} ** 4; - try expect(all_zero[0][0] == 0); + try expectEqual(0, all_zero[0][0]); } // test diff --git a/doc/langref/test_namespaced_container_level_variable.zig b/doc/langref/test_namespaced_container_level_variable.zig index 22f56d7d13..f35aa90d8e 100644 --- a/doc/langref/test_namespaced_container_level_variable.zig +++ b/doc/langref/test_namespaced_container_level_variable.zig @@ -1,9 +1,9 @@ const std = @import("std"); -const expect = std.testing.expect; +const expectEqual = std.testing.expectEqual; test "namespaced container level variable" { - try expect(foo() == 1235); - try expect(foo() == 1236); + try expectEqual(1235, foo()); + try expectEqual(1236, foo()); } const S = struct { diff --git a/doc/langref/test_noreturn_from_exit.zig b/doc/langref/test_noreturn_from_exit.zig index 4c5277d2e6..22ea8b4f49 100644 --- a/doc/langref/test_noreturn_from_exit.zig +++ b/doc/langref/test_noreturn_from_exit.zig @@ -1,14 +1,14 @@ const std = @import("std"); const builtin = @import("builtin"); const native_arch = builtin.cpu.arch; -const expect = std.testing.expect; +const expectEqual = std.testing.expectEqual; const WINAPI: std.builtin.CallingConvention = if (native_arch == .x86) .{ .x86_stdcall = .{} } else .c; extern "kernel32" fn ExitProcess(exit_code: c_uint) callconv(WINAPI) noreturn; test "foo" { const value = bar() catch ExitProcess(1); - try expect(value == 1234); + try expectEqual(1234, value); } fn bar() anyerror!u32 { diff --git a/doc/langref/test_null_terminated_array.zig b/doc/langref/test_null_terminated_array.zig index c89ed59bbd..53ba0d0c65 100644 --- a/doc/langref/test_null_terminated_array.zig +++ b/doc/langref/test_null_terminated_array.zig @@ -1,21 +1,21 @@ const std = @import("std"); -const expect = std.testing.expect; +const expectEqual = std.testing.expectEqual; test "0-terminated sentinel array" { const array = [_:0]u8{ 1, 2, 3, 4 }; - try expect(@TypeOf(array) == [4:0]u8); - try expect(array.len == 4); - try expect(array[4] == 0); + try expectEqual([4:0]u8, @TypeOf(array)); + try expectEqual(4, array.len); + try expectEqual(0, array[4]); } test "extra 0s in 0-terminated sentinel array" { // The sentinel value may appear earlier, but does not influence the compile-time 'len'. const array = [_:0]u8{ 1, 0, 0, 4 }; - try expect(@TypeOf(array) == [4:0]u8); - try expect(array.len == 4); - try expect(array[4] == 0); + try expectEqual([4:0]u8, @TypeOf(array)); + try expectEqual(4, array.len); + try expectEqual(0, array[4]); } // test diff --git a/doc/langref/test_null_terminated_slice.zig b/doc/langref/test_null_terminated_slice.zig index 9f14f9bc1d..44fad5671d 100644 --- a/doc/langref/test_null_terminated_slice.zig +++ b/doc/langref/test_null_terminated_slice.zig @@ -1,11 +1,11 @@ const std = @import("std"); -const expect = std.testing.expect; +const expectEqual = std.testing.expectEqual; test "0-terminated slice" { const slice: [:0]const u8 = "hello"; - try expect(slice.len == 5); - try expect(slice[5] == 0); + try expectEqual(5, slice.len); + try expectEqual(0, slice[5]); } // test diff --git a/doc/langref/test_null_terminated_slicing.zig b/doc/langref/test_null_terminated_slicing.zig index e5a248bed3..b1d5263976 100644 --- a/doc/langref/test_null_terminated_slicing.zig +++ b/doc/langref/test_null_terminated_slicing.zig @@ -1,5 +1,5 @@ const std = @import("std"); -const expect = std.testing.expect; +const expectEqual = std.testing.expectEqual; test "0-terminated slicing" { var array = [_]u8{ 3, 2, 1, 0, 3, 2, 1, 0 }; @@ -7,8 +7,8 @@ test "0-terminated slicing" { _ = &runtime_length; const slice = array[0..runtime_length :0]; - try expect(@TypeOf(slice) == [:0]u8); - try expect(slice.len == 3); + try expectEqual([:0]u8, @TypeOf(slice)); + try expectEqual(3, slice.len); } // test diff --git a/doc/langref/test_optional_pointer.zig b/doc/langref/test_optional_pointer.zig index acad240fd2..dc3d3bbfda 100644 --- a/doc/langref/test_optional_pointer.zig +++ b/doc/langref/test_optional_pointer.zig @@ -1,4 +1,4 @@ -const expect = @import("std").testing.expect; +const expectEqual = @import("std").testing.expectEqual; test "optional pointers" { // Pointers cannot be null. If you want a null pointer, use the optional @@ -8,11 +8,11 @@ test "optional pointers" { var x: i32 = 1; ptr = &x; - try expect(ptr.?.* == 1); + try expectEqual(1, ptr.?.*); // Optional pointers are the same size as normal pointers, because pointer // value 0 is used as the null value. - try expect(@sizeOf(?*i32) == @sizeOf(*i32)); + try expectEqual(@sizeOf(?*i32), @sizeOf(*i32)); } // test diff --git a/doc/langref/test_optional_type.zig b/doc/langref/test_optional_type.zig index 594198b49e..97a87c21f2 100644 --- a/doc/langref/test_optional_type.zig +++ b/doc/langref/test_optional_type.zig @@ -1,4 +1,4 @@ -const expect = @import("std").testing.expect; +const expectEqual = @import("std").testing.expectEqual; test "optional type" { // Declare an optional and coerce from null: @@ -8,7 +8,7 @@ test "optional type" { foo = 1234; // Use compile-time reflection to access the child type of the optional: - try comptime expect(@typeInfo(@TypeOf(foo)).optional.child == i32); + try comptime expectEqual(i32, @typeInfo(@TypeOf(foo)).optional.child); } // test diff --git a/doc/langref/test_overaligned_packed_struct.zig b/doc/langref/test_overaligned_packed_struct.zig index 8bf52b3297..7c67800192 100644 --- a/doc/langref/test_overaligned_packed_struct.zig +++ b/doc/langref/test_overaligned_packed_struct.zig @@ -1,5 +1,5 @@ const std = @import("std"); -const expect = std.testing.expect; +const expectEqual = std.testing.expectEqual; const S = packed struct { a: u32, @@ -9,7 +9,7 @@ test "overaligned pointer to packed struct" { var foo: S align(4) = .{ .a = 1, .b = 2 }; const ptr: *align(4) S = &foo; const ptr_to_b = &ptr.b; - try expect(ptr_to_b.* == 2); + try expectEqual(2, ptr_to_b.*); } // test diff --git a/doc/langref/test_packed_struct_equality.zig b/doc/langref/test_packed_struct_equality.zig index d1c755af19..1449d05652 100644 --- a/doc/langref/test_packed_struct_equality.zig +++ b/doc/langref/test_packed_struct_equality.zig @@ -1,5 +1,5 @@ const std = @import("std"); -const expect = std.testing.expect; +const expectEqual = std.testing.expectEqual; test "packed struct equality" { const S = packed struct { @@ -8,7 +8,7 @@ test "packed struct equality" { }; const x: S = .{ .a = 1, .b = 2 }; const y: S = .{ .b = 2, .a = 1 }; - try expect(x == y); + try expectEqual(x, y); } // test diff --git a/doc/langref/test_packed_struct_field_address.zig b/doc/langref/test_packed_struct_field_address.zig index 979c0377f6..756d36c3a9 100644 --- a/doc/langref/test_packed_struct_field_address.zig +++ b/doc/langref/test_packed_struct_field_address.zig @@ -1,5 +1,5 @@ const std = @import("std"); -const expect = std.testing.expect; +const expectEqual = std.testing.expectEqual; const BitField = packed struct { a: u3, @@ -14,8 +14,8 @@ var bit_field = BitField{ }; test "pointers of sub-byte-aligned fields share addresses" { - try expect(@intFromPtr(&bit_field.a) == @intFromPtr(&bit_field.b)); - try expect(@intFromPtr(&bit_field.a) == @intFromPtr(&bit_field.c)); + try expectEqual(@intFromPtr(&bit_field.a), @intFromPtr(&bit_field.b)); + try expectEqual(@intFromPtr(&bit_field.a), @intFromPtr(&bit_field.c)); } // test diff --git a/doc/langref/test_packed_structs.zig b/doc/langref/test_packed_structs.zig index da1f259d5e..7e46f852a0 100644 --- a/doc/langref/test_packed_structs.zig +++ b/doc/langref/test_packed_structs.zig @@ -1,6 +1,6 @@ const std = @import("std"); const native_endian = @import("builtin").target.cpu.arch.endian(); -const expect = std.testing.expect; +const expectEqual = std.testing.expectEqual; const Full = packed struct { number: u16, @@ -17,23 +17,23 @@ test "@bitCast between packed structs" { } fn doTheTest() !void { - try expect(@sizeOf(Full) == 2); - try expect(@sizeOf(Divided) == 2); + try expectEqual(2, @sizeOf(Full)); + try expectEqual(2, @sizeOf(Divided)); const full = Full{ .number = 0x1234 }; const divided: Divided = @bitCast(full); - try expect(divided.half1 == 0x34); - try expect(divided.quarter3 == 0x2); - try expect(divided.quarter4 == 0x1); + try expectEqual(0x34, divided.half1); + try expectEqual(0x2, divided.quarter3); + try expectEqual(0x1, divided.quarter4); const ordered: [2]u8 = @bitCast(full); switch (native_endian) { .big => { - try expect(ordered[0] == 0x12); - try expect(ordered[1] == 0x34); + try expectEqual(0x12, ordered[0]); + try expectEqual(0x34, ordered[1]); }, .little => { - try expect(ordered[0] == 0x34); - try expect(ordered[1] == 0x12); + try expectEqual(0x34, ordered[0]); + try expectEqual(0x12, ordered[1]); }, } } diff --git a/doc/langref/test_pass_by_reference_or_value.zig b/doc/langref/test_pass_by_reference_or_value.zig index 0bde07747e..e35ccf8ce4 100644 --- a/doc/langref/test_pass_by_reference_or_value.zig +++ b/doc/langref/test_pass_by_reference_or_value.zig @@ -11,10 +11,10 @@ fn foo(point: Point) i32 { return point.x + point.y; } -const expect = @import("std").testing.expect; +const expectEqual = @import("std").testing.expectEqual; test "pass struct to function" { - try expect(foo(Point{ .x = 1, .y = 2 }) == 3); + try expectEqual(3, foo(Point{ .x = 1, .y = 2 })); } // test diff --git a/doc/langref/test_peer_type_resolution.zig b/doc/langref/test_peer_type_resolution.zig index ad0b9f35cb..9bbac881e3 100644 --- a/doc/langref/test_peer_type_resolution.zig +++ b/doc/langref/test_peer_type_resolution.zig @@ -1,20 +1,20 @@ const std = @import("std"); -const expect = std.testing.expect; -const mem = std.mem; +const expectEqual = std.testing.expectEqual; +const expectEqualStrings = std.testing.expectEqualStrings; test "peer resolve int widening" { const a: i8 = 12; const b: i16 = 34; const c = a + b; - try expect(c == 46); - try expect(@TypeOf(c) == i16); + try expectEqual(46, c); + try expectEqual(i16, @TypeOf(c)); } test "peer resolve arrays of different size to const slice" { - try expect(mem.eql(u8, boolToStr(true), "true")); - try expect(mem.eql(u8, boolToStr(false), "false")); - try comptime expect(mem.eql(u8, boolToStr(true), "true")); - try comptime expect(mem.eql(u8, boolToStr(false), "false")); + try expectEqualStrings("true", boolToStr(true)); + try expectEqualStrings("false", boolToStr(false)); + try comptime expectEqualStrings("true", boolToStr(true)); + try comptime expectEqualStrings("false", boolToStr(false)); } fn boolToStr(b: bool) []const u8 { return if (b) "true" else "false"; @@ -27,16 +27,16 @@ test "peer resolve array and const slice" { fn testPeerResolveArrayConstSlice(b: bool) !void { const value1 = if (b) "aoeu" else @as([]const u8, "zz"); const value2 = if (b) @as([]const u8, "zz") else "aoeu"; - try expect(mem.eql(u8, value1, "aoeu")); - try expect(mem.eql(u8, value2, "zz")); + try expectEqualStrings("aoeu", value1); + try expectEqualStrings("zz", value2); } test "peer type resolution: ?T and T" { - try expect(peerTypeTAndOptionalT(true, false).? == 0); - try expect(peerTypeTAndOptionalT(false, false).? == 3); + try expectEqual(0, peerTypeTAndOptionalT(true, false).?); + try expectEqual(3, peerTypeTAndOptionalT(false, false).?); comptime { - try expect(peerTypeTAndOptionalT(true, false).? == 0); - try expect(peerTypeTAndOptionalT(false, false).? == 3); + try expectEqual(0, peerTypeTAndOptionalT(true, false).?); + try expectEqual(3, peerTypeTAndOptionalT(false, false).?); } } fn peerTypeTAndOptionalT(c: bool, b: bool) ?usize { @@ -48,11 +48,11 @@ fn peerTypeTAndOptionalT(c: bool, b: bool) ?usize { } test "peer type resolution: *[0]u8 and []const u8" { - try expect(peerTypeEmptyArrayAndSlice(true, "hi").len == 0); - try expect(peerTypeEmptyArrayAndSlice(false, "hi").len == 1); + try expectEqual(0, peerTypeEmptyArrayAndSlice(true, "hi").len); + try expectEqual(1, peerTypeEmptyArrayAndSlice(false, "hi").len); comptime { - try expect(peerTypeEmptyArrayAndSlice(true, "hi").len == 0); - try expect(peerTypeEmptyArrayAndSlice(false, "hi").len == 1); + try expectEqual(0, peerTypeEmptyArrayAndSlice(true, "hi").len); + try expectEqual(1, peerTypeEmptyArrayAndSlice(false, "hi").len); } } fn peerTypeEmptyArrayAndSlice(a: bool, slice: []const u8) []const u8 { @@ -66,14 +66,14 @@ test "peer type resolution: *[0]u8, []const u8, and anyerror![]u8" { { var data = "hi".*; const slice = data[0..]; - try expect((try peerTypeEmptyArrayAndSliceAndError(true, slice)).len == 0); - try expect((try peerTypeEmptyArrayAndSliceAndError(false, slice)).len == 1); + try expectEqual(0, (try peerTypeEmptyArrayAndSliceAndError(true, slice)).len); + try expectEqual(1, (try peerTypeEmptyArrayAndSliceAndError(false, slice)).len); } comptime { var data = "hi".*; const slice = data[0..]; - try expect((try peerTypeEmptyArrayAndSliceAndError(true, slice)).len == 0); - try expect((try peerTypeEmptyArrayAndSliceAndError(false, slice)).len == 1); + try expectEqual(0, (try peerTypeEmptyArrayAndSliceAndError(true, slice)).len); + try expectEqual(1, (try peerTypeEmptyArrayAndSliceAndError(false, slice)).len); } } fn peerTypeEmptyArrayAndSliceAndError(a: bool, slice: []u8) anyerror![]u8 { @@ -87,8 +87,8 @@ fn peerTypeEmptyArrayAndSliceAndError(a: bool, slice: []u8) anyerror![]u8 { test "peer type resolution: *const T and ?*T" { const a: *const usize = @ptrFromInt(0x123456780); const b: ?*usize = @ptrFromInt(0x123456780); - try expect(a == b); - try expect(b == a); + try expectEqual(a, b); + try expectEqual(b, a); } test "peer type resolution: error union switch" { @@ -104,7 +104,7 @@ test "peer type resolution: error union switch" { error.B => 1, error.C => null, }; - try expect(@TypeOf(b) == ?u32); + try expectEqual(?u32, @TypeOf(b)); // The non-error and error cases are only peers if the error case is just a switch expression; // the pattern `x catch |err| blk: { switch (err) {...} }` does not consider the unwrapped `x` @@ -114,7 +114,7 @@ test "peer type resolution: error union switch" { error.B => 1, error.C => null, }; - try expect(@TypeOf(c) == ?u32); + try expectEqual(?u32, @TypeOf(c)); } // test diff --git a/doc/langref/test_pointer_arithmetic.zig b/doc/langref/test_pointer_arithmetic.zig index 2157428502..457db08ba2 100644 --- a/doc/langref/test_pointer_arithmetic.zig +++ b/doc/langref/test_pointer_arithmetic.zig @@ -1,19 +1,19 @@ -const expect = @import("std").testing.expect; +const expectEqual = @import("std").testing.expectEqual; test "pointer arithmetic with many-item pointer" { const array = [_]i32{ 1, 2, 3, 4 }; var ptr: [*]const i32 = &array; - try expect(ptr[0] == 1); + try expectEqual(1, ptr[0]); ptr += 1; - try expect(ptr[0] == 2); + try expectEqual(2, ptr[0]); // slicing a many-item pointer without an end is equivalent to // pointer arithmetic: `ptr[start..] == ptr + start` - try expect(ptr[1..] == ptr + 1); + try expectEqual(ptr[1..], ptr + 1); // subtraction between any two pointers except slices based on element size is supported - try expect(&ptr[1] - &ptr[0] == 1); + try expectEqual(1, &ptr[1] - &ptr[0]); } test "pointer arithmetic with slices" { @@ -22,14 +22,14 @@ test "pointer arithmetic with slices" { _ = &length; // suppress 'var is never mutated' error var slice = array[length..array.len]; - try expect(slice[0] == 1); - try expect(slice.len == 4); + try expectEqual(1, slice[0]); + try expectEqual(4, slice.len); slice.ptr += 1; // now the slice is in an bad state since len has not been updated - try expect(slice[0] == 2); - try expect(slice.len == 4); + try expectEqual(2, slice[0]); + try expectEqual(4, slice.len); } // test diff --git a/doc/langref/test_pointer_casting.zig b/doc/langref/test_pointer_casting.zig index 359d1dc838..0a3fde2efe 100644 --- a/doc/langref/test_pointer_casting.zig +++ b/doc/langref/test_pointer_casting.zig @@ -1,23 +1,23 @@ const std = @import("std"); -const expect = std.testing.expect; +const expectEqual = std.testing.expectEqual; test "pointer casting" { const bytes align(@alignOf(u32)) = [_]u8{ 0x12, 0x12, 0x12, 0x12 }; const u32_ptr: *const u32 = @ptrCast(&bytes); - try expect(u32_ptr.* == 0x12121212); + try expectEqual(0x12121212, u32_ptr.*); // Even this example is contrived - there are better ways to do the above than // pointer casting. For example, using a slice narrowing cast: const u32_value = std.mem.bytesAsSlice(u32, bytes[0..])[0]; - try expect(u32_value == 0x12121212); + try expectEqual(0x12121212, u32_value); // And even another way, the most straightforward way to do it: - try expect(@as(u32, @bitCast(bytes)) == 0x12121212); + try expectEqual(0x12121212, @as(u32, @bitCast(bytes))); } test "pointer child type" { // pointer types have a `child` field which tells you the type they point to. - try expect(@typeInfo(*u32).pointer.child == u32); + try expectEqual(u32, @typeInfo(*u32).pointer.child); } // test diff --git a/doc/langref/test_pointer_coerce_const_optional.zig b/doc/langref/test_pointer_coerce_const_optional.zig index f955820593..fccb4806b4 100644 --- a/doc/langref/test_pointer_coerce_const_optional.zig +++ b/doc/langref/test_pointer_coerce_const_optional.zig @@ -1,11 +1,11 @@ const std = @import("std"); -const expect = std.testing.expect; +const expectEqualStrings = std.testing.expectEqualStrings; const mem = std.mem; test "cast *[1][*:0]const u8 to []const ?[*:0]const u8" { const window_name = [1][*:0]const u8{"window name"}; const x: []const ?[*:0]const u8 = &window_name; - try expect(mem.eql(u8, mem.span(x[0].?), "window name")); + try expectEqualStrings("window name", mem.span(x[0].?)); } // test diff --git a/doc/langref/test_pointer_to_non-byte_aligned_field.zig b/doc/langref/test_pointer_to_non-byte_aligned_field.zig index 336337caee..fcf45e74f4 100644 --- a/doc/langref/test_pointer_to_non-byte_aligned_field.zig +++ b/doc/langref/test_pointer_to_non-byte_aligned_field.zig @@ -1,5 +1,5 @@ const std = @import("std"); -const expect = std.testing.expect; +const expectEqual = std.testing.expectEqual; const BitField = packed struct { a: u3, @@ -15,7 +15,7 @@ var foo = BitField{ test "pointer to non-byte-aligned field" { const ptr = &foo.b; - try expect(ptr.* == 2); + try expectEqual(2, ptr.*); } // test diff --git a/doc/langref/test_reduce_builtin.zig b/doc/langref/test_reduce_builtin.zig index 82b78b8380..b411b05eea 100644 --- a/doc/langref/test_reduce_builtin.zig +++ b/doc/langref/test_reduce_builtin.zig @@ -1,15 +1,15 @@ const std = @import("std"); -const expect = std.testing.expect; +const expectEqual = std.testing.expectEqual; test "vector @reduce" { const V = @Vector(4, i32); const value = V{ 1, -1, 1, -1 }; const result = value > @as(V, @splat(0)); // result is { true, false, true, false }; - try comptime expect(@TypeOf(result) == @Vector(4, bool)); + try comptime expectEqual(@Vector(4, bool), @TypeOf(result)); const is_all_true = @reduce(.And, result); - try comptime expect(@TypeOf(is_all_true) == bool); - try expect(is_all_true == false); + try comptime expectEqual(bool, @TypeOf(is_all_true)); + try expectEqual(false, is_all_true); } // test diff --git a/doc/langref/test_round_builtin.zig b/doc/langref/test_round_builtin.zig index a317ca79f0..e28b7d5dab 100644 --- a/doc/langref/test_round_builtin.zig +++ b/doc/langref/test_round_builtin.zig @@ -1,10 +1,10 @@ -const expect = @import("std").testing.expect; +const expectEqual = @import("std").testing.expectEqual; test "@round" { - try expect(@round(1.4) == 1); - try expect(@round(1.5) == 2); - try expect(@round(-1.4) == -1); - try expect(@round(-2.5) == -3); + try expectEqual(1, @round(1.4)); + try expectEqual(2, @round(1.5)); + try expectEqual(-1, @round(-1.4)); + try expectEqual(-3, @round(-2.5)); } // test diff --git a/doc/langref/test_sentinel_mismatch.zig b/doc/langref/test_sentinel_mismatch.zig index afa1fd295d..df60680351 100644 --- a/doc/langref/test_sentinel_mismatch.zig +++ b/doc/langref/test_sentinel_mismatch.zig @@ -1,5 +1,5 @@ const std = @import("std"); -const expect = std.testing.expect; +const expectEqual = std.testing.expectEqual; test "sentinel mismatch" { var array = [_]u8{ 3, 2, 1, 0 }; diff --git a/doc/langref/test_shuffle_builtin.zig b/doc/langref/test_shuffle_builtin.zig index c73d1bbfab..1b319d2f47 100644 --- a/doc/langref/test_shuffle_builtin.zig +++ b/doc/langref/test_shuffle_builtin.zig @@ -1,5 +1,5 @@ const std = @import("std"); -const expect = std.testing.expect; +const expectEqualStrings = std.testing.expectEqualStrings; test "vector @shuffle" { const a = @Vector(7, u8){ 'o', 'l', 'h', 'e', 'r', 'z', 'w' }; @@ -9,12 +9,12 @@ test "vector @shuffle" { // Notice that we can re-order, duplicate, or omit elements of the input vector const mask1 = @Vector(5, i32){ 2, 3, 1, 1, 0 }; const res1: @Vector(5, u8) = @shuffle(u8, a, undefined, mask1); - try expect(std.mem.eql(u8, &@as([5]u8, res1), "hello")); + try expectEqualStrings("hello", &@as([5]u8, res1)); // Combining two vectors const mask2 = @Vector(6, i32){ -1, 0, 4, 1, -2, -3 }; const res2: @Vector(6, u8) = @shuffle(u8, a, b, mask2); - try expect(std.mem.eql(u8, &@as([6]u8, res2), "world!")); + try expectEqualStrings("world!", &@as([6]u8, res2)); } // test diff --git a/doc/langref/test_simple_union.zig b/doc/langref/test_simple_union.zig index 899666de07..f257575adb 100644 --- a/doc/langref/test_simple_union.zig +++ b/doc/langref/test_simple_union.zig @@ -1,5 +1,5 @@ const std = @import("std"); -const expect = std.testing.expect; +const expectEqual = std.testing.expectEqual; const Payload = union { int: i64, @@ -8,9 +8,9 @@ const Payload = union { }; test "simple union" { var payload = Payload{ .int = 1234 }; - try expect(payload.int == 1234); + try expectEqual(1234, payload.int); payload = Payload{ .float = 12.34 }; - try expect(payload.float == 12.34); + try expectEqual(12.34, payload.float); } // test diff --git a/doc/langref/test_single_item_pointer.zig b/doc/langref/test_single_item_pointer.zig index 79252b1fa0..0171147d82 100644 --- a/doc/langref/test_single_item_pointer.zig +++ b/doc/langref/test_single_item_pointer.zig @@ -1,4 +1,4 @@ -const expect = @import("std").testing.expect; +const expectEqual = @import("std").testing.expectEqual; test "address of syntax" { // Get the address of a variable: @@ -6,17 +6,17 @@ test "address of syntax" { const x_ptr = &x; // Dereference a pointer: - try expect(x_ptr.* == 1234); + try expectEqual(1234, x_ptr.*); // When you get the address of a const variable, you get a const single-item pointer. - try expect(@TypeOf(x_ptr) == *const i32); + try expectEqual(*const i32, @TypeOf(x_ptr)); // If you want to mutate the value, you'd need an address of a mutable variable: var y: i32 = 5678; const y_ptr = &y; - try expect(@TypeOf(y_ptr) == *i32); + try expectEqual(*i32, @TypeOf(y_ptr)); y_ptr.* += 1; - try expect(y_ptr.* == 5679); + try expectEqual(5679, y_ptr.*); } test "pointer array access" { @@ -25,11 +25,11 @@ test "pointer array access" { // does not support pointer arithmetic. var array = [_]u8{ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; const ptr = &array[2]; - try expect(@TypeOf(ptr) == *u8); + try expectEqual(*u8, @TypeOf(ptr)); - try expect(array[2] == 3); + try expectEqual(3, array[2]); ptr.* += 1; - try expect(array[2] == 4); + try expectEqual(4, array[2]); } test "slice syntax" { @@ -39,11 +39,11 @@ test "slice syntax" { // Convert to array pointer using slice syntax: const x_array_ptr = x_ptr[0..1]; - try expect(@TypeOf(x_array_ptr) == *[1]i32); + try expectEqual(*[1]i32, @TypeOf(x_array_ptr)); // Coerce to many-item pointer: const x_many_ptr: [*]i32 = x_array_ptr; - try expect(x_many_ptr[0] == 1234); + try expectEqual(1234, x_many_ptr[0]); } // test diff --git a/doc/langref/test_slice_bounds.zig b/doc/langref/test_slice_bounds.zig index 23022a2757..8de31a7d32 100644 --- a/doc/langref/test_slice_bounds.zig +++ b/doc/langref/test_slice_bounds.zig @@ -1,15 +1,15 @@ -const expect = @import("std").testing.expect; +const expectEqual = @import("std").testing.expectEqual; test "pointer slicing" { var array = [_]u8{ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; var start: usize = 2; // var to make it runtime-known _ = &start; // suppress 'var is never mutated' error const slice = array[start..4]; - try expect(slice.len == 2); + try expectEqual(2, slice.len); - try expect(array[3] == 4); + try expectEqual(4, array[3]); slice[1] += 1; - try expect(array[3] == 5); + try expectEqual(5, array[3]); } // test diff --git a/doc/langref/test_slices.zig b/doc/langref/test_slices.zig index e1a51e4651..a5ac8cb926 100644 --- a/doc/langref/test_slices.zig +++ b/doc/langref/test_slices.zig @@ -1,6 +1,6 @@ const std = @import("std"); -const expect = std.testing.expect; -const mem = std.mem; +const expectEqual = std.testing.expectEqual; +const expectEqualStrings = std.testing.expectEqualStrings; const fmt = std.fmt; test "using slices for strings" { @@ -23,13 +23,13 @@ test "using slices for strings" { // Generally, you can use UTF-8 and not worry about whether something is a // string. If you don't need to deal with individual characters, no need // to decode. - try expect(mem.eql(u8, hello_world, "hello 世界")); + try expectEqualStrings("hello 世界", hello_world); } test "slice pointer" { var array: [10]u8 = undefined; const ptr = &array; - try expect(@TypeOf(ptr) == *[10]u8); + try expectEqual(*[10]u8, @TypeOf(ptr)); // A pointer to an array can be sliced just like an array: var start: usize = 0; @@ -37,16 +37,16 @@ test "slice pointer" { _ = .{ &start, &end }; const slice = ptr[start..end]; // The slice is mutable because we sliced a mutable pointer. - try expect(@TypeOf(slice) == []u8); + try expectEqual([]u8, @TypeOf(slice)); slice[2] = 3; - try expect(array[2] == 3); + try expectEqual(3, array[2]); // Again, slicing with comptime-known indexes will produce another pointer // to an array: const ptr2 = slice[2..3]; - try expect(ptr2.len == 1); - try expect(ptr2[0] == 3); - try expect(@TypeOf(ptr2) == *[1]u8); + try expectEqual(1, ptr2.len); + try expectEqual(3, ptr2[0]); + try expectEqual(*[1]u8, @TypeOf(ptr2)); } // test diff --git a/doc/langref/test_splat_builtin.zig b/doc/langref/test_splat_builtin.zig index d11556b1a3..d00240620e 100644 --- a/doc/langref/test_splat_builtin.zig +++ b/doc/langref/test_splat_builtin.zig @@ -1,16 +1,16 @@ const std = @import("std"); -const expect = std.testing.expect; +const expectEqualSlices = std.testing.expectEqualSlices; test "vector @splat" { const scalar: u32 = 5; const result: @Vector(4, u32) = @splat(scalar); - try expect(std.mem.eql(u32, &@as([4]u32, result), &[_]u32{ 5, 5, 5, 5 })); + try expectEqualSlices(u32, &[_]u32{ 5, 5, 5, 5 }, &@as([4]u32, result)); } test "array @splat" { const scalar: u32 = 5; const result: [4]u32 = @splat(scalar); - try expect(std.mem.eql(u32, &@as([4]u32, result), &[_]u32{ 5, 5, 5, 5 })); + try expectEqualSlices(u32, &[_]u32{ 5, 5, 5, 5 }, &@as([4]u32, result)); } // test diff --git a/doc/langref/test_src_builtin.zig b/doc/langref/test_src_builtin.zig index 10199be68e..7286f8f5a8 100644 --- a/doc/langref/test_src_builtin.zig +++ b/doc/langref/test_src_builtin.zig @@ -1,5 +1,6 @@ const std = @import("std"); const expect = std.testing.expect; +const expectEqual = std.testing.expectEqual; test "@src" { try doTheTest(); @@ -8,8 +9,8 @@ test "@src" { fn doTheTest() !void { const src = @src(); - try expect(src.line == 9); - try expect(src.column == 17); + try expectEqual(10, src.line); + try expectEqual(17, src.column); try expect(std.mem.endsWith(u8, src.fn_name, "doTheTest")); try expect(std.mem.endsWith(u8, src.file, "test_src_builtin.zig")); } diff --git a/doc/langref/test_static_local_variable.zig b/doc/langref/test_static_local_variable.zig index 4531a96a37..58b4505be4 100644 --- a/doc/langref/test_static_local_variable.zig +++ b/doc/langref/test_static_local_variable.zig @@ -1,9 +1,9 @@ const std = @import("std"); -const expect = std.testing.expect; +const expectEqual = std.testing.expectEqual; test "static local variable" { - try expect(foo() == 1235); - try expect(foo() == 1236); + try expectEqual(1235, foo()); + try expectEqual(1236, foo()); } fn foo() i32 { diff --git a/doc/langref/test_struct_result.zig b/doc/langref/test_struct_result.zig index cb8ecf0673..62b32ecf10 100644 --- a/doc/langref/test_struct_result.zig +++ b/doc/langref/test_struct_result.zig @@ -1,5 +1,5 @@ const std = @import("std"); -const expect = std.testing.expect; +const expectEqual = std.testing.expectEqual; const Point = struct { x: i32, y: i32 }; @@ -8,8 +8,8 @@ test "anonymous struct literal" { .x = 13, .y = 67, }; - try expect(pt.x == 13); - try expect(pt.y == 67); + try expectEqual(13, pt.x); + try expectEqual(67, pt.y); } // test diff --git a/doc/langref/test_structs.zig b/doc/langref/test_structs.zig index b62fd3578d..414dd8be48 100644 --- a/doc/langref/test_structs.zig +++ b/doc/langref/test_structs.zig @@ -34,12 +34,12 @@ const Vec3 = struct { test "dot product" { const v1 = Vec3.init(1.0, 0.0, 0.0); const v2 = Vec3.init(0.0, 1.0, 0.0); - try expect(v1.dot(v2) == 0.0); + try expectEqual(0.0, v1.dot(v2)); // Other than being available to call with dot syntax, struct methods are // not special. You can reference them as any other declaration inside // the struct: - try expect(Vec3.dot(v1, v2) == 0.0); + try expectEqual(0.0, Vec3.dot(v1, v2)); } // Structs can have declarations. @@ -48,8 +48,8 @@ const Empty = struct { pub const PI = 3.14; }; test "struct namespaced variable" { - try expect(Empty.PI == 3.14); - try expect(@sizeOf(Empty) == 0); + try expectEqual(3.14, Empty.PI); + try expectEqual(0, @sizeOf(Empty)); // Empty structs can be instantiated the same as usual. const does_nothing: Empty = .{}; @@ -69,7 +69,7 @@ test "field parent pointer" { .y = 0.5678, }; setYBasedOnX(&point.x, 0.9); - try expect(point.y == 0.9); + try expectEqual(0.9, point.y); } // Structs can be returned from functions. @@ -89,19 +89,19 @@ fn LinkedList(comptime T: type) type { test "linked list" { // Functions called at compile-time are memoized. - try expect(LinkedList(i32) == LinkedList(i32)); + try expectEqual(LinkedList(i32), LinkedList(i32)); const list = LinkedList(i32){ .first = null, .last = null, .len = 0, }; - try expect(list.len == 0); + try expectEqual(0, list.len); // Since types are first class values you can instantiate the type // by assigning it to a variable: const ListOfInts = LinkedList(i32); - try expect(ListOfInts == LinkedList(i32)); + try expectEqual(LinkedList(i32), ListOfInts); var node = ListOfInts.Node{ .prev = null, @@ -117,10 +117,10 @@ test "linked list" { // When using a pointer to a struct, fields can be accessed directly, // without explicitly dereferencing the pointer. // So you can do - try expect(list2.first.?.data == 1234); - // instead of try expect(list2.first.?.*.data == 1234); + try expectEqual(1234, list2.first.?.data); + // instead of try expectEqual(1234, list2.first.?.*.data); } -const expect = @import("std").testing.expect; +const expectEqual = @import("std").testing.expectEqual; // test diff --git a/doc/langref/test_switch.zig b/doc/langref/test_switch.zig index 33fabbdfcd..d6e67c1587 100644 --- a/doc/langref/test_switch.zig +++ b/doc/langref/test_switch.zig @@ -1,6 +1,6 @@ const std = @import("std"); const builtin = @import("builtin"); -const expect = std.testing.expect; +const expectEqual = std.testing.expectEqual; test "switch simple" { const a: u64 = 10; @@ -40,7 +40,7 @@ test "switch simple" { else => 9, }; - try expect(b == 1); + try expectEqual(1, b); } // Switch expressions can be used outside a function: diff --git a/doc/langref/test_switch_modify_tagged_union.zig b/doc/langref/test_switch_modify_tagged_union.zig index 96433900f0..ba5cc5193e 100644 --- a/doc/langref/test_switch_modify_tagged_union.zig +++ b/doc/langref/test_switch_modify_tagged_union.zig @@ -1,5 +1,5 @@ const std = @import("std"); -const expect = std.testing.expect; +const expectEqual = std.testing.expectEqual; const ComplexTypeTag = enum { ok, @@ -18,7 +18,7 @@ test "modify tagged union in switch" { ComplexTypeTag.not_ok => unreachable, } - try expect(c.ok == 43); + try expectEqual(43, c.ok); } // test diff --git a/doc/langref/test_switch_tagged_union.zig b/doc/langref/test_switch_tagged_union.zig index 2644817b47..568092dad9 100644 --- a/doc/langref/test_switch_tagged_union.zig +++ b/doc/langref/test_switch_tagged_union.zig @@ -1,4 +1,4 @@ -const expect = @import("std").testing.expect; +const expectEqual = @import("std").testing.expectEqual; test "switch on tagged union" { const Point = struct { @@ -31,8 +31,8 @@ test "switch on tagged union" { Item.d => 8, }; - try expect(b == 6); - try expect(a.c.x == 2); + try expectEqual(6, b); + try expectEqual(2, a.c.x); } // test diff --git a/doc/langref/test_tagName.zig b/doc/langref/test_tagName.zig index 8b0aa1cb28..1190089433 100644 --- a/doc/langref/test_tagName.zig +++ b/doc/langref/test_tagName.zig @@ -1,5 +1,5 @@ const std = @import("std"); -const expect = std.testing.expect; +const expectEqualSlices = std.testing.expectEqualSlices; const Small2 = union(enum) { a: i32, @@ -7,7 +7,7 @@ const Small2 = union(enum) { c: u8, }; test "@tagName" { - try expect(std.mem.eql(u8, @tagName(Small2.a), "a")); + try expectEqualSlices(u8, "a", @tagName(Small2.a)); } // test diff --git a/doc/langref/test_tagged_union.zig b/doc/langref/test_tagged_union.zig index d118d7e6bd..9efc18cc28 100644 --- a/doc/langref/test_tagged_union.zig +++ b/doc/langref/test_tagged_union.zig @@ -1,5 +1,5 @@ const std = @import("std"); -const expect = std.testing.expect; +const expectEqual = std.testing.expectEqual; const ComplexTypeTag = enum { ok, @@ -12,10 +12,10 @@ const ComplexType = union(ComplexTypeTag) { test "switch on tagged union" { const c = ComplexType{ .ok = 42 }; - try expect(@as(ComplexTypeTag, c) == ComplexTypeTag.ok); + try expectEqual(ComplexTypeTag.ok, @as(ComplexTypeTag, c)); switch (c) { - .ok => |value| try expect(value == 42), + .ok => |value| try expectEqual(42, value), .not_ok => unreachable, } @@ -29,7 +29,7 @@ test "switch on tagged union" { } test "get tag type" { - try expect(std.meta.Tag(ComplexType) == ComplexTypeTag); + try expectEqual(ComplexTypeTag, std.meta.Tag(ComplexType)); } // test diff --git a/doc/langref/test_tagged_union_with_tag_values.zig b/doc/langref/test_tagged_union_with_tag_values.zig index c079b5eac3..229a31d678 100644 --- a/doc/langref/test_tagged_union_with_tag_values.zig +++ b/doc/langref/test_tagged_union_with_tag_values.zig @@ -1,5 +1,5 @@ const std = @import("std"); -const expect = std.testing.expect; +const expectEqual = std.testing.expectEqual; const Tagged = union(enum(u32)) { int: i64 = 123, @@ -8,10 +8,10 @@ const Tagged = union(enum(u32)) { test "tag values" { const int: Tagged = .{ .int = -40 }; - try expect(@intFromEnum(int) == 123); + try expectEqual(123, @intFromEnum(int)); const boolean: Tagged = .{ .boolean = false }; - try expect(@intFromEnum(boolean) == 67); + try expectEqual(67, @intFromEnum(boolean)); } // test diff --git a/doc/langref/test_this_builtin.zig b/doc/langref/test_this_builtin.zig index 5cad4e2553..54cad56fdf 100644 --- a/doc/langref/test_this_builtin.zig +++ b/doc/langref/test_this_builtin.zig @@ -1,10 +1,10 @@ const std = @import("std"); -const expect = std.testing.expect; +const expectEqual = std.testing.expectEqual; test "@This()" { var items = [_]i32{ 1, 2, 3, 4 }; const list = List(i32){ .items = items[0..] }; - try expect(list.length() == 4); + try expectEqual(4, list.length()); } fn List(comptime T: type) type { diff --git a/doc/langref/test_truncate_builtin.zig b/doc/langref/test_truncate_builtin.zig index a893db8206..73484fc41e 100644 --- a/doc/langref/test_truncate_builtin.zig +++ b/doc/langref/test_truncate_builtin.zig @@ -1,10 +1,10 @@ const std = @import("std"); -const expect = std.testing.expect; +const expectEqual = std.testing.expectEqual; test "integer truncation" { const a: u16 = 0xabcd; const b: u8 = @truncate(a); - try expect(b == 0xcd); + try expectEqual(0xcd, b); } // test diff --git a/doc/langref/test_tuples.zig b/doc/langref/test_tuples.zig index 54e05e77e7..2d075b324f 100644 --- a/doc/langref/test_tuples.zig +++ b/doc/langref/test_tuples.zig @@ -1,5 +1,6 @@ const std = @import("std"); const expect = std.testing.expect; +const expectEqual = std.testing.expectEqual; test "tuple" { const values = .{ @@ -8,14 +9,14 @@ test "tuple" { true, "hi", } ++ .{false} ** 2; - try expect(values[0] == 1234); - try expect(values[4] == false); + try expectEqual(1234, values[0]); + try expectEqual(false, values[4]); inline for (values, 0..) |v, i| { if (i != 2) continue; try expect(v); } - try expect(values.len == 6); - try expect(values.@"3"[0] == 'h'); + try expectEqual(6, values.len); + try expectEqual('h', values.@"3"[0]); } // test diff --git a/doc/langref/test_variable_alignment.zig b/doc/langref/test_variable_alignment.zig index ea0024f988..01768e29eb 100644 --- a/doc/langref/test_variable_alignment.zig +++ b/doc/langref/test_variable_alignment.zig @@ -1,14 +1,14 @@ const std = @import("std"); const builtin = @import("builtin"); -const expect = std.testing.expect; +const expectEqual = std.testing.expectEqual; test "variable alignment" { var x: i32 = 1234; const align_of_i32 = @alignOf(@TypeOf(x)); - try expect(@TypeOf(&x) == *i32); - try expect(*i32 == *align(align_of_i32) i32); + try expectEqual(*i32, @TypeOf(&x)); + try expectEqual(*align(align_of_i32) i32, *i32); if (builtin.target.cpu.arch == .x86_64) { - try expect(@typeInfo(*i32).pointer.alignment == 4); + try expectEqual(4, @typeInfo(*i32).pointer.alignment); } } diff --git a/doc/langref/test_variable_func_alignment.zig b/doc/langref/test_variable_func_alignment.zig index e0aa949cee..bd97756c45 100644 --- a/doc/langref/test_variable_func_alignment.zig +++ b/doc/langref/test_variable_func_alignment.zig @@ -1,14 +1,14 @@ -const expect = @import("std").testing.expect; +const expectEqual = @import("std").testing.expectEqual; var foo: u8 align(4) = 100; test "global variable alignment" { - try expect(@typeInfo(@TypeOf(&foo)).pointer.alignment == 4); - try expect(@TypeOf(&foo) == *align(4) u8); + try expectEqual(4, @typeInfo(@TypeOf(&foo)).pointer.alignment); + try expectEqual(*align(4) u8, @TypeOf(&foo)); const as_pointer_to_array: *align(4) [1]u8 = &foo; const as_slice: []align(4) u8 = as_pointer_to_array; const as_unaligned_slice: []u8 = as_slice; - try expect(as_unaligned_slice[0] == 100); + try expectEqual(100, as_unaligned_slice[0]); } fn derp() align(@sizeOf(usize) * 2) i32 { @@ -18,17 +18,17 @@ fn noop1() align(1) void {} fn noop4() align(4) void {} test "function alignment" { - try expect(derp() == 1234); - try expect(@TypeOf(derp) == fn () i32); - try expect(@TypeOf(&derp) == *align(@sizeOf(usize) * 2) const fn () i32); + try expectEqual(1234, derp()); + try expectEqual(fn () i32, @TypeOf(derp)); + try expectEqual(*align(@sizeOf(usize) * 2) const fn () i32, @TypeOf(&derp)); noop1(); - try expect(@TypeOf(noop1) == fn () void); - try expect(@TypeOf(&noop1) == *align(1) const fn () void); + try expectEqual(fn () void, @TypeOf(noop1)); + try expectEqual(*align(1) const fn () void, @TypeOf(&noop1)); noop4(); - try expect(@TypeOf(noop4) == fn () void); - try expect(@TypeOf(&noop4) == *align(4) const fn () void); + try expectEqual(fn () void, @TypeOf(noop4)); + try expectEqual(*align(4) const fn () void, @TypeOf(&noop4)); } // test diff --git a/doc/langref/test_variadic_function.zig b/doc/langref/test_variadic_function.zig index e5d9777f64..f1c389b551 100644 --- a/doc/langref/test_variadic_function.zig +++ b/doc/langref/test_variadic_function.zig @@ -4,7 +4,7 @@ const testing = std.testing; pub extern "c" fn printf(format: [*:0]const u8, ...) c_int; test "variadic function" { - try testing.expect(printf("Hello, world!\n") == 14); + try testing.expectEqual(14, printf("Hello, world!\n")); try testing.expect(@typeInfo(@TypeOf(printf)).@"fn".is_var_args); } diff --git a/doc/langref/test_volatile.zig b/doc/langref/test_volatile.zig index 2c33faddf5..b493dd0b94 100644 --- a/doc/langref/test_volatile.zig +++ b/doc/langref/test_volatile.zig @@ -1,8 +1,8 @@ -const expect = @import("std").testing.expect; +const expectEqual = @import("std").testing.expectEqual; test "volatile" { const mmio_ptr: *volatile u8 = @ptrFromInt(0x12345678); - try expect(@TypeOf(mmio_ptr) == *volatile u8); + try expectEqual(*volatile u8, @TypeOf(mmio_ptr)); } // test diff --git a/doc/langref/test_wasmMemoryGrow_builtin.zig b/doc/langref/test_wasmMemoryGrow_builtin.zig index 7f2dc3e149..e18d5d1b75 100644 --- a/doc/langref/test_wasmMemoryGrow_builtin.zig +++ b/doc/langref/test_wasmMemoryGrow_builtin.zig @@ -1,13 +1,13 @@ const std = @import("std"); const native_arch = @import("builtin").target.cpu.arch; -const expect = std.testing.expect; +const expectEqual = std.testing.expectEqual; test "@wasmMemoryGrow" { if (native_arch != .wasm32) return error.SkipZigTest; const prev = @wasmMemorySize(0); - try expect(prev == @wasmMemoryGrow(0, 1)); - try expect(prev + 1 == @wasmMemorySize(0)); + try expectEqual(@wasmMemoryGrow(0, 1), prev); + try expectEqual(@wasmMemorySize(0), prev + 1); } // test diff --git a/doc/langref/test_while.zig b/doc/langref/test_while.zig index 45b27bc716..a9771410e2 100644 --- a/doc/langref/test_while.zig +++ b/doc/langref/test_while.zig @@ -1,11 +1,11 @@ -const expect = @import("std").testing.expect; +const expectEqual = @import("std").testing.expectEqual; test "while basic" { var i: usize = 0; while (i < 10) { i += 1; } - try expect(i == 10); + try expectEqual(10, i); } // test diff --git a/doc/langref/test_while_break.zig b/doc/langref/test_while_break.zig index d30d481548..c433337d9f 100644 --- a/doc/langref/test_while_break.zig +++ b/doc/langref/test_while_break.zig @@ -1,4 +1,4 @@ -const expect = @import("std").testing.expect; +const expectEqual = @import("std").testing.expectEqual; test "while break" { var i: usize = 0; @@ -7,7 +7,7 @@ test "while break" { break; i += 1; } - try expect(i == 10); + try expectEqual(10, i); } // test diff --git a/doc/langref/test_while_continue.zig b/doc/langref/test_while_continue.zig index afe794223a..22f5ba1a75 100644 --- a/doc/langref/test_while_continue.zig +++ b/doc/langref/test_while_continue.zig @@ -1,4 +1,4 @@ -const expect = @import("std").testing.expect; +const expectEqual = @import("std").testing.expectEqual; test "while continue" { var i: usize = 0; @@ -8,7 +8,7 @@ test "while continue" { continue; break; } - try expect(i == 10); + try expectEqual(10, i); } // test diff --git a/doc/langref/test_while_continue_expression.zig b/doc/langref/test_while_continue_expression.zig index 3831f91c05..2ebc7c8345 100644 --- a/doc/langref/test_while_continue_expression.zig +++ b/doc/langref/test_while_continue_expression.zig @@ -1,9 +1,10 @@ +const expectEqual = @import("std").testing.expectEqual; const expect = @import("std").testing.expect; test "while loop continue expression" { var i: usize = 0; while (i < 10) : (i += 1) {} - try expect(i == 10); + try expectEqual(10, i); } test "while loop continue expression, more complicated" { diff --git a/doc/langref/test_while_error_capture.zig b/doc/langref/test_while_error_capture.zig index b687d1a5e7..739db0229e 100644 --- a/doc/langref/test_while_error_capture.zig +++ b/doc/langref/test_while_error_capture.zig @@ -1,4 +1,4 @@ -const expect = @import("std").testing.expect; +const expectEqual = @import("std").testing.expectEqual; test "while error union capture" { var sum1: u32 = 0; @@ -6,7 +6,7 @@ test "while error union capture" { while (eventuallyErrorSequence()) |value| { sum1 += value; } else |err| { - try expect(err == error.ReachedZero); + try expectEqual(error.ReachedZero, err); } } diff --git a/doc/langref/test_while_null_capture.zig b/doc/langref/test_while_null_capture.zig index dd412ffccd..13fc7e062d 100644 --- a/doc/langref/test_while_null_capture.zig +++ b/doc/langref/test_while_null_capture.zig @@ -1,4 +1,4 @@ -const expect = @import("std").testing.expect; +const expectEqual = @import("std").testing.expectEqual; test "while null capture" { var sum1: u32 = 0; @@ -6,7 +6,7 @@ test "while null capture" { while (eventuallyNullSequence()) |value| { sum1 += value; } - try expect(sum1 == 3); + try expectEqual(3, sum1); // null capture with an else block var sum2: u32 = 0; @@ -14,7 +14,7 @@ test "while null capture" { while (eventuallyNullSequence()) |value| { sum2 += value; } else { - try expect(sum2 == 3); + try expectEqual(3, sum2); } // null capture with a continue expression @@ -24,7 +24,7 @@ test "while null capture" { while (eventuallyNullSequence()) |value| : (i += 1) { sum3 += value; } - try expect(i == 3); + try expectEqual(3, i); } var numbers_left: u32 = undefined; diff --git a/doc/langref/test_wraparound_semantics.zig b/doc/langref/test_wraparound_semantics.zig index 491b0907f6..18c3ce44a6 100644 --- a/doc/langref/test_wraparound_semantics.zig +++ b/doc/langref/test_wraparound_semantics.zig @@ -1,14 +1,14 @@ const std = @import("std"); -const expect = std.testing.expect; +const expectEqual = std.testing.expectEqual; const minInt = std.math.minInt; const maxInt = std.math.maxInt; test "wraparound addition and subtraction" { const x: i32 = maxInt(i32); const min_val = x +% 1; - try expect(min_val == minInt(i32)); + try expectEqual(minInt(i32), min_val); const max_val = min_val -% 1; - try expect(max_val == maxInt(i32)); + try expectEqual(maxInt(i32), max_val); } // test diff --git a/doc/langref/testing_detect_leak.zig b/doc/langref/testing_detect_leak.zig index fd72fc9bba..d15e7b6b1c 100644 --- a/doc/langref/testing_detect_leak.zig +++ b/doc/langref/testing_detect_leak.zig @@ -6,7 +6,7 @@ test "detect leak" { // missing `defer list.deinit(gpa);` try list.append(gpa, '☔'); - try std.testing.expect(list.items.len == 1); + try std.testing.expectEqual(1, list.items.len); } // test_error=1 tests leaked memory diff --git a/doc/langref/testing_introduction.zig b/doc/langref/testing_introduction.zig index 6a46c8d688..22bd70a5ad 100644 --- a/doc/langref/testing_introduction.zig +++ b/doc/langref/testing_introduction.zig @@ -7,12 +7,16 @@ test "expect addOne adds one to 41" { // It will return an error if its argument is false to indicate a failure. // `try` is used to return an error to the test runner to notify it that the test failed. try std.testing.expect(addOne(41) == 42); + + // However, in most cases it is more convenient to use a more specific function like `expectEqual`. + // This gives you much clearer and more helpful error messages when a test fails. + try std.testing.expectEqual(42, addOne(41)); } test addOne { // A test name can also be written using an identifier. // This is a doctest, and serves as documentation for `addOne`. - try std.testing.expect(addOne(41) == 42); + try std.testing.expectEqual(42, addOne(41)); } /// The function `addOne` adds one to the number given as its argument.