authorgravatar for armadil@yandex.ruIvan Agafonov <armadil@yandex.ru> 2026-02-11 02:49:11+05:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2026-02-25 19:34:30+01:00
log333055ced72ae73c1ec74a66aa9436291d8b7d1d
tree7a195896c91173a99cd5014d85c372de367b785a
parenta3a9dc111da7a8455f9a476782f291f349d0ed8d

langref: specific expectEqual* functions instead of expect


105 files changed, 422 insertions(+), 410 deletions(-)

doc/langref/error_union_parsing_u64.zig+1-1
......@@ -35,7 +35,7 @@ fn charToDigit(c: u8) u8 {
3535
3636test "parse u64" {
3737 const result = try parseU64("1234", 10);
38 try std.testing.expect(result == 1234);
38 try std.testing.expectEqual(1234, result);
3939}
4040
4141// test
doc/langref/result_location_interfering_with_swap.zig+3-3
......@@ -1,4 +1,4 @@
1const expect = @import("std").testing.expect;
1const expectEqual = @import("std").testing.expectEqual;
22test "attempt to swap array elements with array initializer" {
33 var arr: [2]u32 = .{ 1, 2 };
44 arr = .{ arr[1], arr[0] };
......@@ -6,8 +6,8 @@ test "attempt to swap array elements with array initializer" {
66 // arr[0] = arr[1];
77 // arr[1] = arr[0];
88 // So this fails!
9 try expect(arr[0] == 2); // succeeds
10 try expect(arr[1] == 1); // fails
9 try expectEqual(2, arr[0]); // succeeds
10 try expectEqual(1, arr[1]); // fails
1111}
1212
1313// test_error=
doc/langref/test_TypeOf_builtin.zig+3-3
......@@ -1,11 +1,11 @@
11const std = @import("std");
2const expect = std.testing.expect;
2const expectEqual = std.testing.expectEqual;
33
44test "no runtime side effects" {
55 var data: i32 = 0;
66 const T = @TypeOf(foo(i32, &data));
7 try comptime expect(T == i32);
8 try expect(data == 0);
7 try comptime expectEqual(i32, T);
8 try expectEqual(0, data);
99}
1010
1111fn foo(comptime T: type, ptr: *T) T {
doc/langref/test_allocator.zig+2-2
......@@ -1,13 +1,13 @@
11const std = @import("std");
22const Allocator = std.mem.Allocator;
3const expect = std.testing.expect;
3const expectEqualStrings = std.testing.expectEqualStrings;
44
55test "using an allocator" {
66 var buffer: [100]u8 = undefined;
77 var fba = std.heap.FixedBufferAllocator.init(&buffer);
88 const allocator = fba.allocator();
99 const result = try concat(allocator, "foo", "bar");
10 try expect(std.mem.eql(u8, "foobar", result));
10 try expectEqualStrings("foobar", result);
1111}
1212
1313fn concat(allocator: Allocator, a: []const u8, b: []const u8) ![]u8 {
doc/langref/test_allowzero.zig+2-2
......@@ -1,11 +1,11 @@
11const std = @import("std");
2const expect = std.testing.expect;
2const expectEqual = std.testing.expectEqual;
33
44test "allowzero" {
55 var zero: usize = 0; // var to make to runtime-known
66 _ = &zero; // suppress 'var is never mutated' error
77 const ptr: *allowzero i32 = @ptrFromInt(zero);
8 try expect(@intFromPtr(ptr) == 0);
8 try expectEqual(0, @intFromPtr(ptr));
99}
1010
1111// test
doc/langref/test_anonymous_struct.zig+5-4
......@@ -1,5 +1,6 @@
11const std = @import("std");
22const expect = std.testing.expect;
3const expectEqual = std.testing.expectEqual;
34
45test "fully anonymous struct" {
56 try check(.{
......@@ -11,11 +12,11 @@ test "fully anonymous struct" {
1112}
1213
1314fn check(args: anytype) !void {
14 try expect(args.int == 1234);
15 try expect(args.float == 12.34);
15 try expectEqual(1234, args.int);
16 try expectEqual(12.34, args.float);
1617 try expect(args.b);
17 try expect(args.s[0] == 'h');
18 try expect(args.s[1] == 'i');
18 try expectEqual('h', args.s[0]);
19 try expectEqual('i', args.s[1]);
1920}
2021
2122// test
doc/langref/test_anonymous_union.zig+3-3
......@@ -1,5 +1,5 @@
11const std = @import("std");
2const expect = std.testing.expect;
2const expectEqual = std.testing.expectEqual;
33
44const Number = union {
55 int: i32,
......@@ -9,8 +9,8 @@ const Number = union {
99test "anonymous union literal syntax" {
1010 const i: Number = .{ .int = 42 };
1111 const f = makeNumber();
12 try expect(i.int == 42);
13 try expect(f.float == 12.34);
12 try expectEqual(42, i.int);
13 try expectEqual(12.34, f.float);
1414}
1515
1616fn makeNumber() Number {
doc/langref/test_arrays.zig+9-9
......@@ -1,4 +1,4 @@
1const expect = @import("std").testing.expect;
1const expectEqual = @import("std").testing.expectEqual;
22const assert = @import("std").debug.assert;
33const mem = @import("std").mem;
44
......@@ -29,7 +29,7 @@ test "iterate over an array" {
2929 for (message) |byte| {
3030 sum += byte;
3131 }
32 try expect(sum == 'h' + 'e' + 'l' * 2 + 'o');
32 try expectEqual('h' + 'e' + 'l' * 2 + 'o', sum);
3333}
3434
3535// modifiable array
......@@ -39,8 +39,8 @@ test "modify an array" {
3939 for (&some_integers, 0..) |*item, i| {
4040 item.* = @intCast(i);
4141 }
42 try expect(some_integers[10] == 10);
43 try expect(some_integers[99] == 99);
42 try expectEqual(10, some_integers[10]);
43 try expectEqual(99, some_integers[99]);
4444}
4545
4646// array concatenation works if the values are known
......@@ -91,8 +91,8 @@ const Point = struct {
9191};
9292
9393test "compile-time array initialization" {
94 try expect(fancy_array[4].x == 4);
95 try expect(fancy_array[4].y == 8);
94 try expectEqual(4, fancy_array[4].x);
95 try expectEqual(8, fancy_array[4].y);
9696}
9797
9898// call a function to initialize an array
......@@ -104,9 +104,9 @@ fn makePoint(x: i32) Point {
104104 };
105105}
106106test "array initialization with function calls" {
107 try expect(more_points[4].x == 3);
108 try expect(more_points[4].y == 6);
109 try expect(more_points.len == 10);
107 try expectEqual(3, more_points[4].x);
108 try expectEqual(6, more_points[4].y);
109 try expectEqual(10, more_points.len);
110110}
111111
112112// test
doc/langref/test_basic_slices.zig+11-11
......@@ -1,4 +1,4 @@
1const expect = @import("std").testing.expect;
1const expectEqual = @import("std").testing.expectEqual;
22const expectEqualSlices = @import("std").testing.expectEqualSlices;
33
44test "basic slices" {
......@@ -12,14 +12,14 @@ test "basic slices" {
1212
1313 try expectEqualSlices(i32, slice, alt_slice);
1414
15 try expect(@TypeOf(slice) == []i32);
16 try expect(&slice[0] == &array[0]);
17 try expect(slice.len == array.len);
15 try expectEqual([]i32, @TypeOf(slice));
16 try expectEqual(&array[0], &slice[0]);
17 try expectEqual(array.len, slice.len);
1818
1919 // If you slice with comptime-known start and end positions, the result is
2020 // a pointer to an array, rather than a slice.
2121 const array_ptr = array[0..array.len];
22 try expect(@TypeOf(array_ptr) == *[array.len]i32);
22 try expectEqual(*[array.len]i32, @TypeOf(array_ptr));
2323
2424 // You can perform a slice-by-length by slicing twice. This allows the compiler
2525 // to perform some optimisations like recognising a comptime-known length when
......@@ -28,13 +28,13 @@ test "basic slices" {
2828 _ = &runtime_start;
2929 const length = 2;
3030 const array_ptr_len = array[runtime_start..][0..length];
31 try expect(@TypeOf(array_ptr_len) == *[length]i32);
31 try expectEqual(*[length]i32, @TypeOf(array_ptr_len));
3232
3333 // Using the address-of operator on a slice gives a single-item pointer.
34 try expect(@TypeOf(&slice[0]) == *i32);
34 try expectEqual(*i32, @TypeOf(&slice[0]));
3535 // Using the `ptr` field gives a many-item pointer.
36 try expect(@TypeOf(slice.ptr) == [*]i32);
37 try expect(@intFromPtr(slice.ptr) == @intFromPtr(&slice[0]));
36 try expectEqual([*]i32, @TypeOf(slice.ptr));
37 try expectEqual(@intFromPtr(slice.ptr), @intFromPtr(&slice[0]));
3838
3939 // Slices have array bounds checking. If you try to access something out
4040 // of bounds, you'll get a safety check failure:
......@@ -47,8 +47,8 @@ test "basic slices" {
4747 const empty1 = &[0]u8{};
4848 // If the type is known you can use this short hand:
4949 const empty2: []u8 = &.{};
50 try expect(empty1.len == 0);
51 try expect(empty2.len == 0);
50 try expectEqual(0, empty1.len);
51 try expectEqual(0, empty2.len);
5252
5353 // A zero-length initialization can always be used to create an empty slice, even if the slice is mutable.
5454 // This is because the pointed-to data is zero bits long, so its immutability is irrelevant.
doc/langref/test_bitOffsetOf_offsetOf.zig+7-7
......@@ -1,5 +1,5 @@
11const std = @import("std");
2const expect = std.testing.expect;
2const expectEqual = std.testing.expectEqual;
33
44const BitField = packed struct {
55 a: u3,
......@@ -9,13 +9,13 @@ const BitField = packed struct {
99
1010test "offsets of non-byte-aligned fields" {
1111 comptime {
12 try expect(@bitOffsetOf(BitField, "a") == 0);
13 try expect(@bitOffsetOf(BitField, "b") == 3);
14 try expect(@bitOffsetOf(BitField, "c") == 6);
12 try expectEqual(0, @bitOffsetOf(BitField, "a"));
13 try expectEqual(3, @bitOffsetOf(BitField, "b"));
14 try expectEqual(6, @bitOffsetOf(BitField, "c"));
1515
16 try expect(@offsetOf(BitField, "a") == 0);
17 try expect(@offsetOf(BitField, "b") == 0);
18 try expect(@offsetOf(BitField, "c") == 0);
16 try expectEqual(0, @offsetOf(BitField, "a"));
17 try expectEqual(0, @offsetOf(BitField, "b"));
18 try expectEqual(0, @offsetOf(BitField, "c"));
1919 }
2020}
2121
doc/langref/test_call_builtin.zig+2-2
......@@ -1,7 +1,7 @@
1const expect = @import("std").testing.expect;
1const expectEqual = @import("std").testing.expectEqual;
22
33test "noinline function call" {
4 try expect(@call(.auto, add, .{ 3, 9 }) == 12);
4 try expectEqual(12, @call(.auto, add, .{ 3, 9 }));
55}
66
77fn add(a: i32, b: i32) i32 {
doc/langref/test_coerce_error_subset_to_superset.zig+1-1
......@@ -12,7 +12,7 @@ const AllocationError = error{
1212
1313test "coerce subset to superset" {
1414 const err = foo(AllocationError.OutOfMemory);
15 try std.testing.expect(err == FileOpenError.OutOfMemory);
15 try std.testing.expectEqual(FileOpenError.OutOfMemory, err);
1616}
1717
1818fn foo(err: AllocationError) FileOpenError {
doc/langref/test_coerce_large_to_small.zig+2-2
......@@ -1,10 +1,10 @@
11const std = @import("std");
2const expect = std.testing.expect;
2const expectEqual = std.testing.expectEqual;
33
44test "coercing large integer type to smaller one when value is comptime-known to fit" {
55 const x: u64 = 255;
66 const y: u8 = x;
7 try expect(y == 255);
7 try expectEqual(255, y);
88}
99
1010// test
doc/langref/test_coerce_optional_wrapped_error_union.zig+3-3
......@@ -1,12 +1,12 @@
11const std = @import("std");
2const expect = std.testing.expect;
2const expectEqual = std.testing.expectEqual;
33
44test "coerce to optionals wrapped in error union" {
55 const x: anyerror!?i32 = 1234;
66 const y: anyerror!?i32 = null;
77
8 try expect((try x).? == 1234);
9 try expect((try y) == null);
8 try expectEqual(1234, (try x).?);
9 try expectEqual(null, (try y));
1010}
1111
1212// test
doc/langref/test_coerce_optionals.zig+3-3
......@@ -1,12 +1,12 @@
11const std = @import("std");
2const expect = std.testing.expect;
2const expectEqual = std.testing.expectEqual;
33
44test "coerce to optionals" {
55 const x: ?i32 = 1234;
66 const y: ?i32 = null;
77
8 try expect(x.? == 1234);
9 try expect(y == null);
8 try expectEqual(1234, x.?);
9 try expectEqual(null, y);
1010}
1111
1212// test
doc/langref/test_coerce_slices_arrays_and_pointers.zig+15-13
......@@ -1,5 +1,7 @@
11const std = @import("std");
2const expect = std.testing.expect;
2const expectEqual = std.testing.expectEqual;
3const expectEqualStrings = std.testing.expectEqualStrings;
4const expectEqualSlices = std.testing.expectEqualSlices;
35
46// You can assign constant pointers to arrays to a slice with
57// const modifier on the element type. Useful in particular for
......@@ -7,48 +9,48 @@ const expect = std.testing.expect;
79test "*const [N]T to []const T" {
810 const x1: []const u8 = "hello";
911 const x2: []const u8 = &[5]u8{ 'h', 'e', 'l', 'l', 111 };
10 try expect(std.mem.eql(u8, x1, x2));
12 try expectEqualStrings(x1, x2);
1113
1214 const y: []const f32 = &[2]f32{ 1.2, 3.4 };
13 try expect(y[0] == 1.2);
15 try expectEqual(1.2, y[0]);
1416}
1517
1618// Likewise, it works when the destination type is an error union.
1719test "*const [N]T to E![]const T" {
1820 const x1: anyerror![]const u8 = "hello";
1921 const x2: anyerror![]const u8 = &[5]u8{ 'h', 'e', 'l', 'l', 111 };
20 try expect(std.mem.eql(u8, try x1, try x2));
22 try expectEqualStrings(try x1, try x2);
2123
2224 const y: anyerror![]const f32 = &[2]f32{ 1.2, 3.4 };
23 try expect((try y)[0] == 1.2);
25 try expectEqual(1.2, (try y)[0]);
2426}
2527
2628// Likewise, it works when the destination type is an optional.
2729test "*const [N]T to ?[]const T" {
2830 const x1: ?[]const u8 = "hello";
2931 const x2: ?[]const u8 = &[5]u8{ 'h', 'e', 'l', 'l', 111 };
30 try expect(std.mem.eql(u8, x1.?, x2.?));
32 try expectEqualStrings(x1.?, x2.?);
3133
3234 const y: ?[]const f32 = &[2]f32{ 1.2, 3.4 };
33 try expect(y.?[0] == 1.2);
35 try expectEqual(1.2, y.?[0]);
3436}
3537
3638// In this cast, the array length becomes the slice length.
3739test "*[N]T to []T" {
3840 var buf: [5]u8 = "hello".*;
3941 const x: []u8 = &buf;
40 try expect(std.mem.eql(u8, x, "hello"));
42 try expectEqualStrings("hello", x);
4143
4244 const buf2 = [2]f32{ 1.2, 3.4 };
4345 const x2: []const f32 = &buf2;
44 try expect(std.mem.eql(f32, x2, &[2]f32{ 1.2, 3.4 }));
46 try expectEqualSlices(f32, &[2]f32{ 1.2, 3.4 }, x2);
4547}
4648
4749// Single-item pointers to arrays can be coerced to many-item pointers.
4850test "*[N]T to [*]T" {
4951 var buf: [5]u8 = "hello".*;
5052 const x: [*]u8 = &buf;
51 try expect(x[4] == 'o');
53 try expectEqual('o', x[4]);
5254 // x[5] would be an uncaught out of bounds pointer dereference!
5355}
5456
......@@ -56,7 +58,7 @@ test "*[N]T to [*]T" {
5658test "*[N]T to ?[*]T" {
5759 var buf: [5]u8 = "hello".*;
5860 const x: ?[*]u8 = &buf;
59 try expect(x.?[4] == 'o');
61 try expectEqual('o', x.?[4]);
6062}
6163
6264// Single-item pointers can be cast to len-1 single-item arrays.
......@@ -64,14 +66,14 @@ test "*T to *[1]T" {
6466 var x: i32 = 1234;
6567 const y: *[1]i32 = &x;
6668 const z: [*]i32 = y;
67 try expect(z[0] == 1234);
69 try expectEqual(1234, z[0]);
6870}
6971
7072// Sentinel-terminated slices can be coerced into sentinel-terminated pointers
7173test "[:x]T to [*:x]T" {
7274 const buf: [:0]const u8 = "hello";
7375 const buf2: [*:0]const u8 = buf;
74 try expect(buf2[4] == 'o');
76 try expectEqual('o', buf2[4]);
7577}
7678
7779// test
doc/langref/test_coerce_to_error_union.zig+2-2
......@@ -1,11 +1,11 @@
11const std = @import("std");
2const expect = std.testing.expect;
2const expectEqual = std.testing.expectEqual;
33
44test "coercion to error unions" {
55 const x: anyerror!i32 = 1234;
66 const y: anyerror!i32 = error.Failure;
77
8 try expect((try x) == 1234);
8 try expectEqual(1234, (try x));
99 try std.testing.expectError(error.Failure, y);
1010}
1111
doc/langref/test_coerce_tuples_arrays.zig+1-1
......@@ -1,5 +1,5 @@
11const std = @import("std");
2const expect = std.testing.expect;
2const expectEqual = std.testing.expectEqual;
33
44const Tuple = struct { u8, u8 };
55test "coercion from homogeneous tuple to array" {
doc/langref/test_coerce_unions_enums.zig+6-6
......@@ -1,5 +1,5 @@
11const std = @import("std");
2const expect = std.testing.expect;
2const expectEqual = std.testing.expectEqual;
33
44const E = enum {
55 one,
......@@ -28,22 +28,22 @@ const U2 = union(enum) {
2828test "coercion between unions and enums" {
2929 const u = U{ .two = 12.34 };
3030 const e: E = u; // coerce union to enum
31 try expect(e == E.two);
31 try expectEqual(E.two, e);
3232
3333 const three = E.three;
3434 const u_2: U = three; // coerce enum to union
35 try expect(u_2 == E.three);
35 try expectEqual(E.three, u_2);
3636
3737 const u_3: U = .three; // coerce enum literal to union
38 try expect(u_3 == E.three);
38 try expectEqual(E.three, u_3);
3939
4040 const u_4: U2 = .a; // coerce enum literal to union with inferred enum tag type.
41 try expect(u_4.tag() == 1);
41 try expectEqual(1, u_4.tag());
4242
4343 // The following example is invalid.
4444 // error: coercion from enum '@EnumLiteral()' to union 'test_coerce_unions_enum.U2' must initialize 'f32' field 'b'
4545 //var u_5: U2 = .b;
46 //try expect(u_5.tag() == 2);
46 //try expectEqual(2, u_5.tag());
4747}
4848
4949// test
doc/langref/test_comptime_evaluation.zig+4-4
......@@ -1,4 +1,4 @@
1const expect = @import("std").testing.expect;
1const expectEqual = @import("std").testing.expectEqual;
22
33const CmdFn = struct {
44 name: []const u8,
......@@ -32,9 +32,9 @@ fn performFn(comptime prefix_char: u8, start_value: i32) i32 {
3232}
3333
3434test "perform fn" {
35 try expect(performFn('t', 1) == 6);
36 try expect(performFn('o', 0) == 1);
37 try expect(performFn('w', 99) == 99);
35 try expectEqual(6, performFn('t', 1));
36 try expectEqual(1, performFn('o', 0));
37 try expectEqual(99, performFn('w', 99));
3838}
3939
4040// test
doc/langref/test_comptime_max_with_bool.zig+1-1
......@@ -8,7 +8,7 @@ fn max(comptime T: type, a: T, b: T) T {
88 }
99}
1010test "try to compare bools" {
11 try @import("std").testing.expect(max(bool, false, true) == true);
11 try @import("std").testing.expectEqual(true, max(bool, false, true));
1212}
1313
1414// test
doc/langref/test_comptime_pointer_conversion.zig+3-3
......@@ -1,4 +1,4 @@
1const expect = @import("std").testing.expect;
1const expectEqual = @import("std").testing.expectEqual;
22
33test "comptime @ptrFromInt" {
44 comptime {
......@@ -6,8 +6,8 @@ test "comptime @ptrFromInt" {
66 // ptr is never dereferenced.
77 const ptr: *i32 = @ptrFromInt(0xdeadbee0);
88 const addr = @intFromPtr(ptr);
9 try expect(@TypeOf(addr) == usize);
10 try expect(addr == 0xdeadbee0);
9 try expectEqual(usize, @TypeOf(addr));
10 try expectEqual(0xdeadbee0, addr);
1111 }
1212}
1313
doc/langref/test_comptime_pointers.zig+2-2
......@@ -1,4 +1,4 @@
1const expect = @import("std").testing.expect;
1const expectEqual = @import("std").testing.expectEqual;
22
33test "comptime pointers" {
44 comptime {
......@@ -6,7 +6,7 @@ test "comptime pointers" {
66 const ptr = &x;
77 ptr.* += 1;
88 x += 1;
9 try expect(ptr.* == 3);
9 try expectEqual(3, ptr.*);
1010 }
1111}
1212
doc/langref/test_comptime_variables.zig+3-3
......@@ -1,5 +1,5 @@
11const std = @import("std");
2const expect = std.testing.expect;
2const expectEqual = std.testing.expectEqual;
33
44test "comptime vars" {
55 var x: i32 = 1;
......@@ -8,8 +8,8 @@ test "comptime vars" {
88 x += 1;
99 y += 1;
1010
11 try expect(x == 2);
12 try expect(y == 2);
11 try expectEqual(2, x);
12 try expectEqual(2, y);
1313
1414 if (y != 2) {
1515 // This compile error never triggers because y is a comptime variable,
doc/langref/test_container-level_comptime_expressions.zig+1-1
......@@ -31,7 +31,7 @@ fn sum(numbers: []const i32) i32 {
3131}
3232
3333test "variable values" {
34 try @import("std").testing.expect(sum_of_first_25_primes == 1060);
34 try @import("std").testing.expectEqual(1060, sum_of_first_25_primes);
3535}
3636
3737// test
doc/langref/test_container_level_variables.zig+3-3
......@@ -2,8 +2,8 @@ var y: i32 = add(10, x);
22const x: i32 = add(12, 34);
33
44test "container level variables" {
5 try expect(x == 46);
6 try expect(y == 56);
5 try expectEqual(46, x);
6 try expectEqual(56, y);
77}
88
99fn add(a: i32, b: i32) i32 {
......@@ -11,6 +11,6 @@ fn add(a: i32, b: i32) i32 {
1111}
1212
1313const std = @import("std");
14const expect = std.testing.expect;
14const expectEqual = std.testing.expectEqual;
1515
1616// test
doc/langref/test_defer.zig+3-3
......@@ -1,5 +1,5 @@
11const std = @import("std");
2const expect = std.testing.expect;
2const expectEqual = std.testing.expectEqual;
33const print = std.debug.print;
44
55fn deferExample() !usize {
......@@ -9,14 +9,14 @@ fn deferExample() !usize {
99 defer a = 2;
1010 a = 1;
1111 }
12 try expect(a == 2);
12 try expectEqual(2, a);
1313
1414 a = 5;
1515 return a;
1616}
1717
1818test "defer basics" {
19 try expect((try deferExample()) == 5);
19 try expectEqual(5, (try deferExample()));
2020}
2121
2222// test
doc/langref/test_empty_block.zig+4-4
......@@ -1,12 +1,12 @@
11const std = @import("std");
2const expect = std.testing.expect;
2const expectEqual = std.testing.expectEqual;
33
44test {
55 const a = {};
66 const b = void{};
7 try expect(@TypeOf(a) == void);
8 try expect(@TypeOf(b) == void);
9 try expect(a == b);
7 try expectEqual(void, @TypeOf(a));
8 try expectEqual(void, @TypeOf(b));
9 try expectEqual(a, b);
1010}
1111
1212// test
doc/langref/test_enum_literals.zig+2-1
......@@ -1,5 +1,6 @@
11const std = @import("std");
22const expect = std.testing.expect;
3const expectEqual = std.testing.expectEqual;
34
45const Color = enum {
56 auto,
......@@ -10,7 +11,7 @@ const Color = enum {
1011test "enum literals" {
1112 const color1: Color = .auto;
1213 const color2 = Color.auto;
13 try expect(color1 == color2);
14 try expectEqual(color1, color2);
1415}
1516
1617test "switch using enum literals" {
doc/langref/test_enums.zig+18-16
......@@ -1,4 +1,6 @@
11const expect = @import("std").testing.expect;
2const expectEqual = @import("std").testing.expectEqual;
3const expectEqualStrings = @import("std").testing.expectEqualStrings;
24const mem = @import("std").mem;
35
46// Declare an enum.
......@@ -20,9 +22,9 @@ const Value = enum(u2) {
2022// Now you can cast between u2 and Value.
2123// The ordinal value starts from 0, counting up by 1 from the previous member.
2224test "enum ordinal value" {
23 try expect(@intFromEnum(Value.zero) == 0);
24 try expect(@intFromEnum(Value.one) == 1);
25 try expect(@intFromEnum(Value.two) == 2);
25 try expectEqual(0, @intFromEnum(Value.zero));
26 try expectEqual(1, @intFromEnum(Value.one));
27 try expectEqual(2, @intFromEnum(Value.two));
2628}
2729
2830// You can override the ordinal value for an enum.
......@@ -32,9 +34,9 @@ const Value2 = enum(u32) {
3234 million = 1000000,
3335};
3436test "set enum ordinal value" {
35 try expect(@intFromEnum(Value2.hundred) == 100);
36 try expect(@intFromEnum(Value2.thousand) == 1000);
37 try expect(@intFromEnum(Value2.million) == 1000000);
37 try expectEqual(100, @intFromEnum(Value2.hundred));
38 try expectEqual(1000, @intFromEnum(Value2.thousand));
39 try expectEqual(1000000, @intFromEnum(Value2.million));
3840}
3941
4042// You can also override only some values.
......@@ -46,11 +48,11 @@ const Value3 = enum(u4) {
4648 e,
4749};
4850test "enum implicit ordinal values and overridden values" {
49 try expect(@intFromEnum(Value3.a) == 0);
50 try expect(@intFromEnum(Value3.b) == 8);
51 try expect(@intFromEnum(Value3.c) == 9);
52 try expect(@intFromEnum(Value3.d) == 4);
53 try expect(@intFromEnum(Value3.e) == 5);
51 try expectEqual(0, @intFromEnum(Value3.a));
52 try expectEqual(8, @intFromEnum(Value3.b));
53 try expectEqual(9, @intFromEnum(Value3.c));
54 try expectEqual(4, @intFromEnum(Value3.d));
55 try expectEqual(5, @intFromEnum(Value3.e));
5456}
5557
5658// Enums can have methods, the same as structs and unions.
......@@ -84,7 +86,7 @@ test "enum switch" {
8486 Foo.number => "this is a number",
8587 Foo.none => "this is a none",
8688 };
87 try expect(mem.eql(u8, what_is_it, "this is a number"));
89 try expectEqualStrings(what_is_it, "this is a number");
8890}
8991
9092// @typeInfo can be used to access the integer tag type of an enum.
......@@ -95,18 +97,18 @@ const Small = enum {
9597 four,
9698};
9799test "std.meta.Tag" {
98 try expect(@typeInfo(Small).@"enum".tag_type == u2);
100 try expectEqual(u2, @typeInfo(Small).@"enum".tag_type);
99101}
100102
101103// @typeInfo tells us the field count and the fields names:
102104test "@typeInfo" {
103 try expect(@typeInfo(Small).@"enum".fields.len == 4);
104 try expect(mem.eql(u8, @typeInfo(Small).@"enum".fields[1].name, "two"));
105 try expectEqual(4, @typeInfo(Small).@"enum".fields.len);
106 try expectEqualStrings(@typeInfo(Small).@"enum".fields[1].name, "two");
105107}
106108
107109// @tagName gives a [:0]const u8 representation of an enum value:
108110test "@tagName" {
109 try expect(mem.eql(u8, @tagName(Small.three), "three"));
111 try expectEqualStrings(@tagName(Small.three), "three");
110112}
111113
112114// test
doc/langref/test_error_union.zig+3-3
......@@ -1,4 +1,4 @@
1const expect = @import("std").testing.expect;
1const expectEqual = @import("std").testing.expectEqual;
22
33test "error union" {
44 var foo: anyerror!i32 = undefined;
......@@ -10,10 +10,10 @@ test "error union" {
1010 foo = error.SomeError;
1111
1212 // Use compile-time reflection to access the payload type of an error union:
13 try comptime expect(@typeInfo(@TypeOf(foo)).error_union.payload == i32);
13 try comptime expectEqual(i32, @typeInfo(@TypeOf(foo)).error_union.payload);
1414
1515 // Use compile-time reflection to access the error set type of an error union:
16 try comptime expect(@typeInfo(@TypeOf(foo)).error_union.error_set == anyerror);
16 try comptime expectEqual(anyerror, @typeInfo(@TypeOf(foo)).error_union.error_set);
1717}
1818
1919// test
doc/langref/test_fibonacci_comptime_overflow.zig+2-2
......@@ -1,4 +1,4 @@
1const expect = @import("std").testing.expect;
1const expectEqual = @import("std").testing.expectEqual;
22
33fn fibonacci(index: u32) u32 {
44 //if (index < 2) return index;
......@@ -6,7 +6,7 @@ fn fibonacci(index: u32) u32 {
66}
77
88test "fibonacci" {
9 try comptime expect(fibonacci(7) == 13);
9 try comptime expectEqual(13, fibonacci(7));
1010}
1111
1212// test_error=overflow of integer type
doc/langref/test_fibonacci_recursion.zig+3-3
......@@ -1,4 +1,4 @@
1const expect = @import("std").testing.expect;
1const expectEqual = @import("std").testing.expectEqual;
22
33fn fibonacci(index: u32) u32 {
44 if (index < 2) return index;
......@@ -7,10 +7,10 @@ fn fibonacci(index: u32) u32 {
77
88test "fibonacci" {
99 // test fibonacci at run-time
10 try expect(fibonacci(7) == 13);
10 try expectEqual(13, fibonacci(7));
1111
1212 // test fibonacci at compile-time
13 try comptime expect(fibonacci(7) == 13);
13 try comptime expectEqual(13, fibonacci(7));
1414}
1515
1616// test
doc/langref/test_field_builtin.zig+5-7
......@@ -1,4 +1,5 @@
11const std = @import("std");
2const expectEqual = std.testing.expectEqual;
23
34const Point = struct {
45 x: u32,
......@@ -8,23 +9,20 @@ const Point = struct {
89};
910
1011test "field access by string" {
11 const expect = std.testing.expect;
1212 var p = Point{ .x = 0, .y = 0 };
1313
1414 @field(p, "x") = 4;
1515 @field(p, "y") = @field(p, "x") + 1;
1616
17 try expect(@field(p, "x") == 4);
18 try expect(@field(p, "y") == 5);
17 try expectEqual(4, @field(p, "x"));
18 try expectEqual(5, @field(p, "y"));
1919}
2020
2121test "decl access by string" {
22 const expect = std.testing.expect;
23
24 try expect(@field(Point, "z") == 1);
22 try expectEqual(1, @field(Point, "z"));
2523
2624 @field(Point, "z") = 2;
27 try expect(@field(Point, "z") == 2);
25 try expectEqual(2, @field(Point, "z"));
2826}
2927
3028// test
doc/langref/test_fn_reflection.zig+2-2
......@@ -3,8 +3,8 @@ const math = std.math;
33const testing = std.testing;
44
55test "fn reflection" {
6 try testing.expect(@typeInfo(@TypeOf(testing.expect)).@"fn".params[0].type.? == bool);
7 try testing.expect(@typeInfo(@TypeOf(testing.tmpDir)).@"fn".return_type.? == testing.TmpDir);
6 try testing.expectEqual(bool, @typeInfo(@TypeOf(testing.expect)).@"fn".params[0].type.?);
7 try testing.expectEqual(testing.TmpDir, @typeInfo(@TypeOf(testing.tmpDir)).@"fn".return_type.?);
88
99 try testing.expect(@typeInfo(@TypeOf(math.Log2Int)).@"fn".is_generic);
1010}
doc/langref/test_fn_type_inference.zig+5-5
......@@ -1,15 +1,15 @@
1const expect = @import("std").testing.expect;
1const expectEqual = @import("std").testing.expectEqual;
22
33fn addFortyTwo(x: anytype) @TypeOf(x) {
44 return x + 42;
55}
66
77test "fn type inference" {
8 try expect(addFortyTwo(1) == 43);
9 try expect(@TypeOf(addFortyTwo(1)) == comptime_int);
8 try expectEqual(43, addFortyTwo(1));
9 try expectEqual(comptime_int, @TypeOf(addFortyTwo(1)));
1010 const y: i64 = 2;
11 try expect(addFortyTwo(y) == 44);
12 try expect(@TypeOf(addFortyTwo(y)) == i64);
11 try expectEqual(44, addFortyTwo(y));
12 try expectEqual(i64, @TypeOf(addFortyTwo(y)));
1313}
1414
1515// test
doc/langref/test_for.zig+12-12
......@@ -1,4 +1,4 @@
1const expect = @import("std").testing.expect;
1const expectEqual = @import("std").testing.expectEqual;
22
33test "for basics" {
44 const items = [_]i32{ 4, 5, 3, 4, 0 };
......@@ -12,22 +12,22 @@ test "for basics" {
1212 }
1313 sum += value;
1414 }
15 try expect(sum == 16);
15 try expectEqual(16, sum);
1616
1717 // To iterate over a portion of a slice, reslice.
1818 for (items[0..1]) |value| {
1919 sum += value;
2020 }
21 try expect(sum == 20);
21 try expectEqual(20, sum);
2222
2323 // To access the index of iteration, specify a second condition as well
2424 // as a second capture value.
2525 var sum2: i32 = 0;
2626 for (items, 0..) |_, i| {
27 try expect(@TypeOf(i) == usize);
27 try expectEqual(usize, @TypeOf(i));
2828 sum2 += @as(i32, @intCast(i));
2929 }
30 try expect(sum2 == 10);
30 try expectEqual(10, sum2);
3131
3232 // To iterate over consecutive integers, use the range syntax.
3333 // Unbounded range is always a compile error.
......@@ -35,7 +35,7 @@ test "for basics" {
3535 for (0..5) |i| {
3636 sum3 += i;
3737 }
38 try expect(sum3 == 10);
38 try expectEqual(10, sum3);
3939}
4040
4141test "multi object for" {
......@@ -50,7 +50,7 @@ test "multi object for" {
5050 count += i + j;
5151 }
5252
53 try expect(count == 21);
53 try expectEqual(21, count);
5454}
5555
5656test "for reference" {
......@@ -62,9 +62,9 @@ test "for reference" {
6262 value.* += 1;
6363 }
6464
65 try expect(items[0] == 4);
66 try expect(items[1] == 5);
67 try expect(items[2] == 3);
65 try expectEqual(4, items[0]);
66 try expectEqual(5, items[1]);
67 try expectEqual(3, items[2]);
6868}
6969
7070test "for else" {
......@@ -79,10 +79,10 @@ test "for else" {
7979 sum += value.?;
8080 }
8181 } else blk: {
82 try expect(sum == 12);
82 try expectEqual(12, sum);
8383 break :blk sum;
8484 };
85 try expect(result == 12);
85 try expectEqual(12, result);
8686}
8787
8888// test
doc/langref/test_for_nested_break.zig+3-3
......@@ -1,5 +1,5 @@
11const std = @import("std");
2const expect = std.testing.expect;
2const expectEqual = std.testing.expectEqual;
33
44test "nested break" {
55 var count: usize = 0;
......@@ -9,7 +9,7 @@ test "nested break" {
99 break :outer;
1010 }
1111 }
12 try expect(count == 1);
12 try expectEqual(1, count);
1313}
1414
1515test "nested continue" {
......@@ -21,7 +21,7 @@ test "nested continue" {
2121 }
2222 }
2323
24 try expect(count == 8);
24 try expectEqual(8, count);
2525}
2626
2727// test
doc/langref/test_functions.zig+3-3
......@@ -1,7 +1,7 @@
11const std = @import("std");
22const builtin = @import("builtin");
33const native_arch = builtin.cpu.arch;
4const expect = std.testing.expect;
4const expectEqual = std.testing.expectEqual;
55
66// Functions are declared like this
77fn add(a: i8, b: i8) i8 {
......@@ -57,8 +57,8 @@ fn doOp(fnCall: Call2Op, op1: i8, op2: i8) i8 {
5757}
5858
5959test "function" {
60 try expect(doOp(add, 5, 6) == 11);
61 try expect(doOp(sub2, 5, 6) == -1);
60 try expectEqual(11, doOp(add, 5, 6));
61 try expectEqual(-1, doOp(sub2, 5, 6));
6262}
6363
6464// test
doc/langref/test_global_assembly.zig+2-2
......@@ -1,5 +1,5 @@
11const std = @import("std");
2const expect = std.testing.expect;
2const expectEqual = std.testing.expectEqual;
33
44comptime {
55 asm (
......@@ -14,7 +14,7 @@ comptime {
1414extern fn my_func(a: i32, b: i32) i32;
1515
1616test "global assembly" {
17 try expect(my_func(12, 34) == 46);
17 try expectEqual(46, my_func(12, 34));
1818}
1919
2020// test
doc/langref/test_if.zig+7-6
......@@ -4,13 +4,14 @@
44// * anyerror!T
55
66const expect = @import("std").testing.expect;
7const expectEqual = @import("std").testing.expectEqual;
78
89test "if expression" {
910 // If expressions are used instead of a ternary expression.
1011 const a: u32 = 5;
1112 const b: u32 = 4;
1213 const result = if (a != b) 47 else 3089;
13 try expect(result == 47);
14 try expectEqual(result, 47);
1415}
1516
1617test "if boolean" {
......@@ -32,7 +33,7 @@ test "if error union" {
3233
3334 const a: anyerror!u32 = 0;
3435 if (a) |value| {
35 try expect(value == 0);
36 try expectEqual(value, 0);
3637 } else |err| {
3738 _ = err;
3839 unreachable;
......@@ -43,17 +44,17 @@ test "if error union" {
4344 _ = value;
4445 unreachable;
4546 } else |err| {
46 try expect(err == error.BadValue);
47 try expectEqual(err, error.BadValue);
4748 }
4849
4950 // The else and |err| capture is strictly required.
5051 if (a) |value| {
51 try expect(value == 0);
52 try expectEqual(value, 0);
5253 } else |_| {}
5354
5455 // To check only the error value, use an empty block expression.
5556 if (b) |_| {} else |err| {
56 try expect(err == error.BadValue);
57 try expectEqual(err, error.BadValue);
5758 }
5859
5960 // Access the value by reference using a pointer capture.
......@@ -65,7 +66,7 @@ test "if error union" {
6566 }
6667
6768 if (c) |value| {
68 try expect(value == 9);
69 try expectEqual(value, 9);
6970 } else |_| {
7071 unreachable;
7172 }
doc/langref/test_if_optionals.zig+8-7
......@@ -1,11 +1,12 @@
11const expect = @import("std").testing.expect;
2const expectEqual = @import("std").testing.expectEqual;
23
34test "if optional" {
45 // If expressions test for null.
56
67 const a: ?u32 = 0;
78 if (a) |value| {
8 try expect(value == 0);
9 try expectEqual(0, value);
910 } else {
1011 unreachable;
1112 }
......@@ -19,7 +20,7 @@ test "if optional" {
1920
2021 // The else is not required.
2122 if (a) |value| {
22 try expect(value == 0);
23 try expectEqual(0, value);
2324 }
2425
2526 // To test against null only, use the binary equality operator.
......@@ -34,7 +35,7 @@ test "if optional" {
3435 }
3536
3637 if (c) |value| {
37 try expect(value == 2);
38 try expectEqual(2, value);
3839 } else {
3940 unreachable;
4041 }
......@@ -46,7 +47,7 @@ test "if error union with optional" {
4647
4748 const a: anyerror!?u32 = 0;
4849 if (a) |optional_value| {
49 try expect(optional_value.? == 0);
50 try expectEqual(0, optional_value.?);
5051 } else |err| {
5152 _ = err;
5253 unreachable;
......@@ -54,7 +55,7 @@ test "if error union with optional" {
5455
5556 const b: anyerror!?u32 = null;
5657 if (b) |optional_value| {
57 try expect(optional_value == null);
58 try expectEqual(null, optional_value);
5859 } else |_| {
5960 unreachable;
6061 }
......@@ -64,7 +65,7 @@ test "if error union with optional" {
6465 _ = optional_value;
6566 unreachable;
6667 } else |err| {
67 try expect(err == error.BadValue);
68 try expectEqual(error.BadValue, err);
6869 }
6970
7071 // Access the value by reference by using a pointer capture each time.
......@@ -78,7 +79,7 @@ test "if error union with optional" {
7879 }
7980
8081 if (d) |optional_value| {
81 try expect(optional_value.? == 9);
82 try expectEqual(9, optional_value.?);
8283 } else |_| {
8384 unreachable;
8485 }
doc/langref/test_incorrect_pointer_alignment.zig+1-1
......@@ -3,7 +3,7 @@ const std = @import("std");
33test "pointer alignment safety" {
44 var array align(4) = [_]u32{ 0x11111111, 0x11111111 };
55 const bytes = std.mem.sliceAsBytes(array[0..]);
6 try std.testing.expect(foo(bytes) == 0x11111111);
6 try std.testing.expectEqual(0x11111111, foo(bytes));
77}
88fn foo(bytes: []u8) u32 {
99 const slice4 = bytes[1..5];
doc/langref/test_inline_else.zig+3-3
......@@ -1,5 +1,5 @@
11const std = @import("std");
2const expect = std.testing.expect;
2const expectEqual = std.testing.expectEqual;
33
44const SliceTypeA = extern struct {
55 len: usize,
......@@ -42,8 +42,8 @@ fn withSwitch(any: AnySlice) usize {
4242
4343test "inline for and inline else similarity" {
4444 const any = AnySlice{ .c = "hello" };
45 try expect(withFor(any) == 5);
46 try expect(withSwitch(any) == 5);
45 try expectEqual(5, withFor(any));
46 try expectEqual(5, withSwitch(any));
4747}
4848
4949// test
doc/langref/test_inline_for.zig+2-2
......@@ -1,4 +1,4 @@
1const expect = @import("std").testing.expect;
1const expectEqual = @import("std").testing.expectEqual;
22
33test "inline for loop" {
44 const nums = [_]i32{ 2, 4, 6 };
......@@ -12,7 +12,7 @@ test "inline for loop" {
1212 };
1313 sum += typeNameLength(T);
1414 }
15 try expect(sum == 9);
15 try expectEqual(9, sum);
1616}
1717
1818fn typeNameLength(comptime T: type) usize {
doc/langref/test_inline_switch_union_tag.zig+2-2
......@@ -1,5 +1,5 @@
11const std = @import("std");
2const expect = std.testing.expect;
2const expectEqual = std.testing.expectEqual;
33
44const U = union(enum) {
55 a: u32,
......@@ -21,7 +21,7 @@ fn getNum(u: U) u32 {
2121
2222test "test" {
2323 const u = U{ .b = 42 };
24 try expect(getNum(u) == 42);
24 try expectEqual(42, getNum(u));
2525}
2626
2727// test
doc/langref/test_inline_while.zig+2-2
......@@ -1,4 +1,4 @@
1const expect = @import("std").testing.expect;
1const expectEqual = @import("std").testing.expectEqual;
22
33test "inline while loop" {
44 comptime var i = 0;
......@@ -12,7 +12,7 @@ test "inline while loop" {
1212 };
1313 sum += typeNameLength(T);
1414 }
15 try expect(sum == 9);
15 try expectEqual(9, sum);
1616}
1717
1818fn typeNameLength(comptime T: type) usize {
doc/langref/test_integer_pointer_conversion.zig+3-3
......@@ -1,10 +1,10 @@
1const expect = @import("std").testing.expect;
1const expectEqual = @import("std").testing.expectEqual;
22
33test "@intFromPtr and @ptrFromInt" {
44 const ptr: *i32 = @ptrFromInt(0xdeadbee0);
55 const addr = @intFromPtr(ptr);
6 try expect(@TypeOf(addr) == usize);
7 try expect(addr == 0xdeadbee0);
6 try expectEqual(usize, @TypeOf(addr));
7 try expectEqual(0xdeadbee0, addr);
88}
99
1010// test
doc/langref/test_integer_widening.zig+4-4
......@@ -1,6 +1,6 @@
11const std = @import("std");
22const builtin = @import("builtin");
3const expect = std.testing.expect;
3const expectEqual = std.testing.expectEqual;
44const mem = std.mem;
55
66test "integer widening" {
......@@ -10,13 +10,13 @@ test "integer widening" {
1010 const d: u64 = c;
1111 const e: u64 = d;
1212 const f: u128 = e;
13 try expect(f == a);
13 try expectEqual(f, a);
1414}
1515
1616test "implicit unsigned integer to signed integer" {
1717 const a: u8 = 250;
1818 const b: i16 = a;
19 try expect(b == 250);
19 try expectEqual(250, b);
2020}
2121
2222test "float widening" {
......@@ -24,7 +24,7 @@ test "float widening" {
2424 const b: f32 = a;
2525 const c: f64 = b;
2626 const d: f128 = c;
27 try expect(d == a);
27 try expectEqual(d, a);
2828}
2929
3030// test
doc/langref/test_labeled_break.zig+3-3
......@@ -1,5 +1,5 @@
11const std = @import("std");
2const expect = std.testing.expect;
2const expectEqual = std.testing.expectEqual;
33
44test "labeled break from labeled block expression" {
55 var y: i32 = 123;
......@@ -8,8 +8,8 @@ test "labeled break from labeled block expression" {
88 y += 1;
99 break :blk y;
1010 };
11 try expect(x == 124);
12 try expect(y == 124);
11 try expectEqual(124, x);
12 try expectEqual(124, y);
1313}
1414
1515// test
doc/langref/test_misaligned_pointer.zig+2-2
......@@ -1,5 +1,5 @@
11const std = @import("std");
2const expect = std.testing.expect;
2const expectEqual = std.testing.expectEqual;
33
44const BitField = packed struct {
55 a: u3,
......@@ -14,7 +14,7 @@ var bit_field = BitField{
1414};
1515
1616test "pointer to non-byte-aligned field" {
17 try expect(bar(&bit_field.b) == 2);
17 try expectEqual(2, bar(&bit_field.b));
1818}
1919
2020fn bar(x: *const u3) u3 {
doc/langref/test_multidimensional_arrays.zig+3-4
......@@ -1,5 +1,4 @@
11const std = @import("std");
2const expect = std.testing.expect;
32const expectEqual = std.testing.expectEqual;
43
54const mat4x5 = [4][5]f32{
......@@ -13,20 +12,20 @@ test "multidimensional arrays" {
1312 try expectEqual(mat4x5[1], [_]f32{ 0.0, 1.0, 0.0, 1.0, 0.0 });
1413
1514 // Access the 2D array by indexing the outer array, and then the inner array.
16 try expect(mat4x5[3][4] == 9.9);
15 try expectEqual(9.9, mat4x5[3][4]);
1716
1817 // Here we iterate with for loops.
1918 for (mat4x5, 0..) |row, row_index| {
2019 for (row, 0..) |cell, column_index| {
2120 if (row_index == column_index) {
22 try expect(cell == 1.0);
21 try expectEqual(1.0, cell);
2322 }
2423 }
2524 }
2625
2726 // Initialize a multidimensional array to zeros.
2827 const all_zero: [4][5]f32 = .{.{0} ** 5} ** 4;
29 try expect(all_zero[0][0] == 0);
28 try expectEqual(0, all_zero[0][0]);
3029}
3130
3231// test
doc/langref/test_namespaced_container_level_variable.zig+3-3
......@@ -1,9 +1,9 @@
11const std = @import("std");
2const expect = std.testing.expect;
2const expectEqual = std.testing.expectEqual;
33
44test "namespaced container level variable" {
5 try expect(foo() == 1235);
6 try expect(foo() == 1236);
5 try expectEqual(1235, foo());
6 try expectEqual(1236, foo());
77}
88
99const S = struct {
doc/langref/test_noreturn_from_exit.zig+2-2
......@@ -1,14 +1,14 @@
11const std = @import("std");
22const builtin = @import("builtin");
33const native_arch = builtin.cpu.arch;
4const expect = std.testing.expect;
4const expectEqual = std.testing.expectEqual;
55
66const WINAPI: std.builtin.CallingConvention = if (native_arch == .x86) .{ .x86_stdcall = .{} } else .c;
77extern "kernel32" fn ExitProcess(exit_code: c_uint) callconv(WINAPI) noreturn;
88
99test "foo" {
1010 const value = bar() catch ExitProcess(1);
11 try expect(value == 1234);
11 try expectEqual(1234, value);
1212}
1313
1414fn bar() anyerror!u32 {
doc/langref/test_null_terminated_array.zig+7-7
......@@ -1,21 +1,21 @@
11const std = @import("std");
2const expect = std.testing.expect;
2const expectEqual = std.testing.expectEqual;
33
44test "0-terminated sentinel array" {
55 const array = [_:0]u8{ 1, 2, 3, 4 };
66
7 try expect(@TypeOf(array) == [4:0]u8);
8 try expect(array.len == 4);
9 try expect(array[4] == 0);
7 try expectEqual([4:0]u8, @TypeOf(array));
8 try expectEqual(4, array.len);
9 try expectEqual(0, array[4]);
1010}
1111
1212test "extra 0s in 0-terminated sentinel array" {
1313 // The sentinel value may appear earlier, but does not influence the compile-time 'len'.
1414 const array = [_:0]u8{ 1, 0, 0, 4 };
1515
16 try expect(@TypeOf(array) == [4:0]u8);
17 try expect(array.len == 4);
18 try expect(array[4] == 0);
16 try expectEqual([4:0]u8, @TypeOf(array));
17 try expectEqual(4, array.len);
18 try expectEqual(0, array[4]);
1919}
2020
2121// test
doc/langref/test_null_terminated_slice.zig+3-3
......@@ -1,11 +1,11 @@
11const std = @import("std");
2const expect = std.testing.expect;
2const expectEqual = std.testing.expectEqual;
33
44test "0-terminated slice" {
55 const slice: [:0]const u8 = "hello";
66
7 try expect(slice.len == 5);
8 try expect(slice[5] == 0);
7 try expectEqual(5, slice.len);
8 try expectEqual(0, slice[5]);
99}
1010
1111// test
doc/langref/test_null_terminated_slicing.zig+3-3
......@@ -1,5 +1,5 @@
11const std = @import("std");
2const expect = std.testing.expect;
2const expectEqual = std.testing.expectEqual;
33
44test "0-terminated slicing" {
55 var array = [_]u8{ 3, 2, 1, 0, 3, 2, 1, 0 };
......@@ -7,8 +7,8 @@ test "0-terminated slicing" {
77 _ = &runtime_length;
88 const slice = array[0..runtime_length :0];
99
10 try expect(@TypeOf(slice) == [:0]u8);
11 try expect(slice.len == 3);
10 try expectEqual([:0]u8, @TypeOf(slice));
11 try expectEqual(3, slice.len);
1212}
1313
1414// test
doc/langref/test_optional_pointer.zig+3-3
......@@ -1,4 +1,4 @@
1const expect = @import("std").testing.expect;
1const expectEqual = @import("std").testing.expectEqual;
22
33test "optional pointers" {
44 // Pointers cannot be null. If you want a null pointer, use the optional
......@@ -8,11 +8,11 @@ test "optional pointers" {
88 var x: i32 = 1;
99 ptr = &x;
1010
11 try expect(ptr.?.* == 1);
11 try expectEqual(1, ptr.?.*);
1212
1313 // Optional pointers are the same size as normal pointers, because pointer
1414 // value 0 is used as the null value.
15 try expect(@sizeOf(?*i32) == @sizeOf(*i32));
15 try expectEqual(@sizeOf(?*i32), @sizeOf(*i32));
1616}
1717
1818// test
doc/langref/test_optional_type.zig+2-2
......@@ -1,4 +1,4 @@
1const expect = @import("std").testing.expect;
1const expectEqual = @import("std").testing.expectEqual;
22
33test "optional type" {
44 // Declare an optional and coerce from null:
......@@ -8,7 +8,7 @@ test "optional type" {
88 foo = 1234;
99
1010 // Use compile-time reflection to access the child type of the optional:
11 try comptime expect(@typeInfo(@TypeOf(foo)).optional.child == i32);
11 try comptime expectEqual(i32, @typeInfo(@TypeOf(foo)).optional.child);
1212}
1313
1414// test
doc/langref/test_overaligned_packed_struct.zig+2-2
......@@ -1,5 +1,5 @@
11const std = @import("std");
2const expect = std.testing.expect;
2const expectEqual = std.testing.expectEqual;
33
44const S = packed struct {
55 a: u32,
......@@ -9,7 +9,7 @@ test "overaligned pointer to packed struct" {
99 var foo: S align(4) = .{ .a = 1, .b = 2 };
1010 const ptr: *align(4) S = &foo;
1111 const ptr_to_b = &ptr.b;
12 try expect(ptr_to_b.* == 2);
12 try expectEqual(2, ptr_to_b.*);
1313}
1414
1515// test
doc/langref/test_packed_struct_equality.zig+2-2
......@@ -1,5 +1,5 @@
11const std = @import("std");
2const expect = std.testing.expect;
2const expectEqual = std.testing.expectEqual;
33
44test "packed struct equality" {
55 const S = packed struct {
......@@ -8,7 +8,7 @@ test "packed struct equality" {
88 };
99 const x: S = .{ .a = 1, .b = 2 };
1010 const y: S = .{ .b = 2, .a = 1 };
11 try expect(x == y);
11 try expectEqual(x, y);
1212}
1313
1414// test
doc/langref/test_packed_struct_field_address.zig+3-3
......@@ -1,5 +1,5 @@
11const std = @import("std");
2const expect = std.testing.expect;
2const expectEqual = std.testing.expectEqual;
33
44const BitField = packed struct {
55 a: u3,
......@@ -14,8 +14,8 @@ var bit_field = BitField{
1414};
1515
1616test "pointers of sub-byte-aligned fields share addresses" {
17 try expect(@intFromPtr(&bit_field.a) == @intFromPtr(&bit_field.b));
18 try expect(@intFromPtr(&bit_field.a) == @intFromPtr(&bit_field.c));
17 try expectEqual(@intFromPtr(&bit_field.a), @intFromPtr(&bit_field.b));
18 try expectEqual(@intFromPtr(&bit_field.a), @intFromPtr(&bit_field.c));
1919}
2020
2121// test
doc/langref/test_packed_structs.zig+10-10
......@@ -1,6 +1,6 @@
11const std = @import("std");
22const native_endian = @import("builtin").target.cpu.arch.endian();
3const expect = std.testing.expect;
3const expectEqual = std.testing.expectEqual;
44
55const Full = packed struct {
66 number: u16,
......@@ -17,23 +17,23 @@ test "@bitCast between packed structs" {
1717}
1818
1919fn doTheTest() !void {
20 try expect(@sizeOf(Full) == 2);
21 try expect(@sizeOf(Divided) == 2);
20 try expectEqual(2, @sizeOf(Full));
21 try expectEqual(2, @sizeOf(Divided));
2222 const full = Full{ .number = 0x1234 };
2323 const divided: Divided = @bitCast(full);
24 try expect(divided.half1 == 0x34);
25 try expect(divided.quarter3 == 0x2);
26 try expect(divided.quarter4 == 0x1);
24 try expectEqual(0x34, divided.half1);
25 try expectEqual(0x2, divided.quarter3);
26 try expectEqual(0x1, divided.quarter4);
2727
2828 const ordered: [2]u8 = @bitCast(full);
2929 switch (native_endian) {
3030 .big => {
31 try expect(ordered[0] == 0x12);
32 try expect(ordered[1] == 0x34);
31 try expectEqual(0x12, ordered[0]);
32 try expectEqual(0x34, ordered[1]);
3333 },
3434 .little => {
35 try expect(ordered[0] == 0x34);
36 try expect(ordered[1] == 0x12);
35 try expectEqual(0x34, ordered[0]);
36 try expectEqual(0x12, ordered[1]);
3737 },
3838 }
3939}
doc/langref/test_pass_by_reference_or_value.zig+2-2
......@@ -11,10 +11,10 @@ fn foo(point: Point) i32 {
1111 return point.x + point.y;
1212}
1313
14const expect = @import("std").testing.expect;
14const expectEqual = @import("std").testing.expectEqual;
1515
1616test "pass struct to function" {
17 try expect(foo(Point{ .x = 1, .y = 2 }) == 3);
17 try expectEqual(3, foo(Point{ .x = 1, .y = 2 }));
1818}
1919
2020// test
doc/langref/test_peer_type_resolution.zig+26-26
......@@ -1,20 +1,20 @@
11const std = @import("std");
2const expect = std.testing.expect;
3const mem = std.mem;
2const expectEqual = std.testing.expectEqual;
3const expectEqualStrings = std.testing.expectEqualStrings;
44
55test "peer resolve int widening" {
66 const a: i8 = 12;
77 const b: i16 = 34;
88 const c = a + b;
9 try expect(c == 46);
10 try expect(@TypeOf(c) == i16);
9 try expectEqual(46, c);
10 try expectEqual(i16, @TypeOf(c));
1111}
1212
1313test "peer resolve arrays of different size to const slice" {
14 try expect(mem.eql(u8, boolToStr(true), "true"));
15 try expect(mem.eql(u8, boolToStr(false), "false"));
16 try comptime expect(mem.eql(u8, boolToStr(true), "true"));
17 try comptime expect(mem.eql(u8, boolToStr(false), "false"));
14 try expectEqualStrings("true", boolToStr(true));
15 try expectEqualStrings("false", boolToStr(false));
16 try comptime expectEqualStrings("true", boolToStr(true));
17 try comptime expectEqualStrings("false", boolToStr(false));
1818}
1919fn boolToStr(b: bool) []const u8 {
2020 return if (b) "true" else "false";
......@@ -27,16 +27,16 @@ test "peer resolve array and const slice" {
2727fn testPeerResolveArrayConstSlice(b: bool) !void {
2828 const value1 = if (b) "aoeu" else @as([]const u8, "zz");
2929 const value2 = if (b) @as([]const u8, "zz") else "aoeu";
30 try expect(mem.eql(u8, value1, "aoeu"));
31 try expect(mem.eql(u8, value2, "zz"));
30 try expectEqualStrings("aoeu", value1);
31 try expectEqualStrings("zz", value2);
3232}
3333
3434test "peer type resolution: ?T and T" {
35 try expect(peerTypeTAndOptionalT(true, false).? == 0);
36 try expect(peerTypeTAndOptionalT(false, false).? == 3);
35 try expectEqual(0, peerTypeTAndOptionalT(true, false).?);
36 try expectEqual(3, peerTypeTAndOptionalT(false, false).?);
3737 comptime {
38 try expect(peerTypeTAndOptionalT(true, false).? == 0);
39 try expect(peerTypeTAndOptionalT(false, false).? == 3);
38 try expectEqual(0, peerTypeTAndOptionalT(true, false).?);
39 try expectEqual(3, peerTypeTAndOptionalT(false, false).?);
4040 }
4141}
4242fn peerTypeTAndOptionalT(c: bool, b: bool) ?usize {
......@@ -48,11 +48,11 @@ fn peerTypeTAndOptionalT(c: bool, b: bool) ?usize {
4848}
4949
5050test "peer type resolution: *[0]u8 and []const u8" {
51 try expect(peerTypeEmptyArrayAndSlice(true, "hi").len == 0);
52 try expect(peerTypeEmptyArrayAndSlice(false, "hi").len == 1);
51 try expectEqual(0, peerTypeEmptyArrayAndSlice(true, "hi").len);
52 try expectEqual(1, peerTypeEmptyArrayAndSlice(false, "hi").len);
5353 comptime {
54 try expect(peerTypeEmptyArrayAndSlice(true, "hi").len == 0);
55 try expect(peerTypeEmptyArrayAndSlice(false, "hi").len == 1);
54 try expectEqual(0, peerTypeEmptyArrayAndSlice(true, "hi").len);
55 try expectEqual(1, peerTypeEmptyArrayAndSlice(false, "hi").len);
5656 }
5757}
5858fn peerTypeEmptyArrayAndSlice(a: bool, slice: []const u8) []const u8 {
......@@ -66,14 +66,14 @@ test "peer type resolution: *[0]u8, []const u8, and anyerror![]u8" {
6666 {
6767 var data = "hi".*;
6868 const slice = data[0..];
69 try expect((try peerTypeEmptyArrayAndSliceAndError(true, slice)).len == 0);
70 try expect((try peerTypeEmptyArrayAndSliceAndError(false, slice)).len == 1);
69 try expectEqual(0, (try peerTypeEmptyArrayAndSliceAndError(true, slice)).len);
70 try expectEqual(1, (try peerTypeEmptyArrayAndSliceAndError(false, slice)).len);
7171 }
7272 comptime {
7373 var data = "hi".*;
7474 const slice = data[0..];
75 try expect((try peerTypeEmptyArrayAndSliceAndError(true, slice)).len == 0);
76 try expect((try peerTypeEmptyArrayAndSliceAndError(false, slice)).len == 1);
75 try expectEqual(0, (try peerTypeEmptyArrayAndSliceAndError(true, slice)).len);
76 try expectEqual(1, (try peerTypeEmptyArrayAndSliceAndError(false, slice)).len);
7777 }
7878}
7979fn peerTypeEmptyArrayAndSliceAndError(a: bool, slice: []u8) anyerror![]u8 {
......@@ -87,8 +87,8 @@ fn peerTypeEmptyArrayAndSliceAndError(a: bool, slice: []u8) anyerror![]u8 {
8787test "peer type resolution: *const T and ?*T" {
8888 const a: *const usize = @ptrFromInt(0x123456780);
8989 const b: ?*usize = @ptrFromInt(0x123456780);
90 try expect(a == b);
91 try expect(b == a);
90 try expectEqual(a, b);
91 try expectEqual(b, a);
9292}
9393
9494test "peer type resolution: error union switch" {
......@@ -104,7 +104,7 @@ test "peer type resolution: error union switch" {
104104 error.B => 1,
105105 error.C => null,
106106 };
107 try expect(@TypeOf(b) == ?u32);
107 try expectEqual(?u32, @TypeOf(b));
108108
109109 // The non-error and error cases are only peers if the error case is just a switch expression;
110110 // 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" {
114114 error.B => 1,
115115 error.C => null,
116116 };
117 try expect(@TypeOf(c) == ?u32);
117 try expectEqual(?u32, @TypeOf(c));
118118}
119119
120120// test
doc/langref/test_pointer_arithmetic.zig+9-9
......@@ -1,19 +1,19 @@
1const expect = @import("std").testing.expect;
1const expectEqual = @import("std").testing.expectEqual;
22
33test "pointer arithmetic with many-item pointer" {
44 const array = [_]i32{ 1, 2, 3, 4 };
55 var ptr: [*]const i32 = &array;
66
7 try expect(ptr[0] == 1);
7 try expectEqual(1, ptr[0]);
88 ptr += 1;
9 try expect(ptr[0] == 2);
9 try expectEqual(2, ptr[0]);
1010
1111 // slicing a many-item pointer without an end is equivalent to
1212 // pointer arithmetic: `ptr[start..] == ptr + start`
13 try expect(ptr[1..] == ptr + 1);
13 try expectEqual(ptr[1..], ptr + 1);
1414
1515 // subtraction between any two pointers except slices based on element size is supported
16 try expect(&ptr[1] - &ptr[0] == 1);
16 try expectEqual(1, &ptr[1] - &ptr[0]);
1717}
1818
1919test "pointer arithmetic with slices" {
......@@ -22,14 +22,14 @@ test "pointer arithmetic with slices" {
2222 _ = &length; // suppress 'var is never mutated' error
2323 var slice = array[length..array.len];
2424
25 try expect(slice[0] == 1);
26 try expect(slice.len == 4);
25 try expectEqual(1, slice[0]);
26 try expectEqual(4, slice.len);
2727
2828 slice.ptr += 1;
2929 // now the slice is in an bad state since len has not been updated
3030
31 try expect(slice[0] == 2);
32 try expect(slice.len == 4);
31 try expectEqual(2, slice[0]);
32 try expectEqual(4, slice.len);
3333}
3434
3535// test
doc/langref/test_pointer_casting.zig+5-5
......@@ -1,23 +1,23 @@
11const std = @import("std");
2const expect = std.testing.expect;
2const expectEqual = std.testing.expectEqual;
33
44test "pointer casting" {
55 const bytes align(@alignOf(u32)) = [_]u8{ 0x12, 0x12, 0x12, 0x12 };
66 const u32_ptr: *const u32 = @ptrCast(&bytes);
7 try expect(u32_ptr.* == 0x12121212);
7 try expectEqual(0x12121212, u32_ptr.*);
88
99 // Even this example is contrived - there are better ways to do the above than
1010 // pointer casting. For example, using a slice narrowing cast:
1111 const u32_value = std.mem.bytesAsSlice(u32, bytes[0..])[0];
12 try expect(u32_value == 0x12121212);
12 try expectEqual(0x12121212, u32_value);
1313
1414 // And even another way, the most straightforward way to do it:
15 try expect(@as(u32, @bitCast(bytes)) == 0x12121212);
15 try expectEqual(0x12121212, @as(u32, @bitCast(bytes)));
1616}
1717
1818test "pointer child type" {
1919 // pointer types have a `child` field which tells you the type they point to.
20 try expect(@typeInfo(*u32).pointer.child == u32);
20 try expectEqual(u32, @typeInfo(*u32).pointer.child);
2121}
2222
2323// test
doc/langref/test_pointer_coerce_const_optional.zig+2-2
......@@ -1,11 +1,11 @@
11const std = @import("std");
2const expect = std.testing.expect;
2const expectEqualStrings = std.testing.expectEqualStrings;
33const mem = std.mem;
44
55test "cast *[1][*:0]const u8 to []const ?[*:0]const u8" {
66 const window_name = [1][*:0]const u8{"window name"};
77 const x: []const ?[*:0]const u8 = &window_name;
8 try expect(mem.eql(u8, mem.span(x[0].?), "window name"));
8 try expectEqualStrings("window name", mem.span(x[0].?));
99}
1010
1111// test
doc/langref/test_pointer_to_non-byte_aligned_field.zig+2-2
......@@ -1,5 +1,5 @@
11const std = @import("std");
2const expect = std.testing.expect;
2const expectEqual = std.testing.expectEqual;
33
44const BitField = packed struct {
55 a: u3,
......@@ -15,7 +15,7 @@ var foo = BitField{
1515
1616test "pointer to non-byte-aligned field" {
1717 const ptr = &foo.b;
18 try expect(ptr.* == 2);
18 try expectEqual(2, ptr.*);
1919}
2020
2121// test
doc/langref/test_reduce_builtin.zig+4-4
......@@ -1,15 +1,15 @@
11const std = @import("std");
2const expect = std.testing.expect;
2const expectEqual = std.testing.expectEqual;
33
44test "vector @reduce" {
55 const V = @Vector(4, i32);
66 const value = V{ 1, -1, 1, -1 };
77 const result = value > @as(V, @splat(0));
88 // result is { true, false, true, false };
9 try comptime expect(@TypeOf(result) == @Vector(4, bool));
9 try comptime expectEqual(@Vector(4, bool), @TypeOf(result));
1010 const is_all_true = @reduce(.And, result);
11 try comptime expect(@TypeOf(is_all_true) == bool);
12 try expect(is_all_true == false);
11 try comptime expectEqual(bool, @TypeOf(is_all_true));
12 try expectEqual(false, is_all_true);
1313}
1414
1515// test
doc/langref/test_round_builtin.zig+5-5
......@@ -1,10 +1,10 @@
1const expect = @import("std").testing.expect;
1const expectEqual = @import("std").testing.expectEqual;
22
33test "@round" {
4 try expect(@round(1.4) == 1);
5 try expect(@round(1.5) == 2);
6 try expect(@round(-1.4) == -1);
7 try expect(@round(-2.5) == -3);
4 try expectEqual(1, @round(1.4));
5 try expectEqual(2, @round(1.5));
6 try expectEqual(-1, @round(-1.4));
7 try expectEqual(-3, @round(-2.5));
88}
99
1010// test
doc/langref/test_sentinel_mismatch.zig+1-1
......@@ -1,5 +1,5 @@
11const std = @import("std");
2const expect = std.testing.expect;
2const expectEqual = std.testing.expectEqual;
33
44test "sentinel mismatch" {
55 var array = [_]u8{ 3, 2, 1, 0 };
doc/langref/test_shuffle_builtin.zig+3-3
......@@ -1,5 +1,5 @@
11const std = @import("std");
2const expect = std.testing.expect;
2const expectEqualStrings = std.testing.expectEqualStrings;
33
44test "vector @shuffle" {
55 const a = @Vector(7, u8){ 'o', 'l', 'h', 'e', 'r', 'z', 'w' };
......@@ -9,12 +9,12 @@ test "vector @shuffle" {
99 // Notice that we can re-order, duplicate, or omit elements of the input vector
1010 const mask1 = @Vector(5, i32){ 2, 3, 1, 1, 0 };
1111 const res1: @Vector(5, u8) = @shuffle(u8, a, undefined, mask1);
12 try expect(std.mem.eql(u8, &@as([5]u8, res1), "hello"));
12 try expectEqualStrings("hello", &@as([5]u8, res1));
1313
1414 // Combining two vectors
1515 const mask2 = @Vector(6, i32){ -1, 0, 4, 1, -2, -3 };
1616 const res2: @Vector(6, u8) = @shuffle(u8, a, b, mask2);
17 try expect(std.mem.eql(u8, &@as([6]u8, res2), "world!"));
17 try expectEqualStrings("world!", &@as([6]u8, res2));
1818}
1919
2020// test
doc/langref/test_simple_union.zig+3-3
......@@ -1,5 +1,5 @@
11const std = @import("std");
2const expect = std.testing.expect;
2const expectEqual = std.testing.expectEqual;
33
44const Payload = union {
55 int: i64,
......@@ -8,9 +8,9 @@ const Payload = union {
88};
99test "simple union" {
1010 var payload = Payload{ .int = 1234 };
11 try expect(payload.int == 1234);
11 try expectEqual(1234, payload.int);
1212 payload = Payload{ .float = 12.34 };
13 try expect(payload.float == 12.34);
13 try expectEqual(12.34, payload.float);
1414}
1515
1616// test
doc/langref/test_single_item_pointer.zig+10-10
......@@ -1,4 +1,4 @@
1const expect = @import("std").testing.expect;
1const expectEqual = @import("std").testing.expectEqual;
22
33test "address of syntax" {
44 // Get the address of a variable:
......@@ -6,17 +6,17 @@ test "address of syntax" {
66 const x_ptr = &x;
77
88 // Dereference a pointer:
9 try expect(x_ptr.* == 1234);
9 try expectEqual(1234, x_ptr.*);
1010
1111 // When you get the address of a const variable, you get a const single-item pointer.
12 try expect(@TypeOf(x_ptr) == *const i32);
12 try expectEqual(*const i32, @TypeOf(x_ptr));
1313
1414 // If you want to mutate the value, you'd need an address of a mutable variable:
1515 var y: i32 = 5678;
1616 const y_ptr = &y;
17 try expect(@TypeOf(y_ptr) == *i32);
17 try expectEqual(*i32, @TypeOf(y_ptr));
1818 y_ptr.* += 1;
19 try expect(y_ptr.* == 5679);
19 try expectEqual(5679, y_ptr.*);
2020}
2121
2222test "pointer array access" {
......@@ -25,11 +25,11 @@ test "pointer array access" {
2525 // does not support pointer arithmetic.
2626 var array = [_]u8{ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
2727 const ptr = &array[2];
28 try expect(@TypeOf(ptr) == *u8);
28 try expectEqual(*u8, @TypeOf(ptr));
2929
30 try expect(array[2] == 3);
30 try expectEqual(3, array[2]);
3131 ptr.* += 1;
32 try expect(array[2] == 4);
32 try expectEqual(4, array[2]);
3333}
3434
3535test "slice syntax" {
......@@ -39,11 +39,11 @@ test "slice syntax" {
3939
4040 // Convert to array pointer using slice syntax:
4141 const x_array_ptr = x_ptr[0..1];
42 try expect(@TypeOf(x_array_ptr) == *[1]i32);
42 try expectEqual(*[1]i32, @TypeOf(x_array_ptr));
4343
4444 // Coerce to many-item pointer:
4545 const x_many_ptr: [*]i32 = x_array_ptr;
46 try expect(x_many_ptr[0] == 1234);
46 try expectEqual(1234, x_many_ptr[0]);
4747}
4848
4949// test
doc/langref/test_slice_bounds.zig+4-4
......@@ -1,15 +1,15 @@
1const expect = @import("std").testing.expect;
1const expectEqual = @import("std").testing.expectEqual;
22
33test "pointer slicing" {
44 var array = [_]u8{ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
55 var start: usize = 2; // var to make it runtime-known
66 _ = &start; // suppress 'var is never mutated' error
77 const slice = array[start..4];
8 try expect(slice.len == 2);
8 try expectEqual(2, slice.len);
99
10 try expect(array[3] == 4);
10 try expectEqual(4, array[3]);
1111 slice[1] += 1;
12 try expect(array[3] == 5);
12 try expectEqual(5, array[3]);
1313}
1414
1515// test
doc/langref/test_slices.zig+9-9
......@@ -1,6 +1,6 @@
11const std = @import("std");
2const expect = std.testing.expect;
3const mem = std.mem;
2const expectEqual = std.testing.expectEqual;
3const expectEqualStrings = std.testing.expectEqualStrings;
44const fmt = std.fmt;
55
66test "using slices for strings" {
......@@ -23,13 +23,13 @@ test "using slices for strings" {
2323 // Generally, you can use UTF-8 and not worry about whether something is a
2424 // string. If you don't need to deal with individual characters, no need
2525 // to decode.
26 try expect(mem.eql(u8, hello_world, "hello 世界"));
26 try expectEqualStrings("hello 世界", hello_world);
2727}
2828
2929test "slice pointer" {
3030 var array: [10]u8 = undefined;
3131 const ptr = &array;
32 try expect(@TypeOf(ptr) == *[10]u8);
32 try expectEqual(*[10]u8, @TypeOf(ptr));
3333
3434 // A pointer to an array can be sliced just like an array:
3535 var start: usize = 0;
......@@ -37,16 +37,16 @@ test "slice pointer" {
3737 _ = .{ &start, &end };
3838 const slice = ptr[start..end];
3939 // The slice is mutable because we sliced a mutable pointer.
40 try expect(@TypeOf(slice) == []u8);
40 try expectEqual([]u8, @TypeOf(slice));
4141 slice[2] = 3;
42 try expect(array[2] == 3);
42 try expectEqual(3, array[2]);
4343
4444 // Again, slicing with comptime-known indexes will produce another pointer
4545 // to an array:
4646 const ptr2 = slice[2..3];
47 try expect(ptr2.len == 1);
48 try expect(ptr2[0] == 3);
49 try expect(@TypeOf(ptr2) == *[1]u8);
47 try expectEqual(1, ptr2.len);
48 try expectEqual(3, ptr2[0]);
49 try expectEqual(*[1]u8, @TypeOf(ptr2));
5050}
5151
5252// test
doc/langref/test_splat_builtin.zig+3-3
......@@ -1,16 +1,16 @@
11const std = @import("std");
2const expect = std.testing.expect;
2const expectEqualSlices = std.testing.expectEqualSlices;
33
44test "vector @splat" {
55 const scalar: u32 = 5;
66 const result: @Vector(4, u32) = @splat(scalar);
7 try expect(std.mem.eql(u32, &@as([4]u32, result), &[_]u32{ 5, 5, 5, 5 }));
7 try expectEqualSlices(u32, &[_]u32{ 5, 5, 5, 5 }, &@as([4]u32, result));
88}
99
1010test "array @splat" {
1111 const scalar: u32 = 5;
1212 const result: [4]u32 = @splat(scalar);
13 try expect(std.mem.eql(u32, &@as([4]u32, result), &[_]u32{ 5, 5, 5, 5 }));
13 try expectEqualSlices(u32, &[_]u32{ 5, 5, 5, 5 }, &@as([4]u32, result));
1414}
1515
1616// test
doc/langref/test_src_builtin.zig+3-2
......@@ -1,5 +1,6 @@
11const std = @import("std");
22const expect = std.testing.expect;
3const expectEqual = std.testing.expectEqual;
34
45test "@src" {
56 try doTheTest();
......@@ -8,8 +9,8 @@ test "@src" {
89fn doTheTest() !void {
910 const src = @src();
1011
11 try expect(src.line == 9);
12 try expect(src.column == 17);
12 try expectEqual(10, src.line);
13 try expectEqual(17, src.column);
1314 try expect(std.mem.endsWith(u8, src.fn_name, "doTheTest"));
1415 try expect(std.mem.endsWith(u8, src.file, "test_src_builtin.zig"));
1516}
doc/langref/test_static_local_variable.zig+3-3
......@@ -1,9 +1,9 @@
11const std = @import("std");
2const expect = std.testing.expect;
2const expectEqual = std.testing.expectEqual;
33
44test "static local variable" {
5 try expect(foo() == 1235);
6 try expect(foo() == 1236);
5 try expectEqual(1235, foo());
6 try expectEqual(1236, foo());
77}
88
99fn foo() i32 {
doc/langref/test_struct_result.zig+3-3
......@@ -1,5 +1,5 @@
11const std = @import("std");
2const expect = std.testing.expect;
2const expectEqual = std.testing.expectEqual;
33
44const Point = struct { x: i32, y: i32 };
55
......@@ -8,8 +8,8 @@ test "anonymous struct literal" {
88 .x = 13,
99 .y = 67,
1010 };
11 try expect(pt.x == 13);
12 try expect(pt.y == 67);
11 try expectEqual(13, pt.x);
12 try expectEqual(67, pt.y);
1313}
1414
1515// test
doc/langref/test_structs.zig+11-11
......@@ -34,12 +34,12 @@ const Vec3 = struct {
3434test "dot product" {
3535 const v1 = Vec3.init(1.0, 0.0, 0.0);
3636 const v2 = Vec3.init(0.0, 1.0, 0.0);
37 try expect(v1.dot(v2) == 0.0);
37 try expectEqual(0.0, v1.dot(v2));
3838
3939 // Other than being available to call with dot syntax, struct methods are
4040 // not special. You can reference them as any other declaration inside
4141 // the struct:
42 try expect(Vec3.dot(v1, v2) == 0.0);
42 try expectEqual(0.0, Vec3.dot(v1, v2));
4343}
4444
4545// Structs can have declarations.
......@@ -48,8 +48,8 @@ const Empty = struct {
4848 pub const PI = 3.14;
4949};
5050test "struct namespaced variable" {
51 try expect(Empty.PI == 3.14);
52 try expect(@sizeOf(Empty) == 0);
51 try expectEqual(3.14, Empty.PI);
52 try expectEqual(0, @sizeOf(Empty));
5353
5454 // Empty structs can be instantiated the same as usual.
5555 const does_nothing: Empty = .{};
......@@ -69,7 +69,7 @@ test "field parent pointer" {
6969 .y = 0.5678,
7070 };
7171 setYBasedOnX(&point.x, 0.9);
72 try expect(point.y == 0.9);
72 try expectEqual(0.9, point.y);
7373}
7474
7575// Structs can be returned from functions.
......@@ -89,19 +89,19 @@ fn LinkedList(comptime T: type) type {
8989
9090test "linked list" {
9191 // Functions called at compile-time are memoized.
92 try expect(LinkedList(i32) == LinkedList(i32));
92 try expectEqual(LinkedList(i32), LinkedList(i32));
9393
9494 const list = LinkedList(i32){
9595 .first = null,
9696 .last = null,
9797 .len = 0,
9898 };
99 try expect(list.len == 0);
99 try expectEqual(0, list.len);
100100
101101 // Since types are first class values you can instantiate the type
102102 // by assigning it to a variable:
103103 const ListOfInts = LinkedList(i32);
104 try expect(ListOfInts == LinkedList(i32));
104 try expectEqual(LinkedList(i32), ListOfInts);
105105
106106 var node = ListOfInts.Node{
107107 .prev = null,
......@@ -117,10 +117,10 @@ test "linked list" {
117117 // When using a pointer to a struct, fields can be accessed directly,
118118 // without explicitly dereferencing the pointer.
119119 // So you can do
120 try expect(list2.first.?.data == 1234);
121 // instead of try expect(list2.first.?.*.data == 1234);
120 try expectEqual(1234, list2.first.?.data);
121 // instead of try expectEqual(1234, list2.first.?.*.data);
122122}
123123
124const expect = @import("std").testing.expect;
124const expectEqual = @import("std").testing.expectEqual;
125125
126126// test
doc/langref/test_switch.zig+2-2
......@@ -1,6 +1,6 @@
11const std = @import("std");
22const builtin = @import("builtin");
3const expect = std.testing.expect;
3const expectEqual = std.testing.expectEqual;
44
55test "switch simple" {
66 const a: u64 = 10;
......@@ -40,7 +40,7 @@ test "switch simple" {
4040 else => 9,
4141 };
4242
43 try expect(b == 1);
43 try expectEqual(1, b);
4444}
4545
4646// Switch expressions can be used outside a function:
doc/langref/test_switch_modify_tagged_union.zig+2-2
......@@ -1,5 +1,5 @@
11const std = @import("std");
2const expect = std.testing.expect;
2const expectEqual = std.testing.expectEqual;
33
44const ComplexTypeTag = enum {
55 ok,
......@@ -18,7 +18,7 @@ test "modify tagged union in switch" {
1818 ComplexTypeTag.not_ok => unreachable,
1919 }
2020
21 try expect(c.ok == 43);
21 try expectEqual(43, c.ok);
2222}
2323
2424// test
doc/langref/test_switch_tagged_union.zig+3-3
......@@ -1,4 +1,4 @@
1const expect = @import("std").testing.expect;
1const expectEqual = @import("std").testing.expectEqual;
22
33test "switch on tagged union" {
44 const Point = struct {
......@@ -31,8 +31,8 @@ test "switch on tagged union" {
3131 Item.d => 8,
3232 };
3333
34 try expect(b == 6);
35 try expect(a.c.x == 2);
34 try expectEqual(6, b);
35 try expectEqual(2, a.c.x);
3636}
3737
3838// test
doc/langref/test_tagName.zig+2-2
......@@ -1,5 +1,5 @@
11const std = @import("std");
2const expect = std.testing.expect;
2const expectEqualSlices = std.testing.expectEqualSlices;
33
44const Small2 = union(enum) {
55 a: i32,
......@@ -7,7 +7,7 @@ const Small2 = union(enum) {
77 c: u8,
88};
99test "@tagName" {
10 try expect(std.mem.eql(u8, @tagName(Small2.a), "a"));
10 try expectEqualSlices(u8, "a", @tagName(Small2.a));
1111}
1212
1313// test
doc/langref/test_tagged_union.zig+4-4
......@@ -1,5 +1,5 @@
11const std = @import("std");
2const expect = std.testing.expect;
2const expectEqual = std.testing.expectEqual;
33
44const ComplexTypeTag = enum {
55 ok,
......@@ -12,10 +12,10 @@ const ComplexType = union(ComplexTypeTag) {
1212
1313test "switch on tagged union" {
1414 const c = ComplexType{ .ok = 42 };
15 try expect(@as(ComplexTypeTag, c) == ComplexTypeTag.ok);
15 try expectEqual(ComplexTypeTag.ok, @as(ComplexTypeTag, c));
1616
1717 switch (c) {
18 .ok => |value| try expect(value == 42),
18 .ok => |value| try expectEqual(42, value),
1919 .not_ok => unreachable,
2020 }
2121
......@@ -29,7 +29,7 @@ test "switch on tagged union" {
2929}
3030
3131test "get tag type" {
32 try expect(std.meta.Tag(ComplexType) == ComplexTypeTag);
32 try expectEqual(ComplexTypeTag, std.meta.Tag(ComplexType));
3333}
3434
3535// test
doc/langref/test_tagged_union_with_tag_values.zig+3-3
......@@ -1,5 +1,5 @@
11const std = @import("std");
2const expect = std.testing.expect;
2const expectEqual = std.testing.expectEqual;
33
44const Tagged = union(enum(u32)) {
55 int: i64 = 123,
......@@ -8,10 +8,10 @@ const Tagged = union(enum(u32)) {
88
99test "tag values" {
1010 const int: Tagged = .{ .int = -40 };
11 try expect(@intFromEnum(int) == 123);
11 try expectEqual(123, @intFromEnum(int));
1212
1313 const boolean: Tagged = .{ .boolean = false };
14 try expect(@intFromEnum(boolean) == 67);
14 try expectEqual(67, @intFromEnum(boolean));
1515}
1616
1717// test
doc/langref/test_this_builtin.zig+2-2
......@@ -1,10 +1,10 @@
11const std = @import("std");
2const expect = std.testing.expect;
2const expectEqual = std.testing.expectEqual;
33
44test "@This()" {
55 var items = [_]i32{ 1, 2, 3, 4 };
66 const list = List(i32){ .items = items[0..] };
7 try expect(list.length() == 4);
7 try expectEqual(4, list.length());
88}
99
1010fn List(comptime T: type) type {
doc/langref/test_truncate_builtin.zig+2-2
......@@ -1,10 +1,10 @@
11const std = @import("std");
2const expect = std.testing.expect;
2const expectEqual = std.testing.expectEqual;
33
44test "integer truncation" {
55 const a: u16 = 0xabcd;
66 const b: u8 = @truncate(a);
7 try expect(b == 0xcd);
7 try expectEqual(0xcd, b);
88}
99
1010// test
doc/langref/test_tuples.zig+5-4
......@@ -1,5 +1,6 @@
11const std = @import("std");
22const expect = std.testing.expect;
3const expectEqual = std.testing.expectEqual;
34
45test "tuple" {
56 const values = .{
......@@ -8,14 +9,14 @@ test "tuple" {
89 true,
910 "hi",
1011 } ++ .{false} ** 2;
11 try expect(values[0] == 1234);
12 try expect(values[4] == false);
12 try expectEqual(1234, values[0]);
13 try expectEqual(false, values[4]);
1314 inline for (values, 0..) |v, i| {
1415 if (i != 2) continue;
1516 try expect(v);
1617 }
17 try expect(values.len == 6);
18 try expect(values.@"3"[0] == 'h');
18 try expectEqual(6, values.len);
19 try expectEqual('h', values.@"3"[0]);
1920}
2021
2122// test
doc/langref/test_variable_alignment.zig+4-4
......@@ -1,14 +1,14 @@
11const std = @import("std");
22const builtin = @import("builtin");
3const expect = std.testing.expect;
3const expectEqual = std.testing.expectEqual;
44
55test "variable alignment" {
66 var x: i32 = 1234;
77 const align_of_i32 = @alignOf(@TypeOf(x));
8 try expect(@TypeOf(&x) == *i32);
9 try expect(*i32 == *align(align_of_i32) i32);
8 try expectEqual(*i32, @TypeOf(&x));
9 try expectEqual(*align(align_of_i32) i32, *i32);
1010 if (builtin.target.cpu.arch == .x86_64) {
11 try expect(@typeInfo(*i32).pointer.alignment == 4);
11 try expectEqual(4, @typeInfo(*i32).pointer.alignment);
1212 }
1313}
1414
doc/langref/test_variable_func_alignment.zig+11-11
......@@ -1,14 +1,14 @@
1const expect = @import("std").testing.expect;
1const expectEqual = @import("std").testing.expectEqual;
22
33var foo: u8 align(4) = 100;
44
55test "global variable alignment" {
6 try expect(@typeInfo(@TypeOf(&foo)).pointer.alignment == 4);
7 try expect(@TypeOf(&foo) == *align(4) u8);
6 try expectEqual(4, @typeInfo(@TypeOf(&foo)).pointer.alignment);
7 try expectEqual(*align(4) u8, @TypeOf(&foo));
88 const as_pointer_to_array: *align(4) [1]u8 = &foo;
99 const as_slice: []align(4) u8 = as_pointer_to_array;
1010 const as_unaligned_slice: []u8 = as_slice;
11 try expect(as_unaligned_slice[0] == 100);
11 try expectEqual(100, as_unaligned_slice[0]);
1212}
1313
1414fn derp() align(@sizeOf(usize) * 2) i32 {
......@@ -18,17 +18,17 @@ fn noop1() align(1) void {}
1818fn noop4() align(4) void {}
1919
2020test "function alignment" {
21 try expect(derp() == 1234);
22 try expect(@TypeOf(derp) == fn () i32);
23 try expect(@TypeOf(&derp) == *align(@sizeOf(usize) * 2) const fn () i32);
21 try expectEqual(1234, derp());
22 try expectEqual(fn () i32, @TypeOf(derp));
23 try expectEqual(*align(@sizeOf(usize) * 2) const fn () i32, @TypeOf(&derp));
2424
2525 noop1();
26 try expect(@TypeOf(noop1) == fn () void);
27 try expect(@TypeOf(&noop1) == *align(1) const fn () void);
26 try expectEqual(fn () void, @TypeOf(noop1));
27 try expectEqual(*align(1) const fn () void, @TypeOf(&noop1));
2828
2929 noop4();
30 try expect(@TypeOf(noop4) == fn () void);
31 try expect(@TypeOf(&noop4) == *align(4) const fn () void);
30 try expectEqual(fn () void, @TypeOf(noop4));
31 try expectEqual(*align(4) const fn () void, @TypeOf(&noop4));
3232}
3333
3434// test
doc/langref/test_variadic_function.zig+1-1
......@@ -4,7 +4,7 @@ const testing = std.testing;
44pub extern "c" fn printf(format: [*:0]const u8, ...) c_int;
55
66test "variadic function" {
7 try testing.expect(printf("Hello, world!\n") == 14);
7 try testing.expectEqual(14, printf("Hello, world!\n"));
88 try testing.expect(@typeInfo(@TypeOf(printf)).@"fn".is_var_args);
99}
1010
doc/langref/test_volatile.zig+2-2
......@@ -1,8 +1,8 @@
1const expect = @import("std").testing.expect;
1const expectEqual = @import("std").testing.expectEqual;
22
33test "volatile" {
44 const mmio_ptr: *volatile u8 = @ptrFromInt(0x12345678);
5 try expect(@TypeOf(mmio_ptr) == *volatile u8);
5 try expectEqual(*volatile u8, @TypeOf(mmio_ptr));
66}
77
88// test
doc/langref/test_wasmMemoryGrow_builtin.zig+3-3
......@@ -1,13 +1,13 @@
11const std = @import("std");
22const native_arch = @import("builtin").target.cpu.arch;
3const expect = std.testing.expect;
3const expectEqual = std.testing.expectEqual;
44
55test "@wasmMemoryGrow" {
66 if (native_arch != .wasm32) return error.SkipZigTest;
77
88 const prev = @wasmMemorySize(0);
9 try expect(prev == @wasmMemoryGrow(0, 1));
10 try expect(prev + 1 == @wasmMemorySize(0));
9 try expectEqual(@wasmMemoryGrow(0, 1), prev);
10 try expectEqual(@wasmMemorySize(0), prev + 1);
1111}
1212
1313// test
doc/langref/test_while.zig+2-2
......@@ -1,11 +1,11 @@
1const expect = @import("std").testing.expect;
1const expectEqual = @import("std").testing.expectEqual;
22
33test "while basic" {
44 var i: usize = 0;
55 while (i < 10) {
66 i += 1;
77 }
8 try expect(i == 10);
8 try expectEqual(10, i);
99}
1010
1111// test
doc/langref/test_while_break.zig+2-2
......@@ -1,4 +1,4 @@
1const expect = @import("std").testing.expect;
1const expectEqual = @import("std").testing.expectEqual;
22
33test "while break" {
44 var i: usize = 0;
......@@ -7,7 +7,7 @@ test "while break" {
77 break;
88 i += 1;
99 }
10 try expect(i == 10);
10 try expectEqual(10, i);
1111}
1212
1313// test
doc/langref/test_while_continue.zig+2-2
......@@ -1,4 +1,4 @@
1const expect = @import("std").testing.expect;
1const expectEqual = @import("std").testing.expectEqual;
22
33test "while continue" {
44 var i: usize = 0;
......@@ -8,7 +8,7 @@ test "while continue" {
88 continue;
99 break;
1010 }
11 try expect(i == 10);
11 try expectEqual(10, i);
1212}
1313
1414// test
doc/langref/test_while_continue_expression.zig+2-1
......@@ -1,9 +1,10 @@
1const expectEqual = @import("std").testing.expectEqual;
12const expect = @import("std").testing.expect;
23
34test "while loop continue expression" {
45 var i: usize = 0;
56 while (i < 10) : (i += 1) {}
6 try expect(i == 10);
7 try expectEqual(10, i);
78}
89
910test "while loop continue expression, more complicated" {
doc/langref/test_while_error_capture.zig+2-2
......@@ -1,4 +1,4 @@
1const expect = @import("std").testing.expect;
1const expectEqual = @import("std").testing.expectEqual;
22
33test "while error union capture" {
44 var sum1: u32 = 0;
......@@ -6,7 +6,7 @@ test "while error union capture" {
66 while (eventuallyErrorSequence()) |value| {
77 sum1 += value;
88 } else |err| {
9 try expect(err == error.ReachedZero);
9 try expectEqual(error.ReachedZero, err);
1010 }
1111}
1212
doc/langref/test_while_null_capture.zig+4-4
......@@ -1,4 +1,4 @@
1const expect = @import("std").testing.expect;
1const expectEqual = @import("std").testing.expectEqual;
22
33test "while null capture" {
44 var sum1: u32 = 0;
......@@ -6,7 +6,7 @@ test "while null capture" {
66 while (eventuallyNullSequence()) |value| {
77 sum1 += value;
88 }
9 try expect(sum1 == 3);
9 try expectEqual(3, sum1);
1010
1111 // null capture with an else block
1212 var sum2: u32 = 0;
......@@ -14,7 +14,7 @@ test "while null capture" {
1414 while (eventuallyNullSequence()) |value| {
1515 sum2 += value;
1616 } else {
17 try expect(sum2 == 3);
17 try expectEqual(3, sum2);
1818 }
1919
2020 // null capture with a continue expression
......@@ -24,7 +24,7 @@ test "while null capture" {
2424 while (eventuallyNullSequence()) |value| : (i += 1) {
2525 sum3 += value;
2626 }
27 try expect(i == 3);
27 try expectEqual(3, i);
2828}
2929
3030var numbers_left: u32 = undefined;
doc/langref/test_wraparound_semantics.zig+3-3
......@@ -1,14 +1,14 @@
11const std = @import("std");
2const expect = std.testing.expect;
2const expectEqual = std.testing.expectEqual;
33const minInt = std.math.minInt;
44const maxInt = std.math.maxInt;
55
66test "wraparound addition and subtraction" {
77 const x: i32 = maxInt(i32);
88 const min_val = x +% 1;
9 try expect(min_val == minInt(i32));
9 try expectEqual(minInt(i32), min_val);
1010 const max_val = min_val -% 1;
11 try expect(max_val == maxInt(i32));
11 try expectEqual(maxInt(i32), max_val);
1212}
1313
1414// test
doc/langref/testing_detect_leak.zig+1-1
......@@ -6,7 +6,7 @@ test "detect leak" {
66 // missing `defer list.deinit(gpa);`
77 try list.append(gpa, '☔');
88
9 try std.testing.expect(list.items.len == 1);
9 try std.testing.expectEqual(1, list.items.len);
1010}
1111
1212// test_error=1 tests leaked memory
doc/langref/testing_introduction.zig+5-1
......@@ -7,12 +7,16 @@ test "expect addOne adds one to 41" {
77 // It will return an error if its argument is false to indicate a failure.
88 // `try` is used to return an error to the test runner to notify it that the test failed.
99 try std.testing.expect(addOne(41) == 42);
10
11 // However, in most cases it is more convenient to use a more specific function like `expectEqual`.
12 // This gives you much clearer and more helpful error messages when a test fails.
13 try std.testing.expectEqual(42, addOne(41));
1014}
1115
1216test addOne {
1317 // A test name can also be written using an identifier.
1418 // This is a doctest, and serves as documentation for `addOne`.
15 try std.testing.expect(addOne(41) == 42);
19 try std.testing.expectEqual(42, addOne(41));
1620}
1721
1822/// The function `addOne` adds one to the number given as its argument.