authorgravatar for mrpaul@aestheticwisdom.comPaul Espinosa <mrpaul@aestheticwisdom.com> 2020-07-11 09:27:26+07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-10-22 15:54:57-07:00
logddd39b994b1eb9751d06227c6db02f15a5f71e9f
tree0ca901104b628f09ed01446a260daef11a0e9c42
parent1e13e8e8172c1409c5152e8b4e935c5a1d31704b

Use std.testing.expect in language reference samples

In this commit, the code samples in the language reference have been changed to use `std.testing.expect` rather than `std.debug.assert` when they are written in `test` code. This will teach Zig learners best practices when they write their own test code. Not all uses of `std.debug.assert` have been replaced. There are examples where using `assert` fits the context of the sample. Using `std.debug.assert` in test code can lead to errors if running tests in ReleaseFast mode. In ReleaseFast mode, the `unreachable` in `assert` is undefined behavior. It is possible that `assert` always causes `zig test` to pass thus possibly leading to incorrect test code outcomes. The goal is to prevent incorrect code from passing test cases. Closes #5836

1 files changed, 426 insertions(+), 426 deletions(-)

doc/langref.html.in+426-426
......@@ -344,16 +344,16 @@ pub fn main() void {
344344 {#header_close#}
345345 {#header_open|Comments#}
346346 {#code_begin|test|comments#}
347const assert = @import("std").debug.assert;
347const expect = @import("std").testing.expect;
348348
349349test "comments" {
350350 // Comments in Zig start with "//" and end at the next LF byte (end of line).
351351 // The below line is a comment, and won't be executed.
352352
353 //assert(false);
353 //expect(false);
354354
355355 const x = true; // another comment
356 assert(x);
356 expect(x);
357357}
358358 {#code_end#}
359359 <p>
......@@ -695,19 +695,19 @@ pub fn main() void {
695695 and character literals.
696696 </p>
697697 {#code_begin|test#}
698const assert = @import("std").debug.assert;
698const expect = @import("std").testing.expect;
699699const mem = @import("std").mem;
700700
701701test "string literals" {
702702 const bytes = "hello";
703 assert(@TypeOf(bytes) == *const [5:0]u8);
704 assert(bytes.len == 5);
705 assert(bytes[1] == 'e');
706 assert(bytes[5] == 0);
707 assert('e' == '\x65');
708 assert('\u{1f4a9}' == 128169);
709 assert('πŸ’―' == 128175);
710 assert(mem.eql(u8, "hello", "h\x65llo"));
703 expect(@TypeOf(bytes) == *const [5:0]u8);
704 expect(bytes.len == 5);
705 expect(bytes[1] == 'e');
706 expect(bytes[5] == 0);
707 expect('e' == '\x65');
708 expect('\u{1f4a9}' == 128169);
709 expect('πŸ’―' == 128175);
710 expect(mem.eql(u8, "hello", "h\x65llo"));
711711}
712712 {#code_end#}
713713 {#see_also|Arrays|Zig Test|Source Encoding#}
......@@ -800,14 +800,14 @@ test "assignment" {
800800 <p>{#syntax#}const{#endsyntax#} applies to all of the bytes that the identifier immediately addresses. {#link|Pointers#} have their own const-ness.</p>
801801 <p>If you need a variable that you can modify, use the {#syntax#}var{#endsyntax#} keyword:</p>
802802 {#code_begin|test#}
803const assert = @import("std").debug.assert;
803const expect = @import("std").testing.expect;
804804
805805test "var" {
806806 var y: i32 = 5678;
807807
808808 y += 1;
809809
810 assert(y == 5679);
810 expect(y == 5679);
811811}
812812 {#code_end#}
813813 <p>Variables must be initialized:</p>
......@@ -821,12 +821,12 @@ test "initialization" {
821821 {#header_open|undefined#}
822822 <p>Use {#syntax#}undefined{#endsyntax#} to leave variables uninitialized:</p>
823823 {#code_begin|test#}
824const assert = @import("std").debug.assert;
824const expect = @import("std").testing.expect;
825825
826826test "init with undefined" {
827827 var x: i32 = undefined;
828828 x = 1;
829 assert(x == 1);
829 expect(x == 1);
830830}
831831 {#code_end#}
832832 <p>
......@@ -868,8 +868,8 @@ var y: i32 = add(10, x);
868868const x: i32 = add(12, 34);
869869
870870test "global variables" {
871 assert(x == 46);
872 assert(y == 56);
871 expect(x == 46);
872 expect(y == 56);
873873}
874874
875875fn add(a: i32, b: i32) i32 {
......@@ -877,18 +877,18 @@ fn add(a: i32, b: i32) i32 {
877877}
878878
879879const std = @import("std");
880const assert = std.debug.assert;
880const expect = std.testing.expect;
881881 {#code_end#}
882882 <p>
883883 Global variables may be declared inside a {#link|struct#}, {#link|union#}, or {#link|enum#}:
884884 </p>
885885 {#code_begin|test|namespaced_global#}
886886const std = @import("std");
887const assert = std.debug.assert;
887const expect = std.testing.expect;
888888
889889test "namespaced global variable" {
890 assert(foo() == 1235);
891 assert(foo() == 1236);
890 expect(foo() == 1235);
891 expect(foo() == 1236);
892892}
893893
894894fn foo() i32 {
......@@ -957,7 +957,7 @@ fn testTls(context: void) void {
957957 </p>
958958 {#code_begin|test|comptime_vars#}
959959const std = @import("std");
960const assert = std.debug.assert;
960const expect = std.testing.expect;
961961
962962test "comptime vars" {
963963 var x: i32 = 1;
......@@ -966,8 +966,8 @@ test "comptime vars" {
966966 x += 1;
967967 y += 1;
968968
969 assert(x == 2);
970 assert(y == 2);
969 expect(x == 2);
970 expect(y == 2);
971971
972972 if (y != 2) {
973973 // This compile error never triggers because y is a comptime variable,
......@@ -1757,7 +1757,7 @@ orelse catch
17571757 {#header_close#}
17581758 {#header_open|Arrays#}
17591759 {#code_begin|test|arrays#}
1760const assert = @import("std").debug.assert;
1760const expect = @import("std").testing.expect;
17611761const mem = @import("std").mem;
17621762
17631763// array literal
......@@ -1765,14 +1765,14 @@ const message = [_]u8{ 'h', 'e', 'l', 'l', 'o' };
17651765
17661766// get the size of an array
17671767comptime {
1768 assert(message.len == 5);
1768 expect(message.len == 5);
17691769}
17701770
17711771// A string literal is a pointer to an array literal.
17721772const same_message = "hello";
17731773
17741774comptime {
1775 assert(mem.eql(u8, &message, same_message));
1775 expect(mem.eql(u8, &message, same_message));
17761776}
17771777
17781778test "iterate over an array" {
......@@ -1780,7 +1780,7 @@ test "iterate over an array" {
17801780 for (message) |byte| {
17811781 sum += byte;
17821782 }
1783 assert(sum == 'h' + 'e' + 'l' * 2 + 'o');
1783 expect(sum == 'h' + 'e' + 'l' * 2 + 'o');
17841784}
17851785
17861786// modifiable array
......@@ -1790,8 +1790,8 @@ test "modify an array" {
17901790 for (some_integers) |*item, i| {
17911791 item.* = @intCast(i32, i);
17921792 }
1793 assert(some_integers[10] == 10);
1794 assert(some_integers[99] == 99);
1793 expect(some_integers[10] == 10);
1794 expect(some_integers[99] == 99);
17951795}
17961796
17971797// array concatenation works if the values are known
......@@ -1800,7 +1800,7 @@ const part_one = [_]i32{ 1, 2, 3, 4 };
18001800const part_two = [_]i32{ 5, 6, 7, 8 };
18011801const all_of_it = part_one ++ part_two;
18021802comptime {
1803 assert(mem.eql(i32, &all_of_it, &[_]i32{ 1, 2, 3, 4, 5, 6, 7, 8 }));
1803 expect(mem.eql(i32, &all_of_it, &[_]i32{ 1, 2, 3, 4, 5, 6, 7, 8 }));
18041804}
18051805
18061806// remember that string literals are arrays
......@@ -1808,21 +1808,21 @@ const hello = "hello";
18081808const world = "world";
18091809const hello_world = hello ++ " " ++ world;
18101810comptime {
1811 assert(mem.eql(u8, hello_world, "hello world"));
1811 expect(mem.eql(u8, hello_world, "hello world"));
18121812}
18131813
18141814// ** does repeating patterns
18151815const pattern = "ab" ** 3;
18161816comptime {
1817 assert(mem.eql(u8, pattern, "ababab"));
1817 expect(mem.eql(u8, pattern, "ababab"));
18181818}
18191819
18201820// initialize an array to zero
18211821const all_zero = [_]u16{0} ** 10;
18221822
18231823comptime {
1824 assert(all_zero.len == 10);
1825 assert(all_zero[5] == 0);
1824 expect(all_zero.len == 10);
1825 expect(all_zero[5] == 0);
18261826}
18271827
18281828// use compile-time code to initialize an array
......@@ -1842,8 +1842,8 @@ const Point = struct {
18421842};
18431843
18441844test "compile-time array initialization" {
1845 assert(fancy_array[4].x == 4);
1846 assert(fancy_array[4].y == 8);
1845 expect(fancy_array[4].x == 4);
1846 expect(fancy_array[4].y == 8);
18471847}
18481848
18491849// call a function to initialize an array
......@@ -1855,9 +1855,9 @@ fn makePoint(x: i32) Point {
18551855 };
18561856}
18571857test "array initialization with function calls" {
1858 assert(more_points[4].x == 3);
1859 assert(more_points[4].y == 6);
1860 assert(more_points.len == 10);
1858 expect(more_points[4].x == 3);
1859 expect(more_points[4].y == 6);
1860 expect(more_points.len == 10);
18611861}
18621862 {#code_end#}
18631863 {#see_also|for|Slices#}
......@@ -1867,14 +1867,14 @@ test "array initialization with function calls" {
18671867 the type can be omitted from array literals:</p>
18681868 {#code_begin|test|anon_list#}
18691869const std = @import("std");
1870const assert = std.debug.assert;
1870const expect = std.testing.expect;
18711871
18721872test "anonymous list literal syntax" {
18731873 var array: [4]u8 = .{11, 22, 33, 44};
1874 assert(array[0] == 11);
1875 assert(array[1] == 22);
1876 assert(array[2] == 33);
1877 assert(array[3] == 44);
1874 expect(array[0] == 11);
1875 expect(array[1] == 22);
1876 expect(array[2] == 33);
1877 expect(array[3] == 44);
18781878}
18791879 {#code_end#}
18801880 <p>
......@@ -1883,18 +1883,18 @@ test "anonymous list literal syntax" {
18831883 </p>
18841884 {#code_begin|test|infer_list_literal#}
18851885const std = @import("std");
1886const assert = std.debug.assert;
1886const expect = std.testing.expect;
18871887
18881888test "fully anonymous list literal" {
18891889 dump(.{ @as(u32, 1234), @as(f64, 12.34), true, "hi"});
18901890}
18911891
18921892fn dump(args: anytype) void {
1893 assert(args.@"0" == 1234);
1894 assert(args.@"1" == 12.34);
1895 assert(args.@"2");
1896 assert(args.@"3"[0] == 'h');
1897 assert(args.@"3"[1] == 'i');
1893 expect(args.@"0" == 1234);
1894 expect(args.@"1" == 12.34);
1895 expect(args.@"2");
1896 expect(args.@"3"[0] == 'h');
1897 expect(args.@"3"[1] == 'i');
18981898}
18991899 {#code_end#}
19001900 {#header_close#}
......@@ -1905,7 +1905,7 @@ fn dump(args: anytype) void {
19051905 </p>
19061906 {#code_begin|test|multidimensional#}
19071907const std = @import("std");
1908const assert = std.debug.assert;
1908const expect = std.testing.expect;
19091909
19101910const mat4x4 = [4][4]f32{
19111911 [_]f32{ 1.0, 0.0, 0.0, 0.0 },
......@@ -1915,13 +1915,13 @@ const mat4x4 = [4][4]f32{
19151915};
19161916test "multidimensional arrays" {
19171917 // Access the 2D array by indexing the outer array, and then the inner array.
1918 assert(mat4x4[1][1] == 1.0);
1918 expect(mat4x4[1][1] == 1.0);
19191919
19201920 // Here we iterate with for loops.
19211921 for (mat4x4) |row, row_index| {
19221922 for (row) |cell, column_index| {
19231923 if (row_index == column_index) {
1924 assert(cell == 1.0);
1924 expect(cell == 1.0);
19251925 }
19261926 }
19271927 }
......@@ -1936,14 +1936,14 @@ test "multidimensional arrays" {
19361936 </p>
19371937 {#code_begin|test|null_terminated_array#}
19381938const std = @import("std");
1939const assert = std.debug.assert;
1939const expect = std.testing.expect;
19401940
19411941test "null terminated array" {
19421942 const array = [_:0]u8 {1, 2, 3, 4};
19431943
1944 assert(@TypeOf(array) == [4:0]u8);
1945 assert(array.len == 4);
1946 assert(array[4] == 0);
1944 expect(@TypeOf(array) == [4:0]u8);
1945 expect(array.len == 4);
1946 expect(array[4] == 0);
19471947}
19481948 {#code_end#}
19491949 {#see_also|Sentinel-Terminated Pointers|Sentinel-Terminated Slices#}
......@@ -2013,7 +2013,7 @@ test "null terminated array" {
20132013 </ul>
20142014 <p>Use {#syntax#}&x{#endsyntax#} to obtain a single-item pointer:</p>
20152015 {#code_begin|test#}
2016const assert = @import("std").debug.assert;
2016const expect = @import("std").testing.expect;
20172017
20182018test "address of syntax" {
20192019 // Get the address of a variable:
......@@ -2021,17 +2021,17 @@ test "address of syntax" {
20212021 const x_ptr = &x;
20222022
20232023 // Dereference a pointer:
2024 assert(x_ptr.* == 1234);
2024 expect(x_ptr.* == 1234);
20252025
20262026 // When you get the address of a const variable, you get a const pointer to a single item.
2027 assert(@TypeOf(x_ptr) == *const i32);
2027 expect(@TypeOf(x_ptr) == *const i32);
20282028
20292029 // If you want to mutate the value, you'd need an address of a mutable variable:
20302030 var y: i32 = 5678;
20312031 const y_ptr = &y;
2032 assert(@TypeOf(y_ptr) == *i32);
2032 expect(@TypeOf(y_ptr) == *i32);
20332033 y_ptr.* += 1;
2034 assert(y_ptr.* == 5679);
2034 expect(y_ptr.* == 5679);
20352035}
20362036
20372037test "pointer array access" {
......@@ -2040,11 +2040,11 @@ test "pointer array access" {
20402040 // does not support pointer arithmetic.
20412041 var array = [_]u8{ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
20422042 const ptr = &array[2];
2043 assert(@TypeOf(ptr) == *u8);
2043 expect(@TypeOf(ptr) == *u8);
20442044
2045 assert(array[2] == 3);
2045 expect(array[2] == 3);
20462046 ptr.* += 1;
2047 assert(array[2] == 4);
2047 expect(array[2] == 4);
20482048}
20492049 {#code_end#}
20502050 <p>
......@@ -2057,22 +2057,22 @@ test "pointer array access" {
20572057 we prefer slices to pointers.
20582058 </p>
20592059 {#code_begin|test#}
2060const assert = @import("std").debug.assert;
2060const expect = @import("std").testing.expect;
20612061
20622062test "pointer slicing" {
20632063 var array = [_]u8{ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
20642064 const slice = array[2..4];
2065 assert(slice.len == 2);
2065 expect(slice.len == 2);
20662066
2067 assert(array[3] == 4);
2067 expect(array[3] == 4);
20682068 slice[1] += 1;
2069 assert(array[3] == 5);
2069 expect(array[3] == 5);
20702070}
20712071 {#code_end#}
20722072 <p>Pointers work at compile-time too, as long as the code does not depend on
20732073 an undefined memory layout:</p>
20742074 {#code_begin|test#}
2075const assert = @import("std").debug.assert;
2075const expect = @import("std").testing.expect;
20762076
20772077test "comptime pointers" {
20782078 comptime {
......@@ -2080,26 +2080,26 @@ test "comptime pointers" {
20802080 const ptr = &x;
20812081 ptr.* += 1;
20822082 x += 1;
2083 assert(ptr.* == 3);
2083 expect(ptr.* == 3);
20842084 }
20852085}
20862086 {#code_end#}
20872087 <p>To convert an integer address into a pointer, use {#syntax#}@intToPtr{#endsyntax#}.
20882088 To convert a pointer to an integer, use {#syntax#}@ptrToInt{#endsyntax#}:</p>
20892089 {#code_begin|test#}
2090const assert = @import("std").debug.assert;
2090const expect = @import("std").testing.expect;
20912091
20922092test "@ptrToInt and @intToPtr" {
20932093 const ptr = @intToPtr(*i32, 0xdeadbee0);
20942094 const addr = @ptrToInt(ptr);
2095 assert(@TypeOf(addr) == usize);
2096 assert(addr == 0xdeadbee0);
2095 expect(@TypeOf(addr) == usize);
2096 expect(addr == 0xdeadbee0);
20972097}
20982098 {#code_end#}
20992099 <p>Zig is able to preserve memory addresses in comptime code, as long as
21002100 the pointer is never dereferenced:</p>
21012101 {#code_begin|test#}
2102const assert = @import("std").debug.assert;
2102const expect = @import("std").testing.expect;
21032103
21042104test "comptime @intToPtr" {
21052105 comptime {
......@@ -2107,8 +2107,8 @@ test "comptime @intToPtr" {
21072107 // ptr is never dereferenced.
21082108 const ptr = @intToPtr(*i32, 0xdeadbee0);
21092109 const addr = @ptrToInt(ptr);
2110 assert(@TypeOf(addr) == usize);
2111 assert(addr == 0xdeadbee0);
2110 expect(@TypeOf(addr) == usize);
2111 expect(addr == 0xdeadbee0);
21122112 }
21132113}
21142114 {#code_end#}
......@@ -2119,11 +2119,11 @@ test "comptime @intToPtr" {
21192119 In the following code, loads and stores with {#syntax#}mmio_ptr{#endsyntax#} are guaranteed to all happen
21202120 and in the same order as in source code:</p>
21212121 {#code_begin|test#}
2122const assert = @import("std").debug.assert;
2122const expect = @import("std").testing.expect;
21232123
21242124test "volatile" {
21252125 const mmio_ptr = @intToPtr(*volatile u8, 0x12345678);
2126 assert(@TypeOf(mmio_ptr) == *volatile u8);
2126 expect(@TypeOf(mmio_ptr) == *volatile u8);
21272127}
21282128 {#code_end#}
21292129 <p>
......@@ -2139,25 +2139,25 @@ test "volatile" {
21392139 </p>
21402140 {#code_begin|test#}
21412141const std = @import("std");
2142const assert = std.debug.assert;
2142const expect = std.testing.expect;
21432143
21442144test "pointer casting" {
21452145 const bytes align(@alignOf(u32)) = [_]u8{ 0x12, 0x12, 0x12, 0x12 };
21462146 const u32_ptr = @ptrCast(*const u32, &bytes);
2147 assert(u32_ptr.* == 0x12121212);
2147 expect(u32_ptr.* == 0x12121212);
21482148
21492149 // Even this example is contrived - there are better ways to do the above than
21502150 // pointer casting. For example, using a slice narrowing cast:
21512151 const u32_value = std.mem.bytesAsSlice(u32, bytes[0..])[0];
2152 assert(u32_value == 0x12121212);
2152 expect(u32_value == 0x12121212);
21532153
21542154 // And even another way, the most straightforward way to do it:
2155 assert(@bitCast(u32, bytes) == 0x12121212);
2155 expect(@bitCast(u32, bytes) == 0x12121212);
21562156}
21572157
21582158test "pointer child type" {
21592159 // pointer types have a `child` field which tells you the type they point to.
2160 assert(@typeInfo(*u32).Pointer.child == u32);
2160 expect(@typeInfo(*u32).Pointer.child == u32);
21612161}
21622162 {#code_end#}
21632163 {#header_open|Alignment#}
......@@ -2177,15 +2177,15 @@ test "pointer child type" {
21772177 </p>
21782178 {#code_begin|test#}
21792179const std = @import("std");
2180const assert = std.debug.assert;
2180const expect = std.testing.expect;
21812181
21822182test "variable alignment" {
21832183 var x: i32 = 1234;
21842184 const align_of_i32 = @alignOf(@TypeOf(x));
2185 assert(@TypeOf(&x) == *i32);
2186 assert(*i32 == *align(align_of_i32) i32);
2185 expect(@TypeOf(&x) == *i32);
2186 expect(*i32 == *align(align_of_i32) i32);
21872187 if (std.Target.current.cpu.arch == .x86_64) {
2188 assert(@typeInfo(*i32).Pointer.alignment == 4);
2188 expect(@typeInfo(*i32).Pointer.alignment == 4);
21892189 }
21902190}
21912191 {#code_end#}
......@@ -2198,16 +2198,16 @@ test "variable alignment" {
21982198 pointers to them get the specified alignment:
21992199 </p>
22002200 {#code_begin|test#}
2201const assert = @import("std").debug.assert;
2201const expect = @import("std").testing.expect;
22022202
22032203var foo: u8 align(4) = 100;
22042204
22052205test "global variable alignment" {
2206 assert(@typeInfo(@TypeOf(&foo)).Pointer.alignment == 4);
2207 assert(@TypeOf(&foo) == *align(4) u8);
2206 expect(@typeInfo(@TypeOf(&foo)).Pointer.alignment == 4);
2207 expect(@TypeOf(&foo) == *align(4) u8);
22082208 const as_pointer_to_array: *[1]u8 = &foo;
22092209 const as_slice: []u8 = as_pointer_to_array;
2210 assert(@TypeOf(as_slice) == []align(4) u8);
2210 expect(@TypeOf(as_slice) == []align(4) u8);
22112211}
22122212
22132213fn derp() align(@sizeOf(usize) * 2) i32 { return 1234; }
......@@ -2215,9 +2215,9 @@ fn noop1() align(1) void {}
22152215fn noop4() align(4) void {}
22162216
22172217test "function alignment" {
2218 assert(derp() == 1234);
2219 assert(@TypeOf(noop1) == fn() align(1) void);
2220 assert(@TypeOf(noop4) == fn() align(4) void);
2218 expect(derp() == 1234);
2219 expect(@TypeOf(noop1) == fn() align(1) void);
2220 expect(@TypeOf(noop4) == fn() align(4) void);
22212221 noop1();
22222222 noop4();
22232223}
......@@ -2234,7 +2234,7 @@ const std = @import("std");
22342234test "pointer alignment safety" {
22352235 var array align(4) = [_]u32{ 0x11111111, 0x11111111 };
22362236 const bytes = std.mem.sliceAsBytes(array[0..]);
2237 std.debug.assert(foo(bytes) == 0x11111111);
2237 std.testing.expect(foo(bytes) == 0x11111111);
22382238}
22392239fn foo(bytes: []u8) u32 {
22402240 const slice4 = bytes[1..5];
......@@ -2255,12 +2255,12 @@ fn foo(bytes: []u8) u32 {
22552255 </p>
22562256 {#code_begin|test|allowzero#}
22572257const std = @import("std");
2258const assert = std.debug.assert;
2258const expect = std.testing.expect;
22592259
22602260test "allowzero" {
22612261 var zero: usize = 0;
22622262 var ptr = @intToPtr(*allowzero i32, zero);
2263 assert(@ptrToInt(ptr) == 0);
2263 expect(@ptrToInt(ptr) == 0);
22642264}
22652265 {#code_end#}
22662266 {#header_close#}
......@@ -2292,7 +2292,7 @@ pub fn main() anyerror!void {
22922292
22932293 {#header_open|Slices#}
22942294 {#code_begin|test_safety|index out of bounds#}
2295const assert = @import("std").debug.assert;
2295const expect = @import("std").testing.expect;
22962296
22972297test "basic slices" {
22982298 var array = [_]i32{ 1, 2, 3, 4 };
......@@ -2302,14 +2302,14 @@ test "basic slices" {
23022302 // Both can be accessed with the `len` field.
23032303 var known_at_runtime_zero: usize = 0;
23042304 const slice = array[known_at_runtime_zero..array.len];
2305 assert(&slice[0] == &array[0]);
2306 assert(slice.len == array.len);
2305 expect(&slice[0] == &array[0]);
2306 expect(slice.len == array.len);
23072307
23082308 // Using the address-of operator on a slice gives a pointer to a single
23092309 // item, while using the `ptr` field gives an unknown length pointer.
2310 assert(@TypeOf(slice.ptr) == [*]i32);
2311 assert(@TypeOf(&slice[0]) == *i32);
2312 assert(@ptrToInt(slice.ptr) == @ptrToInt(&slice[0]));
2310 expect(@TypeOf(slice.ptr) == [*]i32);
2311 expect(@TypeOf(&slice[0]) == *i32);
2312 expect(@ptrToInt(slice.ptr) == @ptrToInt(&slice[0]));
23132313
23142314 // Slices have array bounds checking. If you try to access something out
23152315 // of bounds, you'll get a safety check failure:
......@@ -2322,7 +2322,7 @@ test "basic slices" {
23222322 <p>This is one reason we prefer slices to pointers.</p>
23232323 {#code_begin|test|slices#}
23242324const std = @import("std");
2325const assert = std.debug.assert;
2325const expect = std.testing.expect;
23262326const mem = std.mem;
23272327const fmt = std.fmt;
23282328
......@@ -2343,7 +2343,7 @@ test "using slices for strings" {
23432343 // Generally, you can use UTF-8 and not worry about whether something is a
23442344 // string. If you don't need to deal with individual characters, no need
23452345 // to decode.
2346 assert(mem.eql(u8, hello_world, "hello δΈ–η•Œ"));
2346 expect(mem.eql(u8, hello_world, "hello δΈ–η•Œ"));
23472347}
23482348
23492349test "slice pointer" {
......@@ -2353,16 +2353,16 @@ test "slice pointer" {
23532353 // You can use slicing syntax to convert a pointer into a slice:
23542354 const slice = ptr[0..5];
23552355 slice[2] = 3;
2356 assert(slice[2] == 3);
2356 expect(slice[2] == 3);
23572357 // The slice is mutable because we sliced a mutable pointer.
23582358 // Furthermore, it is actually a pointer to an array, since the start
23592359 // and end indexes were both comptime-known.
2360 assert(@TypeOf(slice) == *[5]u8);
2360 expect(@TypeOf(slice) == *[5]u8);
23612361
23622362 // You can also slice a slice:
23632363 const slice2 = slice[2..3];
2364 assert(slice2.len == 1);
2365 assert(slice2[0] == 3);
2364 expect(slice2.len == 1);
2365 expect(slice2[0] == 3);
23662366}
23672367 {#code_end#}
23682368 {#see_also|Pointers|for|Arrays#}
......@@ -2376,13 +2376,13 @@ test "slice pointer" {
23762376 </p>
23772377 {#code_begin|test|null_terminated_slice#}
23782378const std = @import("std");
2379const assert = std.debug.assert;
2379const expect = std.testing.expect;
23802380
23812381test "null terminated slice" {
23822382 const slice: [:0]const u8 = "hello";
23832383
2384 assert(slice.len == 5);
2385 assert(slice[5] == 0);
2384 expect(slice.len == 5);
2385 expect(slice[5] == 0);
23862386}
23872387 {#code_end#}
23882388 {#see_also|Sentinel-Terminated Pointers|Sentinel-Terminated Arrays#}
......@@ -2440,16 +2440,16 @@ const Vec3 = struct {
24402440 }
24412441};
24422442
2443const assert = @import("std").debug.assert;
2443const expect = @import("std").testing.expect;
24442444test "dot product" {
24452445 const v1 = Vec3.init(1.0, 0.0, 0.0);
24462446 const v2 = Vec3.init(0.0, 1.0, 0.0);
2447 assert(v1.dot(v2) == 0.0);
2447 expect(v1.dot(v2) == 0.0);
24482448
24492449 // Other than being available to call with dot syntax, struct methods are
24502450 // not special. You can reference them as any other declaration inside
24512451 // the struct:
2452 assert(Vec3.dot(v1, v2) == 0.0);
2452 expect(Vec3.dot(v1, v2) == 0.0);
24532453}
24542454
24552455// Structs can have global declarations.
......@@ -2458,8 +2458,8 @@ const Empty = struct {
24582458 pub const PI = 3.14;
24592459};
24602460test "struct namespaced variable" {
2461 assert(Empty.PI == 3.14);
2462 assert(@sizeOf(Empty) == 0);
2461 expect(Empty.PI == 3.14);
2462 expect(@sizeOf(Empty) == 0);
24632463
24642464 // you can still instantiate an empty struct
24652465 const does_nothing = Empty {};
......@@ -2477,7 +2477,7 @@ test "field parent pointer" {
24772477 .y = 0.5678,
24782478 };
24792479 setYBasedOnX(&point.x, 0.9);
2480 assert(point.y == 0.9);
2480 expect(point.y == 0.9);
24812481}
24822482
24832483// You can return a struct from a function. This is how we do generics
......@@ -2499,19 +2499,19 @@ fn LinkedList(comptime T: type) type {
24992499test "linked list" {
25002500 // Functions called at compile-time are memoized. This means you can
25012501 // do this:
2502 assert(LinkedList(i32) == LinkedList(i32));
2502 expect(LinkedList(i32) == LinkedList(i32));
25032503
25042504 var list = LinkedList(i32) {
25052505 .first = null,
25062506 .last = null,
25072507 .len = 0,
25082508 };
2509 assert(list.len == 0);
2509 expect(list.len == 0);
25102510
25112511 // Since types are first class values you can instantiate the type
25122512 // by assigning it to a variable:
25132513 const ListOfInts = LinkedList(i32);
2514 assert(ListOfInts == LinkedList(i32));
2514 expect(ListOfInts == LinkedList(i32));
25152515
25162516 var node = ListOfInts.Node {
25172517 .prev = null,
......@@ -2523,7 +2523,7 @@ test "linked list" {
25232523 .last = &node,
25242524 .len = 1,
25252525 };
2526 assert(list2.first.?.data == 1234);
2526 expect(list2.first.?.data == 1234);
25272527}
25282528 {#code_end#}
25292529
......@@ -2584,7 +2584,7 @@ test "default struct initialization fields" {
25842584 {#code_begin|test#}
25852585const std = @import("std");
25862586const builtin = std.builtin;
2587const assert = std.debug.assert;
2587const expect = std.testing.expect;
25882588
25892589const Full = packed struct {
25902590 number: u16,
......@@ -2601,20 +2601,20 @@ test "@bitCast between packed structs" {
26012601}
26022602
26032603fn doTheTest() void {
2604 assert(@sizeOf(Full) == 2);
2605 assert(@sizeOf(Divided) == 2);
2604 expect(@sizeOf(Full) == 2);
2605 expect(@sizeOf(Divided) == 2);
26062606 var full = Full{ .number = 0x1234 };
26072607 var divided = @bitCast(Divided, full);
26082608 switch (builtin.endian) {
26092609 .Big => {
2610 assert(divided.half1 == 0x12);
2611 assert(divided.quarter3 == 0x3);
2612 assert(divided.quarter4 == 0x4);
2610 expect(divided.half1 == 0x12);
2611 expect(divided.quarter3 == 0x3);
2612 expect(divided.quarter4 == 0x4);
26132613 },
26142614 .Little => {
2615 assert(divided.half1 == 0x34);
2616 assert(divided.quarter3 == 0x2);
2617 assert(divided.quarter4 == 0x1);
2615 expect(divided.half1 == 0x34);
2616 expect(divided.quarter3 == 0x2);
2617 expect(divided.quarter4 == 0x1);
26182618 },
26192619 }
26202620}
......@@ -2624,7 +2624,7 @@ fn doTheTest() void {
26242624 </p>
26252625 {#code_begin|test#}
26262626const std = @import("std");
2627const assert = std.debug.assert;
2627const expect = std.testing.expect;
26282628
26292629const BitField = packed struct {
26302630 a: u3,
......@@ -2640,7 +2640,7 @@ var foo = BitField{
26402640
26412641test "pointer to non-byte-aligned field" {
26422642 const ptr = &foo.b;
2643 assert(ptr.* == 2);
2643 expect(ptr.* == 2);
26442644}
26452645 {#code_end#}
26462646 <p>
......@@ -2649,7 +2649,7 @@ test "pointer to non-byte-aligned field" {
26492649 </p>
26502650 {#code_begin|test_err|expected type#}
26512651const std = @import("std");
2652const assert = std.debug.assert;
2652const expect = std.testing.expect;
26532653
26542654const BitField = packed struct {
26552655 a: u3,
......@@ -2664,7 +2664,7 @@ var bit_field = BitField{
26642664};
26652665
26662666test "pointer to non-bit-aligned field" {
2667 assert(bar(&bit_field.b) == 2);
2667 expect(bar(&bit_field.b) == 2);
26682668}
26692669
26702670fn bar(x: *const u3) u3 {
......@@ -2680,7 +2680,7 @@ fn bar(x: *const u3) u3 {
26802680 </p>
26812681 {#code_begin|test#}
26822682const std = @import("std");
2683const assert = std.debug.assert;
2683const expect = std.testing.expect;
26842684
26852685const BitField = packed struct {
26862686 a: u3,
......@@ -2695,8 +2695,8 @@ var bit_field = BitField{
26952695};
26962696
26972697test "pointer to non-bit-aligned field" {
2698 assert(@ptrToInt(&bit_field.a) == @ptrToInt(&bit_field.b));
2699 assert(@ptrToInt(&bit_field.a) == @ptrToInt(&bit_field.c));
2698 expect(@ptrToInt(&bit_field.a) == @ptrToInt(&bit_field.b));
2699 expect(@ptrToInt(&bit_field.a) == @ptrToInt(&bit_field.c));
27002700}
27012701 {#code_end#}
27022702 <p>
......@@ -2704,7 +2704,7 @@ test "pointer to non-bit-aligned field" {
27042704 </p>
27052705 {#code_begin|test#}
27062706const std = @import("std");
2707const assert = std.debug.assert;
2707const expect = std.testing.expect;
27082708
27092709const BitField = packed struct {
27102710 a: u3,
......@@ -2714,13 +2714,13 @@ const BitField = packed struct {
27142714
27152715test "pointer to non-bit-aligned field" {
27162716 comptime {
2717 assert(@bitOffsetOf(BitField, "a") == 0);
2718 assert(@bitOffsetOf(BitField, "b") == 3);
2719 assert(@bitOffsetOf(BitField, "c") == 6);
2717 expect(@bitOffsetOf(BitField, "a") == 0);
2718 expect(@bitOffsetOf(BitField, "b") == 3);
2719 expect(@bitOffsetOf(BitField, "c") == 6);
27202720
2721 assert(@byteOffsetOf(BitField, "a") == 0);
2722 assert(@byteOffsetOf(BitField, "b") == 0);
2723 assert(@byteOffsetOf(BitField, "c") == 0);
2721 expect(@byteOffsetOf(BitField, "a") == 0);
2722 expect(@byteOffsetOf(BitField, "b") == 0);
2723 expect(@byteOffsetOf(BitField, "c") == 0);
27242724 }
27252725}
27262726 {#code_end#}
......@@ -2791,7 +2791,7 @@ fn List(comptime T: type) type {
27912791 </p>
27922792 {#code_begin|test|struct_result#}
27932793const std = @import("std");
2794const assert = std.debug.assert;
2794const expect = std.testing.expect;
27952795
27962796const Point = struct {x: i32, y: i32};
27972797
......@@ -2800,8 +2800,8 @@ test "anonymous struct literal" {
28002800 .x = 13,
28012801 .y = 67,
28022802 };
2803 assert(pt.x == 13);
2804 assert(pt.y == 67);
2803 expect(pt.x == 13);
2804 expect(pt.y == 67);
28052805}
28062806 {#code_end#}
28072807 <p>
......@@ -2810,7 +2810,7 @@ test "anonymous struct literal" {
28102810 </p>
28112811 {#code_begin|test|struct_anon#}
28122812const std = @import("std");
2813const assert = std.debug.assert;
2813const expect = std.testing.expect;
28142814
28152815test "fully anonymous struct" {
28162816 dump(.{
......@@ -2822,11 +2822,11 @@ test "fully anonymous struct" {
28222822}
28232823
28242824fn dump(args: anytype) void {
2825 assert(args.int == 1234);
2826 assert(args.float == 12.34);
2827 assert(args.b);
2828 assert(args.s[0] == 'h');
2829 assert(args.s[1] == 'i');
2825 expect(args.int == 1234);
2826 expect(args.float == 12.34);
2827 expect(args.b);
2828 expect(args.s[0] == 'h');
2829 expect(args.s[1] == 'i');
28302830}
28312831 {#code_end#}
28322832 {#header_close#}
......@@ -2834,7 +2834,7 @@ fn dump(args: anytype) void {
28342834 {#header_close#}
28352835 {#header_open|enum#}
28362836 {#code_begin|test|enums#}
2837const assert = @import("std").debug.assert;
2837const expect = @import("std").testing.expect;
28382838const mem = @import("std").mem;
28392839
28402840// Declare an enum.
......@@ -2857,9 +2857,9 @@ const Value = enum(u2) {
28572857// Now you can cast between u2 and Value.
28582858// The ordinal value starts from 0, counting up for each member.
28592859test "enum ordinal value" {
2860 assert(@enumToInt(Value.zero) == 0);
2861 assert(@enumToInt(Value.one) == 1);
2862 assert(@enumToInt(Value.two) == 2);
2860 expect(@enumToInt(Value.zero) == 0);
2861 expect(@enumToInt(Value.one) == 1);
2862 expect(@enumToInt(Value.two) == 2);
28632863}
28642864
28652865// You can override the ordinal value for an enum.
......@@ -2869,9 +2869,9 @@ const Value2 = enum(u32) {
28692869 million = 1000000,
28702870};
28712871test "set enum ordinal value" {
2872 assert(@enumToInt(Value2.hundred) == 100);
2873 assert(@enumToInt(Value2.thousand) == 1000);
2874 assert(@enumToInt(Value2.million) == 1000000);
2872 expect(@enumToInt(Value2.hundred) == 100);
2873 expect(@enumToInt(Value2.thousand) == 1000);
2874 expect(@enumToInt(Value2.million) == 1000000);
28752875}
28762876
28772877// Enums can have methods, the same as structs and unions.
......@@ -2889,7 +2889,7 @@ const Suit = enum {
28892889};
28902890test "enum method" {
28912891 const p = Suit.spades;
2892 assert(!p.isClubs());
2892 expect(!p.isClubs());
28932893}
28942894
28952895// An enum variant of different types can be switched upon.
......@@ -2905,7 +2905,7 @@ test "enum variant switch" {
29052905 Foo.number => "this is a number",
29062906 Foo.none => "this is a none",
29072907 };
2908 assert(mem.eql(u8, what_is_it, "this is a number"));
2908 expect(mem.eql(u8, what_is_it, "this is a number"));
29092909}
29102910
29112911// @TagType can be used to access the integer tag type of an enum.
......@@ -2916,18 +2916,18 @@ const Small = enum {
29162916 four,
29172917};
29182918test "@TagType" {
2919 assert(@TagType(Small) == u2);
2919 expect(@TagType(Small) == u2);
29202920}
29212921
29222922// @typeInfo tells us the field count and the fields names:
29232923test "@typeInfo" {
2924 assert(@typeInfo(Small).Enum.fields.len == 4);
2925 assert(mem.eql(u8, @typeInfo(Small).Enum.fields[1].name, "two"));
2924 expect(@typeInfo(Small).Enum.fields.len == 4);
2925 expect(mem.eql(u8, @typeInfo(Small).Enum.fields[1].name, "two"));
29262926}
29272927
29282928// @tagName gives a []const u8 representation of an enum value:
29292929test "@tagName" {
2930 assert(mem.eql(u8, @tagName(Small.three), "three"));
2930 expect(mem.eql(u8, @tagName(Small.three), "three"));
29312931}
29322932 {#code_end#}
29332933 {#see_also|@typeInfo|@tagName|@sizeOf#}
......@@ -2962,7 +2962,7 @@ test "packed enum" {
29622962 two,
29632963 three,
29642964 };
2965 std.debug.assert(@sizeOf(Number) == @sizeOf(u8));
2965 std.testing.expect(@sizeOf(Number) == @sizeOf(u8));
29662966}
29672967 {#code_end#}
29682968 <p>This makes the enum eligible to be in a {#link|packed struct#}.</p>
......@@ -2974,7 +2974,7 @@ test "packed enum" {
29742974 </p>
29752975 {#code_begin|test#}
29762976const std = @import("std");
2977const assert = std.debug.assert;
2977const expect = std.testing.expect;
29782978
29792979const Color = enum {
29802980 auto,
......@@ -2985,7 +2985,7 @@ const Color = enum {
29852985test "enum literals" {
29862986 const color1: Color = .auto;
29872987 const color2 = Color.auto;
2988 assert(color1 == color2);
2988 expect(color1 == color2);
29892989}
29902990
29912991test "switch using enum literals" {
......@@ -2995,7 +2995,7 @@ test "switch using enum literals" {
29952995 .on => true,
29962996 .off => false,
29972997 };
2998 assert(result);
2998 expect(result);
29992999}
30003000 {#code_end#}
30013001 {#header_close#}
......@@ -3014,7 +3014,7 @@ test "switch using enum literals" {
30143014 </p>
30153015 {#code_begin|test#}
30163016const std = @import("std");
3017const assert = std.debug.assert;
3017const expect = std.testing.expect;
30183018
30193019const Number = enum(u8) {
30203020 one,
......@@ -3031,12 +3031,12 @@ test "switch on non-exhaustive enum" {
30313031 .three => false,
30323032 _ => false,
30333033 };
3034 assert(result);
3034 expect(result);
30353035 const is_one = switch (number) {
30363036 .one => true,
30373037 else => false,
30383038 };
3039 assert(is_one);
3039 expect(is_one);
30403040}
30413041 {#code_end#}
30423042 {#header_close#}
......@@ -3067,7 +3067,7 @@ test "simple union" {
30673067 <p>You can activate another field by assigning the entire union:</p>
30683068 {#code_begin|test#}
30693069const std = @import("std");
3070const assert = std.debug.assert;
3070const expect = std.testing.expect;
30713071
30723072const Payload = union {
30733073 int: i64,
......@@ -3076,9 +3076,9 @@ const Payload = union {
30763076};
30773077test "simple union" {
30783078 var payload = Payload{ .int = 1234 };
3079 assert(payload.int == 1234);
3079 expect(payload.int == 1234);
30803080 payload = Payload{ .float = 12.34 };
3081 assert(payload.float == 12.34);
3081 expect(payload.float == 12.34);
30823082}
30833083 {#code_end#}
30843084 <p>
......@@ -3097,7 +3097,7 @@ test "simple union" {
30973097 </p>
30983098 {#code_begin|test#}
30993099const std = @import("std");
3100const assert = std.debug.assert;
3100const expect = std.testing.expect;
31013101
31023102const ComplexTypeTag = enum {
31033103 ok,
......@@ -3110,24 +3110,24 @@ const ComplexType = union(ComplexTypeTag) {
31103110
31113111test "switch on tagged union" {
31123112 const c = ComplexType{ .ok = 42 };
3113 assert(@as(ComplexTypeTag, c) == ComplexTypeTag.ok);
3113 expect(@as(ComplexTypeTag, c) == ComplexTypeTag.ok);
31143114
31153115 switch (c) {
3116 ComplexTypeTag.ok => |value| assert(value == 42),
3116 ComplexTypeTag.ok => |value| expect(value == 42),
31173117 ComplexTypeTag.not_ok => unreachable,
31183118 }
31193119}
31203120
31213121test "@TagType" {
3122 assert(@TagType(ComplexType) == ComplexTypeTag);
3122 expect(@TagType(ComplexType) == ComplexTypeTag);
31233123}
31243124
31253125test "coerce to enum" {
31263126 const c1 = ComplexType{ .ok = 42 };
31273127 const c2 = ComplexType.not_ok;
31283128
3129 assert(c1 == .ok);
3130 assert(c2 == .not_ok);
3129 expect(c1 == .ok);
3130 expect(c2 == .not_ok);
31313131}
31323132 {#code_end#}
31333133 <p>In order to modify the payload of a tagged union in a switch expression,
......@@ -3135,7 +3135,7 @@ test "coerce to enum" {
31353135 </p>
31363136 {#code_begin|test#}
31373137const std = @import("std");
3138const assert = std.debug.assert;
3138const expect = std.testing.expect;
31393139
31403140const ComplexTypeTag = enum {
31413141 ok,
......@@ -3148,14 +3148,14 @@ const ComplexType = union(ComplexTypeTag) {
31483148
31493149test "modify tagged union in switch" {
31503150 var c = ComplexType{ .ok = 42 };
3151 assert(@as(ComplexTypeTag, c) == ComplexTypeTag.ok);
3151 expect(@as(ComplexTypeTag, c) == ComplexTypeTag.ok);
31523152
31533153 switch (c) {
31543154 ComplexTypeTag.ok => |*value| value.* += 1,
31553155 ComplexTypeTag.not_ok => unreachable,
31563156 }
31573157
3158 assert(c.ok == 43);
3158 expect(c.ok == 43);
31593159}
31603160 {#code_end#}
31613161 <p>
......@@ -3164,7 +3164,7 @@ test "modify tagged union in switch" {
31643164 </p>
31653165 {#code_begin|test#}
31663166const std = @import("std");
3167const assert = std.debug.assert;
3167const expect = std.testing.expect;
31683168
31693169const Variant = union(enum) {
31703170 int: i32,
......@@ -3186,8 +3186,8 @@ test "union method" {
31863186 var v1 = Variant{ .int = 1 };
31873187 var v2 = Variant{ .boolean = false };
31883188
3189 assert(v1.truthy());
3190 assert(!v2.truthy());
3189 expect(v1.truthy());
3190 expect(!v2.truthy());
31913191}
31923192 {#code_end#}
31933193 <p>
......@@ -3196,7 +3196,7 @@ test "union method" {
31963196 </p>
31973197 {#code_begin|test#}
31983198const std = @import("std");
3199const assert = std.debug.assert;
3199const expect = std.testing.expect;
32003200
32013201const Small2 = union(enum) {
32023202 a: i32,
......@@ -3204,7 +3204,7 @@ const Small2 = union(enum) {
32043204 c: u8,
32053205};
32063206test "@tagName" {
3207 assert(std.mem.eql(u8, @tagName(Small2.a), "a"));
3207 expect(std.mem.eql(u8, @tagName(Small2.a), "a"));
32083208}
32093209 {#code_end#}
32103210 {#header_close#}
......@@ -3227,7 +3227,7 @@ test "@tagName" {
32273227 the type:</p>
32283228 {#code_begin|test|anon_union#}
32293229const std = @import("std");
3230const assert = std.debug.assert;
3230const expect = std.testing.expect;
32313231
32323232const Number = union {
32333233 int: i32,
......@@ -3237,8 +3237,8 @@ const Number = union {
32373237test "anonymous union literal syntax" {
32383238 var i: Number = .{.int = 42};
32393239 var f = makeNumber();
3240 assert(i.int == 42);
3241 assert(f.float == 12.34);
3240 expect(i.int == 42);
3241 expect(f.float == 12.34);
32423242}
32433243
32443244fn makeNumber() Number {
......@@ -3291,7 +3291,7 @@ test "access variable after block scope" {
32913291 </p>
32923292 {#code_begin|test#}
32933293const std = @import("std");
3294const assert = std.debug.assert;
3294const expect = std.testing.expect;
32953295
32963296test "labeled break from labeled block expression" {
32973297 var y: i32 = 123;
......@@ -3300,8 +3300,8 @@ test "labeled break from labeled block expression" {
33003300 y += 1;
33013301 break :blk y;
33023302 };
3303 assert(x == 124);
3304 assert(y == 124);
3303 expect(x == 124);
3304 expect(y == 124);
33053305}
33063306 {#code_end#}
33073307 <p>Here, {#syntax#}blk{#endsyntax#} can be any name.</p>
......@@ -3339,7 +3339,7 @@ test "separate scopes" {
33393339 {#header_open|switch#}
33403340 {#code_begin|test|switch#}
33413341const std = @import("std");
3342const assert = std.debug.assert;
3342const expect = std.testing.expect;
33433343
33443344test "switch simple" {
33453345 const a: u64 = 10;
......@@ -3379,7 +3379,7 @@ test "switch simple" {
33793379 else => 9,
33803380 };
33813381
3382 assert(b == 1);
3382 expect(b == 1);
33833383}
33843384
33853385// Switch expressions can be used outside a function:
......@@ -3409,7 +3409,7 @@ test "switch inside function" {
34093409 turning it into a pointer.
34103410 </p>
34113411 {#code_begin|test#}
3412const assert = @import("std").debug.assert;
3412const expect = @import("std").testing.expect;
34133413
34143414test "switch on tagged union" {
34153415 const Point = struct {
......@@ -3442,8 +3442,8 @@ test "switch on tagged union" {
34423442 Item.d => 8,
34433443 };
34443444
3445 assert(b == 6);
3446 assert(a.c.x == 2);
3445 expect(b == 6);
3446 expect(a.c.x == 2);
34473447}
34483448 {#code_end#}
34493449 {#see_also|comptime|enum|@compileError|Compile Variables#}
......@@ -3477,7 +3477,7 @@ test "exhaustive switching" {
34773477 </p>
34783478 {#code_begin|test#}
34793479const std = @import("std");
3480const assert = std.debug.assert;
3480const expect = std.testing.expect;
34813481
34823482const Color = enum {
34833483 auto,
......@@ -3492,7 +3492,7 @@ test "enum literals with switch" {
34923492 .on => false,
34933493 .off => true,
34943494 };
3495 assert(result);
3495 expect(result);
34963496}
34973497 {#code_end#}
34983498 {#header_close#}
......@@ -3504,21 +3504,21 @@ test "enum literals with switch" {
35043504 some condition is no longer true.
35053505 </p>
35063506 {#code_begin|test|while#}
3507const assert = @import("std").debug.assert;
3507const expect = @import("std").testing.expect;
35083508
35093509test "while basic" {
35103510 var i: usize = 0;
35113511 while (i < 10) {
35123512 i += 1;
35133513 }
3514 assert(i == 10);
3514 expect(i == 10);
35153515}
35163516 {#code_end#}
35173517 <p>
35183518 Use {#syntax#}break{#endsyntax#} to exit a while loop early.
35193519 </p>
35203520 {#code_begin|test|while#}
3521const assert = @import("std").debug.assert;
3521const expect = @import("std").testing.expect;
35223522
35233523test "while break" {
35243524 var i: usize = 0;
......@@ -3527,14 +3527,14 @@ test "while break" {
35273527 break;
35283528 i += 1;
35293529 }
3530 assert(i == 10);
3530 expect(i == 10);
35313531}
35323532 {#code_end#}
35333533 <p>
35343534 Use {#syntax#}continue{#endsyntax#} to jump back to the beginning of the loop.
35353535 </p>
35363536 {#code_begin|test|while#}
3537const assert = @import("std").debug.assert;
3537const expect = @import("std").testing.expect;
35383538
35393539test "while continue" {
35403540 var i: usize = 0;
......@@ -3544,7 +3544,7 @@ test "while continue" {
35443544 continue;
35453545 break;
35463546 }
3547 assert(i == 10);
3547 expect(i == 10);
35483548}
35493549 {#code_end#}
35503550 <p>
......@@ -3552,12 +3552,12 @@ test "while continue" {
35523552 is continued. The {#syntax#}continue{#endsyntax#} keyword respects this expression.
35533553 </p>
35543554 {#code_begin|test|while#}
3555const assert = @import("std").debug.assert;
3555const expect = @import("std").testing.expect;
35563556
35573557test "while loop continue expression" {
35583558 var i: usize = 0;
35593559 while (i < 10) : (i += 1) {}
3560 assert(i == 10);
3560 expect(i == 10);
35613561}
35623562
35633563test "while loop continue expression, more complicated" {
......@@ -3565,7 +3565,7 @@ test "while loop continue expression, more complicated" {
35653565 var j: usize = 1;
35663566 while (i * j < 2000) : ({ i *= 2; j *= 3; }) {
35673567 const my_ij = i * j;
3568 assert(my_ij < 2000);
3568 expect(my_ij < 2000);
35693569 }
35703570}
35713571 {#code_end#}
......@@ -3581,11 +3581,11 @@ test "while loop continue expression, more complicated" {
35813581 evaluated.
35823582 </p>
35833583 {#code_begin|test|while#}
3584const assert = @import("std").debug.assert;
3584const expect = @import("std").testing.expect;
35853585
35863586test "while else" {
3587 assert(rangeHasNumber(0, 10, 5));
3588 assert(!rangeHasNumber(0, 10, 15));
3587 expect(rangeHasNumber(0, 10, 5));
3588 expect(!rangeHasNumber(0, 10, 15));
35893589}
35903590
35913591fn rangeHasNumber(begin: usize, end: usize, number: usize) bool {
......@@ -3634,7 +3634,7 @@ test "nested continue" {
36343634 be executed on the first null value encountered.
36353635 </p>
36363636 {#code_begin|test|while#}
3637const assert = @import("std").debug.assert;
3637const expect = @import("std").testing.expect;
36383638
36393639test "while null capture" {
36403640 var sum1: u32 = 0;
......@@ -3642,14 +3642,14 @@ test "while null capture" {
36423642 while (eventuallyNullSequence()) |value| {
36433643 sum1 += value;
36443644 }
3645 assert(sum1 == 3);
3645 expect(sum1 == 3);
36463646
36473647 var sum2: u32 = 0;
36483648 numbers_left = 3;
36493649 while (eventuallyNullSequence()) |value| {
36503650 sum2 += value;
36513651 } else {
3652 assert(sum2 == 3);
3652 expect(sum2 == 3);
36533653 }
36543654}
36553655
......@@ -3676,7 +3676,7 @@ fn eventuallyNullSequence() ?u32 {
36763676 the while condition must have an {#link|Error Union Type#}.
36773677 </p>
36783678 {#code_begin|test|while#}
3679const assert = @import("std").debug.assert;
3679const expect = @import("std").testing.expect;
36803680
36813681test "while error union capture" {
36823682 var sum1: u32 = 0;
......@@ -3684,7 +3684,7 @@ test "while error union capture" {
36843684 while (eventuallyErrorSequence()) |value| {
36853685 sum1 += value;
36863686 } else |err| {
3687 assert(err == error.ReachedZero);
3687 expect(err == error.ReachedZero);
36883688 }
36893689}
36903690
......@@ -3706,7 +3706,7 @@ fn eventuallyErrorSequence() anyerror!u32 {
37063706 such as use types as first class values.
37073707 </p>
37083708 {#code_begin|test#}
3709const assert = @import("std").debug.assert;
3709const expect = @import("std").testing.expect;
37103710
37113711test "inline while loop" {
37123712 comptime var i = 0;
......@@ -3720,7 +3720,7 @@ test "inline while loop" {
37203720 };
37213721 sum += typeNameLength(T);
37223722 }
3723 assert(sum == 9);
3723 expect(sum == 9);
37243724}
37253725
37263726fn typeNameLength(comptime T: type) usize {
......@@ -3741,7 +3741,7 @@ fn typeNameLength(comptime T: type) usize {
37413741 {#header_close#}
37423742 {#header_open|for#}
37433743 {#code_begin|test|for#}
3744const assert = @import("std").debug.assert;
3744const expect = @import("std").testing.expect;
37453745
37463746test "for basics" {
37473747 const items = [_]i32 { 4, 5, 3, 4, 0 };
......@@ -3755,22 +3755,22 @@ test "for basics" {
37553755 }
37563756 sum += value;
37573757 }
3758 assert(sum == 16);
3758 expect(sum == 16);
37593759
37603760 // To iterate over a portion of a slice, reslice.
37613761 for (items[0..1]) |value| {
37623762 sum += value;
37633763 }
3764 assert(sum == 20);
3764 expect(sum == 20);
37653765
37663766 // To access the index of iteration, specify a second capture value.
37673767 // This is zero-indexed.
37683768 var sum2: i32 = 0;
37693769 for (items) |value, i| {
3770 assert(@TypeOf(i) == usize);
3770 expect(@TypeOf(i) == usize);
37713771 sum2 += @intCast(i32, i);
37723772 }
3773 assert(sum2 == 10);
3773 expect(sum2 == 10);
37743774}
37753775
37763776test "for reference" {
......@@ -3782,9 +3782,9 @@ test "for reference" {
37823782 value.* += 1;
37833783 }
37843784
3785 assert(items[0] == 4);
3786 assert(items[1] == 5);
3787 assert(items[2] == 3);
3785 expect(items[0] == 4);
3786 expect(items[1] == 5);
3787 expect(items[2] == 3);
37883788}
37893789
37903790test "for else" {
......@@ -3799,10 +3799,10 @@ test "for else" {
37993799 sum += value.?;
38003800 }
38013801 } else blk: {
3802 assert(sum == 12);
3802 expect(sum == 12);
38033803 break :blk sum;
38043804 };
3805 assert(result == 12);
3805 expect(result == 12);
38063806}
38073807 {#code_end#}
38083808 {#header_open|Labeled for#}
......@@ -3810,7 +3810,7 @@ test "for else" {
38103810 or {#syntax#}continue{#endsyntax#} from within a nested loop:</p>
38113811 {#code_begin|test#}
38123812const std = @import("std");
3813const assert = std.debug.assert;
3813const expect = std.testing.expect;
38143814
38153815test "nested break" {
38163816 var count: usize = 0;
......@@ -3820,7 +3820,7 @@ test "nested break" {
38203820 break :outer;
38213821 }
38223822 }
3823 assert(count == 1);
3823 expect(count == 1);
38243824}
38253825
38263826test "nested continue" {
......@@ -3832,7 +3832,7 @@ test "nested continue" {
38323832 }
38333833 }
38343834
3835 assert(count == 8);
3835 expect(count == 8);
38363836}
38373837 {#code_end#}
38383838 {#header_close#}
......@@ -3845,7 +3845,7 @@ test "nested continue" {
38453845 compile-time known.
38463846 </p>
38473847 {#code_begin|test#}
3848const assert = @import("std").debug.assert;
3848const expect = @import("std").testing.expect;
38493849
38503850test "inline for loop" {
38513851 const nums = [_]i32{2, 4, 6};
......@@ -3859,7 +3859,7 @@ test "inline for loop" {
38593859 };
38603860 sum += typeNameLength(T);
38613861 }
3862 assert(sum == 9);
3862 expect(sum == 9);
38633863}
38643864
38653865fn typeNameLength(comptime T: type) usize {
......@@ -3885,14 +3885,14 @@ fn typeNameLength(comptime T: type) usize {
38853885// * ?T
38863886// * anyerror!T
38873887
3888const assert = @import("std").debug.assert;
3888const expect = @import("std").testing.expect;
38893889
38903890test "if expression" {
38913891 // If expressions are used instead of a ternary expression.
38923892 const a: u32 = 5;
38933893 const b: u32 = 4;
38943894 const result = if (a != b) 47 else 3089;
3895 assert(result == 47);
3895 expect(result == 47);
38963896}
38973897
38983898test "if boolean" {
......@@ -3900,7 +3900,7 @@ test "if boolean" {
39003900 const a: u32 = 5;
39013901 const b: u32 = 4;
39023902 if (a != b) {
3903 assert(true);
3903 expect(true);
39043904 } else if (a == 9) {
39053905 unreachable;
39063906 } else {
......@@ -3913,7 +3913,7 @@ test "if optional" {
39133913
39143914 const a: ?u32 = 0;
39153915 if (a) |value| {
3916 assert(value == 0);
3916 expect(value == 0);
39173917 } else {
39183918 unreachable;
39193919 }
......@@ -3922,17 +3922,17 @@ test "if optional" {
39223922 if (b) |value| {
39233923 unreachable;
39243924 } else {
3925 assert(true);
3925 expect(true);
39263926 }
39273927
39283928 // The else is not required.
39293929 if (a) |value| {
3930 assert(value == 0);
3930 expect(value == 0);
39313931 }
39323932
39333933 // To test against null only, use the binary equality operator.
39343934 if (b == null) {
3935 assert(true);
3935 expect(true);
39363936 }
39373937
39383938 // Access the value by reference using a pointer capture.
......@@ -3942,7 +3942,7 @@ test "if optional" {
39423942 }
39433943
39443944 if (c) |value| {
3945 assert(value == 2);
3945 expect(value == 2);
39463946 } else {
39473947 unreachable;
39483948 }
......@@ -3954,7 +3954,7 @@ test "if error union" {
39543954
39553955 const a: anyerror!u32 = 0;
39563956 if (a) |value| {
3957 assert(value == 0);
3957 expect(value == 0);
39583958 } else |err| {
39593959 unreachable;
39603960 }
......@@ -3963,17 +3963,17 @@ test "if error union" {
39633963 if (b) |value| {
39643964 unreachable;
39653965 } else |err| {
3966 assert(err == error.BadValue);
3966 expect(err == error.BadValue);
39673967 }
39683968
39693969 // The else and |err| capture is strictly required.
39703970 if (a) |value| {
3971 assert(value == 0);
3971 expect(value == 0);
39723972 } else |_| {}
39733973
39743974 // To check only the error value, use an empty block expression.
39753975 if (b) |_| {} else |err| {
3976 assert(err == error.BadValue);
3976 expect(err == error.BadValue);
39773977 }
39783978
39793979 // Access the value by reference using a pointer capture.
......@@ -3985,7 +3985,7 @@ test "if error union" {
39853985 }
39863986
39873987 if (c) |value| {
3988 assert(value == 9);
3988 expect(value == 9);
39893989 } else |err| {
39903990 unreachable;
39913991 }
......@@ -3997,14 +3997,14 @@ test "if error union with optional" {
39973997
39983998 const a: anyerror!?u32 = 0;
39993999 if (a) |optional_value| {
4000 assert(optional_value.? == 0);
4000 expect(optional_value.? == 0);
40014001 } else |err| {
40024002 unreachable;
40034003 }
40044004
40054005 const b: anyerror!?u32 = null;
40064006 if (b) |optional_value| {
4007 assert(optional_value == null);
4007 expect(optional_value == null);
40084008 } else |err| {
40094009 unreachable;
40104010 }
......@@ -4013,7 +4013,7 @@ test "if error union with optional" {
40134013 if (c) |optional_value| {
40144014 unreachable;
40154015 } else |err| {
4016 assert(err == error.BadValue);
4016 expect(err == error.BadValue);
40174017 }
40184018
40194019 // Access the value by reference by using a pointer capture each time.
......@@ -4027,7 +4027,7 @@ test "if error union with optional" {
40274027 }
40284028
40294029 if (d) |optional_value| {
4030 assert(optional_value.? == 9);
4030 expect(optional_value.? == 9);
40314031 } else |err| {
40324032 unreachable;
40334033 }
......@@ -4038,7 +4038,7 @@ test "if error union with optional" {
40384038 {#header_open|defer#}
40394039 {#code_begin|test|defer#}
40404040const std = @import("std");
4041const assert = std.debug.assert;
4041const expect = std.testing.expect;
40424042const print = std.debug.print;
40434043
40444044// defer will execute an expression at the end of the current scope.
......@@ -4049,14 +4049,14 @@ fn deferExample() usize {
40494049 defer a = 2;
40504050 a = 1;
40514051 }
4052 assert(a == 2);
4052 expect(a == 2);
40534053
40544054 a = 5;
40554055 return a;
40564056}
40574057
40584058test "defer basics" {
4059 assert(deferExample() == 5);
4059 expect(deferExample() == 5);
40604060}
40614061
40624062// If multiple defer statements are specified, they will be executed in
......@@ -4133,8 +4133,9 @@ test "basic math" {
41334133 }
41344134}
41354135 {#code_end#}
4136 <p>In fact, this is how assert is implemented:</p>
4136 <p>In fact, this is how {#syntax#}std.debug.assert{#endsyntax#} is implemented:</p>
41374137 {#code_begin|test_err#}
4138// This is how std.debug.assert is implemented
41384139fn assert(ok: bool) void {
41394140 if (!ok) unreachable; // assertion failure
41404141}
......@@ -4193,19 +4194,19 @@ pub extern "kernel32" fn ExitProcess(exit_code: c_uint) callconv(.Stdcall) noret
41934194
41944195test "foo" {
41954196 const value = bar() catch ExitProcess(1);
4196 assert(value == 1234);
4197 expect(value == 1234);
41974198}
41984199
41994200fn bar() anyerror!u32 {
42004201 return 1234;
42014202}
42024203
4203const assert = @import("std").debug.assert;
4204const expect = @import("std").testing.expect;
42044205 {#code_end#}
42054206 {#header_close#}
42064207 {#header_open|Functions#}
42074208 {#code_begin|test|functions#}
4208const assert = @import("std").debug.assert;
4209const expect = @import("std").testing.expect;
42094210
42104211// Functions are declared like this
42114212fn add(a: i8, b: i8) i8 {
......@@ -4256,17 +4257,17 @@ fn do_op(fn_call: call2_op, op1: i8, op2: i8) i8 {
42564257}
42574258
42584259test "function" {
4259 assert(do_op(add, 5, 6) == 11);
4260 assert(do_op(sub2, 5, 6) == -1);
4260 expect(do_op(add, 5, 6) == 11);
4261 expect(do_op(sub2, 5, 6) == -1);
42614262}
42624263 {#code_end#}
42634264 <p>Function values are like pointers:</p>
42644265 {#code_begin|obj#}
4265const assert = @import("std").debug.assert;
4266const expect = @import("std").testing.expect;
42664267
42674268comptime {
4268 assert(@TypeOf(foo) == fn()void);
4269 assert(@sizeOf(fn()void) == @sizeOf(?fn()void));
4269 expect(@TypeOf(foo) == fn()void);
4270 expect(@sizeOf(fn()void) == @sizeOf(?fn()void));
42704271}
42714272
42724273fn foo() void { }
......@@ -4298,10 +4299,10 @@ fn foo(point: Point) i32 {
42984299 return point.x + point.y;
42994300}
43004301
4301const assert = @import("std").debug.assert;
4302const expect = @import("std").testing.expect;
43024303
43034304test "pass struct to function" {
4304 assert(foo(Point{ .x = 1, .y = 2 }) == 3);
4305 expect(foo(Point{ .x = 1, .y = 2 }) == 3);
43054306}
43064307 {#code_end#}
43074308 <p>
......@@ -4315,29 +4316,29 @@ test "pass struct to function" {
43154316 Use {#link|@TypeOf#} and {#link|@typeInfo#} to get information about the inferred type.
43164317 </p>
43174318 {#code_begin|test#}
4318const assert = @import("std").debug.assert;
4319const expect = @import("std").testing.expect;
43194320
43204321fn addFortyTwo(x: anytype) @TypeOf(x) {
43214322 return x + 42;
43224323}
43234324
43244325test "fn type inference" {
4325 assert(addFortyTwo(1) == 43);
4326 assert(@TypeOf(addFortyTwo(1)) == comptime_int);
4326 expect(addFortyTwo(1) == 43);
4327 expect(@TypeOf(addFortyTwo(1)) == comptime_int);
43274328 var y: i64 = 2;
4328 assert(addFortyTwo(y) == 44);
4329 assert(@TypeOf(addFortyTwo(y)) == i64);
4329 expect(addFortyTwo(y) == 44);
4330 expect(@TypeOf(addFortyTwo(y)) == i64);
43304331}
43314332 {#code_end#}
43324333
43334334 {#header_close#}
43344335 {#header_open|Function Reflection#}
43354336 {#code_begin|test#}
4336const assert = @import("std").debug.assert;
4337const expect = @import("std").testing.expect;
43374338
43384339test "fn reflection" {
4339 assert(@typeInfo(@TypeOf(assert)).Fn.return_type.? == void);
4340 assert(@typeInfo(@TypeOf(assert)).Fn.is_var_args == false);
4340 expect(@typeInfo(@TypeOf(expect)).Fn.return_type.? == void);
4341 expect(@typeInfo(@TypeOf(expect)).Fn.is_var_args == false);
43414342}
43424343 {#code_end#}
43434344 {#header_close#}
......@@ -4372,7 +4373,7 @@ const AllocationError = error {
43724373
43734374test "coerce subset to superset" {
43744375 const err = foo(AllocationError.OutOfMemory);
4375 std.debug.assert(err == FileOpenError.OutOfMemory);
4376 std.testing.expect(err == FileOpenError.OutOfMemory);
43764377}
43774378
43784379fn foo(err: AllocationError) FileOpenError {
......@@ -4480,7 +4481,7 @@ fn charToDigit(c: u8) u8 {
44804481
44814482test "parse u64" {
44824483 const result = try parseU64("1234", 10);
4483 std.debug.assert(result == 1234);
4484 std.testing.expect(result == 1234);
44844485}
44854486 {#code_end#}
44864487 <p>
......@@ -4625,7 +4626,7 @@ fn createFoo(param: i32) !Foo {
46254626 <p>An error union is created with the {#syntax#}!{#endsyntax#} binary operator.
46264627 You can use compile-time reflection to access the child type of an error union:</p>
46274628 {#code_begin|test#}
4628const assert = @import("std").debug.assert;
4629const expect = @import("std").testing.expect;
46294630
46304631test "error union" {
46314632 var foo: anyerror!i32 = undefined;
......@@ -4637,10 +4638,10 @@ test "error union" {
46374638 foo = error.SomeError;
46384639
46394640 // Use compile-time reflection to access the payload type of an error union:
4640 comptime assert(@typeInfo(@TypeOf(foo)).ErrorUnion.payload == i32);
4641 comptime expect(@typeInfo(@TypeOf(foo)).ErrorUnion.payload == i32);
46414642
46424643 // Use compile-time reflection to access the error set type of an error union:
4643 comptime assert(@typeInfo(@TypeOf(foo)).ErrorUnion.error_set == anyerror);
4644 comptime expect(@typeInfo(@TypeOf(foo)).ErrorUnion.error_set == anyerror);
46444645}
46454646 {#code_end#}
46464647 {#header_open|Merging Error Sets#}
......@@ -5007,7 +5008,7 @@ fn doAThing(optional_foo: ?*Foo) void {
50075008 <p>An optional is created by putting {#syntax#}?{#endsyntax#} in front of a type. You can use compile-time
50085009 reflection to access the child type of an optional:</p>
50095010 {#code_begin|test#}
5010const assert = @import("std").debug.assert;
5011const expect = @import("std").testing.expect;
50115012
50125013test "optional type" {
50135014 // Declare an optional and coerce from null:
......@@ -5017,7 +5018,7 @@ test "optional type" {
50175018 foo = 1234;
50185019
50195020 // Use compile-time reflection to access the child type of the optional:
5020 comptime assert(@typeInfo(@TypeOf(foo)).Optional.child == i32);
5021 comptime expect(@typeInfo(@TypeOf(foo)).Optional.child == i32);
50215022}
50225023 {#code_end#}
50235024 {#header_close#}
......@@ -5034,7 +5035,7 @@ const optional_value: ?i32 = null;
50345035 <p>An optional pointer is guaranteed to be the same size as a pointer. The {#syntax#}null{#endsyntax#} of
50355036 the optional is guaranteed to be address 0.</p>
50365037 {#code_begin|test#}
5037const assert = @import("std").debug.assert;
5038const expect = @import("std").testing.expect;
50385039
50395040test "optional pointers" {
50405041 // Pointers cannot be null. If you want a null pointer, use the optional
......@@ -5044,11 +5045,11 @@ test "optional pointers" {
50445045 var x: i32 = 1;
50455046 ptr = &x;
50465047
5047 assert(ptr.?.* == 1);
5048 expect(ptr.?.* == 1);
50485049
50495050 // Optional pointers are the same size as normal pointers, because pointer
50505051 // value 0 is used as the null value.
5051 assert(@sizeOf(?*i32) == @sizeOf(*i32));
5052 expect(@sizeOf(?*i32) == @sizeOf(*i32));
50525053}
50535054 {#code_end#}
50545055 {#header_close#}
......@@ -5115,13 +5116,13 @@ fn foo(a: *const i32) void {}
51155116 </p>
51165117 {#code_begin|test#}
51175118const std = @import("std");
5118const assert = std.debug.assert;
5119const expect = std.testing.expect;
51195120const mem = std.mem;
51205121
51215122test "cast *[1][*]const u8 to [*]const ?[*]const u8" {
51225123 const window_name = [1][*]const u8{"window name"};
51235124 const x: [*]const ?[*]const u8 = &window_name;
5124 assert(mem.eql(u8, std.mem.spanZ(@ptrCast([*:0]const u8, x[0].?)), "window name"));
5125 expect(mem.eql(u8, std.mem.spanZ(@ptrCast([*:0]const u8, x[0].?)), "window name"));
51255126}
51265127 {#code_end#}
51275128 {#header_close#}
......@@ -5132,7 +5133,7 @@ test "cast *[1][*]const u8 to [*]const ?[*]const u8" {
51325133 </p>
51335134 {#code_begin|test#}
51345135const std = @import("std");
5135const assert = std.debug.assert;
5136const expect = std.testing.expect;
51365137const mem = std.mem;
51375138
51385139test "integer widening" {
......@@ -5142,13 +5143,13 @@ test "integer widening" {
51425143 var d: u64 = c;
51435144 var e: u64 = d;
51445145 var f: u128 = e;
5145 assert(f == a);
5146 expect(f == a);
51465147}
51475148
51485149test "implicit unsigned integer to signed integer" {
51495150 var a: u8 = 250;
51505151 var b: i16 = a;
5151 assert(b == 250);
5152 expect(b == 250);
51525153}
51535154
51545155test "float widening" {
......@@ -5160,7 +5161,7 @@ test "float widening" {
51605161 var b: f32 = a;
51615162 var c: f64 = b;
51625163 var d: f128 = c;
5163 assert(d == a);
5164 expect(d == a);
51645165}
51655166 {#code_end#}
51665167 {#header_close#}
......@@ -5183,7 +5184,7 @@ test "implicit cast to comptime_int" {
51835184 {#header_open|Type Coercion: Arrays and Pointers#}
51845185 {#code_begin|test|coerce_arrays_and_ptrs#}
51855186const std = @import("std");
5186const assert = std.debug.assert;
5187const expect = std.testing.expect;
51875188
51885189// This cast exists primarily so that string literals can be
51895190// passed to functions that accept const slices. However
......@@ -5192,41 +5193,41 @@ const assert = std.debug.assert;
51925193test "[N]T to []const T" {
51935194 var x1: []const u8 = "hello";
51945195 var x2: []const u8 = &[5]u8{ 'h', 'e', 'l', 'l', 111 };
5195 assert(std.mem.eql(u8, x1, x2));
5196 expect(std.mem.eql(u8, x1, x2));
51965197
51975198 var y: []const f32 = &[2]f32{ 1.2, 3.4 };
5198 assert(y[0] == 1.2);
5199 expect(y[0] == 1.2);
51995200}
52005201
52015202// Likewise, it works when the destination type is an error union.
52025203test "[N]T to E![]const T" {
52035204 var x1: anyerror![]const u8 = "hello";
52045205 var x2: anyerror![]const u8 = &[5]u8{ 'h', 'e', 'l', 'l', 111 };
5205 assert(std.mem.eql(u8, try x1, try x2));
5206 expect(std.mem.eql(u8, try x1, try x2));
52065207
52075208 var y: anyerror![]const f32 = &[2]f32{ 1.2, 3.4 };
5208 assert((try y)[0] == 1.2);
5209 expect((try y)[0] == 1.2);
52095210}
52105211
52115212// Likewise, it works when the destination type is an optional.
52125213test "[N]T to ?[]const T" {
52135214 var x1: ?[]const u8 = "hello";
52145215 var x2: ?[]const u8 = &[5]u8{ 'h', 'e', 'l', 'l', 111 };
5215 assert(std.mem.eql(u8, x1.?, x2.?));
5216 expect(std.mem.eql(u8, x1.?, x2.?));
52165217
52175218 var y: ?[]const f32 = &[2]f32{ 1.2, 3.4 };
5218 assert(y.?[0] == 1.2);
5219 expect(y.?[0] == 1.2);
52195220}
52205221
52215222// In this cast, the array length becomes the slice length.
52225223test "*[N]T to []T" {
52235224 var buf: [5]u8 = "hello".*;
52245225 const x: []u8 = &buf;
5225 assert(std.mem.eql(u8, x, "hello"));
5226 expect(std.mem.eql(u8, x, "hello"));
52265227
52275228 const buf2 = [2]f32{ 1.2, 3.4 };
52285229 const x2: []const f32 = &buf2;
5229 assert(std.mem.eql(f32, x2, &[2]f32{ 1.2, 3.4 }));
5230 expect(std.mem.eql(f32, x2, &[2]f32{ 1.2, 3.4 }));
52305231}
52315232
52325233// Single-item pointers to arrays can be coerced to
......@@ -5234,7 +5235,7 @@ test "*[N]T to []T" {
52345235test "*[N]T to [*]T" {
52355236 var buf: [5]u8 = "hello".*;
52365237 const x: [*]u8 = &buf;
5237 assert(x[4] == 'o');
5238 expect(x[4] == 'o');
52385239 // x[5] would be an uncaught out of bounds pointer dereference!
52395240}
52405241
......@@ -5242,7 +5243,7 @@ test "*[N]T to [*]T" {
52425243test "*[N]T to ?[*]T" {
52435244 var buf: [5]u8 = "hello".*;
52445245 const x: ?[*]u8 = &buf;
5245 assert(x.?[4] == 'o');
5246 expect(x.?[4] == 'o');
52465247}
52475248
52485249// Single-item pointers can be cast to len-1 single-item arrays.
......@@ -5250,7 +5251,7 @@ test "*T to *[1]T" {
52505251 var x: i32 = 1234;
52515252 const y: *[1]i32 = &x;
52525253 const z: [*]i32 = y;
5253 assert(z[0] == 1234);
5254 expect(z[0] == 1234);
52545255}
52555256 {#code_end#}
52565257 {#see_also|C Pointers#}
......@@ -5261,27 +5262,27 @@ test "*T to *[1]T" {
52615262 </p>
52625263 {#code_begin|test#}
52635264const std = @import("std");
5264const assert = std.debug.assert;
5265const expect = std.testing.expect;
52655266
52665267test "coerce to optionals" {
52675268 const x: ?i32 = 1234;
52685269 const y: ?i32 = null;
52695270
5270 assert(x.? == 1234);
5271 assert(y == null);
5271 expect(x.? == 1234);
5272 expect(y == null);
52725273}
52735274 {#code_end#}
52745275 <p>It works nested inside the {#link|Error Union Type#}, too:</p>
52755276 {#code_begin|test#}
52765277const std = @import("std");
5277const assert = std.debug.assert;
5278const expect = std.testing.expect;
52785279
52795280test "coerce to optionals wrapped in error union" {
52805281 const x: anyerror!?i32 = 1234;
52815282 const y: anyerror!?i32 = null;
52825283
5283 assert((try x).? == 1234);
5284 assert((try y) == null);
5284 expect((try x).? == 1234);
5285 expect((try y) == null);
52855286}
52865287 {#code_end#}
52875288 {#header_close#}
......@@ -5291,13 +5292,13 @@ test "coerce to optionals wrapped in error union" {
52915292 </p>
52925293 {#code_begin|test#}
52935294const std = @import("std");
5294const assert = std.debug.assert;
5295const expect = std.testing.expect;
52955296
52965297test "coercion to error unions" {
52975298 const x: anyerror!i32 = 1234;
52985299 const y: anyerror!i32 = error.Failure;
52995300
5300 assert((try x) == 1234);
5301 expect((try x) == 1234);
53015302 std.testing.expectError(error.Failure, y);
53025303}
53035304 {#code_end#}
......@@ -5308,12 +5309,12 @@ test "coercion to error unions" {
53085309 </p>
53095310 {#code_begin|test#}
53105311const std = @import("std");
5311const assert = std.debug.assert;
5312const expect = std.testing.expect;
53125313
53135314test "coercing large integer type to smaller one when value is comptime known to fit" {
53145315 const x: u64 = 255;
53155316 const y: u8 = x;
5316 assert(y == 255);
5317 expect(y == 255);
53175318}
53185319 {#code_end#}
53195320 {#header_close#}
......@@ -5324,7 +5325,7 @@ test "coercing large integer type to smaller one when value is comptime known to
53245325 </p>
53255326 {#code_begin|test#}
53265327const std = @import("std");
5327const assert = std.debug.assert;
5328const expect = std.testing.expect;
53285329
53295330const E = enum {
53305331 one,
......@@ -5341,11 +5342,11 @@ const U = union(E) {
53415342test "coercion between unions and enums" {
53425343 var u = U{ .two = 12.34 };
53435344 var e: E = u;
5344 assert(e == E.two);
5345 expect(e == E.two);
53455346
53465347 const three = E.three;
53475348 var another_u: U = three;
5348 assert(another_u == E.three);
5349 expect(another_u == E.three);
53495350}
53505351 {#code_end#}
53515352 {#see_also|union|enum#}
......@@ -5411,22 +5412,22 @@ test "coercion of zero bit types" {
54115412 </p>
54125413 {#code_begin|test|peer_type_resolution#}
54135414const std = @import("std");
5414const assert = std.debug.assert;
5415const expect = std.testing.expect;
54155416const mem = std.mem;
54165417
54175418test "peer resolve int widening" {
54185419 var a: i8 = 12;
54195420 var b: i16 = 34;
54205421 var c = a + b;
5421 assert(c == 46);
5422 assert(@TypeOf(c) == i16);
5422 expect(c == 46);
5423 expect(@TypeOf(c) == i16);
54235424}
54245425
54255426test "peer resolve arrays of different size to const slice" {
5426 assert(mem.eql(u8, boolToStr(true), "true"));
5427 assert(mem.eql(u8, boolToStr(false), "false"));
5428 comptime assert(mem.eql(u8, boolToStr(true), "true"));
5429 comptime assert(mem.eql(u8, boolToStr(false), "false"));
5427 expect(mem.eql(u8, boolToStr(true), "true"));
5428 expect(mem.eql(u8, boolToStr(false), "false"));
5429 comptime expect(mem.eql(u8, boolToStr(true), "true"));
5430 comptime expect(mem.eql(u8, boolToStr(false), "false"));
54305431}
54315432fn boolToStr(b: bool) []const u8 {
54325433 return if (b) "true" else "false";
......@@ -5439,16 +5440,16 @@ test "peer resolve array and const slice" {
54395440fn testPeerResolveArrayConstSlice(b: bool) void {
54405441 const value1 = if (b) "aoeu" else @as([]const u8, "zz");
54415442 const value2 = if (b) @as([]const u8, "zz") else "aoeu";
5442 assert(mem.eql(u8, value1, "aoeu"));
5443 assert(mem.eql(u8, value2, "zz"));
5443 expect(mem.eql(u8, value1, "aoeu"));
5444 expect(mem.eql(u8, value2, "zz"));
54445445}
54455446
54465447test "peer type resolution: ?T and T" {
5447 assert(peerTypeTAndOptionalT(true, false).? == 0);
5448 assert(peerTypeTAndOptionalT(false, false).? == 3);
5448 expect(peerTypeTAndOptionalT(true, false).? == 0);
5449 expect(peerTypeTAndOptionalT(false, false).? == 3);
54495450 comptime {
5450 assert(peerTypeTAndOptionalT(true, false).? == 0);
5451 assert(peerTypeTAndOptionalT(false, false).? == 3);
5451 expect(peerTypeTAndOptionalT(true, false).? == 0);
5452 expect(peerTypeTAndOptionalT(false, false).? == 3);
54525453 }
54535454}
54545455fn peerTypeTAndOptionalT(c: bool, b: bool) ?usize {
......@@ -5460,11 +5461,11 @@ fn peerTypeTAndOptionalT(c: bool, b: bool) ?usize {
54605461}
54615462
54625463test "peer type resolution: *[0]u8 and []const u8" {
5463 assert(peerTypeEmptyArrayAndSlice(true, "hi").len == 0);
5464 assert(peerTypeEmptyArrayAndSlice(false, "hi").len == 1);
5464 expect(peerTypeEmptyArrayAndSlice(true, "hi").len == 0);
5465 expect(peerTypeEmptyArrayAndSlice(false, "hi").len == 1);
54655466 comptime {
5466 assert(peerTypeEmptyArrayAndSlice(true, "hi").len == 0);
5467 assert(peerTypeEmptyArrayAndSlice(false, "hi").len == 1);
5467 expect(peerTypeEmptyArrayAndSlice(true, "hi").len == 0);
5468 expect(peerTypeEmptyArrayAndSlice(false, "hi").len == 1);
54685469 }
54695470}
54705471fn peerTypeEmptyArrayAndSlice(a: bool, slice: []const u8) []const u8 {
......@@ -5478,14 +5479,14 @@ test "peer type resolution: *[0]u8, []const u8, and anyerror![]u8" {
54785479 {
54795480 var data = "hi".*;
54805481 const slice = data[0..];
5481 assert((try peerTypeEmptyArrayAndSliceAndError(true, slice)).len == 0);
5482 assert((try peerTypeEmptyArrayAndSliceAndError(false, slice)).len == 1);
5482 expect((try peerTypeEmptyArrayAndSliceAndError(true, slice)).len == 0);
5483 expect((try peerTypeEmptyArrayAndSliceAndError(false, slice)).len == 1);
54835484 }
54845485 comptime {
54855486 var data = "hi".*;
54865487 const slice = data[0..];
5487 assert((try peerTypeEmptyArrayAndSliceAndError(true, slice)).len == 0);
5488 assert((try peerTypeEmptyArrayAndSliceAndError(false, slice)).len == 1);
5488 expect((try peerTypeEmptyArrayAndSliceAndError(true, slice)).len == 0);
5489 expect((try peerTypeEmptyArrayAndSliceAndError(false, slice)).len == 1);
54895490 }
54905491}
54915492fn peerTypeEmptyArrayAndSliceAndError(a: bool, slice: []u8) anyerror![]u8 {
......@@ -5499,8 +5500,8 @@ fn peerTypeEmptyArrayAndSliceAndError(a: bool, slice: []u8) anyerror![]u8 {
54995500test "peer type resolution: *const T and ?*T" {
55005501 const a = @intToPtr(*const usize, 0x123456780);
55015502 const b = @intToPtr(?*usize, 0x123456780);
5502 assert(a == b);
5503 assert(b == a);
5503 expect(a == b);
5504 expect(b == a);
55045505}
55055506 {#code_end#}
55065507 {#header_close#}
......@@ -5547,7 +5548,7 @@ export fn entry() void {
55475548 </p>
55485549 {#code_begin|test#}
55495550const std = @import("std");
5550const assert = std.debug.assert;
5551const expect = std.testing.expect;
55515552
55525553test "turn HashMap into a set with void" {
55535554 var map = std.AutoHashMap(i32, void).init(std.testing.allocator);
......@@ -5556,11 +5557,11 @@ test "turn HashMap into a set with void" {
55565557 try map.put(1, {});
55575558 try map.put(2, {});
55585559
5559 assert(map.contains(2));
5560 assert(!map.contains(3));
5560 expect(map.contains(2));
5561 expect(!map.contains(3));
55615562
55625563 _ = map.remove(2);
5563 assert(!map.contains(2));
5564 expect(!map.contains(2));
55645565}
55655566 {#code_end#}
55665567 <p>Note that this is different from using a dummy value for the hash map value.
......@@ -5607,7 +5608,7 @@ fn foo() i32 {
56075608 <p>Pointers to zero bit types also have zero bits. They always compare equal to each other:</p>
56085609 {#code_begin|test#}
56095610const std = @import("std");
5610const assert = std.debug.assert;
5611const expect = std.testing.expect;
56115612
56125613test "pointer to empty struct" {
56135614 const Empty = struct {};
......@@ -5615,7 +5616,7 @@ test "pointer to empty struct" {
56155616 var b = Empty{};
56165617 var ptr_a = &a;
56175618 var ptr_b = &b;
5618 comptime assert(ptr_a == ptr_b);
5619 comptime expect(ptr_a == ptr_b);
56195620}
56205621 {#code_end#}
56215622 <p>The type being pointed to can only ever be one value; therefore loads and stores are
......@@ -5650,7 +5651,7 @@ test "@intToPtr for pointer to zero bit type" {
56505651usingnamespace @import("std");
56515652
56525653test "using std namespace" {
5653 debug.assert(true);
5654 testing.expect(true);
56545655}
56555656 {#code_end#}
56565657 <p>
......@@ -5762,7 +5763,7 @@ fn max(comptime T: type, a: T, b: T) T {
57625763 }
57635764}
57645765test "try to compare bools" {
5765 @import("std").debug.assert(max(bool, false, true) == true);
5766 @import("std").testing.expect(max(bool, false, true) == true);
57665767}
57675768 {#code_end#}
57685769 <p>
......@@ -5802,7 +5803,7 @@ fn max(a: bool, b: bool) bool {
58025803 For example:
58035804 </p>
58045805 {#code_begin|test|comptime_vars#}
5805const assert = @import("std").debug.assert;
5806const expect = @import("std").testing.expect;
58065807
58075808const CmdFn = struct {
58085809 name: []const u8,
......@@ -5830,9 +5831,9 @@ fn performFn(comptime prefix_char: u8, start_value: i32) i32 {
58305831}
58315832
58325833test "perform fn" {
5833 assert(performFn('t', 1) == 6);
5834 assert(performFn('o', 0) == 1);
5835 assert(performFn('w', 99) == 99);
5834 expect(performFn('t', 1) == 6);
5835 expect(performFn('o', 0) == 1);
5836 expect(performFn('w', 99) == 99);
58365837}
58375838 {#code_end#}
58385839 <p>
......@@ -5843,7 +5844,7 @@ test "perform fn" {
58435844 </p>
58445845 {#code_begin|syntax#}
58455846// From the line:
5846// assert(performFn('t', 1) == 6);
5847// expect(performFn('t', 1) == 6);
58475848fn performFn(start_value: i32) i32 {
58485849 var result: i32 = start_value;
58495850 result = two(result);
......@@ -5853,7 +5854,7 @@ fn performFn(start_value: i32) i32 {
58535854 {#code_end#}
58545855 {#code_begin|syntax#}
58555856// From the line:
5856// assert(performFn('o', 0) == 1);
5857// expect(performFn('o', 0) == 1);
58575858fn performFn(start_value: i32) i32 {
58585859 var result: i32 = start_value;
58595860 result = one(result);
......@@ -5862,7 +5863,7 @@ fn performFn(start_value: i32) i32 {
58625863 {#code_end#}
58635864 {#code_begin|syntax#}
58645865// From the line:
5865// assert(performFn('w', 99) == 99);
5866// expect(performFn('w', 99) == 99);
58665867fn performFn(start_value: i32) i32 {
58675868 var result: i32 = start_value;
58685869 return result;
......@@ -5915,7 +5916,7 @@ test "foo" {
59155916 Let's look at an example:
59165917 </p>
59175918 {#code_begin|test#}
5918const assert = @import("std").debug.assert;
5919const expect = @import("std").testing.expect;
59195920
59205921fn fibonacci(index: u32) u32 {
59215922 if (index < 2) return index;
......@@ -5924,11 +5925,11 @@ fn fibonacci(index: u32) u32 {
59245925
59255926test "fibonacci" {
59265927 // test fibonacci at run-time
5927 assert(fibonacci(7) == 13);
5928 expect(fibonacci(7) == 13);
59285929
59295930 // test fibonacci at compile-time
59305931 comptime {
5931 assert(fibonacci(7) == 13);
5932 expect(fibonacci(7) == 13);
59325933 }
59335934}
59345935 {#code_end#}
......@@ -5936,7 +5937,7 @@ test "fibonacci" {
59365937 Imagine if we had forgotten the base case of the recursive function and tried to run the tests:
59375938 </p>
59385939 {#code_begin|test_err|operation caused overflow#}
5939const assert = @import("std").debug.assert;
5940const expect = @import("std").testing.expect;
59405941
59415942fn fibonacci(index: u32) u32 {
59425943 //if (index < 2) return index;
......@@ -5945,7 +5946,7 @@ fn fibonacci(index: u32) u32 {
59455946
59465947test "fibonacci" {
59475948 comptime {
5948 assert(fibonacci(7) == 13);
5949 expect(fibonacci(7) == 13);
59495950 }
59505951}
59515952 {#code_end#}
......@@ -5959,7 +5960,7 @@ test "fibonacci" {
59595960 But what would have happened if we used a signed integer?
59605961 </p>
59615962 {#code_begin|test_err|evaluation exceeded 1000 backwards branches#}
5962const assert = @import("std").debug.assert;
5963const expect = @import("std").testing.expect;
59635964
59645965fn fibonacci(index: i32) i32 {
59655966 //if (index < 2) return index;
......@@ -5968,7 +5969,7 @@ fn fibonacci(index: i32) i32 {
59685969
59695970test "fibonacci" {
59705971 comptime {
5971 assert(fibonacci(7) == 13);
5972 expect(fibonacci(7) == 13);
59725973 }
59735974}
59745975 {#code_end#}
......@@ -5979,10 +5980,10 @@ test "fibonacci" {
59795980 {#link|@setEvalBranchQuota#} to change the default number 1000 to something else.
59805981 </p>
59815982 <p>
5982 What if we fix the base case, but put the wrong value in the {#syntax#}assert{#endsyntax#} line?
5983 What if we fix the base case, but put the wrong value in the {#syntax#}expect{#endsyntax#} line?
59835984 </p>
5984 {#code_begin|test_err|unable to evaluate constant expression#}
5985const assert = @import("std").debug.assert;
5985 {#code_begin|test_err|encountered @panic at compile-time#}
5986const expect = @import("std").testing.expect;
59865987
59875988fn fibonacci(index: i32) i32 {
59885989 if (index < 2) return index;
......@@ -5991,16 +5992,15 @@ fn fibonacci(index: i32) i32 {
59915992
59925993test "fibonacci" {
59935994 comptime {
5994 assert(fibonacci(7) == 99999);
5995 expect(fibonacci(7) == 99999);
59955996 }
59965997}
59975998 {#code_end#}
59985999 <p>
5999 What happened is Zig started interpreting the {#syntax#}assert{#endsyntax#} function with the
6000 What happened is Zig started interpreting the {#syntax#}expect{#endsyntax#} function with the
60006001 parameter {#syntax#}ok{#endsyntax#} set to {#syntax#}false{#endsyntax#}. When the interpreter hit
6001 {#syntax#}unreachable{#endsyntax#} it emitted a compile error, because reaching unreachable
6002 code is undefined behavior, and undefined behavior causes a compile error if it is detected
6003 at compile-time.
6002 {#syntax#}@panic{#endsyntax#} it emitted a compile error because a panic during compile
6003 causes a compile error if it is detected at compile-time.
60046004 </p>
60056005
60066006 <p>
......@@ -6042,7 +6042,7 @@ fn sum(numbers: []const i32) i32 {
60426042}
60436043
60446044test "variable values" {
6045 @import("std").debug.assert(sum_of_first_25_primes == 1060);
6045 @import("std").testing.expect(sum_of_first_25_primes == 1060);
60466046}
60476047 {#code_end#}
60486048 <p>
......@@ -6435,7 +6435,7 @@ volatile (
64356435 {#code_begin|test|global-asm#}
64366436 {#target_linux_x86_64#}
64376437const std = @import("std");
6438const assert = std.debug.assert;
6438const expect = std.testing.expect;
64396439
64406440comptime {
64416441 asm (
......@@ -6450,7 +6450,7 @@ comptime {
64506450extern fn my_func(a: i32, b: i32) i32;
64516451
64526452test "global assembly" {
6453 assert(my_func(12, 34) == 46);
6453 expect(my_func(12, 34) == 46);
64546454}
64556455 {#code_end#}
64566456 {#header_close#}
......@@ -6485,13 +6485,13 @@ test "global assembly" {
64856485 </p>
64866486 {#code_begin|test#}
64876487const std = @import("std");
6488const assert = std.debug.assert;
6488const expect = std.testing.expect;
64896489
64906490var x: i32 = 1;
64916491
64926492test "suspend with no resume" {
64936493 var frame = async func();
6494 assert(x == 2);
6494 expect(x == 2);
64956495}
64966496
64976497fn func() void {
......@@ -6511,21 +6511,21 @@ fn func() void {
65116511 </p>
65126512 {#code_begin|test#}
65136513const std = @import("std");
6514const assert = std.debug.assert;
6514const expect = std.testing.expect;
65156515
65166516var the_frame: anyframe = undefined;
65176517var result = false;
65186518
65196519test "async function suspend with block" {
65206520 _ = async testSuspendBlock();
6521 assert(!result);
6521 expect(!result);
65226522 resume the_frame;
6523 assert(result);
6523 expect(result);
65246524}
65256525
65266526fn testSuspendBlock() void {
65276527 suspend {
6528 comptime assert(@TypeOf(@frame()) == *@Frame(testSuspendBlock));
6528 comptime expect(@TypeOf(@frame()) == *@Frame(testSuspendBlock));
65296529 the_frame = @frame();
65306530 }
65316531 result = true;
......@@ -6549,12 +6549,12 @@ fn testSuspendBlock() void {
65496549 </p>
65506550 {#code_begin|test#}
65516551const std = @import("std");
6552const assert = std.debug.assert;
6552const expect = std.testing.expect;
65536553
65546554test "resume from suspend" {
65556555 var my_result: i32 = 1;
65566556 _ = async testResumeFromSuspend(&my_result);
6557 std.debug.assert(my_result == 2);
6557 std.testing.expect(my_result == 2);
65586558}
65596559fn testResumeFromSuspend(my_result: *i32) void {
65606560 suspend {
......@@ -6578,7 +6578,7 @@ fn testResumeFromSuspend(my_result: *i32) void {
65786578 </p>
65796579 {#code_begin|test#}
65806580const std = @import("std");
6581const assert = std.debug.assert;
6581const expect = std.testing.expect;
65826582
65836583test "async and await" {
65846584 // Here we have an exception where we do not match an async
......@@ -6592,7 +6592,7 @@ test "async and await" {
65926592
65936593fn amain() void {
65946594 var frame = async func();
6595 comptime assert(@TypeOf(frame) == @Frame(func));
6595 comptime expect(@TypeOf(frame) == @Frame(func));
65966596
65976597 const ptr: anyframe->void = &frame;
65986598 const any_ptr: anyframe = ptr;
......@@ -6622,7 +6622,7 @@ fn func() void {
66226622 </p>
66236623 {#code_begin|test#}
66246624const std = @import("std");
6625const assert = std.debug.assert;
6625const expect = std.testing.expect;
66266626
66276627var the_frame: anyframe = undefined;
66286628var final_result: i32 = 0;
......@@ -6633,8 +6633,8 @@ test "async function await" {
66336633 seq('f');
66346634 resume the_frame;
66356635 seq('i');
6636 assert(final_result == 1234);
6637 assert(std.mem.eql(u8, &seq_points, "abcdefghi"));
6636 expect(final_result == 1234);
6637 expect(std.mem.eql(u8, &seq_points, "abcdefghi"));
66386638}
66396639fn amain() void {
66406640 seq('b');
......@@ -6848,9 +6848,9 @@ fn readFile(allocator: *Allocator, filename: []const u8) ![]u8 {
68486848 for the current target to match the C ABI. When the child type of a pointer has
68496849 this alignment, the alignment can be omitted from the type.
68506850 </p>
6851 <pre>{#syntax#}const assert = @import("std").debug.assert;
6851 <pre>{#syntax#}const expect = @import("std").testing.expect;
68526852comptime {
6853 assert(*u32 == *align(@alignOf(u32)) u32);
6853 expect(*u32 == *align(@alignOf(u32)) u32);
68546854}{#endsyntax#}</pre>
68556855 <p>
68566856 The result is a target-specific compile time constant. It is guaranteed to be
......@@ -6886,7 +6886,7 @@ comptime {
68866886 </p>
68876887 {#code_begin|test#}
68886888const std = @import("std");
6889const assert = std.debug.assert;
6889const expect = std.testing.expect;
68906890
68916891test "async fn pointer in a struct field" {
68926892 var data: i32 = 1;
......@@ -6896,9 +6896,9 @@ test "async fn pointer in a struct field" {
68966896 var foo = Foo{ .bar = func };
68976897 var bytes: [64]u8 align(@alignOf(@Frame(func))) = undefined;
68986898 const f = @asyncCall(&bytes, {}, foo.bar, .{&data});
6899 assert(data == 2);
6899 expect(data == 2);
69006900 resume f;
6901 assert(data == 4);
6901 expect(data == 4);
69026902}
69036903
69046904fn func(y: *i32) void {
......@@ -7082,10 +7082,10 @@ fn func(y: *i32) void {
70827082 Calls a function, in the same way that invoking an expression with parentheses does:
70837083 </p>
70847084 {#code_begin|test|call#}
7085const assert = @import("std").debug.assert;
7085const expect = @import("std").testing.expect;
70867086
70877087test "noinline function call" {
7088 assert(@call(.{}, add, .{3, 9}) == 12);
7088 expect(@call(.{}, add, .{3, 9}) == 12);
70897089}
70907090
70917091fn add(a: i32, b: i32) i32 {
......@@ -7544,14 +7544,14 @@ const Point = struct {
75447544};
75457545
75467546test "field access by string" {
7547 const assert = std.debug.assert;
7547 const expect = std.testing.expect;
75487548 var p = Point {.x = 0, .y = 0};
75497549
75507550 @field(p, "x") = 4;
75517551 @field(p, "y") = @field(p, "x") + 1;
75527552
7553 assert(@field(p, "x") == 4);
7554 assert(@field(p, "y") == 5);
7553 expect(@field(p, "x") == 4);
7554 expect(@field(p, "y") == 5);
75557555}
75567556 {#code_end#}
75577557
......@@ -7657,7 +7657,7 @@ fn func() void {
76577657 </p>
76587658 {#code_begin|test#}
76597659const std = @import("std");
7660const assert = std.debug.assert;
7660const expect = std.testing.expect;
76617661
76627662const Foo = struct {
76637663 nope: i32,
......@@ -7667,16 +7667,16 @@ const Foo = struct {
76677667};
76687668
76697669test "@hasDecl" {
7670 assert(@hasDecl(Foo, "blah"));
7670 expect(@hasDecl(Foo, "blah"));
76717671
76727672 // Even though `hi` is private, @hasDecl returns true because this test is
76737673 // in the same file scope as Foo. It would return false if Foo was declared
76747674 // in a different file.
7675 assert(@hasDecl(Foo, "hi"));
7675 expect(@hasDecl(Foo, "hi"));
76767676
76777677 // @hasDecl is for declarations; not fields.
7678 assert(!@hasDecl(Foo, "nope"));
7679 assert(!@hasDecl(Foo, "nope1234"));
7678 expect(!@hasDecl(Foo, "nope"));
7679 expect(!@hasDecl(Foo, "nope1234"));
76807680}
76817681 {#code_end#}
76827682 {#see_also|@hasField#}
......@@ -7851,14 +7851,14 @@ mem.set(u8, dest, c);{#endsyntax#}</pre>
78517851 {#code_begin|test#}
78527852const std = @import("std");
78537853const builtin = @import("builtin");
7854const assert = std.debug.assert;
7854const expect = std.testing.expect;
78557855
78567856test "@wasmMemoryGrow" {
78577857 if (builtin.arch != .wasm32) return error.SkipZigTest;
78587858
78597859 var prev = @wasmMemorySize(0);
7860 assert(prev == @wasmMemoryGrow(0, 1));
7861 assert(prev + 1 == @wasmMemorySize(0));
7860 expect(prev == @wasmMemoryGrow(0, 1));
7861 expect(prev + 1 == @wasmMemorySize(0));
78627862}
78637863 {#code_end#}
78647864 {#see_also|@wasmMemorySize#}
......@@ -8194,13 +8194,13 @@ test "@setRuntimeSafety" {
81948194 </p>
81958195 {#code_begin|test#}
81968196const std = @import("std");
8197const assert = std.debug.assert;
8197const expect = std.testing.expect;
81988198
81998199test "vector @splat" {
82008200 const scalar: u32 = 5;
82018201 const result = @splat(4, scalar);
8202 comptime assert(@TypeOf(result) == std.meta.Vector(4, u32));
8203 assert(std.mem.eql(u32, &@as([4]u32, result), &[_]u32{ 5, 5, 5, 5 }));
8202 comptime expect(@TypeOf(result) == std.meta.Vector(4, u32));
8203 expect(std.mem.eql(u32, &@as([4]u32, result), &[_]u32{ 5, 5, 5, 5 }));
82048204}
82058205 {#code_end#}
82068206 <p>
......@@ -8410,12 +8410,12 @@ fn doTheTest() void {
84108410 </p>
84118411 {#code_begin|test#}
84128412const std = @import("std");
8413const assert = std.debug.assert;
8413const expect = std.testing.expect;
84148414
84158415test "@This()" {
84168416 var items = [_]i32{ 1, 2, 3, 4 };
84178417 const list = List(i32){ .items = items[0..] };
8418 assert(list.length() == 4);
8418 expect(list.length() == 4);
84198419}
84208420
84218421fn List(comptime T: type) type {
......@@ -8456,12 +8456,12 @@ test "integer cast panic" {
84568456 </p>
84578457 {#code_begin|test|truncate#}
84588458const std = @import("std");
8459const assert = std.debug.assert;
8459const expect = std.testing.expect;
84608460
84618461test "integer truncation" {
84628462 var a: u16 = 0xabcd;
84638463 var b: u8 = @truncate(u8, a);
8464 assert(b == 0xcd);
8464 expect(b == 0xcd);
84658465}
84668466 {#code_end#}
84678467 <p>
......@@ -8544,13 +8544,13 @@ test "integer truncation" {
85448544 </p>
85458545 {#code_begin|test#}
85468546const std = @import("std");
8547const assert = std.debug.assert;
8547const expect = std.testing.expect;
85488548
85498549test "no runtime side effects" {
85508550 var data: i32 = 0;
85518551 const T = @TypeOf(foo(i32, &data));
8552 comptime assert(T == i32);
8553 assert(data == 0);
8552 comptime expect(T == i32);
8553 expect(data == 0);
85548554}
85558555
85568556fn foo(comptime T: type, ptr: *T) T {
......@@ -8853,16 +8853,16 @@ pub fn main() void {
88538853 </ul>
88548854 {#code_begin|test#}
88558855const std = @import("std");
8856const assert = std.debug.assert;
8856const expect = std.testing.expect;
88578857const minInt = std.math.minInt;
88588858const maxInt = std.math.maxInt;
88598859
88608860test "wraparound addition and subtraction" {
88618861 const x: i32 = maxInt(i32);
88628862 const min_val = x +% 1;
8863 assert(min_val == minInt(i32));
8863 expect(min_val == minInt(i32));
88648864 const max_val = min_val -% 1;
8865 assert(max_val == maxInt(i32));
8865 expect(max_val == maxInt(i32));
88668866}
88678867 {#code_end#}
88688868 {#header_close#}
......@@ -9287,13 +9287,13 @@ pub fn main() void {
92879287 {#code_begin|test|allocator#}
92889288const std = @import("std");
92899289const Allocator = std.mem.Allocator;
9290const assert = std.debug.assert;
9290const expect = std.testing.expect;
92919291
92929292test "using an allocator" {
92939293 var buffer: [100]u8 = undefined;
92949294 const allocator = &std.heap.FixedBufferAllocator.init(&buffer).allocator;
92959295 const result = try concat(allocator, "foo", "bar");
9296 assert(std.mem.eql(u8, "foobar", result));
9296 expect(std.mem.eql(u8, "foobar", result));
92979297}
92989298
92999299fn concat(allocator: *Allocator, a: []const u8, b: []const u8) ![]u8 {
......@@ -9560,10 +9560,10 @@ const separator = if (builtin.os == builtin.Os.windows) '\\' else '/';
95609560 {#code_begin|test|detect_test#}
95619561const std = @import("std");
95629562const builtin = std.builtin;
9563const assert = std.debug.assert;
9563const expect = std.testing.expect;
95649564
95659565test "builtin.is_test" {
9566 assert(builtin.is_test);
9566 expect(builtin.is_test);
95679567}
95689568 {#code_end#}
95699569 <p>
......@@ -9613,7 +9613,7 @@ test "assert in release fast mode" {
96139613const std = @import("std");
96149614const expect = std.testing.expect;
96159615
9616test "assert in release fast mode" {
9616test "expect in release fast mode" {
96179617 expect(false);
96189618}
96199619 {#code_end#}