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 {...@@ -35,7 +35,7 @@ fn charToDigit(c: u8) u8 {
3535
36test "parse u64" {36test "parse u64" {
37 const result = try parseU64("1234", 10);37 const result = try parseU64("1234", 10);
38 try std.testing.expect(result == 1234);38 try std.testing.expectEqual(1234, result);
39}39}
4040
41// test41// test
doc/langref/result_location_interfering_with_swap.zig+3-3
...@@ -1,4 +1,4 @@...@@ -1,4 +1,4 @@
1const expect = @import("std").testing.expect;1const expectEqual = @import("std").testing.expectEqual;
2test "attempt to swap array elements with array initializer" {2test "attempt to swap array elements with array initializer" {
3 var arr: [2]u32 = .{ 1, 2 };3 var arr: [2]u32 = .{ 1, 2 };
4 arr = .{ arr[1], arr[0] };4 arr = .{ arr[1], arr[0] };
...@@ -6,8 +6,8 @@ test "attempt to swap array elements with array initializer" {...@@ -6,8 +6,8 @@ test "attempt to swap array elements with array initializer" {
6 // arr[0] = arr[1];6 // arr[0] = arr[1];
7 // arr[1] = arr[0];7 // arr[1] = arr[0];
8 // So this fails!8 // So this fails!
9 try expect(arr[0] == 2); // succeeds9 try expectEqual(2, arr[0]); // succeeds
10 try expect(arr[1] == 1); // fails10 try expectEqual(1, arr[1]); // fails
11}11}
1212
13// test_error=13// test_error=
doc/langref/test_TypeOf_builtin.zig+3-3
...@@ -1,11 +1,11 @@...@@ -1,11 +1,11 @@
1const std = @import("std");1const std = @import("std");
2const expect = std.testing.expect;2const expectEqual = std.testing.expectEqual;
33
4test "no runtime side effects" {4test "no runtime side effects" {
5 var data: i32 = 0;5 var data: i32 = 0;
6 const T = @TypeOf(foo(i32, &data));6 const T = @TypeOf(foo(i32, &data));
7 try comptime expect(T == i32);7 try comptime expectEqual(i32, T);
8 try expect(data == 0);8 try expectEqual(0, data);
9}9}
1010
11fn foo(comptime T: type, ptr: *T) T {11fn foo(comptime T: type, ptr: *T) T {
doc/langref/test_allocator.zig+2-2
...@@ -1,13 +1,13 @@...@@ -1,13 +1,13 @@
1const std = @import("std");1const std = @import("std");
2const Allocator = std.mem.Allocator;2const Allocator = std.mem.Allocator;
3const expect = std.testing.expect;3const expectEqualStrings = std.testing.expectEqualStrings;
44
5test "using an allocator" {5test "using an allocator" {
6 var buffer: [100]u8 = undefined;6 var buffer: [100]u8 = undefined;
7 var fba = std.heap.FixedBufferAllocator.init(&buffer);7 var fba = std.heap.FixedBufferAllocator.init(&buffer);
8 const allocator = fba.allocator();8 const allocator = fba.allocator();
9 const result = try concat(allocator, "foo", "bar");9 const result = try concat(allocator, "foo", "bar");
10 try expect(std.mem.eql(u8, "foobar", result));10 try expectEqualStrings("foobar", result);
11}11}
1212
13fn concat(allocator: Allocator, a: []const u8, b: []const u8) ![]u8 {13fn concat(allocator: Allocator, a: []const u8, b: []const u8) ![]u8 {
doc/langref/test_allowzero.zig+2-2
...@@ -1,11 +1,11 @@...@@ -1,11 +1,11 @@
1const std = @import("std");1const std = @import("std");
2const expect = std.testing.expect;2const expectEqual = std.testing.expectEqual;
33
4test "allowzero" {4test "allowzero" {
5 var zero: usize = 0; // var to make to runtime-known5 var zero: usize = 0; // var to make to runtime-known
6 _ = &zero; // suppress 'var is never mutated' error6 _ = &zero; // suppress 'var is never mutated' error
7 const ptr: *allowzero i32 = @ptrFromInt(zero);7 const ptr: *allowzero i32 = @ptrFromInt(zero);
8 try expect(@intFromPtr(ptr) == 0);8 try expectEqual(0, @intFromPtr(ptr));
9}9}
1010
11// test11// test
doc/langref/test_anonymous_struct.zig+5-4
...@@ -1,5 +1,6 @@...@@ -1,5 +1,6 @@
1const std = @import("std");1const std = @import("std");
2const expect = std.testing.expect;2const expect = std.testing.expect;
3const expectEqual = std.testing.expectEqual;
34
4test "fully anonymous struct" {5test "fully anonymous struct" {
5 try check(.{6 try check(.{
...@@ -11,11 +12,11 @@ test "fully anonymous struct" {...@@ -11,11 +12,11 @@ test "fully anonymous struct" {
11}12}
1213
13fn check(args: anytype) !void {14fn check(args: anytype) !void {
14 try expect(args.int == 1234);15 try expectEqual(1234, args.int);
15 try expect(args.float == 12.34);16 try expectEqual(12.34, args.float);
16 try expect(args.b);17 try expect(args.b);
17 try expect(args.s[0] == 'h');18 try expectEqual('h', args.s[0]);
18 try expect(args.s[1] == 'i');19 try expectEqual('i', args.s[1]);
19}20}
2021
21// test22// test
doc/langref/test_anonymous_union.zig+3-3
...@@ -1,5 +1,5 @@...@@ -1,5 +1,5 @@
1const std = @import("std");1const std = @import("std");
2const expect = std.testing.expect;2const expectEqual = std.testing.expectEqual;
33
4const Number = union {4const Number = union {
5 int: i32,5 int: i32,
...@@ -9,8 +9,8 @@ const Number = union {...@@ -9,8 +9,8 @@ const Number = union {
9test "anonymous union literal syntax" {9test "anonymous union literal syntax" {
10 const i: Number = .{ .int = 42 };10 const i: Number = .{ .int = 42 };
11 const f = makeNumber();11 const f = makeNumber();
12 try expect(i.int == 42);12 try expectEqual(42, i.int);
13 try expect(f.float == 12.34);13 try expectEqual(12.34, f.float);
14}14}
1515
16fn makeNumber() Number {16fn makeNumber() Number {
doc/langref/test_arrays.zig+9-9
...@@ -1,4 +1,4 @@...@@ -1,4 +1,4 @@
1const expect = @import("std").testing.expect;1const expectEqual = @import("std").testing.expectEqual;
2const assert = @import("std").debug.assert;2const assert = @import("std").debug.assert;
3const mem = @import("std").mem;3const mem = @import("std").mem;
44
...@@ -29,7 +29,7 @@ test "iterate over an array" {...@@ -29,7 +29,7 @@ test "iterate over an array" {
29 for (message) |byte| {29 for (message) |byte| {
30 sum += byte;30 sum += byte;
31 }31 }
32 try expect(sum == 'h' + 'e' + 'l' * 2 + 'o');32 try expectEqual('h' + 'e' + 'l' * 2 + 'o', sum);
33}33}
3434
35// modifiable array35// modifiable array
...@@ -39,8 +39,8 @@ test "modify an array" {...@@ -39,8 +39,8 @@ test "modify an array" {
39 for (&some_integers, 0..) |*item, i| {39 for (&some_integers, 0..) |*item, i| {
40 item.* = @intCast(i);40 item.* = @intCast(i);
41 }41 }
42 try expect(some_integers[10] == 10);42 try expectEqual(10, some_integers[10]);
43 try expect(some_integers[99] == 99);43 try expectEqual(99, some_integers[99]);
44}44}
4545
46// array concatenation works if the values are known46// array concatenation works if the values are known
...@@ -91,8 +91,8 @@ const Point = struct {...@@ -91,8 +91,8 @@ const Point = struct {
91};91};
9292
93test "compile-time array initialization" {93test "compile-time array initialization" {
94 try expect(fancy_array[4].x == 4);94 try expectEqual(4, fancy_array[4].x);
95 try expect(fancy_array[4].y == 8);95 try expectEqual(8, fancy_array[4].y);
96}96}
9797
98// call a function to initialize an array98// call a function to initialize an array
...@@ -104,9 +104,9 @@ fn makePoint(x: i32) Point {...@@ -104,9 +104,9 @@ fn makePoint(x: i32) Point {
104 };104 };
105}105}
106test "array initialization with function calls" {106test "array initialization with function calls" {
107 try expect(more_points[4].x == 3);107 try expectEqual(3, more_points[4].x);
108 try expect(more_points[4].y == 6);108 try expectEqual(6, more_points[4].y);
109 try expect(more_points.len == 10);109 try expectEqual(10, more_points.len);
110}110}
111111
112// test112// test
doc/langref/test_basic_slices.zig+11-11
...@@ -1,4 +1,4 @@...@@ -1,4 +1,4 @@
1const expect = @import("std").testing.expect;1const expectEqual = @import("std").testing.expectEqual;
2const expectEqualSlices = @import("std").testing.expectEqualSlices;2const expectEqualSlices = @import("std").testing.expectEqualSlices;
33
4test "basic slices" {4test "basic slices" {
...@@ -12,14 +12,14 @@ test "basic slices" {...@@ -12,14 +12,14 @@ test "basic slices" {
1212
13 try expectEqualSlices(i32, slice, alt_slice);13 try expectEqualSlices(i32, slice, alt_slice);
1414
15 try expect(@TypeOf(slice) == []i32);15 try expectEqual([]i32, @TypeOf(slice));
16 try expect(&slice[0] == &array[0]);16 try expectEqual(&array[0], &slice[0]);
17 try expect(slice.len == array.len);17 try expectEqual(array.len, slice.len);
1818
19 // If you slice with comptime-known start and end positions, the result is19 // If you slice with comptime-known start and end positions, the result is
20 // a pointer to an array, rather than a slice.20 // a pointer to an array, rather than a slice.
21 const array_ptr = array[0..array.len];21 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
24 // You can perform a slice-by-length by slicing twice. This allows the compiler24 // You can perform a slice-by-length by slicing twice. This allows the compiler
25 // to perform some optimisations like recognising a comptime-known length when25 // to perform some optimisations like recognising a comptime-known length when
...@@ -28,13 +28,13 @@ test "basic slices" {...@@ -28,13 +28,13 @@ test "basic slices" {
28 _ = &runtime_start;28 _ = &runtime_start;
29 const length = 2;29 const length = 2;
30 const array_ptr_len = array[runtime_start..][0..length];30 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
33 // Using the address-of operator on a slice gives a single-item pointer.33 // 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]));
35 // Using the `ptr` field gives a many-item pointer.35 // Using the `ptr` field gives a many-item pointer.
36 try expect(@TypeOf(slice.ptr) == [*]i32);36 try expectEqual([*]i32, @TypeOf(slice.ptr));
37 try expect(@intFromPtr(slice.ptr) == @intFromPtr(&slice[0]));37 try expectEqual(@intFromPtr(slice.ptr), @intFromPtr(&slice[0]));
3838
39 // Slices have array bounds checking. If you try to access something out39 // Slices have array bounds checking. If you try to access something out
40 // of bounds, you'll get a safety check failure:40 // of bounds, you'll get a safety check failure:
...@@ -47,8 +47,8 @@ test "basic slices" {...@@ -47,8 +47,8 @@ test "basic slices" {
47 const empty1 = &[0]u8{};47 const empty1 = &[0]u8{};
48 // If the type is known you can use this short hand:48 // If the type is known you can use this short hand:
49 const empty2: []u8 = &.{};49 const empty2: []u8 = &.{};
50 try expect(empty1.len == 0);50 try expectEqual(0, empty1.len);
51 try expect(empty2.len == 0);51 try expectEqual(0, empty2.len);
5252
53 // A zero-length initialization can always be used to create an empty slice, even if the slice is mutable.53 // A zero-length initialization can always be used to create an empty slice, even if the slice is mutable.
54 // This is because the pointed-to data is zero bits long, so its immutability is irrelevant.54 // 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 @@...@@ -1,5 +1,5 @@
1const std = @import("std");1const std = @import("std");
2const expect = std.testing.expect;2const expectEqual = std.testing.expectEqual;
33
4const BitField = packed struct {4const BitField = packed struct {
5 a: u3,5 a: u3,
...@@ -9,13 +9,13 @@ const BitField = packed struct {...@@ -9,13 +9,13 @@ const BitField = packed struct {
99
10test "offsets of non-byte-aligned fields" {10test "offsets of non-byte-aligned fields" {
11 comptime {11 comptime {
12 try expect(@bitOffsetOf(BitField, "a") == 0);12 try expectEqual(0, @bitOffsetOf(BitField, "a"));
13 try expect(@bitOffsetOf(BitField, "b") == 3);13 try expectEqual(3, @bitOffsetOf(BitField, "b"));
14 try expect(@bitOffsetOf(BitField, "c") == 6);14 try expectEqual(6, @bitOffsetOf(BitField, "c"));
1515
16 try expect(@offsetOf(BitField, "a") == 0);16 try expectEqual(0, @offsetOf(BitField, "a"));
17 try expect(@offsetOf(BitField, "b") == 0);17 try expectEqual(0, @offsetOf(BitField, "b"));
18 try expect(@offsetOf(BitField, "c") == 0);18 try expectEqual(0, @offsetOf(BitField, "c"));
19 }19 }
20}20}
2121
doc/langref/test_call_builtin.zig+2-2
...@@ -1,7 +1,7 @@...@@ -1,7 +1,7 @@
1const expect = @import("std").testing.expect;1const expectEqual = @import("std").testing.expectEqual;
22
3test "noinline function call" {3test "noinline function call" {
4 try expect(@call(.auto, add, .{ 3, 9 }) == 12);4 try expectEqual(12, @call(.auto, add, .{ 3, 9 }));
5}5}
66
7fn add(a: i32, b: i32) i32 {7fn add(a: i32, b: i32) i32 {
doc/langref/test_coerce_error_subset_to_superset.zig+1-1
...@@ -12,7 +12,7 @@ const AllocationError = error{...@@ -12,7 +12,7 @@ const AllocationError = error{
1212
13test "coerce subset to superset" {13test "coerce subset to superset" {
14 const err = foo(AllocationError.OutOfMemory);14 const err = foo(AllocationError.OutOfMemory);
15 try std.testing.expect(err == FileOpenError.OutOfMemory);15 try std.testing.expectEqual(FileOpenError.OutOfMemory, err);
16}16}
1717
18fn foo(err: AllocationError) FileOpenError {18fn foo(err: AllocationError) FileOpenError {
doc/langref/test_coerce_large_to_small.zig+2-2
...@@ -1,10 +1,10 @@...@@ -1,10 +1,10 @@
1const std = @import("std");1const std = @import("std");
2const expect = std.testing.expect;2const expectEqual = std.testing.expectEqual;
33
4test "coercing large integer type to smaller one when value is comptime-known to fit" {4test "coercing large integer type to smaller one when value is comptime-known to fit" {
5 const x: u64 = 255;5 const x: u64 = 255;
6 const y: u8 = x;6 const y: u8 = x;
7 try expect(y == 255);7 try expectEqual(255, y);
8}8}
99
10// test10// test
doc/langref/test_coerce_optional_wrapped_error_union.zig+3-3
...@@ -1,12 +1,12 @@...@@ -1,12 +1,12 @@
1const std = @import("std");1const std = @import("std");
2const expect = std.testing.expect;2const expectEqual = std.testing.expectEqual;
33
4test "coerce to optionals wrapped in error union" {4test "coerce to optionals wrapped in error union" {
5 const x: anyerror!?i32 = 1234;5 const x: anyerror!?i32 = 1234;
6 const y: anyerror!?i32 = null;6 const y: anyerror!?i32 = null;
77
8 try expect((try x).? == 1234);8 try expectEqual(1234, (try x).?);
9 try expect((try y) == null);9 try expectEqual(null, (try y));
10}10}
1111
12// test12// test
doc/langref/test_coerce_optionals.zig+3-3
...@@ -1,12 +1,12 @@...@@ -1,12 +1,12 @@
1const std = @import("std");1const std = @import("std");
2const expect = std.testing.expect;2const expectEqual = std.testing.expectEqual;
33
4test "coerce to optionals" {4test "coerce to optionals" {
5 const x: ?i32 = 1234;5 const x: ?i32 = 1234;
6 const y: ?i32 = null;6 const y: ?i32 = null;
77
8 try expect(x.? == 1234);8 try expectEqual(1234, x.?);
9 try expect(y == null);9 try expectEqual(null, y);
10}10}
1111
12// test12// test
doc/langref/test_coerce_slices_arrays_and_pointers.zig+15-13
...@@ -1,5 +1,7 @@...@@ -1,5 +1,7 @@
1const std = @import("std");1const std = @import("std");
2const expect = std.testing.expect;2const expectEqual = std.testing.expectEqual;
3const expectEqualStrings = std.testing.expectEqualStrings;
4const expectEqualSlices = std.testing.expectEqualSlices;
35
4// You can assign constant pointers to arrays to a slice with6// You can assign constant pointers to arrays to a slice with
5// const modifier on the element type. Useful in particular for7// const modifier on the element type. Useful in particular for
...@@ -7,48 +9,48 @@ const expect = std.testing.expect;...@@ -7,48 +9,48 @@ const expect = std.testing.expect;
7test "*const [N]T to []const T" {9test "*const [N]T to []const T" {
8 const x1: []const u8 = "hello";10 const x1: []const u8 = "hello";
9 const x2: []const u8 = &[5]u8{ 'h', 'e', 'l', 'l', 111 };11 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
12 const y: []const f32 = &[2]f32{ 1.2, 3.4 };14 const y: []const f32 = &[2]f32{ 1.2, 3.4 };
13 try expect(y[0] == 1.2);15 try expectEqual(1.2, y[0]);
14}16}
1517
16// Likewise, it works when the destination type is an error union.18// Likewise, it works when the destination type is an error union.
17test "*const [N]T to E![]const T" {19test "*const [N]T to E![]const T" {
18 const x1: anyerror![]const u8 = "hello";20 const x1: anyerror![]const u8 = "hello";
19 const x2: anyerror![]const u8 = &[5]u8{ 'h', 'e', 'l', 'l', 111 };21 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
22 const y: anyerror![]const f32 = &[2]f32{ 1.2, 3.4 };24 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]);
24}26}
2527
26// Likewise, it works when the destination type is an optional.28// Likewise, it works when the destination type is an optional.
27test "*const [N]T to ?[]const T" {29test "*const [N]T to ?[]const T" {
28 const x1: ?[]const u8 = "hello";30 const x1: ?[]const u8 = "hello";
29 const x2: ?[]const u8 = &[5]u8{ 'h', 'e', 'l', 'l', 111 };31 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
32 const y: ?[]const f32 = &[2]f32{ 1.2, 3.4 };34 const y: ?[]const f32 = &[2]f32{ 1.2, 3.4 };
33 try expect(y.?[0] == 1.2);35 try expectEqual(1.2, y.?[0]);
34}36}
3537
36// In this cast, the array length becomes the slice length.38// In this cast, the array length becomes the slice length.
37test "*[N]T to []T" {39test "*[N]T to []T" {
38 var buf: [5]u8 = "hello".*;40 var buf: [5]u8 = "hello".*;
39 const x: []u8 = &buf;41 const x: []u8 = &buf;
40 try expect(std.mem.eql(u8, x, "hello"));42 try expectEqualStrings("hello", x);
4143
42 const buf2 = [2]f32{ 1.2, 3.4 };44 const buf2 = [2]f32{ 1.2, 3.4 };
43 const x2: []const f32 = &buf2;45 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);
45}47}
4648
47// Single-item pointers to arrays can be coerced to many-item pointers.49// Single-item pointers to arrays can be coerced to many-item pointers.
48test "*[N]T to [*]T" {50test "*[N]T to [*]T" {
49 var buf: [5]u8 = "hello".*;51 var buf: [5]u8 = "hello".*;
50 const x: [*]u8 = &buf;52 const x: [*]u8 = &buf;
51 try expect(x[4] == 'o');53 try expectEqual('o', x[4]);
52 // x[5] would be an uncaught out of bounds pointer dereference!54 // x[5] would be an uncaught out of bounds pointer dereference!
53}55}
5456
...@@ -56,7 +58,7 @@ test "*[N]T to [*]T" {...@@ -56,7 +58,7 @@ test "*[N]T to [*]T" {
56test "*[N]T to ?[*]T" {58test "*[N]T to ?[*]T" {
57 var buf: [5]u8 = "hello".*;59 var buf: [5]u8 = "hello".*;
58 const x: ?[*]u8 = &buf;60 const x: ?[*]u8 = &buf;
59 try expect(x.?[4] == 'o');61 try expectEqual('o', x.?[4]);
60}62}
6163
62// Single-item pointers can be cast to len-1 single-item arrays.64// Single-item pointers can be cast to len-1 single-item arrays.
...@@ -64,14 +66,14 @@ test "*T to *[1]T" {...@@ -64,14 +66,14 @@ test "*T to *[1]T" {
64 var x: i32 = 1234;66 var x: i32 = 1234;
65 const y: *[1]i32 = &x;67 const y: *[1]i32 = &x;
66 const z: [*]i32 = y;68 const z: [*]i32 = y;
67 try expect(z[0] == 1234);69 try expectEqual(1234, z[0]);
68}70}
6971
70// Sentinel-terminated slices can be coerced into sentinel-terminated pointers72// Sentinel-terminated slices can be coerced into sentinel-terminated pointers
71test "[:x]T to [*:x]T" {73test "[:x]T to [*:x]T" {
72 const buf: [:0]const u8 = "hello";74 const buf: [:0]const u8 = "hello";
73 const buf2: [*:0]const u8 = buf;75 const buf2: [*:0]const u8 = buf;
74 try expect(buf2[4] == 'o');76 try expectEqual('o', buf2[4]);
75}77}
7678
77// test79// test
doc/langref/test_coerce_to_error_union.zig+2-2
...@@ -1,11 +1,11 @@...@@ -1,11 +1,11 @@
1const std = @import("std");1const std = @import("std");
2const expect = std.testing.expect;2const expectEqual = std.testing.expectEqual;
33
4test "coercion to error unions" {4test "coercion to error unions" {
5 const x: anyerror!i32 = 1234;5 const x: anyerror!i32 = 1234;
6 const y: anyerror!i32 = error.Failure;6 const y: anyerror!i32 = error.Failure;
77
8 try expect((try x) == 1234);8 try expectEqual(1234, (try x));
9 try std.testing.expectError(error.Failure, y);9 try std.testing.expectError(error.Failure, y);
10}10}
1111
doc/langref/test_coerce_tuples_arrays.zig+1-1
...@@ -1,5 +1,5 @@...@@ -1,5 +1,5 @@
1const std = @import("std");1const std = @import("std");
2const expect = std.testing.expect;2const expectEqual = std.testing.expectEqual;
33
4const Tuple = struct { u8, u8 };4const Tuple = struct { u8, u8 };
5test "coercion from homogeneous tuple to array" {5test "coercion from homogeneous tuple to array" {
doc/langref/test_coerce_unions_enums.zig+6-6
...@@ -1,5 +1,5 @@...@@ -1,5 +1,5 @@
1const std = @import("std");1const std = @import("std");
2const expect = std.testing.expect;2const expectEqual = std.testing.expectEqual;
33
4const E = enum {4const E = enum {
5 one,5 one,
...@@ -28,22 +28,22 @@ const U2 = union(enum) {...@@ -28,22 +28,22 @@ const U2 = union(enum) {
28test "coercion between unions and enums" {28test "coercion between unions and enums" {
29 const u = U{ .two = 12.34 };29 const u = U{ .two = 12.34 };
30 const e: E = u; // coerce union to enum30 const e: E = u; // coerce union to enum
31 try expect(e == E.two);31 try expectEqual(E.two, e);
3232
33 const three = E.three;33 const three = E.three;
34 const u_2: U = three; // coerce enum to union34 const u_2: U = three; // coerce enum to union
35 try expect(u_2 == E.three);35 try expectEqual(E.three, u_2);
3636
37 const u_3: U = .three; // coerce enum literal to union37 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
40 const u_4: U2 = .a; // coerce enum literal to union with inferred enum tag type.40 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
43 // The following example is invalid.43 // The following example is invalid.
44 // error: coercion from enum '@EnumLiteral()' to union 'test_coerce_unions_enum.U2' must initialize 'f32' field 'b'44 // error: coercion from enum '@EnumLiteral()' to union 'test_coerce_unions_enum.U2' must initialize 'f32' field 'b'
45 //var u_5: U2 = .b;45 //var u_5: U2 = .b;
46 //try expect(u_5.tag() == 2);46 //try expectEqual(2, u_5.tag());
47}47}
4848
49// test49// test
doc/langref/test_comptime_evaluation.zig+4-4
...@@ -1,4 +1,4 @@...@@ -1,4 +1,4 @@
1const expect = @import("std").testing.expect;1const expectEqual = @import("std").testing.expectEqual;
22
3const CmdFn = struct {3const CmdFn = struct {
4 name: []const u8,4 name: []const u8,
...@@ -32,9 +32,9 @@ fn performFn(comptime prefix_char: u8, start_value: i32) i32 {...@@ -32,9 +32,9 @@ fn performFn(comptime prefix_char: u8, start_value: i32) i32 {
32}32}
3333
34test "perform fn" {34test "perform fn" {
35 try expect(performFn('t', 1) == 6);35 try expectEqual(6, performFn('t', 1));
36 try expect(performFn('o', 0) == 1);36 try expectEqual(1, performFn('o', 0));
37 try expect(performFn('w', 99) == 99);37 try expectEqual(99, performFn('w', 99));
38}38}
3939
40// test40// 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 {...@@ -8,7 +8,7 @@ fn max(comptime T: type, a: T, b: T) T {
8 }8 }
9}9}
10test "try to compare bools" {10test "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));
12}12}
1313
14// test14// test
doc/langref/test_comptime_pointer_conversion.zig+3-3
...@@ -1,4 +1,4 @@...@@ -1,4 +1,4 @@
1const expect = @import("std").testing.expect;1const expectEqual = @import("std").testing.expectEqual;
22
3test "comptime @ptrFromInt" {3test "comptime @ptrFromInt" {
4 comptime {4 comptime {
...@@ -6,8 +6,8 @@ test "comptime @ptrFromInt" {...@@ -6,8 +6,8 @@ test "comptime @ptrFromInt" {
6 // ptr is never dereferenced.6 // ptr is never dereferenced.
7 const ptr: *i32 = @ptrFromInt(0xdeadbee0);7 const ptr: *i32 = @ptrFromInt(0xdeadbee0);
8 const addr = @intFromPtr(ptr);8 const addr = @intFromPtr(ptr);
9 try expect(@TypeOf(addr) == usize);9 try expectEqual(usize, @TypeOf(addr));
10 try expect(addr == 0xdeadbee0);10 try expectEqual(0xdeadbee0, addr);
11 }11 }
12}12}
1313
doc/langref/test_comptime_pointers.zig+2-2
...@@ -1,4 +1,4 @@...@@ -1,4 +1,4 @@
1const expect = @import("std").testing.expect;1const expectEqual = @import("std").testing.expectEqual;
22
3test "comptime pointers" {3test "comptime pointers" {
4 comptime {4 comptime {
...@@ -6,7 +6,7 @@ test "comptime pointers" {...@@ -6,7 +6,7 @@ test "comptime pointers" {
6 const ptr = &x;6 const ptr = &x;
7 ptr.* += 1;7 ptr.* += 1;
8 x += 1;8 x += 1;
9 try expect(ptr.* == 3);9 try expectEqual(3, ptr.*);
10 }10 }
11}11}
1212
doc/langref/test_comptime_variables.zig+3-3
...@@ -1,5 +1,5 @@...@@ -1,5 +1,5 @@
1const std = @import("std");1const std = @import("std");
2const expect = std.testing.expect;2const expectEqual = std.testing.expectEqual;
33
4test "comptime vars" {4test "comptime vars" {
5 var x: i32 = 1;5 var x: i32 = 1;
...@@ -8,8 +8,8 @@ test "comptime vars" {...@@ -8,8 +8,8 @@ test "comptime vars" {
8 x += 1;8 x += 1;
9 y += 1;9 y += 1;
1010
11 try expect(x == 2);11 try expectEqual(2, x);
12 try expect(y == 2);12 try expectEqual(2, y);
1313
14 if (y != 2) {14 if (y != 2) {
15 // This compile error never triggers because y is a comptime variable,15 // 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 {...@@ -31,7 +31,7 @@ fn sum(numbers: []const i32) i32 {
31}31}
3232
33test "variable values" {33test "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);
35}35}
3636
37// test37// test
doc/langref/test_container_level_variables.zig+3-3
...@@ -2,8 +2,8 @@ var y: i32 = add(10, x);...@@ -2,8 +2,8 @@ var y: i32 = add(10, x);
2const x: i32 = add(12, 34);2const x: i32 = add(12, 34);
33
4test "container level variables" {4test "container level variables" {
5 try expect(x == 46);5 try expectEqual(46, x);
6 try expect(y == 56);6 try expectEqual(56, y);
7}7}
88
9fn add(a: i32, b: i32) i32 {9fn add(a: i32, b: i32) i32 {
...@@ -11,6 +11,6 @@ fn add(a: i32, b: i32) i32 {...@@ -11,6 +11,6 @@ fn add(a: i32, b: i32) i32 {
11}11}
1212
13const std = @import("std");13const std = @import("std");
14const expect = std.testing.expect;14const expectEqual = std.testing.expectEqual;
1515
16// test16// test
doc/langref/test_defer.zig+3-3
...@@ -1,5 +1,5 @@...@@ -1,5 +1,5 @@
1const std = @import("std");1const std = @import("std");
2const expect = std.testing.expect;2const expectEqual = std.testing.expectEqual;
3const print = std.debug.print;3const print = std.debug.print;
44
5fn deferExample() !usize {5fn deferExample() !usize {
...@@ -9,14 +9,14 @@ fn deferExample() !usize {...@@ -9,14 +9,14 @@ fn deferExample() !usize {
9 defer a = 2;9 defer a = 2;
10 a = 1;10 a = 1;
11 }11 }
12 try expect(a == 2);12 try expectEqual(2, a);
1313
14 a = 5;14 a = 5;
15 return a;15 return a;
16}16}
1717
18test "defer basics" {18test "defer basics" {
19 try expect((try deferExample()) == 5);19 try expectEqual(5, (try deferExample()));
20}20}
2121
22// test22// test
doc/langref/test_empty_block.zig+4-4
...@@ -1,12 +1,12 @@...@@ -1,12 +1,12 @@
1const std = @import("std");1const std = @import("std");
2const expect = std.testing.expect;2const expectEqual = std.testing.expectEqual;
33
4test {4test {
5 const a = {};5 const a = {};
6 const b = void{};6 const b = void{};
7 try expect(@TypeOf(a) == void);7 try expectEqual(void, @TypeOf(a));
8 try expect(@TypeOf(b) == void);8 try expectEqual(void, @TypeOf(b));
9 try expect(a == b);9 try expectEqual(a, b);
10}10}
1111
12// test12// test
doc/langref/test_enum_literals.zig+2-1
...@@ -1,5 +1,6 @@...@@ -1,5 +1,6 @@
1const std = @import("std");1const std = @import("std");
2const expect = std.testing.expect;2const expect = std.testing.expect;
3const expectEqual = std.testing.expectEqual;
34
4const Color = enum {5const Color = enum {
5 auto,6 auto,
...@@ -10,7 +11,7 @@ const Color = enum {...@@ -10,7 +11,7 @@ const Color = enum {
10test "enum literals" {11test "enum literals" {
11 const color1: Color = .auto;12 const color1: Color = .auto;
12 const color2 = Color.auto;13 const color2 = Color.auto;
13 try expect(color1 == color2);14 try expectEqual(color1, color2);
14}15}
1516
16test "switch using enum literals" {17test "switch using enum literals" {
doc/langref/test_enums.zig+18-16
...@@ -1,4 +1,6 @@...@@ -1,4 +1,6 @@
1const expect = @import("std").testing.expect;1const expect = @import("std").testing.expect;
2const expectEqual = @import("std").testing.expectEqual;
3const expectEqualStrings = @import("std").testing.expectEqualStrings;
2const mem = @import("std").mem;4const mem = @import("std").mem;
35
4// Declare an enum.6// Declare an enum.
...@@ -20,9 +22,9 @@ const Value = enum(u2) {...@@ -20,9 +22,9 @@ const Value = enum(u2) {
20// Now you can cast between u2 and Value.22// Now you can cast between u2 and Value.
21// The ordinal value starts from 0, counting up by 1 from the previous member.23// The ordinal value starts from 0, counting up by 1 from the previous member.
22test "enum ordinal value" {24test "enum ordinal value" {
23 try expect(@intFromEnum(Value.zero) == 0);25 try expectEqual(0, @intFromEnum(Value.zero));
24 try expect(@intFromEnum(Value.one) == 1);26 try expectEqual(1, @intFromEnum(Value.one));
25 try expect(@intFromEnum(Value.two) == 2);27 try expectEqual(2, @intFromEnum(Value.two));
26}28}
2729
28// You can override the ordinal value for an enum.30// You can override the ordinal value for an enum.
...@@ -32,9 +34,9 @@ const Value2 = enum(u32) {...@@ -32,9 +34,9 @@ const Value2 = enum(u32) {
32 million = 1000000,34 million = 1000000,
33};35};
34test "set enum ordinal value" {36test "set enum ordinal value" {
35 try expect(@intFromEnum(Value2.hundred) == 100);37 try expectEqual(100, @intFromEnum(Value2.hundred));
36 try expect(@intFromEnum(Value2.thousand) == 1000);38 try expectEqual(1000, @intFromEnum(Value2.thousand));
37 try expect(@intFromEnum(Value2.million) == 1000000);39 try expectEqual(1000000, @intFromEnum(Value2.million));
38}40}
3941
40// You can also override only some values.42// You can also override only some values.
...@@ -46,11 +48,11 @@ const Value3 = enum(u4) {...@@ -46,11 +48,11 @@ const Value3 = enum(u4) {
46 e,48 e,
47};49};
48test "enum implicit ordinal values and overridden values" {50test "enum implicit ordinal values and overridden values" {
49 try expect(@intFromEnum(Value3.a) == 0);51 try expectEqual(0, @intFromEnum(Value3.a));
50 try expect(@intFromEnum(Value3.b) == 8);52 try expectEqual(8, @intFromEnum(Value3.b));
51 try expect(@intFromEnum(Value3.c) == 9);53 try expectEqual(9, @intFromEnum(Value3.c));
52 try expect(@intFromEnum(Value3.d) == 4);54 try expectEqual(4, @intFromEnum(Value3.d));
53 try expect(@intFromEnum(Value3.e) == 5);55 try expectEqual(5, @intFromEnum(Value3.e));
54}56}
5557
56// Enums can have methods, the same as structs and unions.58// Enums can have methods, the same as structs and unions.
...@@ -84,7 +86,7 @@ test "enum switch" {...@@ -84,7 +86,7 @@ test "enum switch" {
84 Foo.number => "this is a number",86 Foo.number => "this is a number",
85 Foo.none => "this is a none",87 Foo.none => "this is a none",
86 };88 };
87 try expect(mem.eql(u8, what_is_it, "this is a number"));89 try expectEqualStrings(what_is_it, "this is a number");
88}90}
8991
90// @typeInfo can be used to access the integer tag type of an enum.92// @typeInfo can be used to access the integer tag type of an enum.
...@@ -95,18 +97,18 @@ const Small = enum {...@@ -95,18 +97,18 @@ const Small = enum {
95 four,97 four,
96};98};
97test "std.meta.Tag" {99test "std.meta.Tag" {
98 try expect(@typeInfo(Small).@"enum".tag_type == u2);100 try expectEqual(u2, @typeInfo(Small).@"enum".tag_type);
99}101}
100102
101// @typeInfo tells us the field count and the fields names:103// @typeInfo tells us the field count and the fields names:
102test "@typeInfo" {104test "@typeInfo" {
103 try expect(@typeInfo(Small).@"enum".fields.len == 4);105 try expectEqual(4, @typeInfo(Small).@"enum".fields.len);
104 try expect(mem.eql(u8, @typeInfo(Small).@"enum".fields[1].name, "two"));106 try expectEqualStrings(@typeInfo(Small).@"enum".fields[1].name, "two");
105}107}
106108
107// @tagName gives a [:0]const u8 representation of an enum value:109// @tagName gives a [:0]const u8 representation of an enum value:
108test "@tagName" {110test "@tagName" {
109 try expect(mem.eql(u8, @tagName(Small.three), "three"));111 try expectEqualStrings(@tagName(Small.three), "three");
110}112}
111113
112// test114// test
doc/langref/test_error_union.zig+3-3
...@@ -1,4 +1,4 @@...@@ -1,4 +1,4 @@
1const expect = @import("std").testing.expect;1const expectEqual = @import("std").testing.expectEqual;
22
3test "error union" {3test "error union" {
4 var foo: anyerror!i32 = undefined;4 var foo: anyerror!i32 = undefined;
...@@ -10,10 +10,10 @@ test "error union" {...@@ -10,10 +10,10 @@ test "error union" {
10 foo = error.SomeError;10 foo = error.SomeError;
1111
12 // Use compile-time reflection to access the payload type of an error union:12 // 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
15 // Use compile-time reflection to access the error set type of an error union:15 // 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);
17}17}
1818
19// test19// test
doc/langref/test_fibonacci_comptime_overflow.zig+2-2
...@@ -1,4 +1,4 @@...@@ -1,4 +1,4 @@
1const expect = @import("std").testing.expect;1const expectEqual = @import("std").testing.expectEqual;
22
3fn fibonacci(index: u32) u32 {3fn fibonacci(index: u32) u32 {
4 //if (index < 2) return index;4 //if (index < 2) return index;
...@@ -6,7 +6,7 @@ fn fibonacci(index: u32) u32 {...@@ -6,7 +6,7 @@ fn fibonacci(index: u32) u32 {
6}6}
77
8test "fibonacci" {8test "fibonacci" {
9 try comptime expect(fibonacci(7) == 13);9 try comptime expectEqual(13, fibonacci(7));
10}10}
1111
12// test_error=overflow of integer type12// test_error=overflow of integer type
doc/langref/test_fibonacci_recursion.zig+3-3
...@@ -1,4 +1,4 @@...@@ -1,4 +1,4 @@
1const expect = @import("std").testing.expect;1const expectEqual = @import("std").testing.expectEqual;
22
3fn fibonacci(index: u32) u32 {3fn fibonacci(index: u32) u32 {
4 if (index < 2) return index;4 if (index < 2) return index;
...@@ -7,10 +7,10 @@ fn fibonacci(index: u32) u32 {...@@ -7,10 +7,10 @@ fn fibonacci(index: u32) u32 {
77
8test "fibonacci" {8test "fibonacci" {
9 // test fibonacci at run-time9 // test fibonacci at run-time
10 try expect(fibonacci(7) == 13);10 try expectEqual(13, fibonacci(7));
1111
12 // test fibonacci at compile-time12 // test fibonacci at compile-time
13 try comptime expect(fibonacci(7) == 13);13 try comptime expectEqual(13, fibonacci(7));
14}14}
1515
16// test16// test
doc/langref/test_field_builtin.zig+5-7
...@@ -1,4 +1,5 @@...@@ -1,4 +1,5 @@
1const std = @import("std");1const std = @import("std");
2const expectEqual = std.testing.expectEqual;
23
3const Point = struct {4const Point = struct {
4 x: u32,5 x: u32,
...@@ -8,23 +9,20 @@ const Point = struct {...@@ -8,23 +9,20 @@ const Point = struct {
8};9};
910
10test "field access by string" {11test "field access by string" {
11 const expect = std.testing.expect;
12 var p = Point{ .x = 0, .y = 0 };12 var p = Point{ .x = 0, .y = 0 };
1313
14 @field(p, "x") = 4;14 @field(p, "x") = 4;
15 @field(p, "y") = @field(p, "x") + 1;15 @field(p, "y") = @field(p, "x") + 1;
1616
17 try expect(@field(p, "x") == 4);17 try expectEqual(4, @field(p, "x"));
18 try expect(@field(p, "y") == 5);18 try expectEqual(5, @field(p, "y"));
19}19}
2020
21test "decl access by string" {21test "decl access by string" {
22 const expect = std.testing.expect;22 try expectEqual(1, @field(Point, "z"));
23
24 try expect(@field(Point, "z") == 1);
2523
26 @field(Point, "z") = 2;24 @field(Point, "z") = 2;
27 try expect(@field(Point, "z") == 2);25 try expectEqual(2, @field(Point, "z"));
28}26}
2927
30// test28// test
doc/langref/test_fn_reflection.zig+2-2
...@@ -3,8 +3,8 @@ const math = std.math;...@@ -3,8 +3,8 @@ const math = std.math;
3const testing = std.testing;3const testing = std.testing;
44
5test "fn reflection" {5test "fn reflection" {
6 try testing.expect(@typeInfo(@TypeOf(testing.expect)).@"fn".params[0].type.? == bool);6 try testing.expectEqual(bool, @typeInfo(@TypeOf(testing.expect)).@"fn".params[0].type.?);
7 try testing.expect(@typeInfo(@TypeOf(testing.tmpDir)).@"fn".return_type.? == testing.TmpDir);7 try testing.expectEqual(testing.TmpDir, @typeInfo(@TypeOf(testing.tmpDir)).@"fn".return_type.?);
88
9 try testing.expect(@typeInfo(@TypeOf(math.Log2Int)).@"fn".is_generic);9 try testing.expect(@typeInfo(@TypeOf(math.Log2Int)).@"fn".is_generic);
10}10}
doc/langref/test_fn_type_inference.zig+5-5
...@@ -1,15 +1,15 @@...@@ -1,15 +1,15 @@
1const expect = @import("std").testing.expect;1const expectEqual = @import("std").testing.expectEqual;
22
3fn addFortyTwo(x: anytype) @TypeOf(x) {3fn addFortyTwo(x: anytype) @TypeOf(x) {
4 return x + 42;4 return x + 42;
5}5}
66
7test "fn type inference" {7test "fn type inference" {
8 try expect(addFortyTwo(1) == 43);8 try expectEqual(43, addFortyTwo(1));
9 try expect(@TypeOf(addFortyTwo(1)) == comptime_int);9 try expectEqual(comptime_int, @TypeOf(addFortyTwo(1)));
10 const y: i64 = 2;10 const y: i64 = 2;
11 try expect(addFortyTwo(y) == 44);11 try expectEqual(44, addFortyTwo(y));
12 try expect(@TypeOf(addFortyTwo(y)) == i64);12 try expectEqual(i64, @TypeOf(addFortyTwo(y)));
13}13}
1414
15// test15// test
doc/langref/test_for.zig+12-12
...@@ -1,4 +1,4 @@...@@ -1,4 +1,4 @@
1const expect = @import("std").testing.expect;1const expectEqual = @import("std").testing.expectEqual;
22
3test "for basics" {3test "for basics" {
4 const items = [_]i32{ 4, 5, 3, 4, 0 };4 const items = [_]i32{ 4, 5, 3, 4, 0 };
...@@ -12,22 +12,22 @@ test "for basics" {...@@ -12,22 +12,22 @@ test "for basics" {
12 }12 }
13 sum += value;13 sum += value;
14 }14 }
15 try expect(sum == 16);15 try expectEqual(16, sum);
1616
17 // To iterate over a portion of a slice, reslice.17 // To iterate over a portion of a slice, reslice.
18 for (items[0..1]) |value| {18 for (items[0..1]) |value| {
19 sum += value;19 sum += value;
20 }20 }
21 try expect(sum == 20);21 try expectEqual(20, sum);
2222
23 // To access the index of iteration, specify a second condition as well23 // To access the index of iteration, specify a second condition as well
24 // as a second capture value.24 // as a second capture value.
25 var sum2: i32 = 0;25 var sum2: i32 = 0;
26 for (items, 0..) |_, i| {26 for (items, 0..) |_, i| {
27 try expect(@TypeOf(i) == usize);27 try expectEqual(usize, @TypeOf(i));
28 sum2 += @as(i32, @intCast(i));28 sum2 += @as(i32, @intCast(i));
29 }29 }
30 try expect(sum2 == 10);30 try expectEqual(10, sum2);
3131
32 // To iterate over consecutive integers, use the range syntax.32 // To iterate over consecutive integers, use the range syntax.
33 // Unbounded range is always a compile error.33 // Unbounded range is always a compile error.
...@@ -35,7 +35,7 @@ test "for basics" {...@@ -35,7 +35,7 @@ test "for basics" {
35 for (0..5) |i| {35 for (0..5) |i| {
36 sum3 += i;36 sum3 += i;
37 }37 }
38 try expect(sum3 == 10);38 try expectEqual(10, sum3);
39}39}
4040
41test "multi object for" {41test "multi object for" {
...@@ -50,7 +50,7 @@ test "multi object for" {...@@ -50,7 +50,7 @@ test "multi object for" {
50 count += i + j;50 count += i + j;
51 }51 }
5252
53 try expect(count == 21);53 try expectEqual(21, count);
54}54}
5555
56test "for reference" {56test "for reference" {
...@@ -62,9 +62,9 @@ test "for reference" {...@@ -62,9 +62,9 @@ test "for reference" {
62 value.* += 1;62 value.* += 1;
63 }63 }
6464
65 try expect(items[0] == 4);65 try expectEqual(4, items[0]);
66 try expect(items[1] == 5);66 try expectEqual(5, items[1]);
67 try expect(items[2] == 3);67 try expectEqual(3, items[2]);
68}68}
6969
70test "for else" {70test "for else" {
...@@ -79,10 +79,10 @@ test "for else" {...@@ -79,10 +79,10 @@ test "for else" {
79 sum += value.?;79 sum += value.?;
80 }80 }
81 } else blk: {81 } else blk: {
82 try expect(sum == 12);82 try expectEqual(12, sum);
83 break :blk sum;83 break :blk sum;
84 };84 };
85 try expect(result == 12);85 try expectEqual(12, result);
86}86}
8787
88// test88// test
doc/langref/test_for_nested_break.zig+3-3
...@@ -1,5 +1,5 @@...@@ -1,5 +1,5 @@
1const std = @import("std");1const std = @import("std");
2const expect = std.testing.expect;2const expectEqual = std.testing.expectEqual;
33
4test "nested break" {4test "nested break" {
5 var count: usize = 0;5 var count: usize = 0;
...@@ -9,7 +9,7 @@ test "nested break" {...@@ -9,7 +9,7 @@ test "nested break" {
9 break :outer;9 break :outer;
10 }10 }
11 }11 }
12 try expect(count == 1);12 try expectEqual(1, count);
13}13}
1414
15test "nested continue" {15test "nested continue" {
...@@ -21,7 +21,7 @@ test "nested continue" {...@@ -21,7 +21,7 @@ test "nested continue" {
21 }21 }
22 }22 }
2323
24 try expect(count == 8);24 try expectEqual(8, count);
25}25}
2626
27// test27// test
doc/langref/test_functions.zig+3-3
...@@ -1,7 +1,7 @@...@@ -1,7 +1,7 @@
1const std = @import("std");1const std = @import("std");
2const builtin = @import("builtin");2const builtin = @import("builtin");
3const native_arch = builtin.cpu.arch;3const native_arch = builtin.cpu.arch;
4const expect = std.testing.expect;4const expectEqual = std.testing.expectEqual;
55
6// Functions are declared like this6// Functions are declared like this
7fn add(a: i8, b: i8) i8 {7fn add(a: i8, b: i8) i8 {
...@@ -57,8 +57,8 @@ fn doOp(fnCall: Call2Op, op1: i8, op2: i8) i8 {...@@ -57,8 +57,8 @@ fn doOp(fnCall: Call2Op, op1: i8, op2: i8) i8 {
57}57}
5858
59test "function" {59test "function" {
60 try expect(doOp(add, 5, 6) == 11);60 try expectEqual(11, doOp(add, 5, 6));
61 try expect(doOp(sub2, 5, 6) == -1);61 try expectEqual(-1, doOp(sub2, 5, 6));
62}62}
6363
64// test64// test
doc/langref/test_global_assembly.zig+2-2
...@@ -1,5 +1,5 @@...@@ -1,5 +1,5 @@
1const std = @import("std");1const std = @import("std");
2const expect = std.testing.expect;2const expectEqual = std.testing.expectEqual;
33
4comptime {4comptime {
5 asm (5 asm (
...@@ -14,7 +14,7 @@ comptime {...@@ -14,7 +14,7 @@ comptime {
14extern fn my_func(a: i32, b: i32) i32;14extern fn my_func(a: i32, b: i32) i32;
1515
16test "global assembly" {16test "global assembly" {
17 try expect(my_func(12, 34) == 46);17 try expectEqual(46, my_func(12, 34));
18}18}
1919
20// test20// test
doc/langref/test_if.zig+7-6
...@@ -4,13 +4,14 @@...@@ -4,13 +4,14 @@
4// * anyerror!T4// * anyerror!T
55
6const expect = @import("std").testing.expect;6const expect = @import("std").testing.expect;
7const expectEqual = @import("std").testing.expectEqual;
78
8test "if expression" {9test "if expression" {
9 // If expressions are used instead of a ternary expression.10 // If expressions are used instead of a ternary expression.
10 const a: u32 = 5;11 const a: u32 = 5;
11 const b: u32 = 4;12 const b: u32 = 4;
12 const result = if (a != b) 47 else 3089;13 const result = if (a != b) 47 else 3089;
13 try expect(result == 47);14 try expectEqual(result, 47);
14}15}
1516
16test "if boolean" {17test "if boolean" {
...@@ -32,7 +33,7 @@ test "if error union" {...@@ -32,7 +33,7 @@ test "if error union" {
3233
33 const a: anyerror!u32 = 0;34 const a: anyerror!u32 = 0;
34 if (a) |value| {35 if (a) |value| {
35 try expect(value == 0);36 try expectEqual(value, 0);
36 } else |err| {37 } else |err| {
37 _ = err;38 _ = err;
38 unreachable;39 unreachable;
...@@ -43,17 +44,17 @@ test "if error union" {...@@ -43,17 +44,17 @@ test "if error union" {
43 _ = value;44 _ = value;
44 unreachable;45 unreachable;
45 } else |err| {46 } else |err| {
46 try expect(err == error.BadValue);47 try expectEqual(err, error.BadValue);
47 }48 }
4849
49 // The else and |err| capture is strictly required.50 // The else and |err| capture is strictly required.
50 if (a) |value| {51 if (a) |value| {
51 try expect(value == 0);52 try expectEqual(value, 0);
52 } else |_| {}53 } else |_| {}
5354
54 // To check only the error value, use an empty block expression.55 // To check only the error value, use an empty block expression.
55 if (b) |_| {} else |err| {56 if (b) |_| {} else |err| {
56 try expect(err == error.BadValue);57 try expectEqual(err, error.BadValue);
57 }58 }
5859
59 // Access the value by reference using a pointer capture.60 // Access the value by reference using a pointer capture.
...@@ -65,7 +66,7 @@ test "if error union" {...@@ -65,7 +66,7 @@ test "if error union" {
65 }66 }
6667
67 if (c) |value| {68 if (c) |value| {
68 try expect(value == 9);69 try expectEqual(value, 9);
69 } else |_| {70 } else |_| {
70 unreachable;71 unreachable;
71 }72 }
doc/langref/test_if_optionals.zig+8-7
...@@ -1,11 +1,12 @@...@@ -1,11 +1,12 @@
1const expect = @import("std").testing.expect;1const expect = @import("std").testing.expect;
2const expectEqual = @import("std").testing.expectEqual;
23
3test "if optional" {4test "if optional" {
4 // If expressions test for null.5 // If expressions test for null.
56
6 const a: ?u32 = 0;7 const a: ?u32 = 0;
7 if (a) |value| {8 if (a) |value| {
8 try expect(value == 0);9 try expectEqual(0, value);
9 } else {10 } else {
10 unreachable;11 unreachable;
11 }12 }
...@@ -19,7 +20,7 @@ test "if optional" {...@@ -19,7 +20,7 @@ test "if optional" {
1920
20 // The else is not required.21 // The else is not required.
21 if (a) |value| {22 if (a) |value| {
22 try expect(value == 0);23 try expectEqual(0, value);
23 }24 }
2425
25 // To test against null only, use the binary equality operator.26 // To test against null only, use the binary equality operator.
...@@ -34,7 +35,7 @@ test "if optional" {...@@ -34,7 +35,7 @@ test "if optional" {
34 }35 }
3536
36 if (c) |value| {37 if (c) |value| {
37 try expect(value == 2);38 try expectEqual(2, value);
38 } else {39 } else {
39 unreachable;40 unreachable;
40 }41 }
...@@ -46,7 +47,7 @@ test "if error union with optional" {...@@ -46,7 +47,7 @@ test "if error union with optional" {
4647
47 const a: anyerror!?u32 = 0;48 const a: anyerror!?u32 = 0;
48 if (a) |optional_value| {49 if (a) |optional_value| {
49 try expect(optional_value.? == 0);50 try expectEqual(0, optional_value.?);
50 } else |err| {51 } else |err| {
51 _ = err;52 _ = err;
52 unreachable;53 unreachable;
...@@ -54,7 +55,7 @@ test "if error union with optional" {...@@ -54,7 +55,7 @@ test "if error union with optional" {
5455
55 const b: anyerror!?u32 = null;56 const b: anyerror!?u32 = null;
56 if (b) |optional_value| {57 if (b) |optional_value| {
57 try expect(optional_value == null);58 try expectEqual(null, optional_value);
58 } else |_| {59 } else |_| {
59 unreachable;60 unreachable;
60 }61 }
...@@ -64,7 +65,7 @@ test "if error union with optional" {...@@ -64,7 +65,7 @@ test "if error union with optional" {
64 _ = optional_value;65 _ = optional_value;
65 unreachable;66 unreachable;
66 } else |err| {67 } else |err| {
67 try expect(err == error.BadValue);68 try expectEqual(error.BadValue, err);
68 }69 }
6970
70 // Access the value by reference by using a pointer capture each time.71 // Access the value by reference by using a pointer capture each time.
...@@ -78,7 +79,7 @@ test "if error union with optional" {...@@ -78,7 +79,7 @@ test "if error union with optional" {
78 }79 }
7980
80 if (d) |optional_value| {81 if (d) |optional_value| {
81 try expect(optional_value.? == 9);82 try expectEqual(9, optional_value.?);
82 } else |_| {83 } else |_| {
83 unreachable;84 unreachable;
84 }85 }
doc/langref/test_incorrect_pointer_alignment.zig+1-1
...@@ -3,7 +3,7 @@ const std = @import("std");...@@ -3,7 +3,7 @@ const std = @import("std");
3test "pointer alignment safety" {3test "pointer alignment safety" {
4 var array align(4) = [_]u32{ 0x11111111, 0x11111111 };4 var array align(4) = [_]u32{ 0x11111111, 0x11111111 };
5 const bytes = std.mem.sliceAsBytes(array[0..]);5 const bytes = std.mem.sliceAsBytes(array[0..]);
6 try std.testing.expect(foo(bytes) == 0x11111111);6 try std.testing.expectEqual(0x11111111, foo(bytes));
7}7}
8fn foo(bytes: []u8) u32 {8fn foo(bytes: []u8) u32 {
9 const slice4 = bytes[1..5];9 const slice4 = bytes[1..5];
doc/langref/test_inline_else.zig+3-3
...@@ -1,5 +1,5 @@...@@ -1,5 +1,5 @@
1const std = @import("std");1const std = @import("std");
2const expect = std.testing.expect;2const expectEqual = std.testing.expectEqual;
33
4const SliceTypeA = extern struct {4const SliceTypeA = extern struct {
5 len: usize,5 len: usize,
...@@ -42,8 +42,8 @@ fn withSwitch(any: AnySlice) usize {...@@ -42,8 +42,8 @@ fn withSwitch(any: AnySlice) usize {
4242
43test "inline for and inline else similarity" {43test "inline for and inline else similarity" {
44 const any = AnySlice{ .c = "hello" };44 const any = AnySlice{ .c = "hello" };
45 try expect(withFor(any) == 5);45 try expectEqual(5, withFor(any));
46 try expect(withSwitch(any) == 5);46 try expectEqual(5, withSwitch(any));
47}47}
4848
49// test49// test
doc/langref/test_inline_for.zig+2-2
...@@ -1,4 +1,4 @@...@@ -1,4 +1,4 @@
1const expect = @import("std").testing.expect;1const expectEqual = @import("std").testing.expectEqual;
22
3test "inline for loop" {3test "inline for loop" {
4 const nums = [_]i32{ 2, 4, 6 };4 const nums = [_]i32{ 2, 4, 6 };
...@@ -12,7 +12,7 @@ test "inline for loop" {...@@ -12,7 +12,7 @@ test "inline for loop" {
12 };12 };
13 sum += typeNameLength(T);13 sum += typeNameLength(T);
14 }14 }
15 try expect(sum == 9);15 try expectEqual(9, sum);
16}16}
1717
18fn typeNameLength(comptime T: type) usize {18fn typeNameLength(comptime T: type) usize {
doc/langref/test_inline_switch_union_tag.zig+2-2
...@@ -1,5 +1,5 @@...@@ -1,5 +1,5 @@
1const std = @import("std");1const std = @import("std");
2const expect = std.testing.expect;2const expectEqual = std.testing.expectEqual;
33
4const U = union(enum) {4const U = union(enum) {
5 a: u32,5 a: u32,
...@@ -21,7 +21,7 @@ fn getNum(u: U) u32 {...@@ -21,7 +21,7 @@ fn getNum(u: U) u32 {
2121
22test "test" {22test "test" {
23 const u = U{ .b = 42 };23 const u = U{ .b = 42 };
24 try expect(getNum(u) == 42);24 try expectEqual(42, getNum(u));
25}25}
2626
27// test27// test
doc/langref/test_inline_while.zig+2-2
...@@ -1,4 +1,4 @@...@@ -1,4 +1,4 @@
1const expect = @import("std").testing.expect;1const expectEqual = @import("std").testing.expectEqual;
22
3test "inline while loop" {3test "inline while loop" {
4 comptime var i = 0;4 comptime var i = 0;
...@@ -12,7 +12,7 @@ test "inline while loop" {...@@ -12,7 +12,7 @@ test "inline while loop" {
12 };12 };
13 sum += typeNameLength(T);13 sum += typeNameLength(T);
14 }14 }
15 try expect(sum == 9);15 try expectEqual(9, sum);
16}16}
1717
18fn typeNameLength(comptime T: type) usize {18fn typeNameLength(comptime T: type) usize {
doc/langref/test_integer_pointer_conversion.zig+3-3
...@@ -1,10 +1,10 @@...@@ -1,10 +1,10 @@
1const expect = @import("std").testing.expect;1const expectEqual = @import("std").testing.expectEqual;
22
3test "@intFromPtr and @ptrFromInt" {3test "@intFromPtr and @ptrFromInt" {
4 const ptr: *i32 = @ptrFromInt(0xdeadbee0);4 const ptr: *i32 = @ptrFromInt(0xdeadbee0);
5 const addr = @intFromPtr(ptr);5 const addr = @intFromPtr(ptr);
6 try expect(@TypeOf(addr) == usize);6 try expectEqual(usize, @TypeOf(addr));
7 try expect(addr == 0xdeadbee0);7 try expectEqual(0xdeadbee0, addr);
8}8}
99
10// test10// test
doc/langref/test_integer_widening.zig+4-4
...@@ -1,6 +1,6 @@...@@ -1,6 +1,6 @@
1const std = @import("std");1const std = @import("std");
2const builtin = @import("builtin");2const builtin = @import("builtin");
3const expect = std.testing.expect;3const expectEqual = std.testing.expectEqual;
4const mem = std.mem;4const mem = std.mem;
55
6test "integer widening" {6test "integer widening" {
...@@ -10,13 +10,13 @@ test "integer widening" {...@@ -10,13 +10,13 @@ test "integer widening" {
10 const d: u64 = c;10 const d: u64 = c;
11 const e: u64 = d;11 const e: u64 = d;
12 const f: u128 = e;12 const f: u128 = e;
13 try expect(f == a);13 try expectEqual(f, a);
14}14}
1515
16test "implicit unsigned integer to signed integer" {16test "implicit unsigned integer to signed integer" {
17 const a: u8 = 250;17 const a: u8 = 250;
18 const b: i16 = a;18 const b: i16 = a;
19 try expect(b == 250);19 try expectEqual(250, b);
20}20}
2121
22test "float widening" {22test "float widening" {
...@@ -24,7 +24,7 @@ test "float widening" {...@@ -24,7 +24,7 @@ test "float widening" {
24 const b: f32 = a;24 const b: f32 = a;
25 const c: f64 = b;25 const c: f64 = b;
26 const d: f128 = c;26 const d: f128 = c;
27 try expect(d == a);27 try expectEqual(d, a);
28}28}
2929
30// test30// test
doc/langref/test_labeled_break.zig+3-3
...@@ -1,5 +1,5 @@...@@ -1,5 +1,5 @@
1const std = @import("std");1const std = @import("std");
2const expect = std.testing.expect;2const expectEqual = std.testing.expectEqual;
33
4test "labeled break from labeled block expression" {4test "labeled break from labeled block expression" {
5 var y: i32 = 123;5 var y: i32 = 123;
...@@ -8,8 +8,8 @@ test "labeled break from labeled block expression" {...@@ -8,8 +8,8 @@ test "labeled break from labeled block expression" {
8 y += 1;8 y += 1;
9 break :blk y;9 break :blk y;
10 };10 };
11 try expect(x == 124);11 try expectEqual(124, x);
12 try expect(y == 124);12 try expectEqual(124, y);
13}13}
1414
15// test15// test
doc/langref/test_misaligned_pointer.zig+2-2
...@@ -1,5 +1,5 @@...@@ -1,5 +1,5 @@
1const std = @import("std");1const std = @import("std");
2const expect = std.testing.expect;2const expectEqual = std.testing.expectEqual;
33
4const BitField = packed struct {4const BitField = packed struct {
5 a: u3,5 a: u3,
...@@ -14,7 +14,7 @@ var bit_field = BitField{...@@ -14,7 +14,7 @@ var bit_field = BitField{
14};14};
1515
16test "pointer to non-byte-aligned field" {16test "pointer to non-byte-aligned field" {
17 try expect(bar(&bit_field.b) == 2);17 try expectEqual(2, bar(&bit_field.b));
18}18}
1919
20fn bar(x: *const u3) u3 {20fn bar(x: *const u3) u3 {
doc/langref/test_multidimensional_arrays.zig+3-4
...@@ -1,5 +1,4 @@...@@ -1,5 +1,4 @@
1const std = @import("std");1const std = @import("std");
2const expect = std.testing.expect;
3const expectEqual = std.testing.expectEqual;2const expectEqual = std.testing.expectEqual;
43
5const mat4x5 = [4][5]f32{4const mat4x5 = [4][5]f32{
...@@ -13,20 +12,20 @@ test "multidimensional arrays" {...@@ -13,20 +12,20 @@ test "multidimensional arrays" {
13 try expectEqual(mat4x5[1], [_]f32{ 0.0, 1.0, 0.0, 1.0, 0.0 });12 try expectEqual(mat4x5[1], [_]f32{ 0.0, 1.0, 0.0, 1.0, 0.0 });
1413
15 // Access the 2D array by indexing the outer array, and then the inner array.14 // 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
18 // Here we iterate with for loops.17 // Here we iterate with for loops.
19 for (mat4x5, 0..) |row, row_index| {18 for (mat4x5, 0..) |row, row_index| {
20 for (row, 0..) |cell, column_index| {19 for (row, 0..) |cell, column_index| {
21 if (row_index == column_index) {20 if (row_index == column_index) {
22 try expect(cell == 1.0);21 try expectEqual(1.0, cell);
23 }22 }
24 }23 }
25 }24 }
2625
27 // Initialize a multidimensional array to zeros.26 // Initialize a multidimensional array to zeros.
28 const all_zero: [4][5]f32 = .{.{0} ** 5} ** 4;27 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]);
30}29}
3130
32// test31// test
doc/langref/test_namespaced_container_level_variable.zig+3-3
...@@ -1,9 +1,9 @@...@@ -1,9 +1,9 @@
1const std = @import("std");1const std = @import("std");
2const expect = std.testing.expect;2const expectEqual = std.testing.expectEqual;
33
4test "namespaced container level variable" {4test "namespaced container level variable" {
5 try expect(foo() == 1235);5 try expectEqual(1235, foo());
6 try expect(foo() == 1236);6 try expectEqual(1236, foo());
7}7}
88
9const S = struct {9const S = struct {
doc/langref/test_noreturn_from_exit.zig+2-2
...@@ -1,14 +1,14 @@...@@ -1,14 +1,14 @@
1const std = @import("std");1const std = @import("std");
2const builtin = @import("builtin");2const builtin = @import("builtin");
3const native_arch = builtin.cpu.arch;3const native_arch = builtin.cpu.arch;
4const expect = std.testing.expect;4const expectEqual = std.testing.expectEqual;
55
6const WINAPI: std.builtin.CallingConvention = if (native_arch == .x86) .{ .x86_stdcall = .{} } else .c;6const WINAPI: std.builtin.CallingConvention = if (native_arch == .x86) .{ .x86_stdcall = .{} } else .c;
7extern "kernel32" fn ExitProcess(exit_code: c_uint) callconv(WINAPI) noreturn;7extern "kernel32" fn ExitProcess(exit_code: c_uint) callconv(WINAPI) noreturn;
88
9test "foo" {9test "foo" {
10 const value = bar() catch ExitProcess(1);10 const value = bar() catch ExitProcess(1);
11 try expect(value == 1234);11 try expectEqual(1234, value);
12}12}
1313
14fn bar() anyerror!u32 {14fn bar() anyerror!u32 {
doc/langref/test_null_terminated_array.zig+7-7
...@@ -1,21 +1,21 @@...@@ -1,21 +1,21 @@
1const std = @import("std");1const std = @import("std");
2const expect = std.testing.expect;2const expectEqual = std.testing.expectEqual;
33
4test "0-terminated sentinel array" {4test "0-terminated sentinel array" {
5 const array = [_:0]u8{ 1, 2, 3, 4 };5 const array = [_:0]u8{ 1, 2, 3, 4 };
66
7 try expect(@TypeOf(array) == [4:0]u8);7 try expectEqual([4:0]u8, @TypeOf(array));
8 try expect(array.len == 4);8 try expectEqual(4, array.len);
9 try expect(array[4] == 0);9 try expectEqual(0, array[4]);
10}10}
1111
12test "extra 0s in 0-terminated sentinel array" {12test "extra 0s in 0-terminated sentinel array" {
13 // The sentinel value may appear earlier, but does not influence the compile-time 'len'.13 // The sentinel value may appear earlier, but does not influence the compile-time 'len'.
14 const array = [_:0]u8{ 1, 0, 0, 4 };14 const array = [_:0]u8{ 1, 0, 0, 4 };
1515
16 try expect(@TypeOf(array) == [4:0]u8);16 try expectEqual([4:0]u8, @TypeOf(array));
17 try expect(array.len == 4);17 try expectEqual(4, array.len);
18 try expect(array[4] == 0);18 try expectEqual(0, array[4]);
19}19}
2020
21// test21// test
doc/langref/test_null_terminated_slice.zig+3-3
...@@ -1,11 +1,11 @@...@@ -1,11 +1,11 @@
1const std = @import("std");1const std = @import("std");
2const expect = std.testing.expect;2const expectEqual = std.testing.expectEqual;
33
4test "0-terminated slice" {4test "0-terminated slice" {
5 const slice: [:0]const u8 = "hello";5 const slice: [:0]const u8 = "hello";
66
7 try expect(slice.len == 5);7 try expectEqual(5, slice.len);
8 try expect(slice[5] == 0);8 try expectEqual(0, slice[5]);
9}9}
1010
11// test11// test
doc/langref/test_null_terminated_slicing.zig+3-3
...@@ -1,5 +1,5 @@...@@ -1,5 +1,5 @@
1const std = @import("std");1const std = @import("std");
2const expect = std.testing.expect;2const expectEqual = std.testing.expectEqual;
33
4test "0-terminated slicing" {4test "0-terminated slicing" {
5 var array = [_]u8{ 3, 2, 1, 0, 3, 2, 1, 0 };5 var array = [_]u8{ 3, 2, 1, 0, 3, 2, 1, 0 };
...@@ -7,8 +7,8 @@ test "0-terminated slicing" {...@@ -7,8 +7,8 @@ test "0-terminated slicing" {
7 _ = &runtime_length;7 _ = &runtime_length;
8 const slice = array[0..runtime_length :0];8 const slice = array[0..runtime_length :0];
99
10 try expect(@TypeOf(slice) == [:0]u8);10 try expectEqual([:0]u8, @TypeOf(slice));
11 try expect(slice.len == 3);11 try expectEqual(3, slice.len);
12}12}
1313
14// test14// test
doc/langref/test_optional_pointer.zig+3-3
...@@ -1,4 +1,4 @@...@@ -1,4 +1,4 @@
1const expect = @import("std").testing.expect;1const expectEqual = @import("std").testing.expectEqual;
22
3test "optional pointers" {3test "optional pointers" {
4 // Pointers cannot be null. If you want a null pointer, use the optional4 // Pointers cannot be null. If you want a null pointer, use the optional
...@@ -8,11 +8,11 @@ test "optional pointers" {...@@ -8,11 +8,11 @@ test "optional pointers" {
8 var x: i32 = 1;8 var x: i32 = 1;
9 ptr = &x;9 ptr = &x;
1010
11 try expect(ptr.?.* == 1);11 try expectEqual(1, ptr.?.*);
1212
13 // Optional pointers are the same size as normal pointers, because pointer13 // Optional pointers are the same size as normal pointers, because pointer
14 // value 0 is used as the null value.14 // value 0 is used as the null value.
15 try expect(@sizeOf(?*i32) == @sizeOf(*i32));15 try expectEqual(@sizeOf(?*i32), @sizeOf(*i32));
16}16}
1717
18// test18// test
doc/langref/test_optional_type.zig+2-2
...@@ -1,4 +1,4 @@...@@ -1,4 +1,4 @@
1const expect = @import("std").testing.expect;1const expectEqual = @import("std").testing.expectEqual;
22
3test "optional type" {3test "optional type" {
4 // Declare an optional and coerce from null:4 // Declare an optional and coerce from null:
...@@ -8,7 +8,7 @@ test "optional type" {...@@ -8,7 +8,7 @@ test "optional type" {
8 foo = 1234;8 foo = 1234;
99
10 // Use compile-time reflection to access the child type of the optional:10 // 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);
12}12}
1313
14// test14// test
doc/langref/test_overaligned_packed_struct.zig+2-2
...@@ -1,5 +1,5 @@...@@ -1,5 +1,5 @@
1const std = @import("std");1const std = @import("std");
2const expect = std.testing.expect;2const expectEqual = std.testing.expectEqual;
33
4const S = packed struct {4const S = packed struct {
5 a: u32,5 a: u32,
...@@ -9,7 +9,7 @@ test "overaligned pointer to packed struct" {...@@ -9,7 +9,7 @@ test "overaligned pointer to packed struct" {
9 var foo: S align(4) = .{ .a = 1, .b = 2 };9 var foo: S align(4) = .{ .a = 1, .b = 2 };
10 const ptr: *align(4) S = &foo;10 const ptr: *align(4) S = &foo;
11 const ptr_to_b = &ptr.b;11 const ptr_to_b = &ptr.b;
12 try expect(ptr_to_b.* == 2);12 try expectEqual(2, ptr_to_b.*);
13}13}
1414
15// test15// test
doc/langref/test_packed_struct_equality.zig+2-2
...@@ -1,5 +1,5 @@...@@ -1,5 +1,5 @@
1const std = @import("std");1const std = @import("std");
2const expect = std.testing.expect;2const expectEqual = std.testing.expectEqual;
33
4test "packed struct equality" {4test "packed struct equality" {
5 const S = packed struct {5 const S = packed struct {
...@@ -8,7 +8,7 @@ test "packed struct equality" {...@@ -8,7 +8,7 @@ test "packed struct equality" {
8 };8 };
9 const x: S = .{ .a = 1, .b = 2 };9 const x: S = .{ .a = 1, .b = 2 };
10 const y: S = .{ .b = 2, .a = 1 };10 const y: S = .{ .b = 2, .a = 1 };
11 try expect(x == y);11 try expectEqual(x, y);
12}12}
1313
14// test14// test
doc/langref/test_packed_struct_field_address.zig+3-3
...@@ -1,5 +1,5 @@...@@ -1,5 +1,5 @@
1const std = @import("std");1const std = @import("std");
2const expect = std.testing.expect;2const expectEqual = std.testing.expectEqual;
33
4const BitField = packed struct {4const BitField = packed struct {
5 a: u3,5 a: u3,
...@@ -14,8 +14,8 @@ var bit_field = BitField{...@@ -14,8 +14,8 @@ var bit_field = BitField{
14};14};
1515
16test "pointers of sub-byte-aligned fields share addresses" {16test "pointers of sub-byte-aligned fields share addresses" {
17 try expect(@intFromPtr(&bit_field.a) == @intFromPtr(&bit_field.b));17 try expectEqual(@intFromPtr(&bit_field.a), @intFromPtr(&bit_field.b));
18 try expect(@intFromPtr(&bit_field.a) == @intFromPtr(&bit_field.c));18 try expectEqual(@intFromPtr(&bit_field.a), @intFromPtr(&bit_field.c));
19}19}
2020
21// test21// test
doc/langref/test_packed_structs.zig+10-10
...@@ -1,6 +1,6 @@...@@ -1,6 +1,6 @@
1const std = @import("std");1const std = @import("std");
2const native_endian = @import("builtin").target.cpu.arch.endian();2const native_endian = @import("builtin").target.cpu.arch.endian();
3const expect = std.testing.expect;3const expectEqual = std.testing.expectEqual;
44
5const Full = packed struct {5const Full = packed struct {
6 number: u16,6 number: u16,
...@@ -17,23 +17,23 @@ test "@bitCast between packed structs" {...@@ -17,23 +17,23 @@ test "@bitCast between packed structs" {
17}17}
1818
19fn doTheTest() !void {19fn doTheTest() !void {
20 try expect(@sizeOf(Full) == 2);20 try expectEqual(2, @sizeOf(Full));
21 try expect(@sizeOf(Divided) == 2);21 try expectEqual(2, @sizeOf(Divided));
22 const full = Full{ .number = 0x1234 };22 const full = Full{ .number = 0x1234 };
23 const divided: Divided = @bitCast(full);23 const divided: Divided = @bitCast(full);
24 try expect(divided.half1 == 0x34);24 try expectEqual(0x34, divided.half1);
25 try expect(divided.quarter3 == 0x2);25 try expectEqual(0x2, divided.quarter3);
26 try expect(divided.quarter4 == 0x1);26 try expectEqual(0x1, divided.quarter4);
2727
28 const ordered: [2]u8 = @bitCast(full);28 const ordered: [2]u8 = @bitCast(full);
29 switch (native_endian) {29 switch (native_endian) {
30 .big => {30 .big => {
31 try expect(ordered[0] == 0x12);31 try expectEqual(0x12, ordered[0]);
32 try expect(ordered[1] == 0x34);32 try expectEqual(0x34, ordered[1]);
33 },33 },
34 .little => {34 .little => {
35 try expect(ordered[0] == 0x34);35 try expectEqual(0x34, ordered[0]);
36 try expect(ordered[1] == 0x12);36 try expectEqual(0x12, ordered[1]);
37 },37 },
38 }38 }
39}39}
doc/langref/test_pass_by_reference_or_value.zig+2-2
...@@ -11,10 +11,10 @@ fn foo(point: Point) i32 {...@@ -11,10 +11,10 @@ fn foo(point: Point) i32 {
11 return point.x + point.y;11 return point.x + point.y;
12}12}
1313
14const expect = @import("std").testing.expect;14const expectEqual = @import("std").testing.expectEqual;
1515
16test "pass struct to function" {16test "pass struct to function" {
17 try expect(foo(Point{ .x = 1, .y = 2 }) == 3);17 try expectEqual(3, foo(Point{ .x = 1, .y = 2 }));
18}18}
1919
20// test20// test
doc/langref/test_peer_type_resolution.zig+26-26
...@@ -1,20 +1,20 @@...@@ -1,20 +1,20 @@
1const std = @import("std");1const std = @import("std");
2const expect = std.testing.expect;2const expectEqual = std.testing.expectEqual;
3const mem = std.mem;3const expectEqualStrings = std.testing.expectEqualStrings;
44
5test "peer resolve int widening" {5test "peer resolve int widening" {
6 const a: i8 = 12;6 const a: i8 = 12;
7 const b: i16 = 34;7 const b: i16 = 34;
8 const c = a + b;8 const c = a + b;
9 try expect(c == 46);9 try expectEqual(46, c);
10 try expect(@TypeOf(c) == i16);10 try expectEqual(i16, @TypeOf(c));
11}11}
1212
13test "peer resolve arrays of different size to const slice" {13test "peer resolve arrays of different size to const slice" {
14 try expect(mem.eql(u8, boolToStr(true), "true"));14 try expectEqualStrings("true", boolToStr(true));
15 try expect(mem.eql(u8, boolToStr(false), "false"));15 try expectEqualStrings("false", boolToStr(false));
16 try comptime expect(mem.eql(u8, boolToStr(true), "true"));16 try comptime expectEqualStrings("true", boolToStr(true));
17 try comptime expect(mem.eql(u8, boolToStr(false), "false"));17 try comptime expectEqualStrings("false", boolToStr(false));
18}18}
19fn boolToStr(b: bool) []const u8 {19fn boolToStr(b: bool) []const u8 {
20 return if (b) "true" else "false";20 return if (b) "true" else "false";
...@@ -27,16 +27,16 @@ test "peer resolve array and const slice" {...@@ -27,16 +27,16 @@ test "peer resolve array and const slice" {
27fn testPeerResolveArrayConstSlice(b: bool) !void {27fn testPeerResolveArrayConstSlice(b: bool) !void {
28 const value1 = if (b) "aoeu" else @as([]const u8, "zz");28 const value1 = if (b) "aoeu" else @as([]const u8, "zz");
29 const value2 = if (b) @as([]const u8, "zz") else "aoeu";29 const value2 = if (b) @as([]const u8, "zz") else "aoeu";
30 try expect(mem.eql(u8, value1, "aoeu"));30 try expectEqualStrings("aoeu", value1);
31 try expect(mem.eql(u8, value2, "zz"));31 try expectEqualStrings("zz", value2);
32}32}
3333
34test "peer type resolution: ?T and T" {34test "peer type resolution: ?T and T" {
35 try expect(peerTypeTAndOptionalT(true, false).? == 0);35 try expectEqual(0, peerTypeTAndOptionalT(true, false).?);
36 try expect(peerTypeTAndOptionalT(false, false).? == 3);36 try expectEqual(3, peerTypeTAndOptionalT(false, false).?);
37 comptime {37 comptime {
38 try expect(peerTypeTAndOptionalT(true, false).? == 0);38 try expectEqual(0, peerTypeTAndOptionalT(true, false).?);
39 try expect(peerTypeTAndOptionalT(false, false).? == 3);39 try expectEqual(3, peerTypeTAndOptionalT(false, false).?);
40 }40 }
41}41}
42fn peerTypeTAndOptionalT(c: bool, b: bool) ?usize {42fn peerTypeTAndOptionalT(c: bool, b: bool) ?usize {
...@@ -48,11 +48,11 @@ fn peerTypeTAndOptionalT(c: bool, b: bool) ?usize {...@@ -48,11 +48,11 @@ fn peerTypeTAndOptionalT(c: bool, b: bool) ?usize {
48}48}
4949
50test "peer type resolution: *[0]u8 and []const u8" {50test "peer type resolution: *[0]u8 and []const u8" {
51 try expect(peerTypeEmptyArrayAndSlice(true, "hi").len == 0);51 try expectEqual(0, peerTypeEmptyArrayAndSlice(true, "hi").len);
52 try expect(peerTypeEmptyArrayAndSlice(false, "hi").len == 1);52 try expectEqual(1, peerTypeEmptyArrayAndSlice(false, "hi").len);
53 comptime {53 comptime {
54 try expect(peerTypeEmptyArrayAndSlice(true, "hi").len == 0);54 try expectEqual(0, peerTypeEmptyArrayAndSlice(true, "hi").len);
55 try expect(peerTypeEmptyArrayAndSlice(false, "hi").len == 1);55 try expectEqual(1, peerTypeEmptyArrayAndSlice(false, "hi").len);
56 }56 }
57}57}
58fn peerTypeEmptyArrayAndSlice(a: bool, slice: []const u8) []const u8 {58fn peerTypeEmptyArrayAndSlice(a: bool, slice: []const u8) []const u8 {
...@@ -66,14 +66,14 @@ test "peer type resolution: *[0]u8, []const u8, and anyerror![]u8" {...@@ -66,14 +66,14 @@ test "peer type resolution: *[0]u8, []const u8, and anyerror![]u8" {
66 {66 {
67 var data = "hi".*;67 var data = "hi".*;
68 const slice = data[0..];68 const slice = data[0..];
69 try expect((try peerTypeEmptyArrayAndSliceAndError(true, slice)).len == 0);69 try expectEqual(0, (try peerTypeEmptyArrayAndSliceAndError(true, slice)).len);
70 try expect((try peerTypeEmptyArrayAndSliceAndError(false, slice)).len == 1);70 try expectEqual(1, (try peerTypeEmptyArrayAndSliceAndError(false, slice)).len);
71 }71 }
72 comptime {72 comptime {
73 var data = "hi".*;73 var data = "hi".*;
74 const slice = data[0..];74 const slice = data[0..];
75 try expect((try peerTypeEmptyArrayAndSliceAndError(true, slice)).len == 0);75 try expectEqual(0, (try peerTypeEmptyArrayAndSliceAndError(true, slice)).len);
76 try expect((try peerTypeEmptyArrayAndSliceAndError(false, slice)).len == 1);76 try expectEqual(1, (try peerTypeEmptyArrayAndSliceAndError(false, slice)).len);
77 }77 }
78}78}
79fn peerTypeEmptyArrayAndSliceAndError(a: bool, slice: []u8) anyerror![]u8 {79fn peerTypeEmptyArrayAndSliceAndError(a: bool, slice: []u8) anyerror![]u8 {
...@@ -87,8 +87,8 @@ fn peerTypeEmptyArrayAndSliceAndError(a: bool, slice: []u8) anyerror![]u8 {...@@ -87,8 +87,8 @@ fn peerTypeEmptyArrayAndSliceAndError(a: bool, slice: []u8) anyerror![]u8 {
87test "peer type resolution: *const T and ?*T" {87test "peer type resolution: *const T and ?*T" {
88 const a: *const usize = @ptrFromInt(0x123456780);88 const a: *const usize = @ptrFromInt(0x123456780);
89 const b: ?*usize = @ptrFromInt(0x123456780);89 const b: ?*usize = @ptrFromInt(0x123456780);
90 try expect(a == b);90 try expectEqual(a, b);
91 try expect(b == a);91 try expectEqual(b, a);
92}92}
9393
94test "peer type resolution: error union switch" {94test "peer type resolution: error union switch" {
...@@ -104,7 +104,7 @@ test "peer type resolution: error union switch" {...@@ -104,7 +104,7 @@ test "peer type resolution: error union switch" {
104 error.B => 1,104 error.B => 1,
105 error.C => null,105 error.C => null,
106 };106 };
107 try expect(@TypeOf(b) == ?u32);107 try expectEqual(?u32, @TypeOf(b));
108108
109 // The non-error and error cases are only peers if the error case is just a switch expression;109 // The non-error and error cases are only peers if the error case is just a switch expression;
110 // the pattern `x catch |err| blk: { switch (err) {...} }` does not consider the unwrapped `x`110 // 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" {...@@ -114,7 +114,7 @@ test "peer type resolution: error union switch" {
114 error.B => 1,114 error.B => 1,
115 error.C => null,115 error.C => null,
116 };116 };
117 try expect(@TypeOf(c) == ?u32);117 try expectEqual(?u32, @TypeOf(c));
118}118}
119119
120// test120// test
doc/langref/test_pointer_arithmetic.zig+9-9
...@@ -1,19 +1,19 @@...@@ -1,19 +1,19 @@
1const expect = @import("std").testing.expect;1const expectEqual = @import("std").testing.expectEqual;
22
3test "pointer arithmetic with many-item pointer" {3test "pointer arithmetic with many-item pointer" {
4 const array = [_]i32{ 1, 2, 3, 4 };4 const array = [_]i32{ 1, 2, 3, 4 };
5 var ptr: [*]const i32 = &array;5 var ptr: [*]const i32 = &array;
66
7 try expect(ptr[0] == 1);7 try expectEqual(1, ptr[0]);
8 ptr += 1;8 ptr += 1;
9 try expect(ptr[0] == 2);9 try expectEqual(2, ptr[0]);
1010
11 // slicing a many-item pointer without an end is equivalent to11 // slicing a many-item pointer without an end is equivalent to
12 // pointer arithmetic: `ptr[start..] == ptr + start`12 // pointer arithmetic: `ptr[start..] == ptr + start`
13 try expect(ptr[1..] == ptr + 1);13 try expectEqual(ptr[1..], ptr + 1);
1414
15 // subtraction between any two pointers except slices based on element size is supported15 // 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]);
17}17}
1818
19test "pointer arithmetic with slices" {19test "pointer arithmetic with slices" {
...@@ -22,14 +22,14 @@ test "pointer arithmetic with slices" {...@@ -22,14 +22,14 @@ test "pointer arithmetic with slices" {
22 _ = &length; // suppress 'var is never mutated' error22 _ = &length; // suppress 'var is never mutated' error
23 var slice = array[length..array.len];23 var slice = array[length..array.len];
2424
25 try expect(slice[0] == 1);25 try expectEqual(1, slice[0]);
26 try expect(slice.len == 4);26 try expectEqual(4, slice.len);
2727
28 slice.ptr += 1;28 slice.ptr += 1;
29 // now the slice is in an bad state since len has not been updated29 // now the slice is in an bad state since len has not been updated
3030
31 try expect(slice[0] == 2);31 try expectEqual(2, slice[0]);
32 try expect(slice.len == 4);32 try expectEqual(4, slice.len);
33}33}
3434
35// test35// test
doc/langref/test_pointer_casting.zig+5-5
...@@ -1,23 +1,23 @@...@@ -1,23 +1,23 @@
1const std = @import("std");1const std = @import("std");
2const expect = std.testing.expect;2const expectEqual = std.testing.expectEqual;
33
4test "pointer casting" {4test "pointer casting" {
5 const bytes align(@alignOf(u32)) = [_]u8{ 0x12, 0x12, 0x12, 0x12 };5 const bytes align(@alignOf(u32)) = [_]u8{ 0x12, 0x12, 0x12, 0x12 };
6 const u32_ptr: *const u32 = @ptrCast(&bytes);6 const u32_ptr: *const u32 = @ptrCast(&bytes);
7 try expect(u32_ptr.* == 0x12121212);7 try expectEqual(0x12121212, u32_ptr.*);
88
9 // Even this example is contrived - there are better ways to do the above than9 // Even this example is contrived - there are better ways to do the above than
10 // pointer casting. For example, using a slice narrowing cast:10 // pointer casting. For example, using a slice narrowing cast:
11 const u32_value = std.mem.bytesAsSlice(u32, bytes[0..])[0];11 const u32_value = std.mem.bytesAsSlice(u32, bytes[0..])[0];
12 try expect(u32_value == 0x12121212);12 try expectEqual(0x12121212, u32_value);
1313
14 // And even another way, the most straightforward way to do it:14 // 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)));
16}16}
1717
18test "pointer child type" {18test "pointer child type" {
19 // pointer types have a `child` field which tells you the type they point to.19 // 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);
21}21}
2222
23// test23// test
doc/langref/test_pointer_coerce_const_optional.zig+2-2
...@@ -1,11 +1,11 @@...@@ -1,11 +1,11 @@
1const std = @import("std");1const std = @import("std");
2const expect = std.testing.expect;2const expectEqualStrings = std.testing.expectEqualStrings;
3const mem = std.mem;3const mem = std.mem;
44
5test "cast *[1][*:0]const u8 to []const ?[*:0]const u8" {5test "cast *[1][*:0]const u8 to []const ?[*:0]const u8" {
6 const window_name = [1][*:0]const u8{"window name"};6 const window_name = [1][*:0]const u8{"window name"};
7 const x: []const ?[*:0]const u8 = &window_name;7 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].?));
9}9}
1010
11// test11// test
doc/langref/test_pointer_to_non-byte_aligned_field.zig+2-2
...@@ -1,5 +1,5 @@...@@ -1,5 +1,5 @@
1const std = @import("std");1const std = @import("std");
2const expect = std.testing.expect;2const expectEqual = std.testing.expectEqual;
33
4const BitField = packed struct {4const BitField = packed struct {
5 a: u3,5 a: u3,
...@@ -15,7 +15,7 @@ var foo = BitField{...@@ -15,7 +15,7 @@ var foo = BitField{
1515
16test "pointer to non-byte-aligned field" {16test "pointer to non-byte-aligned field" {
17 const ptr = &foo.b;17 const ptr = &foo.b;
18 try expect(ptr.* == 2);18 try expectEqual(2, ptr.*);
19}19}
2020
21// test21// test
doc/langref/test_reduce_builtin.zig+4-4
...@@ -1,15 +1,15 @@...@@ -1,15 +1,15 @@
1const std = @import("std");1const std = @import("std");
2const expect = std.testing.expect;2const expectEqual = std.testing.expectEqual;
33
4test "vector @reduce" {4test "vector @reduce" {
5 const V = @Vector(4, i32);5 const V = @Vector(4, i32);
6 const value = V{ 1, -1, 1, -1 };6 const value = V{ 1, -1, 1, -1 };
7 const result = value > @as(V, @splat(0));7 const result = value > @as(V, @splat(0));
8 // result is { true, false, true, false };8 // result is { true, false, true, false };
9 try comptime expect(@TypeOf(result) == @Vector(4, bool));9 try comptime expectEqual(@Vector(4, bool), @TypeOf(result));
10 const is_all_true = @reduce(.And, result);10 const is_all_true = @reduce(.And, result);
11 try comptime expect(@TypeOf(is_all_true) == bool);11 try comptime expectEqual(bool, @TypeOf(is_all_true));
12 try expect(is_all_true == false);12 try expectEqual(false, is_all_true);
13}13}
1414
15// test15// test
doc/langref/test_round_builtin.zig+5-5
...@@ -1,10 +1,10 @@...@@ -1,10 +1,10 @@
1const expect = @import("std").testing.expect;1const expectEqual = @import("std").testing.expectEqual;
22
3test "@round" {3test "@round" {
4 try expect(@round(1.4) == 1);4 try expectEqual(1, @round(1.4));
5 try expect(@round(1.5) == 2);5 try expectEqual(2, @round(1.5));
6 try expect(@round(-1.4) == -1);6 try expectEqual(-1, @round(-1.4));
7 try expect(@round(-2.5) == -3);7 try expectEqual(-3, @round(-2.5));
8}8}
99
10// test10// test
doc/langref/test_sentinel_mismatch.zig+1-1
...@@ -1,5 +1,5 @@...@@ -1,5 +1,5 @@
1const std = @import("std");1const std = @import("std");
2const expect = std.testing.expect;2const expectEqual = std.testing.expectEqual;
33
4test "sentinel mismatch" {4test "sentinel mismatch" {
5 var array = [_]u8{ 3, 2, 1, 0 };5 var array = [_]u8{ 3, 2, 1, 0 };
doc/langref/test_shuffle_builtin.zig+3-3
...@@ -1,5 +1,5 @@...@@ -1,5 +1,5 @@
1const std = @import("std");1const std = @import("std");
2const expect = std.testing.expect;2const expectEqualStrings = std.testing.expectEqualStrings;
33
4test "vector @shuffle" {4test "vector @shuffle" {
5 const a = @Vector(7, u8){ 'o', 'l', 'h', 'e', 'r', 'z', 'w' };5 const a = @Vector(7, u8){ 'o', 'l', 'h', 'e', 'r', 'z', 'w' };
...@@ -9,12 +9,12 @@ test "vector @shuffle" {...@@ -9,12 +9,12 @@ test "vector @shuffle" {
9 // Notice that we can re-order, duplicate, or omit elements of the input vector9 // Notice that we can re-order, duplicate, or omit elements of the input vector
10 const mask1 = @Vector(5, i32){ 2, 3, 1, 1, 0 };10 const mask1 = @Vector(5, i32){ 2, 3, 1, 1, 0 };
11 const res1: @Vector(5, u8) = @shuffle(u8, a, undefined, mask1);11 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
14 // Combining two vectors14 // Combining two vectors
15 const mask2 = @Vector(6, i32){ -1, 0, 4, 1, -2, -3 };15 const mask2 = @Vector(6, i32){ -1, 0, 4, 1, -2, -3 };
16 const res2: @Vector(6, u8) = @shuffle(u8, a, b, mask2);16 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));
18}18}
1919
20// test20// test
doc/langref/test_simple_union.zig+3-3
...@@ -1,5 +1,5 @@...@@ -1,5 +1,5 @@
1const std = @import("std");1const std = @import("std");
2const expect = std.testing.expect;2const expectEqual = std.testing.expectEqual;
33
4const Payload = union {4const Payload = union {
5 int: i64,5 int: i64,
...@@ -8,9 +8,9 @@ const Payload = union {...@@ -8,9 +8,9 @@ const Payload = union {
8};8};
9test "simple union" {9test "simple union" {
10 var payload = Payload{ .int = 1234 };10 var payload = Payload{ .int = 1234 };
11 try expect(payload.int == 1234);11 try expectEqual(1234, payload.int);
12 payload = Payload{ .float = 12.34 };12 payload = Payload{ .float = 12.34 };
13 try expect(payload.float == 12.34);13 try expectEqual(12.34, payload.float);
14}14}
1515
16// test16// test
doc/langref/test_single_item_pointer.zig+10-10
...@@ -1,4 +1,4 @@...@@ -1,4 +1,4 @@
1const expect = @import("std").testing.expect;1const expectEqual = @import("std").testing.expectEqual;
22
3test "address of syntax" {3test "address of syntax" {
4 // Get the address of a variable:4 // Get the address of a variable:
...@@ -6,17 +6,17 @@ test "address of syntax" {...@@ -6,17 +6,17 @@ test "address of syntax" {
6 const x_ptr = &x;6 const x_ptr = &x;
77
8 // Dereference a pointer:8 // Dereference a pointer:
9 try expect(x_ptr.* == 1234);9 try expectEqual(1234, x_ptr.*);
1010
11 // When you get the address of a const variable, you get a const single-item pointer.11 // 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
14 // If you want to mutate the value, you'd need an address of a mutable variable:14 // If you want to mutate the value, you'd need an address of a mutable variable:
15 var y: i32 = 5678;15 var y: i32 = 5678;
16 const y_ptr = &y;16 const y_ptr = &y;
17 try expect(@TypeOf(y_ptr) == *i32);17 try expectEqual(*i32, @TypeOf(y_ptr));
18 y_ptr.* += 1;18 y_ptr.* += 1;
19 try expect(y_ptr.* == 5679);19 try expectEqual(5679, y_ptr.*);
20}20}
2121
22test "pointer array access" {22test "pointer array access" {
...@@ -25,11 +25,11 @@ test "pointer array access" {...@@ -25,11 +25,11 @@ test "pointer array access" {
25 // does not support pointer arithmetic.25 // does not support pointer arithmetic.
26 var array = [_]u8{ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };26 var array = [_]u8{ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
27 const ptr = &array[2];27 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]);
31 ptr.* += 1;31 ptr.* += 1;
32 try expect(array[2] == 4);32 try expectEqual(4, array[2]);
33}33}
3434
35test "slice syntax" {35test "slice syntax" {
...@@ -39,11 +39,11 @@ test "slice syntax" {...@@ -39,11 +39,11 @@ test "slice syntax" {
3939
40 // Convert to array pointer using slice syntax:40 // Convert to array pointer using slice syntax:
41 const x_array_ptr = x_ptr[0..1];41 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
44 // Coerce to many-item pointer:44 // Coerce to many-item pointer:
45 const x_many_ptr: [*]i32 = x_array_ptr;45 const x_many_ptr: [*]i32 = x_array_ptr;
46 try expect(x_many_ptr[0] == 1234);46 try expectEqual(1234, x_many_ptr[0]);
47}47}
4848
49// test49// test
doc/langref/test_slice_bounds.zig+4-4
...@@ -1,15 +1,15 @@...@@ -1,15 +1,15 @@
1const expect = @import("std").testing.expect;1const expectEqual = @import("std").testing.expectEqual;
22
3test "pointer slicing" {3test "pointer slicing" {
4 var array = [_]u8{ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };4 var array = [_]u8{ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
5 var start: usize = 2; // var to make it runtime-known5 var start: usize = 2; // var to make it runtime-known
6 _ = &start; // suppress 'var is never mutated' error6 _ = &start; // suppress 'var is never mutated' error
7 const slice = array[start..4];7 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]);
11 slice[1] += 1;11 slice[1] += 1;
12 try expect(array[3] == 5);12 try expectEqual(5, array[3]);
13}13}
1414
15// test15// test
doc/langref/test_slices.zig+9-9
...@@ -1,6 +1,6 @@...@@ -1,6 +1,6 @@
1const std = @import("std");1const std = @import("std");
2const expect = std.testing.expect;2const expectEqual = std.testing.expectEqual;
3const mem = std.mem;3const expectEqualStrings = std.testing.expectEqualStrings;
4const fmt = std.fmt;4const fmt = std.fmt;
55
6test "using slices for strings" {6test "using slices for strings" {
...@@ -23,13 +23,13 @@ test "using slices for strings" {...@@ -23,13 +23,13 @@ test "using slices for strings" {
23 // Generally, you can use UTF-8 and not worry about whether something is a23 // Generally, you can use UTF-8 and not worry about whether something is a
24 // string. If you don't need to deal with individual characters, no need24 // string. If you don't need to deal with individual characters, no need
25 // to decode.25 // to decode.
26 try expect(mem.eql(u8, hello_world, "hello 世界"));26 try expectEqualStrings("hello 世界", hello_world);
27}27}
2828
29test "slice pointer" {29test "slice pointer" {
30 var array: [10]u8 = undefined;30 var array: [10]u8 = undefined;
31 const ptr = &array;31 const ptr = &array;
32 try expect(@TypeOf(ptr) == *[10]u8);32 try expectEqual(*[10]u8, @TypeOf(ptr));
3333
34 // A pointer to an array can be sliced just like an array:34 // A pointer to an array can be sliced just like an array:
35 var start: usize = 0;35 var start: usize = 0;
...@@ -37,16 +37,16 @@ test "slice pointer" {...@@ -37,16 +37,16 @@ test "slice pointer" {
37 _ = .{ &start, &end };37 _ = .{ &start, &end };
38 const slice = ptr[start..end];38 const slice = ptr[start..end];
39 // The slice is mutable because we sliced a mutable pointer.39 // The slice is mutable because we sliced a mutable pointer.
40 try expect(@TypeOf(slice) == []u8);40 try expectEqual([]u8, @TypeOf(slice));
41 slice[2] = 3;41 slice[2] = 3;
42 try expect(array[2] == 3);42 try expectEqual(3, array[2]);
4343
44 // Again, slicing with comptime-known indexes will produce another pointer44 // Again, slicing with comptime-known indexes will produce another pointer
45 // to an array:45 // to an array:
46 const ptr2 = slice[2..3];46 const ptr2 = slice[2..3];
47 try expect(ptr2.len == 1);47 try expectEqual(1, ptr2.len);
48 try expect(ptr2[0] == 3);48 try expectEqual(3, ptr2[0]);
49 try expect(@TypeOf(ptr2) == *[1]u8);49 try expectEqual(*[1]u8, @TypeOf(ptr2));
50}50}
5151
52// test52// test
doc/langref/test_splat_builtin.zig+3-3
...@@ -1,16 +1,16 @@...@@ -1,16 +1,16 @@
1const std = @import("std");1const std = @import("std");
2const expect = std.testing.expect;2const expectEqualSlices = std.testing.expectEqualSlices;
33
4test "vector @splat" {4test "vector @splat" {
5 const scalar: u32 = 5;5 const scalar: u32 = 5;
6 const result: @Vector(4, u32) = @splat(scalar);6 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));
8}8}
99
10test "array @splat" {10test "array @splat" {
11 const scalar: u32 = 5;11 const scalar: u32 = 5;
12 const result: [4]u32 = @splat(scalar);12 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));
14}14}
1515
16// test16// test
doc/langref/test_src_builtin.zig+3-2
...@@ -1,5 +1,6 @@...@@ -1,5 +1,6 @@
1const std = @import("std");1const std = @import("std");
2const expect = std.testing.expect;2const expect = std.testing.expect;
3const expectEqual = std.testing.expectEqual;
34
4test "@src" {5test "@src" {
5 try doTheTest();6 try doTheTest();
...@@ -8,8 +9,8 @@ test "@src" {...@@ -8,8 +9,8 @@ test "@src" {
8fn doTheTest() !void {9fn doTheTest() !void {
9 const src = @src();10 const src = @src();
1011
11 try expect(src.line == 9);12 try expectEqual(10, src.line);
12 try expect(src.column == 17);13 try expectEqual(17, src.column);
13 try expect(std.mem.endsWith(u8, src.fn_name, "doTheTest"));14 try expect(std.mem.endsWith(u8, src.fn_name, "doTheTest"));
14 try expect(std.mem.endsWith(u8, src.file, "test_src_builtin.zig"));15 try expect(std.mem.endsWith(u8, src.file, "test_src_builtin.zig"));
15}16}
doc/langref/test_static_local_variable.zig+3-3
...@@ -1,9 +1,9 @@...@@ -1,9 +1,9 @@
1const std = @import("std");1const std = @import("std");
2const expect = std.testing.expect;2const expectEqual = std.testing.expectEqual;
33
4test "static local variable" {4test "static local variable" {
5 try expect(foo() == 1235);5 try expectEqual(1235, foo());
6 try expect(foo() == 1236);6 try expectEqual(1236, foo());
7}7}
88
9fn foo() i32 {9fn foo() i32 {
doc/langref/test_struct_result.zig+3-3
...@@ -1,5 +1,5 @@...@@ -1,5 +1,5 @@
1const std = @import("std");1const std = @import("std");
2const expect = std.testing.expect;2const expectEqual = std.testing.expectEqual;
33
4const Point = struct { x: i32, y: i32 };4const Point = struct { x: i32, y: i32 };
55
...@@ -8,8 +8,8 @@ test "anonymous struct literal" {...@@ -8,8 +8,8 @@ test "anonymous struct literal" {
8 .x = 13,8 .x = 13,
9 .y = 67,9 .y = 67,
10 };10 };
11 try expect(pt.x == 13);11 try expectEqual(13, pt.x);
12 try expect(pt.y == 67);12 try expectEqual(67, pt.y);
13}13}
1414
15// test15// test
doc/langref/test_structs.zig+11-11
...@@ -34,12 +34,12 @@ const Vec3 = struct {...@@ -34,12 +34,12 @@ const Vec3 = struct {
34test "dot product" {34test "dot product" {
35 const v1 = Vec3.init(1.0, 0.0, 0.0);35 const v1 = Vec3.init(1.0, 0.0, 0.0);
36 const v2 = Vec3.init(0.0, 1.0, 0.0);36 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
39 // Other than being available to call with dot syntax, struct methods are39 // Other than being available to call with dot syntax, struct methods are
40 // not special. You can reference them as any other declaration inside40 // not special. You can reference them as any other declaration inside
41 // the struct:41 // the struct:
42 try expect(Vec3.dot(v1, v2) == 0.0);42 try expectEqual(0.0, Vec3.dot(v1, v2));
43}43}
4444
45// Structs can have declarations.45// Structs can have declarations.
...@@ -48,8 +48,8 @@ const Empty = struct {...@@ -48,8 +48,8 @@ const Empty = struct {
48 pub const PI = 3.14;48 pub const PI = 3.14;
49};49};
50test "struct namespaced variable" {50test "struct namespaced variable" {
51 try expect(Empty.PI == 3.14);51 try expectEqual(3.14, Empty.PI);
52 try expect(@sizeOf(Empty) == 0);52 try expectEqual(0, @sizeOf(Empty));
5353
54 // Empty structs can be instantiated the same as usual.54 // Empty structs can be instantiated the same as usual.
55 const does_nothing: Empty = .{};55 const does_nothing: Empty = .{};
...@@ -69,7 +69,7 @@ test "field parent pointer" {...@@ -69,7 +69,7 @@ test "field parent pointer" {
69 .y = 0.5678,69 .y = 0.5678,
70 };70 };
71 setYBasedOnX(&point.x, 0.9);71 setYBasedOnX(&point.x, 0.9);
72 try expect(point.y == 0.9);72 try expectEqual(0.9, point.y);
73}73}
7474
75// Structs can be returned from functions.75// Structs can be returned from functions.
...@@ -89,19 +89,19 @@ fn LinkedList(comptime T: type) type {...@@ -89,19 +89,19 @@ fn LinkedList(comptime T: type) type {
8989
90test "linked list" {90test "linked list" {
91 // Functions called at compile-time are memoized.91 // Functions called at compile-time are memoized.
92 try expect(LinkedList(i32) == LinkedList(i32));92 try expectEqual(LinkedList(i32), LinkedList(i32));
9393
94 const list = LinkedList(i32){94 const list = LinkedList(i32){
95 .first = null,95 .first = null,
96 .last = null,96 .last = null,
97 .len = 0,97 .len = 0,
98 };98 };
99 try expect(list.len == 0);99 try expectEqual(0, list.len);
100100
101 // Since types are first class values you can instantiate the type101 // Since types are first class values you can instantiate the type
102 // by assigning it to a variable:102 // by assigning it to a variable:
103 const ListOfInts = LinkedList(i32);103 const ListOfInts = LinkedList(i32);
104 try expect(ListOfInts == LinkedList(i32));104 try expectEqual(LinkedList(i32), ListOfInts);
105105
106 var node = ListOfInts.Node{106 var node = ListOfInts.Node{
107 .prev = null,107 .prev = null,
...@@ -117,10 +117,10 @@ test "linked list" {...@@ -117,10 +117,10 @@ test "linked list" {
117 // When using a pointer to a struct, fields can be accessed directly,117 // When using a pointer to a struct, fields can be accessed directly,
118 // without explicitly dereferencing the pointer.118 // without explicitly dereferencing the pointer.
119 // So you can do119 // So you can do
120 try expect(list2.first.?.data == 1234);120 try expectEqual(1234, list2.first.?.data);
121 // instead of try expect(list2.first.?.*.data == 1234);121 // instead of try expectEqual(1234, list2.first.?.*.data);
122}122}
123123
124const expect = @import("std").testing.expect;124const expectEqual = @import("std").testing.expectEqual;
125125
126// test126// test
doc/langref/test_switch.zig+2-2
...@@ -1,6 +1,6 @@...@@ -1,6 +1,6 @@
1const std = @import("std");1const std = @import("std");
2const builtin = @import("builtin");2const builtin = @import("builtin");
3const expect = std.testing.expect;3const expectEqual = std.testing.expectEqual;
44
5test "switch simple" {5test "switch simple" {
6 const a: u64 = 10;6 const a: u64 = 10;
...@@ -40,7 +40,7 @@ test "switch simple" {...@@ -40,7 +40,7 @@ test "switch simple" {
40 else => 9,40 else => 9,
41 };41 };
4242
43 try expect(b == 1);43 try expectEqual(1, b);
44}44}
4545
46// Switch expressions can be used outside a function:46// Switch expressions can be used outside a function:
doc/langref/test_switch_modify_tagged_union.zig+2-2
...@@ -1,5 +1,5 @@...@@ -1,5 +1,5 @@
1const std = @import("std");1const std = @import("std");
2const expect = std.testing.expect;2const expectEqual = std.testing.expectEqual;
33
4const ComplexTypeTag = enum {4const ComplexTypeTag = enum {
5 ok,5 ok,
...@@ -18,7 +18,7 @@ test "modify tagged union in switch" {...@@ -18,7 +18,7 @@ test "modify tagged union in switch" {
18 ComplexTypeTag.not_ok => unreachable,18 ComplexTypeTag.not_ok => unreachable,
19 }19 }
2020
21 try expect(c.ok == 43);21 try expectEqual(43, c.ok);
22}22}
2323
24// test24// test
doc/langref/test_switch_tagged_union.zig+3-3
...@@ -1,4 +1,4 @@...@@ -1,4 +1,4 @@
1const expect = @import("std").testing.expect;1const expectEqual = @import("std").testing.expectEqual;
22
3test "switch on tagged union" {3test "switch on tagged union" {
4 const Point = struct {4 const Point = struct {
...@@ -31,8 +31,8 @@ test "switch on tagged union" {...@@ -31,8 +31,8 @@ test "switch on tagged union" {
31 Item.d => 8,31 Item.d => 8,
32 };32 };
3333
34 try expect(b == 6);34 try expectEqual(6, b);
35 try expect(a.c.x == 2);35 try expectEqual(2, a.c.x);
36}36}
3737
38// test38// test
doc/langref/test_tagName.zig+2-2
...@@ -1,5 +1,5 @@...@@ -1,5 +1,5 @@
1const std = @import("std");1const std = @import("std");
2const expect = std.testing.expect;2const expectEqualSlices = std.testing.expectEqualSlices;
33
4const Small2 = union(enum) {4const Small2 = union(enum) {
5 a: i32,5 a: i32,
...@@ -7,7 +7,7 @@ const Small2 = union(enum) {...@@ -7,7 +7,7 @@ const Small2 = union(enum) {
7 c: u8,7 c: u8,
8};8};
9test "@tagName" {9test "@tagName" {
10 try expect(std.mem.eql(u8, @tagName(Small2.a), "a"));10 try expectEqualSlices(u8, "a", @tagName(Small2.a));
11}11}
1212
13// test13// test
doc/langref/test_tagged_union.zig+4-4
...@@ -1,5 +1,5 @@...@@ -1,5 +1,5 @@
1const std = @import("std");1const std = @import("std");
2const expect = std.testing.expect;2const expectEqual = std.testing.expectEqual;
33
4const ComplexTypeTag = enum {4const ComplexTypeTag = enum {
5 ok,5 ok,
...@@ -12,10 +12,10 @@ const ComplexType = union(ComplexTypeTag) {...@@ -12,10 +12,10 @@ const ComplexType = union(ComplexTypeTag) {
1212
13test "switch on tagged union" {13test "switch on tagged union" {
14 const c = ComplexType{ .ok = 42 };14 const c = ComplexType{ .ok = 42 };
15 try expect(@as(ComplexTypeTag, c) == ComplexTypeTag.ok);15 try expectEqual(ComplexTypeTag.ok, @as(ComplexTypeTag, c));
1616
17 switch (c) {17 switch (c) {
18 .ok => |value| try expect(value == 42),18 .ok => |value| try expectEqual(42, value),
19 .not_ok => unreachable,19 .not_ok => unreachable,
20 }20 }
2121
...@@ -29,7 +29,7 @@ test "switch on tagged union" {...@@ -29,7 +29,7 @@ test "switch on tagged union" {
29}29}
3030
31test "get tag type" {31test "get tag type" {
32 try expect(std.meta.Tag(ComplexType) == ComplexTypeTag);32 try expectEqual(ComplexTypeTag, std.meta.Tag(ComplexType));
33}33}
3434
35// test35// test
doc/langref/test_tagged_union_with_tag_values.zig+3-3
...@@ -1,5 +1,5 @@...@@ -1,5 +1,5 @@
1const std = @import("std");1const std = @import("std");
2const expect = std.testing.expect;2const expectEqual = std.testing.expectEqual;
33
4const Tagged = union(enum(u32)) {4const Tagged = union(enum(u32)) {
5 int: i64 = 123,5 int: i64 = 123,
...@@ -8,10 +8,10 @@ const Tagged = union(enum(u32)) {...@@ -8,10 +8,10 @@ const Tagged = union(enum(u32)) {
88
9test "tag values" {9test "tag values" {
10 const int: Tagged = .{ .int = -40 };10 const int: Tagged = .{ .int = -40 };
11 try expect(@intFromEnum(int) == 123);11 try expectEqual(123, @intFromEnum(int));
1212
13 const boolean: Tagged = .{ .boolean = false };13 const boolean: Tagged = .{ .boolean = false };
14 try expect(@intFromEnum(boolean) == 67);14 try expectEqual(67, @intFromEnum(boolean));
15}15}
1616
17// test17// test
doc/langref/test_this_builtin.zig+2-2
...@@ -1,10 +1,10 @@...@@ -1,10 +1,10 @@
1const std = @import("std");1const std = @import("std");
2const expect = std.testing.expect;2const expectEqual = std.testing.expectEqual;
33
4test "@This()" {4test "@This()" {
5 var items = [_]i32{ 1, 2, 3, 4 };5 var items = [_]i32{ 1, 2, 3, 4 };
6 const list = List(i32){ .items = items[0..] };6 const list = List(i32){ .items = items[0..] };
7 try expect(list.length() == 4);7 try expectEqual(4, list.length());
8}8}
99
10fn List(comptime T: type) type {10fn List(comptime T: type) type {
doc/langref/test_truncate_builtin.zig+2-2
...@@ -1,10 +1,10 @@...@@ -1,10 +1,10 @@
1const std = @import("std");1const std = @import("std");
2const expect = std.testing.expect;2const expectEqual = std.testing.expectEqual;
33
4test "integer truncation" {4test "integer truncation" {
5 const a: u16 = 0xabcd;5 const a: u16 = 0xabcd;
6 const b: u8 = @truncate(a);6 const b: u8 = @truncate(a);
7 try expect(b == 0xcd);7 try expectEqual(0xcd, b);
8}8}
99
10// test10// test
doc/langref/test_tuples.zig+5-4
...@@ -1,5 +1,6 @@...@@ -1,5 +1,6 @@
1const std = @import("std");1const std = @import("std");
2const expect = std.testing.expect;2const expect = std.testing.expect;
3const expectEqual = std.testing.expectEqual;
34
4test "tuple" {5test "tuple" {
5 const values = .{6 const values = .{
...@@ -8,14 +9,14 @@ test "tuple" {...@@ -8,14 +9,14 @@ test "tuple" {
8 true,9 true,
9 "hi",10 "hi",
10 } ++ .{false} ** 2;11 } ++ .{false} ** 2;
11 try expect(values[0] == 1234);12 try expectEqual(1234, values[0]);
12 try expect(values[4] == false);13 try expectEqual(false, values[4]);
13 inline for (values, 0..) |v, i| {14 inline for (values, 0..) |v, i| {
14 if (i != 2) continue;15 if (i != 2) continue;
15 try expect(v);16 try expect(v);
16 }17 }
17 try expect(values.len == 6);18 try expectEqual(6, values.len);
18 try expect(values.@"3"[0] == 'h');19 try expectEqual('h', values.@"3"[0]);
19}20}
2021
21// test22// test
doc/langref/test_variable_alignment.zig+4-4
...@@ -1,14 +1,14 @@...@@ -1,14 +1,14 @@
1const std = @import("std");1const std = @import("std");
2const builtin = @import("builtin");2const builtin = @import("builtin");
3const expect = std.testing.expect;3const expectEqual = std.testing.expectEqual;
44
5test "variable alignment" {5test "variable alignment" {
6 var x: i32 = 1234;6 var x: i32 = 1234;
7 const align_of_i32 = @alignOf(@TypeOf(x));7 const align_of_i32 = @alignOf(@TypeOf(x));
8 try expect(@TypeOf(&x) == *i32);8 try expectEqual(*i32, @TypeOf(&x));
9 try expect(*i32 == *align(align_of_i32) i32);9 try expectEqual(*align(align_of_i32) i32, *i32);
10 if (builtin.target.cpu.arch == .x86_64) {10 if (builtin.target.cpu.arch == .x86_64) {
11 try expect(@typeInfo(*i32).pointer.alignment == 4);11 try expectEqual(4, @typeInfo(*i32).pointer.alignment);
12 }12 }
13}13}
1414
doc/langref/test_variable_func_alignment.zig+11-11
...@@ -1,14 +1,14 @@...@@ -1,14 +1,14 @@
1const expect = @import("std").testing.expect;1const expectEqual = @import("std").testing.expectEqual;
22
3var foo: u8 align(4) = 100;3var foo: u8 align(4) = 100;
44
5test "global variable alignment" {5test "global variable alignment" {
6 try expect(@typeInfo(@TypeOf(&foo)).pointer.alignment == 4);6 try expectEqual(4, @typeInfo(@TypeOf(&foo)).pointer.alignment);
7 try expect(@TypeOf(&foo) == *align(4) u8);7 try expectEqual(*align(4) u8, @TypeOf(&foo));
8 const as_pointer_to_array: *align(4) [1]u8 = &foo;8 const as_pointer_to_array: *align(4) [1]u8 = &foo;
9 const as_slice: []align(4) u8 = as_pointer_to_array;9 const as_slice: []align(4) u8 = as_pointer_to_array;
10 const as_unaligned_slice: []u8 = as_slice;10 const as_unaligned_slice: []u8 = as_slice;
11 try expect(as_unaligned_slice[0] == 100);11 try expectEqual(100, as_unaligned_slice[0]);
12}12}
1313
14fn derp() align(@sizeOf(usize) * 2) i32 {14fn derp() align(@sizeOf(usize) * 2) i32 {
...@@ -18,17 +18,17 @@ fn noop1() align(1) void {}...@@ -18,17 +18,17 @@ fn noop1() align(1) void {}
18fn noop4() align(4) void {}18fn noop4() align(4) void {}
1919
20test "function alignment" {20test "function alignment" {
21 try expect(derp() == 1234);21 try expectEqual(1234, derp());
22 try expect(@TypeOf(derp) == fn () i32);22 try expectEqual(fn () i32, @TypeOf(derp));
23 try expect(@TypeOf(&derp) == *align(@sizeOf(usize) * 2) const fn () i32);23 try expectEqual(*align(@sizeOf(usize) * 2) const fn () i32, @TypeOf(&derp));
2424
25 noop1();25 noop1();
26 try expect(@TypeOf(noop1) == fn () void);26 try expectEqual(fn () void, @TypeOf(noop1));
27 try expect(@TypeOf(&noop1) == *align(1) const fn () void);27 try expectEqual(*align(1) const fn () void, @TypeOf(&noop1));
2828
29 noop4();29 noop4();
30 try expect(@TypeOf(noop4) == fn () void);30 try expectEqual(fn () void, @TypeOf(noop4));
31 try expect(@TypeOf(&noop4) == *align(4) const fn () void);31 try expectEqual(*align(4) const fn () void, @TypeOf(&noop4));
32}32}
3333
34// test34// test
doc/langref/test_variadic_function.zig+1-1
...@@ -4,7 +4,7 @@ const testing = std.testing;...@@ -4,7 +4,7 @@ const testing = std.testing;
4pub extern "c" fn printf(format: [*:0]const u8, ...) c_int;4pub extern "c" fn printf(format: [*:0]const u8, ...) c_int;
55
6test "variadic function" {6test "variadic function" {
7 try testing.expect(printf("Hello, world!\n") == 14);7 try testing.expectEqual(14, printf("Hello, world!\n"));
8 try testing.expect(@typeInfo(@TypeOf(printf)).@"fn".is_var_args);8 try testing.expect(@typeInfo(@TypeOf(printf)).@"fn".is_var_args);
9}9}
1010
doc/langref/test_volatile.zig+2-2
...@@ -1,8 +1,8 @@...@@ -1,8 +1,8 @@
1const expect = @import("std").testing.expect;1const expectEqual = @import("std").testing.expectEqual;
22
3test "volatile" {3test "volatile" {
4 const mmio_ptr: *volatile u8 = @ptrFromInt(0x12345678);4 const mmio_ptr: *volatile u8 = @ptrFromInt(0x12345678);
5 try expect(@TypeOf(mmio_ptr) == *volatile u8);5 try expectEqual(*volatile u8, @TypeOf(mmio_ptr));
6}6}
77
8// test8// test
doc/langref/test_wasmMemoryGrow_builtin.zig+3-3
...@@ -1,13 +1,13 @@...@@ -1,13 +1,13 @@
1const std = @import("std");1const std = @import("std");
2const native_arch = @import("builtin").target.cpu.arch;2const native_arch = @import("builtin").target.cpu.arch;
3const expect = std.testing.expect;3const expectEqual = std.testing.expectEqual;
44
5test "@wasmMemoryGrow" {5test "@wasmMemoryGrow" {
6 if (native_arch != .wasm32) return error.SkipZigTest;6 if (native_arch != .wasm32) return error.SkipZigTest;
77
8 const prev = @wasmMemorySize(0);8 const prev = @wasmMemorySize(0);
9 try expect(prev == @wasmMemoryGrow(0, 1));9 try expectEqual(@wasmMemoryGrow(0, 1), prev);
10 try expect(prev + 1 == @wasmMemorySize(0));10 try expectEqual(@wasmMemorySize(0), prev + 1);
11}11}
1212
13// test13// test
doc/langref/test_while.zig+2-2
...@@ -1,11 +1,11 @@...@@ -1,11 +1,11 @@
1const expect = @import("std").testing.expect;1const expectEqual = @import("std").testing.expectEqual;
22
3test "while basic" {3test "while basic" {
4 var i: usize = 0;4 var i: usize = 0;
5 while (i < 10) {5 while (i < 10) {
6 i += 1;6 i += 1;
7 }7 }
8 try expect(i == 10);8 try expectEqual(10, i);
9}9}
1010
11// test11// test
doc/langref/test_while_break.zig+2-2
...@@ -1,4 +1,4 @@...@@ -1,4 +1,4 @@
1const expect = @import("std").testing.expect;1const expectEqual = @import("std").testing.expectEqual;
22
3test "while break" {3test "while break" {
4 var i: usize = 0;4 var i: usize = 0;
...@@ -7,7 +7,7 @@ test "while break" {...@@ -7,7 +7,7 @@ test "while break" {
7 break;7 break;
8 i += 1;8 i += 1;
9 }9 }
10 try expect(i == 10);10 try expectEqual(10, i);
11}11}
1212
13// test13// test
doc/langref/test_while_continue.zig+2-2
...@@ -1,4 +1,4 @@...@@ -1,4 +1,4 @@
1const expect = @import("std").testing.expect;1const expectEqual = @import("std").testing.expectEqual;
22
3test "while continue" {3test "while continue" {
4 var i: usize = 0;4 var i: usize = 0;
...@@ -8,7 +8,7 @@ test "while continue" {...@@ -8,7 +8,7 @@ test "while continue" {
8 continue;8 continue;
9 break;9 break;
10 }10 }
11 try expect(i == 10);11 try expectEqual(10, i);
12}12}
1313
14// test14// test
doc/langref/test_while_continue_expression.zig+2-1
...@@ -1,9 +1,10 @@...@@ -1,9 +1,10 @@
1const expectEqual = @import("std").testing.expectEqual;
1const expect = @import("std").testing.expect;2const expect = @import("std").testing.expect;
23
3test "while loop continue expression" {4test "while loop continue expression" {
4 var i: usize = 0;5 var i: usize = 0;
5 while (i < 10) : (i += 1) {}6 while (i < 10) : (i += 1) {}
6 try expect(i == 10);7 try expectEqual(10, i);
7}8}
89
9test "while loop continue expression, more complicated" {10test "while loop continue expression, more complicated" {
doc/langref/test_while_error_capture.zig+2-2
...@@ -1,4 +1,4 @@...@@ -1,4 +1,4 @@
1const expect = @import("std").testing.expect;1const expectEqual = @import("std").testing.expectEqual;
22
3test "while error union capture" {3test "while error union capture" {
4 var sum1: u32 = 0;4 var sum1: u32 = 0;
...@@ -6,7 +6,7 @@ test "while error union capture" {...@@ -6,7 +6,7 @@ test "while error union capture" {
6 while (eventuallyErrorSequence()) |value| {6 while (eventuallyErrorSequence()) |value| {
7 sum1 += value;7 sum1 += value;
8 } else |err| {8 } else |err| {
9 try expect(err == error.ReachedZero);9 try expectEqual(error.ReachedZero, err);
10 }10 }
11}11}
1212
doc/langref/test_while_null_capture.zig+4-4
...@@ -1,4 +1,4 @@...@@ -1,4 +1,4 @@
1const expect = @import("std").testing.expect;1const expectEqual = @import("std").testing.expectEqual;
22
3test "while null capture" {3test "while null capture" {
4 var sum1: u32 = 0;4 var sum1: u32 = 0;
...@@ -6,7 +6,7 @@ test "while null capture" {...@@ -6,7 +6,7 @@ test "while null capture" {
6 while (eventuallyNullSequence()) |value| {6 while (eventuallyNullSequence()) |value| {
7 sum1 += value;7 sum1 += value;
8 }8 }
9 try expect(sum1 == 3);9 try expectEqual(3, sum1);
1010
11 // null capture with an else block11 // null capture with an else block
12 var sum2: u32 = 0;12 var sum2: u32 = 0;
...@@ -14,7 +14,7 @@ test "while null capture" {...@@ -14,7 +14,7 @@ test "while null capture" {
14 while (eventuallyNullSequence()) |value| {14 while (eventuallyNullSequence()) |value| {
15 sum2 += value;15 sum2 += value;
16 } else {16 } else {
17 try expect(sum2 == 3);17 try expectEqual(3, sum2);
18 }18 }
1919
20 // null capture with a continue expression20 // null capture with a continue expression
...@@ -24,7 +24,7 @@ test "while null capture" {...@@ -24,7 +24,7 @@ test "while null capture" {
24 while (eventuallyNullSequence()) |value| : (i += 1) {24 while (eventuallyNullSequence()) |value| : (i += 1) {
25 sum3 += value;25 sum3 += value;
26 }26 }
27 try expect(i == 3);27 try expectEqual(3, i);
28}28}
2929
30var numbers_left: u32 = undefined;30var numbers_left: u32 = undefined;
doc/langref/test_wraparound_semantics.zig+3-3
...@@ -1,14 +1,14 @@...@@ -1,14 +1,14 @@
1const std = @import("std");1const std = @import("std");
2const expect = std.testing.expect;2const expectEqual = std.testing.expectEqual;
3const minInt = std.math.minInt;3const minInt = std.math.minInt;
4const maxInt = std.math.maxInt;4const maxInt = std.math.maxInt;
55
6test "wraparound addition and subtraction" {6test "wraparound addition and subtraction" {
7 const x: i32 = maxInt(i32);7 const x: i32 = maxInt(i32);
8 const min_val = x +% 1;8 const min_val = x +% 1;
9 try expect(min_val == minInt(i32));9 try expectEqual(minInt(i32), min_val);
10 const max_val = min_val -% 1;10 const max_val = min_val -% 1;
11 try expect(max_val == maxInt(i32));11 try expectEqual(maxInt(i32), max_val);
12}12}
1313
14// test14// test
doc/langref/testing_detect_leak.zig+1-1
...@@ -6,7 +6,7 @@ test "detect leak" {...@@ -6,7 +6,7 @@ test "detect leak" {
6 // missing `defer list.deinit(gpa);`6 // missing `defer list.deinit(gpa);`
7 try list.append(gpa, '☔');7 try list.append(gpa, '☔');
88
9 try std.testing.expect(list.items.len == 1);9 try std.testing.expectEqual(1, list.items.len);
10}10}
1111
12// test_error=1 tests leaked memory12// test_error=1 tests leaked memory
doc/langref/testing_introduction.zig+5-1
...@@ -7,12 +7,16 @@ test "expect addOne adds one to 41" {...@@ -7,12 +7,16 @@ test "expect addOne adds one to 41" {
7 // It will return an error if its argument is false to indicate a failure.7 // It will return an error if its argument is false to indicate a failure.
8 // `try` is used to return an error to the test runner to notify it that the test failed.8 // `try` is used to return an error to the test runner to notify it that the test failed.
9 try std.testing.expect(addOne(41) == 42);9 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));
10}14}
1115
12test addOne {16test addOne {
13 // A test name can also be written using an identifier.17 // A test name can also be written using an identifier.
14 // This is a doctest, and serves as documentation for `addOne`.18 // 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));
16}20}
1721
18/// The function `addOne` adds one to the number given as its argument.22/// The function `addOne` adds one to the number given as its argument.