authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-05-08 14:45:21-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-05-08 14:45:21-07:00
log5619ce2406a545e177882415195575463989066d
tree5c0e786d19054a56ae42272713de321e25d2efc8
parent5cd9afc6b6cf33f650e5afc6b726b91dfb97e697
parent67154d233ef68d9fd63e673e63e7d66f149060a5

Merge remote-tracking branch 'origin/master' into stage2-whole-file-astgen

Conflicts: * doc/langref.html.in * lib/std/enums.zig * lib/std/fmt.zig * lib/std/hash/auto_hash.zig * lib/std/math.zig * lib/std/mem.zig * lib/std/meta.zig * test/behavior/alignof.zig * test/behavior/bitcast.zig * test/behavior/bugs/1421.zig * test/behavior/cast.zig * test/behavior/ptrcast.zig * test/behavior/type_info.zig * test/behavior/vector.zig Master branch added `try` to a bunch of testing function calls, and some lines also had changed how to refer to the native architecture and other `@import("builtin")` stuff.

408 files changed, 12619 insertions(+), 12610 deletions(-)

doc/langref.html.in+348-347
......@@ -358,7 +358,7 @@ test "comments" {
358358 //expect(false);
359359
360360 const x = true; // another comment
361 expect(x);
361 try expect(x);
362362}
363363 {#code_end#}
364364 <p>
......@@ -718,15 +718,15 @@ const mem = @import("std").mem;
718718
719719test "string literals" {
720720 const bytes = "hello";
721 expect(@TypeOf(bytes) == *const [5:0]u8);
722 expect(bytes.len == 5);
723 expect(bytes[1] == 'e');
724 expect(bytes[5] == 0);
725 expect('e' == '\x65');
726 expect('\u{1f4a9}' == 128169);
727 expect('💯' == 128175);
728 expect(mem.eql(u8, "hello", "h\x65llo"));
729 expect("\xff"[0] == 0xff); // non-UTF-8 strings are possible with \xNN notation.
721 try expect(@TypeOf(bytes) == *const [5:0]u8);
722 try expect(bytes.len == 5);
723 try expect(bytes[1] == 'e');
724 try expect(bytes[5] == 0);
725 try expect('e' == '\x65');
726 try expect('\u{1f4a9}' == 128169);
727 try expect('💯' == 128175);
728 try expect(mem.eql(u8, "hello", "h\x65llo"));
729 try expect("\xff"[0] == 0xff); // non-UTF-8 strings are possible with \xNN notation.
730730}
731731 {#code_end#}
732732 {#see_also|Arrays|Zig Test|Source Encoding#}
......@@ -826,7 +826,7 @@ test "var" {
826826
827827 y += 1;
828828
829 expect(y == 5679);
829 try expect(y == 5679);
830830}
831831 {#code_end#}
832832 <p>Variables must be initialized:</p>
......@@ -845,7 +845,7 @@ const expect = @import("std").testing.expect;
845845test "init with undefined" {
846846 var x: i32 = undefined;
847847 x = 1;
848 expect(x == 1);
848 try expect(x == 1);
849849}
850850 {#code_end#}
851851 <p>
......@@ -887,8 +887,8 @@ var y: i32 = add(10, x);
887887const x: i32 = add(12, 34);
888888
889889test "global variables" {
890 expect(x == 46);
891 expect(y == 56);
890 try expect(x == 46);
891 try expect(y == 56);
892892}
893893
894894fn add(a: i32, b: i32) i32 {
......@@ -906,8 +906,8 @@ const std = @import("std");
906906const expect = std.testing.expect;
907907
908908test "namespaced global variable" {
909 expect(foo() == 1235);
910 expect(foo() == 1236);
909 try expect(foo() == 1235);
910 try expect(foo() == 1236);
911911}
912912
913913fn foo() i32 {
......@@ -985,8 +985,8 @@ test "comptime vars" {
985985 x += 1;
986986 y += 1;
987987
988 expect(x == 2);
989 expect(y == 2);
988 try expect(x == 2);
989 try expect(y == 2);
990990
991991 if (y != 2) {
992992 // This compile error never triggers because y is a comptime variable,
......@@ -1777,6 +1777,7 @@ orelse catch
17771777 {#header_open|Arrays#}
17781778 {#code_begin|test|arrays#}
17791779const expect = @import("std").testing.expect;
1780const assert = @import("std").debug.assert;
17801781const mem = @import("std").mem;
17811782
17821783// array literal
......@@ -1784,14 +1785,14 @@ const message = [_]u8{ 'h', 'e', 'l', 'l', 'o' };
17841785
17851786// get the size of an array
17861787comptime {
1787 expect(message.len == 5);
1788 assert(message.len == 5);
17881789}
17891790
17901791// A string literal is a single-item pointer to an array literal.
17911792const same_message = "hello";
17921793
17931794comptime {
1794 expect(mem.eql(u8, &message, same_message));
1795 assert(mem.eql(u8, &message, same_message));
17951796}
17961797
17971798test "iterate over an array" {
......@@ -1799,7 +1800,7 @@ test "iterate over an array" {
17991800 for (message) |byte| {
18001801 sum += byte;
18011802 }
1802 expect(sum == 'h' + 'e' + 'l' * 2 + 'o');
1803 try expect(sum == 'h' + 'e' + 'l' * 2 + 'o');
18031804}
18041805
18051806// modifiable array
......@@ -1809,8 +1810,8 @@ test "modify an array" {
18091810 for (some_integers) |*item, i| {
18101811 item.* = @intCast(i32, i);
18111812 }
1812 expect(some_integers[10] == 10);
1813 expect(some_integers[99] == 99);
1813 try expect(some_integers[10] == 10);
1814 try expect(some_integers[99] == 99);
18141815}
18151816
18161817// array concatenation works if the values are known
......@@ -1819,7 +1820,7 @@ const part_one = [_]i32{ 1, 2, 3, 4 };
18191820const part_two = [_]i32{ 5, 6, 7, 8 };
18201821const all_of_it = part_one ++ part_two;
18211822comptime {
1822 expect(mem.eql(i32, &all_of_it, &[_]i32{ 1, 2, 3, 4, 5, 6, 7, 8 }));
1823 assert(mem.eql(i32, &all_of_it, &[_]i32{ 1, 2, 3, 4, 5, 6, 7, 8 }));
18231824}
18241825
18251826// remember that string literals are arrays
......@@ -1827,21 +1828,21 @@ const hello = "hello";
18271828const world = "world";
18281829const hello_world = hello ++ " " ++ world;
18291830comptime {
1830 expect(mem.eql(u8, hello_world, "hello world"));
1831 assert(mem.eql(u8, hello_world, "hello world"));
18311832}
18321833
18331834// ** does repeating patterns
18341835const pattern = "ab" ** 3;
18351836comptime {
1836 expect(mem.eql(u8, pattern, "ababab"));
1837 assert(mem.eql(u8, pattern, "ababab"));
18371838}
18381839
18391840// initialize an array to zero
18401841const all_zero = [_]u16{0} ** 10;
18411842
18421843comptime {
1843 expect(all_zero.len == 10);
1844 expect(all_zero[5] == 0);
1844 assert(all_zero.len == 10);
1845 assert(all_zero[5] == 0);
18451846}
18461847
18471848// use compile-time code to initialize an array
......@@ -1861,8 +1862,8 @@ const Point = struct {
18611862};
18621863
18631864test "compile-time array initialization" {
1864 expect(fancy_array[4].x == 4);
1865 expect(fancy_array[4].y == 8);
1865 try expect(fancy_array[4].x == 4);
1866 try expect(fancy_array[4].y == 8);
18661867}
18671868
18681869// call a function to initialize an array
......@@ -1874,9 +1875,9 @@ fn makePoint(x: i32) Point {
18741875 };
18751876}
18761877test "array initialization with function calls" {
1877 expect(more_points[4].x == 3);
1878 expect(more_points[4].y == 6);
1879 expect(more_points.len == 10);
1878 try expect(more_points[4].x == 3);
1879 try expect(more_points[4].y == 6);
1880 try expect(more_points.len == 10);
18801881}
18811882 {#code_end#}
18821883 {#see_also|for|Slices#}
......@@ -1890,10 +1891,10 @@ const expect = std.testing.expect;
18901891
18911892test "anonymous list literal syntax" {
18921893 var array: [4]u8 = .{11, 22, 33, 44};
1893 expect(array[0] == 11);
1894 expect(array[1] == 22);
1895 expect(array[2] == 33);
1896 expect(array[3] == 44);
1894 try expect(array[0] == 11);
1895 try expect(array[1] == 22);
1896 try expect(array[2] == 33);
1897 try expect(array[3] == 44);
18971898}
18981899 {#code_end#}
18991900 <p>
......@@ -1905,15 +1906,15 @@ const std = @import("std");
19051906const expect = std.testing.expect;
19061907
19071908test "fully anonymous list literal" {
1908 dump(.{ @as(u32, 1234), @as(f64, 12.34), true, "hi"});
1909 try dump(.{ @as(u32, 1234), @as(f64, 12.34), true, "hi"});
19091910}
19101911
1911fn dump(args: anytype) void {
1912 expect(args.@"0" == 1234);
1913 expect(args.@"1" == 12.34);
1914 expect(args.@"2");
1915 expect(args.@"3"[0] == 'h');
1916 expect(args.@"3"[1] == 'i');
1912fn dump(args: anytype) !void {
1913 try expect(args.@"0" == 1234);
1914 try expect(args.@"1" == 12.34);
1915 try expect(args.@"2");
1916 try expect(args.@"3"[0] == 'h');
1917 try expect(args.@"3"[1] == 'i');
19171918}
19181919 {#code_end#}
19191920 {#header_close#}
......@@ -1934,13 +1935,13 @@ const mat4x4 = [4][4]f32{
19341935};
19351936test "multidimensional arrays" {
19361937 // Access the 2D array by indexing the outer array, and then the inner array.
1937 expect(mat4x4[1][1] == 1.0);
1938 try expect(mat4x4[1][1] == 1.0);
19381939
19391940 // Here we iterate with for loops.
19401941 for (mat4x4) |row, row_index| {
19411942 for (row) |cell, column_index| {
19421943 if (row_index == column_index) {
1943 expect(cell == 1.0);
1944 try expect(cell == 1.0);
19441945 }
19451946 }
19461947 }
......@@ -1960,9 +1961,9 @@ const expect = std.testing.expect;
19601961test "null terminated array" {
19611962 const array = [_:0]u8 {1, 2, 3, 4};
19621963
1963 expect(@TypeOf(array) == [4:0]u8);
1964 expect(array.len == 4);
1965 expect(array[4] == 0);
1964 try expect(@TypeOf(array) == [4:0]u8);
1965 try expect(array.len == 4);
1966 try expect(array[4] == 0);
19661967}
19671968 {#code_end#}
19681969 {#see_also|Sentinel-Terminated Pointers|Sentinel-Terminated Slices#}
......@@ -2040,17 +2041,17 @@ test "address of syntax" {
20402041 const x_ptr = &x;
20412042
20422043 // Dereference a pointer:
2043 expect(x_ptr.* == 1234);
2044 try expect(x_ptr.* == 1234);
20442045
20452046 // When you get the address of a const variable, you get a const single-item pointer.
2046 expect(@TypeOf(x_ptr) == *const i32);
2047 try expect(@TypeOf(x_ptr) == *const i32);
20472048
20482049 // If you want to mutate the value, you'd need an address of a mutable variable:
20492050 var y: i32 = 5678;
20502051 const y_ptr = &y;
2051 expect(@TypeOf(y_ptr) == *i32);
2052 try expect(@TypeOf(y_ptr) == *i32);
20522053 y_ptr.* += 1;
2053 expect(y_ptr.* == 5679);
2054 try expect(y_ptr.* == 5679);
20542055}
20552056
20562057test "pointer array access" {
......@@ -2059,11 +2060,11 @@ test "pointer array access" {
20592060 // does not support pointer arithmetic.
20602061 var array = [_]u8{ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
20612062 const ptr = &array[2];
2062 expect(@TypeOf(ptr) == *u8);
2063 try expect(@TypeOf(ptr) == *u8);
20632064
2064 expect(array[2] == 3);
2065 try expect(array[2] == 3);
20652066 ptr.* += 1;
2066 expect(array[2] == 4);
2067 try expect(array[2] == 4);
20672068}
20682069 {#code_end#}
20692070 <p>
......@@ -2081,11 +2082,11 @@ const expect = @import("std").testing.expect;
20812082test "pointer slicing" {
20822083 var array = [_]u8{ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
20832084 const slice = array[2..4];
2084 expect(slice.len == 2);
2085 try expect(slice.len == 2);
20852086
2086 expect(array[3] == 4);
2087 try expect(array[3] == 4);
20872088 slice[1] += 1;
2088 expect(array[3] == 5);
2089 try expect(array[3] == 5);
20892090}
20902091 {#code_end#}
20912092 <p>Pointers work at compile-time too, as long as the code does not depend on
......@@ -2099,7 +2100,7 @@ test "comptime pointers" {
20992100 const ptr = &x;
21002101 ptr.* += 1;
21012102 x += 1;
2102 expect(ptr.* == 3);
2103 try expect(ptr.* == 3);
21032104 }
21042105}
21052106 {#code_end#}
......@@ -2111,8 +2112,8 @@ const expect = @import("std").testing.expect;
21112112test "@ptrToInt and @intToPtr" {
21122113 const ptr = @intToPtr(*i32, 0xdeadbee0);
21132114 const addr = @ptrToInt(ptr);
2114 expect(@TypeOf(addr) == usize);
2115 expect(addr == 0xdeadbee0);
2115 try expect(@TypeOf(addr) == usize);
2116 try expect(addr == 0xdeadbee0);
21162117}
21172118 {#code_end#}
21182119 <p>Zig is able to preserve memory addresses in comptime code, as long as
......@@ -2126,8 +2127,8 @@ test "comptime @intToPtr" {
21262127 // ptr is never dereferenced.
21272128 const ptr = @intToPtr(*i32, 0xdeadbee0);
21282129 const addr = @ptrToInt(ptr);
2129 expect(@TypeOf(addr) == usize);
2130 expect(addr == 0xdeadbee0);
2130 try expect(@TypeOf(addr) == usize);
2131 try expect(addr == 0xdeadbee0);
21312132 }
21322133}
21332134 {#code_end#}
......@@ -2142,7 +2143,7 @@ const expect = @import("std").testing.expect;
21422143
21432144test "volatile" {
21442145 const mmio_ptr = @intToPtr(*volatile u8, 0x12345678);
2145 expect(@TypeOf(mmio_ptr) == *volatile u8);
2146 try expect(@TypeOf(mmio_ptr) == *volatile u8);
21462147}
21472148 {#code_end#}
21482149 <p>
......@@ -2163,20 +2164,20 @@ const expect = std.testing.expect;
21632164test "pointer casting" {
21642165 const bytes align(@alignOf(u32)) = [_]u8{ 0x12, 0x12, 0x12, 0x12 };
21652166 const u32_ptr = @ptrCast(*const u32, &bytes);
2166 expect(u32_ptr.* == 0x12121212);
2167 try expect(u32_ptr.* == 0x12121212);
21672168
21682169 // Even this example is contrived - there are better ways to do the above than
21692170 // pointer casting. For example, using a slice narrowing cast:
21702171 const u32_value = std.mem.bytesAsSlice(u32, bytes[0..])[0];
2171 expect(u32_value == 0x12121212);
2172 try expect(u32_value == 0x12121212);
21722173
21732174 // And even another way, the most straightforward way to do it:
2174 expect(@bitCast(u32, bytes) == 0x12121212);
2175 try expect(@bitCast(u32, bytes) == 0x12121212);
21752176}
21762177
21772178test "pointer child type" {
21782179 // pointer types have a `child` field which tells you the type they point to.
2179 expect(@typeInfo(*u32).Pointer.child == u32);
2180 try expect(@typeInfo(*u32).Pointer.child == u32);
21802181}
21812182 {#code_end#}
21822183 {#header_open|Alignment#}
......@@ -2201,10 +2202,10 @@ const expect = std.testing.expect;
22012202test "variable alignment" {
22022203 var x: i32 = 1234;
22032204 const align_of_i32 = @alignOf(@TypeOf(x));
2204 expect(@TypeOf(&x) == *i32);
2205 expect(*i32 == *align(align_of_i32) i32);
2205 try expect(@TypeOf(&x) == *i32);
2206 try expect(*i32 == *align(align_of_i32) i32);
22062207 if (std.Target.current.cpu.arch == .x86_64) {
2207 expect(@typeInfo(*i32).Pointer.alignment == 4);
2208 try expect(@typeInfo(*i32).Pointer.alignment == 4);
22082209 }
22092210}
22102211 {#code_end#}
......@@ -2222,11 +2223,11 @@ const expect = @import("std").testing.expect;
22222223var foo: u8 align(4) = 100;
22232224
22242225test "global variable alignment" {
2225 expect(@typeInfo(@TypeOf(&foo)).Pointer.alignment == 4);
2226 expect(@TypeOf(&foo) == *align(4) u8);
2226 try expect(@typeInfo(@TypeOf(&foo)).Pointer.alignment == 4);
2227 try expect(@TypeOf(&foo) == *align(4) u8);
22272228 const as_pointer_to_array: *[1]u8 = &foo;
22282229 const as_slice: []u8 = as_pointer_to_array;
2229 expect(@TypeOf(as_slice) == []align(4) u8);
2230 try expect(@TypeOf(as_slice) == []align(4) u8);
22302231}
22312232
22322233fn derp() align(@sizeOf(usize) * 2) i32 { return 1234; }
......@@ -2234,9 +2235,9 @@ fn noop1() align(1) void {}
22342235fn noop4() align(4) void {}
22352236
22362237test "function alignment" {
2237 expect(derp() == 1234);
2238 expect(@TypeOf(noop1) == fn() align(1) void);
2239 expect(@TypeOf(noop4) == fn() align(4) void);
2238 try expect(derp() == 1234);
2239 try expect(@TypeOf(noop1) == fn() align(1) void);
2240 try expect(@TypeOf(noop4) == fn() align(4) void);
22402241 noop1();
22412242 noop4();
22422243}
......@@ -2253,7 +2254,7 @@ const std = @import("std");
22532254test "pointer alignment safety" {
22542255 var array align(4) = [_]u32{ 0x11111111, 0x11111111 };
22552256 const bytes = std.mem.sliceAsBytes(array[0..]);
2256 std.testing.expect(foo(bytes) == 0x11111111);
2257 try std.testing.expect(foo(bytes) == 0x11111111);
22572258}
22582259fn foo(bytes: []u8) u32 {
22592260 const slice4 = bytes[1..5];
......@@ -2279,7 +2280,7 @@ const expect = std.testing.expect;
22792280test "allowzero" {
22802281 var zero: usize = 0;
22812282 var ptr = @intToPtr(*allowzero i32, zero);
2282 expect(@ptrToInt(ptr) == 0);
2283 try expect(@ptrToInt(ptr) == 0);
22832284}
22842285 {#code_end#}
22852286 {#header_close#}
......@@ -2321,14 +2322,14 @@ test "basic slices" {
23212322 // Both can be accessed with the `len` field.
23222323 var known_at_runtime_zero: usize = 0;
23232324 const slice = array[known_at_runtime_zero..array.len];
2324 expect(&slice[0] == &array[0]);
2325 expect(slice.len == array.len);
2325 try expect(&slice[0] == &array[0]);
2326 try expect(slice.len == array.len);
23262327
23272328 // Using the address-of operator on a slice gives a single-item pointer,
23282329 // while using the `ptr` field gives a many-item pointer.
2329 expect(@TypeOf(slice.ptr) == [*]i32);
2330 expect(@TypeOf(&slice[0]) == *i32);
2331 expect(@ptrToInt(slice.ptr) == @ptrToInt(&slice[0]));
2330 try expect(@TypeOf(slice.ptr) == [*]i32);
2331 try expect(@TypeOf(&slice[0]) == *i32);
2332 try expect(@ptrToInt(slice.ptr) == @ptrToInt(&slice[0]));
23322333
23332334 // Slices have array bounds checking. If you try to access something out
23342335 // of bounds, you'll get a safety check failure:
......@@ -2362,7 +2363,7 @@ test "using slices for strings" {
23622363 // Generally, you can use UTF-8 and not worry about whether something is a
23632364 // string. If you don't need to deal with individual characters, no need
23642365 // to decode.
2365 expect(mem.eql(u8, hello_world, "hello 世界"));
2366 try expect(mem.eql(u8, hello_world, "hello 世界"));
23662367}
23672368
23682369test "slice pointer" {
......@@ -2372,16 +2373,16 @@ test "slice pointer" {
23722373 // You can use slicing syntax to convert a pointer into a slice:
23732374 const slice = ptr[0..5];
23742375 slice[2] = 3;
2375 expect(slice[2] == 3);
2376 try expect(slice[2] == 3);
23762377 // The slice is mutable because we sliced a mutable pointer.
23772378 // Furthermore, it is actually a pointer to an array, since the start
23782379 // and end indexes were both comptime-known.
2379 expect(@TypeOf(slice) == *[5]u8);
2380 try expect(@TypeOf(slice) == *[5]u8);
23802381
23812382 // You can also slice a slice:
23822383 const slice2 = slice[2..3];
2383 expect(slice2.len == 1);
2384 expect(slice2[0] == 3);
2384 try expect(slice2.len == 1);
2385 try expect(slice2[0] == 3);
23852386}
23862387 {#code_end#}
23872388 {#see_also|Pointers|for|Arrays#}
......@@ -2400,8 +2401,8 @@ const expect = std.testing.expect;
24002401test "null terminated slice" {
24012402 const slice: [:0]const u8 = "hello";
24022403
2403 expect(slice.len == 5);
2404 expect(slice[5] == 0);
2404 try expect(slice.len == 5);
2405 try expect(slice[5] == 0);
24052406}
24062407 {#code_end#}
24072408 {#see_also|Sentinel-Terminated Pointers|Sentinel-Terminated Arrays#}
......@@ -2463,12 +2464,12 @@ const expect = @import("std").testing.expect;
24632464test "dot product" {
24642465 const v1 = Vec3.init(1.0, 0.0, 0.0);
24652466 const v2 = Vec3.init(0.0, 1.0, 0.0);
2466 expect(v1.dot(v2) == 0.0);
2467 try expect(v1.dot(v2) == 0.0);
24672468
24682469 // Other than being available to call with dot syntax, struct methods are
24692470 // not special. You can reference them as any other declaration inside
24702471 // the struct:
2471 expect(Vec3.dot(v1, v2) == 0.0);
2472 try expect(Vec3.dot(v1, v2) == 0.0);
24722473}
24732474
24742475// Structs can have global declarations.
......@@ -2477,8 +2478,8 @@ const Empty = struct {
24772478 pub const PI = 3.14;
24782479};
24792480test "struct namespaced variable" {
2480 expect(Empty.PI == 3.14);
2481 expect(@sizeOf(Empty) == 0);
2481 try expect(Empty.PI == 3.14);
2482 try expect(@sizeOf(Empty) == 0);
24822483
24832484 // you can still instantiate an empty struct
24842485 const does_nothing = Empty {};
......@@ -2496,7 +2497,7 @@ test "field parent pointer" {
24962497 .y = 0.5678,
24972498 };
24982499 setYBasedOnX(&point.x, 0.9);
2499 expect(point.y == 0.9);
2500 try expect(point.y == 0.9);
25002501}
25012502
25022503// You can return a struct from a function. This is how we do generics
......@@ -2518,19 +2519,19 @@ fn LinkedList(comptime T: type) type {
25182519test "linked list" {
25192520 // Functions called at compile-time are memoized. This means you can
25202521 // do this:
2521 expect(LinkedList(i32) == LinkedList(i32));
2522 try expect(LinkedList(i32) == LinkedList(i32));
25222523
25232524 var list = LinkedList(i32) {
25242525 .first = null,
25252526 .last = null,
25262527 .len = 0,
25272528 };
2528 expect(list.len == 0);
2529 try expect(list.len == 0);
25292530
25302531 // Since types are first class values you can instantiate the type
25312532 // by assigning it to a variable:
25322533 const ListOfInts = LinkedList(i32);
2533 expect(ListOfInts == LinkedList(i32));
2534 try expect(ListOfInts == LinkedList(i32));
25342535
25352536 var node = ListOfInts.Node {
25362537 .prev = null,
......@@ -2542,7 +2543,7 @@ test "linked list" {
25422543 .last = &node,
25432544 .len = 1,
25442545 };
2545 expect(list2.first.?.data == 1234);
2546 try expect(list2.first.?.data == 1234);
25462547}
25472548 {#code_end#}
25482549
......@@ -2615,25 +2616,25 @@ const Divided = packed struct {
26152616};
26162617
26172618test "@bitCast between packed structs" {
2618 doTheTest();
2619 comptime doTheTest();
2619 try doTheTest();
2620 comptime try doTheTest();
26202621}
26212622
2622fn doTheTest() void {
2623 expect(@sizeOf(Full) == 2);
2624 expect(@sizeOf(Divided) == 2);
2623fn doTheTest() !void {
2624 try expect(@sizeOf(Full) == 2);
2625 try expect(@sizeOf(Divided) == 2);
26252626 var full = Full{ .number = 0x1234 };
26262627 var divided = @bitCast(Divided, full);
26272628 switch (builtin.endian) {
26282629 .Big => {
2629 expect(divided.half1 == 0x12);
2630 expect(divided.quarter3 == 0x3);
2631 expect(divided.quarter4 == 0x4);
2630 try expect(divided.half1 == 0x12);
2631 try expect(divided.quarter3 == 0x3);
2632 try expect(divided.quarter4 == 0x4);
26322633 },
26332634 .Little => {
2634 expect(divided.half1 == 0x34);
2635 expect(divided.quarter3 == 0x2);
2636 expect(divided.quarter4 == 0x1);
2635 try expect(divided.half1 == 0x34);
2636 try expect(divided.quarter3 == 0x2);
2637 try expect(divided.quarter4 == 0x1);
26372638 },
26382639 }
26392640}
......@@ -2659,7 +2660,7 @@ var foo = BitField{
26592660
26602661test "pointer to non-byte-aligned field" {
26612662 const ptr = &foo.b;
2662 expect(ptr.* == 2);
2663 try expect(ptr.* == 2);
26632664}
26642665 {#code_end#}
26652666 <p>
......@@ -2683,7 +2684,7 @@ var bit_field = BitField{
26832684};
26842685
26852686test "pointer to non-bit-aligned field" {
2686 expect(bar(&bit_field.b) == 2);
2687 try expect(bar(&bit_field.b) == 2);
26872688}
26882689
26892690fn bar(x: *const u3) u3 {
......@@ -2714,8 +2715,8 @@ var bit_field = BitField{
27142715};
27152716
27162717test "pointer to non-bit-aligned field" {
2717 expect(@ptrToInt(&bit_field.a) == @ptrToInt(&bit_field.b));
2718 expect(@ptrToInt(&bit_field.a) == @ptrToInt(&bit_field.c));
2718 try expect(@ptrToInt(&bit_field.a) == @ptrToInt(&bit_field.b));
2719 try expect(@ptrToInt(&bit_field.a) == @ptrToInt(&bit_field.c));
27192720}
27202721 {#code_end#}
27212722 <p>
......@@ -2733,13 +2734,13 @@ const BitField = packed struct {
27332734
27342735test "pointer to non-bit-aligned field" {
27352736 comptime {
2736 expect(@bitOffsetOf(BitField, "a") == 0);
2737 expect(@bitOffsetOf(BitField, "b") == 3);
2738 expect(@bitOffsetOf(BitField, "c") == 6);
2737 try expect(@bitOffsetOf(BitField, "a") == 0);
2738 try expect(@bitOffsetOf(BitField, "b") == 3);
2739 try expect(@bitOffsetOf(BitField, "c") == 6);
27392740
2740 expect(@byteOffsetOf(BitField, "a") == 0);
2741 expect(@byteOffsetOf(BitField, "b") == 0);
2742 expect(@byteOffsetOf(BitField, "c") == 0);
2741 try expect(@byteOffsetOf(BitField, "a") == 0);
2742 try expect(@byteOffsetOf(BitField, "b") == 0);
2743 try expect(@byteOffsetOf(BitField, "c") == 0);
27432744 }
27442745}
27452746 {#code_end#}
......@@ -2776,9 +2777,9 @@ test "aligned struct fields" {
27762777 };
27772778 var foo = S{ .a = 1, .b = 2 };
27782779
2779 expectEqual(64, @alignOf(S));
2780 expectEqual(*align(2) u32, @TypeOf(&foo.a));
2781 expectEqual(*align(64) u32, @TypeOf(&foo.b));
2780 try expectEqual(64, @alignOf(S));
2781 try expectEqual(*align(2) u32, @TypeOf(&foo.a));
2782 try expectEqual(*align(64) u32, @TypeOf(&foo.b));
27822783}
27832784 {#code_end#}
27842785 <p>
......@@ -2834,8 +2835,8 @@ test "anonymous struct literal" {
28342835 .x = 13,
28352836 .y = 67,
28362837 };
2837 expect(pt.x == 13);
2838 expect(pt.y == 67);
2838 try expect(pt.x == 13);
2839 try expect(pt.y == 67);
28392840}
28402841 {#code_end#}
28412842 <p>
......@@ -2847,7 +2848,7 @@ const std = @import("std");
28472848const expect = std.testing.expect;
28482849
28492850test "fully anonymous struct" {
2850 dump(.{
2851 try dump(.{
28512852 .int = @as(u32, 1234),
28522853 .float = @as(f64, 12.34),
28532854 .b = true,
......@@ -2855,12 +2856,12 @@ test "fully anonymous struct" {
28552856 });
28562857}
28572858
2858fn dump(args: anytype) void {
2859 expect(args.int == 1234);
2860 expect(args.float == 12.34);
2861 expect(args.b);
2862 expect(args.s[0] == 'h');
2863 expect(args.s[1] == 'i');
2859fn dump(args: anytype) !void {
2860 try expect(args.int == 1234);
2861 try expect(args.float == 12.34);
2862 try expect(args.b);
2863 try expect(args.s[0] == 'h');
2864 try expect(args.s[1] == 'i');
28642865}
28652866 {#code_end#}
28662867 <p>
......@@ -2884,14 +2885,14 @@ test "tuple" {
28842885 true,
28852886 "hi",
28862887 } ++ .{false} ** 2;
2887 expect(values[0] == 1234);
2888 expect(values[4] == false);
2888 try expect(values[0] == 1234);
2889 try expect(values[4] == false);
28892890 inline for (values) |v, i| {
28902891 if (i != 2) continue;
2891 expect(v);
2892 try expect(v);
28922893 }
2893 expect(values.len == 6);
2894 expect(values.@"3"[0] == 'h');
2894 try expect(values.len == 6);
2895 try expect(values.@"3"[0] == 'h');
28952896}
28962897 {#code_end#}
28972898 {#header_close#}
......@@ -2922,9 +2923,9 @@ const Value = enum(u2) {
29222923// Now you can cast between u2 and Value.
29232924// The ordinal value starts from 0, counting up for each member.
29242925test "enum ordinal value" {
2925 expect(@enumToInt(Value.zero) == 0);
2926 expect(@enumToInt(Value.one) == 1);
2927 expect(@enumToInt(Value.two) == 2);
2926 try expect(@enumToInt(Value.zero) == 0);
2927 try expect(@enumToInt(Value.one) == 1);
2928 try expect(@enumToInt(Value.two) == 2);
29282929}
29292930
29302931// You can override the ordinal value for an enum.
......@@ -2934,9 +2935,9 @@ const Value2 = enum(u32) {
29342935 million = 1000000,
29352936};
29362937test "set enum ordinal value" {
2937 expect(@enumToInt(Value2.hundred) == 100);
2938 expect(@enumToInt(Value2.thousand) == 1000);
2939 expect(@enumToInt(Value2.million) == 1000000);
2938 try expect(@enumToInt(Value2.hundred) == 100);
2939 try expect(@enumToInt(Value2.thousand) == 1000);
2940 try expect(@enumToInt(Value2.million) == 1000000);
29402941}
29412942
29422943// Enums can have methods, the same as structs and unions.
......@@ -2954,7 +2955,7 @@ const Suit = enum {
29542955};
29552956test "enum method" {
29562957 const p = Suit.spades;
2957 expect(!p.isClubs());
2958 try expect(!p.isClubs());
29582959}
29592960
29602961// An enum variant of different types can be switched upon.
......@@ -2970,7 +2971,7 @@ test "enum variant switch" {
29702971 Foo.number => "this is a number",
29712972 Foo.none => "this is a none",
29722973 };
2973 expect(mem.eql(u8, what_is_it, "this is a number"));
2974 try expect(mem.eql(u8, what_is_it, "this is a number"));
29742975}
29752976
29762977// @typeInfo can be used to access the integer tag type of an enum.
......@@ -2981,18 +2982,18 @@ const Small = enum {
29812982 four,
29822983};
29832984test "std.meta.Tag" {
2984 expect(@typeInfo(Small).Enum.tag_type == u2);
2985 try expect(@typeInfo(Small).Enum.tag_type == u2);
29852986}
29862987
29872988// @typeInfo tells us the field count and the fields names:
29882989test "@typeInfo" {
2989 expect(@typeInfo(Small).Enum.fields.len == 4);
2990 expect(mem.eql(u8, @typeInfo(Small).Enum.fields[1].name, "two"));
2990 try expect(@typeInfo(Small).Enum.fields.len == 4);
2991 try expect(mem.eql(u8, @typeInfo(Small).Enum.fields[1].name, "two"));
29912992}
29922993
29932994// @tagName gives a []const u8 representation of an enum value:
29942995test "@tagName" {
2995 expect(mem.eql(u8, @tagName(Small.three), "three"));
2996 try expect(mem.eql(u8, @tagName(Small.three), "three"));
29962997}
29972998 {#code_end#}
29982999 {#see_also|@typeInfo|@tagName|@sizeOf#}
......@@ -3031,7 +3032,7 @@ const Color = enum {
30313032test "enum literals" {
30323033 const color1: Color = .auto;
30333034 const color2 = Color.auto;
3034 expect(color1 == color2);
3035 try expect(color1 == color2);
30353036}
30363037
30373038test "switch using enum literals" {
......@@ -3041,7 +3042,7 @@ test "switch using enum literals" {
30413042 .on => true,
30423043 .off => false,
30433044 };
3044 expect(result);
3045 try expect(result);
30453046}
30463047 {#code_end#}
30473048 {#header_close#}
......@@ -3077,12 +3078,12 @@ test "switch on non-exhaustive enum" {
30773078 .three => false,
30783079 _ => false,
30793080 };
3080 expect(result);
3081 try expect(result);
30813082 const is_one = switch (number) {
30823083 .one => true,
30833084 else => false,
30843085 };
3085 expect(is_one);
3086 try expect(is_one);
30863087}
30873088 {#code_end#}
30883089 {#header_close#}
......@@ -3122,9 +3123,9 @@ const Payload = union {
31223123};
31233124test "simple union" {
31243125 var payload = Payload{ .int = 1234 };
3125 expect(payload.int == 1234);
3126 try expect(payload.int == 1234);
31263127 payload = Payload{ .float = 12.34 };
3127 expect(payload.float == 12.34);
3128 try expect(payload.float == 12.34);
31283129}
31293130 {#code_end#}
31303131 <p>
......@@ -3155,24 +3156,24 @@ const ComplexType = union(ComplexTypeTag) {
31553156
31563157test "switch on tagged union" {
31573158 const c = ComplexType{ .ok = 42 };
3158 expect(@as(ComplexTypeTag, c) == ComplexTypeTag.ok);
3159 try expect(@as(ComplexTypeTag, c) == ComplexTypeTag.ok);
31593160
31603161 switch (c) {
3161 ComplexTypeTag.ok => |value| expect(value == 42),
3162 ComplexTypeTag.ok => |value| try expect(value == 42),
31623163 ComplexTypeTag.not_ok => unreachable,
31633164 }
31643165}
31653166
31663167test "get tag type" {
3167 expect(std.meta.Tag(ComplexType) == ComplexTypeTag);
3168 try expect(std.meta.Tag(ComplexType) == ComplexTypeTag);
31683169}
31693170
31703171test "coerce to enum" {
31713172 const c1 = ComplexType{ .ok = 42 };
31723173 const c2 = ComplexType.not_ok;
31733174
3174 expect(c1 == .ok);
3175 expect(c2 == .not_ok);
3175 try expect(c1 == .ok);
3176 try expect(c2 == .not_ok);
31763177}
31773178 {#code_end#}
31783179 <p>In order to modify the payload of a tagged union in a switch expression,
......@@ -3193,14 +3194,14 @@ const ComplexType = union(ComplexTypeTag) {
31933194
31943195test "modify tagged union in switch" {
31953196 var c = ComplexType{ .ok = 42 };
3196 expect(@as(ComplexTypeTag, c) == ComplexTypeTag.ok);
3197 try expect(@as(ComplexTypeTag, c) == ComplexTypeTag.ok);
31973198
31983199 switch (c) {
31993200 ComplexTypeTag.ok => |*value| value.* += 1,
32003201 ComplexTypeTag.not_ok => unreachable,
32013202 }
32023203
3203 expect(c.ok == 43);
3204 try expect(c.ok == 43);
32043205}
32053206 {#code_end#}
32063207 <p>
......@@ -3231,8 +3232,8 @@ test "union method" {
32313232 var v1 = Variant{ .int = 1 };
32323233 var v2 = Variant{ .boolean = false };
32333234
3234 expect(v1.truthy());
3235 expect(!v2.truthy());
3235 try expect(v1.truthy());
3236 try expect(!v2.truthy());
32363237}
32373238 {#code_end#}
32383239 <p>
......@@ -3249,7 +3250,7 @@ const Small2 = union(enum) {
32493250 c: u8,
32503251};
32513252test "@tagName" {
3252 expect(std.mem.eql(u8, @tagName(Small2.a), "a"));
3253 try expect(std.mem.eql(u8, @tagName(Small2.a), "a"));
32533254}
32543255 {#code_end#}
32553256 {#header_close#}
......@@ -3282,8 +3283,8 @@ const Number = union {
32823283test "anonymous union literal syntax" {
32833284 var i: Number = .{.int = 42};
32843285 var f = makeNumber();
3285 expect(i.int == 42);
3286 expect(f.float == 12.34);
3286 try expect(i.int == 42);
3287 try expect(f.float == 12.34);
32873288}
32883289
32893290fn makeNumber() Number {
......@@ -3345,8 +3346,8 @@ test "labeled break from labeled block expression" {
33453346 y += 1;
33463347 break :blk y;
33473348 };
3348 expect(x == 124);
3349 expect(y == 124);
3349 try expect(x == 124);
3350 try expect(y == 124);
33503351}
33513352 {#code_end#}
33523353 <p>Here, {#syntax#}blk{#endsyntax#} can be any name.</p>
......@@ -3424,7 +3425,7 @@ test "switch simple" {
34243425 else => 9,
34253426 };
34263427
3427 expect(b == 1);
3428 try expect(b == 1);
34283429}
34293430
34303431// Switch expressions can be used outside a function:
......@@ -3487,8 +3488,8 @@ test "switch on tagged union" {
34873488 Item.d => 8,
34883489 };
34893490
3490 expect(b == 6);
3491 expect(a.c.x == 2);
3491 try expect(b == 6);
3492 try expect(a.c.x == 2);
34923493}
34933494 {#code_end#}
34943495 {#see_also|comptime|enum|@compileError|Compile Variables#}
......@@ -3537,7 +3538,7 @@ test "enum literals with switch" {
35373538 .on => false,
35383539 .off => true,
35393540 };
3540 expect(result);
3541 try expect(result);
35413542}
35423543 {#code_end#}
35433544 {#header_close#}
......@@ -3556,7 +3557,7 @@ test "while basic" {
35563557 while (i < 10) {
35573558 i += 1;
35583559 }
3559 expect(i == 10);
3560 try expect(i == 10);
35603561}
35613562 {#code_end#}
35623563 <p>
......@@ -3572,7 +3573,7 @@ test "while break" {
35723573 break;
35733574 i += 1;
35743575 }
3575 expect(i == 10);
3576 try expect(i == 10);
35763577}
35773578 {#code_end#}
35783579 <p>
......@@ -3589,7 +3590,7 @@ test "while continue" {
35893590 continue;
35903591 break;
35913592 }
3592 expect(i == 10);
3593 try expect(i == 10);
35933594}
35943595 {#code_end#}
35953596 <p>
......@@ -3602,7 +3603,7 @@ const expect = @import("std").testing.expect;
36023603test "while loop continue expression" {
36033604 var i: usize = 0;
36043605 while (i < 10) : (i += 1) {}
3605 expect(i == 10);
3606 try expect(i == 10);
36063607}
36073608
36083609test "while loop continue expression, more complicated" {
......@@ -3610,7 +3611,7 @@ test "while loop continue expression, more complicated" {
36103611 var j: usize = 1;
36113612 while (i * j < 2000) : ({ i *= 2; j *= 3; }) {
36123613 const my_ij = i * j;
3613 expect(my_ij < 2000);
3614 try expect(my_ij < 2000);
36143615 }
36153616}
36163617 {#code_end#}
......@@ -3629,8 +3630,8 @@ test "while loop continue expression, more complicated" {
36293630const expect = @import("std").testing.expect;
36303631
36313632test "while else" {
3632 expect(rangeHasNumber(0, 10, 5));
3633 expect(!rangeHasNumber(0, 10, 15));
3633 try expect(rangeHasNumber(0, 10, 5));
3634 try expect(!rangeHasNumber(0, 10, 15));
36343635}
36353636
36363637fn rangeHasNumber(begin: usize, end: usize, number: usize) bool {
......@@ -3687,14 +3688,14 @@ test "while null capture" {
36873688 while (eventuallyNullSequence()) |value| {
36883689 sum1 += value;
36893690 }
3690 expect(sum1 == 3);
3691 try expect(sum1 == 3);
36913692
36923693 var sum2: u32 = 0;
36933694 numbers_left = 3;
36943695 while (eventuallyNullSequence()) |value| {
36953696 sum2 += value;
36963697 } else {
3697 expect(sum2 == 3);
3698 try expect(sum2 == 3);
36983699 }
36993700}
37003701
......@@ -3729,7 +3730,7 @@ test "while error union capture" {
37293730 while (eventuallyErrorSequence()) |value| {
37303731 sum1 += value;
37313732 } else |err| {
3732 expect(err == error.ReachedZero);
3733 try expect(err == error.ReachedZero);
37333734 }
37343735}
37353736
......@@ -3765,7 +3766,7 @@ test "inline while loop" {
37653766 };
37663767 sum += typeNameLength(T);
37673768 }
3768 expect(sum == 9);
3769 try expect(sum == 9);
37693770}
37703771
37713772fn typeNameLength(comptime T: type) usize {
......@@ -3800,22 +3801,22 @@ test "for basics" {
38003801 }
38013802 sum += value;
38023803 }
3803 expect(sum == 16);
3804 try expect(sum == 16);
38043805
38053806 // To iterate over a portion of a slice, reslice.
38063807 for (items[0..1]) |value| {
38073808 sum += value;
38083809 }
3809 expect(sum == 20);
3810 try expect(sum == 20);
38103811
38113812 // To access the index of iteration, specify a second capture value.
38123813 // This is zero-indexed.
38133814 var sum2: i32 = 0;
38143815 for (items) |value, i| {
3815 expect(@TypeOf(i) == usize);
3816 try expect(@TypeOf(i) == usize);
38163817 sum2 += @intCast(i32, i);
38173818 }
3818 expect(sum2 == 10);
3819 try expect(sum2 == 10);
38193820}
38203821
38213822test "for reference" {
......@@ -3827,9 +3828,9 @@ test "for reference" {
38273828 value.* += 1;
38283829 }
38293830
3830 expect(items[0] == 4);
3831 expect(items[1] == 5);
3832 expect(items[2] == 3);
3831 try expect(items[0] == 4);
3832 try expect(items[1] == 5);
3833 try expect(items[2] == 3);
38333834}
38343835
38353836test "for else" {
......@@ -3844,10 +3845,10 @@ test "for else" {
38443845 sum += value.?;
38453846 }
38463847 } else blk: {
3847 expect(sum == 12);
3848 try expect(sum == 12);
38483849 break :blk sum;
38493850 };
3850 expect(result == 12);
3851 try expect(result == 12);
38513852}
38523853 {#code_end#}
38533854 {#header_open|Labeled for#}
......@@ -3865,7 +3866,7 @@ test "nested break" {
38653866 break :outer;
38663867 }
38673868 }
3868 expect(count == 1);
3869 try expect(count == 1);
38693870}
38703871
38713872test "nested continue" {
......@@ -3877,7 +3878,7 @@ test "nested continue" {
38773878 }
38783879 }
38793880
3880 expect(count == 8);
3881 try expect(count == 8);
38813882}
38823883 {#code_end#}
38833884 {#header_close#}
......@@ -3904,7 +3905,7 @@ test "inline for loop" {
39043905 };
39053906 sum += typeNameLength(T);
39063907 }
3907 expect(sum == 9);
3908 try expect(sum == 9);
39083909}
39093910
39103911fn typeNameLength(comptime T: type) usize {
......@@ -3937,7 +3938,7 @@ test "if expression" {
39373938 const a: u32 = 5;
39383939 const b: u32 = 4;
39393940 const result = if (a != b) 47 else 3089;
3940 expect(result == 47);
3941 try expect(result == 47);
39413942}
39423943
39433944test "if boolean" {
......@@ -3945,7 +3946,7 @@ test "if boolean" {
39453946 const a: u32 = 5;
39463947 const b: u32 = 4;
39473948 if (a != b) {
3948 expect(true);
3949 try expect(true);
39493950 } else if (a == 9) {
39503951 unreachable;
39513952 } else {
......@@ -3958,7 +3959,7 @@ test "if optional" {
39583959
39593960 const a: ?u32 = 0;
39603961 if (a) |value| {
3961 expect(value == 0);
3962 try expect(value == 0);
39623963 } else {
39633964 unreachable;
39643965 }
......@@ -3967,17 +3968,17 @@ test "if optional" {
39673968 if (b) |value| {
39683969 unreachable;
39693970 } else {
3970 expect(true);
3971 try expect(true);
39713972 }
39723973
39733974 // The else is not required.
39743975 if (a) |value| {
3975 expect(value == 0);
3976 try expect(value == 0);
39763977 }
39773978
39783979 // To test against null only, use the binary equality operator.
39793980 if (b == null) {
3980 expect(true);
3981 try expect(true);
39813982 }
39823983
39833984 // Access the value by reference using a pointer capture.
......@@ -3987,7 +3988,7 @@ test "if optional" {
39873988 }
39883989
39893990 if (c) |value| {
3990 expect(value == 2);
3991 try expect(value == 2);
39913992 } else {
39923993 unreachable;
39933994 }
......@@ -3999,7 +4000,7 @@ test "if error union" {
39994000
40004001 const a: anyerror!u32 = 0;
40014002 if (a) |value| {
4002 expect(value == 0);
4003 try expect(value == 0);
40034004 } else |err| {
40044005 unreachable;
40054006 }
......@@ -4008,17 +4009,17 @@ test "if error union" {
40084009 if (b) |value| {
40094010 unreachable;
40104011 } else |err| {
4011 expect(err == error.BadValue);
4012 try expect(err == error.BadValue);
40124013 }
40134014
40144015 // The else and |err| capture is strictly required.
40154016 if (a) |value| {
4016 expect(value == 0);
4017 try expect(value == 0);
40174018 } else |_| {}
40184019
40194020 // To check only the error value, use an empty block expression.
40204021 if (b) |_| {} else |err| {
4021 expect(err == error.BadValue);
4022 try expect(err == error.BadValue);
40224023 }
40234024
40244025 // Access the value by reference using a pointer capture.
......@@ -4030,7 +4031,7 @@ test "if error union" {
40304031 }
40314032
40324033 if (c) |value| {
4033 expect(value == 9);
4034 try expect(value == 9);
40344035 } else |err| {
40354036 unreachable;
40364037 }
......@@ -4042,14 +4043,14 @@ test "if error union with optional" {
40424043
40434044 const a: anyerror!?u32 = 0;
40444045 if (a) |optional_value| {
4045 expect(optional_value.? == 0);
4046 try expect(optional_value.? == 0);
40464047 } else |err| {
40474048 unreachable;
40484049 }
40494050
40504051 const b: anyerror!?u32 = null;
40514052 if (b) |optional_value| {
4052 expect(optional_value == null);
4053 try expect(optional_value == null);
40534054 } else |err| {
40544055 unreachable;
40554056 }
......@@ -4058,7 +4059,7 @@ test "if error union with optional" {
40584059 if (c) |optional_value| {
40594060 unreachable;
40604061 } else |err| {
4061 expect(err == error.BadValue);
4062 try expect(err == error.BadValue);
40624063 }
40634064
40644065 // Access the value by reference by using a pointer capture each time.
......@@ -4072,7 +4073,7 @@ test "if error union with optional" {
40724073 }
40734074
40744075 if (d) |optional_value| {
4075 expect(optional_value.? == 9);
4076 try expect(optional_value.? == 9);
40764077 } else |err| {
40774078 unreachable;
40784079 }
......@@ -4087,21 +4088,21 @@ const expect = std.testing.expect;
40874088const print = std.debug.print;
40884089
40894090// defer will execute an expression at the end of the current scope.
4090fn deferExample() usize {
4091fn deferExample() !usize {
40914092 var a: usize = 1;
40924093
40934094 {
40944095 defer a = 2;
40954096 a = 1;
40964097 }
4097 expect(a == 2);
4098 try expect(a == 2);
40984099
40994100 a = 5;
41004101 return a;
41014102}
41024103
41034104test "defer basics" {
4104 expect(deferExample() == 5);
4105 try expect((try deferExample()) == 5);
41054106}
41064107
41074108// If multiple defer statements are specified, they will be executed in
......@@ -4239,7 +4240,7 @@ pub extern "kernel32" fn ExitProcess(exit_code: c_uint) callconv(if (@import("bu
42394240
42404241test "foo" {
42414242 const value = bar() catch ExitProcess(1);
4242 expect(value == 1234);
4243 try expect(value == 1234);
42434244}
42444245
42454246fn bar() anyerror!u32 {
......@@ -4302,17 +4303,17 @@ fn do_op(fn_call: call2_op, op1: i8, op2: i8) i8 {
43024303}
43034304
43044305test "function" {
4305 expect(do_op(add, 5, 6) == 11);
4306 expect(do_op(sub2, 5, 6) == -1);
4306 try expect(do_op(add, 5, 6) == 11);
4307 try expect(do_op(sub2, 5, 6) == -1);
43074308}
43084309 {#code_end#}
43094310 <p>Function values are like pointers:</p>
43104311 {#code_begin|obj#}
4311const expect = @import("std").testing.expect;
4312const assert = @import("std").debug.assert;
43124313
43134314comptime {
4314 expect(@TypeOf(foo) == fn()void);
4315 expect(@sizeOf(fn()void) == @sizeOf(?fn()void));
4315 assert(@TypeOf(foo) == fn()void);
4316 assert(@sizeOf(fn()void) == @sizeOf(?fn()void));
43164317}
43174318
43184319fn foo() void { }
......@@ -4347,7 +4348,7 @@ fn foo(point: Point) i32 {
43474348const expect = @import("std").testing.expect;
43484349
43494350test "pass struct to function" {
4350 expect(foo(Point{ .x = 1, .y = 2 }) == 3);
4351 try expect(foo(Point{ .x = 1, .y = 2 }) == 3);
43514352}
43524353 {#code_end#}
43534354 <p>
......@@ -4368,11 +4369,11 @@ fn addFortyTwo(x: anytype) @TypeOf(x) {
43684369}
43694370
43704371test "fn type inference" {
4371 expect(addFortyTwo(1) == 43);
4372 expect(@TypeOf(addFortyTwo(1)) == comptime_int);
4372 try expect(addFortyTwo(1) == 43);
4373 try expect(@TypeOf(addFortyTwo(1)) == comptime_int);
43734374 var y: i64 = 2;
4374 expect(addFortyTwo(y) == 44);
4375 expect(@TypeOf(addFortyTwo(y)) == i64);
4375 try expect(addFortyTwo(y) == 44);
4376 try expect(@TypeOf(addFortyTwo(y)) == i64);
43764377}
43774378 {#code_end#}
43784379
......@@ -4382,8 +4383,8 @@ test "fn type inference" {
43824383const expect = @import("std").testing.expect;
43834384
43844385test "fn reflection" {
4385 expect(@typeInfo(@TypeOf(expect)).Fn.return_type.? == void);
4386 expect(@typeInfo(@TypeOf(expect)).Fn.is_var_args == false);
4386 try expect(@typeInfo(@TypeOf(expect)).Fn.args[0].arg_type.? == bool);
4387 try expect(@typeInfo(@TypeOf(expect)).Fn.is_var_args == false);
43874388}
43884389 {#code_end#}
43894390 {#header_close#}
......@@ -4418,7 +4419,7 @@ const AllocationError = error {
44184419
44194420test "coerce subset to superset" {
44204421 const err = foo(AllocationError.OutOfMemory);
4421 std.testing.expect(err == FileOpenError.OutOfMemory);
4422 try std.testing.expect(err == FileOpenError.OutOfMemory);
44224423}
44234424
44244425fn foo(err: AllocationError) FileOpenError {
......@@ -4526,7 +4527,7 @@ fn charToDigit(c: u8) u8 {
45264527
45274528test "parse u64" {
45284529 const result = try parseU64("1234", 10);
4529 std.testing.expect(result == 1234);
4530 try std.testing.expect(result == 1234);
45304531}
45314532 {#code_end#}
45324533 <p>
......@@ -4683,10 +4684,10 @@ test "error union" {
46834684 foo = error.SomeError;
46844685
46854686 // Use compile-time reflection to access the payload type of an error union:
4686 comptime expect(@typeInfo(@TypeOf(foo)).ErrorUnion.payload == i32);
4687 comptime try expect(@typeInfo(@TypeOf(foo)).ErrorUnion.payload == i32);
46874688
46884689 // Use compile-time reflection to access the error set type of an error union:
4689 comptime expect(@typeInfo(@TypeOf(foo)).ErrorUnion.error_set == anyerror);
4690 comptime try expect(@typeInfo(@TypeOf(foo)).ErrorUnion.error_set == anyerror);
46904691}
46914692 {#code_end#}
46924693 {#header_open|Merging Error Sets#}
......@@ -5063,7 +5064,7 @@ test "optional type" {
50635064 foo = 1234;
50645065
50655066 // Use compile-time reflection to access the child type of the optional:
5066 comptime expect(@typeInfo(@TypeOf(foo)).Optional.child == i32);
5067 comptime try expect(@typeInfo(@TypeOf(foo)).Optional.child == i32);
50675068}
50685069 {#code_end#}
50695070 {#header_close#}
......@@ -5090,11 +5091,11 @@ test "optional pointers" {
50905091 var x: i32 = 1;
50915092 ptr = &x;
50925093
5093 expect(ptr.?.* == 1);
5094 try expect(ptr.?.* == 1);
50945095
50955096 // Optional pointers are the same size as normal pointers, because pointer
50965097 // value 0 is used as the null value.
5097 expect(@sizeOf(?*i32) == @sizeOf(*i32));
5098 try expect(@sizeOf(?*i32) == @sizeOf(*i32));
50985099}
50995100 {#code_end#}
51005101 {#header_close#}
......@@ -5167,7 +5168,7 @@ const mem = std.mem;
51675168test "cast *[1][*]const u8 to [*]const ?[*]const u8" {
51685169 const window_name = [1][*]const u8{"window name"};
51695170 const x: [*]const ?[*]const u8 = &window_name;
5170 expect(mem.eql(u8, std.mem.spanZ(@ptrCast([*:0]const u8, x[0].?)), "window name"));
5171 try expect(mem.eql(u8, std.mem.spanZ(@ptrCast([*:0]const u8, x[0].?)), "window name"));
51715172}
51725173 {#code_end#}
51735174 {#header_close#}
......@@ -5188,13 +5189,13 @@ test "integer widening" {
51885189 var d: u64 = c;
51895190 var e: u64 = d;
51905191 var f: u128 = e;
5191 expect(f == a);
5192 try expect(f == a);
51925193}
51935194
51945195test "implicit unsigned integer to signed integer" {
51955196 var a: u8 = 250;
51965197 var b: i16 = a;
5197 expect(b == 250);
5198 try expect(b == 250);
51985199}
51995200
52005201test "float widening" {
......@@ -5206,7 +5207,7 @@ test "float widening" {
52065207 var b: f32 = a;
52075208 var c: f64 = b;
52085209 var d: f128 = c;
5209 expect(d == a);
5210 try expect(d == a);
52105211}
52115212 {#code_end#}
52125213 {#header_close#}
......@@ -5238,48 +5239,48 @@ const expect = std.testing.expect;
52385239test "[N]T to []const T" {
52395240 var x1: []const u8 = "hello";
52405241 var x2: []const u8 = &[5]u8{ 'h', 'e', 'l', 'l', 111 };
5241 expect(std.mem.eql(u8, x1, x2));
5242 try expect(std.mem.eql(u8, x1, x2));
52425243
52435244 var y: []const f32 = &[2]f32{ 1.2, 3.4 };
5244 expect(y[0] == 1.2);
5245 try expect(y[0] == 1.2);
52455246}
52465247
52475248// Likewise, it works when the destination type is an error union.
52485249test "[N]T to E![]const T" {
52495250 var x1: anyerror![]const u8 = "hello";
52505251 var x2: anyerror![]const u8 = &[5]u8{ 'h', 'e', 'l', 'l', 111 };
5251 expect(std.mem.eql(u8, try x1, try x2));
5252 try expect(std.mem.eql(u8, try x1, try x2));
52525253
52535254 var y: anyerror![]const f32 = &[2]f32{ 1.2, 3.4 };
5254 expect((try y)[0] == 1.2);
5255 try expect((try y)[0] == 1.2);
52555256}
52565257
52575258// Likewise, it works when the destination type is an optional.
52585259test "[N]T to ?[]const T" {
52595260 var x1: ?[]const u8 = "hello";
52605261 var x2: ?[]const u8 = &[5]u8{ 'h', 'e', 'l', 'l', 111 };
5261 expect(std.mem.eql(u8, x1.?, x2.?));
5262 try expect(std.mem.eql(u8, x1.?, x2.?));
52625263
52635264 var y: ?[]const f32 = &[2]f32{ 1.2, 3.4 };
5264 expect(y.?[0] == 1.2);
5265 try expect(y.?[0] == 1.2);
52655266}
52665267
52675268// In this cast, the array length becomes the slice length.
52685269test "*[N]T to []T" {
52695270 var buf: [5]u8 = "hello".*;
52705271 const x: []u8 = &buf;
5271 expect(std.mem.eql(u8, x, "hello"));
5272 try expect(std.mem.eql(u8, x, "hello"));
52725273
52735274 const buf2 = [2]f32{ 1.2, 3.4 };
52745275 const x2: []const f32 = &buf2;
5275 expect(std.mem.eql(f32, x2, &[2]f32{ 1.2, 3.4 }));
5276 try expect(std.mem.eql(f32, x2, &[2]f32{ 1.2, 3.4 }));
52765277}
52775278
52785279// Single-item pointers to arrays can be coerced to many-item pointers.
52795280test "*[N]T to [*]T" {
52805281 var buf: [5]u8 = "hello".*;
52815282 const x: [*]u8 = &buf;
5282 expect(x[4] == 'o');
5283 try expect(x[4] == 'o');
52835284 // x[5] would be an uncaught out of bounds pointer dereference!
52845285}
52855286
......@@ -5287,7 +5288,7 @@ test "*[N]T to [*]T" {
52875288test "*[N]T to ?[*]T" {
52885289 var buf: [5]u8 = "hello".*;
52895290 const x: ?[*]u8 = &buf;
5290 expect(x.?[4] == 'o');
5291 try expect(x.?[4] == 'o');
52915292}
52925293
52935294// Single-item pointers can be cast to len-1 single-item arrays.
......@@ -5295,7 +5296,7 @@ test "*T to *[1]T" {
52955296 var x: i32 = 1234;
52965297 const y: *[1]i32 = &x;
52975298 const z: [*]i32 = y;
5298 expect(z[0] == 1234);
5299 try expect(z[0] == 1234);
52995300}
53005301 {#code_end#}
53015302 {#see_also|C Pointers#}
......@@ -5312,8 +5313,8 @@ test "coerce to optionals" {
53125313 const x: ?i32 = 1234;
53135314 const y: ?i32 = null;
53145315
5315 expect(x.? == 1234);
5316 expect(y == null);
5316 try expect(x.? == 1234);
5317 try expect(y == null);
53175318}
53185319 {#code_end#}
53195320 <p>It works nested inside the {#link|Error Union Type#}, too:</p>
......@@ -5325,8 +5326,8 @@ test "coerce to optionals wrapped in error union" {
53255326 const x: anyerror!?i32 = 1234;
53265327 const y: anyerror!?i32 = null;
53275328
5328 expect((try x).? == 1234);
5329 expect((try y) == null);
5329 try expect((try x).? == 1234);
5330 try expect((try y) == null);
53305331}
53315332 {#code_end#}
53325333 {#header_close#}
......@@ -5342,8 +5343,8 @@ test "coercion to error unions" {
53425343 const x: anyerror!i32 = 1234;
53435344 const y: anyerror!i32 = error.Failure;
53445345
5345 expect((try x) == 1234);
5346 std.testing.expectError(error.Failure, y);
5346 try expect((try x) == 1234);
5347 try std.testing.expectError(error.Failure, y);
53475348}
53485349 {#code_end#}
53495350 {#header_close#}
......@@ -5358,7 +5359,7 @@ const expect = std.testing.expect;
53585359test "coercing large integer type to smaller one when value is comptime known to fit" {
53595360 const x: u64 = 255;
53605361 const y: u8 = x;
5361 expect(y == 255);
5362 try expect(y == 255);
53625363}
53635364 {#code_end#}
53645365 {#header_close#}
......@@ -5386,11 +5387,11 @@ const U = union(E) {
53865387test "coercion between unions and enums" {
53875388 var u = U{ .two = 12.34 };
53885389 var e: E = u;
5389 expect(e == E.two);
5390 try expect(e == E.two);
53905391
53915392 const three = E.three;
53925393 var another_u: U = three;
5393 expect(another_u == E.three);
5394 try expect(another_u == E.three);
53945395}
53955396 {#code_end#}
53965397 {#see_also|union|enum#}
......@@ -5463,37 +5464,37 @@ test "peer resolve int widening" {
54635464 var a: i8 = 12;
54645465 var b: i16 = 34;
54655466 var c = a + b;
5466 expect(c == 46);
5467 expect(@TypeOf(c) == i16);
5467 try expect(c == 46);
5468 try expect(@TypeOf(c) == i16);
54685469}
54695470
54705471test "peer resolve arrays of different size to const slice" {
5471 expect(mem.eql(u8, boolToStr(true), "true"));
5472 expect(mem.eql(u8, boolToStr(false), "false"));
5473 comptime expect(mem.eql(u8, boolToStr(true), "true"));
5474 comptime expect(mem.eql(u8, boolToStr(false), "false"));
5472 try expect(mem.eql(u8, boolToStr(true), "true"));
5473 try expect(mem.eql(u8, boolToStr(false), "false"));
5474 comptime try expect(mem.eql(u8, boolToStr(true), "true"));
5475 comptime try expect(mem.eql(u8, boolToStr(false), "false"));
54755476}
54765477fn boolToStr(b: bool) []const u8 {
54775478 return if (b) "true" else "false";
54785479}
54795480
54805481test "peer resolve array and const slice" {
5481 testPeerResolveArrayConstSlice(true);
5482 comptime testPeerResolveArrayConstSlice(true);
5482 try testPeerResolveArrayConstSlice(true);
5483 comptime try testPeerResolveArrayConstSlice(true);
54835484}
5484fn testPeerResolveArrayConstSlice(b: bool) void {
5485fn testPeerResolveArrayConstSlice(b: bool) !void {
54855486 const value1 = if (b) "aoeu" else @as([]const u8, "zz");
54865487 const value2 = if (b) @as([]const u8, "zz") else "aoeu";
5487 expect(mem.eql(u8, value1, "aoeu"));
5488 expect(mem.eql(u8, value2, "zz"));
5488 try expect(mem.eql(u8, value1, "aoeu"));
5489 try expect(mem.eql(u8, value2, "zz"));
54895490}
54905491
54915492test "peer type resolution: ?T and T" {
5492 expect(peerTypeTAndOptionalT(true, false).? == 0);
5493 expect(peerTypeTAndOptionalT(false, false).? == 3);
5493 try expect(peerTypeTAndOptionalT(true, false).? == 0);
5494 try expect(peerTypeTAndOptionalT(false, false).? == 3);
54945495 comptime {
5495 expect(peerTypeTAndOptionalT(true, false).? == 0);
5496 expect(peerTypeTAndOptionalT(false, false).? == 3);
5496 try expect(peerTypeTAndOptionalT(true, false).? == 0);
5497 try expect(peerTypeTAndOptionalT(false, false).? == 3);
54975498 }
54985499}
54995500fn peerTypeTAndOptionalT(c: bool, b: bool) ?usize {
......@@ -5505,11 +5506,11 @@ fn peerTypeTAndOptionalT(c: bool, b: bool) ?usize {
55055506}
55065507
55075508test "peer type resolution: *[0]u8 and []const u8" {
5508 expect(peerTypeEmptyArrayAndSlice(true, "hi").len == 0);
5509 expect(peerTypeEmptyArrayAndSlice(false, "hi").len == 1);
5509 try expect(peerTypeEmptyArrayAndSlice(true, "hi").len == 0);
5510 try expect(peerTypeEmptyArrayAndSlice(false, "hi").len == 1);
55105511 comptime {
5511 expect(peerTypeEmptyArrayAndSlice(true, "hi").len == 0);
5512 expect(peerTypeEmptyArrayAndSlice(false, "hi").len == 1);
5512 try expect(peerTypeEmptyArrayAndSlice(true, "hi").len == 0);
5513 try expect(peerTypeEmptyArrayAndSlice(false, "hi").len == 1);
55135514 }
55145515}
55155516fn peerTypeEmptyArrayAndSlice(a: bool, slice: []const u8) []const u8 {
......@@ -5523,14 +5524,14 @@ test "peer type resolution: *[0]u8, []const u8, and anyerror![]u8" {
55235524 {
55245525 var data = "hi".*;
55255526 const slice = data[0..];
5526 expect((try peerTypeEmptyArrayAndSliceAndError(true, slice)).len == 0);
5527 expect((try peerTypeEmptyArrayAndSliceAndError(false, slice)).len == 1);
5527 try expect((try peerTypeEmptyArrayAndSliceAndError(true, slice)).len == 0);
5528 try expect((try peerTypeEmptyArrayAndSliceAndError(false, slice)).len == 1);
55285529 }
55295530 comptime {
55305531 var data = "hi".*;
55315532 const slice = data[0..];
5532 expect((try peerTypeEmptyArrayAndSliceAndError(true, slice)).len == 0);
5533 expect((try peerTypeEmptyArrayAndSliceAndError(false, slice)).len == 1);
5533 try expect((try peerTypeEmptyArrayAndSliceAndError(true, slice)).len == 0);
5534 try expect((try peerTypeEmptyArrayAndSliceAndError(false, slice)).len == 1);
55345535 }
55355536}
55365537fn peerTypeEmptyArrayAndSliceAndError(a: bool, slice: []u8) anyerror![]u8 {
......@@ -5544,8 +5545,8 @@ fn peerTypeEmptyArrayAndSliceAndError(a: bool, slice: []u8) anyerror![]u8 {
55445545test "peer type resolution: *const T and ?*T" {
55455546 const a = @intToPtr(*const usize, 0x123456780);
55465547 const b = @intToPtr(?*usize, 0x123456780);
5547 expect(a == b);
5548 expect(b == a);
5548 try expect(a == b);
5549 try expect(b == a);
55495550}
55505551 {#code_end#}
55515552 {#header_close#}
......@@ -5601,11 +5602,11 @@ test "turn HashMap into a set with void" {
56015602 try map.put(1, {});
56025603 try map.put(2, {});
56035604
5604 expect(map.contains(2));
5605 expect(!map.contains(3));
5605 try expect(map.contains(2));
5606 try expect(!map.contains(3));
56065607
56075608 _ = map.remove(2);
5608 expect(!map.contains(2));
5609 try expect(!map.contains(2));
56095610}
56105611 {#code_end#}
56115612 <p>Note that this is different from using a dummy value for the hash map value.
......@@ -5660,7 +5661,7 @@ test "pointer to empty struct" {
56605661 var b = Empty{};
56615662 var ptr_a = &a;
56625663 var ptr_b = &b;
5663 comptime expect(ptr_a == ptr_b);
5664 comptime try expect(ptr_a == ptr_b);
56645665}
56655666 {#code_end#}
56665667 <p>The type being pointed to can only ever be one value; therefore loads and stores are
......@@ -5695,7 +5696,7 @@ test "@intToPtr for pointer to zero bit type" {
56955696usingnamespace @import("std");
56965697
56975698test "using std namespace" {
5698 testing.expect(true);
5699 try testing.expect(true);
56995700}
57005701 {#code_end#}
57015702 <p>
......@@ -5807,7 +5808,7 @@ fn max(comptime T: type, a: T, b: T) T {
58075808 }
58085809}
58095810test "try to compare bools" {
5810 @import("std").testing.expect(max(bool, false, true) == true);
5811 try @import("std").testing.expect(max(bool, false, true) == true);
58115812}
58125813 {#code_end#}
58135814 <p>
......@@ -5875,9 +5876,9 @@ fn performFn(comptime prefix_char: u8, start_value: i32) i32 {
58755876}
58765877
58775878test "perform fn" {
5878 expect(performFn('t', 1) == 6);
5879 expect(performFn('o', 0) == 1);
5880 expect(performFn('w', 99) == 99);
5879 try expect(performFn('t', 1) == 6);
5880 try expect(performFn('o', 0) == 1);
5881 try expect(performFn('w', 99) == 99);
58815882}
58825883 {#code_end#}
58835884 <p>
......@@ -5969,11 +5970,11 @@ fn fibonacci(index: u32) u32 {
59695970
59705971test "fibonacci" {
59715972 // test fibonacci at run-time
5972 expect(fibonacci(7) == 13);
5973 try expect(fibonacci(7) == 13);
59735974
59745975 // test fibonacci at compile-time
59755976 comptime {
5976 expect(fibonacci(7) == 13);
5977 try expect(fibonacci(7) == 13);
59775978 }
59785979}
59795980 {#code_end#}
......@@ -5990,7 +5991,7 @@ fn fibonacci(index: u32) u32 {
59905991
59915992test "fibonacci" {
59925993 comptime {
5993 expect(fibonacci(7) == 13);
5994 try expect(fibonacci(7) == 13);
59945995 }
59955996}
59965997 {#code_end#}
......@@ -6013,7 +6014,7 @@ fn fibonacci(index: i32) i32 {
60136014
60146015test "fibonacci" {
60156016 comptime {
6016 expect(fibonacci(7) == 13);
6017 try expect(fibonacci(7) == 13);
60176018 }
60186019}
60196020 {#code_end#}
......@@ -6026,7 +6027,7 @@ test "fibonacci" {
60266027 <p>
60276028 What if we fix the base case, but put the wrong value in the {#syntax#}expect{#endsyntax#} line?
60286029 </p>
6029 {#code_begin|test_err|encountered @panic at compile-time#}
6030 {#code_begin|test_err|test "fibonacci"... FAIL (TestUnexpectedResult)#}
60306031const expect = @import("std").testing.expect;
60316032
60326033fn fibonacci(index: i32) i32 {
......@@ -6036,7 +6037,7 @@ fn fibonacci(index: i32) i32 {
60366037
60376038test "fibonacci" {
60386039 comptime {
6039 expect(fibonacci(7) == 99999);
6040 try expect(fibonacci(7) == 99999);
60406041 }
60416042}
60426043 {#code_end#}
......@@ -6086,7 +6087,7 @@ fn sum(numbers: []const i32) i32 {
60866087}
60876088
60886089test "variable values" {
6089 @import("std").testing.expect(sum_of_first_25_primes == 1060);
6090 try @import("std").testing.expect(sum_of_first_25_primes == 1060);
60906091}
60916092 {#code_end#}
60926093 <p>
......@@ -6494,7 +6495,7 @@ comptime {
64946495extern fn my_func(a: i32, b: i32) i32;
64956496
64966497test "global assembly" {
6497 expect(my_func(12, 34) == 46);
6498 try expect(my_func(12, 34) == 46);
64986499}
64996500 {#code_end#}
65006501 {#header_close#}
......@@ -6535,7 +6536,7 @@ var x: i32 = 1;
65356536
65366537test "suspend with no resume" {
65376538 var frame = async func();
6538 expect(x == 2);
6539 try expect(x == 2);
65396540}
65406541
65416542fn func() void {
......@@ -6562,14 +6563,14 @@ var result = false;
65626563
65636564test "async function suspend with block" {
65646565 _ = async testSuspendBlock();
6565 expect(!result);
6566 try expect(!result);
65666567 resume the_frame;
6567 expect(result);
6568 try expect(result);
65686569}
65696570
65706571fn testSuspendBlock() void {
65716572 suspend {
6572 comptime expect(@TypeOf(@frame()) == *@Frame(testSuspendBlock));
6573 comptime try expect(@TypeOf(@frame()) == *@Frame(testSuspendBlock));
65736574 the_frame = @frame();
65746575 }
65756576 result = true;
......@@ -6598,7 +6599,7 @@ const expect = std.testing.expect;
65986599test "resume from suspend" {
65996600 var my_result: i32 = 1;
66006601 _ = async testResumeFromSuspend(&my_result);
6601 std.testing.expect(my_result == 2);
6602 try std.testing.expect(my_result == 2);
66026603}
66036604fn testResumeFromSuspend(my_result: *i32) void {
66046605 suspend {
......@@ -6634,7 +6635,7 @@ test "async and await" {
66346635
66356636fn amain() void {
66366637 var frame = async func();
6637 comptime expect(@TypeOf(frame) == @Frame(func));
6638 comptime try expect(@TypeOf(frame) == @Frame(func));
66386639
66396640 const ptr: anyframe->void = &frame;
66406641 const any_ptr: anyframe = ptr;
......@@ -6675,8 +6676,8 @@ test "async function await" {
66756676 seq('f');
66766677 resume the_frame;
66776678 seq('i');
6678 expect(final_result == 1234);
6679 expect(std.mem.eql(u8, &seq_points, "abcdefghi"));
6679 try expect(final_result == 1234);
6680 try expect(std.mem.eql(u8, &seq_points, "abcdefghi"));
66806681}
66816682fn amain() void {
66826683 seq('b');
......@@ -6890,9 +6891,9 @@ fn readFile(allocator: *Allocator, filename: []const u8) ![]u8 {
68906891 for the current target to match the C ABI. When the child type of a pointer has
68916892 this alignment, the alignment can be omitted from the type.
68926893 </p>
6893 <pre>{#syntax#}const expect = @import("std").testing.expect;
6894 <pre>{#syntax#}const expect = @import("std").debug.assert;
68946895comptime {
6895 expect(*u32 == *align(@alignOf(u32)) u32);
6896 assert(*u32 == *align(@alignOf(u32)) u32);
68966897}{#endsyntax#}</pre>
68976898 <p>
68986899 The result is a target-specific compile time constant. It is guaranteed to be
......@@ -6938,9 +6939,9 @@ test "async fn pointer in a struct field" {
69386939 var foo = Foo{ .bar = func };
69396940 var bytes: [64]u8 align(@alignOf(@Frame(func))) = undefined;
69406941 const f = @asyncCall(&bytes, {}, foo.bar, .{&data});
6941 expect(data == 2);
6942 try expect(data == 2);
69426943 resume f;
6943 expect(data == 4);
6944 try expect(data == 4);
69446945}
69456946
69466947fn func(y: *i32) void {
......@@ -7127,7 +7128,7 @@ fn func(y: *i32) void {
71277128const expect = @import("std").testing.expect;
71287129
71297130test "noinline function call" {
7130 expect(@call(.{}, add, .{3, 9}) == 12);
7131 try expect(@call(.{}, add, .{3, 9}) == 12);
71317132}
71327133
71337134fn add(a: i32, b: i32) i32 {
......@@ -7602,17 +7603,17 @@ test "field access by string" {
76027603 @field(p, "x") = 4;
76037604 @field(p, "y") = @field(p, "x") + 1;
76047605
7605 expect(@field(p, "x") == 4);
7606 expect(@field(p, "y") == 5);
7606 try expect(@field(p, "x") == 4);
7607 try expect(@field(p, "y") == 5);
76077608}
76087609
76097610test "decl access by string" {
76107611 const expect = std.testing.expect;
76117612
7612 expect(@field(Point, "z") == 1);
7613 try expect(@field(Point, "z") == 1);
76137614
76147615 @field(Point, "z") = 2;
7615 expect(@field(Point, "z") == 2);
7616 try expect(@field(Point, "z") == 2);
76167617}
76177618 {#code_end#}
76187619
......@@ -7728,16 +7729,16 @@ const Foo = struct {
77287729};
77297730
77307731test "@hasDecl" {
7731 expect(@hasDecl(Foo, "blah"));
7732 try expect(@hasDecl(Foo, "blah"));
77327733
77337734 // Even though `hi` is private, @hasDecl returns true because this test is
77347735 // in the same file scope as Foo. It would return false if Foo was declared
77357736 // in a different file.
7736 expect(@hasDecl(Foo, "hi"));
7737 try expect(@hasDecl(Foo, "hi"));
77377738
77387739 // @hasDecl is for declarations; not fields.
7739 expect(!@hasDecl(Foo, "nope"));
7740 expect(!@hasDecl(Foo, "nope1234"));
7740 try expect(!@hasDecl(Foo, "nope"));
7741 try expect(!@hasDecl(Foo, "nope1234"));
77417742}
77427743 {#code_end#}
77437744 {#see_also|@hasField#}
......@@ -7918,8 +7919,8 @@ test "@wasmMemoryGrow" {
79187919 if (builtin.arch != .wasm32) return error.SkipZigTest;
79197920
79207921 var prev = @wasmMemorySize(0);
7921 expect(prev == @wasmMemoryGrow(0, 1));
7922 expect(prev + 1 == @wasmMemorySize(0));
7922 try expect(prev == @wasmMemoryGrow(0, 1));
7923 try expect(prev + 1 == @wasmMemorySize(0));
79237924}
79247925 {#code_end#}
79257926 {#see_also|@wasmMemorySize#}
......@@ -8260,8 +8261,8 @@ const expect = std.testing.expect;
82608261test "vector @splat" {
82618262 const scalar: u32 = 5;
82628263 const result = @splat(4, scalar);
8263 comptime expect(@TypeOf(result) == std.meta.Vector(4, u32));
8264 expect(std.mem.eql(u32, &@as([4]u32, result), &[_]u32{ 5, 5, 5, 5 }));
8264 comptime try expect(@TypeOf(result) == std.meta.Vector(4, u32));
8265 try expect(std.mem.eql(u32, &@as([4]u32, result), &[_]u32{ 5, 5, 5, 5 }));
82658266}
82668267 {#code_end#}
82678268 <p>
......@@ -8303,10 +8304,10 @@ test "vector @reduce" {
83038304 const value: std.meta.Vector(4, i32) = [_]i32{ 1, -1, 1, -1 };
83048305 const result = value > @splat(4, @as(i32, 0));
83058306 // result is { true, false, true, false };
8306 comptime expect(@TypeOf(result) == std.meta.Vector(4, bool));
8307 comptime try expect(@TypeOf(result) == std.meta.Vector(4, bool));
83078308 const is_all_true = @reduce(.And, result);
8308 comptime expect(@TypeOf(is_all_true) == bool);
8309 expect(is_all_true == false);
8309 comptime try expect(@TypeOf(is_all_true) == bool);
8310 try expect(is_all_true == false);
83108311}
83118312 {#code_end#}
83128313 {#see_also|Vectors|@setFloatMode#}
......@@ -8322,16 +8323,16 @@ const std = @import("std");
83228323const expect = std.testing.expect;
83238324
83248325test "@src" {
8325 doTheTest();
8326 try doTheTest();
83268327}
83278328
8328fn doTheTest() void {
8329fn doTheTest() !void {
83298330 const src = @src();
83308331
8331 expect(src.line == 9);
8332 expect(src.column == 17);
8333 expect(std.mem.endsWith(u8, src.fn_name, "doTheTest"));
8334 expect(std.mem.endsWith(u8, src.file, "test.zig"));
8332 try expect(src.line == 9);
8333 try expect(src.column == 17);
8334 try expect(std.mem.endsWith(u8, src.fn_name, "doTheTest"));
8335 try expect(std.mem.endsWith(u8, src.file, "test.zig"));
83358336}
83368337 {#code_end#}
83378338 {#header_close#}
......@@ -8508,7 +8509,7 @@ const expect = std.testing.expect;
85088509test "@This()" {
85098510 var items = [_]i32{ 1, 2, 3, 4 };
85108511 const list = List(i32){ .items = items[0..] };
8511 expect(list.length() == 4);
8512 try expect(list.length() == 4);
85128513}
85138514
85148515fn List(comptime T: type) type {
......@@ -8554,7 +8555,7 @@ const expect = std.testing.expect;
85548555test "integer truncation" {
85558556 var a: u16 = 0xabcd;
85568557 var b: u8 = @truncate(u8, a);
8557 expect(b == 0xcd);
8558 try expect(b == 0xcd);
85588559}
85598560 {#code_end#}
85608561 <p>
......@@ -8642,8 +8643,8 @@ const expect = std.testing.expect;
86428643test "no runtime side effects" {
86438644 var data: i32 = 0;
86448645 const T = @TypeOf(foo(i32, &data));
8645 comptime expect(T == i32);
8646 expect(data == 0);
8646 comptime try expect(T == i32);
8647 try expect(data == 0);
86478648}
86488649
86498650fn foo(comptime T: type, ptr: *T) T {
......@@ -8953,9 +8954,9 @@ const maxInt = std.math.maxInt;
89538954test "wraparound addition and subtraction" {
89548955 const x: i32 = maxInt(i32);
89558956 const min_val = x +% 1;
8956 expect(min_val == minInt(i32));
8957 try expect(min_val == minInt(i32));
89578958 const max_val = min_val -% 1;
8958 expect(max_val == maxInt(i32));
8959 try expect(max_val == maxInt(i32));
89598960}
89608961 {#code_end#}
89618962 {#header_close#}
......@@ -9386,7 +9387,7 @@ test "using an allocator" {
93869387 var buffer: [100]u8 = undefined;
93879388 const allocator = &std.heap.FixedBufferAllocator.init(&buffer).allocator;
93889389 const result = try concat(allocator, "foo", "bar");
9389 expect(std.mem.eql(u8, "foobar", result));
9390 try expect(std.mem.eql(u8, "foobar", result));
93909391}
93919392
93929393fn concat(allocator: *Allocator, a: []const u8, b: []const u8) ![]u8 {
......@@ -9656,7 +9657,7 @@ const builtin = std.builtin;
96569657const expect = std.testing.expect;
96579658
96589659test "builtin.is_test" {
9659 expect(builtin.is_test);
9660 try expect(builtin.is_test);
96609661}
96619662 {#code_end#}
96629663 <p>
......@@ -9701,13 +9702,13 @@ test "assert in release fast mode" {
97019702 <p>
97029703 Better practice for checking the output when testing is to use {#syntax#}std.testing.expect{#endsyntax#}:
97039704 </p>
9704 {#code_begin|test_err|test failure#}
9705 {#code_begin|test_err|test "expect in release fast mode"... FAIL (TestUnexpectedResult)#}
97059706 {#code_release_fast#}
97069707const std = @import("std");
97079708const expect = std.testing.expect;
97089709
97099710test "expect in release fast mode" {
9710 expect(false);
9711 try expect(false);
97119712}
97129713 {#code_end#}
97139714 <p>See the rest of the {#syntax#}std.testing{#endsyntax#} namespace for more available functions.</p>
lib/std/SemanticVersion.zig+13-13
......@@ -249,13 +249,13 @@ test "SemanticVersion format" {
249249 "+justmeta",
250250 "9.8.7+meta+meta",
251251 "9.8.7-whatever+meta+meta",
252 }) |invalid| expectError(error.InvalidVersion, parse(invalid));
252 }) |invalid| try expectError(error.InvalidVersion, parse(invalid));
253253
254254 // Valid version string that may overflow.
255255 const big_valid = "99999999999999999999999.999999999999999999.99999999999999999";
256256 if (parse(big_valid)) |ver| {
257257 try std.testing.expectFmt(big_valid, "{}", .{ver});
258 } else |err| expect(err == error.Overflow);
258 } else |err| try expect(err == error.Overflow);
259259
260260 // Invalid version string that may overflow.
261261 const big_invalid = "99999999999999999999999.999999999999999999.99999999999999999----RC-SNAPSHOT.12.09.1--------------------------------..12";
......@@ -264,22 +264,22 @@ test "SemanticVersion format" {
264264
265265test "SemanticVersion precedence" {
266266 // SemVer 2 spec 11.2 example: 1.0.0 < 2.0.0 < 2.1.0 < 2.1.1.
267 expect(order(try parse("1.0.0"), try parse("2.0.0")) == .lt);
268 expect(order(try parse("2.0.0"), try parse("2.1.0")) == .lt);
269 expect(order(try parse("2.1.0"), try parse("2.1.1")) == .lt);
267 try expect(order(try parse("1.0.0"), try parse("2.0.0")) == .lt);
268 try expect(order(try parse("2.0.0"), try parse("2.1.0")) == .lt);
269 try expect(order(try parse("2.1.0"), try parse("2.1.1")) == .lt);
270270
271271 // SemVer 2 spec 11.3 example: 1.0.0-alpha < 1.0.0.
272 expect(order(try parse("1.0.0-alpha"), try parse("1.0.0")) == .lt);
272 try expect(order(try parse("1.0.0-alpha"), try parse("1.0.0")) == .lt);
273273
274274 // SemVer 2 spec 11.4 example: 1.0.0-alpha < 1.0.0-alpha.1 < 1.0.0-alpha.beta < 1.0.0-beta <
275275 // 1.0.0-beta.2 < 1.0.0-beta.11 < 1.0.0-rc.1 < 1.0.0.
276 expect(order(try parse("1.0.0-alpha"), try parse("1.0.0-alpha.1")) == .lt);
277 expect(order(try parse("1.0.0-alpha.1"), try parse("1.0.0-alpha.beta")) == .lt);
278 expect(order(try parse("1.0.0-alpha.beta"), try parse("1.0.0-beta")) == .lt);
279 expect(order(try parse("1.0.0-beta"), try parse("1.0.0-beta.2")) == .lt);
280 expect(order(try parse("1.0.0-beta.2"), try parse("1.0.0-beta.11")) == .lt);
281 expect(order(try parse("1.0.0-beta.11"), try parse("1.0.0-rc.1")) == .lt);
282 expect(order(try parse("1.0.0-rc.1"), try parse("1.0.0")) == .lt);
276 try expect(order(try parse("1.0.0-alpha"), try parse("1.0.0-alpha.1")) == .lt);
277 try expect(order(try parse("1.0.0-alpha.1"), try parse("1.0.0-alpha.beta")) == .lt);
278 try expect(order(try parse("1.0.0-alpha.beta"), try parse("1.0.0-beta")) == .lt);
279 try expect(order(try parse("1.0.0-beta"), try parse("1.0.0-beta.2")) == .lt);
280 try expect(order(try parse("1.0.0-beta.2"), try parse("1.0.0-beta.11")) == .lt);
281 try expect(order(try parse("1.0.0-beta.11"), try parse("1.0.0-rc.1")) == .lt);
282 try expect(order(try parse("1.0.0-rc.1"), try parse("1.0.0")) == .lt);
283283}
284284
285285test "zig_version" {
lib/std/Thread/AutoResetEvent.zig+8-8
......@@ -176,7 +176,7 @@ test "basic usage" {
176176 // test local code paths
177177 {
178178 var event = AutoResetEvent{};
179 testing.expectError(error.TimedOut, event.timedWait(1));
179 try testing.expectError(error.TimedOut, event.timedWait(1));
180180 event.set();
181181 event.wait();
182182 }
......@@ -192,28 +192,28 @@ test "basic usage" {
192192
193193 const Self = @This();
194194
195 fn sender(self: *Self) void {
196 testing.expect(self.value == 0);
195 fn sender(self: *Self) !void {
196 try testing.expect(self.value == 0);
197197 self.value = 1;
198198 self.out.set();
199199
200200 self.in.wait();
201 testing.expect(self.value == 2);
201 try testing.expect(self.value == 2);
202202 self.value = 3;
203203 self.out.set();
204204
205205 self.in.wait();
206 testing.expect(self.value == 4);
206 try testing.expect(self.value == 4);
207207 }
208208
209 fn receiver(self: *Self) void {
209 fn receiver(self: *Self) !void {
210210 self.out.wait();
211 testing.expect(self.value == 1);
211 try testing.expect(self.value == 1);
212212 self.value = 2;
213213 self.in.set();
214214
215215 self.out.wait();
216 testing.expect(self.value == 3);
216 try testing.expect(self.value == 3);
217217 self.value = 4;
218218 self.in.set();
219219 }
lib/std/Thread/Mutex.zig+2-2
......@@ -294,7 +294,7 @@ test "basic usage" {
294294
295295 if (builtin.single_threaded) {
296296 worker(&context);
297 testing.expect(context.data == TestContext.incr_count);
297 try testing.expect(context.data == TestContext.incr_count);
298298 } else {
299299 const thread_count = 10;
300300 var threads: [thread_count]*std.Thread = undefined;
......@@ -304,7 +304,7 @@ test "basic usage" {
304304 for (threads) |t|
305305 t.wait();
306306
307 testing.expect(context.data == thread_count * TestContext.incr_count);
307 try testing.expect(context.data == thread_count * TestContext.incr_count);
308308 }
309309}
310310
lib/std/Thread/ResetEvent.zig+10-10
......@@ -204,7 +204,7 @@ test "basic usage" {
204204 event.reset();
205205
206206 event.set();
207 testing.expectEqual(TimedWaitResult.event_set, event.timedWait(1));
207 try testing.expectEqual(TimedWaitResult.event_set, event.timedWait(1));
208208
209209 // test cross-thread signaling
210210 if (builtin.single_threaded)
......@@ -233,25 +233,25 @@ test "basic usage" {
233233 self.* = undefined;
234234 }
235235
236 fn sender(self: *Self) void {
236 fn sender(self: *Self) !void {
237237 // update value and signal input
238 testing.expect(self.value == 0);
238 try testing.expect(self.value == 0);
239239 self.value = 1;
240240 self.in.set();
241241
242242 // wait for receiver to update value and signal output
243243 self.out.wait();
244 testing.expect(self.value == 2);
244 try testing.expect(self.value == 2);
245245
246246 // update value and signal final input
247247 self.value = 3;
248248 self.in.set();
249249 }
250250
251 fn receiver(self: *Self) void {
251 fn receiver(self: *Self) !void {
252252 // wait for sender to update value and signal input
253253 self.in.wait();
254 assert(self.value == 1);
254 try testing.expect(self.value == 1);
255255
256256 // update value and signal output
257257 self.in.reset();
......@@ -260,7 +260,7 @@ test "basic usage" {
260260
261261 // wait for sender to update value and signal final input
262262 self.in.wait();
263 assert(self.value == 3);
263 try testing.expect(self.value == 3);
264264 }
265265
266266 fn sleeper(self: *Self) void {
......@@ -272,9 +272,9 @@ test "basic usage" {
272272
273273 fn timedWaiter(self: *Self) !void {
274274 self.in.wait();
275 testing.expectEqual(TimedWaitResult.timed_out, self.out.timedWait(time.ns_per_us));
275 try testing.expectEqual(TimedWaitResult.timed_out, self.out.timedWait(time.ns_per_us));
276276 try self.out.timedWait(time.ns_per_ms * 100);
277 testing.expect(self.value == 5);
277 try testing.expect(self.value == 5);
278278 }
279279 };
280280
......@@ -283,7 +283,7 @@ test "basic usage" {
283283 defer context.deinit();
284284 const receiver = try std.Thread.spawn(Context.receiver, &context);
285285 defer receiver.wait();
286 context.sender();
286 try context.sender();
287287
288288 if (false) {
289289 // I have now observed this fail on macOS, Windows, and Linux.
lib/std/Thread/StaticResetEvent.zig+10-10
......@@ -320,7 +320,7 @@ test "basic usage" {
320320 event.reset();
321321
322322 event.set();
323 testing.expectEqual(TimedWaitResult.event_set, event.timedWait(1));
323 try testing.expectEqual(TimedWaitResult.event_set, event.timedWait(1));
324324
325325 // test cross-thread signaling
326326 if (std.builtin.single_threaded)
......@@ -333,25 +333,25 @@ test "basic usage" {
333333 in: StaticResetEvent = .{},
334334 out: StaticResetEvent = .{},
335335
336 fn sender(self: *Self) void {
336 fn sender(self: *Self) !void {
337337 // update value and signal input
338 testing.expect(self.value == 0);
338 try testing.expect(self.value == 0);
339339 self.value = 1;
340340 self.in.set();
341341
342342 // wait for receiver to update value and signal output
343343 self.out.wait();
344 testing.expect(self.value == 2);
344 try testing.expect(self.value == 2);
345345
346346 // update value and signal final input
347347 self.value = 3;
348348 self.in.set();
349349 }
350350
351 fn receiver(self: *Self) void {
351 fn receiver(self: *Self) !void {
352352 // wait for sender to update value and signal input
353353 self.in.wait();
354 assert(self.value == 1);
354 try testing.expect(self.value == 1);
355355
356356 // update value and signal output
357357 self.in.reset();
......@@ -360,7 +360,7 @@ test "basic usage" {
360360
361361 // wait for sender to update value and signal final input
362362 self.in.wait();
363 assert(self.value == 3);
363 try testing.expect(self.value == 3);
364364 }
365365
366366 fn sleeper(self: *Self) void {
......@@ -372,16 +372,16 @@ test "basic usage" {
372372
373373 fn timedWaiter(self: *Self) !void {
374374 self.in.wait();
375 testing.expectEqual(TimedWaitResult.timed_out, self.out.timedWait(time.ns_per_us));
375 try testing.expectEqual(TimedWaitResult.timed_out, self.out.timedWait(time.ns_per_us));
376376 try self.out.timedWait(time.ns_per_ms * 100);
377 testing.expect(self.value == 5);
377 try testing.expect(self.value == 5);
378378 }
379379 };
380380
381381 var context = Context{};
382382 const receiver = try std.Thread.spawn(Context.receiver, &context);
383383 defer receiver.wait();
384 context.sender();
384 try context.sender();
385385
386386 if (false) {
387387 // I have now observed this fail on macOS, Windows, and Linux.
lib/std/array_hash_map.zig+68-68
......@@ -1088,63 +1088,63 @@ test "basic hash map usage" {
10881088 var map = AutoArrayHashMap(i32, i32).init(std.testing.allocator);
10891089 defer map.deinit();
10901090
1091 testing.expect((try map.fetchPut(1, 11)) == null);
1092 testing.expect((try map.fetchPut(2, 22)) == null);
1093 testing.expect((try map.fetchPut(3, 33)) == null);
1094 testing.expect((try map.fetchPut(4, 44)) == null);
1091 try testing.expect((try map.fetchPut(1, 11)) == null);
1092 try testing.expect((try map.fetchPut(2, 22)) == null);
1093 try testing.expect((try map.fetchPut(3, 33)) == null);
1094 try testing.expect((try map.fetchPut(4, 44)) == null);
10951095
10961096 try map.putNoClobber(5, 55);
1097 testing.expect((try map.fetchPut(5, 66)).?.value == 55);
1098 testing.expect((try map.fetchPut(5, 55)).?.value == 66);
1097 try testing.expect((try map.fetchPut(5, 66)).?.value == 55);
1098 try testing.expect((try map.fetchPut(5, 55)).?.value == 66);
10991099
11001100 const gop1 = try map.getOrPut(5);
1101 testing.expect(gop1.found_existing == true);
1102 testing.expect(gop1.entry.value == 55);
1103 testing.expect(gop1.index == 4);
1101 try testing.expect(gop1.found_existing == true);
1102 try testing.expect(gop1.entry.value == 55);
1103 try testing.expect(gop1.index == 4);
11041104 gop1.entry.value = 77;
1105 testing.expect(map.getEntry(5).?.value == 77);
1105 try testing.expect(map.getEntry(5).?.value == 77);
11061106
11071107 const gop2 = try map.getOrPut(99);
1108 testing.expect(gop2.found_existing == false);
1109 testing.expect(gop2.index == 5);
1108 try testing.expect(gop2.found_existing == false);
1109 try testing.expect(gop2.index == 5);
11101110 gop2.entry.value = 42;
1111 testing.expect(map.getEntry(99).?.value == 42);
1111 try testing.expect(map.getEntry(99).?.value == 42);
11121112
11131113 const gop3 = try map.getOrPutValue(5, 5);
1114 testing.expect(gop3.value == 77);
1114 try testing.expect(gop3.value == 77);
11151115
11161116 const gop4 = try map.getOrPutValue(100, 41);
1117 testing.expect(gop4.value == 41);
1117 try testing.expect(gop4.value == 41);
11181118
1119 testing.expect(map.contains(2));
1120 testing.expect(map.getEntry(2).?.value == 22);
1121 testing.expect(map.get(2).? == 22);
1119 try testing.expect(map.contains(2));
1120 try testing.expect(map.getEntry(2).?.value == 22);
1121 try testing.expect(map.get(2).? == 22);
11221122
11231123 const rmv1 = map.swapRemove(2);
1124 testing.expect(rmv1.?.key == 2);
1125 testing.expect(rmv1.?.value == 22);
1126 testing.expect(map.swapRemove(2) == null);
1127 testing.expect(map.getEntry(2) == null);
1128 testing.expect(map.get(2) == null);
1124 try testing.expect(rmv1.?.key == 2);
1125 try testing.expect(rmv1.?.value == 22);
1126 try testing.expect(map.swapRemove(2) == null);
1127 try testing.expect(map.getEntry(2) == null);
1128 try testing.expect(map.get(2) == null);
11291129
11301130 // Since we've used `swapRemove` above, the index of this entry should remain unchanged.
1131 testing.expect(map.getIndex(100).? == 1);
1131 try testing.expect(map.getIndex(100).? == 1);
11321132 const gop5 = try map.getOrPut(5);
1133 testing.expect(gop5.found_existing == true);
1134 testing.expect(gop5.entry.value == 77);
1135 testing.expect(gop5.index == 4);
1133 try testing.expect(gop5.found_existing == true);
1134 try testing.expect(gop5.entry.value == 77);
1135 try testing.expect(gop5.index == 4);
11361136
11371137 // Whereas, if we do an `orderedRemove`, it should move the index forward one spot.
11381138 const rmv2 = map.orderedRemove(100);
1139 testing.expect(rmv2.?.key == 100);
1140 testing.expect(rmv2.?.value == 41);
1141 testing.expect(map.orderedRemove(100) == null);
1142 testing.expect(map.getEntry(100) == null);
1143 testing.expect(map.get(100) == null);
1139 try testing.expect(rmv2.?.key == 100);
1140 try testing.expect(rmv2.?.value == 41);
1141 try testing.expect(map.orderedRemove(100) == null);
1142 try testing.expect(map.getEntry(100) == null);
1143 try testing.expect(map.get(100) == null);
11441144 const gop6 = try map.getOrPut(5);
1145 testing.expect(gop6.found_existing == true);
1146 testing.expect(gop6.entry.value == 77);
1147 testing.expect(gop6.index == 3);
1145 try testing.expect(gop6.found_existing == true);
1146 try testing.expect(gop6.entry.value == 77);
1147 try testing.expect(gop6.index == 3);
11481148
11491149 map.removeAssertDiscard(3);
11501150}
......@@ -1180,11 +1180,11 @@ test "iterator hash map" {
11801180 while (it.next()) |entry| : (count += 1) {
11811181 buffer[@intCast(usize, entry.key)] = entry.value;
11821182 }
1183 testing.expect(count == 3);
1184 testing.expect(it.next() == null);
1183 try testing.expect(count == 3);
1184 try testing.expect(it.next() == null);
11851185
11861186 for (buffer) |v, i| {
1187 testing.expect(buffer[@intCast(usize, keys[i])] == values[i]);
1187 try testing.expect(buffer[@intCast(usize, keys[i])] == values[i]);
11881188 }
11891189
11901190 it.reset();
......@@ -1196,13 +1196,13 @@ test "iterator hash map" {
11961196 }
11971197
11981198 for (buffer[0..2]) |v, i| {
1199 testing.expect(buffer[@intCast(usize, keys[i])] == values[i]);
1199 try testing.expect(buffer[@intCast(usize, keys[i])] == values[i]);
12001200 }
12011201
12021202 it.reset();
12031203 var entry = it.next().?;
1204 testing.expect(entry.key == first_entry.key);
1205 testing.expect(entry.value == first_entry.value);
1204 try testing.expect(entry.key == first_entry.key);
1205 try testing.expect(entry.value == first_entry.value);
12061206}
12071207
12081208test "ensure capacity" {
......@@ -1211,13 +1211,13 @@ test "ensure capacity" {
12111211
12121212 try map.ensureCapacity(20);
12131213 const initial_capacity = map.capacity();
1214 testing.expect(initial_capacity >= 20);
1214 try testing.expect(initial_capacity >= 20);
12151215 var i: i32 = 0;
12161216 while (i < 20) : (i += 1) {
1217 testing.expect(map.fetchPutAssumeCapacity(i, i + 10) == null);
1217 try testing.expect(map.fetchPutAssumeCapacity(i, i + 10) == null);
12181218 }
12191219 // shouldn't resize from putAssumeCapacity
1220 testing.expect(initial_capacity == map.capacity());
1220 try testing.expect(initial_capacity == map.capacity());
12211221}
12221222
12231223test "clone" {
......@@ -1235,7 +1235,7 @@ test "clone" {
12351235
12361236 i = 0;
12371237 while (i < 10) : (i += 1) {
1238 testing.expect(copy.get(i).? == i * 10);
1238 try testing.expect(copy.get(i).? == i * 10);
12391239 }
12401240}
12411241
......@@ -1247,35 +1247,35 @@ test "shrink" {
12471247 const num_entries = 20;
12481248 var i: i32 = 0;
12491249 while (i < num_entries) : (i += 1)
1250 testing.expect((try map.fetchPut(i, i * 10)) == null);
1250 try testing.expect((try map.fetchPut(i, i * 10)) == null);
12511251
1252 testing.expect(map.unmanaged.index_header != null);
1253 testing.expect(map.count() == num_entries);
1252 try testing.expect(map.unmanaged.index_header != null);
1253 try testing.expect(map.count() == num_entries);
12541254
12551255 // Test `shrinkRetainingCapacity`.
12561256 map.shrinkRetainingCapacity(17);
1257 testing.expect(map.count() == 17);
1258 testing.expect(map.capacity() == 20);
1257 try testing.expect(map.count() == 17);
1258 try testing.expect(map.capacity() == 20);
12591259 i = 0;
12601260 while (i < num_entries) : (i += 1) {
12611261 const gop = try map.getOrPut(i);
12621262 if (i < 17) {
1263 testing.expect(gop.found_existing == true);
1264 testing.expect(gop.entry.value == i * 10);
1265 } else testing.expect(gop.found_existing == false);
1263 try testing.expect(gop.found_existing == true);
1264 try testing.expect(gop.entry.value == i * 10);
1265 } else try testing.expect(gop.found_existing == false);
12661266 }
12671267
12681268 // Test `shrinkAndFree`.
12691269 map.shrinkAndFree(15);
1270 testing.expect(map.count() == 15);
1271 testing.expect(map.capacity() == 15);
1270 try testing.expect(map.count() == 15);
1271 try testing.expect(map.capacity() == 15);
12721272 i = 0;
12731273 while (i < num_entries) : (i += 1) {
12741274 const gop = try map.getOrPut(i);
12751275 if (i < 15) {
1276 testing.expect(gop.found_existing == true);
1277 testing.expect(gop.entry.value == i * 10);
1278 } else testing.expect(gop.found_existing == false);
1276 try testing.expect(gop.found_existing == true);
1277 try testing.expect(gop.entry.value == i * 10);
1278 } else try testing.expect(gop.found_existing == false);
12791279 }
12801280}
12811281
......@@ -1288,12 +1288,12 @@ test "pop" {
12881288
12891289 var i: i32 = 0;
12901290 while (i < 9) : (i += 1) {
1291 testing.expect((try map.fetchPut(i, i)) == null);
1291 try testing.expect((try map.fetchPut(i, i)) == null);
12921292 }
12931293
12941294 while (i > 0) : (i -= 1) {
12951295 const pop = map.pop();
1296 testing.expect(pop.key == i - 1 and pop.value == i - 1);
1296 try testing.expect(pop.key == i - 1 and pop.value == i - 1);
12971297 }
12981298}
12991299
......@@ -1305,10 +1305,10 @@ test "reIndex" {
13051305 const num_indexed_entries = 20;
13061306 var i: i32 = 0;
13071307 while (i < num_indexed_entries) : (i += 1)
1308 testing.expect((try map.fetchPut(i, i * 10)) == null);
1308 try testing.expect((try map.fetchPut(i, i * 10)) == null);
13091309
13101310 // Make sure we allocated an index header.
1311 testing.expect(map.unmanaged.index_header != null);
1311 try testing.expect(map.unmanaged.index_header != null);
13121312
13131313 // Now write to the underlying array list directly.
13141314 const num_unindexed_entries = 20;
......@@ -1327,9 +1327,9 @@ test "reIndex" {
13271327 i = 0;
13281328 while (i < num_indexed_entries + num_unindexed_entries) : (i += 1) {
13291329 const gop = try map.getOrPut(i);
1330 testing.expect(gop.found_existing == true);
1331 testing.expect(gop.entry.value == i * 10);
1332 testing.expect(gop.index == i);
1330 try testing.expect(gop.found_existing == true);
1331 try testing.expect(gop.entry.value == i * 10);
1332 try testing.expect(gop.index == i);
13331333 }
13341334}
13351335
......@@ -1356,9 +1356,9 @@ test "fromOwnedArrayList" {
13561356 i = 0;
13571357 while (i < num_entries) : (i += 1) {
13581358 const gop = try map.getOrPut(i);
1359 testing.expect(gop.found_existing == true);
1360 testing.expect(gop.entry.value == i * 10);
1361 testing.expect(gop.index == i);
1359 try testing.expect(gop.found_existing == true);
1360 try testing.expect(gop.entry.value == i * 10);
1361 try testing.expect(gop.index == i);
13621362 }
13631363}
13641364
lib/std/array_list.zig+116-116
......@@ -741,15 +741,15 @@ test "std.ArrayList/ArrayListUnmanaged.init" {
741741 var list = ArrayList(i32).init(testing.allocator);
742742 defer list.deinit();
743743
744 testing.expect(list.items.len == 0);
745 testing.expect(list.capacity == 0);
744 try testing.expect(list.items.len == 0);
745 try testing.expect(list.capacity == 0);
746746 }
747747
748748 {
749749 var list = ArrayListUnmanaged(i32){};
750750
751 testing.expect(list.items.len == 0);
752 testing.expect(list.capacity == 0);
751 try testing.expect(list.items.len == 0);
752 try testing.expect(list.capacity == 0);
753753 }
754754}
755755
......@@ -758,14 +758,14 @@ test "std.ArrayList/ArrayListUnmanaged.initCapacity" {
758758 {
759759 var list = try ArrayList(i8).initCapacity(a, 200);
760760 defer list.deinit();
761 testing.expect(list.items.len == 0);
762 testing.expect(list.capacity >= 200);
761 try testing.expect(list.items.len == 0);
762 try testing.expect(list.capacity >= 200);
763763 }
764764 {
765765 var list = try ArrayListUnmanaged(i8).initCapacity(a, 200);
766766 defer list.deinit(a);
767 testing.expect(list.items.len == 0);
768 testing.expect(list.capacity >= 200);
767 try testing.expect(list.items.len == 0);
768 try testing.expect(list.capacity >= 200);
769769 }
770770}
771771
......@@ -785,33 +785,33 @@ test "std.ArrayList/ArrayListUnmanaged.basic" {
785785 {
786786 var i: usize = 0;
787787 while (i < 10) : (i += 1) {
788 testing.expect(list.items[i] == @intCast(i32, i + 1));
788 try testing.expect(list.items[i] == @intCast(i32, i + 1));
789789 }
790790 }
791791
792792 for (list.items) |v, i| {
793 testing.expect(v == @intCast(i32, i + 1));
793 try testing.expect(v == @intCast(i32, i + 1));
794794 }
795795
796 testing.expect(list.pop() == 10);
797 testing.expect(list.items.len == 9);
796 try testing.expect(list.pop() == 10);
797 try testing.expect(list.items.len == 9);
798798
799799 list.appendSlice(&[_]i32{ 1, 2, 3 }) catch unreachable;
800 testing.expect(list.items.len == 12);
801 testing.expect(list.pop() == 3);
802 testing.expect(list.pop() == 2);
803 testing.expect(list.pop() == 1);
804 testing.expect(list.items.len == 9);
800 try testing.expect(list.items.len == 12);
801 try testing.expect(list.pop() == 3);
802 try testing.expect(list.pop() == 2);
803 try testing.expect(list.pop() == 1);
804 try testing.expect(list.items.len == 9);
805805
806806 list.appendSlice(&[_]i32{}) catch unreachable;
807 testing.expect(list.items.len == 9);
807 try testing.expect(list.items.len == 9);
808808
809809 // can only set on indices < self.items.len
810810 list.items[7] = 33;
811811 list.items[8] = 42;
812812
813 testing.expect(list.pop() == 42);
814 testing.expect(list.pop() == 33);
813 try testing.expect(list.pop() == 42);
814 try testing.expect(list.pop() == 33);
815815 }
816816 {
817817 var list = ArrayListUnmanaged(i32){};
......@@ -827,33 +827,33 @@ test "std.ArrayList/ArrayListUnmanaged.basic" {
827827 {
828828 var i: usize = 0;
829829 while (i < 10) : (i += 1) {
830 testing.expect(list.items[i] == @intCast(i32, i + 1));
830 try testing.expect(list.items[i] == @intCast(i32, i + 1));
831831 }
832832 }
833833
834834 for (list.items) |v, i| {
835 testing.expect(v == @intCast(i32, i + 1));
835 try testing.expect(v == @intCast(i32, i + 1));
836836 }
837837
838 testing.expect(list.pop() == 10);
839 testing.expect(list.items.len == 9);
838 try testing.expect(list.pop() == 10);
839 try testing.expect(list.items.len == 9);
840840
841841 list.appendSlice(a, &[_]i32{ 1, 2, 3 }) catch unreachable;
842 testing.expect(list.items.len == 12);
843 testing.expect(list.pop() == 3);
844 testing.expect(list.pop() == 2);
845 testing.expect(list.pop() == 1);
846 testing.expect(list.items.len == 9);
842 try testing.expect(list.items.len == 12);
843 try testing.expect(list.pop() == 3);
844 try testing.expect(list.pop() == 2);
845 try testing.expect(list.pop() == 1);
846 try testing.expect(list.items.len == 9);
847847
848848 list.appendSlice(a, &[_]i32{}) catch unreachable;
849 testing.expect(list.items.len == 9);
849 try testing.expect(list.items.len == 9);
850850
851851 // can only set on indices < self.items.len
852852 list.items[7] = 33;
853853 list.items[8] = 42;
854854
855 testing.expect(list.pop() == 42);
856 testing.expect(list.pop() == 33);
855 try testing.expect(list.pop() == 42);
856 try testing.expect(list.pop() == 33);
857857 }
858858}
859859
......@@ -864,9 +864,9 @@ test "std.ArrayList/ArrayListUnmanaged.appendNTimes" {
864864 defer list.deinit();
865865
866866 try list.appendNTimes(2, 10);
867 testing.expectEqual(@as(usize, 10), list.items.len);
867 try testing.expectEqual(@as(usize, 10), list.items.len);
868868 for (list.items) |element| {
869 testing.expectEqual(@as(i32, 2), element);
869 try testing.expectEqual(@as(i32, 2), element);
870870 }
871871 }
872872 {
......@@ -874,9 +874,9 @@ test "std.ArrayList/ArrayListUnmanaged.appendNTimes" {
874874 defer list.deinit(a);
875875
876876 try list.appendNTimes(a, 2, 10);
877 testing.expectEqual(@as(usize, 10), list.items.len);
877 try testing.expectEqual(@as(usize, 10), list.items.len);
878878 for (list.items) |element| {
879 testing.expectEqual(@as(i32, 2), element);
879 try testing.expectEqual(@as(i32, 2), element);
880880 }
881881 }
882882}
......@@ -886,12 +886,12 @@ test "std.ArrayList/ArrayListUnmanaged.appendNTimes with failing allocator" {
886886 {
887887 var list = ArrayList(i32).init(a);
888888 defer list.deinit();
889 testing.expectError(error.OutOfMemory, list.appendNTimes(2, 10));
889 try testing.expectError(error.OutOfMemory, list.appendNTimes(2, 10));
890890 }
891891 {
892892 var list = ArrayListUnmanaged(i32){};
893893 defer list.deinit(a);
894 testing.expectError(error.OutOfMemory, list.appendNTimes(a, 2, 10));
894 try testing.expectError(error.OutOfMemory, list.appendNTimes(a, 2, 10));
895895 }
896896}
897897
......@@ -910,18 +910,18 @@ test "std.ArrayList/ArrayListUnmanaged.orderedRemove" {
910910 try list.append(7);
911911
912912 //remove from middle
913 testing.expectEqual(@as(i32, 4), list.orderedRemove(3));
914 testing.expectEqual(@as(i32, 5), list.items[3]);
915 testing.expectEqual(@as(usize, 6), list.items.len);
913 try testing.expectEqual(@as(i32, 4), list.orderedRemove(3));
914 try testing.expectEqual(@as(i32, 5), list.items[3]);
915 try testing.expectEqual(@as(usize, 6), list.items.len);
916916
917917 //remove from end
918 testing.expectEqual(@as(i32, 7), list.orderedRemove(5));
919 testing.expectEqual(@as(usize, 5), list.items.len);
918 try testing.expectEqual(@as(i32, 7), list.orderedRemove(5));
919 try testing.expectEqual(@as(usize, 5), list.items.len);
920920
921921 //remove from front
922 testing.expectEqual(@as(i32, 1), list.orderedRemove(0));
923 testing.expectEqual(@as(i32, 2), list.items[0]);
924 testing.expectEqual(@as(usize, 4), list.items.len);
922 try testing.expectEqual(@as(i32, 1), list.orderedRemove(0));
923 try testing.expectEqual(@as(i32, 2), list.items[0]);
924 try testing.expectEqual(@as(usize, 4), list.items.len);
925925 }
926926 {
927927 var list = ArrayListUnmanaged(i32){};
......@@ -936,18 +936,18 @@ test "std.ArrayList/ArrayListUnmanaged.orderedRemove" {
936936 try list.append(a, 7);
937937
938938 //remove from middle
939 testing.expectEqual(@as(i32, 4), list.orderedRemove(3));
940 testing.expectEqual(@as(i32, 5), list.items[3]);
941 testing.expectEqual(@as(usize, 6), list.items.len);
939 try testing.expectEqual(@as(i32, 4), list.orderedRemove(3));
940 try testing.expectEqual(@as(i32, 5), list.items[3]);
941 try testing.expectEqual(@as(usize, 6), list.items.len);
942942
943943 //remove from end
944 testing.expectEqual(@as(i32, 7), list.orderedRemove(5));
945 testing.expectEqual(@as(usize, 5), list.items.len);
944 try testing.expectEqual(@as(i32, 7), list.orderedRemove(5));
945 try testing.expectEqual(@as(usize, 5), list.items.len);
946946
947947 //remove from front
948 testing.expectEqual(@as(i32, 1), list.orderedRemove(0));
949 testing.expectEqual(@as(i32, 2), list.items[0]);
950 testing.expectEqual(@as(usize, 4), list.items.len);
948 try testing.expectEqual(@as(i32, 1), list.orderedRemove(0));
949 try testing.expectEqual(@as(i32, 2), list.items[0]);
950 try testing.expectEqual(@as(usize, 4), list.items.len);
951951 }
952952}
953953
......@@ -966,18 +966,18 @@ test "std.ArrayList/ArrayListUnmanaged.swapRemove" {
966966 try list.append(7);
967967
968968 //remove from middle
969 testing.expect(list.swapRemove(3) == 4);
970 testing.expect(list.items[3] == 7);
971 testing.expect(list.items.len == 6);
969 try testing.expect(list.swapRemove(3) == 4);
970 try testing.expect(list.items[3] == 7);
971 try testing.expect(list.items.len == 6);
972972
973973 //remove from end
974 testing.expect(list.swapRemove(5) == 6);
975 testing.expect(list.items.len == 5);
974 try testing.expect(list.swapRemove(5) == 6);
975 try testing.expect(list.items.len == 5);
976976
977977 //remove from front
978 testing.expect(list.swapRemove(0) == 1);
979 testing.expect(list.items[0] == 5);
980 testing.expect(list.items.len == 4);
978 try testing.expect(list.swapRemove(0) == 1);
979 try testing.expect(list.items[0] == 5);
980 try testing.expect(list.items.len == 4);
981981 }
982982 {
983983 var list = ArrayListUnmanaged(i32){};
......@@ -992,18 +992,18 @@ test "std.ArrayList/ArrayListUnmanaged.swapRemove" {
992992 try list.append(a, 7);
993993
994994 //remove from middle
995 testing.expect(list.swapRemove(3) == 4);
996 testing.expect(list.items[3] == 7);
997 testing.expect(list.items.len == 6);
995 try testing.expect(list.swapRemove(3) == 4);
996 try testing.expect(list.items[3] == 7);
997 try testing.expect(list.items.len == 6);
998998
999999 //remove from end
1000 testing.expect(list.swapRemove(5) == 6);
1001 testing.expect(list.items.len == 5);
1000 try testing.expect(list.swapRemove(5) == 6);
1001 try testing.expect(list.items.len == 5);
10021002
10031003 //remove from front
1004 testing.expect(list.swapRemove(0) == 1);
1005 testing.expect(list.items[0] == 5);
1006 testing.expect(list.items.len == 4);
1004 try testing.expect(list.swapRemove(0) == 1);
1005 try testing.expect(list.items[0] == 5);
1006 try testing.expect(list.items.len == 4);
10071007 }
10081008}
10091009
......@@ -1017,10 +1017,10 @@ test "std.ArrayList/ArrayListUnmanaged.insert" {
10171017 try list.append(2);
10181018 try list.append(3);
10191019 try list.insert(0, 5);
1020 testing.expect(list.items[0] == 5);
1021 testing.expect(list.items[1] == 1);
1022 testing.expect(list.items[2] == 2);
1023 testing.expect(list.items[3] == 3);
1020 try testing.expect(list.items[0] == 5);
1021 try testing.expect(list.items[1] == 1);
1022 try testing.expect(list.items[2] == 2);
1023 try testing.expect(list.items[3] == 3);
10241024 }
10251025 {
10261026 var list = ArrayListUnmanaged(i32){};
......@@ -1030,10 +1030,10 @@ test "std.ArrayList/ArrayListUnmanaged.insert" {
10301030 try list.append(a, 2);
10311031 try list.append(a, 3);
10321032 try list.insert(a, 0, 5);
1033 testing.expect(list.items[0] == 5);
1034 testing.expect(list.items[1] == 1);
1035 testing.expect(list.items[2] == 2);
1036 testing.expect(list.items[3] == 3);
1033 try testing.expect(list.items[0] == 5);
1034 try testing.expect(list.items[1] == 1);
1035 try testing.expect(list.items[2] == 2);
1036 try testing.expect(list.items[3] == 3);
10371037 }
10381038}
10391039
......@@ -1048,17 +1048,17 @@ test "std.ArrayList/ArrayListUnmanaged.insertSlice" {
10481048 try list.append(3);
10491049 try list.append(4);
10501050 try list.insertSlice(1, &[_]i32{ 9, 8 });
1051 testing.expect(list.items[0] == 1);
1052 testing.expect(list.items[1] == 9);
1053 testing.expect(list.items[2] == 8);
1054 testing.expect(list.items[3] == 2);
1055 testing.expect(list.items[4] == 3);
1056 testing.expect(list.items[5] == 4);
1051 try testing.expect(list.items[0] == 1);
1052 try testing.expect(list.items[1] == 9);
1053 try testing.expect(list.items[2] == 8);
1054 try testing.expect(list.items[3] == 2);
1055 try testing.expect(list.items[4] == 3);
1056 try testing.expect(list.items[5] == 4);
10571057
10581058 const items = [_]i32{1};
10591059 try list.insertSlice(0, items[0..0]);
1060 testing.expect(list.items.len == 6);
1061 testing.expect(list.items[0] == 1);
1060 try testing.expect(list.items.len == 6);
1061 try testing.expect(list.items[0] == 1);
10621062 }
10631063 {
10641064 var list = ArrayListUnmanaged(i32){};
......@@ -1069,17 +1069,17 @@ test "std.ArrayList/ArrayListUnmanaged.insertSlice" {
10691069 try list.append(a, 3);
10701070 try list.append(a, 4);
10711071 try list.insertSlice(a, 1, &[_]i32{ 9, 8 });
1072 testing.expect(list.items[0] == 1);
1073 testing.expect(list.items[1] == 9);
1074 testing.expect(list.items[2] == 8);
1075 testing.expect(list.items[3] == 2);
1076 testing.expect(list.items[4] == 3);
1077 testing.expect(list.items[5] == 4);
1072 try testing.expect(list.items[0] == 1);
1073 try testing.expect(list.items[1] == 9);
1074 try testing.expect(list.items[2] == 8);
1075 try testing.expect(list.items[3] == 2);
1076 try testing.expect(list.items[4] == 3);
1077 try testing.expect(list.items[5] == 4);
10781078
10791079 const items = [_]i32{1};
10801080 try list.insertSlice(a, 0, items[0..0]);
1081 testing.expect(list.items.len == 6);
1082 testing.expect(list.items[0] == 1);
1081 try testing.expect(list.items.len == 6);
1082 try testing.expect(list.items[0] == 1);
10831083 }
10841084}
10851085
......@@ -1112,13 +1112,13 @@ test "std.ArrayList/ArrayListUnmanaged.replaceRange" {
11121112 try list_lt.replaceRange(1, 2, &new);
11131113
11141114 // after_range > new_items.len in function body
1115 testing.expect(1 + 4 > new.len);
1115 try testing.expect(1 + 4 > new.len);
11161116 try list_gt.replaceRange(1, 4, &new);
11171117
1118 testing.expectEqualSlices(i32, list_zero.items, &result_zero);
1119 testing.expectEqualSlices(i32, list_eq.items, &result_eq);
1120 testing.expectEqualSlices(i32, list_lt.items, &result_le);
1121 testing.expectEqualSlices(i32, list_gt.items, &result_gt);
1118 try testing.expectEqualSlices(i32, list_zero.items, &result_zero);
1119 try testing.expectEqualSlices(i32, list_eq.items, &result_eq);
1120 try testing.expectEqualSlices(i32, list_lt.items, &result_le);
1121 try testing.expectEqualSlices(i32, list_gt.items, &result_gt);
11221122 }
11231123 {
11241124 var list_zero = ArrayListUnmanaged(i32){};
......@@ -1136,13 +1136,13 @@ test "std.ArrayList/ArrayListUnmanaged.replaceRange" {
11361136 try list_lt.replaceRange(a, 1, 2, &new);
11371137
11381138 // after_range > new_items.len in function body
1139 testing.expect(1 + 4 > new.len);
1139 try testing.expect(1 + 4 > new.len);
11401140 try list_gt.replaceRange(a, 1, 4, &new);
11411141
1142 testing.expectEqualSlices(i32, list_zero.items, &result_zero);
1143 testing.expectEqualSlices(i32, list_eq.items, &result_eq);
1144 testing.expectEqualSlices(i32, list_lt.items, &result_le);
1145 testing.expectEqualSlices(i32, list_gt.items, &result_gt);
1142 try testing.expectEqualSlices(i32, list_zero.items, &result_zero);
1143 try testing.expectEqualSlices(i32, list_eq.items, &result_eq);
1144 try testing.expectEqualSlices(i32, list_lt.items, &result_le);
1145 try testing.expectEqualSlices(i32, list_gt.items, &result_gt);
11461146 }
11471147}
11481148
......@@ -1162,13 +1162,13 @@ test "std.ArrayList/ArrayListUnmanaged: ArrayList(T) of struct T" {
11621162 var root = Item{ .integer = 1, .sub_items = ArrayList(Item).init(a) };
11631163 defer root.sub_items.deinit();
11641164 try root.sub_items.append(Item{ .integer = 42, .sub_items = ArrayList(Item).init(a) });
1165 testing.expect(root.sub_items.items[0].integer == 42);
1165 try testing.expect(root.sub_items.items[0].integer == 42);
11661166 }
11671167 {
11681168 var root = ItemUnmanaged{ .integer = 1, .sub_items = ArrayListUnmanaged(ItemUnmanaged){} };
11691169 defer root.sub_items.deinit(a);
11701170 try root.sub_items.append(a, ItemUnmanaged{ .integer = 42, .sub_items = ArrayListUnmanaged(ItemUnmanaged){} });
1171 testing.expect(root.sub_items.items[0].integer == 42);
1171 try testing.expect(root.sub_items.items[0].integer == 42);
11721172 }
11731173}
11741174
......@@ -1183,7 +1183,7 @@ test "std.ArrayList(u8)/ArrayListAligned implements writer" {
11831183 const y: i32 = 1234;
11841184 try buffer.writer().print("x: {}\ny: {}\n", .{ x, y });
11851185
1186 testing.expectEqualSlices(u8, "x: 42\ny: 1234\n", buffer.items);
1186 try testing.expectEqualSlices(u8, "x: 42\ny: 1234\n", buffer.items);
11871187 }
11881188 {
11891189 var list = ArrayListAligned(u8, 2).init(a);
......@@ -1195,7 +1195,7 @@ test "std.ArrayList(u8)/ArrayListAligned implements writer" {
11951195 try writer.writeAll("d");
11961196 try writer.writeAll("efg");
11971197
1198 testing.expectEqualSlices(u8, list.items, "abcdefg");
1198 try testing.expectEqualSlices(u8, list.items, "abcdefg");
11991199 }
12001200}
12011201
......@@ -1213,7 +1213,7 @@ test "std.ArrayList/ArrayListUnmanaged.shrink still sets length on error.OutOfMe
12131213 try list.append(3);
12141214
12151215 list.shrinkAndFree(1);
1216 testing.expect(list.items.len == 1);
1216 try testing.expect(list.items.len == 1);
12171217 }
12181218 {
12191219 var list = ArrayListUnmanaged(i32){};
......@@ -1223,7 +1223,7 @@ test "std.ArrayList/ArrayListUnmanaged.shrink still sets length on error.OutOfMe
12231223 try list.append(a, 3);
12241224
12251225 list.shrinkAndFree(a, 1);
1226 testing.expect(list.items.len == 1);
1226 try testing.expect(list.items.len == 1);
12271227 }
12281228}
12291229
......@@ -1237,7 +1237,7 @@ test "std.ArrayList/ArrayListUnmanaged.addManyAsArray" {
12371237 try list.ensureTotalCapacity(8);
12381238 list.addManyAsArrayAssumeCapacity(4).* = "asdf".*;
12391239
1240 testing.expectEqualSlices(u8, list.items, "aoeuasdf");
1240 try testing.expectEqualSlices(u8, list.items, "aoeuasdf");
12411241 }
12421242 {
12431243 var list = ArrayListUnmanaged(u8){};
......@@ -1247,7 +1247,7 @@ test "std.ArrayList/ArrayListUnmanaged.addManyAsArray" {
12471247 try list.ensureTotalCapacity(a, 8);
12481248 list.addManyAsArrayAssumeCapacity(4).* = "asdf".*;
12491249
1250 testing.expectEqualSlices(u8, list.items, "aoeuasdf");
1250 try testing.expectEqualSlices(u8, list.items, "aoeuasdf");
12511251 }
12521252}
12531253
......@@ -1261,7 +1261,7 @@ test "std.ArrayList/ArrayListUnmanaged.toOwnedSliceSentinel" {
12611261
12621262 const result = try list.toOwnedSliceSentinel(0);
12631263 defer a.free(result);
1264 testing.expectEqualStrings(result, mem.spanZ(result.ptr));
1264 try testing.expectEqualStrings(result, mem.spanZ(result.ptr));
12651265 }
12661266 {
12671267 var list = ArrayListUnmanaged(u8){};
......@@ -1271,7 +1271,7 @@ test "std.ArrayList/ArrayListUnmanaged.toOwnedSliceSentinel" {
12711271
12721272 const result = try list.toOwnedSliceSentinel(a, 0);
12731273 defer a.free(result);
1274 testing.expectEqualStrings(result, mem.spanZ(result.ptr));
1274 try testing.expectEqualStrings(result, mem.spanZ(result.ptr));
12751275 }
12761276}
12771277
......@@ -1285,7 +1285,7 @@ test "ArrayListAligned/ArrayListAlignedUnmanaged accepts unaligned slices" {
12851285 try list.insertSlice(2, &.{ 4, 5, 6, 7 });
12861286 try list.replaceRange(1, 3, &.{ 8, 9 });
12871287
1288 testing.expectEqualSlices(u8, list.items, &.{ 0, 8, 9, 6, 7, 2, 3 });
1288 try testing.expectEqualSlices(u8, list.items, &.{ 0, 8, 9, 6, 7, 2, 3 });
12891289 }
12901290 {
12911291 var list = std.ArrayListAlignedUnmanaged(u8, 8){};
......@@ -1295,6 +1295,6 @@ test "ArrayListAligned/ArrayListAlignedUnmanaged accepts unaligned slices" {
12951295 try list.insertSlice(a, 2, &.{ 4, 5, 6, 7 });
12961296 try list.replaceRange(a, 1, 3, &.{ 8, 9 });
12971297
1298 testing.expectEqualSlices(u8, list.items, &.{ 0, 8, 9, 6, 7, 2, 3 });
1298 try testing.expectEqualSlices(u8, list.items, &.{ 0, 8, 9, 6, 7, 2, 3 });
12991299 }
13001300}
lib/std/ascii.zig+23-23
......@@ -236,11 +236,11 @@ pub const spaces = [_]u8{ ' ', '\t', '\n', '\r', control_code.VT, control_code.F
236236
237237test "spaces" {
238238 const testing = std.testing;
239 for (spaces) |space| testing.expect(isSpace(space));
239 for (spaces) |space| try testing.expect(isSpace(space));
240240
241241 var i: u8 = 0;
242242 while (isASCII(i)) : (i += 1) {
243 if (isSpace(i)) testing.expect(std.mem.indexOfScalar(u8, &spaces, i) != null);
243 if (isSpace(i)) try testing.expect(std.mem.indexOfScalar(u8, &spaces, i) != null);
244244 }
245245}
246246
......@@ -279,13 +279,13 @@ pub fn toLower(c: u8) u8 {
279279test "ascii character classes" {
280280 const testing = std.testing;
281281
282 testing.expect('C' == toUpper('c'));
283 testing.expect(':' == toUpper(':'));
284 testing.expect('\xab' == toUpper('\xab'));
285 testing.expect('c' == toLower('C'));
286 testing.expect(isAlpha('c'));
287 testing.expect(!isAlpha('5'));
288 testing.expect(isSpace(' '));
282 try testing.expect('C' == toUpper('c'));
283 try testing.expect(':' == toUpper(':'));
284 try testing.expect('\xab' == toUpper('\xab'));
285 try testing.expect('c' == toLower('C'));
286 try testing.expect(isAlpha('c'));
287 try testing.expect(!isAlpha('5'));
288 try testing.expect(isSpace(' '));
289289}
290290
291291/// Allocates a lower case copy of `ascii_string`.
......@@ -301,7 +301,7 @@ pub fn allocLowerString(allocator: *std.mem.Allocator, ascii_string: []const u8)
301301test "allocLowerString" {
302302 const result = try allocLowerString(std.testing.allocator, "aBcDeFgHiJkLmNOPqrst0234+💩!");
303303 defer std.testing.allocator.free(result);
304 std.testing.expect(std.mem.eql(u8, "abcdefghijklmnopqrst0234+💩!", result));
304 try std.testing.expect(std.mem.eql(u8, "abcdefghijklmnopqrst0234+💩!", result));
305305}
306306
307307/// Allocates an upper case copy of `ascii_string`.
......@@ -317,7 +317,7 @@ pub fn allocUpperString(allocator: *std.mem.Allocator, ascii_string: []const u8)
317317test "allocUpperString" {
318318 const result = try allocUpperString(std.testing.allocator, "aBcDeFgHiJkLmNOPqrst0234+💩!");
319319 defer std.testing.allocator.free(result);
320 std.testing.expect(std.mem.eql(u8, "ABCDEFGHIJKLMNOPQRST0234+💩!", result));
320 try std.testing.expect(std.mem.eql(u8, "ABCDEFGHIJKLMNOPQRST0234+💩!", result));
321321}
322322
323323/// Compares strings `a` and `b` case insensitively and returns whether they are equal.
......@@ -330,9 +330,9 @@ pub fn eqlIgnoreCase(a: []const u8, b: []const u8) bool {
330330}
331331
332332test "eqlIgnoreCase" {
333 std.testing.expect(eqlIgnoreCase("HEl💩Lo!", "hel💩lo!"));
334 std.testing.expect(!eqlIgnoreCase("hElLo!", "hello! "));
335 std.testing.expect(!eqlIgnoreCase("hElLo!", "helro!"));
333 try std.testing.expect(eqlIgnoreCase("HEl💩Lo!", "hel💩lo!"));
334 try std.testing.expect(!eqlIgnoreCase("hElLo!", "hello! "));
335 try std.testing.expect(!eqlIgnoreCase("hElLo!", "helro!"));
336336}
337337
338338pub fn startsWithIgnoreCase(haystack: []const u8, needle: []const u8) bool {
......@@ -340,8 +340,8 @@ pub fn startsWithIgnoreCase(haystack: []const u8, needle: []const u8) bool {
340340}
341341
342342test "ascii.startsWithIgnoreCase" {
343 std.testing.expect(startsWithIgnoreCase("boB", "Bo"));
344 std.testing.expect(!startsWithIgnoreCase("Needle in hAyStAcK", "haystack"));
343 try std.testing.expect(startsWithIgnoreCase("boB", "Bo"));
344 try std.testing.expect(!startsWithIgnoreCase("Needle in hAyStAcK", "haystack"));
345345}
346346
347347pub fn endsWithIgnoreCase(haystack: []const u8, needle: []const u8) bool {
......@@ -349,8 +349,8 @@ pub fn endsWithIgnoreCase(haystack: []const u8, needle: []const u8) bool {
349349}
350350
351351test "ascii.endsWithIgnoreCase" {
352 std.testing.expect(endsWithIgnoreCase("Needle in HaYsTaCk", "haystack"));
353 std.testing.expect(!endsWithIgnoreCase("BoB", "Bo"));
352 try std.testing.expect(endsWithIgnoreCase("Needle in HaYsTaCk", "haystack"));
353 try std.testing.expect(!endsWithIgnoreCase("BoB", "Bo"));
354354}
355355
356356/// Finds `substr` in `container`, ignoring case, starting at `start_index`.
......@@ -372,12 +372,12 @@ pub fn indexOfIgnoreCase(container: []const u8, substr: []const u8) ?usize {
372372}
373373
374374test "indexOfIgnoreCase" {
375 std.testing.expect(indexOfIgnoreCase("one Two Three Four", "foUr").? == 14);
376 std.testing.expect(indexOfIgnoreCase("one two three FouR", "gOur") == null);
377 std.testing.expect(indexOfIgnoreCase("foO", "Foo").? == 0);
378 std.testing.expect(indexOfIgnoreCase("foo", "fool") == null);
375 try std.testing.expect(indexOfIgnoreCase("one Two Three Four", "foUr").? == 14);
376 try std.testing.expect(indexOfIgnoreCase("one two three FouR", "gOur") == null);
377 try std.testing.expect(indexOfIgnoreCase("foO", "Foo").? == 0);
378 try std.testing.expect(indexOfIgnoreCase("foo", "fool") == null);
379379
380 std.testing.expect(indexOfIgnoreCase("FOO foo", "fOo").? == 0);
380 try std.testing.expect(indexOfIgnoreCase("FOO foo", "fOo").? == 0);
381381}
382382
383383/// Compares two slices of numbers lexicographically. O(n).
lib/std/atomic/bool.zig+4-4
......@@ -47,9 +47,9 @@ pub const Bool = extern struct {
4747
4848test "std.atomic.Bool" {
4949 var a = Bool.init(false);
50 testing.expectEqual(false, a.xchg(false, .SeqCst));
51 testing.expectEqual(false, a.load(.SeqCst));
50 try testing.expectEqual(false, a.xchg(false, .SeqCst));
51 try testing.expectEqual(false, a.load(.SeqCst));
5252 a.store(true, .SeqCst);
53 testing.expectEqual(true, a.xchg(false, .SeqCst));
54 testing.expectEqual(false, a.load(.SeqCst));
53 try testing.expectEqual(true, a.xchg(false, .SeqCst));
54 try testing.expectEqual(false, a.load(.SeqCst));
5555}
lib/std/atomic/int.zig+6-6
......@@ -81,12 +81,12 @@ pub fn Int(comptime T: type) type {
8181
8282test "std.atomic.Int" {
8383 var a = Int(u8).init(0);
84 testing.expectEqual(@as(u8, 0), a.incr());
85 testing.expectEqual(@as(u8, 1), a.load(.SeqCst));
84 try testing.expectEqual(@as(u8, 0), a.incr());
85 try testing.expectEqual(@as(u8, 1), a.load(.SeqCst));
8686 a.store(42, .SeqCst);
87 testing.expectEqual(@as(u8, 42), a.decr());
88 testing.expectEqual(@as(u8, 41), a.xchg(100));
89 testing.expectEqual(@as(u8, 100), a.fetchAdd(5));
90 testing.expectEqual(@as(u8, 105), a.get());
87 try testing.expectEqual(@as(u8, 42), a.decr());
88 try testing.expectEqual(@as(u8, 41), a.xchg(100));
89 try testing.expectEqual(@as(u8, 100), a.fetchAdd(5));
90 try testing.expectEqual(@as(u8, 105), a.get());
9191 a.set(200);
9292}
lib/std/atomic/queue.zig+28-28
......@@ -195,24 +195,24 @@ test "std.atomic.Queue" {
195195 };
196196
197197 if (builtin.single_threaded) {
198 expect(context.queue.isEmpty());
198 try expect(context.queue.isEmpty());
199199 {
200200 var i: usize = 0;
201201 while (i < put_thread_count) : (i += 1) {
202 expect(startPuts(&context) == 0);
202 try expect(startPuts(&context) == 0);
203203 }
204204 }
205 expect(!context.queue.isEmpty());
205 try expect(!context.queue.isEmpty());
206206 context.puts_done = true;
207207 {
208208 var i: usize = 0;
209209 while (i < put_thread_count) : (i += 1) {
210 expect(startGets(&context) == 0);
210 try expect(startGets(&context) == 0);
211211 }
212212 }
213 expect(context.queue.isEmpty());
213 try expect(context.queue.isEmpty());
214214 } else {
215 expect(context.queue.isEmpty());
215 try expect(context.queue.isEmpty());
216216
217217 var putters: [put_thread_count]*std.Thread = undefined;
218218 for (putters) |*t| {
......@@ -229,7 +229,7 @@ test "std.atomic.Queue" {
229229 for (getters) |t|
230230 t.wait();
231231
232 expect(context.queue.isEmpty());
232 try expect(context.queue.isEmpty());
233233 }
234234
235235 if (context.put_sum != context.get_sum) {
......@@ -279,7 +279,7 @@ fn startGets(ctx: *Context) u8 {
279279
280280test "std.atomic.Queue single-threaded" {
281281 var queue = Queue(i32).init();
282 expect(queue.isEmpty());
282 try expect(queue.isEmpty());
283283
284284 var node_0 = Queue(i32).Node{
285285 .data = 0,
......@@ -287,7 +287,7 @@ test "std.atomic.Queue single-threaded" {
287287 .prev = undefined,
288288 };
289289 queue.put(&node_0);
290 expect(!queue.isEmpty());
290 try expect(!queue.isEmpty());
291291
292292 var node_1 = Queue(i32).Node{
293293 .data = 1,
......@@ -295,10 +295,10 @@ test "std.atomic.Queue single-threaded" {
295295 .prev = undefined,
296296 };
297297 queue.put(&node_1);
298 expect(!queue.isEmpty());
298 try expect(!queue.isEmpty());
299299
300 expect(queue.get().?.data == 0);
301 expect(!queue.isEmpty());
300 try expect(queue.get().?.data == 0);
301 try expect(!queue.isEmpty());
302302
303303 var node_2 = Queue(i32).Node{
304304 .data = 2,
......@@ -306,7 +306,7 @@ test "std.atomic.Queue single-threaded" {
306306 .prev = undefined,
307307 };
308308 queue.put(&node_2);
309 expect(!queue.isEmpty());
309 try expect(!queue.isEmpty());
310310
311311 var node_3 = Queue(i32).Node{
312312 .data = 3,
......@@ -314,13 +314,13 @@ test "std.atomic.Queue single-threaded" {
314314 .prev = undefined,
315315 };
316316 queue.put(&node_3);
317 expect(!queue.isEmpty());
317 try expect(!queue.isEmpty());
318318
319 expect(queue.get().?.data == 1);
320 expect(!queue.isEmpty());
319 try expect(queue.get().?.data == 1);
320 try expect(!queue.isEmpty());
321321
322 expect(queue.get().?.data == 2);
323 expect(!queue.isEmpty());
322 try expect(queue.get().?.data == 2);
323 try expect(!queue.isEmpty());
324324
325325 var node_4 = Queue(i32).Node{
326326 .data = 4,
......@@ -328,17 +328,17 @@ test "std.atomic.Queue single-threaded" {
328328 .prev = undefined,
329329 };
330330 queue.put(&node_4);
331 expect(!queue.isEmpty());
331 try expect(!queue.isEmpty());
332332
333 expect(queue.get().?.data == 3);
333 try expect(queue.get().?.data == 3);
334334 node_3.next = null;
335 expect(!queue.isEmpty());
335 try expect(!queue.isEmpty());
336336
337 expect(queue.get().?.data == 4);
338 expect(queue.isEmpty());
337 try expect(queue.get().?.data == 4);
338 try expect(queue.isEmpty());
339339
340 expect(queue.get() == null);
341 expect(queue.isEmpty());
340 try expect(queue.get() == null);
341 try expect(queue.isEmpty());
342342}
343343
344344test "std.atomic.Queue dump" {
......@@ -352,7 +352,7 @@ test "std.atomic.Queue dump" {
352352 // Test empty stream
353353 fbs.reset();
354354 try queue.dumpToStream(fbs.writer());
355 expect(mem.eql(u8, buffer[0..fbs.pos],
355 try expect(mem.eql(u8, buffer[0..fbs.pos],
356356 \\head: (null)
357357 \\tail: (null)
358358 \\
......@@ -376,7 +376,7 @@ test "std.atomic.Queue dump" {
376376 \\ (null)
377377 \\
378378 , .{ @ptrToInt(queue.head), @ptrToInt(queue.tail) });
379 expect(mem.eql(u8, buffer[0..fbs.pos], expected));
379 try expect(mem.eql(u8, buffer[0..fbs.pos], expected));
380380
381381 // Test a stream with two elements
382382 var node_1 = Queue(i32).Node{
......@@ -397,5 +397,5 @@ test "std.atomic.Queue dump" {
397397 \\ (null)
398398 \\
399399 , .{ @ptrToInt(queue.head), @ptrToInt(queue.head.?.next), @ptrToInt(queue.tail) });
400 expect(mem.eql(u8, buffer[0..fbs.pos], expected));
400 try expect(mem.eql(u8, buffer[0..fbs.pos], expected));
401401}
lib/std/atomic/stack.zig+2-2
......@@ -110,14 +110,14 @@ test "std.atomic.stack" {
110110 {
111111 var i: usize = 0;
112112 while (i < put_thread_count) : (i += 1) {
113 expect(startPuts(&context) == 0);
113 try expect(startPuts(&context) == 0);
114114 }
115115 }
116116 context.puts_done = true;
117117 {
118118 var i: usize = 0;
119119 while (i < put_thread_count) : (i += 1) {
120 expect(startGets(&context) == 0);
120 try expect(startGets(&context) == 0);
121121 }
122122 }
123123 } else {
lib/std/base64.zig+9-9
......@@ -318,14 +318,14 @@ pub const Base64DecoderWithIgnore = struct {
318318
319319test "base64" {
320320 @setEvalBranchQuota(8000);
321 testBase64() catch unreachable;
322 comptime testAllApis(standard, "comptime", "Y29tcHRpbWU=") catch unreachable;
321 try testBase64();
322 comptime try testAllApis(standard, "comptime", "Y29tcHRpbWU=");
323323}
324324
325325test "base64 url_safe_no_pad" {
326326 @setEvalBranchQuota(8000);
327 testBase64UrlSafeNoPad() catch unreachable;
328 comptime testAllApis(url_safe_no_pad, "comptime", "Y29tcHRpbWU") catch unreachable;
327 try testBase64UrlSafeNoPad();
328 comptime try testAllApis(url_safe_no_pad, "comptime", "Y29tcHRpbWU");
329329}
330330
331331fn testBase64() !void {
......@@ -404,7 +404,7 @@ fn testAllApis(codecs: Codecs, expected_decoded: []const u8, expected_encoded: [
404404 {
405405 var buffer: [0x100]u8 = undefined;
406406 const encoded = codecs.Encoder.encode(&buffer, expected_decoded);
407 testing.expectEqualSlices(u8, expected_encoded, encoded);
407 try testing.expectEqualSlices(u8, expected_encoded, encoded);
408408 }
409409
410410 // Base64Decoder
......@@ -412,7 +412,7 @@ fn testAllApis(codecs: Codecs, expected_decoded: []const u8, expected_encoded: [
412412 var buffer: [0x100]u8 = undefined;
413413 var decoded = buffer[0..try codecs.Decoder.calcSizeForSlice(expected_encoded)];
414414 try codecs.Decoder.decode(decoded, expected_encoded);
415 testing.expectEqualSlices(u8, expected_decoded, decoded);
415 try testing.expectEqualSlices(u8, expected_decoded, decoded);
416416 }
417417
418418 // Base64DecoderWithIgnore
......@@ -421,8 +421,8 @@ fn testAllApis(codecs: Codecs, expected_decoded: []const u8, expected_encoded: [
421421 var buffer: [0x100]u8 = undefined;
422422 var decoded = buffer[0..try decoder_ignore_nothing.calcSizeUpperBound(expected_encoded.len)];
423423 var written = try decoder_ignore_nothing.decode(decoded, expected_encoded);
424 testing.expect(written <= decoded.len);
425 testing.expectEqualSlices(u8, expected_decoded, decoded[0..written]);
424 try testing.expect(written <= decoded.len);
425 try testing.expectEqualSlices(u8, expected_decoded, decoded[0..written]);
426426 }
427427}
428428
......@@ -431,7 +431,7 @@ fn testDecodeIgnoreSpace(codecs: Codecs, expected_decoded: []const u8, encoded:
431431 var buffer: [0x100]u8 = undefined;
432432 var decoded = buffer[0..try decoder_ignore_space.calcSizeUpperBound(encoded.len)];
433433 var written = try decoder_ignore_space.decode(decoded, encoded);
434 testing.expectEqualSlices(u8, expected_decoded, decoded[0..written]);
434 try testing.expectEqualSlices(u8, expected_decoded, decoded[0..written]);
435435}
436436
437437fn testError(codecs: Codecs, encoded: []const u8, expected_err: anyerror) !void {
lib/std/bit_set.zig+89-89
......@@ -998,9 +998,9 @@ fn BitSetIterator(comptime MaskInt: type, comptime options: IteratorOptions) typ
998998
999999const testing = std.testing;
10001000
1001fn testBitSet(a: anytype, b: anytype, len: usize) void {
1002 testing.expectEqual(len, a.capacity());
1003 testing.expectEqual(len, b.capacity());
1001fn testBitSet(a: anytype, b: anytype, len: usize) !void {
1002 try testing.expectEqual(len, a.capacity());
1003 try testing.expectEqual(len, b.capacity());
10041004
10051005 {
10061006 var i: usize = 0;
......@@ -1010,50 +1010,50 @@ fn testBitSet(a: anytype, b: anytype, len: usize) void {
10101010 }
10111011 }
10121012
1013 testing.expectEqual((len + 1) / 2, a.count());
1014 testing.expectEqual((len + 3) / 4 + (len + 2) / 4, b.count());
1013 try testing.expectEqual((len + 1) / 2, a.count());
1014 try testing.expectEqual((len + 3) / 4 + (len + 2) / 4, b.count());
10151015
10161016 {
10171017 var iter = a.iterator(.{});
10181018 var i: usize = 0;
10191019 while (i < len) : (i += 2) {
1020 testing.expectEqual(@as(?usize, i), iter.next());
1020 try testing.expectEqual(@as(?usize, i), iter.next());
10211021 }
1022 testing.expectEqual(@as(?usize, null), iter.next());
1023 testing.expectEqual(@as(?usize, null), iter.next());
1024 testing.expectEqual(@as(?usize, null), iter.next());
1022 try testing.expectEqual(@as(?usize, null), iter.next());
1023 try testing.expectEqual(@as(?usize, null), iter.next());
1024 try testing.expectEqual(@as(?usize, null), iter.next());
10251025 }
10261026 a.toggleAll();
10271027 {
10281028 var iter = a.iterator(.{});
10291029 var i: usize = 1;
10301030 while (i < len) : (i += 2) {
1031 testing.expectEqual(@as(?usize, i), iter.next());
1031 try testing.expectEqual(@as(?usize, i), iter.next());
10321032 }
1033 testing.expectEqual(@as(?usize, null), iter.next());
1034 testing.expectEqual(@as(?usize, null), iter.next());
1035 testing.expectEqual(@as(?usize, null), iter.next());
1033 try testing.expectEqual(@as(?usize, null), iter.next());
1034 try testing.expectEqual(@as(?usize, null), iter.next());
1035 try testing.expectEqual(@as(?usize, null), iter.next());
10361036 }
10371037
10381038 {
10391039 var iter = b.iterator(.{ .kind = .unset });
10401040 var i: usize = 2;
10411041 while (i < len) : (i += 4) {
1042 testing.expectEqual(@as(?usize, i), iter.next());
1042 try testing.expectEqual(@as(?usize, i), iter.next());
10431043 if (i + 1 < len) {
1044 testing.expectEqual(@as(?usize, i + 1), iter.next());
1044 try testing.expectEqual(@as(?usize, i + 1), iter.next());
10451045 }
10461046 }
1047 testing.expectEqual(@as(?usize, null), iter.next());
1048 testing.expectEqual(@as(?usize, null), iter.next());
1049 testing.expectEqual(@as(?usize, null), iter.next());
1047 try testing.expectEqual(@as(?usize, null), iter.next());
1048 try testing.expectEqual(@as(?usize, null), iter.next());
1049 try testing.expectEqual(@as(?usize, null), iter.next());
10501050 }
10511051
10521052 {
10531053 var i: usize = 0;
10541054 while (i < len) : (i += 1) {
1055 testing.expectEqual(i & 1 != 0, a.isSet(i));
1056 testing.expectEqual(i & 2 == 0, b.isSet(i));
1055 try testing.expectEqual(i & 1 != 0, a.isSet(i));
1056 try testing.expectEqual(i & 2 == 0, b.isSet(i));
10571057 }
10581058 }
10591059
......@@ -1061,8 +1061,8 @@ fn testBitSet(a: anytype, b: anytype, len: usize) void {
10611061 {
10621062 var i: usize = 0;
10631063 while (i < len) : (i += 1) {
1064 testing.expectEqual(i & 1 != 0 or i & 2 == 0, a.isSet(i));
1065 testing.expectEqual(i & 2 == 0, b.isSet(i));
1064 try testing.expectEqual(i & 1 != 0 or i & 2 == 0, a.isSet(i));
1065 try testing.expectEqual(i & 2 == 0, b.isSet(i));
10661066 }
10671067
10681068 i = len;
......@@ -1071,27 +1071,27 @@ fn testBitSet(a: anytype, b: anytype, len: usize) void {
10711071 while (i > 0) {
10721072 i -= 1;
10731073 if (i & 1 != 0 or i & 2 == 0) {
1074 testing.expectEqual(@as(?usize, i), set.next());
1074 try testing.expectEqual(@as(?usize, i), set.next());
10751075 } else {
1076 testing.expectEqual(@as(?usize, i), unset.next());
1076 try testing.expectEqual(@as(?usize, i), unset.next());
10771077 }
10781078 }
1079 testing.expectEqual(@as(?usize, null), set.next());
1080 testing.expectEqual(@as(?usize, null), set.next());
1081 testing.expectEqual(@as(?usize, null), set.next());
1082 testing.expectEqual(@as(?usize, null), unset.next());
1083 testing.expectEqual(@as(?usize, null), unset.next());
1084 testing.expectEqual(@as(?usize, null), unset.next());
1079 try testing.expectEqual(@as(?usize, null), set.next());
1080 try testing.expectEqual(@as(?usize, null), set.next());
1081 try testing.expectEqual(@as(?usize, null), set.next());
1082 try testing.expectEqual(@as(?usize, null), unset.next());
1083 try testing.expectEqual(@as(?usize, null), unset.next());
1084 try testing.expectEqual(@as(?usize, null), unset.next());
10851085 }
10861086
10871087 a.toggleSet(b.*);
10881088 {
1089 testing.expectEqual(len / 4, a.count());
1089 try testing.expectEqual(len / 4, a.count());
10901090
10911091 var i: usize = 0;
10921092 while (i < len) : (i += 1) {
1093 testing.expectEqual(i & 1 != 0 and i & 2 != 0, a.isSet(i));
1094 testing.expectEqual(i & 2 == 0, b.isSet(i));
1093 try testing.expectEqual(i & 1 != 0 and i & 2 != 0, a.isSet(i));
1094 try testing.expectEqual(i & 2 == 0, b.isSet(i));
10951095 if (i & 1 == 0) {
10961096 a.set(i);
10971097 } else {
......@@ -1102,29 +1102,29 @@ fn testBitSet(a: anytype, b: anytype, len: usize) void {
11021102
11031103 a.setIntersection(b.*);
11041104 {
1105 testing.expectEqual((len + 3) / 4, a.count());
1105 try testing.expectEqual((len + 3) / 4, a.count());
11061106
11071107 var i: usize = 0;
11081108 while (i < len) : (i += 1) {
1109 testing.expectEqual(i & 1 == 0 and i & 2 == 0, a.isSet(i));
1110 testing.expectEqual(i & 2 == 0, b.isSet(i));
1109 try testing.expectEqual(i & 1 == 0 and i & 2 == 0, a.isSet(i));
1110 try testing.expectEqual(i & 2 == 0, b.isSet(i));
11111111 }
11121112 }
11131113
11141114 a.toggleSet(a.*);
11151115 {
11161116 var iter = a.iterator(.{});
1117 testing.expectEqual(@as(?usize, null), iter.next());
1118 testing.expectEqual(@as(?usize, null), iter.next());
1119 testing.expectEqual(@as(?usize, null), iter.next());
1120 testing.expectEqual(@as(usize, 0), a.count());
1117 try testing.expectEqual(@as(?usize, null), iter.next());
1118 try testing.expectEqual(@as(?usize, null), iter.next());
1119 try testing.expectEqual(@as(?usize, null), iter.next());
1120 try testing.expectEqual(@as(usize, 0), a.count());
11211121 }
11221122 {
11231123 var iter = a.iterator(.{ .direction = .reverse });
1124 testing.expectEqual(@as(?usize, null), iter.next());
1125 testing.expectEqual(@as(?usize, null), iter.next());
1126 testing.expectEqual(@as(?usize, null), iter.next());
1127 testing.expectEqual(@as(usize, 0), a.count());
1124 try testing.expectEqual(@as(?usize, null), iter.next());
1125 try testing.expectEqual(@as(?usize, null), iter.next());
1126 try testing.expectEqual(@as(?usize, null), iter.next());
1127 try testing.expectEqual(@as(usize, 0), a.count());
11281128 }
11291129
11301130 const test_bits = [_]usize{
......@@ -1139,51 +1139,51 @@ fn testBitSet(a: anytype, b: anytype, len: usize) void {
11391139
11401140 for (test_bits) |i| {
11411141 if (i < a.capacity()) {
1142 testing.expectEqual(@as(?usize, i), a.findFirstSet());
1143 testing.expectEqual(@as(?usize, i), a.toggleFirstSet());
1142 try testing.expectEqual(@as(?usize, i), a.findFirstSet());
1143 try testing.expectEqual(@as(?usize, i), a.toggleFirstSet());
11441144 }
11451145 }
1146 testing.expectEqual(@as(?usize, null), a.findFirstSet());
1147 testing.expectEqual(@as(?usize, null), a.toggleFirstSet());
1148 testing.expectEqual(@as(?usize, null), a.findFirstSet());
1149 testing.expectEqual(@as(?usize, null), a.toggleFirstSet());
1150 testing.expectEqual(@as(usize, 0), a.count());
1146 try testing.expectEqual(@as(?usize, null), a.findFirstSet());
1147 try testing.expectEqual(@as(?usize, null), a.toggleFirstSet());
1148 try testing.expectEqual(@as(?usize, null), a.findFirstSet());
1149 try testing.expectEqual(@as(?usize, null), a.toggleFirstSet());
1150 try testing.expectEqual(@as(usize, 0), a.count());
11511151}
11521152
1153fn testStaticBitSet(comptime Set: type) void {
1153fn testStaticBitSet(comptime Set: type) !void {
11541154 var a = Set.initEmpty();
11551155 var b = Set.initFull();
1156 testing.expectEqual(@as(usize, 0), a.count());
1157 testing.expectEqual(@as(usize, Set.bit_length), b.count());
1156 try testing.expectEqual(@as(usize, 0), a.count());
1157 try testing.expectEqual(@as(usize, Set.bit_length), b.count());
11581158
1159 testBitSet(&a, &b, Set.bit_length);
1159 try testBitSet(&a, &b, Set.bit_length);
11601160}
11611161
11621162test "IntegerBitSet" {
1163 testStaticBitSet(IntegerBitSet(0));
1164 testStaticBitSet(IntegerBitSet(1));
1165 testStaticBitSet(IntegerBitSet(2));
1166 testStaticBitSet(IntegerBitSet(5));
1167 testStaticBitSet(IntegerBitSet(8));
1168 testStaticBitSet(IntegerBitSet(32));
1169 testStaticBitSet(IntegerBitSet(64));
1170 testStaticBitSet(IntegerBitSet(127));
1163 try testStaticBitSet(IntegerBitSet(0));
1164 try testStaticBitSet(IntegerBitSet(1));
1165 try testStaticBitSet(IntegerBitSet(2));
1166 try testStaticBitSet(IntegerBitSet(5));
1167 try testStaticBitSet(IntegerBitSet(8));
1168 try testStaticBitSet(IntegerBitSet(32));
1169 try testStaticBitSet(IntegerBitSet(64));
1170 try testStaticBitSet(IntegerBitSet(127));
11711171}
11721172
11731173test "ArrayBitSet" {
11741174 inline for (.{ 0, 1, 2, 31, 32, 33, 63, 64, 65, 254, 500, 3000 }) |size| {
1175 testStaticBitSet(ArrayBitSet(u8, size));
1176 testStaticBitSet(ArrayBitSet(u16, size));
1177 testStaticBitSet(ArrayBitSet(u32, size));
1178 testStaticBitSet(ArrayBitSet(u64, size));
1179 testStaticBitSet(ArrayBitSet(u128, size));
1175 try testStaticBitSet(ArrayBitSet(u8, size));
1176 try testStaticBitSet(ArrayBitSet(u16, size));
1177 try testStaticBitSet(ArrayBitSet(u32, size));
1178 try testStaticBitSet(ArrayBitSet(u64, size));
1179 try testStaticBitSet(ArrayBitSet(u128, size));
11801180 }
11811181}
11821182
11831183test "DynamicBitSetUnmanaged" {
11841184 const allocator = std.testing.allocator;
11851185 var a = try DynamicBitSetUnmanaged.initEmpty(300, allocator);
1186 testing.expectEqual(@as(usize, 0), a.count());
1186 try testing.expectEqual(@as(usize, 0), a.count());
11871187 a.deinit(allocator);
11881188
11891189 a = try DynamicBitSetUnmanaged.initEmpty(0, allocator);
......@@ -1193,10 +1193,10 @@ test "DynamicBitSetUnmanaged" {
11931193
11941194 var tmp = try a.clone(allocator);
11951195 defer tmp.deinit(allocator);
1196 testing.expectEqual(old_len, tmp.capacity());
1196 try testing.expectEqual(old_len, tmp.capacity());
11971197 var i: usize = 0;
11981198 while (i < old_len) : (i += 1) {
1199 testing.expectEqual(a.isSet(i), tmp.isSet(i));
1199 try testing.expectEqual(a.isSet(i), tmp.isSet(i));
12001200 }
12011201
12021202 a.toggleSet(a); // zero a
......@@ -1206,24 +1206,24 @@ test "DynamicBitSetUnmanaged" {
12061206 try tmp.resize(size, false, allocator);
12071207
12081208 if (size > old_len) {
1209 testing.expectEqual(size - old_len, a.count());
1209 try testing.expectEqual(size - old_len, a.count());
12101210 } else {
1211 testing.expectEqual(@as(usize, 0), a.count());
1211 try testing.expectEqual(@as(usize, 0), a.count());
12121212 }
1213 testing.expectEqual(@as(usize, 0), tmp.count());
1213 try testing.expectEqual(@as(usize, 0), tmp.count());
12141214
12151215 var b = try DynamicBitSetUnmanaged.initFull(size, allocator);
12161216 defer b.deinit(allocator);
1217 testing.expectEqual(@as(usize, size), b.count());
1217 try testing.expectEqual(@as(usize, size), b.count());
12181218
1219 testBitSet(&a, &b, size);
1219 try testBitSet(&a, &b, size);
12201220 }
12211221}
12221222
12231223test "DynamicBitSet" {
12241224 const allocator = std.testing.allocator;
12251225 var a = try DynamicBitSet.initEmpty(300, allocator);
1226 testing.expectEqual(@as(usize, 0), a.count());
1226 try testing.expectEqual(@as(usize, 0), a.count());
12271227 a.deinit();
12281228
12291229 a = try DynamicBitSet.initEmpty(0, allocator);
......@@ -1233,10 +1233,10 @@ test "DynamicBitSet" {
12331233
12341234 var tmp = try a.clone(allocator);
12351235 defer tmp.deinit();
1236 testing.expectEqual(old_len, tmp.capacity());
1236 try testing.expectEqual(old_len, tmp.capacity());
12371237 var i: usize = 0;
12381238 while (i < old_len) : (i += 1) {
1239 testing.expectEqual(a.isSet(i), tmp.isSet(i));
1239 try testing.expectEqual(a.isSet(i), tmp.isSet(i));
12401240 }
12411241
12421242 a.toggleSet(a); // zero a
......@@ -1246,24 +1246,24 @@ test "DynamicBitSet" {
12461246 try tmp.resize(size, false);
12471247
12481248 if (size > old_len) {
1249 testing.expectEqual(size - old_len, a.count());
1249 try testing.expectEqual(size - old_len, a.count());
12501250 } else {
1251 testing.expectEqual(@as(usize, 0), a.count());
1251 try testing.expectEqual(@as(usize, 0), a.count());
12521252 }
1253 testing.expectEqual(@as(usize, 0), tmp.count());
1253 try testing.expectEqual(@as(usize, 0), tmp.count());
12541254
12551255 var b = try DynamicBitSet.initFull(size, allocator);
12561256 defer b.deinit();
1257 testing.expectEqual(@as(usize, size), b.count());
1257 try testing.expectEqual(@as(usize, size), b.count());
12581258
1259 testBitSet(&a, &b, size);
1259 try testBitSet(&a, &b, size);
12601260 }
12611261}
12621262
12631263test "StaticBitSet" {
1264 testing.expectEqual(IntegerBitSet(0), StaticBitSet(0));
1265 testing.expectEqual(IntegerBitSet(5), StaticBitSet(5));
1266 testing.expectEqual(IntegerBitSet(@bitSizeOf(usize)), StaticBitSet(@bitSizeOf(usize)));
1267 testing.expectEqual(ArrayBitSet(usize, @bitSizeOf(usize) + 1), StaticBitSet(@bitSizeOf(usize) + 1));
1268 testing.expectEqual(ArrayBitSet(usize, 500), StaticBitSet(500));
1264 try testing.expectEqual(IntegerBitSet(0), StaticBitSet(0));
1265 try testing.expectEqual(IntegerBitSet(5), StaticBitSet(5));
1266 try testing.expectEqual(IntegerBitSet(@bitSizeOf(usize)), StaticBitSet(@bitSizeOf(usize)));
1267 try testing.expectEqual(ArrayBitSet(usize, @bitSizeOf(usize) + 1), StaticBitSet(@bitSizeOf(usize) + 1));
1268 try testing.expectEqual(ArrayBitSet(usize, 500), StaticBitSet(500));
12691269}
lib/std/buf_map.zig+7-7
......@@ -94,19 +94,19 @@ test "BufMap" {
9494 defer bufmap.deinit();
9595
9696 try bufmap.set("x", "1");
97 testing.expect(mem.eql(u8, bufmap.get("x").?, "1"));
98 testing.expect(1 == bufmap.count());
97 try testing.expect(mem.eql(u8, bufmap.get("x").?, "1"));
98 try testing.expect(1 == bufmap.count());
9999
100100 try bufmap.set("x", "2");
101 testing.expect(mem.eql(u8, bufmap.get("x").?, "2"));
102 testing.expect(1 == bufmap.count());
101 try testing.expect(mem.eql(u8, bufmap.get("x").?, "2"));
102 try testing.expect(1 == bufmap.count());
103103
104104 try bufmap.set("x", "3");
105 testing.expect(mem.eql(u8, bufmap.get("x").?, "3"));
106 testing.expect(1 == bufmap.count());
105 try testing.expect(mem.eql(u8, bufmap.get("x").?, "3"));
106 try testing.expect(1 == bufmap.count());
107107
108108 bufmap.delete("x");
109 testing.expect(0 == bufmap.count());
109 try testing.expect(0 == bufmap.count());
110110
111111 try bufmap.setMove(try allocator.dupe(u8, "k"), try allocator.dupe(u8, "v1"));
112112 try bufmap.setMove(try allocator.dupe(u8, "k"), try allocator.dupe(u8, "v2"));
lib/std/buf_set.zig+2-2
......@@ -73,9 +73,9 @@ test "BufSet" {
7373 defer bufset.deinit();
7474
7575 try bufset.put("x");
76 testing.expect(bufset.count() == 1);
76 try testing.expect(bufset.count() == 1);
7777 bufset.delete("x");
78 testing.expect(bufset.count() == 0);
78 try testing.expect(bufset.count() == 0);
7979
8080 try bufset.put("x");
8181 try bufset.put("y");
lib/std/build.zig+11-11
......@@ -3060,19 +3060,19 @@ test "Builder.dupePkg()" {
30603060 const dupe_deps = dupe.dependencies.?;
30613061
30623062 // probably the same top level package details
3063 std.testing.expectEqualStrings(pkg_top.name, dupe.name);
3063 try std.testing.expectEqualStrings(pkg_top.name, dupe.name);
30643064
30653065 // probably the same dependencies
3066 std.testing.expectEqual(original_deps.len, dupe_deps.len);
3067 std.testing.expectEqual(original_deps[0].name, pkg_dep.name);
3066 try std.testing.expectEqual(original_deps.len, dupe_deps.len);
3067 try std.testing.expectEqual(original_deps[0].name, pkg_dep.name);
30683068
30693069 // could segfault otherwise if pointers in duplicated package's fields are
30703070 // the same as those in stack allocated package's fields
3071 std.testing.expect(dupe_deps.ptr != original_deps.ptr);
3072 std.testing.expect(dupe.name.ptr != pkg_top.name.ptr);
3073 std.testing.expect(dupe.path.ptr != pkg_top.path.ptr);
3074 std.testing.expect(dupe_deps[0].name.ptr != pkg_dep.name.ptr);
3075 std.testing.expect(dupe_deps[0].path.ptr != pkg_dep.path.ptr);
3071 try std.testing.expect(dupe_deps.ptr != original_deps.ptr);
3072 try std.testing.expect(dupe.name.ptr != pkg_top.name.ptr);
3073 try std.testing.expect(dupe.path.ptr != pkg_top.path.ptr);
3074 try std.testing.expect(dupe_deps[0].name.ptr != pkg_dep.name.ptr);
3075 try std.testing.expect(dupe_deps[0].path.ptr != pkg_dep.path.ptr);
30763076}
30773077
30783078test "LibExeObjStep.addBuildOption" {
......@@ -3096,7 +3096,7 @@ test "LibExeObjStep.addBuildOption" {
30963096 exe.addBuildOption(?[]const u8, "optional_string", null);
30973097 exe.addBuildOption(std.SemanticVersion, "semantic_version", try std.SemanticVersion.parse("0.1.2-foo+bar"));
30983098
3099 std.testing.expectEqualStrings(
3099 try std.testing.expectEqualStrings(
31003100 \\pub const option1: usize = 1;
31013101 \\pub const option2: ?usize = null;
31023102 \\pub const string: []const u8 = "zigisthebest";
......@@ -3140,10 +3140,10 @@ test "LibExeObjStep.addPackage" {
31403140 var exe = builder.addExecutable("not_an_executable", "/not/an/executable.zig");
31413141 exe.addPackage(pkg_top);
31423142
3143 std.testing.expectEqual(@as(usize, 1), exe.packages.items.len);
3143 try std.testing.expectEqual(@as(usize, 1), exe.packages.items.len);
31443144
31453145 const dupe = exe.packages.items[0];
3146 std.testing.expectEqualStrings(pkg_top.name, dupe.name);
3146 try std.testing.expectEqualStrings(pkg_top.name, dupe.name);
31473147}
31483148
31493149test {
lib/std/builtin.zig+1-1
......@@ -547,7 +547,7 @@ pub fn testVersionParse() !void {
547547 const f = struct {
548548 fn eql(text: []const u8, v1: u32, v2: u32, v3: u32) !void {
549549 const v = try Version.parse(text);
550 std.testing.expect(v.major == v1 and v.minor == v2 and v.patch == v3);
550 try std.testing.expect(v.major == v1 and v.minor == v2 and v.patch == v3);
551551 }
552552
553553 fn err(text: []const u8, expected_err: anyerror) !void {
lib/std/c/tokenizer.zig+8-8
......@@ -1310,7 +1310,7 @@ pub const Tokenizer = struct {
13101310};
13111311
13121312test "operators" {
1313 expectTokens(
1313 try expectTokens(
13141314 \\ ! != | || |= = ==
13151315 \\ ( ) { } [ ] . .. ...
13161316 \\ ^ ^= + ++ += - -- -=
......@@ -1379,7 +1379,7 @@ test "operators" {
13791379}
13801380
13811381test "keywords" {
1382 expectTokens(
1382 try expectTokens(
13831383 \\auto break case char const continue default do
13841384 \\double else enum extern float for goto if int
13851385 \\long register return short signed sizeof static
......@@ -1442,7 +1442,7 @@ test "keywords" {
14421442}
14431443
14441444test "preprocessor keywords" {
1445 expectTokens(
1445 try expectTokens(
14461446 \\#include <test>
14471447 \\#define #include <1
14481448 \\#ifdef
......@@ -1478,7 +1478,7 @@ test "preprocessor keywords" {
14781478}
14791479
14801480test "line continuation" {
1481 expectTokens(
1481 try expectTokens(
14821482 \\#define foo \
14831483 \\ bar
14841484 \\"foo\
......@@ -1509,7 +1509,7 @@ test "line continuation" {
15091509}
15101510
15111511test "string prefix" {
1512 expectTokens(
1512 try expectTokens(
15131513 \\"foo"
15141514 \\u"foo"
15151515 \\u8"foo"
......@@ -1543,7 +1543,7 @@ test "string prefix" {
15431543}
15441544
15451545test "num suffixes" {
1546 expectTokens(
1546 try expectTokens(
15471547 \\ 1.0f 1.0L 1.0 .0 1.
15481548 \\ 0l 0lu 0ll 0llu 0
15491549 \\ 1u 1ul 1ull 1
......@@ -1573,7 +1573,7 @@ test "num suffixes" {
15731573 });
15741574}
15751575
1576fn expectTokens(source: []const u8, expected_tokens: []const Token.Id) void {
1576fn expectTokens(source: []const u8, expected_tokens: []const Token.Id) !void {
15771577 var tokenizer = Tokenizer{
15781578 .buffer = source,
15791579 };
......@@ -1584,5 +1584,5 @@ fn expectTokens(source: []const u8, expected_tokens: []const Token.Id) void {
15841584 }
15851585 }
15861586 const last_token = tokenizer.next();
1587 std.testing.expect(last_token.id == .Eof);
1587 try std.testing.expect(last_token.id == .Eof);
15881588}
lib/std/child_process.zig+2-2
......@@ -1005,7 +1005,7 @@ test "createNullDelimitedEnvMap" {
10051005 defer arena.deinit();
10061006 const environ = try createNullDelimitedEnvMap(&arena.allocator, &envmap);
10071007
1008 testing.expectEqual(@as(usize, 5), environ.len);
1008 try testing.expectEqual(@as(usize, 5), environ.len);
10091009
10101010 inline for (.{
10111011 "HOME=/home/ifreund",
......@@ -1017,7 +1017,7 @@ test "createNullDelimitedEnvMap" {
10171017 for (environ) |variable| {
10181018 if (mem.eql(u8, mem.span(variable orelse continue), target)) break;
10191019 } else {
1020 testing.expect(false); // Environment variable not found
1020 try testing.expect(false); // Environment variable not found
10211021 }
10221022 }
10231023}
lib/std/compress/deflate.zig+1-1
......@@ -669,5 +669,5 @@ test "lengths overflow" {
669669 var inflate = inflateStream(reader, &window);
670670
671671 var buf: [1]u8 = undefined;
672 std.testing.expectError(error.InvalidLength, inflate.read(&buf));
672 try std.testing.expectError(error.InvalidLength, inflate.read(&buf));
673673}
lib/std/compress/gzip.zig+9-9
......@@ -172,17 +172,17 @@ fn testReader(data: []const u8, comptime expected: []const u8) !void {
172172 var hash: [32]u8 = undefined;
173173 std.crypto.hash.sha2.Sha256.hash(buf, hash[0..], .{});
174174
175 assertEqual(expected, &hash);
175 try assertEqual(expected, &hash);
176176}
177177
178178// Assert `expected` == `input` where `input` is a bytestring.
179pub fn assertEqual(comptime expected: []const u8, input: []const u8) void {
179pub fn assertEqual(comptime expected: []const u8, input: []const u8) !void {
180180 var expected_bytes: [expected.len / 2]u8 = undefined;
181181 for (expected_bytes) |*r, i| {
182182 r.* = std.fmt.parseInt(u8, expected[2 * i .. 2 * i + 2], 16) catch unreachable;
183183 }
184184
185 testing.expectEqualSlices(u8, &expected_bytes, input);
185 try testing.expectEqualSlices(u8, &expected_bytes, input);
186186}
187187
188188// All the test cases are obtained by compressing the RFC1952 text
......@@ -198,12 +198,12 @@ test "compressed data" {
198198
199199test "sanity checks" {
200200 // Truncated header
201 testing.expectError(
201 try testing.expectError(
202202 error.EndOfStream,
203203 testReader(&[_]u8{ 0x1f, 0x8B }, ""),
204204 );
205205 // Wrong CM
206 testing.expectError(
206 try testing.expectError(
207207 error.InvalidCompression,
208208 testReader(&[_]u8{
209209 0x1f, 0x8b, 0x09, 0x00, 0x00, 0x00, 0x00, 0x00,
......@@ -211,7 +211,7 @@ test "sanity checks" {
211211 }, ""),
212212 );
213213 // Wrong checksum
214 testing.expectError(
214 try testing.expectError(
215215 error.WrongChecksum,
216216 testReader(&[_]u8{
217217 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00,
......@@ -220,7 +220,7 @@ test "sanity checks" {
220220 }, ""),
221221 );
222222 // Truncated checksum
223 testing.expectError(
223 try testing.expectError(
224224 error.EndOfStream,
225225 testReader(&[_]u8{
226226 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00,
......@@ -228,7 +228,7 @@ test "sanity checks" {
228228 }, ""),
229229 );
230230 // Wrong initial size
231 testing.expectError(
231 try testing.expectError(
232232 error.CorruptedData,
233233 testReader(&[_]u8{
234234 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00,
......@@ -237,7 +237,7 @@ test "sanity checks" {
237237 }, ""),
238238 );
239239 // Truncated initial size field
240 testing.expectError(
240 try testing.expectError(
241241 error.EndOfStream,
242242 testReader(&[_]u8{
243243 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00,
lib/std/compress/zlib.zig+9-9
......@@ -109,17 +109,17 @@ fn testReader(data: []const u8, comptime expected: []const u8) !void {
109109 var hash: [32]u8 = undefined;
110110 std.crypto.hash.sha2.Sha256.hash(buf, hash[0..], .{});
111111
112 assertEqual(expected, &hash);
112 try assertEqual(expected, &hash);
113113}
114114
115115// Assert `expected` == `input` where `input` is a bytestring.
116pub fn assertEqual(comptime expected: []const u8, input: []const u8) void {
116pub fn assertEqual(comptime expected: []const u8, input: []const u8) !void {
117117 var expected_bytes: [expected.len / 2]u8 = undefined;
118118 for (expected_bytes) |*r, i| {
119119 r.* = std.fmt.parseInt(u8, expected[2 * i .. 2 * i + 2], 16) catch unreachable;
120120 }
121121
122 testing.expectEqualSlices(u8, &expected_bytes, input);
122 try testing.expectEqualSlices(u8, &expected_bytes, input);
123123}
124124
125125// All the test cases are obtained by compressing the RFC1950 text
......@@ -159,32 +159,32 @@ test "don't read past deflate stream's end" {
159159
160160test "sanity checks" {
161161 // Truncated header
162 testing.expectError(
162 try testing.expectError(
163163 error.EndOfStream,
164164 testReader(&[_]u8{0x78}, ""),
165165 );
166166 // Failed FCHECK check
167 testing.expectError(
167 try testing.expectError(
168168 error.BadHeader,
169169 testReader(&[_]u8{ 0x78, 0x9D }, ""),
170170 );
171171 // Wrong CM
172 testing.expectError(
172 try testing.expectError(
173173 error.InvalidCompression,
174174 testReader(&[_]u8{ 0x79, 0x94 }, ""),
175175 );
176176 // Wrong CINFO
177 testing.expectError(
177 try testing.expectError(
178178 error.InvalidWindowSize,
179179 testReader(&[_]u8{ 0x88, 0x98 }, ""),
180180 );
181181 // Wrong checksum
182 testing.expectError(
182 try testing.expectError(
183183 error.WrongChecksum,
184184 testReader(&[_]u8{ 0x78, 0xda, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00 }, ""),
185185 );
186186 // Truncated checksum
187 testing.expectError(
187 try testing.expectError(
188188 error.EndOfStream,
189189 testReader(&[_]u8{ 0x78, 0xda, 0x03, 0x00, 0x00 }, ""),
190190 );
lib/std/comptime_string_map.zig+21-21
......@@ -95,7 +95,7 @@ test "ComptimeStringMap list literal of list literals" {
9595 .{ "samelen", .E },
9696 });
9797
98 testMap(map);
98 try testMap(map);
9999}
100100
101101test "ComptimeStringMap array of structs" {
......@@ -111,7 +111,7 @@ test "ComptimeStringMap array of structs" {
111111 .{ .@"0" = "samelen", .@"1" = .E },
112112 });
113113
114 testMap(map);
114 try testMap(map);
115115}
116116
117117test "ComptimeStringMap slice of structs" {
......@@ -128,18 +128,18 @@ test "ComptimeStringMap slice of structs" {
128128 };
129129 const map = ComptimeStringMap(TestEnum, slice);
130130
131 testMap(map);
131 try testMap(map);
132132}
133133
134fn testMap(comptime map: anytype) void {
135 std.testing.expectEqual(TestEnum.A, map.get("have").?);
136 std.testing.expectEqual(TestEnum.B, map.get("nothing").?);
137 std.testing.expect(null == map.get("missing"));
138 std.testing.expectEqual(TestEnum.D, map.get("these").?);
139 std.testing.expectEqual(TestEnum.E, map.get("samelen").?);
134fn testMap(comptime map: anytype) !void {
135 try std.testing.expectEqual(TestEnum.A, map.get("have").?);
136 try std.testing.expectEqual(TestEnum.B, map.get("nothing").?);
137 try std.testing.expect(null == map.get("missing"));
138 try std.testing.expectEqual(TestEnum.D, map.get("these").?);
139 try std.testing.expectEqual(TestEnum.E, map.get("samelen").?);
140140
141 std.testing.expect(!map.has("missing"));
142 std.testing.expect(map.has("these"));
141 try std.testing.expect(!map.has("missing"));
142 try std.testing.expect(map.has("these"));
143143}
144144
145145test "ComptimeStringMap void value type, slice of structs" {
......@@ -155,7 +155,7 @@ test "ComptimeStringMap void value type, slice of structs" {
155155 };
156156 const map = ComptimeStringMap(void, slice);
157157
158 testSet(map);
158 try testSet(map);
159159}
160160
161161test "ComptimeStringMap void value type, list literal of list literals" {
......@@ -167,16 +167,16 @@ test "ComptimeStringMap void value type, list literal of list literals" {
167167 .{"samelen"},
168168 });
169169
170 testSet(map);
170 try testSet(map);
171171}
172172
173fn testSet(comptime map: anytype) void {
174 std.testing.expectEqual({}, map.get("have").?);
175 std.testing.expectEqual({}, map.get("nothing").?);
176 std.testing.expect(null == map.get("missing"));
177 std.testing.expectEqual({}, map.get("these").?);
178 std.testing.expectEqual({}, map.get("samelen").?);
173fn testSet(comptime map: anytype) !void {
174 try std.testing.expectEqual({}, map.get("have").?);
175 try std.testing.expectEqual({}, map.get("nothing").?);
176 try std.testing.expect(null == map.get("missing"));
177 try std.testing.expectEqual({}, map.get("these").?);
178 try std.testing.expectEqual({}, map.get("samelen").?);
179179
180 std.testing.expect(!map.has("missing"));
181 std.testing.expect(map.has("these"));
180 try std.testing.expect(!map.has("missing"));
181 try std.testing.expect(map.has("these"));
182182}
lib/std/crypto.zig+2-2
......@@ -188,7 +188,7 @@ test "CSPRNG" {
188188 const a = random.int(u64);
189189 const b = random.int(u64);
190190 const c = random.int(u64);
191 std.testing.expect(a ^ b ^ c != 0);
191 try std.testing.expect(a ^ b ^ c != 0);
192192}
193193
194194test "issue #4532: no index out of bounds" {
......@@ -226,6 +226,6 @@ test "issue #4532: no index out of bounds" {
226226 h.update(block[1..]);
227227 h.final(&out2);
228228
229 std.testing.expectEqual(out1, out2);
229 try std.testing.expectEqual(out1, out2);
230230 }
231231}
lib/std/crypto/25519/curve25519.zig+6-6
......@@ -120,13 +120,13 @@ test "curve25519" {
120120 const p = try Curve25519.basePoint.clampedMul(s);
121121 try p.rejectIdentity();
122122 var buf: [128]u8 = undefined;
123 std.testing.expectEqualStrings(try std.fmt.bufPrint(&buf, "{s}", .{std.fmt.fmtSliceHexUpper(&p.toBytes())}), "E6F2A4D1C28EE5C7AD0329268255A468AD407D2672824C0C0EB30EA6EF450145");
123 try std.testing.expectEqualStrings(try std.fmt.bufPrint(&buf, "{s}", .{std.fmt.fmtSliceHexUpper(&p.toBytes())}), "E6F2A4D1C28EE5C7AD0329268255A468AD407D2672824C0C0EB30EA6EF450145");
124124 const q = try p.clampedMul(s);
125 std.testing.expectEqualStrings(try std.fmt.bufPrint(&buf, "{s}", .{std.fmt.fmtSliceHexUpper(&q.toBytes())}), "3614E119FFE55EC55B87D6B19971A9F4CBC78EFE80BEC55B96392BABCC712537");
125 try std.testing.expectEqualStrings(try std.fmt.bufPrint(&buf, "{s}", .{std.fmt.fmtSliceHexUpper(&q.toBytes())}), "3614E119FFE55EC55B87D6B19971A9F4CBC78EFE80BEC55B96392BABCC712537");
126126
127127 try Curve25519.rejectNonCanonical(s);
128128 s[31] |= 0x80;
129 std.testing.expectError(error.NonCanonical, Curve25519.rejectNonCanonical(s));
129 try std.testing.expectError(error.NonCanonical, Curve25519.rejectNonCanonical(s));
130130}
131131
132132test "curve25519 small order check" {
......@@ -155,13 +155,13 @@ test "curve25519 small order check" {
155155 },
156156 };
157157 for (small_order_ss) |small_order_s| {
158 std.testing.expectError(error.WeakPublicKey, Curve25519.fromBytes(small_order_s).mul(s));
158 try std.testing.expectError(error.WeakPublicKey, Curve25519.fromBytes(small_order_s).mul(s));
159159 var extra = small_order_s;
160160 extra[31] ^= 0x80;
161 std.testing.expectError(error.WeakPublicKey, Curve25519.fromBytes(extra).mul(s));
161 try std.testing.expectError(error.WeakPublicKey, Curve25519.fromBytes(extra).mul(s));
162162 var valid = small_order_s;
163163 valid[31] = 0x40;
164164 s[0] = 0;
165 std.testing.expectError(error.IdentityElement, Curve25519.fromBytes(valid).mul(s));
165 try std.testing.expectError(error.IdentityElement, Curve25519.fromBytes(valid).mul(s));
166166 }
167167}
lib/std/crypto/25519/ed25519.zig+6-6
......@@ -219,8 +219,8 @@ test "ed25519 key pair creation" {
219219 _ = try fmt.hexToBytes(seed[0..], "8052030376d47112be7f73ed7a019293dd12ad910b654455798b4667d73de166");
220220 const key_pair = try Ed25519.KeyPair.create(seed);
221221 var buf: [256]u8 = undefined;
222 std.testing.expectEqualStrings(try std.fmt.bufPrint(&buf, "{s}", .{std.fmt.fmtSliceHexUpper(&key_pair.secret_key)}), "8052030376D47112BE7F73ED7A019293DD12AD910B654455798B4667D73DE1662D6F7455D97B4A3A10D7293909D1A4F2058CB9A370E43FA8154BB280DB839083");
223 std.testing.expectEqualStrings(try std.fmt.bufPrint(&buf, "{s}", .{std.fmt.fmtSliceHexUpper(&key_pair.public_key)}), "2D6F7455D97B4A3A10D7293909D1A4F2058CB9A370E43FA8154BB280DB839083");
222 try std.testing.expectEqualStrings(try std.fmt.bufPrint(&buf, "{s}", .{std.fmt.fmtSliceHexUpper(&key_pair.secret_key)}), "8052030376D47112BE7F73ED7A019293DD12AD910B654455798B4667D73DE1662D6F7455D97B4A3A10D7293909D1A4F2058CB9A370E43FA8154BB280DB839083");
223 try std.testing.expectEqualStrings(try std.fmt.bufPrint(&buf, "{s}", .{std.fmt.fmtSliceHexUpper(&key_pair.public_key)}), "2D6F7455D97B4A3A10D7293909D1A4F2058CB9A370E43FA8154BB280DB839083");
224224}
225225
226226test "ed25519 signature" {
......@@ -230,9 +230,9 @@ test "ed25519 signature" {
230230
231231 const sig = try Ed25519.sign("test", key_pair, null);
232232 var buf: [128]u8 = undefined;
233 std.testing.expectEqualStrings(try std.fmt.bufPrint(&buf, "{s}", .{std.fmt.fmtSliceHexUpper(&sig)}), "10A442B4A80CC4225B154F43BEF28D2472CA80221951262EB8E0DF9091575E2687CC486E77263C3418C757522D54F84B0359236ABBBD4ACD20DC297FDCA66808");
233 try std.testing.expectEqualStrings(try std.fmt.bufPrint(&buf, "{s}", .{std.fmt.fmtSliceHexUpper(&sig)}), "10A442B4A80CC4225B154F43BEF28D2472CA80221951262EB8E0DF9091575E2687CC486E77263C3418C757522D54F84B0359236ABBBD4ACD20DC297FDCA66808");
234234 try Ed25519.verify(sig, "test", key_pair.public_key);
235 std.testing.expectError(error.SignatureVerificationFailed, Ed25519.verify(sig, "TEST", key_pair.public_key));
235 try std.testing.expectError(error.SignatureVerificationFailed, Ed25519.verify(sig, "TEST", key_pair.public_key));
236236}
237237
238238test "ed25519 batch verification" {
......@@ -260,7 +260,7 @@ test "ed25519 batch verification" {
260260 try Ed25519.verifyBatch(2, signature_batch);
261261
262262 signature_batch[1].sig = sig1;
263 std.testing.expectError(error.SignatureVerificationFailed, Ed25519.verifyBatch(signature_batch.len, signature_batch));
263 try std.testing.expectError(error.SignatureVerificationFailed, Ed25519.verifyBatch(signature_batch.len, signature_batch));
264264 }
265265}
266266
......@@ -354,7 +354,7 @@ test "ed25519 test vectors" {
354354 var sig: [64]u8 = undefined;
355355 _ = try fmt.hexToBytes(&sig, entry.sig_hex);
356356 if (entry.expected) |error_type| {
357 std.testing.expectError(error_type, Ed25519.verify(sig, &msg, public_key));
357 try std.testing.expectError(error_type, Ed25519.verify(sig, &msg, public_key));
358358 } else {
359359 try Ed25519.verify(sig, &msg, public_key);
360360 }
lib/std/crypto/25519/edwards25519.zig+9-9
......@@ -491,7 +491,7 @@ test "edwards25519 packing/unpacking" {
491491 var b = Edwards25519.basePoint;
492492 const pk = try b.mul(s);
493493 var buf: [128]u8 = undefined;
494 std.testing.expectEqualStrings(try std.fmt.bufPrint(&buf, "{s}", .{std.fmt.fmtSliceHexUpper(&pk.toBytes())}), "074BC7E0FCBD587FDBC0969444245FADC562809C8F6E97E949AF62484B5B81A6");
494 try std.testing.expectEqualStrings(try std.fmt.bufPrint(&buf, "{s}", .{std.fmt.fmtSliceHexUpper(&pk.toBytes())}), "074BC7E0FCBD587FDBC0969444245FADC562809C8F6E97E949AF62484B5B81A6");
495495
496496 const small_order_ss: [7][32]u8 = .{
497497 .{
......@@ -518,7 +518,7 @@ test "edwards25519 packing/unpacking" {
518518 };
519519 for (small_order_ss) |small_order_s| {
520520 const small_p = try Edwards25519.fromBytes(small_order_s);
521 std.testing.expectError(error.WeakPublicKey, small_p.mul(s));
521 try std.testing.expectError(error.WeakPublicKey, small_p.mul(s));
522522 }
523523}
524524
......@@ -531,26 +531,26 @@ test "edwards25519 point addition/substraction" {
531531 const q = try Edwards25519.basePoint.clampedMul(s2);
532532 const r = p.add(q).add(q).sub(q).sub(q);
533533 try r.rejectIdentity();
534 std.testing.expectError(error.IdentityElement, r.sub(p).rejectIdentity());
535 std.testing.expectError(error.IdentityElement, p.sub(p).rejectIdentity());
536 std.testing.expectError(error.IdentityElement, p.sub(q).add(q).sub(p).rejectIdentity());
534 try std.testing.expectError(error.IdentityElement, r.sub(p).rejectIdentity());
535 try std.testing.expectError(error.IdentityElement, p.sub(p).rejectIdentity());
536 try std.testing.expectError(error.IdentityElement, p.sub(q).add(q).sub(p).rejectIdentity());
537537}
538538
539539test "edwards25519 uniform-to-point" {
540540 var r = [32]u8{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31 };
541541 var p = Edwards25519.fromUniform(r);
542 htest.assertEqual("0691eee3cf70a0056df6bfa03120635636581b5c4ea571dfc680f78c7e0b4137", p.toBytes()[0..]);
542 try htest.assertEqual("0691eee3cf70a0056df6bfa03120635636581b5c4ea571dfc680f78c7e0b4137", p.toBytes()[0..]);
543543
544544 r[31] = 0xff;
545545 p = Edwards25519.fromUniform(r);
546 htest.assertEqual("f70718e68ef42d90ca1d936bb2d7e159be6c01d8095d39bd70487c82fe5c973a", p.toBytes()[0..]);
546 try htest.assertEqual("f70718e68ef42d90ca1d936bb2d7e159be6c01d8095d39bd70487c82fe5c973a", p.toBytes()[0..]);
547547}
548548
549549// Test vectors from draft-irtf-cfrg-hash-to-curve-10
550550test "edwards25519 hash-to-curve operation" {
551551 var p = Edwards25519.fromString(true, "QUUX-V01-CS02-with-edwards25519_XMD:SHA-512_ELL2_RO_", "abc");
552 htest.assertEqual("31558a26887f23fb8218f143e69d5f0af2e7831130bd5b432ef23883b895831a", p.toBytes()[0..]);
552 try htest.assertEqual("31558a26887f23fb8218f143e69d5f0af2e7831130bd5b432ef23883b895831a", p.toBytes()[0..]);
553553
554554 p = Edwards25519.fromString(false, "QUUX-V01-CS02-with-edwards25519_XMD:SHA-512_ELL2_NU_", "abc");
555 htest.assertEqual("42fa27c8f5a1ae0aa38bb59d5938e5145622ba5dedd11d11736fa2f9502d73e7", p.toBytes()[0..]);
555 try htest.assertEqual("42fa27c8f5a1ae0aa38bb59d5938e5145622ba5dedd11d11736fa2f9502d73e7", p.toBytes()[0..]);
556556}
lib/std/crypto/25519/ristretto255.zig+5-5
......@@ -175,21 +175,21 @@ pub const Ristretto255 = struct {
175175test "ristretto255" {
176176 const p = Ristretto255.basePoint;
177177 var buf: [256]u8 = undefined;
178 std.testing.expectEqualStrings(try std.fmt.bufPrint(&buf, "{s}", .{std.fmt.fmtSliceHexUpper(&p.toBytes())}), "E2F2AE0A6ABC4E71A884A961C500515F58E30B6AA582DD8DB6A65945E08D2D76");
178 try std.testing.expectEqualStrings(try std.fmt.bufPrint(&buf, "{s}", .{std.fmt.fmtSliceHexUpper(&p.toBytes())}), "E2F2AE0A6ABC4E71A884A961C500515F58E30B6AA582DD8DB6A65945E08D2D76");
179179
180180 var r: [Ristretto255.encoded_length]u8 = undefined;
181181 _ = try fmt.hexToBytes(r[0..], "6a493210f7499cd17fecb510ae0cea23a110e8d5b901f8acadd3095c73a3b919");
182182 var q = try Ristretto255.fromBytes(r);
183183 q = q.dbl().add(p);
184 std.testing.expectEqualStrings(try std.fmt.bufPrint(&buf, "{s}", .{std.fmt.fmtSliceHexUpper(&q.toBytes())}), "E882B131016B52C1D3337080187CF768423EFCCBB517BB495AB812C4160FF44E");
184 try std.testing.expectEqualStrings(try std.fmt.bufPrint(&buf, "{s}", .{std.fmt.fmtSliceHexUpper(&q.toBytes())}), "E882B131016B52C1D3337080187CF768423EFCCBB517BB495AB812C4160FF44E");
185185
186186 const s = [_]u8{15} ++ [_]u8{0} ** 31;
187187 const w = try p.mul(s);
188 std.testing.expectEqualStrings(try std.fmt.bufPrint(&buf, "{s}", .{std.fmt.fmtSliceHexUpper(&w.toBytes())}), "E0C418F7C8D9C4CDD7395B93EA124F3AD99021BB681DFC3302A9D99A2E53E64E");
188 try std.testing.expectEqualStrings(try std.fmt.bufPrint(&buf, "{s}", .{std.fmt.fmtSliceHexUpper(&w.toBytes())}), "E0C418F7C8D9C4CDD7395B93EA124F3AD99021BB681DFC3302A9D99A2E53E64E");
189189
190 std.testing.expect(p.dbl().dbl().dbl().dbl().equivalent(w.add(p)));
190 try std.testing.expect(p.dbl().dbl().dbl().dbl().equivalent(w.add(p)));
191191
192192 const h = [_]u8{69} ** 32 ++ [_]u8{42} ** 32;
193193 const ph = Ristretto255.fromUniform(h);
194 std.testing.expectEqualStrings(try std.fmt.bufPrint(&buf, "{s}", .{std.fmt.fmtSliceHexUpper(&ph.toBytes())}), "DCCA54E037A4311EFBEEF413ACD21D35276518970B7A61DC88F8587B493D5E19");
194 try std.testing.expectEqualStrings(try std.fmt.bufPrint(&buf, "{s}", .{std.fmt.fmtSliceHexUpper(&ph.toBytes())}), "DCCA54E037A4311EFBEEF413ACD21D35276518970B7A61DC88F8587B493D5E19");
195195}
lib/std/crypto/25519/scalar.zig+4-4
......@@ -773,15 +773,15 @@ test "scalar25519" {
773773 var y = x.toBytes();
774774 try rejectNonCanonical(y);
775775 var buf: [128]u8 = undefined;
776 std.testing.expectEqualStrings(try std.fmt.bufPrint(&buf, "{s}", .{std.fmt.fmtSliceHexUpper(&y)}), "1E979B917937F3DE71D18077F961F6CEFF01030405060708010203040506070F");
776 try std.testing.expectEqualStrings(try std.fmt.bufPrint(&buf, "{s}", .{std.fmt.fmtSliceHexUpper(&y)}), "1E979B917937F3DE71D18077F961F6CEFF01030405060708010203040506070F");
777777
778778 const reduced = reduce(field_size);
779 std.testing.expectEqualStrings(try std.fmt.bufPrint(&buf, "{s}", .{std.fmt.fmtSliceHexUpper(&reduced)}), "0000000000000000000000000000000000000000000000000000000000000000");
779 try std.testing.expectEqualStrings(try std.fmt.bufPrint(&buf, "{s}", .{std.fmt.fmtSliceHexUpper(&reduced)}), "0000000000000000000000000000000000000000000000000000000000000000");
780780}
781781
782782test "non-canonical scalar25519" {
783783 const too_targe: [32]u8 = .{ 0xed, 0xd3, 0xf5, 0x5c, 0x1a, 0x63, 0x12, 0x58, 0xd6, 0x9c, 0xf7, 0xa2, 0xde, 0xf9, 0xde, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10 };
784 std.testing.expectError(error.NonCanonical, rejectNonCanonical(too_targe));
784 try std.testing.expectError(error.NonCanonical, rejectNonCanonical(too_targe));
785785}
786786
787787test "mulAdd overflow check" {
......@@ -790,5 +790,5 @@ test "mulAdd overflow check" {
790790 const c: [32]u8 = [_]u8{0xff} ** 32;
791791 const x = mulAdd(a, b, c);
792792 var buf: [128]u8 = undefined;
793 std.testing.expectEqualStrings(try std.fmt.bufPrint(&buf, "{s}", .{std.fmt.fmtSliceHexUpper(&x)}), "D14DF91389432C25AD60FF9791B9FD1D67BEF517D273ECCE3D9A307C1B419903");
793 try std.testing.expectEqualStrings(try std.fmt.bufPrint(&buf, "{s}", .{std.fmt.fmtSliceHexUpper(&x)}), "D14DF91389432C25AD60FF9791B9FD1D67BEF517D273ECCE3D9A307C1B419903");
794794}
lib/std/crypto/25519/x25519.zig+8-8
......@@ -92,7 +92,7 @@ test "x25519 public key calculation from secret key" {
9292 _ = try fmt.hexToBytes(sk[0..], "8052030376d47112be7f73ed7a019293dd12ad910b654455798b4667d73de166");
9393 _ = try fmt.hexToBytes(pk_expected[0..], "f1814f0e8ff1043d8a44d25babff3cedcae6c22c3edaa48f857ae70de2baae50");
9494 const pk_calculated = try X25519.recoverPublicKey(sk);
95 std.testing.expectEqual(pk_calculated, pk_expected);
95 try std.testing.expectEqual(pk_calculated, pk_expected);
9696}
9797
9898test "x25519 rfc7748 vector1" {
......@@ -102,7 +102,7 @@ test "x25519 rfc7748 vector1" {
102102 const expected_output = [32]u8{ 0xc3, 0xda, 0x55, 0x37, 0x9d, 0xe9, 0xc6, 0x90, 0x8e, 0x94, 0xea, 0x4d, 0xf2, 0x8d, 0x08, 0x4f, 0x32, 0xec, 0xcf, 0x03, 0x49, 0x1c, 0x71, 0xf7, 0x54, 0xb4, 0x07, 0x55, 0x77, 0xa2, 0x85, 0x52 };
103103
104104 const output = try X25519.scalarmult(secret_key, public_key);
105 std.testing.expectEqual(output, expected_output);
105 try std.testing.expectEqual(output, expected_output);
106106}
107107
108108test "x25519 rfc7748 vector2" {
......@@ -112,7 +112,7 @@ test "x25519 rfc7748 vector2" {
112112 const expected_output = [32]u8{ 0x95, 0xcb, 0xde, 0x94, 0x76, 0xe8, 0x90, 0x7d, 0x7a, 0xad, 0xe4, 0x5c, 0xb4, 0xb8, 0x73, 0xf8, 0x8b, 0x59, 0x5a, 0x68, 0x79, 0x9f, 0xa1, 0x52, 0xe6, 0xf8, 0xf7, 0x64, 0x7a, 0xac, 0x79, 0x57 };
113113
114114 const output = try X25519.scalarmult(secret_key, public_key);
115 std.testing.expectEqual(output, expected_output);
115 try std.testing.expectEqual(output, expected_output);
116116}
117117
118118test "x25519 rfc7748 one iteration" {
......@@ -129,7 +129,7 @@ test "x25519 rfc7748 one iteration" {
129129 mem.copy(u8, k[0..], output[0..]);
130130 }
131131
132 std.testing.expectEqual(k, expected_output);
132 try std.testing.expectEqual(k, expected_output);
133133}
134134
135135test "x25519 rfc7748 1,000 iterations" {
......@@ -151,7 +151,7 @@ test "x25519 rfc7748 1,000 iterations" {
151151 mem.copy(u8, k[0..], output[0..]);
152152 }
153153
154 std.testing.expectEqual(k, expected_output);
154 try std.testing.expectEqual(k, expected_output);
155155}
156156
157157test "x25519 rfc7748 1,000,000 iterations" {
......@@ -172,12 +172,12 @@ test "x25519 rfc7748 1,000,000 iterations" {
172172 mem.copy(u8, k[0..], output[0..]);
173173 }
174174
175 std.testing.expectEqual(k[0..], expected_output);
175 try std.testing.expectEqual(k[0..], expected_output);
176176}
177177
178178test "edwards25519 -> curve25519 map" {
179179 const ed_kp = try crypto.sign.Ed25519.KeyPair.create([_]u8{0x42} ** 32);
180180 const mont_kp = try X25519.KeyPair.fromEd25519(ed_kp);
181 htest.assertEqual("90e7595fc89e52fdfddce9c6a43d74dbf6047025ee0462d2d172e8b6a2841d6e", &mont_kp.secret_key);
182 htest.assertEqual("cc4f2cdb695dd766f34118eb67b98652fed1d8bc49c330b119bbfa8a64989378", &mont_kp.public_key);
181 try htest.assertEqual("90e7595fc89e52fdfddce9c6a43d74dbf6047025ee0462d2d172e8b6a2841d6e", &mont_kp.secret_key);
182 try htest.assertEqual("cc4f2cdb695dd766f34118eb67b98652fed1d8bc49c330b119bbfa8a64989378", &mont_kp.public_key);
183183}
lib/std/crypto/aegis.zig+20-20
......@@ -352,16 +352,16 @@ test "Aegis128L test vector 1" {
352352
353353 Aegis128L.encrypt(&c, &tag, &m, &ad, nonce, key);
354354 try Aegis128L.decrypt(&m2, &c, tag, &ad, nonce, key);
355 testing.expectEqualSlices(u8, &m, &m2);
355 try testing.expectEqualSlices(u8, &m, &m2);
356356
357 htest.assertEqual("79d94593d8c2119d7e8fd9b8fc77845c5c077a05b2528b6ac54b563aed8efe84", &c);
358 htest.assertEqual("cc6f3372f6aa1bb82388d695c3962d9a", &tag);
357 try htest.assertEqual("79d94593d8c2119d7e8fd9b8fc77845c5c077a05b2528b6ac54b563aed8efe84", &c);
358 try htest.assertEqual("cc6f3372f6aa1bb82388d695c3962d9a", &tag);
359359
360360 c[0] +%= 1;
361 testing.expectError(error.AuthenticationFailed, Aegis128L.decrypt(&m2, &c, tag, &ad, nonce, key));
361 try testing.expectError(error.AuthenticationFailed, Aegis128L.decrypt(&m2, &c, tag, &ad, nonce, key));
362362 c[0] -%= 1;
363363 tag[0] +%= 1;
364 testing.expectError(error.AuthenticationFailed, Aegis128L.decrypt(&m2, &c, tag, &ad, nonce, key));
364 try testing.expectError(error.AuthenticationFailed, Aegis128L.decrypt(&m2, &c, tag, &ad, nonce, key));
365365}
366366
367367test "Aegis128L test vector 2" {
......@@ -375,10 +375,10 @@ test "Aegis128L test vector 2" {
375375
376376 Aegis128L.encrypt(&c, &tag, &m, &ad, nonce, key);
377377 try Aegis128L.decrypt(&m2, &c, tag, &ad, nonce, key);
378 testing.expectEqualSlices(u8, &m, &m2);
378 try testing.expectEqualSlices(u8, &m, &m2);
379379
380 htest.assertEqual("41de9000a7b5e40e2d68bb64d99ebb19", &c);
381 htest.assertEqual("f4d997cc9b94227ada4fe4165422b1c8", &tag);
380 try htest.assertEqual("41de9000a7b5e40e2d68bb64d99ebb19", &c);
381 try htest.assertEqual("f4d997cc9b94227ada4fe4165422b1c8", &tag);
382382}
383383
384384test "Aegis128L test vector 3" {
......@@ -392,9 +392,9 @@ test "Aegis128L test vector 3" {
392392
393393 Aegis128L.encrypt(&c, &tag, &m, &ad, nonce, key);
394394 try Aegis128L.decrypt(&m2, &c, tag, &ad, nonce, key);
395 testing.expectEqualSlices(u8, &m, &m2);
395 try testing.expectEqualSlices(u8, &m, &m2);
396396
397 htest.assertEqual("83cc600dc4e3e7e62d4055826174f149", &tag);
397 try htest.assertEqual("83cc600dc4e3e7e62d4055826174f149", &tag);
398398}
399399
400400test "Aegis256 test vector 1" {
......@@ -408,16 +408,16 @@ test "Aegis256 test vector 1" {
408408
409409 Aegis256.encrypt(&c, &tag, &m, &ad, nonce, key);
410410 try Aegis256.decrypt(&m2, &c, tag, &ad, nonce, key);
411 testing.expectEqualSlices(u8, &m, &m2);
411 try testing.expectEqualSlices(u8, &m, &m2);
412412
413 htest.assertEqual("f373079ed84b2709faee373584585d60accd191db310ef5d8b11833df9dec711", &c);
414 htest.assertEqual("8d86f91ee606e9ff26a01b64ccbdd91d", &tag);
413 try htest.assertEqual("f373079ed84b2709faee373584585d60accd191db310ef5d8b11833df9dec711", &c);
414 try htest.assertEqual("8d86f91ee606e9ff26a01b64ccbdd91d", &tag);
415415
416416 c[0] +%= 1;
417 testing.expectError(error.AuthenticationFailed, Aegis256.decrypt(&m2, &c, tag, &ad, nonce, key));
417 try testing.expectError(error.AuthenticationFailed, Aegis256.decrypt(&m2, &c, tag, &ad, nonce, key));
418418 c[0] -%= 1;
419419 tag[0] +%= 1;
420 testing.expectError(error.AuthenticationFailed, Aegis256.decrypt(&m2, &c, tag, &ad, nonce, key));
420 try testing.expectError(error.AuthenticationFailed, Aegis256.decrypt(&m2, &c, tag, &ad, nonce, key));
421421}
422422
423423test "Aegis256 test vector 2" {
......@@ -431,10 +431,10 @@ test "Aegis256 test vector 2" {
431431
432432 Aegis256.encrypt(&c, &tag, &m, &ad, nonce, key);
433433 try Aegis256.decrypt(&m2, &c, tag, &ad, nonce, key);
434 testing.expectEqualSlices(u8, &m, &m2);
434 try testing.expectEqualSlices(u8, &m, &m2);
435435
436 htest.assertEqual("b98f03a947807713d75a4fff9fc277a6", &c);
437 htest.assertEqual("478f3b50dc478ef7d5cf2d0f7cc13180", &tag);
436 try htest.assertEqual("b98f03a947807713d75a4fff9fc277a6", &c);
437 try htest.assertEqual("478f3b50dc478ef7d5cf2d0f7cc13180", &tag);
438438}
439439
440440test "Aegis256 test vector 3" {
......@@ -448,7 +448,7 @@ test "Aegis256 test vector 3" {
448448
449449 Aegis256.encrypt(&c, &tag, &m, &ad, nonce, key);
450450 try Aegis256.decrypt(&m2, &c, tag, &ad, nonce, key);
451 testing.expectEqualSlices(u8, &m, &m2);
451 try testing.expectEqualSlices(u8, &m, &m2);
452452
453 htest.assertEqual("f7a0878f68bd083e8065354071fc27c3", &tag);
453 try htest.assertEqual("f7a0878f68bd083e8065354071fc27c3", &tag);
454454}
lib/std/crypto/aes.zig+9-9
......@@ -48,7 +48,7 @@ test "ctr" {
4848 var out: [exp_out.len]u8 = undefined;
4949 var ctx = Aes128.initEnc(key);
5050 ctr(AesEncryptCtx(Aes128), ctx, out[0..], in[0..], iv, builtin.Endian.Big);
51 testing.expectEqualSlices(u8, exp_out[0..], out[0..]);
51 try testing.expectEqualSlices(u8, exp_out[0..], out[0..]);
5252}
5353
5454test "encrypt" {
......@@ -61,7 +61,7 @@ test "encrypt" {
6161 var out: [exp_out.len]u8 = undefined;
6262 var ctx = Aes128.initEnc(key);
6363 ctx.encrypt(out[0..], in[0..]);
64 testing.expectEqualSlices(u8, exp_out[0..], out[0..]);
64 try testing.expectEqualSlices(u8, exp_out[0..], out[0..]);
6565 }
6666
6767 // Appendix C.3
......@@ -76,7 +76,7 @@ test "encrypt" {
7676 var out: [exp_out.len]u8 = undefined;
7777 var ctx = Aes256.initEnc(key);
7878 ctx.encrypt(out[0..], in[0..]);
79 testing.expectEqualSlices(u8, exp_out[0..], out[0..]);
79 try testing.expectEqualSlices(u8, exp_out[0..], out[0..]);
8080 }
8181}
8282
......@@ -90,7 +90,7 @@ test "decrypt" {
9090 var out: [exp_out.len]u8 = undefined;
9191 var ctx = Aes128.initDec(key);
9292 ctx.decrypt(out[0..], in[0..]);
93 testing.expectEqualSlices(u8, exp_out[0..], out[0..]);
93 try testing.expectEqualSlices(u8, exp_out[0..], out[0..]);
9494 }
9595
9696 // Appendix C.3
......@@ -105,7 +105,7 @@ test "decrypt" {
105105 var out: [exp_out.len]u8 = undefined;
106106 var ctx = Aes256.initDec(key);
107107 ctx.decrypt(out[0..], in[0..]);
108 testing.expectEqualSlices(u8, exp_out[0..], out[0..]);
108 try testing.expectEqualSlices(u8, exp_out[0..], out[0..]);
109109 }
110110}
111111
......@@ -123,11 +123,11 @@ test "expand 128-bit key" {
123123
124124 for (enc.key_schedule.round_keys) |round_key, i| {
125125 _ = try std.fmt.hexToBytes(&exp, exp_enc[i]);
126 testing.expectEqualSlices(u8, &exp, &round_key.toBytes());
126 try testing.expectEqualSlices(u8, &exp, &round_key.toBytes());
127127 }
128128 for (enc.key_schedule.round_keys) |round_key, i| {
129129 _ = try std.fmt.hexToBytes(&exp, exp_dec[i]);
130 testing.expectEqualSlices(u8, &exp, &round_key.toBytes());
130 try testing.expectEqualSlices(u8, &exp, &round_key.toBytes());
131131 }
132132}
133133
......@@ -145,10 +145,10 @@ test "expand 256-bit key" {
145145
146146 for (enc.key_schedule.round_keys) |round_key, i| {
147147 _ = try std.fmt.hexToBytes(&exp, exp_enc[i]);
148 testing.expectEqualSlices(u8, &exp, &round_key.toBytes());
148 try testing.expectEqualSlices(u8, &exp, &round_key.toBytes());
149149 }
150150 for (dec.key_schedule.round_keys) |round_key, i| {
151151 _ = try std.fmt.hexToBytes(&exp, exp_dec[i]);
152 testing.expectEqualSlices(u8, &exp, &round_key.toBytes());
152 try testing.expectEqualSlices(u8, &exp, &round_key.toBytes());
153153 }
154154}
lib/std/crypto/aes_gcm.zig+8-8
......@@ -118,7 +118,7 @@ test "Aes256Gcm - Empty message and no associated data" {
118118 var tag: [Aes256Gcm.tag_length]u8 = undefined;
119119
120120 Aes256Gcm.encrypt(&c, &tag, m, ad, nonce, key);
121 htest.assertEqual("6b6ff610a16fa4cd59f1fb7903154e92", &tag);
121 try htest.assertEqual("6b6ff610a16fa4cd59f1fb7903154e92", &tag);
122122}
123123
124124test "Aes256Gcm - Associated data only" {
......@@ -130,7 +130,7 @@ test "Aes256Gcm - Associated data only" {
130130 var tag: [Aes256Gcm.tag_length]u8 = undefined;
131131
132132 Aes256Gcm.encrypt(&c, &tag, m, ad, nonce, key);
133 htest.assertEqual("262ed164c2dfb26e080a9d108dd9dd4c", &tag);
133 try htest.assertEqual("262ed164c2dfb26e080a9d108dd9dd4c", &tag);
134134}
135135
136136test "Aes256Gcm - Message only" {
......@@ -144,10 +144,10 @@ test "Aes256Gcm - Message only" {
144144
145145 Aes256Gcm.encrypt(&c, &tag, m, ad, nonce, key);
146146 try Aes256Gcm.decrypt(&m2, &c, tag, ad, nonce, key);
147 testing.expectEqualSlices(u8, m[0..], m2[0..]);
147 try testing.expectEqualSlices(u8, m[0..], m2[0..]);
148148
149 htest.assertEqual("5ca1642d90009fea33d01f78cf6eefaf01d539472f7c", &c);
150 htest.assertEqual("07cd7fc9103e2f9e9bf2dfaa319caff4", &tag);
149 try htest.assertEqual("5ca1642d90009fea33d01f78cf6eefaf01d539472f7c", &c);
150 try htest.assertEqual("07cd7fc9103e2f9e9bf2dfaa319caff4", &tag);
151151}
152152
153153test "Aes256Gcm - Message and associated data" {
......@@ -161,8 +161,8 @@ test "Aes256Gcm - Message and associated data" {
161161
162162 Aes256Gcm.encrypt(&c, &tag, m, ad, nonce, key);
163163 try Aes256Gcm.decrypt(&m2, &c, tag, ad, nonce, key);
164 testing.expectEqualSlices(u8, m[0..], m2[0..]);
164 try testing.expectEqualSlices(u8, m[0..], m2[0..]);
165165
166 htest.assertEqual("5ca1642d90009fea33d01f78cf6eefaf01", &c);
167 htest.assertEqual("64accec679d444e2373bd9f6796c0d2c", &tag);
166 try htest.assertEqual("5ca1642d90009fea33d01f78cf6eefaf01", &c);
167 try htest.assertEqual("64accec679d444e2373bd9f6796c0d2c", &tag);
168168}
lib/std/crypto/bcrypt.zig+2-2
......@@ -281,13 +281,13 @@ test "bcrypt codec" {
281281 Codec.encode(salt_str[0..], salt[0..]);
282282 var salt2: [salt_length]u8 = undefined;
283283 try Codec.decode(salt2[0..], salt_str[0..]);
284 testing.expectEqualSlices(u8, salt[0..], salt2[0..]);
284 try testing.expectEqualSlices(u8, salt[0..], salt2[0..]);
285285}
286286
287287test "bcrypt" {
288288 const s = try strHash("password", 5);
289289 try strVerify(s, "password");
290 testing.expectError(error.PasswordVerificationFailed, strVerify(s, "invalid password"));
290 try testing.expectError(error.PasswordVerificationFailed, strVerify(s, "invalid password"));
291291
292292 const long_s = try strHash("password" ** 100, 5);
293293 try strVerify(long_s, "password" ** 100);
lib/std/crypto/blake2.zig+82-82
......@@ -194,16 +194,16 @@ pub fn Blake2s(comptime out_bits: usize) type {
194194
195195test "blake2s160 single" {
196196 const h1 = "354c9c33f735962418bdacb9479873429c34916f";
197 htest.assertEqualHash(Blake2s160, h1, "");
197 try htest.assertEqualHash(Blake2s160, h1, "");
198198
199199 const h2 = "5ae3b99be29b01834c3b508521ede60438f8de17";
200 htest.assertEqualHash(Blake2s160, h2, "abc");
200 try htest.assertEqualHash(Blake2s160, h2, "abc");
201201
202202 const h3 = "5a604fec9713c369e84b0ed68daed7d7504ef240";
203 htest.assertEqualHash(Blake2s160, h3, "The quick brown fox jumps over the lazy dog");
203 try htest.assertEqualHash(Blake2s160, h3, "The quick brown fox jumps over the lazy dog");
204204
205205 const h4 = "b60c4dc60e2681e58fbc24e77f07e02c69e72ed0";
206 htest.assertEqualHash(Blake2s160, h4, "a" ** 32 ++ "b" ** 32);
206 try htest.assertEqualHash(Blake2s160, h4, "a" ** 32 ++ "b" ** 32);
207207}
208208
209209test "blake2s160 streaming" {
......@@ -213,21 +213,21 @@ test "blake2s160 streaming" {
213213 const h1 = "354c9c33f735962418bdacb9479873429c34916f";
214214
215215 h.final(out[0..]);
216 htest.assertEqual(h1, out[0..]);
216 try htest.assertEqual(h1, out[0..]);
217217
218218 const h2 = "5ae3b99be29b01834c3b508521ede60438f8de17";
219219
220220 h = Blake2s160.init(.{});
221221 h.update("abc");
222222 h.final(out[0..]);
223 htest.assertEqual(h2, out[0..]);
223 try htest.assertEqual(h2, out[0..]);
224224
225225 h = Blake2s160.init(.{});
226226 h.update("a");
227227 h.update("b");
228228 h.update("c");
229229 h.final(out[0..]);
230 htest.assertEqual(h2, out[0..]);
230 try htest.assertEqual(h2, out[0..]);
231231
232232 const h3 = "b60c4dc60e2681e58fbc24e77f07e02c69e72ed0";
233233
......@@ -235,12 +235,12 @@ test "blake2s160 streaming" {
235235 h.update("a" ** 32);
236236 h.update("b" ** 32);
237237 h.final(out[0..]);
238 htest.assertEqual(h3, out[0..]);
238 try htest.assertEqual(h3, out[0..]);
239239
240240 h = Blake2s160.init(.{});
241241 h.update("a" ** 32 ++ "b" ** 32);
242242 h.final(out[0..]);
243 htest.assertEqual(h3, out[0..]);
243 try htest.assertEqual(h3, out[0..]);
244244
245245 const h4 = "4667fd60791a7fe41f939bca646b4529e296bd68";
246246
......@@ -248,12 +248,12 @@ test "blake2s160 streaming" {
248248 h.update("a" ** 32);
249249 h.update("b" ** 32);
250250 h.final(out[0..]);
251 htest.assertEqual(h4, out[0..]);
251 try htest.assertEqual(h4, out[0..]);
252252
253253 h = Blake2s160.init(.{ .context = [_]u8{0x69} ** 8, .salt = [_]u8{0x42} ** 8 });
254254 h.update("a" ** 32 ++ "b" ** 32);
255255 h.final(out[0..]);
256 htest.assertEqual(h4, out[0..]);
256 try htest.assertEqual(h4, out[0..]);
257257}
258258
259259test "comptime blake2s160" {
......@@ -265,28 +265,28 @@ test "comptime blake2s160" {
265265
266266 const h1 = "2c56ad9d0b2c8b474aafa93ab307db2f0940105f";
267267
268 htest.assertEqualHash(Blake2s160, h1, block[0..]);
268 try htest.assertEqualHash(Blake2s160, h1, block[0..]);
269269
270270 var h = Blake2s160.init(.{});
271271 h.update(&block);
272272 h.final(out[0..]);
273273
274 htest.assertEqual(h1, out[0..]);
274 try htest.assertEqual(h1, out[0..]);
275275 }
276276}
277277
278278test "blake2s224 single" {
279279 const h1 = "1fa1291e65248b37b3433475b2a0dd63d54a11ecc4e3e034e7bc1ef4";
280 htest.assertEqualHash(Blake2s224, h1, "");
280 try htest.assertEqualHash(Blake2s224, h1, "");
281281
282282 const h2 = "0b033fc226df7abde29f67a05d3dc62cf271ef3dfea4d387407fbd55";
283 htest.assertEqualHash(Blake2s224, h2, "abc");
283 try htest.assertEqualHash(Blake2s224, h2, "abc");
284284
285285 const h3 = "e4e5cb6c7cae41982b397bf7b7d2d9d1949823ae78435326e8db4912";
286 htest.assertEqualHash(Blake2s224, h3, "The quick brown fox jumps over the lazy dog");
286 try htest.assertEqualHash(Blake2s224, h3, "The quick brown fox jumps over the lazy dog");
287287
288288 const h4 = "557381a78facd2b298640f4e32113e58967d61420af1aa939d0cfe01";
289 htest.assertEqualHash(Blake2s224, h4, "a" ** 32 ++ "b" ** 32);
289 try htest.assertEqualHash(Blake2s224, h4, "a" ** 32 ++ "b" ** 32);
290290}
291291
292292test "blake2s224 streaming" {
......@@ -296,21 +296,21 @@ test "blake2s224 streaming" {
296296 const h1 = "1fa1291e65248b37b3433475b2a0dd63d54a11ecc4e3e034e7bc1ef4";
297297
298298 h.final(out[0..]);
299 htest.assertEqual(h1, out[0..]);
299 try htest.assertEqual(h1, out[0..]);
300300
301301 const h2 = "0b033fc226df7abde29f67a05d3dc62cf271ef3dfea4d387407fbd55";
302302
303303 h = Blake2s224.init(.{});
304304 h.update("abc");
305305 h.final(out[0..]);
306 htest.assertEqual(h2, out[0..]);
306 try htest.assertEqual(h2, out[0..]);
307307
308308 h = Blake2s224.init(.{});
309309 h.update("a");
310310 h.update("b");
311311 h.update("c");
312312 h.final(out[0..]);
313 htest.assertEqual(h2, out[0..]);
313 try htest.assertEqual(h2, out[0..]);
314314
315315 const h3 = "557381a78facd2b298640f4e32113e58967d61420af1aa939d0cfe01";
316316
......@@ -318,12 +318,12 @@ test "blake2s224 streaming" {
318318 h.update("a" ** 32);
319319 h.update("b" ** 32);
320320 h.final(out[0..]);
321 htest.assertEqual(h3, out[0..]);
321 try htest.assertEqual(h3, out[0..]);
322322
323323 h = Blake2s224.init(.{});
324324 h.update("a" ** 32 ++ "b" ** 32);
325325 h.final(out[0..]);
326 htest.assertEqual(h3, out[0..]);
326 try htest.assertEqual(h3, out[0..]);
327327
328328 const h4 = "a4d6a9d253441b80e5dfd60a04db169ffab77aec56a2855c402828c3";
329329
......@@ -331,12 +331,12 @@ test "blake2s224 streaming" {
331331 h.update("a" ** 32);
332332 h.update("b" ** 32);
333333 h.final(out[0..]);
334 htest.assertEqual(h4, out[0..]);
334 try htest.assertEqual(h4, out[0..]);
335335
336336 h = Blake2s224.init(.{ .context = [_]u8{0x69} ** 8, .salt = [_]u8{0x42} ** 8 });
337337 h.update("a" ** 32 ++ "b" ** 32);
338338 h.final(out[0..]);
339 htest.assertEqual(h4, out[0..]);
339 try htest.assertEqual(h4, out[0..]);
340340}
341341
342342test "comptime blake2s224" {
......@@ -347,28 +347,28 @@ test "comptime blake2s224" {
347347
348348 const h1 = "86b7611563293f8c73627df7a6d6ba25ca0548c2a6481f7d116ee576";
349349
350 htest.assertEqualHash(Blake2s224, h1, block[0..]);
350 try htest.assertEqualHash(Blake2s224, h1, block[0..]);
351351
352352 var h = Blake2s224.init(.{});
353353 h.update(&block);
354354 h.final(out[0..]);
355355
356 htest.assertEqual(h1, out[0..]);
356 try htest.assertEqual(h1, out[0..]);
357357 }
358358}
359359
360360test "blake2s256 single" {
361361 const h1 = "69217a3079908094e11121d042354a7c1f55b6482ca1a51e1b250dfd1ed0eef9";
362 htest.assertEqualHash(Blake2s256, h1, "");
362 try htest.assertEqualHash(Blake2s256, h1, "");
363363
364364 const h2 = "508c5e8c327c14e2e1a72ba34eeb452f37458b209ed63a294d999b4c86675982";
365 htest.assertEqualHash(Blake2s256, h2, "abc");
365 try htest.assertEqualHash(Blake2s256, h2, "abc");
366366
367367 const h3 = "606beeec743ccbeff6cbcdf5d5302aa855c256c29b88c8ed331ea1a6bf3c8812";
368 htest.assertEqualHash(Blake2s256, h3, "The quick brown fox jumps over the lazy dog");
368 try htest.assertEqualHash(Blake2s256, h3, "The quick brown fox jumps over the lazy dog");
369369
370370 const h4 = "8d8711dade07a6b92b9a3ea1f40bee9b2c53ff3edd2a273dec170b0163568977";
371 htest.assertEqualHash(Blake2s256, h4, "a" ** 32 ++ "b" ** 32);
371 try htest.assertEqualHash(Blake2s256, h4, "a" ** 32 ++ "b" ** 32);
372372}
373373
374374test "blake2s256 streaming" {
......@@ -378,21 +378,21 @@ test "blake2s256 streaming" {
378378 const h1 = "69217a3079908094e11121d042354a7c1f55b6482ca1a51e1b250dfd1ed0eef9";
379379
380380 h.final(out[0..]);
381 htest.assertEqual(h1, out[0..]);
381 try htest.assertEqual(h1, out[0..]);
382382
383383 const h2 = "508c5e8c327c14e2e1a72ba34eeb452f37458b209ed63a294d999b4c86675982";
384384
385385 h = Blake2s256.init(.{});
386386 h.update("abc");
387387 h.final(out[0..]);
388 htest.assertEqual(h2, out[0..]);
388 try htest.assertEqual(h2, out[0..]);
389389
390390 h = Blake2s256.init(.{});
391391 h.update("a");
392392 h.update("b");
393393 h.update("c");
394394 h.final(out[0..]);
395 htest.assertEqual(h2, out[0..]);
395 try htest.assertEqual(h2, out[0..]);
396396
397397 const h3 = "8d8711dade07a6b92b9a3ea1f40bee9b2c53ff3edd2a273dec170b0163568977";
398398
......@@ -400,12 +400,12 @@ test "blake2s256 streaming" {
400400 h.update("a" ** 32);
401401 h.update("b" ** 32);
402402 h.final(out[0..]);
403 htest.assertEqual(h3, out[0..]);
403 try htest.assertEqual(h3, out[0..]);
404404
405405 h = Blake2s256.init(.{});
406406 h.update("a" ** 32 ++ "b" ** 32);
407407 h.final(out[0..]);
408 htest.assertEqual(h3, out[0..]);
408 try htest.assertEqual(h3, out[0..]);
409409}
410410
411411test "blake2s256 keyed" {
......@@ -415,20 +415,20 @@ test "blake2s256 keyed" {
415415 const key = "secret_key";
416416
417417 Blake2s256.hash("a" ** 64 ++ "b" ** 64, &out, .{ .key = key });
418 htest.assertEqual(h1, out[0..]);
418 try htest.assertEqual(h1, out[0..]);
419419
420420 var h = Blake2s256.init(.{ .key = key });
421421 h.update("a" ** 64 ++ "b" ** 64);
422422 h.final(out[0..]);
423423
424 htest.assertEqual(h1, out[0..]);
424 try htest.assertEqual(h1, out[0..]);
425425
426426 h = Blake2s256.init(.{ .key = key });
427427 h.update("a" ** 64);
428428 h.update("b" ** 64);
429429 h.final(out[0..]);
430430
431 htest.assertEqual(h1, out[0..]);
431 try htest.assertEqual(h1, out[0..]);
432432}
433433
434434test "comptime blake2s256" {
......@@ -439,13 +439,13 @@ test "comptime blake2s256" {
439439
440440 const h1 = "ae09db7cd54f42b490ef09b6bc541af688e4959bb8c53f359a6f56e38ab454a3";
441441
442 htest.assertEqualHash(Blake2s256, h1, block[0..]);
442 try htest.assertEqualHash(Blake2s256, h1, block[0..]);
443443
444444 var h = Blake2s256.init(.{});
445445 h.update(&block);
446446 h.final(out[0..]);
447447
448 htest.assertEqual(h1, out[0..]);
448 try htest.assertEqual(h1, out[0..]);
449449 }
450450}
451451
......@@ -617,16 +617,16 @@ pub fn Blake2b(comptime out_bits: usize) type {
617617
618618test "blake2b160 single" {
619619 const h1 = "3345524abf6bbe1809449224b5972c41790b6cf2";
620 htest.assertEqualHash(Blake2b160, h1, "");
620 try htest.assertEqualHash(Blake2b160, h1, "");
621621
622622 const h2 = "384264f676f39536840523f284921cdc68b6846b";
623 htest.assertEqualHash(Blake2b160, h2, "abc");
623 try htest.assertEqualHash(Blake2b160, h2, "abc");
624624
625625 const h3 = "3c523ed102ab45a37d54f5610d5a983162fde84f";
626 htest.assertEqualHash(Blake2b160, h3, "The quick brown fox jumps over the lazy dog");
626 try htest.assertEqualHash(Blake2b160, h3, "The quick brown fox jumps over the lazy dog");
627627
628628 const h4 = "43758f5de1740f651f1ae39de92260fe8bd5a11f";
629 htest.assertEqualHash(Blake2b160, h4, "a" ** 64 ++ "b" ** 64);
629 try htest.assertEqualHash(Blake2b160, h4, "a" ** 64 ++ "b" ** 64);
630630}
631631
632632test "blake2b160 streaming" {
......@@ -636,40 +636,40 @@ test "blake2b160 streaming" {
636636 const h1 = "3345524abf6bbe1809449224b5972c41790b6cf2";
637637
638638 h.final(out[0..]);
639 htest.assertEqual(h1, out[0..]);
639 try htest.assertEqual(h1, out[0..]);
640640
641641 const h2 = "384264f676f39536840523f284921cdc68b6846b";
642642
643643 h = Blake2b160.init(.{});
644644 h.update("abc");
645645 h.final(out[0..]);
646 htest.assertEqual(h2, out[0..]);
646 try htest.assertEqual(h2, out[0..]);
647647
648648 h = Blake2b160.init(.{});
649649 h.update("a");
650650 h.update("b");
651651 h.update("c");
652652 h.final(out[0..]);
653 htest.assertEqual(h2, out[0..]);
653 try htest.assertEqual(h2, out[0..]);
654654
655655 const h3 = "43758f5de1740f651f1ae39de92260fe8bd5a11f";
656656
657657 h = Blake2b160.init(.{});
658658 h.update("a" ** 64 ++ "b" ** 64);
659659 h.final(out[0..]);
660 htest.assertEqual(h3, out[0..]);
660 try htest.assertEqual(h3, out[0..]);
661661
662662 h = Blake2b160.init(.{});
663663 h.update("a" ** 64);
664664 h.update("b" ** 64);
665665 h.final(out[0..]);
666 htest.assertEqual(h3, out[0..]);
666 try htest.assertEqual(h3, out[0..]);
667667
668668 h = Blake2b160.init(.{});
669669 h.update("a" ** 64);
670670 h.update("b" ** 64);
671671 h.final(out[0..]);
672 htest.assertEqual(h3, out[0..]);
672 try htest.assertEqual(h3, out[0..]);
673673
674674 const h4 = "72328f8a8200663752fc302d372b5dd9b49dd8dc";
675675
......@@ -677,13 +677,13 @@ test "blake2b160 streaming" {
677677 h.update("a" ** 64);
678678 h.update("b" ** 64);
679679 h.final(out[0..]);
680 htest.assertEqual(h4, out[0..]);
680 try htest.assertEqual(h4, out[0..]);
681681
682682 h = Blake2b160.init(.{ .context = [_]u8{0x69} ** 16, .salt = [_]u8{0x42} ** 16 });
683683 h.update("a" ** 64);
684684 h.update("b" ** 64);
685685 h.final(out[0..]);
686 htest.assertEqual(h4, out[0..]);
686 try htest.assertEqual(h4, out[0..]);
687687}
688688
689689test "comptime blake2b160" {
......@@ -694,28 +694,28 @@ test "comptime blake2b160" {
694694
695695 const h1 = "8d26f158f564e3293b42f5e3d34263cb173aa9c9";
696696
697 htest.assertEqualHash(Blake2b160, h1, block[0..]);
697 try htest.assertEqualHash(Blake2b160, h1, block[0..]);
698698
699699 var h = Blake2b160.init(.{});
700700 h.update(&block);
701701 h.final(out[0..]);
702702
703 htest.assertEqual(h1, out[0..]);
703 try htest.assertEqual(h1, out[0..]);
704704 }
705705}
706706
707707test "blake2b384 single" {
708708 const h1 = "b32811423377f52d7862286ee1a72ee540524380fda1724a6f25d7978c6fd3244a6caf0498812673c5e05ef583825100";
709 htest.assertEqualHash(Blake2b384, h1, "");
709 try htest.assertEqualHash(Blake2b384, h1, "");
710710
711711 const h2 = "6f56a82c8e7ef526dfe182eb5212f7db9df1317e57815dbda46083fc30f54ee6c66ba83be64b302d7cba6ce15bb556f4";
712 htest.assertEqualHash(Blake2b384, h2, "abc");
712 try htest.assertEqualHash(Blake2b384, h2, "abc");
713713
714714 const h3 = "b7c81b228b6bd912930e8f0b5387989691c1cee1e65aade4da3b86a3c9f678fc8018f6ed9e2906720c8d2a3aeda9c03d";
715 htest.assertEqualHash(Blake2b384, h3, "The quick brown fox jumps over the lazy dog");
715 try htest.assertEqualHash(Blake2b384, h3, "The quick brown fox jumps over the lazy dog");
716716
717717 const h4 = "b7283f0172fecbbd7eca32ce10d8a6c06b453cb3cf675b33eb4246f0da2bb94a6c0bdd6eec0b5fd71ec4fd51be80bf4c";
718 htest.assertEqualHash(Blake2b384, h4, "a" ** 64 ++ "b" ** 64);
718 try htest.assertEqualHash(Blake2b384, h4, "a" ** 64 ++ "b" ** 64);
719719}
720720
721721test "blake2b384 streaming" {
......@@ -725,40 +725,40 @@ test "blake2b384 streaming" {
725725 const h1 = "b32811423377f52d7862286ee1a72ee540524380fda1724a6f25d7978c6fd3244a6caf0498812673c5e05ef583825100";
726726
727727 h.final(out[0..]);
728 htest.assertEqual(h1, out[0..]);
728 try htest.assertEqual(h1, out[0..]);
729729
730730 const h2 = "6f56a82c8e7ef526dfe182eb5212f7db9df1317e57815dbda46083fc30f54ee6c66ba83be64b302d7cba6ce15bb556f4";
731731
732732 h = Blake2b384.init(.{});
733733 h.update("abc");
734734 h.final(out[0..]);
735 htest.assertEqual(h2, out[0..]);
735 try htest.assertEqual(h2, out[0..]);
736736
737737 h = Blake2b384.init(.{});
738738 h.update("a");
739739 h.update("b");
740740 h.update("c");
741741 h.final(out[0..]);
742 htest.assertEqual(h2, out[0..]);
742 try htest.assertEqual(h2, out[0..]);
743743
744744 const h3 = "b7283f0172fecbbd7eca32ce10d8a6c06b453cb3cf675b33eb4246f0da2bb94a6c0bdd6eec0b5fd71ec4fd51be80bf4c";
745745
746746 h = Blake2b384.init(.{});
747747 h.update("a" ** 64 ++ "b" ** 64);
748748 h.final(out[0..]);
749 htest.assertEqual(h3, out[0..]);
749 try htest.assertEqual(h3, out[0..]);
750750
751751 h = Blake2b384.init(.{});
752752 h.update("a" ** 64);
753753 h.update("b" ** 64);
754754 h.final(out[0..]);
755 htest.assertEqual(h3, out[0..]);
755 try htest.assertEqual(h3, out[0..]);
756756
757757 h = Blake2b384.init(.{});
758758 h.update("a" ** 64);
759759 h.update("b" ** 64);
760760 h.final(out[0..]);
761 htest.assertEqual(h3, out[0..]);
761 try htest.assertEqual(h3, out[0..]);
762762
763763 const h4 = "934c48fcb197031c71f583d92f98703510805e72142e0b46f5752d1e971bc86c355d556035613ff7a4154b4de09dac5c";
764764
......@@ -766,13 +766,13 @@ test "blake2b384 streaming" {
766766 h.update("a" ** 64);
767767 h.update("b" ** 64);
768768 h.final(out[0..]);
769 htest.assertEqual(h4, out[0..]);
769 try htest.assertEqual(h4, out[0..]);
770770
771771 h = Blake2b384.init(.{ .context = [_]u8{0x69} ** 16, .salt = [_]u8{0x42} ** 16 });
772772 h.update("a" ** 64);
773773 h.update("b" ** 64);
774774 h.final(out[0..]);
775 htest.assertEqual(h4, out[0..]);
775 try htest.assertEqual(h4, out[0..]);
776776}
777777
778778test "comptime blake2b384" {
......@@ -783,28 +783,28 @@ test "comptime blake2b384" {
783783
784784 const h1 = "e8aa1931ea0422e4446fecdd25c16cf35c240b10cb4659dd5c776eddcaa4d922397a589404b46eb2e53d78132d05fd7d";
785785
786 htest.assertEqualHash(Blake2b384, h1, block[0..]);
786 try htest.assertEqualHash(Blake2b384, h1, block[0..]);
787787
788788 var h = Blake2b384.init(.{});
789789 h.update(&block);
790790 h.final(out[0..]);
791791
792 htest.assertEqual(h1, out[0..]);
792 try htest.assertEqual(h1, out[0..]);
793793 }
794794}
795795
796796test "blake2b512 single" {
797797 const h1 = "786a02f742015903c6c6fd852552d272912f4740e15847618a86e217f71f5419d25e1031afee585313896444934eb04b903a685b1448b755d56f701afe9be2ce";
798 htest.assertEqualHash(Blake2b512, h1, "");
798 try htest.assertEqualHash(Blake2b512, h1, "");
799799
800800 const h2 = "ba80a53f981c4d0d6a2797b69f12f6e94c212f14685ac4b74b12bb6fdbffa2d17d87c5392aab792dc252d5de4533cc9518d38aa8dbf1925ab92386edd4009923";
801 htest.assertEqualHash(Blake2b512, h2, "abc");
801 try htest.assertEqualHash(Blake2b512, h2, "abc");
802802
803803 const h3 = "a8add4bdddfd93e4877d2746e62817b116364a1fa7bc148d95090bc7333b3673f82401cf7aa2e4cb1ecd90296e3f14cb5413f8ed77be73045b13914cdcd6a918";
804 htest.assertEqualHash(Blake2b512, h3, "The quick brown fox jumps over the lazy dog");
804 try htest.assertEqualHash(Blake2b512, h3, "The quick brown fox jumps over the lazy dog");
805805
806806 const h4 = "049980af04d6a2cf16b4b49793c3ed7e40732073788806f2c989ebe9547bda0541d63abe298ec8955d08af48ae731f2e8a0bd6d201655a5473b4aa79d211b920";
807 htest.assertEqualHash(Blake2b512, h4, "a" ** 64 ++ "b" ** 64);
807 try htest.assertEqualHash(Blake2b512, h4, "a" ** 64 ++ "b" ** 64);
808808}
809809
810810test "blake2b512 streaming" {
......@@ -814,34 +814,34 @@ test "blake2b512 streaming" {
814814 const h1 = "786a02f742015903c6c6fd852552d272912f4740e15847618a86e217f71f5419d25e1031afee585313896444934eb04b903a685b1448b755d56f701afe9be2ce";
815815
816816 h.final(out[0..]);
817 htest.assertEqual(h1, out[0..]);
817 try htest.assertEqual(h1, out[0..]);
818818
819819 const h2 = "ba80a53f981c4d0d6a2797b69f12f6e94c212f14685ac4b74b12bb6fdbffa2d17d87c5392aab792dc252d5de4533cc9518d38aa8dbf1925ab92386edd4009923";
820820
821821 h = Blake2b512.init(.{});
822822 h.update("abc");
823823 h.final(out[0..]);
824 htest.assertEqual(h2, out[0..]);
824 try htest.assertEqual(h2, out[0..]);
825825
826826 h = Blake2b512.init(.{});
827827 h.update("a");
828828 h.update("b");
829829 h.update("c");
830830 h.final(out[0..]);
831 htest.assertEqual(h2, out[0..]);
831 try htest.assertEqual(h2, out[0..]);
832832
833833 const h3 = "049980af04d6a2cf16b4b49793c3ed7e40732073788806f2c989ebe9547bda0541d63abe298ec8955d08af48ae731f2e8a0bd6d201655a5473b4aa79d211b920";
834834
835835 h = Blake2b512.init(.{});
836836 h.update("a" ** 64 ++ "b" ** 64);
837837 h.final(out[0..]);
838 htest.assertEqual(h3, out[0..]);
838 try htest.assertEqual(h3, out[0..]);
839839
840840 h = Blake2b512.init(.{});
841841 h.update("a" ** 64);
842842 h.update("b" ** 64);
843843 h.final(out[0..]);
844 htest.assertEqual(h3, out[0..]);
844 try htest.assertEqual(h3, out[0..]);
845845}
846846
847847test "blake2b512 keyed" {
......@@ -851,20 +851,20 @@ test "blake2b512 keyed" {
851851 const key = "secret_key";
852852
853853 Blake2b512.hash("a" ** 64 ++ "b" ** 64, &out, .{ .key = key });
854 htest.assertEqual(h1, out[0..]);
854 try htest.assertEqual(h1, out[0..]);
855855
856856 var h = Blake2b512.init(.{ .key = key });
857857 h.update("a" ** 64 ++ "b" ** 64);
858858 h.final(out[0..]);
859859
860 htest.assertEqual(h1, out[0..]);
860 try htest.assertEqual(h1, out[0..]);
861861
862862 h = Blake2b512.init(.{ .key = key });
863863 h.update("a" ** 64);
864864 h.update("b" ** 64);
865865 h.final(out[0..]);
866866
867 htest.assertEqual(h1, out[0..]);
867 try htest.assertEqual(h1, out[0..]);
868868}
869869
870870test "comptime blake2b512" {
......@@ -875,12 +875,12 @@ test "comptime blake2b512" {
875875
876876 const h1 = "865939e120e6805438478841afb739ae4250cf372653078a065cdcfffca4caf798e6d462b65d658fc165782640eded70963449ae1500fb0f24981d7727e22c41";
877877
878 htest.assertEqualHash(Blake2b512, h1, block[0..]);
878 try htest.assertEqualHash(Blake2b512, h1, block[0..]);
879879
880880 var h = Blake2b512.init(.{});
881881 h.update(&block);
882882 h.final(out[0..]);
883883
884 htest.assertEqual(h1, out[0..]);
884 try htest.assertEqual(h1, out[0..]);
885885 }
886886}
lib/std/crypto/blake3.zig+5-5
......@@ -641,7 +641,7 @@ const reference_test = ReferenceTest{
641641 },
642642};
643643
644fn testBlake3(hasher: *Blake3, input_len: usize, expected_hex: [262]u8) void {
644fn testBlake3(hasher: *Blake3, input_len: usize, expected_hex: [262]u8) !void {
645645 // Save initial state
646646 const initial_state = hasher.*;
647647
......@@ -664,7 +664,7 @@ fn testBlake3(hasher: *Blake3, input_len: usize, expected_hex: [262]u8) void {
664664 // Compare to expected value
665665 var expected_bytes: [expected_hex.len / 2]u8 = undefined;
666666 _ = fmt.hexToBytes(expected_bytes[0..], expected_hex[0..]) catch unreachable;
667 testing.expectEqual(actual_bytes, expected_bytes);
667 try testing.expectEqual(actual_bytes, expected_bytes);
668668
669669 // Restore initial state
670670 hasher.* = initial_state;
......@@ -676,8 +676,8 @@ test "BLAKE3 reference test cases" {
676676 var derive_key = &Blake3.initKdf(reference_test.context_string, .{});
677677
678678 for (reference_test.cases) |t| {
679 testBlake3(hash, t.input_len, t.hash.*);
680 testBlake3(keyed_hash, t.input_len, t.keyed_hash.*);
681 testBlake3(derive_key, t.input_len, t.derive_key.*);
679 try testBlake3(hash, t.input_len, t.hash.*);
680 try testBlake3(keyed_hash, t.input_len, t.keyed_hash.*);
681 try testBlake3(derive_key, t.input_len, t.derive_key.*);
682682 }
683683}
lib/std/crypto/chacha20.zig+21-21
......@@ -604,9 +604,9 @@ test "chacha20 AEAD API" {
604604
605605 aead.encrypt(c[0..], tag[0..], m, ad, nonce, key);
606606 try aead.decrypt(out[0..], c[0..], tag, ad[0..], nonce, key);
607 testing.expectEqualSlices(u8, out[0..], m);
607 try testing.expectEqualSlices(u8, out[0..], m);
608608 c[0] += 1;
609 testing.expectError(error.AuthenticationFailed, aead.decrypt(out[0..], c[0..], tag, ad[0..], nonce, key));
609 try testing.expectError(error.AuthenticationFailed, aead.decrypt(out[0..], c[0..], tag, ad[0..], nonce, key));
610610 }
611611}
612612
......@@ -644,11 +644,11 @@ test "crypto.chacha20 test vector sunscreen" {
644644 };
645645
646646 ChaCha20IETF.xor(result[0..], m[0..], 1, key, nonce);
647 testing.expectEqualSlices(u8, &expected_result, &result);
647 try testing.expectEqualSlices(u8, &expected_result, &result);
648648
649649 var m2: [114]u8 = undefined;
650650 ChaCha20IETF.xor(m2[0..], result[0..], 1, key, nonce);
651 testing.expect(mem.order(u8, m, &m2) == .eq);
651 try testing.expect(mem.order(u8, m, &m2) == .eq);
652652}
653653
654654// https://tools.ietf.org/html/draft-agl-tls-chacha20poly1305-04#section-7
......@@ -683,7 +683,7 @@ test "crypto.chacha20 test vector 1" {
683683 const nonce = [_]u8{ 0, 0, 0, 0, 0, 0, 0, 0 };
684684
685685 ChaCha20With64BitNonce.xor(result[0..], m[0..], 0, key, nonce);
686 testing.expectEqualSlices(u8, &expected_result, &result);
686 try testing.expectEqualSlices(u8, &expected_result, &result);
687687}
688688
689689test "crypto.chacha20 test vector 2" {
......@@ -717,7 +717,7 @@ test "crypto.chacha20 test vector 2" {
717717 const nonce = [_]u8{ 0, 0, 0, 0, 0, 0, 0, 0 };
718718
719719 ChaCha20With64BitNonce.xor(result[0..], m[0..], 0, key, nonce);
720 testing.expectEqualSlices(u8, &expected_result, &result);
720 try testing.expectEqualSlices(u8, &expected_result, &result);
721721}
722722
723723test "crypto.chacha20 test vector 3" {
......@@ -751,7 +751,7 @@ test "crypto.chacha20 test vector 3" {
751751 const nonce = [_]u8{ 0, 0, 0, 0, 0, 0, 0, 1 };
752752
753753 ChaCha20With64BitNonce.xor(result[0..], m[0..], 0, key, nonce);
754 testing.expectEqualSlices(u8, &expected_result, &result);
754 try testing.expectEqualSlices(u8, &expected_result, &result);
755755}
756756
757757test "crypto.chacha20 test vector 4" {
......@@ -785,7 +785,7 @@ test "crypto.chacha20 test vector 4" {
785785 const nonce = [_]u8{ 1, 0, 0, 0, 0, 0, 0, 0 };
786786
787787 ChaCha20With64BitNonce.xor(result[0..], m[0..], 0, key, nonce);
788 testing.expectEqualSlices(u8, &expected_result, &result);
788 try testing.expectEqualSlices(u8, &expected_result, &result);
789789}
790790
791791test "crypto.chacha20 test vector 5" {
......@@ -857,7 +857,7 @@ test "crypto.chacha20 test vector 5" {
857857 };
858858
859859 ChaCha20With64BitNonce.xor(result[0..], m[0..], 0, key, nonce);
860 testing.expectEqualSlices(u8, &expected_result, &result);
860 try testing.expectEqualSlices(u8, &expected_result, &result);
861861}
862862
863863test "seal" {
......@@ -873,7 +873,7 @@ test "seal" {
873873
874874 var out: [exp_out.len]u8 = undefined;
875875 ChaCha20Poly1305.encrypt(out[0..m.len], out[m.len..], m, ad, nonce, key);
876 testing.expectEqualSlices(u8, exp_out[0..], out[0..]);
876 try testing.expectEqualSlices(u8, exp_out[0..], out[0..]);
877877 }
878878 {
879879 const m = [_]u8{
......@@ -906,7 +906,7 @@ test "seal" {
906906
907907 var out: [exp_out.len]u8 = undefined;
908908 ChaCha20Poly1305.encrypt(out[0..m.len], out[m.len..], m[0..], ad[0..], nonce, key);
909 testing.expectEqualSlices(u8, exp_out[0..], out[0..]);
909 try testing.expectEqualSlices(u8, exp_out[0..], out[0..]);
910910 }
911911}
912912
......@@ -923,7 +923,7 @@ test "open" {
923923
924924 var out: [exp_out.len]u8 = undefined;
925925 try ChaCha20Poly1305.decrypt(out[0..], c[0..exp_out.len], c[exp_out.len..].*, ad[0..], nonce, key);
926 testing.expectEqualSlices(u8, exp_out[0..], out[0..]);
926 try testing.expectEqualSlices(u8, exp_out[0..], out[0..]);
927927 }
928928 {
929929 const c = [_]u8{
......@@ -956,21 +956,21 @@ test "open" {
956956
957957 var out: [exp_out.len]u8 = undefined;
958958 try ChaCha20Poly1305.decrypt(out[0..], c[0..exp_out.len], c[exp_out.len..].*, ad[0..], nonce, key);
959 testing.expectEqualSlices(u8, exp_out[0..], out[0..]);
959 try testing.expectEqualSlices(u8, exp_out[0..], out[0..]);
960960
961961 // corrupting the ciphertext, data, key, or nonce should cause a failure
962962 var bad_c = c;
963963 bad_c[0] ^= 1;
964 testing.expectError(error.AuthenticationFailed, ChaCha20Poly1305.decrypt(out[0..], bad_c[0..out.len], bad_c[out.len..].*, ad[0..], nonce, key));
964 try testing.expectError(error.AuthenticationFailed, ChaCha20Poly1305.decrypt(out[0..], bad_c[0..out.len], bad_c[out.len..].*, ad[0..], nonce, key));
965965 var bad_ad = ad;
966966 bad_ad[0] ^= 1;
967 testing.expectError(error.AuthenticationFailed, ChaCha20Poly1305.decrypt(out[0..], c[0..out.len], c[out.len..].*, bad_ad[0..], nonce, key));
967 try testing.expectError(error.AuthenticationFailed, ChaCha20Poly1305.decrypt(out[0..], c[0..out.len], c[out.len..].*, bad_ad[0..], nonce, key));
968968 var bad_key = key;
969969 bad_key[0] ^= 1;
970 testing.expectError(error.AuthenticationFailed, ChaCha20Poly1305.decrypt(out[0..], c[0..out.len], c[out.len..].*, ad[0..], nonce, bad_key));
970 try testing.expectError(error.AuthenticationFailed, ChaCha20Poly1305.decrypt(out[0..], c[0..out.len], c[out.len..].*, ad[0..], nonce, bad_key));
971971 var bad_nonce = nonce;
972972 bad_nonce[0] ^= 1;
973 testing.expectError(error.AuthenticationFailed, ChaCha20Poly1305.decrypt(out[0..], c[0..out.len], c[out.len..].*, ad[0..], bad_nonce, key));
973 try testing.expectError(error.AuthenticationFailed, ChaCha20Poly1305.decrypt(out[0..], c[0..out.len], c[out.len..].*, ad[0..], bad_nonce, key));
974974 }
975975}
976976
......@@ -982,7 +982,7 @@ test "crypto.xchacha20" {
982982 var c: [m.len]u8 = undefined;
983983 XChaCha20IETF.xor(c[0..], m[0..], 0, key, nonce);
984984 var buf: [2 * c.len]u8 = undefined;
985 testing.expectEqualStrings(try std.fmt.bufPrint(&buf, "{s}", .{std.fmt.fmtSliceHexUpper(&c)}), "E0A1BCF939654AFDBDC1746EC49832647C19D891F0D1A81FC0C1703B4514BDEA584B512F6908C2C5E9DD18D5CBC1805DE5803FE3B9CA5F193FB8359E91FAB0C3BB40309A292EB1CF49685C65C4A3ADF4F11DB0CD2B6B67FBC174BC2E860E8F769FD3565BBFAD1C845E05A0FED9BE167C240D");
985 try testing.expectEqualStrings(try std.fmt.bufPrint(&buf, "{s}", .{std.fmt.fmtSliceHexUpper(&c)}), "E0A1BCF939654AFDBDC1746EC49832647C19D891F0D1A81FC0C1703B4514BDEA584B512F6908C2C5E9DD18D5CBC1805DE5803FE3B9CA5F193FB8359E91FAB0C3BB40309A292EB1CF49685C65C4A3ADF4F11DB0CD2B6B67FBC174BC2E860E8F769FD3565BBFAD1C845E05A0FED9BE167C240D");
986986 }
987987 {
988988 const ad = "Additional data";
......@@ -991,9 +991,9 @@ test "crypto.xchacha20" {
991991 var out: [m.len]u8 = undefined;
992992 try XChaCha20Poly1305.decrypt(out[0..], c[0..m.len], c[m.len..].*, ad, nonce, key);
993993 var buf: [2 * c.len]u8 = undefined;
994 testing.expectEqualStrings(try std.fmt.bufPrint(&buf, "{s}", .{std.fmt.fmtSliceHexUpper(&c)}), "994D2DD32333F48E53650C02C7A2ABB8E018B0836D7175AEC779F52E961780768F815C58F1AA52D211498DB89B9216763F569C9433A6BBFCEFB4D4A49387A4C5207FBB3B5A92B5941294DF30588C6740D39DC16FA1F0E634F7246CF7CDCB978E44347D89381B7A74EB7084F754B90BDE9AAF5A94B8F2A85EFD0B50692AE2D425E234");
995 testing.expectEqualSlices(u8, out[0..], m);
994 try testing.expectEqualStrings(try std.fmt.bufPrint(&buf, "{s}", .{std.fmt.fmtSliceHexUpper(&c)}), "994D2DD32333F48E53650C02C7A2ABB8E018B0836D7175AEC779F52E961780768F815C58F1AA52D211498DB89B9216763F569C9433A6BBFCEFB4D4A49387A4C5207FBB3B5A92B5941294DF30588C6740D39DC16FA1F0E634F7246CF7CDCB978E44347D89381B7A74EB7084F754B90BDE9AAF5A94B8F2A85EFD0B50692AE2D425E234");
995 try testing.expectEqualSlices(u8, out[0..], m);
996996 c[0] += 1;
997 testing.expectError(error.AuthenticationFailed, XChaCha20Poly1305.decrypt(out[0..], c[0..m.len], c[m.len..].*, ad, nonce, key));
997 try testing.expectError(error.AuthenticationFailed, XChaCha20Poly1305.decrypt(out[0..], c[0..m.len], c[m.len..].*, ad, nonce, key));
998998 }
999999}
lib/std/crypto/ghash.zig+2-2
......@@ -326,11 +326,11 @@ test "ghash" {
326326 st.update(&m);
327327 var out: [16]u8 = undefined;
328328 st.final(&out);
329 htest.assertEqual("889295fa746e8b174bf4ec80a65dea41", &out);
329 try htest.assertEqual("889295fa746e8b174bf4ec80a65dea41", &out);
330330
331331 st = Ghash.init(&key);
332332 st.update(m[0..100]);
333333 st.update(m[100..]);
334334 st.final(&out);
335 htest.assertEqual("889295fa746e8b174bf4ec80a65dea41", &out);
335 try htest.assertEqual("889295fa746e8b174bf4ec80a65dea41", &out);
336336}
lib/std/crypto/gimli.zig+19-19
......@@ -205,7 +205,7 @@ test "permute" {
205205 while (i < 12) : (i += 1) {
206206 mem.writeIntLittle(u32, expected_output[i * 4 ..][0..4], tv_output[i / 4][i % 4]);
207207 }
208 testing.expectEqualSlices(u8, state.toSliceConst(), expected_output[0..]);
208 try testing.expectEqualSlices(u8, state.toSliceConst(), expected_output[0..]);
209209}
210210
211211pub const Hash = struct {
......@@ -274,7 +274,7 @@ test "hash" {
274274 _ = try std.fmt.hexToBytes(&msg, "000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C");
275275 var md: [32]u8 = undefined;
276276 hash(&md, &msg, .{});
277 htest.assertEqual("1C9A03DC6A5DDC5444CFC6F4B154CFF5CF081633B2CEA4D7D0AE7CCFED5AAA44", &md);
277 try htest.assertEqual("1C9A03DC6A5DDC5444CFC6F4B154CFF5CF081633B2CEA4D7D0AE7CCFED5AAA44", &md);
278278}
279279
280280test "hash test vector 17" {
......@@ -282,7 +282,7 @@ test "hash test vector 17" {
282282 _ = try std.fmt.hexToBytes(&msg, "000102030405060708090A0B0C0D0E0F");
283283 var md: [32]u8 = undefined;
284284 hash(&md, &msg, .{});
285 htest.assertEqual("404C130AF1B9023A7908200919F690FFBB756D5176E056FFDE320016A37C7282", &md);
285 try htest.assertEqual("404C130AF1B9023A7908200919F690FFBB756D5176E056FFDE320016A37C7282", &md);
286286}
287287
288288test "hash test vector 33" {
......@@ -290,7 +290,7 @@ test "hash test vector 33" {
290290 _ = try std.fmt.hexToBytes(&msg, "000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F");
291291 var md: [32]u8 = undefined;
292292 hash(&md, &msg, .{});
293 htest.assertEqual("A8F4FA28708BDA7EFB4C1914CA4AFA9E475B82D588D36504F87DBB0ED9AB3C4B", &md);
293 try htest.assertEqual("A8F4FA28708BDA7EFB4C1914CA4AFA9E475B82D588D36504F87DBB0ED9AB3C4B", &md);
294294}
295295
296296pub const Aead = struct {
......@@ -447,12 +447,12 @@ test "cipher" {
447447 var ct: [pt.len]u8 = undefined;
448448 var tag: [16]u8 = undefined;
449449 Aead.encrypt(&ct, &tag, &pt, &ad, nonce, key);
450 htest.assertEqual("", &ct);
451 htest.assertEqual("14DA9BB7120BF58B985A8E00FDEBA15B", &tag);
450 try htest.assertEqual("", &ct);
451 try htest.assertEqual("14DA9BB7120BF58B985A8E00FDEBA15B", &tag);
452452
453453 var pt2: [pt.len]u8 = undefined;
454454 try Aead.decrypt(&pt2, &ct, tag, &ad, nonce, key);
455 testing.expectEqualSlices(u8, &pt, &pt2);
455 try testing.expectEqualSlices(u8, &pt, &pt2);
456456 }
457457 { // test vector (34) from NIST KAT submission.
458458 const ad: [0]u8 = undefined;
......@@ -462,12 +462,12 @@ test "cipher" {
462462 var ct: [pt.len]u8 = undefined;
463463 var tag: [16]u8 = undefined;
464464 Aead.encrypt(&ct, &tag, &pt, &ad, nonce, key);
465 htest.assertEqual("7F", &ct);
466 htest.assertEqual("80492C317B1CD58A1EDC3A0D3E9876FC", &tag);
465 try htest.assertEqual("7F", &ct);
466 try htest.assertEqual("80492C317B1CD58A1EDC3A0D3E9876FC", &tag);
467467
468468 var pt2: [pt.len]u8 = undefined;
469469 try Aead.decrypt(&pt2, &ct, tag, &ad, nonce, key);
470 testing.expectEqualSlices(u8, &pt, &pt2);
470 try testing.expectEqualSlices(u8, &pt, &pt2);
471471 }
472472 { // test vector (106) from NIST KAT submission.
473473 var ad: [12 / 2]u8 = undefined;
......@@ -478,12 +478,12 @@ test "cipher" {
478478 var ct: [pt.len]u8 = undefined;
479479 var tag: [16]u8 = undefined;
480480 Aead.encrypt(&ct, &tag, &pt, &ad, nonce, key);
481 htest.assertEqual("484D35", &ct);
482 htest.assertEqual("030BBEA23B61C00CED60A923BDCF9147", &tag);
481 try htest.assertEqual("484D35", &ct);
482 try htest.assertEqual("030BBEA23B61C00CED60A923BDCF9147", &tag);
483483
484484 var pt2: [pt.len]u8 = undefined;
485485 try Aead.decrypt(&pt2, &ct, tag, &ad, nonce, key);
486 testing.expectEqualSlices(u8, &pt, &pt2);
486 try testing.expectEqualSlices(u8, &pt, &pt2);
487487 }
488488 { // test vector (790) from NIST KAT submission.
489489 var ad: [60 / 2]u8 = undefined;
......@@ -494,12 +494,12 @@ test "cipher" {
494494 var ct: [pt.len]u8 = undefined;
495495 var tag: [16]u8 = undefined;
496496 Aead.encrypt(&ct, &tag, &pt, &ad, nonce, key);
497 htest.assertEqual("6815B4A0ECDAD01596EAD87D9E690697475D234C6A13D1", &ct);
498 htest.assertEqual("DFE23F1642508290D68245279558B2FB", &tag);
497 try htest.assertEqual("6815B4A0ECDAD01596EAD87D9E690697475D234C6A13D1", &ct);
498 try htest.assertEqual("DFE23F1642508290D68245279558B2FB", &tag);
499499
500500 var pt2: [pt.len]u8 = undefined;
501501 try Aead.decrypt(&pt2, &ct, tag, &ad, nonce, key);
502 testing.expectEqualSlices(u8, &pt, &pt2);
502 try testing.expectEqualSlices(u8, &pt, &pt2);
503503 }
504504 { // test vector (1057) from NIST KAT submission.
505505 const ad: [0]u8 = undefined;
......@@ -509,11 +509,11 @@ test "cipher" {
509509 var ct: [pt.len]u8 = undefined;
510510 var tag: [16]u8 = undefined;
511511 Aead.encrypt(&ct, &tag, &pt, &ad, nonce, key);
512 htest.assertEqual("7F8A2CF4F52AA4D6B2E74105C30A2777B9D0C8AEFDD555DE35861BD3011F652F", &ct);
513 htest.assertEqual("7256456FA935AC34BBF55AE135F33257", &tag);
512 try htest.assertEqual("7F8A2CF4F52AA4D6B2E74105C30A2777B9D0C8AEFDD555DE35861BD3011F652F", &ct);
513 try htest.assertEqual("7256456FA935AC34BBF55AE135F33257", &tag);
514514
515515 var pt2: [pt.len]u8 = undefined;
516516 try Aead.decrypt(&pt2, &ct, tag, &ad, nonce, key);
517 testing.expectEqualSlices(u8, &pt, &pt2);
517 try testing.expectEqualSlices(u8, &pt, &pt2);
518518 }
519519}
lib/std/crypto/hkdf.zig+2-2
......@@ -65,8 +65,8 @@ test "Hkdf" {
6565 const context = [_]u8{ 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8, 0xf9 };
6666 const kdf = HkdfSha256;
6767 const prk = kdf.extract(&salt, &ikm);
68 htest.assertEqual("077709362c2e32df0ddc3f0dc47bba6390b6c73bb50f9c3122ec844ad7c2b3e5", &prk);
68 try htest.assertEqual("077709362c2e32df0ddc3f0dc47bba6390b6c73bb50f9c3122ec844ad7c2b3e5", &prk);
6969 var out: [42]u8 = undefined;
7070 kdf.expand(&out, &context, prk);
71 htest.assertEqual("3cb25f25faacd57a90434f64d0362f2a2d2d0a90cf1a5a4c5db02d56ecc4c5bf34007208d5b887185865", &out);
71 try htest.assertEqual("3cb25f25faacd57a90434f64d0362f2a2d2d0a90cf1a5a4c5db02d56ecc4c5bf34007208d5b887185865", &out);
7272}
lib/std/crypto/hmac.zig+6-6
......@@ -84,26 +84,26 @@ const htest = @import("test.zig");
8484test "hmac md5" {
8585 var out: [HmacMd5.mac_length]u8 = undefined;
8686 HmacMd5.create(out[0..], "", "");
87 htest.assertEqual("74e6f7298a9c2d168935f58c001bad88", out[0..]);
87 try htest.assertEqual("74e6f7298a9c2d168935f58c001bad88", out[0..]);
8888
8989 HmacMd5.create(out[0..], "The quick brown fox jumps over the lazy dog", "key");
90 htest.assertEqual("80070713463e7749b90c2dc24911e275", out[0..]);
90 try htest.assertEqual("80070713463e7749b90c2dc24911e275", out[0..]);
9191}
9292
9393test "hmac sha1" {
9494 var out: [HmacSha1.mac_length]u8 = undefined;
9595 HmacSha1.create(out[0..], "", "");
96 htest.assertEqual("fbdb1d1b18aa6c08324b7d64b71fb76370690e1d", out[0..]);
96 try htest.assertEqual("fbdb1d1b18aa6c08324b7d64b71fb76370690e1d", out[0..]);
9797
9898 HmacSha1.create(out[0..], "The quick brown fox jumps over the lazy dog", "key");
99 htest.assertEqual("de7c9b85b8b78aa6bc8a7a36f70a90701c9db4d9", out[0..]);
99 try htest.assertEqual("de7c9b85b8b78aa6bc8a7a36f70a90701c9db4d9", out[0..]);
100100}
101101
102102test "hmac sha256" {
103103 var out: [sha2.HmacSha256.mac_length]u8 = undefined;
104104 sha2.HmacSha256.create(out[0..], "", "");
105 htest.assertEqual("b613679a0814d9ec772f95d778c35fc5ff1697c493715653c6c712144292c5ad", out[0..]);
105 try htest.assertEqual("b613679a0814d9ec772f95d778c35fc5ff1697c493715653c6c712144292c5ad", out[0..]);
106106
107107 sha2.HmacSha256.create(out[0..], "The quick brown fox jumps over the lazy dog", "key");
108 htest.assertEqual("f7bc83f430538424b13298e6aa6fb143ef4d59a14946175997479dbc2d1a3cd8", out[0..]);
108 try htest.assertEqual("f7bc83f430538424b13298e6aa6fb143ef4d59a14946175997479dbc2d1a3cd8", out[0..]);
109109}
lib/std/crypto/isap.zig+3-3
......@@ -240,8 +240,8 @@ test "ISAP" {
240240 var msg = "test";
241241 var c: [msg.len]u8 = undefined;
242242 IsapA128A.encrypt(c[0..], &tag, msg[0..], ad, n, k);
243 testing.expect(mem.eql(u8, &[_]u8{ 0x8f, 0x68, 0x03, 0x8d }, c[0..]));
244 testing.expect(mem.eql(u8, &[_]u8{ 0x6c, 0x25, 0xe8, 0xe2, 0xe1, 0x1f, 0x38, 0xe9, 0x80, 0x75, 0xde, 0xd5, 0x2d, 0xb2, 0x31, 0x82 }, tag[0..]));
243 try testing.expect(mem.eql(u8, &[_]u8{ 0x8f, 0x68, 0x03, 0x8d }, c[0..]));
244 try testing.expect(mem.eql(u8, &[_]u8{ 0x6c, 0x25, 0xe8, 0xe2, 0xe1, 0x1f, 0x38, 0xe9, 0x80, 0x75, 0xde, 0xd5, 0x2d, 0xb2, 0x31, 0x82 }, tag[0..]));
245245 try IsapA128A.decrypt(c[0..], c[0..], tag, ad, n, k);
246 testing.expect(mem.eql(u8, msg, c[0..]));
246 try testing.expect(mem.eql(u8, msg, c[0..]));
247247}
lib/std/crypto/md5.zig+10-10
......@@ -241,13 +241,13 @@ pub const Md5 = struct {
241241const htest = @import("test.zig");
242242
243243test "md5 single" {
244 htest.assertEqualHash(Md5, "d41d8cd98f00b204e9800998ecf8427e", "");
245 htest.assertEqualHash(Md5, "0cc175b9c0f1b6a831c399e269772661", "a");
246 htest.assertEqualHash(Md5, "900150983cd24fb0d6963f7d28e17f72", "abc");
247 htest.assertEqualHash(Md5, "f96b697d7cb7938d525a2f31aaf161d0", "message digest");
248 htest.assertEqualHash(Md5, "c3fcd3d76192e4007dfb496cca67e13b", "abcdefghijklmnopqrstuvwxyz");
249 htest.assertEqualHash(Md5, "d174ab98d277d9f5a5611c2c9f419d9f", "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789");
250 htest.assertEqualHash(Md5, "57edf4a22be3c955ac49da2e2107b67a", "12345678901234567890123456789012345678901234567890123456789012345678901234567890");
244 try htest.assertEqualHash(Md5, "d41d8cd98f00b204e9800998ecf8427e", "");
245 try htest.assertEqualHash(Md5, "0cc175b9c0f1b6a831c399e269772661", "a");
246 try htest.assertEqualHash(Md5, "900150983cd24fb0d6963f7d28e17f72", "abc");
247 try htest.assertEqualHash(Md5, "f96b697d7cb7938d525a2f31aaf161d0", "message digest");
248 try htest.assertEqualHash(Md5, "c3fcd3d76192e4007dfb496cca67e13b", "abcdefghijklmnopqrstuvwxyz");
249 try htest.assertEqualHash(Md5, "d174ab98d277d9f5a5611c2c9f419d9f", "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789");
250 try htest.assertEqualHash(Md5, "57edf4a22be3c955ac49da2e2107b67a", "12345678901234567890123456789012345678901234567890123456789012345678901234567890");
251251}
252252
253253test "md5 streaming" {
......@@ -255,12 +255,12 @@ test "md5 streaming" {
255255 var out: [16]u8 = undefined;
256256
257257 h.final(out[0..]);
258 htest.assertEqual("d41d8cd98f00b204e9800998ecf8427e", out[0..]);
258 try htest.assertEqual("d41d8cd98f00b204e9800998ecf8427e", out[0..]);
259259
260260 h = Md5.init(.{});
261261 h.update("abc");
262262 h.final(out[0..]);
263 htest.assertEqual("900150983cd24fb0d6963f7d28e17f72", out[0..]);
263 try htest.assertEqual("900150983cd24fb0d6963f7d28e17f72", out[0..]);
264264
265265 h = Md5.init(.{});
266266 h.update("a");
......@@ -268,7 +268,7 @@ test "md5 streaming" {
268268 h.update("c");
269269 h.final(out[0..]);
270270
271 htest.assertEqual("900150983cd24fb0d6963f7d28e17f72", out[0..]);
271 try htest.assertEqual("900150983cd24fb0d6963f7d28e17f72", out[0..]);
272272}
273273
274274test "md5 aligned final" {
lib/std/crypto/pbkdf2.zig+6-6
......@@ -168,7 +168,7 @@ test "RFC 6070 one iteration" {
168168
169169 const expected = "0c60c80f961f0e71f3a9b524af6012062fe037a6";
170170
171 htest.assertEqual(expected, dk[0..]);
171 try htest.assertEqual(expected, dk[0..]);
172172}
173173
174174test "RFC 6070 two iterations" {
......@@ -183,7 +183,7 @@ test "RFC 6070 two iterations" {
183183
184184 const expected = "ea6c014dc72d6f8ccd1ed92ace1d41f0d8de8957";
185185
186 htest.assertEqual(expected, dk[0..]);
186 try htest.assertEqual(expected, dk[0..]);
187187}
188188
189189test "RFC 6070 4096 iterations" {
......@@ -198,7 +198,7 @@ test "RFC 6070 4096 iterations" {
198198
199199 const expected = "4b007901b765489abead49d926f721d065a429c1";
200200
201 htest.assertEqual(expected, dk[0..]);
201 try htest.assertEqual(expected, dk[0..]);
202202}
203203
204204test "RFC 6070 16,777,216 iterations" {
......@@ -218,7 +218,7 @@ test "RFC 6070 16,777,216 iterations" {
218218
219219 const expected = "eefe3d61cd4da4e4e9945b3d6ba2158c2634e984";
220220
221 htest.assertEqual(expected, dk[0..]);
221 try htest.assertEqual(expected, dk[0..]);
222222}
223223
224224test "RFC 6070 multi-block salt and password" {
......@@ -233,7 +233,7 @@ test "RFC 6070 multi-block salt and password" {
233233
234234 const expected = "3d2eec4fe41c849b80c8d83662c0e44a8b291a964cf2f07038";
235235
236 htest.assertEqual(expected, dk[0..]);
236 try htest.assertEqual(expected, dk[0..]);
237237}
238238
239239test "RFC 6070 embedded NUL" {
......@@ -248,7 +248,7 @@ test "RFC 6070 embedded NUL" {
248248
249249 const expected = "56fa6aa75548099dcc37d7f03425e0c3";
250250
251 htest.assertEqual(expected, dk[0..]);
251 try htest.assertEqual(expected, dk[0..]);
252252}
253253
254254test "Very large dk_len" {
lib/std/crypto/pcurves/tests.zig+9-9
......@@ -17,7 +17,7 @@ test "p256 ECDH key exchange" {
1717 const dhB = try P256.basePoint.mul(dhb, .Little);
1818 const shareda = try dhA.mul(dhb, .Little);
1919 const sharedb = try dhB.mul(dha, .Little);
20 testing.expect(shareda.equivalent(sharedb));
20 try testing.expect(shareda.equivalent(sharedb));
2121}
2222
2323test "p256 point from affine coordinates" {
......@@ -28,7 +28,7 @@ test "p256 point from affine coordinates" {
2828 var ys: [32]u8 = undefined;
2929 _ = try fmt.hexToBytes(&ys, yh);
3030 var p = try P256.fromSerializedAffineCoordinates(xs, ys, .Big);
31 testing.expect(p.equivalent(P256.basePoint));
31 try testing.expect(p.equivalent(P256.basePoint));
3232}
3333
3434test "p256 test vectors" {
......@@ -50,7 +50,7 @@ test "p256 test vectors" {
5050 p = p.add(P256.basePoint);
5151 var xs: [32]u8 = undefined;
5252 _ = try fmt.hexToBytes(&xs, xh);
53 testing.expectEqualSlices(u8, &x.toBytes(.Big), &xs);
53 try testing.expectEqualSlices(u8, &x.toBytes(.Big), &xs);
5454 }
5555}
5656
......@@ -67,7 +67,7 @@ test "p256 test vectors - doubling" {
6767 p = p.dbl();
6868 var xs: [32]u8 = undefined;
6969 _ = try fmt.hexToBytes(&xs, xh);
70 testing.expectEqualSlices(u8, &x.toBytes(.Big), &xs);
70 try testing.expectEqualSlices(u8, &x.toBytes(.Big), &xs);
7171 }
7272}
7373
......@@ -75,29 +75,29 @@ test "p256 compressed sec1 encoding/decoding" {
7575 const p = P256.random();
7676 const s = p.toCompressedSec1();
7777 const q = try P256.fromSec1(&s);
78 testing.expect(p.equivalent(q));
78 try testing.expect(p.equivalent(q));
7979}
8080
8181test "p256 uncompressed sec1 encoding/decoding" {
8282 const p = P256.random();
8383 const s = p.toUncompressedSec1();
8484 const q = try P256.fromSec1(&s);
85 testing.expect(p.equivalent(q));
85 try testing.expect(p.equivalent(q));
8686}
8787
8888test "p256 public key is the neutral element" {
8989 const n = P256.scalar.Scalar.zero.toBytes(.Little);
9090 const p = P256.random();
91 testing.expectError(error.IdentityElement, p.mul(n, .Little));
91 try testing.expectError(error.IdentityElement, p.mul(n, .Little));
9292}
9393
9494test "p256 public key is the neutral element (public verification)" {
9595 const n = P256.scalar.Scalar.zero.toBytes(.Little);
9696 const p = P256.random();
97 testing.expectError(error.IdentityElement, p.mulPublic(n, .Little));
97 try testing.expectError(error.IdentityElement, p.mulPublic(n, .Little));
9898}
9999
100100test "p256 field element non-canonical encoding" {
101101 const s = [_]u8{0xff} ** 32;
102 testing.expectError(error.NonCanonical, P256.Fe.fromBytes(s, .Little));
102 try testing.expectError(error.NonCanonical, P256.Fe.fromBytes(s, .Little));
103103}
lib/std/crypto/poly1305.zig+1-1
......@@ -216,5 +216,5 @@ test "poly1305 rfc7439 vector1" {
216216 var mac: [16]u8 = undefined;
217217 Poly1305.create(mac[0..], msg, key);
218218
219 std.testing.expectEqualSlices(u8, expected_mac, &mac);
219 try std.testing.expectEqualSlices(u8, expected_mac, &mac);
220220}
lib/std/crypto/salsa20.zig+3-3
......@@ -561,11 +561,11 @@ test "(x)salsa20" {
561561 var c: [msg.len]u8 = undefined;
562562
563563 Salsa20.xor(&c, msg[0..], 0, key, nonce);
564 htest.assertEqual("30ff9933aa6534ff5207142593cd1fca4b23bdd8", c[0..]);
564 try htest.assertEqual("30ff9933aa6534ff5207142593cd1fca4b23bdd8", c[0..]);
565565
566566 const extended_nonce = [_]u8{0x42} ** 24;
567567 XSalsa20.xor(&c, msg[0..], 0, key, extended_nonce);
568 htest.assertEqual("b4ab7d82e750ec07644fa3281bce6cd91d4243f9", c[0..]);
568 try htest.assertEqual("b4ab7d82e750ec07644fa3281bce6cd91d4243f9", c[0..]);
569569}
570570
571571test "xsalsa20poly1305" {
......@@ -628,5 +628,5 @@ test "secretbox twoblocks" {
628628 const msg = [_]u8{'a'} ** 97;
629629 var ciphertext: [msg.len + SecretBox.tag_length]u8 = undefined;
630630 SecretBox.seal(&ciphertext, &msg, nonce, key);
631 htest.assertEqual("b05760e217288ba079caa2fd57fd3701784974ffcfda20fe523b89211ad8af065a6eb37cdb29d51aca5bd75dafdd21d18b044c54bb7c526cf576c94ee8900f911ceab0147e82b667a28c52d58ceb29554ff45471224d37b03256b01c119b89ff6d36855de8138d103386dbc9d971f52261", &ciphertext);
631 try htest.assertEqual("b05760e217288ba079caa2fd57fd3701784974ffcfda20fe523b89211ad8af065a6eb37cdb29d51aca5bd75dafdd21d18b044c54bb7c526cf576c94ee8900f911ceab0147e82b667a28c52d58ceb29554ff45471224d37b03256b01c119b89ff6d36855de8138d103386dbc9d971f52261", &ciphertext);
632632}
lib/std/crypto/sha1.zig+6-6
......@@ -265,9 +265,9 @@ pub const Sha1 = struct {
265265const htest = @import("test.zig");
266266
267267test "sha1 single" {
268 htest.assertEqualHash(Sha1, "da39a3ee5e6b4b0d3255bfef95601890afd80709", "");
269 htest.assertEqualHash(Sha1, "a9993e364706816aba3e25717850c26c9cd0d89d", "abc");
270 htest.assertEqualHash(Sha1, "a49b2446a02c645bf419f995b67091253a04a259", "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu");
268 try htest.assertEqualHash(Sha1, "da39a3ee5e6b4b0d3255bfef95601890afd80709", "");
269 try htest.assertEqualHash(Sha1, "a9993e364706816aba3e25717850c26c9cd0d89d", "abc");
270 try htest.assertEqualHash(Sha1, "a49b2446a02c645bf419f995b67091253a04a259", "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu");
271271}
272272
273273test "sha1 streaming" {
......@@ -275,19 +275,19 @@ test "sha1 streaming" {
275275 var out: [20]u8 = undefined;
276276
277277 h.final(&out);
278 htest.assertEqual("da39a3ee5e6b4b0d3255bfef95601890afd80709", out[0..]);
278 try htest.assertEqual("da39a3ee5e6b4b0d3255bfef95601890afd80709", out[0..]);
279279
280280 h = Sha1.init(.{});
281281 h.update("abc");
282282 h.final(&out);
283 htest.assertEqual("a9993e364706816aba3e25717850c26c9cd0d89d", out[0..]);
283 try htest.assertEqual("a9993e364706816aba3e25717850c26c9cd0d89d", out[0..]);
284284
285285 h = Sha1.init(.{});
286286 h.update("a");
287287 h.update("b");
288288 h.update("c");
289289 h.final(&out);
290 htest.assertEqual("a9993e364706816aba3e25717850c26c9cd0d89d", out[0..]);
290 try htest.assertEqual("a9993e364706816aba3e25717850c26c9cd0d89d", out[0..]);
291291}
292292
293293test "sha1 aligned final" {
lib/std/crypto/sha2.zig+24-24
......@@ -285,9 +285,9 @@ fn Sha2x32(comptime params: Sha2Params32) type {
285285}
286286
287287test "sha224 single" {
288 htest.assertEqualHash(Sha224, "d14a028c2a3a2bc9476102bb288234c415a2b01f828ea62ac5b3e42f", "");
289 htest.assertEqualHash(Sha224, "23097d223405d8228642a477bda255b32aadbce4bda0b3f7e36c9da7", "abc");
290 htest.assertEqualHash(Sha224, "c97ca9a559850ce97a04a96def6d99a9e0e0e2ab14e6b8df265fc0b3", "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu");
288 try htest.assertEqualHash(Sha224, "d14a028c2a3a2bc9476102bb288234c415a2b01f828ea62ac5b3e42f", "");
289 try htest.assertEqualHash(Sha224, "23097d223405d8228642a477bda255b32aadbce4bda0b3f7e36c9da7", "abc");
290 try htest.assertEqualHash(Sha224, "c97ca9a559850ce97a04a96def6d99a9e0e0e2ab14e6b8df265fc0b3", "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu");
291291}
292292
293293test "sha224 streaming" {
......@@ -295,25 +295,25 @@ test "sha224 streaming" {
295295 var out: [28]u8 = undefined;
296296
297297 h.final(out[0..]);
298 htest.assertEqual("d14a028c2a3a2bc9476102bb288234c415a2b01f828ea62ac5b3e42f", out[0..]);
298 try htest.assertEqual("d14a028c2a3a2bc9476102bb288234c415a2b01f828ea62ac5b3e42f", out[0..]);
299299
300300 h = Sha224.init(.{});
301301 h.update("abc");
302302 h.final(out[0..]);
303 htest.assertEqual("23097d223405d8228642a477bda255b32aadbce4bda0b3f7e36c9da7", out[0..]);
303 try htest.assertEqual("23097d223405d8228642a477bda255b32aadbce4bda0b3f7e36c9da7", out[0..]);
304304
305305 h = Sha224.init(.{});
306306 h.update("a");
307307 h.update("b");
308308 h.update("c");
309309 h.final(out[0..]);
310 htest.assertEqual("23097d223405d8228642a477bda255b32aadbce4bda0b3f7e36c9da7", out[0..]);
310 try htest.assertEqual("23097d223405d8228642a477bda255b32aadbce4bda0b3f7e36c9da7", out[0..]);
311311}
312312
313313test "sha256 single" {
314 htest.assertEqualHash(Sha256, "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", "");
315 htest.assertEqualHash(Sha256, "ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad", "abc");
316 htest.assertEqualHash(Sha256, "cf5b16a778af8380036ce59e7b0492370b249b11e8f07a51afac45037afee9d1", "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu");
314 try htest.assertEqualHash(Sha256, "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", "");
315 try htest.assertEqualHash(Sha256, "ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad", "abc");
316 try htest.assertEqualHash(Sha256, "cf5b16a778af8380036ce59e7b0492370b249b11e8f07a51afac45037afee9d1", "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu");
317317}
318318
319319test "sha256 streaming" {
......@@ -321,19 +321,19 @@ test "sha256 streaming" {
321321 var out: [32]u8 = undefined;
322322
323323 h.final(out[0..]);
324 htest.assertEqual("e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", out[0..]);
324 try htest.assertEqual("e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", out[0..]);
325325
326326 h = Sha256.init(.{});
327327 h.update("abc");
328328 h.final(out[0..]);
329 htest.assertEqual("ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad", out[0..]);
329 try htest.assertEqual("ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad", out[0..]);
330330
331331 h = Sha256.init(.{});
332332 h.update("a");
333333 h.update("b");
334334 h.update("c");
335335 h.final(out[0..]);
336 htest.assertEqual("ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad", out[0..]);
336 try htest.assertEqual("ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad", out[0..]);
337337}
338338
339339test "sha256 aligned final" {
......@@ -675,13 +675,13 @@ fn Sha2x64(comptime params: Sha2Params64) type {
675675
676676test "sha384 single" {
677677 const h1 = "38b060a751ac96384cd9327eb1b1e36a21fdb71114be07434c0cc7bf63f6e1da274edebfe76f65fbd51ad2f14898b95b";
678 htest.assertEqualHash(Sha384, h1, "");
678 try htest.assertEqualHash(Sha384, h1, "");
679679
680680 const h2 = "cb00753f45a35e8bb5a03d699ac65007272c32ab0eded1631a8b605a43ff5bed8086072ba1e7cc2358baeca134c825a7";
681 htest.assertEqualHash(Sha384, h2, "abc");
681 try htest.assertEqualHash(Sha384, h2, "abc");
682682
683683 const h3 = "09330c33f71147e83d192fc782cd1b4753111b173b3b05d22fa08086e3b0f712fcc7c71a557e2db966c3e9fa91746039";
684 htest.assertEqualHash(Sha384, h3, "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu");
684 try htest.assertEqualHash(Sha384, h3, "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu");
685685}
686686
687687test "sha384 streaming" {
......@@ -690,32 +690,32 @@ test "sha384 streaming" {
690690
691691 const h1 = "38b060a751ac96384cd9327eb1b1e36a21fdb71114be07434c0cc7bf63f6e1da274edebfe76f65fbd51ad2f14898b95b";
692692 h.final(out[0..]);
693 htest.assertEqual(h1, out[0..]);
693 try htest.assertEqual(h1, out[0..]);
694694
695695 const h2 = "cb00753f45a35e8bb5a03d699ac65007272c32ab0eded1631a8b605a43ff5bed8086072ba1e7cc2358baeca134c825a7";
696696
697697 h = Sha384.init(.{});
698698 h.update("abc");
699699 h.final(out[0..]);
700 htest.assertEqual(h2, out[0..]);
700 try htest.assertEqual(h2, out[0..]);
701701
702702 h = Sha384.init(.{});
703703 h.update("a");
704704 h.update("b");
705705 h.update("c");
706706 h.final(out[0..]);
707 htest.assertEqual(h2, out[0..]);
707 try htest.assertEqual(h2, out[0..]);
708708}
709709
710710test "sha512 single" {
711711 const h1 = "cf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921d36ce9ce47d0d13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e";
712 htest.assertEqualHash(Sha512, h1, "");
712 try htest.assertEqualHash(Sha512, h1, "");
713713
714714 const h2 = "ddaf35a193617abacc417349ae20413112e6fa4e89a97ea20a9eeee64b55d39a2192992a274fc1a836ba3c23a3feebbd454d4423643ce80e2a9ac94fa54ca49f";
715 htest.assertEqualHash(Sha512, h2, "abc");
715 try htest.assertEqualHash(Sha512, h2, "abc");
716716
717717 const h3 = "8e959b75dae313da8cf4f72814fc143f8f7779c6eb9f7fa17299aeadb6889018501d289e4900f7e4331b99dec4b5433ac7d329eeb6dd26545e96e55b874be909";
718 htest.assertEqualHash(Sha512, h3, "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu");
718 try htest.assertEqualHash(Sha512, h3, "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu");
719719}
720720
721721test "sha512 streaming" {
......@@ -724,21 +724,21 @@ test "sha512 streaming" {
724724
725725 const h1 = "cf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921d36ce9ce47d0d13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e";
726726 h.final(out[0..]);
727 htest.assertEqual(h1, out[0..]);
727 try htest.assertEqual(h1, out[0..]);
728728
729729 const h2 = "ddaf35a193617abacc417349ae20413112e6fa4e89a97ea20a9eeee64b55d39a2192992a274fc1a836ba3c23a3feebbd454d4423643ce80e2a9ac94fa54ca49f";
730730
731731 h = Sha512.init(.{});
732732 h.update("abc");
733733 h.final(out[0..]);
734 htest.assertEqual(h2, out[0..]);
734 try htest.assertEqual(h2, out[0..]);
735735
736736 h = Sha512.init(.{});
737737 h.update("a");
738738 h.update("b");
739739 h.update("c");
740740 h.final(out[0..]);
741 htest.assertEqual(h2, out[0..]);
741 try htest.assertEqual(h2, out[0..]);
742742}
743743
744744test "sha512 aligned final" {
lib/std/crypto/sha3.zig+30-30
......@@ -169,9 +169,9 @@ fn keccakF(comptime F: usize, d: *[F / 8]u8) void {
169169}
170170
171171test "sha3-224 single" {
172 htest.assertEqualHash(Sha3_224, "6b4e03423667dbb73b6e15454f0eb1abd4597f9a1b078e3f5b5a6bc7", "");
173 htest.assertEqualHash(Sha3_224, "e642824c3f8cf24ad09234ee7d3c766fc9a3a5168d0c94ad73b46fdf", "abc");
174 htest.assertEqualHash(Sha3_224, "543e6868e1666c1a643630df77367ae5a62a85070a51c14cbf665cbc", "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu");
172 try htest.assertEqualHash(Sha3_224, "6b4e03423667dbb73b6e15454f0eb1abd4597f9a1b078e3f5b5a6bc7", "");
173 try htest.assertEqualHash(Sha3_224, "e642824c3f8cf24ad09234ee7d3c766fc9a3a5168d0c94ad73b46fdf", "abc");
174 try htest.assertEqualHash(Sha3_224, "543e6868e1666c1a643630df77367ae5a62a85070a51c14cbf665cbc", "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu");
175175}
176176
177177test "sha3-224 streaming" {
......@@ -179,25 +179,25 @@ test "sha3-224 streaming" {
179179 var out: [28]u8 = undefined;
180180
181181 h.final(out[0..]);
182 htest.assertEqual("6b4e03423667dbb73b6e15454f0eb1abd4597f9a1b078e3f5b5a6bc7", out[0..]);
182 try htest.assertEqual("6b4e03423667dbb73b6e15454f0eb1abd4597f9a1b078e3f5b5a6bc7", out[0..]);
183183
184184 h = Sha3_224.init(.{});
185185 h.update("abc");
186186 h.final(out[0..]);
187 htest.assertEqual("e642824c3f8cf24ad09234ee7d3c766fc9a3a5168d0c94ad73b46fdf", out[0..]);
187 try htest.assertEqual("e642824c3f8cf24ad09234ee7d3c766fc9a3a5168d0c94ad73b46fdf", out[0..]);
188188
189189 h = Sha3_224.init(.{});
190190 h.update("a");
191191 h.update("b");
192192 h.update("c");
193193 h.final(out[0..]);
194 htest.assertEqual("e642824c3f8cf24ad09234ee7d3c766fc9a3a5168d0c94ad73b46fdf", out[0..]);
194 try htest.assertEqual("e642824c3f8cf24ad09234ee7d3c766fc9a3a5168d0c94ad73b46fdf", out[0..]);
195195}
196196
197197test "sha3-256 single" {
198 htest.assertEqualHash(Sha3_256, "a7ffc6f8bf1ed76651c14756a061d662f580ff4de43b49fa82d80a4b80f8434a", "");
199 htest.assertEqualHash(Sha3_256, "3a985da74fe225b2045c172d6bd390bd855f086e3e9d525b46bfe24511431532", "abc");
200 htest.assertEqualHash(Sha3_256, "916f6061fe879741ca6469b43971dfdb28b1a32dc36cb3254e812be27aad1d18", "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu");
198 try htest.assertEqualHash(Sha3_256, "a7ffc6f8bf1ed76651c14756a061d662f580ff4de43b49fa82d80a4b80f8434a", "");
199 try htest.assertEqualHash(Sha3_256, "3a985da74fe225b2045c172d6bd390bd855f086e3e9d525b46bfe24511431532", "abc");
200 try htest.assertEqualHash(Sha3_256, "916f6061fe879741ca6469b43971dfdb28b1a32dc36cb3254e812be27aad1d18", "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu");
201201}
202202
203203test "sha3-256 streaming" {
......@@ -205,19 +205,19 @@ test "sha3-256 streaming" {
205205 var out: [32]u8 = undefined;
206206
207207 h.final(out[0..]);
208 htest.assertEqual("a7ffc6f8bf1ed76651c14756a061d662f580ff4de43b49fa82d80a4b80f8434a", out[0..]);
208 try htest.assertEqual("a7ffc6f8bf1ed76651c14756a061d662f580ff4de43b49fa82d80a4b80f8434a", out[0..]);
209209
210210 h = Sha3_256.init(.{});
211211 h.update("abc");
212212 h.final(out[0..]);
213 htest.assertEqual("3a985da74fe225b2045c172d6bd390bd855f086e3e9d525b46bfe24511431532", out[0..]);
213 try htest.assertEqual("3a985da74fe225b2045c172d6bd390bd855f086e3e9d525b46bfe24511431532", out[0..]);
214214
215215 h = Sha3_256.init(.{});
216216 h.update("a");
217217 h.update("b");
218218 h.update("c");
219219 h.final(out[0..]);
220 htest.assertEqual("3a985da74fe225b2045c172d6bd390bd855f086e3e9d525b46bfe24511431532", out[0..]);
220 try htest.assertEqual("3a985da74fe225b2045c172d6bd390bd855f086e3e9d525b46bfe24511431532", out[0..]);
221221}
222222
223223test "sha3-256 aligned final" {
......@@ -231,11 +231,11 @@ test "sha3-256 aligned final" {
231231
232232test "sha3-384 single" {
233233 const h1 = "0c63a75b845e4f7d01107d852e4c2485c51a50aaaa94fc61995e71bbee983a2ac3713831264adb47fb6bd1e058d5f004";
234 htest.assertEqualHash(Sha3_384, h1, "");
234 try htest.assertEqualHash(Sha3_384, h1, "");
235235 const h2 = "ec01498288516fc926459f58e2c6ad8df9b473cb0fc08c2596da7cf0e49be4b298d88cea927ac7f539f1edf228376d25";
236 htest.assertEqualHash(Sha3_384, h2, "abc");
236 try htest.assertEqualHash(Sha3_384, h2, "abc");
237237 const h3 = "79407d3b5916b59c3e30b09822974791c313fb9ecc849e406f23592d04f625dc8c709b98b43b3852b337216179aa7fc7";
238 htest.assertEqualHash(Sha3_384, h3, "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu");
238 try htest.assertEqualHash(Sha3_384, h3, "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu");
239239}
240240
241241test "sha3-384 streaming" {
......@@ -244,29 +244,29 @@ test "sha3-384 streaming" {
244244
245245 const h1 = "0c63a75b845e4f7d01107d852e4c2485c51a50aaaa94fc61995e71bbee983a2ac3713831264adb47fb6bd1e058d5f004";
246246 h.final(out[0..]);
247 htest.assertEqual(h1, out[0..]);
247 try htest.assertEqual(h1, out[0..]);
248248
249249 const h2 = "ec01498288516fc926459f58e2c6ad8df9b473cb0fc08c2596da7cf0e49be4b298d88cea927ac7f539f1edf228376d25";
250250 h = Sha3_384.init(.{});
251251 h.update("abc");
252252 h.final(out[0..]);
253 htest.assertEqual(h2, out[0..]);
253 try htest.assertEqual(h2, out[0..]);
254254
255255 h = Sha3_384.init(.{});
256256 h.update("a");
257257 h.update("b");
258258 h.update("c");
259259 h.final(out[0..]);
260 htest.assertEqual(h2, out[0..]);
260 try htest.assertEqual(h2, out[0..]);
261261}
262262
263263test "sha3-512 single" {
264264 const h1 = "a69f73cca23a9ac5c8b567dc185a756e97c982164fe25859e0d1dcc1475c80a615b2123af1f5f94c11e3e9402c3ac558f500199d95b6d3e301758586281dcd26";
265 htest.assertEqualHash(Sha3_512, h1, "");
265 try htest.assertEqualHash(Sha3_512, h1, "");
266266 const h2 = "b751850b1a57168a5693cd924b6b096e08f621827444f70d884f5d0240d2712e10e116e9192af3c91a7ec57647e3934057340b4cf408d5a56592f8274eec53f0";
267 htest.assertEqualHash(Sha3_512, h2, "abc");
267 try htest.assertEqualHash(Sha3_512, h2, "abc");
268268 const h3 = "afebb2ef542e6579c50cad06d2e578f9f8dd6881d7dc824d26360feebf18a4fa73e3261122948efcfd492e74e82e2189ed0fb440d187f382270cb455f21dd185";
269 htest.assertEqualHash(Sha3_512, h3, "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu");
269 try htest.assertEqualHash(Sha3_512, h3, "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu");
270270}
271271
272272test "sha3-512 streaming" {
......@@ -275,20 +275,20 @@ test "sha3-512 streaming" {
275275
276276 const h1 = "a69f73cca23a9ac5c8b567dc185a756e97c982164fe25859e0d1dcc1475c80a615b2123af1f5f94c11e3e9402c3ac558f500199d95b6d3e301758586281dcd26";
277277 h.final(out[0..]);
278 htest.assertEqual(h1, out[0..]);
278 try htest.assertEqual(h1, out[0..]);
279279
280280 const h2 = "b751850b1a57168a5693cd924b6b096e08f621827444f70d884f5d0240d2712e10e116e9192af3c91a7ec57647e3934057340b4cf408d5a56592f8274eec53f0";
281281 h = Sha3_512.init(.{});
282282 h.update("abc");
283283 h.final(out[0..]);
284 htest.assertEqual(h2, out[0..]);
284 try htest.assertEqual(h2, out[0..]);
285285
286286 h = Sha3_512.init(.{});
287287 h.update("a");
288288 h.update("b");
289289 h.update("c");
290290 h.final(out[0..]);
291 htest.assertEqual(h2, out[0..]);
291 try htest.assertEqual(h2, out[0..]);
292292}
293293
294294test "sha3-512 aligned final" {
......@@ -301,13 +301,13 @@ test "sha3-512 aligned final" {
301301}
302302
303303test "keccak-256 single" {
304 htest.assertEqualHash(Keccak_256, "c5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470", "");
305 htest.assertEqualHash(Keccak_256, "4e03657aea45a94fc7d47ba826c8d667c0d1e6e33a64a036ec44f58fa12d6c45", "abc");
306 htest.assertEqualHash(Keccak_256, "f519747ed599024f3882238e5ab43960132572b7345fbeb9a90769dafd21ad67", "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu");
304 try htest.assertEqualHash(Keccak_256, "c5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470", "");
305 try htest.assertEqualHash(Keccak_256, "4e03657aea45a94fc7d47ba826c8d667c0d1e6e33a64a036ec44f58fa12d6c45", "abc");
306 try htest.assertEqualHash(Keccak_256, "f519747ed599024f3882238e5ab43960132572b7345fbeb9a90769dafd21ad67", "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu");
307307}
308308
309309test "keccak-512 single" {
310 htest.assertEqualHash(Keccak_512, "0eab42de4c3ceb9235fc91acffe746b29c29a8c366b7c60e4e67c466f36a4304c00fa9caf9d87976ba469bcbe06713b435f091ef2769fb160cdab33d3670680e", "");
311 htest.assertEqualHash(Keccak_512, "18587dc2ea106b9a1563e32b3312421ca164c7f1f07bc922a9c83d77cea3a1e5d0c69910739025372dc14ac9642629379540c17e2a65b19d77aa511a9d00bb96", "abc");
312 htest.assertEqualHash(Keccak_512, "ac2fb35251825d3aa48468a9948c0a91b8256f6d97d8fa4160faff2dd9dfcc24f3f1db7a983dad13d53439ccac0b37e24037e7b95f80f59f37a2f683c4ba4682", "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu");
310 try htest.assertEqualHash(Keccak_512, "0eab42de4c3ceb9235fc91acffe746b29c29a8c366b7c60e4e67c466f36a4304c00fa9caf9d87976ba469bcbe06713b435f091ef2769fb160cdab33d3670680e", "");
311 try htest.assertEqualHash(Keccak_512, "18587dc2ea106b9a1563e32b3312421ca164c7f1f07bc922a9c83d77cea3a1e5d0c69910739025372dc14ac9642629379540c17e2a65b19d77aa511a9d00bb96", "abc");
312 try htest.assertEqualHash(Keccak_512, "ac2fb35251825d3aa48468a9948c0a91b8256f6d97d8fa4160faff2dd9dfcc24f3f1db7a983dad13d53439ccac0b37e24037e7b95f80f59f37a2f683c4ba4682", "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu");
313313}
lib/std/crypto/siphash.zig+3-3
......@@ -319,7 +319,7 @@ test "siphash64-2-4 sanity" {
319319
320320 var out: [siphash.mac_length]u8 = undefined;
321321 siphash.create(&out, buffer[0..i], test_key);
322 testing.expectEqual(out, vector);
322 try testing.expectEqual(out, vector);
323323 }
324324}
325325
......@@ -399,7 +399,7 @@ test "siphash128-2-4 sanity" {
399399
400400 var out: [siphash.mac_length]u8 = undefined;
401401 siphash.create(&out, buffer[0..i], test_key[0..]);
402 testing.expectEqual(out, vector);
402 try testing.expectEqual(out, vector);
403403 }
404404}
405405
......@@ -423,6 +423,6 @@ test "iterative non-divisible update" {
423423 }
424424 const iterative_hash = siphash.finalInt();
425425
426 std.testing.expectEqual(iterative_hash, non_iterative_hash);
426 try std.testing.expectEqual(iterative_hash, non_iterative_hash);
427427 }
428428}
lib/std/crypto/test.zig+4-4
......@@ -8,19 +8,19 @@ const testing = std.testing;
88const fmt = std.fmt;
99
1010// Hash using the specified hasher `H` asserting `expected == H(input)`.
11pub fn assertEqualHash(comptime Hasher: anytype, comptime expected_hex: *const [Hasher.digest_length * 2:0]u8, input: []const u8) void {
11pub fn assertEqualHash(comptime Hasher: anytype, comptime expected_hex: *const [Hasher.digest_length * 2:0]u8, input: []const u8) !void {
1212 var h: [Hasher.digest_length]u8 = undefined;
1313 Hasher.hash(input, &h, .{});
1414
15 assertEqual(expected_hex, &h);
15 try assertEqual(expected_hex, &h);
1616}
1717
1818// Assert `expected` == hex(`input`) where `input` is a bytestring
19pub fn assertEqual(comptime expected_hex: [:0]const u8, input: []const u8) void {
19pub fn assertEqual(comptime expected_hex: [:0]const u8, input: []const u8) !void {
2020 var expected_bytes: [expected_hex.len / 2]u8 = undefined;
2121 for (expected_bytes) |*r, i| {
2222 r.* = fmt.parseInt(u8, expected_hex[2 * i .. 2 * i + 2], 16) catch unreachable;
2323 }
2424
25 testing.expectEqualSlices(u8, &expected_bytes, input);
25 try testing.expectEqualSlices(u8, &expected_bytes, input);
2626}
lib/std/crypto/utils.zig+11-11
......@@ -92,9 +92,9 @@ test "crypto.utils.timingSafeEql" {
9292 var b: [100]u8 = undefined;
9393 std.crypto.random.bytes(a[0..]);
9494 std.crypto.random.bytes(b[0..]);
95 testing.expect(!timingSafeEql([100]u8, a, b));
95 try testing.expect(!timingSafeEql([100]u8, a, b));
9696 mem.copy(u8, a[0..], b[0..]);
97 testing.expect(timingSafeEql([100]u8, a, b));
97 try testing.expect(timingSafeEql([100]u8, a, b));
9898}
9999
100100test "crypto.utils.timingSafeEql (vectors)" {
......@@ -104,22 +104,22 @@ test "crypto.utils.timingSafeEql (vectors)" {
104104 std.crypto.random.bytes(b[0..]);
105105 const v1: std.meta.Vector(100, u8) = a;
106106 const v2: std.meta.Vector(100, u8) = b;
107 testing.expect(!timingSafeEql(std.meta.Vector(100, u8), v1, v2));
107 try testing.expect(!timingSafeEql(std.meta.Vector(100, u8), v1, v2));
108108 const v3: std.meta.Vector(100, u8) = a;
109 testing.expect(timingSafeEql(std.meta.Vector(100, u8), v1, v3));
109 try testing.expect(timingSafeEql(std.meta.Vector(100, u8), v1, v3));
110110}
111111
112112test "crypto.utils.timingSafeCompare" {
113113 var a = [_]u8{10} ** 32;
114114 var b = [_]u8{10} ** 32;
115 testing.expectEqual(timingSafeCompare(u8, &a, &b, .Big), .eq);
116 testing.expectEqual(timingSafeCompare(u8, &a, &b, .Little), .eq);
115 try testing.expectEqual(timingSafeCompare(u8, &a, &b, .Big), .eq);
116 try testing.expectEqual(timingSafeCompare(u8, &a, &b, .Little), .eq);
117117 a[31] = 1;
118 testing.expectEqual(timingSafeCompare(u8, &a, &b, .Big), .lt);
119 testing.expectEqual(timingSafeCompare(u8, &a, &b, .Little), .lt);
118 try testing.expectEqual(timingSafeCompare(u8, &a, &b, .Big), .lt);
119 try testing.expectEqual(timingSafeCompare(u8, &a, &b, .Little), .lt);
120120 a[0] = 20;
121 testing.expectEqual(timingSafeCompare(u8, &a, &b, .Big), .gt);
122 testing.expectEqual(timingSafeCompare(u8, &a, &b, .Little), .lt);
121 try testing.expectEqual(timingSafeCompare(u8, &a, &b, .Big), .gt);
122 try testing.expectEqual(timingSafeCompare(u8, &a, &b, .Little), .lt);
123123}
124124
125125test "crypto.utils.secureZero" {
......@@ -129,5 +129,5 @@ test "crypto.utils.secureZero" {
129129 mem.set(u8, a[0..], 0);
130130 secureZero(u8, b[0..]);
131131
132 testing.expectEqualSlices(u8, a[0..], b[0..]);
132 try testing.expectEqualSlices(u8, a[0..], b[0..]);
133133}
lib/std/cstr.zig+7-7
......@@ -27,13 +27,13 @@ pub fn cmp(a: [*:0]const u8, b: [*:0]const u8) i8 {
2727}
2828
2929test "cstr fns" {
30 comptime testCStrFnsImpl();
31 testCStrFnsImpl();
30 comptime try testCStrFnsImpl();
31 try testCStrFnsImpl();
3232}
3333
34fn testCStrFnsImpl() void {
35 testing.expect(cmp("aoeu", "aoez") == -1);
36 testing.expect(mem.len("123456789") == 9);
34fn testCStrFnsImpl() !void {
35 try testing.expect(cmp("aoeu", "aoez") == -1);
36 try testing.expect(mem.len("123456789") == 9);
3737}
3838
3939/// Returns a mutable, null-terminated slice with the same length as `slice`.
......@@ -48,8 +48,8 @@ pub fn addNullByte(allocator: *mem.Allocator, slice: []const u8) ![:0]u8 {
4848test "addNullByte" {
4949 const slice = try addNullByte(std.testing.allocator, "hello"[0..4]);
5050 defer std.testing.allocator.free(slice);
51 testing.expect(slice.len == 4);
52 testing.expect(slice[4] == 0);
51 try testing.expect(slice.len == 4);
52 try testing.expect(slice[4] == 0);
5353}
5454
5555pub const NullTerminated2DArray = struct {
lib/std/dynamic_library.zig+1-1
......@@ -408,7 +408,7 @@ test "dynamic_library" {
408408 };
409409
410410 const dynlib = DynLib.open(libname) catch |err| {
411 testing.expect(err == error.FileNotFound);
411 try testing.expect(err == error.FileNotFound);
412412 return;
413413 };
414414}
lib/std/elf.zig+1-1
......@@ -565,7 +565,7 @@ test "bswapAllFields" {
565565 .ch_addralign = 0x12124242,
566566 };
567567 bswapAllFields(Elf32_Chdr, &s);
568 std.testing.expectEqual(Elf32_Chdr{
568 try std.testing.expectEqual(Elf32_Chdr{
569569 .ch_type = 0x34123412,
570570 .ch_size = 0x78567856,
571571 .ch_addralign = 0x42421212,
lib/std/enums.zig+57-57
......@@ -119,10 +119,10 @@ test "std.enums.directEnumArray" {
119119 .c = true,
120120 });
121121
122 testing.expectEqual([7]bool, @TypeOf(array));
123 testing.expectEqual(true, array[4]);
124 testing.expectEqual(false, array[6]);
125 testing.expectEqual(true, array[2]);
122 try testing.expectEqual([7]bool, @TypeOf(array));
123 try testing.expectEqual(true, array[4]);
124 try testing.expectEqual(false, array[6]);
125 try testing.expectEqual(true, array[2]);
126126}
127127
128128/// Initializes an array of Data which can be indexed by
......@@ -160,10 +160,10 @@ test "std.enums.directEnumArrayDefault" {
160160 .b = runtime_false,
161161 });
162162
163 testing.expectEqual([7]bool, @TypeOf(array));
164 testing.expectEqual(true, array[4]);
165 testing.expectEqual(false, array[6]);
166 testing.expectEqual(false, array[2]);
163 try testing.expectEqual([7]bool, @TypeOf(array));
164 try testing.expectEqual(true, array[4]);
165 try testing.expectEqual(false, array[6]);
166 try testing.expectEqual(false, array[2]);
167167}
168168
169169/// Cast an enum literal, value, or string to the enum value of type E
......@@ -190,23 +190,23 @@ pub fn nameCast(comptime E: type, comptime value: anytype) E {
190190test "std.enums.nameCast" {
191191 const A = enum(u1) { a = 0, b = 1 };
192192 const B = enum(u1) { a = 1, b = 0 };
193 testing.expectEqual(A.a, nameCast(A, .a));
194 testing.expectEqual(A.a, nameCast(A, A.a));
195 testing.expectEqual(A.a, nameCast(A, B.a));
196 testing.expectEqual(A.a, nameCast(A, "a"));
197 testing.expectEqual(A.a, nameCast(A, @as(*const [1]u8, "a")));
198 testing.expectEqual(A.a, nameCast(A, @as([:0]const u8, "a")));
199 testing.expectEqual(A.a, nameCast(A, @as([]const u8, "a")));
200
201 testing.expectEqual(B.a, nameCast(B, .a));
202 testing.expectEqual(B.a, nameCast(B, A.a));
203 testing.expectEqual(B.a, nameCast(B, B.a));
204 testing.expectEqual(B.a, nameCast(B, "a"));
205
206 testing.expectEqual(B.b, nameCast(B, .b));
207 testing.expectEqual(B.b, nameCast(B, A.b));
208 testing.expectEqual(B.b, nameCast(B, B.b));
209 testing.expectEqual(B.b, nameCast(B, "b"));
193 try testing.expectEqual(A.a, nameCast(A, .a));
194 try testing.expectEqual(A.a, nameCast(A, A.a));
195 try testing.expectEqual(A.a, nameCast(A, B.a));
196 try testing.expectEqual(A.a, nameCast(A, "a"));
197 try testing.expectEqual(A.a, nameCast(A, @as(*const [1]u8, "a")));
198 try testing.expectEqual(A.a, nameCast(A, @as([:0]const u8, "a")));
199 try testing.expectEqual(A.a, nameCast(A, @as([]const u8, "a")));
200
201 try testing.expectEqual(B.a, nameCast(B, .a));
202 try testing.expectEqual(B.a, nameCast(B, A.a));
203 try testing.expectEqual(B.a, nameCast(B, B.a));
204 try testing.expectEqual(B.a, nameCast(B, "a"));
205
206 try testing.expectEqual(B.b, nameCast(B, .b));
207 try testing.expectEqual(B.b, nameCast(B, A.b));
208 try testing.expectEqual(B.b, nameCast(B, B.b));
209 try testing.expectEqual(B.b, nameCast(B, "b"));
210210}
211211
212212/// A set of enum elements, backed by a bitfield. If the enum
......@@ -791,62 +791,62 @@ test "std.enums.EnumIndexer dense zeroed" {
791791 const E = enum(u2) { b = 1, a = 0, c = 2 };
792792 const Indexer = EnumIndexer(E);
793793 ensureIndexer(Indexer);
794 testing.expectEqual(E, Indexer.Key);
795 testing.expectEqual(@as(usize, 3), Indexer.count);
794 try testing.expectEqual(E, Indexer.Key);
795 try testing.expectEqual(@as(usize, 3), Indexer.count);
796796
797 testing.expectEqual(@as(usize, 0), Indexer.indexOf(.a));
798 testing.expectEqual(@as(usize, 1), Indexer.indexOf(.b));
799 testing.expectEqual(@as(usize, 2), Indexer.indexOf(.c));
797 try testing.expectEqual(@as(usize, 0), Indexer.indexOf(.a));
798 try testing.expectEqual(@as(usize, 1), Indexer.indexOf(.b));
799 try testing.expectEqual(@as(usize, 2), Indexer.indexOf(.c));
800800
801 testing.expectEqual(E.a, Indexer.keyForIndex(0));
802 testing.expectEqual(E.b, Indexer.keyForIndex(1));
803 testing.expectEqual(E.c, Indexer.keyForIndex(2));
801 try testing.expectEqual(E.a, Indexer.keyForIndex(0));
802 try testing.expectEqual(E.b, Indexer.keyForIndex(1));
803 try testing.expectEqual(E.c, Indexer.keyForIndex(2));
804804}
805805
806806test "std.enums.EnumIndexer dense positive" {
807807 const E = enum(u4) { c = 6, a = 4, b = 5 };
808808 const Indexer = EnumIndexer(E);
809809 ensureIndexer(Indexer);
810 testing.expectEqual(E, Indexer.Key);
811 testing.expectEqual(@as(usize, 3), Indexer.count);
810 try testing.expectEqual(E, Indexer.Key);
811 try testing.expectEqual(@as(usize, 3), Indexer.count);
812812
813 testing.expectEqual(@as(usize, 0), Indexer.indexOf(.a));
814 testing.expectEqual(@as(usize, 1), Indexer.indexOf(.b));
815 testing.expectEqual(@as(usize, 2), Indexer.indexOf(.c));
813 try testing.expectEqual(@as(usize, 0), Indexer.indexOf(.a));
814 try testing.expectEqual(@as(usize, 1), Indexer.indexOf(.b));
815 try testing.expectEqual(@as(usize, 2), Indexer.indexOf(.c));
816816
817 testing.expectEqual(E.a, Indexer.keyForIndex(0));
818 testing.expectEqual(E.b, Indexer.keyForIndex(1));
819 testing.expectEqual(E.c, Indexer.keyForIndex(2));
817 try testing.expectEqual(E.a, Indexer.keyForIndex(0));
818 try testing.expectEqual(E.b, Indexer.keyForIndex(1));
819 try testing.expectEqual(E.c, Indexer.keyForIndex(2));
820820}
821821
822822test "std.enums.EnumIndexer dense negative" {
823823 const E = enum(i4) { a = -6, c = -4, b = -5 };
824824 const Indexer = EnumIndexer(E);
825825 ensureIndexer(Indexer);
826 testing.expectEqual(E, Indexer.Key);
827 testing.expectEqual(@as(usize, 3), Indexer.count);
826 try testing.expectEqual(E, Indexer.Key);
827 try testing.expectEqual(@as(usize, 3), Indexer.count);
828828
829 testing.expectEqual(@as(usize, 0), Indexer.indexOf(.a));
830 testing.expectEqual(@as(usize, 1), Indexer.indexOf(.b));
831 testing.expectEqual(@as(usize, 2), Indexer.indexOf(.c));
829 try testing.expectEqual(@as(usize, 0), Indexer.indexOf(.a));
830 try testing.expectEqual(@as(usize, 1), Indexer.indexOf(.b));
831 try testing.expectEqual(@as(usize, 2), Indexer.indexOf(.c));
832832
833 testing.expectEqual(E.a, Indexer.keyForIndex(0));
834 testing.expectEqual(E.b, Indexer.keyForIndex(1));
835 testing.expectEqual(E.c, Indexer.keyForIndex(2));
833 try testing.expectEqual(E.a, Indexer.keyForIndex(0));
834 try testing.expectEqual(E.b, Indexer.keyForIndex(1));
835 try testing.expectEqual(E.c, Indexer.keyForIndex(2));
836836}
837837
838838test "std.enums.EnumIndexer sparse" {
839839 const E = enum(i4) { a = -2, c = 6, b = 4 };
840840 const Indexer = EnumIndexer(E);
841841 ensureIndexer(Indexer);
842 testing.expectEqual(E, Indexer.Key);
843 testing.expectEqual(@as(usize, 3), Indexer.count);
842 try testing.expectEqual(E, Indexer.Key);
843 try testing.expectEqual(@as(usize, 3), Indexer.count);
844844
845 testing.expectEqual(@as(usize, 0), Indexer.indexOf(.a));
846 testing.expectEqual(@as(usize, 1), Indexer.indexOf(.b));
847 testing.expectEqual(@as(usize, 2), Indexer.indexOf(.c));
845 try testing.expectEqual(@as(usize, 0), Indexer.indexOf(.a));
846 try testing.expectEqual(@as(usize, 1), Indexer.indexOf(.b));
847 try testing.expectEqual(@as(usize, 2), Indexer.indexOf(.c));
848848
849 testing.expectEqual(E.a, Indexer.keyForIndex(0));
850 testing.expectEqual(E.b, Indexer.keyForIndex(1));
851 testing.expectEqual(E.c, Indexer.keyForIndex(2));
849 try testing.expectEqual(E.a, Indexer.keyForIndex(0));
850 try testing.expectEqual(E.b, Indexer.keyForIndex(1));
851 try testing.expectEqual(E.c, Indexer.keyForIndex(2));
852852}
lib/std/event/batch.zig+2-2
......@@ -119,12 +119,12 @@ test "std.event.Batch" {
119119 batch.add(&async sleepALittle(&count));
120120 batch.add(&async increaseByTen(&count));
121121 batch.wait();
122 testing.expect(count == 11);
122 try testing.expect(count == 11);
123123
124124 var another = Batch(anyerror!void, 2, .auto_async).init();
125125 another.add(&async somethingElse());
126126 another.add(&async doSomethingThatFails());
127 testing.expectError(error.ItBroke, another.wait());
127 try testing.expectError(error.ItBroke, another.wait());
128128}
129129
130130fn sleepALittle(count: *usize) void {
lib/std/event/channel.zig+7-7
......@@ -310,25 +310,25 @@ test "std.event.Channel wraparound" {
310310 // the buffer wraps around, make sure it doesn't crash.
311311 var result: i32 = undefined;
312312 channel.put(5);
313 testing.expectEqual(@as(i32, 5), channel.get());
313 try testing.expectEqual(@as(i32, 5), channel.get());
314314 channel.put(6);
315 testing.expectEqual(@as(i32, 6), channel.get());
315 try testing.expectEqual(@as(i32, 6), channel.get());
316316 channel.put(7);
317 testing.expectEqual(@as(i32, 7), channel.get());
317 try testing.expectEqual(@as(i32, 7), channel.get());
318318}
319319fn testChannelGetter(channel: *Channel(i32)) callconv(.Async) void {
320320 const value1 = channel.get();
321 testing.expect(value1 == 1234);
321 try testing.expect(value1 == 1234);
322322
323323 const value2 = channel.get();
324 testing.expect(value2 == 4567);
324 try testing.expect(value2 == 4567);
325325
326326 const value3 = channel.getOrNull();
327 testing.expect(value3 == null);
327 try testing.expect(value3 == null);
328328
329329 var last_put = async testPut(channel, 4444);
330330 const value4 = channel.getOrNull();
331 testing.expect(value4.? == 4444);
331 try testing.expect(value4.? == 4444);
332332 await last_put;
333333}
334334fn testChannelPutter(channel: *Channel(i32)) callconv(.Async) void {
lib/std/event/future.zig+1-1
......@@ -107,7 +107,7 @@ fn testFuture() void {
107107
108108 const result = (await a) + (await b);
109109
110 testing.expect(result == 12);
110 try testing.expect(result == 12);
111111}
112112
113113fn waitOnFuture(future: *Future(i32)) i32 {
lib/std/event/group.zig+2-2
......@@ -140,14 +140,14 @@ fn testGroup(allocator: *Allocator) callconv(.Async) void {
140140 var increase_by_ten_frame = async increaseByTen(&count);
141141 group.add(&increase_by_ten_frame) catch @panic("memory");
142142 group.wait();
143 testing.expect(count == 11);
143 try testing.expect(count == 11);
144144
145145 var another = Group(anyerror!void).init(allocator);
146146 var something_else_frame = async somethingElse();
147147 another.add(&something_else_frame) catch @panic("memory");
148148 var something_that_fails_frame = async doSomethingThatFails();
149149 another.add(&something_that_fails_frame) catch @panic("memory");
150 testing.expectError(error.ItBroke, another.wait());
150 try testing.expectError(error.ItBroke, another.wait());
151151}
152152fn sleepALittle(count: *usize) callconv(.Async) void {
153153 std.time.sleep(1 * std.time.ns_per_ms);
lib/std/event/lock.zig+1-1
......@@ -136,7 +136,7 @@ test "std.event.Lock" {
136136 testLock(&lock);
137137
138138 const expected_result = [1]i32{3 * @intCast(i32, shared_test_data.len)} ** shared_test_data.len;
139 testing.expectEqualSlices(i32, &expected_result, &shared_test_data);
139 try testing.expectEqualSlices(i32, &expected_result, &shared_test_data);
140140}
141141fn testLock(lock: *Lock) void {
142142 var handle1 = async lockRunner(lock);
lib/std/event/loop.zig+3-3
......@@ -1655,7 +1655,7 @@ fn testEventLoop() i32 {
16551655
16561656fn testEventLoop2(h: anyframe->i32, did_it: *bool) void {
16571657 const value = await h;
1658 testing.expect(value == 1234);
1658 try testing.expect(value == 1234);
16591659 did_it.* = true;
16601660}
16611661
......@@ -1682,7 +1682,7 @@ test "std.event.Loop - runDetached" {
16821682 // with the previous runDetached.
16831683 loop.run();
16841684
1685 testing.expect(testRunDetachedData == 1);
1685 try testing.expect(testRunDetachedData == 1);
16861686}
16871687
16881688fn testRunDetached() void {
......@@ -1705,7 +1705,7 @@ test "std.event.Loop - sleep" {
17051705 for (frames) |*frame|
17061706 await frame;
17071707
1708 testing.expect(sleep_count == frames.len);
1708 try testing.expect(sleep_count == frames.len);
17091709}
17101710
17111711fn testSleep(wait_ns: u64, sleep_count: *usize) void {
lib/std/event/rwlock.zig+3-3
......@@ -228,7 +228,7 @@ test "std.event.RwLock" {
228228 const handle = testLock(std.heap.page_allocator, &lock);
229229
230230 const expected_result = [1]i32{shared_it_count * @intCast(i32, shared_test_data.len)} ** shared_test_data.len;
231 testing.expectEqualSlices(i32, expected_result, shared_test_data);
231 try testing.expectEqualSlices(i32, expected_result, shared_test_data);
232232}
233233fn testLock(allocator: *Allocator, lock: *RwLock) callconv(.Async) void {
234234 var read_nodes: [100]Loop.NextTickNode = undefined;
......@@ -290,7 +290,7 @@ fn readRunner(lock: *RwLock) callconv(.Async) void {
290290 const handle = await lock_promise;
291291 defer handle.release();
292292
293 testing.expect(shared_test_index == 0);
294 testing.expect(shared_test_data[i] == @intCast(i32, shared_count));
293 try testing.expect(shared_test_index == 0);
294 try testing.expect(shared_test_data[i] == @intCast(i32, shared_count));
295295 }
296296}
lib/std/fifo.zig+38-38
......@@ -402,59 +402,59 @@ test "LinearFifo(u8, .Dynamic)" {
402402 defer fifo.deinit();
403403
404404 try fifo.write("HELLO");
405 testing.expectEqual(@as(usize, 5), fifo.readableLength());
406 testing.expectEqualSlices(u8, "HELLO", fifo.readableSlice(0));
405 try testing.expectEqual(@as(usize, 5), fifo.readableLength());
406 try testing.expectEqualSlices(u8, "HELLO", fifo.readableSlice(0));
407407
408408 {
409409 var i: usize = 0;
410410 while (i < 5) : (i += 1) {
411411 try fifo.write(&[_]u8{fifo.peekItem(i)});
412412 }
413 testing.expectEqual(@as(usize, 10), fifo.readableLength());
414 testing.expectEqualSlices(u8, "HELLOHELLO", fifo.readableSlice(0));
413 try testing.expectEqual(@as(usize, 10), fifo.readableLength());
414 try testing.expectEqualSlices(u8, "HELLOHELLO", fifo.readableSlice(0));
415415 }
416416
417417 {
418 testing.expectEqual(@as(u8, 'H'), fifo.readItem().?);
419 testing.expectEqual(@as(u8, 'E'), fifo.readItem().?);
420 testing.expectEqual(@as(u8, 'L'), fifo.readItem().?);
421 testing.expectEqual(@as(u8, 'L'), fifo.readItem().?);
422 testing.expectEqual(@as(u8, 'O'), fifo.readItem().?);
418 try testing.expectEqual(@as(u8, 'H'), fifo.readItem().?);
419 try testing.expectEqual(@as(u8, 'E'), fifo.readItem().?);
420 try testing.expectEqual(@as(u8, 'L'), fifo.readItem().?);
421 try testing.expectEqual(@as(u8, 'L'), fifo.readItem().?);
422 try testing.expectEqual(@as(u8, 'O'), fifo.readItem().?);
423423 }
424 testing.expectEqual(@as(usize, 5), fifo.readableLength());
424 try testing.expectEqual(@as(usize, 5), fifo.readableLength());
425425
426426 { // Writes that wrap around
427 testing.expectEqual(@as(usize, 11), fifo.writableLength());
428 testing.expectEqual(@as(usize, 6), fifo.writableSlice(0).len);
427 try testing.expectEqual(@as(usize, 11), fifo.writableLength());
428 try testing.expectEqual(@as(usize, 6), fifo.writableSlice(0).len);
429429 fifo.writeAssumeCapacity("6<chars<11");
430 testing.expectEqualSlices(u8, "HELLO6<char", fifo.readableSlice(0));
431 testing.expectEqualSlices(u8, "s<11", fifo.readableSlice(11));
432 testing.expectEqualSlices(u8, "11", fifo.readableSlice(13));
433 testing.expectEqualSlices(u8, "", fifo.readableSlice(15));
430 try testing.expectEqualSlices(u8, "HELLO6<char", fifo.readableSlice(0));
431 try testing.expectEqualSlices(u8, "s<11", fifo.readableSlice(11));
432 try testing.expectEqualSlices(u8, "11", fifo.readableSlice(13));
433 try testing.expectEqualSlices(u8, "", fifo.readableSlice(15));
434434 fifo.discard(11);
435 testing.expectEqualSlices(u8, "s<11", fifo.readableSlice(0));
435 try testing.expectEqualSlices(u8, "s<11", fifo.readableSlice(0));
436436 fifo.discard(4);
437 testing.expectEqual(@as(usize, 0), fifo.readableLength());
437 try testing.expectEqual(@as(usize, 0), fifo.readableLength());
438438 }
439439
440440 {
441441 const buf = try fifo.writableWithSize(12);
442 testing.expectEqual(@as(usize, 12), buf.len);
442 try testing.expectEqual(@as(usize, 12), buf.len);
443443 var i: u8 = 0;
444444 while (i < 10) : (i += 1) {
445445 buf[i] = i + 'a';
446446 }
447447 fifo.update(10);
448 testing.expectEqualSlices(u8, "abcdefghij", fifo.readableSlice(0));
448 try testing.expectEqualSlices(u8, "abcdefghij", fifo.readableSlice(0));
449449 }
450450
451451 {
452452 try fifo.unget("prependedstring");
453453 var result: [30]u8 = undefined;
454 testing.expectEqualSlices(u8, "prependedstringabcdefghij", result[0..fifo.read(&result)]);
454 try testing.expectEqualSlices(u8, "prependedstringabcdefghij", result[0..fifo.read(&result)]);
455455 try fifo.unget("b");
456456 try fifo.unget("a");
457 testing.expectEqualSlices(u8, "ab", result[0..fifo.read(&result)]);
457 try testing.expectEqualSlices(u8, "ab", result[0..fifo.read(&result)]);
458458 }
459459
460460 fifo.shrink(0);
......@@ -462,17 +462,17 @@ test "LinearFifo(u8, .Dynamic)" {
462462 {
463463 try fifo.writer().print("{s}, {s}!", .{ "Hello", "World" });
464464 var result: [30]u8 = undefined;
465 testing.expectEqualSlices(u8, "Hello, World!", result[0..fifo.read(&result)]);
466 testing.expectEqual(@as(usize, 0), fifo.readableLength());
465 try testing.expectEqualSlices(u8, "Hello, World!", result[0..fifo.read(&result)]);
466 try testing.expectEqual(@as(usize, 0), fifo.readableLength());
467467 }
468468
469469 {
470470 try fifo.writer().writeAll("This is a test");
471471 var result: [30]u8 = undefined;
472 testing.expectEqualSlices(u8, "This", (try fifo.reader().readUntilDelimiterOrEof(&result, ' ')).?);
473 testing.expectEqualSlices(u8, "is", (try fifo.reader().readUntilDelimiterOrEof(&result, ' ')).?);
474 testing.expectEqualSlices(u8, "a", (try fifo.reader().readUntilDelimiterOrEof(&result, ' ')).?);
475 testing.expectEqualSlices(u8, "test", (try fifo.reader().readUntilDelimiterOrEof(&result, ' ')).?);
472 try testing.expectEqualSlices(u8, "This", (try fifo.reader().readUntilDelimiterOrEof(&result, ' ')).?);
473 try testing.expectEqualSlices(u8, "is", (try fifo.reader().readUntilDelimiterOrEof(&result, ' ')).?);
474 try testing.expectEqualSlices(u8, "a", (try fifo.reader().readUntilDelimiterOrEof(&result, ' ')).?);
475 try testing.expectEqualSlices(u8, "test", (try fifo.reader().readUntilDelimiterOrEof(&result, ' ')).?);
476476 }
477477
478478 {
......@@ -481,7 +481,7 @@ test "LinearFifo(u8, .Dynamic)" {
481481 var out_buf: [50]u8 = undefined;
482482 var out_fbs = std.io.fixedBufferStream(&out_buf);
483483 try fifo.pump(in_fbs.reader(), out_fbs.writer());
484 testing.expectEqualSlices(u8, in_fbs.buffer, out_fbs.getWritten());
484 try testing.expectEqualSlices(u8, in_fbs.buffer, out_fbs.getWritten());
485485 }
486486}
487487
......@@ -498,28 +498,28 @@ test "LinearFifo" {
498498 defer fifo.deinit();
499499
500500 try fifo.write(&[_]T{ 0, 1, 1, 0, 1 });
501 testing.expectEqual(@as(usize, 5), fifo.readableLength());
501 try testing.expectEqual(@as(usize, 5), fifo.readableLength());
502502
503503 {
504 testing.expectEqual(@as(T, 0), fifo.readItem().?);
505 testing.expectEqual(@as(T, 1), fifo.readItem().?);
506 testing.expectEqual(@as(T, 1), fifo.readItem().?);
507 testing.expectEqual(@as(T, 0), fifo.readItem().?);
508 testing.expectEqual(@as(T, 1), fifo.readItem().?);
509 testing.expectEqual(@as(usize, 0), fifo.readableLength());
504 try testing.expectEqual(@as(T, 0), fifo.readItem().?);
505 try testing.expectEqual(@as(T, 1), fifo.readItem().?);
506 try testing.expectEqual(@as(T, 1), fifo.readItem().?);
507 try testing.expectEqual(@as(T, 0), fifo.readItem().?);
508 try testing.expectEqual(@as(T, 1), fifo.readItem().?);
509 try testing.expectEqual(@as(usize, 0), fifo.readableLength());
510510 }
511511
512512 {
513513 try fifo.writeItem(1);
514514 try fifo.writeItem(1);
515515 try fifo.writeItem(1);
516 testing.expectEqual(@as(usize, 3), fifo.readableLength());
516 try testing.expectEqual(@as(usize, 3), fifo.readableLength());
517517 }
518518
519519 {
520520 var readBuf: [3]T = undefined;
521521 const n = fifo.read(&readBuf);
522 testing.expectEqual(@as(usize, 3), n); // NOTE: It should be the number of items.
522 try testing.expectEqual(@as(usize, 3), n); // NOTE: It should be the number of items.
523523 }
524524 }
525525 }
lib/std/fmt.zig+89-89
......@@ -1422,7 +1422,7 @@ test "fmtDuration" {
14221422 .{ .s = "1y1m999ns", .d = 365 * std.time.ns_per_day + std.time.ns_per_min + 999 },
14231423 }) |tc| {
14241424 const slice = try bufPrint(&buf, "{}", .{fmtDuration(tc.d)});
1425 std.testing.expectEqualStrings(tc.s, slice);
1425 try std.testing.expectEqualStrings(tc.s, slice);
14261426 }
14271427}
14281428
......@@ -1479,54 +1479,54 @@ pub fn parseInt(comptime T: type, buf: []const u8, radix: u8) ParseIntError!T {
14791479}
14801480
14811481test "parseInt" {
1482 std.testing.expect((try parseInt(i32, "-10", 10)) == -10);
1483 std.testing.expect((try parseInt(i32, "+10", 10)) == 10);
1484 std.testing.expect((try parseInt(u32, "+10", 10)) == 10);
1485 std.testing.expectError(error.Overflow, parseInt(u32, "-10", 10));
1486 std.testing.expectError(error.InvalidCharacter, parseInt(u32, " 10", 10));
1487 std.testing.expectError(error.InvalidCharacter, parseInt(u32, "10 ", 10));
1488 std.testing.expectError(error.InvalidCharacter, parseInt(u32, "_10_", 10));
1489 std.testing.expectError(error.InvalidCharacter, parseInt(u32, "0x_10_", 10));
1490 std.testing.expectError(error.InvalidCharacter, parseInt(u32, "0x10_", 10));
1491 std.testing.expectError(error.InvalidCharacter, parseInt(u32, "0x_10", 10));
1492 std.testing.expect((try parseInt(u8, "255", 10)) == 255);
1493 std.testing.expectError(error.Overflow, parseInt(u8, "256", 10));
1482 try std.testing.expect((try parseInt(i32, "-10", 10)) == -10);
1483 try std.testing.expect((try parseInt(i32, "+10", 10)) == 10);
1484 try std.testing.expect((try parseInt(u32, "+10", 10)) == 10);
1485 try std.testing.expectError(error.Overflow, parseInt(u32, "-10", 10));
1486 try std.testing.expectError(error.InvalidCharacter, parseInt(u32, " 10", 10));
1487 try std.testing.expectError(error.InvalidCharacter, parseInt(u32, "10 ", 10));
1488 try std.testing.expectError(error.InvalidCharacter, parseInt(u32, "_10_", 10));
1489 try std.testing.expectError(error.InvalidCharacter, parseInt(u32, "0x_10_", 10));
1490 try std.testing.expectError(error.InvalidCharacter, parseInt(u32, "0x10_", 10));
1491 try std.testing.expectError(error.InvalidCharacter, parseInt(u32, "0x_10", 10));
1492 try std.testing.expect((try parseInt(u8, "255", 10)) == 255);
1493 try std.testing.expectError(error.Overflow, parseInt(u8, "256", 10));
14941494
14951495 // +0 and -0 should work for unsigned
1496 std.testing.expect((try parseInt(u8, "-0", 10)) == 0);
1497 std.testing.expect((try parseInt(u8, "+0", 10)) == 0);
1496 try std.testing.expect((try parseInt(u8, "-0", 10)) == 0);
1497 try std.testing.expect((try parseInt(u8, "+0", 10)) == 0);
14981498
14991499 // ensure minInt is parsed correctly
1500 std.testing.expect((try parseInt(i8, "-128", 10)) == math.minInt(i8));
1501 std.testing.expect((try parseInt(i43, "-4398046511104", 10)) == math.minInt(i43));
1500 try std.testing.expect((try parseInt(i8, "-128", 10)) == math.minInt(i8));
1501 try std.testing.expect((try parseInt(i43, "-4398046511104", 10)) == math.minInt(i43));
15021502
15031503 // empty string or bare +- is invalid
1504 std.testing.expectError(error.InvalidCharacter, parseInt(u32, "", 10));
1505 std.testing.expectError(error.InvalidCharacter, parseInt(i32, "", 10));
1506 std.testing.expectError(error.InvalidCharacter, parseInt(u32, "+", 10));
1507 std.testing.expectError(error.InvalidCharacter, parseInt(i32, "+", 10));
1508 std.testing.expectError(error.InvalidCharacter, parseInt(u32, "-", 10));
1509 std.testing.expectError(error.InvalidCharacter, parseInt(i32, "-", 10));
1504 try std.testing.expectError(error.InvalidCharacter, parseInt(u32, "", 10));
1505 try std.testing.expectError(error.InvalidCharacter, parseInt(i32, "", 10));
1506 try std.testing.expectError(error.InvalidCharacter, parseInt(u32, "+", 10));
1507 try std.testing.expectError(error.InvalidCharacter, parseInt(i32, "+", 10));
1508 try std.testing.expectError(error.InvalidCharacter, parseInt(u32, "-", 10));
1509 try std.testing.expectError(error.InvalidCharacter, parseInt(i32, "-", 10));
15101510
15111511 // autodectect the radix
1512 std.testing.expect((try parseInt(i32, "111", 0)) == 111);
1513 std.testing.expect((try parseInt(i32, "1_1_1", 0)) == 111);
1514 std.testing.expect((try parseInt(i32, "1_1_1", 0)) == 111);
1515 std.testing.expect((try parseInt(i32, "+0b111", 0)) == 7);
1516 std.testing.expect((try parseInt(i32, "+0b1_11", 0)) == 7);
1517 std.testing.expect((try parseInt(i32, "+0o111", 0)) == 73);
1518 std.testing.expect((try parseInt(i32, "+0o11_1", 0)) == 73);
1519 std.testing.expect((try parseInt(i32, "+0x111", 0)) == 273);
1520 std.testing.expect((try parseInt(i32, "-0b111", 0)) == -7);
1521 std.testing.expect((try parseInt(i32, "-0b11_1", 0)) == -7);
1522 std.testing.expect((try parseInt(i32, "-0o111", 0)) == -73);
1523 std.testing.expect((try parseInt(i32, "-0x111", 0)) == -273);
1524 std.testing.expect((try parseInt(i32, "-0x1_11", 0)) == -273);
1512 try std.testing.expect((try parseInt(i32, "111", 0)) == 111);
1513 try std.testing.expect((try parseInt(i32, "1_1_1", 0)) == 111);
1514 try std.testing.expect((try parseInt(i32, "1_1_1", 0)) == 111);
1515 try std.testing.expect((try parseInt(i32, "+0b111", 0)) == 7);
1516 try std.testing.expect((try parseInt(i32, "+0b1_11", 0)) == 7);
1517 try std.testing.expect((try parseInt(i32, "+0o111", 0)) == 73);
1518 try std.testing.expect((try parseInt(i32, "+0o11_1", 0)) == 73);
1519 try std.testing.expect((try parseInt(i32, "+0x111", 0)) == 273);
1520 try std.testing.expect((try parseInt(i32, "-0b111", 0)) == -7);
1521 try std.testing.expect((try parseInt(i32, "-0b11_1", 0)) == -7);
1522 try std.testing.expect((try parseInt(i32, "-0o111", 0)) == -73);
1523 try std.testing.expect((try parseInt(i32, "-0x111", 0)) == -273);
1524 try std.testing.expect((try parseInt(i32, "-0x1_11", 0)) == -273);
15251525
15261526 // bare binary/octal/decimal prefix is invalid
1527 std.testing.expectError(error.InvalidCharacter, parseInt(u32, "0b", 0));
1528 std.testing.expectError(error.InvalidCharacter, parseInt(u32, "0o", 0));
1529 std.testing.expectError(error.InvalidCharacter, parseInt(u32, "0x", 0));
1527 try std.testing.expectError(error.InvalidCharacter, parseInt(u32, "0b", 0));
1528 try std.testing.expectError(error.InvalidCharacter, parseInt(u32, "0o", 0));
1529 try std.testing.expectError(error.InvalidCharacter, parseInt(u32, "0x", 0));
15301530}
15311531
15321532fn parseWithSign(
......@@ -1598,39 +1598,39 @@ pub fn parseUnsigned(comptime T: type, buf: []const u8, radix: u8) ParseIntError
15981598}
15991599
16001600test "parseUnsigned" {
1601 std.testing.expect((try parseUnsigned(u16, "050124", 10)) == 50124);
1602 std.testing.expect((try parseUnsigned(u16, "65535", 10)) == 65535);
1603 std.testing.expect((try parseUnsigned(u16, "65_535", 10)) == 65535);
1604 std.testing.expectError(error.Overflow, parseUnsigned(u16, "65536", 10));
1601 try std.testing.expect((try parseUnsigned(u16, "050124", 10)) == 50124);
1602 try std.testing.expect((try parseUnsigned(u16, "65535", 10)) == 65535);
1603 try std.testing.expect((try parseUnsigned(u16, "65_535", 10)) == 65535);
1604 try std.testing.expectError(error.Overflow, parseUnsigned(u16, "65536", 10));
16051605
1606 std.testing.expect((try parseUnsigned(u64, "0ffffffffffffffff", 16)) == 0xffffffffffffffff);
1607 std.testing.expect((try parseUnsigned(u64, "0f_fff_fff_fff_fff_fff", 16)) == 0xffffffffffffffff);
1608 std.testing.expectError(error.Overflow, parseUnsigned(u64, "10000000000000000", 16));
1606 try std.testing.expect((try parseUnsigned(u64, "0ffffffffffffffff", 16)) == 0xffffffffffffffff);
1607 try std.testing.expect((try parseUnsigned(u64, "0f_fff_fff_fff_fff_fff", 16)) == 0xffffffffffffffff);
1608 try std.testing.expectError(error.Overflow, parseUnsigned(u64, "10000000000000000", 16));
16091609
1610 std.testing.expect((try parseUnsigned(u32, "DeadBeef", 16)) == 0xDEADBEEF);
1610 try std.testing.expect((try parseUnsigned(u32, "DeadBeef", 16)) == 0xDEADBEEF);
16111611
1612 std.testing.expect((try parseUnsigned(u7, "1", 10)) == 1);
1613 std.testing.expect((try parseUnsigned(u7, "1000", 2)) == 8);
1612 try std.testing.expect((try parseUnsigned(u7, "1", 10)) == 1);
1613 try std.testing.expect((try parseUnsigned(u7, "1000", 2)) == 8);
16141614
1615 std.testing.expectError(error.InvalidCharacter, parseUnsigned(u32, "f", 10));
1616 std.testing.expectError(error.InvalidCharacter, parseUnsigned(u8, "109", 8));
1615 try std.testing.expectError(error.InvalidCharacter, parseUnsigned(u32, "f", 10));
1616 try std.testing.expectError(error.InvalidCharacter, parseUnsigned(u8, "109", 8));
16171617
1618 std.testing.expect((try parseUnsigned(u32, "NUMBER", 36)) == 1442151747);
1618 try std.testing.expect((try parseUnsigned(u32, "NUMBER", 36)) == 1442151747);
16191619
16201620 // these numbers should fit even though the radix itself doesn't fit in the destination type
1621 std.testing.expect((try parseUnsigned(u1, "0", 10)) == 0);
1622 std.testing.expect((try parseUnsigned(u1, "1", 10)) == 1);
1623 std.testing.expectError(error.Overflow, parseUnsigned(u1, "2", 10));
1624 std.testing.expect((try parseUnsigned(u1, "001", 16)) == 1);
1625 std.testing.expect((try parseUnsigned(u2, "3", 16)) == 3);
1626 std.testing.expectError(error.Overflow, parseUnsigned(u2, "4", 16));
1621 try std.testing.expect((try parseUnsigned(u1, "0", 10)) == 0);
1622 try std.testing.expect((try parseUnsigned(u1, "1", 10)) == 1);
1623 try std.testing.expectError(error.Overflow, parseUnsigned(u1, "2", 10));
1624 try std.testing.expect((try parseUnsigned(u1, "001", 16)) == 1);
1625 try std.testing.expect((try parseUnsigned(u2, "3", 16)) == 3);
1626 try std.testing.expectError(error.Overflow, parseUnsigned(u2, "4", 16));
16271627
16281628 // parseUnsigned does not expect a sign
1629 std.testing.expectError(error.InvalidCharacter, parseUnsigned(u8, "+0", 10));
1630 std.testing.expectError(error.InvalidCharacter, parseUnsigned(u8, "-0", 10));
1629 try std.testing.expectError(error.InvalidCharacter, parseUnsigned(u8, "+0", 10));
1630 try std.testing.expectError(error.InvalidCharacter, parseUnsigned(u8, "-0", 10));
16311631
16321632 // test empty string error
1633 std.testing.expectError(error.InvalidCharacter, parseUnsigned(u8, "", 10));
1633 try std.testing.expectError(error.InvalidCharacter, parseUnsigned(u8, "", 10));
16341634}
16351635
16361636pub const parseFloat = @import("fmt/parse_float.zig").parseFloat;
......@@ -1709,21 +1709,21 @@ test "bufPrintInt" {
17091709 var buffer: [100]u8 = undefined;
17101710 const buf = buffer[0..];
17111711
1712 std.testing.expectEqualSlices(u8, "-1", bufPrintIntToSlice(buf, @as(i1, -1), 10, false, FormatOptions{}));
1712 try std.testing.expectEqualSlices(u8, "-1", bufPrintIntToSlice(buf, @as(i1, -1), 10, false, FormatOptions{}));
17131713
1714 std.testing.expectEqualSlices(u8, "-101111000110000101001110", bufPrintIntToSlice(buf, @as(i32, -12345678), 2, false, FormatOptions{}));
1715 std.testing.expectEqualSlices(u8, "-12345678", bufPrintIntToSlice(buf, @as(i32, -12345678), 10, false, FormatOptions{}));
1716 std.testing.expectEqualSlices(u8, "-bc614e", bufPrintIntToSlice(buf, @as(i32, -12345678), 16, false, FormatOptions{}));
1717 std.testing.expectEqualSlices(u8, "-BC614E", bufPrintIntToSlice(buf, @as(i32, -12345678), 16, true, FormatOptions{}));
1714 try std.testing.expectEqualSlices(u8, "-101111000110000101001110", bufPrintIntToSlice(buf, @as(i32, -12345678), 2, false, FormatOptions{}));
1715 try std.testing.expectEqualSlices(u8, "-12345678", bufPrintIntToSlice(buf, @as(i32, -12345678), 10, false, FormatOptions{}));
1716 try std.testing.expectEqualSlices(u8, "-bc614e", bufPrintIntToSlice(buf, @as(i32, -12345678), 16, false, FormatOptions{}));
1717 try std.testing.expectEqualSlices(u8, "-BC614E", bufPrintIntToSlice(buf, @as(i32, -12345678), 16, true, FormatOptions{}));
17181718
1719 std.testing.expectEqualSlices(u8, "12345678", bufPrintIntToSlice(buf, @as(u32, 12345678), 10, true, FormatOptions{}));
1719 try std.testing.expectEqualSlices(u8, "12345678", bufPrintIntToSlice(buf, @as(u32, 12345678), 10, true, FormatOptions{}));
17201720
1721 std.testing.expectEqualSlices(u8, " 666", bufPrintIntToSlice(buf, @as(u32, 666), 10, false, FormatOptions{ .width = 6 }));
1722 std.testing.expectEqualSlices(u8, " 1234", bufPrintIntToSlice(buf, @as(u32, 0x1234), 16, false, FormatOptions{ .width = 6 }));
1723 std.testing.expectEqualSlices(u8, "1234", bufPrintIntToSlice(buf, @as(u32, 0x1234), 16, false, FormatOptions{ .width = 1 }));
1721 try std.testing.expectEqualSlices(u8, " 666", bufPrintIntToSlice(buf, @as(u32, 666), 10, false, FormatOptions{ .width = 6 }));
1722 try std.testing.expectEqualSlices(u8, " 1234", bufPrintIntToSlice(buf, @as(u32, 0x1234), 16, false, FormatOptions{ .width = 6 }));
1723 try std.testing.expectEqualSlices(u8, "1234", bufPrintIntToSlice(buf, @as(u32, 0x1234), 16, false, FormatOptions{ .width = 1 }));
17241724
1725 std.testing.expectEqualSlices(u8, "+42", bufPrintIntToSlice(buf, @as(i32, 42), 10, false, FormatOptions{ .width = 3 }));
1726 std.testing.expectEqualSlices(u8, "-42", bufPrintIntToSlice(buf, @as(i32, -42), 10, false, FormatOptions{ .width = 3 }));
1725 try std.testing.expectEqualSlices(u8, "+42", bufPrintIntToSlice(buf, @as(i32, 42), 10, false, FormatOptions{ .width = 3 }));
1726 try std.testing.expectEqualSlices(u8, "-42", bufPrintIntToSlice(buf, @as(i32, -42), 10, false, FormatOptions{ .width = 3 }));
17271727}
17281728
17291729pub fn bufPrintIntToSlice(buf: []u8, value: anytype, base: u8, uppercase: bool, options: FormatOptions) []u8 {
......@@ -1741,8 +1741,8 @@ pub fn comptimePrint(comptime fmt: []const u8, args: anytype) *const [count(fmt,
17411741
17421742test "comptimePrint" {
17431743 @setEvalBranchQuota(2000);
1744 std.testing.expectEqual(*const [3:0]u8, @TypeOf(comptime comptimePrint("{}", .{100})));
1745 std.testing.expectEqualSlices(u8, "100", comptime comptimePrint("{}", .{100}));
1744 try std.testing.expectEqual(*const [3:0]u8, @TypeOf(comptime comptimePrint("{}", .{100})));
1745 try std.testing.expectEqualSlices(u8, "100", comptime comptimePrint("{}", .{100}));
17461746}
17471747
17481748test "parse u64 digit too big" {
......@@ -1755,7 +1755,7 @@ test "parse u64 digit too big" {
17551755
17561756test "parse unsigned comptime" {
17571757 comptime {
1758 std.testing.expect((try parseUnsigned(usize, "2", 10)) == 2);
1758 try std.testing.expect((try parseUnsigned(usize, "2", 10)) == 2);
17591759 }
17601760}
17611761
......@@ -1852,15 +1852,15 @@ test "buffer" {
18521852 var buf1: [32]u8 = undefined;
18531853 var fbs = std.io.fixedBufferStream(&buf1);
18541854 try formatType(1234, "", FormatOptions{}, fbs.writer(), default_max_depth);
1855 std.testing.expect(mem.eql(u8, fbs.getWritten(), "1234"));
1855 try std.testing.expect(mem.eql(u8, fbs.getWritten(), "1234"));
18561856
18571857 fbs.reset();
18581858 try formatType('a', "c", FormatOptions{}, fbs.writer(), default_max_depth);
1859 std.testing.expect(mem.eql(u8, fbs.getWritten(), "a"));
1859 try std.testing.expect(mem.eql(u8, fbs.getWritten(), "a"));
18601860
18611861 fbs.reset();
18621862 try formatType(0b1100, "b", FormatOptions{}, fbs.writer(), default_max_depth);
1863 std.testing.expect(mem.eql(u8, fbs.getWritten(), "1100"));
1863 try std.testing.expect(mem.eql(u8, fbs.getWritten(), "1100"));
18641864 }
18651865}
18661866
......@@ -2187,10 +2187,10 @@ test "union" {
21872187
21882188 var buf: [100]u8 = undefined;
21892189 const uu_result = try bufPrint(buf[0..], "{}", .{uu_inst});
2190 std.testing.expect(mem.eql(u8, uu_result[0..3], "UU@"));
2190 try std.testing.expect(mem.eql(u8, uu_result[0..3], "UU@"));
21912191
21922192 const eu_result = try bufPrint(buf[0..], "{}", .{eu_inst});
2193 std.testing.expect(mem.eql(u8, uu_result[0..3], "EU@"));
2193 try std.testing.expect(mem.eql(u8, uu_result[0..3], "EU@"));
21942194}
21952195
21962196test "enum" {
......@@ -2273,9 +2273,9 @@ test "hexToBytes" {
22732273 try expectFmt("90" ** 32, "{s}", .{fmtSliceHexUpper(try hexToBytes(&buf, "90" ** 32))});
22742274 try expectFmt("ABCD", "{s}", .{fmtSliceHexUpper(try hexToBytes(&buf, "ABCD"))});
22752275 try expectFmt("", "{s}", .{fmtSliceHexUpper(try hexToBytes(&buf, ""))});
2276 std.testing.expectError(error.InvalidCharacter, hexToBytes(&buf, "012Z"));
2277 std.testing.expectError(error.InvalidLength, hexToBytes(&buf, "AAA"));
2278 std.testing.expectError(error.NoSpaceLeft, hexToBytes(buf[0..1], "ABAB"));
2276 try std.testing.expectError(error.InvalidCharacter, hexToBytes(&buf, "012Z"));
2277 try std.testing.expectError(error.InvalidLength, hexToBytes(&buf, "AAA"));
2278 try std.testing.expectError(error.NoSpaceLeft, hexToBytes(buf[0..1], "ABAB"));
22792279}
22802280
22812281test "formatIntValue with comptime_int" {
......@@ -2284,7 +2284,7 @@ test "formatIntValue with comptime_int" {
22842284 var buf: [20]u8 = undefined;
22852285 var fbs = std.io.fixedBufferStream(&buf);
22862286 try formatIntValue(value, "", FormatOptions{}, fbs.writer());
2287 std.testing.expect(mem.eql(u8, fbs.getWritten(), "123456789123456789"));
2287 try std.testing.expect(mem.eql(u8, fbs.getWritten(), "123456789123456789"));
22882288}
22892289
22902290test "formatFloatValue with comptime_float" {
......@@ -2293,7 +2293,7 @@ test "formatFloatValue with comptime_float" {
22932293 var buf: [20]u8 = undefined;
22942294 var fbs = std.io.fixedBufferStream(&buf);
22952295 try formatFloatValue(value, "", FormatOptions{}, fbs.writer());
2296 std.testing.expect(mem.eql(u8, fbs.getWritten(), "1.0e+00"));
2296 try std.testing.expect(mem.eql(u8, fbs.getWritten(), "1.0e+00"));
22972297
22982298 try expectFmt("1.0e+00", "{}", .{value});
22992299 try expectFmt("1.0e+00", "{}", .{1.0});
......@@ -2349,19 +2349,19 @@ test "formatType max_depth" {
23492349 var buf: [1000]u8 = undefined;
23502350 var fbs = std.io.fixedBufferStream(&buf);
23512351 try formatType(inst, "", FormatOptions{}, fbs.writer(), 0);
2352 std.testing.expect(mem.eql(u8, fbs.getWritten(), "S{ ... }"));
2352 try std.testing.expect(mem.eql(u8, fbs.getWritten(), "S{ ... }"));
23532353
23542354 fbs.reset();
23552355 try formatType(inst, "", FormatOptions{}, fbs.writer(), 1);
2356 std.testing.expect(mem.eql(u8, fbs.getWritten(), "S{ .a = S{ ... }, .tu = TU{ ... }, .e = E.Two, .vec = (10.200,2.220) }"));
2356 try std.testing.expect(mem.eql(u8, fbs.getWritten(), "S{ .a = S{ ... }, .tu = TU{ ... }, .e = E.Two, .vec = (10.200,2.220) }"));
23572357
23582358 fbs.reset();
23592359 try formatType(inst, "", FormatOptions{}, fbs.writer(), 2);
2360 std.testing.expect(mem.eql(u8, fbs.getWritten(), "S{ .a = S{ .a = S{ ... }, .tu = TU{ ... }, .e = E.Two, .vec = (10.200,2.220) }, .tu = TU{ .ptr = TU{ ... } }, .e = E.Two, .vec = (10.200,2.220) }"));
2360 try std.testing.expect(mem.eql(u8, fbs.getWritten(), "S{ .a = S{ .a = S{ ... }, .tu = TU{ ... }, .e = E.Two, .vec = (10.200,2.220) }, .tu = TU{ .ptr = TU{ ... } }, .e = E.Two, .vec = (10.200,2.220) }"));
23612361
23622362 fbs.reset();
23632363 try formatType(inst, "", FormatOptions{}, fbs.writer(), 3);
2364 std.testing.expect(mem.eql(u8, fbs.getWritten(), "S{ .a = S{ .a = S{ .a = S{ ... }, .tu = TU{ ... }, .e = E.Two, .vec = (10.200,2.220) }, .tu = TU{ .ptr = TU{ ... } }, .e = E.Two, .vec = (10.200,2.220) }, .tu = TU{ .ptr = TU{ .ptr = TU{ ... } } }, .e = E.Two, .vec = (10.200,2.220) }"));
2364 try std.testing.expect(mem.eql(u8, fbs.getWritten(), "S{ .a = S{ .a = S{ .a = S{ ... }, .tu = TU{ ... }, .e = E.Two, .vec = (10.200,2.220) }, .tu = TU{ .ptr = TU{ ... } }, .e = E.Two, .vec = (10.200,2.220) }, .tu = TU{ .ptr = TU{ .ptr = TU{ ... } } }, .e = E.Two, .vec = (10.200,2.220) }"));
23652365}
23662366
23672367test "positional" {
lib/std/fmt/parse_float.zig+29-29
......@@ -376,44 +376,44 @@ test "fmt.parseFloat" {
376376 inline for ([_]type{ f16, f32, f64, f128 }) |T| {
377377 const Z = std.meta.Int(.unsigned, @typeInfo(T).Float.bits);
378378
379 testing.expectError(error.InvalidCharacter, parseFloat(T, ""));
380 testing.expectError(error.InvalidCharacter, parseFloat(T, " 1"));
381 testing.expectError(error.InvalidCharacter, parseFloat(T, "1abc"));
382 testing.expectError(error.InvalidCharacter, parseFloat(T, "+"));
383 testing.expectError(error.InvalidCharacter, parseFloat(T, "-"));
379 try testing.expectError(error.InvalidCharacter, parseFloat(T, ""));
380 try testing.expectError(error.InvalidCharacter, parseFloat(T, " 1"));
381 try testing.expectError(error.InvalidCharacter, parseFloat(T, "1abc"));
382 try testing.expectError(error.InvalidCharacter, parseFloat(T, "+"));
383 try testing.expectError(error.InvalidCharacter, parseFloat(T, "-"));
384384
385 expectEqual(try parseFloat(T, "0"), 0.0);
386 expectEqual(try parseFloat(T, "0"), 0.0);
387 expectEqual(try parseFloat(T, "+0"), 0.0);
388 expectEqual(try parseFloat(T, "-0"), 0.0);
385 try expectEqual(try parseFloat(T, "0"), 0.0);
386 try expectEqual(try parseFloat(T, "0"), 0.0);
387 try expectEqual(try parseFloat(T, "+0"), 0.0);
388 try expectEqual(try parseFloat(T, "-0"), 0.0);
389389
390 expectEqual(try parseFloat(T, "0e0"), 0);
391 expectEqual(try parseFloat(T, "2e3"), 2000.0);
392 expectEqual(try parseFloat(T, "1e0"), 1.0);
393 expectEqual(try parseFloat(T, "-2e3"), -2000.0);
394 expectEqual(try parseFloat(T, "-1e0"), -1.0);
395 expectEqual(try parseFloat(T, "1.234e3"), 1234);
390 try expectEqual(try parseFloat(T, "0e0"), 0);
391 try expectEqual(try parseFloat(T, "2e3"), 2000.0);
392 try expectEqual(try parseFloat(T, "1e0"), 1.0);
393 try expectEqual(try parseFloat(T, "-2e3"), -2000.0);
394 try expectEqual(try parseFloat(T, "-1e0"), -1.0);
395 try expectEqual(try parseFloat(T, "1.234e3"), 1234);
396396
397 expect(approxEqAbs(T, try parseFloat(T, "3.141"), 3.141, epsilon));
398 expect(approxEqAbs(T, try parseFloat(T, "-3.141"), -3.141, epsilon));
397 try expect(approxEqAbs(T, try parseFloat(T, "3.141"), 3.141, epsilon));
398 try expect(approxEqAbs(T, try parseFloat(T, "-3.141"), -3.141, epsilon));
399399
400 expectEqual(try parseFloat(T, "1e-700"), 0);
401 expectEqual(try parseFloat(T, "1e+700"), std.math.inf(T));
400 try expectEqual(try parseFloat(T, "1e-700"), 0);
401 try expectEqual(try parseFloat(T, "1e+700"), std.math.inf(T));
402402
403 expectEqual(@bitCast(Z, try parseFloat(T, "nAn")), @bitCast(Z, std.math.nan(T)));
404 expectEqual(try parseFloat(T, "inF"), std.math.inf(T));
405 expectEqual(try parseFloat(T, "-INF"), -std.math.inf(T));
403 try expectEqual(@bitCast(Z, try parseFloat(T, "nAn")), @bitCast(Z, std.math.nan(T)));
404 try expectEqual(try parseFloat(T, "inF"), std.math.inf(T));
405 try expectEqual(try parseFloat(T, "-INF"), -std.math.inf(T));
406406
407 expectEqual(try parseFloat(T, "0.4e0066999999999999999999999999999999999999999999999999999"), std.math.inf(T));
407 try expectEqual(try parseFloat(T, "0.4e0066999999999999999999999999999999999999999999999999999"), std.math.inf(T));
408408
409409 if (T != f16) {
410 expect(approxEqAbs(T, try parseFloat(T, "1e-2"), 0.01, epsilon));
411 expect(approxEqAbs(T, try parseFloat(T, "1234e-2"), 12.34, epsilon));
410 try expect(approxEqAbs(T, try parseFloat(T, "1e-2"), 0.01, epsilon));
411 try expect(approxEqAbs(T, try parseFloat(T, "1234e-2"), 12.34, epsilon));
412412
413 expect(approxEqAbs(T, try parseFloat(T, "123142.1"), 123142.1, epsilon));
414 expect(approxEqAbs(T, try parseFloat(T, "-123142.1124"), @as(T, -123142.1124), epsilon));
415 expect(approxEqAbs(T, try parseFloat(T, "0.7062146892655368"), @as(T, 0.7062146892655368), epsilon));
416 expect(approxEqAbs(T, try parseFloat(T, "2.71828182845904523536"), @as(T, 2.718281828459045), epsilon));
413 try expect(approxEqAbs(T, try parseFloat(T, "123142.1"), 123142.1, epsilon));
414 try expect(approxEqAbs(T, try parseFloat(T, "-123142.1124"), @as(T, -123142.1124), epsilon));
415 try expect(approxEqAbs(T, try parseFloat(T, "0.7062146892655368"), @as(T, 0.7062146892655368), epsilon));
416 try expect(approxEqAbs(T, try parseFloat(T, "2.71828182845904523536"), @as(T, 2.718281828459045), epsilon));
417417 }
418418 }
419419}
lib/std/fmt/parse_hex_float.zig+13-13
......@@ -247,17 +247,17 @@ pub fn parseHexFloat(comptime T: type, s: []const u8) !T {
247247}
248248
249249test "special" {
250 testing.expect(math.isNan(try parseHexFloat(f32, "nAn")));
251 testing.expect(math.isPositiveInf(try parseHexFloat(f32, "iNf")));
252 testing.expect(math.isPositiveInf(try parseHexFloat(f32, "+Inf")));
253 testing.expect(math.isNegativeInf(try parseHexFloat(f32, "-iNf")));
250 try testing.expect(math.isNan(try parseHexFloat(f32, "nAn")));
251 try testing.expect(math.isPositiveInf(try parseHexFloat(f32, "iNf")));
252 try testing.expect(math.isPositiveInf(try parseHexFloat(f32, "+Inf")));
253 try testing.expect(math.isNegativeInf(try parseHexFloat(f32, "-iNf")));
254254}
255255test "zero" {
256 testing.expectEqual(@as(f32, 0.0), try parseHexFloat(f32, "0x0"));
257 testing.expectEqual(@as(f32, 0.0), try parseHexFloat(f32, "-0x0"));
258 testing.expectEqual(@as(f32, 0.0), try parseHexFloat(f32, "0x0p42"));
259 testing.expectEqual(@as(f32, 0.0), try parseHexFloat(f32, "-0x0.00000p42"));
260 testing.expectEqual(@as(f32, 0.0), try parseHexFloat(f32, "0x0.00000p666"));
256 try testing.expectEqual(@as(f32, 0.0), try parseHexFloat(f32, "0x0"));
257 try testing.expectEqual(@as(f32, 0.0), try parseHexFloat(f32, "-0x0"));
258 try testing.expectEqual(@as(f32, 0.0), try parseHexFloat(f32, "0x0p42"));
259 try testing.expectEqual(@as(f32, 0.0), try parseHexFloat(f32, "-0x0.00000p42"));
260 try testing.expectEqual(@as(f32, 0.0), try parseHexFloat(f32, "0x0.00000p666"));
261261}
262262
263263test "f16" {
......@@ -279,7 +279,7 @@ test "f16" {
279279 };
280280
281281 for (cases) |case| {
282 testing.expectEqual(case.v, try parseHexFloat(f16, case.s));
282 try testing.expectEqual(case.v, try parseHexFloat(f16, case.s));
283283 }
284284}
285285test "f32" {
......@@ -303,7 +303,7 @@ test "f32" {
303303 };
304304
305305 for (cases) |case| {
306 testing.expectEqual(case.v, try parseHexFloat(f32, case.s));
306 try testing.expectEqual(case.v, try parseHexFloat(f32, case.s));
307307 }
308308}
309309test "f64" {
......@@ -325,7 +325,7 @@ test "f64" {
325325 };
326326
327327 for (cases) |case| {
328 testing.expectEqual(case.v, try parseHexFloat(f64, case.s));
328 try testing.expectEqual(case.v, try parseHexFloat(f64, case.s));
329329 }
330330}
331331test "f128" {
......@@ -347,6 +347,6 @@ test "f128" {
347347 };
348348
349349 for (cases) |case| {
350 testing.expectEqual(@bitCast(u128, case.v), @bitCast(u128, try parseHexFloat(f128, case.s)));
350 try testing.expectEqual(@bitCast(u128, case.v), @bitCast(u128, try parseHexFloat(f128, case.s)));
351351 }
352352}
lib/std/fs/path.zig+205-205
......@@ -96,72 +96,72 @@ pub fn joinZ(allocator: *Allocator, paths: []const []const u8) ![:0]u8 {
9696 return out[0 .. out.len - 1 :0];
9797}
9898
99fn testJoinMaybeZWindows(paths: []const []const u8, expected: []const u8, zero: bool) void {
99fn testJoinMaybeZWindows(paths: []const []const u8, expected: []const u8, zero: bool) !void {
100100 const windowsIsSep = struct {
101101 fn isSep(byte: u8) bool {
102102 return byte == '/' or byte == '\\';
103103 }
104104 }.isSep;
105 const actual = joinSepMaybeZ(testing.allocator, sep_windows, windowsIsSep, paths, zero) catch @panic("fail");
105 const actual = try joinSepMaybeZ(testing.allocator, sep_windows, windowsIsSep, paths, zero);
106106 defer testing.allocator.free(actual);
107 testing.expectEqualSlices(u8, expected, if (zero) actual[0 .. actual.len - 1 :0] else actual);
107 try testing.expectEqualSlices(u8, expected, if (zero) actual[0 .. actual.len - 1 :0] else actual);
108108}
109109
110fn testJoinMaybeZPosix(paths: []const []const u8, expected: []const u8, zero: bool) void {
110fn testJoinMaybeZPosix(paths: []const []const u8, expected: []const u8, zero: bool) !void {
111111 const posixIsSep = struct {
112112 fn isSep(byte: u8) bool {
113113 return byte == '/';
114114 }
115115 }.isSep;
116 const actual = joinSepMaybeZ(testing.allocator, sep_posix, posixIsSep, paths, zero) catch @panic("fail");
116 const actual = try joinSepMaybeZ(testing.allocator, sep_posix, posixIsSep, paths, zero);
117117 defer testing.allocator.free(actual);
118 testing.expectEqualSlices(u8, expected, if (zero) actual[0 .. actual.len - 1 :0] else actual);
118 try testing.expectEqualSlices(u8, expected, if (zero) actual[0 .. actual.len - 1 :0] else actual);
119119}
120120
121121test "join" {
122122 {
123123 const actual: []u8 = try join(testing.allocator, &[_][]const u8{});
124124 defer testing.allocator.free(actual);
125 testing.expectEqualSlices(u8, "", actual);
125 try testing.expectEqualSlices(u8, "", actual);
126126 }
127127 {
128128 const actual: [:0]u8 = try joinZ(testing.allocator, &[_][]const u8{});
129129 defer testing.allocator.free(actual);
130 testing.expectEqualSlices(u8, "", actual);
130 try testing.expectEqualSlices(u8, "", actual);
131131 }
132132 for (&[_]bool{ false, true }) |zero| {
133 testJoinMaybeZWindows(&[_][]const u8{}, "", zero);
134 testJoinMaybeZWindows(&[_][]const u8{ "c:\\a\\b", "c" }, "c:\\a\\b\\c", zero);
135 testJoinMaybeZWindows(&[_][]const u8{ "c:\\a\\b", "c" }, "c:\\a\\b\\c", zero);
136 testJoinMaybeZWindows(&[_][]const u8{ "c:\\a\\b\\", "c" }, "c:\\a\\b\\c", zero);
133 try testJoinMaybeZWindows(&[_][]const u8{}, "", zero);
134 try testJoinMaybeZWindows(&[_][]const u8{ "c:\\a\\b", "c" }, "c:\\a\\b\\c", zero);
135 try testJoinMaybeZWindows(&[_][]const u8{ "c:\\a\\b", "c" }, "c:\\a\\b\\c", zero);
136 try testJoinMaybeZWindows(&[_][]const u8{ "c:\\a\\b\\", "c" }, "c:\\a\\b\\c", zero);
137137
138 testJoinMaybeZWindows(&[_][]const u8{ "c:\\", "a", "b\\", "c" }, "c:\\a\\b\\c", zero);
139 testJoinMaybeZWindows(&[_][]const u8{ "c:\\a\\", "b\\", "c" }, "c:\\a\\b\\c", zero);
138 try testJoinMaybeZWindows(&[_][]const u8{ "c:\\", "a", "b\\", "c" }, "c:\\a\\b\\c", zero);
139 try testJoinMaybeZWindows(&[_][]const u8{ "c:\\a\\", "b\\", "c" }, "c:\\a\\b\\c", zero);
140140
141 testJoinMaybeZWindows(
141 try testJoinMaybeZWindows(
142142 &[_][]const u8{ "c:\\home\\andy\\dev\\zig\\build\\lib\\zig\\std", "io.zig" },
143143 "c:\\home\\andy\\dev\\zig\\build\\lib\\zig\\std\\io.zig",
144144 zero,
145145 );
146146
147 testJoinMaybeZWindows(&[_][]const u8{ "c:\\", "a", "b/", "c" }, "c:\\a\\b/c", zero);
148 testJoinMaybeZWindows(&[_][]const u8{ "c:\\a/", "b\\", "/c" }, "c:\\a/b\\c", zero);
147 try testJoinMaybeZWindows(&[_][]const u8{ "c:\\", "a", "b/", "c" }, "c:\\a\\b/c", zero);
148 try testJoinMaybeZWindows(&[_][]const u8{ "c:\\a/", "b\\", "/c" }, "c:\\a/b\\c", zero);
149149
150 testJoinMaybeZPosix(&[_][]const u8{}, "", zero);
151 testJoinMaybeZPosix(&[_][]const u8{ "/a/b", "c" }, "/a/b/c", zero);
152 testJoinMaybeZPosix(&[_][]const u8{ "/a/b/", "c" }, "/a/b/c", zero);
150 try testJoinMaybeZPosix(&[_][]const u8{}, "", zero);
151 try testJoinMaybeZPosix(&[_][]const u8{ "/a/b", "c" }, "/a/b/c", zero);
152 try testJoinMaybeZPosix(&[_][]const u8{ "/a/b/", "c" }, "/a/b/c", zero);
153153
154 testJoinMaybeZPosix(&[_][]const u8{ "/", "a", "b/", "c" }, "/a/b/c", zero);
155 testJoinMaybeZPosix(&[_][]const u8{ "/a/", "b/", "c" }, "/a/b/c", zero);
154 try testJoinMaybeZPosix(&[_][]const u8{ "/", "a", "b/", "c" }, "/a/b/c", zero);
155 try testJoinMaybeZPosix(&[_][]const u8{ "/a/", "b/", "c" }, "/a/b/c", zero);
156156
157 testJoinMaybeZPosix(
157 try testJoinMaybeZPosix(
158158 &[_][]const u8{ "/home/andy/dev/zig/build/lib/zig/std", "io.zig" },
159159 "/home/andy/dev/zig/build/lib/zig/std/io.zig",
160160 zero,
161161 );
162162
163 testJoinMaybeZPosix(&[_][]const u8{ "a", "/c" }, "a/c", zero);
164 testJoinMaybeZPosix(&[_][]const u8{ "a/", "/c" }, "a/c", zero);
163 try testJoinMaybeZPosix(&[_][]const u8{ "a", "/c" }, "a/c", zero);
164 try testJoinMaybeZPosix(&[_][]const u8{ "a/", "/c" }, "a/c", zero);
165165 }
166166}
167167
......@@ -235,42 +235,42 @@ pub fn isAbsolutePosixZ(path_c: [*:0]const u8) bool {
235235}
236236
237237test "isAbsoluteWindows" {
238 testIsAbsoluteWindows("", false);
239 testIsAbsoluteWindows("/", true);
240 testIsAbsoluteWindows("//", true);
241 testIsAbsoluteWindows("//server", true);
242 testIsAbsoluteWindows("//server/file", true);
243 testIsAbsoluteWindows("\\\\server\\file", true);
244 testIsAbsoluteWindows("\\\\server", true);
245 testIsAbsoluteWindows("\\\\", true);
246 testIsAbsoluteWindows("c", false);
247 testIsAbsoluteWindows("c:", false);
248 testIsAbsoluteWindows("c:\\", true);
249 testIsAbsoluteWindows("c:/", true);
250 testIsAbsoluteWindows("c://", true);
251 testIsAbsoluteWindows("C:/Users/", true);
252 testIsAbsoluteWindows("C:\\Users\\", true);
253 testIsAbsoluteWindows("C:cwd/another", false);
254 testIsAbsoluteWindows("C:cwd\\another", false);
255 testIsAbsoluteWindows("directory/directory", false);
256 testIsAbsoluteWindows("directory\\directory", false);
257 testIsAbsoluteWindows("/usr/local", true);
238 try testIsAbsoluteWindows("", false);
239 try testIsAbsoluteWindows("/", true);
240 try testIsAbsoluteWindows("//", true);
241 try testIsAbsoluteWindows("//server", true);
242 try testIsAbsoluteWindows("//server/file", true);
243 try testIsAbsoluteWindows("\\\\server\\file", true);
244 try testIsAbsoluteWindows("\\\\server", true);
245 try testIsAbsoluteWindows("\\\\", true);
246 try testIsAbsoluteWindows("c", false);
247 try testIsAbsoluteWindows("c:", false);
248 try testIsAbsoluteWindows("c:\\", true);
249 try testIsAbsoluteWindows("c:/", true);
250 try testIsAbsoluteWindows("c://", true);
251 try testIsAbsoluteWindows("C:/Users/", true);
252 try testIsAbsoluteWindows("C:\\Users\\", true);
253 try testIsAbsoluteWindows("C:cwd/another", false);
254 try testIsAbsoluteWindows("C:cwd\\another", false);
255 try testIsAbsoluteWindows("directory/directory", false);
256 try testIsAbsoluteWindows("directory\\directory", false);
257 try testIsAbsoluteWindows("/usr/local", true);
258258}
259259
260260test "isAbsolutePosix" {
261 testIsAbsolutePosix("", false);
262 testIsAbsolutePosix("/home/foo", true);
263 testIsAbsolutePosix("/home/foo/..", true);
264 testIsAbsolutePosix("bar/", false);
265 testIsAbsolutePosix("./baz", false);
261 try testIsAbsolutePosix("", false);
262 try testIsAbsolutePosix("/home/foo", true);
263 try testIsAbsolutePosix("/home/foo/..", true);
264 try testIsAbsolutePosix("bar/", false);
265 try testIsAbsolutePosix("./baz", false);
266266}
267267
268fn testIsAbsoluteWindows(path: []const u8, expected_result: bool) void {
269 testing.expectEqual(expected_result, isAbsoluteWindows(path));
268fn testIsAbsoluteWindows(path: []const u8, expected_result: bool) !void {
269 try testing.expectEqual(expected_result, isAbsoluteWindows(path));
270270}
271271
272fn testIsAbsolutePosix(path: []const u8, expected_result: bool) void {
273 testing.expectEqual(expected_result, isAbsolutePosix(path));
272fn testIsAbsolutePosix(path: []const u8, expected_result: bool) !void {
273 try testing.expectEqual(expected_result, isAbsolutePosix(path));
274274}
275275
276276pub const WindowsPath = struct {
......@@ -334,33 +334,33 @@ pub fn windowsParsePath(path: []const u8) WindowsPath {
334334test "windowsParsePath" {
335335 {
336336 const parsed = windowsParsePath("//a/b");
337 testing.expect(parsed.is_abs);
338 testing.expect(parsed.kind == WindowsPath.Kind.NetworkShare);
339 testing.expect(mem.eql(u8, parsed.disk_designator, "//a/b"));
337 try testing.expect(parsed.is_abs);
338 try testing.expect(parsed.kind == WindowsPath.Kind.NetworkShare);
339 try testing.expect(mem.eql(u8, parsed.disk_designator, "//a/b"));
340340 }
341341 {
342342 const parsed = windowsParsePath("\\\\a\\b");
343 testing.expect(parsed.is_abs);
344 testing.expect(parsed.kind == WindowsPath.Kind.NetworkShare);
345 testing.expect(mem.eql(u8, parsed.disk_designator, "\\\\a\\b"));
343 try testing.expect(parsed.is_abs);
344 try testing.expect(parsed.kind == WindowsPath.Kind.NetworkShare);
345 try testing.expect(mem.eql(u8, parsed.disk_designator, "\\\\a\\b"));
346346 }
347347 {
348348 const parsed = windowsParsePath("\\\\a\\");
349 testing.expect(!parsed.is_abs);
350 testing.expect(parsed.kind == WindowsPath.Kind.None);
351 testing.expect(mem.eql(u8, parsed.disk_designator, ""));
349 try testing.expect(!parsed.is_abs);
350 try testing.expect(parsed.kind == WindowsPath.Kind.None);
351 try testing.expect(mem.eql(u8, parsed.disk_designator, ""));
352352 }
353353 {
354354 const parsed = windowsParsePath("/usr/local");
355 testing.expect(parsed.is_abs);
356 testing.expect(parsed.kind == WindowsPath.Kind.None);
357 testing.expect(mem.eql(u8, parsed.disk_designator, ""));
355 try testing.expect(parsed.is_abs);
356 try testing.expect(parsed.kind == WindowsPath.Kind.None);
357 try testing.expect(mem.eql(u8, parsed.disk_designator, ""));
358358 }
359359 {
360360 const parsed = windowsParsePath("c:../");
361 testing.expect(!parsed.is_abs);
362 testing.expect(parsed.kind == WindowsPath.Kind.Drive);
363 testing.expect(mem.eql(u8, parsed.disk_designator, "c:"));
361 try testing.expect(!parsed.is_abs);
362 try testing.expect(parsed.kind == WindowsPath.Kind.Drive);
363 try testing.expect(mem.eql(u8, parsed.disk_designator, "c:"));
364364 }
365365}
366366
......@@ -772,13 +772,13 @@ test "resolvePosix" {
772772fn testResolveWindows(paths: []const []const u8, expected: []const u8) !void {
773773 const actual = try resolveWindows(testing.allocator, paths);
774774 defer testing.allocator.free(actual);
775 return testing.expect(mem.eql(u8, actual, expected));
775 try testing.expect(mem.eql(u8, actual, expected));
776776}
777777
778778fn testResolvePosix(paths: []const []const u8, expected: []const u8) !void {
779779 const actual = try resolvePosix(testing.allocator, paths);
780780 defer testing.allocator.free(actual);
781 return testing.expect(mem.eql(u8, actual, expected));
781 try testing.expect(mem.eql(u8, actual, expected));
782782}
783783
784784/// Strip the last component from a file path.
......@@ -856,68 +856,68 @@ pub fn dirnamePosix(path: []const u8) ?[]const u8 {
856856}
857857
858858test "dirnamePosix" {
859 testDirnamePosix("/a/b/c", "/a/b");
860 testDirnamePosix("/a/b/c///", "/a/b");
861 testDirnamePosix("/a", "/");
862 testDirnamePosix("/", null);
863 testDirnamePosix("//", null);
864 testDirnamePosix("///", null);
865 testDirnamePosix("////", null);
866 testDirnamePosix("", null);
867 testDirnamePosix("a", null);
868 testDirnamePosix("a/", null);
869 testDirnamePosix("a//", null);
859 try testDirnamePosix("/a/b/c", "/a/b");
860 try testDirnamePosix("/a/b/c///", "/a/b");
861 try testDirnamePosix("/a", "/");
862 try testDirnamePosix("/", null);
863 try testDirnamePosix("//", null);
864 try testDirnamePosix("///", null);
865 try testDirnamePosix("////", null);
866 try testDirnamePosix("", null);
867 try testDirnamePosix("a", null);
868 try testDirnamePosix("a/", null);
869 try testDirnamePosix("a//", null);
870870}
871871
872872test "dirnameWindows" {
873 testDirnameWindows("c:\\", null);
874 testDirnameWindows("c:\\foo", "c:\\");
875 testDirnameWindows("c:\\foo\\", "c:\\");
876 testDirnameWindows("c:\\foo\\bar", "c:\\foo");
877 testDirnameWindows("c:\\foo\\bar\\", "c:\\foo");
878 testDirnameWindows("c:\\foo\\bar\\baz", "c:\\foo\\bar");
879 testDirnameWindows("\\", null);
880 testDirnameWindows("\\foo", "\\");
881 testDirnameWindows("\\foo\\", "\\");
882 testDirnameWindows("\\foo\\bar", "\\foo");
883 testDirnameWindows("\\foo\\bar\\", "\\foo");
884 testDirnameWindows("\\foo\\bar\\baz", "\\foo\\bar");
885 testDirnameWindows("c:", null);
886 testDirnameWindows("c:foo", null);
887 testDirnameWindows("c:foo\\", null);
888 testDirnameWindows("c:foo\\bar", "c:foo");
889 testDirnameWindows("c:foo\\bar\\", "c:foo");
890 testDirnameWindows("c:foo\\bar\\baz", "c:foo\\bar");
891 testDirnameWindows("file:stream", null);
892 testDirnameWindows("dir\\file:stream", "dir");
893 testDirnameWindows("\\\\unc\\share", null);
894 testDirnameWindows("\\\\unc\\share\\foo", "\\\\unc\\share\\");
895 testDirnameWindows("\\\\unc\\share\\foo\\", "\\\\unc\\share\\");
896 testDirnameWindows("\\\\unc\\share\\foo\\bar", "\\\\unc\\share\\foo");
897 testDirnameWindows("\\\\unc\\share\\foo\\bar\\", "\\\\unc\\share\\foo");
898 testDirnameWindows("\\\\unc\\share\\foo\\bar\\baz", "\\\\unc\\share\\foo\\bar");
899 testDirnameWindows("/a/b/", "/a");
900 testDirnameWindows("/a/b", "/a");
901 testDirnameWindows("/a", "/");
902 testDirnameWindows("", null);
903 testDirnameWindows("/", null);
904 testDirnameWindows("////", null);
905 testDirnameWindows("foo", null);
873 try testDirnameWindows("c:\\", null);
874 try testDirnameWindows("c:\\foo", "c:\\");
875 try testDirnameWindows("c:\\foo\\", "c:\\");
876 try testDirnameWindows("c:\\foo\\bar", "c:\\foo");
877 try testDirnameWindows("c:\\foo\\bar\\", "c:\\foo");
878 try testDirnameWindows("c:\\foo\\bar\\baz", "c:\\foo\\bar");
879 try testDirnameWindows("\\", null);
880 try testDirnameWindows("\\foo", "\\");
881 try testDirnameWindows("\\foo\\", "\\");
882 try testDirnameWindows("\\foo\\bar", "\\foo");
883 try testDirnameWindows("\\foo\\bar\\", "\\foo");
884 try testDirnameWindows("\\foo\\bar\\baz", "\\foo\\bar");
885 try testDirnameWindows("c:", null);
886 try testDirnameWindows("c:foo", null);
887 try testDirnameWindows("c:foo\\", null);
888 try testDirnameWindows("c:foo\\bar", "c:foo");
889 try testDirnameWindows("c:foo\\bar\\", "c:foo");
890 try testDirnameWindows("c:foo\\bar\\baz", "c:foo\\bar");
891 try testDirnameWindows("file:stream", null);
892 try testDirnameWindows("dir\\file:stream", "dir");
893 try testDirnameWindows("\\\\unc\\share", null);
894 try testDirnameWindows("\\\\unc\\share\\foo", "\\\\unc\\share\\");
895 try testDirnameWindows("\\\\unc\\share\\foo\\", "\\\\unc\\share\\");
896 try testDirnameWindows("\\\\unc\\share\\foo\\bar", "\\\\unc\\share\\foo");
897 try testDirnameWindows("\\\\unc\\share\\foo\\bar\\", "\\\\unc\\share\\foo");
898 try testDirnameWindows("\\\\unc\\share\\foo\\bar\\baz", "\\\\unc\\share\\foo\\bar");
899 try testDirnameWindows("/a/b/", "/a");
900 try testDirnameWindows("/a/b", "/a");
901 try testDirnameWindows("/a", "/");
902 try testDirnameWindows("", null);
903 try testDirnameWindows("/", null);
904 try testDirnameWindows("////", null);
905 try testDirnameWindows("foo", null);
906906}
907907
908fn testDirnamePosix(input: []const u8, expected_output: ?[]const u8) void {
908fn testDirnamePosix(input: []const u8, expected_output: ?[]const u8) !void {
909909 if (dirnamePosix(input)) |output| {
910 testing.expect(mem.eql(u8, output, expected_output.?));
910 try testing.expect(mem.eql(u8, output, expected_output.?));
911911 } else {
912 testing.expect(expected_output == null);
912 try testing.expect(expected_output == null);
913913 }
914914}
915915
916fn testDirnameWindows(input: []const u8, expected_output: ?[]const u8) void {
916fn testDirnameWindows(input: []const u8, expected_output: ?[]const u8) !void {
917917 if (dirnameWindows(input)) |output| {
918 testing.expect(mem.eql(u8, output, expected_output.?));
918 try testing.expect(mem.eql(u8, output, expected_output.?));
919919 } else {
920 testing.expect(expected_output == null);
920 try testing.expect(expected_output == null);
921921 }
922922}
923923
......@@ -983,54 +983,54 @@ pub fn basenameWindows(path: []const u8) []const u8 {
983983}
984984
985985test "basename" {
986 testBasename("", "");
987 testBasename("/", "");
988 testBasename("/dir/basename.ext", "basename.ext");
989 testBasename("/basename.ext", "basename.ext");
990 testBasename("basename.ext", "basename.ext");
991 testBasename("basename.ext/", "basename.ext");
992 testBasename("basename.ext//", "basename.ext");
993 testBasename("/aaa/bbb", "bbb");
994 testBasename("/aaa/", "aaa");
995 testBasename("/aaa/b", "b");
996 testBasename("/a/b", "b");
997 testBasename("//a", "a");
998
999 testBasenamePosix("\\dir\\basename.ext", "\\dir\\basename.ext");
1000 testBasenamePosix("\\basename.ext", "\\basename.ext");
1001 testBasenamePosix("basename.ext", "basename.ext");
1002 testBasenamePosix("basename.ext\\", "basename.ext\\");
1003 testBasenamePosix("basename.ext\\\\", "basename.ext\\\\");
1004 testBasenamePosix("foo", "foo");
1005
1006 testBasenameWindows("\\dir\\basename.ext", "basename.ext");
1007 testBasenameWindows("\\basename.ext", "basename.ext");
1008 testBasenameWindows("basename.ext", "basename.ext");
1009 testBasenameWindows("basename.ext\\", "basename.ext");
1010 testBasenameWindows("basename.ext\\\\", "basename.ext");
1011 testBasenameWindows("foo", "foo");
1012 testBasenameWindows("C:", "");
1013 testBasenameWindows("C:.", ".");
1014 testBasenameWindows("C:\\", "");
1015 testBasenameWindows("C:\\dir\\base.ext", "base.ext");
1016 testBasenameWindows("C:\\basename.ext", "basename.ext");
1017 testBasenameWindows("C:basename.ext", "basename.ext");
1018 testBasenameWindows("C:basename.ext\\", "basename.ext");
1019 testBasenameWindows("C:basename.ext\\\\", "basename.ext");
1020 testBasenameWindows("C:foo", "foo");
1021 testBasenameWindows("file:stream", "file:stream");
986 try testBasename("", "");
987 try testBasename("/", "");
988 try testBasename("/dir/basename.ext", "basename.ext");
989 try testBasename("/basename.ext", "basename.ext");
990 try testBasename("basename.ext", "basename.ext");
991 try testBasename("basename.ext/", "basename.ext");
992 try testBasename("basename.ext//", "basename.ext");
993 try testBasename("/aaa/bbb", "bbb");
994 try testBasename("/aaa/", "aaa");
995 try testBasename("/aaa/b", "b");
996 try testBasename("/a/b", "b");
997 try testBasename("//a", "a");
998
999 try testBasenamePosix("\\dir\\basename.ext", "\\dir\\basename.ext");
1000 try testBasenamePosix("\\basename.ext", "\\basename.ext");
1001 try testBasenamePosix("basename.ext", "basename.ext");
1002 try testBasenamePosix("basename.ext\\", "basename.ext\\");
1003 try testBasenamePosix("basename.ext\\\\", "basename.ext\\\\");
1004 try testBasenamePosix("foo", "foo");
1005
1006 try testBasenameWindows("\\dir\\basename.ext", "basename.ext");
1007 try testBasenameWindows("\\basename.ext", "basename.ext");
1008 try testBasenameWindows("basename.ext", "basename.ext");
1009 try testBasenameWindows("basename.ext\\", "basename.ext");
1010 try testBasenameWindows("basename.ext\\\\", "basename.ext");
1011 try testBasenameWindows("foo", "foo");
1012 try testBasenameWindows("C:", "");
1013 try testBasenameWindows("C:.", ".");
1014 try testBasenameWindows("C:\\", "");
1015 try testBasenameWindows("C:\\dir\\base.ext", "base.ext");
1016 try testBasenameWindows("C:\\basename.ext", "basename.ext");
1017 try testBasenameWindows("C:basename.ext", "basename.ext");
1018 try testBasenameWindows("C:basename.ext\\", "basename.ext");
1019 try testBasenameWindows("C:basename.ext\\\\", "basename.ext");
1020 try testBasenameWindows("C:foo", "foo");
1021 try testBasenameWindows("file:stream", "file:stream");
10221022}
10231023
1024fn testBasename(input: []const u8, expected_output: []const u8) void {
1025 testing.expectEqualSlices(u8, expected_output, basename(input));
1024fn testBasename(input: []const u8, expected_output: []const u8) !void {
1025 try testing.expectEqualSlices(u8, expected_output, basename(input));
10261026}
10271027
1028fn testBasenamePosix(input: []const u8, expected_output: []const u8) void {
1029 testing.expectEqualSlices(u8, expected_output, basenamePosix(input));
1028fn testBasenamePosix(input: []const u8, expected_output: []const u8) !void {
1029 try testing.expectEqualSlices(u8, expected_output, basenamePosix(input));
10301030}
10311031
1032fn testBasenameWindows(input: []const u8, expected_output: []const u8) void {
1033 testing.expectEqualSlices(u8, expected_output, basenameWindows(input));
1032fn testBasenameWindows(input: []const u8, expected_output: []const u8) !void {
1033 try testing.expectEqualSlices(u8, expected_output, basenameWindows(input));
10341034}
10351035
10361036/// Returns the relative path from `from` to `to`. If `from` and `to` each
......@@ -1212,13 +1212,13 @@ test "relative" {
12121212fn testRelativePosix(from: []const u8, to: []const u8, expected_output: []const u8) !void {
12131213 const result = try relativePosix(testing.allocator, from, to);
12141214 defer testing.allocator.free(result);
1215 testing.expectEqualSlices(u8, expected_output, result);
1215 try testing.expectEqualSlices(u8, expected_output, result);
12161216}
12171217
12181218fn testRelativeWindows(from: []const u8, to: []const u8, expected_output: []const u8) !void {
12191219 const result = try relativeWindows(testing.allocator, from, to);
12201220 defer testing.allocator.free(result);
1221 testing.expectEqualSlices(u8, expected_output, result);
1221 try testing.expectEqualSlices(u8, expected_output, result);
12221222}
12231223
12241224/// Returns the extension of the file name (if any).
......@@ -1241,47 +1241,47 @@ pub fn extension(path: []const u8) []const u8 {
12411241 return filename[index..];
12421242}
12431243
1244fn testExtension(path: []const u8, expected: []const u8) void {
1245 std.testing.expectEqualStrings(expected, extension(path));
1244fn testExtension(path: []const u8, expected: []const u8) !void {
1245 try std.testing.expectEqualStrings(expected, extension(path));
12461246}
12471247
12481248test "extension" {
1249 testExtension("", "");
1250 testExtension(".", "");
1251 testExtension("a.", ".");
1252 testExtension("abc.", ".");
1253 testExtension(".a", "");
1254 testExtension(".file", "");
1255 testExtension(".gitignore", "");
1256 testExtension("file.ext", ".ext");
1257 testExtension("file.ext.", ".");
1258 testExtension("very-long-file.bruh", ".bruh");
1259 testExtension("a.b.c", ".c");
1260 testExtension("a.b.c/", ".c");
1261
1262 testExtension("/", "");
1263 testExtension("/.", "");
1264 testExtension("/a.", ".");
1265 testExtension("/abc.", ".");
1266 testExtension("/.a", "");
1267 testExtension("/.file", "");
1268 testExtension("/.gitignore", "");
1269 testExtension("/file.ext", ".ext");
1270 testExtension("/file.ext.", ".");
1271 testExtension("/very-long-file.bruh", ".bruh");
1272 testExtension("/a.b.c", ".c");
1273 testExtension("/a.b.c/", ".c");
1274
1275 testExtension("/foo/bar/bam/", "");
1276 testExtension("/foo/bar/bam/.", "");
1277 testExtension("/foo/bar/bam/a.", ".");
1278 testExtension("/foo/bar/bam/abc.", ".");
1279 testExtension("/foo/bar/bam/.a", "");
1280 testExtension("/foo/bar/bam/.file", "");
1281 testExtension("/foo/bar/bam/.gitignore", "");
1282 testExtension("/foo/bar/bam/file.ext", ".ext");
1283 testExtension("/foo/bar/bam/file.ext.", ".");
1284 testExtension("/foo/bar/bam/very-long-file.bruh", ".bruh");
1285 testExtension("/foo/bar/bam/a.b.c", ".c");
1286 testExtension("/foo/bar/bam/a.b.c/", ".c");
1249 try testExtension("", "");
1250 try testExtension(".", "");
1251 try testExtension("a.", ".");
1252 try testExtension("abc.", ".");
1253 try testExtension(".a", "");
1254 try testExtension(".file", "");
1255 try testExtension(".gitignore", "");
1256 try testExtension("file.ext", ".ext");
1257 try testExtension("file.ext.", ".");
1258 try testExtension("very-long-file.bruh", ".bruh");
1259 try testExtension("a.b.c", ".c");
1260 try testExtension("a.b.c/", ".c");
1261
1262 try testExtension("/", "");
1263 try testExtension("/.", "");
1264 try testExtension("/a.", ".");
1265 try testExtension("/abc.", ".");
1266 try testExtension("/.a", "");
1267 try testExtension("/.file", "");
1268 try testExtension("/.gitignore", "");
1269 try testExtension("/file.ext", ".ext");
1270 try testExtension("/file.ext.", ".");
1271 try testExtension("/very-long-file.bruh", ".bruh");
1272 try testExtension("/a.b.c", ".c");
1273 try testExtension("/a.b.c/", ".c");
1274
1275 try testExtension("/foo/bar/bam/", "");
1276 try testExtension("/foo/bar/bam/.", "");
1277 try testExtension("/foo/bar/bam/a.", ".");
1278 try testExtension("/foo/bar/bam/abc.", ".");
1279 try testExtension("/foo/bar/bam/.a", "");
1280 try testExtension("/foo/bar/bam/.file", "");
1281 try testExtension("/foo/bar/bam/.gitignore", "");
1282 try testExtension("/foo/bar/bam/file.ext", ".ext");
1283 try testExtension("/foo/bar/bam/file.ext.", ".");
1284 try testExtension("/foo/bar/bam/very-long-file.bruh", ".bruh");
1285 try testExtension("/foo/bar/bam/a.b.c", ".c");
1286 try testExtension("/foo/bar/bam/a.b.c/", ".c");
12871287}
lib/std/fs/test.zig+52-52
......@@ -46,7 +46,7 @@ test "Dir.readLink" {
4646fn testReadLink(dir: Dir, target_path: []const u8, symlink_path: []const u8) !void {
4747 var buffer: [fs.MAX_PATH_BYTES]u8 = undefined;
4848 const given = try dir.readLink(symlink_path, buffer[0..]);
49 testing.expect(mem.eql(u8, target_path, given));
49 try testing.expect(mem.eql(u8, target_path, given));
5050}
5151
5252test "accessAbsolute" {
......@@ -132,7 +132,7 @@ test "readLinkAbsolute" {
132132fn testReadLinkAbsolute(target_path: []const u8, symlink_path: []const u8) !void {
133133 var buffer: [fs.MAX_PATH_BYTES]u8 = undefined;
134134 const given = try fs.readLinkAbsolute(symlink_path, buffer[0..]);
135 testing.expect(mem.eql(u8, target_path, given));
135 try testing.expect(mem.eql(u8, target_path, given));
136136}
137137
138138test "Dir.Iterator" {
......@@ -159,9 +159,9 @@ test "Dir.Iterator" {
159159 try entries.append(Dir.Entry{ .name = name, .kind = entry.kind });
160160 }
161161
162 testing.expect(entries.items.len == 2); // note that the Iterator skips '.' and '..'
163 testing.expect(contains(&entries, Dir.Entry{ .name = "some_file", .kind = Dir.Entry.Kind.File }));
164 testing.expect(contains(&entries, Dir.Entry{ .name = "some_dir", .kind = Dir.Entry.Kind.Directory }));
162 try testing.expect(entries.items.len == 2); // note that the Iterator skips '.' and '..'
163 try testing.expect(contains(&entries, Dir.Entry{ .name = "some_file", .kind = Dir.Entry.Kind.File }));
164 try testing.expect(contains(&entries, Dir.Entry{ .name = "some_dir", .kind = Dir.Entry.Kind.Directory }));
165165}
166166
167167fn entryEql(lhs: Dir.Entry, rhs: Dir.Entry) bool {
......@@ -203,7 +203,7 @@ test "Dir.realpath smoke test" {
203203 const file_path = try tmp_dir.dir.realpath("test_file", buf1[0..]);
204204 const expected_path = try fs.path.join(&arena.allocator, &[_][]const u8{ base_path, "test_file" });
205205
206 testing.expect(mem.eql(u8, file_path, expected_path));
206 try testing.expect(mem.eql(u8, file_path, expected_path));
207207 }
208208
209209 // Next, test alloc version
......@@ -211,7 +211,7 @@ test "Dir.realpath smoke test" {
211211 const file_path = try tmp_dir.dir.realpathAlloc(&arena.allocator, "test_file");
212212 const expected_path = try fs.path.join(&arena.allocator, &[_][]const u8{ base_path, "test_file" });
213213
214 testing.expect(mem.eql(u8, file_path, expected_path));
214 try testing.expect(mem.eql(u8, file_path, expected_path));
215215 }
216216}
217217
......@@ -224,7 +224,7 @@ test "readAllAlloc" {
224224
225225 const buf1 = try file.readToEndAlloc(testing.allocator, 1024);
226226 defer testing.allocator.free(buf1);
227 testing.expect(buf1.len == 0);
227 try testing.expect(buf1.len == 0);
228228
229229 const write_buf: []const u8 = "this is a test.\nthis is a test.\nthis is a test.\nthis is a test.\n";
230230 try file.writeAll(write_buf);
......@@ -233,19 +233,19 @@ test "readAllAlloc" {
233233 // max_bytes > file_size
234234 const buf2 = try file.readToEndAlloc(testing.allocator, 1024);
235235 defer testing.allocator.free(buf2);
236 testing.expectEqual(write_buf.len, buf2.len);
237 testing.expect(std.mem.eql(u8, write_buf, buf2));
236 try testing.expectEqual(write_buf.len, buf2.len);
237 try testing.expect(std.mem.eql(u8, write_buf, buf2));
238238 try file.seekTo(0);
239239
240240 // max_bytes == file_size
241241 const buf3 = try file.readToEndAlloc(testing.allocator, write_buf.len);
242242 defer testing.allocator.free(buf3);
243 testing.expectEqual(write_buf.len, buf3.len);
244 testing.expect(std.mem.eql(u8, write_buf, buf3));
243 try testing.expectEqual(write_buf.len, buf3.len);
244 try testing.expect(std.mem.eql(u8, write_buf, buf3));
245245 try file.seekTo(0);
246246
247247 // max_bytes < file_size
248 testing.expectError(error.FileTooBig, file.readToEndAlloc(testing.allocator, write_buf.len - 1));
248 try testing.expectError(error.FileTooBig, file.readToEndAlloc(testing.allocator, write_buf.len - 1));
249249}
250250
251251test "directory operations on files" {
......@@ -257,22 +257,22 @@ test "directory operations on files" {
257257 var file = try tmp_dir.dir.createFile(test_file_name, .{ .read = true });
258258 file.close();
259259
260 testing.expectError(error.PathAlreadyExists, tmp_dir.dir.makeDir(test_file_name));
261 testing.expectError(error.NotDir, tmp_dir.dir.openDir(test_file_name, .{}));
262 testing.expectError(error.NotDir, tmp_dir.dir.deleteDir(test_file_name));
260 try testing.expectError(error.PathAlreadyExists, tmp_dir.dir.makeDir(test_file_name));
261 try testing.expectError(error.NotDir, tmp_dir.dir.openDir(test_file_name, .{}));
262 try testing.expectError(error.NotDir, tmp_dir.dir.deleteDir(test_file_name));
263263
264264 if (builtin.os.tag != .wasi and builtin.os.tag != .freebsd and builtin.os.tag != .openbsd) {
265265 const absolute_path = try tmp_dir.dir.realpathAlloc(testing.allocator, test_file_name);
266266 defer testing.allocator.free(absolute_path);
267267
268 testing.expectError(error.PathAlreadyExists, fs.makeDirAbsolute(absolute_path));
269 testing.expectError(error.NotDir, fs.deleteDirAbsolute(absolute_path));
268 try testing.expectError(error.PathAlreadyExists, fs.makeDirAbsolute(absolute_path));
269 try testing.expectError(error.NotDir, fs.deleteDirAbsolute(absolute_path));
270270 }
271271
272272 // ensure the file still exists and is a file as a sanity check
273273 file = try tmp_dir.dir.openFile(test_file_name, .{});
274274 const stat = try file.stat();
275 testing.expect(stat.kind == .File);
275 try testing.expect(stat.kind == .File);
276276 file.close();
277277}
278278
......@@ -287,23 +287,23 @@ test "file operations on directories" {
287287
288288 try tmp_dir.dir.makeDir(test_dir_name);
289289
290 testing.expectError(error.IsDir, tmp_dir.dir.createFile(test_dir_name, .{}));
291 testing.expectError(error.IsDir, tmp_dir.dir.deleteFile(test_dir_name));
290 try testing.expectError(error.IsDir, tmp_dir.dir.createFile(test_dir_name, .{}));
291 try testing.expectError(error.IsDir, tmp_dir.dir.deleteFile(test_dir_name));
292292 // Currently, WASI will return error.Unexpected (via ENOTCAPABLE) when attempting fd_read on a directory handle.
293293 // TODO: Re-enable on WASI once https://github.com/bytecodealliance/wasmtime/issues/1935 is resolved.
294294 if (builtin.os.tag != .wasi) {
295 testing.expectError(error.IsDir, tmp_dir.dir.readFileAlloc(testing.allocator, test_dir_name, std.math.maxInt(usize)));
295 try testing.expectError(error.IsDir, tmp_dir.dir.readFileAlloc(testing.allocator, test_dir_name, std.math.maxInt(usize)));
296296 }
297297 // Note: The `.write = true` is necessary to ensure the error occurs on all platforms.
298298 // TODO: Add a read-only test as well, see https://github.com/ziglang/zig/issues/5732
299 testing.expectError(error.IsDir, tmp_dir.dir.openFile(test_dir_name, .{ .write = true }));
299 try testing.expectError(error.IsDir, tmp_dir.dir.openFile(test_dir_name, .{ .write = true }));
300300
301301 if (builtin.os.tag != .wasi and builtin.os.tag != .freebsd and builtin.os.tag != .openbsd) {
302302 const absolute_path = try tmp_dir.dir.realpathAlloc(testing.allocator, test_dir_name);
303303 defer testing.allocator.free(absolute_path);
304304
305 testing.expectError(error.IsDir, fs.createFileAbsolute(absolute_path, .{}));
306 testing.expectError(error.IsDir, fs.deleteFileAbsolute(absolute_path));
305 try testing.expectError(error.IsDir, fs.createFileAbsolute(absolute_path, .{}));
306 try testing.expectError(error.IsDir, fs.deleteFileAbsolute(absolute_path));
307307 }
308308
309309 // ensure the directory still exists as a sanity check
......@@ -316,7 +316,7 @@ test "deleteDir" {
316316 defer tmp_dir.cleanup();
317317
318318 // deleting a non-existent directory
319 testing.expectError(error.FileNotFound, tmp_dir.dir.deleteDir("test_dir"));
319 try testing.expectError(error.FileNotFound, tmp_dir.dir.deleteDir("test_dir"));
320320
321321 var dir = try tmp_dir.dir.makeOpenPath("test_dir", .{});
322322 var file = try dir.createFile("test_file", .{});
......@@ -326,7 +326,7 @@ test "deleteDir" {
326326 // deleting a non-empty directory
327327 // TODO: Re-enable this check on Windows, see https://github.com/ziglang/zig/issues/5537
328328 if (builtin.os.tag != .windows) {
329 testing.expectError(error.DirNotEmpty, tmp_dir.dir.deleteDir("test_dir"));
329 try testing.expectError(error.DirNotEmpty, tmp_dir.dir.deleteDir("test_dir"));
330330 }
331331
332332 dir = try tmp_dir.dir.openDir("test_dir", .{});
......@@ -341,7 +341,7 @@ test "Dir.rename files" {
341341 var tmp_dir = tmpDir(.{});
342342 defer tmp_dir.cleanup();
343343
344 testing.expectError(error.FileNotFound, tmp_dir.dir.rename("missing_file_name", "something_else"));
344 try testing.expectError(error.FileNotFound, tmp_dir.dir.rename("missing_file_name", "something_else"));
345345
346346 // Renaming files
347347 const test_file_name = "test_file";
......@@ -351,7 +351,7 @@ test "Dir.rename files" {
351351 try tmp_dir.dir.rename(test_file_name, renamed_test_file_name);
352352
353353 // Ensure the file was renamed
354 testing.expectError(error.FileNotFound, tmp_dir.dir.openFile(test_file_name, .{}));
354 try testing.expectError(error.FileNotFound, tmp_dir.dir.openFile(test_file_name, .{}));
355355 file = try tmp_dir.dir.openFile(renamed_test_file_name, .{});
356356 file.close();
357357
......@@ -363,7 +363,7 @@ test "Dir.rename files" {
363363 existing_file.close();
364364 try tmp_dir.dir.rename(renamed_test_file_name, "existing_file");
365365
366 testing.expectError(error.FileNotFound, tmp_dir.dir.openFile(renamed_test_file_name, .{}));
366 try testing.expectError(error.FileNotFound, tmp_dir.dir.openFile(renamed_test_file_name, .{}));
367367 file = try tmp_dir.dir.openFile("existing_file", .{});
368368 file.close();
369369}
......@@ -380,7 +380,7 @@ test "Dir.rename directories" {
380380 try tmp_dir.dir.rename("test_dir", "test_dir_renamed");
381381
382382 // Ensure the directory was renamed
383 testing.expectError(error.FileNotFound, tmp_dir.dir.openDir("test_dir", .{}));
383 try testing.expectError(error.FileNotFound, tmp_dir.dir.openDir("test_dir", .{}));
384384 var dir = try tmp_dir.dir.openDir("test_dir_renamed", .{});
385385
386386 // Put a file in the directory
......@@ -391,7 +391,7 @@ test "Dir.rename directories" {
391391 try tmp_dir.dir.rename("test_dir_renamed", "test_dir_renamed_again");
392392
393393 // Ensure the directory was renamed and the file still exists in it
394 testing.expectError(error.FileNotFound, tmp_dir.dir.openDir("test_dir_renamed", .{}));
394 try testing.expectError(error.FileNotFound, tmp_dir.dir.openDir("test_dir_renamed", .{}));
395395 dir = try tmp_dir.dir.openDir("test_dir_renamed_again", .{});
396396 file = try dir.openFile("test_file", .{});
397397 file.close();
......@@ -402,7 +402,7 @@ test "Dir.rename directories" {
402402 file = try target_dir.createFile("filler", .{ .read = true });
403403 file.close();
404404
405 testing.expectError(error.PathAlreadyExists, tmp_dir.dir.rename("test_dir_renamed_again", "non_empty_target_dir"));
405 try testing.expectError(error.PathAlreadyExists, tmp_dir.dir.rename("test_dir_renamed_again", "non_empty_target_dir"));
406406
407407 // Ensure the directory was not renamed
408408 dir = try tmp_dir.dir.openDir("test_dir_renamed_again", .{});
......@@ -421,8 +421,8 @@ test "Dir.rename file <-> dir" {
421421 var file = try tmp_dir.dir.createFile("test_file", .{ .read = true });
422422 file.close();
423423 try tmp_dir.dir.makeDir("test_dir");
424 testing.expectError(error.IsDir, tmp_dir.dir.rename("test_file", "test_dir"));
425 testing.expectError(error.NotDir, tmp_dir.dir.rename("test_dir", "test_file"));
424 try testing.expectError(error.IsDir, tmp_dir.dir.rename("test_file", "test_dir"));
425 try testing.expectError(error.NotDir, tmp_dir.dir.rename("test_dir", "test_file"));
426426}
427427
428428test "rename" {
......@@ -440,7 +440,7 @@ test "rename" {
440440 try fs.rename(tmp_dir1.dir, test_file_name, tmp_dir2.dir, renamed_test_file_name);
441441
442442 // ensure the file was renamed
443 testing.expectError(error.FileNotFound, tmp_dir1.dir.openFile(test_file_name, .{}));
443 try testing.expectError(error.FileNotFound, tmp_dir1.dir.openFile(test_file_name, .{}));
444444 file = try tmp_dir2.dir.openFile(renamed_test_file_name, .{});
445445 file.close();
446446}
......@@ -461,7 +461,7 @@ test "renameAbsolute" {
461461 break :blk try fs.realpathAlloc(&arena.allocator, relative_path);
462462 };
463463
464 testing.expectError(error.FileNotFound, fs.renameAbsolute(
464 try testing.expectError(error.FileNotFound, fs.renameAbsolute(
465465 try fs.path.join(allocator, &[_][]const u8{ base_path, "missing_file_name" }),
466466 try fs.path.join(allocator, &[_][]const u8{ base_path, "something_else" }),
467467 ));
......@@ -477,10 +477,10 @@ test "renameAbsolute" {
477477 );
478478
479479 // ensure the file was renamed
480 testing.expectError(error.FileNotFound, tmp_dir.dir.openFile(test_file_name, .{}));
480 try testing.expectError(error.FileNotFound, tmp_dir.dir.openFile(test_file_name, .{}));
481481 file = try tmp_dir.dir.openFile(renamed_test_file_name, .{});
482482 const stat = try file.stat();
483 testing.expect(stat.kind == .File);
483 try testing.expect(stat.kind == .File);
484484 file.close();
485485
486486 // Renaming directories
......@@ -493,7 +493,7 @@ test "renameAbsolute" {
493493 );
494494
495495 // ensure the directory was renamed
496 testing.expectError(error.FileNotFound, tmp_dir.dir.openDir(test_dir_name, .{}));
496 try testing.expectError(error.FileNotFound, tmp_dir.dir.openDir(test_dir_name, .{}));
497497 var dir = try tmp_dir.dir.openDir(renamed_test_dir_name, .{});
498498 dir.close();
499499}
......@@ -516,7 +516,7 @@ test "makePath, put some files in it, deleteTree" {
516516 if (tmp.dir.openDir("os_test_tmp", .{})) |dir| {
517517 @panic("expected error");
518518 } else |err| {
519 testing.expect(err == error.FileNotFound);
519 try testing.expect(err == error.FileNotFound);
520520 }
521521}
522522
......@@ -530,7 +530,7 @@ test "access file" {
530530 if (tmp.dir.access("os_test_tmp" ++ fs.path.sep_str ++ "file.txt", .{})) |ok| {
531531 @panic("expected error");
532532 } else |err| {
533 testing.expect(err == error.FileNotFound);
533 try testing.expect(err == error.FileNotFound);
534534 }
535535
536536 try tmp.dir.writeFile("os_test_tmp" ++ fs.path.sep_str ++ "file.txt", "");
......@@ -600,7 +600,7 @@ test "sendfile" {
600600 .header_count = 2,
601601 });
602602 const amt = try dest_file.preadAll(&written_buf, 0);
603 testing.expect(mem.eql(u8, written_buf[0..amt], "header1\nsecond header\nine1\nsecontrailer1\nsecond trailer\n"));
603 try testing.expect(mem.eql(u8, written_buf[0..amt], "header1\nsecond header\nine1\nsecontrailer1\nsecond trailer\n"));
604604}
605605
606606test "copyRangeAll" {
......@@ -626,7 +626,7 @@ test "copyRangeAll" {
626626 _ = try src_file.copyRangeAll(0, dest_file, 0, data.len);
627627
628628 const amt = try dest_file.preadAll(&written_buf, 0);
629 testing.expect(mem.eql(u8, written_buf[0..amt], data));
629 try testing.expect(mem.eql(u8, written_buf[0..amt], data));
630630}
631631
632632test "fs.copyFile" {
......@@ -655,7 +655,7 @@ fn expectFileContents(dir: Dir, file_path: []const u8, data: []const u8) !void {
655655 const contents = try dir.readFileAlloc(testing.allocator, file_path, 1000);
656656 defer testing.allocator.free(contents);
657657
658 testing.expectEqualSlices(u8, data, contents);
658 try testing.expectEqualSlices(u8, data, contents);
659659}
660660
661661test "AtomicFile" {
......@@ -676,7 +676,7 @@ test "AtomicFile" {
676676 }
677677 const content = try tmp.dir.readFileAlloc(testing.allocator, test_out_file, 9999);
678678 defer testing.allocator.free(content);
679 testing.expect(mem.eql(u8, content, test_content));
679 try testing.expect(mem.eql(u8, content, test_content));
680680
681681 try tmp.dir.deleteFile(test_out_file);
682682}
......@@ -685,7 +685,7 @@ test "realpath" {
685685 if (builtin.os.tag == .wasi) return error.SkipZigTest;
686686
687687 var buf: [std.fs.MAX_PATH_BYTES]u8 = undefined;
688 testing.expectError(error.FileNotFound, fs.realpath("definitely_bogus_does_not_exist1234", &buf));
688 try testing.expectError(error.FileNotFound, fs.realpath("definitely_bogus_does_not_exist1234", &buf));
689689}
690690
691691test "open file with exclusive nonblocking lock twice" {
......@@ -700,7 +700,7 @@ test "open file with exclusive nonblocking lock twice" {
700700 defer file1.close();
701701
702702 const file2 = tmp.dir.createFile(filename, .{ .lock = .Exclusive, .lock_nonblocking = true });
703 testing.expectError(error.WouldBlock, file2);
703 try testing.expectError(error.WouldBlock, file2);
704704}
705705
706706test "open file with shared and exclusive nonblocking lock" {
......@@ -715,7 +715,7 @@ test "open file with shared and exclusive nonblocking lock" {
715715 defer file1.close();
716716
717717 const file2 = tmp.dir.createFile(filename, .{ .lock = .Exclusive, .lock_nonblocking = true });
718 testing.expectError(error.WouldBlock, file2);
718 try testing.expectError(error.WouldBlock, file2);
719719}
720720
721721test "open file with exclusive and shared nonblocking lock" {
......@@ -730,7 +730,7 @@ test "open file with exclusive and shared nonblocking lock" {
730730 defer file1.close();
731731
732732 const file2 = tmp.dir.createFile(filename, .{ .lock = .Shared, .lock_nonblocking = true });
733 testing.expectError(error.WouldBlock, file2);
733 try testing.expectError(error.WouldBlock, file2);
734734}
735735
736736test "open file with exclusive lock twice, make sure it waits" {
......@@ -790,7 +790,7 @@ test "open file with exclusive nonblocking lock twice (absolute paths)" {
790790
791791 const file2 = fs.createFileAbsolute(filename, .{ .lock = .Exclusive, .lock_nonblocking = true });
792792 file1.close();
793 testing.expectError(error.WouldBlock, file2);
793 try testing.expectError(error.WouldBlock, file2);
794794
795795 try fs.deleteFileAbsolute(filename);
796796}
......@@ -830,6 +830,6 @@ test "walker" {
830830 try fs.path.join(allocator, &[_][]const u8{ expected_dir_name, name });
831831
832832 var entry = (try walker.next()).?;
833 testing.expectEqualStrings(expected_dir_name, try fs.path.relative(allocator, tmp_path, entry.path));
833 try testing.expectEqualStrings(expected_dir_name, try fs.path.relative(allocator, tmp_path, entry.path));
834834 }
835835}
lib/std/fs/wasi.zig+3-3
......@@ -174,8 +174,8 @@ test "extracting WASI preopens" {
174174
175175 try preopens.populate();
176176
177 std.testing.expectEqual(@as(usize, 1), preopens.asSlice().len);
177 try std.testing.expectEqual(@as(usize, 1), preopens.asSlice().len);
178178 const preopen = preopens.find(PreopenType{ .Dir = "." }) orelse unreachable;
179 std.testing.expect(preopen.@"type".eql(PreopenType{ .Dir = "." }));
180 std.testing.expectEqual(@as(usize, 3), preopen.fd);
179 try std.testing.expect(preopen.@"type".eql(PreopenType{ .Dir = "." }));
180 try std.testing.expectEqual(@as(usize, 3), preopen.fd);
181181}
lib/std/fs/watch.zig+3-3
......@@ -662,13 +662,13 @@ fn testWriteWatchWriteDelete(allocator: *Allocator) !void {
662662
663663 const read_contents = try std.fs.cwd().readFileAlloc(allocator, file_path, 1024 * 1024);
664664 defer allocator.free(read_contents);
665 testing.expectEqualSlices(u8, contents, read_contents);
665 try testing.expectEqualSlices(u8, contents, read_contents);
666666
667667 // now watch the file
668668 var watch = try Watch(void).init(allocator, 0);
669669 defer watch.deinit();
670670
671 testing.expect((try watch.addFile(file_path, {})) == null);
671 try testing.expect((try watch.addFile(file_path, {})) == null);
672672
673673 var ev = async watch.channel.get();
674674 var ev_consumed = false;
......@@ -698,7 +698,7 @@ fn testWriteWatchWriteDelete(allocator: *Allocator) !void {
698698 const contents_updated = try std.fs.cwd().readFileAlloc(allocator, file_path, 1024 * 1024);
699699 defer allocator.free(contents_updated);
700700
701 testing.expectEqualSlices(u8,
701 try testing.expectEqualSlices(u8,
702702 \\line 1
703703 \\lorem ipsum
704704 , contents_updated);
lib/std/hash/adler.zig+6-6
......@@ -99,21 +99,21 @@ pub const Adler32 = struct {
9999};
100100
101101test "adler32 sanity" {
102 testing.expectEqual(@as(u32, 0x620062), Adler32.hash("a"));
103 testing.expectEqual(@as(u32, 0xbc002ed), Adler32.hash("example"));
102 try testing.expectEqual(@as(u32, 0x620062), Adler32.hash("a"));
103 try testing.expectEqual(@as(u32, 0xbc002ed), Adler32.hash("example"));
104104}
105105
106106test "adler32 long" {
107107 const long1 = [_]u8{1} ** 1024;
108 testing.expectEqual(@as(u32, 0x06780401), Adler32.hash(long1[0..]));
108 try testing.expectEqual(@as(u32, 0x06780401), Adler32.hash(long1[0..]));
109109
110110 const long2 = [_]u8{1} ** 1025;
111 testing.expectEqual(@as(u32, 0x0a7a0402), Adler32.hash(long2[0..]));
111 try testing.expectEqual(@as(u32, 0x0a7a0402), Adler32.hash(long2[0..]));
112112}
113113
114114test "adler32 very long" {
115115 const long = [_]u8{1} ** 5553;
116 testing.expectEqual(@as(u32, 0x707f15b2), Adler32.hash(long[0..]));
116 try testing.expectEqual(@as(u32, 0x707f15b2), Adler32.hash(long[0..]));
117117}
118118
119119test "adler32 very long with variation" {
......@@ -129,5 +129,5 @@ test "adler32 very long with variation" {
129129 break :blk result;
130130 };
131131
132 testing.expectEqual(@as(u32, 0x5af38d6e), std.hash.Adler32.hash(long[0..]));
132 try testing.expectEqual(@as(u32, 0x5af38d6e), std.hash.Adler32.hash(long[0..]));
133133}
lib/std/hash/auto_hash.zig+46-46
......@@ -239,18 +239,18 @@ fn testHashDeepRecursive(key: anytype) u64 {
239239
240240test "typeContainsSlice" {
241241 comptime {
242 testing.expect(!typeContainsSlice(meta.Tag(builtin.TypeInfo)));
242 try testing.expect(!typeContainsSlice(meta.Tag(builtin.TypeInfo)));
243243
244 testing.expect(typeContainsSlice([]const u8));
245 testing.expect(!typeContainsSlice(u8));
244 try testing.expect(typeContainsSlice([]const u8));
245 try testing.expect(!typeContainsSlice(u8));
246246 const A = struct { x: []const u8 };
247247 const B = struct { a: A };
248248 const C = struct { b: B };
249249 const D = struct { x: u8 };
250 testing.expect(typeContainsSlice(A));
251 testing.expect(typeContainsSlice(B));
252 testing.expect(typeContainsSlice(C));
253 testing.expect(!typeContainsSlice(D));
250 try testing.expect(typeContainsSlice(A));
251 try testing.expect(typeContainsSlice(B));
252 try testing.expect(typeContainsSlice(C));
253 try testing.expect(!typeContainsSlice(D));
254254 }
255255}
256256
......@@ -261,17 +261,17 @@ test "hash pointer" {
261261 const c = &array[2];
262262 const d = a;
263263
264 testing.expect(testHashShallow(a) == testHashShallow(d));
265 testing.expect(testHashShallow(a) != testHashShallow(c));
266 testing.expect(testHashShallow(a) != testHashShallow(b));
264 try testing.expect(testHashShallow(a) == testHashShallow(d));
265 try testing.expect(testHashShallow(a) != testHashShallow(c));
266 try testing.expect(testHashShallow(a) != testHashShallow(b));
267267
268 testing.expect(testHashDeep(a) == testHashDeep(a));
269 testing.expect(testHashDeep(a) == testHashDeep(c));
270 testing.expect(testHashDeep(a) == testHashDeep(b));
268 try testing.expect(testHashDeep(a) == testHashDeep(a));
269 try testing.expect(testHashDeep(a) == testHashDeep(c));
270 try testing.expect(testHashDeep(a) == testHashDeep(b));
271271
272 testing.expect(testHashDeepRecursive(a) == testHashDeepRecursive(a));
273 testing.expect(testHashDeepRecursive(a) == testHashDeepRecursive(c));
274 testing.expect(testHashDeepRecursive(a) == testHashDeepRecursive(b));
272 try testing.expect(testHashDeepRecursive(a) == testHashDeepRecursive(a));
273 try testing.expect(testHashDeepRecursive(a) == testHashDeepRecursive(c));
274 try testing.expect(testHashDeepRecursive(a) == testHashDeepRecursive(b));
275275}
276276
277277test "hash slice shallow" {
......@@ -286,10 +286,10 @@ test "hash slice shallow" {
286286 const a = array1[runtime_zero..];
287287 const b = array2[runtime_zero..];
288288 const c = array1[runtime_zero..3];
289 testing.expect(testHashShallow(a) == testHashShallow(a));
290 testing.expect(testHashShallow(a) != testHashShallow(array1));
291 testing.expect(testHashShallow(a) != testHashShallow(b));
292 testing.expect(testHashShallow(a) != testHashShallow(c));
289 try testing.expect(testHashShallow(a) == testHashShallow(a));
290 try testing.expect(testHashShallow(a) != testHashShallow(array1));
291 try testing.expect(testHashShallow(a) != testHashShallow(b));
292 try testing.expect(testHashShallow(a) != testHashShallow(c));
293293}
294294
295295test "hash slice deep" {
......@@ -302,10 +302,10 @@ test "hash slice deep" {
302302 const a = array1[0..];
303303 const b = array2[0..];
304304 const c = array1[0..3];
305 testing.expect(testHashDeep(a) == testHashDeep(a));
306 testing.expect(testHashDeep(a) == testHashDeep(array1));
307 testing.expect(testHashDeep(a) == testHashDeep(b));
308 testing.expect(testHashDeep(a) != testHashDeep(c));
305 try testing.expect(testHashDeep(a) == testHashDeep(a));
306 try testing.expect(testHashDeep(a) == testHashDeep(array1));
307 try testing.expect(testHashDeep(a) == testHashDeep(b));
308 try testing.expect(testHashDeep(a) != testHashDeep(c));
309309}
310310
311311test "hash struct deep" {
......@@ -331,28 +331,28 @@ test "hash struct deep" {
331331 defer allocator.destroy(bar.c);
332332 defer allocator.destroy(baz.c);
333333
334 testing.expect(testHashDeep(foo) == testHashDeep(bar));
335 testing.expect(testHashDeep(foo) != testHashDeep(baz));
336 testing.expect(testHashDeep(bar) != testHashDeep(baz));
334 try testing.expect(testHashDeep(foo) == testHashDeep(bar));
335 try testing.expect(testHashDeep(foo) != testHashDeep(baz));
336 try testing.expect(testHashDeep(bar) != testHashDeep(baz));
337337
338338 var hasher = Wyhash.init(0);
339339 const h = testHashDeep(foo);
340340 autoHash(&hasher, foo.a);
341341 autoHash(&hasher, foo.b);
342342 autoHash(&hasher, foo.c.*);
343 testing.expectEqual(h, hasher.final());
343 try testing.expectEqual(h, hasher.final());
344344
345345 const h2 = testHashDeepRecursive(&foo);
346 testing.expect(h2 != testHashDeep(&foo));
347 testing.expect(h2 == testHashDeep(foo));
346 try testing.expect(h2 != testHashDeep(&foo));
347 try testing.expect(h2 == testHashDeep(foo));
348348}
349349
350350test "testHash optional" {
351351 const a: ?u32 = 123;
352352 const b: ?u32 = null;
353 testing.expectEqual(testHash(a), testHash(@as(u32, 123)));
354 testing.expect(testHash(a) != testHash(b));
355 testing.expectEqual(testHash(b), 0);
353 try testing.expectEqual(testHash(a), testHash(@as(u32, 123)));
354 try testing.expect(testHash(a) != testHash(b));
355 try testing.expectEqual(testHash(b), 0);
356356}
357357
358358test "testHash array" {
......@@ -362,7 +362,7 @@ test "testHash array" {
362362 autoHash(&hasher, @as(u32, 1));
363363 autoHash(&hasher, @as(u32, 2));
364364 autoHash(&hasher, @as(u32, 3));
365 testing.expectEqual(h, hasher.final());
365 try testing.expectEqual(h, hasher.final());
366366}
367367
368368test "testHash struct" {
......@@ -377,7 +377,7 @@ test "testHash struct" {
377377 autoHash(&hasher, @as(u32, 1));
378378 autoHash(&hasher, @as(u32, 2));
379379 autoHash(&hasher, @as(u32, 3));
380 testing.expectEqual(h, hasher.final());
380 try testing.expectEqual(h, hasher.final());
381381}
382382
383383test "testHash union" {
......@@ -390,12 +390,12 @@ test "testHash union" {
390390 const a = Foo{ .A = 18 };
391391 var b = Foo{ .B = true };
392392 const c = Foo{ .C = 18 };
393 testing.expect(testHash(a) == testHash(a));
394 testing.expect(testHash(a) != testHash(b));
395 testing.expect(testHash(a) != testHash(c));
393 try testing.expect(testHash(a) == testHash(a));
394 try testing.expect(testHash(a) != testHash(b));
395 try testing.expect(testHash(a) != testHash(c));
396396
397397 b = Foo{ .A = 18 };
398 testing.expect(testHash(a) == testHash(b));
398 try testing.expect(testHash(a) == testHash(b));
399399}
400400
401401test "testHash vector" {
......@@ -404,13 +404,13 @@ test "testHash vector" {
404404
405405 const a: meta.Vector(4, u32) = [_]u32{ 1, 2, 3, 4 };
406406 const b: meta.Vector(4, u32) = [_]u32{ 1, 2, 3, 5 };
407 testing.expect(testHash(a) == testHash(a));
408 testing.expect(testHash(a) != testHash(b));
407 try testing.expect(testHash(a) == testHash(a));
408 try testing.expect(testHash(a) != testHash(b));
409409
410410 const c: meta.Vector(4, u31) = [_]u31{ 1, 2, 3, 4 };
411411 const d: meta.Vector(4, u31) = [_]u31{ 1, 2, 3, 5 };
412 testing.expect(testHash(c) == testHash(c));
413 testing.expect(testHash(c) != testHash(d));
412 try testing.expect(testHash(c) == testHash(c));
413 try testing.expect(testHash(c) != testHash(d));
414414}
415415
416416test "testHash error union" {
......@@ -422,7 +422,7 @@ test "testHash error union" {
422422 };
423423 const f = Foo{};
424424 const g: Errors!Foo = Errors.Test;
425 testing.expect(testHash(f) != testHash(g));
426 testing.expect(testHash(f) == testHash(Foo{}));
427 testing.expect(testHash(g) == testHash(Errors.Test));
425 try testing.expect(testHash(f) != testHash(g));
426 try testing.expect(testHash(f) == testHash(Foo{}));
427 try testing.expect(testHash(g) == testHash(Errors.Test));
428428}
lib/std/hash/cityhash.zig+7-7
......@@ -381,14 +381,14 @@ fn CityHash32hashIgnoreSeed(str: []const u8, seed: u32) u32 {
381381
382382test "cityhash32" {
383383 const Test = struct {
384 fn doTest() void {
384 fn doTest() !void {
385385 // Note: SMHasher doesn't provide a 32bit version of the algorithm.
386386 // Note: The implementation was verified against the Google Abseil version.
387 std.testing.expectEqual(SMHasherTest(CityHash32hashIgnoreSeed), 0x68254F81);
388 std.testing.expectEqual(SMHasherTest(CityHash32hashIgnoreSeed), 0x68254F81);
387 try std.testing.expectEqual(SMHasherTest(CityHash32hashIgnoreSeed), 0x68254F81);
388 try std.testing.expectEqual(SMHasherTest(CityHash32hashIgnoreSeed), 0x68254F81);
389389 }
390390 };
391 Test.doTest();
391 try Test.doTest();
392392 // TODO This is uncommented to prevent OOM on the CI server. Re-enable this test
393393 // case once we ship stage2.
394394 //@setEvalBranchQuota(50000);
......@@ -397,13 +397,13 @@ test "cityhash32" {
397397
398398test "cityhash64" {
399399 const Test = struct {
400 fn doTest() void {
400 fn doTest() !void {
401401 // Note: This is not compliant with the SMHasher implementation of CityHash64!
402402 // Note: The implementation was verified against the Google Abseil version.
403 std.testing.expectEqual(SMHasherTest(CityHash64.hashWithSeed), 0x5FABC5C5);
403 try std.testing.expectEqual(SMHasherTest(CityHash64.hashWithSeed), 0x5FABC5C5);
404404 }
405405 };
406 Test.doTest();
406 try Test.doTest();
407407 // TODO This is uncommented to prevent OOM on the CI server. Re-enable this test
408408 // case once we ship stage2.
409409 //@setEvalBranchQuota(50000);
lib/std/hash/crc.zig+12-12
......@@ -109,9 +109,9 @@ test "crc32 ieee" {
109109
110110 const Crc32Ieee = Crc32WithPoly(.IEEE);
111111
112 testing.expect(Crc32Ieee.hash("") == 0x00000000);
113 testing.expect(Crc32Ieee.hash("a") == 0xe8b7be43);
114 testing.expect(Crc32Ieee.hash("abc") == 0x352441c2);
112 try testing.expect(Crc32Ieee.hash("") == 0x00000000);
113 try testing.expect(Crc32Ieee.hash("a") == 0xe8b7be43);
114 try testing.expect(Crc32Ieee.hash("abc") == 0x352441c2);
115115}
116116
117117test "crc32 castagnoli" {
......@@ -119,9 +119,9 @@ test "crc32 castagnoli" {
119119
120120 const Crc32Castagnoli = Crc32WithPoly(.Castagnoli);
121121
122 testing.expect(Crc32Castagnoli.hash("") == 0x00000000);
123 testing.expect(Crc32Castagnoli.hash("a") == 0xc1d04330);
124 testing.expect(Crc32Castagnoli.hash("abc") == 0x364b3fb7);
122 try testing.expect(Crc32Castagnoli.hash("") == 0x00000000);
123 try testing.expect(Crc32Castagnoli.hash("a") == 0xc1d04330);
124 try testing.expect(Crc32Castagnoli.hash("abc") == 0x364b3fb7);
125125}
126126
127127// half-byte lookup table implementation.
......@@ -177,9 +177,9 @@ test "small crc32 ieee" {
177177
178178 const Crc32Ieee = Crc32SmallWithPoly(.IEEE);
179179
180 testing.expect(Crc32Ieee.hash("") == 0x00000000);
181 testing.expect(Crc32Ieee.hash("a") == 0xe8b7be43);
182 testing.expect(Crc32Ieee.hash("abc") == 0x352441c2);
180 try testing.expect(Crc32Ieee.hash("") == 0x00000000);
181 try testing.expect(Crc32Ieee.hash("a") == 0xe8b7be43);
182 try testing.expect(Crc32Ieee.hash("abc") == 0x352441c2);
183183}
184184
185185test "small crc32 castagnoli" {
......@@ -187,7 +187,7 @@ test "small crc32 castagnoli" {
187187
188188 const Crc32Castagnoli = Crc32SmallWithPoly(.Castagnoli);
189189
190 testing.expect(Crc32Castagnoli.hash("") == 0x00000000);
191 testing.expect(Crc32Castagnoli.hash("a") == 0xc1d04330);
192 testing.expect(Crc32Castagnoli.hash("abc") == 0x364b3fb7);
190 try testing.expect(Crc32Castagnoli.hash("") == 0x00000000);
191 try testing.expect(Crc32Castagnoli.hash("a") == 0xc1d04330);
192 try testing.expect(Crc32Castagnoli.hash("abc") == 0x364b3fb7);
193193}
lib/std/hash/fnv.zig+8-8
......@@ -46,18 +46,18 @@ fn Fnv1a(comptime T: type, comptime prime: T, comptime offset: T) type {
4646}
4747
4848test "fnv1a-32" {
49 testing.expect(Fnv1a_32.hash("") == 0x811c9dc5);
50 testing.expect(Fnv1a_32.hash("a") == 0xe40c292c);
51 testing.expect(Fnv1a_32.hash("foobar") == 0xbf9cf968);
49 try testing.expect(Fnv1a_32.hash("") == 0x811c9dc5);
50 try testing.expect(Fnv1a_32.hash("a") == 0xe40c292c);
51 try testing.expect(Fnv1a_32.hash("foobar") == 0xbf9cf968);
5252}
5353
5454test "fnv1a-64" {
55 testing.expect(Fnv1a_64.hash("") == 0xcbf29ce484222325);
56 testing.expect(Fnv1a_64.hash("a") == 0xaf63dc4c8601ec8c);
57 testing.expect(Fnv1a_64.hash("foobar") == 0x85944171f73967e8);
55 try testing.expect(Fnv1a_64.hash("") == 0xcbf29ce484222325);
56 try testing.expect(Fnv1a_64.hash("a") == 0xaf63dc4c8601ec8c);
57 try testing.expect(Fnv1a_64.hash("foobar") == 0x85944171f73967e8);
5858}
5959
6060test "fnv1a-128" {
61 testing.expect(Fnv1a_128.hash("") == 0x6c62272e07bb014262b821756295c58d);
62 testing.expect(Fnv1a_128.hash("a") == 0xd228cb696f1a8caf78912b704e4a8964);
61 try testing.expect(Fnv1a_128.hash("") == 0x6c62272e07bb014262b821756295c58d);
62 try testing.expect(Fnv1a_128.hash("a") == 0xd228cb696f1a8caf78912b704e4a8964);
6363}
lib/std/hash/murmur.zig+9-9
......@@ -308,7 +308,7 @@ fn SMHasherTest(comptime hash_fn: anytype, comptime hashbits: u32) u32 {
308308}
309309
310310test "murmur2_32" {
311 testing.expectEqual(SMHasherTest(Murmur2_32.hashWithSeed, 32), 0x27864C1E);
311 try testing.expectEqual(SMHasherTest(Murmur2_32.hashWithSeed, 32), 0x27864C1E);
312312 var v0: u32 = 0x12345678;
313313 var v1: u64 = 0x1234567812345678;
314314 var v0le: u32 = v0;
......@@ -317,12 +317,12 @@ test "murmur2_32" {
317317 v0le = @byteSwap(u32, v0le);
318318 v1le = @byteSwap(u64, v1le);
319319 }
320 testing.expectEqual(Murmur2_32.hash(@ptrCast([*]u8, &v0le)[0..4]), Murmur2_32.hashUint32(v0));
321 testing.expectEqual(Murmur2_32.hash(@ptrCast([*]u8, &v1le)[0..8]), Murmur2_32.hashUint64(v1));
320 try testing.expectEqual(Murmur2_32.hash(@ptrCast([*]u8, &v0le)[0..4]), Murmur2_32.hashUint32(v0));
321 try testing.expectEqual(Murmur2_32.hash(@ptrCast([*]u8, &v1le)[0..8]), Murmur2_32.hashUint64(v1));
322322}
323323
324324test "murmur2_64" {
325 std.testing.expectEqual(SMHasherTest(Murmur2_64.hashWithSeed, 64), 0x1F0D3804);
325 try std.testing.expectEqual(SMHasherTest(Murmur2_64.hashWithSeed, 64), 0x1F0D3804);
326326 var v0: u32 = 0x12345678;
327327 var v1: u64 = 0x1234567812345678;
328328 var v0le: u32 = v0;
......@@ -331,12 +331,12 @@ test "murmur2_64" {
331331 v0le = @byteSwap(u32, v0le);
332332 v1le = @byteSwap(u64, v1le);
333333 }
334 testing.expectEqual(Murmur2_64.hash(@ptrCast([*]u8, &v0le)[0..4]), Murmur2_64.hashUint32(v0));
335 testing.expectEqual(Murmur2_64.hash(@ptrCast([*]u8, &v1le)[0..8]), Murmur2_64.hashUint64(v1));
334 try testing.expectEqual(Murmur2_64.hash(@ptrCast([*]u8, &v0le)[0..4]), Murmur2_64.hashUint32(v0));
335 try testing.expectEqual(Murmur2_64.hash(@ptrCast([*]u8, &v1le)[0..8]), Murmur2_64.hashUint64(v1));
336336}
337337
338338test "murmur3_32" {
339 std.testing.expectEqual(SMHasherTest(Murmur3_32.hashWithSeed, 32), 0xB0F57EE3);
339 try std.testing.expectEqual(SMHasherTest(Murmur3_32.hashWithSeed, 32), 0xB0F57EE3);
340340 var v0: u32 = 0x12345678;
341341 var v1: u64 = 0x1234567812345678;
342342 var v0le: u32 = v0;
......@@ -345,6 +345,6 @@ test "murmur3_32" {
345345 v0le = @byteSwap(u32, v0le);
346346 v1le = @byteSwap(u64, v1le);
347347 }
348 testing.expectEqual(Murmur3_32.hash(@ptrCast([*]u8, &v0le)[0..4]), Murmur3_32.hashUint32(v0));
349 testing.expectEqual(Murmur3_32.hash(@ptrCast([*]u8, &v1le)[0..8]), Murmur3_32.hashUint64(v1));
348 try testing.expectEqual(Murmur3_32.hash(@ptrCast([*]u8, &v0le)[0..4]), Murmur3_32.hashUint32(v0));
349 try testing.expectEqual(Murmur3_32.hash(@ptrCast([*]u8, &v1le)[0..8]), Murmur3_32.hashUint64(v1));
350350}
lib/std/hash/wyhash.zig+11-11
......@@ -183,13 +183,13 @@ const expectEqual = std.testing.expectEqual;
183183test "test vectors" {
184184 const hash = Wyhash.hash;
185185
186 expectEqual(hash(0, ""), 0x0);
187 expectEqual(hash(1, "a"), 0xbed235177f41d328);
188 expectEqual(hash(2, "abc"), 0xbe348debe59b27c3);
189 expectEqual(hash(3, "message digest"), 0x37320f657213a290);
190 expectEqual(hash(4, "abcdefghijklmnopqrstuvwxyz"), 0xd0b270e1d8a7019c);
191 expectEqual(hash(5, "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"), 0x602a1894d3bbfe7f);
192 expectEqual(hash(6, "12345678901234567890123456789012345678901234567890123456789012345678901234567890"), 0x829e9c148b75970e);
186 try expectEqual(hash(0, ""), 0x0);
187 try expectEqual(hash(1, "a"), 0xbed235177f41d328);
188 try expectEqual(hash(2, "abc"), 0xbe348debe59b27c3);
189 try expectEqual(hash(3, "message digest"), 0x37320f657213a290);
190 try expectEqual(hash(4, "abcdefghijklmnopqrstuvwxyz"), 0xd0b270e1d8a7019c);
191 try expectEqual(hash(5, "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"), 0x602a1894d3bbfe7f);
192 try expectEqual(hash(6, "12345678901234567890123456789012345678901234567890123456789012345678901234567890"), 0x829e9c148b75970e);
193193}
194194
195195test "test vectors streaming" {
......@@ -197,19 +197,19 @@ test "test vectors streaming" {
197197 for ("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789") |e| {
198198 wh.update(mem.asBytes(&e));
199199 }
200 expectEqual(wh.final(), 0x602a1894d3bbfe7f);
200 try expectEqual(wh.final(), 0x602a1894d3bbfe7f);
201201
202202 const pattern = "1234567890";
203203 const count = 8;
204204 const result = 0x829e9c148b75970e;
205 expectEqual(Wyhash.hash(6, pattern ** 8), result);
205 try expectEqual(Wyhash.hash(6, pattern ** 8), result);
206206
207207 wh = Wyhash.init(6);
208208 var i: u32 = 0;
209209 while (i < count) : (i += 1) {
210210 wh.update(pattern);
211211 }
212 expectEqual(wh.final(), result);
212 try expectEqual(wh.final(), result);
213213}
214214
215215test "iterative non-divisible update" {
......@@ -231,6 +231,6 @@ test "iterative non-divisible update" {
231231 }
232232 const iterative_hash = wy.final();
233233
234 std.testing.expectEqual(iterative_hash, non_iterative_hash);
234 try std.testing.expectEqual(iterative_hash, non_iterative_hash);
235235 }
236236}
lib/std/hash_map.zig+72-72
......@@ -823,15 +823,15 @@ test "std.hash_map basic usage" {
823823 while (it.next()) |kv| {
824824 sum += kv.key;
825825 }
826 expect(sum == total);
826 try expect(sum == total);
827827
828828 i = 0;
829829 sum = 0;
830830 while (i < count) : (i += 1) {
831 expectEqual(map.get(i).?, i);
831 try expectEqual(map.get(i).?, i);
832832 sum += map.get(i).?;
833833 }
834 expectEqual(total, sum);
834 try expectEqual(total, sum);
835835}
836836
837837test "std.hash_map ensureCapacity" {
......@@ -840,13 +840,13 @@ test "std.hash_map ensureCapacity" {
840840
841841 try map.ensureCapacity(20);
842842 const initial_capacity = map.capacity();
843 testing.expect(initial_capacity >= 20);
843 try testing.expect(initial_capacity >= 20);
844844 var i: i32 = 0;
845845 while (i < 20) : (i += 1) {
846 testing.expect(map.fetchPutAssumeCapacity(i, i + 10) == null);
846 try testing.expect(map.fetchPutAssumeCapacity(i, i + 10) == null);
847847 }
848848 // shouldn't resize from putAssumeCapacity
849 testing.expect(initial_capacity == map.capacity());
849 try testing.expect(initial_capacity == map.capacity());
850850}
851851
852852test "std.hash_map ensureCapacity with tombstones" {
......@@ -869,22 +869,22 @@ test "std.hash_map clearRetainingCapacity" {
869869 map.clearRetainingCapacity();
870870
871871 try map.put(1, 1);
872 expectEqual(map.get(1).?, 1);
873 expectEqual(map.count(), 1);
872 try expectEqual(map.get(1).?, 1);
873 try expectEqual(map.count(), 1);
874874
875875 map.clearRetainingCapacity();
876876 map.putAssumeCapacity(1, 1);
877 expectEqual(map.get(1).?, 1);
878 expectEqual(map.count(), 1);
877 try expectEqual(map.get(1).?, 1);
878 try expectEqual(map.count(), 1);
879879
880880 const cap = map.capacity();
881 expect(cap > 0);
881 try expect(cap > 0);
882882
883883 map.clearRetainingCapacity();
884884 map.clearRetainingCapacity();
885 expectEqual(map.count(), 0);
886 expectEqual(map.capacity(), cap);
887 expect(!map.contains(1));
885 try expectEqual(map.count(), 0);
886 try expectEqual(map.capacity(), cap);
887 try expect(!map.contains(1));
888888}
889889
890890test "std.hash_map grow" {
......@@ -897,19 +897,19 @@ test "std.hash_map grow" {
897897 while (i < growTo) : (i += 1) {
898898 try map.put(i, i);
899899 }
900 expectEqual(map.count(), growTo);
900 try expectEqual(map.count(), growTo);
901901
902902 i = 0;
903903 var it = map.iterator();
904904 while (it.next()) |kv| {
905 expectEqual(kv.key, kv.value);
905 try expectEqual(kv.key, kv.value);
906906 i += 1;
907907 }
908 expectEqual(i, growTo);
908 try expectEqual(i, growTo);
909909
910910 i = 0;
911911 while (i < growTo) : (i += 1) {
912 expectEqual(map.get(i).?, i);
912 try expectEqual(map.get(i).?, i);
913913 }
914914}
915915
......@@ -920,7 +920,7 @@ test "std.hash_map clone" {
920920 var a = try map.clone();
921921 defer a.deinit();
922922
923 expectEqual(a.count(), 0);
923 try expectEqual(a.count(), 0);
924924
925925 try a.put(1, 1);
926926 try a.put(2, 2);
......@@ -929,10 +929,10 @@ test "std.hash_map clone" {
929929 var b = try a.clone();
930930 defer b.deinit();
931931
932 expectEqual(b.count(), 3);
933 expectEqual(b.get(1), 1);
934 expectEqual(b.get(2), 2);
935 expectEqual(b.get(3), 3);
932 try expectEqual(b.count(), 3);
933 try expectEqual(b.get(1), 1);
934 try expectEqual(b.get(2), 2);
935 try expectEqual(b.get(3), 3);
936936}
937937
938938test "std.hash_map ensureCapacity with existing elements" {
......@@ -940,12 +940,12 @@ test "std.hash_map ensureCapacity with existing elements" {
940940 defer map.deinit();
941941
942942 try map.put(0, 0);
943 expectEqual(map.count(), 1);
944 expectEqual(map.capacity(), @TypeOf(map).Unmanaged.minimal_capacity);
943 try expectEqual(map.count(), 1);
944 try expectEqual(map.capacity(), @TypeOf(map).Unmanaged.minimal_capacity);
945945
946946 try map.ensureCapacity(65);
947 expectEqual(map.count(), 1);
948 expectEqual(map.capacity(), 128);
947 try expectEqual(map.count(), 1);
948 try expectEqual(map.capacity(), 128);
949949}
950950
951951test "std.hash_map ensureCapacity satisfies max load factor" {
......@@ -953,7 +953,7 @@ test "std.hash_map ensureCapacity satisfies max load factor" {
953953 defer map.deinit();
954954
955955 try map.ensureCapacity(127);
956 expectEqual(map.capacity(), 256);
956 try expectEqual(map.capacity(), 256);
957957}
958958
959959test "std.hash_map remove" {
......@@ -971,19 +971,19 @@ test "std.hash_map remove" {
971971 _ = map.remove(i);
972972 }
973973 }
974 expectEqual(map.count(), 10);
974 try expectEqual(map.count(), 10);
975975 var it = map.iterator();
976976 while (it.next()) |kv| {
977 expectEqual(kv.key, kv.value);
978 expect(kv.key % 3 != 0);
977 try expectEqual(kv.key, kv.value);
978 try expect(kv.key % 3 != 0);
979979 }
980980
981981 i = 0;
982982 while (i < 16) : (i += 1) {
983983 if (i % 3 == 0) {
984 expect(!map.contains(i));
984 try expect(!map.contains(i));
985985 } else {
986 expectEqual(map.get(i).?, i);
986 try expectEqual(map.get(i).?, i);
987987 }
988988 }
989989}
......@@ -1000,14 +1000,14 @@ test "std.hash_map reverse removes" {
10001000 i = 16;
10011001 while (i > 0) : (i -= 1) {
10021002 _ = map.remove(i - 1);
1003 expect(!map.contains(i - 1));
1003 try expect(!map.contains(i - 1));
10041004 var j: u32 = 0;
10051005 while (j < i - 1) : (j += 1) {
1006 expectEqual(map.get(j).?, j);
1006 try expectEqual(map.get(j).?, j);
10071007 }
10081008 }
10091009
1010 expectEqual(map.count(), 0);
1010 try expectEqual(map.count(), 0);
10111011}
10121012
10131013test "std.hash_map multiple removes on same metadata" {
......@@ -1023,17 +1023,17 @@ test "std.hash_map multiple removes on same metadata" {
10231023 _ = map.remove(15);
10241024 _ = map.remove(14);
10251025 _ = map.remove(13);
1026 expect(!map.contains(7));
1027 expect(!map.contains(15));
1028 expect(!map.contains(14));
1029 expect(!map.contains(13));
1026 try expect(!map.contains(7));
1027 try expect(!map.contains(15));
1028 try expect(!map.contains(14));
1029 try expect(!map.contains(13));
10301030
10311031 i = 0;
10321032 while (i < 13) : (i += 1) {
10331033 if (i == 7) {
1034 expect(!map.contains(i));
1034 try expect(!map.contains(i));
10351035 } else {
1036 expectEqual(map.get(i).?, i);
1036 try expectEqual(map.get(i).?, i);
10371037 }
10381038 }
10391039
......@@ -1043,7 +1043,7 @@ test "std.hash_map multiple removes on same metadata" {
10431043 try map.put(7, 7);
10441044 i = 0;
10451045 while (i < 16) : (i += 1) {
1046 expectEqual(map.get(i).?, i);
1046 try expectEqual(map.get(i).?, i);
10471047 }
10481048}
10491049
......@@ -1069,12 +1069,12 @@ test "std.hash_map put and remove loop in random order" {
10691069 for (keys.items) |key| {
10701070 try map.put(key, key);
10711071 }
1072 expectEqual(map.count(), size);
1072 try expectEqual(map.count(), size);
10731073
10741074 for (keys.items) |key| {
10751075 _ = map.remove(key);
10761076 }
1077 expectEqual(map.count(), 0);
1077 try expectEqual(map.count(), 0);
10781078 }
10791079}
10801080
......@@ -1118,7 +1118,7 @@ test "std.hash_map put" {
11181118
11191119 i = 0;
11201120 while (i < 16) : (i += 1) {
1121 expectEqual(map.get(i).?, i);
1121 try expectEqual(map.get(i).?, i);
11221122 }
11231123
11241124 i = 0;
......@@ -1128,7 +1128,7 @@ test "std.hash_map put" {
11281128
11291129 i = 0;
11301130 while (i < 16) : (i += 1) {
1131 expectEqual(map.get(i).?, i * 16 + 1);
1131 try expectEqual(map.get(i).?, i * 16 + 1);
11321132 }
11331133}
11341134
......@@ -1147,7 +1147,7 @@ test "std.hash_map putAssumeCapacity" {
11471147 while (i < 20) : (i += 1) {
11481148 sum += map.get(i).?;
11491149 }
1150 expectEqual(sum, 190);
1150 try expectEqual(sum, 190);
11511151
11521152 i = 0;
11531153 while (i < 20) : (i += 1) {
......@@ -1159,7 +1159,7 @@ test "std.hash_map putAssumeCapacity" {
11591159 while (i < 20) : (i += 1) {
11601160 sum += map.get(i).?;
11611161 }
1162 expectEqual(sum, 20);
1162 try expectEqual(sum, 20);
11631163}
11641164
11651165test "std.hash_map getOrPut" {
......@@ -1182,49 +1182,49 @@ test "std.hash_map getOrPut" {
11821182 sum += map.get(i).?;
11831183 }
11841184
1185 expectEqual(sum, 30);
1185 try expectEqual(sum, 30);
11861186}
11871187
11881188test "std.hash_map basic hash map usage" {
11891189 var map = AutoHashMap(i32, i32).init(std.testing.allocator);
11901190 defer map.deinit();
11911191
1192 testing.expect((try map.fetchPut(1, 11)) == null);
1193 testing.expect((try map.fetchPut(2, 22)) == null);
1194 testing.expect((try map.fetchPut(3, 33)) == null);
1195 testing.expect((try map.fetchPut(4, 44)) == null);
1192 try testing.expect((try map.fetchPut(1, 11)) == null);
1193 try testing.expect((try map.fetchPut(2, 22)) == null);
1194 try testing.expect((try map.fetchPut(3, 33)) == null);
1195 try testing.expect((try map.fetchPut(4, 44)) == null);
11961196
11971197 try map.putNoClobber(5, 55);
1198 testing.expect((try map.fetchPut(5, 66)).?.value == 55);
1199 testing.expect((try map.fetchPut(5, 55)).?.value == 66);
1198 try testing.expect((try map.fetchPut(5, 66)).?.value == 55);
1199 try testing.expect((try map.fetchPut(5, 55)).?.value == 66);
12001200
12011201 const gop1 = try map.getOrPut(5);
1202 testing.expect(gop1.found_existing == true);
1203 testing.expect(gop1.entry.value == 55);
1202 try testing.expect(gop1.found_existing == true);
1203 try testing.expect(gop1.entry.value == 55);
12041204 gop1.entry.value = 77;
1205 testing.expect(map.getEntry(5).?.value == 77);
1205 try testing.expect(map.getEntry(5).?.value == 77);
12061206
12071207 const gop2 = try map.getOrPut(99);
1208 testing.expect(gop2.found_existing == false);
1208 try testing.expect(gop2.found_existing == false);
12091209 gop2.entry.value = 42;
1210 testing.expect(map.getEntry(99).?.value == 42);
1210 try testing.expect(map.getEntry(99).?.value == 42);
12111211
12121212 const gop3 = try map.getOrPutValue(5, 5);
1213 testing.expect(gop3.value == 77);
1213 try testing.expect(gop3.value == 77);
12141214
12151215 const gop4 = try map.getOrPutValue(100, 41);
1216 testing.expect(gop4.value == 41);
1216 try testing.expect(gop4.value == 41);
12171217
1218 testing.expect(map.contains(2));
1219 testing.expect(map.getEntry(2).?.value == 22);
1220 testing.expect(map.get(2).? == 22);
1218 try testing.expect(map.contains(2));
1219 try testing.expect(map.getEntry(2).?.value == 22);
1220 try testing.expect(map.get(2).? == 22);
12211221
12221222 const rmv1 = map.remove(2);
1223 testing.expect(rmv1.?.key == 2);
1224 testing.expect(rmv1.?.value == 22);
1225 testing.expect(map.remove(2) == null);
1226 testing.expect(map.getEntry(2) == null);
1227 testing.expect(map.get(2) == null);
1223 try testing.expect(rmv1.?.key == 2);
1224 try testing.expect(rmv1.?.value == 22);
1225 try testing.expect(map.remove(2) == null);
1226 try testing.expect(map.getEntry(2) == null);
1227 try testing.expect(map.get(2) == null);
12281228
12291229 map.removeAssertDiscard(3);
12301230}
......@@ -1243,6 +1243,6 @@ test "std.hash_map clone" {
12431243
12441244 i = 0;
12451245 while (i < 10) : (i += 1) {
1246 testing.expect(copy.get(i).? == i * 10);
1246 try testing.expect(copy.get(i).? == i * 10);
12471247 }
12481248}
lib/std/heap.zig+43-43
......@@ -858,16 +858,16 @@ test "WasmPageAllocator internals" {
858858 if (comptime std.Target.current.isWasm()) {
859859 const conventional_memsize = WasmPageAllocator.conventional.totalPages() * mem.page_size;
860860 const initial = try page_allocator.alloc(u8, mem.page_size);
861 testing.expect(@ptrToInt(initial.ptr) < conventional_memsize); // If this isn't conventional, the rest of these tests don't make sense. Also we have a serious memory leak in the test suite.
861 try testing.expect(@ptrToInt(initial.ptr) < conventional_memsize); // If this isn't conventional, the rest of these tests don't make sense. Also we have a serious memory leak in the test suite.
862862
863863 var inplace = try page_allocator.realloc(initial, 1);
864 testing.expectEqual(initial.ptr, inplace.ptr);
864 try testing.expectEqual(initial.ptr, inplace.ptr);
865865 inplace = try page_allocator.realloc(inplace, 4);
866 testing.expectEqual(initial.ptr, inplace.ptr);
866 try testing.expectEqual(initial.ptr, inplace.ptr);
867867 page_allocator.free(inplace);
868868
869869 const reuse = try page_allocator.alloc(u8, 1);
870 testing.expectEqual(initial.ptr, reuse.ptr);
870 try testing.expectEqual(initial.ptr, reuse.ptr);
871871 page_allocator.free(reuse);
872872
873873 // This segment may span conventional and extended which has really complex rules so we're just ignoring it for now.
......@@ -875,18 +875,18 @@ test "WasmPageAllocator internals" {
875875 page_allocator.free(padding);
876876
877877 const extended = try page_allocator.alloc(u8, conventional_memsize);
878 testing.expect(@ptrToInt(extended.ptr) >= conventional_memsize);
878 try testing.expect(@ptrToInt(extended.ptr) >= conventional_memsize);
879879
880880 const use_small = try page_allocator.alloc(u8, 1);
881 testing.expectEqual(initial.ptr, use_small.ptr);
881 try testing.expectEqual(initial.ptr, use_small.ptr);
882882 page_allocator.free(use_small);
883883
884884 inplace = try page_allocator.realloc(extended, 1);
885 testing.expectEqual(extended.ptr, inplace.ptr);
885 try testing.expectEqual(extended.ptr, inplace.ptr);
886886 page_allocator.free(inplace);
887887
888888 const reuse_extended = try page_allocator.alloc(u8, conventional_memsize);
889 testing.expectEqual(extended.ptr, reuse_extended.ptr);
889 try testing.expectEqual(extended.ptr, reuse_extended.ptr);
890890 page_allocator.free(reuse_extended);
891891 }
892892}
......@@ -959,15 +959,15 @@ test "FixedBufferAllocator.reset" {
959959
960960 var x = try fba.allocator.create(u64);
961961 x.* = X;
962 testing.expectError(error.OutOfMemory, fba.allocator.create(u64));
962 try testing.expectError(error.OutOfMemory, fba.allocator.create(u64));
963963
964964 fba.reset();
965965 var y = try fba.allocator.create(u64);
966966 y.* = Y;
967967
968968 // we expect Y to have overwritten X.
969 testing.expect(x.* == y.*);
970 testing.expect(y.* == Y);
969 try testing.expect(x.* == y.*);
970 try testing.expect(y.* == Y);
971971}
972972
973973test "StackFallbackAllocator" {
......@@ -987,11 +987,11 @@ test "FixedBufferAllocator Reuse memory on realloc" {
987987 var fixed_buffer_allocator = FixedBufferAllocator.init(small_fixed_buffer[0..]);
988988
989989 var slice0 = try fixed_buffer_allocator.allocator.alloc(u8, 5);
990 testing.expect(slice0.len == 5);
990 try testing.expect(slice0.len == 5);
991991 var slice1 = try fixed_buffer_allocator.allocator.realloc(slice0, 10);
992 testing.expect(slice1.ptr == slice0.ptr);
993 testing.expect(slice1.len == 10);
994 testing.expectError(error.OutOfMemory, fixed_buffer_allocator.allocator.realloc(slice1, 11));
992 try testing.expect(slice1.ptr == slice0.ptr);
993 try testing.expect(slice1.len == 10);
994 try testing.expectError(error.OutOfMemory, fixed_buffer_allocator.allocator.realloc(slice1, 11));
995995 }
996996 // check that we don't re-use the memory if it's not the most recent block
997997 {
......@@ -1002,10 +1002,10 @@ test "FixedBufferAllocator Reuse memory on realloc" {
10021002 slice0[1] = 2;
10031003 var slice1 = try fixed_buffer_allocator.allocator.alloc(u8, 2);
10041004 var slice2 = try fixed_buffer_allocator.allocator.realloc(slice0, 4);
1005 testing.expect(slice0.ptr != slice2.ptr);
1006 testing.expect(slice1.ptr != slice2.ptr);
1007 testing.expect(slice2[0] == 1);
1008 testing.expect(slice2[1] == 2);
1005 try testing.expect(slice0.ptr != slice2.ptr);
1006 try testing.expect(slice1.ptr != slice2.ptr);
1007 try testing.expect(slice2[0] == 1);
1008 try testing.expect(slice2[1] == 2);
10091009 }
10101010}
10111011
......@@ -1024,28 +1024,28 @@ pub fn testAllocator(base_allocator: *mem.Allocator) !void {
10241024 const allocator = &validationAllocator.allocator;
10251025
10261026 var slice = try allocator.alloc(*i32, 100);
1027 testing.expect(slice.len == 100);
1027 try testing.expect(slice.len == 100);
10281028 for (slice) |*item, i| {
10291029 item.* = try allocator.create(i32);
10301030 item.*.* = @intCast(i32, i);
10311031 }
10321032
10331033 slice = try allocator.realloc(slice, 20000);
1034 testing.expect(slice.len == 20000);
1034 try testing.expect(slice.len == 20000);
10351035
10361036 for (slice[0..100]) |item, i| {
1037 testing.expect(item.* == @intCast(i32, i));
1037 try testing.expect(item.* == @intCast(i32, i));
10381038 allocator.destroy(item);
10391039 }
10401040
10411041 slice = allocator.shrink(slice, 50);
1042 testing.expect(slice.len == 50);
1042 try testing.expect(slice.len == 50);
10431043 slice = allocator.shrink(slice, 25);
1044 testing.expect(slice.len == 25);
1044 try testing.expect(slice.len == 25);
10451045 slice = allocator.shrink(slice, 0);
1046 testing.expect(slice.len == 0);
1046 try testing.expect(slice.len == 0);
10471047 slice = try allocator.realloc(slice, 10);
1048 testing.expect(slice.len == 10);
1048 try testing.expect(slice.len == 10);
10491049
10501050 allocator.free(slice);
10511051
......@@ -1058,7 +1058,7 @@ pub fn testAllocator(base_allocator: *mem.Allocator) !void {
10581058 allocator.destroy(zero_bit_ptr);
10591059
10601060 const oversize = try allocator.allocAdvanced(u32, null, 5, .at_least);
1061 testing.expect(oversize.len >= 5);
1061 try testing.expect(oversize.len >= 5);
10621062 for (oversize) |*item| {
10631063 item.* = 0xDEADBEEF;
10641064 }
......@@ -1073,29 +1073,29 @@ pub fn testAllocatorAligned(base_allocator: *mem.Allocator) !void {
10731073 inline for ([_]u29{ 1, 2, 4, 8, 16, 32, 64 }) |alignment| {
10741074 // initial
10751075 var slice = try allocator.alignedAlloc(u8, alignment, 10);
1076 testing.expect(slice.len == 10);
1076 try testing.expect(slice.len == 10);
10771077 // grow
10781078 slice = try allocator.realloc(slice, 100);
1079 testing.expect(slice.len == 100);
1079 try testing.expect(slice.len == 100);
10801080 // shrink
10811081 slice = allocator.shrink(slice, 10);
1082 testing.expect(slice.len == 10);
1082 try testing.expect(slice.len == 10);
10831083 // go to zero
10841084 slice = allocator.shrink(slice, 0);
1085 testing.expect(slice.len == 0);
1085 try testing.expect(slice.len == 0);
10861086 // realloc from zero
10871087 slice = try allocator.realloc(slice, 100);
1088 testing.expect(slice.len == 100);
1088 try testing.expect(slice.len == 100);
10891089 // shrink with shrink
10901090 slice = allocator.shrink(slice, 10);
1091 testing.expect(slice.len == 10);
1091 try testing.expect(slice.len == 10);
10921092 // shrink to zero
10931093 slice = allocator.shrink(slice, 0);
1094 testing.expect(slice.len == 0);
1094 try testing.expect(slice.len == 0);
10951095 }
10961096}
10971097
1098pub fn testAllocatorLargeAlignment(base_allocator: *mem.Allocator) mem.Allocator.Error!void {
1098pub fn testAllocatorLargeAlignment(base_allocator: *mem.Allocator) !void {
10991099 var validationAllocator = mem.validationWrap(base_allocator);
11001100 const allocator = &validationAllocator.allocator;
11011101
......@@ -1110,24 +1110,24 @@ pub fn testAllocatorLargeAlignment(base_allocator: *mem.Allocator) mem.Allocator
11101110 _ = @shlWithOverflow(usize, ~@as(usize, 0), @as(USizeShift, @ctz(u29, large_align)), &align_mask);
11111111
11121112 var slice = try allocator.alignedAlloc(u8, large_align, 500);
1113 testing.expect(@ptrToInt(slice.ptr) & align_mask == @ptrToInt(slice.ptr));
1113 try testing.expect(@ptrToInt(slice.ptr) & align_mask == @ptrToInt(slice.ptr));
11141114
11151115 slice = allocator.shrink(slice, 100);
1116 testing.expect(@ptrToInt(slice.ptr) & align_mask == @ptrToInt(slice.ptr));
1116 try testing.expect(@ptrToInt(slice.ptr) & align_mask == @ptrToInt(slice.ptr));
11171117
11181118 slice = try allocator.realloc(slice, 5000);
1119 testing.expect(@ptrToInt(slice.ptr) & align_mask == @ptrToInt(slice.ptr));
1119 try testing.expect(@ptrToInt(slice.ptr) & align_mask == @ptrToInt(slice.ptr));
11201120
11211121 slice = allocator.shrink(slice, 10);
1122 testing.expect(@ptrToInt(slice.ptr) & align_mask == @ptrToInt(slice.ptr));
1122 try testing.expect(@ptrToInt(slice.ptr) & align_mask == @ptrToInt(slice.ptr));
11231123
11241124 slice = try allocator.realloc(slice, 20000);
1125 testing.expect(@ptrToInt(slice.ptr) & align_mask == @ptrToInt(slice.ptr));
1125 try testing.expect(@ptrToInt(slice.ptr) & align_mask == @ptrToInt(slice.ptr));
11261126
11271127 allocator.free(slice);
11281128}
11291129
1130pub fn testAllocatorAlignedShrink(base_allocator: *mem.Allocator) mem.Allocator.Error!void {
1130pub fn testAllocatorAlignedShrink(base_allocator: *mem.Allocator) !void {
11311131 var validationAllocator = mem.validationWrap(base_allocator);
11321132 const allocator = &validationAllocator.allocator;
11331133
......@@ -1155,8 +1155,8 @@ pub fn testAllocatorAlignedShrink(base_allocator: *mem.Allocator) mem.Allocator.
11551155
11561156 // realloc to a smaller size but with a larger alignment
11571157 slice = try allocator.reallocAdvanced(slice, mem.page_size * 32, alloc_size / 2, .exact);
1158 testing.expect(slice[0] == 0x12);
1159 testing.expect(slice[60] == 0x34);
1158 try testing.expect(slice[0] == 0x12);
1159 try testing.expect(slice[60] == 0x34);
11601160}
11611161
11621162test "heap" {
lib/std/heap/general_purpose_allocator.zig+50-50
......@@ -697,7 +697,7 @@ const test_config = Config{};
697697
698698test "small allocations - free in same order" {
699699 var gpa = GeneralPurposeAllocator(test_config){};
700 defer std.testing.expect(!gpa.deinit());
700 defer std.testing.expect(!gpa.deinit()) catch @panic("leak");
701701 const allocator = &gpa.allocator;
702702
703703 var list = std.ArrayList(*u64).init(std.testing.allocator);
......@@ -716,7 +716,7 @@ test "small allocations - free in same order" {
716716
717717test "small allocations - free in reverse order" {
718718 var gpa = GeneralPurposeAllocator(test_config){};
719 defer std.testing.expect(!gpa.deinit());
719 defer std.testing.expect(!gpa.deinit()) catch @panic("leak");
720720 const allocator = &gpa.allocator;
721721
722722 var list = std.ArrayList(*u64).init(std.testing.allocator);
......@@ -735,7 +735,7 @@ test "small allocations - free in reverse order" {
735735
736736test "large allocations" {
737737 var gpa = GeneralPurposeAllocator(test_config){};
738 defer std.testing.expect(!gpa.deinit());
738 defer std.testing.expect(!gpa.deinit()) catch @panic("leak");
739739 const allocator = &gpa.allocator;
740740
741741 const ptr1 = try allocator.alloc(u64, 42768);
......@@ -748,7 +748,7 @@ test "large allocations" {
748748
749749test "realloc" {
750750 var gpa = GeneralPurposeAllocator(test_config){};
751 defer std.testing.expect(!gpa.deinit());
751 defer std.testing.expect(!gpa.deinit()) catch @panic("leak");
752752 const allocator = &gpa.allocator;
753753
754754 var slice = try allocator.alignedAlloc(u8, @alignOf(u32), 1);
......@@ -758,19 +758,19 @@ test "realloc" {
758758 // This reallocation should keep its pointer address.
759759 const old_slice = slice;
760760 slice = try allocator.realloc(slice, 2);
761 std.testing.expect(old_slice.ptr == slice.ptr);
762 std.testing.expect(slice[0] == 0x12);
761 try std.testing.expect(old_slice.ptr == slice.ptr);
762 try std.testing.expect(slice[0] == 0x12);
763763 slice[1] = 0x34;
764764
765765 // This requires upgrading to a larger size class
766766 slice = try allocator.realloc(slice, 17);
767 std.testing.expect(slice[0] == 0x12);
768 std.testing.expect(slice[1] == 0x34);
767 try std.testing.expect(slice[0] == 0x12);
768 try std.testing.expect(slice[1] == 0x34);
769769}
770770
771771test "shrink" {
772772 var gpa = GeneralPurposeAllocator(test_config){};
773 defer std.testing.expect(!gpa.deinit());
773 defer std.testing.expect(!gpa.deinit()) catch @panic("leak");
774774 const allocator = &gpa.allocator;
775775
776776 var slice = try allocator.alloc(u8, 20);
......@@ -781,19 +781,19 @@ test "shrink" {
781781 slice = allocator.shrink(slice, 17);
782782
783783 for (slice) |b| {
784 std.testing.expect(b == 0x11);
784 try std.testing.expect(b == 0x11);
785785 }
786786
787787 slice = allocator.shrink(slice, 16);
788788
789789 for (slice) |b| {
790 std.testing.expect(b == 0x11);
790 try std.testing.expect(b == 0x11);
791791 }
792792}
793793
794794test "large object - grow" {
795795 var gpa = GeneralPurposeAllocator(test_config){};
796 defer std.testing.expect(!gpa.deinit());
796 defer std.testing.expect(!gpa.deinit()) catch @panic("leak");
797797 const allocator = &gpa.allocator;
798798
799799 var slice1 = try allocator.alloc(u8, page_size * 2 - 20);
......@@ -801,17 +801,17 @@ test "large object - grow" {
801801
802802 const old = slice1;
803803 slice1 = try allocator.realloc(slice1, page_size * 2 - 10);
804 std.testing.expect(slice1.ptr == old.ptr);
804 try std.testing.expect(slice1.ptr == old.ptr);
805805
806806 slice1 = try allocator.realloc(slice1, page_size * 2);
807 std.testing.expect(slice1.ptr == old.ptr);
807 try std.testing.expect(slice1.ptr == old.ptr);
808808
809809 slice1 = try allocator.realloc(slice1, page_size * 2 + 1);
810810}
811811
812812test "realloc small object to large object" {
813813 var gpa = GeneralPurposeAllocator(test_config){};
814 defer std.testing.expect(!gpa.deinit());
814 defer std.testing.expect(!gpa.deinit()) catch @panic("leak");
815815 const allocator = &gpa.allocator;
816816
817817 var slice = try allocator.alloc(u8, 70);
......@@ -822,13 +822,13 @@ test "realloc small object to large object" {
822822 // This requires upgrading to a large object
823823 const large_object_size = page_size * 2 + 50;
824824 slice = try allocator.realloc(slice, large_object_size);
825 std.testing.expect(slice[0] == 0x12);
826 std.testing.expect(slice[60] == 0x34);
825 try std.testing.expect(slice[0] == 0x12);
826 try std.testing.expect(slice[60] == 0x34);
827827}
828828
829829test "shrink large object to large object" {
830830 var gpa = GeneralPurposeAllocator(test_config){};
831 defer std.testing.expect(!gpa.deinit());
831 defer std.testing.expect(!gpa.deinit()) catch @panic("leak");
832832 const allocator = &gpa.allocator;
833833
834834 var slice = try allocator.alloc(u8, page_size * 2 + 50);
......@@ -837,21 +837,21 @@ test "shrink large object to large object" {
837837 slice[60] = 0x34;
838838
839839 slice = try allocator.resize(slice, page_size * 2 + 1);
840 std.testing.expect(slice[0] == 0x12);
841 std.testing.expect(slice[60] == 0x34);
840 try std.testing.expect(slice[0] == 0x12);
841 try std.testing.expect(slice[60] == 0x34);
842842
843843 slice = allocator.shrink(slice, page_size * 2 + 1);
844 std.testing.expect(slice[0] == 0x12);
845 std.testing.expect(slice[60] == 0x34);
844 try std.testing.expect(slice[0] == 0x12);
845 try std.testing.expect(slice[60] == 0x34);
846846
847847 slice = try allocator.realloc(slice, page_size * 2);
848 std.testing.expect(slice[0] == 0x12);
849 std.testing.expect(slice[60] == 0x34);
848 try std.testing.expect(slice[0] == 0x12);
849 try std.testing.expect(slice[60] == 0x34);
850850}
851851
852852test "shrink large object to large object with larger alignment" {
853853 var gpa = GeneralPurposeAllocator(test_config){};
854 defer std.testing.expect(!gpa.deinit());
854 defer std.testing.expect(!gpa.deinit()) catch @panic("leak");
855855 const allocator = &gpa.allocator;
856856
857857 var debug_buffer: [1000]u8 = undefined;
......@@ -880,13 +880,13 @@ test "shrink large object to large object with larger alignment" {
880880 slice[60] = 0x34;
881881
882882 slice = try allocator.reallocAdvanced(slice, big_alignment, alloc_size / 2, .exact);
883 std.testing.expect(slice[0] == 0x12);
884 std.testing.expect(slice[60] == 0x34);
883 try std.testing.expect(slice[0] == 0x12);
884 try std.testing.expect(slice[60] == 0x34);
885885}
886886
887887test "realloc large object to small object" {
888888 var gpa = GeneralPurposeAllocator(test_config){};
889 defer std.testing.expect(!gpa.deinit());
889 defer std.testing.expect(!gpa.deinit()) catch @panic("leak");
890890 const allocator = &gpa.allocator;
891891
892892 var slice = try allocator.alloc(u8, page_size * 2 + 50);
......@@ -895,8 +895,8 @@ test "realloc large object to small object" {
895895 slice[16] = 0x34;
896896
897897 slice = try allocator.realloc(slice, 19);
898 std.testing.expect(slice[0] == 0x12);
899 std.testing.expect(slice[16] == 0x34);
898 try std.testing.expect(slice[0] == 0x12);
899 try std.testing.expect(slice[16] == 0x34);
900900}
901901
902902test "overrideable mutexes" {
......@@ -904,7 +904,7 @@ test "overrideable mutexes" {
904904 .backing_allocator = std.testing.allocator,
905905 .mutex = std.Thread.Mutex{},
906906 };
907 defer std.testing.expect(!gpa.deinit());
907 defer std.testing.expect(!gpa.deinit()) catch @panic("leak");
908908 const allocator = &gpa.allocator;
909909
910910 const ptr = try allocator.create(i32);
......@@ -913,7 +913,7 @@ test "overrideable mutexes" {
913913
914914test "non-page-allocator backing allocator" {
915915 var gpa = GeneralPurposeAllocator(.{}){ .backing_allocator = std.testing.allocator };
916 defer std.testing.expect(!gpa.deinit());
916 defer std.testing.expect(!gpa.deinit()) catch @panic("leak");
917917 const allocator = &gpa.allocator;
918918
919919 const ptr = try allocator.create(i32);
......@@ -922,7 +922,7 @@ test "non-page-allocator backing allocator" {
922922
923923test "realloc large object to larger alignment" {
924924 var gpa = GeneralPurposeAllocator(test_config){};
925 defer std.testing.expect(!gpa.deinit());
925 defer std.testing.expect(!gpa.deinit()) catch @panic("leak");
926926 const allocator = &gpa.allocator;
927927
928928 var debug_buffer: [1000]u8 = undefined;
......@@ -948,22 +948,22 @@ test "realloc large object to larger alignment" {
948948 slice[16] = 0x34;
949949
950950 slice = try allocator.reallocAdvanced(slice, 32, page_size * 2 + 100, .exact);
951 std.testing.expect(slice[0] == 0x12);
952 std.testing.expect(slice[16] == 0x34);
951 try std.testing.expect(slice[0] == 0x12);
952 try std.testing.expect(slice[16] == 0x34);
953953
954954 slice = try allocator.reallocAdvanced(slice, 32, page_size * 2 + 25, .exact);
955 std.testing.expect(slice[0] == 0x12);
956 std.testing.expect(slice[16] == 0x34);
955 try std.testing.expect(slice[0] == 0x12);
956 try std.testing.expect(slice[16] == 0x34);
957957
958958 slice = try allocator.reallocAdvanced(slice, big_alignment, page_size * 2 + 100, .exact);
959 std.testing.expect(slice[0] == 0x12);
960 std.testing.expect(slice[16] == 0x34);
959 try std.testing.expect(slice[0] == 0x12);
960 try std.testing.expect(slice[16] == 0x34);
961961}
962962
963963test "large object shrinks to small but allocation fails during shrink" {
964964 var failing_allocator = std.testing.FailingAllocator.init(std.heap.page_allocator, 3);
965965 var gpa = GeneralPurposeAllocator(.{}){ .backing_allocator = &failing_allocator.allocator };
966 defer std.testing.expect(!gpa.deinit());
966 defer std.testing.expect(!gpa.deinit()) catch @panic("leak");
967967 const allocator = &gpa.allocator;
968968
969969 var slice = try allocator.alloc(u8, page_size * 2 + 50);
......@@ -974,13 +974,13 @@ test "large object shrinks to small but allocation fails during shrink" {
974974 // Next allocation will fail in the backing allocator of the GeneralPurposeAllocator
975975
976976 slice = allocator.shrink(slice, 4);
977 std.testing.expect(slice[0] == 0x12);
978 std.testing.expect(slice[3] == 0x34);
977 try std.testing.expect(slice[0] == 0x12);
978 try std.testing.expect(slice[3] == 0x34);
979979}
980980
981981test "objects of size 1024 and 2048" {
982982 var gpa = GeneralPurposeAllocator(test_config){};
983 defer std.testing.expect(!gpa.deinit());
983 defer std.testing.expect(!gpa.deinit()) catch @panic("leak");
984984 const allocator = &gpa.allocator;
985985
986986 const slice = try allocator.alloc(u8, 1025);
......@@ -992,26 +992,26 @@ test "objects of size 1024 and 2048" {
992992
993993test "setting a memory cap" {
994994 var gpa = GeneralPurposeAllocator(.{ .enable_memory_limit = true }){};
995 defer std.testing.expect(!gpa.deinit());
995 defer std.testing.expect(!gpa.deinit()) catch @panic("leak");
996996 const allocator = &gpa.allocator;
997997
998998 gpa.setRequestedMemoryLimit(1010);
999999
10001000 const small = try allocator.create(i32);
1001 std.testing.expect(gpa.total_requested_bytes == 4);
1001 try std.testing.expect(gpa.total_requested_bytes == 4);
10021002
10031003 const big = try allocator.alloc(u8, 1000);
1004 std.testing.expect(gpa.total_requested_bytes == 1004);
1004 try std.testing.expect(gpa.total_requested_bytes == 1004);
10051005
1006 std.testing.expectError(error.OutOfMemory, allocator.create(u64));
1006 try std.testing.expectError(error.OutOfMemory, allocator.create(u64));
10071007
10081008 allocator.destroy(small);
1009 std.testing.expect(gpa.total_requested_bytes == 1000);
1009 try std.testing.expect(gpa.total_requested_bytes == 1000);
10101010
10111011 allocator.free(big);
1012 std.testing.expect(gpa.total_requested_bytes == 0);
1012 try std.testing.expect(gpa.total_requested_bytes == 0);
10131013
10141014 const exact = try allocator.alloc(u8, 1010);
1015 std.testing.expect(gpa.total_requested_bytes == 1010);
1015 try std.testing.expect(gpa.total_requested_bytes == 1010);
10161016 allocator.free(exact);
10171017}
lib/std/heap/logging_allocator.zig+3-3
......@@ -93,11 +93,11 @@ test "LoggingAllocator" {
9393
9494 var a = try allocator.alloc(u8, 10);
9595 a = allocator.shrink(a, 5);
96 std.testing.expect(a.len == 5);
97 std.testing.expectError(error.OutOfMemory, allocator.resize(a, 20));
96 try std.testing.expect(a.len == 5);
97 try std.testing.expectError(error.OutOfMemory, allocator.resize(a, 20));
9898 allocator.free(a);
9999
100 std.testing.expectEqualSlices(u8,
100 try std.testing.expectEqualSlices(u8,
101101 \\alloc : 10 success!
102102 \\shrink: 10 to 5
103103 \\expand: 5 to 20 failure!
lib/std/io/bit_reader.zig+38-38
......@@ -185,64 +185,64 @@ test "api coverage" {
185185 const expect = testing.expect;
186186 const expectError = testing.expectError;
187187
188 expect(1 == try bit_stream_be.readBits(u2, 1, &out_bits));
189 expect(out_bits == 1);
190 expect(2 == try bit_stream_be.readBits(u5, 2, &out_bits));
191 expect(out_bits == 2);
192 expect(3 == try bit_stream_be.readBits(u128, 3, &out_bits));
193 expect(out_bits == 3);
194 expect(4 == try bit_stream_be.readBits(u8, 4, &out_bits));
195 expect(out_bits == 4);
196 expect(5 == try bit_stream_be.readBits(u9, 5, &out_bits));
197 expect(out_bits == 5);
198 expect(1 == try bit_stream_be.readBits(u1, 1, &out_bits));
199 expect(out_bits == 1);
188 try expect(1 == try bit_stream_be.readBits(u2, 1, &out_bits));
189 try expect(out_bits == 1);
190 try expect(2 == try bit_stream_be.readBits(u5, 2, &out_bits));
191 try expect(out_bits == 2);
192 try expect(3 == try bit_stream_be.readBits(u128, 3, &out_bits));
193 try expect(out_bits == 3);
194 try expect(4 == try bit_stream_be.readBits(u8, 4, &out_bits));
195 try expect(out_bits == 4);
196 try expect(5 == try bit_stream_be.readBits(u9, 5, &out_bits));
197 try expect(out_bits == 5);
198 try expect(1 == try bit_stream_be.readBits(u1, 1, &out_bits));
199 try expect(out_bits == 1);
200200
201201 mem_in_be.pos = 0;
202202 bit_stream_be.bit_count = 0;
203 expect(0b110011010000101 == try bit_stream_be.readBits(u15, 15, &out_bits));
204 expect(out_bits == 15);
203 try expect(0b110011010000101 == try bit_stream_be.readBits(u15, 15, &out_bits));
204 try expect(out_bits == 15);
205205
206206 mem_in_be.pos = 0;
207207 bit_stream_be.bit_count = 0;
208 expect(0b1100110100001011 == try bit_stream_be.readBits(u16, 16, &out_bits));
209 expect(out_bits == 16);
208 try expect(0b1100110100001011 == try bit_stream_be.readBits(u16, 16, &out_bits));
209 try expect(out_bits == 16);
210210
211211 _ = try bit_stream_be.readBits(u0, 0, &out_bits);
212212
213 expect(0 == try bit_stream_be.readBits(u1, 1, &out_bits));
214 expect(out_bits == 0);
215 expectError(error.EndOfStream, bit_stream_be.readBitsNoEof(u1, 1));
213 try expect(0 == try bit_stream_be.readBits(u1, 1, &out_bits));
214 try expect(out_bits == 0);
215 try expectError(error.EndOfStream, bit_stream_be.readBitsNoEof(u1, 1));
216216
217217 var mem_in_le = io.fixedBufferStream(&mem_le);
218218 var bit_stream_le = bitReader(.Little, mem_in_le.reader());
219219
220 expect(1 == try bit_stream_le.readBits(u2, 1, &out_bits));
221 expect(out_bits == 1);
222 expect(2 == try bit_stream_le.readBits(u5, 2, &out_bits));
223 expect(out_bits == 2);
224 expect(3 == try bit_stream_le.readBits(u128, 3, &out_bits));
225 expect(out_bits == 3);
226 expect(4 == try bit_stream_le.readBits(u8, 4, &out_bits));
227 expect(out_bits == 4);
228 expect(5 == try bit_stream_le.readBits(u9, 5, &out_bits));
229 expect(out_bits == 5);
230 expect(1 == try bit_stream_le.readBits(u1, 1, &out_bits));
231 expect(out_bits == 1);
220 try expect(1 == try bit_stream_le.readBits(u2, 1, &out_bits));
221 try expect(out_bits == 1);
222 try expect(2 == try bit_stream_le.readBits(u5, 2, &out_bits));
223 try expect(out_bits == 2);
224 try expect(3 == try bit_stream_le.readBits(u128, 3, &out_bits));
225 try expect(out_bits == 3);
226 try expect(4 == try bit_stream_le.readBits(u8, 4, &out_bits));
227 try expect(out_bits == 4);
228 try expect(5 == try bit_stream_le.readBits(u9, 5, &out_bits));
229 try expect(out_bits == 5);
230 try expect(1 == try bit_stream_le.readBits(u1, 1, &out_bits));
231 try expect(out_bits == 1);
232232
233233 mem_in_le.pos = 0;
234234 bit_stream_le.bit_count = 0;
235 expect(0b001010100011101 == try bit_stream_le.readBits(u15, 15, &out_bits));
236 expect(out_bits == 15);
235 try expect(0b001010100011101 == try bit_stream_le.readBits(u15, 15, &out_bits));
236 try expect(out_bits == 15);
237237
238238 mem_in_le.pos = 0;
239239 bit_stream_le.bit_count = 0;
240 expect(0b1001010100011101 == try bit_stream_le.readBits(u16, 16, &out_bits));
241 expect(out_bits == 16);
240 try expect(0b1001010100011101 == try bit_stream_le.readBits(u16, 16, &out_bits));
241 try expect(out_bits == 16);
242242
243243 _ = try bit_stream_le.readBits(u0, 0, &out_bits);
244244
245 expect(0 == try bit_stream_le.readBits(u1, 1, &out_bits));
246 expect(out_bits == 0);
247 expectError(error.EndOfStream, bit_stream_le.readBitsNoEof(u1, 1));
245 try expect(0 == try bit_stream_le.readBits(u1, 1, &out_bits));
246 try expect(out_bits == 0);
247 try expectError(error.EndOfStream, bit_stream_le.readBitsNoEof(u1, 1));
248248}
lib/std/io/bit_writer.zig+6-6
......@@ -163,17 +163,17 @@ test "api coverage" {
163163 try bit_stream_be.writeBits(@as(u9, 5), 5);
164164 try bit_stream_be.writeBits(@as(u1, 1), 1);
165165
166 testing.expect(mem_be[0] == 0b11001101 and mem_be[1] == 0b00001011);
166 try testing.expect(mem_be[0] == 0b11001101 and mem_be[1] == 0b00001011);
167167
168168 mem_out_be.pos = 0;
169169
170170 try bit_stream_be.writeBits(@as(u15, 0b110011010000101), 15);
171171 try bit_stream_be.flushBits();
172 testing.expect(mem_be[0] == 0b11001101 and mem_be[1] == 0b00001010);
172 try testing.expect(mem_be[0] == 0b11001101 and mem_be[1] == 0b00001010);
173173
174174 mem_out_be.pos = 0;
175175 try bit_stream_be.writeBits(@as(u32, 0b110011010000101), 16);
176 testing.expect(mem_be[0] == 0b01100110 and mem_be[1] == 0b10000101);
176 try testing.expect(mem_be[0] == 0b01100110 and mem_be[1] == 0b10000101);
177177
178178 try bit_stream_be.writeBits(@as(u0, 0), 0);
179179
......@@ -187,16 +187,16 @@ test "api coverage" {
187187 try bit_stream_le.writeBits(@as(u9, 5), 5);
188188 try bit_stream_le.writeBits(@as(u1, 1), 1);
189189
190 testing.expect(mem_le[0] == 0b00011101 and mem_le[1] == 0b10010101);
190 try testing.expect(mem_le[0] == 0b00011101 and mem_le[1] == 0b10010101);
191191
192192 mem_out_le.pos = 0;
193193 try bit_stream_le.writeBits(@as(u15, 0b110011010000101), 15);
194194 try bit_stream_le.flushBits();
195 testing.expect(mem_le[0] == 0b10000101 and mem_le[1] == 0b01100110);
195 try testing.expect(mem_le[0] == 0b10000101 and mem_le[1] == 0b01100110);
196196
197197 mem_out_le.pos = 0;
198198 try bit_stream_le.writeBits(@as(u32, 0b1100110100001011), 16);
199 testing.expect(mem_le[0] == 0b00001011 and mem_le[1] == 0b11001101);
199 try testing.expect(mem_le[0] == 0b00001011 and mem_le[1] == 0b11001101);
200200
201201 try bit_stream_le.writeBits(@as(u0, 0), 0);
202202}
lib/std/io/buffered_reader.zig+1-1
......@@ -87,5 +87,5 @@ test "io.BufferedReader" {
8787
8888 const res = try stream.readAllAlloc(testing.allocator, str.len + 1);
8989 defer testing.allocator.free(res);
90 testing.expectEqualSlices(u8, str, res);
90 try testing.expectEqualSlices(u8, str, res);
9191}
lib/std/io/counting_reader.zig+2-2
......@@ -41,8 +41,8 @@ test "io.CountingReader" {
4141
4242 //read and discard all bytes
4343 while (stream.readByte()) |_| {} else |err| {
44 testing.expect(err == error.EndOfStream);
44 try testing.expect(err == error.EndOfStream);
4545 }
4646
47 testing.expect(counting_stream.bytes_read == bytes.len);
47 try testing.expect(counting_stream.bytes_read == bytes.len);
4848}
lib/std/io/counting_writer.zig+1-1
......@@ -40,5 +40,5 @@ test "io.CountingWriter" {
4040
4141 const bytes = "yay" ** 100;
4242 stream.writeAll(bytes) catch unreachable;
43 testing.expect(counting_stream.bytes_written == bytes.len);
43 try testing.expect(counting_stream.bytes_written == bytes.len);
4444}
lib/std/io/fixed_buffer_stream.zig+13-13
......@@ -134,7 +134,7 @@ test "FixedBufferStream output" {
134134 const stream = fbs.writer();
135135
136136 try stream.print("{s}{s}!", .{ "Hello", "World" });
137 testing.expectEqualSlices(u8, "HelloWorld!", fbs.getWritten());
137 try testing.expectEqualSlices(u8, "HelloWorld!", fbs.getWritten());
138138}
139139
140140test "FixedBufferStream output 2" {
......@@ -142,19 +142,19 @@ test "FixedBufferStream output 2" {
142142 var fbs = fixedBufferStream(&buffer);
143143
144144 try fbs.writer().writeAll("Hello");
145 testing.expect(mem.eql(u8, fbs.getWritten(), "Hello"));
145 try testing.expect(mem.eql(u8, fbs.getWritten(), "Hello"));
146146
147147 try fbs.writer().writeAll("world");
148 testing.expect(mem.eql(u8, fbs.getWritten(), "Helloworld"));
148 try testing.expect(mem.eql(u8, fbs.getWritten(), "Helloworld"));
149149
150 testing.expectError(error.NoSpaceLeft, fbs.writer().writeAll("!"));
151 testing.expect(mem.eql(u8, fbs.getWritten(), "Helloworld"));
150 try testing.expectError(error.NoSpaceLeft, fbs.writer().writeAll("!"));
151 try testing.expect(mem.eql(u8, fbs.getWritten(), "Helloworld"));
152152
153153 fbs.reset();
154 testing.expect(fbs.getWritten().len == 0);
154 try testing.expect(fbs.getWritten().len == 0);
155155
156 testing.expectError(error.NoSpaceLeft, fbs.writer().writeAll("Hello world!"));
157 testing.expect(mem.eql(u8, fbs.getWritten(), "Hello worl"));
156 try testing.expectError(error.NoSpaceLeft, fbs.writer().writeAll("Hello world!"));
157 try testing.expect(mem.eql(u8, fbs.getWritten(), "Hello worl"));
158158}
159159
160160test "FixedBufferStream input" {
......@@ -164,13 +164,13 @@ test "FixedBufferStream input" {
164164 var dest: [4]u8 = undefined;
165165
166166 var read = try fbs.reader().read(dest[0..4]);
167 testing.expect(read == 4);
168 testing.expect(mem.eql(u8, dest[0..4], bytes[0..4]));
167 try testing.expect(read == 4);
168 try testing.expect(mem.eql(u8, dest[0..4], bytes[0..4]));
169169
170170 read = try fbs.reader().read(dest[0..4]);
171 testing.expect(read == 3);
172 testing.expect(mem.eql(u8, dest[0..3], bytes[4..7]));
171 try testing.expect(read == 3);
172 try testing.expect(mem.eql(u8, dest[0..3], bytes[4..7]));
173173
174174 read = try fbs.reader().read(dest[0..4]);
175 testing.expect(read == 0);
175 try testing.expect(read == 0);
176176}
lib/std/io/limited_reader.zig+4-4
......@@ -43,8 +43,8 @@ test "basic usage" {
4343 var early_stream = limitedReader(fbs.reader(), 3);
4444
4545 var buf: [5]u8 = undefined;
46 testing.expectEqual(@as(usize, 3), try early_stream.reader().read(&buf));
47 testing.expectEqualSlices(u8, data[0..3], buf[0..3]);
48 testing.expectEqual(@as(usize, 0), try early_stream.reader().read(&buf));
49 testing.expectError(error.EndOfStream, early_stream.reader().skipBytes(10, .{}));
46 try testing.expectEqual(@as(usize, 3), try early_stream.reader().read(&buf));
47 try testing.expectEqualSlices(u8, data[0..3], buf[0..3]);
48 try testing.expectEqual(@as(usize, 0), try early_stream.reader().read(&buf));
49 try testing.expectError(error.EndOfStream, early_stream.reader().skipBytes(10, .{}));
5050}
lib/std/io/multi_writer.zig+2-2
......@@ -52,6 +52,6 @@ test "MultiWriter" {
5252 var fbs2 = io.fixedBufferStream(&buf2);
5353 var stream = multiWriter(.{ fbs1.writer(), fbs2.writer() });
5454 try stream.writer().print("HI", .{});
55 testing.expectEqualSlices(u8, "HI", fbs1.getWritten());
56 testing.expectEqualSlices(u8, "HI", fbs2.getWritten());
55 try testing.expectEqualSlices(u8, "HI", fbs1.getWritten());
56 try testing.expectEqualSlices(u8, "HI", fbs2.getWritten());
5757}
lib/std/io/peek_stream.zig+11-11
......@@ -94,24 +94,24 @@ test "PeekStream" {
9494 try ps.putBackByte(10);
9595
9696 var read = try ps.reader().read(dest[0..4]);
97 testing.expect(read == 4);
98 testing.expect(dest[0] == 10);
99 testing.expect(dest[1] == 9);
100 testing.expect(mem.eql(u8, dest[2..4], bytes[0..2]));
97 try testing.expect(read == 4);
98 try testing.expect(dest[0] == 10);
99 try testing.expect(dest[1] == 9);
100 try testing.expect(mem.eql(u8, dest[2..4], bytes[0..2]));
101101
102102 read = try ps.reader().read(dest[0..4]);
103 testing.expect(read == 4);
104 testing.expect(mem.eql(u8, dest[0..4], bytes[2..6]));
103 try testing.expect(read == 4);
104 try testing.expect(mem.eql(u8, dest[0..4], bytes[2..6]));
105105
106106 read = try ps.reader().read(dest[0..4]);
107 testing.expect(read == 2);
108 testing.expect(mem.eql(u8, dest[0..2], bytes[6..8]));
107 try testing.expect(read == 2);
108 try testing.expect(mem.eql(u8, dest[0..2], bytes[6..8]));
109109
110110 try ps.putBackByte(11);
111111 try ps.putBackByte(12);
112112
113113 read = try ps.reader().read(dest[0..4]);
114 testing.expect(read == 2);
115 testing.expect(dest[0] == 12);
116 testing.expect(dest[1] == 11);
114 try testing.expect(read == 2);
115 try testing.expect(dest[0] == 12);
116 try testing.expect(dest[1] == 11);
117117}
lib/std/io/reader.zig+7-7
......@@ -329,26 +329,26 @@ pub fn Reader(
329329test "Reader" {
330330 var buf = "a\x02".*;
331331 const reader = std.io.fixedBufferStream(&buf).reader();
332 testing.expect((try reader.readByte()) == 'a');
333 testing.expect((try reader.readEnum(enum(u8) {
332 try testing.expect((try reader.readByte()) == 'a');
333 try testing.expect((try reader.readEnum(enum(u8) {
334334 a = 0,
335335 b = 99,
336336 c = 2,
337337 d = 3,
338338 }, undefined)) == .c);
339 testing.expectError(error.EndOfStream, reader.readByte());
339 try testing.expectError(error.EndOfStream, reader.readByte());
340340}
341341
342342test "Reader.isBytes" {
343343 const reader = std.io.fixedBufferStream("foobar").reader();
344 testing.expectEqual(true, try reader.isBytes("foo"));
345 testing.expectEqual(false, try reader.isBytes("qux"));
344 try testing.expectEqual(true, try reader.isBytes("foo"));
345 try testing.expectEqual(false, try reader.isBytes("qux"));
346346}
347347
348348test "Reader.skipBytes" {
349349 const reader = std.io.fixedBufferStream("foobar").reader();
350350 try reader.skipBytes(3, .{});
351 testing.expect(try reader.isBytes("bar"));
351 try testing.expect(try reader.isBytes("bar"));
352352 try reader.skipBytes(0, .{});
353 testing.expectError(error.EndOfStream, reader.skipBytes(1, .{}));
353 try testing.expectError(error.EndOfStream, reader.skipBytes(1, .{}));
354354}
lib/std/io/test.zig+33-33
......@@ -40,7 +40,7 @@ test "write a file, read it, then delete it" {
4040
4141 {
4242 // Make sure the exclusive flag is honored.
43 expectError(File.OpenError.PathAlreadyExists, tmp.dir.createFile(tmp_file_name, .{ .exclusive = true }));
43 try expectError(File.OpenError.PathAlreadyExists, tmp.dir.createFile(tmp_file_name, .{ .exclusive = true }));
4444 }
4545
4646 {
......@@ -49,16 +49,16 @@ test "write a file, read it, then delete it" {
4949
5050 const file_size = try file.getEndPos();
5151 const expected_file_size: u64 = "begin".len + data.len + "end".len;
52 expectEqual(expected_file_size, file_size);
52 try expectEqual(expected_file_size, file_size);
5353
5454 var buf_stream = io.bufferedReader(file.reader());
5555 const st = buf_stream.reader();
5656 const contents = try st.readAllAlloc(std.testing.allocator, 2 * 1024);
5757 defer std.testing.allocator.free(contents);
5858
59 expect(mem.eql(u8, contents[0.."begin".len], "begin"));
60 expect(mem.eql(u8, contents["begin".len .. contents.len - "end".len], &data));
61 expect(mem.eql(u8, contents[contents.len - "end".len ..], "end"));
59 try expect(mem.eql(u8, contents[0.."begin".len], "begin"));
60 try expect(mem.eql(u8, contents["begin".len .. contents.len - "end".len], &data));
61 try expect(mem.eql(u8, contents[contents.len - "end".len ..], "end"));
6262 }
6363 try tmp.dir.deleteFile(tmp_file_name);
6464}
......@@ -90,20 +90,20 @@ test "BitStreams with File Stream" {
9090
9191 var out_bits: usize = undefined;
9292
93 expect(1 == try bit_stream.readBits(u2, 1, &out_bits));
94 expect(out_bits == 1);
95 expect(2 == try bit_stream.readBits(u5, 2, &out_bits));
96 expect(out_bits == 2);
97 expect(3 == try bit_stream.readBits(u128, 3, &out_bits));
98 expect(out_bits == 3);
99 expect(4 == try bit_stream.readBits(u8, 4, &out_bits));
100 expect(out_bits == 4);
101 expect(5 == try bit_stream.readBits(u9, 5, &out_bits));
102 expect(out_bits == 5);
103 expect(1 == try bit_stream.readBits(u1, 1, &out_bits));
104 expect(out_bits == 1);
105
106 expectError(error.EndOfStream, bit_stream.readBitsNoEof(u1, 1));
93 try expect(1 == try bit_stream.readBits(u2, 1, &out_bits));
94 try expect(out_bits == 1);
95 try expect(2 == try bit_stream.readBits(u5, 2, &out_bits));
96 try expect(out_bits == 2);
97 try expect(3 == try bit_stream.readBits(u128, 3, &out_bits));
98 try expect(out_bits == 3);
99 try expect(4 == try bit_stream.readBits(u8, 4, &out_bits));
100 try expect(out_bits == 4);
101 try expect(5 == try bit_stream.readBits(u9, 5, &out_bits));
102 try expect(out_bits == 5);
103 try expect(1 == try bit_stream.readBits(u1, 1, &out_bits));
104 try expect(out_bits == 1);
105
106 try expectError(error.EndOfStream, bit_stream.readBitsNoEof(u1, 1));
107107 }
108108 try tmp.dir.deleteFile(tmp_file_name);
109109}
......@@ -123,16 +123,16 @@ test "File seek ops" {
123123
124124 // Seek to the end
125125 try file.seekFromEnd(0);
126 expect((try file.getPos()) == try file.getEndPos());
126 try expect((try file.getPos()) == try file.getEndPos());
127127 // Negative delta
128128 try file.seekBy(-4096);
129 expect((try file.getPos()) == 4096);
129 try expect((try file.getPos()) == 4096);
130130 // Positive delta
131131 try file.seekBy(10);
132 expect((try file.getPos()) == 4106);
132 try expect((try file.getPos()) == 4106);
133133 // Absolute position
134134 try file.seekTo(1234);
135 expect((try file.getPos()) == 1234);
135 try expect((try file.getPos()) == 1234);
136136}
137137
138138test "setEndPos" {
......@@ -147,18 +147,18 @@ test "setEndPos" {
147147 }
148148
149149 // Verify that the file size changes and the file offset is not moved
150 std.testing.expect((try file.getEndPos()) == 0);
151 std.testing.expect((try file.getPos()) == 0);
150 try std.testing.expect((try file.getEndPos()) == 0);
151 try std.testing.expect((try file.getPos()) == 0);
152152 try file.setEndPos(8192);
153 std.testing.expect((try file.getEndPos()) == 8192);
154 std.testing.expect((try file.getPos()) == 0);
153 try std.testing.expect((try file.getEndPos()) == 8192);
154 try std.testing.expect((try file.getPos()) == 0);
155155 try file.seekTo(100);
156156 try file.setEndPos(4096);
157 std.testing.expect((try file.getEndPos()) == 4096);
158 std.testing.expect((try file.getPos()) == 100);
157 try std.testing.expect((try file.getEndPos()) == 4096);
158 try std.testing.expect((try file.getPos()) == 100);
159159 try file.setEndPos(0);
160 std.testing.expect((try file.getEndPos()) == 0);
161 std.testing.expect((try file.getPos()) == 100);
160 try std.testing.expect((try file.getEndPos()) == 0);
161 try std.testing.expect((try file.getPos()) == 100);
162162}
163163
164164test "updateTimes" {
......@@ -178,6 +178,6 @@ test "updateTimes" {
178178 stat_old.mtime - 5 * std.time.ns_per_s,
179179 );
180180 var stat_new = try file.stat();
181 expect(stat_new.atime < stat_old.atime);
182 expect(stat_new.mtime < stat_old.mtime);
181 try expect(stat_new.atime < stat_old.atime);
182 try expect(stat_new.mtime < stat_old.mtime);
183183}
lib/std/json.zig+139-139
......@@ -79,18 +79,18 @@ fn encodesTo(decoded: []const u8, encoded: []const u8) bool {
7979
8080test "encodesTo" {
8181 // same
82 testing.expectEqual(true, encodesTo("false", "false"));
82 try testing.expectEqual(true, encodesTo("false", "false"));
8383 // totally different
84 testing.expectEqual(false, encodesTo("false", "true"));
84 try testing.expectEqual(false, encodesTo("false", "true"));
8585 // different lengths
86 testing.expectEqual(false, encodesTo("false", "other"));
86 try testing.expectEqual(false, encodesTo("false", "other"));
8787 // with escape
88 testing.expectEqual(true, encodesTo("\\", "\\\\"));
89 testing.expectEqual(true, encodesTo("with\nescape", "with\\nescape"));
88 try testing.expectEqual(true, encodesTo("\\", "\\\\"));
89 try testing.expectEqual(true, encodesTo("with\nescape", "with\\nescape"));
9090 // with unicode
91 testing.expectEqual(true, encodesTo("ą", "\\u0105"));
92 testing.expectEqual(true, encodesTo("😂", "\\ud83d\\ude02"));
93 testing.expectEqual(true, encodesTo("withąunicode😂", "with\\u0105unicode\\ud83d\\ude02"));
91 try testing.expectEqual(true, encodesTo("ą", "\\u0105"));
92 try testing.expectEqual(true, encodesTo("😂", "\\ud83d\\ude02"));
93 try testing.expectEqual(true, encodesTo("withąunicode😂", "with\\u0105unicode\\ud83d\\ude02"));
9494}
9595
9696/// A single token slice into the parent string.
......@@ -1138,9 +1138,9 @@ pub const TokenStream = struct {
11381138 }
11391139};
11401140
1141fn checkNext(p: *TokenStream, id: std.meta.Tag(Token)) void {
1141fn checkNext(p: *TokenStream, id: std.meta.Tag(Token)) !void {
11421142 const token = (p.next() catch unreachable).?;
1143 debug.assert(std.meta.activeTag(token) == id);
1143 try testing.expect(std.meta.activeTag(token) == id);
11441144}
11451145
11461146test "json.token" {
......@@ -1163,46 +1163,46 @@ test "json.token" {
11631163
11641164 var p = TokenStream.init(s);
11651165
1166 checkNext(&p, .ObjectBegin);
1167 checkNext(&p, .String); // Image
1168 checkNext(&p, .ObjectBegin);
1169 checkNext(&p, .String); // Width
1170 checkNext(&p, .Number);
1171 checkNext(&p, .String); // Height
1172 checkNext(&p, .Number);
1173 checkNext(&p, .String); // Title
1174 checkNext(&p, .String);
1175 checkNext(&p, .String); // Thumbnail
1176 checkNext(&p, .ObjectBegin);
1177 checkNext(&p, .String); // Url
1178 checkNext(&p, .String);
1179 checkNext(&p, .String); // Height
1180 checkNext(&p, .Number);
1181 checkNext(&p, .String); // Width
1182 checkNext(&p, .Number);
1183 checkNext(&p, .ObjectEnd);
1184 checkNext(&p, .String); // Animated
1185 checkNext(&p, .False);
1186 checkNext(&p, .String); // IDs
1187 checkNext(&p, .ArrayBegin);
1188 checkNext(&p, .Number);
1189 checkNext(&p, .Number);
1190 checkNext(&p, .Number);
1191 checkNext(&p, .Number);
1192 checkNext(&p, .ArrayEnd);
1193 checkNext(&p, .ObjectEnd);
1194 checkNext(&p, .ObjectEnd);
1195
1196 testing.expect((try p.next()) == null);
1166 try checkNext(&p, .ObjectBegin);
1167 try checkNext(&p, .String); // Image
1168 try checkNext(&p, .ObjectBegin);
1169 try checkNext(&p, .String); // Width
1170 try checkNext(&p, .Number);
1171 try checkNext(&p, .String); // Height
1172 try checkNext(&p, .Number);
1173 try checkNext(&p, .String); // Title
1174 try checkNext(&p, .String);
1175 try checkNext(&p, .String); // Thumbnail
1176 try checkNext(&p, .ObjectBegin);
1177 try checkNext(&p, .String); // Url
1178 try checkNext(&p, .String);
1179 try checkNext(&p, .String); // Height
1180 try checkNext(&p, .Number);
1181 try checkNext(&p, .String); // Width
1182 try checkNext(&p, .Number);
1183 try checkNext(&p, .ObjectEnd);
1184 try checkNext(&p, .String); // Animated
1185 try checkNext(&p, .False);
1186 try checkNext(&p, .String); // IDs
1187 try checkNext(&p, .ArrayBegin);
1188 try checkNext(&p, .Number);
1189 try checkNext(&p, .Number);
1190 try checkNext(&p, .Number);
1191 try checkNext(&p, .Number);
1192 try checkNext(&p, .ArrayEnd);
1193 try checkNext(&p, .ObjectEnd);
1194 try checkNext(&p, .ObjectEnd);
1195
1196 try testing.expect((try p.next()) == null);
11971197}
11981198
11991199test "json.token mismatched close" {
12001200 var p = TokenStream.init("[102, 111, 111 }");
1201 checkNext(&p, .ArrayBegin);
1202 checkNext(&p, .Number);
1203 checkNext(&p, .Number);
1204 checkNext(&p, .Number);
1205 testing.expectError(error.UnexpectedClosingBrace, p.next());
1201 try checkNext(&p, .ArrayBegin);
1202 try checkNext(&p, .Number);
1203 try checkNext(&p, .Number);
1204 try checkNext(&p, .Number);
1205 try testing.expectError(error.UnexpectedClosingBrace, p.next());
12061206}
12071207
12081208/// Validate a JSON string. This does not limit number precision so a decoder may not necessarily
......@@ -1223,12 +1223,12 @@ pub fn validate(s: []const u8) bool {
12231223}
12241224
12251225test "json.validate" {
1226 testing.expectEqual(true, validate("{}"));
1227 testing.expectEqual(true, validate("[]"));
1228 testing.expectEqual(true, validate("[{[[[[{}]]]]}]"));
1229 testing.expectEqual(false, validate("{]"));
1230 testing.expectEqual(false, validate("[}"));
1231 testing.expectEqual(false, validate("{{{{[]}}}]"));
1226 try testing.expectEqual(true, validate("{}"));
1227 try testing.expectEqual(true, validate("[]"));
1228 try testing.expectEqual(true, validate("[{[[[[{}]]]]}]"));
1229 try testing.expectEqual(false, validate("{]"));
1230 try testing.expectEqual(false, validate("[}"));
1231 try testing.expectEqual(false, validate("{{{{[]}}}]"));
12321232}
12331233
12341234const Allocator = std.mem.Allocator;
......@@ -1326,37 +1326,37 @@ test "Value.jsonStringify" {
13261326 var buffer: [10]u8 = undefined;
13271327 var fbs = std.io.fixedBufferStream(&buffer);
13281328 try @as(Value, .Null).jsonStringify(.{}, fbs.writer());
1329 testing.expectEqualSlices(u8, fbs.getWritten(), "null");
1329 try testing.expectEqualSlices(u8, fbs.getWritten(), "null");
13301330 }
13311331 {
13321332 var buffer: [10]u8 = undefined;
13331333 var fbs = std.io.fixedBufferStream(&buffer);
13341334 try (Value{ .Bool = true }).jsonStringify(.{}, fbs.writer());
1335 testing.expectEqualSlices(u8, fbs.getWritten(), "true");
1335 try testing.expectEqualSlices(u8, fbs.getWritten(), "true");
13361336 }
13371337 {
13381338 var buffer: [10]u8 = undefined;
13391339 var fbs = std.io.fixedBufferStream(&buffer);
13401340 try (Value{ .Integer = 42 }).jsonStringify(.{}, fbs.writer());
1341 testing.expectEqualSlices(u8, fbs.getWritten(), "42");
1341 try testing.expectEqualSlices(u8, fbs.getWritten(), "42");
13421342 }
13431343 {
13441344 var buffer: [10]u8 = undefined;
13451345 var fbs = std.io.fixedBufferStream(&buffer);
13461346 try (Value{ .NumberString = "43" }).jsonStringify(.{}, fbs.writer());
1347 testing.expectEqualSlices(u8, fbs.getWritten(), "43");
1347 try testing.expectEqualSlices(u8, fbs.getWritten(), "43");
13481348 }
13491349 {
13501350 var buffer: [10]u8 = undefined;
13511351 var fbs = std.io.fixedBufferStream(&buffer);
13521352 try (Value{ .Float = 42 }).jsonStringify(.{}, fbs.writer());
1353 testing.expectEqualSlices(u8, fbs.getWritten(), "4.2e+01");
1353 try testing.expectEqualSlices(u8, fbs.getWritten(), "4.2e+01");
13541354 }
13551355 {
13561356 var buffer: [10]u8 = undefined;
13571357 var fbs = std.io.fixedBufferStream(&buffer);
13581358 try (Value{ .String = "weeee" }).jsonStringify(.{}, fbs.writer());
1359 testing.expectEqualSlices(u8, fbs.getWritten(), "\"weeee\"");
1359 try testing.expectEqualSlices(u8, fbs.getWritten(), "\"weeee\"");
13601360 }
13611361 {
13621362 var buffer: [10]u8 = undefined;
......@@ -1369,7 +1369,7 @@ test "Value.jsonStringify" {
13691369 try (Value{
13701370 .Array = Array.fromOwnedSlice(undefined, &vals),
13711371 }).jsonStringify(.{}, fbs.writer());
1372 testing.expectEqualSlices(u8, fbs.getWritten(), "[1,2,3]");
1372 try testing.expectEqualSlices(u8, fbs.getWritten(), "[1,2,3]");
13731373 }
13741374 {
13751375 var buffer: [10]u8 = undefined;
......@@ -1378,7 +1378,7 @@ test "Value.jsonStringify" {
13781378 defer obj.deinit();
13791379 try obj.putNoClobber("a", .{ .String = "b" });
13801380 try (Value{ .Object = obj }).jsonStringify(.{}, fbs.writer());
1381 testing.expectEqualSlices(u8, fbs.getWritten(), "{\"a\":\"b\"}");
1381 try testing.expectEqualSlices(u8, fbs.getWritten(), "{\"a\":\"b\"}");
13821382 }
13831383}
13841384
......@@ -1751,17 +1751,17 @@ pub fn parseFree(comptime T: type, value: T, options: ParseOptions) void {
17511751}
17521752
17531753test "parse" {
1754 testing.expectEqual(false, try parse(bool, &TokenStream.init("false"), ParseOptions{}));
1755 testing.expectEqual(true, try parse(bool, &TokenStream.init("true"), ParseOptions{}));
1756 testing.expectEqual(@as(u1, 1), try parse(u1, &TokenStream.init("1"), ParseOptions{}));
1757 testing.expectError(error.Overflow, parse(u1, &TokenStream.init("50"), ParseOptions{}));
1758 testing.expectEqual(@as(u64, 42), try parse(u64, &TokenStream.init("42"), ParseOptions{}));
1759 testing.expectEqual(@as(f64, 42), try parse(f64, &TokenStream.init("42.0"), ParseOptions{}));
1760 testing.expectEqual(@as(?bool, null), try parse(?bool, &TokenStream.init("null"), ParseOptions{}));
1761 testing.expectEqual(@as(?bool, true), try parse(?bool, &TokenStream.init("true"), ParseOptions{}));
1762
1763 testing.expectEqual(@as([3]u8, "foo".*), try parse([3]u8, &TokenStream.init("\"foo\""), ParseOptions{}));
1764 testing.expectEqual(@as([3]u8, "foo".*), try parse([3]u8, &TokenStream.init("[102, 111, 111]"), ParseOptions{}));
1754 try testing.expectEqual(false, try parse(bool, &TokenStream.init("false"), ParseOptions{}));
1755 try testing.expectEqual(true, try parse(bool, &TokenStream.init("true"), ParseOptions{}));
1756 try testing.expectEqual(@as(u1, 1), try parse(u1, &TokenStream.init("1"), ParseOptions{}));
1757 try testing.expectError(error.Overflow, parse(u1, &TokenStream.init("50"), ParseOptions{}));
1758 try testing.expectEqual(@as(u64, 42), try parse(u64, &TokenStream.init("42"), ParseOptions{}));
1759 try testing.expectEqual(@as(f64, 42), try parse(f64, &TokenStream.init("42.0"), ParseOptions{}));
1760 try testing.expectEqual(@as(?bool, null), try parse(?bool, &TokenStream.init("null"), ParseOptions{}));
1761 try testing.expectEqual(@as(?bool, true), try parse(?bool, &TokenStream.init("true"), ParseOptions{}));
1762
1763 try testing.expectEqual(@as([3]u8, "foo".*), try parse([3]u8, &TokenStream.init("\"foo\""), ParseOptions{}));
1764 try testing.expectEqual(@as([3]u8, "foo".*), try parse([3]u8, &TokenStream.init("[102, 111, 111]"), ParseOptions{}));
17651765}
17661766
17671767test "parse into enum" {
......@@ -1770,31 +1770,31 @@ test "parse into enum" {
17701770 Bar,
17711771 @"with\\escape",
17721772 };
1773 testing.expectEqual(@as(T, .Foo), try parse(T, &TokenStream.init("\"Foo\""), ParseOptions{}));
1774 testing.expectEqual(@as(T, .Foo), try parse(T, &TokenStream.init("42"), ParseOptions{}));
1775 testing.expectEqual(@as(T, .@"with\\escape"), try parse(T, &TokenStream.init("\"with\\\\escape\""), ParseOptions{}));
1776 testing.expectError(error.InvalidEnumTag, parse(T, &TokenStream.init("5"), ParseOptions{}));
1777 testing.expectError(error.InvalidEnumTag, parse(T, &TokenStream.init("\"Qux\""), ParseOptions{}));
1773 try testing.expectEqual(@as(T, .Foo), try parse(T, &TokenStream.init("\"Foo\""), ParseOptions{}));
1774 try testing.expectEqual(@as(T, .Foo), try parse(T, &TokenStream.init("42"), ParseOptions{}));
1775 try testing.expectEqual(@as(T, .@"with\\escape"), try parse(T, &TokenStream.init("\"with\\\\escape\""), ParseOptions{}));
1776 try testing.expectError(error.InvalidEnumTag, parse(T, &TokenStream.init("5"), ParseOptions{}));
1777 try testing.expectError(error.InvalidEnumTag, parse(T, &TokenStream.init("\"Qux\""), ParseOptions{}));
17781778}
17791779
17801780test "parse into that allocates a slice" {
1781 testing.expectError(error.AllocatorRequired, parse([]u8, &TokenStream.init("\"foo\""), ParseOptions{}));
1781 try testing.expectError(error.AllocatorRequired, parse([]u8, &TokenStream.init("\"foo\""), ParseOptions{}));
17821782
17831783 const options = ParseOptions{ .allocator = testing.allocator };
17841784 {
17851785 const r = try parse([]u8, &TokenStream.init("\"foo\""), options);
17861786 defer parseFree([]u8, r, options);
1787 testing.expectEqualSlices(u8, "foo", r);
1787 try testing.expectEqualSlices(u8, "foo", r);
17881788 }
17891789 {
17901790 const r = try parse([]u8, &TokenStream.init("[102, 111, 111]"), options);
17911791 defer parseFree([]u8, r, options);
1792 testing.expectEqualSlices(u8, "foo", r);
1792 try testing.expectEqualSlices(u8, "foo", r);
17931793 }
17941794 {
17951795 const r = try parse([]u8, &TokenStream.init("\"with\\\\escape\""), options);
17961796 defer parseFree([]u8, r, options);
1797 testing.expectEqualSlices(u8, "with\\escape", r);
1797 try testing.expectEqualSlices(u8, "with\\escape", r);
17981798 }
17991799}
18001800
......@@ -1805,7 +1805,7 @@ test "parse into tagged union" {
18051805 float: f64,
18061806 string: []const u8,
18071807 };
1808 testing.expectEqual(T{ .float = 1.5 }, try parse(T, &TokenStream.init("1.5"), ParseOptions{}));
1808 try testing.expectEqual(T{ .float = 1.5 }, try parse(T, &TokenStream.init("1.5"), ParseOptions{}));
18091809 }
18101810
18111811 { // failing allocations should be bubbled up instantly without trying next member
......@@ -1816,7 +1816,7 @@ test "parse into tagged union" {
18161816 string: []const u8,
18171817 array: [3]u8,
18181818 };
1819 testing.expectError(error.OutOfMemory, parse(T, &TokenStream.init("[1,2,3]"), options));
1819 try testing.expectError(error.OutOfMemory, parse(T, &TokenStream.init("[1,2,3]"), options));
18201820 }
18211821
18221822 {
......@@ -1825,7 +1825,7 @@ test "parse into tagged union" {
18251825 x: u8,
18261826 y: u8,
18271827 };
1828 testing.expectEqual(T{ .x = 42 }, try parse(T, &TokenStream.init("42"), ParseOptions{}));
1828 try testing.expectEqual(T{ .x = 42 }, try parse(T, &TokenStream.init("42"), ParseOptions{}));
18291829 }
18301830
18311831 { // needs to back out when first union member doesn't match
......@@ -1833,7 +1833,7 @@ test "parse into tagged union" {
18331833 A: struct { x: u32 },
18341834 B: struct { y: u32 },
18351835 };
1836 testing.expectEqual(T{ .B = .{ .y = 42 } }, try parse(T, &TokenStream.init("{\"y\":42}"), ParseOptions{}));
1836 try testing.expectEqual(T{ .B = .{ .y = 42 } }, try parse(T, &TokenStream.init("{\"y\":42}"), ParseOptions{}));
18371837 }
18381838}
18391839
......@@ -1843,7 +1843,7 @@ test "parse union bubbles up AllocatorRequired" {
18431843 string: []const u8,
18441844 int: i32,
18451845 };
1846 testing.expectError(error.AllocatorRequired, parse(T, &TokenStream.init("42"), ParseOptions{}));
1846 try testing.expectError(error.AllocatorRequired, parse(T, &TokenStream.init("42"), ParseOptions{}));
18471847 }
18481848
18491849 { // string member not first in union (and matching)
......@@ -1852,7 +1852,7 @@ test "parse union bubbles up AllocatorRequired" {
18521852 float: f64,
18531853 string: []const u8,
18541854 };
1855 testing.expectError(error.AllocatorRequired, parse(T, &TokenStream.init("\"foo\""), ParseOptions{}));
1855 try testing.expectError(error.AllocatorRequired, parse(T, &TokenStream.init("\"foo\""), ParseOptions{}));
18561856 }
18571857}
18581858
......@@ -1866,11 +1866,11 @@ test "parseFree descends into tagged union" {
18661866 };
18671867 // use a string with unicode escape so we know result can't be a reference to global constant
18681868 const r = try parse(T, &TokenStream.init("\"with\\u0105unicode\""), options);
1869 testing.expectEqual(std.meta.Tag(T).string, @as(std.meta.Tag(T), r));
1870 testing.expectEqualSlices(u8, "withąunicode", r.string);
1871 testing.expectEqual(@as(usize, 0), fail_alloc.deallocations);
1869 try testing.expectEqual(std.meta.Tag(T).string, @as(std.meta.Tag(T), r));
1870 try testing.expectEqualSlices(u8, "withąunicode", r.string);
1871 try testing.expectEqual(@as(usize, 0), fail_alloc.deallocations);
18721872 parseFree(T, r, options);
1873 testing.expectEqual(@as(usize, 1), fail_alloc.deallocations);
1873 try testing.expectEqual(@as(usize, 1), fail_alloc.deallocations);
18741874}
18751875
18761876test "parse with comptime field" {
......@@ -1879,7 +1879,7 @@ test "parse with comptime field" {
18791879 comptime a: i32 = 0,
18801880 b: bool,
18811881 };
1882 testing.expectEqual(T{ .a = 0, .b = true }, try parse(T, &TokenStream.init(
1882 try testing.expectEqual(T{ .a = 0, .b = true }, try parse(T, &TokenStream.init(
18831883 \\{
18841884 \\ "a": 0,
18851885 \\ "b": true
......@@ -1912,7 +1912,7 @@ test "parse with comptime field" {
19121912
19131913test "parse into struct with no fields" {
19141914 const T = struct {};
1915 testing.expectEqual(T{}, try parse(T, &TokenStream.init("{}"), ParseOptions{}));
1915 try testing.expectEqual(T{}, try parse(T, &TokenStream.init("{}"), ParseOptions{}));
19161916}
19171917
19181918test "parse into struct with misc fields" {
......@@ -1968,24 +1968,24 @@ test "parse into struct with misc fields" {
19681968 \\}
19691969 ), options);
19701970 defer parseFree(T, r, options);
1971 testing.expectEqual(@as(i64, 420), r.int);
1972 testing.expectEqual(@as(f64, 3.14), r.float);
1973 testing.expectEqual(true, r.@"with\\escape");
1974 testing.expectEqual(false, r.@"withąunicode😂");
1975 testing.expectEqualSlices(u8, "zig", r.language);
1976 testing.expectEqual(@as(?bool, null), r.optional);
1977 testing.expectEqual(@as(i32, 42), r.default_field);
1978 testing.expectEqual(@as(f64, 66.6), r.static_array[0]);
1979 testing.expectEqual(@as(f64, 420.420), r.static_array[1]);
1980 testing.expectEqual(@as(f64, 69.69), r.static_array[2]);
1981 testing.expectEqual(@as(usize, 3), r.dynamic_array.len);
1982 testing.expectEqual(@as(f64, 66.6), r.dynamic_array[0]);
1983 testing.expectEqual(@as(f64, 420.420), r.dynamic_array[1]);
1984 testing.expectEqual(@as(f64, 69.69), r.dynamic_array[2]);
1985 testing.expectEqualSlices(u8, r.complex.nested, "zig");
1986 testing.expectEqualSlices(u8, "zig", r.veryComplex[0].foo);
1987 testing.expectEqualSlices(u8, "rocks", r.veryComplex[1].foo);
1988 testing.expectEqual(T.Union{ .float = 100000 }, r.a_union);
1971 try testing.expectEqual(@as(i64, 420), r.int);
1972 try testing.expectEqual(@as(f64, 3.14), r.float);
1973 try testing.expectEqual(true, r.@"with\\escape");
1974 try testing.expectEqual(false, r.@"withąunicode😂");
1975 try testing.expectEqualSlices(u8, "zig", r.language);
1976 try testing.expectEqual(@as(?bool, null), r.optional);
1977 try testing.expectEqual(@as(i32, 42), r.default_field);
1978 try testing.expectEqual(@as(f64, 66.6), r.static_array[0]);
1979 try testing.expectEqual(@as(f64, 420.420), r.static_array[1]);
1980 try testing.expectEqual(@as(f64, 69.69), r.static_array[2]);
1981 try testing.expectEqual(@as(usize, 3), r.dynamic_array.len);
1982 try testing.expectEqual(@as(f64, 66.6), r.dynamic_array[0]);
1983 try testing.expectEqual(@as(f64, 420.420), r.dynamic_array[1]);
1984 try testing.expectEqual(@as(f64, 69.69), r.dynamic_array[2]);
1985 try testing.expectEqualSlices(u8, r.complex.nested, "zig");
1986 try testing.expectEqualSlices(u8, "zig", r.veryComplex[0].foo);
1987 try testing.expectEqualSlices(u8, "rocks", r.veryComplex[1].foo);
1988 try testing.expectEqual(T.Union{ .float = 100000 }, r.a_union);
19891989}
19901990
19911991/// A non-stream JSON parser which constructs a tree of Value's.
......@@ -2320,28 +2320,28 @@ test "json.parser.dynamic" {
23202320 var image = root.Object.get("Image").?;
23212321
23222322 const width = image.Object.get("Width").?;
2323 testing.expect(width.Integer == 800);
2323 try testing.expect(width.Integer == 800);
23242324
23252325 const height = image.Object.get("Height").?;
2326 testing.expect(height.Integer == 600);
2326 try testing.expect(height.Integer == 600);
23272327
23282328 const title = image.Object.get("Title").?;
2329 testing.expect(mem.eql(u8, title.String, "View from 15th Floor"));
2329 try testing.expect(mem.eql(u8, title.String, "View from 15th Floor"));
23302330
23312331 const animated = image.Object.get("Animated").?;
2332 testing.expect(animated.Bool == false);
2332 try testing.expect(animated.Bool == false);
23332333
23342334 const array_of_object = image.Object.get("ArrayOfObject").?;
2335 testing.expect(array_of_object.Array.items.len == 1);
2335 try testing.expect(array_of_object.Array.items.len == 1);
23362336
23372337 const obj0 = array_of_object.Array.items[0].Object.get("n").?;
2338 testing.expect(mem.eql(u8, obj0.String, "m"));
2338 try testing.expect(mem.eql(u8, obj0.String, "m"));
23392339
23402340 const double = image.Object.get("double").?;
2341 testing.expect(double.Float == 1.3412);
2341 try testing.expect(double.Float == 1.3412);
23422342
23432343 const large_int = image.Object.get("LargeInt").?;
2344 testing.expect(mem.eql(u8, large_int.NumberString, "18446744073709551615"));
2344 try testing.expect(mem.eql(u8, large_int.NumberString, "18446744073709551615"));
23452345}
23462346
23472347test "import more json tests" {
......@@ -2388,12 +2388,12 @@ test "write json then parse it" {
23882388 var tree = try parser.parse(fixed_buffer_stream.getWritten());
23892389 defer tree.deinit();
23902390
2391 testing.expect(tree.root.Object.get("f").?.Bool == false);
2392 testing.expect(tree.root.Object.get("t").?.Bool == true);
2393 testing.expect(tree.root.Object.get("int").?.Integer == 1234);
2394 testing.expect(tree.root.Object.get("array").?.Array.items[0].Null == {});
2395 testing.expect(tree.root.Object.get("array").?.Array.items[1].Float == 12.34);
2396 testing.expect(mem.eql(u8, tree.root.Object.get("str").?.String, "hello"));
2391 try testing.expect(tree.root.Object.get("f").?.Bool == false);
2392 try testing.expect(tree.root.Object.get("t").?.Bool == true);
2393 try testing.expect(tree.root.Object.get("int").?.Integer == 1234);
2394 try testing.expect(tree.root.Object.get("array").?.Array.items[0].Null == {});
2395 try testing.expect(tree.root.Object.get("array").?.Array.items[1].Float == 12.34);
2396 try testing.expect(mem.eql(u8, tree.root.Object.get("str").?.String, "hello"));
23972397}
23982398
23992399fn test_parse(arena_allocator: *std.mem.Allocator, json_str: []const u8) !Value {
......@@ -2404,7 +2404,7 @@ fn test_parse(arena_allocator: *std.mem.Allocator, json_str: []const u8) !Value
24042404test "parsing empty string gives appropriate error" {
24052405 var arena_allocator = std.heap.ArenaAllocator.init(std.testing.allocator);
24062406 defer arena_allocator.deinit();
2407 testing.expectError(error.UnexpectedEndOfJson, test_parse(&arena_allocator.allocator, ""));
2407 try testing.expectError(error.UnexpectedEndOfJson, test_parse(&arena_allocator.allocator, ""));
24082408}
24092409
24102410test "integer after float has proper type" {
......@@ -2416,7 +2416,7 @@ test "integer after float has proper type" {
24162416 \\ "ints": [1, 2, 3]
24172417 \\}
24182418 );
2419 std.testing.expect(json.Object.get("ints").?.Array.items[0] == .Integer);
2419 try std.testing.expect(json.Object.get("ints").?.Array.items[0] == .Integer);
24202420}
24212421
24222422test "escaped characters" {
......@@ -2439,16 +2439,16 @@ test "escaped characters" {
24392439
24402440 const obj = (try test_parse(&arena_allocator.allocator, input)).Object;
24412441
2442 testing.expectEqualSlices(u8, obj.get("backslash").?.String, "\\");
2443 testing.expectEqualSlices(u8, obj.get("forwardslash").?.String, "/");
2444 testing.expectEqualSlices(u8, obj.get("newline").?.String, "\n");
2445 testing.expectEqualSlices(u8, obj.get("carriagereturn").?.String, "\r");
2446 testing.expectEqualSlices(u8, obj.get("tab").?.String, "\t");
2447 testing.expectEqualSlices(u8, obj.get("formfeed").?.String, "\x0C");
2448 testing.expectEqualSlices(u8, obj.get("backspace").?.String, "\x08");
2449 testing.expectEqualSlices(u8, obj.get("doublequote").?.String, "\"");
2450 testing.expectEqualSlices(u8, obj.get("unicode").?.String, "ą");
2451 testing.expectEqualSlices(u8, obj.get("surrogatepair").?.String, "😂");
2442 try testing.expectEqualSlices(u8, obj.get("backslash").?.String, "\\");
2443 try testing.expectEqualSlices(u8, obj.get("forwardslash").?.String, "/");
2444 try testing.expectEqualSlices(u8, obj.get("newline").?.String, "\n");
2445 try testing.expectEqualSlices(u8, obj.get("carriagereturn").?.String, "\r");
2446 try testing.expectEqualSlices(u8, obj.get("tab").?.String, "\t");
2447 try testing.expectEqualSlices(u8, obj.get("formfeed").?.String, "\x0C");
2448 try testing.expectEqualSlices(u8, obj.get("backspace").?.String, "\x08");
2449 try testing.expectEqualSlices(u8, obj.get("doublequote").?.String, "\"");
2450 try testing.expectEqualSlices(u8, obj.get("unicode").?.String, "ą");
2451 try testing.expectEqualSlices(u8, obj.get("surrogatepair").?.String, "😂");
24522452}
24532453
24542454test "string copy option" {
......@@ -2471,7 +2471,7 @@ test "string copy option" {
24712471 const obj_copy = tree_copy.root.Object;
24722472
24732473 for ([_][]const u8{ "noescape", "simple", "unicode", "surrogatepair" }) |field_name| {
2474 testing.expectEqualSlices(u8, obj_nocopy.get(field_name).?.String, obj_copy.get(field_name).?.String);
2474 try testing.expectEqualSlices(u8, obj_nocopy.get(field_name).?.String, obj_copy.get(field_name).?.String);
24752475 }
24762476
24772477 const nocopy_addr = &obj_nocopy.get("noescape").?.String[0];
......@@ -2479,12 +2479,12 @@ test "string copy option" {
24792479
24802480 var found_nocopy = false;
24812481 for (input) |_, index| {
2482 testing.expect(copy_addr != &input[index]);
2482 try testing.expect(copy_addr != &input[index]);
24832483 if (nocopy_addr == &input[index]) {
24842484 found_nocopy = true;
24852485 }
24862486 }
2487 testing.expect(found_nocopy);
2487 try testing.expect(found_nocopy);
24882488}
24892489
24902490pub const StringifyOptions = struct {
lib/std/json/test.zig+275-275
......@@ -21,37 +21,37 @@ fn testNonStreaming(s: []const u8) !void {
2121}
2222
2323fn ok(s: []const u8) !void {
24 testing.expect(json.validate(s));
24 try testing.expect(json.validate(s));
2525
2626 try testNonStreaming(s);
2727}
2828
29fn err(s: []const u8) void {
30 testing.expect(!json.validate(s));
29fn err(s: []const u8) !void {
30 try testing.expect(!json.validate(s));
3131
32 testing.expect(std.meta.isError(testNonStreaming(s)));
32 try testing.expect(std.meta.isError(testNonStreaming(s)));
3333}
3434
35fn utf8Error(s: []const u8) void {
36 testing.expect(!json.validate(s));
35fn utf8Error(s: []const u8) !void {
36 try testing.expect(!json.validate(s));
3737
38 testing.expectError(error.InvalidUtf8Byte, testNonStreaming(s));
38 try testing.expectError(error.InvalidUtf8Byte, testNonStreaming(s));
3939}
4040
41fn any(s: []const u8) void {
41fn any(s: []const u8) !void {
4242 _ = json.validate(s);
4343
4444 testNonStreaming(s) catch {};
4545}
4646
47fn anyStreamingErrNonStreaming(s: []const u8) void {
47fn anyStreamingErrNonStreaming(s: []const u8) !void {
4848 _ = json.validate(s);
4949
50 testing.expect(std.meta.isError(testNonStreaming(s)));
50 try testing.expect(std.meta.isError(testNonStreaming(s)));
5151}
5252
5353fn roundTrip(s: []const u8) !void {
54 testing.expect(json.validate(s));
54 try testing.expect(json.validate(s));
5555
5656 var p = json.Parser.init(testing.allocator, false);
5757 defer p.deinit();
......@@ -63,7 +63,7 @@ fn roundTrip(s: []const u8) !void {
6363 var fbs = std.io.fixedBufferStream(&buf);
6464 try tree.root.jsonStringify(.{}, fbs.writer());
6565
66 testing.expectEqualStrings(s, fbs.getWritten());
66 try testing.expectEqualStrings(s, fbs.getWritten());
6767}
6868
6969////////////////////////////////////////////////////////////////////////////////////////////////////
......@@ -642,109 +642,109 @@ test "y_structure_whitespace_array" {
642642////////////////////////////////////////////////////////////////////////////////////////////////////
643643
644644test "n_array_1_true_without_comma" {
645 err(
645 try err(
646646 \\[1 true]
647647 );
648648}
649649
650650test "n_array_a_invalid_utf8" {
651 err(
651 try err(
652652 \\[aå]
653653 );
654654}
655655
656656test "n_array_colon_instead_of_comma" {
657 err(
657 try err(
658658 \\["": 1]
659659 );
660660}
661661
662662test "n_array_comma_after_close" {
663 err(
663 try err(
664664 \\[""],
665665 );
666666}
667667
668668test "n_array_comma_and_number" {
669 err(
669 try err(
670670 \\[,1]
671671 );
672672}
673673
674674test "n_array_double_comma" {
675 err(
675 try err(
676676 \\[1,,2]
677677 );
678678}
679679
680680test "n_array_double_extra_comma" {
681 err(
681 try err(
682682 \\["x",,]
683683 );
684684}
685685
686686test "n_array_extra_close" {
687 err(
687 try err(
688688 \\["x"]]
689689 );
690690}
691691
692692test "n_array_extra_comma" {
693 err(
693 try err(
694694 \\["",]
695695 );
696696}
697697
698698test "n_array_incomplete_invalid_value" {
699 err(
699 try err(
700700 \\[x
701701 );
702702}
703703
704704test "n_array_incomplete" {
705 err(
705 try err(
706706 \\["x"
707707 );
708708}
709709
710710test "n_array_inner_array_no_comma" {
711 err(
711 try err(
712712 \\[3[4]]
713713 );
714714}
715715
716716test "n_array_invalid_utf8" {
717 err(
717 try err(
718718 \\[ÿ]
719719 );
720720}
721721
722722test "n_array_items_separated_by_semicolon" {
723 err(
723 try err(
724724 \\[1:2]
725725 );
726726}
727727
728728test "n_array_just_comma" {
729 err(
729 try err(
730730 \\[,]
731731 );
732732}
733733
734734test "n_array_just_minus" {
735 err(
735 try err(
736736 \\[-]
737737 );
738738}
739739
740740test "n_array_missing_value" {
741 err(
741 try err(
742742 \\[ , ""]
743743 );
744744}
745745
746746test "n_array_newlines_unclosed" {
747 err(
747 try err(
748748 \\["a",
749749 \\4
750750 \\,1,
......@@ -752,41 +752,41 @@ test "n_array_newlines_unclosed" {
752752}
753753
754754test "n_array_number_and_comma" {
755 err(
755 try err(
756756 \\[1,]
757757 );
758758}
759759
760760test "n_array_number_and_several_commas" {
761 err(
761 try err(
762762 \\[1,,]
763763 );
764764}
765765
766766test "n_array_spaces_vertical_tab_formfeed" {
767 err("[\"\x0aa\"\\f]");
767 try err("[\"\x0aa\"\\f]");
768768}
769769
770770test "n_array_star_inside" {
771 err(
771 try err(
772772 \\[*]
773773 );
774774}
775775
776776test "n_array_unclosed" {
777 err(
777 try err(
778778 \\[""
779779 );
780780}
781781
782782test "n_array_unclosed_trailing_comma" {
783 err(
783 try err(
784784 \\[1,
785785 );
786786}
787787
788788test "n_array_unclosed_with_new_lines" {
789 err(
789 try err(
790790 \\[1,
791791 \\1
792792 \\,1
......@@ -794,956 +794,956 @@ test "n_array_unclosed_with_new_lines" {
794794}
795795
796796test "n_array_unclosed_with_object_inside" {
797 err(
797 try err(
798798 \\[{}
799799 );
800800}
801801
802802test "n_incomplete_false" {
803 err(
803 try err(
804804 \\[fals]
805805 );
806806}
807807
808808test "n_incomplete_null" {
809 err(
809 try err(
810810 \\[nul]
811811 );
812812}
813813
814814test "n_incomplete_true" {
815 err(
815 try err(
816816 \\[tru]
817817 );
818818}
819819
820820test "n_multidigit_number_then_00" {
821 err("123\x00");
821 try err("123\x00");
822822}
823823
824824test "n_number_0.1.2" {
825 err(
825 try err(
826826 \\[0.1.2]
827827 );
828828}
829829
830830test "n_number_-01" {
831 err(
831 try err(
832832 \\[-01]
833833 );
834834}
835835
836836test "n_number_0.3e" {
837 err(
837 try err(
838838 \\[0.3e]
839839 );
840840}
841841
842842test "n_number_0.3e+" {
843 err(
843 try err(
844844 \\[0.3e+]
845845 );
846846}
847847
848848test "n_number_0_capital_E" {
849 err(
849 try err(
850850 \\[0E]
851851 );
852852}
853853
854854test "n_number_0_capital_E+" {
855 err(
855 try err(
856856 \\[0E+]
857857 );
858858}
859859
860860test "n_number_0.e1" {
861 err(
861 try err(
862862 \\[0.e1]
863863 );
864864}
865865
866866test "n_number_0e" {
867 err(
867 try err(
868868 \\[0e]
869869 );
870870}
871871
872872test "n_number_0e+" {
873 err(
873 try err(
874874 \\[0e+]
875875 );
876876}
877877
878878test "n_number_1_000" {
879 err(
879 try err(
880880 \\[1 000.0]
881881 );
882882}
883883
884884test "n_number_1.0e-" {
885 err(
885 try err(
886886 \\[1.0e-]
887887 );
888888}
889889
890890test "n_number_1.0e" {
891 err(
891 try err(
892892 \\[1.0e]
893893 );
894894}
895895
896896test "n_number_1.0e+" {
897 err(
897 try err(
898898 \\[1.0e+]
899899 );
900900}
901901
902902test "n_number_-1.0." {
903 err(
903 try err(
904904 \\[-1.0.]
905905 );
906906}
907907
908908test "n_number_1eE2" {
909 err(
909 try err(
910910 \\[1eE2]
911911 );
912912}
913913
914914test "n_number_.-1" {
915 err(
915 try err(
916916 \\[.-1]
917917 );
918918}
919919
920920test "n_number_+1" {
921 err(
921 try err(
922922 \\[+1]
923923 );
924924}
925925
926926test "n_number_.2e-3" {
927 err(
927 try err(
928928 \\[.2e-3]
929929 );
930930}
931931
932932test "n_number_2.e-3" {
933 err(
933 try err(
934934 \\[2.e-3]
935935 );
936936}
937937
938938test "n_number_2.e+3" {
939 err(
939 try err(
940940 \\[2.e+3]
941941 );
942942}
943943
944944test "n_number_2.e3" {
945 err(
945 try err(
946946 \\[2.e3]
947947 );
948948}
949949
950950test "n_number_-2." {
951 err(
951 try err(
952952 \\[-2.]
953953 );
954954}
955955
956956test "n_number_9.e+" {
957 err(
957 try err(
958958 \\[9.e+]
959959 );
960960}
961961
962962test "n_number_expression" {
963 err(
963 try err(
964964 \\[1+2]
965965 );
966966}
967967
968968test "n_number_hex_1_digit" {
969 err(
969 try err(
970970 \\[0x1]
971971 );
972972}
973973
974974test "n_number_hex_2_digits" {
975 err(
975 try err(
976976 \\[0x42]
977977 );
978978}
979979
980980test "n_number_infinity" {
981 err(
981 try err(
982982 \\[Infinity]
983983 );
984984}
985985
986986test "n_number_+Inf" {
987 err(
987 try err(
988988 \\[+Inf]
989989 );
990990}
991991
992992test "n_number_Inf" {
993 err(
993 try err(
994994 \\[Inf]
995995 );
996996}
997997
998998test "n_number_invalid+-" {
999 err(
999 try err(
10001000 \\[0e+-1]
10011001 );
10021002}
10031003
10041004test "n_number_invalid-negative-real" {
1005 err(
1005 try err(
10061006 \\[-123.123foo]
10071007 );
10081008}
10091009
10101010test "n_number_invalid-utf-8-in-bigger-int" {
1011 err(
1011 try err(
10121012 \\[123å]
10131013 );
10141014}
10151015
10161016test "n_number_invalid-utf-8-in-exponent" {
1017 err(
1017 try err(
10181018 \\[1e1å]
10191019 );
10201020}
10211021
10221022test "n_number_invalid-utf-8-in-int" {
1023 err(
1023 try err(
10241024 \\[0å]
10251025 );
10261026}
10271027
10281028test "n_number_++" {
1029 err(
1029 try err(
10301030 \\[++1234]
10311031 );
10321032}
10331033
10341034test "n_number_minus_infinity" {
1035 err(
1035 try err(
10361036 \\[-Infinity]
10371037 );
10381038}
10391039
10401040test "n_number_minus_sign_with_trailing_garbage" {
1041 err(
1041 try err(
10421042 \\[-foo]
10431043 );
10441044}
10451045
10461046test "n_number_minus_space_1" {
1047 err(
1047 try err(
10481048 \\[- 1]
10491049 );
10501050}
10511051
10521052test "n_number_-NaN" {
1053 err(
1053 try err(
10541054 \\[-NaN]
10551055 );
10561056}
10571057
10581058test "n_number_NaN" {
1059 err(
1059 try err(
10601060 \\[NaN]
10611061 );
10621062}
10631063
10641064test "n_number_neg_int_starting_with_zero" {
1065 err(
1065 try err(
10661066 \\[-012]
10671067 );
10681068}
10691069
10701070test "n_number_neg_real_without_int_part" {
1071 err(
1071 try err(
10721072 \\[-.123]
10731073 );
10741074}
10751075
10761076test "n_number_neg_with_garbage_at_end" {
1077 err(
1077 try err(
10781078 \\[-1x]
10791079 );
10801080}
10811081
10821082test "n_number_real_garbage_after_e" {
1083 err(
1083 try err(
10841084 \\[1ea]
10851085 );
10861086}
10871087
10881088test "n_number_real_with_invalid_utf8_after_e" {
1089 err(
1089 try err(
10901090 \\[1eå]
10911091 );
10921092}
10931093
10941094test "n_number_real_without_fractional_part" {
1095 err(
1095 try err(
10961096 \\[1.]
10971097 );
10981098}
10991099
11001100test "n_number_starting_with_dot" {
1101 err(
1101 try err(
11021102 \\[.123]
11031103 );
11041104}
11051105
11061106test "n_number_U+FF11_fullwidth_digit_one" {
1107 err(
1107 try err(
11081108 \\[1]
11091109 );
11101110}
11111111
11121112test "n_number_with_alpha_char" {
1113 err(
1113 try err(
11141114 \\[1.8011670033376514H-308]
11151115 );
11161116}
11171117
11181118test "n_number_with_alpha" {
1119 err(
1119 try err(
11201120 \\[1.2a-3]
11211121 );
11221122}
11231123
11241124test "n_number_with_leading_zero" {
1125 err(
1125 try err(
11261126 \\[012]
11271127 );
11281128}
11291129
11301130test "n_object_bad_value" {
1131 err(
1131 try err(
11321132 \\["x", truth]
11331133 );
11341134}
11351135
11361136test "n_object_bracket_key" {
1137 err(
1137 try err(
11381138 \\{[: "x"}
11391139 );
11401140}
11411141
11421142test "n_object_comma_instead_of_colon" {
1143 err(
1143 try err(
11441144 \\{"x", null}
11451145 );
11461146}
11471147
11481148test "n_object_double_colon" {
1149 err(
1149 try err(
11501150 \\{"x"::"b"}
11511151 );
11521152}
11531153
11541154test "n_object_emoji" {
1155 err(
1155 try err(
11561156 \\{🇨🇭}
11571157 );
11581158}
11591159
11601160test "n_object_garbage_at_end" {
1161 err(
1161 try err(
11621162 \\{"a":"a" 123}
11631163 );
11641164}
11651165
11661166test "n_object_key_with_single_quotes" {
1167 err(
1167 try err(
11681168 \\{key: 'value'}
11691169 );
11701170}
11711171
11721172test "n_object_lone_continuation_byte_in_key_and_trailing_comma" {
1173 err(
1173 try err(
11741174 \\{"¹":"0",}
11751175 );
11761176}
11771177
11781178test "n_object_missing_colon" {
1179 err(
1179 try err(
11801180 \\{"a" b}
11811181 );
11821182}
11831183
11841184test "n_object_missing_key" {
1185 err(
1185 try err(
11861186 \\{:"b"}
11871187 );
11881188}
11891189
11901190test "n_object_missing_semicolon" {
1191 err(
1191 try err(
11921192 \\{"a" "b"}
11931193 );
11941194}
11951195
11961196test "n_object_missing_value" {
1197 err(
1197 try err(
11981198 \\{"a":
11991199 );
12001200}
12011201
12021202test "n_object_no-colon" {
1203 err(
1203 try err(
12041204 \\{"a"
12051205 );
12061206}
12071207
12081208test "n_object_non_string_key_but_huge_number_instead" {
1209 err(
1209 try err(
12101210 \\{9999E9999:1}
12111211 );
12121212}
12131213
12141214test "n_object_non_string_key" {
1215 err(
1215 try err(
12161216 \\{1:1}
12171217 );
12181218}
12191219
12201220test "n_object_repeated_null_null" {
1221 err(
1221 try err(
12221222 \\{null:null,null:null}
12231223 );
12241224}
12251225
12261226test "n_object_several_trailing_commas" {
1227 err(
1227 try err(
12281228 \\{"id":0,,,,,}
12291229 );
12301230}
12311231
12321232test "n_object_single_quote" {
1233 err(
1233 try err(
12341234 \\{'a':0}
12351235 );
12361236}
12371237
12381238test "n_object_trailing_comma" {
1239 err(
1239 try err(
12401240 \\{"id":0,}
12411241 );
12421242}
12431243
12441244test "n_object_trailing_comment" {
1245 err(
1245 try err(
12461246 \\{"a":"b"}/**/
12471247 );
12481248}
12491249
12501250test "n_object_trailing_comment_open" {
1251 err(
1251 try err(
12521252 \\{"a":"b"}/**//
12531253 );
12541254}
12551255
12561256test "n_object_trailing_comment_slash_open_incomplete" {
1257 err(
1257 try err(
12581258 \\{"a":"b"}/
12591259 );
12601260}
12611261
12621262test "n_object_trailing_comment_slash_open" {
1263 err(
1263 try err(
12641264 \\{"a":"b"}//
12651265 );
12661266}
12671267
12681268test "n_object_two_commas_in_a_row" {
1269 err(
1269 try err(
12701270 \\{"a":"b",,"c":"d"}
12711271 );
12721272}
12731273
12741274test "n_object_unquoted_key" {
1275 err(
1275 try err(
12761276 \\{a: "b"}
12771277 );
12781278}
12791279
12801280test "n_object_unterminated-value" {
1281 err(
1281 try err(
12821282 \\{"a":"a
12831283 );
12841284}
12851285
12861286test "n_object_with_single_string" {
1287 err(
1287 try err(
12881288 \\{ "foo" : "bar", "a" }
12891289 );
12901290}
12911291
12921292test "n_object_with_trailing_garbage" {
1293 err(
1293 try err(
12941294 \\{"a":"b"}#
12951295 );
12961296}
12971297
12981298test "n_single_space" {
1299 err(" ");
1299 try err(" ");
13001300}
13011301
13021302test "n_string_1_surrogate_then_escape" {
1303 err(
1303 try err(
13041304 \\["\uD800\"]
13051305 );
13061306}
13071307
13081308test "n_string_1_surrogate_then_escape_u1" {
1309 err(
1309 try err(
13101310 \\["\uD800\u1"]
13111311 );
13121312}
13131313
13141314test "n_string_1_surrogate_then_escape_u1x" {
1315 err(
1315 try err(
13161316 \\["\uD800\u1x"]
13171317 );
13181318}
13191319
13201320test "n_string_1_surrogate_then_escape_u" {
1321 err(
1321 try err(
13221322 \\["\uD800\u"]
13231323 );
13241324}
13251325
13261326test "n_string_accentuated_char_no_quotes" {
1327 err(
1327 try err(
13281328 \\[é]
13291329 );
13301330}
13311331
13321332test "n_string_backslash_00" {
1333 err("[\"\x00\"]");
1333 try err("[\"\x00\"]");
13341334}
13351335
13361336test "n_string_escaped_backslash_bad" {
1337 err(
1337 try err(
13381338 \\["\\\"]
13391339 );
13401340}
13411341
13421342test "n_string_escaped_ctrl_char_tab" {
1343 err("\x5b\x22\x5c\x09\x22\x5d");
1343 try err("\x5b\x22\x5c\x09\x22\x5d");
13441344}
13451345
13461346test "n_string_escaped_emoji" {
1347 err("[\"\x5c\xc3\xb0\xc2\x9f\xc2\x8c\xc2\x80\"]");
1347 try err("[\"\x5c\xc3\xb0\xc2\x9f\xc2\x8c\xc2\x80\"]");
13481348}
13491349
13501350test "n_string_escape_x" {
1351 err(
1351 try err(
13521352 \\["\x00"]
13531353 );
13541354}
13551355
13561356test "n_string_incomplete_escaped_character" {
1357 err(
1357 try err(
13581358 \\["\u00A"]
13591359 );
13601360}
13611361
13621362test "n_string_incomplete_escape" {
1363 err(
1363 try err(
13641364 \\["\"]
13651365 );
13661366}
13671367
13681368test "n_string_incomplete_surrogate_escape_invalid" {
1369 err(
1369 try err(
13701370 \\["\uD800\uD800\x"]
13711371 );
13721372}
13731373
13741374test "n_string_incomplete_surrogate" {
1375 err(
1375 try err(
13761376 \\["\uD834\uDd"]
13771377 );
13781378}
13791379
13801380test "n_string_invalid_backslash_esc" {
1381 err(
1381 try err(
13821382 \\["\a"]
13831383 );
13841384}
13851385
13861386test "n_string_invalid_unicode_escape" {
1387 err(
1387 try err(
13881388 \\["\uqqqq"]
13891389 );
13901390}
13911391
13921392test "n_string_invalid_utf8_after_escape" {
1393 err("[\"\\\x75\xc3\xa5\"]");
1393 try err("[\"\\\x75\xc3\xa5\"]");
13941394}
13951395
13961396test "n_string_invalid-utf-8-in-escape" {
1397 err(
1397 try err(
13981398 \\["\uå"]
13991399 );
14001400}
14011401
14021402test "n_string_leading_uescaped_thinspace" {
1403 err(
1403 try err(
14041404 \\[\u0020"asd"]
14051405 );
14061406}
14071407
14081408test "n_string_no_quotes_with_bad_escape" {
1409 err(
1409 try err(
14101410 \\[\n]
14111411 );
14121412}
14131413
14141414test "n_string_single_doublequote" {
1415 err(
1415 try err(
14161416 \\"
14171417 );
14181418}
14191419
14201420test "n_string_single_quote" {
1421 err(
1421 try err(
14221422 \\['single quote']
14231423 );
14241424}
14251425
14261426test "n_string_single_string_no_double_quotes" {
1427 err(
1427 try err(
14281428 \\abc
14291429 );
14301430}
14311431
14321432test "n_string_start_escape_unclosed" {
1433 err(
1433 try err(
14341434 \\["\
14351435 );
14361436}
14371437
14381438test "n_string_unescaped_crtl_char" {
1439 err("[\"a\x00a\"]");
1439 try err("[\"a\x00a\"]");
14401440}
14411441
14421442test "n_string_unescaped_newline" {
1443 err(
1443 try err(
14441444 \\["new
14451445 \\line"]
14461446 );
14471447}
14481448
14491449test "n_string_unescaped_tab" {
1450 err("[\"\t\"]");
1450 try err("[\"\t\"]");
14511451}
14521452
14531453test "n_string_unicode_CapitalU" {
1454 err(
1454 try err(
14551455 \\"\UA66D"
14561456 );
14571457}
14581458
14591459test "n_string_with_trailing_garbage" {
1460 err(
1460 try err(
14611461 \\""x
14621462 );
14631463}
14641464
14651465test "n_structure_100000_opening_arrays" {
1466 err("[" ** 100000);
1466 try err("[" ** 100000);
14671467}
14681468
14691469test "n_structure_angle_bracket_." {
1470 err(
1470 try err(
14711471 \\<.>
14721472 );
14731473}
14741474
14751475test "n_structure_angle_bracket_null" {
1476 err(
1476 try err(
14771477 \\[<null>]
14781478 );
14791479}
14801480
14811481test "n_structure_array_trailing_garbage" {
1482 err(
1482 try err(
14831483 \\[1]x
14841484 );
14851485}
14861486
14871487test "n_structure_array_with_extra_array_close" {
1488 err(
1488 try err(
14891489 \\[1]]
14901490 );
14911491}
14921492
14931493test "n_structure_array_with_unclosed_string" {
1494 err(
1494 try err(
14951495 \\["asd]
14961496 );
14971497}
14981498
14991499test "n_structure_ascii-unicode-identifier" {
1500 err(
1500 try err(
15011501 \\aå
15021502 );
15031503}
15041504
15051505test "n_structure_capitalized_True" {
1506 err(
1506 try err(
15071507 \\[True]
15081508 );
15091509}
15101510
15111511test "n_structure_close_unopened_array" {
1512 err(
1512 try err(
15131513 \\1]
15141514 );
15151515}
15161516
15171517test "n_structure_comma_instead_of_closing_brace" {
1518 err(
1518 try err(
15191519 \\{"x": true,
15201520 );
15211521}
15221522
15231523test "n_structure_double_array" {
1524 err(
1524 try err(
15251525 \\[][]
15261526 );
15271527}
15281528
15291529test "n_structure_end_array" {
1530 err(
1530 try err(
15311531 \\]
15321532 );
15331533}
15341534
15351535test "n_structure_incomplete_UTF8_BOM" {
1536 err(
1536 try err(
15371537 \\ï»{}
15381538 );
15391539}
15401540
15411541test "n_structure_lone-invalid-utf-8" {
1542 err(
1542 try err(
15431543 \\å
15441544 );
15451545}
15461546
15471547test "n_structure_lone-open-bracket" {
1548 err(
1548 try err(
15491549 \\[
15501550 );
15511551}
15521552
15531553test "n_structure_no_data" {
1554 err(
1554 try err(
15551555 \\
15561556 );
15571557}
15581558
15591559test "n_structure_null-byte-outside-string" {
1560 err("[\x00]");
1560 try err("[\x00]");
15611561}
15621562
15631563test "n_structure_number_with_trailing_garbage" {
1564 err(
1564 try err(
15651565 \\2@
15661566 );
15671567}
15681568
15691569test "n_structure_object_followed_by_closing_object" {
1570 err(
1570 try err(
15711571 \\{}}
15721572 );
15731573}
15741574
15751575test "n_structure_object_unclosed_no_value" {
1576 err(
1576 try err(
15771577 \\{"":
15781578 );
15791579}
15801580
15811581test "n_structure_object_with_comment" {
1582 err(
1582 try err(
15831583 \\{"a":/*comment*/"b"}
15841584 );
15851585}
15861586
15871587test "n_structure_object_with_trailing_garbage" {
1588 err(
1588 try err(
15891589 \\{"a": true} "x"
15901590 );
15911591}
15921592
15931593test "n_structure_open_array_apostrophe" {
1594 err(
1594 try err(
15951595 \\['
15961596 );
15971597}
15981598
15991599test "n_structure_open_array_comma" {
1600 err(
1600 try err(
16011601 \\[,
16021602 );
16031603}
16041604
16051605test "n_structure_open_array_object" {
1606 err("[{\"\":" ** 50000);
1606 try err("[{\"\":" ** 50000);
16071607}
16081608
16091609test "n_structure_open_array_open_object" {
1610 err(
1610 try err(
16111611 \\[{
16121612 );
16131613}
16141614
16151615test "n_structure_open_array_open_string" {
1616 err(
1616 try err(
16171617 \\["a
16181618 );
16191619}
16201620
16211621test "n_structure_open_array_string" {
1622 err(
1622 try err(
16231623 \\["a"
16241624 );
16251625}
16261626
16271627test "n_structure_open_object_close_array" {
1628 err(
1628 try err(
16291629 \\{]
16301630 );
16311631}
16321632
16331633test "n_structure_open_object_comma" {
1634 err(
1634 try err(
16351635 \\{,
16361636 );
16371637}
16381638
16391639test "n_structure_open_object" {
1640 err(
1640 try err(
16411641 \\{
16421642 );
16431643}
16441644
16451645test "n_structure_open_object_open_array" {
1646 err(
1646 try err(
16471647 \\{[
16481648 );
16491649}
16501650
16511651test "n_structure_open_object_open_string" {
1652 err(
1652 try err(
16531653 \\{"a
16541654 );
16551655}
16561656
16571657test "n_structure_open_object_string_with_apostrophes" {
1658 err(
1658 try err(
16591659 \\{'a'
16601660 );
16611661}
16621662
16631663test "n_structure_open_open" {
1664 err(
1664 try err(
16651665 \\["\{["\{["\{["\{
16661666 );
16671667}
16681668
16691669test "n_structure_single_eacute" {
1670 err(
1670 try err(
16711671 \\é
16721672 );
16731673}
16741674
16751675test "n_structure_single_star" {
1676 err(
1676 try err(
16771677 \\*
16781678 );
16791679}
16801680
16811681test "n_structure_trailing_#" {
1682 err(
1682 try err(
16831683 \\{"a":"b"}#{}
16841684 );
16851685}
16861686
16871687test "n_structure_U+2060_word_joined" {
1688 err(
1688 try err(
16891689 \\[⁠]
16901690 );
16911691}
16921692
16931693test "n_structure_uescaped_LF_before_string" {
1694 err(
1694 try err(
16951695 \\[\u000A""]
16961696 );
16971697}
16981698
16991699test "n_structure_unclosed_array" {
1700 err(
1700 try err(
17011701 \\[1
17021702 );
17031703}
17041704
17051705test "n_structure_unclosed_array_partial_null" {
1706 err(
1706 try err(
17071707 \\[ false, nul
17081708 );
17091709}
17101710
17111711test "n_structure_unclosed_array_unfinished_false" {
1712 err(
1712 try err(
17131713 \\[ true, fals
17141714 );
17151715}
17161716
17171717test "n_structure_unclosed_array_unfinished_true" {
1718 err(
1718 try err(
17191719 \\[ false, tru
17201720 );
17211721}
17221722
17231723test "n_structure_unclosed_object" {
1724 err(
1724 try err(
17251725 \\{"asd":"asd"
17261726 );
17271727}
17281728
17291729test "n_structure_unicode-identifier" {
1730 err(
1730 try err(
17311731 \\Ã¥
17321732 );
17331733}
17341734
17351735test "n_structure_UTF8_BOM_no_data" {
1736 err(
1736 try err(
17371737 \\
17381738 );
17391739}
17401740
17411741test "n_structure_whitespace_formfeed" {
1742 err("[\x0c]");
1742 try err("[\x0c]");
17431743}
17441744
17451745test "n_structure_whitespace_U+2060_word_joiner" {
1746 err(
1746 try err(
17471747 \\[⁠]
17481748 );
17491749}
......@@ -1751,255 +1751,255 @@ test "n_structure_whitespace_U+2060_word_joiner" {
17511751////////////////////////////////////////////////////////////////////////////////////////////////////
17521752
17531753test "i_number_double_huge_neg_exp" {
1754 any(
1754 try any(
17551755 \\[123.456e-789]
17561756 );
17571757}
17581758
17591759test "i_number_huge_exp" {
1760 any(
1760 try any(
17611761 \\[0.4e00669999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999969999999006]
17621762 );
17631763}
17641764
17651765test "i_number_neg_int_huge_exp" {
1766 any(
1766 try any(
17671767 \\[-1e+9999]
17681768 );
17691769}
17701770
17711771test "i_number_pos_double_huge_exp" {
1772 any(
1772 try any(
17731773 \\[1.5e+9999]
17741774 );
17751775}
17761776
17771777test "i_number_real_neg_overflow" {
1778 any(
1778 try any(
17791779 \\[-123123e100000]
17801780 );
17811781}
17821782
17831783test "i_number_real_pos_overflow" {
1784 any(
1784 try any(
17851785 \\[123123e100000]
17861786 );
17871787}
17881788
17891789test "i_number_real_underflow" {
1790 any(
1790 try any(
17911791 \\[123e-10000000]
17921792 );
17931793}
17941794
17951795test "i_number_too_big_neg_int" {
1796 any(
1796 try any(
17971797 \\[-123123123123123123123123123123]
17981798 );
17991799}
18001800
18011801test "i_number_too_big_pos_int" {
1802 any(
1802 try any(
18031803 \\[100000000000000000000]
18041804 );
18051805}
18061806
18071807test "i_number_very_big_negative_int" {
1808 any(
1808 try any(
18091809 \\[-237462374673276894279832749832423479823246327846]
18101810 );
18111811}
18121812
18131813test "i_object_key_lone_2nd_surrogate" {
1814 anyStreamingErrNonStreaming(
1814 try anyStreamingErrNonStreaming(
18151815 \\{"\uDFAA":0}
18161816 );
18171817}
18181818
18191819test "i_string_1st_surrogate_but_2nd_missing" {
1820 anyStreamingErrNonStreaming(
1820 try anyStreamingErrNonStreaming(
18211821 \\["\uDADA"]
18221822 );
18231823}
18241824
18251825test "i_string_1st_valid_surrogate_2nd_invalid" {
1826 anyStreamingErrNonStreaming(
1826 try anyStreamingErrNonStreaming(
18271827 \\["\uD888\u1234"]
18281828 );
18291829}
18301830
18311831test "i_string_incomplete_surrogate_and_escape_valid" {
1832 anyStreamingErrNonStreaming(
1832 try anyStreamingErrNonStreaming(
18331833 \\["\uD800\n"]
18341834 );
18351835}
18361836
18371837test "i_string_incomplete_surrogate_pair" {
1838 anyStreamingErrNonStreaming(
1838 try anyStreamingErrNonStreaming(
18391839 \\["\uDd1ea"]
18401840 );
18411841}
18421842
18431843test "i_string_incomplete_surrogates_escape_valid" {
1844 anyStreamingErrNonStreaming(
1844 try anyStreamingErrNonStreaming(
18451845 \\["\uD800\uD800\n"]
18461846 );
18471847}
18481848
18491849test "i_string_invalid_lonely_surrogate" {
1850 anyStreamingErrNonStreaming(
1850 try anyStreamingErrNonStreaming(
18511851 \\["\ud800"]
18521852 );
18531853}
18541854
18551855test "i_string_invalid_surrogate" {
1856 anyStreamingErrNonStreaming(
1856 try anyStreamingErrNonStreaming(
18571857 \\["\ud800abc"]
18581858 );
18591859}
18601860
18611861test "i_string_invalid_utf-8" {
1862 any(
1862 try any(
18631863 \\["ÿ"]
18641864 );
18651865}
18661866
18671867test "i_string_inverted_surrogates_U+1D11E" {
1868 anyStreamingErrNonStreaming(
1868 try anyStreamingErrNonStreaming(
18691869 \\["\uDd1e\uD834"]
18701870 );
18711871}
18721872
18731873test "i_string_iso_latin_1" {
1874 any(
1874 try any(
18751875 \\["é"]
18761876 );
18771877}
18781878
18791879test "i_string_lone_second_surrogate" {
1880 anyStreamingErrNonStreaming(
1880 try anyStreamingErrNonStreaming(
18811881 \\["\uDFAA"]
18821882 );
18831883}
18841884
18851885test "i_string_lone_utf8_continuation_byte" {
1886 any(
1886 try any(
18871887 \\[""]
18881888 );
18891889}
18901890
18911891test "i_string_not_in_unicode_range" {
1892 any(
1892 try any(
18931893 \\["ô¿¿¿"]
18941894 );
18951895}
18961896
18971897test "i_string_overlong_sequence_2_bytes" {
1898 any(
1898 try any(
18991899 \\["À¯"]
19001900 );
19011901}
19021902
19031903test "i_string_overlong_sequence_6_bytes" {
1904 any(
1904 try any(
19051905 \\["üƒ¿¿¿¿"]
19061906 );
19071907}
19081908
19091909test "i_string_overlong_sequence_6_bytes_null" {
1910 any(
1910 try any(
19111911 \\["ü€€€€€"]
19121912 );
19131913}
19141914
19151915test "i_string_truncated-utf-8" {
1916 any(
1916 try any(
19171917 \\["àÿ"]
19181918 );
19191919}
19201920
19211921test "i_string_utf16BE_no_BOM" {
1922 any("\x00\x5b\x00\x22\x00\xc3\xa9\x00\x22\x00\x5d");
1922 try any("\x00\x5b\x00\x22\x00\xc3\xa9\x00\x22\x00\x5d");
19231923}
19241924
19251925test "i_string_utf16LE_no_BOM" {
1926 any("\x5b\x00\x22\x00\xc3\xa9\x00\x22\x00\x5d\x00");
1926 try any("\x5b\x00\x22\x00\xc3\xa9\x00\x22\x00\x5d\x00");
19271927}
19281928
19291929test "i_string_UTF-16LE_with_BOM" {
1930 any("\xc3\xbf\xc3\xbe\x5b\x00\x22\x00\xc3\xa9\x00\x22\x00\x5d\x00");
1930 try any("\xc3\xbf\xc3\xbe\x5b\x00\x22\x00\xc3\xa9\x00\x22\x00\x5d\x00");
19311931}
19321932
19331933test "i_string_UTF-8_invalid_sequence" {
1934 any(
1934 try any(
19351935 \\["日шú"]
19361936 );
19371937}
19381938
19391939test "i_string_UTF8_surrogate_U+D800" {
1940 any(
1940 try any(
19411941 \\["í €"]
19421942 );
19431943}
19441944
19451945test "i_structure_500_nested_arrays" {
1946 any(("[" ** 500) ++ ("]" ** 500));
1946 try any(("[" ** 500) ++ ("]" ** 500));
19471947}
19481948
19491949test "i_structure_UTF-8_BOM_empty_object" {
1950 any(
1950 try any(
19511951 \\{}
19521952 );
19531953}
19541954
19551955test "truncated UTF-8 sequence" {
1956 utf8Error("\"\xc2\"");
1957 utf8Error("\"\xdf\"");
1958 utf8Error("\"\xed\xa0\"");
1959 utf8Error("\"\xf0\x80\"");
1960 utf8Error("\"\xf0\x80\x80\"");
1956 try utf8Error("\"\xc2\"");
1957 try utf8Error("\"\xdf\"");
1958 try utf8Error("\"\xed\xa0\"");
1959 try utf8Error("\"\xf0\x80\"");
1960 try utf8Error("\"\xf0\x80\x80\"");
19611961}
19621962
19631963test "invalid continuation byte" {
1964 utf8Error("\"\xc2\x00\"");
1965 utf8Error("\"\xc2\x7f\"");
1966 utf8Error("\"\xc2\xc0\"");
1967 utf8Error("\"\xc3\xc1\"");
1968 utf8Error("\"\xc4\xf5\"");
1969 utf8Error("\"\xc5\xff\"");
1970 utf8Error("\"\xe4\x80\x00\"");
1971 utf8Error("\"\xe5\x80\x10\"");
1972 utf8Error("\"\xe6\x80\xc0\"");
1973 utf8Error("\"\xe7\x80\xf5\"");
1974 utf8Error("\"\xe8\x00\x80\"");
1975 utf8Error("\"\xf2\x00\x80\x80\"");
1976 utf8Error("\"\xf0\x80\x00\x80\"");
1977 utf8Error("\"\xf1\x80\xc0\x80\"");
1978 utf8Error("\"\xf2\x80\x80\x00\"");
1979 utf8Error("\"\xf3\x80\x80\xc0\"");
1980 utf8Error("\"\xf4\x80\x80\xf5\"");
1964 try utf8Error("\"\xc2\x00\"");
1965 try utf8Error("\"\xc2\x7f\"");
1966 try utf8Error("\"\xc2\xc0\"");
1967 try utf8Error("\"\xc3\xc1\"");
1968 try utf8Error("\"\xc4\xf5\"");
1969 try utf8Error("\"\xc5\xff\"");
1970 try utf8Error("\"\xe4\x80\x00\"");
1971 try utf8Error("\"\xe5\x80\x10\"");
1972 try utf8Error("\"\xe6\x80\xc0\"");
1973 try utf8Error("\"\xe7\x80\xf5\"");
1974 try utf8Error("\"\xe8\x00\x80\"");
1975 try utf8Error("\"\xf2\x00\x80\x80\"");
1976 try utf8Error("\"\xf0\x80\x00\x80\"");
1977 try utf8Error("\"\xf1\x80\xc0\x80\"");
1978 try utf8Error("\"\xf2\x80\x80\x00\"");
1979 try utf8Error("\"\xf3\x80\x80\xc0\"");
1980 try utf8Error("\"\xf4\x80\x80\xf5\"");
19811981}
19821982
19831983test "disallowed overlong form" {
1984 utf8Error("\"\xc0\x80\"");
1985 utf8Error("\"\xc0\x90\"");
1986 utf8Error("\"\xc1\x80\"");
1987 utf8Error("\"\xc1\x90\"");
1988 utf8Error("\"\xe0\x80\x80\"");
1989 utf8Error("\"\xf0\x80\x80\x80\"");
1984 try utf8Error("\"\xc0\x80\"");
1985 try utf8Error("\"\xc0\x90\"");
1986 try utf8Error("\"\xc1\x80\"");
1987 try utf8Error("\"\xc1\x90\"");
1988 try utf8Error("\"\xe0\x80\x80\"");
1989 try utf8Error("\"\xf0\x80\x80\x80\"");
19901990}
19911991
19921992test "out of UTF-16 range" {
1993 utf8Error("\"\xf4\x90\x80\x80\"");
1994 utf8Error("\"\xf5\x80\x80\x80\"");
1995 utf8Error("\"\xf6\x80\x80\x80\"");
1996 utf8Error("\"\xf7\x80\x80\x80\"");
1997 utf8Error("\"\xf8\x80\x80\x80\"");
1998 utf8Error("\"\xf9\x80\x80\x80\"");
1999 utf8Error("\"\xfa\x80\x80\x80\"");
2000 utf8Error("\"\xfb\x80\x80\x80\"");
2001 utf8Error("\"\xfc\x80\x80\x80\"");
2002 utf8Error("\"\xfd\x80\x80\x80\"");
2003 utf8Error("\"\xfe\x80\x80\x80\"");
2004 utf8Error("\"\xff\x80\x80\x80\"");
1993 try utf8Error("\"\xf4\x90\x80\x80\"");
1994 try utf8Error("\"\xf5\x80\x80\x80\"");
1995 try utf8Error("\"\xf6\x80\x80\x80\"");
1996 try utf8Error("\"\xf7\x80\x80\x80\"");
1997 try utf8Error("\"\xf8\x80\x80\x80\"");
1998 try utf8Error("\"\xf9\x80\x80\x80\"");
1999 try utf8Error("\"\xfa\x80\x80\x80\"");
2000 try utf8Error("\"\xfb\x80\x80\x80\"");
2001 try utf8Error("\"\xfc\x80\x80\x80\"");
2002 try utf8Error("\"\xfd\x80\x80\x80\"");
2003 try utf8Error("\"\xfe\x80\x80\x80\"");
2004 try utf8Error("\"\xff\x80\x80\x80\"");
20052005}
lib/std/json/write_stream.zig+1-1
......@@ -288,7 +288,7 @@ test "json write stream" {
288288 \\ "float": 3.5e+00
289289 \\}
290290 ;
291 std.testing.expect(std.mem.eql(u8, expected, result));
291 try std.testing.expect(std.mem.eql(u8, expected, result));
292292}
293293
294294fn getJsonObject(allocator: *std.mem.Allocator) !std.json.Value {
lib/std/leb128.zig+68-68
......@@ -152,22 +152,22 @@ test "writeUnsignedFixed" {
152152 {
153153 var buf: [4]u8 = undefined;
154154 writeUnsignedFixed(4, &buf, 0);
155 testing.expect((try test_read_uleb128(u64, &buf)) == 0);
155 try testing.expect((try test_read_uleb128(u64, &buf)) == 0);
156156 }
157157 {
158158 var buf: [4]u8 = undefined;
159159 writeUnsignedFixed(4, &buf, 1);
160 testing.expect((try test_read_uleb128(u64, &buf)) == 1);
160 try testing.expect((try test_read_uleb128(u64, &buf)) == 1);
161161 }
162162 {
163163 var buf: [4]u8 = undefined;
164164 writeUnsignedFixed(4, &buf, 1000);
165 testing.expect((try test_read_uleb128(u64, &buf)) == 1000);
165 try testing.expect((try test_read_uleb128(u64, &buf)) == 1000);
166166 }
167167 {
168168 var buf: [4]u8 = undefined;
169169 writeUnsignedFixed(4, &buf, 10000000);
170 testing.expect((try test_read_uleb128(u64, &buf)) == 10000000);
170 try testing.expect((try test_read_uleb128(u64, &buf)) == 10000000);
171171 }
172172}
173173
......@@ -212,44 +212,44 @@ fn test_read_uleb128_seq(comptime T: type, comptime N: usize, encoded: []const u
212212
213213test "deserialize signed LEB128" {
214214 // Truncated
215 testing.expectError(error.EndOfStream, test_read_stream_ileb128(i64, "\x80"));
215 try testing.expectError(error.EndOfStream, test_read_stream_ileb128(i64, "\x80"));
216216
217217 // Overflow
218 testing.expectError(error.Overflow, test_read_ileb128(i8, "\x80\x80\x40"));
219 testing.expectError(error.Overflow, test_read_ileb128(i16, "\x80\x80\x80\x40"));
220 testing.expectError(error.Overflow, test_read_ileb128(i32, "\x80\x80\x80\x80\x40"));
221 testing.expectError(error.Overflow, test_read_ileb128(i64, "\x80\x80\x80\x80\x80\x80\x80\x80\x80\x40"));
222 testing.expectError(error.Overflow, test_read_ileb128(i8, "\xff\x7e"));
218 try testing.expectError(error.Overflow, test_read_ileb128(i8, "\x80\x80\x40"));
219 try testing.expectError(error.Overflow, test_read_ileb128(i16, "\x80\x80\x80\x40"));
220 try testing.expectError(error.Overflow, test_read_ileb128(i32, "\x80\x80\x80\x80\x40"));
221 try testing.expectError(error.Overflow, test_read_ileb128(i64, "\x80\x80\x80\x80\x80\x80\x80\x80\x80\x40"));
222 try testing.expectError(error.Overflow, test_read_ileb128(i8, "\xff\x7e"));
223223
224224 // Decode SLEB128
225 testing.expect((try test_read_ileb128(i64, "\x00")) == 0);
226 testing.expect((try test_read_ileb128(i64, "\x01")) == 1);
227 testing.expect((try test_read_ileb128(i64, "\x3f")) == 63);
228 testing.expect((try test_read_ileb128(i64, "\x40")) == -64);
229 testing.expect((try test_read_ileb128(i64, "\x41")) == -63);
230 testing.expect((try test_read_ileb128(i64, "\x7f")) == -1);
231 testing.expect((try test_read_ileb128(i64, "\x80\x01")) == 128);
232 testing.expect((try test_read_ileb128(i64, "\x81\x01")) == 129);
233 testing.expect((try test_read_ileb128(i64, "\xff\x7e")) == -129);
234 testing.expect((try test_read_ileb128(i64, "\x80\x7f")) == -128);
235 testing.expect((try test_read_ileb128(i64, "\x81\x7f")) == -127);
236 testing.expect((try test_read_ileb128(i64, "\xc0\x00")) == 64);
237 testing.expect((try test_read_ileb128(i64, "\xc7\x9f\x7f")) == -12345);
238 testing.expect((try test_read_ileb128(i8, "\xff\x7f")) == -1);
239 testing.expect((try test_read_ileb128(i16, "\xff\xff\x7f")) == -1);
240 testing.expect((try test_read_ileb128(i32, "\xff\xff\xff\xff\x7f")) == -1);
241 testing.expect((try test_read_ileb128(i32, "\x80\x80\x80\x80\x08")) == -0x80000000);
242 testing.expect((try test_read_ileb128(i64, "\x80\x80\x80\x80\x80\x80\x80\x80\x80\x01")) == @bitCast(i64, @intCast(u64, 0x8000000000000000)));
243 testing.expect((try test_read_ileb128(i64, "\x80\x80\x80\x80\x80\x80\x80\x80\x40")) == -0x4000000000000000);
244 testing.expect((try test_read_ileb128(i64, "\x80\x80\x80\x80\x80\x80\x80\x80\x80\x7f")) == -0x8000000000000000);
225 try testing.expect((try test_read_ileb128(i64, "\x00")) == 0);
226 try testing.expect((try test_read_ileb128(i64, "\x01")) == 1);
227 try testing.expect((try test_read_ileb128(i64, "\x3f")) == 63);
228 try testing.expect((try test_read_ileb128(i64, "\x40")) == -64);
229 try testing.expect((try test_read_ileb128(i64, "\x41")) == -63);
230 try testing.expect((try test_read_ileb128(i64, "\x7f")) == -1);
231 try testing.expect((try test_read_ileb128(i64, "\x80\x01")) == 128);
232 try testing.expect((try test_read_ileb128(i64, "\x81\x01")) == 129);
233 try testing.expect((try test_read_ileb128(i64, "\xff\x7e")) == -129);
234 try testing.expect((try test_read_ileb128(i64, "\x80\x7f")) == -128);
235 try testing.expect((try test_read_ileb128(i64, "\x81\x7f")) == -127);
236 try testing.expect((try test_read_ileb128(i64, "\xc0\x00")) == 64);
237 try testing.expect((try test_read_ileb128(i64, "\xc7\x9f\x7f")) == -12345);
238 try testing.expect((try test_read_ileb128(i8, "\xff\x7f")) == -1);
239 try testing.expect((try test_read_ileb128(i16, "\xff\xff\x7f")) == -1);
240 try testing.expect((try test_read_ileb128(i32, "\xff\xff\xff\xff\x7f")) == -1);
241 try testing.expect((try test_read_ileb128(i32, "\x80\x80\x80\x80\x08")) == -0x80000000);
242 try testing.expect((try test_read_ileb128(i64, "\x80\x80\x80\x80\x80\x80\x80\x80\x80\x01")) == @bitCast(i64, @intCast(u64, 0x8000000000000000)));
243 try testing.expect((try test_read_ileb128(i64, "\x80\x80\x80\x80\x80\x80\x80\x80\x40")) == -0x4000000000000000);
244 try testing.expect((try test_read_ileb128(i64, "\x80\x80\x80\x80\x80\x80\x80\x80\x80\x7f")) == -0x8000000000000000);
245245
246246 // Decode unnormalized SLEB128 with extra padding bytes.
247 testing.expect((try test_read_ileb128(i64, "\x80\x00")) == 0);
248 testing.expect((try test_read_ileb128(i64, "\x80\x80\x00")) == 0);
249 testing.expect((try test_read_ileb128(i64, "\xff\x00")) == 0x7f);
250 testing.expect((try test_read_ileb128(i64, "\xff\x80\x00")) == 0x7f);
251 testing.expect((try test_read_ileb128(i64, "\x80\x81\x00")) == 0x80);
252 testing.expect((try test_read_ileb128(i64, "\x80\x81\x80\x00")) == 0x80);
247 try testing.expect((try test_read_ileb128(i64, "\x80\x00")) == 0);
248 try testing.expect((try test_read_ileb128(i64, "\x80\x80\x00")) == 0);
249 try testing.expect((try test_read_ileb128(i64, "\xff\x00")) == 0x7f);
250 try testing.expect((try test_read_ileb128(i64, "\xff\x80\x00")) == 0x7f);
251 try testing.expect((try test_read_ileb128(i64, "\x80\x81\x00")) == 0x80);
252 try testing.expect((try test_read_ileb128(i64, "\x80\x81\x80\x00")) == 0x80);
253253
254254 // Decode sequence of SLEB128 values
255255 try test_read_ileb128_seq(i64, 4, "\x81\x01\x3f\x80\x7f\x80\x80\x80\x00");
......@@ -257,39 +257,39 @@ test "deserialize signed LEB128" {
257257
258258test "deserialize unsigned LEB128" {
259259 // Truncated
260 testing.expectError(error.EndOfStream, test_read_stream_uleb128(u64, "\x80"));
260 try testing.expectError(error.EndOfStream, test_read_stream_uleb128(u64, "\x80"));
261261
262262 // Overflow
263 testing.expectError(error.Overflow, test_read_uleb128(u8, "\x80\x02"));
264 testing.expectError(error.Overflow, test_read_uleb128(u8, "\x80\x80\x40"));
265 testing.expectError(error.Overflow, test_read_uleb128(u16, "\x80\x80\x84"));
266 testing.expectError(error.Overflow, test_read_uleb128(u16, "\x80\x80\x80\x40"));
267 testing.expectError(error.Overflow, test_read_uleb128(u32, "\x80\x80\x80\x80\x90"));
268 testing.expectError(error.Overflow, test_read_uleb128(u32, "\x80\x80\x80\x80\x40"));
269 testing.expectError(error.Overflow, test_read_uleb128(u64, "\x80\x80\x80\x80\x80\x80\x80\x80\x80\x40"));
263 try testing.expectError(error.Overflow, test_read_uleb128(u8, "\x80\x02"));
264 try testing.expectError(error.Overflow, test_read_uleb128(u8, "\x80\x80\x40"));
265 try testing.expectError(error.Overflow, test_read_uleb128(u16, "\x80\x80\x84"));
266 try testing.expectError(error.Overflow, test_read_uleb128(u16, "\x80\x80\x80\x40"));
267 try testing.expectError(error.Overflow, test_read_uleb128(u32, "\x80\x80\x80\x80\x90"));
268 try testing.expectError(error.Overflow, test_read_uleb128(u32, "\x80\x80\x80\x80\x40"));
269 try testing.expectError(error.Overflow, test_read_uleb128(u64, "\x80\x80\x80\x80\x80\x80\x80\x80\x80\x40"));
270270
271271 // Decode ULEB128
272 testing.expect((try test_read_uleb128(u64, "\x00")) == 0);
273 testing.expect((try test_read_uleb128(u64, "\x01")) == 1);
274 testing.expect((try test_read_uleb128(u64, "\x3f")) == 63);
275 testing.expect((try test_read_uleb128(u64, "\x40")) == 64);
276 testing.expect((try test_read_uleb128(u64, "\x7f")) == 0x7f);
277 testing.expect((try test_read_uleb128(u64, "\x80\x01")) == 0x80);
278 testing.expect((try test_read_uleb128(u64, "\x81\x01")) == 0x81);
279 testing.expect((try test_read_uleb128(u64, "\x90\x01")) == 0x90);
280 testing.expect((try test_read_uleb128(u64, "\xff\x01")) == 0xff);
281 testing.expect((try test_read_uleb128(u64, "\x80\x02")) == 0x100);
282 testing.expect((try test_read_uleb128(u64, "\x81\x02")) == 0x101);
283 testing.expect((try test_read_uleb128(u64, "\x80\xc1\x80\x80\x10")) == 4294975616);
284 testing.expect((try test_read_uleb128(u64, "\x80\x80\x80\x80\x80\x80\x80\x80\x80\x01")) == 0x8000000000000000);
272 try testing.expect((try test_read_uleb128(u64, "\x00")) == 0);
273 try testing.expect((try test_read_uleb128(u64, "\x01")) == 1);
274 try testing.expect((try test_read_uleb128(u64, "\x3f")) == 63);
275 try testing.expect((try test_read_uleb128(u64, "\x40")) == 64);
276 try testing.expect((try test_read_uleb128(u64, "\x7f")) == 0x7f);
277 try testing.expect((try test_read_uleb128(u64, "\x80\x01")) == 0x80);
278 try testing.expect((try test_read_uleb128(u64, "\x81\x01")) == 0x81);
279 try testing.expect((try test_read_uleb128(u64, "\x90\x01")) == 0x90);
280 try testing.expect((try test_read_uleb128(u64, "\xff\x01")) == 0xff);
281 try testing.expect((try test_read_uleb128(u64, "\x80\x02")) == 0x100);
282 try testing.expect((try test_read_uleb128(u64, "\x81\x02")) == 0x101);
283 try testing.expect((try test_read_uleb128(u64, "\x80\xc1\x80\x80\x10")) == 4294975616);
284 try testing.expect((try test_read_uleb128(u64, "\x80\x80\x80\x80\x80\x80\x80\x80\x80\x01")) == 0x8000000000000000);
285285
286286 // Decode ULEB128 with extra padding bytes
287 testing.expect((try test_read_uleb128(u64, "\x80\x00")) == 0);
288 testing.expect((try test_read_uleb128(u64, "\x80\x80\x00")) == 0);
289 testing.expect((try test_read_uleb128(u64, "\xff\x00")) == 0x7f);
290 testing.expect((try test_read_uleb128(u64, "\xff\x80\x00")) == 0x7f);
291 testing.expect((try test_read_uleb128(u64, "\x80\x81\x00")) == 0x80);
292 testing.expect((try test_read_uleb128(u64, "\x80\x81\x80\x00")) == 0x80);
287 try testing.expect((try test_read_uleb128(u64, "\x80\x00")) == 0);
288 try testing.expect((try test_read_uleb128(u64, "\x80\x80\x00")) == 0);
289 try testing.expect((try test_read_uleb128(u64, "\xff\x00")) == 0x7f);
290 try testing.expect((try test_read_uleb128(u64, "\xff\x80\x00")) == 0x7f);
291 try testing.expect((try test_read_uleb128(u64, "\x80\x81\x00")) == 0x80);
292 try testing.expect((try test_read_uleb128(u64, "\x80\x81\x80\x00")) == 0x80);
293293
294294 // Decode sequence of ULEB128 values
295295 try test_read_uleb128_seq(u64, 4, "\x81\x01\x3f\x80\x7f\x80\x80\x80\x00");
......@@ -326,19 +326,19 @@ fn test_write_leb128(value: anytype) !void {
326326 // stream write
327327 try writeStream(fbs.writer(), value);
328328 const w1_pos = fbs.pos;
329 testing.expect(w1_pos == bytes_needed);
329 try testing.expect(w1_pos == bytes_needed);
330330
331331 // stream read
332332 fbs.pos = 0;
333333 const sr = try readStream(T, fbs.reader());
334 testing.expect(fbs.pos == w1_pos);
335 testing.expect(sr == value);
334 try testing.expect(fbs.pos == w1_pos);
335 try testing.expect(sr == value);
336336
337337 // bigger type stream read
338338 fbs.pos = 0;
339339 const bsr = try readStream(B, fbs.reader());
340 testing.expect(fbs.pos == w1_pos);
341 testing.expect(bsr == value);
340 try testing.expect(fbs.pos == w1_pos);
341 try testing.expect(bsr == value);
342342}
343343
344344test "serialize unsigned LEB128" {
lib/std/linked_list.zig+20-20
......@@ -123,7 +123,7 @@ test "basic SinglyLinkedList test" {
123123 const L = SinglyLinkedList(u32);
124124 var list = L{};
125125
126 testing.expect(list.len() == 0);
126 try testing.expect(list.len() == 0);
127127
128128 var one = L.Node{ .data = 1 };
129129 var two = L.Node{ .data = 2 };
......@@ -137,14 +137,14 @@ test "basic SinglyLinkedList test" {
137137 two.insertAfter(&three); // {1, 2, 3, 5}
138138 three.insertAfter(&four); // {1, 2, 3, 4, 5}
139139
140 testing.expect(list.len() == 5);
140 try testing.expect(list.len() == 5);
141141
142142 // Traverse forwards.
143143 {
144144 var it = list.first;
145145 var index: u32 = 1;
146146 while (it) |node| : (it = node.next) {
147 testing.expect(node.data == index);
147 try testing.expect(node.data == index);
148148 index += 1;
149149 }
150150 }
......@@ -153,9 +153,9 @@ test "basic SinglyLinkedList test" {
153153 _ = list.remove(&five); // {2, 3, 4}
154154 _ = two.removeNext(); // {2, 4}
155155
156 testing.expect(list.first.?.data == 2);
157 testing.expect(list.first.?.next.?.data == 4);
158 testing.expect(list.first.?.next.?.next == null);
156 try testing.expect(list.first.?.data == 2);
157 try testing.expect(list.first.?.next.?.data == 4);
158 try testing.expect(list.first.?.next.?.next == null);
159159}
160160
161161/// A tail queue is headed by a pair of pointers, one to the head of the
......@@ -344,7 +344,7 @@ test "basic TailQueue test" {
344344 var it = list.first;
345345 var index: u32 = 1;
346346 while (it) |node| : (it = node.next) {
347 testing.expect(node.data == index);
347 try testing.expect(node.data == index);
348348 index += 1;
349349 }
350350 }
......@@ -354,7 +354,7 @@ test "basic TailQueue test" {
354354 var it = list.last;
355355 var index: u32 = 1;
356356 while (it) |node| : (it = node.prev) {
357 testing.expect(node.data == (6 - index));
357 try testing.expect(node.data == (6 - index));
358358 index += 1;
359359 }
360360 }
......@@ -363,9 +363,9 @@ test "basic TailQueue test" {
363363 var last = list.pop(); // {2, 3, 4}
364364 list.remove(&three); // {2, 4}
365365
366 testing.expect(list.first.?.data == 2);
367 testing.expect(list.last.?.data == 4);
368 testing.expect(list.len == 2);
366 try testing.expect(list.first.?.data == 2);
367 try testing.expect(list.last.?.data == 4);
368 try testing.expect(list.len == 2);
369369}
370370
371371test "TailQueue concatenation" {
......@@ -387,18 +387,18 @@ test "TailQueue concatenation" {
387387
388388 list1.concatByMoving(&list2);
389389
390 testing.expect(list1.last == &five);
391 testing.expect(list1.len == 5);
392 testing.expect(list2.first == null);
393 testing.expect(list2.last == null);
394 testing.expect(list2.len == 0);
390 try testing.expect(list1.last == &five);
391 try testing.expect(list1.len == 5);
392 try testing.expect(list2.first == null);
393 try testing.expect(list2.last == null);
394 try testing.expect(list2.len == 0);
395395
396396 // Traverse forwards.
397397 {
398398 var it = list1.first;
399399 var index: u32 = 1;
400400 while (it) |node| : (it = node.next) {
401 testing.expect(node.data == index);
401 try testing.expect(node.data == index);
402402 index += 1;
403403 }
404404 }
......@@ -408,7 +408,7 @@ test "TailQueue concatenation" {
408408 var it = list1.last;
409409 var index: u32 = 1;
410410 while (it) |node| : (it = node.prev) {
411 testing.expect(node.data == (6 - index));
411 try testing.expect(node.data == (6 - index));
412412 index += 1;
413413 }
414414 }
......@@ -421,7 +421,7 @@ test "TailQueue concatenation" {
421421 var it = list2.first;
422422 var index: u32 = 1;
423423 while (it) |node| : (it = node.next) {
424 testing.expect(node.data == index);
424 try testing.expect(node.data == index);
425425 index += 1;
426426 }
427427 }
......@@ -431,7 +431,7 @@ test "TailQueue concatenation" {
431431 var it = list2.last;
432432 var index: u32 = 1;
433433 while (it) |node| : (it = node.prev) {
434 testing.expect(node.data == (6 - index));
434 try testing.expect(node.data == (6 - index));
435435 index += 1;
436436 }
437437 }
lib/std/math.zig+353-353
......@@ -177,20 +177,20 @@ test "approxEqAbs and approxEqRel" {
177177 else => unreachable,
178178 };
179179
180 testing.expect(approxEqAbs(T, 0.0, 0.0, eps_value));
181 testing.expect(approxEqAbs(T, -0.0, -0.0, eps_value));
182 testing.expect(approxEqAbs(T, 0.0, -0.0, eps_value));
183 testing.expect(approxEqRel(T, 1.0, 1.0, sqrt_eps_value));
184 testing.expect(!approxEqRel(T, 1.0, 0.0, sqrt_eps_value));
185 testing.expect(!approxEqAbs(T, 1.0 + 2 * epsilon(T), 1.0, eps_value));
186 testing.expect(approxEqAbs(T, 1.0 + 1 * epsilon(T), 1.0, eps_value));
187 testing.expect(!approxEqRel(T, 1.0, nan_value, sqrt_eps_value));
188 testing.expect(!approxEqRel(T, nan_value, nan_value, sqrt_eps_value));
189 testing.expect(approxEqRel(T, inf_value, inf_value, sqrt_eps_value));
190 testing.expect(approxEqRel(T, min_value, min_value, sqrt_eps_value));
191 testing.expect(approxEqRel(T, -min_value, -min_value, sqrt_eps_value));
192 testing.expect(approxEqAbs(T, min_value, 0.0, eps_value * 2));
193 testing.expect(approxEqAbs(T, -min_value, 0.0, eps_value * 2));
180 try testing.expect(approxEqAbs(T, 0.0, 0.0, eps_value));
181 try testing.expect(approxEqAbs(T, -0.0, -0.0, eps_value));
182 try testing.expect(approxEqAbs(T, 0.0, -0.0, eps_value));
183 try testing.expect(approxEqRel(T, 1.0, 1.0, sqrt_eps_value));
184 try testing.expect(!approxEqRel(T, 1.0, 0.0, sqrt_eps_value));
185 try testing.expect(!approxEqAbs(T, 1.0 + 2 * epsilon(T), 1.0, eps_value));
186 try testing.expect(approxEqAbs(T, 1.0 + 1 * epsilon(T), 1.0, eps_value));
187 try testing.expect(!approxEqRel(T, 1.0, nan_value, sqrt_eps_value));
188 try testing.expect(!approxEqRel(T, nan_value, nan_value, sqrt_eps_value));
189 try testing.expect(approxEqRel(T, inf_value, inf_value, sqrt_eps_value));
190 try testing.expect(approxEqRel(T, min_value, min_value, sqrt_eps_value));
191 try testing.expect(approxEqRel(T, -min_value, -min_value, sqrt_eps_value));
192 try testing.expect(approxEqAbs(T, min_value, 0.0, eps_value * 2));
193 try testing.expect(approxEqAbs(T, -min_value, 0.0, eps_value * 2));
194194 }
195195}
196196
......@@ -349,34 +349,34 @@ pub fn min(x: anytype, y: anytype) Min(@TypeOf(x), @TypeOf(y)) {
349349}
350350
351351test "math.min" {
352 testing.expect(min(@as(i32, -1), @as(i32, 2)) == -1);
352 try testing.expect(min(@as(i32, -1), @as(i32, 2)) == -1);
353353 {
354354 var a: u16 = 999;
355355 var b: u32 = 10;
356356 var result = min(a, b);
357 testing.expect(@TypeOf(result) == u16);
358 testing.expect(result == 10);
357 try testing.expect(@TypeOf(result) == u16);
358 try testing.expect(result == 10);
359359 }
360360 {
361361 var a: f64 = 10.34;
362362 var b: f32 = 999.12;
363363 var result = min(a, b);
364 testing.expect(@TypeOf(result) == f64);
365 testing.expect(result == 10.34);
364 try testing.expect(@TypeOf(result) == f64);
365 try testing.expect(result == 10.34);
366366 }
367367 {
368368 var a: i8 = -127;
369369 var b: i16 = -200;
370370 var result = min(a, b);
371 testing.expect(@TypeOf(result) == i16);
372 testing.expect(result == -200);
371 try testing.expect(@TypeOf(result) == i16);
372 try testing.expect(result == -200);
373373 }
374374 {
375375 const a = 10.34;
376376 var b: f32 = 999.12;
377377 var result = min(a, b);
378 testing.expect(@TypeOf(result) == f32);
379 testing.expect(result == 10.34);
378 try testing.expect(@TypeOf(result) == f32);
379 try testing.expect(result == 10.34);
380380 }
381381}
382382
......@@ -385,7 +385,7 @@ pub fn max(x: anytype, y: anytype) @TypeOf(x, y) {
385385}
386386
387387test "math.max" {
388 testing.expect(max(@as(i32, -1), @as(i32, 2)) == 2);
388 try testing.expect(max(@as(i32, -1), @as(i32, 2)) == 2);
389389}
390390
391391pub fn clamp(val: anytype, lower: anytype, upper: anytype) @TypeOf(val, lower, upper) {
......@@ -394,19 +394,19 @@ pub fn clamp(val: anytype, lower: anytype, upper: anytype) @TypeOf(val, lower, u
394394}
395395test "math.clamp" {
396396 // Within range
397 testing.expect(std.math.clamp(@as(i32, -1), @as(i32, -4), @as(i32, 7)) == -1);
397 try testing.expect(std.math.clamp(@as(i32, -1), @as(i32, -4), @as(i32, 7)) == -1);
398398 // Below
399 testing.expect(std.math.clamp(@as(i32, -5), @as(i32, -4), @as(i32, 7)) == -4);
399 try testing.expect(std.math.clamp(@as(i32, -5), @as(i32, -4), @as(i32, 7)) == -4);
400400 // Above
401 testing.expect(std.math.clamp(@as(i32, 8), @as(i32, -4), @as(i32, 7)) == 7);
401 try testing.expect(std.math.clamp(@as(i32, 8), @as(i32, -4), @as(i32, 7)) == 7);
402402
403403 // Floating point
404 testing.expect(std.math.clamp(@as(f32, 1.1), @as(f32, 0.0), @as(f32, 1.0)) == 1.0);
405 testing.expect(std.math.clamp(@as(f32, -127.5), @as(f32, -200), @as(f32, -100)) == -127.5);
404 try testing.expect(std.math.clamp(@as(f32, 1.1), @as(f32, 0.0), @as(f32, 1.0)) == 1.0);
405 try testing.expect(std.math.clamp(@as(f32, -127.5), @as(f32, -200), @as(f32, -100)) == -127.5);
406406
407407 // Mix of comptime and non-comptime
408408 var i: i32 = 1;
409 testing.expect(std.math.clamp(i, 0, 1) == 1);
409 try testing.expect(std.math.clamp(i, 0, 1) == 1);
410410}
411411
412412pub fn mul(comptime T: type, a: T, b: T) (error{Overflow}!T) {
......@@ -461,17 +461,17 @@ pub fn shl(comptime T: type, a: T, shift_amt: anytype) T {
461461}
462462
463463test "math.shl" {
464 testing.expect(shl(u8, 0b11111111, @as(usize, 3)) == 0b11111000);
465 testing.expect(shl(u8, 0b11111111, @as(usize, 8)) == 0);
466 testing.expect(shl(u8, 0b11111111, @as(usize, 9)) == 0);
467 testing.expect(shl(u8, 0b11111111, @as(isize, -2)) == 0b00111111);
468 testing.expect(shl(u8, 0b11111111, 3) == 0b11111000);
469 testing.expect(shl(u8, 0b11111111, 8) == 0);
470 testing.expect(shl(u8, 0b11111111, 9) == 0);
471 testing.expect(shl(u8, 0b11111111, -2) == 0b00111111);
472 testing.expect(shl(std.meta.Vector(1, u32), std.meta.Vector(1, u32){42}, @as(usize, 1))[0] == @as(u32, 42) << 1);
473 testing.expect(shl(std.meta.Vector(1, u32), std.meta.Vector(1, u32){42}, @as(isize, -1))[0] == @as(u32, 42) >> 1);
474 testing.expect(shl(std.meta.Vector(1, u32), std.meta.Vector(1, u32){42}, 33)[0] == 0);
464 try testing.expect(shl(u8, 0b11111111, @as(usize, 3)) == 0b11111000);
465 try testing.expect(shl(u8, 0b11111111, @as(usize, 8)) == 0);
466 try testing.expect(shl(u8, 0b11111111, @as(usize, 9)) == 0);
467 try testing.expect(shl(u8, 0b11111111, @as(isize, -2)) == 0b00111111);
468 try testing.expect(shl(u8, 0b11111111, 3) == 0b11111000);
469 try testing.expect(shl(u8, 0b11111111, 8) == 0);
470 try testing.expect(shl(u8, 0b11111111, 9) == 0);
471 try testing.expect(shl(u8, 0b11111111, -2) == 0b00111111);
472 try testing.expect(shl(std.meta.Vector(1, u32), std.meta.Vector(1, u32){42}, @as(usize, 1))[0] == @as(u32, 42) << 1);
473 try testing.expect(shl(std.meta.Vector(1, u32), std.meta.Vector(1, u32){42}, @as(isize, -1))[0] == @as(u32, 42) >> 1);
474 try testing.expect(shl(std.meta.Vector(1, u32), std.meta.Vector(1, u32){42}, 33)[0] == 0);
475475}
476476
477477/// Shifts right. Overflowed bits are truncated.
......@@ -501,17 +501,17 @@ pub fn shr(comptime T: type, a: T, shift_amt: anytype) T {
501501}
502502
503503test "math.shr" {
504 testing.expect(shr(u8, 0b11111111, @as(usize, 3)) == 0b00011111);
505 testing.expect(shr(u8, 0b11111111, @as(usize, 8)) == 0);
506 testing.expect(shr(u8, 0b11111111, @as(usize, 9)) == 0);
507 testing.expect(shr(u8, 0b11111111, @as(isize, -2)) == 0b11111100);
508 testing.expect(shr(u8, 0b11111111, 3) == 0b00011111);
509 testing.expect(shr(u8, 0b11111111, 8) == 0);
510 testing.expect(shr(u8, 0b11111111, 9) == 0);
511 testing.expect(shr(u8, 0b11111111, -2) == 0b11111100);
512 testing.expect(shr(std.meta.Vector(1, u32), std.meta.Vector(1, u32){42}, @as(usize, 1))[0] == @as(u32, 42) >> 1);
513 testing.expect(shr(std.meta.Vector(1, u32), std.meta.Vector(1, u32){42}, @as(isize, -1))[0] == @as(u32, 42) << 1);
514 testing.expect(shr(std.meta.Vector(1, u32), std.meta.Vector(1, u32){42}, 33)[0] == 0);
504 try testing.expect(shr(u8, 0b11111111, @as(usize, 3)) == 0b00011111);
505 try testing.expect(shr(u8, 0b11111111, @as(usize, 8)) == 0);
506 try testing.expect(shr(u8, 0b11111111, @as(usize, 9)) == 0);
507 try testing.expect(shr(u8, 0b11111111, @as(isize, -2)) == 0b11111100);
508 try testing.expect(shr(u8, 0b11111111, 3) == 0b00011111);
509 try testing.expect(shr(u8, 0b11111111, 8) == 0);
510 try testing.expect(shr(u8, 0b11111111, 9) == 0);
511 try testing.expect(shr(u8, 0b11111111, -2) == 0b11111100);
512 try testing.expect(shr(std.meta.Vector(1, u32), std.meta.Vector(1, u32){42}, @as(usize, 1))[0] == @as(u32, 42) >> 1);
513 try testing.expect(shr(std.meta.Vector(1, u32), std.meta.Vector(1, u32){42}, @as(isize, -1))[0] == @as(u32, 42) << 1);
514 try testing.expect(shr(std.meta.Vector(1, u32), std.meta.Vector(1, u32){42}, 33)[0] == 0);
515515}
516516
517517/// Rotates right. Only unsigned values can be rotated.
......@@ -533,13 +533,13 @@ pub fn rotr(comptime T: type, x: T, r: anytype) T {
533533}
534534
535535test "math.rotr" {
536 testing.expect(rotr(u8, 0b00000001, @as(usize, 0)) == 0b00000001);
537 testing.expect(rotr(u8, 0b00000001, @as(usize, 9)) == 0b10000000);
538 testing.expect(rotr(u8, 0b00000001, @as(usize, 8)) == 0b00000001);
539 testing.expect(rotr(u8, 0b00000001, @as(usize, 4)) == 0b00010000);
540 testing.expect(rotr(u8, 0b00000001, @as(isize, -1)) == 0b00000010);
541 testing.expect(rotr(std.meta.Vector(1, u32), std.meta.Vector(1, u32){1}, @as(usize, 1))[0] == @as(u32, 1) << 31);
542 testing.expect(rotr(std.meta.Vector(1, u32), std.meta.Vector(1, u32){1}, @as(isize, -1))[0] == @as(u32, 1) << 1);
536 try testing.expect(rotr(u8, 0b00000001, @as(usize, 0)) == 0b00000001);
537 try testing.expect(rotr(u8, 0b00000001, @as(usize, 9)) == 0b10000000);
538 try testing.expect(rotr(u8, 0b00000001, @as(usize, 8)) == 0b00000001);
539 try testing.expect(rotr(u8, 0b00000001, @as(usize, 4)) == 0b00010000);
540 try testing.expect(rotr(u8, 0b00000001, @as(isize, -1)) == 0b00000010);
541 try testing.expect(rotr(std.meta.Vector(1, u32), std.meta.Vector(1, u32){1}, @as(usize, 1))[0] == @as(u32, 1) << 31);
542 try testing.expect(rotr(std.meta.Vector(1, u32), std.meta.Vector(1, u32){1}, @as(isize, -1))[0] == @as(u32, 1) << 1);
543543}
544544
545545/// Rotates left. Only unsigned values can be rotated.
......@@ -561,13 +561,13 @@ pub fn rotl(comptime T: type, x: T, r: anytype) T {
561561}
562562
563563test "math.rotl" {
564 testing.expect(rotl(u8, 0b00000001, @as(usize, 0)) == 0b00000001);
565 testing.expect(rotl(u8, 0b00000001, @as(usize, 9)) == 0b00000010);
566 testing.expect(rotl(u8, 0b00000001, @as(usize, 8)) == 0b00000001);
567 testing.expect(rotl(u8, 0b00000001, @as(usize, 4)) == 0b00010000);
568 testing.expect(rotl(u8, 0b00000001, @as(isize, -1)) == 0b10000000);
569 testing.expect(rotl(std.meta.Vector(1, u32), std.meta.Vector(1, u32){1 << 31}, @as(usize, 1))[0] == 1);
570 testing.expect(rotl(std.meta.Vector(1, u32), std.meta.Vector(1, u32){1 << 31}, @as(isize, -1))[0] == @as(u32, 1) << 30);
564 try testing.expect(rotl(u8, 0b00000001, @as(usize, 0)) == 0b00000001);
565 try testing.expect(rotl(u8, 0b00000001, @as(usize, 9)) == 0b00000010);
566 try testing.expect(rotl(u8, 0b00000001, @as(usize, 8)) == 0b00000001);
567 try testing.expect(rotl(u8, 0b00000001, @as(usize, 4)) == 0b00010000);
568 try testing.expect(rotl(u8, 0b00000001, @as(isize, -1)) == 0b10000000);
569 try testing.expect(rotl(std.meta.Vector(1, u32), std.meta.Vector(1, u32){1 << 31}, @as(usize, 1))[0] == 1);
570 try testing.expect(rotl(std.meta.Vector(1, u32), std.meta.Vector(1, u32){1 << 31}, @as(isize, -1))[0] == @as(u32, 1) << 30);
571571}
572572
573573pub fn Log2Int(comptime T: type) type {
......@@ -598,62 +598,62 @@ pub fn IntFittingRange(comptime from: comptime_int, comptime to: comptime_int) t
598598}
599599
600600test "math.IntFittingRange" {
601 testing.expect(IntFittingRange(0, 0) == u0);
602 testing.expect(IntFittingRange(0, 1) == u1);
603 testing.expect(IntFittingRange(0, 2) == u2);
604 testing.expect(IntFittingRange(0, 3) == u2);
605 testing.expect(IntFittingRange(0, 4) == u3);
606 testing.expect(IntFittingRange(0, 7) == u3);
607 testing.expect(IntFittingRange(0, 8) == u4);
608 testing.expect(IntFittingRange(0, 9) == u4);
609 testing.expect(IntFittingRange(0, 15) == u4);
610 testing.expect(IntFittingRange(0, 16) == u5);
611 testing.expect(IntFittingRange(0, 17) == u5);
612 testing.expect(IntFittingRange(0, 4095) == u12);
613 testing.expect(IntFittingRange(2000, 4095) == u12);
614 testing.expect(IntFittingRange(0, 4096) == u13);
615 testing.expect(IntFittingRange(2000, 4096) == u13);
616 testing.expect(IntFittingRange(0, 4097) == u13);
617 testing.expect(IntFittingRange(2000, 4097) == u13);
618 testing.expect(IntFittingRange(0, 123456789123456798123456789) == u87);
619 testing.expect(IntFittingRange(0, 123456789123456798123456789123456789123456798123456789) == u177);
620
621 testing.expect(IntFittingRange(-1, -1) == i1);
622 testing.expect(IntFittingRange(-1, 0) == i1);
623 testing.expect(IntFittingRange(-1, 1) == i2);
624 testing.expect(IntFittingRange(-2, -2) == i2);
625 testing.expect(IntFittingRange(-2, -1) == i2);
626 testing.expect(IntFittingRange(-2, 0) == i2);
627 testing.expect(IntFittingRange(-2, 1) == i2);
628 testing.expect(IntFittingRange(-2, 2) == i3);
629 testing.expect(IntFittingRange(-1, 2) == i3);
630 testing.expect(IntFittingRange(-1, 3) == i3);
631 testing.expect(IntFittingRange(-1, 4) == i4);
632 testing.expect(IntFittingRange(-1, 7) == i4);
633 testing.expect(IntFittingRange(-1, 8) == i5);
634 testing.expect(IntFittingRange(-1, 9) == i5);
635 testing.expect(IntFittingRange(-1, 15) == i5);
636 testing.expect(IntFittingRange(-1, 16) == i6);
637 testing.expect(IntFittingRange(-1, 17) == i6);
638 testing.expect(IntFittingRange(-1, 4095) == i13);
639 testing.expect(IntFittingRange(-4096, 4095) == i13);
640 testing.expect(IntFittingRange(-1, 4096) == i14);
641 testing.expect(IntFittingRange(-4097, 4095) == i14);
642 testing.expect(IntFittingRange(-1, 4097) == i14);
643 testing.expect(IntFittingRange(-1, 123456789123456798123456789) == i88);
644 testing.expect(IntFittingRange(-1, 123456789123456798123456789123456789123456798123456789) == i178);
601 try testing.expect(IntFittingRange(0, 0) == u0);
602 try testing.expect(IntFittingRange(0, 1) == u1);
603 try testing.expect(IntFittingRange(0, 2) == u2);
604 try testing.expect(IntFittingRange(0, 3) == u2);
605 try testing.expect(IntFittingRange(0, 4) == u3);
606 try testing.expect(IntFittingRange(0, 7) == u3);
607 try testing.expect(IntFittingRange(0, 8) == u4);
608 try testing.expect(IntFittingRange(0, 9) == u4);
609 try testing.expect(IntFittingRange(0, 15) == u4);
610 try testing.expect(IntFittingRange(0, 16) == u5);
611 try testing.expect(IntFittingRange(0, 17) == u5);
612 try testing.expect(IntFittingRange(0, 4095) == u12);
613 try testing.expect(IntFittingRange(2000, 4095) == u12);
614 try testing.expect(IntFittingRange(0, 4096) == u13);
615 try testing.expect(IntFittingRange(2000, 4096) == u13);
616 try testing.expect(IntFittingRange(0, 4097) == u13);
617 try testing.expect(IntFittingRange(2000, 4097) == u13);
618 try testing.expect(IntFittingRange(0, 123456789123456798123456789) == u87);
619 try testing.expect(IntFittingRange(0, 123456789123456798123456789123456789123456798123456789) == u177);
620
621 try testing.expect(IntFittingRange(-1, -1) == i1);
622 try testing.expect(IntFittingRange(-1, 0) == i1);
623 try testing.expect(IntFittingRange(-1, 1) == i2);
624 try testing.expect(IntFittingRange(-2, -2) == i2);
625 try testing.expect(IntFittingRange(-2, -1) == i2);
626 try testing.expect(IntFittingRange(-2, 0) == i2);
627 try testing.expect(IntFittingRange(-2, 1) == i2);
628 try testing.expect(IntFittingRange(-2, 2) == i3);
629 try testing.expect(IntFittingRange(-1, 2) == i3);
630 try testing.expect(IntFittingRange(-1, 3) == i3);
631 try testing.expect(IntFittingRange(-1, 4) == i4);
632 try testing.expect(IntFittingRange(-1, 7) == i4);
633 try testing.expect(IntFittingRange(-1, 8) == i5);
634 try testing.expect(IntFittingRange(-1, 9) == i5);
635 try testing.expect(IntFittingRange(-1, 15) == i5);
636 try testing.expect(IntFittingRange(-1, 16) == i6);
637 try testing.expect(IntFittingRange(-1, 17) == i6);
638 try testing.expect(IntFittingRange(-1, 4095) == i13);
639 try testing.expect(IntFittingRange(-4096, 4095) == i13);
640 try testing.expect(IntFittingRange(-1, 4096) == i14);
641 try testing.expect(IntFittingRange(-4097, 4095) == i14);
642 try testing.expect(IntFittingRange(-1, 4097) == i14);
643 try testing.expect(IntFittingRange(-1, 123456789123456798123456789) == i88);
644 try testing.expect(IntFittingRange(-1, 123456789123456798123456789123456789123456798123456789) == i178);
645645}
646646
647647test "math overflow functions" {
648 testOverflow();
649 comptime testOverflow();
648 try testOverflow();
649 comptime try testOverflow();
650650}
651651
652fn testOverflow() void {
653 testing.expect((mul(i32, 3, 4) catch unreachable) == 12);
654 testing.expect((add(i32, 3, 4) catch unreachable) == 7);
655 testing.expect((sub(i32, 3, 4) catch unreachable) == -1);
656 testing.expect((shlExact(i32, 0b11, 4) catch unreachable) == 0b110000);
652fn testOverflow() !void {
653 try testing.expect((mul(i32, 3, 4) catch unreachable) == 12);
654 try testing.expect((add(i32, 3, 4) catch unreachable) == 7);
655 try testing.expect((sub(i32, 3, 4) catch unreachable) == -1);
656 try testing.expect((shlExact(i32, 0b11, 4) catch unreachable) == 0b110000);
657657}
658658
659659pub fn absInt(x: anytype) !@TypeOf(x) {
......@@ -670,23 +670,23 @@ pub fn absInt(x: anytype) !@TypeOf(x) {
670670}
671671
672672test "math.absInt" {
673 testAbsInt();
674 comptime testAbsInt();
673 try testAbsInt();
674 comptime try testAbsInt();
675675}
676fn testAbsInt() void {
677 testing.expect((absInt(@as(i32, -10)) catch unreachable) == 10);
678 testing.expect((absInt(@as(i32, 10)) catch unreachable) == 10);
676fn testAbsInt() !void {
677 try testing.expect((absInt(@as(i32, -10)) catch unreachable) == 10);
678 try testing.expect((absInt(@as(i32, 10)) catch unreachable) == 10);
679679}
680680
681681pub const absFloat = fabs;
682682
683683test "math.absFloat" {
684 testAbsFloat();
685 comptime testAbsFloat();
684 try testAbsFloat();
685 comptime try testAbsFloat();
686686}
687fn testAbsFloat() void {
688 testing.expect(absFloat(@as(f32, -10.05)) == 10.05);
689 testing.expect(absFloat(@as(f32, 10.05)) == 10.05);
687fn testAbsFloat() !void {
688 try testing.expect(absFloat(@as(f32, -10.05)) == 10.05);
689 try testing.expect(absFloat(@as(f32, 10.05)) == 10.05);
690690}
691691
692692pub fn divTrunc(comptime T: type, numerator: T, denominator: T) !T {
......@@ -697,17 +697,17 @@ pub fn divTrunc(comptime T: type, numerator: T, denominator: T) !T {
697697}
698698
699699test "math.divTrunc" {
700 testDivTrunc();
701 comptime testDivTrunc();
700 try testDivTrunc();
701 comptime try testDivTrunc();
702702}
703fn testDivTrunc() void {
704 testing.expect((divTrunc(i32, 5, 3) catch unreachable) == 1);
705 testing.expect((divTrunc(i32, -5, 3) catch unreachable) == -1);
706 testing.expectError(error.DivisionByZero, divTrunc(i8, -5, 0));
707 testing.expectError(error.Overflow, divTrunc(i8, -128, -1));
703fn testDivTrunc() !void {
704 try testing.expect((divTrunc(i32, 5, 3) catch unreachable) == 1);
705 try testing.expect((divTrunc(i32, -5, 3) catch unreachable) == -1);
706 try testing.expectError(error.DivisionByZero, divTrunc(i8, -5, 0));
707 try testing.expectError(error.Overflow, divTrunc(i8, -128, -1));
708708
709 testing.expect((divTrunc(f32, 5.0, 3.0) catch unreachable) == 1.0);
710 testing.expect((divTrunc(f32, -5.0, 3.0) catch unreachable) == -1.0);
709 try testing.expect((divTrunc(f32, 5.0, 3.0) catch unreachable) == 1.0);
710 try testing.expect((divTrunc(f32, -5.0, 3.0) catch unreachable) == -1.0);
711711}
712712
713713pub fn divFloor(comptime T: type, numerator: T, denominator: T) !T {
......@@ -718,17 +718,17 @@ pub fn divFloor(comptime T: type, numerator: T, denominator: T) !T {
718718}
719719
720720test "math.divFloor" {
721 testDivFloor();
722 comptime testDivFloor();
721 try testDivFloor();
722 comptime try testDivFloor();
723723}
724fn testDivFloor() void {
725 testing.expect((divFloor(i32, 5, 3) catch unreachable) == 1);
726 testing.expect((divFloor(i32, -5, 3) catch unreachable) == -2);
727 testing.expectError(error.DivisionByZero, divFloor(i8, -5, 0));
728 testing.expectError(error.Overflow, divFloor(i8, -128, -1));
724fn testDivFloor() !void {
725 try testing.expect((divFloor(i32, 5, 3) catch unreachable) == 1);
726 try testing.expect((divFloor(i32, -5, 3) catch unreachable) == -2);
727 try testing.expectError(error.DivisionByZero, divFloor(i8, -5, 0));
728 try testing.expectError(error.Overflow, divFloor(i8, -128, -1));
729729
730 testing.expect((divFloor(f32, 5.0, 3.0) catch unreachable) == 1.0);
731 testing.expect((divFloor(f32, -5.0, 3.0) catch unreachable) == -2.0);
730 try testing.expect((divFloor(f32, 5.0, 3.0) catch unreachable) == 1.0);
731 try testing.expect((divFloor(f32, -5.0, 3.0) catch unreachable) == -2.0);
732732}
733733
734734pub fn divCeil(comptime T: type, numerator: T, denominator: T) !T {
......@@ -752,36 +752,36 @@ pub fn divCeil(comptime T: type, numerator: T, denominator: T) !T {
752752}
753753
754754test "math.divCeil" {
755 testDivCeil();
756 comptime testDivCeil();
757}
758fn testDivCeil() void {
759 testing.expectEqual(@as(i32, 2), divCeil(i32, 5, 3) catch unreachable);
760 testing.expectEqual(@as(i32, -1), divCeil(i32, -5, 3) catch unreachable);
761 testing.expectEqual(@as(i32, -1), divCeil(i32, 5, -3) catch unreachable);
762 testing.expectEqual(@as(i32, 2), divCeil(i32, -5, -3) catch unreachable);
763 testing.expectEqual(@as(i32, 0), divCeil(i32, 0, 5) catch unreachable);
764 testing.expectEqual(@as(u32, 0), divCeil(u32, 0, 5) catch unreachable);
765 testing.expectError(error.DivisionByZero, divCeil(i8, -5, 0));
766 testing.expectError(error.Overflow, divCeil(i8, -128, -1));
767
768 testing.expectEqual(@as(f32, 0.0), divCeil(f32, 0.0, 5.0) catch unreachable);
769 testing.expectEqual(@as(f32, 2.0), divCeil(f32, 5.0, 3.0) catch unreachable);
770 testing.expectEqual(@as(f32, -1.0), divCeil(f32, -5.0, 3.0) catch unreachable);
771 testing.expectEqual(@as(f32, -1.0), divCeil(f32, 5.0, -3.0) catch unreachable);
772 testing.expectEqual(@as(f32, 2.0), divCeil(f32, -5.0, -3.0) catch unreachable);
773
774 testing.expectEqual(6, divCeil(comptime_int, 23, 4) catch unreachable);
775 testing.expectEqual(-5, divCeil(comptime_int, -23, 4) catch unreachable);
776 testing.expectEqual(-5, divCeil(comptime_int, 23, -4) catch unreachable);
777 testing.expectEqual(6, divCeil(comptime_int, -23, -4) catch unreachable);
778 testing.expectError(error.DivisionByZero, divCeil(comptime_int, 23, 0));
779
780 testing.expectEqual(6.0, divCeil(comptime_float, 23.0, 4.0) catch unreachable);
781 testing.expectEqual(-5.0, divCeil(comptime_float, -23.0, 4.0) catch unreachable);
782 testing.expectEqual(-5.0, divCeil(comptime_float, 23.0, -4.0) catch unreachable);
783 testing.expectEqual(6.0, divCeil(comptime_float, -23.0, -4.0) catch unreachable);
784 testing.expectError(error.DivisionByZero, divCeil(comptime_float, 23.0, 0.0));
755 try testDivCeil();
756 comptime try testDivCeil();
757}
758fn testDivCeil() !void {
759 try testing.expectEqual(@as(i32, 2), divCeil(i32, 5, 3) catch unreachable);
760 try testing.expectEqual(@as(i32, -1), divCeil(i32, -5, 3) catch unreachable);
761 try testing.expectEqual(@as(i32, -1), divCeil(i32, 5, -3) catch unreachable);
762 try testing.expectEqual(@as(i32, 2), divCeil(i32, -5, -3) catch unreachable);
763 try testing.expectEqual(@as(i32, 0), divCeil(i32, 0, 5) catch unreachable);
764 try testing.expectEqual(@as(u32, 0), divCeil(u32, 0, 5) catch unreachable);
765 try testing.expectError(error.DivisionByZero, divCeil(i8, -5, 0));
766 try testing.expectError(error.Overflow, divCeil(i8, -128, -1));
767
768 try testing.expectEqual(@as(f32, 0.0), divCeil(f32, 0.0, 5.0) catch unreachable);
769 try testing.expectEqual(@as(f32, 2.0), divCeil(f32, 5.0, 3.0) catch unreachable);
770 try testing.expectEqual(@as(f32, -1.0), divCeil(f32, -5.0, 3.0) catch unreachable);
771 try testing.expectEqual(@as(f32, -1.0), divCeil(f32, 5.0, -3.0) catch unreachable);
772 try testing.expectEqual(@as(f32, 2.0), divCeil(f32, -5.0, -3.0) catch unreachable);
773
774 try testing.expectEqual(6, divCeil(comptime_int, 23, 4) catch unreachable);
775 try testing.expectEqual(-5, divCeil(comptime_int, -23, 4) catch unreachable);
776 try testing.expectEqual(-5, divCeil(comptime_int, 23, -4) catch unreachable);
777 try testing.expectEqual(6, divCeil(comptime_int, -23, -4) catch unreachable);
778 try testing.expectError(error.DivisionByZero, divCeil(comptime_int, 23, 0));
779
780 try testing.expectEqual(6.0, divCeil(comptime_float, 23.0, 4.0) catch unreachable);
781 try testing.expectEqual(-5.0, divCeil(comptime_float, -23.0, 4.0) catch unreachable);
782 try testing.expectEqual(-5.0, divCeil(comptime_float, 23.0, -4.0) catch unreachable);
783 try testing.expectEqual(6.0, divCeil(comptime_float, -23.0, -4.0) catch unreachable);
784 try testing.expectError(error.DivisionByZero, divCeil(comptime_float, 23.0, 0.0));
785785}
786786
787787pub fn divExact(comptime T: type, numerator: T, denominator: T) !T {
......@@ -794,19 +794,19 @@ pub fn divExact(comptime T: type, numerator: T, denominator: T) !T {
794794}
795795
796796test "math.divExact" {
797 testDivExact();
798 comptime testDivExact();
797 try testDivExact();
798 comptime try testDivExact();
799799}
800fn testDivExact() void {
801 testing.expect((divExact(i32, 10, 5) catch unreachable) == 2);
802 testing.expect((divExact(i32, -10, 5) catch unreachable) == -2);
803 testing.expectError(error.DivisionByZero, divExact(i8, -5, 0));
804 testing.expectError(error.Overflow, divExact(i8, -128, -1));
805 testing.expectError(error.UnexpectedRemainder, divExact(i32, 5, 2));
800fn testDivExact() !void {
801 try testing.expect((divExact(i32, 10, 5) catch unreachable) == 2);
802 try testing.expect((divExact(i32, -10, 5) catch unreachable) == -2);
803 try testing.expectError(error.DivisionByZero, divExact(i8, -5, 0));
804 try testing.expectError(error.Overflow, divExact(i8, -128, -1));
805 try testing.expectError(error.UnexpectedRemainder, divExact(i32, 5, 2));
806806
807 testing.expect((divExact(f32, 10.0, 5.0) catch unreachable) == 2.0);
808 testing.expect((divExact(f32, -10.0, 5.0) catch unreachable) == -2.0);
809 testing.expectError(error.UnexpectedRemainder, divExact(f32, 5.0, 2.0));
807 try testing.expect((divExact(f32, 10.0, 5.0) catch unreachable) == 2.0);
808 try testing.expect((divExact(f32, -10.0, 5.0) catch unreachable) == -2.0);
809 try testing.expectError(error.UnexpectedRemainder, divExact(f32, 5.0, 2.0));
810810}
811811
812812pub fn mod(comptime T: type, numerator: T, denominator: T) !T {
......@@ -817,19 +817,19 @@ pub fn mod(comptime T: type, numerator: T, denominator: T) !T {
817817}
818818
819819test "math.mod" {
820 testMod();
821 comptime testMod();
820 try testMod();
821 comptime try testMod();
822822}
823fn testMod() void {
824 testing.expect((mod(i32, -5, 3) catch unreachable) == 1);
825 testing.expect((mod(i32, 5, 3) catch unreachable) == 2);
826 testing.expectError(error.NegativeDenominator, mod(i32, 10, -1));
827 testing.expectError(error.DivisionByZero, mod(i32, 10, 0));
823fn testMod() !void {
824 try testing.expect((mod(i32, -5, 3) catch unreachable) == 1);
825 try testing.expect((mod(i32, 5, 3) catch unreachable) == 2);
826 try testing.expectError(error.NegativeDenominator, mod(i32, 10, -1));
827 try testing.expectError(error.DivisionByZero, mod(i32, 10, 0));
828828
829 testing.expect((mod(f32, -5, 3) catch unreachable) == 1);
830 testing.expect((mod(f32, 5, 3) catch unreachable) == 2);
831 testing.expectError(error.NegativeDenominator, mod(f32, 10, -1));
832 testing.expectError(error.DivisionByZero, mod(f32, 10, 0));
829 try testing.expect((mod(f32, -5, 3) catch unreachable) == 1);
830 try testing.expect((mod(f32, 5, 3) catch unreachable) == 2);
831 try testing.expectError(error.NegativeDenominator, mod(f32, 10, -1));
832 try testing.expectError(error.DivisionByZero, mod(f32, 10, 0));
833833}
834834
835835pub fn rem(comptime T: type, numerator: T, denominator: T) !T {
......@@ -840,19 +840,19 @@ pub fn rem(comptime T: type, numerator: T, denominator: T) !T {
840840}
841841
842842test "math.rem" {
843 testRem();
844 comptime testRem();
843 try testRem();
844 comptime try testRem();
845845}
846fn testRem() void {
847 testing.expect((rem(i32, -5, 3) catch unreachable) == -2);
848 testing.expect((rem(i32, 5, 3) catch unreachable) == 2);
849 testing.expectError(error.NegativeDenominator, rem(i32, 10, -1));
850 testing.expectError(error.DivisionByZero, rem(i32, 10, 0));
846fn testRem() !void {
847 try testing.expect((rem(i32, -5, 3) catch unreachable) == -2);
848 try testing.expect((rem(i32, 5, 3) catch unreachable) == 2);
849 try testing.expectError(error.NegativeDenominator, rem(i32, 10, -1));
850 try testing.expectError(error.DivisionByZero, rem(i32, 10, 0));
851851
852 testing.expect((rem(f32, -5, 3) catch unreachable) == -2);
853 testing.expect((rem(f32, 5, 3) catch unreachable) == 2);
854 testing.expectError(error.NegativeDenominator, rem(f32, 10, -1));
855 testing.expectError(error.DivisionByZero, rem(f32, 10, 0));
852 try testing.expect((rem(f32, -5, 3) catch unreachable) == -2);
853 try testing.expect((rem(f32, 5, 3) catch unreachable) == 2);
854 try testing.expectError(error.NegativeDenominator, rem(f32, 10, -1));
855 try testing.expectError(error.DivisionByZero, rem(f32, 10, 0));
856856}
857857
858858/// Returns the absolute value of the integer parameter.
......@@ -883,11 +883,11 @@ pub fn absCast(x: anytype) switch (@typeInfo(@TypeOf(x))) {
883883}
884884
885885test "math.absCast" {
886 testing.expectEqual(@as(u1, 1), absCast(@as(i1, -1)));
887 testing.expectEqual(@as(u32, 999), absCast(@as(i32, -999)));
888 testing.expectEqual(@as(u32, 999), absCast(@as(i32, 999)));
889 testing.expectEqual(@as(u32, -minInt(i32)), absCast(@as(i32, minInt(i32))));
890 testing.expectEqual(999, absCast(-999));
886 try testing.expectEqual(@as(u1, 1), absCast(@as(i1, -1)));
887 try testing.expectEqual(@as(u32, 999), absCast(@as(i32, -999)));
888 try testing.expectEqual(@as(u32, 999), absCast(@as(i32, 999)));
889 try testing.expectEqual(@as(u32, -minInt(i32)), absCast(@as(i32, minInt(i32))));
890 try testing.expectEqual(999, absCast(-999));
891891}
892892
893893/// Returns the negation of the integer parameter.
......@@ -904,13 +904,13 @@ pub fn negateCast(x: anytype) !std.meta.Int(.signed, std.meta.bitCount(@TypeOf(x
904904}
905905
906906test "math.negateCast" {
907 testing.expect((negateCast(@as(u32, 999)) catch unreachable) == -999);
908 testing.expect(@TypeOf(negateCast(@as(u32, 999)) catch unreachable) == i32);
907 try testing.expect((negateCast(@as(u32, 999)) catch unreachable) == -999);
908 try testing.expect(@TypeOf(negateCast(@as(u32, 999)) catch unreachable) == i32);
909909
910 testing.expect((negateCast(@as(u32, -minInt(i32))) catch unreachable) == minInt(i32));
911 testing.expect(@TypeOf(negateCast(@as(u32, -minInt(i32))) catch unreachable) == i32);
910 try testing.expect((negateCast(@as(u32, -minInt(i32))) catch unreachable) == minInt(i32));
911 try testing.expect(@TypeOf(negateCast(@as(u32, -minInt(i32))) catch unreachable) == i32);
912912
913 testing.expectError(error.Overflow, negateCast(@as(u32, maxInt(i32) + 10)));
913 try testing.expectError(error.Overflow, negateCast(@as(u32, maxInt(i32) + 10)));
914914}
915915
916916/// Cast an integer to a different integer type. If the value doesn't fit,
......@@ -929,13 +929,13 @@ pub fn cast(comptime T: type, x: anytype) (error{Overflow}!T) {
929929}
930930
931931test "math.cast" {
932 testing.expectError(error.Overflow, cast(u8, @as(u32, 300)));
933 testing.expectError(error.Overflow, cast(i8, @as(i32, -200)));
934 testing.expectError(error.Overflow, cast(u8, @as(i8, -1)));
935 testing.expectError(error.Overflow, cast(u64, @as(i8, -1)));
932 try testing.expectError(error.Overflow, cast(u8, @as(u32, 300)));
933 try testing.expectError(error.Overflow, cast(i8, @as(i32, -200)));
934 try testing.expectError(error.Overflow, cast(u8, @as(i8, -1)));
935 try testing.expectError(error.Overflow, cast(u64, @as(i8, -1)));
936936
937 testing.expect((try cast(u8, @as(u32, 255))) == @as(u8, 255));
938 testing.expect(@TypeOf(try cast(u8, @as(u32, 255))) == u8);
937 try testing.expect((try cast(u8, @as(u32, 255))) == @as(u8, 255));
938 try testing.expect(@TypeOf(try cast(u8, @as(u32, 255))) == u8);
939939}
940940
941941pub const AlignCastError = error{UnalignedMemory};
......@@ -966,17 +966,17 @@ pub fn floorPowerOfTwo(comptime T: type, value: T) T {
966966}
967967
968968test "math.floorPowerOfTwo" {
969 testFloorPowerOfTwo();
970 comptime testFloorPowerOfTwo();
969 try testFloorPowerOfTwo();
970 comptime try testFloorPowerOfTwo();
971971}
972972
973fn testFloorPowerOfTwo() void {
974 testing.expect(floorPowerOfTwo(u32, 63) == 32);
975 testing.expect(floorPowerOfTwo(u32, 64) == 64);
976 testing.expect(floorPowerOfTwo(u32, 65) == 64);
977 testing.expect(floorPowerOfTwo(u4, 7) == 4);
978 testing.expect(floorPowerOfTwo(u4, 8) == 8);
979 testing.expect(floorPowerOfTwo(u4, 9) == 8);
973fn testFloorPowerOfTwo() !void {
974 try testing.expect(floorPowerOfTwo(u32, 63) == 32);
975 try testing.expect(floorPowerOfTwo(u32, 64) == 64);
976 try testing.expect(floorPowerOfTwo(u32, 65) == 64);
977 try testing.expect(floorPowerOfTwo(u4, 7) == 4);
978 try testing.expect(floorPowerOfTwo(u4, 8) == 8);
979 try testing.expect(floorPowerOfTwo(u4, 9) == 8);
980980}
981981
982982/// Returns the next power of two (if the value is not already a power of two).
......@@ -1012,20 +1012,20 @@ pub fn ceilPowerOfTwoAssert(comptime T: type, value: T) T {
10121012}
10131013
10141014test "math.ceilPowerOfTwoPromote" {
1015 testCeilPowerOfTwoPromote();
1016 comptime testCeilPowerOfTwoPromote();
1015 try testCeilPowerOfTwoPromote();
1016 comptime try testCeilPowerOfTwoPromote();
10171017}
10181018
1019fn testCeilPowerOfTwoPromote() void {
1020 testing.expectEqual(@as(u33, 1), ceilPowerOfTwoPromote(u32, 1));
1021 testing.expectEqual(@as(u33, 2), ceilPowerOfTwoPromote(u32, 2));
1022 testing.expectEqual(@as(u33, 64), ceilPowerOfTwoPromote(u32, 63));
1023 testing.expectEqual(@as(u33, 64), ceilPowerOfTwoPromote(u32, 64));
1024 testing.expectEqual(@as(u33, 128), ceilPowerOfTwoPromote(u32, 65));
1025 testing.expectEqual(@as(u6, 8), ceilPowerOfTwoPromote(u5, 7));
1026 testing.expectEqual(@as(u6, 8), ceilPowerOfTwoPromote(u5, 8));
1027 testing.expectEqual(@as(u6, 16), ceilPowerOfTwoPromote(u5, 9));
1028 testing.expectEqual(@as(u5, 16), ceilPowerOfTwoPromote(u4, 9));
1019fn testCeilPowerOfTwoPromote() !void {
1020 try testing.expectEqual(@as(u33, 1), ceilPowerOfTwoPromote(u32, 1));
1021 try testing.expectEqual(@as(u33, 2), ceilPowerOfTwoPromote(u32, 2));
1022 try testing.expectEqual(@as(u33, 64), ceilPowerOfTwoPromote(u32, 63));
1023 try testing.expectEqual(@as(u33, 64), ceilPowerOfTwoPromote(u32, 64));
1024 try testing.expectEqual(@as(u33, 128), ceilPowerOfTwoPromote(u32, 65));
1025 try testing.expectEqual(@as(u6, 8), ceilPowerOfTwoPromote(u5, 7));
1026 try testing.expectEqual(@as(u6, 8), ceilPowerOfTwoPromote(u5, 8));
1027 try testing.expectEqual(@as(u6, 16), ceilPowerOfTwoPromote(u5, 9));
1028 try testing.expectEqual(@as(u5, 16), ceilPowerOfTwoPromote(u4, 9));
10291029}
10301030
10311031test "math.ceilPowerOfTwo" {
......@@ -1034,15 +1034,15 @@ test "math.ceilPowerOfTwo" {
10341034}
10351035
10361036fn testCeilPowerOfTwo() !void {
1037 testing.expectEqual(@as(u32, 1), try ceilPowerOfTwo(u32, 1));
1038 testing.expectEqual(@as(u32, 2), try ceilPowerOfTwo(u32, 2));
1039 testing.expectEqual(@as(u32, 64), try ceilPowerOfTwo(u32, 63));
1040 testing.expectEqual(@as(u32, 64), try ceilPowerOfTwo(u32, 64));
1041 testing.expectEqual(@as(u32, 128), try ceilPowerOfTwo(u32, 65));
1042 testing.expectEqual(@as(u5, 8), try ceilPowerOfTwo(u5, 7));
1043 testing.expectEqual(@as(u5, 8), try ceilPowerOfTwo(u5, 8));
1044 testing.expectEqual(@as(u5, 16), try ceilPowerOfTwo(u5, 9));
1045 testing.expectError(error.Overflow, ceilPowerOfTwo(u4, 9));
1037 try testing.expectEqual(@as(u32, 1), try ceilPowerOfTwo(u32, 1));
1038 try testing.expectEqual(@as(u32, 2), try ceilPowerOfTwo(u32, 2));
1039 try testing.expectEqual(@as(u32, 64), try ceilPowerOfTwo(u32, 63));
1040 try testing.expectEqual(@as(u32, 64), try ceilPowerOfTwo(u32, 64));
1041 try testing.expectEqual(@as(u32, 128), try ceilPowerOfTwo(u32, 65));
1042 try testing.expectEqual(@as(u5, 8), try ceilPowerOfTwo(u5, 7));
1043 try testing.expectEqual(@as(u5, 8), try ceilPowerOfTwo(u5, 8));
1044 try testing.expectEqual(@as(u5, 16), try ceilPowerOfTwo(u5, 9));
1045 try testing.expectError(error.Overflow, ceilPowerOfTwo(u4, 9));
10461046}
10471047
10481048pub fn log2_int(comptime T: type, x: T) Log2Int(T) {
......@@ -1059,16 +1059,16 @@ pub fn log2_int_ceil(comptime T: type, x: T) Log2Int(T) {
10591059}
10601060
10611061test "std.math.log2_int_ceil" {
1062 testing.expect(log2_int_ceil(u32, 1) == 0);
1063 testing.expect(log2_int_ceil(u32, 2) == 1);
1064 testing.expect(log2_int_ceil(u32, 3) == 2);
1065 testing.expect(log2_int_ceil(u32, 4) == 2);
1066 testing.expect(log2_int_ceil(u32, 5) == 3);
1067 testing.expect(log2_int_ceil(u32, 6) == 3);
1068 testing.expect(log2_int_ceil(u32, 7) == 3);
1069 testing.expect(log2_int_ceil(u32, 8) == 3);
1070 testing.expect(log2_int_ceil(u32, 9) == 4);
1071 testing.expect(log2_int_ceil(u32, 10) == 4);
1062 try testing.expect(log2_int_ceil(u32, 1) == 0);
1063 try testing.expect(log2_int_ceil(u32, 2) == 1);
1064 try testing.expect(log2_int_ceil(u32, 3) == 2);
1065 try testing.expect(log2_int_ceil(u32, 4) == 2);
1066 try testing.expect(log2_int_ceil(u32, 5) == 3);
1067 try testing.expect(log2_int_ceil(u32, 6) == 3);
1068 try testing.expect(log2_int_ceil(u32, 7) == 3);
1069 try testing.expect(log2_int_ceil(u32, 8) == 3);
1070 try testing.expect(log2_int_ceil(u32, 9) == 4);
1071 try testing.expect(log2_int_ceil(u32, 10) == 4);
10721072}
10731073
10741074///Cast a value to a different type. If the value doesn't fit in, or can't be perfectly represented by,
......@@ -1112,15 +1112,15 @@ pub fn lossyCast(comptime T: type, value: anytype) T {
11121112}
11131113
11141114test "math.lossyCast" {
1115 testing.expect(lossyCast(i16, 70000.0) == @as(i16, 32767));
1116 testing.expect(lossyCast(u32, @as(i16, -255)) == @as(u32, 0));
1117 testing.expect(lossyCast(i9, @as(u32, 200)) == @as(i9, 200));
1115 try testing.expect(lossyCast(i16, 70000.0) == @as(i16, 32767));
1116 try testing.expect(lossyCast(u32, @as(i16, -255)) == @as(u32, 0));
1117 try testing.expect(lossyCast(i9, @as(u32, 200)) == @as(i9, 200));
11181118}
11191119
11201120test "math.f64_min" {
11211121 const f64_min_u64 = 0x0010000000000000;
11221122 const fmin: f64 = f64_min;
1123 testing.expect(@bitCast(u64, fmin) == f64_min_u64);
1123 try testing.expect(@bitCast(u64, fmin) == f64_min_u64);
11241124}
11251125
11261126pub fn maxInt(comptime T: type) comptime_int {
......@@ -1139,45 +1139,45 @@ pub fn minInt(comptime T: type) comptime_int {
11391139}
11401140
11411141test "minInt and maxInt" {
1142 testing.expect(maxInt(u0) == 0);
1143 testing.expect(maxInt(u1) == 1);
1144 testing.expect(maxInt(u8) == 255);
1145 testing.expect(maxInt(u16) == 65535);
1146 testing.expect(maxInt(u32) == 4294967295);
1147 testing.expect(maxInt(u64) == 18446744073709551615);
1148 testing.expect(maxInt(u128) == 340282366920938463463374607431768211455);
1149
1150 testing.expect(maxInt(i0) == 0);
1151 testing.expect(maxInt(i1) == 0);
1152 testing.expect(maxInt(i8) == 127);
1153 testing.expect(maxInt(i16) == 32767);
1154 testing.expect(maxInt(i32) == 2147483647);
1155 testing.expect(maxInt(i63) == 4611686018427387903);
1156 testing.expect(maxInt(i64) == 9223372036854775807);
1157 testing.expect(maxInt(i128) == 170141183460469231731687303715884105727);
1158
1159 testing.expect(minInt(u0) == 0);
1160 testing.expect(minInt(u1) == 0);
1161 testing.expect(minInt(u8) == 0);
1162 testing.expect(minInt(u16) == 0);
1163 testing.expect(minInt(u32) == 0);
1164 testing.expect(minInt(u63) == 0);
1165 testing.expect(minInt(u64) == 0);
1166 testing.expect(minInt(u128) == 0);
1167
1168 testing.expect(minInt(i0) == 0);
1169 testing.expect(minInt(i1) == -1);
1170 testing.expect(minInt(i8) == -128);
1171 testing.expect(minInt(i16) == -32768);
1172 testing.expect(minInt(i32) == -2147483648);
1173 testing.expect(minInt(i63) == -4611686018427387904);
1174 testing.expect(minInt(i64) == -9223372036854775808);
1175 testing.expect(minInt(i128) == -170141183460469231731687303715884105728);
1142 try testing.expect(maxInt(u0) == 0);
1143 try testing.expect(maxInt(u1) == 1);
1144 try testing.expect(maxInt(u8) == 255);
1145 try testing.expect(maxInt(u16) == 65535);
1146 try testing.expect(maxInt(u32) == 4294967295);
1147 try testing.expect(maxInt(u64) == 18446744073709551615);
1148 try testing.expect(maxInt(u128) == 340282366920938463463374607431768211455);
1149
1150 try testing.expect(maxInt(i0) == 0);
1151 try testing.expect(maxInt(i1) == 0);
1152 try testing.expect(maxInt(i8) == 127);
1153 try testing.expect(maxInt(i16) == 32767);
1154 try testing.expect(maxInt(i32) == 2147483647);
1155 try testing.expect(maxInt(i63) == 4611686018427387903);
1156 try testing.expect(maxInt(i64) == 9223372036854775807);
1157 try testing.expect(maxInt(i128) == 170141183460469231731687303715884105727);
1158
1159 try testing.expect(minInt(u0) == 0);
1160 try testing.expect(minInt(u1) == 0);
1161 try testing.expect(minInt(u8) == 0);
1162 try testing.expect(minInt(u16) == 0);
1163 try testing.expect(minInt(u32) == 0);
1164 try testing.expect(minInt(u63) == 0);
1165 try testing.expect(minInt(u64) == 0);
1166 try testing.expect(minInt(u128) == 0);
1167
1168 try testing.expect(minInt(i0) == 0);
1169 try testing.expect(minInt(i1) == -1);
1170 try testing.expect(minInt(i8) == -128);
1171 try testing.expect(minInt(i16) == -32768);
1172 try testing.expect(minInt(i32) == -2147483648);
1173 try testing.expect(minInt(i63) == -4611686018427387904);
1174 try testing.expect(minInt(i64) == -9223372036854775808);
1175 try testing.expect(minInt(i128) == -170141183460469231731687303715884105728);
11761176}
11771177
11781178test "max value type" {
11791179 const x: u32 = maxInt(i32);
1180 testing.expect(x == 2147483647);
1180 try testing.expect(x == 2147483647);
11811181}
11821182
11831183pub fn mulWide(comptime T: type, a: T, b: T) std.meta.Int(@typeInfo(T).Int.signedness, @typeInfo(T).Int.bits * 2) {
......@@ -1186,9 +1186,9 @@ pub fn mulWide(comptime T: type, a: T, b: T) std.meta.Int(@typeInfo(T).Int.signe
11861186}
11871187
11881188test "math.mulWide" {
1189 testing.expect(mulWide(u8, 5, 5) == 25);
1190 testing.expect(mulWide(i8, 5, -5) == -25);
1191 testing.expect(mulWide(u8, 100, 100) == 10000);
1189 try testing.expect(mulWide(u8, 5, 5) == 25);
1190 try testing.expect(mulWide(i8, 5, -5) == -25);
1191 try testing.expect(mulWide(u8, 100, 100) == 10000);
11921192}
11931193
11941194/// See also `CompareOperator`.
......@@ -1284,51 +1284,51 @@ pub fn compare(a: anytype, op: CompareOperator, b: anytype) bool {
12841284}
12851285
12861286test "compare between signed and unsigned" {
1287 testing.expect(compare(@as(i8, -1), .lt, @as(u8, 255)));
1288 testing.expect(compare(@as(i8, 2), .gt, @as(u8, 1)));
1289 testing.expect(!compare(@as(i8, -1), .gte, @as(u8, 255)));
1290 testing.expect(compare(@as(u8, 255), .gt, @as(i8, -1)));
1291 testing.expect(!compare(@as(u8, 255), .lte, @as(i8, -1)));
1292 testing.expect(compare(@as(i8, -1), .lt, @as(u9, 255)));
1293 testing.expect(!compare(@as(i8, -1), .gte, @as(u9, 255)));
1294 testing.expect(compare(@as(u9, 255), .gt, @as(i8, -1)));
1295 testing.expect(!compare(@as(u9, 255), .lte, @as(i8, -1)));
1296 testing.expect(compare(@as(i9, -1), .lt, @as(u8, 255)));
1297 testing.expect(!compare(@as(i9, -1), .gte, @as(u8, 255)));
1298 testing.expect(compare(@as(u8, 255), .gt, @as(i9, -1)));
1299 testing.expect(!compare(@as(u8, 255), .lte, @as(i9, -1)));
1300 testing.expect(compare(@as(u8, 1), .lt, @as(u8, 2)));
1301 testing.expect(@bitCast(u8, @as(i8, -1)) == @as(u8, 255));
1302 testing.expect(!compare(@as(u8, 255), .eq, @as(i8, -1)));
1303 testing.expect(compare(@as(u8, 1), .eq, @as(u8, 1)));
1287 try testing.expect(compare(@as(i8, -1), .lt, @as(u8, 255)));
1288 try testing.expect(compare(@as(i8, 2), .gt, @as(u8, 1)));
1289 try testing.expect(!compare(@as(i8, -1), .gte, @as(u8, 255)));
1290 try testing.expect(compare(@as(u8, 255), .gt, @as(i8, -1)));
1291 try testing.expect(!compare(@as(u8, 255), .lte, @as(i8, -1)));
1292 try testing.expect(compare(@as(i8, -1), .lt, @as(u9, 255)));
1293 try testing.expect(!compare(@as(i8, -1), .gte, @as(u9, 255)));
1294 try testing.expect(compare(@as(u9, 255), .gt, @as(i8, -1)));
1295 try testing.expect(!compare(@as(u9, 255), .lte, @as(i8, -1)));
1296 try testing.expect(compare(@as(i9, -1), .lt, @as(u8, 255)));
1297 try testing.expect(!compare(@as(i9, -1), .gte, @as(u8, 255)));
1298 try testing.expect(compare(@as(u8, 255), .gt, @as(i9, -1)));
1299 try testing.expect(!compare(@as(u8, 255), .lte, @as(i9, -1)));
1300 try testing.expect(compare(@as(u8, 1), .lt, @as(u8, 2)));
1301 try testing.expect(@bitCast(u8, @as(i8, -1)) == @as(u8, 255));
1302 try testing.expect(!compare(@as(u8, 255), .eq, @as(i8, -1)));
1303 try testing.expect(compare(@as(u8, 1), .eq, @as(u8, 1)));
13041304}
13051305
13061306test "order" {
1307 testing.expect(order(0, 0) == .eq);
1308 testing.expect(order(1, 0) == .gt);
1309 testing.expect(order(-1, 0) == .lt);
1307 try testing.expect(order(0, 0) == .eq);
1308 try testing.expect(order(1, 0) == .gt);
1309 try testing.expect(order(-1, 0) == .lt);
13101310}
13111311
13121312test "order.invert" {
1313 testing.expect(Order.invert(order(0, 0)) == .eq);
1314 testing.expect(Order.invert(order(1, 0)) == .lt);
1315 testing.expect(Order.invert(order(-1, 0)) == .gt);
1313 try testing.expect(Order.invert(order(0, 0)) == .eq);
1314 try testing.expect(Order.invert(order(1, 0)) == .lt);
1315 try testing.expect(Order.invert(order(-1, 0)) == .gt);
13161316}
13171317
13181318test "order.compare" {
1319 testing.expect(order(-1, 0).compare(.lt));
1320 testing.expect(order(-1, 0).compare(.lte));
1321 testing.expect(order(0, 0).compare(.lte));
1322 testing.expect(order(0, 0).compare(.eq));
1323 testing.expect(order(0, 0).compare(.gte));
1324 testing.expect(order(1, 0).compare(.gte));
1325 testing.expect(order(1, 0).compare(.gt));
1326 testing.expect(order(1, 0).compare(.neq));
1319 try testing.expect(order(-1, 0).compare(.lt));
1320 try testing.expect(order(-1, 0).compare(.lte));
1321 try testing.expect(order(0, 0).compare(.lte));
1322 try testing.expect(order(0, 0).compare(.eq));
1323 try testing.expect(order(0, 0).compare(.gte));
1324 try testing.expect(order(1, 0).compare(.gte));
1325 try testing.expect(order(1, 0).compare(.gt));
1326 try testing.expect(order(1, 0).compare(.neq));
13271327}
13281328
13291329test "math.comptime" {
13301330 const v = comptime (sin(@as(f32, 1)) + ln(@as(f32, 5)));
1331 testing.expect(v == sin(@as(f32, 1)) + ln(@as(f32, 5)));
1331 try testing.expect(v == sin(@as(f32, 1)) + ln(@as(f32, 5)));
13321332}
13331333
13341334/// Returns a mask of all ones if value is true,
......@@ -1354,26 +1354,26 @@ pub fn boolMask(comptime MaskInt: type, value: bool) callconv(.Inline) MaskInt {
13541354
13551355test "boolMask" {
13561356 const runTest = struct {
1357 fn runTest() void {
1358 testing.expectEqual(@as(u1, 0), boolMask(u1, false));
1359 testing.expectEqual(@as(u1, 1), boolMask(u1, true));
1357 fn runTest() !void {
1358 try testing.expectEqual(@as(u1, 0), boolMask(u1, false));
1359 try testing.expectEqual(@as(u1, 1), boolMask(u1, true));
13601360
1361 testing.expectEqual(@as(i1, 0), boolMask(i1, false));
1362 testing.expectEqual(@as(i1, -1), boolMask(i1, true));
1361 try testing.expectEqual(@as(i1, 0), boolMask(i1, false));
1362 try testing.expectEqual(@as(i1, -1), boolMask(i1, true));
13631363
1364 testing.expectEqual(@as(u13, 0), boolMask(u13, false));
1365 testing.expectEqual(@as(u13, 0x1FFF), boolMask(u13, true));
1364 try testing.expectEqual(@as(u13, 0), boolMask(u13, false));
1365 try testing.expectEqual(@as(u13, 0x1FFF), boolMask(u13, true));
13661366
1367 testing.expectEqual(@as(i13, 0), boolMask(i13, false));
1368 testing.expectEqual(@as(i13, -1), boolMask(i13, true));
1367 try testing.expectEqual(@as(i13, 0), boolMask(i13, false));
1368 try testing.expectEqual(@as(i13, -1), boolMask(i13, true));
13691369
1370 testing.expectEqual(@as(u32, 0), boolMask(u32, false));
1371 testing.expectEqual(@as(u32, 0xFFFF_FFFF), boolMask(u32, true));
1370 try testing.expectEqual(@as(u32, 0), boolMask(u32, false));
1371 try testing.expectEqual(@as(u32, 0xFFFF_FFFF), boolMask(u32, true));
13721372
1373 testing.expectEqual(@as(i32, 0), boolMask(i32, false));
1374 testing.expectEqual(@as(i32, -1), boolMask(i32, true));
1373 try testing.expectEqual(@as(i32, 0), boolMask(i32, false));
1374 try testing.expectEqual(@as(i32, -1), boolMask(i32, true));
13751375 }
13761376 }.runTest;
1377 runTest();
1378 comptime runTest();
1377 try runTest();
1378 comptime try runTest();
13791379}
lib/std/math/acos.zig+18-18
......@@ -154,38 +154,38 @@ fn acos64(x: f64) f64 {
154154}
155155
156156test "math.acos" {
157 expect(acos(@as(f32, 0.0)) == acos32(0.0));
158 expect(acos(@as(f64, 0.0)) == acos64(0.0));
157 try expect(acos(@as(f32, 0.0)) == acos32(0.0));
158 try expect(acos(@as(f64, 0.0)) == acos64(0.0));
159159}
160160
161161test "math.acos32" {
162162 const epsilon = 0.000001;
163163
164 expect(math.approxEqAbs(f32, acos32(0.0), 1.570796, epsilon));
165 expect(math.approxEqAbs(f32, acos32(0.2), 1.369438, epsilon));
166 expect(math.approxEqAbs(f32, acos32(0.3434), 1.220262, epsilon));
167 expect(math.approxEqAbs(f32, acos32(0.5), 1.047198, epsilon));
168 expect(math.approxEqAbs(f32, acos32(0.8923), 0.468382, epsilon));
169 expect(math.approxEqAbs(f32, acos32(-0.2), 1.772154, epsilon));
164 try expect(math.approxEqAbs(f32, acos32(0.0), 1.570796, epsilon));
165 try expect(math.approxEqAbs(f32, acos32(0.2), 1.369438, epsilon));
166 try expect(math.approxEqAbs(f32, acos32(0.3434), 1.220262, epsilon));
167 try expect(math.approxEqAbs(f32, acos32(0.5), 1.047198, epsilon));
168 try expect(math.approxEqAbs(f32, acos32(0.8923), 0.468382, epsilon));
169 try expect(math.approxEqAbs(f32, acos32(-0.2), 1.772154, epsilon));
170170}
171171
172172test "math.acos64" {
173173 const epsilon = 0.000001;
174174
175 expect(math.approxEqAbs(f64, acos64(0.0), 1.570796, epsilon));
176 expect(math.approxEqAbs(f64, acos64(0.2), 1.369438, epsilon));
177 expect(math.approxEqAbs(f64, acos64(0.3434), 1.220262, epsilon));
178 expect(math.approxEqAbs(f64, acos64(0.5), 1.047198, epsilon));
179 expect(math.approxEqAbs(f64, acos64(0.8923), 0.468382, epsilon));
180 expect(math.approxEqAbs(f64, acos64(-0.2), 1.772154, epsilon));
175 try expect(math.approxEqAbs(f64, acos64(0.0), 1.570796, epsilon));
176 try expect(math.approxEqAbs(f64, acos64(0.2), 1.369438, epsilon));
177 try expect(math.approxEqAbs(f64, acos64(0.3434), 1.220262, epsilon));
178 try expect(math.approxEqAbs(f64, acos64(0.5), 1.047198, epsilon));
179 try expect(math.approxEqAbs(f64, acos64(0.8923), 0.468382, epsilon));
180 try expect(math.approxEqAbs(f64, acos64(-0.2), 1.772154, epsilon));
181181}
182182
183183test "math.acos32.special" {
184 expect(math.isNan(acos32(-2)));
185 expect(math.isNan(acos32(1.5)));
184 try expect(math.isNan(acos32(-2)));
185 try expect(math.isNan(acos32(1.5)));
186186}
187187
188188test "math.acos64.special" {
189 expect(math.isNan(acos64(-2)));
190 expect(math.isNan(acos64(1.5)));
189 try expect(math.isNan(acos64(-2)));
190 try expect(math.isNan(acos64(1.5)));
191191}
lib/std/math/acosh.zig+14-14
......@@ -65,34 +65,34 @@ fn acosh64(x: f64) f64 {
6565}
6666
6767test "math.acosh" {
68 expect(acosh(@as(f32, 1.5)) == acosh32(1.5));
69 expect(acosh(@as(f64, 1.5)) == acosh64(1.5));
68 try expect(acosh(@as(f32, 1.5)) == acosh32(1.5));
69 try expect(acosh(@as(f64, 1.5)) == acosh64(1.5));
7070}
7171
7272test "math.acosh32" {
7373 const epsilon = 0.000001;
7474
75 expect(math.approxEqAbs(f32, acosh32(1.5), 0.962424, epsilon));
76 expect(math.approxEqAbs(f32, acosh32(37.45), 4.315976, epsilon));
77 expect(math.approxEqAbs(f32, acosh32(89.123), 5.183133, epsilon));
78 expect(math.approxEqAbs(f32, acosh32(123123.234375), 12.414088, epsilon));
75 try expect(math.approxEqAbs(f32, acosh32(1.5), 0.962424, epsilon));
76 try expect(math.approxEqAbs(f32, acosh32(37.45), 4.315976, epsilon));
77 try expect(math.approxEqAbs(f32, acosh32(89.123), 5.183133, epsilon));
78 try expect(math.approxEqAbs(f32, acosh32(123123.234375), 12.414088, epsilon));
7979}
8080
8181test "math.acosh64" {
8282 const epsilon = 0.000001;
8383
84 expect(math.approxEqAbs(f64, acosh64(1.5), 0.962424, epsilon));
85 expect(math.approxEqAbs(f64, acosh64(37.45), 4.315976, epsilon));
86 expect(math.approxEqAbs(f64, acosh64(89.123), 5.183133, epsilon));
87 expect(math.approxEqAbs(f64, acosh64(123123.234375), 12.414088, epsilon));
84 try expect(math.approxEqAbs(f64, acosh64(1.5), 0.962424, epsilon));
85 try expect(math.approxEqAbs(f64, acosh64(37.45), 4.315976, epsilon));
86 try expect(math.approxEqAbs(f64, acosh64(89.123), 5.183133, epsilon));
87 try expect(math.approxEqAbs(f64, acosh64(123123.234375), 12.414088, epsilon));
8888}
8989
9090test "math.acosh32.special" {
91 expect(math.isNan(acosh32(math.nan(f32))));
92 expect(math.isSignalNan(acosh32(0.5)));
91 try expect(math.isNan(acosh32(math.nan(f32))));
92 try expect(math.isSignalNan(acosh32(0.5)));
9393}
9494
9595test "math.acosh64.special" {
96 expect(math.isNan(acosh64(math.nan(f64))));
97 expect(math.isSignalNan(acosh64(0.5)));
96 try expect(math.isNan(acosh64(math.nan(f64))));
97 try expect(math.isSignalNan(acosh64(0.5)));
9898}
lib/std/math/asin.zig+22-22
......@@ -147,42 +147,42 @@ fn asin64(x: f64) f64 {
147147}
148148
149149test "math.asin" {
150 expect(asin(@as(f32, 0.0)) == asin32(0.0));
151 expect(asin(@as(f64, 0.0)) == asin64(0.0));
150 try expect(asin(@as(f32, 0.0)) == asin32(0.0));
151 try expect(asin(@as(f64, 0.0)) == asin64(0.0));
152152}
153153
154154test "math.asin32" {
155155 const epsilon = 0.000001;
156156
157 expect(math.approxEqAbs(f32, asin32(0.0), 0.0, epsilon));
158 expect(math.approxEqAbs(f32, asin32(0.2), 0.201358, epsilon));
159 expect(math.approxEqAbs(f32, asin32(-0.2), -0.201358, epsilon));
160 expect(math.approxEqAbs(f32, asin32(0.3434), 0.350535, epsilon));
161 expect(math.approxEqAbs(f32, asin32(0.5), 0.523599, epsilon));
162 expect(math.approxEqAbs(f32, asin32(0.8923), 1.102415, epsilon));
157 try expect(math.approxEqAbs(f32, asin32(0.0), 0.0, epsilon));
158 try expect(math.approxEqAbs(f32, asin32(0.2), 0.201358, epsilon));
159 try expect(math.approxEqAbs(f32, asin32(-0.2), -0.201358, epsilon));
160 try expect(math.approxEqAbs(f32, asin32(0.3434), 0.350535, epsilon));
161 try expect(math.approxEqAbs(f32, asin32(0.5), 0.523599, epsilon));
162 try expect(math.approxEqAbs(f32, asin32(0.8923), 1.102415, epsilon));
163163}
164164
165165test "math.asin64" {
166166 const epsilon = 0.000001;
167167
168 expect(math.approxEqAbs(f64, asin64(0.0), 0.0, epsilon));
169 expect(math.approxEqAbs(f64, asin64(0.2), 0.201358, epsilon));
170 expect(math.approxEqAbs(f64, asin64(-0.2), -0.201358, epsilon));
171 expect(math.approxEqAbs(f64, asin64(0.3434), 0.350535, epsilon));
172 expect(math.approxEqAbs(f64, asin64(0.5), 0.523599, epsilon));
173 expect(math.approxEqAbs(f64, asin64(0.8923), 1.102415, epsilon));
168 try expect(math.approxEqAbs(f64, asin64(0.0), 0.0, epsilon));
169 try expect(math.approxEqAbs(f64, asin64(0.2), 0.201358, epsilon));
170 try expect(math.approxEqAbs(f64, asin64(-0.2), -0.201358, epsilon));
171 try expect(math.approxEqAbs(f64, asin64(0.3434), 0.350535, epsilon));
172 try expect(math.approxEqAbs(f64, asin64(0.5), 0.523599, epsilon));
173 try expect(math.approxEqAbs(f64, asin64(0.8923), 1.102415, epsilon));
174174}
175175
176176test "math.asin32.special" {
177 expect(asin32(0.0) == 0.0);
178 expect(asin32(-0.0) == -0.0);
179 expect(math.isNan(asin32(-2)));
180 expect(math.isNan(asin32(1.5)));
177 try expect(asin32(0.0) == 0.0);
178 try expect(asin32(-0.0) == -0.0);
179 try expect(math.isNan(asin32(-2)));
180 try expect(math.isNan(asin32(1.5)));
181181}
182182
183183test "math.asin64.special" {
184 expect(asin64(0.0) == 0.0);
185 expect(asin64(-0.0) == -0.0);
186 expect(math.isNan(asin64(-2)));
187 expect(math.isNan(asin64(1.5)));
184 try expect(asin64(0.0) == 0.0);
185 try expect(asin64(-0.0) == -0.0);
186 try expect(math.isNan(asin64(-2)));
187 try expect(math.isNan(asin64(1.5)));
188188}
lib/std/math/asinh.zig+26-26
......@@ -94,46 +94,46 @@ fn asinh64(x: f64) f64 {
9494}
9595
9696test "math.asinh" {
97 expect(asinh(@as(f32, 0.0)) == asinh32(0.0));
98 expect(asinh(@as(f64, 0.0)) == asinh64(0.0));
97 try expect(asinh(@as(f32, 0.0)) == asinh32(0.0));
98 try expect(asinh(@as(f64, 0.0)) == asinh64(0.0));
9999}
100100
101101test "math.asinh32" {
102102 const epsilon = 0.000001;
103103
104 expect(math.approxEqAbs(f32, asinh32(0.0), 0.0, epsilon));
105 expect(math.approxEqAbs(f32, asinh32(0.2), 0.198690, epsilon));
106 expect(math.approxEqAbs(f32, asinh32(0.8923), 0.803133, epsilon));
107 expect(math.approxEqAbs(f32, asinh32(1.5), 1.194763, epsilon));
108 expect(math.approxEqAbs(f32, asinh32(37.45), 4.316332, epsilon));
109 expect(math.approxEqAbs(f32, asinh32(89.123), 5.183196, epsilon));
110 expect(math.approxEqAbs(f32, asinh32(123123.234375), 12.414088, epsilon));
104 try expect(math.approxEqAbs(f32, asinh32(0.0), 0.0, epsilon));
105 try expect(math.approxEqAbs(f32, asinh32(0.2), 0.198690, epsilon));
106 try expect(math.approxEqAbs(f32, asinh32(0.8923), 0.803133, epsilon));
107 try expect(math.approxEqAbs(f32, asinh32(1.5), 1.194763, epsilon));
108 try expect(math.approxEqAbs(f32, asinh32(37.45), 4.316332, epsilon));
109 try expect(math.approxEqAbs(f32, asinh32(89.123), 5.183196, epsilon));
110 try expect(math.approxEqAbs(f32, asinh32(123123.234375), 12.414088, epsilon));
111111}
112112
113113test "math.asinh64" {
114114 const epsilon = 0.000001;
115115
116 expect(math.approxEqAbs(f64, asinh64(0.0), 0.0, epsilon));
117 expect(math.approxEqAbs(f64, asinh64(0.2), 0.198690, epsilon));
118 expect(math.approxEqAbs(f64, asinh64(0.8923), 0.803133, epsilon));
119 expect(math.approxEqAbs(f64, asinh64(1.5), 1.194763, epsilon));
120 expect(math.approxEqAbs(f64, asinh64(37.45), 4.316332, epsilon));
121 expect(math.approxEqAbs(f64, asinh64(89.123), 5.183196, epsilon));
122 expect(math.approxEqAbs(f64, asinh64(123123.234375), 12.414088, epsilon));
116 try expect(math.approxEqAbs(f64, asinh64(0.0), 0.0, epsilon));
117 try expect(math.approxEqAbs(f64, asinh64(0.2), 0.198690, epsilon));
118 try expect(math.approxEqAbs(f64, asinh64(0.8923), 0.803133, epsilon));
119 try expect(math.approxEqAbs(f64, asinh64(1.5), 1.194763, epsilon));
120 try expect(math.approxEqAbs(f64, asinh64(37.45), 4.316332, epsilon));
121 try expect(math.approxEqAbs(f64, asinh64(89.123), 5.183196, epsilon));
122 try expect(math.approxEqAbs(f64, asinh64(123123.234375), 12.414088, epsilon));
123123}
124124
125125test "math.asinh32.special" {
126 expect(asinh32(0.0) == 0.0);
127 expect(asinh32(-0.0) == -0.0);
128 expect(math.isPositiveInf(asinh32(math.inf(f32))));
129 expect(math.isNegativeInf(asinh32(-math.inf(f32))));
130 expect(math.isNan(asinh32(math.nan(f32))));
126 try expect(asinh32(0.0) == 0.0);
127 try expect(asinh32(-0.0) == -0.0);
128 try expect(math.isPositiveInf(asinh32(math.inf(f32))));
129 try expect(math.isNegativeInf(asinh32(-math.inf(f32))));
130 try expect(math.isNan(asinh32(math.nan(f32))));
131131}
132132
133133test "math.asinh64.special" {
134 expect(asinh64(0.0) == 0.0);
135 expect(asinh64(-0.0) == -0.0);
136 expect(math.isPositiveInf(asinh64(math.inf(f64))));
137 expect(math.isNegativeInf(asinh64(-math.inf(f64))));
138 expect(math.isNan(asinh64(math.nan(f64))));
134 try expect(asinh64(0.0) == 0.0);
135 try expect(asinh64(-0.0) == -0.0);
136 try expect(math.isPositiveInf(asinh64(math.inf(f64))));
137 try expect(math.isNegativeInf(asinh64(-math.inf(f64))));
138 try expect(math.isNan(asinh64(math.nan(f64))));
139139}
lib/std/math/atan.zig+20-20
......@@ -217,44 +217,44 @@ fn atan64(x_: f64) f64 {
217217}
218218
219219test "math.atan" {
220 expect(@bitCast(u32, atan(@as(f32, 0.2))) == @bitCast(u32, atan32(0.2)));
221 expect(atan(@as(f64, 0.2)) == atan64(0.2));
220 try expect(@bitCast(u32, atan(@as(f32, 0.2))) == @bitCast(u32, atan32(0.2)));
221 try expect(atan(@as(f64, 0.2)) == atan64(0.2));
222222}
223223
224224test "math.atan32" {
225225 const epsilon = 0.000001;
226226
227 expect(math.approxEqAbs(f32, atan32(0.2), 0.197396, epsilon));
228 expect(math.approxEqAbs(f32, atan32(-0.2), -0.197396, epsilon));
229 expect(math.approxEqAbs(f32, atan32(0.3434), 0.330783, epsilon));
230 expect(math.approxEqAbs(f32, atan32(0.8923), 0.728545, epsilon));
231 expect(math.approxEqAbs(f32, atan32(1.5), 0.982794, epsilon));
227 try expect(math.approxEqAbs(f32, atan32(0.2), 0.197396, epsilon));
228 try expect(math.approxEqAbs(f32, atan32(-0.2), -0.197396, epsilon));
229 try expect(math.approxEqAbs(f32, atan32(0.3434), 0.330783, epsilon));
230 try expect(math.approxEqAbs(f32, atan32(0.8923), 0.728545, epsilon));
231 try expect(math.approxEqAbs(f32, atan32(1.5), 0.982794, epsilon));
232232}
233233
234234test "math.atan64" {
235235 const epsilon = 0.000001;
236236
237 expect(math.approxEqAbs(f64, atan64(0.2), 0.197396, epsilon));
238 expect(math.approxEqAbs(f64, atan64(-0.2), -0.197396, epsilon));
239 expect(math.approxEqAbs(f64, atan64(0.3434), 0.330783, epsilon));
240 expect(math.approxEqAbs(f64, atan64(0.8923), 0.728545, epsilon));
241 expect(math.approxEqAbs(f64, atan64(1.5), 0.982794, epsilon));
237 try expect(math.approxEqAbs(f64, atan64(0.2), 0.197396, epsilon));
238 try expect(math.approxEqAbs(f64, atan64(-0.2), -0.197396, epsilon));
239 try expect(math.approxEqAbs(f64, atan64(0.3434), 0.330783, epsilon));
240 try expect(math.approxEqAbs(f64, atan64(0.8923), 0.728545, epsilon));
241 try expect(math.approxEqAbs(f64, atan64(1.5), 0.982794, epsilon));
242242}
243243
244244test "math.atan32.special" {
245245 const epsilon = 0.000001;
246246
247 expect(atan32(0.0) == 0.0);
248 expect(atan32(-0.0) == -0.0);
249 expect(math.approxEqAbs(f32, atan32(math.inf(f32)), math.pi / 2.0, epsilon));
250 expect(math.approxEqAbs(f32, atan32(-math.inf(f32)), -math.pi / 2.0, epsilon));
247 try expect(atan32(0.0) == 0.0);
248 try expect(atan32(-0.0) == -0.0);
249 try expect(math.approxEqAbs(f32, atan32(math.inf(f32)), math.pi / 2.0, epsilon));
250 try expect(math.approxEqAbs(f32, atan32(-math.inf(f32)), -math.pi / 2.0, epsilon));
251251}
252252
253253test "math.atan64.special" {
254254 const epsilon = 0.000001;
255255
256 expect(atan64(0.0) == 0.0);
257 expect(atan64(-0.0) == -0.0);
258 expect(math.approxEqAbs(f64, atan64(math.inf(f64)), math.pi / 2.0, epsilon));
259 expect(math.approxEqAbs(f64, atan64(-math.inf(f64)), -math.pi / 2.0, epsilon));
256 try expect(atan64(0.0) == 0.0);
257 try expect(atan64(-0.0) == -0.0);
258 try expect(math.approxEqAbs(f64, atan64(math.inf(f64)), math.pi / 2.0, epsilon));
259 try expect(math.approxEqAbs(f64, atan64(-math.inf(f64)), -math.pi / 2.0, epsilon));
260260}
lib/std/math/atan2.zig+52-52
......@@ -217,78 +217,78 @@ fn atan2_64(y: f64, x: f64) f64 {
217217}
218218
219219test "math.atan2" {
220 expect(atan2(f32, 0.2, 0.21) == atan2_32(0.2, 0.21));
221 expect(atan2(f64, 0.2, 0.21) == atan2_64(0.2, 0.21));
220 try expect(atan2(f32, 0.2, 0.21) == atan2_32(0.2, 0.21));
221 try expect(atan2(f64, 0.2, 0.21) == atan2_64(0.2, 0.21));
222222}
223223
224224test "math.atan2_32" {
225225 const epsilon = 0.000001;
226226
227 expect(math.approxEqAbs(f32, atan2_32(0.0, 0.0), 0.0, epsilon));
228 expect(math.approxEqAbs(f32, atan2_32(0.2, 0.2), 0.785398, epsilon));
229 expect(math.approxEqAbs(f32, atan2_32(-0.2, 0.2), -0.785398, epsilon));
230 expect(math.approxEqAbs(f32, atan2_32(0.2, -0.2), 2.356194, epsilon));
231 expect(math.approxEqAbs(f32, atan2_32(-0.2, -0.2), -2.356194, epsilon));
232 expect(math.approxEqAbs(f32, atan2_32(0.34, -0.4), 2.437099, epsilon));
233 expect(math.approxEqAbs(f32, atan2_32(0.34, 1.243), 0.267001, epsilon));
227 try expect(math.approxEqAbs(f32, atan2_32(0.0, 0.0), 0.0, epsilon));
228 try expect(math.approxEqAbs(f32, atan2_32(0.2, 0.2), 0.785398, epsilon));
229 try expect(math.approxEqAbs(f32, atan2_32(-0.2, 0.2), -0.785398, epsilon));
230 try expect(math.approxEqAbs(f32, atan2_32(0.2, -0.2), 2.356194, epsilon));
231 try expect(math.approxEqAbs(f32, atan2_32(-0.2, -0.2), -2.356194, epsilon));
232 try expect(math.approxEqAbs(f32, atan2_32(0.34, -0.4), 2.437099, epsilon));
233 try expect(math.approxEqAbs(f32, atan2_32(0.34, 1.243), 0.267001, epsilon));
234234}
235235
236236test "math.atan2_64" {
237237 const epsilon = 0.000001;
238238
239 expect(math.approxEqAbs(f64, atan2_64(0.0, 0.0), 0.0, epsilon));
240 expect(math.approxEqAbs(f64, atan2_64(0.2, 0.2), 0.785398, epsilon));
241 expect(math.approxEqAbs(f64, atan2_64(-0.2, 0.2), -0.785398, epsilon));
242 expect(math.approxEqAbs(f64, atan2_64(0.2, -0.2), 2.356194, epsilon));
243 expect(math.approxEqAbs(f64, atan2_64(-0.2, -0.2), -2.356194, epsilon));
244 expect(math.approxEqAbs(f64, atan2_64(0.34, -0.4), 2.437099, epsilon));
245 expect(math.approxEqAbs(f64, atan2_64(0.34, 1.243), 0.267001, epsilon));
239 try expect(math.approxEqAbs(f64, atan2_64(0.0, 0.0), 0.0, epsilon));
240 try expect(math.approxEqAbs(f64, atan2_64(0.2, 0.2), 0.785398, epsilon));
241 try expect(math.approxEqAbs(f64, atan2_64(-0.2, 0.2), -0.785398, epsilon));
242 try expect(math.approxEqAbs(f64, atan2_64(0.2, -0.2), 2.356194, epsilon));
243 try expect(math.approxEqAbs(f64, atan2_64(-0.2, -0.2), -2.356194, epsilon));
244 try expect(math.approxEqAbs(f64, atan2_64(0.34, -0.4), 2.437099, epsilon));
245 try expect(math.approxEqAbs(f64, atan2_64(0.34, 1.243), 0.267001, epsilon));
246246}
247247
248248test "math.atan2_32.special" {
249249 const epsilon = 0.000001;
250250
251 expect(math.isNan(atan2_32(1.0, math.nan(f32))));
252 expect(math.isNan(atan2_32(math.nan(f32), 1.0)));
253 expect(atan2_32(0.0, 5.0) == 0.0);
254 expect(atan2_32(-0.0, 5.0) == -0.0);
255 expect(math.approxEqAbs(f32, atan2_32(0.0, -5.0), math.pi, epsilon));
251 try expect(math.isNan(atan2_32(1.0, math.nan(f32))));
252 try expect(math.isNan(atan2_32(math.nan(f32), 1.0)));
253 try expect(atan2_32(0.0, 5.0) == 0.0);
254 try expect(atan2_32(-0.0, 5.0) == -0.0);
255 try expect(math.approxEqAbs(f32, atan2_32(0.0, -5.0), math.pi, epsilon));
256256 //expect(math.approxEqAbs(f32, atan2_32(-0.0, -5.0), -math.pi, .{.rel=0,.abs=epsilon})); TODO support negative zero?
257 expect(math.approxEqAbs(f32, atan2_32(1.0, 0.0), math.pi / 2.0, epsilon));
258 expect(math.approxEqAbs(f32, atan2_32(1.0, -0.0), math.pi / 2.0, epsilon));
259 expect(math.approxEqAbs(f32, atan2_32(-1.0, 0.0), -math.pi / 2.0, epsilon));
260 expect(math.approxEqAbs(f32, atan2_32(-1.0, -0.0), -math.pi / 2.0, epsilon));
261 expect(math.approxEqAbs(f32, atan2_32(math.inf(f32), math.inf(f32)), math.pi / 4.0, epsilon));
262 expect(math.approxEqAbs(f32, atan2_32(-math.inf(f32), math.inf(f32)), -math.pi / 4.0, epsilon));
263 expect(math.approxEqAbs(f32, atan2_32(math.inf(f32), -math.inf(f32)), 3.0 * math.pi / 4.0, epsilon));
264 expect(math.approxEqAbs(f32, atan2_32(-math.inf(f32), -math.inf(f32)), -3.0 * math.pi / 4.0, epsilon));
265 expect(atan2_32(1.0, math.inf(f32)) == 0.0);
266 expect(math.approxEqAbs(f32, atan2_32(1.0, -math.inf(f32)), math.pi, epsilon));
267 expect(math.approxEqAbs(f32, atan2_32(-1.0, -math.inf(f32)), -math.pi, epsilon));
268 expect(math.approxEqAbs(f32, atan2_32(math.inf(f32), 1.0), math.pi / 2.0, epsilon));
269 expect(math.approxEqAbs(f32, atan2_32(-math.inf(f32), 1.0), -math.pi / 2.0, epsilon));
257 try expect(math.approxEqAbs(f32, atan2_32(1.0, 0.0), math.pi / 2.0, epsilon));
258 try expect(math.approxEqAbs(f32, atan2_32(1.0, -0.0), math.pi / 2.0, epsilon));
259 try expect(math.approxEqAbs(f32, atan2_32(-1.0, 0.0), -math.pi / 2.0, epsilon));
260 try expect(math.approxEqAbs(f32, atan2_32(-1.0, -0.0), -math.pi / 2.0, epsilon));
261 try expect(math.approxEqAbs(f32, atan2_32(math.inf(f32), math.inf(f32)), math.pi / 4.0, epsilon));
262 try expect(math.approxEqAbs(f32, atan2_32(-math.inf(f32), math.inf(f32)), -math.pi / 4.0, epsilon));
263 try expect(math.approxEqAbs(f32, atan2_32(math.inf(f32), -math.inf(f32)), 3.0 * math.pi / 4.0, epsilon));
264 try expect(math.approxEqAbs(f32, atan2_32(-math.inf(f32), -math.inf(f32)), -3.0 * math.pi / 4.0, epsilon));
265 try expect(atan2_32(1.0, math.inf(f32)) == 0.0);
266 try expect(math.approxEqAbs(f32, atan2_32(1.0, -math.inf(f32)), math.pi, epsilon));
267 try expect(math.approxEqAbs(f32, atan2_32(-1.0, -math.inf(f32)), -math.pi, epsilon));
268 try expect(math.approxEqAbs(f32, atan2_32(math.inf(f32), 1.0), math.pi / 2.0, epsilon));
269 try expect(math.approxEqAbs(f32, atan2_32(-math.inf(f32), 1.0), -math.pi / 2.0, epsilon));
270270}
271271
272272test "math.atan2_64.special" {
273273 const epsilon = 0.000001;
274274
275 expect(math.isNan(atan2_64(1.0, math.nan(f64))));
276 expect(math.isNan(atan2_64(math.nan(f64), 1.0)));
277 expect(atan2_64(0.0, 5.0) == 0.0);
278 expect(atan2_64(-0.0, 5.0) == -0.0);
279 expect(math.approxEqAbs(f64, atan2_64(0.0, -5.0), math.pi, epsilon));
275 try expect(math.isNan(atan2_64(1.0, math.nan(f64))));
276 try expect(math.isNan(atan2_64(math.nan(f64), 1.0)));
277 try expect(atan2_64(0.0, 5.0) == 0.0);
278 try expect(atan2_64(-0.0, 5.0) == -0.0);
279 try expect(math.approxEqAbs(f64, atan2_64(0.0, -5.0), math.pi, epsilon));
280280 //expect(math.approxEqAbs(f64, atan2_64(-0.0, -5.0), -math.pi, .{.rel=0,.abs=epsilon})); TODO support negative zero?
281 expect(math.approxEqAbs(f64, atan2_64(1.0, 0.0), math.pi / 2.0, epsilon));
282 expect(math.approxEqAbs(f64, atan2_64(1.0, -0.0), math.pi / 2.0, epsilon));
283 expect(math.approxEqAbs(f64, atan2_64(-1.0, 0.0), -math.pi / 2.0, epsilon));
284 expect(math.approxEqAbs(f64, atan2_64(-1.0, -0.0), -math.pi / 2.0, epsilon));
285 expect(math.approxEqAbs(f64, atan2_64(math.inf(f64), math.inf(f64)), math.pi / 4.0, epsilon));
286 expect(math.approxEqAbs(f64, atan2_64(-math.inf(f64), math.inf(f64)), -math.pi / 4.0, epsilon));
287 expect(math.approxEqAbs(f64, atan2_64(math.inf(f64), -math.inf(f64)), 3.0 * math.pi / 4.0, epsilon));
288 expect(math.approxEqAbs(f64, atan2_64(-math.inf(f64), -math.inf(f64)), -3.0 * math.pi / 4.0, epsilon));
289 expect(atan2_64(1.0, math.inf(f64)) == 0.0);
290 expect(math.approxEqAbs(f64, atan2_64(1.0, -math.inf(f64)), math.pi, epsilon));
291 expect(math.approxEqAbs(f64, atan2_64(-1.0, -math.inf(f64)), -math.pi, epsilon));
292 expect(math.approxEqAbs(f64, atan2_64(math.inf(f64), 1.0), math.pi / 2.0, epsilon));
293 expect(math.approxEqAbs(f64, atan2_64(-math.inf(f64), 1.0), -math.pi / 2.0, epsilon));
281 try expect(math.approxEqAbs(f64, atan2_64(1.0, 0.0), math.pi / 2.0, epsilon));
282 try expect(math.approxEqAbs(f64, atan2_64(1.0, -0.0), math.pi / 2.0, epsilon));
283 try expect(math.approxEqAbs(f64, atan2_64(-1.0, 0.0), -math.pi / 2.0, epsilon));
284 try expect(math.approxEqAbs(f64, atan2_64(-1.0, -0.0), -math.pi / 2.0, epsilon));
285 try expect(math.approxEqAbs(f64, atan2_64(math.inf(f64), math.inf(f64)), math.pi / 4.0, epsilon));
286 try expect(math.approxEqAbs(f64, atan2_64(-math.inf(f64), math.inf(f64)), -math.pi / 4.0, epsilon));
287 try expect(math.approxEqAbs(f64, atan2_64(math.inf(f64), -math.inf(f64)), 3.0 * math.pi / 4.0, epsilon));
288 try expect(math.approxEqAbs(f64, atan2_64(-math.inf(f64), -math.inf(f64)), -3.0 * math.pi / 4.0, epsilon));
289 try expect(atan2_64(1.0, math.inf(f64)) == 0.0);
290 try expect(math.approxEqAbs(f64, atan2_64(1.0, -math.inf(f64)), math.pi, epsilon));
291 try expect(math.approxEqAbs(f64, atan2_64(-1.0, -math.inf(f64)), -math.pi, epsilon));
292 try expect(math.approxEqAbs(f64, atan2_64(math.inf(f64), 1.0), math.pi / 2.0, epsilon));
293 try expect(math.approxEqAbs(f64, atan2_64(-math.inf(f64), 1.0), -math.pi / 2.0, epsilon));
294294}
lib/std/math/atanh.zig+18-18
......@@ -89,38 +89,38 @@ fn atanh_64(x: f64) f64 {
8989}
9090
9191test "math.atanh" {
92 expect(atanh(@as(f32, 0.0)) == atanh_32(0.0));
93 expect(atanh(@as(f64, 0.0)) == atanh_64(0.0));
92 try expect(atanh(@as(f32, 0.0)) == atanh_32(0.0));
93 try expect(atanh(@as(f64, 0.0)) == atanh_64(0.0));
9494}
9595
9696test "math.atanh_32" {
9797 const epsilon = 0.000001;
9898
99 expect(math.approxEqAbs(f32, atanh_32(0.0), 0.0, epsilon));
100 expect(math.approxEqAbs(f32, atanh_32(0.2), 0.202733, epsilon));
101 expect(math.approxEqAbs(f32, atanh_32(0.8923), 1.433099, epsilon));
99 try expect(math.approxEqAbs(f32, atanh_32(0.0), 0.0, epsilon));
100 try expect(math.approxEqAbs(f32, atanh_32(0.2), 0.202733, epsilon));
101 try expect(math.approxEqAbs(f32, atanh_32(0.8923), 1.433099, epsilon));
102102}
103103
104104test "math.atanh_64" {
105105 const epsilon = 0.000001;
106106
107 expect(math.approxEqAbs(f64, atanh_64(0.0), 0.0, epsilon));
108 expect(math.approxEqAbs(f64, atanh_64(0.2), 0.202733, epsilon));
109 expect(math.approxEqAbs(f64, atanh_64(0.8923), 1.433099, epsilon));
107 try expect(math.approxEqAbs(f64, atanh_64(0.0), 0.0, epsilon));
108 try expect(math.approxEqAbs(f64, atanh_64(0.2), 0.202733, epsilon));
109 try expect(math.approxEqAbs(f64, atanh_64(0.8923), 1.433099, epsilon));
110110}
111111
112112test "math.atanh32.special" {
113 expect(math.isPositiveInf(atanh_32(1)));
114 expect(math.isNegativeInf(atanh_32(-1)));
115 expect(math.isSignalNan(atanh_32(1.5)));
116 expect(math.isSignalNan(atanh_32(-1.5)));
117 expect(math.isNan(atanh_32(math.nan(f32))));
113 try expect(math.isPositiveInf(atanh_32(1)));
114 try expect(math.isNegativeInf(atanh_32(-1)));
115 try expect(math.isSignalNan(atanh_32(1.5)));
116 try expect(math.isSignalNan(atanh_32(-1.5)));
117 try expect(math.isNan(atanh_32(math.nan(f32))));
118118}
119119
120120test "math.atanh64.special" {
121 expect(math.isPositiveInf(atanh_64(1)));
122 expect(math.isNegativeInf(atanh_64(-1)));
123 expect(math.isSignalNan(atanh_64(1.5)));
124 expect(math.isSignalNan(atanh_64(-1.5)));
125 expect(math.isNan(atanh_64(math.nan(f64))));
121 try expect(math.isPositiveInf(atanh_64(1)));
122 try expect(math.isNegativeInf(atanh_64(-1)));
123 try expect(math.isSignalNan(atanh_64(1.5)));
124 try expect(math.isSignalNan(atanh_64(-1.5)));
125 try expect(math.isNan(atanh_64(math.nan(f64))));
126126}
lib/std/math/big/int_test.zig+211-211
......@@ -30,7 +30,7 @@ test "big.int comptime_int set" {
3030 const result = @as(Limb, s & maxInt(Limb));
3131 s >>= @typeInfo(Limb).Int.bits / 2;
3232 s >>= @typeInfo(Limb).Int.bits / 2;
33 testing.expect(a.limbs[i] == result);
33 try testing.expect(a.limbs[i] == result);
3434 }
3535}
3636
......@@ -38,37 +38,37 @@ test "big.int comptime_int set negative" {
3838 var a = try Managed.initSet(testing.allocator, -10);
3939 defer a.deinit();
4040
41 testing.expect(a.limbs[0] == 10);
42 testing.expect(a.isPositive() == false);
41 try testing.expect(a.limbs[0] == 10);
42 try testing.expect(a.isPositive() == false);
4343}
4444
4545test "big.int int set unaligned small" {
4646 var a = try Managed.initSet(testing.allocator, @as(u7, 45));
4747 defer a.deinit();
4848
49 testing.expect(a.limbs[0] == 45);
50 testing.expect(a.isPositive() == true);
49 try testing.expect(a.limbs[0] == 45);
50 try testing.expect(a.isPositive() == true);
5151}
5252
5353test "big.int comptime_int to" {
5454 var a = try Managed.initSet(testing.allocator, 0xefffffff00000001eeeeeeefaaaaaaab);
5555 defer a.deinit();
5656
57 testing.expect((try a.to(u128)) == 0xefffffff00000001eeeeeeefaaaaaaab);
57 try testing.expect((try a.to(u128)) == 0xefffffff00000001eeeeeeefaaaaaaab);
5858}
5959
6060test "big.int sub-limb to" {
6161 var a = try Managed.initSet(testing.allocator, 10);
6262 defer a.deinit();
6363
64 testing.expect((try a.to(u8)) == 10);
64 try testing.expect((try a.to(u8)) == 10);
6565}
6666
6767test "big.int to target too small error" {
6868 var a = try Managed.initSet(testing.allocator, 0xffffffff);
6969 defer a.deinit();
7070
71 testing.expectError(error.TargetTooSmall, a.to(u8));
71 try testing.expectError(error.TargetTooSmall, a.to(u8));
7272}
7373
7474test "big.int normalize" {
......@@ -81,22 +81,22 @@ test "big.int normalize" {
8181 a.limbs[2] = 3;
8282 a.limbs[3] = 0;
8383 a.normalize(4);
84 testing.expect(a.len() == 3);
84 try testing.expect(a.len() == 3);
8585
8686 a.limbs[0] = 1;
8787 a.limbs[1] = 2;
8888 a.limbs[2] = 3;
8989 a.normalize(3);
90 testing.expect(a.len() == 3);
90 try testing.expect(a.len() == 3);
9191
9292 a.limbs[0] = 0;
9393 a.limbs[1] = 0;
9494 a.normalize(2);
95 testing.expect(a.len() == 1);
95 try testing.expect(a.len() == 1);
9696
9797 a.limbs[0] = 0;
9898 a.normalize(1);
99 testing.expect(a.len() == 1);
99 try testing.expect(a.len() == 1);
100100}
101101
102102test "big.int normalize multi" {
......@@ -109,24 +109,24 @@ test "big.int normalize multi" {
109109 a.limbs[2] = 0;
110110 a.limbs[3] = 0;
111111 a.normalize(4);
112 testing.expect(a.len() == 2);
112 try testing.expect(a.len() == 2);
113113
114114 a.limbs[0] = 1;
115115 a.limbs[1] = 2;
116116 a.limbs[2] = 3;
117117 a.normalize(3);
118 testing.expect(a.len() == 3);
118 try testing.expect(a.len() == 3);
119119
120120 a.limbs[0] = 0;
121121 a.limbs[1] = 0;
122122 a.limbs[2] = 0;
123123 a.limbs[3] = 0;
124124 a.normalize(4);
125 testing.expect(a.len() == 1);
125 try testing.expect(a.len() == 1);
126126
127127 a.limbs[0] = 0;
128128 a.normalize(1);
129 testing.expect(a.len() == 1);
129 try testing.expect(a.len() == 1);
130130}
131131
132132test "big.int parity" {
......@@ -134,12 +134,12 @@ test "big.int parity" {
134134 defer a.deinit();
135135
136136 try a.set(0);
137 testing.expect(a.isEven());
138 testing.expect(!a.isOdd());
137 try testing.expect(a.isEven());
138 try testing.expect(!a.isOdd());
139139
140140 try a.set(7);
141 testing.expect(!a.isEven());
142 testing.expect(a.isOdd());
141 try testing.expect(!a.isEven());
142 try testing.expect(a.isOdd());
143143}
144144
145145test "big.int bitcount + sizeInBaseUpperBound" {
......@@ -147,27 +147,27 @@ test "big.int bitcount + sizeInBaseUpperBound" {
147147 defer a.deinit();
148148
149149 try a.set(0b100);
150 testing.expect(a.bitCountAbs() == 3);
151 testing.expect(a.sizeInBaseUpperBound(2) >= 3);
152 testing.expect(a.sizeInBaseUpperBound(10) >= 1);
150 try testing.expect(a.bitCountAbs() == 3);
151 try testing.expect(a.sizeInBaseUpperBound(2) >= 3);
152 try testing.expect(a.sizeInBaseUpperBound(10) >= 1);
153153
154154 a.negate();
155 testing.expect(a.bitCountAbs() == 3);
156 testing.expect(a.sizeInBaseUpperBound(2) >= 4);
157 testing.expect(a.sizeInBaseUpperBound(10) >= 2);
155 try testing.expect(a.bitCountAbs() == 3);
156 try testing.expect(a.sizeInBaseUpperBound(2) >= 4);
157 try testing.expect(a.sizeInBaseUpperBound(10) >= 2);
158158
159159 try a.set(0xffffffff);
160 testing.expect(a.bitCountAbs() == 32);
161 testing.expect(a.sizeInBaseUpperBound(2) >= 32);
162 testing.expect(a.sizeInBaseUpperBound(10) >= 10);
160 try testing.expect(a.bitCountAbs() == 32);
161 try testing.expect(a.sizeInBaseUpperBound(2) >= 32);
162 try testing.expect(a.sizeInBaseUpperBound(10) >= 10);
163163
164164 try a.shiftLeft(a, 5000);
165 testing.expect(a.bitCountAbs() == 5032);
166 testing.expect(a.sizeInBaseUpperBound(2) >= 5032);
165 try testing.expect(a.bitCountAbs() == 5032);
166 try testing.expect(a.sizeInBaseUpperBound(2) >= 5032);
167167 a.setSign(false);
168168
169 testing.expect(a.bitCountAbs() == 5032);
170 testing.expect(a.sizeInBaseUpperBound(2) >= 5033);
169 try testing.expect(a.bitCountAbs() == 5032);
170 try testing.expect(a.sizeInBaseUpperBound(2) >= 5033);
171171}
172172
173173test "big.int bitcount/to" {
......@@ -175,30 +175,30 @@ test "big.int bitcount/to" {
175175 defer a.deinit();
176176
177177 try a.set(0);
178 testing.expect(a.bitCountTwosComp() == 0);
178 try testing.expect(a.bitCountTwosComp() == 0);
179179
180 testing.expect((try a.to(u0)) == 0);
181 testing.expect((try a.to(i0)) == 0);
180 try testing.expect((try a.to(u0)) == 0);
181 try testing.expect((try a.to(i0)) == 0);
182182
183183 try a.set(-1);
184 testing.expect(a.bitCountTwosComp() == 1);
185 testing.expect((try a.to(i1)) == -1);
184 try testing.expect(a.bitCountTwosComp() == 1);
185 try testing.expect((try a.to(i1)) == -1);
186186
187187 try a.set(-8);
188 testing.expect(a.bitCountTwosComp() == 4);
189 testing.expect((try a.to(i4)) == -8);
188 try testing.expect(a.bitCountTwosComp() == 4);
189 try testing.expect((try a.to(i4)) == -8);
190190
191191 try a.set(127);
192 testing.expect(a.bitCountTwosComp() == 7);
193 testing.expect((try a.to(u7)) == 127);
192 try testing.expect(a.bitCountTwosComp() == 7);
193 try testing.expect((try a.to(u7)) == 127);
194194
195195 try a.set(-128);
196 testing.expect(a.bitCountTwosComp() == 8);
197 testing.expect((try a.to(i8)) == -128);
196 try testing.expect(a.bitCountTwosComp() == 8);
197 try testing.expect((try a.to(i8)) == -128);
198198
199199 try a.set(-129);
200 testing.expect(a.bitCountTwosComp() == 9);
201 testing.expect((try a.to(i9)) == -129);
200 try testing.expect(a.bitCountTwosComp() == 9);
201 try testing.expect((try a.to(i9)) == -129);
202202}
203203
204204test "big.int fits" {
......@@ -206,27 +206,27 @@ test "big.int fits" {
206206 defer a.deinit();
207207
208208 try a.set(0);
209 testing.expect(a.fits(u0));
210 testing.expect(a.fits(i0));
209 try testing.expect(a.fits(u0));
210 try testing.expect(a.fits(i0));
211211
212212 try a.set(255);
213 testing.expect(!a.fits(u0));
214 testing.expect(!a.fits(u1));
215 testing.expect(!a.fits(i8));
216 testing.expect(a.fits(u8));
217 testing.expect(a.fits(u9));
218 testing.expect(a.fits(i9));
213 try testing.expect(!a.fits(u0));
214 try testing.expect(!a.fits(u1));
215 try testing.expect(!a.fits(i8));
216 try testing.expect(a.fits(u8));
217 try testing.expect(a.fits(u9));
218 try testing.expect(a.fits(i9));
219219
220220 try a.set(-128);
221 testing.expect(!a.fits(i7));
222 testing.expect(a.fits(i8));
223 testing.expect(a.fits(i9));
224 testing.expect(!a.fits(u9));
221 try testing.expect(!a.fits(i7));
222 try testing.expect(a.fits(i8));
223 try testing.expect(a.fits(i9));
224 try testing.expect(!a.fits(u9));
225225
226226 try a.set(0x1ffffffffeeeeeeee);
227 testing.expect(!a.fits(u32));
228 testing.expect(!a.fits(u64));
229 testing.expect(a.fits(u65));
227 try testing.expect(!a.fits(u32));
228 try testing.expect(!a.fits(u64));
229 try testing.expect(a.fits(u65));
230230}
231231
232232test "big.int string set" {
......@@ -234,7 +234,7 @@ test "big.int string set" {
234234 defer a.deinit();
235235
236236 try a.setString(10, "120317241209124781241290847124");
237 testing.expect((try a.to(u128)) == 120317241209124781241290847124);
237 try testing.expect((try a.to(u128)) == 120317241209124781241290847124);
238238}
239239
240240test "big.int string negative" {
......@@ -242,7 +242,7 @@ test "big.int string negative" {
242242 defer a.deinit();
243243
244244 try a.setString(10, "-1023");
245 testing.expect((try a.to(i32)) == -1023);
245 try testing.expect((try a.to(i32)) == -1023);
246246}
247247
248248test "big.int string set number with underscores" {
......@@ -250,7 +250,7 @@ test "big.int string set number with underscores" {
250250 defer a.deinit();
251251
252252 try a.setString(10, "__1_2_0_3_1_7_2_4_1_2_0_____9_1__2__4_7_8_1_2_4_1_2_9_0_8_4_7_1_2_4___");
253 testing.expect((try a.to(u128)) == 120317241209124781241290847124);
253 try testing.expect((try a.to(u128)) == 120317241209124781241290847124);
254254}
255255
256256test "big.int string set case insensitive number" {
......@@ -258,19 +258,19 @@ test "big.int string set case insensitive number" {
258258 defer a.deinit();
259259
260260 try a.setString(16, "aB_cD_eF");
261 testing.expect((try a.to(u32)) == 0xabcdef);
261 try testing.expect((try a.to(u32)) == 0xabcdef);
262262}
263263
264264test "big.int string set bad char error" {
265265 var a = try Managed.init(testing.allocator);
266266 defer a.deinit();
267 testing.expectError(error.InvalidCharacter, a.setString(10, "x"));
267 try testing.expectError(error.InvalidCharacter, a.setString(10, "x"));
268268}
269269
270270test "big.int string set bad base error" {
271271 var a = try Managed.init(testing.allocator);
272272 defer a.deinit();
273 testing.expectError(error.InvalidBase, a.setString(45, "10"));
273 try testing.expectError(error.InvalidBase, a.setString(45, "10"));
274274}
275275
276276test "big.int string to" {
......@@ -281,14 +281,14 @@ test "big.int string to" {
281281 defer testing.allocator.free(as);
282282 const es = "120317241209124781241290847124";
283283
284 testing.expect(mem.eql(u8, as, es));
284 try testing.expect(mem.eql(u8, as, es));
285285}
286286
287287test "big.int string to base base error" {
288288 var a = try Managed.initSet(testing.allocator, 0xffffffff);
289289 defer a.deinit();
290290
291 testing.expectError(error.InvalidBase, a.toString(testing.allocator, 45, false));
291 try testing.expectError(error.InvalidBase, a.toString(testing.allocator, 45, false));
292292}
293293
294294test "big.int string to base 2" {
......@@ -299,7 +299,7 @@ test "big.int string to base 2" {
299299 defer testing.allocator.free(as);
300300 const es = "-1011";
301301
302 testing.expect(mem.eql(u8, as, es));
302 try testing.expect(mem.eql(u8, as, es));
303303}
304304
305305test "big.int string to base 16" {
......@@ -310,7 +310,7 @@ test "big.int string to base 16" {
310310 defer testing.allocator.free(as);
311311 const es = "efffffff00000001eeeeeeefaaaaaaab";
312312
313 testing.expect(mem.eql(u8, as, es));
313 try testing.expect(mem.eql(u8, as, es));
314314}
315315
316316test "big.int neg string to" {
......@@ -321,7 +321,7 @@ test "big.int neg string to" {
321321 defer testing.allocator.free(as);
322322 const es = "-123907434";
323323
324 testing.expect(mem.eql(u8, as, es));
324 try testing.expect(mem.eql(u8, as, es));
325325}
326326
327327test "big.int zero string to" {
......@@ -332,7 +332,7 @@ test "big.int zero string to" {
332332 defer testing.allocator.free(as);
333333 const es = "0";
334334
335 testing.expect(mem.eql(u8, as, es));
335 try testing.expect(mem.eql(u8, as, es));
336336}
337337
338338test "big.int clone" {
......@@ -341,12 +341,12 @@ test "big.int clone" {
341341 var b = try a.clone();
342342 defer b.deinit();
343343
344 testing.expect((try a.to(u32)) == 1234);
345 testing.expect((try b.to(u32)) == 1234);
344 try testing.expect((try a.to(u32)) == 1234);
345 try testing.expect((try b.to(u32)) == 1234);
346346
347347 try a.set(77);
348 testing.expect((try a.to(u32)) == 77);
349 testing.expect((try b.to(u32)) == 1234);
348 try testing.expect((try a.to(u32)) == 77);
349 try testing.expect((try b.to(u32)) == 1234);
350350}
351351
352352test "big.int swap" {
......@@ -355,20 +355,20 @@ test "big.int swap" {
355355 var b = try Managed.initSet(testing.allocator, 5678);
356356 defer b.deinit();
357357
358 testing.expect((try a.to(u32)) == 1234);
359 testing.expect((try b.to(u32)) == 5678);
358 try testing.expect((try a.to(u32)) == 1234);
359 try testing.expect((try b.to(u32)) == 5678);
360360
361361 a.swap(&b);
362362
363 testing.expect((try a.to(u32)) == 5678);
364 testing.expect((try b.to(u32)) == 1234);
363 try testing.expect((try a.to(u32)) == 5678);
364 try testing.expect((try b.to(u32)) == 1234);
365365}
366366
367367test "big.int to negative" {
368368 var a = try Managed.initSet(testing.allocator, -10);
369369 defer a.deinit();
370370
371 testing.expect((try a.to(i32)) == -10);
371 try testing.expect((try a.to(i32)) == -10);
372372}
373373
374374test "big.int compare" {
......@@ -377,8 +377,8 @@ test "big.int compare" {
377377 var b = try Managed.initSet(testing.allocator, 10);
378378 defer b.deinit();
379379
380 testing.expect(a.orderAbs(b) == .gt);
381 testing.expect(a.order(b) == .lt);
380 try testing.expect(a.orderAbs(b) == .gt);
381 try testing.expect(a.order(b) == .lt);
382382}
383383
384384test "big.int compare similar" {
......@@ -387,8 +387,8 @@ test "big.int compare similar" {
387387 var b = try Managed.initSet(testing.allocator, 0xffffffffeeeeeeeeffffffffeeeeeeef);
388388 defer b.deinit();
389389
390 testing.expect(a.orderAbs(b) == .lt);
391 testing.expect(b.orderAbs(a) == .gt);
390 try testing.expect(a.orderAbs(b) == .lt);
391 try testing.expect(b.orderAbs(a) == .gt);
392392}
393393
394394test "big.int compare different limb size" {
......@@ -397,8 +397,8 @@ test "big.int compare different limb size" {
397397 var b = try Managed.initSet(testing.allocator, 1);
398398 defer b.deinit();
399399
400 testing.expect(a.orderAbs(b) == .gt);
401 testing.expect(b.orderAbs(a) == .lt);
400 try testing.expect(a.orderAbs(b) == .gt);
401 try testing.expect(b.orderAbs(a) == .lt);
402402}
403403
404404test "big.int compare multi-limb" {
......@@ -407,8 +407,8 @@ test "big.int compare multi-limb" {
407407 var b = try Managed.initSet(testing.allocator, 0x7777777799999999ffffeeeeffffeeeeffffeeeee);
408408 defer b.deinit();
409409
410 testing.expect(a.orderAbs(b) == .gt);
411 testing.expect(a.order(b) == .lt);
410 try testing.expect(a.orderAbs(b) == .gt);
411 try testing.expect(a.order(b) == .lt);
412412}
413413
414414test "big.int equality" {
......@@ -417,8 +417,8 @@ test "big.int equality" {
417417 var b = try Managed.initSet(testing.allocator, -0xffffffff1);
418418 defer b.deinit();
419419
420 testing.expect(a.eqAbs(b));
421 testing.expect(!a.eq(b));
420 try testing.expect(a.eqAbs(b));
421 try testing.expect(!a.eq(b));
422422}
423423
424424test "big.int abs" {
......@@ -426,10 +426,10 @@ test "big.int abs" {
426426 defer a.deinit();
427427
428428 a.abs();
429 testing.expect((try a.to(u32)) == 5);
429 try testing.expect((try a.to(u32)) == 5);
430430
431431 a.abs();
432 testing.expect((try a.to(u32)) == 5);
432 try testing.expect((try a.to(u32)) == 5);
433433}
434434
435435test "big.int negate" {
......@@ -437,10 +437,10 @@ test "big.int negate" {
437437 defer a.deinit();
438438
439439 a.negate();
440 testing.expect((try a.to(i32)) == -5);
440 try testing.expect((try a.to(i32)) == -5);
441441
442442 a.negate();
443 testing.expect((try a.to(i32)) == 5);
443 try testing.expect((try a.to(i32)) == 5);
444444}
445445
446446test "big.int add single-single" {
......@@ -453,7 +453,7 @@ test "big.int add single-single" {
453453 defer c.deinit();
454454 try c.add(a.toConst(), b.toConst());
455455
456 testing.expect((try c.to(u32)) == 55);
456 try testing.expect((try c.to(u32)) == 55);
457457}
458458
459459test "big.int add multi-single" {
......@@ -466,10 +466,10 @@ test "big.int add multi-single" {
466466 defer c.deinit();
467467
468468 try c.add(a.toConst(), b.toConst());
469 testing.expect((try c.to(DoubleLimb)) == maxInt(Limb) + 2);
469 try testing.expect((try c.to(DoubleLimb)) == maxInt(Limb) + 2);
470470
471471 try c.add(b.toConst(), a.toConst());
472 testing.expect((try c.to(DoubleLimb)) == maxInt(Limb) + 2);
472 try testing.expect((try c.to(DoubleLimb)) == maxInt(Limb) + 2);
473473}
474474
475475test "big.int add multi-multi" {
......@@ -484,7 +484,7 @@ test "big.int add multi-multi" {
484484 defer c.deinit();
485485 try c.add(a.toConst(), b.toConst());
486486
487 testing.expect((try c.to(u128)) == op1 + op2);
487 try testing.expect((try c.to(u128)) == op1 + op2);
488488}
489489
490490test "big.int add zero-zero" {
......@@ -497,7 +497,7 @@ test "big.int add zero-zero" {
497497 defer c.deinit();
498498 try c.add(a.toConst(), b.toConst());
499499
500 testing.expect((try c.to(u32)) == 0);
500 try testing.expect((try c.to(u32)) == 0);
501501}
502502
503503test "big.int add alias multi-limb nonzero-zero" {
......@@ -509,7 +509,7 @@ test "big.int add alias multi-limb nonzero-zero" {
509509
510510 try a.add(a.toConst(), b.toConst());
511511
512 testing.expect((try a.to(u128)) == op1);
512 try testing.expect((try a.to(u128)) == op1);
513513}
514514
515515test "big.int add sign" {
......@@ -526,16 +526,16 @@ test "big.int add sign" {
526526 defer neg_two.deinit();
527527
528528 try a.add(one.toConst(), two.toConst());
529 testing.expect((try a.to(i32)) == 3);
529 try testing.expect((try a.to(i32)) == 3);
530530
531531 try a.add(neg_one.toConst(), two.toConst());
532 testing.expect((try a.to(i32)) == 1);
532 try testing.expect((try a.to(i32)) == 1);
533533
534534 try a.add(one.toConst(), neg_two.toConst());
535 testing.expect((try a.to(i32)) == -1);
535 try testing.expect((try a.to(i32)) == -1);
536536
537537 try a.add(neg_one.toConst(), neg_two.toConst());
538 testing.expect((try a.to(i32)) == -3);
538 try testing.expect((try a.to(i32)) == -3);
539539}
540540
541541test "big.int sub single-single" {
......@@ -548,7 +548,7 @@ test "big.int sub single-single" {
548548 defer c.deinit();
549549 try c.sub(a.toConst(), b.toConst());
550550
551 testing.expect((try c.to(u32)) == 45);
551 try testing.expect((try c.to(u32)) == 45);
552552}
553553
554554test "big.int sub multi-single" {
......@@ -561,7 +561,7 @@ test "big.int sub multi-single" {
561561 defer c.deinit();
562562 try c.sub(a.toConst(), b.toConst());
563563
564 testing.expect((try c.to(Limb)) == maxInt(Limb));
564 try testing.expect((try c.to(Limb)) == maxInt(Limb));
565565}
566566
567567test "big.int sub multi-multi" {
......@@ -577,7 +577,7 @@ test "big.int sub multi-multi" {
577577 defer c.deinit();
578578 try c.sub(a.toConst(), b.toConst());
579579
580 testing.expect((try c.to(u128)) == op1 - op2);
580 try testing.expect((try c.to(u128)) == op1 - op2);
581581}
582582
583583test "big.int sub equal" {
......@@ -590,7 +590,7 @@ test "big.int sub equal" {
590590 defer c.deinit();
591591 try c.sub(a.toConst(), b.toConst());
592592
593 testing.expect((try c.to(u32)) == 0);
593 try testing.expect((try c.to(u32)) == 0);
594594}
595595
596596test "big.int sub sign" {
......@@ -607,19 +607,19 @@ test "big.int sub sign" {
607607 defer neg_two.deinit();
608608
609609 try a.sub(one.toConst(), two.toConst());
610 testing.expect((try a.to(i32)) == -1);
610 try testing.expect((try a.to(i32)) == -1);
611611
612612 try a.sub(neg_one.toConst(), two.toConst());
613 testing.expect((try a.to(i32)) == -3);
613 try testing.expect((try a.to(i32)) == -3);
614614
615615 try a.sub(one.toConst(), neg_two.toConst());
616 testing.expect((try a.to(i32)) == 3);
616 try testing.expect((try a.to(i32)) == 3);
617617
618618 try a.sub(neg_one.toConst(), neg_two.toConst());
619 testing.expect((try a.to(i32)) == 1);
619 try testing.expect((try a.to(i32)) == 1);
620620
621621 try a.sub(neg_two.toConst(), neg_one.toConst());
622 testing.expect((try a.to(i32)) == -1);
622 try testing.expect((try a.to(i32)) == -1);
623623}
624624
625625test "big.int mul single-single" {
......@@ -632,7 +632,7 @@ test "big.int mul single-single" {
632632 defer c.deinit();
633633 try c.mul(a.toConst(), b.toConst());
634634
635 testing.expect((try c.to(u64)) == 250);
635 try testing.expect((try c.to(u64)) == 250);
636636}
637637
638638test "big.int mul multi-single" {
......@@ -645,7 +645,7 @@ test "big.int mul multi-single" {
645645 defer c.deinit();
646646 try c.mul(a.toConst(), b.toConst());
647647
648 testing.expect((try c.to(DoubleLimb)) == 2 * maxInt(Limb));
648 try testing.expect((try c.to(DoubleLimb)) == 2 * maxInt(Limb));
649649}
650650
651651test "big.int mul multi-multi" {
......@@ -660,7 +660,7 @@ test "big.int mul multi-multi" {
660660 defer c.deinit();
661661 try c.mul(a.toConst(), b.toConst());
662662
663 testing.expect((try c.to(u256)) == op1 * op2);
663 try testing.expect((try c.to(u256)) == op1 * op2);
664664}
665665
666666test "big.int mul alias r with a" {
......@@ -671,7 +671,7 @@ test "big.int mul alias r with a" {
671671
672672 try a.mul(a.toConst(), b.toConst());
673673
674 testing.expect((try a.to(DoubleLimb)) == 2 * maxInt(Limb));
674 try testing.expect((try a.to(DoubleLimb)) == 2 * maxInt(Limb));
675675}
676676
677677test "big.int mul alias r with b" {
......@@ -682,7 +682,7 @@ test "big.int mul alias r with b" {
682682
683683 try a.mul(b.toConst(), a.toConst());
684684
685 testing.expect((try a.to(DoubleLimb)) == 2 * maxInt(Limb));
685 try testing.expect((try a.to(DoubleLimb)) == 2 * maxInt(Limb));
686686}
687687
688688test "big.int mul alias r with a and b" {
......@@ -691,7 +691,7 @@ test "big.int mul alias r with a and b" {
691691
692692 try a.mul(a.toConst(), a.toConst());
693693
694 testing.expect((try a.to(DoubleLimb)) == maxInt(Limb) * maxInt(Limb));
694 try testing.expect((try a.to(DoubleLimb)) == maxInt(Limb) * maxInt(Limb));
695695}
696696
697697test "big.int mul a*0" {
......@@ -704,7 +704,7 @@ test "big.int mul a*0" {
704704 defer c.deinit();
705705 try c.mul(a.toConst(), b.toConst());
706706
707 testing.expect((try c.to(u32)) == 0);
707 try testing.expect((try c.to(u32)) == 0);
708708}
709709
710710test "big.int mul 0*0" {
......@@ -717,7 +717,7 @@ test "big.int mul 0*0" {
717717 defer c.deinit();
718718 try c.mul(a.toConst(), b.toConst());
719719
720 testing.expect((try c.to(u32)) == 0);
720 try testing.expect((try c.to(u32)) == 0);
721721}
722722
723723test "big.int mul large" {
......@@ -738,7 +738,7 @@ test "big.int mul large" {
738738 try b.mul(a.toConst(), a.toConst());
739739 try c.sqr(a.toConst());
740740
741 testing.expect(b.eq(c));
741 try testing.expect(b.eq(c));
742742}
743743
744744test "big.int div single-single no rem" {
......@@ -753,8 +753,8 @@ test "big.int div single-single no rem" {
753753 defer r.deinit();
754754 try Managed.divTrunc(&q, &r, a.toConst(), b.toConst());
755755
756 testing.expect((try q.to(u32)) == 10);
757 testing.expect((try r.to(u32)) == 0);
756 try testing.expect((try q.to(u32)) == 10);
757 try testing.expect((try r.to(u32)) == 0);
758758}
759759
760760test "big.int div single-single with rem" {
......@@ -769,8 +769,8 @@ test "big.int div single-single with rem" {
769769 defer r.deinit();
770770 try Managed.divTrunc(&q, &r, a.toConst(), b.toConst());
771771
772 testing.expect((try q.to(u32)) == 9);
773 testing.expect((try r.to(u32)) == 4);
772 try testing.expect((try q.to(u32)) == 9);
773 try testing.expect((try r.to(u32)) == 4);
774774}
775775
776776test "big.int div multi-single no rem" {
......@@ -788,8 +788,8 @@ test "big.int div multi-single no rem" {
788788 defer r.deinit();
789789 try Managed.divTrunc(&q, &r, a.toConst(), b.toConst());
790790
791 testing.expect((try q.to(u64)) == op1 / op2);
792 testing.expect((try r.to(u64)) == 0);
791 try testing.expect((try q.to(u64)) == op1 / op2);
792 try testing.expect((try r.to(u64)) == 0);
793793}
794794
795795test "big.int div multi-single with rem" {
......@@ -807,8 +807,8 @@ test "big.int div multi-single with rem" {
807807 defer r.deinit();
808808 try Managed.divTrunc(&q, &r, a.toConst(), b.toConst());
809809
810 testing.expect((try q.to(u64)) == op1 / op2);
811 testing.expect((try r.to(u64)) == 3);
810 try testing.expect((try q.to(u64)) == op1 / op2);
811 try testing.expect((try r.to(u64)) == 3);
812812}
813813
814814test "big.int div multi>2-single" {
......@@ -826,8 +826,8 @@ test "big.int div multi>2-single" {
826826 defer r.deinit();
827827 try Managed.divTrunc(&q, &r, a.toConst(), b.toConst());
828828
829 testing.expect((try q.to(u128)) == op1 / op2);
830 testing.expect((try r.to(u32)) == 0x3e4e);
829 try testing.expect((try q.to(u128)) == op1 / op2);
830 try testing.expect((try r.to(u32)) == 0x3e4e);
831831}
832832
833833test "big.int div single-single q < r" {
......@@ -842,8 +842,8 @@ test "big.int div single-single q < r" {
842842 defer r.deinit();
843843 try Managed.divTrunc(&q, &r, a.toConst(), b.toConst());
844844
845 testing.expect((try q.to(u64)) == 0);
846 testing.expect((try r.to(u64)) == 0x0078f432);
845 try testing.expect((try q.to(u64)) == 0);
846 try testing.expect((try r.to(u64)) == 0x0078f432);
847847}
848848
849849test "big.int div single-single q == r" {
......@@ -858,8 +858,8 @@ test "big.int div single-single q == r" {
858858 defer r.deinit();
859859 try Managed.divTrunc(&q, &r, a.toConst(), b.toConst());
860860
861 testing.expect((try q.to(u64)) == 1);
862 testing.expect((try r.to(u64)) == 0);
861 try testing.expect((try q.to(u64)) == 1);
862 try testing.expect((try r.to(u64)) == 0);
863863}
864864
865865test "big.int div q=0 alias" {
......@@ -870,8 +870,8 @@ test "big.int div q=0 alias" {
870870
871871 try Managed.divTrunc(&a, &b, a.toConst(), b.toConst());
872872
873 testing.expect((try a.to(u64)) == 0);
874 testing.expect((try b.to(u64)) == 3);
873 try testing.expect((try a.to(u64)) == 0);
874 try testing.expect((try b.to(u64)) == 3);
875875}
876876
877877test "big.int div multi-multi q < r" {
......@@ -888,8 +888,8 @@ test "big.int div multi-multi q < r" {
888888 defer r.deinit();
889889 try Managed.divTrunc(&q, &r, a.toConst(), b.toConst());
890890
891 testing.expect((try q.to(u128)) == 0);
892 testing.expect((try r.to(u128)) == op1);
891 try testing.expect((try q.to(u128)) == 0);
892 try testing.expect((try r.to(u128)) == op1);
893893}
894894
895895test "big.int div trunc single-single +/+" {
......@@ -912,8 +912,8 @@ test "big.int div trunc single-single +/+" {
912912 const eq = @divTrunc(u, v);
913913 const er = @mod(u, v);
914914
915 testing.expect((try q.to(i32)) == eq);
916 testing.expect((try r.to(i32)) == er);
915 try testing.expect((try q.to(i32)) == eq);
916 try testing.expect((try r.to(i32)) == er);
917917}
918918
919919test "big.int div trunc single-single -/+" {
......@@ -936,8 +936,8 @@ test "big.int div trunc single-single -/+" {
936936 const eq = -1;
937937 const er = -2;
938938
939 testing.expect((try q.to(i32)) == eq);
940 testing.expect((try r.to(i32)) == er);
939 try testing.expect((try q.to(i32)) == eq);
940 try testing.expect((try r.to(i32)) == er);
941941}
942942
943943test "big.int div trunc single-single +/-" {
......@@ -960,8 +960,8 @@ test "big.int div trunc single-single +/-" {
960960 const eq = -1;
961961 const er = 2;
962962
963 testing.expect((try q.to(i32)) == eq);
964 testing.expect((try r.to(i32)) == er);
963 try testing.expect((try q.to(i32)) == eq);
964 try testing.expect((try r.to(i32)) == er);
965965}
966966
967967test "big.int div trunc single-single -/-" {
......@@ -984,8 +984,8 @@ test "big.int div trunc single-single -/-" {
984984 const eq = 1;
985985 const er = -2;
986986
987 testing.expect((try q.to(i32)) == eq);
988 testing.expect((try r.to(i32)) == er);
987 try testing.expect((try q.to(i32)) == eq);
988 try testing.expect((try r.to(i32)) == er);
989989}
990990
991991test "big.int div floor single-single +/+" {
......@@ -1008,8 +1008,8 @@ test "big.int div floor single-single +/+" {
10081008 const eq = 1;
10091009 const er = 2;
10101010
1011 testing.expect((try q.to(i32)) == eq);
1012 testing.expect((try r.to(i32)) == er);
1011 try testing.expect((try q.to(i32)) == eq);
1012 try testing.expect((try r.to(i32)) == er);
10131013}
10141014
10151015test "big.int div floor single-single -/+" {
......@@ -1032,8 +1032,8 @@ test "big.int div floor single-single -/+" {
10321032 const eq = -2;
10331033 const er = 1;
10341034
1035 testing.expect((try q.to(i32)) == eq);
1036 testing.expect((try r.to(i32)) == er);
1035 try testing.expect((try q.to(i32)) == eq);
1036 try testing.expect((try r.to(i32)) == er);
10371037}
10381038
10391039test "big.int div floor single-single +/-" {
......@@ -1056,8 +1056,8 @@ test "big.int div floor single-single +/-" {
10561056 const eq = -2;
10571057 const er = -1;
10581058
1059 testing.expect((try q.to(i32)) == eq);
1060 testing.expect((try r.to(i32)) == er);
1059 try testing.expect((try q.to(i32)) == eq);
1060 try testing.expect((try r.to(i32)) == er);
10611061}
10621062
10631063test "big.int div floor single-single -/-" {
......@@ -1080,8 +1080,8 @@ test "big.int div floor single-single -/-" {
10801080 const eq = 1;
10811081 const er = -2;
10821082
1083 testing.expect((try q.to(i32)) == eq);
1084 testing.expect((try r.to(i32)) == er);
1083 try testing.expect((try q.to(i32)) == eq);
1084 try testing.expect((try r.to(i32)) == er);
10851085}
10861086
10871087test "big.int div multi-multi with rem" {
......@@ -1096,8 +1096,8 @@ test "big.int div multi-multi with rem" {
10961096 defer r.deinit();
10971097 try Managed.divTrunc(&q, &r, a.toConst(), b.toConst());
10981098
1099 testing.expect((try q.to(u128)) == 0xe38f38e39161aaabd03f0f1b);
1100 testing.expect((try r.to(u128)) == 0x28de0acacd806823638);
1099 try testing.expect((try q.to(u128)) == 0xe38f38e39161aaabd03f0f1b);
1100 try testing.expect((try r.to(u128)) == 0x28de0acacd806823638);
11011101}
11021102
11031103test "big.int div multi-multi no rem" {
......@@ -1112,8 +1112,8 @@ test "big.int div multi-multi no rem" {
11121112 defer r.deinit();
11131113 try Managed.divTrunc(&q, &r, a.toConst(), b.toConst());
11141114
1115 testing.expect((try q.to(u128)) == 0xe38f38e39161aaabd03f0f1b);
1116 testing.expect((try r.to(u128)) == 0);
1115 try testing.expect((try q.to(u128)) == 0xe38f38e39161aaabd03f0f1b);
1116 try testing.expect((try r.to(u128)) == 0);
11171117}
11181118
11191119test "big.int div multi-multi (2 branch)" {
......@@ -1128,8 +1128,8 @@ test "big.int div multi-multi (2 branch)" {
11281128 defer r.deinit();
11291129 try Managed.divTrunc(&q, &r, a.toConst(), b.toConst());
11301130
1131 testing.expect((try q.to(u128)) == 0x10000000000000000);
1132 testing.expect((try r.to(u128)) == 0x44444443444444431111111111111111);
1131 try testing.expect((try q.to(u128)) == 0x10000000000000000);
1132 try testing.expect((try r.to(u128)) == 0x44444443444444431111111111111111);
11331133}
11341134
11351135test "big.int div multi-multi (3.1/3.3 branch)" {
......@@ -1144,8 +1144,8 @@ test "big.int div multi-multi (3.1/3.3 branch)" {
11441144 defer r.deinit();
11451145 try Managed.divTrunc(&q, &r, a.toConst(), b.toConst());
11461146
1147 testing.expect((try q.to(u128)) == 0xfffffffffffffffffff);
1148 testing.expect((try r.to(u256)) == 0x1111111111111111111110b12222222222222222282);
1147 try testing.expect((try q.to(u128)) == 0xfffffffffffffffffff);
1148 try testing.expect((try r.to(u256)) == 0x1111111111111111111110b12222222222222222282);
11491149}
11501150
11511151test "big.int div multi-single zero-limb trailing" {
......@@ -1162,8 +1162,8 @@ test "big.int div multi-single zero-limb trailing" {
11621162
11631163 var expected = try Managed.initSet(testing.allocator, 0x6000000000000000000000000000000000000000000000000);
11641164 defer expected.deinit();
1165 testing.expect(q.eq(expected));
1166 testing.expect(r.eqZero());
1165 try testing.expect(q.eq(expected));
1166 try testing.expect(r.eqZero());
11671167}
11681168
11691169test "big.int div multi-multi zero-limb trailing (with rem)" {
......@@ -1178,11 +1178,11 @@ test "big.int div multi-multi zero-limb trailing (with rem)" {
11781178 defer r.deinit();
11791179 try Managed.divTrunc(&q, &r, a.toConst(), b.toConst());
11801180
1181 testing.expect((try q.to(u128)) == 0x10000000000000000);
1181 try testing.expect((try q.to(u128)) == 0x10000000000000000);
11821182
11831183 const rs = try r.toString(testing.allocator, 16, false);
11841184 defer testing.allocator.free(rs);
1185 testing.expect(std.mem.eql(u8, rs, "4444444344444443111111111111111100000000000000000000000000000000"));
1185 try testing.expect(std.mem.eql(u8, rs, "4444444344444443111111111111111100000000000000000000000000000000"));
11861186}
11871187
11881188test "big.int div multi-multi zero-limb trailing (with rem) and dividend zero-limb count > divisor zero-limb count" {
......@@ -1197,11 +1197,11 @@ test "big.int div multi-multi zero-limb trailing (with rem) and dividend zero-li
11971197 defer r.deinit();
11981198 try Managed.divTrunc(&q, &r, a.toConst(), b.toConst());
11991199
1200 testing.expect((try q.to(u128)) == 0x1);
1200 try testing.expect((try q.to(u128)) == 0x1);
12011201
12021202 const rs = try r.toString(testing.allocator, 16, false);
12031203 defer testing.allocator.free(rs);
1204 testing.expect(std.mem.eql(u8, rs, "444444434444444311111111111111110000000000000000"));
1204 try testing.expect(std.mem.eql(u8, rs, "444444434444444311111111111111110000000000000000"));
12051205}
12061206
12071207test "big.int div multi-multi zero-limb trailing (with rem) and dividend zero-limb count < divisor zero-limb count" {
......@@ -1218,11 +1218,11 @@ test "big.int div multi-multi zero-limb trailing (with rem) and dividend zero-li
12181218
12191219 const qs = try q.toString(testing.allocator, 16, false);
12201220 defer testing.allocator.free(qs);
1221 testing.expect(std.mem.eql(u8, qs, "10000000000000000820820803105186f"));
1221 try testing.expect(std.mem.eql(u8, qs, "10000000000000000820820803105186f"));
12221222
12231223 const rs = try r.toString(testing.allocator, 16, false);
12241224 defer testing.allocator.free(rs);
1225 testing.expect(std.mem.eql(u8, rs, "4e11f2baa5896a321d463b543d0104e30000000000000000"));
1225 try testing.expect(std.mem.eql(u8, rs, "4e11f2baa5896a321d463b543d0104e30000000000000000"));
12261226}
12271227
12281228test "big.int div multi-multi fuzz case #1" {
......@@ -1242,11 +1242,11 @@ test "big.int div multi-multi fuzz case #1" {
12421242
12431243 const qs = try q.toString(testing.allocator, 16, false);
12441244 defer testing.allocator.free(qs);
1245 testing.expect(std.mem.eql(u8, qs, "3ffffffffffffffffffffffffffff0000000000000000000000000000000000001ffffffffffffffffffffffffffff7fffffffe000000000000000000000000000180000000000000000000003fffffbfffffffdfffffffffffffeffff800000100101000000100000000020003fffffdfbfffffe3ffffffffffffeffff7fffc00800a100000017ffe000002000400007efbfff7fe9f00000037ffff3fff7fffa004006100000009ffe00000190038200bf7d2ff7fefe80400060000f7d7f8fbf9401fe38e0403ffc0bdffffa51102c300d7be5ef9df4e5060007b0127ad3fa69f97d0f820b6605ff617ddf7f32ad7a05c0d03f2e7bc78a6000e087a8bbcdc59e07a5a079128a7861f553ddebed7e8e56701756f9ead39b48cd1b0831889ea6ec1fddf643d0565b075ff07e6caea4e2854ec9227fd635ed60a2f5eef2893052ffd54718fa08604acbf6a15e78a467c4a3c53c0278af06c4416573f925491b195e8fd79302cb1aaf7caf4ecfc9aec1254cc969786363ac729f914c6ddcc26738d6b0facd54eba026580aba2eb6482a088b0d224a8852420b91ec1"));
1245 try testing.expect(std.mem.eql(u8, qs, "3ffffffffffffffffffffffffffff0000000000000000000000000000000000001ffffffffffffffffffffffffffff7fffffffe000000000000000000000000000180000000000000000000003fffffbfffffffdfffffffffffffeffff800000100101000000100000000020003fffffdfbfffffe3ffffffffffffeffff7fffc00800a100000017ffe000002000400007efbfff7fe9f00000037ffff3fff7fffa004006100000009ffe00000190038200bf7d2ff7fefe80400060000f7d7f8fbf9401fe38e0403ffc0bdffffa51102c300d7be5ef9df4e5060007b0127ad3fa69f97d0f820b6605ff617ddf7f32ad7a05c0d03f2e7bc78a6000e087a8bbcdc59e07a5a079128a7861f553ddebed7e8e56701756f9ead39b48cd1b0831889ea6ec1fddf643d0565b075ff07e6caea4e2854ec9227fd635ed60a2f5eef2893052ffd54718fa08604acbf6a15e78a467c4a3c53c0278af06c4416573f925491b195e8fd79302cb1aaf7caf4ecfc9aec1254cc969786363ac729f914c6ddcc26738d6b0facd54eba026580aba2eb6482a088b0d224a8852420b91ec1"));
12461246
12471247 const rs = try r.toString(testing.allocator, 16, false);
12481248 defer testing.allocator.free(rs);
1249 testing.expect(std.mem.eql(u8, rs, "310d1d4c414426b4836c2635bad1df3a424e50cbdd167ffccb4dfff57d36b4aae0d6ca0910698220171a0f3373c1060a046c2812f0027e321f72979daa5e7973214170d49e885de0c0ecc167837d44502430674a82522e5df6a0759548052420b91ec1"));
1249 try testing.expect(std.mem.eql(u8, rs, "310d1d4c414426b4836c2635bad1df3a424e50cbdd167ffccb4dfff57d36b4aae0d6ca0910698220171a0f3373c1060a046c2812f0027e321f72979daa5e7973214170d49e885de0c0ecc167837d44502430674a82522e5df6a0759548052420b91ec1"));
12501250}
12511251
12521252test "big.int div multi-multi fuzz case #2" {
......@@ -1266,11 +1266,11 @@ test "big.int div multi-multi fuzz case #2" {
12661266
12671267 const qs = try q.toString(testing.allocator, 16, false);
12681268 defer testing.allocator.free(qs);
1269 testing.expect(std.mem.eql(u8, qs, "40100400fe3f8fe3f8fe3f8fe3f8fe3f8fe4f93e4f93e4f93e4f93e4f93e4f93e4f93e4f93e4f93e4f93e4f93e4f91e4791e4791e4791e4791e4791e4791e4791e4791e4791e4791e4791e4791e4992649926499264991e4791e4791e4791e4791e4791e4791e4791e4791e4791e4791e4791e4791e4791e4791e4791e4791e4791e4791e4791e4791e4791e4791e4791e4792e4b92e4b92e4b92e4b92a4a92a4a92a4"));
1269 try testing.expect(std.mem.eql(u8, qs, "40100400fe3f8fe3f8fe3f8fe3f8fe3f8fe4f93e4f93e4f93e4f93e4f93e4f93e4f93e4f93e4f93e4f93e4f93e4f91e4791e4791e4791e4791e4791e4791e4791e4791e4791e4791e4791e4791e4992649926499264991e4791e4791e4791e4791e4791e4791e4791e4791e4791e4791e4791e4791e4791e4791e4791e4791e4791e4791e4791e4791e4791e4791e4791e4792e4b92e4b92e4b92e4b92a4a92a4a92a4"));
12701270
12711271 const rs = try r.toString(testing.allocator, 16, false);
12721272 defer testing.allocator.free(rs);
1273 testing.expect(std.mem.eql(u8, rs, "a900000000000000000000000000000000000000000000000000"));
1273 try testing.expect(std.mem.eql(u8, rs, "a900000000000000000000000000000000000000000000000000"));
12741274}
12751275
12761276test "big.int shift-right single" {
......@@ -1278,7 +1278,7 @@ test "big.int shift-right single" {
12781278 defer a.deinit();
12791279 try a.shiftRight(a, 16);
12801280
1281 testing.expect((try a.to(u32)) == 0xffff);
1281 try testing.expect((try a.to(u32)) == 0xffff);
12821282}
12831283
12841284test "big.int shift-right multi" {
......@@ -1286,13 +1286,13 @@ test "big.int shift-right multi" {
12861286 defer a.deinit();
12871287 try a.shiftRight(a, 67);
12881288
1289 testing.expect((try a.to(u64)) == 0x1fffe0001dddc222);
1289 try testing.expect((try a.to(u64)) == 0x1fffe0001dddc222);
12901290
12911291 try a.set(0xffff0000eeee1111dddd2222cccc3333);
12921292 try a.shiftRight(a, 63);
12931293 try a.shiftRight(a, 63);
12941294 try a.shiftRight(a, 2);
1295 testing.expect(a.eqZero());
1295 try testing.expect(a.eqZero());
12961296}
12971297
12981298test "big.int shift-left single" {
......@@ -1300,7 +1300,7 @@ test "big.int shift-left single" {
13001300 defer a.deinit();
13011301 try a.shiftLeft(a, 16);
13021302
1303 testing.expect((try a.to(u64)) == 0xffff0000);
1303 try testing.expect((try a.to(u64)) == 0xffff0000);
13041304}
13051305
13061306test "big.int shift-left multi" {
......@@ -1308,7 +1308,7 @@ test "big.int shift-left multi" {
13081308 defer a.deinit();
13091309 try a.shiftLeft(a, 67);
13101310
1311 testing.expect((try a.to(u128)) == 0xffff0000eeee11100000000000000000);
1311 try testing.expect((try a.to(u128)) == 0xffff0000eeee11100000000000000000);
13121312}
13131313
13141314test "big.int shift-right negative" {
......@@ -1318,12 +1318,12 @@ test "big.int shift-right negative" {
13181318 var arg = try Managed.initSet(testing.allocator, -20);
13191319 defer arg.deinit();
13201320 try a.shiftRight(arg, 2);
1321 testing.expect((try a.to(i32)) == -20 >> 2);
1321 try testing.expect((try a.to(i32)) == -20 >> 2);
13221322
13231323 var arg2 = try Managed.initSet(testing.allocator, -5);
13241324 defer arg2.deinit();
13251325 try a.shiftRight(arg2, 10);
1326 testing.expect((try a.to(i32)) == -5 >> 10);
1326 try testing.expect((try a.to(i32)) == -5 >> 10);
13271327}
13281328
13291329test "big.int shift-left negative" {
......@@ -1333,7 +1333,7 @@ test "big.int shift-left negative" {
13331333 var arg = try Managed.initSet(testing.allocator, -10);
13341334 defer arg.deinit();
13351335 try a.shiftRight(arg, 1232);
1336 testing.expect((try a.to(i32)) == -10 >> 1232);
1336 try testing.expect((try a.to(i32)) == -10 >> 1232);
13371337}
13381338
13391339test "big.int bitwise and simple" {
......@@ -1344,7 +1344,7 @@ test "big.int bitwise and simple" {
13441344
13451345 try a.bitAnd(a, b);
13461346
1347 testing.expect((try a.to(u64)) == 0xeeeeeeee00000000);
1347 try testing.expect((try a.to(u64)) == 0xeeeeeeee00000000);
13481348}
13491349
13501350test "big.int bitwise and multi-limb" {
......@@ -1355,7 +1355,7 @@ test "big.int bitwise and multi-limb" {
13551355
13561356 try a.bitAnd(a, b);
13571357
1358 testing.expect((try a.to(u128)) == 0);
1358 try testing.expect((try a.to(u128)) == 0);
13591359}
13601360
13611361test "big.int bitwise xor simple" {
......@@ -1366,7 +1366,7 @@ test "big.int bitwise xor simple" {
13661366
13671367 try a.bitXor(a, b);
13681368
1369 testing.expect((try a.to(u64)) == 0x1111111133333333);
1369 try testing.expect((try a.to(u64)) == 0x1111111133333333);
13701370}
13711371
13721372test "big.int bitwise xor multi-limb" {
......@@ -1377,7 +1377,7 @@ test "big.int bitwise xor multi-limb" {
13771377
13781378 try a.bitXor(a, b);
13791379
1380 testing.expect((try a.to(DoubleLimb)) == (maxInt(Limb) + 1) ^ maxInt(Limb));
1380 try testing.expect((try a.to(DoubleLimb)) == (maxInt(Limb) + 1) ^ maxInt(Limb));
13811381}
13821382
13831383test "big.int bitwise or simple" {
......@@ -1388,7 +1388,7 @@ test "big.int bitwise or simple" {
13881388
13891389 try a.bitOr(a, b);
13901390
1391 testing.expect((try a.to(u64)) == 0xffffffff33333333);
1391 try testing.expect((try a.to(u64)) == 0xffffffff33333333);
13921392}
13931393
13941394test "big.int bitwise or multi-limb" {
......@@ -1400,7 +1400,7 @@ test "big.int bitwise or multi-limb" {
14001400 try a.bitOr(a, b);
14011401
14021402 // TODO: big.int.cpp or is wrong on multi-limb.
1403 testing.expect((try a.to(DoubleLimb)) == (maxInt(Limb) + 1) + maxInt(Limb));
1403 try testing.expect((try a.to(DoubleLimb)) == (maxInt(Limb) + 1) + maxInt(Limb));
14041404}
14051405
14061406test "big.int var args" {
......@@ -1410,15 +1410,15 @@ test "big.int var args" {
14101410 var b = try Managed.initSet(testing.allocator, 6);
14111411 defer b.deinit();
14121412 try a.add(a.toConst(), b.toConst());
1413 testing.expect((try a.to(u64)) == 11);
1413 try testing.expect((try a.to(u64)) == 11);
14141414
14151415 var c = try Managed.initSet(testing.allocator, 11);
14161416 defer c.deinit();
1417 testing.expect(a.order(c) == .eq);
1417 try testing.expect(a.order(c) == .eq);
14181418
14191419 var d = try Managed.initSet(testing.allocator, 14);
14201420 defer d.deinit();
1421 testing.expect(a.order(d) != .gt);
1421 try testing.expect(a.order(d) != .gt);
14221422}
14231423
14241424test "big.int gcd non-one small" {
......@@ -1431,7 +1431,7 @@ test "big.int gcd non-one small" {
14311431
14321432 try r.gcd(a, b);
14331433
1434 testing.expect((try r.to(u32)) == 1);
1434 try testing.expect((try r.to(u32)) == 1);
14351435}
14361436
14371437test "big.int gcd non-one small" {
......@@ -1444,7 +1444,7 @@ test "big.int gcd non-one small" {
14441444
14451445 try r.gcd(a, b);
14461446
1447 testing.expect((try r.to(u32)) == 38);
1447 try testing.expect((try r.to(u32)) == 38);
14481448}
14491449
14501450test "big.int gcd non-one large" {
......@@ -1457,7 +1457,7 @@ test "big.int gcd non-one large" {
14571457
14581458 try r.gcd(a, b);
14591459
1460 testing.expect((try r.to(u32)) == 4369);
1460 try testing.expect((try r.to(u32)) == 4369);
14611461}
14621462
14631463test "big.int gcd large multi-limb result" {
......@@ -1471,7 +1471,7 @@ test "big.int gcd large multi-limb result" {
14711471 try r.gcd(a, b);
14721472
14731473 const answer = (try r.to(u256));
1474 testing.expect(answer == 0xf000000ff00000fff0000ffff000fffff00ffffff1);
1474 try testing.expect(answer == 0xf000000ff00000fff0000ffff000fffff00ffffff1);
14751475}
14761476
14771477test "big.int gcd one large" {
......@@ -1484,7 +1484,7 @@ test "big.int gcd one large" {
14841484
14851485 try r.gcd(a, b);
14861486
1487 testing.expect((try r.to(u64)) == 1);
1487 try testing.expect((try r.to(u64)) == 1);
14881488}
14891489
14901490test "big.int mutable to managed" {
......@@ -1495,7 +1495,7 @@ test "big.int mutable to managed" {
14951495 var a = Mutable.init(limbs_buf, 0xdeadbeef);
14961496 var a_managed = a.toManaged(allocator);
14971497
1498 testing.expect(a.toConst().eq(a_managed.toConst()));
1498 try testing.expect(a.toConst().eq(a_managed.toConst()));
14991499}
15001500
15011501test "big.int const to managed" {
......@@ -1505,7 +1505,7 @@ test "big.int const to managed" {
15051505 var b = try a.toConst().toManaged(testing.allocator);
15061506 defer b.deinit();
15071507
1508 testing.expect(a.toConst().eq(b.toConst()));
1508 try testing.expect(a.toConst().eq(b.toConst()));
15091509}
15101510
15111511test "big.int pow" {
......@@ -1514,10 +1514,10 @@ test "big.int pow" {
15141514 defer a.deinit();
15151515
15161516 try a.pow(a.toConst(), 3);
1517 testing.expectEqual(@as(i32, -27), try a.to(i32));
1517 try testing.expectEqual(@as(i32, -27), try a.to(i32));
15181518
15191519 try a.pow(a.toConst(), 4);
1520 testing.expectEqual(@as(i32, 531441), try a.to(i32));
1520 try testing.expectEqual(@as(i32, 531441), try a.to(i32));
15211521 }
15221522 {
15231523 var a = try Managed.initSet(testing.allocator, 10);
......@@ -1531,11 +1531,11 @@ test "big.int pow" {
15311531 // y and a are aliased
15321532 try a.pow(a.toConst(), 123);
15331533
1534 testing.expect(a.eq(y));
1534 try testing.expect(a.eq(y));
15351535
15361536 const ys = try y.toString(testing.allocator, 16, false);
15371537 defer testing.allocator.free(ys);
1538 testing.expectEqualSlices(
1538 try testing.expectEqualSlices(
15391539 u8,
15401540 "183425a5f872f126e00a5ad62c839075cd6846c6fb0230887c7ad7a9dc530fcb" ++
15411541 "4933f60e8000000000000000000000000000000",
......@@ -1548,17 +1548,17 @@ test "big.int pow" {
15481548 defer a.deinit();
15491549
15501550 try a.pow(a.toConst(), 100);
1551 testing.expectEqual(@as(i32, 0), try a.to(i32));
1551 try testing.expectEqual(@as(i32, 0), try a.to(i32));
15521552
15531553 try a.set(1);
15541554 try a.pow(a.toConst(), 0);
1555 testing.expectEqual(@as(i32, 1), try a.to(i32));
1555 try testing.expectEqual(@as(i32, 1), try a.to(i32));
15561556 try a.pow(a.toConst(), 100);
1557 testing.expectEqual(@as(i32, 1), try a.to(i32));
1557 try testing.expectEqual(@as(i32, 1), try a.to(i32));
15581558 try a.set(-1);
15591559 try a.pow(a.toConst(), 15);
1560 testing.expectEqual(@as(i32, -1), try a.to(i32));
1560 try testing.expectEqual(@as(i32, -1), try a.to(i32));
15611561 try a.pow(a.toConst(), 16);
1562 testing.expectEqual(@as(i32, 1), try a.to(i32));
1562 try testing.expectEqual(@as(i32, 1), try a.to(i32));
15631563 }
15641564}
lib/std/math/big/rational.zig+67-67
......@@ -473,7 +473,7 @@ pub const Rational = struct {
473473};
474474
475475fn extractLowBits(a: Int, comptime T: type) T {
476 testing.expect(@typeInfo(T) == .Int);
476 debug.assert(@typeInfo(T) == .Int);
477477
478478 const t_bits = @typeInfo(T).Int.bits;
479479 const limb_bits = @typeInfo(Limb).Int.bits;
......@@ -498,19 +498,19 @@ test "big.rational extractLowBits" {
498498 defer a.deinit();
499499
500500 const a1 = extractLowBits(a, u8);
501 testing.expect(a1 == 0x21);
501 try testing.expect(a1 == 0x21);
502502
503503 const a2 = extractLowBits(a, u16);
504 testing.expect(a2 == 0x4321);
504 try testing.expect(a2 == 0x4321);
505505
506506 const a3 = extractLowBits(a, u32);
507 testing.expect(a3 == 0x87654321);
507 try testing.expect(a3 == 0x87654321);
508508
509509 const a4 = extractLowBits(a, u64);
510 testing.expect(a4 == 0x1234567887654321);
510 try testing.expect(a4 == 0x1234567887654321);
511511
512512 const a5 = extractLowBits(a, u128);
513 testing.expect(a5 == 0x11112222333344441234567887654321);
513 try testing.expect(a5 == 0x11112222333344441234567887654321);
514514}
515515
516516test "big.rational set" {
......@@ -518,28 +518,28 @@ test "big.rational set" {
518518 defer a.deinit();
519519
520520 try a.setInt(5);
521 testing.expect((try a.p.to(u32)) == 5);
522 testing.expect((try a.q.to(u32)) == 1);
521 try testing.expect((try a.p.to(u32)) == 5);
522 try testing.expect((try a.q.to(u32)) == 1);
523523
524524 try a.setRatio(7, 3);
525 testing.expect((try a.p.to(u32)) == 7);
526 testing.expect((try a.q.to(u32)) == 3);
525 try testing.expect((try a.p.to(u32)) == 7);
526 try testing.expect((try a.q.to(u32)) == 3);
527527
528528 try a.setRatio(9, 3);
529 testing.expect((try a.p.to(i32)) == 3);
530 testing.expect((try a.q.to(i32)) == 1);
529 try testing.expect((try a.p.to(i32)) == 3);
530 try testing.expect((try a.q.to(i32)) == 1);
531531
532532 try a.setRatio(-9, 3);
533 testing.expect((try a.p.to(i32)) == -3);
534 testing.expect((try a.q.to(i32)) == 1);
533 try testing.expect((try a.p.to(i32)) == -3);
534 try testing.expect((try a.q.to(i32)) == 1);
535535
536536 try a.setRatio(9, -3);
537 testing.expect((try a.p.to(i32)) == -3);
538 testing.expect((try a.q.to(i32)) == 1);
537 try testing.expect((try a.p.to(i32)) == -3);
538 try testing.expect((try a.q.to(i32)) == 1);
539539
540540 try a.setRatio(-9, -3);
541 testing.expect((try a.p.to(i32)) == 3);
542 testing.expect((try a.q.to(i32)) == 1);
541 try testing.expect((try a.p.to(i32)) == 3);
542 try testing.expect((try a.q.to(i32)) == 1);
543543}
544544
545545test "big.rational setFloat" {
......@@ -547,24 +547,24 @@ test "big.rational setFloat" {
547547 defer a.deinit();
548548
549549 try a.setFloat(f64, 2.5);
550 testing.expect((try a.p.to(i32)) == 5);
551 testing.expect((try a.q.to(i32)) == 2);
550 try testing.expect((try a.p.to(i32)) == 5);
551 try testing.expect((try a.q.to(i32)) == 2);
552552
553553 try a.setFloat(f32, -2.5);
554 testing.expect((try a.p.to(i32)) == -5);
555 testing.expect((try a.q.to(i32)) == 2);
554 try testing.expect((try a.p.to(i32)) == -5);
555 try testing.expect((try a.q.to(i32)) == 2);
556556
557557 try a.setFloat(f32, 3.141593);
558558
559559 // = 3.14159297943115234375
560 testing.expect((try a.p.to(u32)) == 3294199);
561 testing.expect((try a.q.to(u32)) == 1048576);
560 try testing.expect((try a.p.to(u32)) == 3294199);
561 try testing.expect((try a.q.to(u32)) == 1048576);
562562
563563 try a.setFloat(f64, 72.141593120712409172417410926841290461290467124);
564564
565565 // = 72.1415931207124145885245525278151035308837890625
566 testing.expect((try a.p.to(u128)) == 5076513310880537);
567 testing.expect((try a.q.to(u128)) == 70368744177664);
566 try testing.expect((try a.p.to(u128)) == 5076513310880537);
567 try testing.expect((try a.q.to(u128)) == 70368744177664);
568568}
569569
570570test "big.rational setFloatString" {
......@@ -574,8 +574,8 @@ test "big.rational setFloatString" {
574574 try a.setFloatString("72.14159312071241458852455252781510353");
575575
576576 // = 72.1415931207124145885245525278151035308837890625
577 testing.expect((try a.p.to(u128)) == 7214159312071241458852455252781510353);
578 testing.expect((try a.q.to(u128)) == 100000000000000000000000000000000000);
577 try testing.expect((try a.p.to(u128)) == 7214159312071241458852455252781510353);
578 try testing.expect((try a.q.to(u128)) == 100000000000000000000000000000000000);
579579}
580580
581581test "big.rational toFloat" {
......@@ -584,11 +584,11 @@ test "big.rational toFloat" {
584584
585585 // = 3.14159297943115234375
586586 try a.setRatio(3294199, 1048576);
587 testing.expect((try a.toFloat(f64)) == 3.14159297943115234375);
587 try testing.expect((try a.toFloat(f64)) == 3.14159297943115234375);
588588
589589 // = 72.1415931207124145885245525278151035308837890625
590590 try a.setRatio(5076513310880537, 70368744177664);
591 testing.expect((try a.toFloat(f64)) == 72.141593120712409172417410926841290461290467124);
591 try testing.expect((try a.toFloat(f64)) == 72.141593120712409172417410926841290461290467124);
592592}
593593
594594test "big.rational set/to Float round-trip" {
......@@ -599,7 +599,7 @@ test "big.rational set/to Float round-trip" {
599599 while (i < 512) : (i += 1) {
600600 const r = prng.random.float(f64);
601601 try a.setFloat(f64, r);
602 testing.expect((try a.toFloat(f64)) == r);
602 try testing.expect((try a.toFloat(f64)) == r);
603603 }
604604}
605605
......@@ -611,8 +611,8 @@ test "big.rational copy" {
611611 defer b.deinit();
612612
613613 try a.copyInt(b);
614 testing.expect((try a.p.to(u32)) == 5);
615 testing.expect((try a.q.to(u32)) == 1);
614 try testing.expect((try a.p.to(u32)) == 5);
615 try testing.expect((try a.q.to(u32)) == 1);
616616
617617 var c = try Int.initSet(testing.allocator, 7);
618618 defer c.deinit();
......@@ -620,8 +620,8 @@ test "big.rational copy" {
620620 defer d.deinit();
621621
622622 try a.copyRatio(c, d);
623 testing.expect((try a.p.to(u32)) == 7);
624 testing.expect((try a.q.to(u32)) == 3);
623 try testing.expect((try a.p.to(u32)) == 7);
624 try testing.expect((try a.q.to(u32)) == 3);
625625
626626 var e = try Int.initSet(testing.allocator, 9);
627627 defer e.deinit();
......@@ -629,8 +629,8 @@ test "big.rational copy" {
629629 defer f.deinit();
630630
631631 try a.copyRatio(e, f);
632 testing.expect((try a.p.to(u32)) == 3);
633 testing.expect((try a.q.to(u32)) == 1);
632 try testing.expect((try a.p.to(u32)) == 3);
633 try testing.expect((try a.q.to(u32)) == 1);
634634}
635635
636636test "big.rational negate" {
......@@ -638,16 +638,16 @@ test "big.rational negate" {
638638 defer a.deinit();
639639
640640 try a.setInt(-50);
641 testing.expect((try a.p.to(i32)) == -50);
642 testing.expect((try a.q.to(i32)) == 1);
641 try testing.expect((try a.p.to(i32)) == -50);
642 try testing.expect((try a.q.to(i32)) == 1);
643643
644644 a.negate();
645 testing.expect((try a.p.to(i32)) == 50);
646 testing.expect((try a.q.to(i32)) == 1);
645 try testing.expect((try a.p.to(i32)) == 50);
646 try testing.expect((try a.q.to(i32)) == 1);
647647
648648 a.negate();
649 testing.expect((try a.p.to(i32)) == -50);
650 testing.expect((try a.q.to(i32)) == 1);
649 try testing.expect((try a.p.to(i32)) == -50);
650 try testing.expect((try a.q.to(i32)) == 1);
651651}
652652
653653test "big.rational abs" {
......@@ -655,16 +655,16 @@ test "big.rational abs" {
655655 defer a.deinit();
656656
657657 try a.setInt(-50);
658 testing.expect((try a.p.to(i32)) == -50);
659 testing.expect((try a.q.to(i32)) == 1);
658 try testing.expect((try a.p.to(i32)) == -50);
659 try testing.expect((try a.q.to(i32)) == 1);
660660
661661 a.abs();
662 testing.expect((try a.p.to(i32)) == 50);
663 testing.expect((try a.q.to(i32)) == 1);
662 try testing.expect((try a.p.to(i32)) == 50);
663 try testing.expect((try a.q.to(i32)) == 1);
664664
665665 a.abs();
666 testing.expect((try a.p.to(i32)) == 50);
667 testing.expect((try a.q.to(i32)) == 1);
666 try testing.expect((try a.p.to(i32)) == 50);
667 try testing.expect((try a.q.to(i32)) == 1);
668668}
669669
670670test "big.rational swap" {
......@@ -676,19 +676,19 @@ test "big.rational swap" {
676676 try a.setRatio(50, 23);
677677 try b.setRatio(17, 3);
678678
679 testing.expect((try a.p.to(u32)) == 50);
680 testing.expect((try a.q.to(u32)) == 23);
679 try testing.expect((try a.p.to(u32)) == 50);
680 try testing.expect((try a.q.to(u32)) == 23);
681681
682 testing.expect((try b.p.to(u32)) == 17);
683 testing.expect((try b.q.to(u32)) == 3);
682 try testing.expect((try b.p.to(u32)) == 17);
683 try testing.expect((try b.q.to(u32)) == 3);
684684
685685 a.swap(&b);
686686
687 testing.expect((try a.p.to(u32)) == 17);
688 testing.expect((try a.q.to(u32)) == 3);
687 try testing.expect((try a.p.to(u32)) == 17);
688 try testing.expect((try a.q.to(u32)) == 3);
689689
690 testing.expect((try b.p.to(u32)) == 50);
691 testing.expect((try b.q.to(u32)) == 23);
690 try testing.expect((try b.p.to(u32)) == 50);
691 try testing.expect((try b.q.to(u32)) == 23);
692692}
693693
694694test "big.rational order" {
......@@ -699,11 +699,11 @@ test "big.rational order" {
699699
700700 try a.setRatio(500, 231);
701701 try b.setRatio(18903, 8584);
702 testing.expect((try a.order(b)) == .lt);
702 try testing.expect((try a.order(b)) == .lt);
703703
704704 try a.setRatio(890, 10);
705705 try b.setRatio(89, 1);
706 testing.expect((try a.order(b)) == .eq);
706 try testing.expect((try a.order(b)) == .eq);
707707}
708708
709709test "big.rational add single-limb" {
......@@ -714,11 +714,11 @@ test "big.rational add single-limb" {
714714
715715 try a.setRatio(500, 231);
716716 try b.setRatio(18903, 8584);
717 testing.expect((try a.order(b)) == .lt);
717 try testing.expect((try a.order(b)) == .lt);
718718
719719 try a.setRatio(890, 10);
720720 try b.setRatio(89, 1);
721 testing.expect((try a.order(b)) == .eq);
721 try testing.expect((try a.order(b)) == .eq);
722722}
723723
724724test "big.rational add" {
......@@ -734,7 +734,7 @@ test "big.rational add" {
734734 try a.add(a, b);
735735
736736 try r.setRatio(984786924199, 290395044174);
737 testing.expect((try a.order(r)) == .eq);
737 try testing.expect((try a.order(r)) == .eq);
738738}
739739
740740test "big.rational sub" {
......@@ -750,7 +750,7 @@ test "big.rational sub" {
750750 try a.sub(a, b);
751751
752752 try r.setRatio(979040510045, 290395044174);
753 testing.expect((try a.order(r)) == .eq);
753 try testing.expect((try a.order(r)) == .eq);
754754}
755755
756756test "big.rational mul" {
......@@ -766,7 +766,7 @@ test "big.rational mul" {
766766 try a.mul(a, b);
767767
768768 try r.setRatio(571481443, 17082061422);
769 testing.expect((try a.order(r)) == .eq);
769 try testing.expect((try a.order(r)) == .eq);
770770}
771771
772772test "big.rational div" {
......@@ -782,7 +782,7 @@ test "big.rational div" {
782782 try a.div(a, b);
783783
784784 try r.setRatio(75531824394, 221015929);
785 testing.expect((try a.order(r)) == .eq);
785 try testing.expect((try a.order(r)) == .eq);
786786}
787787
788788test "big.rational div" {
......@@ -795,11 +795,11 @@ test "big.rational div" {
795795 a.invert();
796796
797797 try r.setRatio(23341, 78923);
798 testing.expect((try a.order(r)) == .eq);
798 try testing.expect((try a.order(r)) == .eq);
799799
800800 try a.setRatio(-78923, 23341);
801801 a.invert();
802802
803803 try r.setRatio(-23341, 78923);
804 testing.expect((try a.order(r)) == .eq);
804 try testing.expect((try a.order(r)) == .eq);
805805}
lib/std/math/cbrt.zig+24-24
......@@ -125,44 +125,44 @@ fn cbrt64(x: f64) f64 {
125125}
126126
127127test "math.cbrt" {
128 expect(cbrt(@as(f32, 0.0)) == cbrt32(0.0));
129 expect(cbrt(@as(f64, 0.0)) == cbrt64(0.0));
128 try expect(cbrt(@as(f32, 0.0)) == cbrt32(0.0));
129 try expect(cbrt(@as(f64, 0.0)) == cbrt64(0.0));
130130}
131131
132132test "math.cbrt32" {
133133 const epsilon = 0.000001;
134134
135 expect(cbrt32(0.0) == 0.0);
136 expect(math.approxEqAbs(f32, cbrt32(0.2), 0.584804, epsilon));
137 expect(math.approxEqAbs(f32, cbrt32(0.8923), 0.962728, epsilon));
138 expect(math.approxEqAbs(f32, cbrt32(1.5), 1.144714, epsilon));
139 expect(math.approxEqAbs(f32, cbrt32(37.45), 3.345676, epsilon));
140 expect(math.approxEqAbs(f32, cbrt32(123123.234375), 49.748501, epsilon));
135 try expect(cbrt32(0.0) == 0.0);
136 try expect(math.approxEqAbs(f32, cbrt32(0.2), 0.584804, epsilon));
137 try expect(math.approxEqAbs(f32, cbrt32(0.8923), 0.962728, epsilon));
138 try expect(math.approxEqAbs(f32, cbrt32(1.5), 1.144714, epsilon));
139 try expect(math.approxEqAbs(f32, cbrt32(37.45), 3.345676, epsilon));
140 try expect(math.approxEqAbs(f32, cbrt32(123123.234375), 49.748501, epsilon));
141141}
142142
143143test "math.cbrt64" {
144144 const epsilon = 0.000001;
145145
146 expect(cbrt64(0.0) == 0.0);
147 expect(math.approxEqAbs(f64, cbrt64(0.2), 0.584804, epsilon));
148 expect(math.approxEqAbs(f64, cbrt64(0.8923), 0.962728, epsilon));
149 expect(math.approxEqAbs(f64, cbrt64(1.5), 1.144714, epsilon));
150 expect(math.approxEqAbs(f64, cbrt64(37.45), 3.345676, epsilon));
151 expect(math.approxEqAbs(f64, cbrt64(123123.234375), 49.748501, epsilon));
146 try expect(cbrt64(0.0) == 0.0);
147 try expect(math.approxEqAbs(f64, cbrt64(0.2), 0.584804, epsilon));
148 try expect(math.approxEqAbs(f64, cbrt64(0.8923), 0.962728, epsilon));
149 try expect(math.approxEqAbs(f64, cbrt64(1.5), 1.144714, epsilon));
150 try expect(math.approxEqAbs(f64, cbrt64(37.45), 3.345676, epsilon));
151 try expect(math.approxEqAbs(f64, cbrt64(123123.234375), 49.748501, epsilon));
152152}
153153
154154test "math.cbrt.special" {
155 expect(cbrt32(0.0) == 0.0);
156 expect(cbrt32(-0.0) == -0.0);
157 expect(math.isPositiveInf(cbrt32(math.inf(f32))));
158 expect(math.isNegativeInf(cbrt32(-math.inf(f32))));
159 expect(math.isNan(cbrt32(math.nan(f32))));
155 try expect(cbrt32(0.0) == 0.0);
156 try expect(cbrt32(-0.0) == -0.0);
157 try expect(math.isPositiveInf(cbrt32(math.inf(f32))));
158 try expect(math.isNegativeInf(cbrt32(-math.inf(f32))));
159 try expect(math.isNan(cbrt32(math.nan(f32))));
160160}
161161
162162test "math.cbrt64.special" {
163 expect(cbrt64(0.0) == 0.0);
164 expect(cbrt64(-0.0) == -0.0);
165 expect(math.isPositiveInf(cbrt64(math.inf(f64))));
166 expect(math.isNegativeInf(cbrt64(-math.inf(f64))));
167 expect(math.isNan(cbrt64(math.nan(f64))));
163 try expect(cbrt64(0.0) == 0.0);
164 try expect(cbrt64(-0.0) == -0.0);
165 try expect(math.isPositiveInf(cbrt64(math.inf(f64))));
166 try expect(math.isNegativeInf(cbrt64(-math.inf(f64))));
167 try expect(math.isNan(cbrt64(math.nan(f64))));
168168}
lib/std/math/ceil.zig+27-27
......@@ -119,49 +119,49 @@ fn ceil128(x: f128) f128 {
119119}
120120
121121test "math.ceil" {
122 expect(ceil(@as(f32, 0.0)) == ceil32(0.0));
123 expect(ceil(@as(f64, 0.0)) == ceil64(0.0));
124 expect(ceil(@as(f128, 0.0)) == ceil128(0.0));
122 try expect(ceil(@as(f32, 0.0)) == ceil32(0.0));
123 try expect(ceil(@as(f64, 0.0)) == ceil64(0.0));
124 try expect(ceil(@as(f128, 0.0)) == ceil128(0.0));
125125}
126126
127127test "math.ceil32" {
128 expect(ceil32(1.3) == 2.0);
129 expect(ceil32(-1.3) == -1.0);
130 expect(ceil32(0.2) == 1.0);
128 try expect(ceil32(1.3) == 2.0);
129 try expect(ceil32(-1.3) == -1.0);
130 try expect(ceil32(0.2) == 1.0);
131131}
132132
133133test "math.ceil64" {
134 expect(ceil64(1.3) == 2.0);
135 expect(ceil64(-1.3) == -1.0);
136 expect(ceil64(0.2) == 1.0);
134 try expect(ceil64(1.3) == 2.0);
135 try expect(ceil64(-1.3) == -1.0);
136 try expect(ceil64(0.2) == 1.0);
137137}
138138
139139test "math.ceil128" {
140 expect(ceil128(1.3) == 2.0);
141 expect(ceil128(-1.3) == -1.0);
142 expect(ceil128(0.2) == 1.0);
140 try expect(ceil128(1.3) == 2.0);
141 try expect(ceil128(-1.3) == -1.0);
142 try expect(ceil128(0.2) == 1.0);
143143}
144144
145145test "math.ceil32.special" {
146 expect(ceil32(0.0) == 0.0);
147 expect(ceil32(-0.0) == -0.0);
148 expect(math.isPositiveInf(ceil32(math.inf(f32))));
149 expect(math.isNegativeInf(ceil32(-math.inf(f32))));
150 expect(math.isNan(ceil32(math.nan(f32))));
146 try expect(ceil32(0.0) == 0.0);
147 try expect(ceil32(-0.0) == -0.0);
148 try expect(math.isPositiveInf(ceil32(math.inf(f32))));
149 try expect(math.isNegativeInf(ceil32(-math.inf(f32))));
150 try expect(math.isNan(ceil32(math.nan(f32))));
151151}
152152
153153test "math.ceil64.special" {
154 expect(ceil64(0.0) == 0.0);
155 expect(ceil64(-0.0) == -0.0);
156 expect(math.isPositiveInf(ceil64(math.inf(f64))));
157 expect(math.isNegativeInf(ceil64(-math.inf(f64))));
158 expect(math.isNan(ceil64(math.nan(f64))));
154 try expect(ceil64(0.0) == 0.0);
155 try expect(ceil64(-0.0) == -0.0);
156 try expect(math.isPositiveInf(ceil64(math.inf(f64))));
157 try expect(math.isNegativeInf(ceil64(-math.inf(f64))));
158 try expect(math.isNan(ceil64(math.nan(f64))));
159159}
160160
161161test "math.ceil128.special" {
162 expect(ceil128(0.0) == 0.0);
163 expect(ceil128(-0.0) == -0.0);
164 expect(math.isPositiveInf(ceil128(math.inf(f128))));
165 expect(math.isNegativeInf(ceil128(-math.inf(f128))));
166 expect(math.isNan(ceil128(math.nan(f128))));
162 try expect(ceil128(0.0) == 0.0);
163 try expect(ceil128(-0.0) == -0.0);
164 try expect(math.isPositiveInf(ceil128(math.inf(f128))));
165 try expect(math.isNegativeInf(ceil128(-math.inf(f128))));
166 try expect(math.isNan(ceil128(math.nan(f128))));
167167}
lib/std/math/complex.zig+7-7
......@@ -114,7 +114,7 @@ test "complex.add" {
114114 const b = Complex(f32).new(2, 7);
115115 const c = a.add(b);
116116
117 testing.expect(c.re == 7 and c.im == 10);
117 try testing.expect(c.re == 7 and c.im == 10);
118118}
119119
120120test "complex.sub" {
......@@ -122,7 +122,7 @@ test "complex.sub" {
122122 const b = Complex(f32).new(2, 7);
123123 const c = a.sub(b);
124124
125 testing.expect(c.re == 3 and c.im == -4);
125 try testing.expect(c.re == 3 and c.im == -4);
126126}
127127
128128test "complex.mul" {
......@@ -130,7 +130,7 @@ test "complex.mul" {
130130 const b = Complex(f32).new(2, 7);
131131 const c = a.mul(b);
132132
133 testing.expect(c.re == -11 and c.im == 41);
133 try testing.expect(c.re == -11 and c.im == 41);
134134}
135135
136136test "complex.div" {
......@@ -138,7 +138,7 @@ test "complex.div" {
138138 const b = Complex(f32).new(2, 7);
139139 const c = a.div(b);
140140
141 testing.expect(math.approxEqAbs(f32, c.re, @as(f32, 31) / 53, epsilon) and
141 try testing.expect(math.approxEqAbs(f32, c.re, @as(f32, 31) / 53, epsilon) and
142142 math.approxEqAbs(f32, c.im, @as(f32, -29) / 53, epsilon));
143143}
144144
......@@ -146,14 +146,14 @@ test "complex.conjugate" {
146146 const a = Complex(f32).new(5, 3);
147147 const c = a.conjugate();
148148
149 testing.expect(c.re == 5 and c.im == -3);
149 try testing.expect(c.re == 5 and c.im == -3);
150150}
151151
152152test "complex.reciprocal" {
153153 const a = Complex(f32).new(5, 3);
154154 const c = a.reciprocal();
155155
156 testing.expect(math.approxEqAbs(f32, c.re, @as(f32, 5) / 34, epsilon) and
156 try testing.expect(math.approxEqAbs(f32, c.re, @as(f32, 5) / 34, epsilon) and
157157 math.approxEqAbs(f32, c.im, @as(f32, -3) / 34, epsilon));
158158}
159159
......@@ -161,7 +161,7 @@ test "complex.magnitude" {
161161 const a = Complex(f32).new(5, 3);
162162 const c = a.magnitude();
163163
164 testing.expect(math.approxEqAbs(f32, c, 5.83095, epsilon));
164 try testing.expect(math.approxEqAbs(f32, c, 5.83095, epsilon));
165165}
166166
167167test "complex.cmath" {
lib/std/math/complex/abs.zig+1-1
......@@ -20,5 +20,5 @@ const epsilon = 0.0001;
2020test "complex.cabs" {
2121 const a = Complex(f32).new(5, 3);
2222 const c = abs(a);
23 testing.expect(math.approxEqAbs(f32, c, 5.83095, epsilon));
23 try testing.expect(math.approxEqAbs(f32, c, 5.83095, epsilon));
2424}
lib/std/math/complex/acos.zig+2-2
......@@ -22,6 +22,6 @@ test "complex.cacos" {
2222 const a = Complex(f32).new(5, 3);
2323 const c = acos(a);
2424
25 testing.expect(math.approxEqAbs(f32, c.re, 0.546975, epsilon));
26 testing.expect(math.approxEqAbs(f32, c.im, -2.452914, epsilon));
25 try testing.expect(math.approxEqAbs(f32, c.re, 0.546975, epsilon));
26 try testing.expect(math.approxEqAbs(f32, c.im, -2.452914, epsilon));
2727}
lib/std/math/complex/acosh.zig+2-2
......@@ -22,6 +22,6 @@ test "complex.cacosh" {
2222 const a = Complex(f32).new(5, 3);
2323 const c = acosh(a);
2424
25 testing.expect(math.approxEqAbs(f32, c.re, 2.452914, epsilon));
26 testing.expect(math.approxEqAbs(f32, c.im, 0.546975, epsilon));
25 try testing.expect(math.approxEqAbs(f32, c.re, 2.452914, epsilon));
26 try testing.expect(math.approxEqAbs(f32, c.im, 0.546975, epsilon));
2727}
lib/std/math/complex/arg.zig+1-1
......@@ -20,5 +20,5 @@ const epsilon = 0.0001;
2020test "complex.carg" {
2121 const a = Complex(f32).new(5, 3);
2222 const c = arg(a);
23 testing.expect(math.approxEqAbs(f32, c, 0.540420, epsilon));
23 try testing.expect(math.approxEqAbs(f32, c, 0.540420, epsilon));
2424}
lib/std/math/complex/asin.zig+2-2
......@@ -28,6 +28,6 @@ test "complex.casin" {
2828 const a = Complex(f32).new(5, 3);
2929 const c = asin(a);
3030
31 testing.expect(math.approxEqAbs(f32, c.re, 1.023822, epsilon));
32 testing.expect(math.approxEqAbs(f32, c.im, 2.452914, epsilon));
31 try testing.expect(math.approxEqAbs(f32, c.re, 1.023822, epsilon));
32 try testing.expect(math.approxEqAbs(f32, c.im, 2.452914, epsilon));
3333}
lib/std/math/complex/asinh.zig+2-2
......@@ -23,6 +23,6 @@ test "complex.casinh" {
2323 const a = Complex(f32).new(5, 3);
2424 const c = asinh(a);
2525
26 testing.expect(math.approxEqAbs(f32, c.re, 2.459831, epsilon));
27 testing.expect(math.approxEqAbs(f32, c.im, 0.533999, epsilon));
26 try testing.expect(math.approxEqAbs(f32, c.re, 2.459831, epsilon));
27 try testing.expect(math.approxEqAbs(f32, c.im, 0.533999, epsilon));
2828}
lib/std/math/complex/atan.zig+4-4
......@@ -129,14 +129,14 @@ test "complex.catan32" {
129129 const a = Complex(f32).new(5, 3);
130130 const c = atan(a);
131131
132 testing.expect(math.approxEqAbs(f32, c.re, 1.423679, epsilon));
133 testing.expect(math.approxEqAbs(f32, c.im, 0.086569, epsilon));
132 try testing.expect(math.approxEqAbs(f32, c.re, 1.423679, epsilon));
133 try testing.expect(math.approxEqAbs(f32, c.im, 0.086569, epsilon));
134134}
135135
136136test "complex.catan64" {
137137 const a = Complex(f64).new(5, 3);
138138 const c = atan(a);
139139
140 testing.expect(math.approxEqAbs(f64, c.re, 1.423679, epsilon));
141 testing.expect(math.approxEqAbs(f64, c.im, 0.086569, epsilon));
140 try testing.expect(math.approxEqAbs(f64, c.re, 1.423679, epsilon));
141 try testing.expect(math.approxEqAbs(f64, c.im, 0.086569, epsilon));
142142}
lib/std/math/complex/atanh.zig+2-2
......@@ -23,6 +23,6 @@ test "complex.catanh" {
2323 const a = Complex(f32).new(5, 3);
2424 const c = atanh(a);
2525
26 testing.expect(math.approxEqAbs(f32, c.re, 0.146947, epsilon));
27 testing.expect(math.approxEqAbs(f32, c.im, 1.480870, epsilon));
26 try testing.expect(math.approxEqAbs(f32, c.re, 0.146947, epsilon));
27 try testing.expect(math.approxEqAbs(f32, c.im, 1.480870, epsilon));
2828}
lib/std/math/complex/conj.zig+1-1
......@@ -19,5 +19,5 @@ test "complex.conj" {
1919 const a = Complex(f32).new(5, 3);
2020 const c = a.conjugate();
2121
22 testing.expect(c.re == 5 and c.im == -3);
22 try testing.expect(c.re == 5 and c.im == -3);
2323}
lib/std/math/complex/cos.zig+2-2
......@@ -22,6 +22,6 @@ test "complex.ccos" {
2222 const a = Complex(f32).new(5, 3);
2323 const c = cos(a);
2424
25 testing.expect(math.approxEqAbs(f32, c.re, 2.855815, epsilon));
26 testing.expect(math.approxEqAbs(f32, c.im, 9.606383, epsilon));
25 try testing.expect(math.approxEqAbs(f32, c.re, 2.855815, epsilon));
26 try testing.expect(math.approxEqAbs(f32, c.im, 9.606383, epsilon));
2727}
lib/std/math/complex/cosh.zig+4-4
......@@ -164,14 +164,14 @@ test "complex.ccosh32" {
164164 const a = Complex(f32).new(5, 3);
165165 const c = cosh(a);
166166
167 testing.expect(math.approxEqAbs(f32, c.re, -73.467300, epsilon));
168 testing.expect(math.approxEqAbs(f32, c.im, 10.471557, epsilon));
167 try testing.expect(math.approxEqAbs(f32, c.re, -73.467300, epsilon));
168 try testing.expect(math.approxEqAbs(f32, c.im, 10.471557, epsilon));
169169}
170170
171171test "complex.ccosh64" {
172172 const a = Complex(f64).new(5, 3);
173173 const c = cosh(a);
174174
175 testing.expect(math.approxEqAbs(f64, c.re, -73.467300, epsilon));
176 testing.expect(math.approxEqAbs(f64, c.im, 10.471557, epsilon));
175 try testing.expect(math.approxEqAbs(f64, c.re, -73.467300, epsilon));
176 try testing.expect(math.approxEqAbs(f64, c.im, 10.471557, epsilon));
177177}
lib/std/math/complex/exp.zig+4-4
......@@ -130,14 +130,14 @@ test "complex.cexp32" {
130130 const a = Complex(f32).new(5, 3);
131131 const c = exp(a);
132132
133 testing.expect(math.approxEqAbs(f32, c.re, -146.927917, epsilon));
134 testing.expect(math.approxEqAbs(f32, c.im, 20.944065, epsilon));
133 try testing.expect(math.approxEqAbs(f32, c.re, -146.927917, epsilon));
134 try testing.expect(math.approxEqAbs(f32, c.im, 20.944065, epsilon));
135135}
136136
137137test "complex.cexp64" {
138138 const a = Complex(f64).new(5, 3);
139139 const c = exp(a);
140140
141 testing.expect(math.approxEqAbs(f64, c.re, -146.927917, epsilon));
142 testing.expect(math.approxEqAbs(f64, c.im, 20.944065, epsilon));
141 try testing.expect(math.approxEqAbs(f64, c.re, -146.927917, epsilon));
142 try testing.expect(math.approxEqAbs(f64, c.im, 20.944065, epsilon));
143143}
lib/std/math/complex/log.zig+2-2
......@@ -24,6 +24,6 @@ test "complex.clog" {
2424 const a = Complex(f32).new(5, 3);
2525 const c = log(a);
2626
27 testing.expect(math.approxEqAbs(f32, c.re, 1.763180, epsilon));
28 testing.expect(math.approxEqAbs(f32, c.im, 0.540419, epsilon));
27 try testing.expect(math.approxEqAbs(f32, c.re, 1.763180, epsilon));
28 try testing.expect(math.approxEqAbs(f32, c.im, 0.540419, epsilon));
2929}
lib/std/math/complex/pow.zig+2-2
......@@ -23,6 +23,6 @@ test "complex.cpow" {
2323 const b = Complex(f32).new(2.3, -1.3);
2424 const c = pow(Complex(f32), a, b);
2525
26 testing.expect(math.approxEqAbs(f32, c.re, 58.049110, epsilon));
27 testing.expect(math.approxEqAbs(f32, c.im, -101.003433, epsilon));
26 try testing.expect(math.approxEqAbs(f32, c.re, 58.049110, epsilon));
27 try testing.expect(math.approxEqAbs(f32, c.im, -101.003433, epsilon));
2828}
lib/std/math/complex/proj.zig+1-1
......@@ -26,5 +26,5 @@ test "complex.cproj" {
2626 const a = Complex(f32).new(5, 3);
2727 const c = proj(a);
2828
29 testing.expect(c.re == 5 and c.im == 3);
29 try testing.expect(c.re == 5 and c.im == 3);
3030}
lib/std/math/complex/sin.zig+2-2
......@@ -23,6 +23,6 @@ test "complex.csin" {
2323 const a = Complex(f32).new(5, 3);
2424 const c = sin(a);
2525
26 testing.expect(math.approxEqAbs(f32, c.re, -9.654126, epsilon));
27 testing.expect(math.approxEqAbs(f32, c.im, 2.841692, epsilon));
26 try testing.expect(math.approxEqAbs(f32, c.re, -9.654126, epsilon));
27 try testing.expect(math.approxEqAbs(f32, c.im, 2.841692, epsilon));
2828}
lib/std/math/complex/sinh.zig+4-4
......@@ -163,14 +163,14 @@ test "complex.csinh32" {
163163 const a = Complex(f32).new(5, 3);
164164 const c = sinh(a);
165165
166 testing.expect(math.approxEqAbs(f32, c.re, -73.460617, epsilon));
167 testing.expect(math.approxEqAbs(f32, c.im, 10.472508, epsilon));
166 try testing.expect(math.approxEqAbs(f32, c.re, -73.460617, epsilon));
167 try testing.expect(math.approxEqAbs(f32, c.im, 10.472508, epsilon));
168168}
169169
170170test "complex.csinh64" {
171171 const a = Complex(f64).new(5, 3);
172172 const c = sinh(a);
173173
174 testing.expect(math.approxEqAbs(f64, c.re, -73.460617, epsilon));
175 testing.expect(math.approxEqAbs(f64, c.im, 10.472508, epsilon));
174 try testing.expect(math.approxEqAbs(f64, c.re, -73.460617, epsilon));
175 try testing.expect(math.approxEqAbs(f64, c.im, 10.472508, epsilon));
176176}
lib/std/math/complex/sqrt.zig+4-4
......@@ -138,14 +138,14 @@ test "complex.csqrt32" {
138138 const a = Complex(f32).new(5, 3);
139139 const c = sqrt(a);
140140
141 testing.expect(math.approxEqAbs(f32, c.re, 2.327117, epsilon));
142 testing.expect(math.approxEqAbs(f32, c.im, 0.644574, epsilon));
141 try testing.expect(math.approxEqAbs(f32, c.re, 2.327117, epsilon));
142 try testing.expect(math.approxEqAbs(f32, c.im, 0.644574, epsilon));
143143}
144144
145145test "complex.csqrt64" {
146146 const a = Complex(f64).new(5, 3);
147147 const c = sqrt(a);
148148
149 testing.expect(math.approxEqAbs(f64, c.re, 2.3271175190399496, epsilon));
150 testing.expect(math.approxEqAbs(f64, c.im, 0.6445742373246469, epsilon));
149 try testing.expect(math.approxEqAbs(f64, c.re, 2.3271175190399496, epsilon));
150 try testing.expect(math.approxEqAbs(f64, c.im, 0.6445742373246469, epsilon));
151151}
lib/std/math/complex/tan.zig+2-2
......@@ -23,6 +23,6 @@ test "complex.ctan" {
2323 const a = Complex(f32).new(5, 3);
2424 const c = tan(a);
2525
26 testing.expect(math.approxEqAbs(f32, c.re, -0.002708233, epsilon));
27 testing.expect(math.approxEqAbs(f32, c.im, 1.004165, epsilon));
26 try testing.expect(math.approxEqAbs(f32, c.re, -0.002708233, epsilon));
27 try testing.expect(math.approxEqAbs(f32, c.im, 1.004165, epsilon));
2828}
lib/std/math/complex/tanh.zig+4-4
......@@ -112,14 +112,14 @@ test "complex.ctanh32" {
112112 const a = Complex(f32).new(5, 3);
113113 const c = tanh(a);
114114
115 testing.expect(math.approxEqAbs(f32, c.re, 0.999913, epsilon));
116 testing.expect(math.approxEqAbs(f32, c.im, -0.000025, epsilon));
115 try testing.expect(math.approxEqAbs(f32, c.re, 0.999913, epsilon));
116 try testing.expect(math.approxEqAbs(f32, c.im, -0.000025, epsilon));
117117}
118118
119119test "complex.ctanh64" {
120120 const a = Complex(f64).new(5, 3);
121121 const c = tanh(a);
122122
123 testing.expect(math.approxEqAbs(f64, c.re, 0.999913, epsilon));
124 testing.expect(math.approxEqAbs(f64, c.im, -0.000025, epsilon));
123 try testing.expect(math.approxEqAbs(f64, c.re, 0.999913, epsilon));
124 try testing.expect(math.approxEqAbs(f64, c.im, -0.000025, epsilon));
125125}
lib/std/math/copysign.zig+20-20
......@@ -62,36 +62,36 @@ fn copysign128(x: f128, y: f128) f128 {
6262}
6363
6464test "math.copysign" {
65 expect(copysign(f16, 1.0, 1.0) == copysign16(1.0, 1.0));
66 expect(copysign(f32, 1.0, 1.0) == copysign32(1.0, 1.0));
67 expect(copysign(f64, 1.0, 1.0) == copysign64(1.0, 1.0));
68 expect(copysign(f128, 1.0, 1.0) == copysign128(1.0, 1.0));
65 try expect(copysign(f16, 1.0, 1.0) == copysign16(1.0, 1.0));
66 try expect(copysign(f32, 1.0, 1.0) == copysign32(1.0, 1.0));
67 try expect(copysign(f64, 1.0, 1.0) == copysign64(1.0, 1.0));
68 try expect(copysign(f128, 1.0, 1.0) == copysign128(1.0, 1.0));
6969}
7070
7171test "math.copysign16" {
72 expect(copysign16(5.0, 1.0) == 5.0);
73 expect(copysign16(5.0, -1.0) == -5.0);
74 expect(copysign16(-5.0, -1.0) == -5.0);
75 expect(copysign16(-5.0, 1.0) == 5.0);
72 try expect(copysign16(5.0, 1.0) == 5.0);
73 try expect(copysign16(5.0, -1.0) == -5.0);
74 try expect(copysign16(-5.0, -1.0) == -5.0);
75 try expect(copysign16(-5.0, 1.0) == 5.0);
7676}
7777
7878test "math.copysign32" {
79 expect(copysign32(5.0, 1.0) == 5.0);
80 expect(copysign32(5.0, -1.0) == -5.0);
81 expect(copysign32(-5.0, -1.0) == -5.0);
82 expect(copysign32(-5.0, 1.0) == 5.0);
79 try expect(copysign32(5.0, 1.0) == 5.0);
80 try expect(copysign32(5.0, -1.0) == -5.0);
81 try expect(copysign32(-5.0, -1.0) == -5.0);
82 try expect(copysign32(-5.0, 1.0) == 5.0);
8383}
8484
8585test "math.copysign64" {
86 expect(copysign64(5.0, 1.0) == 5.0);
87 expect(copysign64(5.0, -1.0) == -5.0);
88 expect(copysign64(-5.0, -1.0) == -5.0);
89 expect(copysign64(-5.0, 1.0) == 5.0);
86 try expect(copysign64(5.0, 1.0) == 5.0);
87 try expect(copysign64(5.0, -1.0) == -5.0);
88 try expect(copysign64(-5.0, -1.0) == -5.0);
89 try expect(copysign64(-5.0, 1.0) == 5.0);
9090}
9191
9292test "math.copysign128" {
93 expect(copysign128(5.0, 1.0) == 5.0);
94 expect(copysign128(5.0, -1.0) == -5.0);
95 expect(copysign128(-5.0, -1.0) == -5.0);
96 expect(copysign128(-5.0, 1.0) == 5.0);
93 try expect(copysign128(5.0, 1.0) == 5.0);
94 try expect(copysign128(5.0, -1.0) == -5.0);
95 try expect(copysign128(-5.0, -1.0) == -5.0);
96 try expect(copysign128(-5.0, 1.0) == 5.0);
9797}
lib/std/math/cos.zig+22-22
......@@ -87,42 +87,42 @@ fn cos_(comptime T: type, x_: T) T {
8787}
8888
8989test "math.cos" {
90 expect(cos(@as(f32, 0.0)) == cos_(f32, 0.0));
91 expect(cos(@as(f64, 0.0)) == cos_(f64, 0.0));
90 try expect(cos(@as(f32, 0.0)) == cos_(f32, 0.0));
91 try expect(cos(@as(f64, 0.0)) == cos_(f64, 0.0));
9292}
9393
9494test "math.cos32" {
9595 const epsilon = 0.000001;
9696
97 expect(math.approxEqAbs(f32, cos_(f32, 0.0), 1.0, epsilon));
98 expect(math.approxEqAbs(f32, cos_(f32, 0.2), 0.980067, epsilon));
99 expect(math.approxEqAbs(f32, cos_(f32, 0.8923), 0.627623, epsilon));
100 expect(math.approxEqAbs(f32, cos_(f32, 1.5), 0.070737, epsilon));
101 expect(math.approxEqAbs(f32, cos_(f32, -1.5), 0.070737, epsilon));
102 expect(math.approxEqAbs(f32, cos_(f32, 37.45), 0.969132, epsilon));
103 expect(math.approxEqAbs(f32, cos_(f32, 89.123), 0.400798, epsilon));
97 try expect(math.approxEqAbs(f32, cos_(f32, 0.0), 1.0, epsilon));
98 try expect(math.approxEqAbs(f32, cos_(f32, 0.2), 0.980067, epsilon));
99 try expect(math.approxEqAbs(f32, cos_(f32, 0.8923), 0.627623, epsilon));
100 try expect(math.approxEqAbs(f32, cos_(f32, 1.5), 0.070737, epsilon));
101 try expect(math.approxEqAbs(f32, cos_(f32, -1.5), 0.070737, epsilon));
102 try expect(math.approxEqAbs(f32, cos_(f32, 37.45), 0.969132, epsilon));
103 try expect(math.approxEqAbs(f32, cos_(f32, 89.123), 0.400798, epsilon));
104104}
105105
106106test "math.cos64" {
107107 const epsilon = 0.000001;
108108
109 expect(math.approxEqAbs(f64, cos_(f64, 0.0), 1.0, epsilon));
110 expect(math.approxEqAbs(f64, cos_(f64, 0.2), 0.980067, epsilon));
111 expect(math.approxEqAbs(f64, cos_(f64, 0.8923), 0.627623, epsilon));
112 expect(math.approxEqAbs(f64, cos_(f64, 1.5), 0.070737, epsilon));
113 expect(math.approxEqAbs(f64, cos_(f64, -1.5), 0.070737, epsilon));
114 expect(math.approxEqAbs(f64, cos_(f64, 37.45), 0.969132, epsilon));
115 expect(math.approxEqAbs(f64, cos_(f64, 89.123), 0.40080, epsilon));
109 try expect(math.approxEqAbs(f64, cos_(f64, 0.0), 1.0, epsilon));
110 try expect(math.approxEqAbs(f64, cos_(f64, 0.2), 0.980067, epsilon));
111 try expect(math.approxEqAbs(f64, cos_(f64, 0.8923), 0.627623, epsilon));
112 try expect(math.approxEqAbs(f64, cos_(f64, 1.5), 0.070737, epsilon));
113 try expect(math.approxEqAbs(f64, cos_(f64, -1.5), 0.070737, epsilon));
114 try expect(math.approxEqAbs(f64, cos_(f64, 37.45), 0.969132, epsilon));
115 try expect(math.approxEqAbs(f64, cos_(f64, 89.123), 0.40080, epsilon));
116116}
117117
118118test "math.cos32.special" {
119 expect(math.isNan(cos_(f32, math.inf(f32))));
120 expect(math.isNan(cos_(f32, -math.inf(f32))));
121 expect(math.isNan(cos_(f32, math.nan(f32))));
119 try expect(math.isNan(cos_(f32, math.inf(f32))));
120 try expect(math.isNan(cos_(f32, -math.inf(f32))));
121 try expect(math.isNan(cos_(f32, math.nan(f32))));
122122}
123123
124124test "math.cos64.special" {
125 expect(math.isNan(cos_(f64, math.inf(f64))));
126 expect(math.isNan(cos_(f64, -math.inf(f64))));
127 expect(math.isNan(cos_(f64, math.nan(f64))));
125 try expect(math.isNan(cos_(f64, math.inf(f64))));
126 try expect(math.isNan(cos_(f64, -math.inf(f64))));
127 try expect(math.isNan(cos_(f64, math.nan(f64))));
128128}
lib/std/math/cosh.zig+28-28
......@@ -92,48 +92,48 @@ fn cosh64(x: f64) f64 {
9292}
9393
9494test "math.cosh" {
95 expect(cosh(@as(f32, 1.5)) == cosh32(1.5));
96 expect(cosh(@as(f64, 1.5)) == cosh64(1.5));
95 try expect(cosh(@as(f32, 1.5)) == cosh32(1.5));
96 try expect(cosh(@as(f64, 1.5)) == cosh64(1.5));
9797}
9898
9999test "math.cosh32" {
100100 const epsilon = 0.000001;
101101
102 expect(math.approxEqAbs(f32, cosh32(0.0), 1.0, epsilon));
103 expect(math.approxEqAbs(f32, cosh32(0.2), 1.020067, epsilon));
104 expect(math.approxEqAbs(f32, cosh32(0.8923), 1.425225, epsilon));
105 expect(math.approxEqAbs(f32, cosh32(1.5), 2.352410, epsilon));
106 expect(math.approxEqAbs(f32, cosh32(-0.0), 1.0, epsilon));
107 expect(math.approxEqAbs(f32, cosh32(-0.2), 1.020067, epsilon));
108 expect(math.approxEqAbs(f32, cosh32(-0.8923), 1.425225, epsilon));
109 expect(math.approxEqAbs(f32, cosh32(-1.5), 2.352410, epsilon));
102 try expect(math.approxEqAbs(f32, cosh32(0.0), 1.0, epsilon));
103 try expect(math.approxEqAbs(f32, cosh32(0.2), 1.020067, epsilon));
104 try expect(math.approxEqAbs(f32, cosh32(0.8923), 1.425225, epsilon));
105 try expect(math.approxEqAbs(f32, cosh32(1.5), 2.352410, epsilon));
106 try expect(math.approxEqAbs(f32, cosh32(-0.0), 1.0, epsilon));
107 try expect(math.approxEqAbs(f32, cosh32(-0.2), 1.020067, epsilon));
108 try expect(math.approxEqAbs(f32, cosh32(-0.8923), 1.425225, epsilon));
109 try expect(math.approxEqAbs(f32, cosh32(-1.5), 2.352410, epsilon));
110110}
111111
112112test "math.cosh64" {
113113 const epsilon = 0.000001;
114114
115 expect(math.approxEqAbs(f64, cosh64(0.0), 1.0, epsilon));
116 expect(math.approxEqAbs(f64, cosh64(0.2), 1.020067, epsilon));
117 expect(math.approxEqAbs(f64, cosh64(0.8923), 1.425225, epsilon));
118 expect(math.approxEqAbs(f64, cosh64(1.5), 2.352410, epsilon));
119 expect(math.approxEqAbs(f64, cosh64(-0.0), 1.0, epsilon));
120 expect(math.approxEqAbs(f64, cosh64(-0.2), 1.020067, epsilon));
121 expect(math.approxEqAbs(f64, cosh64(-0.8923), 1.425225, epsilon));
122 expect(math.approxEqAbs(f64, cosh64(-1.5), 2.352410, epsilon));
115 try expect(math.approxEqAbs(f64, cosh64(0.0), 1.0, epsilon));
116 try expect(math.approxEqAbs(f64, cosh64(0.2), 1.020067, epsilon));
117 try expect(math.approxEqAbs(f64, cosh64(0.8923), 1.425225, epsilon));
118 try expect(math.approxEqAbs(f64, cosh64(1.5), 2.352410, epsilon));
119 try expect(math.approxEqAbs(f64, cosh64(-0.0), 1.0, epsilon));
120 try expect(math.approxEqAbs(f64, cosh64(-0.2), 1.020067, epsilon));
121 try expect(math.approxEqAbs(f64, cosh64(-0.8923), 1.425225, epsilon));
122 try expect(math.approxEqAbs(f64, cosh64(-1.5), 2.352410, epsilon));
123123}
124124
125125test "math.cosh32.special" {
126 expect(cosh32(0.0) == 1.0);
127 expect(cosh32(-0.0) == 1.0);
128 expect(math.isPositiveInf(cosh32(math.inf(f32))));
129 expect(math.isPositiveInf(cosh32(-math.inf(f32))));
130 expect(math.isNan(cosh32(math.nan(f32))));
126 try expect(cosh32(0.0) == 1.0);
127 try expect(cosh32(-0.0) == 1.0);
128 try expect(math.isPositiveInf(cosh32(math.inf(f32))));
129 try expect(math.isPositiveInf(cosh32(-math.inf(f32))));
130 try expect(math.isNan(cosh32(math.nan(f32))));
131131}
132132
133133test "math.cosh64.special" {
134 expect(cosh64(0.0) == 1.0);
135 expect(cosh64(-0.0) == 1.0);
136 expect(math.isPositiveInf(cosh64(math.inf(f64))));
137 expect(math.isPositiveInf(cosh64(-math.inf(f64))));
138 expect(math.isNan(cosh64(math.nan(f64))));
134 try expect(cosh64(0.0) == 1.0);
135 try expect(cosh64(-0.0) == 1.0);
136 try expect(math.isPositiveInf(cosh64(math.inf(f64))));
137 try expect(math.isPositiveInf(cosh64(-math.inf(f64))));
138 try expect(math.isNan(cosh64(math.nan(f64))));
139139}
lib/std/math/exp.zig+16-16
......@@ -187,36 +187,36 @@ fn exp64(x_: f64) f64 {
187187}
188188
189189test "math.exp" {
190 expect(exp(@as(f32, 0.0)) == exp32(0.0));
191 expect(exp(@as(f64, 0.0)) == exp64(0.0));
190 try expect(exp(@as(f32, 0.0)) == exp32(0.0));
191 try expect(exp(@as(f64, 0.0)) == exp64(0.0));
192192}
193193
194194test "math.exp32" {
195195 const epsilon = 0.000001;
196196
197 expect(exp32(0.0) == 1.0);
198 expect(math.approxEqAbs(f32, exp32(0.0), 1.0, epsilon));
199 expect(math.approxEqAbs(f32, exp32(0.2), 1.221403, epsilon));
200 expect(math.approxEqAbs(f32, exp32(0.8923), 2.440737, epsilon));
201 expect(math.approxEqAbs(f32, exp32(1.5), 4.481689, epsilon));
197 try expect(exp32(0.0) == 1.0);
198 try expect(math.approxEqAbs(f32, exp32(0.0), 1.0, epsilon));
199 try expect(math.approxEqAbs(f32, exp32(0.2), 1.221403, epsilon));
200 try expect(math.approxEqAbs(f32, exp32(0.8923), 2.440737, epsilon));
201 try expect(math.approxEqAbs(f32, exp32(1.5), 4.481689, epsilon));
202202}
203203
204204test "math.exp64" {
205205 const epsilon = 0.000001;
206206
207 expect(exp64(0.0) == 1.0);
208 expect(math.approxEqAbs(f64, exp64(0.0), 1.0, epsilon));
209 expect(math.approxEqAbs(f64, exp64(0.2), 1.221403, epsilon));
210 expect(math.approxEqAbs(f64, exp64(0.8923), 2.440737, epsilon));
211 expect(math.approxEqAbs(f64, exp64(1.5), 4.481689, epsilon));
207 try expect(exp64(0.0) == 1.0);
208 try expect(math.approxEqAbs(f64, exp64(0.0), 1.0, epsilon));
209 try expect(math.approxEqAbs(f64, exp64(0.2), 1.221403, epsilon));
210 try expect(math.approxEqAbs(f64, exp64(0.8923), 2.440737, epsilon));
211 try expect(math.approxEqAbs(f64, exp64(1.5), 4.481689, epsilon));
212212}
213213
214214test "math.exp32.special" {
215 expect(math.isPositiveInf(exp32(math.inf(f32))));
216 expect(math.isNan(exp32(math.nan(f32))));
215 try expect(math.isPositiveInf(exp32(math.inf(f32))));
216 try expect(math.isNan(exp32(math.nan(f32))));
217217}
218218
219219test "math.exp64.special" {
220 expect(math.isPositiveInf(exp64(math.inf(f64))));
221 expect(math.isNan(exp64(math.nan(f64))));
220 try expect(math.isPositiveInf(exp64(math.inf(f64))));
221 try expect(math.isNan(exp64(math.nan(f64))));
222222}
lib/std/math/exp2.zig+15-15
......@@ -426,35 +426,35 @@ fn exp2_64(x: f64) f64 {
426426}
427427
428428test "math.exp2" {
429 expect(exp2(@as(f32, 0.8923)) == exp2_32(0.8923));
430 expect(exp2(@as(f64, 0.8923)) == exp2_64(0.8923));
429 try expect(exp2(@as(f32, 0.8923)) == exp2_32(0.8923));
430 try expect(exp2(@as(f64, 0.8923)) == exp2_64(0.8923));
431431}
432432
433433test "math.exp2_32" {
434434 const epsilon = 0.000001;
435435
436 expect(exp2_32(0.0) == 1.0);
437 expect(math.approxEqAbs(f32, exp2_32(0.2), 1.148698, epsilon));
438 expect(math.approxEqAbs(f32, exp2_32(0.8923), 1.856133, epsilon));
439 expect(math.approxEqAbs(f32, exp2_32(1.5), 2.828427, epsilon));
440 expect(math.approxEqAbs(f32, exp2_32(37.45), 187747237888, epsilon));
436 try expect(exp2_32(0.0) == 1.0);
437 try expect(math.approxEqAbs(f32, exp2_32(0.2), 1.148698, epsilon));
438 try expect(math.approxEqAbs(f32, exp2_32(0.8923), 1.856133, epsilon));
439 try expect(math.approxEqAbs(f32, exp2_32(1.5), 2.828427, epsilon));
440 try expect(math.approxEqAbs(f32, exp2_32(37.45), 187747237888, epsilon));
441441}
442442
443443test "math.exp2_64" {
444444 const epsilon = 0.000001;
445445
446 expect(exp2_64(0.0) == 1.0);
447 expect(math.approxEqAbs(f64, exp2_64(0.2), 1.148698, epsilon));
448 expect(math.approxEqAbs(f64, exp2_64(0.8923), 1.856133, epsilon));
449 expect(math.approxEqAbs(f64, exp2_64(1.5), 2.828427, epsilon));
446 try expect(exp2_64(0.0) == 1.0);
447 try expect(math.approxEqAbs(f64, exp2_64(0.2), 1.148698, epsilon));
448 try expect(math.approxEqAbs(f64, exp2_64(0.8923), 1.856133, epsilon));
449 try expect(math.approxEqAbs(f64, exp2_64(1.5), 2.828427, epsilon));
450450}
451451
452452test "math.exp2_32.special" {
453 expect(math.isPositiveInf(exp2_32(math.inf(f32))));
454 expect(math.isNan(exp2_32(math.nan(f32))));
453 try expect(math.isPositiveInf(exp2_32(math.inf(f32))));
454 try expect(math.isNan(exp2_32(math.nan(f32))));
455455}
456456
457457test "math.exp2_64.special" {
458 expect(math.isPositiveInf(exp2_64(math.inf(f64))));
459 expect(math.isNan(exp2_64(math.nan(f64))));
458 try expect(math.isPositiveInf(exp2_64(math.inf(f64))));
459 try expect(math.isNan(exp2_64(math.nan(f64))));
460460}
lib/std/math/expm1.zig+18-18
......@@ -291,42 +291,42 @@ fn expm1_64(x_: f64) f64 {
291291}
292292
293293test "math.exp1m" {
294 expect(expm1(@as(f32, 0.0)) == expm1_32(0.0));
295 expect(expm1(@as(f64, 0.0)) == expm1_64(0.0));
294 try expect(expm1(@as(f32, 0.0)) == expm1_32(0.0));
295 try expect(expm1(@as(f64, 0.0)) == expm1_64(0.0));
296296}
297297
298298test "math.expm1_32" {
299299 const epsilon = 0.000001;
300300
301 expect(expm1_32(0.0) == 0.0);
302 expect(math.approxEqAbs(f32, expm1_32(0.0), 0.0, epsilon));
303 expect(math.approxEqAbs(f32, expm1_32(0.2), 0.221403, epsilon));
304 expect(math.approxEqAbs(f32, expm1_32(0.8923), 1.440737, epsilon));
305 expect(math.approxEqAbs(f32, expm1_32(1.5), 3.481689, epsilon));
301 try expect(expm1_32(0.0) == 0.0);
302 try expect(math.approxEqAbs(f32, expm1_32(0.0), 0.0, epsilon));
303 try expect(math.approxEqAbs(f32, expm1_32(0.2), 0.221403, epsilon));
304 try expect(math.approxEqAbs(f32, expm1_32(0.8923), 1.440737, epsilon));
305 try expect(math.approxEqAbs(f32, expm1_32(1.5), 3.481689, epsilon));
306306}
307307
308308test "math.expm1_64" {
309309 const epsilon = 0.000001;
310310
311 expect(expm1_64(0.0) == 0.0);
312 expect(math.approxEqAbs(f64, expm1_64(0.0), 0.0, epsilon));
313 expect(math.approxEqAbs(f64, expm1_64(0.2), 0.221403, epsilon));
314 expect(math.approxEqAbs(f64, expm1_64(0.8923), 1.440737, epsilon));
315 expect(math.approxEqAbs(f64, expm1_64(1.5), 3.481689, epsilon));
311 try expect(expm1_64(0.0) == 0.0);
312 try expect(math.approxEqAbs(f64, expm1_64(0.0), 0.0, epsilon));
313 try expect(math.approxEqAbs(f64, expm1_64(0.2), 0.221403, epsilon));
314 try expect(math.approxEqAbs(f64, expm1_64(0.8923), 1.440737, epsilon));
315 try expect(math.approxEqAbs(f64, expm1_64(1.5), 3.481689, epsilon));
316316}
317317
318318test "math.expm1_32.special" {
319319 const epsilon = 0.000001;
320320
321 expect(math.isPositiveInf(expm1_32(math.inf(f32))));
322 expect(expm1_32(-math.inf(f32)) == -1.0);
323 expect(math.isNan(expm1_32(math.nan(f32))));
321 try expect(math.isPositiveInf(expm1_32(math.inf(f32))));
322 try expect(expm1_32(-math.inf(f32)) == -1.0);
323 try expect(math.isNan(expm1_32(math.nan(f32))));
324324}
325325
326326test "math.expm1_64.special" {
327327 const epsilon = 0.000001;
328328
329 expect(math.isPositiveInf(expm1_64(math.inf(f64))));
330 expect(expm1_64(-math.inf(f64)) == -1.0);
331 expect(math.isNan(expm1_64(math.nan(f64))));
329 try expect(math.isPositiveInf(expm1_64(math.inf(f64))));
330 try expect(expm1_64(-math.inf(f64)) == -1.0);
331 try expect(math.isNan(expm1_64(math.nan(f64))));
332332}
lib/std/math/fabs.zig+24-24
......@@ -55,52 +55,52 @@ fn fabs128(x: f128) f128 {
5555}
5656
5757test "math.fabs" {
58 expect(fabs(@as(f16, 1.0)) == fabs16(1.0));
59 expect(fabs(@as(f32, 1.0)) == fabs32(1.0));
60 expect(fabs(@as(f64, 1.0)) == fabs64(1.0));
61 expect(fabs(@as(f128, 1.0)) == fabs128(1.0));
58 try expect(fabs(@as(f16, 1.0)) == fabs16(1.0));
59 try expect(fabs(@as(f32, 1.0)) == fabs32(1.0));
60 try expect(fabs(@as(f64, 1.0)) == fabs64(1.0));
61 try expect(fabs(@as(f128, 1.0)) == fabs128(1.0));
6262}
6363
6464test "math.fabs16" {
65 expect(fabs16(1.0) == 1.0);
66 expect(fabs16(-1.0) == 1.0);
65 try expect(fabs16(1.0) == 1.0);
66 try expect(fabs16(-1.0) == 1.0);
6767}
6868
6969test "math.fabs32" {
70 expect(fabs32(1.0) == 1.0);
71 expect(fabs32(-1.0) == 1.0);
70 try expect(fabs32(1.0) == 1.0);
71 try expect(fabs32(-1.0) == 1.0);
7272}
7373
7474test "math.fabs64" {
75 expect(fabs64(1.0) == 1.0);
76 expect(fabs64(-1.0) == 1.0);
75 try expect(fabs64(1.0) == 1.0);
76 try expect(fabs64(-1.0) == 1.0);
7777}
7878
7979test "math.fabs128" {
80 expect(fabs128(1.0) == 1.0);
81 expect(fabs128(-1.0) == 1.0);
80 try expect(fabs128(1.0) == 1.0);
81 try expect(fabs128(-1.0) == 1.0);
8282}
8383
8484test "math.fabs16.special" {
85 expect(math.isPositiveInf(fabs(math.inf(f16))));
86 expect(math.isPositiveInf(fabs(-math.inf(f16))));
87 expect(math.isNan(fabs(math.nan(f16))));
85 try expect(math.isPositiveInf(fabs(math.inf(f16))));
86 try expect(math.isPositiveInf(fabs(-math.inf(f16))));
87 try expect(math.isNan(fabs(math.nan(f16))));
8888}
8989
9090test "math.fabs32.special" {
91 expect(math.isPositiveInf(fabs(math.inf(f32))));
92 expect(math.isPositiveInf(fabs(-math.inf(f32))));
93 expect(math.isNan(fabs(math.nan(f32))));
91 try expect(math.isPositiveInf(fabs(math.inf(f32))));
92 try expect(math.isPositiveInf(fabs(-math.inf(f32))));
93 try expect(math.isNan(fabs(math.nan(f32))));
9494}
9595
9696test "math.fabs64.special" {
97 expect(math.isPositiveInf(fabs(math.inf(f64))));
98 expect(math.isPositiveInf(fabs(-math.inf(f64))));
99 expect(math.isNan(fabs(math.nan(f64))));
97 try expect(math.isPositiveInf(fabs(math.inf(f64))));
98 try expect(math.isPositiveInf(fabs(-math.inf(f64))));
99 try expect(math.isNan(fabs(math.nan(f64))));
100100}
101101
102102test "math.fabs128.special" {
103 expect(math.isPositiveInf(fabs(math.inf(f128))));
104 expect(math.isPositiveInf(fabs(-math.inf(f128))));
105 expect(math.isNan(fabs(math.nan(f128))));
103 try expect(math.isPositiveInf(fabs(math.inf(f128))));
104 try expect(math.isPositiveInf(fabs(-math.inf(f128))));
105 try expect(math.isNan(fabs(math.nan(f128))));
106106}
lib/std/math/floor.zig+36-36
......@@ -155,64 +155,64 @@ fn floor128(x: f128) f128 {
155155}
156156
157157test "math.floor" {
158 expect(floor(@as(f16, 1.3)) == floor16(1.3));
159 expect(floor(@as(f32, 1.3)) == floor32(1.3));
160 expect(floor(@as(f64, 1.3)) == floor64(1.3));
161 expect(floor(@as(f128, 1.3)) == floor128(1.3));
158 try expect(floor(@as(f16, 1.3)) == floor16(1.3));
159 try expect(floor(@as(f32, 1.3)) == floor32(1.3));
160 try expect(floor(@as(f64, 1.3)) == floor64(1.3));
161 try expect(floor(@as(f128, 1.3)) == floor128(1.3));
162162}
163163
164164test "math.floor16" {
165 expect(floor16(1.3) == 1.0);
166 expect(floor16(-1.3) == -2.0);
167 expect(floor16(0.2) == 0.0);
165 try expect(floor16(1.3) == 1.0);
166 try expect(floor16(-1.3) == -2.0);
167 try expect(floor16(0.2) == 0.0);
168168}
169169
170170test "math.floor32" {
171 expect(floor32(1.3) == 1.0);
172 expect(floor32(-1.3) == -2.0);
173 expect(floor32(0.2) == 0.0);
171 try expect(floor32(1.3) == 1.0);
172 try expect(floor32(-1.3) == -2.0);
173 try expect(floor32(0.2) == 0.0);
174174}
175175
176176test "math.floor64" {
177 expect(floor64(1.3) == 1.0);
178 expect(floor64(-1.3) == -2.0);
179 expect(floor64(0.2) == 0.0);
177 try expect(floor64(1.3) == 1.0);
178 try expect(floor64(-1.3) == -2.0);
179 try expect(floor64(0.2) == 0.0);
180180}
181181
182182test "math.floor128" {
183 expect(floor128(1.3) == 1.0);
184 expect(floor128(-1.3) == -2.0);
185 expect(floor128(0.2) == 0.0);
183 try expect(floor128(1.3) == 1.0);
184 try expect(floor128(-1.3) == -2.0);
185 try expect(floor128(0.2) == 0.0);
186186}
187187
188188test "math.floor16.special" {
189 expect(floor16(0.0) == 0.0);
190 expect(floor16(-0.0) == -0.0);
191 expect(math.isPositiveInf(floor16(math.inf(f16))));
192 expect(math.isNegativeInf(floor16(-math.inf(f16))));
193 expect(math.isNan(floor16(math.nan(f16))));
189 try expect(floor16(0.0) == 0.0);
190 try expect(floor16(-0.0) == -0.0);
191 try expect(math.isPositiveInf(floor16(math.inf(f16))));
192 try expect(math.isNegativeInf(floor16(-math.inf(f16))));
193 try expect(math.isNan(floor16(math.nan(f16))));
194194}
195195
196196test "math.floor32.special" {
197 expect(floor32(0.0) == 0.0);
198 expect(floor32(-0.0) == -0.0);
199 expect(math.isPositiveInf(floor32(math.inf(f32))));
200 expect(math.isNegativeInf(floor32(-math.inf(f32))));
201 expect(math.isNan(floor32(math.nan(f32))));
197 try expect(floor32(0.0) == 0.0);
198 try expect(floor32(-0.0) == -0.0);
199 try expect(math.isPositiveInf(floor32(math.inf(f32))));
200 try expect(math.isNegativeInf(floor32(-math.inf(f32))));
201 try expect(math.isNan(floor32(math.nan(f32))));
202202}
203203
204204test "math.floor64.special" {
205 expect(floor64(0.0) == 0.0);
206 expect(floor64(-0.0) == -0.0);
207 expect(math.isPositiveInf(floor64(math.inf(f64))));
208 expect(math.isNegativeInf(floor64(-math.inf(f64))));
209 expect(math.isNan(floor64(math.nan(f64))));
205 try expect(floor64(0.0) == 0.0);
206 try expect(floor64(-0.0) == -0.0);
207 try expect(math.isPositiveInf(floor64(math.inf(f64))));
208 try expect(math.isNegativeInf(floor64(-math.inf(f64))));
209 try expect(math.isNan(floor64(math.nan(f64))));
210210}
211211
212212test "math.floor128.special" {
213 expect(floor128(0.0) == 0.0);
214 expect(floor128(-0.0) == -0.0);
215 expect(math.isPositiveInf(floor128(math.inf(f128))));
216 expect(math.isNegativeInf(floor128(-math.inf(f128))));
217 expect(math.isNan(floor128(math.nan(f128))));
213 try expect(floor128(0.0) == 0.0);
214 try expect(floor128(-0.0) == -0.0);
215 try expect(math.isPositiveInf(floor128(math.inf(f128))));
216 try expect(math.isNegativeInf(floor128(-math.inf(f128))));
217 try expect(math.isNan(floor128(math.nan(f128))));
218218}
lib/std/math/fma.zig+16-16
......@@ -148,30 +148,30 @@ fn add_and_denorm(a: f64, b: f64, scale: i32) f64 {
148148}
149149
150150test "math.fma" {
151 expect(fma(f32, 0.0, 1.0, 1.0) == fma32(0.0, 1.0, 1.0));
152 expect(fma(f64, 0.0, 1.0, 1.0) == fma64(0.0, 1.0, 1.0));
151 try expect(fma(f32, 0.0, 1.0, 1.0) == fma32(0.0, 1.0, 1.0));
152 try expect(fma(f64, 0.0, 1.0, 1.0) == fma64(0.0, 1.0, 1.0));
153153}
154154
155155test "math.fma32" {
156156 const epsilon = 0.000001;
157157
158 expect(math.approxEqAbs(f32, fma32(0.0, 5.0, 9.124), 9.124, epsilon));
159 expect(math.approxEqAbs(f32, fma32(0.2, 5.0, 9.124), 10.124, epsilon));
160 expect(math.approxEqAbs(f32, fma32(0.8923, 5.0, 9.124), 13.5855, epsilon));
161 expect(math.approxEqAbs(f32, fma32(1.5, 5.0, 9.124), 16.624, epsilon));
162 expect(math.approxEqAbs(f32, fma32(37.45, 5.0, 9.124), 196.374004, epsilon));
163 expect(math.approxEqAbs(f32, fma32(89.123, 5.0, 9.124), 454.739005, epsilon));
164 expect(math.approxEqAbs(f32, fma32(123123.234375, 5.0, 9.124), 615625.295875, epsilon));
158 try expect(math.approxEqAbs(f32, fma32(0.0, 5.0, 9.124), 9.124, epsilon));
159 try expect(math.approxEqAbs(f32, fma32(0.2, 5.0, 9.124), 10.124, epsilon));
160 try expect(math.approxEqAbs(f32, fma32(0.8923, 5.0, 9.124), 13.5855, epsilon));
161 try expect(math.approxEqAbs(f32, fma32(1.5, 5.0, 9.124), 16.624, epsilon));
162 try expect(math.approxEqAbs(f32, fma32(37.45, 5.0, 9.124), 196.374004, epsilon));
163 try expect(math.approxEqAbs(f32, fma32(89.123, 5.0, 9.124), 454.739005, epsilon));
164 try expect(math.approxEqAbs(f32, fma32(123123.234375, 5.0, 9.124), 615625.295875, epsilon));
165165}
166166
167167test "math.fma64" {
168168 const epsilon = 0.000001;
169169
170 expect(math.approxEqAbs(f64, fma64(0.0, 5.0, 9.124), 9.124, epsilon));
171 expect(math.approxEqAbs(f64, fma64(0.2, 5.0, 9.124), 10.124, epsilon));
172 expect(math.approxEqAbs(f64, fma64(0.8923, 5.0, 9.124), 13.5855, epsilon));
173 expect(math.approxEqAbs(f64, fma64(1.5, 5.0, 9.124), 16.624, epsilon));
174 expect(math.approxEqAbs(f64, fma64(37.45, 5.0, 9.124), 196.374, epsilon));
175 expect(math.approxEqAbs(f64, fma64(89.123, 5.0, 9.124), 454.739, epsilon));
176 expect(math.approxEqAbs(f64, fma64(123123.234375, 5.0, 9.124), 615625.295875, epsilon));
170 try expect(math.approxEqAbs(f64, fma64(0.0, 5.0, 9.124), 9.124, epsilon));
171 try expect(math.approxEqAbs(f64, fma64(0.2, 5.0, 9.124), 10.124, epsilon));
172 try expect(math.approxEqAbs(f64, fma64(0.8923, 5.0, 9.124), 13.5855, epsilon));
173 try expect(math.approxEqAbs(f64, fma64(1.5, 5.0, 9.124), 16.624, epsilon));
174 try expect(math.approxEqAbs(f64, fma64(37.45, 5.0, 9.124), 196.374, epsilon));
175 try expect(math.approxEqAbs(f64, fma64(89.123, 5.0, 9.124), 454.739, epsilon));
176 try expect(math.approxEqAbs(f64, fma64(123123.234375, 5.0, 9.124), 615625.295875, epsilon));
177177}
lib/std/math/frexp.zig+16-16
......@@ -115,11 +115,11 @@ fn frexp64(x: f64) frexp64_result {
115115test "math.frexp" {
116116 const a = frexp(@as(f32, 1.3));
117117 const b = frexp32(1.3);
118 expect(a.significand == b.significand and a.exponent == b.exponent);
118 try expect(a.significand == b.significand and a.exponent == b.exponent);
119119
120120 const c = frexp(@as(f64, 1.3));
121121 const d = frexp64(1.3);
122 expect(c.significand == d.significand and c.exponent == d.exponent);
122 try expect(c.significand == d.significand and c.exponent == d.exponent);
123123}
124124
125125test "math.frexp32" {
......@@ -127,10 +127,10 @@ test "math.frexp32" {
127127 var r: frexp32_result = undefined;
128128
129129 r = frexp32(1.3);
130 expect(math.approxEqAbs(f32, r.significand, 0.65, epsilon) and r.exponent == 1);
130 try expect(math.approxEqAbs(f32, r.significand, 0.65, epsilon) and r.exponent == 1);
131131
132132 r = frexp32(78.0234);
133 expect(math.approxEqAbs(f32, r.significand, 0.609558, epsilon) and r.exponent == 7);
133 try expect(math.approxEqAbs(f32, r.significand, 0.609558, epsilon) and r.exponent == 7);
134134}
135135
136136test "math.frexp64" {
......@@ -138,46 +138,46 @@ test "math.frexp64" {
138138 var r: frexp64_result = undefined;
139139
140140 r = frexp64(1.3);
141 expect(math.approxEqAbs(f64, r.significand, 0.65, epsilon) and r.exponent == 1);
141 try expect(math.approxEqAbs(f64, r.significand, 0.65, epsilon) and r.exponent == 1);
142142
143143 r = frexp64(78.0234);
144 expect(math.approxEqAbs(f64, r.significand, 0.609558, epsilon) and r.exponent == 7);
144 try expect(math.approxEqAbs(f64, r.significand, 0.609558, epsilon) and r.exponent == 7);
145145}
146146
147147test "math.frexp32.special" {
148148 var r: frexp32_result = undefined;
149149
150150 r = frexp32(0.0);
151 expect(r.significand == 0.0 and r.exponent == 0);
151 try expect(r.significand == 0.0 and r.exponent == 0);
152152
153153 r = frexp32(-0.0);
154 expect(r.significand == -0.0 and r.exponent == 0);
154 try expect(r.significand == -0.0 and r.exponent == 0);
155155
156156 r = frexp32(math.inf(f32));
157 expect(math.isPositiveInf(r.significand) and r.exponent == 0);
157 try expect(math.isPositiveInf(r.significand) and r.exponent == 0);
158158
159159 r = frexp32(-math.inf(f32));
160 expect(math.isNegativeInf(r.significand) and r.exponent == 0);
160 try expect(math.isNegativeInf(r.significand) and r.exponent == 0);
161161
162162 r = frexp32(math.nan(f32));
163 expect(math.isNan(r.significand));
163 try expect(math.isNan(r.significand));
164164}
165165
166166test "math.frexp64.special" {
167167 var r: frexp64_result = undefined;
168168
169169 r = frexp64(0.0);
170 expect(r.significand == 0.0 and r.exponent == 0);
170 try expect(r.significand == 0.0 and r.exponent == 0);
171171
172172 r = frexp64(-0.0);
173 expect(r.significand == -0.0 and r.exponent == 0);
173 try expect(r.significand == -0.0 and r.exponent == 0);
174174
175175 r = frexp64(math.inf(f64));
176 expect(math.isPositiveInf(r.significand) and r.exponent == 0);
176 try expect(math.isPositiveInf(r.significand) and r.exponent == 0);
177177
178178 r = frexp64(-math.inf(f64));
179 expect(math.isNegativeInf(r.significand) and r.exponent == 0);
179 try expect(math.isNegativeInf(r.significand) and r.exponent == 0);
180180
181181 r = frexp64(math.nan(f64));
182 expect(math.isNan(r.significand));
182 try expect(math.isNan(r.significand));
183183}
lib/std/math/hypot.zig+28-28
......@@ -126,48 +126,48 @@ fn hypot64(x: f64, y: f64) f64 {
126126}
127127
128128test "math.hypot" {
129 expect(hypot(f32, 0.0, -1.2) == hypot32(0.0, -1.2));
130 expect(hypot(f64, 0.0, -1.2) == hypot64(0.0, -1.2));
129 try expect(hypot(f32, 0.0, -1.2) == hypot32(0.0, -1.2));
130 try expect(hypot(f64, 0.0, -1.2) == hypot64(0.0, -1.2));
131131}
132132
133133test "math.hypot32" {
134134 const epsilon = 0.000001;
135135
136 expect(math.approxEqAbs(f32, hypot32(0.0, -1.2), 1.2, epsilon));
137 expect(math.approxEqAbs(f32, hypot32(0.2, -0.34), 0.394462, epsilon));
138 expect(math.approxEqAbs(f32, hypot32(0.8923, 2.636890), 2.783772, epsilon));
139 expect(math.approxEqAbs(f32, hypot32(1.5, 5.25), 5.460083, epsilon));
140 expect(math.approxEqAbs(f32, hypot32(37.45, 159.835), 164.163742, epsilon));
141 expect(math.approxEqAbs(f32, hypot32(89.123, 382.028905), 392.286865, epsilon));
142 expect(math.approxEqAbs(f32, hypot32(123123.234375, 529428.707813), 543556.875, epsilon));
136 try expect(math.approxEqAbs(f32, hypot32(0.0, -1.2), 1.2, epsilon));
137 try expect(math.approxEqAbs(f32, hypot32(0.2, -0.34), 0.394462, epsilon));
138 try expect(math.approxEqAbs(f32, hypot32(0.8923, 2.636890), 2.783772, epsilon));
139 try expect(math.approxEqAbs(f32, hypot32(1.5, 5.25), 5.460083, epsilon));
140 try expect(math.approxEqAbs(f32, hypot32(37.45, 159.835), 164.163742, epsilon));
141 try expect(math.approxEqAbs(f32, hypot32(89.123, 382.028905), 392.286865, epsilon));
142 try expect(math.approxEqAbs(f32, hypot32(123123.234375, 529428.707813), 543556.875, epsilon));
143143}
144144
145145test "math.hypot64" {
146146 const epsilon = 0.000001;
147147
148 expect(math.approxEqAbs(f64, hypot64(0.0, -1.2), 1.2, epsilon));
149 expect(math.approxEqAbs(f64, hypot64(0.2, -0.34), 0.394462, epsilon));
150 expect(math.approxEqAbs(f64, hypot64(0.8923, 2.636890), 2.783772, epsilon));
151 expect(math.approxEqAbs(f64, hypot64(1.5, 5.25), 5.460082, epsilon));
152 expect(math.approxEqAbs(f64, hypot64(37.45, 159.835), 164.163728, epsilon));
153 expect(math.approxEqAbs(f64, hypot64(89.123, 382.028905), 392.286876, epsilon));
154 expect(math.approxEqAbs(f64, hypot64(123123.234375, 529428.707813), 543556.885247, epsilon));
148 try expect(math.approxEqAbs(f64, hypot64(0.0, -1.2), 1.2, epsilon));
149 try expect(math.approxEqAbs(f64, hypot64(0.2, -0.34), 0.394462, epsilon));
150 try expect(math.approxEqAbs(f64, hypot64(0.8923, 2.636890), 2.783772, epsilon));
151 try expect(math.approxEqAbs(f64, hypot64(1.5, 5.25), 5.460082, epsilon));
152 try expect(math.approxEqAbs(f64, hypot64(37.45, 159.835), 164.163728, epsilon));
153 try expect(math.approxEqAbs(f64, hypot64(89.123, 382.028905), 392.286876, epsilon));
154 try expect(math.approxEqAbs(f64, hypot64(123123.234375, 529428.707813), 543556.885247, epsilon));
155155}
156156
157157test "math.hypot32.special" {
158 expect(math.isPositiveInf(hypot32(math.inf(f32), 0.0)));
159 expect(math.isPositiveInf(hypot32(-math.inf(f32), 0.0)));
160 expect(math.isPositiveInf(hypot32(0.0, math.inf(f32))));
161 expect(math.isPositiveInf(hypot32(0.0, -math.inf(f32))));
162 expect(math.isNan(hypot32(math.nan(f32), 0.0)));
163 expect(math.isNan(hypot32(0.0, math.nan(f32))));
158 try expect(math.isPositiveInf(hypot32(math.inf(f32), 0.0)));
159 try expect(math.isPositiveInf(hypot32(-math.inf(f32), 0.0)));
160 try expect(math.isPositiveInf(hypot32(0.0, math.inf(f32))));
161 try expect(math.isPositiveInf(hypot32(0.0, -math.inf(f32))));
162 try expect(math.isNan(hypot32(math.nan(f32), 0.0)));
163 try expect(math.isNan(hypot32(0.0, math.nan(f32))));
164164}
165165
166166test "math.hypot64.special" {
167 expect(math.isPositiveInf(hypot64(math.inf(f64), 0.0)));
168 expect(math.isPositiveInf(hypot64(-math.inf(f64), 0.0)));
169 expect(math.isPositiveInf(hypot64(0.0, math.inf(f64))));
170 expect(math.isPositiveInf(hypot64(0.0, -math.inf(f64))));
171 expect(math.isNan(hypot64(math.nan(f64), 0.0)));
172 expect(math.isNan(hypot64(0.0, math.nan(f64))));
167 try expect(math.isPositiveInf(hypot64(math.inf(f64), 0.0)));
168 try expect(math.isPositiveInf(hypot64(-math.inf(f64), 0.0)));
169 try expect(math.isPositiveInf(hypot64(0.0, math.inf(f64))));
170 try expect(math.isPositiveInf(hypot64(0.0, -math.inf(f64))));
171 try expect(math.isNan(hypot64(math.nan(f64), 0.0)));
172 try expect(math.isNan(hypot64(0.0, math.nan(f64))));
173173}
lib/std/math/ilogb.zig+22-22
......@@ -106,38 +106,38 @@ fn ilogb64(x: f64) i32 {
106106}
107107
108108test "math.ilogb" {
109 expect(ilogb(@as(f32, 0.2)) == ilogb32(0.2));
110 expect(ilogb(@as(f64, 0.2)) == ilogb64(0.2));
109 try expect(ilogb(@as(f32, 0.2)) == ilogb32(0.2));
110 try expect(ilogb(@as(f64, 0.2)) == ilogb64(0.2));
111111}
112112
113113test "math.ilogb32" {
114 expect(ilogb32(0.0) == fp_ilogb0);
115 expect(ilogb32(0.5) == -1);
116 expect(ilogb32(0.8923) == -1);
117 expect(ilogb32(10.0) == 3);
118 expect(ilogb32(-123984) == 16);
119 expect(ilogb32(2398.23) == 11);
114 try expect(ilogb32(0.0) == fp_ilogb0);
115 try expect(ilogb32(0.5) == -1);
116 try expect(ilogb32(0.8923) == -1);
117 try expect(ilogb32(10.0) == 3);
118 try expect(ilogb32(-123984) == 16);
119 try expect(ilogb32(2398.23) == 11);
120120}
121121
122122test "math.ilogb64" {
123 expect(ilogb64(0.0) == fp_ilogb0);
124 expect(ilogb64(0.5) == -1);
125 expect(ilogb64(0.8923) == -1);
126 expect(ilogb64(10.0) == 3);
127 expect(ilogb64(-123984) == 16);
128 expect(ilogb64(2398.23) == 11);
123 try expect(ilogb64(0.0) == fp_ilogb0);
124 try expect(ilogb64(0.5) == -1);
125 try expect(ilogb64(0.8923) == -1);
126 try expect(ilogb64(10.0) == 3);
127 try expect(ilogb64(-123984) == 16);
128 try expect(ilogb64(2398.23) == 11);
129129}
130130
131131test "math.ilogb32.special" {
132 expect(ilogb32(math.inf(f32)) == maxInt(i32));
133 expect(ilogb32(-math.inf(f32)) == maxInt(i32));
134 expect(ilogb32(0.0) == minInt(i32));
135 expect(ilogb32(math.nan(f32)) == maxInt(i32));
132 try expect(ilogb32(math.inf(f32)) == maxInt(i32));
133 try expect(ilogb32(-math.inf(f32)) == maxInt(i32));
134 try expect(ilogb32(0.0) == minInt(i32));
135 try expect(ilogb32(math.nan(f32)) == maxInt(i32));
136136}
137137
138138test "math.ilogb64.special" {
139 expect(ilogb64(math.inf(f64)) == maxInt(i32));
140 expect(ilogb64(-math.inf(f64)) == maxInt(i32));
141 expect(ilogb64(0.0) == minInt(i32));
142 expect(ilogb64(math.nan(f64)) == maxInt(i32));
139 try expect(ilogb64(math.inf(f64)) == maxInt(i32));
140 try expect(ilogb64(-math.inf(f64)) == maxInt(i32));
141 try expect(ilogb64(0.0) == minInt(i32));
142 try expect(ilogb64(math.nan(f64)) == maxInt(i32));
143143}
lib/std/math/isfinite.zig+24-24
......@@ -35,30 +35,30 @@ pub fn isFinite(x: anytype) bool {
3535}
3636
3737test "math.isFinite" {
38 expect(isFinite(@as(f16, 0.0)));
39 expect(isFinite(@as(f16, -0.0)));
40 expect(isFinite(@as(f32, 0.0)));
41 expect(isFinite(@as(f32, -0.0)));
42 expect(isFinite(@as(f64, 0.0)));
43 expect(isFinite(@as(f64, -0.0)));
44 expect(isFinite(@as(f128, 0.0)));
45 expect(isFinite(@as(f128, -0.0)));
38 try expect(isFinite(@as(f16, 0.0)));
39 try expect(isFinite(@as(f16, -0.0)));
40 try expect(isFinite(@as(f32, 0.0)));
41 try expect(isFinite(@as(f32, -0.0)));
42 try expect(isFinite(@as(f64, 0.0)));
43 try expect(isFinite(@as(f64, -0.0)));
44 try expect(isFinite(@as(f128, 0.0)));
45 try expect(isFinite(@as(f128, -0.0)));
4646
47 expect(!isFinite(math.inf(f16)));
48 expect(!isFinite(-math.inf(f16)));
49 expect(!isFinite(math.inf(f32)));
50 expect(!isFinite(-math.inf(f32)));
51 expect(!isFinite(math.inf(f64)));
52 expect(!isFinite(-math.inf(f64)));
53 expect(!isFinite(math.inf(f128)));
54 expect(!isFinite(-math.inf(f128)));
47 try expect(!isFinite(math.inf(f16)));
48 try expect(!isFinite(-math.inf(f16)));
49 try expect(!isFinite(math.inf(f32)));
50 try expect(!isFinite(-math.inf(f32)));
51 try expect(!isFinite(math.inf(f64)));
52 try expect(!isFinite(-math.inf(f64)));
53 try expect(!isFinite(math.inf(f128)));
54 try expect(!isFinite(-math.inf(f128)));
5555
56 expect(!isFinite(math.nan(f16)));
57 expect(!isFinite(-math.nan(f16)));
58 expect(!isFinite(math.nan(f32)));
59 expect(!isFinite(-math.nan(f32)));
60 expect(!isFinite(math.nan(f64)));
61 expect(!isFinite(-math.nan(f64)));
62 expect(!isFinite(math.nan(f128)));
63 expect(!isFinite(-math.nan(f128)));
56 try expect(!isFinite(math.nan(f16)));
57 try expect(!isFinite(-math.nan(f16)));
58 try expect(!isFinite(math.nan(f32)));
59 try expect(!isFinite(-math.nan(f32)));
60 try expect(!isFinite(math.nan(f64)));
61 try expect(!isFinite(-math.nan(f64)));
62 try expect(!isFinite(math.nan(f128)));
63 try expect(!isFinite(-math.nan(f128)));
6464}
lib/std/math/isinf.zig+48-48
......@@ -79,58 +79,58 @@ pub fn isNegativeInf(x: anytype) bool {
7979}
8080
8181test "math.isInf" {
82 expect(!isInf(@as(f16, 0.0)));
83 expect(!isInf(@as(f16, -0.0)));
84 expect(!isInf(@as(f32, 0.0)));
85 expect(!isInf(@as(f32, -0.0)));
86 expect(!isInf(@as(f64, 0.0)));
87 expect(!isInf(@as(f64, -0.0)));
88 expect(!isInf(@as(f128, 0.0)));
89 expect(!isInf(@as(f128, -0.0)));
90 expect(isInf(math.inf(f16)));
91 expect(isInf(-math.inf(f16)));
92 expect(isInf(math.inf(f32)));
93 expect(isInf(-math.inf(f32)));
94 expect(isInf(math.inf(f64)));
95 expect(isInf(-math.inf(f64)));
96 expect(isInf(math.inf(f128)));
97 expect(isInf(-math.inf(f128)));
82 try expect(!isInf(@as(f16, 0.0)));
83 try expect(!isInf(@as(f16, -0.0)));
84 try expect(!isInf(@as(f32, 0.0)));
85 try expect(!isInf(@as(f32, -0.0)));
86 try expect(!isInf(@as(f64, 0.0)));
87 try expect(!isInf(@as(f64, -0.0)));
88 try expect(!isInf(@as(f128, 0.0)));
89 try expect(!isInf(@as(f128, -0.0)));
90 try expect(isInf(math.inf(f16)));
91 try expect(isInf(-math.inf(f16)));
92 try expect(isInf(math.inf(f32)));
93 try expect(isInf(-math.inf(f32)));
94 try expect(isInf(math.inf(f64)));
95 try expect(isInf(-math.inf(f64)));
96 try expect(isInf(math.inf(f128)));
97 try expect(isInf(-math.inf(f128)));
9898}
9999
100100test "math.isPositiveInf" {
101 expect(!isPositiveInf(@as(f16, 0.0)));
102 expect(!isPositiveInf(@as(f16, -0.0)));
103 expect(!isPositiveInf(@as(f32, 0.0)));
104 expect(!isPositiveInf(@as(f32, -0.0)));
105 expect(!isPositiveInf(@as(f64, 0.0)));
106 expect(!isPositiveInf(@as(f64, -0.0)));
107 expect(!isPositiveInf(@as(f128, 0.0)));
108 expect(!isPositiveInf(@as(f128, -0.0)));
109 expect(isPositiveInf(math.inf(f16)));
110 expect(!isPositiveInf(-math.inf(f16)));
111 expect(isPositiveInf(math.inf(f32)));
112 expect(!isPositiveInf(-math.inf(f32)));
113 expect(isPositiveInf(math.inf(f64)));
114 expect(!isPositiveInf(-math.inf(f64)));
115 expect(isPositiveInf(math.inf(f128)));
116 expect(!isPositiveInf(-math.inf(f128)));
101 try expect(!isPositiveInf(@as(f16, 0.0)));
102 try expect(!isPositiveInf(@as(f16, -0.0)));
103 try expect(!isPositiveInf(@as(f32, 0.0)));
104 try expect(!isPositiveInf(@as(f32, -0.0)));
105 try expect(!isPositiveInf(@as(f64, 0.0)));
106 try expect(!isPositiveInf(@as(f64, -0.0)));
107 try expect(!isPositiveInf(@as(f128, 0.0)));
108 try expect(!isPositiveInf(@as(f128, -0.0)));
109 try expect(isPositiveInf(math.inf(f16)));
110 try expect(!isPositiveInf(-math.inf(f16)));
111 try expect(isPositiveInf(math.inf(f32)));
112 try expect(!isPositiveInf(-math.inf(f32)));
113 try expect(isPositiveInf(math.inf(f64)));
114 try expect(!isPositiveInf(-math.inf(f64)));
115 try expect(isPositiveInf(math.inf(f128)));
116 try expect(!isPositiveInf(-math.inf(f128)));
117117}
118118
119119test "math.isNegativeInf" {
120 expect(!isNegativeInf(@as(f16, 0.0)));
121 expect(!isNegativeInf(@as(f16, -0.0)));
122 expect(!isNegativeInf(@as(f32, 0.0)));
123 expect(!isNegativeInf(@as(f32, -0.0)));
124 expect(!isNegativeInf(@as(f64, 0.0)));
125 expect(!isNegativeInf(@as(f64, -0.0)));
126 expect(!isNegativeInf(@as(f128, 0.0)));
127 expect(!isNegativeInf(@as(f128, -0.0)));
128 expect(!isNegativeInf(math.inf(f16)));
129 expect(isNegativeInf(-math.inf(f16)));
130 expect(!isNegativeInf(math.inf(f32)));
131 expect(isNegativeInf(-math.inf(f32)));
132 expect(!isNegativeInf(math.inf(f64)));
133 expect(isNegativeInf(-math.inf(f64)));
134 expect(!isNegativeInf(math.inf(f128)));
135 expect(isNegativeInf(-math.inf(f128)));
120 try expect(!isNegativeInf(@as(f16, 0.0)));
121 try expect(!isNegativeInf(@as(f16, -0.0)));
122 try expect(!isNegativeInf(@as(f32, 0.0)));
123 try expect(!isNegativeInf(@as(f32, -0.0)));
124 try expect(!isNegativeInf(@as(f64, 0.0)));
125 try expect(!isNegativeInf(@as(f64, -0.0)));
126 try expect(!isNegativeInf(@as(f128, 0.0)));
127 try expect(!isNegativeInf(@as(f128, -0.0)));
128 try expect(!isNegativeInf(math.inf(f16)));
129 try expect(isNegativeInf(-math.inf(f16)));
130 try expect(!isNegativeInf(math.inf(f32)));
131 try expect(isNegativeInf(-math.inf(f32)));
132 try expect(!isNegativeInf(math.inf(f64)));
133 try expect(isNegativeInf(-math.inf(f64)));
134 try expect(!isNegativeInf(math.inf(f128)));
135 try expect(isNegativeInf(-math.inf(f128)));
136136}
lib/std/math/isnan.zig+8-8
......@@ -21,12 +21,12 @@ pub fn isSignalNan(x: anytype) bool {
2121}
2222
2323test "math.isNan" {
24 expect(isNan(math.nan(f16)));
25 expect(isNan(math.nan(f32)));
26 expect(isNan(math.nan(f64)));
27 expect(isNan(math.nan(f128)));
28 expect(!isNan(@as(f16, 1.0)));
29 expect(!isNan(@as(f32, 1.0)));
30 expect(!isNan(@as(f64, 1.0)));
31 expect(!isNan(@as(f128, 1.0)));
24 try expect(isNan(math.nan(f16)));
25 try expect(isNan(math.nan(f32)));
26 try expect(isNan(math.nan(f64)));
27 try expect(isNan(math.nan(f128)));
28 try expect(!isNan(@as(f16, 1.0)));
29 try expect(!isNan(@as(f32, 1.0)));
30 try expect(!isNan(@as(f64, 1.0)));
31 try expect(!isNan(@as(f128, 1.0)));
3232}
lib/std/math/isnormal.zig+9-9
......@@ -31,13 +31,13 @@ pub fn isNormal(x: anytype) bool {
3131}
3232
3333test "math.isNormal" {
34 expect(!isNormal(math.nan(f16)));
35 expect(!isNormal(math.nan(f32)));
36 expect(!isNormal(math.nan(f64)));
37 expect(!isNormal(@as(f16, 0)));
38 expect(!isNormal(@as(f32, 0)));
39 expect(!isNormal(@as(f64, 0)));
40 expect(isNormal(@as(f16, 1.0)));
41 expect(isNormal(@as(f32, 1.0)));
42 expect(isNormal(@as(f64, 1.0)));
34 try expect(!isNormal(math.nan(f16)));
35 try expect(!isNormal(math.nan(f32)));
36 try expect(!isNormal(math.nan(f64)));
37 try expect(!isNormal(@as(f16, 0)));
38 try expect(!isNormal(@as(f32, 0)));
39 try expect(!isNormal(@as(f64, 0)));
40 try expect(isNormal(@as(f16, 1.0)));
41 try expect(isNormal(@as(f32, 1.0)));
42 try expect(isNormal(@as(f64, 1.0)));
4343}
lib/std/math/ln.zig+22-22
......@@ -153,42 +153,42 @@ pub fn ln_64(x_: f64) f64 {
153153}
154154
155155test "math.ln" {
156 expect(ln(@as(f32, 0.2)) == ln_32(0.2));
157 expect(ln(@as(f64, 0.2)) == ln_64(0.2));
156 try expect(ln(@as(f32, 0.2)) == ln_32(0.2));
157 try expect(ln(@as(f64, 0.2)) == ln_64(0.2));
158158}
159159
160160test "math.ln32" {
161161 const epsilon = 0.000001;
162162
163 expect(math.approxEqAbs(f32, ln_32(0.2), -1.609438, epsilon));
164 expect(math.approxEqAbs(f32, ln_32(0.8923), -0.113953, epsilon));
165 expect(math.approxEqAbs(f32, ln_32(1.5), 0.405465, epsilon));
166 expect(math.approxEqAbs(f32, ln_32(37.45), 3.623007, epsilon));
167 expect(math.approxEqAbs(f32, ln_32(89.123), 4.490017, epsilon));
168 expect(math.approxEqAbs(f32, ln_32(123123.234375), 11.720941, epsilon));
163 try expect(math.approxEqAbs(f32, ln_32(0.2), -1.609438, epsilon));
164 try expect(math.approxEqAbs(f32, ln_32(0.8923), -0.113953, epsilon));
165 try expect(math.approxEqAbs(f32, ln_32(1.5), 0.405465, epsilon));
166 try expect(math.approxEqAbs(f32, ln_32(37.45), 3.623007, epsilon));
167 try expect(math.approxEqAbs(f32, ln_32(89.123), 4.490017, epsilon));
168 try expect(math.approxEqAbs(f32, ln_32(123123.234375), 11.720941, epsilon));
169169}
170170
171171test "math.ln64" {
172172 const epsilon = 0.000001;
173173
174 expect(math.approxEqAbs(f64, ln_64(0.2), -1.609438, epsilon));
175 expect(math.approxEqAbs(f64, ln_64(0.8923), -0.113953, epsilon));
176 expect(math.approxEqAbs(f64, ln_64(1.5), 0.405465, epsilon));
177 expect(math.approxEqAbs(f64, ln_64(37.45), 3.623007, epsilon));
178 expect(math.approxEqAbs(f64, ln_64(89.123), 4.490017, epsilon));
179 expect(math.approxEqAbs(f64, ln_64(123123.234375), 11.720941, epsilon));
174 try expect(math.approxEqAbs(f64, ln_64(0.2), -1.609438, epsilon));
175 try expect(math.approxEqAbs(f64, ln_64(0.8923), -0.113953, epsilon));
176 try expect(math.approxEqAbs(f64, ln_64(1.5), 0.405465, epsilon));
177 try expect(math.approxEqAbs(f64, ln_64(37.45), 3.623007, epsilon));
178 try expect(math.approxEqAbs(f64, ln_64(89.123), 4.490017, epsilon));
179 try expect(math.approxEqAbs(f64, ln_64(123123.234375), 11.720941, epsilon));
180180}
181181
182182test "math.ln32.special" {
183 expect(math.isPositiveInf(ln_32(math.inf(f32))));
184 expect(math.isNegativeInf(ln_32(0.0)));
185 expect(math.isNan(ln_32(-1.0)));
186 expect(math.isNan(ln_32(math.nan(f32))));
183 try expect(math.isPositiveInf(ln_32(math.inf(f32))));
184 try expect(math.isNegativeInf(ln_32(0.0)));
185 try expect(math.isNan(ln_32(-1.0)));
186 try expect(math.isNan(ln_32(math.nan(f32))));
187187}
188188
189189test "math.ln64.special" {
190 expect(math.isPositiveInf(ln_64(math.inf(f64))));
191 expect(math.isNegativeInf(ln_64(0.0)));
192 expect(math.isNan(ln_64(-1.0)));
193 expect(math.isNan(ln_64(math.nan(f64))));
190 try expect(math.isPositiveInf(ln_64(math.inf(f64))));
191 try expect(math.isNegativeInf(ln_64(0.0)));
192 try expect(math.isNan(ln_64(-1.0)));
193 try expect(math.isNan(ln_64(math.nan(f64))));
194194}
lib/std/math/log.zig+12-12
......@@ -53,25 +53,25 @@ pub fn log(comptime T: type, base: T, x: T) T {
5353}
5454
5555test "math.log integer" {
56 expect(log(u8, 2, 0x1) == 0);
57 expect(log(u8, 2, 0x2) == 1);
58 expect(log(u16, 2, 0x72) == 6);
59 expect(log(u32, 2, 0xFFFFFF) == 23);
60 expect(log(u64, 2, 0x7FF0123456789ABC) == 62);
56 try expect(log(u8, 2, 0x1) == 0);
57 try expect(log(u8, 2, 0x2) == 1);
58 try expect(log(u16, 2, 0x72) == 6);
59 try expect(log(u32, 2, 0xFFFFFF) == 23);
60 try expect(log(u64, 2, 0x7FF0123456789ABC) == 62);
6161}
6262
6363test "math.log float" {
6464 const epsilon = 0.000001;
6565
66 expect(math.approxEqAbs(f32, log(f32, 6, 0.23947), -0.797723, epsilon));
67 expect(math.approxEqAbs(f32, log(f32, 89, 0.23947), -0.318432, epsilon));
68 expect(math.approxEqAbs(f64, log(f64, 123897, 12389216414), 1.981724596, epsilon));
66 try expect(math.approxEqAbs(f32, log(f32, 6, 0.23947), -0.797723, epsilon));
67 try expect(math.approxEqAbs(f32, log(f32, 89, 0.23947), -0.318432, epsilon));
68 try expect(math.approxEqAbs(f64, log(f64, 123897, 12389216414), 1.981724596, epsilon));
6969}
7070
7171test "math.log float_special" {
72 expect(log(f32, 2, 0.2301974) == math.log2(@as(f32, 0.2301974)));
73 expect(log(f32, 10, 0.2301974) == math.log10(@as(f32, 0.2301974)));
72 try expect(log(f32, 2, 0.2301974) == math.log2(@as(f32, 0.2301974)));
73 try expect(log(f32, 10, 0.2301974) == math.log10(@as(f32, 0.2301974)));
7474
75 expect(log(f64, 2, 213.23019799993) == math.log2(@as(f64, 213.23019799993)));
76 expect(log(f64, 10, 213.23019799993) == math.log10(@as(f64, 213.23019799993)));
75 try expect(log(f64, 2, 213.23019799993) == math.log2(@as(f64, 213.23019799993)));
76 try expect(log(f64, 10, 213.23019799993) == math.log10(@as(f64, 213.23019799993)));
7777}
lib/std/math/log10.zig+22-22
......@@ -181,42 +181,42 @@ pub fn log10_64(x_: f64) f64 {
181181}
182182
183183test "math.log10" {
184 testing.expect(log10(@as(f32, 0.2)) == log10_32(0.2));
185 testing.expect(log10(@as(f64, 0.2)) == log10_64(0.2));
184 try testing.expect(log10(@as(f32, 0.2)) == log10_32(0.2));
185 try testing.expect(log10(@as(f64, 0.2)) == log10_64(0.2));
186186}
187187
188188test "math.log10_32" {
189189 const epsilon = 0.000001;
190190
191 testing.expect(math.approxEqAbs(f32, log10_32(0.2), -0.698970, epsilon));
192 testing.expect(math.approxEqAbs(f32, log10_32(0.8923), -0.049489, epsilon));
193 testing.expect(math.approxEqAbs(f32, log10_32(1.5), 0.176091, epsilon));
194 testing.expect(math.approxEqAbs(f32, log10_32(37.45), 1.573452, epsilon));
195 testing.expect(math.approxEqAbs(f32, log10_32(89.123), 1.94999, epsilon));
196 testing.expect(math.approxEqAbs(f32, log10_32(123123.234375), 5.09034, epsilon));
191 try testing.expect(math.approxEqAbs(f32, log10_32(0.2), -0.698970, epsilon));
192 try testing.expect(math.approxEqAbs(f32, log10_32(0.8923), -0.049489, epsilon));
193 try testing.expect(math.approxEqAbs(f32, log10_32(1.5), 0.176091, epsilon));
194 try testing.expect(math.approxEqAbs(f32, log10_32(37.45), 1.573452, epsilon));
195 try testing.expect(math.approxEqAbs(f32, log10_32(89.123), 1.94999, epsilon));
196 try testing.expect(math.approxEqAbs(f32, log10_32(123123.234375), 5.09034, epsilon));
197197}
198198
199199test "math.log10_64" {
200200 const epsilon = 0.000001;
201201
202 testing.expect(math.approxEqAbs(f64, log10_64(0.2), -0.698970, epsilon));
203 testing.expect(math.approxEqAbs(f64, log10_64(0.8923), -0.049489, epsilon));
204 testing.expect(math.approxEqAbs(f64, log10_64(1.5), 0.176091, epsilon));
205 testing.expect(math.approxEqAbs(f64, log10_64(37.45), 1.573452, epsilon));
206 testing.expect(math.approxEqAbs(f64, log10_64(89.123), 1.94999, epsilon));
207 testing.expect(math.approxEqAbs(f64, log10_64(123123.234375), 5.09034, epsilon));
202 try testing.expect(math.approxEqAbs(f64, log10_64(0.2), -0.698970, epsilon));
203 try testing.expect(math.approxEqAbs(f64, log10_64(0.8923), -0.049489, epsilon));
204 try testing.expect(math.approxEqAbs(f64, log10_64(1.5), 0.176091, epsilon));
205 try testing.expect(math.approxEqAbs(f64, log10_64(37.45), 1.573452, epsilon));
206 try testing.expect(math.approxEqAbs(f64, log10_64(89.123), 1.94999, epsilon));
207 try testing.expect(math.approxEqAbs(f64, log10_64(123123.234375), 5.09034, epsilon));
208208}
209209
210210test "math.log10_32.special" {
211 testing.expect(math.isPositiveInf(log10_32(math.inf(f32))));
212 testing.expect(math.isNegativeInf(log10_32(0.0)));
213 testing.expect(math.isNan(log10_32(-1.0)));
214 testing.expect(math.isNan(log10_32(math.nan(f32))));
211 try testing.expect(math.isPositiveInf(log10_32(math.inf(f32))));
212 try testing.expect(math.isNegativeInf(log10_32(0.0)));
213 try testing.expect(math.isNan(log10_32(-1.0)));
214 try testing.expect(math.isNan(log10_32(math.nan(f32))));
215215}
216216
217217test "math.log10_64.special" {
218 testing.expect(math.isPositiveInf(log10_64(math.inf(f64))));
219 testing.expect(math.isNegativeInf(log10_64(0.0)));
220 testing.expect(math.isNan(log10_64(-1.0)));
221 testing.expect(math.isNan(log10_64(math.nan(f64))));
218 try testing.expect(math.isPositiveInf(log10_64(math.inf(f64))));
219 try testing.expect(math.isNegativeInf(log10_64(0.0)));
220 try testing.expect(math.isNan(log10_64(-1.0)));
221 try testing.expect(math.isNan(log10_64(math.nan(f64))));
222222}
lib/std/math/log1p.zig+28-28
......@@ -187,48 +187,48 @@ fn log1p_64(x: f64) f64 {
187187}
188188
189189test "math.log1p" {
190 expect(log1p(@as(f32, 0.0)) == log1p_32(0.0));
191 expect(log1p(@as(f64, 0.0)) == log1p_64(0.0));
190 try expect(log1p(@as(f32, 0.0)) == log1p_32(0.0));
191 try expect(log1p(@as(f64, 0.0)) == log1p_64(0.0));
192192}
193193
194194test "math.log1p_32" {
195195 const epsilon = 0.000001;
196196
197 expect(math.approxEqAbs(f32, log1p_32(0.0), 0.0, epsilon));
198 expect(math.approxEqAbs(f32, log1p_32(0.2), 0.182322, epsilon));
199 expect(math.approxEqAbs(f32, log1p_32(0.8923), 0.637793, epsilon));
200 expect(math.approxEqAbs(f32, log1p_32(1.5), 0.916291, epsilon));
201 expect(math.approxEqAbs(f32, log1p_32(37.45), 3.649359, epsilon));
202 expect(math.approxEqAbs(f32, log1p_32(89.123), 4.501175, epsilon));
203 expect(math.approxEqAbs(f32, log1p_32(123123.234375), 11.720949, epsilon));
197 try expect(math.approxEqAbs(f32, log1p_32(0.0), 0.0, epsilon));
198 try expect(math.approxEqAbs(f32, log1p_32(0.2), 0.182322, epsilon));
199 try expect(math.approxEqAbs(f32, log1p_32(0.8923), 0.637793, epsilon));
200 try expect(math.approxEqAbs(f32, log1p_32(1.5), 0.916291, epsilon));
201 try expect(math.approxEqAbs(f32, log1p_32(37.45), 3.649359, epsilon));
202 try expect(math.approxEqAbs(f32, log1p_32(89.123), 4.501175, epsilon));
203 try expect(math.approxEqAbs(f32, log1p_32(123123.234375), 11.720949, epsilon));
204204}
205205
206206test "math.log1p_64" {
207207 const epsilon = 0.000001;
208208
209 expect(math.approxEqAbs(f64, log1p_64(0.0), 0.0, epsilon));
210 expect(math.approxEqAbs(f64, log1p_64(0.2), 0.182322, epsilon));
211 expect(math.approxEqAbs(f64, log1p_64(0.8923), 0.637793, epsilon));
212 expect(math.approxEqAbs(f64, log1p_64(1.5), 0.916291, epsilon));
213 expect(math.approxEqAbs(f64, log1p_64(37.45), 3.649359, epsilon));
214 expect(math.approxEqAbs(f64, log1p_64(89.123), 4.501175, epsilon));
215 expect(math.approxEqAbs(f64, log1p_64(123123.234375), 11.720949, epsilon));
209 try expect(math.approxEqAbs(f64, log1p_64(0.0), 0.0, epsilon));
210 try expect(math.approxEqAbs(f64, log1p_64(0.2), 0.182322, epsilon));
211 try expect(math.approxEqAbs(f64, log1p_64(0.8923), 0.637793, epsilon));
212 try expect(math.approxEqAbs(f64, log1p_64(1.5), 0.916291, epsilon));
213 try expect(math.approxEqAbs(f64, log1p_64(37.45), 3.649359, epsilon));
214 try expect(math.approxEqAbs(f64, log1p_64(89.123), 4.501175, epsilon));
215 try expect(math.approxEqAbs(f64, log1p_64(123123.234375), 11.720949, epsilon));
216216}
217217
218218test "math.log1p_32.special" {
219 expect(math.isPositiveInf(log1p_32(math.inf(f32))));
220 expect(log1p_32(0.0) == 0.0);
221 expect(log1p_32(-0.0) == -0.0);
222 expect(math.isNegativeInf(log1p_32(-1.0)));
223 expect(math.isNan(log1p_32(-2.0)));
224 expect(math.isNan(log1p_32(math.nan(f32))));
219 try expect(math.isPositiveInf(log1p_32(math.inf(f32))));
220 try expect(log1p_32(0.0) == 0.0);
221 try expect(log1p_32(-0.0) == -0.0);
222 try expect(math.isNegativeInf(log1p_32(-1.0)));
223 try expect(math.isNan(log1p_32(-2.0)));
224 try expect(math.isNan(log1p_32(math.nan(f32))));
225225}
226226
227227test "math.log1p_64.special" {
228 expect(math.isPositiveInf(log1p_64(math.inf(f64))));
229 expect(log1p_64(0.0) == 0.0);
230 expect(log1p_64(-0.0) == -0.0);
231 expect(math.isNegativeInf(log1p_64(-1.0)));
232 expect(math.isNan(log1p_64(-2.0)));
233 expect(math.isNan(log1p_64(math.nan(f64))));
228 try expect(math.isPositiveInf(log1p_64(math.inf(f64))));
229 try expect(log1p_64(0.0) == 0.0);
230 try expect(log1p_64(-0.0) == -0.0);
231 try expect(math.isNegativeInf(log1p_64(-1.0)));
232 try expect(math.isNan(log1p_64(-2.0)));
233 try expect(math.isNan(log1p_64(math.nan(f64))));
234234}
lib/std/math/log2.zig+20-20
......@@ -179,40 +179,40 @@ pub fn log2_64(x_: f64) f64 {
179179}
180180
181181test "math.log2" {
182 expect(log2(@as(f32, 0.2)) == log2_32(0.2));
183 expect(log2(@as(f64, 0.2)) == log2_64(0.2));
182 try expect(log2(@as(f32, 0.2)) == log2_32(0.2));
183 try expect(log2(@as(f64, 0.2)) == log2_64(0.2));
184184}
185185
186186test "math.log2_32" {
187187 const epsilon = 0.000001;
188188
189 expect(math.approxEqAbs(f32, log2_32(0.2), -2.321928, epsilon));
190 expect(math.approxEqAbs(f32, log2_32(0.8923), -0.164399, epsilon));
191 expect(math.approxEqAbs(f32, log2_32(1.5), 0.584962, epsilon));
192 expect(math.approxEqAbs(f32, log2_32(37.45), 5.226894, epsilon));
193 expect(math.approxEqAbs(f32, log2_32(123123.234375), 16.909744, epsilon));
189 try expect(math.approxEqAbs(f32, log2_32(0.2), -2.321928, epsilon));
190 try expect(math.approxEqAbs(f32, log2_32(0.8923), -0.164399, epsilon));
191 try expect(math.approxEqAbs(f32, log2_32(1.5), 0.584962, epsilon));
192 try expect(math.approxEqAbs(f32, log2_32(37.45), 5.226894, epsilon));
193 try expect(math.approxEqAbs(f32, log2_32(123123.234375), 16.909744, epsilon));
194194}
195195
196196test "math.log2_64" {
197197 const epsilon = 0.000001;
198198
199 expect(math.approxEqAbs(f64, log2_64(0.2), -2.321928, epsilon));
200 expect(math.approxEqAbs(f64, log2_64(0.8923), -0.164399, epsilon));
201 expect(math.approxEqAbs(f64, log2_64(1.5), 0.584962, epsilon));
202 expect(math.approxEqAbs(f64, log2_64(37.45), 5.226894, epsilon));
203 expect(math.approxEqAbs(f64, log2_64(123123.234375), 16.909744, epsilon));
199 try expect(math.approxEqAbs(f64, log2_64(0.2), -2.321928, epsilon));
200 try expect(math.approxEqAbs(f64, log2_64(0.8923), -0.164399, epsilon));
201 try expect(math.approxEqAbs(f64, log2_64(1.5), 0.584962, epsilon));
202 try expect(math.approxEqAbs(f64, log2_64(37.45), 5.226894, epsilon));
203 try expect(math.approxEqAbs(f64, log2_64(123123.234375), 16.909744, epsilon));
204204}
205205
206206test "math.log2_32.special" {
207 expect(math.isPositiveInf(log2_32(math.inf(f32))));
208 expect(math.isNegativeInf(log2_32(0.0)));
209 expect(math.isNan(log2_32(-1.0)));
210 expect(math.isNan(log2_32(math.nan(f32))));
207 try expect(math.isPositiveInf(log2_32(math.inf(f32))));
208 try expect(math.isNegativeInf(log2_32(0.0)));
209 try expect(math.isNan(log2_32(-1.0)));
210 try expect(math.isNan(log2_32(math.nan(f32))));
211211}
212212
213213test "math.log2_64.special" {
214 expect(math.isPositiveInf(log2_64(math.inf(f64))));
215 expect(math.isNegativeInf(log2_64(0.0)));
216 expect(math.isNan(log2_64(-1.0)));
217 expect(math.isNan(log2_64(math.nan(f64))));
214 try expect(math.isPositiveInf(log2_64(math.inf(f64))));
215 try expect(math.isNegativeInf(log2_64(0.0)));
216 try expect(math.isNan(log2_64(-1.0)));
217 try expect(math.isNan(log2_64(math.nan(f64))));
218218}
lib/std/math/modf.zig+28-28
......@@ -131,11 +131,11 @@ test "math.modf" {
131131 const a = modf(@as(f32, 1.0));
132132 const b = modf32(1.0);
133133 // NOTE: No struct comparison on generic return type function? non-named, makes sense, but still.
134 expect(a.ipart == b.ipart and a.fpart == b.fpart);
134 try expect(a.ipart == b.ipart and a.fpart == b.fpart);
135135
136136 const c = modf(@as(f64, 1.0));
137137 const d = modf64(1.0);
138 expect(a.ipart == b.ipart and a.fpart == b.fpart);
138 try expect(a.ipart == b.ipart and a.fpart == b.fpart);
139139}
140140
141141test "math.modf32" {
......@@ -143,24 +143,24 @@ test "math.modf32" {
143143 var r: modf32_result = undefined;
144144
145145 r = modf32(1.0);
146 expect(math.approxEqAbs(f32, r.ipart, 1.0, epsilon));
147 expect(math.approxEqAbs(f32, r.fpart, 0.0, epsilon));
146 try expect(math.approxEqAbs(f32, r.ipart, 1.0, epsilon));
147 try expect(math.approxEqAbs(f32, r.fpart, 0.0, epsilon));
148148
149149 r = modf32(2.545);
150 expect(math.approxEqAbs(f32, r.ipart, 2.0, epsilon));
151 expect(math.approxEqAbs(f32, r.fpart, 0.545, epsilon));
150 try expect(math.approxEqAbs(f32, r.ipart, 2.0, epsilon));
151 try expect(math.approxEqAbs(f32, r.fpart, 0.545, epsilon));
152152
153153 r = modf32(3.978123);
154 expect(math.approxEqAbs(f32, r.ipart, 3.0, epsilon));
155 expect(math.approxEqAbs(f32, r.fpart, 0.978123, epsilon));
154 try expect(math.approxEqAbs(f32, r.ipart, 3.0, epsilon));
155 try expect(math.approxEqAbs(f32, r.fpart, 0.978123, epsilon));
156156
157157 r = modf32(43874.3);
158 expect(math.approxEqAbs(f32, r.ipart, 43874, epsilon));
159 expect(math.approxEqAbs(f32, r.fpart, 0.300781, epsilon));
158 try expect(math.approxEqAbs(f32, r.ipart, 43874, epsilon));
159 try expect(math.approxEqAbs(f32, r.fpart, 0.300781, epsilon));
160160
161161 r = modf32(1234.340780);
162 expect(math.approxEqAbs(f32, r.ipart, 1234, epsilon));
163 expect(math.approxEqAbs(f32, r.fpart, 0.340820, epsilon));
162 try expect(math.approxEqAbs(f32, r.ipart, 1234, epsilon));
163 try expect(math.approxEqAbs(f32, r.fpart, 0.340820, epsilon));
164164}
165165
166166test "math.modf64" {
......@@ -168,48 +168,48 @@ test "math.modf64" {
168168 var r: modf64_result = undefined;
169169
170170 r = modf64(1.0);
171 expect(math.approxEqAbs(f64, r.ipart, 1.0, epsilon));
172 expect(math.approxEqAbs(f64, r.fpart, 0.0, epsilon));
171 try expect(math.approxEqAbs(f64, r.ipart, 1.0, epsilon));
172 try expect(math.approxEqAbs(f64, r.fpart, 0.0, epsilon));
173173
174174 r = modf64(2.545);
175 expect(math.approxEqAbs(f64, r.ipart, 2.0, epsilon));
176 expect(math.approxEqAbs(f64, r.fpart, 0.545, epsilon));
175 try expect(math.approxEqAbs(f64, r.ipart, 2.0, epsilon));
176 try expect(math.approxEqAbs(f64, r.fpart, 0.545, epsilon));
177177
178178 r = modf64(3.978123);
179 expect(math.approxEqAbs(f64, r.ipart, 3.0, epsilon));
180 expect(math.approxEqAbs(f64, r.fpart, 0.978123, epsilon));
179 try expect(math.approxEqAbs(f64, r.ipart, 3.0, epsilon));
180 try expect(math.approxEqAbs(f64, r.fpart, 0.978123, epsilon));
181181
182182 r = modf64(43874.3);
183 expect(math.approxEqAbs(f64, r.ipart, 43874, epsilon));
184 expect(math.approxEqAbs(f64, r.fpart, 0.3, epsilon));
183 try expect(math.approxEqAbs(f64, r.ipart, 43874, epsilon));
184 try expect(math.approxEqAbs(f64, r.fpart, 0.3, epsilon));
185185
186186 r = modf64(1234.340780);
187 expect(math.approxEqAbs(f64, r.ipart, 1234, epsilon));
188 expect(math.approxEqAbs(f64, r.fpart, 0.340780, epsilon));
187 try expect(math.approxEqAbs(f64, r.ipart, 1234, epsilon));
188 try expect(math.approxEqAbs(f64, r.fpart, 0.340780, epsilon));
189189}
190190
191191test "math.modf32.special" {
192192 var r: modf32_result = undefined;
193193
194194 r = modf32(math.inf(f32));
195 expect(math.isPositiveInf(r.ipart) and math.isNan(r.fpart));
195 try expect(math.isPositiveInf(r.ipart) and math.isNan(r.fpart));
196196
197197 r = modf32(-math.inf(f32));
198 expect(math.isNegativeInf(r.ipart) and math.isNan(r.fpart));
198 try expect(math.isNegativeInf(r.ipart) and math.isNan(r.fpart));
199199
200200 r = modf32(math.nan(f32));
201 expect(math.isNan(r.ipart) and math.isNan(r.fpart));
201 try expect(math.isNan(r.ipart) and math.isNan(r.fpart));
202202}
203203
204204test "math.modf64.special" {
205205 var r: modf64_result = undefined;
206206
207207 r = modf64(math.inf(f64));
208 expect(math.isPositiveInf(r.ipart) and math.isNan(r.fpart));
208 try expect(math.isPositiveInf(r.ipart) and math.isNan(r.fpart));
209209
210210 r = modf64(-math.inf(f64));
211 expect(math.isNegativeInf(r.ipart) and math.isNan(r.fpart));
211 try expect(math.isNegativeInf(r.ipart) and math.isNan(r.fpart));
212212
213213 r = modf64(math.nan(f64));
214 expect(math.isNan(r.ipart) and math.isNan(r.fpart));
214 try expect(math.isNan(r.ipart) and math.isNan(r.fpart));
215215}
lib/std/math/pow.zig+52-52
......@@ -190,67 +190,67 @@ fn isOddInteger(x: f64) bool {
190190test "math.pow" {
191191 const epsilon = 0.000001;
192192
193 expect(math.approxEqAbs(f32, pow(f32, 0.0, 3.3), 0.0, epsilon));
194 expect(math.approxEqAbs(f32, pow(f32, 0.8923, 3.3), 0.686572, epsilon));
195 expect(math.approxEqAbs(f32, pow(f32, 0.2, 3.3), 0.004936, epsilon));
196 expect(math.approxEqAbs(f32, pow(f32, 1.5, 3.3), 3.811546, epsilon));
197 expect(math.approxEqAbs(f32, pow(f32, 37.45, 3.3), 155736.703125, epsilon));
198 expect(math.approxEqAbs(f32, pow(f32, 89.123, 3.3), 2722489.5, epsilon));
193 try expect(math.approxEqAbs(f32, pow(f32, 0.0, 3.3), 0.0, epsilon));
194 try expect(math.approxEqAbs(f32, pow(f32, 0.8923, 3.3), 0.686572, epsilon));
195 try expect(math.approxEqAbs(f32, pow(f32, 0.2, 3.3), 0.004936, epsilon));
196 try expect(math.approxEqAbs(f32, pow(f32, 1.5, 3.3), 3.811546, epsilon));
197 try expect(math.approxEqAbs(f32, pow(f32, 37.45, 3.3), 155736.703125, epsilon));
198 try expect(math.approxEqAbs(f32, pow(f32, 89.123, 3.3), 2722489.5, epsilon));
199199
200 expect(math.approxEqAbs(f64, pow(f64, 0.0, 3.3), 0.0, epsilon));
201 expect(math.approxEqAbs(f64, pow(f64, 0.8923, 3.3), 0.686572, epsilon));
202 expect(math.approxEqAbs(f64, pow(f64, 0.2, 3.3), 0.004936, epsilon));
203 expect(math.approxEqAbs(f64, pow(f64, 1.5, 3.3), 3.811546, epsilon));
204 expect(math.approxEqAbs(f64, pow(f64, 37.45, 3.3), 155736.7160616, epsilon));
205 expect(math.approxEqAbs(f64, pow(f64, 89.123, 3.3), 2722490.231436, epsilon));
200 try expect(math.approxEqAbs(f64, pow(f64, 0.0, 3.3), 0.0, epsilon));
201 try expect(math.approxEqAbs(f64, pow(f64, 0.8923, 3.3), 0.686572, epsilon));
202 try expect(math.approxEqAbs(f64, pow(f64, 0.2, 3.3), 0.004936, epsilon));
203 try expect(math.approxEqAbs(f64, pow(f64, 1.5, 3.3), 3.811546, epsilon));
204 try expect(math.approxEqAbs(f64, pow(f64, 37.45, 3.3), 155736.7160616, epsilon));
205 try expect(math.approxEqAbs(f64, pow(f64, 89.123, 3.3), 2722490.231436, epsilon));
206206}
207207
208208test "math.pow.special" {
209209 const epsilon = 0.000001;
210210
211 expect(pow(f32, 4, 0.0) == 1.0);
212 expect(pow(f32, 7, -0.0) == 1.0);
213 expect(pow(f32, 45, 1.0) == 45);
214 expect(pow(f32, -45, 1.0) == -45);
215 expect(math.isNan(pow(f32, math.nan(f32), 5.0)));
216 expect(math.isPositiveInf(pow(f32, -math.inf(f32), 0.5)));
217 expect(math.isPositiveInf(pow(f32, -0, -0.5)));
218 expect(pow(f32, -0, 0.5) == 0);
219 expect(math.isNan(pow(f32, 5.0, math.nan(f32))));
220 expect(math.isPositiveInf(pow(f32, 0.0, -1.0)));
211 try expect(pow(f32, 4, 0.0) == 1.0);
212 try expect(pow(f32, 7, -0.0) == 1.0);
213 try expect(pow(f32, 45, 1.0) == 45);
214 try expect(pow(f32, -45, 1.0) == -45);
215 try expect(math.isNan(pow(f32, math.nan(f32), 5.0)));
216 try expect(math.isPositiveInf(pow(f32, -math.inf(f32), 0.5)));
217 try expect(math.isPositiveInf(pow(f32, -0, -0.5)));
218 try expect(pow(f32, -0, 0.5) == 0);
219 try expect(math.isNan(pow(f32, 5.0, math.nan(f32))));
220 try expect(math.isPositiveInf(pow(f32, 0.0, -1.0)));
221221 //expect(math.isNegativeInf(pow(f32, -0.0, -3.0))); TODO is this required?
222 expect(math.isPositiveInf(pow(f32, 0.0, -math.inf(f32))));
223 expect(math.isPositiveInf(pow(f32, -0.0, -math.inf(f32))));
224 expect(pow(f32, 0.0, math.inf(f32)) == 0.0);
225 expect(pow(f32, -0.0, math.inf(f32)) == 0.0);
226 expect(math.isPositiveInf(pow(f32, 0.0, -2.0)));
227 expect(math.isPositiveInf(pow(f32, -0.0, -2.0)));
228 expect(pow(f32, 0.0, 1.0) == 0.0);
229 expect(pow(f32, -0.0, 1.0) == -0.0);
230 expect(pow(f32, 0.0, 2.0) == 0.0);
231 expect(pow(f32, -0.0, 2.0) == 0.0);
232 expect(math.approxEqAbs(f32, pow(f32, -1.0, math.inf(f32)), 1.0, epsilon));
233 expect(math.approxEqAbs(f32, pow(f32, -1.0, -math.inf(f32)), 1.0, epsilon));
234 expect(math.isPositiveInf(pow(f32, 1.2, math.inf(f32))));
235 expect(math.isPositiveInf(pow(f32, -1.2, math.inf(f32))));
236 expect(pow(f32, 1.2, -math.inf(f32)) == 0.0);
237 expect(pow(f32, -1.2, -math.inf(f32)) == 0.0);
238 expect(pow(f32, 0.2, math.inf(f32)) == 0.0);
239 expect(pow(f32, -0.2, math.inf(f32)) == 0.0);
240 expect(math.isPositiveInf(pow(f32, 0.2, -math.inf(f32))));
241 expect(math.isPositiveInf(pow(f32, -0.2, -math.inf(f32))));
242 expect(math.isPositiveInf(pow(f32, math.inf(f32), 1.0)));
243 expect(pow(f32, math.inf(f32), -1.0) == 0.0);
222 try expect(math.isPositiveInf(pow(f32, 0.0, -math.inf(f32))));
223 try expect(math.isPositiveInf(pow(f32, -0.0, -math.inf(f32))));
224 try expect(pow(f32, 0.0, math.inf(f32)) == 0.0);
225 try expect(pow(f32, -0.0, math.inf(f32)) == 0.0);
226 try expect(math.isPositiveInf(pow(f32, 0.0, -2.0)));
227 try expect(math.isPositiveInf(pow(f32, -0.0, -2.0)));
228 try expect(pow(f32, 0.0, 1.0) == 0.0);
229 try expect(pow(f32, -0.0, 1.0) == -0.0);
230 try expect(pow(f32, 0.0, 2.0) == 0.0);
231 try expect(pow(f32, -0.0, 2.0) == 0.0);
232 try expect(math.approxEqAbs(f32, pow(f32, -1.0, math.inf(f32)), 1.0, epsilon));
233 try expect(math.approxEqAbs(f32, pow(f32, -1.0, -math.inf(f32)), 1.0, epsilon));
234 try expect(math.isPositiveInf(pow(f32, 1.2, math.inf(f32))));
235 try expect(math.isPositiveInf(pow(f32, -1.2, math.inf(f32))));
236 try expect(pow(f32, 1.2, -math.inf(f32)) == 0.0);
237 try expect(pow(f32, -1.2, -math.inf(f32)) == 0.0);
238 try expect(pow(f32, 0.2, math.inf(f32)) == 0.0);
239 try expect(pow(f32, -0.2, math.inf(f32)) == 0.0);
240 try expect(math.isPositiveInf(pow(f32, 0.2, -math.inf(f32))));
241 try expect(math.isPositiveInf(pow(f32, -0.2, -math.inf(f32))));
242 try expect(math.isPositiveInf(pow(f32, math.inf(f32), 1.0)));
243 try expect(pow(f32, math.inf(f32), -1.0) == 0.0);
244244 //expect(pow(f32, -math.inf(f32), 5.0) == pow(f32, -0.0, -5.0)); TODO support negative 0?
245 expect(pow(f32, -math.inf(f32), -5.2) == pow(f32, -0.0, 5.2));
246 expect(math.isNan(pow(f32, -1.0, 1.2)));
247 expect(math.isNan(pow(f32, -12.4, 78.5)));
245 try expect(pow(f32, -math.inf(f32), -5.2) == pow(f32, -0.0, 5.2));
246 try expect(math.isNan(pow(f32, -1.0, 1.2)));
247 try expect(math.isNan(pow(f32, -12.4, 78.5)));
248248}
249249
250250test "math.pow.overflow" {
251 expect(math.isPositiveInf(pow(f64, 2, 1 << 32)));
252 expect(pow(f64, 2, -(1 << 32)) == 0);
253 expect(math.isNegativeInf(pow(f64, -2, (1 << 32) + 1)));
254 expect(pow(f64, 0.5, 1 << 45) == 0);
255 expect(math.isPositiveInf(pow(f64, 0.5, -(1 << 45))));
251 try expect(math.isPositiveInf(pow(f64, 2, 1 << 32)));
252 try expect(pow(f64, 2, -(1 << 32)) == 0);
253 try expect(math.isNegativeInf(pow(f64, -2, (1 << 32) + 1)));
254 try expect(pow(f64, 0.5, 1 << 45) == 0);
255 try expect(math.isPositiveInf(pow(f64, 0.5, -(1 << 45))));
256256}
lib/std/math/powi.zig+75-75
......@@ -111,82 +111,82 @@ pub fn powi(comptime T: type, x: T, y: T) (error{
111111}
112112
113113test "math.powi" {
114 testing.expectError(error.Underflow, powi(i8, -66, 6));
115 testing.expectError(error.Underflow, powi(i16, -13, 13));
116 testing.expectError(error.Underflow, powi(i32, -32, 21));
117 testing.expectError(error.Underflow, powi(i64, -24, 61));
118 testing.expectError(error.Underflow, powi(i17, -15, 15));
119 testing.expectError(error.Underflow, powi(i42, -6, 40));
120
121 testing.expect((try powi(i8, -5, 3)) == -125);
122 testing.expect((try powi(i16, -16, 3)) == -4096);
123 testing.expect((try powi(i32, -91, 3)) == -753571);
124 testing.expect((try powi(i64, -36, 6)) == 2176782336);
125 testing.expect((try powi(i17, -2, 15)) == -32768);
126 testing.expect((try powi(i42, -5, 7)) == -78125);
127
128 testing.expect((try powi(u8, 6, 2)) == 36);
129 testing.expect((try powi(u16, 5, 4)) == 625);
130 testing.expect((try powi(u32, 12, 6)) == 2985984);
131 testing.expect((try powi(u64, 34, 2)) == 1156);
132 testing.expect((try powi(u17, 16, 3)) == 4096);
133 testing.expect((try powi(u42, 34, 6)) == 1544804416);
134
135 testing.expectError(error.Overflow, powi(i8, 120, 7));
136 testing.expectError(error.Overflow, powi(i16, 73, 15));
137 testing.expectError(error.Overflow, powi(i32, 23, 31));
138 testing.expectError(error.Overflow, powi(i64, 68, 61));
139 testing.expectError(error.Overflow, powi(i17, 15, 15));
140 testing.expectError(error.Overflow, powi(i42, 121312, 41));
141
142 testing.expectError(error.Overflow, powi(u8, 123, 7));
143 testing.expectError(error.Overflow, powi(u16, 2313, 15));
144 testing.expectError(error.Overflow, powi(u32, 8968, 31));
145 testing.expectError(error.Overflow, powi(u64, 2342, 63));
146 testing.expectError(error.Overflow, powi(u17, 2723, 16));
147 testing.expectError(error.Overflow, powi(u42, 8234, 41));
114 try testing.expectError(error.Underflow, powi(i8, -66, 6));
115 try testing.expectError(error.Underflow, powi(i16, -13, 13));
116 try testing.expectError(error.Underflow, powi(i32, -32, 21));
117 try testing.expectError(error.Underflow, powi(i64, -24, 61));
118 try testing.expectError(error.Underflow, powi(i17, -15, 15));
119 try testing.expectError(error.Underflow, powi(i42, -6, 40));
120
121 try testing.expect((try powi(i8, -5, 3)) == -125);
122 try testing.expect((try powi(i16, -16, 3)) == -4096);
123 try testing.expect((try powi(i32, -91, 3)) == -753571);
124 try testing.expect((try powi(i64, -36, 6)) == 2176782336);
125 try testing.expect((try powi(i17, -2, 15)) == -32768);
126 try testing.expect((try powi(i42, -5, 7)) == -78125);
127
128 try testing.expect((try powi(u8, 6, 2)) == 36);
129 try testing.expect((try powi(u16, 5, 4)) == 625);
130 try testing.expect((try powi(u32, 12, 6)) == 2985984);
131 try testing.expect((try powi(u64, 34, 2)) == 1156);
132 try testing.expect((try powi(u17, 16, 3)) == 4096);
133 try testing.expect((try powi(u42, 34, 6)) == 1544804416);
134
135 try testing.expectError(error.Overflow, powi(i8, 120, 7));
136 try testing.expectError(error.Overflow, powi(i16, 73, 15));
137 try testing.expectError(error.Overflow, powi(i32, 23, 31));
138 try testing.expectError(error.Overflow, powi(i64, 68, 61));
139 try testing.expectError(error.Overflow, powi(i17, 15, 15));
140 try testing.expectError(error.Overflow, powi(i42, 121312, 41));
141
142 try testing.expectError(error.Overflow, powi(u8, 123, 7));
143 try testing.expectError(error.Overflow, powi(u16, 2313, 15));
144 try testing.expectError(error.Overflow, powi(u32, 8968, 31));
145 try testing.expectError(error.Overflow, powi(u64, 2342, 63));
146 try testing.expectError(error.Overflow, powi(u17, 2723, 16));
147 try testing.expectError(error.Overflow, powi(u42, 8234, 41));
148148}
149149
150150test "math.powi.special" {
151 testing.expectError(error.Underflow, powi(i8, -2, 8));
152 testing.expectError(error.Underflow, powi(i16, -2, 16));
153 testing.expectError(error.Underflow, powi(i32, -2, 32));
154 testing.expectError(error.Underflow, powi(i64, -2, 64));
155 testing.expectError(error.Underflow, powi(i17, -2, 17));
156 testing.expectError(error.Underflow, powi(i42, -2, 42));
157
158 testing.expect((try powi(i8, -1, 3)) == -1);
159 testing.expect((try powi(i16, -1, 2)) == 1);
160 testing.expect((try powi(i32, -1, 16)) == 1);
161 testing.expect((try powi(i64, -1, 6)) == 1);
162 testing.expect((try powi(i17, -1, 15)) == -1);
163 testing.expect((try powi(i42, -1, 7)) == -1);
164
165 testing.expect((try powi(u8, 1, 2)) == 1);
166 testing.expect((try powi(u16, 1, 4)) == 1);
167 testing.expect((try powi(u32, 1, 6)) == 1);
168 testing.expect((try powi(u64, 1, 2)) == 1);
169 testing.expect((try powi(u17, 1, 3)) == 1);
170 testing.expect((try powi(u42, 1, 6)) == 1);
171
172 testing.expectError(error.Overflow, powi(i8, 2, 7));
173 testing.expectError(error.Overflow, powi(i16, 2, 15));
174 testing.expectError(error.Overflow, powi(i32, 2, 31));
175 testing.expectError(error.Overflow, powi(i64, 2, 63));
176 testing.expectError(error.Overflow, powi(i17, 2, 16));
177 testing.expectError(error.Overflow, powi(i42, 2, 41));
178
179 testing.expectError(error.Overflow, powi(u8, 2, 8));
180 testing.expectError(error.Overflow, powi(u16, 2, 16));
181 testing.expectError(error.Overflow, powi(u32, 2, 32));
182 testing.expectError(error.Overflow, powi(u64, 2, 64));
183 testing.expectError(error.Overflow, powi(u17, 2, 17));
184 testing.expectError(error.Overflow, powi(u42, 2, 42));
185
186 testing.expect((try powi(u8, 6, 0)) == 1);
187 testing.expect((try powi(u16, 5, 0)) == 1);
188 testing.expect((try powi(u32, 12, 0)) == 1);
189 testing.expect((try powi(u64, 34, 0)) == 1);
190 testing.expect((try powi(u17, 16, 0)) == 1);
191 testing.expect((try powi(u42, 34, 0)) == 1);
151 try testing.expectError(error.Underflow, powi(i8, -2, 8));
152 try testing.expectError(error.Underflow, powi(i16, -2, 16));
153 try testing.expectError(error.Underflow, powi(i32, -2, 32));
154 try testing.expectError(error.Underflow, powi(i64, -2, 64));
155 try testing.expectError(error.Underflow, powi(i17, -2, 17));
156 try testing.expectError(error.Underflow, powi(i42, -2, 42));
157
158 try testing.expect((try powi(i8, -1, 3)) == -1);
159 try testing.expect((try powi(i16, -1, 2)) == 1);
160 try testing.expect((try powi(i32, -1, 16)) == 1);
161 try testing.expect((try powi(i64, -1, 6)) == 1);
162 try testing.expect((try powi(i17, -1, 15)) == -1);
163 try testing.expect((try powi(i42, -1, 7)) == -1);
164
165 try testing.expect((try powi(u8, 1, 2)) == 1);
166 try testing.expect((try powi(u16, 1, 4)) == 1);
167 try testing.expect((try powi(u32, 1, 6)) == 1);
168 try testing.expect((try powi(u64, 1, 2)) == 1);
169 try testing.expect((try powi(u17, 1, 3)) == 1);
170 try testing.expect((try powi(u42, 1, 6)) == 1);
171
172 try testing.expectError(error.Overflow, powi(i8, 2, 7));
173 try testing.expectError(error.Overflow, powi(i16, 2, 15));
174 try testing.expectError(error.Overflow, powi(i32, 2, 31));
175 try testing.expectError(error.Overflow, powi(i64, 2, 63));
176 try testing.expectError(error.Overflow, powi(i17, 2, 16));
177 try testing.expectError(error.Overflow, powi(i42, 2, 41));
178
179 try testing.expectError(error.Overflow, powi(u8, 2, 8));
180 try testing.expectError(error.Overflow, powi(u16, 2, 16));
181 try testing.expectError(error.Overflow, powi(u32, 2, 32));
182 try testing.expectError(error.Overflow, powi(u64, 2, 64));
183 try testing.expectError(error.Overflow, powi(u17, 2, 17));
184 try testing.expectError(error.Overflow, powi(u42, 2, 42));
185
186 try testing.expect((try powi(u8, 6, 0)) == 1);
187 try testing.expect((try powi(u16, 5, 0)) == 1);
188 try testing.expect((try powi(u32, 12, 0)) == 1);
189 try testing.expect((try powi(u64, 34, 0)) == 1);
190 try testing.expect((try powi(u17, 16, 0)) == 1);
191 try testing.expect((try powi(u42, 34, 0)) == 1);
192192}
lib/std/math/round.zig+30-30
......@@ -129,52 +129,52 @@ fn round128(x_: f128) f128 {
129129}
130130
131131test "math.round" {
132 expect(round(@as(f32, 1.3)) == round32(1.3));
133 expect(round(@as(f64, 1.3)) == round64(1.3));
134 expect(round(@as(f128, 1.3)) == round128(1.3));
132 try expect(round(@as(f32, 1.3)) == round32(1.3));
133 try expect(round(@as(f64, 1.3)) == round64(1.3));
134 try expect(round(@as(f128, 1.3)) == round128(1.3));
135135}
136136
137137test "math.round32" {
138 expect(round32(1.3) == 1.0);
139 expect(round32(-1.3) == -1.0);
140 expect(round32(0.2) == 0.0);
141 expect(round32(1.8) == 2.0);
138 try expect(round32(1.3) == 1.0);
139 try expect(round32(-1.3) == -1.0);
140 try expect(round32(0.2) == 0.0);
141 try expect(round32(1.8) == 2.0);
142142}
143143
144144test "math.round64" {
145 expect(round64(1.3) == 1.0);
146 expect(round64(-1.3) == -1.0);
147 expect(round64(0.2) == 0.0);
148 expect(round64(1.8) == 2.0);
145 try expect(round64(1.3) == 1.0);
146 try expect(round64(-1.3) == -1.0);
147 try expect(round64(0.2) == 0.0);
148 try expect(round64(1.8) == 2.0);
149149}
150150
151151test "math.round128" {
152 expect(round128(1.3) == 1.0);
153 expect(round128(-1.3) == -1.0);
154 expect(round128(0.2) == 0.0);
155 expect(round128(1.8) == 2.0);
152 try expect(round128(1.3) == 1.0);
153 try expect(round128(-1.3) == -1.0);
154 try expect(round128(0.2) == 0.0);
155 try expect(round128(1.8) == 2.0);
156156}
157157
158158test "math.round32.special" {
159 expect(round32(0.0) == 0.0);
160 expect(round32(-0.0) == -0.0);
161 expect(math.isPositiveInf(round32(math.inf(f32))));
162 expect(math.isNegativeInf(round32(-math.inf(f32))));
163 expect(math.isNan(round32(math.nan(f32))));
159 try expect(round32(0.0) == 0.0);
160 try expect(round32(-0.0) == -0.0);
161 try expect(math.isPositiveInf(round32(math.inf(f32))));
162 try expect(math.isNegativeInf(round32(-math.inf(f32))));
163 try expect(math.isNan(round32(math.nan(f32))));
164164}
165165
166166test "math.round64.special" {
167 expect(round64(0.0) == 0.0);
168 expect(round64(-0.0) == -0.0);
169 expect(math.isPositiveInf(round64(math.inf(f64))));
170 expect(math.isNegativeInf(round64(-math.inf(f64))));
171 expect(math.isNan(round64(math.nan(f64))));
167 try expect(round64(0.0) == 0.0);
168 try expect(round64(-0.0) == -0.0);
169 try expect(math.isPositiveInf(round64(math.inf(f64))));
170 try expect(math.isNegativeInf(round64(-math.inf(f64))));
171 try expect(math.isNan(round64(math.nan(f64))));
172172}
173173
174174test "math.round128.special" {
175 expect(round128(0.0) == 0.0);
176 expect(round128(-0.0) == -0.0);
177 expect(math.isPositiveInf(round128(math.inf(f128))));
178 expect(math.isNegativeInf(round128(-math.inf(f128))));
179 expect(math.isNan(round128(math.nan(f128))));
175 try expect(round128(0.0) == 0.0);
176 try expect(round128(-0.0) == -0.0);
177 try expect(math.isPositiveInf(round128(math.inf(f128))));
178 try expect(math.isNegativeInf(round128(-math.inf(f128))));
179 try expect(math.isNan(round128(math.nan(f128))));
180180}
lib/std/math/scalbn.zig+4-4
......@@ -84,14 +84,14 @@ fn scalbn64(x: f64, n_: i32) f64 {
8484}
8585
8686test "math.scalbn" {
87 expect(scalbn(@as(f32, 1.5), 4) == scalbn32(1.5, 4));
88 expect(scalbn(@as(f64, 1.5), 4) == scalbn64(1.5, 4));
87 try expect(scalbn(@as(f32, 1.5), 4) == scalbn32(1.5, 4));
88 try expect(scalbn(@as(f64, 1.5), 4) == scalbn64(1.5, 4));
8989}
9090
9191test "math.scalbn32" {
92 expect(scalbn32(1.5, 4) == 24.0);
92 try expect(scalbn32(1.5, 4) == 24.0);
9393}
9494
9595test "math.scalbn64" {
96 expect(scalbn64(1.5, 4) == 24.0);
96 try expect(scalbn64(1.5, 4) == 24.0);
9797}
lib/std/math/signbit.zig+12-12
......@@ -40,28 +40,28 @@ fn signbit128(x: f128) bool {
4040}
4141
4242test "math.signbit" {
43 expect(signbit(@as(f16, 4.0)) == signbit16(4.0));
44 expect(signbit(@as(f32, 4.0)) == signbit32(4.0));
45 expect(signbit(@as(f64, 4.0)) == signbit64(4.0));
46 expect(signbit(@as(f128, 4.0)) == signbit128(4.0));
43 try expect(signbit(@as(f16, 4.0)) == signbit16(4.0));
44 try expect(signbit(@as(f32, 4.0)) == signbit32(4.0));
45 try expect(signbit(@as(f64, 4.0)) == signbit64(4.0));
46 try expect(signbit(@as(f128, 4.0)) == signbit128(4.0));
4747}
4848
4949test "math.signbit16" {
50 expect(!signbit16(4.0));
51 expect(signbit16(-3.0));
50 try expect(!signbit16(4.0));
51 try expect(signbit16(-3.0));
5252}
5353
5454test "math.signbit32" {
55 expect(!signbit32(4.0));
56 expect(signbit32(-3.0));
55 try expect(!signbit32(4.0));
56 try expect(signbit32(-3.0));
5757}
5858
5959test "math.signbit64" {
60 expect(!signbit64(4.0));
61 expect(signbit64(-3.0));
60 try expect(!signbit64(4.0));
61 try expect(signbit64(-3.0));
6262}
6363
6464test "math.signbit128" {
65 expect(!signbit128(4.0));
66 expect(signbit128(-3.0));
65 try expect(!signbit128(4.0));
66 try expect(signbit128(-3.0));
6767}
lib/std/math/sin.zig+27-27
......@@ -88,47 +88,47 @@ fn sin_(comptime T: type, x_: T) T {
8888}
8989
9090test "math.sin" {
91 expect(sin(@as(f32, 0.0)) == sin_(f32, 0.0));
92 expect(sin(@as(f64, 0.0)) == sin_(f64, 0.0));
93 expect(comptime (math.sin(@as(f64, 2))) == math.sin(@as(f64, 2)));
91 try expect(sin(@as(f32, 0.0)) == sin_(f32, 0.0));
92 try expect(sin(@as(f64, 0.0)) == sin_(f64, 0.0));
93 try expect(comptime (math.sin(@as(f64, 2))) == math.sin(@as(f64, 2)));
9494}
9595
9696test "math.sin32" {
9797 const epsilon = 0.000001;
9898
99 expect(math.approxEqAbs(f32, sin_(f32, 0.0), 0.0, epsilon));
100 expect(math.approxEqAbs(f32, sin_(f32, 0.2), 0.198669, epsilon));
101 expect(math.approxEqAbs(f32, sin_(f32, 0.8923), 0.778517, epsilon));
102 expect(math.approxEqAbs(f32, sin_(f32, 1.5), 0.997495, epsilon));
103 expect(math.approxEqAbs(f32, sin_(f32, -1.5), -0.997495, epsilon));
104 expect(math.approxEqAbs(f32, sin_(f32, 37.45), -0.246544, epsilon));
105 expect(math.approxEqAbs(f32, sin_(f32, 89.123), 0.916166, epsilon));
99 try expect(math.approxEqAbs(f32, sin_(f32, 0.0), 0.0, epsilon));
100 try expect(math.approxEqAbs(f32, sin_(f32, 0.2), 0.198669, epsilon));
101 try expect(math.approxEqAbs(f32, sin_(f32, 0.8923), 0.778517, epsilon));
102 try expect(math.approxEqAbs(f32, sin_(f32, 1.5), 0.997495, epsilon));
103 try expect(math.approxEqAbs(f32, sin_(f32, -1.5), -0.997495, epsilon));
104 try expect(math.approxEqAbs(f32, sin_(f32, 37.45), -0.246544, epsilon));
105 try expect(math.approxEqAbs(f32, sin_(f32, 89.123), 0.916166, epsilon));
106106}
107107
108108test "math.sin64" {
109109 const epsilon = 0.000001;
110110
111 expect(math.approxEqAbs(f64, sin_(f64, 0.0), 0.0, epsilon));
112 expect(math.approxEqAbs(f64, sin_(f64, 0.2), 0.198669, epsilon));
113 expect(math.approxEqAbs(f64, sin_(f64, 0.8923), 0.778517, epsilon));
114 expect(math.approxEqAbs(f64, sin_(f64, 1.5), 0.997495, epsilon));
115 expect(math.approxEqAbs(f64, sin_(f64, -1.5), -0.997495, epsilon));
116 expect(math.approxEqAbs(f64, sin_(f64, 37.45), -0.246543, epsilon));
117 expect(math.approxEqAbs(f64, sin_(f64, 89.123), 0.916166, epsilon));
111 try expect(math.approxEqAbs(f64, sin_(f64, 0.0), 0.0, epsilon));
112 try expect(math.approxEqAbs(f64, sin_(f64, 0.2), 0.198669, epsilon));
113 try expect(math.approxEqAbs(f64, sin_(f64, 0.8923), 0.778517, epsilon));
114 try expect(math.approxEqAbs(f64, sin_(f64, 1.5), 0.997495, epsilon));
115 try expect(math.approxEqAbs(f64, sin_(f64, -1.5), -0.997495, epsilon));
116 try expect(math.approxEqAbs(f64, sin_(f64, 37.45), -0.246543, epsilon));
117 try expect(math.approxEqAbs(f64, sin_(f64, 89.123), 0.916166, epsilon));
118118}
119119
120120test "math.sin32.special" {
121 expect(sin_(f32, 0.0) == 0.0);
122 expect(sin_(f32, -0.0) == -0.0);
123 expect(math.isNan(sin_(f32, math.inf(f32))));
124 expect(math.isNan(sin_(f32, -math.inf(f32))));
125 expect(math.isNan(sin_(f32, math.nan(f32))));
121 try expect(sin_(f32, 0.0) == 0.0);
122 try expect(sin_(f32, -0.0) == -0.0);
123 try expect(math.isNan(sin_(f32, math.inf(f32))));
124 try expect(math.isNan(sin_(f32, -math.inf(f32))));
125 try expect(math.isNan(sin_(f32, math.nan(f32))));
126126}
127127
128128test "math.sin64.special" {
129 expect(sin_(f64, 0.0) == 0.0);
130 expect(sin_(f64, -0.0) == -0.0);
131 expect(math.isNan(sin_(f64, math.inf(f64))));
132 expect(math.isNan(sin_(f64, -math.inf(f64))));
133 expect(math.isNan(sin_(f64, math.nan(f64))));
129 try expect(sin_(f64, 0.0) == 0.0);
130 try expect(sin_(f64, -0.0) == -0.0);
131 try expect(math.isNan(sin_(f64, math.inf(f64))));
132 try expect(math.isNan(sin_(f64, -math.inf(f64))));
133 try expect(math.isNan(sin_(f64, math.nan(f64))));
134134}
lib/std/math/sinh.zig+28-28
......@@ -97,48 +97,48 @@ fn sinh64(x: f64) f64 {
9797}
9898
9999test "math.sinh" {
100 expect(sinh(@as(f32, 1.5)) == sinh32(1.5));
101 expect(sinh(@as(f64, 1.5)) == sinh64(1.5));
100 try expect(sinh(@as(f32, 1.5)) == sinh32(1.5));
101 try expect(sinh(@as(f64, 1.5)) == sinh64(1.5));
102102}
103103
104104test "math.sinh32" {
105105 const epsilon = 0.000001;
106106
107 expect(math.approxEqAbs(f32, sinh32(0.0), 0.0, epsilon));
108 expect(math.approxEqAbs(f32, sinh32(0.2), 0.201336, epsilon));
109 expect(math.approxEqAbs(f32, sinh32(0.8923), 1.015512, epsilon));
110 expect(math.approxEqAbs(f32, sinh32(1.5), 2.129279, epsilon));
111 expect(math.approxEqAbs(f32, sinh32(-0.0), -0.0, epsilon));
112 expect(math.approxEqAbs(f32, sinh32(-0.2), -0.201336, epsilon));
113 expect(math.approxEqAbs(f32, sinh32(-0.8923), -1.015512, epsilon));
114 expect(math.approxEqAbs(f32, sinh32(-1.5), -2.129279, epsilon));
107 try expect(math.approxEqAbs(f32, sinh32(0.0), 0.0, epsilon));
108 try expect(math.approxEqAbs(f32, sinh32(0.2), 0.201336, epsilon));
109 try expect(math.approxEqAbs(f32, sinh32(0.8923), 1.015512, epsilon));
110 try expect(math.approxEqAbs(f32, sinh32(1.5), 2.129279, epsilon));
111 try expect(math.approxEqAbs(f32, sinh32(-0.0), -0.0, epsilon));
112 try expect(math.approxEqAbs(f32, sinh32(-0.2), -0.201336, epsilon));
113 try expect(math.approxEqAbs(f32, sinh32(-0.8923), -1.015512, epsilon));
114 try expect(math.approxEqAbs(f32, sinh32(-1.5), -2.129279, epsilon));
115115}
116116
117117test "math.sinh64" {
118118 const epsilon = 0.000001;
119119
120 expect(math.approxEqAbs(f64, sinh64(0.0), 0.0, epsilon));
121 expect(math.approxEqAbs(f64, sinh64(0.2), 0.201336, epsilon));
122 expect(math.approxEqAbs(f64, sinh64(0.8923), 1.015512, epsilon));
123 expect(math.approxEqAbs(f64, sinh64(1.5), 2.129279, epsilon));
124 expect(math.approxEqAbs(f64, sinh64(-0.0), -0.0, epsilon));
125 expect(math.approxEqAbs(f64, sinh64(-0.2), -0.201336, epsilon));
126 expect(math.approxEqAbs(f64, sinh64(-0.8923), -1.015512, epsilon));
127 expect(math.approxEqAbs(f64, sinh64(-1.5), -2.129279, epsilon));
120 try expect(math.approxEqAbs(f64, sinh64(0.0), 0.0, epsilon));
121 try expect(math.approxEqAbs(f64, sinh64(0.2), 0.201336, epsilon));
122 try expect(math.approxEqAbs(f64, sinh64(0.8923), 1.015512, epsilon));
123 try expect(math.approxEqAbs(f64, sinh64(1.5), 2.129279, epsilon));
124 try expect(math.approxEqAbs(f64, sinh64(-0.0), -0.0, epsilon));
125 try expect(math.approxEqAbs(f64, sinh64(-0.2), -0.201336, epsilon));
126 try expect(math.approxEqAbs(f64, sinh64(-0.8923), -1.015512, epsilon));
127 try expect(math.approxEqAbs(f64, sinh64(-1.5), -2.129279, epsilon));
128128}
129129
130130test "math.sinh32.special" {
131 expect(sinh32(0.0) == 0.0);
132 expect(sinh32(-0.0) == -0.0);
133 expect(math.isPositiveInf(sinh32(math.inf(f32))));
134 expect(math.isNegativeInf(sinh32(-math.inf(f32))));
135 expect(math.isNan(sinh32(math.nan(f32))));
131 try expect(sinh32(0.0) == 0.0);
132 try expect(sinh32(-0.0) == -0.0);
133 try expect(math.isPositiveInf(sinh32(math.inf(f32))));
134 try expect(math.isNegativeInf(sinh32(-math.inf(f32))));
135 try expect(math.isNan(sinh32(math.nan(f32))));
136136}
137137
138138test "math.sinh64.special" {
139 expect(sinh64(0.0) == 0.0);
140 expect(sinh64(-0.0) == -0.0);
141 expect(math.isPositiveInf(sinh64(math.inf(f64))));
142 expect(math.isNegativeInf(sinh64(-math.inf(f64))));
143 expect(math.isNan(sinh64(math.nan(f64))));
139 try expect(sinh64(0.0) == 0.0);
140 try expect(sinh64(-0.0) == -0.0);
141 try expect(math.isPositiveInf(sinh64(math.inf(f64))));
142 try expect(math.isNegativeInf(sinh64(-math.inf(f64))));
143 try expect(math.isNan(sinh64(math.nan(f64))));
144144}
lib/std/math/sqrt.zig+8-8
......@@ -68,14 +68,14 @@ fn sqrt_int(comptime T: type, value: T) Sqrt(T) {
6868}
6969
7070test "math.sqrt_int" {
71 expect(sqrt_int(u0, 0) == 0);
72 expect(sqrt_int(u1, 1) == 1);
73 expect(sqrt_int(u32, 3) == 1);
74 expect(sqrt_int(u32, 4) == 2);
75 expect(sqrt_int(u32, 5) == 2);
76 expect(sqrt_int(u32, 8) == 2);
77 expect(sqrt_int(u32, 9) == 3);
78 expect(sqrt_int(u32, 10) == 3);
71 try expect(sqrt_int(u0, 0) == 0);
72 try expect(sqrt_int(u1, 1) == 1);
73 try expect(sqrt_int(u32, 3) == 1);
74 try expect(sqrt_int(u32, 4) == 2);
75 try expect(sqrt_int(u32, 5) == 2);
76 try expect(sqrt_int(u32, 8) == 2);
77 try expect(sqrt_int(u32, 9) == 3);
78 try expect(sqrt_int(u32, 10) == 3);
7979}
8080
8181/// Returns the return type `sqrt` will return given an operand of type `T`.
lib/std/math/tan.zig+24-24
......@@ -79,44 +79,44 @@ fn tan_(comptime T: type, x_: T) T {
7979}
8080
8181test "math.tan" {
82 expect(tan(@as(f32, 0.0)) == tan_(f32, 0.0));
83 expect(tan(@as(f64, 0.0)) == tan_(f64, 0.0));
82 try expect(tan(@as(f32, 0.0)) == tan_(f32, 0.0));
83 try expect(tan(@as(f64, 0.0)) == tan_(f64, 0.0));
8484}
8585
8686test "math.tan32" {
8787 const epsilon = 0.000001;
8888
89 expect(math.approxEqAbs(f32, tan_(f32, 0.0), 0.0, epsilon));
90 expect(math.approxEqAbs(f32, tan_(f32, 0.2), 0.202710, epsilon));
91 expect(math.approxEqAbs(f32, tan_(f32, 0.8923), 1.240422, epsilon));
92 expect(math.approxEqAbs(f32, tan_(f32, 1.5), 14.101420, epsilon));
93 expect(math.approxEqAbs(f32, tan_(f32, 37.45), -0.254397, epsilon));
94 expect(math.approxEqAbs(f32, tan_(f32, 89.123), 2.285852, epsilon));
89 try expect(math.approxEqAbs(f32, tan_(f32, 0.0), 0.0, epsilon));
90 try expect(math.approxEqAbs(f32, tan_(f32, 0.2), 0.202710, epsilon));
91 try expect(math.approxEqAbs(f32, tan_(f32, 0.8923), 1.240422, epsilon));
92 try expect(math.approxEqAbs(f32, tan_(f32, 1.5), 14.101420, epsilon));
93 try expect(math.approxEqAbs(f32, tan_(f32, 37.45), -0.254397, epsilon));
94 try expect(math.approxEqAbs(f32, tan_(f32, 89.123), 2.285852, epsilon));
9595}
9696
9797test "math.tan64" {
9898 const epsilon = 0.000001;
9999
100 expect(math.approxEqAbs(f64, tan_(f64, 0.0), 0.0, epsilon));
101 expect(math.approxEqAbs(f64, tan_(f64, 0.2), 0.202710, epsilon));
102 expect(math.approxEqAbs(f64, tan_(f64, 0.8923), 1.240422, epsilon));
103 expect(math.approxEqAbs(f64, tan_(f64, 1.5), 14.101420, epsilon));
104 expect(math.approxEqAbs(f64, tan_(f64, 37.45), -0.254397, epsilon));
105 expect(math.approxEqAbs(f64, tan_(f64, 89.123), 2.2858376, epsilon));
100 try expect(math.approxEqAbs(f64, tan_(f64, 0.0), 0.0, epsilon));
101 try expect(math.approxEqAbs(f64, tan_(f64, 0.2), 0.202710, epsilon));
102 try expect(math.approxEqAbs(f64, tan_(f64, 0.8923), 1.240422, epsilon));
103 try expect(math.approxEqAbs(f64, tan_(f64, 1.5), 14.101420, epsilon));
104 try expect(math.approxEqAbs(f64, tan_(f64, 37.45), -0.254397, epsilon));
105 try expect(math.approxEqAbs(f64, tan_(f64, 89.123), 2.2858376, epsilon));
106106}
107107
108108test "math.tan32.special" {
109 expect(tan_(f32, 0.0) == 0.0);
110 expect(tan_(f32, -0.0) == -0.0);
111 expect(math.isNan(tan_(f32, math.inf(f32))));
112 expect(math.isNan(tan_(f32, -math.inf(f32))));
113 expect(math.isNan(tan_(f32, math.nan(f32))));
109 try expect(tan_(f32, 0.0) == 0.0);
110 try expect(tan_(f32, -0.0) == -0.0);
111 try expect(math.isNan(tan_(f32, math.inf(f32))));
112 try expect(math.isNan(tan_(f32, -math.inf(f32))));
113 try expect(math.isNan(tan_(f32, math.nan(f32))));
114114}
115115
116116test "math.tan64.special" {
117 expect(tan_(f64, 0.0) == 0.0);
118 expect(tan_(f64, -0.0) == -0.0);
119 expect(math.isNan(tan_(f64, math.inf(f64))));
120 expect(math.isNan(tan_(f64, -math.inf(f64))));
121 expect(math.isNan(tan_(f64, math.nan(f64))));
117 try expect(tan_(f64, 0.0) == 0.0);
118 try expect(tan_(f64, -0.0) == -0.0);
119 try expect(math.isNan(tan_(f64, math.inf(f64))));
120 try expect(math.isNan(tan_(f64, -math.inf(f64))));
121 try expect(math.isNan(tan_(f64, math.nan(f64))));
122122}
lib/std/math/tanh.zig+22-22
......@@ -123,42 +123,42 @@ fn tanh64(x: f64) f64 {
123123}
124124
125125test "math.tanh" {
126 expect(tanh(@as(f32, 1.5)) == tanh32(1.5));
127 expect(tanh(@as(f64, 1.5)) == tanh64(1.5));
126 try expect(tanh(@as(f32, 1.5)) == tanh32(1.5));
127 try expect(tanh(@as(f64, 1.5)) == tanh64(1.5));
128128}
129129
130130test "math.tanh32" {
131131 const epsilon = 0.000001;
132132
133 expect(math.approxEqAbs(f32, tanh32(0.0), 0.0, epsilon));
134 expect(math.approxEqAbs(f32, tanh32(0.2), 0.197375, epsilon));
135 expect(math.approxEqAbs(f32, tanh32(0.8923), 0.712528, epsilon));
136 expect(math.approxEqAbs(f32, tanh32(1.5), 0.905148, epsilon));
137 expect(math.approxEqAbs(f32, tanh32(37.45), 1.0, epsilon));
133 try expect(math.approxEqAbs(f32, tanh32(0.0), 0.0, epsilon));
134 try expect(math.approxEqAbs(f32, tanh32(0.2), 0.197375, epsilon));
135 try expect(math.approxEqAbs(f32, tanh32(0.8923), 0.712528, epsilon));
136 try expect(math.approxEqAbs(f32, tanh32(1.5), 0.905148, epsilon));
137 try expect(math.approxEqAbs(f32, tanh32(37.45), 1.0, epsilon));
138138}
139139
140140test "math.tanh64" {
141141 const epsilon = 0.000001;
142142
143 expect(math.approxEqAbs(f64, tanh64(0.0), 0.0, epsilon));
144 expect(math.approxEqAbs(f64, tanh64(0.2), 0.197375, epsilon));
145 expect(math.approxEqAbs(f64, tanh64(0.8923), 0.712528, epsilon));
146 expect(math.approxEqAbs(f64, tanh64(1.5), 0.905148, epsilon));
147 expect(math.approxEqAbs(f64, tanh64(37.45), 1.0, epsilon));
143 try expect(math.approxEqAbs(f64, tanh64(0.0), 0.0, epsilon));
144 try expect(math.approxEqAbs(f64, tanh64(0.2), 0.197375, epsilon));
145 try expect(math.approxEqAbs(f64, tanh64(0.8923), 0.712528, epsilon));
146 try expect(math.approxEqAbs(f64, tanh64(1.5), 0.905148, epsilon));
147 try expect(math.approxEqAbs(f64, tanh64(37.45), 1.0, epsilon));
148148}
149149
150150test "math.tanh32.special" {
151 expect(tanh32(0.0) == 0.0);
152 expect(tanh32(-0.0) == -0.0);
153 expect(tanh32(math.inf(f32)) == 1.0);
154 expect(tanh32(-math.inf(f32)) == -1.0);
155 expect(math.isNan(tanh32(math.nan(f32))));
151 try expect(tanh32(0.0) == 0.0);
152 try expect(tanh32(-0.0) == -0.0);
153 try expect(tanh32(math.inf(f32)) == 1.0);
154 try expect(tanh32(-math.inf(f32)) == -1.0);
155 try expect(math.isNan(tanh32(math.nan(f32))));
156156}
157157
158158test "math.tanh64.special" {
159 expect(tanh64(0.0) == 0.0);
160 expect(tanh64(-0.0) == -0.0);
161 expect(tanh64(math.inf(f64)) == 1.0);
162 expect(tanh64(-math.inf(f64)) == -1.0);
163 expect(math.isNan(tanh64(math.nan(f64))));
159 try expect(tanh64(0.0) == 0.0);
160 try expect(tanh64(-0.0) == -0.0);
161 try expect(tanh64(math.inf(f64)) == 1.0);
162 try expect(tanh64(-math.inf(f64)) == -1.0);
163 try expect(math.isNan(tanh64(math.nan(f64))));
164164}
lib/std/math/trunc.zig+27-27
......@@ -94,49 +94,49 @@ fn trunc128(x: f128) f128 {
9494}
9595
9696test "math.trunc" {
97 expect(trunc(@as(f32, 1.3)) == trunc32(1.3));
98 expect(trunc(@as(f64, 1.3)) == trunc64(1.3));
99 expect(trunc(@as(f128, 1.3)) == trunc128(1.3));
97 try expect(trunc(@as(f32, 1.3)) == trunc32(1.3));
98 try expect(trunc(@as(f64, 1.3)) == trunc64(1.3));
99 try expect(trunc(@as(f128, 1.3)) == trunc128(1.3));
100100}
101101
102102test "math.trunc32" {
103 expect(trunc32(1.3) == 1.0);
104 expect(trunc32(-1.3) == -1.0);
105 expect(trunc32(0.2) == 0.0);
103 try expect(trunc32(1.3) == 1.0);
104 try expect(trunc32(-1.3) == -1.0);
105 try expect(trunc32(0.2) == 0.0);
106106}
107107
108108test "math.trunc64" {
109 expect(trunc64(1.3) == 1.0);
110 expect(trunc64(-1.3) == -1.0);
111 expect(trunc64(0.2) == 0.0);
109 try expect(trunc64(1.3) == 1.0);
110 try expect(trunc64(-1.3) == -1.0);
111 try expect(trunc64(0.2) == 0.0);
112112}
113113
114114test "math.trunc128" {
115 expect(trunc128(1.3) == 1.0);
116 expect(trunc128(-1.3) == -1.0);
117 expect(trunc128(0.2) == 0.0);
115 try expect(trunc128(1.3) == 1.0);
116 try expect(trunc128(-1.3) == -1.0);
117 try expect(trunc128(0.2) == 0.0);
118118}
119119
120120test "math.trunc32.special" {
121 expect(trunc32(0.0) == 0.0); // 0x3F800000
122 expect(trunc32(-0.0) == -0.0);
123 expect(math.isPositiveInf(trunc32(math.inf(f32))));
124 expect(math.isNegativeInf(trunc32(-math.inf(f32))));
125 expect(math.isNan(trunc32(math.nan(f32))));
121 try expect(trunc32(0.0) == 0.0); // 0x3F800000
122 try expect(trunc32(-0.0) == -0.0);
123 try expect(math.isPositiveInf(trunc32(math.inf(f32))));
124 try expect(math.isNegativeInf(trunc32(-math.inf(f32))));
125 try expect(math.isNan(trunc32(math.nan(f32))));
126126}
127127
128128test "math.trunc64.special" {
129 expect(trunc64(0.0) == 0.0);
130 expect(trunc64(-0.0) == -0.0);
131 expect(math.isPositiveInf(trunc64(math.inf(f64))));
132 expect(math.isNegativeInf(trunc64(-math.inf(f64))));
133 expect(math.isNan(trunc64(math.nan(f64))));
129 try expect(trunc64(0.0) == 0.0);
130 try expect(trunc64(-0.0) == -0.0);
131 try expect(math.isPositiveInf(trunc64(math.inf(f64))));
132 try expect(math.isNegativeInf(trunc64(-math.inf(f64))));
133 try expect(math.isNan(trunc64(math.nan(f64))));
134134}
135135
136136test "math.trunc128.special" {
137 expect(trunc128(0.0) == 0.0);
138 expect(trunc128(-0.0) == -0.0);
139 expect(math.isPositiveInf(trunc128(math.inf(f128))));
140 expect(math.isNegativeInf(trunc128(-math.inf(f128))));
141 expect(math.isNan(trunc128(math.nan(f128))));
137 try expect(trunc128(0.0) == 0.0);
138 try expect(trunc128(-0.0) == -0.0);
139 try expect(math.isPositiveInf(trunc128(math.inf(f128))));
140 try expect(math.isNegativeInf(trunc128(-math.inf(f128))));
141 try expect(math.isNan(trunc128(math.nan(f128))));
142142}
lib/std/mem.zig+359-359
......@@ -143,8 +143,8 @@ fn failAllocatorAlloc(self: *Allocator, n: usize, alignment: u29, len_align: u29
143143}
144144
145145test "mem.Allocator basics" {
146 testing.expectError(error.OutOfMemory, failAllocator.alloc(u8, 1));
147 testing.expectError(error.OutOfMemory, failAllocator.allocSentinel(u8, 1, 0));
146 try testing.expectError(error.OutOfMemory, failAllocator.alloc(u8, 1));
147 try testing.expectError(error.OutOfMemory, failAllocator.allocSentinel(u8, 1, 0));
148148}
149149
150150/// Copy all of source into dest at position 0.
......@@ -277,8 +277,8 @@ test "mem.zeroes" {
277277 var a = zeroes(C_struct);
278278 a.y += 10;
279279
280 testing.expect(a.x == 0);
281 testing.expect(a.y == 10);
280 try testing.expect(a.x == 0);
281 try testing.expect(a.y == 10);
282282
283283 const ZigStruct = struct {
284284 integral_types: struct {
......@@ -315,32 +315,32 @@ test "mem.zeroes" {
315315 };
316316
317317 const b = zeroes(ZigStruct);
318 testing.expectEqual(@as(i8, 0), b.integral_types.integer_0);
319 testing.expectEqual(@as(i8, 0), b.integral_types.integer_8);
320 testing.expectEqual(@as(i16, 0), b.integral_types.integer_16);
321 testing.expectEqual(@as(i32, 0), b.integral_types.integer_32);
322 testing.expectEqual(@as(i64, 0), b.integral_types.integer_64);
323 testing.expectEqual(@as(i128, 0), b.integral_types.integer_128);
324 testing.expectEqual(@as(u8, 0), b.integral_types.unsigned_0);
325 testing.expectEqual(@as(u8, 0), b.integral_types.unsigned_8);
326 testing.expectEqual(@as(u16, 0), b.integral_types.unsigned_16);
327 testing.expectEqual(@as(u32, 0), b.integral_types.unsigned_32);
328 testing.expectEqual(@as(u64, 0), b.integral_types.unsigned_64);
329 testing.expectEqual(@as(u128, 0), b.integral_types.unsigned_128);
330 testing.expectEqual(@as(f32, 0), b.integral_types.float_32);
331 testing.expectEqual(@as(f64, 0), b.integral_types.float_64);
332 testing.expectEqual(@as(?*u8, null), b.pointers.optional);
333 testing.expectEqual(@as([*c]u8, null), b.pointers.c_pointer);
334 testing.expectEqual(@as([]u8, &[_]u8{}), b.pointers.slice);
318 try testing.expectEqual(@as(i8, 0), b.integral_types.integer_0);
319 try testing.expectEqual(@as(i8, 0), b.integral_types.integer_8);
320 try testing.expectEqual(@as(i16, 0), b.integral_types.integer_16);
321 try testing.expectEqual(@as(i32, 0), b.integral_types.integer_32);
322 try testing.expectEqual(@as(i64, 0), b.integral_types.integer_64);
323 try testing.expectEqual(@as(i128, 0), b.integral_types.integer_128);
324 try testing.expectEqual(@as(u8, 0), b.integral_types.unsigned_0);
325 try testing.expectEqual(@as(u8, 0), b.integral_types.unsigned_8);
326 try testing.expectEqual(@as(u16, 0), b.integral_types.unsigned_16);
327 try testing.expectEqual(@as(u32, 0), b.integral_types.unsigned_32);
328 try testing.expectEqual(@as(u64, 0), b.integral_types.unsigned_64);
329 try testing.expectEqual(@as(u128, 0), b.integral_types.unsigned_128);
330 try testing.expectEqual(@as(f32, 0), b.integral_types.float_32);
331 try testing.expectEqual(@as(f64, 0), b.integral_types.float_64);
332 try testing.expectEqual(@as(?*u8, null), b.pointers.optional);
333 try testing.expectEqual(@as([*c]u8, null), b.pointers.c_pointer);
334 try testing.expectEqual(@as([]u8, &[_]u8{}), b.pointers.slice);
335335 for (b.array) |e| {
336 testing.expectEqual(@as(u32, 0), e);
336 try testing.expectEqual(@as(u32, 0), e);
337337 }
338 testing.expectEqual(@splat(2, @as(u32, 0)), b.vector_u32);
339 testing.expectEqual(@splat(2, @as(f32, 0.0)), b.vector_f32);
340 testing.expectEqual(@splat(2, @as(bool, false)), b.vector_bool);
341 testing.expectEqual(@as(?u8, null), b.optional_int);
338 try testing.expectEqual(@splat(2, @as(u32, 0)), b.vector_u32);
339 try testing.expectEqual(@splat(2, @as(f32, 0.0)), b.vector_f32);
340 try testing.expectEqual(@splat(2, @as(bool, false)), b.vector_bool);
341 try testing.expectEqual(@as(?u8, null), b.optional_int);
342342 for (b.sentinel) |e| {
343 testing.expectEqual(@as(u8, 0), e);
343 try testing.expectEqual(@as(u8, 0), e);
344344 }
345345
346346 const C_union = extern union {
......@@ -349,7 +349,7 @@ test "mem.zeroes" {
349349 };
350350
351351 var c = zeroes(C_union);
352 testing.expectEqual(@as(u8, 0), c.a);
352 try testing.expectEqual(@as(u8, 0), c.a);
353353}
354354
355355/// Initializes all fields of the struct with their default value, or zero values if no default value is present.
......@@ -422,7 +422,7 @@ test "zeroInit" {
422422 .a = 42,
423423 });
424424
425 testing.expectEqual(S{
425 try testing.expectEqual(S{
426426 .a = 42,
427427 .b = null,
428428 .c = .{
......@@ -440,7 +440,7 @@ test "zeroInit" {
440440 };
441441
442442 const c = zeroInit(Color, .{ 255, 255 });
443 testing.expectEqual(Color{
443 try testing.expectEqual(Color{
444444 .r = 255,
445445 .g = 255,
446446 .b = 0,
......@@ -463,11 +463,11 @@ pub fn order(comptime T: type, lhs: []const T, rhs: []const T) math.Order {
463463}
464464
465465test "order" {
466 testing.expect(order(u8, "abcd", "bee") == .lt);
467 testing.expect(order(u8, "abc", "abc") == .eq);
468 testing.expect(order(u8, "abc", "abc0") == .lt);
469 testing.expect(order(u8, "", "") == .eq);
470 testing.expect(order(u8, "", "a") == .lt);
466 try testing.expect(order(u8, "abcd", "bee") == .lt);
467 try testing.expect(order(u8, "abc", "abc") == .eq);
468 try testing.expect(order(u8, "abc", "abc0") == .lt);
469 try testing.expect(order(u8, "", "") == .eq);
470 try testing.expect(order(u8, "", "a") == .lt);
471471}
472472
473473/// Returns true if lhs < rhs, false otherwise
......@@ -476,11 +476,11 @@ pub fn lessThan(comptime T: type, lhs: []const T, rhs: []const T) bool {
476476}
477477
478478test "mem.lessThan" {
479 testing.expect(lessThan(u8, "abcd", "bee"));
480 testing.expect(!lessThan(u8, "abc", "abc"));
481 testing.expect(lessThan(u8, "abc", "abc0"));
482 testing.expect(!lessThan(u8, "", ""));
483 testing.expect(lessThan(u8, "", "a"));
479 try testing.expect(lessThan(u8, "abcd", "bee"));
480 try testing.expect(!lessThan(u8, "abc", "abc"));
481 try testing.expect(lessThan(u8, "abc", "abc0"));
482 try testing.expect(!lessThan(u8, "", ""));
483 try testing.expect(lessThan(u8, "", "a"));
484484}
485485
486486/// Compares two slices and returns whether they are equal.
......@@ -505,11 +505,11 @@ pub fn indexOfDiff(comptime T: type, a: []const T, b: []const T) ?usize {
505505}
506506
507507test "indexOfDiff" {
508 testing.expectEqual(indexOfDiff(u8, "one", "one"), null);
509 testing.expectEqual(indexOfDiff(u8, "one two", "one"), 3);
510 testing.expectEqual(indexOfDiff(u8, "one", "one two"), 3);
511 testing.expectEqual(indexOfDiff(u8, "one twx", "one two"), 6);
512 testing.expectEqual(indexOfDiff(u8, "xne", "one"), 0);
508 try testing.expectEqual(indexOfDiff(u8, "one", "one"), null);
509 try testing.expectEqual(indexOfDiff(u8, "one two", "one"), 3);
510 try testing.expectEqual(indexOfDiff(u8, "one", "one two"), 3);
511 try testing.expectEqual(indexOfDiff(u8, "one twx", "one two"), 6);
512 try testing.expectEqual(indexOfDiff(u8, "xne", "one"), 0);
513513}
514514
515515pub const toSliceConst = @compileError("deprecated; use std.mem.spanZ");
......@@ -549,26 +549,26 @@ pub fn Span(comptime T: type) type {
549549}
550550
551551test "Span" {
552 testing.expect(Span(*[5]u16) == []u16);
553 testing.expect(Span(?*[5]u16) == ?[]u16);
554 testing.expect(Span(*const [5]u16) == []const u16);
555 testing.expect(Span(?*const [5]u16) == ?[]const u16);
556 testing.expect(Span([]u16) == []u16);
557 testing.expect(Span(?[]u16) == ?[]u16);
558 testing.expect(Span([]const u8) == []const u8);
559 testing.expect(Span(?[]const u8) == ?[]const u8);
560 testing.expect(Span([:1]u16) == [:1]u16);
561 testing.expect(Span(?[:1]u16) == ?[:1]u16);
562 testing.expect(Span([:1]const u8) == [:1]const u8);
563 testing.expect(Span(?[:1]const u8) == ?[:1]const u8);
564 testing.expect(Span([*:1]u16) == [:1]u16);
565 testing.expect(Span(?[*:1]u16) == ?[:1]u16);
566 testing.expect(Span([*:1]const u8) == [:1]const u8);
567 testing.expect(Span(?[*:1]const u8) == ?[:1]const u8);
568 testing.expect(Span([*c]u16) == [:0]u16);
569 testing.expect(Span(?[*c]u16) == ?[:0]u16);
570 testing.expect(Span([*c]const u8) == [:0]const u8);
571 testing.expect(Span(?[*c]const u8) == ?[:0]const u8);
552 try testing.expect(Span(*[5]u16) == []u16);
553 try testing.expect(Span(?*[5]u16) == ?[]u16);
554 try testing.expect(Span(*const [5]u16) == []const u16);
555 try testing.expect(Span(?*const [5]u16) == ?[]const u16);
556 try testing.expect(Span([]u16) == []u16);
557 try testing.expect(Span(?[]u16) == ?[]u16);
558 try testing.expect(Span([]const u8) == []const u8);
559 try testing.expect(Span(?[]const u8) == ?[]const u8);
560 try testing.expect(Span([:1]u16) == [:1]u16);
561 try testing.expect(Span(?[:1]u16) == ?[:1]u16);
562 try testing.expect(Span([:1]const u8) == [:1]const u8);
563 try testing.expect(Span(?[:1]const u8) == ?[:1]const u8);
564 try testing.expect(Span([*:1]u16) == [:1]u16);
565 try testing.expect(Span(?[*:1]u16) == ?[:1]u16);
566 try testing.expect(Span([*:1]const u8) == [:1]const u8);
567 try testing.expect(Span(?[*:1]const u8) == ?[:1]const u8);
568 try testing.expect(Span([*c]u16) == [:0]u16);
569 try testing.expect(Span(?[*c]u16) == ?[:0]u16);
570 try testing.expect(Span([*c]const u8) == [:0]const u8);
571 try testing.expect(Span(?[*c]const u8) == ?[:0]const u8);
572572}
573573
574574/// Takes a pointer to an array, a sentinel-terminated pointer, or a slice, and
......@@ -598,9 +598,9 @@ pub fn span(ptr: anytype) Span(@TypeOf(ptr)) {
598598test "span" {
599599 var array: [5]u16 = [_]u16{ 1, 2, 3, 4, 5 };
600600 const ptr = @as([*:3]u16, array[0..2 :3]);
601 testing.expect(eql(u16, span(ptr), &[_]u16{ 1, 2 }));
602 testing.expect(eql(u16, span(&array), &[_]u16{ 1, 2, 3, 4, 5 }));
603 testing.expectEqual(@as(?[:0]u16, null), span(@as(?[*:0]u16, null)));
601 try testing.expect(eql(u16, span(ptr), &[_]u16{ 1, 2 }));
602 try testing.expect(eql(u16, span(&array), &[_]u16{ 1, 2, 3, 4, 5 }));
603 try testing.expectEqual(@as(?[:0]u16, null), span(@as(?[*:0]u16, null)));
604604}
605605
606606/// Same as `span`, except when there is both a sentinel and an array
......@@ -626,9 +626,9 @@ pub fn spanZ(ptr: anytype) Span(@TypeOf(ptr)) {
626626test "spanZ" {
627627 var array: [5]u16 = [_]u16{ 1, 2, 3, 4, 5 };
628628 const ptr = @as([*:3]u16, array[0..2 :3]);
629 testing.expect(eql(u16, spanZ(ptr), &[_]u16{ 1, 2 }));
630 testing.expect(eql(u16, spanZ(&array), &[_]u16{ 1, 2, 3, 4, 5 }));
631 testing.expectEqual(@as(?[:0]u16, null), spanZ(@as(?[*:0]u16, null)));
629 try testing.expect(eql(u16, spanZ(ptr), &[_]u16{ 1, 2 }));
630 try testing.expect(eql(u16, spanZ(&array), &[_]u16{ 1, 2, 3, 4, 5 }));
631 try testing.expectEqual(@as(?[:0]u16, null), spanZ(@as(?[*:0]u16, null)));
632632}
633633
634634/// Takes a pointer to an array, an array, a vector, a sentinel-terminated pointer,
......@@ -662,30 +662,30 @@ pub fn len(value: anytype) usize {
662662}
663663
664664test "len" {
665 testing.expect(len("aoeu") == 4);
665 try testing.expect(len("aoeu") == 4);
666666
667667 {
668668 var array: [5]u16 = [_]u16{ 1, 2, 3, 4, 5 };
669 testing.expect(len(&array) == 5);
670 testing.expect(len(array[0..3]) == 3);
669 try testing.expect(len(&array) == 5);
670 try testing.expect(len(array[0..3]) == 3);
671671 array[2] = 0;
672672 const ptr = @as([*:0]u16, array[0..2 :0]);
673 testing.expect(len(ptr) == 2);
673 try testing.expect(len(ptr) == 2);
674674 }
675675 {
676676 var array: [5:0]u16 = [_:0]u16{ 1, 2, 3, 4, 5 };
677 testing.expect(len(&array) == 5);
677 try testing.expect(len(&array) == 5);
678678 array[2] = 0;
679 testing.expect(len(&array) == 5);
679 try testing.expect(len(&array) == 5);
680680 }
681681 {
682682 const vector: meta.Vector(2, u32) = [2]u32{ 1, 2 };
683 testing.expect(len(vector) == 2);
683 try testing.expect(len(vector) == 2);
684684 }
685685 {
686686 const tuple = .{ 1, 2 };
687 testing.expect(len(tuple) == 2);
688 testing.expect(tuple[0] == 1);
687 try testing.expect(len(tuple) == 2);
688 try testing.expect(tuple[0] == 1);
689689 }
690690}
691691
......@@ -726,21 +726,21 @@ pub fn lenZ(ptr: anytype) usize {
726726}
727727
728728test "lenZ" {
729 testing.expect(lenZ("aoeu") == 4);
729 try testing.expect(lenZ("aoeu") == 4);
730730
731731 {
732732 var array: [5]u16 = [_]u16{ 1, 2, 3, 4, 5 };
733 testing.expect(lenZ(&array) == 5);
734 testing.expect(lenZ(array[0..3]) == 3);
733 try testing.expect(lenZ(&array) == 5);
734 try testing.expect(lenZ(array[0..3]) == 3);
735735 array[2] = 0;
736736 const ptr = @as([*:0]u16, array[0..2 :0]);
737 testing.expect(lenZ(ptr) == 2);
737 try testing.expect(lenZ(ptr) == 2);
738738 }
739739 {
740740 var array: [5:0]u16 = [_:0]u16{ 1, 2, 3, 4, 5 };
741 testing.expect(lenZ(&array) == 5);
741 try testing.expect(lenZ(&array) == 5);
742742 array[2] = 0;
743 testing.expect(lenZ(&array) == 2);
743 try testing.expect(lenZ(&array) == 2);
744744 }
745745}
746746
......@@ -794,10 +794,10 @@ pub fn trim(comptime T: type, slice: []const T, values_to_strip: []const T) []co
794794}
795795
796796test "mem.trim" {
797 testing.expectEqualSlices(u8, "foo\n ", trimLeft(u8, " foo\n ", " \n"));
798 testing.expectEqualSlices(u8, " foo", trimRight(u8, " foo\n ", " \n"));
799 testing.expectEqualSlices(u8, "foo", trim(u8, " foo\n ", " \n"));
800 testing.expectEqualSlices(u8, "foo", trim(u8, "foo", " \n"));
797 try testing.expectEqualSlices(u8, "foo\n ", trimLeft(u8, " foo\n ", " \n"));
798 try testing.expectEqualSlices(u8, " foo", trimRight(u8, " foo\n ", " \n"));
799 try testing.expectEqualSlices(u8, "foo", trim(u8, " foo\n ", " \n"));
800 try testing.expectEqualSlices(u8, "foo", trim(u8, "foo", " \n"));
801801}
802802
803803/// Linear search for the index of a scalar value inside a slice.
......@@ -952,28 +952,28 @@ pub fn indexOfPos(comptime T: type, haystack: []const T, start_index: usize, nee
952952}
953953
954954test "mem.indexOf" {
955 testing.expect(indexOf(u8, "one two three four five six seven eight nine ten eleven", "three four").? == 8);
956 testing.expect(lastIndexOf(u8, "one two three four five six seven eight nine ten eleven", "three four").? == 8);
957 testing.expect(indexOf(u8, "one two three four five six seven eight nine ten eleven", "two two") == null);
958 testing.expect(lastIndexOf(u8, "one two three four five six seven eight nine ten eleven", "two two") == null);
959
960 testing.expect(indexOf(u8, "one two three four five six seven eight nine ten", "").? == 0);
961 testing.expect(lastIndexOf(u8, "one two three four five six seven eight nine ten", "").? == 48);
962
963 testing.expect(indexOf(u8, "one two three four", "four").? == 14);
964 testing.expect(lastIndexOf(u8, "one two three two four", "two").? == 14);
965 testing.expect(indexOf(u8, "one two three four", "gour") == null);
966 testing.expect(lastIndexOf(u8, "one two three four", "gour") == null);
967 testing.expect(indexOf(u8, "foo", "foo").? == 0);
968 testing.expect(lastIndexOf(u8, "foo", "foo").? == 0);
969 testing.expect(indexOf(u8, "foo", "fool") == null);
970 testing.expect(lastIndexOf(u8, "foo", "lfoo") == null);
971 testing.expect(lastIndexOf(u8, "foo", "fool") == null);
972
973 testing.expect(indexOf(u8, "foo foo", "foo").? == 0);
974 testing.expect(lastIndexOf(u8, "foo foo", "foo").? == 4);
975 testing.expect(lastIndexOfAny(u8, "boo, cat", "abo").? == 6);
976 testing.expect(lastIndexOfScalar(u8, "boo", 'o').? == 2);
955 try testing.expect(indexOf(u8, "one two three four five six seven eight nine ten eleven", "three four").? == 8);
956 try testing.expect(lastIndexOf(u8, "one two three four five six seven eight nine ten eleven", "three four").? == 8);
957 try testing.expect(indexOf(u8, "one two three four five six seven eight nine ten eleven", "two two") == null);
958 try testing.expect(lastIndexOf(u8, "one two three four five six seven eight nine ten eleven", "two two") == null);
959
960 try testing.expect(indexOf(u8, "one two three four five six seven eight nine ten", "").? == 0);
961 try testing.expect(lastIndexOf(u8, "one two three four five six seven eight nine ten", "").? == 48);
962
963 try testing.expect(indexOf(u8, "one two three four", "four").? == 14);
964 try testing.expect(lastIndexOf(u8, "one two three two four", "two").? == 14);
965 try testing.expect(indexOf(u8, "one two three four", "gour") == null);
966 try testing.expect(lastIndexOf(u8, "one two three four", "gour") == null);
967 try testing.expect(indexOf(u8, "foo", "foo").? == 0);
968 try testing.expect(lastIndexOf(u8, "foo", "foo").? == 0);
969 try testing.expect(indexOf(u8, "foo", "fool") == null);
970 try testing.expect(lastIndexOf(u8, "foo", "lfoo") == null);
971 try testing.expect(lastIndexOf(u8, "foo", "fool") == null);
972
973 try testing.expect(indexOf(u8, "foo foo", "foo").? == 0);
974 try testing.expect(lastIndexOf(u8, "foo foo", "foo").? == 4);
975 try testing.expect(lastIndexOfAny(u8, "boo, cat", "abo").? == 6);
976 try testing.expect(lastIndexOfScalar(u8, "boo", 'o').? == 2);
977977}
978978
979979/// Returns the number of needles inside the haystack
......@@ -993,17 +993,17 @@ pub fn count(comptime T: type, haystack: []const T, needle: []const T) usize {
993993}
994994
995995test "mem.count" {
996 testing.expect(count(u8, "", "h") == 0);
997 testing.expect(count(u8, "h", "h") == 1);
998 testing.expect(count(u8, "hh", "h") == 2);
999 testing.expect(count(u8, "world!", "hello") == 0);
1000 testing.expect(count(u8, "hello world!", "hello") == 1);
1001 testing.expect(count(u8, " abcabc abc", "abc") == 3);
1002 testing.expect(count(u8, "udexdcbvbruhasdrw", "bruh") == 1);
1003 testing.expect(count(u8, "foo bar", "o bar") == 1);
1004 testing.expect(count(u8, "foofoofoo", "foo") == 3);
1005 testing.expect(count(u8, "fffffff", "ff") == 3);
1006 testing.expect(count(u8, "owowowu", "owowu") == 1);
996 try testing.expect(count(u8, "", "h") == 0);
997 try testing.expect(count(u8, "h", "h") == 1);
998 try testing.expect(count(u8, "hh", "h") == 2);
999 try testing.expect(count(u8, "world!", "hello") == 0);
1000 try testing.expect(count(u8, "hello world!", "hello") == 1);
1001 try testing.expect(count(u8, " abcabc abc", "abc") == 3);
1002 try testing.expect(count(u8, "udexdcbvbruhasdrw", "bruh") == 1);
1003 try testing.expect(count(u8, "foo bar", "o bar") == 1);
1004 try testing.expect(count(u8, "foofoofoo", "foo") == 3);
1005 try testing.expect(count(u8, "fffffff", "ff") == 3);
1006 try testing.expect(count(u8, "owowowu", "owowu") == 1);
10071007}
10081008
10091009/// Returns true if the haystack contains expected_count or more needles
......@@ -1025,19 +1025,19 @@ pub fn containsAtLeast(comptime T: type, haystack: []const T, expected_count: us
10251025}
10261026
10271027test "mem.containsAtLeast" {
1028 testing.expect(containsAtLeast(u8, "aa", 0, "a"));
1029 testing.expect(containsAtLeast(u8, "aa", 1, "a"));
1030 testing.expect(containsAtLeast(u8, "aa", 2, "a"));
1031 testing.expect(!containsAtLeast(u8, "aa", 3, "a"));
1028 try testing.expect(containsAtLeast(u8, "aa", 0, "a"));
1029 try testing.expect(containsAtLeast(u8, "aa", 1, "a"));
1030 try testing.expect(containsAtLeast(u8, "aa", 2, "a"));
1031 try testing.expect(!containsAtLeast(u8, "aa", 3, "a"));
10321032
1033 testing.expect(containsAtLeast(u8, "radaradar", 1, "radar"));
1034 testing.expect(!containsAtLeast(u8, "radaradar", 2, "radar"));
1033 try testing.expect(containsAtLeast(u8, "radaradar", 1, "radar"));
1034 try testing.expect(!containsAtLeast(u8, "radaradar", 2, "radar"));
10351035
1036 testing.expect(containsAtLeast(u8, "radarradaradarradar", 3, "radar"));
1037 testing.expect(!containsAtLeast(u8, "radarradaradarradar", 4, "radar"));
1036 try testing.expect(containsAtLeast(u8, "radarradaradarradar", 3, "radar"));
1037 try testing.expect(!containsAtLeast(u8, "radarradaradarradar", 4, "radar"));
10381038
1039 testing.expect(containsAtLeast(u8, " radar radar ", 2, "radar"));
1040 testing.expect(!containsAtLeast(u8, " radar radar ", 3, "radar"));
1039 try testing.expect(containsAtLeast(u8, " radar radar ", 2, "radar"));
1040 try testing.expect(!containsAtLeast(u8, " radar radar ", 3, "radar"));
10411041}
10421042
10431043/// Reads an integer from memory with size equal to bytes.len.
......@@ -1142,34 +1142,34 @@ test "comptime read/write int" {
11421142 var bytes: [2]u8 = undefined;
11431143 writeIntLittle(u16, &bytes, 0x1234);
11441144 const result = readIntBig(u16, &bytes);
1145 testing.expect(result == 0x3412);
1145 try testing.expect(result == 0x3412);
11461146 }
11471147 comptime {
11481148 var bytes: [2]u8 = undefined;
11491149 writeIntBig(u16, &bytes, 0x1234);
11501150 const result = readIntLittle(u16, &bytes);
1151 testing.expect(result == 0x3412);
1151 try testing.expect(result == 0x3412);
11521152 }
11531153}
11541154
11551155test "readIntBig and readIntLittle" {
1156 testing.expect(readIntSliceBig(u0, &[_]u8{}) == 0x0);
1157 testing.expect(readIntSliceLittle(u0, &[_]u8{}) == 0x0);
1156 try testing.expect(readIntSliceBig(u0, &[_]u8{}) == 0x0);
1157 try testing.expect(readIntSliceLittle(u0, &[_]u8{}) == 0x0);
11581158
1159 testing.expect(readIntSliceBig(u8, &[_]u8{0x32}) == 0x32);
1160 testing.expect(readIntSliceLittle(u8, &[_]u8{0x12}) == 0x12);
1159 try testing.expect(readIntSliceBig(u8, &[_]u8{0x32}) == 0x32);
1160 try testing.expect(readIntSliceLittle(u8, &[_]u8{0x12}) == 0x12);
11611161
1162 testing.expect(readIntSliceBig(u16, &[_]u8{ 0x12, 0x34 }) == 0x1234);
1163 testing.expect(readIntSliceLittle(u16, &[_]u8{ 0x12, 0x34 }) == 0x3412);
1162 try testing.expect(readIntSliceBig(u16, &[_]u8{ 0x12, 0x34 }) == 0x1234);
1163 try testing.expect(readIntSliceLittle(u16, &[_]u8{ 0x12, 0x34 }) == 0x3412);
11641164
1165 testing.expect(readIntSliceBig(u72, &[_]u8{ 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x24 }) == 0x123456789abcdef024);
1166 testing.expect(readIntSliceLittle(u72, &[_]u8{ 0xec, 0x10, 0x32, 0x54, 0x76, 0x98, 0xba, 0xdc, 0xfe }) == 0xfedcba9876543210ec);
1165 try testing.expect(readIntSliceBig(u72, &[_]u8{ 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x24 }) == 0x123456789abcdef024);
1166 try testing.expect(readIntSliceLittle(u72, &[_]u8{ 0xec, 0x10, 0x32, 0x54, 0x76, 0x98, 0xba, 0xdc, 0xfe }) == 0xfedcba9876543210ec);
11671167
1168 testing.expect(readIntSliceBig(i8, &[_]u8{0xff}) == -1);
1169 testing.expect(readIntSliceLittle(i8, &[_]u8{0xfe}) == -2);
1168 try testing.expect(readIntSliceBig(i8, &[_]u8{0xff}) == -1);
1169 try testing.expect(readIntSliceLittle(i8, &[_]u8{0xfe}) == -2);
11701170
1171 testing.expect(readIntSliceBig(i16, &[_]u8{ 0xff, 0xfd }) == -3);
1172 testing.expect(readIntSliceLittle(i16, &[_]u8{ 0xfc, 0xff }) == -4);
1171 try testing.expect(readIntSliceBig(i16, &[_]u8{ 0xff, 0xfd }) == -3);
1172 try testing.expect(readIntSliceLittle(i16, &[_]u8{ 0xfc, 0xff }) == -4);
11731173}
11741174
11751175/// Writes an integer to memory, storing it in twos-complement.
......@@ -1284,34 +1284,34 @@ test "writeIntBig and writeIntLittle" {
12841284 var buf9: [9]u8 = undefined;
12851285
12861286 writeIntBig(u0, &buf0, 0x0);
1287 testing.expect(eql(u8, buf0[0..], &[_]u8{}));
1287 try testing.expect(eql(u8, buf0[0..], &[_]u8{}));
12881288 writeIntLittle(u0, &buf0, 0x0);
1289 testing.expect(eql(u8, buf0[0..], &[_]u8{}));
1289 try testing.expect(eql(u8, buf0[0..], &[_]u8{}));
12901290
12911291 writeIntBig(u8, &buf1, 0x12);
1292 testing.expect(eql(u8, buf1[0..], &[_]u8{0x12}));
1292 try testing.expect(eql(u8, buf1[0..], &[_]u8{0x12}));
12931293 writeIntLittle(u8, &buf1, 0x34);
1294 testing.expect(eql(u8, buf1[0..], &[_]u8{0x34}));
1294 try testing.expect(eql(u8, buf1[0..], &[_]u8{0x34}));
12951295
12961296 writeIntBig(u16, &buf2, 0x1234);
1297 testing.expect(eql(u8, buf2[0..], &[_]u8{ 0x12, 0x34 }));
1297 try testing.expect(eql(u8, buf2[0..], &[_]u8{ 0x12, 0x34 }));
12981298 writeIntLittle(u16, &buf2, 0x5678);
1299 testing.expect(eql(u8, buf2[0..], &[_]u8{ 0x78, 0x56 }));
1299 try testing.expect(eql(u8, buf2[0..], &[_]u8{ 0x78, 0x56 }));
13001300
13011301 writeIntBig(u72, &buf9, 0x123456789abcdef024);
1302 testing.expect(eql(u8, buf9[0..], &[_]u8{ 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x24 }));
1302 try testing.expect(eql(u8, buf9[0..], &[_]u8{ 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x24 }));
13031303 writeIntLittle(u72, &buf9, 0xfedcba9876543210ec);
1304 testing.expect(eql(u8, buf9[0..], &[_]u8{ 0xec, 0x10, 0x32, 0x54, 0x76, 0x98, 0xba, 0xdc, 0xfe }));
1304 try testing.expect(eql(u8, buf9[0..], &[_]u8{ 0xec, 0x10, 0x32, 0x54, 0x76, 0x98, 0xba, 0xdc, 0xfe }));
13051305
13061306 writeIntBig(i8, &buf1, -1);
1307 testing.expect(eql(u8, buf1[0..], &[_]u8{0xff}));
1307 try testing.expect(eql(u8, buf1[0..], &[_]u8{0xff}));
13081308 writeIntLittle(i8, &buf1, -2);
1309 testing.expect(eql(u8, buf1[0..], &[_]u8{0xfe}));
1309 try testing.expect(eql(u8, buf1[0..], &[_]u8{0xfe}));
13101310
13111311 writeIntBig(i16, &buf2, -3);
1312 testing.expect(eql(u8, buf2[0..], &[_]u8{ 0xff, 0xfd }));
1312 try testing.expect(eql(u8, buf2[0..], &[_]u8{ 0xff, 0xfd }));
13131313 writeIntLittle(i16, &buf2, -4);
1314 testing.expect(eql(u8, buf2[0..], &[_]u8{ 0xfc, 0xff }));
1314 try testing.expect(eql(u8, buf2[0..], &[_]u8{ 0xfc, 0xff }));
13151315}
13161316
13171317/// Returns an iterator that iterates over the slices of `buffer` that are not
......@@ -1332,60 +1332,60 @@ pub fn tokenize(buffer: []const u8, delimiter_bytes: []const u8) TokenIterator {
13321332
13331333test "mem.tokenize" {
13341334 var it = tokenize(" abc def ghi ", " ");
1335 testing.expect(eql(u8, it.next().?, "abc"));
1336 testing.expect(eql(u8, it.next().?, "def"));
1337 testing.expect(eql(u8, it.next().?, "ghi"));
1338 testing.expect(it.next() == null);
1335 try testing.expect(eql(u8, it.next().?, "abc"));
1336 try testing.expect(eql(u8, it.next().?, "def"));
1337 try testing.expect(eql(u8, it.next().?, "ghi"));
1338 try testing.expect(it.next() == null);
13391339
13401340 it = tokenize("..\\bob", "\\");
1341 testing.expect(eql(u8, it.next().?, ".."));
1342 testing.expect(eql(u8, "..", "..\\bob"[0..it.index]));
1343 testing.expect(eql(u8, it.next().?, "bob"));
1344 testing.expect(it.next() == null);
1341 try testing.expect(eql(u8, it.next().?, ".."));
1342 try testing.expect(eql(u8, "..", "..\\bob"[0..it.index]));
1343 try testing.expect(eql(u8, it.next().?, "bob"));
1344 try testing.expect(it.next() == null);
13451345
13461346 it = tokenize("//a/b", "/");
1347 testing.expect(eql(u8, it.next().?, "a"));
1348 testing.expect(eql(u8, it.next().?, "b"));
1349 testing.expect(eql(u8, "//a/b", "//a/b"[0..it.index]));
1350 testing.expect(it.next() == null);
1347 try testing.expect(eql(u8, it.next().?, "a"));
1348 try testing.expect(eql(u8, it.next().?, "b"));
1349 try testing.expect(eql(u8, "//a/b", "//a/b"[0..it.index]));
1350 try testing.expect(it.next() == null);
13511351
13521352 it = tokenize("|", "|");
1353 testing.expect(it.next() == null);
1353 try testing.expect(it.next() == null);
13541354
13551355 it = tokenize("", "|");
1356 testing.expect(it.next() == null);
1356 try testing.expect(it.next() == null);
13571357
13581358 it = tokenize("hello", "");
1359 testing.expect(eql(u8, it.next().?, "hello"));
1360 testing.expect(it.next() == null);
1359 try testing.expect(eql(u8, it.next().?, "hello"));
1360 try testing.expect(it.next() == null);
13611361
13621362 it = tokenize("hello", " ");
1363 testing.expect(eql(u8, it.next().?, "hello"));
1364 testing.expect(it.next() == null);
1363 try testing.expect(eql(u8, it.next().?, "hello"));
1364 try testing.expect(it.next() == null);
13651365}
13661366
13671367test "mem.tokenize (multibyte)" {
13681368 var it = tokenize("a|b,c/d e", " /,|");
1369 testing.expect(eql(u8, it.next().?, "a"));
1370 testing.expect(eql(u8, it.next().?, "b"));
1371 testing.expect(eql(u8, it.next().?, "c"));
1372 testing.expect(eql(u8, it.next().?, "d"));
1373 testing.expect(eql(u8, it.next().?, "e"));
1374 testing.expect(it.next() == null);
1369 try testing.expect(eql(u8, it.next().?, "a"));
1370 try testing.expect(eql(u8, it.next().?, "b"));
1371 try testing.expect(eql(u8, it.next().?, "c"));
1372 try testing.expect(eql(u8, it.next().?, "d"));
1373 try testing.expect(eql(u8, it.next().?, "e"));
1374 try testing.expect(it.next() == null);
13751375}
13761376
13771377test "mem.tokenize (reset)" {
13781378 var it = tokenize(" abc def ghi ", " ");
1379 testing.expect(eql(u8, it.next().?, "abc"));
1380 testing.expect(eql(u8, it.next().?, "def"));
1381 testing.expect(eql(u8, it.next().?, "ghi"));
1379 try testing.expect(eql(u8, it.next().?, "abc"));
1380 try testing.expect(eql(u8, it.next().?, "def"));
1381 try testing.expect(eql(u8, it.next().?, "ghi"));
13821382
13831383 it.reset();
13841384
1385 testing.expect(eql(u8, it.next().?, "abc"));
1386 testing.expect(eql(u8, it.next().?, "def"));
1387 testing.expect(eql(u8, it.next().?, "ghi"));
1388 testing.expect(it.next() == null);
1385 try testing.expect(eql(u8, it.next().?, "abc"));
1386 try testing.expect(eql(u8, it.next().?, "def"));
1387 try testing.expect(eql(u8, it.next().?, "ghi"));
1388 try testing.expect(it.next() == null);
13891389}
13901390
13911391/// Returns an iterator that iterates over the slices of `buffer` that
......@@ -1409,34 +1409,34 @@ pub const separate = @compileError("deprecated: renamed to split (behavior remai
14091409
14101410test "mem.split" {
14111411 var it = split("abc|def||ghi", "|");
1412 testing.expect(eql(u8, it.next().?, "abc"));
1413 testing.expect(eql(u8, it.next().?, "def"));
1414 testing.expect(eql(u8, it.next().?, ""));
1415 testing.expect(eql(u8, it.next().?, "ghi"));
1416 testing.expect(it.next() == null);
1412 try testing.expect(eql(u8, it.next().?, "abc"));
1413 try testing.expect(eql(u8, it.next().?, "def"));
1414 try testing.expect(eql(u8, it.next().?, ""));
1415 try testing.expect(eql(u8, it.next().?, "ghi"));
1416 try testing.expect(it.next() == null);
14171417
14181418 it = split("", "|");
1419 testing.expect(eql(u8, it.next().?, ""));
1420 testing.expect(it.next() == null);
1419 try testing.expect(eql(u8, it.next().?, ""));
1420 try testing.expect(it.next() == null);
14211421
14221422 it = split("|", "|");
1423 testing.expect(eql(u8, it.next().?, ""));
1424 testing.expect(eql(u8, it.next().?, ""));
1425 testing.expect(it.next() == null);
1423 try testing.expect(eql(u8, it.next().?, ""));
1424 try testing.expect(eql(u8, it.next().?, ""));
1425 try testing.expect(it.next() == null);
14261426
14271427 it = split("hello", " ");
1428 testing.expect(eql(u8, it.next().?, "hello"));
1429 testing.expect(it.next() == null);
1428 try testing.expect(eql(u8, it.next().?, "hello"));
1429 try testing.expect(it.next() == null);
14301430}
14311431
14321432test "mem.split (multibyte)" {
14331433 var it = split("a, b ,, c, d, e", ", ");
1434 testing.expect(eql(u8, it.next().?, "a"));
1435 testing.expect(eql(u8, it.next().?, "b ,"));
1436 testing.expect(eql(u8, it.next().?, "c"));
1437 testing.expect(eql(u8, it.next().?, "d"));
1438 testing.expect(eql(u8, it.next().?, "e"));
1439 testing.expect(it.next() == null);
1434 try testing.expect(eql(u8, it.next().?, "a"));
1435 try testing.expect(eql(u8, it.next().?, "b ,"));
1436 try testing.expect(eql(u8, it.next().?, "c"));
1437 try testing.expect(eql(u8, it.next().?, "d"));
1438 try testing.expect(eql(u8, it.next().?, "e"));
1439 try testing.expect(it.next() == null);
14401440}
14411441
14421442pub fn startsWith(comptime T: type, haystack: []const T, needle: []const T) bool {
......@@ -1444,8 +1444,8 @@ pub fn startsWith(comptime T: type, haystack: []const T, needle: []const T) bool
14441444}
14451445
14461446test "mem.startsWith" {
1447 testing.expect(startsWith(u8, "Bob", "Bo"));
1448 testing.expect(!startsWith(u8, "Needle in haystack", "haystack"));
1447 try testing.expect(startsWith(u8, "Bob", "Bo"));
1448 try testing.expect(!startsWith(u8, "Needle in haystack", "haystack"));
14491449}
14501450
14511451pub fn endsWith(comptime T: type, haystack: []const T, needle: []const T) bool {
......@@ -1453,8 +1453,8 @@ pub fn endsWith(comptime T: type, haystack: []const T, needle: []const T) bool {
14531453}
14541454
14551455test "mem.endsWith" {
1456 testing.expect(endsWith(u8, "Needle in haystack", "haystack"));
1457 testing.expect(!endsWith(u8, "Bob", "Bo"));
1456 try testing.expect(endsWith(u8, "Needle in haystack", "haystack"));
1457 try testing.expect(!endsWith(u8, "Bob", "Bo"));
14581458}
14591459
14601460pub const TokenIterator = struct {
......@@ -1572,22 +1572,22 @@ test "mem.join" {
15721572 {
15731573 const str = try join(testing.allocator, ",", &[_][]const u8{});
15741574 defer testing.allocator.free(str);
1575 testing.expect(eql(u8, str, ""));
1575 try testing.expect(eql(u8, str, ""));
15761576 }
15771577 {
15781578 const str = try join(testing.allocator, ",", &[_][]const u8{ "a", "b", "c" });
15791579 defer testing.allocator.free(str);
1580 testing.expect(eql(u8, str, "a,b,c"));
1580 try testing.expect(eql(u8, str, "a,b,c"));
15811581 }
15821582 {
15831583 const str = try join(testing.allocator, ",", &[_][]const u8{"a"});
15841584 defer testing.allocator.free(str);
1585 testing.expect(eql(u8, str, "a"));
1585 try testing.expect(eql(u8, str, "a"));
15861586 }
15871587 {
15881588 const str = try join(testing.allocator, ",", &[_][]const u8{ "a", "", "b", "", "c" });
15891589 defer testing.allocator.free(str);
1590 testing.expect(eql(u8, str, "a,,b,,c"));
1590 try testing.expect(eql(u8, str, "a,,b,,c"));
15911591 }
15921592}
15931593
......@@ -1595,26 +1595,26 @@ test "mem.joinZ" {
15951595 {
15961596 const str = try joinZ(testing.allocator, ",", &[_][]const u8{});
15971597 defer testing.allocator.free(str);
1598 testing.expect(eql(u8, str, ""));
1599 testing.expectEqual(str[str.len], 0);
1598 try testing.expect(eql(u8, str, ""));
1599 try testing.expectEqual(str[str.len], 0);
16001600 }
16011601 {
16021602 const str = try joinZ(testing.allocator, ",", &[_][]const u8{ "a", "b", "c" });
16031603 defer testing.allocator.free(str);
1604 testing.expect(eql(u8, str, "a,b,c"));
1605 testing.expectEqual(str[str.len], 0);
1604 try testing.expect(eql(u8, str, "a,b,c"));
1605 try testing.expectEqual(str[str.len], 0);
16061606 }
16071607 {
16081608 const str = try joinZ(testing.allocator, ",", &[_][]const u8{"a"});
16091609 defer testing.allocator.free(str);
1610 testing.expect(eql(u8, str, "a"));
1611 testing.expectEqual(str[str.len], 0);
1610 try testing.expect(eql(u8, str, "a"));
1611 try testing.expectEqual(str[str.len], 0);
16121612 }
16131613 {
16141614 const str = try joinZ(testing.allocator, ",", &[_][]const u8{ "a", "", "b", "", "c" });
16151615 defer testing.allocator.free(str);
1616 testing.expect(eql(u8, str, "a,,b,,c"));
1617 testing.expectEqual(str[str.len], 0);
1616 try testing.expect(eql(u8, str, "a,,b,,c"));
1617 try testing.expectEqual(str[str.len], 0);
16181618 }
16191619}
16201620
......@@ -1647,7 +1647,7 @@ test "concat" {
16471647 {
16481648 const str = try concat(testing.allocator, u8, &[_][]const u8{ "abc", "def", "ghi" });
16491649 defer testing.allocator.free(str);
1650 testing.expect(eql(u8, str, "abcdefghi"));
1650 try testing.expect(eql(u8, str, "abcdefghi"));
16511651 }
16521652 {
16531653 const str = try concat(testing.allocator, u32, &[_][]const u32{
......@@ -1657,21 +1657,21 @@ test "concat" {
16571657 &[_]u32{5},
16581658 });
16591659 defer testing.allocator.free(str);
1660 testing.expect(eql(u32, str, &[_]u32{ 0, 1, 2, 3, 4, 5 }));
1660 try testing.expect(eql(u32, str, &[_]u32{ 0, 1, 2, 3, 4, 5 }));
16611661 }
16621662}
16631663
16641664test "testStringEquality" {
1665 testing.expect(eql(u8, "abcd", "abcd"));
1666 testing.expect(!eql(u8, "abcdef", "abZdef"));
1667 testing.expect(!eql(u8, "abcdefg", "abcdef"));
1665 try testing.expect(eql(u8, "abcd", "abcd"));
1666 try testing.expect(!eql(u8, "abcdef", "abZdef"));
1667 try testing.expect(!eql(u8, "abcdefg", "abcdef"));
16681668}
16691669
16701670test "testReadInt" {
1671 testReadIntImpl();
1672 comptime testReadIntImpl();
1671 try testReadIntImpl();
1672 comptime try testReadIntImpl();
16731673}
1674fn testReadIntImpl() void {
1674fn testReadIntImpl() !void {
16751675 {
16761676 const bytes = [_]u8{
16771677 0x12,
......@@ -1679,12 +1679,12 @@ fn testReadIntImpl() void {
16791679 0x56,
16801680 0x78,
16811681 };
1682 testing.expect(readInt(u32, &bytes, Endian.Big) == 0x12345678);
1683 testing.expect(readIntBig(u32, &bytes) == 0x12345678);
1684 testing.expect(readIntBig(i32, &bytes) == 0x12345678);
1685 testing.expect(readInt(u32, &bytes, Endian.Little) == 0x78563412);
1686 testing.expect(readIntLittle(u32, &bytes) == 0x78563412);
1687 testing.expect(readIntLittle(i32, &bytes) == 0x78563412);
1682 try testing.expect(readInt(u32, &bytes, Endian.Big) == 0x12345678);
1683 try testing.expect(readIntBig(u32, &bytes) == 0x12345678);
1684 try testing.expect(readIntBig(i32, &bytes) == 0x12345678);
1685 try testing.expect(readInt(u32, &bytes, Endian.Little) == 0x78563412);
1686 try testing.expect(readIntLittle(u32, &bytes) == 0x78563412);
1687 try testing.expect(readIntLittle(i32, &bytes) == 0x78563412);
16881688 }
16891689 {
16901690 const buf = [_]u8{
......@@ -1694,7 +1694,7 @@ fn testReadIntImpl() void {
16941694 0x34,
16951695 };
16961696 const answer = readInt(u32, &buf, Endian.Big);
1697 testing.expect(answer == 0x00001234);
1697 try testing.expect(answer == 0x00001234);
16981698 }
16991699 {
17001700 const buf = [_]u8{
......@@ -1704,41 +1704,41 @@ fn testReadIntImpl() void {
17041704 0x00,
17051705 };
17061706 const answer = readInt(u32, &buf, Endian.Little);
1707 testing.expect(answer == 0x00003412);
1707 try testing.expect(answer == 0x00003412);
17081708 }
17091709 {
17101710 const bytes = [_]u8{
17111711 0xff,
17121712 0xfe,
17131713 };
1714 testing.expect(readIntBig(u16, &bytes) == 0xfffe);
1715 testing.expect(readIntBig(i16, &bytes) == -0x0002);
1716 testing.expect(readIntLittle(u16, &bytes) == 0xfeff);
1717 testing.expect(readIntLittle(i16, &bytes) == -0x0101);
1714 try testing.expect(readIntBig(u16, &bytes) == 0xfffe);
1715 try testing.expect(readIntBig(i16, &bytes) == -0x0002);
1716 try testing.expect(readIntLittle(u16, &bytes) == 0xfeff);
1717 try testing.expect(readIntLittle(i16, &bytes) == -0x0101);
17181718 }
17191719}
17201720
17211721test "writeIntSlice" {
1722 testWriteIntImpl();
1723 comptime testWriteIntImpl();
1722 try testWriteIntImpl();
1723 comptime try testWriteIntImpl();
17241724}
1725fn testWriteIntImpl() void {
1725fn testWriteIntImpl() !void {
17261726 var bytes: [8]u8 = undefined;
17271727
17281728 writeIntSlice(u0, bytes[0..], 0, Endian.Big);
1729 testing.expect(eql(u8, &bytes, &[_]u8{
1729 try testing.expect(eql(u8, &bytes, &[_]u8{
17301730 0x00, 0x00, 0x00, 0x00,
17311731 0x00, 0x00, 0x00, 0x00,
17321732 }));
17331733
17341734 writeIntSlice(u0, bytes[0..], 0, Endian.Little);
1735 testing.expect(eql(u8, &bytes, &[_]u8{
1735 try testing.expect(eql(u8, &bytes, &[_]u8{
17361736 0x00, 0x00, 0x00, 0x00,
17371737 0x00, 0x00, 0x00, 0x00,
17381738 }));
17391739
17401740 writeIntSlice(u64, bytes[0..], 0x12345678CAFEBABE, Endian.Big);
1741 testing.expect(eql(u8, &bytes, &[_]u8{
1741 try testing.expect(eql(u8, &bytes, &[_]u8{
17421742 0x12,
17431743 0x34,
17441744 0x56,
......@@ -1750,7 +1750,7 @@ fn testWriteIntImpl() void {
17501750 }));
17511751
17521752 writeIntSlice(u64, bytes[0..], 0xBEBAFECA78563412, Endian.Little);
1753 testing.expect(eql(u8, &bytes, &[_]u8{
1753 try testing.expect(eql(u8, &bytes, &[_]u8{
17541754 0x12,
17551755 0x34,
17561756 0x56,
......@@ -1762,7 +1762,7 @@ fn testWriteIntImpl() void {
17621762 }));
17631763
17641764 writeIntSlice(u32, bytes[0..], 0x12345678, Endian.Big);
1765 testing.expect(eql(u8, &bytes, &[_]u8{
1765 try testing.expect(eql(u8, &bytes, &[_]u8{
17661766 0x00,
17671767 0x00,
17681768 0x00,
......@@ -1774,7 +1774,7 @@ fn testWriteIntImpl() void {
17741774 }));
17751775
17761776 writeIntSlice(u32, bytes[0..], 0x78563412, Endian.Little);
1777 testing.expect(eql(u8, &bytes, &[_]u8{
1777 try testing.expect(eql(u8, &bytes, &[_]u8{
17781778 0x12,
17791779 0x34,
17801780 0x56,
......@@ -1786,7 +1786,7 @@ fn testWriteIntImpl() void {
17861786 }));
17871787
17881788 writeIntSlice(u16, bytes[0..], 0x1234, Endian.Big);
1789 testing.expect(eql(u8, &bytes, &[_]u8{
1789 try testing.expect(eql(u8, &bytes, &[_]u8{
17901790 0x00,
17911791 0x00,
17921792 0x00,
......@@ -1798,7 +1798,7 @@ fn testWriteIntImpl() void {
17981798 }));
17991799
18001800 writeIntSlice(u16, bytes[0..], 0x1234, Endian.Little);
1801 testing.expect(eql(u8, &bytes, &[_]u8{
1801 try testing.expect(eql(u8, &bytes, &[_]u8{
18021802 0x34,
18031803 0x12,
18041804 0x00,
......@@ -1821,7 +1821,7 @@ pub fn min(comptime T: type, slice: []const T) T {
18211821}
18221822
18231823test "mem.min" {
1824 testing.expect(min(u8, "abcdefg") == 'a');
1824 try testing.expect(min(u8, "abcdefg") == 'a');
18251825}
18261826
18271827/// Returns the largest number in a slice. O(n).
......@@ -1835,7 +1835,7 @@ pub fn max(comptime T: type, slice: []const T) T {
18351835}
18361836
18371837test "mem.max" {
1838 testing.expect(max(u8, "abcdefg") == 'g');
1838 try testing.expect(max(u8, "abcdefg") == 'g');
18391839}
18401840
18411841pub fn swap(comptime T: type, a: *T, b: *T) void {
......@@ -1857,7 +1857,7 @@ test "reverse" {
18571857 var arr = [_]i32{ 5, 3, 1, 2, 4 };
18581858 reverse(i32, arr[0..]);
18591859
1860 testing.expect(eql(i32, &arr, &[_]i32{ 4, 2, 1, 3, 5 }));
1860 try testing.expect(eql(i32, &arr, &[_]i32{ 4, 2, 1, 3, 5 }));
18611861}
18621862
18631863/// In-place rotation of the values in an array ([0 1 2 3] becomes [1 2 3 0] if we rotate by 1)
......@@ -1872,7 +1872,7 @@ test "rotate" {
18721872 var arr = [_]i32{ 5, 3, 1, 2, 4 };
18731873 rotate(i32, arr[0..], 2);
18741874
1875 testing.expect(eql(i32, &arr, &[_]i32{ 1, 2, 4, 5, 3 }));
1875 try testing.expect(eql(i32, &arr, &[_]i32{ 1, 2, 4, 5, 3 }));
18761876}
18771877
18781878/// Replace needle with replacement as many times as possible, writing to an output buffer which is assumed to be of
......@@ -1905,31 +1905,31 @@ test "replace" {
19051905 var output: [29]u8 = undefined;
19061906 var replacements = replace(u8, "All your base are belong to us", "base", "Zig", output[0..]);
19071907 var expected: []const u8 = "All your Zig are belong to us";
1908 testing.expect(replacements == 1);
1909 testing.expectEqualStrings(expected, output[0..expected.len]);
1908 try testing.expect(replacements == 1);
1909 try testing.expectEqualStrings(expected, output[0..expected.len]);
19101910
19111911 replacements = replace(u8, "Favor reading code over writing code.", "code", "", output[0..]);
19121912 expected = "Favor reading over writing .";
1913 testing.expect(replacements == 2);
1914 testing.expectEqualStrings(expected, output[0..expected.len]);
1913 try testing.expect(replacements == 2);
1914 try testing.expectEqualStrings(expected, output[0..expected.len]);
19151915
19161916 // Empty needle is not allowed but input may be empty.
19171917 replacements = replace(u8, "", "x", "y", output[0..0]);
19181918 expected = "";
1919 testing.expect(replacements == 0);
1920 testing.expectEqualStrings(expected, output[0..expected.len]);
1919 try testing.expect(replacements == 0);
1920 try testing.expectEqualStrings(expected, output[0..expected.len]);
19211921
19221922 // Adjacent replacements.
19231923
19241924 replacements = replace(u8, "\\n\\n", "\\n", "\n", output[0..]);
19251925 expected = "\n\n";
1926 testing.expect(replacements == 2);
1927 testing.expectEqualStrings(expected, output[0..expected.len]);
1926 try testing.expect(replacements == 2);
1927 try testing.expectEqualStrings(expected, output[0..expected.len]);
19281928
19291929 replacements = replace(u8, "abbba", "b", "cd", output[0..]);
19301930 expected = "acdcdcda";
1931 testing.expect(replacements == 3);
1932 testing.expectEqualStrings(expected, output[0..expected.len]);
1931 try testing.expect(replacements == 3);
1932 try testing.expectEqualStrings(expected, output[0..expected.len]);
19331933}
19341934
19351935/// Calculate the size needed in an output buffer to perform a replacement.
......@@ -1953,16 +1953,16 @@ pub fn replacementSize(comptime T: type, input: []const T, needle: []const T, re
19531953}
19541954
19551955test "replacementSize" {
1956 testing.expect(replacementSize(u8, "All your base are belong to us", "base", "Zig") == 29);
1957 testing.expect(replacementSize(u8, "Favor reading code over writing code.", "code", "") == 29);
1958 testing.expect(replacementSize(u8, "Only one obvious way to do things.", "things.", "things in Zig.") == 41);
1956 try testing.expect(replacementSize(u8, "All your base are belong to us", "base", "Zig") == 29);
1957 try testing.expect(replacementSize(u8, "Favor reading code over writing code.", "code", "") == 29);
1958 try testing.expect(replacementSize(u8, "Only one obvious way to do things.", "things.", "things in Zig.") == 41);
19591959
19601960 // Empty needle is not allowed but input may be empty.
1961 testing.expect(replacementSize(u8, "", "x", "y") == 0);
1961 try testing.expect(replacementSize(u8, "", "x", "y") == 0);
19621962
19631963 // Adjacent replacements.
1964 testing.expect(replacementSize(u8, "\\n\\n", "\\n", "\n") == 2);
1965 testing.expect(replacementSize(u8, "abbba", "b", "cd") == 8);
1964 try testing.expect(replacementSize(u8, "\\n\\n", "\\n", "\n") == 2);
1965 try testing.expect(replacementSize(u8, "abbba", "b", "cd") == 8);
19661966}
19671967
19681968/// Perform a replacement on an allocated buffer of pre-determined size. Caller must free returned memory.
......@@ -1977,11 +1977,11 @@ test "replaceOwned" {
19771977
19781978 const base_replace = replaceOwned(u8, allocator, "All your base are belong to us", "base", "Zig") catch unreachable;
19791979 defer allocator.free(base_replace);
1980 testing.expect(eql(u8, base_replace, "All your Zig are belong to us"));
1980 try testing.expect(eql(u8, base_replace, "All your Zig are belong to us"));
19811981
19821982 const zen_replace = replaceOwned(u8, allocator, "Favor reading code over writing code.", " code", "") catch unreachable;
19831983 defer allocator.free(zen_replace);
1984 testing.expect(eql(u8, zen_replace, "Favor reading over writing."));
1984 try testing.expect(eql(u8, zen_replace, "Favor reading over writing."));
19851985}
19861986
19871987/// Converts a little-endian integer to host endianness.
......@@ -2069,12 +2069,12 @@ test "asBytes" {
20692069 .Little => "\xEF\xBE\xAD\xDE",
20702070 };
20712071
2072 testing.expect(eql(u8, asBytes(&deadbeef), deadbeef_bytes));
2072 try testing.expect(eql(u8, asBytes(&deadbeef), deadbeef_bytes));
20732073
20742074 var codeface = @as(u32, 0xC0DEFACE);
20752075 for (asBytes(&codeface).*) |*b|
20762076 b.* = 0;
2077 testing.expect(codeface == 0);
2077 try testing.expect(codeface == 0);
20782078
20792079 const S = packed struct {
20802080 a: u8,
......@@ -2089,11 +2089,11 @@ test "asBytes" {
20892089 .c = 0xDE,
20902090 .d = 0xA1,
20912091 };
2092 testing.expect(eql(u8, asBytes(&inst), "\xBE\xEF\xDE\xA1"));
2092 try testing.expect(eql(u8, asBytes(&inst), "\xBE\xEF\xDE\xA1"));
20932093
20942094 const ZST = struct {};
20952095 const zero = ZST{};
2096 testing.expect(eql(u8, asBytes(&zero), ""));
2096 try testing.expect(eql(u8, asBytes(&zero), ""));
20972097}
20982098
20992099test "asBytes preserves pointer attributes" {
......@@ -2104,10 +2104,10 @@ test "asBytes preserves pointer attributes" {
21042104 const in = @typeInfo(@TypeOf(inPtr)).Pointer;
21052105 const out = @typeInfo(@TypeOf(outSlice)).Pointer;
21062106
2107 testing.expectEqual(in.is_const, out.is_const);
2108 testing.expectEqual(in.is_volatile, out.is_volatile);
2109 testing.expectEqual(in.is_allowzero, out.is_allowzero);
2110 testing.expectEqual(in.alignment, out.alignment);
2107 try testing.expectEqual(in.is_const, out.is_const);
2108 try testing.expectEqual(in.is_volatile, out.is_volatile);
2109 try testing.expectEqual(in.is_allowzero, out.is_allowzero);
2110 try testing.expectEqual(in.alignment, out.alignment);
21112111}
21122112
21132113/// Given any value, returns a copy of its bytes in an array.
......@@ -2118,14 +2118,14 @@ pub fn toBytes(value: anytype) [@sizeOf(@TypeOf(value))]u8 {
21182118test "toBytes" {
21192119 var my_bytes = toBytes(@as(u32, 0x12345678));
21202120 switch (native_endian) {
2121 .Big => testing.expect(eql(u8, &my_bytes, "\x12\x34\x56\x78")),
2122 .Little => testing.expect(eql(u8, &my_bytes, "\x78\x56\x34\x12")),
2121 .Big => try testing.expect(eql(u8, &my_bytes, "\x12\x34\x56\x78")),
2122 .Little => try testing.expect(eql(u8, &my_bytes, "\x78\x56\x34\x12")),
21232123 }
21242124
21252125 my_bytes[0] = '\x99';
21262126 switch (native_endian) {
2127 .Big => testing.expect(eql(u8, &my_bytes, "\x99\x34\x56\x78")),
2128 .Little => testing.expect(eql(u8, &my_bytes, "\x99\x56\x34\x12")),
2127 .Big => try testing.expect(eql(u8, &my_bytes, "\x99\x34\x56\x78")),
2128 .Little => try testing.expect(eql(u8, &my_bytes, "\x99\x56\x34\x12")),
21292129 }
21302130}
21312131
......@@ -2155,17 +2155,17 @@ test "bytesAsValue" {
21552155 .Little => "\xEF\xBE\xAD\xDE",
21562156 };
21572157
2158 testing.expect(deadbeef == bytesAsValue(u32, deadbeef_bytes).*);
2158 try testing.expect(deadbeef == bytesAsValue(u32, deadbeef_bytes).*);
21592159
21602160 var codeface_bytes: [4]u8 = switch (native_endian) {
21612161 .Big => "\xC0\xDE\xFA\xCE",
21622162 .Little => "\xCE\xFA\xDE\xC0",
21632163 }.*;
21642164 var codeface = bytesAsValue(u32, &codeface_bytes);
2165 testing.expect(codeface.* == 0xC0DEFACE);
2165 try testing.expect(codeface.* == 0xC0DEFACE);
21662166 codeface.* = 0;
21672167 for (codeface_bytes) |b|
2168 testing.expect(b == 0);
2168 try testing.expect(b == 0);
21692169
21702170 const S = packed struct {
21712171 a: u8,
......@@ -2182,7 +2182,7 @@ test "bytesAsValue" {
21822182 };
21832183 const inst_bytes = "\xBE\xEF\xDE\xA1";
21842184 const inst2 = bytesAsValue(S, inst_bytes);
2185 testing.expect(meta.eql(inst, inst2.*));
2185 try testing.expect(meta.eql(inst, inst2.*));
21862186}
21872187
21882188test "bytesAsValue preserves pointer attributes" {
......@@ -2193,10 +2193,10 @@ test "bytesAsValue preserves pointer attributes" {
21932193 const in = @typeInfo(@TypeOf(inSlice)).Pointer;
21942194 const out = @typeInfo(@TypeOf(outPtr)).Pointer;
21952195
2196 testing.expectEqual(in.is_const, out.is_const);
2197 testing.expectEqual(in.is_volatile, out.is_volatile);
2198 testing.expectEqual(in.is_allowzero, out.is_allowzero);
2199 testing.expectEqual(in.alignment, out.alignment);
2196 try testing.expectEqual(in.is_const, out.is_const);
2197 try testing.expectEqual(in.is_volatile, out.is_volatile);
2198 try testing.expectEqual(in.is_allowzero, out.is_allowzero);
2199 try testing.expectEqual(in.alignment, out.alignment);
22002200}
22012201
22022202/// Given a pointer to an array of bytes, returns a value of the specified type backed by a
......@@ -2211,7 +2211,7 @@ test "bytesToValue" {
22112211 };
22122212
22132213 const deadbeef = bytesToValue(u32, deadbeef_bytes);
2214 testing.expect(deadbeef == @as(u32, 0xDEADBEEF));
2214 try testing.expect(deadbeef == @as(u32, 0xDEADBEEF));
22152215}
22162216
22172217fn BytesAsSliceReturnType(comptime T: type, comptime bytesType: type) type {
......@@ -2244,17 +2244,17 @@ test "bytesAsSlice" {
22442244 {
22452245 const bytes = [_]u8{ 0xDE, 0xAD, 0xBE, 0xEF };
22462246 const slice = bytesAsSlice(u16, bytes[0..]);
2247 testing.expect(slice.len == 2);
2248 testing.expect(bigToNative(u16, slice[0]) == 0xDEAD);
2249 testing.expect(bigToNative(u16, slice[1]) == 0xBEEF);
2247 try testing.expect(slice.len == 2);
2248 try testing.expect(bigToNative(u16, slice[0]) == 0xDEAD);
2249 try testing.expect(bigToNative(u16, slice[1]) == 0xBEEF);
22502250 }
22512251 {
22522252 const bytes = [_]u8{ 0xDE, 0xAD, 0xBE, 0xEF };
22532253 var runtime_zero: usize = 0;
22542254 const slice = bytesAsSlice(u16, bytes[runtime_zero..]);
2255 testing.expect(slice.len == 2);
2256 testing.expect(bigToNative(u16, slice[0]) == 0xDEAD);
2257 testing.expect(bigToNative(u16, slice[1]) == 0xBEEF);
2255 try testing.expect(slice.len == 2);
2256 try testing.expect(bigToNative(u16, slice[0]) == 0xDEAD);
2257 try testing.expect(bigToNative(u16, slice[1]) == 0xBEEF);
22582258 }
22592259}
22602260
......@@ -2262,13 +2262,13 @@ test "bytesAsSlice keeps pointer alignment" {
22622262 {
22632263 var bytes = [_]u8{ 0x01, 0x02, 0x03, 0x04 };
22642264 const numbers = bytesAsSlice(u32, bytes[0..]);
2265 comptime testing.expect(@TypeOf(numbers) == []align(@alignOf(@TypeOf(bytes))) u32);
2265 comptime try testing.expect(@TypeOf(numbers) == []align(@alignOf(@TypeOf(bytes))) u32);
22662266 }
22672267 {
22682268 var bytes = [_]u8{ 0x01, 0x02, 0x03, 0x04 };
22692269 var runtime_zero: usize = 0;
22702270 const numbers = bytesAsSlice(u32, bytes[runtime_zero..]);
2271 comptime testing.expect(@TypeOf(numbers) == []align(@alignOf(@TypeOf(bytes))) u32);
2271 comptime try testing.expect(@TypeOf(numbers) == []align(@alignOf(@TypeOf(bytes))) u32);
22722272 }
22732273}
22742274
......@@ -2279,7 +2279,7 @@ test "bytesAsSlice on a packed struct" {
22792279
22802280 var b = [1]u8{9};
22812281 var f = bytesAsSlice(F, &b);
2282 testing.expect(f[0].a == 9);
2282 try testing.expect(f[0].a == 9);
22832283}
22842284
22852285test "bytesAsSlice with specified alignment" {
......@@ -2290,7 +2290,7 @@ test "bytesAsSlice with specified alignment" {
22902290 0x33,
22912291 };
22922292 const slice: []u32 = std.mem.bytesAsSlice(u32, bytes[0..]);
2293 testing.expect(slice[0] == 0x33333333);
2293 try testing.expect(slice[0] == 0x33333333);
22942294}
22952295
22962296test "bytesAsSlice preserves pointer attributes" {
......@@ -2301,10 +2301,10 @@ test "bytesAsSlice preserves pointer attributes" {
23012301 const in = @typeInfo(@TypeOf(inSlice)).Pointer;
23022302 const out = @typeInfo(@TypeOf(outSlice)).Pointer;
23032303
2304 testing.expectEqual(in.is_const, out.is_const);
2305 testing.expectEqual(in.is_volatile, out.is_volatile);
2306 testing.expectEqual(in.is_allowzero, out.is_allowzero);
2307 testing.expectEqual(in.alignment, out.alignment);
2304 try testing.expectEqual(in.is_const, out.is_const);
2305 try testing.expectEqual(in.is_volatile, out.is_volatile);
2306 try testing.expectEqual(in.is_allowzero, out.is_allowzero);
2307 try testing.expectEqual(in.alignment, out.alignment);
23082308}
23092309
23102310fn SliceAsBytesReturnType(comptime sliceType: type) type {
......@@ -2333,8 +2333,8 @@ pub fn sliceAsBytes(slice: anytype) SliceAsBytesReturnType(@TypeOf(slice)) {
23332333test "sliceAsBytes" {
23342334 const bytes = [_]u16{ 0xDEAD, 0xBEEF };
23352335 const slice = sliceAsBytes(bytes[0..]);
2336 testing.expect(slice.len == 4);
2337 testing.expect(eql(u8, slice, switch (native_endian) {
2336 try testing.expect(slice.len == 4);
2337 try testing.expect(eql(u8, slice, switch (native_endian) {
23382338 .Big => "\xDE\xAD\xBE\xEF",
23392339 .Little => "\xAD\xDE\xEF\xBE",
23402340 }));
......@@ -2343,7 +2343,7 @@ test "sliceAsBytes" {
23432343test "sliceAsBytes with sentinel slice" {
23442344 const empty_string: [:0]const u8 = "";
23452345 const bytes = sliceAsBytes(empty_string);
2346 testing.expect(bytes.len == 0);
2346 try testing.expect(bytes.len == 0);
23472347}
23482348
23492349test "sliceAsBytes packed struct at runtime and comptime" {
......@@ -2352,49 +2352,49 @@ test "sliceAsBytes packed struct at runtime and comptime" {
23522352 b: u4,
23532353 };
23542354 const S = struct {
2355 fn doTheTest() void {
2355 fn doTheTest() !void {
23562356 var foo: Foo = undefined;
23572357 var slice = sliceAsBytes(@as(*[1]Foo, &foo)[0..1]);
23582358 slice[0] = 0x13;
23592359 switch (native_endian) {
23602360 .Big => {
2361 testing.expect(foo.a == 0x1);
2362 testing.expect(foo.b == 0x3);
2361 try testing.expect(foo.a == 0x1);
2362 try testing.expect(foo.b == 0x3);
23632363 },
23642364 .Little => {
2365 testing.expect(foo.a == 0x3);
2366 testing.expect(foo.b == 0x1);
2365 try testing.expect(foo.a == 0x3);
2366 try testing.expect(foo.b == 0x1);
23672367 },
23682368 }
23692369 }
23702370 };
2371 S.doTheTest();
2372 comptime S.doTheTest();
2371 try S.doTheTest();
2372 comptime try S.doTheTest();
23732373}
23742374
23752375test "sliceAsBytes and bytesAsSlice back" {
2376 testing.expect(@sizeOf(i32) == 4);
2376 try testing.expect(@sizeOf(i32) == 4);
23772377
23782378 var big_thing_array = [_]i32{ 1, 2, 3, 4 };
23792379 const big_thing_slice: []i32 = big_thing_array[0..];
23802380
23812381 const bytes = sliceAsBytes(big_thing_slice);
2382 testing.expect(bytes.len == 4 * 4);
2382 try testing.expect(bytes.len == 4 * 4);
23832383
23842384 bytes[4] = 0;
23852385 bytes[5] = 0;
23862386 bytes[6] = 0;
23872387 bytes[7] = 0;
2388 testing.expect(big_thing_slice[1] == 0);
2388 try testing.expect(big_thing_slice[1] == 0);
23892389
23902390 const big_thing_again = bytesAsSlice(i32, bytes);
2391 testing.expect(big_thing_again[2] == 3);
2391 try testing.expect(big_thing_again[2] == 3);
23922392
23932393 big_thing_again[2] = -1;
2394 testing.expect(bytes[8] == math.maxInt(u8));
2395 testing.expect(bytes[9] == math.maxInt(u8));
2396 testing.expect(bytes[10] == math.maxInt(u8));
2397 testing.expect(bytes[11] == math.maxInt(u8));
2394 try testing.expect(bytes[8] == math.maxInt(u8));
2395 try testing.expect(bytes[9] == math.maxInt(u8));
2396 try testing.expect(bytes[10] == math.maxInt(u8));
2397 try testing.expect(bytes[11] == math.maxInt(u8));
23982398}
23992399
24002400test "sliceAsBytes preserves pointer attributes" {
......@@ -2405,10 +2405,10 @@ test "sliceAsBytes preserves pointer attributes" {
24052405 const in = @typeInfo(@TypeOf(inSlice)).Pointer;
24062406 const out = @typeInfo(@TypeOf(outSlice)).Pointer;
24072407
2408 testing.expectEqual(in.is_const, out.is_const);
2409 testing.expectEqual(in.is_volatile, out.is_volatile);
2410 testing.expectEqual(in.is_allowzero, out.is_allowzero);
2411 testing.expectEqual(in.alignment, out.alignment);
2408 try testing.expectEqual(in.is_const, out.is_const);
2409 try testing.expectEqual(in.is_volatile, out.is_volatile);
2410 try testing.expectEqual(in.is_allowzero, out.is_allowzero);
2411 try testing.expectEqual(in.alignment, out.alignment);
24122412}
24132413
24142414/// Round an address up to the nearest aligned address
......@@ -2435,18 +2435,18 @@ pub fn doNotOptimizeAway(val: anytype) void {
24352435}
24362436
24372437test "alignForward" {
2438 testing.expect(alignForward(1, 1) == 1);
2439 testing.expect(alignForward(2, 1) == 2);
2440 testing.expect(alignForward(1, 2) == 2);
2441 testing.expect(alignForward(2, 2) == 2);
2442 testing.expect(alignForward(3, 2) == 4);
2443 testing.expect(alignForward(4, 2) == 4);
2444 testing.expect(alignForward(7, 8) == 8);
2445 testing.expect(alignForward(8, 8) == 8);
2446 testing.expect(alignForward(9, 8) == 16);
2447 testing.expect(alignForward(15, 8) == 16);
2448 testing.expect(alignForward(16, 8) == 16);
2449 testing.expect(alignForward(17, 8) == 24);
2438 try testing.expect(alignForward(1, 1) == 1);
2439 try testing.expect(alignForward(2, 1) == 2);
2440 try testing.expect(alignForward(1, 2) == 2);
2441 try testing.expect(alignForward(2, 2) == 2);
2442 try testing.expect(alignForward(3, 2) == 4);
2443 try testing.expect(alignForward(4, 2) == 4);
2444 try testing.expect(alignForward(7, 8) == 8);
2445 try testing.expect(alignForward(8, 8) == 8);
2446 try testing.expect(alignForward(9, 8) == 16);
2447 try testing.expect(alignForward(15, 8) == 16);
2448 try testing.expect(alignForward(16, 8) == 16);
2449 try testing.expect(alignForward(17, 8) == 24);
24502450}
24512451
24522452/// Round an address up to the previous aligned address
......@@ -2498,19 +2498,19 @@ pub fn isAlignedGeneric(comptime T: type, addr: T, alignment: T) bool {
24982498}
24992499
25002500test "isAligned" {
2501 testing.expect(isAligned(0, 4));
2502 testing.expect(isAligned(1, 1));
2503 testing.expect(isAligned(2, 1));
2504 testing.expect(isAligned(2, 2));
2505 testing.expect(!isAligned(2, 4));
2506 testing.expect(isAligned(3, 1));
2507 testing.expect(!isAligned(3, 2));
2508 testing.expect(!isAligned(3, 4));
2509 testing.expect(isAligned(4, 4));
2510 testing.expect(isAligned(4, 2));
2511 testing.expect(isAligned(4, 1));
2512 testing.expect(!isAligned(4, 8));
2513 testing.expect(!isAligned(4, 16));
2501 try testing.expect(isAligned(0, 4));
2502 try testing.expect(isAligned(1, 1));
2503 try testing.expect(isAligned(2, 1));
2504 try testing.expect(isAligned(2, 2));
2505 try testing.expect(!isAligned(2, 4));
2506 try testing.expect(isAligned(3, 1));
2507 try testing.expect(!isAligned(3, 2));
2508 try testing.expect(!isAligned(3, 4));
2509 try testing.expect(isAligned(4, 4));
2510 try testing.expect(isAligned(4, 2));
2511 try testing.expect(isAligned(4, 1));
2512 try testing.expect(!isAligned(4, 8));
2513 try testing.expect(!isAligned(4, 16));
25142514}
25152515
25162516test "freeing empty string with null-terminated sentinel" {
lib/std/meta.zig+188-188
......@@ -47,16 +47,16 @@ test "std.meta.tagName" {
4747 var u2a = U2{ .C = 0 };
4848 var u2b = U2{ .D = 0 };
4949
50 testing.expect(mem.eql(u8, tagName(E1.A), "A"));
51 testing.expect(mem.eql(u8, tagName(E1.B), "B"));
52 testing.expect(mem.eql(u8, tagName(E2.C), "C"));
53 testing.expect(mem.eql(u8, tagName(E2.D), "D"));
54 testing.expect(mem.eql(u8, tagName(error.E), "E"));
55 testing.expect(mem.eql(u8, tagName(error.F), "F"));
56 testing.expect(mem.eql(u8, tagName(u1g), "G"));
57 testing.expect(mem.eql(u8, tagName(u1h), "H"));
58 testing.expect(mem.eql(u8, tagName(u2a), "C"));
59 testing.expect(mem.eql(u8, tagName(u2b), "D"));
50 try testing.expect(mem.eql(u8, tagName(E1.A), "A"));
51 try testing.expect(mem.eql(u8, tagName(E1.B), "B"));
52 try testing.expect(mem.eql(u8, tagName(E2.C), "C"));
53 try testing.expect(mem.eql(u8, tagName(E2.D), "D"));
54 try testing.expect(mem.eql(u8, tagName(error.E), "E"));
55 try testing.expect(mem.eql(u8, tagName(error.F), "F"));
56 try testing.expect(mem.eql(u8, tagName(u1g), "G"));
57 try testing.expect(mem.eql(u8, tagName(u1h), "H"));
58 try testing.expect(mem.eql(u8, tagName(u2a), "C"));
59 try testing.expect(mem.eql(u8, tagName(u2b), "D"));
6060}
6161
6262pub fn stringToEnum(comptime T: type, str: []const u8) ?T {
......@@ -98,9 +98,9 @@ test "std.meta.stringToEnum" {
9898 A,
9999 B,
100100 };
101 testing.expect(E1.A == stringToEnum(E1, "A").?);
102 testing.expect(E1.B == stringToEnum(E1, "B").?);
103 testing.expect(null == stringToEnum(E1, "C"));
101 try testing.expect(E1.A == stringToEnum(E1, "A").?);
102 try testing.expect(E1.B == stringToEnum(E1, "B").?);
103 try testing.expect(null == stringToEnum(E1, "C"));
104104}
105105
106106pub fn bitCount(comptime T: type) comptime_int {
......@@ -113,8 +113,8 @@ pub fn bitCount(comptime T: type) comptime_int {
113113}
114114
115115test "std.meta.bitCount" {
116 testing.expect(bitCount(u8) == 8);
117 testing.expect(bitCount(f32) == 32);
116 try testing.expect(bitCount(u8) == 8);
117 try testing.expect(bitCount(f32) == 32);
118118}
119119
120120/// Returns the alignment of type T.
......@@ -135,13 +135,13 @@ pub fn alignment(comptime T: type) comptime_int {
135135}
136136
137137test "std.meta.alignment" {
138 testing.expect(alignment(u8) == 1);
139 testing.expect(alignment(*align(1) u8) == 1);
140 testing.expect(alignment(*align(2) u8) == 2);
141 testing.expect(alignment([]align(1) u8) == 1);
142 testing.expect(alignment([]align(2) u8) == 2);
143 testing.expect(alignment(fn () void) > 0);
144 testing.expect(alignment(fn () align(128) void) == 128);
138 try testing.expect(alignment(u8) == 1);
139 try testing.expect(alignment(*align(1) u8) == 1);
140 try testing.expect(alignment(*align(2) u8) == 2);
141 try testing.expect(alignment([]align(1) u8) == 1);
142 try testing.expect(alignment([]align(2) u8) == 2);
143 try testing.expect(alignment(fn () void) > 0);
144 try testing.expect(alignment(fn () align(128) void) == 128);
145145}
146146
147147pub fn Child(comptime T: type) type {
......@@ -155,11 +155,11 @@ pub fn Child(comptime T: type) type {
155155}
156156
157157test "std.meta.Child" {
158 testing.expect(Child([1]u8) == u8);
159 testing.expect(Child(*u8) == u8);
160 testing.expect(Child([]u8) == u8);
161 testing.expect(Child(?u8) == u8);
162 testing.expect(Child(Vector(2, u8)) == u8);
158 try testing.expect(Child([1]u8) == u8);
159 try testing.expect(Child(*u8) == u8);
160 try testing.expect(Child([]u8) == u8);
161 try testing.expect(Child(?u8) == u8);
162 try testing.expect(Child(Vector(2, u8)) == u8);
163163}
164164
165165/// Given a "memory span" type, returns the "element type".
......@@ -188,13 +188,13 @@ pub fn Elem(comptime T: type) type {
188188}
189189
190190test "std.meta.Elem" {
191 testing.expect(Elem([1]u8) == u8);
192 testing.expect(Elem([*]u8) == u8);
193 testing.expect(Elem([]u8) == u8);
194 testing.expect(Elem(*[10]u8) == u8);
195 testing.expect(Elem(Vector(2, u8)) == u8);
196 testing.expect(Elem(*Vector(2, u8)) == u8);
197 testing.expect(Elem(?[*]u8) == u8);
191 try testing.expect(Elem([1]u8) == u8);
192 try testing.expect(Elem([*]u8) == u8);
193 try testing.expect(Elem([]u8) == u8);
194 try testing.expect(Elem(*[10]u8) == u8);
195 try testing.expect(Elem(Vector(2, u8)) == u8);
196 try testing.expect(Elem(*Vector(2, u8)) == u8);
197 try testing.expect(Elem(?[*]u8) == u8);
198198}
199199
200200/// Given a type which can have a sentinel e.g. `[:0]u8`, returns the sentinel value,
......@@ -219,20 +219,20 @@ pub fn sentinel(comptime T: type) ?Elem(T) {
219219}
220220
221221test "std.meta.sentinel" {
222 testSentinel();
223 comptime testSentinel();
222 try testSentinel();
223 comptime try testSentinel();
224224}
225225
226fn testSentinel() void {
227 testing.expectEqual(@as(u8, 0), sentinel([:0]u8).?);
228 testing.expectEqual(@as(u8, 0), sentinel([*:0]u8).?);
229 testing.expectEqual(@as(u8, 0), sentinel([5:0]u8).?);
230 testing.expectEqual(@as(u8, 0), sentinel(*const [5:0]u8).?);
226fn testSentinel() !void {
227 try testing.expectEqual(@as(u8, 0), sentinel([:0]u8).?);
228 try testing.expectEqual(@as(u8, 0), sentinel([*:0]u8).?);
229 try testing.expectEqual(@as(u8, 0), sentinel([5:0]u8).?);
230 try testing.expectEqual(@as(u8, 0), sentinel(*const [5:0]u8).?);
231231
232 testing.expect(sentinel([]u8) == null);
233 testing.expect(sentinel([*]u8) == null);
234 testing.expect(sentinel([5]u8) == null);
235 testing.expect(sentinel(*const [5]u8) == null);
232 try testing.expect(sentinel([]u8) == null);
233 try testing.expect(sentinel([*]u8) == null);
234 try testing.expect(sentinel([5]u8) == null);
235 try testing.expect(sentinel(*const [5]u8) == null);
236236}
237237
238238/// Given a "memory span" type, returns the same type except with the given sentinel value.
......@@ -322,17 +322,17 @@ pub fn assumeSentinel(p: anytype, comptime sentinel_val: Elem(@TypeOf(p))) Senti
322322}
323323
324324test "std.meta.assumeSentinel" {
325 testing.expect([*:0]u8 == @TypeOf(assumeSentinel(@as([*]u8, undefined), 0)));
326 testing.expect([:0]u8 == @TypeOf(assumeSentinel(@as([]u8, undefined), 0)));
327 testing.expect([*:0]const u8 == @TypeOf(assumeSentinel(@as([*]const u8, undefined), 0)));
328 testing.expect([:0]const u8 == @TypeOf(assumeSentinel(@as([]const u8, undefined), 0)));
329 testing.expect([*:0]u16 == @TypeOf(assumeSentinel(@as([*]u16, undefined), 0)));
330 testing.expect([:0]const u16 == @TypeOf(assumeSentinel(@as([]const u16, undefined), 0)));
331 testing.expect([*:3]u8 == @TypeOf(assumeSentinel(@as([*:1]u8, undefined), 3)));
332 testing.expect([:null]?[*]u8 == @TypeOf(assumeSentinel(@as([]?[*]u8, undefined), null)));
333 testing.expect([*:null]?[*]u8 == @TypeOf(assumeSentinel(@as([*]?[*]u8, undefined), null)));
334 testing.expect(*[10:0]u8 == @TypeOf(assumeSentinel(@as(*[10]u8, undefined), 0)));
335 testing.expect(?[*:0]u8 == @TypeOf(assumeSentinel(@as(?[*]u8, undefined), 0)));
325 try testing.expect([*:0]u8 == @TypeOf(assumeSentinel(@as([*]u8, undefined), 0)));
326 try testing.expect([:0]u8 == @TypeOf(assumeSentinel(@as([]u8, undefined), 0)));
327 try testing.expect([*:0]const u8 == @TypeOf(assumeSentinel(@as([*]const u8, undefined), 0)));
328 try testing.expect([:0]const u8 == @TypeOf(assumeSentinel(@as([]const u8, undefined), 0)));
329 try testing.expect([*:0]u16 == @TypeOf(assumeSentinel(@as([*]u16, undefined), 0)));
330 try testing.expect([:0]const u16 == @TypeOf(assumeSentinel(@as([]const u16, undefined), 0)));
331 try testing.expect([*:3]u8 == @TypeOf(assumeSentinel(@as([*:1]u8, undefined), 3)));
332 try testing.expect([:null]?[*]u8 == @TypeOf(assumeSentinel(@as([]?[*]u8, undefined), null)));
333 try testing.expect([*:null]?[*]u8 == @TypeOf(assumeSentinel(@as([*]?[*]u8, undefined), null)));
334 try testing.expect(*[10:0]u8 == @TypeOf(assumeSentinel(@as(*[10]u8, undefined), 0)));
335 try testing.expect(?[*:0]u8 == @TypeOf(assumeSentinel(@as(?[*]u8, undefined), 0)));
336336}
337337
338338pub fn containerLayout(comptime T: type) TypeInfo.ContainerLayout {
......@@ -361,13 +361,13 @@ test "std.meta.containerLayout" {
361361 a: u8,
362362 };
363363
364 testing.expect(containerLayout(E1) == .Auto);
365 testing.expect(containerLayout(S1) == .Auto);
366 testing.expect(containerLayout(S2) == .Packed);
367 testing.expect(containerLayout(S3) == .Extern);
368 testing.expect(containerLayout(U1) == .Auto);
369 testing.expect(containerLayout(U2) == .Packed);
370 testing.expect(containerLayout(U3) == .Extern);
364 try testing.expect(containerLayout(E1) == .Auto);
365 try testing.expect(containerLayout(S1) == .Auto);
366 try testing.expect(containerLayout(S2) == .Packed);
367 try testing.expect(containerLayout(S3) == .Extern);
368 try testing.expect(containerLayout(U1) == .Auto);
369 try testing.expect(containerLayout(U2) == .Packed);
370 try testing.expect(containerLayout(U3) == .Extern);
371371}
372372
373373pub fn declarations(comptime T: type) []const TypeInfo.Declaration {
......@@ -406,8 +406,8 @@ test "std.meta.declarations" {
406406 };
407407
408408 inline for (decls) |decl| {
409 testing.expect(decl.len == 1);
410 testing.expect(comptime mem.eql(u8, decl[0].name, "a"));
409 try testing.expect(decl.len == 1);
410 try testing.expect(comptime mem.eql(u8, decl[0].name, "a"));
411411 }
412412}
413413
......@@ -442,8 +442,8 @@ test "std.meta.declarationInfo" {
442442 };
443443
444444 inline for (infos) |info| {
445 testing.expect(comptime mem.eql(u8, info.name, "a"));
446 testing.expect(!info.is_pub);
445 try testing.expect(comptime mem.eql(u8, info.name, "a"));
446 try testing.expect(!info.is_pub);
447447 }
448448}
449449
......@@ -480,16 +480,16 @@ test "std.meta.fields" {
480480 const sf = comptime fields(S1);
481481 const uf = comptime fields(U1);
482482
483 testing.expect(e1f.len == 1);
484 testing.expect(e2f.len == 1);
485 testing.expect(sf.len == 1);
486 testing.expect(uf.len == 1);
487 testing.expect(mem.eql(u8, e1f[0].name, "A"));
488 testing.expect(mem.eql(u8, e2f[0].name, "A"));
489 testing.expect(mem.eql(u8, sf[0].name, "a"));
490 testing.expect(mem.eql(u8, uf[0].name, "a"));
491 testing.expect(comptime sf[0].field_type == u8);
492 testing.expect(comptime uf[0].field_type == u8);
483 try testing.expect(e1f.len == 1);
484 try testing.expect(e2f.len == 1);
485 try testing.expect(sf.len == 1);
486 try testing.expect(uf.len == 1);
487 try testing.expect(mem.eql(u8, e1f[0].name, "A"));
488 try testing.expect(mem.eql(u8, e2f[0].name, "A"));
489 try testing.expect(mem.eql(u8, sf[0].name, "a"));
490 try testing.expect(mem.eql(u8, uf[0].name, "a"));
491 try testing.expect(comptime sf[0].field_type == u8);
492 try testing.expect(comptime uf[0].field_type == u8);
493493}
494494
495495pub fn fieldInfo(comptime T: type, comptime field: FieldEnum(T)) switch (@typeInfo(T)) {
......@@ -519,12 +519,12 @@ test "std.meta.fieldInfo" {
519519 const sf = fieldInfo(S1, .a);
520520 const uf = fieldInfo(U1, .a);
521521
522 testing.expect(mem.eql(u8, e1f.name, "A"));
523 testing.expect(mem.eql(u8, e2f.name, "A"));
524 testing.expect(mem.eql(u8, sf.name, "a"));
525 testing.expect(mem.eql(u8, uf.name, "a"));
526 testing.expect(comptime sf.field_type == u8);
527 testing.expect(comptime uf.field_type == u8);
522 try testing.expect(mem.eql(u8, e1f.name, "A"));
523 try testing.expect(mem.eql(u8, e2f.name, "A"));
524 try testing.expect(mem.eql(u8, sf.name, "a"));
525 try testing.expect(mem.eql(u8, uf.name, "a"));
526 try testing.expect(comptime sf.field_type == u8);
527 try testing.expect(comptime uf.field_type == u8);
528528}
529529
530530pub fn fieldNames(comptime T: type) *const [fields(T).len][]const u8 {
......@@ -554,16 +554,16 @@ test "std.meta.fieldNames" {
554554 const s1names = fieldNames(S1);
555555 const u1names = fieldNames(U1);
556556
557 testing.expect(e1names.len == 2);
558 testing.expectEqualSlices(u8, e1names[0], "A");
559 testing.expectEqualSlices(u8, e1names[1], "B");
560 testing.expect(e2names.len == 1);
561 testing.expectEqualSlices(u8, e2names[0], "A");
562 testing.expect(s1names.len == 1);
563 testing.expectEqualSlices(u8, s1names[0], "a");
564 testing.expect(u1names.len == 2);
565 testing.expectEqualSlices(u8, u1names[0], "a");
566 testing.expectEqualSlices(u8, u1names[1], "b");
557 try testing.expect(e1names.len == 2);
558 try testing.expectEqualSlices(u8, e1names[0], "A");
559 try testing.expectEqualSlices(u8, e1names[1], "B");
560 try testing.expect(e2names.len == 1);
561 try testing.expectEqualSlices(u8, e2names[0], "A");
562 try testing.expect(s1names.len == 1);
563 try testing.expectEqualSlices(u8, s1names[0], "a");
564 try testing.expect(u1names.len == 2);
565 try testing.expectEqualSlices(u8, u1names[0], "a");
566 try testing.expectEqualSlices(u8, u1names[1], "b");
567567}
568568
569569pub fn FieldEnum(comptime T: type) type {
......@@ -587,20 +587,20 @@ pub fn FieldEnum(comptime T: type) type {
587587 });
588588}
589589
590fn expectEqualEnum(expected: anytype, actual: @TypeOf(expected)) void {
590fn expectEqualEnum(expected: anytype, actual: @TypeOf(expected)) !void {
591591 // TODO: https://github.com/ziglang/zig/issues/7419
592592 // testing.expectEqual(@typeInfo(expected).Enum, @typeInfo(actual).Enum);
593 testing.expectEqual(@typeInfo(expected).Enum.layout, @typeInfo(actual).Enum.layout);
594 testing.expectEqual(@typeInfo(expected).Enum.tag_type, @typeInfo(actual).Enum.tag_type);
595 comptime testing.expectEqualSlices(std.builtin.TypeInfo.EnumField, @typeInfo(expected).Enum.fields, @typeInfo(actual).Enum.fields);
596 comptime testing.expectEqualSlices(std.builtin.TypeInfo.Declaration, @typeInfo(expected).Enum.decls, @typeInfo(actual).Enum.decls);
597 testing.expectEqual(@typeInfo(expected).Enum.is_exhaustive, @typeInfo(actual).Enum.is_exhaustive);
593 try testing.expectEqual(@typeInfo(expected).Enum.layout, @typeInfo(actual).Enum.layout);
594 try testing.expectEqual(@typeInfo(expected).Enum.tag_type, @typeInfo(actual).Enum.tag_type);
595 comptime try testing.expectEqualSlices(std.builtin.TypeInfo.EnumField, @typeInfo(expected).Enum.fields, @typeInfo(actual).Enum.fields);
596 comptime try testing.expectEqualSlices(std.builtin.TypeInfo.Declaration, @typeInfo(expected).Enum.decls, @typeInfo(actual).Enum.decls);
597 try testing.expectEqual(@typeInfo(expected).Enum.is_exhaustive, @typeInfo(actual).Enum.is_exhaustive);
598598}
599599
600600test "std.meta.FieldEnum" {
601 expectEqualEnum(enum { a }, FieldEnum(struct { a: u8 }));
602 expectEqualEnum(enum { a, b, c }, FieldEnum(struct { a: u8, b: void, c: f32 }));
603 expectEqualEnum(enum { a, b, c }, FieldEnum(union { a: u8, b: void, c: f32 }));
601 try expectEqualEnum(enum { a }, FieldEnum(struct { a: u8 }));
602 try expectEqualEnum(enum { a, b, c }, FieldEnum(struct { a: u8, b: void, c: f32 }));
603 try expectEqualEnum(enum { a, b, c }, FieldEnum(union { a: u8, b: void, c: f32 }));
604604}
605605
606606// Deprecated: use Tag
......@@ -624,8 +624,8 @@ test "std.meta.Tag" {
624624 D: u16,
625625 };
626626
627 testing.expect(Tag(E) == u8);
628 testing.expect(Tag(U) == E);
627 try testing.expect(Tag(E) == u8);
628 try testing.expect(Tag(U) == E);
629629}
630630
631631///Returns the active tag of a tagged union
......@@ -646,10 +646,10 @@ test "std.meta.activeTag" {
646646 };
647647
648648 var u = U{ .Int = 32 };
649 testing.expect(activeTag(u) == UE.Int);
649 try testing.expect(activeTag(u) == UE.Int);
650650
651651 u = U{ .Float = 112.9876 };
652 testing.expect(activeTag(u) == UE.Float);
652 try testing.expect(activeTag(u) == UE.Float);
653653}
654654
655655const TagPayloadType = TagPayload;
......@@ -657,7 +657,7 @@ const TagPayloadType = TagPayload;
657657///Given a tagged union type, and an enum, return the type of the union
658658/// field corresponding to the enum tag.
659659pub fn TagPayload(comptime U: type, tag: Tag(U)) type {
660 testing.expect(trait.is(.Union)(U));
660 try testing.expect(trait.is(.Union)(U));
661661
662662 const info = @typeInfo(U).Union;
663663 const tag_info = @typeInfo(Tag(U)).Enum;
......@@ -679,7 +679,7 @@ test "std.meta.TagPayload" {
679679 };
680680 const MovedEvent = TagPayload(Event, Event.Moved);
681681 var e: Event = undefined;
682 testing.expect(MovedEvent == @TypeOf(e.Moved));
682 try testing.expect(MovedEvent == @TypeOf(e.Moved));
683683}
684684
685685/// Compares two of any type for equality. Containers are compared on a field-by-field basis,
......@@ -779,19 +779,19 @@ test "std.meta.eql" {
779779 const u_2 = U{ .s = s_1 };
780780 const u_3 = U{ .f = 24 };
781781
782 testing.expect(eql(s_1, s_3));
783 testing.expect(eql(&s_1, &s_1));
784 testing.expect(!eql(&s_1, &s_3));
785 testing.expect(eql(u_1, u_3));
786 testing.expect(!eql(u_1, u_2));
782 try testing.expect(eql(s_1, s_3));
783 try testing.expect(eql(&s_1, &s_1));
784 try testing.expect(!eql(&s_1, &s_3));
785 try testing.expect(eql(u_1, u_3));
786 try testing.expect(!eql(u_1, u_2));
787787
788788 var a1 = "abcdef".*;
789789 var a2 = "abcdef".*;
790790 var a3 = "ghijkl".*;
791791
792 testing.expect(eql(a1, a2));
793 testing.expect(!eql(a1, a3));
794 testing.expect(!eql(a1[0..], a2[0..]));
792 try testing.expect(eql(a1, a2));
793 try testing.expect(!eql(a1, a3));
794 try testing.expect(!eql(a1[0..], a2[0..]));
795795
796796 const EU = struct {
797797 fn tst(err: bool) !u8 {
......@@ -800,16 +800,16 @@ test "std.meta.eql" {
800800 }
801801 };
802802
803 testing.expect(eql(EU.tst(true), EU.tst(true)));
804 testing.expect(eql(EU.tst(false), EU.tst(false)));
805 testing.expect(!eql(EU.tst(false), EU.tst(true)));
803 try testing.expect(eql(EU.tst(true), EU.tst(true)));
804 try testing.expect(eql(EU.tst(false), EU.tst(false)));
805 try testing.expect(!eql(EU.tst(false), EU.tst(true)));
806806
807807 var v1 = @splat(4, @as(u32, 1));
808808 var v2 = @splat(4, @as(u32, 1));
809809 var v3 = @splat(4, @as(u32, 2));
810810
811 testing.expect(eql(v1, v2));
812 testing.expect(!eql(v1, v3));
811 try testing.expect(eql(v1, v2));
812 try testing.expect(!eql(v1, v3));
813813}
814814
815815test "intToEnum with error return" {
......@@ -823,9 +823,9 @@ test "intToEnum with error return" {
823823
824824 var zero: u8 = 0;
825825 var one: u16 = 1;
826 testing.expect(intToEnum(E1, zero) catch unreachable == E1.A);
827 testing.expect(intToEnum(E2, one) catch unreachable == E2.B);
828 testing.expectError(error.InvalidEnumTag, intToEnum(E1, one));
826 try testing.expect(intToEnum(E1, zero) catch unreachable == E1.A);
827 try testing.expect(intToEnum(E2, one) catch unreachable == E2.B);
828 try testing.expectError(error.InvalidEnumTag, intToEnum(E1, one));
829829}
830830
831831pub const IntToEnumError = error{InvalidEnumTag};
......@@ -1000,27 +1000,27 @@ test "std.meta.cast" {
10001000
10011001 var i = @as(i64, 10);
10021002
1003 testing.expect(cast(*u8, 16) == @intToPtr(*u8, 16));
1004 testing.expect(cast(*u64, &i).* == @as(u64, 10));
1005 testing.expect(cast(*i64, @as(?*align(1) i64, &i)) == &i);
1003 try testing.expect(cast(*u8, 16) == @intToPtr(*u8, 16));
1004 try testing.expect(cast(*u64, &i).* == @as(u64, 10));
1005 try testing.expect(cast(*i64, @as(?*align(1) i64, &i)) == &i);
10061006
1007 testing.expect(cast(?*u8, 2) == @intToPtr(*u8, 2));
1008 testing.expect(cast(?*i64, @as(*align(1) i64, &i)) == &i);
1009 testing.expect(cast(?*i64, @as(?*align(1) i64, &i)) == &i);
1007 try testing.expect(cast(?*u8, 2) == @intToPtr(*u8, 2));
1008 try testing.expect(cast(?*i64, @as(*align(1) i64, &i)) == &i);
1009 try testing.expect(cast(?*i64, @as(?*align(1) i64, &i)) == &i);
10101010
1011 testing.expect(cast(E, 1) == .One);
1011 try testing.expect(cast(E, 1) == .One);
10121012
1013 testing.expectEqual(@as(u32, 4), cast(u32, @intToPtr(*u32, 4)));
1014 testing.expectEqual(@as(u32, 4), cast(u32, @intToPtr(?*u32, 4)));
1015 testing.expectEqual(@as(u32, 10), cast(u32, @as(u64, 10)));
1016 testing.expectEqual(@as(u8, 2), cast(u8, E.Two));
1013 try testing.expectEqual(@as(u32, 4), cast(u32, @intToPtr(*u32, 4)));
1014 try testing.expectEqual(@as(u32, 4), cast(u32, @intToPtr(?*u32, 4)));
1015 try testing.expectEqual(@as(u32, 10), cast(u32, @as(u64, 10)));
1016 try testing.expectEqual(@as(u8, 2), cast(u8, E.Two));
10171017
1018 testing.expectEqual(@bitCast(i32, @as(u32, 0x8000_0000)), cast(i32, @as(u32, 0x8000_0000)));
1018 try testing.expectEqual(@bitCast(i32, @as(u32, 0x8000_0000)), cast(i32, @as(u32, 0x8000_0000)));
10191019
1020 testing.expectEqual(@intToPtr(*u8, 2), cast(*u8, @intToPtr(*const u8, 2)));
1021 testing.expectEqual(@intToPtr(*u8, 2), cast(*u8, @intToPtr(*volatile u8, 2)));
1020 try testing.expectEqual(@intToPtr(*u8, 2), cast(*u8, @intToPtr(*const u8, 2)));
1021 try testing.expectEqual(@intToPtr(*u8, 2), cast(*u8, @intToPtr(*volatile u8, 2)));
10221022
1023 testing.expectEqual(@intToPtr(?*c_void, 2), cast(?*c_void, @intToPtr(*u8, 2)));
1023 try testing.expectEqual(@intToPtr(?*c_void, 2), cast(?*c_void, @intToPtr(*u8, 2)));
10241024
10251025 const C_ENUM = enum(c_int) {
10261026 A = 0,
......@@ -1028,10 +1028,10 @@ test "std.meta.cast" {
10281028 C,
10291029 _,
10301030 };
1031 testing.expectEqual(cast(C_ENUM, @as(i64, -1)), @intToEnum(C_ENUM, -1));
1032 testing.expectEqual(cast(C_ENUM, @as(i8, 1)), .B);
1033 testing.expectEqual(cast(C_ENUM, @as(u64, 1)), .B);
1034 testing.expectEqual(cast(C_ENUM, @as(u64, 42)), @intToEnum(C_ENUM, 42));
1031 try testing.expectEqual(cast(C_ENUM, @as(i64, -1)), @intToEnum(C_ENUM, -1));
1032 try testing.expectEqual(cast(C_ENUM, @as(i8, 1)), .B);
1033 try testing.expectEqual(cast(C_ENUM, @as(u64, 1)), .B);
1034 try testing.expectEqual(cast(C_ENUM, @as(u64, 42)), @intToEnum(C_ENUM, 42));
10351035}
10361036
10371037/// Given a value returns its size as C's sizeof operator would.
......@@ -1110,43 +1110,43 @@ test "sizeof" {
11101110
11111111 const ptr_size = @sizeOf(*c_void);
11121112
1113 testing.expect(sizeof(u32) == 4);
1114 testing.expect(sizeof(@as(u32, 2)) == 4);
1115 testing.expect(sizeof(2) == @sizeOf(c_int));
1113 try testing.expect(sizeof(u32) == 4);
1114 try testing.expect(sizeof(@as(u32, 2)) == 4);
1115 try testing.expect(sizeof(2) == @sizeOf(c_int));
11161116
1117 testing.expect(sizeof(2.0) == @sizeOf(f64));
1117 try testing.expect(sizeof(2.0) == @sizeOf(f64));
11181118
1119 testing.expect(sizeof(E) == @sizeOf(c_int));
1120 testing.expect(sizeof(E.One) == @sizeOf(c_int));
1119 try testing.expect(sizeof(E) == @sizeOf(c_int));
1120 try testing.expect(sizeof(E.One) == @sizeOf(c_int));
11211121
1122 testing.expect(sizeof(S) == 4);
1122 try testing.expect(sizeof(S) == 4);
11231123
1124 testing.expect(sizeof([_]u32{ 4, 5, 6 }) == 12);
1125 testing.expect(sizeof([3]u32) == 12);
1126 testing.expect(sizeof([3:0]u32) == 16);
1127 testing.expect(sizeof(&[_]u32{ 4, 5, 6 }) == ptr_size);
1124 try testing.expect(sizeof([_]u32{ 4, 5, 6 }) == 12);
1125 try testing.expect(sizeof([3]u32) == 12);
1126 try testing.expect(sizeof([3:0]u32) == 16);
1127 try testing.expect(sizeof(&[_]u32{ 4, 5, 6 }) == ptr_size);
11281128
1129 testing.expect(sizeof(*u32) == ptr_size);
1130 testing.expect(sizeof([*]u32) == ptr_size);
1131 testing.expect(sizeof([*c]u32) == ptr_size);
1132 testing.expect(sizeof(?*u32) == ptr_size);
1133 testing.expect(sizeof(?[*]u32) == ptr_size);
1134 testing.expect(sizeof(*c_void) == ptr_size);
1135 testing.expect(sizeof(*void) == ptr_size);
1136 testing.expect(sizeof(null) == ptr_size);
1129 try testing.expect(sizeof(*u32) == ptr_size);
1130 try testing.expect(sizeof([*]u32) == ptr_size);
1131 try testing.expect(sizeof([*c]u32) == ptr_size);
1132 try testing.expect(sizeof(?*u32) == ptr_size);
1133 try testing.expect(sizeof(?[*]u32) == ptr_size);
1134 try testing.expect(sizeof(*c_void) == ptr_size);
1135 try testing.expect(sizeof(*void) == ptr_size);
1136 try testing.expect(sizeof(null) == ptr_size);
11371137
1138 testing.expect(sizeof("foobar") == 7);
1139 testing.expect(sizeof(&[_:0]u16{ 'f', 'o', 'o', 'b', 'a', 'r' }) == 14);
1140 testing.expect(sizeof(*const [4:0]u8) == 5);
1141 testing.expect(sizeof(*[4:0]u8) == ptr_size);
1142 testing.expect(sizeof([*]const [4:0]u8) == ptr_size);
1143 testing.expect(sizeof(*const *const [4:0]u8) == ptr_size);
1144 testing.expect(sizeof(*const [4]u8) == ptr_size);
1138 try testing.expect(sizeof("foobar") == 7);
1139 try testing.expect(sizeof(&[_:0]u16{ 'f', 'o', 'o', 'b', 'a', 'r' }) == 14);
1140 try testing.expect(sizeof(*const [4:0]u8) == 5);
1141 try testing.expect(sizeof(*[4:0]u8) == ptr_size);
1142 try testing.expect(sizeof([*]const [4:0]u8) == ptr_size);
1143 try testing.expect(sizeof(*const *const [4:0]u8) == ptr_size);
1144 try testing.expect(sizeof(*const [4]u8) == ptr_size);
11451145
1146 testing.expect(sizeof(sizeof) == @sizeOf(@TypeOf(sizeof)));
1146 try testing.expect(sizeof(sizeof) == @sizeOf(@TypeOf(sizeof)));
11471147
1148 testing.expect(sizeof(void) == 1);
1149 testing.expect(sizeof(c_void) == 1);
1148 try testing.expect(sizeof(void) == 1);
1149 try testing.expect(sizeof(c_void) == 1);
11501150}
11511151
11521152pub const CIntLiteralRadix = enum { decimal, octal, hexadecimal };
......@@ -1185,7 +1185,7 @@ pub fn promoteIntLiteral(
11851185
11861186test "promoteIntLiteral" {
11871187 const signed_hex = promoteIntLiteral(c_int, math.maxInt(c_int) + 1, .hexadecimal);
1188 testing.expectEqual(c_uint, @TypeOf(signed_hex));
1188 try testing.expectEqual(c_uint, @TypeOf(signed_hex));
11891189
11901190 if (math.maxInt(c_longlong) == math.maxInt(c_int)) return;
11911191
......@@ -1193,11 +1193,11 @@ test "promoteIntLiteral" {
11931193 const unsigned = promoteIntLiteral(c_uint, math.maxInt(c_uint) + 1, .hexadecimal);
11941194
11951195 if (math.maxInt(c_long) > math.maxInt(c_int)) {
1196 testing.expectEqual(c_long, @TypeOf(signed_decimal));
1197 testing.expectEqual(c_ulong, @TypeOf(unsigned));
1196 try testing.expectEqual(c_long, @TypeOf(signed_decimal));
1197 try testing.expectEqual(c_ulong, @TypeOf(unsigned));
11981198 } else {
1199 testing.expectEqual(c_longlong, @TypeOf(signed_decimal));
1200 testing.expectEqual(c_ulonglong, @TypeOf(unsigned));
1199 try testing.expectEqual(c_longlong, @TypeOf(signed_decimal));
1200 try testing.expectEqual(c_ulonglong, @TypeOf(unsigned));
12011201 }
12021202}
12031203
......@@ -1339,17 +1339,17 @@ pub fn shuffleVectorIndex(comptime this_index: c_int, comptime source_vector_len
13391339test "shuffleVectorIndex" {
13401340 const vector_len: usize = 4;
13411341
1342 testing.expect(shuffleVectorIndex(-1, vector_len) == 0);
1342 try testing.expect(shuffleVectorIndex(-1, vector_len) == 0);
13431343
1344 testing.expect(shuffleVectorIndex(0, vector_len) == 0);
1345 testing.expect(shuffleVectorIndex(1, vector_len) == 1);
1346 testing.expect(shuffleVectorIndex(2, vector_len) == 2);
1347 testing.expect(shuffleVectorIndex(3, vector_len) == 3);
1344 try testing.expect(shuffleVectorIndex(0, vector_len) == 0);
1345 try testing.expect(shuffleVectorIndex(1, vector_len) == 1);
1346 try testing.expect(shuffleVectorIndex(2, vector_len) == 2);
1347 try testing.expect(shuffleVectorIndex(3, vector_len) == 3);
13481348
1349 testing.expect(shuffleVectorIndex(4, vector_len) == -1);
1350 testing.expect(shuffleVectorIndex(5, vector_len) == -2);
1351 testing.expect(shuffleVectorIndex(6, vector_len) == -3);
1352 testing.expect(shuffleVectorIndex(7, vector_len) == -4);
1349 try testing.expect(shuffleVectorIndex(4, vector_len) == -1);
1350 try testing.expect(shuffleVectorIndex(5, vector_len) == -2);
1351 try testing.expect(shuffleVectorIndex(6, vector_len) == -3);
1352 try testing.expect(shuffleVectorIndex(7, vector_len) == -4);
13531353}
13541354
13551355/// Returns whether `error_union` contains an error.
......@@ -1358,6 +1358,6 @@ pub fn isError(error_union: anytype) bool {
13581358}
13591359
13601360test "isError" {
1361 std.testing.expect(isError(math.absInt(@as(i8, -128))));
1362 std.testing.expect(!isError(math.absInt(@as(i8, -127))));
1361 try std.testing.expect(isError(math.absInt(@as(i8, -128))));
1362 try std.testing.expect(!isError(math.absInt(@as(i8, -127))));
13631363}
lib/std/meta/trailer_flags.zig+7-7
......@@ -146,7 +146,7 @@ test "TrailerFlags" {
146146 b: bool,
147147 c: u64,
148148 });
149 testing.expectEqual(u2, meta.Tag(Flags.FieldEnum));
149 try testing.expectEqual(u2, meta.Tag(Flags.FieldEnum));
150150
151151 var flags = Flags.init(.{
152152 .b = true,
......@@ -158,16 +158,16 @@ test "TrailerFlags" {
158158 flags.set(slice.ptr, .b, false);
159159 flags.set(slice.ptr, .c, 12345678);
160160
161 testing.expect(flags.get(slice.ptr, .a) == null);
162 testing.expect(!flags.get(slice.ptr, .b).?);
163 testing.expect(flags.get(slice.ptr, .c).? == 12345678);
161 try testing.expect(flags.get(slice.ptr, .a) == null);
162 try testing.expect(!flags.get(slice.ptr, .b).?);
163 try testing.expect(flags.get(slice.ptr, .c).? == 12345678);
164164
165165 flags.setMany(slice.ptr, .{
166166 .b = true,
167167 .c = 5678,
168168 });
169169
170 testing.expect(flags.get(slice.ptr, .a) == null);
171 testing.expect(flags.get(slice.ptr, .b).?);
172 testing.expect(flags.get(slice.ptr, .c).? == 5678);
170 try testing.expect(flags.get(slice.ptr, .a) == null);
171 try testing.expect(flags.get(slice.ptr, .b).?);
172 try testing.expect(flags.get(slice.ptr, .c).? == 5678);
173173}
lib/std/meta/trait.zig+142-142
......@@ -45,8 +45,8 @@ test "std.meta.trait.multiTrait" {
4545 hasField("x"),
4646 hasField("y"),
4747 });
48 testing.expect(isVector(Vector2));
49 testing.expect(!isVector(u8));
48 try testing.expect(isVector(Vector2));
49 try testing.expect(!isVector(u8));
5050}
5151
5252pub fn hasFn(comptime name: []const u8) TraitFn {
......@@ -66,9 +66,9 @@ test "std.meta.trait.hasFn" {
6666 pub fn useless() void {}
6767 };
6868
69 testing.expect(hasFn("useless")(TestStruct));
70 testing.expect(!hasFn("append")(TestStruct));
71 testing.expect(!hasFn("useless")(u8));
69 try testing.expect(hasFn("useless")(TestStruct));
70 try testing.expect(!hasFn("append")(TestStruct));
71 try testing.expect(!hasFn("useless")(u8));
7272}
7373
7474pub fn hasField(comptime name: []const u8) TraitFn {
......@@ -96,11 +96,11 @@ test "std.meta.trait.hasField" {
9696 value: u32,
9797 };
9898
99 testing.expect(hasField("value")(TestStruct));
100 testing.expect(!hasField("value")(*TestStruct));
101 testing.expect(!hasField("x")(TestStruct));
102 testing.expect(!hasField("x")(**TestStruct));
103 testing.expect(!hasField("value")(u8));
99 try testing.expect(hasField("value")(TestStruct));
100 try testing.expect(!hasField("value")(*TestStruct));
101 try testing.expect(!hasField("x")(TestStruct));
102 try testing.expect(!hasField("x")(**TestStruct));
103 try testing.expect(!hasField("value")(u8));
104104}
105105
106106pub fn is(comptime id: builtin.TypeId) TraitFn {
......@@ -113,11 +113,11 @@ pub fn is(comptime id: builtin.TypeId) TraitFn {
113113}
114114
115115test "std.meta.trait.is" {
116 testing.expect(is(.Int)(u8));
117 testing.expect(!is(.Int)(f32));
118 testing.expect(is(.Pointer)(*u8));
119 testing.expect(is(.Void)(void));
120 testing.expect(!is(.Optional)(anyerror));
116 try testing.expect(is(.Int)(u8));
117 try testing.expect(!is(.Int)(f32));
118 try testing.expect(is(.Pointer)(*u8));
119 try testing.expect(is(.Void)(void));
120 try testing.expect(!is(.Optional)(anyerror));
121121}
122122
123123pub fn isPtrTo(comptime id: builtin.TypeId) TraitFn {
......@@ -131,9 +131,9 @@ pub fn isPtrTo(comptime id: builtin.TypeId) TraitFn {
131131}
132132
133133test "std.meta.trait.isPtrTo" {
134 testing.expect(!isPtrTo(.Struct)(struct {}));
135 testing.expect(isPtrTo(.Struct)(*struct {}));
136 testing.expect(!isPtrTo(.Struct)(**struct {}));
134 try testing.expect(!isPtrTo(.Struct)(struct {}));
135 try testing.expect(isPtrTo(.Struct)(*struct {}));
136 try testing.expect(!isPtrTo(.Struct)(**struct {}));
137137}
138138
139139pub fn isSliceOf(comptime id: builtin.TypeId) TraitFn {
......@@ -147,9 +147,9 @@ pub fn isSliceOf(comptime id: builtin.TypeId) TraitFn {
147147}
148148
149149test "std.meta.trait.isSliceOf" {
150 testing.expect(!isSliceOf(.Struct)(struct {}));
151 testing.expect(isSliceOf(.Struct)([]struct {}));
152 testing.expect(!isSliceOf(.Struct)([][]struct {}));
150 try testing.expect(!isSliceOf(.Struct)(struct {}));
151 try testing.expect(isSliceOf(.Struct)([]struct {}));
152 try testing.expect(!isSliceOf(.Struct)([][]struct {}));
153153}
154154
155155///////////Strait trait Fns
......@@ -170,9 +170,9 @@ test "std.meta.trait.isExtern" {
170170 const TestExStruct = extern struct {};
171171 const TestStruct = struct {};
172172
173 testing.expect(isExtern(TestExStruct));
174 testing.expect(!isExtern(TestStruct));
175 testing.expect(!isExtern(u8));
173 try testing.expect(isExtern(TestExStruct));
174 try testing.expect(!isExtern(TestStruct));
175 try testing.expect(!isExtern(u8));
176176}
177177
178178pub fn isPacked(comptime T: type) bool {
......@@ -188,9 +188,9 @@ test "std.meta.trait.isPacked" {
188188 const TestPStruct = packed struct {};
189189 const TestStruct = struct {};
190190
191 testing.expect(isPacked(TestPStruct));
192 testing.expect(!isPacked(TestStruct));
193 testing.expect(!isPacked(u8));
191 try testing.expect(isPacked(TestPStruct));
192 try testing.expect(!isPacked(TestStruct));
193 try testing.expect(!isPacked(u8));
194194}
195195
196196pub fn isUnsignedInt(comptime T: type) bool {
......@@ -201,10 +201,10 @@ pub fn isUnsignedInt(comptime T: type) bool {
201201}
202202
203203test "isUnsignedInt" {
204 testing.expect(isUnsignedInt(u32) == true);
205 testing.expect(isUnsignedInt(comptime_int) == false);
206 testing.expect(isUnsignedInt(i64) == false);
207 testing.expect(isUnsignedInt(f64) == false);
204 try testing.expect(isUnsignedInt(u32) == true);
205 try testing.expect(isUnsignedInt(comptime_int) == false);
206 try testing.expect(isUnsignedInt(i64) == false);
207 try testing.expect(isUnsignedInt(f64) == false);
208208}
209209
210210pub fn isSignedInt(comptime T: type) bool {
......@@ -216,10 +216,10 @@ pub fn isSignedInt(comptime T: type) bool {
216216}
217217
218218test "isSignedInt" {
219 testing.expect(isSignedInt(u32) == false);
220 testing.expect(isSignedInt(comptime_int) == true);
221 testing.expect(isSignedInt(i64) == true);
222 testing.expect(isSignedInt(f64) == false);
219 try testing.expect(isSignedInt(u32) == false);
220 try testing.expect(isSignedInt(comptime_int) == true);
221 try testing.expect(isSignedInt(i64) == true);
222 try testing.expect(isSignedInt(f64) == false);
223223}
224224
225225pub fn isSingleItemPtr(comptime T: type) bool {
......@@ -231,10 +231,10 @@ pub fn isSingleItemPtr(comptime T: type) bool {
231231
232232test "std.meta.trait.isSingleItemPtr" {
233233 const array = [_]u8{0} ** 10;
234 comptime testing.expect(isSingleItemPtr(@TypeOf(&array[0])));
235 comptime testing.expect(!isSingleItemPtr(@TypeOf(array)));
234 comptime try testing.expect(isSingleItemPtr(@TypeOf(&array[0])));
235 comptime try testing.expect(!isSingleItemPtr(@TypeOf(array)));
236236 var runtime_zero: usize = 0;
237 testing.expect(!isSingleItemPtr(@TypeOf(array[runtime_zero..1])));
237 try testing.expect(!isSingleItemPtr(@TypeOf(array[runtime_zero..1])));
238238}
239239
240240pub fn isManyItemPtr(comptime T: type) bool {
......@@ -247,9 +247,9 @@ pub fn isManyItemPtr(comptime T: type) bool {
247247test "std.meta.trait.isManyItemPtr" {
248248 const array = [_]u8{0} ** 10;
249249 const mip = @ptrCast([*]const u8, &array[0]);
250 testing.expect(isManyItemPtr(@TypeOf(mip)));
251 testing.expect(!isManyItemPtr(@TypeOf(array)));
252 testing.expect(!isManyItemPtr(@TypeOf(array[0..1])));
250 try testing.expect(isManyItemPtr(@TypeOf(mip)));
251 try testing.expect(!isManyItemPtr(@TypeOf(array)));
252 try testing.expect(!isManyItemPtr(@TypeOf(array[0..1])));
253253}
254254
255255pub fn isSlice(comptime T: type) bool {
......@@ -262,9 +262,9 @@ pub fn isSlice(comptime T: type) bool {
262262test "std.meta.trait.isSlice" {
263263 const array = [_]u8{0} ** 10;
264264 var runtime_zero: usize = 0;
265 testing.expect(isSlice(@TypeOf(array[runtime_zero..])));
266 testing.expect(!isSlice(@TypeOf(array)));
267 testing.expect(!isSlice(@TypeOf(&array[0])));
265 try testing.expect(isSlice(@TypeOf(array[runtime_zero..])));
266 try testing.expect(!isSlice(@TypeOf(array)));
267 try testing.expect(!isSlice(@TypeOf(&array[0])));
268268}
269269
270270pub fn isIndexable(comptime T: type) bool {
......@@ -283,12 +283,12 @@ test "std.meta.trait.isIndexable" {
283283 const vector: meta.Vector(2, u32) = [_]u32{0} ** 2;
284284 const tuple = .{ 1, 2, 3 };
285285
286 testing.expect(isIndexable(@TypeOf(array)));
287 testing.expect(isIndexable(@TypeOf(&array)));
288 testing.expect(isIndexable(@TypeOf(slice)));
289 testing.expect(!isIndexable(meta.Child(@TypeOf(slice))));
290 testing.expect(isIndexable(@TypeOf(vector)));
291 testing.expect(isIndexable(@TypeOf(tuple)));
286 try testing.expect(isIndexable(@TypeOf(array)));
287 try testing.expect(isIndexable(@TypeOf(&array)));
288 try testing.expect(isIndexable(@TypeOf(slice)));
289 try testing.expect(!isIndexable(meta.Child(@TypeOf(slice))));
290 try testing.expect(isIndexable(@TypeOf(vector)));
291 try testing.expect(isIndexable(@TypeOf(tuple)));
292292}
293293
294294pub fn isNumber(comptime T: type) bool {
......@@ -317,13 +317,13 @@ test "std.meta.trait.isNumber" {
317317 number: u8,
318318 };
319319
320 testing.expect(isNumber(u32));
321 testing.expect(isNumber(f32));
322 testing.expect(isNumber(u64));
323 testing.expect(isNumber(@TypeOf(102)));
324 testing.expect(isNumber(@TypeOf(102.123)));
325 testing.expect(!isNumber([]u8));
326 testing.expect(!isNumber(NotANumber));
320 try testing.expect(isNumber(u32));
321 try testing.expect(isNumber(f32));
322 try testing.expect(isNumber(u64));
323 try testing.expect(isNumber(@TypeOf(102)));
324 try testing.expect(isNumber(@TypeOf(102.123)));
325 try testing.expect(!isNumber([]u8));
326 try testing.expect(!isNumber(NotANumber));
327327}
328328
329329pub fn isIntegral(comptime T: type) bool {
......@@ -334,12 +334,12 @@ pub fn isIntegral(comptime T: type) bool {
334334}
335335
336336test "isIntegral" {
337 testing.expect(isIntegral(u32));
338 testing.expect(!isIntegral(f32));
339 testing.expect(isIntegral(@TypeOf(102)));
340 testing.expect(!isIntegral(@TypeOf(102.123)));
341 testing.expect(!isIntegral(*u8));
342 testing.expect(!isIntegral([]u8));
337 try testing.expect(isIntegral(u32));
338 try testing.expect(!isIntegral(f32));
339 try testing.expect(isIntegral(@TypeOf(102)));
340 try testing.expect(!isIntegral(@TypeOf(102.123)));
341 try testing.expect(!isIntegral(*u8));
342 try testing.expect(!isIntegral([]u8));
343343}
344344
345345pub fn isFloat(comptime T: type) bool {
......@@ -350,12 +350,12 @@ pub fn isFloat(comptime T: type) bool {
350350}
351351
352352test "isFloat" {
353 testing.expect(!isFloat(u32));
354 testing.expect(isFloat(f32));
355 testing.expect(!isFloat(@TypeOf(102)));
356 testing.expect(isFloat(@TypeOf(102.123)));
357 testing.expect(!isFloat(*f64));
358 testing.expect(!isFloat([]f32));
353 try testing.expect(!isFloat(u32));
354 try testing.expect(isFloat(f32));
355 try testing.expect(!isFloat(@TypeOf(102)));
356 try testing.expect(isFloat(@TypeOf(102.123)));
357 try testing.expect(!isFloat(*f64));
358 try testing.expect(!isFloat([]f32));
359359}
360360
361361pub fn isConstPtr(comptime T: type) bool {
......@@ -366,10 +366,10 @@ pub fn isConstPtr(comptime T: type) bool {
366366test "std.meta.trait.isConstPtr" {
367367 var t = @as(u8, 0);
368368 const c = @as(u8, 0);
369 testing.expect(isConstPtr(*const @TypeOf(t)));
370 testing.expect(isConstPtr(@TypeOf(&c)));
371 testing.expect(!isConstPtr(*@TypeOf(t)));
372 testing.expect(!isConstPtr(@TypeOf(6)));
369 try testing.expect(isConstPtr(*const @TypeOf(t)));
370 try testing.expect(isConstPtr(@TypeOf(&c)));
371 try testing.expect(!isConstPtr(*@TypeOf(t)));
372 try testing.expect(!isConstPtr(@TypeOf(6)));
373373}
374374
375375pub fn isContainer(comptime T: type) bool {
......@@ -389,10 +389,10 @@ test "std.meta.trait.isContainer" {
389389 B,
390390 };
391391
392 testing.expect(isContainer(TestStruct));
393 testing.expect(isContainer(TestUnion));
394 testing.expect(isContainer(TestEnum));
395 testing.expect(!isContainer(u8));
392 try testing.expect(isContainer(TestStruct));
393 try testing.expect(isContainer(TestUnion));
394 try testing.expect(isContainer(TestEnum));
395 try testing.expect(!isContainer(u8));
396396}
397397
398398pub fn isTuple(comptime T: type) bool {
......@@ -403,9 +403,9 @@ test "std.meta.trait.isTuple" {
403403 const t1 = struct {};
404404 const t2 = .{ .a = 0 };
405405 const t3 = .{ 1, 2, 3 };
406 testing.expect(!isTuple(t1));
407 testing.expect(!isTuple(@TypeOf(t2)));
408 testing.expect(isTuple(@TypeOf(t3)));
406 try testing.expect(!isTuple(t1));
407 try testing.expect(!isTuple(@TypeOf(t2)));
408 try testing.expect(isTuple(@TypeOf(t3)));
409409}
410410
411411/// Returns true if the passed type will coerce to []const u8.
......@@ -449,41 +449,41 @@ pub fn isZigString(comptime T: type) bool {
449449}
450450
451451test "std.meta.trait.isZigString" {
452 testing.expect(isZigString([]const u8));
453 testing.expect(isZigString([]u8));
454 testing.expect(isZigString([:0]const u8));
455 testing.expect(isZigString([:0]u8));
456 testing.expect(isZigString([:5]const u8));
457 testing.expect(isZigString([:5]u8));
458 testing.expect(isZigString(*const [0]u8));
459 testing.expect(isZigString(*[0]u8));
460 testing.expect(isZigString(*const [0:0]u8));
461 testing.expect(isZigString(*[0:0]u8));
462 testing.expect(isZigString(*const [0:5]u8));
463 testing.expect(isZigString(*[0:5]u8));
464 testing.expect(isZigString(*const [10]u8));
465 testing.expect(isZigString(*[10]u8));
466 testing.expect(isZigString(*const [10:0]u8));
467 testing.expect(isZigString(*[10:0]u8));
468 testing.expect(isZigString(*const [10:5]u8));
469 testing.expect(isZigString(*[10:5]u8));
470
471 testing.expect(!isZigString(u8));
472 testing.expect(!isZigString([4]u8));
473 testing.expect(!isZigString([4:0]u8));
474 testing.expect(!isZigString([*]const u8));
475 testing.expect(!isZigString([*]const [4]u8));
476 testing.expect(!isZigString([*c]const u8));
477 testing.expect(!isZigString([*c]const [4]u8));
478 testing.expect(!isZigString([*:0]const u8));
479 testing.expect(!isZigString([*:0]const u8));
480 testing.expect(!isZigString(*[]const u8));
481 testing.expect(!isZigString(?[]const u8));
482 testing.expect(!isZigString(?*const [4]u8));
483 testing.expect(!isZigString([]allowzero u8));
484 testing.expect(!isZigString([]volatile u8));
485 testing.expect(!isZigString(*allowzero [4]u8));
486 testing.expect(!isZigString(*volatile [4]u8));
452 try testing.expect(isZigString([]const u8));
453 try testing.expect(isZigString([]u8));
454 try testing.expect(isZigString([:0]const u8));
455 try testing.expect(isZigString([:0]u8));
456 try testing.expect(isZigString([:5]const u8));
457 try testing.expect(isZigString([:5]u8));
458 try testing.expect(isZigString(*const [0]u8));
459 try testing.expect(isZigString(*[0]u8));
460 try testing.expect(isZigString(*const [0:0]u8));
461 try testing.expect(isZigString(*[0:0]u8));
462 try testing.expect(isZigString(*const [0:5]u8));
463 try testing.expect(isZigString(*[0:5]u8));
464 try testing.expect(isZigString(*const [10]u8));
465 try testing.expect(isZigString(*[10]u8));
466 try testing.expect(isZigString(*const [10:0]u8));
467 try testing.expect(isZigString(*[10:0]u8));
468 try testing.expect(isZigString(*const [10:5]u8));
469 try testing.expect(isZigString(*[10:5]u8));
470
471 try testing.expect(!isZigString(u8));
472 try testing.expect(!isZigString([4]u8));
473 try testing.expect(!isZigString([4:0]u8));
474 try testing.expect(!isZigString([*]const u8));
475 try testing.expect(!isZigString([*]const [4]u8));
476 try testing.expect(!isZigString([*c]const u8));
477 try testing.expect(!isZigString([*c]const [4]u8));
478 try testing.expect(!isZigString([*:0]const u8));
479 try testing.expect(!isZigString([*:0]const u8));
480 try testing.expect(!isZigString(*[]const u8));
481 try testing.expect(!isZigString(?[]const u8));
482 try testing.expect(!isZigString(?*const [4]u8));
483 try testing.expect(!isZigString([]allowzero u8));
484 try testing.expect(!isZigString([]volatile u8));
485 try testing.expect(!isZigString(*allowzero [4]u8));
486 try testing.expect(!isZigString(*volatile [4]u8));
487487}
488488
489489pub fn hasDecls(comptime T: type, comptime names: anytype) bool {
......@@ -505,11 +505,11 @@ test "std.meta.trait.hasDecls" {
505505
506506 const tuple = .{ "a", "b", "c" };
507507
508 testing.expect(!hasDecls(TestStruct1, .{"a"}));
509 testing.expect(hasDecls(TestStruct2, .{ "a", "b" }));
510 testing.expect(hasDecls(TestStruct2, .{ "a", "b", "useless" }));
511 testing.expect(!hasDecls(TestStruct2, .{ "a", "b", "c" }));
512 testing.expect(!hasDecls(TestStruct2, tuple));
508 try testing.expect(!hasDecls(TestStruct1, .{"a"}));
509 try testing.expect(hasDecls(TestStruct2, .{ "a", "b" }));
510 try testing.expect(hasDecls(TestStruct2, .{ "a", "b", "useless" }));
511 try testing.expect(!hasDecls(TestStruct2, .{ "a", "b", "c" }));
512 try testing.expect(!hasDecls(TestStruct2, tuple));
513513}
514514
515515pub fn hasFields(comptime T: type, comptime names: anytype) bool {
......@@ -531,11 +531,11 @@ test "std.meta.trait.hasFields" {
531531
532532 const tuple = .{ "a", "b", "c" };
533533
534 testing.expect(!hasFields(TestStruct1, .{"a"}));
535 testing.expect(hasFields(TestStruct2, .{ "a", "b" }));
536 testing.expect(hasFields(TestStruct2, .{ "a", "b", "c" }));
537 testing.expect(hasFields(TestStruct2, tuple));
538 testing.expect(!hasFields(TestStruct2, .{ "a", "b", "useless" }));
534 try testing.expect(!hasFields(TestStruct1, .{"a"}));
535 try testing.expect(hasFields(TestStruct2, .{ "a", "b" }));
536 try testing.expect(hasFields(TestStruct2, .{ "a", "b", "c" }));
537 try testing.expect(hasFields(TestStruct2, tuple));
538 try testing.expect(!hasFields(TestStruct2, .{ "a", "b", "useless" }));
539539}
540540
541541pub fn hasFunctions(comptime T: type, comptime names: anytype) bool {
......@@ -555,10 +555,10 @@ test "std.meta.trait.hasFunctions" {
555555
556556 const tuple = .{ "a", "b", "c" };
557557
558 testing.expect(!hasFunctions(TestStruct1, .{"a"}));
559 testing.expect(hasFunctions(TestStruct2, .{ "a", "b" }));
560 testing.expect(!hasFunctions(TestStruct2, .{ "a", "b", "c" }));
561 testing.expect(!hasFunctions(TestStruct2, tuple));
558 try testing.expect(!hasFunctions(TestStruct1, .{"a"}));
559 try testing.expect(hasFunctions(TestStruct2, .{ "a", "b" }));
560 try testing.expect(!hasFunctions(TestStruct2, .{ "a", "b", "c" }));
561 try testing.expect(!hasFunctions(TestStruct2, tuple));
562562}
563563
564564/// True if every value of the type `T` has a unique bit pattern representing it.
......@@ -606,65 +606,65 @@ test "std.meta.trait.hasUniqueRepresentation" {
606606 b: u32,
607607 };
608608
609 testing.expect(hasUniqueRepresentation(TestStruct1));
609 try testing.expect(hasUniqueRepresentation(TestStruct1));
610610
611611 const TestStruct2 = struct {
612612 a: u32,
613613 b: u16,
614614 };
615615
616 testing.expect(!hasUniqueRepresentation(TestStruct2));
616 try testing.expect(!hasUniqueRepresentation(TestStruct2));
617617
618618 const TestStruct3 = struct {
619619 a: u32,
620620 b: u32,
621621 };
622622
623 testing.expect(hasUniqueRepresentation(TestStruct3));
623 try testing.expect(hasUniqueRepresentation(TestStruct3));
624624
625625 const TestStruct4 = struct { a: []const u8 };
626626
627 testing.expect(!hasUniqueRepresentation(TestStruct4));
627 try testing.expect(!hasUniqueRepresentation(TestStruct4));
628628
629629 const TestStruct5 = struct { a: TestStruct4 };
630630
631 testing.expect(!hasUniqueRepresentation(TestStruct5));
631 try testing.expect(!hasUniqueRepresentation(TestStruct5));
632632
633633 const TestUnion1 = packed union {
634634 a: u32,
635635 b: u16,
636636 };
637637
638 testing.expect(!hasUniqueRepresentation(TestUnion1));
638 try testing.expect(!hasUniqueRepresentation(TestUnion1));
639639
640640 const TestUnion2 = extern union {
641641 a: u32,
642642 b: u16,
643643 };
644644
645 testing.expect(!hasUniqueRepresentation(TestUnion2));
645 try testing.expect(!hasUniqueRepresentation(TestUnion2));
646646
647647 const TestUnion3 = union {
648648 a: u32,
649649 b: u16,
650650 };
651651
652 testing.expect(!hasUniqueRepresentation(TestUnion3));
652 try testing.expect(!hasUniqueRepresentation(TestUnion3));
653653
654654 const TestUnion4 = union(enum) {
655655 a: u32,
656656 b: u16,
657657 };
658658
659 testing.expect(!hasUniqueRepresentation(TestUnion4));
659 try testing.expect(!hasUniqueRepresentation(TestUnion4));
660660
661661 inline for ([_]type{ i0, u8, i16, u32, i64 }) |T| {
662 testing.expect(hasUniqueRepresentation(T));
662 try testing.expect(hasUniqueRepresentation(T));
663663 }
664664 inline for ([_]type{ i1, u9, i17, u33, i24 }) |T| {
665 testing.expect(!hasUniqueRepresentation(T));
665 try testing.expect(!hasUniqueRepresentation(T));
666666 }
667667
668 testing.expect(!hasUniqueRepresentation([]u8));
669 testing.expect(!hasUniqueRepresentation([]const u8));
668 try testing.expect(!hasUniqueRepresentation([]u8));
669 try testing.expect(!hasUniqueRepresentation([]const u8));
670670}
lib/std/multi_array_list.zig+57-57
......@@ -312,7 +312,7 @@ test "basic usage" {
312312 var list = MultiArrayList(Foo){};
313313 defer list.deinit(ally);
314314
315 testing.expectEqual(@as(usize, 0), list.items(.a).len);
315 try testing.expectEqual(@as(usize, 0), list.items(.a).len);
316316
317317 try list.ensureTotalCapacity(ally, 2);
318318
......@@ -328,12 +328,12 @@ test "basic usage" {
328328 .c = 'b',
329329 });
330330
331 testing.expectEqualSlices(u32, list.items(.a), &[_]u32{ 1, 2 });
332 testing.expectEqualSlices(u8, list.items(.c), &[_]u8{ 'a', 'b' });
331 try testing.expectEqualSlices(u32, list.items(.a), &[_]u32{ 1, 2 });
332 try testing.expectEqualSlices(u8, list.items(.c), &[_]u8{ 'a', 'b' });
333333
334 testing.expectEqual(@as(usize, 2), list.items(.b).len);
335 testing.expectEqualStrings("foobar", list.items(.b)[0]);
336 testing.expectEqualStrings("zigzag", list.items(.b)[1]);
334 try testing.expectEqual(@as(usize, 2), list.items(.b).len);
335 try testing.expectEqualStrings("foobar", list.items(.b)[0]);
336 try testing.expectEqualStrings("zigzag", list.items(.b)[1]);
337337
338338 try list.append(ally, .{
339339 .a = 3,
......@@ -341,13 +341,13 @@ test "basic usage" {
341341 .c = 'c',
342342 });
343343
344 testing.expectEqualSlices(u32, list.items(.a), &[_]u32{ 1, 2, 3 });
345 testing.expectEqualSlices(u8, list.items(.c), &[_]u8{ 'a', 'b', 'c' });
344 try testing.expectEqualSlices(u32, list.items(.a), &[_]u32{ 1, 2, 3 });
345 try testing.expectEqualSlices(u8, list.items(.c), &[_]u8{ 'a', 'b', 'c' });
346346
347 testing.expectEqual(@as(usize, 3), list.items(.b).len);
348 testing.expectEqualStrings("foobar", list.items(.b)[0]);
349 testing.expectEqualStrings("zigzag", list.items(.b)[1]);
350 testing.expectEqualStrings("fizzbuzz", list.items(.b)[2]);
347 try testing.expectEqual(@as(usize, 3), list.items(.b).len);
348 try testing.expectEqualStrings("foobar", list.items(.b)[0]);
349 try testing.expectEqualStrings("zigzag", list.items(.b)[1]);
350 try testing.expectEqualStrings("fizzbuzz", list.items(.b)[2]);
351351
352352 // Add 6 more things to force a capacity increase.
353353 var i: usize = 0;
......@@ -359,12 +359,12 @@ test "basic usage" {
359359 });
360360 }
361361
362 testing.expectEqualSlices(
362 try testing.expectEqualSlices(
363363 u32,
364364 &[_]u32{ 1, 2, 3, 4, 5, 6, 7, 8, 9 },
365365 list.items(.a),
366366 );
367 testing.expectEqualSlices(
367 try testing.expectEqualSlices(
368368 u8,
369369 &[_]u8{ 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i' },
370370 list.items(.c),
......@@ -372,13 +372,13 @@ test "basic usage" {
372372
373373 list.shrinkAndFree(ally, 3);
374374
375 testing.expectEqualSlices(u32, list.items(.a), &[_]u32{ 1, 2, 3 });
376 testing.expectEqualSlices(u8, list.items(.c), &[_]u8{ 'a', 'b', 'c' });
375 try testing.expectEqualSlices(u32, list.items(.a), &[_]u32{ 1, 2, 3 });
376 try testing.expectEqualSlices(u8, list.items(.c), &[_]u8{ 'a', 'b', 'c' });
377377
378 testing.expectEqual(@as(usize, 3), list.items(.b).len);
379 testing.expectEqualStrings("foobar", list.items(.b)[0]);
380 testing.expectEqualStrings("zigzag", list.items(.b)[1]);
381 testing.expectEqualStrings("fizzbuzz", list.items(.b)[2]);
378 try testing.expectEqual(@as(usize, 3), list.items(.b).len);
379 try testing.expectEqualStrings("foobar", list.items(.b)[0]);
380 try testing.expectEqualStrings("zigzag", list.items(.b)[1]);
381 try testing.expectEqualStrings("fizzbuzz", list.items(.b)[2]);
382382}
383383
384384// This was observed to fail on aarch64 with LLVM 11, when the capacityInBytes
......@@ -427,37 +427,37 @@ test "regression test for @reduce bug" {
427427 try list.append(ally, .{ .tag = .eof, .start = 123 });
428428
429429 const tags = list.items(.tag);
430 testing.expectEqual(tags[1], .identifier);
431 testing.expectEqual(tags[2], .equal);
432 testing.expectEqual(tags[3], .builtin);
433 testing.expectEqual(tags[4], .l_paren);
434 testing.expectEqual(tags[5], .string_literal);
435 testing.expectEqual(tags[6], .r_paren);
436 testing.expectEqual(tags[7], .semicolon);
437 testing.expectEqual(tags[8], .keyword_pub);
438 testing.expectEqual(tags[9], .keyword_fn);
439 testing.expectEqual(tags[10], .identifier);
440 testing.expectEqual(tags[11], .l_paren);
441 testing.expectEqual(tags[12], .r_paren);
442 testing.expectEqual(tags[13], .identifier);
443 testing.expectEqual(tags[14], .bang);
444 testing.expectEqual(tags[15], .identifier);
445 testing.expectEqual(tags[16], .l_brace);
446 testing.expectEqual(tags[17], .identifier);
447 testing.expectEqual(tags[18], .period);
448 testing.expectEqual(tags[19], .identifier);
449 testing.expectEqual(tags[20], .period);
450 testing.expectEqual(tags[21], .identifier);
451 testing.expectEqual(tags[22], .l_paren);
452 testing.expectEqual(tags[23], .string_literal);
453 testing.expectEqual(tags[24], .comma);
454 testing.expectEqual(tags[25], .period);
455 testing.expectEqual(tags[26], .l_brace);
456 testing.expectEqual(tags[27], .r_brace);
457 testing.expectEqual(tags[28], .r_paren);
458 testing.expectEqual(tags[29], .semicolon);
459 testing.expectEqual(tags[30], .r_brace);
460 testing.expectEqual(tags[31], .eof);
430 try testing.expectEqual(tags[1], .identifier);
431 try testing.expectEqual(tags[2], .equal);
432 try testing.expectEqual(tags[3], .builtin);
433 try testing.expectEqual(tags[4], .l_paren);
434 try testing.expectEqual(tags[5], .string_literal);
435 try testing.expectEqual(tags[6], .r_paren);
436 try testing.expectEqual(tags[7], .semicolon);
437 try testing.expectEqual(tags[8], .keyword_pub);
438 try testing.expectEqual(tags[9], .keyword_fn);
439 try testing.expectEqual(tags[10], .identifier);
440 try testing.expectEqual(tags[11], .l_paren);
441 try testing.expectEqual(tags[12], .r_paren);
442 try testing.expectEqual(tags[13], .identifier);
443 try testing.expectEqual(tags[14], .bang);
444 try testing.expectEqual(tags[15], .identifier);
445 try testing.expectEqual(tags[16], .l_brace);
446 try testing.expectEqual(tags[17], .identifier);
447 try testing.expectEqual(tags[18], .period);
448 try testing.expectEqual(tags[19], .identifier);
449 try testing.expectEqual(tags[20], .period);
450 try testing.expectEqual(tags[21], .identifier);
451 try testing.expectEqual(tags[22], .l_paren);
452 try testing.expectEqual(tags[23], .string_literal);
453 try testing.expectEqual(tags[24], .comma);
454 try testing.expectEqual(tags[25], .period);
455 try testing.expectEqual(tags[26], .l_brace);
456 try testing.expectEqual(tags[27], .r_brace);
457 try testing.expectEqual(tags[28], .r_paren);
458 try testing.expectEqual(tags[29], .semicolon);
459 try testing.expectEqual(tags[30], .r_brace);
460 try testing.expectEqual(tags[31], .eof);
461461}
462462
463463test "ensure capacity on empty list" {
......@@ -475,15 +475,15 @@ test "ensure capacity on empty list" {
475475 list.appendAssumeCapacity(.{ .a = 1, .b = 2 });
476476 list.appendAssumeCapacity(.{ .a = 3, .b = 4 });
477477
478 testing.expectEqualSlices(u32, &[_]u32{ 1, 3 }, list.items(.a));
479 testing.expectEqualSlices(u8, &[_]u8{ 2, 4 }, list.items(.b));
478 try testing.expectEqualSlices(u32, &[_]u32{ 1, 3 }, list.items(.a));
479 try testing.expectEqualSlices(u8, &[_]u8{ 2, 4 }, list.items(.b));
480480
481481 list.len = 0;
482482 list.appendAssumeCapacity(.{ .a = 5, .b = 6 });
483483 list.appendAssumeCapacity(.{ .a = 7, .b = 8 });
484484
485 testing.expectEqualSlices(u32, &[_]u32{ 5, 7 }, list.items(.a));
486 testing.expectEqualSlices(u8, &[_]u8{ 6, 8 }, list.items(.b));
485 try testing.expectEqualSlices(u32, &[_]u32{ 5, 7 }, list.items(.a));
486 try testing.expectEqualSlices(u8, &[_]u8{ 6, 8 }, list.items(.b));
487487
488488 list.len = 0;
489489 try list.ensureTotalCapacity(ally, 16);
......@@ -491,6 +491,6 @@ test "ensure capacity on empty list" {
491491 list.appendAssumeCapacity(.{ .a = 9, .b = 10 });
492492 list.appendAssumeCapacity(.{ .a = 11, .b = 12 });
493493
494 testing.expectEqualSlices(u32, &[_]u32{ 9, 11 }, list.items(.a));
495 testing.expectEqualSlices(u8, &[_]u8{ 10, 12 }, list.items(.b));
494 try testing.expectEqualSlices(u32, &[_]u32{ 9, 11 }, list.items(.a));
495 try testing.expectEqualSlices(u8, &[_]u8{ 10, 12 }, list.items(.b));
496496}
lib/std/net/test.zig+24-24
......@@ -38,26 +38,26 @@ test "parse and render IPv6 addresses" {
3838 for (ips) |ip, i| {
3939 var addr = net.Address.parseIp6(ip, 0) catch unreachable;
4040 var newIp = std.fmt.bufPrint(buffer[0..], "{}", .{addr}) catch unreachable;
41 std.testing.expect(std.mem.eql(u8, printed[i], newIp[1 .. newIp.len - 3]));
41 try std.testing.expect(std.mem.eql(u8, printed[i], newIp[1 .. newIp.len - 3]));
4242
4343 if (std.builtin.os.tag == .linux) {
4444 var addr_via_resolve = net.Address.resolveIp6(ip, 0) catch unreachable;
4545 var newResolvedIp = std.fmt.bufPrint(buffer[0..], "{}", .{addr_via_resolve}) catch unreachable;
46 std.testing.expect(std.mem.eql(u8, printed[i], newResolvedIp[1 .. newResolvedIp.len - 3]));
46 try std.testing.expect(std.mem.eql(u8, printed[i], newResolvedIp[1 .. newResolvedIp.len - 3]));
4747 }
4848 }
4949
50 testing.expectError(error.InvalidCharacter, net.Address.parseIp6(":::", 0));
51 testing.expectError(error.Overflow, net.Address.parseIp6("FF001::FB", 0));
52 testing.expectError(error.InvalidCharacter, net.Address.parseIp6("FF01::Fb:zig", 0));
53 testing.expectError(error.InvalidEnd, net.Address.parseIp6("FF01:0:0:0:0:0:0:FB:", 0));
54 testing.expectError(error.Incomplete, net.Address.parseIp6("FF01:", 0));
55 testing.expectError(error.InvalidIpv4Mapping, net.Address.parseIp6("::123.123.123.123", 0));
50 try testing.expectError(error.InvalidCharacter, net.Address.parseIp6(":::", 0));
51 try testing.expectError(error.Overflow, net.Address.parseIp6("FF001::FB", 0));
52 try testing.expectError(error.InvalidCharacter, net.Address.parseIp6("FF01::Fb:zig", 0));
53 try testing.expectError(error.InvalidEnd, net.Address.parseIp6("FF01:0:0:0:0:0:0:FB:", 0));
54 try testing.expectError(error.Incomplete, net.Address.parseIp6("FF01:", 0));
55 try testing.expectError(error.InvalidIpv4Mapping, net.Address.parseIp6("::123.123.123.123", 0));
5656 // TODO Make this test pass on other operating systems.
5757 if (std.builtin.os.tag == .linux) {
58 testing.expectError(error.Incomplete, net.Address.resolveIp6("ff01::fb%", 0));
59 testing.expectError(error.Overflow, net.Address.resolveIp6("ff01::fb%wlp3s0s0s0s0s0s0s0s0", 0));
60 testing.expectError(error.Overflow, net.Address.resolveIp6("ff01::fb%12345678901234", 0));
58 try testing.expectError(error.Incomplete, net.Address.resolveIp6("ff01::fb%", 0));
59 try testing.expectError(error.Overflow, net.Address.resolveIp6("ff01::fb%wlp3s0s0s0s0s0s0s0s0", 0));
60 try testing.expectError(error.Overflow, net.Address.resolveIp6("ff01::fb%12345678901234", 0));
6161 }
6262}
6363
......@@ -68,7 +68,7 @@ test "invalid but parseable IPv6 scope ids" {
6868 return error.SkipZigTest;
6969 }
7070
71 testing.expectError(error.InterfaceNotFound, net.Address.resolveIp6("ff01::fb%123s45678901234", 0));
71 try testing.expectError(error.InterfaceNotFound, net.Address.resolveIp6("ff01::fb%123s45678901234", 0));
7272}
7373
7474test "parse and render IPv4 addresses" {
......@@ -84,14 +84,14 @@ test "parse and render IPv4 addresses" {
8484 }) |ip| {
8585 var addr = net.Address.parseIp4(ip, 0) catch unreachable;
8686 var newIp = std.fmt.bufPrint(buffer[0..], "{}", .{addr}) catch unreachable;
87 std.testing.expect(std.mem.eql(u8, ip, newIp[0 .. newIp.len - 2]));
87 try std.testing.expect(std.mem.eql(u8, ip, newIp[0 .. newIp.len - 2]));
8888 }
8989
90 testing.expectError(error.Overflow, net.Address.parseIp4("256.0.0.1", 0));
91 testing.expectError(error.InvalidCharacter, net.Address.parseIp4("x.0.0.1", 0));
92 testing.expectError(error.InvalidEnd, net.Address.parseIp4("127.0.0.1.1", 0));
93 testing.expectError(error.Incomplete, net.Address.parseIp4("127.0.0.", 0));
94 testing.expectError(error.InvalidCharacter, net.Address.parseIp4("100..0.1", 0));
90 try testing.expectError(error.Overflow, net.Address.parseIp4("256.0.0.1", 0));
91 try testing.expectError(error.InvalidCharacter, net.Address.parseIp4("x.0.0.1", 0));
92 try testing.expectError(error.InvalidEnd, net.Address.parseIp4("127.0.0.1.1", 0));
93 try testing.expectError(error.Incomplete, net.Address.parseIp4("127.0.0.", 0));
94 try testing.expectError(error.InvalidCharacter, net.Address.parseIp4("100..0.1", 0));
9595}
9696
9797test "resolve DNS" {
......@@ -169,8 +169,8 @@ test "listen on a port, send bytes, receive bytes" {
169169 var buf: [16]u8 = undefined;
170170 const n = try client.stream.reader().read(&buf);
171171
172 testing.expectEqual(@as(usize, 12), n);
173 testing.expectEqualSlices(u8, "Hello world!", buf[0..n]);
172 try testing.expectEqual(@as(usize, 12), n);
173 try testing.expectEqualSlices(u8, "Hello world!", buf[0..n]);
174174}
175175
176176test "listen on a port, send bytes, receive bytes" {
......@@ -230,7 +230,7 @@ fn testClientToHost(allocator: *mem.Allocator, name: []const u8, port: u16) anye
230230 var buf: [100]u8 = undefined;
231231 const len = try connection.read(&buf);
232232 const msg = buf[0..len];
233 testing.expect(mem.eql(u8, msg, "hello from server\n"));
233 try testing.expect(mem.eql(u8, msg, "hello from server\n"));
234234}
235235
236236fn testClient(addr: net.Address) anyerror!void {
......@@ -242,7 +242,7 @@ fn testClient(addr: net.Address) anyerror!void {
242242 var buf: [100]u8 = undefined;
243243 const len = try socket_file.read(&buf);
244244 const msg = buf[0..len];
245 testing.expect(mem.eql(u8, msg, "hello from server\n"));
245 try testing.expect(mem.eql(u8, msg, "hello from server\n"));
246246}
247247
248248fn testServer(server: *net.StreamServer) anyerror!void {
......@@ -293,6 +293,6 @@ test "listen on a unix socket, send bytes, receive bytes" {
293293 var buf: [16]u8 = undefined;
294294 const n = try client.stream.reader().read(&buf);
295295
296 testing.expectEqual(@as(usize, 12), n);
297 testing.expectEqualSlices(u8, "Hello world!", buf[0..n]);
296 try testing.expectEqual(@as(usize, 12), n);
297 try testing.expectEqualSlices(u8, "Hello world!", buf[0..n]);
298298}
lib/std/once.zig+1-1
......@@ -67,5 +67,5 @@ test "Once executes its function just once" {
6767 }
6868 }
6969
70 testing.expectEqual(@as(i32, 1), global_number);
70 try testing.expectEqual(@as(i32, 1), global_number);
7171}
lib/std/os/linux/bpf.zig+100-100
......@@ -737,11 +737,11 @@ pub const Insn = packed struct {
737737};
738738
739739test "insn bitsize" {
740 expectEqual(@bitSizeOf(Insn), 64);
740 try expectEqual(@bitSizeOf(Insn), 64);
741741}
742742
743fn expect_opcode(code: u8, insn: Insn) void {
744 expectEqual(code, insn.code);
743fn expect_opcode(code: u8, insn: Insn) !void {
744 try expectEqual(code, insn.code);
745745}
746746
747747// The opcodes were grabbed from https://github.com/iovisor/bpf-docs/blob/master/eBPF.md
......@@ -750,108 +750,108 @@ test "opcodes" {
750750 // loading 64-bit immediates (imm is only 32 bits wide)
751751
752752 // alu instructions
753 expect_opcode(0x07, Insn.add(.r1, 0));
754 expect_opcode(0x0f, Insn.add(.r1, .r2));
755 expect_opcode(0x17, Insn.sub(.r1, 0));
756 expect_opcode(0x1f, Insn.sub(.r1, .r2));
757 expect_opcode(0x27, Insn.mul(.r1, 0));
758 expect_opcode(0x2f, Insn.mul(.r1, .r2));
759 expect_opcode(0x37, Insn.div(.r1, 0));
760 expect_opcode(0x3f, Insn.div(.r1, .r2));
761 expect_opcode(0x47, Insn.alu_or(.r1, 0));
762 expect_opcode(0x4f, Insn.alu_or(.r1, .r2));
763 expect_opcode(0x57, Insn.alu_and(.r1, 0));
764 expect_opcode(0x5f, Insn.alu_and(.r1, .r2));
765 expect_opcode(0x67, Insn.lsh(.r1, 0));
766 expect_opcode(0x6f, Insn.lsh(.r1, .r2));
767 expect_opcode(0x77, Insn.rsh(.r1, 0));
768 expect_opcode(0x7f, Insn.rsh(.r1, .r2));
769 expect_opcode(0x87, Insn.neg(.r1));
770 expect_opcode(0x97, Insn.mod(.r1, 0));
771 expect_opcode(0x9f, Insn.mod(.r1, .r2));
772 expect_opcode(0xa7, Insn.xor(.r1, 0));
773 expect_opcode(0xaf, Insn.xor(.r1, .r2));
774 expect_opcode(0xb7, Insn.mov(.r1, 0));
775 expect_opcode(0xbf, Insn.mov(.r1, .r2));
776 expect_opcode(0xc7, Insn.arsh(.r1, 0));
777 expect_opcode(0xcf, Insn.arsh(.r1, .r2));
753 try expect_opcode(0x07, Insn.add(.r1, 0));
754 try expect_opcode(0x0f, Insn.add(.r1, .r2));
755 try expect_opcode(0x17, Insn.sub(.r1, 0));
756 try expect_opcode(0x1f, Insn.sub(.r1, .r2));
757 try expect_opcode(0x27, Insn.mul(.r1, 0));
758 try expect_opcode(0x2f, Insn.mul(.r1, .r2));
759 try expect_opcode(0x37, Insn.div(.r1, 0));
760 try expect_opcode(0x3f, Insn.div(.r1, .r2));
761 try expect_opcode(0x47, Insn.alu_or(.r1, 0));
762 try expect_opcode(0x4f, Insn.alu_or(.r1, .r2));
763 try expect_opcode(0x57, Insn.alu_and(.r1, 0));
764 try expect_opcode(0x5f, Insn.alu_and(.r1, .r2));
765 try expect_opcode(0x67, Insn.lsh(.r1, 0));
766 try expect_opcode(0x6f, Insn.lsh(.r1, .r2));
767 try expect_opcode(0x77, Insn.rsh(.r1, 0));
768 try expect_opcode(0x7f, Insn.rsh(.r1, .r2));
769 try expect_opcode(0x87, Insn.neg(.r1));
770 try expect_opcode(0x97, Insn.mod(.r1, 0));
771 try expect_opcode(0x9f, Insn.mod(.r1, .r2));
772 try expect_opcode(0xa7, Insn.xor(.r1, 0));
773 try expect_opcode(0xaf, Insn.xor(.r1, .r2));
774 try expect_opcode(0xb7, Insn.mov(.r1, 0));
775 try expect_opcode(0xbf, Insn.mov(.r1, .r2));
776 try expect_opcode(0xc7, Insn.arsh(.r1, 0));
777 try expect_opcode(0xcf, Insn.arsh(.r1, .r2));
778778
779779 // atomic instructions: might be more of these not documented in the wild
780 expect_opcode(0xdb, Insn.xadd(.r1, .r2));
780 try expect_opcode(0xdb, Insn.xadd(.r1, .r2));
781781
782782 // TODO: byteswap instructions
783 expect_opcode(0xd4, Insn.le(.half_word, .r1));
784 expectEqual(@intCast(i32, 16), Insn.le(.half_word, .r1).imm);
785 expect_opcode(0xd4, Insn.le(.word, .r1));
786 expectEqual(@intCast(i32, 32), Insn.le(.word, .r1).imm);
787 expect_opcode(0xd4, Insn.le(.double_word, .r1));
788 expectEqual(@intCast(i32, 64), Insn.le(.double_word, .r1).imm);
789 expect_opcode(0xdc, Insn.be(.half_word, .r1));
790 expectEqual(@intCast(i32, 16), Insn.be(.half_word, .r1).imm);
791 expect_opcode(0xdc, Insn.be(.word, .r1));
792 expectEqual(@intCast(i32, 32), Insn.be(.word, .r1).imm);
793 expect_opcode(0xdc, Insn.be(.double_word, .r1));
794 expectEqual(@intCast(i32, 64), Insn.be(.double_word, .r1).imm);
783 try expect_opcode(0xd4, Insn.le(.half_word, .r1));
784 try expectEqual(@intCast(i32, 16), Insn.le(.half_word, .r1).imm);
785 try expect_opcode(0xd4, Insn.le(.word, .r1));
786 try expectEqual(@intCast(i32, 32), Insn.le(.word, .r1).imm);
787 try expect_opcode(0xd4, Insn.le(.double_word, .r1));
788 try expectEqual(@intCast(i32, 64), Insn.le(.double_word, .r1).imm);
789 try expect_opcode(0xdc, Insn.be(.half_word, .r1));
790 try expectEqual(@intCast(i32, 16), Insn.be(.half_word, .r1).imm);
791 try expect_opcode(0xdc, Insn.be(.word, .r1));
792 try expectEqual(@intCast(i32, 32), Insn.be(.word, .r1).imm);
793 try expect_opcode(0xdc, Insn.be(.double_word, .r1));
794 try expectEqual(@intCast(i32, 64), Insn.be(.double_word, .r1).imm);
795795
796796 // memory instructions
797 expect_opcode(0x18, Insn.ld_dw1(.r1, 0));
798 expect_opcode(0x00, Insn.ld_dw2(0));
797 try expect_opcode(0x18, Insn.ld_dw1(.r1, 0));
798 try expect_opcode(0x00, Insn.ld_dw2(0));
799799
800800 // loading a map fd
801 expect_opcode(0x18, Insn.ld_map_fd1(.r1, 0));
802 expectEqual(@intCast(u4, PSEUDO_MAP_FD), Insn.ld_map_fd1(.r1, 0).src);
803 expect_opcode(0x00, Insn.ld_map_fd2(0));
804
805 expect_opcode(0x38, Insn.ld_abs(.double_word, .r1, .r2, 0));
806 expect_opcode(0x20, Insn.ld_abs(.word, .r1, .r2, 0));
807 expect_opcode(0x28, Insn.ld_abs(.half_word, .r1, .r2, 0));
808 expect_opcode(0x30, Insn.ld_abs(.byte, .r1, .r2, 0));
809
810 expect_opcode(0x58, Insn.ld_ind(.double_word, .r1, .r2, 0));
811 expect_opcode(0x40, Insn.ld_ind(.word, .r1, .r2, 0));
812 expect_opcode(0x48, Insn.ld_ind(.half_word, .r1, .r2, 0));
813 expect_opcode(0x50, Insn.ld_ind(.byte, .r1, .r2, 0));
814
815 expect_opcode(0x79, Insn.ldx(.double_word, .r1, .r2, 0));
816 expect_opcode(0x61, Insn.ldx(.word, .r1, .r2, 0));
817 expect_opcode(0x69, Insn.ldx(.half_word, .r1, .r2, 0));
818 expect_opcode(0x71, Insn.ldx(.byte, .r1, .r2, 0));
819
820 expect_opcode(0x62, Insn.st(.word, .r1, 0, 0));
821 expect_opcode(0x6a, Insn.st(.half_word, .r1, 0, 0));
822 expect_opcode(0x72, Insn.st(.byte, .r1, 0, 0));
823
824 expect_opcode(0x63, Insn.stx(.word, .r1, 0, .r2));
825 expect_opcode(0x6b, Insn.stx(.half_word, .r1, 0, .r2));
826 expect_opcode(0x73, Insn.stx(.byte, .r1, 0, .r2));
827 expect_opcode(0x7b, Insn.stx(.double_word, .r1, 0, .r2));
801 try expect_opcode(0x18, Insn.ld_map_fd1(.r1, 0));
802 try expectEqual(@intCast(u4, PSEUDO_MAP_FD), Insn.ld_map_fd1(.r1, 0).src);
803 try expect_opcode(0x00, Insn.ld_map_fd2(0));
804
805 try expect_opcode(0x38, Insn.ld_abs(.double_word, .r1, .r2, 0));
806 try expect_opcode(0x20, Insn.ld_abs(.word, .r1, .r2, 0));
807 try expect_opcode(0x28, Insn.ld_abs(.half_word, .r1, .r2, 0));
808 try expect_opcode(0x30, Insn.ld_abs(.byte, .r1, .r2, 0));
809
810 try expect_opcode(0x58, Insn.ld_ind(.double_word, .r1, .r2, 0));
811 try expect_opcode(0x40, Insn.ld_ind(.word, .r1, .r2, 0));
812 try expect_opcode(0x48, Insn.ld_ind(.half_word, .r1, .r2, 0));
813 try expect_opcode(0x50, Insn.ld_ind(.byte, .r1, .r2, 0));
814
815 try expect_opcode(0x79, Insn.ldx(.double_word, .r1, .r2, 0));
816 try expect_opcode(0x61, Insn.ldx(.word, .r1, .r2, 0));
817 try expect_opcode(0x69, Insn.ldx(.half_word, .r1, .r2, 0));
818 try expect_opcode(0x71, Insn.ldx(.byte, .r1, .r2, 0));
819
820 try expect_opcode(0x62, Insn.st(.word, .r1, 0, 0));
821 try expect_opcode(0x6a, Insn.st(.half_word, .r1, 0, 0));
822 try expect_opcode(0x72, Insn.st(.byte, .r1, 0, 0));
823
824 try expect_opcode(0x63, Insn.stx(.word, .r1, 0, .r2));
825 try expect_opcode(0x6b, Insn.stx(.half_word, .r1, 0, .r2));
826 try expect_opcode(0x73, Insn.stx(.byte, .r1, 0, .r2));
827 try expect_opcode(0x7b, Insn.stx(.double_word, .r1, 0, .r2));
828828
829829 // branch instructions
830 expect_opcode(0x05, Insn.ja(0));
831 expect_opcode(0x15, Insn.jeq(.r1, 0, 0));
832 expect_opcode(0x1d, Insn.jeq(.r1, .r2, 0));
833 expect_opcode(0x25, Insn.jgt(.r1, 0, 0));
834 expect_opcode(0x2d, Insn.jgt(.r1, .r2, 0));
835 expect_opcode(0x35, Insn.jge(.r1, 0, 0));
836 expect_opcode(0x3d, Insn.jge(.r1, .r2, 0));
837 expect_opcode(0xa5, Insn.jlt(.r1, 0, 0));
838 expect_opcode(0xad, Insn.jlt(.r1, .r2, 0));
839 expect_opcode(0xb5, Insn.jle(.r1, 0, 0));
840 expect_opcode(0xbd, Insn.jle(.r1, .r2, 0));
841 expect_opcode(0x45, Insn.jset(.r1, 0, 0));
842 expect_opcode(0x4d, Insn.jset(.r1, .r2, 0));
843 expect_opcode(0x55, Insn.jne(.r1, 0, 0));
844 expect_opcode(0x5d, Insn.jne(.r1, .r2, 0));
845 expect_opcode(0x65, Insn.jsgt(.r1, 0, 0));
846 expect_opcode(0x6d, Insn.jsgt(.r1, .r2, 0));
847 expect_opcode(0x75, Insn.jsge(.r1, 0, 0));
848 expect_opcode(0x7d, Insn.jsge(.r1, .r2, 0));
849 expect_opcode(0xc5, Insn.jslt(.r1, 0, 0));
850 expect_opcode(0xcd, Insn.jslt(.r1, .r2, 0));
851 expect_opcode(0xd5, Insn.jsle(.r1, 0, 0));
852 expect_opcode(0xdd, Insn.jsle(.r1, .r2, 0));
853 expect_opcode(0x85, Insn.call(.unspec));
854 expect_opcode(0x95, Insn.exit());
830 try expect_opcode(0x05, Insn.ja(0));
831 try expect_opcode(0x15, Insn.jeq(.r1, 0, 0));
832 try expect_opcode(0x1d, Insn.jeq(.r1, .r2, 0));
833 try expect_opcode(0x25, Insn.jgt(.r1, 0, 0));
834 try expect_opcode(0x2d, Insn.jgt(.r1, .r2, 0));
835 try expect_opcode(0x35, Insn.jge(.r1, 0, 0));
836 try expect_opcode(0x3d, Insn.jge(.r1, .r2, 0));
837 try expect_opcode(0xa5, Insn.jlt(.r1, 0, 0));
838 try expect_opcode(0xad, Insn.jlt(.r1, .r2, 0));
839 try expect_opcode(0xb5, Insn.jle(.r1, 0, 0));
840 try expect_opcode(0xbd, Insn.jle(.r1, .r2, 0));
841 try expect_opcode(0x45, Insn.jset(.r1, 0, 0));
842 try expect_opcode(0x4d, Insn.jset(.r1, .r2, 0));
843 try expect_opcode(0x55, Insn.jne(.r1, 0, 0));
844 try expect_opcode(0x5d, Insn.jne(.r1, .r2, 0));
845 try expect_opcode(0x65, Insn.jsgt(.r1, 0, 0));
846 try expect_opcode(0x6d, Insn.jsgt(.r1, .r2, 0));
847 try expect_opcode(0x75, Insn.jsge(.r1, 0, 0));
848 try expect_opcode(0x7d, Insn.jsge(.r1, .r2, 0));
849 try expect_opcode(0xc5, Insn.jslt(.r1, 0, 0));
850 try expect_opcode(0xcd, Insn.jslt(.r1, .r2, 0));
851 try expect_opcode(0xd5, Insn.jsle(.r1, 0, 0));
852 try expect_opcode(0xdd, Insn.jsle(.r1, .r2, 0));
853 try expect_opcode(0x85, Insn.call(.unspec));
854 try expect_opcode(0x95, Insn.exit());
855855}
856856
857857pub const Cmd = enum(usize) {
......@@ -1596,7 +1596,7 @@ test "map lookup, update, and delete" {
15961596 var value = std.mem.zeroes([value_size]u8);
15971597
15981598 // fails looking up value that doesn't exist
1599 expectError(error.NotFound, map_lookup_elem(map, &key, &value));
1599 try expectError(error.NotFound, map_lookup_elem(map, &key, &value));
16001600
16011601 // succeed at updating and looking up element
16021602 try map_update_elem(map, &key, &value, 0);
......@@ -1604,14 +1604,14 @@ test "map lookup, update, and delete" {
16041604
16051605 // fails inserting more than max entries
16061606 const second_key = [key_size]u8{ 0, 0, 0, 1 };
1607 expectError(error.ReachedMaxEntries, map_update_elem(map, &second_key, &value, 0));
1607 try expectError(error.ReachedMaxEntries, map_update_elem(map, &second_key, &value, 0));
16081608
16091609 // succeed at deleting an existing elem
16101610 try map_delete_elem(map, &key);
1611 expectError(error.NotFound, map_lookup_elem(map, &key, &value));
1611 try expectError(error.NotFound, map_lookup_elem(map, &key, &value));
16121612
16131613 // fail at deleting a non-existing elem
1614 expectError(error.NotFound, map_delete_elem(map, &key));
1614 try expectError(error.NotFound, map_delete_elem(map, &key));
16151615}
16161616
16171617pub fn prog_load(
......@@ -1662,5 +1662,5 @@ test "prog_load" {
16621662 const prog = try prog_load(.socket_filter, &good_prog, null, "MIT", 0);
16631663 defer std.os.close(prog);
16641664
1665 expectError(error.UnsafeProgram, prog_load(.socket_filter, &bad_prog, null, "MIT", 0));
1665 try expectError(error.UnsafeProgram, prog_load(.socket_filter, &bad_prog, null, "MIT", 0));
16661666}
lib/std/os/linux/bpf/btf.zig+1-1
......@@ -92,7 +92,7 @@ pub const IntInfo = packed struct {
9292};
9393
9494test "IntInfo is 32 bits" {
95 std.testing.expectEqual(@bitSizeOf(IntInfo), 32);
95 try std.testing.expectEqual(@bitSizeOf(IntInfo), 32);
9696}
9797
9898/// Enum kind is followed by this struct
lib/std/os/linux/io_uring.zig+104-104
......@@ -937,16 +937,16 @@ pub fn io_uring_prep_fallocate(
937937test "structs/offsets/entries" {
938938 if (builtin.os.tag != .linux) return error.SkipZigTest;
939939
940 testing.expectEqual(@as(usize, 120), @sizeOf(io_uring_params));
941 testing.expectEqual(@as(usize, 64), @sizeOf(io_uring_sqe));
942 testing.expectEqual(@as(usize, 16), @sizeOf(io_uring_cqe));
940 try testing.expectEqual(@as(usize, 120), @sizeOf(io_uring_params));
941 try testing.expectEqual(@as(usize, 64), @sizeOf(io_uring_sqe));
942 try testing.expectEqual(@as(usize, 16), @sizeOf(io_uring_cqe));
943943
944 testing.expectEqual(0, linux.IORING_OFF_SQ_RING);
945 testing.expectEqual(0x8000000, linux.IORING_OFF_CQ_RING);
946 testing.expectEqual(0x10000000, linux.IORING_OFF_SQES);
944 try testing.expectEqual(0, linux.IORING_OFF_SQ_RING);
945 try testing.expectEqual(0x8000000, linux.IORING_OFF_CQ_RING);
946 try testing.expectEqual(0x10000000, linux.IORING_OFF_SQES);
947947
948 testing.expectError(error.EntriesZero, IO_Uring.init(0, 0));
949 testing.expectError(error.EntriesNotPowerOfTwo, IO_Uring.init(3, 0));
948 try testing.expectError(error.EntriesZero, IO_Uring.init(0, 0));
949 try testing.expectError(error.EntriesNotPowerOfTwo, IO_Uring.init(3, 0));
950950}
951951
952952test "nop" {
......@@ -959,11 +959,11 @@ test "nop" {
959959 };
960960 defer {
961961 ring.deinit();
962 testing.expectEqual(@as(os.fd_t, -1), ring.fd);
962 testing.expectEqual(@as(os.fd_t, -1), ring.fd) catch @panic("test failed");
963963 }
964964
965965 const sqe = try ring.nop(0xaaaaaaaa);
966 testing.expectEqual(io_uring_sqe{
966 try testing.expectEqual(io_uring_sqe{
967967 .opcode = .NOP,
968968 .flags = 0,
969969 .ioprio = 0,
......@@ -979,40 +979,40 @@ test "nop" {
979979 .__pad2 = [2]u64{ 0, 0 },
980980 }, sqe.*);
981981
982 testing.expectEqual(@as(u32, 0), ring.sq.sqe_head);
983 testing.expectEqual(@as(u32, 1), ring.sq.sqe_tail);
984 testing.expectEqual(@as(u32, 0), ring.sq.tail.*);
985 testing.expectEqual(@as(u32, 0), ring.cq.head.*);
986 testing.expectEqual(@as(u32, 1), ring.sq_ready());
987 testing.expectEqual(@as(u32, 0), ring.cq_ready());
988
989 testing.expectEqual(@as(u32, 1), try ring.submit());
990 testing.expectEqual(@as(u32, 1), ring.sq.sqe_head);
991 testing.expectEqual(@as(u32, 1), ring.sq.sqe_tail);
992 testing.expectEqual(@as(u32, 1), ring.sq.tail.*);
993 testing.expectEqual(@as(u32, 0), ring.cq.head.*);
994 testing.expectEqual(@as(u32, 0), ring.sq_ready());
995
996 testing.expectEqual(io_uring_cqe{
982 try testing.expectEqual(@as(u32, 0), ring.sq.sqe_head);
983 try testing.expectEqual(@as(u32, 1), ring.sq.sqe_tail);
984 try testing.expectEqual(@as(u32, 0), ring.sq.tail.*);
985 try testing.expectEqual(@as(u32, 0), ring.cq.head.*);
986 try testing.expectEqual(@as(u32, 1), ring.sq_ready());
987 try testing.expectEqual(@as(u32, 0), ring.cq_ready());
988
989 try testing.expectEqual(@as(u32, 1), try ring.submit());
990 try testing.expectEqual(@as(u32, 1), ring.sq.sqe_head);
991 try testing.expectEqual(@as(u32, 1), ring.sq.sqe_tail);
992 try testing.expectEqual(@as(u32, 1), ring.sq.tail.*);
993 try testing.expectEqual(@as(u32, 0), ring.cq.head.*);
994 try testing.expectEqual(@as(u32, 0), ring.sq_ready());
995
996 try testing.expectEqual(io_uring_cqe{
997997 .user_data = 0xaaaaaaaa,
998998 .res = 0,
999999 .flags = 0,
10001000 }, try ring.copy_cqe());
1001 testing.expectEqual(@as(u32, 1), ring.cq.head.*);
1002 testing.expectEqual(@as(u32, 0), ring.cq_ready());
1001 try testing.expectEqual(@as(u32, 1), ring.cq.head.*);
1002 try testing.expectEqual(@as(u32, 0), ring.cq_ready());
10031003
10041004 const sqe_barrier = try ring.nop(0xbbbbbbbb);
10051005 sqe_barrier.flags |= linux.IOSQE_IO_DRAIN;
1006 testing.expectEqual(@as(u32, 1), try ring.submit());
1007 testing.expectEqual(io_uring_cqe{
1006 try testing.expectEqual(@as(u32, 1), try ring.submit());
1007 try testing.expectEqual(io_uring_cqe{
10081008 .user_data = 0xbbbbbbbb,
10091009 .res = 0,
10101010 .flags = 0,
10111011 }, try ring.copy_cqe());
1012 testing.expectEqual(@as(u32, 2), ring.sq.sqe_head);
1013 testing.expectEqual(@as(u32, 2), ring.sq.sqe_tail);
1014 testing.expectEqual(@as(u32, 2), ring.sq.tail.*);
1015 testing.expectEqual(@as(u32, 2), ring.cq.head.*);
1012 try testing.expectEqual(@as(u32, 2), ring.sq.sqe_head);
1013 try testing.expectEqual(@as(u32, 2), ring.sq.sqe_tail);
1014 try testing.expectEqual(@as(u32, 2), ring.sq.tail.*);
1015 try testing.expectEqual(@as(u32, 2), ring.cq.head.*);
10161016}
10171017
10181018test "readv" {
......@@ -1042,17 +1042,17 @@ test "readv" {
10421042 var buffer = [_]u8{42} ** 128;
10431043 var iovecs = [_]os.iovec{os.iovec{ .iov_base = &buffer, .iov_len = buffer.len }};
10441044 const sqe = try ring.readv(0xcccccccc, fd_index, iovecs[0..], 0);
1045 testing.expectEqual(linux.IORING_OP.READV, sqe.opcode);
1045 try testing.expectEqual(linux.IORING_OP.READV, sqe.opcode);
10461046 sqe.flags |= linux.IOSQE_FIXED_FILE;
10471047
1048 testing.expectError(error.SubmissionQueueFull, ring.nop(0));
1049 testing.expectEqual(@as(u32, 1), try ring.submit());
1050 testing.expectEqual(linux.io_uring_cqe{
1048 try testing.expectError(error.SubmissionQueueFull, ring.nop(0));
1049 try testing.expectEqual(@as(u32, 1), try ring.submit());
1050 try testing.expectEqual(linux.io_uring_cqe{
10511051 .user_data = 0xcccccccc,
10521052 .res = buffer.len,
10531053 .flags = 0,
10541054 }, try ring.copy_cqe());
1055 testing.expectEqualSlices(u8, &([_]u8{0} ** buffer.len), buffer[0..]);
1055 try testing.expectEqualSlices(u8, &([_]u8{0} ** buffer.len), buffer[0..]);
10561056
10571057 try ring.unregister_files();
10581058}
......@@ -1083,46 +1083,46 @@ test "writev/fsync/readv" {
10831083 };
10841084
10851085 const sqe_writev = try ring.writev(0xdddddddd, fd, iovecs_write[0..], 17);
1086 testing.expectEqual(linux.IORING_OP.WRITEV, sqe_writev.opcode);
1087 testing.expectEqual(@as(u64, 17), sqe_writev.off);
1086 try testing.expectEqual(linux.IORING_OP.WRITEV, sqe_writev.opcode);
1087 try testing.expectEqual(@as(u64, 17), sqe_writev.off);
10881088 sqe_writev.flags |= linux.IOSQE_IO_LINK;
10891089
10901090 const sqe_fsync = try ring.fsync(0xeeeeeeee, fd, 0);
1091 testing.expectEqual(linux.IORING_OP.FSYNC, sqe_fsync.opcode);
1092 testing.expectEqual(fd, sqe_fsync.fd);
1091 try testing.expectEqual(linux.IORING_OP.FSYNC, sqe_fsync.opcode);
1092 try testing.expectEqual(fd, sqe_fsync.fd);
10931093 sqe_fsync.flags |= linux.IOSQE_IO_LINK;
10941094
10951095 const sqe_readv = try ring.readv(0xffffffff, fd, iovecs_read[0..], 17);
1096 testing.expectEqual(linux.IORING_OP.READV, sqe_readv.opcode);
1097 testing.expectEqual(@as(u64, 17), sqe_readv.off);
1096 try testing.expectEqual(linux.IORING_OP.READV, sqe_readv.opcode);
1097 try testing.expectEqual(@as(u64, 17), sqe_readv.off);
10981098
1099 testing.expectEqual(@as(u32, 3), ring.sq_ready());
1100 testing.expectEqual(@as(u32, 3), try ring.submit_and_wait(3));
1101 testing.expectEqual(@as(u32, 0), ring.sq_ready());
1102 testing.expectEqual(@as(u32, 3), ring.cq_ready());
1099 try testing.expectEqual(@as(u32, 3), ring.sq_ready());
1100 try testing.expectEqual(@as(u32, 3), try ring.submit_and_wait(3));
1101 try testing.expectEqual(@as(u32, 0), ring.sq_ready());
1102 try testing.expectEqual(@as(u32, 3), ring.cq_ready());
11031103
1104 testing.expectEqual(linux.io_uring_cqe{
1104 try testing.expectEqual(linux.io_uring_cqe{
11051105 .user_data = 0xdddddddd,
11061106 .res = buffer_write.len,
11071107 .flags = 0,
11081108 }, try ring.copy_cqe());
1109 testing.expectEqual(@as(u32, 2), ring.cq_ready());
1109 try testing.expectEqual(@as(u32, 2), ring.cq_ready());
11101110
1111 testing.expectEqual(linux.io_uring_cqe{
1111 try testing.expectEqual(linux.io_uring_cqe{
11121112 .user_data = 0xeeeeeeee,
11131113 .res = 0,
11141114 .flags = 0,
11151115 }, try ring.copy_cqe());
1116 testing.expectEqual(@as(u32, 1), ring.cq_ready());
1116 try testing.expectEqual(@as(u32, 1), ring.cq_ready());
11171117
1118 testing.expectEqual(linux.io_uring_cqe{
1118 try testing.expectEqual(linux.io_uring_cqe{
11191119 .user_data = 0xffffffff,
11201120 .res = buffer_read.len,
11211121 .flags = 0,
11221122 }, try ring.copy_cqe());
1123 testing.expectEqual(@as(u32, 0), ring.cq_ready());
1123 try testing.expectEqual(@as(u32, 0), ring.cq_ready());
11241124
1125 testing.expectEqualSlices(u8, buffer_write[0..], buffer_read[0..]);
1125 try testing.expectEqualSlices(u8, buffer_write[0..], buffer_read[0..]);
11261126}
11271127
11281128test "write/read" {
......@@ -1144,13 +1144,13 @@ test "write/read" {
11441144 const buffer_write = [_]u8{97} ** 20;
11451145 var buffer_read = [_]u8{98} ** 20;
11461146 const sqe_write = try ring.write(0x11111111, fd, buffer_write[0..], 10);
1147 testing.expectEqual(linux.IORING_OP.WRITE, sqe_write.opcode);
1148 testing.expectEqual(@as(u64, 10), sqe_write.off);
1147 try testing.expectEqual(linux.IORING_OP.WRITE, sqe_write.opcode);
1148 try testing.expectEqual(@as(u64, 10), sqe_write.off);
11491149 sqe_write.flags |= linux.IOSQE_IO_LINK;
11501150 const sqe_read = try ring.read(0x22222222, fd, buffer_read[0..], 10);
1151 testing.expectEqual(linux.IORING_OP.READ, sqe_read.opcode);
1152 testing.expectEqual(@as(u64, 10), sqe_read.off);
1153 testing.expectEqual(@as(u32, 2), try ring.submit());
1151 try testing.expectEqual(linux.IORING_OP.READ, sqe_read.opcode);
1152 try testing.expectEqual(@as(u64, 10), sqe_read.off);
1153 try testing.expectEqual(@as(u32, 2), try ring.submit());
11541154
11551155 const cqe_write = try ring.copy_cqe();
11561156 const cqe_read = try ring.copy_cqe();
......@@ -1158,17 +1158,17 @@ test "write/read" {
11581158 // https://lwn.net/Articles/809820/
11591159 if (cqe_write.res == -linux.EINVAL) return error.SkipZigTest;
11601160 if (cqe_read.res == -linux.EINVAL) return error.SkipZigTest;
1161 testing.expectEqual(linux.io_uring_cqe{
1161 try testing.expectEqual(linux.io_uring_cqe{
11621162 .user_data = 0x11111111,
11631163 .res = buffer_write.len,
11641164 .flags = 0,
11651165 }, cqe_write);
1166 testing.expectEqual(linux.io_uring_cqe{
1166 try testing.expectEqual(linux.io_uring_cqe{
11671167 .user_data = 0x22222222,
11681168 .res = buffer_read.len,
11691169 .flags = 0,
11701170 }, cqe_read);
1171 testing.expectEqualSlices(u8, buffer_write[0..], buffer_read[0..]);
1171 try testing.expectEqualSlices(u8, buffer_write[0..], buffer_read[0..]);
11721172}
11731173
11741174test "openat" {
......@@ -1187,7 +1187,7 @@ test "openat" {
11871187 const flags: u32 = os.O_CLOEXEC | os.O_RDWR | os.O_CREAT;
11881188 const mode: os.mode_t = 0o666;
11891189 const sqe_openat = try ring.openat(0x33333333, linux.AT_FDCWD, path, flags, mode);
1190 testing.expectEqual(io_uring_sqe{
1190 try testing.expectEqual(io_uring_sqe{
11911191 .opcode = .OPENAT,
11921192 .flags = 0,
11931193 .ioprio = 0,
......@@ -1202,10 +1202,10 @@ test "openat" {
12021202 .splice_fd_in = 0,
12031203 .__pad2 = [2]u64{ 0, 0 },
12041204 }, sqe_openat.*);
1205 testing.expectEqual(@as(u32, 1), try ring.submit());
1205 try testing.expectEqual(@as(u32, 1), try ring.submit());
12061206
12071207 const cqe_openat = try ring.copy_cqe();
1208 testing.expectEqual(@as(u64, 0x33333333), cqe_openat.user_data);
1208 try testing.expectEqual(@as(u64, 0x33333333), cqe_openat.user_data);
12091209 if (cqe_openat.res == -linux.EINVAL) return error.SkipZigTest;
12101210 // AT_FDCWD is not fully supported before kernel 5.6:
12111211 // See https://lore.kernel.org/io-uring/20200207155039.12819-1-axboe@kernel.dk/T/
......@@ -1214,8 +1214,8 @@ test "openat" {
12141214 return error.SkipZigTest;
12151215 }
12161216 if (cqe_openat.res <= 0) std.debug.print("\ncqe_openat.res={}\n", .{cqe_openat.res});
1217 testing.expect(cqe_openat.res > 0);
1218 testing.expectEqual(@as(u32, 0), cqe_openat.flags);
1217 try testing.expect(cqe_openat.res > 0);
1218 try testing.expectEqual(@as(u32, 0), cqe_openat.flags);
12191219
12201220 os.close(cqe_openat.res);
12211221}
......@@ -1236,13 +1236,13 @@ test "close" {
12361236 defer std.fs.cwd().deleteFile(path) catch {};
12371237
12381238 const sqe_close = try ring.close(0x44444444, file.handle);
1239 testing.expectEqual(linux.IORING_OP.CLOSE, sqe_close.opcode);
1240 testing.expectEqual(file.handle, sqe_close.fd);
1241 testing.expectEqual(@as(u32, 1), try ring.submit());
1239 try testing.expectEqual(linux.IORING_OP.CLOSE, sqe_close.opcode);
1240 try testing.expectEqual(file.handle, sqe_close.fd);
1241 try testing.expectEqual(@as(u32, 1), try ring.submit());
12421242
12431243 const cqe_close = try ring.copy_cqe();
12441244 if (cqe_close.res == -linux.EINVAL) return error.SkipZigTest;
1245 testing.expectEqual(linux.io_uring_cqe{
1245 try testing.expectEqual(linux.io_uring_cqe{
12461246 .user_data = 0x44444444,
12471247 .res = 0,
12481248 .flags = 0,
......@@ -1273,12 +1273,12 @@ test "accept/connect/send/recv" {
12731273 var accept_addr: os.sockaddr = undefined;
12741274 var accept_addr_len: os.socklen_t = @sizeOf(@TypeOf(accept_addr));
12751275 const accept = try ring.accept(0xaaaaaaaa, server, &accept_addr, &accept_addr_len, 0);
1276 testing.expectEqual(@as(u32, 1), try ring.submit());
1276 try testing.expectEqual(@as(u32, 1), try ring.submit());
12771277
12781278 const client = try os.socket(address.any.family, os.SOCK_STREAM | os.SOCK_CLOEXEC, 0);
12791279 defer os.close(client);
12801280 const connect = try ring.connect(0xcccccccc, client, &address.any, address.getOsSockLen());
1281 testing.expectEqual(@as(u32, 1), try ring.submit());
1281 try testing.expectEqual(@as(u32, 1), try ring.submit());
12821282
12831283 var cqe_accept = try ring.copy_cqe();
12841284 if (cqe_accept.res == -linux.EINVAL) return error.SkipZigTest;
......@@ -1293,11 +1293,11 @@ test "accept/connect/send/recv" {
12931293 cqe_connect = a;
12941294 }
12951295
1296 testing.expectEqual(@as(u64, 0xaaaaaaaa), cqe_accept.user_data);
1296 try testing.expectEqual(@as(u64, 0xaaaaaaaa), cqe_accept.user_data);
12971297 if (cqe_accept.res <= 0) std.debug.print("\ncqe_accept.res={}\n", .{cqe_accept.res});
1298 testing.expect(cqe_accept.res > 0);
1299 testing.expectEqual(@as(u32, 0), cqe_accept.flags);
1300 testing.expectEqual(linux.io_uring_cqe{
1298 try testing.expect(cqe_accept.res > 0);
1299 try testing.expectEqual(@as(u32, 0), cqe_accept.flags);
1300 try testing.expectEqual(linux.io_uring_cqe{
13011301 .user_data = 0xcccccccc,
13021302 .res = 0,
13031303 .flags = 0,
......@@ -1306,11 +1306,11 @@ test "accept/connect/send/recv" {
13061306 const send = try ring.send(0xeeeeeeee, client, buffer_send[0..], 0);
13071307 send.flags |= linux.IOSQE_IO_LINK;
13081308 const recv = try ring.recv(0xffffffff, cqe_accept.res, buffer_recv[0..], 0);
1309 testing.expectEqual(@as(u32, 2), try ring.submit());
1309 try testing.expectEqual(@as(u32, 2), try ring.submit());
13101310
13111311 const cqe_send = try ring.copy_cqe();
13121312 if (cqe_send.res == -linux.EINVAL) return error.SkipZigTest;
1313 testing.expectEqual(linux.io_uring_cqe{
1313 try testing.expectEqual(linux.io_uring_cqe{
13141314 .user_data = 0xeeeeeeee,
13151315 .res = buffer_send.len,
13161316 .flags = 0,
......@@ -1318,13 +1318,13 @@ test "accept/connect/send/recv" {
13181318
13191319 const cqe_recv = try ring.copy_cqe();
13201320 if (cqe_recv.res == -linux.EINVAL) return error.SkipZigTest;
1321 testing.expectEqual(linux.io_uring_cqe{
1321 try testing.expectEqual(linux.io_uring_cqe{
13221322 .user_data = 0xffffffff,
13231323 .res = buffer_recv.len,
13241324 .flags = 0,
13251325 }, cqe_recv);
13261326
1327 testing.expectEqualSlices(u8, buffer_send[0..buffer_recv.len], buffer_recv[0..]);
1327 try testing.expectEqualSlices(u8, buffer_send[0..buffer_recv.len], buffer_recv[0..]);
13281328}
13291329
13301330test "timeout (after a relative time)" {
......@@ -1343,12 +1343,12 @@ test "timeout (after a relative time)" {
13431343
13441344 const started = std.time.milliTimestamp();
13451345 const sqe = try ring.timeout(0x55555555, &ts, 0, 0);
1346 testing.expectEqual(linux.IORING_OP.TIMEOUT, sqe.opcode);
1347 testing.expectEqual(@as(u32, 1), try ring.submit());
1346 try testing.expectEqual(linux.IORING_OP.TIMEOUT, sqe.opcode);
1347 try testing.expectEqual(@as(u32, 1), try ring.submit());
13481348 const cqe = try ring.copy_cqe();
13491349 const stopped = std.time.milliTimestamp();
13501350
1351 testing.expectEqual(linux.io_uring_cqe{
1351 try testing.expectEqual(linux.io_uring_cqe{
13521352 .user_data = 0x55555555,
13531353 .res = -linux.ETIME,
13541354 .flags = 0,
......@@ -1371,20 +1371,20 @@ test "timeout (after a number of completions)" {
13711371 const ts = os.__kernel_timespec{ .tv_sec = 3, .tv_nsec = 0 };
13721372 const count_completions: u64 = 1;
13731373 const sqe_timeout = try ring.timeout(0x66666666, &ts, count_completions, 0);
1374 testing.expectEqual(linux.IORING_OP.TIMEOUT, sqe_timeout.opcode);
1375 testing.expectEqual(count_completions, sqe_timeout.off);
1374 try testing.expectEqual(linux.IORING_OP.TIMEOUT, sqe_timeout.opcode);
1375 try testing.expectEqual(count_completions, sqe_timeout.off);
13761376 _ = try ring.nop(0x77777777);
1377 testing.expectEqual(@as(u32, 2), try ring.submit());
1377 try testing.expectEqual(@as(u32, 2), try ring.submit());
13781378
13791379 const cqe_nop = try ring.copy_cqe();
1380 testing.expectEqual(linux.io_uring_cqe{
1380 try testing.expectEqual(linux.io_uring_cqe{
13811381 .user_data = 0x77777777,
13821382 .res = 0,
13831383 .flags = 0,
13841384 }, cqe_nop);
13851385
13861386 const cqe_timeout = try ring.copy_cqe();
1387 testing.expectEqual(linux.io_uring_cqe{
1387 try testing.expectEqual(linux.io_uring_cqe{
13881388 .user_data = 0x66666666,
13891389 .res = 0,
13901390 .flags = 0,
......@@ -1403,15 +1403,15 @@ test "timeout_remove" {
14031403
14041404 const ts = os.__kernel_timespec{ .tv_sec = 3, .tv_nsec = 0 };
14051405 const sqe_timeout = try ring.timeout(0x88888888, &ts, 0, 0);
1406 testing.expectEqual(linux.IORING_OP.TIMEOUT, sqe_timeout.opcode);
1407 testing.expectEqual(@as(u64, 0x88888888), sqe_timeout.user_data);
1406 try testing.expectEqual(linux.IORING_OP.TIMEOUT, sqe_timeout.opcode);
1407 try testing.expectEqual(@as(u64, 0x88888888), sqe_timeout.user_data);
14081408
14091409 const sqe_timeout_remove = try ring.timeout_remove(0x99999999, 0x88888888, 0);
1410 testing.expectEqual(linux.IORING_OP.TIMEOUT_REMOVE, sqe_timeout_remove.opcode);
1411 testing.expectEqual(@as(u64, 0x88888888), sqe_timeout_remove.addr);
1412 testing.expectEqual(@as(u64, 0x99999999), sqe_timeout_remove.user_data);
1410 try testing.expectEqual(linux.IORING_OP.TIMEOUT_REMOVE, sqe_timeout_remove.opcode);
1411 try testing.expectEqual(@as(u64, 0x88888888), sqe_timeout_remove.addr);
1412 try testing.expectEqual(@as(u64, 0x99999999), sqe_timeout_remove.user_data);
14131413
1414 testing.expectEqual(@as(u32, 2), try ring.submit());
1414 try testing.expectEqual(@as(u32, 2), try ring.submit());
14151415
14161416 const cqe_timeout = try ring.copy_cqe();
14171417 // IORING_OP_TIMEOUT_REMOVE is not supported by this kernel version:
......@@ -1424,14 +1424,14 @@ test "timeout_remove" {
14241424 {
14251425 return error.SkipZigTest;
14261426 }
1427 testing.expectEqual(linux.io_uring_cqe{
1427 try testing.expectEqual(linux.io_uring_cqe{
14281428 .user_data = 0x88888888,
14291429 .res = -linux.ECANCELED,
14301430 .flags = 0,
14311431 }, cqe_timeout);
14321432
14331433 const cqe_timeout_remove = try ring.copy_cqe();
1434 testing.expectEqual(linux.io_uring_cqe{
1434 try testing.expectEqual(linux.io_uring_cqe{
14351435 .user_data = 0x99999999,
14361436 .res = 0,
14371437 .flags = 0,
......@@ -1453,13 +1453,13 @@ test "fallocate" {
14531453 defer file.close();
14541454 defer std.fs.cwd().deleteFile(path) catch {};
14551455
1456 testing.expectEqual(@as(u64, 0), (try file.stat()).size);
1456 try testing.expectEqual(@as(u64, 0), (try file.stat()).size);
14571457
14581458 const len: u64 = 65536;
14591459 const sqe = try ring.fallocate(0xaaaaaaaa, file.handle, 0, 0, len);
1460 testing.expectEqual(linux.IORING_OP.FALLOCATE, sqe.opcode);
1461 testing.expectEqual(file.handle, sqe.fd);
1462 testing.expectEqual(@as(u32, 1), try ring.submit());
1460 try testing.expectEqual(linux.IORING_OP.FALLOCATE, sqe.opcode);
1461 try testing.expectEqual(file.handle, sqe.fd);
1462 try testing.expectEqual(@as(u32, 1), try ring.submit());
14631463
14641464 const cqe = try ring.copy_cqe();
14651465 switch (-cqe.res) {
......@@ -1473,11 +1473,11 @@ test "fallocate" {
14731473 linux.EOPNOTSUPP => return error.SkipZigTest,
14741474 else => |errno| std.debug.panic("unhandled errno: {}", .{errno}),
14751475 }
1476 testing.expectEqual(linux.io_uring_cqe{
1476 try testing.expectEqual(linux.io_uring_cqe{
14771477 .user_data = 0xaaaaaaaa,
14781478 .res = 0,
14791479 .flags = 0,
14801480 }, cqe);
14811481
1482 testing.expectEqual(len, (try file.stat()).size);
1482 try testing.expectEqual(len, (try file.stat()).size);
14831483}
lib/std/os/linux/test.zig+17-17
......@@ -18,7 +18,7 @@ test "fallocate" {
1818 defer file.close();
1919 defer fs.cwd().deleteFile(path) catch {};
2020
21 expect((try file.stat()).size == 0);
21 try expect((try file.stat()).size == 0);
2222
2323 const len: u64 = 65536;
2424 switch (linux.getErrno(linux.fallocate(file.handle, 0, 0, len))) {
......@@ -28,20 +28,20 @@ test "fallocate" {
2828 else => |errno| std.debug.panic("unhandled errno: {}", .{errno}),
2929 }
3030
31 expect((try file.stat()).size == len);
31 try expect((try file.stat()).size == len);
3232}
3333
3434test "getpid" {
35 expect(linux.getpid() != 0);
35 try expect(linux.getpid() != 0);
3636}
3737
3838test "timer" {
3939 const epoll_fd = linux.epoll_create();
4040 var err: usize = linux.getErrno(epoll_fd);
41 expect(err == 0);
41 try expect(err == 0);
4242
4343 const timer_fd = linux.timerfd_create(linux.CLOCK_MONOTONIC, 0);
44 expect(linux.getErrno(timer_fd) == 0);
44 try expect(linux.getErrno(timer_fd) == 0);
4545
4646 const time_interval = linux.timespec{
4747 .tv_sec = 0,
......@@ -54,7 +54,7 @@ test "timer" {
5454 };
5555
5656 err = linux.timerfd_settime(@intCast(i32, timer_fd), 0, &new_time, null);
57 expect(err == 0);
57 try expect(err == 0);
5858
5959 var event = linux.epoll_event{
6060 .events = linux.EPOLLIN | linux.EPOLLOUT | linux.EPOLLET,
......@@ -62,7 +62,7 @@ test "timer" {
6262 };
6363
6464 err = linux.epoll_ctl(@intCast(i32, epoll_fd), linux.EPOLL_CTL_ADD, @intCast(i32, timer_fd), &event);
65 expect(err == 0);
65 try expect(err == 0);
6666
6767 const events_one: linux.epoll_event = undefined;
6868 var events = [_]linux.epoll_event{events_one} ** 8;
......@@ -93,18 +93,18 @@ test "statx" {
9393 else => unreachable,
9494 }
9595
96 expect(stat_buf.mode == statx_buf.mode);
97 expect(@bitCast(u32, stat_buf.uid) == statx_buf.uid);
98 expect(@bitCast(u32, stat_buf.gid) == statx_buf.gid);
99 expect(@bitCast(u64, @as(i64, stat_buf.size)) == statx_buf.size);
100 expect(@bitCast(u64, @as(i64, stat_buf.blksize)) == statx_buf.blksize);
101 expect(@bitCast(u64, @as(i64, stat_buf.blocks)) == statx_buf.blocks);
96 try expect(stat_buf.mode == statx_buf.mode);
97 try expect(@bitCast(u32, stat_buf.uid) == statx_buf.uid);
98 try expect(@bitCast(u32, stat_buf.gid) == statx_buf.gid);
99 try expect(@bitCast(u64, @as(i64, stat_buf.size)) == statx_buf.size);
100 try expect(@bitCast(u64, @as(i64, stat_buf.blksize)) == statx_buf.blksize);
101 try expect(@bitCast(u64, @as(i64, stat_buf.blocks)) == statx_buf.blocks);
102102}
103103
104104test "user and group ids" {
105105 if (builtin.link_libc) return error.SkipZigTest;
106 expectEqual(linux.getauxval(elf.AT_UID), linux.getuid());
107 expectEqual(linux.getauxval(elf.AT_GID), linux.getgid());
108 expectEqual(linux.getauxval(elf.AT_EUID), linux.geteuid());
109 expectEqual(linux.getauxval(elf.AT_EGID), linux.getegid());
106 try expectEqual(linux.getauxval(elf.AT_UID), linux.getuid());
107 try expectEqual(linux.getauxval(elf.AT_GID), linux.getgid());
108 try expectEqual(linux.getauxval(elf.AT_EUID), linux.geteuid());
109 try expectEqual(linux.getauxval(elf.AT_EGID), linux.getegid());
110110}
lib/std/os/test.zig+51-51
......@@ -37,7 +37,7 @@ test "chdir smoke test" {
3737 try os.chdir(old_cwd);
3838 var new_cwd_buf: [fs.MAX_PATH_BYTES]u8 = undefined;
3939 const new_cwd = try os.getcwd(new_cwd_buf[0..]);
40 expect(mem.eql(u8, old_cwd, new_cwd));
40 try expect(mem.eql(u8, old_cwd, new_cwd));
4141 }
4242 {
4343 // Next, change current working directory to one level above
......@@ -47,7 +47,7 @@ test "chdir smoke test" {
4747 defer os.chdir(old_cwd) catch unreachable;
4848 var new_cwd_buf: [fs.MAX_PATH_BYTES]u8 = undefined;
4949 const new_cwd = try os.getcwd(new_cwd_buf[0..]);
50 expect(mem.eql(u8, parent, new_cwd));
50 try expect(mem.eql(u8, parent, new_cwd));
5151 }
5252}
5353
......@@ -79,7 +79,7 @@ test "open smoke test" {
7979
8080 // Try this again with the same flags. This op should fail with error.PathAlreadyExists.
8181 file_path = try fs.path.join(&arena.allocator, &[_][]const u8{ base_path, "some_file" });
82 expectError(error.PathAlreadyExists, os.open(file_path, os.O_RDWR | os.O_CREAT | os.O_EXCL, mode));
82 try expectError(error.PathAlreadyExists, os.open(file_path, os.O_RDWR | os.O_CREAT | os.O_EXCL, mode));
8383
8484 // Try opening without `O_EXCL` flag.
8585 file_path = try fs.path.join(&arena.allocator, &[_][]const u8{ base_path, "some_file" });
......@@ -88,7 +88,7 @@ test "open smoke test" {
8888
8989 // Try opening as a directory which should fail.
9090 file_path = try fs.path.join(&arena.allocator, &[_][]const u8{ base_path, "some_file" });
91 expectError(error.NotDir, os.open(file_path, os.O_RDWR | os.O_DIRECTORY, mode));
91 try expectError(error.NotDir, os.open(file_path, os.O_RDWR | os.O_DIRECTORY, mode));
9292
9393 // Create some directory
9494 file_path = try fs.path.join(&arena.allocator, &[_][]const u8{ base_path, "some_dir" });
......@@ -101,7 +101,7 @@ test "open smoke test" {
101101
102102 // Try opening as file which should fail.
103103 file_path = try fs.path.join(&arena.allocator, &[_][]const u8{ base_path, "some_dir" });
104 expectError(error.IsDir, os.open(file_path, os.O_RDWR, mode));
104 try expectError(error.IsDir, os.open(file_path, os.O_RDWR, mode));
105105}
106106
107107test "openat smoke test" {
......@@ -120,14 +120,14 @@ test "openat smoke test" {
120120 os.close(fd);
121121
122122 // Try this again with the same flags. This op should fail with error.PathAlreadyExists.
123 expectError(error.PathAlreadyExists, os.openat(tmp.dir.fd, "some_file", os.O_RDWR | os.O_CREAT | os.O_EXCL, mode));
123 try expectError(error.PathAlreadyExists, os.openat(tmp.dir.fd, "some_file", os.O_RDWR | os.O_CREAT | os.O_EXCL, mode));
124124
125125 // Try opening without `O_EXCL` flag.
126126 fd = try os.openat(tmp.dir.fd, "some_file", os.O_RDWR | os.O_CREAT, mode);
127127 os.close(fd);
128128
129129 // Try opening as a directory which should fail.
130 expectError(error.NotDir, os.openat(tmp.dir.fd, "some_file", os.O_RDWR | os.O_DIRECTORY, mode));
130 try expectError(error.NotDir, os.openat(tmp.dir.fd, "some_file", os.O_RDWR | os.O_DIRECTORY, mode));
131131
132132 // Create some directory
133133 try os.mkdirat(tmp.dir.fd, "some_dir", mode);
......@@ -137,7 +137,7 @@ test "openat smoke test" {
137137 os.close(fd);
138138
139139 // Try opening as file which should fail.
140 expectError(error.IsDir, os.openat(tmp.dir.fd, "some_dir", os.O_RDWR, mode));
140 try expectError(error.IsDir, os.openat(tmp.dir.fd, "some_dir", os.O_RDWR, mode));
141141}
142142
143143test "symlink with relative paths" {
......@@ -171,7 +171,7 @@ test "symlink with relative paths" {
171171
172172 var buffer: [fs.MAX_PATH_BYTES]u8 = undefined;
173173 const given = try os.readlink("symlinked", buffer[0..]);
174 expect(mem.eql(u8, "file.txt", given));
174 try expect(mem.eql(u8, "file.txt", given));
175175
176176 try cwd.deleteFile("file.txt");
177177 try cwd.deleteFile("symlinked");
......@@ -188,7 +188,7 @@ test "readlink on Windows" {
188188fn testReadlink(target_path: []const u8, symlink_path: []const u8) !void {
189189 var buffer: [fs.MAX_PATH_BYTES]u8 = undefined;
190190 const given = try os.readlink(symlink_path, buffer[0..]);
191 expect(mem.eql(u8, target_path, given));
191 try expect(mem.eql(u8, target_path, given));
192192}
193193
194194test "link with relative paths" {
......@@ -211,15 +211,15 @@ test "link with relative paths" {
211211 const estat = try os.fstat(efd.handle);
212212 const nstat = try os.fstat(nfd.handle);
213213
214 testing.expectEqual(estat.ino, nstat.ino);
215 testing.expectEqual(@as(usize, 2), nstat.nlink);
214 try testing.expectEqual(estat.ino, nstat.ino);
215 try testing.expectEqual(@as(usize, 2), nstat.nlink);
216216 }
217217
218218 try os.unlink("new.txt");
219219
220220 {
221221 const estat = try os.fstat(efd.handle);
222 testing.expectEqual(@as(usize, 1), estat.nlink);
222 try testing.expectEqual(@as(usize, 1), estat.nlink);
223223 }
224224
225225 try cwd.deleteFile("example.txt");
......@@ -246,15 +246,15 @@ test "linkat with different directories" {
246246 const estat = try os.fstat(efd.handle);
247247 const nstat = try os.fstat(nfd.handle);
248248
249 testing.expectEqual(estat.ino, nstat.ino);
250 testing.expectEqual(@as(usize, 2), nstat.nlink);
249 try testing.expectEqual(estat.ino, nstat.ino);
250 try testing.expectEqual(@as(usize, 2), nstat.nlink);
251251 }
252252
253253 try os.unlinkat(tmp.dir.fd, "new.txt", 0);
254254
255255 {
256256 const estat = try os.fstat(efd.handle);
257 testing.expectEqual(@as(usize, 1), estat.nlink);
257 try testing.expectEqual(@as(usize, 1), estat.nlink);
258258 }
259259
260260 try cwd.deleteFile("example.txt");
......@@ -283,7 +283,7 @@ test "fstatat" {
283283 // now repeat but using `fstatat` instead
284284 const flags = if (builtin.os.tag == .wasi) 0x0 else os.AT_SYMLINK_NOFOLLOW;
285285 const statat = try os.fstatat(tmp.dir.fd, "file.txt", flags);
286 expectEqual(stat, statat);
286 try expectEqual(stat, statat);
287287}
288288
289289test "readlinkat" {
......@@ -312,7 +312,7 @@ test "readlinkat" {
312312 // read the link
313313 var buffer: [fs.MAX_PATH_BYTES]u8 = undefined;
314314 const read_link = try os.readlinkat(tmp.dir.fd, "link", buffer[0..]);
315 expect(mem.eql(u8, "file.txt", read_link));
315 try expect(mem.eql(u8, "file.txt", read_link));
316316}
317317
318318fn testThreadIdFn(thread_id: *Thread.Id) void {
......@@ -327,13 +327,13 @@ test "std.Thread.getCurrentId" {
327327 const thread_id = thread.handle();
328328 thread.wait();
329329 if (Thread.use_pthreads) {
330 expect(thread_current_id == thread_id);
330 try expect(thread_current_id == thread_id);
331331 } else if (builtin.os.tag == .windows) {
332 expect(Thread.getCurrentId() != thread_current_id);
332 try expect(Thread.getCurrentId() != thread_current_id);
333333 } else {
334334 // If the thread completes very quickly, then thread_id can be 0. See the
335335 // documentation comments for `std.Thread.handle`.
336 expect(thread_id == 0 or thread_current_id == thread_id);
336 try expect(thread_id == 0 or thread_current_id == thread_id);
337337 }
338338}
339339
......@@ -352,7 +352,7 @@ test "spawn threads" {
352352 thread3.wait();
353353 thread4.wait();
354354
355 expect(shared_ctx == 4);
355 try expect(shared_ctx == 4);
356356}
357357
358358fn start1(ctx: void) u8 {
......@@ -368,23 +368,23 @@ test "cpu count" {
368368 if (builtin.os.tag == .wasi) return error.SkipZigTest;
369369
370370 const cpu_count = try Thread.cpuCount();
371 expect(cpu_count >= 1);
371 try expect(cpu_count >= 1);
372372}
373373
374374test "thread local storage" {
375375 if (builtin.single_threaded) return error.SkipZigTest;
376376 const thread1 = try Thread.spawn(testTls, {});
377377 const thread2 = try Thread.spawn(testTls, {});
378 testTls({});
378 try testTls({});
379379 thread1.wait();
380380 thread2.wait();
381381}
382382
383383threadlocal var x: i32 = 1234;
384fn testTls(context: void) void {
385 if (x != 1234) @panic("bad start value");
384fn testTls(context: void) !void {
385 if (x != 1234) return error.TlsBadStartValue;
386386 x += 1;
387 if (x != 1235) @panic("bad end value");
387 if (x != 1235) return error.TlsBadEndValue;
388388}
389389
390390test "getrandom" {
......@@ -394,7 +394,7 @@ test "getrandom" {
394394 try os.getrandom(&buf_b);
395395 // If this test fails the chance is significantly higher that there is a bug than
396396 // that two sets of 50 bytes were equal.
397 expect(!mem.eql(u8, &buf_a, &buf_b));
397 try expect(!mem.eql(u8, &buf_a, &buf_b));
398398}
399399
400400test "getcwd" {
......@@ -413,7 +413,7 @@ test "sigaltstack" {
413413 // Setting a stack size less than MINSIGSTKSZ returns ENOMEM
414414 st.ss_flags = 0;
415415 st.ss_size = 1;
416 testing.expectError(error.SizeTooSmall, os.sigaltstack(&st, null));
416 try testing.expectError(error.SizeTooSmall, os.sigaltstack(&st, null));
417417}
418418
419419// If the type is not available use void to avoid erroring out when `iter_fn` is
......@@ -464,7 +464,7 @@ test "dl_iterate_phdr" {
464464
465465 var counter: usize = 0;
466466 try os.dl_iterate_phdr(&counter, IterFnError, iter_fn);
467 expect(counter != 0);
467 try expect(counter != 0);
468468}
469469
470470test "gethostname" {
......@@ -473,7 +473,7 @@ test "gethostname" {
473473
474474 var buf: [os.HOST_NAME_MAX]u8 = undefined;
475475 const hostname = try os.gethostname(&buf);
476 expect(hostname.len != 0);
476 try expect(hostname.len != 0);
477477}
478478
479479test "pipe" {
......@@ -481,10 +481,10 @@ test "pipe" {
481481 return error.SkipZigTest;
482482
483483 var fds = try os.pipe();
484 expect((try os.write(fds[1], "hello")) == 5);
484 try expect((try os.write(fds[1], "hello")) == 5);
485485 var buf: [16]u8 = undefined;
486 expect((try os.read(fds[0], buf[0..])) == 5);
487 testing.expectEqualSlices(u8, buf[0..5], "hello");
486 try expect((try os.read(fds[0], buf[0..])) == 5);
487 try testing.expectEqualSlices(u8, buf[0..5], "hello");
488488 os.close(fds[1]);
489489 os.close(fds[0]);
490490}
......@@ -503,13 +503,13 @@ test "memfd_create" {
503503 else => |e| return e,
504504 };
505505 defer std.os.close(fd);
506 expect((try std.os.write(fd, "test")) == 4);
506 try expect((try std.os.write(fd, "test")) == 4);
507507 try std.os.lseek_SET(fd, 0);
508508
509509 var buf: [10]u8 = undefined;
510510 const bytes_read = try std.os.read(fd, &buf);
511 expect(bytes_read == 4);
512 expect(mem.eql(u8, buf[0..4], "test"));
511 try expect(bytes_read == 4);
512 try expect(mem.eql(u8, buf[0..4], "test"));
513513}
514514
515515test "mmap" {
......@@ -531,14 +531,14 @@ test "mmap" {
531531 );
532532 defer os.munmap(data);
533533
534 testing.expectEqual(@as(usize, 1234), data.len);
534 try testing.expectEqual(@as(usize, 1234), data.len);
535535
536536 // By definition the data returned by mmap is zero-filled
537 testing.expect(mem.eql(u8, data, &[_]u8{0x00} ** 1234));
537 try testing.expect(mem.eql(u8, data, &[_]u8{0x00} ** 1234));
538538
539539 // Make sure the memory is writeable as requested
540540 std.mem.set(u8, data, 0x55);
541 testing.expect(mem.eql(u8, data, &[_]u8{0x55} ** 1234));
541 try testing.expect(mem.eql(u8, data, &[_]u8{0x55} ** 1234));
542542 }
543543
544544 const test_out_file = "os_tmp_test";
......@@ -578,7 +578,7 @@ test "mmap" {
578578
579579 var i: u32 = 0;
580580 while (i < alloc_size / @sizeOf(u32)) : (i += 1) {
581 testing.expectEqual(i, try stream.readIntNative(u32));
581 try testing.expectEqual(i, try stream.readIntNative(u32));
582582 }
583583 }
584584
......@@ -602,7 +602,7 @@ test "mmap" {
602602
603603 var i: u32 = alloc_size / 2 / @sizeOf(u32);
604604 while (i < alloc_size / @sizeOf(u32)) : (i += 1) {
605 testing.expectEqual(i, try stream.readIntNative(u32));
605 try testing.expectEqual(i, try stream.readIntNative(u32));
606606 }
607607 }
608608
......@@ -611,9 +611,9 @@ test "mmap" {
611611
612612test "getenv" {
613613 if (builtin.os.tag == .windows) {
614 expect(os.getenvW(&[_:0]u16{ 'B', 'O', 'G', 'U', 'S', 0x11, 0x22, 0x33, 0x44, 0x55 }) == null);
614 try expect(os.getenvW(&[_:0]u16{ 'B', 'O', 'G', 'U', 'S', 0x11, 0x22, 0x33, 0x44, 0x55 }) == null);
615615 } else {
616 expect(os.getenvZ("BOGUSDOESNOTEXISTENVVAR") == null);
616 try expect(os.getenvZ("BOGUSDOESNOTEXISTENVVAR") == null);
617617 }
618618}
619619
......@@ -635,17 +635,17 @@ test "fcntl" {
635635 // Note: The test assumes createFile opens the file with O_CLOEXEC
636636 {
637637 const flags = try os.fcntl(file.handle, os.F_GETFD, 0);
638 expect((flags & os.FD_CLOEXEC) != 0);
638 try expect((flags & os.FD_CLOEXEC) != 0);
639639 }
640640 {
641641 _ = try os.fcntl(file.handle, os.F_SETFD, 0);
642642 const flags = try os.fcntl(file.handle, os.F_GETFD, 0);
643 expect((flags & os.FD_CLOEXEC) == 0);
643 try expect((flags & os.FD_CLOEXEC) == 0);
644644 }
645645 {
646646 _ = try os.fcntl(file.handle, os.F_SETFD, os.FD_CLOEXEC);
647647 const flags = try os.fcntl(file.handle, os.F_GETFD, 0);
648 expect((flags & os.FD_CLOEXEC) != 0);
648 try expect((flags & os.FD_CLOEXEC) != 0);
649649 }
650650}
651651
......@@ -750,12 +750,12 @@ test "sigaction" {
750750 os.sigaction(os.SIGUSR1, &sa, null);
751751 // Check that we can read it back correctly.
752752 os.sigaction(os.SIGUSR1, null, &old_sa);
753 testing.expectEqual(S.handler, old_sa.handler.sigaction.?);
754 testing.expect((old_sa.flags & os.SA_SIGINFO) != 0);
753 try testing.expectEqual(S.handler, old_sa.handler.sigaction.?);
754 try testing.expect((old_sa.flags & os.SA_SIGINFO) != 0);
755755 // Invoke the handler.
756756 try os.raise(os.SIGUSR1);
757 testing.expect(signal_test_failed == false);
757 try testing.expect(signal_test_failed == false);
758758 // Check if the handler has been correctly reset to SIG_DFL
759759 os.sigaction(os.SIGUSR1, null, &old_sa);
760 testing.expectEqual(os.SIG_DFL, old_sa.handler.sigaction);
760 try testing.expectEqual(os.SIG_DFL, old_sa.handler.sigaction);
761761}
lib/std/os/windows.zig+3-3
......@@ -997,7 +997,7 @@ test "QueryObjectName" {
997997 var result_path = try QueryObjectName(handle, &out_buffer);
998998 const required_len_in_u16 = result_path.len + @divExact(@ptrToInt(result_path.ptr) - @ptrToInt(&out_buffer), 2) + 1;
999999 //insufficient size
1000 std.testing.expectError(error.NameTooLong, QueryObjectName(handle, out_buffer[0 .. required_len_in_u16 - 1]));
1000 try std.testing.expectError(error.NameTooLong, QueryObjectName(handle, out_buffer[0 .. required_len_in_u16 - 1]));
10011001 //exactly-sufficient size
10021002 _ = try QueryObjectName(handle, out_buffer[0..required_len_in_u16]);
10031003}
......@@ -1155,8 +1155,8 @@ test "GetFinalPathNameByHandle" {
11551155
11561156 const required_len_in_u16 = nt_path.len + @divExact(@ptrToInt(nt_path.ptr) - @ptrToInt(&buffer), 2) + 1;
11571157 //check with insufficient size
1158 std.testing.expectError(error.NameTooLong, GetFinalPathNameByHandle(handle, .{ .volume_name = .Nt }, buffer[0 .. required_len_in_u16 - 1]));
1159 std.testing.expectError(error.NameTooLong, GetFinalPathNameByHandle(handle, .{ .volume_name = .Dos }, buffer[0 .. required_len_in_u16 - 1]));
1158 try std.testing.expectError(error.NameTooLong, GetFinalPathNameByHandle(handle, .{ .volume_name = .Nt }, buffer[0 .. required_len_in_u16 - 1]));
1159 try std.testing.expectError(error.NameTooLong, GetFinalPathNameByHandle(handle, .{ .volume_name = .Dos }, buffer[0 .. required_len_in_u16 - 1]));
11601160
11611161 //check with exactly-sufficient size
11621162 _ = try GetFinalPathNameByHandle(handle, .{ .volume_name = .Nt }, buffer[0..required_len_in_u16]);
lib/std/packed_int_array.zig+49-49
......@@ -355,7 +355,7 @@ test "PackedIntArray" {
355355
356356 const PackedArray = PackedIntArray(I, int_count);
357357 const expected_bytes = ((bits * int_count) + 7) / 8;
358 testing.expect(@sizeOf(PackedArray) == expected_bytes);
358 try testing.expect(@sizeOf(PackedArray) == expected_bytes);
359359
360360 var data = @as(PackedArray, undefined);
361361
......@@ -372,7 +372,7 @@ test "PackedIntArray" {
372372 count = 0;
373373 while (i < data.len()) : (i += 1) {
374374 const val = data.get(i);
375 testing.expect(val == count);
375 try testing.expect(val == count);
376376 if (bits > 0) count +%= 1;
377377 }
378378 }
......@@ -429,7 +429,7 @@ test "PackedIntSlice" {
429429 count = 0;
430430 while (i < data.len()) : (i += 1) {
431431 const val = data.get(i);
432 testing.expect(val == count);
432 try testing.expect(val == count);
433433 if (bits > 0) count +%= 1;
434434 }
435435 }
......@@ -456,48 +456,48 @@ test "PackedIntSlice of PackedInt(Array/Slice)" {
456456
457457 //slice of array
458458 var packed_slice = packed_array.slice(2, 5);
459 testing.expect(packed_slice.len() == 3);
459 try testing.expect(packed_slice.len() == 3);
460460 const ps_bit_count = (bits * packed_slice.len()) + packed_slice.bit_offset;
461461 const ps_expected_bytes = (ps_bit_count + 7) / 8;
462 testing.expect(packed_slice.bytes.len == ps_expected_bytes);
463 testing.expect(packed_slice.get(0) == 2 % limit);
464 testing.expect(packed_slice.get(1) == 3 % limit);
465 testing.expect(packed_slice.get(2) == 4 % limit);
462 try testing.expect(packed_slice.bytes.len == ps_expected_bytes);
463 try testing.expect(packed_slice.get(0) == 2 % limit);
464 try testing.expect(packed_slice.get(1) == 3 % limit);
465 try testing.expect(packed_slice.get(2) == 4 % limit);
466466 packed_slice.set(1, 7 % limit);
467 testing.expect(packed_slice.get(1) == 7 % limit);
467 try testing.expect(packed_slice.get(1) == 7 % limit);
468468
469469 //write through slice
470 testing.expect(packed_array.get(3) == 7 % limit);
470 try testing.expect(packed_array.get(3) == 7 % limit);
471471
472472 //slice of a slice
473473 const packed_slice_two = packed_slice.slice(0, 3);
474 testing.expect(packed_slice_two.len() == 3);
474 try testing.expect(packed_slice_two.len() == 3);
475475 const ps2_bit_count = (bits * packed_slice_two.len()) + packed_slice_two.bit_offset;
476476 const ps2_expected_bytes = (ps2_bit_count + 7) / 8;
477 testing.expect(packed_slice_two.bytes.len == ps2_expected_bytes);
478 testing.expect(packed_slice_two.get(1) == 7 % limit);
479 testing.expect(packed_slice_two.get(2) == 4 % limit);
477 try testing.expect(packed_slice_two.bytes.len == ps2_expected_bytes);
478 try testing.expect(packed_slice_two.get(1) == 7 % limit);
479 try testing.expect(packed_slice_two.get(2) == 4 % limit);
480480
481481 //size one case
482482 const packed_slice_three = packed_slice_two.slice(1, 2);
483 testing.expect(packed_slice_three.len() == 1);
483 try testing.expect(packed_slice_three.len() == 1);
484484 const ps3_bit_count = (bits * packed_slice_three.len()) + packed_slice_three.bit_offset;
485485 const ps3_expected_bytes = (ps3_bit_count + 7) / 8;
486 testing.expect(packed_slice_three.bytes.len == ps3_expected_bytes);
487 testing.expect(packed_slice_three.get(0) == 7 % limit);
486 try testing.expect(packed_slice_three.bytes.len == ps3_expected_bytes);
487 try testing.expect(packed_slice_three.get(0) == 7 % limit);
488488
489489 //empty slice case
490490 const packed_slice_empty = packed_slice.slice(0, 0);
491 testing.expect(packed_slice_empty.len() == 0);
492 testing.expect(packed_slice_empty.bytes.len == 0);
491 try testing.expect(packed_slice_empty.len() == 0);
492 try testing.expect(packed_slice_empty.bytes.len == 0);
493493
494494 //slicing at byte boundaries
495495 const packed_slice_edge = packed_array.slice(8, 16);
496 testing.expect(packed_slice_edge.len() == 8);
496 try testing.expect(packed_slice_edge.len() == 8);
497497 const pse_bit_count = (bits * packed_slice_edge.len()) + packed_slice_edge.bit_offset;
498498 const pse_expected_bytes = (pse_bit_count + 7) / 8;
499 testing.expect(packed_slice_edge.bytes.len == pse_expected_bytes);
500 testing.expect(packed_slice_edge.bit_offset == 0);
499 try testing.expect(packed_slice_edge.bytes.len == pse_expected_bytes);
500 try testing.expect(packed_slice_edge.bit_offset == 0);
501501 }
502502}
503503
......@@ -545,7 +545,7 @@ test "PackedInt(Array/Slice) sliceCast" {
545545 .Big => 0b01,
546546 .Little => 0b10,
547547 };
548 testing.expect(packed_slice_cast_2.get(i) == val);
548 try testing.expect(packed_slice_cast_2.get(i) == val);
549549 }
550550 i = 0;
551551 while (i < packed_slice_cast_4.len()) : (i += 1) {
......@@ -553,12 +553,12 @@ test "PackedInt(Array/Slice) sliceCast" {
553553 .Big => 0b0101,
554554 .Little => 0b1010,
555555 };
556 testing.expect(packed_slice_cast_4.get(i) == val);
556 try testing.expect(packed_slice_cast_4.get(i) == val);
557557 }
558558 i = 0;
559559 while (i < packed_slice_cast_9.len()) : (i += 1) {
560560 const val = 0b010101010;
561 testing.expect(packed_slice_cast_9.get(i) == val);
561 try testing.expect(packed_slice_cast_9.get(i) == val);
562562 packed_slice_cast_9.set(i, 0b111000111);
563563 }
564564 i = 0;
......@@ -567,7 +567,7 @@ test "PackedInt(Array/Slice) sliceCast" {
567567 .Big => if (i % 2 == 0) @as(u3, 0b111) else @as(u3, 0b000),
568568 .Little => if (i % 2 == 0) @as(u3, 0b111) else @as(u3, 0b000),
569569 };
570 testing.expect(packed_slice_cast_3.get(i) == val);
570 try testing.expect(packed_slice_cast_3.get(i) == val);
571571 }
572572}
573573
......@@ -577,58 +577,58 @@ test "PackedInt(Array/Slice)Endian" {
577577 {
578578 const PackedArrayBe = PackedIntArrayEndian(u4, .Big, 8);
579579 var packed_array_be = PackedArrayBe.init([_]u4{ 0, 1, 2, 3, 4, 5, 6, 7 });
580 testing.expect(packed_array_be.bytes[0] == 0b00000001);
581 testing.expect(packed_array_be.bytes[1] == 0b00100011);
580 try testing.expect(packed_array_be.bytes[0] == 0b00000001);
581 try testing.expect(packed_array_be.bytes[1] == 0b00100011);
582582
583583 var i = @as(usize, 0);
584584 while (i < packed_array_be.len()) : (i += 1) {
585 testing.expect(packed_array_be.get(i) == i);
585 try testing.expect(packed_array_be.get(i) == i);
586586 }
587587
588588 var packed_slice_le = packed_array_be.sliceCastEndian(u4, .Little);
589589 i = 0;
590590 while (i < packed_slice_le.len()) : (i += 1) {
591591 const val = if (i % 2 == 0) i + 1 else i - 1;
592 testing.expect(packed_slice_le.get(i) == val);
592 try testing.expect(packed_slice_le.get(i) == val);
593593 }
594594
595595 var packed_slice_le_shift = packed_array_be.slice(1, 5).sliceCastEndian(u4, .Little);
596596 i = 0;
597597 while (i < packed_slice_le_shift.len()) : (i += 1) {
598598 const val = if (i % 2 == 0) i else i + 2;
599 testing.expect(packed_slice_le_shift.get(i) == val);
599 try testing.expect(packed_slice_le_shift.get(i) == val);
600600 }
601601 }
602602
603603 {
604604 const PackedArrayBe = PackedIntArrayEndian(u11, .Big, 8);
605605 var packed_array_be = PackedArrayBe.init([_]u11{ 0, 1, 2, 3, 4, 5, 6, 7 });
606 testing.expect(packed_array_be.bytes[0] == 0b00000000);
607 testing.expect(packed_array_be.bytes[1] == 0b00000000);
608 testing.expect(packed_array_be.bytes[2] == 0b00000100);
609 testing.expect(packed_array_be.bytes[3] == 0b00000001);
610 testing.expect(packed_array_be.bytes[4] == 0b00000000);
606 try testing.expect(packed_array_be.bytes[0] == 0b00000000);
607 try testing.expect(packed_array_be.bytes[1] == 0b00000000);
608 try testing.expect(packed_array_be.bytes[2] == 0b00000100);
609 try testing.expect(packed_array_be.bytes[3] == 0b00000001);
610 try testing.expect(packed_array_be.bytes[4] == 0b00000000);
611611
612612 var i = @as(usize, 0);
613613 while (i < packed_array_be.len()) : (i += 1) {
614 testing.expect(packed_array_be.get(i) == i);
614 try testing.expect(packed_array_be.get(i) == i);
615615 }
616616
617617 var packed_slice_le = packed_array_be.sliceCastEndian(u11, .Little);
618 testing.expect(packed_slice_le.get(0) == 0b00000000000);
619 testing.expect(packed_slice_le.get(1) == 0b00010000000);
620 testing.expect(packed_slice_le.get(2) == 0b00000000100);
621 testing.expect(packed_slice_le.get(3) == 0b00000000000);
622 testing.expect(packed_slice_le.get(4) == 0b00010000011);
623 testing.expect(packed_slice_le.get(5) == 0b00000000010);
624 testing.expect(packed_slice_le.get(6) == 0b10000010000);
625 testing.expect(packed_slice_le.get(7) == 0b00000111001);
618 try testing.expect(packed_slice_le.get(0) == 0b00000000000);
619 try testing.expect(packed_slice_le.get(1) == 0b00010000000);
620 try testing.expect(packed_slice_le.get(2) == 0b00000000100);
621 try testing.expect(packed_slice_le.get(3) == 0b00000000000);
622 try testing.expect(packed_slice_le.get(4) == 0b00010000011);
623 try testing.expect(packed_slice_le.get(5) == 0b00000000010);
624 try testing.expect(packed_slice_le.get(6) == 0b10000010000);
625 try testing.expect(packed_slice_le.get(7) == 0b00000111001);
626626
627627 var packed_slice_le_shift = packed_array_be.slice(1, 5).sliceCastEndian(u11, .Little);
628 testing.expect(packed_slice_le_shift.get(0) == 0b00010000000);
629 testing.expect(packed_slice_le_shift.get(1) == 0b00000000100);
630 testing.expect(packed_slice_le_shift.get(2) == 0b00000000000);
631 testing.expect(packed_slice_le_shift.get(3) == 0b00010000011);
628 try testing.expect(packed_slice_le_shift.get(0) == 0b00010000000);
629 try testing.expect(packed_slice_le_shift.get(1) == 0b00000000100);
630 try testing.expect(packed_slice_le_shift.get(2) == 0b00000000000);
631 try testing.expect(packed_slice_le_shift.get(3) == 0b00010000011);
632632 }
633633}
634634
lib/std/priority_dequeue.zig+89-89
......@@ -482,12 +482,12 @@ test "std.PriorityDequeue: add and remove min" {
482482 try queue.add(25);
483483 try queue.add(13);
484484
485 expectEqual(@as(u32, 7), queue.removeMin());
486 expectEqual(@as(u32, 12), queue.removeMin());
487 expectEqual(@as(u32, 13), queue.removeMin());
488 expectEqual(@as(u32, 23), queue.removeMin());
489 expectEqual(@as(u32, 25), queue.removeMin());
490 expectEqual(@as(u32, 54), queue.removeMin());
485 try expectEqual(@as(u32, 7), queue.removeMin());
486 try expectEqual(@as(u32, 12), queue.removeMin());
487 try expectEqual(@as(u32, 13), queue.removeMin());
488 try expectEqual(@as(u32, 23), queue.removeMin());
489 try expectEqual(@as(u32, 25), queue.removeMin());
490 try expectEqual(@as(u32, 54), queue.removeMin());
491491}
492492
493493test "std.PriorityDequeue: add and remove min structs" {
......@@ -508,12 +508,12 @@ test "std.PriorityDequeue: add and remove min structs" {
508508 try queue.add(.{ .size = 25 });
509509 try queue.add(.{ .size = 13 });
510510
511 expectEqual(@as(u32, 7), queue.removeMin().size);
512 expectEqual(@as(u32, 12), queue.removeMin().size);
513 expectEqual(@as(u32, 13), queue.removeMin().size);
514 expectEqual(@as(u32, 23), queue.removeMin().size);
515 expectEqual(@as(u32, 25), queue.removeMin().size);
516 expectEqual(@as(u32, 54), queue.removeMin().size);
511 try expectEqual(@as(u32, 7), queue.removeMin().size);
512 try expectEqual(@as(u32, 12), queue.removeMin().size);
513 try expectEqual(@as(u32, 13), queue.removeMin().size);
514 try expectEqual(@as(u32, 23), queue.removeMin().size);
515 try expectEqual(@as(u32, 25), queue.removeMin().size);
516 try expectEqual(@as(u32, 54), queue.removeMin().size);
517517}
518518
519519test "std.PriorityDequeue: add and remove max" {
......@@ -527,12 +527,12 @@ test "std.PriorityDequeue: add and remove max" {
527527 try queue.add(25);
528528 try queue.add(13);
529529
530 expectEqual(@as(u32, 54), queue.removeMax());
531 expectEqual(@as(u32, 25), queue.removeMax());
532 expectEqual(@as(u32, 23), queue.removeMax());
533 expectEqual(@as(u32, 13), queue.removeMax());
534 expectEqual(@as(u32, 12), queue.removeMax());
535 expectEqual(@as(u32, 7), queue.removeMax());
530 try expectEqual(@as(u32, 54), queue.removeMax());
531 try expectEqual(@as(u32, 25), queue.removeMax());
532 try expectEqual(@as(u32, 23), queue.removeMax());
533 try expectEqual(@as(u32, 13), queue.removeMax());
534 try expectEqual(@as(u32, 12), queue.removeMax());
535 try expectEqual(@as(u32, 7), queue.removeMax());
536536}
537537
538538test "std.PriorityDequeue: add and remove same min" {
......@@ -546,12 +546,12 @@ test "std.PriorityDequeue: add and remove same min" {
546546 try queue.add(1);
547547 try queue.add(1);
548548
549 expectEqual(@as(u32, 1), queue.removeMin());
550 expectEqual(@as(u32, 1), queue.removeMin());
551 expectEqual(@as(u32, 1), queue.removeMin());
552 expectEqual(@as(u32, 1), queue.removeMin());
553 expectEqual(@as(u32, 2), queue.removeMin());
554 expectEqual(@as(u32, 2), queue.removeMin());
549 try expectEqual(@as(u32, 1), queue.removeMin());
550 try expectEqual(@as(u32, 1), queue.removeMin());
551 try expectEqual(@as(u32, 1), queue.removeMin());
552 try expectEqual(@as(u32, 1), queue.removeMin());
553 try expectEqual(@as(u32, 2), queue.removeMin());
554 try expectEqual(@as(u32, 2), queue.removeMin());
555555}
556556
557557test "std.PriorityDequeue: add and remove same max" {
......@@ -565,20 +565,20 @@ test "std.PriorityDequeue: add and remove same max" {
565565 try queue.add(1);
566566 try queue.add(1);
567567
568 expectEqual(@as(u32, 2), queue.removeMax());
569 expectEqual(@as(u32, 2), queue.removeMax());
570 expectEqual(@as(u32, 1), queue.removeMax());
571 expectEqual(@as(u32, 1), queue.removeMax());
572 expectEqual(@as(u32, 1), queue.removeMax());
573 expectEqual(@as(u32, 1), queue.removeMax());
568 try expectEqual(@as(u32, 2), queue.removeMax());
569 try expectEqual(@as(u32, 2), queue.removeMax());
570 try expectEqual(@as(u32, 1), queue.removeMax());
571 try expectEqual(@as(u32, 1), queue.removeMax());
572 try expectEqual(@as(u32, 1), queue.removeMax());
573 try expectEqual(@as(u32, 1), queue.removeMax());
574574}
575575
576576test "std.PriorityDequeue: removeOrNull empty" {
577577 var queue = PDQ.init(testing.allocator, lessThanComparison);
578578 defer queue.deinit();
579579
580 expect(queue.removeMinOrNull() == null);
581 expect(queue.removeMaxOrNull() == null);
580 try expect(queue.removeMinOrNull() == null);
581 try expect(queue.removeMaxOrNull() == null);
582582}
583583
584584test "std.PriorityDequeue: edge case 3 elements" {
......@@ -589,9 +589,9 @@ test "std.PriorityDequeue: edge case 3 elements" {
589589 try queue.add(3);
590590 try queue.add(2);
591591
592 expectEqual(@as(u32, 2), queue.removeMin());
593 expectEqual(@as(u32, 3), queue.removeMin());
594 expectEqual(@as(u32, 9), queue.removeMin());
592 try expectEqual(@as(u32, 2), queue.removeMin());
593 try expectEqual(@as(u32, 3), queue.removeMin());
594 try expectEqual(@as(u32, 9), queue.removeMin());
595595}
596596
597597test "std.PriorityDequeue: edge case 3 elements max" {
......@@ -602,37 +602,37 @@ test "std.PriorityDequeue: edge case 3 elements max" {
602602 try queue.add(3);
603603 try queue.add(2);
604604
605 expectEqual(@as(u32, 9), queue.removeMax());
606 expectEqual(@as(u32, 3), queue.removeMax());
607 expectEqual(@as(u32, 2), queue.removeMax());
605 try expectEqual(@as(u32, 9), queue.removeMax());
606 try expectEqual(@as(u32, 3), queue.removeMax());
607 try expectEqual(@as(u32, 2), queue.removeMax());
608608}
609609
610610test "std.PriorityDequeue: peekMin" {
611611 var queue = PDQ.init(testing.allocator, lessThanComparison);
612612 defer queue.deinit();
613613
614 expect(queue.peekMin() == null);
614 try expect(queue.peekMin() == null);
615615
616616 try queue.add(9);
617617 try queue.add(3);
618618 try queue.add(2);
619619
620 expect(queue.peekMin().? == 2);
621 expect(queue.peekMin().? == 2);
620 try expect(queue.peekMin().? == 2);
621 try expect(queue.peekMin().? == 2);
622622}
623623
624624test "std.PriorityDequeue: peekMax" {
625625 var queue = PDQ.init(testing.allocator, lessThanComparison);
626626 defer queue.deinit();
627627
628 expect(queue.peekMin() == null);
628 try expect(queue.peekMin() == null);
629629
630630 try queue.add(9);
631631 try queue.add(3);
632632 try queue.add(2);
633633
634 expect(queue.peekMax().? == 9);
635 expect(queue.peekMax().? == 9);
634 try expect(queue.peekMax().? == 9);
635 try expect(queue.peekMax().? == 9);
636636}
637637
638638test "std.PriorityDequeue: sift up with odd indices" {
......@@ -645,7 +645,7 @@ test "std.PriorityDequeue: sift up with odd indices" {
645645
646646 const sorted_items = [_]u32{ 1, 2, 5, 6, 7, 7, 11, 12, 13, 14, 15, 15, 16, 21, 22, 24, 24, 25 };
647647 for (sorted_items) |e| {
648 expectEqual(e, queue.removeMin());
648 try expectEqual(e, queue.removeMin());
649649 }
650650}
651651
......@@ -659,7 +659,7 @@ test "std.PriorityDequeue: sift up with odd indices" {
659659
660660 const sorted_items = [_]u32{ 25, 24, 24, 22, 21, 16, 15, 15, 14, 13, 12, 11, 7, 7, 6, 5, 2, 1 };
661661 for (sorted_items) |e| {
662 expectEqual(e, queue.removeMax());
662 try expectEqual(e, queue.removeMax());
663663 }
664664}
665665
......@@ -671,7 +671,7 @@ test "std.PriorityDequeue: addSlice min" {
671671
672672 const sorted_items = [_]u32{ 1, 2, 5, 6, 7, 7, 11, 12, 13, 14, 15, 15, 16, 21, 22, 24, 24, 25 };
673673 for (sorted_items) |e| {
674 expectEqual(e, queue.removeMin());
674 try expectEqual(e, queue.removeMin());
675675 }
676676}
677677
......@@ -683,7 +683,7 @@ test "std.PriorityDequeue: addSlice max" {
683683
684684 const sorted_items = [_]u32{ 25, 24, 24, 22, 21, 16, 15, 15, 14, 13, 12, 11, 7, 7, 6, 5, 2, 1 };
685685 for (sorted_items) |e| {
686 expectEqual(e, queue.removeMax());
686 try expectEqual(e, queue.removeMax());
687687 }
688688}
689689
......@@ -692,8 +692,8 @@ test "std.PriorityDequeue: fromOwnedSlice trivial case 0" {
692692 const queue_items = try testing.allocator.dupe(u32, &items);
693693 var queue = PDQ.fromOwnedSlice(testing.allocator, lessThanComparison, queue_items[0..]);
694694 defer queue.deinit();
695 expectEqual(@as(usize, 0), queue.len);
696 expect(queue.removeMinOrNull() == null);
695 try expectEqual(@as(usize, 0), queue.len);
696 try expect(queue.removeMinOrNull() == null);
697697}
698698
699699test "std.PriorityDequeue: fromOwnedSlice trivial case 1" {
......@@ -702,9 +702,9 @@ test "std.PriorityDequeue: fromOwnedSlice trivial case 1" {
702702 var queue = PDQ.fromOwnedSlice(testing.allocator, lessThanComparison, queue_items[0..]);
703703 defer queue.deinit();
704704
705 expectEqual(@as(usize, 1), queue.len);
706 expectEqual(items[0], queue.removeMin());
707 expect(queue.removeMinOrNull() == null);
705 try expectEqual(@as(usize, 1), queue.len);
706 try expectEqual(items[0], queue.removeMin());
707 try expect(queue.removeMinOrNull() == null);
708708}
709709
710710test "std.PriorityDequeue: fromOwnedSlice" {
......@@ -715,7 +715,7 @@ test "std.PriorityDequeue: fromOwnedSlice" {
715715
716716 const sorted_items = [_]u32{ 1, 2, 5, 6, 7, 7, 11, 12, 13, 14, 15, 15, 16, 21, 22, 24, 24, 25 };
717717 for (sorted_items) |e| {
718 expectEqual(e, queue.removeMin());
718 try expectEqual(e, queue.removeMin());
719719 }
720720}
721721
......@@ -729,9 +729,9 @@ test "std.PriorityDequeue: update min queue" {
729729 try queue.update(55, 5);
730730 try queue.update(44, 4);
731731 try queue.update(11, 1);
732 expectEqual(@as(u32, 1), queue.removeMin());
733 expectEqual(@as(u32, 4), queue.removeMin());
734 expectEqual(@as(u32, 5), queue.removeMin());
732 try expectEqual(@as(u32, 1), queue.removeMin());
733 try expectEqual(@as(u32, 4), queue.removeMin());
734 try expectEqual(@as(u32, 5), queue.removeMin());
735735}
736736
737737test "std.PriorityDequeue: update same min queue" {
......@@ -744,10 +744,10 @@ test "std.PriorityDequeue: update same min queue" {
744744 try queue.add(2);
745745 try queue.update(1, 5);
746746 try queue.update(2, 4);
747 expectEqual(@as(u32, 1), queue.removeMin());
748 expectEqual(@as(u32, 2), queue.removeMin());
749 expectEqual(@as(u32, 4), queue.removeMin());
750 expectEqual(@as(u32, 5), queue.removeMin());
747 try expectEqual(@as(u32, 1), queue.removeMin());
748 try expectEqual(@as(u32, 2), queue.removeMin());
749 try expectEqual(@as(u32, 4), queue.removeMin());
750 try expectEqual(@as(u32, 5), queue.removeMin());
751751}
752752
753753test "std.PriorityDequeue: update max queue" {
......@@ -761,9 +761,9 @@ test "std.PriorityDequeue: update max queue" {
761761 try queue.update(44, 1);
762762 try queue.update(11, 4);
763763
764 expectEqual(@as(u32, 5), queue.removeMax());
765 expectEqual(@as(u32, 4), queue.removeMax());
766 expectEqual(@as(u32, 1), queue.removeMax());
764 try expectEqual(@as(u32, 5), queue.removeMax());
765 try expectEqual(@as(u32, 4), queue.removeMax());
766 try expectEqual(@as(u32, 1), queue.removeMax());
767767}
768768
769769test "std.PriorityDequeue: update same max queue" {
......@@ -776,10 +776,10 @@ test "std.PriorityDequeue: update same max queue" {
776776 try queue.add(2);
777777 try queue.update(1, 5);
778778 try queue.update(2, 4);
779 expectEqual(@as(u32, 5), queue.removeMax());
780 expectEqual(@as(u32, 4), queue.removeMax());
781 expectEqual(@as(u32, 2), queue.removeMax());
782 expectEqual(@as(u32, 1), queue.removeMax());
779 try expectEqual(@as(u32, 5), queue.removeMax());
780 try expectEqual(@as(u32, 4), queue.removeMax());
781 try expectEqual(@as(u32, 2), queue.removeMax());
782 try expectEqual(@as(u32, 1), queue.removeMax());
783783}
784784
785785test "std.PriorityDequeue: iterator" {
......@@ -801,7 +801,7 @@ test "std.PriorityDequeue: iterator" {
801801 _ = map.remove(e);
802802 }
803803
804 expectEqual(@as(usize, 0), map.count());
804 try expectEqual(@as(usize, 0), map.count());
805805}
806806
807807test "std.PriorityDequeue: remove at index" {
......@@ -821,10 +821,10 @@ test "std.PriorityDequeue: remove at index" {
821821 idx += 1;
822822 } else unreachable;
823823
824 expectEqual(queue.removeIndex(two_idx), 2);
825 expectEqual(queue.removeMin(), 1);
826 expectEqual(queue.removeMin(), 3);
827 expectEqual(queue.removeMinOrNull(), null);
824 try expectEqual(queue.removeIndex(two_idx), 2);
825 try expectEqual(queue.removeMin(), 1);
826 try expectEqual(queue.removeMin(), 3);
827 try expectEqual(queue.removeMinOrNull(), null);
828828}
829829
830830test "std.PriorityDequeue: iterator while empty" {
......@@ -833,7 +833,7 @@ test "std.PriorityDequeue: iterator while empty" {
833833
834834 var it = queue.iterator();
835835
836 expectEqual(it.next(), null);
836 try expectEqual(it.next(), null);
837837}
838838
839839test "std.PriorityDequeue: shrinkRetainingCapacity and shrinkAndFree" {
......@@ -841,26 +841,26 @@ test "std.PriorityDequeue: shrinkRetainingCapacity and shrinkAndFree" {
841841 defer queue.deinit();
842842
843843 try queue.ensureCapacity(4);
844 expect(queue.capacity() >= 4);
844 try expect(queue.capacity() >= 4);
845845
846846 try queue.add(1);
847847 try queue.add(2);
848848 try queue.add(3);
849 expect(queue.capacity() >= 4);
850 expectEqual(@as(usize, 3), queue.len);
849 try expect(queue.capacity() >= 4);
850 try expectEqual(@as(usize, 3), queue.len);
851851
852852 queue.shrinkRetainingCapacity(3);
853 expect(queue.capacity() >= 4);
854 expectEqual(@as(usize, 3), queue.len);
853 try expect(queue.capacity() >= 4);
854 try expectEqual(@as(usize, 3), queue.len);
855855
856856 queue.shrinkAndFree(3);
857 expectEqual(@as(usize, 3), queue.capacity());
858 expectEqual(@as(usize, 3), queue.len);
857 try expectEqual(@as(usize, 3), queue.capacity());
858 try expectEqual(@as(usize, 3), queue.len);
859859
860 expectEqual(@as(u32, 3), queue.removeMax());
861 expectEqual(@as(u32, 2), queue.removeMax());
862 expectEqual(@as(u32, 1), queue.removeMax());
863 expect(queue.removeMaxOrNull() == null);
860 try expectEqual(@as(u32, 3), queue.removeMax());
861 try expectEqual(@as(u32, 2), queue.removeMax());
862 try expectEqual(@as(u32, 1), queue.removeMax());
863 try expect(queue.removeMaxOrNull() == null);
864864}
865865
866866test "std.PriorityDequeue: fuzz testing min" {
......@@ -885,7 +885,7 @@ fn fuzzTestMin(rng: *std.rand.Random, comptime queue_size: usize) !void {
885885 var last_removed: ?u32 = null;
886886 while (queue.removeMinOrNull()) |next| {
887887 if (last_removed) |last| {
888 expect(last <= next);
888 try expect(last <= next);
889889 }
890890 last_removed = next;
891891 }
......@@ -913,7 +913,7 @@ fn fuzzTestMax(rng: *std.rand.Random, queue_size: usize) !void {
913913 var last_removed: ?u32 = null;
914914 while (queue.removeMaxOrNull()) |next| {
915915 if (last_removed) |last| {
916 expect(last >= next);
916 try expect(last >= next);
917917 }
918918 last_removed = next;
919919 }
......@@ -945,13 +945,13 @@ fn fuzzTestMinMax(rng: *std.rand.Random, queue_size: usize) !void {
945945 if (i % 2 == 0) {
946946 const next = queue.removeMin();
947947 if (last_min) |last| {
948 expect(last <= next);
948 try expect(last <= next);
949949 }
950950 last_min = next;
951951 } else {
952952 const next = queue.removeMax();
953953 if (last_max) |last| {
954 expect(last >= next);
954 try expect(last >= next);
955955 }
956956 last_max = next;
957957 }
lib/std/priority_queue.zig+70-70
......@@ -290,12 +290,12 @@ test "std.PriorityQueue: add and remove min heap" {
290290 try queue.add(23);
291291 try queue.add(25);
292292 try queue.add(13);
293 expectEqual(@as(u32, 7), queue.remove());
294 expectEqual(@as(u32, 12), queue.remove());
295 expectEqual(@as(u32, 13), queue.remove());
296 expectEqual(@as(u32, 23), queue.remove());
297 expectEqual(@as(u32, 25), queue.remove());
298 expectEqual(@as(u32, 54), queue.remove());
293 try expectEqual(@as(u32, 7), queue.remove());
294 try expectEqual(@as(u32, 12), queue.remove());
295 try expectEqual(@as(u32, 13), queue.remove());
296 try expectEqual(@as(u32, 23), queue.remove());
297 try expectEqual(@as(u32, 25), queue.remove());
298 try expectEqual(@as(u32, 54), queue.remove());
299299}
300300
301301test "std.PriorityQueue: add and remove same min heap" {
......@@ -308,19 +308,19 @@ test "std.PriorityQueue: add and remove same min heap" {
308308 try queue.add(2);
309309 try queue.add(1);
310310 try queue.add(1);
311 expectEqual(@as(u32, 1), queue.remove());
312 expectEqual(@as(u32, 1), queue.remove());
313 expectEqual(@as(u32, 1), queue.remove());
314 expectEqual(@as(u32, 1), queue.remove());
315 expectEqual(@as(u32, 2), queue.remove());
316 expectEqual(@as(u32, 2), queue.remove());
311 try expectEqual(@as(u32, 1), queue.remove());
312 try expectEqual(@as(u32, 1), queue.remove());
313 try expectEqual(@as(u32, 1), queue.remove());
314 try expectEqual(@as(u32, 1), queue.remove());
315 try expectEqual(@as(u32, 2), queue.remove());
316 try expectEqual(@as(u32, 2), queue.remove());
317317}
318318
319319test "std.PriorityQueue: removeOrNull on empty" {
320320 var queue = PQ.init(testing.allocator, lessThan);
321321 defer queue.deinit();
322322
323 expect(queue.removeOrNull() == null);
323 try expect(queue.removeOrNull() == null);
324324}
325325
326326test "std.PriorityQueue: edge case 3 elements" {
......@@ -330,21 +330,21 @@ test "std.PriorityQueue: edge case 3 elements" {
330330 try queue.add(9);
331331 try queue.add(3);
332332 try queue.add(2);
333 expectEqual(@as(u32, 2), queue.remove());
334 expectEqual(@as(u32, 3), queue.remove());
335 expectEqual(@as(u32, 9), queue.remove());
333 try expectEqual(@as(u32, 2), queue.remove());
334 try expectEqual(@as(u32, 3), queue.remove());
335 try expectEqual(@as(u32, 9), queue.remove());
336336}
337337
338338test "std.PriorityQueue: peek" {
339339 var queue = PQ.init(testing.allocator, lessThan);
340340 defer queue.deinit();
341341
342 expect(queue.peek() == null);
342 try expect(queue.peek() == null);
343343 try queue.add(9);
344344 try queue.add(3);
345345 try queue.add(2);
346 expectEqual(@as(u32, 2), queue.peek().?);
347 expectEqual(@as(u32, 2), queue.peek().?);
346 try expectEqual(@as(u32, 2), queue.peek().?);
347 try expectEqual(@as(u32, 2), queue.peek().?);
348348}
349349
350350test "std.PriorityQueue: sift up with odd indices" {
......@@ -357,7 +357,7 @@ test "std.PriorityQueue: sift up with odd indices" {
357357
358358 const sorted_items = [_]u32{ 1, 2, 5, 6, 7, 7, 11, 12, 13, 14, 15, 15, 16, 21, 22, 24, 24, 25 };
359359 for (sorted_items) |e| {
360 expectEqual(e, queue.remove());
360 try expectEqual(e, queue.remove());
361361 }
362362}
363363
......@@ -369,7 +369,7 @@ test "std.PriorityQueue: addSlice" {
369369
370370 const sorted_items = [_]u32{ 1, 2, 5, 6, 7, 7, 11, 12, 13, 14, 15, 15, 16, 21, 22, 24, 24, 25 };
371371 for (sorted_items) |e| {
372 expectEqual(e, queue.remove());
372 try expectEqual(e, queue.remove());
373373 }
374374}
375375
......@@ -378,8 +378,8 @@ test "std.PriorityQueue: fromOwnedSlice trivial case 0" {
378378 const queue_items = try testing.allocator.dupe(u32, &items);
379379 var queue = PQ.fromOwnedSlice(testing.allocator, lessThan, queue_items[0..]);
380380 defer queue.deinit();
381 expectEqual(@as(usize, 0), queue.len);
382 expect(queue.removeOrNull() == null);
381 try expectEqual(@as(usize, 0), queue.len);
382 try expect(queue.removeOrNull() == null);
383383}
384384
385385test "std.PriorityQueue: fromOwnedSlice trivial case 1" {
......@@ -388,9 +388,9 @@ test "std.PriorityQueue: fromOwnedSlice trivial case 1" {
388388 var queue = PQ.fromOwnedSlice(testing.allocator, lessThan, queue_items[0..]);
389389 defer queue.deinit();
390390
391 expectEqual(@as(usize, 1), queue.len);
392 expectEqual(items[0], queue.remove());
393 expect(queue.removeOrNull() == null);
391 try expectEqual(@as(usize, 1), queue.len);
392 try expectEqual(items[0], queue.remove());
393 try expect(queue.removeOrNull() == null);
394394}
395395
396396test "std.PriorityQueue: fromOwnedSlice" {
......@@ -401,7 +401,7 @@ test "std.PriorityQueue: fromOwnedSlice" {
401401
402402 const sorted_items = [_]u32{ 1, 2, 5, 6, 7, 7, 11, 12, 13, 14, 15, 15, 16, 21, 22, 24, 24, 25 };
403403 for (sorted_items) |e| {
404 expectEqual(e, queue.remove());
404 try expectEqual(e, queue.remove());
405405 }
406406}
407407
......@@ -415,12 +415,12 @@ test "std.PriorityQueue: add and remove max heap" {
415415 try queue.add(23);
416416 try queue.add(25);
417417 try queue.add(13);
418 expectEqual(@as(u32, 54), queue.remove());
419 expectEqual(@as(u32, 25), queue.remove());
420 expectEqual(@as(u32, 23), queue.remove());
421 expectEqual(@as(u32, 13), queue.remove());
422 expectEqual(@as(u32, 12), queue.remove());
423 expectEqual(@as(u32, 7), queue.remove());
418 try expectEqual(@as(u32, 54), queue.remove());
419 try expectEqual(@as(u32, 25), queue.remove());
420 try expectEqual(@as(u32, 23), queue.remove());
421 try expectEqual(@as(u32, 13), queue.remove());
422 try expectEqual(@as(u32, 12), queue.remove());
423 try expectEqual(@as(u32, 7), queue.remove());
424424}
425425
426426test "std.PriorityQueue: add and remove same max heap" {
......@@ -433,12 +433,12 @@ test "std.PriorityQueue: add and remove same max heap" {
433433 try queue.add(2);
434434 try queue.add(1);
435435 try queue.add(1);
436 expectEqual(@as(u32, 2), queue.remove());
437 expectEqual(@as(u32, 2), queue.remove());
438 expectEqual(@as(u32, 1), queue.remove());
439 expectEqual(@as(u32, 1), queue.remove());
440 expectEqual(@as(u32, 1), queue.remove());
441 expectEqual(@as(u32, 1), queue.remove());
436 try expectEqual(@as(u32, 2), queue.remove());
437 try expectEqual(@as(u32, 2), queue.remove());
438 try expectEqual(@as(u32, 1), queue.remove());
439 try expectEqual(@as(u32, 1), queue.remove());
440 try expectEqual(@as(u32, 1), queue.remove());
441 try expectEqual(@as(u32, 1), queue.remove());
442442}
443443
444444test "std.PriorityQueue: iterator" {
......@@ -460,7 +460,7 @@ test "std.PriorityQueue: iterator" {
460460 _ = map.remove(e);
461461 }
462462
463 expectEqual(@as(usize, 0), map.count());
463 try expectEqual(@as(usize, 0), map.count());
464464}
465465
466466test "std.PriorityQueue: remove at index" {
......@@ -480,10 +480,10 @@ test "std.PriorityQueue: remove at index" {
480480 idx += 1;
481481 } else unreachable;
482482
483 expectEqual(queue.removeIndex(two_idx), 2);
484 expectEqual(queue.remove(), 1);
485 expectEqual(queue.remove(), 3);
486 expectEqual(queue.removeOrNull(), null);
483 try expectEqual(queue.removeIndex(two_idx), 2);
484 try expectEqual(queue.remove(), 1);
485 try expectEqual(queue.remove(), 3);
486 try expectEqual(queue.removeOrNull(), null);
487487}
488488
489489test "std.PriorityQueue: iterator while empty" {
......@@ -492,7 +492,7 @@ test "std.PriorityQueue: iterator while empty" {
492492
493493 var it = queue.iterator();
494494
495 expectEqual(it.next(), null);
495 try expectEqual(it.next(), null);
496496}
497497
498498test "std.PriorityQueue: shrinkRetainingCapacity and shrinkAndFree" {
......@@ -500,26 +500,26 @@ test "std.PriorityQueue: shrinkRetainingCapacity and shrinkAndFree" {
500500 defer queue.deinit();
501501
502502 try queue.ensureCapacity(4);
503 expect(queue.capacity() >= 4);
503 try expect(queue.capacity() >= 4);
504504
505505 try queue.add(1);
506506 try queue.add(2);
507507 try queue.add(3);
508 expect(queue.capacity() >= 4);
509 expectEqual(@as(usize, 3), queue.len);
508 try expect(queue.capacity() >= 4);
509 try expectEqual(@as(usize, 3), queue.len);
510510
511511 queue.shrinkRetainingCapacity(3);
512 expect(queue.capacity() >= 4);
513 expectEqual(@as(usize, 3), queue.len);
512 try expect(queue.capacity() >= 4);
513 try expectEqual(@as(usize, 3), queue.len);
514514
515515 queue.shrinkAndFree(3);
516 expectEqual(@as(usize, 3), queue.capacity());
517 expectEqual(@as(usize, 3), queue.len);
516 try expectEqual(@as(usize, 3), queue.capacity());
517 try expectEqual(@as(usize, 3), queue.len);
518518
519 expectEqual(@as(u32, 1), queue.remove());
520 expectEqual(@as(u32, 2), queue.remove());
521 expectEqual(@as(u32, 3), queue.remove());
522 expect(queue.removeOrNull() == null);
519 try expectEqual(@as(u32, 1), queue.remove());
520 try expectEqual(@as(u32, 2), queue.remove());
521 try expectEqual(@as(u32, 3), queue.remove());
522 try expect(queue.removeOrNull() == null);
523523}
524524
525525test "std.PriorityQueue: update min heap" {
......@@ -532,9 +532,9 @@ test "std.PriorityQueue: update min heap" {
532532 try queue.update(55, 5);
533533 try queue.update(44, 4);
534534 try queue.update(11, 1);
535 expectEqual(@as(u32, 1), queue.remove());
536 expectEqual(@as(u32, 4), queue.remove());
537 expectEqual(@as(u32, 5), queue.remove());
535 try expectEqual(@as(u32, 1), queue.remove());
536 try expectEqual(@as(u32, 4), queue.remove());
537 try expectEqual(@as(u32, 5), queue.remove());
538538}
539539
540540test "std.PriorityQueue: update same min heap" {
......@@ -547,10 +547,10 @@ test "std.PriorityQueue: update same min heap" {
547547 try queue.add(2);
548548 try queue.update(1, 5);
549549 try queue.update(2, 4);
550 expectEqual(@as(u32, 1), queue.remove());
551 expectEqual(@as(u32, 2), queue.remove());
552 expectEqual(@as(u32, 4), queue.remove());
553 expectEqual(@as(u32, 5), queue.remove());
550 try expectEqual(@as(u32, 1), queue.remove());
551 try expectEqual(@as(u32, 2), queue.remove());
552 try expectEqual(@as(u32, 4), queue.remove());
553 try expectEqual(@as(u32, 5), queue.remove());
554554}
555555
556556test "std.PriorityQueue: update max heap" {
......@@ -563,9 +563,9 @@ test "std.PriorityQueue: update max heap" {
563563 try queue.update(55, 5);
564564 try queue.update(44, 1);
565565 try queue.update(11, 4);
566 expectEqual(@as(u32, 5), queue.remove());
567 expectEqual(@as(u32, 4), queue.remove());
568 expectEqual(@as(u32, 1), queue.remove());
566 try expectEqual(@as(u32, 5), queue.remove());
567 try expectEqual(@as(u32, 4), queue.remove());
568 try expectEqual(@as(u32, 1), queue.remove());
569569}
570570
571571test "std.PriorityQueue: update same max heap" {
......@@ -578,8 +578,8 @@ test "std.PriorityQueue: update same max heap" {
578578 try queue.add(2);
579579 try queue.update(1, 5);
580580 try queue.update(2, 4);
581 expectEqual(@as(u32, 5), queue.remove());
582 expectEqual(@as(u32, 4), queue.remove());
583 expectEqual(@as(u32, 2), queue.remove());
584 expectEqual(@as(u32, 1), queue.remove());
581 try expectEqual(@as(u32, 5), queue.remove());
582 try expectEqual(@as(u32, 4), queue.remove());
583 try expectEqual(@as(u32, 2), queue.remove());
584 try expectEqual(@as(u32, 1), queue.remove());
585585}
lib/std/process.zig+16-16
......@@ -181,7 +181,7 @@ pub fn getEnvVarOwned(allocator: *mem.Allocator, key: []const u8) GetEnvVarOwned
181181
182182test "os.getEnvVarOwned" {
183183 var ga = std.testing.allocator;
184 testing.expectError(error.EnvironmentVariableNotFound, getEnvVarOwned(ga, "BADENV"));
184 try testing.expectError(error.EnvironmentVariableNotFound, getEnvVarOwned(ga, "BADENV"));
185185}
186186
187187pub const ArgIteratorPosix = struct {
......@@ -516,10 +516,10 @@ test "args iterator" {
516516 };
517517 const given_suffix = std.fs.path.basename(prog_name);
518518
519 testing.expect(mem.eql(u8, expected_suffix, given_suffix));
520 testing.expect(it.skip()); // Skip over zig_exe_path, passed to the test runner
521 testing.expect(it.next(ga) == null);
522 testing.expect(!it.skip());
519 try testing.expect(mem.eql(u8, expected_suffix, given_suffix));
520 try testing.expect(it.skip()); // Skip over zig_exe_path, passed to the test runner
521 try testing.expect(it.next(ga) == null);
522 try testing.expect(!it.skip());
523523}
524524
525525/// Caller must call argsFree on result.
......@@ -575,14 +575,14 @@ pub fn argsFree(allocator: *mem.Allocator, args_alloc: []const [:0]u8) void {
575575
576576test "windows arg parsing" {
577577 const utf16Literal = std.unicode.utf8ToUtf16LeStringLiteral;
578 testWindowsCmdLine(utf16Literal("a b\tc d"), &[_][]const u8{ "a", "b", "c", "d" });
579 testWindowsCmdLine(utf16Literal("\"abc\" d e"), &[_][]const u8{ "abc", "d", "e" });
580 testWindowsCmdLine(utf16Literal("a\\\\\\b d\"e f\"g h"), &[_][]const u8{ "a\\\\\\b", "de fg", "h" });
581 testWindowsCmdLine(utf16Literal("a\\\\\\\"b c d"), &[_][]const u8{ "a\\\"b", "c", "d" });
582 testWindowsCmdLine(utf16Literal("a\\\\\\\\\"b c\" d e"), &[_][]const u8{ "a\\\\b c", "d", "e" });
583 testWindowsCmdLine(utf16Literal("a b\tc \"d f"), &[_][]const u8{ "a", "b", "c", "d f" });
584
585 testWindowsCmdLine(utf16Literal("\".\\..\\zig-cache\\build\" \"bin\\zig.exe\" \".\\..\" \".\\..\\zig-cache\" \"--help\""), &[_][]const u8{
578 try testWindowsCmdLine(utf16Literal("a b\tc d"), &[_][]const u8{ "a", "b", "c", "d" });
579 try testWindowsCmdLine(utf16Literal("\"abc\" d e"), &[_][]const u8{ "abc", "d", "e" });
580 try testWindowsCmdLine(utf16Literal("a\\\\\\b d\"e f\"g h"), &[_][]const u8{ "a\\\\\\b", "de fg", "h" });
581 try testWindowsCmdLine(utf16Literal("a\\\\\\\"b c d"), &[_][]const u8{ "a\\\"b", "c", "d" });
582 try testWindowsCmdLine(utf16Literal("a\\\\\\\\\"b c\" d e"), &[_][]const u8{ "a\\\\b c", "d", "e" });
583 try testWindowsCmdLine(utf16Literal("a b\tc \"d f"), &[_][]const u8{ "a", "b", "c", "d f" });
584
585 try testWindowsCmdLine(utf16Literal("\".\\..\\zig-cache\\build\" \"bin\\zig.exe\" \".\\..\" \".\\..\\zig-cache\" \"--help\""), &[_][]const u8{
586586 ".\\..\\zig-cache\\build",
587587 "bin\\zig.exe",
588588 ".\\..",
......@@ -591,14 +591,14 @@ test "windows arg parsing" {
591591 });
592592}
593593
594fn testWindowsCmdLine(input_cmd_line: [*]const u16, expected_args: []const []const u8) void {
594fn testWindowsCmdLine(input_cmd_line: [*]const u16, expected_args: []const []const u8) !void {
595595 var it = ArgIteratorWindows.initWithCmdLine(input_cmd_line);
596596 for (expected_args) |expected_arg| {
597597 const arg = it.next(std.testing.allocator).? catch unreachable;
598598 defer std.testing.allocator.free(arg);
599 testing.expectEqualStrings(expected_arg, arg);
599 try testing.expectEqualStrings(expected_arg, arg);
600600 }
601 testing.expect(it.next(std.testing.allocator) == null);
601 try testing.expect(it.next(std.testing.allocator) == null);
602602}
603603
604604pub const UserInfo = struct {
lib/std/rand.zig+96-96
......@@ -319,139 +319,139 @@ const SequentialPrng = struct {
319319};
320320
321321test "Random int" {
322 testRandomInt();
323 comptime testRandomInt();
322 try testRandomInt();
323 comptime try testRandomInt();
324324}
325fn testRandomInt() void {
325fn testRandomInt() !void {
326326 var r = SequentialPrng.init();
327327
328 expect(r.random.int(u0) == 0);
328 try expect(r.random.int(u0) == 0);
329329
330330 r.next_value = 0;
331 expect(r.random.int(u1) == 0);
332 expect(r.random.int(u1) == 1);
333 expect(r.random.int(u2) == 2);
334 expect(r.random.int(u2) == 3);
335 expect(r.random.int(u2) == 0);
331 try expect(r.random.int(u1) == 0);
332 try expect(r.random.int(u1) == 1);
333 try expect(r.random.int(u2) == 2);
334 try expect(r.random.int(u2) == 3);
335 try expect(r.random.int(u2) == 0);
336336
337337 r.next_value = 0xff;
338 expect(r.random.int(u8) == 0xff);
338 try expect(r.random.int(u8) == 0xff);
339339 r.next_value = 0x11;
340 expect(r.random.int(u8) == 0x11);
340 try expect(r.random.int(u8) == 0x11);
341341
342342 r.next_value = 0xff;
343 expect(r.random.int(u32) == 0xffffffff);
343 try expect(r.random.int(u32) == 0xffffffff);
344344 r.next_value = 0x11;
345 expect(r.random.int(u32) == 0x11111111);
345 try expect(r.random.int(u32) == 0x11111111);
346346
347347 r.next_value = 0xff;
348 expect(r.random.int(i32) == -1);
348 try expect(r.random.int(i32) == -1);
349349 r.next_value = 0x11;
350 expect(r.random.int(i32) == 0x11111111);
350 try expect(r.random.int(i32) == 0x11111111);
351351
352352 r.next_value = 0xff;
353 expect(r.random.int(i8) == -1);
353 try expect(r.random.int(i8) == -1);
354354 r.next_value = 0x11;
355 expect(r.random.int(i8) == 0x11);
355 try expect(r.random.int(i8) == 0x11);
356356
357357 r.next_value = 0xff;
358 expect(r.random.int(u33) == 0x1ffffffff);
358 try expect(r.random.int(u33) == 0x1ffffffff);
359359 r.next_value = 0xff;
360 expect(r.random.int(i1) == -1);
360 try expect(r.random.int(i1) == -1);
361361 r.next_value = 0xff;
362 expect(r.random.int(i2) == -1);
362 try expect(r.random.int(i2) == -1);
363363 r.next_value = 0xff;
364 expect(r.random.int(i33) == -1);
364 try expect(r.random.int(i33) == -1);
365365}
366366
367367test "Random boolean" {
368 testRandomBoolean();
369 comptime testRandomBoolean();
368 try testRandomBoolean();
369 comptime try testRandomBoolean();
370370}
371fn testRandomBoolean() void {
371fn testRandomBoolean() !void {
372372 var r = SequentialPrng.init();
373 expect(r.random.boolean() == false);
374 expect(r.random.boolean() == true);
375 expect(r.random.boolean() == false);
376 expect(r.random.boolean() == true);
373 try expect(r.random.boolean() == false);
374 try expect(r.random.boolean() == true);
375 try expect(r.random.boolean() == false);
376 try expect(r.random.boolean() == true);
377377}
378378
379379test "Random intLessThan" {
380380 @setEvalBranchQuota(10000);
381 testRandomIntLessThan();
382 comptime testRandomIntLessThan();
381 try testRandomIntLessThan();
382 comptime try testRandomIntLessThan();
383383}
384fn testRandomIntLessThan() void {
384fn testRandomIntLessThan() !void {
385385 var r = SequentialPrng.init();
386386 r.next_value = 0xff;
387 expect(r.random.uintLessThan(u8, 4) == 3);
388 expect(r.next_value == 0);
389 expect(r.random.uintLessThan(u8, 4) == 0);
390 expect(r.next_value == 1);
387 try expect(r.random.uintLessThan(u8, 4) == 3);
388 try expect(r.next_value == 0);
389 try expect(r.random.uintLessThan(u8, 4) == 0);
390 try expect(r.next_value == 1);
391391
392392 r.next_value = 0;
393 expect(r.random.uintLessThan(u64, 32) == 0);
393 try expect(r.random.uintLessThan(u64, 32) == 0);
394394
395395 // trigger the bias rejection code path
396396 r.next_value = 0;
397 expect(r.random.uintLessThan(u8, 3) == 0);
397 try expect(r.random.uintLessThan(u8, 3) == 0);
398398 // verify we incremented twice
399 expect(r.next_value == 2);
399 try expect(r.next_value == 2);
400400
401401 r.next_value = 0xff;
402 expect(r.random.intRangeLessThan(u8, 0, 0x80) == 0x7f);
402 try expect(r.random.intRangeLessThan(u8, 0, 0x80) == 0x7f);
403403 r.next_value = 0xff;
404 expect(r.random.intRangeLessThan(u8, 0x7f, 0xff) == 0xfe);
404 try expect(r.random.intRangeLessThan(u8, 0x7f, 0xff) == 0xfe);
405405
406406 r.next_value = 0xff;
407 expect(r.random.intRangeLessThan(i8, 0, 0x40) == 0x3f);
407 try expect(r.random.intRangeLessThan(i8, 0, 0x40) == 0x3f);
408408 r.next_value = 0xff;
409 expect(r.random.intRangeLessThan(i8, -0x40, 0x40) == 0x3f);
409 try expect(r.random.intRangeLessThan(i8, -0x40, 0x40) == 0x3f);
410410 r.next_value = 0xff;
411 expect(r.random.intRangeLessThan(i8, -0x80, 0) == -1);
411 try expect(r.random.intRangeLessThan(i8, -0x80, 0) == -1);
412412
413413 r.next_value = 0xff;
414 expect(r.random.intRangeLessThan(i3, -4, 0) == -1);
414 try expect(r.random.intRangeLessThan(i3, -4, 0) == -1);
415415 r.next_value = 0xff;
416 expect(r.random.intRangeLessThan(i3, -2, 2) == 1);
416 try expect(r.random.intRangeLessThan(i3, -2, 2) == 1);
417417}
418418
419419test "Random intAtMost" {
420420 @setEvalBranchQuota(10000);
421 testRandomIntAtMost();
422 comptime testRandomIntAtMost();
421 try testRandomIntAtMost();
422 comptime try testRandomIntAtMost();
423423}
424fn testRandomIntAtMost() void {
424fn testRandomIntAtMost() !void {
425425 var r = SequentialPrng.init();
426426 r.next_value = 0xff;
427 expect(r.random.uintAtMost(u8, 3) == 3);
428 expect(r.next_value == 0);
429 expect(r.random.uintAtMost(u8, 3) == 0);
427 try expect(r.random.uintAtMost(u8, 3) == 3);
428 try expect(r.next_value == 0);
429 try expect(r.random.uintAtMost(u8, 3) == 0);
430430
431431 // trigger the bias rejection code path
432432 r.next_value = 0;
433 expect(r.random.uintAtMost(u8, 2) == 0);
433 try expect(r.random.uintAtMost(u8, 2) == 0);
434434 // verify we incremented twice
435 expect(r.next_value == 2);
435 try expect(r.next_value == 2);
436436
437437 r.next_value = 0xff;
438 expect(r.random.intRangeAtMost(u8, 0, 0x7f) == 0x7f);
438 try expect(r.random.intRangeAtMost(u8, 0, 0x7f) == 0x7f);
439439 r.next_value = 0xff;
440 expect(r.random.intRangeAtMost(u8, 0x7f, 0xfe) == 0xfe);
440 try expect(r.random.intRangeAtMost(u8, 0x7f, 0xfe) == 0xfe);
441441
442442 r.next_value = 0xff;
443 expect(r.random.intRangeAtMost(i8, 0, 0x3f) == 0x3f);
443 try expect(r.random.intRangeAtMost(i8, 0, 0x3f) == 0x3f);
444444 r.next_value = 0xff;
445 expect(r.random.intRangeAtMost(i8, -0x40, 0x3f) == 0x3f);
445 try expect(r.random.intRangeAtMost(i8, -0x40, 0x3f) == 0x3f);
446446 r.next_value = 0xff;
447 expect(r.random.intRangeAtMost(i8, -0x80, -1) == -1);
447 try expect(r.random.intRangeAtMost(i8, -0x80, -1) == -1);
448448
449449 r.next_value = 0xff;
450 expect(r.random.intRangeAtMost(i3, -4, -1) == -1);
450 try expect(r.random.intRangeAtMost(i3, -4, -1) == -1);
451451 r.next_value = 0xff;
452 expect(r.random.intRangeAtMost(i3, -2, 1) == 1);
452 try expect(r.random.intRangeAtMost(i3, -2, 1) == 1);
453453
454 expect(r.random.uintAtMost(u0, 0) == 0);
454 try expect(r.random.uintAtMost(u0, 0) == 0);
455455}
456456
457457test "Random Biased" {
......@@ -459,30 +459,30 @@ test "Random Biased" {
459459 // Not thoroughly checking the logic here.
460460 // Just want to execute all the paths with different types.
461461
462 expect(r.random.uintLessThanBiased(u1, 1) == 0);
463 expect(r.random.uintLessThanBiased(u32, 10) < 10);
464 expect(r.random.uintLessThanBiased(u64, 20) < 20);
462 try expect(r.random.uintLessThanBiased(u1, 1) == 0);
463 try expect(r.random.uintLessThanBiased(u32, 10) < 10);
464 try expect(r.random.uintLessThanBiased(u64, 20) < 20);
465465
466 expect(r.random.uintAtMostBiased(u0, 0) == 0);
467 expect(r.random.uintAtMostBiased(u1, 0) <= 0);
468 expect(r.random.uintAtMostBiased(u32, 10) <= 10);
469 expect(r.random.uintAtMostBiased(u64, 20) <= 20);
466 try expect(r.random.uintAtMostBiased(u0, 0) == 0);
467 try expect(r.random.uintAtMostBiased(u1, 0) <= 0);
468 try expect(r.random.uintAtMostBiased(u32, 10) <= 10);
469 try expect(r.random.uintAtMostBiased(u64, 20) <= 20);
470470
471 expect(r.random.intRangeLessThanBiased(u1, 0, 1) == 0);
472 expect(r.random.intRangeLessThanBiased(i1, -1, 0) == -1);
473 expect(r.random.intRangeLessThanBiased(u32, 10, 20) >= 10);
474 expect(r.random.intRangeLessThanBiased(i32, 10, 20) >= 10);
475 expect(r.random.intRangeLessThanBiased(u64, 20, 40) >= 20);
476 expect(r.random.intRangeLessThanBiased(i64, 20, 40) >= 20);
471 try expect(r.random.intRangeLessThanBiased(u1, 0, 1) == 0);
472 try expect(r.random.intRangeLessThanBiased(i1, -1, 0) == -1);
473 try expect(r.random.intRangeLessThanBiased(u32, 10, 20) >= 10);
474 try expect(r.random.intRangeLessThanBiased(i32, 10, 20) >= 10);
475 try expect(r.random.intRangeLessThanBiased(u64, 20, 40) >= 20);
476 try expect(r.random.intRangeLessThanBiased(i64, 20, 40) >= 20);
477477
478478 // uncomment for broken module error:
479479 //expect(r.random.intRangeAtMostBiased(u0, 0, 0) == 0);
480 expect(r.random.intRangeAtMostBiased(u1, 0, 1) >= 0);
481 expect(r.random.intRangeAtMostBiased(i1, -1, 0) >= -1);
482 expect(r.random.intRangeAtMostBiased(u32, 10, 20) >= 10);
483 expect(r.random.intRangeAtMostBiased(i32, 10, 20) >= 10);
484 expect(r.random.intRangeAtMostBiased(u64, 20, 40) >= 20);
485 expect(r.random.intRangeAtMostBiased(i64, 20, 40) >= 20);
480 try expect(r.random.intRangeAtMostBiased(u1, 0, 1) >= 0);
481 try expect(r.random.intRangeAtMostBiased(i1, -1, 0) >= -1);
482 try expect(r.random.intRangeAtMostBiased(u32, 10, 20) >= 10);
483 try expect(r.random.intRangeAtMostBiased(i32, 10, 20) >= 10);
484 try expect(r.random.intRangeAtMostBiased(u64, 20, 40) >= 20);
485 try expect(r.random.intRangeAtMostBiased(i64, 20, 40) >= 20);
486486}
487487
488488// Generator to extend 64-bit seed values into longer sequences.
......@@ -519,7 +519,7 @@ test "splitmix64 sequence" {
519519 };
520520
521521 for (seq) |s| {
522 expect(s == r.next());
522 try expect(s == r.next());
523523 }
524524}
525525
......@@ -530,12 +530,12 @@ test "Random float" {
530530 var i: usize = 0;
531531 while (i < 1000) : (i += 1) {
532532 const val1 = prng.random.float(f32);
533 expect(val1 >= 0.0);
534 expect(val1 < 1.0);
533 try expect(val1 >= 0.0);
534 try expect(val1 < 1.0);
535535
536536 const val2 = prng.random.float(f64);
537 expect(val2 >= 0.0);
538 expect(val2 < 1.0);
537 try expect(val2 >= 0.0);
538 try expect(val2 < 1.0);
539539 }
540540}
541541
......@@ -549,12 +549,12 @@ test "Random shuffle" {
549549 while (i < 1000) : (i += 1) {
550550 prng.random.shuffle(u8, seq[0..]);
551551 seen[seq[0]] = true;
552 expect(sumArray(seq[0..]) == 10);
552 try expect(sumArray(seq[0..]) == 10);
553553 }
554554
555555 // we should see every entry at the head at least once
556556 for (seen) |e| {
557 expect(e == true);
557 try expect(e == true);
558558 }
559559}
560560
......@@ -567,17 +567,17 @@ fn sumArray(s: []const u8) u32 {
567567
568568test "Random range" {
569569 var prng = DefaultPrng.init(0);
570 testRange(&prng.random, -4, 3);
571 testRange(&prng.random, -4, -1);
572 testRange(&prng.random, 10, 14);
573 testRange(&prng.random, -0x80, 0x7f);
570 try testRange(&prng.random, -4, 3);
571 try testRange(&prng.random, -4, -1);
572 try testRange(&prng.random, 10, 14);
573 try testRange(&prng.random, -0x80, 0x7f);
574574}
575575
576fn testRange(r: *Random, start: i8, end: i8) void {
577 testRangeBias(r, start, end, true);
578 testRangeBias(r, start, end, false);
576fn testRange(r: *Random, start: i8, end: i8) !void {
577 try testRangeBias(r, start, end, true);
578 try testRangeBias(r, start, end, false);
579579}
580fn testRangeBias(r: *Random, start: i8, end: i8, biased: bool) void {
580fn testRangeBias(r: *Random, start: i8, end: i8, biased: bool) !void {
581581 const count = @intCast(usize, @as(i32, end) - @as(i32, start));
582582 var values_buffer = [_]bool{false} ** 0x100;
583583 const values = values_buffer[0..count];
......@@ -599,7 +599,7 @@ test "CSPRNG" {
599599 const a = csprng.random.int(u64);
600600 const b = csprng.random.int(u64);
601601 const c = csprng.random.int(u64);
602 expect(a ^ b ^ c != 0);
602 try expect(a ^ b ^ c != 0);
603603}
604604
605605test {
lib/std/rand/Isaac64.zig+2-2
......@@ -205,7 +205,7 @@ test "isaac64 sequence" {
205205 };
206206
207207 for (seq) |s| {
208 std.testing.expect(s == r.next());
208 try std.testing.expect(s == r.next());
209209 }
210210}
211211
......@@ -237,6 +237,6 @@ test "isaac64 fill" {
237237 var buf1: [7]u8 = undefined;
238238 std.mem.writeIntLittle(u64, &buf0, s);
239239 Isaac64.fill(&r.random, &buf1);
240 std.testing.expect(std.mem.eql(u8, buf0[0..7], buf1[0..]));
240 try std.testing.expect(std.mem.eql(u8, buf0[0..7], buf1[0..]));
241241 }
242242}
lib/std/rand/Pcg.zig+2-2
......@@ -96,7 +96,7 @@ test "pcg sequence" {
9696 };
9797
9898 for (seq) |s| {
99 std.testing.expect(s == r.next());
99 try std.testing.expect(s == r.next());
100100 }
101101}
102102
......@@ -120,6 +120,6 @@ test "pcg fill" {
120120 var buf1: [3]u8 = undefined;
121121 std.mem.writeIntLittle(u32, &buf0, s);
122122 Pcg.fill(&r.random, &buf1);
123 std.testing.expect(std.mem.eql(u8, buf0[0..3], buf1[0..]));
123 try std.testing.expect(std.mem.eql(u8, buf0[0..3], buf1[0..]));
124124 }
125125}
lib/std/rand/Sfc64.zig+2-2
......@@ -103,7 +103,7 @@ test "Sfc64 sequence" {
103103 };
104104
105105 for (seq) |s| {
106 std.testing.expectEqual(s, r.next());
106 try std.testing.expectEqual(s, r.next());
107107 }
108108}
109109
......@@ -135,6 +135,6 @@ test "Sfc64 fill" {
135135 var buf1: [7]u8 = undefined;
136136 std.mem.writeIntLittle(u64, &buf0, s);
137137 Sfc64.fill(&r.random, &buf1);
138 std.testing.expect(std.mem.eql(u8, buf0[0..7], buf1[0..]));
138 try std.testing.expect(std.mem.eql(u8, buf0[0..7], buf1[0..]));
139139 }
140140}
lib/std/rand/Xoroshiro128.zig+3-3
......@@ -113,7 +113,7 @@ test "xoroshiro sequence" {
113113 };
114114
115115 for (seq1) |s| {
116 std.testing.expect(s == r.next());
116 try std.testing.expect(s == r.next());
117117 }
118118
119119 r.jump();
......@@ -128,7 +128,7 @@ test "xoroshiro sequence" {
128128 };
129129
130130 for (seq2) |s| {
131 std.testing.expect(s == r.next());
131 try std.testing.expect(s == r.next());
132132 }
133133}
134134
......@@ -151,6 +151,6 @@ test "xoroshiro fill" {
151151 var buf1: [7]u8 = undefined;
152152 std.mem.writeIntLittle(u64, &buf0, s);
153153 Xoroshiro128.fill(&r.random, &buf1);
154 std.testing.expect(std.mem.eql(u8, buf0[0..7], buf1[0..]));
154 try std.testing.expect(std.mem.eql(u8, buf0[0..7], buf1[0..]));
155155 }
156156}
lib/std/sort.zig+65-65
......@@ -43,35 +43,35 @@ test "binarySearch" {
4343 return math.order(lhs, rhs);
4444 }
4545 };
46 testing.expectEqual(
46 try testing.expectEqual(
4747 @as(?usize, null),
4848 binarySearch(u32, 1, &[_]u32{}, {}, S.order_u32),
4949 );
50 testing.expectEqual(
50 try testing.expectEqual(
5151 @as(?usize, 0),
5252 binarySearch(u32, 1, &[_]u32{1}, {}, S.order_u32),
5353 );
54 testing.expectEqual(
54 try testing.expectEqual(
5555 @as(?usize, null),
5656 binarySearch(u32, 1, &[_]u32{0}, {}, S.order_u32),
5757 );
58 testing.expectEqual(
58 try testing.expectEqual(
5959 @as(?usize, null),
6060 binarySearch(u32, 0, &[_]u32{1}, {}, S.order_u32),
6161 );
62 testing.expectEqual(
62 try testing.expectEqual(
6363 @as(?usize, 4),
6464 binarySearch(u32, 5, &[_]u32{ 1, 2, 3, 4, 5 }, {}, S.order_u32),
6565 );
66 testing.expectEqual(
66 try testing.expectEqual(
6767 @as(?usize, 0),
6868 binarySearch(u32, 2, &[_]u32{ 2, 4, 8, 16, 32, 64 }, {}, S.order_u32),
6969 );
70 testing.expectEqual(
70 try testing.expectEqual(
7171 @as(?usize, 1),
7272 binarySearch(i32, -4, &[_]i32{ -7, -4, 0, 9, 10 }, {}, S.order_i32),
7373 );
74 testing.expectEqual(
74 try testing.expectEqual(
7575 @as(?usize, 3),
7676 binarySearch(i32, 98, &[_]i32{ -100, -25, 2, 98, 99, 100 }, {}, S.order_i32),
7777 );
......@@ -1152,10 +1152,10 @@ pub fn desc(comptime T: type) fn (void, T, T) bool {
11521152}
11531153
11541154test "stable sort" {
1155 testStableSort();
1156 comptime testStableSort();
1155 try testStableSort();
1156 comptime try testStableSort();
11571157}
1158fn testStableSort() void {
1158fn testStableSort() !void {
11591159 var expected = [_]IdAndValue{
11601160 IdAndValue{ .id = 0, .value = 0 },
11611161 IdAndValue{ .id = 1, .value = 0 },
......@@ -1194,8 +1194,8 @@ fn testStableSort() void {
11941194 for (cases) |*case| {
11951195 insertionSort(IdAndValue, (case.*)[0..], {}, cmpByValue);
11961196 for (case.*) |item, i| {
1197 testing.expect(item.id == expected[i].id);
1198 testing.expect(item.value == expected[i].value);
1197 try testing.expect(item.id == expected[i].id);
1198 try testing.expect(item.value == expected[i].value);
11991199 }
12001200 }
12011201}
......@@ -1245,7 +1245,7 @@ test "sort" {
12451245 const slice = buf[0..case[0].len];
12461246 mem.copy(u8, slice, case[0]);
12471247 sort(u8, slice, {}, asc_u8);
1248 testing.expect(mem.eql(u8, slice, case[1]));
1248 try testing.expect(mem.eql(u8, slice, case[1]));
12491249 }
12501250
12511251 const i32cases = [_][]const []const i32{
......@@ -1280,7 +1280,7 @@ test "sort" {
12801280 const slice = buf[0..case[0].len];
12811281 mem.copy(i32, slice, case[0]);
12821282 sort(i32, slice, {}, asc_i32);
1283 testing.expect(mem.eql(i32, slice, case[1]));
1283 try testing.expect(mem.eql(i32, slice, case[1]));
12841284 }
12851285}
12861286
......@@ -1317,7 +1317,7 @@ test "sort descending" {
13171317 const slice = buf[0..case[0].len];
13181318 mem.copy(i32, slice, case[0]);
13191319 sort(i32, slice, {}, desc_i32);
1320 testing.expect(mem.eql(i32, slice, case[1]));
1320 try testing.expect(mem.eql(i32, slice, case[1]));
13211321 }
13221322}
13231323
......@@ -1325,7 +1325,7 @@ test "another sort case" {
13251325 var arr = [_]i32{ 5, 3, 1, 2, 4 };
13261326 sort(i32, arr[0..], {}, asc_i32);
13271327
1328 testing.expect(mem.eql(i32, &arr, &[_]i32{ 1, 2, 3, 4, 5 }));
1328 try testing.expect(mem.eql(i32, &arr, &[_]i32{ 1, 2, 3, 4, 5 }));
13291329}
13301330
13311331test "sort fuzz testing" {
......@@ -1353,9 +1353,9 @@ fn fuzzTest(rng: *std.rand.Random) !void {
13531353 var index: usize = 1;
13541354 while (index < array.len) : (index += 1) {
13551355 if (array[index].value == array[index - 1].value) {
1356 testing.expect(array[index].id > array[index - 1].id);
1356 try testing.expect(array[index].id > array[index - 1].id);
13571357 } else {
1358 testing.expect(array[index].value > array[index - 1].value);
1358 try testing.expect(array[index].value > array[index - 1].value);
13591359 }
13601360 }
13611361}
......@@ -1383,13 +1383,13 @@ pub fn argMin(
13831383}
13841384
13851385test "argMin" {
1386 testing.expectEqual(@as(?usize, null), argMin(i32, &[_]i32{}, {}, asc_i32));
1387 testing.expectEqual(@as(?usize, 0), argMin(i32, &[_]i32{1}, {}, asc_i32));
1388 testing.expectEqual(@as(?usize, 0), argMin(i32, &[_]i32{ 1, 2, 3, 4, 5 }, {}, asc_i32));
1389 testing.expectEqual(@as(?usize, 3), argMin(i32, &[_]i32{ 9, 3, 8, 2, 5 }, {}, asc_i32));
1390 testing.expectEqual(@as(?usize, 0), argMin(i32, &[_]i32{ 1, 1, 1, 1, 1 }, {}, asc_i32));
1391 testing.expectEqual(@as(?usize, 0), argMin(i32, &[_]i32{ -10, 1, 10 }, {}, asc_i32));
1392 testing.expectEqual(@as(?usize, 3), argMin(i32, &[_]i32{ 6, 3, 5, 7, 6 }, {}, desc_i32));
1386 try testing.expectEqual(@as(?usize, null), argMin(i32, &[_]i32{}, {}, asc_i32));
1387 try testing.expectEqual(@as(?usize, 0), argMin(i32, &[_]i32{1}, {}, asc_i32));
1388 try testing.expectEqual(@as(?usize, 0), argMin(i32, &[_]i32{ 1, 2, 3, 4, 5 }, {}, asc_i32));
1389 try testing.expectEqual(@as(?usize, 3), argMin(i32, &[_]i32{ 9, 3, 8, 2, 5 }, {}, asc_i32));
1390 try testing.expectEqual(@as(?usize, 0), argMin(i32, &[_]i32{ 1, 1, 1, 1, 1 }, {}, asc_i32));
1391 try testing.expectEqual(@as(?usize, 0), argMin(i32, &[_]i32{ -10, 1, 10 }, {}, asc_i32));
1392 try testing.expectEqual(@as(?usize, 3), argMin(i32, &[_]i32{ 6, 3, 5, 7, 6 }, {}, desc_i32));
13931393}
13941394
13951395pub fn min(
......@@ -1403,13 +1403,13 @@ pub fn min(
14031403}
14041404
14051405test "min" {
1406 testing.expectEqual(@as(?i32, null), min(i32, &[_]i32{}, {}, asc_i32));
1407 testing.expectEqual(@as(?i32, 1), min(i32, &[_]i32{1}, {}, asc_i32));
1408 testing.expectEqual(@as(?i32, 1), min(i32, &[_]i32{ 1, 2, 3, 4, 5 }, {}, asc_i32));
1409 testing.expectEqual(@as(?i32, 2), min(i32, &[_]i32{ 9, 3, 8, 2, 5 }, {}, asc_i32));
1410 testing.expectEqual(@as(?i32, 1), min(i32, &[_]i32{ 1, 1, 1, 1, 1 }, {}, asc_i32));
1411 testing.expectEqual(@as(?i32, -10), min(i32, &[_]i32{ -10, 1, 10 }, {}, asc_i32));
1412 testing.expectEqual(@as(?i32, 7), min(i32, &[_]i32{ 6, 3, 5, 7, 6 }, {}, desc_i32));
1406 try testing.expectEqual(@as(?i32, null), min(i32, &[_]i32{}, {}, asc_i32));
1407 try testing.expectEqual(@as(?i32, 1), min(i32, &[_]i32{1}, {}, asc_i32));
1408 try testing.expectEqual(@as(?i32, 1), min(i32, &[_]i32{ 1, 2, 3, 4, 5 }, {}, asc_i32));
1409 try testing.expectEqual(@as(?i32, 2), min(i32, &[_]i32{ 9, 3, 8, 2, 5 }, {}, asc_i32));
1410 try testing.expectEqual(@as(?i32, 1), min(i32, &[_]i32{ 1, 1, 1, 1, 1 }, {}, asc_i32));
1411 try testing.expectEqual(@as(?i32, -10), min(i32, &[_]i32{ -10, 1, 10 }, {}, asc_i32));
1412 try testing.expectEqual(@as(?i32, 7), min(i32, &[_]i32{ 6, 3, 5, 7, 6 }, {}, desc_i32));
14131413}
14141414
14151415pub fn argMax(
......@@ -1435,13 +1435,13 @@ pub fn argMax(
14351435}
14361436
14371437test "argMax" {
1438 testing.expectEqual(@as(?usize, null), argMax(i32, &[_]i32{}, {}, asc_i32));
1439 testing.expectEqual(@as(?usize, 0), argMax(i32, &[_]i32{1}, {}, asc_i32));
1440 testing.expectEqual(@as(?usize, 4), argMax(i32, &[_]i32{ 1, 2, 3, 4, 5 }, {}, asc_i32));
1441 testing.expectEqual(@as(?usize, 0), argMax(i32, &[_]i32{ 9, 3, 8, 2, 5 }, {}, asc_i32));
1442 testing.expectEqual(@as(?usize, 0), argMax(i32, &[_]i32{ 1, 1, 1, 1, 1 }, {}, asc_i32));
1443 testing.expectEqual(@as(?usize, 2), argMax(i32, &[_]i32{ -10, 1, 10 }, {}, asc_i32));
1444 testing.expectEqual(@as(?usize, 1), argMax(i32, &[_]i32{ 6, 3, 5, 7, 6 }, {}, desc_i32));
1438 try testing.expectEqual(@as(?usize, null), argMax(i32, &[_]i32{}, {}, asc_i32));
1439 try testing.expectEqual(@as(?usize, 0), argMax(i32, &[_]i32{1}, {}, asc_i32));
1440 try testing.expectEqual(@as(?usize, 4), argMax(i32, &[_]i32{ 1, 2, 3, 4, 5 }, {}, asc_i32));
1441 try testing.expectEqual(@as(?usize, 0), argMax(i32, &[_]i32{ 9, 3, 8, 2, 5 }, {}, asc_i32));
1442 try testing.expectEqual(@as(?usize, 0), argMax(i32, &[_]i32{ 1, 1, 1, 1, 1 }, {}, asc_i32));
1443 try testing.expectEqual(@as(?usize, 2), argMax(i32, &[_]i32{ -10, 1, 10 }, {}, asc_i32));
1444 try testing.expectEqual(@as(?usize, 1), argMax(i32, &[_]i32{ 6, 3, 5, 7, 6 }, {}, desc_i32));
14451445}
14461446
14471447pub fn max(
......@@ -1455,13 +1455,13 @@ pub fn max(
14551455}
14561456
14571457test "max" {
1458 testing.expectEqual(@as(?i32, null), max(i32, &[_]i32{}, {}, asc_i32));
1459 testing.expectEqual(@as(?i32, 1), max(i32, &[_]i32{1}, {}, asc_i32));
1460 testing.expectEqual(@as(?i32, 5), max(i32, &[_]i32{ 1, 2, 3, 4, 5 }, {}, asc_i32));
1461 testing.expectEqual(@as(?i32, 9), max(i32, &[_]i32{ 9, 3, 8, 2, 5 }, {}, asc_i32));
1462 testing.expectEqual(@as(?i32, 1), max(i32, &[_]i32{ 1, 1, 1, 1, 1 }, {}, asc_i32));
1463 testing.expectEqual(@as(?i32, 10), max(i32, &[_]i32{ -10, 1, 10 }, {}, asc_i32));
1464 testing.expectEqual(@as(?i32, 3), max(i32, &[_]i32{ 6, 3, 5, 7, 6 }, {}, desc_i32));
1458 try testing.expectEqual(@as(?i32, null), max(i32, &[_]i32{}, {}, asc_i32));
1459 try testing.expectEqual(@as(?i32, 1), max(i32, &[_]i32{1}, {}, asc_i32));
1460 try testing.expectEqual(@as(?i32, 5), max(i32, &[_]i32{ 1, 2, 3, 4, 5 }, {}, asc_i32));
1461 try testing.expectEqual(@as(?i32, 9), max(i32, &[_]i32{ 9, 3, 8, 2, 5 }, {}, asc_i32));
1462 try testing.expectEqual(@as(?i32, 1), max(i32, &[_]i32{ 1, 1, 1, 1, 1 }, {}, asc_i32));
1463 try testing.expectEqual(@as(?i32, 10), max(i32, &[_]i32{ -10, 1, 10 }, {}, asc_i32));
1464 try testing.expectEqual(@as(?i32, 3), max(i32, &[_]i32{ 6, 3, 5, 7, 6 }, {}, desc_i32));
14651465}
14661466
14671467pub fn isSorted(
......@@ -1481,28 +1481,28 @@ pub fn isSorted(
14811481}
14821482
14831483test "isSorted" {
1484 testing.expect(isSorted(i32, &[_]i32{}, {}, asc_i32));
1485 testing.expect(isSorted(i32, &[_]i32{10}, {}, asc_i32));
1486 testing.expect(isSorted(i32, &[_]i32{ 1, 2, 3, 4, 5 }, {}, asc_i32));
1487 testing.expect(isSorted(i32, &[_]i32{ -10, 1, 1, 1, 10 }, {}, asc_i32));
1484 try testing.expect(isSorted(i32, &[_]i32{}, {}, asc_i32));
1485 try testing.expect(isSorted(i32, &[_]i32{10}, {}, asc_i32));
1486 try testing.expect(isSorted(i32, &[_]i32{ 1, 2, 3, 4, 5 }, {}, asc_i32));
1487 try testing.expect(isSorted(i32, &[_]i32{ -10, 1, 1, 1, 10 }, {}, asc_i32));
14881488
1489 testing.expect(isSorted(i32, &[_]i32{}, {}, desc_i32));
1490 testing.expect(isSorted(i32, &[_]i32{-20}, {}, desc_i32));
1491 testing.expect(isSorted(i32, &[_]i32{ 3, 2, 1, 0, -1 }, {}, desc_i32));
1492 testing.expect(isSorted(i32, &[_]i32{ 10, -10 }, {}, desc_i32));
1489 try testing.expect(isSorted(i32, &[_]i32{}, {}, desc_i32));
1490 try testing.expect(isSorted(i32, &[_]i32{-20}, {}, desc_i32));
1491 try testing.expect(isSorted(i32, &[_]i32{ 3, 2, 1, 0, -1 }, {}, desc_i32));
1492 try testing.expect(isSorted(i32, &[_]i32{ 10, -10 }, {}, desc_i32));
14931493
1494 testing.expect(isSorted(i32, &[_]i32{ 1, 1, 1, 1, 1 }, {}, asc_i32));
1495 testing.expect(isSorted(i32, &[_]i32{ 1, 1, 1, 1, 1 }, {}, desc_i32));
1494 try testing.expect(isSorted(i32, &[_]i32{ 1, 1, 1, 1, 1 }, {}, asc_i32));
1495 try testing.expect(isSorted(i32, &[_]i32{ 1, 1, 1, 1, 1 }, {}, desc_i32));
14961496
1497 testing.expectEqual(false, isSorted(i32, &[_]i32{ 5, 4, 3, 2, 1 }, {}, asc_i32));
1498 testing.expectEqual(false, isSorted(i32, &[_]i32{ 1, 2, 3, 4, 5 }, {}, desc_i32));
1497 try testing.expectEqual(false, isSorted(i32, &[_]i32{ 5, 4, 3, 2, 1 }, {}, asc_i32));
1498 try testing.expectEqual(false, isSorted(i32, &[_]i32{ 1, 2, 3, 4, 5 }, {}, desc_i32));
14991499
1500 testing.expect(isSorted(u8, "abcd", {}, asc_u8));
1501 testing.expect(isSorted(u8, "zyxw", {}, desc_u8));
1500 try testing.expect(isSorted(u8, "abcd", {}, asc_u8));
1501 try testing.expect(isSorted(u8, "zyxw", {}, desc_u8));
15021502
1503 testing.expectEqual(false, isSorted(u8, "abcd", {}, desc_u8));
1504 testing.expectEqual(false, isSorted(u8, "zyxw", {}, asc_u8));
1503 try testing.expectEqual(false, isSorted(u8, "abcd", {}, desc_u8));
1504 try testing.expectEqual(false, isSorted(u8, "zyxw", {}, asc_u8));
15051505
1506 testing.expect(isSorted(u8, "ffff", {}, asc_u8));
1507 testing.expect(isSorted(u8, "ffff", {}, desc_u8));
1506 try testing.expect(isSorted(u8, "ffff", {}, asc_u8));
1507 try testing.expect(isSorted(u8, "ffff", {}, desc_u8));
15081508}
lib/std/special/c.zig+47-47
......@@ -69,7 +69,7 @@ test "strcpy" {
6969
7070 s1[0] = 0;
7171 _ = strcpy(&s1, "foobarbaz");
72 std.testing.expectEqualSlices(u8, "foobarbaz", std.mem.spanZ(&s1));
72 try std.testing.expectEqualSlices(u8, "foobarbaz", std.mem.spanZ(&s1));
7373}
7474
7575fn strncpy(dest: [*:0]u8, src: [*:0]const u8, n: usize) callconv(.C) [*:0]u8 {
......@@ -89,7 +89,7 @@ test "strncpy" {
8989
9090 s1[0] = 0;
9191 _ = strncpy(&s1, "foobarbaz", @sizeOf(@TypeOf(s1)));
92 std.testing.expectEqualSlices(u8, "foobarbaz", std.mem.spanZ(&s1));
92 try std.testing.expectEqualSlices(u8, "foobarbaz", std.mem.spanZ(&s1));
9393}
9494
9595fn strcat(dest: [*:0]u8, src: [*:0]const u8) callconv(.C) [*:0]u8 {
......@@ -112,7 +112,7 @@ test "strcat" {
112112 _ = strcat(&s1, "foo");
113113 _ = strcat(&s1, "bar");
114114 _ = strcat(&s1, "baz");
115 std.testing.expectEqualSlices(u8, "foobarbaz", std.mem.spanZ(&s1));
115 try std.testing.expectEqualSlices(u8, "foobarbaz", std.mem.spanZ(&s1));
116116}
117117
118118fn strncat(dest: [*:0]u8, src: [*:0]const u8, avail: usize) callconv(.C) [*:0]u8 {
......@@ -135,7 +135,7 @@ test "strncat" {
135135 _ = strncat(&s1, "foo1111", 3);
136136 _ = strncat(&s1, "bar1111", 3);
137137 _ = strncat(&s1, "baz1111", 3);
138 std.testing.expectEqualSlices(u8, "foobarbaz", std.mem.spanZ(&s1));
138 try std.testing.expectEqualSlices(u8, "foobarbaz", std.mem.spanZ(&s1));
139139}
140140
141141fn strcmp(s1: [*:0]const u8, s2: [*:0]const u8) callconv(.C) c_int {
......@@ -164,10 +164,10 @@ fn strerror(errnum: c_int) callconv(.C) [*:0]const u8 {
164164}
165165
166166test "strncmp" {
167 std.testing.expect(strncmp("a", "b", 1) == -1);
168 std.testing.expect(strncmp("a", "c", 1) == -2);
169 std.testing.expect(strncmp("b", "a", 1) == 1);
170 std.testing.expect(strncmp("\xff", "\x02", 1) == 253);
167 try std.testing.expect(strncmp("a", "b", 1) == -1);
168 try std.testing.expect(strncmp("a", "c", 1) == -2);
169 try std.testing.expect(strncmp("b", "a", 1) == 1);
170 try std.testing.expect(strncmp("\xff", "\x02", 1) == 253);
171171}
172172
173173// Avoid dragging in the runtime safety mechanisms into this .o file,
......@@ -248,9 +248,9 @@ test "memcmp" {
248248 const arr2 = &[_]u8{ 1, 0, 1 };
249249 const arr3 = &[_]u8{ 1, 2, 1 };
250250
251 std.testing.expect(memcmp(base_arr[0..], arr1[0..], base_arr.len) == 0);
252 std.testing.expect(memcmp(base_arr[0..], arr2[0..], base_arr.len) > 0);
253 std.testing.expect(memcmp(base_arr[0..], arr3[0..], base_arr.len) < 0);
251 try std.testing.expect(memcmp(base_arr[0..], arr1[0..], base_arr.len) == 0);
252 try std.testing.expect(memcmp(base_arr[0..], arr2[0..], base_arr.len) > 0);
253 try std.testing.expect(memcmp(base_arr[0..], arr3[0..], base_arr.len) < 0);
254254}
255255
256256export fn bcmp(vl: [*]allowzero const u8, vr: [*]allowzero const u8, n: usize) callconv(.C) isize {
......@@ -272,9 +272,9 @@ test "bcmp" {
272272 const arr2 = &[_]u8{ 1, 0, 1 };
273273 const arr3 = &[_]u8{ 1, 2, 1 };
274274
275 std.testing.expect(bcmp(base_arr[0..], arr1[0..], base_arr.len) == 0);
276 std.testing.expect(bcmp(base_arr[0..], arr2[0..], base_arr.len) != 0);
277 std.testing.expect(bcmp(base_arr[0..], arr3[0..], base_arr.len) != 0);
275 try std.testing.expect(bcmp(base_arr[0..], arr1[0..], base_arr.len) == 0);
276 try std.testing.expect(bcmp(base_arr[0..], arr2[0..], base_arr.len) != 0);
277 try std.testing.expect(bcmp(base_arr[0..], arr3[0..], base_arr.len) != 0);
278278}
279279
280280comptime {
......@@ -868,19 +868,19 @@ test "fmod, fmodf" {
868868 const nan_val = math.nan(T);
869869 const inf_val = math.inf(T);
870870
871 std.testing.expect(isNan(generic_fmod(T, nan_val, 1.0)));
872 std.testing.expect(isNan(generic_fmod(T, 1.0, nan_val)));
873 std.testing.expect(isNan(generic_fmod(T, inf_val, 1.0)));
874 std.testing.expect(isNan(generic_fmod(T, 0.0, 0.0)));
875 std.testing.expect(isNan(generic_fmod(T, 1.0, 0.0)));
871 try std.testing.expect(isNan(generic_fmod(T, nan_val, 1.0)));
872 try std.testing.expect(isNan(generic_fmod(T, 1.0, nan_val)));
873 try std.testing.expect(isNan(generic_fmod(T, inf_val, 1.0)));
874 try std.testing.expect(isNan(generic_fmod(T, 0.0, 0.0)));
875 try std.testing.expect(isNan(generic_fmod(T, 1.0, 0.0)));
876876
877 std.testing.expectEqual(@as(T, 0.0), generic_fmod(T, 0.0, 2.0));
878 std.testing.expectEqual(@as(T, -0.0), generic_fmod(T, -0.0, 2.0));
877 try std.testing.expectEqual(@as(T, 0.0), generic_fmod(T, 0.0, 2.0));
878 try std.testing.expectEqual(@as(T, -0.0), generic_fmod(T, -0.0, 2.0));
879879
880 std.testing.expectEqual(@as(T, -2.0), generic_fmod(T, -32.0, 10.0));
881 std.testing.expectEqual(@as(T, -2.0), generic_fmod(T, -32.0, -10.0));
882 std.testing.expectEqual(@as(T, 2.0), generic_fmod(T, 32.0, 10.0));
883 std.testing.expectEqual(@as(T, 2.0), generic_fmod(T, 32.0, -10.0));
880 try std.testing.expectEqual(@as(T, -2.0), generic_fmod(T, -32.0, 10.0));
881 try std.testing.expectEqual(@as(T, -2.0), generic_fmod(T, -32.0, -10.0));
882 try std.testing.expectEqual(@as(T, 2.0), generic_fmod(T, 32.0, 10.0));
883 try std.testing.expectEqual(@as(T, 2.0), generic_fmod(T, 32.0, -10.0));
884884 }
885885}
886886
......@@ -904,12 +904,12 @@ test "fmin, fminf" {
904904 inline for ([_]type{ f32, f64 }) |T| {
905905 const nan_val = math.nan(T);
906906
907 std.testing.expect(isNan(generic_fmin(T, nan_val, nan_val)));
908 std.testing.expectEqual(@as(T, 1.0), generic_fmin(T, nan_val, 1.0));
909 std.testing.expectEqual(@as(T, 1.0), generic_fmin(T, 1.0, nan_val));
907 try std.testing.expect(isNan(generic_fmin(T, nan_val, nan_val)));
908 try std.testing.expectEqual(@as(T, 1.0), generic_fmin(T, nan_val, 1.0));
909 try std.testing.expectEqual(@as(T, 1.0), generic_fmin(T, 1.0, nan_val));
910910
911 std.testing.expectEqual(@as(T, 1.0), generic_fmin(T, 1.0, 10.0));
912 std.testing.expectEqual(@as(T, -1.0), generic_fmin(T, 1.0, -1.0));
911 try std.testing.expectEqual(@as(T, 1.0), generic_fmin(T, 1.0, 10.0));
912 try std.testing.expectEqual(@as(T, -1.0), generic_fmin(T, 1.0, -1.0));
913913 }
914914}
915915
......@@ -933,12 +933,12 @@ test "fmax, fmaxf" {
933933 inline for ([_]type{ f32, f64 }) |T| {
934934 const nan_val = math.nan(T);
935935
936 std.testing.expect(isNan(generic_fmax(T, nan_val, nan_val)));
937 std.testing.expectEqual(@as(T, 1.0), generic_fmax(T, nan_val, 1.0));
938 std.testing.expectEqual(@as(T, 1.0), generic_fmax(T, 1.0, nan_val));
936 try std.testing.expect(isNan(generic_fmax(T, nan_val, nan_val)));
937 try std.testing.expectEqual(@as(T, 1.0), generic_fmax(T, nan_val, 1.0));
938 try std.testing.expectEqual(@as(T, 1.0), generic_fmax(T, 1.0, nan_val));
939939
940 std.testing.expectEqual(@as(T, 10.0), generic_fmax(T, 1.0, 10.0));
941 std.testing.expectEqual(@as(T, 1.0), generic_fmax(T, 1.0, -1.0));
940 try std.testing.expectEqual(@as(T, 10.0), generic_fmax(T, 1.0, 10.0));
941 try std.testing.expectEqual(@as(T, 1.0), generic_fmax(T, 1.0, -1.0));
942942 }
943943}
944944
......@@ -1093,15 +1093,15 @@ test "sqrt" {
10931093 // Note that @sqrt will either generate the sqrt opcode (if supported by the
10941094 // target ISA) or a call to `sqrtf` otherwise.
10951095 for (V) |val|
1096 std.testing.expectEqual(@sqrt(val), sqrt(val));
1096 try std.testing.expectEqual(@sqrt(val), sqrt(val));
10971097}
10981098
10991099test "sqrt special" {
1100 std.testing.expect(std.math.isPositiveInf(sqrt(std.math.inf(f64))));
1101 std.testing.expect(sqrt(0.0) == 0.0);
1102 std.testing.expect(sqrt(-0.0) == -0.0);
1103 std.testing.expect(isNan(sqrt(-1.0)));
1104 std.testing.expect(isNan(sqrt(std.math.nan(f64))));
1100 try std.testing.expect(std.math.isPositiveInf(sqrt(std.math.inf(f64))));
1101 try std.testing.expect(sqrt(0.0) == 0.0);
1102 try std.testing.expect(sqrt(-0.0) == -0.0);
1103 try std.testing.expect(isNan(sqrt(-1.0)));
1104 try std.testing.expect(isNan(sqrt(std.math.nan(f64))));
11051105}
11061106
11071107export fn sqrtf(x: f32) f32 {
......@@ -1198,13 +1198,13 @@ test "sqrtf" {
11981198 // Note that @sqrt will either generate the sqrt opcode (if supported by the
11991199 // target ISA) or a call to `sqrtf` otherwise.
12001200 for (V) |val|
1201 std.testing.expectEqual(@sqrt(val), sqrtf(val));
1201 try std.testing.expectEqual(@sqrt(val), sqrtf(val));
12021202}
12031203
12041204test "sqrtf special" {
1205 std.testing.expect(std.math.isPositiveInf(sqrtf(std.math.inf(f32))));
1206 std.testing.expect(sqrtf(0.0) == 0.0);
1207 std.testing.expect(sqrtf(-0.0) == -0.0);
1208 std.testing.expect(isNan(sqrtf(-1.0)));
1209 std.testing.expect(isNan(sqrtf(std.math.nan(f32))));
1205 try std.testing.expect(std.math.isPositiveInf(sqrtf(std.math.inf(f32))));
1206 try std.testing.expect(sqrtf(0.0) == 0.0);
1207 try std.testing.expect(sqrtf(-0.0) == -0.0);
1208 try std.testing.expect(isNan(sqrtf(-1.0)));
1209 try std.testing.expect(isNan(sqrtf(std.math.nan(f32))));
12101210}
lib/std/special/compiler_rt/addXf3_test.zig+13-13
......@@ -13,7 +13,7 @@ const inf128 = @bitCast(f128, @as(u128, 0x7fff000000000000) << 64);
1313
1414const __addtf3 = @import("addXf3.zig").__addtf3;
1515
16fn test__addtf3(a: f128, b: f128, expected_hi: u64, expected_lo: u64) void {
16fn test__addtf3(a: f128, b: f128, expected_hi: u64, expected_lo: u64) !void {
1717 const x = __addtf3(a, b);
1818
1919 const rep = @bitCast(u128, x);
......@@ -32,28 +32,28 @@ fn test__addtf3(a: f128, b: f128, expected_hi: u64, expected_lo: u64) void {
3232 }
3333 }
3434
35 @panic("__addtf3 test failure");
35 return error.TestFailed;
3636}
3737
3838test "addtf3" {
39 test__addtf3(qnan128, 0x1.23456789abcdefp+5, 0x7fff800000000000, 0x0);
39 try test__addtf3(qnan128, 0x1.23456789abcdefp+5, 0x7fff800000000000, 0x0);
4040
4141 // NaN + any = NaN
42 test__addtf3(@bitCast(f128, (@as(u128, 0x7fff000000000000) << 64) | @as(u128, 0x800030000000)), 0x1.23456789abcdefp+5, 0x7fff800000000000, 0x0);
42 try test__addtf3(@bitCast(f128, (@as(u128, 0x7fff000000000000) << 64) | @as(u128, 0x800030000000)), 0x1.23456789abcdefp+5, 0x7fff800000000000, 0x0);
4343
4444 // inf + inf = inf
45 test__addtf3(inf128, inf128, 0x7fff000000000000, 0x0);
45 try test__addtf3(inf128, inf128, 0x7fff000000000000, 0x0);
4646
4747 // inf + any = inf
48 test__addtf3(inf128, 0x1.2335653452436234723489432abcdefp+5, 0x7fff000000000000, 0x0);
48 try test__addtf3(inf128, 0x1.2335653452436234723489432abcdefp+5, 0x7fff000000000000, 0x0);
4949
5050 // any + any
51 test__addtf3(0x1.23456734245345543849abcdefp+5, 0x1.edcba52449872455634654321fp-1, 0x40042afc95c8b579, 0x61e58dd6c51eb77c);
51 try test__addtf3(0x1.23456734245345543849abcdefp+5, 0x1.edcba52449872455634654321fp-1, 0x40042afc95c8b579, 0x61e58dd6c51eb77c);
5252}
5353
5454const __subtf3 = @import("addXf3.zig").__subtf3;
5555
56fn test__subtf3(a: f128, b: f128, expected_hi: u64, expected_lo: u64) void {
56fn test__subtf3(a: f128, b: f128, expected_hi: u64, expected_lo: u64) !void {
5757 const x = __subtf3(a, b);
5858
5959 const rep = @bitCast(u128, x);
......@@ -72,19 +72,19 @@ fn test__subtf3(a: f128, b: f128, expected_hi: u64, expected_lo: u64) void {
7272 }
7373 }
7474
75 @panic("__subtf3 test failure");
75 return error.TestFailed;
7676}
7777
7878test "subtf3" {
7979 // qNaN - any = qNaN
80 test__subtf3(qnan128, 0x1.23456789abcdefp+5, 0x7fff800000000000, 0x0);
80 try test__subtf3(qnan128, 0x1.23456789abcdefp+5, 0x7fff800000000000, 0x0);
8181
8282 // NaN + any = NaN
83 test__subtf3(@bitCast(f128, (@as(u128, 0x7fff000000000000) << 64) | @as(u128, 0x800030000000)), 0x1.23456789abcdefp+5, 0x7fff800000000000, 0x0);
83 try test__subtf3(@bitCast(f128, (@as(u128, 0x7fff000000000000) << 64) | @as(u128, 0x800030000000)), 0x1.23456789abcdefp+5, 0x7fff800000000000, 0x0);
8484
8585 // inf - any = inf
86 test__subtf3(inf128, 0x1.23456789abcdefp+5, 0x7fff000000000000, 0x0);
86 try test__subtf3(inf128, 0x1.23456789abcdefp+5, 0x7fff000000000000, 0x0);
8787
8888 // any + any
89 test__subtf3(0x1.234567829a3bcdef5678ade36734p+5, 0x1.ee9d7c52354a6936ab8d7654321fp-1, 0x40041b8af1915166, 0xa44a7bca780a166c);
89 try test__subtf3(0x1.234567829a3bcdef5678ade36734p+5, 0x1.ee9d7c52354a6936ab8d7654321fp-1, 0x40041b8af1915166, 0xa44a7bca780a166c);
9090}
lib/std/special/compiler_rt/ashldi3_test.zig+20-20
......@@ -6,32 +6,32 @@
66const __ashldi3 = @import("shift.zig").__ashldi3;
77const testing = @import("std").testing;
88
9fn test__ashldi3(a: i64, b: i32, expected: u64) void {
9fn test__ashldi3(a: i64, b: i32, expected: u64) !void {
1010 const x = __ashldi3(a, b);
11 testing.expectEqual(@bitCast(i64, expected), x);
11 try testing.expectEqual(@bitCast(i64, expected), x);
1212}
1313
1414test "ashldi3" {
15 test__ashldi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 0, 0x123456789ABCDEF);
16 test__ashldi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 1, 0x2468ACF13579BDE);
17 test__ashldi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 2, 0x48D159E26AF37BC);
18 test__ashldi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 3, 0x91A2B3C4D5E6F78);
19 test__ashldi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 4, 0x123456789ABCDEF0);
15 try test__ashldi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 0, 0x123456789ABCDEF);
16 try test__ashldi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 1, 0x2468ACF13579BDE);
17 try test__ashldi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 2, 0x48D159E26AF37BC);
18 try test__ashldi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 3, 0x91A2B3C4D5E6F78);
19 try test__ashldi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 4, 0x123456789ABCDEF0);
2020
21 test__ashldi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 28, 0x789ABCDEF0000000);
22 test__ashldi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 29, 0xF13579BDE0000000);
23 test__ashldi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 30, 0xE26AF37BC0000000);
24 test__ashldi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 31, 0xC4D5E6F780000000);
21 try test__ashldi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 28, 0x789ABCDEF0000000);
22 try test__ashldi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 29, 0xF13579BDE0000000);
23 try test__ashldi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 30, 0xE26AF37BC0000000);
24 try test__ashldi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 31, 0xC4D5E6F780000000);
2525
26 test__ashldi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 32, 0x89ABCDEF00000000);
26 try test__ashldi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 32, 0x89ABCDEF00000000);
2727
28 test__ashldi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 33, 0x13579BDE00000000);
29 test__ashldi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 34, 0x26AF37BC00000000);
30 test__ashldi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 35, 0x4D5E6F7800000000);
31 test__ashldi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 36, 0x9ABCDEF000000000);
28 try test__ashldi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 33, 0x13579BDE00000000);
29 try test__ashldi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 34, 0x26AF37BC00000000);
30 try test__ashldi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 35, 0x4D5E6F7800000000);
31 try test__ashldi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 36, 0x9ABCDEF000000000);
3232
33 test__ashldi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 60, 0xF000000000000000);
34 test__ashldi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 61, 0xE000000000000000);
35 test__ashldi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 62, 0xC000000000000000);
36 test__ashldi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 63, 0x8000000000000000);
33 try test__ashldi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 60, 0xF000000000000000);
34 try test__ashldi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 61, 0xE000000000000000);
35 try test__ashldi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 62, 0xC000000000000000);
36 try test__ashldi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 63, 0x8000000000000000);
3737}
lib/std/special/compiler_rt/ashlti3_test.zig+38-38
......@@ -6,46 +6,46 @@
66const __ashlti3 = @import("shift.zig").__ashlti3;
77const testing = @import("std").testing;
88
9fn test__ashlti3(a: i128, b: i32, expected: i128) void {
9fn test__ashlti3(a: i128, b: i32, expected: i128) !void {
1010 const x = __ashlti3(a, b);
11 testing.expectEqual(expected, x);
11 try testing.expectEqual(expected, x);
1212}
1313
1414test "ashlti3" {
15 test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 0, @bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)));
16 test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 1, @bitCast(i128, @intCast(u128, 0xFDB97530ECA8642BFDB97530ECA8642A)));
17 test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 2, @bitCast(i128, @intCast(u128, 0xFB72EA61D950C857FB72EA61D950C854)));
18 test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 3, @bitCast(i128, @intCast(u128, 0xF6E5D4C3B2A190AFF6E5D4C3B2A190A8)));
19 test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 4, @bitCast(i128, @intCast(u128, 0xEDCBA9876543215FEDCBA98765432150)));
20 test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 28, @bitCast(i128, @intCast(u128, 0x876543215FEDCBA98765432150000000)));
21 test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 29, @bitCast(i128, @intCast(u128, 0x0ECA8642BFDB97530ECA8642A0000000)));
22 test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 30, @bitCast(i128, @intCast(u128, 0x1D950C857FB72EA61D950C8540000000)));
23 test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 31, @bitCast(i128, @intCast(u128, 0x3B2A190AFF6E5D4C3B2A190A80000000)));
24 test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 32, @bitCast(i128, @intCast(u128, 0x76543215FEDCBA987654321500000000)));
25 test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 33, @bitCast(i128, @intCast(u128, 0xECA8642BFDB97530ECA8642A00000000)));
26 test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 34, @bitCast(i128, @intCast(u128, 0xD950C857FB72EA61D950C85400000000)));
27 test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 35, @bitCast(i128, @intCast(u128, 0xB2A190AFF6E5D4C3B2A190A800000000)));
28 test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 36, @bitCast(i128, @intCast(u128, 0x6543215FEDCBA9876543215000000000)));
29 test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 60, @bitCast(i128, @intCast(u128, 0x5FEDCBA9876543215000000000000000)));
30 test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 61, @bitCast(i128, @intCast(u128, 0xBFDB97530ECA8642A000000000000000)));
31 test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 62, @bitCast(i128, @intCast(u128, 0x7FB72EA61D950C854000000000000000)));
32 test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 63, @bitCast(i128, @intCast(u128, 0xFF6E5D4C3B2A190A8000000000000000)));
33 test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 64, @bitCast(i128, @intCast(u128, 0xFEDCBA98765432150000000000000000)));
34 test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 65, @bitCast(i128, @intCast(u128, 0xFDB97530ECA8642A0000000000000000)));
35 test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 66, @bitCast(i128, @intCast(u128, 0xFB72EA61D950C8540000000000000000)));
36 test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 67, @bitCast(i128, @intCast(u128, 0xF6E5D4C3B2A190A80000000000000000)));
37 test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 68, @bitCast(i128, @intCast(u128, 0xEDCBA987654321500000000000000000)));
38 test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 92, @bitCast(i128, @intCast(u128, 0x87654321500000000000000000000000)));
39 test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 93, @bitCast(i128, @intCast(u128, 0x0ECA8642A00000000000000000000000)));
40 test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 94, @bitCast(i128, @intCast(u128, 0x1D950C85400000000000000000000000)));
41 test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 95, @bitCast(i128, @intCast(u128, 0x3B2A190A800000000000000000000000)));
42 test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 96, @bitCast(i128, @intCast(u128, 0x76543215000000000000000000000000)));
43 test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 97, @bitCast(i128, @intCast(u128, 0xECA8642A000000000000000000000000)));
44 test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 98, @bitCast(i128, @intCast(u128, 0xD950C854000000000000000000000000)));
45 test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 99, @bitCast(i128, @intCast(u128, 0xB2A190A8000000000000000000000000)));
46 test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 100, @bitCast(i128, @intCast(u128, 0x65432150000000000000000000000000)));
47 test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 124, @bitCast(i128, @intCast(u128, 0x50000000000000000000000000000000)));
48 test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 125, @bitCast(i128, @intCast(u128, 0xA0000000000000000000000000000000)));
49 test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 126, @bitCast(i128, @intCast(u128, 0x40000000000000000000000000000000)));
50 test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 127, @bitCast(i128, @intCast(u128, 0x80000000000000000000000000000000)));
15 try test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 0, @bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)));
16 try test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 1, @bitCast(i128, @intCast(u128, 0xFDB97530ECA8642BFDB97530ECA8642A)));
17 try test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 2, @bitCast(i128, @intCast(u128, 0xFB72EA61D950C857FB72EA61D950C854)));
18 try test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 3, @bitCast(i128, @intCast(u128, 0xF6E5D4C3B2A190AFF6E5D4C3B2A190A8)));
19 try test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 4, @bitCast(i128, @intCast(u128, 0xEDCBA9876543215FEDCBA98765432150)));
20 try test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 28, @bitCast(i128, @intCast(u128, 0x876543215FEDCBA98765432150000000)));
21 try test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 29, @bitCast(i128, @intCast(u128, 0x0ECA8642BFDB97530ECA8642A0000000)));
22 try test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 30, @bitCast(i128, @intCast(u128, 0x1D950C857FB72EA61D950C8540000000)));
23 try test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 31, @bitCast(i128, @intCast(u128, 0x3B2A190AFF6E5D4C3B2A190A80000000)));
24 try test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 32, @bitCast(i128, @intCast(u128, 0x76543215FEDCBA987654321500000000)));
25 try test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 33, @bitCast(i128, @intCast(u128, 0xECA8642BFDB97530ECA8642A00000000)));
26 try test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 34, @bitCast(i128, @intCast(u128, 0xD950C857FB72EA61D950C85400000000)));
27 try test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 35, @bitCast(i128, @intCast(u128, 0xB2A190AFF6E5D4C3B2A190A800000000)));
28 try test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 36, @bitCast(i128, @intCast(u128, 0x6543215FEDCBA9876543215000000000)));
29 try test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 60, @bitCast(i128, @intCast(u128, 0x5FEDCBA9876543215000000000000000)));
30 try test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 61, @bitCast(i128, @intCast(u128, 0xBFDB97530ECA8642A000000000000000)));
31 try test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 62, @bitCast(i128, @intCast(u128, 0x7FB72EA61D950C854000000000000000)));
32 try test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 63, @bitCast(i128, @intCast(u128, 0xFF6E5D4C3B2A190A8000000000000000)));
33 try test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 64, @bitCast(i128, @intCast(u128, 0xFEDCBA98765432150000000000000000)));
34 try test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 65, @bitCast(i128, @intCast(u128, 0xFDB97530ECA8642A0000000000000000)));
35 try test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 66, @bitCast(i128, @intCast(u128, 0xFB72EA61D950C8540000000000000000)));
36 try test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 67, @bitCast(i128, @intCast(u128, 0xF6E5D4C3B2A190A80000000000000000)));
37 try test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 68, @bitCast(i128, @intCast(u128, 0xEDCBA987654321500000000000000000)));
38 try test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 92, @bitCast(i128, @intCast(u128, 0x87654321500000000000000000000000)));
39 try test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 93, @bitCast(i128, @intCast(u128, 0x0ECA8642A00000000000000000000000)));
40 try test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 94, @bitCast(i128, @intCast(u128, 0x1D950C85400000000000000000000000)));
41 try test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 95, @bitCast(i128, @intCast(u128, 0x3B2A190A800000000000000000000000)));
42 try test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 96, @bitCast(i128, @intCast(u128, 0x76543215000000000000000000000000)));
43 try test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 97, @bitCast(i128, @intCast(u128, 0xECA8642A000000000000000000000000)));
44 try test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 98, @bitCast(i128, @intCast(u128, 0xD950C854000000000000000000000000)));
45 try test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 99, @bitCast(i128, @intCast(u128, 0xB2A190A8000000000000000000000000)));
46 try test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 100, @bitCast(i128, @intCast(u128, 0x65432150000000000000000000000000)));
47 try test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 124, @bitCast(i128, @intCast(u128, 0x50000000000000000000000000000000)));
48 try test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 125, @bitCast(i128, @intCast(u128, 0xA0000000000000000000000000000000)));
49 try test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 126, @bitCast(i128, @intCast(u128, 0x40000000000000000000000000000000)));
50 try test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 127, @bitCast(i128, @intCast(u128, 0x80000000000000000000000000000000)));
5151}
lib/std/special/compiler_rt/ashrdi3_test.zig+47-47
......@@ -6,55 +6,55 @@
66const __ashrdi3 = @import("shift.zig").__ashrdi3;
77const testing = @import("std").testing;
88
9fn test__ashrdi3(a: i64, b: i32, expected: u64) void {
9fn test__ashrdi3(a: i64, b: i32, expected: u64) !void {
1010 const x = __ashrdi3(a, b);
11 testing.expectEqual(@bitCast(i64, expected), x);
11 try testing.expectEqual(@bitCast(i64, expected), x);
1212}
1313
1414test "ashrdi3" {
15 test__ashrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 0, 0x123456789ABCDEF);
16 test__ashrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 1, 0x91A2B3C4D5E6F7);
17 test__ashrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 2, 0x48D159E26AF37B);
18 test__ashrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 3, 0x2468ACF13579BD);
19 test__ashrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 4, 0x123456789ABCDE);
20
21 test__ashrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 28, 0x12345678);
22 test__ashrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 29, 0x91A2B3C);
23 test__ashrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 30, 0x48D159E);
24 test__ashrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 31, 0x2468ACF);
25
26 test__ashrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 32, 0x1234567);
27
28 test__ashrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 33, 0x91A2B3);
29 test__ashrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 34, 0x48D159);
30 test__ashrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 35, 0x2468AC);
31 test__ashrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 36, 0x123456);
32
33 test__ashrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 60, 0);
34 test__ashrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 61, 0);
35 test__ashrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 62, 0);
36 test__ashrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 63, 0);
37
38 test__ashrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 0, 0xFEDCBA9876543210);
39 test__ashrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 1, 0xFF6E5D4C3B2A1908);
40 test__ashrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 2, 0xFFB72EA61D950C84);
41 test__ashrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 3, 0xFFDB97530ECA8642);
42 test__ashrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 4, 0xFFEDCBA987654321);
43
44 test__ashrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 28, 0xFFFFFFFFEDCBA987);
45 test__ashrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 29, 0xFFFFFFFFF6E5D4C3);
46 test__ashrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 30, 0xFFFFFFFFFB72EA61);
47 test__ashrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 31, 0xFFFFFFFFFDB97530);
48
49 test__ashrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 32, 0xFFFFFFFFFEDCBA98);
50
51 test__ashrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 33, 0xFFFFFFFFFF6E5D4C);
52 test__ashrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 34, 0xFFFFFFFFFFB72EA6);
53 test__ashrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 35, 0xFFFFFFFFFFDB9753);
54 test__ashrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 36, 0xFFFFFFFFFFEDCBA9);
55
56 test__ashrdi3(@bitCast(i64, @as(u64, 0xAEDCBA9876543210)), 60, 0xFFFFFFFFFFFFFFFA);
57 test__ashrdi3(@bitCast(i64, @as(u64, 0xAEDCBA9876543210)), 61, 0xFFFFFFFFFFFFFFFD);
58 test__ashrdi3(@bitCast(i64, @as(u64, 0xAEDCBA9876543210)), 62, 0xFFFFFFFFFFFFFFFE);
59 test__ashrdi3(@bitCast(i64, @as(u64, 0xAEDCBA9876543210)), 63, 0xFFFFFFFFFFFFFFFF);
15 try test__ashrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 0, 0x123456789ABCDEF);
16 try test__ashrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 1, 0x91A2B3C4D5E6F7);
17 try test__ashrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 2, 0x48D159E26AF37B);
18 try test__ashrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 3, 0x2468ACF13579BD);
19 try test__ashrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 4, 0x123456789ABCDE);
20
21 try test__ashrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 28, 0x12345678);
22 try test__ashrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 29, 0x91A2B3C);
23 try test__ashrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 30, 0x48D159E);
24 try test__ashrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 31, 0x2468ACF);
25
26 try test__ashrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 32, 0x1234567);
27
28 try test__ashrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 33, 0x91A2B3);
29 try test__ashrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 34, 0x48D159);
30 try test__ashrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 35, 0x2468AC);
31 try test__ashrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 36, 0x123456);
32
33 try test__ashrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 60, 0);
34 try test__ashrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 61, 0);
35 try test__ashrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 62, 0);
36 try test__ashrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 63, 0);
37
38 try test__ashrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 0, 0xFEDCBA9876543210);
39 try test__ashrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 1, 0xFF6E5D4C3B2A1908);
40 try test__ashrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 2, 0xFFB72EA61D950C84);
41 try test__ashrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 3, 0xFFDB97530ECA8642);
42 try test__ashrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 4, 0xFFEDCBA987654321);
43
44 try test__ashrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 28, 0xFFFFFFFFEDCBA987);
45 try test__ashrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 29, 0xFFFFFFFFF6E5D4C3);
46 try test__ashrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 30, 0xFFFFFFFFFB72EA61);
47 try test__ashrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 31, 0xFFFFFFFFFDB97530);
48
49 try test__ashrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 32, 0xFFFFFFFFFEDCBA98);
50
51 try test__ashrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 33, 0xFFFFFFFFFF6E5D4C);
52 try test__ashrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 34, 0xFFFFFFFFFFB72EA6);
53 try test__ashrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 35, 0xFFFFFFFFFFDB9753);
54 try test__ashrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 36, 0xFFFFFFFFFFEDCBA9);
55
56 try test__ashrdi3(@bitCast(i64, @as(u64, 0xAEDCBA9876543210)), 60, 0xFFFFFFFFFFFFFFFA);
57 try test__ashrdi3(@bitCast(i64, @as(u64, 0xAEDCBA9876543210)), 61, 0xFFFFFFFFFFFFFFFD);
58 try test__ashrdi3(@bitCast(i64, @as(u64, 0xAEDCBA9876543210)), 62, 0xFFFFFFFFFFFFFFFE);
59 try test__ashrdi3(@bitCast(i64, @as(u64, 0xAEDCBA9876543210)), 63, 0xFFFFFFFFFFFFFFFF);
6060}
lib/std/special/compiler_rt/ashrti3_test.zig+48-48
......@@ -6,56 +6,56 @@
66const __ashrti3 = @import("shift.zig").__ashrti3;
77const testing = @import("std").testing;
88
9fn test__ashrti3(a: i128, b: i32, expected: i128) void {
9fn test__ashrti3(a: i128, b: i32, expected: i128) !void {
1010 const x = __ashrti3(a, b);
11 testing.expectEqual(expected, x);
11 try testing.expectEqual(expected, x);
1212}
1313
1414test "ashrti3" {
15 test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 0, @bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)));
16 test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 1, @bitCast(i128, @intCast(u128, 0xFF6E5D4C3B2A190AFF6E5D4C3B2A190A)));
17 test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 2, @bitCast(i128, @intCast(u128, 0xFFB72EA61D950C857FB72EA61D950C85)));
18 test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 3, @bitCast(i128, @intCast(u128, 0xFFDB97530ECA8642BFDB97530ECA8642)));
19 test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 4, @bitCast(i128, @intCast(u128, 0xFFEDCBA9876543215FEDCBA987654321)));
20
21 test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 28, @bitCast(i128, @intCast(u128, 0xFFFFFFFFEDCBA9876543215FEDCBA987)));
22 test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 29, @bitCast(i128, @intCast(u128, 0xFFFFFFFFF6E5D4C3B2A190AFF6E5D4C3)));
23 test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 30, @bitCast(i128, @intCast(u128, 0xFFFFFFFFFB72EA61D950C857FB72EA61)));
24 test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 31, @bitCast(i128, @intCast(u128, 0xFFFFFFFFFDB97530ECA8642BFDB97530)));
25
26 test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 32, @bitCast(i128, @intCast(u128, 0xFFFFFFFFFEDCBA9876543215FEDCBA98)));
27
28 test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 33, @bitCast(i128, @intCast(u128, 0xFFFFFFFFFF6E5D4C3B2A190AFF6E5D4C)));
29 test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 34, @bitCast(i128, @intCast(u128, 0xFFFFFFFFFFB72EA61D950C857FB72EA6)));
30 test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 35, @bitCast(i128, @intCast(u128, 0xFFFFFFFFFFDB97530ECA8642BFDB9753)));
31 test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 36, @bitCast(i128, @intCast(u128, 0xFFFFFFFFFFEDCBA9876543215FEDCBA9)));
32
33 test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 60, @bitCast(i128, @intCast(u128, 0xFFFFFFFFFFFFFFFFEDCBA9876543215F)));
34 test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 61, @bitCast(i128, @intCast(u128, 0xFFFFFFFFFFFFFFFFF6E5D4C3B2A190AF)));
35 test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 62, @bitCast(i128, @intCast(u128, 0xFFFFFFFFFFFFFFFFFB72EA61D950C857)));
36 test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 63, @bitCast(i128, @intCast(u128, 0xFFFFFFFFFFFFFFFFFDB97530ECA8642B)));
37
38 test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 64, @bitCast(i128, @intCast(u128, 0xFFFFFFFFFFFFFFFFFEDCBA9876543215)));
39
40 test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 65, @bitCast(i128, @intCast(u128, 0xFFFFFFFFFFFFFFFFFF6E5D4C3B2A190A)));
41 test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 66, @bitCast(i128, @intCast(u128, 0xFFFFFFFFFFFFFFFFFFB72EA61D950C85)));
42 test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 67, @bitCast(i128, @intCast(u128, 0xFFFFFFFFFFFFFFFFFFDB97530ECA8642)));
43 test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 68, @bitCast(i128, @intCast(u128, 0xFFFFFFFFFFFFFFFFFFEDCBA987654321)));
44
45 test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 92, @bitCast(i128, @intCast(u128, 0xFFFFFFFFFFFFFFFFFFFFFFFFEDCBA987)));
46 test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 93, @bitCast(i128, @intCast(u128, 0xFFFFFFFFFFFFFFFFFFFFFFFFF6E5D4C3)));
47 test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 94, @bitCast(i128, @intCast(u128, 0xFFFFFFFFFFFFFFFFFFFFFFFFFB72EA61)));
48 test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 95, @bitCast(i128, @intCast(u128, 0xFFFFFFFFFFFFFFFFFFFFFFFFFDB97530)));
49
50 test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 96, @bitCast(i128, @intCast(u128, 0xFFFFFFFFFFFFFFFFFFFFFFFFFEDCBA98)));
51
52 test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 97, @bitCast(i128, @intCast(u128, 0xFFFFFFFFFFFFFFFFFFFFFFFFFF6E5D4C)));
53 test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 98, @bitCast(i128, @intCast(u128, 0xFFFFFFFFFFFFFFFFFFFFFFFFFFB72EA6)));
54 test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 99, @bitCast(i128, @intCast(u128, 0xFFFFFFFFFFFFFFFFFFFFFFFFFFDB9753)));
55 test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 100, @bitCast(i128, @intCast(u128, 0xFFFFFFFFFFFFFFFFFFFFFFFFFFEDCBA9)));
56
57 test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 124, @bitCast(i128, @intCast(u128, 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)));
58 test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 125, @bitCast(i128, @intCast(u128, 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)));
59 test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 126, @bitCast(i128, @intCast(u128, 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)));
60 test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 127, @bitCast(i128, @intCast(u128, 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)));
15 try test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 0, @bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)));
16 try test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 1, @bitCast(i128, @intCast(u128, 0xFF6E5D4C3B2A190AFF6E5D4C3B2A190A)));
17 try test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 2, @bitCast(i128, @intCast(u128, 0xFFB72EA61D950C857FB72EA61D950C85)));
18 try test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 3, @bitCast(i128, @intCast(u128, 0xFFDB97530ECA8642BFDB97530ECA8642)));
19 try test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 4, @bitCast(i128, @intCast(u128, 0xFFEDCBA9876543215FEDCBA987654321)));
20
21 try test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 28, @bitCast(i128, @intCast(u128, 0xFFFFFFFFEDCBA9876543215FEDCBA987)));
22 try test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 29, @bitCast(i128, @intCast(u128, 0xFFFFFFFFF6E5D4C3B2A190AFF6E5D4C3)));
23 try test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 30, @bitCast(i128, @intCast(u128, 0xFFFFFFFFFB72EA61D950C857FB72EA61)));
24 try test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 31, @bitCast(i128, @intCast(u128, 0xFFFFFFFFFDB97530ECA8642BFDB97530)));
25
26 try test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 32, @bitCast(i128, @intCast(u128, 0xFFFFFFFFFEDCBA9876543215FEDCBA98)));
27
28 try test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 33, @bitCast(i128, @intCast(u128, 0xFFFFFFFFFF6E5D4C3B2A190AFF6E5D4C)));
29 try test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 34, @bitCast(i128, @intCast(u128, 0xFFFFFFFFFFB72EA61D950C857FB72EA6)));
30 try test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 35, @bitCast(i128, @intCast(u128, 0xFFFFFFFFFFDB97530ECA8642BFDB9753)));
31 try test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 36, @bitCast(i128, @intCast(u128, 0xFFFFFFFFFFEDCBA9876543215FEDCBA9)));
32
33 try test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 60, @bitCast(i128, @intCast(u128, 0xFFFFFFFFFFFFFFFFEDCBA9876543215F)));
34 try test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 61, @bitCast(i128, @intCast(u128, 0xFFFFFFFFFFFFFFFFF6E5D4C3B2A190AF)));
35 try test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 62, @bitCast(i128, @intCast(u128, 0xFFFFFFFFFFFFFFFFFB72EA61D950C857)));
36 try test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 63, @bitCast(i128, @intCast(u128, 0xFFFFFFFFFFFFFFFFFDB97530ECA8642B)));
37
38 try test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 64, @bitCast(i128, @intCast(u128, 0xFFFFFFFFFFFFFFFFFEDCBA9876543215)));
39
40 try test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 65, @bitCast(i128, @intCast(u128, 0xFFFFFFFFFFFFFFFFFF6E5D4C3B2A190A)));
41 try test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 66, @bitCast(i128, @intCast(u128, 0xFFFFFFFFFFFFFFFFFFB72EA61D950C85)));
42 try test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 67, @bitCast(i128, @intCast(u128, 0xFFFFFFFFFFFFFFFFFFDB97530ECA8642)));
43 try test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 68, @bitCast(i128, @intCast(u128, 0xFFFFFFFFFFFFFFFFFFEDCBA987654321)));
44
45 try test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 92, @bitCast(i128, @intCast(u128, 0xFFFFFFFFFFFFFFFFFFFFFFFFEDCBA987)));
46 try test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 93, @bitCast(i128, @intCast(u128, 0xFFFFFFFFFFFFFFFFFFFFFFFFF6E5D4C3)));
47 try test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 94, @bitCast(i128, @intCast(u128, 0xFFFFFFFFFFFFFFFFFFFFFFFFFB72EA61)));
48 try test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 95, @bitCast(i128, @intCast(u128, 0xFFFFFFFFFFFFFFFFFFFFFFFFFDB97530)));
49
50 try test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 96, @bitCast(i128, @intCast(u128, 0xFFFFFFFFFFFFFFFFFFFFFFFFFEDCBA98)));
51
52 try test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 97, @bitCast(i128, @intCast(u128, 0xFFFFFFFFFFFFFFFFFFFFFFFFFF6E5D4C)));
53 try test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 98, @bitCast(i128, @intCast(u128, 0xFFFFFFFFFFFFFFFFFFFFFFFFFFB72EA6)));
54 try test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 99, @bitCast(i128, @intCast(u128, 0xFFFFFFFFFFFFFFFFFFFFFFFFFFDB9753)));
55 try test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 100, @bitCast(i128, @intCast(u128, 0xFFFFFFFFFFFFFFFFFFFFFFFFFFEDCBA9)));
56
57 try test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 124, @bitCast(i128, @intCast(u128, 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)));
58 try test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 125, @bitCast(i128, @intCast(u128, 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)));
59 try test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 126, @bitCast(i128, @intCast(u128, 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)));
60 try test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 127, @bitCast(i128, @intCast(u128, 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)));
6161}
lib/std/special/compiler_rt/clzsi2_test.zig+281-281
......@@ -6,294 +6,294 @@
66const clzsi2 = @import("clzsi2.zig");
77const testing = @import("std").testing;
88
9fn test__clzsi2(a: u32, expected: i32) void {
9fn test__clzsi2(a: u32, expected: i32) !void {
1010 // XXX At high optimization levels this test may be horribly miscompiled if
1111 // one of the naked implementations is selected.
1212 var nakedClzsi2 = clzsi2.__clzsi2;
1313 var actualClzsi2 = @ptrCast(fn (a: i32) callconv(.C) i32, nakedClzsi2);
1414 var x = @bitCast(i32, a);
1515 var result = actualClzsi2(x);
16 testing.expectEqual(expected, result);
16 try testing.expectEqual(expected, result);
1717}
1818
1919test "clzsi2" {
20 test__clzsi2(0x00800000, 8);
21 test__clzsi2(0x01000000, 7);
22 test__clzsi2(0x02000000, 6);
23 test__clzsi2(0x03000000, 6);
24 test__clzsi2(0x04000000, 5);
25 test__clzsi2(0x05000000, 5);
26 test__clzsi2(0x06000000, 5);
27 test__clzsi2(0x07000000, 5);
28 test__clzsi2(0x08000000, 4);
29 test__clzsi2(0x09000000, 4);
30 test__clzsi2(0x0A000000, 4);
31 test__clzsi2(0x0B000000, 4);
32 test__clzsi2(0x0C000000, 4);
33 test__clzsi2(0x0D000000, 4);
34 test__clzsi2(0x0E000000, 4);
35 test__clzsi2(0x0F000000, 4);
36 test__clzsi2(0x10000000, 3);
37 test__clzsi2(0x11000000, 3);
38 test__clzsi2(0x12000000, 3);
39 test__clzsi2(0x13000000, 3);
40 test__clzsi2(0x14000000, 3);
41 test__clzsi2(0x15000000, 3);
42 test__clzsi2(0x16000000, 3);
43 test__clzsi2(0x17000000, 3);
44 test__clzsi2(0x18000000, 3);
45 test__clzsi2(0x19000000, 3);
46 test__clzsi2(0x1A000000, 3);
47 test__clzsi2(0x1B000000, 3);
48 test__clzsi2(0x1C000000, 3);
49 test__clzsi2(0x1D000000, 3);
50 test__clzsi2(0x1E000000, 3);
51 test__clzsi2(0x1F000000, 3);
52 test__clzsi2(0x20000000, 2);
53 test__clzsi2(0x21000000, 2);
54 test__clzsi2(0x22000000, 2);
55 test__clzsi2(0x23000000, 2);
56 test__clzsi2(0x24000000, 2);
57 test__clzsi2(0x25000000, 2);
58 test__clzsi2(0x26000000, 2);
59 test__clzsi2(0x27000000, 2);
60 test__clzsi2(0x28000000, 2);
61 test__clzsi2(0x29000000, 2);
62 test__clzsi2(0x2A000000, 2);
63 test__clzsi2(0x2B000000, 2);
64 test__clzsi2(0x2C000000, 2);
65 test__clzsi2(0x2D000000, 2);
66 test__clzsi2(0x2E000000, 2);
67 test__clzsi2(0x2F000000, 2);
68 test__clzsi2(0x30000000, 2);
69 test__clzsi2(0x31000000, 2);
70 test__clzsi2(0x32000000, 2);
71 test__clzsi2(0x33000000, 2);
72 test__clzsi2(0x34000000, 2);
73 test__clzsi2(0x35000000, 2);
74 test__clzsi2(0x36000000, 2);
75 test__clzsi2(0x37000000, 2);
76 test__clzsi2(0x38000000, 2);
77 test__clzsi2(0x39000000, 2);
78 test__clzsi2(0x3A000000, 2);
79 test__clzsi2(0x3B000000, 2);
80 test__clzsi2(0x3C000000, 2);
81 test__clzsi2(0x3D000000, 2);
82 test__clzsi2(0x3E000000, 2);
83 test__clzsi2(0x3F000000, 2);
84 test__clzsi2(0x40000000, 1);
85 test__clzsi2(0x41000000, 1);
86 test__clzsi2(0x42000000, 1);
87 test__clzsi2(0x43000000, 1);
88 test__clzsi2(0x44000000, 1);
89 test__clzsi2(0x45000000, 1);
90 test__clzsi2(0x46000000, 1);
91 test__clzsi2(0x47000000, 1);
92 test__clzsi2(0x48000000, 1);
93 test__clzsi2(0x49000000, 1);
94 test__clzsi2(0x4A000000, 1);
95 test__clzsi2(0x4B000000, 1);
96 test__clzsi2(0x4C000000, 1);
97 test__clzsi2(0x4D000000, 1);
98 test__clzsi2(0x4E000000, 1);
99 test__clzsi2(0x4F000000, 1);
100 test__clzsi2(0x50000000, 1);
101 test__clzsi2(0x51000000, 1);
102 test__clzsi2(0x52000000, 1);
103 test__clzsi2(0x53000000, 1);
104 test__clzsi2(0x54000000, 1);
105 test__clzsi2(0x55000000, 1);
106 test__clzsi2(0x56000000, 1);
107 test__clzsi2(0x57000000, 1);
108 test__clzsi2(0x58000000, 1);
109 test__clzsi2(0x59000000, 1);
110 test__clzsi2(0x5A000000, 1);
111 test__clzsi2(0x5B000000, 1);
112 test__clzsi2(0x5C000000, 1);
113 test__clzsi2(0x5D000000, 1);
114 test__clzsi2(0x5E000000, 1);
115 test__clzsi2(0x5F000000, 1);
116 test__clzsi2(0x60000000, 1);
117 test__clzsi2(0x61000000, 1);
118 test__clzsi2(0x62000000, 1);
119 test__clzsi2(0x63000000, 1);
120 test__clzsi2(0x64000000, 1);
121 test__clzsi2(0x65000000, 1);
122 test__clzsi2(0x66000000, 1);
123 test__clzsi2(0x67000000, 1);
124 test__clzsi2(0x68000000, 1);
125 test__clzsi2(0x69000000, 1);
126 test__clzsi2(0x6A000000, 1);
127 test__clzsi2(0x6B000000, 1);
128 test__clzsi2(0x6C000000, 1);
129 test__clzsi2(0x6D000000, 1);
130 test__clzsi2(0x6E000000, 1);
131 test__clzsi2(0x6F000000, 1);
132 test__clzsi2(0x70000000, 1);
133 test__clzsi2(0x71000000, 1);
134 test__clzsi2(0x72000000, 1);
135 test__clzsi2(0x73000000, 1);
136 test__clzsi2(0x74000000, 1);
137 test__clzsi2(0x75000000, 1);
138 test__clzsi2(0x76000000, 1);
139 test__clzsi2(0x77000000, 1);
140 test__clzsi2(0x78000000, 1);
141 test__clzsi2(0x79000000, 1);
142 test__clzsi2(0x7A000000, 1);
143 test__clzsi2(0x7B000000, 1);
144 test__clzsi2(0x7C000000, 1);
145 test__clzsi2(0x7D000000, 1);
146 test__clzsi2(0x7E000000, 1);
147 test__clzsi2(0x7F000000, 1);
148 test__clzsi2(0x80000000, 0);
149 test__clzsi2(0x81000000, 0);
150 test__clzsi2(0x82000000, 0);
151 test__clzsi2(0x83000000, 0);
152 test__clzsi2(0x84000000, 0);
153 test__clzsi2(0x85000000, 0);
154 test__clzsi2(0x86000000, 0);
155 test__clzsi2(0x87000000, 0);
156 test__clzsi2(0x88000000, 0);
157 test__clzsi2(0x89000000, 0);
158 test__clzsi2(0x8A000000, 0);
159 test__clzsi2(0x8B000000, 0);
160 test__clzsi2(0x8C000000, 0);
161 test__clzsi2(0x8D000000, 0);
162 test__clzsi2(0x8E000000, 0);
163 test__clzsi2(0x8F000000, 0);
164 test__clzsi2(0x90000000, 0);
165 test__clzsi2(0x91000000, 0);
166 test__clzsi2(0x92000000, 0);
167 test__clzsi2(0x93000000, 0);
168 test__clzsi2(0x94000000, 0);
169 test__clzsi2(0x95000000, 0);
170 test__clzsi2(0x96000000, 0);
171 test__clzsi2(0x97000000, 0);
172 test__clzsi2(0x98000000, 0);
173 test__clzsi2(0x99000000, 0);
174 test__clzsi2(0x9A000000, 0);
175 test__clzsi2(0x9B000000, 0);
176 test__clzsi2(0x9C000000, 0);
177 test__clzsi2(0x9D000000, 0);
178 test__clzsi2(0x9E000000, 0);
179 test__clzsi2(0x9F000000, 0);
180 test__clzsi2(0xA0000000, 0);
181 test__clzsi2(0xA1000000, 0);
182 test__clzsi2(0xA2000000, 0);
183 test__clzsi2(0xA3000000, 0);
184 test__clzsi2(0xA4000000, 0);
185 test__clzsi2(0xA5000000, 0);
186 test__clzsi2(0xA6000000, 0);
187 test__clzsi2(0xA7000000, 0);
188 test__clzsi2(0xA8000000, 0);
189 test__clzsi2(0xA9000000, 0);
190 test__clzsi2(0xAA000000, 0);
191 test__clzsi2(0xAB000000, 0);
192 test__clzsi2(0xAC000000, 0);
193 test__clzsi2(0xAD000000, 0);
194 test__clzsi2(0xAE000000, 0);
195 test__clzsi2(0xAF000000, 0);
196 test__clzsi2(0xB0000000, 0);
197 test__clzsi2(0xB1000000, 0);
198 test__clzsi2(0xB2000000, 0);
199 test__clzsi2(0xB3000000, 0);
200 test__clzsi2(0xB4000000, 0);
201 test__clzsi2(0xB5000000, 0);
202 test__clzsi2(0xB6000000, 0);
203 test__clzsi2(0xB7000000, 0);
204 test__clzsi2(0xB8000000, 0);
205 test__clzsi2(0xB9000000, 0);
206 test__clzsi2(0xBA000000, 0);
207 test__clzsi2(0xBB000000, 0);
208 test__clzsi2(0xBC000000, 0);
209 test__clzsi2(0xBD000000, 0);
210 test__clzsi2(0xBE000000, 0);
211 test__clzsi2(0xBF000000, 0);
212 test__clzsi2(0xC0000000, 0);
213 test__clzsi2(0xC1000000, 0);
214 test__clzsi2(0xC2000000, 0);
215 test__clzsi2(0xC3000000, 0);
216 test__clzsi2(0xC4000000, 0);
217 test__clzsi2(0xC5000000, 0);
218 test__clzsi2(0xC6000000, 0);
219 test__clzsi2(0xC7000000, 0);
220 test__clzsi2(0xC8000000, 0);
221 test__clzsi2(0xC9000000, 0);
222 test__clzsi2(0xCA000000, 0);
223 test__clzsi2(0xCB000000, 0);
224 test__clzsi2(0xCC000000, 0);
225 test__clzsi2(0xCD000000, 0);
226 test__clzsi2(0xCE000000, 0);
227 test__clzsi2(0xCF000000, 0);
228 test__clzsi2(0xD0000000, 0);
229 test__clzsi2(0xD1000000, 0);
230 test__clzsi2(0xD2000000, 0);
231 test__clzsi2(0xD3000000, 0);
232 test__clzsi2(0xD4000000, 0);
233 test__clzsi2(0xD5000000, 0);
234 test__clzsi2(0xD6000000, 0);
235 test__clzsi2(0xD7000000, 0);
236 test__clzsi2(0xD8000000, 0);
237 test__clzsi2(0xD9000000, 0);
238 test__clzsi2(0xDA000000, 0);
239 test__clzsi2(0xDB000000, 0);
240 test__clzsi2(0xDC000000, 0);
241 test__clzsi2(0xDD000000, 0);
242 test__clzsi2(0xDE000000, 0);
243 test__clzsi2(0xDF000000, 0);
244 test__clzsi2(0xE0000000, 0);
245 test__clzsi2(0xE1000000, 0);
246 test__clzsi2(0xE2000000, 0);
247 test__clzsi2(0xE3000000, 0);
248 test__clzsi2(0xE4000000, 0);
249 test__clzsi2(0xE5000000, 0);
250 test__clzsi2(0xE6000000, 0);
251 test__clzsi2(0xE7000000, 0);
252 test__clzsi2(0xE8000000, 0);
253 test__clzsi2(0xE9000000, 0);
254 test__clzsi2(0xEA000000, 0);
255 test__clzsi2(0xEB000000, 0);
256 test__clzsi2(0xEC000000, 0);
257 test__clzsi2(0xED000000, 0);
258 test__clzsi2(0xEE000000, 0);
259 test__clzsi2(0xEF000000, 0);
260 test__clzsi2(0xF0000000, 0);
261 test__clzsi2(0xF1000000, 0);
262 test__clzsi2(0xF2000000, 0);
263 test__clzsi2(0xF3000000, 0);
264 test__clzsi2(0xF4000000, 0);
265 test__clzsi2(0xF5000000, 0);
266 test__clzsi2(0xF6000000, 0);
267 test__clzsi2(0xF7000000, 0);
268 test__clzsi2(0xF8000000, 0);
269 test__clzsi2(0xF9000000, 0);
270 test__clzsi2(0xFA000000, 0);
271 test__clzsi2(0xFB000000, 0);
272 test__clzsi2(0xFC000000, 0);
273 test__clzsi2(0xFD000000, 0);
274 test__clzsi2(0xFE000000, 0);
275 test__clzsi2(0xFF000000, 0);
276 test__clzsi2(0x00000001, 31);
277 test__clzsi2(0x00000002, 30);
278 test__clzsi2(0x00000004, 29);
279 test__clzsi2(0x00000008, 28);
280 test__clzsi2(0x00000010, 27);
281 test__clzsi2(0x00000020, 26);
282 test__clzsi2(0x00000040, 25);
283 test__clzsi2(0x00000080, 24);
284 test__clzsi2(0x00000100, 23);
285 test__clzsi2(0x00000200, 22);
286 test__clzsi2(0x00000400, 21);
287 test__clzsi2(0x00000800, 20);
288 test__clzsi2(0x00001000, 19);
289 test__clzsi2(0x00002000, 18);
290 test__clzsi2(0x00004000, 17);
291 test__clzsi2(0x00008000, 16);
292 test__clzsi2(0x00010000, 15);
293 test__clzsi2(0x00020000, 14);
294 test__clzsi2(0x00040000, 13);
295 test__clzsi2(0x00080000, 12);
296 test__clzsi2(0x00100000, 11);
297 test__clzsi2(0x00200000, 10);
298 test__clzsi2(0x00400000, 9);
20 try test__clzsi2(0x00800000, 8);
21 try test__clzsi2(0x01000000, 7);
22 try test__clzsi2(0x02000000, 6);
23 try test__clzsi2(0x03000000, 6);
24 try test__clzsi2(0x04000000, 5);
25 try test__clzsi2(0x05000000, 5);
26 try test__clzsi2(0x06000000, 5);
27 try test__clzsi2(0x07000000, 5);
28 try test__clzsi2(0x08000000, 4);
29 try test__clzsi2(0x09000000, 4);
30 try test__clzsi2(0x0A000000, 4);
31 try test__clzsi2(0x0B000000, 4);
32 try test__clzsi2(0x0C000000, 4);
33 try test__clzsi2(0x0D000000, 4);
34 try test__clzsi2(0x0E000000, 4);
35 try test__clzsi2(0x0F000000, 4);
36 try test__clzsi2(0x10000000, 3);
37 try test__clzsi2(0x11000000, 3);
38 try test__clzsi2(0x12000000, 3);
39 try test__clzsi2(0x13000000, 3);
40 try test__clzsi2(0x14000000, 3);
41 try test__clzsi2(0x15000000, 3);
42 try test__clzsi2(0x16000000, 3);
43 try test__clzsi2(0x17000000, 3);
44 try test__clzsi2(0x18000000, 3);
45 try test__clzsi2(0x19000000, 3);
46 try test__clzsi2(0x1A000000, 3);
47 try test__clzsi2(0x1B000000, 3);
48 try test__clzsi2(0x1C000000, 3);
49 try test__clzsi2(0x1D000000, 3);
50 try test__clzsi2(0x1E000000, 3);
51 try test__clzsi2(0x1F000000, 3);
52 try test__clzsi2(0x20000000, 2);
53 try test__clzsi2(0x21000000, 2);
54 try test__clzsi2(0x22000000, 2);
55 try test__clzsi2(0x23000000, 2);
56 try test__clzsi2(0x24000000, 2);
57 try test__clzsi2(0x25000000, 2);
58 try test__clzsi2(0x26000000, 2);
59 try test__clzsi2(0x27000000, 2);
60 try test__clzsi2(0x28000000, 2);
61 try test__clzsi2(0x29000000, 2);
62 try test__clzsi2(0x2A000000, 2);
63 try test__clzsi2(0x2B000000, 2);
64 try test__clzsi2(0x2C000000, 2);
65 try test__clzsi2(0x2D000000, 2);
66 try test__clzsi2(0x2E000000, 2);
67 try test__clzsi2(0x2F000000, 2);
68 try test__clzsi2(0x30000000, 2);
69 try test__clzsi2(0x31000000, 2);
70 try test__clzsi2(0x32000000, 2);
71 try test__clzsi2(0x33000000, 2);
72 try test__clzsi2(0x34000000, 2);
73 try test__clzsi2(0x35000000, 2);
74 try test__clzsi2(0x36000000, 2);
75 try test__clzsi2(0x37000000, 2);
76 try test__clzsi2(0x38000000, 2);
77 try test__clzsi2(0x39000000, 2);
78 try test__clzsi2(0x3A000000, 2);
79 try test__clzsi2(0x3B000000, 2);
80 try test__clzsi2(0x3C000000, 2);
81 try test__clzsi2(0x3D000000, 2);
82 try test__clzsi2(0x3E000000, 2);
83 try test__clzsi2(0x3F000000, 2);
84 try test__clzsi2(0x40000000, 1);
85 try test__clzsi2(0x41000000, 1);
86 try test__clzsi2(0x42000000, 1);
87 try test__clzsi2(0x43000000, 1);
88 try test__clzsi2(0x44000000, 1);
89 try test__clzsi2(0x45000000, 1);
90 try test__clzsi2(0x46000000, 1);
91 try test__clzsi2(0x47000000, 1);
92 try test__clzsi2(0x48000000, 1);
93 try test__clzsi2(0x49000000, 1);
94 try test__clzsi2(0x4A000000, 1);
95 try test__clzsi2(0x4B000000, 1);
96 try test__clzsi2(0x4C000000, 1);
97 try test__clzsi2(0x4D000000, 1);
98 try test__clzsi2(0x4E000000, 1);
99 try test__clzsi2(0x4F000000, 1);
100 try test__clzsi2(0x50000000, 1);
101 try test__clzsi2(0x51000000, 1);
102 try test__clzsi2(0x52000000, 1);
103 try test__clzsi2(0x53000000, 1);
104 try test__clzsi2(0x54000000, 1);
105 try test__clzsi2(0x55000000, 1);
106 try test__clzsi2(0x56000000, 1);
107 try test__clzsi2(0x57000000, 1);
108 try test__clzsi2(0x58000000, 1);
109 try test__clzsi2(0x59000000, 1);
110 try test__clzsi2(0x5A000000, 1);
111 try test__clzsi2(0x5B000000, 1);
112 try test__clzsi2(0x5C000000, 1);
113 try test__clzsi2(0x5D000000, 1);
114 try test__clzsi2(0x5E000000, 1);
115 try test__clzsi2(0x5F000000, 1);
116 try test__clzsi2(0x60000000, 1);
117 try test__clzsi2(0x61000000, 1);
118 try test__clzsi2(0x62000000, 1);
119 try test__clzsi2(0x63000000, 1);
120 try test__clzsi2(0x64000000, 1);
121 try test__clzsi2(0x65000000, 1);
122 try test__clzsi2(0x66000000, 1);
123 try test__clzsi2(0x67000000, 1);
124 try test__clzsi2(0x68000000, 1);
125 try test__clzsi2(0x69000000, 1);
126 try test__clzsi2(0x6A000000, 1);
127 try test__clzsi2(0x6B000000, 1);
128 try test__clzsi2(0x6C000000, 1);
129 try test__clzsi2(0x6D000000, 1);
130 try test__clzsi2(0x6E000000, 1);
131 try test__clzsi2(0x6F000000, 1);
132 try test__clzsi2(0x70000000, 1);
133 try test__clzsi2(0x71000000, 1);
134 try test__clzsi2(0x72000000, 1);
135 try test__clzsi2(0x73000000, 1);
136 try test__clzsi2(0x74000000, 1);
137 try test__clzsi2(0x75000000, 1);
138 try test__clzsi2(0x76000000, 1);
139 try test__clzsi2(0x77000000, 1);
140 try test__clzsi2(0x78000000, 1);
141 try test__clzsi2(0x79000000, 1);
142 try test__clzsi2(0x7A000000, 1);
143 try test__clzsi2(0x7B000000, 1);
144 try test__clzsi2(0x7C000000, 1);
145 try test__clzsi2(0x7D000000, 1);
146 try test__clzsi2(0x7E000000, 1);
147 try test__clzsi2(0x7F000000, 1);
148 try test__clzsi2(0x80000000, 0);
149 try test__clzsi2(0x81000000, 0);
150 try test__clzsi2(0x82000000, 0);
151 try test__clzsi2(0x83000000, 0);
152 try test__clzsi2(0x84000000, 0);
153 try test__clzsi2(0x85000000, 0);
154 try test__clzsi2(0x86000000, 0);
155 try test__clzsi2(0x87000000, 0);
156 try test__clzsi2(0x88000000, 0);
157 try test__clzsi2(0x89000000, 0);
158 try test__clzsi2(0x8A000000, 0);
159 try test__clzsi2(0x8B000000, 0);
160 try test__clzsi2(0x8C000000, 0);
161 try test__clzsi2(0x8D000000, 0);
162 try test__clzsi2(0x8E000000, 0);
163 try test__clzsi2(0x8F000000, 0);
164 try test__clzsi2(0x90000000, 0);
165 try test__clzsi2(0x91000000, 0);
166 try test__clzsi2(0x92000000, 0);
167 try test__clzsi2(0x93000000, 0);
168 try test__clzsi2(0x94000000, 0);
169 try test__clzsi2(0x95000000, 0);
170 try test__clzsi2(0x96000000, 0);
171 try test__clzsi2(0x97000000, 0);
172 try test__clzsi2(0x98000000, 0);
173 try test__clzsi2(0x99000000, 0);
174 try test__clzsi2(0x9A000000, 0);
175 try test__clzsi2(0x9B000000, 0);
176 try test__clzsi2(0x9C000000, 0);
177 try test__clzsi2(0x9D000000, 0);
178 try test__clzsi2(0x9E000000, 0);
179 try test__clzsi2(0x9F000000, 0);
180 try test__clzsi2(0xA0000000, 0);
181 try test__clzsi2(0xA1000000, 0);
182 try test__clzsi2(0xA2000000, 0);
183 try test__clzsi2(0xA3000000, 0);
184 try test__clzsi2(0xA4000000, 0);
185 try test__clzsi2(0xA5000000, 0);
186 try test__clzsi2(0xA6000000, 0);
187 try test__clzsi2(0xA7000000, 0);
188 try test__clzsi2(0xA8000000, 0);
189 try test__clzsi2(0xA9000000, 0);
190 try test__clzsi2(0xAA000000, 0);
191 try test__clzsi2(0xAB000000, 0);
192 try test__clzsi2(0xAC000000, 0);
193 try test__clzsi2(0xAD000000, 0);
194 try test__clzsi2(0xAE000000, 0);
195 try test__clzsi2(0xAF000000, 0);
196 try test__clzsi2(0xB0000000, 0);
197 try test__clzsi2(0xB1000000, 0);
198 try test__clzsi2(0xB2000000, 0);
199 try test__clzsi2(0xB3000000, 0);
200 try test__clzsi2(0xB4000000, 0);
201 try test__clzsi2(0xB5000000, 0);
202 try test__clzsi2(0xB6000000, 0);
203 try test__clzsi2(0xB7000000, 0);
204 try test__clzsi2(0xB8000000, 0);
205 try test__clzsi2(0xB9000000, 0);
206 try test__clzsi2(0xBA000000, 0);
207 try test__clzsi2(0xBB000000, 0);
208 try test__clzsi2(0xBC000000, 0);
209 try test__clzsi2(0xBD000000, 0);
210 try test__clzsi2(0xBE000000, 0);
211 try test__clzsi2(0xBF000000, 0);
212 try test__clzsi2(0xC0000000, 0);
213 try test__clzsi2(0xC1000000, 0);
214 try test__clzsi2(0xC2000000, 0);
215 try test__clzsi2(0xC3000000, 0);
216 try test__clzsi2(0xC4000000, 0);
217 try test__clzsi2(0xC5000000, 0);
218 try test__clzsi2(0xC6000000, 0);
219 try test__clzsi2(0xC7000000, 0);
220 try test__clzsi2(0xC8000000, 0);
221 try test__clzsi2(0xC9000000, 0);
222 try test__clzsi2(0xCA000000, 0);
223 try test__clzsi2(0xCB000000, 0);
224 try test__clzsi2(0xCC000000, 0);
225 try test__clzsi2(0xCD000000, 0);
226 try test__clzsi2(0xCE000000, 0);
227 try test__clzsi2(0xCF000000, 0);
228 try test__clzsi2(0xD0000000, 0);
229 try test__clzsi2(0xD1000000, 0);
230 try test__clzsi2(0xD2000000, 0);
231 try test__clzsi2(0xD3000000, 0);
232 try test__clzsi2(0xD4000000, 0);
233 try test__clzsi2(0xD5000000, 0);
234 try test__clzsi2(0xD6000000, 0);
235 try test__clzsi2(0xD7000000, 0);
236 try test__clzsi2(0xD8000000, 0);
237 try test__clzsi2(0xD9000000, 0);
238 try test__clzsi2(0xDA000000, 0);
239 try test__clzsi2(0xDB000000, 0);
240 try test__clzsi2(0xDC000000, 0);
241 try test__clzsi2(0xDD000000, 0);
242 try test__clzsi2(0xDE000000, 0);
243 try test__clzsi2(0xDF000000, 0);
244 try test__clzsi2(0xE0000000, 0);
245 try test__clzsi2(0xE1000000, 0);
246 try test__clzsi2(0xE2000000, 0);
247 try test__clzsi2(0xE3000000, 0);
248 try test__clzsi2(0xE4000000, 0);
249 try test__clzsi2(0xE5000000, 0);
250 try test__clzsi2(0xE6000000, 0);
251 try test__clzsi2(0xE7000000, 0);
252 try test__clzsi2(0xE8000000, 0);
253 try test__clzsi2(0xE9000000, 0);
254 try test__clzsi2(0xEA000000, 0);
255 try test__clzsi2(0xEB000000, 0);
256 try test__clzsi2(0xEC000000, 0);
257 try test__clzsi2(0xED000000, 0);
258 try test__clzsi2(0xEE000000, 0);
259 try test__clzsi2(0xEF000000, 0);
260 try test__clzsi2(0xF0000000, 0);
261 try test__clzsi2(0xF1000000, 0);
262 try test__clzsi2(0xF2000000, 0);
263 try test__clzsi2(0xF3000000, 0);
264 try test__clzsi2(0xF4000000, 0);
265 try test__clzsi2(0xF5000000, 0);
266 try test__clzsi2(0xF6000000, 0);
267 try test__clzsi2(0xF7000000, 0);
268 try test__clzsi2(0xF8000000, 0);
269 try test__clzsi2(0xF9000000, 0);
270 try test__clzsi2(0xFA000000, 0);
271 try test__clzsi2(0xFB000000, 0);
272 try test__clzsi2(0xFC000000, 0);
273 try test__clzsi2(0xFD000000, 0);
274 try test__clzsi2(0xFE000000, 0);
275 try test__clzsi2(0xFF000000, 0);
276 try test__clzsi2(0x00000001, 31);
277 try test__clzsi2(0x00000002, 30);
278 try test__clzsi2(0x00000004, 29);
279 try test__clzsi2(0x00000008, 28);
280 try test__clzsi2(0x00000010, 27);
281 try test__clzsi2(0x00000020, 26);
282 try test__clzsi2(0x00000040, 25);
283 try test__clzsi2(0x00000080, 24);
284 try test__clzsi2(0x00000100, 23);
285 try test__clzsi2(0x00000200, 22);
286 try test__clzsi2(0x00000400, 21);
287 try test__clzsi2(0x00000800, 20);
288 try test__clzsi2(0x00001000, 19);
289 try test__clzsi2(0x00002000, 18);
290 try test__clzsi2(0x00004000, 17);
291 try test__clzsi2(0x00008000, 16);
292 try test__clzsi2(0x00010000, 15);
293 try test__clzsi2(0x00020000, 14);
294 try test__clzsi2(0x00040000, 13);
295 try test__clzsi2(0x00080000, 12);
296 try test__clzsi2(0x00100000, 11);
297 try test__clzsi2(0x00200000, 10);
298 try test__clzsi2(0x00400000, 9);
299299}
lib/std/special/compiler_rt/comparedf2_test.zig+1-1
......@@ -101,6 +101,6 @@ const test_vectors = init: {
101101
102102test "compare f64" {
103103 for (test_vectors) |vector, i| {
104 std.testing.expect(test__cmpdf2(vector));
104 try std.testing.expect(test__cmpdf2(vector));
105105 }
106106}
lib/std/special/compiler_rt/comparesf2_test.zig+1-1
......@@ -101,6 +101,6 @@ const test_vectors = init: {
101101
102102test "compare f32" {
103103 for (test_vectors) |vector, i| {
104 std.testing.expect(test__cmpsf2(vector));
104 try std.testing.expect(test__cmpsf2(vector));
105105 }
106106}
lib/std/special/compiler_rt/divdf3_test.zig+4-4
......@@ -27,13 +27,13 @@ fn compareResultD(result: f64, expected: u64) bool {
2727 return false;
2828}
2929
30fn test__divdf3(a: f64, b: f64, expected: u64) void {
30fn test__divdf3(a: f64, b: f64, expected: u64) !void {
3131 const x = __divdf3(a, b);
3232 const ret = compareResultD(x, expected);
33 testing.expect(ret == true);
33 try testing.expect(ret == true);
3434}
3535
3636test "divdf3" {
37 test__divdf3(1.0, 3.0, 0x3fd5555555555555);
38 test__divdf3(4.450147717014403e-308, 2.0, 0x10000000000000);
37 try test__divdf3(1.0, 3.0, 0x3fd5555555555555);
38 try test__divdf3(4.450147717014403e-308, 2.0, 0x10000000000000);
3939}
lib/std/special/compiler_rt/divsf3_test.zig+4-4
......@@ -27,13 +27,13 @@ fn compareResultF(result: f32, expected: u32) bool {
2727 return false;
2828}
2929
30fn test__divsf3(a: f32, b: f32, expected: u32) void {
30fn test__divsf3(a: f32, b: f32, expected: u32) !void {
3131 const x = __divsf3(a, b);
3232 const ret = compareResultF(x, expected);
33 testing.expect(ret == true);
33 try testing.expect(ret == true);
3434}
3535
3636test "divsf3" {
37 test__divsf3(1.0, 3.0, 0x3EAAAAAB);
38 test__divsf3(2.3509887e-38, 2.0, 0x00800000);
37 try test__divsf3(1.0, 3.0, 0x3EAAAAAB);
38 try test__divsf3(2.3509887e-38, 2.0, 0x00800000);
3939}
lib/std/special/compiler_rt/divtf3_test.zig+11-11
......@@ -28,24 +28,24 @@ fn compareResultLD(result: f128, expectedHi: u64, expectedLo: u64) bool {
2828 return false;
2929}
3030
31fn test__divtf3(a: f128, b: f128, expectedHi: u64, expectedLo: u64) void {
31fn test__divtf3(a: f128, b: f128, expectedHi: u64, expectedLo: u64) !void {
3232 const x = __divtf3(a, b);
3333 const ret = compareResultLD(x, expectedHi, expectedLo);
34 testing.expect(ret == true);
34 try testing.expect(ret == true);
3535}
3636
3737test "divtf3" {
3838 // qNaN / any = qNaN
39 test__divtf3(math.qnan_f128, 0x1.23456789abcdefp+5, 0x7fff800000000000, 0);
39 try test__divtf3(math.qnan_f128, 0x1.23456789abcdefp+5, 0x7fff800000000000, 0);
4040 // NaN / any = NaN
41 test__divtf3(math.nan_f128, 0x1.23456789abcdefp+5, 0x7fff800000000000, 0);
41 try test__divtf3(math.nan_f128, 0x1.23456789abcdefp+5, 0x7fff800000000000, 0);
4242 // inf / any = inf
43 test__divtf3(math.inf_f128, 0x1.23456789abcdefp+5, 0x7fff000000000000, 0);
43 try test__divtf3(math.inf_f128, 0x1.23456789abcdefp+5, 0x7fff000000000000, 0);
4444
45 test__divtf3(0x1.a23b45362464523375893ab4cdefp+5, 0x1.eedcbaba3a94546558237654321fp-1, 0x4004b0b72924d407, 0x0717e84356c6eba2);
46 test__divtf3(0x1.a2b34c56d745382f9abf2c3dfeffp-50, 0x1.ed2c3ba15935332532287654321fp-9, 0x3fd5b2af3f828c9b, 0x40e51f64cde8b1f2);
47 test__divtf3(0x1.2345f6aaaa786555f42432abcdefp+456, 0x1.edacbba9874f765463544dd3621fp+6400, 0x28c62e15dc464466, 0xb5a07586348557ac);
48 test__divtf3(0x1.2d3456f789ba6322bc665544edefp-234, 0x1.eddcdba39f3c8b7a36564354321fp-4455, 0x507b38442b539266, 0x22ce0f1d024e1252);
49 test__divtf3(0x1.2345f6b77b7a8953365433abcdefp+234, 0x1.edcba987d6bb3aa467754354321fp-4055, 0x50bf2e02f0798d36, 0x5e6fcb6b60044078);
50 test__divtf3(6.72420628622418701252535563464350521E-4932, 2.0, 0x0001000000000000, 0);
45 try test__divtf3(0x1.a23b45362464523375893ab4cdefp+5, 0x1.eedcbaba3a94546558237654321fp-1, 0x4004b0b72924d407, 0x0717e84356c6eba2);
46 try test__divtf3(0x1.a2b34c56d745382f9abf2c3dfeffp-50, 0x1.ed2c3ba15935332532287654321fp-9, 0x3fd5b2af3f828c9b, 0x40e51f64cde8b1f2);
47 try test__divtf3(0x1.2345f6aaaa786555f42432abcdefp+456, 0x1.edacbba9874f765463544dd3621fp+6400, 0x28c62e15dc464466, 0xb5a07586348557ac);
48 try test__divtf3(0x1.2d3456f789ba6322bc665544edefp-234, 0x1.eddcdba39f3c8b7a36564354321fp-4455, 0x507b38442b539266, 0x22ce0f1d024e1252);
49 try test__divtf3(0x1.2345f6b77b7a8953365433abcdefp+234, 0x1.edcba987d6bb3aa467754354321fp-4055, 0x50bf2e02f0798d36, 0x5e6fcb6b60044078);
50 try test__divtf3(6.72420628622418701252535563464350521E-4932, 2.0, 0x0001000000000000, 0);
5151}
lib/std/special/compiler_rt/divti3_test.zig+12-12
......@@ -6,21 +6,21 @@
66const __divti3 = @import("divti3.zig").__divti3;
77const testing = @import("std").testing;
88
9fn test__divti3(a: i128, b: i128, expected: i128) void {
9fn test__divti3(a: i128, b: i128, expected: i128) !void {
1010 const x = __divti3(a, b);
11 testing.expect(x == expected);
11 try testing.expect(x == expected);
1212}
1313
1414test "divti3" {
15 test__divti3(0, 1, 0);
16 test__divti3(0, -1, 0);
17 test__divti3(2, 1, 2);
18 test__divti3(2, -1, -2);
19 test__divti3(-2, 1, -2);
20 test__divti3(-2, -1, 2);
15 try test__divti3(0, 1, 0);
16 try test__divti3(0, -1, 0);
17 try test__divti3(2, 1, 2);
18 try test__divti3(2, -1, -2);
19 try test__divti3(-2, 1, -2);
20 try test__divti3(-2, -1, 2);
2121
22 test__divti3(@bitCast(i128, @as(u128, 0x8 << 124)), 1, @bitCast(i128, @as(u128, 0x8 << 124)));
23 test__divti3(@bitCast(i128, @as(u128, 0x8 << 124)), -1, @bitCast(i128, @as(u128, 0x8 << 124)));
24 test__divti3(@bitCast(i128, @as(u128, 0x8 << 124)), -2, @bitCast(i128, @as(u128, 0x4 << 124)));
25 test__divti3(@bitCast(i128, @as(u128, 0x8 << 124)), 2, @bitCast(i128, @as(u128, 0xc << 124)));
22 try test__divti3(@bitCast(i128, @as(u128, 0x8 << 124)), 1, @bitCast(i128, @as(u128, 0x8 << 124)));
23 try test__divti3(@bitCast(i128, @as(u128, 0x8 << 124)), -1, @bitCast(i128, @as(u128, 0x8 << 124)));
24 try test__divti3(@bitCast(i128, @as(u128, 0x8 << 124)), -2, @bitCast(i128, @as(u128, 0x4 << 124)));
25 try test__divti3(@bitCast(i128, @as(u128, 0x8 << 124)), 2, @bitCast(i128, @as(u128, 0xc << 124)));
2626}
lib/std/special/compiler_rt/emutls.zig+11-11
......@@ -339,12 +339,12 @@ test "simple_allocator" {
339339
340340test "__emutls_get_address zeroed" {
341341 var ctl = emutls_control.init(usize, null);
342 expect(ctl.object.index == 0);
342 try expect(ctl.object.index == 0);
343343
344344 // retrieve a variable from ctl
345345 var x = @ptrCast(*usize, @alignCast(@alignOf(usize), __emutls_get_address(&ctl)));
346 expect(ctl.object.index != 0); // index has been allocated for this ctl
347 expect(x.* == 0); // storage has been zeroed
346 try expect(ctl.object.index != 0); // index has been allocated for this ctl
347 try expect(x.* == 0); // storage has been zeroed
348348
349349 // modify the storage
350350 x.* = 1234;
......@@ -352,26 +352,26 @@ test "__emutls_get_address zeroed" {
352352 // retrieve a variable from ctl (same ctl)
353353 var y = @ptrCast(*usize, @alignCast(@alignOf(usize), __emutls_get_address(&ctl)));
354354
355 expect(y.* == 1234); // same content that x.*
356 expect(x == y); // same pointer
355 try expect(y.* == 1234); // same content that x.*
356 try expect(x == y); // same pointer
357357}
358358
359359test "__emutls_get_address with default_value" {
360360 var value: usize = 5678; // default value
361361 var ctl = emutls_control.init(usize, &value);
362 expect(ctl.object.index == 0);
362 try expect(ctl.object.index == 0);
363363
364364 var x: *usize = @ptrCast(*usize, @alignCast(@alignOf(usize), __emutls_get_address(&ctl)));
365 expect(ctl.object.index != 0);
366 expect(x.* == 5678); // storage initialized with default value
365 try expect(ctl.object.index != 0);
366 try expect(x.* == 5678); // storage initialized with default value
367367
368368 // modify the storage
369369 x.* = 9012;
370370
371 expect(value == 5678); // the default value didn't change
371 try expect(value == 5678); // the default value didn't change
372372
373373 var y = @ptrCast(*usize, @alignCast(@alignOf(usize), __emutls_get_address(&ctl)));
374 expect(y.* == 9012); // the modified storage persists
374 try expect(y.* == 9012); // the modified storage persists
375375}
376376
377377test "test default_value with differents sizes" {
......@@ -380,7 +380,7 @@ test "test default_value with differents sizes" {
380380 var def: T = value;
381381 var ctl = emutls_control.init(T, &def);
382382 var x = ctl.get_typed_pointer(T);
383 expect(x.* == value);
383 try expect(x.* == value);
384384 }
385385 }._testType;
386386
lib/std/special/compiler_rt/extendXfYf2_test.zig+55-55
......@@ -9,7 +9,7 @@ const __extendhftf2 = @import("extendXfYf2.zig").__extendhftf2;
99const __extendsftf2 = @import("extendXfYf2.zig").__extendsftf2;
1010const __extenddftf2 = @import("extendXfYf2.zig").__extenddftf2;
1111
12fn test__extenddftf2(a: f64, expectedHi: u64, expectedLo: u64) void {
12fn test__extenddftf2(a: f64, expectedHi: u64, expectedLo: u64) !void {
1313 const x = __extenddftf2(a);
1414
1515 const rep = @bitCast(u128, x);
......@@ -31,7 +31,7 @@ fn test__extenddftf2(a: f64, expectedHi: u64, expectedLo: u64) void {
3131 @panic("__extenddftf2 test failure");
3232}
3333
34fn test__extendhfsf2(a: u16, expected: u32) void {
34fn test__extendhfsf2(a: u16, expected: u32) !void {
3535 const x = __extendhfsf2(a);
3636 const rep = @bitCast(u32, x);
3737
......@@ -44,10 +44,10 @@ fn test__extendhfsf2(a: u16, expected: u32) void {
4444 }
4545 }
4646
47 @panic("__extendhfsf2 test failure");
47 return error.TestFailure;
4848}
4949
50fn test__extendsftf2(a: f32, expectedHi: u64, expectedLo: u64) void {
50fn test__extendsftf2(a: f32, expectedHi: u64, expectedLo: u64) !void {
5151 const x = __extendsftf2(a);
5252
5353 const rep = @bitCast(u128, x);
......@@ -66,77 +66,77 @@ fn test__extendsftf2(a: f32, expectedHi: u64, expectedLo: u64) void {
6666 }
6767 }
6868
69 @panic("__extendsftf2 test failure");
69 return error.TestFailure;
7070}
7171
7272test "extenddftf2" {
7373 // qNaN
74 test__extenddftf2(makeQNaN64(), 0x7fff800000000000, 0x0);
74 try test__extenddftf2(makeQNaN64(), 0x7fff800000000000, 0x0);
7575
7676 // NaN
77 test__extenddftf2(makeNaN64(0x7100000000000), 0x7fff710000000000, 0x0);
77 try test__extenddftf2(makeNaN64(0x7100000000000), 0x7fff710000000000, 0x0);
7878
7979 // inf
80 test__extenddftf2(makeInf64(), 0x7fff000000000000, 0x0);
80 try test__extenddftf2(makeInf64(), 0x7fff000000000000, 0x0);
8181
8282 // zero
83 test__extenddftf2(0.0, 0x0, 0x0);
83 try test__extenddftf2(0.0, 0x0, 0x0);
8484
85 test__extenddftf2(0x1.23456789abcdefp+5, 0x400423456789abcd, 0xf000000000000000);
85 try test__extenddftf2(0x1.23456789abcdefp+5, 0x400423456789abcd, 0xf000000000000000);
8686
87 test__extenddftf2(0x1.edcba987654321fp-9, 0x3ff6edcba9876543, 0x2000000000000000);
87 try test__extenddftf2(0x1.edcba987654321fp-9, 0x3ff6edcba9876543, 0x2000000000000000);
8888
89 test__extenddftf2(0x1.23456789abcdefp+45, 0x402c23456789abcd, 0xf000000000000000);
89 try test__extenddftf2(0x1.23456789abcdefp+45, 0x402c23456789abcd, 0xf000000000000000);
9090
91 test__extenddftf2(0x1.edcba987654321fp-45, 0x3fd2edcba9876543, 0x2000000000000000);
91 try test__extenddftf2(0x1.edcba987654321fp-45, 0x3fd2edcba9876543, 0x2000000000000000);
9292}
9393
9494test "extendhfsf2" {
95 test__extendhfsf2(0x7e00, 0x7fc00000); // qNaN
96 test__extendhfsf2(0x7f00, 0x7fe00000); // sNaN
95 try test__extendhfsf2(0x7e00, 0x7fc00000); // qNaN
96 try test__extendhfsf2(0x7f00, 0x7fe00000); // sNaN
9797 // On x86 the NaN becomes quiet because the return is pushed on the x87
9898 // stack due to ABI requirements
9999 if (builtin.arch != .i386 and builtin.os.tag == .windows)
100 test__extendhfsf2(0x7c01, 0x7f802000); // sNaN
100 try test__extendhfsf2(0x7c01, 0x7f802000); // sNaN
101101
102 test__extendhfsf2(0, 0); // 0
103 test__extendhfsf2(0x8000, 0x80000000); // -0
102 try test__extendhfsf2(0, 0); // 0
103 try test__extendhfsf2(0x8000, 0x80000000); // -0
104104
105 test__extendhfsf2(0x7c00, 0x7f800000); // inf
106 test__extendhfsf2(0xfc00, 0xff800000); // -inf
105 try test__extendhfsf2(0x7c00, 0x7f800000); // inf
106 try test__extendhfsf2(0xfc00, 0xff800000); // -inf
107107
108 test__extendhfsf2(0x0001, 0x33800000); // denormal (min), 2**-24
109 test__extendhfsf2(0x8001, 0xb3800000); // denormal (min), -2**-24
108 try test__extendhfsf2(0x0001, 0x33800000); // denormal (min), 2**-24
109 try test__extendhfsf2(0x8001, 0xb3800000); // denormal (min), -2**-24
110110
111 test__extendhfsf2(0x03ff, 0x387fc000); // denormal (max), 2**-14 - 2**-24
112 test__extendhfsf2(0x83ff, 0xb87fc000); // denormal (max), -2**-14 + 2**-24
111 try test__extendhfsf2(0x03ff, 0x387fc000); // denormal (max), 2**-14 - 2**-24
112 try test__extendhfsf2(0x83ff, 0xb87fc000); // denormal (max), -2**-14 + 2**-24
113113
114 test__extendhfsf2(0x0400, 0x38800000); // normal (min), 2**-14
115 test__extendhfsf2(0x8400, 0xb8800000); // normal (min), -2**-14
114 try test__extendhfsf2(0x0400, 0x38800000); // normal (min), 2**-14
115 try test__extendhfsf2(0x8400, 0xb8800000); // normal (min), -2**-14
116116
117 test__extendhfsf2(0x7bff, 0x477fe000); // normal (max), 65504
118 test__extendhfsf2(0xfbff, 0xc77fe000); // normal (max), -65504
117 try test__extendhfsf2(0x7bff, 0x477fe000); // normal (max), 65504
118 try test__extendhfsf2(0xfbff, 0xc77fe000); // normal (max), -65504
119119
120 test__extendhfsf2(0x3c01, 0x3f802000); // normal, 1 + 2**-10
121 test__extendhfsf2(0xbc01, 0xbf802000); // normal, -1 - 2**-10
120 try test__extendhfsf2(0x3c01, 0x3f802000); // normal, 1 + 2**-10
121 try test__extendhfsf2(0xbc01, 0xbf802000); // normal, -1 - 2**-10
122122
123 test__extendhfsf2(0x3555, 0x3eaaa000); // normal, approx. 1/3
124 test__extendhfsf2(0xb555, 0xbeaaa000); // normal, approx. -1/3
123 try test__extendhfsf2(0x3555, 0x3eaaa000); // normal, approx. 1/3
124 try test__extendhfsf2(0xb555, 0xbeaaa000); // normal, approx. -1/3
125125}
126126
127127test "extendsftf2" {
128128 // qNaN
129 test__extendsftf2(makeQNaN32(), 0x7fff800000000000, 0x0);
129 try test__extendsftf2(makeQNaN32(), 0x7fff800000000000, 0x0);
130130 // NaN
131 test__extendsftf2(makeNaN32(0x410000), 0x7fff820000000000, 0x0);
131 try test__extendsftf2(makeNaN32(0x410000), 0x7fff820000000000, 0x0);
132132 // inf
133 test__extendsftf2(makeInf32(), 0x7fff000000000000, 0x0);
133 try test__extendsftf2(makeInf32(), 0x7fff000000000000, 0x0);
134134 // zero
135 test__extendsftf2(0.0, 0x0, 0x0);
136 test__extendsftf2(0x1.23456p+5, 0x4004234560000000, 0x0);
137 test__extendsftf2(0x1.edcbap-9, 0x3ff6edcba0000000, 0x0);
138 test__extendsftf2(0x1.23456p+45, 0x402c234560000000, 0x0);
139 test__extendsftf2(0x1.edcbap-45, 0x3fd2edcba0000000, 0x0);
135 try test__extendsftf2(0.0, 0x0, 0x0);
136 try test__extendsftf2(0x1.23456p+5, 0x4004234560000000, 0x0);
137 try test__extendsftf2(0x1.edcbap-9, 0x3ff6edcba0000000, 0x0);
138 try test__extendsftf2(0x1.23456p+45, 0x402c234560000000, 0x0);
139 try test__extendsftf2(0x1.edcbap-45, 0x3fd2edcba0000000, 0x0);
140140}
141141
142142fn makeQNaN64() f64 {
......@@ -163,7 +163,7 @@ fn makeInf32() f32 {
163163 return @bitCast(f32, @as(u32, 0x7f800000));
164164}
165165
166fn test__extendhftf2(a: u16, expectedHi: u64, expectedLo: u64) void {
166fn test__extendhftf2(a: u16, expectedHi: u64, expectedLo: u64) !void {
167167 const x = __extendhftf2(a);
168168
169169 const rep = @bitCast(u128, x);
......@@ -182,29 +182,29 @@ fn test__extendhftf2(a: u16, expectedHi: u64, expectedLo: u64) void {
182182 }
183183 }
184184
185 @panic("__extendhftf2 test failure");
185 return error.TestFailure;
186186}
187187
188188test "extendhftf2" {
189189 // qNaN
190 test__extendhftf2(0x7e00, 0x7fff800000000000, 0x0);
190 try test__extendhftf2(0x7e00, 0x7fff800000000000, 0x0);
191191 // NaN
192 test__extendhftf2(0x7d00, 0x7fff400000000000, 0x0);
192 try test__extendhftf2(0x7d00, 0x7fff400000000000, 0x0);
193193 // inf
194 test__extendhftf2(0x7c00, 0x7fff000000000000, 0x0);
195 test__extendhftf2(0xfc00, 0xffff000000000000, 0x0);
194 try test__extendhftf2(0x7c00, 0x7fff000000000000, 0x0);
195 try test__extendhftf2(0xfc00, 0xffff000000000000, 0x0);
196196 // zero
197 test__extendhftf2(0x0000, 0x0000000000000000, 0x0);
198 test__extendhftf2(0x8000, 0x8000000000000000, 0x0);
197 try test__extendhftf2(0x0000, 0x0000000000000000, 0x0);
198 try test__extendhftf2(0x8000, 0x8000000000000000, 0x0);
199199 // denormal
200 test__extendhftf2(0x0010, 0x3feb000000000000, 0x0);
201 test__extendhftf2(0x0001, 0x3fe7000000000000, 0x0);
202 test__extendhftf2(0x8001, 0xbfe7000000000000, 0x0);
200 try test__extendhftf2(0x0010, 0x3feb000000000000, 0x0);
201 try test__extendhftf2(0x0001, 0x3fe7000000000000, 0x0);
202 try test__extendhftf2(0x8001, 0xbfe7000000000000, 0x0);
203203
204204 // pi
205 test__extendhftf2(0x4248, 0x4000920000000000, 0x0);
206 test__extendhftf2(0xc248, 0xc000920000000000, 0x0);
205 try test__extendhftf2(0x4248, 0x4000920000000000, 0x0);
206 try test__extendhftf2(0xc248, 0xc000920000000000, 0x0);
207207
208 test__extendhftf2(0x508c, 0x4004230000000000, 0x0);
209 test__extendhftf2(0x1bb7, 0x3ff6edc000000000, 0x0);
208 try test__extendhftf2(0x508c, 0x4004230000000000, 0x0);
209 try test__extendhftf2(0x1bb7, 0x3ff6edc000000000, 0x0);
210210}
lib/std/special/compiler_rt/fixdfdi_test.zig+42-42
......@@ -9,62 +9,62 @@ const math = std.math;
99const testing = std.testing;
1010const warn = std.debug.warn;
1111
12fn test__fixdfdi(a: f64, expected: i64) void {
12fn test__fixdfdi(a: f64, expected: i64) !void {
1313 const x = __fixdfdi(a);
1414 //warn("a={}:{x} x={}:{x} expected={}:{x}:@as(u64, {x})\n", .{a, @bitCast(u64, a), x, x, expected, expected, @bitCast(u64, expected)});
15 testing.expect(x == expected);
15 try testing.expect(x == expected);
1616}
1717
1818test "fixdfdi" {
1919 //warn("\n", .{});
20 test__fixdfdi(-math.f64_max, math.minInt(i64));
20 try test__fixdfdi(-math.f64_max, math.minInt(i64));
2121
22 test__fixdfdi(-0x1.FFFFFFFFFFFFFp+1023, math.minInt(i64));
23 test__fixdfdi(-0x1.FFFFFFFFFFFFFp+1023, -0x8000000000000000);
22 try test__fixdfdi(-0x1.FFFFFFFFFFFFFp+1023, math.minInt(i64));
23 try test__fixdfdi(-0x1.FFFFFFFFFFFFFp+1023, -0x8000000000000000);
2424
25 test__fixdfdi(-0x1.0000000000000p+127, -0x8000000000000000);
26 test__fixdfdi(-0x1.FFFFFFFFFFFFFp+126, -0x8000000000000000);
27 test__fixdfdi(-0x1.FFFFFFFFFFFFEp+126, -0x8000000000000000);
25 try test__fixdfdi(-0x1.0000000000000p+127, -0x8000000000000000);
26 try test__fixdfdi(-0x1.FFFFFFFFFFFFFp+126, -0x8000000000000000);
27 try test__fixdfdi(-0x1.FFFFFFFFFFFFEp+126, -0x8000000000000000);
2828
29 test__fixdfdi(-0x1.0000000000001p+63, -0x8000000000000000);
30 test__fixdfdi(-0x1.0000000000000p+63, -0x8000000000000000);
31 test__fixdfdi(-0x1.FFFFFFFFFFFFFp+62, -0x7FFFFFFFFFFFFC00);
32 test__fixdfdi(-0x1.FFFFFFFFFFFFEp+62, -0x7FFFFFFFFFFFF800);
29 try test__fixdfdi(-0x1.0000000000001p+63, -0x8000000000000000);
30 try test__fixdfdi(-0x1.0000000000000p+63, -0x8000000000000000);
31 try test__fixdfdi(-0x1.FFFFFFFFFFFFFp+62, -0x7FFFFFFFFFFFFC00);
32 try test__fixdfdi(-0x1.FFFFFFFFFFFFEp+62, -0x7FFFFFFFFFFFF800);
3333
34 test__fixdfdi(-0x1.FFFFFEp+62, -0x7fffff8000000000);
35 test__fixdfdi(-0x1.FFFFFCp+62, -0x7fffff0000000000);
34 try test__fixdfdi(-0x1.FFFFFEp+62, -0x7fffff8000000000);
35 try test__fixdfdi(-0x1.FFFFFCp+62, -0x7fffff0000000000);
3636
37 test__fixdfdi(-2.01, -2);
38 test__fixdfdi(-2.0, -2);
39 test__fixdfdi(-1.99, -1);
40 test__fixdfdi(-1.0, -1);
41 test__fixdfdi(-0.99, 0);
42 test__fixdfdi(-0.5, 0);
43 test__fixdfdi(-math.f64_min, 0);
44 test__fixdfdi(0.0, 0);
45 test__fixdfdi(math.f64_min, 0);
46 test__fixdfdi(0.5, 0);
47 test__fixdfdi(0.99, 0);
48 test__fixdfdi(1.0, 1);
49 test__fixdfdi(1.5, 1);
50 test__fixdfdi(1.99, 1);
51 test__fixdfdi(2.0, 2);
52 test__fixdfdi(2.01, 2);
37 try test__fixdfdi(-2.01, -2);
38 try test__fixdfdi(-2.0, -2);
39 try test__fixdfdi(-1.99, -1);
40 try test__fixdfdi(-1.0, -1);
41 try test__fixdfdi(-0.99, 0);
42 try test__fixdfdi(-0.5, 0);
43 try test__fixdfdi(-math.f64_min, 0);
44 try test__fixdfdi(0.0, 0);
45 try test__fixdfdi(math.f64_min, 0);
46 try test__fixdfdi(0.5, 0);
47 try test__fixdfdi(0.99, 0);
48 try test__fixdfdi(1.0, 1);
49 try test__fixdfdi(1.5, 1);
50 try test__fixdfdi(1.99, 1);
51 try test__fixdfdi(2.0, 2);
52 try test__fixdfdi(2.01, 2);
5353
54 test__fixdfdi(0x1.FFFFFCp+62, 0x7FFFFF0000000000);
55 test__fixdfdi(0x1.FFFFFEp+62, 0x7FFFFF8000000000);
54 try test__fixdfdi(0x1.FFFFFCp+62, 0x7FFFFF0000000000);
55 try test__fixdfdi(0x1.FFFFFEp+62, 0x7FFFFF8000000000);
5656
57 test__fixdfdi(0x1.FFFFFFFFFFFFEp+62, 0x7FFFFFFFFFFFF800);
58 test__fixdfdi(0x1.FFFFFFFFFFFFFp+62, 0x7FFFFFFFFFFFFC00);
59 test__fixdfdi(0x1.0000000000000p+63, 0x7FFFFFFFFFFFFFFF);
60 test__fixdfdi(0x1.0000000000001p+63, 0x7FFFFFFFFFFFFFFF);
57 try test__fixdfdi(0x1.FFFFFFFFFFFFEp+62, 0x7FFFFFFFFFFFF800);
58 try test__fixdfdi(0x1.FFFFFFFFFFFFFp+62, 0x7FFFFFFFFFFFFC00);
59 try test__fixdfdi(0x1.0000000000000p+63, 0x7FFFFFFFFFFFFFFF);
60 try test__fixdfdi(0x1.0000000000001p+63, 0x7FFFFFFFFFFFFFFF);
6161
62 test__fixdfdi(0x1.FFFFFFFFFFFFEp+126, 0x7FFFFFFFFFFFFFFF);
63 test__fixdfdi(0x1.FFFFFFFFFFFFFp+126, 0x7FFFFFFFFFFFFFFF);
64 test__fixdfdi(0x1.0000000000000p+127, 0x7FFFFFFFFFFFFFFF);
62 try test__fixdfdi(0x1.FFFFFFFFFFFFEp+126, 0x7FFFFFFFFFFFFFFF);
63 try test__fixdfdi(0x1.FFFFFFFFFFFFFp+126, 0x7FFFFFFFFFFFFFFF);
64 try test__fixdfdi(0x1.0000000000000p+127, 0x7FFFFFFFFFFFFFFF);
6565
66 test__fixdfdi(0x1.FFFFFFFFFFFFFp+1023, 0x7FFFFFFFFFFFFFFF);
67 test__fixdfdi(0x1.FFFFFFFFFFFFFp+1023, math.maxInt(i64));
66 try test__fixdfdi(0x1.FFFFFFFFFFFFFp+1023, 0x7FFFFFFFFFFFFFFF);
67 try test__fixdfdi(0x1.FFFFFFFFFFFFFp+1023, math.maxInt(i64));
6868
69 test__fixdfdi(math.f64_max, math.maxInt(i64));
69 try test__fixdfdi(math.f64_max, math.maxInt(i64));
7070}
lib/std/special/compiler_rt/fixdfsi_test.zig+48-48
......@@ -9,70 +9,70 @@ const math = std.math;
99const testing = std.testing;
1010const warn = std.debug.warn;
1111
12fn test__fixdfsi(a: f64, expected: i32) void {
12fn test__fixdfsi(a: f64, expected: i32) !void {
1313 const x = __fixdfsi(a);
1414 //warn("a={}:{x} x={}:{x} expected={}:{x}:@as(u64, {x})\n", .{a, @bitCast(u64, a), x, x, expected, expected, @bitCast(u32, expected)});
15 testing.expect(x == expected);
15 try testing.expect(x == expected);
1616}
1717
1818test "fixdfsi" {
1919 //warn("\n", .{});
20 test__fixdfsi(-math.f64_max, math.minInt(i32));
20 try test__fixdfsi(-math.f64_max, math.minInt(i32));
2121
22 test__fixdfsi(-0x1.FFFFFFFFFFFFFp+1023, math.minInt(i32));
23 test__fixdfsi(-0x1.FFFFFFFFFFFFFp+1023, -0x80000000);
22 try test__fixdfsi(-0x1.FFFFFFFFFFFFFp+1023, math.minInt(i32));
23 try test__fixdfsi(-0x1.FFFFFFFFFFFFFp+1023, -0x80000000);
2424
25 test__fixdfsi(-0x1.0000000000000p+127, -0x80000000);
26 test__fixdfsi(-0x1.FFFFFFFFFFFFFp+126, -0x80000000);
27 test__fixdfsi(-0x1.FFFFFFFFFFFFEp+126, -0x80000000);
25 try test__fixdfsi(-0x1.0000000000000p+127, -0x80000000);
26 try test__fixdfsi(-0x1.FFFFFFFFFFFFFp+126, -0x80000000);
27 try test__fixdfsi(-0x1.FFFFFFFFFFFFEp+126, -0x80000000);
2828
29 test__fixdfsi(-0x1.0000000000001p+63, -0x80000000);
30 test__fixdfsi(-0x1.0000000000000p+63, -0x80000000);
31 test__fixdfsi(-0x1.FFFFFFFFFFFFFp+62, -0x80000000);
32 test__fixdfsi(-0x1.FFFFFFFFFFFFEp+62, -0x80000000);
29 try test__fixdfsi(-0x1.0000000000001p+63, -0x80000000);
30 try test__fixdfsi(-0x1.0000000000000p+63, -0x80000000);
31 try test__fixdfsi(-0x1.FFFFFFFFFFFFFp+62, -0x80000000);
32 try test__fixdfsi(-0x1.FFFFFFFFFFFFEp+62, -0x80000000);
3333
34 test__fixdfsi(-0x1.FFFFFEp+62, -0x80000000);
35 test__fixdfsi(-0x1.FFFFFCp+62, -0x80000000);
34 try test__fixdfsi(-0x1.FFFFFEp+62, -0x80000000);
35 try test__fixdfsi(-0x1.FFFFFCp+62, -0x80000000);
3636
37 test__fixdfsi(-0x1.000000p+31, -0x80000000);
38 test__fixdfsi(-0x1.FFFFFFp+30, -0x7FFFFFC0);
39 test__fixdfsi(-0x1.FFFFFEp+30, -0x7FFFFF80);
37 try test__fixdfsi(-0x1.000000p+31, -0x80000000);
38 try test__fixdfsi(-0x1.FFFFFFp+30, -0x7FFFFFC0);
39 try test__fixdfsi(-0x1.FFFFFEp+30, -0x7FFFFF80);
4040
41 test__fixdfsi(-2.01, -2);
42 test__fixdfsi(-2.0, -2);
43 test__fixdfsi(-1.99, -1);
44 test__fixdfsi(-1.0, -1);
45 test__fixdfsi(-0.99, 0);
46 test__fixdfsi(-0.5, 0);
47 test__fixdfsi(-math.f64_min, 0);
48 test__fixdfsi(0.0, 0);
49 test__fixdfsi(math.f64_min, 0);
50 test__fixdfsi(0.5, 0);
51 test__fixdfsi(0.99, 0);
52 test__fixdfsi(1.0, 1);
53 test__fixdfsi(1.5, 1);
54 test__fixdfsi(1.99, 1);
55 test__fixdfsi(2.0, 2);
56 test__fixdfsi(2.01, 2);
41 try test__fixdfsi(-2.01, -2);
42 try test__fixdfsi(-2.0, -2);
43 try test__fixdfsi(-1.99, -1);
44 try test__fixdfsi(-1.0, -1);
45 try test__fixdfsi(-0.99, 0);
46 try test__fixdfsi(-0.5, 0);
47 try test__fixdfsi(-math.f64_min, 0);
48 try test__fixdfsi(0.0, 0);
49 try test__fixdfsi(math.f64_min, 0);
50 try test__fixdfsi(0.5, 0);
51 try test__fixdfsi(0.99, 0);
52 try test__fixdfsi(1.0, 1);
53 try test__fixdfsi(1.5, 1);
54 try test__fixdfsi(1.99, 1);
55 try test__fixdfsi(2.0, 2);
56 try test__fixdfsi(2.01, 2);
5757
58 test__fixdfsi(0x1.FFFFFEp+30, 0x7FFFFF80);
59 test__fixdfsi(0x1.FFFFFFp+30, 0x7FFFFFC0);
60 test__fixdfsi(0x1.000000p+31, 0x7FFFFFFF);
58 try test__fixdfsi(0x1.FFFFFEp+30, 0x7FFFFF80);
59 try test__fixdfsi(0x1.FFFFFFp+30, 0x7FFFFFC0);
60 try test__fixdfsi(0x1.000000p+31, 0x7FFFFFFF);
6161
62 test__fixdfsi(0x1.FFFFFCp+62, 0x7FFFFFFF);
63 test__fixdfsi(0x1.FFFFFEp+62, 0x7FFFFFFF);
62 try test__fixdfsi(0x1.FFFFFCp+62, 0x7FFFFFFF);
63 try test__fixdfsi(0x1.FFFFFEp+62, 0x7FFFFFFF);
6464
65 test__fixdfsi(0x1.FFFFFFFFFFFFEp+62, 0x7FFFFFFF);
66 test__fixdfsi(0x1.FFFFFFFFFFFFFp+62, 0x7FFFFFFF);
67 test__fixdfsi(0x1.0000000000000p+63, 0x7FFFFFFF);
68 test__fixdfsi(0x1.0000000000001p+63, 0x7FFFFFFF);
65 try test__fixdfsi(0x1.FFFFFFFFFFFFEp+62, 0x7FFFFFFF);
66 try test__fixdfsi(0x1.FFFFFFFFFFFFFp+62, 0x7FFFFFFF);
67 try test__fixdfsi(0x1.0000000000000p+63, 0x7FFFFFFF);
68 try test__fixdfsi(0x1.0000000000001p+63, 0x7FFFFFFF);
6969
70 test__fixdfsi(0x1.FFFFFFFFFFFFEp+126, 0x7FFFFFFF);
71 test__fixdfsi(0x1.FFFFFFFFFFFFFp+126, 0x7FFFFFFF);
72 test__fixdfsi(0x1.0000000000000p+127, 0x7FFFFFFF);
70 try test__fixdfsi(0x1.FFFFFFFFFFFFEp+126, 0x7FFFFFFF);
71 try test__fixdfsi(0x1.FFFFFFFFFFFFFp+126, 0x7FFFFFFF);
72 try test__fixdfsi(0x1.0000000000000p+127, 0x7FFFFFFF);
7373
74 test__fixdfsi(0x1.FFFFFFFFFFFFFp+1023, 0x7FFFFFFF);
75 test__fixdfsi(0x1.FFFFFFFFFFFFFp+1023, math.maxInt(i32));
74 try test__fixdfsi(0x1.FFFFFFFFFFFFFp+1023, 0x7FFFFFFF);
75 try test__fixdfsi(0x1.FFFFFFFFFFFFFp+1023, math.maxInt(i32));
7676
77 test__fixdfsi(math.f64_max, math.maxInt(i32));
77 try test__fixdfsi(math.f64_max, math.maxInt(i32));
7878}
lib/std/special/compiler_rt/fixdfti_test.zig+42-42
......@@ -9,62 +9,62 @@ const math = std.math;
99const testing = std.testing;
1010const warn = std.debug.warn;
1111
12fn test__fixdfti(a: f64, expected: i128) void {
12fn test__fixdfti(a: f64, expected: i128) !void {
1313 const x = __fixdfti(a);
1414 //warn("a={}:{x} x={}:{x} expected={}:{x}:@as(u64, {x})\n", .{a, @bitCast(u64, a), x, x, expected, expected, @bitCast(u128, expected)});
15 testing.expect(x == expected);
15 try testing.expect(x == expected);
1616}
1717
1818test "fixdfti" {
1919 //warn("\n", .{});
20 test__fixdfti(-math.f64_max, math.minInt(i128));
20 try test__fixdfti(-math.f64_max, math.minInt(i128));
2121
22 test__fixdfti(-0x1.FFFFFFFFFFFFFp+1023, math.minInt(i128));
23 test__fixdfti(-0x1.FFFFFFFFFFFFFp+1023, -0x80000000000000000000000000000000);
22 try test__fixdfti(-0x1.FFFFFFFFFFFFFp+1023, math.minInt(i128));
23 try test__fixdfti(-0x1.FFFFFFFFFFFFFp+1023, -0x80000000000000000000000000000000);
2424
25 test__fixdfti(-0x1.0000000000000p+127, -0x80000000000000000000000000000000);
26 test__fixdfti(-0x1.FFFFFFFFFFFFFp+126, -0x7FFFFFFFFFFFFC000000000000000000);
27 test__fixdfti(-0x1.FFFFFFFFFFFFEp+126, -0x7FFFFFFFFFFFF8000000000000000000);
25 try test__fixdfti(-0x1.0000000000000p+127, -0x80000000000000000000000000000000);
26 try test__fixdfti(-0x1.FFFFFFFFFFFFFp+126, -0x7FFFFFFFFFFFFC000000000000000000);
27 try test__fixdfti(-0x1.FFFFFFFFFFFFEp+126, -0x7FFFFFFFFFFFF8000000000000000000);
2828
29 test__fixdfti(-0x1.0000000000001p+63, -0x8000000000000800);
30 test__fixdfti(-0x1.0000000000000p+63, -0x8000000000000000);
31 test__fixdfti(-0x1.FFFFFFFFFFFFFp+62, -0x7FFFFFFFFFFFFC00);
32 test__fixdfti(-0x1.FFFFFFFFFFFFEp+62, -0x7FFFFFFFFFFFF800);
29 try test__fixdfti(-0x1.0000000000001p+63, -0x8000000000000800);
30 try test__fixdfti(-0x1.0000000000000p+63, -0x8000000000000000);
31 try test__fixdfti(-0x1.FFFFFFFFFFFFFp+62, -0x7FFFFFFFFFFFFC00);
32 try test__fixdfti(-0x1.FFFFFFFFFFFFEp+62, -0x7FFFFFFFFFFFF800);
3333
34 test__fixdfti(-0x1.FFFFFEp+62, -0x7fffff8000000000);
35 test__fixdfti(-0x1.FFFFFCp+62, -0x7fffff0000000000);
34 try test__fixdfti(-0x1.FFFFFEp+62, -0x7fffff8000000000);
35 try test__fixdfti(-0x1.FFFFFCp+62, -0x7fffff0000000000);
3636
37 test__fixdfti(-2.01, -2);
38 test__fixdfti(-2.0, -2);
39 test__fixdfti(-1.99, -1);
40 test__fixdfti(-1.0, -1);
41 test__fixdfti(-0.99, 0);
42 test__fixdfti(-0.5, 0);
43 test__fixdfti(-math.f64_min, 0);
44 test__fixdfti(0.0, 0);
45 test__fixdfti(math.f64_min, 0);
46 test__fixdfti(0.5, 0);
47 test__fixdfti(0.99, 0);
48 test__fixdfti(1.0, 1);
49 test__fixdfti(1.5, 1);
50 test__fixdfti(1.99, 1);
51 test__fixdfti(2.0, 2);
52 test__fixdfti(2.01, 2);
37 try test__fixdfti(-2.01, -2);
38 try test__fixdfti(-2.0, -2);
39 try test__fixdfti(-1.99, -1);
40 try test__fixdfti(-1.0, -1);
41 try test__fixdfti(-0.99, 0);
42 try test__fixdfti(-0.5, 0);
43 try test__fixdfti(-math.f64_min, 0);
44 try test__fixdfti(0.0, 0);
45 try test__fixdfti(math.f64_min, 0);
46 try test__fixdfti(0.5, 0);
47 try test__fixdfti(0.99, 0);
48 try test__fixdfti(1.0, 1);
49 try test__fixdfti(1.5, 1);
50 try test__fixdfti(1.99, 1);
51 try test__fixdfti(2.0, 2);
52 try test__fixdfti(2.01, 2);
5353
54 test__fixdfti(0x1.FFFFFCp+62, 0x7FFFFF0000000000);
55 test__fixdfti(0x1.FFFFFEp+62, 0x7FFFFF8000000000);
54 try test__fixdfti(0x1.FFFFFCp+62, 0x7FFFFF0000000000);
55 try test__fixdfti(0x1.FFFFFEp+62, 0x7FFFFF8000000000);
5656
57 test__fixdfti(0x1.FFFFFFFFFFFFEp+62, 0x7FFFFFFFFFFFF800);
58 test__fixdfti(0x1.FFFFFFFFFFFFFp+62, 0x7FFFFFFFFFFFFC00);
59 test__fixdfti(0x1.0000000000000p+63, 0x8000000000000000);
60 test__fixdfti(0x1.0000000000001p+63, 0x8000000000000800);
57 try test__fixdfti(0x1.FFFFFFFFFFFFEp+62, 0x7FFFFFFFFFFFF800);
58 try test__fixdfti(0x1.FFFFFFFFFFFFFp+62, 0x7FFFFFFFFFFFFC00);
59 try test__fixdfti(0x1.0000000000000p+63, 0x8000000000000000);
60 try test__fixdfti(0x1.0000000000001p+63, 0x8000000000000800);
6161
62 test__fixdfti(0x1.FFFFFFFFFFFFEp+126, 0x7FFFFFFFFFFFF8000000000000000000);
63 test__fixdfti(0x1.FFFFFFFFFFFFFp+126, 0x7FFFFFFFFFFFFC000000000000000000);
64 test__fixdfti(0x1.0000000000000p+127, 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF);
62 try test__fixdfti(0x1.FFFFFFFFFFFFEp+126, 0x7FFFFFFFFFFFF8000000000000000000);
63 try test__fixdfti(0x1.FFFFFFFFFFFFFp+126, 0x7FFFFFFFFFFFFC000000000000000000);
64 try test__fixdfti(0x1.0000000000000p+127, 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF);
6565
66 test__fixdfti(0x1.FFFFFFFFFFFFFp+1023, 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF);
67 test__fixdfti(0x1.FFFFFFFFFFFFFp+1023, math.maxInt(i128));
66 try test__fixdfti(0x1.FFFFFFFFFFFFFp+1023, 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF);
67 try test__fixdfti(0x1.FFFFFFFFFFFFFp+1023, math.maxInt(i128));
6868
69 test__fixdfti(math.f64_max, math.maxInt(i128));
69 try test__fixdfti(math.f64_max, math.maxInt(i128));
7070}
lib/std/special/compiler_rt/fixint_test.zig+123-123
......@@ -11,147 +11,147 @@ const warn = std.debug.warn;
1111
1212const fixint = @import("fixint.zig").fixint;
1313
14fn test__fixint(comptime fp_t: type, comptime fixint_t: type, a: fp_t, expected: fixint_t) void {
14fn test__fixint(comptime fp_t: type, comptime fixint_t: type, a: fp_t, expected: fixint_t) !void {
1515 const x = fixint(fp_t, fixint_t, a);
1616 //warn("a={} x={}:{x} expected={}:{x})\n", .{a, x, x, expected, expected});
17 testing.expect(x == expected);
17 try testing.expect(x == expected);
1818}
1919
2020test "fixint.i1" {
21 test__fixint(f32, i1, -math.inf_f32, -1);
22 test__fixint(f32, i1, -math.f32_max, -1);
23 test__fixint(f32, i1, -2.0, -1);
24 test__fixint(f32, i1, -1.1, -1);
25 test__fixint(f32, i1, -1.0, -1);
26 test__fixint(f32, i1, -0.9, 0);
27 test__fixint(f32, i1, -0.1, 0);
28 test__fixint(f32, i1, -math.f32_min, 0);
29 test__fixint(f32, i1, -0.0, 0);
30 test__fixint(f32, i1, 0.0, 0);
31 test__fixint(f32, i1, math.f32_min, 0);
32 test__fixint(f32, i1, 0.1, 0);
33 test__fixint(f32, i1, 0.9, 0);
34 test__fixint(f32, i1, 1.0, 0);
35 test__fixint(f32, i1, 2.0, 0);
36 test__fixint(f32, i1, math.f32_max, 0);
37 test__fixint(f32, i1, math.inf_f32, 0);
21 try test__fixint(f32, i1, -math.inf_f32, -1);
22 try test__fixint(f32, i1, -math.f32_max, -1);
23 try test__fixint(f32, i1, -2.0, -1);
24 try test__fixint(f32, i1, -1.1, -1);
25 try test__fixint(f32, i1, -1.0, -1);
26 try test__fixint(f32, i1, -0.9, 0);
27 try test__fixint(f32, i1, -0.1, 0);
28 try test__fixint(f32, i1, -math.f32_min, 0);
29 try test__fixint(f32, i1, -0.0, 0);
30 try test__fixint(f32, i1, 0.0, 0);
31 try test__fixint(f32, i1, math.f32_min, 0);
32 try test__fixint(f32, i1, 0.1, 0);
33 try test__fixint(f32, i1, 0.9, 0);
34 try test__fixint(f32, i1, 1.0, 0);
35 try test__fixint(f32, i1, 2.0, 0);
36 try test__fixint(f32, i1, math.f32_max, 0);
37 try test__fixint(f32, i1, math.inf_f32, 0);
3838}
3939
4040test "fixint.i2" {
41 test__fixint(f32, i2, -math.inf_f32, -2);
42 test__fixint(f32, i2, -math.f32_max, -2);
43 test__fixint(f32, i2, -2.0, -2);
44 test__fixint(f32, i2, -1.9, -1);
45 test__fixint(f32, i2, -1.1, -1);
46 test__fixint(f32, i2, -1.0, -1);
47 test__fixint(f32, i2, -0.9, 0);
48 test__fixint(f32, i2, -0.1, 0);
49 test__fixint(f32, i2, -math.f32_min, 0);
50 test__fixint(f32, i2, -0.0, 0);
51 test__fixint(f32, i2, 0.0, 0);
52 test__fixint(f32, i2, math.f32_min, 0);
53 test__fixint(f32, i2, 0.1, 0);
54 test__fixint(f32, i2, 0.9, 0);
55 test__fixint(f32, i2, 1.0, 1);
56 test__fixint(f32, i2, 2.0, 1);
57 test__fixint(f32, i2, math.f32_max, 1);
58 test__fixint(f32, i2, math.inf_f32, 1);
41 try test__fixint(f32, i2, -math.inf_f32, -2);
42 try test__fixint(f32, i2, -math.f32_max, -2);
43 try test__fixint(f32, i2, -2.0, -2);
44 try test__fixint(f32, i2, -1.9, -1);
45 try test__fixint(f32, i2, -1.1, -1);
46 try test__fixint(f32, i2, -1.0, -1);
47 try test__fixint(f32, i2, -0.9, 0);
48 try test__fixint(f32, i2, -0.1, 0);
49 try test__fixint(f32, i2, -math.f32_min, 0);
50 try test__fixint(f32, i2, -0.0, 0);
51 try test__fixint(f32, i2, 0.0, 0);
52 try test__fixint(f32, i2, math.f32_min, 0);
53 try test__fixint(f32, i2, 0.1, 0);
54 try test__fixint(f32, i2, 0.9, 0);
55 try test__fixint(f32, i2, 1.0, 1);
56 try test__fixint(f32, i2, 2.0, 1);
57 try test__fixint(f32, i2, math.f32_max, 1);
58 try test__fixint(f32, i2, math.inf_f32, 1);
5959}
6060
6161test "fixint.i3" {
62 test__fixint(f32, i3, -math.inf_f32, -4);
63 test__fixint(f32, i3, -math.f32_max, -4);
64 test__fixint(f32, i3, -4.0, -4);
65 test__fixint(f32, i3, -3.0, -3);
66 test__fixint(f32, i3, -2.0, -2);
67 test__fixint(f32, i3, -1.9, -1);
68 test__fixint(f32, i3, -1.1, -1);
69 test__fixint(f32, i3, -1.0, -1);
70 test__fixint(f32, i3, -0.9, 0);
71 test__fixint(f32, i3, -0.1, 0);
72 test__fixint(f32, i3, -math.f32_min, 0);
73 test__fixint(f32, i3, -0.0, 0);
74 test__fixint(f32, i3, 0.0, 0);
75 test__fixint(f32, i3, math.f32_min, 0);
76 test__fixint(f32, i3, 0.1, 0);
77 test__fixint(f32, i3, 0.9, 0);
78 test__fixint(f32, i3, 1.0, 1);
79 test__fixint(f32, i3, 2.0, 2);
80 test__fixint(f32, i3, 3.0, 3);
81 test__fixint(f32, i3, 4.0, 3);
82 test__fixint(f32, i3, math.f32_max, 3);
83 test__fixint(f32, i3, math.inf_f32, 3);
62 try test__fixint(f32, i3, -math.inf_f32, -4);
63 try test__fixint(f32, i3, -math.f32_max, -4);
64 try test__fixint(f32, i3, -4.0, -4);
65 try test__fixint(f32, i3, -3.0, -3);
66 try test__fixint(f32, i3, -2.0, -2);
67 try test__fixint(f32, i3, -1.9, -1);
68 try test__fixint(f32, i3, -1.1, -1);
69 try test__fixint(f32, i3, -1.0, -1);
70 try test__fixint(f32, i3, -0.9, 0);
71 try test__fixint(f32, i3, -0.1, 0);
72 try test__fixint(f32, i3, -math.f32_min, 0);
73 try test__fixint(f32, i3, -0.0, 0);
74 try test__fixint(f32, i3, 0.0, 0);
75 try test__fixint(f32, i3, math.f32_min, 0);
76 try test__fixint(f32, i3, 0.1, 0);
77 try test__fixint(f32, i3, 0.9, 0);
78 try test__fixint(f32, i3, 1.0, 1);
79 try test__fixint(f32, i3, 2.0, 2);
80 try test__fixint(f32, i3, 3.0, 3);
81 try test__fixint(f32, i3, 4.0, 3);
82 try test__fixint(f32, i3, math.f32_max, 3);
83 try test__fixint(f32, i3, math.inf_f32, 3);
8484}
8585
8686test "fixint.i32" {
87 test__fixint(f64, i32, -math.inf_f64, math.minInt(i32));
88 test__fixint(f64, i32, -math.f64_max, math.minInt(i32));
89 test__fixint(f64, i32, @as(f64, math.minInt(i32)), math.minInt(i32));
90 test__fixint(f64, i32, @as(f64, math.minInt(i32)) + 1, math.minInt(i32) + 1);
91 test__fixint(f64, i32, -2.0, -2);
92 test__fixint(f64, i32, -1.9, -1);
93 test__fixint(f64, i32, -1.1, -1);
94 test__fixint(f64, i32, -1.0, -1);
95 test__fixint(f64, i32, -0.9, 0);
96 test__fixint(f64, i32, -0.1, 0);
97 test__fixint(f64, i32, -math.f32_min, 0);
98 test__fixint(f64, i32, -0.0, 0);
99 test__fixint(f64, i32, 0.0, 0);
100 test__fixint(f64, i32, math.f32_min, 0);
101 test__fixint(f64, i32, 0.1, 0);
102 test__fixint(f64, i32, 0.9, 0);
103 test__fixint(f64, i32, 1.0, 1);
104 test__fixint(f64, i32, @as(f64, math.maxInt(i32)) - 1, math.maxInt(i32) - 1);
105 test__fixint(f64, i32, @as(f64, math.maxInt(i32)), math.maxInt(i32));
106 test__fixint(f64, i32, math.f64_max, math.maxInt(i32));
107 test__fixint(f64, i32, math.inf_f64, math.maxInt(i32));
87 try test__fixint(f64, i32, -math.inf_f64, math.minInt(i32));
88 try test__fixint(f64, i32, -math.f64_max, math.minInt(i32));
89 try test__fixint(f64, i32, @as(f64, math.minInt(i32)), math.minInt(i32));
90 try test__fixint(f64, i32, @as(f64, math.minInt(i32)) + 1, math.minInt(i32) + 1);
91 try test__fixint(f64, i32, -2.0, -2);
92 try test__fixint(f64, i32, -1.9, -1);
93 try test__fixint(f64, i32, -1.1, -1);
94 try test__fixint(f64, i32, -1.0, -1);
95 try test__fixint(f64, i32, -0.9, 0);
96 try test__fixint(f64, i32, -0.1, 0);
97 try test__fixint(f64, i32, -math.f32_min, 0);
98 try test__fixint(f64, i32, -0.0, 0);
99 try test__fixint(f64, i32, 0.0, 0);
100 try test__fixint(f64, i32, math.f32_min, 0);
101 try test__fixint(f64, i32, 0.1, 0);
102 try test__fixint(f64, i32, 0.9, 0);
103 try test__fixint(f64, i32, 1.0, 1);
104 try test__fixint(f64, i32, @as(f64, math.maxInt(i32)) - 1, math.maxInt(i32) - 1);
105 try test__fixint(f64, i32, @as(f64, math.maxInt(i32)), math.maxInt(i32));
106 try test__fixint(f64, i32, math.f64_max, math.maxInt(i32));
107 try test__fixint(f64, i32, math.inf_f64, math.maxInt(i32));
108108}
109109
110110test "fixint.i64" {
111 test__fixint(f64, i64, -math.inf_f64, math.minInt(i64));
112 test__fixint(f64, i64, -math.f64_max, math.minInt(i64));
113 test__fixint(f64, i64, @as(f64, math.minInt(i64)), math.minInt(i64));
114 test__fixint(f64, i64, @as(f64, math.minInt(i64)) + 1, math.minInt(i64));
115 test__fixint(f64, i64, @as(f64, math.minInt(i64) / 2), math.minInt(i64) / 2);
116 test__fixint(f64, i64, -2.0, -2);
117 test__fixint(f64, i64, -1.9, -1);
118 test__fixint(f64, i64, -1.1, -1);
119 test__fixint(f64, i64, -1.0, -1);
120 test__fixint(f64, i64, -0.9, 0);
121 test__fixint(f64, i64, -0.1, 0);
122 test__fixint(f64, i64, -math.f32_min, 0);
123 test__fixint(f64, i64, -0.0, 0);
124 test__fixint(f64, i64, 0.0, 0);
125 test__fixint(f64, i64, math.f32_min, 0);
126 test__fixint(f64, i64, 0.1, 0);
127 test__fixint(f64, i64, 0.9, 0);
128 test__fixint(f64, i64, 1.0, 1);
129 test__fixint(f64, i64, @as(f64, math.maxInt(i64)) - 1, math.maxInt(i64));
130 test__fixint(f64, i64, @as(f64, math.maxInt(i64)), math.maxInt(i64));
131 test__fixint(f64, i64, math.f64_max, math.maxInt(i64));
132 test__fixint(f64, i64, math.inf_f64, math.maxInt(i64));
111 try test__fixint(f64, i64, -math.inf_f64, math.minInt(i64));
112 try test__fixint(f64, i64, -math.f64_max, math.minInt(i64));
113 try test__fixint(f64, i64, @as(f64, math.minInt(i64)), math.minInt(i64));
114 try test__fixint(f64, i64, @as(f64, math.minInt(i64)) + 1, math.minInt(i64));
115 try test__fixint(f64, i64, @as(f64, math.minInt(i64) / 2), math.minInt(i64) / 2);
116 try test__fixint(f64, i64, -2.0, -2);
117 try test__fixint(f64, i64, -1.9, -1);
118 try test__fixint(f64, i64, -1.1, -1);
119 try test__fixint(f64, i64, -1.0, -1);
120 try test__fixint(f64, i64, -0.9, 0);
121 try test__fixint(f64, i64, -0.1, 0);
122 try test__fixint(f64, i64, -math.f32_min, 0);
123 try test__fixint(f64, i64, -0.0, 0);
124 try test__fixint(f64, i64, 0.0, 0);
125 try test__fixint(f64, i64, math.f32_min, 0);
126 try test__fixint(f64, i64, 0.1, 0);
127 try test__fixint(f64, i64, 0.9, 0);
128 try test__fixint(f64, i64, 1.0, 1);
129 try test__fixint(f64, i64, @as(f64, math.maxInt(i64)) - 1, math.maxInt(i64));
130 try test__fixint(f64, i64, @as(f64, math.maxInt(i64)), math.maxInt(i64));
131 try test__fixint(f64, i64, math.f64_max, math.maxInt(i64));
132 try test__fixint(f64, i64, math.inf_f64, math.maxInt(i64));
133133}
134134
135135test "fixint.i128" {
136 test__fixint(f64, i128, -math.inf_f64, math.minInt(i128));
137 test__fixint(f64, i128, -math.f64_max, math.minInt(i128));
138 test__fixint(f64, i128, @as(f64, math.minInt(i128)), math.minInt(i128));
139 test__fixint(f64, i128, @as(f64, math.minInt(i128)) + 1, math.minInt(i128));
140 test__fixint(f64, i128, -2.0, -2);
141 test__fixint(f64, i128, -1.9, -1);
142 test__fixint(f64, i128, -1.1, -1);
143 test__fixint(f64, i128, -1.0, -1);
144 test__fixint(f64, i128, -0.9, 0);
145 test__fixint(f64, i128, -0.1, 0);
146 test__fixint(f64, i128, -math.f32_min, 0);
147 test__fixint(f64, i128, -0.0, 0);
148 test__fixint(f64, i128, 0.0, 0);
149 test__fixint(f64, i128, math.f32_min, 0);
150 test__fixint(f64, i128, 0.1, 0);
151 test__fixint(f64, i128, 0.9, 0);
152 test__fixint(f64, i128, 1.0, 1);
153 test__fixint(f64, i128, @as(f64, math.maxInt(i128)) - 1, math.maxInt(i128));
154 test__fixint(f64, i128, @as(f64, math.maxInt(i128)), math.maxInt(i128));
155 test__fixint(f64, i128, math.f64_max, math.maxInt(i128));
156 test__fixint(f64, i128, math.inf_f64, math.maxInt(i128));
136 try test__fixint(f64, i128, -math.inf_f64, math.minInt(i128));
137 try test__fixint(f64, i128, -math.f64_max, math.minInt(i128));
138 try test__fixint(f64, i128, @as(f64, math.minInt(i128)), math.minInt(i128));
139 try test__fixint(f64, i128, @as(f64, math.minInt(i128)) + 1, math.minInt(i128));
140 try test__fixint(f64, i128, -2.0, -2);
141 try test__fixint(f64, i128, -1.9, -1);
142 try test__fixint(f64, i128, -1.1, -1);
143 try test__fixint(f64, i128, -1.0, -1);
144 try test__fixint(f64, i128, -0.9, 0);
145 try test__fixint(f64, i128, -0.1, 0);
146 try test__fixint(f64, i128, -math.f32_min, 0);
147 try test__fixint(f64, i128, -0.0, 0);
148 try test__fixint(f64, i128, 0.0, 0);
149 try test__fixint(f64, i128, math.f32_min, 0);
150 try test__fixint(f64, i128, 0.1, 0);
151 try test__fixint(f64, i128, 0.9, 0);
152 try test__fixint(f64, i128, 1.0, 1);
153 try test__fixint(f64, i128, @as(f64, math.maxInt(i128)) - 1, math.maxInt(i128));
154 try test__fixint(f64, i128, @as(f64, math.maxInt(i128)), math.maxInt(i128));
155 try test__fixint(f64, i128, math.f64_max, math.maxInt(i128));
156 try test__fixint(f64, i128, math.inf_f64, math.maxInt(i128));
157157}
lib/std/special/compiler_rt/fixsfdi_test.zig+44-44
......@@ -9,64 +9,64 @@ const math = std.math;
99const testing = std.testing;
1010const warn = std.debug.warn;
1111
12fn test__fixsfdi(a: f32, expected: i64) void {
12fn test__fixsfdi(a: f32, expected: i64) !void {
1313 const x = __fixsfdi(a);
1414 //warn("a={}:{x} x={}:{x} expected={}:{x}:@as(u32, {x})\n", .{a, @bitCast(u32, a), x, x, expected, expected, @bitCast(u64, expected)});
15 testing.expect(x == expected);
15 try testing.expect(x == expected);
1616}
1717
1818test "fixsfdi" {
1919 //warn("\n", .{});
20 test__fixsfdi(-math.f32_max, math.minInt(i64));
20 try test__fixsfdi(-math.f32_max, math.minInt(i64));
2121
22 test__fixsfdi(-0x1.FFFFFFFFFFFFFp+1023, math.minInt(i64));
23 test__fixsfdi(-0x1.FFFFFFFFFFFFFp+1023, -0x8000000000000000);
22 try test__fixsfdi(-0x1.FFFFFFFFFFFFFp+1023, math.minInt(i64));
23 try test__fixsfdi(-0x1.FFFFFFFFFFFFFp+1023, -0x8000000000000000);
2424
25 test__fixsfdi(-0x1.0000000000000p+127, -0x8000000000000000);
26 test__fixsfdi(-0x1.FFFFFFFFFFFFFp+126, -0x8000000000000000);
27 test__fixsfdi(-0x1.FFFFFFFFFFFFEp+126, -0x8000000000000000);
25 try test__fixsfdi(-0x1.0000000000000p+127, -0x8000000000000000);
26 try test__fixsfdi(-0x1.FFFFFFFFFFFFFp+126, -0x8000000000000000);
27 try test__fixsfdi(-0x1.FFFFFFFFFFFFEp+126, -0x8000000000000000);
2828
29 test__fixsfdi(-0x1.0000000000001p+63, -0x8000000000000000);
30 test__fixsfdi(-0x1.0000000000000p+63, -0x8000000000000000);
31 test__fixsfdi(-0x1.FFFFFFFFFFFFFp+62, -0x8000000000000000);
32 test__fixsfdi(-0x1.FFFFFFFFFFFFEp+62, -0x8000000000000000);
29 try test__fixsfdi(-0x1.0000000000001p+63, -0x8000000000000000);
30 try test__fixsfdi(-0x1.0000000000000p+63, -0x8000000000000000);
31 try test__fixsfdi(-0x1.FFFFFFFFFFFFFp+62, -0x8000000000000000);
32 try test__fixsfdi(-0x1.FFFFFFFFFFFFEp+62, -0x8000000000000000);
3333
34 test__fixsfdi(-0x1.FFFFFFp+62, -0x8000000000000000);
35 test__fixsfdi(-0x1.FFFFFEp+62, -0x7fffff8000000000);
36 test__fixsfdi(-0x1.FFFFFCp+62, -0x7fffff0000000000);
34 try test__fixsfdi(-0x1.FFFFFFp+62, -0x8000000000000000);
35 try test__fixsfdi(-0x1.FFFFFEp+62, -0x7fffff8000000000);
36 try test__fixsfdi(-0x1.FFFFFCp+62, -0x7fffff0000000000);
3737
38 test__fixsfdi(-2.01, -2);
39 test__fixsfdi(-2.0, -2);
40 test__fixsfdi(-1.99, -1);
41 test__fixsfdi(-1.0, -1);
42 test__fixsfdi(-0.99, 0);
43 test__fixsfdi(-0.5, 0);
44 test__fixsfdi(-math.f32_min, 0);
45 test__fixsfdi(0.0, 0);
46 test__fixsfdi(math.f32_min, 0);
47 test__fixsfdi(0.5, 0);
48 test__fixsfdi(0.99, 0);
49 test__fixsfdi(1.0, 1);
50 test__fixsfdi(1.5, 1);
51 test__fixsfdi(1.99, 1);
52 test__fixsfdi(2.0, 2);
53 test__fixsfdi(2.01, 2);
38 try test__fixsfdi(-2.01, -2);
39 try test__fixsfdi(-2.0, -2);
40 try test__fixsfdi(-1.99, -1);
41 try test__fixsfdi(-1.0, -1);
42 try test__fixsfdi(-0.99, 0);
43 try test__fixsfdi(-0.5, 0);
44 try test__fixsfdi(-math.f32_min, 0);
45 try test__fixsfdi(0.0, 0);
46 try test__fixsfdi(math.f32_min, 0);
47 try test__fixsfdi(0.5, 0);
48 try test__fixsfdi(0.99, 0);
49 try test__fixsfdi(1.0, 1);
50 try test__fixsfdi(1.5, 1);
51 try test__fixsfdi(1.99, 1);
52 try test__fixsfdi(2.0, 2);
53 try test__fixsfdi(2.01, 2);
5454
55 test__fixsfdi(0x1.FFFFFCp+62, 0x7FFFFF0000000000);
56 test__fixsfdi(0x1.FFFFFEp+62, 0x7FFFFF8000000000);
57 test__fixsfdi(0x1.FFFFFFp+62, 0x7FFFFFFFFFFFFFFF);
55 try test__fixsfdi(0x1.FFFFFCp+62, 0x7FFFFF0000000000);
56 try test__fixsfdi(0x1.FFFFFEp+62, 0x7FFFFF8000000000);
57 try test__fixsfdi(0x1.FFFFFFp+62, 0x7FFFFFFFFFFFFFFF);
5858
59 test__fixsfdi(0x1.FFFFFFFFFFFFEp+62, 0x7FFFFFFFFFFFFFFF);
60 test__fixsfdi(0x1.FFFFFFFFFFFFFp+62, 0x7FFFFFFFFFFFFFFF);
61 test__fixsfdi(0x1.0000000000000p+63, 0x7FFFFFFFFFFFFFFF);
62 test__fixsfdi(0x1.0000000000001p+63, 0x7FFFFFFFFFFFFFFF);
59 try test__fixsfdi(0x1.FFFFFFFFFFFFEp+62, 0x7FFFFFFFFFFFFFFF);
60 try test__fixsfdi(0x1.FFFFFFFFFFFFFp+62, 0x7FFFFFFFFFFFFFFF);
61 try test__fixsfdi(0x1.0000000000000p+63, 0x7FFFFFFFFFFFFFFF);
62 try test__fixsfdi(0x1.0000000000001p+63, 0x7FFFFFFFFFFFFFFF);
6363
64 test__fixsfdi(0x1.FFFFFFFFFFFFEp+126, 0x7FFFFFFFFFFFFFFF);
65 test__fixsfdi(0x1.FFFFFFFFFFFFFp+126, 0x7FFFFFFFFFFFFFFF);
66 test__fixsfdi(0x1.0000000000000p+127, 0x7FFFFFFFFFFFFFFF);
64 try test__fixsfdi(0x1.FFFFFFFFFFFFEp+126, 0x7FFFFFFFFFFFFFFF);
65 try test__fixsfdi(0x1.FFFFFFFFFFFFFp+126, 0x7FFFFFFFFFFFFFFF);
66 try test__fixsfdi(0x1.0000000000000p+127, 0x7FFFFFFFFFFFFFFF);
6767
68 test__fixsfdi(0x1.FFFFFFFFFFFFFp+1023, 0x7FFFFFFFFFFFFFFF);
69 test__fixsfdi(0x1.FFFFFFFFFFFFFp+1023, math.maxInt(i64));
68 try test__fixsfdi(0x1.FFFFFFFFFFFFFp+1023, 0x7FFFFFFFFFFFFFFF);
69 try test__fixsfdi(0x1.FFFFFFFFFFFFFp+1023, math.maxInt(i64));
7070
71 test__fixsfdi(math.f64_max, math.maxInt(i64));
71 try test__fixsfdi(math.f64_max, math.maxInt(i64));
7272}
lib/std/special/compiler_rt/fixsfsi_test.zig+50-50
......@@ -9,72 +9,72 @@ const math = std.math;
99const testing = std.testing;
1010const warn = std.debug.warn;
1111
12fn test__fixsfsi(a: f32, expected: i32) void {
12fn test__fixsfsi(a: f32, expected: i32) !void {
1313 const x = __fixsfsi(a);
1414 //warn("a={}:{x} x={}:{x} expected={}:{x}:@as(u32, {x})\n", .{a, @bitCast(u32, a), x, x, expected, expected, @bitCast(u32, expected)});
15 testing.expect(x == expected);
15 try testing.expect(x == expected);
1616}
1717
1818test "fixsfsi" {
1919 //warn("\n", .{});
20 test__fixsfsi(-math.f32_max, math.minInt(i32));
20 try test__fixsfsi(-math.f32_max, math.minInt(i32));
2121
22 test__fixsfsi(-0x1.FFFFFFFFFFFFFp+1023, math.minInt(i32));
23 test__fixsfsi(-0x1.FFFFFFFFFFFFFp+1023, -0x80000000);
22 try test__fixsfsi(-0x1.FFFFFFFFFFFFFp+1023, math.minInt(i32));
23 try test__fixsfsi(-0x1.FFFFFFFFFFFFFp+1023, -0x80000000);
2424
25 test__fixsfsi(-0x1.0000000000000p+127, -0x80000000);
26 test__fixsfsi(-0x1.FFFFFFFFFFFFFp+126, -0x80000000);
27 test__fixsfsi(-0x1.FFFFFFFFFFFFEp+126, -0x80000000);
25 try test__fixsfsi(-0x1.0000000000000p+127, -0x80000000);
26 try test__fixsfsi(-0x1.FFFFFFFFFFFFFp+126, -0x80000000);
27 try test__fixsfsi(-0x1.FFFFFFFFFFFFEp+126, -0x80000000);
2828
29 test__fixsfsi(-0x1.0000000000001p+63, -0x80000000);
30 test__fixsfsi(-0x1.0000000000000p+63, -0x80000000);
31 test__fixsfsi(-0x1.FFFFFFFFFFFFFp+62, -0x80000000);
32 test__fixsfsi(-0x1.FFFFFFFFFFFFEp+62, -0x80000000);
29 try test__fixsfsi(-0x1.0000000000001p+63, -0x80000000);
30 try test__fixsfsi(-0x1.0000000000000p+63, -0x80000000);
31 try test__fixsfsi(-0x1.FFFFFFFFFFFFFp+62, -0x80000000);
32 try test__fixsfsi(-0x1.FFFFFFFFFFFFEp+62, -0x80000000);
3333
34 test__fixsfsi(-0x1.FFFFFEp+62, -0x80000000);
35 test__fixsfsi(-0x1.FFFFFCp+62, -0x80000000);
34 try test__fixsfsi(-0x1.FFFFFEp+62, -0x80000000);
35 try test__fixsfsi(-0x1.FFFFFCp+62, -0x80000000);
3636
37 test__fixsfsi(-0x1.000000p+31, -0x80000000);
38 test__fixsfsi(-0x1.FFFFFFp+30, -0x80000000);
39 test__fixsfsi(-0x1.FFFFFEp+30, -0x7FFFFF80);
40 test__fixsfsi(-0x1.FFFFFCp+30, -0x7FFFFF00);
37 try test__fixsfsi(-0x1.000000p+31, -0x80000000);
38 try test__fixsfsi(-0x1.FFFFFFp+30, -0x80000000);
39 try test__fixsfsi(-0x1.FFFFFEp+30, -0x7FFFFF80);
40 try test__fixsfsi(-0x1.FFFFFCp+30, -0x7FFFFF00);
4141
42 test__fixsfsi(-2.01, -2);
43 test__fixsfsi(-2.0, -2);
44 test__fixsfsi(-1.99, -1);
45 test__fixsfsi(-1.0, -1);
46 test__fixsfsi(-0.99, 0);
47 test__fixsfsi(-0.5, 0);
48 test__fixsfsi(-math.f32_min, 0);
49 test__fixsfsi(0.0, 0);
50 test__fixsfsi(math.f32_min, 0);
51 test__fixsfsi(0.5, 0);
52 test__fixsfsi(0.99, 0);
53 test__fixsfsi(1.0, 1);
54 test__fixsfsi(1.5, 1);
55 test__fixsfsi(1.99, 1);
56 test__fixsfsi(2.0, 2);
57 test__fixsfsi(2.01, 2);
42 try test__fixsfsi(-2.01, -2);
43 try test__fixsfsi(-2.0, -2);
44 try test__fixsfsi(-1.99, -1);
45 try test__fixsfsi(-1.0, -1);
46 try test__fixsfsi(-0.99, 0);
47 try test__fixsfsi(-0.5, 0);
48 try test__fixsfsi(-math.f32_min, 0);
49 try test__fixsfsi(0.0, 0);
50 try test__fixsfsi(math.f32_min, 0);
51 try test__fixsfsi(0.5, 0);
52 try test__fixsfsi(0.99, 0);
53 try test__fixsfsi(1.0, 1);
54 try test__fixsfsi(1.5, 1);
55 try test__fixsfsi(1.99, 1);
56 try test__fixsfsi(2.0, 2);
57 try test__fixsfsi(2.01, 2);
5858
59 test__fixsfsi(0x1.FFFFFCp+30, 0x7FFFFF00);
60 test__fixsfsi(0x1.FFFFFEp+30, 0x7FFFFF80);
61 test__fixsfsi(0x1.FFFFFFp+30, 0x7FFFFFFF);
62 test__fixsfsi(0x1.000000p+31, 0x7FFFFFFF);
59 try test__fixsfsi(0x1.FFFFFCp+30, 0x7FFFFF00);
60 try test__fixsfsi(0x1.FFFFFEp+30, 0x7FFFFF80);
61 try test__fixsfsi(0x1.FFFFFFp+30, 0x7FFFFFFF);
62 try test__fixsfsi(0x1.000000p+31, 0x7FFFFFFF);
6363
64 test__fixsfsi(0x1.FFFFFCp+62, 0x7FFFFFFF);
65 test__fixsfsi(0x1.FFFFFEp+62, 0x7FFFFFFF);
64 try test__fixsfsi(0x1.FFFFFCp+62, 0x7FFFFFFF);
65 try test__fixsfsi(0x1.FFFFFEp+62, 0x7FFFFFFF);
6666
67 test__fixsfsi(0x1.FFFFFFFFFFFFEp+62, 0x7FFFFFFF);
68 test__fixsfsi(0x1.FFFFFFFFFFFFFp+62, 0x7FFFFFFF);
69 test__fixsfsi(0x1.0000000000000p+63, 0x7FFFFFFF);
70 test__fixsfsi(0x1.0000000000001p+63, 0x7FFFFFFF);
67 try test__fixsfsi(0x1.FFFFFFFFFFFFEp+62, 0x7FFFFFFF);
68 try test__fixsfsi(0x1.FFFFFFFFFFFFFp+62, 0x7FFFFFFF);
69 try test__fixsfsi(0x1.0000000000000p+63, 0x7FFFFFFF);
70 try test__fixsfsi(0x1.0000000000001p+63, 0x7FFFFFFF);
7171
72 test__fixsfsi(0x1.FFFFFFFFFFFFEp+126, 0x7FFFFFFF);
73 test__fixsfsi(0x1.FFFFFFFFFFFFFp+126, 0x7FFFFFFF);
74 test__fixsfsi(0x1.0000000000000p+127, 0x7FFFFFFF);
72 try test__fixsfsi(0x1.FFFFFFFFFFFFEp+126, 0x7FFFFFFF);
73 try test__fixsfsi(0x1.FFFFFFFFFFFFFp+126, 0x7FFFFFFF);
74 try test__fixsfsi(0x1.0000000000000p+127, 0x7FFFFFFF);
7575
76 test__fixsfsi(0x1.FFFFFFFFFFFFFp+1023, 0x7FFFFFFF);
77 test__fixsfsi(0x1.FFFFFFFFFFFFFp+1023, math.maxInt(i32));
76 try test__fixsfsi(0x1.FFFFFFFFFFFFFp+1023, 0x7FFFFFFF);
77 try test__fixsfsi(0x1.FFFFFFFFFFFFFp+1023, math.maxInt(i32));
7878
79 test__fixsfsi(math.f32_max, math.maxInt(i32));
79 try test__fixsfsi(math.f32_max, math.maxInt(i32));
8080}
lib/std/special/compiler_rt/fixsfti_test.zig+58-58
......@@ -9,80 +9,80 @@ const math = std.math;
99const testing = std.testing;
1010const warn = std.debug.warn;
1111
12fn test__fixsfti(a: f32, expected: i128) void {
12fn test__fixsfti(a: f32, expected: i128) !void {
1313 const x = __fixsfti(a);
1414 //warn("a={}:{x} x={}:{x} expected={}:{x}:@as(u128, {x})\n", .{a, @bitCast(u32, a), x, x, expected, expected, @bitCast(u128, expected)});
15 testing.expect(x == expected);
15 try testing.expect(x == expected);
1616}
1717
1818test "fixsfti" {
1919 //warn("\n", .{});
20 test__fixsfti(-math.f32_max, math.minInt(i128));
20 try test__fixsfti(-math.f32_max, math.minInt(i128));
2121
22 test__fixsfti(-0x1.FFFFFFFFFFFFFp+1023, math.minInt(i128));
23 test__fixsfti(-0x1.FFFFFFFFFFFFFp+1023, -0x80000000000000000000000000000000);
22 try test__fixsfti(-0x1.FFFFFFFFFFFFFp+1023, math.minInt(i128));
23 try test__fixsfti(-0x1.FFFFFFFFFFFFFp+1023, -0x80000000000000000000000000000000);
2424
25 test__fixsfti(-0x1.0000000000000p+127, -0x80000000000000000000000000000000);
26 test__fixsfti(-0x1.FFFFFFFFFFFFFp+126, -0x80000000000000000000000000000000);
27 test__fixsfti(-0x1.FFFFFFFFFFFFEp+126, -0x80000000000000000000000000000000);
28 test__fixsfti(-0x1.FFFFFF0000000p+126, -0x80000000000000000000000000000000);
29 test__fixsfti(-0x1.FFFFFE0000000p+126, -0x7FFFFF80000000000000000000000000);
30 test__fixsfti(-0x1.FFFFFC0000000p+126, -0x7FFFFF00000000000000000000000000);
25 try test__fixsfti(-0x1.0000000000000p+127, -0x80000000000000000000000000000000);
26 try test__fixsfti(-0x1.FFFFFFFFFFFFFp+126, -0x80000000000000000000000000000000);
27 try test__fixsfti(-0x1.FFFFFFFFFFFFEp+126, -0x80000000000000000000000000000000);
28 try test__fixsfti(-0x1.FFFFFF0000000p+126, -0x80000000000000000000000000000000);
29 try test__fixsfti(-0x1.FFFFFE0000000p+126, -0x7FFFFF80000000000000000000000000);
30 try test__fixsfti(-0x1.FFFFFC0000000p+126, -0x7FFFFF00000000000000000000000000);
3131
32 test__fixsfti(-0x1.0000000000001p+63, -0x8000000000000000);
33 test__fixsfti(-0x1.0000000000000p+63, -0x8000000000000000);
34 test__fixsfti(-0x1.FFFFFFFFFFFFFp+62, -0x8000000000000000);
35 test__fixsfti(-0x1.FFFFFFFFFFFFEp+62, -0x8000000000000000);
32 try test__fixsfti(-0x1.0000000000001p+63, -0x8000000000000000);
33 try test__fixsfti(-0x1.0000000000000p+63, -0x8000000000000000);
34 try test__fixsfti(-0x1.FFFFFFFFFFFFFp+62, -0x8000000000000000);
35 try test__fixsfti(-0x1.FFFFFFFFFFFFEp+62, -0x8000000000000000);
3636
37 test__fixsfti(-0x1.FFFFFFp+62, -0x8000000000000000);
38 test__fixsfti(-0x1.FFFFFEp+62, -0x7fffff8000000000);
39 test__fixsfti(-0x1.FFFFFCp+62, -0x7fffff0000000000);
37 try test__fixsfti(-0x1.FFFFFFp+62, -0x8000000000000000);
38 try test__fixsfti(-0x1.FFFFFEp+62, -0x7fffff8000000000);
39 try test__fixsfti(-0x1.FFFFFCp+62, -0x7fffff0000000000);
4040
41 test__fixsfti(-0x1.000000p+31, -0x80000000);
42 test__fixsfti(-0x1.FFFFFFp+30, -0x80000000);
43 test__fixsfti(-0x1.FFFFFEp+30, -0x7FFFFF80);
44 test__fixsfti(-0x1.FFFFFCp+30, -0x7FFFFF00);
41 try test__fixsfti(-0x1.000000p+31, -0x80000000);
42 try test__fixsfti(-0x1.FFFFFFp+30, -0x80000000);
43 try test__fixsfti(-0x1.FFFFFEp+30, -0x7FFFFF80);
44 try test__fixsfti(-0x1.FFFFFCp+30, -0x7FFFFF00);
4545
46 test__fixsfti(-2.01, -2);
47 test__fixsfti(-2.0, -2);
48 test__fixsfti(-1.99, -1);
49 test__fixsfti(-1.0, -1);
50 test__fixsfti(-0.99, 0);
51 test__fixsfti(-0.5, 0);
52 test__fixsfti(-math.f32_min, 0);
53 test__fixsfti(0.0, 0);
54 test__fixsfti(math.f32_min, 0);
55 test__fixsfti(0.5, 0);
56 test__fixsfti(0.99, 0);
57 test__fixsfti(1.0, 1);
58 test__fixsfti(1.5, 1);
59 test__fixsfti(1.99, 1);
60 test__fixsfti(2.0, 2);
61 test__fixsfti(2.01, 2);
46 try test__fixsfti(-2.01, -2);
47 try test__fixsfti(-2.0, -2);
48 try test__fixsfti(-1.99, -1);
49 try test__fixsfti(-1.0, -1);
50 try test__fixsfti(-0.99, 0);
51 try test__fixsfti(-0.5, 0);
52 try test__fixsfti(-math.f32_min, 0);
53 try test__fixsfti(0.0, 0);
54 try test__fixsfti(math.f32_min, 0);
55 try test__fixsfti(0.5, 0);
56 try test__fixsfti(0.99, 0);
57 try test__fixsfti(1.0, 1);
58 try test__fixsfti(1.5, 1);
59 try test__fixsfti(1.99, 1);
60 try test__fixsfti(2.0, 2);
61 try test__fixsfti(2.01, 2);
6262
63 test__fixsfti(0x1.FFFFFCp+30, 0x7FFFFF00);
64 test__fixsfti(0x1.FFFFFEp+30, 0x7FFFFF80);
65 test__fixsfti(0x1.FFFFFFp+30, 0x80000000);
66 test__fixsfti(0x1.000000p+31, 0x80000000);
63 try test__fixsfti(0x1.FFFFFCp+30, 0x7FFFFF00);
64 try test__fixsfti(0x1.FFFFFEp+30, 0x7FFFFF80);
65 try test__fixsfti(0x1.FFFFFFp+30, 0x80000000);
66 try test__fixsfti(0x1.000000p+31, 0x80000000);
6767
68 test__fixsfti(0x1.FFFFFCp+62, 0x7FFFFF0000000000);
69 test__fixsfti(0x1.FFFFFEp+62, 0x7FFFFF8000000000);
70 test__fixsfti(0x1.FFFFFFp+62, 0x8000000000000000);
68 try test__fixsfti(0x1.FFFFFCp+62, 0x7FFFFF0000000000);
69 try test__fixsfti(0x1.FFFFFEp+62, 0x7FFFFF8000000000);
70 try test__fixsfti(0x1.FFFFFFp+62, 0x8000000000000000);
7171
72 test__fixsfti(0x1.FFFFFFFFFFFFEp+62, 0x8000000000000000);
73 test__fixsfti(0x1.FFFFFFFFFFFFFp+62, 0x8000000000000000);
74 test__fixsfti(0x1.0000000000000p+63, 0x8000000000000000);
75 test__fixsfti(0x1.0000000000001p+63, 0x8000000000000000);
72 try test__fixsfti(0x1.FFFFFFFFFFFFEp+62, 0x8000000000000000);
73 try test__fixsfti(0x1.FFFFFFFFFFFFFp+62, 0x8000000000000000);
74 try test__fixsfti(0x1.0000000000000p+63, 0x8000000000000000);
75 try test__fixsfti(0x1.0000000000001p+63, 0x8000000000000000);
7676
77 test__fixsfti(0x1.FFFFFC0000000p+126, 0x7FFFFF00000000000000000000000000);
78 test__fixsfti(0x1.FFFFFE0000000p+126, 0x7FFFFF80000000000000000000000000);
79 test__fixsfti(0x1.FFFFFF0000000p+126, 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF);
80 test__fixsfti(0x1.FFFFFFFFFFFFEp+126, 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF);
81 test__fixsfti(0x1.FFFFFFFFFFFFFp+126, 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF);
82 test__fixsfti(0x1.0000000000000p+127, 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF);
77 try test__fixsfti(0x1.FFFFFC0000000p+126, 0x7FFFFF00000000000000000000000000);
78 try test__fixsfti(0x1.FFFFFE0000000p+126, 0x7FFFFF80000000000000000000000000);
79 try test__fixsfti(0x1.FFFFFF0000000p+126, 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF);
80 try test__fixsfti(0x1.FFFFFFFFFFFFEp+126, 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF);
81 try test__fixsfti(0x1.FFFFFFFFFFFFFp+126, 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF);
82 try test__fixsfti(0x1.0000000000000p+127, 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF);
8383
84 test__fixsfti(0x1.FFFFFFFFFFFFFp+1023, 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF);
85 test__fixsfti(0x1.FFFFFFFFFFFFFp+1023, math.maxInt(i128));
84 try test__fixsfti(0x1.FFFFFFFFFFFFFp+1023, 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF);
85 try test__fixsfti(0x1.FFFFFFFFFFFFFp+1023, math.maxInt(i128));
8686
87 test__fixsfti(math.f32_max, math.maxInt(i128));
87 try test__fixsfti(math.f32_max, math.maxInt(i128));
8888}
lib/std/special/compiler_rt/fixtfdi_test.zig+50-50
......@@ -9,72 +9,72 @@ const math = std.math;
99const testing = std.testing;
1010const warn = std.debug.warn;
1111
12fn test__fixtfdi(a: f128, expected: i64) void {
12fn test__fixtfdi(a: f128, expected: i64) !void {
1313 const x = __fixtfdi(a);
1414 //warn("a={}:{x} x={}:{x} expected={}:{x}:@as(u64, {x})\n", .{a, @bitCast(u128, a), x, x, expected, expected, @bitCast(u64, expected)});
15 testing.expect(x == expected);
15 try testing.expect(x == expected);
1616}
1717
1818test "fixtfdi" {
1919 //warn("\n", .{});
20 test__fixtfdi(-math.f128_max, math.minInt(i64));
20 try test__fixtfdi(-math.f128_max, math.minInt(i64));
2121
22 test__fixtfdi(-0x1.FFFFFFFFFFFFFp+1023, math.minInt(i64));
23 test__fixtfdi(-0x1.FFFFFFFFFFFFFp+1023, -0x8000000000000000);
22 try test__fixtfdi(-0x1.FFFFFFFFFFFFFp+1023, math.minInt(i64));
23 try test__fixtfdi(-0x1.FFFFFFFFFFFFFp+1023, -0x8000000000000000);
2424
25 test__fixtfdi(-0x1.0000000000000p+127, -0x8000000000000000);
26 test__fixtfdi(-0x1.FFFFFFFFFFFFFp+126, -0x8000000000000000);
27 test__fixtfdi(-0x1.FFFFFFFFFFFFEp+126, -0x8000000000000000);
25 try test__fixtfdi(-0x1.0000000000000p+127, -0x8000000000000000);
26 try test__fixtfdi(-0x1.FFFFFFFFFFFFFp+126, -0x8000000000000000);
27 try test__fixtfdi(-0x1.FFFFFFFFFFFFEp+126, -0x8000000000000000);
2828
29 test__fixtfdi(-0x1.0000000000001p+63, -0x8000000000000000);
30 test__fixtfdi(-0x1.0000000000000p+63, -0x8000000000000000);
31 test__fixtfdi(-0x1.FFFFFFFFFFFFFp+62, -0x7FFFFFFFFFFFFC00);
32 test__fixtfdi(-0x1.FFFFFFFFFFFFEp+62, -0x7FFFFFFFFFFFF800);
29 try test__fixtfdi(-0x1.0000000000001p+63, -0x8000000000000000);
30 try test__fixtfdi(-0x1.0000000000000p+63, -0x8000000000000000);
31 try test__fixtfdi(-0x1.FFFFFFFFFFFFFp+62, -0x7FFFFFFFFFFFFC00);
32 try test__fixtfdi(-0x1.FFFFFFFFFFFFEp+62, -0x7FFFFFFFFFFFF800);
3333
34 test__fixtfdi(-0x1.FFFFFEp+62, -0x7FFFFF8000000000);
35 test__fixtfdi(-0x1.FFFFFCp+62, -0x7FFFFF0000000000);
34 try test__fixtfdi(-0x1.FFFFFEp+62, -0x7FFFFF8000000000);
35 try test__fixtfdi(-0x1.FFFFFCp+62, -0x7FFFFF0000000000);
3636
37 test__fixtfdi(-0x1.000000p+31, -0x80000000);
38 test__fixtfdi(-0x1.FFFFFFp+30, -0x7FFFFFC0);
39 test__fixtfdi(-0x1.FFFFFEp+30, -0x7FFFFF80);
40 test__fixtfdi(-0x1.FFFFFCp+30, -0x7FFFFF00);
37 try test__fixtfdi(-0x1.000000p+31, -0x80000000);
38 try test__fixtfdi(-0x1.FFFFFFp+30, -0x7FFFFFC0);
39 try test__fixtfdi(-0x1.FFFFFEp+30, -0x7FFFFF80);
40 try test__fixtfdi(-0x1.FFFFFCp+30, -0x7FFFFF00);
4141
42 test__fixtfdi(-2.01, -2);
43 test__fixtfdi(-2.0, -2);
44 test__fixtfdi(-1.99, -1);
45 test__fixtfdi(-1.0, -1);
46 test__fixtfdi(-0.99, 0);
47 test__fixtfdi(-0.5, 0);
48 test__fixtfdi(-math.f64_min, 0);
49 test__fixtfdi(0.0, 0);
50 test__fixtfdi(math.f64_min, 0);
51 test__fixtfdi(0.5, 0);
52 test__fixtfdi(0.99, 0);
53 test__fixtfdi(1.0, 1);
54 test__fixtfdi(1.5, 1);
55 test__fixtfdi(1.99, 1);
56 test__fixtfdi(2.0, 2);
57 test__fixtfdi(2.01, 2);
42 try test__fixtfdi(-2.01, -2);
43 try test__fixtfdi(-2.0, -2);
44 try test__fixtfdi(-1.99, -1);
45 try test__fixtfdi(-1.0, -1);
46 try test__fixtfdi(-0.99, 0);
47 try test__fixtfdi(-0.5, 0);
48 try test__fixtfdi(-math.f64_min, 0);
49 try test__fixtfdi(0.0, 0);
50 try test__fixtfdi(math.f64_min, 0);
51 try test__fixtfdi(0.5, 0);
52 try test__fixtfdi(0.99, 0);
53 try test__fixtfdi(1.0, 1);
54 try test__fixtfdi(1.5, 1);
55 try test__fixtfdi(1.99, 1);
56 try test__fixtfdi(2.0, 2);
57 try test__fixtfdi(2.01, 2);
5858
59 test__fixtfdi(0x1.FFFFFCp+30, 0x7FFFFF00);
60 test__fixtfdi(0x1.FFFFFEp+30, 0x7FFFFF80);
61 test__fixtfdi(0x1.FFFFFFp+30, 0x7FFFFFC0);
62 test__fixtfdi(0x1.000000p+31, 0x80000000);
59 try test__fixtfdi(0x1.FFFFFCp+30, 0x7FFFFF00);
60 try test__fixtfdi(0x1.FFFFFEp+30, 0x7FFFFF80);
61 try test__fixtfdi(0x1.FFFFFFp+30, 0x7FFFFFC0);
62 try test__fixtfdi(0x1.000000p+31, 0x80000000);
6363
64 test__fixtfdi(0x1.FFFFFCp+62, 0x7FFFFF0000000000);
65 test__fixtfdi(0x1.FFFFFEp+62, 0x7FFFFF8000000000);
64 try test__fixtfdi(0x1.FFFFFCp+62, 0x7FFFFF0000000000);
65 try test__fixtfdi(0x1.FFFFFEp+62, 0x7FFFFF8000000000);
6666
67 test__fixtfdi(0x1.FFFFFFFFFFFFEp+62, 0x7FFFFFFFFFFFF800);
68 test__fixtfdi(0x1.FFFFFFFFFFFFFp+62, 0x7FFFFFFFFFFFFC00);
69 test__fixtfdi(0x1.0000000000000p+63, 0x7FFFFFFFFFFFFFFF);
70 test__fixtfdi(0x1.0000000000001p+63, 0x7FFFFFFFFFFFFFFF);
67 try test__fixtfdi(0x1.FFFFFFFFFFFFEp+62, 0x7FFFFFFFFFFFF800);
68 try test__fixtfdi(0x1.FFFFFFFFFFFFFp+62, 0x7FFFFFFFFFFFFC00);
69 try test__fixtfdi(0x1.0000000000000p+63, 0x7FFFFFFFFFFFFFFF);
70 try test__fixtfdi(0x1.0000000000001p+63, 0x7FFFFFFFFFFFFFFF);
7171
72 test__fixtfdi(0x1.FFFFFFFFFFFFEp+126, 0x7FFFFFFFFFFFFFFF);
73 test__fixtfdi(0x1.FFFFFFFFFFFFFp+126, 0x7FFFFFFFFFFFFFFF);
74 test__fixtfdi(0x1.0000000000000p+127, 0x7FFFFFFFFFFFFFFF);
72 try test__fixtfdi(0x1.FFFFFFFFFFFFEp+126, 0x7FFFFFFFFFFFFFFF);
73 try test__fixtfdi(0x1.FFFFFFFFFFFFFp+126, 0x7FFFFFFFFFFFFFFF);
74 try test__fixtfdi(0x1.0000000000000p+127, 0x7FFFFFFFFFFFFFFF);
7575
76 test__fixtfdi(0x1.FFFFFFFFFFFFFp+1023, 0x7FFFFFFFFFFFFFFF);
77 test__fixtfdi(0x1.FFFFFFFFFFFFFp+1023, math.maxInt(i64));
76 try test__fixtfdi(0x1.FFFFFFFFFFFFFp+1023, 0x7FFFFFFFFFFFFFFF);
77 try test__fixtfdi(0x1.FFFFFFFFFFFFFp+1023, math.maxInt(i64));
7878
79 test__fixtfdi(math.f128_max, math.maxInt(i64));
79 try test__fixtfdi(math.f128_max, math.maxInt(i64));
8080}
lib/std/special/compiler_rt/fixtfsi_test.zig+50-50
......@@ -9,72 +9,72 @@ const math = std.math;
99const testing = std.testing;
1010const warn = std.debug.warn;
1111
12fn test__fixtfsi(a: f128, expected: i32) void {
12fn test__fixtfsi(a: f128, expected: i32) !void {
1313 const x = __fixtfsi(a);
1414 //warn("a={}:{x} x={}:{x} expected={}:{x}:@as(u32, {x})\n", .{a, @bitCast(u128, a), x, x, expected, expected, @bitCast(u32, expected)});
15 testing.expect(x == expected);
15 try testing.expect(x == expected);
1616}
1717
1818test "fixtfsi" {
1919 //warn("\n", .{});
20 test__fixtfsi(-math.f128_max, math.minInt(i32));
20 try test__fixtfsi(-math.f128_max, math.minInt(i32));
2121
22 test__fixtfsi(-0x1.FFFFFFFFFFFFFp+1023, math.minInt(i32));
23 test__fixtfsi(-0x1.FFFFFFFFFFFFFp+1023, -0x80000000);
22 try test__fixtfsi(-0x1.FFFFFFFFFFFFFp+1023, math.minInt(i32));
23 try test__fixtfsi(-0x1.FFFFFFFFFFFFFp+1023, -0x80000000);
2424
25 test__fixtfsi(-0x1.0000000000000p+127, -0x80000000);
26 test__fixtfsi(-0x1.FFFFFFFFFFFFFp+126, -0x80000000);
27 test__fixtfsi(-0x1.FFFFFFFFFFFFEp+126, -0x80000000);
25 try test__fixtfsi(-0x1.0000000000000p+127, -0x80000000);
26 try test__fixtfsi(-0x1.FFFFFFFFFFFFFp+126, -0x80000000);
27 try test__fixtfsi(-0x1.FFFFFFFFFFFFEp+126, -0x80000000);
2828
29 test__fixtfsi(-0x1.0000000000001p+63, -0x80000000);
30 test__fixtfsi(-0x1.0000000000000p+63, -0x80000000);
31 test__fixtfsi(-0x1.FFFFFFFFFFFFFp+62, -0x80000000);
32 test__fixtfsi(-0x1.FFFFFFFFFFFFEp+62, -0x80000000);
29 try test__fixtfsi(-0x1.0000000000001p+63, -0x80000000);
30 try test__fixtfsi(-0x1.0000000000000p+63, -0x80000000);
31 try test__fixtfsi(-0x1.FFFFFFFFFFFFFp+62, -0x80000000);
32 try test__fixtfsi(-0x1.FFFFFFFFFFFFEp+62, -0x80000000);
3333
34 test__fixtfsi(-0x1.FFFFFEp+62, -0x80000000);
35 test__fixtfsi(-0x1.FFFFFCp+62, -0x80000000);
34 try test__fixtfsi(-0x1.FFFFFEp+62, -0x80000000);
35 try test__fixtfsi(-0x1.FFFFFCp+62, -0x80000000);
3636
37 test__fixtfsi(-0x1.000000p+31, -0x80000000);
38 test__fixtfsi(-0x1.FFFFFFp+30, -0x7FFFFFC0);
39 test__fixtfsi(-0x1.FFFFFEp+30, -0x7FFFFF80);
40 test__fixtfsi(-0x1.FFFFFCp+30, -0x7FFFFF00);
37 try test__fixtfsi(-0x1.000000p+31, -0x80000000);
38 try test__fixtfsi(-0x1.FFFFFFp+30, -0x7FFFFFC0);
39 try test__fixtfsi(-0x1.FFFFFEp+30, -0x7FFFFF80);
40 try test__fixtfsi(-0x1.FFFFFCp+30, -0x7FFFFF00);
4141
42 test__fixtfsi(-2.01, -2);
43 test__fixtfsi(-2.0, -2);
44 test__fixtfsi(-1.99, -1);
45 test__fixtfsi(-1.0, -1);
46 test__fixtfsi(-0.99, 0);
47 test__fixtfsi(-0.5, 0);
48 test__fixtfsi(-math.f32_min, 0);
49 test__fixtfsi(0.0, 0);
50 test__fixtfsi(math.f32_min, 0);
51 test__fixtfsi(0.5, 0);
52 test__fixtfsi(0.99, 0);
53 test__fixtfsi(1.0, 1);
54 test__fixtfsi(1.5, 1);
55 test__fixtfsi(1.99, 1);
56 test__fixtfsi(2.0, 2);
57 test__fixtfsi(2.01, 2);
42 try test__fixtfsi(-2.01, -2);
43 try test__fixtfsi(-2.0, -2);
44 try test__fixtfsi(-1.99, -1);
45 try test__fixtfsi(-1.0, -1);
46 try test__fixtfsi(-0.99, 0);
47 try test__fixtfsi(-0.5, 0);
48 try test__fixtfsi(-math.f32_min, 0);
49 try test__fixtfsi(0.0, 0);
50 try test__fixtfsi(math.f32_min, 0);
51 try test__fixtfsi(0.5, 0);
52 try test__fixtfsi(0.99, 0);
53 try test__fixtfsi(1.0, 1);
54 try test__fixtfsi(1.5, 1);
55 try test__fixtfsi(1.99, 1);
56 try test__fixtfsi(2.0, 2);
57 try test__fixtfsi(2.01, 2);
5858
59 test__fixtfsi(0x1.FFFFFCp+30, 0x7FFFFF00);
60 test__fixtfsi(0x1.FFFFFEp+30, 0x7FFFFF80);
61 test__fixtfsi(0x1.FFFFFFp+30, 0x7FFFFFC0);
62 test__fixtfsi(0x1.000000p+31, 0x7FFFFFFF);
59 try test__fixtfsi(0x1.FFFFFCp+30, 0x7FFFFF00);
60 try test__fixtfsi(0x1.FFFFFEp+30, 0x7FFFFF80);
61 try test__fixtfsi(0x1.FFFFFFp+30, 0x7FFFFFC0);
62 try test__fixtfsi(0x1.000000p+31, 0x7FFFFFFF);
6363
64 test__fixtfsi(0x1.FFFFFCp+62, 0x7FFFFFFF);
65 test__fixtfsi(0x1.FFFFFEp+62, 0x7FFFFFFF);
64 try test__fixtfsi(0x1.FFFFFCp+62, 0x7FFFFFFF);
65 try test__fixtfsi(0x1.FFFFFEp+62, 0x7FFFFFFF);
6666
67 test__fixtfsi(0x1.FFFFFFFFFFFFEp+62, 0x7FFFFFFF);
68 test__fixtfsi(0x1.FFFFFFFFFFFFFp+62, 0x7FFFFFFF);
69 test__fixtfsi(0x1.0000000000000p+63, 0x7FFFFFFF);
70 test__fixtfsi(0x1.0000000000001p+63, 0x7FFFFFFF);
67 try test__fixtfsi(0x1.FFFFFFFFFFFFEp+62, 0x7FFFFFFF);
68 try test__fixtfsi(0x1.FFFFFFFFFFFFFp+62, 0x7FFFFFFF);
69 try test__fixtfsi(0x1.0000000000000p+63, 0x7FFFFFFF);
70 try test__fixtfsi(0x1.0000000000001p+63, 0x7FFFFFFF);
7171
72 test__fixtfsi(0x1.FFFFFFFFFFFFEp+126, 0x7FFFFFFF);
73 test__fixtfsi(0x1.FFFFFFFFFFFFFp+126, 0x7FFFFFFF);
74 test__fixtfsi(0x1.0000000000000p+127, 0x7FFFFFFF);
72 try test__fixtfsi(0x1.FFFFFFFFFFFFEp+126, 0x7FFFFFFF);
73 try test__fixtfsi(0x1.FFFFFFFFFFFFFp+126, 0x7FFFFFFF);
74 try test__fixtfsi(0x1.0000000000000p+127, 0x7FFFFFFF);
7575
76 test__fixtfsi(0x1.FFFFFFFFFFFFFp+1023, 0x7FFFFFFF);
77 test__fixtfsi(0x1.FFFFFFFFFFFFFp+1023, math.maxInt(i32));
76 try test__fixtfsi(0x1.FFFFFFFFFFFFFp+1023, 0x7FFFFFFF);
77 try test__fixtfsi(0x1.FFFFFFFFFFFFFp+1023, math.maxInt(i32));
7878
79 test__fixtfsi(math.f128_max, math.maxInt(i32));
79 try test__fixtfsi(math.f128_max, math.maxInt(i32));
8080}
lib/std/special/compiler_rt/fixtfti_test.zig+42-42
......@@ -9,62 +9,62 @@ const math = std.math;
99const testing = std.testing;
1010const warn = std.debug.warn;
1111
12fn test__fixtfti(a: f128, expected: i128) void {
12fn test__fixtfti(a: f128, expected: i128) !void {
1313 const x = __fixtfti(a);
1414 //warn("a={}:{x} x={}:{x} expected={}:{x}:@as(u128, {x})\n", .{a, @bitCast(u128, a), x, x, expected, expected, @bitCast(u128, expected)});
15 testing.expect(x == expected);
15 try testing.expect(x == expected);
1616}
1717
1818test "fixtfti" {
1919 //warn("\n", .{});
20 test__fixtfti(-math.f128_max, math.minInt(i128));
20 try test__fixtfti(-math.f128_max, math.minInt(i128));
2121
22 test__fixtfti(-0x1.FFFFFFFFFFFFFp+1023, math.minInt(i128));
23 test__fixtfti(-0x1.FFFFFFFFFFFFFp+1023, -0x80000000000000000000000000000000);
22 try test__fixtfti(-0x1.FFFFFFFFFFFFFp+1023, math.minInt(i128));
23 try test__fixtfti(-0x1.FFFFFFFFFFFFFp+1023, -0x80000000000000000000000000000000);
2424
25 test__fixtfti(-0x1.0000000000000p+127, -0x80000000000000000000000000000000);
26 test__fixtfti(-0x1.FFFFFFFFFFFFFp+126, -0x7FFFFFFFFFFFFC000000000000000000);
27 test__fixtfti(-0x1.FFFFFFFFFFFFEp+126, -0x7FFFFFFFFFFFF8000000000000000000);
25 try test__fixtfti(-0x1.0000000000000p+127, -0x80000000000000000000000000000000);
26 try test__fixtfti(-0x1.FFFFFFFFFFFFFp+126, -0x7FFFFFFFFFFFFC000000000000000000);
27 try test__fixtfti(-0x1.FFFFFFFFFFFFEp+126, -0x7FFFFFFFFFFFF8000000000000000000);
2828
29 test__fixtfti(-0x1.0000000000001p+63, -0x8000000000000800);
30 test__fixtfti(-0x1.0000000000000p+63, -0x8000000000000000);
31 test__fixtfti(-0x1.FFFFFFFFFFFFFp+62, -0x7FFFFFFFFFFFFC00);
32 test__fixtfti(-0x1.FFFFFFFFFFFFEp+62, -0x7FFFFFFFFFFFF800);
29 try test__fixtfti(-0x1.0000000000001p+63, -0x8000000000000800);
30 try test__fixtfti(-0x1.0000000000000p+63, -0x8000000000000000);
31 try test__fixtfti(-0x1.FFFFFFFFFFFFFp+62, -0x7FFFFFFFFFFFFC00);
32 try test__fixtfti(-0x1.FFFFFFFFFFFFEp+62, -0x7FFFFFFFFFFFF800);
3333
34 test__fixtfti(-0x1.FFFFFEp+62, -0x7fffff8000000000);
35 test__fixtfti(-0x1.FFFFFCp+62, -0x7fffff0000000000);
34 try test__fixtfti(-0x1.FFFFFEp+62, -0x7fffff8000000000);
35 try test__fixtfti(-0x1.FFFFFCp+62, -0x7fffff0000000000);
3636
37 test__fixtfti(-2.01, -2);
38 test__fixtfti(-2.0, -2);
39 test__fixtfti(-1.99, -1);
40 test__fixtfti(-1.0, -1);
41 test__fixtfti(-0.99, 0);
42 test__fixtfti(-0.5, 0);
43 test__fixtfti(-math.f128_min, 0);
44 test__fixtfti(0.0, 0);
45 test__fixtfti(math.f128_min, 0);
46 test__fixtfti(0.5, 0);
47 test__fixtfti(0.99, 0);
48 test__fixtfti(1.0, 1);
49 test__fixtfti(1.5, 1);
50 test__fixtfti(1.99, 1);
51 test__fixtfti(2.0, 2);
52 test__fixtfti(2.01, 2);
37 try test__fixtfti(-2.01, -2);
38 try test__fixtfti(-2.0, -2);
39 try test__fixtfti(-1.99, -1);
40 try test__fixtfti(-1.0, -1);
41 try test__fixtfti(-0.99, 0);
42 try test__fixtfti(-0.5, 0);
43 try test__fixtfti(-math.f128_min, 0);
44 try test__fixtfti(0.0, 0);
45 try test__fixtfti(math.f128_min, 0);
46 try test__fixtfti(0.5, 0);
47 try test__fixtfti(0.99, 0);
48 try test__fixtfti(1.0, 1);
49 try test__fixtfti(1.5, 1);
50 try test__fixtfti(1.99, 1);
51 try test__fixtfti(2.0, 2);
52 try test__fixtfti(2.01, 2);
5353
54 test__fixtfti(0x1.FFFFFCp+62, 0x7FFFFF0000000000);
55 test__fixtfti(0x1.FFFFFEp+62, 0x7FFFFF8000000000);
54 try test__fixtfti(0x1.FFFFFCp+62, 0x7FFFFF0000000000);
55 try test__fixtfti(0x1.FFFFFEp+62, 0x7FFFFF8000000000);
5656
57 test__fixtfti(0x1.FFFFFFFFFFFFEp+62, 0x7FFFFFFFFFFFF800);
58 test__fixtfti(0x1.FFFFFFFFFFFFFp+62, 0x7FFFFFFFFFFFFC00);
59 test__fixtfti(0x1.0000000000000p+63, 0x8000000000000000);
60 test__fixtfti(0x1.0000000000001p+63, 0x8000000000000800);
57 try test__fixtfti(0x1.FFFFFFFFFFFFEp+62, 0x7FFFFFFFFFFFF800);
58 try test__fixtfti(0x1.FFFFFFFFFFFFFp+62, 0x7FFFFFFFFFFFFC00);
59 try test__fixtfti(0x1.0000000000000p+63, 0x8000000000000000);
60 try test__fixtfti(0x1.0000000000001p+63, 0x8000000000000800);
6161
62 test__fixtfti(0x1.FFFFFFFFFFFFEp+126, 0x7FFFFFFFFFFFF8000000000000000000);
63 test__fixtfti(0x1.FFFFFFFFFFFFFp+126, 0x7FFFFFFFFFFFFC000000000000000000);
64 test__fixtfti(0x1.0000000000000p+127, 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF);
62 try test__fixtfti(0x1.FFFFFFFFFFFFEp+126, 0x7FFFFFFFFFFFF8000000000000000000);
63 try test__fixtfti(0x1.FFFFFFFFFFFFFp+126, 0x7FFFFFFFFFFFFC000000000000000000);
64 try test__fixtfti(0x1.0000000000000p+127, 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF);
6565
66 test__fixtfti(0x1.FFFFFFFFFFFFFp+1023, 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF);
67 test__fixtfti(0x1.FFFFFFFFFFFFFp+1023, math.maxInt(i128));
66 try test__fixtfti(0x1.FFFFFFFFFFFFFp+1023, 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF);
67 try test__fixtfti(0x1.FFFFFFFFFFFFFp+1023, math.maxInt(i128));
6868
69 test__fixtfti(math.f128_max, math.maxInt(i128));
69 try test__fixtfti(math.f128_max, math.maxInt(i128));
7070}
lib/std/special/compiler_rt/fixunsdfdi_test.zig+24-24
......@@ -6,39 +6,39 @@
66const __fixunsdfdi = @import("fixunsdfdi.zig").__fixunsdfdi;
77const testing = @import("std").testing;
88
9fn test__fixunsdfdi(a: f64, expected: u64) void {
9fn test__fixunsdfdi(a: f64, expected: u64) !void {
1010 const x = __fixunsdfdi(a);
11 testing.expect(x == expected);
11 try testing.expect(x == expected);
1212}
1313
1414test "fixunsdfdi" {
1515 //test__fixunsdfdi(0.0, 0);
1616 //test__fixunsdfdi(0.5, 0);
1717 //test__fixunsdfdi(0.99, 0);
18 test__fixunsdfdi(1.0, 1);
19 test__fixunsdfdi(1.5, 1);
20 test__fixunsdfdi(1.99, 1);
21 test__fixunsdfdi(2.0, 2);
22 test__fixunsdfdi(2.01, 2);
23 test__fixunsdfdi(-0.5, 0);
24 test__fixunsdfdi(-0.99, 0);
25 test__fixunsdfdi(-1.0, 0);
26 test__fixunsdfdi(-1.5, 0);
27 test__fixunsdfdi(-1.99, 0);
28 test__fixunsdfdi(-2.0, 0);
29 test__fixunsdfdi(-2.01, 0);
18 try test__fixunsdfdi(1.0, 1);
19 try test__fixunsdfdi(1.5, 1);
20 try test__fixunsdfdi(1.99, 1);
21 try test__fixunsdfdi(2.0, 2);
22 try test__fixunsdfdi(2.01, 2);
23 try test__fixunsdfdi(-0.5, 0);
24 try test__fixunsdfdi(-0.99, 0);
25 try test__fixunsdfdi(-1.0, 0);
26 try test__fixunsdfdi(-1.5, 0);
27 try test__fixunsdfdi(-1.99, 0);
28 try test__fixunsdfdi(-2.0, 0);
29 try test__fixunsdfdi(-2.01, 0);
3030
31 test__fixunsdfdi(0x1.FFFFFEp+62, 0x7FFFFF8000000000);
32 test__fixunsdfdi(0x1.FFFFFCp+62, 0x7FFFFF0000000000);
31 try test__fixunsdfdi(0x1.FFFFFEp+62, 0x7FFFFF8000000000);
32 try test__fixunsdfdi(0x1.FFFFFCp+62, 0x7FFFFF0000000000);
3333
34 test__fixunsdfdi(-0x1.FFFFFEp+62, 0);
35 test__fixunsdfdi(-0x1.FFFFFCp+62, 0);
34 try test__fixunsdfdi(-0x1.FFFFFEp+62, 0);
35 try test__fixunsdfdi(-0x1.FFFFFCp+62, 0);
3636
37 test__fixunsdfdi(0x1.FFFFFFFFFFFFFp+63, 0xFFFFFFFFFFFFF800);
38 test__fixunsdfdi(0x1.0000000000000p+63, 0x8000000000000000);
39 test__fixunsdfdi(0x1.FFFFFFFFFFFFFp+62, 0x7FFFFFFFFFFFFC00);
40 test__fixunsdfdi(0x1.FFFFFFFFFFFFEp+62, 0x7FFFFFFFFFFFF800);
37 try test__fixunsdfdi(0x1.FFFFFFFFFFFFFp+63, 0xFFFFFFFFFFFFF800);
38 try test__fixunsdfdi(0x1.0000000000000p+63, 0x8000000000000000);
39 try test__fixunsdfdi(0x1.FFFFFFFFFFFFFp+62, 0x7FFFFFFFFFFFFC00);
40 try test__fixunsdfdi(0x1.FFFFFFFFFFFFEp+62, 0x7FFFFFFFFFFFF800);
4141
42 test__fixunsdfdi(-0x1.FFFFFFFFFFFFFp+62, 0);
43 test__fixunsdfdi(-0x1.FFFFFFFFFFFFEp+62, 0);
42 try test__fixunsdfdi(-0x1.FFFFFFFFFFFFFp+62, 0);
43 try test__fixunsdfdi(-0x1.FFFFFFFFFFFFEp+62, 0);
4444}
lib/std/special/compiler_rt/fixunsdfsi_test.zig+27-27
......@@ -6,39 +6,39 @@
66const __fixunsdfsi = @import("fixunsdfsi.zig").__fixunsdfsi;
77const testing = @import("std").testing;
88
9fn test__fixunsdfsi(a: f64, expected: u32) void {
9fn test__fixunsdfsi(a: f64, expected: u32) !void {
1010 const x = __fixunsdfsi(a);
11 testing.expect(x == expected);
11 try testing.expect(x == expected);
1212}
1313
1414test "fixunsdfsi" {
15 test__fixunsdfsi(0.0, 0);
15 try test__fixunsdfsi(0.0, 0);
1616
17 test__fixunsdfsi(0.5, 0);
18 test__fixunsdfsi(0.99, 0);
19 test__fixunsdfsi(1.0, 1);
20 test__fixunsdfsi(1.5, 1);
21 test__fixunsdfsi(1.99, 1);
22 test__fixunsdfsi(2.0, 2);
23 test__fixunsdfsi(2.01, 2);
24 test__fixunsdfsi(-0.5, 0);
25 test__fixunsdfsi(-0.99, 0);
26 test__fixunsdfsi(-1.0, 0);
27 test__fixunsdfsi(-1.5, 0);
28 test__fixunsdfsi(-1.99, 0);
29 test__fixunsdfsi(-2.0, 0);
30 test__fixunsdfsi(-2.01, 0);
17 try test__fixunsdfsi(0.5, 0);
18 try test__fixunsdfsi(0.99, 0);
19 try test__fixunsdfsi(1.0, 1);
20 try test__fixunsdfsi(1.5, 1);
21 try test__fixunsdfsi(1.99, 1);
22 try test__fixunsdfsi(2.0, 2);
23 try test__fixunsdfsi(2.01, 2);
24 try test__fixunsdfsi(-0.5, 0);
25 try test__fixunsdfsi(-0.99, 0);
26 try test__fixunsdfsi(-1.0, 0);
27 try test__fixunsdfsi(-1.5, 0);
28 try test__fixunsdfsi(-1.99, 0);
29 try test__fixunsdfsi(-2.0, 0);
30 try test__fixunsdfsi(-2.01, 0);
3131
32 test__fixunsdfsi(0x1.000000p+31, 0x80000000);
33 test__fixunsdfsi(0x1.000000p+32, 0xFFFFFFFF);
34 test__fixunsdfsi(0x1.FFFFFEp+31, 0xFFFFFF00);
35 test__fixunsdfsi(0x1.FFFFFEp+30, 0x7FFFFF80);
36 test__fixunsdfsi(0x1.FFFFFCp+30, 0x7FFFFF00);
32 try test__fixunsdfsi(0x1.000000p+31, 0x80000000);
33 try test__fixunsdfsi(0x1.000000p+32, 0xFFFFFFFF);
34 try test__fixunsdfsi(0x1.FFFFFEp+31, 0xFFFFFF00);
35 try test__fixunsdfsi(0x1.FFFFFEp+30, 0x7FFFFF80);
36 try test__fixunsdfsi(0x1.FFFFFCp+30, 0x7FFFFF00);
3737
38 test__fixunsdfsi(-0x1.FFFFFEp+30, 0);
39 test__fixunsdfsi(-0x1.FFFFFCp+30, 0);
38 try test__fixunsdfsi(-0x1.FFFFFEp+30, 0);
39 try test__fixunsdfsi(-0x1.FFFFFCp+30, 0);
4040
41 test__fixunsdfsi(0x1.FFFFFFFEp+31, 0xFFFFFFFF);
42 test__fixunsdfsi(0x1.FFFFFFFC00000p+30, 0x7FFFFFFF);
43 test__fixunsdfsi(0x1.FFFFFFF800000p+30, 0x7FFFFFFE);
41 try test__fixunsdfsi(0x1.FFFFFFFEp+31, 0xFFFFFFFF);
42 try test__fixunsdfsi(0x1.FFFFFFFC00000p+30, 0x7FFFFFFF);
43 try test__fixunsdfsi(0x1.FFFFFFF800000p+30, 0x7FFFFFFE);
4444}
lib/std/special/compiler_rt/fixunsdfti_test.zig+38-38
......@@ -6,46 +6,46 @@
66const __fixunsdfti = @import("fixunsdfti.zig").__fixunsdfti;
77const testing = @import("std").testing;
88
9fn test__fixunsdfti(a: f64, expected: u128) void {
9fn test__fixunsdfti(a: f64, expected: u128) !void {
1010 const x = __fixunsdfti(a);
11 testing.expect(x == expected);
11 try testing.expect(x == expected);
1212}
1313
1414test "fixunsdfti" {
15 test__fixunsdfti(0.0, 0);
16
17 test__fixunsdfti(0.5, 0);
18 test__fixunsdfti(0.99, 0);
19 test__fixunsdfti(1.0, 1);
20 test__fixunsdfti(1.5, 1);
21 test__fixunsdfti(1.99, 1);
22 test__fixunsdfti(2.0, 2);
23 test__fixunsdfti(2.01, 2);
24 test__fixunsdfti(-0.5, 0);
25 test__fixunsdfti(-0.99, 0);
26 test__fixunsdfti(-1.0, 0);
27 test__fixunsdfti(-1.5, 0);
28 test__fixunsdfti(-1.99, 0);
29 test__fixunsdfti(-2.0, 0);
30 test__fixunsdfti(-2.01, 0);
31
32 test__fixunsdfti(0x1.FFFFFEp+62, 0x7FFFFF8000000000);
33 test__fixunsdfti(0x1.FFFFFCp+62, 0x7FFFFF0000000000);
34
35 test__fixunsdfti(-0x1.FFFFFEp+62, 0);
36 test__fixunsdfti(-0x1.FFFFFCp+62, 0);
37
38 test__fixunsdfti(0x1.FFFFFFFFFFFFFp+63, 0xFFFFFFFFFFFFF800);
39 test__fixunsdfti(0x1.0000000000000p+63, 0x8000000000000000);
40 test__fixunsdfti(0x1.FFFFFFFFFFFFFp+62, 0x7FFFFFFFFFFFFC00);
41 test__fixunsdfti(0x1.FFFFFFFFFFFFEp+62, 0x7FFFFFFFFFFFF800);
42
43 test__fixunsdfti(0x1.FFFFFFFFFFFFFp+127, 0xFFFFFFFFFFFFF8000000000000000000);
44 test__fixunsdfti(0x1.0000000000000p+127, 0x80000000000000000000000000000000);
45 test__fixunsdfti(0x1.FFFFFFFFFFFFFp+126, 0x7FFFFFFFFFFFFC000000000000000000);
46 test__fixunsdfti(0x1.FFFFFFFFFFFFEp+126, 0x7FFFFFFFFFFFF8000000000000000000);
47 test__fixunsdfti(0x1.0000000000000p+128, 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF);
48
49 test__fixunsdfti(-0x1.FFFFFFFFFFFFFp+62, 0);
50 test__fixunsdfti(-0x1.FFFFFFFFFFFFEp+62, 0);
15 try test__fixunsdfti(0.0, 0);
16
17 try test__fixunsdfti(0.5, 0);
18 try test__fixunsdfti(0.99, 0);
19 try test__fixunsdfti(1.0, 1);
20 try test__fixunsdfti(1.5, 1);
21 try test__fixunsdfti(1.99, 1);
22 try test__fixunsdfti(2.0, 2);
23 try test__fixunsdfti(2.01, 2);
24 try test__fixunsdfti(-0.5, 0);
25 try test__fixunsdfti(-0.99, 0);
26 try test__fixunsdfti(-1.0, 0);
27 try test__fixunsdfti(-1.5, 0);
28 try test__fixunsdfti(-1.99, 0);
29 try test__fixunsdfti(-2.0, 0);
30 try test__fixunsdfti(-2.01, 0);
31
32 try test__fixunsdfti(0x1.FFFFFEp+62, 0x7FFFFF8000000000);
33 try test__fixunsdfti(0x1.FFFFFCp+62, 0x7FFFFF0000000000);
34
35 try test__fixunsdfti(-0x1.FFFFFEp+62, 0);
36 try test__fixunsdfti(-0x1.FFFFFCp+62, 0);
37
38 try test__fixunsdfti(0x1.FFFFFFFFFFFFFp+63, 0xFFFFFFFFFFFFF800);
39 try test__fixunsdfti(0x1.0000000000000p+63, 0x8000000000000000);
40 try test__fixunsdfti(0x1.FFFFFFFFFFFFFp+62, 0x7FFFFFFFFFFFFC00);
41 try test__fixunsdfti(0x1.FFFFFFFFFFFFEp+62, 0x7FFFFFFFFFFFF800);
42
43 try test__fixunsdfti(0x1.FFFFFFFFFFFFFp+127, 0xFFFFFFFFFFFFF8000000000000000000);
44 try test__fixunsdfti(0x1.0000000000000p+127, 0x80000000000000000000000000000000);
45 try test__fixunsdfti(0x1.FFFFFFFFFFFFFp+126, 0x7FFFFFFFFFFFFC000000000000000000);
46 try test__fixunsdfti(0x1.FFFFFFFFFFFFEp+126, 0x7FFFFFFFFFFFF8000000000000000000);
47 try test__fixunsdfti(0x1.0000000000000p+128, 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF);
48
49 try test__fixunsdfti(-0x1.FFFFFFFFFFFFFp+62, 0);
50 try test__fixunsdfti(-0x1.FFFFFFFFFFFFEp+62, 0);
5151}
lib/std/special/compiler_rt/fixunssfdi_test.zig+23-23
......@@ -6,35 +6,35 @@
66const __fixunssfdi = @import("fixunssfdi.zig").__fixunssfdi;
77const testing = @import("std").testing;
88
9fn test__fixunssfdi(a: f32, expected: u64) void {
9fn test__fixunssfdi(a: f32, expected: u64) !void {
1010 const x = __fixunssfdi(a);
11 testing.expect(x == expected);
11 try testing.expect(x == expected);
1212}
1313
1414test "fixunssfdi" {
15 test__fixunssfdi(0.0, 0);
15 try test__fixunssfdi(0.0, 0);
1616
17 test__fixunssfdi(0.5, 0);
18 test__fixunssfdi(0.99, 0);
19 test__fixunssfdi(1.0, 1);
20 test__fixunssfdi(1.5, 1);
21 test__fixunssfdi(1.99, 1);
22 test__fixunssfdi(2.0, 2);
23 test__fixunssfdi(2.01, 2);
24 test__fixunssfdi(-0.5, 0);
25 test__fixunssfdi(-0.99, 0);
17 try test__fixunssfdi(0.5, 0);
18 try test__fixunssfdi(0.99, 0);
19 try test__fixunssfdi(1.0, 1);
20 try test__fixunssfdi(1.5, 1);
21 try test__fixunssfdi(1.99, 1);
22 try test__fixunssfdi(2.0, 2);
23 try test__fixunssfdi(2.01, 2);
24 try test__fixunssfdi(-0.5, 0);
25 try test__fixunssfdi(-0.99, 0);
2626
27 test__fixunssfdi(-1.0, 0);
28 test__fixunssfdi(-1.5, 0);
29 test__fixunssfdi(-1.99, 0);
30 test__fixunssfdi(-2.0, 0);
31 test__fixunssfdi(-2.01, 0);
27 try test__fixunssfdi(-1.0, 0);
28 try test__fixunssfdi(-1.5, 0);
29 try test__fixunssfdi(-1.99, 0);
30 try test__fixunssfdi(-2.0, 0);
31 try test__fixunssfdi(-2.01, 0);
3232
33 test__fixunssfdi(0x1.FFFFFEp+63, 0xFFFFFF0000000000);
34 test__fixunssfdi(0x1.000000p+63, 0x8000000000000000);
35 test__fixunssfdi(0x1.FFFFFEp+62, 0x7FFFFF8000000000);
36 test__fixunssfdi(0x1.FFFFFCp+62, 0x7FFFFF0000000000);
33 try test__fixunssfdi(0x1.FFFFFEp+63, 0xFFFFFF0000000000);
34 try test__fixunssfdi(0x1.000000p+63, 0x8000000000000000);
35 try test__fixunssfdi(0x1.FFFFFEp+62, 0x7FFFFF8000000000);
36 try test__fixunssfdi(0x1.FFFFFCp+62, 0x7FFFFF0000000000);
3737
38 test__fixunssfdi(-0x1.FFFFFEp+62, 0x0000000000000000);
39 test__fixunssfdi(-0x1.FFFFFCp+62, 0x0000000000000000);
38 try test__fixunssfdi(-0x1.FFFFFEp+62, 0x0000000000000000);
39 try test__fixunssfdi(-0x1.FFFFFCp+62, 0x0000000000000000);
4040}
lib/std/special/compiler_rt/fixunssfsi_test.zig+24-24
......@@ -6,36 +6,36 @@
66const __fixunssfsi = @import("fixunssfsi.zig").__fixunssfsi;
77const testing = @import("std").testing;
88
9fn test__fixunssfsi(a: f32, expected: u32) void {
9fn test__fixunssfsi(a: f32, expected: u32) !void {
1010 const x = __fixunssfsi(a);
11 testing.expect(x == expected);
11 try testing.expect(x == expected);
1212}
1313
1414test "fixunssfsi" {
15 test__fixunssfsi(0.0, 0);
15 try test__fixunssfsi(0.0, 0);
1616
17 test__fixunssfsi(0.5, 0);
18 test__fixunssfsi(0.99, 0);
19 test__fixunssfsi(1.0, 1);
20 test__fixunssfsi(1.5, 1);
21 test__fixunssfsi(1.99, 1);
22 test__fixunssfsi(2.0, 2);
23 test__fixunssfsi(2.01, 2);
24 test__fixunssfsi(-0.5, 0);
25 test__fixunssfsi(-0.99, 0);
17 try test__fixunssfsi(0.5, 0);
18 try test__fixunssfsi(0.99, 0);
19 try test__fixunssfsi(1.0, 1);
20 try test__fixunssfsi(1.5, 1);
21 try test__fixunssfsi(1.99, 1);
22 try test__fixunssfsi(2.0, 2);
23 try test__fixunssfsi(2.01, 2);
24 try test__fixunssfsi(-0.5, 0);
25 try test__fixunssfsi(-0.99, 0);
2626
27 test__fixunssfsi(-1.0, 0);
28 test__fixunssfsi(-1.5, 0);
29 test__fixunssfsi(-1.99, 0);
30 test__fixunssfsi(-2.0, 0);
31 test__fixunssfsi(-2.01, 0);
27 try test__fixunssfsi(-1.0, 0);
28 try test__fixunssfsi(-1.5, 0);
29 try test__fixunssfsi(-1.99, 0);
30 try test__fixunssfsi(-2.0, 0);
31 try test__fixunssfsi(-2.01, 0);
3232
33 test__fixunssfsi(0x1.000000p+31, 0x80000000);
34 test__fixunssfsi(0x1.000000p+32, 0xFFFFFFFF);
35 test__fixunssfsi(0x1.FFFFFEp+31, 0xFFFFFF00);
36 test__fixunssfsi(0x1.FFFFFEp+30, 0x7FFFFF80);
37 test__fixunssfsi(0x1.FFFFFCp+30, 0x7FFFFF00);
33 try test__fixunssfsi(0x1.000000p+31, 0x80000000);
34 try test__fixunssfsi(0x1.000000p+32, 0xFFFFFFFF);
35 try test__fixunssfsi(0x1.FFFFFEp+31, 0xFFFFFF00);
36 try test__fixunssfsi(0x1.FFFFFEp+30, 0x7FFFFF80);
37 try test__fixunssfsi(0x1.FFFFFCp+30, 0x7FFFFF00);
3838
39 test__fixunssfsi(-0x1.FFFFFEp+30, 0);
40 test__fixunssfsi(-0x1.FFFFFCp+30, 0);
39 try test__fixunssfsi(-0x1.FFFFFEp+30, 0);
40 try test__fixunssfsi(-0x1.FFFFFCp+30, 0);
4141}
lib/std/special/compiler_rt/fixunssfti_test.zig+29-29
......@@ -6,41 +6,41 @@
66const __fixunssfti = @import("fixunssfti.zig").__fixunssfti;
77const testing = @import("std").testing;
88
9fn test__fixunssfti(a: f32, expected: u128) void {
9fn test__fixunssfti(a: f32, expected: u128) !void {
1010 const x = __fixunssfti(a);
11 testing.expect(x == expected);
11 try testing.expect(x == expected);
1212}
1313
1414test "fixunssfti" {
15 test__fixunssfti(0.0, 0);
15 try test__fixunssfti(0.0, 0);
1616
17 test__fixunssfti(0.5, 0);
18 test__fixunssfti(0.99, 0);
19 test__fixunssfti(1.0, 1);
20 test__fixunssfti(1.5, 1);
21 test__fixunssfti(1.99, 1);
22 test__fixunssfti(2.0, 2);
23 test__fixunssfti(2.01, 2);
24 test__fixunssfti(-0.5, 0);
25 test__fixunssfti(-0.99, 0);
17 try test__fixunssfti(0.5, 0);
18 try test__fixunssfti(0.99, 0);
19 try test__fixunssfti(1.0, 1);
20 try test__fixunssfti(1.5, 1);
21 try test__fixunssfti(1.99, 1);
22 try test__fixunssfti(2.0, 2);
23 try test__fixunssfti(2.01, 2);
24 try test__fixunssfti(-0.5, 0);
25 try test__fixunssfti(-0.99, 0);
2626
27 test__fixunssfti(-1.0, 0);
28 test__fixunssfti(-1.5, 0);
29 test__fixunssfti(-1.99, 0);
30 test__fixunssfti(-2.0, 0);
31 test__fixunssfti(-2.01, 0);
27 try test__fixunssfti(-1.0, 0);
28 try test__fixunssfti(-1.5, 0);
29 try test__fixunssfti(-1.99, 0);
30 try test__fixunssfti(-2.0, 0);
31 try test__fixunssfti(-2.01, 0);
3232
33 test__fixunssfti(0x1.FFFFFEp+63, 0xFFFFFF0000000000);
34 test__fixunssfti(0x1.000000p+63, 0x8000000000000000);
35 test__fixunssfti(0x1.FFFFFEp+62, 0x7FFFFF8000000000);
36 test__fixunssfti(0x1.FFFFFCp+62, 0x7FFFFF0000000000);
37 test__fixunssfti(0x1.FFFFFEp+127, 0xFFFFFF00000000000000000000000000);
38 test__fixunssfti(0x1.000000p+127, 0x80000000000000000000000000000000);
39 test__fixunssfti(0x1.FFFFFEp+126, 0x7FFFFF80000000000000000000000000);
40 test__fixunssfti(0x1.FFFFFCp+126, 0x7FFFFF00000000000000000000000000);
33 try test__fixunssfti(0x1.FFFFFEp+63, 0xFFFFFF0000000000);
34 try test__fixunssfti(0x1.000000p+63, 0x8000000000000000);
35 try test__fixunssfti(0x1.FFFFFEp+62, 0x7FFFFF8000000000);
36 try test__fixunssfti(0x1.FFFFFCp+62, 0x7FFFFF0000000000);
37 try test__fixunssfti(0x1.FFFFFEp+127, 0xFFFFFF00000000000000000000000000);
38 try test__fixunssfti(0x1.000000p+127, 0x80000000000000000000000000000000);
39 try test__fixunssfti(0x1.FFFFFEp+126, 0x7FFFFF80000000000000000000000000);
40 try test__fixunssfti(0x1.FFFFFCp+126, 0x7FFFFF00000000000000000000000000);
4141
42 test__fixunssfti(-0x1.FFFFFEp+62, 0x0000000000000000);
43 test__fixunssfti(-0x1.FFFFFCp+62, 0x0000000000000000);
44 test__fixunssfti(-0x1.FFFFFEp+126, 0x0000000000000000);
45 test__fixunssfti(-0x1.FFFFFCp+126, 0x0000000000000000);
42 try test__fixunssfti(-0x1.FFFFFEp+62, 0x0000000000000000);
43 try test__fixunssfti(-0x1.FFFFFCp+62, 0x0000000000000000);
44 try test__fixunssfti(-0x1.FFFFFEp+126, 0x0000000000000000);
45 try test__fixunssfti(-0x1.FFFFFCp+126, 0x0000000000000000);
4646}
lib/std/special/compiler_rt/fixunstfdi_test.zig+41-41
......@@ -6,49 +6,49 @@
66const __fixunstfdi = @import("fixunstfdi.zig").__fixunstfdi;
77const testing = @import("std").testing;
88
9fn test__fixunstfdi(a: f128, expected: u64) void {
9fn test__fixunstfdi(a: f128, expected: u64) !void {
1010 const x = __fixunstfdi(a);
11 testing.expect(x == expected);
11 try testing.expect(x == expected);
1212}
1313
1414test "fixunstfdi" {
15 test__fixunstfdi(0.0, 0);
16
17 test__fixunstfdi(0.5, 0);
18 test__fixunstfdi(0.99, 0);
19 test__fixunstfdi(1.0, 1);
20 test__fixunstfdi(1.5, 1);
21 test__fixunstfdi(1.99, 1);
22 test__fixunstfdi(2.0, 2);
23 test__fixunstfdi(2.01, 2);
24 test__fixunstfdi(-0.5, 0);
25 test__fixunstfdi(-0.99, 0);
26 test__fixunstfdi(-1.0, 0);
27 test__fixunstfdi(-1.5, 0);
28 test__fixunstfdi(-1.99, 0);
29 test__fixunstfdi(-2.0, 0);
30 test__fixunstfdi(-2.01, 0);
31
32 test__fixunstfdi(0x1.FFFFFEp+62, 0x7FFFFF8000000000);
33 test__fixunstfdi(0x1.FFFFFCp+62, 0x7FFFFF0000000000);
34
35 test__fixunstfdi(-0x1.FFFFFEp+62, 0);
36 test__fixunstfdi(-0x1.FFFFFCp+62, 0);
37
38 test__fixunstfdi(0x1.FFFFFFFFFFFFFp+62, 0x7FFFFFFFFFFFFC00);
39 test__fixunstfdi(0x1.FFFFFFFFFFFFEp+62, 0x7FFFFFFFFFFFF800);
40
41 test__fixunstfdi(-0x1.FFFFFFFFFFFFFp+62, 0);
42 test__fixunstfdi(-0x1.FFFFFFFFFFFFEp+62, 0);
43
44 test__fixunstfdi(0x1.FFFFFFFFFFFFFFFEp+63, 0xFFFFFFFFFFFFFFFF);
45 test__fixunstfdi(0x1.0000000000000002p+63, 0x8000000000000001);
46 test__fixunstfdi(0x1.0000000000000000p+63, 0x8000000000000000);
47 test__fixunstfdi(0x1.FFFFFFFFFFFFFFFCp+62, 0x7FFFFFFFFFFFFFFF);
48 test__fixunstfdi(0x1.FFFFFFFFFFFFFFF8p+62, 0x7FFFFFFFFFFFFFFE);
49 test__fixunstfdi(0x1.p+64, 0xFFFFFFFFFFFFFFFF);
50
51 test__fixunstfdi(-0x1.0000000000000000p+63, 0);
52 test__fixunstfdi(-0x1.FFFFFFFFFFFFFFFCp+62, 0);
53 test__fixunstfdi(-0x1.FFFFFFFFFFFFFFF8p+62, 0);
15 try test__fixunstfdi(0.0, 0);
16
17 try test__fixunstfdi(0.5, 0);
18 try test__fixunstfdi(0.99, 0);
19 try test__fixunstfdi(1.0, 1);
20 try test__fixunstfdi(1.5, 1);
21 try test__fixunstfdi(1.99, 1);
22 try test__fixunstfdi(2.0, 2);
23 try test__fixunstfdi(2.01, 2);
24 try test__fixunstfdi(-0.5, 0);
25 try test__fixunstfdi(-0.99, 0);
26 try test__fixunstfdi(-1.0, 0);
27 try test__fixunstfdi(-1.5, 0);
28 try test__fixunstfdi(-1.99, 0);
29 try test__fixunstfdi(-2.0, 0);
30 try test__fixunstfdi(-2.01, 0);
31
32 try test__fixunstfdi(0x1.FFFFFEp+62, 0x7FFFFF8000000000);
33 try test__fixunstfdi(0x1.FFFFFCp+62, 0x7FFFFF0000000000);
34
35 try test__fixunstfdi(-0x1.FFFFFEp+62, 0);
36 try test__fixunstfdi(-0x1.FFFFFCp+62, 0);
37
38 try test__fixunstfdi(0x1.FFFFFFFFFFFFFp+62, 0x7FFFFFFFFFFFFC00);
39 try test__fixunstfdi(0x1.FFFFFFFFFFFFEp+62, 0x7FFFFFFFFFFFF800);
40
41 try test__fixunstfdi(-0x1.FFFFFFFFFFFFFp+62, 0);
42 try test__fixunstfdi(-0x1.FFFFFFFFFFFFEp+62, 0);
43
44 try test__fixunstfdi(0x1.FFFFFFFFFFFFFFFEp+63, 0xFFFFFFFFFFFFFFFF);
45 try test__fixunstfdi(0x1.0000000000000002p+63, 0x8000000000000001);
46 try test__fixunstfdi(0x1.0000000000000000p+63, 0x8000000000000000);
47 try test__fixunstfdi(0x1.FFFFFFFFFFFFFFFCp+62, 0x7FFFFFFFFFFFFFFF);
48 try test__fixunstfdi(0x1.FFFFFFFFFFFFFFF8p+62, 0x7FFFFFFFFFFFFFFE);
49 try test__fixunstfdi(0x1.p+64, 0xFFFFFFFFFFFFFFFF);
50
51 try test__fixunstfdi(-0x1.0000000000000000p+63, 0);
52 try test__fixunstfdi(-0x1.FFFFFFFFFFFFFFFCp+62, 0);
53 try test__fixunstfdi(-0x1.FFFFFFFFFFFFFFF8p+62, 0);
5454}
lib/std/special/compiler_rt/fixunstfsi_test.zig+11-11
......@@ -6,22 +6,22 @@
66const __fixunstfsi = @import("fixunstfsi.zig").__fixunstfsi;
77const testing = @import("std").testing;
88
9fn test__fixunstfsi(a: f128, expected: u32) void {
9fn test__fixunstfsi(a: f128, expected: u32) !void {
1010 const x = __fixunstfsi(a);
11 testing.expect(x == expected);
11 try testing.expect(x == expected);
1212}
1313
1414const inf128 = @bitCast(f128, @as(u128, 0x7fff0000000000000000000000000000));
1515
1616test "fixunstfsi" {
17 test__fixunstfsi(inf128, 0xffffffff);
18 test__fixunstfsi(0, 0x0);
19 test__fixunstfsi(0x1.23456789abcdefp+5, 0x24);
20 test__fixunstfsi(0x1.23456789abcdefp-3, 0x0);
21 test__fixunstfsi(0x1.23456789abcdefp+20, 0x123456);
22 test__fixunstfsi(0x1.23456789abcdefp+40, 0xffffffff);
23 test__fixunstfsi(0x1.23456789abcdefp+256, 0xffffffff);
24 test__fixunstfsi(-0x1.23456789abcdefp+3, 0x0);
17 try test__fixunstfsi(inf128, 0xffffffff);
18 try test__fixunstfsi(0, 0x0);
19 try test__fixunstfsi(0x1.23456789abcdefp+5, 0x24);
20 try test__fixunstfsi(0x1.23456789abcdefp-3, 0x0);
21 try test__fixunstfsi(0x1.23456789abcdefp+20, 0x123456);
22 try test__fixunstfsi(0x1.23456789abcdefp+40, 0xffffffff);
23 try test__fixunstfsi(0x1.23456789abcdefp+256, 0xffffffff);
24 try test__fixunstfsi(-0x1.23456789abcdefp+3, 0x0);
2525
26 test__fixunstfsi(0x1.p+32, 0xFFFFFFFF);
26 try test__fixunstfsi(0x1.p+32, 0xFFFFFFFF);
2727}
lib/std/special/compiler_rt/fixunstfti_test.zig+18-18
......@@ -6,32 +6,32 @@
66const __fixunstfti = @import("fixunstfti.zig").__fixunstfti;
77const testing = @import("std").testing;
88
9fn test__fixunstfti(a: f128, expected: u128) void {
9fn test__fixunstfti(a: f128, expected: u128) !void {
1010 const x = __fixunstfti(a);
11 testing.expect(x == expected);
11 try testing.expect(x == expected);
1212}
1313
1414const inf128 = @bitCast(f128, @as(u128, 0x7fff0000000000000000000000000000));
1515
1616test "fixunstfti" {
17 test__fixunstfti(inf128, 0xffffffffffffffffffffffffffffffff);
17 try test__fixunstfti(inf128, 0xffffffffffffffffffffffffffffffff);
1818
19 test__fixunstfti(0.0, 0);
19 try test__fixunstfti(0.0, 0);
2020
21 test__fixunstfti(0.5, 0);
22 test__fixunstfti(0.99, 0);
23 test__fixunstfti(1.0, 1);
24 test__fixunstfti(1.5, 1);
25 test__fixunstfti(1.99, 1);
26 test__fixunstfti(2.0, 2);
27 test__fixunstfti(2.01, 2);
28 test__fixunstfti(-0.01, 0);
29 test__fixunstfti(-0.99, 0);
21 try test__fixunstfti(0.5, 0);
22 try test__fixunstfti(0.99, 0);
23 try test__fixunstfti(1.0, 1);
24 try test__fixunstfti(1.5, 1);
25 try test__fixunstfti(1.99, 1);
26 try test__fixunstfti(2.0, 2);
27 try test__fixunstfti(2.01, 2);
28 try test__fixunstfti(-0.01, 0);
29 try test__fixunstfti(-0.99, 0);
3030
31 test__fixunstfti(0x1.p+128, 0xffffffffffffffffffffffffffffffff);
31 try test__fixunstfti(0x1.p+128, 0xffffffffffffffffffffffffffffffff);
3232
33 test__fixunstfti(0x1.FFFFFEp+126, 0x7fffff80000000000000000000000000);
34 test__fixunstfti(0x1.FFFFFEp+127, 0xffffff00000000000000000000000000);
35 test__fixunstfti(0x1.FFFFFEp+128, 0xffffffffffffffffffffffffffffffff);
36 test__fixunstfti(0x1.FFFFFEp+129, 0xffffffffffffffffffffffffffffffff);
33 try test__fixunstfti(0x1.FFFFFEp+126, 0x7fffff80000000000000000000000000);
34 try test__fixunstfti(0x1.FFFFFEp+127, 0xffffff00000000000000000000000000);
35 try test__fixunstfti(0x1.FFFFFEp+128, 0xffffffffffffffffffffffffffffffff);
36 try test__fixunstfti(0x1.FFFFFEp+129, 0xffffffffffffffffffffffffffffffff);
3737}
lib/std/special/compiler_rt/floatdidf_test.zig+45-45
......@@ -6,53 +6,53 @@
66const __floatdidf = @import("floatdidf.zig").__floatdidf;
77const testing = @import("std").testing;
88
9fn test__floatdidf(a: i64, expected: f64) void {
9fn test__floatdidf(a: i64, expected: f64) !void {
1010 const r = __floatdidf(a);
11 testing.expect(r == expected);
11 try testing.expect(r == expected);
1212}
1313
1414test "floatdidf" {
15 test__floatdidf(0, 0.0);
16 test__floatdidf(1, 1.0);
17 test__floatdidf(2, 2.0);
18 test__floatdidf(20, 20.0);
19 test__floatdidf(-1, -1.0);
20 test__floatdidf(-2, -2.0);
21 test__floatdidf(-20, -20.0);
22 test__floatdidf(0x7FFFFF8000000000, 0x1.FFFFFEp+62);
23 test__floatdidf(0x7FFFFFFFFFFFF800, 0x1.FFFFFFFFFFFFEp+62);
24 test__floatdidf(0x7FFFFF0000000000, 0x1.FFFFFCp+62);
25 test__floatdidf(0x7FFFFFFFFFFFF000, 0x1.FFFFFFFFFFFFCp+62);
26 test__floatdidf(@bitCast(i64, @intCast(u64, 0x8000008000000000)), -0x1.FFFFFEp+62);
27 test__floatdidf(@bitCast(i64, @intCast(u64, 0x8000000000000800)), -0x1.FFFFFFFFFFFFEp+62);
28 test__floatdidf(@bitCast(i64, @intCast(u64, 0x8000010000000000)), -0x1.FFFFFCp+62);
29 test__floatdidf(@bitCast(i64, @intCast(u64, 0x8000000000001000)), -0x1.FFFFFFFFFFFFCp+62);
30 test__floatdidf(@bitCast(i64, @intCast(u64, 0x8000000000000000)), -0x1.000000p+63);
31 test__floatdidf(@bitCast(i64, @intCast(u64, 0x8000000000000001)), -0x1.000000p+63);
32 test__floatdidf(0x0007FB72E8000000, 0x1.FEDCBAp+50);
33 test__floatdidf(0x0007FB72EA000000, 0x1.FEDCBA8p+50);
34 test__floatdidf(0x0007FB72EB000000, 0x1.FEDCBACp+50);
35 test__floatdidf(0x0007FB72EBFFFFFF, 0x1.FEDCBAFFFFFFCp+50);
36 test__floatdidf(0x0007FB72EC000000, 0x1.FEDCBBp+50);
37 test__floatdidf(0x0007FB72E8000001, 0x1.FEDCBA0000004p+50);
38 test__floatdidf(0x0007FB72E6000000, 0x1.FEDCB98p+50);
39 test__floatdidf(0x0007FB72E7000000, 0x1.FEDCB9Cp+50);
40 test__floatdidf(0x0007FB72E7FFFFFF, 0x1.FEDCB9FFFFFFCp+50);
41 test__floatdidf(0x0007FB72E4000001, 0x1.FEDCB90000004p+50);
42 test__floatdidf(0x0007FB72E4000000, 0x1.FEDCB9p+50);
43 test__floatdidf(0x023479FD0E092DC0, 0x1.1A3CFE870496Ep+57);
44 test__floatdidf(0x023479FD0E092DA1, 0x1.1A3CFE870496Dp+57);
45 test__floatdidf(0x023479FD0E092DB0, 0x1.1A3CFE870496Ep+57);
46 test__floatdidf(0x023479FD0E092DB8, 0x1.1A3CFE870496Ep+57);
47 test__floatdidf(0x023479FD0E092DB6, 0x1.1A3CFE870496Ep+57);
48 test__floatdidf(0x023479FD0E092DBF, 0x1.1A3CFE870496Ep+57);
49 test__floatdidf(0x023479FD0E092DC1, 0x1.1A3CFE870496Ep+57);
50 test__floatdidf(0x023479FD0E092DC7, 0x1.1A3CFE870496Ep+57);
51 test__floatdidf(0x023479FD0E092DC8, 0x1.1A3CFE870496Ep+57);
52 test__floatdidf(0x023479FD0E092DCF, 0x1.1A3CFE870496Ep+57);
53 test__floatdidf(0x023479FD0E092DD0, 0x1.1A3CFE870496Ep+57);
54 test__floatdidf(0x023479FD0E092DD1, 0x1.1A3CFE870496Fp+57);
55 test__floatdidf(0x023479FD0E092DD8, 0x1.1A3CFE870496Fp+57);
56 test__floatdidf(0x023479FD0E092DDF, 0x1.1A3CFE870496Fp+57);
57 test__floatdidf(0x023479FD0E092DE0, 0x1.1A3CFE870496Fp+57);
15 try test__floatdidf(0, 0.0);
16 try test__floatdidf(1, 1.0);
17 try test__floatdidf(2, 2.0);
18 try test__floatdidf(20, 20.0);
19 try test__floatdidf(-1, -1.0);
20 try test__floatdidf(-2, -2.0);
21 try test__floatdidf(-20, -20.0);
22 try test__floatdidf(0x7FFFFF8000000000, 0x1.FFFFFEp+62);
23 try test__floatdidf(0x7FFFFFFFFFFFF800, 0x1.FFFFFFFFFFFFEp+62);
24 try test__floatdidf(0x7FFFFF0000000000, 0x1.FFFFFCp+62);
25 try test__floatdidf(0x7FFFFFFFFFFFF000, 0x1.FFFFFFFFFFFFCp+62);
26 try test__floatdidf(@bitCast(i64, @intCast(u64, 0x8000008000000000)), -0x1.FFFFFEp+62);
27 try test__floatdidf(@bitCast(i64, @intCast(u64, 0x8000000000000800)), -0x1.FFFFFFFFFFFFEp+62);
28 try test__floatdidf(@bitCast(i64, @intCast(u64, 0x8000010000000000)), -0x1.FFFFFCp+62);
29 try test__floatdidf(@bitCast(i64, @intCast(u64, 0x8000000000001000)), -0x1.FFFFFFFFFFFFCp+62);
30 try test__floatdidf(@bitCast(i64, @intCast(u64, 0x8000000000000000)), -0x1.000000p+63);
31 try test__floatdidf(@bitCast(i64, @intCast(u64, 0x8000000000000001)), -0x1.000000p+63);
32 try test__floatdidf(0x0007FB72E8000000, 0x1.FEDCBAp+50);
33 try test__floatdidf(0x0007FB72EA000000, 0x1.FEDCBA8p+50);
34 try test__floatdidf(0x0007FB72EB000000, 0x1.FEDCBACp+50);
35 try test__floatdidf(0x0007FB72EBFFFFFF, 0x1.FEDCBAFFFFFFCp+50);
36 try test__floatdidf(0x0007FB72EC000000, 0x1.FEDCBBp+50);
37 try test__floatdidf(0x0007FB72E8000001, 0x1.FEDCBA0000004p+50);
38 try test__floatdidf(0x0007FB72E6000000, 0x1.FEDCB98p+50);
39 try test__floatdidf(0x0007FB72E7000000, 0x1.FEDCB9Cp+50);
40 try test__floatdidf(0x0007FB72E7FFFFFF, 0x1.FEDCB9FFFFFFCp+50);
41 try test__floatdidf(0x0007FB72E4000001, 0x1.FEDCB90000004p+50);
42 try test__floatdidf(0x0007FB72E4000000, 0x1.FEDCB9p+50);
43 try test__floatdidf(0x023479FD0E092DC0, 0x1.1A3CFE870496Ep+57);
44 try test__floatdidf(0x023479FD0E092DA1, 0x1.1A3CFE870496Dp+57);
45 try test__floatdidf(0x023479FD0E092DB0, 0x1.1A3CFE870496Ep+57);
46 try test__floatdidf(0x023479FD0E092DB8, 0x1.1A3CFE870496Ep+57);
47 try test__floatdidf(0x023479FD0E092DB6, 0x1.1A3CFE870496Ep+57);
48 try test__floatdidf(0x023479FD0E092DBF, 0x1.1A3CFE870496Ep+57);
49 try test__floatdidf(0x023479FD0E092DC1, 0x1.1A3CFE870496Ep+57);
50 try test__floatdidf(0x023479FD0E092DC7, 0x1.1A3CFE870496Ep+57);
51 try test__floatdidf(0x023479FD0E092DC8, 0x1.1A3CFE870496Ep+57);
52 try test__floatdidf(0x023479FD0E092DCF, 0x1.1A3CFE870496Ep+57);
53 try test__floatdidf(0x023479FD0E092DD0, 0x1.1A3CFE870496Ep+57);
54 try test__floatdidf(0x023479FD0E092DD1, 0x1.1A3CFE870496Fp+57);
55 try test__floatdidf(0x023479FD0E092DD8, 0x1.1A3CFE870496Fp+57);
56 try test__floatdidf(0x023479FD0E092DDF, 0x1.1A3CFE870496Fp+57);
57 try test__floatdidf(0x023479FD0E092DE0, 0x1.1A3CFE870496Fp+57);
5858}
lib/std/special/compiler_rt/floatdisf_test.zig+24-24
......@@ -6,32 +6,32 @@
66const __floatdisf = @import("floatXisf.zig").__floatdisf;
77const testing = @import("std").testing;
88
9fn test__floatdisf(a: i64, expected: f32) void {
9fn test__floatdisf(a: i64, expected: f32) !void {
1010 const x = __floatdisf(a);
11 testing.expect(x == expected);
11 try testing.expect(x == expected);
1212}
1313
1414test "floatdisf" {
15 test__floatdisf(0, 0.0);
16 test__floatdisf(1, 1.0);
17 test__floatdisf(2, 2.0);
18 test__floatdisf(-1, -1.0);
19 test__floatdisf(-2, -2.0);
20 test__floatdisf(0x7FFFFF8000000000, 0x1.FFFFFEp+62);
21 test__floatdisf(0x7FFFFF0000000000, 0x1.FFFFFCp+62);
22 test__floatdisf(0x8000008000000000, -0x1.FFFFFEp+62);
23 test__floatdisf(0x8000010000000000, -0x1.FFFFFCp+62);
24 test__floatdisf(0x8000000000000000, -0x1.000000p+63);
25 test__floatdisf(0x8000000000000001, -0x1.000000p+63);
26 test__floatdisf(0x0007FB72E8000000, 0x1.FEDCBAp+50);
27 test__floatdisf(0x0007FB72EA000000, 0x1.FEDCBAp+50);
28 test__floatdisf(0x0007FB72EB000000, 0x1.FEDCBAp+50);
29 test__floatdisf(0x0007FB72EBFFFFFF, 0x1.FEDCBAp+50);
30 test__floatdisf(0x0007FB72EC000000, 0x1.FEDCBCp+50);
31 test__floatdisf(0x0007FB72E8000001, 0x1.FEDCBAp+50);
32 test__floatdisf(0x0007FB72E6000000, 0x1.FEDCBAp+50);
33 test__floatdisf(0x0007FB72E7000000, 0x1.FEDCBAp+50);
34 test__floatdisf(0x0007FB72E7FFFFFF, 0x1.FEDCBAp+50);
35 test__floatdisf(0x0007FB72E4000001, 0x1.FEDCBAp+50);
36 test__floatdisf(0x0007FB72E4000000, 0x1.FEDCB8p+50);
15 try test__floatdisf(0, 0.0);
16 try test__floatdisf(1, 1.0);
17 try test__floatdisf(2, 2.0);
18 try test__floatdisf(-1, -1.0);
19 try test__floatdisf(-2, -2.0);
20 try test__floatdisf(0x7FFFFF8000000000, 0x1.FFFFFEp+62);
21 try test__floatdisf(0x7FFFFF0000000000, 0x1.FFFFFCp+62);
22 try test__floatdisf(0x8000008000000000, -0x1.FFFFFEp+62);
23 try test__floatdisf(0x8000010000000000, -0x1.FFFFFCp+62);
24 try test__floatdisf(0x8000000000000000, -0x1.000000p+63);
25 try test__floatdisf(0x8000000000000001, -0x1.000000p+63);
26 try test__floatdisf(0x0007FB72E8000000, 0x1.FEDCBAp+50);
27 try test__floatdisf(0x0007FB72EA000000, 0x1.FEDCBAp+50);
28 try test__floatdisf(0x0007FB72EB000000, 0x1.FEDCBAp+50);
29 try test__floatdisf(0x0007FB72EBFFFFFF, 0x1.FEDCBAp+50);
30 try test__floatdisf(0x0007FB72EC000000, 0x1.FEDCBCp+50);
31 try test__floatdisf(0x0007FB72E8000001, 0x1.FEDCBAp+50);
32 try test__floatdisf(0x0007FB72E6000000, 0x1.FEDCBAp+50);
33 try test__floatdisf(0x0007FB72E7000000, 0x1.FEDCBAp+50);
34 try test__floatdisf(0x0007FB72E7FFFFFF, 0x1.FEDCBAp+50);
35 try test__floatdisf(0x0007FB72E4000001, 0x1.FEDCBAp+50);
36 try test__floatdisf(0x0007FB72E4000000, 0x1.FEDCB8p+50);
3737}
lib/std/special/compiler_rt/floatditf_test.zig+11-11
......@@ -6,21 +6,21 @@
66const __floatditf = @import("floatditf.zig").__floatditf;
77const testing = @import("std").testing;
88
9fn test__floatditf(a: i64, expected: f128) void {
9fn test__floatditf(a: i64, expected: f128) !void {
1010 const x = __floatditf(a);
11 testing.expect(x == expected);
11 try testing.expect(x == expected);
1212}
1313
1414test "floatditf" {
15 test__floatditf(0x7fffffffffffffff, make_ti(0x403dffffffffffff, 0xfffc000000000000));
16 test__floatditf(0x123456789abcdef1, make_ti(0x403b23456789abcd, 0xef10000000000000));
17 test__floatditf(0x2, make_ti(0x4000000000000000, 0x0));
18 test__floatditf(0x1, make_ti(0x3fff000000000000, 0x0));
19 test__floatditf(0x0, make_ti(0x0, 0x0));
20 test__floatditf(@bitCast(i64, @as(u64, 0xffffffffffffffff)), make_ti(0xbfff000000000000, 0x0));
21 test__floatditf(@bitCast(i64, @as(u64, 0xfffffffffffffffe)), make_ti(0xc000000000000000, 0x0));
22 test__floatditf(-0x123456789abcdef1, make_ti(0xc03b23456789abcd, 0xef10000000000000));
23 test__floatditf(@bitCast(i64, @as(u64, 0x8000000000000000)), make_ti(0xc03e000000000000, 0x0));
15 try test__floatditf(0x7fffffffffffffff, make_ti(0x403dffffffffffff, 0xfffc000000000000));
16 try test__floatditf(0x123456789abcdef1, make_ti(0x403b23456789abcd, 0xef10000000000000));
17 try test__floatditf(0x2, make_ti(0x4000000000000000, 0x0));
18 try test__floatditf(0x1, make_ti(0x3fff000000000000, 0x0));
19 try test__floatditf(0x0, make_ti(0x0, 0x0));
20 try test__floatditf(@bitCast(i64, @as(u64, 0xffffffffffffffff)), make_ti(0xbfff000000000000, 0x0));
21 try test__floatditf(@bitCast(i64, @as(u64, 0xfffffffffffffffe)), make_ti(0xc000000000000000, 0x0));
22 try test__floatditf(-0x123456789abcdef1, make_ti(0xc03b23456789abcd, 0xef10000000000000));
23 try test__floatditf(@bitCast(i64, @as(u64, 0x8000000000000000)), make_ti(0xc03e000000000000, 0x0));
2424}
2525
2626fn make_ti(high: u64, low: u64) f128 {
lib/std/special/compiler_rt/floatsiXf.zig+22-22
......@@ -84,42 +84,42 @@ pub fn __aeabi_i2f(arg: i32) callconv(.AAPCS) f32 {
8484 return @call(.{ .modifier = .always_inline }, __floatsisf, .{arg});
8585}
8686
87fn test_one_floatsitf(a: i32, expected: u128) void {
87fn test_one_floatsitf(a: i32, expected: u128) !void {
8888 const r = __floatsitf(a);
89 std.testing.expect(@bitCast(u128, r) == expected);
89 try std.testing.expect(@bitCast(u128, r) == expected);
9090}
9191
92fn test_one_floatsidf(a: i32, expected: u64) void {
92fn test_one_floatsidf(a: i32, expected: u64) !void {
9393 const r = __floatsidf(a);
94 std.testing.expect(@bitCast(u64, r) == expected);
94 try std.testing.expect(@bitCast(u64, r) == expected);
9595}
9696
97fn test_one_floatsisf(a: i32, expected: u32) void {
97fn test_one_floatsisf(a: i32, expected: u32) !void {
9898 const r = __floatsisf(a);
99 std.testing.expect(@bitCast(u32, r) == expected);
99 try std.testing.expect(@bitCast(u32, r) == expected);
100100}
101101
102102test "floatsidf" {
103 test_one_floatsidf(0, 0x0000000000000000);
104 test_one_floatsidf(1, 0x3ff0000000000000);
105 test_one_floatsidf(-1, 0xbff0000000000000);
106 test_one_floatsidf(0x7FFFFFFF, 0x41dfffffffc00000);
107 test_one_floatsidf(@bitCast(i32, @intCast(u32, 0x80000000)), 0xc1e0000000000000);
103 try test_one_floatsidf(0, 0x0000000000000000);
104 try test_one_floatsidf(1, 0x3ff0000000000000);
105 try test_one_floatsidf(-1, 0xbff0000000000000);
106 try test_one_floatsidf(0x7FFFFFFF, 0x41dfffffffc00000);
107 try test_one_floatsidf(@bitCast(i32, @intCast(u32, 0x80000000)), 0xc1e0000000000000);
108108}
109109
110110test "floatsisf" {
111 test_one_floatsisf(0, 0x00000000);
112 test_one_floatsisf(1, 0x3f800000);
113 test_one_floatsisf(-1, 0xbf800000);
114 test_one_floatsisf(0x7FFFFFFF, 0x4f000000);
115 test_one_floatsisf(@bitCast(i32, @intCast(u32, 0x80000000)), 0xcf000000);
111 try test_one_floatsisf(0, 0x00000000);
112 try test_one_floatsisf(1, 0x3f800000);
113 try test_one_floatsisf(-1, 0xbf800000);
114 try test_one_floatsisf(0x7FFFFFFF, 0x4f000000);
115 try test_one_floatsisf(@bitCast(i32, @intCast(u32, 0x80000000)), 0xcf000000);
116116}
117117
118118test "floatsitf" {
119 test_one_floatsitf(0, 0);
120 test_one_floatsitf(0x7FFFFFFF, 0x401dfffffffc00000000000000000000);
121 test_one_floatsitf(0x12345678, 0x401b2345678000000000000000000000);
122 test_one_floatsitf(-0x12345678, 0xc01b2345678000000000000000000000);
123 test_one_floatsitf(@bitCast(i32, @intCast(u32, 0xffffffff)), 0xbfff0000000000000000000000000000);
124 test_one_floatsitf(@bitCast(i32, @intCast(u32, 0x80000000)), 0xc01e0000000000000000000000000000);
119 try test_one_floatsitf(0, 0);
120 try test_one_floatsitf(0x7FFFFFFF, 0x401dfffffffc00000000000000000000);
121 try test_one_floatsitf(0x12345678, 0x401b2345678000000000000000000000);
122 try test_one_floatsitf(-0x12345678, 0xc01b2345678000000000000000000000);
123 try test_one_floatsitf(@bitCast(i32, @intCast(u32, 0xffffffff)), 0xbfff0000000000000000000000000000);
124 try test_one_floatsitf(@bitCast(i32, @intCast(u32, 0x80000000)), 0xc01e0000000000000000000000000000);
125125}
lib/std/special/compiler_rt/floattidf_test.zig+60-60
......@@ -6,79 +6,79 @@
66const __floattidf = @import("floattidf.zig").__floattidf;
77const testing = @import("std").testing;
88
9fn test__floattidf(a: i128, expected: f64) void {
9fn test__floattidf(a: i128, expected: f64) !void {
1010 const x = __floattidf(a);
11 testing.expect(x == expected);
11 try testing.expect(x == expected);
1212}
1313
1414test "floattidf" {
15 test__floattidf(0, 0.0);
15 try test__floattidf(0, 0.0);
1616
17 test__floattidf(1, 1.0);
18 test__floattidf(2, 2.0);
19 test__floattidf(20, 20.0);
20 test__floattidf(-1, -1.0);
21 test__floattidf(-2, -2.0);
22 test__floattidf(-20, -20.0);
17 try test__floattidf(1, 1.0);
18 try test__floattidf(2, 2.0);
19 try test__floattidf(20, 20.0);
20 try test__floattidf(-1, -1.0);
21 try test__floattidf(-2, -2.0);
22 try test__floattidf(-20, -20.0);
2323
24 test__floattidf(0x7FFFFF8000000000, 0x1.FFFFFEp+62);
25 test__floattidf(0x7FFFFFFFFFFFF800, 0x1.FFFFFFFFFFFFEp+62);
26 test__floattidf(0x7FFFFF0000000000, 0x1.FFFFFCp+62);
27 test__floattidf(0x7FFFFFFFFFFFF000, 0x1.FFFFFFFFFFFFCp+62);
24 try test__floattidf(0x7FFFFF8000000000, 0x1.FFFFFEp+62);
25 try test__floattidf(0x7FFFFFFFFFFFF800, 0x1.FFFFFFFFFFFFEp+62);
26 try test__floattidf(0x7FFFFF0000000000, 0x1.FFFFFCp+62);
27 try test__floattidf(0x7FFFFFFFFFFFF000, 0x1.FFFFFFFFFFFFCp+62);
2828
29 test__floattidf(make_ti(0x8000008000000000, 0), -0x1.FFFFFEp+126);
30 test__floattidf(make_ti(0x8000000000000800, 0), -0x1.FFFFFFFFFFFFEp+126);
31 test__floattidf(make_ti(0x8000010000000000, 0), -0x1.FFFFFCp+126);
32 test__floattidf(make_ti(0x8000000000001000, 0), -0x1.FFFFFFFFFFFFCp+126);
29 try test__floattidf(make_ti(0x8000008000000000, 0), -0x1.FFFFFEp+126);
30 try test__floattidf(make_ti(0x8000000000000800, 0), -0x1.FFFFFFFFFFFFEp+126);
31 try test__floattidf(make_ti(0x8000010000000000, 0), -0x1.FFFFFCp+126);
32 try test__floattidf(make_ti(0x8000000000001000, 0), -0x1.FFFFFFFFFFFFCp+126);
3333
34 test__floattidf(make_ti(0x8000000000000000, 0), -0x1.000000p+127);
35 test__floattidf(make_ti(0x8000000000000001, 0), -0x1.000000p+127);
34 try test__floattidf(make_ti(0x8000000000000000, 0), -0x1.000000p+127);
35 try test__floattidf(make_ti(0x8000000000000001, 0), -0x1.000000p+127);
3636
37 test__floattidf(0x0007FB72E8000000, 0x1.FEDCBAp+50);
37 try test__floattidf(0x0007FB72E8000000, 0x1.FEDCBAp+50);
3838
39 test__floattidf(0x0007FB72EA000000, 0x1.FEDCBA8p+50);
40 test__floattidf(0x0007FB72EB000000, 0x1.FEDCBACp+50);
41 test__floattidf(0x0007FB72EBFFFFFF, 0x1.FEDCBAFFFFFFCp+50);
42 test__floattidf(0x0007FB72EC000000, 0x1.FEDCBBp+50);
43 test__floattidf(0x0007FB72E8000001, 0x1.FEDCBA0000004p+50);
39 try test__floattidf(0x0007FB72EA000000, 0x1.FEDCBA8p+50);
40 try test__floattidf(0x0007FB72EB000000, 0x1.FEDCBACp+50);
41 try test__floattidf(0x0007FB72EBFFFFFF, 0x1.FEDCBAFFFFFFCp+50);
42 try test__floattidf(0x0007FB72EC000000, 0x1.FEDCBBp+50);
43 try test__floattidf(0x0007FB72E8000001, 0x1.FEDCBA0000004p+50);
4444
45 test__floattidf(0x0007FB72E6000000, 0x1.FEDCB98p+50);
46 test__floattidf(0x0007FB72E7000000, 0x1.FEDCB9Cp+50);
47 test__floattidf(0x0007FB72E7FFFFFF, 0x1.FEDCB9FFFFFFCp+50);
48 test__floattidf(0x0007FB72E4000001, 0x1.FEDCB90000004p+50);
49 test__floattidf(0x0007FB72E4000000, 0x1.FEDCB9p+50);
45 try test__floattidf(0x0007FB72E6000000, 0x1.FEDCB98p+50);
46 try test__floattidf(0x0007FB72E7000000, 0x1.FEDCB9Cp+50);
47 try test__floattidf(0x0007FB72E7FFFFFF, 0x1.FEDCB9FFFFFFCp+50);
48 try test__floattidf(0x0007FB72E4000001, 0x1.FEDCB90000004p+50);
49 try test__floattidf(0x0007FB72E4000000, 0x1.FEDCB9p+50);
5050
51 test__floattidf(0x023479FD0E092DC0, 0x1.1A3CFE870496Ep+57);
52 test__floattidf(0x023479FD0E092DA1, 0x1.1A3CFE870496Dp+57);
53 test__floattidf(0x023479FD0E092DB0, 0x1.1A3CFE870496Ep+57);
54 test__floattidf(0x023479FD0E092DB8, 0x1.1A3CFE870496Ep+57);
55 test__floattidf(0x023479FD0E092DB6, 0x1.1A3CFE870496Ep+57);
56 test__floattidf(0x023479FD0E092DBF, 0x1.1A3CFE870496Ep+57);
57 test__floattidf(0x023479FD0E092DC1, 0x1.1A3CFE870496Ep+57);
58 test__floattidf(0x023479FD0E092DC7, 0x1.1A3CFE870496Ep+57);
59 test__floattidf(0x023479FD0E092DC8, 0x1.1A3CFE870496Ep+57);
60 test__floattidf(0x023479FD0E092DCF, 0x1.1A3CFE870496Ep+57);
61 test__floattidf(0x023479FD0E092DD0, 0x1.1A3CFE870496Ep+57);
62 test__floattidf(0x023479FD0E092DD1, 0x1.1A3CFE870496Fp+57);
63 test__floattidf(0x023479FD0E092DD8, 0x1.1A3CFE870496Fp+57);
64 test__floattidf(0x023479FD0E092DDF, 0x1.1A3CFE870496Fp+57);
65 test__floattidf(0x023479FD0E092DE0, 0x1.1A3CFE870496Fp+57);
51 try test__floattidf(0x023479FD0E092DC0, 0x1.1A3CFE870496Ep+57);
52 try test__floattidf(0x023479FD0E092DA1, 0x1.1A3CFE870496Dp+57);
53 try test__floattidf(0x023479FD0E092DB0, 0x1.1A3CFE870496Ep+57);
54 try test__floattidf(0x023479FD0E092DB8, 0x1.1A3CFE870496Ep+57);
55 try test__floattidf(0x023479FD0E092DB6, 0x1.1A3CFE870496Ep+57);
56 try test__floattidf(0x023479FD0E092DBF, 0x1.1A3CFE870496Ep+57);
57 try test__floattidf(0x023479FD0E092DC1, 0x1.1A3CFE870496Ep+57);
58 try test__floattidf(0x023479FD0E092DC7, 0x1.1A3CFE870496Ep+57);
59 try test__floattidf(0x023479FD0E092DC8, 0x1.1A3CFE870496Ep+57);
60 try test__floattidf(0x023479FD0E092DCF, 0x1.1A3CFE870496Ep+57);
61 try test__floattidf(0x023479FD0E092DD0, 0x1.1A3CFE870496Ep+57);
62 try test__floattidf(0x023479FD0E092DD1, 0x1.1A3CFE870496Fp+57);
63 try test__floattidf(0x023479FD0E092DD8, 0x1.1A3CFE870496Fp+57);
64 try test__floattidf(0x023479FD0E092DDF, 0x1.1A3CFE870496Fp+57);
65 try test__floattidf(0x023479FD0E092DE0, 0x1.1A3CFE870496Fp+57);
6666
67 test__floattidf(make_ti(0x023479FD0E092DC0, 0), 0x1.1A3CFE870496Ep+121);
68 test__floattidf(make_ti(0x023479FD0E092DA1, 1), 0x1.1A3CFE870496Dp+121);
69 test__floattidf(make_ti(0x023479FD0E092DB0, 2), 0x1.1A3CFE870496Ep+121);
70 test__floattidf(make_ti(0x023479FD0E092DB8, 3), 0x1.1A3CFE870496Ep+121);
71 test__floattidf(make_ti(0x023479FD0E092DB6, 4), 0x1.1A3CFE870496Ep+121);
72 test__floattidf(make_ti(0x023479FD0E092DBF, 5), 0x1.1A3CFE870496Ep+121);
73 test__floattidf(make_ti(0x023479FD0E092DC1, 6), 0x1.1A3CFE870496Ep+121);
74 test__floattidf(make_ti(0x023479FD0E092DC7, 7), 0x1.1A3CFE870496Ep+121);
75 test__floattidf(make_ti(0x023479FD0E092DC8, 8), 0x1.1A3CFE870496Ep+121);
76 test__floattidf(make_ti(0x023479FD0E092DCF, 9), 0x1.1A3CFE870496Ep+121);
77 test__floattidf(make_ti(0x023479FD0E092DD0, 0), 0x1.1A3CFE870496Ep+121);
78 test__floattidf(make_ti(0x023479FD0E092DD1, 11), 0x1.1A3CFE870496Fp+121);
79 test__floattidf(make_ti(0x023479FD0E092DD8, 12), 0x1.1A3CFE870496Fp+121);
80 test__floattidf(make_ti(0x023479FD0E092DDF, 13), 0x1.1A3CFE870496Fp+121);
81 test__floattidf(make_ti(0x023479FD0E092DE0, 14), 0x1.1A3CFE870496Fp+121);
67 try test__floattidf(make_ti(0x023479FD0E092DC0, 0), 0x1.1A3CFE870496Ep+121);
68 try test__floattidf(make_ti(0x023479FD0E092DA1, 1), 0x1.1A3CFE870496Dp+121);
69 try test__floattidf(make_ti(0x023479FD0E092DB0, 2), 0x1.1A3CFE870496Ep+121);
70 try test__floattidf(make_ti(0x023479FD0E092DB8, 3), 0x1.1A3CFE870496Ep+121);
71 try test__floattidf(make_ti(0x023479FD0E092DB6, 4), 0x1.1A3CFE870496Ep+121);
72 try test__floattidf(make_ti(0x023479FD0E092DBF, 5), 0x1.1A3CFE870496Ep+121);
73 try test__floattidf(make_ti(0x023479FD0E092DC1, 6), 0x1.1A3CFE870496Ep+121);
74 try test__floattidf(make_ti(0x023479FD0E092DC7, 7), 0x1.1A3CFE870496Ep+121);
75 try test__floattidf(make_ti(0x023479FD0E092DC8, 8), 0x1.1A3CFE870496Ep+121);
76 try test__floattidf(make_ti(0x023479FD0E092DCF, 9), 0x1.1A3CFE870496Ep+121);
77 try test__floattidf(make_ti(0x023479FD0E092DD0, 0), 0x1.1A3CFE870496Ep+121);
78 try test__floattidf(make_ti(0x023479FD0E092DD1, 11), 0x1.1A3CFE870496Fp+121);
79 try test__floattidf(make_ti(0x023479FD0E092DD8, 12), 0x1.1A3CFE870496Fp+121);
80 try test__floattidf(make_ti(0x023479FD0E092DDF, 13), 0x1.1A3CFE870496Fp+121);
81 try test__floattidf(make_ti(0x023479FD0E092DE0, 14), 0x1.1A3CFE870496Fp+121);
8282}
8383
8484fn make_ti(high: u64, low: u64) i128 {
lib/std/special/compiler_rt/floattisf_test.zig+35-35
......@@ -6,55 +6,55 @@
66const __floattisf = @import("floatXisf.zig").__floattisf;
77const testing = @import("std").testing;
88
9fn test__floattisf(a: i128, expected: f32) void {
9fn test__floattisf(a: i128, expected: f32) !void {
1010 const x = __floattisf(a);
11 testing.expect(x == expected);
11 try testing.expect(x == expected);
1212}
1313
1414test "floattisf" {
15 test__floattisf(0, 0.0);
15 try test__floattisf(0, 0.0);
1616
17 test__floattisf(1, 1.0);
18 test__floattisf(2, 2.0);
19 test__floattisf(-1, -1.0);
20 test__floattisf(-2, -2.0);
17 try test__floattisf(1, 1.0);
18 try test__floattisf(2, 2.0);
19 try test__floattisf(-1, -1.0);
20 try test__floattisf(-2, -2.0);
2121
22 test__floattisf(0x7FFFFF8000000000, 0x1.FFFFFEp+62);
23 test__floattisf(0x7FFFFF0000000000, 0x1.FFFFFCp+62);
22 try test__floattisf(0x7FFFFF8000000000, 0x1.FFFFFEp+62);
23 try test__floattisf(0x7FFFFF0000000000, 0x1.FFFFFCp+62);
2424
25 test__floattisf(make_ti(0xFFFFFFFFFFFFFFFF, 0x8000008000000000), -0x1.FFFFFEp+62);
26 test__floattisf(make_ti(0xFFFFFFFFFFFFFFFF, 0x8000010000000000), -0x1.FFFFFCp+62);
25 try test__floattisf(make_ti(0xFFFFFFFFFFFFFFFF, 0x8000008000000000), -0x1.FFFFFEp+62);
26 try test__floattisf(make_ti(0xFFFFFFFFFFFFFFFF, 0x8000010000000000), -0x1.FFFFFCp+62);
2727
28 test__floattisf(make_ti(0xFFFFFFFFFFFFFFFF, 0x8000000000000000), -0x1.000000p+63);
29 test__floattisf(make_ti(0xFFFFFFFFFFFFFFFF, 0x8000000000000001), -0x1.000000p+63);
28 try test__floattisf(make_ti(0xFFFFFFFFFFFFFFFF, 0x8000000000000000), -0x1.000000p+63);
29 try test__floattisf(make_ti(0xFFFFFFFFFFFFFFFF, 0x8000000000000001), -0x1.000000p+63);
3030
31 test__floattisf(0x0007FB72E8000000, 0x1.FEDCBAp+50);
31 try test__floattisf(0x0007FB72E8000000, 0x1.FEDCBAp+50);
3232
33 test__floattisf(0x0007FB72EA000000, 0x1.FEDCBAp+50);
34 test__floattisf(0x0007FB72EB000000, 0x1.FEDCBAp+50);
35 test__floattisf(0x0007FB72EBFFFFFF, 0x1.FEDCBAp+50);
36 test__floattisf(0x0007FB72EC000000, 0x1.FEDCBCp+50);
37 test__floattisf(0x0007FB72E8000001, 0x1.FEDCBAp+50);
33 try test__floattisf(0x0007FB72EA000000, 0x1.FEDCBAp+50);
34 try test__floattisf(0x0007FB72EB000000, 0x1.FEDCBAp+50);
35 try test__floattisf(0x0007FB72EBFFFFFF, 0x1.FEDCBAp+50);
36 try test__floattisf(0x0007FB72EC000000, 0x1.FEDCBCp+50);
37 try test__floattisf(0x0007FB72E8000001, 0x1.FEDCBAp+50);
3838
39 test__floattisf(0x0007FB72E6000000, 0x1.FEDCBAp+50);
40 test__floattisf(0x0007FB72E7000000, 0x1.FEDCBAp+50);
41 test__floattisf(0x0007FB72E7FFFFFF, 0x1.FEDCBAp+50);
42 test__floattisf(0x0007FB72E4000001, 0x1.FEDCBAp+50);
43 test__floattisf(0x0007FB72E4000000, 0x1.FEDCB8p+50);
39 try test__floattisf(0x0007FB72E6000000, 0x1.FEDCBAp+50);
40 try test__floattisf(0x0007FB72E7000000, 0x1.FEDCBAp+50);
41 try test__floattisf(0x0007FB72E7FFFFFF, 0x1.FEDCBAp+50);
42 try test__floattisf(0x0007FB72E4000001, 0x1.FEDCBAp+50);
43 try test__floattisf(0x0007FB72E4000000, 0x1.FEDCB8p+50);
4444
45 test__floattisf(make_ti(0x0007FB72E8000000, 0), 0x1.FEDCBAp+114);
45 try test__floattisf(make_ti(0x0007FB72E8000000, 0), 0x1.FEDCBAp+114);
4646
47 test__floattisf(make_ti(0x0007FB72EA000000, 0), 0x1.FEDCBAp+114);
48 test__floattisf(make_ti(0x0007FB72EB000000, 0), 0x1.FEDCBAp+114);
49 test__floattisf(make_ti(0x0007FB72EBFFFFFF, 0), 0x1.FEDCBAp+114);
50 test__floattisf(make_ti(0x0007FB72EC000000, 0), 0x1.FEDCBCp+114);
51 test__floattisf(make_ti(0x0007FB72E8000001, 0), 0x1.FEDCBAp+114);
47 try test__floattisf(make_ti(0x0007FB72EA000000, 0), 0x1.FEDCBAp+114);
48 try test__floattisf(make_ti(0x0007FB72EB000000, 0), 0x1.FEDCBAp+114);
49 try test__floattisf(make_ti(0x0007FB72EBFFFFFF, 0), 0x1.FEDCBAp+114);
50 try test__floattisf(make_ti(0x0007FB72EC000000, 0), 0x1.FEDCBCp+114);
51 try test__floattisf(make_ti(0x0007FB72E8000001, 0), 0x1.FEDCBAp+114);
5252
53 test__floattisf(make_ti(0x0007FB72E6000000, 0), 0x1.FEDCBAp+114);
54 test__floattisf(make_ti(0x0007FB72E7000000, 0), 0x1.FEDCBAp+114);
55 test__floattisf(make_ti(0x0007FB72E7FFFFFF, 0), 0x1.FEDCBAp+114);
56 test__floattisf(make_ti(0x0007FB72E4000001, 0), 0x1.FEDCBAp+114);
57 test__floattisf(make_ti(0x0007FB72E4000000, 0), 0x1.FEDCB8p+114);
53 try test__floattisf(make_ti(0x0007FB72E6000000, 0), 0x1.FEDCBAp+114);
54 try test__floattisf(make_ti(0x0007FB72E7000000, 0), 0x1.FEDCBAp+114);
55 try test__floattisf(make_ti(0x0007FB72E7FFFFFF, 0), 0x1.FEDCBAp+114);
56 try test__floattisf(make_ti(0x0007FB72E4000001, 0), 0x1.FEDCBAp+114);
57 try test__floattisf(make_ti(0x0007FB72E4000000, 0), 0x1.FEDCB8p+114);
5858}
5959
6060fn make_ti(high: u64, low: u64) i128 {
lib/std/special/compiler_rt/floattitf_test.zig+70-70
......@@ -6,91 +6,91 @@
66const __floattitf = @import("floattitf.zig").__floattitf;
77const testing = @import("std").testing;
88
9fn test__floattitf(a: i128, expected: f128) void {
9fn test__floattitf(a: i128, expected: f128) !void {
1010 const x = __floattitf(a);
11 testing.expect(x == expected);
11 try testing.expect(x == expected);
1212}
1313
1414test "floattitf" {
15 test__floattitf(0, 0.0);
15 try test__floattitf(0, 0.0);
1616
17 test__floattitf(1, 1.0);
18 test__floattitf(2, 2.0);
19 test__floattitf(20, 20.0);
20 test__floattitf(-1, -1.0);
21 test__floattitf(-2, -2.0);
22 test__floattitf(-20, -20.0);
17 try test__floattitf(1, 1.0);
18 try test__floattitf(2, 2.0);
19 try test__floattitf(20, 20.0);
20 try test__floattitf(-1, -1.0);
21 try test__floattitf(-2, -2.0);
22 try test__floattitf(-20, -20.0);
2323
24 test__floattitf(0x7FFFFF8000000000, 0x1.FFFFFEp+62);
25 test__floattitf(0x7FFFFFFFFFFFF800, 0x1.FFFFFFFFFFFFEp+62);
26 test__floattitf(0x7FFFFF0000000000, 0x1.FFFFFCp+62);
27 test__floattitf(0x7FFFFFFFFFFFF000, 0x1.FFFFFFFFFFFFCp+62);
24 try test__floattitf(0x7FFFFF8000000000, 0x1.FFFFFEp+62);
25 try test__floattitf(0x7FFFFFFFFFFFF800, 0x1.FFFFFFFFFFFFEp+62);
26 try test__floattitf(0x7FFFFF0000000000, 0x1.FFFFFCp+62);
27 try test__floattitf(0x7FFFFFFFFFFFF000, 0x1.FFFFFFFFFFFFCp+62);
2828
29 test__floattitf(make_ti(0x8000008000000000, 0), -0x1.FFFFFEp+126);
30 test__floattitf(make_ti(0x8000000000000800, 0), -0x1.FFFFFFFFFFFFEp+126);
31 test__floattitf(make_ti(0x8000010000000000, 0), -0x1.FFFFFCp+126);
32 test__floattitf(make_ti(0x8000000000001000, 0), -0x1.FFFFFFFFFFFFCp+126);
29 try test__floattitf(make_ti(0x8000008000000000, 0), -0x1.FFFFFEp+126);
30 try test__floattitf(make_ti(0x8000000000000800, 0), -0x1.FFFFFFFFFFFFEp+126);
31 try test__floattitf(make_ti(0x8000010000000000, 0), -0x1.FFFFFCp+126);
32 try test__floattitf(make_ti(0x8000000000001000, 0), -0x1.FFFFFFFFFFFFCp+126);
3333
34 test__floattitf(make_ti(0x8000000000000000, 0), -0x1.000000p+127);
35 test__floattitf(make_ti(0x8000000000000001, 0), -0x1.FFFFFFFFFFFFFFFCp+126);
34 try test__floattitf(make_ti(0x8000000000000000, 0), -0x1.000000p+127);
35 try test__floattitf(make_ti(0x8000000000000001, 0), -0x1.FFFFFFFFFFFFFFFCp+126);
3636
37 test__floattitf(0x0007FB72E8000000, 0x1.FEDCBAp+50);
37 try test__floattitf(0x0007FB72E8000000, 0x1.FEDCBAp+50);
3838
39 test__floattitf(0x0007FB72EA000000, 0x1.FEDCBA8p+50);
40 test__floattitf(0x0007FB72EB000000, 0x1.FEDCBACp+50);
41 test__floattitf(0x0007FB72EBFFFFFF, 0x1.FEDCBAFFFFFFCp+50);
42 test__floattitf(0x0007FB72EC000000, 0x1.FEDCBBp+50);
43 test__floattitf(0x0007FB72E8000001, 0x1.FEDCBA0000004p+50);
39 try test__floattitf(0x0007FB72EA000000, 0x1.FEDCBA8p+50);
40 try test__floattitf(0x0007FB72EB000000, 0x1.FEDCBACp+50);
41 try test__floattitf(0x0007FB72EBFFFFFF, 0x1.FEDCBAFFFFFFCp+50);
42 try test__floattitf(0x0007FB72EC000000, 0x1.FEDCBBp+50);
43 try test__floattitf(0x0007FB72E8000001, 0x1.FEDCBA0000004p+50);
4444
45 test__floattitf(0x0007FB72E6000000, 0x1.FEDCB98p+50);
46 test__floattitf(0x0007FB72E7000000, 0x1.FEDCB9Cp+50);
47 test__floattitf(0x0007FB72E7FFFFFF, 0x1.FEDCB9FFFFFFCp+50);
48 test__floattitf(0x0007FB72E4000001, 0x1.FEDCB90000004p+50);
49 test__floattitf(0x0007FB72E4000000, 0x1.FEDCB9p+50);
45 try test__floattitf(0x0007FB72E6000000, 0x1.FEDCB98p+50);
46 try test__floattitf(0x0007FB72E7000000, 0x1.FEDCB9Cp+50);
47 try test__floattitf(0x0007FB72E7FFFFFF, 0x1.FEDCB9FFFFFFCp+50);
48 try test__floattitf(0x0007FB72E4000001, 0x1.FEDCB90000004p+50);
49 try test__floattitf(0x0007FB72E4000000, 0x1.FEDCB9p+50);
5050
51 test__floattitf(0x023479FD0E092DC0, 0x1.1A3CFE870496Ep+57);
52 test__floattitf(0x023479FD0E092DA1, 0x1.1A3CFE870496D08p+57);
53 test__floattitf(0x023479FD0E092DB0, 0x1.1A3CFE870496D8p+57);
54 test__floattitf(0x023479FD0E092DB8, 0x1.1A3CFE870496DCp+57);
55 test__floattitf(0x023479FD0E092DB6, 0x1.1A3CFE870496DBp+57);
56 test__floattitf(0x023479FD0E092DBF, 0x1.1A3CFE870496DF8p+57);
57 test__floattitf(0x023479FD0E092DC1, 0x1.1A3CFE870496E08p+57);
58 test__floattitf(0x023479FD0E092DC7, 0x1.1A3CFE870496E38p+57);
59 test__floattitf(0x023479FD0E092DC8, 0x1.1A3CFE870496E4p+57);
60 test__floattitf(0x023479FD0E092DCF, 0x1.1A3CFE870496E78p+57);
61 test__floattitf(0x023479FD0E092DD0, 0x1.1A3CFE870496E8p+57);
62 test__floattitf(0x023479FD0E092DD1, 0x1.1A3CFE870496E88p+57);
63 test__floattitf(0x023479FD0E092DD8, 0x1.1A3CFE870496ECp+57);
64 test__floattitf(0x023479FD0E092DDF, 0x1.1A3CFE870496EF8p+57);
65 test__floattitf(0x023479FD0E092DE0, 0x1.1A3CFE870496Fp+57);
51 try test__floattitf(0x023479FD0E092DC0, 0x1.1A3CFE870496Ep+57);
52 try test__floattitf(0x023479FD0E092DA1, 0x1.1A3CFE870496D08p+57);
53 try test__floattitf(0x023479FD0E092DB0, 0x1.1A3CFE870496D8p+57);
54 try test__floattitf(0x023479FD0E092DB8, 0x1.1A3CFE870496DCp+57);
55 try test__floattitf(0x023479FD0E092DB6, 0x1.1A3CFE870496DBp+57);
56 try test__floattitf(0x023479FD0E092DBF, 0x1.1A3CFE870496DF8p+57);
57 try test__floattitf(0x023479FD0E092DC1, 0x1.1A3CFE870496E08p+57);
58 try test__floattitf(0x023479FD0E092DC7, 0x1.1A3CFE870496E38p+57);
59 try test__floattitf(0x023479FD0E092DC8, 0x1.1A3CFE870496E4p+57);
60 try test__floattitf(0x023479FD0E092DCF, 0x1.1A3CFE870496E78p+57);
61 try test__floattitf(0x023479FD0E092DD0, 0x1.1A3CFE870496E8p+57);
62 try test__floattitf(0x023479FD0E092DD1, 0x1.1A3CFE870496E88p+57);
63 try test__floattitf(0x023479FD0E092DD8, 0x1.1A3CFE870496ECp+57);
64 try test__floattitf(0x023479FD0E092DDF, 0x1.1A3CFE870496EF8p+57);
65 try test__floattitf(0x023479FD0E092DE0, 0x1.1A3CFE870496Fp+57);
6666
67 test__floattitf(make_ti(0x023479FD0E092DC0, 0), 0x1.1A3CFE870496Ep+121);
68 test__floattitf(make_ti(0x023479FD0E092DA1, 1), 0x1.1A3CFE870496D08p+121);
69 test__floattitf(make_ti(0x023479FD0E092DB0, 2), 0x1.1A3CFE870496D8p+121);
70 test__floattitf(make_ti(0x023479FD0E092DB8, 3), 0x1.1A3CFE870496DCp+121);
71 test__floattitf(make_ti(0x023479FD0E092DB6, 4), 0x1.1A3CFE870496DBp+121);
72 test__floattitf(make_ti(0x023479FD0E092DBF, 5), 0x1.1A3CFE870496DF8p+121);
73 test__floattitf(make_ti(0x023479FD0E092DC1, 6), 0x1.1A3CFE870496E08p+121);
74 test__floattitf(make_ti(0x023479FD0E092DC7, 7), 0x1.1A3CFE870496E38p+121);
75 test__floattitf(make_ti(0x023479FD0E092DC8, 8), 0x1.1A3CFE870496E4p+121);
76 test__floattitf(make_ti(0x023479FD0E092DCF, 9), 0x1.1A3CFE870496E78p+121);
77 test__floattitf(make_ti(0x023479FD0E092DD0, 0), 0x1.1A3CFE870496E8p+121);
78 test__floattitf(make_ti(0x023479FD0E092DD1, 11), 0x1.1A3CFE870496E88p+121);
79 test__floattitf(make_ti(0x023479FD0E092DD8, 12), 0x1.1A3CFE870496ECp+121);
80 test__floattitf(make_ti(0x023479FD0E092DDF, 13), 0x1.1A3CFE870496EF8p+121);
81 test__floattitf(make_ti(0x023479FD0E092DE0, 14), 0x1.1A3CFE870496Fp+121);
67 try test__floattitf(make_ti(0x023479FD0E092DC0, 0), 0x1.1A3CFE870496Ep+121);
68 try test__floattitf(make_ti(0x023479FD0E092DA1, 1), 0x1.1A3CFE870496D08p+121);
69 try test__floattitf(make_ti(0x023479FD0E092DB0, 2), 0x1.1A3CFE870496D8p+121);
70 try test__floattitf(make_ti(0x023479FD0E092DB8, 3), 0x1.1A3CFE870496DCp+121);
71 try test__floattitf(make_ti(0x023479FD0E092DB6, 4), 0x1.1A3CFE870496DBp+121);
72 try test__floattitf(make_ti(0x023479FD0E092DBF, 5), 0x1.1A3CFE870496DF8p+121);
73 try test__floattitf(make_ti(0x023479FD0E092DC1, 6), 0x1.1A3CFE870496E08p+121);
74 try test__floattitf(make_ti(0x023479FD0E092DC7, 7), 0x1.1A3CFE870496E38p+121);
75 try test__floattitf(make_ti(0x023479FD0E092DC8, 8), 0x1.1A3CFE870496E4p+121);
76 try test__floattitf(make_ti(0x023479FD0E092DCF, 9), 0x1.1A3CFE870496E78p+121);
77 try test__floattitf(make_ti(0x023479FD0E092DD0, 0), 0x1.1A3CFE870496E8p+121);
78 try test__floattitf(make_ti(0x023479FD0E092DD1, 11), 0x1.1A3CFE870496E88p+121);
79 try test__floattitf(make_ti(0x023479FD0E092DD8, 12), 0x1.1A3CFE870496ECp+121);
80 try test__floattitf(make_ti(0x023479FD0E092DDF, 13), 0x1.1A3CFE870496EF8p+121);
81 try test__floattitf(make_ti(0x023479FD0E092DE0, 14), 0x1.1A3CFE870496Fp+121);
8282
83 test__floattitf(make_ti(0, 0xFFFFFFFFFFFFFFFF), 0x1.FFFFFFFFFFFFFFFEp+63);
83 try test__floattitf(make_ti(0, 0xFFFFFFFFFFFFFFFF), 0x1.FFFFFFFFFFFFFFFEp+63);
8484
85 test__floattitf(make_ti(0x123456789ABCDEF0, 0x123456789ABC2801), 0x1.23456789ABCDEF0123456789ABC3p+124);
86 test__floattitf(make_ti(0x123456789ABCDEF0, 0x123456789ABC3000), 0x1.23456789ABCDEF0123456789ABC3p+124);
87 test__floattitf(make_ti(0x123456789ABCDEF0, 0x123456789ABC37FF), 0x1.23456789ABCDEF0123456789ABC3p+124);
88 test__floattitf(make_ti(0x123456789ABCDEF0, 0x123456789ABC3800), 0x1.23456789ABCDEF0123456789ABC4p+124);
89 test__floattitf(make_ti(0x123456789ABCDEF0, 0x123456789ABC4000), 0x1.23456789ABCDEF0123456789ABC4p+124);
90 test__floattitf(make_ti(0x123456789ABCDEF0, 0x123456789ABC47FF), 0x1.23456789ABCDEF0123456789ABC4p+124);
91 test__floattitf(make_ti(0x123456789ABCDEF0, 0x123456789ABC4800), 0x1.23456789ABCDEF0123456789ABC4p+124);
92 test__floattitf(make_ti(0x123456789ABCDEF0, 0x123456789ABC4801), 0x1.23456789ABCDEF0123456789ABC5p+124);
93 test__floattitf(make_ti(0x123456789ABCDEF0, 0x123456789ABC57FF), 0x1.23456789ABCDEF0123456789ABC5p+124);
85 try test__floattitf(make_ti(0x123456789ABCDEF0, 0x123456789ABC2801), 0x1.23456789ABCDEF0123456789ABC3p+124);
86 try test__floattitf(make_ti(0x123456789ABCDEF0, 0x123456789ABC3000), 0x1.23456789ABCDEF0123456789ABC3p+124);
87 try test__floattitf(make_ti(0x123456789ABCDEF0, 0x123456789ABC37FF), 0x1.23456789ABCDEF0123456789ABC3p+124);
88 try test__floattitf(make_ti(0x123456789ABCDEF0, 0x123456789ABC3800), 0x1.23456789ABCDEF0123456789ABC4p+124);
89 try test__floattitf(make_ti(0x123456789ABCDEF0, 0x123456789ABC4000), 0x1.23456789ABCDEF0123456789ABC4p+124);
90 try test__floattitf(make_ti(0x123456789ABCDEF0, 0x123456789ABC47FF), 0x1.23456789ABCDEF0123456789ABC4p+124);
91 try test__floattitf(make_ti(0x123456789ABCDEF0, 0x123456789ABC4800), 0x1.23456789ABCDEF0123456789ABC4p+124);
92 try test__floattitf(make_ti(0x123456789ABCDEF0, 0x123456789ABC4801), 0x1.23456789ABCDEF0123456789ABC5p+124);
93 try test__floattitf(make_ti(0x123456789ABCDEF0, 0x123456789ABC57FF), 0x1.23456789ABCDEF0123456789ABC5p+124);
9494}
9595
9696fn make_ti(high: u64, low: u64) i128 {
lib/std/special/compiler_rt/floatundidf_test.zig+42-42
......@@ -6,50 +6,50 @@
66const __floatundidf = @import("floatundidf.zig").__floatundidf;
77const testing = @import("std").testing;
88
9fn test__floatundidf(a: u64, expected: f64) void {
9fn test__floatundidf(a: u64, expected: f64) !void {
1010 const r = __floatundidf(a);
11 testing.expect(r == expected);
11 try testing.expect(r == expected);
1212}
1313
1414test "floatundidf" {
15 test__floatundidf(0, 0.0);
16 test__floatundidf(1, 1.0);
17 test__floatundidf(2, 2.0);
18 test__floatundidf(20, 20.0);
19 test__floatundidf(0x7FFFFF8000000000, 0x1.FFFFFEp+62);
20 test__floatundidf(0x7FFFFFFFFFFFF800, 0x1.FFFFFFFFFFFFEp+62);
21 test__floatundidf(0x7FFFFF0000000000, 0x1.FFFFFCp+62);
22 test__floatundidf(0x7FFFFFFFFFFFF000, 0x1.FFFFFFFFFFFFCp+62);
23 test__floatundidf(0x8000008000000000, 0x1.000001p+63);
24 test__floatundidf(0x8000000000000800, 0x1.0000000000001p+63);
25 test__floatundidf(0x8000010000000000, 0x1.000002p+63);
26 test__floatundidf(0x8000000000001000, 0x1.0000000000002p+63);
27 test__floatundidf(0x8000000000000000, 0x1p+63);
28 test__floatundidf(0x8000000000000001, 0x1p+63);
29 test__floatundidf(0x0007FB72E8000000, 0x1.FEDCBAp+50);
30 test__floatundidf(0x0007FB72EA000000, 0x1.FEDCBA8p+50);
31 test__floatundidf(0x0007FB72EB000000, 0x1.FEDCBACp+50);
32 test__floatundidf(0x0007FB72EBFFFFFF, 0x1.FEDCBAFFFFFFCp+50);
33 test__floatundidf(0x0007FB72EC000000, 0x1.FEDCBBp+50);
34 test__floatundidf(0x0007FB72E8000001, 0x1.FEDCBA0000004p+50);
35 test__floatundidf(0x0007FB72E6000000, 0x1.FEDCB98p+50);
36 test__floatundidf(0x0007FB72E7000000, 0x1.FEDCB9Cp+50);
37 test__floatundidf(0x0007FB72E7FFFFFF, 0x1.FEDCB9FFFFFFCp+50);
38 test__floatundidf(0x0007FB72E4000001, 0x1.FEDCB90000004p+50);
39 test__floatundidf(0x0007FB72E4000000, 0x1.FEDCB9p+50);
40 test__floatundidf(0x023479FD0E092DC0, 0x1.1A3CFE870496Ep+57);
41 test__floatundidf(0x023479FD0E092DA1, 0x1.1A3CFE870496Dp+57);
42 test__floatundidf(0x023479FD0E092DB0, 0x1.1A3CFE870496Ep+57);
43 test__floatundidf(0x023479FD0E092DB8, 0x1.1A3CFE870496Ep+57);
44 test__floatundidf(0x023479FD0E092DB6, 0x1.1A3CFE870496Ep+57);
45 test__floatundidf(0x023479FD0E092DBF, 0x1.1A3CFE870496Ep+57);
46 test__floatundidf(0x023479FD0E092DC1, 0x1.1A3CFE870496Ep+57);
47 test__floatundidf(0x023479FD0E092DC7, 0x1.1A3CFE870496Ep+57);
48 test__floatundidf(0x023479FD0E092DC8, 0x1.1A3CFE870496Ep+57);
49 test__floatundidf(0x023479FD0E092DCF, 0x1.1A3CFE870496Ep+57);
50 test__floatundidf(0x023479FD0E092DD0, 0x1.1A3CFE870496Ep+57);
51 test__floatundidf(0x023479FD0E092DD1, 0x1.1A3CFE870496Fp+57);
52 test__floatundidf(0x023479FD0E092DD8, 0x1.1A3CFE870496Fp+57);
53 test__floatundidf(0x023479FD0E092DDF, 0x1.1A3CFE870496Fp+57);
54 test__floatundidf(0x023479FD0E092DE0, 0x1.1A3CFE870496Fp+57);
15 try test__floatundidf(0, 0.0);
16 try test__floatundidf(1, 1.0);
17 try test__floatundidf(2, 2.0);
18 try test__floatundidf(20, 20.0);
19 try test__floatundidf(0x7FFFFF8000000000, 0x1.FFFFFEp+62);
20 try test__floatundidf(0x7FFFFFFFFFFFF800, 0x1.FFFFFFFFFFFFEp+62);
21 try test__floatundidf(0x7FFFFF0000000000, 0x1.FFFFFCp+62);
22 try test__floatundidf(0x7FFFFFFFFFFFF000, 0x1.FFFFFFFFFFFFCp+62);
23 try test__floatundidf(0x8000008000000000, 0x1.000001p+63);
24 try test__floatundidf(0x8000000000000800, 0x1.0000000000001p+63);
25 try test__floatundidf(0x8000010000000000, 0x1.000002p+63);
26 try test__floatundidf(0x8000000000001000, 0x1.0000000000002p+63);
27 try test__floatundidf(0x8000000000000000, 0x1p+63);
28 try test__floatundidf(0x8000000000000001, 0x1p+63);
29 try test__floatundidf(0x0007FB72E8000000, 0x1.FEDCBAp+50);
30 try test__floatundidf(0x0007FB72EA000000, 0x1.FEDCBA8p+50);
31 try test__floatundidf(0x0007FB72EB000000, 0x1.FEDCBACp+50);
32 try test__floatundidf(0x0007FB72EBFFFFFF, 0x1.FEDCBAFFFFFFCp+50);
33 try test__floatundidf(0x0007FB72EC000000, 0x1.FEDCBBp+50);
34 try test__floatundidf(0x0007FB72E8000001, 0x1.FEDCBA0000004p+50);
35 try test__floatundidf(0x0007FB72E6000000, 0x1.FEDCB98p+50);
36 try test__floatundidf(0x0007FB72E7000000, 0x1.FEDCB9Cp+50);
37 try test__floatundidf(0x0007FB72E7FFFFFF, 0x1.FEDCB9FFFFFFCp+50);
38 try test__floatundidf(0x0007FB72E4000001, 0x1.FEDCB90000004p+50);
39 try test__floatundidf(0x0007FB72E4000000, 0x1.FEDCB9p+50);
40 try test__floatundidf(0x023479FD0E092DC0, 0x1.1A3CFE870496Ep+57);
41 try test__floatundidf(0x023479FD0E092DA1, 0x1.1A3CFE870496Dp+57);
42 try test__floatundidf(0x023479FD0E092DB0, 0x1.1A3CFE870496Ep+57);
43 try test__floatundidf(0x023479FD0E092DB8, 0x1.1A3CFE870496Ep+57);
44 try test__floatundidf(0x023479FD0E092DB6, 0x1.1A3CFE870496Ep+57);
45 try test__floatundidf(0x023479FD0E092DBF, 0x1.1A3CFE870496Ep+57);
46 try test__floatundidf(0x023479FD0E092DC1, 0x1.1A3CFE870496Ep+57);
47 try test__floatundidf(0x023479FD0E092DC7, 0x1.1A3CFE870496Ep+57);
48 try test__floatundidf(0x023479FD0E092DC8, 0x1.1A3CFE870496Ep+57);
49 try test__floatundidf(0x023479FD0E092DCF, 0x1.1A3CFE870496Ep+57);
50 try test__floatundidf(0x023479FD0E092DD0, 0x1.1A3CFE870496Ep+57);
51 try test__floatundidf(0x023479FD0E092DD1, 0x1.1A3CFE870496Fp+57);
52 try test__floatundidf(0x023479FD0E092DD8, 0x1.1A3CFE870496Fp+57);
53 try test__floatundidf(0x023479FD0E092DDF, 0x1.1A3CFE870496Fp+57);
54 try test__floatundidf(0x023479FD0E092DE0, 0x1.1A3CFE870496Fp+57);
5555}
lib/std/special/compiler_rt/floatundisf.zig+24-24
......@@ -66,31 +66,31 @@ pub fn __aeabi_ul2f(arg: u64) callconv(.AAPCS) f32 {
6666 return @call(.{ .modifier = .always_inline }, __floatundisf, .{arg});
6767}
6868
69fn test__floatundisf(a: u64, expected: f32) void {
70 std.testing.expectEqual(expected, __floatundisf(a));
69fn test__floatundisf(a: u64, expected: f32) !void {
70 try std.testing.expectEqual(expected, __floatundisf(a));
7171}
7272
7373test "floatundisf" {
74 test__floatundisf(0, 0.0);
75 test__floatundisf(1, 1.0);
76 test__floatundisf(2, 2.0);
77 test__floatundisf(0x7FFFFF8000000000, 0x1.FFFFFEp+62);
78 test__floatundisf(0x7FFFFF0000000000, 0x1.FFFFFCp+62);
79 test__floatundisf(0x8000008000000000, 0x1p+63);
80 test__floatundisf(0x8000010000000000, 0x1.000002p+63);
81 test__floatundisf(0x8000000000000000, 0x1p+63);
82 test__floatundisf(0x8000000000000001, 0x1p+63);
83 test__floatundisf(0xFFFFFFFFFFFFFFFE, 0x1p+64);
84 test__floatundisf(0xFFFFFFFFFFFFFFFF, 0x1p+64);
85 test__floatundisf(0x0007FB72E8000000, 0x1.FEDCBAp+50);
86 test__floatundisf(0x0007FB72EA000000, 0x1.FEDCBAp+50);
87 test__floatundisf(0x0007FB72EB000000, 0x1.FEDCBAp+50);
88 test__floatundisf(0x0007FB72EBFFFFFF, 0x1.FEDCBAp+50);
89 test__floatundisf(0x0007FB72EC000000, 0x1.FEDCBCp+50);
90 test__floatundisf(0x0007FB72E8000001, 0x1.FEDCBAp+50);
91 test__floatundisf(0x0007FB72E6000000, 0x1.FEDCBAp+50);
92 test__floatundisf(0x0007FB72E7000000, 0x1.FEDCBAp+50);
93 test__floatundisf(0x0007FB72E7FFFFFF, 0x1.FEDCBAp+50);
94 test__floatundisf(0x0007FB72E4000001, 0x1.FEDCBAp+50);
95 test__floatundisf(0x0007FB72E4000000, 0x1.FEDCB8p+50);
74 try test__floatundisf(0, 0.0);
75 try test__floatundisf(1, 1.0);
76 try test__floatundisf(2, 2.0);
77 try test__floatundisf(0x7FFFFF8000000000, 0x1.FFFFFEp+62);
78 try test__floatundisf(0x7FFFFF0000000000, 0x1.FFFFFCp+62);
79 try test__floatundisf(0x8000008000000000, 0x1p+63);
80 try test__floatundisf(0x8000010000000000, 0x1.000002p+63);
81 try test__floatundisf(0x8000000000000000, 0x1p+63);
82 try test__floatundisf(0x8000000000000001, 0x1p+63);
83 try test__floatundisf(0xFFFFFFFFFFFFFFFE, 0x1p+64);
84 try test__floatundisf(0xFFFFFFFFFFFFFFFF, 0x1p+64);
85 try test__floatundisf(0x0007FB72E8000000, 0x1.FEDCBAp+50);
86 try test__floatundisf(0x0007FB72EA000000, 0x1.FEDCBAp+50);
87 try test__floatundisf(0x0007FB72EB000000, 0x1.FEDCBAp+50);
88 try test__floatundisf(0x0007FB72EBFFFFFF, 0x1.FEDCBAp+50);
89 try test__floatundisf(0x0007FB72EC000000, 0x1.FEDCBCp+50);
90 try test__floatundisf(0x0007FB72E8000001, 0x1.FEDCBAp+50);
91 try test__floatundisf(0x0007FB72E6000000, 0x1.FEDCBAp+50);
92 try test__floatundisf(0x0007FB72E7000000, 0x1.FEDCBAp+50);
93 try test__floatundisf(0x0007FB72E7FFFFFF, 0x1.FEDCBAp+50);
94 try test__floatundisf(0x0007FB72E4000001, 0x1.FEDCBAp+50);
95 try test__floatundisf(0x0007FB72E4000000, 0x1.FEDCB8p+50);
9696}
lib/std/special/compiler_rt/floatunditf_test.zig+9-9
......@@ -5,7 +5,7 @@
55// and substantial portions of the software.
66const __floatunditf = @import("floatunditf.zig").__floatunditf;
77
8fn test__floatunditf(a: u64, expected_hi: u64, expected_lo: u64) void {
8fn test__floatunditf(a: u64, expected_hi: u64, expected_lo: u64) !void {
99 const x = __floatunditf(a);
1010
1111 const x_repr = @bitCast(u128, x);
......@@ -26,12 +26,12 @@ fn test__floatunditf(a: u64, expected_hi: u64, expected_lo: u64) void {
2626}
2727
2828test "floatunditf" {
29 test__floatunditf(0xffffffffffffffff, 0x403effffffffffff, 0xfffe000000000000);
30 test__floatunditf(0xfffffffffffffffe, 0x403effffffffffff, 0xfffc000000000000);
31 test__floatunditf(0x8000000000000000, 0x403e000000000000, 0x0);
32 test__floatunditf(0x7fffffffffffffff, 0x403dffffffffffff, 0xfffc000000000000);
33 test__floatunditf(0x123456789abcdef1, 0x403b23456789abcd, 0xef10000000000000);
34 test__floatunditf(0x2, 0x4000000000000000, 0x0);
35 test__floatunditf(0x1, 0x3fff000000000000, 0x0);
36 test__floatunditf(0x0, 0x0, 0x0);
29 try test__floatunditf(0xffffffffffffffff, 0x403effffffffffff, 0xfffe000000000000);
30 try test__floatunditf(0xfffffffffffffffe, 0x403effffffffffff, 0xfffc000000000000);
31 try test__floatunditf(0x8000000000000000, 0x403e000000000000, 0x0);
32 try test__floatunditf(0x7fffffffffffffff, 0x403dffffffffffff, 0xfffc000000000000);
33 try test__floatunditf(0x123456789abcdef1, 0x403b23456789abcd, 0xef10000000000000);
34 try test__floatunditf(0x2, 0x4000000000000000, 0x0);
35 try test__floatunditf(0x1, 0x3fff000000000000, 0x0);
36 try test__floatunditf(0x0, 0x0, 0x0);
3737}
lib/std/special/compiler_rt/floatunsidf.zig+7-7
......@@ -28,16 +28,16 @@ pub fn __aeabi_ui2d(arg: u32) callconv(.AAPCS) f64 {
2828 return @call(.{ .modifier = .always_inline }, __floatunsidf, .{arg});
2929}
3030
31fn test_one_floatunsidf(a: u32, expected: u64) void {
31fn test_one_floatunsidf(a: u32, expected: u64) !void {
3232 const r = __floatunsidf(a);
33 std.testing.expect(@bitCast(u64, r) == expected);
33 try std.testing.expect(@bitCast(u64, r) == expected);
3434}
3535
3636test "floatsidf" {
3737 // Test the produced bit pattern
38 test_one_floatunsidf(0, 0x0000000000000000);
39 test_one_floatunsidf(1, 0x3ff0000000000000);
40 test_one_floatunsidf(0x7FFFFFFF, 0x41dfffffffc00000);
41 test_one_floatunsidf(@intCast(u32, 0x80000000), 0x41e0000000000000);
42 test_one_floatunsidf(@intCast(u32, 0xFFFFFFFF), 0x41efffffffe00000);
38 try test_one_floatunsidf(0, 0x0000000000000000);
39 try test_one_floatunsidf(1, 0x3ff0000000000000);
40 try test_one_floatunsidf(0x7FFFFFFF, 0x41dfffffffc00000);
41 try test_one_floatunsidf(@intCast(u32, 0x80000000), 0x41e0000000000000);
42 try test_one_floatunsidf(@intCast(u32, 0xFFFFFFFF), 0x41efffffffe00000);
4343}
lib/std/special/compiler_rt/floatunsisf.zig+7-7
......@@ -48,16 +48,16 @@ pub fn __aeabi_ui2f(arg: u32) callconv(.AAPCS) f32 {
4848 return @call(.{ .modifier = .always_inline }, __floatunsisf, .{arg});
4949}
5050
51fn test_one_floatunsisf(a: u32, expected: u32) void {
51fn test_one_floatunsisf(a: u32, expected: u32) !void {
5252 const r = __floatunsisf(a);
53 std.testing.expect(@bitCast(u32, r) == expected);
53 try std.testing.expect(@bitCast(u32, r) == expected);
5454}
5555
5656test "floatunsisf" {
5757 // Test the produced bit pattern
58 test_one_floatunsisf(0, 0);
59 test_one_floatunsisf(1, 0x3f800000);
60 test_one_floatunsisf(0x7FFFFFFF, 0x4f000000);
61 test_one_floatunsisf(0x80000000, 0x4f000000);
62 test_one_floatunsisf(0xFFFFFFFF, 0x4f800000);
58 try test_one_floatunsisf(0, 0);
59 try test_one_floatunsisf(1, 0x3f800000);
60 try test_one_floatunsisf(0x7FFFFFFF, 0x4f000000);
61 try test_one_floatunsisf(0x80000000, 0x4f000000);
62 try test_one_floatunsisf(0xFFFFFFFF, 0x4f800000);
6363}
lib/std/special/compiler_rt/floatunsitf_test.zig+5-5
......@@ -5,7 +5,7 @@
55// and substantial portions of the software.
66const __floatunsitf = @import("floatunsitf.zig").__floatunsitf;
77
8fn test__floatunsitf(a: u64, expected_hi: u64, expected_lo: u64) void {
8fn test__floatunsitf(a: u64, expected_hi: u64, expected_lo: u64) !void {
99 const x = __floatunsitf(a);
1010
1111 const x_repr = @bitCast(u128, x);
......@@ -26,8 +26,8 @@ fn test__floatunsitf(a: u64, expected_hi: u64, expected_lo: u64) void {
2626}
2727
2828test "floatunsitf" {
29 test__floatunsitf(0x7fffffff, 0x401dfffffffc0000, 0x0);
30 test__floatunsitf(0, 0x0, 0x0);
31 test__floatunsitf(0xffffffff, 0x401efffffffe0000, 0x0);
32 test__floatunsitf(0x12345678, 0x401b234567800000, 0x0);
29 try test__floatunsitf(0x7fffffff, 0x401dfffffffc0000, 0x0);
30 try test__floatunsitf(0, 0x0, 0x0);
31 try test__floatunsitf(0xffffffff, 0x401efffffffe0000, 0x0);
32 try test__floatunsitf(0x12345678, 0x401b234567800000, 0x0);
3333}
lib/std/special/compiler_rt/floatuntidf_test.zig+57-57
......@@ -6,76 +6,76 @@
66const __floatuntidf = @import("floatuntidf.zig").__floatuntidf;
77const testing = @import("std").testing;
88
9fn test__floatuntidf(a: u128, expected: f64) void {
9fn test__floatuntidf(a: u128, expected: f64) !void {
1010 const x = __floatuntidf(a);
11 testing.expect(x == expected);
11 try testing.expect(x == expected);
1212}
1313
1414test "floatuntidf" {
15 test__floatuntidf(0, 0.0);
15 try test__floatuntidf(0, 0.0);
1616
17 test__floatuntidf(1, 1.0);
18 test__floatuntidf(2, 2.0);
19 test__floatuntidf(20, 20.0);
17 try test__floatuntidf(1, 1.0);
18 try test__floatuntidf(2, 2.0);
19 try test__floatuntidf(20, 20.0);
2020
21 test__floatuntidf(0x7FFFFF8000000000, 0x1.FFFFFEp+62);
22 test__floatuntidf(0x7FFFFFFFFFFFF800, 0x1.FFFFFFFFFFFFEp+62);
23 test__floatuntidf(0x7FFFFF0000000000, 0x1.FFFFFCp+62);
24 test__floatuntidf(0x7FFFFFFFFFFFF000, 0x1.FFFFFFFFFFFFCp+62);
21 try test__floatuntidf(0x7FFFFF8000000000, 0x1.FFFFFEp+62);
22 try test__floatuntidf(0x7FFFFFFFFFFFF800, 0x1.FFFFFFFFFFFFEp+62);
23 try test__floatuntidf(0x7FFFFF0000000000, 0x1.FFFFFCp+62);
24 try test__floatuntidf(0x7FFFFFFFFFFFF000, 0x1.FFFFFFFFFFFFCp+62);
2525
26 test__floatuntidf(make_ti(0x8000008000000000, 0), 0x1.000001p+127);
27 test__floatuntidf(make_ti(0x8000000000000800, 0), 0x1.0000000000001p+127);
28 test__floatuntidf(make_ti(0x8000010000000000, 0), 0x1.000002p+127);
29 test__floatuntidf(make_ti(0x8000000000001000, 0), 0x1.0000000000002p+127);
26 try test__floatuntidf(make_ti(0x8000008000000000, 0), 0x1.000001p+127);
27 try test__floatuntidf(make_ti(0x8000000000000800, 0), 0x1.0000000000001p+127);
28 try test__floatuntidf(make_ti(0x8000010000000000, 0), 0x1.000002p+127);
29 try test__floatuntidf(make_ti(0x8000000000001000, 0), 0x1.0000000000002p+127);
3030
31 test__floatuntidf(make_ti(0x8000000000000000, 0), 0x1.000000p+127);
32 test__floatuntidf(make_ti(0x8000000000000001, 0), 0x1.0000000000000002p+127);
31 try test__floatuntidf(make_ti(0x8000000000000000, 0), 0x1.000000p+127);
32 try test__floatuntidf(make_ti(0x8000000000000001, 0), 0x1.0000000000000002p+127);
3333
34 test__floatuntidf(0x0007FB72E8000000, 0x1.FEDCBAp+50);
34 try test__floatuntidf(0x0007FB72E8000000, 0x1.FEDCBAp+50);
3535
36 test__floatuntidf(0x0007FB72EA000000, 0x1.FEDCBA8p+50);
37 test__floatuntidf(0x0007FB72EB000000, 0x1.FEDCBACp+50);
38 test__floatuntidf(0x0007FB72EBFFFFFF, 0x1.FEDCBAFFFFFFCp+50);
39 test__floatuntidf(0x0007FB72EC000000, 0x1.FEDCBBp+50);
40 test__floatuntidf(0x0007FB72E8000001, 0x1.FEDCBA0000004p+50);
36 try test__floatuntidf(0x0007FB72EA000000, 0x1.FEDCBA8p+50);
37 try test__floatuntidf(0x0007FB72EB000000, 0x1.FEDCBACp+50);
38 try test__floatuntidf(0x0007FB72EBFFFFFF, 0x1.FEDCBAFFFFFFCp+50);
39 try test__floatuntidf(0x0007FB72EC000000, 0x1.FEDCBBp+50);
40 try test__floatuntidf(0x0007FB72E8000001, 0x1.FEDCBA0000004p+50);
4141
42 test__floatuntidf(0x0007FB72E6000000, 0x1.FEDCB98p+50);
43 test__floatuntidf(0x0007FB72E7000000, 0x1.FEDCB9Cp+50);
44 test__floatuntidf(0x0007FB72E7FFFFFF, 0x1.FEDCB9FFFFFFCp+50);
45 test__floatuntidf(0x0007FB72E4000001, 0x1.FEDCB90000004p+50);
46 test__floatuntidf(0x0007FB72E4000000, 0x1.FEDCB9p+50);
42 try test__floatuntidf(0x0007FB72E6000000, 0x1.FEDCB98p+50);
43 try test__floatuntidf(0x0007FB72E7000000, 0x1.FEDCB9Cp+50);
44 try test__floatuntidf(0x0007FB72E7FFFFFF, 0x1.FEDCB9FFFFFFCp+50);
45 try test__floatuntidf(0x0007FB72E4000001, 0x1.FEDCB90000004p+50);
46 try test__floatuntidf(0x0007FB72E4000000, 0x1.FEDCB9p+50);
4747
48 test__floatuntidf(0x023479FD0E092DC0, 0x1.1A3CFE870496Ep+57);
49 test__floatuntidf(0x023479FD0E092DA1, 0x1.1A3CFE870496Dp+57);
50 test__floatuntidf(0x023479FD0E092DB0, 0x1.1A3CFE870496Ep+57);
51 test__floatuntidf(0x023479FD0E092DB8, 0x1.1A3CFE870496Ep+57);
52 test__floatuntidf(0x023479FD0E092DB6, 0x1.1A3CFE870496Ep+57);
53 test__floatuntidf(0x023479FD0E092DBF, 0x1.1A3CFE870496Ep+57);
54 test__floatuntidf(0x023479FD0E092DC1, 0x1.1A3CFE870496Ep+57);
55 test__floatuntidf(0x023479FD0E092DC7, 0x1.1A3CFE870496Ep+57);
56 test__floatuntidf(0x023479FD0E092DC8, 0x1.1A3CFE870496Ep+57);
57 test__floatuntidf(0x023479FD0E092DCF, 0x1.1A3CFE870496Ep+57);
58 test__floatuntidf(0x023479FD0E092DD0, 0x1.1A3CFE870496Ep+57);
59 test__floatuntidf(0x023479FD0E092DD1, 0x1.1A3CFE870496Fp+57);
60 test__floatuntidf(0x023479FD0E092DD8, 0x1.1A3CFE870496Fp+57);
61 test__floatuntidf(0x023479FD0E092DDF, 0x1.1A3CFE870496Fp+57);
62 test__floatuntidf(0x023479FD0E092DE0, 0x1.1A3CFE870496Fp+57);
48 try test__floatuntidf(0x023479FD0E092DC0, 0x1.1A3CFE870496Ep+57);
49 try test__floatuntidf(0x023479FD0E092DA1, 0x1.1A3CFE870496Dp+57);
50 try test__floatuntidf(0x023479FD0E092DB0, 0x1.1A3CFE870496Ep+57);
51 try test__floatuntidf(0x023479FD0E092DB8, 0x1.1A3CFE870496Ep+57);
52 try test__floatuntidf(0x023479FD0E092DB6, 0x1.1A3CFE870496Ep+57);
53 try test__floatuntidf(0x023479FD0E092DBF, 0x1.1A3CFE870496Ep+57);
54 try test__floatuntidf(0x023479FD0E092DC1, 0x1.1A3CFE870496Ep+57);
55 try test__floatuntidf(0x023479FD0E092DC7, 0x1.1A3CFE870496Ep+57);
56 try test__floatuntidf(0x023479FD0E092DC8, 0x1.1A3CFE870496Ep+57);
57 try test__floatuntidf(0x023479FD0E092DCF, 0x1.1A3CFE870496Ep+57);
58 try test__floatuntidf(0x023479FD0E092DD0, 0x1.1A3CFE870496Ep+57);
59 try test__floatuntidf(0x023479FD0E092DD1, 0x1.1A3CFE870496Fp+57);
60 try test__floatuntidf(0x023479FD0E092DD8, 0x1.1A3CFE870496Fp+57);
61 try test__floatuntidf(0x023479FD0E092DDF, 0x1.1A3CFE870496Fp+57);
62 try test__floatuntidf(0x023479FD0E092DE0, 0x1.1A3CFE870496Fp+57);
6363
64 test__floatuntidf(make_ti(0x023479FD0E092DC0, 0), 0x1.1A3CFE870496Ep+121);
65 test__floatuntidf(make_ti(0x023479FD0E092DA1, 1), 0x1.1A3CFE870496Dp+121);
66 test__floatuntidf(make_ti(0x023479FD0E092DB0, 2), 0x1.1A3CFE870496Ep+121);
67 test__floatuntidf(make_ti(0x023479FD0E092DB8, 3), 0x1.1A3CFE870496Ep+121);
68 test__floatuntidf(make_ti(0x023479FD0E092DB6, 4), 0x1.1A3CFE870496Ep+121);
69 test__floatuntidf(make_ti(0x023479FD0E092DBF, 5), 0x1.1A3CFE870496Ep+121);
70 test__floatuntidf(make_ti(0x023479FD0E092DC1, 6), 0x1.1A3CFE870496Ep+121);
71 test__floatuntidf(make_ti(0x023479FD0E092DC7, 7), 0x1.1A3CFE870496Ep+121);
72 test__floatuntidf(make_ti(0x023479FD0E092DC8, 8), 0x1.1A3CFE870496Ep+121);
73 test__floatuntidf(make_ti(0x023479FD0E092DCF, 9), 0x1.1A3CFE870496Ep+121);
74 test__floatuntidf(make_ti(0x023479FD0E092DD0, 0), 0x1.1A3CFE870496Ep+121);
75 test__floatuntidf(make_ti(0x023479FD0E092DD1, 11), 0x1.1A3CFE870496Fp+121);
76 test__floatuntidf(make_ti(0x023479FD0E092DD8, 12), 0x1.1A3CFE870496Fp+121);
77 test__floatuntidf(make_ti(0x023479FD0E092DDF, 13), 0x1.1A3CFE870496Fp+121);
78 test__floatuntidf(make_ti(0x023479FD0E092DE0, 14), 0x1.1A3CFE870496Fp+121);
64 try test__floatuntidf(make_ti(0x023479FD0E092DC0, 0), 0x1.1A3CFE870496Ep+121);
65 try test__floatuntidf(make_ti(0x023479FD0E092DA1, 1), 0x1.1A3CFE870496Dp+121);
66 try test__floatuntidf(make_ti(0x023479FD0E092DB0, 2), 0x1.1A3CFE870496Ep+121);
67 try test__floatuntidf(make_ti(0x023479FD0E092DB8, 3), 0x1.1A3CFE870496Ep+121);
68 try test__floatuntidf(make_ti(0x023479FD0E092DB6, 4), 0x1.1A3CFE870496Ep+121);
69 try test__floatuntidf(make_ti(0x023479FD0E092DBF, 5), 0x1.1A3CFE870496Ep+121);
70 try test__floatuntidf(make_ti(0x023479FD0E092DC1, 6), 0x1.1A3CFE870496Ep+121);
71 try test__floatuntidf(make_ti(0x023479FD0E092DC7, 7), 0x1.1A3CFE870496Ep+121);
72 try test__floatuntidf(make_ti(0x023479FD0E092DC8, 8), 0x1.1A3CFE870496Ep+121);
73 try test__floatuntidf(make_ti(0x023479FD0E092DCF, 9), 0x1.1A3CFE870496Ep+121);
74 try test__floatuntidf(make_ti(0x023479FD0E092DD0, 0), 0x1.1A3CFE870496Ep+121);
75 try test__floatuntidf(make_ti(0x023479FD0E092DD1, 11), 0x1.1A3CFE870496Fp+121);
76 try test__floatuntidf(make_ti(0x023479FD0E092DD8, 12), 0x1.1A3CFE870496Fp+121);
77 try test__floatuntidf(make_ti(0x023479FD0E092DDF, 13), 0x1.1A3CFE870496Fp+121);
78 try test__floatuntidf(make_ti(0x023479FD0E092DE0, 14), 0x1.1A3CFE870496Fp+121);
7979}
8080
8181fn make_ti(high: u64, low: u64) u128 {
lib/std/special/compiler_rt/floatuntisf_test.zig+44-44
......@@ -6,67 +6,67 @@
66const __floatuntisf = @import("floatuntisf.zig").__floatuntisf;
77const testing = @import("std").testing;
88
9fn test__floatuntisf(a: u128, expected: f32) void {
9fn test__floatuntisf(a: u128, expected: f32) !void {
1010 const x = __floatuntisf(a);
11 testing.expect(x == expected);
11 try testing.expect(x == expected);
1212}
1313
1414test "floatuntisf" {
15 test__floatuntisf(0, 0.0);
15 try test__floatuntisf(0, 0.0);
1616
17 test__floatuntisf(1, 1.0);
18 test__floatuntisf(2, 2.0);
19 test__floatuntisf(20, 20.0);
17 try test__floatuntisf(1, 1.0);
18 try test__floatuntisf(2, 2.0);
19 try test__floatuntisf(20, 20.0);
2020
21 test__floatuntisf(0x7FFFFF8000000000, 0x1.FFFFFEp+62);
22 test__floatuntisf(0x7FFFFF0000000000, 0x1.FFFFFCp+62);
21 try test__floatuntisf(0x7FFFFF8000000000, 0x1.FFFFFEp+62);
22 try test__floatuntisf(0x7FFFFF0000000000, 0x1.FFFFFCp+62);
2323
24 test__floatuntisf(make_ti(0x8000008000000000, 0), 0x1.000001p+127);
25 test__floatuntisf(make_ti(0x8000000000000800, 0), 0x1.0p+127);
26 test__floatuntisf(make_ti(0x8000010000000000, 0), 0x1.000002p+127);
24 try test__floatuntisf(make_ti(0x8000008000000000, 0), 0x1.000001p+127);
25 try test__floatuntisf(make_ti(0x8000000000000800, 0), 0x1.0p+127);
26 try test__floatuntisf(make_ti(0x8000010000000000, 0), 0x1.000002p+127);
2727
28 test__floatuntisf(make_ti(0x8000000000000000, 0), 0x1.000000p+127);
28 try test__floatuntisf(make_ti(0x8000000000000000, 0), 0x1.000000p+127);
2929
30 test__floatuntisf(0x0007FB72E8000000, 0x1.FEDCBAp+50);
30 try test__floatuntisf(0x0007FB72E8000000, 0x1.FEDCBAp+50);
3131
32 test__floatuntisf(0x0007FB72EA000000, 0x1.FEDCBA8p+50);
33 test__floatuntisf(0x0007FB72EB000000, 0x1.FEDCBACp+50);
32 try test__floatuntisf(0x0007FB72EA000000, 0x1.FEDCBA8p+50);
33 try test__floatuntisf(0x0007FB72EB000000, 0x1.FEDCBACp+50);
3434
35 test__floatuntisf(0x0007FB72EC000000, 0x1.FEDCBBp+50);
35 try test__floatuntisf(0x0007FB72EC000000, 0x1.FEDCBBp+50);
3636
37 test__floatuntisf(0x0007FB72E6000000, 0x1.FEDCB98p+50);
38 test__floatuntisf(0x0007FB72E7000000, 0x1.FEDCB9Cp+50);
39 test__floatuntisf(0x0007FB72E4000000, 0x1.FEDCB9p+50);
37 try test__floatuntisf(0x0007FB72E6000000, 0x1.FEDCB98p+50);
38 try test__floatuntisf(0x0007FB72E7000000, 0x1.FEDCB9Cp+50);
39 try test__floatuntisf(0x0007FB72E4000000, 0x1.FEDCB9p+50);
4040
41 test__floatuntisf(0xFFFFFFFFFFFFFFFE, 0x1p+64);
42 test__floatuntisf(0xFFFFFFFFFFFFFFFF, 0x1p+64);
41 try test__floatuntisf(0xFFFFFFFFFFFFFFFE, 0x1p+64);
42 try test__floatuntisf(0xFFFFFFFFFFFFFFFF, 0x1p+64);
4343
44 test__floatuntisf(0x0007FB72E8000000, 0x1.FEDCBAp+50);
44 try test__floatuntisf(0x0007FB72E8000000, 0x1.FEDCBAp+50);
4545
46 test__floatuntisf(0x0007FB72EA000000, 0x1.FEDCBAp+50);
47 test__floatuntisf(0x0007FB72EB000000, 0x1.FEDCBAp+50);
48 test__floatuntisf(0x0007FB72EBFFFFFF, 0x1.FEDCBAp+50);
49 test__floatuntisf(0x0007FB72EC000000, 0x1.FEDCBCp+50);
50 test__floatuntisf(0x0007FB72E8000001, 0x1.FEDCBAp+50);
46 try test__floatuntisf(0x0007FB72EA000000, 0x1.FEDCBAp+50);
47 try test__floatuntisf(0x0007FB72EB000000, 0x1.FEDCBAp+50);
48 try test__floatuntisf(0x0007FB72EBFFFFFF, 0x1.FEDCBAp+50);
49 try test__floatuntisf(0x0007FB72EC000000, 0x1.FEDCBCp+50);
50 try test__floatuntisf(0x0007FB72E8000001, 0x1.FEDCBAp+50);
5151
52 test__floatuntisf(0x0007FB72E6000000, 0x1.FEDCBAp+50);
53 test__floatuntisf(0x0007FB72E7000000, 0x1.FEDCBAp+50);
54 test__floatuntisf(0x0007FB72E7FFFFFF, 0x1.FEDCBAp+50);
55 test__floatuntisf(0x0007FB72E4000001, 0x1.FEDCBAp+50);
56 test__floatuntisf(0x0007FB72E4000000, 0x1.FEDCB8p+50);
52 try test__floatuntisf(0x0007FB72E6000000, 0x1.FEDCBAp+50);
53 try test__floatuntisf(0x0007FB72E7000000, 0x1.FEDCBAp+50);
54 try test__floatuntisf(0x0007FB72E7FFFFFF, 0x1.FEDCBAp+50);
55 try test__floatuntisf(0x0007FB72E4000001, 0x1.FEDCBAp+50);
56 try test__floatuntisf(0x0007FB72E4000000, 0x1.FEDCB8p+50);
5757
58 test__floatuntisf(make_ti(0x0000000000001FED, 0xCB90000000000001), 0x1.FEDCBAp+76);
59 test__floatuntisf(make_ti(0x0000000000001FED, 0xCBA0000000000000), 0x1.FEDCBAp+76);
60 test__floatuntisf(make_ti(0x0000000000001FED, 0xCBAFFFFFFFFFFFFF), 0x1.FEDCBAp+76);
61 test__floatuntisf(make_ti(0x0000000000001FED, 0xCBB0000000000000), 0x1.FEDCBCp+76);
62 test__floatuntisf(make_ti(0x0000000000001FED, 0xCBB0000000000001), 0x1.FEDCBCp+76);
63 test__floatuntisf(make_ti(0x0000000000001FED, 0xCBBFFFFFFFFFFFFF), 0x1.FEDCBCp+76);
64 test__floatuntisf(make_ti(0x0000000000001FED, 0xCBC0000000000000), 0x1.FEDCBCp+76);
65 test__floatuntisf(make_ti(0x0000000000001FED, 0xCBC0000000000001), 0x1.FEDCBCp+76);
66 test__floatuntisf(make_ti(0x0000000000001FED, 0xCBD0000000000000), 0x1.FEDCBCp+76);
67 test__floatuntisf(make_ti(0x0000000000001FED, 0xCBD0000000000001), 0x1.FEDCBEp+76);
68 test__floatuntisf(make_ti(0x0000000000001FED, 0xCBDFFFFFFFFFFFFF), 0x1.FEDCBEp+76);
69 test__floatuntisf(make_ti(0x0000000000001FED, 0xCBE0000000000000), 0x1.FEDCBEp+76);
58 try test__floatuntisf(make_ti(0x0000000000001FED, 0xCB90000000000001), 0x1.FEDCBAp+76);
59 try test__floatuntisf(make_ti(0x0000000000001FED, 0xCBA0000000000000), 0x1.FEDCBAp+76);
60 try test__floatuntisf(make_ti(0x0000000000001FED, 0xCBAFFFFFFFFFFFFF), 0x1.FEDCBAp+76);
61 try test__floatuntisf(make_ti(0x0000000000001FED, 0xCBB0000000000000), 0x1.FEDCBCp+76);
62 try test__floatuntisf(make_ti(0x0000000000001FED, 0xCBB0000000000001), 0x1.FEDCBCp+76);
63 try test__floatuntisf(make_ti(0x0000000000001FED, 0xCBBFFFFFFFFFFFFF), 0x1.FEDCBCp+76);
64 try test__floatuntisf(make_ti(0x0000000000001FED, 0xCBC0000000000000), 0x1.FEDCBCp+76);
65 try test__floatuntisf(make_ti(0x0000000000001FED, 0xCBC0000000000001), 0x1.FEDCBCp+76);
66 try test__floatuntisf(make_ti(0x0000000000001FED, 0xCBD0000000000000), 0x1.FEDCBCp+76);
67 try test__floatuntisf(make_ti(0x0000000000001FED, 0xCBD0000000000001), 0x1.FEDCBEp+76);
68 try test__floatuntisf(make_ti(0x0000000000001FED, 0xCBDFFFFFFFFFFFFF), 0x1.FEDCBEp+76);
69 try test__floatuntisf(make_ti(0x0000000000001FED, 0xCBE0000000000000), 0x1.FEDCBEp+76);
7070}
7171
7272fn make_ti(high: u64, low: u64) u128 {
lib/std/special/compiler_rt/floatuntitf_test.zig+72-72
......@@ -6,94 +6,94 @@
66const __floatuntitf = @import("floatuntitf.zig").__floatuntitf;
77const testing = @import("std").testing;
88
9fn test__floatuntitf(a: u128, expected: f128) void {
9fn test__floatuntitf(a: u128, expected: f128) !void {
1010 const x = __floatuntitf(a);
11 testing.expect(x == expected);
11 try testing.expect(x == expected);
1212}
1313
1414test "floatuntitf" {
15 test__floatuntitf(0, 0.0);
15 try test__floatuntitf(0, 0.0);
1616
17 test__floatuntitf(1, 1.0);
18 test__floatuntitf(2, 2.0);
19 test__floatuntitf(20, 20.0);
17 try test__floatuntitf(1, 1.0);
18 try test__floatuntitf(2, 2.0);
19 try test__floatuntitf(20, 20.0);
2020
21 test__floatuntitf(0x7FFFFF8000000000, 0x1.FFFFFEp+62);
22 test__floatuntitf(0x7FFFFFFFFFFFF800, 0x1.FFFFFFFFFFFFEp+62);
23 test__floatuntitf(0x7FFFFF0000000000, 0x1.FFFFFCp+62);
24 test__floatuntitf(0x7FFFFFFFFFFFF000, 0x1.FFFFFFFFFFFFCp+62);
25 test__floatuntitf(0x7FFFFFFFFFFFFFFF, 0xF.FFFFFFFFFFFFFFEp+59);
26 test__floatuntitf(0xFFFFFFFFFFFFFFFE, 0xF.FFFFFFFFFFFFFFEp+60);
27 test__floatuntitf(0xFFFFFFFFFFFFFFFF, 0xF.FFFFFFFFFFFFFFFp+60);
21 try test__floatuntitf(0x7FFFFF8000000000, 0x1.FFFFFEp+62);
22 try test__floatuntitf(0x7FFFFFFFFFFFF800, 0x1.FFFFFFFFFFFFEp+62);
23 try test__floatuntitf(0x7FFFFF0000000000, 0x1.FFFFFCp+62);
24 try test__floatuntitf(0x7FFFFFFFFFFFF000, 0x1.FFFFFFFFFFFFCp+62);
25 try test__floatuntitf(0x7FFFFFFFFFFFFFFF, 0xF.FFFFFFFFFFFFFFEp+59);
26 try test__floatuntitf(0xFFFFFFFFFFFFFFFE, 0xF.FFFFFFFFFFFFFFEp+60);
27 try test__floatuntitf(0xFFFFFFFFFFFFFFFF, 0xF.FFFFFFFFFFFFFFFp+60);
2828
29 test__floatuntitf(0x8000008000000000, 0x8.000008p+60);
30 test__floatuntitf(0x8000000000000800, 0x8.0000000000008p+60);
31 test__floatuntitf(0x8000010000000000, 0x8.00001p+60);
32 test__floatuntitf(0x8000000000001000, 0x8.000000000001p+60);
29 try test__floatuntitf(0x8000008000000000, 0x8.000008p+60);
30 try test__floatuntitf(0x8000000000000800, 0x8.0000000000008p+60);
31 try test__floatuntitf(0x8000010000000000, 0x8.00001p+60);
32 try test__floatuntitf(0x8000000000001000, 0x8.000000000001p+60);
3333
34 test__floatuntitf(0x8000000000000000, 0x8p+60);
35 test__floatuntitf(0x8000000000000001, 0x8.000000000000001p+60);
34 try test__floatuntitf(0x8000000000000000, 0x8p+60);
35 try test__floatuntitf(0x8000000000000001, 0x8.000000000000001p+60);
3636
37 test__floatuntitf(0x0007FB72E8000000, 0x1.FEDCBAp+50);
37 try test__floatuntitf(0x0007FB72E8000000, 0x1.FEDCBAp+50);
3838
39 test__floatuntitf(0x0007FB72EA000000, 0x1.FEDCBA8p+50);
40 test__floatuntitf(0x0007FB72EB000000, 0x1.FEDCBACp+50);
41 test__floatuntitf(0x0007FB72EBFFFFFF, 0x1.FEDCBAFFFFFFCp+50);
42 test__floatuntitf(0x0007FB72EC000000, 0x1.FEDCBBp+50);
43 test__floatuntitf(0x0007FB72E8000001, 0x1.FEDCBA0000004p+50);
39 try test__floatuntitf(0x0007FB72EA000000, 0x1.FEDCBA8p+50);
40 try test__floatuntitf(0x0007FB72EB000000, 0x1.FEDCBACp+50);
41 try test__floatuntitf(0x0007FB72EBFFFFFF, 0x1.FEDCBAFFFFFFCp+50);
42 try test__floatuntitf(0x0007FB72EC000000, 0x1.FEDCBBp+50);
43 try test__floatuntitf(0x0007FB72E8000001, 0x1.FEDCBA0000004p+50);
4444
45 test__floatuntitf(0x0007FB72E6000000, 0x1.FEDCB98p+50);
46 test__floatuntitf(0x0007FB72E7000000, 0x1.FEDCB9Cp+50);
47 test__floatuntitf(0x0007FB72E7FFFFFF, 0x1.FEDCB9FFFFFFCp+50);
48 test__floatuntitf(0x0007FB72E4000001, 0x1.FEDCB90000004p+50);
49 test__floatuntitf(0x0007FB72E4000000, 0x1.FEDCB9p+50);
45 try test__floatuntitf(0x0007FB72E6000000, 0x1.FEDCB98p+50);
46 try test__floatuntitf(0x0007FB72E7000000, 0x1.FEDCB9Cp+50);
47 try test__floatuntitf(0x0007FB72E7FFFFFF, 0x1.FEDCB9FFFFFFCp+50);
48 try test__floatuntitf(0x0007FB72E4000001, 0x1.FEDCB90000004p+50);
49 try test__floatuntitf(0x0007FB72E4000000, 0x1.FEDCB9p+50);
5050
51 test__floatuntitf(0x023479FD0E092DC0, 0x1.1A3CFE870496Ep+57);
52 test__floatuntitf(0x023479FD0E092DA1, 0x1.1A3CFE870496D08p+57);
53 test__floatuntitf(0x023479FD0E092DB0, 0x1.1A3CFE870496D8p+57);
54 test__floatuntitf(0x023479FD0E092DB8, 0x1.1A3CFE870496DCp+57);
55 test__floatuntitf(0x023479FD0E092DB6, 0x1.1A3CFE870496DBp+57);
56 test__floatuntitf(0x023479FD0E092DBF, 0x1.1A3CFE870496DF8p+57);
57 test__floatuntitf(0x023479FD0E092DC1, 0x1.1A3CFE870496E08p+57);
58 test__floatuntitf(0x023479FD0E092DC7, 0x1.1A3CFE870496E38p+57);
59 test__floatuntitf(0x023479FD0E092DC8, 0x1.1A3CFE870496E4p+57);
60 test__floatuntitf(0x023479FD0E092DCF, 0x1.1A3CFE870496E78p+57);
61 test__floatuntitf(0x023479FD0E092DD0, 0x1.1A3CFE870496E8p+57);
62 test__floatuntitf(0x023479FD0E092DD1, 0x1.1A3CFE870496E88p+57);
63 test__floatuntitf(0x023479FD0E092DD8, 0x1.1A3CFE870496ECp+57);
64 test__floatuntitf(0x023479FD0E092DDF, 0x1.1A3CFE870496EF8p+57);
65 test__floatuntitf(0x023479FD0E092DE0, 0x1.1A3CFE870496Fp+57);
51 try test__floatuntitf(0x023479FD0E092DC0, 0x1.1A3CFE870496Ep+57);
52 try test__floatuntitf(0x023479FD0E092DA1, 0x1.1A3CFE870496D08p+57);
53 try test__floatuntitf(0x023479FD0E092DB0, 0x1.1A3CFE870496D8p+57);
54 try test__floatuntitf(0x023479FD0E092DB8, 0x1.1A3CFE870496DCp+57);
55 try test__floatuntitf(0x023479FD0E092DB6, 0x1.1A3CFE870496DBp+57);
56 try test__floatuntitf(0x023479FD0E092DBF, 0x1.1A3CFE870496DF8p+57);
57 try test__floatuntitf(0x023479FD0E092DC1, 0x1.1A3CFE870496E08p+57);
58 try test__floatuntitf(0x023479FD0E092DC7, 0x1.1A3CFE870496E38p+57);
59 try test__floatuntitf(0x023479FD0E092DC8, 0x1.1A3CFE870496E4p+57);
60 try test__floatuntitf(0x023479FD0E092DCF, 0x1.1A3CFE870496E78p+57);
61 try test__floatuntitf(0x023479FD0E092DD0, 0x1.1A3CFE870496E8p+57);
62 try test__floatuntitf(0x023479FD0E092DD1, 0x1.1A3CFE870496E88p+57);
63 try test__floatuntitf(0x023479FD0E092DD8, 0x1.1A3CFE870496ECp+57);
64 try test__floatuntitf(0x023479FD0E092DDF, 0x1.1A3CFE870496EF8p+57);
65 try test__floatuntitf(0x023479FD0E092DE0, 0x1.1A3CFE870496Fp+57);
6666
67 test__floatuntitf(make_ti(0x023479FD0E092DC0, 0), 0x1.1A3CFE870496Ep+121);
68 test__floatuntitf(make_ti(0x023479FD0E092DA1, 1), 0x1.1A3CFE870496D08p+121);
69 test__floatuntitf(make_ti(0x023479FD0E092DB0, 2), 0x1.1A3CFE870496D8p+121);
70 test__floatuntitf(make_ti(0x023479FD0E092DB8, 3), 0x1.1A3CFE870496DCp+121);
71 test__floatuntitf(make_ti(0x023479FD0E092DB6, 4), 0x1.1A3CFE870496DBp+121);
72 test__floatuntitf(make_ti(0x023479FD0E092DBF, 5), 0x1.1A3CFE870496DF8p+121);
73 test__floatuntitf(make_ti(0x023479FD0E092DC1, 6), 0x1.1A3CFE870496E08p+121);
74 test__floatuntitf(make_ti(0x023479FD0E092DC7, 7), 0x1.1A3CFE870496E38p+121);
75 test__floatuntitf(make_ti(0x023479FD0E092DC8, 8), 0x1.1A3CFE870496E4p+121);
76 test__floatuntitf(make_ti(0x023479FD0E092DCF, 9), 0x1.1A3CFE870496E78p+121);
77 test__floatuntitf(make_ti(0x023479FD0E092DD0, 0), 0x1.1A3CFE870496E8p+121);
78 test__floatuntitf(make_ti(0x023479FD0E092DD1, 11), 0x1.1A3CFE870496E88p+121);
79 test__floatuntitf(make_ti(0x023479FD0E092DD8, 12), 0x1.1A3CFE870496ECp+121);
80 test__floatuntitf(make_ti(0x023479FD0E092DDF, 13), 0x1.1A3CFE870496EF8p+121);
81 test__floatuntitf(make_ti(0x023479FD0E092DE0, 14), 0x1.1A3CFE870496Fp+121);
67 try test__floatuntitf(make_ti(0x023479FD0E092DC0, 0), 0x1.1A3CFE870496Ep+121);
68 try test__floatuntitf(make_ti(0x023479FD0E092DA1, 1), 0x1.1A3CFE870496D08p+121);
69 try test__floatuntitf(make_ti(0x023479FD0E092DB0, 2), 0x1.1A3CFE870496D8p+121);
70 try test__floatuntitf(make_ti(0x023479FD0E092DB8, 3), 0x1.1A3CFE870496DCp+121);
71 try test__floatuntitf(make_ti(0x023479FD0E092DB6, 4), 0x1.1A3CFE870496DBp+121);
72 try test__floatuntitf(make_ti(0x023479FD0E092DBF, 5), 0x1.1A3CFE870496DF8p+121);
73 try test__floatuntitf(make_ti(0x023479FD0E092DC1, 6), 0x1.1A3CFE870496E08p+121);
74 try test__floatuntitf(make_ti(0x023479FD0E092DC7, 7), 0x1.1A3CFE870496E38p+121);
75 try test__floatuntitf(make_ti(0x023479FD0E092DC8, 8), 0x1.1A3CFE870496E4p+121);
76 try test__floatuntitf(make_ti(0x023479FD0E092DCF, 9), 0x1.1A3CFE870496E78p+121);
77 try test__floatuntitf(make_ti(0x023479FD0E092DD0, 0), 0x1.1A3CFE870496E8p+121);
78 try test__floatuntitf(make_ti(0x023479FD0E092DD1, 11), 0x1.1A3CFE870496E88p+121);
79 try test__floatuntitf(make_ti(0x023479FD0E092DD8, 12), 0x1.1A3CFE870496ECp+121);
80 try test__floatuntitf(make_ti(0x023479FD0E092DDF, 13), 0x1.1A3CFE870496EF8p+121);
81 try test__floatuntitf(make_ti(0x023479FD0E092DE0, 14), 0x1.1A3CFE870496Fp+121);
8282
83 test__floatuntitf(make_ti(0, 0xFFFFFFFFFFFFFFFF), 0x1.FFFFFFFFFFFFFFFEp+63);
83 try test__floatuntitf(make_ti(0, 0xFFFFFFFFFFFFFFFF), 0x1.FFFFFFFFFFFFFFFEp+63);
8484
85 test__floatuntitf(make_ti(0xFFFFFFFFFFFFFFFF, 0x0000000000000000), 0x1.FFFFFFFFFFFFFFFEp+127);
86 test__floatuntitf(make_ti(0xFFFFFFFFFFFFFFFF, 0xFFFFFFFFFFFFFFFF), 0x1.0000000000000000p+128);
85 try test__floatuntitf(make_ti(0xFFFFFFFFFFFFFFFF, 0x0000000000000000), 0x1.FFFFFFFFFFFFFFFEp+127);
86 try test__floatuntitf(make_ti(0xFFFFFFFFFFFFFFFF, 0xFFFFFFFFFFFFFFFF), 0x1.0000000000000000p+128);
8787
88 test__floatuntitf(make_ti(0x123456789ABCDEF0, 0x123456789ABC2801), 0x1.23456789ABCDEF0123456789ABC3p+124);
89 test__floatuntitf(make_ti(0x123456789ABCDEF0, 0x123456789ABC3000), 0x1.23456789ABCDEF0123456789ABC3p+124);
90 test__floatuntitf(make_ti(0x123456789ABCDEF0, 0x123456789ABC37FF), 0x1.23456789ABCDEF0123456789ABC3p+124);
91 test__floatuntitf(make_ti(0x123456789ABCDEF0, 0x123456789ABC3800), 0x1.23456789ABCDEF0123456789ABC4p+124);
92 test__floatuntitf(make_ti(0x123456789ABCDEF0, 0x123456789ABC4000), 0x1.23456789ABCDEF0123456789ABC4p+124);
93 test__floatuntitf(make_ti(0x123456789ABCDEF0, 0x123456789ABC47FF), 0x1.23456789ABCDEF0123456789ABC4p+124);
94 test__floatuntitf(make_ti(0x123456789ABCDEF0, 0x123456789ABC4800), 0x1.23456789ABCDEF0123456789ABC4p+124);
95 test__floatuntitf(make_ti(0x123456789ABCDEF0, 0x123456789ABC4801), 0x1.23456789ABCDEF0123456789ABC5p+124);
96 test__floatuntitf(make_ti(0x123456789ABCDEF0, 0x123456789ABC57FF), 0x1.23456789ABCDEF0123456789ABC5p+124);
88 try test__floatuntitf(make_ti(0x123456789ABCDEF0, 0x123456789ABC2801), 0x1.23456789ABCDEF0123456789ABC3p+124);
89 try test__floatuntitf(make_ti(0x123456789ABCDEF0, 0x123456789ABC3000), 0x1.23456789ABCDEF0123456789ABC3p+124);
90 try test__floatuntitf(make_ti(0x123456789ABCDEF0, 0x123456789ABC37FF), 0x1.23456789ABCDEF0123456789ABC3p+124);
91 try test__floatuntitf(make_ti(0x123456789ABCDEF0, 0x123456789ABC3800), 0x1.23456789ABCDEF0123456789ABC4p+124);
92 try test__floatuntitf(make_ti(0x123456789ABCDEF0, 0x123456789ABC4000), 0x1.23456789ABCDEF0123456789ABC4p+124);
93 try test__floatuntitf(make_ti(0x123456789ABCDEF0, 0x123456789ABC47FF), 0x1.23456789ABCDEF0123456789ABC4p+124);
94 try test__floatuntitf(make_ti(0x123456789ABCDEF0, 0x123456789ABC4800), 0x1.23456789ABCDEF0123456789ABC4p+124);
95 try test__floatuntitf(make_ti(0x123456789ABCDEF0, 0x123456789ABC4801), 0x1.23456789ABCDEF0123456789ABC5p+124);
96 try test__floatuntitf(make_ti(0x123456789ABCDEF0, 0x123456789ABC57FF), 0x1.23456789ABCDEF0123456789ABC5p+124);
9797}
9898
9999fn make_ti(high: u64, low: u64) u128 {
lib/std/special/compiler_rt/int.zig+65-65
......@@ -58,13 +58,13 @@ test "test_divdi3" {
5858 };
5959
6060 for (cases) |case| {
61 test_one_divdi3(case[0], case[1], case[2]);
61 try test_one_divdi3(case[0], case[1], case[2]);
6262 }
6363}
6464
65fn test_one_divdi3(a: i64, b: i64, expected_q: i64) void {
65fn test_one_divdi3(a: i64, b: i64, expected_q: i64) !void {
6666 const q: i64 = __divdi3(a, b);
67 testing.expect(q == expected_q);
67 try testing.expect(q == expected_q);
6868}
6969
7070pub fn __moddi3(a: i64, b: i64) callconv(.C) i64 {
......@@ -98,13 +98,13 @@ test "test_moddi3" {
9898 };
9999
100100 for (cases) |case| {
101 test_one_moddi3(case[0], case[1], case[2]);
101 try test_one_moddi3(case[0], case[1], case[2]);
102102 }
103103}
104104
105fn test_one_moddi3(a: i64, b: i64, expected_r: i64) void {
105fn test_one_moddi3(a: i64, b: i64, expected_r: i64) !void {
106106 const r: i64 = __moddi3(a, b);
107 testing.expect(r == expected_r);
107 try testing.expect(r == expected_r);
108108}
109109
110110pub fn __udivdi3(a: u64, b: u64) callconv(.C) u64 {
......@@ -121,16 +121,16 @@ pub fn __umoddi3(a: u64, b: u64) callconv(.C) u64 {
121121}
122122
123123test "test_umoddi3" {
124 test_one_umoddi3(0, 1, 0);
125 test_one_umoddi3(2, 1, 0);
126 test_one_umoddi3(0x8000000000000000, 1, 0x0);
127 test_one_umoddi3(0x8000000000000000, 2, 0x0);
128 test_one_umoddi3(0xFFFFFFFFFFFFFFFF, 2, 0x1);
124 try test_one_umoddi3(0, 1, 0);
125 try test_one_umoddi3(2, 1, 0);
126 try test_one_umoddi3(0x8000000000000000, 1, 0x0);
127 try test_one_umoddi3(0x8000000000000000, 2, 0x0);
128 try test_one_umoddi3(0xFFFFFFFFFFFFFFFF, 2, 0x1);
129129}
130130
131fn test_one_umoddi3(a: u64, b: u64, expected_r: u64) void {
131fn test_one_umoddi3(a: u64, b: u64, expected_r: u64) !void {
132132 const r = __umoddi3(a, b);
133 testing.expect(r == expected_r);
133 try testing.expect(r == expected_r);
134134}
135135
136136pub fn __divmodsi4(a: i32, b: i32, rem: *i32) callconv(.C) i32 {
......@@ -159,14 +159,14 @@ test "test_divmodsi4" {
159159 };
160160
161161 for (cases) |case| {
162 test_one_divmodsi4(case[0], case[1], case[2], case[3]);
162 try test_one_divmodsi4(case[0], case[1], case[2], case[3]);
163163 }
164164}
165165
166fn test_one_divmodsi4(a: i32, b: i32, expected_q: i32, expected_r: i32) void {
166fn test_one_divmodsi4(a: i32, b: i32, expected_q: i32, expected_r: i32) !void {
167167 var r: i32 = undefined;
168168 const q: i32 = __divmodsi4(a, b, &r);
169 testing.expect(q == expected_q and r == expected_r);
169 try testing.expect(q == expected_q and r == expected_r);
170170}
171171
172172pub fn __udivmodsi4(a: u32, b: u32, rem: *u32) callconv(.C) u32 {
......@@ -207,13 +207,13 @@ test "test_divsi3" {
207207 };
208208
209209 for (cases) |case| {
210 test_one_divsi3(case[0], case[1], case[2]);
210 try test_one_divsi3(case[0], case[1], case[2]);
211211 }
212212}
213213
214fn test_one_divsi3(a: i32, b: i32, expected_q: i32) void {
214fn test_one_divsi3(a: i32, b: i32, expected_q: i32) !void {
215215 const q: i32 = __divsi3(a, b);
216 testing.expect(q == expected_q);
216 try testing.expect(q == expected_q);
217217}
218218
219219pub fn __udivsi3(n: u32, d: u32) callconv(.C) u32 {
......@@ -394,13 +394,13 @@ test "test_udivsi3" {
394394 };
395395
396396 for (cases) |case| {
397 test_one_udivsi3(case[0], case[1], case[2]);
397 try test_one_udivsi3(case[0], case[1], case[2]);
398398 }
399399}
400400
401fn test_one_udivsi3(a: u32, b: u32, expected_q: u32) void {
401fn test_one_udivsi3(a: u32, b: u32, expected_q: u32) !void {
402402 const q: u32 = __udivsi3(a, b);
403 testing.expect(q == expected_q);
403 try testing.expect(q == expected_q);
404404}
405405
406406pub fn __modsi3(n: i32, d: i32) callconv(.C) i32 {
......@@ -425,13 +425,13 @@ test "test_modsi3" {
425425 };
426426
427427 for (cases) |case| {
428 test_one_modsi3(case[0], case[1], case[2]);
428 try test_one_modsi3(case[0], case[1], case[2]);
429429 }
430430}
431431
432fn test_one_modsi3(a: i32, b: i32, expected_r: i32) void {
432fn test_one_modsi3(a: i32, b: i32, expected_r: i32) !void {
433433 const r: i32 = __modsi3(a, b);
434 testing.expect(r == expected_r);
434 try testing.expect(r == expected_r);
435435}
436436
437437pub fn __umodsi3(n: u32, d: u32) callconv(.C) u32 {
......@@ -577,13 +577,13 @@ test "test_umodsi3" {
577577 };
578578
579579 for (cases) |case| {
580 test_one_umodsi3(case[0], case[1], case[2]);
580 try test_one_umodsi3(case[0], case[1], case[2]);
581581 }
582582}
583583
584fn test_one_umodsi3(a: u32, b: u32, expected_r: u32) void {
584fn test_one_umodsi3(a: u32, b: u32, expected_r: u32) !void {
585585 const r: u32 = __umodsi3(a, b);
586 testing.expect(r == expected_r);
586 try testing.expect(r == expected_r);
587587}
588588
589589pub fn __mulsi3(a: i32, b: i32) callconv(.C) i32 {
......@@ -602,44 +602,44 @@ pub fn __mulsi3(a: i32, b: i32) callconv(.C) i32 {
602602 return @bitCast(i32, r);
603603}
604604
605fn test_one_mulsi3(a: i32, b: i32, result: i32) void {
606 testing.expectEqual(result, __mulsi3(a, b));
605fn test_one_mulsi3(a: i32, b: i32, result: i32) !void {
606 try testing.expectEqual(result, __mulsi3(a, b));
607607}
608608
609609test "mulsi3" {
610 test_one_mulsi3(0, 0, 0);
611 test_one_mulsi3(0, 1, 0);
612 test_one_mulsi3(1, 0, 0);
613 test_one_mulsi3(0, 10, 0);
614 test_one_mulsi3(10, 0, 0);
615 test_one_mulsi3(0, maxInt(i32), 0);
616 test_one_mulsi3(maxInt(i32), 0, 0);
617 test_one_mulsi3(0, -1, 0);
618 test_one_mulsi3(-1, 0, 0);
619 test_one_mulsi3(0, -10, 0);
620 test_one_mulsi3(-10, 0, 0);
621 test_one_mulsi3(0, minInt(i32), 0);
622 test_one_mulsi3(minInt(i32), 0, 0);
623 test_one_mulsi3(1, 1, 1);
624 test_one_mulsi3(1, 10, 10);
625 test_one_mulsi3(10, 1, 10);
626 test_one_mulsi3(1, maxInt(i32), maxInt(i32));
627 test_one_mulsi3(maxInt(i32), 1, maxInt(i32));
628 test_one_mulsi3(1, -1, -1);
629 test_one_mulsi3(1, -10, -10);
630 test_one_mulsi3(-10, 1, -10);
631 test_one_mulsi3(1, minInt(i32), minInt(i32));
632 test_one_mulsi3(minInt(i32), 1, minInt(i32));
633 test_one_mulsi3(46340, 46340, 2147395600);
634 test_one_mulsi3(-46340, 46340, -2147395600);
635 test_one_mulsi3(46340, -46340, -2147395600);
636 test_one_mulsi3(-46340, -46340, 2147395600);
637 test_one_mulsi3(4194303, 8192, @truncate(i32, 34359730176));
638 test_one_mulsi3(-4194303, 8192, @truncate(i32, -34359730176));
639 test_one_mulsi3(4194303, -8192, @truncate(i32, -34359730176));
640 test_one_mulsi3(-4194303, -8192, @truncate(i32, 34359730176));
641 test_one_mulsi3(8192, 4194303, @truncate(i32, 34359730176));
642 test_one_mulsi3(-8192, 4194303, @truncate(i32, -34359730176));
643 test_one_mulsi3(8192, -4194303, @truncate(i32, -34359730176));
644 test_one_mulsi3(-8192, -4194303, @truncate(i32, 34359730176));
610 try test_one_mulsi3(0, 0, 0);
611 try test_one_mulsi3(0, 1, 0);
612 try test_one_mulsi3(1, 0, 0);
613 try test_one_mulsi3(0, 10, 0);
614 try test_one_mulsi3(10, 0, 0);
615 try test_one_mulsi3(0, maxInt(i32), 0);
616 try test_one_mulsi3(maxInt(i32), 0, 0);
617 try test_one_mulsi3(0, -1, 0);
618 try test_one_mulsi3(-1, 0, 0);
619 try test_one_mulsi3(0, -10, 0);
620 try test_one_mulsi3(-10, 0, 0);
621 try test_one_mulsi3(0, minInt(i32), 0);
622 try test_one_mulsi3(minInt(i32), 0, 0);
623 try test_one_mulsi3(1, 1, 1);
624 try test_one_mulsi3(1, 10, 10);
625 try test_one_mulsi3(10, 1, 10);
626 try test_one_mulsi3(1, maxInt(i32), maxInt(i32));
627 try test_one_mulsi3(maxInt(i32), 1, maxInt(i32));
628 try test_one_mulsi3(1, -1, -1);
629 try test_one_mulsi3(1, -10, -10);
630 try test_one_mulsi3(-10, 1, -10);
631 try test_one_mulsi3(1, minInt(i32), minInt(i32));
632 try test_one_mulsi3(minInt(i32), 1, minInt(i32));
633 try test_one_mulsi3(46340, 46340, 2147395600);
634 try test_one_mulsi3(-46340, 46340, -2147395600);
635 try test_one_mulsi3(46340, -46340, -2147395600);
636 try test_one_mulsi3(-46340, -46340, 2147395600);
637 try test_one_mulsi3(4194303, 8192, @truncate(i32, 34359730176));
638 try test_one_mulsi3(-4194303, 8192, @truncate(i32, -34359730176));
639 try test_one_mulsi3(4194303, -8192, @truncate(i32, -34359730176));
640 try test_one_mulsi3(-4194303, -8192, @truncate(i32, 34359730176));
641 try test_one_mulsi3(8192, 4194303, @truncate(i32, 34359730176));
642 try test_one_mulsi3(-8192, 4194303, @truncate(i32, -34359730176));
643 try test_one_mulsi3(8192, -4194303, @truncate(i32, -34359730176));
644 try test_one_mulsi3(-8192, -4194303, @truncate(i32, 34359730176));
645645}
lib/std/special/compiler_rt/lshrdi3_test.zig+47-47
......@@ -6,55 +6,55 @@
66const __lshrdi3 = @import("shift.zig").__lshrdi3;
77const testing = @import("std").testing;
88
9fn test__lshrdi3(a: i64, b: i32, expected: u64) void {
9fn test__lshrdi3(a: i64, b: i32, expected: u64) !void {
1010 const x = __lshrdi3(a, b);
11 testing.expectEqual(@bitCast(i64, expected), x);
11 try testing.expectEqual(@bitCast(i64, expected), x);
1212}
1313
1414test "lshrdi3" {
15 test__lshrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 0, 0x123456789ABCDEF);
16 test__lshrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 1, 0x91A2B3C4D5E6F7);
17 test__lshrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 2, 0x48D159E26AF37B);
18 test__lshrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 3, 0x2468ACF13579BD);
19 test__lshrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 4, 0x123456789ABCDE);
20
21 test__lshrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 28, 0x12345678);
22 test__lshrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 29, 0x91A2B3C);
23 test__lshrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 30, 0x48D159E);
24 test__lshrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 31, 0x2468ACF);
25
26 test__lshrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 32, 0x1234567);
27
28 test__lshrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 33, 0x91A2B3);
29 test__lshrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 34, 0x48D159);
30 test__lshrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 35, 0x2468AC);
31 test__lshrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 36, 0x123456);
32
33 test__lshrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 60, 0);
34 test__lshrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 61, 0);
35 test__lshrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 62, 0);
36 test__lshrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 63, 0);
37
38 test__lshrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 0, 0xFEDCBA9876543210);
39 test__lshrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 1, 0x7F6E5D4C3B2A1908);
40 test__lshrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 2, 0x3FB72EA61D950C84);
41 test__lshrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 3, 0x1FDB97530ECA8642);
42 test__lshrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 4, 0xFEDCBA987654321);
43
44 test__lshrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 28, 0xFEDCBA987);
45 test__lshrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 29, 0x7F6E5D4C3);
46 test__lshrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 30, 0x3FB72EA61);
47 test__lshrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 31, 0x1FDB97530);
48
49 test__lshrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 32, 0xFEDCBA98);
50
51 test__lshrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 33, 0x7F6E5D4C);
52 test__lshrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 34, 0x3FB72EA6);
53 test__lshrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 35, 0x1FDB9753);
54 test__lshrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 36, 0xFEDCBA9);
55
56 test__lshrdi3(@bitCast(i64, @as(u64, 0xAEDCBA9876543210)), 60, 0xA);
57 test__lshrdi3(@bitCast(i64, @as(u64, 0xAEDCBA9876543210)), 61, 0x5);
58 test__lshrdi3(@bitCast(i64, @as(u64, 0xAEDCBA9876543210)), 62, 0x2);
59 test__lshrdi3(@bitCast(i64, @as(u64, 0xAEDCBA9876543210)), 63, 0x1);
15 try test__lshrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 0, 0x123456789ABCDEF);
16 try test__lshrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 1, 0x91A2B3C4D5E6F7);
17 try test__lshrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 2, 0x48D159E26AF37B);
18 try test__lshrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 3, 0x2468ACF13579BD);
19 try test__lshrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 4, 0x123456789ABCDE);
20
21 try test__lshrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 28, 0x12345678);
22 try test__lshrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 29, 0x91A2B3C);
23 try test__lshrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 30, 0x48D159E);
24 try test__lshrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 31, 0x2468ACF);
25
26 try test__lshrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 32, 0x1234567);
27
28 try test__lshrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 33, 0x91A2B3);
29 try test__lshrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 34, 0x48D159);
30 try test__lshrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 35, 0x2468AC);
31 try test__lshrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 36, 0x123456);
32
33 try test__lshrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 60, 0);
34 try test__lshrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 61, 0);
35 try test__lshrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 62, 0);
36 try test__lshrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 63, 0);
37
38 try test__lshrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 0, 0xFEDCBA9876543210);
39 try test__lshrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 1, 0x7F6E5D4C3B2A1908);
40 try test__lshrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 2, 0x3FB72EA61D950C84);
41 try test__lshrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 3, 0x1FDB97530ECA8642);
42 try test__lshrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 4, 0xFEDCBA987654321);
43
44 try test__lshrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 28, 0xFEDCBA987);
45 try test__lshrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 29, 0x7F6E5D4C3);
46 try test__lshrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 30, 0x3FB72EA61);
47 try test__lshrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 31, 0x1FDB97530);
48
49 try test__lshrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 32, 0xFEDCBA98);
50
51 try test__lshrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 33, 0x7F6E5D4C);
52 try test__lshrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 34, 0x3FB72EA6);
53 try test__lshrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 35, 0x1FDB9753);
54 try test__lshrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 36, 0xFEDCBA9);
55
56 try test__lshrdi3(@bitCast(i64, @as(u64, 0xAEDCBA9876543210)), 60, 0xA);
57 try test__lshrdi3(@bitCast(i64, @as(u64, 0xAEDCBA9876543210)), 61, 0x5);
58 try test__lshrdi3(@bitCast(i64, @as(u64, 0xAEDCBA9876543210)), 62, 0x2);
59 try test__lshrdi3(@bitCast(i64, @as(u64, 0xAEDCBA9876543210)), 63, 0x1);
6060}
lib/std/special/compiler_rt/lshrti3_test.zig+38-38
......@@ -6,46 +6,46 @@
66const __lshrti3 = @import("shift.zig").__lshrti3;
77const testing = @import("std").testing;
88
9fn test__lshrti3(a: i128, b: i32, expected: i128) void {
9fn test__lshrti3(a: i128, b: i32, expected: i128) !void {
1010 const x = __lshrti3(a, b);
11 testing.expectEqual(expected, x);
11 try testing.expectEqual(expected, x);
1212}
1313
1414test "lshrti3" {
15 test__lshrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 0, @bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)));
16 test__lshrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 1, @bitCast(i128, @intCast(u128, 0x7F6E5D4C3B2A190AFF6E5D4C3B2A190A)));
17 test__lshrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 2, @bitCast(i128, @intCast(u128, 0x3FB72EA61D950C857FB72EA61D950C85)));
18 test__lshrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 3, @bitCast(i128, @intCast(u128, 0x1FDB97530ECA8642BFDB97530ECA8642)));
19 test__lshrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 4, @bitCast(i128, @intCast(u128, 0x0FEDCBA9876543215FEDCBA987654321)));
20 test__lshrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 28, @bitCast(i128, @intCast(u128, 0x0000000FEDCBA9876543215FEDCBA987)));
21 test__lshrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 29, @bitCast(i128, @intCast(u128, 0x00000007F6E5D4C3B2A190AFF6E5D4C3)));
22 test__lshrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 30, @bitCast(i128, @intCast(u128, 0x00000003FB72EA61D950C857FB72EA61)));
23 test__lshrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 31, @bitCast(i128, @intCast(u128, 0x00000001FDB97530ECA8642BFDB97530)));
24 test__lshrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 32, @bitCast(i128, @intCast(u128, 0x00000000FEDCBA9876543215FEDCBA98)));
25 test__lshrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 33, @bitCast(i128, @intCast(u128, 0x000000007F6E5D4C3B2A190AFF6E5D4C)));
26 test__lshrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 34, @bitCast(i128, @intCast(u128, 0x000000003FB72EA61D950C857FB72EA6)));
27 test__lshrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 35, @bitCast(i128, @intCast(u128, 0x000000001FDB97530ECA8642BFDB9753)));
28 test__lshrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 36, @bitCast(i128, @intCast(u128, 0x000000000FEDCBA9876543215FEDCBA9)));
29 test__lshrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 60, @bitCast(i128, @intCast(u128, 0x000000000000000FEDCBA9876543215F)));
30 test__lshrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 61, @bitCast(i128, @intCast(u128, 0x0000000000000007F6E5D4C3B2A190AF)));
31 test__lshrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 62, @bitCast(i128, @intCast(u128, 0x0000000000000003FB72EA61D950C857)));
32 test__lshrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 63, @bitCast(i128, @intCast(u128, 0x0000000000000001FDB97530ECA8642B)));
33 test__lshrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 64, @bitCast(i128, @intCast(u128, 0x0000000000000000FEDCBA9876543215)));
34 test__lshrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 65, @bitCast(i128, @intCast(u128, 0x00000000000000007F6E5D4C3B2A190A)));
35 test__lshrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 66, @bitCast(i128, @intCast(u128, 0x00000000000000003FB72EA61D950C85)));
36 test__lshrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 67, @bitCast(i128, @intCast(u128, 0x00000000000000001FDB97530ECA8642)));
37 test__lshrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 68, @bitCast(i128, @intCast(u128, 0x00000000000000000FEDCBA987654321)));
38 test__lshrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 92, @bitCast(i128, @intCast(u128, 0x00000000000000000000000FEDCBA987)));
39 test__lshrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 93, @bitCast(i128, @intCast(u128, 0x000000000000000000000007F6E5D4C3)));
40 test__lshrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 94, @bitCast(i128, @intCast(u128, 0x000000000000000000000003FB72EA61)));
41 test__lshrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 95, @bitCast(i128, @intCast(u128, 0x000000000000000000000001FDB97530)));
42 test__lshrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 96, @bitCast(i128, @intCast(u128, 0x000000000000000000000000FEDCBA98)));
43 test__lshrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 97, @bitCast(i128, @intCast(u128, 0x0000000000000000000000007F6E5D4C)));
44 test__lshrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 98, @bitCast(i128, @intCast(u128, 0x0000000000000000000000003FB72EA6)));
45 test__lshrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 99, @bitCast(i128, @intCast(u128, 0x0000000000000000000000001FDB9753)));
46 test__lshrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 100, @bitCast(i128, @intCast(u128, 0x0000000000000000000000000FEDCBA9)));
47 test__lshrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 124, @bitCast(i128, @intCast(u128, 0x0000000000000000000000000000000F)));
48 test__lshrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 125, @bitCast(i128, @intCast(u128, 0x00000000000000000000000000000007)));
49 test__lshrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 126, @bitCast(i128, @intCast(u128, 0x00000000000000000000000000000003)));
50 test__lshrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 127, @bitCast(i128, @intCast(u128, 0x00000000000000000000000000000001)));
15 try test__lshrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 0, @bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)));
16 try test__lshrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 1, @bitCast(i128, @intCast(u128, 0x7F6E5D4C3B2A190AFF6E5D4C3B2A190A)));
17 try test__lshrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 2, @bitCast(i128, @intCast(u128, 0x3FB72EA61D950C857FB72EA61D950C85)));
18 try test__lshrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 3, @bitCast(i128, @intCast(u128, 0x1FDB97530ECA8642BFDB97530ECA8642)));
19 try test__lshrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 4, @bitCast(i128, @intCast(u128, 0x0FEDCBA9876543215FEDCBA987654321)));
20 try test__lshrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 28, @bitCast(i128, @intCast(u128, 0x0000000FEDCBA9876543215FEDCBA987)));
21 try test__lshrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 29, @bitCast(i128, @intCast(u128, 0x00000007F6E5D4C3B2A190AFF6E5D4C3)));
22 try test__lshrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 30, @bitCast(i128, @intCast(u128, 0x00000003FB72EA61D950C857FB72EA61)));
23 try test__lshrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 31, @bitCast(i128, @intCast(u128, 0x00000001FDB97530ECA8642BFDB97530)));
24 try test__lshrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 32, @bitCast(i128, @intCast(u128, 0x00000000FEDCBA9876543215FEDCBA98)));
25 try test__lshrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 33, @bitCast(i128, @intCast(u128, 0x000000007F6E5D4C3B2A190AFF6E5D4C)));
26 try test__lshrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 34, @bitCast(i128, @intCast(u128, 0x000000003FB72EA61D950C857FB72EA6)));
27 try test__lshrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 35, @bitCast(i128, @intCast(u128, 0x000000001FDB97530ECA8642BFDB9753)));
28 try test__lshrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 36, @bitCast(i128, @intCast(u128, 0x000000000FEDCBA9876543215FEDCBA9)));
29 try test__lshrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 60, @bitCast(i128, @intCast(u128, 0x000000000000000FEDCBA9876543215F)));
30 try test__lshrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 61, @bitCast(i128, @intCast(u128, 0x0000000000000007F6E5D4C3B2A190AF)));
31 try test__lshrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 62, @bitCast(i128, @intCast(u128, 0x0000000000000003FB72EA61D950C857)));
32 try test__lshrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 63, @bitCast(i128, @intCast(u128, 0x0000000000000001FDB97530ECA8642B)));
33 try test__lshrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 64, @bitCast(i128, @intCast(u128, 0x0000000000000000FEDCBA9876543215)));
34 try test__lshrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 65, @bitCast(i128, @intCast(u128, 0x00000000000000007F6E5D4C3B2A190A)));
35 try test__lshrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 66, @bitCast(i128, @intCast(u128, 0x00000000000000003FB72EA61D950C85)));
36 try test__lshrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 67, @bitCast(i128, @intCast(u128, 0x00000000000000001FDB97530ECA8642)));
37 try test__lshrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 68, @bitCast(i128, @intCast(u128, 0x00000000000000000FEDCBA987654321)));
38 try test__lshrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 92, @bitCast(i128, @intCast(u128, 0x00000000000000000000000FEDCBA987)));
39 try test__lshrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 93, @bitCast(i128, @intCast(u128, 0x000000000000000000000007F6E5D4C3)));
40 try test__lshrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 94, @bitCast(i128, @intCast(u128, 0x000000000000000000000003FB72EA61)));
41 try test__lshrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 95, @bitCast(i128, @intCast(u128, 0x000000000000000000000001FDB97530)));
42 try test__lshrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 96, @bitCast(i128, @intCast(u128, 0x000000000000000000000000FEDCBA98)));
43 try test__lshrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 97, @bitCast(i128, @intCast(u128, 0x0000000000000000000000007F6E5D4C)));
44 try test__lshrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 98, @bitCast(i128, @intCast(u128, 0x0000000000000000000000003FB72EA6)));
45 try test__lshrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 99, @bitCast(i128, @intCast(u128, 0x0000000000000000000000001FDB9753)));
46 try test__lshrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 100, @bitCast(i128, @intCast(u128, 0x0000000000000000000000000FEDCBA9)));
47 try test__lshrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 124, @bitCast(i128, @intCast(u128, 0x0000000000000000000000000000000F)));
48 try test__lshrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 125, @bitCast(i128, @intCast(u128, 0x00000000000000000000000000000007)));
49 try test__lshrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 126, @bitCast(i128, @intCast(u128, 0x00000000000000000000000000000003)));
50 try test__lshrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 127, @bitCast(i128, @intCast(u128, 0x00000000000000000000000000000001)));
5151}
lib/std/special/compiler_rt/modti3_test.zig+20-20
......@@ -6,32 +6,32 @@
66const __modti3 = @import("modti3.zig").__modti3;
77const testing = @import("std").testing;
88
9fn test__modti3(a: i128, b: i128, expected: i128) void {
9fn test__modti3(a: i128, b: i128, expected: i128) !void {
1010 const x = __modti3(a, b);
11 testing.expect(x == expected);
11 try testing.expect(x == expected);
1212}
1313
1414test "modti3" {
15 test__modti3(0, 1, 0);
16 test__modti3(0, -1, 0);
17 test__modti3(5, 3, 2);
18 test__modti3(5, -3, 2);
19 test__modti3(-5, 3, -2);
20 test__modti3(-5, -3, -2);
15 try test__modti3(0, 1, 0);
16 try test__modti3(0, -1, 0);
17 try test__modti3(5, 3, 2);
18 try test__modti3(5, -3, 2);
19 try test__modti3(-5, 3, -2);
20 try test__modti3(-5, -3, -2);
2121
22 test__modti3(0x8000000000000000, 1, 0x0);
23 test__modti3(0x8000000000000000, -1, 0x0);
24 test__modti3(0x8000000000000000, 2, 0x0);
25 test__modti3(0x8000000000000000, -2, 0x0);
26 test__modti3(0x8000000000000000, 3, 2);
27 test__modti3(0x8000000000000000, -3, 2);
22 try test__modti3(0x8000000000000000, 1, 0x0);
23 try test__modti3(0x8000000000000000, -1, 0x0);
24 try test__modti3(0x8000000000000000, 2, 0x0);
25 try test__modti3(0x8000000000000000, -2, 0x0);
26 try test__modti3(0x8000000000000000, 3, 2);
27 try test__modti3(0x8000000000000000, -3, 2);
2828
29 test__modti3(make_ti(0x8000000000000000, 0), 1, 0x0);
30 test__modti3(make_ti(0x8000000000000000, 0), -1, 0x0);
31 test__modti3(make_ti(0x8000000000000000, 0), 2, 0x0);
32 test__modti3(make_ti(0x8000000000000000, 0), -2, 0x0);
33 test__modti3(make_ti(0x8000000000000000, 0), 3, -2);
34 test__modti3(make_ti(0x8000000000000000, 0), -3, -2);
29 try test__modti3(make_ti(0x8000000000000000, 0), 1, 0x0);
30 try test__modti3(make_ti(0x8000000000000000, 0), -1, 0x0);
31 try test__modti3(make_ti(0x8000000000000000, 0), 2, 0x0);
32 try test__modti3(make_ti(0x8000000000000000, 0), -2, 0x0);
33 try test__modti3(make_ti(0x8000000000000000, 0), 3, -2);
34 try test__modti3(make_ti(0x8000000000000000, 0), -3, -2);
3535}
3636
3737fn make_ti(high: u64, low: u64) i128 {
lib/std/special/compiler_rt/mulXf3_test.zig+9-9
......@@ -34,7 +34,7 @@ fn compareResultLD(result: f128, expectedHi: u64, expectedLo: u64) bool {
3434 return false;
3535}
3636
37fn test__multf3(a: f128, b: f128, expected_hi: u64, expected_lo: u64) void {
37fn test__multf3(a: f128, b: f128, expected_hi: u64, expected_lo: u64) !void {
3838 const x = __multf3(a, b);
3939
4040 if (compareResultLD(x, expected_hi, expected_lo))
......@@ -50,42 +50,42 @@ fn makeNaN128(rand: u64) f128 {
5050}
5151test "multf3" {
5252 // qNaN * any = qNaN
53 test__multf3(qnan128, 0x1.23456789abcdefp+5, 0x7fff800000000000, 0x0);
53 try test__multf3(qnan128, 0x1.23456789abcdefp+5, 0x7fff800000000000, 0x0);
5454
5555 // NaN * any = NaN
5656 const a = makeNaN128(0x800030000000);
57 test__multf3(a, 0x1.23456789abcdefp+5, 0x7fff800000000000, 0x0);
57 try test__multf3(a, 0x1.23456789abcdefp+5, 0x7fff800000000000, 0x0);
5858 // inf * any = inf
59 test__multf3(inf128, 0x1.23456789abcdefp+5, 0x7fff000000000000, 0x0);
59 try test__multf3(inf128, 0x1.23456789abcdefp+5, 0x7fff000000000000, 0x0);
6060
6161 // any * any
62 test__multf3(
62 try test__multf3(
6363 @bitCast(f128, @as(u128, 0x40042eab345678439abcdefea5678234)),
6464 @bitCast(f128, @as(u128, 0x3ffeedcb34a235253948765432134675)),
6565 0x400423e7f9e3c9fc,
6666 0xd906c2c2a85777c4,
6767 );
6868
69 test__multf3(
69 try test__multf3(
7070 @bitCast(f128, @as(u128, 0x3fcd353e45674d89abacc3a2ebf3ff50)),
7171 @bitCast(f128, @as(u128, 0x3ff6ed8764648369535adf4be3214568)),
7272 0x3fc52a163c6223fc,
7373 0xc94c4bf0430768b4,
7474 );
7575
76 test__multf3(
76 try test__multf3(
7777 0x1.234425696abcad34a35eeffefdcbap+456,
7878 0x451.ed98d76e5d46e5f24323dff21ffp+600,
7979 0x44293a91de5e0e94,
8080 0xe8ed17cc2cdf64ac,
8181 );
8282
83 test__multf3(
83 try test__multf3(
8484 @bitCast(f128, @as(u128, 0x3f154356473c82a9fabf2d22ace345df)),
8585 @bitCast(f128, @as(u128, 0x3e38eda98765476743ab21da23d45679)),
8686 0x3d4f37c1a3137cae,
8787 0xfc6807048bc2836a,
8888 );
8989
90 test__multf3(0x1.23456734245345p-10000, 0x1.edcba524498724p-6497, 0x0, 0x0);
90 try test__multf3(0x1.23456734245345p-10000, 0x1.edcba524498724p-6497, 0x0, 0x0);
9191}
lib/std/special/compiler_rt/muldi3_test.zig+43-43
......@@ -6,51 +6,51 @@
66const __muldi3 = @import("muldi3.zig").__muldi3;
77const testing = @import("std").testing;
88
9fn test__muldi3(a: i64, b: i64, expected: i64) void {
9fn test__muldi3(a: i64, b: i64, expected: i64) !void {
1010 const x = __muldi3(a, b);
11 testing.expect(x == expected);
11 try testing.expect(x == expected);
1212}
1313
1414test "muldi3" {
15 test__muldi3(0, 0, 0);
16 test__muldi3(0, 1, 0);
17 test__muldi3(1, 0, 0);
18 test__muldi3(0, 10, 0);
19 test__muldi3(10, 0, 0);
20 test__muldi3(0, 81985529216486895, 0);
21 test__muldi3(81985529216486895, 0, 0);
22
23 test__muldi3(0, -1, 0);
24 test__muldi3(-1, 0, 0);
25 test__muldi3(0, -10, 0);
26 test__muldi3(-10, 0, 0);
27 test__muldi3(0, -81985529216486895, 0);
28 test__muldi3(-81985529216486895, 0, 0);
29
30 test__muldi3(1, 1, 1);
31 test__muldi3(1, 10, 10);
32 test__muldi3(10, 1, 10);
33 test__muldi3(1, 81985529216486895, 81985529216486895);
34 test__muldi3(81985529216486895, 1, 81985529216486895);
35
36 test__muldi3(1, -1, -1);
37 test__muldi3(1, -10, -10);
38 test__muldi3(-10, 1, -10);
39 test__muldi3(1, -81985529216486895, -81985529216486895);
40 test__muldi3(-81985529216486895, 1, -81985529216486895);
41
42 test__muldi3(3037000499, 3037000499, 9223372030926249001);
43 test__muldi3(-3037000499, 3037000499, -9223372030926249001);
44 test__muldi3(3037000499, -3037000499, -9223372030926249001);
45 test__muldi3(-3037000499, -3037000499, 9223372030926249001);
46
47 test__muldi3(4398046511103, 2097152, 9223372036852678656);
48 test__muldi3(-4398046511103, 2097152, -9223372036852678656);
49 test__muldi3(4398046511103, -2097152, -9223372036852678656);
50 test__muldi3(-4398046511103, -2097152, 9223372036852678656);
51
52 test__muldi3(2097152, 4398046511103, 9223372036852678656);
53 test__muldi3(-2097152, 4398046511103, -9223372036852678656);
54 test__muldi3(2097152, -4398046511103, -9223372036852678656);
55 test__muldi3(-2097152, -4398046511103, 9223372036852678656);
15 try test__muldi3(0, 0, 0);
16 try test__muldi3(0, 1, 0);
17 try test__muldi3(1, 0, 0);
18 try test__muldi3(0, 10, 0);
19 try test__muldi3(10, 0, 0);
20 try test__muldi3(0, 81985529216486895, 0);
21 try test__muldi3(81985529216486895, 0, 0);
22
23 try test__muldi3(0, -1, 0);
24 try test__muldi3(-1, 0, 0);
25 try test__muldi3(0, -10, 0);
26 try test__muldi3(-10, 0, 0);
27 try test__muldi3(0, -81985529216486895, 0);
28 try test__muldi3(-81985529216486895, 0, 0);
29
30 try test__muldi3(1, 1, 1);
31 try test__muldi3(1, 10, 10);
32 try test__muldi3(10, 1, 10);
33 try test__muldi3(1, 81985529216486895, 81985529216486895);
34 try test__muldi3(81985529216486895, 1, 81985529216486895);
35
36 try test__muldi3(1, -1, -1);
37 try test__muldi3(1, -10, -10);
38 try test__muldi3(-10, 1, -10);
39 try test__muldi3(1, -81985529216486895, -81985529216486895);
40 try test__muldi3(-81985529216486895, 1, -81985529216486895);
41
42 try test__muldi3(3037000499, 3037000499, 9223372030926249001);
43 try test__muldi3(-3037000499, 3037000499, -9223372030926249001);
44 try test__muldi3(3037000499, -3037000499, -9223372030926249001);
45 try test__muldi3(-3037000499, -3037000499, 9223372030926249001);
46
47 try test__muldi3(4398046511103, 2097152, 9223372036852678656);
48 try test__muldi3(-4398046511103, 2097152, -9223372036852678656);
49 try test__muldi3(4398046511103, -2097152, -9223372036852678656);
50 try test__muldi3(-4398046511103, -2097152, 9223372036852678656);
51
52 try test__muldi3(2097152, 4398046511103, 9223372036852678656);
53 try test__muldi3(-2097152, 4398046511103, -9223372036852678656);
54 try test__muldi3(2097152, -4398046511103, -9223372036852678656);
55 try test__muldi3(-2097152, -4398046511103, 9223372036852678656);
5656}
lib/std/special/compiler_rt/mulodi4_test.zig+67-67
......@@ -6,85 +6,85 @@
66const __mulodi4 = @import("mulodi4.zig").__mulodi4;
77const testing = @import("std").testing;
88
9fn test__mulodi4(a: i64, b: i64, expected: i64, expected_overflow: c_int) void {
9fn test__mulodi4(a: i64, b: i64, expected: i64, expected_overflow: c_int) !void {
1010 var overflow: c_int = undefined;
1111 const x = __mulodi4(a, b, &overflow);
12 testing.expect(overflow == expected_overflow and (expected_overflow != 0 or x == expected));
12 try testing.expect(overflow == expected_overflow and (expected_overflow != 0 or x == expected));
1313}
1414
1515test "mulodi4" {
16 test__mulodi4(0, 0, 0, 0);
17 test__mulodi4(0, 1, 0, 0);
18 test__mulodi4(1, 0, 0, 0);
19 test__mulodi4(0, 10, 0, 0);
20 test__mulodi4(10, 0, 0, 0);
21 test__mulodi4(0, 81985529216486895, 0, 0);
22 test__mulodi4(81985529216486895, 0, 0, 0);
16 try test__mulodi4(0, 0, 0, 0);
17 try test__mulodi4(0, 1, 0, 0);
18 try test__mulodi4(1, 0, 0, 0);
19 try test__mulodi4(0, 10, 0, 0);
20 try test__mulodi4(10, 0, 0, 0);
21 try test__mulodi4(0, 81985529216486895, 0, 0);
22 try test__mulodi4(81985529216486895, 0, 0, 0);
2323
24 test__mulodi4(0, -1, 0, 0);
25 test__mulodi4(-1, 0, 0, 0);
26 test__mulodi4(0, -10, 0, 0);
27 test__mulodi4(-10, 0, 0, 0);
28 test__mulodi4(0, -81985529216486895, 0, 0);
29 test__mulodi4(-81985529216486895, 0, 0, 0);
24 try test__mulodi4(0, -1, 0, 0);
25 try test__mulodi4(-1, 0, 0, 0);
26 try test__mulodi4(0, -10, 0, 0);
27 try test__mulodi4(-10, 0, 0, 0);
28 try test__mulodi4(0, -81985529216486895, 0, 0);
29 try test__mulodi4(-81985529216486895, 0, 0, 0);
3030
31 test__mulodi4(1, 1, 1, 0);
32 test__mulodi4(1, 10, 10, 0);
33 test__mulodi4(10, 1, 10, 0);
34 test__mulodi4(1, 81985529216486895, 81985529216486895, 0);
35 test__mulodi4(81985529216486895, 1, 81985529216486895, 0);
31 try test__mulodi4(1, 1, 1, 0);
32 try test__mulodi4(1, 10, 10, 0);
33 try test__mulodi4(10, 1, 10, 0);
34 try test__mulodi4(1, 81985529216486895, 81985529216486895, 0);
35 try test__mulodi4(81985529216486895, 1, 81985529216486895, 0);
3636
37 test__mulodi4(1, -1, -1, 0);
38 test__mulodi4(1, -10, -10, 0);
39 test__mulodi4(-10, 1, -10, 0);
40 test__mulodi4(1, -81985529216486895, -81985529216486895, 0);
41 test__mulodi4(-81985529216486895, 1, -81985529216486895, 0);
37 try test__mulodi4(1, -1, -1, 0);
38 try test__mulodi4(1, -10, -10, 0);
39 try test__mulodi4(-10, 1, -10, 0);
40 try test__mulodi4(1, -81985529216486895, -81985529216486895, 0);
41 try test__mulodi4(-81985529216486895, 1, -81985529216486895, 0);
4242
43 test__mulodi4(3037000499, 3037000499, 9223372030926249001, 0);
44 test__mulodi4(-3037000499, 3037000499, -9223372030926249001, 0);
45 test__mulodi4(3037000499, -3037000499, -9223372030926249001, 0);
46 test__mulodi4(-3037000499, -3037000499, 9223372030926249001, 0);
43 try test__mulodi4(3037000499, 3037000499, 9223372030926249001, 0);
44 try test__mulodi4(-3037000499, 3037000499, -9223372030926249001, 0);
45 try test__mulodi4(3037000499, -3037000499, -9223372030926249001, 0);
46 try test__mulodi4(-3037000499, -3037000499, 9223372030926249001, 0);
4747
48 test__mulodi4(4398046511103, 2097152, 9223372036852678656, 0);
49 test__mulodi4(-4398046511103, 2097152, -9223372036852678656, 0);
50 test__mulodi4(4398046511103, -2097152, -9223372036852678656, 0);
51 test__mulodi4(-4398046511103, -2097152, 9223372036852678656, 0);
48 try test__mulodi4(4398046511103, 2097152, 9223372036852678656, 0);
49 try test__mulodi4(-4398046511103, 2097152, -9223372036852678656, 0);
50 try test__mulodi4(4398046511103, -2097152, -9223372036852678656, 0);
51 try test__mulodi4(-4398046511103, -2097152, 9223372036852678656, 0);
5252
53 test__mulodi4(2097152, 4398046511103, 9223372036852678656, 0);
54 test__mulodi4(-2097152, 4398046511103, -9223372036852678656, 0);
55 test__mulodi4(2097152, -4398046511103, -9223372036852678656, 0);
56 test__mulodi4(-2097152, -4398046511103, 9223372036852678656, 0);
53 try test__mulodi4(2097152, 4398046511103, 9223372036852678656, 0);
54 try test__mulodi4(-2097152, 4398046511103, -9223372036852678656, 0);
55 try test__mulodi4(2097152, -4398046511103, -9223372036852678656, 0);
56 try test__mulodi4(-2097152, -4398046511103, 9223372036852678656, 0);
5757
58 test__mulodi4(0x7FFFFFFFFFFFFFFF, -2, 2, 1);
59 test__mulodi4(-2, 0x7FFFFFFFFFFFFFFF, 2, 1);
60 test__mulodi4(0x7FFFFFFFFFFFFFFF, -1, @bitCast(i64, @as(u64, 0x8000000000000001)), 0);
61 test__mulodi4(-1, 0x7FFFFFFFFFFFFFFF, @bitCast(i64, @as(u64, 0x8000000000000001)), 0);
62 test__mulodi4(0x7FFFFFFFFFFFFFFF, 0, 0, 0);
63 test__mulodi4(0, 0x7FFFFFFFFFFFFFFF, 0, 0);
64 test__mulodi4(0x7FFFFFFFFFFFFFFF, 1, 0x7FFFFFFFFFFFFFFF, 0);
65 test__mulodi4(1, 0x7FFFFFFFFFFFFFFF, 0x7FFFFFFFFFFFFFFF, 0);
66 test__mulodi4(0x7FFFFFFFFFFFFFFF, 2, @bitCast(i64, @as(u64, 0x8000000000000001)), 1);
67 test__mulodi4(2, 0x7FFFFFFFFFFFFFFF, @bitCast(i64, @as(u64, 0x8000000000000001)), 1);
58 try test__mulodi4(0x7FFFFFFFFFFFFFFF, -2, 2, 1);
59 try test__mulodi4(-2, 0x7FFFFFFFFFFFFFFF, 2, 1);
60 try test__mulodi4(0x7FFFFFFFFFFFFFFF, -1, @bitCast(i64, @as(u64, 0x8000000000000001)), 0);
61 try test__mulodi4(-1, 0x7FFFFFFFFFFFFFFF, @bitCast(i64, @as(u64, 0x8000000000000001)), 0);
62 try test__mulodi4(0x7FFFFFFFFFFFFFFF, 0, 0, 0);
63 try test__mulodi4(0, 0x7FFFFFFFFFFFFFFF, 0, 0);
64 try test__mulodi4(0x7FFFFFFFFFFFFFFF, 1, 0x7FFFFFFFFFFFFFFF, 0);
65 try test__mulodi4(1, 0x7FFFFFFFFFFFFFFF, 0x7FFFFFFFFFFFFFFF, 0);
66 try test__mulodi4(0x7FFFFFFFFFFFFFFF, 2, @bitCast(i64, @as(u64, 0x8000000000000001)), 1);
67 try test__mulodi4(2, 0x7FFFFFFFFFFFFFFF, @bitCast(i64, @as(u64, 0x8000000000000001)), 1);
6868
69 test__mulodi4(@bitCast(i64, @as(u64, 0x8000000000000000)), -2, @bitCast(i64, @as(u64, 0x8000000000000000)), 1);
70 test__mulodi4(-2, @bitCast(i64, @as(u64, 0x8000000000000000)), @bitCast(i64, @as(u64, 0x8000000000000000)), 1);
71 test__mulodi4(@bitCast(i64, @as(u64, 0x8000000000000000)), -1, @bitCast(i64, @as(u64, 0x8000000000000000)), 1);
72 test__mulodi4(-1, @bitCast(i64, @as(u64, 0x8000000000000000)), @bitCast(i64, @as(u64, 0x8000000000000000)), 1);
73 test__mulodi4(@bitCast(i64, @as(u64, 0x8000000000000000)), 0, 0, 0);
74 test__mulodi4(0, @bitCast(i64, @as(u64, 0x8000000000000000)), 0, 0);
75 test__mulodi4(@bitCast(i64, @as(u64, 0x8000000000000000)), 1, @bitCast(i64, @as(u64, 0x8000000000000000)), 0);
76 test__mulodi4(1, @bitCast(i64, @as(u64, 0x8000000000000000)), @bitCast(i64, @as(u64, 0x8000000000000000)), 0);
77 test__mulodi4(@bitCast(i64, @as(u64, 0x8000000000000000)), 2, @bitCast(i64, @as(u64, 0x8000000000000000)), 1);
78 test__mulodi4(2, @bitCast(i64, @as(u64, 0x8000000000000000)), @bitCast(i64, @as(u64, 0x8000000000000000)), 1);
69 try test__mulodi4(@bitCast(i64, @as(u64, 0x8000000000000000)), -2, @bitCast(i64, @as(u64, 0x8000000000000000)), 1);
70 try test__mulodi4(-2, @bitCast(i64, @as(u64, 0x8000000000000000)), @bitCast(i64, @as(u64, 0x8000000000000000)), 1);
71 try test__mulodi4(@bitCast(i64, @as(u64, 0x8000000000000000)), -1, @bitCast(i64, @as(u64, 0x8000000000000000)), 1);
72 try test__mulodi4(-1, @bitCast(i64, @as(u64, 0x8000000000000000)), @bitCast(i64, @as(u64, 0x8000000000000000)), 1);
73 try test__mulodi4(@bitCast(i64, @as(u64, 0x8000000000000000)), 0, 0, 0);
74 try test__mulodi4(0, @bitCast(i64, @as(u64, 0x8000000000000000)), 0, 0);
75 try test__mulodi4(@bitCast(i64, @as(u64, 0x8000000000000000)), 1, @bitCast(i64, @as(u64, 0x8000000000000000)), 0);
76 try test__mulodi4(1, @bitCast(i64, @as(u64, 0x8000000000000000)), @bitCast(i64, @as(u64, 0x8000000000000000)), 0);
77 try test__mulodi4(@bitCast(i64, @as(u64, 0x8000000000000000)), 2, @bitCast(i64, @as(u64, 0x8000000000000000)), 1);
78 try test__mulodi4(2, @bitCast(i64, @as(u64, 0x8000000000000000)), @bitCast(i64, @as(u64, 0x8000000000000000)), 1);
7979
80 test__mulodi4(@bitCast(i64, @as(u64, 0x8000000000000001)), -2, @bitCast(i64, @as(u64, 0x8000000000000001)), 1);
81 test__mulodi4(-2, @bitCast(i64, @as(u64, 0x8000000000000001)), @bitCast(i64, @as(u64, 0x8000000000000001)), 1);
82 test__mulodi4(@bitCast(i64, @as(u64, 0x8000000000000001)), -1, 0x7FFFFFFFFFFFFFFF, 0);
83 test__mulodi4(-1, @bitCast(i64, @as(u64, 0x8000000000000001)), 0x7FFFFFFFFFFFFFFF, 0);
84 test__mulodi4(@bitCast(i64, @as(u64, 0x8000000000000001)), 0, 0, 0);
85 test__mulodi4(0, @bitCast(i64, @as(u64, 0x8000000000000001)), 0, 0);
86 test__mulodi4(@bitCast(i64, @as(u64, 0x8000000000000001)), 1, @bitCast(i64, @as(u64, 0x8000000000000001)), 0);
87 test__mulodi4(1, @bitCast(i64, @as(u64, 0x8000000000000001)), @bitCast(i64, @as(u64, 0x8000000000000001)), 0);
88 test__mulodi4(@bitCast(i64, @as(u64, 0x8000000000000001)), 2, @bitCast(i64, @as(u64, 0x8000000000000000)), 1);
89 test__mulodi4(2, @bitCast(i64, @as(u64, 0x8000000000000001)), @bitCast(i64, @as(u64, 0x8000000000000000)), 1);
80 try test__mulodi4(@bitCast(i64, @as(u64, 0x8000000000000001)), -2, @bitCast(i64, @as(u64, 0x8000000000000001)), 1);
81 try test__mulodi4(-2, @bitCast(i64, @as(u64, 0x8000000000000001)), @bitCast(i64, @as(u64, 0x8000000000000001)), 1);
82 try test__mulodi4(@bitCast(i64, @as(u64, 0x8000000000000001)), -1, 0x7FFFFFFFFFFFFFFF, 0);
83 try test__mulodi4(-1, @bitCast(i64, @as(u64, 0x8000000000000001)), 0x7FFFFFFFFFFFFFFF, 0);
84 try test__mulodi4(@bitCast(i64, @as(u64, 0x8000000000000001)), 0, 0, 0);
85 try test__mulodi4(0, @bitCast(i64, @as(u64, 0x8000000000000001)), 0, 0);
86 try test__mulodi4(@bitCast(i64, @as(u64, 0x8000000000000001)), 1, @bitCast(i64, @as(u64, 0x8000000000000001)), 0);
87 try test__mulodi4(1, @bitCast(i64, @as(u64, 0x8000000000000001)), @bitCast(i64, @as(u64, 0x8000000000000001)), 0);
88 try test__mulodi4(@bitCast(i64, @as(u64, 0x8000000000000001)), 2, @bitCast(i64, @as(u64, 0x8000000000000000)), 1);
89 try test__mulodi4(2, @bitCast(i64, @as(u64, 0x8000000000000001)), @bitCast(i64, @as(u64, 0x8000000000000000)), 1);
9090}
lib/std/special/compiler_rt/muloti4_test.zig+58-58
......@@ -6,76 +6,76 @@
66const __muloti4 = @import("muloti4.zig").__muloti4;
77const testing = @import("std").testing;
88
9fn test__muloti4(a: i128, b: i128, expected: i128, expected_overflow: c_int) void {
9fn test__muloti4(a: i128, b: i128, expected: i128, expected_overflow: c_int) !void {
1010 var overflow: c_int = undefined;
1111 const x = __muloti4(a, b, &overflow);
12 testing.expect(overflow == expected_overflow and (expected_overflow != 0 or x == expected));
12 try testing.expect(overflow == expected_overflow and (expected_overflow != 0 or x == expected));
1313}
1414
1515test "muloti4" {
16 test__muloti4(0, 0, 0, 0);
17 test__muloti4(0, 1, 0, 0);
18 test__muloti4(1, 0, 0, 0);
19 test__muloti4(0, 10, 0, 0);
20 test__muloti4(10, 0, 0, 0);
16 try test__muloti4(0, 0, 0, 0);
17 try test__muloti4(0, 1, 0, 0);
18 try test__muloti4(1, 0, 0, 0);
19 try test__muloti4(0, 10, 0, 0);
20 try test__muloti4(10, 0, 0, 0);
2121
22 test__muloti4(0, 81985529216486895, 0, 0);
23 test__muloti4(81985529216486895, 0, 0, 0);
22 try test__muloti4(0, 81985529216486895, 0, 0);
23 try test__muloti4(81985529216486895, 0, 0, 0);
2424
25 test__muloti4(0, -1, 0, 0);
26 test__muloti4(-1, 0, 0, 0);
27 test__muloti4(0, -10, 0, 0);
28 test__muloti4(-10, 0, 0, 0);
29 test__muloti4(0, -81985529216486895, 0, 0);
30 test__muloti4(-81985529216486895, 0, 0, 0);
25 try test__muloti4(0, -1, 0, 0);
26 try test__muloti4(-1, 0, 0, 0);
27 try test__muloti4(0, -10, 0, 0);
28 try test__muloti4(-10, 0, 0, 0);
29 try test__muloti4(0, -81985529216486895, 0, 0);
30 try test__muloti4(-81985529216486895, 0, 0, 0);
3131
32 test__muloti4(3037000499, 3037000499, 9223372030926249001, 0);
33 test__muloti4(-3037000499, 3037000499, -9223372030926249001, 0);
34 test__muloti4(3037000499, -3037000499, -9223372030926249001, 0);
35 test__muloti4(-3037000499, -3037000499, 9223372030926249001, 0);
32 try test__muloti4(3037000499, 3037000499, 9223372030926249001, 0);
33 try test__muloti4(-3037000499, 3037000499, -9223372030926249001, 0);
34 try test__muloti4(3037000499, -3037000499, -9223372030926249001, 0);
35 try test__muloti4(-3037000499, -3037000499, 9223372030926249001, 0);
3636
37 test__muloti4(4398046511103, 2097152, 9223372036852678656, 0);
38 test__muloti4(-4398046511103, 2097152, -9223372036852678656, 0);
39 test__muloti4(4398046511103, -2097152, -9223372036852678656, 0);
40 test__muloti4(-4398046511103, -2097152, 9223372036852678656, 0);
37 try test__muloti4(4398046511103, 2097152, 9223372036852678656, 0);
38 try test__muloti4(-4398046511103, 2097152, -9223372036852678656, 0);
39 try test__muloti4(4398046511103, -2097152, -9223372036852678656, 0);
40 try test__muloti4(-4398046511103, -2097152, 9223372036852678656, 0);
4141
42 test__muloti4(2097152, 4398046511103, 9223372036852678656, 0);
43 test__muloti4(-2097152, 4398046511103, -9223372036852678656, 0);
44 test__muloti4(2097152, -4398046511103, -9223372036852678656, 0);
45 test__muloti4(-2097152, -4398046511103, 9223372036852678656, 0);
42 try test__muloti4(2097152, 4398046511103, 9223372036852678656, 0);
43 try test__muloti4(-2097152, 4398046511103, -9223372036852678656, 0);
44 try test__muloti4(2097152, -4398046511103, -9223372036852678656, 0);
45 try test__muloti4(-2097152, -4398046511103, 9223372036852678656, 0);
4646
47 test__muloti4(@bitCast(i128, @as(u128, 0x00000000000000B504F333F9DE5BE000)), @bitCast(i128, @as(u128, 0x000000000000000000B504F333F9DE5B)), @bitCast(i128, @as(u128, 0x7FFFFFFFFFFFF328DF915DA296E8A000)), 0);
48 test__muloti4(@bitCast(i128, @as(u128, 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)), -2, @bitCast(i128, @as(u128, 0x80000000000000000000000000000001)), 1);
49 test__muloti4(-2, @bitCast(i128, @as(u128, 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)), @bitCast(i128, @as(u128, 0x80000000000000000000000000000001)), 1);
47 try test__muloti4(@bitCast(i128, @as(u128, 0x00000000000000B504F333F9DE5BE000)), @bitCast(i128, @as(u128, 0x000000000000000000B504F333F9DE5B)), @bitCast(i128, @as(u128, 0x7FFFFFFFFFFFF328DF915DA296E8A000)), 0);
48 try test__muloti4(@bitCast(i128, @as(u128, 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)), -2, @bitCast(i128, @as(u128, 0x80000000000000000000000000000001)), 1);
49 try test__muloti4(-2, @bitCast(i128, @as(u128, 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)), @bitCast(i128, @as(u128, 0x80000000000000000000000000000001)), 1);
5050
51 test__muloti4(@bitCast(i128, @as(u128, 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)), -1, @bitCast(i128, @as(u128, 0x80000000000000000000000000000001)), 0);
52 test__muloti4(-1, @bitCast(i128, @as(u128, 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)), @bitCast(i128, @as(u128, 0x80000000000000000000000000000001)), 0);
53 test__muloti4(@bitCast(i128, @as(u128, 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)), 0, 0, 0);
54 test__muloti4(0, @bitCast(i128, @as(u128, 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)), 0, 0);
55 test__muloti4(@bitCast(i128, @as(u128, 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)), 1, @bitCast(i128, @as(u128, 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)), 0);
56 test__muloti4(1, @bitCast(i128, @as(u128, 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)), @bitCast(i128, @as(u128, 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)), 0);
57 test__muloti4(@bitCast(i128, @as(u128, 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)), 2, @bitCast(i128, @as(u128, 0x80000000000000000000000000000001)), 1);
58 test__muloti4(2, @bitCast(i128, @as(u128, 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)), @bitCast(i128, @as(u128, 0x80000000000000000000000000000001)), 1);
51 try test__muloti4(@bitCast(i128, @as(u128, 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)), -1, @bitCast(i128, @as(u128, 0x80000000000000000000000000000001)), 0);
52 try test__muloti4(-1, @bitCast(i128, @as(u128, 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)), @bitCast(i128, @as(u128, 0x80000000000000000000000000000001)), 0);
53 try test__muloti4(@bitCast(i128, @as(u128, 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)), 0, 0, 0);
54 try test__muloti4(0, @bitCast(i128, @as(u128, 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)), 0, 0);
55 try test__muloti4(@bitCast(i128, @as(u128, 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)), 1, @bitCast(i128, @as(u128, 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)), 0);
56 try test__muloti4(1, @bitCast(i128, @as(u128, 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)), @bitCast(i128, @as(u128, 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)), 0);
57 try test__muloti4(@bitCast(i128, @as(u128, 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)), 2, @bitCast(i128, @as(u128, 0x80000000000000000000000000000001)), 1);
58 try test__muloti4(2, @bitCast(i128, @as(u128, 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)), @bitCast(i128, @as(u128, 0x80000000000000000000000000000001)), 1);
5959
60 test__muloti4(@bitCast(i128, @as(u128, 0x80000000000000000000000000000000)), -2, @bitCast(i128, @as(u128, 0x80000000000000000000000000000000)), 1);
61 test__muloti4(-2, @bitCast(i128, @as(u128, 0x80000000000000000000000000000000)), @bitCast(i128, @as(u128, 0x80000000000000000000000000000000)), 1);
62 test__muloti4(@bitCast(i128, @as(u128, 0x80000000000000000000000000000000)), -1, @bitCast(i128, @as(u128, 0x80000000000000000000000000000000)), 1);
63 test__muloti4(-1, @bitCast(i128, @as(u128, 0x80000000000000000000000000000000)), @bitCast(i128, @as(u128, 0x80000000000000000000000000000000)), 1);
64 test__muloti4(@bitCast(i128, @as(u128, 0x80000000000000000000000000000000)), 0, 0, 0);
65 test__muloti4(0, @bitCast(i128, @as(u128, 0x80000000000000000000000000000000)), 0, 0);
66 test__muloti4(@bitCast(i128, @as(u128, 0x80000000000000000000000000000000)), 1, @bitCast(i128, @as(u128, 0x80000000000000000000000000000000)), 0);
67 test__muloti4(1, @bitCast(i128, @as(u128, 0x80000000000000000000000000000000)), @bitCast(i128, @as(u128, 0x80000000000000000000000000000000)), 0);
68 test__muloti4(@bitCast(i128, @as(u128, 0x80000000000000000000000000000000)), 2, @bitCast(i128, @as(u128, 0x80000000000000000000000000000000)), 1);
69 test__muloti4(2, @bitCast(i128, @as(u128, 0x80000000000000000000000000000000)), @bitCast(i128, @as(u128, 0x80000000000000000000000000000000)), 1);
60 try test__muloti4(@bitCast(i128, @as(u128, 0x80000000000000000000000000000000)), -2, @bitCast(i128, @as(u128, 0x80000000000000000000000000000000)), 1);
61 try test__muloti4(-2, @bitCast(i128, @as(u128, 0x80000000000000000000000000000000)), @bitCast(i128, @as(u128, 0x80000000000000000000000000000000)), 1);
62 try test__muloti4(@bitCast(i128, @as(u128, 0x80000000000000000000000000000000)), -1, @bitCast(i128, @as(u128, 0x80000000000000000000000000000000)), 1);
63 try test__muloti4(-1, @bitCast(i128, @as(u128, 0x80000000000000000000000000000000)), @bitCast(i128, @as(u128, 0x80000000000000000000000000000000)), 1);
64 try test__muloti4(@bitCast(i128, @as(u128, 0x80000000000000000000000000000000)), 0, 0, 0);
65 try test__muloti4(0, @bitCast(i128, @as(u128, 0x80000000000000000000000000000000)), 0, 0);
66 try test__muloti4(@bitCast(i128, @as(u128, 0x80000000000000000000000000000000)), 1, @bitCast(i128, @as(u128, 0x80000000000000000000000000000000)), 0);
67 try test__muloti4(1, @bitCast(i128, @as(u128, 0x80000000000000000000000000000000)), @bitCast(i128, @as(u128, 0x80000000000000000000000000000000)), 0);
68 try test__muloti4(@bitCast(i128, @as(u128, 0x80000000000000000000000000000000)), 2, @bitCast(i128, @as(u128, 0x80000000000000000000000000000000)), 1);
69 try test__muloti4(2, @bitCast(i128, @as(u128, 0x80000000000000000000000000000000)), @bitCast(i128, @as(u128, 0x80000000000000000000000000000000)), 1);
7070
71 test__muloti4(@bitCast(i128, @as(u128, 0x80000000000000000000000000000001)), -2, @bitCast(i128, @as(u128, 0x80000000000000000000000000000001)), 1);
72 test__muloti4(-2, @bitCast(i128, @as(u128, 0x80000000000000000000000000000001)), @bitCast(i128, @as(u128, 0x80000000000000000000000000000001)), 1);
73 test__muloti4(@bitCast(i128, @as(u128, 0x80000000000000000000000000000001)), -1, @bitCast(i128, @as(u128, 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)), 0);
74 test__muloti4(-1, @bitCast(i128, @as(u128, 0x80000000000000000000000000000001)), @bitCast(i128, @as(u128, 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)), 0);
75 test__muloti4(@bitCast(i128, @as(u128, 0x80000000000000000000000000000001)), 0, 0, 0);
76 test__muloti4(0, @bitCast(i128, @as(u128, 0x80000000000000000000000000000001)), 0, 0);
77 test__muloti4(@bitCast(i128, @as(u128, 0x80000000000000000000000000000001)), 1, @bitCast(i128, @as(u128, 0x80000000000000000000000000000001)), 0);
78 test__muloti4(1, @bitCast(i128, @as(u128, 0x80000000000000000000000000000001)), @bitCast(i128, @as(u128, 0x80000000000000000000000000000001)), 0);
79 test__muloti4(@bitCast(i128, @as(u128, 0x80000000000000000000000000000001)), 2, @bitCast(i128, @as(u128, 0x80000000000000000000000000000000)), 1);
80 test__muloti4(2, @bitCast(i128, @as(u128, 0x80000000000000000000000000000001)), @bitCast(i128, @as(u128, 0x80000000000000000000000000000000)), 1);
71 try test__muloti4(@bitCast(i128, @as(u128, 0x80000000000000000000000000000001)), -2, @bitCast(i128, @as(u128, 0x80000000000000000000000000000001)), 1);
72 try test__muloti4(-2, @bitCast(i128, @as(u128, 0x80000000000000000000000000000001)), @bitCast(i128, @as(u128, 0x80000000000000000000000000000001)), 1);
73 try test__muloti4(@bitCast(i128, @as(u128, 0x80000000000000000000000000000001)), -1, @bitCast(i128, @as(u128, 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)), 0);
74 try test__muloti4(-1, @bitCast(i128, @as(u128, 0x80000000000000000000000000000001)), @bitCast(i128, @as(u128, 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)), 0);
75 try test__muloti4(@bitCast(i128, @as(u128, 0x80000000000000000000000000000001)), 0, 0, 0);
76 try test__muloti4(0, @bitCast(i128, @as(u128, 0x80000000000000000000000000000001)), 0, 0);
77 try test__muloti4(@bitCast(i128, @as(u128, 0x80000000000000000000000000000001)), 1, @bitCast(i128, @as(u128, 0x80000000000000000000000000000001)), 0);
78 try test__muloti4(1, @bitCast(i128, @as(u128, 0x80000000000000000000000000000001)), @bitCast(i128, @as(u128, 0x80000000000000000000000000000001)), 0);
79 try test__muloti4(@bitCast(i128, @as(u128, 0x80000000000000000000000000000001)), 2, @bitCast(i128, @as(u128, 0x80000000000000000000000000000000)), 1);
80 try test__muloti4(2, @bitCast(i128, @as(u128, 0x80000000000000000000000000000001)), @bitCast(i128, @as(u128, 0x80000000000000000000000000000000)), 1);
8181}
lib/std/special/compiler_rt/multi3_test.zig+45-45
......@@ -6,53 +6,53 @@
66const __multi3 = @import("multi3.zig").__multi3;
77const testing = @import("std").testing;
88
9fn test__multi3(a: i128, b: i128, expected: i128) void {
9fn test__multi3(a: i128, b: i128, expected: i128) !void {
1010 const x = __multi3(a, b);
11 testing.expect(x == expected);
11 try testing.expect(x == expected);
1212}
1313
1414test "multi3" {
15 test__multi3(0, 0, 0);
16 test__multi3(0, 1, 0);
17 test__multi3(1, 0, 0);
18 test__multi3(0, 10, 0);
19 test__multi3(10, 0, 0);
20 test__multi3(0, 81985529216486895, 0);
21 test__multi3(81985529216486895, 0, 0);
22
23 test__multi3(0, -1, 0);
24 test__multi3(-1, 0, 0);
25 test__multi3(0, -10, 0);
26 test__multi3(-10, 0, 0);
27 test__multi3(0, -81985529216486895, 0);
28 test__multi3(-81985529216486895, 0, 0);
29
30 test__multi3(1, 1, 1);
31 test__multi3(1, 10, 10);
32 test__multi3(10, 1, 10);
33 test__multi3(1, 81985529216486895, 81985529216486895);
34 test__multi3(81985529216486895, 1, 81985529216486895);
35
36 test__multi3(1, -1, -1);
37 test__multi3(1, -10, -10);
38 test__multi3(-10, 1, -10);
39 test__multi3(1, -81985529216486895, -81985529216486895);
40 test__multi3(-81985529216486895, 1, -81985529216486895);
41
42 test__multi3(3037000499, 3037000499, 9223372030926249001);
43 test__multi3(-3037000499, 3037000499, -9223372030926249001);
44 test__multi3(3037000499, -3037000499, -9223372030926249001);
45 test__multi3(-3037000499, -3037000499, 9223372030926249001);
46
47 test__multi3(4398046511103, 2097152, 9223372036852678656);
48 test__multi3(-4398046511103, 2097152, -9223372036852678656);
49 test__multi3(4398046511103, -2097152, -9223372036852678656);
50 test__multi3(-4398046511103, -2097152, 9223372036852678656);
51
52 test__multi3(2097152, 4398046511103, 9223372036852678656);
53 test__multi3(-2097152, 4398046511103, -9223372036852678656);
54 test__multi3(2097152, -4398046511103, -9223372036852678656);
55 test__multi3(-2097152, -4398046511103, 9223372036852678656);
56
57 test__multi3(0x00000000000000B504F333F9DE5BE000, 0x000000000000000000B504F333F9DE5B, 0x7FFFFFFFFFFFF328DF915DA296E8A000);
15 try test__multi3(0, 0, 0);
16 try test__multi3(0, 1, 0);
17 try test__multi3(1, 0, 0);
18 try test__multi3(0, 10, 0);
19 try test__multi3(10, 0, 0);
20 try test__multi3(0, 81985529216486895, 0);
21 try test__multi3(81985529216486895, 0, 0);
22
23 try test__multi3(0, -1, 0);
24 try test__multi3(-1, 0, 0);
25 try test__multi3(0, -10, 0);
26 try test__multi3(-10, 0, 0);
27 try test__multi3(0, -81985529216486895, 0);
28 try test__multi3(-81985529216486895, 0, 0);
29
30 try test__multi3(1, 1, 1);
31 try test__multi3(1, 10, 10);
32 try test__multi3(10, 1, 10);
33 try test__multi3(1, 81985529216486895, 81985529216486895);
34 try test__multi3(81985529216486895, 1, 81985529216486895);
35
36 try test__multi3(1, -1, -1);
37 try test__multi3(1, -10, -10);
38 try test__multi3(-10, 1, -10);
39 try test__multi3(1, -81985529216486895, -81985529216486895);
40 try test__multi3(-81985529216486895, 1, -81985529216486895);
41
42 try test__multi3(3037000499, 3037000499, 9223372030926249001);
43 try test__multi3(-3037000499, 3037000499, -9223372030926249001);
44 try test__multi3(3037000499, -3037000499, -9223372030926249001);
45 try test__multi3(-3037000499, -3037000499, 9223372030926249001);
46
47 try test__multi3(4398046511103, 2097152, 9223372036852678656);
48 try test__multi3(-4398046511103, 2097152, -9223372036852678656);
49 try test__multi3(4398046511103, -2097152, -9223372036852678656);
50 try test__multi3(-4398046511103, -2097152, 9223372036852678656);
51
52 try test__multi3(2097152, 4398046511103, 9223372036852678656);
53 try test__multi3(-2097152, 4398046511103, -9223372036852678656);
54 try test__multi3(2097152, -4398046511103, -9223372036852678656);
55 try test__multi3(-2097152, -4398046511103, 9223372036852678656);
56
57 try test__multi3(0x00000000000000B504F333F9DE5BE000, 0x000000000000000000B504F333F9DE5B, 0x7FFFFFFFFFFFF328DF915DA296E8A000);
5858}
lib/std/special/compiler_rt/popcountdi2_test.zig+8-8
......@@ -15,18 +15,18 @@ fn naive_popcount(a_param: i64) i32 {
1515 return r;
1616}
1717
18fn test__popcountdi2(a: i64) void {
18fn test__popcountdi2(a: i64) !void {
1919 const x = __popcountdi2(a);
2020 const expected = naive_popcount(a);
21 testing.expect(expected == x);
21 try testing.expect(expected == x);
2222}
2323
2424test "popcountdi2" {
25 test__popcountdi2(0);
26 test__popcountdi2(1);
27 test__popcountdi2(2);
28 test__popcountdi2(@bitCast(i64, @as(u64, 0xFFFFFFFFFFFFFFFD)));
29 test__popcountdi2(@bitCast(i64, @as(u64, 0xFFFFFFFFFFFFFFFE)));
30 test__popcountdi2(@bitCast(i64, @as(u64, 0xFFFFFFFFFFFFFFFF)));
25 try test__popcountdi2(0);
26 try test__popcountdi2(1);
27 try test__popcountdi2(2);
28 try test__popcountdi2(@bitCast(i64, @as(u64, 0xFFFFFFFFFFFFFFFD)));
29 try test__popcountdi2(@bitCast(i64, @as(u64, 0xFFFFFFFFFFFFFFFE)));
30 try test__popcountdi2(@bitCast(i64, @as(u64, 0xFFFFFFFFFFFFFFFF)));
3131 // TODO some fuzz testing
3232}
lib/std/special/compiler_rt/truncXfYf2_test.zig+36-36
......@@ -5,67 +5,67 @@
55// and substantial portions of the software.
66const __truncsfhf2 = @import("truncXfYf2.zig").__truncsfhf2;
77
8fn test__truncsfhf2(a: u32, expected: u16) void {
8fn test__truncsfhf2(a: u32, expected: u16) !void {
99 const actual = __truncsfhf2(@bitCast(f32, a));
1010
1111 if (actual == expected) {
1212 return;
1313 }
1414
15 @panic("__truncsfhf2 test failure");
15 return error.TestFailure;
1616}
1717
1818test "truncsfhf2" {
19 test__truncsfhf2(0x7fc00000, 0x7e00); // qNaN
20 test__truncsfhf2(0x7fe00000, 0x7f00); // sNaN
19 try test__truncsfhf2(0x7fc00000, 0x7e00); // qNaN
20 try test__truncsfhf2(0x7fe00000, 0x7f00); // sNaN
2121
22 test__truncsfhf2(0, 0); // 0
23 test__truncsfhf2(0x80000000, 0x8000); // -0
22 try test__truncsfhf2(0, 0); // 0
23 try test__truncsfhf2(0x80000000, 0x8000); // -0
2424
25 test__truncsfhf2(0x7f800000, 0x7c00); // inf
26 test__truncsfhf2(0xff800000, 0xfc00); // -inf
25 try test__truncsfhf2(0x7f800000, 0x7c00); // inf
26 try test__truncsfhf2(0xff800000, 0xfc00); // -inf
2727
28 test__truncsfhf2(0x477ff000, 0x7c00); // 65520 -> inf
29 test__truncsfhf2(0xc77ff000, 0xfc00); // -65520 -> -inf
28 try test__truncsfhf2(0x477ff000, 0x7c00); // 65520 -> inf
29 try test__truncsfhf2(0xc77ff000, 0xfc00); // -65520 -> -inf
3030
31 test__truncsfhf2(0x71cc3892, 0x7c00); // 0x1.987124876876324p+100 -> inf
32 test__truncsfhf2(0xf1cc3892, 0xfc00); // -0x1.987124876876324p+100 -> -inf
31 try test__truncsfhf2(0x71cc3892, 0x7c00); // 0x1.987124876876324p+100 -> inf
32 try test__truncsfhf2(0xf1cc3892, 0xfc00); // -0x1.987124876876324p+100 -> -inf
3333
34 test__truncsfhf2(0x38800000, 0x0400); // normal (min), 2**-14
35 test__truncsfhf2(0xb8800000, 0x8400); // normal (min), -2**-14
34 try test__truncsfhf2(0x38800000, 0x0400); // normal (min), 2**-14
35 try test__truncsfhf2(0xb8800000, 0x8400); // normal (min), -2**-14
3636
37 test__truncsfhf2(0x477fe000, 0x7bff); // normal (max), 65504
38 test__truncsfhf2(0xc77fe000, 0xfbff); // normal (max), -65504
37 try test__truncsfhf2(0x477fe000, 0x7bff); // normal (max), 65504
38 try test__truncsfhf2(0xc77fe000, 0xfbff); // normal (max), -65504
3939
40 test__truncsfhf2(0x477fe100, 0x7bff); // normal, 65505 -> 65504
41 test__truncsfhf2(0xc77fe100, 0xfbff); // normal, -65505 -> -65504
40 try test__truncsfhf2(0x477fe100, 0x7bff); // normal, 65505 -> 65504
41 try test__truncsfhf2(0xc77fe100, 0xfbff); // normal, -65505 -> -65504
4242
43 test__truncsfhf2(0x477fef00, 0x7bff); // normal, 65519 -> 65504
44 test__truncsfhf2(0xc77fef00, 0xfbff); // normal, -65519 -> -65504
43 try test__truncsfhf2(0x477fef00, 0x7bff); // normal, 65519 -> 65504
44 try test__truncsfhf2(0xc77fef00, 0xfbff); // normal, -65519 -> -65504
4545
46 test__truncsfhf2(0x3f802000, 0x3c01); // normal, 1 + 2**-10
47 test__truncsfhf2(0xbf802000, 0xbc01); // normal, -1 - 2**-10
46 try test__truncsfhf2(0x3f802000, 0x3c01); // normal, 1 + 2**-10
47 try test__truncsfhf2(0xbf802000, 0xbc01); // normal, -1 - 2**-10
4848
49 test__truncsfhf2(0x3eaaa000, 0x3555); // normal, approx. 1/3
50 test__truncsfhf2(0xbeaaa000, 0xb555); // normal, approx. -1/3
49 try test__truncsfhf2(0x3eaaa000, 0x3555); // normal, approx. 1/3
50 try test__truncsfhf2(0xbeaaa000, 0xb555); // normal, approx. -1/3
5151
52 test__truncsfhf2(0x40490fdb, 0x4248); // normal, 3.1415926535
53 test__truncsfhf2(0xc0490fdb, 0xc248); // normal, -3.1415926535
52 try test__truncsfhf2(0x40490fdb, 0x4248); // normal, 3.1415926535
53 try test__truncsfhf2(0xc0490fdb, 0xc248); // normal, -3.1415926535
5454
55 test__truncsfhf2(0x45cc3892, 0x6e62); // normal, 0x1.987124876876324p+12
55 try test__truncsfhf2(0x45cc3892, 0x6e62); // normal, 0x1.987124876876324p+12
5656
57 test__truncsfhf2(0x3f800000, 0x3c00); // normal, 1
58 test__truncsfhf2(0x38800000, 0x0400); // normal, 0x1.0p-14
57 try test__truncsfhf2(0x3f800000, 0x3c00); // normal, 1
58 try test__truncsfhf2(0x38800000, 0x0400); // normal, 0x1.0p-14
5959
60 test__truncsfhf2(0x33800000, 0x0001); // denormal (min), 2**-24
61 test__truncsfhf2(0xb3800000, 0x8001); // denormal (min), -2**-24
60 try test__truncsfhf2(0x33800000, 0x0001); // denormal (min), 2**-24
61 try test__truncsfhf2(0xb3800000, 0x8001); // denormal (min), -2**-24
6262
63 test__truncsfhf2(0x387fc000, 0x03ff); // denormal (max), 2**-14 - 2**-24
64 test__truncsfhf2(0xb87fc000, 0x83ff); // denormal (max), -2**-14 + 2**-24
63 try test__truncsfhf2(0x387fc000, 0x03ff); // denormal (max), 2**-14 - 2**-24
64 try test__truncsfhf2(0xb87fc000, 0x83ff); // denormal (max), -2**-14 + 2**-24
6565
66 test__truncsfhf2(0x35800000, 0x0010); // denormal, 0x1.0p-20
67 test__truncsfhf2(0x33280000, 0x0001); // denormal, 0x1.5p-25 -> 0x1.0p-24
68 test__truncsfhf2(0x33000000, 0x0000); // 0x1.0p-25 -> zero
66 try test__truncsfhf2(0x35800000, 0x0010); // denormal, 0x1.0p-20
67 try test__truncsfhf2(0x33280000, 0x0001); // denormal, 0x1.5p-25 -> 0x1.0p-24
68 try test__truncsfhf2(0x33000000, 0x0000); // 0x1.0p-25 -> zero
6969}
7070
7171const __truncdfhf2 = @import("truncXfYf2.zig").__truncdfhf2;
lib/std/special/compiler_rt/udivmoddi4_test.zig+4-4
......@@ -8,16 +8,16 @@
88const __udivmoddi4 = @import("int.zig").__udivmoddi4;
99const testing = @import("std").testing;
1010
11fn test__udivmoddi4(a: u64, b: u64, expected_q: u64, expected_r: u64) void {
11fn test__udivmoddi4(a: u64, b: u64, expected_q: u64, expected_r: u64) !void {
1212 var r: u64 = undefined;
1313 const q = __udivmoddi4(a, b, &r);
14 testing.expect(q == expected_q);
15 testing.expect(r == expected_r);
14 try testing.expect(q == expected_q);
15 try testing.expect(r == expected_r);
1616}
1717
1818test "udivmoddi4" {
1919 for (cases) |case| {
20 test__udivmoddi4(case[0], case[1], case[2], case[3]);
20 try test__udivmoddi4(case[0], case[1], case[2], case[3]);
2121 }
2222}
2323
lib/std/special/compiler_rt/udivmodti4_test.zig+4-4
......@@ -8,16 +8,16 @@
88const __udivmodti4 = @import("udivmodti4.zig").__udivmodti4;
99const testing = @import("std").testing;
1010
11fn test__udivmodti4(a: u128, b: u128, expected_q: u128, expected_r: u128) void {
11fn test__udivmodti4(a: u128, b: u128, expected_q: u128, expected_r: u128) !void {
1212 var r: u128 = undefined;
1313 const q = __udivmodti4(a, b, &r);
14 testing.expect(q == expected_q);
15 testing.expect(r == expected_r);
14 try testing.expect(q == expected_q);
15 try testing.expect(r == expected_r);
1616}
1717
1818test "udivmodti4" {
1919 for (cases) |case| {
20 test__udivmodti4(case[0], case[1], case[2], case[3]);
20 try test__udivmodti4(case[0], case[1], case[2], case[3]);
2121 }
2222}
2323
lib/std/special/init-lib/src/main.zig+1-1
......@@ -6,5 +6,5 @@ export fn add(a: i32, b: i32) i32 {
66}
77
88test "basic add functionality" {
9 testing.expect(add(3, 7) == 10);
9 try testing.expect(add(3, 7) == 10);
1010}
lib/std/special/test_runner.zig+9-6
......@@ -23,6 +23,7 @@ pub fn main() anyerror!void {
2323 const test_fn_list = builtin.test_functions;
2424 var ok_count: usize = 0;
2525 var skip_count: usize = 0;
26 var fail_count: usize = 0;
2627 var progress = std.Progress{};
2728 const root_node = progress.start("Test", test_fn_list.len) catch |err| switch (err) {
2829 // TODO still run tests in this case
......@@ -62,7 +63,7 @@ pub fn main() anyerror!void {
6263 .blocking => {
6364 skip_count += 1;
6465 test_node.end();
65 progress.log("{s}...SKIP (async test)\n", .{test_fn.name});
66 progress.log("{s}... SKIP (async test)\n", .{test_fn.name});
6667 if (progress.terminal == null) std.debug.print("SKIP (async test)\n", .{});
6768 continue;
6869 },
......@@ -75,12 +76,14 @@ pub fn main() anyerror!void {
7576 error.SkipZigTest => {
7677 skip_count += 1;
7778 test_node.end();
78 progress.log("{s}...SKIP\n", .{test_fn.name});
79 progress.log("{s}... SKIP\n", .{test_fn.name});
7980 if (progress.terminal == null) std.debug.print("SKIP\n", .{});
8081 },
8182 else => {
82 progress.log("", .{});
83 return err;
83 fail_count += 1;
84 test_node.end();
85 progress.log("{s}... FAIL ({s})\n", .{ test_fn.name, @errorName(err) });
86 if (progress.terminal == null) std.debug.print("FAIL ({s})\n", .{@errorName(err)});
8487 },
8588 }
8689 }
......@@ -88,7 +91,7 @@ pub fn main() anyerror!void {
8891 if (ok_count == test_fn_list.len) {
8992 std.debug.print("All {d} tests passed.\n", .{ok_count});
9093 } else {
91 std.debug.print("{d} passed; {d} skipped.\n", .{ ok_count, skip_count });
94 std.debug.print("{d} passed; {d} skipped; {d} failed.\n", .{ ok_count, skip_count, fail_count });
9295 }
9396 if (log_err_count != 0) {
9497 std.debug.print("{d} errors were logged.\n", .{log_err_count});
......@@ -96,7 +99,7 @@ pub fn main() anyerror!void {
9699 if (leaks != 0) {
97100 std.debug.print("{d} tests leaked memory.\n", .{leaks});
98101 }
99 if (leaks != 0 or log_err_count != 0) {
102 if (leaks != 0 or log_err_count != 0 or fail_count != 0) {
100103 std.process.exit(1);
101104 }
102105}
lib/std/testing.zig+63-45
......@@ -27,15 +27,17 @@ pub var zig_exe_path: []const u8 = undefined;
2727
2828/// This function is intended to be used only in tests. It prints diagnostics to stderr
2929/// and then aborts when actual_error_union is not expected_error.
30pub fn expectError(expected_error: anyerror, actual_error_union: anytype) void {
30pub fn expectError(expected_error: anyerror, actual_error_union: anytype) !void {
3131 if (actual_error_union) |actual_payload| {
32 std.debug.panic("expected error.{s}, found {any}", .{ @errorName(expected_error), actual_payload });
32 std.debug.print("expected error.{s}, found {any}", .{ @errorName(expected_error), actual_payload });
33 return error.TestUnexpectedError;
3334 } else |actual_error| {
3435 if (expected_error != actual_error) {
35 std.debug.panic("expected error.{s}, found error.{s}", .{
36 std.debug.print("expected error.{s}, found error.{s}", .{
3637 @errorName(expected_error),
3738 @errorName(actual_error),
3839 });
40 return error.TestExpectedError;
3941 }
4042 }
4143}
......@@ -44,7 +46,7 @@ pub fn expectError(expected_error: anyerror, actual_error_union: anytype) void {
4446/// equal, prints diagnostics to stderr to show exactly how they are not equal,
4547/// then aborts.
4648/// `actual` is casted to the type of `expected`.
47pub fn expectEqual(expected: anytype, actual: @TypeOf(expected)) void {
49pub fn expectEqual(expected: anytype, actual: @TypeOf(expected)) !void {
4850 switch (@typeInfo(@TypeOf(actual))) {
4951 .NoReturn,
5052 .BoundFn,
......@@ -60,7 +62,8 @@ pub fn expectEqual(expected: anytype, actual: @TypeOf(expected)) void {
6062
6163 .Type => {
6264 if (actual != expected) {
63 std.debug.panic("expected type {s}, found type {s}", .{ @typeName(expected), @typeName(actual) });
65 std.debug.print("expected type {s}, found type {s}", .{ @typeName(expected), @typeName(actual) });
66 return error.TestExpectedEqual;
6467 }
6568 },
6669
......@@ -75,7 +78,8 @@ pub fn expectEqual(expected: anytype, actual: @TypeOf(expected)) void {
7578 .ErrorSet,
7679 => {
7780 if (actual != expected) {
78 std.debug.panic("expected {}, found {}", .{ expected, actual });
81 std.debug.print("expected {}, found {}", .{ expected, actual });
82 return error.TestExpectedEqual;
7983 }
8084 },
8185
......@@ -83,34 +87,38 @@ pub fn expectEqual(expected: anytype, actual: @TypeOf(expected)) void {
8387 switch (pointer.size) {
8488 .One, .Many, .C => {
8589 if (actual != expected) {
86 std.debug.panic("expected {*}, found {*}", .{ expected, actual });
90 std.debug.print("expected {*}, found {*}", .{ expected, actual });
91 return error.TestExpectedEqual;
8792 }
8893 },
8994 .Slice => {
9095 if (actual.ptr != expected.ptr) {
91 std.debug.panic("expected slice ptr {*}, found {*}", .{ expected.ptr, actual.ptr });
96 std.debug.print("expected slice ptr {*}, found {*}", .{ expected.ptr, actual.ptr });
97 return error.TestExpectedEqual;
9298 }
9399 if (actual.len != expected.len) {
94 std.debug.panic("expected slice len {}, found {}", .{ expected.len, actual.len });
100 std.debug.print("expected slice len {}, found {}", .{ expected.len, actual.len });
101 return error.TestExpectedEqual;
95102 }
96103 },
97104 }
98105 },
99106
100 .Array => |array| expectEqualSlices(array.child, &expected, &actual),
107 .Array => |array| try expectEqualSlices(array.child, &expected, &actual),
101108
102109 .Vector => |vectorType| {
103110 var i: usize = 0;
104111 while (i < vectorType.len) : (i += 1) {
105112 if (!std.meta.eql(expected[i], actual[i])) {
106 std.debug.panic("index {} incorrect. expected {}, found {}", .{ i, expected[i], actual[i] });
113 std.debug.print("index {} incorrect. expected {}, found {}", .{ i, expected[i], actual[i] });
114 return error.TestExpectedEqual;
107115 }
108116 }
109117 },
110118
111119 .Struct => |structType| {
112120 inline for (structType.fields) |field| {
113 expectEqual(@field(expected, field.name), @field(actual, field.name));
121 try expectEqual(@field(expected, field.name), @field(actual, field.name));
114122 }
115123 },
116124
......@@ -124,12 +132,12 @@ pub fn expectEqual(expected: anytype, actual: @TypeOf(expected)) void {
124132 const expectedTag = @as(Tag, expected);
125133 const actualTag = @as(Tag, actual);
126134
127 expectEqual(expectedTag, actualTag);
135 try expectEqual(expectedTag, actualTag);
128136
129137 // we only reach this loop if the tags are equal
130138 inline for (std.meta.fields(@TypeOf(actual))) |fld| {
131139 if (std.mem.eql(u8, fld.name, @tagName(actualTag))) {
132 expectEqual(@field(expected, fld.name), @field(actual, fld.name));
140 try expectEqual(@field(expected, fld.name), @field(actual, fld.name));
133141 return;
134142 }
135143 }
......@@ -143,13 +151,15 @@ pub fn expectEqual(expected: anytype, actual: @TypeOf(expected)) void {
143151 .Optional => {
144152 if (expected) |expected_payload| {
145153 if (actual) |actual_payload| {
146 expectEqual(expected_payload, actual_payload);
154 try expectEqual(expected_payload, actual_payload);
147155 } else {
148 std.debug.panic("expected {any}, found null", .{expected_payload});
156 std.debug.print("expected {any}, found null", .{expected_payload});
157 return error.TestExpectedEqual;
149158 }
150159 } else {
151160 if (actual) |actual_payload| {
152 std.debug.panic("expected null, found {any}", .{actual_payload});
161 std.debug.print("expected null, found {any}", .{actual_payload});
162 return error.TestExpectedEqual;
153163 }
154164 }
155165 },
......@@ -157,15 +167,17 @@ pub fn expectEqual(expected: anytype, actual: @TypeOf(expected)) void {
157167 .ErrorUnion => {
158168 if (expected) |expected_payload| {
159169 if (actual) |actual_payload| {
160 expectEqual(expected_payload, actual_payload);
170 try expectEqual(expected_payload, actual_payload);
161171 } else |actual_err| {
162 std.debug.panic("expected {any}, found {}", .{ expected_payload, actual_err });
172 std.debug.print("expected {any}, found {}", .{ expected_payload, actual_err });
173 return error.TestExpectedEqual;
163174 }
164175 } else |expected_err| {
165176 if (actual) |actual_payload| {
166 std.debug.panic("expected {}, found {any}", .{ expected_err, actual_payload });
177 std.debug.print("expected {}, found {any}", .{ expected_err, actual_payload });
178 return error.TestExpectedEqual;
167179 } else |actual_err| {
168 expectEqual(expected_err, actual_err);
180 try expectEqual(expected_err, actual_err);
169181 }
170182 }
171183 },
......@@ -181,7 +193,7 @@ test "expectEqual.union(enum)" {
181193 const a10 = T{ .a = 10 };
182194 const a20 = T{ .a = 20 };
183195
184 expectEqual(a10, a10);
196 try expectEqual(a10, a10);
185197}
186198
187199/// This function is intended to be used only in tests. When the formatted result of the template
......@@ -197,7 +209,7 @@ pub fn expectFmt(expected: []const u8, comptime template: []const u8, args: anyt
197209 print("\n======== instead found this: =========\n", .{});
198210 print("{s}", .{result});
199211 print("\n======================================\n", .{});
200 return error.TestFailed;
212 return error.TestExpectedFmt;
201213}
202214
203215pub const expectWithinMargin = @compileError("expectWithinMargin is deprecated, use expectApproxEqAbs or expectApproxEqRel");
......@@ -208,12 +220,14 @@ pub const expectWithinEpsilon = @compileError("expectWithinEpsilon is deprecated
208220/// to show exactly how they are not equal, then aborts.
209221/// See `math.approxEqAbs` for more informations on the tolerance parameter.
210222/// The types must be floating point
211pub fn expectApproxEqAbs(expected: anytype, actual: @TypeOf(expected), tolerance: @TypeOf(expected)) void {
223pub fn expectApproxEqAbs(expected: anytype, actual: @TypeOf(expected), tolerance: @TypeOf(expected)) !void {
212224 const T = @TypeOf(expected);
213225
214226 switch (@typeInfo(T)) {
215 .Float => if (!math.approxEqAbs(T, expected, actual, tolerance))
216 std.debug.panic("actual {}, not within absolute tolerance {} of expected {}", .{ actual, tolerance, expected }),
227 .Float => if (!math.approxEqAbs(T, expected, actual, tolerance)) {
228 std.debug.print("actual {}, not within absolute tolerance {} of expected {}", .{ actual, tolerance, expected });
229 return error.TestExpectedApproxEqAbs;
230 },
217231
218232 .ComptimeFloat => @compileError("Cannot approximately compare two comptime_float values"),
219233
......@@ -228,8 +242,8 @@ test "expectApproxEqAbs" {
228242 const neg_x: T = -12.0;
229243 const neg_y: T = -12.06;
230244
231 expectApproxEqAbs(pos_x, pos_y, 0.1);
232 expectApproxEqAbs(neg_x, neg_y, 0.1);
245 try expectApproxEqAbs(pos_x, pos_y, 0.1);
246 try expectApproxEqAbs(neg_x, neg_y, 0.1);
233247 }
234248}
235249
......@@ -238,12 +252,14 @@ test "expectApproxEqAbs" {
238252/// to show exactly how they are not equal, then aborts.
239253/// See `math.approxEqRel` for more informations on the tolerance parameter.
240254/// The types must be floating point
241pub fn expectApproxEqRel(expected: anytype, actual: @TypeOf(expected), tolerance: @TypeOf(expected)) void {
255pub fn expectApproxEqRel(expected: anytype, actual: @TypeOf(expected), tolerance: @TypeOf(expected)) !void {
242256 const T = @TypeOf(expected);
243257
244258 switch (@typeInfo(T)) {
245 .Float => if (!math.approxEqRel(T, expected, actual, tolerance))
246 std.debug.panic("actual {}, not within relative tolerance {} of expected {}", .{ actual, tolerance, expected }),
259 .Float => if (!math.approxEqRel(T, expected, actual, tolerance)) {
260 std.debug.print("actual {}, not within relative tolerance {} of expected {}", .{ actual, tolerance, expected });
261 return error.TestExpectedApproxEqRel;
262 },
247263
248264 .ComptimeFloat => @compileError("Cannot approximately compare two comptime_float values"),
249265
......@@ -261,8 +277,8 @@ test "expectApproxEqRel" {
261277 const neg_x: T = -12.0;
262278 const neg_y: T = neg_x - 2 * eps_value;
263279
264 expectApproxEqRel(pos_x, pos_y, sqrt_eps_value);
265 expectApproxEqRel(neg_x, neg_y, sqrt_eps_value);
280 try expectApproxEqRel(pos_x, pos_y, sqrt_eps_value);
281 try expectApproxEqRel(neg_x, neg_y, sqrt_eps_value);
266282 }
267283}
268284
......@@ -270,26 +286,28 @@ test "expectApproxEqRel" {
270286/// equal, prints diagnostics to stderr to show exactly how they are not equal,
271287/// then aborts.
272288/// If your inputs are UTF-8 encoded strings, consider calling `expectEqualStrings` instead.
273pub fn expectEqualSlices(comptime T: type, expected: []const T, actual: []const T) void {
289pub fn expectEqualSlices(comptime T: type, expected: []const T, actual: []const T) !void {
274290 // TODO better printing of the difference
275291 // If the arrays are small enough we could print the whole thing
276292 // If the child type is u8 and no weird bytes, we could print it as strings
277293 // Even for the length difference, it would be useful to see the values of the slices probably.
278294 if (expected.len != actual.len) {
279 std.debug.panic("slice lengths differ. expected {d}, found {d}", .{ expected.len, actual.len });
295 std.debug.print("slice lengths differ. expected {d}, found {d}", .{ expected.len, actual.len });
296 return error.TestExpectedEqual;
280297 }
281298 var i: usize = 0;
282299 while (i < expected.len) : (i += 1) {
283300 if (!std.meta.eql(expected[i], actual[i])) {
284 std.debug.panic("index {} incorrect. expected {any}, found {any}", .{ i, expected[i], actual[i] });
301 std.debug.print("index {} incorrect. expected {any}, found {any}", .{ i, expected[i], actual[i] });
302 return error.TestExpectedEqual;
285303 }
286304 }
287305}
288306
289307/// This function is intended to be used only in tests. When `ok` is false, the test fails.
290308/// A message is printed to stderr and then abort is called.
291pub fn expect(ok: bool) void {
292 if (!ok) @panic("test failure");
309pub fn expect(ok: bool) !void {
310 if (!ok) return error.TestUnexpectedResult;
293311}
294312
295313pub const TmpDir = struct {
......@@ -356,17 +374,17 @@ test "expectEqual nested array" {
356374 [_]f32{ 0.0, 1.0 },
357375 };
358376
359 expectEqual(a, b);
377 try expectEqual(a, b);
360378}
361379
362380test "expectEqual vector" {
363381 var a = @splat(4, @as(u32, 4));
364382 var b = @splat(4, @as(u32, 4));
365383
366 expectEqual(a, b);
384 try expectEqual(a, b);
367385}
368386
369pub fn expectEqualStrings(expected: []const u8, actual: []const u8) void {
387pub fn expectEqualStrings(expected: []const u8, actual: []const u8) !void {
370388 if (std.mem.indexOfDiff(u8, actual, expected)) |diff_index| {
371389 print("\n====== expected this output: =========\n", .{});
372390 printWithVisibleNewlines(expected);
......@@ -386,11 +404,11 @@ pub fn expectEqualStrings(expected: []const u8, actual: []const u8) void {
386404 print("found:\n", .{});
387405 printIndicatorLine(actual, diff_index);
388406
389 @panic("test failure");
407 return error.TestExpectedEqual;
390408 }
391409}
392410
393pub fn expectStringEndsWith(actual: []const u8, expected_ends_with: []const u8) void {
411pub fn expectStringEndsWith(actual: []const u8, expected_ends_with: []const u8) !void {
394412 if (std.mem.endsWith(u8, actual, expected_ends_with))
395413 return;
396414
......@@ -407,7 +425,7 @@ pub fn expectStringEndsWith(actual: []const u8, expected_ends_with: []const u8)
407425 printWithVisibleNewlines(actual);
408426 print("\n======================================\n", .{});
409427
410 @panic("test failure");
428 return error.TestExpectedEndsWith;
411429}
412430
413431fn printIndicatorLine(source: []const u8, indicator_index: usize) void {
......@@ -446,7 +464,7 @@ fn printLine(line: []const u8) void {
446464}
447465
448466test {
449 expectEqualStrings("foo", "foo");
467 try expectEqualStrings("foo", "foo");
450468}
451469
452470/// Given a type, reference all the declarations inside, so that the semantic analyzer sees them.
lib/std/time.zig+4-4
......@@ -271,7 +271,7 @@ test "timestamp" {
271271 sleep(ns_per_ms);
272272 const time_1 = milliTimestamp();
273273 const interval = time_1 - time_0;
274 testing.expect(interval > 0);
274 try testing.expect(interval > 0);
275275 // Tests should not depend on timings: skip test if outside margin.
276276 if (!(interval < margin)) return error.SkipZigTest;
277277}
......@@ -282,13 +282,13 @@ test "Timer" {
282282 var timer = try Timer.start();
283283 sleep(10 * ns_per_ms);
284284 const time_0 = timer.read();
285 testing.expect(time_0 > 0);
285 try testing.expect(time_0 > 0);
286286 // Tests should not depend on timings: skip test if outside margin.
287287 if (!(time_0 < margin)) return error.SkipZigTest;
288288
289289 const time_1 = timer.lap();
290 testing.expect(time_1 >= time_0);
290 try testing.expect(time_1 >= time_0);
291291
292292 timer.reset();
293 testing.expect(timer.read() < time_1);
293 try testing.expect(timer.read() < time_1);
294294}
lib/std/unicode.zig+172-172
......@@ -336,224 +336,224 @@ pub const Utf16LeIterator = struct {
336336};
337337
338338test "utf8 encode" {
339 comptime testUtf8Encode() catch unreachable;
339 comptime try testUtf8Encode();
340340 try testUtf8Encode();
341341}
342342fn testUtf8Encode() !void {
343343 // A few taken from wikipedia a few taken elsewhere
344344 var array: [4]u8 = undefined;
345 testing.expect((try utf8Encode(try utf8Decode("€"), array[0..])) == 3);
346 testing.expect(array[0] == 0b11100010);
347 testing.expect(array[1] == 0b10000010);
348 testing.expect(array[2] == 0b10101100);
345 try testing.expect((try utf8Encode(try utf8Decode("€"), array[0..])) == 3);
346 try testing.expect(array[0] == 0b11100010);
347 try testing.expect(array[1] == 0b10000010);
348 try testing.expect(array[2] == 0b10101100);
349349
350 testing.expect((try utf8Encode(try utf8Decode("$"), array[0..])) == 1);
351 testing.expect(array[0] == 0b00100100);
350 try testing.expect((try utf8Encode(try utf8Decode("$"), array[0..])) == 1);
351 try testing.expect(array[0] == 0b00100100);
352352
353 testing.expect((try utf8Encode(try utf8Decode("¢"), array[0..])) == 2);
354 testing.expect(array[0] == 0b11000010);
355 testing.expect(array[1] == 0b10100010);
353 try testing.expect((try utf8Encode(try utf8Decode("¢"), array[0..])) == 2);
354 try testing.expect(array[0] == 0b11000010);
355 try testing.expect(array[1] == 0b10100010);
356356
357 testing.expect((try utf8Encode(try utf8Decode("𐍈"), array[0..])) == 4);
358 testing.expect(array[0] == 0b11110000);
359 testing.expect(array[1] == 0b10010000);
360 testing.expect(array[2] == 0b10001101);
361 testing.expect(array[3] == 0b10001000);
357 try testing.expect((try utf8Encode(try utf8Decode("𐍈"), array[0..])) == 4);
358 try testing.expect(array[0] == 0b11110000);
359 try testing.expect(array[1] == 0b10010000);
360 try testing.expect(array[2] == 0b10001101);
361 try testing.expect(array[3] == 0b10001000);
362362}
363363
364364test "utf8 encode error" {
365 comptime testUtf8EncodeError();
366 testUtf8EncodeError();
365 comptime try testUtf8EncodeError();
366 try testUtf8EncodeError();
367367}
368fn testUtf8EncodeError() void {
368fn testUtf8EncodeError() !void {
369369 var array: [4]u8 = undefined;
370 testErrorEncode(0xd800, array[0..], error.Utf8CannotEncodeSurrogateHalf);
371 testErrorEncode(0xdfff, array[0..], error.Utf8CannotEncodeSurrogateHalf);
372 testErrorEncode(0x110000, array[0..], error.CodepointTooLarge);
373 testErrorEncode(0x1fffff, array[0..], error.CodepointTooLarge);
370 try testErrorEncode(0xd800, array[0..], error.Utf8CannotEncodeSurrogateHalf);
371 try testErrorEncode(0xdfff, array[0..], error.Utf8CannotEncodeSurrogateHalf);
372 try testErrorEncode(0x110000, array[0..], error.CodepointTooLarge);
373 try testErrorEncode(0x1fffff, array[0..], error.CodepointTooLarge);
374374}
375375
376fn testErrorEncode(codePoint: u21, array: []u8, expectedErr: anyerror) void {
377 testing.expectError(expectedErr, utf8Encode(codePoint, array));
376fn testErrorEncode(codePoint: u21, array: []u8, expectedErr: anyerror) !void {
377 try testing.expectError(expectedErr, utf8Encode(codePoint, array));
378378}
379379
380380test "utf8 iterator on ascii" {
381 comptime testUtf8IteratorOnAscii();
382 testUtf8IteratorOnAscii();
381 comptime try testUtf8IteratorOnAscii();
382 try testUtf8IteratorOnAscii();
383383}
384fn testUtf8IteratorOnAscii() void {
384fn testUtf8IteratorOnAscii() !void {
385385 const s = Utf8View.initComptime("abc");
386386
387387 var it1 = s.iterator();
388 testing.expect(std.mem.eql(u8, "a", it1.nextCodepointSlice().?));
389 testing.expect(std.mem.eql(u8, "b", it1.nextCodepointSlice().?));
390 testing.expect(std.mem.eql(u8, "c", it1.nextCodepointSlice().?));
391 testing.expect(it1.nextCodepointSlice() == null);
388 try testing.expect(std.mem.eql(u8, "a", it1.nextCodepointSlice().?));
389 try testing.expect(std.mem.eql(u8, "b", it1.nextCodepointSlice().?));
390 try testing.expect(std.mem.eql(u8, "c", it1.nextCodepointSlice().?));
391 try testing.expect(it1.nextCodepointSlice() == null);
392392
393393 var it2 = s.iterator();
394 testing.expect(it2.nextCodepoint().? == 'a');
395 testing.expect(it2.nextCodepoint().? == 'b');
396 testing.expect(it2.nextCodepoint().? == 'c');
397 testing.expect(it2.nextCodepoint() == null);
394 try testing.expect(it2.nextCodepoint().? == 'a');
395 try testing.expect(it2.nextCodepoint().? == 'b');
396 try testing.expect(it2.nextCodepoint().? == 'c');
397 try testing.expect(it2.nextCodepoint() == null);
398398}
399399
400400test "utf8 view bad" {
401 comptime testUtf8ViewBad();
402 testUtf8ViewBad();
401 comptime try testUtf8ViewBad();
402 try testUtf8ViewBad();
403403}
404fn testUtf8ViewBad() void {
404fn testUtf8ViewBad() !void {
405405 // Compile-time error.
406406 // const s3 = Utf8View.initComptime("\xfe\xf2");
407 testing.expectError(error.InvalidUtf8, Utf8View.init("hel\xadlo"));
407 try testing.expectError(error.InvalidUtf8, Utf8View.init("hel\xadlo"));
408408}
409409
410410test "utf8 view ok" {
411 comptime testUtf8ViewOk();
412 testUtf8ViewOk();
411 comptime try testUtf8ViewOk();
412 try testUtf8ViewOk();
413413}
414fn testUtf8ViewOk() void {
414fn testUtf8ViewOk() !void {
415415 const s = Utf8View.initComptime("東京市");
416416
417417 var it1 = s.iterator();
418 testing.expect(std.mem.eql(u8, "東", it1.nextCodepointSlice().?));
419 testing.expect(std.mem.eql(u8, "京", it1.nextCodepointSlice().?));
420 testing.expect(std.mem.eql(u8, "市", it1.nextCodepointSlice().?));
421 testing.expect(it1.nextCodepointSlice() == null);
418 try testing.expect(std.mem.eql(u8, "東", it1.nextCodepointSlice().?));
419 try testing.expect(std.mem.eql(u8, "京", it1.nextCodepointSlice().?));
420 try testing.expect(std.mem.eql(u8, "市", it1.nextCodepointSlice().?));
421 try testing.expect(it1.nextCodepointSlice() == null);
422422
423423 var it2 = s.iterator();
424 testing.expect(it2.nextCodepoint().? == 0x6771);
425 testing.expect(it2.nextCodepoint().? == 0x4eac);
426 testing.expect(it2.nextCodepoint().? == 0x5e02);
427 testing.expect(it2.nextCodepoint() == null);
424 try testing.expect(it2.nextCodepoint().? == 0x6771);
425 try testing.expect(it2.nextCodepoint().? == 0x4eac);
426 try testing.expect(it2.nextCodepoint().? == 0x5e02);
427 try testing.expect(it2.nextCodepoint() == null);
428428}
429429
430430test "bad utf8 slice" {
431 comptime testBadUtf8Slice();
432 testBadUtf8Slice();
431 comptime try testBadUtf8Slice();
432 try testBadUtf8Slice();
433433}
434fn testBadUtf8Slice() void {
435 testing.expect(utf8ValidateSlice("abc"));
436 testing.expect(!utf8ValidateSlice("abc\xc0"));
437 testing.expect(!utf8ValidateSlice("abc\xc0abc"));
438 testing.expect(utf8ValidateSlice("abc\xdf\xbf"));
434fn testBadUtf8Slice() !void {
435 try testing.expect(utf8ValidateSlice("abc"));
436 try testing.expect(!utf8ValidateSlice("abc\xc0"));
437 try testing.expect(!utf8ValidateSlice("abc\xc0abc"));
438 try testing.expect(utf8ValidateSlice("abc\xdf\xbf"));
439439}
440440
441441test "valid utf8" {
442 comptime testValidUtf8();
443 testValidUtf8();
444}
445fn testValidUtf8() void {
446 testValid("\x00", 0x0);
447 testValid("\x20", 0x20);
448 testValid("\x7f", 0x7f);
449 testValid("\xc2\x80", 0x80);
450 testValid("\xdf\xbf", 0x7ff);
451 testValid("\xe0\xa0\x80", 0x800);
452 testValid("\xe1\x80\x80", 0x1000);
453 testValid("\xef\xbf\xbf", 0xffff);
454 testValid("\xf0\x90\x80\x80", 0x10000);
455 testValid("\xf1\x80\x80\x80", 0x40000);
456 testValid("\xf3\xbf\xbf\xbf", 0xfffff);
457 testValid("\xf4\x8f\xbf\xbf", 0x10ffff);
442 comptime try testValidUtf8();
443 try testValidUtf8();
444}
445fn testValidUtf8() !void {
446 try testValid("\x00", 0x0);
447 try testValid("\x20", 0x20);
448 try testValid("\x7f", 0x7f);
449 try testValid("\xc2\x80", 0x80);
450 try testValid("\xdf\xbf", 0x7ff);
451 try testValid("\xe0\xa0\x80", 0x800);
452 try testValid("\xe1\x80\x80", 0x1000);
453 try testValid("\xef\xbf\xbf", 0xffff);
454 try testValid("\xf0\x90\x80\x80", 0x10000);
455 try testValid("\xf1\x80\x80\x80", 0x40000);
456 try testValid("\xf3\xbf\xbf\xbf", 0xfffff);
457 try testValid("\xf4\x8f\xbf\xbf", 0x10ffff);
458458}
459459
460460test "invalid utf8 continuation bytes" {
461 comptime testInvalidUtf8ContinuationBytes();
462 testInvalidUtf8ContinuationBytes();
461 comptime try testInvalidUtf8ContinuationBytes();
462 try testInvalidUtf8ContinuationBytes();
463463}
464fn testInvalidUtf8ContinuationBytes() void {
464fn testInvalidUtf8ContinuationBytes() !void {
465465 // unexpected continuation
466 testError("\x80", error.Utf8InvalidStartByte);
467 testError("\xbf", error.Utf8InvalidStartByte);
466 try testError("\x80", error.Utf8InvalidStartByte);
467 try testError("\xbf", error.Utf8InvalidStartByte);
468468 // too many leading 1's
469 testError("\xf8", error.Utf8InvalidStartByte);
470 testError("\xff", error.Utf8InvalidStartByte);
469 try testError("\xf8", error.Utf8InvalidStartByte);
470 try testError("\xff", error.Utf8InvalidStartByte);
471471 // expected continuation for 2 byte sequences
472 testError("\xc2", error.UnexpectedEof);
473 testError("\xc2\x00", error.Utf8ExpectedContinuation);
474 testError("\xc2\xc0", error.Utf8ExpectedContinuation);
472 try testError("\xc2", error.UnexpectedEof);
473 try testError("\xc2\x00", error.Utf8ExpectedContinuation);
474 try testError("\xc2\xc0", error.Utf8ExpectedContinuation);
475475 // expected continuation for 3 byte sequences
476 testError("\xe0", error.UnexpectedEof);
477 testError("\xe0\x00", error.UnexpectedEof);
478 testError("\xe0\xc0", error.UnexpectedEof);
479 testError("\xe0\xa0", error.UnexpectedEof);
480 testError("\xe0\xa0\x00", error.Utf8ExpectedContinuation);
481 testError("\xe0\xa0\xc0", error.Utf8ExpectedContinuation);
476 try testError("\xe0", error.UnexpectedEof);
477 try testError("\xe0\x00", error.UnexpectedEof);
478 try testError("\xe0\xc0", error.UnexpectedEof);
479 try testError("\xe0\xa0", error.UnexpectedEof);
480 try testError("\xe0\xa0\x00", error.Utf8ExpectedContinuation);
481 try testError("\xe0\xa0\xc0", error.Utf8ExpectedContinuation);
482482 // expected continuation for 4 byte sequences
483 testError("\xf0", error.UnexpectedEof);
484 testError("\xf0\x00", error.UnexpectedEof);
485 testError("\xf0\xc0", error.UnexpectedEof);
486 testError("\xf0\x90\x00", error.UnexpectedEof);
487 testError("\xf0\x90\xc0", error.UnexpectedEof);
488 testError("\xf0\x90\x80\x00", error.Utf8ExpectedContinuation);
489 testError("\xf0\x90\x80\xc0", error.Utf8ExpectedContinuation);
483 try testError("\xf0", error.UnexpectedEof);
484 try testError("\xf0\x00", error.UnexpectedEof);
485 try testError("\xf0\xc0", error.UnexpectedEof);
486 try testError("\xf0\x90\x00", error.UnexpectedEof);
487 try testError("\xf0\x90\xc0", error.UnexpectedEof);
488 try testError("\xf0\x90\x80\x00", error.Utf8ExpectedContinuation);
489 try testError("\xf0\x90\x80\xc0", error.Utf8ExpectedContinuation);
490490}
491491
492492test "overlong utf8 codepoint" {
493 comptime testOverlongUtf8Codepoint();
494 testOverlongUtf8Codepoint();
493 comptime try testOverlongUtf8Codepoint();
494 try testOverlongUtf8Codepoint();
495495}
496fn testOverlongUtf8Codepoint() void {
497 testError("\xc0\x80", error.Utf8OverlongEncoding);
498 testError("\xc1\xbf", error.Utf8OverlongEncoding);
499 testError("\xe0\x80\x80", error.Utf8OverlongEncoding);
500 testError("\xe0\x9f\xbf", error.Utf8OverlongEncoding);
501 testError("\xf0\x80\x80\x80", error.Utf8OverlongEncoding);
502 testError("\xf0\x8f\xbf\xbf", error.Utf8OverlongEncoding);
496fn testOverlongUtf8Codepoint() !void {
497 try testError("\xc0\x80", error.Utf8OverlongEncoding);
498 try testError("\xc1\xbf", error.Utf8OverlongEncoding);
499 try testError("\xe0\x80\x80", error.Utf8OverlongEncoding);
500 try testError("\xe0\x9f\xbf", error.Utf8OverlongEncoding);
501 try testError("\xf0\x80\x80\x80", error.Utf8OverlongEncoding);
502 try testError("\xf0\x8f\xbf\xbf", error.Utf8OverlongEncoding);
503503}
504504
505505test "misc invalid utf8" {
506 comptime testMiscInvalidUtf8();
507 testMiscInvalidUtf8();
506 comptime try testMiscInvalidUtf8();
507 try testMiscInvalidUtf8();
508508}
509fn testMiscInvalidUtf8() void {
509fn testMiscInvalidUtf8() !void {
510510 // codepoint out of bounds
511 testError("\xf4\x90\x80\x80", error.Utf8CodepointTooLarge);
512 testError("\xf7\xbf\xbf\xbf", error.Utf8CodepointTooLarge);
511 try testError("\xf4\x90\x80\x80", error.Utf8CodepointTooLarge);
512 try testError("\xf7\xbf\xbf\xbf", error.Utf8CodepointTooLarge);
513513 // surrogate halves
514 testValid("\xed\x9f\xbf", 0xd7ff);
515 testError("\xed\xa0\x80", error.Utf8EncodesSurrogateHalf);
516 testError("\xed\xbf\xbf", error.Utf8EncodesSurrogateHalf);
517 testValid("\xee\x80\x80", 0xe000);
514 try testValid("\xed\x9f\xbf", 0xd7ff);
515 try testError("\xed\xa0\x80", error.Utf8EncodesSurrogateHalf);
516 try testError("\xed\xbf\xbf", error.Utf8EncodesSurrogateHalf);
517 try testValid("\xee\x80\x80", 0xe000);
518518}
519519
520520test "utf8 iterator peeking" {
521 comptime testUtf8Peeking();
522 testUtf8Peeking();
521 comptime try testUtf8Peeking();
522 try testUtf8Peeking();
523523}
524524
525fn testUtf8Peeking() void {
525fn testUtf8Peeking() !void {
526526 const s = Utf8View.initComptime("noël");
527527 var it = s.iterator();
528528
529 testing.expect(std.mem.eql(u8, "n", it.nextCodepointSlice().?));
529 try testing.expect(std.mem.eql(u8, "n", it.nextCodepointSlice().?));
530530
531 testing.expect(std.mem.eql(u8, "o", it.peek(1)));
532 testing.expect(std.mem.eql(u8, "oë", it.peek(2)));
533 testing.expect(std.mem.eql(u8, "oël", it.peek(3)));
534 testing.expect(std.mem.eql(u8, "oël", it.peek(4)));
535 testing.expect(std.mem.eql(u8, "oël", it.peek(10)));
531 try testing.expect(std.mem.eql(u8, "o", it.peek(1)));
532 try testing.expect(std.mem.eql(u8, "oë", it.peek(2)));
533 try testing.expect(std.mem.eql(u8, "oël", it.peek(3)));
534 try testing.expect(std.mem.eql(u8, "oël", it.peek(4)));
535 try testing.expect(std.mem.eql(u8, "oël", it.peek(10)));
536536
537 testing.expect(std.mem.eql(u8, "o", it.nextCodepointSlice().?));
538 testing.expect(std.mem.eql(u8, "ë", it.nextCodepointSlice().?));
539 testing.expect(std.mem.eql(u8, "l", it.nextCodepointSlice().?));
540 testing.expect(it.nextCodepointSlice() == null);
537 try testing.expect(std.mem.eql(u8, "o", it.nextCodepointSlice().?));
538 try testing.expect(std.mem.eql(u8, "ë", it.nextCodepointSlice().?));
539 try testing.expect(std.mem.eql(u8, "l", it.nextCodepointSlice().?));
540 try testing.expect(it.nextCodepointSlice() == null);
541541
542 testing.expect(std.mem.eql(u8, &[_]u8{}, it.peek(1)));
542 try testing.expect(std.mem.eql(u8, &[_]u8{}, it.peek(1)));
543543}
544544
545fn testError(bytes: []const u8, expected_err: anyerror) void {
546 testing.expectError(expected_err, testDecode(bytes));
545fn testError(bytes: []const u8, expected_err: anyerror) !void {
546 try testing.expectError(expected_err, testDecode(bytes));
547547}
548548
549fn testValid(bytes: []const u8, expected_codepoint: u21) void {
550 testing.expect((testDecode(bytes) catch unreachable) == expected_codepoint);
549fn testValid(bytes: []const u8, expected_codepoint: u21) !void {
550 try testing.expect((testDecode(bytes) catch unreachable) == expected_codepoint);
551551}
552552
553553fn testDecode(bytes: []const u8) !u21 {
554554 const length = try utf8ByteSequenceLength(bytes[0]);
555555 if (bytes.len < length) return error.UnexpectedEof;
556 testing.expect(bytes.len == length);
556 try testing.expect(bytes.len == length);
557557 return utf8Decode(bytes);
558558}
559559
......@@ -615,7 +615,7 @@ test "utf16leToUtf8" {
615615 mem.writeIntSliceLittle(u16, utf16le_as_bytes[2..], 'a');
616616 const utf8 = try utf16leToUtf8Alloc(std.testing.allocator, &utf16le);
617617 defer std.testing.allocator.free(utf8);
618 testing.expect(mem.eql(u8, utf8, "Aa"));
618 try testing.expect(mem.eql(u8, utf8, "Aa"));
619619 }
620620
621621 {
......@@ -623,7 +623,7 @@ test "utf16leToUtf8" {
623623 mem.writeIntSliceLittle(u16, utf16le_as_bytes[2..], 0xffff);
624624 const utf8 = try utf16leToUtf8Alloc(std.testing.allocator, &utf16le);
625625 defer std.testing.allocator.free(utf8);
626 testing.expect(mem.eql(u8, utf8, "\xc2\x80" ++ "\xef\xbf\xbf"));
626 try testing.expect(mem.eql(u8, utf8, "\xc2\x80" ++ "\xef\xbf\xbf"));
627627 }
628628
629629 {
......@@ -632,7 +632,7 @@ test "utf16leToUtf8" {
632632 mem.writeIntSliceLittle(u16, utf16le_as_bytes[2..], 0xe000);
633633 const utf8 = try utf16leToUtf8Alloc(std.testing.allocator, &utf16le);
634634 defer std.testing.allocator.free(utf8);
635 testing.expect(mem.eql(u8, utf8, "\xed\x9f\xbf" ++ "\xee\x80\x80"));
635 try testing.expect(mem.eql(u8, utf8, "\xed\x9f\xbf" ++ "\xee\x80\x80"));
636636 }
637637
638638 {
......@@ -641,7 +641,7 @@ test "utf16leToUtf8" {
641641 mem.writeIntSliceLittle(u16, utf16le_as_bytes[2..], 0xdc00);
642642 const utf8 = try utf16leToUtf8Alloc(std.testing.allocator, &utf16le);
643643 defer std.testing.allocator.free(utf8);
644 testing.expect(mem.eql(u8, utf8, "\xf0\x90\x80\x80"));
644 try testing.expect(mem.eql(u8, utf8, "\xf0\x90\x80\x80"));
645645 }
646646
647647 {
......@@ -650,7 +650,7 @@ test "utf16leToUtf8" {
650650 mem.writeIntSliceLittle(u16, utf16le_as_bytes[2..], 0xdfff);
651651 const utf8 = try utf16leToUtf8Alloc(std.testing.allocator, &utf16le);
652652 defer std.testing.allocator.free(utf8);
653 testing.expect(mem.eql(u8, utf8, "\xf4\x8f\xbf\xbf"));
653 try testing.expect(mem.eql(u8, utf8, "\xf4\x8f\xbf\xbf"));
654654 }
655655
656656 {
......@@ -658,7 +658,7 @@ test "utf16leToUtf8" {
658658 mem.writeIntSliceLittle(u16, utf16le_as_bytes[2..], 0xdc00);
659659 const utf8 = try utf16leToUtf8Alloc(std.testing.allocator, &utf16le);
660660 defer std.testing.allocator.free(utf8);
661 testing.expect(mem.eql(u8, utf8, "\xf4\x8f\xb0\x80"));
661 try testing.expect(mem.eql(u8, utf8, "\xf4\x8f\xb0\x80"));
662662 }
663663}
664664
......@@ -717,13 +717,13 @@ test "utf8ToUtf16Le" {
717717 var utf16le: [2]u16 = [_]u16{0} ** 2;
718718 {
719719 const length = try utf8ToUtf16Le(utf16le[0..], "𐐷");
720 testing.expectEqual(@as(usize, 2), length);
721 testing.expectEqualSlices(u8, "\x01\xd8\x37\xdc", mem.sliceAsBytes(utf16le[0..]));
720 try testing.expectEqual(@as(usize, 2), length);
721 try testing.expectEqualSlices(u8, "\x01\xd8\x37\xdc", mem.sliceAsBytes(utf16le[0..]));
722722 }
723723 {
724724 const length = try utf8ToUtf16Le(utf16le[0..], "\u{10FFFF}");
725 testing.expectEqual(@as(usize, 2), length);
726 testing.expectEqualSlices(u8, "\xff\xdb\xff\xdf", mem.sliceAsBytes(utf16le[0..]));
725 try testing.expectEqual(@as(usize, 2), length);
726 try testing.expectEqualSlices(u8, "\xff\xdb\xff\xdf", mem.sliceAsBytes(utf16le[0..]));
727727 }
728728}
729729
......@@ -731,14 +731,14 @@ test "utf8ToUtf16LeWithNull" {
731731 {
732732 const utf16 = try utf8ToUtf16LeWithNull(testing.allocator, "𐐷");
733733 defer testing.allocator.free(utf16);
734 testing.expectEqualSlices(u8, "\x01\xd8\x37\xdc", mem.sliceAsBytes(utf16[0..]));
735 testing.expect(utf16[2] == 0);
734 try testing.expectEqualSlices(u8, "\x01\xd8\x37\xdc", mem.sliceAsBytes(utf16[0..]));
735 try testing.expect(utf16[2] == 0);
736736 }
737737 {
738738 const utf16 = try utf8ToUtf16LeWithNull(testing.allocator, "\u{10FFFF}");
739739 defer testing.allocator.free(utf16);
740 testing.expectEqualSlices(u8, "\xff\xdb\xff\xdf", mem.sliceAsBytes(utf16[0..]));
741 testing.expect(utf16[2] == 0);
740 try testing.expectEqualSlices(u8, "\xff\xdb\xff\xdf", mem.sliceAsBytes(utf16[0..]));
741 try testing.expect(utf16[2] == 0);
742742 }
743743}
744744
......@@ -776,8 +776,8 @@ test "utf8ToUtf16LeStringLiteral" {
776776 mem.nativeToLittle(u16, 0x41),
777777 };
778778 const utf16 = utf8ToUtf16LeStringLiteral("A");
779 testing.expectEqualSlices(u16, &bytes, utf16);
780 testing.expect(utf16[1] == 0);
779 try testing.expectEqualSlices(u16, &bytes, utf16);
780 try testing.expect(utf16[1] == 0);
781781 }
782782 {
783783 const bytes = [_:0]u16{
......@@ -785,32 +785,32 @@ test "utf8ToUtf16LeStringLiteral" {
785785 mem.nativeToLittle(u16, 0xDC37),
786786 };
787787 const utf16 = utf8ToUtf16LeStringLiteral("𐐷");
788 testing.expectEqualSlices(u16, &bytes, utf16);
789 testing.expect(utf16[2] == 0);
788 try testing.expectEqualSlices(u16, &bytes, utf16);
789 try testing.expect(utf16[2] == 0);
790790 }
791791 {
792792 const bytes = [_:0]u16{
793793 mem.nativeToLittle(u16, 0x02FF),
794794 };
795795 const utf16 = utf8ToUtf16LeStringLiteral("\u{02FF}");
796 testing.expectEqualSlices(u16, &bytes, utf16);
797 testing.expect(utf16[1] == 0);
796 try testing.expectEqualSlices(u16, &bytes, utf16);
797 try testing.expect(utf16[1] == 0);
798798 }
799799 {
800800 const bytes = [_:0]u16{
801801 mem.nativeToLittle(u16, 0x7FF),
802802 };
803803 const utf16 = utf8ToUtf16LeStringLiteral("\u{7FF}");
804 testing.expectEqualSlices(u16, &bytes, utf16);
805 testing.expect(utf16[1] == 0);
804 try testing.expectEqualSlices(u16, &bytes, utf16);
805 try testing.expect(utf16[1] == 0);
806806 }
807807 {
808808 const bytes = [_:0]u16{
809809 mem.nativeToLittle(u16, 0x801),
810810 };
811811 const utf16 = utf8ToUtf16LeStringLiteral("\u{801}");
812 testing.expectEqualSlices(u16, &bytes, utf16);
813 testing.expect(utf16[1] == 0);
812 try testing.expectEqualSlices(u16, &bytes, utf16);
813 try testing.expect(utf16[1] == 0);
814814 }
815815 {
816816 const bytes = [_:0]u16{
......@@ -818,35 +818,35 @@ test "utf8ToUtf16LeStringLiteral" {
818818 mem.nativeToLittle(u16, 0xDFFF),
819819 };
820820 const utf16 = utf8ToUtf16LeStringLiteral("\u{10FFFF}");
821 testing.expectEqualSlices(u16, &bytes, utf16);
822 testing.expect(utf16[2] == 0);
821 try testing.expectEqualSlices(u16, &bytes, utf16);
822 try testing.expect(utf16[2] == 0);
823823 }
824824}
825825
826826fn testUtf8CountCodepoints() !void {
827 testing.expectEqual(@as(usize, 10), try utf8CountCodepoints("abcdefghij"));
828 testing.expectEqual(@as(usize, 10), try utf8CountCodepoints("äåéëþüúíóö"));
829 testing.expectEqual(@as(usize, 5), try utf8CountCodepoints("こんにちは"));
827 try testing.expectEqual(@as(usize, 10), try utf8CountCodepoints("abcdefghij"));
828 try testing.expectEqual(@as(usize, 10), try utf8CountCodepoints("äåéëþüúíóö"));
829 try testing.expectEqual(@as(usize, 5), try utf8CountCodepoints("こんにちは"));
830830 // testing.expectError(error.Utf8EncodesSurrogateHalf, utf8CountCodepoints("\xED\xA0\x80"));
831831}
832832
833833test "utf8 count codepoints" {
834834 try testUtf8CountCodepoints();
835 comptime testUtf8CountCodepoints() catch unreachable;
835 comptime try testUtf8CountCodepoints();
836836}
837837
838838fn testUtf8ValidCodepoint() !void {
839 testing.expect(utf8ValidCodepoint('e'));
840 testing.expect(utf8ValidCodepoint('ë'));
841 testing.expect(utf8ValidCodepoint('は'));
842 testing.expect(utf8ValidCodepoint(0xe000));
843 testing.expect(utf8ValidCodepoint(0x10ffff));
844 testing.expect(!utf8ValidCodepoint(0xd800));
845 testing.expect(!utf8ValidCodepoint(0xdfff));
846 testing.expect(!utf8ValidCodepoint(0x110000));
839 try testing.expect(utf8ValidCodepoint('e'));
840 try testing.expect(utf8ValidCodepoint('ë'));
841 try testing.expect(utf8ValidCodepoint('は'));
842 try testing.expect(utf8ValidCodepoint(0xe000));
843 try testing.expect(utf8ValidCodepoint(0x10ffff));
844 try testing.expect(!utf8ValidCodepoint(0xd800));
845 try testing.expect(!utf8ValidCodepoint(0xdfff));
846 try testing.expect(!utf8ValidCodepoint(0x110000));
847847}
848848
849849test "utf8 valid codepoint" {
850850 try testUtf8ValidCodepoint();
851 comptime testUtf8ValidCodepoint() catch unreachable;
851 comptime try testUtf8ValidCodepoint();
852852}
lib/std/valgrind/memcheck.zig+2-2
......@@ -149,7 +149,7 @@ pub fn countLeaks() CountResult {
149149}
150150
151151test "countLeaks" {
152 testing.expectEqual(
152 try testing.expectEqual(
153153 @as(CountResult, .{
154154 .leaked = 0,
155155 .dubious = 0,
......@@ -179,7 +179,7 @@ pub fn countLeakBlocks() CountResult {
179179}
180180
181181test "countLeakBlocks" {
182 testing.expectEqual(
182 try testing.expectEqual(
183183 @as(CountResult, .{
184184 .leaked = 0,
185185 .dubious = 0,
lib/std/wasm.zig+9-9
......@@ -200,11 +200,11 @@ test "Wasm - opcodes" {
200200 const local_get = opcode(.local_get);
201201 const i64_extend32_s = opcode(.i64_extend32_s);
202202
203 testing.expectEqual(@as(u16, 0x41), i32_const);
204 testing.expectEqual(@as(u16, 0x0B), end);
205 testing.expectEqual(@as(u16, 0x1A), drop);
206 testing.expectEqual(@as(u16, 0x20), local_get);
207 testing.expectEqual(@as(u16, 0xC4), i64_extend32_s);
203 try testing.expectEqual(@as(u16, 0x41), i32_const);
204 try testing.expectEqual(@as(u16, 0x0B), end);
205 try testing.expectEqual(@as(u16, 0x1A), drop);
206 try testing.expectEqual(@as(u16, 0x20), local_get);
207 try testing.expectEqual(@as(u16, 0xC4), i64_extend32_s);
208208}
209209
210210/// Enum representing all Wasm value types as per spec:
......@@ -227,10 +227,10 @@ test "Wasm - valtypes" {
227227 const _f32 = valtype(.f32);
228228 const _f64 = valtype(.f64);
229229
230 testing.expectEqual(@as(u8, 0x7F), _i32);
231 testing.expectEqual(@as(u8, 0x7E), _i64);
232 testing.expectEqual(@as(u8, 0x7D), _f32);
233 testing.expectEqual(@as(u8, 0x7C), _f64);
230 try testing.expectEqual(@as(u8, 0x7F), _i32);
231 try testing.expectEqual(@as(u8, 0x7E), _i64);
232 try testing.expectEqual(@as(u8, 0x7D), _f32);
233 try testing.expectEqual(@as(u8, 0x7C), _f64);
234234}
235235
236236/// Wasm module sections as per spec:
lib/std/x/net/tcp.zig+3-3
......@@ -322,7 +322,7 @@ test "tcp/client: set read timeout of 1 millisecond on blocking client" {
322322 defer conn.deinit();
323323
324324 var buf: [1]u8 = undefined;
325 testing.expectError(error.WouldBlock, client.read(&buf));
325 try testing.expectError(error.WouldBlock, client.read(&buf));
326326}
327327
328328test "tcp/listener: bind to unspecified ipv4 address" {
......@@ -335,7 +335,7 @@ test "tcp/listener: bind to unspecified ipv4 address" {
335335 try listener.listen(128);
336336
337337 const address = try listener.getLocalAddress();
338 testing.expect(address == .ipv4);
338 try testing.expect(address == .ipv4);
339339}
340340
341341test "tcp/listener: bind to unspecified ipv6 address" {
......@@ -348,5 +348,5 @@ test "tcp/listener: bind to unspecified ipv6 address" {
348348 try listener.listen(128);
349349
350350 const address = try listener.getLocalAddress();
351 testing.expect(address == .ipv6);
351 try testing.expect(address == .ipv6);
352352}
lib/std/x/os/net.zig+3-3
......@@ -499,12 +499,12 @@ test {
499499
500500test "ip: convert to and from ipv6" {
501501 try testing.expectFmt("::7f00:1", "{}", .{IPv4.localhost.toIPv6()});
502 testing.expect(!IPv4.localhost.toIPv6().mapsToIPv4());
502 try testing.expect(!IPv4.localhost.toIPv6().mapsToIPv4());
503503
504504 try testing.expectFmt("::ffff:127.0.0.1", "{}", .{IPv4.localhost.mapToIPv6()});
505 testing.expect(IPv4.localhost.mapToIPv6().mapsToIPv4());
505 try testing.expect(IPv4.localhost.mapToIPv6().mapsToIPv4());
506506
507 testing.expect(IPv4.localhost.toIPv6().toIPv4() == null);
507 try testing.expect(IPv4.localhost.toIPv6().toIPv4() == null);
508508 try testing.expectFmt("127.0.0.1", "{}", .{IPv4.localhost.mapToIPv6().toIPv4()});
509509}
510510
lib/std/zig.zig+19-19
......@@ -257,26 +257,26 @@ pub fn parseCharLiteral(
257257
258258test "parseCharLiteral" {
259259 var bad_index: usize = undefined;
260 std.testing.expectEqual(try parseCharLiteral("'a'", &bad_index), 'a');
261 std.testing.expectEqual(try parseCharLiteral("'ä'", &bad_index), 'ä');
262 std.testing.expectEqual(try parseCharLiteral("'\\x00'", &bad_index), 0);
263 std.testing.expectEqual(try parseCharLiteral("'\\x4f'", &bad_index), 0x4f);
264 std.testing.expectEqual(try parseCharLiteral("'\\x4F'", &bad_index), 0x4f);
265 std.testing.expectEqual(try parseCharLiteral("'ぁ'", &bad_index), 0x3041);
266 std.testing.expectEqual(try parseCharLiteral("'\\u{0}'", &bad_index), 0);
267 std.testing.expectEqual(try parseCharLiteral("'\\u{3041}'", &bad_index), 0x3041);
268 std.testing.expectEqual(try parseCharLiteral("'\\u{7f}'", &bad_index), 0x7f);
269 std.testing.expectEqual(try parseCharLiteral("'\\u{7FFF}'", &bad_index), 0x7FFF);
260 try std.testing.expectEqual(try parseCharLiteral("'a'", &bad_index), 'a');
261 try std.testing.expectEqual(try parseCharLiteral("'ä'", &bad_index), 'ä');
262 try std.testing.expectEqual(try parseCharLiteral("'\\x00'", &bad_index), 0);
263 try std.testing.expectEqual(try parseCharLiteral("'\\x4f'", &bad_index), 0x4f);
264 try std.testing.expectEqual(try parseCharLiteral("'\\x4F'", &bad_index), 0x4f);
265 try std.testing.expectEqual(try parseCharLiteral("'ぁ'", &bad_index), 0x3041);
266 try std.testing.expectEqual(try parseCharLiteral("'\\u{0}'", &bad_index), 0);
267 try std.testing.expectEqual(try parseCharLiteral("'\\u{3041}'", &bad_index), 0x3041);
268 try std.testing.expectEqual(try parseCharLiteral("'\\u{7f}'", &bad_index), 0x7f);
269 try std.testing.expectEqual(try parseCharLiteral("'\\u{7FFF}'", &bad_index), 0x7FFF);
270270
271 std.testing.expectError(error.InvalidCharacter, parseCharLiteral("'\\x0'", &bad_index));
272 std.testing.expectError(error.InvalidCharacter, parseCharLiteral("'\\x000'", &bad_index));
273 std.testing.expectError(error.InvalidCharacter, parseCharLiteral("'\\y'", &bad_index));
274 std.testing.expectError(error.InvalidCharacter, parseCharLiteral("'\\u'", &bad_index));
275 std.testing.expectError(error.InvalidCharacter, parseCharLiteral("'\\uFFFF'", &bad_index));
276 std.testing.expectError(error.InvalidCharacter, parseCharLiteral("'\\u{}'", &bad_index));
277 std.testing.expectError(error.InvalidCharacter, parseCharLiteral("'\\u{FFFFFF}'", &bad_index));
278 std.testing.expectError(error.InvalidCharacter, parseCharLiteral("'\\u{FFFF'", &bad_index));
279 std.testing.expectError(error.InvalidCharacter, parseCharLiteral("'\\u{FFFF}x'", &bad_index));
271 try std.testing.expectError(error.InvalidCharacter, parseCharLiteral("'\\x0'", &bad_index));
272 try std.testing.expectError(error.InvalidCharacter, parseCharLiteral("'\\x000'", &bad_index));
273 try std.testing.expectError(error.InvalidCharacter, parseCharLiteral("'\\y'", &bad_index));
274 try std.testing.expectError(error.InvalidCharacter, parseCharLiteral("'\\u'", &bad_index));
275 try std.testing.expectError(error.InvalidCharacter, parseCharLiteral("'\\uFFFF'", &bad_index));
276 try std.testing.expectError(error.InvalidCharacter, parseCharLiteral("'\\u{}'", &bad_index));
277 try std.testing.expectError(error.InvalidCharacter, parseCharLiteral("'\\u{FFFFFF}'", &bad_index));
278 try std.testing.expectError(error.InvalidCharacter, parseCharLiteral("'\\u{FFFF'", &bad_index));
279 try std.testing.expectError(error.InvalidCharacter, parseCharLiteral("'\\u{FFFF}x'", &bad_index));
280280}
281281
282282test {
lib/std/zig/cross_target.zig+38-38
......@@ -800,7 +800,7 @@ test "CrossTarget.parse" {
800800 .{@tagName(std.Target.current.abi)},
801801 ) catch unreachable;
802802
803 std.testing.expectEqualSlices(u8, triple, text);
803 try std.testing.expectEqualSlices(u8, triple, text);
804804 }
805805 {
806806 const cross_target = try CrossTarget.parse(.{
......@@ -808,18 +808,18 @@ test "CrossTarget.parse" {
808808 .cpu_features = "native",
809809 });
810810
811 std.testing.expect(cross_target.cpu_arch.? == .aarch64);
812 std.testing.expect(cross_target.cpu_model == .native);
811 try std.testing.expect(cross_target.cpu_arch.? == .aarch64);
812 try std.testing.expect(cross_target.cpu_model == .native);
813813 }
814814 {
815815 const cross_target = try CrossTarget.parse(.{ .arch_os_abi = "native" });
816816
817 std.testing.expect(cross_target.cpu_arch == null);
818 std.testing.expect(cross_target.isNative());
817 try std.testing.expect(cross_target.cpu_arch == null);
818 try std.testing.expect(cross_target.isNative());
819819
820820 const text = try cross_target.zigTriple(std.testing.allocator);
821821 defer std.testing.allocator.free(text);
822 std.testing.expectEqualSlices(u8, "native", text);
822 try std.testing.expectEqualSlices(u8, "native", text);
823823 }
824824 {
825825 const cross_target = try CrossTarget.parse(.{
......@@ -828,23 +828,23 @@ test "CrossTarget.parse" {
828828 });
829829 const target = cross_target.toTarget();
830830
831 std.testing.expect(target.os.tag == .linux);
832 std.testing.expect(target.abi == .gnu);
833 std.testing.expect(target.cpu.arch == .x86_64);
834 std.testing.expect(!Target.x86.featureSetHas(target.cpu.features, .sse));
835 std.testing.expect(!Target.x86.featureSetHas(target.cpu.features, .avx));
836 std.testing.expect(!Target.x86.featureSetHas(target.cpu.features, .cx8));
837 std.testing.expect(Target.x86.featureSetHas(target.cpu.features, .cmov));
838 std.testing.expect(Target.x86.featureSetHas(target.cpu.features, .fxsr));
831 try std.testing.expect(target.os.tag == .linux);
832 try std.testing.expect(target.abi == .gnu);
833 try std.testing.expect(target.cpu.arch == .x86_64);
834 try std.testing.expect(!Target.x86.featureSetHas(target.cpu.features, .sse));
835 try std.testing.expect(!Target.x86.featureSetHas(target.cpu.features, .avx));
836 try std.testing.expect(!Target.x86.featureSetHas(target.cpu.features, .cx8));
837 try std.testing.expect(Target.x86.featureSetHas(target.cpu.features, .cmov));
838 try std.testing.expect(Target.x86.featureSetHas(target.cpu.features, .fxsr));
839839
840 std.testing.expect(Target.x86.featureSetHasAny(target.cpu.features, .{ .sse, .avx, .cmov }));
841 std.testing.expect(!Target.x86.featureSetHasAny(target.cpu.features, .{ .sse, .avx }));
842 std.testing.expect(Target.x86.featureSetHasAll(target.cpu.features, .{ .mmx, .x87 }));
843 std.testing.expect(!Target.x86.featureSetHasAll(target.cpu.features, .{ .mmx, .x87, .sse }));
840 try std.testing.expect(Target.x86.featureSetHasAny(target.cpu.features, .{ .sse, .avx, .cmov }));
841 try std.testing.expect(!Target.x86.featureSetHasAny(target.cpu.features, .{ .sse, .avx }));
842 try std.testing.expect(Target.x86.featureSetHasAll(target.cpu.features, .{ .mmx, .x87 }));
843 try std.testing.expect(!Target.x86.featureSetHasAll(target.cpu.features, .{ .mmx, .x87, .sse }));
844844
845845 const text = try cross_target.zigTriple(std.testing.allocator);
846846 defer std.testing.allocator.free(text);
847 std.testing.expectEqualSlices(u8, "x86_64-linux-gnu", text);
847 try std.testing.expectEqualSlices(u8, "x86_64-linux-gnu", text);
848848 }
849849 {
850850 const cross_target = try CrossTarget.parse(.{
......@@ -853,15 +853,15 @@ test "CrossTarget.parse" {
853853 });
854854 const target = cross_target.toTarget();
855855
856 std.testing.expect(target.os.tag == .linux);
857 std.testing.expect(target.abi == .musleabihf);
858 std.testing.expect(target.cpu.arch == .arm);
859 std.testing.expect(target.cpu.model == &Target.arm.cpu.generic);
860 std.testing.expect(Target.arm.featureSetHas(target.cpu.features, .v8a));
856 try std.testing.expect(target.os.tag == .linux);
857 try std.testing.expect(target.abi == .musleabihf);
858 try std.testing.expect(target.cpu.arch == .arm);
859 try std.testing.expect(target.cpu.model == &Target.arm.cpu.generic);
860 try std.testing.expect(Target.arm.featureSetHas(target.cpu.features, .v8a));
861861
862862 const text = try cross_target.zigTriple(std.testing.allocator);
863863 defer std.testing.allocator.free(text);
864 std.testing.expectEqualSlices(u8, "arm-linux-musleabihf", text);
864 try std.testing.expectEqualSlices(u8, "arm-linux-musleabihf", text);
865865 }
866866 {
867867 const cross_target = try CrossTarget.parse(.{
......@@ -870,21 +870,21 @@ test "CrossTarget.parse" {
870870 });
871871 const target = cross_target.toTarget();
872872
873 std.testing.expect(target.cpu.arch == .aarch64);
874 std.testing.expect(target.os.tag == .linux);
875 std.testing.expect(target.os.version_range.linux.range.min.major == 3);
876 std.testing.expect(target.os.version_range.linux.range.min.minor == 10);
877 std.testing.expect(target.os.version_range.linux.range.min.patch == 0);
878 std.testing.expect(target.os.version_range.linux.range.max.major == 4);
879 std.testing.expect(target.os.version_range.linux.range.max.minor == 4);
880 std.testing.expect(target.os.version_range.linux.range.max.patch == 1);
881 std.testing.expect(target.os.version_range.linux.glibc.major == 2);
882 std.testing.expect(target.os.version_range.linux.glibc.minor == 27);
883 std.testing.expect(target.os.version_range.linux.glibc.patch == 0);
884 std.testing.expect(target.abi == .gnu);
873 try std.testing.expect(target.cpu.arch == .aarch64);
874 try std.testing.expect(target.os.tag == .linux);
875 try std.testing.expect(target.os.version_range.linux.range.min.major == 3);
876 try std.testing.expect(target.os.version_range.linux.range.min.minor == 10);
877 try std.testing.expect(target.os.version_range.linux.range.min.patch == 0);
878 try std.testing.expect(target.os.version_range.linux.range.max.major == 4);
879 try std.testing.expect(target.os.version_range.linux.range.max.minor == 4);
880 try std.testing.expect(target.os.version_range.linux.range.max.patch == 1);
881 try std.testing.expect(target.os.version_range.linux.glibc.major == 2);
882 try std.testing.expect(target.os.version_range.linux.glibc.minor == 27);
883 try std.testing.expect(target.os.version_range.linux.glibc.patch == 0);
884 try std.testing.expect(target.abi == .gnu);
885885
886886 const text = try cross_target.zigTriple(std.testing.allocator);
887887 defer std.testing.allocator.free(text);
888 std.testing.expectEqualSlices(u8, "aarch64-linux.3.10...4.4.1-gnu.2.27", text);
888 try std.testing.expectEqualSlices(u8, "aarch64-linux.3.10...4.4.1-gnu.2.27", text);
889889 }
890890}
lib/std/zig/parser_test.zig+9-10
......@@ -988,7 +988,7 @@ test "zig fmt: while else err prong with no block" {
988988 \\ const result = while (returnError()) |value| {
989989 \\ break value;
990990 \\ } else |err| @as(i32, 2);
991 \\ expect(result == 2);
991 \\ try expect(result == 2);
992992 \\}
993993 \\
994994 );
......@@ -5135,7 +5135,7 @@ test "recovery: missing while rbrace" {
51355135
51365136const std = @import("std");
51375137const mem = std.mem;
5138const warn = std.debug.warn;
5138const print = std.debug.print;
51395139const io = std.io;
51405140const maxInt = std.math.maxInt;
51415141
......@@ -5177,13 +5177,13 @@ fn testTransform(source: []const u8, expected_source: []const u8) !void {
51775177 var failing_allocator = std.testing.FailingAllocator.init(&fixed_allocator.allocator, maxInt(usize));
51785178 var anything_changed: bool = undefined;
51795179 const result_source = try testParse(source, &failing_allocator.allocator, &anything_changed);
5180 std.testing.expectEqualStrings(expected_source, result_source);
5180 try std.testing.expectEqualStrings(expected_source, result_source);
51815181 const changes_expected = source.ptr != expected_source.ptr;
51825182 if (anything_changed != changes_expected) {
5183 warn("std.zig.render returned {} instead of {}\n", .{ anything_changed, changes_expected });
5183 print("std.zig.render returned {} instead of {}\n", .{ anything_changed, changes_expected });
51845184 return error.TestFailed;
51855185 }
5186 std.testing.expect(anything_changed == changes_expected);
5186 try std.testing.expect(anything_changed == changes_expected);
51875187 failing_allocator.allocator.free(result_source);
51885188 break :x failing_allocator.index;
51895189 };
......@@ -5198,7 +5198,7 @@ fn testTransform(source: []const u8, expected_source: []const u8) !void {
51985198 } else |err| switch (err) {
51995199 error.OutOfMemory => {
52005200 if (failing_allocator.allocated_bytes != failing_allocator.freed_bytes) {
5201 warn(
5201 print(
52025202 "\nfail_index: {d}/{d}\nallocated bytes: {d}\nfreed bytes: {d}\nallocations: {d}\ndeallocations: {d}\n",
52035203 .{
52045204 fail_index,
......@@ -5212,8 +5212,7 @@ fn testTransform(source: []const u8, expected_source: []const u8) !void {
52125212 return error.MemoryLeakDetected;
52135213 }
52145214 },
5215 error.ParseError => @panic("test failed"),
5216 else => @panic("test failed"),
5215 else => return err,
52175216 }
52185217 }
52195218}
......@@ -5227,8 +5226,8 @@ fn testError(source: []const u8, expected_errors: []const Error) !void {
52275226 var tree = try std.zig.parse(std.testing.allocator, source);
52285227 defer tree.deinit(std.testing.allocator);
52295228
5230 std.testing.expectEqual(expected_errors.len, tree.errors.len);
5229 try std.testing.expectEqual(expected_errors.len, tree.errors.len);
52315230 for (expected_errors) |expected, i| {
5232 std.testing.expectEqual(expected, tree.errors[i].tag);
5231 try std.testing.expectEqual(expected, tree.errors[i].tag);
52335232 }
52345233}
lib/std/zig/string_literal.zig+3-3
......@@ -153,7 +153,7 @@ test "parse" {
153153 var fixed_buf_alloc = std.heap.FixedBufferAllocator.init(fixed_buf_mem[0..]);
154154 var alloc = &fixed_buf_alloc.allocator;
155155
156 expect(eql(u8, "foo", try parseAlloc(alloc, "\"foo\"")));
157 expect(eql(u8, "foo", try parseAlloc(alloc, "\"f\x6f\x6f\"")));
158 expect(eql(u8, "f💯", try parseAlloc(alloc, "\"f\u{1f4af}\"")));
156 try expect(eql(u8, "foo", try parseAlloc(alloc, "\"foo\"")));
157 try expect(eql(u8, "foo", try parseAlloc(alloc, "\"f\x6f\x6f\"")));
158 try expect(eql(u8, "f💯", try parseAlloc(alloc, "\"f\u{1f4af}\"")));
159159}
lib/std/zig/system/linux.zig+2-2
......@@ -414,8 +414,8 @@ fn testParser(
414414) !void {
415415 var fbs = io.fixedBufferStream(input);
416416 const result = try parser.parse(arch, fbs.reader());
417 testing.expectEqual(expected_model, result.?.model);
418 testing.expect(expected_model.features.eql(result.?.features));
417 try testing.expectEqual(expected_model, result.?.model);
418 try testing.expect(expected_model.features.eql(result.?.features));
419419}
420420
421421// The generic implementation of a /proc/cpuinfo parser.
lib/std/zig/system/macos.zig+1-1
......@@ -402,7 +402,7 @@ fn testVersionEquality(expected: std.builtin.Version, got: std.builtin.Version)
402402 var b_got: [64]u8 = undefined;
403403 const s_got: []const u8 = try std.fmt.bufPrint(b_got[0..], "{}", .{got});
404404
405 testing.expectEqualStrings(s_expected, s_got);
405 try testing.expectEqualStrings(s_expected, s_got);
406406}
407407
408408/// Detect SDK path on Darwin.
lib/std/zig/tokenizer.zig+294-294
......@@ -1503,11 +1503,11 @@ pub const Tokenizer = struct {
15031503};
15041504
15051505test "tokenizer" {
1506 testTokenize("test", &.{.keyword_test});
1506 try testTokenize("test", &.{.keyword_test});
15071507}
15081508
15091509test "line comment followed by top-level comptime" {
1510 testTokenize(
1510 try testTokenize(
15111511 \\// line comment
15121512 \\comptime {}
15131513 \\
......@@ -1519,7 +1519,7 @@ test "line comment followed by top-level comptime" {
15191519}
15201520
15211521test "tokenizer - unknown length pointer and then c pointer" {
1522 testTokenize(
1522 try testTokenize(
15231523 \\[*]u8
15241524 \\[*c]u8
15251525 , &.{
......@@ -1536,72 +1536,72 @@ test "tokenizer - unknown length pointer and then c pointer" {
15361536}
15371537
15381538test "tokenizer - code point literal with hex escape" {
1539 testTokenize(
1539 try testTokenize(
15401540 \\'\x1b'
15411541 , &.{.char_literal});
1542 testTokenize(
1542 try testTokenize(
15431543 \\'\x1'
15441544 , &.{ .invalid, .invalid });
15451545}
15461546
15471547test "tokenizer - code point literal with unicode escapes" {
15481548 // Valid unicode escapes
1549 testTokenize(
1549 try testTokenize(
15501550 \\'\u{3}'
15511551 , &.{.char_literal});
1552 testTokenize(
1552 try testTokenize(
15531553 \\'\u{01}'
15541554 , &.{.char_literal});
1555 testTokenize(
1555 try testTokenize(
15561556 \\'\u{2a}'
15571557 , &.{.char_literal});
1558 testTokenize(
1558 try testTokenize(
15591559 \\'\u{3f9}'
15601560 , &.{.char_literal});
1561 testTokenize(
1561 try testTokenize(
15621562 \\'\u{6E09aBc1523}'
15631563 , &.{.char_literal});
1564 testTokenize(
1564 try testTokenize(
15651565 \\"\u{440}"
15661566 , &.{.string_literal});
15671567
15681568 // Invalid unicode escapes
1569 testTokenize(
1569 try testTokenize(
15701570 \\'\u'
15711571 , &.{.invalid});
1572 testTokenize(
1572 try testTokenize(
15731573 \\'\u{{'
15741574 , &.{ .invalid, .invalid });
1575 testTokenize(
1575 try testTokenize(
15761576 \\'\u{}'
15771577 , &.{ .invalid, .invalid });
1578 testTokenize(
1578 try testTokenize(
15791579 \\'\u{s}'
15801580 , &.{ .invalid, .invalid });
1581 testTokenize(
1581 try testTokenize(
15821582 \\'\u{2z}'
15831583 , &.{ .invalid, .invalid });
1584 testTokenize(
1584 try testTokenize(
15851585 \\'\u{4a'
15861586 , &.{.invalid});
15871587
15881588 // Test old-style unicode literals
1589 testTokenize(
1589 try testTokenize(
15901590 \\'\u0333'
15911591 , &.{ .invalid, .invalid });
1592 testTokenize(
1592 try testTokenize(
15931593 \\'\U0333'
15941594 , &.{ .invalid, .integer_literal, .invalid });
15951595}
15961596
15971597test "tokenizer - code point literal with unicode code point" {
1598 testTokenize(
1598 try testTokenize(
15991599 \\'💩'
16001600 , &.{.char_literal});
16011601}
16021602
16031603test "tokenizer - float literal e exponent" {
1604 testTokenize("a = 4.94065645841246544177e-324;\n", &.{
1604 try testTokenize("a = 4.94065645841246544177e-324;\n", &.{
16051605 .identifier,
16061606 .equal,
16071607 .float_literal,
......@@ -1610,7 +1610,7 @@ test "tokenizer - float literal e exponent" {
16101610}
16111611
16121612test "tokenizer - float literal p exponent" {
1613 testTokenize("a = 0x1.a827999fcef32p+1022;\n", &.{
1613 try testTokenize("a = 0x1.a827999fcef32p+1022;\n", &.{
16141614 .identifier,
16151615 .equal,
16161616 .float_literal,
......@@ -1619,84 +1619,84 @@ test "tokenizer - float literal p exponent" {
16191619}
16201620
16211621test "tokenizer - chars" {
1622 testTokenize("'c'", &.{.char_literal});
1622 try testTokenize("'c'", &.{.char_literal});
16231623}
16241624
16251625test "tokenizer - invalid token characters" {
1626 testTokenize("#", &.{.invalid});
1627 testTokenize("`", &.{.invalid});
1628 testTokenize("'c", &.{.invalid});
1629 testTokenize("'", &.{.invalid});
1630 testTokenize("''", &.{ .invalid, .invalid });
1626 try testTokenize("#", &.{.invalid});
1627 try testTokenize("`", &.{.invalid});
1628 try testTokenize("'c", &.{.invalid});
1629 try testTokenize("'", &.{.invalid});
1630 try testTokenize("''", &.{ .invalid, .invalid });
16311631}
16321632
16331633test "tokenizer - invalid literal/comment characters" {
1634 testTokenize("\"\x00\"", &.{
1634 try testTokenize("\"\x00\"", &.{
16351635 .string_literal,
16361636 .invalid,
16371637 });
1638 testTokenize("//\x00", &.{
1638 try testTokenize("//\x00", &.{
16391639 .invalid,
16401640 });
1641 testTokenize("//\x1f", &.{
1641 try testTokenize("//\x1f", &.{
16421642 .invalid,
16431643 });
1644 testTokenize("//\x7f", &.{
1644 try testTokenize("//\x7f", &.{
16451645 .invalid,
16461646 });
16471647}
16481648
16491649test "tokenizer - utf8" {
1650 testTokenize("//\xc2\x80", &.{});
1651 testTokenize("//\xf4\x8f\xbf\xbf", &.{});
1650 try testTokenize("//\xc2\x80", &.{});
1651 try testTokenize("//\xf4\x8f\xbf\xbf", &.{});
16521652}
16531653
16541654test "tokenizer - invalid utf8" {
1655 testTokenize("//\x80", &.{
1655 try testTokenize("//\x80", &.{
16561656 .invalid,
16571657 });
1658 testTokenize("//\xbf", &.{
1658 try testTokenize("//\xbf", &.{
16591659 .invalid,
16601660 });
1661 testTokenize("//\xf8", &.{
1661 try testTokenize("//\xf8", &.{
16621662 .invalid,
16631663 });
1664 testTokenize("//\xff", &.{
1664 try testTokenize("//\xff", &.{
16651665 .invalid,
16661666 });
1667 testTokenize("//\xc2\xc0", &.{
1667 try testTokenize("//\xc2\xc0", &.{
16681668 .invalid,
16691669 });
1670 testTokenize("//\xe0", &.{
1670 try testTokenize("//\xe0", &.{
16711671 .invalid,
16721672 });
1673 testTokenize("//\xf0", &.{
1673 try testTokenize("//\xf0", &.{
16741674 .invalid,
16751675 });
1676 testTokenize("//\xf0\x90\x80\xc0", &.{
1676 try testTokenize("//\xf0\x90\x80\xc0", &.{
16771677 .invalid,
16781678 });
16791679}
16801680
16811681test "tokenizer - illegal unicode codepoints" {
16821682 // unicode newline characters.U+0085, U+2028, U+2029
1683 testTokenize("//\xc2\x84", &.{});
1684 testTokenize("//\xc2\x85", &.{
1683 try testTokenize("//\xc2\x84", &.{});
1684 try testTokenize("//\xc2\x85", &.{
16851685 .invalid,
16861686 });
1687 testTokenize("//\xc2\x86", &.{});
1688 testTokenize("//\xe2\x80\xa7", &.{});
1689 testTokenize("//\xe2\x80\xa8", &.{
1687 try testTokenize("//\xc2\x86", &.{});
1688 try testTokenize("//\xe2\x80\xa7", &.{});
1689 try testTokenize("//\xe2\x80\xa8", &.{
16901690 .invalid,
16911691 });
1692 testTokenize("//\xe2\x80\xa9", &.{
1692 try testTokenize("//\xe2\x80\xa9", &.{
16931693 .invalid,
16941694 });
1695 testTokenize("//\xe2\x80\xaa", &.{});
1695 try testTokenize("//\xe2\x80\xaa", &.{});
16961696}
16971697
16981698test "tokenizer - string identifier and builtin fns" {
1699 testTokenize(
1699 try testTokenize(
17001700 \\const @"if" = @import("std");
17011701 , &.{
17021702 .keyword_const,
......@@ -1711,7 +1711,7 @@ test "tokenizer - string identifier and builtin fns" {
17111711}
17121712
17131713test "tokenizer - multiline string literal with literal tab" {
1714 testTokenize(
1714 try testTokenize(
17151715 \\\\foo bar
17161716 , &.{
17171717 .multiline_string_literal_line,
......@@ -1719,7 +1719,7 @@ test "tokenizer - multiline string literal with literal tab" {
17191719}
17201720
17211721test "tokenizer - comments with literal tab" {
1722 testTokenize(
1722 try testTokenize(
17231723 \\//foo bar
17241724 \\//!foo bar
17251725 \\///foo bar
......@@ -1735,25 +1735,25 @@ test "tokenizer - comments with literal tab" {
17351735}
17361736
17371737test "tokenizer - pipe and then invalid" {
1738 testTokenize("||=", &.{
1738 try testTokenize("||=", &.{
17391739 .pipe_pipe,
17401740 .equal,
17411741 });
17421742}
17431743
17441744test "tokenizer - line comment and doc comment" {
1745 testTokenize("//", &.{});
1746 testTokenize("// a / b", &.{});
1747 testTokenize("// /", &.{});
1748 testTokenize("/// a", &.{.doc_comment});
1749 testTokenize("///", &.{.doc_comment});
1750 testTokenize("////", &.{});
1751 testTokenize("//!", &.{.container_doc_comment});
1752 testTokenize("//!!", &.{.container_doc_comment});
1745 try testTokenize("//", &.{});
1746 try testTokenize("// a / b", &.{});
1747 try testTokenize("// /", &.{});
1748 try testTokenize("/// a", &.{.doc_comment});
1749 try testTokenize("///", &.{.doc_comment});
1750 try testTokenize("////", &.{});
1751 try testTokenize("//!", &.{.container_doc_comment});
1752 try testTokenize("//!!", &.{.container_doc_comment});
17531753}
17541754
17551755test "tokenizer - line comment followed by identifier" {
1756 testTokenize(
1756 try testTokenize(
17571757 \\ Unexpected,
17581758 \\ // another
17591759 \\ Another,
......@@ -1766,14 +1766,14 @@ test "tokenizer - line comment followed by identifier" {
17661766}
17671767
17681768test "tokenizer - UTF-8 BOM is recognized and skipped" {
1769 testTokenize("\xEF\xBB\xBFa;\n", &.{
1769 try testTokenize("\xEF\xBB\xBFa;\n", &.{
17701770 .identifier,
17711771 .semicolon,
17721772 });
17731773}
17741774
17751775test "correctly parse pointer assignment" {
1776 testTokenize("b.*=3;\n", &.{
1776 try testTokenize("b.*=3;\n", &.{
17771777 .identifier,
17781778 .period_asterisk,
17791779 .equal,
......@@ -1783,14 +1783,14 @@ test "correctly parse pointer assignment" {
17831783}
17841784
17851785test "correctly parse pointer dereference followed by asterisk" {
1786 testTokenize("\"b\".* ** 10", &.{
1786 try testTokenize("\"b\".* ** 10", &.{
17871787 .string_literal,
17881788 .period_asterisk,
17891789 .asterisk_asterisk,
17901790 .integer_literal,
17911791 });
17921792
1793 testTokenize("(\"b\".*)** 10", &.{
1793 try testTokenize("(\"b\".*)** 10", &.{
17941794 .l_paren,
17951795 .string_literal,
17961796 .period_asterisk,
......@@ -1799,7 +1799,7 @@ test "correctly parse pointer dereference followed by asterisk" {
17991799 .integer_literal,
18001800 });
18011801
1802 testTokenize("\"b\".*** 10", &.{
1802 try testTokenize("\"b\".*** 10", &.{
18031803 .string_literal,
18041804 .invalid_periodasterisks,
18051805 .asterisk_asterisk,
......@@ -1808,245 +1808,245 @@ test "correctly parse pointer dereference followed by asterisk" {
18081808}
18091809
18101810test "tokenizer - range literals" {
1811 testTokenize("0...9", &.{ .integer_literal, .ellipsis3, .integer_literal });
1812 testTokenize("'0'...'9'", &.{ .char_literal, .ellipsis3, .char_literal });
1813 testTokenize("0x00...0x09", &.{ .integer_literal, .ellipsis3, .integer_literal });
1814 testTokenize("0b00...0b11", &.{ .integer_literal, .ellipsis3, .integer_literal });
1815 testTokenize("0o00...0o11", &.{ .integer_literal, .ellipsis3, .integer_literal });
1811 try testTokenize("0...9", &.{ .integer_literal, .ellipsis3, .integer_literal });
1812 try testTokenize("'0'...'9'", &.{ .char_literal, .ellipsis3, .char_literal });
1813 try testTokenize("0x00...0x09", &.{ .integer_literal, .ellipsis3, .integer_literal });
1814 try testTokenize("0b00...0b11", &.{ .integer_literal, .ellipsis3, .integer_literal });
1815 try testTokenize("0o00...0o11", &.{ .integer_literal, .ellipsis3, .integer_literal });
18161816}
18171817
18181818test "tokenizer - number literals decimal" {
1819 testTokenize("0", &.{.integer_literal});
1820 testTokenize("1", &.{.integer_literal});
1821 testTokenize("2", &.{.integer_literal});
1822 testTokenize("3", &.{.integer_literal});
1823 testTokenize("4", &.{.integer_literal});
1824 testTokenize("5", &.{.integer_literal});
1825 testTokenize("6", &.{.integer_literal});
1826 testTokenize("7", &.{.integer_literal});
1827 testTokenize("8", &.{.integer_literal});
1828 testTokenize("9", &.{.integer_literal});
1829 testTokenize("1..", &.{ .integer_literal, .ellipsis2 });
1830 testTokenize("0a", &.{ .invalid, .identifier });
1831 testTokenize("9b", &.{ .invalid, .identifier });
1832 testTokenize("1z", &.{ .invalid, .identifier });
1833 testTokenize("1z_1", &.{ .invalid, .identifier });
1834 testTokenize("9z3", &.{ .invalid, .identifier });
1835
1836 testTokenize("0_0", &.{.integer_literal});
1837 testTokenize("0001", &.{.integer_literal});
1838 testTokenize("01234567890", &.{.integer_literal});
1839 testTokenize("012_345_6789_0", &.{.integer_literal});
1840 testTokenize("0_1_2_3_4_5_6_7_8_9_0", &.{.integer_literal});
1841
1842 testTokenize("00_", &.{.invalid});
1843 testTokenize("0_0_", &.{.invalid});
1844 testTokenize("0__0", &.{ .invalid, .identifier });
1845 testTokenize("0_0f", &.{ .invalid, .identifier });
1846 testTokenize("0_0_f", &.{ .invalid, .identifier });
1847 testTokenize("0_0_f_00", &.{ .invalid, .identifier });
1848 testTokenize("1_,", &.{ .invalid, .comma });
1849
1850 testTokenize("1.", &.{.float_literal});
1851 testTokenize("0.0", &.{.float_literal});
1852 testTokenize("1.0", &.{.float_literal});
1853 testTokenize("10.0", &.{.float_literal});
1854 testTokenize("0e0", &.{.float_literal});
1855 testTokenize("1e0", &.{.float_literal});
1856 testTokenize("1e100", &.{.float_literal});
1857 testTokenize("1.e100", &.{.float_literal});
1858 testTokenize("1.0e100", &.{.float_literal});
1859 testTokenize("1.0e+100", &.{.float_literal});
1860 testTokenize("1.0e-100", &.{.float_literal});
1861 testTokenize("1_0_0_0.0_0_0_0_0_1e1_0_0_0", &.{.float_literal});
1862 testTokenize("1.+", &.{ .float_literal, .plus });
1863
1864 testTokenize("1e", &.{.invalid});
1865 testTokenize("1.0e1f0", &.{ .invalid, .identifier });
1866 testTokenize("1.0p100", &.{ .invalid, .identifier });
1867 testTokenize("1.0p-100", &.{ .invalid, .identifier, .minus, .integer_literal });
1868 testTokenize("1.0p1f0", &.{ .invalid, .identifier });
1869 testTokenize("1.0_,", &.{ .invalid, .comma });
1870 testTokenize("1_.0", &.{ .invalid, .period, .integer_literal });
1871 testTokenize("1._", &.{ .invalid, .identifier });
1872 testTokenize("1.a", &.{ .invalid, .identifier });
1873 testTokenize("1.z", &.{ .invalid, .identifier });
1874 testTokenize("1._0", &.{ .invalid, .identifier });
1875 testTokenize("1._+", &.{ .invalid, .identifier, .plus });
1876 testTokenize("1._e", &.{ .invalid, .identifier });
1877 testTokenize("1.0e", &.{.invalid});
1878 testTokenize("1.0e,", &.{ .invalid, .comma });
1879 testTokenize("1.0e_", &.{ .invalid, .identifier });
1880 testTokenize("1.0e+_", &.{ .invalid, .identifier });
1881 testTokenize("1.0e-_", &.{ .invalid, .identifier });
1882 testTokenize("1.0e0_+", &.{ .invalid, .plus });
1819 try testTokenize("0", &.{.integer_literal});
1820 try testTokenize("1", &.{.integer_literal});
1821 try testTokenize("2", &.{.integer_literal});
1822 try testTokenize("3", &.{.integer_literal});
1823 try testTokenize("4", &.{.integer_literal});
1824 try testTokenize("5", &.{.integer_literal});
1825 try testTokenize("6", &.{.integer_literal});
1826 try testTokenize("7", &.{.integer_literal});
1827 try testTokenize("8", &.{.integer_literal});
1828 try testTokenize("9", &.{.integer_literal});
1829 try testTokenize("1..", &.{ .integer_literal, .ellipsis2 });
1830 try testTokenize("0a", &.{ .invalid, .identifier });
1831 try testTokenize("9b", &.{ .invalid, .identifier });
1832 try testTokenize("1z", &.{ .invalid, .identifier });
1833 try testTokenize("1z_1", &.{ .invalid, .identifier });
1834 try testTokenize("9z3", &.{ .invalid, .identifier });
1835
1836 try testTokenize("0_0", &.{.integer_literal});
1837 try testTokenize("0001", &.{.integer_literal});
1838 try testTokenize("01234567890", &.{.integer_literal});
1839 try testTokenize("012_345_6789_0", &.{.integer_literal});
1840 try testTokenize("0_1_2_3_4_5_6_7_8_9_0", &.{.integer_literal});
1841
1842 try testTokenize("00_", &.{.invalid});
1843 try testTokenize("0_0_", &.{.invalid});
1844 try testTokenize("0__0", &.{ .invalid, .identifier });
1845 try testTokenize("0_0f", &.{ .invalid, .identifier });
1846 try testTokenize("0_0_f", &.{ .invalid, .identifier });
1847 try testTokenize("0_0_f_00", &.{ .invalid, .identifier });
1848 try testTokenize("1_,", &.{ .invalid, .comma });
1849
1850 try testTokenize("1.", &.{.float_literal});
1851 try testTokenize("0.0", &.{.float_literal});
1852 try testTokenize("1.0", &.{.float_literal});
1853 try testTokenize("10.0", &.{.float_literal});
1854 try testTokenize("0e0", &.{.float_literal});
1855 try testTokenize("1e0", &.{.float_literal});
1856 try testTokenize("1e100", &.{.float_literal});
1857 try testTokenize("1.e100", &.{.float_literal});
1858 try testTokenize("1.0e100", &.{.float_literal});
1859 try testTokenize("1.0e+100", &.{.float_literal});
1860 try testTokenize("1.0e-100", &.{.float_literal});
1861 try testTokenize("1_0_0_0.0_0_0_0_0_1e1_0_0_0", &.{.float_literal});
1862 try testTokenize("1.+", &.{ .float_literal, .plus });
1863
1864 try testTokenize("1e", &.{.invalid});
1865 try testTokenize("1.0e1f0", &.{ .invalid, .identifier });
1866 try testTokenize("1.0p100", &.{ .invalid, .identifier });
1867 try testTokenize("1.0p-100", &.{ .invalid, .identifier, .minus, .integer_literal });
1868 try testTokenize("1.0p1f0", &.{ .invalid, .identifier });
1869 try testTokenize("1.0_,", &.{ .invalid, .comma });
1870 try testTokenize("1_.0", &.{ .invalid, .period, .integer_literal });
1871 try testTokenize("1._", &.{ .invalid, .identifier });
1872 try testTokenize("1.a", &.{ .invalid, .identifier });
1873 try testTokenize("1.z", &.{ .invalid, .identifier });
1874 try testTokenize("1._0", &.{ .invalid, .identifier });
1875 try testTokenize("1._+", &.{ .invalid, .identifier, .plus });
1876 try testTokenize("1._e", &.{ .invalid, .identifier });
1877 try testTokenize("1.0e", &.{.invalid});
1878 try testTokenize("1.0e,", &.{ .invalid, .comma });
1879 try testTokenize("1.0e_", &.{ .invalid, .identifier });
1880 try testTokenize("1.0e+_", &.{ .invalid, .identifier });
1881 try testTokenize("1.0e-_", &.{ .invalid, .identifier });
1882 try testTokenize("1.0e0_+", &.{ .invalid, .plus });
18831883}
18841884
18851885test "tokenizer - number literals binary" {
1886 testTokenize("0b0", &.{.integer_literal});
1887 testTokenize("0b1", &.{.integer_literal});
1888 testTokenize("0b2", &.{ .invalid, .integer_literal });
1889 testTokenize("0b3", &.{ .invalid, .integer_literal });
1890 testTokenize("0b4", &.{ .invalid, .integer_literal });
1891 testTokenize("0b5", &.{ .invalid, .integer_literal });
1892 testTokenize("0b6", &.{ .invalid, .integer_literal });
1893 testTokenize("0b7", &.{ .invalid, .integer_literal });
1894 testTokenize("0b8", &.{ .invalid, .integer_literal });
1895 testTokenize("0b9", &.{ .invalid, .integer_literal });
1896 testTokenize("0ba", &.{ .invalid, .identifier });
1897 testTokenize("0bb", &.{ .invalid, .identifier });
1898 testTokenize("0bc", &.{ .invalid, .identifier });
1899 testTokenize("0bd", &.{ .invalid, .identifier });
1900 testTokenize("0be", &.{ .invalid, .identifier });
1901 testTokenize("0bf", &.{ .invalid, .identifier });
1902 testTokenize("0bz", &.{ .invalid, .identifier });
1903
1904 testTokenize("0b0000_0000", &.{.integer_literal});
1905 testTokenize("0b1111_1111", &.{.integer_literal});
1906 testTokenize("0b10_10_10_10", &.{.integer_literal});
1907 testTokenize("0b0_1_0_1_0_1_0_1", &.{.integer_literal});
1908 testTokenize("0b1.", &.{ .integer_literal, .period });
1909 testTokenize("0b1.0", &.{ .integer_literal, .period, .integer_literal });
1910
1911 testTokenize("0B0", &.{ .invalid, .identifier });
1912 testTokenize("0b_", &.{ .invalid, .identifier });
1913 testTokenize("0b_0", &.{ .invalid, .identifier });
1914 testTokenize("0b1_", &.{.invalid});
1915 testTokenize("0b0__1", &.{ .invalid, .identifier });
1916 testTokenize("0b0_1_", &.{.invalid});
1917 testTokenize("0b1e", &.{ .invalid, .identifier });
1918 testTokenize("0b1p", &.{ .invalid, .identifier });
1919 testTokenize("0b1e0", &.{ .invalid, .identifier });
1920 testTokenize("0b1p0", &.{ .invalid, .identifier });
1921 testTokenize("0b1_,", &.{ .invalid, .comma });
1886 try testTokenize("0b0", &.{.integer_literal});
1887 try testTokenize("0b1", &.{.integer_literal});
1888 try testTokenize("0b2", &.{ .invalid, .integer_literal });
1889 try testTokenize("0b3", &.{ .invalid, .integer_literal });
1890 try testTokenize("0b4", &.{ .invalid, .integer_literal });
1891 try testTokenize("0b5", &.{ .invalid, .integer_literal });
1892 try testTokenize("0b6", &.{ .invalid, .integer_literal });
1893 try testTokenize("0b7", &.{ .invalid, .integer_literal });
1894 try testTokenize("0b8", &.{ .invalid, .integer_literal });
1895 try testTokenize("0b9", &.{ .invalid, .integer_literal });
1896 try testTokenize("0ba", &.{ .invalid, .identifier });
1897 try testTokenize("0bb", &.{ .invalid, .identifier });
1898 try testTokenize("0bc", &.{ .invalid, .identifier });
1899 try testTokenize("0bd", &.{ .invalid, .identifier });
1900 try testTokenize("0be", &.{ .invalid, .identifier });
1901 try testTokenize("0bf", &.{ .invalid, .identifier });
1902 try testTokenize("0bz", &.{ .invalid, .identifier });
1903
1904 try testTokenize("0b0000_0000", &.{.integer_literal});
1905 try testTokenize("0b1111_1111", &.{.integer_literal});
1906 try testTokenize("0b10_10_10_10", &.{.integer_literal});
1907 try testTokenize("0b0_1_0_1_0_1_0_1", &.{.integer_literal});
1908 try testTokenize("0b1.", &.{ .integer_literal, .period });
1909 try testTokenize("0b1.0", &.{ .integer_literal, .period, .integer_literal });
1910
1911 try testTokenize("0B0", &.{ .invalid, .identifier });
1912 try testTokenize("0b_", &.{ .invalid, .identifier });
1913 try testTokenize("0b_0", &.{ .invalid, .identifier });
1914 try testTokenize("0b1_", &.{.invalid});
1915 try testTokenize("0b0__1", &.{ .invalid, .identifier });
1916 try testTokenize("0b0_1_", &.{.invalid});
1917 try testTokenize("0b1e", &.{ .invalid, .identifier });
1918 try testTokenize("0b1p", &.{ .invalid, .identifier });
1919 try testTokenize("0b1e0", &.{ .invalid, .identifier });
1920 try testTokenize("0b1p0", &.{ .invalid, .identifier });
1921 try testTokenize("0b1_,", &.{ .invalid, .comma });
19221922}
19231923
19241924test "tokenizer - number literals octal" {
1925 testTokenize("0o0", &.{.integer_literal});
1926 testTokenize("0o1", &.{.integer_literal});
1927 testTokenize("0o2", &.{.integer_literal});
1928 testTokenize("0o3", &.{.integer_literal});
1929 testTokenize("0o4", &.{.integer_literal});
1930 testTokenize("0o5", &.{.integer_literal});
1931 testTokenize("0o6", &.{.integer_literal});
1932 testTokenize("0o7", &.{.integer_literal});
1933 testTokenize("0o8", &.{ .invalid, .integer_literal });
1934 testTokenize("0o9", &.{ .invalid, .integer_literal });
1935 testTokenize("0oa", &.{ .invalid, .identifier });
1936 testTokenize("0ob", &.{ .invalid, .identifier });
1937 testTokenize("0oc", &.{ .invalid, .identifier });
1938 testTokenize("0od", &.{ .invalid, .identifier });
1939 testTokenize("0oe", &.{ .invalid, .identifier });
1940 testTokenize("0of", &.{ .invalid, .identifier });
1941 testTokenize("0oz", &.{ .invalid, .identifier });
1942
1943 testTokenize("0o01234567", &.{.integer_literal});
1944 testTokenize("0o0123_4567", &.{.integer_literal});
1945 testTokenize("0o01_23_45_67", &.{.integer_literal});
1946 testTokenize("0o0_1_2_3_4_5_6_7", &.{.integer_literal});
1947 testTokenize("0o7.", &.{ .integer_literal, .period });
1948 testTokenize("0o7.0", &.{ .integer_literal, .period, .integer_literal });
1949
1950 testTokenize("0O0", &.{ .invalid, .identifier });
1951 testTokenize("0o_", &.{ .invalid, .identifier });
1952 testTokenize("0o_0", &.{ .invalid, .identifier });
1953 testTokenize("0o1_", &.{.invalid});
1954 testTokenize("0o0__1", &.{ .invalid, .identifier });
1955 testTokenize("0o0_1_", &.{.invalid});
1956 testTokenize("0o1e", &.{ .invalid, .identifier });
1957 testTokenize("0o1p", &.{ .invalid, .identifier });
1958 testTokenize("0o1e0", &.{ .invalid, .identifier });
1959 testTokenize("0o1p0", &.{ .invalid, .identifier });
1960 testTokenize("0o_,", &.{ .invalid, .identifier, .comma });
1925 try testTokenize("0o0", &.{.integer_literal});
1926 try testTokenize("0o1", &.{.integer_literal});
1927 try testTokenize("0o2", &.{.integer_literal});
1928 try testTokenize("0o3", &.{.integer_literal});
1929 try testTokenize("0o4", &.{.integer_literal});
1930 try testTokenize("0o5", &.{.integer_literal});
1931 try testTokenize("0o6", &.{.integer_literal});
1932 try testTokenize("0o7", &.{.integer_literal});
1933 try testTokenize("0o8", &.{ .invalid, .integer_literal });
1934 try testTokenize("0o9", &.{ .invalid, .integer_literal });
1935 try testTokenize("0oa", &.{ .invalid, .identifier });
1936 try testTokenize("0ob", &.{ .invalid, .identifier });
1937 try testTokenize("0oc", &.{ .invalid, .identifier });
1938 try testTokenize("0od", &.{ .invalid, .identifier });
1939 try testTokenize("0oe", &.{ .invalid, .identifier });
1940 try testTokenize("0of", &.{ .invalid, .identifier });
1941 try testTokenize("0oz", &.{ .invalid, .identifier });
1942
1943 try testTokenize("0o01234567", &.{.integer_literal});
1944 try testTokenize("0o0123_4567", &.{.integer_literal});
1945 try testTokenize("0o01_23_45_67", &.{.integer_literal});
1946 try testTokenize("0o0_1_2_3_4_5_6_7", &.{.integer_literal});
1947 try testTokenize("0o7.", &.{ .integer_literal, .period });
1948 try testTokenize("0o7.0", &.{ .integer_literal, .period, .integer_literal });
1949
1950 try testTokenize("0O0", &.{ .invalid, .identifier });
1951 try testTokenize("0o_", &.{ .invalid, .identifier });
1952 try testTokenize("0o_0", &.{ .invalid, .identifier });
1953 try testTokenize("0o1_", &.{.invalid});
1954 try testTokenize("0o0__1", &.{ .invalid, .identifier });
1955 try testTokenize("0o0_1_", &.{.invalid});
1956 try testTokenize("0o1e", &.{ .invalid, .identifier });
1957 try testTokenize("0o1p", &.{ .invalid, .identifier });
1958 try testTokenize("0o1e0", &.{ .invalid, .identifier });
1959 try testTokenize("0o1p0", &.{ .invalid, .identifier });
1960 try testTokenize("0o_,", &.{ .invalid, .identifier, .comma });
19611961}
19621962
19631963test "tokenizer - number literals hexadeciaml" {
1964 testTokenize("0x0", &.{.integer_literal});
1965 testTokenize("0x1", &.{.integer_literal});
1966 testTokenize("0x2", &.{.integer_literal});
1967 testTokenize("0x3", &.{.integer_literal});
1968 testTokenize("0x4", &.{.integer_literal});
1969 testTokenize("0x5", &.{.integer_literal});
1970 testTokenize("0x6", &.{.integer_literal});
1971 testTokenize("0x7", &.{.integer_literal});
1972 testTokenize("0x8", &.{.integer_literal});
1973 testTokenize("0x9", &.{.integer_literal});
1974 testTokenize("0xa", &.{.integer_literal});
1975 testTokenize("0xb", &.{.integer_literal});
1976 testTokenize("0xc", &.{.integer_literal});
1977 testTokenize("0xd", &.{.integer_literal});
1978 testTokenize("0xe", &.{.integer_literal});
1979 testTokenize("0xf", &.{.integer_literal});
1980 testTokenize("0xA", &.{.integer_literal});
1981 testTokenize("0xB", &.{.integer_literal});
1982 testTokenize("0xC", &.{.integer_literal});
1983 testTokenize("0xD", &.{.integer_literal});
1984 testTokenize("0xE", &.{.integer_literal});
1985 testTokenize("0xF", &.{.integer_literal});
1986 testTokenize("0x0z", &.{ .invalid, .identifier });
1987 testTokenize("0xz", &.{ .invalid, .identifier });
1988
1989 testTokenize("0x0123456789ABCDEF", &.{.integer_literal});
1990 testTokenize("0x0123_4567_89AB_CDEF", &.{.integer_literal});
1991 testTokenize("0x01_23_45_67_89AB_CDE_F", &.{.integer_literal});
1992 testTokenize("0x0_1_2_3_4_5_6_7_8_9_A_B_C_D_E_F", &.{.integer_literal});
1993
1994 testTokenize("0X0", &.{ .invalid, .identifier });
1995 testTokenize("0x_", &.{ .invalid, .identifier });
1996 testTokenize("0x_1", &.{ .invalid, .identifier });
1997 testTokenize("0x1_", &.{.invalid});
1998 testTokenize("0x0__1", &.{ .invalid, .identifier });
1999 testTokenize("0x0_1_", &.{.invalid});
2000 testTokenize("0x_,", &.{ .invalid, .identifier, .comma });
2001
2002 testTokenize("0x1.", &.{.float_literal});
2003 testTokenize("0x1.0", &.{.float_literal});
2004 testTokenize("0xF.", &.{.float_literal});
2005 testTokenize("0xF.0", &.{.float_literal});
2006 testTokenize("0xF.F", &.{.float_literal});
2007 testTokenize("0xF.Fp0", &.{.float_literal});
2008 testTokenize("0xF.FP0", &.{.float_literal});
2009 testTokenize("0x1p0", &.{.float_literal});
2010 testTokenize("0xfp0", &.{.float_literal});
2011 testTokenize("0x1.+0xF.", &.{ .float_literal, .plus, .float_literal });
2012
2013 testTokenize("0x0123456.789ABCDEF", &.{.float_literal});
2014 testTokenize("0x0_123_456.789_ABC_DEF", &.{.float_literal});
2015 testTokenize("0x0_1_2_3_4_5_6.7_8_9_A_B_C_D_E_F", &.{.float_literal});
2016 testTokenize("0x0p0", &.{.float_literal});
2017 testTokenize("0x0.0p0", &.{.float_literal});
2018 testTokenize("0xff.ffp10", &.{.float_literal});
2019 testTokenize("0xff.ffP10", &.{.float_literal});
2020 testTokenize("0xff.p10", &.{.float_literal});
2021 testTokenize("0xffp10", &.{.float_literal});
2022 testTokenize("0xff_ff.ff_ffp1_0_0_0", &.{.float_literal});
2023 testTokenize("0xf_f_f_f.f_f_f_fp+1_000", &.{.float_literal});
2024 testTokenize("0xf_f_f_f.f_f_f_fp-1_00_0", &.{.float_literal});
2025
2026 testTokenize("0x1e", &.{.integer_literal});
2027 testTokenize("0x1e0", &.{.integer_literal});
2028 testTokenize("0x1p", &.{.invalid});
2029 testTokenize("0xfp0z1", &.{ .invalid, .identifier });
2030 testTokenize("0xff.ffpff", &.{ .invalid, .identifier });
2031 testTokenize("0x0.p", &.{.invalid});
2032 testTokenize("0x0.z", &.{ .invalid, .identifier });
2033 testTokenize("0x0._", &.{ .invalid, .identifier });
2034 testTokenize("0x0_.0", &.{ .invalid, .period, .integer_literal });
2035 testTokenize("0x0_.0.0", &.{ .invalid, .period, .float_literal });
2036 testTokenize("0x0._0", &.{ .invalid, .identifier });
2037 testTokenize("0x0.0_", &.{.invalid});
2038 testTokenize("0x0_p0", &.{ .invalid, .identifier });
2039 testTokenize("0x0_.p0", &.{ .invalid, .period, .identifier });
2040 testTokenize("0x0._p0", &.{ .invalid, .identifier });
2041 testTokenize("0x0.0_p0", &.{ .invalid, .identifier });
2042 testTokenize("0x0._0p0", &.{ .invalid, .identifier });
2043 testTokenize("0x0.0p_0", &.{ .invalid, .identifier });
2044 testTokenize("0x0.0p+_0", &.{ .invalid, .identifier });
2045 testTokenize("0x0.0p-_0", &.{ .invalid, .identifier });
2046 testTokenize("0x0.0p0_", &.{ .invalid, .eof });
1964 try testTokenize("0x0", &.{.integer_literal});
1965 try testTokenize("0x1", &.{.integer_literal});
1966 try testTokenize("0x2", &.{.integer_literal});
1967 try testTokenize("0x3", &.{.integer_literal});
1968 try testTokenize("0x4", &.{.integer_literal});
1969 try testTokenize("0x5", &.{.integer_literal});
1970 try testTokenize("0x6", &.{.integer_literal});
1971 try testTokenize("0x7", &.{.integer_literal});
1972 try testTokenize("0x8", &.{.integer_literal});
1973 try testTokenize("0x9", &.{.integer_literal});
1974 try testTokenize("0xa", &.{.integer_literal});
1975 try testTokenize("0xb", &.{.integer_literal});
1976 try testTokenize("0xc", &.{.integer_literal});
1977 try testTokenize("0xd", &.{.integer_literal});
1978 try testTokenize("0xe", &.{.integer_literal});
1979 try testTokenize("0xf", &.{.integer_literal});
1980 try testTokenize("0xA", &.{.integer_literal});
1981 try testTokenize("0xB", &.{.integer_literal});
1982 try testTokenize("0xC", &.{.integer_literal});
1983 try testTokenize("0xD", &.{.integer_literal});
1984 try testTokenize("0xE", &.{.integer_literal});
1985 try testTokenize("0xF", &.{.integer_literal});
1986 try testTokenize("0x0z", &.{ .invalid, .identifier });
1987 try testTokenize("0xz", &.{ .invalid, .identifier });
1988
1989 try testTokenize("0x0123456789ABCDEF", &.{.integer_literal});
1990 try testTokenize("0x0123_4567_89AB_CDEF", &.{.integer_literal});
1991 try testTokenize("0x01_23_45_67_89AB_CDE_F", &.{.integer_literal});
1992 try testTokenize("0x0_1_2_3_4_5_6_7_8_9_A_B_C_D_E_F", &.{.integer_literal});
1993
1994 try testTokenize("0X0", &.{ .invalid, .identifier });
1995 try testTokenize("0x_", &.{ .invalid, .identifier });
1996 try testTokenize("0x_1", &.{ .invalid, .identifier });
1997 try testTokenize("0x1_", &.{.invalid});
1998 try testTokenize("0x0__1", &.{ .invalid, .identifier });
1999 try testTokenize("0x0_1_", &.{.invalid});
2000 try testTokenize("0x_,", &.{ .invalid, .identifier, .comma });
2001
2002 try testTokenize("0x1.", &.{.float_literal});
2003 try testTokenize("0x1.0", &.{.float_literal});
2004 try testTokenize("0xF.", &.{.float_literal});
2005 try testTokenize("0xF.0", &.{.float_literal});
2006 try testTokenize("0xF.F", &.{.float_literal});
2007 try testTokenize("0xF.Fp0", &.{.float_literal});
2008 try testTokenize("0xF.FP0", &.{.float_literal});
2009 try testTokenize("0x1p0", &.{.float_literal});
2010 try testTokenize("0xfp0", &.{.float_literal});
2011 try testTokenize("0x1.+0xF.", &.{ .float_literal, .plus, .float_literal });
2012
2013 try testTokenize("0x0123456.789ABCDEF", &.{.float_literal});
2014 try testTokenize("0x0_123_456.789_ABC_DEF", &.{.float_literal});
2015 try testTokenize("0x0_1_2_3_4_5_6.7_8_9_A_B_C_D_E_F", &.{.float_literal});
2016 try testTokenize("0x0p0", &.{.float_literal});
2017 try testTokenize("0x0.0p0", &.{.float_literal});
2018 try testTokenize("0xff.ffp10", &.{.float_literal});
2019 try testTokenize("0xff.ffP10", &.{.float_literal});
2020 try testTokenize("0xff.p10", &.{.float_literal});
2021 try testTokenize("0xffp10", &.{.float_literal});
2022 try testTokenize("0xff_ff.ff_ffp1_0_0_0", &.{.float_literal});
2023 try testTokenize("0xf_f_f_f.f_f_f_fp+1_000", &.{.float_literal});
2024 try testTokenize("0xf_f_f_f.f_f_f_fp-1_00_0", &.{.float_literal});
2025
2026 try testTokenize("0x1e", &.{.integer_literal});
2027 try testTokenize("0x1e0", &.{.integer_literal});
2028 try testTokenize("0x1p", &.{.invalid});
2029 try testTokenize("0xfp0z1", &.{ .invalid, .identifier });
2030 try testTokenize("0xff.ffpff", &.{ .invalid, .identifier });
2031 try testTokenize("0x0.p", &.{.invalid});
2032 try testTokenize("0x0.z", &.{ .invalid, .identifier });
2033 try testTokenize("0x0._", &.{ .invalid, .identifier });
2034 try testTokenize("0x0_.0", &.{ .invalid, .period, .integer_literal });
2035 try testTokenize("0x0_.0.0", &.{ .invalid, .period, .float_literal });
2036 try testTokenize("0x0._0", &.{ .invalid, .identifier });
2037 try testTokenize("0x0.0_", &.{.invalid});
2038 try testTokenize("0x0_p0", &.{ .invalid, .identifier });
2039 try testTokenize("0x0_.p0", &.{ .invalid, .period, .identifier });
2040 try testTokenize("0x0._p0", &.{ .invalid, .identifier });
2041 try testTokenize("0x0.0_p0", &.{ .invalid, .identifier });
2042 try testTokenize("0x0._0p0", &.{ .invalid, .identifier });
2043 try testTokenize("0x0.0p_0", &.{ .invalid, .identifier });
2044 try testTokenize("0x0.0p+_0", &.{ .invalid, .identifier });
2045 try testTokenize("0x0.0p-_0", &.{ .invalid, .identifier });
2046 try testTokenize("0x0.0p0_", &.{ .invalid, .eof });
20472047}
20482048
2049fn testTokenize(source: []const u8, expected_tokens: []const Token.Tag) void {
2049fn testTokenize(source: []const u8, expected_tokens: []const Token.Tag) !void {
20502050 var tokenizer = Tokenizer.init(source);
20512051 for (expected_tokens) |expected_token_id| {
20522052 const token = tokenizer.next();
......@@ -2055,6 +2055,6 @@ fn testTokenize(source: []const u8, expected_tokens: []const Token.Tag) void {
20552055 }
20562056 }
20572057 const last_token = tokenizer.next();
2058 std.testing.expect(last_token.tag == .eof);
2059 std.testing.expect(last_token.loc.start == source.len);
2058 try std.testing.expect(last_token.tag == .eof);
2059 try std.testing.expect(last_token.loc.start == source.len);
20602060}
src/Cache.zig+18-18
......@@ -727,7 +727,7 @@ test "cache file and then recall it" {
727727 _ = try ch.addFile(temp_file, null);
728728
729729 // There should be nothing in the cache
730 testing.expectEqual(false, try ch.hit());
730 try testing.expectEqual(false, try ch.hit());
731731
732732 digest1 = ch.final();
733733 try ch.writeManifest();
......@@ -742,13 +742,13 @@ test "cache file and then recall it" {
742742 _ = try ch.addFile(temp_file, null);
743743
744744 // Cache hit! We just "built" the same file
745 testing.expect(try ch.hit());
745 try testing.expect(try ch.hit());
746746 digest2 = ch.final();
747747
748748 try ch.writeManifest();
749749 }
750750
751 testing.expectEqual(digest1, digest2);
751 try testing.expectEqual(digest1, digest2);
752752 }
753753
754754 try cwd.deleteTree(temp_manifest_dir);
......@@ -760,11 +760,11 @@ test "give problematic timestamp" {
760760 // to make it problematic, we make it only accurate to the second
761761 fs_clock = @divTrunc(fs_clock, std.time.ns_per_s);
762762 fs_clock *= std.time.ns_per_s;
763 testing.expect(isProblematicTimestamp(fs_clock));
763 try testing.expect(isProblematicTimestamp(fs_clock));
764764}
765765
766766test "give nonproblematic timestamp" {
767 testing.expect(!isProblematicTimestamp(std.time.nanoTimestamp() - std.time.ns_per_s));
767 try testing.expect(!isProblematicTimestamp(std.time.nanoTimestamp() - std.time.ns_per_s));
768768}
769769
770770test "check that changing a file makes cache fail" {
......@@ -807,9 +807,9 @@ test "check that changing a file makes cache fail" {
807807 const temp_file_idx = try ch.addFile(temp_file, 100);
808808
809809 // There should be nothing in the cache
810 testing.expectEqual(false, try ch.hit());
810 try testing.expectEqual(false, try ch.hit());
811811
812 testing.expect(mem.eql(u8, original_temp_file_contents, ch.files.items[temp_file_idx].contents.?));
812 try testing.expect(mem.eql(u8, original_temp_file_contents, ch.files.items[temp_file_idx].contents.?));
813813
814814 digest1 = ch.final();
815815
......@@ -826,17 +826,17 @@ test "check that changing a file makes cache fail" {
826826 const temp_file_idx = try ch.addFile(temp_file, 100);
827827
828828 // A file that we depend on has been updated, so the cache should not contain an entry for it
829 testing.expectEqual(false, try ch.hit());
829 try testing.expectEqual(false, try ch.hit());
830830
831831 // The cache system does not keep the contents of re-hashed input files.
832 testing.expect(ch.files.items[temp_file_idx].contents == null);
832 try testing.expect(ch.files.items[temp_file_idx].contents == null);
833833
834834 digest2 = ch.final();
835835
836836 try ch.writeManifest();
837837 }
838838
839 testing.expect(!mem.eql(u8, digest1[0..], digest2[0..]));
839 try testing.expect(!mem.eql(u8, digest1[0..], digest2[0..]));
840840 }
841841
842842 try cwd.deleteTree(temp_manifest_dir);
......@@ -868,7 +868,7 @@ test "no file inputs" {
868868 ch.hash.addBytes("1234");
869869
870870 // There should be nothing in the cache
871 testing.expectEqual(false, try ch.hit());
871 try testing.expectEqual(false, try ch.hit());
872872
873873 digest1 = ch.final();
874874
......@@ -880,12 +880,12 @@ test "no file inputs" {
880880
881881 ch.hash.addBytes("1234");
882882
883 testing.expect(try ch.hit());
883 try testing.expect(try ch.hit());
884884 digest2 = ch.final();
885885 try ch.writeManifest();
886886 }
887887
888 testing.expectEqual(digest1, digest2);
888 try testing.expectEqual(digest1, digest2);
889889}
890890
891891test "Manifest with files added after initial hash work" {
......@@ -926,7 +926,7 @@ test "Manifest with files added after initial hash work" {
926926 _ = try ch.addFile(temp_file1, null);
927927
928928 // There should be nothing in the cache
929 testing.expectEqual(false, try ch.hit());
929 try testing.expectEqual(false, try ch.hit());
930930
931931 _ = try ch.addFilePost(temp_file2);
932932
......@@ -940,12 +940,12 @@ test "Manifest with files added after initial hash work" {
940940 ch.hash.addBytes("1234");
941941 _ = try ch.addFile(temp_file1, null);
942942
943 testing.expect(try ch.hit());
943 try testing.expect(try ch.hit());
944944 digest2 = ch.final();
945945
946946 try ch.writeManifest();
947947 }
948 testing.expect(mem.eql(u8, &digest1, &digest2));
948 try testing.expect(mem.eql(u8, &digest1, &digest2));
949949
950950 // Modify the file added after initial hash
951951 const ts2 = std.time.nanoTimestamp();
......@@ -963,7 +963,7 @@ test "Manifest with files added after initial hash work" {
963963 _ = try ch.addFile(temp_file1, null);
964964
965965 // A file that we depend on has been updated, so the cache should not contain an entry for it
966 testing.expectEqual(false, try ch.hit());
966 try testing.expectEqual(false, try ch.hit());
967967
968968 _ = try ch.addFilePost(temp_file2);
969969
......@@ -972,7 +972,7 @@ test "Manifest with files added after initial hash work" {
972972 try ch.writeManifest();
973973 }
974974
975 testing.expect(!mem.eql(u8, &digest1, &digest3));
975 try testing.expect(!mem.eql(u8, &digest1, &digest3));
976976 }
977977
978978 try cwd.deleteTree(temp_manifest_dir);
src/Compilation.zig+8-8
......@@ -3093,14 +3093,14 @@ pub fn classifyFileExt(filename: []const u8) FileExt {
30933093}
30943094
30953095test "classifyFileExt" {
3096 std.testing.expectEqual(FileExt.cpp, classifyFileExt("foo.cc"));
3097 std.testing.expectEqual(FileExt.unknown, classifyFileExt("foo.nim"));
3098 std.testing.expectEqual(FileExt.shared_library, classifyFileExt("foo.so"));
3099 std.testing.expectEqual(FileExt.shared_library, classifyFileExt("foo.so.1"));
3100 std.testing.expectEqual(FileExt.shared_library, classifyFileExt("foo.so.1.2"));
3101 std.testing.expectEqual(FileExt.shared_library, classifyFileExt("foo.so.1.2.3"));
3102 std.testing.expectEqual(FileExt.unknown, classifyFileExt("foo.so.1.2.3~"));
3103 std.testing.expectEqual(FileExt.zig, classifyFileExt("foo.zig"));
3096 try std.testing.expectEqual(FileExt.cpp, classifyFileExt("foo.cc"));
3097 try std.testing.expectEqual(FileExt.unknown, classifyFileExt("foo.nim"));
3098 try std.testing.expectEqual(FileExt.shared_library, classifyFileExt("foo.so"));
3099 try std.testing.expectEqual(FileExt.shared_library, classifyFileExt("foo.so.1"));
3100 try std.testing.expectEqual(FileExt.shared_library, classifyFileExt("foo.so.1.2"));
3101 try std.testing.expectEqual(FileExt.shared_library, classifyFileExt("foo.so.1.2.3"));
3102 try std.testing.expectEqual(FileExt.unknown, classifyFileExt("foo.so.1.2.3~"));
3103 try std.testing.expectEqual(FileExt.zig, classifyFileExt("foo.zig"));
31043104}
31053105
31063106fn haveFramePointer(comp: *const Compilation) bool {
src/DepTokenizer.zig+2-2
......@@ -918,7 +918,7 @@ fn depTokenizer(input: []const u8, expect: []const u8) !void {
918918 }
919919
920920 if (std.mem.eql(u8, expect, buffer.items)) {
921 testing.expect(true);
921 try testing.expect(true);
922922 return;
923923 }
924924
......@@ -930,7 +930,7 @@ fn depTokenizer(input: []const u8, expect: []const u8) !void {
930930 try printSection(out, ">>>> got", buffer.items);
931931 try printRuler(out);
932932
933 testing.expect(false);
933 try testing.expect(false);
934934}
935935
936936fn printSection(out: anytype, label: []const u8, bytes: []const u8) !void {
src/codegen/aarch64.zig+34-34
......@@ -67,27 +67,27 @@ pub const c_abi_int_param_regs = [_]Register{ .x0, .x1, .x2, .x3, .x4, .x5, .x6,
6767pub const c_abi_int_return_regs = [_]Register{ .x0, .x1, .x2, .x3, .x4, .x5, .x6, .x7 };
6868
6969test "Register.id" {
70 testing.expectEqual(@as(u5, 0), Register.x0.id());
71 testing.expectEqual(@as(u5, 0), Register.w0.id());
70 try testing.expectEqual(@as(u5, 0), Register.x0.id());
71 try testing.expectEqual(@as(u5, 0), Register.w0.id());
7272
73 testing.expectEqual(@as(u5, 31), Register.xzr.id());
74 testing.expectEqual(@as(u5, 31), Register.wzr.id());
73 try testing.expectEqual(@as(u5, 31), Register.xzr.id());
74 try testing.expectEqual(@as(u5, 31), Register.wzr.id());
7575
76 testing.expectEqual(@as(u5, 31), Register.sp.id());
77 testing.expectEqual(@as(u5, 31), Register.sp.id());
76 try testing.expectEqual(@as(u5, 31), Register.sp.id());
77 try testing.expectEqual(@as(u5, 31), Register.sp.id());
7878}
7979
8080test "Register.size" {
81 testing.expectEqual(@as(u7, 64), Register.x19.size());
82 testing.expectEqual(@as(u7, 32), Register.w3.size());
81 try testing.expectEqual(@as(u7, 64), Register.x19.size());
82 try testing.expectEqual(@as(u7, 32), Register.w3.size());
8383}
8484
8585test "Register.to64/to32" {
86 testing.expectEqual(Register.x0, Register.w0.to64());
87 testing.expectEqual(Register.x0, Register.x0.to64());
86 try testing.expectEqual(Register.x0, Register.w0.to64());
87 try testing.expectEqual(Register.x0, Register.x0.to64());
8888
89 testing.expectEqual(Register.w3, Register.w3.to32());
90 testing.expectEqual(Register.w3, Register.x3.to32());
89 try testing.expectEqual(Register.w3, Register.w3.to32());
90 try testing.expectEqual(Register.w3, Register.x3.to32());
9191}
9292
9393// zig fmt: off
......@@ -169,33 +169,33 @@ pub const FloatingPointRegister = enum(u8) {
169169// zig fmt: on
170170
171171test "FloatingPointRegister.id" {
172 testing.expectEqual(@as(u5, 0), FloatingPointRegister.b0.id());
173 testing.expectEqual(@as(u5, 0), FloatingPointRegister.h0.id());
174 testing.expectEqual(@as(u5, 0), FloatingPointRegister.s0.id());
175 testing.expectEqual(@as(u5, 0), FloatingPointRegister.d0.id());
176 testing.expectEqual(@as(u5, 0), FloatingPointRegister.q0.id());
177
178 testing.expectEqual(@as(u5, 2), FloatingPointRegister.q2.id());
179 testing.expectEqual(@as(u5, 31), FloatingPointRegister.d31.id());
172 try testing.expectEqual(@as(u5, 0), FloatingPointRegister.b0.id());
173 try testing.expectEqual(@as(u5, 0), FloatingPointRegister.h0.id());
174 try testing.expectEqual(@as(u5, 0), FloatingPointRegister.s0.id());
175 try testing.expectEqual(@as(u5, 0), FloatingPointRegister.d0.id());
176 try testing.expectEqual(@as(u5, 0), FloatingPointRegister.q0.id());
177
178 try testing.expectEqual(@as(u5, 2), FloatingPointRegister.q2.id());
179 try testing.expectEqual(@as(u5, 31), FloatingPointRegister.d31.id());
180180}
181181
182182test "FloatingPointRegister.size" {
183 testing.expectEqual(@as(u8, 128), FloatingPointRegister.q1.size());
184 testing.expectEqual(@as(u8, 64), FloatingPointRegister.d2.size());
185 testing.expectEqual(@as(u8, 32), FloatingPointRegister.s3.size());
186 testing.expectEqual(@as(u8, 16), FloatingPointRegister.h4.size());
187 testing.expectEqual(@as(u8, 8), FloatingPointRegister.b5.size());
183 try testing.expectEqual(@as(u8, 128), FloatingPointRegister.q1.size());
184 try testing.expectEqual(@as(u8, 64), FloatingPointRegister.d2.size());
185 try testing.expectEqual(@as(u8, 32), FloatingPointRegister.s3.size());
186 try testing.expectEqual(@as(u8, 16), FloatingPointRegister.h4.size());
187 try testing.expectEqual(@as(u8, 8), FloatingPointRegister.b5.size());
188188}
189189
190190test "FloatingPointRegister.toX" {
191 testing.expectEqual(FloatingPointRegister.q1, FloatingPointRegister.q1.to128());
192 testing.expectEqual(FloatingPointRegister.q2, FloatingPointRegister.b2.to128());
193 testing.expectEqual(FloatingPointRegister.q3, FloatingPointRegister.h3.to128());
194
195 testing.expectEqual(FloatingPointRegister.d0, FloatingPointRegister.q0.to64());
196 testing.expectEqual(FloatingPointRegister.s1, FloatingPointRegister.d1.to32());
197 testing.expectEqual(FloatingPointRegister.h2, FloatingPointRegister.s2.to16());
198 testing.expectEqual(FloatingPointRegister.b3, FloatingPointRegister.h3.to8());
191 try testing.expectEqual(FloatingPointRegister.q1, FloatingPointRegister.q1.to128());
192 try testing.expectEqual(FloatingPointRegister.q2, FloatingPointRegister.b2.to128());
193 try testing.expectEqual(FloatingPointRegister.q3, FloatingPointRegister.h3.to128());
194
195 try testing.expectEqual(FloatingPointRegister.d0, FloatingPointRegister.q0.to64());
196 try testing.expectEqual(FloatingPointRegister.s1, FloatingPointRegister.d1.to32());
197 try testing.expectEqual(FloatingPointRegister.h2, FloatingPointRegister.s2.to16());
198 try testing.expectEqual(FloatingPointRegister.b3, FloatingPointRegister.h3.to8());
199199}
200200
201201/// Represents an instruction in the AArch64 instruction set
......@@ -1225,6 +1225,6 @@ test "serialize instructions" {
12251225
12261226 for (testcases) |case| {
12271227 const actual = case.inst.toU32();
1228 testing.expectEqual(case.expected, actual);
1228 try testing.expectEqual(case.expected, actual);
12291229 }
12301230}
src/codegen/arm.zig+12-12
......@@ -88,19 +88,19 @@ pub const Condition = enum(u4) {
8888};
8989
9090test "condition from CompareOperator" {
91 testing.expectEqual(@as(Condition, .eq), Condition.fromCompareOperatorSigned(.eq));
92 testing.expectEqual(@as(Condition, .eq), Condition.fromCompareOperatorUnsigned(.eq));
91 try testing.expectEqual(@as(Condition, .eq), Condition.fromCompareOperatorSigned(.eq));
92 try testing.expectEqual(@as(Condition, .eq), Condition.fromCompareOperatorUnsigned(.eq));
9393
94 testing.expectEqual(@as(Condition, .gt), Condition.fromCompareOperatorSigned(.gt));
95 testing.expectEqual(@as(Condition, .hi), Condition.fromCompareOperatorUnsigned(.gt));
94 try testing.expectEqual(@as(Condition, .gt), Condition.fromCompareOperatorSigned(.gt));
95 try testing.expectEqual(@as(Condition, .hi), Condition.fromCompareOperatorUnsigned(.gt));
9696
97 testing.expectEqual(@as(Condition, .le), Condition.fromCompareOperatorSigned(.lte));
98 testing.expectEqual(@as(Condition, .ls), Condition.fromCompareOperatorUnsigned(.lte));
97 try testing.expectEqual(@as(Condition, .le), Condition.fromCompareOperatorSigned(.lte));
98 try testing.expectEqual(@as(Condition, .ls), Condition.fromCompareOperatorUnsigned(.lte));
9999}
100100
101101test "negate condition" {
102 testing.expectEqual(@as(Condition, .eq), Condition.ne.negate());
103 testing.expectEqual(@as(Condition, .ne), Condition.eq.negate());
102 try testing.expectEqual(@as(Condition, .eq), Condition.ne.negate());
103 try testing.expectEqual(@as(Condition, .ne), Condition.eq.negate());
104104}
105105
106106/// Represents a register in the ARM instruction set architecture
......@@ -175,8 +175,8 @@ pub const Register = enum(u5) {
175175};
176176
177177test "Register.id" {
178 testing.expectEqual(@as(u4, 15), Register.r15.id());
179 testing.expectEqual(@as(u4, 15), Register.pc.id());
178 try testing.expectEqual(@as(u4, 15), Register.r15.id());
179 try testing.expectEqual(@as(u4, 15), Register.pc.id());
180180}
181181
182182/// Program status registers containing flags, mode bits and other
......@@ -1225,7 +1225,7 @@ test "serialize instructions" {
12251225
12261226 for (testcases) |case| {
12271227 const actual = case.inst.toU32();
1228 testing.expectEqual(case.expected, actual);
1228 try testing.expectEqual(case.expected, actual);
12291229 }
12301230}
12311231
......@@ -1265,6 +1265,6 @@ test "aliases" {
12651265 };
12661266
12671267 for (testcases) |case| {
1268 testing.expectEqual(case.expected.toU32(), case.actual.toU32());
1268 try testing.expectEqual(case.expected.toU32(), case.actual.toU32());
12691269 }
12701270}
src/codegen/riscv64.zig+1-1
......@@ -465,6 +465,6 @@ test "serialize instructions" {
465465
466466 for (testcases) |case| {
467467 const actual = case.inst.toU32();
468 testing.expectEqual(case.expected, actual);
468 try testing.expectEqual(case.expected, actual);
469469 }
470470}
src/codegen/wasm.zig+5-5
......@@ -463,11 +463,11 @@ test "Wasm - buildOpcode" {
463463 const i64_extend32_s = buildOpcode(.{ .op = .extend, .valtype1 = .i64, .width = 32, .signedness = .signed });
464464 const f64_reinterpret_i64 = buildOpcode(.{ .op = .reinterpret, .valtype1 = .f64, .valtype2 = .i64 });
465465
466 testing.expectEqual(@as(wasm.Opcode, .i32_const), i32_const);
467 testing.expectEqual(@as(wasm.Opcode, .end), end);
468 testing.expectEqual(@as(wasm.Opcode, .local_get), local_get);
469 testing.expectEqual(@as(wasm.Opcode, .i64_extend32_s), i64_extend32_s);
470 testing.expectEqual(@as(wasm.Opcode, .f64_reinterpret_i64), f64_reinterpret_i64);
466 try testing.expectEqual(@as(wasm.Opcode, .i32_const), i32_const);
467 try testing.expectEqual(@as(wasm.Opcode, .end), end);
468 try testing.expectEqual(@as(wasm.Opcode, .local_get), local_get);
469 try testing.expectEqual(@as(wasm.Opcode, .i64_extend32_s), i64_extend32_s);
470 try testing.expectEqual(@as(wasm.Opcode, .f64_reinterpret_i64), f64_reinterpret_i64);
471471}
472472
473473pub const Result = union(enum) {
src/link/MachO.zig+1-4
......@@ -687,10 +687,7 @@ fn linkWithLLD(self: *MachO, comp: *Compilation) !void {
687687 try argv.append("zig");
688688 try argv.append("ld");
689689
690 try argv.ensureCapacity(input_files.items.len);
691 for (input_files.items) |f| {
692 argv.appendAssumeCapacity(f);
693 }
690 try argv.appendSlice(input_files.items);
694691
695692 try argv.append("-o");
696693 try argv.append(full_out_path);
src/link/MachO/CodeSignature.zig+1-1
......@@ -182,7 +182,7 @@ test "CodeSignature header" {
182182 try code_sig.writeHeader(stream.writer());
183183
184184 const expected = &[_]u8{ 0xfa, 0xde, 0x0c, 0xc0, 0x0, 0x0, 0x0, 0xc, 0x0, 0x0, 0x0, 0x0 };
185 testing.expect(mem.eql(u8, expected, &buffer));
185 try testing.expect(mem.eql(u8, expected, &buffer));
186186}
187187
188188pub fn calcCodeSignaturePaddingSize(id: []const u8, file_size: u64, page_size: u16) u32 {
src/link/MachO/Trie.zig+26-26
......@@ -404,15 +404,15 @@ test "Trie node count" {
404404 var trie = Trie.init(gpa);
405405 defer trie.deinit();
406406
407 testing.expectEqual(trie.node_count, 0);
408 testing.expect(trie.root == null);
407 try testing.expectEqual(trie.node_count, 0);
408 try testing.expect(trie.root == null);
409409
410410 try trie.put(.{
411411 .name = "_main",
412412 .vmaddr_offset = 0,
413413 .export_flags = 0,
414414 });
415 testing.expectEqual(trie.node_count, 2);
415 try testing.expectEqual(trie.node_count, 2);
416416
417417 // Inserting the same node shouldn't update the trie.
418418 try trie.put(.{
......@@ -420,14 +420,14 @@ test "Trie node count" {
420420 .vmaddr_offset = 0,
421421 .export_flags = 0,
422422 });
423 testing.expectEqual(trie.node_count, 2);
423 try testing.expectEqual(trie.node_count, 2);
424424
425425 try trie.put(.{
426426 .name = "__mh_execute_header",
427427 .vmaddr_offset = 0x1000,
428428 .export_flags = 0,
429429 });
430 testing.expectEqual(trie.node_count, 4);
430 try testing.expectEqual(trie.node_count, 4);
431431
432432 // Inserting the same node shouldn't update the trie.
433433 try trie.put(.{
......@@ -435,13 +435,13 @@ test "Trie node count" {
435435 .vmaddr_offset = 0x1000,
436436 .export_flags = 0,
437437 });
438 testing.expectEqual(trie.node_count, 4);
438 try testing.expectEqual(trie.node_count, 4);
439439 try trie.put(.{
440440 .name = "_main",
441441 .vmaddr_offset = 0,
442442 .export_flags = 0,
443443 });
444 testing.expectEqual(trie.node_count, 4);
444 try testing.expectEqual(trie.node_count, 4);
445445}
446446
447447test "Trie basic" {
......@@ -455,8 +455,8 @@ test "Trie basic" {
455455 .vmaddr_offset = 0,
456456 .export_flags = 0,
457457 });
458 testing.expect(trie.root.?.edges.items.len == 1);
459 testing.expect(mem.eql(u8, trie.root.?.edges.items[0].label, "_st"));
458 try testing.expect(trie.root.?.edges.items.len == 1);
459 try testing.expect(mem.eql(u8, trie.root.?.edges.items[0].label, "_st"));
460460
461461 {
462462 // root --- _st ---> node --- art ---> node
......@@ -465,12 +465,12 @@ test "Trie basic" {
465465 .vmaddr_offset = 0,
466466 .export_flags = 0,
467467 });
468 testing.expect(trie.root.?.edges.items.len == 1);
468 try testing.expect(trie.root.?.edges.items.len == 1);
469469
470470 const nextEdge = &trie.root.?.edges.items[0];
471 testing.expect(mem.eql(u8, nextEdge.label, "_st"));
472 testing.expect(nextEdge.to.edges.items.len == 1);
473 testing.expect(mem.eql(u8, nextEdge.to.edges.items[0].label, "art"));
471 try testing.expect(mem.eql(u8, nextEdge.label, "_st"));
472 try testing.expect(nextEdge.to.edges.items.len == 1);
473 try testing.expect(mem.eql(u8, nextEdge.to.edges.items[0].label, "art"));
474474 }
475475 {
476476 // root --- _ ---> node --- st ---> node --- art ---> node
......@@ -481,16 +481,16 @@ test "Trie basic" {
481481 .vmaddr_offset = 0,
482482 .export_flags = 0,
483483 });
484 testing.expect(trie.root.?.edges.items.len == 1);
484 try testing.expect(trie.root.?.edges.items.len == 1);
485485
486486 const nextEdge = &trie.root.?.edges.items[0];
487 testing.expect(mem.eql(u8, nextEdge.label, "_"));
488 testing.expect(nextEdge.to.edges.items.len == 2);
489 testing.expect(mem.eql(u8, nextEdge.to.edges.items[0].label, "st"));
490 testing.expect(mem.eql(u8, nextEdge.to.edges.items[1].label, "main"));
487 try testing.expect(mem.eql(u8, nextEdge.label, "_"));
488 try testing.expect(nextEdge.to.edges.items.len == 2);
489 try testing.expect(mem.eql(u8, nextEdge.to.edges.items[0].label, "st"));
490 try testing.expect(mem.eql(u8, nextEdge.to.edges.items[1].label, "main"));
491491
492492 const nextNextEdge = &nextEdge.to.edges.items[0];
493 testing.expect(mem.eql(u8, nextNextEdge.to.edges.items[0].label, "art"));
493 try testing.expect(mem.eql(u8, nextNextEdge.to.edges.items[0].label, "art"));
494494 }
495495}
496496
......@@ -529,15 +529,15 @@ test "write Trie to a byte stream" {
529529 var stream = std.io.fixedBufferStream(buffer);
530530 {
531531 const nwritten = try trie.write(stream.writer());
532 testing.expect(nwritten == trie.size);
533 testing.expect(mem.eql(u8, buffer, &exp_buffer));
532 try testing.expect(nwritten == trie.size);
533 try testing.expect(mem.eql(u8, buffer, &exp_buffer));
534534 }
535535 {
536536 // Writing finalized trie again should yield the same result.
537537 try stream.seekTo(0);
538538 const nwritten = try trie.write(stream.writer());
539 testing.expect(nwritten == trie.size);
540 testing.expect(mem.eql(u8, buffer, &exp_buffer));
539 try testing.expect(nwritten == trie.size);
540 try testing.expect(mem.eql(u8, buffer, &exp_buffer));
541541 }
542542}
543543
......@@ -560,7 +560,7 @@ test "parse Trie from byte stream" {
560560 defer trie.deinit();
561561 const nread = try trie.read(in_stream.reader());
562562
563 testing.expect(nread == in_buffer.len);
563 try testing.expect(nread == in_buffer.len);
564564
565565 try trie.finalize();
566566
......@@ -569,6 +569,6 @@ test "parse Trie from byte stream" {
569569 var out_stream = std.io.fixedBufferStream(out_buffer);
570570 const nwritten = try trie.write(out_stream.writer());
571571
572 testing.expect(nwritten == trie.size);
573 testing.expect(mem.eql(u8, &in_buffer, out_buffer));
572 try testing.expect(nwritten == trie.size);
573 try testing.expect(mem.eql(u8, &in_buffer, out_buffer));
574574}
src/link/MachO/commands.zig+2-2
......@@ -286,13 +286,13 @@ fn testRead(allocator: *Allocator, buffer: []const u8, expected: anytype) !void
286286 var stream = io.fixedBufferStream(buffer);
287287 var given = try LoadCommand.read(allocator, stream.reader());
288288 defer given.deinit(allocator);
289 testing.expect(expected.eql(given));
289 try testing.expect(expected.eql(given));
290290}
291291
292292fn testWrite(buffer: []u8, cmd: LoadCommand, expected: []const u8) !void {
293293 var stream = io.fixedBufferStream(buffer);
294294 try cmd.write(stream.writer());
295 testing.expect(mem.eql(u8, expected, buffer[0..expected.len]));
295 try testing.expect(mem.eql(u8, expected, buffer[0..expected.len]));
296296}
297297
298298test "read-write segment command" {
src/register_manager.zig+24-24
......@@ -267,21 +267,21 @@ test "tryAllocReg: no spilling" {
267267 .src = .unneeded,
268268 };
269269
270 std.testing.expect(!function.register_manager.isRegAllocated(.r2));
271 std.testing.expect(!function.register_manager.isRegAllocated(.r3));
270 try std.testing.expect(!function.register_manager.isRegAllocated(.r2));
271 try std.testing.expect(!function.register_manager.isRegAllocated(.r3));
272272
273 std.testing.expectEqual(@as(?MockRegister, .r2), function.register_manager.tryAllocReg(&mock_instruction));
274 std.testing.expectEqual(@as(?MockRegister, .r3), function.register_manager.tryAllocReg(&mock_instruction));
275 std.testing.expectEqual(@as(?MockRegister, null), function.register_manager.tryAllocReg(&mock_instruction));
273 try std.testing.expectEqual(@as(?MockRegister, .r2), function.register_manager.tryAllocReg(&mock_instruction));
274 try std.testing.expectEqual(@as(?MockRegister, .r3), function.register_manager.tryAllocReg(&mock_instruction));
275 try std.testing.expectEqual(@as(?MockRegister, null), function.register_manager.tryAllocReg(&mock_instruction));
276276
277 std.testing.expect(function.register_manager.isRegAllocated(.r2));
278 std.testing.expect(function.register_manager.isRegAllocated(.r3));
277 try std.testing.expect(function.register_manager.isRegAllocated(.r2));
278 try std.testing.expect(function.register_manager.isRegAllocated(.r3));
279279
280280 function.register_manager.freeReg(.r2);
281281 function.register_manager.freeReg(.r3);
282282
283 std.testing.expect(function.register_manager.isRegAllocated(.r2));
284 std.testing.expect(function.register_manager.isRegAllocated(.r3));
283 try std.testing.expect(function.register_manager.isRegAllocated(.r2));
284 try std.testing.expect(function.register_manager.isRegAllocated(.r3));
285285}
286286
287287test "allocReg: spilling" {
......@@ -298,20 +298,20 @@ test "allocReg: spilling" {
298298 .src = .unneeded,
299299 };
300300
301 std.testing.expect(!function.register_manager.isRegAllocated(.r2));
302 std.testing.expect(!function.register_manager.isRegAllocated(.r3));
301 try std.testing.expect(!function.register_manager.isRegAllocated(.r2));
302 try std.testing.expect(!function.register_manager.isRegAllocated(.r3));
303303
304 std.testing.expectEqual(@as(?MockRegister, .r2), try function.register_manager.allocReg(&mock_instruction));
305 std.testing.expectEqual(@as(?MockRegister, .r3), try function.register_manager.allocReg(&mock_instruction));
304 try std.testing.expectEqual(@as(?MockRegister, .r2), try function.register_manager.allocReg(&mock_instruction));
305 try std.testing.expectEqual(@as(?MockRegister, .r3), try function.register_manager.allocReg(&mock_instruction));
306306
307307 // Spill a register
308 std.testing.expectEqual(@as(?MockRegister, .r2), try function.register_manager.allocReg(&mock_instruction));
309 std.testing.expectEqualSlices(MockRegister, &[_]MockRegister{.r2}, function.spilled.items);
308 try std.testing.expectEqual(@as(?MockRegister, .r2), try function.register_manager.allocReg(&mock_instruction));
309 try std.testing.expectEqualSlices(MockRegister, &[_]MockRegister{.r2}, function.spilled.items);
310310
311311 // No spilling necessary
312312 function.register_manager.freeReg(.r3);
313 std.testing.expectEqual(@as(?MockRegister, .r3), try function.register_manager.allocReg(&mock_instruction));
314 std.testing.expectEqualSlices(MockRegister, &[_]MockRegister{.r2}, function.spilled.items);
313 try std.testing.expectEqual(@as(?MockRegister, .r3), try function.register_manager.allocReg(&mock_instruction));
314 try std.testing.expectEqualSlices(MockRegister, &[_]MockRegister{.r2}, function.spilled.items);
315315}
316316
317317test "getReg" {
......@@ -328,18 +328,18 @@ test "getReg" {
328328 .src = .unneeded,
329329 };
330330
331 std.testing.expect(!function.register_manager.isRegAllocated(.r2));
332 std.testing.expect(!function.register_manager.isRegAllocated(.r3));
331 try std.testing.expect(!function.register_manager.isRegAllocated(.r2));
332 try std.testing.expect(!function.register_manager.isRegAllocated(.r3));
333333
334334 try function.register_manager.getReg(.r3, &mock_instruction);
335335
336 std.testing.expect(!function.register_manager.isRegAllocated(.r2));
337 std.testing.expect(function.register_manager.isRegAllocated(.r3));
336 try std.testing.expect(!function.register_manager.isRegAllocated(.r2));
337 try std.testing.expect(function.register_manager.isRegAllocated(.r3));
338338
339339 // Spill r3
340340 try function.register_manager.getReg(.r3, &mock_instruction);
341341
342 std.testing.expect(!function.register_manager.isRegAllocated(.r2));
343 std.testing.expect(function.register_manager.isRegAllocated(.r3));
344 std.testing.expectEqualSlices(MockRegister, &[_]MockRegister{.r3}, function.spilled.items);
342 try std.testing.expect(!function.register_manager.isRegAllocated(.r2));
343 try std.testing.expect(function.register_manager.isRegAllocated(.r3));
344 try std.testing.expectEqualSlices(MockRegister, &[_]MockRegister{.r3}, function.spilled.items);
345345}
src/test.zig+3-3
......@@ -704,14 +704,14 @@ pub const TestContext = struct {
704704 defer file.close();
705705 const out = try file.reader().readAllAlloc(arena, 5 * 1024 * 1024);
706706
707 std.testing.expectEqualStrings(expected_output, out);
707 try std.testing.expectEqualStrings(expected_output, out);
708708 },
709709 .CompareObjectFile => |expected_output| {
710710 var file = try tmp.dir.openFile(bin_name, .{ .read = true });
711711 defer file.close();
712712 const out = try file.reader().readAllAlloc(arena, 5 * 1024 * 1024);
713713
714 std.testing.expectEqualStrings(expected_output, out);
714 try std.testing.expectEqualStrings(expected_output, out);
715715 },
716716 .Error => |case_error_list| {
717717 var test_node = update_node.start("assert", 0);
......@@ -938,7 +938,7 @@ pub const TestContext = struct {
938938 return error.ZigTestFailed;
939939 },
940940 }
941 std.testing.expectEqualStrings(expected_stdout, exec_result.stdout);
941 try std.testing.expectEqualStrings(expected_stdout, exec_result.stdout);
942942 // We allow stderr to have garbage in it because wasmtime prints a
943943 // warning about --invoke even though we don't pass it.
944944 //std.testing.expectEqualStrings("", exec_result.stderr);
src/value.zig+3-3
......@@ -1650,19 +1650,19 @@ test "hash same value different representation" {
16501650 .data = 0,
16511651 };
16521652 const zero_2 = Value.initPayload(&payload_1.base);
1653 std.testing.expectEqual(zero_1.hash(), zero_2.hash());
1653 try std.testing.expectEqual(zero_1.hash(), zero_2.hash());
16541654
16551655 var payload_2 = Value.Payload.I64{
16561656 .base = .{ .tag = .int_i64 },
16571657 .data = 0,
16581658 };
16591659 const zero_3 = Value.initPayload(&payload_2.base);
1660 std.testing.expectEqual(zero_2.hash(), zero_3.hash());
1660 try std.testing.expectEqual(zero_2.hash(), zero_3.hash());
16611661
16621662 var payload_3 = Value.Payload.BigInt{
16631663 .base = .{ .tag = .int_big_negative },
16641664 .data = &[_]std.math.big.Limb{0},
16651665 };
16661666 const zero_4 = Value.initPayload(&payload_3.base);
1667 std.testing.expectEqual(zero_3.hash(), zero_4.hash());
1667 try std.testing.expectEqual(zero_3.hash(), zero_4.hash());
16681668}
test/behavior/align.zig+66-66
......@@ -6,16 +6,16 @@ const native_arch = builtin.target.cpu.arch;
66var foo: u8 align(4) = 100;
77
88test "global variable alignment" {
9 comptime expect(@typeInfo(@TypeOf(&foo)).Pointer.alignment == 4);
10 comptime expect(@TypeOf(&foo) == *align(4) u8);
9 comptime try expect(@typeInfo(@TypeOf(&foo)).Pointer.alignment == 4);
10 comptime try expect(@TypeOf(&foo) == *align(4) u8);
1111 {
1212 const slice = @as(*[1]u8, &foo)[0..];
13 comptime expect(@TypeOf(slice) == *align(4) [1]u8);
13 comptime try expect(@TypeOf(slice) == *align(4) [1]u8);
1414 }
1515 {
1616 var runtime_zero: usize = 0;
1717 const slice = @as(*[1]u8, &foo)[runtime_zero..];
18 comptime expect(@TypeOf(slice) == []align(4) u8);
18 comptime try expect(@TypeOf(slice) == []align(4) u8);
1919 }
2020}
2121
......@@ -29,9 +29,9 @@ test "function alignment" {
2929 // function alignment is a compile error on wasm32/wasm64
3030 if (native_arch == .wasm32 or native_arch == .wasm64) return error.SkipZigTest;
3131
32 expect(derp() == 1234);
33 expect(@TypeOf(noop1) == fn () align(1) void);
34 expect(@TypeOf(noop4) == fn () align(4) void);
32 try expect(derp() == 1234);
33 try expect(@TypeOf(noop1) == fn () align(1) void);
34 try expect(@TypeOf(noop4) == fn () align(4) void);
3535 noop1();
3636 noop4();
3737}
......@@ -42,7 +42,7 @@ var baz: packed struct {
4242} = undefined;
4343
4444test "packed struct alignment" {
45 expect(@TypeOf(&baz.b) == *align(1) u32);
45 try expect(@TypeOf(&baz.b) == *align(1) u32);
4646}
4747
4848const blah: packed struct {
......@@ -52,17 +52,17 @@ const blah: packed struct {
5252} = undefined;
5353
5454test "bit field alignment" {
55 expect(@TypeOf(&blah.b) == *align(1:3:1) const u3);
55 try expect(@TypeOf(&blah.b) == *align(1:3:1) const u3);
5656}
5757
5858test "default alignment allows unspecified in type syntax" {
59 expect(*u32 == *align(@alignOf(u32)) u32);
59 try expect(*u32 == *align(@alignOf(u32)) u32);
6060}
6161
6262test "implicitly decreasing pointer alignment" {
6363 const a: u32 align(4) = 3;
6464 const b: u32 align(8) = 4;
65 expect(addUnaligned(&a, &b) == 7);
65 try expect(addUnaligned(&a, &b) == 7);
6666}
6767
6868fn addUnaligned(a: *align(1) const u32, b: *align(1) const u32) u32 {
......@@ -72,16 +72,16 @@ fn addUnaligned(a: *align(1) const u32, b: *align(1) const u32) u32 {
7272test "implicitly decreasing slice alignment" {
7373 const a: u32 align(4) = 3;
7474 const b: u32 align(8) = 4;
75 expect(addUnalignedSlice(@as(*const [1]u32, &a)[0..], @as(*const [1]u32, &b)[0..]) == 7);
75 try expect(addUnalignedSlice(@as(*const [1]u32, &a)[0..], @as(*const [1]u32, &b)[0..]) == 7);
7676}
7777fn addUnalignedSlice(a: []align(1) const u32, b: []align(1) const u32) u32 {
7878 return a[0] + b[0];
7979}
8080
8181test "specifying alignment allows pointer cast" {
82 testBytesAlign(0x33);
82 try testBytesAlign(0x33);
8383}
84fn testBytesAlign(b: u8) void {
84fn testBytesAlign(b: u8) !void {
8585 var bytes align(4) = [_]u8{
8686 b,
8787 b,
......@@ -89,13 +89,13 @@ fn testBytesAlign(b: u8) void {
8989 b,
9090 };
9191 const ptr = @ptrCast(*u32, &bytes[0]);
92 expect(ptr.* == 0x33333333);
92 try expect(ptr.* == 0x33333333);
9393}
9494
9595test "@alignCast pointers" {
9696 var x: u32 align(4) = 1;
9797 expectsOnly1(&x);
98 expect(x == 2);
98 try expect(x == 2);
9999}
100100fn expectsOnly1(x: *align(1) u32) void {
101101 expects4(@alignCast(4, x));
......@@ -111,7 +111,7 @@ test "@alignCast slices" {
111111 };
112112 const slice = array[0..];
113113 sliceExpectsOnly1(slice);
114 expect(slice[0] == 2);
114 try expect(slice[0] == 2);
115115}
116116fn sliceExpectsOnly1(slice: []align(1) u32) void {
117117 sliceExpects4(@alignCast(4, slice));
......@@ -124,12 +124,12 @@ test "implicitly decreasing fn alignment" {
124124 // function alignment is a compile error on wasm32/wasm64
125125 if (native_arch == .wasm32 or native_arch == .wasm64) return error.SkipZigTest;
126126
127 testImplicitlyDecreaseFnAlign(alignedSmall, 1234);
128 testImplicitlyDecreaseFnAlign(alignedBig, 5678);
127 try testImplicitlyDecreaseFnAlign(alignedSmall, 1234);
128 try testImplicitlyDecreaseFnAlign(alignedBig, 5678);
129129}
130130
131fn testImplicitlyDecreaseFnAlign(ptr: fn () align(1) i32, answer: i32) void {
132 expect(ptr() == answer);
131fn testImplicitlyDecreaseFnAlign(ptr: fn () align(1) i32, answer: i32) !void {
132 try expect(ptr() == answer);
133133}
134134
135135fn alignedSmall() align(8) i32 {
......@@ -144,7 +144,7 @@ test "@alignCast functions" {
144144 if (native_arch == .wasm32 or native_arch == .wasm64) return error.SkipZigTest;
145145 if (native_arch == .thumb) return error.SkipZigTest;
146146
147 expect(fnExpectsOnly1(simple4) == 0x19);
147 try expect(fnExpectsOnly1(simple4) == 0x19);
148148}
149149fn fnExpectsOnly1(ptr: fn () align(1) i32) i32 {
150150 return fnExpects4(@alignCast(4, ptr));
......@@ -161,9 +161,9 @@ test "generic function with align param" {
161161 if (native_arch == .wasm32 or native_arch == .wasm64) return error.SkipZigTest;
162162 if (native_arch == .thumb) return error.SkipZigTest;
163163
164 expect(whyWouldYouEverDoThis(1) == 0x1);
165 expect(whyWouldYouEverDoThis(4) == 0x1);
166 expect(whyWouldYouEverDoThis(8) == 0x1);
164 try expect(whyWouldYouEverDoThis(1) == 0x1);
165 try expect(whyWouldYouEverDoThis(4) == 0x1);
166 try expect(whyWouldYouEverDoThis(8) == 0x1);
167167}
168168
169169fn whyWouldYouEverDoThis(comptime align_bytes: u8) align(align_bytes) u8 {
......@@ -173,49 +173,49 @@ fn whyWouldYouEverDoThis(comptime align_bytes: u8) align(align_bytes) u8 {
173173test "@ptrCast preserves alignment of bigger source" {
174174 var x: u32 align(16) = 1234;
175175 const ptr = @ptrCast(*u8, &x);
176 expect(@TypeOf(ptr) == *align(16) u8);
176 try expect(@TypeOf(ptr) == *align(16) u8);
177177}
178178
179179test "runtime known array index has best alignment possible" {
180180 // take full advantage of over-alignment
181181 var array align(4) = [_]u8{ 1, 2, 3, 4 };
182 expect(@TypeOf(&array[0]) == *align(4) u8);
183 expect(@TypeOf(&array[1]) == *u8);
184 expect(@TypeOf(&array[2]) == *align(2) u8);
185 expect(@TypeOf(&array[3]) == *u8);
182 try expect(@TypeOf(&array[0]) == *align(4) u8);
183 try expect(@TypeOf(&array[1]) == *u8);
184 try expect(@TypeOf(&array[2]) == *align(2) u8);
185 try expect(@TypeOf(&array[3]) == *u8);
186186
187187 // because align is too small but we still figure out to use 2
188188 var bigger align(2) = [_]u64{ 1, 2, 3, 4 };
189 expect(@TypeOf(&bigger[0]) == *align(2) u64);
190 expect(@TypeOf(&bigger[1]) == *align(2) u64);
191 expect(@TypeOf(&bigger[2]) == *align(2) u64);
192 expect(@TypeOf(&bigger[3]) == *align(2) u64);
189 try expect(@TypeOf(&bigger[0]) == *align(2) u64);
190 try expect(@TypeOf(&bigger[1]) == *align(2) u64);
191 try expect(@TypeOf(&bigger[2]) == *align(2) u64);
192 try expect(@TypeOf(&bigger[3]) == *align(2) u64);
193193
194194 // because pointer is align 2 and u32 align % 2 == 0 we can assume align 2
195195 var smaller align(2) = [_]u32{ 1, 2, 3, 4 };
196196 var runtime_zero: usize = 0;
197 comptime expect(@TypeOf(smaller[runtime_zero..]) == []align(2) u32);
198 comptime expect(@TypeOf(smaller[runtime_zero..].ptr) == [*]align(2) u32);
199 testIndex(smaller[runtime_zero..].ptr, 0, *align(2) u32);
200 testIndex(smaller[runtime_zero..].ptr, 1, *align(2) u32);
201 testIndex(smaller[runtime_zero..].ptr, 2, *align(2) u32);
202 testIndex(smaller[runtime_zero..].ptr, 3, *align(2) u32);
197 comptime try expect(@TypeOf(smaller[runtime_zero..]) == []align(2) u32);
198 comptime try expect(@TypeOf(smaller[runtime_zero..].ptr) == [*]align(2) u32);
199 try testIndex(smaller[runtime_zero..].ptr, 0, *align(2) u32);
200 try testIndex(smaller[runtime_zero..].ptr, 1, *align(2) u32);
201 try testIndex(smaller[runtime_zero..].ptr, 2, *align(2) u32);
202 try testIndex(smaller[runtime_zero..].ptr, 3, *align(2) u32);
203203
204204 // has to use ABI alignment because index known at runtime only
205 testIndex2(array[runtime_zero..].ptr, 0, *u8);
206 testIndex2(array[runtime_zero..].ptr, 1, *u8);
207 testIndex2(array[runtime_zero..].ptr, 2, *u8);
208 testIndex2(array[runtime_zero..].ptr, 3, *u8);
205 try testIndex2(array[runtime_zero..].ptr, 0, *u8);
206 try testIndex2(array[runtime_zero..].ptr, 1, *u8);
207 try testIndex2(array[runtime_zero..].ptr, 2, *u8);
208 try testIndex2(array[runtime_zero..].ptr, 3, *u8);
209209}
210fn testIndex(smaller: [*]align(2) u32, index: usize, comptime T: type) void {
211 comptime expect(@TypeOf(&smaller[index]) == T);
210fn testIndex(smaller: [*]align(2) u32, index: usize, comptime T: type) !void {
211 comptime try expect(@TypeOf(&smaller[index]) == T);
212212}
213fn testIndex2(ptr: [*]align(4) u8, index: usize, comptime T: type) void {
214 comptime expect(@TypeOf(&ptr[index]) == T);
213fn testIndex2(ptr: [*]align(4) u8, index: usize, comptime T: type) !void {
214 comptime try expect(@TypeOf(&ptr[index]) == T);
215215}
216216
217217test "alignstack" {
218 expect(fnWithAlignedStack() == 1234);
218 try expect(fnWithAlignedStack() == 1234);
219219}
220220
221221fn fnWithAlignedStack() i32 {
......@@ -224,7 +224,7 @@ fn fnWithAlignedStack() i32 {
224224}
225225
226226test "alignment of structs" {
227 expect(@alignOf(struct {
227 try expect(@alignOf(struct {
228228 a: i32,
229229 b: *i32,
230230 }) == @alignOf(usize));
......@@ -240,37 +240,37 @@ test "alignment of function with c calling convention" {
240240fn nothing() callconv(.C) void {}
241241
242242test "return error union with 128-bit integer" {
243 expect(3 == try give());
243 try expect(3 == try give());
244244}
245245fn give() anyerror!u128 {
246246 return 3;
247247}
248248
249249test "alignment of >= 128-bit integer type" {
250 expect(@alignOf(u128) == 16);
251 expect(@alignOf(u129) == 16);
250 try expect(@alignOf(u128) == 16);
251 try expect(@alignOf(u129) == 16);
252252}
253253
254254test "alignment of struct with 128-bit field" {
255 expect(@alignOf(struct {
255 try expect(@alignOf(struct {
256256 x: u128,
257257 }) == 16);
258258
259259 comptime {
260 expect(@alignOf(struct {
260 try expect(@alignOf(struct {
261261 x: u128,
262262 }) == 16);
263263 }
264264}
265265
266266test "size of extern struct with 128-bit field" {
267 expect(@sizeOf(extern struct {
267 try expect(@sizeOf(extern struct {
268268 x: u128,
269269 y: u8,
270270 }) == 32);
271271
272272 comptime {
273 expect(@sizeOf(extern struct {
273 try expect(@sizeOf(extern struct {
274274 x: u128,
275275 y: u8,
276276 }) == 32);
......@@ -287,8 +287,8 @@ test "read 128-bit field from default aligned struct in stack memory" {
287287 .nevermind = 1,
288288 .badguy = 12,
289289 };
290 expect((@ptrToInt(&default_aligned.badguy) % 16) == 0);
291 expect(12 == default_aligned.badguy);
290 try expect((@ptrToInt(&default_aligned.badguy) % 16) == 0);
291 try expect(12 == default_aligned.badguy);
292292}
293293
294294var default_aligned_global = DefaultAligned{
......@@ -297,8 +297,8 @@ var default_aligned_global = DefaultAligned{
297297};
298298
299299test "read 128-bit field from default aligned struct in global memory" {
300 expect((@ptrToInt(&default_aligned_global.badguy) % 16) == 0);
301 expect(12 == default_aligned_global.badguy);
300 try expect((@ptrToInt(&default_aligned_global.badguy) % 16) == 0);
301 try expect(12 == default_aligned_global.badguy);
302302}
303303
304304test "struct field explicit alignment" {
......@@ -311,9 +311,9 @@ test "struct field explicit alignment" {
311311
312312 var node: S.Node = undefined;
313313 node.massive_byte = 100;
314 expect(node.massive_byte == 100);
315 comptime expect(@TypeOf(&node.massive_byte) == *align(64) u8);
316 expect(@ptrToInt(&node.massive_byte) % 64 == 0);
314 try expect(node.massive_byte == 100);
315 comptime try expect(@TypeOf(&node.massive_byte) == *align(64) u8);
316 try expect(@ptrToInt(&node.massive_byte) % 64 == 0);
317317}
318318
319319test "align(@alignOf(T)) T does not force resolution of T" {
......@@ -335,7 +335,7 @@ test "align(@alignOf(T)) T does not force resolution of T" {
335335 var ok = false;
336336 };
337337 _ = async S.doTheTest();
338 expect(S.ok);
338 try expect(S.ok);
339339}
340340
341341test "align(N) on functions" {
......@@ -343,7 +343,7 @@ test "align(N) on functions" {
343343 if (native_arch == .wasm32 or native_arch == .wasm64) return error.SkipZigTest;
344344 if (native_arch == .thumb) return error.SkipZigTest;
345345
346 expect((@ptrToInt(overaligned_fn) & (0x1000 - 1)) == 0);
346 try expect((@ptrToInt(overaligned_fn) & (0x1000 - 1)) == 0);
347347}
348348fn overaligned_fn() align(0x1000) i32 {
349349 return 42;
test/behavior/alignof.zig+14-14
......@@ -11,29 +11,29 @@ const Foo = struct {
1111};
1212
1313test "@alignOf(T) before referencing T" {
14 comptime expect(@alignOf(Foo) != maxInt(usize));
14 comptime try expect(@alignOf(Foo) != maxInt(usize));
1515 if (native_arch == .x86_64) {
16 comptime expect(@alignOf(Foo) == 4);
16 comptime try expect(@alignOf(Foo) == 4);
1717 }
1818}
1919
2020test "comparison of @alignOf(T) against zero" {
2121 {
2222 const T = struct { x: u32 };
23 expect(!(@alignOf(T) == 0));
24 expect(@alignOf(T) != 0);
25 expect(!(@alignOf(T) < 0));
26 expect(!(@alignOf(T) <= 0));
27 expect(@alignOf(T) > 0);
28 expect(@alignOf(T) >= 0);
23 try expect(!(@alignOf(T) == 0));
24 try expect(@alignOf(T) != 0);
25 try expect(!(@alignOf(T) < 0));
26 try expect(!(@alignOf(T) <= 0));
27 try expect(@alignOf(T) > 0);
28 try expect(@alignOf(T) >= 0);
2929 }
3030 {
3131 const T = struct {};
32 expect(@alignOf(T) == 0);
33 expect(!(@alignOf(T) != 0));
34 expect(!(@alignOf(T) < 0));
35 expect(@alignOf(T) <= 0);
36 expect(!(@alignOf(T) > 0));
37 expect(@alignOf(T) >= 0);
32 try expect(@alignOf(T) == 0);
33 try expect(!(@alignOf(T) != 0));
34 try expect(!(@alignOf(T) < 0));
35 try expect(@alignOf(T) <= 0);
36 try expect(!(@alignOf(T) > 0));
37 try expect(@alignOf(T) >= 0);
3838 }
3939}
test/behavior/array.zig+141-141
......@@ -21,8 +21,8 @@ test "arrays" {
2121 i += 1;
2222 }
2323
24 expect(accumulator == 15);
25 expect(getArrayLen(&array) == 5);
24 try expect(accumulator == 15);
25 try expect(getArrayLen(&array) == 5);
2626}
2727fn getArrayLen(a: []const u32) usize {
2828 return a.len;
......@@ -30,37 +30,37 @@ fn getArrayLen(a: []const u32) usize {
3030
3131test "array with sentinels" {
3232 const S = struct {
33 fn doTheTest(is_ct: bool) void {
33 fn doTheTest(is_ct: bool) !void {
3434 if (is_ct) {
3535 var zero_sized: [0:0xde]u8 = [_:0xde]u8{};
3636 // Disabled at runtime because of
3737 // https://github.com/ziglang/zig/issues/4372
38 expectEqual(@as(u8, 0xde), zero_sized[0]);
38 try expectEqual(@as(u8, 0xde), zero_sized[0]);
3939 var reinterpreted = @ptrCast(*[1]u8, &zero_sized);
40 expectEqual(@as(u8, 0xde), reinterpreted[0]);
40 try expectEqual(@as(u8, 0xde), reinterpreted[0]);
4141 }
4242 var arr: [3:0x55]u8 = undefined;
4343 // Make sure the sentinel pointer is pointing after the last element
4444 if (!is_ct) {
4545 const sentinel_ptr = @ptrToInt(&arr[3]);
4646 const last_elem_ptr = @ptrToInt(&arr[2]);
47 expectEqual(@as(usize, 1), sentinel_ptr - last_elem_ptr);
47 try expectEqual(@as(usize, 1), sentinel_ptr - last_elem_ptr);
4848 }
4949 // Make sure the sentinel is writeable
5050 arr[3] = 0x55;
5151 }
5252 };
5353
54 S.doTheTest(false);
55 comptime S.doTheTest(true);
54 try S.doTheTest(false);
55 comptime try S.doTheTest(true);
5656}
5757
5858test "void arrays" {
5959 var array: [4]void = undefined;
6060 array[0] = void{};
6161 array[1] = array[2];
62 expect(@sizeOf(@TypeOf(array)) == 0);
63 expect(array.len == 4);
62 try expect(@sizeOf(@TypeOf(array)) == 0);
63 try expect(array.len == 4);
6464}
6565
6666test "array literal" {
......@@ -71,12 +71,12 @@ test "array literal" {
7171 1,
7272 };
7373
74 expect(hex_mult.len == 4);
75 expect(hex_mult[1] == 256);
74 try expect(hex_mult.len == 4);
75 try expect(hex_mult[1] == 256);
7676}
7777
7878test "array dot len const expr" {
79 expect(comptime x: {
79 try expect(comptime x: {
8080 break :x some_array.len == 4;
8181 });
8282}
......@@ -100,11 +100,11 @@ test "nested arrays" {
100100 "thing",
101101 };
102102 for (array_of_strings) |s, i| {
103 if (i == 0) expect(mem.eql(u8, s, "hello"));
104 if (i == 1) expect(mem.eql(u8, s, "this"));
105 if (i == 2) expect(mem.eql(u8, s, "is"));
106 if (i == 3) expect(mem.eql(u8, s, "my"));
107 if (i == 4) expect(mem.eql(u8, s, "thing"));
103 if (i == 0) try expect(mem.eql(u8, s, "hello"));
104 if (i == 1) try expect(mem.eql(u8, s, "this"));
105 if (i == 2) try expect(mem.eql(u8, s, "is"));
106 if (i == 3) try expect(mem.eql(u8, s, "my"));
107 if (i == 4) try expect(mem.eql(u8, s, "thing"));
108108 }
109109}
110110
......@@ -122,9 +122,9 @@ test "set global var array via slice embedded in struct" {
122122 s.a[1].b = 2;
123123 s.a[2].b = 3;
124124
125 expect(s_array[0].b == 1);
126 expect(s_array[1].b == 2);
127 expect(s_array[2].b == 3);
125 try expect(s_array[0].b == 1);
126 try expect(s_array[1].b == 2);
127 try expect(s_array[2].b == 3);
128128}
129129
130130test "array literal with specified size" {
......@@ -132,34 +132,34 @@ test "array literal with specified size" {
132132 1,
133133 2,
134134 };
135 expect(array[0] == 1);
136 expect(array[1] == 2);
135 try expect(array[0] == 1);
136 try expect(array[1] == 2);
137137}
138138
139139test "array len field" {
140140 var arr = [4]u8{ 0, 0, 0, 0 };
141141 var ptr = &arr;
142 expect(arr.len == 4);
143 comptime expect(arr.len == 4);
144 expect(ptr.len == 4);
145 comptime expect(ptr.len == 4);
142 try expect(arr.len == 4);
143 comptime try expect(arr.len == 4);
144 try expect(ptr.len == 4);
145 comptime try expect(ptr.len == 4);
146146}
147147
148148test "single-item pointer to array indexing and slicing" {
149 testSingleItemPtrArrayIndexSlice();
150 comptime testSingleItemPtrArrayIndexSlice();
149 try testSingleItemPtrArrayIndexSlice();
150 comptime try testSingleItemPtrArrayIndexSlice();
151151}
152152
153fn testSingleItemPtrArrayIndexSlice() void {
153fn testSingleItemPtrArrayIndexSlice() !void {
154154 {
155155 var array: [4]u8 = "aaaa".*;
156156 doSomeMangling(&array);
157 expect(mem.eql(u8, "azya", &array));
157 try expect(mem.eql(u8, "azya", &array));
158158 }
159159 {
160160 var array = "aaaa".*;
161161 doSomeMangling(&array);
162 expect(mem.eql(u8, "azya", &array));
162 try expect(mem.eql(u8, "azya", &array));
163163 }
164164}
165165
......@@ -169,15 +169,15 @@ fn doSomeMangling(array: *[4]u8) void {
169169}
170170
171171test "implicit cast single-item pointer" {
172 testImplicitCastSingleItemPtr();
173 comptime testImplicitCastSingleItemPtr();
172 try testImplicitCastSingleItemPtr();
173 comptime try testImplicitCastSingleItemPtr();
174174}
175175
176fn testImplicitCastSingleItemPtr() void {
176fn testImplicitCastSingleItemPtr() !void {
177177 var byte: u8 = 100;
178178 const slice = @as(*[1]u8, &byte)[0..];
179179 slice[0] += 1;
180 expect(byte == 101);
180 try expect(byte == 101);
181181}
182182
183183fn testArrayByValAtComptime(b: [2]u8) u8 {
......@@ -192,7 +192,7 @@ test "comptime evalutating function that takes array by value" {
192192
193193test "implicit comptime in array type size" {
194194 var arr: [plusOne(10)]bool = undefined;
195 expect(arr.len == 11);
195 try expect(arr.len == 11);
196196}
197197
198198fn plusOne(x: u32) u32 {
......@@ -202,52 +202,52 @@ fn plusOne(x: u32) u32 {
202202test "runtime initialize array elem and then implicit cast to slice" {
203203 var two: i32 = 2;
204204 const x: []const i32 = &[_]i32{two};
205 expect(x[0] == 2);
205 try expect(x[0] == 2);
206206}
207207
208208test "array literal as argument to function" {
209209 const S = struct {
210 fn entry(two: i32) void {
211 foo(&[_]i32{
210 fn entry(two: i32) !void {
211 try foo(&[_]i32{
212212 1,
213213 2,
214214 3,
215215 });
216 foo(&[_]i32{
216 try foo(&[_]i32{
217217 1,
218218 two,
219219 3,
220220 });
221 foo2(true, &[_]i32{
221 try foo2(true, &[_]i32{
222222 1,
223223 2,
224224 3,
225225 });
226 foo2(true, &[_]i32{
226 try foo2(true, &[_]i32{
227227 1,
228228 two,
229229 3,
230230 });
231231 }
232 fn foo(x: []const i32) void {
233 expect(x[0] == 1);
234 expect(x[1] == 2);
235 expect(x[2] == 3);
232 fn foo(x: []const i32) !void {
233 try expect(x[0] == 1);
234 try expect(x[1] == 2);
235 try expect(x[2] == 3);
236236 }
237 fn foo2(trash: bool, x: []const i32) void {
238 expect(trash);
239 expect(x[0] == 1);
240 expect(x[1] == 2);
241 expect(x[2] == 3);
237 fn foo2(trash: bool, x: []const i32) !void {
238 try expect(trash);
239 try expect(x[0] == 1);
240 try expect(x[1] == 2);
241 try expect(x[2] == 3);
242242 }
243243 };
244 S.entry(2);
245 comptime S.entry(2);
244 try S.entry(2);
245 comptime try S.entry(2);
246246}
247247
248248test "double nested array to const slice cast in array literal" {
249249 const S = struct {
250 fn entry(two: i32) void {
250 fn entry(two: i32) !void {
251251 const cases = [_][]const []const i32{
252252 &[_][]const i32{&[_]i32{1}},
253253 &[_][]const i32{&[_]i32{ 2, 3 }},
......@@ -256,18 +256,18 @@ test "double nested array to const slice cast in array literal" {
256256 &[_]i32{ 5, 6, 7 },
257257 },
258258 };
259 check(&cases);
259 try check(&cases);
260260
261261 const cases2 = [_][]const i32{
262262 &[_]i32{1},
263263 &[_]i32{ two, 3 },
264264 };
265 expect(cases2.len == 2);
266 expect(cases2[0].len == 1);
267 expect(cases2[0][0] == 1);
268 expect(cases2[1].len == 2);
269 expect(cases2[1][0] == 2);
270 expect(cases2[1][1] == 3);
265 try expect(cases2.len == 2);
266 try expect(cases2[0].len == 1);
267 try expect(cases2[0][0] == 1);
268 try expect(cases2[1].len == 2);
269 try expect(cases2[1][0] == 2);
270 try expect(cases2[1][1] == 3);
271271
272272 const cases3 = [_][]const []const i32{
273273 &[_][]const i32{&[_]i32{1}},
......@@ -277,37 +277,37 @@ test "double nested array to const slice cast in array literal" {
277277 &[_]i32{ 5, 6, 7 },
278278 },
279279 };
280 check(&cases3);
280 try check(&cases3);
281281 }
282282
283 fn check(cases: []const []const []const i32) void {
284 expect(cases.len == 3);
285 expect(cases[0].len == 1);
286 expect(cases[0][0].len == 1);
287 expect(cases[0][0][0] == 1);
288 expect(cases[1].len == 1);
289 expect(cases[1][0].len == 2);
290 expect(cases[1][0][0] == 2);
291 expect(cases[1][0][1] == 3);
292 expect(cases[2].len == 2);
293 expect(cases[2][0].len == 1);
294 expect(cases[2][0][0] == 4);
295 expect(cases[2][1].len == 3);
296 expect(cases[2][1][0] == 5);
297 expect(cases[2][1][1] == 6);
298 expect(cases[2][1][2] == 7);
283 fn check(cases: []const []const []const i32) !void {
284 try expect(cases.len == 3);
285 try expect(cases[0].len == 1);
286 try expect(cases[0][0].len == 1);
287 try expect(cases[0][0][0] == 1);
288 try expect(cases[1].len == 1);
289 try expect(cases[1][0].len == 2);
290 try expect(cases[1][0][0] == 2);
291 try expect(cases[1][0][1] == 3);
292 try expect(cases[2].len == 2);
293 try expect(cases[2][0].len == 1);
294 try expect(cases[2][0][0] == 4);
295 try expect(cases[2][1].len == 3);
296 try expect(cases[2][1][0] == 5);
297 try expect(cases[2][1][1] == 6);
298 try expect(cases[2][1][2] == 7);
299299 }
300300 };
301 S.entry(2);
302 comptime S.entry(2);
301 try S.entry(2);
302 comptime try S.entry(2);
303303}
304304
305305test "read/write through global variable array of struct fields initialized via array mult" {
306306 const S = struct {
307 fn doTheTest() void {
308 expect(storage[0].term == 1);
307 fn doTheTest() !void {
308 try expect(storage[0].term == 1);
309309 storage[0] = MyStruct{ .term = 123 };
310 expect(storage[0].term == 123);
310 try expect(storage[0].term == 123);
311311 }
312312
313313 pub const MyStruct = struct {
......@@ -316,34 +316,34 @@ test "read/write through global variable array of struct fields initialized via
316316
317317 var storage: [1]MyStruct = [_]MyStruct{MyStruct{ .term = 1 }} ** 1;
318318 };
319 S.doTheTest();
319 try S.doTheTest();
320320}
321321
322322test "implicit cast zero sized array ptr to slice" {
323323 {
324324 var b = "".*;
325325 const c: []const u8 = &b;
326 expect(c.len == 0);
326 try expect(c.len == 0);
327327 }
328328 {
329329 var b: [0]u8 = "".*;
330330 const c: []const u8 = &b;
331 expect(c.len == 0);
331 try expect(c.len == 0);
332332 }
333333}
334334
335335test "anonymous list literal syntax" {
336336 const S = struct {
337 fn doTheTest() void {
337 fn doTheTest() !void {
338338 var array: [4]u8 = .{ 1, 2, 3, 4 };
339 expect(array[0] == 1);
340 expect(array[1] == 2);
341 expect(array[2] == 3);
342 expect(array[3] == 4);
339 try expect(array[0] == 1);
340 try expect(array[1] == 2);
341 try expect(array[2] == 3);
342 try expect(array[3] == 4);
343343 }
344344 };
345 S.doTheTest();
346 comptime S.doTheTest();
345 try S.doTheTest();
346 comptime try S.doTheTest();
347347}
348348
349349test "anonymous literal in array" {
......@@ -352,51 +352,51 @@ test "anonymous literal in array" {
352352 a: usize = 2,
353353 b: usize = 4,
354354 };
355 fn doTheTest() void {
355 fn doTheTest() !void {
356356 var array: [2]Foo = .{
357357 .{ .a = 3 },
358358 .{ .b = 3 },
359359 };
360 expect(array[0].a == 3);
361 expect(array[0].b == 4);
362 expect(array[1].a == 2);
363 expect(array[1].b == 3);
360 try expect(array[0].a == 3);
361 try expect(array[0].b == 4);
362 try expect(array[1].a == 2);
363 try expect(array[1].b == 3);
364364 }
365365 };
366 S.doTheTest();
367 comptime S.doTheTest();
366 try S.doTheTest();
367 comptime try S.doTheTest();
368368}
369369
370370test "access the null element of a null terminated array" {
371371 const S = struct {
372 fn doTheTest() void {
372 fn doTheTest() !void {
373373 var array: [4:0]u8 = .{ 'a', 'o', 'e', 'u' };
374 expect(array[4] == 0);
374 try expect(array[4] == 0);
375375 var len: usize = 4;
376 expect(array[len] == 0);
376 try expect(array[len] == 0);
377377 }
378378 };
379 S.doTheTest();
380 comptime S.doTheTest();
379 try S.doTheTest();
380 comptime try S.doTheTest();
381381}
382382
383383test "type deduction for array subscript expression" {
384384 const S = struct {
385 fn doTheTest() void {
385 fn doTheTest() !void {
386386 var array = [_]u8{ 0x55, 0xAA };
387387 var v0 = true;
388 expectEqual(@as(u8, 0xAA), array[if (v0) 1 else 0]);
388 try expectEqual(@as(u8, 0xAA), array[if (v0) 1 else 0]);
389389 var v1 = false;
390 expectEqual(@as(u8, 0x55), array[if (v1) 1 else 0]);
390 try expectEqual(@as(u8, 0x55), array[if (v1) 1 else 0]);
391391 }
392392 };
393 S.doTheTest();
394 comptime S.doTheTest();
393 try S.doTheTest();
394 comptime try S.doTheTest();
395395}
396396
397397test "sentinel element count towards the ABI size calculation" {
398398 const S = struct {
399 fn doTheTest() void {
399 fn doTheTest() !void {
400400 const T = packed struct {
401401 fill_pre: u8 = 0x55,
402402 data: [0:0]u8 = undefined,
......@@ -404,14 +404,14 @@ test "sentinel element count towards the ABI size calculation" {
404404 };
405405 var x = T{};
406406 var as_slice = mem.asBytes(&x);
407 expectEqual(@as(usize, 3), as_slice.len);
408 expectEqual(@as(u8, 0x55), as_slice[0]);
409 expectEqual(@as(u8, 0xAA), as_slice[2]);
407 try expectEqual(@as(usize, 3), as_slice.len);
408 try expectEqual(@as(u8, 0x55), as_slice[0]);
409 try expectEqual(@as(u8, 0xAA), as_slice[2]);
410410 }
411411 };
412412
413 S.doTheTest();
414 comptime S.doTheTest();
413 try S.doTheTest();
414 comptime try S.doTheTest();
415415}
416416
417417test "zero-sized array with recursive type definition" {
......@@ -429,61 +429,61 @@ test "zero-sized array with recursive type definition" {
429429 };
430430
431431 var t: S = .{ .list = .{ .s = undefined } };
432 expectEqual(@as(usize, 0), t.list.x);
432 try expectEqual(@as(usize, 0), t.list.x);
433433}
434434
435435test "type coercion of anon struct literal to array" {
436436 const S = struct {
437 const U = union{
437 const U = union {
438438 a: u32,
439439 b: bool,
440440 c: []const u8,
441441 };
442442
443 fn doTheTest() void {
443 fn doTheTest() !void {
444444 var x1: u8 = 42;
445445 const t1 = .{ x1, 56, 54 };
446446 var arr1: [3]u8 = t1;
447 expect(arr1[0] == 42);
448 expect(arr1[1] == 56);
449 expect(arr1[2] == 54);
450
447 try expect(arr1[0] == 42);
448 try expect(arr1[1] == 56);
449 try expect(arr1[2] == 54);
450
451451 var x2: U = .{ .a = 42 };
452452 const t2 = .{ x2, .{ .b = true }, .{ .c = "hello" } };
453453 var arr2: [3]U = t2;
454 expect(arr2[0].a == 42);
455 expect(arr2[1].b == true);
456 expect(mem.eql(u8, arr2[2].c, "hello"));
454 try expect(arr2[0].a == 42);
455 try expect(arr2[1].b == true);
456 try expect(mem.eql(u8, arr2[2].c, "hello"));
457457 }
458458 };
459 S.doTheTest();
460 comptime S.doTheTest();
459 try S.doTheTest();
460 comptime try S.doTheTest();
461461}
462462
463463test "type coercion of pointer to anon struct literal to pointer to array" {
464464 const S = struct {
465 const U = union{
465 const U = union {
466466 a: u32,
467467 b: bool,
468468 c: []const u8,
469469 };
470470
471 fn doTheTest() void {
471 fn doTheTest() !void {
472472 var x1: u8 = 42;
473473 const t1 = &.{ x1, 56, 54 };
474 var arr1: *const[3]u8 = t1;
475 expect(arr1[0] == 42);
476 expect(arr1[1] == 56);
477 expect(arr1[2] == 54);
478
474 var arr1: *const [3]u8 = t1;
475 try expect(arr1[0] == 42);
476 try expect(arr1[1] == 56);
477 try expect(arr1[2] == 54);
478
479479 var x2: U = .{ .a = 42 };
480480 const t2 = &.{ x2, .{ .b = true }, .{ .c = "hello" } };
481481 var arr2: *const [3]U = t2;
482 expect(arr2[0].a == 42);
483 expect(arr2[1].b == true);
484 expect(mem.eql(u8, arr2[2].c, "hello"));
482 try expect(arr2[0].a == 42);
483 try expect(arr2[1].b == true);
484 try expect(mem.eql(u8, arr2[2].c, "hello"));
485485 }
486486 };
487 S.doTheTest();
488 comptime S.doTheTest();
487 try S.doTheTest();
488 comptime try S.doTheTest();
489489}
test/behavior/asm.zig+1-1
......@@ -15,7 +15,7 @@ comptime {
1515
1616test "module level assembly" {
1717 if (is_x86_64_linux) {
18 expect(this_is_my_alias() == 1234);
18 try expect(this_is_my_alias() == 1234);
1919 }
2020}
2121
test/behavior/async_fn.zig+165-165
......@@ -9,12 +9,12 @@ var global_x: i32 = 1;
99
1010test "simple coroutine suspend and resume" {
1111 var frame = async simpleAsyncFn();
12 expect(global_x == 2);
12 try expect(global_x == 2);
1313 resume frame;
14 expect(global_x == 3);
14 try expect(global_x == 3);
1515 const af: anyframe->void = &frame;
1616 resume frame;
17 expect(global_x == 4);
17 try expect(global_x == 4);
1818}
1919fn simpleAsyncFn() void {
2020 global_x += 1;
......@@ -28,9 +28,9 @@ var global_y: i32 = 1;
2828
2929test "pass parameter to coroutine" {
3030 var p = async simpleAsyncFnWithArg(2);
31 expect(global_y == 3);
31 try expect(global_y == 3);
3232 resume p;
33 expect(global_y == 5);
33 try expect(global_y == 5);
3434}
3535fn simpleAsyncFnWithArg(delta: i32) void {
3636 global_y += delta;
......@@ -42,10 +42,10 @@ test "suspend at end of function" {
4242 const S = struct {
4343 var x: i32 = 1;
4444
45 fn doTheTest() void {
46 expect(x == 1);
45 fn doTheTest() !void {
46 try expect(x == 1);
4747 const p = async suspendAtEnd();
48 expect(x == 2);
48 try expect(x == 2);
4949 }
5050
5151 fn suspendAtEnd() void {
......@@ -53,23 +53,23 @@ test "suspend at end of function" {
5353 suspend {}
5454 }
5555 };
56 S.doTheTest();
56 try S.doTheTest();
5757}
5858
5959test "local variable in async function" {
6060 const S = struct {
6161 var x: i32 = 0;
6262
63 fn doTheTest() void {
64 expect(x == 0);
63 fn doTheTest() !void {
64 try expect(x == 0);
6565 var p = async add(1, 2);
66 expect(x == 0);
66 try expect(x == 0);
6767 resume p;
68 expect(x == 0);
68 try expect(x == 0);
6969 resume p;
70 expect(x == 0);
70 try expect(x == 0);
7171 resume p;
72 expect(x == 3);
72 try expect(x == 3);
7373 }
7474
7575 fn add(a: i32, b: i32) void {
......@@ -82,7 +82,7 @@ test "local variable in async function" {
8282 x = accum;
8383 }
8484 };
85 S.doTheTest();
85 try S.doTheTest();
8686}
8787
8888test "calling an inferred async function" {
......@@ -90,11 +90,11 @@ test "calling an inferred async function" {
9090 var x: i32 = 1;
9191 var other_frame: *@Frame(other) = undefined;
9292
93 fn doTheTest() void {
93 fn doTheTest() !void {
9494 _ = async first();
95 expect(x == 1);
95 try expect(x == 1);
9696 resume other_frame.*;
97 expect(x == 2);
97 try expect(x == 2);
9898 }
9999
100100 fn first() void {
......@@ -106,7 +106,7 @@ test "calling an inferred async function" {
106106 x += 1;
107107 }
108108 };
109 S.doTheTest();
109 try S.doTheTest();
110110}
111111
112112test "@frameSize" {
......@@ -114,16 +114,16 @@ test "@frameSize" {
114114 return error.SkipZigTest;
115115
116116 const S = struct {
117 fn doTheTest() void {
117 fn doTheTest() !void {
118118 {
119119 var ptr = @ptrCast(fn (i32) callconv(.Async) void, other);
120120 const size = @frameSize(ptr);
121 expect(size == @sizeOf(@Frame(other)));
121 try expect(size == @sizeOf(@Frame(other)));
122122 }
123123 {
124124 var ptr = @ptrCast(fn () callconv(.Async) void, first);
125125 const size = @frameSize(ptr);
126 expect(size == @sizeOf(@Frame(first)));
126 try expect(size == @sizeOf(@Frame(first)));
127127 }
128128 }
129129
......@@ -135,20 +135,20 @@ test "@frameSize" {
135135 suspend {}
136136 }
137137 };
138 S.doTheTest();
138 try S.doTheTest();
139139}
140140
141141test "coroutine suspend, resume" {
142142 const S = struct {
143143 var frame: anyframe = undefined;
144144
145 fn doTheTest() void {
145 fn doTheTest() !void {
146146 _ = async amain();
147147 seq('d');
148148 resume frame;
149149 seq('h');
150150
151 expect(std.mem.eql(u8, &points, "abcdefgh"));
151 try expect(std.mem.eql(u8, &points, "abcdefgh"));
152152 }
153153
154154 fn amain() void {
......@@ -176,27 +176,27 @@ test "coroutine suspend, resume" {
176176 index += 1;
177177 }
178178 };
179 S.doTheTest();
179 try S.doTheTest();
180180}
181181
182182test "coroutine suspend with block" {
183183 const p = async testSuspendBlock();
184 expect(!global_result);
184 try expect(!global_result);
185185 resume a_promise;
186 expect(global_result);
186 try expect(global_result);
187187}
188188
189189var a_promise: anyframe = undefined;
190190var global_result = false;
191191fn testSuspendBlock() callconv(.Async) void {
192192 suspend {
193 comptime expect(@TypeOf(@frame()) == *@Frame(testSuspendBlock));
193 comptime expect(@TypeOf(@frame()) == *@Frame(testSuspendBlock)) catch unreachable;
194194 a_promise = @frame();
195195 }
196196
197197 // Test to make sure that @frame() works as advertised (issue #1296)
198198 // var our_handle: anyframe = @frame();
199 expect(a_promise == @as(anyframe, @frame()));
199 expect(a_promise == @as(anyframe, @frame())) catch @panic("test failed");
200200
201201 global_result = true;
202202}
......@@ -210,8 +210,8 @@ test "coroutine await" {
210210 await_seq('f');
211211 resume await_a_promise;
212212 await_seq('i');
213 expect(await_final_result == 1234);
214 expect(std.mem.eql(u8, &await_points, "abcdefghi"));
213 try expect(await_final_result == 1234);
214 try expect(std.mem.eql(u8, &await_points, "abcdefghi"));
215215}
216216fn await_amain() callconv(.Async) void {
217217 await_seq('b');
......@@ -244,8 +244,8 @@ test "coroutine await early return" {
244244 early_seq('a');
245245 var p = async early_amain();
246246 early_seq('f');
247 expect(early_final_result == 1234);
248 expect(std.mem.eql(u8, &early_points, "abcdef"));
247 try expect(early_final_result == 1234);
248 try expect(std.mem.eql(u8, &early_points, "abcdef"));
249249}
250250fn early_amain() callconv(.Async) void {
251251 early_seq('b');
......@@ -276,7 +276,7 @@ test "async function with dot syntax" {
276276 }
277277 };
278278 const p = async S.foo();
279 expect(S.y == 2);
279 try expect(S.y == 2);
280280}
281281
282282test "async fn pointer in a struct field" {
......@@ -287,12 +287,12 @@ test "async fn pointer in a struct field" {
287287 var foo = Foo{ .bar = simpleAsyncFn2 };
288288 var bytes: [64]u8 align(16) = undefined;
289289 const f = @asyncCall(&bytes, {}, foo.bar, .{&data});
290 comptime expect(@TypeOf(f) == anyframe->void);
291 expect(data == 2);
290 comptime try expect(@TypeOf(f) == anyframe->void);
291 try expect(data == 2);
292292 resume f;
293 expect(data == 4);
293 try expect(data == 4);
294294 _ = async doTheAwait(f);
295 expect(data == 4);
295 try expect(data == 4);
296296}
297297
298298fn doTheAwait(f: anyframe->void) void {
......@@ -323,22 +323,22 @@ test "@asyncCall with return type" {
323323 var bytes: [150]u8 align(16) = undefined;
324324 var aresult: i32 = 0;
325325 _ = @asyncCall(&bytes, &aresult, foo.bar, .{});
326 expect(aresult == 0);
326 try expect(aresult == 0);
327327 resume Foo.global_frame;
328 expect(aresult == 1234);
328 try expect(aresult == 1234);
329329}
330330
331331test "async fn with inferred error set" {
332332 const S = struct {
333333 var global_frame: anyframe = undefined;
334334
335 fn doTheTest() void {
335 fn doTheTest() !void {
336336 var frame: [1]@Frame(middle) = undefined;
337337 var fn_ptr = middle;
338338 var result: @typeInfo(@typeInfo(@TypeOf(fn_ptr)).Fn.return_type.?).ErrorUnion.error_set!void = undefined;
339339 _ = @asyncCall(std.mem.sliceAsBytes(frame[0..]), &result, fn_ptr, .{});
340340 resume global_frame;
341 std.testing.expectError(error.Fail, result);
341 try std.testing.expectError(error.Fail, result);
342342 }
343343 fn middle() callconv(.Async) !void {
344344 var f = async middle2();
......@@ -355,7 +355,7 @@ test "async fn with inferred error set" {
355355 return error.Fail;
356356 }
357357 };
358 S.doTheTest();
358 try S.doTheTest();
359359}
360360
361361test "error return trace across suspend points - early return" {
......@@ -383,9 +383,9 @@ fn suspendThenFail() callconv(.Async) anyerror!void {
383383}
384384fn printTrace(p: anyframe->(anyerror!void)) callconv(.Async) void {
385385 (await p) catch |e| {
386 std.testing.expect(e == error.Fail);
386 std.testing.expect(e == error.Fail) catch @panic("test failure");
387387 if (@errorReturnTrace()) |trace| {
388 expect(trace.index == 1);
388 expect(trace.index == 1) catch @panic("test failure");
389389 } else switch (builtin.mode) {
390390 .Debug, .ReleaseSafe => @panic("expected return trace"),
391391 .ReleaseFast, .ReleaseSmall => {},
......@@ -396,7 +396,7 @@ fn printTrace(p: anyframe->(anyerror!void)) callconv(.Async) void {
396396test "break from suspend" {
397397 var my_result: i32 = 1;
398398 const p = async testBreakFromSuspend(&my_result);
399 std.testing.expect(my_result == 2);
399 try std.testing.expect(my_result == 2);
400400}
401401fn testBreakFromSuspend(my_result: *i32) callconv(.Async) void {
402402 suspend {
......@@ -415,11 +415,11 @@ test "heap allocated async function frame" {
415415 const frame = try std.testing.allocator.create(@Frame(someFunc));
416416 defer std.testing.allocator.destroy(frame);
417417
418 expect(x == 42);
418 try expect(x == 42);
419419 frame.* = async someFunc();
420 expect(x == 43);
420 try expect(x == 43);
421421 resume frame;
422 expect(x == 44);
422 try expect(x == 44);
423423 }
424424
425425 fn someFunc() void {
......@@ -436,15 +436,15 @@ test "async function call return value" {
436436 var frame: anyframe = undefined;
437437 var pt = Point{ .x = 10, .y = 11 };
438438
439 fn doTheTest() void {
440 expectEqual(pt.x, 10);
441 expectEqual(pt.y, 11);
439 fn doTheTest() !void {
440 try expectEqual(pt.x, 10);
441 try expectEqual(pt.y, 11);
442442 _ = async first();
443 expectEqual(pt.x, 10);
444 expectEqual(pt.y, 11);
443 try expectEqual(pt.x, 10);
444 try expectEqual(pt.y, 11);
445445 resume frame;
446 expectEqual(pt.x, 1);
447 expectEqual(pt.y, 2);
446 try expectEqual(pt.x, 1);
447 try expectEqual(pt.y, 2);
448448 }
449449
450450 fn first() void {
......@@ -469,23 +469,23 @@ test "async function call return value" {
469469 y: i32,
470470 };
471471 };
472 S.doTheTest();
472 try S.doTheTest();
473473}
474474
475475test "suspension points inside branching control flow" {
476476 const S = struct {
477477 var result: i32 = 10;
478478
479 fn doTheTest() void {
480 expect(10 == result);
479 fn doTheTest() !void {
480 try expect(10 == result);
481481 var frame = async func(true);
482 expect(10 == result);
482 try expect(10 == result);
483483 resume frame;
484 expect(11 == result);
484 try expect(11 == result);
485485 resume frame;
486 expect(12 == result);
486 try expect(12 == result);
487487 resume frame;
488 expect(13 == result);
488 try expect(13 == result);
489489 }
490490
491491 fn func(b: bool) void {
......@@ -495,7 +495,7 @@ test "suspension points inside branching control flow" {
495495 }
496496 }
497497 };
498 S.doTheTest();
498 try S.doTheTest();
499499}
500500
501501test "call async function which has struct return type" {
......@@ -509,8 +509,8 @@ test "call async function which has struct return type" {
509509
510510 fn atest() void {
511511 const result = func();
512 expect(result.x == 5);
513 expect(result.y == 6);
512 expect(result.x == 5) catch @panic("test failed");
513 expect(result.y == 6) catch @panic("test failed");
514514 }
515515
516516 const Point = struct {
......@@ -536,27 +536,27 @@ test "pass string literal to async function" {
536536 var frame: anyframe = undefined;
537537 var ok: bool = false;
538538
539 fn doTheTest() void {
539 fn doTheTest() !void {
540540 _ = async hello("hello");
541541 resume frame;
542 expect(ok);
542 try expect(ok);
543543 }
544544
545545 fn hello(msg: []const u8) void {
546546 frame = @frame();
547547 suspend {}
548 expectEqualStrings("hello", msg);
548 expectEqualStrings("hello", msg) catch @panic("test failed");
549549 ok = true;
550550 }
551551 };
552 S.doTheTest();
552 try S.doTheTest();
553553}
554554
555555test "await inside an errdefer" {
556556 const S = struct {
557557 var frame: anyframe = undefined;
558558
559 fn doTheTest() void {
559 fn doTheTest() !void {
560560 _ = async amainWrap();
561561 resume frame;
562562 }
......@@ -572,7 +572,7 @@ test "await inside an errdefer" {
572572 suspend {}
573573 }
574574 };
575 S.doTheTest();
575 try S.doTheTest();
576576}
577577
578578test "try in an async function with error union and non-zero-bit payload" {
......@@ -580,14 +580,14 @@ test "try in an async function with error union and non-zero-bit payload" {
580580 var frame: anyframe = undefined;
581581 var ok = false;
582582
583 fn doTheTest() void {
583 fn doTheTest() !void {
584584 _ = async amain();
585585 resume frame;
586 expect(ok);
586 try expect(ok);
587587 }
588588
589589 fn amain() void {
590 std.testing.expectError(error.Bad, theProblem());
590 std.testing.expectError(error.Bad, theProblem()) catch @panic("test failed");
591591 ok = true;
592592 }
593593
......@@ -602,7 +602,7 @@ test "try in an async function with error union and non-zero-bit payload" {
602602 return error.Bad;
603603 }
604604 };
605 S.doTheTest();
605 try S.doTheTest();
606606}
607607
608608test "returning a const error from async function" {
......@@ -610,10 +610,10 @@ test "returning a const error from async function" {
610610 var frame: anyframe = undefined;
611611 var ok = false;
612612
613 fn doTheTest() void {
613 fn doTheTest() !void {
614614 _ = async amain();
615615 resume frame;
616 expect(ok);
616 try expect(ok);
617617 }
618618
619619 fn amain() !void {
......@@ -630,7 +630,7 @@ test "returning a const error from async function" {
630630 return error.OutOfMemory;
631631 }
632632 };
633 S.doTheTest();
633 try S.doTheTest();
634634}
635635
636636test "async/await typical usage" {
......@@ -663,11 +663,11 @@ fn testAsyncAwaitTypicalUsage(
663663 }
664664 fn amainWrap() void {
665665 if (amain()) |_| {
666 expect(!simulate_fail_download);
667 expect(!simulate_fail_file);
666 expect(!simulate_fail_download) catch @panic("test failure");
667 expect(!simulate_fail_file) catch @panic("test failure");
668668 } else |e| switch (e) {
669 error.NoResponse => expect(simulate_fail_download),
670 error.FileNotFound => expect(simulate_fail_file),
669 error.NoResponse => expect(simulate_fail_download) catch @panic("test failure"),
670 error.FileNotFound => expect(simulate_fail_file) catch @panic("test failure"),
671671 else => @panic("test failure"),
672672 }
673673 }
......@@ -694,8 +694,8 @@ fn testAsyncAwaitTypicalUsage(
694694 const file_text = try await file_frame;
695695 defer allocator.free(file_text);
696696
697 expect(std.mem.eql(u8, "expected download text", download_text));
698 expect(std.mem.eql(u8, "expected file text", file_text));
697 try expect(std.mem.eql(u8, "expected download text", download_text));
698 try expect(std.mem.eql(u8, "expected file text", file_text));
699699 }
700700
701701 var global_download_frame: anyframe = undefined;
......@@ -728,13 +728,13 @@ fn testAsyncAwaitTypicalUsage(
728728
729729test "alignment of local variables in async functions" {
730730 const S = struct {
731 fn doTheTest() void {
731 fn doTheTest() !void {
732732 var y: u8 = 123;
733733 var x: u8 align(128) = 1;
734 expect(@ptrToInt(&x) % 128 == 0);
734 try expect(@ptrToInt(&x) % 128 == 0);
735735 }
736736 };
737 S.doTheTest();
737 try S.doTheTest();
738738}
739739
740740test "no reason to resolve frame still works" {
......@@ -746,10 +746,10 @@ fn simpleNothing() void {
746746
747747test "async call a generic function" {
748748 const S = struct {
749 fn doTheTest() void {
749 fn doTheTest() !void {
750750 var f = async func(i32, 2);
751751 const result = await f;
752 expect(result == 3);
752 try expect(result == 3);
753753 }
754754
755755 fn func(comptime T: type, inc: T) T {
......@@ -766,8 +766,8 @@ test "async call a generic function" {
766766
767767test "return from suspend block" {
768768 const S = struct {
769 fn doTheTest() void {
770 expect(func() == 1234);
769 fn doTheTest() !void {
770 expect(func() == 1234) catch @panic("test failure");
771771 }
772772 fn func() i32 {
773773 suspend {
......@@ -808,7 +808,7 @@ test "struct parameter to async function is copied to the frame" {
808808 var pt = Point{ .x = 1, .y = 2 };
809809 f.* = async foo(pt);
810810 var result = await f;
811 expect(result == 1);
811 expect(result == 1) catch @panic("test failure");
812812 }
813813
814814 fn foo(point: Point) i32 {
......@@ -833,7 +833,7 @@ test "cast fn to async fn when it is inferred to be async" {
833833 var result: i32 = undefined;
834834 const f = @asyncCall(&buf, &result, ptr, .{});
835835 _ = await f;
836 expect(result == 1234);
836 expect(result == 1234) catch @panic("test failure");
837837 ok = true;
838838 }
839839
......@@ -846,7 +846,7 @@ test "cast fn to async fn when it is inferred to be async" {
846846 };
847847 _ = async S.doTheTest();
848848 resume S.frame;
849 expect(S.ok);
849 try expect(S.ok);
850850}
851851
852852test "cast fn to async fn when it is inferred to be async, awaited directly" {
......@@ -860,7 +860,7 @@ test "cast fn to async fn when it is inferred to be async, awaited directly" {
860860 var buf: [100]u8 align(16) = undefined;
861861 var result: i32 = undefined;
862862 _ = await @asyncCall(&buf, &result, ptr, .{});
863 expect(result == 1234);
863 expect(result == 1234) catch @panic("test failure");
864864 ok = true;
865865 }
866866
......@@ -873,7 +873,7 @@ test "cast fn to async fn when it is inferred to be async, awaited directly" {
873873 };
874874 _ = async S.doTheTest();
875875 resume S.frame;
876 expect(S.ok);
876 try expect(S.ok);
877877}
878878
879879test "await does not force async if callee is blocking" {
......@@ -883,12 +883,12 @@ test "await does not force async if callee is blocking" {
883883 }
884884 };
885885 var x = async S.simple();
886 expect(await x == 1234);
886 try expect(await x == 1234);
887887}
888888
889889test "recursive async function" {
890 expect(recursiveAsyncFunctionTest(false).doTheTest() == 55);
891 expect(recursiveAsyncFunctionTest(true).doTheTest() == 55);
890 try expect(recursiveAsyncFunctionTest(false).doTheTest() == 55);
891 try expect(recursiveAsyncFunctionTest(true).doTheTest() == 55);
892892}
893893
894894fn recursiveAsyncFunctionTest(comptime suspending_implementation: bool) type {
......@@ -952,12 +952,12 @@ test "@asyncCall with comptime-known function, but not awaited directly" {
952952 const S = struct {
953953 var global_frame: anyframe = undefined;
954954
955 fn doTheTest() void {
955 fn doTheTest() !void {
956956 var frame: [1]@Frame(middle) = undefined;
957957 var result: @typeInfo(@typeInfo(@TypeOf(middle)).Fn.return_type.?).ErrorUnion.error_set!void = undefined;
958958 _ = @asyncCall(std.mem.sliceAsBytes(frame[0..]), &result, middle, .{});
959959 resume global_frame;
960 std.testing.expectError(error.Fail, result);
960 try std.testing.expectError(error.Fail, result);
961961 }
962962 fn middle() callconv(.Async) !void {
963963 var f = async middle2();
......@@ -974,7 +974,7 @@ test "@asyncCall with comptime-known function, but not awaited directly" {
974974 return error.Fail;
975975 }
976976 };
977 S.doTheTest();
977 try S.doTheTest();
978978}
979979
980980test "@asyncCall with actual frame instead of byte buffer" {
......@@ -988,7 +988,7 @@ test "@asyncCall with actual frame instead of byte buffer" {
988988 var result: i32 = undefined;
989989 const ptr = @asyncCall(&frame, &result, S.func, .{});
990990 resume ptr;
991 expect(result == 1234);
991 try expect(result == 1234);
992992}
993993
994994test "@asyncCall using the result location inside the frame" {
......@@ -1010,19 +1010,19 @@ test "@asyncCall using the result location inside the frame" {
10101010 var foo = Foo{ .bar = S.simple2 };
10111011 var bytes: [64]u8 align(16) = undefined;
10121012 const f = @asyncCall(&bytes, {}, foo.bar, .{&data});
1013 comptime expect(@TypeOf(f) == anyframe->i32);
1014 expect(data == 2);
1013 comptime try expect(@TypeOf(f) == anyframe->i32);
1014 try expect(data == 2);
10151015 resume f;
1016 expect(data == 4);
1016 try expect(data == 4);
10171017 _ = async S.getAnswer(f, &data);
1018 expect(data == 1234);
1018 try expect(data == 1234);
10191019}
10201020
10211021test "@TypeOf an async function call of generic fn with error union type" {
10221022 const S = struct {
10231023 fn func(comptime x: anytype) anyerror!i32 {
10241024 const T = @TypeOf(async func(x));
1025 comptime expect(T == @typeInfo(@TypeOf(@frame())).Pointer.child);
1025 comptime try expect(T == @typeInfo(@TypeOf(@frame())).Pointer.child);
10261026 return undefined;
10271027 }
10281028 };
......@@ -1051,7 +1051,7 @@ test "using @TypeOf on a generic function call" {
10511051 };
10521052 _ = async S.amain(@as(u32, 1));
10531053 resume S.global_frame;
1054 expect(S.global_ok);
1054 try expect(S.global_ok);
10551055}
10561056
10571057test "recursive call of await @asyncCall with struct return type" {
......@@ -1084,17 +1084,17 @@ test "recursive call of await @asyncCall with struct return type" {
10841084 var frame: @TypeOf(async S.amain(@as(u32, 1))) = undefined;
10851085 _ = @asyncCall(&frame, &res, S.amain, .{@as(u32, 1)});
10861086 resume S.global_frame;
1087 expect(S.global_ok);
1088 expect(res.x == 1);
1089 expect(res.y == 2);
1090 expect(res.z == 3);
1087 try expect(S.global_ok);
1088 try expect(res.x == 1);
1089 try expect(res.y == 2);
1090 try expect(res.z == 3);
10911091}
10921092
10931093test "nosuspend function call" {
10941094 const S = struct {
1095 fn doTheTest() void {
1095 fn doTheTest() !void {
10961096 const result = nosuspend add(50, 100);
1097 expect(result == 150);
1097 try expect(result == 150);
10981098 }
10991099 fn add(a: i32, b: i32) i32 {
11001100 if (a > 100) {
......@@ -1103,7 +1103,7 @@ test "nosuspend function call" {
11031103 return a + b;
11041104 }
11051105 };
1106 S.doTheTest();
1106 try S.doTheTest();
11071107}
11081108
11091109test "await used in expression and awaiting fn with no suspend but async calling convention" {
......@@ -1113,7 +1113,7 @@ test "await used in expression and awaiting fn with no suspend but async calling
11131113 var f2 = async add(3, 4);
11141114
11151115 const sum = (await f1) + (await f2);
1116 expect(sum == 10);
1116 expect(sum == 10) catch @panic("test failure");
11171117 }
11181118 fn add(a: i32, b: i32) callconv(.Async) i32 {
11191119 return a + b;
......@@ -1128,7 +1128,7 @@ test "await used in expression after a fn call" {
11281128 var f1 = async add(3, 4);
11291129 var sum: i32 = 0;
11301130 sum = foo() + await f1;
1131 expect(sum == 8);
1131 expect(sum == 8) catch @panic("test failure");
11321132 }
11331133 fn add(a: i32, b: i32) callconv(.Async) i32 {
11341134 return a + b;
......@@ -1145,7 +1145,7 @@ test "async fn call used in expression after a fn call" {
11451145 fn atest() void {
11461146 var sum: i32 = 0;
11471147 sum = foo() + add(3, 4);
1148 expect(sum == 8);
1148 expect(sum == 8) catch @panic("test failure");
11491149 }
11501150 fn add(a: i32, b: i32) callconv(.Async) i32 {
11511151 return a + b;
......@@ -1167,7 +1167,7 @@ test "suspend in for loop" {
11671167 }
11681168
11691169 fn atest() void {
1170 expect(func(&[_]u8{ 1, 2, 3 }) == 6);
1170 expect(func(&[_]u8{ 1, 2, 3 }) == 6) catch @panic("test failure");
11711171 }
11721172 fn func(stuff: []const u8) u32 {
11731173 global_frame = @frame();
......@@ -1193,8 +1193,8 @@ test "suspend in while loop" {
11931193 }
11941194
11951195 fn atest() void {
1196 expect(optional(6) == 6);
1197 expect(errunion(6) == 6);
1196 expect(optional(6) == 6) catch @panic("test failure");
1197 expect(errunion(6) == 6) catch @panic("test failure");
11981198 }
11991199 fn optional(stuff: ?u32) u32 {
12001200 global_frame = @frame();
......@@ -1223,8 +1223,8 @@ test "correctly spill when returning the error union result of another async fn"
12231223 const S = struct {
12241224 var global_frame: anyframe = undefined;
12251225
1226 fn doTheTest() void {
1227 expect((atest() catch unreachable) == 1234);
1226 fn doTheTest() !void {
1227 expect((atest() catch unreachable) == 1234) catch @panic("test failure");
12281228 }
12291229
12301230 fn atest() !i32 {
......@@ -1246,11 +1246,11 @@ test "spill target expr in a for loop" {
12461246 const S = struct {
12471247 var global_frame: anyframe = undefined;
12481248
1249 fn doTheTest() void {
1249 fn doTheTest() !void {
12501250 var foo = Foo{
12511251 .slice = &[_]i32{ 1, 2 },
12521252 };
1253 expect(atest(&foo) == 3);
1253 expect(atest(&foo) == 3) catch @panic("test failure");
12541254 }
12551255
12561256 const Foo = struct {
......@@ -1277,11 +1277,11 @@ test "spill target expr in a for loop, with a var decl in the loop body" {
12771277 const S = struct {
12781278 var global_frame: anyframe = undefined;
12791279
1280 fn doTheTest() void {
1280 fn doTheTest() !void {
12811281 var foo = Foo{
12821282 .slice = &[_]i32{ 1, 2 },
12831283 };
1284 expect(atest(&foo) == 3);
1284 expect(atest(&foo) == 3) catch @panic("test failure");
12851285 }
12861286
12871287 const Foo = struct {
......@@ -1319,7 +1319,7 @@ test "async call with @call" {
13191319 fn atest() void {
13201320 var frame = @call(.{ .modifier = .async_kw }, afoo, .{});
13211321 const res = await frame;
1322 expect(res == 42);
1322 expect(res == 42) catch @panic("test failure");
13231323 }
13241324 fn afoo() i32 {
13251325 suspend {
......@@ -1348,7 +1348,7 @@ test "async function passed 0-bit arg after non-0-bit arg" {
13481348 };
13491349 _ = async S.foo();
13501350 resume S.global_frame;
1351 expect(S.global_int == 1);
1351 try expect(S.global_int == 1);
13521352}
13531353
13541354test "async function passed align(16) arg after align(8) arg" {
......@@ -1362,7 +1362,7 @@ test "async function passed align(16) arg after align(8) arg" {
13621362 }
13631363
13641364 fn bar(x: u64, args: anytype) anyerror!void {
1365 expect(x == 10);
1365 try expect(x == 10);
13661366 global_frame = @frame();
13671367 suspend {}
13681368 global_int = args[0];
......@@ -1370,7 +1370,7 @@ test "async function passed align(16) arg after align(8) arg" {
13701370 };
13711371 _ = async S.foo();
13721372 resume S.global_frame;
1373 expect(S.global_int == 99);
1373 try expect(S.global_int == 99);
13741374}
13751375
13761376test "async function call resolves target fn frame, comptime func" {
......@@ -1392,7 +1392,7 @@ test "async function call resolves target fn frame, comptime func" {
13921392 };
13931393 _ = async S.foo();
13941394 resume S.global_frame;
1395 expect(S.global_int == 10);
1395 try expect(S.global_int == 10);
13961396}
13971397
13981398test "async function call resolves target fn frame, runtime func" {
......@@ -1415,7 +1415,7 @@ test "async function call resolves target fn frame, runtime func" {
14151415 };
14161416 _ = async S.foo();
14171417 resume S.global_frame;
1418 expect(S.global_int == 10);
1418 try expect(S.global_int == 10);
14191419}
14201420
14211421test "properly spill optional payload capture value" {
......@@ -1439,7 +1439,7 @@ test "properly spill optional payload capture value" {
14391439 };
14401440 _ = async S.foo();
14411441 resume S.global_frame;
1442 expect(S.global_int == 1237);
1442 try expect(S.global_int == 1237);
14431443}
14441444
14451445test "handle defer interfering with return value spill" {
......@@ -1449,16 +1449,16 @@ test "handle defer interfering with return value spill" {
14491449 var finished = false;
14501450 var baz_happened = false;
14511451
1452 fn doTheTest() void {
1452 fn doTheTest() !void {
14531453 _ = async testFoo();
14541454 resume global_frame1;
14551455 resume global_frame2;
1456 expect(baz_happened);
1457 expect(finished);
1456 try expect(baz_happened);
1457 try expect(finished);
14581458 }
14591459
14601460 fn testFoo() void {
1461 expectError(error.Bad, foo());
1461 expectError(error.Bad, foo()) catch @panic("test failure");
14621462 finished = true;
14631463 }
14641464
......@@ -1479,7 +1479,7 @@ test "handle defer interfering with return value spill" {
14791479 baz_happened = true;
14801480 }
14811481 };
1482 S.doTheTest();
1482 try S.doTheTest();
14831483}
14841484
14851485test "take address of temporary async frame" {
......@@ -1487,14 +1487,14 @@ test "take address of temporary async frame" {
14871487 var global_frame: anyframe = undefined;
14881488 var finished = false;
14891489
1490 fn doTheTest() void {
1490 fn doTheTest() !void {
14911491 _ = async asyncDoTheTest();
14921492 resume global_frame;
1493 expect(finished);
1493 try expect(finished);
14941494 }
14951495
14961496 fn asyncDoTheTest() void {
1497 expect(finishIt(&async foo(10)) == 1245);
1497 expect(finishIt(&async foo(10)) == 1245) catch @panic("test failure");
14981498 finished = true;
14991499 }
15001500
......@@ -1508,16 +1508,16 @@ test "take address of temporary async frame" {
15081508 return (await frame) + 1;
15091509 }
15101510 };
1511 S.doTheTest();
1511 try S.doTheTest();
15121512}
15131513
15141514test "nosuspend await" {
15151515 const S = struct {
15161516 var finished = false;
15171517
1518 fn doTheTest() void {
1518 fn doTheTest() !void {
15191519 var frame = async foo(false);
1520 expect(nosuspend await frame == 42);
1520 try expect(nosuspend await frame == 42);
15211521 finished = true;
15221522 }
15231523
......@@ -1528,8 +1528,8 @@ test "nosuspend await" {
15281528 return 42;
15291529 }
15301530 };
1531 S.doTheTest();
1532 expect(S.finished);
1531 try S.doTheTest();
1532 try expect(S.finished);
15331533}
15341534
15351535test "nosuspend on function calls" {
......@@ -1544,8 +1544,8 @@ test "nosuspend on function calls" {
15441544 return S0{};
15451545 }
15461546 };
1547 expectEqual(@as(i32, 42), nosuspend S1.c().b);
1548 expectEqual(@as(i32, 42), (try nosuspend S1.d()).b);
1547 try expectEqual(@as(i32, 42), nosuspend S1.c().b);
1548 try expectEqual(@as(i32, 42), (try nosuspend S1.d()).b);
15491549}
15501550
15511551test "nosuspend on async function calls" {
......@@ -1561,9 +1561,9 @@ test "nosuspend on async function calls" {
15611561 }
15621562 };
15631563 var frame_c = nosuspend async S1.c();
1564 expectEqual(@as(i32, 42), (await frame_c).b);
1564 try expectEqual(@as(i32, 42), (await frame_c).b);
15651565 var frame_d = nosuspend async S1.d();
1566 expectEqual(@as(i32, 42), (try await frame_d).b);
1566 try expectEqual(@as(i32, 42), (try await frame_d).b);
15671567}
15681568
15691569// test "resume nosuspend async function calls" {
......@@ -1582,10 +1582,10 @@ test "nosuspend on async function calls" {
15821582// };
15831583// var frame_c = nosuspend async S1.c();
15841584// resume frame_c;
1585// expectEqual(@as(i32, 42), (await frame_c).b);
1585// try expectEqual(@as(i32, 42), (await frame_c).b);
15861586// var frame_d = nosuspend async S1.d();
15871587// resume frame_d;
1588// expectEqual(@as(i32, 42), (try await frame_d).b);
1588// try expectEqual(@as(i32, 42), (try await frame_d).b);
15891589// }
15901590
15911591test "nosuspend resume async function calls" {
......@@ -1604,10 +1604,10 @@ test "nosuspend resume async function calls" {
16041604 };
16051605 var frame_c = async S1.c();
16061606 nosuspend resume frame_c;
1607 expectEqual(@as(i32, 42), (await frame_c).b);
1607 try expectEqual(@as(i32, 42), (await frame_c).b);
16081608 var frame_d = async S1.d();
16091609 nosuspend resume frame_d;
1610 expectEqual(@as(i32, 42), (try await frame_d).b);
1610 try expectEqual(@as(i32, 42), (try await frame_d).b);
16111611}
16121612
16131613test "avoid forcing frame alignment resolution implicit cast to *c_void" {
......@@ -1623,7 +1623,7 @@ test "avoid forcing frame alignment resolution implicit cast to *c_void" {
16231623 };
16241624 var frame = async S.foo();
16251625 resume @ptrCast(anyframe->bool, @alignCast(@alignOf(@Frame(S.foo)), S.x));
1626 expect(nosuspend await frame);
1626 try expect(nosuspend await frame);
16271627}
16281628
16291629test "@asyncCall with pass-by-value arguments" {
......@@ -1638,9 +1638,9 @@ test "@asyncCall with pass-by-value arguments" {
16381638 pub fn f(_fill0: u64, s: ST, _fill1: u64, a: AT, _fill2: u64) callconv(.Async) void {
16391639 // Check that the array and struct arguments passed by value don't
16401640 // end up overflowing the adjacent fields in the frame structure.
1641 expectEqual(F0, _fill0);
1642 expectEqual(F1, _fill1);
1643 expectEqual(F2, _fill2);
1641 expectEqual(F0, _fill0) catch @panic("test failure");
1642 expectEqual(F1, _fill1) catch @panic("test failure");
1643 expectEqual(F2, _fill2) catch @panic("test failure");
16441644 }
16451645 };
16461646
......@@ -1664,8 +1664,8 @@ test "@asyncCall with arguments having non-standard alignment" {
16641664 pub fn f(_fill0: u32, s: struct { x: u64 align(16) }, _fill1: u64) callconv(.Async) void {
16651665 // The compiler inserts extra alignment for s, check that the
16661666 // generated code picks the right slot for fill1.
1667 expectEqual(F0, _fill0);
1668 expectEqual(F1, _fill1);
1667 expectEqual(F0, _fill0) catch @panic("test failure");
1668 expectEqual(F1, _fill1) catch @panic("test failure");
16691669 }
16701670 };
16711671
test/behavior/atomics.zig+69-69
......@@ -4,25 +4,25 @@ const expectEqual = std.testing.expectEqual;
44const builtin = @import("builtin");
55
66test "cmpxchg" {
7 testCmpxchg();
8 comptime testCmpxchg();
7 try testCmpxchg();
8 comptime try testCmpxchg();
99}
1010
11fn testCmpxchg() void {
11fn testCmpxchg() !void {
1212 var x: i32 = 1234;
1313 if (@cmpxchgWeak(i32, &x, 99, 5678, .SeqCst, .SeqCst)) |x1| {
14 expect(x1 == 1234);
14 try expect(x1 == 1234);
1515 } else {
1616 @panic("cmpxchg should have failed");
1717 }
1818
1919 while (@cmpxchgWeak(i32, &x, 1234, 5678, .SeqCst, .SeqCst)) |x1| {
20 expect(x1 == 1234);
20 try expect(x1 == 1234);
2121 }
22 expect(x == 5678);
22 try expect(x == 5678);
2323
24 expect(@cmpxchgStrong(i32, &x, 5678, 42, .SeqCst, .SeqCst) == null);
25 expect(x == 42);
24 try expect(@cmpxchgStrong(i32, &x, 5678, 42, .SeqCst, .SeqCst) == null);
25 try expect(x == 42);
2626}
2727
2828test "fence" {
......@@ -33,25 +33,25 @@ test "fence" {
3333
3434test "atomicrmw and atomicload" {
3535 var data: u8 = 200;
36 testAtomicRmw(&data);
37 expect(data == 42);
38 testAtomicLoad(&data);
36 try testAtomicRmw(&data);
37 try expect(data == 42);
38 try testAtomicLoad(&data);
3939}
4040
41fn testAtomicRmw(ptr: *u8) void {
41fn testAtomicRmw(ptr: *u8) !void {
4242 const prev_value = @atomicRmw(u8, ptr, .Xchg, 42, .SeqCst);
43 expect(prev_value == 200);
43 try expect(prev_value == 200);
4444 comptime {
4545 var x: i32 = 1234;
4646 const y: i32 = 12345;
47 expect(@atomicLoad(i32, &x, .SeqCst) == 1234);
48 expect(@atomicLoad(i32, &y, .SeqCst) == 12345);
47 try expect(@atomicLoad(i32, &x, .SeqCst) == 1234);
48 try expect(@atomicLoad(i32, &y, .SeqCst) == 12345);
4949 }
5050}
5151
52fn testAtomicLoad(ptr: *u8) void {
52fn testAtomicLoad(ptr: *u8) !void {
5353 const x = @atomicLoad(u8, ptr, .SeqCst);
54 expect(x == 42);
54 try expect(x == 42);
5555}
5656
5757test "cmpxchg with ptr" {
......@@ -60,18 +60,18 @@ test "cmpxchg with ptr" {
6060 var data3: i32 = 9101;
6161 var x: *i32 = &data1;
6262 if (@cmpxchgWeak(*i32, &x, &data2, &data3, .SeqCst, .SeqCst)) |x1| {
63 expect(x1 == &data1);
63 try expect(x1 == &data1);
6464 } else {
6565 @panic("cmpxchg should have failed");
6666 }
6767
6868 while (@cmpxchgWeak(*i32, &x, &data1, &data3, .SeqCst, .SeqCst)) |x1| {
69 expect(x1 == &data1);
69 try expect(x1 == &data1);
7070 }
71 expect(x == &data3);
71 try expect(x == &data3);
7272
73 expect(@cmpxchgStrong(*i32, &x, &data3, &data2, .SeqCst, .SeqCst) == null);
74 expect(x == &data2);
73 try expect(@cmpxchgStrong(*i32, &x, &data3, &data2, .SeqCst, .SeqCst) == null);
74 try expect(x == &data2);
7575}
7676
7777// TODO this test is disabled until this issue is resolved:
......@@ -81,18 +81,18 @@ test "cmpxchg with ptr" {
8181//test "128-bit cmpxchg" {
8282// var x: u128 align(16) = 1234; // TODO: https://github.com/ziglang/zig/issues/2987
8383// if (@cmpxchgWeak(u128, &x, 99, 5678, .SeqCst, .SeqCst)) |x1| {
84// expect(x1 == 1234);
84// try expect(x1 == 1234);
8585// } else {
8686// @panic("cmpxchg should have failed");
8787// }
8888//
8989// while (@cmpxchgWeak(u128, &x, 1234, 5678, .SeqCst, .SeqCst)) |x1| {
90// expect(x1 == 1234);
90// try expect(x1 == 1234);
9191// }
92// expect(x == 5678);
92// try expect(x == 5678);
9393//
94// expect(@cmpxchgStrong(u128, &x, 5678, 42, .SeqCst, .SeqCst) == null);
95// expect(x == 42);
94// try expect(@cmpxchgStrong(u128, &x, 5678, 42, .SeqCst, .SeqCst) == null);
95// try expect(x == 42);
9696//}
9797
9898test "cmpxchg with ignored result" {
......@@ -101,14 +101,14 @@ test "cmpxchg with ignored result" {
101101
102102 _ = @cmpxchgStrong(i32, &x, 1234, 5678, .Monotonic, .Monotonic);
103103
104 expectEqual(@as(i32, 5678), x);
104 try expectEqual(@as(i32, 5678), x);
105105}
106106
107107var a_global_variable = @as(u32, 1234);
108108
109109test "cmpxchg on a global variable" {
110110 _ = @cmpxchgWeak(u32, &a_global_variable, 1234, 42, .Acquire, .Monotonic);
111 expectEqual(@as(u32, 42), a_global_variable);
111 try expectEqual(@as(u32, 42), a_global_variable);
112112}
113113
114114test "atomic load and rmw with enum" {
......@@ -119,33 +119,33 @@ test "atomic load and rmw with enum" {
119119 };
120120 var x = Value.a;
121121
122 expect(@atomicLoad(Value, &x, .SeqCst) != .b);
122 try expect(@atomicLoad(Value, &x, .SeqCst) != .b);
123123
124124 _ = @atomicRmw(Value, &x, .Xchg, .c, .SeqCst);
125 expect(@atomicLoad(Value, &x, .SeqCst) == .c);
126 expect(@atomicLoad(Value, &x, .SeqCst) != .a);
127 expect(@atomicLoad(Value, &x, .SeqCst) != .b);
125 try expect(@atomicLoad(Value, &x, .SeqCst) == .c);
126 try expect(@atomicLoad(Value, &x, .SeqCst) != .a);
127 try expect(@atomicLoad(Value, &x, .SeqCst) != .b);
128128}
129129
130130test "atomic store" {
131131 var x: u32 = 0;
132132 @atomicStore(u32, &x, 1, .SeqCst);
133 expect(@atomicLoad(u32, &x, .SeqCst) == 1);
133 try expect(@atomicLoad(u32, &x, .SeqCst) == 1);
134134 @atomicStore(u32, &x, 12345678, .SeqCst);
135 expect(@atomicLoad(u32, &x, .SeqCst) == 12345678);
135 try expect(@atomicLoad(u32, &x, .SeqCst) == 12345678);
136136}
137137
138138test "atomic store comptime" {
139 comptime testAtomicStore();
140 testAtomicStore();
139 comptime try testAtomicStore();
140 try testAtomicStore();
141141}
142142
143fn testAtomicStore() void {
143fn testAtomicStore() !void {
144144 var x: u32 = 0;
145145 @atomicStore(u32, &x, 1, .SeqCst);
146 expect(@atomicLoad(u32, &x, .SeqCst) == 1);
146 try expect(@atomicLoad(u32, &x, .SeqCst) == 1);
147147 @atomicStore(u32, &x, 12345678, .SeqCst);
148 expect(@atomicLoad(u32, &x, .SeqCst) == 12345678);
148 try expect(@atomicLoad(u32, &x, .SeqCst) == 12345678);
149149}
150150
151151test "atomicrmw with floats" {
......@@ -154,66 +154,66 @@ test "atomicrmw with floats" {
154154 .aarch64, .arm, .thumb, .riscv64 => return error.SkipZigTest,
155155 else => {},
156156 }
157 testAtomicRmwFloat();
158 comptime testAtomicRmwFloat();
157 try testAtomicRmwFloat();
158 comptime try testAtomicRmwFloat();
159159}
160160
161fn testAtomicRmwFloat() void {
161fn testAtomicRmwFloat() !void {
162162 var x: f32 = 0;
163 expect(x == 0);
163 try expect(x == 0);
164164 _ = @atomicRmw(f32, &x, .Xchg, 1, .SeqCst);
165 expect(x == 1);
165 try expect(x == 1);
166166 _ = @atomicRmw(f32, &x, .Add, 5, .SeqCst);
167 expect(x == 6);
167 try expect(x == 6);
168168 _ = @atomicRmw(f32, &x, .Sub, 2, .SeqCst);
169 expect(x == 4);
169 try expect(x == 4);
170170}
171171
172172test "atomicrmw with ints" {
173 testAtomicRmwInt();
174 comptime testAtomicRmwInt();
173 try testAtomicRmwInt();
174 comptime try testAtomicRmwInt();
175175}
176176
177fn testAtomicRmwInt() void {
177fn testAtomicRmwInt() !void {
178178 var x: u8 = 1;
179179 var res = @atomicRmw(u8, &x, .Xchg, 3, .SeqCst);
180 expect(x == 3 and res == 1);
180 try expect(x == 3 and res == 1);
181181 _ = @atomicRmw(u8, &x, .Add, 3, .SeqCst);
182 expect(x == 6);
182 try expect(x == 6);
183183 _ = @atomicRmw(u8, &x, .Sub, 1, .SeqCst);
184 expect(x == 5);
184 try expect(x == 5);
185185 _ = @atomicRmw(u8, &x, .And, 4, .SeqCst);
186 expect(x == 4);
186 try expect(x == 4);
187187 _ = @atomicRmw(u8, &x, .Nand, 4, .SeqCst);
188 expect(x == 0xfb);
188 try expect(x == 0xfb);
189189 _ = @atomicRmw(u8, &x, .Or, 6, .SeqCst);
190 expect(x == 0xff);
190 try expect(x == 0xff);
191191 _ = @atomicRmw(u8, &x, .Xor, 2, .SeqCst);
192 expect(x == 0xfd);
192 try expect(x == 0xfd);
193193
194194 _ = @atomicRmw(u8, &x, .Max, 1, .SeqCst);
195 expect(x == 0xfd);
195 try expect(x == 0xfd);
196196 _ = @atomicRmw(u8, &x, .Min, 1, .SeqCst);
197 expect(x == 1);
197 try expect(x == 1);
198198}
199199
200200test "atomics with different types" {
201 testAtomicsWithType(bool, true, false);
201 try testAtomicsWithType(bool, true, false);
202202 inline for (.{ u1, i5, u15 }) |T| {
203203 var x: T = 0;
204 testAtomicsWithType(T, 0, 1);
204 try testAtomicsWithType(T, 0, 1);
205205 }
206 testAtomicsWithType(u0, 0, 0);
207 testAtomicsWithType(i0, 0, 0);
206 try testAtomicsWithType(u0, 0, 0);
207 try testAtomicsWithType(i0, 0, 0);
208208}
209209
210fn testAtomicsWithType(comptime T: type, a: T, b: T) void {
210fn testAtomicsWithType(comptime T: type, a: T, b: T) !void {
211211 var x: T = b;
212212 @atomicStore(T, &x, a, .SeqCst);
213 expect(x == a);
214 expect(@atomicLoad(T, &x, .SeqCst) == a);
215 expect(@atomicRmw(T, &x, .Xchg, b, .SeqCst) == a);
216 expect(@cmpxchgStrong(T, &x, b, a, .SeqCst, .SeqCst) == null);
213 try expect(x == a);
214 try expect(@atomicLoad(T, &x, .SeqCst) == a);
215 try expect(@atomicRmw(T, &x, .Xchg, b, .SeqCst) == a);
216 try expect(@cmpxchgStrong(T, &x, b, a, .SeqCst, .SeqCst) == null);
217217 if (@sizeOf(T) != 0)
218 expect(@cmpxchgStrong(T, &x, b, a, .SeqCst, .SeqCst).? == a);
218 try expect(@cmpxchgStrong(T, &x, b, a, .SeqCst, .SeqCst).? == a);
219219}
test/behavior/await_struct.zig+2-2
......@@ -15,8 +15,8 @@ test "coroutine await struct" {
1515 await_seq('f');
1616 resume await_a_promise;
1717 await_seq('i');
18 expect(await_final_result.x == 1234);
19 expect(std.mem.eql(u8, &await_points, "abcdefghi"));
18 try expect(await_final_result.x == 1234);
19 try expect(std.mem.eql(u8, &await_points, "abcdefghi"));
2020}
2121fn await_amain() callconv(.Async) void {
2222 await_seq('b');
test/behavior/bit_shifting.zig+14-14
......@@ -3,8 +3,8 @@ const expect = std.testing.expect;
33
44fn ShardedTable(comptime Key: type, comptime mask_bit_count: comptime_int, comptime V: type) type {
55 const key_bits = @typeInfo(Key).Int.bits;
6 expect(Key == std.meta.Int(.unsigned, key_bits));
7 expect(key_bits >= mask_bit_count);
6 std.debug.assert(Key == std.meta.Int(.unsigned, key_bits));
7 std.debug.assert(key_bits >= mask_bit_count);
88 const shard_key_bits = mask_bit_count;
99 const ShardKey = std.meta.Int(.unsigned, mask_bit_count);
1010 const shift_amount = key_bits - shard_key_bits;
......@@ -61,31 +61,31 @@ fn ShardedTable(comptime Key: type, comptime mask_bit_count: comptime_int, compt
6161
6262test "sharded table" {
6363 // realistic 16-way sharding
64 testShardedTable(u32, 4, 8);
64 try testShardedTable(u32, 4, 8);
6565
66 testShardedTable(u5, 0, 32); // ShardKey == u0
67 testShardedTable(u5, 2, 32);
68 testShardedTable(u5, 5, 32);
66 try testShardedTable(u5, 0, 32); // ShardKey == u0
67 try testShardedTable(u5, 2, 32);
68 try testShardedTable(u5, 5, 32);
6969
70 testShardedTable(u1, 0, 2);
71 testShardedTable(u1, 1, 2); // this does u1 >> u0
70 try testShardedTable(u1, 0, 2);
71 try testShardedTable(u1, 1, 2); // this does u1 >> u0
7272
73 testShardedTable(u0, 0, 1);
73 try testShardedTable(u0, 0, 1);
7474}
75fn testShardedTable(comptime Key: type, comptime mask_bit_count: comptime_int, comptime node_count: comptime_int) void {
75fn testShardedTable(comptime Key: type, comptime mask_bit_count: comptime_int, comptime node_count: comptime_int) !void {
7676 const Table = ShardedTable(Key, mask_bit_count, void);
7777
7878 var table = Table.create();
7979 var node_buffer: [node_count]Table.Node = undefined;
8080 for (node_buffer) |*node, i| {
8181 const key = @intCast(Key, i);
82 expect(table.get(key) == null);
82 try expect(table.get(key) == null);
8383 node.init(key, {});
8484 table.put(node);
8585 }
8686
8787 for (node_buffer) |*node, i| {
88 expect(table.get(@intCast(Key, i)) == node);
88 try expect(table.get(@intCast(Key, i)) == node);
8989 }
9090}
9191
......@@ -93,9 +93,9 @@ fn testShardedTable(comptime Key: type, comptime mask_bit_count: comptime_int, c
9393test "comptime shr of BigInt" {
9494 comptime {
9595 var n0 = 0xdeadbeef0000000000000000;
96 std.debug.assert(n0 >> 64 == 0xdeadbeef);
96 try expect(n0 >> 64 == 0xdeadbeef);
9797 var n1 = 17908056155735594659;
98 std.debug.assert(n1 >> 64 == 0);
98 try expect(n1 >> 64 == 0);
9999 }
100100}
101101
test/behavior/bitcast.zig+52-52
......@@ -6,13 +6,13 @@ const maxInt = std.math.maxInt;
66const native_endian = builtin.target.cpu.arch.endian();
77
88test "@bitCast i32 -> u32" {
9 testBitCast_i32_u32();
10 comptime testBitCast_i32_u32();
9 try testBitCast_i32_u32();
10 comptime try testBitCast_i32_u32();
1111}
1212
13fn testBitCast_i32_u32() void {
14 expect(conv(-1) == maxInt(u32));
15 expect(conv2(maxInt(u32)) == -1);
13fn testBitCast_i32_u32() !void {
14 try expect(conv(-1) == maxInt(u32));
15 try expect(conv2(maxInt(u32)) == -1);
1616}
1717
1818fn conv(x: i32) u32 {
......@@ -27,15 +27,15 @@ test "@bitCast extern enum to its integer type" {
2727 A,
2828 B,
2929
30 fn testBitCastExternEnum() void {
30 fn testBitCastExternEnum() !void {
3131 var SOCK_DGRAM = @This().B;
3232 var sock_dgram = @bitCast(c_int, SOCK_DGRAM);
33 expect(sock_dgram == 1);
33 try expect(sock_dgram == 1);
3434 }
3535 };
3636
37 SOCK.testBitCastExternEnum();
38 comptime SOCK.testBitCastExternEnum();
37 try SOCK.testBitCastExternEnum();
38 comptime try SOCK.testBitCastExternEnum();
3939}
4040
4141test "@bitCast packed structs at runtime and comptime" {
......@@ -48,25 +48,25 @@ test "@bitCast packed structs at runtime and comptime" {
4848 quarter4: u4,
4949 };
5050 const S = struct {
51 fn doTheTest() void {
51 fn doTheTest() !void {
5252 var full = Full{ .number = 0x1234 };
5353 var two_halves = @bitCast(Divided, full);
5454 switch (native_endian) {
5555 .Big => {
56 expect(two_halves.half1 == 0x12);
57 expect(two_halves.quarter3 == 0x3);
58 expect(two_halves.quarter4 == 0x4);
56 try expect(two_halves.half1 == 0x12);
57 try expect(two_halves.quarter3 == 0x3);
58 try expect(two_halves.quarter4 == 0x4);
5959 },
6060 .Little => {
61 expect(two_halves.half1 == 0x34);
62 expect(two_halves.quarter3 == 0x2);
63 expect(two_halves.quarter4 == 0x1);
61 try expect(two_halves.half1 == 0x34);
62 try expect(two_halves.quarter3 == 0x2);
63 try expect(two_halves.quarter4 == 0x1);
6464 },
6565 }
6666 }
6767 };
68 S.doTheTest();
69 comptime S.doTheTest();
68 try S.doTheTest();
69 comptime try S.doTheTest();
7070}
7171
7272test "@bitCast extern structs at runtime and comptime" {
......@@ -78,23 +78,23 @@ test "@bitCast extern structs at runtime and comptime" {
7878 half2: u8,
7979 };
8080 const S = struct {
81 fn doTheTest() void {
81 fn doTheTest() !void {
8282 var full = Full{ .number = 0x1234 };
8383 var two_halves = @bitCast(TwoHalves, full);
8484 switch (native_endian) {
8585 .Big => {
86 expect(two_halves.half1 == 0x12);
87 expect(two_halves.half2 == 0x34);
86 try expect(two_halves.half1 == 0x12);
87 try expect(two_halves.half2 == 0x34);
8888 },
8989 .Little => {
90 expect(two_halves.half1 == 0x34);
91 expect(two_halves.half2 == 0x12);
90 try expect(two_halves.half1 == 0x34);
91 try expect(two_halves.half2 == 0x12);
9292 },
9393 }
9494 }
9595 };
96 S.doTheTest();
97 comptime S.doTheTest();
96 try S.doTheTest();
97 comptime try S.doTheTest();
9898}
9999
100100test "bitcast packed struct to integer and back" {
......@@ -103,35 +103,35 @@ test "bitcast packed struct to integer and back" {
103103 level: u7,
104104 };
105105 const S = struct {
106 fn doTheTest() void {
106 fn doTheTest() !void {
107107 var move = LevelUpMove{ .move_id = 1, .level = 2 };
108108 var v = @bitCast(u16, move);
109109 var back_to_a_move = @bitCast(LevelUpMove, v);
110 expect(back_to_a_move.move_id == 1);
111 expect(back_to_a_move.level == 2);
110 try expect(back_to_a_move.move_id == 1);
111 try expect(back_to_a_move.level == 2);
112112 }
113113 };
114 S.doTheTest();
115 comptime S.doTheTest();
114 try S.doTheTest();
115 comptime try S.doTheTest();
116116}
117117
118118test "implicit cast to error union by returning" {
119119 const S = struct {
120 fn entry() void {
121 expect((func(-1) catch unreachable) == maxInt(u64));
120 fn entry() !void {
121 try expect((func(-1) catch unreachable) == maxInt(u64));
122122 }
123123 pub fn func(sz: i64) anyerror!u64 {
124124 return @bitCast(u64, sz);
125125 }
126126 };
127 S.entry();
128 comptime S.entry();
127 try S.entry();
128 comptime try S.entry();
129129}
130130
131131// issue #3010: compiler segfault
132132test "bitcast literal [4]u8 param to u32" {
133133 const ip = @bitCast(u32, [_]u8{ 255, 255, 255, 255 });
134 expect(ip == maxInt(u32));
134 try expect(ip == maxInt(u32));
135135}
136136
137137test "bitcast packed struct literal to byte" {
......@@ -139,14 +139,14 @@ test "bitcast packed struct literal to byte" {
139139 value: u8,
140140 };
141141 const casted = @bitCast(u8, Foo{ .value = 0xF });
142 expect(casted == 0xf);
142 try expect(casted == 0xf);
143143}
144144
145145test "comptime bitcast used in expression has the correct type" {
146146 const Foo = packed struct {
147147 value: u8,
148148 };
149 expect(@bitCast(u8, Foo{ .value = 0xF }) == 0xf);
149 try expect(@bitCast(u8, Foo{ .value = 0xF }) == 0xf);
150150}
151151
152152test "bitcast result to _" {
......@@ -155,43 +155,43 @@ test "bitcast result to _" {
155155
156156test "nested bitcast" {
157157 const S = struct {
158 fn moo(x: isize) void {
159 @import("std").testing.expectEqual(@intCast(isize, 42), x);
158 fn moo(x: isize) !void {
159 try @import("std").testing.expectEqual(@intCast(isize, 42), x);
160160 }
161161
162 fn foo(x: isize) void {
163 @This().moo(
162 fn foo(x: isize) !void {
163 try @This().moo(
164164 @bitCast(isize, if (x != 0) @bitCast(usize, x) else @bitCast(usize, x)),
165165 );
166166 }
167167 };
168168
169 S.foo(42);
170 comptime S.foo(42);
169 try S.foo(42);
170 comptime try S.foo(42);
171171}
172172
173173test "bitcast passed as tuple element" {
174174 const S = struct {
175 fn foo(args: anytype) void {
176 comptime expect(@TypeOf(args[0]) == f32);
177 expect(args[0] == 12.34);
175 fn foo(args: anytype) !void {
176 comptime try expect(@TypeOf(args[0]) == f32);
177 try expect(args[0] == 12.34);
178178 }
179179 };
180 S.foo(.{@bitCast(f32, @as(u32, 0x414570A4))});
180 try S.foo(.{@bitCast(f32, @as(u32, 0x414570A4))});
181181}
182182
183183test "triple level result location with bitcast sandwich passed as tuple element" {
184184 const S = struct {
185 fn foo(args: anytype) void {
186 comptime expect(@TypeOf(args[0]) == f64);
187 expect(args[0] > 12.33 and args[0] < 12.35);
185 fn foo(args: anytype) !void {
186 comptime try expect(@TypeOf(args[0]) == f64);
187 try expect(args[0] > 12.33 and args[0] < 12.35);
188188 }
189189 };
190 S.foo(.{@as(f64, @bitCast(f32, @as(u32, 0x414570A4)))});
190 try S.foo(.{@as(f64, @bitCast(f32, @as(u32, 0x414570A4)))});
191191}
192192
193193test "bitcast generates a temporary value" {
194194 var y = @as(u16, 0x55AA);
195195 const x = @bitCast(u16, @bitCast([2]u8, y));
196 expectEqual(y, x);
196 try expectEqual(y, x);
197197}
test/behavior/bitreverse.zig+39-39
......@@ -3,67 +3,67 @@ const expect = std.testing.expect;
33const minInt = std.math.minInt;
44
55test "@bitReverse" {
6 comptime testBitReverse();
7 testBitReverse();
6 comptime try testBitReverse();
7 try testBitReverse();
88}
99
10fn testBitReverse() void {
10fn testBitReverse() !void {
1111 // using comptime_ints, unsigned
12 expect(@bitReverse(u0, 0) == 0);
13 expect(@bitReverse(u5, 0x12) == 0x9);
14 expect(@bitReverse(u8, 0x12) == 0x48);
15 expect(@bitReverse(u16, 0x1234) == 0x2c48);
16 expect(@bitReverse(u24, 0x123456) == 0x6a2c48);
17 expect(@bitReverse(u32, 0x12345678) == 0x1e6a2c48);
18 expect(@bitReverse(u40, 0x123456789a) == 0x591e6a2c48);
19 expect(@bitReverse(u48, 0x123456789abc) == 0x3d591e6a2c48);
20 expect(@bitReverse(u56, 0x123456789abcde) == 0x7b3d591e6a2c48);
21 expect(@bitReverse(u64, 0x123456789abcdef1) == 0x8f7b3d591e6a2c48);
22 expect(@bitReverse(u128, 0x123456789abcdef11121314151617181) == 0x818e868a828c84888f7b3d591e6a2c48);
12 try expect(@bitReverse(u0, 0) == 0);
13 try expect(@bitReverse(u5, 0x12) == 0x9);
14 try expect(@bitReverse(u8, 0x12) == 0x48);
15 try expect(@bitReverse(u16, 0x1234) == 0x2c48);
16 try expect(@bitReverse(u24, 0x123456) == 0x6a2c48);
17 try expect(@bitReverse(u32, 0x12345678) == 0x1e6a2c48);
18 try expect(@bitReverse(u40, 0x123456789a) == 0x591e6a2c48);
19 try expect(@bitReverse(u48, 0x123456789abc) == 0x3d591e6a2c48);
20 try expect(@bitReverse(u56, 0x123456789abcde) == 0x7b3d591e6a2c48);
21 try expect(@bitReverse(u64, 0x123456789abcdef1) == 0x8f7b3d591e6a2c48);
22 try expect(@bitReverse(u128, 0x123456789abcdef11121314151617181) == 0x818e868a828c84888f7b3d591e6a2c48);
2323
2424 // using runtime uints, unsigned
2525 var num0: u0 = 0;
26 expect(@bitReverse(u0, num0) == 0);
26 try expect(@bitReverse(u0, num0) == 0);
2727 var num5: u5 = 0x12;
28 expect(@bitReverse(u5, num5) == 0x9);
28 try expect(@bitReverse(u5, num5) == 0x9);
2929 var num8: u8 = 0x12;
30 expect(@bitReverse(u8, num8) == 0x48);
30 try expect(@bitReverse(u8, num8) == 0x48);
3131 var num16: u16 = 0x1234;
32 expect(@bitReverse(u16, num16) == 0x2c48);
32 try expect(@bitReverse(u16, num16) == 0x2c48);
3333 var num24: u24 = 0x123456;
34 expect(@bitReverse(u24, num24) == 0x6a2c48);
34 try expect(@bitReverse(u24, num24) == 0x6a2c48);
3535 var num32: u32 = 0x12345678;
36 expect(@bitReverse(u32, num32) == 0x1e6a2c48);
36 try expect(@bitReverse(u32, num32) == 0x1e6a2c48);
3737 var num40: u40 = 0x123456789a;
38 expect(@bitReverse(u40, num40) == 0x591e6a2c48);
38 try expect(@bitReverse(u40, num40) == 0x591e6a2c48);
3939 var num48: u48 = 0x123456789abc;
40 expect(@bitReverse(u48, num48) == 0x3d591e6a2c48);
40 try expect(@bitReverse(u48, num48) == 0x3d591e6a2c48);
4141 var num56: u56 = 0x123456789abcde;
42 expect(@bitReverse(u56, num56) == 0x7b3d591e6a2c48);
42 try expect(@bitReverse(u56, num56) == 0x7b3d591e6a2c48);
4343 var num64: u64 = 0x123456789abcdef1;
44 expect(@bitReverse(u64, num64) == 0x8f7b3d591e6a2c48);
44 try expect(@bitReverse(u64, num64) == 0x8f7b3d591e6a2c48);
4545 var num128: u128 = 0x123456789abcdef11121314151617181;
46 expect(@bitReverse(u128, num128) == 0x818e868a828c84888f7b3d591e6a2c48);
46 try expect(@bitReverse(u128, num128) == 0x818e868a828c84888f7b3d591e6a2c48);
4747
4848 // using comptime_ints, signed, positive
49 expect(@bitReverse(u8, @as(u8, 0)) == 0);
50 expect(@bitReverse(i8, @bitCast(i8, @as(u8, 0x92))) == @bitCast(i8, @as(u8, 0x49)));
51 expect(@bitReverse(i16, @bitCast(i16, @as(u16, 0x1234))) == @bitCast(i16, @as(u16, 0x2c48)));
52 expect(@bitReverse(i24, @bitCast(i24, @as(u24, 0x123456))) == @bitCast(i24, @as(u24, 0x6a2c48)));
53 expect(@bitReverse(i32, @bitCast(i32, @as(u32, 0x12345678))) == @bitCast(i32, @as(u32, 0x1e6a2c48)));
54 expect(@bitReverse(i40, @bitCast(i40, @as(u40, 0x123456789a))) == @bitCast(i40, @as(u40, 0x591e6a2c48)));
55 expect(@bitReverse(i48, @bitCast(i48, @as(u48, 0x123456789abc))) == @bitCast(i48, @as(u48, 0x3d591e6a2c48)));
56 expect(@bitReverse(i56, @bitCast(i56, @as(u56, 0x123456789abcde))) == @bitCast(i56, @as(u56, 0x7b3d591e6a2c48)));
57 expect(@bitReverse(i64, @bitCast(i64, @as(u64, 0x123456789abcdef1))) == @bitCast(i64, @as(u64, 0x8f7b3d591e6a2c48)));
58 expect(@bitReverse(i128, @bitCast(i128, @as(u128, 0x123456789abcdef11121314151617181))) == @bitCast(i128, @as(u128, 0x818e868a828c84888f7b3d591e6a2c48)));
49 try expect(@bitReverse(u8, @as(u8, 0)) == 0);
50 try expect(@bitReverse(i8, @bitCast(i8, @as(u8, 0x92))) == @bitCast(i8, @as(u8, 0x49)));
51 try expect(@bitReverse(i16, @bitCast(i16, @as(u16, 0x1234))) == @bitCast(i16, @as(u16, 0x2c48)));
52 try expect(@bitReverse(i24, @bitCast(i24, @as(u24, 0x123456))) == @bitCast(i24, @as(u24, 0x6a2c48)));
53 try expect(@bitReverse(i32, @bitCast(i32, @as(u32, 0x12345678))) == @bitCast(i32, @as(u32, 0x1e6a2c48)));
54 try expect(@bitReverse(i40, @bitCast(i40, @as(u40, 0x123456789a))) == @bitCast(i40, @as(u40, 0x591e6a2c48)));
55 try expect(@bitReverse(i48, @bitCast(i48, @as(u48, 0x123456789abc))) == @bitCast(i48, @as(u48, 0x3d591e6a2c48)));
56 try expect(@bitReverse(i56, @bitCast(i56, @as(u56, 0x123456789abcde))) == @bitCast(i56, @as(u56, 0x7b3d591e6a2c48)));
57 try expect(@bitReverse(i64, @bitCast(i64, @as(u64, 0x123456789abcdef1))) == @bitCast(i64, @as(u64, 0x8f7b3d591e6a2c48)));
58 try expect(@bitReverse(i128, @bitCast(i128, @as(u128, 0x123456789abcdef11121314151617181))) == @bitCast(i128, @as(u128, 0x818e868a828c84888f7b3d591e6a2c48)));
5959
6060 // using signed, negative. Compare to runtime ints returned from llvm.
6161 var neg8: i8 = -18;
62 expect(@bitReverse(i8, @as(i8, -18)) == @bitReverse(i8, neg8));
62 try expect(@bitReverse(i8, @as(i8, -18)) == @bitReverse(i8, neg8));
6363 var neg16: i16 = -32694;
64 expect(@bitReverse(i16, @as(i16, -32694)) == @bitReverse(i16, neg16));
64 try expect(@bitReverse(i16, @as(i16, -32694)) == @bitReverse(i16, neg16));
6565 var neg24: i24 = -6773785;
66 expect(@bitReverse(i24, @as(i24, -6773785)) == @bitReverse(i24, neg24));
66 try expect(@bitReverse(i24, @as(i24, -6773785)) == @bitReverse(i24, neg24));
6767 var neg32: i32 = -16773785;
68 expect(@bitReverse(i32, @as(i32, -16773785)) == @bitReverse(i32, neg32));
68 try expect(@bitReverse(i32, @as(i32, -16773785)) == @bitReverse(i32, neg32));
6969}
test/behavior/bool.zig+11-11
......@@ -1,25 +1,25 @@
11const expect = @import("std").testing.expect;
22
33test "bool literals" {
4 expect(true);
5 expect(!false);
4 try expect(true);
5 try expect(!false);
66}
77
88test "cast bool to int" {
99 const t = true;
1010 const f = false;
11 expect(@boolToInt(t) == @as(u32, 1));
12 expect(@boolToInt(f) == @as(u32, 0));
13 nonConstCastBoolToInt(t, f);
11 try expect(@boolToInt(t) == @as(u32, 1));
12 try expect(@boolToInt(f) == @as(u32, 0));
13 try nonConstCastBoolToInt(t, f);
1414}
1515
16fn nonConstCastBoolToInt(t: bool, f: bool) void {
17 expect(@boolToInt(t) == @as(u32, 1));
18 expect(@boolToInt(f) == @as(u32, 0));
16fn nonConstCastBoolToInt(t: bool, f: bool) !void {
17 try expect(@boolToInt(t) == @as(u32, 1));
18 try expect(@boolToInt(f) == @as(u32, 0));
1919}
2020
2121test "bool cmp" {
22 expect(testBoolCmp(true, false) == false);
22 try expect(testBoolCmp(true, false) == false);
2323}
2424fn testBoolCmp(a: bool, b: bool) bool {
2525 return a == b;
......@@ -30,6 +30,6 @@ const global_t = true;
3030const not_global_f = !global_f;
3131const not_global_t = !global_t;
3232test "compile time bool not" {
33 expect(not_global_f);
34 expect(!not_global_t);
33 try expect(not_global_f);
34 try expect(!not_global_t);
3535}
test/behavior/bugs/1025.zig+1-1
......@@ -8,5 +8,5 @@ fn getA() A {
88
99test "bug 1025" {
1010 const a = getA();
11 @import("std").testing.expect(a.B == u8);
11 try @import("std").testing.expect(a.B == u8);
1212}
test/behavior/bugs/1076.zig+5-5
......@@ -3,21 +3,21 @@ const mem = std.mem;
33const expect = std.testing.expect;
44
55test "comptime code should not modify constant data" {
6 testCastPtrOfArrayToSliceAndPtr();
7 comptime testCastPtrOfArrayToSliceAndPtr();
6 try testCastPtrOfArrayToSliceAndPtr();
7 comptime try testCastPtrOfArrayToSliceAndPtr();
88}
99
10fn testCastPtrOfArrayToSliceAndPtr() void {
10fn testCastPtrOfArrayToSliceAndPtr() !void {
1111 {
1212 var array = "aoeu".*;
1313 const x: [*]u8 = &array;
1414 x[0] += 1;
15 expect(mem.eql(u8, array[0..], "boeu"));
15 try expect(mem.eql(u8, array[0..], "boeu"));
1616 }
1717 {
1818 var array: [4]u8 = "aoeu".*;
1919 const x: [*]u8 = &array;
2020 x[0] += 1;
21 expect(mem.eql(u8, array[0..], "boeu"));
21 try expect(mem.eql(u8, array[0..], "boeu"));
2222 }
2323}
test/behavior/bugs/1120.zig+1-1
......@@ -19,5 +19,5 @@ test "bug 1120" {
1919 1 => &b.a,
2020 else => unreachable,
2121 };
22 expect(ptr.* == 2);
22 try expect(ptr.* == 2);
2323}
test/behavior/bugs/1277.zig+1-1
......@@ -11,5 +11,5 @@ fn f() i32 {
1111}
1212
1313test "don't emit an LLVM global for a const function when it's in an optional in a struct" {
14 std.testing.expect(s.f.?() == 1234);
14 try std.testing.expect(s.f.?() == 1234);
1515}
test/behavior/bugs/1310.zig+1-1
......@@ -20,5 +20,5 @@ fn agent_callback(_vm: [*]VM, options: [*]u8) callconv(.C) i32 {
2020}
2121
2222test "fixed" {
23 expect(agent_callback(undefined, undefined) == 11);
23 try expect(agent_callback(undefined, undefined) == 11);
2424}
test/behavior/bugs/1322.zig+2-2
......@@ -13,7 +13,7 @@ const C = struct {};
1313
1414test "tagged union with all void fields but a meaningful tag" {
1515 var a: A = A{ .b = B{ .c = C{} } };
16 std.testing.expect(@as(std.meta.Tag(B), a.b) == std.meta.Tag(B).c);
16 try std.testing.expect(@as(std.meta.Tag(B), a.b) == std.meta.Tag(B).c);
1717 a = A{ .b = B.None };
18 std.testing.expect(@as(std.meta.Tag(B), a.b) == std.meta.Tag(B).None);
18 try std.testing.expect(@as(std.meta.Tag(B), a.b) == std.meta.Tag(B).None);
1919}
test/behavior/bugs/1381.zig+1-1
......@@ -17,5 +17,5 @@ test "union that needs padding bytes inside an array" {
1717 };
1818
1919 const a = as[0].B;
20 std.testing.expect(a.D == 1);
20 try std.testing.expect(a.D == 1);
2121}
test/behavior/bugs/1421.zig+1-1
......@@ -9,5 +9,5 @@ const S = struct {
99
1010test "functions with return type required to be comptime are generic" {
1111 const ti = S.method();
12 expect(@as(std.builtin.TypeId, ti) == std.builtin.TypeId.Struct);
12 try expect(@as(std.builtin.TypeId, ti) == std.builtin.TypeId.Struct);
1313}
test/behavior/bugs/1442.zig+1-1
......@@ -7,5 +7,5 @@ const Union = union(enum) {
77
88test "const error union field alignment" {
99 var union_or_err: anyerror!Union = Union{ .Color = 1234 };
10 std.testing.expect((union_or_err catch unreachable).Color == 1234);
10 try std.testing.expect((union_or_err catch unreachable).Color == 1234);
1111}
test/behavior/bugs/1486.zig+2-2
......@@ -5,6 +5,6 @@ var global: u64 = 123;
55
66test "constant pointer to global variable causes runtime load" {
77 global = 1234;
8 expect(&global == ptr);
9 expect(ptr.* == 1234);
8 try expect(&global == ptr);
9 try expect(ptr.* == 1234);
1010}
test/behavior/bugs/1607.zig+4-4
......@@ -3,13 +3,13 @@ const testing = std.testing;
33
44const a = [_]u8{ 1, 2, 3 };
55
6fn checkAddress(s: []const u8) void {
6fn checkAddress(s: []const u8) !void {
77 for (s) |*i, j| {
8 testing.expect(i == &a[j]);
8 try testing.expect(i == &a[j]);
99 }
1010}
1111
1212test "slices pointing at the same address as global array." {
13 checkAddress(&a);
14 comptime checkAddress(&a);
13 try checkAddress(&a);
14 comptime try checkAddress(&a);
1515}
test/behavior/bugs/1735.zig+1-1
......@@ -42,5 +42,5 @@ const a = struct {
4242
4343test "intialization" {
4444 var t = a.init();
45 std.testing.expect(t.foo.len == 0);
45 try std.testing.expect(t.foo.len == 0);
4646}
test/behavior/bugs/1741.zig+1-1
......@@ -2,5 +2,5 @@ const std = @import("std");
22
33test "fixed" {
44 const x: f32 align(128) = 12.34;
5 std.testing.expect(@ptrToInt(&x) % 128 == 0);
5 try std.testing.expect(@ptrToInt(&x) % 128 == 0);
66}
test/behavior/bugs/1851.zig+9-9
......@@ -2,25 +2,25 @@ const std = @import("std");
22const expect = std.testing.expect;
33
44test "allocation and looping over 3-byte integer" {
5 expect(@sizeOf(u24) == 4);
6 expect(@sizeOf([1]u24) == 4);
7 expect(@alignOf(u24) == 4);
8 expect(@alignOf([1]u24) == 4);
5 try expect(@sizeOf(u24) == 4);
6 try expect(@sizeOf([1]u24) == 4);
7 try expect(@alignOf(u24) == 4);
8 try expect(@alignOf([1]u24) == 4);
99
1010 var x = try std.testing.allocator.alloc(u24, 2);
1111 defer std.testing.allocator.free(x);
12 expect(x.len == 2);
12 try expect(x.len == 2);
1313 x[0] = 0xFFFFFF;
1414 x[1] = 0xFFFFFF;
1515
1616 const bytes = std.mem.sliceAsBytes(x);
17 expect(@TypeOf(bytes) == []align(4) u8);
18 expect(bytes.len == 8);
17 try expect(@TypeOf(bytes) == []align(4) u8);
18 try expect(bytes.len == 8);
1919
2020 for (bytes) |*b| {
2121 b.* = 0x00;
2222 }
2323
24 expect(x[0] == 0x00);
25 expect(x[1] == 0x00);
24 try expect(x[0] == 0x00);
25 try expect(x[1] == 0x00);
2626}
test/behavior/bugs/2006.zig+2-2
......@@ -7,6 +7,6 @@ const S = struct {
77test "bug 2006" {
88 var a: S = undefined;
99 a = S{ .p = undefined };
10 expect(@sizeOf(S) != 0);
11 expect(@sizeOf(*void) == 0);
10 try expect(@sizeOf(S) != 0);
11 try expect(@sizeOf(*void) == 0);
1212}
test/behavior/bugs/2114.zig+7-7
......@@ -7,13 +7,13 @@ fn ctz(x: anytype) usize {
77}
88
99test "fixed" {
10 testClz();
11 comptime testClz();
10 try testClz();
11 comptime try testClz();
1212}
1313
14fn testClz() void {
15 expect(ctz(@as(u128, 0x40000000000000000000000000000000)) == 126);
16 expect(math.rotl(u128, @as(u128, 0x40000000000000000000000000000000), @as(u8, 1)) == @as(u128, 0x80000000000000000000000000000000));
17 expect(ctz(@as(u128, 0x80000000000000000000000000000000)) == 127);
18 expect(ctz(math.rotl(u128, @as(u128, 0x40000000000000000000000000000000), @as(u8, 1))) == 127);
14fn testClz() !void {
15 try expect(ctz(@as(u128, 0x40000000000000000000000000000000)) == 126);
16 try expect(math.rotl(u128, @as(u128, 0x40000000000000000000000000000000), @as(u8, 1)) == @as(u128, 0x80000000000000000000000000000000));
17 try expect(ctz(@as(u128, 0x80000000000000000000000000000000)) == 127);
18 try expect(ctz(math.rotl(u128, @as(u128, 0x40000000000000000000000000000000), @as(u8, 1))) == 127);
1919}
test/behavior/bugs/2889.zig+1-1
......@@ -27,5 +27,5 @@ fn parseNote() ?i32 {
2727
2828test "fixed" {
2929 const result = parseNote();
30 std.testing.expect(result.? == 9);
30 try std.testing.expect(result.? == 9);
3131}
test/behavior/bugs/3007.zig+1-1
......@@ -19,5 +19,5 @@ fn get_foo() Foo.FooError!*Foo {
1919
2020test "fixed" {
2121 default_foo = get_foo() catch null; // This Line
22 std.testing.expect(!default_foo.?.free);
22 try std.testing.expect(!default_foo.?.free);
2323}
test/behavior/bugs/3046.zig+1-1
......@@ -15,5 +15,5 @@ test "fixed" {
1515 some_struct = SomeStruct{
1616 .field = couldFail() catch |_| @as(i32, 0),
1717 };
18 expect(some_struct.field == 1);
18 try expect(some_struct.field == 1);
1919}
test/behavior/bugs/3112.zig+1-1
......@@ -7,7 +7,7 @@ const State = struct {
77};
88
99fn prev(p: ?State) void {
10 expect(p == null);
10 expect(p == null) catch @panic("test failure");
1111}
1212
1313test "zig test crash" {
test/behavior/bugs/3384.zig+6-6
......@@ -2,10 +2,10 @@ const std = @import("std");
22const expect = std.testing.expect;
33
44test "resolve array slice using builtin" {
5 expect(@hasDecl(@This(), "std") == true);
6 expect(@hasDecl(@This(), "std"[0..0]) == false);
7 expect(@hasDecl(@This(), "std"[0..1]) == false);
8 expect(@hasDecl(@This(), "std"[0..2]) == false);
9 expect(@hasDecl(@This(), "std"[0..3]) == true);
10 expect(@hasDecl(@This(), "std"[0..]) == true);
5 try expect(@hasDecl(@This(), "std") == true);
6 try expect(@hasDecl(@This(), "std"[0..0]) == false);
7 try expect(@hasDecl(@This(), "std"[0..1]) == false);
8 try expect(@hasDecl(@This(), "std"[0..2]) == false);
9 try expect(@hasDecl(@This(), "std"[0..3]) == true);
10 try expect(@hasDecl(@This(), "std"[0..]) == true);
1111}
test/behavior/bugs/394.zig+1-1
......@@ -14,5 +14,5 @@ test "bug 394 fixed" {
1414 .x = 3,
1515 .y = E{ .B = 1 },
1616 };
17 expect(x.x == 3);
17 try expect(x.x == 3);
1818}
test/behavior/bugs/421.zig+4-4
......@@ -1,12 +1,12 @@
11const expect = @import("std").testing.expect;
22
33test "bitCast to array" {
4 comptime testBitCastArray();
5 testBitCastArray();
4 comptime try testBitCastArray();
5 try testBitCastArray();
66}
77
8fn testBitCastArray() void {
9 expect(extractOne64(0x0123456789abcdef0123456789abcdef) == 0x0123456789abcdef);
8fn testBitCastArray() !void {
9 try expect(extractOne64(0x0123456789abcdef0123456789abcdef) == 0x0123456789abcdef);
1010}
1111
1212fn extractOne64(a: u128) u64 {
test/behavior/bugs/4328.zig+14-14
......@@ -25,14 +25,14 @@ test "Extern function calls in @TypeOf" {
2525 return 1;
2626 }
2727
28 fn doTheTest() void {
29 expectEqual(c_int, @TypeOf(test_fn_1(0, 42)));
30 expectEqual(c_short, @TypeOf(test_fn_2(0)));
28 fn doTheTest() !void {
29 try expectEqual(c_int, @TypeOf(test_fn_1(0, 42)));
30 try expectEqual(c_short, @TypeOf(test_fn_2(0)));
3131 }
3232 };
3333
34 Test.doTheTest();
35 comptime Test.doTheTest();
34 try Test.doTheTest();
35 comptime try Test.doTheTest();
3636}
3737
3838test "Peer resolution of extern function calls in @TypeOf" {
......@@ -41,13 +41,13 @@ test "Peer resolution of extern function calls in @TypeOf" {
4141 return 0;
4242 }
4343
44 fn doTheTest() void {
45 expectEqual(c_long, @TypeOf(test_fn()));
44 fn doTheTest() !void {
45 try expectEqual(c_long, @TypeOf(test_fn()));
4646 }
4747 };
4848
49 Test.doTheTest();
50 comptime Test.doTheTest();
49 try Test.doTheTest();
50 comptime try Test.doTheTest();
5151}
5252
5353test "Extern function calls, dereferences and field access in @TypeOf" {
......@@ -60,12 +60,12 @@ test "Extern function calls, dereferences and field access in @TypeOf" {
6060 return 255;
6161 }
6262
63 fn doTheTest() void {
64 expectEqual(FILE, @TypeOf(test_fn_1(0)));
65 expectEqual(u8, @TypeOf(test_fn_2(0)));
63 fn doTheTest() !void {
64 try expectEqual(FILE, @TypeOf(test_fn_1(0)));
65 try expectEqual(u8, @TypeOf(test_fn_2(0)));
6666 }
6767 };
6868
69 Test.doTheTest();
70 comptime Test.doTheTest();
69 try Test.doTheTest();
70 comptime try Test.doTheTest();
7171}
test/behavior/bugs/4560.zig+3-3
......@@ -8,9 +8,9 @@ test "fixed" {
88 .max_distance_from_start_index = 456,
99 },
1010 };
11 std.testing.expect(s.a == 1);
12 std.testing.expect(s.b.size == 123);
13 std.testing.expect(s.b.max_distance_from_start_index == 456);
11 try std.testing.expect(s.a == 1);
12 try std.testing.expect(s.b.size == 123);
13 try std.testing.expect(s.b.max_distance_from_start_index == 456);
1414}
1515
1616const S = struct {
test/behavior/bugs/4769_a.zig+1-1
......@@ -1 +1 @@
1//
\ No newline at end of file
1//
test/behavior/bugs/4769_b.zig+1-1
......@@ -1 +1 @@
1//!
\ No newline at end of file
1//!
test/behavior/bugs/5398.zig+3-3
......@@ -25,7 +25,7 @@ test "assignment of field with padding" {
2525 .emits_shadows = false,
2626 },
2727 };
28 testing.expectEqual(false, renderable.material.transparent);
29 testing.expectEqual(false, renderable.material.emits_shadows);
30 testing.expectEqual(true, renderable.material.render_color);
28 try testing.expectEqual(false, renderable.material.transparent);
29 try testing.expectEqual(false, renderable.material.emits_shadows);
30 try testing.expectEqual(true, renderable.material.render_color);
3131}
test/behavior/bugs/5413.zig+2-2
......@@ -1,6 +1,6 @@
11const expect = @import("std").testing.expect;
22
33test "Peer type resolution with string literals and unknown length u8 pointers" {
4 expect(@TypeOf("", "a", @as([*:0]const u8, "")) == [*:0]const u8);
5 expect(@TypeOf(@as([*:0]const u8, "baz"), "foo", "bar") == [*:0]const u8);
4 try expect(@TypeOf("", "a", @as([*:0]const u8, "")) == [*:0]const u8);
5 try expect(@TypeOf(@as([*:0]const u8, "baz"), "foo", "bar") == [*:0]const u8);
66}
test/behavior/bugs/5474.zig+9-9
......@@ -25,33 +25,33 @@ const Box2 = struct {
2525 };
2626};
2727
28fn doTest() void {
28fn doTest() !void {
2929 // var
3030 {
3131 var box0: Box0 = .{ .items = undefined };
32 std.testing.expect(@typeInfo(@TypeOf(box0.items[0..])).Pointer.is_const == false);
32 try std.testing.expect(@typeInfo(@TypeOf(box0.items[0..])).Pointer.is_const == false);
3333
3434 var box1: Box1 = .{ .items = undefined };
35 std.testing.expect(@typeInfo(@TypeOf(box1.items[0..])).Pointer.is_const == false);
35 try std.testing.expect(@typeInfo(@TypeOf(box1.items[0..])).Pointer.is_const == false);
3636
3737 var box2: Box2 = .{ .items = undefined };
38 std.testing.expect(@typeInfo(@TypeOf(box2.items[0..])).Pointer.is_const == false);
38 try std.testing.expect(@typeInfo(@TypeOf(box2.items[0..])).Pointer.is_const == false);
3939 }
4040
4141 // const
4242 {
4343 const box0: Box0 = .{ .items = undefined };
44 std.testing.expect(@typeInfo(@TypeOf(box0.items[0..])).Pointer.is_const == true);
44 try std.testing.expect(@typeInfo(@TypeOf(box0.items[0..])).Pointer.is_const == true);
4545
4646 const box1: Box1 = .{ .items = undefined };
47 std.testing.expect(@typeInfo(@TypeOf(box1.items[0..])).Pointer.is_const == true);
47 try std.testing.expect(@typeInfo(@TypeOf(box1.items[0..])).Pointer.is_const == true);
4848
4949 const box2: Box2 = .{ .items = undefined };
50 std.testing.expect(@typeInfo(@TypeOf(box2.items[0..])).Pointer.is_const == true);
50 try std.testing.expect(@typeInfo(@TypeOf(box2.items[0..])).Pointer.is_const == true);
5151 }
5252}
5353
5454test "pointer-to-array constness for zero-size elements" {
55 doTest();
56 comptime doTest();
55 try doTest();
56 comptime try doTest();
5757}
test/behavior/bugs/624.zig+1-1
......@@ -19,5 +19,5 @@ fn MemoryPool(comptime T: type) type {
1919
2020test "foo" {
2121 var allocator = ContextAllocator{ .n = 10 };
22 expect(allocator.n == 10);
22 try expect(allocator.n == 10);
2323}
test/behavior/bugs/6456.zig+4-4
......@@ -34,9 +34,9 @@ test "issue 6456" {
3434 });
3535
3636 const gen_fields = @typeInfo(T).Struct.fields;
37 testing.expectEqual(3, gen_fields.len);
38 testing.expectEqualStrings("f1", gen_fields[0].name);
39 testing.expectEqualStrings("f2", gen_fields[1].name);
40 testing.expectEqualStrings("f3", gen_fields[2].name);
37 try testing.expectEqual(3, gen_fields.len);
38 try testing.expectEqualStrings("f1", gen_fields[0].name);
39 try testing.expectEqualStrings("f2", gen_fields[1].name);
40 try testing.expectEqualStrings("f3", gen_fields[2].name);
4141 }
4242}
test/behavior/bugs/655.zig+4-4
......@@ -3,10 +3,10 @@ const other_file = @import("655_other_file.zig");
33
44test "function with *const parameter with type dereferenced by namespace" {
55 const x: other_file.Integer = 1234;
6 comptime std.testing.expect(@TypeOf(&x) == *const other_file.Integer);
7 foo(&x);
6 comptime try std.testing.expect(@TypeOf(&x) == *const other_file.Integer);
7 try foo(&x);
88}
99
10fn foo(x: *const other_file.Integer) void {
11 std.testing.expect(x.* == 1234);
10fn foo(x: *const other_file.Integer) !void {
11 try std.testing.expect(x.* == 1234);
1212}
test/behavior/bugs/656.zig+3-3
......@@ -10,10 +10,10 @@ const Value = struct {
1010};
1111
1212test "optional if after an if in a switch prong of a switch with 2 prongs in an else" {
13 foo(false, true);
13 try foo(false, true);
1414}
1515
16fn foo(a: bool, b: bool) void {
16fn foo(a: bool, b: bool) !void {
1717 var prefix_op = PrefixOp{
1818 .AddrOf = Value{ .align_expr = 1234 },
1919 };
......@@ -22,7 +22,7 @@ fn foo(a: bool, b: bool) void {
2222 PrefixOp.AddrOf => |addr_of_info| {
2323 if (b) {}
2424 if (addr_of_info.align_expr) |align_expr| {
25 expect(align_expr == 1234);
25 try expect(align_expr == 1234);
2626 }
2727 },
2828 PrefixOp.Return => {},
test/behavior/bugs/679.zig+1-1
......@@ -13,5 +13,5 @@ const Element = struct {
1313test "false dependency loop in struct definition" {
1414 const listType = ElementList;
1515 var x: listType = 42;
16 expect(x == 42);
16 try expect(x == 42);
1717}
test/behavior/bugs/6850.zig+1-1
......@@ -4,7 +4,7 @@ test "lazy sizeof comparison with zero" {
44 const Empty = struct {};
55 const T = *Empty;
66
7 std.testing.expect(hasNoBits(T));
7 try std.testing.expect(hasNoBits(T));
88}
99
1010fn hasNoBits(comptime T: type) bool {
test/behavior/bugs/7047.zig+2-2
......@@ -15,8 +15,8 @@ fn S(comptime query: U) type {
1515
1616test "compiler doesn't consider equal unions with different 'type' payload" {
1717 const s1 = S(U{ .T = u32 }).tag();
18 std.testing.expectEqual(u32, s1);
18 try std.testing.expectEqual(u32, s1);
1919
2020 const s2 = S(U{ .T = u64 }).tag();
21 std.testing.expectEqual(u64, s2);
21 try std.testing.expectEqual(u64, s2);
2222}
test/behavior/bugs/718.zig+4-4
......@@ -10,8 +10,8 @@ const Keys = struct {
1010var keys: Keys = undefined;
1111test "zero keys with @memset" {
1212 @memset(@ptrCast([*]u8, &keys), 0, @sizeOf(@TypeOf(keys)));
13 expect(!keys.up);
14 expect(!keys.down);
15 expect(!keys.left);
16 expect(!keys.right);
13 try expect(!keys.up);
14 try expect(!keys.down);
15 try expect(!keys.left);
16 try expect(!keys.right);
1717}
test/behavior/bugs/726.zig+2-2
......@@ -3,7 +3,7 @@ const expect = @import("std").testing.expect;
33test "@ptrCast from const to nullable" {
44 const c: u8 = 4;
55 var x: ?*const u8 = @ptrCast(?*const u8, &c);
6 expect(x.?.* == 4);
6 try expect(x.?.* == 4);
77}
88
99test "@ptrCast from var in empty struct to nullable" {
......@@ -11,5 +11,5 @@ test "@ptrCast from var in empty struct to nullable" {
1111 var c: u8 = 4;
1212 };
1313 var x: ?*const u8 = @ptrCast(?*const u8, &container.c);
14 expect(x.?.* == 4);
14 try expect(x.?.* == 4);
1515}
test/behavior/bugs/920.zig+1-1
......@@ -60,6 +60,6 @@ test "bug 920 fixed" {
6060 };
6161
6262 for (NormalDist1.f) |_, i| {
63 std.testing.expectEqual(NormalDist1.f[i], NormalDist.f[i]);
63 try std.testing.expectEqual(NormalDist1.f[i], NormalDist.f[i]);
6464 }
6565}
test/behavior/byteswap.zig+33-33
......@@ -3,39 +3,39 @@ const expect = std.testing.expect;
33
44test "@byteSwap integers" {
55 const ByteSwapIntTest = struct {
6 fn run() void {
7 t(u0, 0, 0);
8 t(u8, 0x12, 0x12);
9 t(u16, 0x1234, 0x3412);
10 t(u24, 0x123456, 0x563412);
11 t(u32, 0x12345678, 0x78563412);
12 t(u40, 0x123456789a, 0x9a78563412);
13 t(i48, 0x123456789abc, @bitCast(i48, @as(u48, 0xbc9a78563412)));
14 t(u56, 0x123456789abcde, 0xdebc9a78563412);
15 t(u64, 0x123456789abcdef1, 0xf1debc9a78563412);
16 t(u128, 0x123456789abcdef11121314151617181, 0x8171615141312111f1debc9a78563412);
6 fn run() !void {
7 try t(u0, 0, 0);
8 try t(u8, 0x12, 0x12);
9 try t(u16, 0x1234, 0x3412);
10 try t(u24, 0x123456, 0x563412);
11 try t(u32, 0x12345678, 0x78563412);
12 try t(u40, 0x123456789a, 0x9a78563412);
13 try t(i48, 0x123456789abc, @bitCast(i48, @as(u48, 0xbc9a78563412)));
14 try t(u56, 0x123456789abcde, 0xdebc9a78563412);
15 try t(u64, 0x123456789abcdef1, 0xf1debc9a78563412);
16 try t(u128, 0x123456789abcdef11121314151617181, 0x8171615141312111f1debc9a78563412);
1717
18 t(u0, @as(u0, 0), 0);
19 t(i8, @as(i8, -50), -50);
20 t(i16, @bitCast(i16, @as(u16, 0x1234)), @bitCast(i16, @as(u16, 0x3412)));
21 t(i24, @bitCast(i24, @as(u24, 0x123456)), @bitCast(i24, @as(u24, 0x563412)));
22 t(i32, @bitCast(i32, @as(u32, 0x12345678)), @bitCast(i32, @as(u32, 0x78563412)));
23 t(u40, @bitCast(i40, @as(u40, 0x123456789a)), @as(u40, 0x9a78563412));
24 t(i48, @bitCast(i48, @as(u48, 0x123456789abc)), @bitCast(i48, @as(u48, 0xbc9a78563412)));
25 t(i56, @bitCast(i56, @as(u56, 0x123456789abcde)), @bitCast(i56, @as(u56, 0xdebc9a78563412)));
26 t(i64, @bitCast(i64, @as(u64, 0x123456789abcdef1)), @bitCast(i64, @as(u64, 0xf1debc9a78563412)));
27 t(
18 try t(u0, @as(u0, 0), 0);
19 try t(i8, @as(i8, -50), -50);
20 try t(i16, @bitCast(i16, @as(u16, 0x1234)), @bitCast(i16, @as(u16, 0x3412)));
21 try t(i24, @bitCast(i24, @as(u24, 0x123456)), @bitCast(i24, @as(u24, 0x563412)));
22 try t(i32, @bitCast(i32, @as(u32, 0x12345678)), @bitCast(i32, @as(u32, 0x78563412)));
23 try t(u40, @bitCast(i40, @as(u40, 0x123456789a)), @as(u40, 0x9a78563412));
24 try t(i48, @bitCast(i48, @as(u48, 0x123456789abc)), @bitCast(i48, @as(u48, 0xbc9a78563412)));
25 try t(i56, @bitCast(i56, @as(u56, 0x123456789abcde)), @bitCast(i56, @as(u56, 0xdebc9a78563412)));
26 try t(i64, @bitCast(i64, @as(u64, 0x123456789abcdef1)), @bitCast(i64, @as(u64, 0xf1debc9a78563412)));
27 try t(
2828 i128,
2929 @bitCast(i128, @as(u128, 0x123456789abcdef11121314151617181)),
3030 @bitCast(i128, @as(u128, 0x8171615141312111f1debc9a78563412)),
3131 );
3232 }
33 fn t(comptime I: type, input: I, expected_output: I) void {
34 std.testing.expectEqual(expected_output, @byteSwap(I, input));
33 fn t(comptime I: type, input: I, expected_output: I) !void {
34 try std.testing.expectEqual(expected_output, @byteSwap(I, input));
3535 }
3636 };
37 comptime ByteSwapIntTest.run();
38 ByteSwapIntTest.run();
37 comptime try ByteSwapIntTest.run();
38 try ByteSwapIntTest.run();
3939}
4040
4141test "@byteSwap vectors" {
......@@ -46,10 +46,10 @@ test "@byteSwap vectors" {
4646 if (std.Target.current.cpu.arch == .mipsel or std.Target.current.cpu.arch == .mips) return error.SkipZigTest;
4747
4848 const ByteSwapVectorTest = struct {
49 fn run() void {
50 t(u8, 2, [_]u8{ 0x12, 0x13 }, [_]u8{ 0x12, 0x13 });
51 t(u16, 2, [_]u16{ 0x1234, 0x2345 }, [_]u16{ 0x3412, 0x4523 });
52 t(u24, 2, [_]u24{ 0x123456, 0x234567 }, [_]u24{ 0x563412, 0x674523 });
49 fn run() !void {
50 try t(u8, 2, [_]u8{ 0x12, 0x13 }, [_]u8{ 0x12, 0x13 });
51 try t(u16, 2, [_]u16{ 0x1234, 0x2345 }, [_]u16{ 0x3412, 0x4523 });
52 try t(u24, 2, [_]u24{ 0x123456, 0x234567 }, [_]u24{ 0x563412, 0x674523 });
5353 }
5454
5555 fn t(
......@@ -57,12 +57,12 @@ test "@byteSwap vectors" {
5757 comptime n: comptime_int,
5858 input: std.meta.Vector(n, I),
5959 expected_vector: std.meta.Vector(n, I),
60 ) void {
60 ) !void {
6161 const actual_output: [n]I = @byteSwap(I, input);
6262 const expected_output: [n]I = expected_vector;
63 std.testing.expectEqual(expected_output, actual_output);
63 try std.testing.expectEqual(expected_output, actual_output);
6464 }
6565 };
66 comptime ByteSwapVectorTest.run();
67 ByteSwapVectorTest.run();
66 comptime try ByteSwapVectorTest.run();
67 try ByteSwapVectorTest.run();
6868}
test/behavior/byval_arg_var.zig+1-1
......@@ -6,7 +6,7 @@ test "pass string literal byvalue to a generic var param" {
66 start();
77 blowUpStack(10);
88
9 std.testing.expect(std.mem.eql(u8, result, "string literal"));
9 try std.testing.expect(std.mem.eql(u8, result, "string literal"));
1010}
1111
1212fn start() void {
test/behavior/call.zig+19-19
......@@ -8,25 +8,25 @@ test "basic invocations" {
88 return 1234;
99 }
1010 }.foo;
11 expect(@call(.{}, foo, .{}) == 1234);
11 try expect(@call(.{}, foo, .{}) == 1234);
1212 comptime {
1313 // modifiers that allow comptime calls
14 expect(@call(.{}, foo, .{}) == 1234);
15 expect(@call(.{ .modifier = .no_async }, foo, .{}) == 1234);
16 expect(@call(.{ .modifier = .always_tail }, foo, .{}) == 1234);
17 expect(@call(.{ .modifier = .always_inline }, foo, .{}) == 1234);
14 try expect(@call(.{}, foo, .{}) == 1234);
15 try expect(@call(.{ .modifier = .no_async }, foo, .{}) == 1234);
16 try expect(@call(.{ .modifier = .always_tail }, foo, .{}) == 1234);
17 try expect(@call(.{ .modifier = .always_inline }, foo, .{}) == 1234);
1818 }
1919 {
2020 // comptime call without comptime keyword
2121 const result = @call(.{ .modifier = .compile_time }, foo, .{}) == 1234;
22 comptime expect(result);
22 comptime try expect(result);
2323 }
2424 {
2525 // call of non comptime-known function
2626 var alias_foo = foo;
27 expect(@call(.{ .modifier = .no_async }, alias_foo, .{}) == 1234);
28 expect(@call(.{ .modifier = .never_tail }, alias_foo, .{}) == 1234);
29 expect(@call(.{ .modifier = .never_inline }, alias_foo, .{}) == 1234);
27 try expect(@call(.{ .modifier = .no_async }, alias_foo, .{}) == 1234);
28 try expect(@call(.{ .modifier = .never_tail }, alias_foo, .{}) == 1234);
29 try expect(@call(.{ .modifier = .never_inline }, alias_foo, .{}) == 1234);
3030 }
3131}
3232
......@@ -38,20 +38,20 @@ test "tuple parameters" {
3838 }.add;
3939 var a: i32 = 12;
4040 var b: i32 = 34;
41 expect(@call(.{}, add, .{ a, 34 }) == 46);
42 expect(@call(.{}, add, .{ 12, b }) == 46);
43 expect(@call(.{}, add, .{ a, b }) == 46);
44 expect(@call(.{}, add, .{ 12, 34 }) == 46);
45 comptime expect(@call(.{}, add, .{ 12, 34 }) == 46);
41 try expect(@call(.{}, add, .{ a, 34 }) == 46);
42 try expect(@call(.{}, add, .{ 12, b }) == 46);
43 try expect(@call(.{}, add, .{ a, b }) == 46);
44 try expect(@call(.{}, add, .{ 12, 34 }) == 46);
45 comptime try expect(@call(.{}, add, .{ 12, 34 }) == 46);
4646 {
4747 const separate_args0 = .{ a, b };
4848 const separate_args1 = .{ a, 34 };
4949 const separate_args2 = .{ 12, 34 };
5050 const separate_args3 = .{ 12, b };
51 expect(@call(.{ .modifier = .always_inline }, add, separate_args0) == 46);
52 expect(@call(.{ .modifier = .always_inline }, add, separate_args1) == 46);
53 expect(@call(.{ .modifier = .always_inline }, add, separate_args2) == 46);
54 expect(@call(.{ .modifier = .always_inline }, add, separate_args3) == 46);
51 try expect(@call(.{ .modifier = .always_inline }, add, separate_args0) == 46);
52 try expect(@call(.{ .modifier = .always_inline }, add, separate_args1) == 46);
53 try expect(@call(.{ .modifier = .always_inline }, add, separate_args2) == 46);
54 try expect(@call(.{ .modifier = .always_inline }, add, separate_args3) == 46);
5555 }
5656}
5757
......@@ -70,5 +70,5 @@ test "comptime call with bound function as parameter" {
7070 };
7171
7272 var inst: S = undefined;
73 expectEqual(?i32, S.ReturnType(inst.call_me_maybe));
73 try expectEqual(?i32, S.ReturnType(inst.call_me_maybe));
7474}
test/behavior/cast.zig+226-226
......@@ -9,12 +9,12 @@ test "int to ptr cast" {
99 const x = @as(usize, 13);
1010 const y = @intToPtr(*u8, x);
1111 const z = @ptrToInt(y);
12 expect(z == 13);
12 try expect(z == 13);
1313}
1414
1515test "integer literal to pointer cast" {
1616 const vga_mem = @intToPtr(*u16, 0xB8000);
17 expect(@ptrToInt(vga_mem) == 0xB8000);
17 try expect(@ptrToInt(vga_mem) == 0xB8000);
1818}
1919
2020test "pointer reinterpret const float to int" {
......@@ -24,9 +24,9 @@ test "pointer reinterpret const float to int" {
2424 const int_ptr = @ptrCast(*const i32, float_ptr);
2525 const int_val = int_ptr.*;
2626 if (native_endian == .Little)
27 expect(int_val == 0x33333303)
27 try expect(int_val == 0x33333303)
2828 else
29 expect(int_val == 0x3fe33333);
29 try expect(int_val == 0x3fe33333);
3030}
3131
3232test "implicitly cast indirect pointer to maybe-indirect pointer" {
......@@ -50,62 +50,62 @@ test "implicitly cast indirect pointer to maybe-indirect pointer" {
5050 const p = &s;
5151 const q = &p;
5252 const r = &q;
53 expect(42 == S.constConst(q));
54 expect(42 == S.maybeConstConst(q));
55 expect(42 == S.constConstConst(r));
56 expect(42 == S.maybeConstConstConst(r));
53 try expect(42 == S.constConst(q));
54 try expect(42 == S.maybeConstConst(q));
55 try expect(42 == S.constConstConst(r));
56 try expect(42 == S.maybeConstConstConst(r));
5757}
5858
5959test "explicit cast from integer to error type" {
60 testCastIntToErr(error.ItBroke);
61 comptime testCastIntToErr(error.ItBroke);
60 try testCastIntToErr(error.ItBroke);
61 comptime try testCastIntToErr(error.ItBroke);
6262}
63fn testCastIntToErr(err: anyerror) void {
63fn testCastIntToErr(err: anyerror) !void {
6464 const x = @errorToInt(err);
6565 const y = @intToError(x);
66 expect(error.ItBroke == y);
66 try expect(error.ItBroke == y);
6767}
6868
6969test "peer resolve arrays of different size to const slice" {
70 expect(mem.eql(u8, boolToStr(true), "true"));
71 expect(mem.eql(u8, boolToStr(false), "false"));
72 comptime expect(mem.eql(u8, boolToStr(true), "true"));
73 comptime expect(mem.eql(u8, boolToStr(false), "false"));
70 try expect(mem.eql(u8, boolToStr(true), "true"));
71 try expect(mem.eql(u8, boolToStr(false), "false"));
72 comptime try expect(mem.eql(u8, boolToStr(true), "true"));
73 comptime try expect(mem.eql(u8, boolToStr(false), "false"));
7474}
7575fn boolToStr(b: bool) []const u8 {
7676 return if (b) "true" else "false";
7777}
7878
7979test "peer resolve array and const slice" {
80 testPeerResolveArrayConstSlice(true);
81 comptime testPeerResolveArrayConstSlice(true);
80 try testPeerResolveArrayConstSlice(true);
81 comptime try testPeerResolveArrayConstSlice(true);
8282}
83fn testPeerResolveArrayConstSlice(b: bool) void {
83fn testPeerResolveArrayConstSlice(b: bool) !void {
8484 const value1 = if (b) "aoeu" else @as([]const u8, "zz");
8585 const value2 = if (b) @as([]const u8, "zz") else "aoeu";
86 expect(mem.eql(u8, value1, "aoeu"));
87 expect(mem.eql(u8, value2, "zz"));
86 try expect(mem.eql(u8, value1, "aoeu"));
87 try expect(mem.eql(u8, value2, "zz"));
8888}
8989
9090test "implicitly cast from T to anyerror!?T" {
91 castToOptionalTypeError(1);
92 comptime castToOptionalTypeError(1);
91 try castToOptionalTypeError(1);
92 comptime try castToOptionalTypeError(1);
9393}
9494
9595const A = struct {
9696 a: i32,
9797};
98fn castToOptionalTypeError(z: i32) void {
98fn castToOptionalTypeError(z: i32) !void {
9999 const x = @as(i32, 1);
100100 const y: anyerror!?i32 = x;
101 expect((try y).? == 1);
101 try expect((try y).? == 1);
102102
103103 const f = z;
104104 const g: anyerror!?i32 = f;
105105
106106 const a = A{ .a = z };
107107 const b: anyerror!?A = a;
108 expect((b catch unreachable).?.a == 1);
108 try expect((b catch unreachable).?.a == 1);
109109}
110110
111111test "implicitly cast from int to anyerror!?T" {
......@@ -120,7 +120,7 @@ fn implicitIntLitToOptional() void {
120120test "return null from fn() anyerror!?&T" {
121121 const a = returnNullFromOptionalTypeErrorRef();
122122 const b = returnNullLitFromOptionalTypeErrorRef();
123 expect((try a) == null and (try b) == null);
123 try expect((try a) == null and (try b) == null);
124124}
125125fn returnNullFromOptionalTypeErrorRef() anyerror!?*A {
126126 const a: ?*A = null;
......@@ -131,11 +131,11 @@ fn returnNullLitFromOptionalTypeErrorRef() anyerror!?*A {
131131}
132132
133133test "peer type resolution: ?T and T" {
134 expect(peerTypeTAndOptionalT(true, false).? == 0);
135 expect(peerTypeTAndOptionalT(false, false).? == 3);
134 try expect(peerTypeTAndOptionalT(true, false).? == 0);
135 try expect(peerTypeTAndOptionalT(false, false).? == 3);
136136 comptime {
137 expect(peerTypeTAndOptionalT(true, false).? == 0);
138 expect(peerTypeTAndOptionalT(false, false).? == 3);
137 try expect(peerTypeTAndOptionalT(true, false).? == 0);
138 try expect(peerTypeTAndOptionalT(false, false).? == 3);
139139 }
140140}
141141fn peerTypeTAndOptionalT(c: bool, b: bool) ?usize {
......@@ -147,11 +147,11 @@ fn peerTypeTAndOptionalT(c: bool, b: bool) ?usize {
147147}
148148
149149test "peer type resolution: [0]u8 and []const u8" {
150 expect(peerTypeEmptyArrayAndSlice(true, "hi").len == 0);
151 expect(peerTypeEmptyArrayAndSlice(false, "hi").len == 1);
150 try expect(peerTypeEmptyArrayAndSlice(true, "hi").len == 0);
151 try expect(peerTypeEmptyArrayAndSlice(false, "hi").len == 1);
152152 comptime {
153 expect(peerTypeEmptyArrayAndSlice(true, "hi").len == 0);
154 expect(peerTypeEmptyArrayAndSlice(false, "hi").len == 1);
153 try expect(peerTypeEmptyArrayAndSlice(true, "hi").len == 0);
154 try expect(peerTypeEmptyArrayAndSlice(false, "hi").len == 1);
155155 }
156156}
157157fn peerTypeEmptyArrayAndSlice(a: bool, slice: []const u8) []const u8 {
......@@ -163,8 +163,8 @@ fn peerTypeEmptyArrayAndSlice(a: bool, slice: []const u8) []const u8 {
163163}
164164
165165test "implicitly cast from [N]T to ?[]const T" {
166 expect(mem.eql(u8, castToOptionalSlice().?, "hi"));
167 comptime expect(mem.eql(u8, castToOptionalSlice().?, "hi"));
166 try expect(mem.eql(u8, castToOptionalSlice().?, "hi"));
167 comptime try expect(mem.eql(u8, castToOptionalSlice().?, "hi"));
168168}
169169
170170fn castToOptionalSlice() ?[]const u8 {
......@@ -172,12 +172,12 @@ fn castToOptionalSlice() ?[]const u8 {
172172}
173173
174174test "implicitly cast from [0]T to anyerror![]T" {
175 testCastZeroArrayToErrSliceMut();
176 comptime testCastZeroArrayToErrSliceMut();
175 try testCastZeroArrayToErrSliceMut();
176 comptime try testCastZeroArrayToErrSliceMut();
177177}
178178
179fn testCastZeroArrayToErrSliceMut() void {
180 expect((gimmeErrOrSlice() catch unreachable).len == 0);
179fn testCastZeroArrayToErrSliceMut() !void {
180 try expect((gimmeErrOrSlice() catch unreachable).len == 0);
181181}
182182
183183fn gimmeErrOrSlice() anyerror![]u8 {
......@@ -190,19 +190,19 @@ test "peer type resolution: [0]u8, []const u8, and anyerror![]u8" {
190190 {
191191 var data = "hi".*;
192192 const slice = data[0..];
193 expect((try peerTypeEmptyArrayAndSliceAndError(true, slice)).len == 0);
194 expect((try peerTypeEmptyArrayAndSliceAndError(false, slice)).len == 1);
193 try expect((try peerTypeEmptyArrayAndSliceAndError(true, slice)).len == 0);
194 try expect((try peerTypeEmptyArrayAndSliceAndError(false, slice)).len == 1);
195195 }
196196 {
197197 var data: [2]u8 = "hi".*;
198198 const slice = data[0..];
199 expect((try peerTypeEmptyArrayAndSliceAndError(true, slice)).len == 0);
200 expect((try peerTypeEmptyArrayAndSliceAndError(false, slice)).len == 1);
199 try expect((try peerTypeEmptyArrayAndSliceAndError(true, slice)).len == 0);
200 try expect((try peerTypeEmptyArrayAndSliceAndError(false, slice)).len == 1);
201201 }
202202 }
203203 };
204204 try S.doTheTest();
205 try comptime S.doTheTest();
205 comptime try S.doTheTest();
206206}
207207fn peerTypeEmptyArrayAndSliceAndError(a: bool, slice: []u8) anyerror![]u8 {
208208 if (a) {
......@@ -213,43 +213,43 @@ fn peerTypeEmptyArrayAndSliceAndError(a: bool, slice: []u8) anyerror![]u8 {
213213}
214214
215215test "resolve undefined with integer" {
216 testResolveUndefWithInt(true, 1234);
217 comptime testResolveUndefWithInt(true, 1234);
216 try testResolveUndefWithInt(true, 1234);
217 comptime try testResolveUndefWithInt(true, 1234);
218218}
219fn testResolveUndefWithInt(b: bool, x: i32) void {
219fn testResolveUndefWithInt(b: bool, x: i32) !void {
220220 const value = if (b) x else undefined;
221221 if (b) {
222 expect(value == x);
222 try expect(value == x);
223223 }
224224}
225225
226226test "implicit cast from &const [N]T to []const T" {
227 testCastConstArrayRefToConstSlice();
228 comptime testCastConstArrayRefToConstSlice();
227 try testCastConstArrayRefToConstSlice();
228 comptime try testCastConstArrayRefToConstSlice();
229229}
230230
231fn testCastConstArrayRefToConstSlice() void {
231fn testCastConstArrayRefToConstSlice() !void {
232232 {
233233 const blah = "aoeu".*;
234234 const const_array_ref = &blah;
235 expect(@TypeOf(const_array_ref) == *const [4:0]u8);
235 try expect(@TypeOf(const_array_ref) == *const [4:0]u8);
236236 const slice: []const u8 = const_array_ref;
237 expect(mem.eql(u8, slice, "aoeu"));
237 try expect(mem.eql(u8, slice, "aoeu"));
238238 }
239239 {
240240 const blah: [4]u8 = "aoeu".*;
241241 const const_array_ref = &blah;
242 expect(@TypeOf(const_array_ref) == *const [4]u8);
242 try expect(@TypeOf(const_array_ref) == *const [4]u8);
243243 const slice: []const u8 = const_array_ref;
244 expect(mem.eql(u8, slice, "aoeu"));
244 try expect(mem.eql(u8, slice, "aoeu"));
245245 }
246246}
247247
248248test "peer type resolution: error and [N]T" {
249 expect(mem.eql(u8, try testPeerErrorAndArray(0), "OK"));
250 comptime expect(mem.eql(u8, try testPeerErrorAndArray(0), "OK"));
251 expect(mem.eql(u8, try testPeerErrorAndArray2(1), "OKK"));
252 comptime expect(mem.eql(u8, try testPeerErrorAndArray2(1), "OKK"));
249 try expect(mem.eql(u8, try testPeerErrorAndArray(0), "OK"));
250 comptime try expect(mem.eql(u8, try testPeerErrorAndArray(0), "OK"));
251 try expect(mem.eql(u8, try testPeerErrorAndArray2(1), "OKK"));
252 comptime try expect(mem.eql(u8, try testPeerErrorAndArray2(1), "OKK"));
253253}
254254
255255fn testPeerErrorAndArray(x: u8) anyerror![]const u8 {
......@@ -267,35 +267,35 @@ fn testPeerErrorAndArray2(x: u8) anyerror![]const u8 {
267267}
268268
269269test "@floatToInt" {
270 testFloatToInts();
271 comptime testFloatToInts();
270 try testFloatToInts();
271 comptime try testFloatToInts();
272272}
273273
274fn testFloatToInts() void {
274fn testFloatToInts() !void {
275275 const x = @as(i32, 1e4);
276 expect(x == 10000);
276 try expect(x == 10000);
277277 const y = @floatToInt(i32, @as(f32, 1e4));
278 expect(y == 10000);
279 expectFloatToInt(f16, 255.1, u8, 255);
280 expectFloatToInt(f16, 127.2, i8, 127);
281 expectFloatToInt(f16, -128.2, i8, -128);
282 expectFloatToInt(f32, 255.1, u8, 255);
283 expectFloatToInt(f32, 127.2, i8, 127);
284 expectFloatToInt(f32, -128.2, i8, -128);
285 expectFloatToInt(comptime_int, 1234, i16, 1234);
278 try expect(y == 10000);
279 try expectFloatToInt(f16, 255.1, u8, 255);
280 try expectFloatToInt(f16, 127.2, i8, 127);
281 try expectFloatToInt(f16, -128.2, i8, -128);
282 try expectFloatToInt(f32, 255.1, u8, 255);
283 try expectFloatToInt(f32, 127.2, i8, 127);
284 try expectFloatToInt(f32, -128.2, i8, -128);
285 try expectFloatToInt(comptime_int, 1234, i16, 1234);
286286}
287287
288fn expectFloatToInt(comptime F: type, f: F, comptime I: type, i: I) void {
289 expect(@floatToInt(I, f) == i);
288fn expectFloatToInt(comptime F: type, f: F, comptime I: type, i: I) !void {
289 try expect(@floatToInt(I, f) == i);
290290}
291291
292292test "cast u128 to f128 and back" {
293 comptime testCast128();
294 testCast128();
293 comptime try testCast128();
294 try testCast128();
295295}
296296
297fn testCast128() void {
298 expect(cast128Int(cast128Float(0x7fff0000000000000000000000000000)) == 0x7fff0000000000000000000000000000);
297fn testCast128() !void {
298 try expect(cast128Int(cast128Float(0x7fff0000000000000000000000000000)) == 0x7fff0000000000000000000000000000);
299299}
300300
301301fn cast128Int(x: f128) u128 {
......@@ -307,69 +307,69 @@ fn cast128Float(x: u128) f128 {
307307}
308308
309309test "single-item pointer of array to slice and to unknown length pointer" {
310 testCastPtrOfArrayToSliceAndPtr();
311 comptime testCastPtrOfArrayToSliceAndPtr();
310 try testCastPtrOfArrayToSliceAndPtr();
311 comptime try testCastPtrOfArrayToSliceAndPtr();
312312}
313313
314fn testCastPtrOfArrayToSliceAndPtr() void {
314fn testCastPtrOfArrayToSliceAndPtr() !void {
315315 {
316316 var array = "aoeu".*;
317317 const x: [*]u8 = &array;
318318 x[0] += 1;
319 expect(mem.eql(u8, array[0..], "boeu"));
319 try expect(mem.eql(u8, array[0..], "boeu"));
320320 const y: []u8 = &array;
321321 y[0] += 1;
322 expect(mem.eql(u8, array[0..], "coeu"));
322 try expect(mem.eql(u8, array[0..], "coeu"));
323323 }
324324 {
325325 var array: [4]u8 = "aoeu".*;
326326 const x: [*]u8 = &array;
327327 x[0] += 1;
328 expect(mem.eql(u8, array[0..], "boeu"));
328 try expect(mem.eql(u8, array[0..], "boeu"));
329329 const y: []u8 = &array;
330330 y[0] += 1;
331 expect(mem.eql(u8, array[0..], "coeu"));
331 try expect(mem.eql(u8, array[0..], "coeu"));
332332 }
333333}
334334
335335test "cast *[1][*]const u8 to [*]const ?[*]const u8" {
336336 const window_name = [1][*]const u8{"window name"};
337337 const x: [*]const ?[*]const u8 = &window_name;
338 expect(mem.eql(u8, std.mem.spanZ(@ptrCast([*:0]const u8, x[0].?)), "window name"));
338 try expect(mem.eql(u8, std.mem.spanZ(@ptrCast([*:0]const u8, x[0].?)), "window name"));
339339}
340340
341341test "@intCast comptime_int" {
342342 const result = @intCast(i32, 1234);
343 expect(@TypeOf(result) == i32);
344 expect(result == 1234);
343 try expect(@TypeOf(result) == i32);
344 try expect(result == 1234);
345345}
346346
347347test "@floatCast comptime_int and comptime_float" {
348348 {
349349 const result = @floatCast(f16, 1234);
350 expect(@TypeOf(result) == f16);
351 expect(result == 1234.0);
350 try expect(@TypeOf(result) == f16);
351 try expect(result == 1234.0);
352352 }
353353 {
354354 const result = @floatCast(f16, 1234.0);
355 expect(@TypeOf(result) == f16);
356 expect(result == 1234.0);
355 try expect(@TypeOf(result) == f16);
356 try expect(result == 1234.0);
357357 }
358358 {
359359 const result = @floatCast(f32, 1234);
360 expect(@TypeOf(result) == f32);
361 expect(result == 1234.0);
360 try expect(@TypeOf(result) == f32);
361 try expect(result == 1234.0);
362362 }
363363 {
364364 const result = @floatCast(f32, 1234.0);
365 expect(@TypeOf(result) == f32);
366 expect(result == 1234.0);
365 try expect(@TypeOf(result) == f32);
366 try expect(result == 1234.0);
367367 }
368368}
369369
370370test "vector casts" {
371371 const S = struct {
372 fn doTheTest() void {
372 fn doTheTest() !void {
373373 // Upcast (implicit, equivalent to @intCast)
374374 var up0: Vector(2, u8) = [_]u8{ 0x55, 0xaa };
375375 var up1 = @as(Vector(2, u16), up0);
......@@ -381,55 +381,55 @@ test "vector casts" {
381381 var down2 = @intCast(Vector(2, u16), down0);
382382 var down3 = @intCast(Vector(2, u8), down0);
383383
384 expect(mem.eql(u16, &@as([2]u16, up1), &[2]u16{ 0x55, 0xaa }));
385 expect(mem.eql(u32, &@as([2]u32, up2), &[2]u32{ 0x55, 0xaa }));
386 expect(mem.eql(u64, &@as([2]u64, up3), &[2]u64{ 0x55, 0xaa }));
384 try expect(mem.eql(u16, &@as([2]u16, up1), &[2]u16{ 0x55, 0xaa }));
385 try expect(mem.eql(u32, &@as([2]u32, up2), &[2]u32{ 0x55, 0xaa }));
386 try expect(mem.eql(u64, &@as([2]u64, up3), &[2]u64{ 0x55, 0xaa }));
387387
388 expect(mem.eql(u32, &@as([2]u32, down1), &[2]u32{ 0x55, 0xaa }));
389 expect(mem.eql(u16, &@as([2]u16, down2), &[2]u16{ 0x55, 0xaa }));
390 expect(mem.eql(u8, &@as([2]u8, down3), &[2]u8{ 0x55, 0xaa }));
388 try expect(mem.eql(u32, &@as([2]u32, down1), &[2]u32{ 0x55, 0xaa }));
389 try expect(mem.eql(u16, &@as([2]u16, down2), &[2]u16{ 0x55, 0xaa }));
390 try expect(mem.eql(u8, &@as([2]u8, down3), &[2]u8{ 0x55, 0xaa }));
391391 }
392392
393 fn doTheTestFloat() void {
393 fn doTheTestFloat() !void {
394394 var vec = @splat(2, @as(f32, 1234.0));
395395 var wider: Vector(2, f64) = vec;
396 expect(wider[0] == 1234.0);
397 expect(wider[1] == 1234.0);
396 try expect(wider[0] == 1234.0);
397 try expect(wider[1] == 1234.0);
398398 }
399399 };
400400
401 S.doTheTest();
402 comptime S.doTheTest();
403 S.doTheTestFloat();
404 comptime S.doTheTestFloat();
401 try S.doTheTest();
402 comptime try S.doTheTest();
403 try S.doTheTestFloat();
404 comptime try S.doTheTestFloat();
405405}
406406
407407test "comptime_int @intToFloat" {
408408 {
409409 const result = @intToFloat(f16, 1234);
410 expect(@TypeOf(result) == f16);
411 expect(result == 1234.0);
410 try expect(@TypeOf(result) == f16);
411 try expect(result == 1234.0);
412412 }
413413 {
414414 const result = @intToFloat(f32, 1234);
415 expect(@TypeOf(result) == f32);
416 expect(result == 1234.0);
415 try expect(@TypeOf(result) == f32);
416 try expect(result == 1234.0);
417417 }
418418 {
419419 const result = @intToFloat(f64, 1234);
420 expect(@TypeOf(result) == f64);
421 expect(result == 1234.0);
420 try expect(@TypeOf(result) == f64);
421 try expect(result == 1234.0);
422422 }
423423 {
424424 const result = @intToFloat(f128, 1234);
425 expect(@TypeOf(result) == f128);
426 expect(result == 1234.0);
425 try expect(@TypeOf(result) == f128);
426 try expect(result == 1234.0);
427427 }
428428 // big comptime_int (> 64 bits) to f128 conversion
429429 {
430430 const result = @intToFloat(f128, 0x1_0000_0000_0000_0000);
431 expect(@TypeOf(result) == f128);
432 expect(result == 0x1_0000_0000_0000_0000.0);
431 try expect(@TypeOf(result) == f128);
432 try expect(result == 0x1_0000_0000_0000_0000.0);
433433 }
434434}
435435
......@@ -437,25 +437,25 @@ test "@intCast i32 to u7" {
437437 var x: u128 = maxInt(u128);
438438 var y: i32 = 120;
439439 var z = x >> @intCast(u7, y);
440 expect(z == 0xff);
440 try expect(z == 0xff);
441441}
442442
443443test "@floatCast cast down" {
444444 {
445445 var double: f64 = 0.001534;
446446 var single = @floatCast(f32, double);
447 expect(single == 0.001534);
447 try expect(single == 0.001534);
448448 }
449449 {
450450 const double: f64 = 0.001534;
451451 const single = @floatCast(f32, double);
452 expect(single == 0.001534);
452 try expect(single == 0.001534);
453453 }
454454}
455455
456456test "implicit cast undefined to optional" {
457 expect(MakeType(void).getNull() == null);
458 expect(MakeType(void).getNonNull() != null);
457 try expect(MakeType(void).getNull() == null);
458 try expect(MakeType(void).getNonNull() != null);
459459}
460460
461461fn MakeType(comptime T: type) type {
......@@ -475,26 +475,26 @@ test "implicit cast from *[N]T to ?[*]T" {
475475 var y: [4]u16 = [4]u16{ 0, 1, 2, 3 };
476476
477477 x = &y;
478 expect(std.mem.eql(u16, x.?[0..4], y[0..4]));
478 try expect(std.mem.eql(u16, x.?[0..4], y[0..4]));
479479 x.?[0] = 8;
480480 y[3] = 6;
481 expect(std.mem.eql(u16, x.?[0..4], y[0..4]));
481 try expect(std.mem.eql(u16, x.?[0..4], y[0..4]));
482482}
483483
484484test "implicit cast from *[N]T to [*c]T" {
485485 var x: [4]u16 = [4]u16{ 0, 1, 2, 3 };
486486 var y: [*c]u16 = &x;
487487
488 expect(std.mem.eql(u16, x[0..4], y[0..4]));
488 try expect(std.mem.eql(u16, x[0..4], y[0..4]));
489489 x[0] = 8;
490490 y[3] = 6;
491 expect(std.mem.eql(u16, x[0..4], y[0..4]));
491 try expect(std.mem.eql(u16, x[0..4], y[0..4]));
492492}
493493
494494test "implicit cast from *T to ?*c_void" {
495495 var a: u8 = 1;
496496 incrementVoidPtrValue(&a);
497 std.testing.expect(a == 2);
497 try std.testing.expect(a == 2);
498498}
499499
500500fn incrementVoidPtrValue(value: ?*c_void) void {
......@@ -505,7 +505,7 @@ test "implicit cast from [*]T to ?*c_void" {
505505 var a = [_]u8{ 3, 2, 1 };
506506 var runtime_zero: usize = 0;
507507 incrementVoidPtrArray(a[runtime_zero..].ptr, 3);
508 expect(std.mem.eql(u8, &a, &[_]u8{ 4, 3, 2 }));
508 try expect(std.mem.eql(u8, &a, &[_]u8{ 4, 3, 2 }));
509509}
510510
511511fn incrementVoidPtrArray(array: ?*c_void, len: usize) void {
......@@ -522,34 +522,34 @@ test "*usize to *void" {
522522}
523523
524524test "compile time int to ptr of function" {
525 foobar(FUNCTION_CONSTANT);
525 try foobar(FUNCTION_CONSTANT);
526526}
527527
528528pub const FUNCTION_CONSTANT = @intToPtr(PFN_void, maxInt(usize));
529529pub const PFN_void = fn (*c_void) callconv(.C) void;
530530
531fn foobar(func: PFN_void) void {
532 std.testing.expect(@ptrToInt(func) == maxInt(usize));
531fn foobar(func: PFN_void) !void {
532 try std.testing.expect(@ptrToInt(func) == maxInt(usize));
533533}
534534
535535test "implicit ptr to *c_void" {
536536 var a: u32 = 1;
537537 var ptr: *align(@alignOf(u32)) c_void = &a;
538538 var b: *u32 = @ptrCast(*u32, ptr);
539 expect(b.* == 1);
539 try expect(b.* == 1);
540540 var ptr2: ?*align(@alignOf(u32)) c_void = &a;
541541 var c: *u32 = @ptrCast(*u32, ptr2.?);
542 expect(c.* == 1);
542 try expect(c.* == 1);
543543}
544544
545545test "@intCast to comptime_int" {
546 expect(@intCast(comptime_int, 0) == 0);
546 try expect(@intCast(comptime_int, 0) == 0);
547547}
548548
549549test "implicit cast comptime numbers to any type when the value fits" {
550550 const a: u64 = 255;
551551 var b: u8 = a;
552 expect(b == 255);
552 try expect(b == 255);
553553}
554554
555555test "@intToEnum passed a comptime_int to an enum with one item" {
......@@ -557,7 +557,7 @@ test "@intToEnum passed a comptime_int to an enum with one item" {
557557 A,
558558 };
559559 const x = @intToEnum(E, 0);
560 expect(x == E.A);
560 try expect(x == E.A);
561561}
562562
563563test "@intToEnum runtime to an extern enum with duplicate values" {
......@@ -567,33 +567,33 @@ test "@intToEnum runtime to an extern enum with duplicate values" {
567567 };
568568 var a: u8 = 1;
569569 var x = @intToEnum(E, a);
570 expect(x == E.A);
571 expect(x == E.B);
570 try expect(x == E.A);
571 try expect(x == E.B);
572572}
573573
574574test "@intCast to u0 and use the result" {
575575 const S = struct {
576 fn doTheTest(zero: u1, one: u1, bigzero: i32) void {
577 expect((one << @intCast(u0, bigzero)) == 1);
578 expect((zero << @intCast(u0, bigzero)) == 0);
576 fn doTheTest(zero: u1, one: u1, bigzero: i32) !void {
577 try expect((one << @intCast(u0, bigzero)) == 1);
578 try expect((zero << @intCast(u0, bigzero)) == 0);
579579 }
580580 };
581 S.doTheTest(0, 1, 0);
582 comptime S.doTheTest(0, 1, 0);
581 try S.doTheTest(0, 1, 0);
582 comptime try S.doTheTest(0, 1, 0);
583583}
584584
585585test "peer type resolution: unreachable, null, slice" {
586586 const S = struct {
587 fn doTheTest(num: usize, word: []const u8) void {
587 fn doTheTest(num: usize, word: []const u8) !void {
588588 const result = switch (num) {
589589 0 => null,
590590 1 => word,
591591 else => unreachable,
592592 };
593 expect(mem.eql(u8, result.?, "hi"));
593 try expect(mem.eql(u8, result.?, "hi"));
594594 }
595595 };
596 S.doTheTest(1, "hi");
596 try S.doTheTest(1, "hi");
597597}
598598
599599test "peer type resolution: unreachable, error set, unreachable" {
......@@ -616,17 +616,17 @@ test "peer type resolution: unreachable, error set, unreachable" {
616616 error.FileDescriptorIncompatibleWithEpoll => unreachable,
617617 error.Unexpected => unreachable,
618618 };
619 expect(transformed_err == error.SystemResources);
619 try expect(transformed_err == error.SystemResources);
620620}
621621
622622test "implicit cast comptime_int to comptime_float" {
623 comptime expect(@as(comptime_float, 10) == @as(f32, 10));
624 expect(2 == 2.0);
623 comptime try expect(@as(comptime_float, 10) == @as(f32, 10));
624 try expect(2 == 2.0);
625625}
626626
627627test "implicit cast *[0]T to E![]const u8" {
628628 var x = @as(anyerror![]const u8, &[0]u8{});
629 expect((x catch unreachable).len == 0);
629 try expect((x catch unreachable).len == 0);
630630}
631631
632632test "peer cast *[0]T to E![]const T" {
......@@ -634,7 +634,7 @@ test "peer cast *[0]T to E![]const T" {
634634 var buf: anyerror![]const u8 = buffer[0..];
635635 var b = false;
636636 var y = if (b) &[0]u8{} else buf;
637 expect(mem.eql(u8, "abcde", y catch unreachable));
637 try expect(mem.eql(u8, "abcde", y catch unreachable));
638638}
639639
640640test "peer cast *[0]T to []const T" {
......@@ -642,25 +642,25 @@ test "peer cast *[0]T to []const T" {
642642 var buf: []const u8 = buffer[0..];
643643 var b = false;
644644 var y = if (b) &[0]u8{} else buf;
645 expect(mem.eql(u8, "abcde", y));
645 try expect(mem.eql(u8, "abcde", y));
646646}
647647
648648var global_array: [4]u8 = undefined;
649649test "cast from array reference to fn" {
650650 const f = @ptrCast(fn () callconv(.C) void, &global_array);
651 expect(@ptrToInt(f) == @ptrToInt(&global_array));
651 try expect(@ptrToInt(f) == @ptrToInt(&global_array));
652652}
653653
654654test "*const [N]null u8 to ?[]const u8" {
655655 const S = struct {
656 fn doTheTest() void {
656 fn doTheTest() !void {
657657 var a = "Hello";
658658 var b: ?[]const u8 = a;
659 expect(mem.eql(u8, b.?, "Hello"));
659 try expect(mem.eql(u8, b.?, "Hello"));
660660 }
661661 };
662 S.doTheTest();
663 comptime S.doTheTest();
662 try S.doTheTest();
663 comptime try S.doTheTest();
664664}
665665
666666test "peer resolution of string literals" {
......@@ -672,54 +672,54 @@ test "peer resolution of string literals" {
672672 d,
673673 };
674674
675 fn doTheTest(e: E) void {
675 fn doTheTest(e: E) !void {
676676 const cmd = switch (e) {
677677 .a => "one",
678678 .b => "two",
679679 .c => "three",
680680 .d => "four",
681681 };
682 expect(mem.eql(u8, cmd, "two"));
682 try expect(mem.eql(u8, cmd, "two"));
683683 }
684684 };
685 S.doTheTest(.b);
686 comptime S.doTheTest(.b);
685 try S.doTheTest(.b);
686 comptime try S.doTheTest(.b);
687687}
688688
689689test "type coercion related to sentinel-termination" {
690690 const S = struct {
691 fn doTheTest() void {
691 fn doTheTest() !void {
692692 // [:x]T to []T
693693 {
694694 var array = [4:0]i32{ 1, 2, 3, 4 };
695695 var slice: [:0]i32 = &array;
696696 var dest: []i32 = slice;
697 expect(mem.eql(i32, dest, &[_]i32{ 1, 2, 3, 4 }));
697 try expect(mem.eql(i32, dest, &[_]i32{ 1, 2, 3, 4 }));
698698 }
699699
700700 // [*:x]T to [*]T
701701 {
702702 var array = [4:99]i32{ 1, 2, 3, 4 };
703703 var dest: [*]i32 = &array;
704 expect(dest[0] == 1);
705 expect(dest[1] == 2);
706 expect(dest[2] == 3);
707 expect(dest[3] == 4);
708 expect(dest[4] == 99);
704 try expect(dest[0] == 1);
705 try expect(dest[1] == 2);
706 try expect(dest[2] == 3);
707 try expect(dest[3] == 4);
708 try expect(dest[4] == 99);
709709 }
710710
711711 // [N:x]T to [N]T
712712 {
713713 var array = [4:0]i32{ 1, 2, 3, 4 };
714714 var dest: [4]i32 = array;
715 expect(mem.eql(i32, &dest, &[_]i32{ 1, 2, 3, 4 }));
715 try expect(mem.eql(i32, &dest, &[_]i32{ 1, 2, 3, 4 }));
716716 }
717717
718718 // *[N:x]T to *[N]T
719719 {
720720 var array = [4:0]i32{ 1, 2, 3, 4 };
721721 var dest: *[4]i32 = &array;
722 expect(mem.eql(i32, dest, &[_]i32{ 1, 2, 3, 4 }));
722 try expect(mem.eql(i32, dest, &[_]i32{ 1, 2, 3, 4 }));
723723 }
724724
725725 // [:x]T to [*:x]T
......@@ -727,24 +727,24 @@ test "type coercion related to sentinel-termination" {
727727 var array = [4:0]i32{ 1, 2, 3, 4 };
728728 var slice: [:0]i32 = &array;
729729 var dest: [*:0]i32 = slice;
730 expect(dest[0] == 1);
731 expect(dest[1] == 2);
732 expect(dest[2] == 3);
733 expect(dest[3] == 4);
734 expect(dest[4] == 0);
730 try expect(dest[0] == 1);
731 try expect(dest[1] == 2);
732 try expect(dest[2] == 3);
733 try expect(dest[3] == 4);
734 try expect(dest[4] == 0);
735735 }
736736 }
737737 };
738 S.doTheTest();
739 comptime S.doTheTest();
738 try S.doTheTest();
739 comptime try S.doTheTest();
740740}
741741
742742test "cast i8 fn call peers to i32 result" {
743743 const S = struct {
744 fn doTheTest() void {
744 fn doTheTest() !void {
745745 var cond = true;
746746 const value: i32 = if (cond) smallBoi() else bigBoi();
747 expect(value == 123);
747 try expect(value == 123);
748748 }
749749 fn smallBoi() i8 {
750750 return 123;
......@@ -753,21 +753,21 @@ test "cast i8 fn call peers to i32 result" {
753753 return 1234;
754754 }
755755 };
756 S.doTheTest();
757 comptime S.doTheTest();
756 try S.doTheTest();
757 comptime try S.doTheTest();
758758}
759759
760760test "return u8 coercing into ?u32 return type" {
761761 const S = struct {
762 fn doTheTest() void {
763 expect(foo(123).? == 123);
762 fn doTheTest() !void {
763 try expect(foo(123).? == 123);
764764 }
765765 fn foo(arg: u8) ?u32 {
766766 return arg;
767767 }
768768 };
769 S.doTheTest();
770 comptime S.doTheTest();
769 try S.doTheTest();
770 comptime try S.doTheTest();
771771}
772772
773773test "peer result null and comptime_int" {
......@@ -783,17 +783,17 @@ test "peer result null and comptime_int" {
783783 }
784784 };
785785
786 expect(S.blah(0) == null);
787 comptime expect(S.blah(0) == null);
788 expect(S.blah(10).? == 1);
789 comptime expect(S.blah(10).? == 1);
790 expect(S.blah(-10).? == -1);
791 comptime expect(S.blah(-10).? == -1);
786 try expect(S.blah(0) == null);
787 comptime try expect(S.blah(0) == null);
788 try expect(S.blah(10).? == 1);
789 comptime try expect(S.blah(10).? == 1);
790 try expect(S.blah(-10).? == -1);
791 comptime try expect(S.blah(-10).? == -1);
792792}
793793
794794test "peer type resolution implicit cast to return type" {
795795 const S = struct {
796 fn doTheTest() void {
796 fn doTheTest() !void {
797797 for ("hello") |c| _ = f(c);
798798 }
799799 fn f(c: u8) []const u8 {
......@@ -804,13 +804,13 @@ test "peer type resolution implicit cast to return type" {
804804 };
805805 }
806806 };
807 S.doTheTest();
808 comptime S.doTheTest();
807 try S.doTheTest();
808 comptime try S.doTheTest();
809809}
810810
811811test "peer type resolution implicit cast to variable type" {
812812 const S = struct {
813 fn doTheTest() void {
813 fn doTheTest() !void {
814814 var x: []const u8 = undefined;
815815 for ("hello") |c| x = switch (c) {
816816 'h', 'e' => &[_]u8{c}, // should cast to slice
......@@ -819,14 +819,14 @@ test "peer type resolution implicit cast to variable type" {
819819 };
820820 }
821821 };
822 S.doTheTest();
823 comptime S.doTheTest();
822 try S.doTheTest();
823 comptime try S.doTheTest();
824824}
825825
826826test "variable initialization uses result locations properly with regards to the type" {
827827 var b = true;
828828 const x: i32 = if (b) 1 else 2;
829 expect(x == 1);
829 try expect(x == 1);
830830}
831831
832832test "cast between [*c]T and ?[*:0]T on fn parameter" {
......@@ -848,27 +848,27 @@ test "cast between C pointer with different but compatible types" {
848848 fn foo(arg: [*]c_ushort) u16 {
849849 return arg[0];
850850 }
851 fn doTheTest() void {
851 fn doTheTest() !void {
852852 var x = [_]u16{ 4, 2, 1, 3 };
853 expect(foo(@ptrCast([*]u16, &x)) == 4);
853 try expect(foo(@ptrCast([*]u16, &x)) == 4);
854854 }
855855 };
856 S.doTheTest();
856 try S.doTheTest();
857857}
858858
859859var global_struct: struct { f0: usize } = undefined;
860860
861861test "assignment to optional pointer result loc" {
862862 var foo: struct { ptr: ?*c_void } = .{ .ptr = &global_struct };
863 expect(foo.ptr.? == @ptrCast(*c_void, &global_struct));
863 try expect(foo.ptr.? == @ptrCast(*c_void, &global_struct));
864864}
865865
866866test "peer type resolve string lit with sentinel-terminated mutable slice" {
867867 var array: [4:0]u8 = undefined;
868868 array[4] = 0; // TODO remove this when #4372 is solved
869869 var slice: [:0]u8 = array[0..4 :0];
870 comptime expect(@TypeOf(slice, "hi") == [:0]const u8);
871 comptime expect(@TypeOf("hi", slice) == [:0]const u8);
870 comptime try expect(@TypeOf(slice, "hi") == [:0]const u8);
871 comptime try expect(@TypeOf("hi", slice) == [:0]const u8);
872872}
873873
874874test "peer type unsigned int to signed" {
......@@ -876,15 +876,15 @@ test "peer type unsigned int to signed" {
876876 var x: u8 = 7;
877877 var y: i32 = -5;
878878 var a = w + y + x;
879 comptime expect(@TypeOf(a) == i32);
880 expect(a == 7);
879 comptime try expect(@TypeOf(a) == i32);
880 try expect(a == 7);
881881}
882882
883883test "peer type resolve array pointers, one of them const" {
884884 var array1: [4]u8 = undefined;
885885 const array2: [5]u8 = undefined;
886 comptime expect(@TypeOf(&array1, &array2) == []const u8);
887 comptime expect(@TypeOf(&array2, &array1) == []const u8);
886 comptime try expect(@TypeOf(&array1, &array2) == []const u8);
887 comptime try expect(@TypeOf(&array2, &array1) == []const u8);
888888}
889889
890890test "peer type resolve array pointer and unknown pointer" {
......@@ -893,35 +893,35 @@ test "peer type resolve array pointer and unknown pointer" {
893893 var const_ptr: [*]const u8 = undefined;
894894 var ptr: [*]u8 = undefined;
895895
896 comptime expect(@TypeOf(&array, ptr) == [*]u8);
897 comptime expect(@TypeOf(ptr, &array) == [*]u8);
896 comptime try expect(@TypeOf(&array, ptr) == [*]u8);
897 comptime try expect(@TypeOf(ptr, &array) == [*]u8);
898898
899 comptime expect(@TypeOf(&const_array, ptr) == [*]const u8);
900 comptime expect(@TypeOf(ptr, &const_array) == [*]const u8);
899 comptime try expect(@TypeOf(&const_array, ptr) == [*]const u8);
900 comptime try expect(@TypeOf(ptr, &const_array) == [*]const u8);
901901
902 comptime expect(@TypeOf(&array, const_ptr) == [*]const u8);
903 comptime expect(@TypeOf(const_ptr, &array) == [*]const u8);
902 comptime try expect(@TypeOf(&array, const_ptr) == [*]const u8);
903 comptime try expect(@TypeOf(const_ptr, &array) == [*]const u8);
904904
905 comptime expect(@TypeOf(&const_array, const_ptr) == [*]const u8);
906 comptime expect(@TypeOf(const_ptr, &const_array) == [*]const u8);
905 comptime try expect(@TypeOf(&const_array, const_ptr) == [*]const u8);
906 comptime try expect(@TypeOf(const_ptr, &const_array) == [*]const u8);
907907}
908908
909909test "comptime float casts" {
910910 const a = @intToFloat(comptime_float, 1);
911 expect(a == 1);
912 expect(@TypeOf(a) == comptime_float);
911 try expect(a == 1);
912 try expect(@TypeOf(a) == comptime_float);
913913 const b = @floatToInt(comptime_int, 2);
914 expect(b == 2);
915 expect(@TypeOf(b) == comptime_int);
914 try expect(b == 2);
915 try expect(@TypeOf(b) == comptime_int);
916916}
917917
918918test "cast from ?[*]T to ??[*]T" {
919919 const a: ??[*]u8 = @as(?[*]u8, null);
920 expect(a != null and a.? == null);
920 try expect(a != null and a.? == null);
921921}
922922
923923test "cast between *[N]void and []void" {
924924 var a: [4]void = undefined;
925925 var b: []void = &a;
926 expect(b.len == 4);
926 try expect(b.len == 4);
927927}
test/behavior/const_slice_child.zig+8-8
......@@ -12,24 +12,24 @@ test "const slice child" {
1212 "three",
1313 };
1414 argv = &strs;
15 bar(strs.len);
15 try bar(strs.len);
1616}
1717
18fn foo(args: [][]const u8) void {
19 expect(args.len == 3);
20 expect(streql(args[0], "one"));
21 expect(streql(args[1], "two"));
22 expect(streql(args[2], "three"));
18fn foo(args: [][]const u8) !void {
19 try expect(args.len == 3);
20 try expect(streql(args[0], "one"));
21 try expect(streql(args[1], "two"));
22 try expect(streql(args[2], "three"));
2323}
2424
25fn bar(argc: usize) void {
25fn bar(argc: usize) !void {
2626 const args = testing.allocator.alloc([]const u8, argc) catch unreachable;
2727 defer testing.allocator.free(args);
2828 for (args) |_, i| {
2929 const ptr = argv[i];
3030 args[i] = ptr[0..strlen(ptr)];
3131 }
32 foo(args);
32 try foo(args);
3333}
3434
3535fn strlen(ptr: [*]const u8) usize {
test/behavior/defer.zig+20-20
......@@ -24,18 +24,18 @@ fn runSomeErrorDefers(x: bool) !bool {
2424}
2525
2626test "mixing normal and error defers" {
27 expect(runSomeErrorDefers(true) catch unreachable);
28 expect(result[0] == 'c');
29 expect(result[1] == 'a');
27 try expect(runSomeErrorDefers(true) catch unreachable);
28 try expect(result[0] == 'c');
29 try expect(result[1] == 'a');
3030
3131 const ok = runSomeErrorDefers(false) catch |err| x: {
32 expect(err == error.FalseNotAllowed);
32 try expect(err == error.FalseNotAllowed);
3333 break :x true;
3434 };
35 expect(ok);
36 expect(result[0] == 'c');
37 expect(result[1] == 'b');
38 expect(result[2] == 'a');
35 try expect(ok);
36 try expect(result[0] == 'c');
37 try expect(result[1] == 'b');
38 try expect(result[2] == 'a');
3939}
4040
4141test "break and continue inside loop inside defer expression" {
......@@ -50,7 +50,7 @@ fn testBreakContInDefer(x: usize) void {
5050 if (i < 5) continue;
5151 if (i == 5) break;
5252 }
53 expect(i == 5);
53 expect(i == 5) catch @panic("test failure");
5454 }
5555}
5656
......@@ -62,11 +62,11 @@ test "defer and labeled break" {
6262 break :blk;
6363 }
6464
65 expect(i == 1);
65 try expect(i == 1);
6666}
6767
6868test "errdefer does not apply to fn inside fn" {
69 if (testNestedFnErrDefer()) |_| @panic("expected error") else |e| expect(e == error.Bad);
69 if (testNestedFnErrDefer()) |_| @panic("expected error") else |e| try expect(e == error.Bad);
7070}
7171
7272fn testNestedFnErrDefer() anyerror!void {
......@@ -82,8 +82,8 @@ fn testNestedFnErrDefer() anyerror!void {
8282
8383test "return variable while defer expression in scope to modify it" {
8484 const S = struct {
85 fn doTheTest() void {
86 expect(notNull().? == 1);
85 fn doTheTest() !void {
86 try expect(notNull().? == 1);
8787 }
8888
8989 fn notNull() ?u8 {
......@@ -93,22 +93,22 @@ test "return variable while defer expression in scope to modify it" {
9393 }
9494 };
9595
96 S.doTheTest();
97 comptime S.doTheTest();
96 try S.doTheTest();
97 comptime try S.doTheTest();
9898}
9999
100100test "errdefer with payload" {
101101 const S = struct {
102102 fn foo() !i32 {
103103 errdefer |a| {
104 expectEqual(error.One, a);
104 expectEqual(error.One, a) catch @panic("test failure");
105105 }
106106 return error.One;
107107 }
108 fn doTheTest() void {
109 expectError(error.One, foo());
108 fn doTheTest() !void {
109 try expectError(error.One, foo());
110110 }
111111 };
112 S.doTheTest();
113 comptime S.doTheTest();
112 try S.doTheTest();
113 comptime try S.doTheTest();
114114}
test/behavior/enum.zig+112-112
......@@ -29,41 +29,41 @@ test "non-exhaustive enum" {
2929 b,
3030 _,
3131 };
32 fn doTheTest(y: u8) void {
32 fn doTheTest(y: u8) !void {
3333 var e: E = .b;
34 expect(switch (e) {
34 try expect(switch (e) {
3535 .a => false,
3636 .b => true,
3737 _ => false,
3838 });
3939 e = @intToEnum(E, 12);
40 expect(switch (e) {
40 try expect(switch (e) {
4141 .a => false,
4242 .b => false,
4343 _ => true,
4444 });
4545
46 expect(switch (e) {
46 try expect(switch (e) {
4747 .a => false,
4848 .b => false,
4949 else => true,
5050 });
5151 e = .b;
52 expect(switch (e) {
52 try expect(switch (e) {
5353 .a => false,
5454 else => true,
5555 });
5656
57 expect(@typeInfo(E).Enum.fields.len == 2);
57 try expect(@typeInfo(E).Enum.fields.len == 2);
5858 e = @intToEnum(E, 12);
59 expect(@enumToInt(e) == 12);
59 try expect(@enumToInt(e) == 12);
6060 e = @intToEnum(E, y);
61 expect(@enumToInt(e) == 52);
62 expect(@typeInfo(E).Enum.is_exhaustive == false);
61 try expect(@enumToInt(e) == 52);
62 try expect(@typeInfo(E).Enum.is_exhaustive == false);
6363 }
6464 };
65 S.doTheTest(52);
66 comptime S.doTheTest(52);
65 try S.doTheTest(52);
66 comptime try S.doTheTest(52);
6767}
6868
6969test "empty non-exhaustive enum" {
......@@ -71,19 +71,19 @@ test "empty non-exhaustive enum" {
7171 const E = enum(u8) {
7272 _,
7373 };
74 fn doTheTest(y: u8) void {
74 fn doTheTest(y: u8) !void {
7575 var e = @intToEnum(E, y);
76 expect(switch (e) {
76 try expect(switch (e) {
7777 _ => true,
7878 });
79 expect(@enumToInt(e) == y);
79 try expect(@enumToInt(e) == y);
8080
81 expect(@typeInfo(E).Enum.fields.len == 0);
82 expect(@typeInfo(E).Enum.is_exhaustive == false);
81 try expect(@typeInfo(E).Enum.fields.len == 0);
82 try expect(@typeInfo(E).Enum.is_exhaustive == false);
8383 }
8484 };
85 S.doTheTest(42);
86 comptime S.doTheTest(42);
85 try S.doTheTest(42);
86 comptime try S.doTheTest(42);
8787}
8888
8989test "single field non-exhaustive enum" {
......@@ -92,35 +92,35 @@ test "single field non-exhaustive enum" {
9292 a,
9393 _,
9494 };
95 fn doTheTest(y: u8) void {
95 fn doTheTest(y: u8) !void {
9696 var e: E = .a;
97 expect(switch (e) {
97 try expect(switch (e) {
9898 .a => true,
9999 _ => false,
100100 });
101101 e = @intToEnum(E, 12);
102 expect(switch (e) {
102 try expect(switch (e) {
103103 .a => false,
104104 _ => true,
105105 });
106106
107 expect(switch (e) {
107 try expect(switch (e) {
108108 .a => false,
109109 else => true,
110110 });
111111 e = .a;
112 expect(switch (e) {
112 try expect(switch (e) {
113113 .a => true,
114114 else => false,
115115 });
116116
117 expect(@enumToInt(@intToEnum(E, y)) == y);
118 expect(@typeInfo(E).Enum.fields.len == 1);
119 expect(@typeInfo(E).Enum.is_exhaustive == false);
117 try expect(@enumToInt(@intToEnum(E, y)) == y);
118 try expect(@typeInfo(E).Enum.fields.len == 1);
119 try expect(@typeInfo(E).Enum.is_exhaustive == false);
120120 }
121121 };
122 S.doTheTest(23);
123 comptime S.doTheTest(23);
122 try S.doTheTest(23);
123 comptime try S.doTheTest(23);
124124}
125125
126126test "enum type" {
......@@ -133,16 +133,16 @@ test "enum type" {
133133 };
134134 const bar = Bar.B;
135135
136 expect(bar == Bar.B);
137 expect(@typeInfo(Foo).Union.fields.len == 3);
138 expect(@typeInfo(Bar).Enum.fields.len == 4);
139 expect(@sizeOf(Foo) == @sizeOf(FooNoVoid));
140 expect(@sizeOf(Bar) == 1);
136 try expect(bar == Bar.B);
137 try expect(@typeInfo(Foo).Union.fields.len == 3);
138 try expect(@typeInfo(Bar).Enum.fields.len == 4);
139 try expect(@sizeOf(Foo) == @sizeOf(FooNoVoid));
140 try expect(@sizeOf(Bar) == 1);
141141}
142142
143143test "enum as return value" {
144144 switch (returnAnInt(13)) {
145 Foo.One => |value| expect(value == 13),
145 Foo.One => |value| try expect(value == 13),
146146 else => unreachable,
147147 }
148148}
......@@ -206,22 +206,22 @@ const Number = enum {
206206};
207207
208208test "enum to int" {
209 shouldEqual(Number.Zero, 0);
210 shouldEqual(Number.One, 1);
211 shouldEqual(Number.Two, 2);
212 shouldEqual(Number.Three, 3);
213 shouldEqual(Number.Four, 4);
209 try shouldEqual(Number.Zero, 0);
210 try shouldEqual(Number.One, 1);
211 try shouldEqual(Number.Two, 2);
212 try shouldEqual(Number.Three, 3);
213 try shouldEqual(Number.Four, 4);
214214}
215215
216fn shouldEqual(n: Number, expected: u3) void {
217 expect(@enumToInt(n) == expected);
216fn shouldEqual(n: Number, expected: u3) !void {
217 try expect(@enumToInt(n) == expected);
218218}
219219
220220test "int to enum" {
221 testIntToEnumEval(3);
221 try testIntToEnumEval(3);
222222}
223fn testIntToEnumEval(x: i32) void {
224 expect(@intToEnum(IntToEnumNumber, @intCast(u3, x)) == IntToEnumNumber.Three);
223fn testIntToEnumEval(x: i32) !void {
224 try expect(@intToEnum(IntToEnumNumber, @intCast(u3, x)) == IntToEnumNumber.Three);
225225}
226226const IntToEnumNumber = enum {
227227 Zero,
......@@ -232,18 +232,18 @@ const IntToEnumNumber = enum {
232232};
233233
234234test "@tagName" {
235 expect(mem.eql(u8, testEnumTagNameBare(BareNumber.Three), "Three"));
236 comptime expect(mem.eql(u8, testEnumTagNameBare(BareNumber.Three), "Three"));
235 try expect(mem.eql(u8, testEnumTagNameBare(BareNumber.Three), "Three"));
236 comptime try expect(mem.eql(u8, testEnumTagNameBare(BareNumber.Three), "Three"));
237237}
238238
239239test "@tagName extern enum with duplicates" {
240 expect(mem.eql(u8, testEnumTagNameBare(ExternDuplicates.B), "A"));
241 comptime expect(mem.eql(u8, testEnumTagNameBare(ExternDuplicates.B), "A"));
240 try expect(mem.eql(u8, testEnumTagNameBare(ExternDuplicates.B), "A"));
241 comptime try expect(mem.eql(u8, testEnumTagNameBare(ExternDuplicates.B), "A"));
242242}
243243
244244test "@tagName non-exhaustive enum" {
245 expect(mem.eql(u8, testEnumTagNameBare(NonExhaustive.B), "B"));
246 comptime expect(mem.eql(u8, testEnumTagNameBare(NonExhaustive.B), "B"));
245 try expect(mem.eql(u8, testEnumTagNameBare(NonExhaustive.B), "B"));
246 comptime try expect(mem.eql(u8, testEnumTagNameBare(NonExhaustive.B), "B"));
247247}
248248
249249fn testEnumTagNameBare(n: anytype) []const u8 {
......@@ -269,8 +269,8 @@ const NonExhaustive = enum(u8) {
269269
270270test "enum alignment" {
271271 comptime {
272 expect(@alignOf(AlignTestEnum) >= @alignOf([9]u8));
273 expect(@alignOf(AlignTestEnum) >= @alignOf(u64));
272 try expect(@alignOf(AlignTestEnum) >= @alignOf([9]u8));
273 try expect(@alignOf(AlignTestEnum) >= @alignOf(u64));
274274 }
275275}
276276
......@@ -806,10 +806,10 @@ const ValueCount257 = enum {
806806
807807test "enum sizes" {
808808 comptime {
809 expect(@sizeOf(ValueCount1) == 0);
810 expect(@sizeOf(ValueCount2) == 1);
811 expect(@sizeOf(ValueCount256) == 1);
812 expect(@sizeOf(ValueCount257) == 2);
809 try expect(@sizeOf(ValueCount1) == 0);
810 try expect(@sizeOf(ValueCount2) == 1);
811 try expect(@sizeOf(ValueCount256) == 1);
812 try expect(@sizeOf(ValueCount257) == 2);
813813 }
814814}
815815
......@@ -828,12 +828,12 @@ test "set enum tag type" {
828828 {
829829 var x = Small.One;
830830 x = Small.Two;
831 comptime expect(Tag(Small) == u2);
831 comptime try expect(Tag(Small) == u2);
832832 }
833833 {
834834 var x = Small2.One;
835835 x = Small2.Two;
836 comptime expect(Tag(Small2) == u2);
836 comptime try expect(Tag(Small2) == u2);
837837 }
838838}
839839
......@@ -880,17 +880,17 @@ const bit_field_1 = BitFieldOfEnums{
880880
881881test "bit field access with enum fields" {
882882 var data = bit_field_1;
883 expect(getA(&data) == A.Two);
884 expect(getB(&data) == B.Three3);
885 expect(getC(&data) == C.Four4);
886 comptime expect(@sizeOf(BitFieldOfEnums) == 1);
883 try expect(getA(&data) == A.Two);
884 try expect(getB(&data) == B.Three3);
885 try expect(getC(&data) == C.Four4);
886 comptime try expect(@sizeOf(BitFieldOfEnums) == 1);
887887
888888 data.b = B.Four3;
889 expect(data.b == B.Four3);
889 try expect(data.b == B.Four3);
890890
891891 data.a = A.Three;
892 expect(data.a == A.Three);
893 expect(data.b == B.Four3);
892 try expect(data.a == A.Three);
893 try expect(data.b == B.Four3);
894894}
895895
896896fn getA(data: *const BitFieldOfEnums) A {
......@@ -906,12 +906,12 @@ fn getC(data: *const BitFieldOfEnums) C {
906906}
907907
908908test "casting enum to its tag type" {
909 testCastEnumTag(Small2.Two);
910 comptime testCastEnumTag(Small2.Two);
909 try testCastEnumTag(Small2.Two);
910 comptime try testCastEnumTag(Small2.Two);
911911}
912912
913fn testCastEnumTag(value: Small2) void {
914 expect(@enumToInt(value) == 1);
913fn testCastEnumTag(value: Small2) !void {
914 try expect(@enumToInt(value) == 1);
915915}
916916
917917const MultipleChoice = enum(u32) {
......@@ -922,13 +922,13 @@ const MultipleChoice = enum(u32) {
922922};
923923
924924test "enum with specified tag values" {
925 testEnumWithSpecifiedTagValues(MultipleChoice.C);
926 comptime testEnumWithSpecifiedTagValues(MultipleChoice.C);
925 try testEnumWithSpecifiedTagValues(MultipleChoice.C);
926 comptime try testEnumWithSpecifiedTagValues(MultipleChoice.C);
927927}
928928
929fn testEnumWithSpecifiedTagValues(x: MultipleChoice) void {
930 expect(@enumToInt(x) == 60);
931 expect(1234 == switch (x) {
929fn testEnumWithSpecifiedTagValues(x: MultipleChoice) !void {
930 try expect(@enumToInt(x) == 60);
931 try expect(1234 == switch (x) {
932932 MultipleChoice.A => 1,
933933 MultipleChoice.B => 2,
934934 MultipleChoice.C => @as(u32, 1234),
......@@ -949,13 +949,13 @@ const MultipleChoice2 = enum(u32) {
949949};
950950
951951test "enum with specified and unspecified tag values" {
952 testEnumWithSpecifiedAndUnspecifiedTagValues(MultipleChoice2.D);
953 comptime testEnumWithSpecifiedAndUnspecifiedTagValues(MultipleChoice2.D);
952 try testEnumWithSpecifiedAndUnspecifiedTagValues(MultipleChoice2.D);
953 comptime try testEnumWithSpecifiedAndUnspecifiedTagValues(MultipleChoice2.D);
954954}
955955
956fn testEnumWithSpecifiedAndUnspecifiedTagValues(x: MultipleChoice2) void {
957 expect(@enumToInt(x) == 1000);
958 expect(1234 == switch (x) {
956fn testEnumWithSpecifiedAndUnspecifiedTagValues(x: MultipleChoice2) !void {
957 try expect(@enumToInt(x) == 1000);
958 try expect(1234 == switch (x) {
959959 MultipleChoice2.A => 1,
960960 MultipleChoice2.B => 2,
961961 MultipleChoice2.C => 3,
......@@ -969,8 +969,8 @@ fn testEnumWithSpecifiedAndUnspecifiedTagValues(x: MultipleChoice2) void {
969969}
970970
971971test "cast integer literal to enum" {
972 expect(@intToEnum(MultipleChoice2, 0) == MultipleChoice2.Unspecified1);
973 expect(@intToEnum(MultipleChoice2, 40) == MultipleChoice2.B);
972 try expect(@intToEnum(MultipleChoice2, 0) == MultipleChoice2.Unspecified1);
973 try expect(@intToEnum(MultipleChoice2, 40) == MultipleChoice2.B);
974974}
975975
976976const EnumWithOneMember = enum {
......@@ -1008,14 +1008,14 @@ const EnumWithTagValues = enum(u4) {
10081008 D = 1 << 3,
10091009};
10101010test "enum with tag values don't require parens" {
1011 expect(@enumToInt(EnumWithTagValues.C) == 0b0100);
1011 try expect(@enumToInt(EnumWithTagValues.C) == 0b0100);
10121012}
10131013
10141014test "enum with 1 field but explicit tag type should still have the tag type" {
10151015 const Enum = enum(u8) {
10161016 B = 2,
10171017 };
1018 comptime @import("std").testing.expect(@sizeOf(Enum) == @sizeOf(u8));
1018 comptime try expect(@sizeOf(Enum) == @sizeOf(u8));
10191019}
10201020
10211021test "empty extern enum with members" {
......@@ -1024,7 +1024,7 @@ test "empty extern enum with members" {
10241024 B,
10251025 C,
10261026 };
1027 expect(@sizeOf(E) == @sizeOf(c_int));
1027 try expect(@sizeOf(E) == @sizeOf(c_int));
10281028}
10291029
10301030test "tag name with assigned enum values" {
......@@ -1033,7 +1033,7 @@ test "tag name with assigned enum values" {
10331033 B = 0,
10341034 };
10351035 var b = LocalFoo.B;
1036 expect(mem.eql(u8, @tagName(b), "B"));
1036 try expect(mem.eql(u8, @tagName(b), "B"));
10371037}
10381038
10391039test "enum literal equality" {
......@@ -1041,8 +1041,8 @@ test "enum literal equality" {
10411041 const y = .ok;
10421042 const z = .hi;
10431043
1044 expect(x != y);
1045 expect(x == z);
1044 try expect(x != y);
1045 try expect(x == z);
10461046}
10471047
10481048test "enum literal cast to enum" {
......@@ -1054,7 +1054,7 @@ test "enum literal cast to enum" {
10541054
10551055 var color1: Color = .Auto;
10561056 var color2 = Color.Auto;
1057 expect(color1 == color2);
1057 try expect(color1 == color2);
10581058}
10591059
10601060test "peer type resolution with enum literal" {
......@@ -1063,8 +1063,8 @@ test "peer type resolution with enum literal" {
10631063 two,
10641064 };
10651065
1066 expect(Items.two == .two);
1067 expect(.two == Items.two);
1066 try expect(Items.two == .two);
1067 try expect(.two == Items.two);
10681068}
10691069
10701070test "enum literal in array literal" {
......@@ -1078,8 +1078,8 @@ test "enum literal in array literal" {
10781078 .two,
10791079 };
10801080
1081 expect(array[0] == .one);
1082 expect(array[1] == .two);
1081 try expect(array[0] == .one);
1082 try expect(array[1] == .two);
10831083}
10841084
10851085test "signed integer as enum tag" {
......@@ -1089,9 +1089,9 @@ test "signed integer as enum tag" {
10891089 A2 = 1,
10901090 };
10911091
1092 expect(@enumToInt(SignedEnum.A0) == -1);
1093 expect(@enumToInt(SignedEnum.A1) == 0);
1094 expect(@enumToInt(SignedEnum.A2) == 1);
1092 try expect(@enumToInt(SignedEnum.A0) == -1);
1093 try expect(@enumToInt(SignedEnum.A1) == 0);
1094 try expect(@enumToInt(SignedEnum.A2) == 1);
10951095}
10961096
10971097test "enum value allocation" {
......@@ -1101,9 +1101,9 @@ test "enum value allocation" {
11011101 A2,
11021102 };
11031103
1104 expect(@enumToInt(LargeEnum.A0) == 0x80000000);
1105 expect(@enumToInt(LargeEnum.A1) == 0x80000001);
1106 expect(@enumToInt(LargeEnum.A2) == 0x80000002);
1104 try expect(@enumToInt(LargeEnum.A0) == 0x80000000);
1105 try expect(@enumToInt(LargeEnum.A1) == 0x80000001);
1106 try expect(@enumToInt(LargeEnum.A2) == 0x80000002);
11071107}
11081108
11091109test "enum literal casting to tagged union" {
......@@ -1130,32 +1130,32 @@ test "enum with one member and custom tag type" {
11301130 const E = enum(u2) {
11311131 One,
11321132 };
1133 expect(@enumToInt(E.One) == 0);
1133 try expect(@enumToInt(E.One) == 0);
11341134 const E2 = enum(u2) {
11351135 One = 2,
11361136 };
1137 expect(@enumToInt(E2.One) == 2);
1137 try expect(@enumToInt(E2.One) == 2);
11381138}
11391139
11401140test "enum literal casting to optional" {
11411141 var bar: ?Bar = undefined;
11421142 bar = .B;
11431143
1144 expect(bar.? == Bar.B);
1144 try expect(bar.? == Bar.B);
11451145}
11461146
11471147test "enum literal casting to error union with payload enum" {
11481148 var bar: error{B}!Bar = undefined;
11491149 bar = .B; // should never cast to the error set
11501150
1151 expect((try bar) == Bar.B);
1151 try expect((try bar) == Bar.B);
11521152}
11531153
11541154test "enum with one member and u1 tag type @enumToInt" {
11551155 const Enum = enum(u1) {
11561156 Test,
11571157 };
1158 expect(@enumToInt(Enum.Test) == 0);
1158 try expect(@enumToInt(Enum.Test) == 0);
11591159}
11601160
11611161test "enum with comptime_int tag type" {
......@@ -1164,19 +1164,19 @@ test "enum with comptime_int tag type" {
11641164 Two = 2,
11651165 Three = 1,
11661166 };
1167 comptime expect(Tag(Enum) == comptime_int);
1167 comptime try expect(Tag(Enum) == comptime_int);
11681168}
11691169
11701170test "enum with one member default to u0 tag type" {
11711171 const E0 = enum {
11721172 X,
11731173 };
1174 comptime expect(Tag(E0) == u0);
1174 comptime try expect(Tag(E0) == u0);
11751175}
11761176
11771177test "tagName on enum literals" {
1178 expect(mem.eql(u8, @tagName(.FooBar), "FooBar"));
1179 comptime expect(mem.eql(u8, @tagName(.FooBar), "FooBar"));
1178 try expect(mem.eql(u8, @tagName(.FooBar), "FooBar"));
1179 comptime try expect(mem.eql(u8, @tagName(.FooBar), "FooBar"));
11801180}
11811181
11821182test "method call on an enum" {
......@@ -1193,12 +1193,12 @@ test "method call on an enum" {
11931193 return self.* == .two and foo == bool;
11941194 }
11951195 };
1196 fn doTheTest() void {
1196 fn doTheTest() !void {
11971197 var e = E.two;
1198 expect(e.method());
1199 expect(e.generic_method(bool));
1198 try expect(e.method());
1199 try expect(e.generic_method(bool));
12001200 }
12011201 };
1202 S.doTheTest();
1203 comptime S.doTheTest();
1202 try S.doTheTest();
1203 comptime try S.doTheTest();
12041204}
test/behavior/enum_with_members.zig+4-4
......@@ -19,9 +19,9 @@ test "enum with members" {
1919 const b = ET{ .UINT = 42 };
2020 var buf: [20]u8 = undefined;
2121
22 expect((a.print(buf[0..]) catch unreachable) == 3);
23 expect(mem.eql(u8, buf[0..3], "-42"));
22 try expect((a.print(buf[0..]) catch unreachable) == 3);
23 try expect(mem.eql(u8, buf[0..3], "-42"));
2424
25 expect((b.print(buf[0..]) catch unreachable) == 2);
26 expect(mem.eql(u8, buf[0..2], "42"));
25 try expect((b.print(buf[0..]) catch unreachable) == 2);
26 try expect(mem.eql(u8, buf[0..2], "42"));
2727}
test/behavior/error.zig+60-60
......@@ -19,7 +19,7 @@ pub fn baz() anyerror!i32 {
1919}
2020
2121test "error wrapping" {
22 expect((baz() catch unreachable) == 15);
22 try expect((baz() catch unreachable) == 15);
2323}
2424
2525fn gimmeItBroke() []const u8 {
......@@ -27,14 +27,14 @@ fn gimmeItBroke() []const u8 {
2727}
2828
2929test "@errorName" {
30 expect(mem.eql(u8, @errorName(error.AnError), "AnError"));
31 expect(mem.eql(u8, @errorName(error.ALongerErrorName), "ALongerErrorName"));
30 try expect(mem.eql(u8, @errorName(error.AnError), "AnError"));
31 try expect(mem.eql(u8, @errorName(error.ALongerErrorName), "ALongerErrorName"));
3232}
3333
3434test "error values" {
3535 const a = @errorToInt(error.err1);
3636 const b = @errorToInt(error.err2);
37 expect(a != b);
37 try expect(a != b);
3838}
3939
4040test "redefinition of error values allowed" {
......@@ -47,8 +47,8 @@ fn shouldBeNotEqual(a: anyerror, b: anyerror) void {
4747test "error binary operator" {
4848 const a = errBinaryOperatorG(true) catch 3;
4949 const b = errBinaryOperatorG(false) catch 3;
50 expect(a == 3);
51 expect(b == 10);
50 try expect(a == 3);
51 try expect(b == 10);
5252}
5353fn errBinaryOperatorG(x: bool) anyerror!isize {
5454 return if (x) error.ItBroke else @as(isize, 10);
......@@ -56,7 +56,7 @@ fn errBinaryOperatorG(x: bool) anyerror!isize {
5656
5757test "unwrap simple value from error" {
5858 const i = unwrapSimpleValueFromErrorDo() catch unreachable;
59 expect(i == 13);
59 try expect(i == 13);
6060}
6161fn unwrapSimpleValueFromErrorDo() anyerror!isize {
6262 return 13;
......@@ -76,21 +76,21 @@ fn makeANonErr() anyerror!i32 {
7676}
7777
7878test "error union type " {
79 testErrorUnionType();
80 comptime testErrorUnionType();
79 try testErrorUnionType();
80 comptime try testErrorUnionType();
8181}
8282
83fn testErrorUnionType() void {
83fn testErrorUnionType() !void {
8484 const x: anyerror!i32 = 1234;
85 if (x) |value| expect(value == 1234) else |_| unreachable;
86 expect(@typeInfo(@TypeOf(x)) == .ErrorUnion);
87 expect(@typeInfo(@typeInfo(@TypeOf(x)).ErrorUnion.error_set) == .ErrorSet);
88 expect(@typeInfo(@TypeOf(x)).ErrorUnion.error_set == anyerror);
85 if (x) |value| try expect(value == 1234) else |_| unreachable;
86 try expect(@typeInfo(@TypeOf(x)) == .ErrorUnion);
87 try expect(@typeInfo(@typeInfo(@TypeOf(x)).ErrorUnion.error_set) == .ErrorSet);
88 try expect(@typeInfo(@TypeOf(x)).ErrorUnion.error_set == anyerror);
8989}
9090
9191test "error set type" {
92 testErrorSetType();
93 comptime testErrorSetType();
92 try testErrorSetType();
93 comptime try testErrorSetType();
9494}
9595
9696const MyErrSet = error{
......@@ -98,21 +98,21 @@ const MyErrSet = error{
9898 FileNotFound,
9999};
100100
101fn testErrorSetType() void {
102 expect(@typeInfo(MyErrSet).ErrorSet.?.len == 2);
101fn testErrorSetType() !void {
102 try expect(@typeInfo(MyErrSet).ErrorSet.?.len == 2);
103103
104104 const a: MyErrSet!i32 = 5678;
105105 const b: MyErrSet!i32 = MyErrSet.OutOfMemory;
106106
107 if (a) |value| expect(value == 5678) else |err| switch (err) {
107 if (a) |value| try expect(value == 5678) else |err| switch (err) {
108108 error.OutOfMemory => unreachable,
109109 error.FileNotFound => unreachable,
110110 }
111111}
112112
113113test "explicit error set cast" {
114 testExplicitErrorSetCast(Set1.A);
115 comptime testExplicitErrorSetCast(Set1.A);
114 try testExplicitErrorSetCast(Set1.A);
115 comptime try testExplicitErrorSetCast(Set1.A);
116116}
117117
118118const Set1 = error{
......@@ -124,26 +124,26 @@ const Set2 = error{
124124 C,
125125};
126126
127fn testExplicitErrorSetCast(set1: Set1) void {
127fn testExplicitErrorSetCast(set1: Set1) !void {
128128 var x = @errSetCast(Set2, set1);
129129 var y = @errSetCast(Set1, x);
130 expect(y == error.A);
130 try expect(y == error.A);
131131}
132132
133133test "comptime test error for empty error set" {
134 testComptimeTestErrorEmptySet(1234);
135 comptime testComptimeTestErrorEmptySet(1234);
134 try testComptimeTestErrorEmptySet(1234);
135 comptime try testComptimeTestErrorEmptySet(1234);
136136}
137137
138138const EmptyErrorSet = error{};
139139
140fn testComptimeTestErrorEmptySet(x: EmptyErrorSet!i32) void {
141 if (x) |v| expect(v == 1234) else |err| @compileError("bad");
140fn testComptimeTestErrorEmptySet(x: EmptyErrorSet!i32) !void {
141 if (x) |v| try expect(v == 1234) else |err| @compileError("bad");
142142}
143143
144144test "syntax: optional operator in front of error union operator" {
145145 comptime {
146 expect(?(anyerror!i32) == ?(anyerror!i32));
146 try expect(?(anyerror!i32) == ?(anyerror!i32));
147147 }
148148}
149149
......@@ -165,10 +165,10 @@ test "empty error union" {
165165}
166166
167167test "error union peer type resolution" {
168 testErrorUnionPeerTypeResolution(1);
168 try testErrorUnionPeerTypeResolution(1);
169169}
170170
171fn testErrorUnionPeerTypeResolution(x: i32) void {
171fn testErrorUnionPeerTypeResolution(x: i32) !void {
172172 const y = switch (x) {
173173 1 => bar_1(),
174174 2 => baz_1(),
......@@ -177,7 +177,7 @@ fn testErrorUnionPeerTypeResolution(x: i32) void {
177177 if (y) |_| {
178178 @panic("expected error");
179179 } else |e| {
180 expect(e == error.A);
180 try expect(e == error.A);
181181 }
182182}
183183
......@@ -286,13 +286,13 @@ test "nested error union function call in optional unwrap" {
286286 return null;
287287 }
288288 };
289 expect((try S.errorable()) == 1234);
290 expectError(error.Failure, S.errorable2());
291 expectError(error.Other, S.errorable3());
289 try expect((try S.errorable()) == 1234);
290 try expectError(error.Failure, S.errorable2());
291 try expectError(error.Other, S.errorable3());
292292 comptime {
293 expect((try S.errorable()) == 1234);
294 expectError(error.Failure, S.errorable2());
295 expectError(error.Other, S.errorable3());
293 try expect((try S.errorable()) == 1234);
294 try expectError(error.Failure, S.errorable2());
295 try expectError(error.Other, S.errorable3());
296296 }
297297}
298298
......@@ -307,7 +307,7 @@ test "widen cast integer payload of error union function call" {
307307 return 1234;
308308 }
309309 };
310 expect((try S.errorable()) == 1234);
310 try expect((try S.errorable()) == 1234);
311311}
312312
313313test "return function call to error set from error union function" {
......@@ -320,19 +320,19 @@ test "return function call to error set from error union function" {
320320 return error.Failure;
321321 }
322322 };
323 expectError(error.Failure, S.errorable());
324 comptime expectError(error.Failure, S.errorable());
323 try expectError(error.Failure, S.errorable());
324 comptime try expectError(error.Failure, S.errorable());
325325}
326326
327327test "optional error set is the same size as error set" {
328 comptime expect(@sizeOf(?anyerror) == @sizeOf(anyerror));
328 comptime try expect(@sizeOf(?anyerror) == @sizeOf(anyerror));
329329 const S = struct {
330330 fn returnsOptErrSet() ?anyerror {
331331 return null;
332332 }
333333 };
334 expect(S.returnsOptErrSet() == null);
335 comptime expect(S.returnsOptErrSet() == null);
334 try expect(S.returnsOptErrSet() == null);
335 comptime try expect(S.returnsOptErrSet() == null);
336336}
337337
338338test "debug info for optional error set" {
......@@ -342,8 +342,8 @@ test "debug info for optional error set" {
342342
343343test "nested catch" {
344344 const S = struct {
345 fn entry() void {
346 expectError(error.Bad, func());
345 fn entry() !void {
346 try expectError(error.Bad, func());
347347 }
348348 fn fail() anyerror!Foo {
349349 return error.Wrong;
......@@ -358,16 +358,16 @@ test "nested catch" {
358358 field: i32,
359359 };
360360 };
361 S.entry();
362 comptime S.entry();
361 try S.entry();
362 comptime try S.entry();
363363}
364364
365365test "implicit cast to optional to error union to return result loc" {
366366 const S = struct {
367 fn entry() void {
367 fn entry() !void {
368368 var x: Foo = undefined;
369369 if (func(&x)) |opt| {
370 expect(opt != null);
370 try expect(opt != null);
371371 } else |_| @panic("expected non error");
372372 }
373373 fn func(f: *Foo) anyerror!?*Foo {
......@@ -377,7 +377,7 @@ test "implicit cast to optional to error union to return result loc" {
377377 field: i32,
378378 };
379379 };
380 S.entry();
380 try S.entry();
381381 //comptime S.entry(); TODO
382382}
383383
......@@ -393,23 +393,23 @@ test "function pointer with return type that is error union with payload which i
393393 return Err.UnspecifiedErr;
394394 }
395395
396 fn doTheTest() void {
396 fn doTheTest() !void {
397397 var x = Foo{ .fun = bar };
398 expectError(error.UnspecifiedErr, x.fun(1));
398 try expectError(error.UnspecifiedErr, x.fun(1));
399399 }
400400 };
401 S.doTheTest();
401 try S.doTheTest();
402402}
403403
404404test "return result loc as peer result loc in inferred error set function" {
405405 const S = struct {
406 fn doTheTest() void {
406 fn doTheTest() !void {
407407 if (foo(2)) |x| {
408 expect(x.Two);
408 try expect(x.Two);
409409 } else |e| switch (e) {
410410 error.Whatever => @panic("fail"),
411411 }
412 expectError(error.Whatever, foo(99));
412 try expectError(error.Whatever, foo(99));
413413 }
414414 const FormValue = union(enum) {
415415 One: void,
......@@ -424,8 +424,8 @@ test "return result loc as peer result loc in inferred error set function" {
424424 };
425425 }
426426 };
427 S.doTheTest();
428 comptime S.doTheTest();
427 try S.doTheTest();
428 comptime try S.doTheTest();
429429}
430430
431431test "error payload type is correctly resolved" {
......@@ -439,7 +439,7 @@ test "error payload type is correctly resolved" {
439439 }
440440 };
441441
442 expectEqual(MyIntWrapper{ .x = 42 }, try MyIntWrapper.create());
442 try expectEqual(MyIntWrapper{ .x = 42 }, try MyIntWrapper.create());
443443}
444444
445445test "error union comptime caching" {
......@@ -449,4 +449,4 @@ test "error union comptime caching" {
449449
450450 S.foo(@as(anyerror!void, {}));
451451 S.foo(@as(anyerror!void, {}));
452}
\ No newline at end of file
452}
test/behavior/eval.zig+119-119
......@@ -3,7 +3,7 @@ const expect = std.testing.expect;
33const expectEqual = std.testing.expectEqual;
44
55test "compile time recursion" {
6 expect(some_data.len == 21);
6 try expect(some_data.len == 21);
77}
88var some_data: [@intCast(usize, fibonacci(7))]u8 = undefined;
99fn fibonacci(x: i32) i32 {
......@@ -16,7 +16,7 @@ fn unwrapAndAddOne(blah: ?i32) i32 {
1616}
1717const should_be_1235 = unwrapAndAddOne(1234);
1818test "static add one" {
19 expect(should_be_1235 == 1235);
19 try expect(should_be_1235 == 1235);
2020}
2121
2222test "inlined loop" {
......@@ -24,7 +24,7 @@ test "inlined loop" {
2424 comptime var sum = 0;
2525 inline while (i <= 5) : (i += 1)
2626 sum += i;
27 expect(sum == 15);
27 try expect(sum == 15);
2828}
2929
3030fn gimme1or2(comptime a: bool) i32 {
......@@ -34,12 +34,12 @@ fn gimme1or2(comptime a: bool) i32 {
3434 return z;
3535}
3636test "inline variable gets result of const if" {
37 expect(gimme1or2(true) == 1);
38 expect(gimme1or2(false) == 2);
37 try expect(gimme1or2(true) == 1);
38 try expect(gimme1or2(false) == 2);
3939}
4040
4141test "static function evaluation" {
42 expect(statically_added_number == 3);
42 try expect(statically_added_number == 3);
4343}
4444const statically_added_number = staticAdd(1, 2);
4545fn staticAdd(a: i32, b: i32) i32 {
......@@ -47,8 +47,8 @@ fn staticAdd(a: i32, b: i32) i32 {
4747}
4848
4949test "const expr eval on single expr blocks" {
50 expect(constExprEvalOnSingleExprBlocksFn(1, true) == 3);
51 comptime expect(constExprEvalOnSingleExprBlocksFn(1, true) == 3);
50 try expect(constExprEvalOnSingleExprBlocksFn(1, true) == 3);
51 comptime try expect(constExprEvalOnSingleExprBlocksFn(1, true) == 3);
5252}
5353
5454fn constExprEvalOnSingleExprBlocksFn(x: i32, b: bool) i32 {
......@@ -64,10 +64,10 @@ fn constExprEvalOnSingleExprBlocksFn(x: i32, b: bool) i32 {
6464}
6565
6666test "statically initialized list" {
67 expect(static_point_list[0].x == 1);
68 expect(static_point_list[0].y == 2);
69 expect(static_point_list[1].x == 3);
70 expect(static_point_list[1].y == 4);
67 try expect(static_point_list[0].x == 1);
68 try expect(static_point_list[0].y == 2);
69 try expect(static_point_list[1].x == 3);
70 try expect(static_point_list[1].y == 4);
7171}
7272const Point = struct {
7373 x: i32,
......@@ -85,8 +85,8 @@ fn makePoint(x: i32, y: i32) Point {
8585}
8686
8787test "static eval list init" {
88 expect(static_vec3.data[2] == 1.0);
89 expect(vec3(0.0, 0.0, 3.0).data[2] == 3.0);
88 try expect(static_vec3.data[2] == 1.0);
89 try expect(vec3(0.0, 0.0, 3.0).data[2] == 3.0);
9090}
9191const static_vec3 = vec3(0.0, 0.0, 1.0);
9292pub const Vec3 = struct {
......@@ -104,12 +104,12 @@ pub fn vec3(x: f32, y: f32, z: f32) Vec3 {
104104
105105test "constant expressions" {
106106 var array: [array_size]u8 = undefined;
107 expect(@sizeOf(@TypeOf(array)) == 20);
107 try expect(@sizeOf(@TypeOf(array)) == 20);
108108}
109109const array_size: u8 = 20;
110110
111111test "constant struct with negation" {
112 expect(vertices[0].x == -0.6);
112 try expect(vertices[0].x == -0.6);
113113}
114114const Vertex = struct {
115115 x: f32,
......@@ -144,7 +144,7 @@ const vertices = [_]Vertex{
144144
145145test "statically initialized struct" {
146146 st_init_str_foo.x += 1;
147 expect(st_init_str_foo.x == 14);
147 try expect(st_init_str_foo.x == 14);
148148}
149149const StInitStrFoo = struct {
150150 x: i32,
......@@ -157,7 +157,7 @@ var st_init_str_foo = StInitStrFoo{
157157
158158test "statically initalized array literal" {
159159 const y: [4]u8 = st_init_arr_lit_x;
160 expect(y[3] == 4);
160 try expect(y[3] == 4);
161161}
162162const st_init_arr_lit_x = [_]u8{
163163 1,
......@@ -169,15 +169,15 @@ const st_init_arr_lit_x = [_]u8{
169169test "const slice" {
170170 comptime {
171171 const a = "1234567890";
172 expect(a.len == 10);
172 try expect(a.len == 10);
173173 const b = a[1..2];
174 expect(b.len == 1);
175 expect(b[0] == '2');
174 try expect(b.len == 1);
175 try expect(b[0] == '2');
176176 }
177177}
178178
179179test "try to trick eval with runtime if" {
180 expect(testTryToTrickEvalWithRuntimeIf(true) == 10);
180 try expect(testTryToTrickEvalWithRuntimeIf(true) == 10);
181181}
182182
183183fn testTryToTrickEvalWithRuntimeIf(b: bool) usize {
......@@ -197,7 +197,7 @@ test "inlined loop has array literal with elided runtime scope on first iteratio
197197 const result = if (i == 0) [1]i32{2} else runtime;
198198 }
199199 comptime {
200 expect(i == 2);
200 try expect(i == 2);
201201 }
202202}
203203
......@@ -214,16 +214,16 @@ fn letsTryToCompareBools(a: bool, b: bool) bool {
214214 return max(bool, a, b);
215215}
216216test "inlined block and runtime block phi" {
217 expect(letsTryToCompareBools(true, true));
218 expect(letsTryToCompareBools(true, false));
219 expect(letsTryToCompareBools(false, true));
220 expect(!letsTryToCompareBools(false, false));
217 try expect(letsTryToCompareBools(true, true));
218 try expect(letsTryToCompareBools(true, false));
219 try expect(letsTryToCompareBools(false, true));
220 try expect(!letsTryToCompareBools(false, false));
221221
222222 comptime {
223 expect(letsTryToCompareBools(true, true));
224 expect(letsTryToCompareBools(true, false));
225 expect(letsTryToCompareBools(false, true));
226 expect(!letsTryToCompareBools(false, false));
223 try expect(letsTryToCompareBools(true, true));
224 try expect(letsTryToCompareBools(true, false));
225 try expect(letsTryToCompareBools(false, true));
226 try expect(!letsTryToCompareBools(false, false));
227227 }
228228}
229229
......@@ -268,14 +268,14 @@ fn performFn(comptime prefix_char: u8, start_value: i32) i32 {
268268}
269269
270270test "comptime iterate over fn ptr list" {
271 expect(performFn('t', 1) == 6);
272 expect(performFn('o', 0) == 1);
273 expect(performFn('w', 99) == 99);
271 try expect(performFn('t', 1) == 6);
272 try expect(performFn('o', 0) == 1);
273 try expect(performFn('w', 99) == 99);
274274}
275275
276276test "eval @setRuntimeSafety at compile-time" {
277277 const result = comptime fnWithSetRuntimeSafety();
278 expect(result == 1234);
278 try expect(result == 1234);
279279}
280280
281281fn fnWithSetRuntimeSafety() i32 {
......@@ -285,7 +285,7 @@ fn fnWithSetRuntimeSafety() i32 {
285285
286286test "eval @setFloatMode at compile-time" {
287287 const result = comptime fnWithFloatMode();
288 expect(result == 1234.0);
288 try expect(result == 1234.0);
289289}
290290
291291fn fnWithFloatMode() f32 {
......@@ -306,15 +306,15 @@ var simple_struct = SimpleStruct{ .field = 1234 };
306306const bound_fn = simple_struct.method;
307307
308308test "call method on bound fn referring to var instance" {
309 expect(bound_fn() == 1237);
309 try expect(bound_fn() == 1237);
310310}
311311
312312test "ptr to local array argument at comptime" {
313313 comptime {
314314 var bytes: [10]u8 = undefined;
315315 modifySomeBytes(bytes[0..]);
316 expect(bytes[0] == 'a');
317 expect(bytes[9] == 'b');
316 try expect(bytes[0] == 'a');
317 try expect(bytes[9] == 'b');
318318 }
319319}
320320
......@@ -342,9 +342,9 @@ fn testCompTimeUIntComparisons(x: u32) void {
342342}
343343
344344test "const ptr to variable data changes at runtime" {
345 expect(foo_ref.name[0] == 'a');
345 try expect(foo_ref.name[0] == 'a');
346346 foo_ref.name = "b";
347 expect(foo_ref.name[0] == 'b');
347 try expect(foo_ref.name[0] == 'b');
348348}
349349
350350const Foo = struct {
......@@ -355,8 +355,8 @@ var foo_contents = Foo{ .name = "a" };
355355const foo_ref = &foo_contents;
356356
357357test "create global array with for loop" {
358 expect(global_array[5] == 5 * 5);
359 expect(global_array[9] == 9 * 9);
358 try expect(global_array[5] == 5 * 5);
359 try expect(global_array[9] == 9 * 9);
360360}
361361
362362const global_array = x: {
......@@ -371,18 +371,18 @@ test "compile-time downcast when the bits fit" {
371371 comptime {
372372 const spartan_count: u16 = 255;
373373 const byte = @intCast(u8, spartan_count);
374 expect(byte == 255);
374 try expect(byte == 255);
375375 }
376376}
377377
378378const hi1 = "hi";
379379const hi2 = hi1;
380380test "const global shares pointer with other same one" {
381 assertEqualPtrs(&hi1[0], &hi2[0]);
382 comptime expect(&hi1[0] == &hi2[0]);
381 try assertEqualPtrs(&hi1[0], &hi2[0]);
382 comptime try expect(&hi1[0] == &hi2[0]);
383383}
384fn assertEqualPtrs(ptr1: *const u8, ptr2: *const u8) void {
385 expect(ptr1 == ptr2);
384fn assertEqualPtrs(ptr1: *const u8, ptr2: *const u8) !void {
385 try expect(ptr1 == ptr2);
386386}
387387
388388test "@setEvalBranchQuota" {
......@@ -394,29 +394,29 @@ test "@setEvalBranchQuota" {
394394 while (i < 1001) : (i += 1) {
395395 sum += i;
396396 }
397 expect(sum == 500500);
397 try expect(sum == 500500);
398398 }
399399}
400400
401401test "float literal at compile time not lossy" {
402 expect(16777216.0 + 1.0 == 16777217.0);
403 expect(9007199254740992.0 + 1.0 == 9007199254740993.0);
402 try expect(16777216.0 + 1.0 == 16777217.0);
403 try expect(9007199254740992.0 + 1.0 == 9007199254740993.0);
404404}
405405
406406test "f32 at compile time is lossy" {
407 expect(@as(f32, 1 << 24) + 1 == 1 << 24);
407 try expect(@as(f32, 1 << 24) + 1 == 1 << 24);
408408}
409409
410410test "f64 at compile time is lossy" {
411 expect(@as(f64, 1 << 53) + 1 == 1 << 53);
411 try expect(@as(f64, 1 << 53) + 1 == 1 << 53);
412412}
413413
414414test "f128 at compile time is lossy" {
415 expect(@as(f128, 10384593717069655257060992658440192.0) + 1 == 10384593717069655257060992658440192.0);
415 try expect(@as(f128, 10384593717069655257060992658440192.0) + 1 == 10384593717069655257060992658440192.0);
416416}
417417
418418comptime {
419 expect(@as(f128, 1 << 113) == 10384593717069655257060992658440192);
419 try expect(@as(f128, 1 << 113) == 10384593717069655257060992658440192);
420420}
421421
422422pub fn TypeWithCompTimeSlice(comptime field_name: []const u8) type {
......@@ -428,15 +428,15 @@ pub fn TypeWithCompTimeSlice(comptime field_name: []const u8) type {
428428test "string literal used as comptime slice is memoized" {
429429 const a = "link";
430430 const b = "link";
431 comptime expect(TypeWithCompTimeSlice(a).Node == TypeWithCompTimeSlice(b).Node);
432 comptime expect(TypeWithCompTimeSlice("link").Node == TypeWithCompTimeSlice("link").Node);
431 comptime try expect(TypeWithCompTimeSlice(a).Node == TypeWithCompTimeSlice(b).Node);
432 comptime try expect(TypeWithCompTimeSlice("link").Node == TypeWithCompTimeSlice("link").Node);
433433}
434434
435435test "comptime slice of undefined pointer of length 0" {
436436 const slice1 = @as([*]i32, undefined)[0..0];
437 expect(slice1.len == 0);
437 try expect(slice1.len == 0);
438438 const slice2 = @as([*]i32, undefined)[100..100];
439 expect(slice2.len == 0);
439 try expect(slice2.len == 0);
440440}
441441
442442fn copyWithPartialInline(s: []u32, b: []u8) void {
......@@ -458,16 +458,16 @@ test "binary math operator in partially inlined function" {
458458 r.* = @intCast(u8, i + 1);
459459
460460 copyWithPartialInline(s[0..], b[0..]);
461 expect(s[0] == 0x1020304);
462 expect(s[1] == 0x5060708);
463 expect(s[2] == 0x90a0b0c);
464 expect(s[3] == 0xd0e0f10);
461 try expect(s[0] == 0x1020304);
462 try expect(s[1] == 0x5060708);
463 try expect(s[2] == 0x90a0b0c);
464 try expect(s[3] == 0xd0e0f10);
465465}
466466
467467test "comptime function with the same args is memoized" {
468468 comptime {
469 expect(MakeType(i32) == MakeType(i32));
470 expect(MakeType(i32) != MakeType(f64));
469 try expect(MakeType(i32) == MakeType(i32));
470 try expect(MakeType(i32) != MakeType(f64));
471471 }
472472}
473473
......@@ -483,7 +483,7 @@ test "comptime function with mutable pointer is not memoized" {
483483 const ptr = &x;
484484 increment(ptr);
485485 increment(ptr);
486 expect(x == 3);
486 try expect(x == 3);
487487 }
488488}
489489
......@@ -509,14 +509,14 @@ fn doesAlotT(comptime T: type, value: usize) T {
509509}
510510
511511test "@setEvalBranchQuota at same scope as generic function call" {
512 expect(doesAlotT(u32, 2) == 2);
512 try expect(doesAlotT(u32, 2) == 2);
513513}
514514
515515test "comptime slice of slice preserves comptime var" {
516516 comptime {
517517 var buff: [10]u8 = undefined;
518518 buff[0..][0..][0] = 1;
519 expect(buff[0..][0..][0] == 1);
519 try expect(buff[0..][0..][0] == 1);
520520 }
521521}
522522
......@@ -525,7 +525,7 @@ test "comptime slice of pointer preserves comptime var" {
525525 var buff: [10]u8 = undefined;
526526 var a = @ptrCast([*]u8, &buff);
527527 a[0..1][0] = 1;
528 expect(buff[0..][0..][0] == 1);
528 try expect(buff[0..][0..][0] == 1);
529529 }
530530}
531531
......@@ -539,9 +539,9 @@ const SingleFieldStruct = struct {
539539test "const ptr to comptime mutable data is not memoized" {
540540 comptime {
541541 var foo = SingleFieldStruct{ .x = 1 };
542 expect(foo.read_x() == 1);
542 try expect(foo.read_x() == 1);
543543 foo.x = 2;
544 expect(foo.read_x() == 2);
544 try expect(foo.read_x() == 2);
545545 }
546546}
547547
......@@ -550,7 +550,7 @@ test "array concat of slices gives slice" {
550550 var a: []const u8 = "aoeu";
551551 var b: []const u8 = "asdf";
552552 const c = a ++ b;
553 expect(std.mem.eql(u8, c, "aoeuasdf"));
553 try expect(std.mem.eql(u8, c, "aoeuasdf"));
554554 }
555555}
556556
......@@ -567,14 +567,14 @@ test "comptime shlWithOverflow" {
567567 break :amt amt;
568568 };
569569
570 expect(ct_shifted == rt_shifted);
570 try expect(ct_shifted == rt_shifted);
571571}
572572
573573test "runtime 128 bit integer division" {
574574 var a: u128 = 152313999999999991610955792383;
575575 var b: u128 = 10000000000000000000;
576576 var c = a / b;
577 expect(c == 15231399999);
577 try expect(c == 15231399999);
578578}
579579
580580pub const Info = struct {
......@@ -587,20 +587,20 @@ test "comptime modification of const struct field" {
587587 comptime {
588588 var res = diamond_info;
589589 res.version = 1;
590 expect(diamond_info.version == 0);
591 expect(res.version == 1);
590 try expect(diamond_info.version == 0);
591 try expect(res.version == 1);
592592 }
593593}
594594
595595test "pointer to type" {
596596 comptime {
597597 var T: type = i32;
598 expect(T == i32);
598 try expect(T == i32);
599599 var ptr = &T;
600 expect(@TypeOf(ptr) == *type);
600 try expect(@TypeOf(ptr) == *type);
601601 ptr.* = f32;
602 expect(T == f32);
603 expect(*T == *f32);
602 try expect(T == f32);
603 try expect(*T == *f32);
604604 }
605605}
606606
......@@ -609,17 +609,17 @@ test "slice of type" {
609609 var types_array = [_]type{ i32, f64, type };
610610 for (types_array) |T, i| {
611611 switch (i) {
612 0 => expect(T == i32),
613 1 => expect(T == f64),
614 2 => expect(T == type),
612 0 => try expect(T == i32),
613 1 => try expect(T == f64),
614 2 => try expect(T == type),
615615 else => unreachable,
616616 }
617617 }
618618 for (types_array[0..]) |T, i| {
619619 switch (i) {
620 0 => expect(T == i32),
621 1 => expect(T == f64),
622 2 => expect(T == type),
620 0 => try expect(T == i32),
621 1 => try expect(T == f64),
622 2 => try expect(T == type),
623623 else => unreachable,
624624 }
625625 }
......@@ -636,7 +636,7 @@ fn wrap(comptime T: type) Wrapper {
636636
637637test "function which returns struct with type field causes implicit comptime" {
638638 const ty = wrap(i32).T;
639 expect(ty == i32);
639 try expect(ty == i32);
640640}
641641
642642test "call method with comptime pass-by-non-copying-value self parameter" {
......@@ -650,12 +650,12 @@ test "call method with comptime pass-by-non-copying-value self parameter" {
650650
651651 const s = S{ .a = 2 };
652652 var b = s.b();
653 expect(b == 2);
653 try expect(b == 2);
654654}
655655
656656test "@tagName of @typeInfo" {
657657 const str = @tagName(@typeInfo(u8));
658 expect(std.mem.eql(u8, str, "Int"));
658 try expect(std.mem.eql(u8, str, "Int"));
659659}
660660
661661test "setting backward branch quota just before a generic fn call" {
......@@ -669,15 +669,15 @@ fn loopNTimes(comptime n: usize) void {
669669}
670670
671671test "variable inside inline loop that has different types on different iterations" {
672 testVarInsideInlineLoop(.{ true, @as(u32, 42) });
672 try testVarInsideInlineLoop(.{ true, @as(u32, 42) });
673673}
674674
675fn testVarInsideInlineLoop(args: anytype) void {
675fn testVarInsideInlineLoop(args: anytype) !void {
676676 comptime var i = 0;
677677 inline while (i < args.len) : (i += 1) {
678678 const x = args[i];
679 if (i == 0) expect(x);
680 if (i == 1) expect(x == 42);
679 if (i == 0) try expect(x);
680 if (i == 1) try expect(x == 42);
681681 }
682682}
683683
......@@ -687,7 +687,7 @@ test "inline for with same type but different values" {
687687 var a: T = undefined;
688688 res += a.len;
689689 }
690 expect(res == 5);
690 try expect(res == 5);
691691}
692692
693693test "refer to the type of a generic function" {
......@@ -701,13 +701,13 @@ fn doNothingWithType(comptime T: type) void {}
701701test "zero extend from u0 to u1" {
702702 var zero_u0: u0 = 0;
703703 var zero_u1: u1 = zero_u0;
704 expect(zero_u1 == 0);
704 try expect(zero_u1 == 0);
705705}
706706
707707test "bit shift a u1" {
708708 var x: u1 = 1;
709709 var y = x << 0;
710 expect(y == 1);
710 try expect(y == 1);
711711}
712712
713713test "comptime pointer cast array and then slice" {
......@@ -719,8 +719,8 @@ test "comptime pointer cast array and then slice" {
719719 const ptrB: [*]const u8 = &array;
720720 const sliceB: []const u8 = ptrB[0..2];
721721
722 expect(sliceA[1] == 2);
723 expect(sliceB[1] == 2);
722 try expect(sliceA[1] == 2);
723 try expect(sliceB[1] == 2);
724724}
725725
726726test "slice bounds in comptime concatenation" {
......@@ -729,46 +729,46 @@ test "slice bounds in comptime concatenation" {
729729 break :blk b[8..9];
730730 };
731731 const str = "" ++ bs;
732 expect(str.len == 1);
733 expect(std.mem.eql(u8, str, "1"));
732 try expect(str.len == 1);
733 try expect(std.mem.eql(u8, str, "1"));
734734
735735 const str2 = bs ++ "";
736 expect(str2.len == 1);
737 expect(std.mem.eql(u8, str2, "1"));
736 try expect(str2.len == 1);
737 try expect(std.mem.eql(u8, str2, "1"));
738738}
739739
740740test "comptime bitwise operators" {
741741 comptime {
742 expect(3 & 1 == 1);
743 expect(3 & -1 == 3);
744 expect(-3 & -1 == -3);
745 expect(3 | -1 == -1);
746 expect(-3 | -1 == -1);
747 expect(3 ^ -1 == -4);
748 expect(-3 ^ -1 == 2);
749 expect(~@as(i8, -1) == 0);
750 expect(~@as(i128, -1) == 0);
751 expect(18446744073709551615 & 18446744073709551611 == 18446744073709551611);
752 expect(-18446744073709551615 & -18446744073709551611 == -18446744073709551615);
753 expect(~@as(u128, 0) == 0xffffffffffffffffffffffffffffffff);
742 try expect(3 & 1 == 1);
743 try expect(3 & -1 == 3);
744 try expect(-3 & -1 == -3);
745 try expect(3 | -1 == -1);
746 try expect(-3 | -1 == -1);
747 try expect(3 ^ -1 == -4);
748 try expect(-3 ^ -1 == 2);
749 try expect(~@as(i8, -1) == 0);
750 try expect(~@as(i128, -1) == 0);
751 try expect(18446744073709551615 & 18446744073709551611 == 18446744073709551611);
752 try expect(-18446744073709551615 & -18446744073709551611 == -18446744073709551615);
753 try expect(~@as(u128, 0) == 0xffffffffffffffffffffffffffffffff);
754754 }
755755}
756756
757757test "*align(1) u16 is the same as *align(1:0:2) u16" {
758758 comptime {
759 expect(*align(1:0:2) u16 == *align(1) u16);
760 expect(*align(2:0:2) u16 == *u16);
759 try expect(*align(1:0:2) u16 == *align(1) u16);
760 try expect(*align(2:0:2) u16 == *u16);
761761 }
762762}
763763
764764test "array concatenation forces comptime" {
765765 var a = oneItem(3) ++ oneItem(4);
766 expect(std.mem.eql(i32, &a, &[_]i32{ 3, 4 }));
766 try expect(std.mem.eql(i32, &a, &[_]i32{ 3, 4 }));
767767}
768768
769769test "array multiplication forces comptime" {
770770 var a = oneItem(3) ** scalar(2);
771 expect(std.mem.eql(i32, &a, &[_]i32{ 3, 3 }));
771 try expect(std.mem.eql(i32, &a, &[_]i32{ 3, 3 }));
772772}
773773
774774fn oneItem(x: i32) [1]i32 {
......@@ -790,7 +790,7 @@ test "comptime assign int to optional int" {
790790 var x: ?i32 = null;
791791 x = 2;
792792 x.? *= 10;
793 expectEqual(20, x.?);
793 try expectEqual(20, x.?);
794794 }
795795}
796796
test/behavior/field_parent_ptr.zig+12-12
......@@ -1,13 +1,13 @@
11const expect = @import("std").testing.expect;
22
33test "@fieldParentPtr non-first field" {
4 testParentFieldPtr(&foo.c);
5 comptime testParentFieldPtr(&foo.c);
4 try testParentFieldPtr(&foo.c);
5 comptime try testParentFieldPtr(&foo.c);
66}
77
88test "@fieldParentPtr first field" {
9 testParentFieldPtrFirst(&foo.a);
10 comptime testParentFieldPtrFirst(&foo.a);
9 try testParentFieldPtrFirst(&foo.a);
10 comptime try testParentFieldPtrFirst(&foo.a);
1111}
1212
1313const Foo = struct {
......@@ -24,18 +24,18 @@ const foo = Foo{
2424 .d = -10,
2525};
2626
27fn testParentFieldPtr(c: *const i32) void {
28 expect(c == &foo.c);
27fn testParentFieldPtr(c: *const i32) !void {
28 try expect(c == &foo.c);
2929
3030 const base = @fieldParentPtr(Foo, "c", c);
31 expect(base == &foo);
32 expect(&base.c == c);
31 try expect(base == &foo);
32 try expect(&base.c == c);
3333}
3434
35fn testParentFieldPtrFirst(a: *const bool) void {
36 expect(a == &foo.a);
35fn testParentFieldPtrFirst(a: *const bool) !void {
36 try expect(a == &foo.a);
3737
3838 const base = @fieldParentPtr(Foo, "a", a);
39 expect(base == &foo);
40 expect(&base.a == a);
39 try expect(base == &foo);
40 try expect(&base.a == a);
4141}
test/behavior/floatop.zig+161-161
......@@ -8,441 +8,441 @@ const Vector = std.meta.Vector;
88const epsilon = 0.000001;
99
1010test "@sqrt" {
11 comptime testSqrt();
12 testSqrt();
11 comptime try testSqrt();
12 try testSqrt();
1313}
1414
15fn testSqrt() void {
15fn testSqrt() !void {
1616 {
1717 var a: f16 = 4;
18 expect(@sqrt(a) == 2);
18 try expect(@sqrt(a) == 2);
1919 }
2020 {
2121 var a: f32 = 9;
22 expect(@sqrt(a) == 3);
22 try expect(@sqrt(a) == 3);
2323 var b: f32 = 1.1;
24 expect(math.approxEqAbs(f32, @sqrt(b), 1.0488088481701516, epsilon));
24 try expect(math.approxEqAbs(f32, @sqrt(b), 1.0488088481701516, epsilon));
2525 }
2626 {
2727 var a: f64 = 25;
28 expect(@sqrt(a) == 5);
28 try expect(@sqrt(a) == 5);
2929 }
3030 {
3131 const a: comptime_float = 25.0;
32 expect(@sqrt(a) == 5.0);
32 try expect(@sqrt(a) == 5.0);
3333 }
3434 // TODO https://github.com/ziglang/zig/issues/4026
3535 //{
3636 // var a: f128 = 49;
37 // expect(@sqrt(a) == 7);
37 //try expect(@sqrt(a) == 7);
3838 //}
3939 {
4040 var v: Vector(4, f32) = [_]f32{ 1.1, 2.2, 3.3, 4.4 };
4141 var result = @sqrt(v);
42 expect(math.approxEqAbs(f32, @sqrt(@as(f32, 1.1)), result[0], epsilon));
43 expect(math.approxEqAbs(f32, @sqrt(@as(f32, 2.2)), result[1], epsilon));
44 expect(math.approxEqAbs(f32, @sqrt(@as(f32, 3.3)), result[2], epsilon));
45 expect(math.approxEqAbs(f32, @sqrt(@as(f32, 4.4)), result[3], epsilon));
42 try expect(math.approxEqAbs(f32, @sqrt(@as(f32, 1.1)), result[0], epsilon));
43 try expect(math.approxEqAbs(f32, @sqrt(@as(f32, 2.2)), result[1], epsilon));
44 try expect(math.approxEqAbs(f32, @sqrt(@as(f32, 3.3)), result[2], epsilon));
45 try expect(math.approxEqAbs(f32, @sqrt(@as(f32, 4.4)), result[3], epsilon));
4646 }
4747}
4848
4949test "more @sqrt f16 tests" {
5050 // TODO these are not all passing at comptime
51 expect(@sqrt(@as(f16, 0.0)) == 0.0);
52 expect(math.approxEqAbs(f16, @sqrt(@as(f16, 2.0)), 1.414214, epsilon));
53 expect(math.approxEqAbs(f16, @sqrt(@as(f16, 3.6)), 1.897367, epsilon));
54 expect(@sqrt(@as(f16, 4.0)) == 2.0);
55 expect(math.approxEqAbs(f16, @sqrt(@as(f16, 7.539840)), 2.745877, epsilon));
56 expect(math.approxEqAbs(f16, @sqrt(@as(f16, 19.230934)), 4.385309, epsilon));
57 expect(@sqrt(@as(f16, 64.0)) == 8.0);
58 expect(math.approxEqAbs(f16, @sqrt(@as(f16, 64.1)), 8.006248, epsilon));
59 expect(math.approxEqAbs(f16, @sqrt(@as(f16, 8942.230469)), 94.563370, epsilon));
51 try expect(@sqrt(@as(f16, 0.0)) == 0.0);
52 try expect(math.approxEqAbs(f16, @sqrt(@as(f16, 2.0)), 1.414214, epsilon));
53 try expect(math.approxEqAbs(f16, @sqrt(@as(f16, 3.6)), 1.897367, epsilon));
54 try expect(@sqrt(@as(f16, 4.0)) == 2.0);
55 try expect(math.approxEqAbs(f16, @sqrt(@as(f16, 7.539840)), 2.745877, epsilon));
56 try expect(math.approxEqAbs(f16, @sqrt(@as(f16, 19.230934)), 4.385309, epsilon));
57 try expect(@sqrt(@as(f16, 64.0)) == 8.0);
58 try expect(math.approxEqAbs(f16, @sqrt(@as(f16, 64.1)), 8.006248, epsilon));
59 try expect(math.approxEqAbs(f16, @sqrt(@as(f16, 8942.230469)), 94.563370, epsilon));
6060
6161 // special cases
62 expect(math.isPositiveInf(@sqrt(@as(f16, math.inf(f16)))));
63 expect(@sqrt(@as(f16, 0.0)) == 0.0);
64 expect(@sqrt(@as(f16, -0.0)) == -0.0);
65 expect(math.isNan(@sqrt(@as(f16, -1.0))));
66 expect(math.isNan(@sqrt(@as(f16, math.nan(f16)))));
62 try expect(math.isPositiveInf(@sqrt(@as(f16, math.inf(f16)))));
63 try expect(@sqrt(@as(f16, 0.0)) == 0.0);
64 try expect(@sqrt(@as(f16, -0.0)) == -0.0);
65 try expect(math.isNan(@sqrt(@as(f16, -1.0))));
66 try expect(math.isNan(@sqrt(@as(f16, math.nan(f16)))));
6767}
6868
6969test "@sin" {
70 comptime testSin();
71 testSin();
70 comptime try testSin();
71 try testSin();
7272}
7373
74fn testSin() void {
74fn testSin() !void {
7575 // TODO test f128, and c_longdouble
7676 // https://github.com/ziglang/zig/issues/4026
7777 {
7878 var a: f16 = 0;
79 expect(@sin(a) == 0);
79 try expect(@sin(a) == 0);
8080 }
8181 {
8282 var a: f32 = 0;
83 expect(@sin(a) == 0);
83 try expect(@sin(a) == 0);
8484 }
8585 {
8686 var a: f64 = 0;
87 expect(@sin(a) == 0);
87 try expect(@sin(a) == 0);
8888 }
8989 {
9090 var v: Vector(4, f32) = [_]f32{ 1.1, 2.2, 3.3, 4.4 };
9191 var result = @sin(v);
92 expect(math.approxEqAbs(f32, @sin(@as(f32, 1.1)), result[0], epsilon));
93 expect(math.approxEqAbs(f32, @sin(@as(f32, 2.2)), result[1], epsilon));
94 expect(math.approxEqAbs(f32, @sin(@as(f32, 3.3)), result[2], epsilon));
95 expect(math.approxEqAbs(f32, @sin(@as(f32, 4.4)), result[3], epsilon));
92 try expect(math.approxEqAbs(f32, @sin(@as(f32, 1.1)), result[0], epsilon));
93 try expect(math.approxEqAbs(f32, @sin(@as(f32, 2.2)), result[1], epsilon));
94 try expect(math.approxEqAbs(f32, @sin(@as(f32, 3.3)), result[2], epsilon));
95 try expect(math.approxEqAbs(f32, @sin(@as(f32, 4.4)), result[3], epsilon));
9696 }
9797}
9898
9999test "@cos" {
100 comptime testCos();
101 testCos();
100 comptime try testCos();
101 try testCos();
102102}
103103
104fn testCos() void {
104fn testCos() !void {
105105 // TODO test f128, and c_longdouble
106106 // https://github.com/ziglang/zig/issues/4026
107107 {
108108 var a: f16 = 0;
109 expect(@cos(a) == 1);
109 try expect(@cos(a) == 1);
110110 }
111111 {
112112 var a: f32 = 0;
113 expect(@cos(a) == 1);
113 try expect(@cos(a) == 1);
114114 }
115115 {
116116 var a: f64 = 0;
117 expect(@cos(a) == 1);
117 try expect(@cos(a) == 1);
118118 }
119119 {
120120 var v: Vector(4, f32) = [_]f32{ 1.1, 2.2, 3.3, 4.4 };
121121 var result = @cos(v);
122 expect(math.approxEqAbs(f32, @cos(@as(f32, 1.1)), result[0], epsilon));
123 expect(math.approxEqAbs(f32, @cos(@as(f32, 2.2)), result[1], epsilon));
124 expect(math.approxEqAbs(f32, @cos(@as(f32, 3.3)), result[2], epsilon));
125 expect(math.approxEqAbs(f32, @cos(@as(f32, 4.4)), result[3], epsilon));
122 try expect(math.approxEqAbs(f32, @cos(@as(f32, 1.1)), result[0], epsilon));
123 try expect(math.approxEqAbs(f32, @cos(@as(f32, 2.2)), result[1], epsilon));
124 try expect(math.approxEqAbs(f32, @cos(@as(f32, 3.3)), result[2], epsilon));
125 try expect(math.approxEqAbs(f32, @cos(@as(f32, 4.4)), result[3], epsilon));
126126 }
127127}
128128
129129test "@exp" {
130 comptime testExp();
131 testExp();
130 comptime try testExp();
131 try testExp();
132132}
133133
134fn testExp() void {
134fn testExp() !void {
135135 // TODO test f128, and c_longdouble
136136 // https://github.com/ziglang/zig/issues/4026
137137 {
138138 var a: f16 = 0;
139 expect(@exp(a) == 1);
139 try expect(@exp(a) == 1);
140140 }
141141 {
142142 var a: f32 = 0;
143 expect(@exp(a) == 1);
143 try expect(@exp(a) == 1);
144144 }
145145 {
146146 var a: f64 = 0;
147 expect(@exp(a) == 1);
147 try expect(@exp(a) == 1);
148148 }
149149 {
150150 var v: Vector(4, f32) = [_]f32{ 1.1, 2.2, 0.3, 0.4 };
151151 var result = @exp(v);
152 expect(math.approxEqAbs(f32, @exp(@as(f32, 1.1)), result[0], epsilon));
153 expect(math.approxEqAbs(f32, @exp(@as(f32, 2.2)), result[1], epsilon));
154 expect(math.approxEqAbs(f32, @exp(@as(f32, 0.3)), result[2], epsilon));
155 expect(math.approxEqAbs(f32, @exp(@as(f32, 0.4)), result[3], epsilon));
152 try expect(math.approxEqAbs(f32, @exp(@as(f32, 1.1)), result[0], epsilon));
153 try expect(math.approxEqAbs(f32, @exp(@as(f32, 2.2)), result[1], epsilon));
154 try expect(math.approxEqAbs(f32, @exp(@as(f32, 0.3)), result[2], epsilon));
155 try expect(math.approxEqAbs(f32, @exp(@as(f32, 0.4)), result[3], epsilon));
156156 }
157157}
158158
159159test "@exp2" {
160 comptime testExp2();
161 testExp2();
160 comptime try testExp2();
161 try testExp2();
162162}
163163
164fn testExp2() void {
164fn testExp2() !void {
165165 // TODO test f128, and c_longdouble
166166 // https://github.com/ziglang/zig/issues/4026
167167 {
168168 var a: f16 = 2;
169 expect(@exp2(a) == 4);
169 try expect(@exp2(a) == 4);
170170 }
171171 {
172172 var a: f32 = 2;
173 expect(@exp2(a) == 4);
173 try expect(@exp2(a) == 4);
174174 }
175175 {
176176 var a: f64 = 2;
177 expect(@exp2(a) == 4);
177 try expect(@exp2(a) == 4);
178178 }
179179 {
180180 var v: Vector(4, f32) = [_]f32{ 1.1, 2.2, 0.3, 0.4 };
181181 var result = @exp2(v);
182 expect(math.approxEqAbs(f32, @exp2(@as(f32, 1.1)), result[0], epsilon));
183 expect(math.approxEqAbs(f32, @exp2(@as(f32, 2.2)), result[1], epsilon));
184 expect(math.approxEqAbs(f32, @exp2(@as(f32, 0.3)), result[2], epsilon));
185 expect(math.approxEqAbs(f32, @exp2(@as(f32, 0.4)), result[3], epsilon));
182 try expect(math.approxEqAbs(f32, @exp2(@as(f32, 1.1)), result[0], epsilon));
183 try expect(math.approxEqAbs(f32, @exp2(@as(f32, 2.2)), result[1], epsilon));
184 try expect(math.approxEqAbs(f32, @exp2(@as(f32, 0.3)), result[2], epsilon));
185 try expect(math.approxEqAbs(f32, @exp2(@as(f32, 0.4)), result[3], epsilon));
186186 }
187187}
188188
189189test "@log" {
190190 // Old musl (and glibc?), and our current math.ln implementation do not return 1
191191 // so also accept those values.
192 comptime testLog();
193 testLog();
192 comptime try testLog();
193 try testLog();
194194}
195195
196fn testLog() void {
196fn testLog() !void {
197197 // TODO test f128, and c_longdouble
198198 // https://github.com/ziglang/zig/issues/4026
199199 {
200200 var a: f16 = e;
201 expect(math.approxEqAbs(f16, @log(a), 1, epsilon));
201 try expect(math.approxEqAbs(f16, @log(a), 1, epsilon));
202202 }
203203 {
204204 var a: f32 = e;
205 expect(@log(a) == 1 or @log(a) == @bitCast(f32, @as(u32, 0x3f7fffff)));
205 try expect(@log(a) == 1 or @log(a) == @bitCast(f32, @as(u32, 0x3f7fffff)));
206206 }
207207 {
208208 var a: f64 = e;
209 expect(@log(a) == 1 or @log(a) == @bitCast(f64, @as(u64, 0x3ff0000000000000)));
209 try expect(@log(a) == 1 or @log(a) == @bitCast(f64, @as(u64, 0x3ff0000000000000)));
210210 }
211211 {
212212 var v: Vector(4, f32) = [_]f32{ 1.1, 2.2, 0.3, 0.4 };
213213 var result = @log(v);
214 expect(math.approxEqAbs(f32, @log(@as(f32, 1.1)), result[0], epsilon));
215 expect(math.approxEqAbs(f32, @log(@as(f32, 2.2)), result[1], epsilon));
216 expect(math.approxEqAbs(f32, @log(@as(f32, 0.3)), result[2], epsilon));
217 expect(math.approxEqAbs(f32, @log(@as(f32, 0.4)), result[3], epsilon));
214 try expect(math.approxEqAbs(f32, @log(@as(f32, 1.1)), result[0], epsilon));
215 try expect(math.approxEqAbs(f32, @log(@as(f32, 2.2)), result[1], epsilon));
216 try expect(math.approxEqAbs(f32, @log(@as(f32, 0.3)), result[2], epsilon));
217 try expect(math.approxEqAbs(f32, @log(@as(f32, 0.4)), result[3], epsilon));
218218 }
219219}
220220
221221test "@log2" {
222 comptime testLog2();
223 testLog2();
222 comptime try testLog2();
223 try testLog2();
224224}
225225
226fn testLog2() void {
226fn testLog2() !void {
227227 // TODO test f128, and c_longdouble
228228 // https://github.com/ziglang/zig/issues/4026
229229 {
230230 var a: f16 = 4;
231 expect(@log2(a) == 2);
231 try expect(@log2(a) == 2);
232232 }
233233 {
234234 var a: f32 = 4;
235 expect(@log2(a) == 2);
235 try expect(@log2(a) == 2);
236236 }
237237 {
238238 var a: f64 = 4;
239 expect(@log2(a) == 2);
239 try expect(@log2(a) == 2);
240240 }
241241 {
242242 var v: Vector(4, f32) = [_]f32{ 1.1, 2.2, 0.3, 0.4 };
243243 var result = @log2(v);
244 expect(math.approxEqAbs(f32, @log2(@as(f32, 1.1)), result[0], epsilon));
245 expect(math.approxEqAbs(f32, @log2(@as(f32, 2.2)), result[1], epsilon));
246 expect(math.approxEqAbs(f32, @log2(@as(f32, 0.3)), result[2], epsilon));
247 expect(math.approxEqAbs(f32, @log2(@as(f32, 0.4)), result[3], epsilon));
244 try expect(math.approxEqAbs(f32, @log2(@as(f32, 1.1)), result[0], epsilon));
245 try expect(math.approxEqAbs(f32, @log2(@as(f32, 2.2)), result[1], epsilon));
246 try expect(math.approxEqAbs(f32, @log2(@as(f32, 0.3)), result[2], epsilon));
247 try expect(math.approxEqAbs(f32, @log2(@as(f32, 0.4)), result[3], epsilon));
248248 }
249249}
250250
251251test "@log10" {
252 comptime testLog10();
253 testLog10();
252 comptime try testLog10();
253 try testLog10();
254254}
255255
256fn testLog10() void {
256fn testLog10() !void {
257257 // TODO test f128, and c_longdouble
258258 // https://github.com/ziglang/zig/issues/4026
259259 {
260260 var a: f16 = 100;
261 expect(@log10(a) == 2);
261 try expect(@log10(a) == 2);
262262 }
263263 {
264264 var a: f32 = 100;
265 expect(@log10(a) == 2);
265 try expect(@log10(a) == 2);
266266 }
267267 {
268268 var a: f64 = 1000;
269 expect(@log10(a) == 3);
269 try expect(@log10(a) == 3);
270270 }
271271 {
272272 var v: Vector(4, f32) = [_]f32{ 1.1, 2.2, 0.3, 0.4 };
273273 var result = @log10(v);
274 expect(math.approxEqAbs(f32, @log10(@as(f32, 1.1)), result[0], epsilon));
275 expect(math.approxEqAbs(f32, @log10(@as(f32, 2.2)), result[1], epsilon));
276 expect(math.approxEqAbs(f32, @log10(@as(f32, 0.3)), result[2], epsilon));
277 expect(math.approxEqAbs(f32, @log10(@as(f32, 0.4)), result[3], epsilon));
274 try expect(math.approxEqAbs(f32, @log10(@as(f32, 1.1)), result[0], epsilon));
275 try expect(math.approxEqAbs(f32, @log10(@as(f32, 2.2)), result[1], epsilon));
276 try expect(math.approxEqAbs(f32, @log10(@as(f32, 0.3)), result[2], epsilon));
277 try expect(math.approxEqAbs(f32, @log10(@as(f32, 0.4)), result[3], epsilon));
278278 }
279279}
280280
281281test "@fabs" {
282 comptime testFabs();
283 testFabs();
282 comptime try testFabs();
283 try testFabs();
284284}
285285
286fn testFabs() void {
286fn testFabs() !void {
287287 // TODO test f128, and c_longdouble
288288 // https://github.com/ziglang/zig/issues/4026
289289 {
290290 var a: f16 = -2.5;
291291 var b: f16 = 2.5;
292 expect(@fabs(a) == 2.5);
293 expect(@fabs(b) == 2.5);
292 try expect(@fabs(a) == 2.5);
293 try expect(@fabs(b) == 2.5);
294294 }
295295 {
296296 var a: f32 = -2.5;
297297 var b: f32 = 2.5;
298 expect(@fabs(a) == 2.5);
299 expect(@fabs(b) == 2.5);
298 try expect(@fabs(a) == 2.5);
299 try expect(@fabs(b) == 2.5);
300300 }
301301 {
302302 var a: f64 = -2.5;
303303 var b: f64 = 2.5;
304 expect(@fabs(a) == 2.5);
305 expect(@fabs(b) == 2.5);
304 try expect(@fabs(a) == 2.5);
305 try expect(@fabs(b) == 2.5);
306306 }
307307 {
308308 var v: Vector(4, f32) = [_]f32{ 1.1, -2.2, 0.3, -0.4 };
309309 var result = @fabs(v);
310 expect(math.approxEqAbs(f32, @fabs(@as(f32, 1.1)), result[0], epsilon));
311 expect(math.approxEqAbs(f32, @fabs(@as(f32, -2.2)), result[1], epsilon));
312 expect(math.approxEqAbs(f32, @fabs(@as(f32, 0.3)), result[2], epsilon));
313 expect(math.approxEqAbs(f32, @fabs(@as(f32, -0.4)), result[3], epsilon));
310 try expect(math.approxEqAbs(f32, @fabs(@as(f32, 1.1)), result[0], epsilon));
311 try expect(math.approxEqAbs(f32, @fabs(@as(f32, -2.2)), result[1], epsilon));
312 try expect(math.approxEqAbs(f32, @fabs(@as(f32, 0.3)), result[2], epsilon));
313 try expect(math.approxEqAbs(f32, @fabs(@as(f32, -0.4)), result[3], epsilon));
314314 }
315315}
316316
317317test "@floor" {
318 comptime testFloor();
319 testFloor();
318 comptime try testFloor();
319 try testFloor();
320320}
321321
322fn testFloor() void {
322fn testFloor() !void {
323323 // TODO test f128, and c_longdouble
324324 // https://github.com/ziglang/zig/issues/4026
325325 {
326326 var a: f16 = 2.1;
327 expect(@floor(a) == 2);
327 try expect(@floor(a) == 2);
328328 }
329329 {
330330 var a: f32 = 2.1;
331 expect(@floor(a) == 2);
331 try expect(@floor(a) == 2);
332332 }
333333 {
334334 var a: f64 = 3.5;
335 expect(@floor(a) == 3);
335 try expect(@floor(a) == 3);
336336 }
337337 {
338338 var v: Vector(4, f32) = [_]f32{ 1.1, -2.2, 0.3, -0.4 };
339339 var result = @floor(v);
340 expect(math.approxEqAbs(f32, @floor(@as(f32, 1.1)), result[0], epsilon));
341 expect(math.approxEqAbs(f32, @floor(@as(f32, -2.2)), result[1], epsilon));
342 expect(math.approxEqAbs(f32, @floor(@as(f32, 0.3)), result[2], epsilon));
343 expect(math.approxEqAbs(f32, @floor(@as(f32, -0.4)), result[3], epsilon));
340 try expect(math.approxEqAbs(f32, @floor(@as(f32, 1.1)), result[0], epsilon));
341 try expect(math.approxEqAbs(f32, @floor(@as(f32, -2.2)), result[1], epsilon));
342 try expect(math.approxEqAbs(f32, @floor(@as(f32, 0.3)), result[2], epsilon));
343 try expect(math.approxEqAbs(f32, @floor(@as(f32, -0.4)), result[3], epsilon));
344344 }
345345}
346346
347347test "@ceil" {
348 comptime testCeil();
349 testCeil();
348 comptime try testCeil();
349 try testCeil();
350350}
351351
352fn testCeil() void {
352fn testCeil() !void {
353353 // TODO test f128, and c_longdouble
354354 // https://github.com/ziglang/zig/issues/4026
355355 {
356356 var a: f16 = 2.1;
357 expect(@ceil(a) == 3);
357 try expect(@ceil(a) == 3);
358358 }
359359 {
360360 var a: f32 = 2.1;
361 expect(@ceil(a) == 3);
361 try expect(@ceil(a) == 3);
362362 }
363363 {
364364 var a: f64 = 3.5;
365 expect(@ceil(a) == 4);
365 try expect(@ceil(a) == 4);
366366 }
367367 {
368368 var v: Vector(4, f32) = [_]f32{ 1.1, -2.2, 0.3, -0.4 };
369369 var result = @ceil(v);
370 expect(math.approxEqAbs(f32, @ceil(@as(f32, 1.1)), result[0], epsilon));
371 expect(math.approxEqAbs(f32, @ceil(@as(f32, -2.2)), result[1], epsilon));
372 expect(math.approxEqAbs(f32, @ceil(@as(f32, 0.3)), result[2], epsilon));
373 expect(math.approxEqAbs(f32, @ceil(@as(f32, -0.4)), result[3], epsilon));
370 try expect(math.approxEqAbs(f32, @ceil(@as(f32, 1.1)), result[0], epsilon));
371 try expect(math.approxEqAbs(f32, @ceil(@as(f32, -2.2)), result[1], epsilon));
372 try expect(math.approxEqAbs(f32, @ceil(@as(f32, 0.3)), result[2], epsilon));
373 try expect(math.approxEqAbs(f32, @ceil(@as(f32, -0.4)), result[3], epsilon));
374374 }
375375}
376376
377377test "@trunc" {
378 comptime testTrunc();
379 testTrunc();
378 comptime try testTrunc();
379 try testTrunc();
380380}
381381
382fn testTrunc() void {
382fn testTrunc() !void {
383383 // TODO test f128, and c_longdouble
384384 // https://github.com/ziglang/zig/issues/4026
385385 {
386386 var a: f16 = 2.1;
387 expect(@trunc(a) == 2);
387 try expect(@trunc(a) == 2);
388388 }
389389 {
390390 var a: f32 = 2.1;
391 expect(@trunc(a) == 2);
391 try expect(@trunc(a) == 2);
392392 }
393393 {
394394 var a: f64 = -3.5;
395 expect(@trunc(a) == -3);
395 try expect(@trunc(a) == -3);
396396 }
397397 {
398398 var v: Vector(4, f32) = [_]f32{ 1.1, -2.2, 0.3, -0.4 };
399399 var result = @trunc(v);
400 expect(math.approxEqAbs(f32, @trunc(@as(f32, 1.1)), result[0], epsilon));
401 expect(math.approxEqAbs(f32, @trunc(@as(f32, -2.2)), result[1], epsilon));
402 expect(math.approxEqAbs(f32, @trunc(@as(f32, 0.3)), result[2], epsilon));
403 expect(math.approxEqAbs(f32, @trunc(@as(f32, -0.4)), result[3], epsilon));
400 try expect(math.approxEqAbs(f32, @trunc(@as(f32, 1.1)), result[0], epsilon));
401 try expect(math.approxEqAbs(f32, @trunc(@as(f32, -2.2)), result[1], epsilon));
402 try expect(math.approxEqAbs(f32, @trunc(@as(f32, 0.3)), result[2], epsilon));
403 try expect(math.approxEqAbs(f32, @trunc(@as(f32, -0.4)), result[3], epsilon));
404404 }
405405}
406406
407407test "floating point comparisons" {
408 testFloatComparisons();
409 comptime testFloatComparisons();
408 try testFloatComparisons();
409 comptime try testFloatComparisons();
410410}
411411
412fn testFloatComparisons() void {
412fn testFloatComparisons() !void {
413413 inline for ([_]type{ f16, f32, f64, f128 }) |ty| {
414414 // No decimal part
415415 {
416416 const x: ty = 1.0;
417 expect(x == 1);
418 expect(x != 0);
419 expect(x > 0);
420 expect(x < 2);
421 expect(x >= 1);
422 expect(x <= 1);
417 try expect(x == 1);
418 try expect(x != 0);
419 try expect(x > 0);
420 try expect(x < 2);
421 try expect(x >= 1);
422 try expect(x <= 1);
423423 }
424424 // Non-zero decimal part
425425 {
426426 const x: ty = 1.5;
427 expect(x != 1);
428 expect(x != 2);
429 expect(x > 1);
430 expect(x < 2);
431 expect(x >= 1);
432 expect(x <= 2);
427 try expect(x != 1);
428 try expect(x != 2);
429 try expect(x > 1);
430 try expect(x < 2);
431 try expect(x >= 1);
432 try expect(x <= 2);
433433 }
434434 }
435435}
436436
437437test "different sized float comparisons" {
438 testDifferentSizedFloatComparisons();
439 comptime testDifferentSizedFloatComparisons();
438 try testDifferentSizedFloatComparisons();
439 comptime try testDifferentSizedFloatComparisons();
440440}
441441
442fn testDifferentSizedFloatComparisons() void {
442fn testDifferentSizedFloatComparisons() !void {
443443 var a: f16 = 1;
444444 var b: f64 = 2;
445 expect(a < b);
445 try expect(a < b);
446446}
447447
448448// TODO This is waiting on library support for the Windows build (not sure why the other's don't need it)
......@@ -456,10 +456,10 @@ fn testDifferentSizedFloatComparisons() void {
456456// // https://github.com/ziglang/zig/issues/4026
457457// {
458458// var a: f32 = 2.1;
459// expect(@nearbyint(a) == 2);
459// try expect(@nearbyint(a) == 2);
460460// }
461461// {
462462// var a: f64 = -3.75;
463// expect(@nearbyint(a) == -4);
463// try expect(@nearbyint(a) == -4);
464464// }
465465//}
test/behavior/fn.zig+41-41
......@@ -5,7 +5,7 @@ const expect = testing.expect;
55const expectEqual = testing.expectEqual;
66
77test "params" {
8 expect(testParamsAdd(22, 11) == 33);
8 try expect(testParamsAdd(22, 11) == 33);
99}
1010fn testParamsAdd(a: i32, b: i32) i32 {
1111 return a + b;
......@@ -20,37 +20,37 @@ fn testLocVars(b: i32) void {
2020}
2121
2222test "void parameters" {
23 voidFun(1, void{}, 2, {});
23 try voidFun(1, void{}, 2, {});
2424}
25fn voidFun(a: i32, b: void, c: i32, d: void) void {
25fn voidFun(a: i32, b: void, c: i32, d: void) !void {
2626 const v = b;
2727 const vv: void = if (a == 1) v else {};
28 expect(a + c == 3);
28 try expect(a + c == 3);
2929 return vv;
3030}
3131
3232test "mutable local variables" {
3333 var zero: i32 = 0;
34 expect(zero == 0);
34 try expect(zero == 0);
3535
3636 var i = @as(i32, 0);
3737 while (i != 3) {
3838 i += 1;
3939 }
40 expect(i == 3);
40 try expect(i == 3);
4141}
4242
4343test "separate block scopes" {
4444 {
4545 const no_conflict: i32 = 5;
46 expect(no_conflict == 5);
46 try expect(no_conflict == 5);
4747 }
4848
4949 const c = x: {
5050 const no_conflict = @as(i32, 10);
5151 break :x no_conflict;
5252 };
53 expect(c == 10);
53 try expect(c == 10);
5454}
5555
5656test "call function with empty string" {
......@@ -63,7 +63,7 @@ fn @"weird function name"() i32 {
6363 return 1234;
6464}
6565test "weird function name" {
66 expect(@"weird function name"() == 1234);
66 try expect(@"weird function name"() == 1234);
6767}
6868
6969test "implicit cast function unreachable return" {
......@@ -84,7 +84,7 @@ test "function pointers" {
8484 fn4,
8585 };
8686 for (fns) |f, i| {
87 expect(f() == @intCast(u32, i) + 5);
87 try expect(f() == @intCast(u32, i) + 5);
8888 }
8989}
9090fn fn1() u32 {
......@@ -101,12 +101,12 @@ fn fn4() u32 {
101101}
102102
103103test "number literal as an argument" {
104 numberLiteralArg(3);
105 comptime numberLiteralArg(3);
104 try numberLiteralArg(3);
105 comptime try numberLiteralArg(3);
106106}
107107
108fn numberLiteralArg(a: anytype) void {
109 expect(a == 3);
108fn numberLiteralArg(a: anytype) !void {
109 try expect(a == 3);
110110}
111111
112112test "assign inline fn to const variable" {
......@@ -117,7 +117,7 @@ test "assign inline fn to const variable" {
117117fn inlineFn() callconv(.Inline) void {}
118118
119119test "pass by non-copying value" {
120 expect(addPointCoords(Point{ .x = 1, .y = 2 }) == 3);
120 try expect(addPointCoords(Point{ .x = 1, .y = 2 }) == 3);
121121}
122122
123123const Point = struct {
......@@ -130,17 +130,17 @@ fn addPointCoords(pt: Point) i32 {
130130}
131131
132132test "pass by non-copying value through var arg" {
133 expect(addPointCoordsVar(Point{ .x = 1, .y = 2 }) == 3);
133 try expect((try addPointCoordsVar(Point{ .x = 1, .y = 2 })) == 3);
134134}
135135
136fn addPointCoordsVar(pt: anytype) i32 {
137 comptime expect(@TypeOf(pt) == Point);
136fn addPointCoordsVar(pt: anytype) !i32 {
137 comptime try expect(@TypeOf(pt) == Point);
138138 return pt.x + pt.y;
139139}
140140
141141test "pass by non-copying value as method" {
142142 var pt = Point2{ .x = 1, .y = 2 };
143 expect(pt.addPointCoords() == 3);
143 try expect(pt.addPointCoords() == 3);
144144}
145145
146146const Point2 = struct {
......@@ -154,7 +154,7 @@ const Point2 = struct {
154154
155155test "pass by non-copying value as method, which is generic" {
156156 var pt = Point3{ .x = 1, .y = 2 };
157 expect(pt.addPointCoords(i32) == 3);
157 try expect(pt.addPointCoords(i32) == 3);
158158}
159159
160160const Point3 = struct {
......@@ -169,7 +169,7 @@ const Point3 = struct {
169169test "pass by non-copying value as method, at comptime" {
170170 comptime {
171171 var pt = Point2{ .x = 1, .y = 2 };
172 expect(pt.addPointCoords() == 3);
172 try expect(pt.addPointCoords() == 3);
173173 }
174174}
175175
......@@ -185,7 +185,7 @@ fn outer(y: u32) fn (u32) u32 {
185185
186186test "return inner function which references comptime variable of outer function" {
187187 var func = outer(10);
188 expect(func(3) == 7);
188 try expect(func(3) == 7);
189189}
190190
191191test "extern struct with stdcallcc fn pointer" {
......@@ -199,16 +199,16 @@ test "extern struct with stdcallcc fn pointer" {
199199
200200 var s: S = undefined;
201201 s.ptr = S.foo;
202 expect(s.ptr() == 1234);
202 try expect(s.ptr() == 1234);
203203}
204204
205205test "implicit cast fn call result to optional in field result" {
206206 const S = struct {
207 fn entry() void {
207 fn entry() !void {
208208 var x = Foo{
209209 .field = optionalPtr(),
210210 };
211 expect(x.field.?.* == 999);
211 try expect(x.field.?.* == 999);
212212 }
213213
214214 const glob: i32 = 999;
......@@ -221,8 +221,8 @@ test "implicit cast fn call result to optional in field result" {
221221 field: ?*const i32,
222222 };
223223 };
224 S.entry();
225 comptime S.entry();
224 try S.entry();
225 comptime try S.entry();
226226}
227227
228228test "discard the result of a function that returns a struct" {
......@@ -246,26 +246,26 @@ test "discard the result of a function that returns a struct" {
246246
247247test "function call with anon list literal" {
248248 const S = struct {
249 fn doTheTest() void {
250 consumeVec(.{ 9, 8, 7 });
249 fn doTheTest() !void {
250 try consumeVec(.{ 9, 8, 7 });
251251 }
252252
253 fn consumeVec(vec: [3]f32) void {
254 expect(vec[0] == 9);
255 expect(vec[1] == 8);
256 expect(vec[2] == 7);
253 fn consumeVec(vec: [3]f32) !void {
254 try expect(vec[0] == 9);
255 try expect(vec[1] == 8);
256 try expect(vec[2] == 7);
257257 }
258258 };
259 S.doTheTest();
260 comptime S.doTheTest();
259 try S.doTheTest();
260 comptime try S.doTheTest();
261261}
262262
263263test "ability to give comptime types and non comptime types to same parameter" {
264264 const S = struct {
265 fn doTheTest() void {
265 fn doTheTest() !void {
266266 var x: i32 = 1;
267 expect(foo(x) == 10);
268 expect(foo(i32) == 20);
267 try expect(foo(x) == 10);
268 try expect(foo(i32) == 20);
269269 }
270270
271271 fn foo(arg: anytype) i32 {
......@@ -273,8 +273,8 @@ test "ability to give comptime types and non comptime types to same parameter" {
273273 return 9 + arg;
274274 }
275275 };
276 S.doTheTest();
277 comptime S.doTheTest();
276 try S.doTheTest();
277 comptime try S.doTheTest();
278278}
279279
280280test "function with inferred error set but returning no error" {
......@@ -283,5 +283,5 @@ test "function with inferred error set but returning no error" {
283283 };
284284
285285 const return_ty = @typeInfo(@TypeOf(S.foo)).Fn.return_type.?;
286 expectEqual(0, @typeInfo(@typeInfo(return_ty).ErrorUnion.error_set).ErrorSet.?.len);
286 try expectEqual(0, @typeInfo(@typeInfo(return_ty).ErrorUnion.error_set).ErrorSet.?.len);
287287}
test/behavior/fn_delegation.zig+4-4
......@@ -32,8 +32,8 @@ fn custom(comptime T: type, comptime num: u64) fn (T) u64 {
3232
3333test "fn delegation" {
3434 const foo = Foo{};
35 expect(foo.one() == 11);
36 expect(foo.two() == 12);
37 expect(foo.three() == 13);
38 expect(foo.four() == 14);
35 try expect(foo.one() == 11);
36 try expect(foo.two() == 12);
37 try expect(foo.three() == 13);
38 try expect(foo.four() == 14);
3939}
test/behavior/fn_in_struct_in_comptime.zig+1-1
......@@ -13,5 +13,5 @@ fn get_foo() fn (*u8) usize {
1313
1414test "define a function in an anonymous struct in comptime" {
1515 const foo = get_foo();
16 expect(foo(@intToPtr(*u8, 12345)) == 12345);
16 try expect(foo(@intToPtr(*u8, 12345)) == 12345);
1717}
test/behavior/for.zig+28-28
......@@ -27,12 +27,12 @@ test "for loop with pointer elem var" {
2727 var target: [source.len]u8 = undefined;
2828 mem.copy(u8, target[0..], source);
2929 mangleString(target[0..]);
30 expect(mem.eql(u8, &target, "bcdefgh"));
30 try expect(mem.eql(u8, &target, "bcdefgh"));
3131
3232 for (source) |*c, i|
33 expect(@TypeOf(c) == *const u8);
33 try expect(@TypeOf(c) == *const u8);
3434 for (target) |*c, i|
35 expect(@TypeOf(c) == *u8);
35 try expect(@TypeOf(c) == *u8);
3636}
3737
3838fn mangleString(s: []u8) void {
......@@ -75,15 +75,15 @@ test "basic for loop" {
7575 buf_index += 1;
7676 }
7777
78 expect(mem.eql(u8, buffer[0..buf_index], &expected_result));
78 try expect(mem.eql(u8, buffer[0..buf_index], &expected_result));
7979}
8080
8181test "break from outer for loop" {
82 testBreakOuter();
83 comptime testBreakOuter();
82 try testBreakOuter();
83 comptime try testBreakOuter();
8484}
8585
86fn testBreakOuter() void {
86fn testBreakOuter() !void {
8787 var array = "aoeu";
8888 var count: usize = 0;
8989 outer: for (array) |_| {
......@@ -92,15 +92,15 @@ fn testBreakOuter() void {
9292 break :outer;
9393 }
9494 }
95 expect(count == 1);
95 try expect(count == 1);
9696}
9797
9898test "continue outer for loop" {
99 testContinueOuter();
100 comptime testContinueOuter();
99 try testContinueOuter();
100 comptime try testContinueOuter();
101101}
102102
103fn testContinueOuter() void {
103fn testContinueOuter() !void {
104104 var array = "aoeu";
105105 var counter: usize = 0;
106106 outer: for (array) |_| {
......@@ -109,28 +109,28 @@ fn testContinueOuter() void {
109109 continue :outer;
110110 }
111111 }
112 expect(counter == array.len);
112 try expect(counter == array.len);
113113}
114114
115115test "2 break statements and an else" {
116116 const S = struct {
117 fn entry(t: bool, f: bool) void {
117 fn entry(t: bool, f: bool) !void {
118118 var buf: [10]u8 = undefined;
119119 var ok = false;
120120 ok = for (buf) |item| {
121121 if (f) break false;
122122 if (t) break true;
123123 } else false;
124 expect(ok);
124 try expect(ok);
125125 }
126126 };
127 S.entry(true, false);
128 comptime S.entry(true, false);
127 try S.entry(true, false);
128 comptime try S.entry(true, false);
129129}
130130
131131test "for with null and T peer types and inferred result location type" {
132132 const S = struct {
133 fn doTheTest(slice: []const u8) void {
133 fn doTheTest(slice: []const u8) !void {
134134 if (for (slice) |item| {
135135 if (item == 10) {
136136 break item;
......@@ -140,33 +140,33 @@ test "for with null and T peer types and inferred result location type" {
140140 }
141141 }
142142 };
143 S.doTheTest(&[_]u8{ 1, 2 });
144 comptime S.doTheTest(&[_]u8{ 1, 2 });
143 try S.doTheTest(&[_]u8{ 1, 2 });
144 comptime try S.doTheTest(&[_]u8{ 1, 2 });
145145}
146146
147147test "for copies its payload" {
148148 const S = struct {
149 fn doTheTest() void {
149 fn doTheTest() !void {
150150 var x = [_]usize{ 1, 2, 3 };
151151 for (x) |value, i| {
152152 // Modify the original array
153153 x[i] += 99;
154 expectEqual(value, i + 1);
154 try expectEqual(value, i + 1);
155155 }
156156 }
157157 };
158 S.doTheTest();
159 comptime S.doTheTest();
158 try S.doTheTest();
159 comptime try S.doTheTest();
160160}
161161
162162test "for on slice with allowzero ptr" {
163163 const S = struct {
164 fn doTheTest(slice: []const u8) void {
164 fn doTheTest(slice: []const u8) !void {
165165 var ptr = @ptrCast([*]allowzero const u8, slice.ptr)[0..slice.len];
166 for (ptr) |x, i| expect(x == i + 1);
167 for (ptr) |*x, i| expect(x.* == i + 1);
166 for (ptr) |x, i| try expect(x == i + 1);
167 for (ptr) |*x, i| try expect(x.* == i + 1);
168168 }
169169 };
170 S.doTheTest(&[_]u8{ 1, 2, 3, 4 });
171 comptime S.doTheTest(&[_]u8{ 1, 2, 3, 4 });
170 try S.doTheTest(&[_]u8{ 1, 2, 3, 4 });
171 comptime try S.doTheTest(&[_]u8{ 1, 2, 3, 4 });
172172}
test/behavior/generics.zig+25-25
......@@ -4,9 +4,9 @@ const expect = testing.expect;
44const expectEqual = testing.expectEqual;
55
66test "simple generic fn" {
7 expect(max(i32, 3, -1) == 3);
8 expect(max(f32, 0.123, 0.456) == 0.456);
9 expect(add(2, 3) == 5);
7 try expect(max(i32, 3, -1) == 3);
8 try expect(max(f32, 0.123, 0.456) == 0.456);
9 try expect(add(2, 3) == 5);
1010}
1111
1212fn max(comptime T: type, a: T, b: T) T {
......@@ -19,7 +19,7 @@ fn add(comptime a: i32, b: i32) i32 {
1919
2020const the_max = max(u32, 1234, 5678);
2121test "compile time generic eval" {
22 expect(the_max == 5678);
22 try expect(the_max == 5678);
2323}
2424
2525fn gimmeTheBigOne(a: u32, b: u32) u32 {
......@@ -35,19 +35,19 @@ fn sameButWithFloats(a: f64, b: f64) f64 {
3535}
3636
3737test "fn with comptime args" {
38 expect(gimmeTheBigOne(1234, 5678) == 5678);
39 expect(shouldCallSameInstance(34, 12) == 34);
40 expect(sameButWithFloats(0.43, 0.49) == 0.49);
38 try expect(gimmeTheBigOne(1234, 5678) == 5678);
39 try expect(shouldCallSameInstance(34, 12) == 34);
40 try expect(sameButWithFloats(0.43, 0.49) == 0.49);
4141}
4242
4343test "var params" {
44 expect(max_i32(12, 34) == 34);
45 expect(max_f64(1.2, 3.4) == 3.4);
44 try expect(max_i32(12, 34) == 34);
45 try expect(max_f64(1.2, 3.4) == 3.4);
4646}
4747
4848comptime {
49 expect(max_i32(12, 34) == 34);
50 expect(max_f64(1.2, 3.4) == 3.4);
49 try expect(max_i32(12, 34) == 34);
50 try expect(max_f64(1.2, 3.4) == 3.4);
5151}
5252
5353fn max_var(a: anytype, b: anytype) @TypeOf(a + b) {
......@@ -79,8 +79,8 @@ test "function with return type type" {
7979 var list2: List(i32) = undefined;
8080 list.length = 10;
8181 list2.length = 10;
82 expect(list.prealloc_items.len == 8);
83 expect(list2.prealloc_items.len == 8);
82 try expect(list.prealloc_items.len == 8);
83 try expect(list2.prealloc_items.len == 8);
8484}
8585
8686test "generic struct" {
......@@ -92,9 +92,9 @@ test "generic struct" {
9292 .value = true,
9393 .next = null,
9494 };
95 expect(a1.value == 13);
96 expect(a1.value == a1.getVal());
97 expect(b1.getVal());
95 try expect(a1.value == 13);
96 try expect(a1.value == a1.getVal());
97 try expect(b1.getVal());
9898}
9999fn GenNode(comptime T: type) type {
100100 return struct {
......@@ -107,7 +107,7 @@ fn GenNode(comptime T: type) type {
107107}
108108
109109test "const decls in struct" {
110 expect(GenericDataThing(3).count_plus_one == 4);
110 try expect(GenericDataThing(3).count_plus_one == 4);
111111}
112112fn GenericDataThing(comptime count: isize) type {
113113 return struct {
......@@ -116,15 +116,15 @@ fn GenericDataThing(comptime count: isize) type {
116116}
117117
118118test "use generic param in generic param" {
119 expect(aGenericFn(i32, 3, 4) == 7);
119 try expect(aGenericFn(i32, 3, 4) == 7);
120120}
121121fn aGenericFn(comptime T: type, comptime a: T, b: T) T {
122122 return a + b;
123123}
124124
125125test "generic fn with implicit cast" {
126 expect(getFirstByte(u8, &[_]u8{13}) == 13);
127 expect(getFirstByte(u16, &[_]u16{
126 try expect(getFirstByte(u8, &[_]u8{13}) == 13);
127 try expect(getFirstByte(u16, &[_]u16{
128128 0,
129129 13,
130130 }) == 0);
......@@ -149,21 +149,21 @@ fn foo2(arg: anytype) bool {
149149}
150150
151151test "array of generic fns" {
152 expect(foos[0](true));
153 expect(!foos[1](true));
152 try expect(foos[0](true));
153 try expect(!foos[1](true));
154154}
155155
156156test "generic fn keeps non-generic parameter types" {
157157 const A = 128;
158158
159159 const S = struct {
160 fn f(comptime T: type, s: []T) void {
161 expect(A != @typeInfo(@TypeOf(s)).Pointer.alignment);
160 fn f(comptime T: type, s: []T) !void {
161 try expect(A != @typeInfo(@TypeOf(s)).Pointer.alignment);
162162 }
163163 };
164164
165165 // The compiler monomorphizes `S.f` for `T=u8` on its first use, check that
166166 // `x` type not affect `s` parameter type.
167167 var x: [16]u8 align(A) = undefined;
168 S.f(u8, &x);
168 try S.f(u8, &x);
169169}
test/behavior/hasdecl.zig+6-6
......@@ -11,11 +11,11 @@ const Bar = struct {
1111};
1212
1313test "@hasDecl" {
14 expect(@hasDecl(Foo, "public_thing"));
15 expect(!@hasDecl(Foo, "private_thing"));
16 expect(!@hasDecl(Foo, "no_thing"));
14 try expect(@hasDecl(Foo, "public_thing"));
15 try expect(!@hasDecl(Foo, "private_thing"));
16 try expect(!@hasDecl(Foo, "no_thing"));
1717
18 expect(@hasDecl(Bar, "hi"));
19 expect(@hasDecl(Bar, "blah"));
20 expect(!@hasDecl(Bar, "nope"));
18 try expect(@hasDecl(Bar, "hi"));
19 try expect(@hasDecl(Bar, "blah"));
20 try expect(!@hasDecl(Bar, "nope"));
2121}
test/behavior/hasfield.zig+12-12
......@@ -8,10 +8,10 @@ test "@hasField" {
88
99 pub const nope = 1;
1010 };
11 expect(@hasField(struc, "a") == true);
12 expect(@hasField(struc, "b") == true);
13 expect(@hasField(struc, "non-existant") == false);
14 expect(@hasField(struc, "nope") == false);
11 try expect(@hasField(struc, "a") == true);
12 try expect(@hasField(struc, "b") == true);
13 try expect(@hasField(struc, "non-existant") == false);
14 try expect(@hasField(struc, "nope") == false);
1515
1616 const unin = union {
1717 a: u64,
......@@ -19,10 +19,10 @@ test "@hasField" {
1919
2020 pub const nope = 1;
2121 };
22 expect(@hasField(unin, "a") == true);
23 expect(@hasField(unin, "b") == true);
24 expect(@hasField(unin, "non-existant") == false);
25 expect(@hasField(unin, "nope") == false);
22 try expect(@hasField(unin, "a") == true);
23 try expect(@hasField(unin, "b") == true);
24 try expect(@hasField(unin, "non-existant") == false);
25 try expect(@hasField(unin, "nope") == false);
2626
2727 const enm = enum {
2828 a,
......@@ -30,8 +30,8 @@ test "@hasField" {
3030
3131 pub const nope = 1;
3232 };
33 expect(@hasField(enm, "a") == true);
34 expect(@hasField(enm, "b") == true);
35 expect(@hasField(enm, "non-existant") == false);
36 expect(@hasField(enm, "nope") == false);
33 try expect(@hasField(enm, "a") == true);
34 try expect(@hasField(enm, "b") == true);
35 try expect(@hasField(enm, "non-existant") == false);
36 try expect(@hasField(enm, "nope") == false);
3737}
test/behavior/if.zig+14-14
......@@ -26,7 +26,7 @@ fn firstEqlThird(a: i32, b: i32, c: i32) void {
2626}
2727
2828test "else if expression" {
29 expect(elseIfExpressionF(1) == 1);
29 try expect(elseIfExpressionF(1) == 1);
3030}
3131fn elseIfExpressionF(c: u8) u8 {
3232 if (c == 0) {
......@@ -44,14 +44,14 @@ var global_with_err: anyerror!u32 = error.SomeError;
4444
4545test "unwrap mutable global var" {
4646 if (global_with_val) |v| {
47 expect(v == 0);
47 try expect(v == 0);
4848 } else |e| {
4949 unreachable;
5050 }
5151 if (global_with_err) |_| {
5252 unreachable;
5353 } else |e| {
54 expect(e == error.SomeError);
54 try expect(e == error.SomeError);
5555 }
5656}
5757
......@@ -63,7 +63,7 @@ test "labeled break inside comptime if inside runtime if" {
6363 break :blk @as(i32, 42);
6464 };
6565 }
66 expect(answer == 42);
66 try expect(answer == 42);
6767}
6868
6969test "const result loc, runtime if cond, else unreachable" {
......@@ -74,36 +74,36 @@ test "const result loc, runtime if cond, else unreachable" {
7474
7575 var t = true;
7676 const x = if (t) Num.Two else unreachable;
77 expect(x == .Two);
77 try expect(x == .Two);
7878}
7979
8080test "if prongs cast to expected type instead of peer type resolution" {
8181 const S = struct {
82 fn doTheTest(f: bool) void {
82 fn doTheTest(f: bool) !void {
8383 var x: i32 = 0;
8484 x = if (f) 1 else 2;
85 expect(x == 2);
85 try expect(x == 2);
8686
8787 var b = true;
8888 const y: i32 = if (b) 1 else 2;
89 expect(y == 1);
89 try expect(y == 1);
9090 }
9191 };
92 S.doTheTest(false);
93 comptime S.doTheTest(false);
92 try S.doTheTest(false);
93 comptime try S.doTheTest(false);
9494}
9595
9696test "while copies its payload" {
9797 const S = struct {
98 fn doTheTest() void {
98 fn doTheTest() !void {
9999 var tmp: ?i32 = 10;
100100 if (tmp) |value| {
101101 // Modify the original variable
102102 tmp = null;
103 expectEqual(@as(i32, 10), value);
103 try expectEqual(@as(i32, 10), value);
104104 } else unreachable;
105105 }
106106 };
107 S.doTheTest();
108 comptime S.doTheTest();
107 try S.doTheTest();
108 comptime try S.doTheTest();
109109}
test/behavior/import.zig+3-3
......@@ -3,18 +3,18 @@ const expectEqual = @import("std").testing.expectEqual;
33const a_namespace = @import("import/a_namespace.zig");
44
55test "call fn via namespace lookup" {
6 expectEqual(@as(i32, 1234), a_namespace.foo());
6 try expectEqual(@as(i32, 1234), a_namespace.foo());
77}
88
99test "importing the same thing gives the same import" {
10 expect(@import("std") == @import("std"));
10 try expect(@import("std") == @import("std"));
1111}
1212
1313test "import in non-toplevel scope" {
1414 const S = struct {
1515 usingnamespace @import("import/a_namespace.zig");
1616 };
17 expectEqual(@as(i32, 1234), S.foo());
17 try expectEqual(@as(i32, 1234), S.foo());
1818}
1919
2020test "import empty file" {
test/behavior/incomplete_struct_param_tld.zig+1-1
......@@ -26,5 +26,5 @@ test "incomplete struct param top level declaration" {
2626 .c = C{ .x = 13 },
2727 },
2828 };
29 expect(foo(a) == 13);
29 try expect(foo(a) == 13);
3030}
test/behavior/inttoptr.zig-4
......@@ -1,7 +1,3 @@
1const builtin = @import("builtin");
2const std = @import("std");
3const expect = std.testing.expect;
4
51test "casting random address to function pointer" {
62 randomAddressToFunction();
73 comptime randomAddressToFunction();
test/behavior/ir_block_deps.zig+2-2
......@@ -16,6 +16,6 @@ fn getErrInt() anyerror!i32 {
1616}
1717
1818test "ir block deps" {
19 expect((foo(1) catch unreachable) == 0);
20 expect((foo(2) catch unreachable) == 0);
19 try expect((foo(1) catch unreachable) == 0);
20 try expect((foo(2) catch unreachable) == 0);
2121}
test/behavior/math.zig+357-357
......@@ -7,71 +7,71 @@ const minInt = std.math.minInt;
77const mem = std.mem;
88
99test "division" {
10 testDivision();
11 comptime testDivision();
12}
13fn testDivision() void {
14 expect(div(u32, 13, 3) == 4);
15 expect(div(f16, 1.0, 2.0) == 0.5);
16 expect(div(f32, 1.0, 2.0) == 0.5);
17
18 expect(divExact(u32, 55, 11) == 5);
19 expect(divExact(i32, -55, 11) == -5);
20 expect(divExact(f16, 55.0, 11.0) == 5.0);
21 expect(divExact(f16, -55.0, 11.0) == -5.0);
22 expect(divExact(f32, 55.0, 11.0) == 5.0);
23 expect(divExact(f32, -55.0, 11.0) == -5.0);
24
25 expect(divFloor(i32, 5, 3) == 1);
26 expect(divFloor(i32, -5, 3) == -2);
27 expect(divFloor(f16, 5.0, 3.0) == 1.0);
28 expect(divFloor(f16, -5.0, 3.0) == -2.0);
29 expect(divFloor(f32, 5.0, 3.0) == 1.0);
30 expect(divFloor(f32, -5.0, 3.0) == -2.0);
31 expect(divFloor(i32, -0x80000000, -2) == 0x40000000);
32 expect(divFloor(i32, 0, -0x80000000) == 0);
33 expect(divFloor(i32, -0x40000001, 0x40000000) == -2);
34 expect(divFloor(i32, -0x80000000, 1) == -0x80000000);
35 expect(divFloor(i32, 10, 12) == 0);
36 expect(divFloor(i32, -14, 12) == -2);
37 expect(divFloor(i32, -2, 12) == -1);
38
39 expect(divTrunc(i32, 5, 3) == 1);
40 expect(divTrunc(i32, -5, 3) == -1);
41 expect(divTrunc(f16, 5.0, 3.0) == 1.0);
42 expect(divTrunc(f16, -5.0, 3.0) == -1.0);
43 expect(divTrunc(f32, 5.0, 3.0) == 1.0);
44 expect(divTrunc(f32, -5.0, 3.0) == -1.0);
45 expect(divTrunc(f64, 5.0, 3.0) == 1.0);
46 expect(divTrunc(f64, -5.0, 3.0) == -1.0);
47 expect(divTrunc(i32, 10, 12) == 0);
48 expect(divTrunc(i32, -14, 12) == -1);
49 expect(divTrunc(i32, -2, 12) == 0);
50
51 expect(mod(i32, 10, 12) == 10);
52 expect(mod(i32, -14, 12) == 10);
53 expect(mod(i32, -2, 12) == 10);
10 try testDivision();
11 comptime try testDivision();
12}
13fn testDivision() !void {
14 try expect(div(u32, 13, 3) == 4);
15 try expect(div(f16, 1.0, 2.0) == 0.5);
16 try expect(div(f32, 1.0, 2.0) == 0.5);
17
18 try expect(divExact(u32, 55, 11) == 5);
19 try expect(divExact(i32, -55, 11) == -5);
20 try expect(divExact(f16, 55.0, 11.0) == 5.0);
21 try expect(divExact(f16, -55.0, 11.0) == -5.0);
22 try expect(divExact(f32, 55.0, 11.0) == 5.0);
23 try expect(divExact(f32, -55.0, 11.0) == -5.0);
24
25 try expect(divFloor(i32, 5, 3) == 1);
26 try expect(divFloor(i32, -5, 3) == -2);
27 try expect(divFloor(f16, 5.0, 3.0) == 1.0);
28 try expect(divFloor(f16, -5.0, 3.0) == -2.0);
29 try expect(divFloor(f32, 5.0, 3.0) == 1.0);
30 try expect(divFloor(f32, -5.0, 3.0) == -2.0);
31 try expect(divFloor(i32, -0x80000000, -2) == 0x40000000);
32 try expect(divFloor(i32, 0, -0x80000000) == 0);
33 try expect(divFloor(i32, -0x40000001, 0x40000000) == -2);
34 try expect(divFloor(i32, -0x80000000, 1) == -0x80000000);
35 try expect(divFloor(i32, 10, 12) == 0);
36 try expect(divFloor(i32, -14, 12) == -2);
37 try expect(divFloor(i32, -2, 12) == -1);
38
39 try expect(divTrunc(i32, 5, 3) == 1);
40 try expect(divTrunc(i32, -5, 3) == -1);
41 try expect(divTrunc(f16, 5.0, 3.0) == 1.0);
42 try expect(divTrunc(f16, -5.0, 3.0) == -1.0);
43 try expect(divTrunc(f32, 5.0, 3.0) == 1.0);
44 try expect(divTrunc(f32, -5.0, 3.0) == -1.0);
45 try expect(divTrunc(f64, 5.0, 3.0) == 1.0);
46 try expect(divTrunc(f64, -5.0, 3.0) == -1.0);
47 try expect(divTrunc(i32, 10, 12) == 0);
48 try expect(divTrunc(i32, -14, 12) == -1);
49 try expect(divTrunc(i32, -2, 12) == 0);
50
51 try expect(mod(i32, 10, 12) == 10);
52 try expect(mod(i32, -14, 12) == 10);
53 try expect(mod(i32, -2, 12) == 10);
5454
5555 comptime {
56 expect(
56 try expect(
5757 1194735857077236777412821811143690633098347576 % 508740759824825164163191790951174292733114988 == 177254337427586449086438229241342047632117600,
5858 );
59 expect(
59 try expect(
6060 @rem(-1194735857077236777412821811143690633098347576, 508740759824825164163191790951174292733114988) == -177254337427586449086438229241342047632117600,
6161 );
62 expect(
62 try expect(
6363 1194735857077236777412821811143690633098347576 / 508740759824825164163191790951174292733114988 == 2,
6464 );
65 expect(
65 try expect(
6666 @divTrunc(-1194735857077236777412821811143690633098347576, 508740759824825164163191790951174292733114988) == -2,
6767 );
68 expect(
68 try expect(
6969 @divTrunc(1194735857077236777412821811143690633098347576, -508740759824825164163191790951174292733114988) == -2,
7070 );
71 expect(
71 try expect(
7272 @divTrunc(-1194735857077236777412821811143690633098347576, -508740759824825164163191790951174292733114988) == 2,
7373 );
74 expect(
74 try expect(
7575 4126227191251978491697987544882340798050766755606969681711 % 10 == 1,
7676 );
7777 }
......@@ -94,9 +94,9 @@ fn mod(comptime T: type, a: T, b: T) T {
9494
9595test "@addWithOverflow" {
9696 var result: u8 = undefined;
97 expect(@addWithOverflow(u8, 250, 100, &result));
98 expect(!@addWithOverflow(u8, 100, 150, &result));
99 expect(result == 250);
97 try expect(@addWithOverflow(u8, 250, 100, &result));
98 try expect(!@addWithOverflow(u8, 100, 150, &result));
99 try expect(result == 250);
100100}
101101
102102// TODO test mulWithOverflow
......@@ -104,31 +104,31 @@ test "@addWithOverflow" {
104104
105105test "@shlWithOverflow" {
106106 var result: u16 = undefined;
107 expect(@shlWithOverflow(u16, 0b0010111111111111, 3, &result));
108 expect(!@shlWithOverflow(u16, 0b0010111111111111, 2, &result));
109 expect(result == 0b1011111111111100);
107 try expect(@shlWithOverflow(u16, 0b0010111111111111, 3, &result));
108 try expect(!@shlWithOverflow(u16, 0b0010111111111111, 2, &result));
109 try expect(result == 0b1011111111111100);
110110}
111111
112112test "@*WithOverflow with u0 values" {
113113 var result: u0 = undefined;
114 expect(!@addWithOverflow(u0, 0, 0, &result));
115 expect(!@subWithOverflow(u0, 0, 0, &result));
116 expect(!@mulWithOverflow(u0, 0, 0, &result));
117 expect(!@shlWithOverflow(u0, 0, 0, &result));
114 try expect(!@addWithOverflow(u0, 0, 0, &result));
115 try expect(!@subWithOverflow(u0, 0, 0, &result));
116 try expect(!@mulWithOverflow(u0, 0, 0, &result));
117 try expect(!@shlWithOverflow(u0, 0, 0, &result));
118118}
119119
120120test "@clz" {
121 testClz();
122 comptime testClz();
121 try testClz();
122 comptime try testClz();
123123}
124124
125fn testClz() void {
126 expect(clz(u8, 0b10001010) == 0);
127 expect(clz(u8, 0b00001010) == 4);
128 expect(clz(u8, 0b00011010) == 3);
129 expect(clz(u8, 0b00000000) == 8);
130 expect(clz(u128, 0xffffffffffffffff) == 64);
131 expect(clz(u128, 0x10000000000000000) == 63);
125fn testClz() !void {
126 try expect(clz(u8, 0b10001010) == 0);
127 try expect(clz(u8, 0b00001010) == 4);
128 try expect(clz(u8, 0b00011010) == 3);
129 try expect(clz(u8, 0b00000000) == 8);
130 try expect(clz(u128, 0xffffffffffffffff) == 64);
131 try expect(clz(u128, 0x10000000000000000) == 63);
132132}
133133
134134fn clz(comptime T: type, x: T) usize {
......@@ -136,15 +136,15 @@ fn clz(comptime T: type, x: T) usize {
136136}
137137
138138test "@ctz" {
139 testCtz();
140 comptime testCtz();
139 try testCtz();
140 comptime try testCtz();
141141}
142142
143fn testCtz() void {
144 expect(ctz(u8, 0b10100000) == 5);
145 expect(ctz(u8, 0b10001010) == 1);
146 expect(ctz(u8, 0b00000000) == 8);
147 expect(ctz(u16, 0b00000000) == 16);
143fn testCtz() !void {
144 try expect(ctz(u8, 0b10100000) == 5);
145 try expect(ctz(u8, 0b10001010) == 1);
146 try expect(ctz(u8, 0b00000000) == 8);
147 try expect(ctz(u16, 0b00000000) == 16);
148148}
149149
150150fn ctz(comptime T: type, x: T) usize {
......@@ -154,109 +154,109 @@ fn ctz(comptime T: type, x: T) usize {
154154test "assignment operators" {
155155 var i: u32 = 0;
156156 i += 5;
157 expect(i == 5);
157 try expect(i == 5);
158158 i -= 2;
159 expect(i == 3);
159 try expect(i == 3);
160160 i *= 20;
161 expect(i == 60);
161 try expect(i == 60);
162162 i /= 3;
163 expect(i == 20);
163 try expect(i == 20);
164164 i %= 11;
165 expect(i == 9);
165 try expect(i == 9);
166166 i <<= 1;
167 expect(i == 18);
167 try expect(i == 18);
168168 i >>= 2;
169 expect(i == 4);
169 try expect(i == 4);
170170 i = 6;
171171 i &= 5;
172 expect(i == 4);
172 try expect(i == 4);
173173 i ^= 6;
174 expect(i == 2);
174 try expect(i == 2);
175175 i = 6;
176176 i |= 3;
177 expect(i == 7);
177 try expect(i == 7);
178178}
179179
180180test "three expr in a row" {
181 testThreeExprInARow(false, true);
182 comptime testThreeExprInARow(false, true);
183}
184fn testThreeExprInARow(f: bool, t: bool) void {
185 assertFalse(f or f or f);
186 assertFalse(t and t and f);
187 assertFalse(1 | 2 | 4 != 7);
188 assertFalse(3 ^ 6 ^ 8 != 13);
189 assertFalse(7 & 14 & 28 != 4);
190 assertFalse(9 << 1 << 2 != 9 << 3);
191 assertFalse(90 >> 1 >> 2 != 90 >> 3);
192 assertFalse(100 - 1 + 1000 != 1099);
193 assertFalse(5 * 4 / 2 % 3 != 1);
194 assertFalse(@as(i32, @as(i32, 5)) != 5);
195 assertFalse(!!false);
196 assertFalse(@as(i32, 7) != --(@as(i32, 7)));
197}
198fn assertFalse(b: bool) void {
199 expect(!b);
181 try testThreeExprInARow(false, true);
182 comptime try testThreeExprInARow(false, true);
183}
184fn testThreeExprInARow(f: bool, t: bool) !void {
185 try assertFalse(f or f or f);
186 try assertFalse(t and t and f);
187 try assertFalse(1 | 2 | 4 != 7);
188 try assertFalse(3 ^ 6 ^ 8 != 13);
189 try assertFalse(7 & 14 & 28 != 4);
190 try assertFalse(9 << 1 << 2 != 9 << 3);
191 try assertFalse(90 >> 1 >> 2 != 90 >> 3);
192 try assertFalse(100 - 1 + 1000 != 1099);
193 try assertFalse(5 * 4 / 2 % 3 != 1);
194 try assertFalse(@as(i32, @as(i32, 5)) != 5);
195 try assertFalse(!!false);
196 try assertFalse(@as(i32, 7) != --(@as(i32, 7)));
197}
198fn assertFalse(b: bool) !void {
199 try expect(!b);
200200}
201201
202202test "const number literal" {
203203 const one = 1;
204204 const eleven = ten + one;
205205
206 expect(eleven == 11);
206 try expect(eleven == 11);
207207}
208208const ten = 10;
209209
210210test "unsigned wrapping" {
211 testUnsignedWrappingEval(maxInt(u32));
212 comptime testUnsignedWrappingEval(maxInt(u32));
211 try testUnsignedWrappingEval(maxInt(u32));
212 comptime try testUnsignedWrappingEval(maxInt(u32));
213213}
214fn testUnsignedWrappingEval(x: u32) void {
214fn testUnsignedWrappingEval(x: u32) !void {
215215 const zero = x +% 1;
216 expect(zero == 0);
216 try expect(zero == 0);
217217 const orig = zero -% 1;
218 expect(orig == maxInt(u32));
218 try expect(orig == maxInt(u32));
219219}
220220
221221test "signed wrapping" {
222 testSignedWrappingEval(maxInt(i32));
223 comptime testSignedWrappingEval(maxInt(i32));
222 try testSignedWrappingEval(maxInt(i32));
223 comptime try testSignedWrappingEval(maxInt(i32));
224224}
225fn testSignedWrappingEval(x: i32) void {
225fn testSignedWrappingEval(x: i32) !void {
226226 const min_val = x +% 1;
227 expect(min_val == minInt(i32));
227 try expect(min_val == minInt(i32));
228228 const max_val = min_val -% 1;
229 expect(max_val == maxInt(i32));
229 try expect(max_val == maxInt(i32));
230230}
231231
232232test "signed negation wrapping" {
233 testSignedNegationWrappingEval(minInt(i16));
234 comptime testSignedNegationWrappingEval(minInt(i16));
233 try testSignedNegationWrappingEval(minInt(i16));
234 comptime try testSignedNegationWrappingEval(minInt(i16));
235235}
236fn testSignedNegationWrappingEval(x: i16) void {
237 expect(x == -32768);
236fn testSignedNegationWrappingEval(x: i16) !void {
237 try expect(x == -32768);
238238 const neg = -%x;
239 expect(neg == -32768);
239 try expect(neg == -32768);
240240}
241241
242242test "unsigned negation wrapping" {
243 testUnsignedNegationWrappingEval(1);
244 comptime testUnsignedNegationWrappingEval(1);
243 try testUnsignedNegationWrappingEval(1);
244 comptime try testUnsignedNegationWrappingEval(1);
245245}
246fn testUnsignedNegationWrappingEval(x: u16) void {
247 expect(x == 1);
246fn testUnsignedNegationWrappingEval(x: u16) !void {
247 try expect(x == 1);
248248 const neg = -%x;
249 expect(neg == maxInt(u16));
249 try expect(neg == maxInt(u16));
250250}
251251
252252test "unsigned 64-bit division" {
253 test_u64_div();
254 comptime test_u64_div();
253 try test_u64_div();
254 comptime try test_u64_div();
255255}
256fn test_u64_div() void {
256fn test_u64_div() !void {
257257 const result = divWithResult(1152921504606846976, 34359738365);
258 expect(result.quotient == 33554432);
259 expect(result.remainder == 100663296);
258 try expect(result.quotient == 33554432);
259 try expect(result.remainder == 100663296);
260260}
261261fn divWithResult(a: u64, b: u64) DivResult {
262262 return DivResult{
......@@ -270,62 +270,62 @@ const DivResult = struct {
270270};
271271
272272test "binary not" {
273 expect(comptime x: {
273 try expect(comptime x: {
274274 break :x ~@as(u16, 0b1010101010101010) == 0b0101010101010101;
275275 });
276 expect(comptime x: {
276 try expect(comptime x: {
277277 break :x ~@as(u64, 2147483647) == 18446744071562067968;
278278 });
279 testBinaryNot(0b1010101010101010);
279 try testBinaryNot(0b1010101010101010);
280280}
281281
282fn testBinaryNot(x: u16) void {
283 expect(~x == 0b0101010101010101);
282fn testBinaryNot(x: u16) !void {
283 try expect(~x == 0b0101010101010101);
284284}
285285
286286test "small int addition" {
287287 var x: u2 = 0;
288 expect(x == 0);
288 try expect(x == 0);
289289
290290 x += 1;
291 expect(x == 1);
291 try expect(x == 1);
292292
293293 x += 1;
294 expect(x == 2);
294 try expect(x == 2);
295295
296296 x += 1;
297 expect(x == 3);
297 try expect(x == 3);
298298
299299 var result: @TypeOf(x) = 3;
300 expect(@addWithOverflow(@TypeOf(x), x, 1, &result));
300 try expect(@addWithOverflow(@TypeOf(x), x, 1, &result));
301301
302 expect(result == 0);
302 try expect(result == 0);
303303}
304304
305305test "float equality" {
306306 const x: f64 = 0.012;
307307 const y: f64 = x + 1.0;
308308
309 testFloatEqualityImpl(x, y);
310 comptime testFloatEqualityImpl(x, y);
309 try testFloatEqualityImpl(x, y);
310 comptime try testFloatEqualityImpl(x, y);
311311}
312312
313fn testFloatEqualityImpl(x: f64, y: f64) void {
313fn testFloatEqualityImpl(x: f64, y: f64) !void {
314314 const y2 = x + 1.0;
315 expect(y == y2);
315 try expect(y == y2);
316316}
317317
318318test "allow signed integer division/remainder when values are comptime known and positive or exact" {
319 expect(5 / 3 == 1);
320 expect(-5 / -3 == 1);
321 expect(-6 / 3 == -2);
319 try expect(5 / 3 == 1);
320 try expect(-5 / -3 == 1);
321 try expect(-6 / 3 == -2);
322322
323 expect(5 % 3 == 2);
324 expect(-6 % 3 == 0);
323 try expect(5 % 3 == 2);
324 try expect(-6 % 3 == 0);
325325}
326326
327327test "hex float literal parsing" {
328 comptime expect(0x1.0 == 1.0);
328 comptime try expect(0x1.0 == 1.0);
329329}
330330
331331test "quad hex float literal parsing in range" {
......@@ -340,29 +340,29 @@ test "quad hex float literal parsing accurate" {
340340
341341 // implied 1 is dropped, with an exponent of 0 (0x3fff) after biasing.
342342 const expected: u128 = 0x3fff1111222233334444555566667777;
343 expect(@bitCast(u128, a) == expected);
343 try expect(@bitCast(u128, a) == expected);
344344
345345 // non-normalized
346346 const b: f128 = 0x11.111222233334444555566667777p-4;
347 expect(@bitCast(u128, b) == expected);
347 try expect(@bitCast(u128, b) == expected);
348348
349349 const S = struct {
350 fn doTheTest() void {
350 fn doTheTest() !void {
351351 {
352352 var f: f128 = 0x1.2eab345678439abcdefea56782346p+5;
353 expect(@bitCast(u128, f) == 0x40042eab345678439abcdefea5678234);
353 try expect(@bitCast(u128, f) == 0x40042eab345678439abcdefea5678234);
354354 }
355355 {
356356 var f: f128 = 0x1.edcb34a235253948765432134674fp-1;
357 expect(@bitCast(u128, f) == 0x3ffeedcb34a235253948765432134674);
357 try expect(@bitCast(u128, f) == 0x3ffeedcb34a235253948765432134674);
358358 }
359359 {
360360 var f: f128 = 0x1.353e45674d89abacc3a2ebf3ff4ffp-50;
361 expect(@bitCast(u128, f) == 0x3fcd353e45674d89abacc3a2ebf3ff50);
361 try expect(@bitCast(u128, f) == 0x3fcd353e45674d89abacc3a2ebf3ff50);
362362 }
363363 {
364364 var f: f128 = 0x1.ed8764648369535adf4be3214567fp-9;
365 expect(@bitCast(u128, f) == 0x3ff6ed8764648369535adf4be3214568);
365 try expect(@bitCast(u128, f) == 0x3ff6ed8764648369535adf4be3214568);
366366 }
367367 const exp2ft = [_]f64{
368368 0x1.6a09e667f3bcdp-1,
......@@ -417,40 +417,40 @@ test "quad hex float literal parsing accurate" {
417417 };
418418
419419 for (exp2ft) |x, i| {
420 expect(@bitCast(u64, x) == answers[i]);
420 try expect(@bitCast(u64, x) == answers[i]);
421421 }
422422 }
423423 };
424 S.doTheTest();
425 comptime S.doTheTest();
424 try S.doTheTest();
425 comptime try S.doTheTest();
426426}
427427
428428test "underscore separator parsing" {
429 expect(0_0_0_0 == 0);
430 expect(1_234_567 == 1234567);
431 expect(001_234_567 == 1234567);
432 expect(0_0_1_2_3_4_5_6_7 == 1234567);
429 try expect(0_0_0_0 == 0);
430 try expect(1_234_567 == 1234567);
431 try expect(001_234_567 == 1234567);
432 try expect(0_0_1_2_3_4_5_6_7 == 1234567);
433433
434 expect(0b0_0_0_0 == 0);
435 expect(0b1010_1010 == 0b10101010);
436 expect(0b0000_1010_1010 == 0b10101010);
437 expect(0b1_0_1_0_1_0_1_0 == 0b10101010);
434 try expect(0b0_0_0_0 == 0);
435 try expect(0b1010_1010 == 0b10101010);
436 try expect(0b0000_1010_1010 == 0b10101010);
437 try expect(0b1_0_1_0_1_0_1_0 == 0b10101010);
438438
439 expect(0o0_0_0_0 == 0);
440 expect(0o1010_1010 == 0o10101010);
441 expect(0o0000_1010_1010 == 0o10101010);
442 expect(0o1_0_1_0_1_0_1_0 == 0o10101010);
439 try expect(0o0_0_0_0 == 0);
440 try expect(0o1010_1010 == 0o10101010);
441 try expect(0o0000_1010_1010 == 0o10101010);
442 try expect(0o1_0_1_0_1_0_1_0 == 0o10101010);
443443
444 expect(0x0_0_0_0 == 0);
445 expect(0x1010_1010 == 0x10101010);
446 expect(0x0000_1010_1010 == 0x10101010);
447 expect(0x1_0_1_0_1_0_1_0 == 0x10101010);
444 try expect(0x0_0_0_0 == 0);
445 try expect(0x1010_1010 == 0x10101010);
446 try expect(0x0000_1010_1010 == 0x10101010);
447 try expect(0x1_0_1_0_1_0_1_0 == 0x10101010);
448448
449 expect(123_456.789_000e1_0 == 123456.789000e10);
450 expect(0_1_2_3_4_5_6.7_8_9_0_0_0e0_0_1_0 == 123456.789000e10);
449 try expect(123_456.789_000e1_0 == 123456.789000e10);
450 try expect(0_1_2_3_4_5_6.7_8_9_0_0_0e0_0_1_0 == 123456.789000e10);
451451
452 expect(0x1234_5678.9ABC_DEF0p-1_0 == 0x12345678.9ABCDEF0p-10);
453 expect(0x1_2_3_4_5_6_7_8.9_A_B_C_D_E_F_0p-0_0_0_1_0 == 0x12345678.9ABCDEF0p-10);
452 try expect(0x1234_5678.9ABC_DEF0p-1_0 == 0x12345678.9ABCDEF0p-10);
453 try expect(0x1_2_3_4_5_6_7_8.9_A_B_C_D_E_F_0p-0_0_0_1_0 == 0x12345678.9ABCDEF0p-10);
454454}
455455
456456test "hex float literal within range" {
......@@ -460,73 +460,73 @@ test "hex float literal within range" {
460460}
461461
462462test "truncating shift left" {
463 testShlTrunc(maxInt(u16));
464 comptime testShlTrunc(maxInt(u16));
463 try testShlTrunc(maxInt(u16));
464 comptime try testShlTrunc(maxInt(u16));
465465}
466fn testShlTrunc(x: u16) void {
466fn testShlTrunc(x: u16) !void {
467467 const shifted = x << 1;
468 expect(shifted == 65534);
468 try expect(shifted == 65534);
469469}
470470
471471test "truncating shift right" {
472 testShrTrunc(maxInt(u16));
473 comptime testShrTrunc(maxInt(u16));
472 try testShrTrunc(maxInt(u16));
473 comptime try testShrTrunc(maxInt(u16));
474474}
475fn testShrTrunc(x: u16) void {
475fn testShrTrunc(x: u16) !void {
476476 const shifted = x >> 1;
477 expect(shifted == 32767);
477 try expect(shifted == 32767);
478478}
479479
480480test "exact shift left" {
481 testShlExact(0b00110101);
482 comptime testShlExact(0b00110101);
481 try testShlExact(0b00110101);
482 comptime try testShlExact(0b00110101);
483483}
484fn testShlExact(x: u8) void {
484fn testShlExact(x: u8) !void {
485485 const shifted = @shlExact(x, 2);
486 expect(shifted == 0b11010100);
486 try expect(shifted == 0b11010100);
487487}
488488
489489test "exact shift right" {
490 testShrExact(0b10110100);
491 comptime testShrExact(0b10110100);
490 try testShrExact(0b10110100);
491 comptime try testShrExact(0b10110100);
492492}
493fn testShrExact(x: u8) void {
493fn testShrExact(x: u8) !void {
494494 const shifted = @shrExact(x, 2);
495 expect(shifted == 0b00101101);
495 try expect(shifted == 0b00101101);
496496}
497497
498498test "shift left/right on u0 operand" {
499499 const S = struct {
500 fn doTheTest() void {
500 fn doTheTest() !void {
501501 var x: u0 = 0;
502502 var y: u0 = 0;
503 expectEqual(@as(u0, 0), x << 0);
504 expectEqual(@as(u0, 0), x >> 0);
505 expectEqual(@as(u0, 0), x << y);
506 expectEqual(@as(u0, 0), x >> y);
507 expectEqual(@as(u0, 0), @shlExact(x, 0));
508 expectEqual(@as(u0, 0), @shrExact(x, 0));
509 expectEqual(@as(u0, 0), @shlExact(x, y));
510 expectEqual(@as(u0, 0), @shrExact(x, y));
503 try expectEqual(@as(u0, 0), x << 0);
504 try expectEqual(@as(u0, 0), x >> 0);
505 try expectEqual(@as(u0, 0), x << y);
506 try expectEqual(@as(u0, 0), x >> y);
507 try expectEqual(@as(u0, 0), @shlExact(x, 0));
508 try expectEqual(@as(u0, 0), @shrExact(x, 0));
509 try expectEqual(@as(u0, 0), @shlExact(x, y));
510 try expectEqual(@as(u0, 0), @shrExact(x, y));
511511 }
512512 };
513 S.doTheTest();
514 comptime S.doTheTest();
513 try S.doTheTest();
514 comptime try S.doTheTest();
515515}
516516
517517test "comptime_int addition" {
518518 comptime {
519 expect(35361831660712422535336160538497375248 + 101752735581729509668353361206450473702 == 137114567242441932203689521744947848950);
520 expect(594491908217841670578297176641415611445982232488944558774612 + 390603545391089362063884922208143568023166603618446395589768 == 985095453608931032642182098849559179469148836107390954364380);
519 try expect(35361831660712422535336160538497375248 + 101752735581729509668353361206450473702 == 137114567242441932203689521744947848950);
520 try expect(594491908217841670578297176641415611445982232488944558774612 + 390603545391089362063884922208143568023166603618446395589768 == 985095453608931032642182098849559179469148836107390954364380);
521521 }
522522}
523523
524524test "comptime_int multiplication" {
525525 comptime {
526 expect(
526 try expect(
527527 45960427431263824329884196484953148229 * 128339149605334697009938835852565949723 == 5898522172026096622534201617172456926982464453350084962781392314016180490567,
528528 );
529 expect(
529 try expect(
530530 594491908217841670578297176641415611445982232488944558774612 * 390603545391089362063884922208143568023166603618446395589768 == 232210647056203049913662402532976186578842425262306016094292237500303028346593132411865381225871291702600263463125370016,
531531 );
532532 }
......@@ -534,7 +534,7 @@ test "comptime_int multiplication" {
534534
535535test "comptime_int shifting" {
536536 comptime {
537 expect((@as(u128, 1) << 127) == 0x80000000000000000000000000000000);
537 try expect((@as(u128, 1) << 127) == 0x80000000000000000000000000000000);
538538 }
539539}
540540
......@@ -542,16 +542,16 @@ test "comptime_int multi-limb shift and mask" {
542542 comptime {
543543 var a = 0xefffffffa0000001eeeeeeefaaaaaaab;
544544
545 expect(@as(u32, a & 0xffffffff) == 0xaaaaaaab);
545 try expect(@as(u32, a & 0xffffffff) == 0xaaaaaaab);
546546 a >>= 32;
547 expect(@as(u32, a & 0xffffffff) == 0xeeeeeeef);
547 try expect(@as(u32, a & 0xffffffff) == 0xeeeeeeef);
548548 a >>= 32;
549 expect(@as(u32, a & 0xffffffff) == 0xa0000001);
549 try expect(@as(u32, a & 0xffffffff) == 0xa0000001);
550550 a >>= 32;
551 expect(@as(u32, a & 0xffffffff) == 0xefffffff);
551 try expect(@as(u32, a & 0xffffffff) == 0xefffffff);
552552 a >>= 32;
553553
554 expect(a == 0);
554 try expect(a == 0);
555555 }
556556}
557557
......@@ -559,227 +559,227 @@ test "comptime_int multi-limb partial shift right" {
559559 comptime {
560560 var a = 0x1ffffffffeeeeeeee;
561561 a >>= 16;
562 expect(a == 0x1ffffffffeeee);
562 try expect(a == 0x1ffffffffeeee);
563563 }
564564}
565565
566566test "xor" {
567 test_xor();
568 comptime test_xor();
567 try test_xor();
568 comptime try test_xor();
569569}
570570
571fn test_xor() void {
572 expect(0xFF ^ 0x00 == 0xFF);
573 expect(0xF0 ^ 0x0F == 0xFF);
574 expect(0xFF ^ 0xF0 == 0x0F);
575 expect(0xFF ^ 0x0F == 0xF0);
576 expect(0xFF ^ 0xFF == 0x00);
571fn test_xor() !void {
572 try expect(0xFF ^ 0x00 == 0xFF);
573 try expect(0xF0 ^ 0x0F == 0xFF);
574 try expect(0xFF ^ 0xF0 == 0x0F);
575 try expect(0xFF ^ 0x0F == 0xF0);
576 try expect(0xFF ^ 0xFF == 0x00);
577577}
578578
579579test "comptime_int xor" {
580580 comptime {
581 expect(0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF ^ 0x00000000000000000000000000000000 == 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF);
582 expect(0xFFFFFFFFFFFFFFFF0000000000000000 ^ 0x0000000000000000FFFFFFFFFFFFFFFF == 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF);
583 expect(0xFFFFFFFFFFFFFFFF0000000000000000 ^ 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF == 0x0000000000000000FFFFFFFFFFFFFFFF);
584 expect(0x0000000000000000FFFFFFFFFFFFFFFF ^ 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF == 0xFFFFFFFFFFFFFFFF0000000000000000);
585 expect(0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF ^ 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF == 0x00000000000000000000000000000000);
586 expect(0xFFFFFFFF00000000FFFFFFFF00000000 ^ 0x00000000FFFFFFFF00000000FFFFFFFF == 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF);
587 expect(0xFFFFFFFF00000000FFFFFFFF00000000 ^ 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF == 0x00000000FFFFFFFF00000000FFFFFFFF);
588 expect(0x00000000FFFFFFFF00000000FFFFFFFF ^ 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF == 0xFFFFFFFF00000000FFFFFFFF00000000);
581 try expect(0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF ^ 0x00000000000000000000000000000000 == 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF);
582 try expect(0xFFFFFFFFFFFFFFFF0000000000000000 ^ 0x0000000000000000FFFFFFFFFFFFFFFF == 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF);
583 try expect(0xFFFFFFFFFFFFFFFF0000000000000000 ^ 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF == 0x0000000000000000FFFFFFFFFFFFFFFF);
584 try expect(0x0000000000000000FFFFFFFFFFFFFFFF ^ 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF == 0xFFFFFFFFFFFFFFFF0000000000000000);
585 try expect(0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF ^ 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF == 0x00000000000000000000000000000000);
586 try expect(0xFFFFFFFF00000000FFFFFFFF00000000 ^ 0x00000000FFFFFFFF00000000FFFFFFFF == 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF);
587 try expect(0xFFFFFFFF00000000FFFFFFFF00000000 ^ 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF == 0x00000000FFFFFFFF00000000FFFFFFFF);
588 try expect(0x00000000FFFFFFFF00000000FFFFFFFF ^ 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF == 0xFFFFFFFF00000000FFFFFFFF00000000);
589589 }
590590}
591591
592592test "f128" {
593 test_f128();
594 comptime test_f128();
593 try test_f128();
594 comptime try test_f128();
595595}
596596
597597fn make_f128(x: f128) f128 {
598598 return x;
599599}
600600
601fn test_f128() void {
602 expect(@sizeOf(f128) == 16);
603 expect(make_f128(1.0) == 1.0);
604 expect(make_f128(1.0) != 1.1);
605 expect(make_f128(1.0) > 0.9);
606 expect(make_f128(1.0) >= 0.9);
607 expect(make_f128(1.0) >= 1.0);
608 should_not_be_zero(1.0);
601fn test_f128() !void {
602 try expect(@sizeOf(f128) == 16);
603 try expect(make_f128(1.0) == 1.0);
604 try expect(make_f128(1.0) != 1.1);
605 try expect(make_f128(1.0) > 0.9);
606 try expect(make_f128(1.0) >= 0.9);
607 try expect(make_f128(1.0) >= 1.0);
608 try should_not_be_zero(1.0);
609609}
610610
611fn should_not_be_zero(x: f128) void {
612 expect(x != 0.0);
611fn should_not_be_zero(x: f128) !void {
612 try expect(x != 0.0);
613613}
614614
615615test "comptime float rem int" {
616616 comptime {
617617 var x = @as(f32, 1) % 2;
618 expect(x == 1.0);
618 try expect(x == 1.0);
619619 }
620620}
621621
622622test "remainder division" {
623 comptime remdiv(f16);
624 comptime remdiv(f32);
625 comptime remdiv(f64);
626 comptime remdiv(f128);
627 remdiv(f16);
628 remdiv(f64);
629 remdiv(f128);
623 comptime try remdiv(f16);
624 comptime try remdiv(f32);
625 comptime try remdiv(f64);
626 comptime try remdiv(f128);
627 try remdiv(f16);
628 try remdiv(f64);
629 try remdiv(f128);
630630}
631631
632fn remdiv(comptime T: type) void {
633 expect(@as(T, 1) == @as(T, 1) % @as(T, 2));
634 expect(@as(T, 1) == @as(T, 7) % @as(T, 3));
632fn remdiv(comptime T: type) !void {
633 try expect(@as(T, 1) == @as(T, 1) % @as(T, 2));
634 try expect(@as(T, 1) == @as(T, 7) % @as(T, 3));
635635}
636636
637637test "@sqrt" {
638 testSqrt(f64, 12.0);
639 comptime testSqrt(f64, 12.0);
640 testSqrt(f32, 13.0);
641 comptime testSqrt(f32, 13.0);
642 testSqrt(f16, 13.0);
643 comptime testSqrt(f16, 13.0);
638 try testSqrt(f64, 12.0);
639 comptime try testSqrt(f64, 12.0);
640 try testSqrt(f32, 13.0);
641 comptime try testSqrt(f32, 13.0);
642 try testSqrt(f16, 13.0);
643 comptime try testSqrt(f16, 13.0);
644644
645645 const x = 14.0;
646646 const y = x * x;
647647 const z = @sqrt(y);
648 comptime expect(z == x);
648 comptime try expect(z == x);
649649}
650650
651fn testSqrt(comptime T: type, x: T) void {
652 expect(@sqrt(x * x) == x);
651fn testSqrt(comptime T: type, x: T) !void {
652 try expect(@sqrt(x * x) == x);
653653}
654654
655655test "@fabs" {
656 testFabs(f128, 12.0);
657 comptime testFabs(f128, 12.0);
658 testFabs(f64, 12.0);
659 comptime testFabs(f64, 12.0);
660 testFabs(f32, 12.0);
661 comptime testFabs(f32, 12.0);
662 testFabs(f16, 12.0);
663 comptime testFabs(f16, 12.0);
656 try testFabs(f128, 12.0);
657 comptime try testFabs(f128, 12.0);
658 try testFabs(f64, 12.0);
659 comptime try testFabs(f64, 12.0);
660 try testFabs(f32, 12.0);
661 comptime try testFabs(f32, 12.0);
662 try testFabs(f16, 12.0);
663 comptime try testFabs(f16, 12.0);
664664
665665 const x = 14.0;
666666 const y = -x;
667667 const z = @fabs(y);
668 comptime expectEqual(x, z);
668 comptime try expectEqual(x, z);
669669}
670670
671fn testFabs(comptime T: type, x: T) void {
671fn testFabs(comptime T: type, x: T) !void {
672672 const y = -x;
673673 const z = @fabs(y);
674 expectEqual(x, z);
674 try expectEqual(x, z);
675675}
676676
677677test "@floor" {
678678 // FIXME: Generates a floorl function call
679679 // testFloor(f128, 12.0);
680 comptime testFloor(f128, 12.0);
681 testFloor(f64, 12.0);
682 comptime testFloor(f64, 12.0);
683 testFloor(f32, 12.0);
684 comptime testFloor(f32, 12.0);
685 testFloor(f16, 12.0);
686 comptime testFloor(f16, 12.0);
680 comptime try testFloor(f128, 12.0);
681 try testFloor(f64, 12.0);
682 comptime try testFloor(f64, 12.0);
683 try testFloor(f32, 12.0);
684 comptime try testFloor(f32, 12.0);
685 try testFloor(f16, 12.0);
686 comptime try testFloor(f16, 12.0);
687687
688688 const x = 14.0;
689689 const y = x + 0.7;
690690 const z = @floor(y);
691 comptime expectEqual(x, z);
691 comptime try expectEqual(x, z);
692692}
693693
694fn testFloor(comptime T: type, x: T) void {
694fn testFloor(comptime T: type, x: T) !void {
695695 const y = x + 0.6;
696696 const z = @floor(y);
697 expectEqual(x, z);
697 try expectEqual(x, z);
698698}
699699
700700test "@ceil" {
701701 // FIXME: Generates a ceill function call
702702 //testCeil(f128, 12.0);
703 comptime testCeil(f128, 12.0);
704 testCeil(f64, 12.0);
705 comptime testCeil(f64, 12.0);
706 testCeil(f32, 12.0);
707 comptime testCeil(f32, 12.0);
708 testCeil(f16, 12.0);
709 comptime testCeil(f16, 12.0);
703 comptime try testCeil(f128, 12.0);
704 try testCeil(f64, 12.0);
705 comptime try testCeil(f64, 12.0);
706 try testCeil(f32, 12.0);
707 comptime try testCeil(f32, 12.0);
708 try testCeil(f16, 12.0);
709 comptime try testCeil(f16, 12.0);
710710
711711 const x = 14.0;
712712 const y = x - 0.7;
713713 const z = @ceil(y);
714 comptime expectEqual(x, z);
714 comptime try expectEqual(x, z);
715715}
716716
717fn testCeil(comptime T: type, x: T) void {
717fn testCeil(comptime T: type, x: T) !void {
718718 const y = x - 0.8;
719719 const z = @ceil(y);
720 expectEqual(x, z);
720 try expectEqual(x, z);
721721}
722722
723723test "@trunc" {
724724 // FIXME: Generates a truncl function call
725725 //testTrunc(f128, 12.0);
726 comptime testTrunc(f128, 12.0);
727 testTrunc(f64, 12.0);
728 comptime testTrunc(f64, 12.0);
729 testTrunc(f32, 12.0);
730 comptime testTrunc(f32, 12.0);
731 testTrunc(f16, 12.0);
732 comptime testTrunc(f16, 12.0);
726 comptime try testTrunc(f128, 12.0);
727 try testTrunc(f64, 12.0);
728 comptime try testTrunc(f64, 12.0);
729 try testTrunc(f32, 12.0);
730 comptime try testTrunc(f32, 12.0);
731 try testTrunc(f16, 12.0);
732 comptime try testTrunc(f16, 12.0);
733733
734734 const x = 14.0;
735735 const y = x + 0.7;
736736 const z = @trunc(y);
737 comptime expectEqual(x, z);
737 comptime try expectEqual(x, z);
738738}
739739
740fn testTrunc(comptime T: type, x: T) void {
740fn testTrunc(comptime T: type, x: T) !void {
741741 {
742742 const y = x + 0.8;
743743 const z = @trunc(y);
744 expectEqual(x, z);
744 try expectEqual(x, z);
745745 }
746746
747747 {
748748 const y = -x - 0.8;
749749 const z = @trunc(y);
750 expectEqual(-x, z);
750 try expectEqual(-x, z);
751751 }
752752}
753753
754754test "@round" {
755755 // FIXME: Generates a roundl function call
756756 //testRound(f128, 12.0);
757 comptime testRound(f128, 12.0);
758 testRound(f64, 12.0);
759 comptime testRound(f64, 12.0);
760 testRound(f32, 12.0);
761 comptime testRound(f32, 12.0);
762 testRound(f16, 12.0);
763 comptime testRound(f16, 12.0);
757 comptime try testRound(f128, 12.0);
758 try testRound(f64, 12.0);
759 comptime try testRound(f64, 12.0);
760 try testRound(f32, 12.0);
761 comptime try testRound(f32, 12.0);
762 try testRound(f16, 12.0);
763 comptime try testRound(f16, 12.0);
764764
765765 const x = 14.0;
766766 const y = x + 0.4;
767767 const z = @round(y);
768 comptime expectEqual(x, z);
768 comptime try expectEqual(x, z);
769769}
770770
771fn testRound(comptime T: type, x: T) void {
771fn testRound(comptime T: type, x: T) !void {
772772 const y = x - 0.5;
773773 const z = @round(y);
774 expectEqual(x, z);
774 try expectEqual(x, z);
775775}
776776
777777test "comptime_int param and return" {
778778 const a = comptimeAdd(35361831660712422535336160538497375248, 101752735581729509668353361206450473702);
779 expect(a == 137114567242441932203689521744947848950);
779 try expect(a == 137114567242441932203689521744947848950);
780780
781781 const b = comptimeAdd(594491908217841670578297176641415611445982232488944558774612, 390603545391089362063884922208143568023166603618446395589768);
782 expect(b == 985095453608931032642182098849559179469148836107390954364380);
782 try expect(b == 985095453608931032642182098849559179469148836107390954364380);
783783}
784784
785785fn comptimeAdd(comptime a: comptime_int, comptime b: comptime_int) comptime_int {
......@@ -788,85 +788,85 @@ fn comptimeAdd(comptime a: comptime_int, comptime b: comptime_int) comptime_int
788788
789789test "vector integer addition" {
790790 const S = struct {
791 fn doTheTest() void {
791 fn doTheTest() !void {
792792 var a: std.meta.Vector(4, i32) = [_]i32{ 1, 2, 3, 4 };
793793 var b: std.meta.Vector(4, i32) = [_]i32{ 5, 6, 7, 8 };
794794 var result = a + b;
795795 var result_array: [4]i32 = result;
796796 const expected = [_]i32{ 6, 8, 10, 12 };
797 expectEqualSlices(i32, &expected, &result_array);
797 try expectEqualSlices(i32, &expected, &result_array);
798798 }
799799 };
800 S.doTheTest();
801 comptime S.doTheTest();
800 try S.doTheTest();
801 comptime try S.doTheTest();
802802}
803803
804804test "NaN comparison" {
805 testNanEqNan(f16);
806 testNanEqNan(f32);
807 testNanEqNan(f64);
808 testNanEqNan(f128);
809 comptime testNanEqNan(f16);
810 comptime testNanEqNan(f32);
811 comptime testNanEqNan(f64);
812 comptime testNanEqNan(f128);
805 try testNanEqNan(f16);
806 try testNanEqNan(f32);
807 try testNanEqNan(f64);
808 try testNanEqNan(f128);
809 comptime try testNanEqNan(f16);
810 comptime try testNanEqNan(f32);
811 comptime try testNanEqNan(f64);
812 comptime try testNanEqNan(f128);
813813}
814814
815fn testNanEqNan(comptime F: type) void {
815fn testNanEqNan(comptime F: type) !void {
816816 var nan1 = std.math.nan(F);
817817 var nan2 = std.math.nan(F);
818 expect(nan1 != nan2);
819 expect(!(nan1 == nan2));
820 expect(!(nan1 > nan2));
821 expect(!(nan1 >= nan2));
822 expect(!(nan1 < nan2));
823 expect(!(nan1 <= nan2));
818 try expect(nan1 != nan2);
819 try expect(!(nan1 == nan2));
820 try expect(!(nan1 > nan2));
821 try expect(!(nan1 >= nan2));
822 try expect(!(nan1 < nan2));
823 try expect(!(nan1 <= nan2));
824824}
825825
826826test "128-bit multiplication" {
827827 var a: i128 = 3;
828828 var b: i128 = 2;
829829 var c = a * b;
830 expect(c == 6);
830 try expect(c == 6);
831831}
832832
833833test "vector comparison" {
834834 const S = struct {
835 fn doTheTest() void {
835 fn doTheTest() !void {
836836 var a: std.meta.Vector(6, i32) = [_]i32{ 1, 3, -1, 5, 7, 9 };
837837 var b: std.meta.Vector(6, i32) = [_]i32{ -1, 3, 0, 6, 10, -10 };
838 expect(mem.eql(bool, &@as([6]bool, a < b), &[_]bool{ false, false, true, true, true, false }));
839 expect(mem.eql(bool, &@as([6]bool, a <= b), &[_]bool{ false, true, true, true, true, false }));
840 expect(mem.eql(bool, &@as([6]bool, a == b), &[_]bool{ false, true, false, false, false, false }));
841 expect(mem.eql(bool, &@as([6]bool, a != b), &[_]bool{ true, false, true, true, true, true }));
842 expect(mem.eql(bool, &@as([6]bool, a > b), &[_]bool{ true, false, false, false, false, true }));
843 expect(mem.eql(bool, &@as([6]bool, a >= b), &[_]bool{ true, true, false, false, false, true }));
838 try expect(mem.eql(bool, &@as([6]bool, a < b), &[_]bool{ false, false, true, true, true, false }));
839 try expect(mem.eql(bool, &@as([6]bool, a <= b), &[_]bool{ false, true, true, true, true, false }));
840 try expect(mem.eql(bool, &@as([6]bool, a == b), &[_]bool{ false, true, false, false, false, false }));
841 try expect(mem.eql(bool, &@as([6]bool, a != b), &[_]bool{ true, false, true, true, true, true }));
842 try expect(mem.eql(bool, &@as([6]bool, a > b), &[_]bool{ true, false, false, false, false, true }));
843 try expect(mem.eql(bool, &@as([6]bool, a >= b), &[_]bool{ true, true, false, false, false, true }));
844844 }
845845 };
846 S.doTheTest();
847 comptime S.doTheTest();
846 try S.doTheTest();
847 comptime try S.doTheTest();
848848}
849849
850850test "compare undefined literal with comptime_int" {
851851 var x = undefined == 1;
852852 // x is now undefined with type bool
853853 x = true;
854 expect(x);
854 try expect(x);
855855}
856856
857857test "signed zeros are represented properly" {
858858 const S = struct {
859 fn doTheTest() void {
859 fn doTheTest() !void {
860860 inline for ([_]type{ f16, f32, f64, f128 }) |T| {
861861 const ST = std.meta.Int(.unsigned, @typeInfo(T).Float.bits);
862862 var as_fp_val = -@as(T, 0.0);
863863 var as_uint_val = @bitCast(ST, as_fp_val);
864864 // Ensure the sign bit is set.
865 expect(as_uint_val >> (@typeInfo(T).Float.bits - 1) == 1);
865 try expect(as_uint_val >> (@typeInfo(T).Float.bits - 1) == 1);
866866 }
867867 }
868868 };
869869
870 S.doTheTest();
871 comptime S.doTheTest();
870 try S.doTheTest();
871 comptime try S.doTheTest();
872872}
test/behavior/misc.zig+107-107
......@@ -25,18 +25,18 @@ test "call disabled extern fn" {
2525}
2626
2727test "short circuit" {
28 testShortCircuit(false, true);
29 comptime testShortCircuit(false, true);
28 try testShortCircuit(false, true);
29 comptime try testShortCircuit(false, true);
3030}
3131
32fn testShortCircuit(f: bool, t: bool) void {
32fn testShortCircuit(f: bool, t: bool) !void {
3333 var hit_1 = f;
3434 var hit_2 = f;
3535 var hit_3 = f;
3636 var hit_4 = f;
3737
3838 if (t or x: {
39 expect(f);
39 try expect(f);
4040 break :x f;
4141 }) {
4242 hit_1 = t;
......@@ -45,31 +45,31 @@ fn testShortCircuit(f: bool, t: bool) void {
4545 hit_2 = t;
4646 break :x f;
4747 }) {
48 expect(f);
48 try expect(f);
4949 }
5050
5151 if (t and x: {
5252 hit_3 = t;
5353 break :x f;
5454 }) {
55 expect(f);
55 try expect(f);
5656 }
5757 if (f and x: {
58 expect(f);
58 try expect(f);
5959 break :x f;
6060 }) {
61 expect(f);
61 try expect(f);
6262 } else {
6363 hit_4 = t;
6464 }
65 expect(hit_1);
66 expect(hit_2);
67 expect(hit_3);
68 expect(hit_4);
65 try expect(hit_1);
66 try expect(hit_2);
67 try expect(hit_3);
68 try expect(hit_4);
6969}
7070
7171test "truncate" {
72 expect(testTruncate(0x10fd) == 0xfd);
72 try expect(testTruncate(0x10fd) == 0xfd);
7373}
7474fn testTruncate(x: u32) u8 {
7575 return @truncate(u8, x);
......@@ -80,16 +80,16 @@ fn first4KeysOfHomeRow() []const u8 {
8080}
8181
8282test "return string from function" {
83 expect(mem.eql(u8, first4KeysOfHomeRow(), "aoeu"));
83 try expect(mem.eql(u8, first4KeysOfHomeRow(), "aoeu"));
8484}
8585
8686const g1: i32 = 1233 + 1;
8787var g2: i32 = 0;
8888
8989test "global variables" {
90 expect(g2 == 0);
90 try expect(g2 == 0);
9191 g2 = g1;
92 expect(g2 == 1234);
92 try expect(g2 == 1234);
9393}
9494
9595test "memcpy and memset intrinsics" {
......@@ -106,7 +106,7 @@ test "builtin static eval" {
106106 const x: i32 = comptime x: {
107107 break :x 1 + 2 + 3;
108108 };
109 expect(x == comptime 6);
109 try expect(x == comptime 6);
110110}
111111
112112test "slicing" {
......@@ -127,7 +127,7 @@ test "slicing" {
127127
128128test "constant equal function pointers" {
129129 const alias = emptyFn;
130 expect(comptime x: {
130 try expect(comptime x: {
131131 break :x emptyFn == alias;
132132 });
133133}
......@@ -135,25 +135,25 @@ test "constant equal function pointers" {
135135fn emptyFn() void {}
136136
137137test "hex escape" {
138 expect(mem.eql(u8, "\x68\x65\x6c\x6c\x6f", "hello"));
138 try expect(mem.eql(u8, "\x68\x65\x6c\x6c\x6f", "hello"));
139139}
140140
141141test "string concatenation" {
142 expect(mem.eql(u8, "OK" ++ " IT " ++ "WORKED", "OK IT WORKED"));
142 try expect(mem.eql(u8, "OK" ++ " IT " ++ "WORKED", "OK IT WORKED"));
143143}
144144
145145test "array mult operator" {
146 expect(mem.eql(u8, "ab" ** 5, "ababababab"));
146 try expect(mem.eql(u8, "ab" ** 5, "ababababab"));
147147}
148148
149149test "string escapes" {
150 expect(mem.eql(u8, "\"", "\x22"));
151 expect(mem.eql(u8, "\'", "\x27"));
152 expect(mem.eql(u8, "\n", "\x0a"));
153 expect(mem.eql(u8, "\r", "\x0d"));
154 expect(mem.eql(u8, "\t", "\x09"));
155 expect(mem.eql(u8, "\\", "\x5c"));
156 expect(mem.eql(u8, "\u{1234}\u{069}\u{1}", "\xe1\x88\xb4\x69\x01"));
150 try expect(mem.eql(u8, "\"", "\x22"));
151 try expect(mem.eql(u8, "\'", "\x27"));
152 try expect(mem.eql(u8, "\n", "\x0a"));
153 try expect(mem.eql(u8, "\r", "\x0d"));
154 try expect(mem.eql(u8, "\t", "\x09"));
155 try expect(mem.eql(u8, "\\", "\x5c"));
156 try expect(mem.eql(u8, "\u{1234}\u{069}\u{1}", "\xe1\x88\xb4\x69\x01"));
157157}
158158
159159test "multiline string" {
......@@ -163,7 +163,7 @@ test "multiline string" {
163163 \\three
164164 ;
165165 const s2 = "one\ntwo)\nthree";
166 expect(mem.eql(u8, s1, s2));
166 try expect(mem.eql(u8, s1, s2));
167167}
168168
169169test "multiline string comments at start" {
......@@ -173,7 +173,7 @@ test "multiline string comments at start" {
173173 \\three
174174 ;
175175 const s2 = "two)\nthree";
176 expect(mem.eql(u8, s1, s2));
176 try expect(mem.eql(u8, s1, s2));
177177}
178178
179179test "multiline string comments at end" {
......@@ -183,7 +183,7 @@ test "multiline string comments at end" {
183183 //\\three
184184 ;
185185 const s2 = "one\ntwo)";
186 expect(mem.eql(u8, s1, s2));
186 try expect(mem.eql(u8, s1, s2));
187187}
188188
189189test "multiline string comments in middle" {
......@@ -193,7 +193,7 @@ test "multiline string comments in middle" {
193193 \\three
194194 ;
195195 const s2 = "one\nthree";
196 expect(mem.eql(u8, s1, s2));
196 try expect(mem.eql(u8, s1, s2));
197197}
198198
199199test "multiline string comments at multiple places" {
......@@ -205,7 +205,7 @@ test "multiline string comments at multiple places" {
205205 \\five
206206 ;
207207 const s2 = "one\nthree\nfive";
208 expect(mem.eql(u8, s1, s2));
208 try expect(mem.eql(u8, s1, s2));
209209}
210210
211211test "multiline C string" {
......@@ -215,11 +215,11 @@ test "multiline C string" {
215215 \\three
216216 ;
217217 const s2 = "one\ntwo)\nthree";
218 expect(std.cstr.cmp(s1, s2) == 0);
218 try expect(std.cstr.cmp(s1, s2) == 0);
219219}
220220
221221test "type equality" {
222 expect(*const u8 != *u8);
222 try expect(*const u8 != *u8);
223223}
224224
225225const global_a: i32 = 1234;
......@@ -227,7 +227,7 @@ const global_b: *const i32 = &global_a;
227227const global_c: *const f32 = @ptrCast(*const f32, global_b);
228228test "compile time global reinterpret" {
229229 const d = @ptrCast(*const i32, global_c);
230 expect(d.* == 1234);
230 try expect(d.* == 1234);
231231}
232232
233233test "explicit cast maybe pointers" {
......@@ -253,8 +253,8 @@ test "cast undefined" {
253253fn testCastUndefined(x: []const u8) void {}
254254
255255test "cast small unsigned to larger signed" {
256 expect(castSmallUnsignedToLargerSigned1(200) == @as(i16, 200));
257 expect(castSmallUnsignedToLargerSigned2(9999) == @as(i64, 9999));
256 try expect(castSmallUnsignedToLargerSigned1(200) == @as(i16, 200));
257 try expect(castSmallUnsignedToLargerSigned2(9999) == @as(i64, 9999));
258258}
259259fn castSmallUnsignedToLargerSigned1(x: u8) i16 {
260260 return x;
......@@ -264,7 +264,7 @@ fn castSmallUnsignedToLargerSigned2(x: u16) i64 {
264264}
265265
266266test "implicit cast after unreachable" {
267 expect(outer() == 1234);
267 try expect(outer() == 1234);
268268}
269269fn inner() i32 {
270270 return 1234;
......@@ -279,13 +279,13 @@ test "pointer dereferencing" {
279279
280280 y.* += 1;
281281
282 expect(x == 4);
283 expect(y.* == 4);
282 try expect(x == 4);
283 try expect(y.* == 4);
284284}
285285
286286test "call result of if else expression" {
287 expect(mem.eql(u8, f2(true), "a"));
288 expect(mem.eql(u8, f2(false), "b"));
287 try expect(mem.eql(u8, f2(true), "a"));
288 try expect(mem.eql(u8, f2(false), "b"));
289289}
290290fn f2(x: bool) []const u8 {
291291 return (if (x) fA else fB)();
......@@ -305,8 +305,8 @@ test "const expression eval handling of variables" {
305305}
306306
307307test "constant enum initialization with differing sizes" {
308 test3_1(test3_foo);
309 test3_2(test3_bar);
308 try test3_1(test3_foo);
309 try test3_2(test3_bar);
310310}
311311const Test3Foo = union(enum) {
312312 One: void,
......@@ -324,41 +324,41 @@ const test3_foo = Test3Foo{
324324 },
325325};
326326const test3_bar = Test3Foo{ .Two = 13 };
327fn test3_1(f: Test3Foo) void {
327fn test3_1(f: Test3Foo) !void {
328328 switch (f) {
329329 Test3Foo.Three => |pt| {
330 expect(pt.x == 3);
331 expect(pt.y == 4);
330 try expect(pt.x == 3);
331 try expect(pt.y == 4);
332332 },
333333 else => unreachable,
334334 }
335335}
336fn test3_2(f: Test3Foo) void {
336fn test3_2(f: Test3Foo) !void {
337337 switch (f) {
338338 Test3Foo.Two => |x| {
339 expect(x == 13);
339 try expect(x == 13);
340340 },
341341 else => unreachable,
342342 }
343343}
344344
345345test "character literals" {
346 expect('\'' == single_quote);
346 try expect('\'' == single_quote);
347347}
348348const single_quote = '\'';
349349
350350test "take address of parameter" {
351 testTakeAddressOfParameter(12.34);
351 try testTakeAddressOfParameter(12.34);
352352}
353fn testTakeAddressOfParameter(f: f32) void {
353fn testTakeAddressOfParameter(f: f32) !void {
354354 const f_ptr = &f;
355 expect(f_ptr.* == 12.34);
355 try expect(f_ptr.* == 12.34);
356356}
357357
358358test "pointer comparison" {
359359 const a = @as([]const u8, "a");
360360 const b = &a;
361 expect(ptrEql(b, b));
361 try expect(ptrEql(b, b));
362362}
363363fn ptrEql(a: *const []const u8, b: *const []const u8) bool {
364364 return a == b;
......@@ -368,19 +368,19 @@ test "string concatenation" {
368368 const a = "OK" ++ " IT " ++ "WORKED";
369369 const b = "OK IT WORKED";
370370
371 comptime expect(@TypeOf(a) == *const [12:0]u8);
372 comptime expect(@TypeOf(b) == *const [12:0]u8);
371 comptime try expect(@TypeOf(a) == *const [12:0]u8);
372 comptime try expect(@TypeOf(b) == *const [12:0]u8);
373373
374374 const len = mem.len(b);
375375 const len_with_null = len + 1;
376376 {
377377 var i: u32 = 0;
378378 while (i < len_with_null) : (i += 1) {
379 expect(a[i] == b[i]);
379 try expect(a[i] == b[i]);
380380 }
381381 }
382 expect(a[len] == 0);
383 expect(b[len] == 0);
382 try expect(a[len] == 0);
383 try expect(b[len] == 0);
384384}
385385
386386test "pointer to void return type" {
......@@ -397,7 +397,7 @@ fn testPointerToVoidReturnType2() *const void {
397397
398398test "non const ptr to aliased type" {
399399 const int = i32;
400 expect(?*int == ?*i32);
400 try expect(?*int == ?*i32);
401401}
402402
403403test "array 2D const double ptr" {
......@@ -405,13 +405,13 @@ test "array 2D const double ptr" {
405405 [_]f32{1.0},
406406 [_]f32{2.0},
407407 };
408 testArray2DConstDoublePtr(&rect_2d_vertexes[0][0]);
408 try testArray2DConstDoublePtr(&rect_2d_vertexes[0][0]);
409409}
410410
411fn testArray2DConstDoublePtr(ptr: *const f32) void {
411fn testArray2DConstDoublePtr(ptr: *const f32) !void {
412412 const ptr2 = @ptrCast([*]const f32, ptr);
413 expect(ptr2[0] == 1.0);
414 expect(ptr2[1] == 2.0);
413 try expect(ptr2[0] == 1.0);
414 try expect(ptr2[1] == 2.0);
415415}
416416
417417const AStruct = struct {
......@@ -439,13 +439,13 @@ test "@typeName" {
439439 Unused,
440440 };
441441 comptime {
442 expect(mem.eql(u8, @typeName(i64), "i64"));
443 expect(mem.eql(u8, @typeName(*usize), "*usize"));
442 try expect(mem.eql(u8, @typeName(i64), "i64"));
443 try expect(mem.eql(u8, @typeName(*usize), "*usize"));
444444 // https://github.com/ziglang/zig/issues/675
445 expect(mem.eql(u8, "behavior.misc.TypeFromFn(u8)", @typeName(TypeFromFn(u8))));
446 expect(mem.eql(u8, @typeName(Struct), "Struct"));
447 expect(mem.eql(u8, @typeName(Union), "Union"));
448 expect(mem.eql(u8, @typeName(Enum), "Enum"));
445 try expect(mem.eql(u8, "behavior.misc.TypeFromFn(u8)", @typeName(TypeFromFn(u8))));
446 try expect(mem.eql(u8, @typeName(Struct), "Struct"));
447 try expect(mem.eql(u8, @typeName(Union), "Union"));
448 try expect(mem.eql(u8, @typeName(Enum), "Enum"));
449449 }
450450}
451451
......@@ -455,14 +455,14 @@ fn TypeFromFn(comptime T: type) type {
455455
456456test "double implicit cast in same expression" {
457457 var x = @as(i32, @as(u16, nine()));
458 expect(x == 9);
458 try expect(x == 9);
459459}
460460fn nine() u8 {
461461 return 9;
462462}
463463
464464test "global variable initialized to global variable array element" {
465 expect(global_ptr == &gdt[0]);
465 try expect(global_ptr == &gdt[0]);
466466}
467467const GDTEntry = struct {
468468 field: i32,
......@@ -483,9 +483,9 @@ export fn writeToVRam() void {
483483const OpaqueA = opaque {};
484484const OpaqueB = opaque {};
485485test "opaque types" {
486 expect(*OpaqueA != *OpaqueB);
487 expect(mem.eql(u8, @typeName(OpaqueA), "OpaqueA"));
488 expect(mem.eql(u8, @typeName(OpaqueB), "OpaqueB"));
486 try expect(*OpaqueA != *OpaqueB);
487 try expect(mem.eql(u8, @typeName(OpaqueA), "OpaqueA"));
488 try expect(mem.eql(u8, @typeName(OpaqueB), "OpaqueB"));
489489}
490490
491491test "variable is allowed to be a pointer to an opaque type" {
......@@ -525,7 +525,7 @@ fn fnThatClosesOverLocalConst() type {
525525
526526test "function closes over local const" {
527527 const x = fnThatClosesOverLocalConst().g();
528 expect(x == 1);
528 try expect(x == 1);
529529}
530530
531531test "cold function" {
......@@ -562,21 +562,21 @@ export fn testPackedStuff(a: *const PackedStruct, b: *const PackedUnion, c: Pack
562562test "slicing zero length array" {
563563 const s1 = ""[0..];
564564 const s2 = ([_]u32{})[0..];
565 expect(s1.len == 0);
566 expect(s2.len == 0);
567 expect(mem.eql(u8, s1, ""));
568 expect(mem.eql(u32, s2, &[_]u32{}));
565 try expect(s1.len == 0);
566 try expect(s2.len == 0);
567 try expect(mem.eql(u8, s1, ""));
568 try expect(mem.eql(u32, s2, &[_]u32{}));
569569}
570570
571571const addr1 = @ptrCast(*const u8, emptyFn);
572572test "comptime cast fn to ptr" {
573573 const addr2 = @ptrCast(*const u8, emptyFn);
574 comptime expect(addr1 == addr2);
574 comptime try expect(addr1 == addr2);
575575}
576576
577577test "equality compare fn ptrs" {
578578 var a = emptyFn;
579 expect(a == a);
579 try expect(a == a);
580580}
581581
582582test "self reference through fn ptr field" {
......@@ -591,34 +591,34 @@ test "self reference through fn ptr field" {
591591 };
592592 var a: S.A = undefined;
593593 a.f = S.foo;
594 expect(a.f(a) == 12);
594 try expect(a.f(a) == 12);
595595}
596596
597597test "volatile load and store" {
598598 var number: i32 = 1234;
599599 const ptr = @as(*volatile i32, &number);
600600 ptr.* += 1;
601 expect(ptr.* == 1235);
601 try expect(ptr.* == 1235);
602602}
603603
604604test "slice string literal has correct type" {
605605 comptime {
606 expect(@TypeOf("aoeu"[0..]) == *const [4:0]u8);
606 try expect(@TypeOf("aoeu"[0..]) == *const [4:0]u8);
607607 const array = [_]i32{ 1, 2, 3, 4 };
608 expect(@TypeOf(array[0..]) == *const [4]i32);
608 try expect(@TypeOf(array[0..]) == *const [4]i32);
609609 }
610610 var runtime_zero: usize = 0;
611 comptime expect(@TypeOf("aoeu"[runtime_zero..]) == [:0]const u8);
611 comptime try expect(@TypeOf("aoeu"[runtime_zero..]) == [:0]const u8);
612612 const array = [_]i32{ 1, 2, 3, 4 };
613 comptime expect(@TypeOf(array[runtime_zero..]) == []const i32);
613 comptime try expect(@TypeOf(array[runtime_zero..]) == []const i32);
614614}
615615
616616test "struct inside function" {
617 testStructInFn();
618 comptime testStructInFn();
617 try testStructInFn();
618 comptime try testStructInFn();
619619}
620620
621fn testStructInFn() void {
621fn testStructInFn() !void {
622622 const BlockKind = u32;
623623
624624 const Block = struct {
......@@ -629,11 +629,11 @@ fn testStructInFn() void {
629629
630630 block.kind += 1;
631631
632 expect(block.kind == 1235);
632 try expect(block.kind == 1235);
633633}
634634
635635test "fn call returning scalar optional in equality expression" {
636 expect(getNull() == null);
636 try expect(getNull() == null);
637637}
638638
639639fn getNull() ?*i32 {
......@@ -645,16 +645,16 @@ test "thread local variable" {
645645 threadlocal var t: i32 = 1234;
646646 };
647647 S.t += 1;
648 expect(S.t == 1235);
648 try expect(S.t == 1235);
649649}
650650
651651test "unicode escape in character literal" {
652652 var a: u24 = '\u{01f4a9}';
653 expect(a == 128169);
653 try expect(a == 128169);
654654}
655655
656656test "unicode character in character literal" {
657 expect('💩' == 128169);
657 try expect('💩' == 128169);
658658}
659659
660660test "result location zero sized array inside struct field implicit cast to slice" {
......@@ -662,7 +662,7 @@ test "result location zero sized array inside struct field implicit cast to slic
662662 entries: []u32,
663663 };
664664 var foo = E{ .entries = &[_]u32{} };
665 expect(foo.entries.len == 0);
665 try expect(foo.entries.len == 0);
666666}
667667
668668var global_foo: *i32 = undefined;
......@@ -677,7 +677,7 @@ test "global variable assignment with optional unwrapping with var initialized t
677677 global_foo = S.foo() orelse {
678678 @panic("bad");
679679 };
680 expect(global_foo.* == 1234);
680 try expect(global_foo.* == 1234);
681681}
682682
683683test "peer result location with typed parent, runtime condition, comptime prongs" {
......@@ -696,8 +696,8 @@ test "peer result location with typed parent, runtime condition, comptime prongs
696696 bleh: i32,
697697 };
698698 };
699 expect(S.doTheTest(0) == 1234);
700 expect(S.doTheTest(1) == 1234);
699 try expect(S.doTheTest(0) == 1234);
700 try expect(S.doTheTest(1) == 1234);
701701}
702702
703703test "nested optional field in struct" {
......@@ -710,7 +710,7 @@ test "nested optional field in struct" {
710710 var s = S1{
711711 .x = S2{ .y = 127 },
712712 };
713 expect(s.x.?.y == 127);
713 try expect(s.x.?.y == 127);
714714}
715715
716716fn maybe(x: bool) anyerror!?u32 {
......@@ -722,7 +722,7 @@ fn maybe(x: bool) anyerror!?u32 {
722722
723723test "result location is optional inside error union" {
724724 const x = maybe(true) catch unreachable;
725 expect(x.? == 42);
725 try expect(x.? == 42);
726726}
727727
728728threadlocal var buffer: [11]u8 = undefined;
......@@ -730,7 +730,7 @@ threadlocal var buffer: [11]u8 = undefined;
730730test "pointer to thread local array" {
731731 const s = "Hello world";
732732 std.mem.copy(u8, buffer[0..], s);
733 std.testing.expectEqualSlices(u8, buffer[0..], s);
733 try std.testing.expectEqualSlices(u8, buffer[0..], s);
734734}
735735
736736test "auto created variables have correct alignment" {
......@@ -742,15 +742,15 @@ test "auto created variables have correct alignment" {
742742 return 0;
743743 }
744744 };
745 expect(S.foo("\x7a\x7a\x7a\x7a") == 0x7a7a7a7a);
746 comptime expect(S.foo("\x7a\x7a\x7a\x7a") == 0x7a7a7a7a);
745 try expect(S.foo("\x7a\x7a\x7a\x7a") == 0x7a7a7a7a);
746 comptime try expect(S.foo("\x7a\x7a\x7a\x7a") == 0x7a7a7a7a);
747747}
748748
749749extern var opaque_extern_var: opaque {};
750750var var_to_export: u32 = 42;
751751test "extern variable with non-pointer opaque type" {
752752 @export(var_to_export, .{ .name = "opaque_extern_var" });
753 expect(@ptrCast(*align(1) u32, &opaque_extern_var).* == 42);
753 try expect(@ptrCast(*align(1) u32, &opaque_extern_var).* == 42);
754754}
755755
756756test "lazy typeInfo value as generic parameter" {
test/behavior/muladd.zig+7-7
......@@ -1,34 +1,34 @@
11const expect = @import("std").testing.expect;
22
33test "@mulAdd" {
4 comptime testMulAdd();
5 testMulAdd();
4 comptime try testMulAdd();
5 try testMulAdd();
66}
77
8fn testMulAdd() void {
8fn testMulAdd() !void {
99 {
1010 var a: f16 = 5.5;
1111 var b: f16 = 2.5;
1212 var c: f16 = 6.25;
13 expect(@mulAdd(f16, a, b, c) == 20);
13 try expect(@mulAdd(f16, a, b, c) == 20);
1414 }
1515 {
1616 var a: f32 = 5.5;
1717 var b: f32 = 2.5;
1818 var c: f32 = 6.25;
19 expect(@mulAdd(f32, a, b, c) == 20);
19 try expect(@mulAdd(f32, a, b, c) == 20);
2020 }
2121 {
2222 var a: f64 = 5.5;
2323 var b: f64 = 2.5;
2424 var c: f64 = 6.25;
25 expect(@mulAdd(f64, a, b, c) == 20);
25 try expect(@mulAdd(f64, a, b, c) == 20);
2626 }
2727 // Awaits implementation in libm.zig
2828 //{
2929 // var a: f16 = 5.5;
3030 // var b: f128 = 2.5;
3131 // var c: f128 = 6.25;
32 // expect(@mulAdd(f128, a, b, c) == 20);
32 //try expect(@mulAdd(f128, a, b, c) == 20);
3333 //}
3434}
test/behavior/namespace_depends_on_compile_var.zig+2-2
......@@ -3,9 +3,9 @@ const expect = std.testing.expect;
33
44test "namespace depends on compile var" {
55 if (some_namespace.a_bool) {
6 expect(some_namespace.a_bool);
6 try expect(some_namespace.a_bool);
77 } else {
8 expect(!some_namespace.a_bool);
8 try expect(!some_namespace.a_bool);
99 }
1010}
1111const some_namespace = switch (std.builtin.os.tag) {
test/behavior/null.zig+24-24
......@@ -17,13 +17,13 @@ test "optional type" {
1717
1818 const z = next_x orelse 1234;
1919
20 expect(z == 1234);
20 try expect(z == 1234);
2121
2222 const final_x: ?i32 = 13;
2323
2424 const num = final_x orelse unreachable;
2525
26 expect(num == 13);
26 try expect(num == 13);
2727}
2828
2929test "test maybe object and get a pointer to the inner value" {
......@@ -33,7 +33,7 @@ test "test maybe object and get a pointer to the inner value" {
3333 b.* = false;
3434 }
3535
36 expect(maybe_bool.? == false);
36 try expect(maybe_bool.? == false);
3737}
3838
3939test "rhs maybe unwrap return" {
......@@ -42,14 +42,14 @@ test "rhs maybe unwrap return" {
4242}
4343
4444test "maybe return" {
45 maybeReturnImpl();
46 comptime maybeReturnImpl();
45 try maybeReturnImpl();
46 comptime try maybeReturnImpl();
4747}
4848
49fn maybeReturnImpl() void {
50 expect(foo(1235).?);
49fn maybeReturnImpl() !void {
50 try expect(foo(1235).?);
5151 if (foo(null) != null) unreachable;
52 expect(!foo(1234).?);
52 try expect(!foo(1234).?);
5353}
5454
5555fn foo(x: ?i32) ?bool {
......@@ -58,7 +58,7 @@ fn foo(x: ?i32) ?bool {
5858}
5959
6060test "if var maybe pointer" {
61 expect(shouldBeAPlus1(Particle{
61 try expect(shouldBeAPlus1(Particle{
6262 .a = 14,
6363 .b = 1,
6464 .c = 1,
......@@ -84,10 +84,10 @@ const Particle = struct {
8484
8585test "null literal outside function" {
8686 const is_null = here_is_a_null_literal.context == null;
87 expect(is_null);
87 try expect(is_null);
8888
8989 const is_non_null = here_is_a_null_literal.context != null;
90 expect(!is_non_null);
90 try expect(!is_non_null);
9191}
9292const SillyStruct = struct {
9393 context: ?i32,
......@@ -95,21 +95,21 @@ const SillyStruct = struct {
9595const here_is_a_null_literal = SillyStruct{ .context = null };
9696
9797test "test null runtime" {
98 testTestNullRuntime(null);
98 try testTestNullRuntime(null);
9999}
100fn testTestNullRuntime(x: ?i32) void {
101 expect(x == null);
102 expect(!(x != null));
100fn testTestNullRuntime(x: ?i32) !void {
101 try expect(x == null);
102 try expect(!(x != null));
103103}
104104
105105test "optional void" {
106 optionalVoidImpl();
107 comptime optionalVoidImpl();
106 try optionalVoidImpl();
107 comptime try optionalVoidImpl();
108108}
109109
110fn optionalVoidImpl() void {
111 expect(bar(null) == null);
112 expect(bar({}) != null);
110fn optionalVoidImpl() !void {
111 try expect(bar(null) == null);
112 try expect(bar({}) != null);
113113}
114114
115115fn bar(x: ?void) ?void {
......@@ -133,7 +133,7 @@ test "unwrap optional which is field of global var" {
133133 }
134134 struct_with_optional.field = 1234;
135135 if (struct_with_optional.field) |payload| {
136 expect(payload == 1234);
136 try expect(payload == 1234);
137137 } else {
138138 unreachable;
139139 }
......@@ -141,13 +141,13 @@ test "unwrap optional which is field of global var" {
141141
142142test "null with default unwrap" {
143143 const x: i32 = null orelse 1;
144 expect(x == 1);
144 try expect(x == 1);
145145}
146146
147147test "optional types" {
148148 comptime {
149149 const opt_type_struct = StructWithOptionalType{ .t = u8 };
150 expect(opt_type_struct.t != null and opt_type_struct.t.? == u8);
150 try expect(opt_type_struct.t != null and opt_type_struct.t.? == u8);
151151 }
152152}
153153
......@@ -158,5 +158,5 @@ const StructWithOptionalType = struct {
158158test "optional pointer to 0 bit type null value at runtime" {
159159 const EmptyStruct = struct {};
160160 var x: ?*EmptyStruct = null;
161 expect(x == null);
161 try expect(x == null);
162162}
test/behavior/optional.zig+51-51
......@@ -8,28 +8,28 @@ pub const EmptyStruct = struct {};
88test "optional pointer to size zero struct" {
99 var e = EmptyStruct{};
1010 var o: ?*EmptyStruct = &e;
11 expect(o != null);
11 try expect(o != null);
1212}
1313
1414test "equality compare nullable pointers" {
15 testNullPtrsEql();
16 comptime testNullPtrsEql();
15 try testNullPtrsEql();
16 comptime try testNullPtrsEql();
1717}
1818
19fn testNullPtrsEql() void {
19fn testNullPtrsEql() !void {
2020 var number: i32 = 1234;
2121
2222 var x: ?*i32 = null;
2323 var y: ?*i32 = null;
24 expect(x == y);
24 try expect(x == y);
2525 y = &number;
26 expect(x != y);
27 expect(x != &number);
28 expect(&number != x);
26 try expect(x != y);
27 try expect(x != &number);
28 try expect(&number != x);
2929 x = &number;
30 expect(x == y);
31 expect(x == &number);
32 expect(&number == x);
30 try expect(x == y);
31 try expect(x == &number);
32 try expect(&number == x);
3333}
3434
3535test "address of unwrap optional" {
......@@ -46,23 +46,23 @@ test "address of unwrap optional" {
4646 };
4747 S.global = S.Foo{ .a = 1234 };
4848 const foo = S.getFoo() catch unreachable;
49 expect(foo.a == 1234);
49 try expect(foo.a == 1234);
5050}
5151
5252test "equality compare optional with non-optional" {
53 test_cmp_optional_non_optional();
54 comptime test_cmp_optional_non_optional();
53 try test_cmp_optional_non_optional();
54 comptime try test_cmp_optional_non_optional();
5555}
5656
57fn test_cmp_optional_non_optional() void {
57fn test_cmp_optional_non_optional() !void {
5858 var ten: i32 = 10;
5959 var opt_ten: ?i32 = 10;
6060 var five: i32 = 5;
6161 var int_n: ?i32 = null;
6262
63 expect(int_n != ten);
64 expect(opt_ten == ten);
65 expect(opt_ten != five);
63 try expect(int_n != ten);
64 try expect(opt_ten == ten);
65 try expect(opt_ten != five);
6666
6767 // test evaluation is always lexical
6868 // ensure that the optional isn't always computed before the non-optional
......@@ -71,14 +71,14 @@ fn test_cmp_optional_non_optional() void {
7171 mutable_state += 1;
7272 break :blk1 @as(?f64, 10.0);
7373 } != blk2: {
74 expect(mutable_state == 1);
74 try expect(mutable_state == 1);
7575 break :blk2 @as(f64, 5.0);
7676 };
7777 _ = blk1: {
7878 mutable_state += 1;
7979 break :blk1 @as(f64, 10.0);
8080 } != blk2: {
81 expect(mutable_state == 2);
81 try expect(mutable_state == 2);
8282 break :blk2 @as(?f64, 5.0);
8383 };
8484}
......@@ -94,15 +94,15 @@ test "passing an optional integer as a parameter" {
9494 return x.? == 1234;
9595 }
9696 };
97 expect(S.entry());
98 comptime expect(S.entry());
97 try expect(S.entry());
98 comptime try expect(S.entry());
9999}
100100
101101test "unwrap function call with optional pointer return value" {
102102 const S = struct {
103 fn entry() void {
104 expect(foo().?.* == 1234);
105 expect(bar() == null);
103 fn entry() !void {
104 try expect(foo().?.* == 1234);
105 try expect(bar() == null);
106106 }
107107 const global: i32 = 1234;
108108 fn foo() ?*const i32 {
......@@ -112,14 +112,14 @@ test "unwrap function call with optional pointer return value" {
112112 return null;
113113 }
114114 };
115 S.entry();
116 comptime S.entry();
115 try S.entry();
116 comptime try S.entry();
117117}
118118
119119test "nested orelse" {
120120 const S = struct {
121 fn entry() void {
122 expect(func() == null);
121 fn entry() !void {
122 try expect(func() == null);
123123 }
124124 fn maybe() ?Foo {
125125 return null;
......@@ -134,8 +134,8 @@ test "nested orelse" {
134134 field: i32,
135135 };
136136 };
137 S.entry();
138 comptime S.entry();
137 try S.entry();
138 comptime try S.entry();
139139}
140140
141141test "self-referential struct through a slice of optional" {
......@@ -154,7 +154,7 @@ test "self-referential struct through a slice of optional" {
154154 };
155155
156156 var n = S.Node.new();
157 expect(n.data == null);
157 try expect(n.data == null);
158158}
159159
160160test "assigning to an unwrapped optional field in an inline loop" {
......@@ -173,14 +173,14 @@ test "coerce an anon struct literal to optional struct" {
173173 const Struct = struct {
174174 field: u32,
175175 };
176 export fn doTheTest() void {
176 fn doTheTest() !void {
177177 var maybe_dims: ?Struct = null;
178178 maybe_dims = .{ .field = 1 };
179 expect(maybe_dims.?.field == 1);
179 try expect(maybe_dims.?.field == 1);
180180 }
181181 };
182 S.doTheTest();
183 comptime S.doTheTest();
182 try S.doTheTest();
183 comptime try S.doTheTest();
184184}
185185
186186test "optional with void type" {
......@@ -188,15 +188,15 @@ test "optional with void type" {
188188 x: ?void,
189189 };
190190 var x = Foo{ .x = null };
191 expect(x.x == null);
191 try expect(x.x == null);
192192}
193193
194194test "0-bit child type coerced to optional return ptr result location" {
195195 const S = struct {
196 fn doTheTest() void {
196 fn doTheTest() !void {
197197 var y = Foo{};
198198 var z = y.thing();
199 expect(z != null);
199 try expect(z != null);
200200 }
201201
202202 const Foo = struct {
......@@ -209,17 +209,17 @@ test "0-bit child type coerced to optional return ptr result location" {
209209 }
210210 };
211211 };
212 S.doTheTest();
213 comptime S.doTheTest();
212 try S.doTheTest();
213 comptime try S.doTheTest();
214214}
215215
216216test "0-bit child type coerced to optional" {
217217 const S = struct {
218 fn doTheTest() void {
218 fn doTheTest() !void {
219219 var it: Foo = .{
220220 .list = undefined,
221221 };
222 expect(it.foo() != null);
222 try expect(it.foo() != null);
223223 }
224224
225225 const Empty = struct {};
......@@ -232,8 +232,8 @@ test "0-bit child type coerced to optional" {
232232 }
233233 };
234234 };
235 S.doTheTest();
236 comptime S.doTheTest();
235 try S.doTheTest();
236 comptime try S.doTheTest();
237237}
238238
239239test "array of optional unaligned types" {
......@@ -255,15 +255,15 @@ test "array of optional unaligned types" {
255255
256256 // The index must be a runtime value
257257 var i: usize = 0;
258 expectEqual(Enum.one, values[i].?.Num);
258 try expectEqual(Enum.one, values[i].?.Num);
259259 i += 1;
260 expectEqual(Enum.two, values[i].?.Num);
260 try expectEqual(Enum.two, values[i].?.Num);
261261 i += 1;
262 expectEqual(Enum.three, values[i].?.Num);
262 try expectEqual(Enum.three, values[i].?.Num);
263263 i += 1;
264 expectEqual(Enum.one, values[i].?.Num);
264 try expectEqual(Enum.one, values[i].?.Num);
265265 i += 1;
266 expectEqual(Enum.two, values[i].?.Num);
266 try expectEqual(Enum.two, values[i].?.Num);
267267 i += 1;
268 expectEqual(Enum.three, values[i].?.Num);
268 try expectEqual(Enum.three, values[i].?.Num);
269269}
test/behavior/pointers.zig+108-108
......@@ -4,15 +4,15 @@ const expect = testing.expect;
44const expectError = testing.expectError;
55
66test "dereference pointer" {
7 comptime testDerefPtr();
8 testDerefPtr();
7 comptime try testDerefPtr();
8 try testDerefPtr();
99}
1010
11fn testDerefPtr() void {
11fn testDerefPtr() !void {
1212 var x: i32 = 1234;
1313 var y = &x;
1414 y.* += 1;
15 expect(x == 1235);
15 try expect(x == 1235);
1616}
1717
1818const Foo1 = struct {
......@@ -20,41 +20,41 @@ const Foo1 = struct {
2020};
2121
2222test "dereference pointer again" {
23 testDerefPtrOneVal();
24 comptime testDerefPtrOneVal();
23 try testDerefPtrOneVal();
24 comptime try testDerefPtrOneVal();
2525}
2626
27fn testDerefPtrOneVal() void {
27fn testDerefPtrOneVal() !void {
2828 // Foo1 satisfies the OnePossibleValueYes criteria
2929 const x = &Foo1{ .x = {} };
3030 const y = x.*;
31 expect(@TypeOf(y.x) == void);
31 try expect(@TypeOf(y.x) == void);
3232}
3333
3434test "pointer arithmetic" {
3535 var ptr: [*]const u8 = "abcd";
3636
37 expect(ptr[0] == 'a');
37 try expect(ptr[0] == 'a');
3838 ptr += 1;
39 expect(ptr[0] == 'b');
39 try expect(ptr[0] == 'b');
4040 ptr += 1;
41 expect(ptr[0] == 'c');
41 try expect(ptr[0] == 'c');
4242 ptr += 1;
43 expect(ptr[0] == 'd');
43 try expect(ptr[0] == 'd');
4444 ptr += 1;
45 expect(ptr[0] == 0);
45 try expect(ptr[0] == 0);
4646 ptr -= 1;
47 expect(ptr[0] == 'd');
47 try expect(ptr[0] == 'd');
4848 ptr -= 1;
49 expect(ptr[0] == 'c');
49 try expect(ptr[0] == 'c');
5050 ptr -= 1;
51 expect(ptr[0] == 'b');
51 try expect(ptr[0] == 'b');
5252 ptr -= 1;
53 expect(ptr[0] == 'a');
53 try expect(ptr[0] == 'a');
5454}
5555
5656test "double pointer parsing" {
57 comptime expect(PtrOf(PtrOf(i32)) == **i32);
57 comptime try expect(PtrOf(PtrOf(i32)) == **i32);
5858}
5959
6060fn PtrOf(comptime T: type) type {
......@@ -72,33 +72,33 @@ test "implicit cast single item pointer to C pointer and back" {
7272 var x: [*c]u8 = &y;
7373 var z: *u8 = x;
7474 z.* += 1;
75 expect(y == 12);
75 try expect(y == 12);
7676}
7777
7878test "C pointer comparison and arithmetic" {
7979 const S = struct {
80 fn doTheTest() void {
80 fn doTheTest() !void {
8181 var one: usize = 1;
8282 var ptr1: [*c]u32 = 0;
8383 var ptr2 = ptr1 + 10;
84 expect(ptr1 == 0);
85 expect(ptr1 >= 0);
86 expect(ptr1 <= 0);
84 try expect(ptr1 == 0);
85 try expect(ptr1 >= 0);
86 try expect(ptr1 <= 0);
8787 // expect(ptr1 < 1);
8888 // expect(ptr1 < one);
8989 // expect(1 > ptr1);
9090 // expect(one > ptr1);
91 expect(ptr1 < ptr2);
92 expect(ptr2 > ptr1);
93 expect(ptr2 >= 40);
94 expect(ptr2 == 40);
95 expect(ptr2 <= 40);
91 try expect(ptr1 < ptr2);
92 try expect(ptr2 > ptr1);
93 try expect(ptr2 >= 40);
94 try expect(ptr2 == 40);
95 try expect(ptr2 <= 40);
9696 ptr2 -= 10;
97 expect(ptr1 == ptr2);
97 try expect(ptr1 == ptr2);
9898 }
9999 };
100 S.doTheTest();
101 comptime S.doTheTest();
100 try S.doTheTest();
101 comptime try S.doTheTest();
102102}
103103
104104test "peer type resolution with C pointers" {
......@@ -110,10 +110,10 @@ test "peer type resolution with C pointers" {
110110 var x2 = if (t) ptr_many else ptr_c;
111111 var x3 = if (t) ptr_c else ptr_one;
112112 var x4 = if (t) ptr_c else ptr_many;
113 expect(@TypeOf(x1) == [*c]u8);
114 expect(@TypeOf(x2) == [*c]u8);
115 expect(@TypeOf(x3) == [*c]u8);
116 expect(@TypeOf(x4) == [*c]u8);
113 try expect(@TypeOf(x1) == [*c]u8);
114 try expect(@TypeOf(x2) == [*c]u8);
115 try expect(@TypeOf(x3) == [*c]u8);
116 try expect(@TypeOf(x4) == [*c]u8);
117117}
118118
119119test "implicit casting between C pointer and optional non-C pointer" {
......@@ -121,15 +121,15 @@ test "implicit casting between C pointer and optional non-C pointer" {
121121 const opt_many_ptr: ?[*]const u8 = slice.ptr;
122122 var ptr_opt_many_ptr = &opt_many_ptr;
123123 var c_ptr: [*c]const [*c]const u8 = ptr_opt_many_ptr;
124 expect(c_ptr.*.* == 'a');
124 try expect(c_ptr.*.* == 'a');
125125 ptr_opt_many_ptr = c_ptr;
126 expect(ptr_opt_many_ptr.*.?[1] == 'o');
126 try expect(ptr_opt_many_ptr.*.?[1] == 'o');
127127}
128128
129129test "implicit cast error unions with non-optional to optional pointer" {
130130 const S = struct {
131 fn doTheTest() void {
132 expectError(error.Fail, foo());
131 fn doTheTest() !void {
132 try expectError(error.Fail, foo());
133133 }
134134 fn foo() anyerror!?*u8 {
135135 return bar() orelse error.Fail;
......@@ -138,111 +138,111 @@ test "implicit cast error unions with non-optional to optional pointer" {
138138 return null;
139139 }
140140 };
141 S.doTheTest();
142 comptime S.doTheTest();
141 try S.doTheTest();
142 comptime try S.doTheTest();
143143}
144144
145145test "initialize const optional C pointer to null" {
146146 const a: ?[*c]i32 = null;
147 expect(a == null);
148 comptime expect(a == null);
147 try expect(a == null);
148 comptime try expect(a == null);
149149}
150150
151151test "compare equality of optional and non-optional pointer" {
152152 const a = @intToPtr(*const usize, 0x12345678);
153153 const b = @intToPtr(?*usize, 0x12345678);
154 expect(a == b);
155 expect(b == a);
154 try expect(a == b);
155 try expect(b == a);
156156}
157157
158158test "allowzero pointer and slice" {
159159 var ptr = @intToPtr([*]allowzero i32, 0);
160160 var opt_ptr: ?[*]allowzero i32 = ptr;
161 expect(opt_ptr != null);
162 expect(@ptrToInt(ptr) == 0);
161 try expect(opt_ptr != null);
162 try expect(@ptrToInt(ptr) == 0);
163163 var runtime_zero: usize = 0;
164164 var slice = ptr[runtime_zero..10];
165 comptime expect(@TypeOf(slice) == []allowzero i32);
166 expect(@ptrToInt(&slice[5]) == 20);
165 comptime try expect(@TypeOf(slice) == []allowzero i32);
166 try expect(@ptrToInt(&slice[5]) == 20);
167167
168 comptime expect(@typeInfo(@TypeOf(ptr)).Pointer.is_allowzero);
169 comptime expect(@typeInfo(@TypeOf(slice)).Pointer.is_allowzero);
168 comptime try expect(@typeInfo(@TypeOf(ptr)).Pointer.is_allowzero);
169 comptime try expect(@typeInfo(@TypeOf(slice)).Pointer.is_allowzero);
170170}
171171
172172test "assign null directly to C pointer and test null equality" {
173173 var x: [*c]i32 = null;
174 expect(x == null);
175 expect(null == x);
176 expect(!(x != null));
177 expect(!(null != x));
174 try expect(x == null);
175 try expect(null == x);
176 try expect(!(x != null));
177 try expect(!(null != x));
178178 if (x) |same_x| {
179179 @panic("fail");
180180 }
181181 var otherx: i32 = undefined;
182 expect((x orelse &otherx) == &otherx);
182 try expect((x orelse &otherx) == &otherx);
183183
184184 const y: [*c]i32 = null;
185 comptime expect(y == null);
186 comptime expect(null == y);
187 comptime expect(!(y != null));
188 comptime expect(!(null != y));
185 comptime try expect(y == null);
186 comptime try expect(null == y);
187 comptime try expect(!(y != null));
188 comptime try expect(!(null != y));
189189 if (y) |same_y| @panic("fail");
190190 const othery: i32 = undefined;
191 comptime expect((y orelse &othery) == &othery);
191 comptime try expect((y orelse &othery) == &othery);
192192
193193 var n: i32 = 1234;
194194 var x1: [*c]i32 = &n;
195 expect(!(x1 == null));
196 expect(!(null == x1));
197 expect(x1 != null);
198 expect(null != x1);
199 expect(x1.?.* == 1234);
195 try expect(!(x1 == null));
196 try expect(!(null == x1));
197 try expect(x1 != null);
198 try expect(null != x1);
199 try expect(x1.?.* == 1234);
200200 if (x1) |same_x1| {
201 expect(same_x1.* == 1234);
201 try expect(same_x1.* == 1234);
202202 } else {
203203 @panic("fail");
204204 }
205 expect((x1 orelse &otherx) == x1);
205 try expect((x1 orelse &otherx) == x1);
206206
207207 const nc: i32 = 1234;
208208 const y1: [*c]const i32 = &nc;
209 comptime expect(!(y1 == null));
210 comptime expect(!(null == y1));
211 comptime expect(y1 != null);
212 comptime expect(null != y1);
213 comptime expect(y1.?.* == 1234);
209 comptime try expect(!(y1 == null));
210 comptime try expect(!(null == y1));
211 comptime try expect(y1 != null);
212 comptime try expect(null != y1);
213 comptime try expect(y1.?.* == 1234);
214214 if (y1) |same_y1| {
215 expect(same_y1.* == 1234);
215 try expect(same_y1.* == 1234);
216216 } else {
217217 @compileError("fail");
218218 }
219 comptime expect((y1 orelse &othery) == y1);
219 comptime try expect((y1 orelse &othery) == y1);
220220}
221221
222222test "null terminated pointer" {
223223 const S = struct {
224 fn doTheTest() void {
224 fn doTheTest() !void {
225225 var array_with_zero = [_:0]u8{ 'h', 'e', 'l', 'l', 'o' };
226226 var zero_ptr: [*:0]const u8 = @ptrCast([*:0]const u8, &array_with_zero);
227227 var no_zero_ptr: [*]const u8 = zero_ptr;
228228 var zero_ptr_again = @ptrCast([*:0]const u8, no_zero_ptr);
229 expect(std.mem.eql(u8, std.mem.spanZ(zero_ptr_again), "hello"));
229 try expect(std.mem.eql(u8, std.mem.spanZ(zero_ptr_again), "hello"));
230230 }
231231 };
232 S.doTheTest();
233 comptime S.doTheTest();
232 try S.doTheTest();
233 comptime try S.doTheTest();
234234}
235235
236236test "allow any sentinel" {
237237 const S = struct {
238 fn doTheTest() void {
238 fn doTheTest() !void {
239239 var array = [_:std.math.minInt(i32)]i32{ 1, 2, 3, 4 };
240240 var ptr: [*:std.math.minInt(i32)]i32 = &array;
241 expect(ptr[4] == std.math.minInt(i32));
241 try expect(ptr[4] == std.math.minInt(i32));
242242 }
243243 };
244 S.doTheTest();
245 comptime S.doTheTest();
244 try S.doTheTest();
245 comptime try S.doTheTest();
246246}
247247
248248test "pointer sentinel with enums" {
......@@ -253,42 +253,42 @@ test "pointer sentinel with enums" {
253253 sentinel,
254254 };
255255
256 fn doTheTest() void {
256 fn doTheTest() !void {
257257 var ptr: [*:.sentinel]const Number = &[_:.sentinel]Number{ .one, .two, .two, .one };
258 expect(ptr[4] == .sentinel); // TODO this should be comptime expect, see #3731
258 try expect(ptr[4] == .sentinel); // TODO this should be comptime try expect, see #3731
259259 }
260260 };
261 S.doTheTest();
262 comptime S.doTheTest();
261 try S.doTheTest();
262 comptime try S.doTheTest();
263263}
264264
265265test "pointer sentinel with optional element" {
266266 const S = struct {
267 fn doTheTest() void {
267 fn doTheTest() !void {
268268 var ptr: [*:null]const ?i32 = &[_:null]?i32{ 1, 2, 3, 4 };
269 expect(ptr[4] == null); // TODO this should be comptime expect, see #3731
269 try expect(ptr[4] == null); // TODO this should be comptime try expect, see #3731
270270 }
271271 };
272 S.doTheTest();
273 comptime S.doTheTest();
272 try S.doTheTest();
273 comptime try S.doTheTest();
274274}
275275
276276test "pointer sentinel with +inf" {
277277 const S = struct {
278 fn doTheTest() void {
278 fn doTheTest() !void {
279279 const inf = std.math.inf_f32;
280280 var ptr: [*:inf]const f32 = &[_:inf]f32{ 1.1, 2.2, 3.3, 4.4 };
281 expect(ptr[4] == inf); // TODO this should be comptime expect, see #3731
281 try expect(ptr[4] == inf); // TODO this should be comptime try expect, see #3731
282282 }
283283 };
284 S.doTheTest();
285 comptime S.doTheTest();
284 try S.doTheTest();
285 comptime try S.doTheTest();
286286}
287287
288288test "pointer to array at fixed address" {
289289 const array = @intToPtr(*volatile [1]u32, 0x10);
290290 // Silly check just to reference `array`
291 expect(@ptrToInt(&array[0]) == 0x10);
291 try expect(@ptrToInt(&array[0]) == 0x10);
292292}
293293
294294test "pointer arithmetic affects the alignment" {
......@@ -296,28 +296,28 @@ test "pointer arithmetic affects the alignment" {
296296 var ptr: [*]align(8) u32 = undefined;
297297 var x: usize = 1;
298298
299 expect(@typeInfo(@TypeOf(ptr)).Pointer.alignment == 8);
299 try expect(@typeInfo(@TypeOf(ptr)).Pointer.alignment == 8);
300300 const ptr1 = ptr + 1; // 1 * 4 = 4 -> lcd(4,8) = 4
301 expect(@typeInfo(@TypeOf(ptr1)).Pointer.alignment == 4);
301 try expect(@typeInfo(@TypeOf(ptr1)).Pointer.alignment == 4);
302302 const ptr2 = ptr + 4; // 4 * 4 = 16 -> lcd(16,8) = 8
303 expect(@typeInfo(@TypeOf(ptr2)).Pointer.alignment == 8);
303 try expect(@typeInfo(@TypeOf(ptr2)).Pointer.alignment == 8);
304304 const ptr3 = ptr + 0; // no-op
305 expect(@typeInfo(@TypeOf(ptr3)).Pointer.alignment == 8);
305 try expect(@typeInfo(@TypeOf(ptr3)).Pointer.alignment == 8);
306306 const ptr4 = ptr + x; // runtime-known addend
307 expect(@typeInfo(@TypeOf(ptr4)).Pointer.alignment == 4);
307 try expect(@typeInfo(@TypeOf(ptr4)).Pointer.alignment == 4);
308308 }
309309 {
310310 var ptr: [*]align(8) [3]u8 = undefined;
311311 var x: usize = 1;
312312
313313 const ptr1 = ptr + 17; // 3 * 17 = 51
314 expect(@typeInfo(@TypeOf(ptr1)).Pointer.alignment == 1);
314 try expect(@typeInfo(@TypeOf(ptr1)).Pointer.alignment == 1);
315315 const ptr2 = ptr + x; // runtime-known addend
316 expect(@typeInfo(@TypeOf(ptr2)).Pointer.alignment == 1);
316 try expect(@typeInfo(@TypeOf(ptr2)).Pointer.alignment == 1);
317317 const ptr3 = ptr + 8; // 3 * 8 = 24 -> lcd(8,24) = 8
318 expect(@typeInfo(@TypeOf(ptr3)).Pointer.alignment == 8);
318 try expect(@typeInfo(@TypeOf(ptr3)).Pointer.alignment == 8);
319319 const ptr4 = ptr + 4; // 3 * 4 = 12 -> lcd(8,12) = 4
320 expect(@typeInfo(@TypeOf(ptr4)).Pointer.alignment == 4);
320 try expect(@typeInfo(@TypeOf(ptr4)).Pointer.alignment == 4);
321321 }
322322}
323323
......@@ -325,15 +325,15 @@ test "@ptrToInt on null optional at comptime" {
325325 {
326326 const pointer = @intToPtr(?*u8, 0x000);
327327 const x = @ptrToInt(pointer);
328 comptime expect(0 == @ptrToInt(pointer));
328 comptime try expect(0 == @ptrToInt(pointer));
329329 }
330330 {
331331 const pointer = @intToPtr(?*u8, 0xf00);
332 comptime expect(0xf00 == @ptrToInt(pointer));
332 comptime try expect(0xf00 == @ptrToInt(pointer));
333333 }
334334}
335335
336336test "indexing array with sentinel returns correct type" {
337337 var s: [:0]const u8 = "abc";
338 testing.expectEqualSlices(u8, "*const u8", @typeName(@TypeOf(&s[0])));
338 try testing.expectEqualSlices(u8, "*const u8", @typeName(@TypeOf(&s[0])));
339339}
test/behavior/popcount.zig+12-12
......@@ -1,43 +1,43 @@
11const expect = @import("std").testing.expect;
22
33test "@popCount" {
4 comptime testPopCount();
5 testPopCount();
4 comptime try testPopCount();
5 try testPopCount();
66}
77
8fn testPopCount() void {
8fn testPopCount() !void {
99 {
1010 var x: u32 = 0xffffffff;
11 expect(@popCount(u32, x) == 32);
11 try expect(@popCount(u32, x) == 32);
1212 }
1313 {
1414 var x: u5 = 0x1f;
15 expect(@popCount(u5, x) == 5);
15 try expect(@popCount(u5, x) == 5);
1616 }
1717 {
1818 var x: u32 = 0xaa;
19 expect(@popCount(u32, x) == 4);
19 try expect(@popCount(u32, x) == 4);
2020 }
2121 {
2222 var x: u32 = 0xaaaaaaaa;
23 expect(@popCount(u32, x) == 16);
23 try expect(@popCount(u32, x) == 16);
2424 }
2525 {
2626 var x: u32 = 0xaaaaaaaa;
27 expect(@popCount(u32, x) == 16);
27 try expect(@popCount(u32, x) == 16);
2828 }
2929 {
3030 var x: i16 = -1;
31 expect(@popCount(i16, x) == 16);
31 try expect(@popCount(i16, x) == 16);
3232 }
3333 {
3434 var x: i8 = -120;
35 expect(@popCount(i8, x) == 2);
35 try expect(@popCount(i8, x) == 2);
3636 }
3737 comptime {
38 expect(@popCount(u8, @bitCast(u8, @as(i8, -120))) == 2);
38 try expect(@popCount(u8, @bitCast(u8, @as(i8, -120))) == 2);
3939 }
4040 comptime {
41 expect(@popCount(i128, 0b11111111000110001100010000100001000011000011100101010001) == 24);
41 try expect(@popCount(i128, 0b11111111000110001100010000100001000011000011100101010001) == 24);
4242 }
4343}
test/behavior/ptrcast.zig+12-12
......@@ -4,25 +4,25 @@ const expect = std.testing.expect;
44const native_endian = builtin.target.cpu.arch.endian();
55
66test "reinterpret bytes as integer with nonzero offset" {
7 testReinterpretBytesAsInteger();
8 comptime testReinterpretBytesAsInteger();
7 try testReinterpretBytesAsInteger();
8 comptime try testReinterpretBytesAsInteger();
99}
1010
11fn testReinterpretBytesAsInteger() void {
11fn testReinterpretBytesAsInteger() !void {
1212 const bytes = "\x12\x34\x56\x78\xab";
1313 const expected = switch (native_endian) {
1414 .Little => 0xab785634,
1515 .Big => 0x345678ab,
1616 };
17 expect(@ptrCast(*align(1) const u32, bytes[1..5]).* == expected);
17 try expect(@ptrCast(*align(1) const u32, bytes[1..5]).* == expected);
1818}
1919
2020test "reinterpret bytes of an array into an extern struct" {
21 testReinterpretBytesAsExternStruct();
22 comptime testReinterpretBytesAsExternStruct();
21 try testReinterpretBytesAsExternStruct();
22 comptime try testReinterpretBytesAsExternStruct();
2323}
2424
25fn testReinterpretBytesAsExternStruct() void {
25fn testReinterpretBytesAsExternStruct() !void {
2626 var bytes align(2) = [_]u8{ 1, 2, 3, 4, 5, 6 };
2727
2828 const S = extern struct {
......@@ -33,15 +33,15 @@ fn testReinterpretBytesAsExternStruct() void {
3333
3434 var ptr = @ptrCast(*const S, &bytes);
3535 var val = ptr.c;
36 expect(val == 5);
36 try expect(val == 5);
3737}
3838
3939test "reinterpret struct field at comptime" {
4040 const numNative = comptime Bytes.init(0x12345678);
4141 if (native_endian != .Little) {
42 expect(std.mem.eql(u8, &[_]u8{ 0x12, 0x34, 0x56, 0x78 }, &numNative.bytes));
42 try expect(std.mem.eql(u8, &[_]u8{ 0x12, 0x34, 0x56, 0x78 }, &numNative.bytes));
4343 } else {
44 expect(std.mem.eql(u8, &[_]u8{ 0x78, 0x56, 0x34, 0x12 }, &numNative.bytes));
44 try expect(std.mem.eql(u8, &[_]u8{ 0x78, 0x56, 0x34, 0x12 }, &numNative.bytes));
4545 }
4646}
4747
......@@ -60,7 +60,7 @@ test "comptime ptrcast keeps larger alignment" {
6060 comptime {
6161 const a: u32 = 1234;
6262 const p = @ptrCast([*]const u8, &a);
63 std.debug.assert(@TypeOf(p) == [*]align(@alignOf(u32)) const u8);
63 try expect(@TypeOf(p) == [*]align(@alignOf(u32)) const u8);
6464 }
6565}
6666
......@@ -69,5 +69,5 @@ test "implicit optional pointer to optional c_void pointer" {
6969 var x: ?[*]u8 = &buf;
7070 var y: ?*c_void = x;
7171 var z = @ptrCast(*[4]u8, y);
72 expect(std.mem.eql(u8, z, "aoeu"));
72 try expect(std.mem.eql(u8, z, "aoeu"));
7373}
test/behavior/pub_enum.zig+4-4
......@@ -2,12 +2,12 @@ const other = @import("pub_enum/other.zig");
22const expect = @import("std").testing.expect;
33
44test "pub enum" {
5 pubEnumTest(other.APubEnum.Two);
5 try pubEnumTest(other.APubEnum.Two);
66}
7fn pubEnumTest(foo: other.APubEnum) void {
8 expect(foo == other.APubEnum.Two);
7fn pubEnumTest(foo: other.APubEnum) !void {
8 try expect(foo == other.APubEnum.Two);
99}
1010
1111test "cast with imported symbol" {
12 expect(@as(other.size_t, 42) == 42);
12 try expect(@as(other.size_t, 42) == 42);
1313}
test/behavior/ref_var_in_if_after_if_2nd_switch_prong.zig+10-10
......@@ -3,12 +3,12 @@ const mem = @import("std").mem;
33
44var ok: bool = false;
55test "reference a variable in an if after an if in the 2nd switch prong" {
6 foo(true, Num.Two, false, "aoeu");
7 expect(!ok);
8 foo(false, Num.One, false, "aoeu");
9 expect(!ok);
10 foo(true, Num.One, false, "aoeu");
11 expect(ok);
6 try foo(true, Num.Two, false, "aoeu");
7 try expect(!ok);
8 try foo(false, Num.One, false, "aoeu");
9 try expect(!ok);
10 try foo(true, Num.One, false, "aoeu");
11 try expect(ok);
1212}
1313
1414const Num = enum {
......@@ -16,7 +16,7 @@ const Num = enum {
1616 Two,
1717};
1818
19fn foo(c: bool, k: Num, c2: bool, b: []const u8) void {
19fn foo(c: bool, k: Num, c2: bool, b: []const u8) !void {
2020 switch (k) {
2121 Num.Two => {},
2222 Num.One => {
......@@ -25,13 +25,13 @@ fn foo(c: bool, k: Num, c2: bool, b: []const u8) void {
2525
2626 if (c2) {}
2727
28 a(output_path);
28 try a(output_path);
2929 }
3030 },
3131 }
3232}
3333
34fn a(x: []const u8) void {
35 expect(mem.eql(u8, x, "aoeu"));
34fn a(x: []const u8) !void {
35 try expect(mem.eql(u8, x, "aoeu"));
3636 ok = true;
3737}
test/behavior/reflection.zig+17-17
......@@ -5,12 +5,12 @@ const reflection = @This();
55test "reflection: function return type, var args, and param types" {
66 comptime {
77 const info = @typeInfo(@TypeOf(dummy)).Fn;
8 expect(info.return_type.? == i32);
9 expect(!info.is_var_args);
10 expect(info.args.len == 3);
11 expect(info.args[0].arg_type.? == bool);
12 expect(info.args[1].arg_type.? == i32);
13 expect(info.args[2].arg_type.? == f32);
8 try expect(info.return_type.? == i32);
9 try expect(!info.is_var_args);
10 try expect(info.args.len == 3);
11 try expect(info.args[0].arg_type.? == bool);
12 try expect(info.args[1].arg_type.? == i32);
13 try expect(info.args[2].arg_type.? == f32);
1414 }
1515}
1616
......@@ -25,18 +25,18 @@ test "reflection: @field" {
2525 .three = void{},
2626 };
2727
28 expect(f.one == f.one);
29 expect(@field(f, "o" ++ "ne") == f.one);
30 expect(@field(f, "t" ++ "wo") == f.two);
31 expect(@field(f, "th" ++ "ree") == f.three);
32 expect(@field(Foo, "const" ++ "ant") == Foo.constant);
33 expect(@field(Bar, "O" ++ "ne") == Bar.One);
34 expect(@field(Bar, "T" ++ "wo") == Bar.Two);
35 expect(@field(Bar, "Th" ++ "ree") == Bar.Three);
36 expect(@field(Bar, "F" ++ "our") == Bar.Four);
37 expect(@field(reflection, "dum" ++ "my")(true, 1, 2) == dummy(true, 1, 2));
28 try expect(f.one == f.one);
29 try expect(@field(f, "o" ++ "ne") == f.one);
30 try expect(@field(f, "t" ++ "wo") == f.two);
31 try expect(@field(f, "th" ++ "ree") == f.three);
32 try expect(@field(Foo, "const" ++ "ant") == Foo.constant);
33 try expect(@field(Bar, "O" ++ "ne") == Bar.One);
34 try expect(@field(Bar, "T" ++ "wo") == Bar.Two);
35 try expect(@field(Bar, "Th" ++ "ree") == Bar.Three);
36 try expect(@field(Bar, "F" ++ "our") == Bar.Four);
37 try expect(@field(reflection, "dum" ++ "my")(true, 1, 2) == dummy(true, 1, 2));
3838 @field(f, "o" ++ "ne") = 4;
39 expect(f.one == 4);
39 try expect(f.one == 4);
4040}
4141
4242const Foo = struct {
test/behavior/shuffle.zig+10-10
......@@ -9,33 +9,33 @@ test "@shuffle" {
99 if (builtin.os.tag == .wasi) return error.SkipZigTest;
1010
1111 const S = struct {
12 fn doTheTest() void {
12 fn doTheTest() !void {
1313 var v: Vector(4, i32) = [4]i32{ 2147483647, -2, 30, 40 };
1414 var x: Vector(4, i32) = [4]i32{ 1, 2147483647, 3, 4 };
1515 const mask: Vector(4, i32) = [4]i32{ 0, ~@as(i32, 2), 3, ~@as(i32, 3) };
1616 var res = @shuffle(i32, v, x, mask);
17 expect(mem.eql(i32, &@as([4]i32, res), &[4]i32{ 2147483647, 3, 40, 4 }));
17 try expect(mem.eql(i32, &@as([4]i32, res), &[4]i32{ 2147483647, 3, 40, 4 }));
1818
1919 // Implicit cast from array (of mask)
2020 res = @shuffle(i32, v, x, [4]i32{ 0, ~@as(i32, 2), 3, ~@as(i32, 3) });
21 expect(mem.eql(i32, &@as([4]i32, res), &[4]i32{ 2147483647, 3, 40, 4 }));
21 try expect(mem.eql(i32, &@as([4]i32, res), &[4]i32{ 2147483647, 3, 40, 4 }));
2222
2323 // Undefined
2424 const mask2: Vector(4, i32) = [4]i32{ 3, 1, 2, 0 };
2525 res = @shuffle(i32, v, undefined, mask2);
26 expect(mem.eql(i32, &@as([4]i32, res), &[4]i32{ 40, -2, 30, 2147483647 }));
26 try expect(mem.eql(i32, &@as([4]i32, res), &[4]i32{ 40, -2, 30, 2147483647 }));
2727
2828 // Upcasting of b
2929 var v2: Vector(2, i32) = [2]i32{ 2147483647, undefined };
3030 const mask3: Vector(4, i32) = [4]i32{ ~@as(i32, 0), 2, ~@as(i32, 0), 3 };
3131 res = @shuffle(i32, x, v2, mask3);
32 expect(mem.eql(i32, &@as([4]i32, res), &[4]i32{ 2147483647, 3, 2147483647, 4 }));
32 try expect(mem.eql(i32, &@as([4]i32, res), &[4]i32{ 2147483647, 3, 2147483647, 4 }));
3333
3434 // Upcasting of a
3535 var v3: Vector(2, i32) = [2]i32{ 2147483647, -2 };
3636 const mask4: Vector(4, i32) = [4]i32{ 0, ~@as(i32, 2), 1, ~@as(i32, 3) };
3737 res = @shuffle(i32, v3, x, mask4);
38 expect(mem.eql(i32, &@as([4]i32, res), &[4]i32{ 2147483647, 3, -2, 4 }));
38 try expect(mem.eql(i32, &@as([4]i32, res), &[4]i32{ 2147483647, 3, -2, 4 }));
3939
4040 // bool
4141 // https://github.com/ziglang/zig/issues/3317
......@@ -44,7 +44,7 @@ test "@shuffle" {
4444 var v4: Vector(2, bool) = [2]bool{ true, false };
4545 const mask5: Vector(4, i32) = [4]i32{ 0, ~@as(i32, 1), 1, 2 };
4646 var res2 = @shuffle(bool, x2, v4, mask5);
47 expect(mem.eql(bool, &@as([4]bool, res2), &[4]bool{ false, false, true, false }));
47 try expect(mem.eql(bool, &@as([4]bool, res2), &[4]bool{ false, false, true, false }));
4848 }
4949
5050 // TODO re-enable when LLVM codegen is fixed
......@@ -54,10 +54,10 @@ test "@shuffle" {
5454 var v4: Vector(2, bool) = [2]bool{ true, false };
5555 const mask5: Vector(4, i32) = [4]i32{ 0, ~@as(i32, 1), 1, 2 };
5656 var res2 = @shuffle(bool, x2, v4, mask5);
57 expect(mem.eql(bool, &@as([4]bool, res2), &[4]bool{ false, false, true, false }));
57 try expect(mem.eql(bool, &@as([4]bool, res2), &[4]bool{ false, false, true, false }));
5858 }
5959 }
6060 };
61 S.doTheTest();
62 comptime S.doTheTest();
61 try S.doTheTest();
62 comptime try S.doTheTest();
6363}
test/behavior/sizeof_and_typeof.zig+75-75
......@@ -5,7 +5,7 @@ const expectEqual = std.testing.expectEqual;
55
66test "@sizeOf and @TypeOf" {
77 const y: @TypeOf(x) = 120;
8 expect(@sizeOf(@TypeOf(y)) == 2);
8 try expect(@sizeOf(@TypeOf(y)) == 2);
99}
1010const x: u16 = 13;
1111const z: @TypeOf(x) = 19;
......@@ -36,27 +36,27 @@ const P = packed struct {
3636
3737test "@byteOffsetOf" {
3838 // Packed structs have fixed memory layout
39 expect(@byteOffsetOf(P, "a") == 0);
40 expect(@byteOffsetOf(P, "b") == 1);
41 expect(@byteOffsetOf(P, "c") == 5);
42 expect(@byteOffsetOf(P, "d") == 6);
43 expect(@byteOffsetOf(P, "e") == 6);
44 expect(@byteOffsetOf(P, "f") == 7);
45 expect(@byteOffsetOf(P, "g") == 9);
46 expect(@byteOffsetOf(P, "h") == 11);
47 expect(@byteOffsetOf(P, "i") == 12);
39 try expect(@byteOffsetOf(P, "a") == 0);
40 try expect(@byteOffsetOf(P, "b") == 1);
41 try expect(@byteOffsetOf(P, "c") == 5);
42 try expect(@byteOffsetOf(P, "d") == 6);
43 try expect(@byteOffsetOf(P, "e") == 6);
44 try expect(@byteOffsetOf(P, "f") == 7);
45 try expect(@byteOffsetOf(P, "g") == 9);
46 try expect(@byteOffsetOf(P, "h") == 11);
47 try expect(@byteOffsetOf(P, "i") == 12);
4848
4949 // Normal struct fields can be moved/padded
5050 var a: A = undefined;
51 expect(@ptrToInt(&a.a) - @ptrToInt(&a) == @byteOffsetOf(A, "a"));
52 expect(@ptrToInt(&a.b) - @ptrToInt(&a) == @byteOffsetOf(A, "b"));
53 expect(@ptrToInt(&a.c) - @ptrToInt(&a) == @byteOffsetOf(A, "c"));
54 expect(@ptrToInt(&a.d) - @ptrToInt(&a) == @byteOffsetOf(A, "d"));
55 expect(@ptrToInt(&a.e) - @ptrToInt(&a) == @byteOffsetOf(A, "e"));
56 expect(@ptrToInt(&a.f) - @ptrToInt(&a) == @byteOffsetOf(A, "f"));
57 expect(@ptrToInt(&a.g) - @ptrToInt(&a) == @byteOffsetOf(A, "g"));
58 expect(@ptrToInt(&a.h) - @ptrToInt(&a) == @byteOffsetOf(A, "h"));
59 expect(@ptrToInt(&a.i) - @ptrToInt(&a) == @byteOffsetOf(A, "i"));
51 try expect(@ptrToInt(&a.a) - @ptrToInt(&a) == @byteOffsetOf(A, "a"));
52 try expect(@ptrToInt(&a.b) - @ptrToInt(&a) == @byteOffsetOf(A, "b"));
53 try expect(@ptrToInt(&a.c) - @ptrToInt(&a) == @byteOffsetOf(A, "c"));
54 try expect(@ptrToInt(&a.d) - @ptrToInt(&a) == @byteOffsetOf(A, "d"));
55 try expect(@ptrToInt(&a.e) - @ptrToInt(&a) == @byteOffsetOf(A, "e"));
56 try expect(@ptrToInt(&a.f) - @ptrToInt(&a) == @byteOffsetOf(A, "f"));
57 try expect(@ptrToInt(&a.g) - @ptrToInt(&a) == @byteOffsetOf(A, "g"));
58 try expect(@ptrToInt(&a.h) - @ptrToInt(&a) == @byteOffsetOf(A, "h"));
59 try expect(@ptrToInt(&a.i) - @ptrToInt(&a) == @byteOffsetOf(A, "i"));
6060}
6161
6262test "@byteOffsetOf packed struct, array length not power of 2 or multiple of native pointer width in bytes" {
......@@ -65,68 +65,68 @@ test "@byteOffsetOf packed struct, array length not power of 2 or multiple of na
6565 a: [p3a_len]u8,
6666 b: usize,
6767 };
68 std.testing.expectEqual(0, @byteOffsetOf(P3, "a"));
69 std.testing.expectEqual(p3a_len, @byteOffsetOf(P3, "b"));
68 try std.testing.expectEqual(0, @byteOffsetOf(P3, "a"));
69 try std.testing.expectEqual(p3a_len, @byteOffsetOf(P3, "b"));
7070
7171 const p5a_len = 5;
7272 const P5 = packed struct {
7373 a: [p5a_len]u8,
7474 b: usize,
7575 };
76 std.testing.expectEqual(0, @byteOffsetOf(P5, "a"));
77 std.testing.expectEqual(p5a_len, @byteOffsetOf(P5, "b"));
76 try std.testing.expectEqual(0, @byteOffsetOf(P5, "a"));
77 try std.testing.expectEqual(p5a_len, @byteOffsetOf(P5, "b"));
7878
7979 const p6a_len = 6;
8080 const P6 = packed struct {
8181 a: [p6a_len]u8,
8282 b: usize,
8383 };
84 std.testing.expectEqual(0, @byteOffsetOf(P6, "a"));
85 std.testing.expectEqual(p6a_len, @byteOffsetOf(P6, "b"));
84 try std.testing.expectEqual(0, @byteOffsetOf(P6, "a"));
85 try std.testing.expectEqual(p6a_len, @byteOffsetOf(P6, "b"));
8686
8787 const p7a_len = 7;
8888 const P7 = packed struct {
8989 a: [p7a_len]u8,
9090 b: usize,
9191 };
92 std.testing.expectEqual(0, @byteOffsetOf(P7, "a"));
93 std.testing.expectEqual(p7a_len, @byteOffsetOf(P7, "b"));
92 try std.testing.expectEqual(0, @byteOffsetOf(P7, "a"));
93 try std.testing.expectEqual(p7a_len, @byteOffsetOf(P7, "b"));
9494
9595 const p9a_len = 9;
9696 const P9 = packed struct {
9797 a: [p9a_len]u8,
9898 b: usize,
9999 };
100 std.testing.expectEqual(0, @byteOffsetOf(P9, "a"));
101 std.testing.expectEqual(p9a_len, @byteOffsetOf(P9, "b"));
100 try std.testing.expectEqual(0, @byteOffsetOf(P9, "a"));
101 try std.testing.expectEqual(p9a_len, @byteOffsetOf(P9, "b"));
102102
103103 // 10, 11, 12, 13, 14, 15, 17, 18, 19, 20, 21, 22, 23, 25 etc. are further cases
104104}
105105
106106test "@bitOffsetOf" {
107107 // Packed structs have fixed memory layout
108 expect(@bitOffsetOf(P, "a") == 0);
109 expect(@bitOffsetOf(P, "b") == 8);
110 expect(@bitOffsetOf(P, "c") == 40);
111 expect(@bitOffsetOf(P, "d") == 48);
112 expect(@bitOffsetOf(P, "e") == 51);
113 expect(@bitOffsetOf(P, "f") == 56);
114 expect(@bitOffsetOf(P, "g") == 72);
108 try expect(@bitOffsetOf(P, "a") == 0);
109 try expect(@bitOffsetOf(P, "b") == 8);
110 try expect(@bitOffsetOf(P, "c") == 40);
111 try expect(@bitOffsetOf(P, "d") == 48);
112 try expect(@bitOffsetOf(P, "e") == 51);
113 try expect(@bitOffsetOf(P, "f") == 56);
114 try expect(@bitOffsetOf(P, "g") == 72);
115115
116 expect(@byteOffsetOf(A, "a") * 8 == @bitOffsetOf(A, "a"));
117 expect(@byteOffsetOf(A, "b") * 8 == @bitOffsetOf(A, "b"));
118 expect(@byteOffsetOf(A, "c") * 8 == @bitOffsetOf(A, "c"));
119 expect(@byteOffsetOf(A, "d") * 8 == @bitOffsetOf(A, "d"));
120 expect(@byteOffsetOf(A, "e") * 8 == @bitOffsetOf(A, "e"));
121 expect(@byteOffsetOf(A, "f") * 8 == @bitOffsetOf(A, "f"));
122 expect(@byteOffsetOf(A, "g") * 8 == @bitOffsetOf(A, "g"));
116 try expect(@byteOffsetOf(A, "a") * 8 == @bitOffsetOf(A, "a"));
117 try expect(@byteOffsetOf(A, "b") * 8 == @bitOffsetOf(A, "b"));
118 try expect(@byteOffsetOf(A, "c") * 8 == @bitOffsetOf(A, "c"));
119 try expect(@byteOffsetOf(A, "d") * 8 == @bitOffsetOf(A, "d"));
120 try expect(@byteOffsetOf(A, "e") * 8 == @bitOffsetOf(A, "e"));
121 try expect(@byteOffsetOf(A, "f") * 8 == @bitOffsetOf(A, "f"));
122 try expect(@byteOffsetOf(A, "g") * 8 == @bitOffsetOf(A, "g"));
123123}
124124
125125test "@sizeOf on compile-time types" {
126 expect(@sizeOf(comptime_int) == 0);
127 expect(@sizeOf(comptime_float) == 0);
128 expect(@sizeOf(@TypeOf(.hi)) == 0);
129 expect(@sizeOf(@TypeOf(type)) == 0);
126 try expect(@sizeOf(comptime_int) == 0);
127 try expect(@sizeOf(comptime_float) == 0);
128 try expect(@sizeOf(@TypeOf(.hi)) == 0);
129 try expect(@sizeOf(@TypeOf(type)) == 0);
130130}
131131
132132test "@sizeOf(T) == 0 doesn't force resolving struct size" {
......@@ -140,8 +140,8 @@ test "@sizeOf(T) == 0 doesn't force resolving struct size" {
140140 };
141141 };
142142
143 expect(@sizeOf(S.Foo) == 4);
144 expect(@sizeOf(S.Bar) == 8);
143 try expect(@sizeOf(S.Foo) == 4);
144 try expect(@sizeOf(S.Bar) == 8);
145145}
146146
147147test "@TypeOf() has no runtime side effects" {
......@@ -153,8 +153,8 @@ test "@TypeOf() has no runtime side effects" {
153153 };
154154 var data: i32 = 0;
155155 const T = @TypeOf(S.foo(i32, &data));
156 comptime expect(T == i32);
157 expect(data == 0);
156 comptime try expect(T == i32);
157 try expect(data == 0);
158158}
159159
160160test "@TypeOf() with multiple arguments" {
......@@ -162,21 +162,21 @@ test "@TypeOf() with multiple arguments" {
162162 var var_1: u32 = undefined;
163163 var var_2: u8 = undefined;
164164 var var_3: u64 = undefined;
165 comptime expect(@TypeOf(var_1, var_2, var_3) == u64);
165 comptime try expect(@TypeOf(var_1, var_2, var_3) == u64);
166166 }
167167 {
168168 var var_1: f16 = undefined;
169169 var var_2: f32 = undefined;
170170 var var_3: f64 = undefined;
171 comptime expect(@TypeOf(var_1, var_2, var_3) == f64);
171 comptime try expect(@TypeOf(var_1, var_2, var_3) == f64);
172172 }
173173 {
174174 var var_1: u16 = undefined;
175 comptime expect(@TypeOf(var_1, 0xffff) == u16);
175 comptime try expect(@TypeOf(var_1, 0xffff) == u16);
176176 }
177177 {
178178 var var_1: f32 = undefined;
179 comptime expect(@TypeOf(var_1, 3.1415) == f32);
179 comptime try expect(@TypeOf(var_1, 3.1415) == f32);
180180 }
181181}
182182
......@@ -189,8 +189,8 @@ test "branching logic inside @TypeOf" {
189189 }
190190 };
191191 const T = @TypeOf(S.foo() catch undefined);
192 comptime expect(T == i32);
193 expect(S.data == 0);
192 comptime try expect(T == i32);
193 try expect(S.data == 0);
194194}
195195
196196fn fn1(alpha: bool) void {
......@@ -203,12 +203,12 @@ test "lazy @sizeOf result is checked for definedness" {
203203}
204204
205205test "@bitSizeOf" {
206 expect(@bitSizeOf(u2) == 2);
207 expect(@bitSizeOf(u8) == @sizeOf(u8) * 8);
208 expect(@bitSizeOf(struct {
206 try expect(@bitSizeOf(u2) == 2);
207 try expect(@bitSizeOf(u8) == @sizeOf(u8) * 8);
208 try expect(@bitSizeOf(struct {
209209 a: u2,
210210 }) == 8);
211 expect(@bitSizeOf(packed struct {
211 try expect(@bitSizeOf(packed struct {
212212 a: u2,
213213 }) == 2);
214214}
......@@ -241,24 +241,24 @@ test "@sizeOf comparison against zero" {
241241 f2: H(***@This()),
242242 };
243243 const S = struct {
244 fn doTheTest(comptime T: type, comptime result: bool) void {
245 expectEqual(result, @sizeOf(T) > 0);
244 fn doTheTest(comptime T: type, comptime result: bool) !void {
245 try expectEqual(result, @sizeOf(T) > 0);
246246 }
247247 };
248248 // Zero-sized type
249 S.doTheTest(u0, false);
250 S.doTheTest(*u0, false);
249 try S.doTheTest(u0, false);
250 try S.doTheTest(*u0, false);
251251 // Non byte-sized type
252 S.doTheTest(u1, true);
253 S.doTheTest(*u1, true);
252 try S.doTheTest(u1, true);
253 try S.doTheTest(*u1, true);
254254 // Regular type
255 S.doTheTest(u8, true);
256 S.doTheTest(*u8, true);
257 S.doTheTest(f32, true);
258 S.doTheTest(*f32, true);
255 try S.doTheTest(u8, true);
256 try S.doTheTest(*u8, true);
257 try S.doTheTest(f32, true);
258 try S.doTheTest(*f32, true);
259259 // Container with ptr pointing to themselves
260 S.doTheTest(S0, true);
261 S.doTheTest(U0, true);
262 S.doTheTest(S1, true);
263 S.doTheTest(U1, true);
260 try S.doTheTest(S0, true);
261 try S.doTheTest(U0, true);
262 try S.doTheTest(S1, true);
263 try S.doTheTest(U1, true);
264264}
test/behavior/slice.zig+119-119
......@@ -7,11 +7,11 @@ const mem = std.mem;
77const x = @intToPtr([*]i32, 0x1000)[0..0x500];
88const y = x[0x100..];
99test "compile time slice of pointer to hard coded address" {
10 expect(@ptrToInt(x) == 0x1000);
11 expect(x.len == 0x500);
10 try expect(@ptrToInt(x) == 0x1000);
11 try expect(x.len == 0x500);
1212
13 expect(@ptrToInt(y) == 0x1100);
14 expect(y.len == 0x400);
13 try expect(@ptrToInt(y) == 0x1100);
14 try expect(y.len == 0x400);
1515}
1616
1717test "runtime safety lets us slice from len..len" {
......@@ -20,7 +20,7 @@ test "runtime safety lets us slice from len..len" {
2020 2,
2121 3,
2222 };
23 expect(mem.eql(u8, sliceFromLenToLen(an_array[0..], 3, 3), ""));
23 try expect(mem.eql(u8, sliceFromLenToLen(an_array[0..], 3, 3), ""));
2424}
2525
2626fn sliceFromLenToLen(a_slice: []u8, start: usize, end: usize) []u8 {
......@@ -29,18 +29,18 @@ fn sliceFromLenToLen(a_slice: []u8, start: usize, end: usize) []u8 {
2929
3030test "implicitly cast array of size 0 to slice" {
3131 var msg = [_]u8{};
32 assertLenIsZero(&msg);
32 try assertLenIsZero(&msg);
3333}
3434
35fn assertLenIsZero(msg: []const u8) void {
36 expect(msg.len == 0);
35fn assertLenIsZero(msg: []const u8) !void {
36 try expect(msg.len == 0);
3737}
3838
3939test "C pointer" {
4040 var buf: [*c]const u8 = "kjdhfkjdhfdkjhfkfjhdfkjdhfkdjhfdkjhf";
4141 var len: u32 = 10;
4242 var slice = buf[0..len];
43 expectEqualSlices(u8, "kjdhfkjdhf", slice);
43 try expectEqualSlices(u8, "kjdhfkjdhf", slice);
4444}
4545
4646test "C pointer slice access" {
......@@ -48,11 +48,11 @@ test "C pointer slice access" {
4848 const c_ptr = @ptrCast([*c]const u32, &buf);
4949
5050 var runtime_zero: usize = 0;
51 comptime expectEqual([]const u32, @TypeOf(c_ptr[runtime_zero..1]));
52 comptime expectEqual(*const [1]u32, @TypeOf(c_ptr[0..1]));
51 comptime try expectEqual([]const u32, @TypeOf(c_ptr[runtime_zero..1]));
52 comptime try expectEqual(*const [1]u32, @TypeOf(c_ptr[0..1]));
5353
5454 for (c_ptr[0..5]) |*cl| {
55 expectEqual(@as(u32, 42), cl.*);
55 try expectEqual(@as(u32, 42), cl.*);
5656 }
5757}
5858
......@@ -65,8 +65,8 @@ fn sliceSum(comptime q: []const u8) i32 {
6565}
6666
6767test "comptime slices are disambiguated" {
68 expect(sliceSum(&[_]u8{ 1, 2 }) == 3);
69 expect(sliceSum(&[_]u8{ 3, 4 }) == 7);
68 try expect(sliceSum(&[_]u8{ 1, 2 }) == 3);
69 try expect(sliceSum(&[_]u8{ 3, 4 }) == 7);
7070}
7171
7272test "slice type with custom alignment" {
......@@ -77,20 +77,20 @@ test "slice type with custom alignment" {
7777 var array: [10]LazilyResolvedType align(32) = undefined;
7878 slice = &array;
7979 slice[1].anything = 42;
80 expect(array[1].anything == 42);
80 try expect(array[1].anything == 42);
8181}
8282
8383test "access len index of sentinel-terminated slice" {
8484 const S = struct {
85 fn doTheTest() void {
85 fn doTheTest() !void {
8686 var slice: [:0]const u8 = "hello";
8787
88 expect(slice.len == 5);
89 expect(slice[5] == 0);
88 try expect(slice.len == 5);
89 try expect(slice[5] == 0);
9090 }
9191 };
92 S.doTheTest();
93 comptime S.doTheTest();
92 try S.doTheTest();
93 comptime try S.doTheTest();
9494}
9595
9696test "obtaining a null terminated slice" {
......@@ -108,230 +108,230 @@ test "obtaining a null terminated slice" {
108108 var runtime_len: usize = 3;
109109 const ptr2 = buf[0..runtime_len :0];
110110 // ptr2 is a null-terminated slice
111 comptime expect(@TypeOf(ptr2) == [:0]u8);
112 comptime expect(@TypeOf(ptr2[0..2]) == *[2]u8);
111 comptime try expect(@TypeOf(ptr2) == [:0]u8);
112 comptime try expect(@TypeOf(ptr2[0..2]) == *[2]u8);
113113 var runtime_zero: usize = 0;
114 comptime expect(@TypeOf(ptr2[runtime_zero..2]) == []u8);
114 comptime try expect(@TypeOf(ptr2[runtime_zero..2]) == []u8);
115115}
116116
117117test "empty array to slice" {
118118 const S = struct {
119 fn doTheTest() void {
119 fn doTheTest() !void {
120120 const empty: []align(16) u8 = &[_]u8{};
121121 const align_1: []align(1) u8 = empty;
122122 const align_4: []align(4) u8 = empty;
123123 const align_16: []align(16) u8 = empty;
124 expectEqual(1, @typeInfo(@TypeOf(align_1)).Pointer.alignment);
125 expectEqual(4, @typeInfo(@TypeOf(align_4)).Pointer.alignment);
126 expectEqual(16, @typeInfo(@TypeOf(align_16)).Pointer.alignment);
124 try expectEqual(1, @typeInfo(@TypeOf(align_1)).Pointer.alignment);
125 try expectEqual(4, @typeInfo(@TypeOf(align_4)).Pointer.alignment);
126 try expectEqual(16, @typeInfo(@TypeOf(align_16)).Pointer.alignment);
127127 }
128128 };
129129
130 S.doTheTest();
131 comptime S.doTheTest();
130 try S.doTheTest();
131 comptime try S.doTheTest();
132132}
133133
134134test "@ptrCast slice to pointer" {
135135 const S = struct {
136 fn doTheTest() void {
136 fn doTheTest() !void {
137137 var array align(@alignOf(u16)) = [5]u8{ 0xff, 0xff, 0xff, 0xff, 0xff };
138138 var slice: []u8 = &array;
139139 var ptr = @ptrCast(*u16, slice);
140 expect(ptr.* == 65535);
140 try expect(ptr.* == 65535);
141141 }
142142 };
143143
144 S.doTheTest();
145 comptime S.doTheTest();
144 try S.doTheTest();
145 comptime try S.doTheTest();
146146}
147147
148148test "slice syntax resulting in pointer-to-array" {
149149 const S = struct {
150 fn doTheTest() void {
151 testArray();
152 testArrayZ();
153 testArray0();
154 testArrayAlign();
155 testPointer();
156 testPointerZ();
157 testPointer0();
158 testPointerAlign();
159 testSlice();
160 testSliceZ();
161 testSlice0();
162 testSliceOpt();
163 testSliceAlign();
150 fn doTheTest() !void {
151 try testArray();
152 try testArrayZ();
153 try testArray0();
154 try testArrayAlign();
155 try testPointer();
156 try testPointerZ();
157 try testPointer0();
158 try testPointerAlign();
159 try testSlice();
160 try testSliceZ();
161 try testSlice0();
162 try testSliceOpt();
163 try testSliceAlign();
164164 }
165165
166 fn testArray() void {
166 fn testArray() !void {
167167 var array = [5]u8{ 1, 2, 3, 4, 5 };
168168 var slice = array[1..3];
169 comptime expect(@TypeOf(slice) == *[2]u8);
170 expect(slice[0] == 2);
171 expect(slice[1] == 3);
169 comptime try expect(@TypeOf(slice) == *[2]u8);
170 try expect(slice[0] == 2);
171 try expect(slice[1] == 3);
172172 }
173173
174 fn testArrayZ() void {
174 fn testArrayZ() !void {
175175 var array = [5:0]u8{ 1, 2, 3, 4, 5 };
176 comptime expect(@TypeOf(array[1..3]) == *[2]u8);
177 comptime expect(@TypeOf(array[1..5]) == *[4:0]u8);
178 comptime expect(@TypeOf(array[1..]) == *[4:0]u8);
179 comptime expect(@TypeOf(array[1..3 :4]) == *[2:4]u8);
176 comptime try expect(@TypeOf(array[1..3]) == *[2]u8);
177 comptime try expect(@TypeOf(array[1..5]) == *[4:0]u8);
178 comptime try expect(@TypeOf(array[1..]) == *[4:0]u8);
179 comptime try expect(@TypeOf(array[1..3 :4]) == *[2:4]u8);
180180 }
181181
182 fn testArray0() void {
182 fn testArray0() !void {
183183 {
184184 var array = [0]u8{};
185185 var slice = array[0..0];
186 comptime expect(@TypeOf(slice) == *[0]u8);
186 comptime try expect(@TypeOf(slice) == *[0]u8);
187187 }
188188 {
189189 var array = [0:0]u8{};
190190 var slice = array[0..0];
191 comptime expect(@TypeOf(slice) == *[0:0]u8);
192 expect(slice[0] == 0);
191 comptime try expect(@TypeOf(slice) == *[0:0]u8);
192 try expect(slice[0] == 0);
193193 }
194194 }
195195
196 fn testArrayAlign() void {
196 fn testArrayAlign() !void {
197197 var array align(4) = [5]u8{ 1, 2, 3, 4, 5 };
198198 var slice = array[4..5];
199 comptime expect(@TypeOf(slice) == *align(4) [1]u8);
200 expect(slice[0] == 5);
201 comptime expect(@TypeOf(array[0..2]) == *align(4) [2]u8);
199 comptime try expect(@TypeOf(slice) == *align(4) [1]u8);
200 try expect(slice[0] == 5);
201 comptime try expect(@TypeOf(array[0..2]) == *align(4) [2]u8);
202202 }
203203
204 fn testPointer() void {
204 fn testPointer() !void {
205205 var array = [5]u8{ 1, 2, 3, 4, 5 };
206206 var pointer: [*]u8 = &array;
207207 var slice = pointer[1..3];
208 comptime expect(@TypeOf(slice) == *[2]u8);
209 expect(slice[0] == 2);
210 expect(slice[1] == 3);
208 comptime try expect(@TypeOf(slice) == *[2]u8);
209 try expect(slice[0] == 2);
210 try expect(slice[1] == 3);
211211 }
212212
213 fn testPointerZ() void {
213 fn testPointerZ() !void {
214214 var array = [5:0]u8{ 1, 2, 3, 4, 5 };
215215 var pointer: [*:0]u8 = &array;
216 comptime expect(@TypeOf(pointer[1..3]) == *[2]u8);
217 comptime expect(@TypeOf(pointer[1..3 :4]) == *[2:4]u8);
216 comptime try expect(@TypeOf(pointer[1..3]) == *[2]u8);
217 comptime try expect(@TypeOf(pointer[1..3 :4]) == *[2:4]u8);
218218 }
219219
220 fn testPointer0() void {
220 fn testPointer0() !void {
221221 var pointer: [*]const u0 = &[1]u0{0};
222222 var slice = pointer[0..1];
223 comptime expect(@TypeOf(slice) == *const [1]u0);
224 expect(slice[0] == 0);
223 comptime try expect(@TypeOf(slice) == *const [1]u0);
224 try expect(slice[0] == 0);
225225 }
226226
227 fn testPointerAlign() void {
227 fn testPointerAlign() !void {
228228 var array align(4) = [5]u8{ 1, 2, 3, 4, 5 };
229229 var pointer: [*]align(4) u8 = &array;
230230 var slice = pointer[4..5];
231 comptime expect(@TypeOf(slice) == *align(4) [1]u8);
232 expect(slice[0] == 5);
233 comptime expect(@TypeOf(pointer[0..2]) == *align(4) [2]u8);
231 comptime try expect(@TypeOf(slice) == *align(4) [1]u8);
232 try expect(slice[0] == 5);
233 comptime try expect(@TypeOf(pointer[0..2]) == *align(4) [2]u8);
234234 }
235235
236 fn testSlice() void {
236 fn testSlice() !void {
237237 var array = [5]u8{ 1, 2, 3, 4, 5 };
238238 var src_slice: []u8 = &array;
239239 var slice = src_slice[1..3];
240 comptime expect(@TypeOf(slice) == *[2]u8);
241 expect(slice[0] == 2);
242 expect(slice[1] == 3);
240 comptime try expect(@TypeOf(slice) == *[2]u8);
241 try expect(slice[0] == 2);
242 try expect(slice[1] == 3);
243243 }
244244
245 fn testSliceZ() void {
245 fn testSliceZ() !void {
246246 var array = [5:0]u8{ 1, 2, 3, 4, 5 };
247247 var slice: [:0]u8 = &array;
248 comptime expect(@TypeOf(slice[1..3]) == *[2]u8);
249 comptime expect(@TypeOf(slice[1..]) == [:0]u8);
250 comptime expect(@TypeOf(slice[1..3 :4]) == *[2:4]u8);
248 comptime try expect(@TypeOf(slice[1..3]) == *[2]u8);
249 comptime try expect(@TypeOf(slice[1..]) == [:0]u8);
250 comptime try expect(@TypeOf(slice[1..3 :4]) == *[2:4]u8);
251251 }
252252
253 fn testSliceOpt() void {
253 fn testSliceOpt() !void {
254254 var array: [2]u8 = [2]u8{ 1, 2 };
255255 var slice: ?[]u8 = &array;
256 comptime expect(@TypeOf(&array, slice) == ?[]u8);
257 comptime expect(@TypeOf(slice.?[0..2]) == *[2]u8);
256 comptime try expect(@TypeOf(&array, slice) == ?[]u8);
257 comptime try expect(@TypeOf(slice.?[0..2]) == *[2]u8);
258258 }
259259
260 fn testSlice0() void {
260 fn testSlice0() !void {
261261 {
262262 var array = [0]u8{};
263263 var src_slice: []u8 = &array;
264264 var slice = src_slice[0..0];
265 comptime expect(@TypeOf(slice) == *[0]u8);
265 comptime try expect(@TypeOf(slice) == *[0]u8);
266266 }
267267 {
268268 var array = [0:0]u8{};
269269 var src_slice: [:0]u8 = &array;
270270 var slice = src_slice[0..0];
271 comptime expect(@TypeOf(slice) == *[0]u8);
271 comptime try expect(@TypeOf(slice) == *[0]u8);
272272 }
273273 }
274274
275 fn testSliceAlign() void {
275 fn testSliceAlign() !void {
276276 var array align(4) = [5]u8{ 1, 2, 3, 4, 5 };
277277 var src_slice: []align(4) u8 = &array;
278278 var slice = src_slice[4..5];
279 comptime expect(@TypeOf(slice) == *align(4) [1]u8);
280 expect(slice[0] == 5);
281 comptime expect(@TypeOf(src_slice[0..2]) == *align(4) [2]u8);
279 comptime try expect(@TypeOf(slice) == *align(4) [1]u8);
280 try expect(slice[0] == 5);
281 comptime try expect(@TypeOf(src_slice[0..2]) == *align(4) [2]u8);
282282 }
283283
284 fn testConcatStrLiterals() void {
285 expectEqualSlices("a"[0..] ++ "b"[0..], "ab");
286 expectEqualSlices("a"[0..:0] ++ "b"[0..:0], "ab");
284 fn testConcatStrLiterals() !void {
285 try expectEqualSlices("a"[0..] ++ "b"[0..], "ab");
286 try expectEqualSlices("a"[0.. :0] ++ "b"[0.. :0], "ab");
287287 }
288288 };
289289
290 S.doTheTest();
291 comptime S.doTheTest();
290 try S.doTheTest();
291 comptime try S.doTheTest();
292292}
293293
294294test "slice of hardcoded address to pointer" {
295295 const S = struct {
296 fn doTheTest() void {
296 fn doTheTest() !void {
297297 const pointer = @intToPtr([*]u8, 0x04)[0..2];
298 comptime expect(@TypeOf(pointer) == *[2]u8);
298 comptime try expect(@TypeOf(pointer) == *[2]u8);
299299 const slice: []const u8 = pointer;
300 expect(@ptrToInt(slice.ptr) == 4);
301 expect(slice.len == 2);
300 try expect(@ptrToInt(slice.ptr) == 4);
301 try expect(slice.len == 2);
302302 }
303303 };
304304
305 S.doTheTest();
305 try S.doTheTest();
306306}
307307
308308test "type coercion of pointer to anon struct literal to pointer to slice" {
309309 const S = struct {
310 const U = union{
310 const U = union {
311311 a: u32,
312312 b: bool,
313313 c: []const u8,
314314 };
315315
316 fn doTheTest() void {
316 fn doTheTest() !void {
317317 var x1: u8 = 42;
318318 const t1 = &.{ x1, 56, 54 };
319319 var slice1: []const u8 = t1;
320 expect(slice1.len == 3);
321 expect(slice1[0] == 42);
322 expect(slice1[1] == 56);
323 expect(slice1[2] == 54);
324
320 try expect(slice1.len == 3);
321 try expect(slice1[0] == 42);
322 try expect(slice1[1] == 56);
323 try expect(slice1[2] == 54);
324
325325 var x2: []const u8 = "hello";
326326 const t2 = &.{ x2, ", ", "world!" };
327327 // @compileLog(@TypeOf(t2));
328328 var slice2: []const []const u8 = t2;
329 expect(slice2.len == 3);
330 expect(mem.eql(u8, slice2[0], "hello"));
331 expect(mem.eql(u8, slice2[1], ", "));
332 expect(mem.eql(u8, slice2[2], "world!"));
329 try expect(slice2.len == 3);
330 try expect(mem.eql(u8, slice2[0], "hello"));
331 try expect(mem.eql(u8, slice2[1], ", "));
332 try expect(mem.eql(u8, slice2[2], "world!"));
333333 }
334334 };
335 // S.doTheTest();
336 comptime S.doTheTest();
335 // try S.doTheTest();
336 comptime try S.doTheTest();
337337}
test/behavior/src.zig+8-8
......@@ -2,16 +2,16 @@ const std = @import("std");
22const expect = std.testing.expect;
33
44test "@src" {
5 doTheTest();
5 try doTheTest();
66}
77
8fn doTheTest() void {
8fn doTheTest() !void {
99 const src = @src();
1010
11 expect(src.line == 9);
12 expect(src.column == 17);
13 expect(std.mem.endsWith(u8, src.fn_name, "doTheTest"));
14 expect(std.mem.endsWith(u8, src.file, "src.zig"));
15 expect(src.fn_name[src.fn_name.len] == 0);
16 expect(src.file[src.file.len] == 0);
11 try expect(src.line == 9);
12 try expect(src.column == 17);
13 try expect(std.mem.endsWith(u8, src.fn_name, "doTheTest"));
14 try expect(std.mem.endsWith(u8, src.file, "src.zig"));
15 try expect(src.fn_name[src.fn_name.len] == 0);
16 try expect(src.file[src.file.len] == 0);
1717}
test/behavior/struct.zig+191-190
......@@ -19,12 +19,12 @@ test "top level fields" {
1919 .top_level_field = 1234,
2020 };
2121 instance.top_level_field += 1;
22 expectEqual(@as(i32, 1235), instance.top_level_field);
22 try expectEqual(@as(i32, 1235), instance.top_level_field);
2323}
2424
2525test "call struct static method" {
2626 const result = StructWithNoFields.add(3, 4);
27 expect(result == 7);
27 try expect(result == 7);
2828}
2929
3030test "return empty struct instance" {
......@@ -37,7 +37,7 @@ fn returnEmptyStructInstance() StructWithNoFields {
3737const should_be_11 = StructWithNoFields.add(5, 6);
3838
3939test "invoke static method in global scope" {
40 expect(should_be_11 == 11);
40 try expect(should_be_11 == 11);
4141}
4242
4343test "void struct fields" {
......@@ -46,8 +46,8 @@ test "void struct fields" {
4646 .b = 1,
4747 .c = void{},
4848 };
49 expect(foo.b == 1);
50 expect(@sizeOf(VoidStructFieldsFoo) == 4);
49 try expect(foo.b == 1);
50 try expect(@sizeOf(VoidStructFieldsFoo) == 4);
5151}
5252const VoidStructFieldsFoo = struct {
5353 a: void,
......@@ -60,17 +60,17 @@ test "structs" {
6060 @memset(@ptrCast([*]u8, &foo), 0, @sizeOf(StructFoo));
6161 foo.a += 1;
6262 foo.b = foo.a == 1;
63 testFoo(foo);
63 try testFoo(foo);
6464 testMutation(&foo);
65 expect(foo.c == 100);
65 try expect(foo.c == 100);
6666}
6767const StructFoo = struct {
6868 a: i32,
6969 b: bool,
7070 c: f32,
7171};
72fn testFoo(foo: StructFoo) void {
73 expect(foo.b);
72fn testFoo(foo: StructFoo) !void {
73 try expect(foo.b);
7474}
7575fn testMutation(foo: *StructFoo) void {
7676 foo.c = 100;
......@@ -95,7 +95,7 @@ test "struct point to self" {
9595
9696 root.next = &node;
9797
98 expect(node.next.next.next.val.x == 1);
98 try expect(node.next.next.next.val.x == 1);
9999}
100100
101101test "struct byval assign" {
......@@ -104,14 +104,14 @@ test "struct byval assign" {
104104
105105 foo1.a = 1234;
106106 foo2.a = 0;
107 expect(foo2.a == 0);
107 try expect(foo2.a == 0);
108108 foo2 = foo1;
109 expect(foo2.a == 1234);
109 try expect(foo2.a == 1234);
110110}
111111
112112fn structInitializer() void {
113113 const val = Val{ .x = 42 };
114 expect(val.x == 42);
114 try expect(val.x == 42);
115115}
116116
117117test "fn call of struct field" {
......@@ -128,14 +128,14 @@ test "fn call of struct field" {
128128 }
129129 };
130130
131 expect(S.callStructField(Foo{ .ptr = S.aFunc }) == 13);
131 try expect(S.callStructField(Foo{ .ptr = S.aFunc }) == 13);
132132}
133133
134134test "store member function in variable" {
135135 const instance = MemberFnTestFoo{ .x = 1234 };
136136 const memberFn = MemberFnTestFoo.member;
137137 const result = memberFn(instance);
138 expect(result == 1234);
138 try expect(result == 1234);
139139}
140140const MemberFnTestFoo = struct {
141141 x: i32,
......@@ -147,12 +147,12 @@ const MemberFnTestFoo = struct {
147147test "call member function directly" {
148148 const instance = MemberFnTestFoo{ .x = 1234 };
149149 const result = MemberFnTestFoo.member(instance);
150 expect(result == 1234);
150 try expect(result == 1234);
151151}
152152
153153test "member functions" {
154154 const r = MemberFnRand{ .seed = 1234 };
155 expect(r.getSeed() == 1234);
155 try expect(r.getSeed() == 1234);
156156}
157157const MemberFnRand = struct {
158158 seed: u32,
......@@ -163,7 +163,7 @@ const MemberFnRand = struct {
163163
164164test "return struct byval from function" {
165165 const bar = makeBar(1234, 5678);
166 expect(bar.y == 5678);
166 try expect(bar.y == 5678);
167167}
168168const Bar = struct {
169169 x: i32,
......@@ -178,7 +178,7 @@ fn makeBar(x: i32, y: i32) Bar {
178178
179179test "empty struct method call" {
180180 const es = EmptyStruct{};
181 expect(es.method() == 1234);
181 try expect(es.method() == 1234);
182182}
183183const EmptyStruct = struct {
184184 fn method(es: *const EmptyStruct) i32 {
......@@ -195,7 +195,7 @@ fn testReturnEmptyStructFromFn() EmptyStruct2 {
195195}
196196
197197test "pass slice of empty struct to fn" {
198 expect(testPassSliceOfEmptyStructToFn(&[_]EmptyStruct2{EmptyStruct2{}}) == 1);
198 try expect(testPassSliceOfEmptyStructToFn(&[_]EmptyStruct2{EmptyStruct2{}}) == 1);
199199}
200200fn testPassSliceOfEmptyStructToFn(slice: []const EmptyStruct2) usize {
201201 return slice.len;
......@@ -213,7 +213,7 @@ test "packed struct" {
213213 };
214214 foo.y += 1;
215215 const four = foo.x + foo.y;
216 expect(four == 4);
216 try expect(four == 4);
217217}
218218
219219const BitField1 = packed struct {
......@@ -230,17 +230,17 @@ const bit_field_1 = BitField1{
230230
231231test "bit field access" {
232232 var data = bit_field_1;
233 expect(getA(&data) == 1);
234 expect(getB(&data) == 2);
235 expect(getC(&data) == 3);
236 comptime expect(@sizeOf(BitField1) == 1);
233 try expect(getA(&data) == 1);
234 try expect(getB(&data) == 2);
235 try expect(getC(&data) == 3);
236 comptime try expect(@sizeOf(BitField1) == 1);
237237
238238 data.b += 1;
239 expect(data.b == 3);
239 try expect(data.b == 3);
240240
241241 data.a += 1;
242 expect(data.a == 2);
243 expect(data.b == 3);
242 try expect(data.a == 2);
243 try expect(data.b == 3);
244244}
245245
246246fn getA(data: *const BitField1) u3 {
......@@ -267,11 +267,11 @@ const Foo96Bits = packed struct {
267267
268268test "packed struct 24bits" {
269269 comptime {
270 expect(@sizeOf(Foo24Bits) == 4);
270 try expect(@sizeOf(Foo24Bits) == 4);
271271 if (@sizeOf(usize) == 4) {
272 expect(@sizeOf(Foo96Bits) == 12);
272 try expect(@sizeOf(Foo96Bits) == 12);
273273 } else {
274 expect(@sizeOf(Foo96Bits) == 16);
274 try expect(@sizeOf(Foo96Bits) == 16);
275275 }
276276 }
277277
......@@ -282,28 +282,28 @@ test "packed struct 24bits" {
282282 .d = 0,
283283 };
284284 value.a += 1;
285 expect(value.a == 1);
286 expect(value.b == 0);
287 expect(value.c == 0);
288 expect(value.d == 0);
285 try expect(value.a == 1);
286 try expect(value.b == 0);
287 try expect(value.c == 0);
288 try expect(value.d == 0);
289289
290290 value.b += 1;
291 expect(value.a == 1);
292 expect(value.b == 1);
293 expect(value.c == 0);
294 expect(value.d == 0);
291 try expect(value.a == 1);
292 try expect(value.b == 1);
293 try expect(value.c == 0);
294 try expect(value.d == 0);
295295
296296 value.c += 1;
297 expect(value.a == 1);
298 expect(value.b == 1);
299 expect(value.c == 1);
300 expect(value.d == 0);
297 try expect(value.a == 1);
298 try expect(value.b == 1);
299 try expect(value.c == 1);
300 try expect(value.d == 0);
301301
302302 value.d += 1;
303 expect(value.a == 1);
304 expect(value.b == 1);
305 expect(value.c == 1);
306 expect(value.d == 1);
303 try expect(value.a == 1);
304 try expect(value.b == 1);
305 try expect(value.c == 1);
306 try expect(value.d == 1);
307307}
308308
309309const Foo32Bits = packed struct {
......@@ -320,43 +320,43 @@ const FooArray24Bits = packed struct {
320320// TODO revisit this test when doing https://github.com/ziglang/zig/issues/1512
321321test "packed array 24bits" {
322322 comptime {
323 expect(@sizeOf([9]Foo32Bits) == 9 * 4);
324 expect(@sizeOf(FooArray24Bits) == 2 + 2 * 4 + 2);
323 try expect(@sizeOf([9]Foo32Bits) == 9 * 4);
324 try expect(@sizeOf(FooArray24Bits) == 2 + 2 * 4 + 2);
325325 }
326326
327327 var bytes = [_]u8{0} ** (@sizeOf(FooArray24Bits) + 1);
328328 bytes[bytes.len - 1] = 0xaa;
329329 const ptr = &std.mem.bytesAsSlice(FooArray24Bits, bytes[0 .. bytes.len - 1])[0];
330 expect(ptr.a == 0);
331 expect(ptr.b[0].field == 0);
332 expect(ptr.b[1].field == 0);
333 expect(ptr.c == 0);
330 try expect(ptr.a == 0);
331 try expect(ptr.b[0].field == 0);
332 try expect(ptr.b[1].field == 0);
333 try expect(ptr.c == 0);
334334
335335 ptr.a = maxInt(u16);
336 expect(ptr.a == maxInt(u16));
337 expect(ptr.b[0].field == 0);
338 expect(ptr.b[1].field == 0);
339 expect(ptr.c == 0);
336 try expect(ptr.a == maxInt(u16));
337 try expect(ptr.b[0].field == 0);
338 try expect(ptr.b[1].field == 0);
339 try expect(ptr.c == 0);
340340
341341 ptr.b[0].field = maxInt(u24);
342 expect(ptr.a == maxInt(u16));
343 expect(ptr.b[0].field == maxInt(u24));
344 expect(ptr.b[1].field == 0);
345 expect(ptr.c == 0);
342 try expect(ptr.a == maxInt(u16));
343 try expect(ptr.b[0].field == maxInt(u24));
344 try expect(ptr.b[1].field == 0);
345 try expect(ptr.c == 0);
346346
347347 ptr.b[1].field = maxInt(u24);
348 expect(ptr.a == maxInt(u16));
349 expect(ptr.b[0].field == maxInt(u24));
350 expect(ptr.b[1].field == maxInt(u24));
351 expect(ptr.c == 0);
348 try expect(ptr.a == maxInt(u16));
349 try expect(ptr.b[0].field == maxInt(u24));
350 try expect(ptr.b[1].field == maxInt(u24));
351 try expect(ptr.c == 0);
352352
353353 ptr.c = maxInt(u16);
354 expect(ptr.a == maxInt(u16));
355 expect(ptr.b[0].field == maxInt(u24));
356 expect(ptr.b[1].field == maxInt(u24));
357 expect(ptr.c == maxInt(u16));
354 try expect(ptr.a == maxInt(u16));
355 try expect(ptr.b[0].field == maxInt(u24));
356 try expect(ptr.b[1].field == maxInt(u24));
357 try expect(ptr.c == maxInt(u16));
358358
359 expect(bytes[bytes.len - 1] == 0xaa);
359 try expect(bytes[bytes.len - 1] == 0xaa);
360360}
361361
362362const FooStructAligned = packed struct {
......@@ -370,17 +370,17 @@ const FooArrayOfAligned = packed struct {
370370
371371test "aligned array of packed struct" {
372372 comptime {
373 expect(@sizeOf(FooStructAligned) == 2);
374 expect(@sizeOf(FooArrayOfAligned) == 2 * 2);
373 try expect(@sizeOf(FooStructAligned) == 2);
374 try expect(@sizeOf(FooArrayOfAligned) == 2 * 2);
375375 }
376376
377377 var bytes = [_]u8{0xbb} ** @sizeOf(FooArrayOfAligned);
378378 const ptr = &std.mem.bytesAsSlice(FooArrayOfAligned, bytes[0..])[0];
379379
380 expect(ptr.a[0].a == 0xbb);
381 expect(ptr.a[0].b == 0xbb);
382 expect(ptr.a[1].a == 0xbb);
383 expect(ptr.a[1].b == 0xbb);
380 try expect(ptr.a[0].a == 0xbb);
381 try expect(ptr.a[0].b == 0xbb);
382 try expect(ptr.a[1].a == 0xbb);
383 try expect(ptr.a[1].b == 0xbb);
384384}
385385
386386test "runtime struct initialization of bitfield" {
......@@ -393,10 +393,10 @@ test "runtime struct initialization of bitfield" {
393393 .y = @intCast(u4, x2),
394394 };
395395
396 expect(s1.x == x1);
397 expect(s1.y == x1);
398 expect(s2.x == @intCast(u4, x2));
399 expect(s2.y == @intCast(u4, x2));
396 try expect(s1.x == x1);
397 try expect(s1.y == x1);
398 try expect(s2.x == @intCast(u4, x2));
399 try expect(s2.y == @intCast(u4, x2));
400400}
401401
402402var x1 = @as(u4, 1);
......@@ -426,18 +426,18 @@ test "native bit field understands endianness" {
426426 @memcpy(&bytes, @ptrCast([*]u8, &all), 8);
427427 var bitfields = @ptrCast(*Bitfields, &bytes).*;
428428
429 expect(bitfields.f1 == 0x1111);
430 expect(bitfields.f2 == 0x2222);
431 expect(bitfields.f3 == 0x33);
432 expect(bitfields.f4 == 0x44);
433 expect(bitfields.f5 == 0x5);
434 expect(bitfields.f6 == 0x6);
435 expect(bitfields.f7 == 0x77);
429 try expect(bitfields.f1 == 0x1111);
430 try expect(bitfields.f2 == 0x2222);
431 try expect(bitfields.f3 == 0x33);
432 try expect(bitfields.f4 == 0x44);
433 try expect(bitfields.f5 == 0x5);
434 try expect(bitfields.f6 == 0x6);
435 try expect(bitfields.f7 == 0x77);
436436}
437437
438438test "align 1 field before self referential align 8 field as slice return type" {
439439 const result = alloc(Expr);
440 expect(result.len == 0);
440 try expect(result.len == 0);
441441}
442442
443443const Expr = union(enum) {
......@@ -460,10 +460,10 @@ test "call method with mutable reference to struct with no fields" {
460460 };
461461
462462 var s = S{};
463 expect(S.doC(&s));
464 expect(s.doC());
465 expect(S.do(&s));
466 expect(s.do());
463 try expect(S.doC(&s));
464 try expect(s.doC());
465 try expect(S.do(&s));
466 try expect(s.do());
467467}
468468
469469test "implicit cast packed struct field to const ptr" {
......@@ -479,7 +479,7 @@ test "implicit cast packed struct field to const ptr" {
479479 var lup: LevelUpMove = undefined;
480480 lup.level = 12;
481481 const res = LevelUpMove.toInt(lup.level);
482 expect(res == 12);
482 try expect(res == 12);
483483}
484484
485485test "pointer to packed struct member in a stack variable" {
......@@ -490,9 +490,9 @@ test "pointer to packed struct member in a stack variable" {
490490
491491 var s = S{ .a = 2, .b = 0 };
492492 var b_ptr = &s.b;
493 expect(s.b == 0);
493 try expect(s.b == 0);
494494 b_ptr.* = 2;
495 expect(s.b == 2);
495 try expect(s.b == 2);
496496}
497497
498498test "non-byte-aligned array inside packed struct" {
......@@ -501,20 +501,20 @@ test "non-byte-aligned array inside packed struct" {
501501 b: [0x16]u8,
502502 };
503503 const S = struct {
504 fn bar(slice: []const u8) void {
505 expectEqualSlices(u8, slice, "abcdefghijklmnopqurstu");
504 fn bar(slice: []const u8) !void {
505 try expectEqualSlices(u8, slice, "abcdefghijklmnopqurstu");
506506 }
507 fn doTheTest() void {
507 fn doTheTest() !void {
508508 var foo = Foo{
509509 .a = true,
510510 .b = "abcdefghijklmnopqurstu".*,
511511 };
512512 const value = foo.b;
513 bar(&value);
513 try bar(&value);
514514 }
515515 };
516 S.doTheTest();
517 comptime S.doTheTest();
516 try S.doTheTest();
517 comptime try S.doTheTest();
518518}
519519
520520test "packed struct with u0 field access" {
......@@ -522,7 +522,7 @@ test "packed struct with u0 field access" {
522522 f0: u0,
523523 };
524524 var s = S{ .f0 = 0 };
525 comptime expect(s.f0 == 0);
525 comptime try expect(s.f0 == 0);
526526}
527527
528528const S0 = struct {
......@@ -541,7 +541,7 @@ var g_foo: S0 = S0.init();
541541
542542test "access to global struct fields" {
543543 g_foo.bar.value = 42;
544 expect(g_foo.bar.value == 42);
544 try expect(g_foo.bar.value == 42);
545545}
546546
547547test "packed struct with fp fields" {
......@@ -560,9 +560,9 @@ test "packed struct with fp fields" {
560560 s.data[1] = 2.0;
561561 s.data[2] = 3.0;
562562 s.frob();
563 expectEqual(@as(f32, 6.0), s.data[0]);
564 expectEqual(@as(f32, 11.0), s.data[1]);
565 expectEqual(@as(f32, 20.0), s.data[2]);
563 try expectEqual(@as(f32, 6.0), s.data[0]);
564 try expectEqual(@as(f32, 11.0), s.data[1]);
565 try expectEqual(@as(f32, 20.0), s.data[2]);
566566}
567567
568568test "use within struct scope" {
......@@ -573,7 +573,7 @@ test "use within struct scope" {
573573 }
574574 };
575575 };
576 expectEqual(@as(i32, 42), S.inner());
576 try expectEqual(@as(i32, 42), S.inner());
577577}
578578
579579test "default struct initialization fields" {
......@@ -591,14 +591,14 @@ test "default struct initialization fields" {
591591 const y = S{
592592 .b = five,
593593 };
594 expectEqual(1239, x.a + x.b);
594 try expectEqual(1239, x.a + x.b);
595595}
596596
597597test "fn with C calling convention returns struct by value" {
598598 const S = struct {
599 fn entry() void {
599 fn entry() !void {
600600 var x = makeBar(10);
601 expectEqual(@as(i32, 10), x.handle);
601 try expectEqual(@as(i32, 10), x.handle);
602602 }
603603
604604 const ExternBar = extern struct {
......@@ -611,8 +611,8 @@ test "fn with C calling convention returns struct by value" {
611611 };
612612 }
613613 };
614 S.entry();
615 comptime S.entry();
614 try S.entry();
615 comptime try S.entry();
616616}
617617
618618test "for loop over pointers to struct, getting field from struct pointer" {
......@@ -633,7 +633,7 @@ test "for loop over pointers to struct, getting field from struct pointer" {
633633 }
634634 };
635635
636 fn doTheTest() void {
636 fn doTheTest() !void {
637637 var objects: ArrayList = undefined;
638638
639639 for (objects.toSlice()) |obj| {
......@@ -642,10 +642,10 @@ test "for loop over pointers to struct, getting field from struct pointer" {
642642 }
643643 }
644644
645 expect(ok);
645 try expect(ok);
646646 }
647647 };
648 S.doTheTest();
648 try S.doTheTest();
649649}
650650
651651test "zero-bit field in packed struct" {
......@@ -658,20 +658,20 @@ test "zero-bit field in packed struct" {
658658
659659test "struct field init with catch" {
660660 const S = struct {
661 fn doTheTest() void {
661 fn doTheTest() !void {
662662 var x: anyerror!isize = 1;
663663 var req = Foo{
664664 .field = x catch undefined,
665665 };
666 expect(req.field == 1);
666 try expect(req.field == 1);
667667 }
668668
669669 pub const Foo = extern struct {
670670 field: isize,
671671 };
672672 };
673 S.doTheTest();
674 comptime S.doTheTest();
673 try S.doTheTest();
674 comptime try S.doTheTest();
675675}
676676
677677test "packed struct with non-ABI-aligned field" {
......@@ -682,8 +682,8 @@ test "packed struct with non-ABI-aligned field" {
682682 var s: S = undefined;
683683 s.x = 1;
684684 s.y = 42;
685 expect(s.x == 1);
686 expect(s.y == 42);
685 try expect(s.x == 1);
686 try expect(s.y == 42);
687687}
688688
689689test "non-packed struct with u128 entry in union" {
......@@ -699,10 +699,10 @@ test "non-packed struct with u128 entry in union" {
699699
700700 var sx: S = undefined;
701701 var s = &sx;
702 std.testing.expect(@ptrToInt(&s.f2) - @ptrToInt(&s.f1) == @byteOffsetOf(S, "f2"));
702 try std.testing.expect(@ptrToInt(&s.f2) - @ptrToInt(&s.f1) == @byteOffsetOf(S, "f2"));
703703 var v2 = U{ .Num = 123 };
704704 s.f2 = v2;
705 std.testing.expect(s.f2.Num == 123);
705 try std.testing.expect(s.f2.Num == 123);
706706}
707707
708708test "packed struct field passed to generic function" {
......@@ -722,7 +722,7 @@ test "packed struct field passed to generic function" {
722722 var p: S.P = undefined;
723723 p.b = 29;
724724 var loaded = S.genericReadPackedField(&p.b);
725 expect(loaded == 29);
725 try expect(loaded == 29);
726726}
727727
728728test "anonymous struct literal syntax" {
......@@ -732,63 +732,63 @@ test "anonymous struct literal syntax" {
732732 y: i32,
733733 };
734734
735 fn doTheTest() void {
735 fn doTheTest() !void {
736736 var p: Point = .{
737737 .x = 1,
738738 .y = 2,
739739 };
740 expect(p.x == 1);
741 expect(p.y == 2);
740 try expect(p.x == 1);
741 try expect(p.y == 2);
742742 }
743743 };
744 S.doTheTest();
745 comptime S.doTheTest();
744 try S.doTheTest();
745 comptime try S.doTheTest();
746746}
747747
748748test "fully anonymous struct" {
749749 const S = struct {
750 fn doTheTest() void {
751 dump(.{
750 fn doTheTest() !void {
751 try dump(.{
752752 .int = @as(u32, 1234),
753753 .float = @as(f64, 12.34),
754754 .b = true,
755755 .s = "hi",
756756 });
757757 }
758 fn dump(args: anytype) void {
759 expect(args.int == 1234);
760 expect(args.float == 12.34);
761 expect(args.b);
762 expect(args.s[0] == 'h');
763 expect(args.s[1] == 'i');
758 fn dump(args: anytype) !void {
759 try expect(args.int == 1234);
760 try expect(args.float == 12.34);
761 try expect(args.b);
762 try expect(args.s[0] == 'h');
763 try expect(args.s[1] == 'i');
764764 }
765765 };
766 S.doTheTest();
767 comptime S.doTheTest();
766 try S.doTheTest();
767 comptime try S.doTheTest();
768768}
769769
770770test "fully anonymous list literal" {
771771 const S = struct {
772 fn doTheTest() void {
773 dump(.{ @as(u32, 1234), @as(f64, 12.34), true, "hi" });
772 fn doTheTest() !void {
773 try dump(.{ @as(u32, 1234), @as(f64, 12.34), true, "hi" });
774774 }
775 fn dump(args: anytype) void {
776 expect(args.@"0" == 1234);
777 expect(args.@"1" == 12.34);
778 expect(args.@"2");
779 expect(args.@"3"[0] == 'h');
780 expect(args.@"3"[1] == 'i');
775 fn dump(args: anytype) !void {
776 try expect(args.@"0" == 1234);
777 try expect(args.@"1" == 12.34);
778 try expect(args.@"2");
779 try expect(args.@"3"[0] == 'h');
780 try expect(args.@"3"[1] == 'i');
781781 }
782782 };
783 S.doTheTest();
784 comptime S.doTheTest();
783 try S.doTheTest();
784 comptime try S.doTheTest();
785785}
786786
787787test "anonymous struct literal assigned to variable" {
788788 var vec = .{ @as(i32, 22), @as(i32, 55), @as(i32, 99) };
789 expect(vec.@"0" == 22);
790 expect(vec.@"1" == 55);
791 expect(vec.@"2" == 99);
789 try expect(vec.@"0" == 22);
790 try expect(vec.@"1" == 55);
791 try expect(vec.@"2" == 99);
792792}
793793
794794test "struct with var field" {
......@@ -800,8 +800,8 @@ test "struct with var field" {
800800 .x = 1,
801801 .y = 2,
802802 };
803 expect(pt.x == 1);
804 expect(pt.y == 2);
803 try expect(pt.x == 1);
804 try expect(pt.y == 2);
805805}
806806
807807test "comptime struct field" {
......@@ -811,21 +811,21 @@ test "comptime struct field" {
811811 };
812812
813813 var foo: T = undefined;
814 comptime expect(foo.b == 1234);
814 comptime try expect(foo.b == 1234);
815815}
816816
817817test "anon struct literal field value initialized with fn call" {
818818 const S = struct {
819 fn doTheTest() void {
819 fn doTheTest() !void {
820820 var x = .{foo()};
821 expectEqualSlices(u8, x[0], "hi");
821 try expectEqualSlices(u8, x[0], "hi");
822822 }
823823 fn foo() []const u8 {
824824 return "hi";
825825 }
826826 };
827 S.doTheTest();
828 comptime S.doTheTest();
827 try S.doTheTest();
828 comptime try S.doTheTest();
829829}
830830
831831test "self-referencing struct via array member" {
......@@ -834,7 +834,7 @@ test "self-referencing struct via array member" {
834834 };
835835 var x: T = undefined;
836836 x = T{ .children = .{&x} };
837 expect(x.children[0] == &x);
837 try expect(x.children[0] == &x);
838838}
839839
840840test "struct with union field" {
......@@ -849,8 +849,8 @@ test "struct with union field" {
849849 var True = Value{
850850 .kind = .{ .Bool = true },
851851 };
852 expectEqual(@as(u32, 2), True.ref);
853 expectEqual(true, True.kind.Bool);
852 try expectEqual(@as(u32, 2), True.ref);
853 try expectEqual(true, True.kind.Bool);
854854}
855855
856856test "type coercion of anon struct literal to struct" {
......@@ -866,24 +866,24 @@ test "type coercion of anon struct literal to struct" {
866866 field: i32 = 1234,
867867 };
868868
869 fn doTheTest() void {
869 fn doTheTest() !void {
870870 var y: u32 = 42;
871871 const t0 = .{ .A = 123, .B = "foo", .C = {} };
872872 const t1 = .{ .A = y, .B = "foo", .C = {} };
873873 const y0: S2 = t0;
874874 var y1: S2 = t1;
875 expect(y0.A == 123);
876 expect(std.mem.eql(u8, y0.B, "foo"));
877 expect(y0.C == {});
878 expect(y0.D.field == 1234);
879 expect(y1.A == y);
880 expect(std.mem.eql(u8, y1.B, "foo"));
881 expect(y1.C == {});
882 expect(y1.D.field == 1234);
875 try expect(y0.A == 123);
876 try expect(std.mem.eql(u8, y0.B, "foo"));
877 try expect(y0.C == {});
878 try expect(y0.D.field == 1234);
879 try expect(y1.A == y);
880 try expect(std.mem.eql(u8, y1.B, "foo"));
881 try expect(y1.C == {});
882 try expect(y1.D.field == 1234);
883883 }
884884 };
885 S.doTheTest();
886 comptime S.doTheTest();
885 try S.doTheTest();
886 comptime try S.doTheTest();
887887}
888888
889889test "type coercion of pointer to anon struct literal to pointer to struct" {
......@@ -899,24 +899,24 @@ test "type coercion of pointer to anon struct literal to pointer to struct" {
899899 field: i32 = 1234,
900900 };
901901
902 fn doTheTest() void {
902 fn doTheTest() !void {
903903 var y: u32 = 42;
904904 const t0 = &.{ .A = 123, .B = "foo", .C = {} };
905905 const t1 = &.{ .A = y, .B = "foo", .C = {} };
906906 const y0: *const S2 = t0;
907907 var y1: *const S2 = t1;
908 expect(y0.A == 123);
909 expect(std.mem.eql(u8, y0.B, "foo"));
910 expect(y0.C == {});
911 expect(y0.D.field == 1234);
912 expect(y1.A == y);
913 expect(std.mem.eql(u8, y1.B, "foo"));
914 expect(y1.C == {});
915 expect(y1.D.field == 1234);
908 try expect(y0.A == 123);
909 try expect(std.mem.eql(u8, y0.B, "foo"));
910 try expect(y0.C == {});
911 try expect(y0.D.field == 1234);
912 try expect(y1.A == y);
913 try expect(std.mem.eql(u8, y1.B, "foo"));
914 try expect(y1.C == {});
915 try expect(y1.D.field == 1234);
916916 }
917917 };
918 S.doTheTest();
919 comptime S.doTheTest();
918 try S.doTheTest();
919 comptime try S.doTheTest();
920920}
921921
922922test "packed struct with undefined initializers" {
......@@ -930,16 +930,17 @@ test "packed struct with undefined initializers" {
930930 _c: u3 = undefined,
931931 };
932932
933 fn doTheTest() void {
933 fn doTheTest() !void {
934934 var p: P = undefined;
935935 p = P{ .a = 2, .b = 4, .c = 6 };
936936 // Make sure the compiler doesn't touch the unprefixed fields.
937 expectEqual(@as(u3, 2), p.a);
938 expectEqual(@as(u3, 4), p.b);
939 expectEqual(@as(u3, 6), p.c);
937 // Use expect since i386-linux doesn't like expectEqual
938 try expect(p.a == 2);
939 try expect(p.b == 4);
940 try expect(p.c == 6);
940941 }
941942 };
942943
943 S.doTheTest();
944 comptime S.doTheTest();
944 try S.doTheTest();
945 comptime try S.doTheTest();
945946}
test/behavior/struct_contains_null_ptr_itself.zig+1-1
......@@ -3,7 +3,7 @@ const expect = std.testing.expect;
33
44test "struct contains null pointer which contains original struct" {
55 var x: ?*NodeLineComment = null;
6 expect(x == null);
6 try expect(x == null);
77}
88
99pub const Node = struct {
test/behavior/struct_contains_slice_of_itself.zig+12-12
......@@ -39,12 +39,12 @@ test "struct contains slice of itself" {
3939 .payload = 1234,
4040 .children = nodes[0..],
4141 };
42 expect(root.payload == 1234);
43 expect(root.children[0].payload == 1);
44 expect(root.children[1].payload == 2);
45 expect(root.children[2].payload == 3);
46 expect(root.children[2].children[0].payload == 31);
47 expect(root.children[2].children[1].payload == 32);
42 try expect(root.payload == 1234);
43 try expect(root.children[0].payload == 1);
44 try expect(root.children[1].payload == 2);
45 try expect(root.children[2].payload == 3);
46 try expect(root.children[2].children[0].payload == 31);
47 try expect(root.children[2].children[1].payload == 32);
4848}
4949
5050test "struct contains aligned slice of itself" {
......@@ -76,10 +76,10 @@ test "struct contains aligned slice of itself" {
7676 .payload = 1234,
7777 .children = nodes[0..],
7878 };
79 expect(root.payload == 1234);
80 expect(root.children[0].payload == 1);
81 expect(root.children[1].payload == 2);
82 expect(root.children[2].payload == 3);
83 expect(root.children[2].children[0].payload == 31);
84 expect(root.children[2].children[1].payload == 32);
79 try expect(root.payload == 1234);
80 try expect(root.children[0].payload == 1);
81 try expect(root.children[1].payload == 2);
82 try expect(root.children[2].payload == 3);
83 try expect(root.children[2].children[0].payload == 31);
84 try expect(root.children[2].children[1].payload == 32);
8585}
test/behavior/switch.zig+104-104
......@@ -4,23 +4,23 @@ const expectError = std.testing.expectError;
44const expectEqual = std.testing.expectEqual;
55
66test "switch with numbers" {
7 testSwitchWithNumbers(13);
7 try testSwitchWithNumbers(13);
88}
99
10fn testSwitchWithNumbers(x: u32) void {
10fn testSwitchWithNumbers(x: u32) !void {
1111 const result = switch (x) {
1212 1, 2, 3, 4...8 => false,
1313 13 => true,
1414 else => false,
1515 };
16 expect(result);
16 try expect(result);
1717}
1818
1919test "switch with all ranges" {
20 expect(testSwitchWithAllRanges(50, 3) == 1);
21 expect(testSwitchWithAllRanges(101, 0) == 2);
22 expect(testSwitchWithAllRanges(300, 5) == 3);
23 expect(testSwitchWithAllRanges(301, 6) == 6);
20 try expect(testSwitchWithAllRanges(50, 3) == 1);
21 try expect(testSwitchWithAllRanges(101, 0) == 2);
22 try expect(testSwitchWithAllRanges(300, 5) == 3);
23 try expect(testSwitchWithAllRanges(301, 6) == 6);
2424}
2525
2626fn testSwitchWithAllRanges(x: u32, y: u32) u32 {
......@@ -43,7 +43,7 @@ test "implicit comptime switch" {
4343 };
4444
4545 comptime {
46 expect(result + 1 == 14);
46 try expect(result + 1 == 14);
4747 }
4848}
4949
......@@ -65,16 +65,16 @@ fn nonConstSwitchOnEnum(fruit: Fruit) void {
6565}
6666
6767test "switch statement" {
68 nonConstSwitch(SwitchStatmentFoo.C);
68 try nonConstSwitch(SwitchStatmentFoo.C);
6969}
70fn nonConstSwitch(foo: SwitchStatmentFoo) void {
70fn nonConstSwitch(foo: SwitchStatmentFoo) !void {
7171 const val = switch (foo) {
7272 SwitchStatmentFoo.A => @as(i32, 1),
7373 SwitchStatmentFoo.B => 2,
7474 SwitchStatmentFoo.C => 3,
7575 SwitchStatmentFoo.D => 4,
7676 };
77 expect(val == 3);
77 try expect(val == 3);
7878}
7979const SwitchStatmentFoo = enum {
8080 A,
......@@ -84,22 +84,22 @@ const SwitchStatmentFoo = enum {
8484};
8585
8686test "switch prong with variable" {
87 switchProngWithVarFn(SwitchProngWithVarEnum{ .One = 13 });
88 switchProngWithVarFn(SwitchProngWithVarEnum{ .Two = 13.0 });
89 switchProngWithVarFn(SwitchProngWithVarEnum{ .Meh = {} });
87 try switchProngWithVarFn(SwitchProngWithVarEnum{ .One = 13 });
88 try switchProngWithVarFn(SwitchProngWithVarEnum{ .Two = 13.0 });
89 try switchProngWithVarFn(SwitchProngWithVarEnum{ .Meh = {} });
9090}
9191const SwitchProngWithVarEnum = union(enum) {
9292 One: i32,
9393 Two: f32,
9494 Meh: void,
9595};
96fn switchProngWithVarFn(a: SwitchProngWithVarEnum) void {
96fn switchProngWithVarFn(a: SwitchProngWithVarEnum) !void {
9797 switch (a) {
9898 SwitchProngWithVarEnum.One => |x| {
99 expect(x == 13);
99 try expect(x == 13);
100100 },
101101 SwitchProngWithVarEnum.Two => |x| {
102 expect(x == 13.0);
102 try expect(x == 13.0);
103103 },
104104 SwitchProngWithVarEnum.Meh => |x| {
105105 const v: void = x;
......@@ -108,18 +108,18 @@ fn switchProngWithVarFn(a: SwitchProngWithVarEnum) void {
108108}
109109
110110test "switch on enum using pointer capture" {
111 testSwitchEnumPtrCapture();
112 comptime testSwitchEnumPtrCapture();
111 try testSwitchEnumPtrCapture();
112 comptime try testSwitchEnumPtrCapture();
113113}
114114
115fn testSwitchEnumPtrCapture() void {
115fn testSwitchEnumPtrCapture() !void {
116116 var value = SwitchProngWithVarEnum{ .One = 1234 };
117117 switch (value) {
118118 SwitchProngWithVarEnum.One => |*x| x.* += 1,
119119 else => unreachable,
120120 }
121121 switch (value) {
122 SwitchProngWithVarEnum.One => |x| expect(x == 1235),
122 SwitchProngWithVarEnum.One => |x| try expect(x == 1235),
123123 else => unreachable,
124124 }
125125}
......@@ -130,7 +130,7 @@ test "switch with multiple expressions" {
130130 4, 5, 6 => 2,
131131 else => @as(i32, 3),
132132 };
133 expect(x == 2);
133 try expect(x == 2);
134134}
135135fn returnsFive() i32 {
136136 return 5;
......@@ -152,12 +152,12 @@ fn returnsFalse() bool {
152152 }
153153}
154154test "switch on const enum with var" {
155 expect(!returnsFalse());
155 try expect(!returnsFalse());
156156}
157157
158158test "switch on type" {
159 expect(trueIfBoolFalseOtherwise(bool));
160 expect(!trueIfBoolFalseOtherwise(i32));
159 try expect(trueIfBoolFalseOtherwise(bool));
160 try expect(!trueIfBoolFalseOtherwise(i32));
161161}
162162
163163fn trueIfBoolFalseOtherwise(comptime T: type) bool {
......@@ -168,21 +168,21 @@ fn trueIfBoolFalseOtherwise(comptime T: type) bool {
168168}
169169
170170test "switch handles all cases of number" {
171 testSwitchHandleAllCases();
172 comptime testSwitchHandleAllCases();
171 try testSwitchHandleAllCases();
172 comptime try testSwitchHandleAllCases();
173173}
174174
175fn testSwitchHandleAllCases() void {
176 expect(testSwitchHandleAllCasesExhaustive(0) == 3);
177 expect(testSwitchHandleAllCasesExhaustive(1) == 2);
178 expect(testSwitchHandleAllCasesExhaustive(2) == 1);
179 expect(testSwitchHandleAllCasesExhaustive(3) == 0);
175fn testSwitchHandleAllCases() !void {
176 try expect(testSwitchHandleAllCasesExhaustive(0) == 3);
177 try expect(testSwitchHandleAllCasesExhaustive(1) == 2);
178 try expect(testSwitchHandleAllCasesExhaustive(2) == 1);
179 try expect(testSwitchHandleAllCasesExhaustive(3) == 0);
180180
181 expect(testSwitchHandleAllCasesRange(100) == 0);
182 expect(testSwitchHandleAllCasesRange(200) == 1);
183 expect(testSwitchHandleAllCasesRange(201) == 2);
184 expect(testSwitchHandleAllCasesRange(202) == 4);
185 expect(testSwitchHandleAllCasesRange(230) == 3);
181 try expect(testSwitchHandleAllCasesRange(100) == 0);
182 try expect(testSwitchHandleAllCasesRange(200) == 1);
183 try expect(testSwitchHandleAllCasesRange(201) == 2);
184 try expect(testSwitchHandleAllCasesRange(202) == 4);
185 try expect(testSwitchHandleAllCasesRange(230) == 3);
186186}
187187
188188fn testSwitchHandleAllCasesExhaustive(x: u2) u2 {
......@@ -205,13 +205,13 @@ fn testSwitchHandleAllCasesRange(x: u8) u8 {
205205}
206206
207207test "switch all prongs unreachable" {
208 testAllProngsUnreachable();
209 comptime testAllProngsUnreachable();
208 try testAllProngsUnreachable();
209 comptime try testAllProngsUnreachable();
210210}
211211
212fn testAllProngsUnreachable() void {
213 expect(switchWithUnreachable(1) == 2);
214 expect(switchWithUnreachable(2) == 10);
212fn testAllProngsUnreachable() !void {
213 try expect(switchWithUnreachable(1) == 2);
214 try expect(switchWithUnreachable(2) == 10);
215215}
216216
217217fn switchWithUnreachable(x: i32) i32 {
......@@ -233,23 +233,23 @@ test "capture value of switch with all unreachable prongs" {
233233 const x = return_a_number() catch |err| switch (err) {
234234 else => unreachable,
235235 };
236 expect(x == 1);
236 try expect(x == 1);
237237}
238238
239239test "switching on booleans" {
240 testSwitchOnBools();
241 comptime testSwitchOnBools();
240 try testSwitchOnBools();
241 comptime try testSwitchOnBools();
242242}
243243
244fn testSwitchOnBools() void {
245 expect(testSwitchOnBoolsTrueAndFalse(true) == false);
246 expect(testSwitchOnBoolsTrueAndFalse(false) == true);
244fn testSwitchOnBools() !void {
245 try expect(testSwitchOnBoolsTrueAndFalse(true) == false);
246 try expect(testSwitchOnBoolsTrueAndFalse(false) == true);
247247
248 expect(testSwitchOnBoolsTrueWithElse(true) == false);
249 expect(testSwitchOnBoolsTrueWithElse(false) == true);
248 try expect(testSwitchOnBoolsTrueWithElse(true) == false);
249 try expect(testSwitchOnBoolsTrueWithElse(false) == true);
250250
251 expect(testSwitchOnBoolsFalseWithElse(true) == false);
252 expect(testSwitchOnBoolsFalseWithElse(false) == true);
251 try expect(testSwitchOnBoolsFalseWithElse(true) == false);
252 try expect(testSwitchOnBoolsFalseWithElse(false) == true);
253253}
254254
255255fn testSwitchOnBoolsTrueAndFalse(x: bool) bool {
......@@ -276,14 +276,14 @@ fn testSwitchOnBoolsFalseWithElse(x: bool) bool {
276276test "u0" {
277277 var val: u0 = 0;
278278 switch (val) {
279 0 => expect(val == 0),
279 0 => try expect(val == 0),
280280 }
281281}
282282
283283test "undefined.u0" {
284284 var val: u0 = undefined;
285285 switch (val) {
286 0 => expect(val == 0),
286 0 => try expect(val == 0),
287287 }
288288}
289289
......@@ -295,15 +295,15 @@ test "anon enum literal used in switch on union enum" {
295295 var foo = Foo{ .a = 1234 };
296296 switch (foo) {
297297 .a => |x| {
298 expect(x == 1234);
298 try expect(x == 1234);
299299 },
300300 }
301301}
302302
303303test "else prong of switch on error set excludes other cases" {
304304 const S = struct {
305 fn doTheTest() void {
306 expectError(error.C, bar());
305 fn doTheTest() !void {
306 try expectError(error.C, bar());
307307 }
308308 const E = error{
309309 A,
......@@ -326,14 +326,14 @@ test "else prong of switch on error set excludes other cases" {
326326 };
327327 }
328328 };
329 S.doTheTest();
330 comptime S.doTheTest();
329 try S.doTheTest();
330 comptime try S.doTheTest();
331331}
332332
333333test "switch prongs with error set cases make a new error set type for capture value" {
334334 const S = struct {
335 fn doTheTest() void {
336 expectError(error.B, bar());
335 fn doTheTest() !void {
336 try expectError(error.B, bar());
337337 }
338338 const E = E1 || E2;
339339
......@@ -358,14 +358,14 @@ test "switch prongs with error set cases make a new error set type for capture v
358358 };
359359 }
360360 };
361 S.doTheTest();
362 comptime S.doTheTest();
361 try S.doTheTest();
362 comptime try S.doTheTest();
363363}
364364
365365test "return result loc and then switch with range implicit casted to error union" {
366366 const S = struct {
367 fn doTheTest() void {
368 expect((func(0xb) catch unreachable) == 0xb);
367 fn doTheTest() !void {
368 try expect((func(0xb) catch unreachable) == 0xb);
369369 }
370370 fn func(d: u8) anyerror!u8 {
371371 return switch (d) {
......@@ -374,13 +374,13 @@ test "return result loc and then switch with range implicit casted to error unio
374374 };
375375 }
376376 };
377 S.doTheTest();
378 comptime S.doTheTest();
377 try S.doTheTest();
378 comptime try S.doTheTest();
379379}
380380
381381test "switch with null and T peer types and inferred result location type" {
382382 const S = struct {
383 fn doTheTest(c: u8) void {
383 fn doTheTest(c: u8) !void {
384384 if (switch (c) {
385385 0 => true,
386386 else => null,
......@@ -389,8 +389,8 @@ test "switch with null and T peer types and inferred result location type" {
389389 }
390390 }
391391 };
392 S.doTheTest(1);
393 comptime S.doTheTest(1);
392 try S.doTheTest(1);
393 comptime try S.doTheTest(1);
394394}
395395
396396test "switch prongs with cases with identical payload types" {
......@@ -400,31 +400,31 @@ test "switch prongs with cases with identical payload types" {
400400 C: usize,
401401 };
402402 const S = struct {
403 fn doTheTest() void {
404 doTheSwitch1(Union{ .A = 8 });
405 doTheSwitch2(Union{ .B = -8 });
403 fn doTheTest() !void {
404 try doTheSwitch1(Union{ .A = 8 });
405 try doTheSwitch2(Union{ .B = -8 });
406406 }
407 fn doTheSwitch1(u: Union) void {
407 fn doTheSwitch1(u: Union) !void {
408408 switch (u) {
409409 .A, .C => |e| {
410 expect(@TypeOf(e) == usize);
411 expect(e == 8);
410 try expect(@TypeOf(e) == usize);
411 try expect(e == 8);
412412 },
413413 .B => |e| @panic("fail"),
414414 }
415415 }
416 fn doTheSwitch2(u: Union) void {
416 fn doTheSwitch2(u: Union) !void {
417417 switch (u) {
418418 .A, .C => |e| @panic("fail"),
419419 .B => |e| {
420 expect(@TypeOf(e) == isize);
421 expect(e == -8);
420 try expect(@TypeOf(e) == isize);
421 try expect(e == -8);
422422 },
423423 }
424424 }
425425 };
426 S.doTheTest();
427 comptime S.doTheTest();
426 try S.doTheTest();
427 comptime try S.doTheTest();
428428}
429429
430430test "switch with disjoint range" {
......@@ -438,19 +438,19 @@ test "switch with disjoint range" {
438438
439439test "switch variable for range and multiple prongs" {
440440 const S = struct {
441 fn doTheTest() void {
441 fn doTheTest() !void {
442442 var u: u8 = 16;
443 doTheSwitch(u);
444 comptime doTheSwitch(u);
443 try doTheSwitch(u);
444 comptime try doTheSwitch(u);
445445 var v: u8 = 42;
446 doTheSwitch(v);
447 comptime doTheSwitch(v);
446 try doTheSwitch(v);
447 comptime try doTheSwitch(v);
448448 }
449 fn doTheSwitch(q: u8) void {
449 fn doTheSwitch(q: u8) !void {
450450 switch (q) {
451 0...40 => |x| expect(x == 16),
452 41, 42, 43 => |x| expect(x == 42),
453 else => expect(false),
451 0...40 => |x| try expect(x == 16),
452 41, 42, 43 => |x| try expect(x == 42),
453 else => try expect(false),
454454 }
455455 }
456456 };
......@@ -493,31 +493,31 @@ test "switch on pointer type" {
493493 }
494494 };
495495
496 expect(1 == S.doTheTest(S.P1));
497 expect(2 == S.doTheTest(S.P2));
498 expect(3 == S.doTheTest(S.P3));
499 comptime expect(1 == S.doTheTest(S.P1));
500 comptime expect(2 == S.doTheTest(S.P2));
501 comptime expect(3 == S.doTheTest(S.P3));
496 try expect(1 == S.doTheTest(S.P1));
497 try expect(2 == S.doTheTest(S.P2));
498 try expect(3 == S.doTheTest(S.P3));
499 comptime try expect(1 == S.doTheTest(S.P1));
500 comptime try expect(2 == S.doTheTest(S.P2));
501 comptime try expect(3 == S.doTheTest(S.P3));
502502}
503503
504504test "switch on error set with single else" {
505505 const S = struct {
506 fn doTheTest() void {
506 fn doTheTest() !void {
507507 var some: error{Foo} = error.Foo;
508 expect(switch (some) {
508 try expect(switch (some) {
509509 else => |a| true,
510510 });
511511 }
512512 };
513513
514 S.doTheTest();
515 comptime S.doTheTest();
514 try S.doTheTest();
515 comptime try S.doTheTest();
516516}
517517
518518test "while copies its payload" {
519519 const S = struct {
520 fn doTheTest() void {
520 fn doTheTest() !void {
521521 var tmp: union(enum) {
522522 A: u8,
523523 B: u32,
......@@ -526,12 +526,12 @@ test "while copies its payload" {
526526 .A => |value| {
527527 // Modify the original union
528528 tmp = .{ .B = 0x10101010 };
529 expectEqual(@as(u8, 42), value);
529 try expectEqual(@as(u8, 42), value);
530530 },
531531 else => unreachable,
532532 }
533533 }
534534 };
535 S.doTheTest();
536 comptime S.doTheTest();
535 try S.doTheTest();
536 comptime try S.doTheTest();
537537}
test/behavior/switch_prong_err_enum.zig+2-2
......@@ -22,9 +22,9 @@ fn doThing(form_id: u64) anyerror!FormValue {
2222test "switch prong returns error enum" {
2323 switch (doThing(17) catch unreachable) {
2424 FormValue.Address => |payload| {
25 expect(payload == 1);
25 try expect(payload == 1);
2626 },
2727 else => unreachable,
2828 }
29 expect(read_count == 1);
29 try expect(read_count == 1);
3030}
test/behavior/switch_prong_implicit_cast.zig+1-1
......@@ -18,5 +18,5 @@ test "switch prong implicit cast" {
1818 FormValue.One => false,
1919 FormValue.Two => |x| x,
2020 };
21 expect(result);
21 try expect(result);
2222}
test/behavior/this.zig+3-3
......@@ -20,7 +20,7 @@ fn add(x: i32, y: i32) i32 {
2020}
2121
2222test "this refer to module call private fn" {
23 expect(module.add(1, 2) == 3);
23 try expect(module.add(1, 2) == 3);
2424}
2525
2626test "this refer to container" {
......@@ -29,6 +29,6 @@ test "this refer to container" {
2929 .y = 34,
3030 };
3131 pt.addOne();
32 expect(pt.x == 13);
33 expect(pt.y == 35);
32 try expect(pt.x == 13);
33 try expect(pt.y == 35);
3434}
test/behavior/translate_c_macros.zig+4-4
......@@ -4,7 +4,7 @@ const expectEqual = @import("std").testing.expectEqual;
44const h = @cImport(@cInclude("behavior/translate_c_macros.h"));
55
66test "initializer list expression" {
7 expectEqual(h.Color{
7 try expectEqual(h.Color{
88 .r = 200,
99 .g = 200,
1010 .b = 200,
......@@ -13,10 +13,10 @@ test "initializer list expression" {
1313}
1414
1515test "sizeof in macros" {
16 expectEqual(@as(c_int, @sizeOf(u32)), h.MY_SIZEOF(u32));
17 expectEqual(@as(c_int, @sizeOf(u32)), h.MY_SIZEOF2(u32));
16 try expectEqual(@as(c_int, @sizeOf(u32)), h.MY_SIZEOF(u32));
17 try expectEqual(@as(c_int, @sizeOf(u32)), h.MY_SIZEOF2(u32));
1818}
1919
2020test "reference to a struct type" {
21 expectEqual(@sizeOf(h.struct_Foo), h.SIZE_OF_FOO);
21 try expectEqual(@sizeOf(h.struct_Foo), h.SIZE_OF_FOO);
2222}
test/behavior/truncate.zig+6-6
......@@ -4,33 +4,33 @@ const expect = std.testing.expect;
44test "truncate u0 to larger integer allowed and has comptime known result" {
55 var x: u0 = 0;
66 const y = @truncate(u8, x);
7 comptime expect(y == 0);
7 comptime try expect(y == 0);
88}
99
1010test "truncate.u0.literal" {
1111 var z = @truncate(u0, 0);
12 expect(z == 0);
12 try expect(z == 0);
1313}
1414
1515test "truncate.u0.const" {
1616 const c0: usize = 0;
1717 var z = @truncate(u0, c0);
18 expect(z == 0);
18 try expect(z == 0);
1919}
2020
2121test "truncate.u0.var" {
2222 var d: u8 = 2;
2323 var z = @truncate(u0, d);
24 expect(z == 0);
24 try expect(z == 0);
2525}
2626
2727test "truncate sign mismatch but comptime known so it works anyway" {
2828 const x: u32 = 10;
2929 var result = @truncate(i8, x);
30 expect(result == 10);
30 try expect(result == 10);
3131}
3232
3333test "truncate on comptime integer" {
3434 var x = @truncate(u16, 9999);
35 expect(x == 9999);
35 try expect(x == 9999);
3636}
test/behavior/try.zig+7-7
......@@ -1,17 +1,17 @@
11const expect = @import("std").testing.expect;
22
33test "try on error union" {
4 tryOnErrorUnionImpl();
5 comptime tryOnErrorUnionImpl();
4 try tryOnErrorUnionImpl();
5 comptime try tryOnErrorUnionImpl();
66}
77
8fn tryOnErrorUnionImpl() void {
8fn tryOnErrorUnionImpl() !void {
99 const x = if (returnsTen()) |val| val + 1 else |err| switch (err) {
1010 error.ItBroke, error.NoMem => 1,
1111 error.CrappedOut => @as(i32, 2),
1212 else => unreachable,
1313 };
14 expect(x == 11);
14 try expect(x == 11);
1515}
1616
1717fn returnsTen() anyerror!i32 {
......@@ -20,10 +20,10 @@ fn returnsTen() anyerror!i32 {
2020
2121test "try without vars" {
2222 const result1 = if (failIfTrue(true)) 1 else |_| @as(i32, 2);
23 expect(result1 == 2);
23 try expect(result1 == 2);
2424
2525 const result2 = if (failIfTrue(false)) 1 else |_| @as(i32, 2);
26 expect(result2 == 1);
26 try expect(result2 == 1);
2727}
2828
2929fn failIfTrue(ok: bool) anyerror!void {
......@@ -38,6 +38,6 @@ test "try then not executed with assignment" {
3838 if (failIfTrue(true)) {
3939 unreachable;
4040 } else |err| {
41 expect(err == error.ItBroke);
41 try expect(err == error.ItBroke);
4242 }
4343}
test/behavior/tuple.zig+44-44
......@@ -5,93 +5,93 @@ const expectEqual = testing.expectEqual;
55
66test "tuple concatenation" {
77 const S = struct {
8 fn doTheTest() void {
8 fn doTheTest() !void {
99 var a: i32 = 1;
1010 var b: i32 = 2;
1111 var x = .{a};
1212 var y = .{b};
1313 var c = x ++ y;
14 expectEqual(@as(i32, 1), c[0]);
15 expectEqual(@as(i32, 2), c[1]);
14 try expectEqual(@as(i32, 1), c[0]);
15 try expectEqual(@as(i32, 2), c[1]);
1616 }
1717 };
18 S.doTheTest();
19 comptime S.doTheTest();
18 try S.doTheTest();
19 comptime try S.doTheTest();
2020}
2121
2222test "tuple multiplication" {
2323 const S = struct {
24 fn doTheTest() void {
24 fn doTheTest() !void {
2525 {
2626 const t = .{} ** 4;
27 expectEqual(0, @typeInfo(@TypeOf(t)).Struct.fields.len);
27 try expectEqual(0, @typeInfo(@TypeOf(t)).Struct.fields.len);
2828 }
2929 {
3030 const t = .{'a'} ** 4;
31 expectEqual(4, @typeInfo(@TypeOf(t)).Struct.fields.len);
32 inline for (t) |x| expectEqual('a', x);
31 try expectEqual(4, @typeInfo(@TypeOf(t)).Struct.fields.len);
32 inline for (t) |x| try expectEqual('a', x);
3333 }
3434 {
3535 const t = .{ 1, 2, 3 } ** 4;
36 expectEqual(12, @typeInfo(@TypeOf(t)).Struct.fields.len);
37 inline for (t) |x, i| expectEqual(1 + i % 3, x);
36 try expectEqual(12, @typeInfo(@TypeOf(t)).Struct.fields.len);
37 inline for (t) |x, i| try expectEqual(1 + i % 3, x);
3838 }
3939 }
4040 };
41 S.doTheTest();
42 comptime S.doTheTest();
41 try S.doTheTest();
42 comptime try S.doTheTest();
4343
4444 const T = struct {
45 fn consume_tuple(tuple: anytype, len: usize) void {
46 expect(tuple.len == len);
45 fn consume_tuple(tuple: anytype, len: usize) !void {
46 try expect(tuple.len == len);
4747 }
4848
49 fn doTheTest() void {
49 fn doTheTest() !void {
5050 const t1 = .{};
5151
5252 var rt_var: u8 = 42;
5353 const t2 = .{rt_var} ++ .{};
5454
55 expect(t2.len == 1);
56 expect(t2.@"0" == rt_var);
57 expect(t2.@"0" == 42);
58 expect(&t2.@"0" != &rt_var);
55 try expect(t2.len == 1);
56 try expect(t2.@"0" == rt_var);
57 try expect(t2.@"0" == 42);
58 try expect(&t2.@"0" != &rt_var);
5959
60 consume_tuple(t1 ++ t1, 0);
61 consume_tuple(.{} ++ .{}, 0);
62 consume_tuple(.{0} ++ .{}, 1);
63 consume_tuple(.{0} ++ .{1}, 2);
64 consume_tuple(.{ 0, 1, 2 } ++ .{ u8, 1, noreturn }, 6);
65 consume_tuple(t2 ++ t1, 1);
66 consume_tuple(t1 ++ t2, 1);
67 consume_tuple(t2 ++ t2, 2);
68 consume_tuple(.{rt_var} ++ .{}, 1);
69 consume_tuple(.{rt_var} ++ t1, 1);
70 consume_tuple(.{} ++ .{rt_var}, 1);
71 consume_tuple(t2 ++ .{void}, 2);
72 consume_tuple(t2 ++ .{0}, 2);
73 consume_tuple(.{0} ++ t2, 2);
74 consume_tuple(.{void} ++ t2, 2);
75 consume_tuple(.{u8} ++ .{rt_var} ++ .{true}, 3);
60 try consume_tuple(t1 ++ t1, 0);
61 try consume_tuple(.{} ++ .{}, 0);
62 try consume_tuple(.{0} ++ .{}, 1);
63 try consume_tuple(.{0} ++ .{1}, 2);
64 try consume_tuple(.{ 0, 1, 2 } ++ .{ u8, 1, noreturn }, 6);
65 try consume_tuple(t2 ++ t1, 1);
66 try consume_tuple(t1 ++ t2, 1);
67 try consume_tuple(t2 ++ t2, 2);
68 try consume_tuple(.{rt_var} ++ .{}, 1);
69 try consume_tuple(.{rt_var} ++ t1, 1);
70 try consume_tuple(.{} ++ .{rt_var}, 1);
71 try consume_tuple(t2 ++ .{void}, 2);
72 try consume_tuple(t2 ++ .{0}, 2);
73 try consume_tuple(.{0} ++ t2, 2);
74 try consume_tuple(.{void} ++ t2, 2);
75 try consume_tuple(.{u8} ++ .{rt_var} ++ .{true}, 3);
7676 }
7777 };
7878
79 T.doTheTest();
80 comptime T.doTheTest();
79 try T.doTheTest();
80 comptime try T.doTheTest();
8181}
8282
8383test "pass tuple to comptime var parameter" {
8484 const S = struct {
85 fn Foo(comptime args: anytype) void {
86 expect(args[0] == 1);
85 fn Foo(comptime args: anytype) !void {
86 try expect(args[0] == 1);
8787 }
8888
89 fn doTheTest() void {
90 Foo(.{1});
89 fn doTheTest() !void {
90 try Foo(.{1});
9191 }
9292 };
93 S.doTheTest();
94 comptime S.doTheTest();
93 try S.doTheTest();
94 comptime try S.doTheTest();
9595}
9696
9797test "tuple initializer for var" {
test/behavior/type.zig+84-84
......@@ -3,52 +3,52 @@ const builtin = @import("builtin");
33const TypeInfo = std.builtin.TypeInfo;
44const testing = std.testing;
55
6fn testTypes(comptime types: []const type) void {
6fn testTypes(comptime types: []const type) !void {
77 inline for (types) |testType| {
8 testing.expect(testType == @Type(@typeInfo(testType)));
8 try testing.expect(testType == @Type(@typeInfo(testType)));
99 }
1010}
1111
1212test "Type.MetaType" {
13 testing.expect(type == @Type(TypeInfo{ .Type = undefined }));
14 testTypes(&[_]type{type});
13 try testing.expect(type == @Type(TypeInfo{ .Type = undefined }));
14 try testTypes(&[_]type{type});
1515}
1616
1717test "Type.Void" {
18 testing.expect(void == @Type(TypeInfo{ .Void = undefined }));
19 testTypes(&[_]type{void});
18 try testing.expect(void == @Type(TypeInfo{ .Void = undefined }));
19 try testTypes(&[_]type{void});
2020}
2121
2222test "Type.Bool" {
23 testing.expect(bool == @Type(TypeInfo{ .Bool = undefined }));
24 testTypes(&[_]type{bool});
23 try testing.expect(bool == @Type(TypeInfo{ .Bool = undefined }));
24 try testTypes(&[_]type{bool});
2525}
2626
2727test "Type.NoReturn" {
28 testing.expect(noreturn == @Type(TypeInfo{ .NoReturn = undefined }));
29 testTypes(&[_]type{noreturn});
28 try testing.expect(noreturn == @Type(TypeInfo{ .NoReturn = undefined }));
29 try testTypes(&[_]type{noreturn});
3030}
3131
3232test "Type.Int" {
33 testing.expect(u1 == @Type(TypeInfo{ .Int = TypeInfo.Int{ .signedness = .unsigned, .bits = 1 } }));
34 testing.expect(i1 == @Type(TypeInfo{ .Int = TypeInfo.Int{ .signedness = .signed, .bits = 1 } }));
35 testing.expect(u8 == @Type(TypeInfo{ .Int = TypeInfo.Int{ .signedness = .unsigned, .bits = 8 } }));
36 testing.expect(i8 == @Type(TypeInfo{ .Int = TypeInfo.Int{ .signedness = .signed, .bits = 8 } }));
37 testing.expect(u64 == @Type(TypeInfo{ .Int = TypeInfo.Int{ .signedness = .unsigned, .bits = 64 } }));
38 testing.expect(i64 == @Type(TypeInfo{ .Int = TypeInfo.Int{ .signedness = .signed, .bits = 64 } }));
39 testTypes(&[_]type{ u8, u32, i64 });
33 try testing.expect(u1 == @Type(TypeInfo{ .Int = TypeInfo.Int{ .signedness = .unsigned, .bits = 1 } }));
34 try testing.expect(i1 == @Type(TypeInfo{ .Int = TypeInfo.Int{ .signedness = .signed, .bits = 1 } }));
35 try testing.expect(u8 == @Type(TypeInfo{ .Int = TypeInfo.Int{ .signedness = .unsigned, .bits = 8 } }));
36 try testing.expect(i8 == @Type(TypeInfo{ .Int = TypeInfo.Int{ .signedness = .signed, .bits = 8 } }));
37 try testing.expect(u64 == @Type(TypeInfo{ .Int = TypeInfo.Int{ .signedness = .unsigned, .bits = 64 } }));
38 try testing.expect(i64 == @Type(TypeInfo{ .Int = TypeInfo.Int{ .signedness = .signed, .bits = 64 } }));
39 try testTypes(&[_]type{ u8, u32, i64 });
4040}
4141
4242test "Type.Float" {
43 testing.expect(f16 == @Type(TypeInfo{ .Float = TypeInfo.Float{ .bits = 16 } }));
44 testing.expect(f32 == @Type(TypeInfo{ .Float = TypeInfo.Float{ .bits = 32 } }));
45 testing.expect(f64 == @Type(TypeInfo{ .Float = TypeInfo.Float{ .bits = 64 } }));
46 testing.expect(f128 == @Type(TypeInfo{ .Float = TypeInfo.Float{ .bits = 128 } }));
47 testTypes(&[_]type{ f16, f32, f64, f128 });
43 try testing.expect(f16 == @Type(TypeInfo{ .Float = TypeInfo.Float{ .bits = 16 } }));
44 try testing.expect(f32 == @Type(TypeInfo{ .Float = TypeInfo.Float{ .bits = 32 } }));
45 try testing.expect(f64 == @Type(TypeInfo{ .Float = TypeInfo.Float{ .bits = 64 } }));
46 try testing.expect(f128 == @Type(TypeInfo{ .Float = TypeInfo.Float{ .bits = 128 } }));
47 try testTypes(&[_]type{ f16, f32, f64, f128 });
4848}
4949
5050test "Type.Pointer" {
51 testTypes(&[_]type{
51 try testTypes(&[_]type{
5252 // One Value Pointer Types
5353 *u8, *const u8,
5454 *volatile u8, *const volatile u8,
......@@ -93,41 +93,41 @@ test "Type.Pointer" {
9393}
9494
9595test "Type.Array" {
96 testing.expect([123]u8 == @Type(TypeInfo{
96 try testing.expect([123]u8 == @Type(TypeInfo{
9797 .Array = TypeInfo.Array{
9898 .len = 123,
9999 .child = u8,
100100 .sentinel = null,
101101 },
102102 }));
103 testing.expect([2]u32 == @Type(TypeInfo{
103 try testing.expect([2]u32 == @Type(TypeInfo{
104104 .Array = TypeInfo.Array{
105105 .len = 2,
106106 .child = u32,
107107 .sentinel = null,
108108 },
109109 }));
110 testing.expect([2:0]u32 == @Type(TypeInfo{
110 try testing.expect([2:0]u32 == @Type(TypeInfo{
111111 .Array = TypeInfo.Array{
112112 .len = 2,
113113 .child = u32,
114114 .sentinel = 0,
115115 },
116116 }));
117 testTypes(&[_]type{ [1]u8, [30]usize, [7]bool });
117 try testTypes(&[_]type{ [1]u8, [30]usize, [7]bool });
118118}
119119
120120test "Type.ComptimeFloat" {
121 testTypes(&[_]type{comptime_float});
121 try testTypes(&[_]type{comptime_float});
122122}
123123test "Type.ComptimeInt" {
124 testTypes(&[_]type{comptime_int});
124 try testTypes(&[_]type{comptime_int});
125125}
126126test "Type.Undefined" {
127 testTypes(&[_]type{@TypeOf(undefined)});
127 try testTypes(&[_]type{@TypeOf(undefined)});
128128}
129129test "Type.Null" {
130 testTypes(&[_]type{@TypeOf(null)});
130 try testTypes(&[_]type{@TypeOf(null)});
131131}
132132test "@Type create slice with null sentinel" {
133133 const Slice = @Type(TypeInfo{
......@@ -141,10 +141,10 @@ test "@Type create slice with null sentinel" {
141141 .sentinel = null,
142142 },
143143 });
144 testing.expect(Slice == []align(8) const *i32);
144 try testing.expect(Slice == []align(8) const *i32);
145145}
146146test "@Type picks up the sentinel value from TypeInfo" {
147 testTypes(&[_]type{
147 try testTypes(&[_]type{
148148 [11:0]u8, [4:10]u8,
149149 [*:0]u8, [*:0]const u8,
150150 [*:0]volatile u8, [*:0]const volatile u8,
......@@ -172,7 +172,7 @@ test "@Type picks up the sentinel value from TypeInfo" {
172172}
173173
174174test "Type.Optional" {
175 testTypes(&[_]type{
175 try testTypes(&[_]type{
176176 ?u8,
177177 ?*u8,
178178 ?[]u8,
......@@ -182,7 +182,7 @@ test "Type.Optional" {
182182}
183183
184184test "Type.ErrorUnion" {
185 testTypes(&[_]type{
185 try testTypes(&[_]type{
186186 error{}!void,
187187 error{Error}!void,
188188 });
......@@ -194,8 +194,8 @@ test "Type.Opaque" {
194194 .decls = &[_]TypeInfo.Declaration{},
195195 },
196196 });
197 testing.expect(Opaque != opaque {});
198 testing.expectEqualSlices(
197 try testing.expect(Opaque != opaque {});
198 try testing.expectEqualSlices(
199199 TypeInfo.Declaration,
200200 &[_]TypeInfo.Declaration{},
201201 @typeInfo(Opaque).Opaque.decls,
......@@ -203,7 +203,7 @@ test "Type.Opaque" {
203203}
204204
205205test "Type.Vector" {
206 testTypes(&[_]type{
206 try testTypes(&[_]type{
207207 @Vector(0, u8),
208208 @Vector(4, u8),
209209 @Vector(8, *u8),
......@@ -214,7 +214,7 @@ test "Type.Vector" {
214214}
215215
216216test "Type.AnyFrame" {
217 testTypes(&[_]type{
217 try testTypes(&[_]type{
218218 anyframe,
219219 anyframe->u8,
220220 anyframe->anyframe->u8,
......@@ -222,7 +222,7 @@ test "Type.AnyFrame" {
222222}
223223
224224test "Type.EnumLiteral" {
225 testTypes(&[_]type{
225 try testTypes(&[_]type{
226226 @TypeOf(.Dummy),
227227 });
228228}
......@@ -232,7 +232,7 @@ fn add(a: i32, b: i32) i32 {
232232}
233233
234234test "Type.Frame" {
235 testTypes(&[_]type{
235 try testTypes(&[_]type{
236236 @Frame(add),
237237 });
238238}
......@@ -247,45 +247,45 @@ test "Type.ErrorSet" {
247247test "Type.Struct" {
248248 const A = @Type(@typeInfo(struct { x: u8, y: u32 }));
249249 const infoA = @typeInfo(A).Struct;
250 testing.expectEqual(TypeInfo.ContainerLayout.Auto, infoA.layout);
251 testing.expectEqualSlices(u8, "x", infoA.fields[0].name);
252 testing.expectEqual(u8, infoA.fields[0].field_type);
253 testing.expectEqual(@as(?u8, null), infoA.fields[0].default_value);
254 testing.expectEqualSlices(u8, "y", infoA.fields[1].name);
255 testing.expectEqual(u32, infoA.fields[1].field_type);
256 testing.expectEqual(@as(?u32, null), infoA.fields[1].default_value);
257 testing.expectEqualSlices(TypeInfo.Declaration, &[_]TypeInfo.Declaration{}, infoA.decls);
258 testing.expectEqual(@as(bool, false), infoA.is_tuple);
250 try testing.expectEqual(TypeInfo.ContainerLayout.Auto, infoA.layout);
251 try testing.expectEqualSlices(u8, "x", infoA.fields[0].name);
252 try testing.expectEqual(u8, infoA.fields[0].field_type);
253 try testing.expectEqual(@as(?u8, null), infoA.fields[0].default_value);
254 try testing.expectEqualSlices(u8, "y", infoA.fields[1].name);
255 try testing.expectEqual(u32, infoA.fields[1].field_type);
256 try testing.expectEqual(@as(?u32, null), infoA.fields[1].default_value);
257 try testing.expectEqualSlices(TypeInfo.Declaration, &[_]TypeInfo.Declaration{}, infoA.decls);
258 try testing.expectEqual(@as(bool, false), infoA.is_tuple);
259259
260260 var a = A{ .x = 0, .y = 1 };
261 testing.expectEqual(@as(u8, 0), a.x);
262 testing.expectEqual(@as(u32, 1), a.y);
261 try testing.expectEqual(@as(u8, 0), a.x);
262 try testing.expectEqual(@as(u32, 1), a.y);
263263 a.y += 1;
264 testing.expectEqual(@as(u32, 2), a.y);
264 try testing.expectEqual(@as(u32, 2), a.y);
265265
266266 const B = @Type(@typeInfo(extern struct { x: u8, y: u32 = 5 }));
267267 const infoB = @typeInfo(B).Struct;
268 testing.expectEqual(TypeInfo.ContainerLayout.Extern, infoB.layout);
269 testing.expectEqualSlices(u8, "x", infoB.fields[0].name);
270 testing.expectEqual(u8, infoB.fields[0].field_type);
271 testing.expectEqual(@as(?u8, null), infoB.fields[0].default_value);
272 testing.expectEqualSlices(u8, "y", infoB.fields[1].name);
273 testing.expectEqual(u32, infoB.fields[1].field_type);
274 testing.expectEqual(@as(?u32, 5), infoB.fields[1].default_value);
275 testing.expectEqual(@as(usize, 0), infoB.decls.len);
276 testing.expectEqual(@as(bool, false), infoB.is_tuple);
268 try testing.expectEqual(TypeInfo.ContainerLayout.Extern, infoB.layout);
269 try testing.expectEqualSlices(u8, "x", infoB.fields[0].name);
270 try testing.expectEqual(u8, infoB.fields[0].field_type);
271 try testing.expectEqual(@as(?u8, null), infoB.fields[0].default_value);
272 try testing.expectEqualSlices(u8, "y", infoB.fields[1].name);
273 try testing.expectEqual(u32, infoB.fields[1].field_type);
274 try testing.expectEqual(@as(?u32, 5), infoB.fields[1].default_value);
275 try testing.expectEqual(@as(usize, 0), infoB.decls.len);
276 try testing.expectEqual(@as(bool, false), infoB.is_tuple);
277277
278278 const C = @Type(@typeInfo(packed struct { x: u8 = 3, y: u32 = 5 }));
279279 const infoC = @typeInfo(C).Struct;
280 testing.expectEqual(TypeInfo.ContainerLayout.Packed, infoC.layout);
281 testing.expectEqualSlices(u8, "x", infoC.fields[0].name);
282 testing.expectEqual(u8, infoC.fields[0].field_type);
283 testing.expectEqual(@as(?u8, 3), infoC.fields[0].default_value);
284 testing.expectEqualSlices(u8, "y", infoC.fields[1].name);
285 testing.expectEqual(u32, infoC.fields[1].field_type);
286 testing.expectEqual(@as(?u32, 5), infoC.fields[1].default_value);
287 testing.expectEqual(@as(usize, 0), infoC.decls.len);
288 testing.expectEqual(@as(bool, false), infoC.is_tuple);
280 try testing.expectEqual(TypeInfo.ContainerLayout.Packed, infoC.layout);
281 try testing.expectEqualSlices(u8, "x", infoC.fields[0].name);
282 try testing.expectEqual(u8, infoC.fields[0].field_type);
283 try testing.expectEqual(@as(?u8, 3), infoC.fields[0].default_value);
284 try testing.expectEqualSlices(u8, "y", infoC.fields[1].name);
285 try testing.expectEqual(u32, infoC.fields[1].field_type);
286 try testing.expectEqual(@as(?u32, 5), infoC.fields[1].default_value);
287 try testing.expectEqual(@as(usize, 0), infoC.decls.len);
288 try testing.expectEqual(@as(bool, false), infoC.is_tuple);
289289}
290290
291291test "Type.Enum" {
......@@ -301,9 +301,9 @@ test "Type.Enum" {
301301 .is_exhaustive = true,
302302 },
303303 });
304 testing.expectEqual(true, @typeInfo(Foo).Enum.is_exhaustive);
305 testing.expectEqual(@as(u8, 1), @enumToInt(Foo.a));
306 testing.expectEqual(@as(u8, 5), @enumToInt(Foo.b));
304 try testing.expectEqual(true, @typeInfo(Foo).Enum.is_exhaustive);
305 try testing.expectEqual(@as(u8, 1), @enumToInt(Foo.a));
306 try testing.expectEqual(@as(u8, 5), @enumToInt(Foo.b));
307307 const Bar = @Type(.{
308308 .Enum = .{
309309 .layout = .Extern,
......@@ -316,10 +316,10 @@ test "Type.Enum" {
316316 .is_exhaustive = false,
317317 },
318318 });
319 testing.expectEqual(false, @typeInfo(Bar).Enum.is_exhaustive);
320 testing.expectEqual(@as(u32, 1), @enumToInt(Bar.a));
321 testing.expectEqual(@as(u32, 5), @enumToInt(Bar.b));
322 testing.expectEqual(@as(u32, 6), @enumToInt(@intToEnum(Bar, 6)));
319 try testing.expectEqual(false, @typeInfo(Bar).Enum.is_exhaustive);
320 try testing.expectEqual(@as(u32, 1), @enumToInt(Bar.a));
321 try testing.expectEqual(@as(u32, 5), @enumToInt(Bar.b));
322 try testing.expectEqual(@as(u32, 6), @enumToInt(@intToEnum(Bar, 6)));
323323}
324324
325325test "Type.Union" {
......@@ -337,7 +337,7 @@ test "Type.Union" {
337337 var untagged = Untagged{ .int = 1 };
338338 untagged.float = 2.0;
339339 untagged.int = 3;
340 testing.expectEqual(@as(i32, 3), untagged.int);
340 try testing.expectEqual(@as(i32, 3), untagged.int);
341341
342342 const PackedUntagged = @Type(.{
343343 .Union = .{
......@@ -351,8 +351,8 @@ test "Type.Union" {
351351 },
352352 });
353353 var packed_untagged = PackedUntagged{ .signed = -1 };
354 testing.expectEqual(@as(i32, -1), packed_untagged.signed);
355 testing.expectEqual(~@as(u32, 0), packed_untagged.unsigned);
354 try testing.expectEqual(@as(i32, -1), packed_untagged.signed);
355 try testing.expectEqual(~@as(u32, 0), packed_untagged.unsigned);
356356
357357 const Tag = @Type(.{
358358 .Enum = .{
......@@ -378,9 +378,9 @@ test "Type.Union" {
378378 },
379379 });
380380 var tagged = Tagged{ .signed = -1 };
381 testing.expectEqual(Tag.signed, tagged);
381 try testing.expectEqual(Tag.signed, tagged);
382382 tagged = .{ .unsigned = 1 };
383 testing.expectEqual(Tag.unsigned, tagged);
383 try testing.expectEqual(Tag.unsigned, tagged);
384384}
385385
386386test "Type.Union from Type.Enum" {
......@@ -446,7 +446,7 @@ test "Type.BoundFn" {
446446 pub fn foo(self: *const @This()) align(4) callconv(.Unspecified) void {}
447447 };
448448 const test_instance: TestStruct = undefined;
449 testing.expect(std.meta.eql(
449 try testing.expect(std.meta.eql(
450450 @typeName(@TypeOf(test_instance.foo)),
451451 @typeName(@Type(@typeInfo(@TypeOf(test_instance.foo)))),
452452 ));
test/behavior/type_info.zig+187-187
......@@ -9,151 +9,151 @@ const expect = std.testing.expect;
99const expectEqualStrings = std.testing.expectEqualStrings;
1010
1111test "type info: tag type, void info" {
12 testBasic();
13 comptime testBasic();
12 try testBasic();
13 comptime try testBasic();
1414}
1515
16fn testBasic() void {
17 expect(@typeInfo(TypeInfo).Union.tag_type == TypeId);
16fn testBasic() !void {
17 try expect(@typeInfo(TypeInfo).Union.tag_type == TypeId);
1818 const void_info = @typeInfo(void);
19 expect(void_info == TypeId.Void);
20 expect(void_info.Void == {});
19 try expect(void_info == TypeId.Void);
20 try expect(void_info.Void == {});
2121}
2222
2323test "type info: integer, floating point type info" {
24 testIntFloat();
25 comptime testIntFloat();
24 try testIntFloat();
25 comptime try testIntFloat();
2626}
2727
28fn testIntFloat() void {
28fn testIntFloat() !void {
2929 const u8_info = @typeInfo(u8);
30 expect(u8_info == .Int);
31 expect(u8_info.Int.signedness == .unsigned);
32 expect(u8_info.Int.bits == 8);
30 try expect(u8_info == .Int);
31 try expect(u8_info.Int.signedness == .unsigned);
32 try expect(u8_info.Int.bits == 8);
3333
3434 const f64_info = @typeInfo(f64);
35 expect(f64_info == .Float);
36 expect(f64_info.Float.bits == 64);
35 try expect(f64_info == .Float);
36 try expect(f64_info.Float.bits == 64);
3737}
3838
3939test "type info: pointer type info" {
40 testPointer();
41 comptime testPointer();
40 try testPointer();
41 comptime try testPointer();
4242}
4343
44fn testPointer() void {
44fn testPointer() !void {
4545 const u32_ptr_info = @typeInfo(*u32);
46 expect(u32_ptr_info == .Pointer);
47 expect(u32_ptr_info.Pointer.size == TypeInfo.Pointer.Size.One);
48 expect(u32_ptr_info.Pointer.is_const == false);
49 expect(u32_ptr_info.Pointer.is_volatile == false);
50 expect(u32_ptr_info.Pointer.alignment == @alignOf(u32));
51 expect(u32_ptr_info.Pointer.child == u32);
52 expect(u32_ptr_info.Pointer.sentinel == null);
46 try expect(u32_ptr_info == .Pointer);
47 try expect(u32_ptr_info.Pointer.size == TypeInfo.Pointer.Size.One);
48 try expect(u32_ptr_info.Pointer.is_const == false);
49 try expect(u32_ptr_info.Pointer.is_volatile == false);
50 try expect(u32_ptr_info.Pointer.alignment == @alignOf(u32));
51 try expect(u32_ptr_info.Pointer.child == u32);
52 try expect(u32_ptr_info.Pointer.sentinel == null);
5353}
5454
5555test "type info: unknown length pointer type info" {
56 testUnknownLenPtr();
57 comptime testUnknownLenPtr();
56 try testUnknownLenPtr();
57 comptime try testUnknownLenPtr();
5858}
5959
60fn testUnknownLenPtr() void {
60fn testUnknownLenPtr() !void {
6161 const u32_ptr_info = @typeInfo([*]const volatile f64);
62 expect(u32_ptr_info == .Pointer);
63 expect(u32_ptr_info.Pointer.size == TypeInfo.Pointer.Size.Many);
64 expect(u32_ptr_info.Pointer.is_const == true);
65 expect(u32_ptr_info.Pointer.is_volatile == true);
66 expect(u32_ptr_info.Pointer.sentinel == null);
67 expect(u32_ptr_info.Pointer.alignment == @alignOf(f64));
68 expect(u32_ptr_info.Pointer.child == f64);
62 try expect(u32_ptr_info == .Pointer);
63 try expect(u32_ptr_info.Pointer.size == TypeInfo.Pointer.Size.Many);
64 try expect(u32_ptr_info.Pointer.is_const == true);
65 try expect(u32_ptr_info.Pointer.is_volatile == true);
66 try expect(u32_ptr_info.Pointer.sentinel == null);
67 try expect(u32_ptr_info.Pointer.alignment == @alignOf(f64));
68 try expect(u32_ptr_info.Pointer.child == f64);
6969}
7070
7171test "type info: null terminated pointer type info" {
72 testNullTerminatedPtr();
73 comptime testNullTerminatedPtr();
72 try testNullTerminatedPtr();
73 comptime try testNullTerminatedPtr();
7474}
7575
76fn testNullTerminatedPtr() void {
76fn testNullTerminatedPtr() !void {
7777 const ptr_info = @typeInfo([*:0]u8);
78 expect(ptr_info == .Pointer);
79 expect(ptr_info.Pointer.size == TypeInfo.Pointer.Size.Many);
80 expect(ptr_info.Pointer.is_const == false);
81 expect(ptr_info.Pointer.is_volatile == false);
82 expect(ptr_info.Pointer.sentinel.? == 0);
78 try expect(ptr_info == .Pointer);
79 try expect(ptr_info.Pointer.size == TypeInfo.Pointer.Size.Many);
80 try expect(ptr_info.Pointer.is_const == false);
81 try expect(ptr_info.Pointer.is_volatile == false);
82 try expect(ptr_info.Pointer.sentinel.? == 0);
8383
84 expect(@typeInfo([:0]u8).Pointer.sentinel != null);
84 try expect(@typeInfo([:0]u8).Pointer.sentinel != null);
8585}
8686
8787test "type info: C pointer type info" {
88 testCPtr();
89 comptime testCPtr();
88 try testCPtr();
89 comptime try testCPtr();
9090}
9191
92fn testCPtr() void {
92fn testCPtr() !void {
9393 const ptr_info = @typeInfo([*c]align(4) const i8);
94 expect(ptr_info == .Pointer);
95 expect(ptr_info.Pointer.size == .C);
96 expect(ptr_info.Pointer.is_const);
97 expect(!ptr_info.Pointer.is_volatile);
98 expect(ptr_info.Pointer.alignment == 4);
99 expect(ptr_info.Pointer.child == i8);
94 try expect(ptr_info == .Pointer);
95 try expect(ptr_info.Pointer.size == .C);
96 try expect(ptr_info.Pointer.is_const);
97 try expect(!ptr_info.Pointer.is_volatile);
98 try expect(ptr_info.Pointer.alignment == 4);
99 try expect(ptr_info.Pointer.child == i8);
100100}
101101
102102test "type info: slice type info" {
103 testSlice();
104 comptime testSlice();
103 try testSlice();
104 comptime try testSlice();
105105}
106106
107fn testSlice() void {
107fn testSlice() !void {
108108 const u32_slice_info = @typeInfo([]u32);
109 expect(u32_slice_info == .Pointer);
110 expect(u32_slice_info.Pointer.size == .Slice);
111 expect(u32_slice_info.Pointer.is_const == false);
112 expect(u32_slice_info.Pointer.is_volatile == false);
113 expect(u32_slice_info.Pointer.alignment == 4);
114 expect(u32_slice_info.Pointer.child == u32);
109 try expect(u32_slice_info == .Pointer);
110 try expect(u32_slice_info.Pointer.size == .Slice);
111 try expect(u32_slice_info.Pointer.is_const == false);
112 try expect(u32_slice_info.Pointer.is_volatile == false);
113 try expect(u32_slice_info.Pointer.alignment == 4);
114 try expect(u32_slice_info.Pointer.child == u32);
115115}
116116
117117test "type info: array type info" {
118 testArray();
119 comptime testArray();
118 try testArray();
119 comptime try testArray();
120120}
121121
122fn testArray() void {
122fn testArray() !void {
123123 {
124124 const info = @typeInfo([42]u8);
125 expect(info == .Array);
126 expect(info.Array.len == 42);
127 expect(info.Array.child == u8);
128 expect(info.Array.sentinel == null);
125 try expect(info == .Array);
126 try expect(info.Array.len == 42);
127 try expect(info.Array.child == u8);
128 try expect(info.Array.sentinel == null);
129129 }
130130
131131 {
132132 const info = @typeInfo([10:0]u8);
133 expect(info.Array.len == 10);
134 expect(info.Array.child == u8);
135 expect(info.Array.sentinel.? == @as(u8, 0));
136 expect(@sizeOf([10:0]u8) == info.Array.len + 1);
133 try expect(info.Array.len == 10);
134 try expect(info.Array.child == u8);
135 try expect(info.Array.sentinel.? == @as(u8, 0));
136 try expect(@sizeOf([10:0]u8) == info.Array.len + 1);
137137 }
138138}
139139
140140test "type info: optional type info" {
141 testOptional();
142 comptime testOptional();
141 try testOptional();
142 comptime try testOptional();
143143}
144144
145fn testOptional() void {
145fn testOptional() !void {
146146 const null_info = @typeInfo(?void);
147 expect(null_info == .Optional);
148 expect(null_info.Optional.child == void);
147 try expect(null_info == .Optional);
148 try expect(null_info.Optional.child == void);
149149}
150150
151151test "type info: error set, error union info" {
152 testErrorSet();
153 comptime testErrorSet();
152 try testErrorSet();
153 comptime try testErrorSet();
154154}
155155
156fn testErrorSet() void {
156fn testErrorSet() !void {
157157 const TestErrorSet = error{
158158 First,
159159 Second,
......@@ -161,26 +161,26 @@ fn testErrorSet() void {
161161 };
162162
163163 const error_set_info = @typeInfo(TestErrorSet);
164 expect(error_set_info == .ErrorSet);
165 expect(error_set_info.ErrorSet.?.len == 3);
166 expect(mem.eql(u8, error_set_info.ErrorSet.?[0].name, "First"));
164 try expect(error_set_info == .ErrorSet);
165 try expect(error_set_info.ErrorSet.?.len == 3);
166 try expect(mem.eql(u8, error_set_info.ErrorSet.?[0].name, "First"));
167167
168168 const error_union_info = @typeInfo(TestErrorSet!usize);
169 expect(error_union_info == .ErrorUnion);
170 expect(error_union_info.ErrorUnion.error_set == TestErrorSet);
171 expect(error_union_info.ErrorUnion.payload == usize);
169 try expect(error_union_info == .ErrorUnion);
170 try expect(error_union_info.ErrorUnion.error_set == TestErrorSet);
171 try expect(error_union_info.ErrorUnion.payload == usize);
172172
173173 const global_info = @typeInfo(anyerror);
174 expect(global_info == .ErrorSet);
175 expect(global_info.ErrorSet == null);
174 try expect(global_info == .ErrorSet);
175 try expect(global_info.ErrorSet == null);
176176}
177177
178178test "type info: enum info" {
179 testEnum();
180 comptime testEnum();
179 try testEnum();
180 comptime try testEnum();
181181}
182182
183fn testEnum() void {
183fn testEnum() !void {
184184 const Os = enum {
185185 Windows,
186186 Macos,
......@@ -189,28 +189,28 @@ fn testEnum() void {
189189 };
190190
191191 const os_info = @typeInfo(Os);
192 expect(os_info == .Enum);
193 expect(os_info.Enum.layout == .Auto);
194 expect(os_info.Enum.fields.len == 4);
195 expect(mem.eql(u8, os_info.Enum.fields[1].name, "Macos"));
196 expect(os_info.Enum.fields[3].value == 3);
197 expect(os_info.Enum.tag_type == u2);
198 expect(os_info.Enum.decls.len == 0);
192 try expect(os_info == .Enum);
193 try expect(os_info.Enum.layout == .Auto);
194 try expect(os_info.Enum.fields.len == 4);
195 try expect(mem.eql(u8, os_info.Enum.fields[1].name, "Macos"));
196 try expect(os_info.Enum.fields[3].value == 3);
197 try expect(os_info.Enum.tag_type == u2);
198 try expect(os_info.Enum.decls.len == 0);
199199}
200200
201201test "type info: union info" {
202 testUnion();
203 comptime testUnion();
202 try testUnion();
203 comptime try testUnion();
204204}
205205
206fn testUnion() void {
206fn testUnion() !void {
207207 const typeinfo_info = @typeInfo(TypeInfo);
208 expect(typeinfo_info == .Union);
209 expect(typeinfo_info.Union.layout == .Auto);
210 expect(typeinfo_info.Union.tag_type.? == TypeId);
211 expect(typeinfo_info.Union.fields.len == 25);
212 expect(typeinfo_info.Union.fields[4].field_type == @TypeOf(@typeInfo(u8).Int));
213 expect(typeinfo_info.Union.decls.len == 22);
208 try expect(typeinfo_info == .Union);
209 try expect(typeinfo_info.Union.layout == .Auto);
210 try expect(typeinfo_info.Union.tag_type.? == TypeId);
211 try expect(typeinfo_info.Union.fields.len == 25);
212 try expect(typeinfo_info.Union.fields[4].field_type == @TypeOf(@typeInfo(u8).Int));
213 try expect(typeinfo_info.Union.decls.len == 22);
214214
215215 const TestNoTagUnion = union {
216216 Foo: void,
......@@ -218,52 +218,52 @@ fn testUnion() void {
218218 };
219219
220220 const notag_union_info = @typeInfo(TestNoTagUnion);
221 expect(notag_union_info == .Union);
222 expect(notag_union_info.Union.tag_type == null);
223 expect(notag_union_info.Union.layout == .Auto);
224 expect(notag_union_info.Union.fields.len == 2);
225 expect(notag_union_info.Union.fields[0].alignment == @alignOf(void));
226 expect(notag_union_info.Union.fields[1].field_type == u32);
227 expect(notag_union_info.Union.fields[1].alignment == @alignOf(u32));
221 try expect(notag_union_info == .Union);
222 try expect(notag_union_info.Union.tag_type == null);
223 try expect(notag_union_info.Union.layout == .Auto);
224 try expect(notag_union_info.Union.fields.len == 2);
225 try expect(notag_union_info.Union.fields[0].alignment == @alignOf(void));
226 try expect(notag_union_info.Union.fields[1].field_type == u32);
227 try expect(notag_union_info.Union.fields[1].alignment == @alignOf(u32));
228228
229229 const TestExternUnion = extern union {
230230 foo: *c_void,
231231 };
232232
233233 const extern_union_info = @typeInfo(TestExternUnion);
234 expect(extern_union_info.Union.layout == .Extern);
235 expect(extern_union_info.Union.tag_type == null);
236 expect(extern_union_info.Union.fields[0].field_type == *c_void);
234 try expect(extern_union_info.Union.layout == .Extern);
235 try expect(extern_union_info.Union.tag_type == null);
236 try expect(extern_union_info.Union.fields[0].field_type == *c_void);
237237}
238238
239239test "type info: struct info" {
240 testStruct();
241 comptime testStruct();
240 try testStruct();
241 comptime try testStruct();
242242}
243243
244fn testStruct() void {
244fn testStruct() !void {
245245 const unpacked_struct_info = @typeInfo(TestUnpackedStruct);
246 expect(unpacked_struct_info.Struct.is_tuple == false);
247 expect(unpacked_struct_info.Struct.fields[0].alignment == @alignOf(u32));
248 expect(unpacked_struct_info.Struct.fields[0].default_value.? == 4);
249 expectEqualStrings("foobar", unpacked_struct_info.Struct.fields[1].default_value.?);
246 try expect(unpacked_struct_info.Struct.is_tuple == false);
247 try expect(unpacked_struct_info.Struct.fields[0].alignment == @alignOf(u32));
248 try expect(unpacked_struct_info.Struct.fields[0].default_value.? == 4);
249 try expectEqualStrings("foobar", unpacked_struct_info.Struct.fields[1].default_value.?);
250250
251251 const struct_info = @typeInfo(TestStruct);
252 expect(struct_info == .Struct);
253 expect(struct_info.Struct.is_tuple == false);
254 expect(struct_info.Struct.layout == .Packed);
255 expect(struct_info.Struct.fields.len == 4);
256 expect(struct_info.Struct.fields[0].alignment == 2 * @alignOf(usize));
257 expect(struct_info.Struct.fields[2].field_type == *TestStruct);
258 expect(struct_info.Struct.fields[2].default_value == null);
259 expect(struct_info.Struct.fields[3].default_value.? == 4);
260 expect(struct_info.Struct.fields[3].alignment == 1);
261 expect(struct_info.Struct.decls.len == 2);
262 expect(struct_info.Struct.decls[0].is_pub);
263 expect(!struct_info.Struct.decls[0].data.Fn.is_extern);
264 expect(struct_info.Struct.decls[0].data.Fn.lib_name == null);
265 expect(struct_info.Struct.decls[0].data.Fn.return_type == void);
266 expect(struct_info.Struct.decls[0].data.Fn.fn_type == fn (*const TestStruct) void);
252 try expect(struct_info == .Struct);
253 try expect(struct_info.Struct.is_tuple == false);
254 try expect(struct_info.Struct.layout == .Packed);
255 try expect(struct_info.Struct.fields.len == 4);
256 try expect(struct_info.Struct.fields[0].alignment == 2 * @alignOf(usize));
257 try expect(struct_info.Struct.fields[2].field_type == *TestStruct);
258 try expect(struct_info.Struct.fields[2].default_value == null);
259 try expect(struct_info.Struct.fields[3].default_value.? == 4);
260 try expect(struct_info.Struct.fields[3].alignment == 1);
261 try expect(struct_info.Struct.decls.len == 2);
262 try expect(struct_info.Struct.decls[0].is_pub);
263 try expect(!struct_info.Struct.decls[0].data.Fn.is_extern);
264 try expect(struct_info.Struct.decls[0].data.Fn.lib_name == null);
265 try expect(struct_info.Struct.decls[0].data.Fn.return_type == void);
266 try expect(struct_info.Struct.decls[0].data.Fn.fn_type == fn (*const TestStruct) void);
267267}
268268
269269const TestUnpackedStruct = struct {
......@@ -282,44 +282,44 @@ const TestStruct = packed struct {
282282};
283283
284284test "type info: opaque info" {
285 testOpaque();
286 comptime testOpaque();
285 try testOpaque();
286 comptime try testOpaque();
287287}
288288
289fn testOpaque() void {
289fn testOpaque() !void {
290290 const Foo = opaque {
291291 const A = 1;
292292 fn b() void {}
293293 };
294294
295295 const foo_info = @typeInfo(Foo);
296 expect(foo_info.Opaque.decls.len == 2);
296 try expect(foo_info.Opaque.decls.len == 2);
297297}
298298
299299test "type info: function type info" {
300300 // wasm doesn't support align attributes on functions
301301 if (builtin.target.cpu.arch == .wasm32 or builtin.target.cpu.arch == .wasm64) return error.SkipZigTest;
302 testFunction();
303 comptime testFunction();
302 try testFunction();
303 comptime try testFunction();
304304}
305305
306fn testFunction() void {
306fn testFunction() !void {
307307 const fn_info = @typeInfo(@TypeOf(foo));
308 expect(fn_info == .Fn);
308 try expect(fn_info == .Fn);
309309 // TODO Fix this before merging the branch
310 //expect(fn_info.Fn.alignment > 0);
311 expect(fn_info.Fn.calling_convention == .C);
312 expect(!fn_info.Fn.is_generic);
313 expect(fn_info.Fn.args.len == 2);
314 expect(fn_info.Fn.is_var_args);
315 expect(fn_info.Fn.return_type.? == usize);
310 //try expect(fn_info.Fn.alignment > 0);
311 try expect(fn_info.Fn.calling_convention == .C);
312 try expect(!fn_info.Fn.is_generic);
313 try expect(fn_info.Fn.args.len == 2);
314 try expect(fn_info.Fn.is_var_args);
315 try expect(fn_info.Fn.return_type.? == usize);
316316 const fn_aligned_info = @typeInfo(@TypeOf(fooAligned));
317 expect(fn_aligned_info.Fn.alignment == 4);
317 try expect(fn_aligned_info.Fn.alignment == 4);
318318
319319 const test_instance: TestStruct = undefined;
320320 const bound_fn_info = @typeInfo(@TypeOf(test_instance.foo));
321 expect(bound_fn_info == .BoundFn);
322 expect(bound_fn_info.BoundFn.args[0].arg_type.? == *const TestStruct);
321 try expect(bound_fn_info == .BoundFn);
322 try expect(bound_fn_info.BoundFn.args[0].arg_type.? == *const TestStruct);
323323}
324324
325325extern fn foo(a: usize, b: bool, ...) callconv(.C) usize;
......@@ -333,33 +333,33 @@ test "typeInfo with comptime parameter in struct fn def" {
333333}
334334
335335test "type info: vectors" {
336 testVector();
337 comptime testVector();
336 try testVector();
337 comptime try testVector();
338338}
339339
340fn testVector() void {
340fn testVector() !void {
341341 const vec_info = @typeInfo(std.meta.Vector(4, i32));
342 expect(vec_info == .Vector);
343 expect(vec_info.Vector.len == 4);
344 expect(vec_info.Vector.child == i32);
342 try expect(vec_info == .Vector);
343 try expect(vec_info.Vector.len == 4);
344 try expect(vec_info.Vector.child == i32);
345345}
346346
347347test "type info: anyframe and anyframe->T" {
348 testAnyFrame();
349 comptime testAnyFrame();
348 try testAnyFrame();
349 comptime try testAnyFrame();
350350}
351351
352fn testAnyFrame() void {
352fn testAnyFrame() !void {
353353 {
354354 const anyframe_info = @typeInfo(anyframe->i32);
355 expect(anyframe_info == .AnyFrame);
356 expect(anyframe_info.AnyFrame.child.? == i32);
355 try expect(anyframe_info == .AnyFrame);
356 try expect(anyframe_info.AnyFrame.child.? == i32);
357357 }
358358
359359 {
360360 const anyframe_info = @typeInfo(anyframe);
361 expect(anyframe_info == .AnyFrame);
362 expect(anyframe_info.AnyFrame.child == null);
361 try expect(anyframe_info == .AnyFrame);
362 try expect(anyframe_info.AnyFrame.child == null);
363363 }
364364}
365365
......@@ -386,9 +386,9 @@ test "type info: extern fns with and without lib names" {
386386 comptime {
387387 for (info.Struct.decls) |decl| {
388388 if (std.mem.eql(u8, decl.name, "bar1")) {
389 expect(decl.data.Fn.lib_name == null);
389 try expect(decl.data.Fn.lib_name == null);
390390 } else {
391 expectEqualStrings("cool", decl.data.Fn.lib_name.?);
391 try expectEqualStrings("cool", decl.data.Fn.lib_name.?);
392392 }
393393 }
394394 }
......@@ -398,12 +398,12 @@ test "data field is a compile-time value" {
398398 const S = struct {
399399 const Bar = @as(isize, -1);
400400 };
401 comptime expect(@typeInfo(S).Struct.decls[0].data.Var == isize);
401 comptime try expect(@typeInfo(S).Struct.decls[0].data.Var == isize);
402402}
403403
404404test "sentinel of opaque pointer type" {
405405 const c_void_info = @typeInfo(*c_void);
406 expect(c_void_info.Pointer.sentinel == null);
406 try expect(c_void_info.Pointer.sentinel == null);
407407}
408408
409409test "@typeInfo does not force declarations into existence" {
......@@ -414,12 +414,12 @@ test "@typeInfo does not force declarations into existence" {
414414 @compileError("test failed");
415415 }
416416 };
417 comptime expect(@typeInfo(S).Struct.fields.len == 1);
417 comptime try expect(@typeInfo(S).Struct.fields.len == 1);
418418}
419419
420420test "defaut value for a var-typed field" {
421421 const S = struct { x: anytype };
422 expect(@typeInfo(S).Struct.fields[0].default_value == null);
422 try expect(@typeInfo(S).Struct.fields[0].default_value == null);
423423}
424424
425425fn add(a: i32, b: i32) i32 {
......@@ -429,7 +429,7 @@ fn add(a: i32, b: i32) i32 {
429429test "type info for async frames" {
430430 switch (@typeInfo(@Frame(add))) {
431431 .Frame => |frame| {
432 expect(frame.function == add);
432 try expect(frame.function == add);
433433 },
434434 else => unreachable,
435435 }
......@@ -439,7 +439,7 @@ test "type info: value is correctly copied" {
439439 comptime {
440440 var ptrInfo = @typeInfo([]u32);
441441 ptrInfo.Pointer.size = .One;
442 expect(@typeInfo([]u32).Pointer.size == .Slice);
442 try expect(@typeInfo([]u32).Pointer.size == .Slice);
443443 }
444444}
445445
......@@ -452,22 +452,22 @@ test "Declarations are returned in declaration order" {
452452 const e = 5;
453453 };
454454 const d = @typeInfo(S).Struct.decls;
455 expect(std.mem.eql(u8, d[0].name, "a"));
456 expect(std.mem.eql(u8, d[1].name, "b"));
457 expect(std.mem.eql(u8, d[2].name, "c"));
458 expect(std.mem.eql(u8, d[3].name, "d"));
459 expect(std.mem.eql(u8, d[4].name, "e"));
455 try expect(std.mem.eql(u8, d[0].name, "a"));
456 try expect(std.mem.eql(u8, d[1].name, "b"));
457 try expect(std.mem.eql(u8, d[2].name, "c"));
458 try expect(std.mem.eql(u8, d[3].name, "d"));
459 try expect(std.mem.eql(u8, d[4].name, "e"));
460460}
461461
462462test "Struct.is_tuple" {
463 expect(@typeInfo(@TypeOf(.{0})).Struct.is_tuple);
464 expect(!@typeInfo(@TypeOf(.{ .a = 0 })).Struct.is_tuple);
463 try expect(@typeInfo(@TypeOf(.{0})).Struct.is_tuple);
464 try expect(!@typeInfo(@TypeOf(.{ .a = 0 })).Struct.is_tuple);
465465}
466466
467467test "StructField.is_comptime" {
468468 const info = @typeInfo(struct { x: u8 = 3, comptime y: u32 = 5 }).Struct;
469 expect(!info.fields[0].is_comptime);
470 expect(info.fields[1].is_comptime);
469 try expect(!info.fields[0].is_comptime);
470 try expect(info.fields[1].is_comptime);
471471}
472472
473473test "typeInfo resolves usingnamespace declarations" {
......@@ -480,6 +480,6 @@ test "typeInfo resolves usingnamespace declarations" {
480480 usingnamespace A;
481481 };
482482
483 expect(@typeInfo(B).Struct.decls.len == 2);
483 try expect(@typeInfo(B).Struct.decls.len == 2);
484484 //a
485485}
test/behavior/typename.zig+1-1
......@@ -3,5 +3,5 @@ const expect = std.testing.expect;
33const expectEqualSlices = std.testing.expectEqualSlices;
44
55test "slice" {
6 expectEqualSlices(u8, "[]u8", @typeName([]u8));
6 try expectEqualSlices(u8, "[]u8", @typeName([]u8));
77}
test/behavior/undefined.zig+13-13
......@@ -12,16 +12,16 @@ fn initStaticArray() [10]i32 {
1212}
1313const static_array = initStaticArray();
1414test "init static array to undefined" {
15 expect(static_array[0] == 1);
16 expect(static_array[4] == 2);
17 expect(static_array[7] == 3);
18 expect(static_array[9] == 4);
15 try expect(static_array[0] == 1);
16 try expect(static_array[4] == 2);
17 try expect(static_array[7] == 3);
18 try expect(static_array[9] == 4);
1919
2020 comptime {
21 expect(static_array[0] == 1);
22 expect(static_array[4] == 2);
23 expect(static_array[7] == 3);
24 expect(static_array[9] == 4);
21 try expect(static_array[0] == 1);
22 try expect(static_array[4] == 2);
23 try expect(static_array[7] == 3);
24 try expect(static_array[9] == 4);
2525 }
2626}
2727
......@@ -41,12 +41,12 @@ test "assign undefined to struct" {
4141 comptime {
4242 var foo: Foo = undefined;
4343 setFooX(&foo);
44 expect(foo.x == 2);
44 try expect(foo.x == 2);
4545 }
4646 {
4747 var foo: Foo = undefined;
4848 setFooX(&foo);
49 expect(foo.x == 2);
49 try expect(foo.x == 2);
5050 }
5151}
5252
......@@ -54,16 +54,16 @@ test "assign undefined to struct with method" {
5454 comptime {
5555 var foo: Foo = undefined;
5656 foo.setFooXMethod();
57 expect(foo.x == 3);
57 try expect(foo.x == 3);
5858 }
5959 {
6060 var foo: Foo = undefined;
6161 foo.setFooXMethod();
62 expect(foo.x == 3);
62 try expect(foo.x == 3);
6363 }
6464}
6565
6666test "type name of undefined" {
6767 const x = undefined;
68 expect(mem.eql(u8, @typeName(@TypeOf(x)), "(undefined)"));
68 try expect(mem.eql(u8, @typeName(@TypeOf(x)), "(undefined)"));
6969}
test/behavior/union.zig+142-142
......@@ -30,11 +30,11 @@ const array = [_]Value{
3030
3131test "unions embedded in aggregate types" {
3232 switch (array[1]) {
33 Value.Array => |arr| expect(arr[4] == 3),
33 Value.Array => |arr| try expect(arr[4] == 3),
3434 else => unreachable,
3535 }
3636 switch ((err catch unreachable).val1) {
37 Value.Int => |x| expect(x == 1234),
37 Value.Int => |x| try expect(x == 1234),
3838 else => unreachable,
3939 }
4040}
......@@ -46,18 +46,18 @@ const Foo = union {
4646
4747test "basic unions" {
4848 var foo = Foo{ .int = 1 };
49 expect(foo.int == 1);
49 try expect(foo.int == 1);
5050 foo = Foo{ .float = 12.34 };
51 expect(foo.float == 12.34);
51 try expect(foo.float == 12.34);
5252}
5353
5454test "comptime union field access" {
5555 comptime {
5656 var foo = Foo{ .int = 0 };
57 expect(foo.int == 0);
57 try expect(foo.int == 0);
5858
5959 foo = Foo{ .float = 42.42 };
60 expect(foo.float == 42.42);
60 try expect(foo.float == 42.42);
6161 }
6262}
6363
......@@ -65,10 +65,10 @@ test "init union with runtime value" {
6565 var foo: Foo = undefined;
6666
6767 setFloat(&foo, 12.34);
68 expect(foo.float == 12.34);
68 try expect(foo.float == 12.34);
6969
7070 setInt(&foo, 42);
71 expect(foo.int == 42);
71 try expect(foo.int == 42);
7272}
7373
7474fn setFloat(foo: *Foo, x: f64) void {
......@@ -86,9 +86,9 @@ const FooExtern = extern union {
8686
8787test "basic extern unions" {
8888 var foo = FooExtern{ .int = 1 };
89 expect(foo.int == 1);
89 try expect(foo.int == 1);
9090 foo.float = 12.34;
91 expect(foo.float == 12.34);
91 try expect(foo.float == 12.34);
9292}
9393
9494const Letter = enum {
......@@ -103,16 +103,16 @@ const Payload = union(Letter) {
103103};
104104
105105test "union with specified enum tag" {
106 doTest();
107 comptime doTest();
106 try doTest();
107 comptime try doTest();
108108}
109109
110fn doTest() void {
111 expect(bar(Payload{ .A = 1234 }) == -10);
110fn doTest() !void {
111 try expect((try bar(Payload{ .A = 1234 })) == -10);
112112}
113113
114fn bar(value: Payload) i32 {
115 expect(@as(Letter, value) == Letter.A);
114fn bar(value: Payload) !i32 {
115 try expect(@as(Letter, value) == Letter.A);
116116 return switch (value) {
117117 Payload.A => |x| return x - 1244,
118118 Payload.B => |x| if (x == 12.34) @as(i32, 20) else 21,
......@@ -128,8 +128,8 @@ const MultipleChoice = union(enum(u32)) {
128128};
129129test "simple union(enum(u32))" {
130130 var x = MultipleChoice.C;
131 expect(x == MultipleChoice.C);
132 expect(@enumToInt(@as(Tag(MultipleChoice), x)) == 60);
131 try expect(x == MultipleChoice.C);
132 try expect(@enumToInt(@as(Tag(MultipleChoice), x)) == 60);
133133}
134134
135135const MultipleChoice2 = union(enum(u32)) {
......@@ -145,14 +145,14 @@ const MultipleChoice2 = union(enum(u32)) {
145145};
146146
147147test "union(enum(u32)) with specified and unspecified tag values" {
148 comptime expect(Tag(Tag(MultipleChoice2)) == u32);
149 testEnumWithSpecifiedAndUnspecifiedTagValues(MultipleChoice2{ .C = 123 });
150 comptime testEnumWithSpecifiedAndUnspecifiedTagValues(MultipleChoice2{ .C = 123 });
148 comptime try expect(Tag(Tag(MultipleChoice2)) == u32);
149 try testEnumWithSpecifiedAndUnspecifiedTagValues(MultipleChoice2{ .C = 123 });
150 comptime try testEnumWithSpecifiedAndUnspecifiedTagValues(MultipleChoice2{ .C = 123 });
151151}
152152
153fn testEnumWithSpecifiedAndUnspecifiedTagValues(x: MultipleChoice2) void {
154 expect(@enumToInt(@as(Tag(MultipleChoice2), x)) == 60);
155 expect(1123 == switch (x) {
153fn testEnumWithSpecifiedAndUnspecifiedTagValues(x: MultipleChoice2) !void {
154 try expect(@enumToInt(@as(Tag(MultipleChoice2), x)) == 60);
155 try expect(1123 == switch (x) {
156156 MultipleChoice2.A => 1,
157157 MultipleChoice2.B => 2,
158158 MultipleChoice2.C => |v| @as(i32, 1000) + v,
......@@ -170,7 +170,7 @@ const ExternPtrOrInt = extern union {
170170 int: u64,
171171};
172172test "extern union size" {
173 comptime expect(@sizeOf(ExternPtrOrInt) == 8);
173 comptime try expect(@sizeOf(ExternPtrOrInt) == 8);
174174}
175175
176176const PackedPtrOrInt = packed union {
......@@ -178,14 +178,14 @@ const PackedPtrOrInt = packed union {
178178 int: u64,
179179};
180180test "extern union size" {
181 comptime expect(@sizeOf(PackedPtrOrInt) == 8);
181 comptime try expect(@sizeOf(PackedPtrOrInt) == 8);
182182}
183183
184184const ZeroBits = union {
185185 OnlyField: void,
186186};
187187test "union with only 1 field which is void should be zero bits" {
188 comptime expect(@sizeOf(ZeroBits) == 0);
188 comptime try expect(@sizeOf(ZeroBits) == 0);
189189}
190190
191191const TheTag = enum {
......@@ -199,23 +199,23 @@ const TheUnion = union(TheTag) {
199199 C: i32,
200200};
201201test "union field access gives the enum values" {
202 expect(TheUnion.A == TheTag.A);
203 expect(TheUnion.B == TheTag.B);
204 expect(TheUnion.C == TheTag.C);
202 try expect(TheUnion.A == TheTag.A);
203 try expect(TheUnion.B == TheTag.B);
204 try expect(TheUnion.C == TheTag.C);
205205}
206206
207207test "cast union to tag type of union" {
208 testCastUnionToTag(TheUnion{ .B = 1234 });
209 comptime testCastUnionToTag(TheUnion{ .B = 1234 });
208 try testCastUnionToTag(TheUnion{ .B = 1234 });
209 comptime try testCastUnionToTag(TheUnion{ .B = 1234 });
210210}
211211
212fn testCastUnionToTag(x: TheUnion) void {
213 expect(@as(TheTag, x) == TheTag.B);
212fn testCastUnionToTag(x: TheUnion) !void {
213 try expect(@as(TheTag, x) == TheTag.B);
214214}
215215
216216test "cast tag type of union to union" {
217217 var x: Value2 = Letter2.B;
218 expect(@as(Letter2, x) == Letter2.B);
218 try expect(@as(Letter2, x) == Letter2.B);
219219}
220220const Letter2 = enum {
221221 A,
......@@ -230,11 +230,11 @@ const Value2 = union(Letter2) {
230230
231231test "implicit cast union to its tag type" {
232232 var x: Value2 = Letter2.B;
233 expect(x == Letter2.B);
234 giveMeLetterB(x);
233 try expect(x == Letter2.B);
234 try giveMeLetterB(x);
235235}
236fn giveMeLetterB(x: Letter2) void {
237 expect(x == Value2.B);
236fn giveMeLetterB(x: Letter2) !void {
237 try expect(x == Value2.B);
238238}
239239
240240pub const PackThis = union(enum) {
......@@ -243,11 +243,11 @@ pub const PackThis = union(enum) {
243243};
244244
245245test "constant packed union" {
246 testConstPackedUnion(&[_]PackThis{PackThis{ .StringLiteral = 1 }});
246 try testConstPackedUnion(&[_]PackThis{PackThis{ .StringLiteral = 1 }});
247247}
248248
249fn testConstPackedUnion(expected_tokens: []const PackThis) void {
250 expect(expected_tokens[0].StringLiteral == 1);
249fn testConstPackedUnion(expected_tokens: []const PackThis) !void {
250 try expect(expected_tokens[0].StringLiteral == 1);
251251}
252252
253253test "switch on union with only 1 field" {
......@@ -259,7 +259,7 @@ test "switch on union with only 1 field" {
259259 z = PartialInstWithPayload{ .Compiled = 1234 };
260260 switch (z) {
261261 PartialInstWithPayload.Compiled => |x| {
262 expect(x == 1234);
262 try expect(x == 1234);
263263 return;
264264 },
265265 }
......@@ -285,11 +285,11 @@ test "access a member of tagged union with conflicting enum tag name" {
285285 const B = void;
286286 };
287287
288 comptime expect(Bar.A == u8);
288 comptime try expect(Bar.A == u8);
289289}
290290
291291test "tagged union initialization with runtime void" {
292 expect(testTaggedUnionInit({}));
292 try expect(testTaggedUnionInit({}));
293293}
294294
295295const TaggedUnionWithAVoid = union(enum) {
......@@ -327,9 +327,9 @@ test "union with only 1 field casted to its enum type" {
327327
328328 var e = Expr{ .Literal = Literal{ .Bool = true } };
329329 const ExprTag = Tag(Expr);
330 comptime expect(Tag(ExprTag) == u0);
330 comptime try expect(Tag(ExprTag) == u0);
331331 var t = @as(ExprTag, e);
332 expect(t == Expr.Literal);
332 try expect(t == Expr.Literal);
333333}
334334
335335test "union with only 1 field casted to its enum type which has enum value specified" {
......@@ -347,11 +347,11 @@ test "union with only 1 field casted to its enum type which has enum value speci
347347 };
348348
349349 var e = Expr{ .Literal = Literal{ .Bool = true } };
350 comptime expect(Tag(ExprTag) == comptime_int);
350 comptime try expect(Tag(ExprTag) == comptime_int);
351351 var t = @as(ExprTag, e);
352 expect(t == Expr.Literal);
353 expect(@enumToInt(t) == 33);
354 comptime expect(@enumToInt(t) == 33);
352 try expect(t == Expr.Literal);
353 try expect(@enumToInt(t) == 33);
354 comptime try expect(@enumToInt(t) == 33);
355355}
356356
357357test "@enumToInt works on unions" {
......@@ -364,9 +364,9 @@ test "@enumToInt works on unions" {
364364 const a = Bar{ .A = true };
365365 var b = Bar{ .B = undefined };
366366 var c = Bar.C;
367 expect(@enumToInt(a) == 0);
368 expect(@enumToInt(b) == 1);
369 expect(@enumToInt(c) == 2);
367 try expect(@enumToInt(a) == 0);
368 try expect(@enumToInt(b) == 1);
369 try expect(@enumToInt(c) == 2);
370370}
371371
372372const Attribute = union(enum) {
......@@ -393,23 +393,23 @@ test "comptime union field value equality" {
393393 const b1 = Setter(Attribute{ .B = 9 });
394394 const b2 = Setter(Attribute{ .B = 5 });
395395
396 expect(a0 == a0);
397 expect(a1 == a1);
398 expect(a0 == a2);
396 try expect(a0 == a0);
397 try expect(a1 == a1);
398 try expect(a0 == a2);
399399
400 expect(b0 == b0);
401 expect(b1 == b1);
402 expect(b0 == b2);
400 try expect(b0 == b0);
401 try expect(b1 == b1);
402 try expect(b0 == b2);
403403
404 expect(a0 != b0);
405 expect(a0 != a1);
406 expect(b0 != b1);
404 try expect(a0 != b0);
405 try expect(a0 != a1);
406 try expect(b0 != b1);
407407}
408408
409409test "return union init with void payload" {
410410 const S = struct {
411 fn entry() void {
412 expect(func().state == State.one);
411 fn entry() !void {
412 try expect(func().state == State.one);
413413 }
414414 const Outer = union(enum) {
415415 state: State,
......@@ -422,8 +422,8 @@ test "return union init with void payload" {
422422 return Outer{ .state = State{ .one = {} } };
423423 }
424424 };
425 S.entry();
426 comptime S.entry();
425 try S.entry();
426 comptime try S.entry();
427427}
428428
429429test "@unionInit can modify a union type" {
......@@ -435,14 +435,14 @@ test "@unionInit can modify a union type" {
435435 var value: UnionInitEnum = undefined;
436436
437437 value = @unionInit(UnionInitEnum, "Boolean", true);
438 expect(value.Boolean == true);
438 try expect(value.Boolean == true);
439439 value.Boolean = false;
440 expect(value.Boolean == false);
440 try expect(value.Boolean == false);
441441
442442 value = @unionInit(UnionInitEnum, "Byte", 2);
443 expect(value.Byte == 2);
443 try expect(value.Byte == 2);
444444 value.Byte = 3;
445 expect(value.Byte == 3);
445 try expect(value.Byte == 3);
446446}
447447
448448test "@unionInit can modify a pointer value" {
......@@ -455,10 +455,10 @@ test "@unionInit can modify a pointer value" {
455455 var value_ptr = &value;
456456
457457 value_ptr.* = @unionInit(UnionInitEnum, "Boolean", true);
458 expect(value.Boolean == true);
458 try expect(value.Boolean == true);
459459
460460 value_ptr.* = @unionInit(UnionInitEnum, "Byte", 2);
461 expect(value.Byte == 2);
461 try expect(value.Byte == 2);
462462}
463463
464464test "union no tag with struct member" {
......@@ -471,38 +471,38 @@ test "union no tag with struct member" {
471471 u.foo();
472472}
473473
474fn testComparison() void {
474fn testComparison() !void {
475475 var x = Payload{ .A = 42 };
476 expect(x == .A);
477 expect(x != .B);
478 expect(x != .C);
479 expect((x == .B) == false);
480 expect((x == .C) == false);
481 expect((x != .A) == false);
476 try expect(x == .A);
477 try expect(x != .B);
478 try expect(x != .C);
479 try expect((x == .B) == false);
480 try expect((x == .C) == false);
481 try expect((x != .A) == false);
482482}
483483
484484test "comparison between union and enum literal" {
485 testComparison();
486 comptime testComparison();
485 try testComparison();
486 comptime try testComparison();
487487}
488488
489489test "packed union generates correctly aligned LLVM type" {
490490 const U = packed union {
491 f1: fn () void,
491 f1: fn () error{TestUnexpectedResult}!void,
492492 f2: u32,
493493 };
494494 var foo = [_]U{
495495 U{ .f1 = doTest },
496496 U{ .f2 = 0 },
497497 };
498 foo[0].f1();
498 try foo[0].f1();
499499}
500500
501501test "union with one member defaults to u0 tag type" {
502502 const U0 = union(enum) {
503503 X: u32,
504504 };
505 comptime expect(Tag(Tag(U0)) == u0);
505 comptime try expect(Tag(Tag(U0)) == u0);
506506}
507507
508508test "union with comptime_int tag" {
......@@ -511,7 +511,7 @@ test "union with comptime_int tag" {
511511 Y: u16,
512512 Z: u8,
513513 };
514 comptime expect(Tag(Tag(Union)) == comptime_int);
514 comptime try expect(Tag(Tag(Union)) == comptime_int);
515515}
516516
517517test "extern union doesn't trigger field check at comptime" {
......@@ -521,7 +521,7 @@ test "extern union doesn't trigger field check at comptime" {
521521 };
522522
523523 const x = U{ .x = 0x55AAAA55 };
524 comptime expect(x.y == 0x55);
524 comptime try expect(x.y == 0x55);
525525}
526526
527527const Foo1 = union(enum) {
......@@ -535,7 +535,7 @@ test "global union with single field is correctly initialized" {
535535 glbl = Foo1{
536536 .f = @typeInfo(Foo1).Union.fields[0].field_type{ .x = 123 },
537537 };
538 expect(glbl.f.x == 123);
538 try expect(glbl.f.x == 123);
539539}
540540
541541pub const FooUnion = union(enum) {
......@@ -548,8 +548,8 @@ var glbl_array: [2]FooUnion = undefined;
548548test "initialize global array of union" {
549549 glbl_array[1] = FooUnion{ .U1 = 2 };
550550 glbl_array[0] = FooUnion{ .U0 = 1 };
551 expect(glbl_array[0].U0 == 1);
552 expect(glbl_array[1].U1 == 2);
551 try expect(glbl_array[0].U0 == 1);
552 try expect(glbl_array[1].U1 == 2);
553553}
554554
555555test "anonymous union literal syntax" {
......@@ -559,19 +559,19 @@ test "anonymous union literal syntax" {
559559 float: f64,
560560 };
561561
562 fn doTheTest() void {
562 fn doTheTest() !void {
563563 var i: Number = .{ .int = 42 };
564564 var f = makeNumber();
565 expect(i.int == 42);
566 expect(f.float == 12.34);
565 try expect(i.int == 42);
566 try expect(f.float == 12.34);
567567 }
568568
569569 fn makeNumber() Number {
570570 return .{ .float = 12.34 };
571571 }
572572 };
573 S.doTheTest();
574 comptime S.doTheTest();
573 try S.doTheTest();
574 comptime try S.doTheTest();
575575}
576576
577577test "update the tag value for zero-sized unions" {
......@@ -580,9 +580,9 @@ test "update the tag value for zero-sized unions" {
580580 U1: void,
581581 };
582582 var x = S{ .U0 = {} };
583 expect(x == .U0);
583 try expect(x == .U0);
584584 x = S{ .U1 = {} };
585 expect(x == .U1);
585 try expect(x == .U1);
586586}
587587
588588test "function call result coerces from tagged union to the tag" {
......@@ -594,12 +594,12 @@ test "function call result coerces from tagged union to the tag" {
594594
595595 const ArchTag = Tag(Arch);
596596
597 fn doTheTest() void {
597 fn doTheTest() !void {
598598 var x: ArchTag = getArch1();
599 expect(x == .One);
599 try expect(x == .One);
600600
601601 var y: ArchTag = getArch2();
602 expect(y == .Two);
602 try expect(y == .Two);
603603 }
604604
605605 pub fn getArch1() Arch {
......@@ -610,8 +610,8 @@ test "function call result coerces from tagged union to the tag" {
610610 return .{ .Two = 99 };
611611 }
612612 };
613 S.doTheTest();
614 comptime S.doTheTest();
613 try S.doTheTest();
614 comptime try S.doTheTest();
615615}
616616
617617test "0-sized extern union definition" {
......@@ -620,7 +620,7 @@ test "0-sized extern union definition" {
620620 const f = 1;
621621 };
622622
623 expect(U.f == 1);
623 try expect(U.f == 1);
624624}
625625
626626test "union initializer generates padding only if needed" {
......@@ -629,7 +629,7 @@ test "union initializer generates padding only if needed" {
629629 };
630630
631631 var v = U{ .A = 532 };
632 expect(v.A == 532);
632 try expect(v.A == 532);
633633}
634634
635635test "runtime tag name with single field" {
......@@ -638,7 +638,7 @@ test "runtime tag name with single field" {
638638 };
639639
640640 var v = U{ .A = 42 };
641 expect(std.mem.eql(u8, @tagName(v), "A"));
641 try expect(std.mem.eql(u8, @tagName(v), "A"));
642642}
643643
644644test "cast from anonymous struct to union" {
......@@ -648,7 +648,7 @@ test "cast from anonymous struct to union" {
648648 B: []const u8,
649649 C: void,
650650 };
651 fn doTheTest() void {
651 fn doTheTest() !void {
652652 var y: u32 = 42;
653653 const t0 = .{ .A = 123 };
654654 const t1 = .{ .B = "foo" };
......@@ -658,14 +658,14 @@ test "cast from anonymous struct to union" {
658658 var x1: U = t1;
659659 const x2: U = t2;
660660 var x3: U = t3;
661 expect(x0.A == 123);
662 expect(std.mem.eql(u8, x1.B, "foo"));
663 expect(x2 == .C);
664 expect(x3.A == y);
661 try expect(x0.A == 123);
662 try expect(std.mem.eql(u8, x1.B, "foo"));
663 try expect(x2 == .C);
664 try expect(x3.A == y);
665665 }
666666 };
667 S.doTheTest();
668 comptime S.doTheTest();
667 try S.doTheTest();
668 comptime try S.doTheTest();
669669}
670670
671671test "cast from pointer to anonymous struct to pointer to union" {
......@@ -675,7 +675,7 @@ test "cast from pointer to anonymous struct to pointer to union" {
675675 B: []const u8,
676676 C: void,
677677 };
678 fn doTheTest() void {
678 fn doTheTest() !void {
679679 var y: u32 = 42;
680680 const t0 = &.{ .A = 123 };
681681 const t1 = &.{ .B = "foo" };
......@@ -685,14 +685,14 @@ test "cast from pointer to anonymous struct to pointer to union" {
685685 var x1: *const U = t1;
686686 const x2: *const U = t2;
687687 var x3: *const U = t3;
688 expect(x0.A == 123);
689 expect(std.mem.eql(u8, x1.B, "foo"));
690 expect(x2.* == .C);
691 expect(x3.A == y);
688 try expect(x0.A == 123);
689 try expect(std.mem.eql(u8, x1.B, "foo"));
690 try expect(x2.* == .C);
691 try expect(x3.A == y);
692692 }
693693 };
694 S.doTheTest();
695 comptime S.doTheTest();
694 try S.doTheTest();
695 comptime try S.doTheTest();
696696}
697697
698698test "method call on an empty union" {
......@@ -707,13 +707,13 @@ test "method call on an empty union" {
707707 }
708708 };
709709
710 fn doTheTest() void {
710 fn doTheTest() !void {
711711 var u = MyUnion{ .X1 = [0]u8{} };
712 expect(u.useIt());
712 try expect(u.useIt());
713713 }
714714 };
715 S.doTheTest();
716 comptime S.doTheTest();
715 try S.doTheTest();
716 comptime try S.doTheTest();
717717}
718718
719719test "switching on non exhaustive union" {
......@@ -727,16 +727,16 @@ test "switching on non exhaustive union" {
727727 a: i32,
728728 b: u32,
729729 };
730 fn doTheTest() void {
730 fn doTheTest() !void {
731731 var a = U{ .a = 2 };
732732 switch (a) {
733 .a => |val| expect(val == 2),
733 .a => |val| try expect(val == 2),
734734 .b => unreachable,
735735 }
736736 }
737737 };
738 S.doTheTest();
739 comptime S.doTheTest();
738 try S.doTheTest();
739 comptime try S.doTheTest();
740740}
741741
742742test "containers with single-field enums" {
......@@ -746,21 +746,21 @@ test "containers with single-field enums" {
746746 const C = struct { a: A };
747747 const D = struct { a: B };
748748
749 fn doTheTest() void {
749 fn doTheTest() !void {
750750 var array1 = [1]A{A{ .f1 = {} }};
751751 var array2 = [1]B{B{ .f1 = {} }};
752 expect(array1[0] == .f1);
753 expect(array2[0] == .f1);
752 try expect(array1[0] == .f1);
753 try expect(array2[0] == .f1);
754754
755755 var struct1 = C{ .a = A{ .f1 = {} } };
756756 var struct2 = D{ .a = B{ .f1 = {} } };
757 expect(struct1.a == .f1);
758 expect(struct2.a == .f1);
757 try expect(struct1.a == .f1);
758 try expect(struct2.a == .f1);
759759 }
760760 };
761761
762 S.doTheTest();
763 comptime S.doTheTest();
762 try S.doTheTest();
763 comptime try S.doTheTest();
764764}
765765
766766test "@unionInit on union w/ tag but no fields" {
......@@ -776,18 +776,18 @@ test "@unionInit on union w/ tag but no fields" {
776776 };
777777
778778 comptime {
779 expect(@sizeOf(Data) != 0);
779 try expect(@sizeOf(Data) != 0);
780780 }
781781
782 fn doTheTest() void {
782 fn doTheTest() !void {
783783 var data: Data = .{ .no_op = .{} };
784784 var o = Data.decode(&[_]u8{});
785 expectEqual(Type.no_op, o);
785 try expectEqual(Type.no_op, o);
786786 }
787787 };
788788
789 S.doTheTest();
790 comptime S.doTheTest();
789 try S.doTheTest();
790 comptime try S.doTheTest();
791791}
792792
793793test "union enum type gets a separate scope" {
......@@ -797,10 +797,10 @@ test "union enum type gets a separate scope" {
797797 const foo = 1;
798798 };
799799
800 fn doTheTest() void {
801 expect(!@hasDecl(Tag(U), "foo"));
800 fn doTheTest() !void {
801 try expect(!@hasDecl(Tag(U), "foo"));
802802 }
803803 };
804804
805 S.doTheTest();
805 try S.doTheTest();
806806}
test/behavior/usingnamespace.zig+3-3
......@@ -9,8 +9,8 @@ fn Foo(comptime T: type) type {
99test "usingnamespace inside a generic struct" {
1010 const std2 = Foo(std);
1111 const testing2 = Foo(std.testing);
12 std2.testing.expect(true);
13 testing2.expect(true);
12 try std2.testing.expect(true);
13 try testing2.expect(true);
1414}
1515
1616usingnamespace struct {
......@@ -18,5 +18,5 @@ usingnamespace struct {
1818};
1919
2020test "usingnamespace does not redeclare an imported variable" {
21 comptime std.testing.expect(foo == 42);
21 comptime try std.testing.expect(foo == 42);
2222}
test/behavior/var_args.zig+17-17
......@@ -12,9 +12,9 @@ fn add(args: anytype) i32 {
1212}
1313
1414test "add arbitrary args" {
15 expect(add(.{ @as(i32, 1), @as(i32, 2), @as(i32, 3), @as(i32, 4) }) == 10);
16 expect(add(.{@as(i32, 1234)}) == 1234);
17 expect(add(.{}) == 0);
15 try expect(add(.{ @as(i32, 1), @as(i32, 2), @as(i32, 3), @as(i32, 4) }) == 10);
16 try expect(add(.{@as(i32, 1234)}) == 1234);
17 try expect(add(.{}) == 0);
1818}
1919
2020fn readFirstVarArg(args: anytype) void {
......@@ -26,9 +26,9 @@ test "send void arg to var args" {
2626}
2727
2828test "pass args directly" {
29 expect(addSomeStuff(.{ @as(i32, 1), @as(i32, 2), @as(i32, 3), @as(i32, 4) }) == 10);
30 expect(addSomeStuff(.{@as(i32, 1234)}) == 1234);
31 expect(addSomeStuff(.{}) == 0);
29 try expect(addSomeStuff(.{ @as(i32, 1), @as(i32, 2), @as(i32, 3), @as(i32, 4) }) == 10);
30 try expect(addSomeStuff(.{@as(i32, 1234)}) == 1234);
31 try expect(addSomeStuff(.{}) == 0);
3232}
3333
3434fn addSomeStuff(args: anytype) i32 {
......@@ -36,23 +36,23 @@ fn addSomeStuff(args: anytype) i32 {
3636}
3737
3838test "runtime parameter before var args" {
39 expect(extraFn(10, .{}) == 0);
40 expect(extraFn(10, .{false}) == 1);
41 expect(extraFn(10, .{ false, true }) == 2);
39 try expect((try extraFn(10, .{})) == 0);
40 try expect((try extraFn(10, .{false})) == 1);
41 try expect((try extraFn(10, .{ false, true })) == 2);
4242
4343 comptime {
44 expect(extraFn(10, .{}) == 0);
45 expect(extraFn(10, .{false}) == 1);
46 expect(extraFn(10, .{ false, true }) == 2);
44 try expect((try extraFn(10, .{})) == 0);
45 try expect((try extraFn(10, .{false})) == 1);
46 try expect((try extraFn(10, .{ false, true })) == 2);
4747 }
4848}
4949
50fn extraFn(extra: u32, args: anytype) usize {
50fn extraFn(extra: u32, args: anytype) !usize {
5151 if (args.len >= 1) {
52 expect(args[0] == false);
52 try expect(args[0] == false);
5353 }
5454 if (args.len >= 2) {
55 expect(args[1] == true);
55 try expect(args[1] == true);
5656 }
5757 return args.len;
5858}
......@@ -70,8 +70,8 @@ fn foo2(args: anytype) bool {
7070}
7171
7272test "array of var args functions" {
73 expect(foos[0](.{}));
74 expect(!foos[1](.{}));
73 try expect(foos[0](.{}));
74 try expect(!foos[1](.{}));
7575}
7676
7777test "pass zero length array to var args param" {
test/behavior/vector.zig+280-280
......@@ -9,104 +9,104 @@ const Vector = std.meta.Vector;
99
1010test "implicit cast vector to array - bool" {
1111 const S = struct {
12 fn doTheTest() void {
12 fn doTheTest() !void {
1313 const a: Vector(4, bool) = [_]bool{ true, false, true, false };
1414 const result_array: [4]bool = a;
15 expect(mem.eql(bool, &result_array, &[4]bool{ true, false, true, false }));
15 try expect(mem.eql(bool, &result_array, &[4]bool{ true, false, true, false }));
1616 }
1717 };
18 S.doTheTest();
19 comptime S.doTheTest();
18 try S.doTheTest();
19 comptime try S.doTheTest();
2020}
2121
2222test "vector wrap operators" {
2323 const S = struct {
24 fn doTheTest() void {
24 fn doTheTest() !void {
2525 var v: Vector(4, i32) = [4]i32{ 2147483647, -2, 30, 40 };
2626 var x: Vector(4, i32) = [4]i32{ 1, 2147483647, 3, 4 };
27 expect(mem.eql(i32, &@as([4]i32, v +% x), &[4]i32{ -2147483648, 2147483645, 33, 44 }));
28 expect(mem.eql(i32, &@as([4]i32, v -% x), &[4]i32{ 2147483646, 2147483647, 27, 36 }));
29 expect(mem.eql(i32, &@as([4]i32, v *% x), &[4]i32{ 2147483647, 2, 90, 160 }));
27 try expect(mem.eql(i32, &@as([4]i32, v +% x), &[4]i32{ -2147483648, 2147483645, 33, 44 }));
28 try expect(mem.eql(i32, &@as([4]i32, v -% x), &[4]i32{ 2147483646, 2147483647, 27, 36 }));
29 try expect(mem.eql(i32, &@as([4]i32, v *% x), &[4]i32{ 2147483647, 2, 90, 160 }));
3030 var z: Vector(4, i32) = [4]i32{ 1, 2, 3, -2147483648 };
31 expect(mem.eql(i32, &@as([4]i32, -%z), &[4]i32{ -1, -2, -3, -2147483648 }));
31 try expect(mem.eql(i32, &@as([4]i32, -%z), &[4]i32{ -1, -2, -3, -2147483648 }));
3232 }
3333 };
34 S.doTheTest();
35 comptime S.doTheTest();
34 try S.doTheTest();
35 comptime try S.doTheTest();
3636}
3737
3838test "vector bin compares with mem.eql" {
3939 const S = struct {
40 fn doTheTest() void {
40 fn doTheTest() !void {
4141 var v: Vector(4, i32) = [4]i32{ 2147483647, -2, 30, 40 };
4242 var x: Vector(4, i32) = [4]i32{ 1, 2147483647, 30, 4 };
43 expect(mem.eql(bool, &@as([4]bool, v == x), &[4]bool{ false, false, true, false }));
44 expect(mem.eql(bool, &@as([4]bool, v != x), &[4]bool{ true, true, false, true }));
45 expect(mem.eql(bool, &@as([4]bool, v < x), &[4]bool{ false, true, false, false }));
46 expect(mem.eql(bool, &@as([4]bool, v > x), &[4]bool{ true, false, false, true }));
47 expect(mem.eql(bool, &@as([4]bool, v <= x), &[4]bool{ false, true, true, false }));
48 expect(mem.eql(bool, &@as([4]bool, v >= x), &[4]bool{ true, false, true, true }));
43 try expect(mem.eql(bool, &@as([4]bool, v == x), &[4]bool{ false, false, true, false }));
44 try expect(mem.eql(bool, &@as([4]bool, v != x), &[4]bool{ true, true, false, true }));
45 try expect(mem.eql(bool, &@as([4]bool, v < x), &[4]bool{ false, true, false, false }));
46 try expect(mem.eql(bool, &@as([4]bool, v > x), &[4]bool{ true, false, false, true }));
47 try expect(mem.eql(bool, &@as([4]bool, v <= x), &[4]bool{ false, true, true, false }));
48 try expect(mem.eql(bool, &@as([4]bool, v >= x), &[4]bool{ true, false, true, true }));
4949 }
5050 };
51 S.doTheTest();
52 comptime S.doTheTest();
51 try S.doTheTest();
52 comptime try S.doTheTest();
5353}
5454
5555test "vector int operators" {
5656 const S = struct {
57 fn doTheTest() void {
57 fn doTheTest() !void {
5858 var v: Vector(4, i32) = [4]i32{ 10, 20, 30, 40 };
5959 var x: Vector(4, i32) = [4]i32{ 1, 2, 3, 4 };
60 expect(mem.eql(i32, &@as([4]i32, v + x), &[4]i32{ 11, 22, 33, 44 }));
61 expect(mem.eql(i32, &@as([4]i32, v - x), &[4]i32{ 9, 18, 27, 36 }));
62 expect(mem.eql(i32, &@as([4]i32, v * x), &[4]i32{ 10, 40, 90, 160 }));
63 expect(mem.eql(i32, &@as([4]i32, -v), &[4]i32{ -10, -20, -30, -40 }));
60 try expect(mem.eql(i32, &@as([4]i32, v + x), &[4]i32{ 11, 22, 33, 44 }));
61 try expect(mem.eql(i32, &@as([4]i32, v - x), &[4]i32{ 9, 18, 27, 36 }));
62 try expect(mem.eql(i32, &@as([4]i32, v * x), &[4]i32{ 10, 40, 90, 160 }));
63 try expect(mem.eql(i32, &@as([4]i32, -v), &[4]i32{ -10, -20, -30, -40 }));
6464 }
6565 };
66 S.doTheTest();
67 comptime S.doTheTest();
66 try S.doTheTest();
67 comptime try S.doTheTest();
6868}
6969
7070test "vector float operators" {
7171 const S = struct {
72 fn doTheTest() void {
72 fn doTheTest() !void {
7373 var v: Vector(4, f32) = [4]f32{ 10, 20, 30, 40 };
7474 var x: Vector(4, f32) = [4]f32{ 1, 2, 3, 4 };
75 expect(mem.eql(f32, &@as([4]f32, v + x), &[4]f32{ 11, 22, 33, 44 }));
76 expect(mem.eql(f32, &@as([4]f32, v - x), &[4]f32{ 9, 18, 27, 36 }));
77 expect(mem.eql(f32, &@as([4]f32, v * x), &[4]f32{ 10, 40, 90, 160 }));
78 expect(mem.eql(f32, &@as([4]f32, -x), &[4]f32{ -1, -2, -3, -4 }));
75 try expect(mem.eql(f32, &@as([4]f32, v + x), &[4]f32{ 11, 22, 33, 44 }));
76 try expect(mem.eql(f32, &@as([4]f32, v - x), &[4]f32{ 9, 18, 27, 36 }));
77 try expect(mem.eql(f32, &@as([4]f32, v * x), &[4]f32{ 10, 40, 90, 160 }));
78 try expect(mem.eql(f32, &@as([4]f32, -x), &[4]f32{ -1, -2, -3, -4 }));
7979 }
8080 };
81 S.doTheTest();
82 comptime S.doTheTest();
81 try S.doTheTest();
82 comptime try S.doTheTest();
8383}
8484
8585test "vector bit operators" {
8686 const S = struct {
87 fn doTheTest() void {
87 fn doTheTest() !void {
8888 var v: Vector(4, u8) = [4]u8{ 0b10101010, 0b10101010, 0b10101010, 0b10101010 };
8989 var x: Vector(4, u8) = [4]u8{ 0b11110000, 0b00001111, 0b10101010, 0b01010101 };
90 expect(mem.eql(u8, &@as([4]u8, v ^ x), &[4]u8{ 0b01011010, 0b10100101, 0b00000000, 0b11111111 }));
91 expect(mem.eql(u8, &@as([4]u8, v | x), &[4]u8{ 0b11111010, 0b10101111, 0b10101010, 0b11111111 }));
92 expect(mem.eql(u8, &@as([4]u8, v & x), &[4]u8{ 0b10100000, 0b00001010, 0b10101010, 0b00000000 }));
90 try expect(mem.eql(u8, &@as([4]u8, v ^ x), &[4]u8{ 0b01011010, 0b10100101, 0b00000000, 0b11111111 }));
91 try expect(mem.eql(u8, &@as([4]u8, v | x), &[4]u8{ 0b11111010, 0b10101111, 0b10101010, 0b11111111 }));
92 try expect(mem.eql(u8, &@as([4]u8, v & x), &[4]u8{ 0b10100000, 0b00001010, 0b10101010, 0b00000000 }));
9393 }
9494 };
95 S.doTheTest();
96 comptime S.doTheTest();
95 try S.doTheTest();
96 comptime try S.doTheTest();
9797}
9898
9999test "implicit cast vector to array" {
100100 const S = struct {
101 fn doTheTest() void {
101 fn doTheTest() !void {
102102 var a: Vector(4, i32) = [_]i32{ 1, 2, 3, 4 };
103103 var result_array: [4]i32 = a;
104104 result_array = a;
105 expect(mem.eql(i32, &result_array, &[4]i32{ 1, 2, 3, 4 }));
105 try expect(mem.eql(i32, &result_array, &[4]i32{ 1, 2, 3, 4 }));
106106 }
107107 };
108 S.doTheTest();
109 comptime S.doTheTest();
108 try S.doTheTest();
109 comptime try S.doTheTest();
110110}
111111
112112test "array to vector" {
......@@ -120,141 +120,141 @@ test "vector casts of sizes not divisable by 8" {
120120 if (std.Target.current.os.tag == .dragonfly) return error.SkipZigTest;
121121
122122 const S = struct {
123 fn doTheTest() void {
123 fn doTheTest() !void {
124124 {
125125 var v: Vector(4, u3) = [4]u3{ 5, 2, 3, 0 };
126126 var x: [4]u3 = v;
127 expect(mem.eql(u3, &x, &@as([4]u3, v)));
127 try expect(mem.eql(u3, &x, &@as([4]u3, v)));
128128 }
129129 {
130130 var v: Vector(4, u2) = [4]u2{ 1, 2, 3, 0 };
131131 var x: [4]u2 = v;
132 expect(mem.eql(u2, &x, &@as([4]u2, v)));
132 try expect(mem.eql(u2, &x, &@as([4]u2, v)));
133133 }
134134 {
135135 var v: Vector(4, u1) = [4]u1{ 1, 0, 1, 0 };
136136 var x: [4]u1 = v;
137 expect(mem.eql(u1, &x, &@as([4]u1, v)));
137 try expect(mem.eql(u1, &x, &@as([4]u1, v)));
138138 }
139139 {
140140 var v: Vector(4, bool) = [4]bool{ false, false, true, false };
141141 var x: [4]bool = v;
142 expect(mem.eql(bool, &x, &@as([4]bool, v)));
142 try expect(mem.eql(bool, &x, &@as([4]bool, v)));
143143 }
144144 }
145145 };
146 S.doTheTest();
147 comptime S.doTheTest();
146 try S.doTheTest();
147 comptime try S.doTheTest();
148148}
149149
150150test "vector @splat" {
151151 const S = struct {
152 fn testForT(comptime N: comptime_int, v: anytype) void {
152 fn testForT(comptime N: comptime_int, v: anytype) !void {
153153 const T = @TypeOf(v);
154154 var vec = @splat(N, v);
155 expectEqual(Vector(N, T), @TypeOf(vec));
155 try expectEqual(Vector(N, T), @TypeOf(vec));
156156 var as_array = @as([N]T, vec);
157 for (as_array) |elem| expectEqual(v, elem);
157 for (as_array) |elem| try expectEqual(v, elem);
158158 }
159 fn doTheTest() void {
159 fn doTheTest() !void {
160160 // Splats with multiple-of-8 bit types that fill a 128bit vector.
161 testForT(16, @as(u8, 0xEE));
162 testForT(8, @as(u16, 0xBEEF));
163 testForT(4, @as(u32, 0xDEADBEEF));
164 testForT(2, @as(u64, 0xCAFEF00DDEADBEEF));
161 try testForT(16, @as(u8, 0xEE));
162 try testForT(8, @as(u16, 0xBEEF));
163 try testForT(4, @as(u32, 0xDEADBEEF));
164 try testForT(2, @as(u64, 0xCAFEF00DDEADBEEF));
165165
166 testForT(8, @as(f16, 3.1415));
167 testForT(4, @as(f32, 3.1415));
168 testForT(2, @as(f64, 3.1415));
166 try testForT(8, @as(f16, 3.1415));
167 try testForT(4, @as(f32, 3.1415));
168 try testForT(2, @as(f64, 3.1415));
169169
170170 // Same but fill more than 128 bits.
171 testForT(16 * 2, @as(u8, 0xEE));
172 testForT(8 * 2, @as(u16, 0xBEEF));
173 testForT(4 * 2, @as(u32, 0xDEADBEEF));
174 testForT(2 * 2, @as(u64, 0xCAFEF00DDEADBEEF));
175
176 testForT(8 * 2, @as(f16, 3.1415));
177 testForT(4 * 2, @as(f32, 3.1415));
178 testForT(2 * 2, @as(f64, 3.1415));
171 try testForT(16 * 2, @as(u8, 0xEE));
172 try testForT(8 * 2, @as(u16, 0xBEEF));
173 try testForT(4 * 2, @as(u32, 0xDEADBEEF));
174 try testForT(2 * 2, @as(u64, 0xCAFEF00DDEADBEEF));
175
176 try testForT(8 * 2, @as(f16, 3.1415));
177 try testForT(4 * 2, @as(f32, 3.1415));
178 try testForT(2 * 2, @as(f64, 3.1415));
179179 }
180180 };
181 S.doTheTest();
182 comptime S.doTheTest();
181 try S.doTheTest();
182 comptime try S.doTheTest();
183183}
184184
185185test "load vector elements via comptime index" {
186186 const S = struct {
187 fn doTheTest() void {
187 fn doTheTest() !void {
188188 var v: Vector(4, i32) = [_]i32{ 1, 2, 3, undefined };
189 expect(v[0] == 1);
190 expect(v[1] == 2);
191 expect(loadv(&v[2]) == 3);
189 try expect(v[0] == 1);
190 try expect(v[1] == 2);
191 try expect(loadv(&v[2]) == 3);
192192 }
193193 fn loadv(ptr: anytype) i32 {
194194 return ptr.*;
195195 }
196196 };
197197
198 S.doTheTest();
199 comptime S.doTheTest();
198 try S.doTheTest();
199 comptime try S.doTheTest();
200200}
201201
202202test "store vector elements via comptime index" {
203203 const S = struct {
204 fn doTheTest() void {
204 fn doTheTest() !void {
205205 var v: Vector(4, i32) = [_]i32{ 1, 5, 3, undefined };
206206
207207 v[2] = 42;
208 expect(v[1] == 5);
208 try expect(v[1] == 5);
209209 v[3] = -364;
210 expect(v[2] == 42);
211 expect(-364 == v[3]);
210 try expect(v[2] == 42);
211 try expect(-364 == v[3]);
212212
213213 storev(&v[0], 100);
214 expect(v[0] == 100);
214 try expect(v[0] == 100);
215215 }
216216 fn storev(ptr: anytype, x: i32) void {
217217 ptr.* = x;
218218 }
219219 };
220220
221 S.doTheTest();
222 comptime S.doTheTest();
221 try S.doTheTest();
222 comptime try S.doTheTest();
223223}
224224
225225test "load vector elements via runtime index" {
226226 const S = struct {
227 fn doTheTest() void {
227 fn doTheTest() !void {
228228 var v: Vector(4, i32) = [_]i32{ 1, 2, 3, undefined };
229229 var i: u32 = 0;
230 expect(v[i] == 1);
230 try expect(v[i] == 1);
231231 i += 1;
232 expect(v[i] == 2);
232 try expect(v[i] == 2);
233233 i += 1;
234 expect(v[i] == 3);
234 try expect(v[i] == 3);
235235 }
236236 };
237237
238 S.doTheTest();
239 comptime S.doTheTest();
238 try S.doTheTest();
239 comptime try S.doTheTest();
240240}
241241
242242test "store vector elements via runtime index" {
243243 const S = struct {
244 fn doTheTest() void {
244 fn doTheTest() !void {
245245 var v: Vector(4, i32) = [_]i32{ 1, 5, 3, undefined };
246246 var i: u32 = 2;
247247 v[i] = 1;
248 expect(v[1] == 5);
249 expect(v[2] == 1);
248 try expect(v[1] == 5);
249 try expect(v[2] == 1);
250250 i += 1;
251251 v[i] = -364;
252 expect(-364 == v[3]);
252 try expect(-364 == v[3]);
253253 }
254254 };
255255
256 S.doTheTest();
257 comptime S.doTheTest();
256 try S.doTheTest();
257 comptime try S.doTheTest();
258258}
259259
260260test "initialize vector which is a struct field" {
......@@ -263,155 +263,155 @@ test "initialize vector which is a struct field" {
263263 };
264264
265265 const S = struct {
266 fn doTheTest() void {
266 fn doTheTest() !void {
267267 var foo = Vec4Obj{
268268 .data = [_]f32{ 1, 2, 3, 4 },
269269 };
270270 }
271271 };
272 S.doTheTest();
273 comptime S.doTheTest();
272 try S.doTheTest();
273 comptime try S.doTheTest();
274274}
275275
276276test "vector comparison operators" {
277277 const S = struct {
278 fn doTheTest() void {
278 fn doTheTest() !void {
279279 {
280280 const v1: Vector(4, bool) = [_]bool{ true, false, true, false };
281281 const v2: Vector(4, bool) = [_]bool{ false, true, false, true };
282 expectEqual(@splat(4, true), v1 == v1);
283 expectEqual(@splat(4, false), v1 == v2);
284 expectEqual(@splat(4, true), v1 != v2);
285 expectEqual(@splat(4, false), v2 != v2);
282 try expectEqual(@splat(4, true), v1 == v1);
283 try expectEqual(@splat(4, false), v1 == v2);
284 try expectEqual(@splat(4, true), v1 != v2);
285 try expectEqual(@splat(4, false), v2 != v2);
286286 }
287287 {
288288 const v1 = @splat(4, @as(u32, 0xc0ffeeee));
289289 const v2: Vector(4, c_uint) = v1;
290290 const v3 = @splat(4, @as(u32, 0xdeadbeef));
291 expectEqual(@splat(4, true), v1 == v2);
292 expectEqual(@splat(4, false), v1 == v3);
293 expectEqual(@splat(4, true), v1 != v3);
294 expectEqual(@splat(4, false), v1 != v2);
291 try expectEqual(@splat(4, true), v1 == v2);
292 try expectEqual(@splat(4, false), v1 == v3);
293 try expectEqual(@splat(4, true), v1 != v3);
294 try expectEqual(@splat(4, false), v1 != v2);
295295 }
296296 {
297297 // Comptime-known LHS/RHS
298298 var v1: @Vector(4, u32) = [_]u32{ 2, 1, 2, 1 };
299299 const v2 = @splat(4, @as(u32, 2));
300300 const v3: @Vector(4, bool) = [_]bool{ true, false, true, false };
301 expectEqual(v3, v1 == v2);
302 expectEqual(v3, v2 == v1);
301 try expectEqual(v3, v1 == v2);
302 try expectEqual(v3, v2 == v1);
303303 }
304304 }
305305 };
306 S.doTheTest();
307 comptime S.doTheTest();
306 try S.doTheTest();
307 comptime try S.doTheTest();
308308}
309309
310310test "vector division operators" {
311311 const S = struct {
312 fn doTheTestDiv(comptime T: type, x: Vector(4, T), y: Vector(4, T)) void {
312 fn doTheTestDiv(comptime T: type, x: Vector(4, T), y: Vector(4, T)) !void {
313313 if (!comptime std.meta.trait.isSignedInt(T)) {
314314 const d0 = x / y;
315315 for (@as([4]T, d0)) |v, i| {
316 expectEqual(x[i] / y[i], v);
316 try expectEqual(x[i] / y[i], v);
317317 }
318318 }
319319 const d1 = @divExact(x, y);
320320 for (@as([4]T, d1)) |v, i| {
321 expectEqual(@divExact(x[i], y[i]), v);
321 try expectEqual(@divExact(x[i], y[i]), v);
322322 }
323323 const d2 = @divFloor(x, y);
324324 for (@as([4]T, d2)) |v, i| {
325 expectEqual(@divFloor(x[i], y[i]), v);
325 try expectEqual(@divFloor(x[i], y[i]), v);
326326 }
327327 const d3 = @divTrunc(x, y);
328328 for (@as([4]T, d3)) |v, i| {
329 expectEqual(@divTrunc(x[i], y[i]), v);
329 try expectEqual(@divTrunc(x[i], y[i]), v);
330330 }
331331 }
332332
333 fn doTheTestMod(comptime T: type, x: Vector(4, T), y: Vector(4, T)) void {
333 fn doTheTestMod(comptime T: type, x: Vector(4, T), y: Vector(4, T)) !void {
334334 if ((!comptime std.meta.trait.isSignedInt(T)) and @typeInfo(T) != .Float) {
335335 const r0 = x % y;
336336 for (@as([4]T, r0)) |v, i| {
337 expectEqual(x[i] % y[i], v);
337 try expectEqual(x[i] % y[i], v);
338338 }
339339 }
340340 const r1 = @mod(x, y);
341341 for (@as([4]T, r1)) |v, i| {
342 expectEqual(@mod(x[i], y[i]), v);
342 try expectEqual(@mod(x[i], y[i]), v);
343343 }
344344 const r2 = @rem(x, y);
345345 for (@as([4]T, r2)) |v, i| {
346 expectEqual(@rem(x[i], y[i]), v);
346 try expectEqual(@rem(x[i], y[i]), v);
347347 }
348348 }
349349
350 fn doTheTest() void {
350 fn doTheTest() !void {
351351 // https://github.com/ziglang/zig/issues/4952
352352 if (builtin.target.os.tag != .windows) {
353 doTheTestDiv(f16, [4]f16{ 4.0, -4.0, 4.0, -4.0 }, [4]f16{ 1.0, 2.0, -1.0, -2.0 });
353 try doTheTestDiv(f16, [4]f16{ 4.0, -4.0, 4.0, -4.0 }, [4]f16{ 1.0, 2.0, -1.0, -2.0 });
354354 }
355355
356 doTheTestDiv(f32, [4]f32{ 4.0, -4.0, 4.0, -4.0 }, [4]f32{ 1.0, 2.0, -1.0, -2.0 });
357 doTheTestDiv(f64, [4]f64{ 4.0, -4.0, 4.0, -4.0 }, [4]f64{ 1.0, 2.0, -1.0, -2.0 });
356 try doTheTestDiv(f32, [4]f32{ 4.0, -4.0, 4.0, -4.0 }, [4]f32{ 1.0, 2.0, -1.0, -2.0 });
357 try doTheTestDiv(f64, [4]f64{ 4.0, -4.0, 4.0, -4.0 }, [4]f64{ 1.0, 2.0, -1.0, -2.0 });
358358
359359 // https://github.com/ziglang/zig/issues/4952
360360 if (builtin.target.os.tag != .windows) {
361 doTheTestMod(f16, [4]f16{ 4.0, -4.0, 4.0, -4.0 }, [4]f16{ 1.0, 2.0, 0.5, 3.0 });
361 try doTheTestMod(f16, [4]f16{ 4.0, -4.0, 4.0, -4.0 }, [4]f16{ 1.0, 2.0, 0.5, 3.0 });
362362 }
363 doTheTestMod(f32, [4]f32{ 4.0, -4.0, 4.0, -4.0 }, [4]f32{ 1.0, 2.0, 0.5, 3.0 });
364 doTheTestMod(f64, [4]f64{ 4.0, -4.0, 4.0, -4.0 }, [4]f64{ 1.0, 2.0, 0.5, 3.0 });
365
366 doTheTestDiv(i8, [4]i8{ 4, -4, 4, -4 }, [4]i8{ 1, 2, -1, -2 });
367 doTheTestDiv(i16, [4]i16{ 4, -4, 4, -4 }, [4]i16{ 1, 2, -1, -2 });
368 doTheTestDiv(i32, [4]i32{ 4, -4, 4, -4 }, [4]i32{ 1, 2, -1, -2 });
369 doTheTestDiv(i64, [4]i64{ 4, -4, 4, -4 }, [4]i64{ 1, 2, -1, -2 });
370
371 doTheTestMod(i8, [4]i8{ 4, -4, 4, -4 }, [4]i8{ 1, 2, 4, 8 });
372 doTheTestMod(i16, [4]i16{ 4, -4, 4, -4 }, [4]i16{ 1, 2, 4, 8 });
373 doTheTestMod(i32, [4]i32{ 4, -4, 4, -4 }, [4]i32{ 1, 2, 4, 8 });
374 doTheTestMod(i64, [4]i64{ 4, -4, 4, -4 }, [4]i64{ 1, 2, 4, 8 });
375
376 doTheTestDiv(u8, [4]u8{ 1, 2, 4, 8 }, [4]u8{ 1, 1, 2, 4 });
377 doTheTestDiv(u16, [4]u16{ 1, 2, 4, 8 }, [4]u16{ 1, 1, 2, 4 });
378 doTheTestDiv(u32, [4]u32{ 1, 2, 4, 8 }, [4]u32{ 1, 1, 2, 4 });
379 doTheTestDiv(u64, [4]u64{ 1, 2, 4, 8 }, [4]u64{ 1, 1, 2, 4 });
380
381 doTheTestMod(u8, [4]u8{ 1, 2, 4, 8 }, [4]u8{ 1, 1, 2, 4 });
382 doTheTestMod(u16, [4]u16{ 1, 2, 4, 8 }, [4]u16{ 1, 1, 2, 4 });
383 doTheTestMod(u32, [4]u32{ 1, 2, 4, 8 }, [4]u32{ 1, 1, 2, 4 });
384 doTheTestMod(u64, [4]u64{ 1, 2, 4, 8 }, [4]u64{ 1, 1, 2, 4 });
363 try doTheTestMod(f32, [4]f32{ 4.0, -4.0, 4.0, -4.0 }, [4]f32{ 1.0, 2.0, 0.5, 3.0 });
364 try doTheTestMod(f64, [4]f64{ 4.0, -4.0, 4.0, -4.0 }, [4]f64{ 1.0, 2.0, 0.5, 3.0 });
365
366 try doTheTestDiv(i8, [4]i8{ 4, -4, 4, -4 }, [4]i8{ 1, 2, -1, -2 });
367 try doTheTestDiv(i16, [4]i16{ 4, -4, 4, -4 }, [4]i16{ 1, 2, -1, -2 });
368 try doTheTestDiv(i32, [4]i32{ 4, -4, 4, -4 }, [4]i32{ 1, 2, -1, -2 });
369 try doTheTestDiv(i64, [4]i64{ 4, -4, 4, -4 }, [4]i64{ 1, 2, -1, -2 });
370
371 try doTheTestMod(i8, [4]i8{ 4, -4, 4, -4 }, [4]i8{ 1, 2, 4, 8 });
372 try doTheTestMod(i16, [4]i16{ 4, -4, 4, -4 }, [4]i16{ 1, 2, 4, 8 });
373 try doTheTestMod(i32, [4]i32{ 4, -4, 4, -4 }, [4]i32{ 1, 2, 4, 8 });
374 try doTheTestMod(i64, [4]i64{ 4, -4, 4, -4 }, [4]i64{ 1, 2, 4, 8 });
375
376 try doTheTestDiv(u8, [4]u8{ 1, 2, 4, 8 }, [4]u8{ 1, 1, 2, 4 });
377 try doTheTestDiv(u16, [4]u16{ 1, 2, 4, 8 }, [4]u16{ 1, 1, 2, 4 });
378 try doTheTestDiv(u32, [4]u32{ 1, 2, 4, 8 }, [4]u32{ 1, 1, 2, 4 });
379 try doTheTestDiv(u64, [4]u64{ 1, 2, 4, 8 }, [4]u64{ 1, 1, 2, 4 });
380
381 try doTheTestMod(u8, [4]u8{ 1, 2, 4, 8 }, [4]u8{ 1, 1, 2, 4 });
382 try doTheTestMod(u16, [4]u16{ 1, 2, 4, 8 }, [4]u16{ 1, 1, 2, 4 });
383 try doTheTestMod(u32, [4]u32{ 1, 2, 4, 8 }, [4]u32{ 1, 1, 2, 4 });
384 try doTheTestMod(u64, [4]u64{ 1, 2, 4, 8 }, [4]u64{ 1, 1, 2, 4 });
385385 }
386386 };
387387
388 S.doTheTest();
389 comptime S.doTheTest();
388 try S.doTheTest();
389 comptime try S.doTheTest();
390390}
391391
392392test "vector bitwise not operator" {
393393 const S = struct {
394 fn doTheTestNot(comptime T: type, x: Vector(4, T)) void {
394 fn doTheTestNot(comptime T: type, x: Vector(4, T)) !void {
395395 var y = ~x;
396396 for (@as([4]T, y)) |v, i| {
397 expectEqual(~x[i], v);
397 try expectEqual(~x[i], v);
398398 }
399399 }
400 fn doTheTest() void {
401 doTheTestNot(u8, [_]u8{ 0, 2, 4, 255 });
402 doTheTestNot(u16, [_]u16{ 0, 2, 4, 255 });
403 doTheTestNot(u32, [_]u32{ 0, 2, 4, 255 });
404 doTheTestNot(u64, [_]u64{ 0, 2, 4, 255 });
405
406 doTheTestNot(u8, [_]u8{ 0, 2, 4, 255 });
407 doTheTestNot(u16, [_]u16{ 0, 2, 4, 255 });
408 doTheTestNot(u32, [_]u32{ 0, 2, 4, 255 });
409 doTheTestNot(u64, [_]u64{ 0, 2, 4, 255 });
400 fn doTheTest() !void {
401 try doTheTestNot(u8, [_]u8{ 0, 2, 4, 255 });
402 try doTheTestNot(u16, [_]u16{ 0, 2, 4, 255 });
403 try doTheTestNot(u32, [_]u32{ 0, 2, 4, 255 });
404 try doTheTestNot(u64, [_]u64{ 0, 2, 4, 255 });
405
406 try doTheTestNot(u8, [_]u8{ 0, 2, 4, 255 });
407 try doTheTestNot(u16, [_]u16{ 0, 2, 4, 255 });
408 try doTheTestNot(u32, [_]u32{ 0, 2, 4, 255 });
409 try doTheTestNot(u64, [_]u64{ 0, 2, 4, 255 });
410410 }
411411 };
412412
413 S.doTheTest();
414 comptime S.doTheTest();
413 try S.doTheTest();
414 comptime try S.doTheTest();
415415}
416416
417417test "vector shift operators" {
......@@ -419,7 +419,7 @@ test "vector shift operators" {
419419 if (builtin.target.os.tag == .wasi) return error.SkipZigTest;
420420
421421 const S = struct {
422 fn doTheTestShift(x: anytype, y: anytype) void {
422 fn doTheTestShift(x: anytype, y: anytype) !void {
423423 const N = @typeInfo(@TypeOf(x)).Array.len;
424424 const TX = @typeInfo(@TypeOf(x)).Array.child;
425425 const TY = @typeInfo(@TypeOf(y)).Array.child;
......@@ -429,14 +429,14 @@ test "vector shift operators" {
429429
430430 var z0 = xv >> yv;
431431 for (@as([N]TX, z0)) |v, i| {
432 expectEqual(x[i] >> y[i], v);
432 try expectEqual(x[i] >> y[i], v);
433433 }
434434 var z1 = xv << yv;
435435 for (@as([N]TX, z1)) |v, i| {
436 expectEqual(x[i] << y[i], v);
436 try expectEqual(x[i] << y[i], v);
437437 }
438438 }
439 fn doTheTestShiftExact(x: anytype, y: anytype, dir: enum { Left, Right }) void {
439 fn doTheTestShiftExact(x: anytype, y: anytype, dir: enum { Left, Right }) !void {
440440 const N = @typeInfo(@TypeOf(x)).Array.len;
441441 const TX = @typeInfo(@TypeOf(x)).Array.child;
442442 const TY = @typeInfo(@TypeOf(y)).Array.child;
......@@ -447,33 +447,33 @@ test "vector shift operators" {
447447 var z = if (dir == .Left) @shlExact(xv, yv) else @shrExact(xv, yv);
448448 for (@as([N]TX, z)) |v, i| {
449449 const check = if (dir == .Left) x[i] << y[i] else x[i] >> y[i];
450 expectEqual(check, v);
450 try expectEqual(check, v);
451451 }
452452 }
453 fn doTheTest() void {
454 doTheTestShift([_]u8{ 0, 2, 4, math.maxInt(u8) }, [_]u3{ 2, 0, 2, 7 });
455 doTheTestShift([_]u16{ 0, 2, 4, math.maxInt(u16) }, [_]u4{ 2, 0, 2, 15 });
456 doTheTestShift([_]u24{ 0, 2, 4, math.maxInt(u24) }, [_]u5{ 2, 0, 2, 23 });
457 doTheTestShift([_]u32{ 0, 2, 4, math.maxInt(u32) }, [_]u5{ 2, 0, 2, 31 });
458 doTheTestShift([_]u64{ 0xfe, math.maxInt(u64) }, [_]u6{ 0, 63 });
459
460 doTheTestShift([_]i8{ 0, 2, 4, math.maxInt(i8) }, [_]u3{ 2, 0, 2, 7 });
461 doTheTestShift([_]i16{ 0, 2, 4, math.maxInt(i16) }, [_]u4{ 2, 0, 2, 7 });
462 doTheTestShift([_]i24{ 0, 2, 4, math.maxInt(i24) }, [_]u5{ 2, 0, 2, 7 });
463 doTheTestShift([_]i32{ 0, 2, 4, math.maxInt(i32) }, [_]u5{ 2, 0, 2, 7 });
464 doTheTestShift([_]i64{ 0xfe, math.maxInt(i64) }, [_]u6{ 0, 63 });
465
466 doTheTestShiftExact([_]u8{ 0, 1, 1 << 7, math.maxInt(u8) ^ 1 }, [_]u3{ 4, 0, 7, 1 }, .Right);
467 doTheTestShiftExact([_]u16{ 0, 1, 1 << 15, math.maxInt(u16) ^ 1 }, [_]u4{ 4, 0, 15, 1 }, .Right);
468 doTheTestShiftExact([_]u24{ 0, 1, 1 << 23, math.maxInt(u24) ^ 1 }, [_]u5{ 4, 0, 23, 1 }, .Right);
469 doTheTestShiftExact([_]u32{ 0, 1, 1 << 31, math.maxInt(u32) ^ 1 }, [_]u5{ 4, 0, 31, 1 }, .Right);
470 doTheTestShiftExact([_]u64{ 1 << 63, 1 }, [_]u6{ 63, 0 }, .Right);
471
472 doTheTestShiftExact([_]u8{ 0, 1, 1, math.maxInt(u8) ^ (1 << 7) }, [_]u3{ 4, 0, 7, 1 }, .Left);
473 doTheTestShiftExact([_]u16{ 0, 1, 1, math.maxInt(u16) ^ (1 << 15) }, [_]u4{ 4, 0, 15, 1 }, .Left);
474 doTheTestShiftExact([_]u24{ 0, 1, 1, math.maxInt(u24) ^ (1 << 23) }, [_]u5{ 4, 0, 23, 1 }, .Left);
475 doTheTestShiftExact([_]u32{ 0, 1, 1, math.maxInt(u32) ^ (1 << 31) }, [_]u5{ 4, 0, 31, 1 }, .Left);
476 doTheTestShiftExact([_]u64{ 1 << 63, 1 }, [_]u6{ 0, 63 }, .Left);
453 fn doTheTest() !void {
454 try doTheTestShift([_]u8{ 0, 2, 4, math.maxInt(u8) }, [_]u3{ 2, 0, 2, 7 });
455 try doTheTestShift([_]u16{ 0, 2, 4, math.maxInt(u16) }, [_]u4{ 2, 0, 2, 15 });
456 try doTheTestShift([_]u24{ 0, 2, 4, math.maxInt(u24) }, [_]u5{ 2, 0, 2, 23 });
457 try doTheTestShift([_]u32{ 0, 2, 4, math.maxInt(u32) }, [_]u5{ 2, 0, 2, 31 });
458 try doTheTestShift([_]u64{ 0xfe, math.maxInt(u64) }, [_]u6{ 0, 63 });
459
460 try doTheTestShift([_]i8{ 0, 2, 4, math.maxInt(i8) }, [_]u3{ 2, 0, 2, 7 });
461 try doTheTestShift([_]i16{ 0, 2, 4, math.maxInt(i16) }, [_]u4{ 2, 0, 2, 7 });
462 try doTheTestShift([_]i24{ 0, 2, 4, math.maxInt(i24) }, [_]u5{ 2, 0, 2, 7 });
463 try doTheTestShift([_]i32{ 0, 2, 4, math.maxInt(i32) }, [_]u5{ 2, 0, 2, 7 });
464 try doTheTestShift([_]i64{ 0xfe, math.maxInt(i64) }, [_]u6{ 0, 63 });
465
466 try doTheTestShiftExact([_]u8{ 0, 1, 1 << 7, math.maxInt(u8) ^ 1 }, [_]u3{ 4, 0, 7, 1 }, .Right);
467 try doTheTestShiftExact([_]u16{ 0, 1, 1 << 15, math.maxInt(u16) ^ 1 }, [_]u4{ 4, 0, 15, 1 }, .Right);
468 try doTheTestShiftExact([_]u24{ 0, 1, 1 << 23, math.maxInt(u24) ^ 1 }, [_]u5{ 4, 0, 23, 1 }, .Right);
469 try doTheTestShiftExact([_]u32{ 0, 1, 1 << 31, math.maxInt(u32) ^ 1 }, [_]u5{ 4, 0, 31, 1 }, .Right);
470 try doTheTestShiftExact([_]u64{ 1 << 63, 1 }, [_]u6{ 63, 0 }, .Right);
471
472 try doTheTestShiftExact([_]u8{ 0, 1, 1, math.maxInt(u8) ^ (1 << 7) }, [_]u3{ 4, 0, 7, 1 }, .Left);
473 try doTheTestShiftExact([_]u16{ 0, 1, 1, math.maxInt(u16) ^ (1 << 15) }, [_]u4{ 4, 0, 15, 1 }, .Left);
474 try doTheTestShiftExact([_]u24{ 0, 1, 1, math.maxInt(u24) ^ (1 << 23) }, [_]u5{ 4, 0, 23, 1 }, .Left);
475 try doTheTestShiftExact([_]u32{ 0, 1, 1, math.maxInt(u32) ^ (1 << 31) }, [_]u5{ 4, 0, 31, 1 }, .Left);
476 try doTheTestShiftExact([_]u64{ 1 << 63, 1 }, [_]u6{ 0, 63 }, .Left);
477477 }
478478 };
479479
......@@ -500,19 +500,19 @@ test "vector shift operators" {
500500 else => {},
501501 }
502502
503 S.doTheTest();
504 comptime S.doTheTest();
503 try S.doTheTest();
504 comptime try S.doTheTest();
505505}
506506
507507test "vector reduce operation" {
508508 const S = struct {
509 fn doTheTestReduce(comptime op: std.builtin.ReduceOp, x: anytype, expected: anytype) void {
509 fn doTheTestReduce(comptime op: std.builtin.ReduceOp, x: anytype, expected: anytype) !void {
510510 const N = @typeInfo(@TypeOf(x)).Array.len;
511511 const TX = @typeInfo(@TypeOf(x)).Array.child;
512512
513513 var r = @reduce(op, @as(Vector(N, TX), x));
514514 switch (@typeInfo(TX)) {
515 .Int, .Bool => expectEqual(expected, r),
515 .Int, .Bool => try expectEqual(expected, r),
516516 .Float => {
517517 const expected_nan = math.isNan(expected);
518518 const got_nan = math.isNan(r);
......@@ -521,120 +521,120 @@ test "vector reduce operation" {
521521 // Do this check explicitly as two NaN values are never
522522 // equal.
523523 } else {
524 expectApproxEqRel(expected, r, math.sqrt(math.epsilon(TX)));
524 try expectApproxEqRel(expected, r, math.sqrt(math.epsilon(TX)));
525525 }
526526 },
527527 else => unreachable,
528528 }
529529 }
530 fn doTheTest() void {
531 doTheTestReduce(.Add, [4]i16{ -9, -99, -999, -9999 }, @as(i32, -11106));
532 doTheTestReduce(.Add, [4]u16{ 9, 99, 999, 9999 }, @as(u32, 11106));
533 doTheTestReduce(.Add, [4]i32{ -9, -99, -999, -9999 }, @as(i32, -11106));
534 doTheTestReduce(.Add, [4]u32{ 9, 99, 999, 9999 }, @as(u32, 11106));
535 doTheTestReduce(.Add, [4]i64{ -9, -99, -999, -9999 }, @as(i64, -11106));
536 doTheTestReduce(.Add, [4]u64{ 9, 99, 999, 9999 }, @as(u64, 11106));
537 doTheTestReduce(.Add, [4]i128{ -9, -99, -999, -9999 }, @as(i128, -11106));
538 doTheTestReduce(.Add, [4]u128{ 9, 99, 999, 9999 }, @as(u128, 11106));
539 doTheTestReduce(.Add, [4]f16{ -1.9, 5.1, -60.3, 100.0 }, @as(f16, 42.9));
540 doTheTestReduce(.Add, [4]f32{ -1.9, 5.1, -60.3, 100.0 }, @as(f32, 42.9));
541 doTheTestReduce(.Add, [4]f64{ -1.9, 5.1, -60.3, 100.0 }, @as(f64, 42.9));
542
543 doTheTestReduce(.And, [4]bool{ true, false, true, true }, @as(bool, false));
544 doTheTestReduce(.And, [4]u1{ 1, 0, 1, 1 }, @as(u1, 0));
545 doTheTestReduce(.And, [4]u16{ 0xffff, 0xff55, 0xaaff, 0x1010 }, @as(u16, 0x10));
546 doTheTestReduce(.And, [4]u32{ 0xffffffff, 0xffff5555, 0xaaaaffff, 0x10101010 }, @as(u32, 0x1010));
547 doTheTestReduce(.And, [4]u64{ 0xffffffff, 0xffff5555, 0xaaaaffff, 0x10101010 }, @as(u64, 0x1010));
548
549 doTheTestReduce(.Min, [4]i16{ -1, 2, 3, 4 }, @as(i16, -1));
550 doTheTestReduce(.Min, [4]u16{ 1, 2, 3, 4 }, @as(u16, 1));
551 doTheTestReduce(.Min, [4]i32{ 1234567, -386, 0, 3 }, @as(i32, -386));
552 doTheTestReduce(.Min, [4]u32{ 99, 9999, 9, 99999 }, @as(u32, 9));
530 fn doTheTest() !void {
531 try doTheTestReduce(.Add, [4]i16{ -9, -99, -999, -9999 }, @as(i32, -11106));
532 try doTheTestReduce(.Add, [4]u16{ 9, 99, 999, 9999 }, @as(u32, 11106));
533 try doTheTestReduce(.Add, [4]i32{ -9, -99, -999, -9999 }, @as(i32, -11106));
534 try doTheTestReduce(.Add, [4]u32{ 9, 99, 999, 9999 }, @as(u32, 11106));
535 try doTheTestReduce(.Add, [4]i64{ -9, -99, -999, -9999 }, @as(i64, -11106));
536 try doTheTestReduce(.Add, [4]u64{ 9, 99, 999, 9999 }, @as(u64, 11106));
537 try doTheTestReduce(.Add, [4]i128{ -9, -99, -999, -9999 }, @as(i128, -11106));
538 try doTheTestReduce(.Add, [4]u128{ 9, 99, 999, 9999 }, @as(u128, 11106));
539 try doTheTestReduce(.Add, [4]f16{ -1.9, 5.1, -60.3, 100.0 }, @as(f16, 42.9));
540 try doTheTestReduce(.Add, [4]f32{ -1.9, 5.1, -60.3, 100.0 }, @as(f32, 42.9));
541 try doTheTestReduce(.Add, [4]f64{ -1.9, 5.1, -60.3, 100.0 }, @as(f64, 42.9));
542
543 try doTheTestReduce(.And, [4]bool{ true, false, true, true }, @as(bool, false));
544 try doTheTestReduce(.And, [4]u1{ 1, 0, 1, 1 }, @as(u1, 0));
545 try doTheTestReduce(.And, [4]u16{ 0xffff, 0xff55, 0xaaff, 0x1010 }, @as(u16, 0x10));
546 try doTheTestReduce(.And, [4]u32{ 0xffffffff, 0xffff5555, 0xaaaaffff, 0x10101010 }, @as(u32, 0x1010));
547 try doTheTestReduce(.And, [4]u64{ 0xffffffff, 0xffff5555, 0xaaaaffff, 0x10101010 }, @as(u64, 0x1010));
548
549 try doTheTestReduce(.Min, [4]i16{ -1, 2, 3, 4 }, @as(i16, -1));
550 try doTheTestReduce(.Min, [4]u16{ 1, 2, 3, 4 }, @as(u16, 1));
551 try doTheTestReduce(.Min, [4]i32{ 1234567, -386, 0, 3 }, @as(i32, -386));
552 try doTheTestReduce(.Min, [4]u32{ 99, 9999, 9, 99999 }, @as(u32, 9));
553553
554554 // LLVM 11 ERROR: Cannot select type
555555 // https://github.com/ziglang/zig/issues/7138
556556 if (builtin.target.cpu.arch != .aarch64) {
557 doTheTestReduce(.Min, [4]i64{ 1234567, -386, 0, 3 }, @as(i64, -386));
558 doTheTestReduce(.Min, [4]u64{ 99, 9999, 9, 99999 }, @as(u64, 9));
557 try doTheTestReduce(.Min, [4]i64{ 1234567, -386, 0, 3 }, @as(i64, -386));
558 try doTheTestReduce(.Min, [4]u64{ 99, 9999, 9, 99999 }, @as(u64, 9));
559559 }
560560
561 doTheTestReduce(.Min, [4]i128{ 1234567, -386, 0, 3 }, @as(i128, -386));
562 doTheTestReduce(.Min, [4]u128{ 99, 9999, 9, 99999 }, @as(u128, 9));
563 doTheTestReduce(.Min, [4]f16{ -10.3, 10.0e9, 13.0, -100.0 }, @as(f16, -100.0));
564 doTheTestReduce(.Min, [4]f32{ -10.3, 10.0e9, 13.0, -100.0 }, @as(f32, -100.0));
565 doTheTestReduce(.Min, [4]f64{ -10.3, 10.0e9, 13.0, -100.0 }, @as(f64, -100.0));
561 try doTheTestReduce(.Min, [4]i128{ 1234567, -386, 0, 3 }, @as(i128, -386));
562 try doTheTestReduce(.Min, [4]u128{ 99, 9999, 9, 99999 }, @as(u128, 9));
563 try doTheTestReduce(.Min, [4]f16{ -10.3, 10.0e9, 13.0, -100.0 }, @as(f16, -100.0));
564 try doTheTestReduce(.Min, [4]f32{ -10.3, 10.0e9, 13.0, -100.0 }, @as(f32, -100.0));
565 try doTheTestReduce(.Min, [4]f64{ -10.3, 10.0e9, 13.0, -100.0 }, @as(f64, -100.0));
566566
567 doTheTestReduce(.Max, [4]i16{ -1, 2, 3, 4 }, @as(i16, 4));
568 doTheTestReduce(.Max, [4]u16{ 1, 2, 3, 4 }, @as(u16, 4));
569 doTheTestReduce(.Max, [4]i32{ 1234567, -386, 0, 3 }, @as(i32, 1234567));
570 doTheTestReduce(.Max, [4]u32{ 99, 9999, 9, 99999 }, @as(u32, 99999));
567 try doTheTestReduce(.Max, [4]i16{ -1, 2, 3, 4 }, @as(i16, 4));
568 try doTheTestReduce(.Max, [4]u16{ 1, 2, 3, 4 }, @as(u16, 4));
569 try doTheTestReduce(.Max, [4]i32{ 1234567, -386, 0, 3 }, @as(i32, 1234567));
570 try doTheTestReduce(.Max, [4]u32{ 99, 9999, 9, 99999 }, @as(u32, 99999));
571571
572572 // LLVM 11 ERROR: Cannot select type
573573 // https://github.com/ziglang/zig/issues/7138
574574 if (builtin.target.cpu.arch != .aarch64) {
575 doTheTestReduce(.Max, [4]i64{ 1234567, -386, 0, 3 }, @as(i64, 1234567));
576 doTheTestReduce(.Max, [4]u64{ 99, 9999, 9, 99999 }, @as(u64, 99999));
575 try doTheTestReduce(.Max, [4]i64{ 1234567, -386, 0, 3 }, @as(i64, 1234567));
576 try doTheTestReduce(.Max, [4]u64{ 99, 9999, 9, 99999 }, @as(u64, 99999));
577577 }
578578
579 doTheTestReduce(.Max, [4]i128{ 1234567, -386, 0, 3 }, @as(i128, 1234567));
580 doTheTestReduce(.Max, [4]u128{ 99, 9999, 9, 99999 }, @as(u128, 99999));
581 doTheTestReduce(.Max, [4]f16{ -10.3, 10.0e9, 13.0, -100.0 }, @as(f16, 10.0e9));
582 doTheTestReduce(.Max, [4]f32{ -10.3, 10.0e9, 13.0, -100.0 }, @as(f32, 10.0e9));
583 doTheTestReduce(.Max, [4]f64{ -10.3, 10.0e9, 13.0, -100.0 }, @as(f64, 10.0e9));
584
585 doTheTestReduce(.Mul, [4]i16{ -1, 2, 3, 4 }, @as(i16, -24));
586 doTheTestReduce(.Mul, [4]u16{ 1, 2, 3, 4 }, @as(u16, 24));
587 doTheTestReduce(.Mul, [4]i32{ -9, -99, -999, 999 }, @as(i32, -889218891));
588 doTheTestReduce(.Mul, [4]u32{ 1, 2, 3, 4 }, @as(u32, 24));
589 doTheTestReduce(.Mul, [4]i64{ 9, 99, 999, 9999 }, @as(i64, 8900199891));
590 doTheTestReduce(.Mul, [4]u64{ 9, 99, 999, 9999 }, @as(u64, 8900199891));
591 doTheTestReduce(.Mul, [4]i128{ -9, -99, -999, 9999 }, @as(i128, -8900199891));
592 doTheTestReduce(.Mul, [4]u128{ 9, 99, 999, 9999 }, @as(u128, 8900199891));
593 doTheTestReduce(.Mul, [4]f16{ -1.9, 5.1, -60.3, 100.0 }, @as(f16, 58430.7));
594 doTheTestReduce(.Mul, [4]f32{ -1.9, 5.1, -60.3, 100.0 }, @as(f32, 58430.7));
595 doTheTestReduce(.Mul, [4]f64{ -1.9, 5.1, -60.3, 100.0 }, @as(f64, 58430.7));
596
597 doTheTestReduce(.Or, [4]bool{ false, true, false, false }, @as(bool, true));
598 doTheTestReduce(.Or, [4]u1{ 0, 1, 0, 0 }, @as(u1, 1));
599 doTheTestReduce(.Or, [4]u16{ 0xff00, 0xff00, 0xf0, 0xf }, ~@as(u16, 0));
600 doTheTestReduce(.Or, [4]u32{ 0xffff0000, 0xff00, 0xf0, 0xf }, ~@as(u32, 0));
601 doTheTestReduce(.Or, [4]u64{ 0xffff0000, 0xff00, 0xf0, 0xf }, @as(u64, 0xffffffff));
602 doTheTestReduce(.Or, [4]u128{ 0xffff0000, 0xff00, 0xf0, 0xf }, @as(u128, 0xffffffff));
603
604 doTheTestReduce(.Xor, [4]bool{ true, true, true, false }, @as(bool, true));
605 doTheTestReduce(.Xor, [4]u1{ 1, 1, 1, 0 }, @as(u1, 1));
606 doTheTestReduce(.Xor, [4]u16{ 0x0000, 0x3333, 0x8888, 0x4444 }, ~@as(u16, 0));
607 doTheTestReduce(.Xor, [4]u32{ 0x00000000, 0x33333333, 0x88888888, 0x44444444 }, ~@as(u32, 0));
608 doTheTestReduce(.Xor, [4]u64{ 0x00000000, 0x33333333, 0x88888888, 0x44444444 }, @as(u64, 0xffffffff));
609 doTheTestReduce(.Xor, [4]u128{ 0x00000000, 0x33333333, 0x88888888, 0x44444444 }, @as(u128, 0xffffffff));
579 try doTheTestReduce(.Max, [4]i128{ 1234567, -386, 0, 3 }, @as(i128, 1234567));
580 try doTheTestReduce(.Max, [4]u128{ 99, 9999, 9, 99999 }, @as(u128, 99999));
581 try doTheTestReduce(.Max, [4]f16{ -10.3, 10.0e9, 13.0, -100.0 }, @as(f16, 10.0e9));
582 try doTheTestReduce(.Max, [4]f32{ -10.3, 10.0e9, 13.0, -100.0 }, @as(f32, 10.0e9));
583 try doTheTestReduce(.Max, [4]f64{ -10.3, 10.0e9, 13.0, -100.0 }, @as(f64, 10.0e9));
584
585 try doTheTestReduce(.Mul, [4]i16{ -1, 2, 3, 4 }, @as(i16, -24));
586 try doTheTestReduce(.Mul, [4]u16{ 1, 2, 3, 4 }, @as(u16, 24));
587 try doTheTestReduce(.Mul, [4]i32{ -9, -99, -999, 999 }, @as(i32, -889218891));
588 try doTheTestReduce(.Mul, [4]u32{ 1, 2, 3, 4 }, @as(u32, 24));
589 try doTheTestReduce(.Mul, [4]i64{ 9, 99, 999, 9999 }, @as(i64, 8900199891));
590 try doTheTestReduce(.Mul, [4]u64{ 9, 99, 999, 9999 }, @as(u64, 8900199891));
591 try doTheTestReduce(.Mul, [4]i128{ -9, -99, -999, 9999 }, @as(i128, -8900199891));
592 try doTheTestReduce(.Mul, [4]u128{ 9, 99, 999, 9999 }, @as(u128, 8900199891));
593 try doTheTestReduce(.Mul, [4]f16{ -1.9, 5.1, -60.3, 100.0 }, @as(f16, 58430.7));
594 try doTheTestReduce(.Mul, [4]f32{ -1.9, 5.1, -60.3, 100.0 }, @as(f32, 58430.7));
595 try doTheTestReduce(.Mul, [4]f64{ -1.9, 5.1, -60.3, 100.0 }, @as(f64, 58430.7));
596
597 try doTheTestReduce(.Or, [4]bool{ false, true, false, false }, @as(bool, true));
598 try doTheTestReduce(.Or, [4]u1{ 0, 1, 0, 0 }, @as(u1, 1));
599 try doTheTestReduce(.Or, [4]u16{ 0xff00, 0xff00, 0xf0, 0xf }, ~@as(u16, 0));
600 try doTheTestReduce(.Or, [4]u32{ 0xffff0000, 0xff00, 0xf0, 0xf }, ~@as(u32, 0));
601 try doTheTestReduce(.Or, [4]u64{ 0xffff0000, 0xff00, 0xf0, 0xf }, @as(u64, 0xffffffff));
602 try doTheTestReduce(.Or, [4]u128{ 0xffff0000, 0xff00, 0xf0, 0xf }, @as(u128, 0xffffffff));
603
604 try doTheTestReduce(.Xor, [4]bool{ true, true, true, false }, @as(bool, true));
605 try doTheTestReduce(.Xor, [4]u1{ 1, 1, 1, 0 }, @as(u1, 1));
606 try doTheTestReduce(.Xor, [4]u16{ 0x0000, 0x3333, 0x8888, 0x4444 }, ~@as(u16, 0));
607 try doTheTestReduce(.Xor, [4]u32{ 0x00000000, 0x33333333, 0x88888888, 0x44444444 }, ~@as(u32, 0));
608 try doTheTestReduce(.Xor, [4]u64{ 0x00000000, 0x33333333, 0x88888888, 0x44444444 }, @as(u64, 0xffffffff));
609 try doTheTestReduce(.Xor, [4]u128{ 0x00000000, 0x33333333, 0x88888888, 0x44444444 }, @as(u128, 0xffffffff));
610610
611611 // Test the reduction on vectors containing NaNs.
612612 const f16_nan = math.nan(f16);
613613 const f32_nan = math.nan(f32);
614614 const f64_nan = math.nan(f64);
615615
616 doTheTestReduce(.Add, [4]f16{ -1.9, 5.1, f16_nan, 100.0 }, f16_nan);
617 doTheTestReduce(.Add, [4]f32{ -1.9, 5.1, f32_nan, 100.0 }, f32_nan);
618 doTheTestReduce(.Add, [4]f64{ -1.9, 5.1, f64_nan, 100.0 }, f64_nan);
616 try doTheTestReduce(.Add, [4]f16{ -1.9, 5.1, f16_nan, 100.0 }, f16_nan);
617 try doTheTestReduce(.Add, [4]f32{ -1.9, 5.1, f32_nan, 100.0 }, f32_nan);
618 try doTheTestReduce(.Add, [4]f64{ -1.9, 5.1, f64_nan, 100.0 }, f64_nan);
619619
620620 // LLVM 11 ERROR: Cannot select type
621621 // https://github.com/ziglang/zig/issues/7138
622622 if (false) {
623 doTheTestReduce(.Min, [4]f16{ -1.9, 5.1, f16_nan, 100.0 }, f16_nan);
624 doTheTestReduce(.Min, [4]f32{ -1.9, 5.1, f32_nan, 100.0 }, f32_nan);
625 doTheTestReduce(.Min, [4]f64{ -1.9, 5.1, f64_nan, 100.0 }, f64_nan);
623 try doTheTestReduce(.Min, [4]f16{ -1.9, 5.1, f16_nan, 100.0 }, f16_nan);
624 try doTheTestReduce(.Min, [4]f32{ -1.9, 5.1, f32_nan, 100.0 }, f32_nan);
625 try doTheTestReduce(.Min, [4]f64{ -1.9, 5.1, f64_nan, 100.0 }, f64_nan);
626626
627 doTheTestReduce(.Max, [4]f16{ -1.9, 5.1, f16_nan, 100.0 }, f16_nan);
628 doTheTestReduce(.Max, [4]f32{ -1.9, 5.1, f32_nan, 100.0 }, f32_nan);
629 doTheTestReduce(.Max, [4]f64{ -1.9, 5.1, f64_nan, 100.0 }, f64_nan);
627 try doTheTestReduce(.Max, [4]f16{ -1.9, 5.1, f16_nan, 100.0 }, f16_nan);
628 try doTheTestReduce(.Max, [4]f32{ -1.9, 5.1, f32_nan, 100.0 }, f32_nan);
629 try doTheTestReduce(.Max, [4]f64{ -1.9, 5.1, f64_nan, 100.0 }, f64_nan);
630630 }
631631
632 doTheTestReduce(.Mul, [4]f16{ -1.9, 5.1, f16_nan, 100.0 }, f16_nan);
633 doTheTestReduce(.Mul, [4]f32{ -1.9, 5.1, f32_nan, 100.0 }, f32_nan);
634 doTheTestReduce(.Mul, [4]f64{ -1.9, 5.1, f64_nan, 100.0 }, f64_nan);
632 try doTheTestReduce(.Mul, [4]f16{ -1.9, 5.1, f16_nan, 100.0 }, f16_nan);
633 try doTheTestReduce(.Mul, [4]f32{ -1.9, 5.1, f32_nan, 100.0 }, f32_nan);
634 try doTheTestReduce(.Mul, [4]f64{ -1.9, 5.1, f64_nan, 100.0 }, f64_nan);
635635 }
636636 };
637637
638 S.doTheTest();
639 comptime S.doTheTest();
638 try S.doTheTest();
639 comptime try S.doTheTest();
640640}
test/behavior/void.zig+3-3
......@@ -13,14 +13,14 @@ test "compare void with void compile time known" {
1313 .b = 1,
1414 .c = {},
1515 };
16 expect(foo.a == {});
16 try expect(foo.a == {});
1717 }
1818}
1919
2020test "iterate over a void slice" {
2121 var j: usize = 0;
2222 for (times(10)) |_, i| {
23 expect(i == j);
23 try expect(i == j);
2424 j += 1;
2525 }
2626}
......@@ -31,7 +31,7 @@ fn times(n: usize) []const void {
3131
3232test "void optional" {
3333 var x: ?void = {};
34 expect(x != null);
34 try expect(x != null);
3535}
3636
3737test "void array as a local variable initializer" {
test/behavior/wasm.zig+2-2
......@@ -3,6 +3,6 @@ const expect = std.testing.expect;
33
44test "memory size and grow" {
55 var prev = @wasmMemorySize(0);
6 expect(prev == @wasmMemoryGrow(0, 1));
7 expect(prev + 1 == @wasmMemorySize(0));
6 try expect(prev == @wasmMemoryGrow(0, 1));
7 try expect(prev + 1 == @wasmMemorySize(0));
88}
test/behavior/while.zig+45-51
......@@ -6,8 +6,8 @@ test "while loop" {
66 while (i < 4) {
77 i += 1;
88 }
9 expect(i == 4);
10 expect(whileLoop1() == 1);
9 try expect(i == 4);
10 try expect(whileLoop1() == 1);
1111}
1212fn whileLoop1() i32 {
1313 return whileLoop2();
......@@ -19,7 +19,7 @@ fn whileLoop2() i32 {
1919}
2020
2121test "static eval while" {
22 expect(static_eval_while_number == 1);
22 try expect(static_eval_while_number == 1);
2323}
2424const static_eval_while_number = staticWhileLoop1();
2525fn staticWhileLoop1() i32 {
......@@ -32,11 +32,11 @@ fn staticWhileLoop2() i32 {
3232}
3333
3434test "continue and break" {
35 runContinueAndBreakTest();
36 expect(continue_and_break_counter == 8);
35 try runContinueAndBreakTest();
36 try expect(continue_and_break_counter == 8);
3737}
3838var continue_and_break_counter: i32 = 0;
39fn runContinueAndBreakTest() void {
39fn runContinueAndBreakTest() !void {
4040 var i: i32 = 0;
4141 while (true) {
4242 continue_and_break_counter += 2;
......@@ -46,7 +46,7 @@ fn runContinueAndBreakTest() void {
4646 }
4747 break;
4848 }
49 expect(i == 4);
49 try expect(i == 4);
5050}
5151
5252test "return with implicit cast from while loop" {
......@@ -67,7 +67,7 @@ test "while with continue expression" {
6767 sum += i;
6868 }
6969 }
70 expect(sum == 40);
70 try expect(sum == 40);
7171}
7272
7373test "while with else" {
......@@ -79,8 +79,8 @@ test "while with else" {
7979 } else {
8080 got_else += 1;
8181 }
82 expect(sum == 10);
83 expect(got_else == 1);
82 try expect(sum == 10);
83 try expect(got_else == 1);
8484}
8585
8686test "while with optional as condition" {
......@@ -89,7 +89,7 @@ test "while with optional as condition" {
8989 while (getNumberOrNull()) |value| {
9090 sum += value;
9191 }
92 expect(sum == 45);
92 try expect(sum == 45);
9393}
9494
9595test "while with optional as condition with else" {
......@@ -98,12 +98,12 @@ test "while with optional as condition with else" {
9898 var got_else: i32 = 0;
9999 while (getNumberOrNull()) |value| {
100100 sum += value;
101 expect(got_else == 0);
101 try expect(got_else == 0);
102102 } else {
103103 got_else += 1;
104104 }
105 expect(sum == 45);
106 expect(got_else == 1);
105 try expect(sum == 45);
106 try expect(got_else == 1);
107107}
108108
109109test "while with error union condition" {
......@@ -113,11 +113,11 @@ test "while with error union condition" {
113113 while (getNumberOrErr()) |value| {
114114 sum += value;
115115 } else |err| {
116 expect(err == error.OutOfNumbers);
116 try expect(err == error.OutOfNumbers);
117117 got_else += 1;
118118 }
119 expect(sum == 45);
120 expect(got_else == 1);
119 try expect(sum == 45);
120 try expect(got_else == 1);
121121}
122122
123123var numbers_left: i32 = undefined;
......@@ -137,49 +137,43 @@ fn getNumberOrNull() ?i32 {
137137test "while on optional with else result follow else prong" {
138138 const result = while (returnNull()) |value| {
139139 break value;
140 } else
141 @as(i32, 2);
142 expect(result == 2);
140 } else @as(i32, 2);
141 try expect(result == 2);
143142}
144143
145144test "while on optional with else result follow break prong" {
146145 const result = while (returnOptional(10)) |value| {
147146 break value;
148 } else
149 @as(i32, 2);
150 expect(result == 10);
147 } else @as(i32, 2);
148 try expect(result == 10);
151149}
152150
153151test "while on error union with else result follow else prong" {
154152 const result = while (returnError()) |value| {
155153 break value;
156 } else |err|
157 @as(i32, 2);
158 expect(result == 2);
154 } else |err| @as(i32, 2);
155 try expect(result == 2);
159156}
160157
161158test "while on error union with else result follow break prong" {
162159 const result = while (returnSuccess(10)) |value| {
163160 break value;
164 } else |err|
165 @as(i32, 2);
166 expect(result == 10);
161 } else |err| @as(i32, 2);
162 try expect(result == 10);
167163}
168164
169165test "while on bool with else result follow else prong" {
170166 const result = while (returnFalse()) {
171167 break @as(i32, 10);
172 } else
173 @as(i32, 2);
174 expect(result == 2);
168 } else @as(i32, 2);
169 try expect(result == 2);
175170}
176171
177172test "while on bool with else result follow break prong" {
178173 const result = while (returnTrue()) {
179174 break @as(i32, 10);
180 } else
181 @as(i32, 2);
182 expect(result == 10);
175 } else @as(i32, 2);
176 try expect(result == 10);
183177}
184178
185179test "break from outer while loop" {
......@@ -230,60 +224,60 @@ fn returnTrue() bool {
230224
231225test "while bool 2 break statements and an else" {
232226 const S = struct {
233 fn entry(t: bool, f: bool) void {
227 fn entry(t: bool, f: bool) !void {
234228 var ok = false;
235229 ok = while (t) {
236230 if (f) break false;
237231 if (t) break true;
238232 } else false;
239 expect(ok);
233 try expect(ok);
240234 }
241235 };
242 S.entry(true, false);
243 comptime S.entry(true, false);
236 try S.entry(true, false);
237 comptime try S.entry(true, false);
244238}
245239
246240test "while optional 2 break statements and an else" {
247241 const S = struct {
248 fn entry(opt_t: ?bool, f: bool) void {
242 fn entry(opt_t: ?bool, f: bool) !void {
249243 var ok = false;
250244 ok = while (opt_t) |t| {
251245 if (f) break false;
252246 if (t) break true;
253247 } else false;
254 expect(ok);
248 try expect(ok);
255249 }
256250 };
257 S.entry(true, false);
258 comptime S.entry(true, false);
251 try S.entry(true, false);
252 comptime try S.entry(true, false);
259253}
260254
261255test "while error 2 break statements and an else" {
262256 const S = struct {
263 fn entry(opt_t: anyerror!bool, f: bool) void {
257 fn entry(opt_t: anyerror!bool, f: bool) !void {
264258 var ok = false;
265259 ok = while (opt_t) |t| {
266260 if (f) break false;
267261 if (t) break true;
268262 } else |_| false;
269 expect(ok);
263 try expect(ok);
270264 }
271265 };
272 S.entry(true, false);
273 comptime S.entry(true, false);
266 try S.entry(true, false);
267 comptime try S.entry(true, false);
274268}
275269
276270test "while copies its payload" {
277271 const S = struct {
278 fn doTheTest() void {
272 fn doTheTest() !void {
279273 var tmp: ?i32 = 10;
280274 while (tmp) |value| {
281275 // Modify the original variable
282276 tmp = null;
283 expect(value == 10);
277 try expect(value == 10);
284278 }
285279 }
286280 };
287 S.doTheTest();
288 comptime S.doTheTest();
281 try S.doTheTest();
282 comptime try S.doTheTest();
289283}
test/behavior/widening.zig+6-6
......@@ -9,13 +9,13 @@ test "integer widening" {
99 var d: u64 = c;
1010 var e: u64 = d;
1111 var f: u128 = e;
12 expect(f == a);
12 try expect(f == a);
1313}
1414
1515test "implicit unsigned integer to signed integer" {
1616 var a: u8 = 250;
1717 var b: i16 = a;
18 expect(b == 250);
18 try expect(b == 250);
1919}
2020
2121test "float widening" {
......@@ -23,9 +23,9 @@ test "float widening" {
2323 var b: f32 = a;
2424 var c: f64 = b;
2525 var d: f128 = c;
26 expect(a == b);
27 expect(b == c);
28 expect(c == d);
26 try expect(a == b);
27 try expect(b == c);
28 try expect(c == d);
2929}
3030
3131test "float widening f16 to f128" {
......@@ -35,5 +35,5 @@ test "float widening f16 to f128" {
3535
3636 var x: f16 = 12.34;
3737 var y: f128 = x;
38 expect(x == y);
38 try expect(x == y);
3939}
test/cli.zig+14-14
......@@ -29,7 +29,7 @@ pub fn main() !void {
2929
3030 const dir_path = try fs.path.join(a, &[_][]const u8{ cache_root, "clitest" });
3131 defer fs.cwd().deleteTree(dir_path) catch {};
32
32
3333 const TestFn = fn ([]const u8, []const u8) anyerror!void;
3434 const test_fns = [_]TestFn{
3535 testZigInitLib,
......@@ -94,13 +94,13 @@ fn exec(cwd: []const u8, expect_0: bool, argv: []const []const u8) !ChildProcess
9494fn testZigInitLib(zig_exe: []const u8, dir_path: []const u8) !void {
9595 _ = try exec(dir_path, true, &[_][]const u8{ zig_exe, "init-lib" });
9696 const test_result = try exec(dir_path, true, &[_][]const u8{ zig_exe, "build", "test" });
97 testing.expectStringEndsWith(test_result.stderr, "All 1 tests passed.\n");
97 try testing.expectStringEndsWith(test_result.stderr, "All 1 tests passed.\n");
9898}
9999
100100fn testZigInitExe(zig_exe: []const u8, dir_path: []const u8) !void {
101101 _ = try exec(dir_path, true, &[_][]const u8{ zig_exe, "init-exe" });
102102 const run_result = try exec(dir_path, true, &[_][]const u8{ zig_exe, "build", "run" });
103 testing.expectEqualStrings("info: All your codebase are belong to us.\n", run_result.stderr);
103 try testing.expectEqualStrings("info: All your codebase are belong to us.\n", run_result.stderr);
104104}
105105
106106fn testGodboltApi(zig_exe: []const u8, dir_path: []const u8) anyerror!void {
......@@ -136,9 +136,9 @@ fn testGodboltApi(zig_exe: []const u8, dir_path: []const u8) anyerror!void {
136136 _ = try exec(dir_path, true, args.items);
137137
138138 const out_asm = try std.fs.cwd().readFileAlloc(a, example_s_path, std.math.maxInt(usize));
139 testing.expect(std.mem.indexOf(u8, out_asm, "square:") != null);
140 testing.expect(std.mem.indexOf(u8, out_asm, "mov\teax, edi") != null);
141 testing.expect(std.mem.indexOf(u8, out_asm, "imul\teax, edi") != null);
139 try testing.expect(std.mem.indexOf(u8, out_asm, "square:") != null);
140 try testing.expect(std.mem.indexOf(u8, out_asm, "mov\teax, edi") != null);
141 try testing.expect(std.mem.indexOf(u8, out_asm, "imul\teax, edi") != null);
142142}
143143
144144fn testMissingOutputPath(zig_exe: []const u8, dir_path: []const u8) !void {
......@@ -149,7 +149,7 @@ fn testMissingOutputPath(zig_exe: []const u8, dir_path: []const u8) !void {
149149 const result = try exec(dir_path, false, &[_][]const u8{ zig_exe, "build-exe", source_path, output_arg });
150150 const s = std.fs.path.sep_str;
151151 const expected: []const u8 = "error: unable to open output directory 'does" ++ s ++ "not" ++ s ++ "exist': FileNotFound\n";
152 testing.expectEqualStrings(expected, result.stderr);
152 try testing.expectEqualStrings(expected, result.stderr);
153153}
154154
155155fn testZigFmt(zig_exe: []const u8, dir_path: []const u8) !void {
......@@ -162,20 +162,20 @@ fn testZigFmt(zig_exe: []const u8, dir_path: []const u8) !void {
162162
163163 const run_result1 = try exec(dir_path, true, &[_][]const u8{ zig_exe, "fmt", fmt1_zig_path });
164164 // stderr should be file path + \n
165 testing.expect(std.mem.startsWith(u8, run_result1.stdout, fmt1_zig_path));
166 testing.expect(run_result1.stdout.len == fmt1_zig_path.len + 1 and run_result1.stdout[run_result1.stdout.len - 1] == '\n');
165 try testing.expect(std.mem.startsWith(u8, run_result1.stdout, fmt1_zig_path));
166 try testing.expect(run_result1.stdout.len == fmt1_zig_path.len + 1 and run_result1.stdout[run_result1.stdout.len - 1] == '\n');
167167
168168 const fmt2_zig_path = try fs.path.join(a, &[_][]const u8{ dir_path, "fmt2.zig" });
169169 try fs.cwd().writeFile(fmt2_zig_path, unformatted_code);
170170
171171 const run_result2 = try exec(dir_path, true, &[_][]const u8{ zig_exe, "fmt", dir_path });
172172 // running it on the dir, only the new file should be changed
173 testing.expect(std.mem.startsWith(u8, run_result2.stdout, fmt2_zig_path));
174 testing.expect(run_result2.stdout.len == fmt2_zig_path.len + 1 and run_result2.stdout[run_result2.stdout.len - 1] == '\n');
173 try testing.expect(std.mem.startsWith(u8, run_result2.stdout, fmt2_zig_path));
174 try testing.expect(run_result2.stdout.len == fmt2_zig_path.len + 1 and run_result2.stdout[run_result2.stdout.len - 1] == '\n');
175175
176176 const run_result3 = try exec(dir_path, true, &[_][]const u8{ zig_exe, "fmt", dir_path });
177177 // both files have been formatted, nothing should change now
178 testing.expect(run_result3.stdout.len == 0);
178 try testing.expect(run_result3.stdout.len == 0);
179179
180180 // Check UTF-16 decoding
181181 const fmt4_zig_path = try fs.path.join(a, &[_][]const u8{ dir_path, "fmt4.zig" });
......@@ -183,6 +183,6 @@ fn testZigFmt(zig_exe: []const u8, dir_path: []const u8) !void {
183183 try fs.cwd().writeFile(fmt4_zig_path, unformatted_code_utf16);
184184
185185 const run_result4 = try exec(dir_path, true, &[_][]const u8{ zig_exe, "fmt", dir_path });
186 testing.expect(std.mem.startsWith(u8, run_result4.stdout, fmt4_zig_path));
187 testing.expect(run_result4.stdout.len == fmt4_zig_path.len + 1 and run_result4.stdout[run_result4.stdout.len - 1] == '\n');
186 try testing.expect(std.mem.startsWith(u8, run_result4.stdout, fmt4_zig_path));
187 try testing.expect(run_result4.stdout.len == fmt4_zig_path.len + 1 and run_result4.stdout[run_result4.stdout.len - 1] == '\n');
188188}
test/compile_errors.zig+1-1
......@@ -230,7 +230,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
230230
231231 cases.add("array in c exported function",
232232 \\export fn zig_array(x: [10]u8) void {
233 \\ expect(std.mem.eql(u8, &x, "1234567890"));
233 \\try expect(std.mem.eql(u8, &x, "1234567890"));
234234 \\}
235235 \\
236236 \\export fn zig_return_array() [10]u8 {
test/stack_traces.zig+17-17
......@@ -5,13 +5,13 @@ const tests = @import("tests.zig");
55pub fn addCases(cases: *tests.StackTracesContext) void {
66 cases.addCase(.{
77 .name = "return",
8 .source =
8 .source =
99 \\pub fn main() !void {
1010 \\ return error.TheSkyIsFalling;
1111 \\}
1212 ,
1313 .Debug = .{
14 .expect =
14 .expect =
1515 \\error: TheSkyIsFalling
1616 \\source.zig:2:5: [address] in main (test)
1717 \\ return error.TheSkyIsFalling;
......@@ -23,7 +23,7 @@ pub fn addCases(cases: *tests.StackTracesContext) void {
2323 .exclude_os = .{
2424 .windows, // segfault
2525 },
26 .expect =
26 .expect =
2727 \\error: TheSkyIsFalling
2828 \\source.zig:2:5: [address] in [function]
2929 \\ return error.TheSkyIsFalling;
......@@ -32,13 +32,13 @@ pub fn addCases(cases: *tests.StackTracesContext) void {
3232 ,
3333 },
3434 .ReleaseFast = .{
35 .expect =
35 .expect =
3636 \\error: TheSkyIsFalling
3737 \\
3838 ,
3939 },
4040 .ReleaseSmall = .{
41 .expect =
41 .expect =
4242 \\error: TheSkyIsFalling
4343 \\
4444 ,
......@@ -47,7 +47,7 @@ pub fn addCases(cases: *tests.StackTracesContext) void {
4747
4848 cases.addCase(.{
4949 .name = "try return",
50 .source =
50 .source =
5151 \\fn foo() !void {
5252 \\ return error.TheSkyIsFalling;
5353 \\}
......@@ -57,7 +57,7 @@ pub fn addCases(cases: *tests.StackTracesContext) void {
5757 \\}
5858 ,
5959 .Debug = .{
60 .expect =
60 .expect =
6161 \\error: TheSkyIsFalling
6262 \\source.zig:2:5: [address] in foo (test)
6363 \\ return error.TheSkyIsFalling;
......@@ -72,7 +72,7 @@ pub fn addCases(cases: *tests.StackTracesContext) void {
7272 .exclude_os = .{
7373 .windows, // segfault
7474 },
75 .expect =
75 .expect =
7676 \\error: TheSkyIsFalling
7777 \\source.zig:2:5: [address] in [function]
7878 \\ return error.TheSkyIsFalling;
......@@ -84,13 +84,13 @@ pub fn addCases(cases: *tests.StackTracesContext) void {
8484 ,
8585 },
8686 .ReleaseFast = .{
87 .expect =
87 .expect =
8888 \\error: TheSkyIsFalling
8989 \\
9090 ,
9191 },
9292 .ReleaseSmall = .{
93 .expect =
93 .expect =
9494 \\error: TheSkyIsFalling
9595 \\
9696 ,
......@@ -99,7 +99,7 @@ pub fn addCases(cases: *tests.StackTracesContext) void {
9999
100100 cases.addCase(.{
101101 .name = "try try return return",
102 .source =
102 .source =
103103 \\fn foo() !void {
104104 \\ try bar();
105105 \\}
......@@ -117,7 +117,7 @@ pub fn addCases(cases: *tests.StackTracesContext) void {
117117 \\}
118118 ,
119119 .Debug = .{
120 .expect =
120 .expect =
121121 \\error: TheSkyIsFalling
122122 \\source.zig:10:5: [address] in make_error (test)
123123 \\ return error.TheSkyIsFalling;
......@@ -138,7 +138,7 @@ pub fn addCases(cases: *tests.StackTracesContext) void {
138138 .exclude_os = .{
139139 .windows, // segfault
140140 },
141 .expect =
141 .expect =
142142 \\error: TheSkyIsFalling
143143 \\source.zig:10:5: [address] in [function]
144144 \\ return error.TheSkyIsFalling;
......@@ -156,13 +156,13 @@ pub fn addCases(cases: *tests.StackTracesContext) void {
156156 ,
157157 },
158158 .ReleaseFast = .{
159 .expect =
159 .expect =
160160 \\error: TheSkyIsFalling
161161 \\
162162 ,
163163 },
164164 .ReleaseSmall = .{
165 .expect =
165 .expect =
166166 \\error: TheSkyIsFalling
167167 \\
168168 ,
......@@ -174,7 +174,7 @@ pub fn addCases(cases: *tests.StackTracesContext) void {
174174 .windows,
175175 },
176176 .name = "dumpCurrentStackTrace",
177 .source =
177 .source =
178178 \\const std = @import("std");
179179 \\
180180 \\fn bar() void {
......@@ -189,7 +189,7 @@ pub fn addCases(cases: *tests.StackTracesContext) void {
189189 \\}
190190 ,
191191 .Debug = .{
192 .expect =
192 .expect =
193193 \\source.zig:7:8: [address] in foo (test)
194194 \\ bar();
195195 \\ ^
test/stage1/c_abi/main.zig+58-58
......@@ -24,11 +24,11 @@ extern fn c_i64(i64) void;
2424extern fn c_five_integers(i32, i32, i32, i32, i32) void;
2525
2626export fn zig_five_integers(a: i32, b: i32, c: i32, d: i32, e: i32) void {
27 expect(a == 12);
28 expect(b == 34);
29 expect(c == 56);
30 expect(d == 78);
31 expect(e == 90);
27 expect(a == 12) catch @panic("test failure");
28 expect(b == 34) catch @panic("test failure");
29 expect(c == 56) catch @panic("test failure");
30 expect(d == 78) catch @panic("test failure");
31 expect(e == 90) catch @panic("test failure");
3232}
3333
3434test "C ABI integers" {
......@@ -45,28 +45,28 @@ test "C ABI integers" {
4545}
4646
4747export fn zig_u8(x: u8) void {
48 expect(x == 0xff);
48 expect(x == 0xff) catch @panic("test failure");
4949}
5050export fn zig_u16(x: u16) void {
51 expect(x == 0xfffe);
51 expect(x == 0xfffe) catch @panic("test failure");
5252}
5353export fn zig_u32(x: u32) void {
54 expect(x == 0xfffffffd);
54 expect(x == 0xfffffffd) catch @panic("test failure");
5555}
5656export fn zig_u64(x: u64) void {
57 expect(x == 0xfffffffffffffffc);
57 expect(x == 0xfffffffffffffffc) catch @panic("test failure");
5858}
5959export fn zig_i8(x: i8) void {
60 expect(x == -1);
60 expect(x == -1) catch @panic("test failure");
6161}
6262export fn zig_i16(x: i16) void {
63 expect(x == -2);
63 expect(x == -2) catch @panic("test failure");
6464}
6565export fn zig_i32(x: i32) void {
66 expect(x == -3);
66 expect(x == -3) catch @panic("test failure");
6767}
6868export fn zig_i64(x: i64) void {
69 expect(x == -4);
69 expect(x == -4) catch @panic("test failure");
7070}
7171
7272extern fn c_f32(f32) void;
......@@ -76,11 +76,11 @@ extern fn c_f64(f64) void;
7676extern fn c_five_floats(f32, f32, f32, f32, f32) void;
7777
7878export fn zig_five_floats(a: f32, b: f32, c: f32, d: f32, e: f32) void {
79 expect(a == 1.0);
80 expect(b == 2.0);
81 expect(c == 3.0);
82 expect(d == 4.0);
83 expect(e == 5.0);
79 expect(a == 1.0) catch @panic("test failure");
80 expect(b == 2.0) catch @panic("test failure");
81 expect(c == 3.0) catch @panic("test failure");
82 expect(d == 4.0) catch @panic("test failure");
83 expect(e == 5.0) catch @panic("test failure");
8484}
8585
8686test "C ABI floats" {
......@@ -90,10 +90,10 @@ test "C ABI floats" {
9090}
9191
9292export fn zig_f32(x: f32) void {
93 expect(x == 12.34);
93 expect(x == 12.34) catch @panic("test failure");
9494}
9595export fn zig_f64(x: f64) void {
96 expect(x == 56.78);
96 expect(x == 56.78) catch @panic("test failure");
9797}
9898
9999extern fn c_ptr(*c_void) void;
......@@ -103,7 +103,7 @@ test "C ABI pointer" {
103103}
104104
105105export fn zig_ptr(x: *c_void) void {
106 expect(@ptrToInt(x) == 0xdeadbeef);
106 expect(@ptrToInt(x) == 0xdeadbeef) catch @panic("test failure");
107107}
108108
109109extern fn c_bool(bool) void;
......@@ -113,7 +113,7 @@ test "C ABI bool" {
113113}
114114
115115export fn zig_bool(x: bool) void {
116 expect(x);
116 expect(x) catch @panic("test failure");
117117}
118118
119119const BigStruct = extern struct {
......@@ -137,11 +137,11 @@ test "C ABI big struct" {
137137}
138138
139139export fn zig_big_struct(x: BigStruct) void {
140 expect(x.a == 1);
141 expect(x.b == 2);
142 expect(x.c == 3);
143 expect(x.d == 4);
144 expect(x.e == 5);
140 expect(x.a == 1) catch @panic("test failure");
141 expect(x.b == 2) catch @panic("test failure");
142 expect(x.c == 3) catch @panic("test failure");
143 expect(x.d == 4) catch @panic("test failure");
144 expect(x.e == 5) catch @panic("test failure");
145145}
146146
147147const BigUnion = extern union {
......@@ -163,11 +163,11 @@ test "C ABI big union" {
163163}
164164
165165export fn zig_big_union(x: BigUnion) void {
166 expect(x.a.a == 1);
167 expect(x.a.b == 2);
168 expect(x.a.c == 3);
169 expect(x.a.d == 4);
170 expect(x.a.e == 5);
166 expect(x.a.a == 1) catch @panic("test failure");
167 expect(x.a.b == 2) catch @panic("test failure");
168 expect(x.a.c == 3) catch @panic("test failure");
169 expect(x.a.d == 4) catch @panic("test failure");
170 expect(x.a.e == 5) catch @panic("test failure");
171171}
172172
173173const SmallStructInts = extern struct {
......@@ -189,10 +189,10 @@ test "C ABI small struct of ints" {
189189}
190190
191191export fn zig_small_struct_ints(x: SmallStructInts) void {
192 expect(x.a == 1);
193 expect(x.b == 2);
194 expect(x.c == 3);
195 expect(x.d == 4);
192 expect(x.a == 1) catch @panic("test failure");
193 expect(x.b == 2) catch @panic("test failure");
194 expect(x.c == 3) catch @panic("test failure");
195 expect(x.d == 4) catch @panic("test failure");
196196}
197197
198198const SplitStructInt = extern struct {
......@@ -212,9 +212,9 @@ test "C ABI split struct of ints" {
212212}
213213
214214export fn zig_split_struct_ints(x: SplitStructInt) void {
215 expect(x.a == 1234);
216 expect(x.b == 100);
217 expect(x.c == 1337);
215 expect(x.a == 1234) catch @panic("test failure");
216 expect(x.b == 100) catch @panic("test failure");
217 expect(x.c == 1337) catch @panic("test failure");
218218}
219219
220220extern fn c_big_struct_both(BigStruct) BigStruct;
......@@ -228,19 +228,19 @@ test "C ABI sret and byval together" {
228228 .e = 5,
229229 };
230230 var y = c_big_struct_both(s);
231 expect(y.a == 10);
232 expect(y.b == 11);
233 expect(y.c == 12);
234 expect(y.d == 13);
235 expect(y.e == 14);
231 try expect(y.a == 10);
232 try expect(y.b == 11);
233 try expect(y.c == 12);
234 try expect(y.d == 13);
235 try expect(y.e == 14);
236236}
237237
238238export fn zig_big_struct_both(x: BigStruct) BigStruct {
239 expect(x.a == 30);
240 expect(x.b == 31);
241 expect(x.c == 32);
242 expect(x.d == 33);
243 expect(x.e == 34);
239 expect(x.a == 30) catch @panic("test failure");
240 expect(x.b == 31) catch @panic("test failure");
241 expect(x.c == 32) catch @panic("test failure");
242 expect(x.d == 33) catch @panic("test failure");
243 expect(x.e == 34) catch @panic("test failure");
244244 var s = BigStruct{
245245 .a = 20,
246246 .b = 21,
......@@ -324,15 +324,15 @@ extern fn c_ret_i32() i32;
324324extern fn c_ret_i64() i64;
325325
326326test "C ABI integer return types" {
327 expect(c_ret_bool() == true);
327 try expect(c_ret_bool() == true);
328328
329 expect(c_ret_u8() == 0xff);
330 expect(c_ret_u16() == 0xffff);
331 expect(c_ret_u32() == 0xffffffff);
332 expect(c_ret_u64() == 0xffffffffffffffff);
329 try expect(c_ret_u8() == 0xff);
330 try expect(c_ret_u16() == 0xffff);
331 try expect(c_ret_u32() == 0xffffffff);
332 try expect(c_ret_u64() == 0xffffffffffffffff);
333333
334 expect(c_ret_i8() == -1);
335 expect(c_ret_i16() == -1);
336 expect(c_ret_i32() == -1);
337 expect(c_ret_i64() == -1);
334 try expect(c_ret_i8() == -1);
335 try expect(c_ret_i16() == -1);
336 try expect(c_ret_i32() == -1);
337 try expect(c_ret_i64() == -1);
338338}
test/standalone/brace_expansion/main.zig+31-31
......@@ -241,52 +241,52 @@ pub fn main() !void {
241241test "invalid inputs" {
242242 global_allocator = std.testing.allocator;
243243
244 expectError("}ABC", error.InvalidInput);
245 expectError("{ABC", error.InvalidInput);
246 expectError("}{", error.InvalidInput);
247 expectError("{}", error.InvalidInput);
248 expectError("A,B,C", error.InvalidInput);
249 expectError("{A{B,C}", error.InvalidInput);
250 expectError("{A,}", error.InvalidInput);
251
252 expectError("\n", error.InvalidInput);
244 try expectError("}ABC", error.InvalidInput);
245 try expectError("{ABC", error.InvalidInput);
246 try expectError("}{", error.InvalidInput);
247 try expectError("{}", error.InvalidInput);
248 try expectError("A,B,C", error.InvalidInput);
249 try expectError("{A{B,C}", error.InvalidInput);
250 try expectError("{A,}", error.InvalidInput);
251
252 try expectError("\n", error.InvalidInput);
253253}
254254
255fn expectError(test_input: []const u8, expected_err: anyerror) void {
255fn expectError(test_input: []const u8, expected_err: anyerror) !void {
256256 var output_buf = ArrayList(u8).init(global_allocator);
257257 defer output_buf.deinit();
258258
259 testing.expectError(expected_err, expandString(test_input, &output_buf));
259 try testing.expectError(expected_err, expandString(test_input, &output_buf));
260260}
261261
262262test "valid inputs" {
263263 global_allocator = std.testing.allocator;
264264
265 expectExpansion("{x,y,z}", "x y z");
266 expectExpansion("{A,B}{x,y}", "Ax Ay Bx By");
267 expectExpansion("{A,B{x,y}}", "A Bx By");
268
269 expectExpansion("{ABC}", "ABC");
270 expectExpansion("{A,B,C}", "A B C");
271 expectExpansion("ABC", "ABC");
272
273 expectExpansion("", "");
274 expectExpansion("{A,B}{C,{x,y}}{g,h}", "ACg ACh Axg Axh Ayg Ayh BCg BCh Bxg Bxh Byg Byh");
275 expectExpansion("{A,B}{C,C{x,y}}{g,h}", "ACg ACh ACxg ACxh ACyg ACyh BCg BCh BCxg BCxh BCyg BCyh");
276 expectExpansion("{A,B}a", "Aa Ba");
277 expectExpansion("{C,{x,y}}", "C x y");
278 expectExpansion("z{C,{x,y}}", "zC zx zy");
279 expectExpansion("a{b,c{d,e{f,g}}}", "ab acd acef aceg");
280 expectExpansion("a{x,y}b", "axb ayb");
281 expectExpansion("z{{a,b}}", "za zb");
282 expectExpansion("a{b}", "ab");
265 try expectExpansion("{x,y,z}", "x y z");
266 try expectExpansion("{A,B}{x,y}", "Ax Ay Bx By");
267 try expectExpansion("{A,B{x,y}}", "A Bx By");
268
269 try expectExpansion("{ABC}", "ABC");
270 try expectExpansion("{A,B,C}", "A B C");
271 try expectExpansion("ABC", "ABC");
272
273 try expectExpansion("", "");
274 try expectExpansion("{A,B}{C,{x,y}}{g,h}", "ACg ACh Axg Axh Ayg Ayh BCg BCh Bxg Bxh Byg Byh");
275 try expectExpansion("{A,B}{C,C{x,y}}{g,h}", "ACg ACh ACxg ACxh ACyg ACyh BCg BCh BCxg BCxh BCyg BCyh");
276 try expectExpansion("{A,B}a", "Aa Ba");
277 try expectExpansion("{C,{x,y}}", "C x y");
278 try expectExpansion("z{C,{x,y}}", "zC zx zy");
279 try expectExpansion("a{b,c{d,e{f,g}}}", "ab acd acef aceg");
280 try expectExpansion("a{x,y}b", "axb ayb");
281 try expectExpansion("z{{a,b}}", "za zb");
282 try expectExpansion("a{b}", "ab");
283283}
284284
285fn expectExpansion(test_input: []const u8, expected_result: []const u8) void {
285fn expectExpansion(test_input: []const u8, expected_result: []const u8) !void {
286286 var result = ArrayList(u8).init(global_allocator);
287287 defer result.deinit();
288288
289289 expandString(test_input, &result) catch unreachable;
290290
291 testing.expectEqualSlices(u8, expected_result, result.items);
291 try testing.expectEqualSlices(u8, expected_result, result.items);
292292}
test/standalone/empty_env/main.zig+2-2
......@@ -1,6 +1,6 @@
11const std = @import("std");
22
3pub fn main() void {
3pub fn main() !void {
44 const env_map = std.process.getEnvMap(std.testing.allocator) catch @panic("unable to get env map");
5 std.testing.expect(env_map.count() == 0);
5 try std.testing.expect(env_map.count() == 0);
66}
test/standalone/global_linkage/main.zig+2-2
......@@ -4,6 +4,6 @@ extern var obj1_integer: usize;
44extern var obj2_integer: usize;
55
66test "access the external integers" {
7 std.testing.expect(obj1_integer == 421);
8 std.testing.expect(obj2_integer == 422);
7 try std.testing.expect(obj1_integer == 421);
8 try std.testing.expect(obj2_integer == 422);
99}
test/standalone/issue_794/main.zig+1-1
......@@ -3,5 +3,5 @@ const std = @import("std");
33const testing = std.testing;
44
55test "c import" {
6 comptime testing.expect(c.NUMBER == 1234);
6 comptime try testing.expect(c.NUMBER == 1234);
77}
test/standalone/link_interdependent_static_c_libs/main.zig+1-1
......@@ -4,5 +4,5 @@ const c = @cImport(@cInclude("b.h"));
44
55test "import C sub" {
66 const result = c.sub(2, 1);
7 expect(result == 1);
7 try expect(result == 1);
88}
test/standalone/static_c_lib/foo.zig+2-2
......@@ -4,9 +4,9 @@ const c = @cImport(@cInclude("foo.h"));
44
55test "C add" {
66 const result = c.add(1, 2);
7 expect(result == 3);
7 try expect(result == 3);
88}
99
1010test "C extern variable" {
11 expect(c.foo == 12345);
11 try expect(c.foo == 12345);
1212}
test/standalone/use_alias/main.zig+1-1
......@@ -6,5 +6,5 @@ test "symbol exists" {
66 .a = 1,
77 .b = 1,
88 };
9 expect(foo.a + foo.b == 2);
9 try expect(foo.a + foo.b == 2);
1010}