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" {...@@ -358,7 +358,7 @@ test "comments" {
358 //expect(false);358 //expect(false);
359359
360 const x = true; // another comment360 const x = true; // another comment
361 expect(x);361 try expect(x);
362}362}
363 {#code_end#}363 {#code_end#}
364 <p>364 <p>
...@@ -718,15 +718,15 @@ const mem = @import("std").mem;...@@ -718,15 +718,15 @@ const mem = @import("std").mem;
718718
719test "string literals" {719test "string literals" {
720 const bytes = "hello";720 const bytes = "hello";
721 expect(@TypeOf(bytes) == *const [5:0]u8);721 try expect(@TypeOf(bytes) == *const [5:0]u8);
722 expect(bytes.len == 5);722 try expect(bytes.len == 5);
723 expect(bytes[1] == 'e');723 try expect(bytes[1] == 'e');
724 expect(bytes[5] == 0);724 try expect(bytes[5] == 0);
725 expect('e' == '\x65');725 try expect('e' == '\x65');
726 expect('\u{1f4a9}' == 128169);726 try expect('\u{1f4a9}' == 128169);
727 expect('💯' == 128175);727 try expect('💯' == 128175);
728 expect(mem.eql(u8, "hello", "h\x65llo"));728 try expect(mem.eql(u8, "hello", "h\x65llo"));
729 expect("\xff"[0] == 0xff); // non-UTF-8 strings are possible with \xNN notation.729 try expect("\xff"[0] == 0xff); // non-UTF-8 strings are possible with \xNN notation.
730}730}
731 {#code_end#}731 {#code_end#}
732 {#see_also|Arrays|Zig Test|Source Encoding#}732 {#see_also|Arrays|Zig Test|Source Encoding#}
...@@ -826,7 +826,7 @@ test "var" {...@@ -826,7 +826,7 @@ test "var" {
826826
827 y += 1;827 y += 1;
828828
829 expect(y == 5679);829 try expect(y == 5679);
830}830}
831 {#code_end#}831 {#code_end#}
832 <p>Variables must be initialized:</p>832 <p>Variables must be initialized:</p>
...@@ -845,7 +845,7 @@ const expect = @import("std").testing.expect;...@@ -845,7 +845,7 @@ const expect = @import("std").testing.expect;
845test "init with undefined" {845test "init with undefined" {
846 var x: i32 = undefined;846 var x: i32 = undefined;
847 x = 1;847 x = 1;
848 expect(x == 1);848 try expect(x == 1);
849}849}
850 {#code_end#}850 {#code_end#}
851 <p>851 <p>
...@@ -887,8 +887,8 @@ var y: i32 = add(10, x);...@@ -887,8 +887,8 @@ var y: i32 = add(10, x);
887const x: i32 = add(12, 34);887const x: i32 = add(12, 34);
888888
889test "global variables" {889test "global variables" {
890 expect(x == 46);890 try expect(x == 46);
891 expect(y == 56);891 try expect(y == 56);
892}892}
893893
894fn add(a: i32, b: i32) i32 {894fn add(a: i32, b: i32) i32 {
...@@ -906,8 +906,8 @@ const std = @import("std");...@@ -906,8 +906,8 @@ const std = @import("std");
906const expect = std.testing.expect;906const expect = std.testing.expect;
907907
908test "namespaced global variable" {908test "namespaced global variable" {
909 expect(foo() == 1235);909 try expect(foo() == 1235);
910 expect(foo() == 1236);910 try expect(foo() == 1236);
911}911}
912912
913fn foo() i32 {913fn foo() i32 {
...@@ -985,8 +985,8 @@ test "comptime vars" {...@@ -985,8 +985,8 @@ test "comptime vars" {
985 x += 1;985 x += 1;
986 y += 1;986 y += 1;
987987
988 expect(x == 2);988 try expect(x == 2);
989 expect(y == 2);989 try expect(y == 2);
990990
991 if (y != 2) {991 if (y != 2) {
992 // This compile error never triggers because y is a comptime variable,992 // This compile error never triggers because y is a comptime variable,
...@@ -1777,6 +1777,7 @@ orelse catch...@@ -1777,6 +1777,7 @@ orelse catch
1777 {#header_open|Arrays#}1777 {#header_open|Arrays#}
1778 {#code_begin|test|arrays#}1778 {#code_begin|test|arrays#}
1779const expect = @import("std").testing.expect;1779const expect = @import("std").testing.expect;
1780const assert = @import("std").debug.assert;
1780const mem = @import("std").mem;1781const mem = @import("std").mem;
17811782
1782// array literal1783// array literal
...@@ -1784,14 +1785,14 @@ const message = [_]u8{ 'h', 'e', 'l', 'l', 'o' };...@@ -1784,14 +1785,14 @@ const message = [_]u8{ 'h', 'e', 'l', 'l', 'o' };
17841785
1785// get the size of an array1786// get the size of an array
1786comptime {1787comptime {
1787 expect(message.len == 5);1788 assert(message.len == 5);
1788}1789}
17891790
1790// A string literal is a single-item pointer to an array literal.1791// A string literal is a single-item pointer to an array literal.
1791const same_message = "hello";1792const same_message = "hello";
17921793
1793comptime {1794comptime {
1794 expect(mem.eql(u8, &message, same_message));1795 assert(mem.eql(u8, &message, same_message));
1795}1796}
17961797
1797test "iterate over an array" {1798test "iterate over an array" {
...@@ -1799,7 +1800,7 @@ test "iterate over an array" {...@@ -1799,7 +1800,7 @@ test "iterate over an array" {
1799 for (message) |byte| {1800 for (message) |byte| {
1800 sum += byte;1801 sum += byte;
1801 }1802 }
1802 expect(sum == 'h' + 'e' + 'l' * 2 + 'o');1803 try expect(sum == 'h' + 'e' + 'l' * 2 + 'o');
1803}1804}
18041805
1805// modifiable array1806// modifiable array
...@@ -1809,8 +1810,8 @@ test "modify an array" {...@@ -1809,8 +1810,8 @@ test "modify an array" {
1809 for (some_integers) |*item, i| {1810 for (some_integers) |*item, i| {
1810 item.* = @intCast(i32, i);1811 item.* = @intCast(i32, i);
1811 }1812 }
1812 expect(some_integers[10] == 10);1813 try expect(some_integers[10] == 10);
1813 expect(some_integers[99] == 99);1814 try expect(some_integers[99] == 99);
1814}1815}
18151816
1816// array concatenation works if the values are known1817// array concatenation works if the values are known
...@@ -1819,7 +1820,7 @@ const part_one = [_]i32{ 1, 2, 3, 4 };...@@ -1819,7 +1820,7 @@ const part_one = [_]i32{ 1, 2, 3, 4 };
1819const part_two = [_]i32{ 5, 6, 7, 8 };1820const part_two = [_]i32{ 5, 6, 7, 8 };
1820const all_of_it = part_one ++ part_two;1821const all_of_it = part_one ++ part_two;
1821comptime {1822comptime {
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 }));
1823}1824}
18241825
1825// remember that string literals are arrays1826// remember that string literals are arrays
...@@ -1827,21 +1828,21 @@ const hello = "hello";...@@ -1827,21 +1828,21 @@ const hello = "hello";
1827const world = "world";1828const world = "world";
1828const hello_world = hello ++ " " ++ world;1829const hello_world = hello ++ " " ++ world;
1829comptime {1830comptime {
1830 expect(mem.eql(u8, hello_world, "hello world"));1831 assert(mem.eql(u8, hello_world, "hello world"));
1831}1832}
18321833
1833// ** does repeating patterns1834// ** does repeating patterns
1834const pattern = "ab" ** 3;1835const pattern = "ab" ** 3;
1835comptime {1836comptime {
1836 expect(mem.eql(u8, pattern, "ababab"));1837 assert(mem.eql(u8, pattern, "ababab"));
1837}1838}
18381839
1839// initialize an array to zero1840// initialize an array to zero
1840const all_zero = [_]u16{0} ** 10;1841const all_zero = [_]u16{0} ** 10;
18411842
1842comptime {1843comptime {
1843 expect(all_zero.len == 10);1844 assert(all_zero.len == 10);
1844 expect(all_zero[5] == 0);1845 assert(all_zero[5] == 0);
1845}1846}
18461847
1847// use compile-time code to initialize an array1848// use compile-time code to initialize an array
...@@ -1861,8 +1862,8 @@ const Point = struct {...@@ -1861,8 +1862,8 @@ const Point = struct {
1861};1862};
18621863
1863test "compile-time array initialization" {1864test "compile-time array initialization" {
1864 expect(fancy_array[4].x == 4);1865 try expect(fancy_array[4].x == 4);
1865 expect(fancy_array[4].y == 8);1866 try expect(fancy_array[4].y == 8);
1866}1867}
18671868
1868// call a function to initialize an array1869// call a function to initialize an array
...@@ -1874,9 +1875,9 @@ fn makePoint(x: i32) Point {...@@ -1874,9 +1875,9 @@ fn makePoint(x: i32) Point {
1874 };1875 };
1875}1876}
1876test "array initialization with function calls" {1877test "array initialization with function calls" {
1877 expect(more_points[4].x == 3);1878 try expect(more_points[4].x == 3);
1878 expect(more_points[4].y == 6);1879 try expect(more_points[4].y == 6);
1879 expect(more_points.len == 10);1880 try expect(more_points.len == 10);
1880}1881}
1881 {#code_end#}1882 {#code_end#}
1882 {#see_also|for|Slices#}1883 {#see_also|for|Slices#}
...@@ -1890,10 +1891,10 @@ const expect = std.testing.expect;...@@ -1890,10 +1891,10 @@ const expect = std.testing.expect;
18901891
1891test "anonymous list literal syntax" {1892test "anonymous list literal syntax" {
1892 var array: [4]u8 = .{11, 22, 33, 44};1893 var array: [4]u8 = .{11, 22, 33, 44};
1893 expect(array[0] == 11);1894 try expect(array[0] == 11);
1894 expect(array[1] == 22);1895 try expect(array[1] == 22);
1895 expect(array[2] == 33);1896 try expect(array[2] == 33);
1896 expect(array[3] == 44);1897 try expect(array[3] == 44);
1897}1898}
1898 {#code_end#}1899 {#code_end#}
1899 <p>1900 <p>
...@@ -1905,15 +1906,15 @@ const std = @import("std");...@@ -1905,15 +1906,15 @@ const std = @import("std");
1905const expect = std.testing.expect;1906const expect = std.testing.expect;
19061907
1907test "fully anonymous list literal" {1908test "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"});
1909}1910}
19101911
1911fn dump(args: anytype) void {1912fn dump(args: anytype) !void {
1912 expect(args.@"0" == 1234);1913 try expect(args.@"0" == 1234);
1913 expect(args.@"1" == 12.34);1914 try expect(args.@"1" == 12.34);
1914 expect(args.@"2");1915 try expect(args.@"2");
1915 expect(args.@"3"[0] == 'h');1916 try expect(args.@"3"[0] == 'h');
1916 expect(args.@"3"[1] == 'i');1917 try expect(args.@"3"[1] == 'i');
1917}1918}
1918 {#code_end#}1919 {#code_end#}
1919 {#header_close#}1920 {#header_close#}
...@@ -1934,13 +1935,13 @@ const mat4x4 = [4][4]f32{...@@ -1934,13 +1935,13 @@ const mat4x4 = [4][4]f32{
1934};1935};
1935test "multidimensional arrays" {1936test "multidimensional arrays" {
1936 // Access the 2D array by indexing the outer array, and then the inner array.1937 // 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
1939 // Here we iterate with for loops.1940 // Here we iterate with for loops.
1940 for (mat4x4) |row, row_index| {1941 for (mat4x4) |row, row_index| {
1941 for (row) |cell, column_index| {1942 for (row) |cell, column_index| {
1942 if (row_index == column_index) {1943 if (row_index == column_index) {
1943 expect(cell == 1.0);1944 try expect(cell == 1.0);
1944 }1945 }
1945 }1946 }
1946 }1947 }
...@@ -1960,9 +1961,9 @@ const expect = std.testing.expect;...@@ -1960,9 +1961,9 @@ const expect = std.testing.expect;
1960test "null terminated array" {1961test "null terminated array" {
1961 const array = [_:0]u8 {1, 2, 3, 4};1962 const array = [_:0]u8 {1, 2, 3, 4};
19621963
1963 expect(@TypeOf(array) == [4:0]u8);1964 try expect(@TypeOf(array) == [4:0]u8);
1964 expect(array.len == 4);1965 try expect(array.len == 4);
1965 expect(array[4] == 0);1966 try expect(array[4] == 0);
1966}1967}
1967 {#code_end#}1968 {#code_end#}
1968 {#see_also|Sentinel-Terminated Pointers|Sentinel-Terminated Slices#}1969 {#see_also|Sentinel-Terminated Pointers|Sentinel-Terminated Slices#}
...@@ -2040,17 +2041,17 @@ test "address of syntax" {...@@ -2040,17 +2041,17 @@ test "address of syntax" {
2040 const x_ptr = &x;2041 const x_ptr = &x;
20412042
2042 // Dereference a pointer:2043 // Dereference a pointer:
2043 expect(x_ptr.* == 1234);2044 try expect(x_ptr.* == 1234);
20442045
2045 // When you get the address of a const variable, you get a const single-item pointer.2046 // 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
2048 // If you want to mutate the value, you'd need an address of a mutable variable:2049 // If you want to mutate the value, you'd need an address of a mutable variable:
2049 var y: i32 = 5678;2050 var y: i32 = 5678;
2050 const y_ptr = &y;2051 const y_ptr = &y;
2051 expect(@TypeOf(y_ptr) == *i32);2052 try expect(@TypeOf(y_ptr) == *i32);
2052 y_ptr.* += 1;2053 y_ptr.* += 1;
2053 expect(y_ptr.* == 5679);2054 try expect(y_ptr.* == 5679);
2054}2055}
20552056
2056test "pointer array access" {2057test "pointer array access" {
...@@ -2059,11 +2060,11 @@ test "pointer array access" {...@@ -2059,11 +2060,11 @@ test "pointer array access" {
2059 // does not support pointer arithmetic.2060 // does not support pointer arithmetic.
2060 var array = [_]u8{ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };2061 var array = [_]u8{ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
2061 const ptr = &array[2];2062 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);
2065 ptr.* += 1;2066 ptr.* += 1;
2066 expect(array[2] == 4);2067 try expect(array[2] == 4);
2067}2068}
2068 {#code_end#}2069 {#code_end#}
2069 <p>2070 <p>
...@@ -2081,11 +2082,11 @@ const expect = @import("std").testing.expect;...@@ -2081,11 +2082,11 @@ const expect = @import("std").testing.expect;
2081test "pointer slicing" {2082test "pointer slicing" {
2082 var array = [_]u8{ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };2083 var array = [_]u8{ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
2083 const slice = array[2..4];2084 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);
2087 slice[1] += 1;2088 slice[1] += 1;
2088 expect(array[3] == 5);2089 try expect(array[3] == 5);
2089}2090}
2090 {#code_end#}2091 {#code_end#}
2091 <p>Pointers work at compile-time too, as long as the code does not depend on2092 <p>Pointers work at compile-time too, as long as the code does not depend on
...@@ -2099,7 +2100,7 @@ test "comptime pointers" {...@@ -2099,7 +2100,7 @@ test "comptime pointers" {
2099 const ptr = &x;2100 const ptr = &x;
2100 ptr.* += 1;2101 ptr.* += 1;
2101 x += 1;2102 x += 1;
2102 expect(ptr.* == 3);2103 try expect(ptr.* == 3);
2103 }2104 }
2104}2105}
2105 {#code_end#}2106 {#code_end#}
...@@ -2111,8 +2112,8 @@ const expect = @import("std").testing.expect;...@@ -2111,8 +2112,8 @@ const expect = @import("std").testing.expect;
2111test "@ptrToInt and @intToPtr" {2112test "@ptrToInt and @intToPtr" {
2112 const ptr = @intToPtr(*i32, 0xdeadbee0);2113 const ptr = @intToPtr(*i32, 0xdeadbee0);
2113 const addr = @ptrToInt(ptr);2114 const addr = @ptrToInt(ptr);
2114 expect(@TypeOf(addr) == usize);2115 try expect(@TypeOf(addr) == usize);
2115 expect(addr == 0xdeadbee0);2116 try expect(addr == 0xdeadbee0);
2116}2117}
2117 {#code_end#}2118 {#code_end#}
2118 <p>Zig is able to preserve memory addresses in comptime code, as long as2119 <p>Zig is able to preserve memory addresses in comptime code, as long as
...@@ -2126,8 +2127,8 @@ test "comptime @intToPtr" {...@@ -2126,8 +2127,8 @@ test "comptime @intToPtr" {
2126 // ptr is never dereferenced.2127 // ptr is never dereferenced.
2127 const ptr = @intToPtr(*i32, 0xdeadbee0);2128 const ptr = @intToPtr(*i32, 0xdeadbee0);
2128 const addr = @ptrToInt(ptr);2129 const addr = @ptrToInt(ptr);
2129 expect(@TypeOf(addr) == usize);2130 try expect(@TypeOf(addr) == usize);
2130 expect(addr == 0xdeadbee0);2131 try expect(addr == 0xdeadbee0);
2131 }2132 }
2132}2133}
2133 {#code_end#}2134 {#code_end#}
...@@ -2142,7 +2143,7 @@ const expect = @import("std").testing.expect;...@@ -2142,7 +2143,7 @@ const expect = @import("std").testing.expect;
21422143
2143test "volatile" {2144test "volatile" {
2144 const mmio_ptr = @intToPtr(*volatile u8, 0x12345678);2145 const mmio_ptr = @intToPtr(*volatile u8, 0x12345678);
2145 expect(@TypeOf(mmio_ptr) == *volatile u8);2146 try expect(@TypeOf(mmio_ptr) == *volatile u8);
2146}2147}
2147 {#code_end#}2148 {#code_end#}
2148 <p>2149 <p>
...@@ -2163,20 +2164,20 @@ const expect = std.testing.expect;...@@ -2163,20 +2164,20 @@ const expect = std.testing.expect;
2163test "pointer casting" {2164test "pointer casting" {
2164 const bytes align(@alignOf(u32)) = [_]u8{ 0x12, 0x12, 0x12, 0x12 };2165 const bytes align(@alignOf(u32)) = [_]u8{ 0x12, 0x12, 0x12, 0x12 };
2165 const u32_ptr = @ptrCast(*const u32, &bytes);2166 const u32_ptr = @ptrCast(*const u32, &bytes);
2166 expect(u32_ptr.* == 0x12121212);2167 try expect(u32_ptr.* == 0x12121212);
21672168
2168 // Even this example is contrived - there are better ways to do the above than2169 // Even this example is contrived - there are better ways to do the above than
2169 // pointer casting. For example, using a slice narrowing cast:2170 // pointer casting. For example, using a slice narrowing cast:
2170 const u32_value = std.mem.bytesAsSlice(u32, bytes[0..])[0];2171 const u32_value = std.mem.bytesAsSlice(u32, bytes[0..])[0];
2171 expect(u32_value == 0x12121212);2172 try expect(u32_value == 0x12121212);
21722173
2173 // And even another way, the most straightforward way to do it:2174 // And even another way, the most straightforward way to do it:
2174 expect(@bitCast(u32, bytes) == 0x12121212);2175 try expect(@bitCast(u32, bytes) == 0x12121212);
2175}2176}
21762177
2177test "pointer child type" {2178test "pointer child type" {
2178 // pointer types have a `child` field which tells you the type they point to.2179 // 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);
2180}2181}
2181 {#code_end#}2182 {#code_end#}
2182 {#header_open|Alignment#}2183 {#header_open|Alignment#}
...@@ -2201,10 +2202,10 @@ const expect = std.testing.expect;...@@ -2201,10 +2202,10 @@ const expect = std.testing.expect;
2201test "variable alignment" {2202test "variable alignment" {
2202 var x: i32 = 1234;2203 var x: i32 = 1234;
2203 const align_of_i32 = @alignOf(@TypeOf(x));2204 const align_of_i32 = @alignOf(@TypeOf(x));
2204 expect(@TypeOf(&x) == *i32);2205 try expect(@TypeOf(&x) == *i32);
2205 expect(*i32 == *align(align_of_i32) i32);2206 try expect(*i32 == *align(align_of_i32) i32);
2206 if (std.Target.current.cpu.arch == .x86_64) {2207 if (std.Target.current.cpu.arch == .x86_64) {
2207 expect(@typeInfo(*i32).Pointer.alignment == 4);2208 try expect(@typeInfo(*i32).Pointer.alignment == 4);
2208 }2209 }
2209}2210}
2210 {#code_end#}2211 {#code_end#}
...@@ -2222,11 +2223,11 @@ const expect = @import("std").testing.expect;...@@ -2222,11 +2223,11 @@ const expect = @import("std").testing.expect;
2222var foo: u8 align(4) = 100;2223var foo: u8 align(4) = 100;
22232224
2224test "global variable alignment" {2225test "global variable alignment" {
2225 expect(@typeInfo(@TypeOf(&foo)).Pointer.alignment == 4);2226 try expect(@typeInfo(@TypeOf(&foo)).Pointer.alignment == 4);
2226 expect(@TypeOf(&foo) == *align(4) u8);2227 try expect(@TypeOf(&foo) == *align(4) u8);
2227 const as_pointer_to_array: *[1]u8 = &foo;2228 const as_pointer_to_array: *[1]u8 = &foo;
2228 const as_slice: []u8 = as_pointer_to_array;2229 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);
2230}2231}
22312232
2232fn derp() align(@sizeOf(usize) * 2) i32 { return 1234; }2233fn derp() align(@sizeOf(usize) * 2) i32 { return 1234; }
...@@ -2234,9 +2235,9 @@ fn noop1() align(1) void {}...@@ -2234,9 +2235,9 @@ fn noop1() align(1) void {}
2234fn noop4() align(4) void {}2235fn noop4() align(4) void {}
22352236
2236test "function alignment" {2237test "function alignment" {
2237 expect(derp() == 1234);2238 try expect(derp() == 1234);
2238 expect(@TypeOf(noop1) == fn() align(1) void);2239 try expect(@TypeOf(noop1) == fn() align(1) void);
2239 expect(@TypeOf(noop4) == fn() align(4) void);2240 try expect(@TypeOf(noop4) == fn() align(4) void);
2240 noop1();2241 noop1();
2241 noop4();2242 noop4();
2242}2243}
...@@ -2253,7 +2254,7 @@ const std = @import("std");...@@ -2253,7 +2254,7 @@ const std = @import("std");
2253test "pointer alignment safety" {2254test "pointer alignment safety" {
2254 var array align(4) = [_]u32{ 0x11111111, 0x11111111 };2255 var array align(4) = [_]u32{ 0x11111111, 0x11111111 };
2255 const bytes = std.mem.sliceAsBytes(array[0..]);2256 const bytes = std.mem.sliceAsBytes(array[0..]);
2256 std.testing.expect(foo(bytes) == 0x11111111);2257 try std.testing.expect(foo(bytes) == 0x11111111);
2257}2258}
2258fn foo(bytes: []u8) u32 {2259fn foo(bytes: []u8) u32 {
2259 const slice4 = bytes[1..5];2260 const slice4 = bytes[1..5];
...@@ -2279,7 +2280,7 @@ const expect = std.testing.expect;...@@ -2279,7 +2280,7 @@ const expect = std.testing.expect;
2279test "allowzero" {2280test "allowzero" {
2280 var zero: usize = 0;2281 var zero: usize = 0;
2281 var ptr = @intToPtr(*allowzero i32, zero);2282 var ptr = @intToPtr(*allowzero i32, zero);
2282 expect(@ptrToInt(ptr) == 0);2283 try expect(@ptrToInt(ptr) == 0);
2283}2284}
2284 {#code_end#}2285 {#code_end#}
2285 {#header_close#}2286 {#header_close#}
...@@ -2321,14 +2322,14 @@ test "basic slices" {...@@ -2321,14 +2322,14 @@ test "basic slices" {
2321 // Both can be accessed with the `len` field.2322 // Both can be accessed with the `len` field.
2322 var known_at_runtime_zero: usize = 0;2323 var known_at_runtime_zero: usize = 0;
2323 const slice = array[known_at_runtime_zero..array.len];2324 const slice = array[known_at_runtime_zero..array.len];
2324 expect(&slice[0] == &array[0]);2325 try expect(&slice[0] == &array[0]);
2325 expect(slice.len == array.len);2326 try expect(slice.len == array.len);
23262327
2327 // Using the address-of operator on a slice gives a single-item pointer,2328 // Using the address-of operator on a slice gives a single-item pointer,
2328 // while using the `ptr` field gives a many-item pointer.2329 // while using the `ptr` field gives a many-item pointer.
2329 expect(@TypeOf(slice.ptr) == [*]i32);2330 try expect(@TypeOf(slice.ptr) == [*]i32);
2330 expect(@TypeOf(&slice[0]) == *i32);2331 try expect(@TypeOf(&slice[0]) == *i32);
2331 expect(@ptrToInt(slice.ptr) == @ptrToInt(&slice[0]));2332 try expect(@ptrToInt(slice.ptr) == @ptrToInt(&slice[0]));
23322333
2333 // Slices have array bounds checking. If you try to access something out2334 // Slices have array bounds checking. If you try to access something out
2334 // of bounds, you'll get a safety check failure:2335 // of bounds, you'll get a safety check failure:
...@@ -2362,7 +2363,7 @@ test "using slices for strings" {...@@ -2362,7 +2363,7 @@ test "using slices for strings" {
2362 // Generally, you can use UTF-8 and not worry about whether something is a2363 // Generally, you can use UTF-8 and not worry about whether something is a
2363 // string. If you don't need to deal with individual characters, no need2364 // string. If you don't need to deal with individual characters, no need
2364 // to decode.2365 // to decode.
2365 expect(mem.eql(u8, hello_world, "hello 世界"));2366 try expect(mem.eql(u8, hello_world, "hello 世界"));
2366}2367}
23672368
2368test "slice pointer" {2369test "slice pointer" {
...@@ -2372,16 +2373,16 @@ test "slice pointer" {...@@ -2372,16 +2373,16 @@ test "slice pointer" {
2372 // You can use slicing syntax to convert a pointer into a slice:2373 // You can use slicing syntax to convert a pointer into a slice:
2373 const slice = ptr[0..5];2374 const slice = ptr[0..5];
2374 slice[2] = 3;2375 slice[2] = 3;
2375 expect(slice[2] == 3);2376 try expect(slice[2] == 3);
2376 // The slice is mutable because we sliced a mutable pointer.2377 // The slice is mutable because we sliced a mutable pointer.
2377 // Furthermore, it is actually a pointer to an array, since the start2378 // Furthermore, it is actually a pointer to an array, since the start
2378 // and end indexes were both comptime-known.2379 // and end indexes were both comptime-known.
2379 expect(@TypeOf(slice) == *[5]u8);2380 try expect(@TypeOf(slice) == *[5]u8);
23802381
2381 // You can also slice a slice:2382 // You can also slice a slice:
2382 const slice2 = slice[2..3];2383 const slice2 = slice[2..3];
2383 expect(slice2.len == 1);2384 try expect(slice2.len == 1);
2384 expect(slice2[0] == 3);2385 try expect(slice2[0] == 3);
2385}2386}
2386 {#code_end#}2387 {#code_end#}
2387 {#see_also|Pointers|for|Arrays#}2388 {#see_also|Pointers|for|Arrays#}
...@@ -2400,8 +2401,8 @@ const expect = std.testing.expect;...@@ -2400,8 +2401,8 @@ const expect = std.testing.expect;
2400test "null terminated slice" {2401test "null terminated slice" {
2401 const slice: [:0]const u8 = "hello";2402 const slice: [:0]const u8 = "hello";
24022403
2403 expect(slice.len == 5);2404 try expect(slice.len == 5);
2404 expect(slice[5] == 0);2405 try expect(slice[5] == 0);
2405}2406}
2406 {#code_end#}2407 {#code_end#}
2407 {#see_also|Sentinel-Terminated Pointers|Sentinel-Terminated Arrays#}2408 {#see_also|Sentinel-Terminated Pointers|Sentinel-Terminated Arrays#}
...@@ -2463,12 +2464,12 @@ const expect = @import("std").testing.expect;...@@ -2463,12 +2464,12 @@ const expect = @import("std").testing.expect;
2463test "dot product" {2464test "dot product" {
2464 const v1 = Vec3.init(1.0, 0.0, 0.0);2465 const v1 = Vec3.init(1.0, 0.0, 0.0);
2465 const v2 = Vec3.init(0.0, 1.0, 0.0);2466 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
2468 // Other than being available to call with dot syntax, struct methods are2469 // Other than being available to call with dot syntax, struct methods are
2469 // not special. You can reference them as any other declaration inside2470 // not special. You can reference them as any other declaration inside
2470 // the struct:2471 // the struct:
2471 expect(Vec3.dot(v1, v2) == 0.0);2472 try expect(Vec3.dot(v1, v2) == 0.0);
2472}2473}
24732474
2474// Structs can have global declarations.2475// Structs can have global declarations.
...@@ -2477,8 +2478,8 @@ const Empty = struct {...@@ -2477,8 +2478,8 @@ const Empty = struct {
2477 pub const PI = 3.14;2478 pub const PI = 3.14;
2478};2479};
2479test "struct namespaced variable" {2480test "struct namespaced variable" {
2480 expect(Empty.PI == 3.14);2481 try expect(Empty.PI == 3.14);
2481 expect(@sizeOf(Empty) == 0);2482 try expect(@sizeOf(Empty) == 0);
24822483
2483 // you can still instantiate an empty struct2484 // you can still instantiate an empty struct
2484 const does_nothing = Empty {};2485 const does_nothing = Empty {};
...@@ -2496,7 +2497,7 @@ test "field parent pointer" {...@@ -2496,7 +2497,7 @@ test "field parent pointer" {
2496 .y = 0.5678,2497 .y = 0.5678,
2497 };2498 };
2498 setYBasedOnX(&point.x, 0.9);2499 setYBasedOnX(&point.x, 0.9);
2499 expect(point.y == 0.9);2500 try expect(point.y == 0.9);
2500}2501}
25012502
2502// You can return a struct from a function. This is how we do generics2503// You can return a struct from a function. This is how we do generics
...@@ -2518,19 +2519,19 @@ fn LinkedList(comptime T: type) type {...@@ -2518,19 +2519,19 @@ fn LinkedList(comptime T: type) type {
2518test "linked list" {2519test "linked list" {
2519 // Functions called at compile-time are memoized. This means you can2520 // Functions called at compile-time are memoized. This means you can
2520 // do this:2521 // do this:
2521 expect(LinkedList(i32) == LinkedList(i32));2522 try expect(LinkedList(i32) == LinkedList(i32));
25222523
2523 var list = LinkedList(i32) {2524 var list = LinkedList(i32) {
2524 .first = null,2525 .first = null,
2525 .last = null,2526 .last = null,
2526 .len = 0,2527 .len = 0,
2527 };2528 };
2528 expect(list.len == 0);2529 try expect(list.len == 0);
25292530
2530 // Since types are first class values you can instantiate the type2531 // Since types are first class values you can instantiate the type
2531 // by assigning it to a variable:2532 // by assigning it to a variable:
2532 const ListOfInts = LinkedList(i32);2533 const ListOfInts = LinkedList(i32);
2533 expect(ListOfInts == LinkedList(i32));2534 try expect(ListOfInts == LinkedList(i32));
25342535
2535 var node = ListOfInts.Node {2536 var node = ListOfInts.Node {
2536 .prev = null,2537 .prev = null,
...@@ -2542,7 +2543,7 @@ test "linked list" {...@@ -2542,7 +2543,7 @@ test "linked list" {
2542 .last = &node,2543 .last = &node,
2543 .len = 1,2544 .len = 1,
2544 };2545 };
2545 expect(list2.first.?.data == 1234);2546 try expect(list2.first.?.data == 1234);
2546}2547}
2547 {#code_end#}2548 {#code_end#}
25482549
...@@ -2615,25 +2616,25 @@ const Divided = packed struct {...@@ -2615,25 +2616,25 @@ const Divided = packed struct {
2615};2616};
26162617
2617test "@bitCast between packed structs" {2618test "@bitCast between packed structs" {
2618 doTheTest();2619 try doTheTest();
2619 comptime doTheTest();2620 comptime try doTheTest();
2620}2621}
26212622
2622fn doTheTest() void {2623fn doTheTest() !void {
2623 expect(@sizeOf(Full) == 2);2624 try expect(@sizeOf(Full) == 2);
2624 expect(@sizeOf(Divided) == 2);2625 try expect(@sizeOf(Divided) == 2);
2625 var full = Full{ .number = 0x1234 };2626 var full = Full{ .number = 0x1234 };
2626 var divided = @bitCast(Divided, full);2627 var divided = @bitCast(Divided, full);
2627 switch (builtin.endian) {2628 switch (builtin.endian) {
2628 .Big => {2629 .Big => {
2629 expect(divided.half1 == 0x12);2630 try expect(divided.half1 == 0x12);
2630 expect(divided.quarter3 == 0x3);2631 try expect(divided.quarter3 == 0x3);
2631 expect(divided.quarter4 == 0x4);2632 try expect(divided.quarter4 == 0x4);
2632 },2633 },
2633 .Little => {2634 .Little => {
2634 expect(divided.half1 == 0x34);2635 try expect(divided.half1 == 0x34);
2635 expect(divided.quarter3 == 0x2);2636 try expect(divided.quarter3 == 0x2);
2636 expect(divided.quarter4 == 0x1);2637 try expect(divided.quarter4 == 0x1);
2637 },2638 },
2638 }2639 }
2639}2640}
...@@ -2659,7 +2660,7 @@ var foo = BitField{...@@ -2659,7 +2660,7 @@ var foo = BitField{
26592660
2660test "pointer to non-byte-aligned field" {2661test "pointer to non-byte-aligned field" {
2661 const ptr = &foo.b;2662 const ptr = &foo.b;
2662 expect(ptr.* == 2);2663 try expect(ptr.* == 2);
2663}2664}
2664 {#code_end#}2665 {#code_end#}
2665 <p>2666 <p>
...@@ -2683,7 +2684,7 @@ var bit_field = BitField{...@@ -2683,7 +2684,7 @@ var bit_field = BitField{
2683};2684};
26842685
2685test "pointer to non-bit-aligned field" {2686test "pointer to non-bit-aligned field" {
2686 expect(bar(&bit_field.b) == 2);2687 try expect(bar(&bit_field.b) == 2);
2687}2688}
26882689
2689fn bar(x: *const u3) u3 {2690fn bar(x: *const u3) u3 {
...@@ -2714,8 +2715,8 @@ var bit_field = BitField{...@@ -2714,8 +2715,8 @@ var bit_field = BitField{
2714};2715};
27152716
2716test "pointer to non-bit-aligned field" {2717test "pointer to non-bit-aligned field" {
2717 expect(@ptrToInt(&bit_field.a) == @ptrToInt(&bit_field.b));2718 try expect(@ptrToInt(&bit_field.a) == @ptrToInt(&bit_field.b));
2718 expect(@ptrToInt(&bit_field.a) == @ptrToInt(&bit_field.c));2719 try expect(@ptrToInt(&bit_field.a) == @ptrToInt(&bit_field.c));
2719}2720}
2720 {#code_end#}2721 {#code_end#}
2721 <p>2722 <p>
...@@ -2733,13 +2734,13 @@ const BitField = packed struct {...@@ -2733,13 +2734,13 @@ const BitField = packed struct {
27332734
2734test "pointer to non-bit-aligned field" {2735test "pointer to non-bit-aligned field" {
2735 comptime {2736 comptime {
2736 expect(@bitOffsetOf(BitField, "a") == 0);2737 try expect(@bitOffsetOf(BitField, "a") == 0);
2737 expect(@bitOffsetOf(BitField, "b") == 3);2738 try expect(@bitOffsetOf(BitField, "b") == 3);
2738 expect(@bitOffsetOf(BitField, "c") == 6);2739 try expect(@bitOffsetOf(BitField, "c") == 6);
27392740
2740 expect(@byteOffsetOf(BitField, "a") == 0);2741 try expect(@byteOffsetOf(BitField, "a") == 0);
2741 expect(@byteOffsetOf(BitField, "b") == 0);2742 try expect(@byteOffsetOf(BitField, "b") == 0);
2742 expect(@byteOffsetOf(BitField, "c") == 0);2743 try expect(@byteOffsetOf(BitField, "c") == 0);
2743 }2744 }
2744}2745}
2745 {#code_end#}2746 {#code_end#}
...@@ -2776,9 +2777,9 @@ test "aligned struct fields" {...@@ -2776,9 +2777,9 @@ test "aligned struct fields" {
2776 };2777 };
2777 var foo = S{ .a = 1, .b = 2 };2778 var foo = S{ .a = 1, .b = 2 };
27782779
2779 expectEqual(64, @alignOf(S));2780 try expectEqual(64, @alignOf(S));
2780 expectEqual(*align(2) u32, @TypeOf(&foo.a));2781 try expectEqual(*align(2) u32, @TypeOf(&foo.a));
2781 expectEqual(*align(64) u32, @TypeOf(&foo.b));2782 try expectEqual(*align(64) u32, @TypeOf(&foo.b));
2782}2783}
2783 {#code_end#}2784 {#code_end#}
2784 <p>2785 <p>
...@@ -2834,8 +2835,8 @@ test "anonymous struct literal" {...@@ -2834,8 +2835,8 @@ test "anonymous struct literal" {
2834 .x = 13,2835 .x = 13,
2835 .y = 67,2836 .y = 67,
2836 };2837 };
2837 expect(pt.x == 13);2838 try expect(pt.x == 13);
2838 expect(pt.y == 67);2839 try expect(pt.y == 67);
2839}2840}
2840 {#code_end#}2841 {#code_end#}
2841 <p>2842 <p>
...@@ -2847,7 +2848,7 @@ const std = @import("std");...@@ -2847,7 +2848,7 @@ const std = @import("std");
2847const expect = std.testing.expect;2848const expect = std.testing.expect;
28482849
2849test "fully anonymous struct" {2850test "fully anonymous struct" {
2850 dump(.{2851 try dump(.{
2851 .int = @as(u32, 1234),2852 .int = @as(u32, 1234),
2852 .float = @as(f64, 12.34),2853 .float = @as(f64, 12.34),
2853 .b = true,2854 .b = true,
...@@ -2855,12 +2856,12 @@ test "fully anonymous struct" {...@@ -2855,12 +2856,12 @@ test "fully anonymous struct" {
2855 });2856 });
2856}2857}
28572858
2858fn dump(args: anytype) void {2859fn dump(args: anytype) !void {
2859 expect(args.int == 1234);2860 try expect(args.int == 1234);
2860 expect(args.float == 12.34);2861 try expect(args.float == 12.34);
2861 expect(args.b);2862 try expect(args.b);
2862 expect(args.s[0] == 'h');2863 try expect(args.s[0] == 'h');
2863 expect(args.s[1] == 'i');2864 try expect(args.s[1] == 'i');
2864}2865}
2865 {#code_end#}2866 {#code_end#}
2866 <p>2867 <p>
...@@ -2884,14 +2885,14 @@ test "tuple" {...@@ -2884,14 +2885,14 @@ test "tuple" {
2884 true,2885 true,
2885 "hi",2886 "hi",
2886 } ++ .{false} ** 2;2887 } ++ .{false} ** 2;
2887 expect(values[0] == 1234);2888 try expect(values[0] == 1234);
2888 expect(values[4] == false);2889 try expect(values[4] == false);
2889 inline for (values) |v, i| {2890 inline for (values) |v, i| {
2890 if (i != 2) continue;2891 if (i != 2) continue;
2891 expect(v);2892 try expect(v);
2892 }2893 }
2893 expect(values.len == 6);2894 try expect(values.len == 6);
2894 expect(values.@"3"[0] == 'h');2895 try expect(values.@"3"[0] == 'h');
2895}2896}
2896 {#code_end#}2897 {#code_end#}
2897 {#header_close#}2898 {#header_close#}
...@@ -2922,9 +2923,9 @@ const Value = enum(u2) {...@@ -2922,9 +2923,9 @@ const Value = enum(u2) {
2922// Now you can cast between u2 and Value.2923// Now you can cast between u2 and Value.
2923// The ordinal value starts from 0, counting up for each member.2924// The ordinal value starts from 0, counting up for each member.
2924test "enum ordinal value" {2925test "enum ordinal value" {
2925 expect(@enumToInt(Value.zero) == 0);2926 try expect(@enumToInt(Value.zero) == 0);
2926 expect(@enumToInt(Value.one) == 1);2927 try expect(@enumToInt(Value.one) == 1);
2927 expect(@enumToInt(Value.two) == 2);2928 try expect(@enumToInt(Value.two) == 2);
2928}2929}
29292930
2930// You can override the ordinal value for an enum.2931// You can override the ordinal value for an enum.
...@@ -2934,9 +2935,9 @@ const Value2 = enum(u32) {...@@ -2934,9 +2935,9 @@ const Value2 = enum(u32) {
2934 million = 1000000,2935 million = 1000000,
2935};2936};
2936test "set enum ordinal value" {2937test "set enum ordinal value" {
2937 expect(@enumToInt(Value2.hundred) == 100);2938 try expect(@enumToInt(Value2.hundred) == 100);
2938 expect(@enumToInt(Value2.thousand) == 1000);2939 try expect(@enumToInt(Value2.thousand) == 1000);
2939 expect(@enumToInt(Value2.million) == 1000000);2940 try expect(@enumToInt(Value2.million) == 1000000);
2940}2941}
29412942
2942// Enums can have methods, the same as structs and unions.2943// Enums can have methods, the same as structs and unions.
...@@ -2954,7 +2955,7 @@ const Suit = enum {...@@ -2954,7 +2955,7 @@ const Suit = enum {
2954};2955};
2955test "enum method" {2956test "enum method" {
2956 const p = Suit.spades;2957 const p = Suit.spades;
2957 expect(!p.isClubs());2958 try expect(!p.isClubs());
2958}2959}
29592960
2960// An enum variant of different types can be switched upon.2961// An enum variant of different types can be switched upon.
...@@ -2970,7 +2971,7 @@ test "enum variant switch" {...@@ -2970,7 +2971,7 @@ test "enum variant switch" {
2970 Foo.number => "this is a number",2971 Foo.number => "this is a number",
2971 Foo.none => "this is a none",2972 Foo.none => "this is a none",
2972 };2973 };
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"));
2974}2975}
29752976
2976// @typeInfo can be used to access the integer tag type of an enum.2977// @typeInfo can be used to access the integer tag type of an enum.
...@@ -2981,18 +2982,18 @@ const Small = enum {...@@ -2981,18 +2982,18 @@ const Small = enum {
2981 four,2982 four,
2982};2983};
2983test "std.meta.Tag" {2984test "std.meta.Tag" {
2984 expect(@typeInfo(Small).Enum.tag_type == u2);2985 try expect(@typeInfo(Small).Enum.tag_type == u2);
2985}2986}
29862987
2987// @typeInfo tells us the field count and the fields names:2988// @typeInfo tells us the field count and the fields names:
2988test "@typeInfo" {2989test "@typeInfo" {
2989 expect(@typeInfo(Small).Enum.fields.len == 4);2990 try expect(@typeInfo(Small).Enum.fields.len == 4);
2990 expect(mem.eql(u8, @typeInfo(Small).Enum.fields[1].name, "two"));2991 try expect(mem.eql(u8, @typeInfo(Small).Enum.fields[1].name, "two"));
2991}2992}
29922993
2993// @tagName gives a []const u8 representation of an enum value:2994// @tagName gives a []const u8 representation of an enum value:
2994test "@tagName" {2995test "@tagName" {
2995 expect(mem.eql(u8, @tagName(Small.three), "three"));2996 try expect(mem.eql(u8, @tagName(Small.three), "three"));
2996}2997}
2997 {#code_end#}2998 {#code_end#}
2998 {#see_also|@typeInfo|@tagName|@sizeOf#}2999 {#see_also|@typeInfo|@tagName|@sizeOf#}
...@@ -3031,7 +3032,7 @@ const Color = enum {...@@ -3031,7 +3032,7 @@ const Color = enum {
3031test "enum literals" {3032test "enum literals" {
3032 const color1: Color = .auto;3033 const color1: Color = .auto;
3033 const color2 = Color.auto;3034 const color2 = Color.auto;
3034 expect(color1 == color2);3035 try expect(color1 == color2);
3035}3036}
30363037
3037test "switch using enum literals" {3038test "switch using enum literals" {
...@@ -3041,7 +3042,7 @@ test "switch using enum literals" {...@@ -3041,7 +3042,7 @@ test "switch using enum literals" {
3041 .on => true,3042 .on => true,
3042 .off => false,3043 .off => false,
3043 };3044 };
3044 expect(result);3045 try expect(result);
3045}3046}
3046 {#code_end#}3047 {#code_end#}
3047 {#header_close#}3048 {#header_close#}
...@@ -3077,12 +3078,12 @@ test "switch on non-exhaustive enum" {...@@ -3077,12 +3078,12 @@ test "switch on non-exhaustive enum" {
3077 .three => false,3078 .three => false,
3078 _ => false,3079 _ => false,
3079 };3080 };
3080 expect(result);3081 try expect(result);
3081 const is_one = switch (number) {3082 const is_one = switch (number) {
3082 .one => true,3083 .one => true,
3083 else => false,3084 else => false,
3084 };3085 };
3085 expect(is_one);3086 try expect(is_one);
3086}3087}
3087 {#code_end#}3088 {#code_end#}
3088 {#header_close#}3089 {#header_close#}
...@@ -3122,9 +3123,9 @@ const Payload = union {...@@ -3122,9 +3123,9 @@ const Payload = union {
3122};3123};
3123test "simple union" {3124test "simple union" {
3124 var payload = Payload{ .int = 1234 };3125 var payload = Payload{ .int = 1234 };
3125 expect(payload.int == 1234);3126 try expect(payload.int == 1234);
3126 payload = Payload{ .float = 12.34 };3127 payload = Payload{ .float = 12.34 };
3127 expect(payload.float == 12.34);3128 try expect(payload.float == 12.34);
3128}3129}
3129 {#code_end#}3130 {#code_end#}
3130 <p>3131 <p>
...@@ -3155,24 +3156,24 @@ const ComplexType = union(ComplexTypeTag) {...@@ -3155,24 +3156,24 @@ const ComplexType = union(ComplexTypeTag) {
31553156
3156test "switch on tagged union" {3157test "switch on tagged union" {
3157 const c = ComplexType{ .ok = 42 };3158 const c = ComplexType{ .ok = 42 };
3158 expect(@as(ComplexTypeTag, c) == ComplexTypeTag.ok);3159 try expect(@as(ComplexTypeTag, c) == ComplexTypeTag.ok);
31593160
3160 switch (c) {3161 switch (c) {
3161 ComplexTypeTag.ok => |value| expect(value == 42),3162 ComplexTypeTag.ok => |value| try expect(value == 42),
3162 ComplexTypeTag.not_ok => unreachable,3163 ComplexTypeTag.not_ok => unreachable,
3163 }3164 }
3164}3165}
31653166
3166test "get tag type" {3167test "get tag type" {
3167 expect(std.meta.Tag(ComplexType) == ComplexTypeTag);3168 try expect(std.meta.Tag(ComplexType) == ComplexTypeTag);
3168}3169}
31693170
3170test "coerce to enum" {3171test "coerce to enum" {
3171 const c1 = ComplexType{ .ok = 42 };3172 const c1 = ComplexType{ .ok = 42 };
3172 const c2 = ComplexType.not_ok;3173 const c2 = ComplexType.not_ok;
31733174
3174 expect(c1 == .ok);3175 try expect(c1 == .ok);
3175 expect(c2 == .not_ok);3176 try expect(c2 == .not_ok);
3176}3177}
3177 {#code_end#}3178 {#code_end#}
3178 <p>In order to modify the payload of a tagged union in a switch expression,3179 <p>In order to modify the payload of a tagged union in a switch expression,
...@@ -3193,14 +3194,14 @@ const ComplexType = union(ComplexTypeTag) {...@@ -3193,14 +3194,14 @@ const ComplexType = union(ComplexTypeTag) {
31933194
3194test "modify tagged union in switch" {3195test "modify tagged union in switch" {
3195 var c = ComplexType{ .ok = 42 };3196 var c = ComplexType{ .ok = 42 };
3196 expect(@as(ComplexTypeTag, c) == ComplexTypeTag.ok);3197 try expect(@as(ComplexTypeTag, c) == ComplexTypeTag.ok);
31973198
3198 switch (c) {3199 switch (c) {
3199 ComplexTypeTag.ok => |*value| value.* += 1,3200 ComplexTypeTag.ok => |*value| value.* += 1,
3200 ComplexTypeTag.not_ok => unreachable,3201 ComplexTypeTag.not_ok => unreachable,
3201 }3202 }
32023203
3203 expect(c.ok == 43);3204 try expect(c.ok == 43);
3204}3205}
3205 {#code_end#}3206 {#code_end#}
3206 <p>3207 <p>
...@@ -3231,8 +3232,8 @@ test "union method" {...@@ -3231,8 +3232,8 @@ test "union method" {
3231 var v1 = Variant{ .int = 1 };3232 var v1 = Variant{ .int = 1 };
3232 var v2 = Variant{ .boolean = false };3233 var v2 = Variant{ .boolean = false };
32333234
3234 expect(v1.truthy());3235 try expect(v1.truthy());
3235 expect(!v2.truthy());3236 try expect(!v2.truthy());
3236}3237}
3237 {#code_end#}3238 {#code_end#}
3238 <p>3239 <p>
...@@ -3249,7 +3250,7 @@ const Small2 = union(enum) {...@@ -3249,7 +3250,7 @@ const Small2 = union(enum) {
3249 c: u8,3250 c: u8,
3250};3251};
3251test "@tagName" {3252test "@tagName" {
3252 expect(std.mem.eql(u8, @tagName(Small2.a), "a"));3253 try expect(std.mem.eql(u8, @tagName(Small2.a), "a"));
3253}3254}
3254 {#code_end#}3255 {#code_end#}
3255 {#header_close#}3256 {#header_close#}
...@@ -3282,8 +3283,8 @@ const Number = union {...@@ -3282,8 +3283,8 @@ const Number = union {
3282test "anonymous union literal syntax" {3283test "anonymous union literal syntax" {
3283 var i: Number = .{.int = 42};3284 var i: Number = .{.int = 42};
3284 var f = makeNumber();3285 var f = makeNumber();
3285 expect(i.int == 42);3286 try expect(i.int == 42);
3286 expect(f.float == 12.34);3287 try expect(f.float == 12.34);
3287}3288}
32883289
3289fn makeNumber() Number {3290fn makeNumber() Number {
...@@ -3345,8 +3346,8 @@ test "labeled break from labeled block expression" {...@@ -3345,8 +3346,8 @@ test "labeled break from labeled block expression" {
3345 y += 1;3346 y += 1;
3346 break :blk y;3347 break :blk y;
3347 };3348 };
3348 expect(x == 124);3349 try expect(x == 124);
3349 expect(y == 124);3350 try expect(y == 124);
3350}3351}
3351 {#code_end#}3352 {#code_end#}
3352 <p>Here, {#syntax#}blk{#endsyntax#} can be any name.</p>3353 <p>Here, {#syntax#}blk{#endsyntax#} can be any name.</p>
...@@ -3424,7 +3425,7 @@ test "switch simple" {...@@ -3424,7 +3425,7 @@ test "switch simple" {
3424 else => 9,3425 else => 9,
3425 };3426 };
34263427
3427 expect(b == 1);3428 try expect(b == 1);
3428}3429}
34293430
3430// Switch expressions can be used outside a function:3431// Switch expressions can be used outside a function:
...@@ -3487,8 +3488,8 @@ test "switch on tagged union" {...@@ -3487,8 +3488,8 @@ test "switch on tagged union" {
3487 Item.d => 8,3488 Item.d => 8,
3488 };3489 };
34893490
3490 expect(b == 6);3491 try expect(b == 6);
3491 expect(a.c.x == 2);3492 try expect(a.c.x == 2);
3492}3493}
3493 {#code_end#}3494 {#code_end#}
3494 {#see_also|comptime|enum|@compileError|Compile Variables#}3495 {#see_also|comptime|enum|@compileError|Compile Variables#}
...@@ -3537,7 +3538,7 @@ test "enum literals with switch" {...@@ -3537,7 +3538,7 @@ test "enum literals with switch" {
3537 .on => false,3538 .on => false,
3538 .off => true,3539 .off => true,
3539 };3540 };
3540 expect(result);3541 try expect(result);
3541}3542}
3542 {#code_end#}3543 {#code_end#}
3543 {#header_close#}3544 {#header_close#}
...@@ -3556,7 +3557,7 @@ test "while basic" {...@@ -3556,7 +3557,7 @@ test "while basic" {
3556 while (i < 10) {3557 while (i < 10) {
3557 i += 1;3558 i += 1;
3558 }3559 }
3559 expect(i == 10);3560 try expect(i == 10);
3560}3561}
3561 {#code_end#}3562 {#code_end#}
3562 <p>3563 <p>
...@@ -3572,7 +3573,7 @@ test "while break" {...@@ -3572,7 +3573,7 @@ test "while break" {
3572 break;3573 break;
3573 i += 1;3574 i += 1;
3574 }3575 }
3575 expect(i == 10);3576 try expect(i == 10);
3576}3577}
3577 {#code_end#}3578 {#code_end#}
3578 <p>3579 <p>
...@@ -3589,7 +3590,7 @@ test "while continue" {...@@ -3589,7 +3590,7 @@ test "while continue" {
3589 continue;3590 continue;
3590 break;3591 break;
3591 }3592 }
3592 expect(i == 10);3593 try expect(i == 10);
3593}3594}
3594 {#code_end#}3595 {#code_end#}
3595 <p>3596 <p>
...@@ -3602,7 +3603,7 @@ const expect = @import("std").testing.expect;...@@ -3602,7 +3603,7 @@ const expect = @import("std").testing.expect;
3602test "while loop continue expression" {3603test "while loop continue expression" {
3603 var i: usize = 0;3604 var i: usize = 0;
3604 while (i < 10) : (i += 1) {}3605 while (i < 10) : (i += 1) {}
3605 expect(i == 10);3606 try expect(i == 10);
3606}3607}
36073608
3608test "while loop continue expression, more complicated" {3609test "while loop continue expression, more complicated" {
...@@ -3610,7 +3611,7 @@ test "while loop continue expression, more complicated" {...@@ -3610,7 +3611,7 @@ test "while loop continue expression, more complicated" {
3610 var j: usize = 1;3611 var j: usize = 1;
3611 while (i * j < 2000) : ({ i *= 2; j *= 3; }) {3612 while (i * j < 2000) : ({ i *= 2; j *= 3; }) {
3612 const my_ij = i * j;3613 const my_ij = i * j;
3613 expect(my_ij < 2000);3614 try expect(my_ij < 2000);
3614 }3615 }
3615}3616}
3616 {#code_end#}3617 {#code_end#}
...@@ -3629,8 +3630,8 @@ test "while loop continue expression, more complicated" {...@@ -3629,8 +3630,8 @@ test "while loop continue expression, more complicated" {
3629const expect = @import("std").testing.expect;3630const expect = @import("std").testing.expect;
36303631
3631test "while else" {3632test "while else" {
3632 expect(rangeHasNumber(0, 10, 5));3633 try expect(rangeHasNumber(0, 10, 5));
3633 expect(!rangeHasNumber(0, 10, 15));3634 try expect(!rangeHasNumber(0, 10, 15));
3634}3635}
36353636
3636fn rangeHasNumber(begin: usize, end: usize, number: usize) bool {3637fn rangeHasNumber(begin: usize, end: usize, number: usize) bool {
...@@ -3687,14 +3688,14 @@ test "while null capture" {...@@ -3687,14 +3688,14 @@ test "while null capture" {
3687 while (eventuallyNullSequence()) |value| {3688 while (eventuallyNullSequence()) |value| {
3688 sum1 += value;3689 sum1 += value;
3689 }3690 }
3690 expect(sum1 == 3);3691 try expect(sum1 == 3);
36913692
3692 var sum2: u32 = 0;3693 var sum2: u32 = 0;
3693 numbers_left = 3;3694 numbers_left = 3;
3694 while (eventuallyNullSequence()) |value| {3695 while (eventuallyNullSequence()) |value| {
3695 sum2 += value;3696 sum2 += value;
3696 } else {3697 } else {
3697 expect(sum2 == 3);3698 try expect(sum2 == 3);
3698 }3699 }
3699}3700}
37003701
...@@ -3729,7 +3730,7 @@ test "while error union capture" {...@@ -3729,7 +3730,7 @@ test "while error union capture" {
3729 while (eventuallyErrorSequence()) |value| {3730 while (eventuallyErrorSequence()) |value| {
3730 sum1 += value;3731 sum1 += value;
3731 } else |err| {3732 } else |err| {
3732 expect(err == error.ReachedZero);3733 try expect(err == error.ReachedZero);
3733 }3734 }
3734}3735}
37353736
...@@ -3765,7 +3766,7 @@ test "inline while loop" {...@@ -3765,7 +3766,7 @@ test "inline while loop" {
3765 };3766 };
3766 sum += typeNameLength(T);3767 sum += typeNameLength(T);
3767 }3768 }
3768 expect(sum == 9);3769 try expect(sum == 9);
3769}3770}
37703771
3771fn typeNameLength(comptime T: type) usize {3772fn typeNameLength(comptime T: type) usize {
...@@ -3800,22 +3801,22 @@ test "for basics" {...@@ -3800,22 +3801,22 @@ test "for basics" {
3800 }3801 }
3801 sum += value;3802 sum += value;
3802 }3803 }
3803 expect(sum == 16);3804 try expect(sum == 16);
38043805
3805 // To iterate over a portion of a slice, reslice.3806 // To iterate over a portion of a slice, reslice.
3806 for (items[0..1]) |value| {3807 for (items[0..1]) |value| {
3807 sum += value;3808 sum += value;
3808 }3809 }
3809 expect(sum == 20);3810 try expect(sum == 20);
38103811
3811 // To access the index of iteration, specify a second capture value.3812 // To access the index of iteration, specify a second capture value.
3812 // This is zero-indexed.3813 // This is zero-indexed.
3813 var sum2: i32 = 0;3814 var sum2: i32 = 0;
3814 for (items) |value, i| {3815 for (items) |value, i| {
3815 expect(@TypeOf(i) == usize);3816 try expect(@TypeOf(i) == usize);
3816 sum2 += @intCast(i32, i);3817 sum2 += @intCast(i32, i);
3817 }3818 }
3818 expect(sum2 == 10);3819 try expect(sum2 == 10);
3819}3820}
38203821
3821test "for reference" {3822test "for reference" {
...@@ -3827,9 +3828,9 @@ test "for reference" {...@@ -3827,9 +3828,9 @@ test "for reference" {
3827 value.* += 1;3828 value.* += 1;
3828 }3829 }
38293830
3830 expect(items[0] == 4);3831 try expect(items[0] == 4);
3831 expect(items[1] == 5);3832 try expect(items[1] == 5);
3832 expect(items[2] == 3);3833 try expect(items[2] == 3);
3833}3834}
38343835
3835test "for else" {3836test "for else" {
...@@ -3844,10 +3845,10 @@ test "for else" {...@@ -3844,10 +3845,10 @@ test "for else" {
3844 sum += value.?;3845 sum += value.?;
3845 }3846 }
3846 } else blk: {3847 } else blk: {
3847 expect(sum == 12);3848 try expect(sum == 12);
3848 break :blk sum;3849 break :blk sum;
3849 };3850 };
3850 expect(result == 12);3851 try expect(result == 12);
3851}3852}
3852 {#code_end#}3853 {#code_end#}
3853 {#header_open|Labeled for#}3854 {#header_open|Labeled for#}
...@@ -3865,7 +3866,7 @@ test "nested break" {...@@ -3865,7 +3866,7 @@ test "nested break" {
3865 break :outer;3866 break :outer;
3866 }3867 }
3867 }3868 }
3868 expect(count == 1);3869 try expect(count == 1);
3869}3870}
38703871
3871test "nested continue" {3872test "nested continue" {
...@@ -3877,7 +3878,7 @@ test "nested continue" {...@@ -3877,7 +3878,7 @@ test "nested continue" {
3877 }3878 }
3878 }3879 }
38793880
3880 expect(count == 8);3881 try expect(count == 8);
3881}3882}
3882 {#code_end#}3883 {#code_end#}
3883 {#header_close#}3884 {#header_close#}
...@@ -3904,7 +3905,7 @@ test "inline for loop" {...@@ -3904,7 +3905,7 @@ test "inline for loop" {
3904 };3905 };
3905 sum += typeNameLength(T);3906 sum += typeNameLength(T);
3906 }3907 }
3907 expect(sum == 9);3908 try expect(sum == 9);
3908}3909}
39093910
3910fn typeNameLength(comptime T: type) usize {3911fn typeNameLength(comptime T: type) usize {
...@@ -3937,7 +3938,7 @@ test "if expression" {...@@ -3937,7 +3938,7 @@ test "if expression" {
3937 const a: u32 = 5;3938 const a: u32 = 5;
3938 const b: u32 = 4;3939 const b: u32 = 4;
3939 const result = if (a != b) 47 else 3089;3940 const result = if (a != b) 47 else 3089;
3940 expect(result == 47);3941 try expect(result == 47);
3941}3942}
39423943
3943test "if boolean" {3944test "if boolean" {
...@@ -3945,7 +3946,7 @@ test "if boolean" {...@@ -3945,7 +3946,7 @@ test "if boolean" {
3945 const a: u32 = 5;3946 const a: u32 = 5;
3946 const b: u32 = 4;3947 const b: u32 = 4;
3947 if (a != b) {3948 if (a != b) {
3948 expect(true);3949 try expect(true);
3949 } else if (a == 9) {3950 } else if (a == 9) {
3950 unreachable;3951 unreachable;
3951 } else {3952 } else {
...@@ -3958,7 +3959,7 @@ test "if optional" {...@@ -3958,7 +3959,7 @@ test "if optional" {
39583959
3959 const a: ?u32 = 0;3960 const a: ?u32 = 0;
3960 if (a) |value| {3961 if (a) |value| {
3961 expect(value == 0);3962 try expect(value == 0);
3962 } else {3963 } else {
3963 unreachable;3964 unreachable;
3964 }3965 }
...@@ -3967,17 +3968,17 @@ test "if optional" {...@@ -3967,17 +3968,17 @@ test "if optional" {
3967 if (b) |value| {3968 if (b) |value| {
3968 unreachable;3969 unreachable;
3969 } else {3970 } else {
3970 expect(true);3971 try expect(true);
3971 }3972 }
39723973
3973 // The else is not required.3974 // The else is not required.
3974 if (a) |value| {3975 if (a) |value| {
3975 expect(value == 0);3976 try expect(value == 0);
3976 }3977 }
39773978
3978 // To test against null only, use the binary equality operator.3979 // To test against null only, use the binary equality operator.
3979 if (b == null) {3980 if (b == null) {
3980 expect(true);3981 try expect(true);
3981 }3982 }
39823983
3983 // Access the value by reference using a pointer capture.3984 // Access the value by reference using a pointer capture.
...@@ -3987,7 +3988,7 @@ test "if optional" {...@@ -3987,7 +3988,7 @@ test "if optional" {
3987 }3988 }
39883989
3989 if (c) |value| {3990 if (c) |value| {
3990 expect(value == 2);3991 try expect(value == 2);
3991 } else {3992 } else {
3992 unreachable;3993 unreachable;
3993 }3994 }
...@@ -3999,7 +4000,7 @@ test "if error union" {...@@ -3999,7 +4000,7 @@ test "if error union" {
39994000
4000 const a: anyerror!u32 = 0;4001 const a: anyerror!u32 = 0;
4001 if (a) |value| {4002 if (a) |value| {
4002 expect(value == 0);4003 try expect(value == 0);
4003 } else |err| {4004 } else |err| {
4004 unreachable;4005 unreachable;
4005 }4006 }
...@@ -4008,17 +4009,17 @@ test "if error union" {...@@ -4008,17 +4009,17 @@ test "if error union" {
4008 if (b) |value| {4009 if (b) |value| {
4009 unreachable;4010 unreachable;
4010 } else |err| {4011 } else |err| {
4011 expect(err == error.BadValue);4012 try expect(err == error.BadValue);
4012 }4013 }
40134014
4014 // The else and |err| capture is strictly required.4015 // The else and |err| capture is strictly required.
4015 if (a) |value| {4016 if (a) |value| {
4016 expect(value == 0);4017 try expect(value == 0);
4017 } else |_| {}4018 } else |_| {}
40184019
4019 // To check only the error value, use an empty block expression.4020 // To check only the error value, use an empty block expression.
4020 if (b) |_| {} else |err| {4021 if (b) |_| {} else |err| {
4021 expect(err == error.BadValue);4022 try expect(err == error.BadValue);
4022 }4023 }
40234024
4024 // Access the value by reference using a pointer capture.4025 // Access the value by reference using a pointer capture.
...@@ -4030,7 +4031,7 @@ test "if error union" {...@@ -4030,7 +4031,7 @@ test "if error union" {
4030 }4031 }
40314032
4032 if (c) |value| {4033 if (c) |value| {
4033 expect(value == 9);4034 try expect(value == 9);
4034 } else |err| {4035 } else |err| {
4035 unreachable;4036 unreachable;
4036 }4037 }
...@@ -4042,14 +4043,14 @@ test "if error union with optional" {...@@ -4042,14 +4043,14 @@ test "if error union with optional" {
40424043
4043 const a: anyerror!?u32 = 0;4044 const a: anyerror!?u32 = 0;
4044 if (a) |optional_value| {4045 if (a) |optional_value| {
4045 expect(optional_value.? == 0);4046 try expect(optional_value.? == 0);
4046 } else |err| {4047 } else |err| {
4047 unreachable;4048 unreachable;
4048 }4049 }
40494050
4050 const b: anyerror!?u32 = null;4051 const b: anyerror!?u32 = null;
4051 if (b) |optional_value| {4052 if (b) |optional_value| {
4052 expect(optional_value == null);4053 try expect(optional_value == null);
4053 } else |err| {4054 } else |err| {
4054 unreachable;4055 unreachable;
4055 }4056 }
...@@ -4058,7 +4059,7 @@ test "if error union with optional" {...@@ -4058,7 +4059,7 @@ test "if error union with optional" {
4058 if (c) |optional_value| {4059 if (c) |optional_value| {
4059 unreachable;4060 unreachable;
4060 } else |err| {4061 } else |err| {
4061 expect(err == error.BadValue);4062 try expect(err == error.BadValue);
4062 }4063 }
40634064
4064 // Access the value by reference by using a pointer capture each time.4065 // Access the value by reference by using a pointer capture each time.
...@@ -4072,7 +4073,7 @@ test "if error union with optional" {...@@ -4072,7 +4073,7 @@ test "if error union with optional" {
4072 }4073 }
40734074
4074 if (d) |optional_value| {4075 if (d) |optional_value| {
4075 expect(optional_value.? == 9);4076 try expect(optional_value.? == 9);
4076 } else |err| {4077 } else |err| {
4077 unreachable;4078 unreachable;
4078 }4079 }
...@@ -4087,21 +4088,21 @@ const expect = std.testing.expect;...@@ -4087,21 +4088,21 @@ const expect = std.testing.expect;
4087const print = std.debug.print;4088const print = std.debug.print;
40884089
4089// defer will execute an expression at the end of the current scope.4090// defer will execute an expression at the end of the current scope.
4090fn deferExample() usize {4091fn deferExample() !usize {
4091 var a: usize = 1;4092 var a: usize = 1;
40924093
4093 {4094 {
4094 defer a = 2;4095 defer a = 2;
4095 a = 1;4096 a = 1;
4096 }4097 }
4097 expect(a == 2);4098 try expect(a == 2);
40984099
4099 a = 5;4100 a = 5;
4100 return a;4101 return a;
4101}4102}
41024103
4103test "defer basics" {4104test "defer basics" {
4104 expect(deferExample() == 5);4105 try expect((try deferExample()) == 5);
4105}4106}
41064107
4107// If multiple defer statements are specified, they will be executed in4108// 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...@@ -4239,7 +4240,7 @@ pub extern "kernel32" fn ExitProcess(exit_code: c_uint) callconv(if (@import("bu
42394240
4240test "foo" {4241test "foo" {
4241 const value = bar() catch ExitProcess(1);4242 const value = bar() catch ExitProcess(1);
4242 expect(value == 1234);4243 try expect(value == 1234);
4243}4244}
42444245
4245fn bar() anyerror!u32 {4246fn bar() anyerror!u32 {
...@@ -4302,17 +4303,17 @@ fn do_op(fn_call: call2_op, op1: i8, op2: i8) i8 {...@@ -4302,17 +4303,17 @@ fn do_op(fn_call: call2_op, op1: i8, op2: i8) i8 {
4302}4303}
43034304
4304test "function" {4305test "function" {
4305 expect(do_op(add, 5, 6) == 11);4306 try expect(do_op(add, 5, 6) == 11);
4306 expect(do_op(sub2, 5, 6) == -1);4307 try expect(do_op(sub2, 5, 6) == -1);
4307}4308}
4308 {#code_end#}4309 {#code_end#}
4309 <p>Function values are like pointers:</p>4310 <p>Function values are like pointers:</p>
4310 {#code_begin|obj#}4311 {#code_begin|obj#}
4311const expect = @import("std").testing.expect;4312const assert = @import("std").debug.assert;
43124313
4313comptime {4314comptime {
4314 expect(@TypeOf(foo) == fn()void);4315 assert(@TypeOf(foo) == fn()void);
4315 expect(@sizeOf(fn()void) == @sizeOf(?fn()void));4316 assert(@sizeOf(fn()void) == @sizeOf(?fn()void));
4316}4317}
43174318
4318fn foo() void { }4319fn foo() void { }
...@@ -4347,7 +4348,7 @@ fn foo(point: Point) i32 {...@@ -4347,7 +4348,7 @@ fn foo(point: Point) i32 {
4347const expect = @import("std").testing.expect;4348const expect = @import("std").testing.expect;
43484349
4349test "pass struct to function" {4350test "pass struct to function" {
4350 expect(foo(Point{ .x = 1, .y = 2 }) == 3);4351 try expect(foo(Point{ .x = 1, .y = 2 }) == 3);
4351}4352}
4352 {#code_end#}4353 {#code_end#}
4353 <p>4354 <p>
...@@ -4368,11 +4369,11 @@ fn addFortyTwo(x: anytype) @TypeOf(x) {...@@ -4368,11 +4369,11 @@ fn addFortyTwo(x: anytype) @TypeOf(x) {
4368}4369}
43694370
4370test "fn type inference" {4371test "fn type inference" {
4371 expect(addFortyTwo(1) == 43);4372 try expect(addFortyTwo(1) == 43);
4372 expect(@TypeOf(addFortyTwo(1)) == comptime_int);4373 try expect(@TypeOf(addFortyTwo(1)) == comptime_int);
4373 var y: i64 = 2;4374 var y: i64 = 2;
4374 expect(addFortyTwo(y) == 44);4375 try expect(addFortyTwo(y) == 44);
4375 expect(@TypeOf(addFortyTwo(y)) == i64);4376 try expect(@TypeOf(addFortyTwo(y)) == i64);
4376}4377}
4377 {#code_end#}4378 {#code_end#}
43784379
...@@ -4382,8 +4383,8 @@ test "fn type inference" {...@@ -4382,8 +4383,8 @@ test "fn type inference" {
4382const expect = @import("std").testing.expect;4383const expect = @import("std").testing.expect;
43834384
4384test "fn reflection" {4385test "fn reflection" {
4385 expect(@typeInfo(@TypeOf(expect)).Fn.return_type.? == void);4386 try expect(@typeInfo(@TypeOf(expect)).Fn.args[0].arg_type.? == bool);
4386 expect(@typeInfo(@TypeOf(expect)).Fn.is_var_args == false);4387 try expect(@typeInfo(@TypeOf(expect)).Fn.is_var_args == false);
4387}4388}
4388 {#code_end#}4389 {#code_end#}
4389 {#header_close#}4390 {#header_close#}
...@@ -4418,7 +4419,7 @@ const AllocationError = error {...@@ -4418,7 +4419,7 @@ const AllocationError = error {
44184419
4419test "coerce subset to superset" {4420test "coerce subset to superset" {
4420 const err = foo(AllocationError.OutOfMemory);4421 const err = foo(AllocationError.OutOfMemory);
4421 std.testing.expect(err == FileOpenError.OutOfMemory);4422 try std.testing.expect(err == FileOpenError.OutOfMemory);
4422}4423}
44234424
4424fn foo(err: AllocationError) FileOpenError {4425fn foo(err: AllocationError) FileOpenError {
...@@ -4526,7 +4527,7 @@ fn charToDigit(c: u8) u8 {...@@ -4526,7 +4527,7 @@ fn charToDigit(c: u8) u8 {
45264527
4527test "parse u64" {4528test "parse u64" {
4528 const result = try parseU64("1234", 10);4529 const result = try parseU64("1234", 10);
4529 std.testing.expect(result == 1234);4530 try std.testing.expect(result == 1234);
4530}4531}
4531 {#code_end#}4532 {#code_end#}
4532 <p>4533 <p>
...@@ -4683,10 +4684,10 @@ test "error union" {...@@ -4683,10 +4684,10 @@ test "error union" {
4683 foo = error.SomeError;4684 foo = error.SomeError;
46844685
4685 // Use compile-time reflection to access the payload type of an error union:4686 // 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
4688 // Use compile-time reflection to access the error set type of an error union:4689 // 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);
4690}4691}
4691 {#code_end#}4692 {#code_end#}
4692 {#header_open|Merging Error Sets#}4693 {#header_open|Merging Error Sets#}
...@@ -5063,7 +5064,7 @@ test "optional type" {...@@ -5063,7 +5064,7 @@ test "optional type" {
5063 foo = 1234;5064 foo = 1234;
50645065
5065 // Use compile-time reflection to access the child type of the optional:5066 // 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);
5067}5068}
5068 {#code_end#}5069 {#code_end#}
5069 {#header_close#}5070 {#header_close#}
...@@ -5090,11 +5091,11 @@ test "optional pointers" {...@@ -5090,11 +5091,11 @@ test "optional pointers" {
5090 var x: i32 = 1;5091 var x: i32 = 1;
5091 ptr = &x;5092 ptr = &x;
50925093
5093 expect(ptr.?.* == 1);5094 try expect(ptr.?.* == 1);
50945095
5095 // Optional pointers are the same size as normal pointers, because pointer5096 // Optional pointers are the same size as normal pointers, because pointer
5096 // value 0 is used as the null value.5097 // value 0 is used as the null value.
5097 expect(@sizeOf(?*i32) == @sizeOf(*i32));5098 try expect(@sizeOf(?*i32) == @sizeOf(*i32));
5098}5099}
5099 {#code_end#}5100 {#code_end#}
5100 {#header_close#}5101 {#header_close#}
...@@ -5167,7 +5168,7 @@ const mem = std.mem;...@@ -5167,7 +5168,7 @@ const mem = std.mem;
5167test "cast *[1][*]const u8 to [*]const ?[*]const u8" {5168test "cast *[1][*]const u8 to [*]const ?[*]const u8" {
5168 const window_name = [1][*]const u8{"window name"};5169 const window_name = [1][*]const u8{"window name"};
5169 const x: [*]const ?[*]const u8 = &window_name;5170 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"));
5171}5172}
5172 {#code_end#}5173 {#code_end#}
5173 {#header_close#}5174 {#header_close#}
...@@ -5188,13 +5189,13 @@ test "integer widening" {...@@ -5188,13 +5189,13 @@ test "integer widening" {
5188 var d: u64 = c;5189 var d: u64 = c;
5189 var e: u64 = d;5190 var e: u64 = d;
5190 var f: u128 = e;5191 var f: u128 = e;
5191 expect(f == a);5192 try expect(f == a);
5192}5193}
51935194
5194test "implicit unsigned integer to signed integer" {5195test "implicit unsigned integer to signed integer" {
5195 var a: u8 = 250;5196 var a: u8 = 250;
5196 var b: i16 = a;5197 var b: i16 = a;
5197 expect(b == 250);5198 try expect(b == 250);
5198}5199}
51995200
5200test "float widening" {5201test "float widening" {
...@@ -5206,7 +5207,7 @@ test "float widening" {...@@ -5206,7 +5207,7 @@ test "float widening" {
5206 var b: f32 = a;5207 var b: f32 = a;
5207 var c: f64 = b;5208 var c: f64 = b;
5208 var d: f128 = c;5209 var d: f128 = c;
5209 expect(d == a);5210 try expect(d == a);
5210}5211}
5211 {#code_end#}5212 {#code_end#}
5212 {#header_close#}5213 {#header_close#}
...@@ -5238,48 +5239,48 @@ const expect = std.testing.expect;...@@ -5238,48 +5239,48 @@ const expect = std.testing.expect;
5238test "[N]T to []const T" {5239test "[N]T to []const T" {
5239 var x1: []const u8 = "hello";5240 var x1: []const u8 = "hello";
5240 var x2: []const u8 = &[5]u8{ 'h', 'e', 'l', 'l', 111 };5241 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
5243 var y: []const f32 = &[2]f32{ 1.2, 3.4 };5244 var y: []const f32 = &[2]f32{ 1.2, 3.4 };
5244 expect(y[0] == 1.2);5245 try expect(y[0] == 1.2);
5245}5246}
52465247
5247// Likewise, it works when the destination type is an error union.5248// Likewise, it works when the destination type is an error union.
5248test "[N]T to E![]const T" {5249test "[N]T to E![]const T" {
5249 var x1: anyerror![]const u8 = "hello";5250 var x1: anyerror![]const u8 = "hello";
5250 var x2: anyerror![]const u8 = &[5]u8{ 'h', 'e', 'l', 'l', 111 };5251 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
5253 var y: anyerror![]const f32 = &[2]f32{ 1.2, 3.4 };5254 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);
5255}5256}
52565257
5257// Likewise, it works when the destination type is an optional.5258// Likewise, it works when the destination type is an optional.
5258test "[N]T to ?[]const T" {5259test "[N]T to ?[]const T" {
5259 var x1: ?[]const u8 = "hello";5260 var x1: ?[]const u8 = "hello";
5260 var x2: ?[]const u8 = &[5]u8{ 'h', 'e', 'l', 'l', 111 };5261 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
5263 var y: ?[]const f32 = &[2]f32{ 1.2, 3.4 };5264 var y: ?[]const f32 = &[2]f32{ 1.2, 3.4 };
5264 expect(y.?[0] == 1.2);5265 try expect(y.?[0] == 1.2);
5265}5266}
52665267
5267// In this cast, the array length becomes the slice length.5268// In this cast, the array length becomes the slice length.
5268test "*[N]T to []T" {5269test "*[N]T to []T" {
5269 var buf: [5]u8 = "hello".*;5270 var buf: [5]u8 = "hello".*;
5270 const x: []u8 = &buf;5271 const x: []u8 = &buf;
5271 expect(std.mem.eql(u8, x, "hello"));5272 try expect(std.mem.eql(u8, x, "hello"));
52725273
5273 const buf2 = [2]f32{ 1.2, 3.4 };5274 const buf2 = [2]f32{ 1.2, 3.4 };
5274 const x2: []const f32 = &buf2;5275 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 }));
5276}5277}
52775278
5278// Single-item pointers to arrays can be coerced to many-item pointers.5279// Single-item pointers to arrays can be coerced to many-item pointers.
5279test "*[N]T to [*]T" {5280test "*[N]T to [*]T" {
5280 var buf: [5]u8 = "hello".*;5281 var buf: [5]u8 = "hello".*;
5281 const x: [*]u8 = &buf;5282 const x: [*]u8 = &buf;
5282 expect(x[4] == 'o');5283 try expect(x[4] == 'o');
5283 // x[5] would be an uncaught out of bounds pointer dereference!5284 // x[5] would be an uncaught out of bounds pointer dereference!
5284}5285}
52855286
...@@ -5287,7 +5288,7 @@ test "*[N]T to [*]T" {...@@ -5287,7 +5288,7 @@ test "*[N]T to [*]T" {
5287test "*[N]T to ?[*]T" {5288test "*[N]T to ?[*]T" {
5288 var buf: [5]u8 = "hello".*;5289 var buf: [5]u8 = "hello".*;
5289 const x: ?[*]u8 = &buf;5290 const x: ?[*]u8 = &buf;
5290 expect(x.?[4] == 'o');5291 try expect(x.?[4] == 'o');
5291}5292}
52925293
5293// Single-item pointers can be cast to len-1 single-item arrays.5294// Single-item pointers can be cast to len-1 single-item arrays.
...@@ -5295,7 +5296,7 @@ test "*T to *[1]T" {...@@ -5295,7 +5296,7 @@ test "*T to *[1]T" {
5295 var x: i32 = 1234;5296 var x: i32 = 1234;
5296 const y: *[1]i32 = &x;5297 const y: *[1]i32 = &x;
5297 const z: [*]i32 = y;5298 const z: [*]i32 = y;
5298 expect(z[0] == 1234);5299 try expect(z[0] == 1234);
5299}5300}
5300 {#code_end#}5301 {#code_end#}
5301 {#see_also|C Pointers#}5302 {#see_also|C Pointers#}
...@@ -5312,8 +5313,8 @@ test "coerce to optionals" {...@@ -5312,8 +5313,8 @@ test "coerce to optionals" {
5312 const x: ?i32 = 1234;5313 const x: ?i32 = 1234;
5313 const y: ?i32 = null;5314 const y: ?i32 = null;
53145315
5315 expect(x.? == 1234);5316 try expect(x.? == 1234);
5316 expect(y == null);5317 try expect(y == null);
5317}5318}
5318 {#code_end#}5319 {#code_end#}
5319 <p>It works nested inside the {#link|Error Union Type#}, too:</p>5320 <p>It works nested inside the {#link|Error Union Type#}, too:</p>
...@@ -5325,8 +5326,8 @@ test "coerce to optionals wrapped in error union" {...@@ -5325,8 +5326,8 @@ test "coerce to optionals wrapped in error union" {
5325 const x: anyerror!?i32 = 1234;5326 const x: anyerror!?i32 = 1234;
5326 const y: anyerror!?i32 = null;5327 const y: anyerror!?i32 = null;
53275328
5328 expect((try x).? == 1234);5329 try expect((try x).? == 1234);
5329 expect((try y) == null);5330 try expect((try y) == null);
5330}5331}
5331 {#code_end#}5332 {#code_end#}
5332 {#header_close#}5333 {#header_close#}
...@@ -5342,8 +5343,8 @@ test "coercion to error unions" {...@@ -5342,8 +5343,8 @@ test "coercion to error unions" {
5342 const x: anyerror!i32 = 1234;5343 const x: anyerror!i32 = 1234;
5343 const y: anyerror!i32 = error.Failure;5344 const y: anyerror!i32 = error.Failure;
53445345
5345 expect((try x) == 1234);5346 try expect((try x) == 1234);
5346 std.testing.expectError(error.Failure, y);5347 try std.testing.expectError(error.Failure, y);
5347}5348}
5348 {#code_end#}5349 {#code_end#}
5349 {#header_close#}5350 {#header_close#}
...@@ -5358,7 +5359,7 @@ const expect = std.testing.expect;...@@ -5358,7 +5359,7 @@ const expect = std.testing.expect;
5358test "coercing large integer type to smaller one when value is comptime known to fit" {5359test "coercing large integer type to smaller one when value is comptime known to fit" {
5359 const x: u64 = 255;5360 const x: u64 = 255;
5360 const y: u8 = x;5361 const y: u8 = x;
5361 expect(y == 255);5362 try expect(y == 255);
5362}5363}
5363 {#code_end#}5364 {#code_end#}
5364 {#header_close#}5365 {#header_close#}
...@@ -5386,11 +5387,11 @@ const U = union(E) {...@@ -5386,11 +5387,11 @@ const U = union(E) {
5386test "coercion between unions and enums" {5387test "coercion between unions and enums" {
5387 var u = U{ .two = 12.34 };5388 var u = U{ .two = 12.34 };
5388 var e: E = u;5389 var e: E = u;
5389 expect(e == E.two);5390 try expect(e == E.two);
53905391
5391 const three = E.three;5392 const three = E.three;
5392 var another_u: U = three;5393 var another_u: U = three;
5393 expect(another_u == E.three);5394 try expect(another_u == E.three);
5394}5395}
5395 {#code_end#}5396 {#code_end#}
5396 {#see_also|union|enum#}5397 {#see_also|union|enum#}
...@@ -5463,37 +5464,37 @@ test "peer resolve int widening" {...@@ -5463,37 +5464,37 @@ test "peer resolve int widening" {
5463 var a: i8 = 12;5464 var a: i8 = 12;
5464 var b: i16 = 34;5465 var b: i16 = 34;
5465 var c = a + b;5466 var c = a + b;
5466 expect(c == 46);5467 try expect(c == 46);
5467 expect(@TypeOf(c) == i16);5468 try expect(@TypeOf(c) == i16);
5468}5469}
54695470
5470test "peer resolve arrays of different size to const slice" {5471test "peer resolve arrays of different size to const slice" {
5471 expect(mem.eql(u8, boolToStr(true), "true"));5472 try expect(mem.eql(u8, boolToStr(true), "true"));
5472 expect(mem.eql(u8, boolToStr(false), "false"));5473 try expect(mem.eql(u8, boolToStr(false), "false"));
5473 comptime expect(mem.eql(u8, boolToStr(true), "true"));5474 comptime try expect(mem.eql(u8, boolToStr(true), "true"));
5474 comptime expect(mem.eql(u8, boolToStr(false), "false"));5475 comptime try expect(mem.eql(u8, boolToStr(false), "false"));
5475}5476}
5476fn boolToStr(b: bool) []const u8 {5477fn boolToStr(b: bool) []const u8 {
5477 return if (b) "true" else "false";5478 return if (b) "true" else "false";
5478}5479}
54795480
5480test "peer resolve array and const slice" {5481test "peer resolve array and const slice" {
5481 testPeerResolveArrayConstSlice(true);5482 try testPeerResolveArrayConstSlice(true);
5482 comptime testPeerResolveArrayConstSlice(true);5483 comptime try testPeerResolveArrayConstSlice(true);
5483}5484}
5484fn testPeerResolveArrayConstSlice(b: bool) void {5485fn testPeerResolveArrayConstSlice(b: bool) !void {
5485 const value1 = if (b) "aoeu" else @as([]const u8, "zz");5486 const value1 = if (b) "aoeu" else @as([]const u8, "zz");
5486 const value2 = if (b) @as([]const u8, "zz") else "aoeu";5487 const value2 = if (b) @as([]const u8, "zz") else "aoeu";
5487 expect(mem.eql(u8, value1, "aoeu"));5488 try expect(mem.eql(u8, value1, "aoeu"));
5488 expect(mem.eql(u8, value2, "zz"));5489 try expect(mem.eql(u8, value2, "zz"));
5489}5490}
54905491
5491test "peer type resolution: ?T and T" {5492test "peer type resolution: ?T and T" {
5492 expect(peerTypeTAndOptionalT(true, false).? == 0);5493 try expect(peerTypeTAndOptionalT(true, false).? == 0);
5493 expect(peerTypeTAndOptionalT(false, false).? == 3);5494 try expect(peerTypeTAndOptionalT(false, false).? == 3);
5494 comptime {5495 comptime {
5495 expect(peerTypeTAndOptionalT(true, false).? == 0);5496 try expect(peerTypeTAndOptionalT(true, false).? == 0);
5496 expect(peerTypeTAndOptionalT(false, false).? == 3);5497 try expect(peerTypeTAndOptionalT(false, false).? == 3);
5497 }5498 }
5498}5499}
5499fn peerTypeTAndOptionalT(c: bool, b: bool) ?usize {5500fn peerTypeTAndOptionalT(c: bool, b: bool) ?usize {
...@@ -5505,11 +5506,11 @@ fn peerTypeTAndOptionalT(c: bool, b: bool) ?usize {...@@ -5505,11 +5506,11 @@ fn peerTypeTAndOptionalT(c: bool, b: bool) ?usize {
5505}5506}
55065507
5507test "peer type resolution: *[0]u8 and []const u8" {5508test "peer type resolution: *[0]u8 and []const u8" {
5508 expect(peerTypeEmptyArrayAndSlice(true, "hi").len == 0);5509 try expect(peerTypeEmptyArrayAndSlice(true, "hi").len == 0);
5509 expect(peerTypeEmptyArrayAndSlice(false, "hi").len == 1);5510 try expect(peerTypeEmptyArrayAndSlice(false, "hi").len == 1);
5510 comptime {5511 comptime {
5511 expect(peerTypeEmptyArrayAndSlice(true, "hi").len == 0);5512 try expect(peerTypeEmptyArrayAndSlice(true, "hi").len == 0);
5512 expect(peerTypeEmptyArrayAndSlice(false, "hi").len == 1);5513 try expect(peerTypeEmptyArrayAndSlice(false, "hi").len == 1);
5513 }5514 }
5514}5515}
5515fn peerTypeEmptyArrayAndSlice(a: bool, slice: []const u8) []const u8 {5516fn peerTypeEmptyArrayAndSlice(a: bool, slice: []const u8) []const u8 {
...@@ -5523,14 +5524,14 @@ test "peer type resolution: *[0]u8, []const u8, and anyerror![]u8" {...@@ -5523,14 +5524,14 @@ test "peer type resolution: *[0]u8, []const u8, and anyerror![]u8" {
5523 {5524 {
5524 var data = "hi".*;5525 var data = "hi".*;
5525 const slice = data[0..];5526 const slice = data[0..];
5526 expect((try peerTypeEmptyArrayAndSliceAndError(true, slice)).len == 0);5527 try expect((try peerTypeEmptyArrayAndSliceAndError(true, slice)).len == 0);
5527 expect((try peerTypeEmptyArrayAndSliceAndError(false, slice)).len == 1);5528 try expect((try peerTypeEmptyArrayAndSliceAndError(false, slice)).len == 1);
5528 }5529 }
5529 comptime {5530 comptime {
5530 var data = "hi".*;5531 var data = "hi".*;
5531 const slice = data[0..];5532 const slice = data[0..];
5532 expect((try peerTypeEmptyArrayAndSliceAndError(true, slice)).len == 0);5533 try expect((try peerTypeEmptyArrayAndSliceAndError(true, slice)).len == 0);
5533 expect((try peerTypeEmptyArrayAndSliceAndError(false, slice)).len == 1);5534 try expect((try peerTypeEmptyArrayAndSliceAndError(false, slice)).len == 1);
5534 }5535 }
5535}5536}
5536fn peerTypeEmptyArrayAndSliceAndError(a: bool, slice: []u8) anyerror![]u8 {5537fn peerTypeEmptyArrayAndSliceAndError(a: bool, slice: []u8) anyerror![]u8 {
...@@ -5544,8 +5545,8 @@ fn peerTypeEmptyArrayAndSliceAndError(a: bool, slice: []u8) anyerror![]u8 {...@@ -5544,8 +5545,8 @@ fn peerTypeEmptyArrayAndSliceAndError(a: bool, slice: []u8) anyerror![]u8 {
5544test "peer type resolution: *const T and ?*T" {5545test "peer type resolution: *const T and ?*T" {
5545 const a = @intToPtr(*const usize, 0x123456780);5546 const a = @intToPtr(*const usize, 0x123456780);
5546 const b = @intToPtr(?*usize, 0x123456780);5547 const b = @intToPtr(?*usize, 0x123456780);
5547 expect(a == b);5548 try expect(a == b);
5548 expect(b == a);5549 try expect(b == a);
5549}5550}
5550 {#code_end#}5551 {#code_end#}
5551 {#header_close#}5552 {#header_close#}
...@@ -5601,11 +5602,11 @@ test "turn HashMap into a set with void" {...@@ -5601,11 +5602,11 @@ test "turn HashMap into a set with void" {
5601 try map.put(1, {});5602 try map.put(1, {});
5602 try map.put(2, {});5603 try map.put(2, {});
56035604
5604 expect(map.contains(2));5605 try expect(map.contains(2));
5605 expect(!map.contains(3));5606 try expect(!map.contains(3));
56065607
5607 _ = map.remove(2);5608 _ = map.remove(2);
5608 expect(!map.contains(2));5609 try expect(!map.contains(2));
5609}5610}
5610 {#code_end#}5611 {#code_end#}
5611 <p>Note that this is different from using a dummy value for the hash map value.5612 <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" {...@@ -5660,7 +5661,7 @@ test "pointer to empty struct" {
5660 var b = Empty{};5661 var b = Empty{};
5661 var ptr_a = &a;5662 var ptr_a = &a;
5662 var ptr_b = &b;5663 var ptr_b = &b;
5663 comptime expect(ptr_a == ptr_b);5664 comptime try expect(ptr_a == ptr_b);
5664}5665}
5665 {#code_end#}5666 {#code_end#}
5666 <p>The type being pointed to can only ever be one value; therefore loads and stores are5667 <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" {...@@ -5695,7 +5696,7 @@ test "@intToPtr for pointer to zero bit type" {
5695usingnamespace @import("std");5696usingnamespace @import("std");
56965697
5697test "using std namespace" {5698test "using std namespace" {
5698 testing.expect(true);5699 try testing.expect(true);
5699}5700}
5700 {#code_end#}5701 {#code_end#}
5701 <p>5702 <p>
...@@ -5807,7 +5808,7 @@ fn max(comptime T: type, a: T, b: T) T {...@@ -5807,7 +5808,7 @@ fn max(comptime T: type, a: T, b: T) T {
5807 }5808 }
5808}5809}
5809test "try to compare bools" {5810test "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);
5811}5812}
5812 {#code_end#}5813 {#code_end#}
5813 <p>5814 <p>
...@@ -5875,9 +5876,9 @@ fn performFn(comptime prefix_char: u8, start_value: i32) i32 {...@@ -5875,9 +5876,9 @@ fn performFn(comptime prefix_char: u8, start_value: i32) i32 {
5875}5876}
58765877
5877test "perform fn" {5878test "perform fn" {
5878 expect(performFn('t', 1) == 6);5879 try expect(performFn('t', 1) == 6);
5879 expect(performFn('o', 0) == 1);5880 try expect(performFn('o', 0) == 1);
5880 expect(performFn('w', 99) == 99);5881 try expect(performFn('w', 99) == 99);
5881}5882}
5882 {#code_end#}5883 {#code_end#}
5883 <p>5884 <p>
...@@ -5969,11 +5970,11 @@ fn fibonacci(index: u32) u32 {...@@ -5969,11 +5970,11 @@ fn fibonacci(index: u32) u32 {
59695970
5970test "fibonacci" {5971test "fibonacci" {
5971 // test fibonacci at run-time5972 // test fibonacci at run-time
5972 expect(fibonacci(7) == 13);5973 try expect(fibonacci(7) == 13);
59735974
5974 // test fibonacci at compile-time5975 // test fibonacci at compile-time
5975 comptime {5976 comptime {
5976 expect(fibonacci(7) == 13);5977 try expect(fibonacci(7) == 13);
5977 }5978 }
5978}5979}
5979 {#code_end#}5980 {#code_end#}
...@@ -5990,7 +5991,7 @@ fn fibonacci(index: u32) u32 {...@@ -5990,7 +5991,7 @@ fn fibonacci(index: u32) u32 {
59905991
5991test "fibonacci" {5992test "fibonacci" {
5992 comptime {5993 comptime {
5993 expect(fibonacci(7) == 13);5994 try expect(fibonacci(7) == 13);
5994 }5995 }
5995}5996}
5996 {#code_end#}5997 {#code_end#}
...@@ -6013,7 +6014,7 @@ fn fibonacci(index: i32) i32 {...@@ -6013,7 +6014,7 @@ fn fibonacci(index: i32) i32 {
60136014
6014test "fibonacci" {6015test "fibonacci" {
6015 comptime {6016 comptime {
6016 expect(fibonacci(7) == 13);6017 try expect(fibonacci(7) == 13);
6017 }6018 }
6018}6019}
6019 {#code_end#}6020 {#code_end#}
...@@ -6026,7 +6027,7 @@ test "fibonacci" {...@@ -6026,7 +6027,7 @@ test "fibonacci" {
6026 <p>6027 <p>
6027 What if we fix the base case, but put the wrong value in the {#syntax#}expect{#endsyntax#} line?6028 What if we fix the base case, but put the wrong value in the {#syntax#}expect{#endsyntax#} line?
6028 </p>6029 </p>
6029 {#code_begin|test_err|encountered @panic at compile-time#}6030 {#code_begin|test_err|test "fibonacci"... FAIL (TestUnexpectedResult)#}
6030const expect = @import("std").testing.expect;6031const expect = @import("std").testing.expect;
60316032
6032fn fibonacci(index: i32) i32 {6033fn fibonacci(index: i32) i32 {
...@@ -6036,7 +6037,7 @@ fn fibonacci(index: i32) i32 {...@@ -6036,7 +6037,7 @@ fn fibonacci(index: i32) i32 {
60366037
6037test "fibonacci" {6038test "fibonacci" {
6038 comptime {6039 comptime {
6039 expect(fibonacci(7) == 99999);6040 try expect(fibonacci(7) == 99999);
6040 }6041 }
6041}6042}
6042 {#code_end#}6043 {#code_end#}
...@@ -6086,7 +6087,7 @@ fn sum(numbers: []const i32) i32 {...@@ -6086,7 +6087,7 @@ fn sum(numbers: []const i32) i32 {
6086}6087}
60876088
6088test "variable values" {6089test "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);
6090}6091}
6091 {#code_end#}6092 {#code_end#}
6092 <p>6093 <p>
...@@ -6494,7 +6495,7 @@ comptime {...@@ -6494,7 +6495,7 @@ comptime {
6494extern fn my_func(a: i32, b: i32) i32;6495extern fn my_func(a: i32, b: i32) i32;
64956496
6496test "global assembly" {6497test "global assembly" {
6497 expect(my_func(12, 34) == 46);6498 try expect(my_func(12, 34) == 46);
6498}6499}
6499 {#code_end#}6500 {#code_end#}
6500 {#header_close#}6501 {#header_close#}
...@@ -6535,7 +6536,7 @@ var x: i32 = 1;...@@ -6535,7 +6536,7 @@ var x: i32 = 1;
65356536
6536test "suspend with no resume" {6537test "suspend with no resume" {
6537 var frame = async func();6538 var frame = async func();
6538 expect(x == 2);6539 try expect(x == 2);
6539}6540}
65406541
6541fn func() void {6542fn func() void {
...@@ -6562,14 +6563,14 @@ var result = false;...@@ -6562,14 +6563,14 @@ var result = false;
65626563
6563test "async function suspend with block" {6564test "async function suspend with block" {
6564 _ = async testSuspendBlock();6565 _ = async testSuspendBlock();
6565 expect(!result);6566 try expect(!result);
6566 resume the_frame;6567 resume the_frame;
6567 expect(result);6568 try expect(result);
6568}6569}
65696570
6570fn testSuspendBlock() void {6571fn testSuspendBlock() void {
6571 suspend {6572 suspend {
6572 comptime expect(@TypeOf(@frame()) == *@Frame(testSuspendBlock));6573 comptime try expect(@TypeOf(@frame()) == *@Frame(testSuspendBlock));
6573 the_frame = @frame();6574 the_frame = @frame();
6574 }6575 }
6575 result = true;6576 result = true;
...@@ -6598,7 +6599,7 @@ const expect = std.testing.expect;...@@ -6598,7 +6599,7 @@ const expect = std.testing.expect;
6598test "resume from suspend" {6599test "resume from suspend" {
6599 var my_result: i32 = 1;6600 var my_result: i32 = 1;
6600 _ = async testResumeFromSuspend(&my_result);6601 _ = async testResumeFromSuspend(&my_result);
6601 std.testing.expect(my_result == 2);6602 try std.testing.expect(my_result == 2);
6602}6603}
6603fn testResumeFromSuspend(my_result: *i32) void {6604fn testResumeFromSuspend(my_result: *i32) void {
6604 suspend {6605 suspend {
...@@ -6634,7 +6635,7 @@ test "async and await" {...@@ -6634,7 +6635,7 @@ test "async and await" {
66346635
6635fn amain() void {6636fn amain() void {
6636 var frame = async func();6637 var frame = async func();
6637 comptime expect(@TypeOf(frame) == @Frame(func));6638 comptime try expect(@TypeOf(frame) == @Frame(func));
66386639
6639 const ptr: anyframe->void = &frame;6640 const ptr: anyframe->void = &frame;
6640 const any_ptr: anyframe = ptr;6641 const any_ptr: anyframe = ptr;
...@@ -6675,8 +6676,8 @@ test "async function await" {...@@ -6675,8 +6676,8 @@ test "async function await" {
6675 seq('f');6676 seq('f');
6676 resume the_frame;6677 resume the_frame;
6677 seq('i');6678 seq('i');
6678 expect(final_result == 1234);6679 try expect(final_result == 1234);
6679 expect(std.mem.eql(u8, &seq_points, "abcdefghi"));6680 try expect(std.mem.eql(u8, &seq_points, "abcdefghi"));
6680}6681}
6681fn amain() void {6682fn amain() void {
6682 seq('b');6683 seq('b');
...@@ -6890,9 +6891,9 @@ fn readFile(allocator: *Allocator, filename: []const u8) ![]u8 {...@@ -6890,9 +6891,9 @@ fn readFile(allocator: *Allocator, filename: []const u8) ![]u8 {
6890 for the current target to match the C ABI. When the child type of a pointer has6891 for the current target to match the C ABI. When the child type of a pointer has
6891 this alignment, the alignment can be omitted from the type.6892 this alignment, the alignment can be omitted from the type.
6892 </p>6893 </p>
6893 <pre>{#syntax#}const expect = @import("std").testing.expect;6894 <pre>{#syntax#}const expect = @import("std").debug.assert;
6894comptime {6895comptime {
6895 expect(*u32 == *align(@alignOf(u32)) u32);6896 assert(*u32 == *align(@alignOf(u32)) u32);
6896}{#endsyntax#}</pre>6897}{#endsyntax#}</pre>
6897 <p>6898 <p>
6898 The result is a target-specific compile time constant. It is guaranteed to be6899 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" {...@@ -6938,9 +6939,9 @@ test "async fn pointer in a struct field" {
6938 var foo = Foo{ .bar = func };6939 var foo = Foo{ .bar = func };
6939 var bytes: [64]u8 align(@alignOf(@Frame(func))) = undefined;6940 var bytes: [64]u8 align(@alignOf(@Frame(func))) = undefined;
6940 const f = @asyncCall(&bytes, {}, foo.bar, .{&data});6941 const f = @asyncCall(&bytes, {}, foo.bar, .{&data});
6941 expect(data == 2);6942 try expect(data == 2);
6942 resume f;6943 resume f;
6943 expect(data == 4);6944 try expect(data == 4);
6944}6945}
69456946
6946fn func(y: *i32) void {6947fn func(y: *i32) void {
...@@ -7127,7 +7128,7 @@ fn func(y: *i32) void {...@@ -7127,7 +7128,7 @@ fn func(y: *i32) void {
7127const expect = @import("std").testing.expect;7128const expect = @import("std").testing.expect;
71287129
7129test "noinline function call" {7130test "noinline function call" {
7130 expect(@call(.{}, add, .{3, 9}) == 12);7131 try expect(@call(.{}, add, .{3, 9}) == 12);
7131}7132}
71327133
7133fn add(a: i32, b: i32) i32 {7134fn add(a: i32, b: i32) i32 {
...@@ -7602,17 +7603,17 @@ test "field access by string" {...@@ -7602,17 +7603,17 @@ test "field access by string" {
7602 @field(p, "x") = 4;7603 @field(p, "x") = 4;
7603 @field(p, "y") = @field(p, "x") + 1;7604 @field(p, "y") = @field(p, "x") + 1;
76047605
7605 expect(@field(p, "x") == 4);7606 try expect(@field(p, "x") == 4);
7606 expect(@field(p, "y") == 5);7607 try expect(@field(p, "y") == 5);
7607}7608}
76087609
7609test "decl access by string" {7610test "decl access by string" {
7610 const expect = std.testing.expect;7611 const expect = std.testing.expect;
76117612
7612 expect(@field(Point, "z") == 1);7613 try expect(@field(Point, "z") == 1);
76137614
7614 @field(Point, "z") = 2;7615 @field(Point, "z") = 2;
7615 expect(@field(Point, "z") == 2);7616 try expect(@field(Point, "z") == 2);
7616}7617}
7617 {#code_end#}7618 {#code_end#}
76187619
...@@ -7728,16 +7729,16 @@ const Foo = struct {...@@ -7728,16 +7729,16 @@ const Foo = struct {
7728};7729};
77297730
7730test "@hasDecl" {7731test "@hasDecl" {
7731 expect(@hasDecl(Foo, "blah"));7732 try expect(@hasDecl(Foo, "blah"));
77327733
7733 // Even though `hi` is private, @hasDecl returns true because this test is7734 // Even though `hi` is private, @hasDecl returns true because this test is
7734 // in the same file scope as Foo. It would return false if Foo was declared7735 // in the same file scope as Foo. It would return false if Foo was declared
7735 // in a different file.7736 // in a different file.
7736 expect(@hasDecl(Foo, "hi"));7737 try expect(@hasDecl(Foo, "hi"));
77377738
7738 // @hasDecl is for declarations; not fields.7739 // @hasDecl is for declarations; not fields.
7739 expect(!@hasDecl(Foo, "nope"));7740 try expect(!@hasDecl(Foo, "nope"));
7740 expect(!@hasDecl(Foo, "nope1234"));7741 try expect(!@hasDecl(Foo, "nope1234"));
7741}7742}
7742 {#code_end#}7743 {#code_end#}
7743 {#see_also|@hasField#}7744 {#see_also|@hasField#}
...@@ -7918,8 +7919,8 @@ test "@wasmMemoryGrow" {...@@ -7918,8 +7919,8 @@ test "@wasmMemoryGrow" {
7918 if (builtin.arch != .wasm32) return error.SkipZigTest;7919 if (builtin.arch != .wasm32) return error.SkipZigTest;
79197920
7920 var prev = @wasmMemorySize(0);7921 var prev = @wasmMemorySize(0);
7921 expect(prev == @wasmMemoryGrow(0, 1));7922 try expect(prev == @wasmMemoryGrow(0, 1));
7922 expect(prev + 1 == @wasmMemorySize(0));7923 try expect(prev + 1 == @wasmMemorySize(0));
7923}7924}
7924 {#code_end#}7925 {#code_end#}
7925 {#see_also|@wasmMemorySize#}7926 {#see_also|@wasmMemorySize#}
...@@ -8260,8 +8261,8 @@ const expect = std.testing.expect;...@@ -8260,8 +8261,8 @@ const expect = std.testing.expect;
8260test "vector @splat" {8261test "vector @splat" {
8261 const scalar: u32 = 5;8262 const scalar: u32 = 5;
8262 const result = @splat(4, scalar);8263 const result = @splat(4, scalar);
8263 comptime expect(@TypeOf(result) == std.meta.Vector(4, u32));8264 comptime try expect(@TypeOf(result) == std.meta.Vector(4, u32));
8264 expect(std.mem.eql(u32, &@as([4]u32, result), &[_]u32{ 5, 5, 5, 5 }));8265 try expect(std.mem.eql(u32, &@as([4]u32, result), &[_]u32{ 5, 5, 5, 5 }));
8265}8266}
8266 {#code_end#}8267 {#code_end#}
8267 <p>8268 <p>
...@@ -8303,10 +8304,10 @@ test "vector @reduce" {...@@ -8303,10 +8304,10 @@ test "vector @reduce" {
8303 const value: std.meta.Vector(4, i32) = [_]i32{ 1, -1, 1, -1 };8304 const value: std.meta.Vector(4, i32) = [_]i32{ 1, -1, 1, -1 };
8304 const result = value > @splat(4, @as(i32, 0));8305 const result = value > @splat(4, @as(i32, 0));
8305 // result is { true, false, true, false };8306 // 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));
8307 const is_all_true = @reduce(.And, result);8308 const is_all_true = @reduce(.And, result);
8308 comptime expect(@TypeOf(is_all_true) == bool);8309 comptime try expect(@TypeOf(is_all_true) == bool);
8309 expect(is_all_true == false);8310 try expect(is_all_true == false);
8310}8311}
8311 {#code_end#}8312 {#code_end#}
8312 {#see_also|Vectors|@setFloatMode#}8313 {#see_also|Vectors|@setFloatMode#}
...@@ -8322,16 +8323,16 @@ const std = @import("std");...@@ -8322,16 +8323,16 @@ const std = @import("std");
8322const expect = std.testing.expect;8323const expect = std.testing.expect;
83238324
8324test "@src" {8325test "@src" {
8325 doTheTest();8326 try doTheTest();
8326}8327}
83278328
8328fn doTheTest() void {8329fn doTheTest() !void {
8329 const src = @src();8330 const src = @src();
83308331
8331 expect(src.line == 9);8332 try expect(src.line == 9);
8332 expect(src.column == 17);8333 try expect(src.column == 17);
8333 expect(std.mem.endsWith(u8, src.fn_name, "doTheTest"));8334 try expect(std.mem.endsWith(u8, src.fn_name, "doTheTest"));
8334 expect(std.mem.endsWith(u8, src.file, "test.zig"));8335 try expect(std.mem.endsWith(u8, src.file, "test.zig"));
8335}8336}
8336 {#code_end#}8337 {#code_end#}
8337 {#header_close#}8338 {#header_close#}
...@@ -8508,7 +8509,7 @@ const expect = std.testing.expect;...@@ -8508,7 +8509,7 @@ const expect = std.testing.expect;
8508test "@This()" {8509test "@This()" {
8509 var items = [_]i32{ 1, 2, 3, 4 };8510 var items = [_]i32{ 1, 2, 3, 4 };
8510 const list = List(i32){ .items = items[0..] };8511 const list = List(i32){ .items = items[0..] };
8511 expect(list.length() == 4);8512 try expect(list.length() == 4);
8512}8513}
85138514
8514fn List(comptime T: type) type {8515fn List(comptime T: type) type {
...@@ -8554,7 +8555,7 @@ const expect = std.testing.expect;...@@ -8554,7 +8555,7 @@ const expect = std.testing.expect;
8554test "integer truncation" {8555test "integer truncation" {
8555 var a: u16 = 0xabcd;8556 var a: u16 = 0xabcd;
8556 var b: u8 = @truncate(u8, a);8557 var b: u8 = @truncate(u8, a);
8557 expect(b == 0xcd);8558 try expect(b == 0xcd);
8558}8559}
8559 {#code_end#}8560 {#code_end#}
8560 <p>8561 <p>
...@@ -8642,8 +8643,8 @@ const expect = std.testing.expect;...@@ -8642,8 +8643,8 @@ const expect = std.testing.expect;
8642test "no runtime side effects" {8643test "no runtime side effects" {
8643 var data: i32 = 0;8644 var data: i32 = 0;
8644 const T = @TypeOf(foo(i32, &data));8645 const T = @TypeOf(foo(i32, &data));
8645 comptime expect(T == i32);8646 comptime try expect(T == i32);
8646 expect(data == 0);8647 try expect(data == 0);
8647}8648}
86488649
8649fn foo(comptime T: type, ptr: *T) T {8650fn foo(comptime T: type, ptr: *T) T {
...@@ -8953,9 +8954,9 @@ const maxInt = std.math.maxInt;...@@ -8953,9 +8954,9 @@ const maxInt = std.math.maxInt;
8953test "wraparound addition and subtraction" {8954test "wraparound addition and subtraction" {
8954 const x: i32 = maxInt(i32);8955 const x: i32 = maxInt(i32);
8955 const min_val = x +% 1;8956 const min_val = x +% 1;
8956 expect(min_val == minInt(i32));8957 try expect(min_val == minInt(i32));
8957 const max_val = min_val -% 1;8958 const max_val = min_val -% 1;
8958 expect(max_val == maxInt(i32));8959 try expect(max_val == maxInt(i32));
8959}8960}
8960 {#code_end#}8961 {#code_end#}
8961 {#header_close#}8962 {#header_close#}
...@@ -9386,7 +9387,7 @@ test "using an allocator" {...@@ -9386,7 +9387,7 @@ test "using an allocator" {
9386 var buffer: [100]u8 = undefined;9387 var buffer: [100]u8 = undefined;
9387 const allocator = &std.heap.FixedBufferAllocator.init(&buffer).allocator;9388 const allocator = &std.heap.FixedBufferAllocator.init(&buffer).allocator;
9388 const result = try concat(allocator, "foo", "bar");9389 const result = try concat(allocator, "foo", "bar");
9389 expect(std.mem.eql(u8, "foobar", result));9390 try expect(std.mem.eql(u8, "foobar", result));
9390}9391}
93919392
9392fn concat(allocator: *Allocator, a: []const u8, b: []const u8) ![]u8 {9393fn concat(allocator: *Allocator, a: []const u8, b: []const u8) ![]u8 {
...@@ -9656,7 +9657,7 @@ const builtin = std.builtin;...@@ -9656,7 +9657,7 @@ const builtin = std.builtin;
9656const expect = std.testing.expect;9657const expect = std.testing.expect;
96579658
9658test "builtin.is_test" {9659test "builtin.is_test" {
9659 expect(builtin.is_test);9660 try expect(builtin.is_test);
9660}9661}
9661 {#code_end#}9662 {#code_end#}
9662 <p>9663 <p>
...@@ -9701,13 +9702,13 @@ test "assert in release fast mode" {...@@ -9701,13 +9702,13 @@ test "assert in release fast mode" {
9701 <p>9702 <p>
9702 Better practice for checking the output when testing is to use {#syntax#}std.testing.expect{#endsyntax#}:9703 Better practice for checking the output when testing is to use {#syntax#}std.testing.expect{#endsyntax#}:
9703 </p>9704 </p>
9704 {#code_begin|test_err|test failure#}9705 {#code_begin|test_err|test "expect in release fast mode"... FAIL (TestUnexpectedResult)#}
9705 {#code_release_fast#}9706 {#code_release_fast#}
9706const std = @import("std");9707const std = @import("std");
9707const expect = std.testing.expect;9708const expect = std.testing.expect;
97089709
9709test "expect in release fast mode" {9710test "expect in release fast mode" {
9710 expect(false);9711 try expect(false);
9711}9712}
9712 {#code_end#}9713 {#code_end#}
9713 <p>See the rest of the {#syntax#}std.testing{#endsyntax#} namespace for more available functions.</p>9714 <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" {...@@ -249,13 +249,13 @@ test "SemanticVersion format" {
249 "+justmeta",249 "+justmeta",
250 "9.8.7+meta+meta",250 "9.8.7+meta+meta",
251 "9.8.7-whatever+meta+meta",251 "9.8.7-whatever+meta+meta",
252 }) |invalid| expectError(error.InvalidVersion, parse(invalid));252 }) |invalid| try expectError(error.InvalidVersion, parse(invalid));
253253
254 // Valid version string that may overflow.254 // Valid version string that may overflow.
255 const big_valid = "99999999999999999999999.999999999999999999.99999999999999999";255 const big_valid = "99999999999999999999999.999999999999999999.99999999999999999";
256 if (parse(big_valid)) |ver| {256 if (parse(big_valid)) |ver| {
257 try std.testing.expectFmt(big_valid, "{}", .{ver});257 try std.testing.expectFmt(big_valid, "{}", .{ver});
258 } else |err| expect(err == error.Overflow);258 } else |err| try expect(err == error.Overflow);
259259
260 // Invalid version string that may overflow.260 // Invalid version string that may overflow.
261 const big_invalid = "99999999999999999999999.999999999999999999.99999999999999999----RC-SNAPSHOT.12.09.1--------------------------------..12";261 const big_invalid = "99999999999999999999999.999999999999999999.99999999999999999----RC-SNAPSHOT.12.09.1--------------------------------..12";
...@@ -264,22 +264,22 @@ test "SemanticVersion format" {...@@ -264,22 +264,22 @@ test "SemanticVersion format" {
264264
265test "SemanticVersion precedence" {265test "SemanticVersion precedence" {
266 // SemVer 2 spec 11.2 example: 1.0.0 < 2.0.0 < 2.1.0 < 2.1.1.266 // 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);267 try 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);268 try 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);269 try expect(order(try parse("2.1.0"), try parse("2.1.1")) == .lt);
270270
271 // SemVer 2 spec 11.3 example: 1.0.0-alpha < 1.0.0.271 // 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
274 // SemVer 2 spec 11.4 example: 1.0.0-alpha < 1.0.0-alpha.1 < 1.0.0-alpha.beta < 1.0.0-beta <274 // SemVer 2 spec 11.4 example: 1.0.0-alpha < 1.0.0-alpha.1 < 1.0.0-alpha.beta < 1.0.0-beta <
275 // 1.0.0-beta.2 < 1.0.0-beta.11 < 1.0.0-rc.1 < 1.0.0.275 // 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);276 try 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);277 try 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);278 try 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);279 try 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);280 try 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);281 try 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);282 try expect(order(try parse("1.0.0-rc.1"), try parse("1.0.0")) == .lt);
283}283}
284284
285test "zig_version" {285test "zig_version" {
lib/std/Thread/AutoResetEvent.zig+8-8
...@@ -176,7 +176,7 @@ test "basic usage" {...@@ -176,7 +176,7 @@ test "basic usage" {
176 // test local code paths176 // test local code paths
177 {177 {
178 var event = AutoResetEvent{};178 var event = AutoResetEvent{};
179 testing.expectError(error.TimedOut, event.timedWait(1));179 try testing.expectError(error.TimedOut, event.timedWait(1));
180 event.set();180 event.set();
181 event.wait();181 event.wait();
182 }182 }
...@@ -192,28 +192,28 @@ test "basic usage" {...@@ -192,28 +192,28 @@ test "basic usage" {
192192
193 const Self = @This();193 const Self = @This();
194194
195 fn sender(self: *Self) void {195 fn sender(self: *Self) !void {
196 testing.expect(self.value == 0);196 try testing.expect(self.value == 0);
197 self.value = 1;197 self.value = 1;
198 self.out.set();198 self.out.set();
199199
200 self.in.wait();200 self.in.wait();
201 testing.expect(self.value == 2);201 try testing.expect(self.value == 2);
202 self.value = 3;202 self.value = 3;
203 self.out.set();203 self.out.set();
204204
205 self.in.wait();205 self.in.wait();
206 testing.expect(self.value == 4);206 try testing.expect(self.value == 4);
207 }207 }
208208
209 fn receiver(self: *Self) void {209 fn receiver(self: *Self) !void {
210 self.out.wait();210 self.out.wait();
211 testing.expect(self.value == 1);211 try testing.expect(self.value == 1);
212 self.value = 2;212 self.value = 2;
213 self.in.set();213 self.in.set();
214214
215 self.out.wait();215 self.out.wait();
216 testing.expect(self.value == 3);216 try testing.expect(self.value == 3);
217 self.value = 4;217 self.value = 4;
218 self.in.set();218 self.in.set();
219 }219 }
lib/std/Thread/Mutex.zig+2-2
...@@ -294,7 +294,7 @@ test "basic usage" {...@@ -294,7 +294,7 @@ test "basic usage" {
294294
295 if (builtin.single_threaded) {295 if (builtin.single_threaded) {
296 worker(&context);296 worker(&context);
297 testing.expect(context.data == TestContext.incr_count);297 try testing.expect(context.data == TestContext.incr_count);
298 } else {298 } else {
299 const thread_count = 10;299 const thread_count = 10;
300 var threads: [thread_count]*std.Thread = undefined;300 var threads: [thread_count]*std.Thread = undefined;
...@@ -304,7 +304,7 @@ test "basic usage" {...@@ -304,7 +304,7 @@ test "basic usage" {
304 for (threads) |t|304 for (threads) |t|
305 t.wait();305 t.wait();
306306
307 testing.expect(context.data == thread_count * TestContext.incr_count);307 try testing.expect(context.data == thread_count * TestContext.incr_count);
308 }308 }
309}309}
310310
lib/std/Thread/ResetEvent.zig+10-10
...@@ -204,7 +204,7 @@ test "basic usage" {...@@ -204,7 +204,7 @@ test "basic usage" {
204 event.reset();204 event.reset();
205205
206 event.set();206 event.set();
207 testing.expectEqual(TimedWaitResult.event_set, event.timedWait(1));207 try testing.expectEqual(TimedWaitResult.event_set, event.timedWait(1));
208208
209 // test cross-thread signaling209 // test cross-thread signaling
210 if (builtin.single_threaded)210 if (builtin.single_threaded)
...@@ -233,25 +233,25 @@ test "basic usage" {...@@ -233,25 +233,25 @@ test "basic usage" {
233 self.* = undefined;233 self.* = undefined;
234 }234 }
235235
236 fn sender(self: *Self) void {236 fn sender(self: *Self) !void {
237 // update value and signal input237 // update value and signal input
238 testing.expect(self.value == 0);238 try testing.expect(self.value == 0);
239 self.value = 1;239 self.value = 1;
240 self.in.set();240 self.in.set();
241241
242 // wait for receiver to update value and signal output242 // wait for receiver to update value and signal output
243 self.out.wait();243 self.out.wait();
244 testing.expect(self.value == 2);244 try testing.expect(self.value == 2);
245245
246 // update value and signal final input246 // update value and signal final input
247 self.value = 3;247 self.value = 3;
248 self.in.set();248 self.in.set();
249 }249 }
250250
251 fn receiver(self: *Self) void {251 fn receiver(self: *Self) !void {
252 // wait for sender to update value and signal input252 // wait for sender to update value and signal input
253 self.in.wait();253 self.in.wait();
254 assert(self.value == 1);254 try testing.expect(self.value == 1);
255255
256 // update value and signal output256 // update value and signal output
257 self.in.reset();257 self.in.reset();
...@@ -260,7 +260,7 @@ test "basic usage" {...@@ -260,7 +260,7 @@ test "basic usage" {
260260
261 // wait for sender to update value and signal final input261 // wait for sender to update value and signal final input
262 self.in.wait();262 self.in.wait();
263 assert(self.value == 3);263 try testing.expect(self.value == 3);
264 }264 }
265265
266 fn sleeper(self: *Self) void {266 fn sleeper(self: *Self) void {
...@@ -272,9 +272,9 @@ test "basic usage" {...@@ -272,9 +272,9 @@ test "basic usage" {
272272
273 fn timedWaiter(self: *Self) !void {273 fn timedWaiter(self: *Self) !void {
274 self.in.wait();274 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));
276 try self.out.timedWait(time.ns_per_ms * 100);276 try self.out.timedWait(time.ns_per_ms * 100);
277 testing.expect(self.value == 5);277 try testing.expect(self.value == 5);
278 }278 }
279 };279 };
280280
...@@ -283,7 +283,7 @@ test "basic usage" {...@@ -283,7 +283,7 @@ test "basic usage" {
283 defer context.deinit();283 defer context.deinit();
284 const receiver = try std.Thread.spawn(Context.receiver, &context);284 const receiver = try std.Thread.spawn(Context.receiver, &context);
285 defer receiver.wait();285 defer receiver.wait();
286 context.sender();286 try context.sender();
287287
288 if (false) {288 if (false) {
289 // I have now observed this fail on macOS, Windows, and Linux.289 // 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" {...@@ -320,7 +320,7 @@ test "basic usage" {
320 event.reset();320 event.reset();
321321
322 event.set();322 event.set();
323 testing.expectEqual(TimedWaitResult.event_set, event.timedWait(1));323 try testing.expectEqual(TimedWaitResult.event_set, event.timedWait(1));
324324
325 // test cross-thread signaling325 // test cross-thread signaling
326 if (std.builtin.single_threaded)326 if (std.builtin.single_threaded)
...@@ -333,25 +333,25 @@ test "basic usage" {...@@ -333,25 +333,25 @@ test "basic usage" {
333 in: StaticResetEvent = .{},333 in: StaticResetEvent = .{},
334 out: StaticResetEvent = .{},334 out: StaticResetEvent = .{},
335335
336 fn sender(self: *Self) void {336 fn sender(self: *Self) !void {
337 // update value and signal input337 // update value and signal input
338 testing.expect(self.value == 0);338 try testing.expect(self.value == 0);
339 self.value = 1;339 self.value = 1;
340 self.in.set();340 self.in.set();
341341
342 // wait for receiver to update value and signal output342 // wait for receiver to update value and signal output
343 self.out.wait();343 self.out.wait();
344 testing.expect(self.value == 2);344 try testing.expect(self.value == 2);
345345
346 // update value and signal final input346 // update value and signal final input
347 self.value = 3;347 self.value = 3;
348 self.in.set();348 self.in.set();
349 }349 }
350350
351 fn receiver(self: *Self) void {351 fn receiver(self: *Self) !void {
352 // wait for sender to update value and signal input352 // wait for sender to update value and signal input
353 self.in.wait();353 self.in.wait();
354 assert(self.value == 1);354 try testing.expect(self.value == 1);
355355
356 // update value and signal output356 // update value and signal output
357 self.in.reset();357 self.in.reset();
...@@ -360,7 +360,7 @@ test "basic usage" {...@@ -360,7 +360,7 @@ test "basic usage" {
360360
361 // wait for sender to update value and signal final input361 // wait for sender to update value and signal final input
362 self.in.wait();362 self.in.wait();
363 assert(self.value == 3);363 try testing.expect(self.value == 3);
364 }364 }
365365
366 fn sleeper(self: *Self) void {366 fn sleeper(self: *Self) void {
...@@ -372,16 +372,16 @@ test "basic usage" {...@@ -372,16 +372,16 @@ test "basic usage" {
372372
373 fn timedWaiter(self: *Self) !void {373 fn timedWaiter(self: *Self) !void {
374 self.in.wait();374 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));
376 try self.out.timedWait(time.ns_per_ms * 100);376 try self.out.timedWait(time.ns_per_ms * 100);
377 testing.expect(self.value == 5);377 try testing.expect(self.value == 5);
378 }378 }
379 };379 };
380380
381 var context = Context{};381 var context = Context{};
382 const receiver = try std.Thread.spawn(Context.receiver, &context);382 const receiver = try std.Thread.spawn(Context.receiver, &context);
383 defer receiver.wait();383 defer receiver.wait();
384 context.sender();384 try context.sender();
385385
386 if (false) {386 if (false) {
387 // I have now observed this fail on macOS, Windows, and Linux.387 // 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" {...@@ -1088,63 +1088,63 @@ test "basic hash map usage" {
1088 var map = AutoArrayHashMap(i32, i32).init(std.testing.allocator);1088 var map = AutoArrayHashMap(i32, i32).init(std.testing.allocator);
1089 defer map.deinit();1089 defer map.deinit();
10901090
1091 testing.expect((try map.fetchPut(1, 11)) == null);1091 try testing.expect((try map.fetchPut(1, 11)) == null);
1092 testing.expect((try map.fetchPut(2, 22)) == null);1092 try testing.expect((try map.fetchPut(2, 22)) == null);
1093 testing.expect((try map.fetchPut(3, 33)) == null);1093 try testing.expect((try map.fetchPut(3, 33)) == null);
1094 testing.expect((try map.fetchPut(4, 44)) == null);1094 try testing.expect((try map.fetchPut(4, 44)) == null);
10951095
1096 try map.putNoClobber(5, 55);1096 try map.putNoClobber(5, 55);
1097 testing.expect((try map.fetchPut(5, 66)).?.value == 55);1097 try testing.expect((try map.fetchPut(5, 66)).?.value == 55);
1098 testing.expect((try map.fetchPut(5, 55)).?.value == 66);1098 try testing.expect((try map.fetchPut(5, 55)).?.value == 66);
10991099
1100 const gop1 = try map.getOrPut(5);1100 const gop1 = try map.getOrPut(5);
1101 testing.expect(gop1.found_existing == true);1101 try testing.expect(gop1.found_existing == true);
1102 testing.expect(gop1.entry.value == 55);1102 try testing.expect(gop1.entry.value == 55);
1103 testing.expect(gop1.index == 4);1103 try testing.expect(gop1.index == 4);
1104 gop1.entry.value = 77;1104 gop1.entry.value = 77;
1105 testing.expect(map.getEntry(5).?.value == 77);1105 try testing.expect(map.getEntry(5).?.value == 77);
11061106
1107 const gop2 = try map.getOrPut(99);1107 const gop2 = try map.getOrPut(99);
1108 testing.expect(gop2.found_existing == false);1108 try testing.expect(gop2.found_existing == false);
1109 testing.expect(gop2.index == 5);1109 try testing.expect(gop2.index == 5);
1110 gop2.entry.value = 42;1110 gop2.entry.value = 42;
1111 testing.expect(map.getEntry(99).?.value == 42);1111 try testing.expect(map.getEntry(99).?.value == 42);
11121112
1113 const gop3 = try map.getOrPutValue(5, 5);1113 const gop3 = try map.getOrPutValue(5, 5);
1114 testing.expect(gop3.value == 77);1114 try testing.expect(gop3.value == 77);
11151115
1116 const gop4 = try map.getOrPutValue(100, 41);1116 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));1119 try testing.expect(map.contains(2));
1120 testing.expect(map.getEntry(2).?.value == 22);1120 try testing.expect(map.getEntry(2).?.value == 22);
1121 testing.expect(map.get(2).? == 22);1121 try testing.expect(map.get(2).? == 22);
11221122
1123 const rmv1 = map.swapRemove(2);1123 const rmv1 = map.swapRemove(2);
1124 testing.expect(rmv1.?.key == 2);1124 try testing.expect(rmv1.?.key == 2);
1125 testing.expect(rmv1.?.value == 22);1125 try testing.expect(rmv1.?.value == 22);
1126 testing.expect(map.swapRemove(2) == null);1126 try testing.expect(map.swapRemove(2) == null);
1127 testing.expect(map.getEntry(2) == null);1127 try testing.expect(map.getEntry(2) == null);
1128 testing.expect(map.get(2) == null);1128 try testing.expect(map.get(2) == null);
11291129
1130 // Since we've used `swapRemove` above, the index of this entry should remain unchanged.1130 // 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);
1132 const gop5 = try map.getOrPut(5);1132 const gop5 = try map.getOrPut(5);
1133 testing.expect(gop5.found_existing == true);1133 try testing.expect(gop5.found_existing == true);
1134 testing.expect(gop5.entry.value == 77);1134 try testing.expect(gop5.entry.value == 77);
1135 testing.expect(gop5.index == 4);1135 try testing.expect(gop5.index == 4);
11361136
1137 // Whereas, if we do an `orderedRemove`, it should move the index forward one spot.1137 // Whereas, if we do an `orderedRemove`, it should move the index forward one spot.
1138 const rmv2 = map.orderedRemove(100);1138 const rmv2 = map.orderedRemove(100);
1139 testing.expect(rmv2.?.key == 100);1139 try testing.expect(rmv2.?.key == 100);
1140 testing.expect(rmv2.?.value == 41);1140 try testing.expect(rmv2.?.value == 41);
1141 testing.expect(map.orderedRemove(100) == null);1141 try testing.expect(map.orderedRemove(100) == null);
1142 testing.expect(map.getEntry(100) == null);1142 try testing.expect(map.getEntry(100) == null);
1143 testing.expect(map.get(100) == null);1143 try testing.expect(map.get(100) == null);
1144 const gop6 = try map.getOrPut(5);1144 const gop6 = try map.getOrPut(5);
1145 testing.expect(gop6.found_existing == true);1145 try testing.expect(gop6.found_existing == true);
1146 testing.expect(gop6.entry.value == 77);1146 try testing.expect(gop6.entry.value == 77);
1147 testing.expect(gop6.index == 3);1147 try testing.expect(gop6.index == 3);
11481148
1149 map.removeAssertDiscard(3);1149 map.removeAssertDiscard(3);
1150}1150}
...@@ -1180,11 +1180,11 @@ test "iterator hash map" {...@@ -1180,11 +1180,11 @@ test "iterator hash map" {
1180 while (it.next()) |entry| : (count += 1) {1180 while (it.next()) |entry| : (count += 1) {
1181 buffer[@intCast(usize, entry.key)] = entry.value;1181 buffer[@intCast(usize, entry.key)] = entry.value;
1182 }1182 }
1183 testing.expect(count == 3);1183 try testing.expect(count == 3);
1184 testing.expect(it.next() == null);1184 try testing.expect(it.next() == null);
11851185
1186 for (buffer) |v, i| {1186 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]);
1188 }1188 }
11891189
1190 it.reset();1190 it.reset();
...@@ -1196,13 +1196,13 @@ test "iterator hash map" {...@@ -1196,13 +1196,13 @@ test "iterator hash map" {
1196 }1196 }
11971197
1198 for (buffer[0..2]) |v, i| {1198 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]);
1200 }1200 }
12011201
1202 it.reset();1202 it.reset();
1203 var entry = it.next().?;1203 var entry = it.next().?;
1204 testing.expect(entry.key == first_entry.key);1204 try testing.expect(entry.key == first_entry.key);
1205 testing.expect(entry.value == first_entry.value);1205 try testing.expect(entry.value == first_entry.value);
1206}1206}
12071207
1208test "ensure capacity" {1208test "ensure capacity" {
...@@ -1211,13 +1211,13 @@ test "ensure capacity" {...@@ -1211,13 +1211,13 @@ test "ensure capacity" {
12111211
1212 try map.ensureCapacity(20);1212 try map.ensureCapacity(20);
1213 const initial_capacity = map.capacity();1213 const initial_capacity = map.capacity();
1214 testing.expect(initial_capacity >= 20);1214 try testing.expect(initial_capacity >= 20);
1215 var i: i32 = 0;1215 var i: i32 = 0;
1216 while (i < 20) : (i += 1) {1216 while (i < 20) : (i += 1) {
1217 testing.expect(map.fetchPutAssumeCapacity(i, i + 10) == null);1217 try testing.expect(map.fetchPutAssumeCapacity(i, i + 10) == null);
1218 }1218 }
1219 // shouldn't resize from putAssumeCapacity1219 // shouldn't resize from putAssumeCapacity
1220 testing.expect(initial_capacity == map.capacity());1220 try testing.expect(initial_capacity == map.capacity());
1221}1221}
12221222
1223test "clone" {1223test "clone" {
...@@ -1235,7 +1235,7 @@ test "clone" {...@@ -1235,7 +1235,7 @@ test "clone" {
12351235
1236 i = 0;1236 i = 0;
1237 while (i < 10) : (i += 1) {1237 while (i < 10) : (i += 1) {
1238 testing.expect(copy.get(i).? == i * 10);1238 try testing.expect(copy.get(i).? == i * 10);
1239 }1239 }
1240}1240}
12411241
...@@ -1247,35 +1247,35 @@ test "shrink" {...@@ -1247,35 +1247,35 @@ test "shrink" {
1247 const num_entries = 20;1247 const num_entries = 20;
1248 var i: i32 = 0;1248 var i: i32 = 0;
1249 while (i < num_entries) : (i += 1)1249 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);1252 try testing.expect(map.unmanaged.index_header != null);
1253 testing.expect(map.count() == num_entries);1253 try testing.expect(map.count() == num_entries);
12541254
1255 // Test `shrinkRetainingCapacity`.1255 // Test `shrinkRetainingCapacity`.
1256 map.shrinkRetainingCapacity(17);1256 map.shrinkRetainingCapacity(17);
1257 testing.expect(map.count() == 17);1257 try testing.expect(map.count() == 17);
1258 testing.expect(map.capacity() == 20);1258 try testing.expect(map.capacity() == 20);
1259 i = 0;1259 i = 0;
1260 while (i < num_entries) : (i += 1) {1260 while (i < num_entries) : (i += 1) {
1261 const gop = try map.getOrPut(i);1261 const gop = try map.getOrPut(i);
1262 if (i < 17) {1262 if (i < 17) {
1263 testing.expect(gop.found_existing == true);1263 try testing.expect(gop.found_existing == true);
1264 testing.expect(gop.entry.value == i * 10);1264 try testing.expect(gop.entry.value == i * 10);
1265 } else testing.expect(gop.found_existing == false);1265 } else try testing.expect(gop.found_existing == false);
1266 }1266 }
12671267
1268 // Test `shrinkAndFree`.1268 // Test `shrinkAndFree`.
1269 map.shrinkAndFree(15);1269 map.shrinkAndFree(15);
1270 testing.expect(map.count() == 15);1270 try testing.expect(map.count() == 15);
1271 testing.expect(map.capacity() == 15);1271 try testing.expect(map.capacity() == 15);
1272 i = 0;1272 i = 0;
1273 while (i < num_entries) : (i += 1) {1273 while (i < num_entries) : (i += 1) {
1274 const gop = try map.getOrPut(i);1274 const gop = try map.getOrPut(i);
1275 if (i < 15) {1275 if (i < 15) {
1276 testing.expect(gop.found_existing == true);1276 try testing.expect(gop.found_existing == true);
1277 testing.expect(gop.entry.value == i * 10);1277 try testing.expect(gop.entry.value == i * 10);
1278 } else testing.expect(gop.found_existing == false);1278 } else try testing.expect(gop.found_existing == false);
1279 }1279 }
1280}1280}
12811281
...@@ -1288,12 +1288,12 @@ test "pop" {...@@ -1288,12 +1288,12 @@ test "pop" {
12881288
1289 var i: i32 = 0;1289 var i: i32 = 0;
1290 while (i < 9) : (i += 1) {1290 while (i < 9) : (i += 1) {
1291 testing.expect((try map.fetchPut(i, i)) == null);1291 try testing.expect((try map.fetchPut(i, i)) == null);
1292 }1292 }
12931293
1294 while (i > 0) : (i -= 1) {1294 while (i > 0) : (i -= 1) {
1295 const pop = map.pop();1295 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);
1297 }1297 }
1298}1298}
12991299
...@@ -1305,10 +1305,10 @@ test "reIndex" {...@@ -1305,10 +1305,10 @@ test "reIndex" {
1305 const num_indexed_entries = 20;1305 const num_indexed_entries = 20;
1306 var i: i32 = 0;1306 var i: i32 = 0;
1307 while (i < num_indexed_entries) : (i += 1)1307 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
1310 // Make sure we allocated an index header.1310 // 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
1313 // Now write to the underlying array list directly.1313 // Now write to the underlying array list directly.
1314 const num_unindexed_entries = 20;1314 const num_unindexed_entries = 20;
...@@ -1327,9 +1327,9 @@ test "reIndex" {...@@ -1327,9 +1327,9 @@ test "reIndex" {
1327 i = 0;1327 i = 0;
1328 while (i < num_indexed_entries + num_unindexed_entries) : (i += 1) {1328 while (i < num_indexed_entries + num_unindexed_entries) : (i += 1) {
1329 const gop = try map.getOrPut(i);1329 const gop = try map.getOrPut(i);
1330 testing.expect(gop.found_existing == true);1330 try testing.expect(gop.found_existing == true);
1331 testing.expect(gop.entry.value == i * 10);1331 try testing.expect(gop.entry.value == i * 10);
1332 testing.expect(gop.index == i);1332 try testing.expect(gop.index == i);
1333 }1333 }
1334}1334}
13351335
...@@ -1356,9 +1356,9 @@ test "fromOwnedArrayList" {...@@ -1356,9 +1356,9 @@ test "fromOwnedArrayList" {
1356 i = 0;1356 i = 0;
1357 while (i < num_entries) : (i += 1) {1357 while (i < num_entries) : (i += 1) {
1358 const gop = try map.getOrPut(i);1358 const gop = try map.getOrPut(i);
1359 testing.expect(gop.found_existing == true);1359 try testing.expect(gop.found_existing == true);
1360 testing.expect(gop.entry.value == i * 10);1360 try testing.expect(gop.entry.value == i * 10);
1361 testing.expect(gop.index == i);1361 try testing.expect(gop.index == i);
1362 }1362 }
1363}1363}
13641364
lib/std/array_list.zig+116-116
...@@ -741,15 +741,15 @@ test "std.ArrayList/ArrayListUnmanaged.init" {...@@ -741,15 +741,15 @@ test "std.ArrayList/ArrayListUnmanaged.init" {
741 var list = ArrayList(i32).init(testing.allocator);741 var list = ArrayList(i32).init(testing.allocator);
742 defer list.deinit();742 defer list.deinit();
743743
744 testing.expect(list.items.len == 0);744 try testing.expect(list.items.len == 0);
745 testing.expect(list.capacity == 0);745 try testing.expect(list.capacity == 0);
746 }746 }
747747
748 {748 {
749 var list = ArrayListUnmanaged(i32){};749 var list = ArrayListUnmanaged(i32){};
750750
751 testing.expect(list.items.len == 0);751 try testing.expect(list.items.len == 0);
752 testing.expect(list.capacity == 0);752 try testing.expect(list.capacity == 0);
753 }753 }
754}754}
755755
...@@ -758,14 +758,14 @@ test "std.ArrayList/ArrayListUnmanaged.initCapacity" {...@@ -758,14 +758,14 @@ test "std.ArrayList/ArrayListUnmanaged.initCapacity" {
758 {758 {
759 var list = try ArrayList(i8).initCapacity(a, 200);759 var list = try ArrayList(i8).initCapacity(a, 200);
760 defer list.deinit();760 defer list.deinit();
761 testing.expect(list.items.len == 0);761 try testing.expect(list.items.len == 0);
762 testing.expect(list.capacity >= 200);762 try testing.expect(list.capacity >= 200);
763 }763 }
764 {764 {
765 var list = try ArrayListUnmanaged(i8).initCapacity(a, 200);765 var list = try ArrayListUnmanaged(i8).initCapacity(a, 200);
766 defer list.deinit(a);766 defer list.deinit(a);
767 testing.expect(list.items.len == 0);767 try testing.expect(list.items.len == 0);
768 testing.expect(list.capacity >= 200);768 try testing.expect(list.capacity >= 200);
769 }769 }
770}770}
771771
...@@ -785,33 +785,33 @@ test "std.ArrayList/ArrayListUnmanaged.basic" {...@@ -785,33 +785,33 @@ test "std.ArrayList/ArrayListUnmanaged.basic" {
785 {785 {
786 var i: usize = 0;786 var i: usize = 0;
787 while (i < 10) : (i += 1) {787 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));
789 }789 }
790 }790 }
791791
792 for (list.items) |v, i| {792 for (list.items) |v, i| {
793 testing.expect(v == @intCast(i32, i + 1));793 try testing.expect(v == @intCast(i32, i + 1));
794 }794 }
795795
796 testing.expect(list.pop() == 10);796 try testing.expect(list.pop() == 10);
797 testing.expect(list.items.len == 9);797 try testing.expect(list.items.len == 9);
798798
799 list.appendSlice(&[_]i32{ 1, 2, 3 }) catch unreachable;799 list.appendSlice(&[_]i32{ 1, 2, 3 }) catch unreachable;
800 testing.expect(list.items.len == 12);800 try testing.expect(list.items.len == 12);
801 testing.expect(list.pop() == 3);801 try testing.expect(list.pop() == 3);
802 testing.expect(list.pop() == 2);802 try testing.expect(list.pop() == 2);
803 testing.expect(list.pop() == 1);803 try testing.expect(list.pop() == 1);
804 testing.expect(list.items.len == 9);804 try testing.expect(list.items.len == 9);
805805
806 list.appendSlice(&[_]i32{}) catch unreachable;806 list.appendSlice(&[_]i32{}) catch unreachable;
807 testing.expect(list.items.len == 9);807 try testing.expect(list.items.len == 9);
808808
809 // can only set on indices < self.items.len809 // can only set on indices < self.items.len
810 list.items[7] = 33;810 list.items[7] = 33;
811 list.items[8] = 42;811 list.items[8] = 42;
812812
813 testing.expect(list.pop() == 42);813 try testing.expect(list.pop() == 42);
814 testing.expect(list.pop() == 33);814 try testing.expect(list.pop() == 33);
815 }815 }
816 {816 {
817 var list = ArrayListUnmanaged(i32){};817 var list = ArrayListUnmanaged(i32){};
...@@ -827,33 +827,33 @@ test "std.ArrayList/ArrayListUnmanaged.basic" {...@@ -827,33 +827,33 @@ test "std.ArrayList/ArrayListUnmanaged.basic" {
827 {827 {
828 var i: usize = 0;828 var i: usize = 0;
829 while (i < 10) : (i += 1) {829 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));
831 }831 }
832 }832 }
833833
834 for (list.items) |v, i| {834 for (list.items) |v, i| {
835 testing.expect(v == @intCast(i32, i + 1));835 try testing.expect(v == @intCast(i32, i + 1));
836 }836 }
837837
838 testing.expect(list.pop() == 10);838 try testing.expect(list.pop() == 10);
839 testing.expect(list.items.len == 9);839 try testing.expect(list.items.len == 9);
840840
841 list.appendSlice(a, &[_]i32{ 1, 2, 3 }) catch unreachable;841 list.appendSlice(a, &[_]i32{ 1, 2, 3 }) catch unreachable;
842 testing.expect(list.items.len == 12);842 try testing.expect(list.items.len == 12);
843 testing.expect(list.pop() == 3);843 try testing.expect(list.pop() == 3);
844 testing.expect(list.pop() == 2);844 try testing.expect(list.pop() == 2);
845 testing.expect(list.pop() == 1);845 try testing.expect(list.pop() == 1);
846 testing.expect(list.items.len == 9);846 try testing.expect(list.items.len == 9);
847847
848 list.appendSlice(a, &[_]i32{}) catch unreachable;848 list.appendSlice(a, &[_]i32{}) catch unreachable;
849 testing.expect(list.items.len == 9);849 try testing.expect(list.items.len == 9);
850850
851 // can only set on indices < self.items.len851 // can only set on indices < self.items.len
852 list.items[7] = 33;852 list.items[7] = 33;
853 list.items[8] = 42;853 list.items[8] = 42;
854854
855 testing.expect(list.pop() == 42);855 try testing.expect(list.pop() == 42);
856 testing.expect(list.pop() == 33);856 try testing.expect(list.pop() == 33);
857 }857 }
858}858}
859859
...@@ -864,9 +864,9 @@ test "std.ArrayList/ArrayListUnmanaged.appendNTimes" {...@@ -864,9 +864,9 @@ test "std.ArrayList/ArrayListUnmanaged.appendNTimes" {
864 defer list.deinit();864 defer list.deinit();
865865
866 try list.appendNTimes(2, 10);866 try list.appendNTimes(2, 10);
867 testing.expectEqual(@as(usize, 10), list.items.len);867 try testing.expectEqual(@as(usize, 10), list.items.len);
868 for (list.items) |element| {868 for (list.items) |element| {
869 testing.expectEqual(@as(i32, 2), element);869 try testing.expectEqual(@as(i32, 2), element);
870 }870 }
871 }871 }
872 {872 {
...@@ -874,9 +874,9 @@ test "std.ArrayList/ArrayListUnmanaged.appendNTimes" {...@@ -874,9 +874,9 @@ test "std.ArrayList/ArrayListUnmanaged.appendNTimes" {
874 defer list.deinit(a);874 defer list.deinit(a);
875875
876 try list.appendNTimes(a, 2, 10);876 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);
878 for (list.items) |element| {878 for (list.items) |element| {
879 testing.expectEqual(@as(i32, 2), element);879 try testing.expectEqual(@as(i32, 2), element);
880 }880 }
881 }881 }
882}882}
...@@ -886,12 +886,12 @@ test "std.ArrayList/ArrayListUnmanaged.appendNTimes with failing allocator" {...@@ -886,12 +886,12 @@ test "std.ArrayList/ArrayListUnmanaged.appendNTimes with failing allocator" {
886 {886 {
887 var list = ArrayList(i32).init(a);887 var list = ArrayList(i32).init(a);
888 defer list.deinit();888 defer list.deinit();
889 testing.expectError(error.OutOfMemory, list.appendNTimes(2, 10));889 try testing.expectError(error.OutOfMemory, list.appendNTimes(2, 10));
890 }890 }
891 {891 {
892 var list = ArrayListUnmanaged(i32){};892 var list = ArrayListUnmanaged(i32){};
893 defer list.deinit(a);893 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));
895 }895 }
896}896}
897897
...@@ -910,18 +910,18 @@ test "std.ArrayList/ArrayListUnmanaged.orderedRemove" {...@@ -910,18 +910,18 @@ test "std.ArrayList/ArrayListUnmanaged.orderedRemove" {
910 try list.append(7);910 try list.append(7);
911911
912 //remove from middle912 //remove from middle
913 testing.expectEqual(@as(i32, 4), list.orderedRemove(3));913 try testing.expectEqual(@as(i32, 4), list.orderedRemove(3));
914 testing.expectEqual(@as(i32, 5), list.items[3]);914 try testing.expectEqual(@as(i32, 5), list.items[3]);
915 testing.expectEqual(@as(usize, 6), list.items.len);915 try testing.expectEqual(@as(usize, 6), list.items.len);
916916
917 //remove from end917 //remove from end
918 testing.expectEqual(@as(i32, 7), list.orderedRemove(5));918 try testing.expectEqual(@as(i32, 7), list.orderedRemove(5));
919 testing.expectEqual(@as(usize, 5), list.items.len);919 try testing.expectEqual(@as(usize, 5), list.items.len);
920920
921 //remove from front921 //remove from front
922 testing.expectEqual(@as(i32, 1), list.orderedRemove(0));922 try testing.expectEqual(@as(i32, 1), list.orderedRemove(0));
923 testing.expectEqual(@as(i32, 2), list.items[0]);923 try testing.expectEqual(@as(i32, 2), list.items[0]);
924 testing.expectEqual(@as(usize, 4), list.items.len);924 try testing.expectEqual(@as(usize, 4), list.items.len);
925 }925 }
926 {926 {
927 var list = ArrayListUnmanaged(i32){};927 var list = ArrayListUnmanaged(i32){};
...@@ -936,18 +936,18 @@ test "std.ArrayList/ArrayListUnmanaged.orderedRemove" {...@@ -936,18 +936,18 @@ test "std.ArrayList/ArrayListUnmanaged.orderedRemove" {
936 try list.append(a, 7);936 try list.append(a, 7);
937937
938 //remove from middle938 //remove from middle
939 testing.expectEqual(@as(i32, 4), list.orderedRemove(3));939 try testing.expectEqual(@as(i32, 4), list.orderedRemove(3));
940 testing.expectEqual(@as(i32, 5), list.items[3]);940 try testing.expectEqual(@as(i32, 5), list.items[3]);
941 testing.expectEqual(@as(usize, 6), list.items.len);941 try testing.expectEqual(@as(usize, 6), list.items.len);
942942
943 //remove from end943 //remove from end
944 testing.expectEqual(@as(i32, 7), list.orderedRemove(5));944 try testing.expectEqual(@as(i32, 7), list.orderedRemove(5));
945 testing.expectEqual(@as(usize, 5), list.items.len);945 try testing.expectEqual(@as(usize, 5), list.items.len);
946946
947 //remove from front947 //remove from front
948 testing.expectEqual(@as(i32, 1), list.orderedRemove(0));948 try testing.expectEqual(@as(i32, 1), list.orderedRemove(0));
949 testing.expectEqual(@as(i32, 2), list.items[0]);949 try testing.expectEqual(@as(i32, 2), list.items[0]);
950 testing.expectEqual(@as(usize, 4), list.items.len);950 try testing.expectEqual(@as(usize, 4), list.items.len);
951 }951 }
952}952}
953953
...@@ -966,18 +966,18 @@ test "std.ArrayList/ArrayListUnmanaged.swapRemove" {...@@ -966,18 +966,18 @@ test "std.ArrayList/ArrayListUnmanaged.swapRemove" {
966 try list.append(7);966 try list.append(7);
967967
968 //remove from middle968 //remove from middle
969 testing.expect(list.swapRemove(3) == 4);969 try testing.expect(list.swapRemove(3) == 4);
970 testing.expect(list.items[3] == 7);970 try testing.expect(list.items[3] == 7);
971 testing.expect(list.items.len == 6);971 try testing.expect(list.items.len == 6);
972972
973 //remove from end973 //remove from end
974 testing.expect(list.swapRemove(5) == 6);974 try testing.expect(list.swapRemove(5) == 6);
975 testing.expect(list.items.len == 5);975 try testing.expect(list.items.len == 5);
976976
977 //remove from front977 //remove from front
978 testing.expect(list.swapRemove(0) == 1);978 try testing.expect(list.swapRemove(0) == 1);
979 testing.expect(list.items[0] == 5);979 try testing.expect(list.items[0] == 5);
980 testing.expect(list.items.len == 4);980 try testing.expect(list.items.len == 4);
981 }981 }
982 {982 {
983 var list = ArrayListUnmanaged(i32){};983 var list = ArrayListUnmanaged(i32){};
...@@ -992,18 +992,18 @@ test "std.ArrayList/ArrayListUnmanaged.swapRemove" {...@@ -992,18 +992,18 @@ test "std.ArrayList/ArrayListUnmanaged.swapRemove" {
992 try list.append(a, 7);992 try list.append(a, 7);
993993
994 //remove from middle994 //remove from middle
995 testing.expect(list.swapRemove(3) == 4);995 try testing.expect(list.swapRemove(3) == 4);
996 testing.expect(list.items[3] == 7);996 try testing.expect(list.items[3] == 7);
997 testing.expect(list.items.len == 6);997 try testing.expect(list.items.len == 6);
998998
999 //remove from end999 //remove from end
1000 testing.expect(list.swapRemove(5) == 6);1000 try testing.expect(list.swapRemove(5) == 6);
1001 testing.expect(list.items.len == 5);1001 try testing.expect(list.items.len == 5);
10021002
1003 //remove from front1003 //remove from front
1004 testing.expect(list.swapRemove(0) == 1);1004 try testing.expect(list.swapRemove(0) == 1);
1005 testing.expect(list.items[0] == 5);1005 try testing.expect(list.items[0] == 5);
1006 testing.expect(list.items.len == 4);1006 try testing.expect(list.items.len == 4);
1007 }1007 }
1008}1008}
10091009
...@@ -1017,10 +1017,10 @@ test "std.ArrayList/ArrayListUnmanaged.insert" {...@@ -1017,10 +1017,10 @@ test "std.ArrayList/ArrayListUnmanaged.insert" {
1017 try list.append(2);1017 try list.append(2);
1018 try list.append(3);1018 try list.append(3);
1019 try list.insert(0, 5);1019 try list.insert(0, 5);
1020 testing.expect(list.items[0] == 5);1020 try testing.expect(list.items[0] == 5);
1021 testing.expect(list.items[1] == 1);1021 try testing.expect(list.items[1] == 1);
1022 testing.expect(list.items[2] == 2);1022 try testing.expect(list.items[2] == 2);
1023 testing.expect(list.items[3] == 3);1023 try testing.expect(list.items[3] == 3);
1024 }1024 }
1025 {1025 {
1026 var list = ArrayListUnmanaged(i32){};1026 var list = ArrayListUnmanaged(i32){};
...@@ -1030,10 +1030,10 @@ test "std.ArrayList/ArrayListUnmanaged.insert" {...@@ -1030,10 +1030,10 @@ test "std.ArrayList/ArrayListUnmanaged.insert" {
1030 try list.append(a, 2);1030 try list.append(a, 2);
1031 try list.append(a, 3);1031 try list.append(a, 3);
1032 try list.insert(a, 0, 5);1032 try list.insert(a, 0, 5);
1033 testing.expect(list.items[0] == 5);1033 try testing.expect(list.items[0] == 5);
1034 testing.expect(list.items[1] == 1);1034 try testing.expect(list.items[1] == 1);
1035 testing.expect(list.items[2] == 2);1035 try testing.expect(list.items[2] == 2);
1036 testing.expect(list.items[3] == 3);1036 try testing.expect(list.items[3] == 3);
1037 }1037 }
1038}1038}
10391039
...@@ -1048,17 +1048,17 @@ test "std.ArrayList/ArrayListUnmanaged.insertSlice" {...@@ -1048,17 +1048,17 @@ test "std.ArrayList/ArrayListUnmanaged.insertSlice" {
1048 try list.append(3);1048 try list.append(3);
1049 try list.append(4);1049 try list.append(4);
1050 try list.insertSlice(1, &[_]i32{ 9, 8 });1050 try list.insertSlice(1, &[_]i32{ 9, 8 });
1051 testing.expect(list.items[0] == 1);1051 try testing.expect(list.items[0] == 1);
1052 testing.expect(list.items[1] == 9);1052 try testing.expect(list.items[1] == 9);
1053 testing.expect(list.items[2] == 8);1053 try testing.expect(list.items[2] == 8);
1054 testing.expect(list.items[3] == 2);1054 try testing.expect(list.items[3] == 2);
1055 testing.expect(list.items[4] == 3);1055 try testing.expect(list.items[4] == 3);
1056 testing.expect(list.items[5] == 4);1056 try testing.expect(list.items[5] == 4);
10571057
1058 const items = [_]i32{1};1058 const items = [_]i32{1};
1059 try list.insertSlice(0, items[0..0]);1059 try list.insertSlice(0, items[0..0]);
1060 testing.expect(list.items.len == 6);1060 try testing.expect(list.items.len == 6);
1061 testing.expect(list.items[0] == 1);1061 try testing.expect(list.items[0] == 1);
1062 }1062 }
1063 {1063 {
1064 var list = ArrayListUnmanaged(i32){};1064 var list = ArrayListUnmanaged(i32){};
...@@ -1069,17 +1069,17 @@ test "std.ArrayList/ArrayListUnmanaged.insertSlice" {...@@ -1069,17 +1069,17 @@ test "std.ArrayList/ArrayListUnmanaged.insertSlice" {
1069 try list.append(a, 3);1069 try list.append(a, 3);
1070 try list.append(a, 4);1070 try list.append(a, 4);
1071 try list.insertSlice(a, 1, &[_]i32{ 9, 8 });1071 try list.insertSlice(a, 1, &[_]i32{ 9, 8 });
1072 testing.expect(list.items[0] == 1);1072 try testing.expect(list.items[0] == 1);
1073 testing.expect(list.items[1] == 9);1073 try testing.expect(list.items[1] == 9);
1074 testing.expect(list.items[2] == 8);1074 try testing.expect(list.items[2] == 8);
1075 testing.expect(list.items[3] == 2);1075 try testing.expect(list.items[3] == 2);
1076 testing.expect(list.items[4] == 3);1076 try testing.expect(list.items[4] == 3);
1077 testing.expect(list.items[5] == 4);1077 try testing.expect(list.items[5] == 4);
10781078
1079 const items = [_]i32{1};1079 const items = [_]i32{1};
1080 try list.insertSlice(a, 0, items[0..0]);1080 try list.insertSlice(a, 0, items[0..0]);
1081 testing.expect(list.items.len == 6);1081 try testing.expect(list.items.len == 6);
1082 testing.expect(list.items[0] == 1);1082 try testing.expect(list.items[0] == 1);
1083 }1083 }
1084}1084}
10851085
...@@ -1112,13 +1112,13 @@ test "std.ArrayList/ArrayListUnmanaged.replaceRange" {...@@ -1112,13 +1112,13 @@ test "std.ArrayList/ArrayListUnmanaged.replaceRange" {
1112 try list_lt.replaceRange(1, 2, &new);1112 try list_lt.replaceRange(1, 2, &new);
11131113
1114 // after_range > new_items.len in function body1114 // after_range > new_items.len in function body
1115 testing.expect(1 + 4 > new.len);1115 try testing.expect(1 + 4 > new.len);
1116 try list_gt.replaceRange(1, 4, &new);1116 try list_gt.replaceRange(1, 4, &new);
11171117
1118 testing.expectEqualSlices(i32, list_zero.items, &result_zero);1118 try testing.expectEqualSlices(i32, list_zero.items, &result_zero);
1119 testing.expectEqualSlices(i32, list_eq.items, &result_eq);1119 try testing.expectEqualSlices(i32, list_eq.items, &result_eq);
1120 testing.expectEqualSlices(i32, list_lt.items, &result_le);1120 try testing.expectEqualSlices(i32, list_lt.items, &result_le);
1121 testing.expectEqualSlices(i32, list_gt.items, &result_gt);1121 try testing.expectEqualSlices(i32, list_gt.items, &result_gt);
1122 }1122 }
1123 {1123 {
1124 var list_zero = ArrayListUnmanaged(i32){};1124 var list_zero = ArrayListUnmanaged(i32){};
...@@ -1136,13 +1136,13 @@ test "std.ArrayList/ArrayListUnmanaged.replaceRange" {...@@ -1136,13 +1136,13 @@ test "std.ArrayList/ArrayListUnmanaged.replaceRange" {
1136 try list_lt.replaceRange(a, 1, 2, &new);1136 try list_lt.replaceRange(a, 1, 2, &new);
11371137
1138 // after_range > new_items.len in function body1138 // after_range > new_items.len in function body
1139 testing.expect(1 + 4 > new.len);1139 try testing.expect(1 + 4 > new.len);
1140 try list_gt.replaceRange(a, 1, 4, &new);1140 try list_gt.replaceRange(a, 1, 4, &new);
11411141
1142 testing.expectEqualSlices(i32, list_zero.items, &result_zero);1142 try testing.expectEqualSlices(i32, list_zero.items, &result_zero);
1143 testing.expectEqualSlices(i32, list_eq.items, &result_eq);1143 try testing.expectEqualSlices(i32, list_eq.items, &result_eq);
1144 testing.expectEqualSlices(i32, list_lt.items, &result_le);1144 try testing.expectEqualSlices(i32, list_lt.items, &result_le);
1145 testing.expectEqualSlices(i32, list_gt.items, &result_gt);1145 try testing.expectEqualSlices(i32, list_gt.items, &result_gt);
1146 }1146 }
1147}1147}
11481148
...@@ -1162,13 +1162,13 @@ test "std.ArrayList/ArrayListUnmanaged: ArrayList(T) of struct T" {...@@ -1162,13 +1162,13 @@ test "std.ArrayList/ArrayListUnmanaged: ArrayList(T) of struct T" {
1162 var root = Item{ .integer = 1, .sub_items = ArrayList(Item).init(a) };1162 var root = Item{ .integer = 1, .sub_items = ArrayList(Item).init(a) };
1163 defer root.sub_items.deinit();1163 defer root.sub_items.deinit();
1164 try root.sub_items.append(Item{ .integer = 42, .sub_items = ArrayList(Item).init(a) });1164 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);
1166 }1166 }
1167 {1167 {
1168 var root = ItemUnmanaged{ .integer = 1, .sub_items = ArrayListUnmanaged(ItemUnmanaged){} };1168 var root = ItemUnmanaged{ .integer = 1, .sub_items = ArrayListUnmanaged(ItemUnmanaged){} };
1169 defer root.sub_items.deinit(a);1169 defer root.sub_items.deinit(a);
1170 try root.sub_items.append(a, ItemUnmanaged{ .integer = 42, .sub_items = ArrayListUnmanaged(ItemUnmanaged){} });1170 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);
1172 }1172 }
1173}1173}
11741174
...@@ -1183,7 +1183,7 @@ test "std.ArrayList(u8)/ArrayListAligned implements writer" {...@@ -1183,7 +1183,7 @@ test "std.ArrayList(u8)/ArrayListAligned implements writer" {
1183 const y: i32 = 1234;1183 const y: i32 = 1234;
1184 try buffer.writer().print("x: {}\ny: {}\n", .{ x, y });1184 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);
1187 }1187 }
1188 {1188 {
1189 var list = ArrayListAligned(u8, 2).init(a);1189 var list = ArrayListAligned(u8, 2).init(a);
...@@ -1195,7 +1195,7 @@ test "std.ArrayList(u8)/ArrayListAligned implements writer" {...@@ -1195,7 +1195,7 @@ test "std.ArrayList(u8)/ArrayListAligned implements writer" {
1195 try writer.writeAll("d");1195 try writer.writeAll("d");
1196 try writer.writeAll("efg");1196 try writer.writeAll("efg");
11971197
1198 testing.expectEqualSlices(u8, list.items, "abcdefg");1198 try testing.expectEqualSlices(u8, list.items, "abcdefg");
1199 }1199 }
1200}1200}
12011201
...@@ -1213,7 +1213,7 @@ test "std.ArrayList/ArrayListUnmanaged.shrink still sets length on error.OutOfMe...@@ -1213,7 +1213,7 @@ test "std.ArrayList/ArrayListUnmanaged.shrink still sets length on error.OutOfMe
1213 try list.append(3);1213 try list.append(3);
12141214
1215 list.shrinkAndFree(1);1215 list.shrinkAndFree(1);
1216 testing.expect(list.items.len == 1);1216 try testing.expect(list.items.len == 1);
1217 }1217 }
1218 {1218 {
1219 var list = ArrayListUnmanaged(i32){};1219 var list = ArrayListUnmanaged(i32){};
...@@ -1223,7 +1223,7 @@ test "std.ArrayList/ArrayListUnmanaged.shrink still sets length on error.OutOfMe...@@ -1223,7 +1223,7 @@ test "std.ArrayList/ArrayListUnmanaged.shrink still sets length on error.OutOfMe
1223 try list.append(a, 3);1223 try list.append(a, 3);
12241224
1225 list.shrinkAndFree(a, 1);1225 list.shrinkAndFree(a, 1);
1226 testing.expect(list.items.len == 1);1226 try testing.expect(list.items.len == 1);
1227 }1227 }
1228}1228}
12291229
...@@ -1237,7 +1237,7 @@ test "std.ArrayList/ArrayListUnmanaged.addManyAsArray" {...@@ -1237,7 +1237,7 @@ test "std.ArrayList/ArrayListUnmanaged.addManyAsArray" {
1237 try list.ensureTotalCapacity(8);1237 try list.ensureTotalCapacity(8);
1238 list.addManyAsArrayAssumeCapacity(4).* = "asdf".*;1238 list.addManyAsArrayAssumeCapacity(4).* = "asdf".*;
12391239
1240 testing.expectEqualSlices(u8, list.items, "aoeuasdf");1240 try testing.expectEqualSlices(u8, list.items, "aoeuasdf");
1241 }1241 }
1242 {1242 {
1243 var list = ArrayListUnmanaged(u8){};1243 var list = ArrayListUnmanaged(u8){};
...@@ -1247,7 +1247,7 @@ test "std.ArrayList/ArrayListUnmanaged.addManyAsArray" {...@@ -1247,7 +1247,7 @@ test "std.ArrayList/ArrayListUnmanaged.addManyAsArray" {
1247 try list.ensureTotalCapacity(a, 8);1247 try list.ensureTotalCapacity(a, 8);
1248 list.addManyAsArrayAssumeCapacity(4).* = "asdf".*;1248 list.addManyAsArrayAssumeCapacity(4).* = "asdf".*;
12491249
1250 testing.expectEqualSlices(u8, list.items, "aoeuasdf");1250 try testing.expectEqualSlices(u8, list.items, "aoeuasdf");
1251 }1251 }
1252}1252}
12531253
...@@ -1261,7 +1261,7 @@ test "std.ArrayList/ArrayListUnmanaged.toOwnedSliceSentinel" {...@@ -1261,7 +1261,7 @@ test "std.ArrayList/ArrayListUnmanaged.toOwnedSliceSentinel" {
12611261
1262 const result = try list.toOwnedSliceSentinel(0);1262 const result = try list.toOwnedSliceSentinel(0);
1263 defer a.free(result);1263 defer a.free(result);
1264 testing.expectEqualStrings(result, mem.spanZ(result.ptr));1264 try testing.expectEqualStrings(result, mem.spanZ(result.ptr));
1265 }1265 }
1266 {1266 {
1267 var list = ArrayListUnmanaged(u8){};1267 var list = ArrayListUnmanaged(u8){};
...@@ -1271,7 +1271,7 @@ test "std.ArrayList/ArrayListUnmanaged.toOwnedSliceSentinel" {...@@ -1271,7 +1271,7 @@ test "std.ArrayList/ArrayListUnmanaged.toOwnedSliceSentinel" {
12711271
1272 const result = try list.toOwnedSliceSentinel(a, 0);1272 const result = try list.toOwnedSliceSentinel(a, 0);
1273 defer a.free(result);1273 defer a.free(result);
1274 testing.expectEqualStrings(result, mem.spanZ(result.ptr));1274 try testing.expectEqualStrings(result, mem.spanZ(result.ptr));
1275 }1275 }
1276}1276}
12771277
...@@ -1285,7 +1285,7 @@ test "ArrayListAligned/ArrayListAlignedUnmanaged accepts unaligned slices" {...@@ -1285,7 +1285,7 @@ test "ArrayListAligned/ArrayListAlignedUnmanaged accepts unaligned slices" {
1285 try list.insertSlice(2, &.{ 4, 5, 6, 7 });1285 try list.insertSlice(2, &.{ 4, 5, 6, 7 });
1286 try list.replaceRange(1, 3, &.{ 8, 9 });1286 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 });
1289 }1289 }
1290 {1290 {
1291 var list = std.ArrayListAlignedUnmanaged(u8, 8){};1291 var list = std.ArrayListAlignedUnmanaged(u8, 8){};
...@@ -1295,6 +1295,6 @@ test "ArrayListAligned/ArrayListAlignedUnmanaged accepts unaligned slices" {...@@ -1295,6 +1295,6 @@ test "ArrayListAligned/ArrayListAlignedUnmanaged accepts unaligned slices" {
1295 try list.insertSlice(a, 2, &.{ 4, 5, 6, 7 });1295 try list.insertSlice(a, 2, &.{ 4, 5, 6, 7 });
1296 try list.replaceRange(a, 1, 3, &.{ 8, 9 });1296 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 });
1299 }1299 }
1300}1300}
lib/std/ascii.zig+23-23
...@@ -236,11 +236,11 @@ pub const spaces = [_]u8{ ' ', '\t', '\n', '\r', control_code.VT, control_code.F...@@ -236,11 +236,11 @@ pub const spaces = [_]u8{ ' ', '\t', '\n', '\r', control_code.VT, control_code.F
236236
237test "spaces" {237test "spaces" {
238 const testing = std.testing;238 const testing = std.testing;
239 for (spaces) |space| testing.expect(isSpace(space));239 for (spaces) |space| try testing.expect(isSpace(space));
240240
241 var i: u8 = 0;241 var i: u8 = 0;
242 while (isASCII(i)) : (i += 1) {242 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);
244 }244 }
245}245}
246246
...@@ -279,13 +279,13 @@ pub fn toLower(c: u8) u8 {...@@ -279,13 +279,13 @@ pub fn toLower(c: u8) u8 {
279test "ascii character classes" {279test "ascii character classes" {
280 const testing = std.testing;280 const testing = std.testing;
281281
282 testing.expect('C' == toUpper('c'));282 try testing.expect('C' == toUpper('c'));
283 testing.expect(':' == toUpper(':'));283 try testing.expect(':' == toUpper(':'));
284 testing.expect('\xab' == toUpper('\xab'));284 try testing.expect('\xab' == toUpper('\xab'));
285 testing.expect('c' == toLower('C'));285 try testing.expect('c' == toLower('C'));
286 testing.expect(isAlpha('c'));286 try testing.expect(isAlpha('c'));
287 testing.expect(!isAlpha('5'));287 try testing.expect(!isAlpha('5'));
288 testing.expect(isSpace(' '));288 try testing.expect(isSpace(' '));
289}289}
290290
291/// Allocates a lower case copy of `ascii_string`.291/// Allocates a lower case copy of `ascii_string`.
...@@ -301,7 +301,7 @@ pub fn allocLowerString(allocator: *std.mem.Allocator, ascii_string: []const u8)...@@ -301,7 +301,7 @@ pub fn allocLowerString(allocator: *std.mem.Allocator, ascii_string: []const u8)
301test "allocLowerString" {301test "allocLowerString" {
302 const result = try allocLowerString(std.testing.allocator, "aBcDeFgHiJkLmNOPqrst0234+💩!");302 const result = try allocLowerString(std.testing.allocator, "aBcDeFgHiJkLmNOPqrst0234+💩!");
303 defer std.testing.allocator.free(result);303 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));
305}305}
306306
307/// Allocates an upper case copy of `ascii_string`.307/// Allocates an upper case copy of `ascii_string`.
...@@ -317,7 +317,7 @@ pub fn allocUpperString(allocator: *std.mem.Allocator, ascii_string: []const u8)...@@ -317,7 +317,7 @@ pub fn allocUpperString(allocator: *std.mem.Allocator, ascii_string: []const u8)
317test "allocUpperString" {317test "allocUpperString" {
318 const result = try allocUpperString(std.testing.allocator, "aBcDeFgHiJkLmNOPqrst0234+💩!");318 const result = try allocUpperString(std.testing.allocator, "aBcDeFgHiJkLmNOPqrst0234+💩!");
319 defer std.testing.allocator.free(result);319 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));
321}321}
322322
323/// Compares strings `a` and `b` case insensitively and returns whether they are equal.323/// 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 {...@@ -330,9 +330,9 @@ pub fn eqlIgnoreCase(a: []const u8, b: []const u8) bool {
330}330}
331331
332test "eqlIgnoreCase" {332test "eqlIgnoreCase" {
333 std.testing.expect(eqlIgnoreCase("HEl💩Lo!", "hel💩lo!"));333 try std.testing.expect(eqlIgnoreCase("HEl💩Lo!", "hel💩lo!"));
334 std.testing.expect(!eqlIgnoreCase("hElLo!", "hello! "));334 try std.testing.expect(!eqlIgnoreCase("hElLo!", "hello! "));
335 std.testing.expect(!eqlIgnoreCase("hElLo!", "helro!"));335 try std.testing.expect(!eqlIgnoreCase("hElLo!", "helro!"));
336}336}
337337
338pub fn startsWithIgnoreCase(haystack: []const u8, needle: []const u8) bool {338pub fn startsWithIgnoreCase(haystack: []const u8, needle: []const u8) bool {
...@@ -340,8 +340,8 @@ pub fn startsWithIgnoreCase(haystack: []const u8, needle: []const u8) bool {...@@ -340,8 +340,8 @@ pub fn startsWithIgnoreCase(haystack: []const u8, needle: []const u8) bool {
340}340}
341341
342test "ascii.startsWithIgnoreCase" {342test "ascii.startsWithIgnoreCase" {
343 std.testing.expect(startsWithIgnoreCase("boB", "Bo"));343 try std.testing.expect(startsWithIgnoreCase("boB", "Bo"));
344 std.testing.expect(!startsWithIgnoreCase("Needle in hAyStAcK", "haystack"));344 try std.testing.expect(!startsWithIgnoreCase("Needle in hAyStAcK", "haystack"));
345}345}
346346
347pub fn endsWithIgnoreCase(haystack: []const u8, needle: []const u8) bool {347pub fn endsWithIgnoreCase(haystack: []const u8, needle: []const u8) bool {
...@@ -349,8 +349,8 @@ pub fn endsWithIgnoreCase(haystack: []const u8, needle: []const u8) bool {...@@ -349,8 +349,8 @@ pub fn endsWithIgnoreCase(haystack: []const u8, needle: []const u8) bool {
349}349}
350350
351test "ascii.endsWithIgnoreCase" {351test "ascii.endsWithIgnoreCase" {
352 std.testing.expect(endsWithIgnoreCase("Needle in HaYsTaCk", "haystack"));352 try std.testing.expect(endsWithIgnoreCase("Needle in HaYsTaCk", "haystack"));
353 std.testing.expect(!endsWithIgnoreCase("BoB", "Bo"));353 try std.testing.expect(!endsWithIgnoreCase("BoB", "Bo"));
354}354}
355355
356/// Finds `substr` in `container`, ignoring case, starting at `start_index`.356/// Finds `substr` in `container`, ignoring case, starting at `start_index`.
...@@ -372,12 +372,12 @@ pub fn indexOfIgnoreCase(container: []const u8, substr: []const u8) ?usize {...@@ -372,12 +372,12 @@ pub fn indexOfIgnoreCase(container: []const u8, substr: []const u8) ?usize {
372}372}
373373
374test "indexOfIgnoreCase" {374test "indexOfIgnoreCase" {
375 std.testing.expect(indexOfIgnoreCase("one Two Three Four", "foUr").? == 14);375 try std.testing.expect(indexOfIgnoreCase("one Two Three Four", "foUr").? == 14);
376 std.testing.expect(indexOfIgnoreCase("one two three FouR", "gOur") == null);376 try std.testing.expect(indexOfIgnoreCase("one two three FouR", "gOur") == null);
377 std.testing.expect(indexOfIgnoreCase("foO", "Foo").? == 0);377 try std.testing.expect(indexOfIgnoreCase("foO", "Foo").? == 0);
378 std.testing.expect(indexOfIgnoreCase("foo", "fool") == null);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);
381}381}
382382
383/// Compares two slices of numbers lexicographically. O(n).383/// Compares two slices of numbers lexicographically. O(n).
lib/std/atomic/bool.zig+4-4
...@@ -47,9 +47,9 @@ pub const Bool = extern struct {...@@ -47,9 +47,9 @@ pub const Bool = extern struct {
4747
48test "std.atomic.Bool" {48test "std.atomic.Bool" {
49 var a = Bool.init(false);49 var a = Bool.init(false);
50 testing.expectEqual(false, a.xchg(false, .SeqCst));50 try testing.expectEqual(false, a.xchg(false, .SeqCst));
51 testing.expectEqual(false, a.load(.SeqCst));51 try testing.expectEqual(false, a.load(.SeqCst));
52 a.store(true, .SeqCst);52 a.store(true, .SeqCst);
53 testing.expectEqual(true, a.xchg(false, .SeqCst));53 try testing.expectEqual(true, a.xchg(false, .SeqCst));
54 testing.expectEqual(false, a.load(.SeqCst));54 try testing.expectEqual(false, a.load(.SeqCst));
55}55}
lib/std/atomic/int.zig+6-6
...@@ -81,12 +81,12 @@ pub fn Int(comptime T: type) type {...@@ -81,12 +81,12 @@ pub fn Int(comptime T: type) type {
8181
82test "std.atomic.Int" {82test "std.atomic.Int" {
83 var a = Int(u8).init(0);83 var a = Int(u8).init(0);
84 testing.expectEqual(@as(u8, 0), a.incr());84 try testing.expectEqual(@as(u8, 0), a.incr());
85 testing.expectEqual(@as(u8, 1), a.load(.SeqCst));85 try testing.expectEqual(@as(u8, 1), a.load(.SeqCst));
86 a.store(42, .SeqCst);86 a.store(42, .SeqCst);
87 testing.expectEqual(@as(u8, 42), a.decr());87 try testing.expectEqual(@as(u8, 42), a.decr());
88 testing.expectEqual(@as(u8, 41), a.xchg(100));88 try testing.expectEqual(@as(u8, 41), a.xchg(100));
89 testing.expectEqual(@as(u8, 100), a.fetchAdd(5));89 try testing.expectEqual(@as(u8, 100), a.fetchAdd(5));
90 testing.expectEqual(@as(u8, 105), a.get());90 try testing.expectEqual(@as(u8, 105), a.get());
91 a.set(200);91 a.set(200);
92}92}
lib/std/atomic/queue.zig+28-28
...@@ -195,24 +195,24 @@ test "std.atomic.Queue" {...@@ -195,24 +195,24 @@ test "std.atomic.Queue" {
195 };195 };
196196
197 if (builtin.single_threaded) {197 if (builtin.single_threaded) {
198 expect(context.queue.isEmpty());198 try expect(context.queue.isEmpty());
199 {199 {
200 var i: usize = 0;200 var i: usize = 0;
201 while (i < put_thread_count) : (i += 1) {201 while (i < put_thread_count) : (i += 1) {
202 expect(startPuts(&context) == 0);202 try expect(startPuts(&context) == 0);
203 }203 }
204 }204 }
205 expect(!context.queue.isEmpty());205 try expect(!context.queue.isEmpty());
206 context.puts_done = true;206 context.puts_done = true;
207 {207 {
208 var i: usize = 0;208 var i: usize = 0;
209 while (i < put_thread_count) : (i += 1) {209 while (i < put_thread_count) : (i += 1) {
210 expect(startGets(&context) == 0);210 try expect(startGets(&context) == 0);
211 }211 }
212 }212 }
213 expect(context.queue.isEmpty());213 try expect(context.queue.isEmpty());
214 } else {214 } else {
215 expect(context.queue.isEmpty());215 try expect(context.queue.isEmpty());
216216
217 var putters: [put_thread_count]*std.Thread = undefined;217 var putters: [put_thread_count]*std.Thread = undefined;
218 for (putters) |*t| {218 for (putters) |*t| {
...@@ -229,7 +229,7 @@ test "std.atomic.Queue" {...@@ -229,7 +229,7 @@ test "std.atomic.Queue" {
229 for (getters) |t|229 for (getters) |t|
230 t.wait();230 t.wait();
231231
232 expect(context.queue.isEmpty());232 try expect(context.queue.isEmpty());
233 }233 }
234234
235 if (context.put_sum != context.get_sum) {235 if (context.put_sum != context.get_sum) {
...@@ -279,7 +279,7 @@ fn startGets(ctx: *Context) u8 {...@@ -279,7 +279,7 @@ fn startGets(ctx: *Context) u8 {
279279
280test "std.atomic.Queue single-threaded" {280test "std.atomic.Queue single-threaded" {
281 var queue = Queue(i32).init();281 var queue = Queue(i32).init();
282 expect(queue.isEmpty());282 try expect(queue.isEmpty());
283283
284 var node_0 = Queue(i32).Node{284 var node_0 = Queue(i32).Node{
285 .data = 0,285 .data = 0,
...@@ -287,7 +287,7 @@ test "std.atomic.Queue single-threaded" {...@@ -287,7 +287,7 @@ test "std.atomic.Queue single-threaded" {
287 .prev = undefined,287 .prev = undefined,
288 };288 };
289 queue.put(&node_0);289 queue.put(&node_0);
290 expect(!queue.isEmpty());290 try expect(!queue.isEmpty());
291291
292 var node_1 = Queue(i32).Node{292 var node_1 = Queue(i32).Node{
293 .data = 1,293 .data = 1,
...@@ -295,10 +295,10 @@ test "std.atomic.Queue single-threaded" {...@@ -295,10 +295,10 @@ test "std.atomic.Queue single-threaded" {
295 .prev = undefined,295 .prev = undefined,
296 };296 };
297 queue.put(&node_1);297 queue.put(&node_1);
298 expect(!queue.isEmpty());298 try expect(!queue.isEmpty());
299299
300 expect(queue.get().?.data == 0);300 try expect(queue.get().?.data == 0);
301 expect(!queue.isEmpty());301 try expect(!queue.isEmpty());
302302
303 var node_2 = Queue(i32).Node{303 var node_2 = Queue(i32).Node{
304 .data = 2,304 .data = 2,
...@@ -306,7 +306,7 @@ test "std.atomic.Queue single-threaded" {...@@ -306,7 +306,7 @@ test "std.atomic.Queue single-threaded" {
306 .prev = undefined,306 .prev = undefined,
307 };307 };
308 queue.put(&node_2);308 queue.put(&node_2);
309 expect(!queue.isEmpty());309 try expect(!queue.isEmpty());
310310
311 var node_3 = Queue(i32).Node{311 var node_3 = Queue(i32).Node{
312 .data = 3,312 .data = 3,
...@@ -314,13 +314,13 @@ test "std.atomic.Queue single-threaded" {...@@ -314,13 +314,13 @@ test "std.atomic.Queue single-threaded" {
314 .prev = undefined,314 .prev = undefined,
315 };315 };
316 queue.put(&node_3);316 queue.put(&node_3);
317 expect(!queue.isEmpty());317 try expect(!queue.isEmpty());
318318
319 expect(queue.get().?.data == 1);319 try expect(queue.get().?.data == 1);
320 expect(!queue.isEmpty());320 try expect(!queue.isEmpty());
321321
322 expect(queue.get().?.data == 2);322 try expect(queue.get().?.data == 2);
323 expect(!queue.isEmpty());323 try expect(!queue.isEmpty());
324324
325 var node_4 = Queue(i32).Node{325 var node_4 = Queue(i32).Node{
326 .data = 4,326 .data = 4,
...@@ -328,17 +328,17 @@ test "std.atomic.Queue single-threaded" {...@@ -328,17 +328,17 @@ test "std.atomic.Queue single-threaded" {
328 .prev = undefined,328 .prev = undefined,
329 };329 };
330 queue.put(&node_4);330 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);
334 node_3.next = null;334 node_3.next = null;
335 expect(!queue.isEmpty());335 try expect(!queue.isEmpty());
336336
337 expect(queue.get().?.data == 4);337 try expect(queue.get().?.data == 4);
338 expect(queue.isEmpty());338 try expect(queue.isEmpty());
339339
340 expect(queue.get() == null);340 try expect(queue.get() == null);
341 expect(queue.isEmpty());341 try expect(queue.isEmpty());
342}342}
343343
344test "std.atomic.Queue dump" {344test "std.atomic.Queue dump" {
...@@ -352,7 +352,7 @@ test "std.atomic.Queue dump" {...@@ -352,7 +352,7 @@ test "std.atomic.Queue dump" {
352 // Test empty stream352 // Test empty stream
353 fbs.reset();353 fbs.reset();
354 try queue.dumpToStream(fbs.writer());354 try queue.dumpToStream(fbs.writer());
355 expect(mem.eql(u8, buffer[0..fbs.pos],355 try expect(mem.eql(u8, buffer[0..fbs.pos],
356 \\head: (null)356 \\head: (null)
357 \\tail: (null)357 \\tail: (null)
358 \\358 \\
...@@ -376,7 +376,7 @@ test "std.atomic.Queue dump" {...@@ -376,7 +376,7 @@ test "std.atomic.Queue dump" {
376 \\ (null)376 \\ (null)
377 \\377 \\
378 , .{ @ptrToInt(queue.head), @ptrToInt(queue.tail) });378 , .{ @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
381 // Test a stream with two elements381 // Test a stream with two elements
382 var node_1 = Queue(i32).Node{382 var node_1 = Queue(i32).Node{
...@@ -397,5 +397,5 @@ test "std.atomic.Queue dump" {...@@ -397,5 +397,5 @@ test "std.atomic.Queue dump" {
397 \\ (null)397 \\ (null)
398 \\398 \\
399 , .{ @ptrToInt(queue.head), @ptrToInt(queue.head.?.next), @ptrToInt(queue.tail) });399 , .{ @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));
401}401}
lib/std/atomic/stack.zig+2-2
...@@ -110,14 +110,14 @@ test "std.atomic.stack" {...@@ -110,14 +110,14 @@ test "std.atomic.stack" {
110 {110 {
111 var i: usize = 0;111 var i: usize = 0;
112 while (i < put_thread_count) : (i += 1) {112 while (i < put_thread_count) : (i += 1) {
113 expect(startPuts(&context) == 0);113 try expect(startPuts(&context) == 0);
114 }114 }
115 }115 }
116 context.puts_done = true;116 context.puts_done = true;
117 {117 {
118 var i: usize = 0;118 var i: usize = 0;
119 while (i < put_thread_count) : (i += 1) {119 while (i < put_thread_count) : (i += 1) {
120 expect(startGets(&context) == 0);120 try expect(startGets(&context) == 0);
121 }121 }
122 }122 }
123 } else {123 } else {
lib/std/base64.zig+9-9
...@@ -318,14 +318,14 @@ pub const Base64DecoderWithIgnore = struct {...@@ -318,14 +318,14 @@ pub const Base64DecoderWithIgnore = struct {
318318
319test "base64" {319test "base64" {
320 @setEvalBranchQuota(8000);320 @setEvalBranchQuota(8000);
321 testBase64() catch unreachable;321 try testBase64();
322 comptime testAllApis(standard, "comptime", "Y29tcHRpbWU=") catch unreachable;322 comptime try testAllApis(standard, "comptime", "Y29tcHRpbWU=");
323}323}
324324
325test "base64 url_safe_no_pad" {325test "base64 url_safe_no_pad" {
326 @setEvalBranchQuota(8000);326 @setEvalBranchQuota(8000);
327 testBase64UrlSafeNoPad() catch unreachable;327 try testBase64UrlSafeNoPad();
328 comptime testAllApis(url_safe_no_pad, "comptime", "Y29tcHRpbWU") catch unreachable;328 comptime try testAllApis(url_safe_no_pad, "comptime", "Y29tcHRpbWU");
329}329}
330330
331fn testBase64() !void {331fn testBase64() !void {
...@@ -404,7 +404,7 @@ fn testAllApis(codecs: Codecs, expected_decoded: []const u8, expected_encoded: [...@@ -404,7 +404,7 @@ fn testAllApis(codecs: Codecs, expected_decoded: []const u8, expected_encoded: [
404 {404 {
405 var buffer: [0x100]u8 = undefined;405 var buffer: [0x100]u8 = undefined;
406 const encoded = codecs.Encoder.encode(&buffer, expected_decoded);406 const encoded = codecs.Encoder.encode(&buffer, expected_decoded);
407 testing.expectEqualSlices(u8, expected_encoded, encoded);407 try testing.expectEqualSlices(u8, expected_encoded, encoded);
408 }408 }
409409
410 // Base64Decoder410 // Base64Decoder
...@@ -412,7 +412,7 @@ fn testAllApis(codecs: Codecs, expected_decoded: []const u8, expected_encoded: [...@@ -412,7 +412,7 @@ fn testAllApis(codecs: Codecs, expected_decoded: []const u8, expected_encoded: [
412 var buffer: [0x100]u8 = undefined;412 var buffer: [0x100]u8 = undefined;
413 var decoded = buffer[0..try codecs.Decoder.calcSizeForSlice(expected_encoded)];413 var decoded = buffer[0..try codecs.Decoder.calcSizeForSlice(expected_encoded)];
414 try codecs.Decoder.decode(decoded, expected_encoded);414 try codecs.Decoder.decode(decoded, expected_encoded);
415 testing.expectEqualSlices(u8, expected_decoded, decoded);415 try testing.expectEqualSlices(u8, expected_decoded, decoded);
416 }416 }
417417
418 // Base64DecoderWithIgnore418 // Base64DecoderWithIgnore
...@@ -421,8 +421,8 @@ fn testAllApis(codecs: Codecs, expected_decoded: []const u8, expected_encoded: [...@@ -421,8 +421,8 @@ fn testAllApis(codecs: Codecs, expected_decoded: []const u8, expected_encoded: [
421 var buffer: [0x100]u8 = undefined;421 var buffer: [0x100]u8 = undefined;
422 var decoded = buffer[0..try decoder_ignore_nothing.calcSizeUpperBound(expected_encoded.len)];422 var decoded = buffer[0..try decoder_ignore_nothing.calcSizeUpperBound(expected_encoded.len)];
423 var written = try decoder_ignore_nothing.decode(decoded, expected_encoded);423 var written = try decoder_ignore_nothing.decode(decoded, expected_encoded);
424 testing.expect(written <= decoded.len);424 try testing.expect(written <= decoded.len);
425 testing.expectEqualSlices(u8, expected_decoded, decoded[0..written]);425 try testing.expectEqualSlices(u8, expected_decoded, decoded[0..written]);
426 }426 }
427}427}
428428
...@@ -431,7 +431,7 @@ fn testDecodeIgnoreSpace(codecs: Codecs, expected_decoded: []const u8, encoded:...@@ -431,7 +431,7 @@ fn testDecodeIgnoreSpace(codecs: Codecs, expected_decoded: []const u8, encoded:
431 var buffer: [0x100]u8 = undefined;431 var buffer: [0x100]u8 = undefined;
432 var decoded = buffer[0..try decoder_ignore_space.calcSizeUpperBound(encoded.len)];432 var decoded = buffer[0..try decoder_ignore_space.calcSizeUpperBound(encoded.len)];
433 var written = try decoder_ignore_space.decode(decoded, encoded);433 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]);
435}435}
436436
437fn testError(codecs: Codecs, encoded: []const u8, expected_err: anyerror) !void {437fn 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...@@ -998,9 +998,9 @@ fn BitSetIterator(comptime MaskInt: type, comptime options: IteratorOptions) typ
998998
999const testing = std.testing;999const testing = std.testing;
10001000
1001fn testBitSet(a: anytype, b: anytype, len: usize) void {1001fn testBitSet(a: anytype, b: anytype, len: usize) !void {
1002 testing.expectEqual(len, a.capacity());1002 try testing.expectEqual(len, a.capacity());
1003 testing.expectEqual(len, b.capacity());1003 try testing.expectEqual(len, b.capacity());
10041004
1005 {1005 {
1006 var i: usize = 0;1006 var i: usize = 0;
...@@ -1010,50 +1010,50 @@ fn testBitSet(a: anytype, b: anytype, len: usize) void {...@@ -1010,50 +1010,50 @@ fn testBitSet(a: anytype, b: anytype, len: usize) void {
1010 }1010 }
1011 }1011 }
10121012
1013 testing.expectEqual((len + 1) / 2, a.count());1013 try testing.expectEqual((len + 1) / 2, a.count());
1014 testing.expectEqual((len + 3) / 4 + (len + 2) / 4, b.count());1014 try testing.expectEqual((len + 3) / 4 + (len + 2) / 4, b.count());
10151015
1016 {1016 {
1017 var iter = a.iterator(.{});1017 var iter = a.iterator(.{});
1018 var i: usize = 0;1018 var i: usize = 0;
1019 while (i < len) : (i += 2) {1019 while (i < len) : (i += 2) {
1020 testing.expectEqual(@as(?usize, i), iter.next());1020 try testing.expectEqual(@as(?usize, i), iter.next());
1021 }1021 }
1022 testing.expectEqual(@as(?usize, null), iter.next());1022 try testing.expectEqual(@as(?usize, null), iter.next());
1023 testing.expectEqual(@as(?usize, null), iter.next());1023 try testing.expectEqual(@as(?usize, null), iter.next());
1024 testing.expectEqual(@as(?usize, null), iter.next());1024 try testing.expectEqual(@as(?usize, null), iter.next());
1025 }1025 }
1026 a.toggleAll();1026 a.toggleAll();
1027 {1027 {
1028 var iter = a.iterator(.{});1028 var iter = a.iterator(.{});
1029 var i: usize = 1;1029 var i: usize = 1;
1030 while (i < len) : (i += 2) {1030 while (i < len) : (i += 2) {
1031 testing.expectEqual(@as(?usize, i), iter.next());1031 try testing.expectEqual(@as(?usize, i), iter.next());
1032 }1032 }
1033 testing.expectEqual(@as(?usize, null), iter.next());1033 try testing.expectEqual(@as(?usize, null), iter.next());
1034 testing.expectEqual(@as(?usize, null), iter.next());1034 try testing.expectEqual(@as(?usize, null), iter.next());
1035 testing.expectEqual(@as(?usize, null), iter.next());1035 try testing.expectEqual(@as(?usize, null), iter.next());
1036 }1036 }
10371037
1038 {1038 {
1039 var iter = b.iterator(.{ .kind = .unset });1039 var iter = b.iterator(.{ .kind = .unset });
1040 var i: usize = 2;1040 var i: usize = 2;
1041 while (i < len) : (i += 4) {1041 while (i < len) : (i += 4) {
1042 testing.expectEqual(@as(?usize, i), iter.next());1042 try testing.expectEqual(@as(?usize, i), iter.next());
1043 if (i + 1 < len) {1043 if (i + 1 < len) {
1044 testing.expectEqual(@as(?usize, i + 1), iter.next());1044 try testing.expectEqual(@as(?usize, i + 1), iter.next());
1045 }1045 }
1046 }1046 }
1047 testing.expectEqual(@as(?usize, null), iter.next());1047 try testing.expectEqual(@as(?usize, null), iter.next());
1048 testing.expectEqual(@as(?usize, null), iter.next());1048 try testing.expectEqual(@as(?usize, null), iter.next());
1049 testing.expectEqual(@as(?usize, null), iter.next());1049 try testing.expectEqual(@as(?usize, null), iter.next());
1050 }1050 }
10511051
1052 {1052 {
1053 var i: usize = 0;1053 var i: usize = 0;
1054 while (i < len) : (i += 1) {1054 while (i < len) : (i += 1) {
1055 testing.expectEqual(i & 1 != 0, a.isSet(i));1055 try testing.expectEqual(i & 1 != 0, a.isSet(i));
1056 testing.expectEqual(i & 2 == 0, b.isSet(i));1056 try testing.expectEqual(i & 2 == 0, b.isSet(i));
1057 }1057 }
1058 }1058 }
10591059
...@@ -1061,8 +1061,8 @@ fn testBitSet(a: anytype, b: anytype, len: usize) void {...@@ -1061,8 +1061,8 @@ fn testBitSet(a: anytype, b: anytype, len: usize) void {
1061 {1061 {
1062 var i: usize = 0;1062 var i: usize = 0;
1063 while (i < len) : (i += 1) {1063 while (i < len) : (i += 1) {
1064 testing.expectEqual(i & 1 != 0 or i & 2 == 0, a.isSet(i));1064 try testing.expectEqual(i & 1 != 0 or i & 2 == 0, a.isSet(i));
1065 testing.expectEqual(i & 2 == 0, b.isSet(i));1065 try testing.expectEqual(i & 2 == 0, b.isSet(i));
1066 }1066 }
10671067
1068 i = len;1068 i = len;
...@@ -1071,27 +1071,27 @@ fn testBitSet(a: anytype, b: anytype, len: usize) void {...@@ -1071,27 +1071,27 @@ fn testBitSet(a: anytype, b: anytype, len: usize) void {
1071 while (i > 0) {1071 while (i > 0) {
1072 i -= 1;1072 i -= 1;
1073 if (i & 1 != 0 or i & 2 == 0) {1073 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());
1075 } else {1075 } else {
1076 testing.expectEqual(@as(?usize, i), unset.next());1076 try testing.expectEqual(@as(?usize, i), unset.next());
1077 }1077 }
1078 }1078 }
1079 testing.expectEqual(@as(?usize, null), set.next());1079 try testing.expectEqual(@as(?usize, null), set.next());
1080 testing.expectEqual(@as(?usize, null), set.next());1080 try testing.expectEqual(@as(?usize, null), set.next());
1081 testing.expectEqual(@as(?usize, null), set.next());1081 try testing.expectEqual(@as(?usize, null), set.next());
1082 testing.expectEqual(@as(?usize, null), unset.next());1082 try testing.expectEqual(@as(?usize, null), unset.next());
1083 testing.expectEqual(@as(?usize, null), unset.next());1083 try testing.expectEqual(@as(?usize, null), unset.next());
1084 testing.expectEqual(@as(?usize, null), unset.next());1084 try testing.expectEqual(@as(?usize, null), unset.next());
1085 }1085 }
10861086
1087 a.toggleSet(b.*);1087 a.toggleSet(b.*);
1088 {1088 {
1089 testing.expectEqual(len / 4, a.count());1089 try testing.expectEqual(len / 4, a.count());
10901090
1091 var i: usize = 0;1091 var i: usize = 0;
1092 while (i < len) : (i += 1) {1092 while (i < len) : (i += 1) {
1093 testing.expectEqual(i & 1 != 0 and i & 2 != 0, a.isSet(i));1093 try testing.expectEqual(i & 1 != 0 and i & 2 != 0, a.isSet(i));
1094 testing.expectEqual(i & 2 == 0, b.isSet(i));1094 try testing.expectEqual(i & 2 == 0, b.isSet(i));
1095 if (i & 1 == 0) {1095 if (i & 1 == 0) {
1096 a.set(i);1096 a.set(i);
1097 } else {1097 } else {
...@@ -1102,29 +1102,29 @@ fn testBitSet(a: anytype, b: anytype, len: usize) void {...@@ -1102,29 +1102,29 @@ fn testBitSet(a: anytype, b: anytype, len: usize) void {
11021102
1103 a.setIntersection(b.*);1103 a.setIntersection(b.*);
1104 {1104 {
1105 testing.expectEqual((len + 3) / 4, a.count());1105 try testing.expectEqual((len + 3) / 4, a.count());
11061106
1107 var i: usize = 0;1107 var i: usize = 0;
1108 while (i < len) : (i += 1) {1108 while (i < len) : (i += 1) {
1109 testing.expectEqual(i & 1 == 0 and i & 2 == 0, a.isSet(i));1109 try testing.expectEqual(i & 1 == 0 and i & 2 == 0, a.isSet(i));
1110 testing.expectEqual(i & 2 == 0, b.isSet(i));1110 try testing.expectEqual(i & 2 == 0, b.isSet(i));
1111 }1111 }
1112 }1112 }
11131113
1114 a.toggleSet(a.*);1114 a.toggleSet(a.*);
1115 {1115 {
1116 var iter = a.iterator(.{});1116 var iter = a.iterator(.{});
1117 testing.expectEqual(@as(?usize, null), iter.next());1117 try testing.expectEqual(@as(?usize, null), iter.next());
1118 testing.expectEqual(@as(?usize, null), iter.next());1118 try testing.expectEqual(@as(?usize, null), iter.next());
1119 testing.expectEqual(@as(?usize, null), iter.next());1119 try testing.expectEqual(@as(?usize, null), iter.next());
1120 testing.expectEqual(@as(usize, 0), a.count());1120 try testing.expectEqual(@as(usize, 0), a.count());
1121 }1121 }
1122 {1122 {
1123 var iter = a.iterator(.{ .direction = .reverse });1123 var iter = a.iterator(.{ .direction = .reverse });
1124 testing.expectEqual(@as(?usize, null), iter.next());1124 try testing.expectEqual(@as(?usize, null), iter.next());
1125 testing.expectEqual(@as(?usize, null), iter.next());1125 try testing.expectEqual(@as(?usize, null), iter.next());
1126 testing.expectEqual(@as(?usize, null), iter.next());1126 try testing.expectEqual(@as(?usize, null), iter.next());
1127 testing.expectEqual(@as(usize, 0), a.count());1127 try testing.expectEqual(@as(usize, 0), a.count());
1128 }1128 }
11291129
1130 const test_bits = [_]usize{1130 const test_bits = [_]usize{
...@@ -1139,51 +1139,51 @@ fn testBitSet(a: anytype, b: anytype, len: usize) void {...@@ -1139,51 +1139,51 @@ fn testBitSet(a: anytype, b: anytype, len: usize) void {
11391139
1140 for (test_bits) |i| {1140 for (test_bits) |i| {
1141 if (i < a.capacity()) {1141 if (i < a.capacity()) {
1142 testing.expectEqual(@as(?usize, i), a.findFirstSet());1142 try testing.expectEqual(@as(?usize, i), a.findFirstSet());
1143 testing.expectEqual(@as(?usize, i), a.toggleFirstSet());1143 try testing.expectEqual(@as(?usize, i), a.toggleFirstSet());
1144 }1144 }
1145 }1145 }
1146 testing.expectEqual(@as(?usize, null), a.findFirstSet());1146 try testing.expectEqual(@as(?usize, null), a.findFirstSet());
1147 testing.expectEqual(@as(?usize, null), a.toggleFirstSet());1147 try testing.expectEqual(@as(?usize, null), a.toggleFirstSet());
1148 testing.expectEqual(@as(?usize, null), a.findFirstSet());1148 try testing.expectEqual(@as(?usize, null), a.findFirstSet());
1149 testing.expectEqual(@as(?usize, null), a.toggleFirstSet());1149 try testing.expectEqual(@as(?usize, null), a.toggleFirstSet());
1150 testing.expectEqual(@as(usize, 0), a.count());1150 try testing.expectEqual(@as(usize, 0), a.count());
1151}1151}
11521152
1153fn testStaticBitSet(comptime Set: type) void {1153fn testStaticBitSet(comptime Set: type) !void {
1154 var a = Set.initEmpty();1154 var a = Set.initEmpty();
1155 var b = Set.initFull();1155 var b = Set.initFull();
1156 testing.expectEqual(@as(usize, 0), a.count());1156 try testing.expectEqual(@as(usize, 0), a.count());
1157 testing.expectEqual(@as(usize, Set.bit_length), b.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);
1160}1160}
11611161
1162test "IntegerBitSet" {1162test "IntegerBitSet" {
1163 testStaticBitSet(IntegerBitSet(0));1163 try testStaticBitSet(IntegerBitSet(0));
1164 testStaticBitSet(IntegerBitSet(1));1164 try testStaticBitSet(IntegerBitSet(1));
1165 testStaticBitSet(IntegerBitSet(2));1165 try testStaticBitSet(IntegerBitSet(2));
1166 testStaticBitSet(IntegerBitSet(5));1166 try testStaticBitSet(IntegerBitSet(5));
1167 testStaticBitSet(IntegerBitSet(8));1167 try testStaticBitSet(IntegerBitSet(8));
1168 testStaticBitSet(IntegerBitSet(32));1168 try testStaticBitSet(IntegerBitSet(32));
1169 testStaticBitSet(IntegerBitSet(64));1169 try testStaticBitSet(IntegerBitSet(64));
1170 testStaticBitSet(IntegerBitSet(127));1170 try testStaticBitSet(IntegerBitSet(127));
1171}1171}
11721172
1173test "ArrayBitSet" {1173test "ArrayBitSet" {
1174 inline for (.{ 0, 1, 2, 31, 32, 33, 63, 64, 65, 254, 500, 3000 }) |size| {1174 inline for (.{ 0, 1, 2, 31, 32, 33, 63, 64, 65, 254, 500, 3000 }) |size| {
1175 testStaticBitSet(ArrayBitSet(u8, size));1175 try testStaticBitSet(ArrayBitSet(u8, size));
1176 testStaticBitSet(ArrayBitSet(u16, size));1176 try testStaticBitSet(ArrayBitSet(u16, size));
1177 testStaticBitSet(ArrayBitSet(u32, size));1177 try testStaticBitSet(ArrayBitSet(u32, size));
1178 testStaticBitSet(ArrayBitSet(u64, size));1178 try testStaticBitSet(ArrayBitSet(u64, size));
1179 testStaticBitSet(ArrayBitSet(u128, size));1179 try testStaticBitSet(ArrayBitSet(u128, size));
1180 }1180 }
1181}1181}
11821182
1183test "DynamicBitSetUnmanaged" {1183test "DynamicBitSetUnmanaged" {
1184 const allocator = std.testing.allocator;1184 const allocator = std.testing.allocator;
1185 var a = try DynamicBitSetUnmanaged.initEmpty(300, allocator);1185 var a = try DynamicBitSetUnmanaged.initEmpty(300, allocator);
1186 testing.expectEqual(@as(usize, 0), a.count());1186 try testing.expectEqual(@as(usize, 0), a.count());
1187 a.deinit(allocator);1187 a.deinit(allocator);
11881188
1189 a = try DynamicBitSetUnmanaged.initEmpty(0, allocator);1189 a = try DynamicBitSetUnmanaged.initEmpty(0, allocator);
...@@ -1193,10 +1193,10 @@ test "DynamicBitSetUnmanaged" {...@@ -1193,10 +1193,10 @@ test "DynamicBitSetUnmanaged" {
11931193
1194 var tmp = try a.clone(allocator);1194 var tmp = try a.clone(allocator);
1195 defer tmp.deinit(allocator);1195 defer tmp.deinit(allocator);
1196 testing.expectEqual(old_len, tmp.capacity());1196 try testing.expectEqual(old_len, tmp.capacity());
1197 var i: usize = 0;1197 var i: usize = 0;
1198 while (i < old_len) : (i += 1) {1198 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));
1200 }1200 }
12011201
1202 a.toggleSet(a); // zero a1202 a.toggleSet(a); // zero a
...@@ -1206,24 +1206,24 @@ test "DynamicBitSetUnmanaged" {...@@ -1206,24 +1206,24 @@ test "DynamicBitSetUnmanaged" {
1206 try tmp.resize(size, false, allocator);1206 try tmp.resize(size, false, allocator);
12071207
1208 if (size > old_len) {1208 if (size > old_len) {
1209 testing.expectEqual(size - old_len, a.count());1209 try testing.expectEqual(size - old_len, a.count());
1210 } else {1210 } else {
1211 testing.expectEqual(@as(usize, 0), a.count());1211 try testing.expectEqual(@as(usize, 0), a.count());
1212 }1212 }
1213 testing.expectEqual(@as(usize, 0), tmp.count());1213 try testing.expectEqual(@as(usize, 0), tmp.count());
12141214
1215 var b = try DynamicBitSetUnmanaged.initFull(size, allocator);1215 var b = try DynamicBitSetUnmanaged.initFull(size, allocator);
1216 defer b.deinit(allocator);1216 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);
1220 }1220 }
1221}1221}
12221222
1223test "DynamicBitSet" {1223test "DynamicBitSet" {
1224 const allocator = std.testing.allocator;1224 const allocator = std.testing.allocator;
1225 var a = try DynamicBitSet.initEmpty(300, allocator);1225 var a = try DynamicBitSet.initEmpty(300, allocator);
1226 testing.expectEqual(@as(usize, 0), a.count());1226 try testing.expectEqual(@as(usize, 0), a.count());
1227 a.deinit();1227 a.deinit();
12281228
1229 a = try DynamicBitSet.initEmpty(0, allocator);1229 a = try DynamicBitSet.initEmpty(0, allocator);
...@@ -1233,10 +1233,10 @@ test "DynamicBitSet" {...@@ -1233,10 +1233,10 @@ test "DynamicBitSet" {
12331233
1234 var tmp = try a.clone(allocator);1234 var tmp = try a.clone(allocator);
1235 defer tmp.deinit();1235 defer tmp.deinit();
1236 testing.expectEqual(old_len, tmp.capacity());1236 try testing.expectEqual(old_len, tmp.capacity());
1237 var i: usize = 0;1237 var i: usize = 0;
1238 while (i < old_len) : (i += 1) {1238 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));
1240 }1240 }
12411241
1242 a.toggleSet(a); // zero a1242 a.toggleSet(a); // zero a
...@@ -1246,24 +1246,24 @@ test "DynamicBitSet" {...@@ -1246,24 +1246,24 @@ test "DynamicBitSet" {
1246 try tmp.resize(size, false);1246 try tmp.resize(size, false);
12471247
1248 if (size > old_len) {1248 if (size > old_len) {
1249 testing.expectEqual(size - old_len, a.count());1249 try testing.expectEqual(size - old_len, a.count());
1250 } else {1250 } else {
1251 testing.expectEqual(@as(usize, 0), a.count());1251 try testing.expectEqual(@as(usize, 0), a.count());
1252 }1252 }
1253 testing.expectEqual(@as(usize, 0), tmp.count());1253 try testing.expectEqual(@as(usize, 0), tmp.count());
12541254
1255 var b = try DynamicBitSet.initFull(size, allocator);1255 var b = try DynamicBitSet.initFull(size, allocator);
1256 defer b.deinit();1256 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);
1260 }1260 }
1261}1261}
12621262
1263test "StaticBitSet" {1263test "StaticBitSet" {
1264 testing.expectEqual(IntegerBitSet(0), StaticBitSet(0));1264 try testing.expectEqual(IntegerBitSet(0), StaticBitSet(0));
1265 testing.expectEqual(IntegerBitSet(5), StaticBitSet(5));1265 try testing.expectEqual(IntegerBitSet(5), StaticBitSet(5));
1266 testing.expectEqual(IntegerBitSet(@bitSizeOf(usize)), StaticBitSet(@bitSizeOf(usize)));1266 try testing.expectEqual(IntegerBitSet(@bitSizeOf(usize)), StaticBitSet(@bitSizeOf(usize)));
1267 testing.expectEqual(ArrayBitSet(usize, @bitSizeOf(usize) + 1), StaticBitSet(@bitSizeOf(usize) + 1));1267 try testing.expectEqual(ArrayBitSet(usize, @bitSizeOf(usize) + 1), StaticBitSet(@bitSizeOf(usize) + 1));
1268 testing.expectEqual(ArrayBitSet(usize, 500), StaticBitSet(500));1268 try testing.expectEqual(ArrayBitSet(usize, 500), StaticBitSet(500));
1269}1269}
lib/std/buf_map.zig+7-7
...@@ -94,19 +94,19 @@ test "BufMap" {...@@ -94,19 +94,19 @@ test "BufMap" {
94 defer bufmap.deinit();94 defer bufmap.deinit();
9595
96 try bufmap.set("x", "1");96 try bufmap.set("x", "1");
97 testing.expect(mem.eql(u8, bufmap.get("x").?, "1"));97 try testing.expect(mem.eql(u8, bufmap.get("x").?, "1"));
98 testing.expect(1 == bufmap.count());98 try testing.expect(1 == bufmap.count());
9999
100 try bufmap.set("x", "2");100 try bufmap.set("x", "2");
101 testing.expect(mem.eql(u8, bufmap.get("x").?, "2"));101 try testing.expect(mem.eql(u8, bufmap.get("x").?, "2"));
102 testing.expect(1 == bufmap.count());102 try testing.expect(1 == bufmap.count());
103103
104 try bufmap.set("x", "3");104 try bufmap.set("x", "3");
105 testing.expect(mem.eql(u8, bufmap.get("x").?, "3"));105 try testing.expect(mem.eql(u8, bufmap.get("x").?, "3"));
106 testing.expect(1 == bufmap.count());106 try testing.expect(1 == bufmap.count());
107107
108 bufmap.delete("x");108 bufmap.delete("x");
109 testing.expect(0 == bufmap.count());109 try testing.expect(0 == bufmap.count());
110110
111 try bufmap.setMove(try allocator.dupe(u8, "k"), try allocator.dupe(u8, "v1"));111 try bufmap.setMove(try allocator.dupe(u8, "k"), try allocator.dupe(u8, "v1"));
112 try bufmap.setMove(try allocator.dupe(u8, "k"), try allocator.dupe(u8, "v2"));112 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" {...@@ -73,9 +73,9 @@ test "BufSet" {
73 defer bufset.deinit();73 defer bufset.deinit();
7474
75 try bufset.put("x");75 try bufset.put("x");
76 testing.expect(bufset.count() == 1);76 try testing.expect(bufset.count() == 1);
77 bufset.delete("x");77 bufset.delete("x");
78 testing.expect(bufset.count() == 0);78 try testing.expect(bufset.count() == 0);
7979
80 try bufset.put("x");80 try bufset.put("x");
81 try bufset.put("y");81 try bufset.put("y");
lib/std/build.zig+11-11
...@@ -3060,19 +3060,19 @@ test "Builder.dupePkg()" {...@@ -3060,19 +3060,19 @@ test "Builder.dupePkg()" {
3060 const dupe_deps = dupe.dependencies.?;3060 const dupe_deps = dupe.dependencies.?;
30613061
3062 // probably the same top level package details3062 // 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
3065 // probably the same dependencies3065 // probably the same dependencies
3066 std.testing.expectEqual(original_deps.len, dupe_deps.len);3066 try std.testing.expectEqual(original_deps.len, dupe_deps.len);
3067 std.testing.expectEqual(original_deps[0].name, pkg_dep.name);3067 try std.testing.expectEqual(original_deps[0].name, pkg_dep.name);
30683068
3069 // could segfault otherwise if pointers in duplicated package's fields are3069 // could segfault otherwise if pointers in duplicated package's fields are
3070 // the same as those in stack allocated package's fields3070 // the same as those in stack allocated package's fields
3071 std.testing.expect(dupe_deps.ptr != original_deps.ptr);3071 try std.testing.expect(dupe_deps.ptr != original_deps.ptr);
3072 std.testing.expect(dupe.name.ptr != pkg_top.name.ptr);3072 try std.testing.expect(dupe.name.ptr != pkg_top.name.ptr);
3073 std.testing.expect(dupe.path.ptr != pkg_top.path.ptr);3073 try std.testing.expect(dupe.path.ptr != pkg_top.path.ptr);
3074 std.testing.expect(dupe_deps[0].name.ptr != pkg_dep.name.ptr);3074 try 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);3075 try std.testing.expect(dupe_deps[0].path.ptr != pkg_dep.path.ptr);
3076}3076}
30773077
3078test "LibExeObjStep.addBuildOption" {3078test "LibExeObjStep.addBuildOption" {
...@@ -3096,7 +3096,7 @@ test "LibExeObjStep.addBuildOption" {...@@ -3096,7 +3096,7 @@ test "LibExeObjStep.addBuildOption" {
3096 exe.addBuildOption(?[]const u8, "optional_string", null);3096 exe.addBuildOption(?[]const u8, "optional_string", null);
3097 exe.addBuildOption(std.SemanticVersion, "semantic_version", try std.SemanticVersion.parse("0.1.2-foo+bar"));3097 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(
3100 \\pub const option1: usize = 1;3100 \\pub const option1: usize = 1;
3101 \\pub const option2: ?usize = null;3101 \\pub const option2: ?usize = null;
3102 \\pub const string: []const u8 = "zigisthebest";3102 \\pub const string: []const u8 = "zigisthebest";
...@@ -3140,10 +3140,10 @@ test "LibExeObjStep.addPackage" {...@@ -3140,10 +3140,10 @@ test "LibExeObjStep.addPackage" {
3140 var exe = builder.addExecutable("not_an_executable", "/not/an/executable.zig");3140 var exe = builder.addExecutable("not_an_executable", "/not/an/executable.zig");
3141 exe.addPackage(pkg_top);3141 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
3145 const dupe = exe.packages.items[0];3145 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);
3147}3147}
31483148
3149test {3149test {
lib/std/builtin.zig+1-1
...@@ -547,7 +547,7 @@ pub fn testVersionParse() !void {...@@ -547,7 +547,7 @@ pub fn testVersionParse() !void {
547 const f = struct {547 const f = struct {
548 fn eql(text: []const u8, v1: u32, v2: u32, v3: u32) !void {548 fn eql(text: []const u8, v1: u32, v2: u32, v3: u32) !void {
549 const v = try Version.parse(text);549 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);
551 }551 }
552552
553 fn err(text: []const u8, expected_err: anyerror) !void {553 fn err(text: []const u8, expected_err: anyerror) !void {
lib/std/c/tokenizer.zig+8-8
...@@ -1310,7 +1310,7 @@ pub const Tokenizer = struct {...@@ -1310,7 +1310,7 @@ pub const Tokenizer = struct {
1310};1310};
13111311
1312test "operators" {1312test "operators" {
1313 expectTokens(1313 try expectTokens(
1314 \\ ! != | || |= = ==1314 \\ ! != | || |= = ==
1315 \\ ( ) { } [ ] . .. ...1315 \\ ( ) { } [ ] . .. ...
1316 \\ ^ ^= + ++ += - -- -=1316 \\ ^ ^= + ++ += - -- -=
...@@ -1379,7 +1379,7 @@ test "operators" {...@@ -1379,7 +1379,7 @@ test "operators" {
1379}1379}
13801380
1381test "keywords" {1381test "keywords" {
1382 expectTokens(1382 try expectTokens(
1383 \\auto break case char const continue default do 1383 \\auto break case char const continue default do
1384 \\double else enum extern float for goto if int 1384 \\double else enum extern float for goto if int
1385 \\long register return short signed sizeof static 1385 \\long register return short signed sizeof static
...@@ -1442,7 +1442,7 @@ test "keywords" {...@@ -1442,7 +1442,7 @@ test "keywords" {
1442}1442}
14431443
1444test "preprocessor keywords" {1444test "preprocessor keywords" {
1445 expectTokens(1445 try expectTokens(
1446 \\#include <test>1446 \\#include <test>
1447 \\#define #include <11447 \\#define #include <1
1448 \\#ifdef1448 \\#ifdef
...@@ -1478,7 +1478,7 @@ test "preprocessor keywords" {...@@ -1478,7 +1478,7 @@ test "preprocessor keywords" {
1478}1478}
14791479
1480test "line continuation" {1480test "line continuation" {
1481 expectTokens(1481 try expectTokens(
1482 \\#define foo \1482 \\#define foo \
1483 \\ bar1483 \\ bar
1484 \\"foo\1484 \\"foo\
...@@ -1509,7 +1509,7 @@ test "line continuation" {...@@ -1509,7 +1509,7 @@ test "line continuation" {
1509}1509}
15101510
1511test "string prefix" {1511test "string prefix" {
1512 expectTokens(1512 try expectTokens(
1513 \\"foo"1513 \\"foo"
1514 \\u"foo"1514 \\u"foo"
1515 \\u8"foo"1515 \\u8"foo"
...@@ -1543,7 +1543,7 @@ test "string prefix" {...@@ -1543,7 +1543,7 @@ test "string prefix" {
1543}1543}
15441544
1545test "num suffixes" {1545test "num suffixes" {
1546 expectTokens(1546 try expectTokens(
1547 \\ 1.0f 1.0L 1.0 .0 1.1547 \\ 1.0f 1.0L 1.0 .0 1.
1548 \\ 0l 0lu 0ll 0llu 01548 \\ 0l 0lu 0ll 0llu 0
1549 \\ 1u 1ul 1ull 11549 \\ 1u 1ul 1ull 1
...@@ -1573,7 +1573,7 @@ test "num suffixes" {...@@ -1573,7 +1573,7 @@ test "num suffixes" {
1573 });1573 });
1574}1574}
15751575
1576fn expectTokens(source: []const u8, expected_tokens: []const Token.Id) void {1576fn expectTokens(source: []const u8, expected_tokens: []const Token.Id) !void {
1577 var tokenizer = Tokenizer{1577 var tokenizer = Tokenizer{
1578 .buffer = source,1578 .buffer = source,
1579 };1579 };
...@@ -1584,5 +1584,5 @@ fn expectTokens(source: []const u8, expected_tokens: []const Token.Id) void {...@@ -1584,5 +1584,5 @@ fn expectTokens(source: []const u8, expected_tokens: []const Token.Id) void {
1584 }1584 }
1585 }1585 }
1586 const last_token = tokenizer.next();1586 const last_token = tokenizer.next();
1587 std.testing.expect(last_token.id == .Eof);1587 try std.testing.expect(last_token.id == .Eof);
1588}1588}
lib/std/child_process.zig+2-2
...@@ -1005,7 +1005,7 @@ test "createNullDelimitedEnvMap" {...@@ -1005,7 +1005,7 @@ test "createNullDelimitedEnvMap" {
1005 defer arena.deinit();1005 defer arena.deinit();
1006 const environ = try createNullDelimitedEnvMap(&arena.allocator, &envmap);1006 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
1010 inline for (.{1010 inline for (.{
1011 "HOME=/home/ifreund",1011 "HOME=/home/ifreund",
...@@ -1017,7 +1017,7 @@ test "createNullDelimitedEnvMap" {...@@ -1017,7 +1017,7 @@ test "createNullDelimitedEnvMap" {
1017 for (environ) |variable| {1017 for (environ) |variable| {
1018 if (mem.eql(u8, mem.span(variable orelse continue), target)) break;1018 if (mem.eql(u8, mem.span(variable orelse continue), target)) break;
1019 } else {1019 } else {
1020 testing.expect(false); // Environment variable not found1020 try testing.expect(false); // Environment variable not found
1021 }1021 }
1022 }1022 }
1023}1023}
lib/std/compress/deflate.zig+1-1
...@@ -669,5 +669,5 @@ test "lengths overflow" {...@@ -669,5 +669,5 @@ test "lengths overflow" {
669 var inflate = inflateStream(reader, &window);669 var inflate = inflateStream(reader, &window);
670670
671 var buf: [1]u8 = undefined;671 var buf: [1]u8 = undefined;
672 std.testing.expectError(error.InvalidLength, inflate.read(&buf));672 try std.testing.expectError(error.InvalidLength, inflate.read(&buf));
673}673}
lib/std/compress/gzip.zig+9-9
...@@ -172,17 +172,17 @@ fn testReader(data: []const u8, comptime expected: []const u8) !void {...@@ -172,17 +172,17 @@ fn testReader(data: []const u8, comptime expected: []const u8) !void {
172 var hash: [32]u8 = undefined;172 var hash: [32]u8 = undefined;
173 std.crypto.hash.sha2.Sha256.hash(buf, hash[0..], .{});173 std.crypto.hash.sha2.Sha256.hash(buf, hash[0..], .{});
174174
175 assertEqual(expected, &hash);175 try assertEqual(expected, &hash);
176}176}
177177
178// Assert `expected` == `input` where `input` is a bytestring.178// 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 {
180 var expected_bytes: [expected.len / 2]u8 = undefined;180 var expected_bytes: [expected.len / 2]u8 = undefined;
181 for (expected_bytes) |*r, i| {181 for (expected_bytes) |*r, i| {
182 r.* = std.fmt.parseInt(u8, expected[2 * i .. 2 * i + 2], 16) catch unreachable;182 r.* = std.fmt.parseInt(u8, expected[2 * i .. 2 * i + 2], 16) catch unreachable;
183 }183 }
184184
185 testing.expectEqualSlices(u8, &expected_bytes, input);185 try testing.expectEqualSlices(u8, &expected_bytes, input);
186}186}
187187
188// All the test cases are obtained by compressing the RFC1952 text188// All the test cases are obtained by compressing the RFC1952 text
...@@ -198,12 +198,12 @@ test "compressed data" {...@@ -198,12 +198,12 @@ test "compressed data" {
198198
199test "sanity checks" {199test "sanity checks" {
200 // Truncated header200 // Truncated header
201 testing.expectError(201 try testing.expectError(
202 error.EndOfStream,202 error.EndOfStream,
203 testReader(&[_]u8{ 0x1f, 0x8B }, ""),203 testReader(&[_]u8{ 0x1f, 0x8B }, ""),
204 );204 );
205 // Wrong CM205 // Wrong CM
206 testing.expectError(206 try testing.expectError(
207 error.InvalidCompression,207 error.InvalidCompression,
208 testReader(&[_]u8{208 testReader(&[_]u8{
209 0x1f, 0x8b, 0x09, 0x00, 0x00, 0x00, 0x00, 0x00,209 0x1f, 0x8b, 0x09, 0x00, 0x00, 0x00, 0x00, 0x00,
...@@ -211,7 +211,7 @@ test "sanity checks" {...@@ -211,7 +211,7 @@ test "sanity checks" {
211 }, ""),211 }, ""),
212 );212 );
213 // Wrong checksum213 // Wrong checksum
214 testing.expectError(214 try testing.expectError(
215 error.WrongChecksum,215 error.WrongChecksum,
216 testReader(&[_]u8{216 testReader(&[_]u8{
217 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00,217 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00,
...@@ -220,7 +220,7 @@ test "sanity checks" {...@@ -220,7 +220,7 @@ test "sanity checks" {
220 }, ""),220 }, ""),
221 );221 );
222 // Truncated checksum222 // Truncated checksum
223 testing.expectError(223 try testing.expectError(
224 error.EndOfStream,224 error.EndOfStream,
225 testReader(&[_]u8{225 testReader(&[_]u8{
226 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00,226 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00,
...@@ -228,7 +228,7 @@ test "sanity checks" {...@@ -228,7 +228,7 @@ test "sanity checks" {
228 }, ""),228 }, ""),
229 );229 );
230 // Wrong initial size230 // Wrong initial size
231 testing.expectError(231 try testing.expectError(
232 error.CorruptedData,232 error.CorruptedData,
233 testReader(&[_]u8{233 testReader(&[_]u8{
234 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00,234 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00,
...@@ -237,7 +237,7 @@ test "sanity checks" {...@@ -237,7 +237,7 @@ test "sanity checks" {
237 }, ""),237 }, ""),
238 );238 );
239 // Truncated initial size field239 // Truncated initial size field
240 testing.expectError(240 try testing.expectError(
241 error.EndOfStream,241 error.EndOfStream,
242 testReader(&[_]u8{242 testReader(&[_]u8{
243 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00,243 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 {...@@ -109,17 +109,17 @@ fn testReader(data: []const u8, comptime expected: []const u8) !void {
109 var hash: [32]u8 = undefined;109 var hash: [32]u8 = undefined;
110 std.crypto.hash.sha2.Sha256.hash(buf, hash[0..], .{});110 std.crypto.hash.sha2.Sha256.hash(buf, hash[0..], .{});
111111
112 assertEqual(expected, &hash);112 try assertEqual(expected, &hash);
113}113}
114114
115// Assert `expected` == `input` where `input` is a bytestring.115// 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 {
117 var expected_bytes: [expected.len / 2]u8 = undefined;117 var expected_bytes: [expected.len / 2]u8 = undefined;
118 for (expected_bytes) |*r, i| {118 for (expected_bytes) |*r, i| {
119 r.* = std.fmt.parseInt(u8, expected[2 * i .. 2 * i + 2], 16) catch unreachable;119 r.* = std.fmt.parseInt(u8, expected[2 * i .. 2 * i + 2], 16) catch unreachable;
120 }120 }
121121
122 testing.expectEqualSlices(u8, &expected_bytes, input);122 try testing.expectEqualSlices(u8, &expected_bytes, input);
123}123}
124124
125// All the test cases are obtained by compressing the RFC1950 text125// All the test cases are obtained by compressing the RFC1950 text
...@@ -159,32 +159,32 @@ test "don't read past deflate stream's end" {...@@ -159,32 +159,32 @@ test "don't read past deflate stream's end" {
159159
160test "sanity checks" {160test "sanity checks" {
161 // Truncated header161 // Truncated header
162 testing.expectError(162 try testing.expectError(
163 error.EndOfStream,163 error.EndOfStream,
164 testReader(&[_]u8{0x78}, ""),164 testReader(&[_]u8{0x78}, ""),
165 );165 );
166 // Failed FCHECK check166 // Failed FCHECK check
167 testing.expectError(167 try testing.expectError(
168 error.BadHeader,168 error.BadHeader,
169 testReader(&[_]u8{ 0x78, 0x9D }, ""),169 testReader(&[_]u8{ 0x78, 0x9D }, ""),
170 );170 );
171 // Wrong CM171 // Wrong CM
172 testing.expectError(172 try testing.expectError(
173 error.InvalidCompression,173 error.InvalidCompression,
174 testReader(&[_]u8{ 0x79, 0x94 }, ""),174 testReader(&[_]u8{ 0x79, 0x94 }, ""),
175 );175 );
176 // Wrong CINFO176 // Wrong CINFO
177 testing.expectError(177 try testing.expectError(
178 error.InvalidWindowSize,178 error.InvalidWindowSize,
179 testReader(&[_]u8{ 0x88, 0x98 }, ""),179 testReader(&[_]u8{ 0x88, 0x98 }, ""),
180 );180 );
181 // Wrong checksum181 // Wrong checksum
182 testing.expectError(182 try testing.expectError(
183 error.WrongChecksum,183 error.WrongChecksum,
184 testReader(&[_]u8{ 0x78, 0xda, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00 }, ""),184 testReader(&[_]u8{ 0x78, 0xda, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00 }, ""),
185 );185 );
186 // Truncated checksum186 // Truncated checksum
187 testing.expectError(187 try testing.expectError(
188 error.EndOfStream,188 error.EndOfStream,
189 testReader(&[_]u8{ 0x78, 0xda, 0x03, 0x00, 0x00 }, ""),189 testReader(&[_]u8{ 0x78, 0xda, 0x03, 0x00, 0x00 }, ""),
190 );190 );
lib/std/comptime_string_map.zig+21-21
...@@ -95,7 +95,7 @@ test "ComptimeStringMap list literal of list literals" {...@@ -95,7 +95,7 @@ test "ComptimeStringMap list literal of list literals" {
95 .{ "samelen", .E },95 .{ "samelen", .E },
96 });96 });
9797
98 testMap(map);98 try testMap(map);
99}99}
100100
101test "ComptimeStringMap array of structs" {101test "ComptimeStringMap array of structs" {
...@@ -111,7 +111,7 @@ test "ComptimeStringMap array of structs" {...@@ -111,7 +111,7 @@ test "ComptimeStringMap array of structs" {
111 .{ .@"0" = "samelen", .@"1" = .E },111 .{ .@"0" = "samelen", .@"1" = .E },
112 });112 });
113113
114 testMap(map);114 try testMap(map);
115}115}
116116
117test "ComptimeStringMap slice of structs" {117test "ComptimeStringMap slice of structs" {
...@@ -128,18 +128,18 @@ test "ComptimeStringMap slice of structs" {...@@ -128,18 +128,18 @@ test "ComptimeStringMap slice of structs" {
128 };128 };
129 const map = ComptimeStringMap(TestEnum, slice);129 const map = ComptimeStringMap(TestEnum, slice);
130130
131 testMap(map);131 try testMap(map);
132}132}
133133
134fn testMap(comptime map: anytype) void {134fn testMap(comptime map: anytype) !void {
135 std.testing.expectEqual(TestEnum.A, map.get("have").?);135 try std.testing.expectEqual(TestEnum.A, map.get("have").?);
136 std.testing.expectEqual(TestEnum.B, map.get("nothing").?);136 try std.testing.expectEqual(TestEnum.B, map.get("nothing").?);
137 std.testing.expect(null == map.get("missing"));137 try std.testing.expect(null == map.get("missing"));
138 std.testing.expectEqual(TestEnum.D, map.get("these").?);138 try std.testing.expectEqual(TestEnum.D, map.get("these").?);
139 std.testing.expectEqual(TestEnum.E, map.get("samelen").?);139 try std.testing.expectEqual(TestEnum.E, map.get("samelen").?);
140140
141 std.testing.expect(!map.has("missing"));141 try std.testing.expect(!map.has("missing"));
142 std.testing.expect(map.has("these"));142 try std.testing.expect(map.has("these"));
143}143}
144144
145test "ComptimeStringMap void value type, slice of structs" {145test "ComptimeStringMap void value type, slice of structs" {
...@@ -155,7 +155,7 @@ test "ComptimeStringMap void value type, slice of structs" {...@@ -155,7 +155,7 @@ test "ComptimeStringMap void value type, slice of structs" {
155 };155 };
156 const map = ComptimeStringMap(void, slice);156 const map = ComptimeStringMap(void, slice);
157157
158 testSet(map);158 try testSet(map);
159}159}
160160
161test "ComptimeStringMap void value type, list literal of list literals" {161test "ComptimeStringMap void value type, list literal of list literals" {
...@@ -167,16 +167,16 @@ test "ComptimeStringMap void value type, list literal of list literals" {...@@ -167,16 +167,16 @@ test "ComptimeStringMap void value type, list literal of list literals" {
167 .{"samelen"},167 .{"samelen"},
168 });168 });
169169
170 testSet(map);170 try testSet(map);
171}171}
172172
173fn testSet(comptime map: anytype) void {173fn testSet(comptime map: anytype) !void {
174 std.testing.expectEqual({}, map.get("have").?);174 try std.testing.expectEqual({}, map.get("have").?);
175 std.testing.expectEqual({}, map.get("nothing").?);175 try std.testing.expectEqual({}, map.get("nothing").?);
176 std.testing.expect(null == map.get("missing"));176 try std.testing.expect(null == map.get("missing"));
177 std.testing.expectEqual({}, map.get("these").?);177 try std.testing.expectEqual({}, map.get("these").?);
178 std.testing.expectEqual({}, map.get("samelen").?);178 try std.testing.expectEqual({}, map.get("samelen").?);
179179
180 std.testing.expect(!map.has("missing"));180 try std.testing.expect(!map.has("missing"));
181 std.testing.expect(map.has("these"));181 try std.testing.expect(map.has("these"));
182}182}
lib/std/crypto.zig+2-2
...@@ -188,7 +188,7 @@ test "CSPRNG" {...@@ -188,7 +188,7 @@ test "CSPRNG" {
188 const a = random.int(u64);188 const a = random.int(u64);
189 const b = random.int(u64);189 const b = random.int(u64);
190 const c = random.int(u64);190 const c = random.int(u64);
191 std.testing.expect(a ^ b ^ c != 0);191 try std.testing.expect(a ^ b ^ c != 0);
192}192}
193193
194test "issue #4532: no index out of bounds" {194test "issue #4532: no index out of bounds" {
...@@ -226,6 +226,6 @@ test "issue #4532: no index out of bounds" {...@@ -226,6 +226,6 @@ test "issue #4532: no index out of bounds" {
226 h.update(block[1..]);226 h.update(block[1..]);
227 h.final(&out2);227 h.final(&out2);
228228
229 std.testing.expectEqual(out1, out2);229 try std.testing.expectEqual(out1, out2);
230 }230 }
231}231}
lib/std/crypto/25519/curve25519.zig+6-6
...@@ -120,13 +120,13 @@ test "curve25519" {...@@ -120,13 +120,13 @@ test "curve25519" {
120 const p = try Curve25519.basePoint.clampedMul(s);120 const p = try Curve25519.basePoint.clampedMul(s);
121 try p.rejectIdentity();121 try p.rejectIdentity();
122 var buf: [128]u8 = undefined;122 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");
124 const q = try p.clampedMul(s);124 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
127 try Curve25519.rejectNonCanonical(s);127 try Curve25519.rejectNonCanonical(s);
128 s[31] |= 0x80;128 s[31] |= 0x80;
129 std.testing.expectError(error.NonCanonical, Curve25519.rejectNonCanonical(s));129 try std.testing.expectError(error.NonCanonical, Curve25519.rejectNonCanonical(s));
130}130}
131131
132test "curve25519 small order check" {132test "curve25519 small order check" {
...@@ -155,13 +155,13 @@ test "curve25519 small order check" {...@@ -155,13 +155,13 @@ test "curve25519 small order check" {
155 },155 },
156 };156 };
157 for (small_order_ss) |small_order_s| {157 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));
159 var extra = small_order_s;159 var extra = small_order_s;
160 extra[31] ^= 0x80;160 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));
162 var valid = small_order_s;162 var valid = small_order_s;
163 valid[31] = 0x40;163 valid[31] = 0x40;
164 s[0] = 0;164 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));
166 }166 }
167}167}
lib/std/crypto/25519/ed25519.zig+6-6
...@@ -219,8 +219,8 @@ test "ed25519 key pair creation" {...@@ -219,8 +219,8 @@ test "ed25519 key pair creation" {
219 _ = try fmt.hexToBytes(seed[0..], "8052030376d47112be7f73ed7a019293dd12ad910b654455798b4667d73de166");219 _ = try fmt.hexToBytes(seed[0..], "8052030376d47112be7f73ed7a019293dd12ad910b654455798b4667d73de166");
220 const key_pair = try Ed25519.KeyPair.create(seed);220 const key_pair = try Ed25519.KeyPair.create(seed);
221 var buf: [256]u8 = undefined;221 var buf: [256]u8 = undefined;
222 std.testing.expectEqualStrings(try std.fmt.bufPrint(&buf, "{s}", .{std.fmt.fmtSliceHexUpper(&key_pair.secret_key)}), "8052030376D47112BE7F73ED7A019293DD12AD910B654455798B4667D73DE1662D6F7455D97B4A3A10D7293909D1A4F2058CB9A370E43FA8154BB280DB839083");222 try 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");223 try std.testing.expectEqualStrings(try std.fmt.bufPrint(&buf, "{s}", .{std.fmt.fmtSliceHexUpper(&key_pair.public_key)}), "2D6F7455D97B4A3A10D7293909D1A4F2058CB9A370E43FA8154BB280DB839083");
224}224}
225225
226test "ed25519 signature" {226test "ed25519 signature" {
...@@ -230,9 +230,9 @@ test "ed25519 signature" {...@@ -230,9 +230,9 @@ test "ed25519 signature" {
230230
231 const sig = try Ed25519.sign("test", key_pair, null);231 const sig = try Ed25519.sign("test", key_pair, null);
232 var buf: [128]u8 = undefined;232 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");
234 try Ed25519.verify(sig, "test", key_pair.public_key);234 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));
236}236}
237237
238test "ed25519 batch verification" {238test "ed25519 batch verification" {
...@@ -260,7 +260,7 @@ test "ed25519 batch verification" {...@@ -260,7 +260,7 @@ test "ed25519 batch verification" {
260 try Ed25519.verifyBatch(2, signature_batch);260 try Ed25519.verifyBatch(2, signature_batch);
261261
262 signature_batch[1].sig = sig1;262 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));
264 }264 }
265}265}
266266
...@@ -354,7 +354,7 @@ test "ed25519 test vectors" {...@@ -354,7 +354,7 @@ test "ed25519 test vectors" {
354 var sig: [64]u8 = undefined;354 var sig: [64]u8 = undefined;
355 _ = try fmt.hexToBytes(&sig, entry.sig_hex);355 _ = try fmt.hexToBytes(&sig, entry.sig_hex);
356 if (entry.expected) |error_type| {356 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));
358 } else {358 } else {
359 try Ed25519.verify(sig, &msg, public_key);359 try Ed25519.verify(sig, &msg, public_key);
360 }360 }
lib/std/crypto/25519/edwards25519.zig+9-9
...@@ -491,7 +491,7 @@ test "edwards25519 packing/unpacking" {...@@ -491,7 +491,7 @@ test "edwards25519 packing/unpacking" {
491 var b = Edwards25519.basePoint;491 var b = Edwards25519.basePoint;
492 const pk = try b.mul(s);492 const pk = try b.mul(s);
493 var buf: [128]u8 = undefined;493 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
496 const small_order_ss: [7][32]u8 = .{496 const small_order_ss: [7][32]u8 = .{
497 .{497 .{
...@@ -518,7 +518,7 @@ test "edwards25519 packing/unpacking" {...@@ -518,7 +518,7 @@ test "edwards25519 packing/unpacking" {
518 };518 };
519 for (small_order_ss) |small_order_s| {519 for (small_order_ss) |small_order_s| {
520 const small_p = try Edwards25519.fromBytes(small_order_s);520 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));
522 }522 }
523}523}
524524
...@@ -531,26 +531,26 @@ test "edwards25519 point addition/substraction" {...@@ -531,26 +531,26 @@ test "edwards25519 point addition/substraction" {
531 const q = try Edwards25519.basePoint.clampedMul(s2);531 const q = try Edwards25519.basePoint.clampedMul(s2);
532 const r = p.add(q).add(q).sub(q).sub(q);532 const r = p.add(q).add(q).sub(q).sub(q);
533 try r.rejectIdentity();533 try r.rejectIdentity();
534 std.testing.expectError(error.IdentityElement, r.sub(p).rejectIdentity());534 try std.testing.expectError(error.IdentityElement, r.sub(p).rejectIdentity());
535 std.testing.expectError(error.IdentityElement, p.sub(p).rejectIdentity());535 try std.testing.expectError(error.IdentityElement, p.sub(p).rejectIdentity());
536 std.testing.expectError(error.IdentityElement, p.sub(q).add(q).sub(p).rejectIdentity());536 try std.testing.expectError(error.IdentityElement, p.sub(q).add(q).sub(p).rejectIdentity());
537}537}
538538
539test "edwards25519 uniform-to-point" {539test "edwards25519 uniform-to-point" {
540 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 };540 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 };
541 var p = Edwards25519.fromUniform(r);541 var p = Edwards25519.fromUniform(r);
542 htest.assertEqual("0691eee3cf70a0056df6bfa03120635636581b5c4ea571dfc680f78c7e0b4137", p.toBytes()[0..]);542 try htest.assertEqual("0691eee3cf70a0056df6bfa03120635636581b5c4ea571dfc680f78c7e0b4137", p.toBytes()[0..]);
543543
544 r[31] = 0xff;544 r[31] = 0xff;
545 p = Edwards25519.fromUniform(r);545 p = Edwards25519.fromUniform(r);
546 htest.assertEqual("f70718e68ef42d90ca1d936bb2d7e159be6c01d8095d39bd70487c82fe5c973a", p.toBytes()[0..]);546 try htest.assertEqual("f70718e68ef42d90ca1d936bb2d7e159be6c01d8095d39bd70487c82fe5c973a", p.toBytes()[0..]);
547}547}
548548
549// Test vectors from draft-irtf-cfrg-hash-to-curve-10549// Test vectors from draft-irtf-cfrg-hash-to-curve-10
550test "edwards25519 hash-to-curve operation" {550test "edwards25519 hash-to-curve operation" {
551 var p = Edwards25519.fromString(true, "QUUX-V01-CS02-with-edwards25519_XMD:SHA-512_ELL2_RO_", "abc");551 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
554 p = Edwards25519.fromString(false, "QUUX-V01-CS02-with-edwards25519_XMD:SHA-512_ELL2_NU_", "abc");554 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..]);
556}556}
lib/std/crypto/25519/ristretto255.zig+5-5
...@@ -175,21 +175,21 @@ pub const Ristretto255 = struct {...@@ -175,21 +175,21 @@ pub const Ristretto255 = struct {
175test "ristretto255" {175test "ristretto255" {
176 const p = Ristretto255.basePoint;176 const p = Ristretto255.basePoint;
177 var buf: [256]u8 = undefined;177 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
180 var r: [Ristretto255.encoded_length]u8 = undefined;180 var r: [Ristretto255.encoded_length]u8 = undefined;
181 _ = try fmt.hexToBytes(r[0..], "6a493210f7499cd17fecb510ae0cea23a110e8d5b901f8acadd3095c73a3b919");181 _ = try fmt.hexToBytes(r[0..], "6a493210f7499cd17fecb510ae0cea23a110e8d5b901f8acadd3095c73a3b919");
182 var q = try Ristretto255.fromBytes(r);182 var q = try Ristretto255.fromBytes(r);
183 q = q.dbl().add(p);183 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
186 const s = [_]u8{15} ++ [_]u8{0} ** 31;186 const s = [_]u8{15} ++ [_]u8{0} ** 31;
187 const w = try p.mul(s);187 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
192 const h = [_]u8{69} ** 32 ++ [_]u8{42} ** 32;192 const h = [_]u8{69} ** 32 ++ [_]u8{42} ** 32;
193 const ph = Ristretto255.fromUniform(h);193 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");
195}195}
lib/std/crypto/25519/scalar.zig+4-4
...@@ -773,15 +773,15 @@ test "scalar25519" {...@@ -773,15 +773,15 @@ test "scalar25519" {
773 var y = x.toBytes();773 var y = x.toBytes();
774 try rejectNonCanonical(y);774 try rejectNonCanonical(y);
775 var buf: [128]u8 = undefined;775 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
778 const reduced = reduce(field_size);778 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");
780}780}
781781
782test "non-canonical scalar25519" {782test "non-canonical scalar25519" {
783 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 };783 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));
785}785}
786786
787test "mulAdd overflow check" {787test "mulAdd overflow check" {
...@@ -790,5 +790,5 @@ test "mulAdd overflow check" {...@@ -790,5 +790,5 @@ test "mulAdd overflow check" {
790 const c: [32]u8 = [_]u8{0xff} ** 32;790 const c: [32]u8 = [_]u8{0xff} ** 32;
791 const x = mulAdd(a, b, c);791 const x = mulAdd(a, b, c);
792 var buf: [128]u8 = undefined;792 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");
794}794}
lib/std/crypto/25519/x25519.zig+8-8
...@@ -92,7 +92,7 @@ test "x25519 public key calculation from secret key" {...@@ -92,7 +92,7 @@ test "x25519 public key calculation from secret key" {
92 _ = try fmt.hexToBytes(sk[0..], "8052030376d47112be7f73ed7a019293dd12ad910b654455798b4667d73de166");92 _ = try fmt.hexToBytes(sk[0..], "8052030376d47112be7f73ed7a019293dd12ad910b654455798b4667d73de166");
93 _ = try fmt.hexToBytes(pk_expected[0..], "f1814f0e8ff1043d8a44d25babff3cedcae6c22c3edaa48f857ae70de2baae50");93 _ = try fmt.hexToBytes(pk_expected[0..], "f1814f0e8ff1043d8a44d25babff3cedcae6c22c3edaa48f857ae70de2baae50");
94 const pk_calculated = try X25519.recoverPublicKey(sk);94 const pk_calculated = try X25519.recoverPublicKey(sk);
95 std.testing.expectEqual(pk_calculated, pk_expected);95 try std.testing.expectEqual(pk_calculated, pk_expected);
96}96}
9797
98test "x25519 rfc7748 vector1" {98test "x25519 rfc7748 vector1" {
...@@ -102,7 +102,7 @@ test "x25519 rfc7748 vector1" {...@@ -102,7 +102,7 @@ test "x25519 rfc7748 vector1" {
102 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 };102 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
104 const output = try X25519.scalarmult(secret_key, public_key);104 const output = try X25519.scalarmult(secret_key, public_key);
105 std.testing.expectEqual(output, expected_output);105 try std.testing.expectEqual(output, expected_output);
106}106}
107107
108test "x25519 rfc7748 vector2" {108test "x25519 rfc7748 vector2" {
...@@ -112,7 +112,7 @@ test "x25519 rfc7748 vector2" {...@@ -112,7 +112,7 @@ test "x25519 rfc7748 vector2" {
112 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 };112 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
114 const output = try X25519.scalarmult(secret_key, public_key);114 const output = try X25519.scalarmult(secret_key, public_key);
115 std.testing.expectEqual(output, expected_output);115 try std.testing.expectEqual(output, expected_output);
116}116}
117117
118test "x25519 rfc7748 one iteration" {118test "x25519 rfc7748 one iteration" {
...@@ -129,7 +129,7 @@ test "x25519 rfc7748 one iteration" {...@@ -129,7 +129,7 @@ test "x25519 rfc7748 one iteration" {
129 mem.copy(u8, k[0..], output[0..]);129 mem.copy(u8, k[0..], output[0..]);
130 }130 }
131131
132 std.testing.expectEqual(k, expected_output);132 try std.testing.expectEqual(k, expected_output);
133}133}
134134
135test "x25519 rfc7748 1,000 iterations" {135test "x25519 rfc7748 1,000 iterations" {
...@@ -151,7 +151,7 @@ test "x25519 rfc7748 1,000 iterations" {...@@ -151,7 +151,7 @@ test "x25519 rfc7748 1,000 iterations" {
151 mem.copy(u8, k[0..], output[0..]);151 mem.copy(u8, k[0..], output[0..]);
152 }152 }
153153
154 std.testing.expectEqual(k, expected_output);154 try std.testing.expectEqual(k, expected_output);
155}155}
156156
157test "x25519 rfc7748 1,000,000 iterations" {157test "x25519 rfc7748 1,000,000 iterations" {
...@@ -172,12 +172,12 @@ test "x25519 rfc7748 1,000,000 iterations" {...@@ -172,12 +172,12 @@ test "x25519 rfc7748 1,000,000 iterations" {
172 mem.copy(u8, k[0..], output[0..]);172 mem.copy(u8, k[0..], output[0..]);
173 }173 }
174174
175 std.testing.expectEqual(k[0..], expected_output);175 try std.testing.expectEqual(k[0..], expected_output);
176}176}
177177
178test "edwards25519 -> curve25519 map" {178test "edwards25519 -> curve25519 map" {
179 const ed_kp = try crypto.sign.Ed25519.KeyPair.create([_]u8{0x42} ** 32);179 const ed_kp = try crypto.sign.Ed25519.KeyPair.create([_]u8{0x42} ** 32);
180 const mont_kp = try X25519.KeyPair.fromEd25519(ed_kp);180 const mont_kp = try X25519.KeyPair.fromEd25519(ed_kp);
181 htest.assertEqual("90e7595fc89e52fdfddce9c6a43d74dbf6047025ee0462d2d172e8b6a2841d6e", &mont_kp.secret_key);181 try htest.assertEqual("90e7595fc89e52fdfddce9c6a43d74dbf6047025ee0462d2d172e8b6a2841d6e", &mont_kp.secret_key);
182 htest.assertEqual("cc4f2cdb695dd766f34118eb67b98652fed1d8bc49c330b119bbfa8a64989378", &mont_kp.public_key);182 try htest.assertEqual("cc4f2cdb695dd766f34118eb67b98652fed1d8bc49c330b119bbfa8a64989378", &mont_kp.public_key);
183}183}
lib/std/crypto/aegis.zig+20-20
...@@ -352,16 +352,16 @@ test "Aegis128L test vector 1" {...@@ -352,16 +352,16 @@ test "Aegis128L test vector 1" {
352352
353 Aegis128L.encrypt(&c, &tag, &m, &ad, nonce, key);353 Aegis128L.encrypt(&c, &tag, &m, &ad, nonce, key);
354 try Aegis128L.decrypt(&m2, &c, tag, &ad, nonce, key);354 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);357 try htest.assertEqual("79d94593d8c2119d7e8fd9b8fc77845c5c077a05b2528b6ac54b563aed8efe84", &c);
358 htest.assertEqual("cc6f3372f6aa1bb82388d695c3962d9a", &tag);358 try htest.assertEqual("cc6f3372f6aa1bb82388d695c3962d9a", &tag);
359359
360 c[0] +%= 1;360 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));
362 c[0] -%= 1;362 c[0] -%= 1;
363 tag[0] +%= 1;363 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));
365}365}
366366
367test "Aegis128L test vector 2" {367test "Aegis128L test vector 2" {
...@@ -375,10 +375,10 @@ test "Aegis128L test vector 2" {...@@ -375,10 +375,10 @@ test "Aegis128L test vector 2" {
375375
376 Aegis128L.encrypt(&c, &tag, &m, &ad, nonce, key);376 Aegis128L.encrypt(&c, &tag, &m, &ad, nonce, key);
377 try Aegis128L.decrypt(&m2, &c, tag, &ad, nonce, key);377 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);380 try htest.assertEqual("41de9000a7b5e40e2d68bb64d99ebb19", &c);
381 htest.assertEqual("f4d997cc9b94227ada4fe4165422b1c8", &tag);381 try htest.assertEqual("f4d997cc9b94227ada4fe4165422b1c8", &tag);
382}382}
383383
384test "Aegis128L test vector 3" {384test "Aegis128L test vector 3" {
...@@ -392,9 +392,9 @@ test "Aegis128L test vector 3" {...@@ -392,9 +392,9 @@ test "Aegis128L test vector 3" {
392392
393 Aegis128L.encrypt(&c, &tag, &m, &ad, nonce, key);393 Aegis128L.encrypt(&c, &tag, &m, &ad, nonce, key);
394 try Aegis128L.decrypt(&m2, &c, tag, &ad, nonce, key);394 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);
398}398}
399399
400test "Aegis256 test vector 1" {400test "Aegis256 test vector 1" {
...@@ -408,16 +408,16 @@ test "Aegis256 test vector 1" {...@@ -408,16 +408,16 @@ test "Aegis256 test vector 1" {
408408
409 Aegis256.encrypt(&c, &tag, &m, &ad, nonce, key);409 Aegis256.encrypt(&c, &tag, &m, &ad, nonce, key);
410 try Aegis256.decrypt(&m2, &c, tag, &ad, nonce, key);410 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);413 try htest.assertEqual("f373079ed84b2709faee373584585d60accd191db310ef5d8b11833df9dec711", &c);
414 htest.assertEqual("8d86f91ee606e9ff26a01b64ccbdd91d", &tag);414 try htest.assertEqual("8d86f91ee606e9ff26a01b64ccbdd91d", &tag);
415415
416 c[0] +%= 1;416 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));
418 c[0] -%= 1;418 c[0] -%= 1;
419 tag[0] +%= 1;419 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));
421}421}
422422
423test "Aegis256 test vector 2" {423test "Aegis256 test vector 2" {
...@@ -431,10 +431,10 @@ test "Aegis256 test vector 2" {...@@ -431,10 +431,10 @@ test "Aegis256 test vector 2" {
431431
432 Aegis256.encrypt(&c, &tag, &m, &ad, nonce, key);432 Aegis256.encrypt(&c, &tag, &m, &ad, nonce, key);
433 try Aegis256.decrypt(&m2, &c, tag, &ad, nonce, key);433 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);436 try htest.assertEqual("b98f03a947807713d75a4fff9fc277a6", &c);
437 htest.assertEqual("478f3b50dc478ef7d5cf2d0f7cc13180", &tag);437 try htest.assertEqual("478f3b50dc478ef7d5cf2d0f7cc13180", &tag);
438}438}
439439
440test "Aegis256 test vector 3" {440test "Aegis256 test vector 3" {
...@@ -448,7 +448,7 @@ test "Aegis256 test vector 3" {...@@ -448,7 +448,7 @@ test "Aegis256 test vector 3" {
448448
449 Aegis256.encrypt(&c, &tag, &m, &ad, nonce, key);449 Aegis256.encrypt(&c, &tag, &m, &ad, nonce, key);
450 try Aegis256.decrypt(&m2, &c, tag, &ad, nonce, key);450 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);
454}454}
lib/std/crypto/aes.zig+9-9
...@@ -48,7 +48,7 @@ test "ctr" {...@@ -48,7 +48,7 @@ test "ctr" {
48 var out: [exp_out.len]u8 = undefined;48 var out: [exp_out.len]u8 = undefined;
49 var ctx = Aes128.initEnc(key);49 var ctx = Aes128.initEnc(key);
50 ctr(AesEncryptCtx(Aes128), ctx, out[0..], in[0..], iv, builtin.Endian.Big);50 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..]);
52}52}
5353
54test "encrypt" {54test "encrypt" {
...@@ -61,7 +61,7 @@ test "encrypt" {...@@ -61,7 +61,7 @@ test "encrypt" {
61 var out: [exp_out.len]u8 = undefined;61 var out: [exp_out.len]u8 = undefined;
62 var ctx = Aes128.initEnc(key);62 var ctx = Aes128.initEnc(key);
63 ctx.encrypt(out[0..], in[0..]);63 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..]);
65 }65 }
6666
67 // Appendix C.367 // Appendix C.3
...@@ -76,7 +76,7 @@ test "encrypt" {...@@ -76,7 +76,7 @@ test "encrypt" {
76 var out: [exp_out.len]u8 = undefined;76 var out: [exp_out.len]u8 = undefined;
77 var ctx = Aes256.initEnc(key);77 var ctx = Aes256.initEnc(key);
78 ctx.encrypt(out[0..], in[0..]);78 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..]);
80 }80 }
81}81}
8282
...@@ -90,7 +90,7 @@ test "decrypt" {...@@ -90,7 +90,7 @@ test "decrypt" {
90 var out: [exp_out.len]u8 = undefined;90 var out: [exp_out.len]u8 = undefined;
91 var ctx = Aes128.initDec(key);91 var ctx = Aes128.initDec(key);
92 ctx.decrypt(out[0..], in[0..]);92 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..]);
94 }94 }
9595
96 // Appendix C.396 // Appendix C.3
...@@ -105,7 +105,7 @@ test "decrypt" {...@@ -105,7 +105,7 @@ test "decrypt" {
105 var out: [exp_out.len]u8 = undefined;105 var out: [exp_out.len]u8 = undefined;
106 var ctx = Aes256.initDec(key);106 var ctx = Aes256.initDec(key);
107 ctx.decrypt(out[0..], in[0..]);107 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..]);
109 }109 }
110}110}
111111
...@@ -123,11 +123,11 @@ test "expand 128-bit key" {...@@ -123,11 +123,11 @@ test "expand 128-bit key" {
123123
124 for (enc.key_schedule.round_keys) |round_key, i| {124 for (enc.key_schedule.round_keys) |round_key, i| {
125 _ = try std.fmt.hexToBytes(&exp, exp_enc[i]);125 _ = 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());
127 }127 }
128 for (enc.key_schedule.round_keys) |round_key, i| {128 for (enc.key_schedule.round_keys) |round_key, i| {
129 _ = try std.fmt.hexToBytes(&exp, exp_dec[i]);129 _ = 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());
131 }131 }
132}132}
133133
...@@ -145,10 +145,10 @@ test "expand 256-bit key" {...@@ -145,10 +145,10 @@ test "expand 256-bit key" {
145145
146 for (enc.key_schedule.round_keys) |round_key, i| {146 for (enc.key_schedule.round_keys) |round_key, i| {
147 _ = try std.fmt.hexToBytes(&exp, exp_enc[i]);147 _ = 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());
149 }149 }
150 for (dec.key_schedule.round_keys) |round_key, i| {150 for (dec.key_schedule.round_keys) |round_key, i| {
151 _ = try std.fmt.hexToBytes(&exp, exp_dec[i]);151 _ = 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());
153 }153 }
154}154}
lib/std/crypto/aes_gcm.zig+8-8
...@@ -118,7 +118,7 @@ test "Aes256Gcm - Empty message and no associated data" {...@@ -118,7 +118,7 @@ test "Aes256Gcm - Empty message and no associated data" {
118 var tag: [Aes256Gcm.tag_length]u8 = undefined;118 var tag: [Aes256Gcm.tag_length]u8 = undefined;
119119
120 Aes256Gcm.encrypt(&c, &tag, m, ad, nonce, key);120 Aes256Gcm.encrypt(&c, &tag, m, ad, nonce, key);
121 htest.assertEqual("6b6ff610a16fa4cd59f1fb7903154e92", &tag);121 try htest.assertEqual("6b6ff610a16fa4cd59f1fb7903154e92", &tag);
122}122}
123123
124test "Aes256Gcm - Associated data only" {124test "Aes256Gcm - Associated data only" {
...@@ -130,7 +130,7 @@ test "Aes256Gcm - Associated data only" {...@@ -130,7 +130,7 @@ test "Aes256Gcm - Associated data only" {
130 var tag: [Aes256Gcm.tag_length]u8 = undefined;130 var tag: [Aes256Gcm.tag_length]u8 = undefined;
131131
132 Aes256Gcm.encrypt(&c, &tag, m, ad, nonce, key);132 Aes256Gcm.encrypt(&c, &tag, m, ad, nonce, key);
133 htest.assertEqual("262ed164c2dfb26e080a9d108dd9dd4c", &tag);133 try htest.assertEqual("262ed164c2dfb26e080a9d108dd9dd4c", &tag);
134}134}
135135
136test "Aes256Gcm - Message only" {136test "Aes256Gcm - Message only" {
...@@ -144,10 +144,10 @@ test "Aes256Gcm - Message only" {...@@ -144,10 +144,10 @@ test "Aes256Gcm - Message only" {
144144
145 Aes256Gcm.encrypt(&c, &tag, m, ad, nonce, key);145 Aes256Gcm.encrypt(&c, &tag, m, ad, nonce, key);
146 try Aes256Gcm.decrypt(&m2, &c, tag, ad, nonce, key);146 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);149 try htest.assertEqual("5ca1642d90009fea33d01f78cf6eefaf01d539472f7c", &c);
150 htest.assertEqual("07cd7fc9103e2f9e9bf2dfaa319caff4", &tag);150 try htest.assertEqual("07cd7fc9103e2f9e9bf2dfaa319caff4", &tag);
151}151}
152152
153test "Aes256Gcm - Message and associated data" {153test "Aes256Gcm - Message and associated data" {
...@@ -161,8 +161,8 @@ test "Aes256Gcm - Message and associated data" {...@@ -161,8 +161,8 @@ test "Aes256Gcm - Message and associated data" {
161161
162 Aes256Gcm.encrypt(&c, &tag, m, ad, nonce, key);162 Aes256Gcm.encrypt(&c, &tag, m, ad, nonce, key);
163 try Aes256Gcm.decrypt(&m2, &c, tag, ad, nonce, key);163 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);166 try htest.assertEqual("5ca1642d90009fea33d01f78cf6eefaf01", &c);
167 htest.assertEqual("64accec679d444e2373bd9f6796c0d2c", &tag);167 try htest.assertEqual("64accec679d444e2373bd9f6796c0d2c", &tag);
168}168}
lib/std/crypto/bcrypt.zig+2-2
...@@ -281,13 +281,13 @@ test "bcrypt codec" {...@@ -281,13 +281,13 @@ test "bcrypt codec" {
281 Codec.encode(salt_str[0..], salt[0..]);281 Codec.encode(salt_str[0..], salt[0..]);
282 var salt2: [salt_length]u8 = undefined;282 var salt2: [salt_length]u8 = undefined;
283 try Codec.decode(salt2[0..], salt_str[0..]);283 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..]);
285}285}
286286
287test "bcrypt" {287test "bcrypt" {
288 const s = try strHash("password", 5);288 const s = try strHash("password", 5);
289 try strVerify(s, "password");289 try strVerify(s, "password");
290 testing.expectError(error.PasswordVerificationFailed, strVerify(s, "invalid password"));290 try testing.expectError(error.PasswordVerificationFailed, strVerify(s, "invalid password"));
291291
292 const long_s = try strHash("password" ** 100, 5);292 const long_s = try strHash("password" ** 100, 5);
293 try strVerify(long_s, "password" ** 100);293 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 {...@@ -194,16 +194,16 @@ pub fn Blake2s(comptime out_bits: usize) type {
194194
195test "blake2s160 single" {195test "blake2s160 single" {
196 const h1 = "354c9c33f735962418bdacb9479873429c34916f";196 const h1 = "354c9c33f735962418bdacb9479873429c34916f";
197 htest.assertEqualHash(Blake2s160, h1, "");197 try htest.assertEqualHash(Blake2s160, h1, "");
198198
199 const h2 = "5ae3b99be29b01834c3b508521ede60438f8de17";199 const h2 = "5ae3b99be29b01834c3b508521ede60438f8de17";
200 htest.assertEqualHash(Blake2s160, h2, "abc");200 try htest.assertEqualHash(Blake2s160, h2, "abc");
201201
202 const h3 = "5a604fec9713c369e84b0ed68daed7d7504ef240";202 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
205 const h4 = "b60c4dc60e2681e58fbc24e77f07e02c69e72ed0";205 const h4 = "b60c4dc60e2681e58fbc24e77f07e02c69e72ed0";
206 htest.assertEqualHash(Blake2s160, h4, "a" ** 32 ++ "b" ** 32);206 try htest.assertEqualHash(Blake2s160, h4, "a" ** 32 ++ "b" ** 32);
207}207}
208208
209test "blake2s160 streaming" {209test "blake2s160 streaming" {
...@@ -213,21 +213,21 @@ test "blake2s160 streaming" {...@@ -213,21 +213,21 @@ test "blake2s160 streaming" {
213 const h1 = "354c9c33f735962418bdacb9479873429c34916f";213 const h1 = "354c9c33f735962418bdacb9479873429c34916f";
214214
215 h.final(out[0..]);215 h.final(out[0..]);
216 htest.assertEqual(h1, out[0..]);216 try htest.assertEqual(h1, out[0..]);
217217
218 const h2 = "5ae3b99be29b01834c3b508521ede60438f8de17";218 const h2 = "5ae3b99be29b01834c3b508521ede60438f8de17";
219219
220 h = Blake2s160.init(.{});220 h = Blake2s160.init(.{});
221 h.update("abc");221 h.update("abc");
222 h.final(out[0..]);222 h.final(out[0..]);
223 htest.assertEqual(h2, out[0..]);223 try htest.assertEqual(h2, out[0..]);
224224
225 h = Blake2s160.init(.{});225 h = Blake2s160.init(.{});
226 h.update("a");226 h.update("a");
227 h.update("b");227 h.update("b");
228 h.update("c");228 h.update("c");
229 h.final(out[0..]);229 h.final(out[0..]);
230 htest.assertEqual(h2, out[0..]);230 try htest.assertEqual(h2, out[0..]);
231231
232 const h3 = "b60c4dc60e2681e58fbc24e77f07e02c69e72ed0";232 const h3 = "b60c4dc60e2681e58fbc24e77f07e02c69e72ed0";
233233
...@@ -235,12 +235,12 @@ test "blake2s160 streaming" {...@@ -235,12 +235,12 @@ test "blake2s160 streaming" {
235 h.update("a" ** 32);235 h.update("a" ** 32);
236 h.update("b" ** 32);236 h.update("b" ** 32);
237 h.final(out[0..]);237 h.final(out[0..]);
238 htest.assertEqual(h3, out[0..]);238 try htest.assertEqual(h3, out[0..]);
239239
240 h = Blake2s160.init(.{});240 h = Blake2s160.init(.{});
241 h.update("a" ** 32 ++ "b" ** 32);241 h.update("a" ** 32 ++ "b" ** 32);
242 h.final(out[0..]);242 h.final(out[0..]);
243 htest.assertEqual(h3, out[0..]);243 try htest.assertEqual(h3, out[0..]);
244244
245 const h4 = "4667fd60791a7fe41f939bca646b4529e296bd68";245 const h4 = "4667fd60791a7fe41f939bca646b4529e296bd68";
246246
...@@ -248,12 +248,12 @@ test "blake2s160 streaming" {...@@ -248,12 +248,12 @@ test "blake2s160 streaming" {
248 h.update("a" ** 32);248 h.update("a" ** 32);
249 h.update("b" ** 32);249 h.update("b" ** 32);
250 h.final(out[0..]);250 h.final(out[0..]);
251 htest.assertEqual(h4, out[0..]);251 try htest.assertEqual(h4, out[0..]);
252252
253 h = Blake2s160.init(.{ .context = [_]u8{0x69} ** 8, .salt = [_]u8{0x42} ** 8 });253 h = Blake2s160.init(.{ .context = [_]u8{0x69} ** 8, .salt = [_]u8{0x42} ** 8 });
254 h.update("a" ** 32 ++ "b" ** 32);254 h.update("a" ** 32 ++ "b" ** 32);
255 h.final(out[0..]);255 h.final(out[0..]);
256 htest.assertEqual(h4, out[0..]);256 try htest.assertEqual(h4, out[0..]);
257}257}
258258
259test "comptime blake2s160" {259test "comptime blake2s160" {
...@@ -265,28 +265,28 @@ test "comptime blake2s160" {...@@ -265,28 +265,28 @@ test "comptime blake2s160" {
265265
266 const h1 = "2c56ad9d0b2c8b474aafa93ab307db2f0940105f";266 const h1 = "2c56ad9d0b2c8b474aafa93ab307db2f0940105f";
267267
268 htest.assertEqualHash(Blake2s160, h1, block[0..]);268 try htest.assertEqualHash(Blake2s160, h1, block[0..]);
269269
270 var h = Blake2s160.init(.{});270 var h = Blake2s160.init(.{});
271 h.update(&block);271 h.update(&block);
272 h.final(out[0..]);272 h.final(out[0..]);
273273
274 htest.assertEqual(h1, out[0..]);274 try htest.assertEqual(h1, out[0..]);
275 }275 }
276}276}
277277
278test "blake2s224 single" {278test "blake2s224 single" {
279 const h1 = "1fa1291e65248b37b3433475b2a0dd63d54a11ecc4e3e034e7bc1ef4";279 const h1 = "1fa1291e65248b37b3433475b2a0dd63d54a11ecc4e3e034e7bc1ef4";
280 htest.assertEqualHash(Blake2s224, h1, "");280 try htest.assertEqualHash(Blake2s224, h1, "");
281281
282 const h2 = "0b033fc226df7abde29f67a05d3dc62cf271ef3dfea4d387407fbd55";282 const h2 = "0b033fc226df7abde29f67a05d3dc62cf271ef3dfea4d387407fbd55";
283 htest.assertEqualHash(Blake2s224, h2, "abc");283 try htest.assertEqualHash(Blake2s224, h2, "abc");
284284
285 const h3 = "e4e5cb6c7cae41982b397bf7b7d2d9d1949823ae78435326e8db4912";285 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
288 const h4 = "557381a78facd2b298640f4e32113e58967d61420af1aa939d0cfe01";288 const h4 = "557381a78facd2b298640f4e32113e58967d61420af1aa939d0cfe01";
289 htest.assertEqualHash(Blake2s224, h4, "a" ** 32 ++ "b" ** 32);289 try htest.assertEqualHash(Blake2s224, h4, "a" ** 32 ++ "b" ** 32);
290}290}
291291
292test "blake2s224 streaming" {292test "blake2s224 streaming" {
...@@ -296,21 +296,21 @@ test "blake2s224 streaming" {...@@ -296,21 +296,21 @@ test "blake2s224 streaming" {
296 const h1 = "1fa1291e65248b37b3433475b2a0dd63d54a11ecc4e3e034e7bc1ef4";296 const h1 = "1fa1291e65248b37b3433475b2a0dd63d54a11ecc4e3e034e7bc1ef4";
297297
298 h.final(out[0..]);298 h.final(out[0..]);
299 htest.assertEqual(h1, out[0..]);299 try htest.assertEqual(h1, out[0..]);
300300
301 const h2 = "0b033fc226df7abde29f67a05d3dc62cf271ef3dfea4d387407fbd55";301 const h2 = "0b033fc226df7abde29f67a05d3dc62cf271ef3dfea4d387407fbd55";
302302
303 h = Blake2s224.init(.{});303 h = Blake2s224.init(.{});
304 h.update("abc");304 h.update("abc");
305 h.final(out[0..]);305 h.final(out[0..]);
306 htest.assertEqual(h2, out[0..]);306 try htest.assertEqual(h2, out[0..]);
307307
308 h = Blake2s224.init(.{});308 h = Blake2s224.init(.{});
309 h.update("a");309 h.update("a");
310 h.update("b");310 h.update("b");
311 h.update("c");311 h.update("c");
312 h.final(out[0..]);312 h.final(out[0..]);
313 htest.assertEqual(h2, out[0..]);313 try htest.assertEqual(h2, out[0..]);
314314
315 const h3 = "557381a78facd2b298640f4e32113e58967d61420af1aa939d0cfe01";315 const h3 = "557381a78facd2b298640f4e32113e58967d61420af1aa939d0cfe01";
316316
...@@ -318,12 +318,12 @@ test "blake2s224 streaming" {...@@ -318,12 +318,12 @@ test "blake2s224 streaming" {
318 h.update("a" ** 32);318 h.update("a" ** 32);
319 h.update("b" ** 32);319 h.update("b" ** 32);
320 h.final(out[0..]);320 h.final(out[0..]);
321 htest.assertEqual(h3, out[0..]);321 try htest.assertEqual(h3, out[0..]);
322322
323 h = Blake2s224.init(.{});323 h = Blake2s224.init(.{});
324 h.update("a" ** 32 ++ "b" ** 32);324 h.update("a" ** 32 ++ "b" ** 32);
325 h.final(out[0..]);325 h.final(out[0..]);
326 htest.assertEqual(h3, out[0..]);326 try htest.assertEqual(h3, out[0..]);
327327
328 const h4 = "a4d6a9d253441b80e5dfd60a04db169ffab77aec56a2855c402828c3";328 const h4 = "a4d6a9d253441b80e5dfd60a04db169ffab77aec56a2855c402828c3";
329329
...@@ -331,12 +331,12 @@ test "blake2s224 streaming" {...@@ -331,12 +331,12 @@ test "blake2s224 streaming" {
331 h.update("a" ** 32);331 h.update("a" ** 32);
332 h.update("b" ** 32);332 h.update("b" ** 32);
333 h.final(out[0..]);333 h.final(out[0..]);
334 htest.assertEqual(h4, out[0..]);334 try htest.assertEqual(h4, out[0..]);
335335
336 h = Blake2s224.init(.{ .context = [_]u8{0x69} ** 8, .salt = [_]u8{0x42} ** 8 });336 h = Blake2s224.init(.{ .context = [_]u8{0x69} ** 8, .salt = [_]u8{0x42} ** 8 });
337 h.update("a" ** 32 ++ "b" ** 32);337 h.update("a" ** 32 ++ "b" ** 32);
338 h.final(out[0..]);338 h.final(out[0..]);
339 htest.assertEqual(h4, out[0..]);339 try htest.assertEqual(h4, out[0..]);
340}340}
341341
342test "comptime blake2s224" {342test "comptime blake2s224" {
...@@ -347,28 +347,28 @@ test "comptime blake2s224" {...@@ -347,28 +347,28 @@ test "comptime blake2s224" {
347347
348 const h1 = "86b7611563293f8c73627df7a6d6ba25ca0548c2a6481f7d116ee576";348 const h1 = "86b7611563293f8c73627df7a6d6ba25ca0548c2a6481f7d116ee576";
349349
350 htest.assertEqualHash(Blake2s224, h1, block[0..]);350 try htest.assertEqualHash(Blake2s224, h1, block[0..]);
351351
352 var h = Blake2s224.init(.{});352 var h = Blake2s224.init(.{});
353 h.update(&block);353 h.update(&block);
354 h.final(out[0..]);354 h.final(out[0..]);
355355
356 htest.assertEqual(h1, out[0..]);356 try htest.assertEqual(h1, out[0..]);
357 }357 }
358}358}
359359
360test "blake2s256 single" {360test "blake2s256 single" {
361 const h1 = "69217a3079908094e11121d042354a7c1f55b6482ca1a51e1b250dfd1ed0eef9";361 const h1 = "69217a3079908094e11121d042354a7c1f55b6482ca1a51e1b250dfd1ed0eef9";
362 htest.assertEqualHash(Blake2s256, h1, "");362 try htest.assertEqualHash(Blake2s256, h1, "");
363363
364 const h2 = "508c5e8c327c14e2e1a72ba34eeb452f37458b209ed63a294d999b4c86675982";364 const h2 = "508c5e8c327c14e2e1a72ba34eeb452f37458b209ed63a294d999b4c86675982";
365 htest.assertEqualHash(Blake2s256, h2, "abc");365 try htest.assertEqualHash(Blake2s256, h2, "abc");
366366
367 const h3 = "606beeec743ccbeff6cbcdf5d5302aa855c256c29b88c8ed331ea1a6bf3c8812";367 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
370 const h4 = "8d8711dade07a6b92b9a3ea1f40bee9b2c53ff3edd2a273dec170b0163568977";370 const h4 = "8d8711dade07a6b92b9a3ea1f40bee9b2c53ff3edd2a273dec170b0163568977";
371 htest.assertEqualHash(Blake2s256, h4, "a" ** 32 ++ "b" ** 32);371 try htest.assertEqualHash(Blake2s256, h4, "a" ** 32 ++ "b" ** 32);
372}372}
373373
374test "blake2s256 streaming" {374test "blake2s256 streaming" {
...@@ -378,21 +378,21 @@ test "blake2s256 streaming" {...@@ -378,21 +378,21 @@ test "blake2s256 streaming" {
378 const h1 = "69217a3079908094e11121d042354a7c1f55b6482ca1a51e1b250dfd1ed0eef9";378 const h1 = "69217a3079908094e11121d042354a7c1f55b6482ca1a51e1b250dfd1ed0eef9";
379379
380 h.final(out[0..]);380 h.final(out[0..]);
381 htest.assertEqual(h1, out[0..]);381 try htest.assertEqual(h1, out[0..]);
382382
383 const h2 = "508c5e8c327c14e2e1a72ba34eeb452f37458b209ed63a294d999b4c86675982";383 const h2 = "508c5e8c327c14e2e1a72ba34eeb452f37458b209ed63a294d999b4c86675982";
384384
385 h = Blake2s256.init(.{});385 h = Blake2s256.init(.{});
386 h.update("abc");386 h.update("abc");
387 h.final(out[0..]);387 h.final(out[0..]);
388 htest.assertEqual(h2, out[0..]);388 try htest.assertEqual(h2, out[0..]);
389389
390 h = Blake2s256.init(.{});390 h = Blake2s256.init(.{});
391 h.update("a");391 h.update("a");
392 h.update("b");392 h.update("b");
393 h.update("c");393 h.update("c");
394 h.final(out[0..]);394 h.final(out[0..]);
395 htest.assertEqual(h2, out[0..]);395 try htest.assertEqual(h2, out[0..]);
396396
397 const h3 = "8d8711dade07a6b92b9a3ea1f40bee9b2c53ff3edd2a273dec170b0163568977";397 const h3 = "8d8711dade07a6b92b9a3ea1f40bee9b2c53ff3edd2a273dec170b0163568977";
398398
...@@ -400,12 +400,12 @@ test "blake2s256 streaming" {...@@ -400,12 +400,12 @@ test "blake2s256 streaming" {
400 h.update("a" ** 32);400 h.update("a" ** 32);
401 h.update("b" ** 32);401 h.update("b" ** 32);
402 h.final(out[0..]);402 h.final(out[0..]);
403 htest.assertEqual(h3, out[0..]);403 try htest.assertEqual(h3, out[0..]);
404404
405 h = Blake2s256.init(.{});405 h = Blake2s256.init(.{});
406 h.update("a" ** 32 ++ "b" ** 32);406 h.update("a" ** 32 ++ "b" ** 32);
407 h.final(out[0..]);407 h.final(out[0..]);
408 htest.assertEqual(h3, out[0..]);408 try htest.assertEqual(h3, out[0..]);
409}409}
410410
411test "blake2s256 keyed" {411test "blake2s256 keyed" {
...@@ -415,20 +415,20 @@ test "blake2s256 keyed" {...@@ -415,20 +415,20 @@ test "blake2s256 keyed" {
415 const key = "secret_key";415 const key = "secret_key";
416416
417 Blake2s256.hash("a" ** 64 ++ "b" ** 64, &out, .{ .key = key });417 Blake2s256.hash("a" ** 64 ++ "b" ** 64, &out, .{ .key = key });
418 htest.assertEqual(h1, out[0..]);418 try htest.assertEqual(h1, out[0..]);
419419
420 var h = Blake2s256.init(.{ .key = key });420 var h = Blake2s256.init(.{ .key = key });
421 h.update("a" ** 64 ++ "b" ** 64);421 h.update("a" ** 64 ++ "b" ** 64);
422 h.final(out[0..]);422 h.final(out[0..]);
423423
424 htest.assertEqual(h1, out[0..]);424 try htest.assertEqual(h1, out[0..]);
425425
426 h = Blake2s256.init(.{ .key = key });426 h = Blake2s256.init(.{ .key = key });
427 h.update("a" ** 64);427 h.update("a" ** 64);
428 h.update("b" ** 64);428 h.update("b" ** 64);
429 h.final(out[0..]);429 h.final(out[0..]);
430430
431 htest.assertEqual(h1, out[0..]);431 try htest.assertEqual(h1, out[0..]);
432}432}
433433
434test "comptime blake2s256" {434test "comptime blake2s256" {
...@@ -439,13 +439,13 @@ test "comptime blake2s256" {...@@ -439,13 +439,13 @@ test "comptime blake2s256" {
439439
440 const h1 = "ae09db7cd54f42b490ef09b6bc541af688e4959bb8c53f359a6f56e38ab454a3";440 const h1 = "ae09db7cd54f42b490ef09b6bc541af688e4959bb8c53f359a6f56e38ab454a3";
441441
442 htest.assertEqualHash(Blake2s256, h1, block[0..]);442 try htest.assertEqualHash(Blake2s256, h1, block[0..]);
443443
444 var h = Blake2s256.init(.{});444 var h = Blake2s256.init(.{});
445 h.update(&block);445 h.update(&block);
446 h.final(out[0..]);446 h.final(out[0..]);
447447
448 htest.assertEqual(h1, out[0..]);448 try htest.assertEqual(h1, out[0..]);
449 }449 }
450}450}
451451
...@@ -617,16 +617,16 @@ pub fn Blake2b(comptime out_bits: usize) type {...@@ -617,16 +617,16 @@ pub fn Blake2b(comptime out_bits: usize) type {
617617
618test "blake2b160 single" {618test "blake2b160 single" {
619 const h1 = "3345524abf6bbe1809449224b5972c41790b6cf2";619 const h1 = "3345524abf6bbe1809449224b5972c41790b6cf2";
620 htest.assertEqualHash(Blake2b160, h1, "");620 try htest.assertEqualHash(Blake2b160, h1, "");
621621
622 const h2 = "384264f676f39536840523f284921cdc68b6846b";622 const h2 = "384264f676f39536840523f284921cdc68b6846b";
623 htest.assertEqualHash(Blake2b160, h2, "abc");623 try htest.assertEqualHash(Blake2b160, h2, "abc");
624624
625 const h3 = "3c523ed102ab45a37d54f5610d5a983162fde84f";625 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
628 const h4 = "43758f5de1740f651f1ae39de92260fe8bd5a11f";628 const h4 = "43758f5de1740f651f1ae39de92260fe8bd5a11f";
629 htest.assertEqualHash(Blake2b160, h4, "a" ** 64 ++ "b" ** 64);629 try htest.assertEqualHash(Blake2b160, h4, "a" ** 64 ++ "b" ** 64);
630}630}
631631
632test "blake2b160 streaming" {632test "blake2b160 streaming" {
...@@ -636,40 +636,40 @@ test "blake2b160 streaming" {...@@ -636,40 +636,40 @@ test "blake2b160 streaming" {
636 const h1 = "3345524abf6bbe1809449224b5972c41790b6cf2";636 const h1 = "3345524abf6bbe1809449224b5972c41790b6cf2";
637637
638 h.final(out[0..]);638 h.final(out[0..]);
639 htest.assertEqual(h1, out[0..]);639 try htest.assertEqual(h1, out[0..]);
640640
641 const h2 = "384264f676f39536840523f284921cdc68b6846b";641 const h2 = "384264f676f39536840523f284921cdc68b6846b";
642642
643 h = Blake2b160.init(.{});643 h = Blake2b160.init(.{});
644 h.update("abc");644 h.update("abc");
645 h.final(out[0..]);645 h.final(out[0..]);
646 htest.assertEqual(h2, out[0..]);646 try htest.assertEqual(h2, out[0..]);
647647
648 h = Blake2b160.init(.{});648 h = Blake2b160.init(.{});
649 h.update("a");649 h.update("a");
650 h.update("b");650 h.update("b");
651 h.update("c");651 h.update("c");
652 h.final(out[0..]);652 h.final(out[0..]);
653 htest.assertEqual(h2, out[0..]);653 try htest.assertEqual(h2, out[0..]);
654654
655 const h3 = "43758f5de1740f651f1ae39de92260fe8bd5a11f";655 const h3 = "43758f5de1740f651f1ae39de92260fe8bd5a11f";
656656
657 h = Blake2b160.init(.{});657 h = Blake2b160.init(.{});
658 h.update("a" ** 64 ++ "b" ** 64);658 h.update("a" ** 64 ++ "b" ** 64);
659 h.final(out[0..]);659 h.final(out[0..]);
660 htest.assertEqual(h3, out[0..]);660 try htest.assertEqual(h3, out[0..]);
661661
662 h = Blake2b160.init(.{});662 h = Blake2b160.init(.{});
663 h.update("a" ** 64);663 h.update("a" ** 64);
664 h.update("b" ** 64);664 h.update("b" ** 64);
665 h.final(out[0..]);665 h.final(out[0..]);
666 htest.assertEqual(h3, out[0..]);666 try htest.assertEqual(h3, out[0..]);
667667
668 h = Blake2b160.init(.{});668 h = Blake2b160.init(.{});
669 h.update("a" ** 64);669 h.update("a" ** 64);
670 h.update("b" ** 64);670 h.update("b" ** 64);
671 h.final(out[0..]);671 h.final(out[0..]);
672 htest.assertEqual(h3, out[0..]);672 try htest.assertEqual(h3, out[0..]);
673673
674 const h4 = "72328f8a8200663752fc302d372b5dd9b49dd8dc";674 const h4 = "72328f8a8200663752fc302d372b5dd9b49dd8dc";
675675
...@@ -677,13 +677,13 @@ test "blake2b160 streaming" {...@@ -677,13 +677,13 @@ test "blake2b160 streaming" {
677 h.update("a" ** 64);677 h.update("a" ** 64);
678 h.update("b" ** 64);678 h.update("b" ** 64);
679 h.final(out[0..]);679 h.final(out[0..]);
680 htest.assertEqual(h4, out[0..]);680 try htest.assertEqual(h4, out[0..]);
681681
682 h = Blake2b160.init(.{ .context = [_]u8{0x69} ** 16, .salt = [_]u8{0x42} ** 16 });682 h = Blake2b160.init(.{ .context = [_]u8{0x69} ** 16, .salt = [_]u8{0x42} ** 16 });
683 h.update("a" ** 64);683 h.update("a" ** 64);
684 h.update("b" ** 64);684 h.update("b" ** 64);
685 h.final(out[0..]);685 h.final(out[0..]);
686 htest.assertEqual(h4, out[0..]);686 try htest.assertEqual(h4, out[0..]);
687}687}
688688
689test "comptime blake2b160" {689test "comptime blake2b160" {
...@@ -694,28 +694,28 @@ test "comptime blake2b160" {...@@ -694,28 +694,28 @@ test "comptime blake2b160" {
694694
695 const h1 = "8d26f158f564e3293b42f5e3d34263cb173aa9c9";695 const h1 = "8d26f158f564e3293b42f5e3d34263cb173aa9c9";
696696
697 htest.assertEqualHash(Blake2b160, h1, block[0..]);697 try htest.assertEqualHash(Blake2b160, h1, block[0..]);
698698
699 var h = Blake2b160.init(.{});699 var h = Blake2b160.init(.{});
700 h.update(&block);700 h.update(&block);
701 h.final(out[0..]);701 h.final(out[0..]);
702702
703 htest.assertEqual(h1, out[0..]);703 try htest.assertEqual(h1, out[0..]);
704 }704 }
705}705}
706706
707test "blake2b384 single" {707test "blake2b384 single" {
708 const h1 = "b32811423377f52d7862286ee1a72ee540524380fda1724a6f25d7978c6fd3244a6caf0498812673c5e05ef583825100";708 const h1 = "b32811423377f52d7862286ee1a72ee540524380fda1724a6f25d7978c6fd3244a6caf0498812673c5e05ef583825100";
709 htest.assertEqualHash(Blake2b384, h1, "");709 try htest.assertEqualHash(Blake2b384, h1, "");
710710
711 const h2 = "6f56a82c8e7ef526dfe182eb5212f7db9df1317e57815dbda46083fc30f54ee6c66ba83be64b302d7cba6ce15bb556f4";711 const h2 = "6f56a82c8e7ef526dfe182eb5212f7db9df1317e57815dbda46083fc30f54ee6c66ba83be64b302d7cba6ce15bb556f4";
712 htest.assertEqualHash(Blake2b384, h2, "abc");712 try htest.assertEqualHash(Blake2b384, h2, "abc");
713713
714 const h3 = "b7c81b228b6bd912930e8f0b5387989691c1cee1e65aade4da3b86a3c9f678fc8018f6ed9e2906720c8d2a3aeda9c03d";714 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
717 const h4 = "b7283f0172fecbbd7eca32ce10d8a6c06b453cb3cf675b33eb4246f0da2bb94a6c0bdd6eec0b5fd71ec4fd51be80bf4c";717 const h4 = "b7283f0172fecbbd7eca32ce10d8a6c06b453cb3cf675b33eb4246f0da2bb94a6c0bdd6eec0b5fd71ec4fd51be80bf4c";
718 htest.assertEqualHash(Blake2b384, h4, "a" ** 64 ++ "b" ** 64);718 try htest.assertEqualHash(Blake2b384, h4, "a" ** 64 ++ "b" ** 64);
719}719}
720720
721test "blake2b384 streaming" {721test "blake2b384 streaming" {
...@@ -725,40 +725,40 @@ test "blake2b384 streaming" {...@@ -725,40 +725,40 @@ test "blake2b384 streaming" {
725 const h1 = "b32811423377f52d7862286ee1a72ee540524380fda1724a6f25d7978c6fd3244a6caf0498812673c5e05ef583825100";725 const h1 = "b32811423377f52d7862286ee1a72ee540524380fda1724a6f25d7978c6fd3244a6caf0498812673c5e05ef583825100";
726726
727 h.final(out[0..]);727 h.final(out[0..]);
728 htest.assertEqual(h1, out[0..]);728 try htest.assertEqual(h1, out[0..]);
729729
730 const h2 = "6f56a82c8e7ef526dfe182eb5212f7db9df1317e57815dbda46083fc30f54ee6c66ba83be64b302d7cba6ce15bb556f4";730 const h2 = "6f56a82c8e7ef526dfe182eb5212f7db9df1317e57815dbda46083fc30f54ee6c66ba83be64b302d7cba6ce15bb556f4";
731731
732 h = Blake2b384.init(.{});732 h = Blake2b384.init(.{});
733 h.update("abc");733 h.update("abc");
734 h.final(out[0..]);734 h.final(out[0..]);
735 htest.assertEqual(h2, out[0..]);735 try htest.assertEqual(h2, out[0..]);
736736
737 h = Blake2b384.init(.{});737 h = Blake2b384.init(.{});
738 h.update("a");738 h.update("a");
739 h.update("b");739 h.update("b");
740 h.update("c");740 h.update("c");
741 h.final(out[0..]);741 h.final(out[0..]);
742 htest.assertEqual(h2, out[0..]);742 try htest.assertEqual(h2, out[0..]);
743743
744 const h3 = "b7283f0172fecbbd7eca32ce10d8a6c06b453cb3cf675b33eb4246f0da2bb94a6c0bdd6eec0b5fd71ec4fd51be80bf4c";744 const h3 = "b7283f0172fecbbd7eca32ce10d8a6c06b453cb3cf675b33eb4246f0da2bb94a6c0bdd6eec0b5fd71ec4fd51be80bf4c";
745745
746 h = Blake2b384.init(.{});746 h = Blake2b384.init(.{});
747 h.update("a" ** 64 ++ "b" ** 64);747 h.update("a" ** 64 ++ "b" ** 64);
748 h.final(out[0..]);748 h.final(out[0..]);
749 htest.assertEqual(h3, out[0..]);749 try htest.assertEqual(h3, out[0..]);
750750
751 h = Blake2b384.init(.{});751 h = Blake2b384.init(.{});
752 h.update("a" ** 64);752 h.update("a" ** 64);
753 h.update("b" ** 64);753 h.update("b" ** 64);
754 h.final(out[0..]);754 h.final(out[0..]);
755 htest.assertEqual(h3, out[0..]);755 try htest.assertEqual(h3, out[0..]);
756756
757 h = Blake2b384.init(.{});757 h = Blake2b384.init(.{});
758 h.update("a" ** 64);758 h.update("a" ** 64);
759 h.update("b" ** 64);759 h.update("b" ** 64);
760 h.final(out[0..]);760 h.final(out[0..]);
761 htest.assertEqual(h3, out[0..]);761 try htest.assertEqual(h3, out[0..]);
762762
763 const h4 = "934c48fcb197031c71f583d92f98703510805e72142e0b46f5752d1e971bc86c355d556035613ff7a4154b4de09dac5c";763 const h4 = "934c48fcb197031c71f583d92f98703510805e72142e0b46f5752d1e971bc86c355d556035613ff7a4154b4de09dac5c";
764764
...@@ -766,13 +766,13 @@ test "blake2b384 streaming" {...@@ -766,13 +766,13 @@ test "blake2b384 streaming" {
766 h.update("a" ** 64);766 h.update("a" ** 64);
767 h.update("b" ** 64);767 h.update("b" ** 64);
768 h.final(out[0..]);768 h.final(out[0..]);
769 htest.assertEqual(h4, out[0..]);769 try htest.assertEqual(h4, out[0..]);
770770
771 h = Blake2b384.init(.{ .context = [_]u8{0x69} ** 16, .salt = [_]u8{0x42} ** 16 });771 h = Blake2b384.init(.{ .context = [_]u8{0x69} ** 16, .salt = [_]u8{0x42} ** 16 });
772 h.update("a" ** 64);772 h.update("a" ** 64);
773 h.update("b" ** 64);773 h.update("b" ** 64);
774 h.final(out[0..]);774 h.final(out[0..]);
775 htest.assertEqual(h4, out[0..]);775 try htest.assertEqual(h4, out[0..]);
776}776}
777777
778test "comptime blake2b384" {778test "comptime blake2b384" {
...@@ -783,28 +783,28 @@ test "comptime blake2b384" {...@@ -783,28 +783,28 @@ test "comptime blake2b384" {
783783
784 const h1 = "e8aa1931ea0422e4446fecdd25c16cf35c240b10cb4659dd5c776eddcaa4d922397a589404b46eb2e53d78132d05fd7d";784 const h1 = "e8aa1931ea0422e4446fecdd25c16cf35c240b10cb4659dd5c776eddcaa4d922397a589404b46eb2e53d78132d05fd7d";
785785
786 htest.assertEqualHash(Blake2b384, h1, block[0..]);786 try htest.assertEqualHash(Blake2b384, h1, block[0..]);
787787
788 var h = Blake2b384.init(.{});788 var h = Blake2b384.init(.{});
789 h.update(&block);789 h.update(&block);
790 h.final(out[0..]);790 h.final(out[0..]);
791791
792 htest.assertEqual(h1, out[0..]);792 try htest.assertEqual(h1, out[0..]);
793 }793 }
794}794}
795795
796test "blake2b512 single" {796test "blake2b512 single" {
797 const h1 = "786a02f742015903c6c6fd852552d272912f4740e15847618a86e217f71f5419d25e1031afee585313896444934eb04b903a685b1448b755d56f701afe9be2ce";797 const h1 = "786a02f742015903c6c6fd852552d272912f4740e15847618a86e217f71f5419d25e1031afee585313896444934eb04b903a685b1448b755d56f701afe9be2ce";
798 htest.assertEqualHash(Blake2b512, h1, "");798 try htest.assertEqualHash(Blake2b512, h1, "");
799799
800 const h2 = "ba80a53f981c4d0d6a2797b69f12f6e94c212f14685ac4b74b12bb6fdbffa2d17d87c5392aab792dc252d5de4533cc9518d38aa8dbf1925ab92386edd4009923";800 const h2 = "ba80a53f981c4d0d6a2797b69f12f6e94c212f14685ac4b74b12bb6fdbffa2d17d87c5392aab792dc252d5de4533cc9518d38aa8dbf1925ab92386edd4009923";
801 htest.assertEqualHash(Blake2b512, h2, "abc");801 try htest.assertEqualHash(Blake2b512, h2, "abc");
802802
803 const h3 = "a8add4bdddfd93e4877d2746e62817b116364a1fa7bc148d95090bc7333b3673f82401cf7aa2e4cb1ecd90296e3f14cb5413f8ed77be73045b13914cdcd6a918";803 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
806 const h4 = "049980af04d6a2cf16b4b49793c3ed7e40732073788806f2c989ebe9547bda0541d63abe298ec8955d08af48ae731f2e8a0bd6d201655a5473b4aa79d211b920";806 const h4 = "049980af04d6a2cf16b4b49793c3ed7e40732073788806f2c989ebe9547bda0541d63abe298ec8955d08af48ae731f2e8a0bd6d201655a5473b4aa79d211b920";
807 htest.assertEqualHash(Blake2b512, h4, "a" ** 64 ++ "b" ** 64);807 try htest.assertEqualHash(Blake2b512, h4, "a" ** 64 ++ "b" ** 64);
808}808}
809809
810test "blake2b512 streaming" {810test "blake2b512 streaming" {
...@@ -814,34 +814,34 @@ test "blake2b512 streaming" {...@@ -814,34 +814,34 @@ test "blake2b512 streaming" {
814 const h1 = "786a02f742015903c6c6fd852552d272912f4740e15847618a86e217f71f5419d25e1031afee585313896444934eb04b903a685b1448b755d56f701afe9be2ce";814 const h1 = "786a02f742015903c6c6fd852552d272912f4740e15847618a86e217f71f5419d25e1031afee585313896444934eb04b903a685b1448b755d56f701afe9be2ce";
815815
816 h.final(out[0..]);816 h.final(out[0..]);
817 htest.assertEqual(h1, out[0..]);817 try htest.assertEqual(h1, out[0..]);
818818
819 const h2 = "ba80a53f981c4d0d6a2797b69f12f6e94c212f14685ac4b74b12bb6fdbffa2d17d87c5392aab792dc252d5de4533cc9518d38aa8dbf1925ab92386edd4009923";819 const h2 = "ba80a53f981c4d0d6a2797b69f12f6e94c212f14685ac4b74b12bb6fdbffa2d17d87c5392aab792dc252d5de4533cc9518d38aa8dbf1925ab92386edd4009923";
820820
821 h = Blake2b512.init(.{});821 h = Blake2b512.init(.{});
822 h.update("abc");822 h.update("abc");
823 h.final(out[0..]);823 h.final(out[0..]);
824 htest.assertEqual(h2, out[0..]);824 try htest.assertEqual(h2, out[0..]);
825825
826 h = Blake2b512.init(.{});826 h = Blake2b512.init(.{});
827 h.update("a");827 h.update("a");
828 h.update("b");828 h.update("b");
829 h.update("c");829 h.update("c");
830 h.final(out[0..]);830 h.final(out[0..]);
831 htest.assertEqual(h2, out[0..]);831 try htest.assertEqual(h2, out[0..]);
832832
833 const h3 = "049980af04d6a2cf16b4b49793c3ed7e40732073788806f2c989ebe9547bda0541d63abe298ec8955d08af48ae731f2e8a0bd6d201655a5473b4aa79d211b920";833 const h3 = "049980af04d6a2cf16b4b49793c3ed7e40732073788806f2c989ebe9547bda0541d63abe298ec8955d08af48ae731f2e8a0bd6d201655a5473b4aa79d211b920";
834834
835 h = Blake2b512.init(.{});835 h = Blake2b512.init(.{});
836 h.update("a" ** 64 ++ "b" ** 64);836 h.update("a" ** 64 ++ "b" ** 64);
837 h.final(out[0..]);837 h.final(out[0..]);
838 htest.assertEqual(h3, out[0..]);838 try htest.assertEqual(h3, out[0..]);
839839
840 h = Blake2b512.init(.{});840 h = Blake2b512.init(.{});
841 h.update("a" ** 64);841 h.update("a" ** 64);
842 h.update("b" ** 64);842 h.update("b" ** 64);
843 h.final(out[0..]);843 h.final(out[0..]);
844 htest.assertEqual(h3, out[0..]);844 try htest.assertEqual(h3, out[0..]);
845}845}
846846
847test "blake2b512 keyed" {847test "blake2b512 keyed" {
...@@ -851,20 +851,20 @@ test "blake2b512 keyed" {...@@ -851,20 +851,20 @@ test "blake2b512 keyed" {
851 const key = "secret_key";851 const key = "secret_key";
852852
853 Blake2b512.hash("a" ** 64 ++ "b" ** 64, &out, .{ .key = key });853 Blake2b512.hash("a" ** 64 ++ "b" ** 64, &out, .{ .key = key });
854 htest.assertEqual(h1, out[0..]);854 try htest.assertEqual(h1, out[0..]);
855855
856 var h = Blake2b512.init(.{ .key = key });856 var h = Blake2b512.init(.{ .key = key });
857 h.update("a" ** 64 ++ "b" ** 64);857 h.update("a" ** 64 ++ "b" ** 64);
858 h.final(out[0..]);858 h.final(out[0..]);
859859
860 htest.assertEqual(h1, out[0..]);860 try htest.assertEqual(h1, out[0..]);
861861
862 h = Blake2b512.init(.{ .key = key });862 h = Blake2b512.init(.{ .key = key });
863 h.update("a" ** 64);863 h.update("a" ** 64);
864 h.update("b" ** 64);864 h.update("b" ** 64);
865 h.final(out[0..]);865 h.final(out[0..]);
866866
867 htest.assertEqual(h1, out[0..]);867 try htest.assertEqual(h1, out[0..]);
868}868}
869869
870test "comptime blake2b512" {870test "comptime blake2b512" {
...@@ -875,12 +875,12 @@ test "comptime blake2b512" {...@@ -875,12 +875,12 @@ test "comptime blake2b512" {
875875
876 const h1 = "865939e120e6805438478841afb739ae4250cf372653078a065cdcfffca4caf798e6d462b65d658fc165782640eded70963449ae1500fb0f24981d7727e22c41";876 const h1 = "865939e120e6805438478841afb739ae4250cf372653078a065cdcfffca4caf798e6d462b65d658fc165782640eded70963449ae1500fb0f24981d7727e22c41";
877877
878 htest.assertEqualHash(Blake2b512, h1, block[0..]);878 try htest.assertEqualHash(Blake2b512, h1, block[0..]);
879879
880 var h = Blake2b512.init(.{});880 var h = Blake2b512.init(.{});
881 h.update(&block);881 h.update(&block);
882 h.final(out[0..]);882 h.final(out[0..]);
883883
884 htest.assertEqual(h1, out[0..]);884 try htest.assertEqual(h1, out[0..]);
885 }885 }
886}886}
lib/std/crypto/blake3.zig+5-5
...@@ -641,7 +641,7 @@ const reference_test = ReferenceTest{...@@ -641,7 +641,7 @@ const reference_test = ReferenceTest{
641 },641 },
642};642};
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 {
645 // Save initial state645 // Save initial state
646 const initial_state = hasher.*;646 const initial_state = hasher.*;
647647
...@@ -664,7 +664,7 @@ fn testBlake3(hasher: *Blake3, input_len: usize, expected_hex: [262]u8) void {...@@ -664,7 +664,7 @@ fn testBlake3(hasher: *Blake3, input_len: usize, expected_hex: [262]u8) void {
664 // Compare to expected value664 // Compare to expected value
665 var expected_bytes: [expected_hex.len / 2]u8 = undefined;665 var expected_bytes: [expected_hex.len / 2]u8 = undefined;
666 _ = fmt.hexToBytes(expected_bytes[0..], expected_hex[0..]) catch unreachable;666 _ = 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
669 // Restore initial state669 // Restore initial state
670 hasher.* = initial_state;670 hasher.* = initial_state;
...@@ -676,8 +676,8 @@ test "BLAKE3 reference test cases" {...@@ -676,8 +676,8 @@ test "BLAKE3 reference test cases" {
676 var derive_key = &Blake3.initKdf(reference_test.context_string, .{});676 var derive_key = &Blake3.initKdf(reference_test.context_string, .{});
677677
678 for (reference_test.cases) |t| {678 for (reference_test.cases) |t| {
679 testBlake3(hash, t.input_len, t.hash.*);679 try testBlake3(hash, t.input_len, t.hash.*);
680 testBlake3(keyed_hash, t.input_len, t.keyed_hash.*);680 try testBlake3(keyed_hash, t.input_len, t.keyed_hash.*);
681 testBlake3(derive_key, t.input_len, t.derive_key.*);681 try testBlake3(derive_key, t.input_len, t.derive_key.*);
682 }682 }
683}683}
lib/std/crypto/chacha20.zig+21-21
...@@ -604,9 +604,9 @@ test "chacha20 AEAD API" {...@@ -604,9 +604,9 @@ test "chacha20 AEAD API" {
604604
605 aead.encrypt(c[0..], tag[0..], m, ad, nonce, key);605 aead.encrypt(c[0..], tag[0..], m, ad, nonce, key);
606 try aead.decrypt(out[0..], c[0..], tag, ad[0..], nonce, key);606 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);
608 c[0] += 1;608 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));
610 }610 }
611}611}
612612
...@@ -644,11 +644,11 @@ test "crypto.chacha20 test vector sunscreen" {...@@ -644,11 +644,11 @@ test "crypto.chacha20 test vector sunscreen" {
644 };644 };
645645
646 ChaCha20IETF.xor(result[0..], m[0..], 1, key, nonce);646 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
649 var m2: [114]u8 = undefined;649 var m2: [114]u8 = undefined;
650 ChaCha20IETF.xor(m2[0..], result[0..], 1, key, nonce);650 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);
652}652}
653653
654// https://tools.ietf.org/html/draft-agl-tls-chacha20poly1305-04#section-7654// https://tools.ietf.org/html/draft-agl-tls-chacha20poly1305-04#section-7
...@@ -683,7 +683,7 @@ test "crypto.chacha20 test vector 1" {...@@ -683,7 +683,7 @@ test "crypto.chacha20 test vector 1" {
683 const nonce = [_]u8{ 0, 0, 0, 0, 0, 0, 0, 0 };683 const nonce = [_]u8{ 0, 0, 0, 0, 0, 0, 0, 0 };
684684
685 ChaCha20With64BitNonce.xor(result[0..], m[0..], 0, key, nonce);685 ChaCha20With64BitNonce.xor(result[0..], m[0..], 0, key, nonce);
686 testing.expectEqualSlices(u8, &expected_result, &result);686 try testing.expectEqualSlices(u8, &expected_result, &result);
687}687}
688688
689test "crypto.chacha20 test vector 2" {689test "crypto.chacha20 test vector 2" {
...@@ -717,7 +717,7 @@ test "crypto.chacha20 test vector 2" {...@@ -717,7 +717,7 @@ test "crypto.chacha20 test vector 2" {
717 const nonce = [_]u8{ 0, 0, 0, 0, 0, 0, 0, 0 };717 const nonce = [_]u8{ 0, 0, 0, 0, 0, 0, 0, 0 };
718718
719 ChaCha20With64BitNonce.xor(result[0..], m[0..], 0, key, nonce);719 ChaCha20With64BitNonce.xor(result[0..], m[0..], 0, key, nonce);
720 testing.expectEqualSlices(u8, &expected_result, &result);720 try testing.expectEqualSlices(u8, &expected_result, &result);
721}721}
722722
723test "crypto.chacha20 test vector 3" {723test "crypto.chacha20 test vector 3" {
...@@ -751,7 +751,7 @@ test "crypto.chacha20 test vector 3" {...@@ -751,7 +751,7 @@ test "crypto.chacha20 test vector 3" {
751 const nonce = [_]u8{ 0, 0, 0, 0, 0, 0, 0, 1 };751 const nonce = [_]u8{ 0, 0, 0, 0, 0, 0, 0, 1 };
752752
753 ChaCha20With64BitNonce.xor(result[0..], m[0..], 0, key, nonce);753 ChaCha20With64BitNonce.xor(result[0..], m[0..], 0, key, nonce);
754 testing.expectEqualSlices(u8, &expected_result, &result);754 try testing.expectEqualSlices(u8, &expected_result, &result);
755}755}
756756
757test "crypto.chacha20 test vector 4" {757test "crypto.chacha20 test vector 4" {
...@@ -785,7 +785,7 @@ test "crypto.chacha20 test vector 4" {...@@ -785,7 +785,7 @@ test "crypto.chacha20 test vector 4" {
785 const nonce = [_]u8{ 1, 0, 0, 0, 0, 0, 0, 0 };785 const nonce = [_]u8{ 1, 0, 0, 0, 0, 0, 0, 0 };
786786
787 ChaCha20With64BitNonce.xor(result[0..], m[0..], 0, key, nonce);787 ChaCha20With64BitNonce.xor(result[0..], m[0..], 0, key, nonce);
788 testing.expectEqualSlices(u8, &expected_result, &result);788 try testing.expectEqualSlices(u8, &expected_result, &result);
789}789}
790790
791test "crypto.chacha20 test vector 5" {791test "crypto.chacha20 test vector 5" {
...@@ -857,7 +857,7 @@ test "crypto.chacha20 test vector 5" {...@@ -857,7 +857,7 @@ test "crypto.chacha20 test vector 5" {
857 };857 };
858858
859 ChaCha20With64BitNonce.xor(result[0..], m[0..], 0, key, nonce);859 ChaCha20With64BitNonce.xor(result[0..], m[0..], 0, key, nonce);
860 testing.expectEqualSlices(u8, &expected_result, &result);860 try testing.expectEqualSlices(u8, &expected_result, &result);
861}861}
862862
863test "seal" {863test "seal" {
...@@ -873,7 +873,7 @@ test "seal" {...@@ -873,7 +873,7 @@ test "seal" {
873873
874 var out: [exp_out.len]u8 = undefined;874 var out: [exp_out.len]u8 = undefined;
875 ChaCha20Poly1305.encrypt(out[0..m.len], out[m.len..], m, ad, nonce, key);875 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..]);
877 }877 }
878 {878 {
879 const m = [_]u8{879 const m = [_]u8{
...@@ -906,7 +906,7 @@ test "seal" {...@@ -906,7 +906,7 @@ test "seal" {
906906
907 var out: [exp_out.len]u8 = undefined;907 var out: [exp_out.len]u8 = undefined;
908 ChaCha20Poly1305.encrypt(out[0..m.len], out[m.len..], m[0..], ad[0..], nonce, key);908 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..]);
910 }910 }
911}911}
912912
...@@ -923,7 +923,7 @@ test "open" {...@@ -923,7 +923,7 @@ test "open" {
923923
924 var out: [exp_out.len]u8 = undefined;924 var out: [exp_out.len]u8 = undefined;
925 try ChaCha20Poly1305.decrypt(out[0..], c[0..exp_out.len], c[exp_out.len..].*, ad[0..], nonce, key);925 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..]);
927 }927 }
928 {928 {
929 const c = [_]u8{929 const c = [_]u8{
...@@ -956,21 +956,21 @@ test "open" {...@@ -956,21 +956,21 @@ test "open" {
956956
957 var out: [exp_out.len]u8 = undefined;957 var out: [exp_out.len]u8 = undefined;
958 try ChaCha20Poly1305.decrypt(out[0..], c[0..exp_out.len], c[exp_out.len..].*, ad[0..], nonce, key);958 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
961 // corrupting the ciphertext, data, key, or nonce should cause a failure961 // corrupting the ciphertext, data, key, or nonce should cause a failure
962 var bad_c = c;962 var bad_c = c;
963 bad_c[0] ^= 1;963 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));
965 var bad_ad = ad;965 var bad_ad = ad;
966 bad_ad[0] ^= 1;966 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));
968 var bad_key = key;968 var bad_key = key;
969 bad_key[0] ^= 1;969 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));
971 var bad_nonce = nonce;971 var bad_nonce = nonce;
972 bad_nonce[0] ^= 1;972 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));
974 }974 }
975}975}
976976
...@@ -982,7 +982,7 @@ test "crypto.xchacha20" {...@@ -982,7 +982,7 @@ test "crypto.xchacha20" {
982 var c: [m.len]u8 = undefined;982 var c: [m.len]u8 = undefined;
983 XChaCha20IETF.xor(c[0..], m[0..], 0, key, nonce);983 XChaCha20IETF.xor(c[0..], m[0..], 0, key, nonce);
984 var buf: [2 * c.len]u8 = undefined;984 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");
986 }986 }
987 {987 {
988 const ad = "Additional data";988 const ad = "Additional data";
...@@ -991,9 +991,9 @@ test "crypto.xchacha20" {...@@ -991,9 +991,9 @@ test "crypto.xchacha20" {
991 var out: [m.len]u8 = undefined;991 var out: [m.len]u8 = undefined;
992 try XChaCha20Poly1305.decrypt(out[0..], c[0..m.len], c[m.len..].*, ad, nonce, key);992 try XChaCha20Poly1305.decrypt(out[0..], c[0..m.len], c[m.len..].*, ad, nonce, key);
993 var buf: [2 * c.len]u8 = undefined;993 var buf: [2 * c.len]u8 = undefined;
994 testing.expectEqualStrings(try std.fmt.bufPrint(&buf, "{s}", .{std.fmt.fmtSliceHexUpper(&c)}), "994D2DD32333F48E53650C02C7A2ABB8E018B0836D7175AEC779F52E961780768F815C58F1AA52D211498DB89B9216763F569C9433A6BBFCEFB4D4A49387A4C5207FBB3B5A92B5941294DF30588C6740D39DC16FA1F0E634F7246CF7CDCB978E44347D89381B7A74EB7084F754B90BDE9AAF5A94B8F2A85EFD0B50692AE2D425E234");994 try testing.expectEqualStrings(try std.fmt.bufPrint(&buf, "{s}", .{std.fmt.fmtSliceHexUpper(&c)}), "994D2DD32333F48E53650C02C7A2ABB8E018B0836D7175AEC779F52E961780768F815C58F1AA52D211498DB89B9216763F569C9433A6BBFCEFB4D4A49387A4C5207FBB3B5A92B5941294DF30588C6740D39DC16FA1F0E634F7246CF7CDCB978E44347D89381B7A74EB7084F754B90BDE9AAF5A94B8F2A85EFD0B50692AE2D425E234");
995 testing.expectEqualSlices(u8, out[0..], m);995 try testing.expectEqualSlices(u8, out[0..], m);
996 c[0] += 1;996 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));
998 }998 }
999}999}
lib/std/crypto/ghash.zig+2-2
...@@ -326,11 +326,11 @@ test "ghash" {...@@ -326,11 +326,11 @@ test "ghash" {
326 st.update(&m);326 st.update(&m);
327 var out: [16]u8 = undefined;327 var out: [16]u8 = undefined;
328 st.final(&out);328 st.final(&out);
329 htest.assertEqual("889295fa746e8b174bf4ec80a65dea41", &out);329 try htest.assertEqual("889295fa746e8b174bf4ec80a65dea41", &out);
330330
331 st = Ghash.init(&key);331 st = Ghash.init(&key);
332 st.update(m[0..100]);332 st.update(m[0..100]);
333 st.update(m[100..]);333 st.update(m[100..]);
334 st.final(&out);334 st.final(&out);
335 htest.assertEqual("889295fa746e8b174bf4ec80a65dea41", &out);335 try htest.assertEqual("889295fa746e8b174bf4ec80a65dea41", &out);
336}336}
lib/std/crypto/gimli.zig+19-19
...@@ -205,7 +205,7 @@ test "permute" {...@@ -205,7 +205,7 @@ test "permute" {
205 while (i < 12) : (i += 1) {205 while (i < 12) : (i += 1) {
206 mem.writeIntLittle(u32, expected_output[i * 4 ..][0..4], tv_output[i / 4][i % 4]);206 mem.writeIntLittle(u32, expected_output[i * 4 ..][0..4], tv_output[i / 4][i % 4]);
207 }207 }
208 testing.expectEqualSlices(u8, state.toSliceConst(), expected_output[0..]);208 try testing.expectEqualSlices(u8, state.toSliceConst(), expected_output[0..]);
209}209}
210210
211pub const Hash = struct {211pub const Hash = struct {
...@@ -274,7 +274,7 @@ test "hash" {...@@ -274,7 +274,7 @@ test "hash" {
274 _ = try std.fmt.hexToBytes(&msg, "000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C");274 _ = try std.fmt.hexToBytes(&msg, "000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C");
275 var md: [32]u8 = undefined;275 var md: [32]u8 = undefined;
276 hash(&md, &msg, .{});276 hash(&md, &msg, .{});
277 htest.assertEqual("1C9A03DC6A5DDC5444CFC6F4B154CFF5CF081633B2CEA4D7D0AE7CCFED5AAA44", &md);277 try htest.assertEqual("1C9A03DC6A5DDC5444CFC6F4B154CFF5CF081633B2CEA4D7D0AE7CCFED5AAA44", &md);
278}278}
279279
280test "hash test vector 17" {280test "hash test vector 17" {
...@@ -282,7 +282,7 @@ test "hash test vector 17" {...@@ -282,7 +282,7 @@ test "hash test vector 17" {
282 _ = try std.fmt.hexToBytes(&msg, "000102030405060708090A0B0C0D0E0F");282 _ = try std.fmt.hexToBytes(&msg, "000102030405060708090A0B0C0D0E0F");
283 var md: [32]u8 = undefined;283 var md: [32]u8 = undefined;
284 hash(&md, &msg, .{});284 hash(&md, &msg, .{});
285 htest.assertEqual("404C130AF1B9023A7908200919F690FFBB756D5176E056FFDE320016A37C7282", &md);285 try htest.assertEqual("404C130AF1B9023A7908200919F690FFBB756D5176E056FFDE320016A37C7282", &md);
286}286}
287287
288test "hash test vector 33" {288test "hash test vector 33" {
...@@ -290,7 +290,7 @@ test "hash test vector 33" {...@@ -290,7 +290,7 @@ test "hash test vector 33" {
290 _ = try std.fmt.hexToBytes(&msg, "000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F");290 _ = try std.fmt.hexToBytes(&msg, "000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F");
291 var md: [32]u8 = undefined;291 var md: [32]u8 = undefined;
292 hash(&md, &msg, .{});292 hash(&md, &msg, .{});
293 htest.assertEqual("A8F4FA28708BDA7EFB4C1914CA4AFA9E475B82D588D36504F87DBB0ED9AB3C4B", &md);293 try htest.assertEqual("A8F4FA28708BDA7EFB4C1914CA4AFA9E475B82D588D36504F87DBB0ED9AB3C4B", &md);
294}294}
295295
296pub const Aead = struct {296pub const Aead = struct {
...@@ -447,12 +447,12 @@ test "cipher" {...@@ -447,12 +447,12 @@ test "cipher" {
447 var ct: [pt.len]u8 = undefined;447 var ct: [pt.len]u8 = undefined;
448 var tag: [16]u8 = undefined;448 var tag: [16]u8 = undefined;
449 Aead.encrypt(&ct, &tag, &pt, &ad, nonce, key);449 Aead.encrypt(&ct, &tag, &pt, &ad, nonce, key);
450 htest.assertEqual("", &ct);450 try htest.assertEqual("", &ct);
451 htest.assertEqual("14DA9BB7120BF58B985A8E00FDEBA15B", &tag);451 try htest.assertEqual("14DA9BB7120BF58B985A8E00FDEBA15B", &tag);
452452
453 var pt2: [pt.len]u8 = undefined;453 var pt2: [pt.len]u8 = undefined;
454 try Aead.decrypt(&pt2, &ct, tag, &ad, nonce, key);454 try Aead.decrypt(&pt2, &ct, tag, &ad, nonce, key);
455 testing.expectEqualSlices(u8, &pt, &pt2);455 try testing.expectEqualSlices(u8, &pt, &pt2);
456 }456 }
457 { // test vector (34) from NIST KAT submission.457 { // test vector (34) from NIST KAT submission.
458 const ad: [0]u8 = undefined;458 const ad: [0]u8 = undefined;
...@@ -462,12 +462,12 @@ test "cipher" {...@@ -462,12 +462,12 @@ test "cipher" {
462 var ct: [pt.len]u8 = undefined;462 var ct: [pt.len]u8 = undefined;
463 var tag: [16]u8 = undefined;463 var tag: [16]u8 = undefined;
464 Aead.encrypt(&ct, &tag, &pt, &ad, nonce, key);464 Aead.encrypt(&ct, &tag, &pt, &ad, nonce, key);
465 htest.assertEqual("7F", &ct);465 try htest.assertEqual("7F", &ct);
466 htest.assertEqual("80492C317B1CD58A1EDC3A0D3E9876FC", &tag);466 try htest.assertEqual("80492C317B1CD58A1EDC3A0D3E9876FC", &tag);
467467
468 var pt2: [pt.len]u8 = undefined;468 var pt2: [pt.len]u8 = undefined;
469 try Aead.decrypt(&pt2, &ct, tag, &ad, nonce, key);469 try Aead.decrypt(&pt2, &ct, tag, &ad, nonce, key);
470 testing.expectEqualSlices(u8, &pt, &pt2);470 try testing.expectEqualSlices(u8, &pt, &pt2);
471 }471 }
472 { // test vector (106) from NIST KAT submission.472 { // test vector (106) from NIST KAT submission.
473 var ad: [12 / 2]u8 = undefined;473 var ad: [12 / 2]u8 = undefined;
...@@ -478,12 +478,12 @@ test "cipher" {...@@ -478,12 +478,12 @@ test "cipher" {
478 var ct: [pt.len]u8 = undefined;478 var ct: [pt.len]u8 = undefined;
479 var tag: [16]u8 = undefined;479 var tag: [16]u8 = undefined;
480 Aead.encrypt(&ct, &tag, &pt, &ad, nonce, key);480 Aead.encrypt(&ct, &tag, &pt, &ad, nonce, key);
481 htest.assertEqual("484D35", &ct);481 try htest.assertEqual("484D35", &ct);
482 htest.assertEqual("030BBEA23B61C00CED60A923BDCF9147", &tag);482 try htest.assertEqual("030BBEA23B61C00CED60A923BDCF9147", &tag);
483483
484 var pt2: [pt.len]u8 = undefined;484 var pt2: [pt.len]u8 = undefined;
485 try Aead.decrypt(&pt2, &ct, tag, &ad, nonce, key);485 try Aead.decrypt(&pt2, &ct, tag, &ad, nonce, key);
486 testing.expectEqualSlices(u8, &pt, &pt2);486 try testing.expectEqualSlices(u8, &pt, &pt2);
487 }487 }
488 { // test vector (790) from NIST KAT submission.488 { // test vector (790) from NIST KAT submission.
489 var ad: [60 / 2]u8 = undefined;489 var ad: [60 / 2]u8 = undefined;
...@@ -494,12 +494,12 @@ test "cipher" {...@@ -494,12 +494,12 @@ test "cipher" {
494 var ct: [pt.len]u8 = undefined;494 var ct: [pt.len]u8 = undefined;
495 var tag: [16]u8 = undefined;495 var tag: [16]u8 = undefined;
496 Aead.encrypt(&ct, &tag, &pt, &ad, nonce, key);496 Aead.encrypt(&ct, &tag, &pt, &ad, nonce, key);
497 htest.assertEqual("6815B4A0ECDAD01596EAD87D9E690697475D234C6A13D1", &ct);497 try htest.assertEqual("6815B4A0ECDAD01596EAD87D9E690697475D234C6A13D1", &ct);
498 htest.assertEqual("DFE23F1642508290D68245279558B2FB", &tag);498 try htest.assertEqual("DFE23F1642508290D68245279558B2FB", &tag);
499499
500 var pt2: [pt.len]u8 = undefined;500 var pt2: [pt.len]u8 = undefined;
501 try Aead.decrypt(&pt2, &ct, tag, &ad, nonce, key);501 try Aead.decrypt(&pt2, &ct, tag, &ad, nonce, key);
502 testing.expectEqualSlices(u8, &pt, &pt2);502 try testing.expectEqualSlices(u8, &pt, &pt2);
503 }503 }
504 { // test vector (1057) from NIST KAT submission.504 { // test vector (1057) from NIST KAT submission.
505 const ad: [0]u8 = undefined;505 const ad: [0]u8 = undefined;
...@@ -509,11 +509,11 @@ test "cipher" {...@@ -509,11 +509,11 @@ test "cipher" {
509 var ct: [pt.len]u8 = undefined;509 var ct: [pt.len]u8 = undefined;
510 var tag: [16]u8 = undefined;510 var tag: [16]u8 = undefined;
511 Aead.encrypt(&ct, &tag, &pt, &ad, nonce, key);511 Aead.encrypt(&ct, &tag, &pt, &ad, nonce, key);
512 htest.assertEqual("7F8A2CF4F52AA4D6B2E74105C30A2777B9D0C8AEFDD555DE35861BD3011F652F", &ct);512 try htest.assertEqual("7F8A2CF4F52AA4D6B2E74105C30A2777B9D0C8AEFDD555DE35861BD3011F652F", &ct);
513 htest.assertEqual("7256456FA935AC34BBF55AE135F33257", &tag);513 try htest.assertEqual("7256456FA935AC34BBF55AE135F33257", &tag);
514514
515 var pt2: [pt.len]u8 = undefined;515 var pt2: [pt.len]u8 = undefined;
516 try Aead.decrypt(&pt2, &ct, tag, &ad, nonce, key);516 try Aead.decrypt(&pt2, &ct, tag, &ad, nonce, key);
517 testing.expectEqualSlices(u8, &pt, &pt2);517 try testing.expectEqualSlices(u8, &pt, &pt2);
518 }518 }
519}519}
lib/std/crypto/hkdf.zig+2-2
...@@ -65,8 +65,8 @@ test "Hkdf" {...@@ -65,8 +65,8 @@ test "Hkdf" {
65 const context = [_]u8{ 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8, 0xf9 };65 const context = [_]u8{ 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8, 0xf9 };
66 const kdf = HkdfSha256;66 const kdf = HkdfSha256;
67 const prk = kdf.extract(&salt, &ikm);67 const prk = kdf.extract(&salt, &ikm);
68 htest.assertEqual("077709362c2e32df0ddc3f0dc47bba6390b6c73bb50f9c3122ec844ad7c2b3e5", &prk);68 try htest.assertEqual("077709362c2e32df0ddc3f0dc47bba6390b6c73bb50f9c3122ec844ad7c2b3e5", &prk);
69 var out: [42]u8 = undefined;69 var out: [42]u8 = undefined;
70 kdf.expand(&out, &context, prk);70 kdf.expand(&out, &context, prk);
71 htest.assertEqual("3cb25f25faacd57a90434f64d0362f2a2d2d0a90cf1a5a4c5db02d56ecc4c5bf34007208d5b887185865", &out);71 try htest.assertEqual("3cb25f25faacd57a90434f64d0362f2a2d2d0a90cf1a5a4c5db02d56ecc4c5bf34007208d5b887185865", &out);
72}72}
lib/std/crypto/hmac.zig+6-6
...@@ -84,26 +84,26 @@ const htest = @import("test.zig");...@@ -84,26 +84,26 @@ const htest = @import("test.zig");
84test "hmac md5" {84test "hmac md5" {
85 var out: [HmacMd5.mac_length]u8 = undefined;85 var out: [HmacMd5.mac_length]u8 = undefined;
86 HmacMd5.create(out[0..], "", "");86 HmacMd5.create(out[0..], "", "");
87 htest.assertEqual("74e6f7298a9c2d168935f58c001bad88", out[0..]);87 try htest.assertEqual("74e6f7298a9c2d168935f58c001bad88", out[0..]);
8888
89 HmacMd5.create(out[0..], "The quick brown fox jumps over the lazy dog", "key");89 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..]);
91}91}
9292
93test "hmac sha1" {93test "hmac sha1" {
94 var out: [HmacSha1.mac_length]u8 = undefined;94 var out: [HmacSha1.mac_length]u8 = undefined;
95 HmacSha1.create(out[0..], "", "");95 HmacSha1.create(out[0..], "", "");
96 htest.assertEqual("fbdb1d1b18aa6c08324b7d64b71fb76370690e1d", out[0..]);96 try htest.assertEqual("fbdb1d1b18aa6c08324b7d64b71fb76370690e1d", out[0..]);
9797
98 HmacSha1.create(out[0..], "The quick brown fox jumps over the lazy dog", "key");98 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..]);
100}100}
101101
102test "hmac sha256" {102test "hmac sha256" {
103 var out: [sha2.HmacSha256.mac_length]u8 = undefined;103 var out: [sha2.HmacSha256.mac_length]u8 = undefined;
104 sha2.HmacSha256.create(out[0..], "", "");104 sha2.HmacSha256.create(out[0..], "", "");
105 htest.assertEqual("b613679a0814d9ec772f95d778c35fc5ff1697c493715653c6c712144292c5ad", out[0..]);105 try htest.assertEqual("b613679a0814d9ec772f95d778c35fc5ff1697c493715653c6c712144292c5ad", out[0..]);
106106
107 sha2.HmacSha256.create(out[0..], "The quick brown fox jumps over the lazy dog", "key");107 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..]);
109}109}
lib/std/crypto/isap.zig+3-3
...@@ -240,8 +240,8 @@ test "ISAP" {...@@ -240,8 +240,8 @@ test "ISAP" {
240 var msg = "test";240 var msg = "test";
241 var c: [msg.len]u8 = undefined;241 var c: [msg.len]u8 = undefined;
242 IsapA128A.encrypt(c[0..], &tag, msg[0..], ad, n, k);242 IsapA128A.encrypt(c[0..], &tag, msg[0..], ad, n, k);
243 testing.expect(mem.eql(u8, &[_]u8{ 0x8f, 0x68, 0x03, 0x8d }, c[0..]));243 try 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..]));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..]));
245 try IsapA128A.decrypt(c[0..], c[0..], tag, ad, n, k);245 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..]));
247}247}
lib/std/crypto/md5.zig+10-10
...@@ -241,13 +241,13 @@ pub const Md5 = struct {...@@ -241,13 +241,13 @@ pub const Md5 = struct {
241const htest = @import("test.zig");241const htest = @import("test.zig");
242242
243test "md5 single" {243test "md5 single" {
244 htest.assertEqualHash(Md5, "d41d8cd98f00b204e9800998ecf8427e", "");244 try htest.assertEqualHash(Md5, "d41d8cd98f00b204e9800998ecf8427e", "");
245 htest.assertEqualHash(Md5, "0cc175b9c0f1b6a831c399e269772661", "a");245 try htest.assertEqualHash(Md5, "0cc175b9c0f1b6a831c399e269772661", "a");
246 htest.assertEqualHash(Md5, "900150983cd24fb0d6963f7d28e17f72", "abc");246 try htest.assertEqualHash(Md5, "900150983cd24fb0d6963f7d28e17f72", "abc");
247 htest.assertEqualHash(Md5, "f96b697d7cb7938d525a2f31aaf161d0", "message digest");247 try htest.assertEqualHash(Md5, "f96b697d7cb7938d525a2f31aaf161d0", "message digest");
248 htest.assertEqualHash(Md5, "c3fcd3d76192e4007dfb496cca67e13b", "abcdefghijklmnopqrstuvwxyz");248 try htest.assertEqualHash(Md5, "c3fcd3d76192e4007dfb496cca67e13b", "abcdefghijklmnopqrstuvwxyz");
249 htest.assertEqualHash(Md5, "d174ab98d277d9f5a5611c2c9f419d9f", "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789");249 try htest.assertEqualHash(Md5, "d174ab98d277d9f5a5611c2c9f419d9f", "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789");
250 htest.assertEqualHash(Md5, "57edf4a22be3c955ac49da2e2107b67a", "12345678901234567890123456789012345678901234567890123456789012345678901234567890");250 try htest.assertEqualHash(Md5, "57edf4a22be3c955ac49da2e2107b67a", "12345678901234567890123456789012345678901234567890123456789012345678901234567890");
251}251}
252252
253test "md5 streaming" {253test "md5 streaming" {
...@@ -255,12 +255,12 @@ test "md5 streaming" {...@@ -255,12 +255,12 @@ test "md5 streaming" {
255 var out: [16]u8 = undefined;255 var out: [16]u8 = undefined;
256256
257 h.final(out[0..]);257 h.final(out[0..]);
258 htest.assertEqual("d41d8cd98f00b204e9800998ecf8427e", out[0..]);258 try htest.assertEqual("d41d8cd98f00b204e9800998ecf8427e", out[0..]);
259259
260 h = Md5.init(.{});260 h = Md5.init(.{});
261 h.update("abc");261 h.update("abc");
262 h.final(out[0..]);262 h.final(out[0..]);
263 htest.assertEqual("900150983cd24fb0d6963f7d28e17f72", out[0..]);263 try htest.assertEqual("900150983cd24fb0d6963f7d28e17f72", out[0..]);
264264
265 h = Md5.init(.{});265 h = Md5.init(.{});
266 h.update("a");266 h.update("a");
...@@ -268,7 +268,7 @@ test "md5 streaming" {...@@ -268,7 +268,7 @@ test "md5 streaming" {
268 h.update("c");268 h.update("c");
269 h.final(out[0..]);269 h.final(out[0..]);
270270
271 htest.assertEqual("900150983cd24fb0d6963f7d28e17f72", out[0..]);271 try htest.assertEqual("900150983cd24fb0d6963f7d28e17f72", out[0..]);
272}272}
273273
274test "md5 aligned final" {274test "md5 aligned final" {
lib/std/crypto/pbkdf2.zig+6-6
...@@ -168,7 +168,7 @@ test "RFC 6070 one iteration" {...@@ -168,7 +168,7 @@ test "RFC 6070 one iteration" {
168168
169 const expected = "0c60c80f961f0e71f3a9b524af6012062fe037a6";169 const expected = "0c60c80f961f0e71f3a9b524af6012062fe037a6";
170170
171 htest.assertEqual(expected, dk[0..]);171 try htest.assertEqual(expected, dk[0..]);
172}172}
173173
174test "RFC 6070 two iterations" {174test "RFC 6070 two iterations" {
...@@ -183,7 +183,7 @@ test "RFC 6070 two iterations" {...@@ -183,7 +183,7 @@ test "RFC 6070 two iterations" {
183183
184 const expected = "ea6c014dc72d6f8ccd1ed92ace1d41f0d8de8957";184 const expected = "ea6c014dc72d6f8ccd1ed92ace1d41f0d8de8957";
185185
186 htest.assertEqual(expected, dk[0..]);186 try htest.assertEqual(expected, dk[0..]);
187}187}
188188
189test "RFC 6070 4096 iterations" {189test "RFC 6070 4096 iterations" {
...@@ -198,7 +198,7 @@ test "RFC 6070 4096 iterations" {...@@ -198,7 +198,7 @@ test "RFC 6070 4096 iterations" {
198198
199 const expected = "4b007901b765489abead49d926f721d065a429c1";199 const expected = "4b007901b765489abead49d926f721d065a429c1";
200200
201 htest.assertEqual(expected, dk[0..]);201 try htest.assertEqual(expected, dk[0..]);
202}202}
203203
204test "RFC 6070 16,777,216 iterations" {204test "RFC 6070 16,777,216 iterations" {
...@@ -218,7 +218,7 @@ test "RFC 6070 16,777,216 iterations" {...@@ -218,7 +218,7 @@ test "RFC 6070 16,777,216 iterations" {
218218
219 const expected = "eefe3d61cd4da4e4e9945b3d6ba2158c2634e984";219 const expected = "eefe3d61cd4da4e4e9945b3d6ba2158c2634e984";
220220
221 htest.assertEqual(expected, dk[0..]);221 try htest.assertEqual(expected, dk[0..]);
222}222}
223223
224test "RFC 6070 multi-block salt and password" {224test "RFC 6070 multi-block salt and password" {
...@@ -233,7 +233,7 @@ test "RFC 6070 multi-block salt and password" {...@@ -233,7 +233,7 @@ test "RFC 6070 multi-block salt and password" {
233233
234 const expected = "3d2eec4fe41c849b80c8d83662c0e44a8b291a964cf2f07038";234 const expected = "3d2eec4fe41c849b80c8d83662c0e44a8b291a964cf2f07038";
235235
236 htest.assertEqual(expected, dk[0..]);236 try htest.assertEqual(expected, dk[0..]);
237}237}
238238
239test "RFC 6070 embedded NUL" {239test "RFC 6070 embedded NUL" {
...@@ -248,7 +248,7 @@ test "RFC 6070 embedded NUL" {...@@ -248,7 +248,7 @@ test "RFC 6070 embedded NUL" {
248248
249 const expected = "56fa6aa75548099dcc37d7f03425e0c3";249 const expected = "56fa6aa75548099dcc37d7f03425e0c3";
250250
251 htest.assertEqual(expected, dk[0..]);251 try htest.assertEqual(expected, dk[0..]);
252}252}
253253
254test "Very large dk_len" {254test "Very large dk_len" {
lib/std/crypto/pcurves/tests.zig+9-9
...@@ -17,7 +17,7 @@ test "p256 ECDH key exchange" {...@@ -17,7 +17,7 @@ test "p256 ECDH key exchange" {
17 const dhB = try P256.basePoint.mul(dhb, .Little);17 const dhB = try P256.basePoint.mul(dhb, .Little);
18 const shareda = try dhA.mul(dhb, .Little);18 const shareda = try dhA.mul(dhb, .Little);
19 const sharedb = try dhB.mul(dha, .Little);19 const sharedb = try dhB.mul(dha, .Little);
20 testing.expect(shareda.equivalent(sharedb));20 try testing.expect(shareda.equivalent(sharedb));
21}21}
2222
23test "p256 point from affine coordinates" {23test "p256 point from affine coordinates" {
...@@ -28,7 +28,7 @@ test "p256 point from affine coordinates" {...@@ -28,7 +28,7 @@ test "p256 point from affine coordinates" {
28 var ys: [32]u8 = undefined;28 var ys: [32]u8 = undefined;
29 _ = try fmt.hexToBytes(&ys, yh);29 _ = try fmt.hexToBytes(&ys, yh);
30 var p = try P256.fromSerializedAffineCoordinates(xs, ys, .Big);30 var p = try P256.fromSerializedAffineCoordinates(xs, ys, .Big);
31 testing.expect(p.equivalent(P256.basePoint));31 try testing.expect(p.equivalent(P256.basePoint));
32}32}
3333
34test "p256 test vectors" {34test "p256 test vectors" {
...@@ -50,7 +50,7 @@ test "p256 test vectors" {...@@ -50,7 +50,7 @@ test "p256 test vectors" {
50 p = p.add(P256.basePoint);50 p = p.add(P256.basePoint);
51 var xs: [32]u8 = undefined;51 var xs: [32]u8 = undefined;
52 _ = try fmt.hexToBytes(&xs, xh);52 _ = try fmt.hexToBytes(&xs, xh);
53 testing.expectEqualSlices(u8, &x.toBytes(.Big), &xs);53 try testing.expectEqualSlices(u8, &x.toBytes(.Big), &xs);
54 }54 }
55}55}
5656
...@@ -67,7 +67,7 @@ test "p256 test vectors - doubling" {...@@ -67,7 +67,7 @@ test "p256 test vectors - doubling" {
67 p = p.dbl();67 p = p.dbl();
68 var xs: [32]u8 = undefined;68 var xs: [32]u8 = undefined;
69 _ = try fmt.hexToBytes(&xs, xh);69 _ = try fmt.hexToBytes(&xs, xh);
70 testing.expectEqualSlices(u8, &x.toBytes(.Big), &xs);70 try testing.expectEqualSlices(u8, &x.toBytes(.Big), &xs);
71 }71 }
72}72}
7373
...@@ -75,29 +75,29 @@ test "p256 compressed sec1 encoding/decoding" {...@@ -75,29 +75,29 @@ test "p256 compressed sec1 encoding/decoding" {
75 const p = P256.random();75 const p = P256.random();
76 const s = p.toCompressedSec1();76 const s = p.toCompressedSec1();
77 const q = try P256.fromSec1(&s);77 const q = try P256.fromSec1(&s);
78 testing.expect(p.equivalent(q));78 try testing.expect(p.equivalent(q));
79}79}
8080
81test "p256 uncompressed sec1 encoding/decoding" {81test "p256 uncompressed sec1 encoding/decoding" {
82 const p = P256.random();82 const p = P256.random();
83 const s = p.toUncompressedSec1();83 const s = p.toUncompressedSec1();
84 const q = try P256.fromSec1(&s);84 const q = try P256.fromSec1(&s);
85 testing.expect(p.equivalent(q));85 try testing.expect(p.equivalent(q));
86}86}
8787
88test "p256 public key is the neutral element" {88test "p256 public key is the neutral element" {
89 const n = P256.scalar.Scalar.zero.toBytes(.Little);89 const n = P256.scalar.Scalar.zero.toBytes(.Little);
90 const p = P256.random();90 const p = P256.random();
91 testing.expectError(error.IdentityElement, p.mul(n, .Little));91 try testing.expectError(error.IdentityElement, p.mul(n, .Little));
92}92}
9393
94test "p256 public key is the neutral element (public verification)" {94test "p256 public key is the neutral element (public verification)" {
95 const n = P256.scalar.Scalar.zero.toBytes(.Little);95 const n = P256.scalar.Scalar.zero.toBytes(.Little);
96 const p = P256.random();96 const p = P256.random();
97 testing.expectError(error.IdentityElement, p.mulPublic(n, .Little));97 try testing.expectError(error.IdentityElement, p.mulPublic(n, .Little));
98}98}
9999
100test "p256 field element non-canonical encoding" {100test "p256 field element non-canonical encoding" {
101 const s = [_]u8{0xff} ** 32;101 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));
103}103}
lib/std/crypto/poly1305.zig+1-1
...@@ -216,5 +216,5 @@ test "poly1305 rfc7439 vector1" {...@@ -216,5 +216,5 @@ test "poly1305 rfc7439 vector1" {
216 var mac: [16]u8 = undefined;216 var mac: [16]u8 = undefined;
217 Poly1305.create(mac[0..], msg, key);217 Poly1305.create(mac[0..], msg, key);
218218
219 std.testing.expectEqualSlices(u8, expected_mac, &mac);219 try std.testing.expectEqualSlices(u8, expected_mac, &mac);
220}220}
lib/std/crypto/salsa20.zig+3-3
...@@ -561,11 +561,11 @@ test "(x)salsa20" {...@@ -561,11 +561,11 @@ test "(x)salsa20" {
561 var c: [msg.len]u8 = undefined;561 var c: [msg.len]u8 = undefined;
562562
563 Salsa20.xor(&c, msg[0..], 0, key, nonce);563 Salsa20.xor(&c, msg[0..], 0, key, nonce);
564 htest.assertEqual("30ff9933aa6534ff5207142593cd1fca4b23bdd8", c[0..]);564 try htest.assertEqual("30ff9933aa6534ff5207142593cd1fca4b23bdd8", c[0..]);
565565
566 const extended_nonce = [_]u8{0x42} ** 24;566 const extended_nonce = [_]u8{0x42} ** 24;
567 XSalsa20.xor(&c, msg[0..], 0, key, extended_nonce);567 XSalsa20.xor(&c, msg[0..], 0, key, extended_nonce);
568 htest.assertEqual("b4ab7d82e750ec07644fa3281bce6cd91d4243f9", c[0..]);568 try htest.assertEqual("b4ab7d82e750ec07644fa3281bce6cd91d4243f9", c[0..]);
569}569}
570570
571test "xsalsa20poly1305" {571test "xsalsa20poly1305" {
...@@ -628,5 +628,5 @@ test "secretbox twoblocks" {...@@ -628,5 +628,5 @@ test "secretbox twoblocks" {
628 const msg = [_]u8{'a'} ** 97;628 const msg = [_]u8{'a'} ** 97;
629 var ciphertext: [msg.len + SecretBox.tag_length]u8 = undefined;629 var ciphertext: [msg.len + SecretBox.tag_length]u8 = undefined;
630 SecretBox.seal(&ciphertext, &msg, nonce, key);630 SecretBox.seal(&ciphertext, &msg, nonce, key);
631 htest.assertEqual("b05760e217288ba079caa2fd57fd3701784974ffcfda20fe523b89211ad8af065a6eb37cdb29d51aca5bd75dafdd21d18b044c54bb7c526cf576c94ee8900f911ceab0147e82b667a28c52d58ceb29554ff45471224d37b03256b01c119b89ff6d36855de8138d103386dbc9d971f52261", &ciphertext);631 try htest.assertEqual("b05760e217288ba079caa2fd57fd3701784974ffcfda20fe523b89211ad8af065a6eb37cdb29d51aca5bd75dafdd21d18b044c54bb7c526cf576c94ee8900f911ceab0147e82b667a28c52d58ceb29554ff45471224d37b03256b01c119b89ff6d36855de8138d103386dbc9d971f52261", &ciphertext);
632}632}
lib/std/crypto/sha1.zig+6-6
...@@ -265,9 +265,9 @@ pub const Sha1 = struct {...@@ -265,9 +265,9 @@ pub const Sha1 = struct {
265const htest = @import("test.zig");265const htest = @import("test.zig");
266266
267test "sha1 single" {267test "sha1 single" {
268 htest.assertEqualHash(Sha1, "da39a3ee5e6b4b0d3255bfef95601890afd80709", "");268 try htest.assertEqualHash(Sha1, "da39a3ee5e6b4b0d3255bfef95601890afd80709", "");
269 htest.assertEqualHash(Sha1, "a9993e364706816aba3e25717850c26c9cd0d89d", "abc");269 try htest.assertEqualHash(Sha1, "a9993e364706816aba3e25717850c26c9cd0d89d", "abc");
270 htest.assertEqualHash(Sha1, "a49b2446a02c645bf419f995b67091253a04a259", "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu");270 try htest.assertEqualHash(Sha1, "a49b2446a02c645bf419f995b67091253a04a259", "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu");
271}271}
272272
273test "sha1 streaming" {273test "sha1 streaming" {
...@@ -275,19 +275,19 @@ test "sha1 streaming" {...@@ -275,19 +275,19 @@ test "sha1 streaming" {
275 var out: [20]u8 = undefined;275 var out: [20]u8 = undefined;
276276
277 h.final(&out);277 h.final(&out);
278 htest.assertEqual("da39a3ee5e6b4b0d3255bfef95601890afd80709", out[0..]);278 try htest.assertEqual("da39a3ee5e6b4b0d3255bfef95601890afd80709", out[0..]);
279279
280 h = Sha1.init(.{});280 h = Sha1.init(.{});
281 h.update("abc");281 h.update("abc");
282 h.final(&out);282 h.final(&out);
283 htest.assertEqual("a9993e364706816aba3e25717850c26c9cd0d89d", out[0..]);283 try htest.assertEqual("a9993e364706816aba3e25717850c26c9cd0d89d", out[0..]);
284284
285 h = Sha1.init(.{});285 h = Sha1.init(.{});
286 h.update("a");286 h.update("a");
287 h.update("b");287 h.update("b");
288 h.update("c");288 h.update("c");
289 h.final(&out);289 h.final(&out);
290 htest.assertEqual("a9993e364706816aba3e25717850c26c9cd0d89d", out[0..]);290 try htest.assertEqual("a9993e364706816aba3e25717850c26c9cd0d89d", out[0..]);
291}291}
292292
293test "sha1 aligned final" {293test "sha1 aligned final" {
lib/std/crypto/sha2.zig+24-24
...@@ -285,9 +285,9 @@ fn Sha2x32(comptime params: Sha2Params32) type {...@@ -285,9 +285,9 @@ fn Sha2x32(comptime params: Sha2Params32) type {
285}285}
286286
287test "sha224 single" {287test "sha224 single" {
288 htest.assertEqualHash(Sha224, "d14a028c2a3a2bc9476102bb288234c415a2b01f828ea62ac5b3e42f", "");288 try htest.assertEqualHash(Sha224, "d14a028c2a3a2bc9476102bb288234c415a2b01f828ea62ac5b3e42f", "");
289 htest.assertEqualHash(Sha224, "23097d223405d8228642a477bda255b32aadbce4bda0b3f7e36c9da7", "abc");289 try htest.assertEqualHash(Sha224, "23097d223405d8228642a477bda255b32aadbce4bda0b3f7e36c9da7", "abc");
290 htest.assertEqualHash(Sha224, "c97ca9a559850ce97a04a96def6d99a9e0e0e2ab14e6b8df265fc0b3", "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu");290 try htest.assertEqualHash(Sha224, "c97ca9a559850ce97a04a96def6d99a9e0e0e2ab14e6b8df265fc0b3", "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu");
291}291}
292292
293test "sha224 streaming" {293test "sha224 streaming" {
...@@ -295,25 +295,25 @@ test "sha224 streaming" {...@@ -295,25 +295,25 @@ test "sha224 streaming" {
295 var out: [28]u8 = undefined;295 var out: [28]u8 = undefined;
296296
297 h.final(out[0..]);297 h.final(out[0..]);
298 htest.assertEqual("d14a028c2a3a2bc9476102bb288234c415a2b01f828ea62ac5b3e42f", out[0..]);298 try htest.assertEqual("d14a028c2a3a2bc9476102bb288234c415a2b01f828ea62ac5b3e42f", out[0..]);
299299
300 h = Sha224.init(.{});300 h = Sha224.init(.{});
301 h.update("abc");301 h.update("abc");
302 h.final(out[0..]);302 h.final(out[0..]);
303 htest.assertEqual("23097d223405d8228642a477bda255b32aadbce4bda0b3f7e36c9da7", out[0..]);303 try htest.assertEqual("23097d223405d8228642a477bda255b32aadbce4bda0b3f7e36c9da7", out[0..]);
304304
305 h = Sha224.init(.{});305 h = Sha224.init(.{});
306 h.update("a");306 h.update("a");
307 h.update("b");307 h.update("b");
308 h.update("c");308 h.update("c");
309 h.final(out[0..]);309 h.final(out[0..]);
310 htest.assertEqual("23097d223405d8228642a477bda255b32aadbce4bda0b3f7e36c9da7", out[0..]);310 try htest.assertEqual("23097d223405d8228642a477bda255b32aadbce4bda0b3f7e36c9da7", out[0..]);
311}311}
312312
313test "sha256 single" {313test "sha256 single" {
314 htest.assertEqualHash(Sha256, "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", "");314 try htest.assertEqualHash(Sha256, "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", "");
315 htest.assertEqualHash(Sha256, "ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad", "abc");315 try htest.assertEqualHash(Sha256, "ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad", "abc");
316 htest.assertEqualHash(Sha256, "cf5b16a778af8380036ce59e7b0492370b249b11e8f07a51afac45037afee9d1", "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu");316 try htest.assertEqualHash(Sha256, "cf5b16a778af8380036ce59e7b0492370b249b11e8f07a51afac45037afee9d1", "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu");
317}317}
318318
319test "sha256 streaming" {319test "sha256 streaming" {
...@@ -321,19 +321,19 @@ test "sha256 streaming" {...@@ -321,19 +321,19 @@ test "sha256 streaming" {
321 var out: [32]u8 = undefined;321 var out: [32]u8 = undefined;
322322
323 h.final(out[0..]);323 h.final(out[0..]);
324 htest.assertEqual("e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", out[0..]);324 try htest.assertEqual("e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", out[0..]);
325325
326 h = Sha256.init(.{});326 h = Sha256.init(.{});
327 h.update("abc");327 h.update("abc");
328 h.final(out[0..]);328 h.final(out[0..]);
329 htest.assertEqual("ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad", out[0..]);329 try htest.assertEqual("ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad", out[0..]);
330330
331 h = Sha256.init(.{});331 h = Sha256.init(.{});
332 h.update("a");332 h.update("a");
333 h.update("b");333 h.update("b");
334 h.update("c");334 h.update("c");
335 h.final(out[0..]);335 h.final(out[0..]);
336 htest.assertEqual("ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad", out[0..]);336 try htest.assertEqual("ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad", out[0..]);
337}337}
338338
339test "sha256 aligned final" {339test "sha256 aligned final" {
...@@ -675,13 +675,13 @@ fn Sha2x64(comptime params: Sha2Params64) type {...@@ -675,13 +675,13 @@ fn Sha2x64(comptime params: Sha2Params64) type {
675675
676test "sha384 single" {676test "sha384 single" {
677 const h1 = "38b060a751ac96384cd9327eb1b1e36a21fdb71114be07434c0cc7bf63f6e1da274edebfe76f65fbd51ad2f14898b95b";677 const h1 = "38b060a751ac96384cd9327eb1b1e36a21fdb71114be07434c0cc7bf63f6e1da274edebfe76f65fbd51ad2f14898b95b";
678 htest.assertEqualHash(Sha384, h1, "");678 try htest.assertEqualHash(Sha384, h1, "");
679679
680 const h2 = "cb00753f45a35e8bb5a03d699ac65007272c32ab0eded1631a8b605a43ff5bed8086072ba1e7cc2358baeca134c825a7";680 const h2 = "cb00753f45a35e8bb5a03d699ac65007272c32ab0eded1631a8b605a43ff5bed8086072ba1e7cc2358baeca134c825a7";
681 htest.assertEqualHash(Sha384, h2, "abc");681 try htest.assertEqualHash(Sha384, h2, "abc");
682682
683 const h3 = "09330c33f71147e83d192fc782cd1b4753111b173b3b05d22fa08086e3b0f712fcc7c71a557e2db966c3e9fa91746039";683 const h3 = "09330c33f71147e83d192fc782cd1b4753111b173b3b05d22fa08086e3b0f712fcc7c71a557e2db966c3e9fa91746039";
684 htest.assertEqualHash(Sha384, h3, "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu");684 try htest.assertEqualHash(Sha384, h3, "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu");
685}685}
686686
687test "sha384 streaming" {687test "sha384 streaming" {
...@@ -690,32 +690,32 @@ test "sha384 streaming" {...@@ -690,32 +690,32 @@ test "sha384 streaming" {
690690
691 const h1 = "38b060a751ac96384cd9327eb1b1e36a21fdb71114be07434c0cc7bf63f6e1da274edebfe76f65fbd51ad2f14898b95b";691 const h1 = "38b060a751ac96384cd9327eb1b1e36a21fdb71114be07434c0cc7bf63f6e1da274edebfe76f65fbd51ad2f14898b95b";
692 h.final(out[0..]);692 h.final(out[0..]);
693 htest.assertEqual(h1, out[0..]);693 try htest.assertEqual(h1, out[0..]);
694694
695 const h2 = "cb00753f45a35e8bb5a03d699ac65007272c32ab0eded1631a8b605a43ff5bed8086072ba1e7cc2358baeca134c825a7";695 const h2 = "cb00753f45a35e8bb5a03d699ac65007272c32ab0eded1631a8b605a43ff5bed8086072ba1e7cc2358baeca134c825a7";
696696
697 h = Sha384.init(.{});697 h = Sha384.init(.{});
698 h.update("abc");698 h.update("abc");
699 h.final(out[0..]);699 h.final(out[0..]);
700 htest.assertEqual(h2, out[0..]);700 try htest.assertEqual(h2, out[0..]);
701701
702 h = Sha384.init(.{});702 h = Sha384.init(.{});
703 h.update("a");703 h.update("a");
704 h.update("b");704 h.update("b");
705 h.update("c");705 h.update("c");
706 h.final(out[0..]);706 h.final(out[0..]);
707 htest.assertEqual(h2, out[0..]);707 try htest.assertEqual(h2, out[0..]);
708}708}
709709
710test "sha512 single" {710test "sha512 single" {
711 const h1 = "cf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921d36ce9ce47d0d13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e";711 const h1 = "cf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921d36ce9ce47d0d13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e";
712 htest.assertEqualHash(Sha512, h1, "");712 try htest.assertEqualHash(Sha512, h1, "");
713713
714 const h2 = "ddaf35a193617abacc417349ae20413112e6fa4e89a97ea20a9eeee64b55d39a2192992a274fc1a836ba3c23a3feebbd454d4423643ce80e2a9ac94fa54ca49f";714 const h2 = "ddaf35a193617abacc417349ae20413112e6fa4e89a97ea20a9eeee64b55d39a2192992a274fc1a836ba3c23a3feebbd454d4423643ce80e2a9ac94fa54ca49f";
715 htest.assertEqualHash(Sha512, h2, "abc");715 try htest.assertEqualHash(Sha512, h2, "abc");
716716
717 const h3 = "8e959b75dae313da8cf4f72814fc143f8f7779c6eb9f7fa17299aeadb6889018501d289e4900f7e4331b99dec4b5433ac7d329eeb6dd26545e96e55b874be909";717 const h3 = "8e959b75dae313da8cf4f72814fc143f8f7779c6eb9f7fa17299aeadb6889018501d289e4900f7e4331b99dec4b5433ac7d329eeb6dd26545e96e55b874be909";
718 htest.assertEqualHash(Sha512, h3, "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu");718 try htest.assertEqualHash(Sha512, h3, "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu");
719}719}
720720
721test "sha512 streaming" {721test "sha512 streaming" {
...@@ -724,21 +724,21 @@ test "sha512 streaming" {...@@ -724,21 +724,21 @@ test "sha512 streaming" {
724724
725 const h1 = "cf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921d36ce9ce47d0d13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e";725 const h1 = "cf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921d36ce9ce47d0d13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e";
726 h.final(out[0..]);726 h.final(out[0..]);
727 htest.assertEqual(h1, out[0..]);727 try htest.assertEqual(h1, out[0..]);
728728
729 const h2 = "ddaf35a193617abacc417349ae20413112e6fa4e89a97ea20a9eeee64b55d39a2192992a274fc1a836ba3c23a3feebbd454d4423643ce80e2a9ac94fa54ca49f";729 const h2 = "ddaf35a193617abacc417349ae20413112e6fa4e89a97ea20a9eeee64b55d39a2192992a274fc1a836ba3c23a3feebbd454d4423643ce80e2a9ac94fa54ca49f";
730730
731 h = Sha512.init(.{});731 h = Sha512.init(.{});
732 h.update("abc");732 h.update("abc");
733 h.final(out[0..]);733 h.final(out[0..]);
734 htest.assertEqual(h2, out[0..]);734 try htest.assertEqual(h2, out[0..]);
735735
736 h = Sha512.init(.{});736 h = Sha512.init(.{});
737 h.update("a");737 h.update("a");
738 h.update("b");738 h.update("b");
739 h.update("c");739 h.update("c");
740 h.final(out[0..]);740 h.final(out[0..]);
741 htest.assertEqual(h2, out[0..]);741 try htest.assertEqual(h2, out[0..]);
742}742}
743743
744test "sha512 aligned final" {744test "sha512 aligned final" {
lib/std/crypto/sha3.zig+30-30
...@@ -169,9 +169,9 @@ fn keccakF(comptime F: usize, d: *[F / 8]u8) void {...@@ -169,9 +169,9 @@ fn keccakF(comptime F: usize, d: *[F / 8]u8) void {
169}169}
170170
171test "sha3-224 single" {171test "sha3-224 single" {
172 htest.assertEqualHash(Sha3_224, "6b4e03423667dbb73b6e15454f0eb1abd4597f9a1b078e3f5b5a6bc7", "");172 try htest.assertEqualHash(Sha3_224, "6b4e03423667dbb73b6e15454f0eb1abd4597f9a1b078e3f5b5a6bc7", "");
173 htest.assertEqualHash(Sha3_224, "e642824c3f8cf24ad09234ee7d3c766fc9a3a5168d0c94ad73b46fdf", "abc");173 try htest.assertEqualHash(Sha3_224, "e642824c3f8cf24ad09234ee7d3c766fc9a3a5168d0c94ad73b46fdf", "abc");
174 htest.assertEqualHash(Sha3_224, "543e6868e1666c1a643630df77367ae5a62a85070a51c14cbf665cbc", "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu");174 try htest.assertEqualHash(Sha3_224, "543e6868e1666c1a643630df77367ae5a62a85070a51c14cbf665cbc", "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu");
175}175}
176176
177test "sha3-224 streaming" {177test "sha3-224 streaming" {
...@@ -179,25 +179,25 @@ test "sha3-224 streaming" {...@@ -179,25 +179,25 @@ test "sha3-224 streaming" {
179 var out: [28]u8 = undefined;179 var out: [28]u8 = undefined;
180180
181 h.final(out[0..]);181 h.final(out[0..]);
182 htest.assertEqual("6b4e03423667dbb73b6e15454f0eb1abd4597f9a1b078e3f5b5a6bc7", out[0..]);182 try htest.assertEqual("6b4e03423667dbb73b6e15454f0eb1abd4597f9a1b078e3f5b5a6bc7", out[0..]);
183183
184 h = Sha3_224.init(.{});184 h = Sha3_224.init(.{});
185 h.update("abc");185 h.update("abc");
186 h.final(out[0..]);186 h.final(out[0..]);
187 htest.assertEqual("e642824c3f8cf24ad09234ee7d3c766fc9a3a5168d0c94ad73b46fdf", out[0..]);187 try htest.assertEqual("e642824c3f8cf24ad09234ee7d3c766fc9a3a5168d0c94ad73b46fdf", out[0..]);
188188
189 h = Sha3_224.init(.{});189 h = Sha3_224.init(.{});
190 h.update("a");190 h.update("a");
191 h.update("b");191 h.update("b");
192 h.update("c");192 h.update("c");
193 h.final(out[0..]);193 h.final(out[0..]);
194 htest.assertEqual("e642824c3f8cf24ad09234ee7d3c766fc9a3a5168d0c94ad73b46fdf", out[0..]);194 try htest.assertEqual("e642824c3f8cf24ad09234ee7d3c766fc9a3a5168d0c94ad73b46fdf", out[0..]);
195}195}
196196
197test "sha3-256 single" {197test "sha3-256 single" {
198 htest.assertEqualHash(Sha3_256, "a7ffc6f8bf1ed76651c14756a061d662f580ff4de43b49fa82d80a4b80f8434a", "");198 try htest.assertEqualHash(Sha3_256, "a7ffc6f8bf1ed76651c14756a061d662f580ff4de43b49fa82d80a4b80f8434a", "");
199 htest.assertEqualHash(Sha3_256, "3a985da74fe225b2045c172d6bd390bd855f086e3e9d525b46bfe24511431532", "abc");199 try htest.assertEqualHash(Sha3_256, "3a985da74fe225b2045c172d6bd390bd855f086e3e9d525b46bfe24511431532", "abc");
200 htest.assertEqualHash(Sha3_256, "916f6061fe879741ca6469b43971dfdb28b1a32dc36cb3254e812be27aad1d18", "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu");200 try htest.assertEqualHash(Sha3_256, "916f6061fe879741ca6469b43971dfdb28b1a32dc36cb3254e812be27aad1d18", "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu");
201}201}
202202
203test "sha3-256 streaming" {203test "sha3-256 streaming" {
...@@ -205,19 +205,19 @@ test "sha3-256 streaming" {...@@ -205,19 +205,19 @@ test "sha3-256 streaming" {
205 var out: [32]u8 = undefined;205 var out: [32]u8 = undefined;
206206
207 h.final(out[0..]);207 h.final(out[0..]);
208 htest.assertEqual("a7ffc6f8bf1ed76651c14756a061d662f580ff4de43b49fa82d80a4b80f8434a", out[0..]);208 try htest.assertEqual("a7ffc6f8bf1ed76651c14756a061d662f580ff4de43b49fa82d80a4b80f8434a", out[0..]);
209209
210 h = Sha3_256.init(.{});210 h = Sha3_256.init(.{});
211 h.update("abc");211 h.update("abc");
212 h.final(out[0..]);212 h.final(out[0..]);
213 htest.assertEqual("3a985da74fe225b2045c172d6bd390bd855f086e3e9d525b46bfe24511431532", out[0..]);213 try htest.assertEqual("3a985da74fe225b2045c172d6bd390bd855f086e3e9d525b46bfe24511431532", out[0..]);
214214
215 h = Sha3_256.init(.{});215 h = Sha3_256.init(.{});
216 h.update("a");216 h.update("a");
217 h.update("b");217 h.update("b");
218 h.update("c");218 h.update("c");
219 h.final(out[0..]);219 h.final(out[0..]);
220 htest.assertEqual("3a985da74fe225b2045c172d6bd390bd855f086e3e9d525b46bfe24511431532", out[0..]);220 try htest.assertEqual("3a985da74fe225b2045c172d6bd390bd855f086e3e9d525b46bfe24511431532", out[0..]);
221}221}
222222
223test "sha3-256 aligned final" {223test "sha3-256 aligned final" {
...@@ -231,11 +231,11 @@ test "sha3-256 aligned final" {...@@ -231,11 +231,11 @@ test "sha3-256 aligned final" {
231231
232test "sha3-384 single" {232test "sha3-384 single" {
233 const h1 = "0c63a75b845e4f7d01107d852e4c2485c51a50aaaa94fc61995e71bbee983a2ac3713831264adb47fb6bd1e058d5f004";233 const h1 = "0c63a75b845e4f7d01107d852e4c2485c51a50aaaa94fc61995e71bbee983a2ac3713831264adb47fb6bd1e058d5f004";
234 htest.assertEqualHash(Sha3_384, h1, "");234 try htest.assertEqualHash(Sha3_384, h1, "");
235 const h2 = "ec01498288516fc926459f58e2c6ad8df9b473cb0fc08c2596da7cf0e49be4b298d88cea927ac7f539f1edf228376d25";235 const h2 = "ec01498288516fc926459f58e2c6ad8df9b473cb0fc08c2596da7cf0e49be4b298d88cea927ac7f539f1edf228376d25";
236 htest.assertEqualHash(Sha3_384, h2, "abc");236 try htest.assertEqualHash(Sha3_384, h2, "abc");
237 const h3 = "79407d3b5916b59c3e30b09822974791c313fb9ecc849e406f23592d04f625dc8c709b98b43b3852b337216179aa7fc7";237 const h3 = "79407d3b5916b59c3e30b09822974791c313fb9ecc849e406f23592d04f625dc8c709b98b43b3852b337216179aa7fc7";
238 htest.assertEqualHash(Sha3_384, h3, "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu");238 try htest.assertEqualHash(Sha3_384, h3, "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu");
239}239}
240240
241test "sha3-384 streaming" {241test "sha3-384 streaming" {
...@@ -244,29 +244,29 @@ test "sha3-384 streaming" {...@@ -244,29 +244,29 @@ test "sha3-384 streaming" {
244244
245 const h1 = "0c63a75b845e4f7d01107d852e4c2485c51a50aaaa94fc61995e71bbee983a2ac3713831264adb47fb6bd1e058d5f004";245 const h1 = "0c63a75b845e4f7d01107d852e4c2485c51a50aaaa94fc61995e71bbee983a2ac3713831264adb47fb6bd1e058d5f004";
246 h.final(out[0..]);246 h.final(out[0..]);
247 htest.assertEqual(h1, out[0..]);247 try htest.assertEqual(h1, out[0..]);
248248
249 const h2 = "ec01498288516fc926459f58e2c6ad8df9b473cb0fc08c2596da7cf0e49be4b298d88cea927ac7f539f1edf228376d25";249 const h2 = "ec01498288516fc926459f58e2c6ad8df9b473cb0fc08c2596da7cf0e49be4b298d88cea927ac7f539f1edf228376d25";
250 h = Sha3_384.init(.{});250 h = Sha3_384.init(.{});
251 h.update("abc");251 h.update("abc");
252 h.final(out[0..]);252 h.final(out[0..]);
253 htest.assertEqual(h2, out[0..]);253 try htest.assertEqual(h2, out[0..]);
254254
255 h = Sha3_384.init(.{});255 h = Sha3_384.init(.{});
256 h.update("a");256 h.update("a");
257 h.update("b");257 h.update("b");
258 h.update("c");258 h.update("c");
259 h.final(out[0..]);259 h.final(out[0..]);
260 htest.assertEqual(h2, out[0..]);260 try htest.assertEqual(h2, out[0..]);
261}261}
262262
263test "sha3-512 single" {263test "sha3-512 single" {
264 const h1 = "a69f73cca23a9ac5c8b567dc185a756e97c982164fe25859e0d1dcc1475c80a615b2123af1f5f94c11e3e9402c3ac558f500199d95b6d3e301758586281dcd26";264 const h1 = "a69f73cca23a9ac5c8b567dc185a756e97c982164fe25859e0d1dcc1475c80a615b2123af1f5f94c11e3e9402c3ac558f500199d95b6d3e301758586281dcd26";
265 htest.assertEqualHash(Sha3_512, h1, "");265 try htest.assertEqualHash(Sha3_512, h1, "");
266 const h2 = "b751850b1a57168a5693cd924b6b096e08f621827444f70d884f5d0240d2712e10e116e9192af3c91a7ec57647e3934057340b4cf408d5a56592f8274eec53f0";266 const h2 = "b751850b1a57168a5693cd924b6b096e08f621827444f70d884f5d0240d2712e10e116e9192af3c91a7ec57647e3934057340b4cf408d5a56592f8274eec53f0";
267 htest.assertEqualHash(Sha3_512, h2, "abc");267 try htest.assertEqualHash(Sha3_512, h2, "abc");
268 const h3 = "afebb2ef542e6579c50cad06d2e578f9f8dd6881d7dc824d26360feebf18a4fa73e3261122948efcfd492e74e82e2189ed0fb440d187f382270cb455f21dd185";268 const h3 = "afebb2ef542e6579c50cad06d2e578f9f8dd6881d7dc824d26360feebf18a4fa73e3261122948efcfd492e74e82e2189ed0fb440d187f382270cb455f21dd185";
269 htest.assertEqualHash(Sha3_512, h3, "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu");269 try htest.assertEqualHash(Sha3_512, h3, "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu");
270}270}
271271
272test "sha3-512 streaming" {272test "sha3-512 streaming" {
...@@ -275,20 +275,20 @@ test "sha3-512 streaming" {...@@ -275,20 +275,20 @@ test "sha3-512 streaming" {
275275
276 const h1 = "a69f73cca23a9ac5c8b567dc185a756e97c982164fe25859e0d1dcc1475c80a615b2123af1f5f94c11e3e9402c3ac558f500199d95b6d3e301758586281dcd26";276 const h1 = "a69f73cca23a9ac5c8b567dc185a756e97c982164fe25859e0d1dcc1475c80a615b2123af1f5f94c11e3e9402c3ac558f500199d95b6d3e301758586281dcd26";
277 h.final(out[0..]);277 h.final(out[0..]);
278 htest.assertEqual(h1, out[0..]);278 try htest.assertEqual(h1, out[0..]);
279279
280 const h2 = "b751850b1a57168a5693cd924b6b096e08f621827444f70d884f5d0240d2712e10e116e9192af3c91a7ec57647e3934057340b4cf408d5a56592f8274eec53f0";280 const h2 = "b751850b1a57168a5693cd924b6b096e08f621827444f70d884f5d0240d2712e10e116e9192af3c91a7ec57647e3934057340b4cf408d5a56592f8274eec53f0";
281 h = Sha3_512.init(.{});281 h = Sha3_512.init(.{});
282 h.update("abc");282 h.update("abc");
283 h.final(out[0..]);283 h.final(out[0..]);
284 htest.assertEqual(h2, out[0..]);284 try htest.assertEqual(h2, out[0..]);
285285
286 h = Sha3_512.init(.{});286 h = Sha3_512.init(.{});
287 h.update("a");287 h.update("a");
288 h.update("b");288 h.update("b");
289 h.update("c");289 h.update("c");
290 h.final(out[0..]);290 h.final(out[0..]);
291 htest.assertEqual(h2, out[0..]);291 try htest.assertEqual(h2, out[0..]);
292}292}
293293
294test "sha3-512 aligned final" {294test "sha3-512 aligned final" {
...@@ -301,13 +301,13 @@ test "sha3-512 aligned final" {...@@ -301,13 +301,13 @@ test "sha3-512 aligned final" {
301}301}
302302
303test "keccak-256 single" {303test "keccak-256 single" {
304 htest.assertEqualHash(Keccak_256, "c5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470", "");304 try htest.assertEqualHash(Keccak_256, "c5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470", "");
305 htest.assertEqualHash(Keccak_256, "4e03657aea45a94fc7d47ba826c8d667c0d1e6e33a64a036ec44f58fa12d6c45", "abc");305 try htest.assertEqualHash(Keccak_256, "4e03657aea45a94fc7d47ba826c8d667c0d1e6e33a64a036ec44f58fa12d6c45", "abc");
306 htest.assertEqualHash(Keccak_256, "f519747ed599024f3882238e5ab43960132572b7345fbeb9a90769dafd21ad67", "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu");306 try htest.assertEqualHash(Keccak_256, "f519747ed599024f3882238e5ab43960132572b7345fbeb9a90769dafd21ad67", "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu");
307}307}
308308
309test "keccak-512 single" {309test "keccak-512 single" {
310 htest.assertEqualHash(Keccak_512, "0eab42de4c3ceb9235fc91acffe746b29c29a8c366b7c60e4e67c466f36a4304c00fa9caf9d87976ba469bcbe06713b435f091ef2769fb160cdab33d3670680e", "");310 try htest.assertEqualHash(Keccak_512, "0eab42de4c3ceb9235fc91acffe746b29c29a8c366b7c60e4e67c466f36a4304c00fa9caf9d87976ba469bcbe06713b435f091ef2769fb160cdab33d3670680e", "");
311 htest.assertEqualHash(Keccak_512, "18587dc2ea106b9a1563e32b3312421ca164c7f1f07bc922a9c83d77cea3a1e5d0c69910739025372dc14ac9642629379540c17e2a65b19d77aa511a9d00bb96", "abc");311 try htest.assertEqualHash(Keccak_512, "18587dc2ea106b9a1563e32b3312421ca164c7f1f07bc922a9c83d77cea3a1e5d0c69910739025372dc14ac9642629379540c17e2a65b19d77aa511a9d00bb96", "abc");
312 htest.assertEqualHash(Keccak_512, "ac2fb35251825d3aa48468a9948c0a91b8256f6d97d8fa4160faff2dd9dfcc24f3f1db7a983dad13d53439ccac0b37e24037e7b95f80f59f37a2f683c4ba4682", "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu");312 try htest.assertEqualHash(Keccak_512, "ac2fb35251825d3aa48468a9948c0a91b8256f6d97d8fa4160faff2dd9dfcc24f3f1db7a983dad13d53439ccac0b37e24037e7b95f80f59f37a2f683c4ba4682", "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu");
313}313}
lib/std/crypto/siphash.zig+3-3
...@@ -319,7 +319,7 @@ test "siphash64-2-4 sanity" {...@@ -319,7 +319,7 @@ test "siphash64-2-4 sanity" {
319319
320 var out: [siphash.mac_length]u8 = undefined;320 var out: [siphash.mac_length]u8 = undefined;
321 siphash.create(&out, buffer[0..i], test_key);321 siphash.create(&out, buffer[0..i], test_key);
322 testing.expectEqual(out, vector);322 try testing.expectEqual(out, vector);
323 }323 }
324}324}
325325
...@@ -399,7 +399,7 @@ test "siphash128-2-4 sanity" {...@@ -399,7 +399,7 @@ test "siphash128-2-4 sanity" {
399399
400 var out: [siphash.mac_length]u8 = undefined;400 var out: [siphash.mac_length]u8 = undefined;
401 siphash.create(&out, buffer[0..i], test_key[0..]);401 siphash.create(&out, buffer[0..i], test_key[0..]);
402 testing.expectEqual(out, vector);402 try testing.expectEqual(out, vector);
403 }403 }
404}404}
405405
...@@ -423,6 +423,6 @@ test "iterative non-divisible update" {...@@ -423,6 +423,6 @@ test "iterative non-divisible update" {
423 }423 }
424 const iterative_hash = siphash.finalInt();424 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);
427 }427 }
428}428}
lib/std/crypto/test.zig+4-4
...@@ -8,19 +8,19 @@ const testing = std.testing;...@@ -8,19 +8,19 @@ const testing = std.testing;
8const fmt = std.fmt;8const fmt = std.fmt;
99
10// Hash using the specified hasher `H` asserting `expected == H(input)`.10// 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 {
12 var h: [Hasher.digest_length]u8 = undefined;12 var h: [Hasher.digest_length]u8 = undefined;
13 Hasher.hash(input, &h, .{});13 Hasher.hash(input, &h, .{});
1414
15 assertEqual(expected_hex, &h);15 try assertEqual(expected_hex, &h);
16}16}
1717
18// Assert `expected` == hex(`input`) where `input` is a bytestring18// 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 {
20 var expected_bytes: [expected_hex.len / 2]u8 = undefined;20 var expected_bytes: [expected_hex.len / 2]u8 = undefined;
21 for (expected_bytes) |*r, i| {21 for (expected_bytes) |*r, i| {
22 r.* = fmt.parseInt(u8, expected_hex[2 * i .. 2 * i + 2], 16) catch unreachable;22 r.* = fmt.parseInt(u8, expected_hex[2 * i .. 2 * i + 2], 16) catch unreachable;
23 }23 }
2424
25 testing.expectEqualSlices(u8, &expected_bytes, input);25 try testing.expectEqualSlices(u8, &expected_bytes, input);
26}26}
lib/std/crypto/utils.zig+11-11
...@@ -92,9 +92,9 @@ test "crypto.utils.timingSafeEql" {...@@ -92,9 +92,9 @@ test "crypto.utils.timingSafeEql" {
92 var b: [100]u8 = undefined;92 var b: [100]u8 = undefined;
93 std.crypto.random.bytes(a[0..]);93 std.crypto.random.bytes(a[0..]);
94 std.crypto.random.bytes(b[0..]);94 std.crypto.random.bytes(b[0..]);
95 testing.expect(!timingSafeEql([100]u8, a, b));95 try testing.expect(!timingSafeEql([100]u8, a, b));
96 mem.copy(u8, a[0..], b[0..]);96 mem.copy(u8, a[0..], b[0..]);
97 testing.expect(timingSafeEql([100]u8, a, b));97 try testing.expect(timingSafeEql([100]u8, a, b));
98}98}
9999
100test "crypto.utils.timingSafeEql (vectors)" {100test "crypto.utils.timingSafeEql (vectors)" {
...@@ -104,22 +104,22 @@ test "crypto.utils.timingSafeEql (vectors)" {...@@ -104,22 +104,22 @@ test "crypto.utils.timingSafeEql (vectors)" {
104 std.crypto.random.bytes(b[0..]);104 std.crypto.random.bytes(b[0..]);
105 const v1: std.meta.Vector(100, u8) = a;105 const v1: std.meta.Vector(100, u8) = a;
106 const v2: std.meta.Vector(100, u8) = b;106 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));
108 const v3: std.meta.Vector(100, u8) = a;108 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));
110}110}
111111
112test "crypto.utils.timingSafeCompare" {112test "crypto.utils.timingSafeCompare" {
113 var a = [_]u8{10} ** 32;113 var a = [_]u8{10} ** 32;
114 var b = [_]u8{10} ** 32;114 var b = [_]u8{10} ** 32;
115 testing.expectEqual(timingSafeCompare(u8, &a, &b, .Big), .eq);115 try testing.expectEqual(timingSafeCompare(u8, &a, &b, .Big), .eq);
116 testing.expectEqual(timingSafeCompare(u8, &a, &b, .Little), .eq);116 try testing.expectEqual(timingSafeCompare(u8, &a, &b, .Little), .eq);
117 a[31] = 1;117 a[31] = 1;
118 testing.expectEqual(timingSafeCompare(u8, &a, &b, .Big), .lt);118 try testing.expectEqual(timingSafeCompare(u8, &a, &b, .Big), .lt);
119 testing.expectEqual(timingSafeCompare(u8, &a, &b, .Little), .lt);119 try testing.expectEqual(timingSafeCompare(u8, &a, &b, .Little), .lt);
120 a[0] = 20;120 a[0] = 20;
121 testing.expectEqual(timingSafeCompare(u8, &a, &b, .Big), .gt);121 try testing.expectEqual(timingSafeCompare(u8, &a, &b, .Big), .gt);
122 testing.expectEqual(timingSafeCompare(u8, &a, &b, .Little), .lt);122 try testing.expectEqual(timingSafeCompare(u8, &a, &b, .Little), .lt);
123}123}
124124
125test "crypto.utils.secureZero" {125test "crypto.utils.secureZero" {
...@@ -129,5 +129,5 @@ test "crypto.utils.secureZero" {...@@ -129,5 +129,5 @@ test "crypto.utils.secureZero" {
129 mem.set(u8, a[0..], 0);129 mem.set(u8, a[0..], 0);
130 secureZero(u8, b[0..]);130 secureZero(u8, b[0..]);
131131
132 testing.expectEqualSlices(u8, a[0..], b[0..]);132 try testing.expectEqualSlices(u8, a[0..], b[0..]);
133}133}
lib/std/cstr.zig+7-7
...@@ -27,13 +27,13 @@ pub fn cmp(a: [*:0]const u8, b: [*:0]const u8) i8 {...@@ -27,13 +27,13 @@ pub fn cmp(a: [*:0]const u8, b: [*:0]const u8) i8 {
27}27}
2828
29test "cstr fns" {29test "cstr fns" {
30 comptime testCStrFnsImpl();30 comptime try testCStrFnsImpl();
31 testCStrFnsImpl();31 try testCStrFnsImpl();
32}32}
3333
34fn testCStrFnsImpl() void {34fn testCStrFnsImpl() !void {
35 testing.expect(cmp("aoeu", "aoez") == -1);35 try testing.expect(cmp("aoeu", "aoez") == -1);
36 testing.expect(mem.len("123456789") == 9);36 try testing.expect(mem.len("123456789") == 9);
37}37}
3838
39/// Returns a mutable, null-terminated slice with the same length as `slice`.39/// 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 {...@@ -48,8 +48,8 @@ pub fn addNullByte(allocator: *mem.Allocator, slice: []const u8) ![:0]u8 {
48test "addNullByte" {48test "addNullByte" {
49 const slice = try addNullByte(std.testing.allocator, "hello"[0..4]);49 const slice = try addNullByte(std.testing.allocator, "hello"[0..4]);
50 defer std.testing.allocator.free(slice);50 defer std.testing.allocator.free(slice);
51 testing.expect(slice.len == 4);51 try testing.expect(slice.len == 4);
52 testing.expect(slice[4] == 0);52 try testing.expect(slice[4] == 0);
53}53}
5454
55pub const NullTerminated2DArray = struct {55pub const NullTerminated2DArray = struct {
lib/std/dynamic_library.zig+1-1
...@@ -408,7 +408,7 @@ test "dynamic_library" {...@@ -408,7 +408,7 @@ test "dynamic_library" {
408 };408 };
409409
410 const dynlib = DynLib.open(libname) catch |err| {410 const dynlib = DynLib.open(libname) catch |err| {
411 testing.expect(err == error.FileNotFound);411 try testing.expect(err == error.FileNotFound);
412 return;412 return;
413 };413 };
414}414}
lib/std/elf.zig+1-1
...@@ -565,7 +565,7 @@ test "bswapAllFields" {...@@ -565,7 +565,7 @@ test "bswapAllFields" {
565 .ch_addralign = 0x12124242,565 .ch_addralign = 0x12124242,
566 };566 };
567 bswapAllFields(Elf32_Chdr, &s);567 bswapAllFields(Elf32_Chdr, &s);
568 std.testing.expectEqual(Elf32_Chdr{568 try std.testing.expectEqual(Elf32_Chdr{
569 .ch_type = 0x34123412,569 .ch_type = 0x34123412,
570 .ch_size = 0x78567856,570 .ch_size = 0x78567856,
571 .ch_addralign = 0x42421212,571 .ch_addralign = 0x42421212,
lib/std/enums.zig+57-57
...@@ -119,10 +119,10 @@ test "std.enums.directEnumArray" {...@@ -119,10 +119,10 @@ test "std.enums.directEnumArray" {
119 .c = true,119 .c = true,
120 });120 });
121121
122 testing.expectEqual([7]bool, @TypeOf(array));122 try testing.expectEqual([7]bool, @TypeOf(array));
123 testing.expectEqual(true, array[4]);123 try testing.expectEqual(true, array[4]);
124 testing.expectEqual(false, array[6]);124 try testing.expectEqual(false, array[6]);
125 testing.expectEqual(true, array[2]);125 try testing.expectEqual(true, array[2]);
126}126}
127127
128/// Initializes an array of Data which can be indexed by128/// Initializes an array of Data which can be indexed by
...@@ -160,10 +160,10 @@ test "std.enums.directEnumArrayDefault" {...@@ -160,10 +160,10 @@ test "std.enums.directEnumArrayDefault" {
160 .b = runtime_false,160 .b = runtime_false,
161 });161 });
162162
163 testing.expectEqual([7]bool, @TypeOf(array));163 try testing.expectEqual([7]bool, @TypeOf(array));
164 testing.expectEqual(true, array[4]);164 try testing.expectEqual(true, array[4]);
165 testing.expectEqual(false, array[6]);165 try testing.expectEqual(false, array[6]);
166 testing.expectEqual(false, array[2]);166 try testing.expectEqual(false, array[2]);
167}167}
168168
169/// Cast an enum literal, value, or string to the enum value of type E169/// 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 {...@@ -190,23 +190,23 @@ pub fn nameCast(comptime E: type, comptime value: anytype) E {
190test "std.enums.nameCast" {190test "std.enums.nameCast" {
191 const A = enum(u1) { a = 0, b = 1 };191 const A = enum(u1) { a = 0, b = 1 };
192 const B = enum(u1) { a = 1, b = 0 };192 const B = enum(u1) { a = 1, b = 0 };
193 testing.expectEqual(A.a, nameCast(A, .a));193 try testing.expectEqual(A.a, nameCast(A, .a));
194 testing.expectEqual(A.a, nameCast(A, A.a));194 try testing.expectEqual(A.a, nameCast(A, A.a));
195 testing.expectEqual(A.a, nameCast(A, B.a));195 try testing.expectEqual(A.a, nameCast(A, B.a));
196 testing.expectEqual(A.a, nameCast(A, "a"));196 try testing.expectEqual(A.a, nameCast(A, "a"));
197 testing.expectEqual(A.a, nameCast(A, @as(*const [1]u8, "a")));197 try testing.expectEqual(A.a, nameCast(A, @as(*const [1]u8, "a")));
198 testing.expectEqual(A.a, nameCast(A, @as([:0]const u8, "a")));198 try testing.expectEqual(A.a, nameCast(A, @as([:0]const u8, "a")));
199 testing.expectEqual(A.a, nameCast(A, @as([]const u8, "a")));199 try testing.expectEqual(A.a, nameCast(A, @as([]const u8, "a")));
200200
201 testing.expectEqual(B.a, nameCast(B, .a));201 try testing.expectEqual(B.a, nameCast(B, .a));
202 testing.expectEqual(B.a, nameCast(B, A.a));202 try testing.expectEqual(B.a, nameCast(B, A.a));
203 testing.expectEqual(B.a, nameCast(B, B.a));203 try testing.expectEqual(B.a, nameCast(B, B.a));
204 testing.expectEqual(B.a, nameCast(B, "a"));204 try testing.expectEqual(B.a, nameCast(B, "a"));
205205
206 testing.expectEqual(B.b, nameCast(B, .b));206 try testing.expectEqual(B.b, nameCast(B, .b));
207 testing.expectEqual(B.b, nameCast(B, A.b));207 try testing.expectEqual(B.b, nameCast(B, A.b));
208 testing.expectEqual(B.b, nameCast(B, B.b));208 try testing.expectEqual(B.b, nameCast(B, B.b));
209 testing.expectEqual(B.b, nameCast(B, "b"));209 try testing.expectEqual(B.b, nameCast(B, "b"));
210}210}
211211
212/// A set of enum elements, backed by a bitfield. If the enum212/// A set of enum elements, backed by a bitfield. If the enum
...@@ -791,62 +791,62 @@ test "std.enums.EnumIndexer dense zeroed" {...@@ -791,62 +791,62 @@ test "std.enums.EnumIndexer dense zeroed" {
791 const E = enum(u2) { b = 1, a = 0, c = 2 };791 const E = enum(u2) { b = 1, a = 0, c = 2 };
792 const Indexer = EnumIndexer(E);792 const Indexer = EnumIndexer(E);
793 ensureIndexer(Indexer);793 ensureIndexer(Indexer);
794 testing.expectEqual(E, Indexer.Key);794 try testing.expectEqual(E, Indexer.Key);
795 testing.expectEqual(@as(usize, 3), Indexer.count);795 try testing.expectEqual(@as(usize, 3), Indexer.count);
796796
797 testing.expectEqual(@as(usize, 0), Indexer.indexOf(.a));797 try testing.expectEqual(@as(usize, 0), Indexer.indexOf(.a));
798 testing.expectEqual(@as(usize, 1), Indexer.indexOf(.b));798 try testing.expectEqual(@as(usize, 1), Indexer.indexOf(.b));
799 testing.expectEqual(@as(usize, 2), Indexer.indexOf(.c));799 try testing.expectEqual(@as(usize, 2), Indexer.indexOf(.c));
800800
801 testing.expectEqual(E.a, Indexer.keyForIndex(0));801 try testing.expectEqual(E.a, Indexer.keyForIndex(0));
802 testing.expectEqual(E.b, Indexer.keyForIndex(1));802 try testing.expectEqual(E.b, Indexer.keyForIndex(1));
803 testing.expectEqual(E.c, Indexer.keyForIndex(2));803 try testing.expectEqual(E.c, Indexer.keyForIndex(2));
804}804}
805805
806test "std.enums.EnumIndexer dense positive" {806test "std.enums.EnumIndexer dense positive" {
807 const E = enum(u4) { c = 6, a = 4, b = 5 };807 const E = enum(u4) { c = 6, a = 4, b = 5 };
808 const Indexer = EnumIndexer(E);808 const Indexer = EnumIndexer(E);
809 ensureIndexer(Indexer);809 ensureIndexer(Indexer);
810 testing.expectEqual(E, Indexer.Key);810 try testing.expectEqual(E, Indexer.Key);
811 testing.expectEqual(@as(usize, 3), Indexer.count);811 try testing.expectEqual(@as(usize, 3), Indexer.count);
812812
813 testing.expectEqual(@as(usize, 0), Indexer.indexOf(.a));813 try testing.expectEqual(@as(usize, 0), Indexer.indexOf(.a));
814 testing.expectEqual(@as(usize, 1), Indexer.indexOf(.b));814 try testing.expectEqual(@as(usize, 1), Indexer.indexOf(.b));
815 testing.expectEqual(@as(usize, 2), Indexer.indexOf(.c));815 try testing.expectEqual(@as(usize, 2), Indexer.indexOf(.c));
816816
817 testing.expectEqual(E.a, Indexer.keyForIndex(0));817 try testing.expectEqual(E.a, Indexer.keyForIndex(0));
818 testing.expectEqual(E.b, Indexer.keyForIndex(1));818 try testing.expectEqual(E.b, Indexer.keyForIndex(1));
819 testing.expectEqual(E.c, Indexer.keyForIndex(2));819 try testing.expectEqual(E.c, Indexer.keyForIndex(2));
820}820}
821821
822test "std.enums.EnumIndexer dense negative" {822test "std.enums.EnumIndexer dense negative" {
823 const E = enum(i4) { a = -6, c = -4, b = -5 };823 const E = enum(i4) { a = -6, c = -4, b = -5 };
824 const Indexer = EnumIndexer(E);824 const Indexer = EnumIndexer(E);
825 ensureIndexer(Indexer);825 ensureIndexer(Indexer);
826 testing.expectEqual(E, Indexer.Key);826 try testing.expectEqual(E, Indexer.Key);
827 testing.expectEqual(@as(usize, 3), Indexer.count);827 try testing.expectEqual(@as(usize, 3), Indexer.count);
828828
829 testing.expectEqual(@as(usize, 0), Indexer.indexOf(.a));829 try testing.expectEqual(@as(usize, 0), Indexer.indexOf(.a));
830 testing.expectEqual(@as(usize, 1), Indexer.indexOf(.b));830 try testing.expectEqual(@as(usize, 1), Indexer.indexOf(.b));
831 testing.expectEqual(@as(usize, 2), Indexer.indexOf(.c));831 try testing.expectEqual(@as(usize, 2), Indexer.indexOf(.c));
832832
833 testing.expectEqual(E.a, Indexer.keyForIndex(0));833 try testing.expectEqual(E.a, Indexer.keyForIndex(0));
834 testing.expectEqual(E.b, Indexer.keyForIndex(1));834 try testing.expectEqual(E.b, Indexer.keyForIndex(1));
835 testing.expectEqual(E.c, Indexer.keyForIndex(2));835 try testing.expectEqual(E.c, Indexer.keyForIndex(2));
836}836}
837837
838test "std.enums.EnumIndexer sparse" {838test "std.enums.EnumIndexer sparse" {
839 const E = enum(i4) { a = -2, c = 6, b = 4 };839 const E = enum(i4) { a = -2, c = 6, b = 4 };
840 const Indexer = EnumIndexer(E);840 const Indexer = EnumIndexer(E);
841 ensureIndexer(Indexer);841 ensureIndexer(Indexer);
842 testing.expectEqual(E, Indexer.Key);842 try testing.expectEqual(E, Indexer.Key);
843 testing.expectEqual(@as(usize, 3), Indexer.count);843 try testing.expectEqual(@as(usize, 3), Indexer.count);
844844
845 testing.expectEqual(@as(usize, 0), Indexer.indexOf(.a));845 try testing.expectEqual(@as(usize, 0), Indexer.indexOf(.a));
846 testing.expectEqual(@as(usize, 1), Indexer.indexOf(.b));846 try testing.expectEqual(@as(usize, 1), Indexer.indexOf(.b));
847 testing.expectEqual(@as(usize, 2), Indexer.indexOf(.c));847 try testing.expectEqual(@as(usize, 2), Indexer.indexOf(.c));
848848
849 testing.expectEqual(E.a, Indexer.keyForIndex(0));849 try testing.expectEqual(E.a, Indexer.keyForIndex(0));
850 testing.expectEqual(E.b, Indexer.keyForIndex(1));850 try testing.expectEqual(E.b, Indexer.keyForIndex(1));
851 testing.expectEqual(E.c, Indexer.keyForIndex(2));851 try testing.expectEqual(E.c, Indexer.keyForIndex(2));
852}852}
lib/std/event/batch.zig+2-2
...@@ -119,12 +119,12 @@ test "std.event.Batch" {...@@ -119,12 +119,12 @@ test "std.event.Batch" {
119 batch.add(&async sleepALittle(&count));119 batch.add(&async sleepALittle(&count));
120 batch.add(&async increaseByTen(&count));120 batch.add(&async increaseByTen(&count));
121 batch.wait();121 batch.wait();
122 testing.expect(count == 11);122 try testing.expect(count == 11);
123123
124 var another = Batch(anyerror!void, 2, .auto_async).init();124 var another = Batch(anyerror!void, 2, .auto_async).init();
125 another.add(&async somethingElse());125 another.add(&async somethingElse());
126 another.add(&async doSomethingThatFails());126 another.add(&async doSomethingThatFails());
127 testing.expectError(error.ItBroke, another.wait());127 try testing.expectError(error.ItBroke, another.wait());
128}128}
129129
130fn sleepALittle(count: *usize) void {130fn sleepALittle(count: *usize) void {
lib/std/event/channel.zig+7-7
...@@ -310,25 +310,25 @@ test "std.event.Channel wraparound" {...@@ -310,25 +310,25 @@ test "std.event.Channel wraparound" {
310 // the buffer wraps around, make sure it doesn't crash.310 // the buffer wraps around, make sure it doesn't crash.
311 var result: i32 = undefined;311 var result: i32 = undefined;
312 channel.put(5);312 channel.put(5);
313 testing.expectEqual(@as(i32, 5), channel.get());313 try testing.expectEqual(@as(i32, 5), channel.get());
314 channel.put(6);314 channel.put(6);
315 testing.expectEqual(@as(i32, 6), channel.get());315 try testing.expectEqual(@as(i32, 6), channel.get());
316 channel.put(7);316 channel.put(7);
317 testing.expectEqual(@as(i32, 7), channel.get());317 try testing.expectEqual(@as(i32, 7), channel.get());
318}318}
319fn testChannelGetter(channel: *Channel(i32)) callconv(.Async) void {319fn testChannelGetter(channel: *Channel(i32)) callconv(.Async) void {
320 const value1 = channel.get();320 const value1 = channel.get();
321 testing.expect(value1 == 1234);321 try testing.expect(value1 == 1234);
322322
323 const value2 = channel.get();323 const value2 = channel.get();
324 testing.expect(value2 == 4567);324 try testing.expect(value2 == 4567);
325325
326 const value3 = channel.getOrNull();326 const value3 = channel.getOrNull();
327 testing.expect(value3 == null);327 try testing.expect(value3 == null);
328328
329 var last_put = async testPut(channel, 4444);329 var last_put = async testPut(channel, 4444);
330 const value4 = channel.getOrNull();330 const value4 = channel.getOrNull();
331 testing.expect(value4.? == 4444);331 try testing.expect(value4.? == 4444);
332 await last_put;332 await last_put;
333}333}
334fn testChannelPutter(channel: *Channel(i32)) callconv(.Async) void {334fn testChannelPutter(channel: *Channel(i32)) callconv(.Async) void {
lib/std/event/future.zig+1-1
...@@ -107,7 +107,7 @@ fn testFuture() void {...@@ -107,7 +107,7 @@ fn testFuture() void {
107107
108 const result = (await a) + (await b);108 const result = (await a) + (await b);
109109
110 testing.expect(result == 12);110 try testing.expect(result == 12);
111}111}
112112
113fn waitOnFuture(future: *Future(i32)) i32 {113fn waitOnFuture(future: *Future(i32)) i32 {
lib/std/event/group.zig+2-2
...@@ -140,14 +140,14 @@ fn testGroup(allocator: *Allocator) callconv(.Async) void {...@@ -140,14 +140,14 @@ fn testGroup(allocator: *Allocator) callconv(.Async) void {
140 var increase_by_ten_frame = async increaseByTen(&count);140 var increase_by_ten_frame = async increaseByTen(&count);
141 group.add(&increase_by_ten_frame) catch @panic("memory");141 group.add(&increase_by_ten_frame) catch @panic("memory");
142 group.wait();142 group.wait();
143 testing.expect(count == 11);143 try testing.expect(count == 11);
144144
145 var another = Group(anyerror!void).init(allocator);145 var another = Group(anyerror!void).init(allocator);
146 var something_else_frame = async somethingElse();146 var something_else_frame = async somethingElse();
147 another.add(&something_else_frame) catch @panic("memory");147 another.add(&something_else_frame) catch @panic("memory");
148 var something_that_fails_frame = async doSomethingThatFails();148 var something_that_fails_frame = async doSomethingThatFails();
149 another.add(&something_that_fails_frame) catch @panic("memory");149 another.add(&something_that_fails_frame) catch @panic("memory");
150 testing.expectError(error.ItBroke, another.wait());150 try testing.expectError(error.ItBroke, another.wait());
151}151}
152fn sleepALittle(count: *usize) callconv(.Async) void {152fn sleepALittle(count: *usize) callconv(.Async) void {
153 std.time.sleep(1 * std.time.ns_per_ms);153 std.time.sleep(1 * std.time.ns_per_ms);
lib/std/event/lock.zig+1-1
...@@ -136,7 +136,7 @@ test "std.event.Lock" {...@@ -136,7 +136,7 @@ test "std.event.Lock" {
136 testLock(&lock);136 testLock(&lock);
137137
138 const expected_result = [1]i32{3 * @intCast(i32, shared_test_data.len)} ** shared_test_data.len;138 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);
140}140}
141fn testLock(lock: *Lock) void {141fn testLock(lock: *Lock) void {
142 var handle1 = async lockRunner(lock);142 var handle1 = async lockRunner(lock);
lib/std/event/loop.zig+3-3
...@@ -1655,7 +1655,7 @@ fn testEventLoop() i32 {...@@ -1655,7 +1655,7 @@ fn testEventLoop() i32 {
16551655
1656fn testEventLoop2(h: anyframe->i32, did_it: *bool) void {1656fn testEventLoop2(h: anyframe->i32, did_it: *bool) void {
1657 const value = await h;1657 const value = await h;
1658 testing.expect(value == 1234);1658 try testing.expect(value == 1234);
1659 did_it.* = true;1659 did_it.* = true;
1660}1660}
16611661
...@@ -1682,7 +1682,7 @@ test "std.event.Loop - runDetached" {...@@ -1682,7 +1682,7 @@ test "std.event.Loop - runDetached" {
1682 // with the previous runDetached.1682 // with the previous runDetached.
1683 loop.run();1683 loop.run();
16841684
1685 testing.expect(testRunDetachedData == 1);1685 try testing.expect(testRunDetachedData == 1);
1686}1686}
16871687
1688fn testRunDetached() void {1688fn testRunDetached() void {
...@@ -1705,7 +1705,7 @@ test "std.event.Loop - sleep" {...@@ -1705,7 +1705,7 @@ test "std.event.Loop - sleep" {
1705 for (frames) |*frame|1705 for (frames) |*frame|
1706 await frame;1706 await frame;
17071707
1708 testing.expect(sleep_count == frames.len);1708 try testing.expect(sleep_count == frames.len);
1709}1709}
17101710
1711fn testSleep(wait_ns: u64, sleep_count: *usize) void {1711fn testSleep(wait_ns: u64, sleep_count: *usize) void {
lib/std/event/rwlock.zig+3-3
...@@ -228,7 +228,7 @@ test "std.event.RwLock" {...@@ -228,7 +228,7 @@ test "std.event.RwLock" {
228 const handle = testLock(std.heap.page_allocator, &lock);228 const handle = testLock(std.heap.page_allocator, &lock);
229229
230 const expected_result = [1]i32{shared_it_count * @intCast(i32, shared_test_data.len)} ** shared_test_data.len;230 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);
232}232}
233fn testLock(allocator: *Allocator, lock: *RwLock) callconv(.Async) void {233fn testLock(allocator: *Allocator, lock: *RwLock) callconv(.Async) void {
234 var read_nodes: [100]Loop.NextTickNode = undefined;234 var read_nodes: [100]Loop.NextTickNode = undefined;
...@@ -290,7 +290,7 @@ fn readRunner(lock: *RwLock) callconv(.Async) void {...@@ -290,7 +290,7 @@ fn readRunner(lock: *RwLock) callconv(.Async) void {
290 const handle = await lock_promise;290 const handle = await lock_promise;
291 defer handle.release();291 defer handle.release();
292292
293 testing.expect(shared_test_index == 0);293 try testing.expect(shared_test_index == 0);
294 testing.expect(shared_test_data[i] == @intCast(i32, shared_count));294 try testing.expect(shared_test_data[i] == @intCast(i32, shared_count));
295 }295 }
296}296}
lib/std/fifo.zig+38-38
...@@ -402,59 +402,59 @@ test "LinearFifo(u8, .Dynamic)" {...@@ -402,59 +402,59 @@ test "LinearFifo(u8, .Dynamic)" {
402 defer fifo.deinit();402 defer fifo.deinit();
403403
404 try fifo.write("HELLO");404 try fifo.write("HELLO");
405 testing.expectEqual(@as(usize, 5), fifo.readableLength());405 try testing.expectEqual(@as(usize, 5), fifo.readableLength());
406 testing.expectEqualSlices(u8, "HELLO", fifo.readableSlice(0));406 try testing.expectEqualSlices(u8, "HELLO", fifo.readableSlice(0));
407407
408 {408 {
409 var i: usize = 0;409 var i: usize = 0;
410 while (i < 5) : (i += 1) {410 while (i < 5) : (i += 1) {
411 try fifo.write(&[_]u8{fifo.peekItem(i)});411 try fifo.write(&[_]u8{fifo.peekItem(i)});
412 }412 }
413 testing.expectEqual(@as(usize, 10), fifo.readableLength());413 try testing.expectEqual(@as(usize, 10), fifo.readableLength());
414 testing.expectEqualSlices(u8, "HELLOHELLO", fifo.readableSlice(0));414 try testing.expectEqualSlices(u8, "HELLOHELLO", fifo.readableSlice(0));
415 }415 }
416416
417 {417 {
418 testing.expectEqual(@as(u8, 'H'), fifo.readItem().?);418 try testing.expectEqual(@as(u8, 'H'), fifo.readItem().?);
419 testing.expectEqual(@as(u8, 'E'), fifo.readItem().?);419 try testing.expectEqual(@as(u8, 'E'), fifo.readItem().?);
420 testing.expectEqual(@as(u8, 'L'), fifo.readItem().?);420 try testing.expectEqual(@as(u8, 'L'), fifo.readItem().?);
421 testing.expectEqual(@as(u8, 'L'), fifo.readItem().?);421 try testing.expectEqual(@as(u8, 'L'), fifo.readItem().?);
422 testing.expectEqual(@as(u8, 'O'), fifo.readItem().?);422 try testing.expectEqual(@as(u8, 'O'), fifo.readItem().?);
423 }423 }
424 testing.expectEqual(@as(usize, 5), fifo.readableLength());424 try testing.expectEqual(@as(usize, 5), fifo.readableLength());
425425
426 { // Writes that wrap around426 { // Writes that wrap around
427 testing.expectEqual(@as(usize, 11), fifo.writableLength());427 try testing.expectEqual(@as(usize, 11), fifo.writableLength());
428 testing.expectEqual(@as(usize, 6), fifo.writableSlice(0).len);428 try testing.expectEqual(@as(usize, 6), fifo.writableSlice(0).len);
429 fifo.writeAssumeCapacity("6<chars<11");429 fifo.writeAssumeCapacity("6<chars<11");
430 testing.expectEqualSlices(u8, "HELLO6<char", fifo.readableSlice(0));430 try testing.expectEqualSlices(u8, "HELLO6<char", fifo.readableSlice(0));
431 testing.expectEqualSlices(u8, "s<11", fifo.readableSlice(11));431 try testing.expectEqualSlices(u8, "s<11", fifo.readableSlice(11));
432 testing.expectEqualSlices(u8, "11", fifo.readableSlice(13));432 try testing.expectEqualSlices(u8, "11", fifo.readableSlice(13));
433 testing.expectEqualSlices(u8, "", fifo.readableSlice(15));433 try testing.expectEqualSlices(u8, "", fifo.readableSlice(15));
434 fifo.discard(11);434 fifo.discard(11);
435 testing.expectEqualSlices(u8, "s<11", fifo.readableSlice(0));435 try testing.expectEqualSlices(u8, "s<11", fifo.readableSlice(0));
436 fifo.discard(4);436 fifo.discard(4);
437 testing.expectEqual(@as(usize, 0), fifo.readableLength());437 try testing.expectEqual(@as(usize, 0), fifo.readableLength());
438 }438 }
439439
440 {440 {
441 const buf = try fifo.writableWithSize(12);441 const buf = try fifo.writableWithSize(12);
442 testing.expectEqual(@as(usize, 12), buf.len);442 try testing.expectEqual(@as(usize, 12), buf.len);
443 var i: u8 = 0;443 var i: u8 = 0;
444 while (i < 10) : (i += 1) {444 while (i < 10) : (i += 1) {
445 buf[i] = i + 'a';445 buf[i] = i + 'a';
446 }446 }
447 fifo.update(10);447 fifo.update(10);
448 testing.expectEqualSlices(u8, "abcdefghij", fifo.readableSlice(0));448 try testing.expectEqualSlices(u8, "abcdefghij", fifo.readableSlice(0));
449 }449 }
450450
451 {451 {
452 try fifo.unget("prependedstring");452 try fifo.unget("prependedstring");
453 var result: [30]u8 = undefined;453 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)]);
455 try fifo.unget("b");455 try fifo.unget("b");
456 try fifo.unget("a");456 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)]);
458 }458 }
459459
460 fifo.shrink(0);460 fifo.shrink(0);
...@@ -462,17 +462,17 @@ test "LinearFifo(u8, .Dynamic)" {...@@ -462,17 +462,17 @@ test "LinearFifo(u8, .Dynamic)" {
462 {462 {
463 try fifo.writer().print("{s}, {s}!", .{ "Hello", "World" });463 try fifo.writer().print("{s}, {s}!", .{ "Hello", "World" });
464 var result: [30]u8 = undefined;464 var result: [30]u8 = undefined;
465 testing.expectEqualSlices(u8, "Hello, World!", result[0..fifo.read(&result)]);465 try testing.expectEqualSlices(u8, "Hello, World!", result[0..fifo.read(&result)]);
466 testing.expectEqual(@as(usize, 0), fifo.readableLength());466 try testing.expectEqual(@as(usize, 0), fifo.readableLength());
467 }467 }
468468
469 {469 {
470 try fifo.writer().writeAll("This is a test");470 try fifo.writer().writeAll("This is a test");
471 var result: [30]u8 = undefined;471 var result: [30]u8 = undefined;
472 testing.expectEqualSlices(u8, "This", (try fifo.reader().readUntilDelimiterOrEof(&result, ' ')).?);472 try testing.expectEqualSlices(u8, "This", (try fifo.reader().readUntilDelimiterOrEof(&result, ' ')).?);
473 testing.expectEqualSlices(u8, "is", (try fifo.reader().readUntilDelimiterOrEof(&result, ' ')).?);473 try testing.expectEqualSlices(u8, "is", (try fifo.reader().readUntilDelimiterOrEof(&result, ' ')).?);
474 testing.expectEqualSlices(u8, "a", (try fifo.reader().readUntilDelimiterOrEof(&result, ' ')).?);474 try testing.expectEqualSlices(u8, "a", (try fifo.reader().readUntilDelimiterOrEof(&result, ' ')).?);
475 testing.expectEqualSlices(u8, "test", (try fifo.reader().readUntilDelimiterOrEof(&result, ' ')).?);475 try testing.expectEqualSlices(u8, "test", (try fifo.reader().readUntilDelimiterOrEof(&result, ' ')).?);
476 }476 }
477477
478 {478 {
...@@ -481,7 +481,7 @@ test "LinearFifo(u8, .Dynamic)" {...@@ -481,7 +481,7 @@ test "LinearFifo(u8, .Dynamic)" {
481 var out_buf: [50]u8 = undefined;481 var out_buf: [50]u8 = undefined;
482 var out_fbs = std.io.fixedBufferStream(&out_buf);482 var out_fbs = std.io.fixedBufferStream(&out_buf);
483 try fifo.pump(in_fbs.reader(), out_fbs.writer());483 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());
485 }485 }
486}486}
487487
...@@ -498,28 +498,28 @@ test "LinearFifo" {...@@ -498,28 +498,28 @@ test "LinearFifo" {
498 defer fifo.deinit();498 defer fifo.deinit();
499499
500 try fifo.write(&[_]T{ 0, 1, 1, 0, 1 });500 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
503 {503 {
504 testing.expectEqual(@as(T, 0), fifo.readItem().?);504 try testing.expectEqual(@as(T, 0), fifo.readItem().?);
505 testing.expectEqual(@as(T, 1), fifo.readItem().?);505 try testing.expectEqual(@as(T, 1), fifo.readItem().?);
506 testing.expectEqual(@as(T, 1), fifo.readItem().?);506 try testing.expectEqual(@as(T, 1), fifo.readItem().?);
507 testing.expectEqual(@as(T, 0), fifo.readItem().?);507 try testing.expectEqual(@as(T, 0), fifo.readItem().?);
508 testing.expectEqual(@as(T, 1), fifo.readItem().?);508 try testing.expectEqual(@as(T, 1), fifo.readItem().?);
509 testing.expectEqual(@as(usize, 0), fifo.readableLength());509 try testing.expectEqual(@as(usize, 0), fifo.readableLength());
510 }510 }
511511
512 {512 {
513 try fifo.writeItem(1);513 try fifo.writeItem(1);
514 try fifo.writeItem(1);514 try fifo.writeItem(1);
515 try fifo.writeItem(1);515 try fifo.writeItem(1);
516 testing.expectEqual(@as(usize, 3), fifo.readableLength());516 try testing.expectEqual(@as(usize, 3), fifo.readableLength());
517 }517 }
518518
519 {519 {
520 var readBuf: [3]T = undefined;520 var readBuf: [3]T = undefined;
521 const n = fifo.read(&readBuf);521 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.
523 }523 }
524 }524 }
525 }525 }
lib/std/fmt.zig+89-89
...@@ -1422,7 +1422,7 @@ test "fmtDuration" {...@@ -1422,7 +1422,7 @@ test "fmtDuration" {
1422 .{ .s = "1y1m999ns", .d = 365 * std.time.ns_per_day + std.time.ns_per_min + 999 },1422 .{ .s = "1y1m999ns", .d = 365 * std.time.ns_per_day + std.time.ns_per_min + 999 },
1423 }) |tc| {1423 }) |tc| {
1424 const slice = try bufPrint(&buf, "{}", .{fmtDuration(tc.d)});1424 const slice = try bufPrint(&buf, "{}", .{fmtDuration(tc.d)});
1425 std.testing.expectEqualStrings(tc.s, slice);1425 try std.testing.expectEqualStrings(tc.s, slice);
1426 }1426 }
1427}1427}
14281428
...@@ -1479,54 +1479,54 @@ pub fn parseInt(comptime T: type, buf: []const u8, radix: u8) ParseIntError!T {...@@ -1479,54 +1479,54 @@ pub fn parseInt(comptime T: type, buf: []const u8, radix: u8) ParseIntError!T {
1479}1479}
14801480
1481test "parseInt" {1481test "parseInt" {
1482 std.testing.expect((try parseInt(i32, "-10", 10)) == -10);1482 try std.testing.expect((try parseInt(i32, "-10", 10)) == -10);
1483 std.testing.expect((try parseInt(i32, "+10", 10)) == 10);1483 try std.testing.expect((try parseInt(i32, "+10", 10)) == 10);
1484 std.testing.expect((try parseInt(u32, "+10", 10)) == 10);1484 try std.testing.expect((try parseInt(u32, "+10", 10)) == 10);
1485 std.testing.expectError(error.Overflow, parseInt(u32, "-10", 10));1485 try std.testing.expectError(error.Overflow, parseInt(u32, "-10", 10));
1486 std.testing.expectError(error.InvalidCharacter, parseInt(u32, " 10", 10));1486 try std.testing.expectError(error.InvalidCharacter, parseInt(u32, " 10", 10));
1487 std.testing.expectError(error.InvalidCharacter, parseInt(u32, "10 ", 10));1487 try std.testing.expectError(error.InvalidCharacter, parseInt(u32, "10 ", 10));
1488 std.testing.expectError(error.InvalidCharacter, parseInt(u32, "_10_", 10));1488 try std.testing.expectError(error.InvalidCharacter, parseInt(u32, "_10_", 10));
1489 std.testing.expectError(error.InvalidCharacter, parseInt(u32, "0x_10_", 10));1489 try std.testing.expectError(error.InvalidCharacter, parseInt(u32, "0x_10_", 10));
1490 std.testing.expectError(error.InvalidCharacter, parseInt(u32, "0x10_", 10));1490 try std.testing.expectError(error.InvalidCharacter, parseInt(u32, "0x10_", 10));
1491 std.testing.expectError(error.InvalidCharacter, parseInt(u32, "0x_10", 10));1491 try std.testing.expectError(error.InvalidCharacter, parseInt(u32, "0x_10", 10));
1492 std.testing.expect((try parseInt(u8, "255", 10)) == 255);1492 try std.testing.expect((try parseInt(u8, "255", 10)) == 255);
1493 std.testing.expectError(error.Overflow, parseInt(u8, "256", 10));1493 try std.testing.expectError(error.Overflow, parseInt(u8, "256", 10));
14941494
1495 // +0 and -0 should work for unsigned1495 // +0 and -0 should work for unsigned
1496 std.testing.expect((try parseInt(u8, "-0", 10)) == 0);1496 try std.testing.expect((try parseInt(u8, "-0", 10)) == 0);
1497 std.testing.expect((try parseInt(u8, "+0", 10)) == 0);1497 try std.testing.expect((try parseInt(u8, "+0", 10)) == 0);
14981498
1499 // ensure minInt is parsed correctly1499 // ensure minInt is parsed correctly
1500 std.testing.expect((try parseInt(i8, "-128", 10)) == math.minInt(i8));1500 try std.testing.expect((try parseInt(i8, "-128", 10)) == math.minInt(i8));
1501 std.testing.expect((try parseInt(i43, "-4398046511104", 10)) == math.minInt(i43));1501 try std.testing.expect((try parseInt(i43, "-4398046511104", 10)) == math.minInt(i43));
15021502
1503 // empty string or bare +- is invalid1503 // empty string or bare +- is invalid
1504 std.testing.expectError(error.InvalidCharacter, parseInt(u32, "", 10));1504 try std.testing.expectError(error.InvalidCharacter, parseInt(u32, "", 10));
1505 std.testing.expectError(error.InvalidCharacter, parseInt(i32, "", 10));1505 try std.testing.expectError(error.InvalidCharacter, parseInt(i32, "", 10));
1506 std.testing.expectError(error.InvalidCharacter, parseInt(u32, "+", 10));1506 try std.testing.expectError(error.InvalidCharacter, parseInt(u32, "+", 10));
1507 std.testing.expectError(error.InvalidCharacter, parseInt(i32, "+", 10));1507 try std.testing.expectError(error.InvalidCharacter, parseInt(i32, "+", 10));
1508 std.testing.expectError(error.InvalidCharacter, parseInt(u32, "-", 10));1508 try std.testing.expectError(error.InvalidCharacter, parseInt(u32, "-", 10));
1509 std.testing.expectError(error.InvalidCharacter, parseInt(i32, "-", 10));1509 try std.testing.expectError(error.InvalidCharacter, parseInt(i32, "-", 10));
15101510
1511 // autodectect the radix1511 // autodectect the radix
1512 std.testing.expect((try parseInt(i32, "111", 0)) == 111);1512 try std.testing.expect((try parseInt(i32, "111", 0)) == 111);
1513 std.testing.expect((try parseInt(i32, "1_1_1", 0)) == 111);1513 try std.testing.expect((try parseInt(i32, "1_1_1", 0)) == 111);
1514 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 std.testing.expect((try parseInt(i32, "+0b111", 0)) == 7);1515 try std.testing.expect((try parseInt(i32, "+0b111", 0)) == 7);
1516 std.testing.expect((try parseInt(i32, "+0b1_11", 0)) == 7);1516 try std.testing.expect((try parseInt(i32, "+0b1_11", 0)) == 7);
1517 std.testing.expect((try parseInt(i32, "+0o111", 0)) == 73);1517 try std.testing.expect((try parseInt(i32, "+0o111", 0)) == 73);
1518 std.testing.expect((try parseInt(i32, "+0o11_1", 0)) == 73);1518 try std.testing.expect((try parseInt(i32, "+0o11_1", 0)) == 73);
1519 std.testing.expect((try parseInt(i32, "+0x111", 0)) == 273);1519 try std.testing.expect((try parseInt(i32, "+0x111", 0)) == 273);
1520 std.testing.expect((try parseInt(i32, "-0b111", 0)) == -7);1520 try std.testing.expect((try parseInt(i32, "-0b111", 0)) == -7);
1521 std.testing.expect((try parseInt(i32, "-0b11_1", 0)) == -7);1521 try std.testing.expect((try parseInt(i32, "-0b11_1", 0)) == -7);
1522 std.testing.expect((try parseInt(i32, "-0o111", 0)) == -73);1522 try std.testing.expect((try parseInt(i32, "-0o111", 0)) == -73);
1523 std.testing.expect((try parseInt(i32, "-0x111", 0)) == -273);1523 try std.testing.expect((try parseInt(i32, "-0x111", 0)) == -273);
1524 std.testing.expect((try parseInt(i32, "-0x1_11", 0)) == -273);1524 try std.testing.expect((try parseInt(i32, "-0x1_11", 0)) == -273);
15251525
1526 // bare binary/octal/decimal prefix is invalid1526 // bare binary/octal/decimal prefix is invalid
1527 std.testing.expectError(error.InvalidCharacter, parseInt(u32, "0b", 0));1527 try std.testing.expectError(error.InvalidCharacter, parseInt(u32, "0b", 0));
1528 std.testing.expectError(error.InvalidCharacter, parseInt(u32, "0o", 0));1528 try std.testing.expectError(error.InvalidCharacter, parseInt(u32, "0o", 0));
1529 std.testing.expectError(error.InvalidCharacter, parseInt(u32, "0x", 0));1529 try std.testing.expectError(error.InvalidCharacter, parseInt(u32, "0x", 0));
1530}1530}
15311531
1532fn parseWithSign(1532fn parseWithSign(
...@@ -1598,39 +1598,39 @@ pub fn parseUnsigned(comptime T: type, buf: []const u8, radix: u8) ParseIntError...@@ -1598,39 +1598,39 @@ pub fn parseUnsigned(comptime T: type, buf: []const u8, radix: u8) ParseIntError
1598}1598}
15991599
1600test "parseUnsigned" {1600test "parseUnsigned" {
1601 std.testing.expect((try parseUnsigned(u16, "050124", 10)) == 50124);1601 try std.testing.expect((try parseUnsigned(u16, "050124", 10)) == 50124);
1602 std.testing.expect((try parseUnsigned(u16, "65535", 10)) == 65535);1602 try std.testing.expect((try parseUnsigned(u16, "65535", 10)) == 65535);
1603 std.testing.expect((try parseUnsigned(u16, "65_535", 10)) == 65535);1603 try std.testing.expect((try parseUnsigned(u16, "65_535", 10)) == 65535);
1604 std.testing.expectError(error.Overflow, parseUnsigned(u16, "65536", 10));1604 try std.testing.expectError(error.Overflow, parseUnsigned(u16, "65536", 10));
16051605
1606 std.testing.expect((try parseUnsigned(u64, "0ffffffffffffffff", 16)) == 0xffffffffffffffff);1606 try std.testing.expect((try parseUnsigned(u64, "0ffffffffffffffff", 16)) == 0xffffffffffffffff);
1607 std.testing.expect((try parseUnsigned(u64, "0f_fff_fff_fff_fff_fff", 16)) == 0xffffffffffffffff);1607 try std.testing.expect((try parseUnsigned(u64, "0f_fff_fff_fff_fff_fff", 16)) == 0xffffffffffffffff);
1608 std.testing.expectError(error.Overflow, parseUnsigned(u64, "10000000000000000", 16));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);1612 try std.testing.expect((try parseUnsigned(u7, "1", 10)) == 1);
1613 std.testing.expect((try parseUnsigned(u7, "1000", 2)) == 8);1613 try std.testing.expect((try parseUnsigned(u7, "1000", 2)) == 8);
16141614
1615 std.testing.expectError(error.InvalidCharacter, parseUnsigned(u32, "f", 10));1615 try std.testing.expectError(error.InvalidCharacter, parseUnsigned(u32, "f", 10));
1616 std.testing.expectError(error.InvalidCharacter, parseUnsigned(u8, "109", 8));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
1620 // these numbers should fit even though the radix itself doesn't fit in the destination type1620 // 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);1621 try std.testing.expect((try parseUnsigned(u1, "0", 10)) == 0);
1622 std.testing.expect((try parseUnsigned(u1, "1", 10)) == 1);1622 try std.testing.expect((try parseUnsigned(u1, "1", 10)) == 1);
1623 std.testing.expectError(error.Overflow, parseUnsigned(u1, "2", 10));1623 try std.testing.expectError(error.Overflow, parseUnsigned(u1, "2", 10));
1624 std.testing.expect((try parseUnsigned(u1, "001", 16)) == 1);1624 try std.testing.expect((try parseUnsigned(u1, "001", 16)) == 1);
1625 std.testing.expect((try parseUnsigned(u2, "3", 16)) == 3);1625 try std.testing.expect((try parseUnsigned(u2, "3", 16)) == 3);
1626 std.testing.expectError(error.Overflow, parseUnsigned(u2, "4", 16));1626 try std.testing.expectError(error.Overflow, parseUnsigned(u2, "4", 16));
16271627
1628 // parseUnsigned does not expect a sign1628 // parseUnsigned does not expect a sign
1629 std.testing.expectError(error.InvalidCharacter, parseUnsigned(u8, "+0", 10));1629 try std.testing.expectError(error.InvalidCharacter, parseUnsigned(u8, "+0", 10));
1630 std.testing.expectError(error.InvalidCharacter, parseUnsigned(u8, "-0", 10));1630 try std.testing.expectError(error.InvalidCharacter, parseUnsigned(u8, "-0", 10));
16311631
1632 // test empty string error1632 // test empty string error
1633 std.testing.expectError(error.InvalidCharacter, parseUnsigned(u8, "", 10));1633 try std.testing.expectError(error.InvalidCharacter, parseUnsigned(u8, "", 10));
1634}1634}
16351635
1636pub const parseFloat = @import("fmt/parse_float.zig").parseFloat;1636pub const parseFloat = @import("fmt/parse_float.zig").parseFloat;
...@@ -1709,21 +1709,21 @@ test "bufPrintInt" {...@@ -1709,21 +1709,21 @@ test "bufPrintInt" {
1709 var buffer: [100]u8 = undefined;1709 var buffer: [100]u8 = undefined;
1710 const buf = buffer[0..];1710 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{}));1714 try 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{}));1715 try 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{}));1716 try 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{}));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 }));1721 try 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 }));1722 try 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 }));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 }));1725 try 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 }));1726 try std.testing.expectEqualSlices(u8, "-42", bufPrintIntToSlice(buf, @as(i32, -42), 10, false, FormatOptions{ .width = 3 }));
1727}1727}
17281728
1729pub fn bufPrintIntToSlice(buf: []u8, value: anytype, base: u8, uppercase: bool, options: FormatOptions) []u8 {1729pub 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,...@@ -1741,8 +1741,8 @@ pub fn comptimePrint(comptime fmt: []const u8, args: anytype) *const [count(fmt,
17411741
1742test "comptimePrint" {1742test "comptimePrint" {
1743 @setEvalBranchQuota(2000);1743 @setEvalBranchQuota(2000);
1744 std.testing.expectEqual(*const [3:0]u8, @TypeOf(comptime comptimePrint("{}", .{100})));1744 try std.testing.expectEqual(*const [3:0]u8, @TypeOf(comptime comptimePrint("{}", .{100})));
1745 std.testing.expectEqualSlices(u8, "100", comptime comptimePrint("{}", .{100}));1745 try std.testing.expectEqualSlices(u8, "100", comptime comptimePrint("{}", .{100}));
1746}1746}
17471747
1748test "parse u64 digit too big" {1748test "parse u64 digit too big" {
...@@ -1755,7 +1755,7 @@ test "parse u64 digit too big" {...@@ -1755,7 +1755,7 @@ test "parse u64 digit too big" {
17551755
1756test "parse unsigned comptime" {1756test "parse unsigned comptime" {
1757 comptime {1757 comptime {
1758 std.testing.expect((try parseUnsigned(usize, "2", 10)) == 2);1758 try std.testing.expect((try parseUnsigned(usize, "2", 10)) == 2);
1759 }1759 }
1760}1760}
17611761
...@@ -1852,15 +1852,15 @@ test "buffer" {...@@ -1852,15 +1852,15 @@ test "buffer" {
1852 var buf1: [32]u8 = undefined;1852 var buf1: [32]u8 = undefined;
1853 var fbs = std.io.fixedBufferStream(&buf1);1853 var fbs = std.io.fixedBufferStream(&buf1);
1854 try formatType(1234, "", FormatOptions{}, fbs.writer(), default_max_depth);1854 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
1857 fbs.reset();1857 fbs.reset();
1858 try formatType('a', "c", FormatOptions{}, fbs.writer(), default_max_depth);1858 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
1861 fbs.reset();1861 fbs.reset();
1862 try formatType(0b1100, "b", FormatOptions{}, fbs.writer(), default_max_depth);1862 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"));
1864 }1864 }
1865}1865}
18661866
...@@ -2187,10 +2187,10 @@ test "union" {...@@ -2187,10 +2187,10 @@ test "union" {
21872187
2188 var buf: [100]u8 = undefined;2188 var buf: [100]u8 = undefined;
2189 const uu_result = try bufPrint(buf[0..], "{}", .{uu_inst});2189 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
2192 const eu_result = try bufPrint(buf[0..], "{}", .{eu_inst});2192 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@"));
2194}2194}
21952195
2196test "enum" {2196test "enum" {
...@@ -2273,9 +2273,9 @@ test "hexToBytes" {...@@ -2273,9 +2273,9 @@ test "hexToBytes" {
2273 try expectFmt("90" ** 32, "{s}", .{fmtSliceHexUpper(try hexToBytes(&buf, "90" ** 32))});2273 try expectFmt("90" ** 32, "{s}", .{fmtSliceHexUpper(try hexToBytes(&buf, "90" ** 32))});
2274 try expectFmt("ABCD", "{s}", .{fmtSliceHexUpper(try hexToBytes(&buf, "ABCD"))});2274 try expectFmt("ABCD", "{s}", .{fmtSliceHexUpper(try hexToBytes(&buf, "ABCD"))});
2275 try expectFmt("", "{s}", .{fmtSliceHexUpper(try hexToBytes(&buf, ""))});2275 try expectFmt("", "{s}", .{fmtSliceHexUpper(try hexToBytes(&buf, ""))});
2276 std.testing.expectError(error.InvalidCharacter, hexToBytes(&buf, "012Z"));2276 try std.testing.expectError(error.InvalidCharacter, hexToBytes(&buf, "012Z"));
2277 std.testing.expectError(error.InvalidLength, hexToBytes(&buf, "AAA"));2277 try std.testing.expectError(error.InvalidLength, hexToBytes(&buf, "AAA"));
2278 std.testing.expectError(error.NoSpaceLeft, hexToBytes(buf[0..1], "ABAB"));2278 try std.testing.expectError(error.NoSpaceLeft, hexToBytes(buf[0..1], "ABAB"));
2279}2279}
22802280
2281test "formatIntValue with comptime_int" {2281test "formatIntValue with comptime_int" {
...@@ -2284,7 +2284,7 @@ test "formatIntValue with comptime_int" {...@@ -2284,7 +2284,7 @@ test "formatIntValue with comptime_int" {
2284 var buf: [20]u8 = undefined;2284 var buf: [20]u8 = undefined;
2285 var fbs = std.io.fixedBufferStream(&buf);2285 var fbs = std.io.fixedBufferStream(&buf);
2286 try formatIntValue(value, "", FormatOptions{}, fbs.writer());2286 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"));
2288}2288}
22892289
2290test "formatFloatValue with comptime_float" {2290test "formatFloatValue with comptime_float" {
...@@ -2293,7 +2293,7 @@ test "formatFloatValue with comptime_float" {...@@ -2293,7 +2293,7 @@ test "formatFloatValue with comptime_float" {
2293 var buf: [20]u8 = undefined;2293 var buf: [20]u8 = undefined;
2294 var fbs = std.io.fixedBufferStream(&buf);2294 var fbs = std.io.fixedBufferStream(&buf);
2295 try formatFloatValue(value, "", FormatOptions{}, fbs.writer());2295 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
2298 try expectFmt("1.0e+00", "{}", .{value});2298 try expectFmt("1.0e+00", "{}", .{value});
2299 try expectFmt("1.0e+00", "{}", .{1.0});2299 try expectFmt("1.0e+00", "{}", .{1.0});
...@@ -2349,19 +2349,19 @@ test "formatType max_depth" {...@@ -2349,19 +2349,19 @@ test "formatType max_depth" {
2349 var buf: [1000]u8 = undefined;2349 var buf: [1000]u8 = undefined;
2350 var fbs = std.io.fixedBufferStream(&buf);2350 var fbs = std.io.fixedBufferStream(&buf);
2351 try formatType(inst, "", FormatOptions{}, fbs.writer(), 0);2351 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
2354 fbs.reset();2354 fbs.reset();
2355 try formatType(inst, "", FormatOptions{}, fbs.writer(), 1);2355 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
2358 fbs.reset();2358 fbs.reset();
2359 try formatType(inst, "", FormatOptions{}, fbs.writer(), 2);2359 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
2362 fbs.reset();2362 fbs.reset();
2363 try formatType(inst, "", FormatOptions{}, fbs.writer(), 3);2363 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) }"));
2365}2365}
23662366
2367test "positional" {2367test "positional" {
lib/std/fmt/parse_float.zig+29-29
...@@ -376,44 +376,44 @@ test "fmt.parseFloat" {...@@ -376,44 +376,44 @@ test "fmt.parseFloat" {
376 inline for ([_]type{ f16, f32, f64, f128 }) |T| {376 inline for ([_]type{ f16, f32, f64, f128 }) |T| {
377 const Z = std.meta.Int(.unsigned, @typeInfo(T).Float.bits);377 const Z = std.meta.Int(.unsigned, @typeInfo(T).Float.bits);
378378
379 testing.expectError(error.InvalidCharacter, parseFloat(T, ""));379 try testing.expectError(error.InvalidCharacter, parseFloat(T, ""));
380 testing.expectError(error.InvalidCharacter, parseFloat(T, " 1"));380 try testing.expectError(error.InvalidCharacter, parseFloat(T, " 1"));
381 testing.expectError(error.InvalidCharacter, parseFloat(T, "1abc"));381 try testing.expectError(error.InvalidCharacter, parseFloat(T, "1abc"));
382 testing.expectError(error.InvalidCharacter, parseFloat(T, "+"));382 try testing.expectError(error.InvalidCharacter, parseFloat(T, "+"));
383 testing.expectError(error.InvalidCharacter, parseFloat(T, "-"));383 try testing.expectError(error.InvalidCharacter, parseFloat(T, "-"));
384384
385 expectEqual(try parseFloat(T, "0"), 0.0);385 try expectEqual(try parseFloat(T, "0"), 0.0);
386 expectEqual(try parseFloat(T, "0"), 0.0);386 try expectEqual(try parseFloat(T, "0"), 0.0);
387 expectEqual(try parseFloat(T, "+0"), 0.0);387 try expectEqual(try parseFloat(T, "+0"), 0.0);
388 expectEqual(try parseFloat(T, "-0"), 0.0);388 try expectEqual(try parseFloat(T, "-0"), 0.0);
389389
390 expectEqual(try parseFloat(T, "0e0"), 0);390 try expectEqual(try parseFloat(T, "0e0"), 0);
391 expectEqual(try parseFloat(T, "2e3"), 2000.0);391 try expectEqual(try parseFloat(T, "2e3"), 2000.0);
392 expectEqual(try parseFloat(T, "1e0"), 1.0);392 try expectEqual(try parseFloat(T, "1e0"), 1.0);
393 expectEqual(try parseFloat(T, "-2e3"), -2000.0);393 try expectEqual(try parseFloat(T, "-2e3"), -2000.0);
394 expectEqual(try parseFloat(T, "-1e0"), -1.0);394 try expectEqual(try parseFloat(T, "-1e0"), -1.0);
395 expectEqual(try parseFloat(T, "1.234e3"), 1234);395 try expectEqual(try parseFloat(T, "1.234e3"), 1234);
396396
397 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 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);400 try expectEqual(try parseFloat(T, "1e-700"), 0);
401 expectEqual(try parseFloat(T, "1e+700"), std.math.inf(T));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)));403 try expectEqual(@bitCast(Z, try parseFloat(T, "nAn")), @bitCast(Z, std.math.nan(T)));
404 expectEqual(try parseFloat(T, "inF"), std.math.inf(T));404 try expectEqual(try parseFloat(T, "inF"), std.math.inf(T));
405 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
409 if (T != f16) {409 if (T != f16) {
410 expect(approxEqAbs(T, try parseFloat(T, "1e-2"), 0.01, epsilon));410 try expect(approxEqAbs(T, try parseFloat(T, "1e-2"), 0.01, epsilon));
411 expect(approxEqAbs(T, try parseFloat(T, "1234e-2"), 12.34, 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));413 try 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));414 try 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));415 try 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));416 try expect(approxEqAbs(T, try parseFloat(T, "2.71828182845904523536"), @as(T, 2.718281828459045), epsilon));
417 }417 }
418 }418 }
419}419}
lib/std/fmt/parse_hex_float.zig+13-13
...@@ -247,17 +247,17 @@ pub fn parseHexFloat(comptime T: type, s: []const u8) !T {...@@ -247,17 +247,17 @@ pub fn parseHexFloat(comptime T: type, s: []const u8) !T {
247}247}
248248
249test "special" {249test "special" {
250 testing.expect(math.isNan(try parseHexFloat(f32, "nAn")));250 try testing.expect(math.isNan(try parseHexFloat(f32, "nAn")));
251 testing.expect(math.isPositiveInf(try parseHexFloat(f32, "iNf")));251 try testing.expect(math.isPositiveInf(try parseHexFloat(f32, "iNf")));
252 testing.expect(math.isPositiveInf(try parseHexFloat(f32, "+Inf")));252 try testing.expect(math.isPositiveInf(try parseHexFloat(f32, "+Inf")));
253 testing.expect(math.isNegativeInf(try parseHexFloat(f32, "-iNf")));253 try testing.expect(math.isNegativeInf(try parseHexFloat(f32, "-iNf")));
254}254}
255test "zero" {255test "zero" {
256 testing.expectEqual(@as(f32, 0.0), try parseHexFloat(f32, "0x0"));256 try testing.expectEqual(@as(f32, 0.0), try parseHexFloat(f32, "0x0"));
257 testing.expectEqual(@as(f32, 0.0), try parseHexFloat(f32, "-0x0"));257 try testing.expectEqual(@as(f32, 0.0), try parseHexFloat(f32, "-0x0"));
258 testing.expectEqual(@as(f32, 0.0), try parseHexFloat(f32, "0x0p42"));258 try testing.expectEqual(@as(f32, 0.0), try parseHexFloat(f32, "0x0p42"));
259 testing.expectEqual(@as(f32, 0.0), try parseHexFloat(f32, "-0x0.00000p42"));259 try testing.expectEqual(@as(f32, 0.0), try parseHexFloat(f32, "-0x0.00000p42"));
260 testing.expectEqual(@as(f32, 0.0), try parseHexFloat(f32, "0x0.00000p666"));260 try testing.expectEqual(@as(f32, 0.0), try parseHexFloat(f32, "0x0.00000p666"));
261}261}
262262
263test "f16" {263test "f16" {
...@@ -279,7 +279,7 @@ test "f16" {...@@ -279,7 +279,7 @@ test "f16" {
279 };279 };
280280
281 for (cases) |case| {281 for (cases) |case| {
282 testing.expectEqual(case.v, try parseHexFloat(f16, case.s));282 try testing.expectEqual(case.v, try parseHexFloat(f16, case.s));
283 }283 }
284}284}
285test "f32" {285test "f32" {
...@@ -303,7 +303,7 @@ test "f32" {...@@ -303,7 +303,7 @@ test "f32" {
303 };303 };
304304
305 for (cases) |case| {305 for (cases) |case| {
306 testing.expectEqual(case.v, try parseHexFloat(f32, case.s));306 try testing.expectEqual(case.v, try parseHexFloat(f32, case.s));
307 }307 }
308}308}
309test "f64" {309test "f64" {
...@@ -325,7 +325,7 @@ test "f64" {...@@ -325,7 +325,7 @@ test "f64" {
325 };325 };
326326
327 for (cases) |case| {327 for (cases) |case| {
328 testing.expectEqual(case.v, try parseHexFloat(f64, case.s));328 try testing.expectEqual(case.v, try parseHexFloat(f64, case.s));
329 }329 }
330}330}
331test "f128" {331test "f128" {
...@@ -347,6 +347,6 @@ test "f128" {...@@ -347,6 +347,6 @@ test "f128" {
347 };347 };
348348
349 for (cases) |case| {349 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)));
351 }351 }
352}352}
lib/std/fs/path.zig+205-205
...@@ -96,72 +96,72 @@ pub fn joinZ(allocator: *Allocator, paths: []const []const u8) ![:0]u8 {...@@ -96,72 +96,72 @@ pub fn joinZ(allocator: *Allocator, paths: []const []const u8) ![:0]u8 {
96 return out[0 .. out.len - 1 :0];96 return out[0 .. out.len - 1 :0];
97}97}
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 {
100 const windowsIsSep = struct {100 const windowsIsSep = struct {
101 fn isSep(byte: u8) bool {101 fn isSep(byte: u8) bool {
102 return byte == '/' or byte == '\\';102 return byte == '/' or byte == '\\';
103 }103 }
104 }.isSep;104 }.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);
106 defer testing.allocator.free(actual);106 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);
108}108}
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 {
111 const posixIsSep = struct {111 const posixIsSep = struct {
112 fn isSep(byte: u8) bool {112 fn isSep(byte: u8) bool {
113 return byte == '/';113 return byte == '/';
114 }114 }
115 }.isSep;115 }.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);
117 defer testing.allocator.free(actual);117 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);
119}119}
120120
121test "join" {121test "join" {
122 {122 {
123 const actual: []u8 = try join(testing.allocator, &[_][]const u8{});123 const actual: []u8 = try join(testing.allocator, &[_][]const u8{});
124 defer testing.allocator.free(actual);124 defer testing.allocator.free(actual);
125 testing.expectEqualSlices(u8, "", actual);125 try testing.expectEqualSlices(u8, "", actual);
126 }126 }
127 {127 {
128 const actual: [:0]u8 = try joinZ(testing.allocator, &[_][]const u8{});128 const actual: [:0]u8 = try joinZ(testing.allocator, &[_][]const u8{});
129 defer testing.allocator.free(actual);129 defer testing.allocator.free(actual);
130 testing.expectEqualSlices(u8, "", actual);130 try testing.expectEqualSlices(u8, "", actual);
131 }131 }
132 for (&[_]bool{ false, true }) |zero| {132 for (&[_]bool{ false, true }) |zero| {
133 testJoinMaybeZWindows(&[_][]const u8{}, "", zero);133 try testJoinMaybeZWindows(&[_][]const u8{}, "", zero);
134 testJoinMaybeZWindows(&[_][]const u8{ "c:\\a\\b", "c" }, "c:\\a\\b\\c", zero);134 try 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);135 try 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);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);138 try 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);139 try testJoinMaybeZWindows(&[_][]const u8{ "c:\\a\\", "b\\", "c" }, "c:\\a\\b\\c", zero);
140140
141 testJoinMaybeZWindows(141 try testJoinMaybeZWindows(
142 &[_][]const u8{ "c:\\home\\andy\\dev\\zig\\build\\lib\\zig\\std", "io.zig" },142 &[_][]const u8{ "c:\\home\\andy\\dev\\zig\\build\\lib\\zig\\std", "io.zig" },
143 "c:\\home\\andy\\dev\\zig\\build\\lib\\zig\\std\\io.zig",143 "c:\\home\\andy\\dev\\zig\\build\\lib\\zig\\std\\io.zig",
144 zero,144 zero,
145 );145 );
146146
147 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 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);150 try testJoinMaybeZPosix(&[_][]const u8{}, "", zero);
151 testJoinMaybeZPosix(&[_][]const u8{ "/a/b", "c" }, "/a/b/c", zero);151 try testJoinMaybeZPosix(&[_][]const u8{ "/a/b", "c" }, "/a/b/c", zero);
152 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);154 try testJoinMaybeZPosix(&[_][]const u8{ "/", "a", "b/", "c" }, "/a/b/c", zero);
155 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(
158 &[_][]const u8{ "/home/andy/dev/zig/build/lib/zig/std", "io.zig" },158 &[_][]const u8{ "/home/andy/dev/zig/build/lib/zig/std", "io.zig" },
159 "/home/andy/dev/zig/build/lib/zig/std/io.zig",159 "/home/andy/dev/zig/build/lib/zig/std/io.zig",
160 zero,160 zero,
161 );161 );
162162
163 testJoinMaybeZPosix(&[_][]const u8{ "a", "/c" }, "a/c", zero);163 try testJoinMaybeZPosix(&[_][]const u8{ "a", "/c" }, "a/c", zero);
164 testJoinMaybeZPosix(&[_][]const u8{ "a/", "/c" }, "a/c", zero);164 try testJoinMaybeZPosix(&[_][]const u8{ "a/", "/c" }, "a/c", zero);
165 }165 }
166}166}
167167
...@@ -235,42 +235,42 @@ pub fn isAbsolutePosixZ(path_c: [*:0]const u8) bool {...@@ -235,42 +235,42 @@ pub fn isAbsolutePosixZ(path_c: [*:0]const u8) bool {
235}235}
236236
237test "isAbsoluteWindows" {237test "isAbsoluteWindows" {
238 testIsAbsoluteWindows("", false);238 try testIsAbsoluteWindows("", false);
239 testIsAbsoluteWindows("/", true);239 try testIsAbsoluteWindows("/", true);
240 testIsAbsoluteWindows("//", true);240 try testIsAbsoluteWindows("//", true);
241 testIsAbsoluteWindows("//server", true);241 try testIsAbsoluteWindows("//server", true);
242 testIsAbsoluteWindows("//server/file", true);242 try testIsAbsoluteWindows("//server/file", true);
243 testIsAbsoluteWindows("\\\\server\\file", true);243 try testIsAbsoluteWindows("\\\\server\\file", true);
244 testIsAbsoluteWindows("\\\\server", true);244 try testIsAbsoluteWindows("\\\\server", true);
245 testIsAbsoluteWindows("\\\\", true);245 try testIsAbsoluteWindows("\\\\", true);
246 testIsAbsoluteWindows("c", false);246 try testIsAbsoluteWindows("c", false);
247 testIsAbsoluteWindows("c:", false);247 try testIsAbsoluteWindows("c:", false);
248 testIsAbsoluteWindows("c:\\", true);248 try testIsAbsoluteWindows("c:\\", true);
249 testIsAbsoluteWindows("c:/", true);249 try testIsAbsoluteWindows("c:/", true);
250 testIsAbsoluteWindows("c://", true);250 try testIsAbsoluteWindows("c://", true);
251 testIsAbsoluteWindows("C:/Users/", true);251 try testIsAbsoluteWindows("C:/Users/", true);
252 testIsAbsoluteWindows("C:\\Users\\", true);252 try testIsAbsoluteWindows("C:\\Users\\", true);
253 testIsAbsoluteWindows("C:cwd/another", false);253 try testIsAbsoluteWindows("C:cwd/another", false);
254 testIsAbsoluteWindows("C:cwd\\another", false);254 try testIsAbsoluteWindows("C:cwd\\another", false);
255 testIsAbsoluteWindows("directory/directory", false);255 try testIsAbsoluteWindows("directory/directory", false);
256 testIsAbsoluteWindows("directory\\directory", false);256 try testIsAbsoluteWindows("directory\\directory", false);
257 testIsAbsoluteWindows("/usr/local", true);257 try testIsAbsoluteWindows("/usr/local", true);
258}258}
259259
260test "isAbsolutePosix" {260test "isAbsolutePosix" {
261 testIsAbsolutePosix("", false);261 try testIsAbsolutePosix("", false);
262 testIsAbsolutePosix("/home/foo", true);262 try testIsAbsolutePosix("/home/foo", true);
263 testIsAbsolutePosix("/home/foo/..", true);263 try testIsAbsolutePosix("/home/foo/..", true);
264 testIsAbsolutePosix("bar/", false);264 try testIsAbsolutePosix("bar/", false);
265 testIsAbsolutePosix("./baz", false);265 try testIsAbsolutePosix("./baz", false);
266}266}
267267
268fn testIsAbsoluteWindows(path: []const u8, expected_result: bool) void {268fn testIsAbsoluteWindows(path: []const u8, expected_result: bool) !void {
269 testing.expectEqual(expected_result, isAbsoluteWindows(path));269 try testing.expectEqual(expected_result, isAbsoluteWindows(path));
270}270}
271271
272fn testIsAbsolutePosix(path: []const u8, expected_result: bool) void {272fn testIsAbsolutePosix(path: []const u8, expected_result: bool) !void {
273 testing.expectEqual(expected_result, isAbsolutePosix(path));273 try testing.expectEqual(expected_result, isAbsolutePosix(path));
274}274}
275275
276pub const WindowsPath = struct {276pub const WindowsPath = struct {
...@@ -334,33 +334,33 @@ pub fn windowsParsePath(path: []const u8) WindowsPath {...@@ -334,33 +334,33 @@ pub fn windowsParsePath(path: []const u8) WindowsPath {
334test "windowsParsePath" {334test "windowsParsePath" {
335 {335 {
336 const parsed = windowsParsePath("//a/b");336 const parsed = windowsParsePath("//a/b");
337 testing.expect(parsed.is_abs);337 try testing.expect(parsed.is_abs);
338 testing.expect(parsed.kind == WindowsPath.Kind.NetworkShare);338 try testing.expect(parsed.kind == WindowsPath.Kind.NetworkShare);
339 testing.expect(mem.eql(u8, parsed.disk_designator, "//a/b"));339 try testing.expect(mem.eql(u8, parsed.disk_designator, "//a/b"));
340 }340 }
341 {341 {
342 const parsed = windowsParsePath("\\\\a\\b");342 const parsed = windowsParsePath("\\\\a\\b");
343 testing.expect(parsed.is_abs);343 try testing.expect(parsed.is_abs);
344 testing.expect(parsed.kind == WindowsPath.Kind.NetworkShare);344 try testing.expect(parsed.kind == WindowsPath.Kind.NetworkShare);
345 testing.expect(mem.eql(u8, parsed.disk_designator, "\\\\a\\b"));345 try testing.expect(mem.eql(u8, parsed.disk_designator, "\\\\a\\b"));
346 }346 }
347 {347 {
348 const parsed = windowsParsePath("\\\\a\\");348 const parsed = windowsParsePath("\\\\a\\");
349 testing.expect(!parsed.is_abs);349 try testing.expect(!parsed.is_abs);
350 testing.expect(parsed.kind == WindowsPath.Kind.None);350 try testing.expect(parsed.kind == WindowsPath.Kind.None);
351 testing.expect(mem.eql(u8, parsed.disk_designator, ""));351 try testing.expect(mem.eql(u8, parsed.disk_designator, ""));
352 }352 }
353 {353 {
354 const parsed = windowsParsePath("/usr/local");354 const parsed = windowsParsePath("/usr/local");
355 testing.expect(parsed.is_abs);355 try testing.expect(parsed.is_abs);
356 testing.expect(parsed.kind == WindowsPath.Kind.None);356 try testing.expect(parsed.kind == WindowsPath.Kind.None);
357 testing.expect(mem.eql(u8, parsed.disk_designator, ""));357 try testing.expect(mem.eql(u8, parsed.disk_designator, ""));
358 }358 }
359 {359 {
360 const parsed = windowsParsePath("c:../");360 const parsed = windowsParsePath("c:../");
361 testing.expect(!parsed.is_abs);361 try testing.expect(!parsed.is_abs);
362 testing.expect(parsed.kind == WindowsPath.Kind.Drive);362 try testing.expect(parsed.kind == WindowsPath.Kind.Drive);
363 testing.expect(mem.eql(u8, parsed.disk_designator, "c:"));363 try testing.expect(mem.eql(u8, parsed.disk_designator, "c:"));
364 }364 }
365}365}
366366
...@@ -772,13 +772,13 @@ test "resolvePosix" {...@@ -772,13 +772,13 @@ test "resolvePosix" {
772fn testResolveWindows(paths: []const []const u8, expected: []const u8) !void {772fn testResolveWindows(paths: []const []const u8, expected: []const u8) !void {
773 const actual = try resolveWindows(testing.allocator, paths);773 const actual = try resolveWindows(testing.allocator, paths);
774 defer testing.allocator.free(actual);774 defer testing.allocator.free(actual);
775 return testing.expect(mem.eql(u8, actual, expected));775 try testing.expect(mem.eql(u8, actual, expected));
776}776}
777777
778fn testResolvePosix(paths: []const []const u8, expected: []const u8) !void {778fn testResolvePosix(paths: []const []const u8, expected: []const u8) !void {
779 const actual = try resolvePosix(testing.allocator, paths);779 const actual = try resolvePosix(testing.allocator, paths);
780 defer testing.allocator.free(actual);780 defer testing.allocator.free(actual);
781 return testing.expect(mem.eql(u8, actual, expected));781 try testing.expect(mem.eql(u8, actual, expected));
782}782}
783783
784/// Strip the last component from a file path.784/// Strip the last component from a file path.
...@@ -856,68 +856,68 @@ pub fn dirnamePosix(path: []const u8) ?[]const u8 {...@@ -856,68 +856,68 @@ pub fn dirnamePosix(path: []const u8) ?[]const u8 {
856}856}
857857
858test "dirnamePosix" {858test "dirnamePosix" {
859 testDirnamePosix("/a/b/c", "/a/b");859 try testDirnamePosix("/a/b/c", "/a/b");
860 testDirnamePosix("/a/b/c///", "/a/b");860 try testDirnamePosix("/a/b/c///", "/a/b");
861 testDirnamePosix("/a", "/");861 try testDirnamePosix("/a", "/");
862 testDirnamePosix("/", null);862 try testDirnamePosix("/", null);
863 testDirnamePosix("//", null);863 try testDirnamePosix("//", null);
864 testDirnamePosix("///", null);864 try testDirnamePosix("///", null);
865 testDirnamePosix("////", null);865 try testDirnamePosix("////", null);
866 testDirnamePosix("", null);866 try testDirnamePosix("", null);
867 testDirnamePosix("a", null);867 try testDirnamePosix("a", null);
868 testDirnamePosix("a/", null);868 try testDirnamePosix("a/", null);
869 testDirnamePosix("a//", null);869 try testDirnamePosix("a//", null);
870}870}
871871
872test "dirnameWindows" {872test "dirnameWindows" {
873 testDirnameWindows("c:\\", null);873 try testDirnameWindows("c:\\", null);
874 testDirnameWindows("c:\\foo", "c:\\");874 try testDirnameWindows("c:\\foo", "c:\\");
875 testDirnameWindows("c:\\foo\\", "c:\\");875 try testDirnameWindows("c:\\foo\\", "c:\\");
876 testDirnameWindows("c:\\foo\\bar", "c:\\foo");876 try testDirnameWindows("c:\\foo\\bar", "c:\\foo");
877 testDirnameWindows("c:\\foo\\bar\\", "c:\\foo");877 try testDirnameWindows("c:\\foo\\bar\\", "c:\\foo");
878 testDirnameWindows("c:\\foo\\bar\\baz", "c:\\foo\\bar");878 try testDirnameWindows("c:\\foo\\bar\\baz", "c:\\foo\\bar");
879 testDirnameWindows("\\", null);879 try testDirnameWindows("\\", null);
880 testDirnameWindows("\\foo", "\\");880 try testDirnameWindows("\\foo", "\\");
881 testDirnameWindows("\\foo\\", "\\");881 try testDirnameWindows("\\foo\\", "\\");
882 testDirnameWindows("\\foo\\bar", "\\foo");882 try testDirnameWindows("\\foo\\bar", "\\foo");
883 testDirnameWindows("\\foo\\bar\\", "\\foo");883 try testDirnameWindows("\\foo\\bar\\", "\\foo");
884 testDirnameWindows("\\foo\\bar\\baz", "\\foo\\bar");884 try testDirnameWindows("\\foo\\bar\\baz", "\\foo\\bar");
885 testDirnameWindows("c:", null);885 try testDirnameWindows("c:", null);
886 testDirnameWindows("c:foo", null);886 try testDirnameWindows("c:foo", null);
887 testDirnameWindows("c:foo\\", null);887 try testDirnameWindows("c:foo\\", null);
888 testDirnameWindows("c:foo\\bar", "c:foo");888 try testDirnameWindows("c:foo\\bar", "c:foo");
889 testDirnameWindows("c:foo\\bar\\", "c:foo");889 try testDirnameWindows("c:foo\\bar\\", "c:foo");
890 testDirnameWindows("c:foo\\bar\\baz", "c:foo\\bar");890 try testDirnameWindows("c:foo\\bar\\baz", "c:foo\\bar");
891 testDirnameWindows("file:stream", null);891 try testDirnameWindows("file:stream", null);
892 testDirnameWindows("dir\\file:stream", "dir");892 try testDirnameWindows("dir\\file:stream", "dir");
893 testDirnameWindows("\\\\unc\\share", null);893 try testDirnameWindows("\\\\unc\\share", null);
894 testDirnameWindows("\\\\unc\\share\\foo", "\\\\unc\\share\\");894 try testDirnameWindows("\\\\unc\\share\\foo", "\\\\unc\\share\\");
895 testDirnameWindows("\\\\unc\\share\\foo\\", "\\\\unc\\share\\");895 try testDirnameWindows("\\\\unc\\share\\foo\\", "\\\\unc\\share\\");
896 testDirnameWindows("\\\\unc\\share\\foo\\bar", "\\\\unc\\share\\foo");896 try testDirnameWindows("\\\\unc\\share\\foo\\bar", "\\\\unc\\share\\foo");
897 testDirnameWindows("\\\\unc\\share\\foo\\bar\\", "\\\\unc\\share\\foo");897 try testDirnameWindows("\\\\unc\\share\\foo\\bar\\", "\\\\unc\\share\\foo");
898 testDirnameWindows("\\\\unc\\share\\foo\\bar\\baz", "\\\\unc\\share\\foo\\bar");898 try testDirnameWindows("\\\\unc\\share\\foo\\bar\\baz", "\\\\unc\\share\\foo\\bar");
899 testDirnameWindows("/a/b/", "/a");899 try testDirnameWindows("/a/b/", "/a");
900 testDirnameWindows("/a/b", "/a");900 try testDirnameWindows("/a/b", "/a");
901 testDirnameWindows("/a", "/");901 try testDirnameWindows("/a", "/");
902 testDirnameWindows("", null);902 try testDirnameWindows("", null);
903 testDirnameWindows("/", null);903 try testDirnameWindows("/", null);
904 testDirnameWindows("////", null);904 try testDirnameWindows("////", null);
905 testDirnameWindows("foo", null);905 try testDirnameWindows("foo", null);
906}906}
907907
908fn testDirnamePosix(input: []const u8, expected_output: ?[]const u8) void {908fn testDirnamePosix(input: []const u8, expected_output: ?[]const u8) !void {
909 if (dirnamePosix(input)) |output| {909 if (dirnamePosix(input)) |output| {
910 testing.expect(mem.eql(u8, output, expected_output.?));910 try testing.expect(mem.eql(u8, output, expected_output.?));
911 } else {911 } else {
912 testing.expect(expected_output == null);912 try testing.expect(expected_output == null);
913 }913 }
914}914}
915915
916fn testDirnameWindows(input: []const u8, expected_output: ?[]const u8) void {916fn testDirnameWindows(input: []const u8, expected_output: ?[]const u8) !void {
917 if (dirnameWindows(input)) |output| {917 if (dirnameWindows(input)) |output| {
918 testing.expect(mem.eql(u8, output, expected_output.?));918 try testing.expect(mem.eql(u8, output, expected_output.?));
919 } else {919 } else {
920 testing.expect(expected_output == null);920 try testing.expect(expected_output == null);
921 }921 }
922}922}
923923
...@@ -983,54 +983,54 @@ pub fn basenameWindows(path: []const u8) []const u8 {...@@ -983,54 +983,54 @@ pub fn basenameWindows(path: []const u8) []const u8 {
983}983}
984984
985test "basename" {985test "basename" {
986 testBasename("", "");986 try testBasename("", "");
987 testBasename("/", "");987 try testBasename("/", "");
988 testBasename("/dir/basename.ext", "basename.ext");988 try testBasename("/dir/basename.ext", "basename.ext");
989 testBasename("/basename.ext", "basename.ext");989 try testBasename("/basename.ext", "basename.ext");
990 testBasename("basename.ext", "basename.ext");990 try testBasename("basename.ext", "basename.ext");
991 testBasename("basename.ext/", "basename.ext");991 try testBasename("basename.ext/", "basename.ext");
992 testBasename("basename.ext//", "basename.ext");992 try testBasename("basename.ext//", "basename.ext");
993 testBasename("/aaa/bbb", "bbb");993 try testBasename("/aaa/bbb", "bbb");
994 testBasename("/aaa/", "aaa");994 try testBasename("/aaa/", "aaa");
995 testBasename("/aaa/b", "b");995 try testBasename("/aaa/b", "b");
996 testBasename("/a/b", "b");996 try testBasename("/a/b", "b");
997 testBasename("//a", "a");997 try testBasename("//a", "a");
998998
999 testBasenamePosix("\\dir\\basename.ext", "\\dir\\basename.ext");999 try testBasenamePosix("\\dir\\basename.ext", "\\dir\\basename.ext");
1000 testBasenamePosix("\\basename.ext", "\\basename.ext");1000 try testBasenamePosix("\\basename.ext", "\\basename.ext");
1001 testBasenamePosix("basename.ext", "basename.ext");1001 try testBasenamePosix("basename.ext", "basename.ext");
1002 testBasenamePosix("basename.ext\\", "basename.ext\\");1002 try testBasenamePosix("basename.ext\\", "basename.ext\\");
1003 testBasenamePosix("basename.ext\\\\", "basename.ext\\\\");1003 try testBasenamePosix("basename.ext\\\\", "basename.ext\\\\");
1004 testBasenamePosix("foo", "foo");1004 try testBasenamePosix("foo", "foo");
10051005
1006 testBasenameWindows("\\dir\\basename.ext", "basename.ext");1006 try testBasenameWindows("\\dir\\basename.ext", "basename.ext");
1007 testBasenameWindows("\\basename.ext", "basename.ext");1007 try testBasenameWindows("\\basename.ext", "basename.ext");
1008 testBasenameWindows("basename.ext", "basename.ext");1008 try testBasenameWindows("basename.ext", "basename.ext");
1009 testBasenameWindows("basename.ext\\", "basename.ext");1009 try testBasenameWindows("basename.ext\\", "basename.ext");
1010 testBasenameWindows("basename.ext\\\\", "basename.ext");1010 try testBasenameWindows("basename.ext\\\\", "basename.ext");
1011 testBasenameWindows("foo", "foo");1011 try testBasenameWindows("foo", "foo");
1012 testBasenameWindows("C:", "");1012 try testBasenameWindows("C:", "");
1013 testBasenameWindows("C:.", ".");1013 try testBasenameWindows("C:.", ".");
1014 testBasenameWindows("C:\\", "");1014 try testBasenameWindows("C:\\", "");
1015 testBasenameWindows("C:\\dir\\base.ext", "base.ext");1015 try testBasenameWindows("C:\\dir\\base.ext", "base.ext");
1016 testBasenameWindows("C:\\basename.ext", "basename.ext");1016 try testBasenameWindows("C:\\basename.ext", "basename.ext");
1017 testBasenameWindows("C:basename.ext", "basename.ext");1017 try testBasenameWindows("C:basename.ext", "basename.ext");
1018 testBasenameWindows("C:basename.ext\\", "basename.ext");1018 try testBasenameWindows("C:basename.ext\\", "basename.ext");
1019 testBasenameWindows("C:basename.ext\\\\", "basename.ext");1019 try testBasenameWindows("C:basename.ext\\\\", "basename.ext");
1020 testBasenameWindows("C:foo", "foo");1020 try testBasenameWindows("C:foo", "foo");
1021 testBasenameWindows("file:stream", "file:stream");1021 try testBasenameWindows("file:stream", "file:stream");
1022}1022}
10231023
1024fn testBasename(input: []const u8, expected_output: []const u8) void {1024fn testBasename(input: []const u8, expected_output: []const u8) !void {
1025 testing.expectEqualSlices(u8, expected_output, basename(input));1025 try testing.expectEqualSlices(u8, expected_output, basename(input));
1026}1026}
10271027
1028fn testBasenamePosix(input: []const u8, expected_output: []const u8) void {1028fn testBasenamePosix(input: []const u8, expected_output: []const u8) !void {
1029 testing.expectEqualSlices(u8, expected_output, basenamePosix(input));1029 try testing.expectEqualSlices(u8, expected_output, basenamePosix(input));
1030}1030}
10311031
1032fn testBasenameWindows(input: []const u8, expected_output: []const u8) void {1032fn testBasenameWindows(input: []const u8, expected_output: []const u8) !void {
1033 testing.expectEqualSlices(u8, expected_output, basenameWindows(input));1033 try testing.expectEqualSlices(u8, expected_output, basenameWindows(input));
1034}1034}
10351035
1036/// Returns the relative path from `from` to `to`. If `from` and `to` each1036/// Returns the relative path from `from` to `to`. If `from` and `to` each
...@@ -1212,13 +1212,13 @@ test "relative" {...@@ -1212,13 +1212,13 @@ test "relative" {
1212fn testRelativePosix(from: []const u8, to: []const u8, expected_output: []const u8) !void {1212fn testRelativePosix(from: []const u8, to: []const u8, expected_output: []const u8) !void {
1213 const result = try relativePosix(testing.allocator, from, to);1213 const result = try relativePosix(testing.allocator, from, to);
1214 defer testing.allocator.free(result);1214 defer testing.allocator.free(result);
1215 testing.expectEqualSlices(u8, expected_output, result);1215 try testing.expectEqualSlices(u8, expected_output, result);
1216}1216}
12171217
1218fn testRelativeWindows(from: []const u8, to: []const u8, expected_output: []const u8) !void {1218fn testRelativeWindows(from: []const u8, to: []const u8, expected_output: []const u8) !void {
1219 const result = try relativeWindows(testing.allocator, from, to);1219 const result = try relativeWindows(testing.allocator, from, to);
1220 defer testing.allocator.free(result);1220 defer testing.allocator.free(result);
1221 testing.expectEqualSlices(u8, expected_output, result);1221 try testing.expectEqualSlices(u8, expected_output, result);
1222}1222}
12231223
1224/// Returns the extension of the file name (if any).1224/// Returns the extension of the file name (if any).
...@@ -1241,47 +1241,47 @@ pub fn extension(path: []const u8) []const u8 {...@@ -1241,47 +1241,47 @@ pub fn extension(path: []const u8) []const u8 {
1241 return filename[index..];1241 return filename[index..];
1242}1242}
12431243
1244fn testExtension(path: []const u8, expected: []const u8) void {1244fn testExtension(path: []const u8, expected: []const u8) !void {
1245 std.testing.expectEqualStrings(expected, extension(path));1245 try std.testing.expectEqualStrings(expected, extension(path));
1246}1246}
12471247
1248test "extension" {1248test "extension" {
1249 testExtension("", "");1249 try testExtension("", "");
1250 testExtension(".", "");1250 try testExtension(".", "");
1251 testExtension("a.", ".");1251 try testExtension("a.", ".");
1252 testExtension("abc.", ".");1252 try testExtension("abc.", ".");
1253 testExtension(".a", "");1253 try testExtension(".a", "");
1254 testExtension(".file", "");1254 try testExtension(".file", "");
1255 testExtension(".gitignore", "");1255 try testExtension(".gitignore", "");
1256 testExtension("file.ext", ".ext");1256 try testExtension("file.ext", ".ext");
1257 testExtension("file.ext.", ".");1257 try testExtension("file.ext.", ".");
1258 testExtension("very-long-file.bruh", ".bruh");1258 try testExtension("very-long-file.bruh", ".bruh");
1259 testExtension("a.b.c", ".c");1259 try testExtension("a.b.c", ".c");
1260 testExtension("a.b.c/", ".c");1260 try testExtension("a.b.c/", ".c");
12611261
1262 testExtension("/", "");1262 try testExtension("/", "");
1263 testExtension("/.", "");1263 try testExtension("/.", "");
1264 testExtension("/a.", ".");1264 try testExtension("/a.", ".");
1265 testExtension("/abc.", ".");1265 try testExtension("/abc.", ".");
1266 testExtension("/.a", "");1266 try testExtension("/.a", "");
1267 testExtension("/.file", "");1267 try testExtension("/.file", "");
1268 testExtension("/.gitignore", "");1268 try testExtension("/.gitignore", "");
1269 testExtension("/file.ext", ".ext");1269 try testExtension("/file.ext", ".ext");
1270 testExtension("/file.ext.", ".");1270 try testExtension("/file.ext.", ".");
1271 testExtension("/very-long-file.bruh", ".bruh");1271 try testExtension("/very-long-file.bruh", ".bruh");
1272 testExtension("/a.b.c", ".c");1272 try testExtension("/a.b.c", ".c");
1273 testExtension("/a.b.c/", ".c");1273 try testExtension("/a.b.c/", ".c");
12741274
1275 testExtension("/foo/bar/bam/", "");1275 try testExtension("/foo/bar/bam/", "");
1276 testExtension("/foo/bar/bam/.", "");1276 try testExtension("/foo/bar/bam/.", "");
1277 testExtension("/foo/bar/bam/a.", ".");1277 try testExtension("/foo/bar/bam/a.", ".");
1278 testExtension("/foo/bar/bam/abc.", ".");1278 try testExtension("/foo/bar/bam/abc.", ".");
1279 testExtension("/foo/bar/bam/.a", "");1279 try testExtension("/foo/bar/bam/.a", "");
1280 testExtension("/foo/bar/bam/.file", "");1280 try testExtension("/foo/bar/bam/.file", "");
1281 testExtension("/foo/bar/bam/.gitignore", "");1281 try testExtension("/foo/bar/bam/.gitignore", "");
1282 testExtension("/foo/bar/bam/file.ext", ".ext");1282 try testExtension("/foo/bar/bam/file.ext", ".ext");
1283 testExtension("/foo/bar/bam/file.ext.", ".");1283 try testExtension("/foo/bar/bam/file.ext.", ".");
1284 testExtension("/foo/bar/bam/very-long-file.bruh", ".bruh");1284 try testExtension("/foo/bar/bam/very-long-file.bruh", ".bruh");
1285 testExtension("/foo/bar/bam/a.b.c", ".c");1285 try testExtension("/foo/bar/bam/a.b.c", ".c");
1286 testExtension("/foo/bar/bam/a.b.c/", ".c");1286 try testExtension("/foo/bar/bam/a.b.c/", ".c");
1287}1287}
lib/std/fs/test.zig+52-52
...@@ -46,7 +46,7 @@ test "Dir.readLink" {...@@ -46,7 +46,7 @@ test "Dir.readLink" {
46fn testReadLink(dir: Dir, target_path: []const u8, symlink_path: []const u8) !void {46fn testReadLink(dir: Dir, target_path: []const u8, symlink_path: []const u8) !void {
47 var buffer: [fs.MAX_PATH_BYTES]u8 = undefined;47 var buffer: [fs.MAX_PATH_BYTES]u8 = undefined;
48 const given = try dir.readLink(symlink_path, buffer[0..]);48 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));
50}50}
5151
52test "accessAbsolute" {52test "accessAbsolute" {
...@@ -132,7 +132,7 @@ test "readLinkAbsolute" {...@@ -132,7 +132,7 @@ test "readLinkAbsolute" {
132fn testReadLinkAbsolute(target_path: []const u8, symlink_path: []const u8) !void {132fn testReadLinkAbsolute(target_path: []const u8, symlink_path: []const u8) !void {
133 var buffer: [fs.MAX_PATH_BYTES]u8 = undefined;133 var buffer: [fs.MAX_PATH_BYTES]u8 = undefined;
134 const given = try fs.readLinkAbsolute(symlink_path, buffer[0..]);134 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));
136}136}
137137
138test "Dir.Iterator" {138test "Dir.Iterator" {
...@@ -159,9 +159,9 @@ test "Dir.Iterator" {...@@ -159,9 +159,9 @@ test "Dir.Iterator" {
159 try entries.append(Dir.Entry{ .name = name, .kind = entry.kind });159 try entries.append(Dir.Entry{ .name = name, .kind = entry.kind });
160 }160 }
161161
162 testing.expect(entries.items.len == 2); // note that the Iterator skips '.' and '..'162 try 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 }));163 try 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 }));164 try testing.expect(contains(&entries, Dir.Entry{ .name = "some_dir", .kind = Dir.Entry.Kind.Directory }));
165}165}
166166
167fn entryEql(lhs: Dir.Entry, rhs: Dir.Entry) bool {167fn entryEql(lhs: Dir.Entry, rhs: Dir.Entry) bool {
...@@ -203,7 +203,7 @@ test "Dir.realpath smoke test" {...@@ -203,7 +203,7 @@ test "Dir.realpath smoke test" {
203 const file_path = try tmp_dir.dir.realpath("test_file", buf1[0..]);203 const file_path = try tmp_dir.dir.realpath("test_file", buf1[0..]);
204 const expected_path = try fs.path.join(&arena.allocator, &[_][]const u8{ base_path, "test_file" });204 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));
207 }207 }
208208
209 // Next, test alloc version209 // Next, test alloc version
...@@ -211,7 +211,7 @@ test "Dir.realpath smoke test" {...@@ -211,7 +211,7 @@ test "Dir.realpath smoke test" {
211 const file_path = try tmp_dir.dir.realpathAlloc(&arena.allocator, "test_file");211 const file_path = try tmp_dir.dir.realpathAlloc(&arena.allocator, "test_file");
212 const expected_path = try fs.path.join(&arena.allocator, &[_][]const u8{ base_path, "test_file" });212 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));
215 }215 }
216}216}
217217
...@@ -224,7 +224,7 @@ test "readAllAlloc" {...@@ -224,7 +224,7 @@ test "readAllAlloc" {
224224
225 const buf1 = try file.readToEndAlloc(testing.allocator, 1024);225 const buf1 = try file.readToEndAlloc(testing.allocator, 1024);
226 defer testing.allocator.free(buf1);226 defer testing.allocator.free(buf1);
227 testing.expect(buf1.len == 0);227 try testing.expect(buf1.len == 0);
228228
229 const write_buf: []const u8 = "this is a test.\nthis is a test.\nthis is a test.\nthis is a test.\n";229 const write_buf: []const u8 = "this is a test.\nthis is a test.\nthis is a test.\nthis is a test.\n";
230 try file.writeAll(write_buf);230 try file.writeAll(write_buf);
...@@ -233,19 +233,19 @@ test "readAllAlloc" {...@@ -233,19 +233,19 @@ test "readAllAlloc" {
233 // max_bytes > file_size233 // max_bytes > file_size
234 const buf2 = try file.readToEndAlloc(testing.allocator, 1024);234 const buf2 = try file.readToEndAlloc(testing.allocator, 1024);
235 defer testing.allocator.free(buf2);235 defer testing.allocator.free(buf2);
236 testing.expectEqual(write_buf.len, buf2.len);236 try testing.expectEqual(write_buf.len, buf2.len);
237 testing.expect(std.mem.eql(u8, write_buf, buf2));237 try testing.expect(std.mem.eql(u8, write_buf, buf2));
238 try file.seekTo(0);238 try file.seekTo(0);
239239
240 // max_bytes == file_size240 // max_bytes == file_size
241 const buf3 = try file.readToEndAlloc(testing.allocator, write_buf.len);241 const buf3 = try file.readToEndAlloc(testing.allocator, write_buf.len);
242 defer testing.allocator.free(buf3);242 defer testing.allocator.free(buf3);
243 testing.expectEqual(write_buf.len, buf3.len);243 try testing.expectEqual(write_buf.len, buf3.len);
244 testing.expect(std.mem.eql(u8, write_buf, buf3));244 try testing.expect(std.mem.eql(u8, write_buf, buf3));
245 try file.seekTo(0);245 try file.seekTo(0);
246246
247 // max_bytes < file_size247 // 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));
249}249}
250250
251test "directory operations on files" {251test "directory operations on files" {
...@@ -257,22 +257,22 @@ test "directory operations on files" {...@@ -257,22 +257,22 @@ test "directory operations on files" {
257 var file = try tmp_dir.dir.createFile(test_file_name, .{ .read = true });257 var file = try tmp_dir.dir.createFile(test_file_name, .{ .read = true });
258 file.close();258 file.close();
259259
260 testing.expectError(error.PathAlreadyExists, tmp_dir.dir.makeDir(test_file_name));260 try testing.expectError(error.PathAlreadyExists, tmp_dir.dir.makeDir(test_file_name));
261 testing.expectError(error.NotDir, tmp_dir.dir.openDir(test_file_name, .{}));261 try testing.expectError(error.NotDir, tmp_dir.dir.openDir(test_file_name, .{}));
262 testing.expectError(error.NotDir, tmp_dir.dir.deleteDir(test_file_name));262 try testing.expectError(error.NotDir, tmp_dir.dir.deleteDir(test_file_name));
263263
264 if (builtin.os.tag != .wasi and builtin.os.tag != .freebsd and builtin.os.tag != .openbsd) {264 if (builtin.os.tag != .wasi and builtin.os.tag != .freebsd and builtin.os.tag != .openbsd) {
265 const absolute_path = try tmp_dir.dir.realpathAlloc(testing.allocator, test_file_name);265 const absolute_path = try tmp_dir.dir.realpathAlloc(testing.allocator, test_file_name);
266 defer testing.allocator.free(absolute_path);266 defer testing.allocator.free(absolute_path);
267267
268 testing.expectError(error.PathAlreadyExists, fs.makeDirAbsolute(absolute_path));268 try testing.expectError(error.PathAlreadyExists, fs.makeDirAbsolute(absolute_path));
269 testing.expectError(error.NotDir, fs.deleteDirAbsolute(absolute_path));269 try testing.expectError(error.NotDir, fs.deleteDirAbsolute(absolute_path));
270 }270 }
271271
272 // ensure the file still exists and is a file as a sanity check272 // ensure the file still exists and is a file as a sanity check
273 file = try tmp_dir.dir.openFile(test_file_name, .{});273 file = try tmp_dir.dir.openFile(test_file_name, .{});
274 const stat = try file.stat();274 const stat = try file.stat();
275 testing.expect(stat.kind == .File);275 try testing.expect(stat.kind == .File);
276 file.close();276 file.close();
277}277}
278278
...@@ -287,23 +287,23 @@ test "file operations on directories" {...@@ -287,23 +287,23 @@ test "file operations on directories" {
287287
288 try tmp_dir.dir.makeDir(test_dir_name);288 try tmp_dir.dir.makeDir(test_dir_name);
289289
290 testing.expectError(error.IsDir, tmp_dir.dir.createFile(test_dir_name, .{}));290 try testing.expectError(error.IsDir, tmp_dir.dir.createFile(test_dir_name, .{}));
291 testing.expectError(error.IsDir, tmp_dir.dir.deleteFile(test_dir_name));291 try testing.expectError(error.IsDir, tmp_dir.dir.deleteFile(test_dir_name));
292 // Currently, WASI will return error.Unexpected (via ENOTCAPABLE) when attempting fd_read on a directory handle.292 // Currently, WASI will return error.Unexpected (via ENOTCAPABLE) when attempting fd_read on a directory handle.
293 // TODO: Re-enable on WASI once https://github.com/bytecodealliance/wasmtime/issues/1935 is resolved.293 // TODO: Re-enable on WASI once https://github.com/bytecodealliance/wasmtime/issues/1935 is resolved.
294 if (builtin.os.tag != .wasi) {294 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)));
296 }296 }
297 // Note: The `.write = true` is necessary to ensure the error occurs on all platforms.297 // Note: The `.write = true` is necessary to ensure the error occurs on all platforms.
298 // TODO: Add a read-only test as well, see https://github.com/ziglang/zig/issues/5732298 // 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
301 if (builtin.os.tag != .wasi and builtin.os.tag != .freebsd and builtin.os.tag != .openbsd) {301 if (builtin.os.tag != .wasi and builtin.os.tag != .freebsd and builtin.os.tag != .openbsd) {
302 const absolute_path = try tmp_dir.dir.realpathAlloc(testing.allocator, test_dir_name);302 const absolute_path = try tmp_dir.dir.realpathAlloc(testing.allocator, test_dir_name);
303 defer testing.allocator.free(absolute_path);303 defer testing.allocator.free(absolute_path);
304304
305 testing.expectError(error.IsDir, fs.createFileAbsolute(absolute_path, .{}));305 try testing.expectError(error.IsDir, fs.createFileAbsolute(absolute_path, .{}));
306 testing.expectError(error.IsDir, fs.deleteFileAbsolute(absolute_path));306 try testing.expectError(error.IsDir, fs.deleteFileAbsolute(absolute_path));
307 }307 }
308308
309 // ensure the directory still exists as a sanity check309 // ensure the directory still exists as a sanity check
...@@ -316,7 +316,7 @@ test "deleteDir" {...@@ -316,7 +316,7 @@ test "deleteDir" {
316 defer tmp_dir.cleanup();316 defer tmp_dir.cleanup();
317317
318 // deleting a non-existent directory318 // 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
321 var dir = try tmp_dir.dir.makeOpenPath("test_dir", .{});321 var dir = try tmp_dir.dir.makeOpenPath("test_dir", .{});
322 var file = try dir.createFile("test_file", .{});322 var file = try dir.createFile("test_file", .{});
...@@ -326,7 +326,7 @@ test "deleteDir" {...@@ -326,7 +326,7 @@ test "deleteDir" {
326 // deleting a non-empty directory326 // deleting a non-empty directory
327 // TODO: Re-enable this check on Windows, see https://github.com/ziglang/zig/issues/5537327 // TODO: Re-enable this check on Windows, see https://github.com/ziglang/zig/issues/5537
328 if (builtin.os.tag != .windows) {328 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"));
330 }330 }
331331
332 dir = try tmp_dir.dir.openDir("test_dir", .{});332 dir = try tmp_dir.dir.openDir("test_dir", .{});
...@@ -341,7 +341,7 @@ test "Dir.rename files" {...@@ -341,7 +341,7 @@ test "Dir.rename files" {
341 var tmp_dir = tmpDir(.{});341 var tmp_dir = tmpDir(.{});
342 defer tmp_dir.cleanup();342 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
346 // Renaming files346 // Renaming files
347 const test_file_name = "test_file";347 const test_file_name = "test_file";
...@@ -351,7 +351,7 @@ test "Dir.rename files" {...@@ -351,7 +351,7 @@ test "Dir.rename files" {
351 try tmp_dir.dir.rename(test_file_name, renamed_test_file_name);351 try tmp_dir.dir.rename(test_file_name, renamed_test_file_name);
352352
353 // Ensure the file was renamed353 // 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, .{}));
355 file = try tmp_dir.dir.openFile(renamed_test_file_name, .{});355 file = try tmp_dir.dir.openFile(renamed_test_file_name, .{});
356 file.close();356 file.close();
357357
...@@ -363,7 +363,7 @@ test "Dir.rename files" {...@@ -363,7 +363,7 @@ test "Dir.rename files" {
363 existing_file.close();363 existing_file.close();
364 try tmp_dir.dir.rename(renamed_test_file_name, "existing_file");364 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, .{}));
367 file = try tmp_dir.dir.openFile("existing_file", .{});367 file = try tmp_dir.dir.openFile("existing_file", .{});
368 file.close();368 file.close();
369}369}
...@@ -380,7 +380,7 @@ test "Dir.rename directories" {...@@ -380,7 +380,7 @@ test "Dir.rename directories" {
380 try tmp_dir.dir.rename("test_dir", "test_dir_renamed");380 try tmp_dir.dir.rename("test_dir", "test_dir_renamed");
381381
382 // Ensure the directory was renamed382 // 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", .{}));
384 var dir = try tmp_dir.dir.openDir("test_dir_renamed", .{});384 var dir = try tmp_dir.dir.openDir("test_dir_renamed", .{});
385385
386 // Put a file in the directory386 // Put a file in the directory
...@@ -391,7 +391,7 @@ test "Dir.rename directories" {...@@ -391,7 +391,7 @@ test "Dir.rename directories" {
391 try tmp_dir.dir.rename("test_dir_renamed", "test_dir_renamed_again");391 try tmp_dir.dir.rename("test_dir_renamed", "test_dir_renamed_again");
392392
393 // Ensure the directory was renamed and the file still exists in it393 // 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", .{}));
395 dir = try tmp_dir.dir.openDir("test_dir_renamed_again", .{});395 dir = try tmp_dir.dir.openDir("test_dir_renamed_again", .{});
396 file = try dir.openFile("test_file", .{});396 file = try dir.openFile("test_file", .{});
397 file.close();397 file.close();
...@@ -402,7 +402,7 @@ test "Dir.rename directories" {...@@ -402,7 +402,7 @@ test "Dir.rename directories" {
402 file = try target_dir.createFile("filler", .{ .read = true });402 file = try target_dir.createFile("filler", .{ .read = true });
403 file.close();403 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
407 // Ensure the directory was not renamed407 // Ensure the directory was not renamed
408 dir = try tmp_dir.dir.openDir("test_dir_renamed_again", .{});408 dir = try tmp_dir.dir.openDir("test_dir_renamed_again", .{});
...@@ -421,8 +421,8 @@ test "Dir.rename file <-> dir" {...@@ -421,8 +421,8 @@ test "Dir.rename file <-> dir" {
421 var file = try tmp_dir.dir.createFile("test_file", .{ .read = true });421 var file = try tmp_dir.dir.createFile("test_file", .{ .read = true });
422 file.close();422 file.close();
423 try tmp_dir.dir.makeDir("test_dir");423 try tmp_dir.dir.makeDir("test_dir");
424 testing.expectError(error.IsDir, tmp_dir.dir.rename("test_file", "test_dir"));424 try 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"));425 try testing.expectError(error.NotDir, tmp_dir.dir.rename("test_dir", "test_file"));
426}426}
427427
428test "rename" {428test "rename" {
...@@ -440,7 +440,7 @@ test "rename" {...@@ -440,7 +440,7 @@ test "rename" {
440 try fs.rename(tmp_dir1.dir, test_file_name, tmp_dir2.dir, renamed_test_file_name);440 try fs.rename(tmp_dir1.dir, test_file_name, tmp_dir2.dir, renamed_test_file_name);
441441
442 // ensure the file was renamed442 // 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, .{}));
444 file = try tmp_dir2.dir.openFile(renamed_test_file_name, .{});444 file = try tmp_dir2.dir.openFile(renamed_test_file_name, .{});
445 file.close();445 file.close();
446}446}
...@@ -461,7 +461,7 @@ test "renameAbsolute" {...@@ -461,7 +461,7 @@ test "renameAbsolute" {
461 break :blk try fs.realpathAlloc(&arena.allocator, relative_path);461 break :blk try fs.realpathAlloc(&arena.allocator, relative_path);
462 };462 };
463463
464 testing.expectError(error.FileNotFound, fs.renameAbsolute(464 try testing.expectError(error.FileNotFound, fs.renameAbsolute(
465 try fs.path.join(allocator, &[_][]const u8{ base_path, "missing_file_name" }),465 try fs.path.join(allocator, &[_][]const u8{ base_path, "missing_file_name" }),
466 try fs.path.join(allocator, &[_][]const u8{ base_path, "something_else" }),466 try fs.path.join(allocator, &[_][]const u8{ base_path, "something_else" }),
467 ));467 ));
...@@ -477,10 +477,10 @@ test "renameAbsolute" {...@@ -477,10 +477,10 @@ test "renameAbsolute" {
477 );477 );
478478
479 // ensure the file was renamed479 // 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, .{}));
481 file = try tmp_dir.dir.openFile(renamed_test_file_name, .{});481 file = try tmp_dir.dir.openFile(renamed_test_file_name, .{});
482 const stat = try file.stat();482 const stat = try file.stat();
483 testing.expect(stat.kind == .File);483 try testing.expect(stat.kind == .File);
484 file.close();484 file.close();
485485
486 // Renaming directories486 // Renaming directories
...@@ -493,7 +493,7 @@ test "renameAbsolute" {...@@ -493,7 +493,7 @@ test "renameAbsolute" {
493 );493 );
494494
495 // ensure the directory was renamed495 // 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, .{}));
497 var dir = try tmp_dir.dir.openDir(renamed_test_dir_name, .{});497 var dir = try tmp_dir.dir.openDir(renamed_test_dir_name, .{});
498 dir.close();498 dir.close();
499}499}
...@@ -516,7 +516,7 @@ test "makePath, put some files in it, deleteTree" {...@@ -516,7 +516,7 @@ test "makePath, put some files in it, deleteTree" {
516 if (tmp.dir.openDir("os_test_tmp", .{})) |dir| {516 if (tmp.dir.openDir("os_test_tmp", .{})) |dir| {
517 @panic("expected error");517 @panic("expected error");
518 } else |err| {518 } else |err| {
519 testing.expect(err == error.FileNotFound);519 try testing.expect(err == error.FileNotFound);
520 }520 }
521}521}
522522
...@@ -530,7 +530,7 @@ test "access file" {...@@ -530,7 +530,7 @@ test "access file" {
530 if (tmp.dir.access("os_test_tmp" ++ fs.path.sep_str ++ "file.txt", .{})) |ok| {530 if (tmp.dir.access("os_test_tmp" ++ fs.path.sep_str ++ "file.txt", .{})) |ok| {
531 @panic("expected error");531 @panic("expected error");
532 } else |err| {532 } else |err| {
533 testing.expect(err == error.FileNotFound);533 try testing.expect(err == error.FileNotFound);
534 }534 }
535535
536 try tmp.dir.writeFile("os_test_tmp" ++ fs.path.sep_str ++ "file.txt", "");536 try tmp.dir.writeFile("os_test_tmp" ++ fs.path.sep_str ++ "file.txt", "");
...@@ -600,7 +600,7 @@ test "sendfile" {...@@ -600,7 +600,7 @@ test "sendfile" {
600 .header_count = 2,600 .header_count = 2,
601 });601 });
602 const amt = try dest_file.preadAll(&written_buf, 0);602 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"));
604}604}
605605
606test "copyRangeAll" {606test "copyRangeAll" {
...@@ -626,7 +626,7 @@ test "copyRangeAll" {...@@ -626,7 +626,7 @@ test "copyRangeAll" {
626 _ = try src_file.copyRangeAll(0, dest_file, 0, data.len);626 _ = try src_file.copyRangeAll(0, dest_file, 0, data.len);
627627
628 const amt = try dest_file.preadAll(&written_buf, 0);628 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));
630}630}
631631
632test "fs.copyFile" {632test "fs.copyFile" {
...@@ -655,7 +655,7 @@ fn expectFileContents(dir: Dir, file_path: []const u8, data: []const u8) !void {...@@ -655,7 +655,7 @@ fn expectFileContents(dir: Dir, file_path: []const u8, data: []const u8) !void {
655 const contents = try dir.readFileAlloc(testing.allocator, file_path, 1000);655 const contents = try dir.readFileAlloc(testing.allocator, file_path, 1000);
656 defer testing.allocator.free(contents);656 defer testing.allocator.free(contents);
657657
658 testing.expectEqualSlices(u8, data, contents);658 try testing.expectEqualSlices(u8, data, contents);
659}659}
660660
661test "AtomicFile" {661test "AtomicFile" {
...@@ -676,7 +676,7 @@ test "AtomicFile" {...@@ -676,7 +676,7 @@ test "AtomicFile" {
676 }676 }
677 const content = try tmp.dir.readFileAlloc(testing.allocator, test_out_file, 9999);677 const content = try tmp.dir.readFileAlloc(testing.allocator, test_out_file, 9999);
678 defer testing.allocator.free(content);678 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
681 try tmp.dir.deleteFile(test_out_file);681 try tmp.dir.deleteFile(test_out_file);
682}682}
...@@ -685,7 +685,7 @@ test "realpath" {...@@ -685,7 +685,7 @@ test "realpath" {
685 if (builtin.os.tag == .wasi) return error.SkipZigTest;685 if (builtin.os.tag == .wasi) return error.SkipZigTest;
686686
687 var buf: [std.fs.MAX_PATH_BYTES]u8 = undefined;687 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));
689}689}
690690
691test "open file with exclusive nonblocking lock twice" {691test "open file with exclusive nonblocking lock twice" {
...@@ -700,7 +700,7 @@ test "open file with exclusive nonblocking lock twice" {...@@ -700,7 +700,7 @@ test "open file with exclusive nonblocking lock twice" {
700 defer file1.close();700 defer file1.close();
701701
702 const file2 = tmp.dir.createFile(filename, .{ .lock = .Exclusive, .lock_nonblocking = true });702 const file2 = tmp.dir.createFile(filename, .{ .lock = .Exclusive, .lock_nonblocking = true });
703 testing.expectError(error.WouldBlock, file2);703 try testing.expectError(error.WouldBlock, file2);
704}704}
705705
706test "open file with shared and exclusive nonblocking lock" {706test "open file with shared and exclusive nonblocking lock" {
...@@ -715,7 +715,7 @@ test "open file with shared and exclusive nonblocking lock" {...@@ -715,7 +715,7 @@ test "open file with shared and exclusive nonblocking lock" {
715 defer file1.close();715 defer file1.close();
716716
717 const file2 = tmp.dir.createFile(filename, .{ .lock = .Exclusive, .lock_nonblocking = true });717 const file2 = tmp.dir.createFile(filename, .{ .lock = .Exclusive, .lock_nonblocking = true });
718 testing.expectError(error.WouldBlock, file2);718 try testing.expectError(error.WouldBlock, file2);
719}719}
720720
721test "open file with exclusive and shared nonblocking lock" {721test "open file with exclusive and shared nonblocking lock" {
...@@ -730,7 +730,7 @@ test "open file with exclusive and shared nonblocking lock" {...@@ -730,7 +730,7 @@ test "open file with exclusive and shared nonblocking lock" {
730 defer file1.close();730 defer file1.close();
731731
732 const file2 = tmp.dir.createFile(filename, .{ .lock = .Shared, .lock_nonblocking = true });732 const file2 = tmp.dir.createFile(filename, .{ .lock = .Shared, .lock_nonblocking = true });
733 testing.expectError(error.WouldBlock, file2);733 try testing.expectError(error.WouldBlock, file2);
734}734}
735735
736test "open file with exclusive lock twice, make sure it waits" {736test "open file with exclusive lock twice, make sure it waits" {
...@@ -790,7 +790,7 @@ test "open file with exclusive nonblocking lock twice (absolute paths)" {...@@ -790,7 +790,7 @@ test "open file with exclusive nonblocking lock twice (absolute paths)" {
790790
791 const file2 = fs.createFileAbsolute(filename, .{ .lock = .Exclusive, .lock_nonblocking = true });791 const file2 = fs.createFileAbsolute(filename, .{ .lock = .Exclusive, .lock_nonblocking = true });
792 file1.close();792 file1.close();
793 testing.expectError(error.WouldBlock, file2);793 try testing.expectError(error.WouldBlock, file2);
794794
795 try fs.deleteFileAbsolute(filename);795 try fs.deleteFileAbsolute(filename);
796}796}
...@@ -830,6 +830,6 @@ test "walker" {...@@ -830,6 +830,6 @@ test "walker" {
830 try fs.path.join(allocator, &[_][]const u8{ expected_dir_name, name });830 try fs.path.join(allocator, &[_][]const u8{ expected_dir_name, name });
831831
832 var entry = (try walker.next()).?;832 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));
834 }834 }
835}835}
lib/std/fs/wasi.zig+3-3
...@@ -174,8 +174,8 @@ test "extracting WASI preopens" {...@@ -174,8 +174,8 @@ test "extracting WASI preopens" {
174174
175 try preopens.populate();175 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);
178 const preopen = preopens.find(PreopenType{ .Dir = "." }) orelse unreachable;178 const preopen = preopens.find(PreopenType{ .Dir = "." }) orelse unreachable;
179 std.testing.expect(preopen.@"type".eql(PreopenType{ .Dir = "." }));179 try std.testing.expect(preopen.@"type".eql(PreopenType{ .Dir = "." }));
180 std.testing.expectEqual(@as(usize, 3), preopen.fd);180 try std.testing.expectEqual(@as(usize, 3), preopen.fd);
181}181}
lib/std/fs/watch.zig+3-3
...@@ -662,13 +662,13 @@ fn testWriteWatchWriteDelete(allocator: *Allocator) !void {...@@ -662,13 +662,13 @@ fn testWriteWatchWriteDelete(allocator: *Allocator) !void {
662662
663 const read_contents = try std.fs.cwd().readFileAlloc(allocator, file_path, 1024 * 1024);663 const read_contents = try std.fs.cwd().readFileAlloc(allocator, file_path, 1024 * 1024);
664 defer allocator.free(read_contents);664 defer allocator.free(read_contents);
665 testing.expectEqualSlices(u8, contents, read_contents);665 try testing.expectEqualSlices(u8, contents, read_contents);
666666
667 // now watch the file667 // now watch the file
668 var watch = try Watch(void).init(allocator, 0);668 var watch = try Watch(void).init(allocator, 0);
669 defer watch.deinit();669 defer watch.deinit();
670670
671 testing.expect((try watch.addFile(file_path, {})) == null);671 try testing.expect((try watch.addFile(file_path, {})) == null);
672672
673 var ev = async watch.channel.get();673 var ev = async watch.channel.get();
674 var ev_consumed = false;674 var ev_consumed = false;
...@@ -698,7 +698,7 @@ fn testWriteWatchWriteDelete(allocator: *Allocator) !void {...@@ -698,7 +698,7 @@ fn testWriteWatchWriteDelete(allocator: *Allocator) !void {
698 const contents_updated = try std.fs.cwd().readFileAlloc(allocator, file_path, 1024 * 1024);698 const contents_updated = try std.fs.cwd().readFileAlloc(allocator, file_path, 1024 * 1024);
699 defer allocator.free(contents_updated);699 defer allocator.free(contents_updated);
700700
701 testing.expectEqualSlices(u8,701 try testing.expectEqualSlices(u8,
702 \\line 1702 \\line 1
703 \\lorem ipsum703 \\lorem ipsum
704 , contents_updated);704 , contents_updated);
lib/std/hash/adler.zig+6-6
...@@ -99,21 +99,21 @@ pub const Adler32 = struct {...@@ -99,21 +99,21 @@ pub const Adler32 = struct {
99};99};
100100
101test "adler32 sanity" {101test "adler32 sanity" {
102 testing.expectEqual(@as(u32, 0x620062), Adler32.hash("a"));102 try testing.expectEqual(@as(u32, 0x620062), Adler32.hash("a"));
103 testing.expectEqual(@as(u32, 0xbc002ed), Adler32.hash("example"));103 try testing.expectEqual(@as(u32, 0xbc002ed), Adler32.hash("example"));
104}104}
105105
106test "adler32 long" {106test "adler32 long" {
107 const long1 = [_]u8{1} ** 1024;107 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
110 const long2 = [_]u8{1} ** 1025;110 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..]));
112}112}
113113
114test "adler32 very long" {114test "adler32 very long" {
115 const long = [_]u8{1} ** 5553;115 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..]));
117}117}
118118
119test "adler32 very long with variation" {119test "adler32 very long with variation" {
...@@ -129,5 +129,5 @@ test "adler32 very long with variation" {...@@ -129,5 +129,5 @@ test "adler32 very long with variation" {
129 break :blk result;129 break :blk result;
130 };130 };
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..]));
133}133}
lib/std/hash/auto_hash.zig+46-46
...@@ -239,18 +239,18 @@ fn testHashDeepRecursive(key: anytype) u64 {...@@ -239,18 +239,18 @@ fn testHashDeepRecursive(key: anytype) u64 {
239239
240test "typeContainsSlice" {240test "typeContainsSlice" {
241 comptime {241 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));244 try testing.expect(typeContainsSlice([]const u8));
245 testing.expect(!typeContainsSlice(u8));245 try testing.expect(!typeContainsSlice(u8));
246 const A = struct { x: []const u8 };246 const A = struct { x: []const u8 };
247 const B = struct { a: A };247 const B = struct { a: A };
248 const C = struct { b: B };248 const C = struct { b: B };
249 const D = struct { x: u8 };249 const D = struct { x: u8 };
250 testing.expect(typeContainsSlice(A));250 try testing.expect(typeContainsSlice(A));
251 testing.expect(typeContainsSlice(B));251 try testing.expect(typeContainsSlice(B));
252 testing.expect(typeContainsSlice(C));252 try testing.expect(typeContainsSlice(C));
253 testing.expect(!typeContainsSlice(D));253 try testing.expect(!typeContainsSlice(D));
254 }254 }
255}255}
256256
...@@ -261,17 +261,17 @@ test "hash pointer" {...@@ -261,17 +261,17 @@ test "hash pointer" {
261 const c = &array[2];261 const c = &array[2];
262 const d = a;262 const d = a;
263263
264 testing.expect(testHashShallow(a) == testHashShallow(d));264 try testing.expect(testHashShallow(a) == testHashShallow(d));
265 testing.expect(testHashShallow(a) != testHashShallow(c));265 try testing.expect(testHashShallow(a) != testHashShallow(c));
266 testing.expect(testHashShallow(a) != testHashShallow(b));266 try testing.expect(testHashShallow(a) != testHashShallow(b));
267267
268 testing.expect(testHashDeep(a) == testHashDeep(a));268 try testing.expect(testHashDeep(a) == testHashDeep(a));
269 testing.expect(testHashDeep(a) == testHashDeep(c));269 try testing.expect(testHashDeep(a) == testHashDeep(c));
270 testing.expect(testHashDeep(a) == testHashDeep(b));270 try testing.expect(testHashDeep(a) == testHashDeep(b));
271271
272 testing.expect(testHashDeepRecursive(a) == testHashDeepRecursive(a));272 try testing.expect(testHashDeepRecursive(a) == testHashDeepRecursive(a));
273 testing.expect(testHashDeepRecursive(a) == testHashDeepRecursive(c));273 try testing.expect(testHashDeepRecursive(a) == testHashDeepRecursive(c));
274 testing.expect(testHashDeepRecursive(a) == testHashDeepRecursive(b));274 try testing.expect(testHashDeepRecursive(a) == testHashDeepRecursive(b));
275}275}
276276
277test "hash slice shallow" {277test "hash slice shallow" {
...@@ -286,10 +286,10 @@ test "hash slice shallow" {...@@ -286,10 +286,10 @@ test "hash slice shallow" {
286 const a = array1[runtime_zero..];286 const a = array1[runtime_zero..];
287 const b = array2[runtime_zero..];287 const b = array2[runtime_zero..];
288 const c = array1[runtime_zero..3];288 const c = array1[runtime_zero..3];
289 testing.expect(testHashShallow(a) == testHashShallow(a));289 try testing.expect(testHashShallow(a) == testHashShallow(a));
290 testing.expect(testHashShallow(a) != testHashShallow(array1));290 try testing.expect(testHashShallow(a) != testHashShallow(array1));
291 testing.expect(testHashShallow(a) != testHashShallow(b));291 try testing.expect(testHashShallow(a) != testHashShallow(b));
292 testing.expect(testHashShallow(a) != testHashShallow(c));292 try testing.expect(testHashShallow(a) != testHashShallow(c));
293}293}
294294
295test "hash slice deep" {295test "hash slice deep" {
...@@ -302,10 +302,10 @@ test "hash slice deep" {...@@ -302,10 +302,10 @@ test "hash slice deep" {
302 const a = array1[0..];302 const a = array1[0..];
303 const b = array2[0..];303 const b = array2[0..];
304 const c = array1[0..3];304 const c = array1[0..3];
305 testing.expect(testHashDeep(a) == testHashDeep(a));305 try testing.expect(testHashDeep(a) == testHashDeep(a));
306 testing.expect(testHashDeep(a) == testHashDeep(array1));306 try testing.expect(testHashDeep(a) == testHashDeep(array1));
307 testing.expect(testHashDeep(a) == testHashDeep(b));307 try testing.expect(testHashDeep(a) == testHashDeep(b));
308 testing.expect(testHashDeep(a) != testHashDeep(c));308 try testing.expect(testHashDeep(a) != testHashDeep(c));
309}309}
310310
311test "hash struct deep" {311test "hash struct deep" {
...@@ -331,28 +331,28 @@ test "hash struct deep" {...@@ -331,28 +331,28 @@ test "hash struct deep" {
331 defer allocator.destroy(bar.c);331 defer allocator.destroy(bar.c);
332 defer allocator.destroy(baz.c);332 defer allocator.destroy(baz.c);
333333
334 testing.expect(testHashDeep(foo) == testHashDeep(bar));334 try testing.expect(testHashDeep(foo) == testHashDeep(bar));
335 testing.expect(testHashDeep(foo) != testHashDeep(baz));335 try testing.expect(testHashDeep(foo) != testHashDeep(baz));
336 testing.expect(testHashDeep(bar) != testHashDeep(baz));336 try testing.expect(testHashDeep(bar) != testHashDeep(baz));
337337
338 var hasher = Wyhash.init(0);338 var hasher = Wyhash.init(0);
339 const h = testHashDeep(foo);339 const h = testHashDeep(foo);
340 autoHash(&hasher, foo.a);340 autoHash(&hasher, foo.a);
341 autoHash(&hasher, foo.b);341 autoHash(&hasher, foo.b);
342 autoHash(&hasher, foo.c.*);342 autoHash(&hasher, foo.c.*);
343 testing.expectEqual(h, hasher.final());343 try testing.expectEqual(h, hasher.final());
344344
345 const h2 = testHashDeepRecursive(&foo);345 const h2 = testHashDeepRecursive(&foo);
346 testing.expect(h2 != testHashDeep(&foo));346 try testing.expect(h2 != testHashDeep(&foo));
347 testing.expect(h2 == testHashDeep(foo));347 try testing.expect(h2 == testHashDeep(foo));
348}348}
349349
350test "testHash optional" {350test "testHash optional" {
351 const a: ?u32 = 123;351 const a: ?u32 = 123;
352 const b: ?u32 = null;352 const b: ?u32 = null;
353 testing.expectEqual(testHash(a), testHash(@as(u32, 123)));353 try testing.expectEqual(testHash(a), testHash(@as(u32, 123)));
354 testing.expect(testHash(a) != testHash(b));354 try testing.expect(testHash(a) != testHash(b));
355 testing.expectEqual(testHash(b), 0);355 try testing.expectEqual(testHash(b), 0);
356}356}
357357
358test "testHash array" {358test "testHash array" {
...@@ -362,7 +362,7 @@ test "testHash array" {...@@ -362,7 +362,7 @@ test "testHash array" {
362 autoHash(&hasher, @as(u32, 1));362 autoHash(&hasher, @as(u32, 1));
363 autoHash(&hasher, @as(u32, 2));363 autoHash(&hasher, @as(u32, 2));
364 autoHash(&hasher, @as(u32, 3));364 autoHash(&hasher, @as(u32, 3));
365 testing.expectEqual(h, hasher.final());365 try testing.expectEqual(h, hasher.final());
366}366}
367367
368test "testHash struct" {368test "testHash struct" {
...@@ -377,7 +377,7 @@ test "testHash struct" {...@@ -377,7 +377,7 @@ test "testHash struct" {
377 autoHash(&hasher, @as(u32, 1));377 autoHash(&hasher, @as(u32, 1));
378 autoHash(&hasher, @as(u32, 2));378 autoHash(&hasher, @as(u32, 2));
379 autoHash(&hasher, @as(u32, 3));379 autoHash(&hasher, @as(u32, 3));
380 testing.expectEqual(h, hasher.final());380 try testing.expectEqual(h, hasher.final());
381}381}
382382
383test "testHash union" {383test "testHash union" {
...@@ -390,12 +390,12 @@ test "testHash union" {...@@ -390,12 +390,12 @@ test "testHash union" {
390 const a = Foo{ .A = 18 };390 const a = Foo{ .A = 18 };
391 var b = Foo{ .B = true };391 var b = Foo{ .B = true };
392 const c = Foo{ .C = 18 };392 const c = Foo{ .C = 18 };
393 testing.expect(testHash(a) == testHash(a));393 try testing.expect(testHash(a) == testHash(a));
394 testing.expect(testHash(a) != testHash(b));394 try testing.expect(testHash(a) != testHash(b));
395 testing.expect(testHash(a) != testHash(c));395 try testing.expect(testHash(a) != testHash(c));
396396
397 b = Foo{ .A = 18 };397 b = Foo{ .A = 18 };
398 testing.expect(testHash(a) == testHash(b));398 try testing.expect(testHash(a) == testHash(b));
399}399}
400400
401test "testHash vector" {401test "testHash vector" {
...@@ -404,13 +404,13 @@ test "testHash vector" {...@@ -404,13 +404,13 @@ test "testHash vector" {
404404
405 const a: meta.Vector(4, u32) = [_]u32{ 1, 2, 3, 4 };405 const a: meta.Vector(4, u32) = [_]u32{ 1, 2, 3, 4 };
406 const b: meta.Vector(4, u32) = [_]u32{ 1, 2, 3, 5 };406 const b: meta.Vector(4, u32) = [_]u32{ 1, 2, 3, 5 };
407 testing.expect(testHash(a) == testHash(a));407 try testing.expect(testHash(a) == testHash(a));
408 testing.expect(testHash(a) != testHash(b));408 try testing.expect(testHash(a) != testHash(b));
409409
410 const c: meta.Vector(4, u31) = [_]u31{ 1, 2, 3, 4 };410 const c: meta.Vector(4, u31) = [_]u31{ 1, 2, 3, 4 };
411 const d: meta.Vector(4, u31) = [_]u31{ 1, 2, 3, 5 };411 const d: meta.Vector(4, u31) = [_]u31{ 1, 2, 3, 5 };
412 testing.expect(testHash(c) == testHash(c));412 try testing.expect(testHash(c) == testHash(c));
413 testing.expect(testHash(c) != testHash(d));413 try testing.expect(testHash(c) != testHash(d));
414}414}
415415
416test "testHash error union" {416test "testHash error union" {
...@@ -422,7 +422,7 @@ test "testHash error union" {...@@ -422,7 +422,7 @@ test "testHash error union" {
422 };422 };
423 const f = Foo{};423 const f = Foo{};
424 const g: Errors!Foo = Errors.Test;424 const g: Errors!Foo = Errors.Test;
425 testing.expect(testHash(f) != testHash(g));425 try testing.expect(testHash(f) != testHash(g));
426 testing.expect(testHash(f) == testHash(Foo{}));426 try testing.expect(testHash(f) == testHash(Foo{}));
427 testing.expect(testHash(g) == testHash(Errors.Test));427 try testing.expect(testHash(g) == testHash(Errors.Test));
428}428}
lib/std/hash/cityhash.zig+7-7
...@@ -381,14 +381,14 @@ fn CityHash32hashIgnoreSeed(str: []const u8, seed: u32) u32 {...@@ -381,14 +381,14 @@ fn CityHash32hashIgnoreSeed(str: []const u8, seed: u32) u32 {
381381
382test "cityhash32" {382test "cityhash32" {
383 const Test = struct {383 const Test = struct {
384 fn doTest() void {384 fn doTest() !void {
385 // Note: SMHasher doesn't provide a 32bit version of the algorithm.385 // Note: SMHasher doesn't provide a 32bit version of the algorithm.
386 // Note: The implementation was verified against the Google Abseil version.386 // Note: The implementation was verified against the Google Abseil version.
387 std.testing.expectEqual(SMHasherTest(CityHash32hashIgnoreSeed), 0x68254F81);387 try std.testing.expectEqual(SMHasherTest(CityHash32hashIgnoreSeed), 0x68254F81);
388 std.testing.expectEqual(SMHasherTest(CityHash32hashIgnoreSeed), 0x68254F81);388 try std.testing.expectEqual(SMHasherTest(CityHash32hashIgnoreSeed), 0x68254F81);
389 }389 }
390 };390 };
391 Test.doTest();391 try Test.doTest();
392 // TODO This is uncommented to prevent OOM on the CI server. Re-enable this test392 // TODO This is uncommented to prevent OOM on the CI server. Re-enable this test
393 // case once we ship stage2.393 // case once we ship stage2.
394 //@setEvalBranchQuota(50000);394 //@setEvalBranchQuota(50000);
...@@ -397,13 +397,13 @@ test "cityhash32" {...@@ -397,13 +397,13 @@ test "cityhash32" {
397397
398test "cityhash64" {398test "cityhash64" {
399 const Test = struct {399 const Test = struct {
400 fn doTest() void {400 fn doTest() !void {
401 // Note: This is not compliant with the SMHasher implementation of CityHash64!401 // Note: This is not compliant with the SMHasher implementation of CityHash64!
402 // Note: The implementation was verified against the Google Abseil version.402 // 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);
404 }404 }
405 };405 };
406 Test.doTest();406 try Test.doTest();
407 // TODO This is uncommented to prevent OOM on the CI server. Re-enable this test407 // TODO This is uncommented to prevent OOM on the CI server. Re-enable this test
408 // case once we ship stage2.408 // case once we ship stage2.
409 //@setEvalBranchQuota(50000);409 //@setEvalBranchQuota(50000);
lib/std/hash/crc.zig+12-12
...@@ -109,9 +109,9 @@ test "crc32 ieee" {...@@ -109,9 +109,9 @@ test "crc32 ieee" {
109109
110 const Crc32Ieee = Crc32WithPoly(.IEEE);110 const Crc32Ieee = Crc32WithPoly(.IEEE);
111111
112 testing.expect(Crc32Ieee.hash("") == 0x00000000);112 try testing.expect(Crc32Ieee.hash("") == 0x00000000);
113 testing.expect(Crc32Ieee.hash("a") == 0xe8b7be43);113 try testing.expect(Crc32Ieee.hash("a") == 0xe8b7be43);
114 testing.expect(Crc32Ieee.hash("abc") == 0x352441c2);114 try testing.expect(Crc32Ieee.hash("abc") == 0x352441c2);
115}115}
116116
117test "crc32 castagnoli" {117test "crc32 castagnoli" {
...@@ -119,9 +119,9 @@ test "crc32 castagnoli" {...@@ -119,9 +119,9 @@ test "crc32 castagnoli" {
119119
120 const Crc32Castagnoli = Crc32WithPoly(.Castagnoli);120 const Crc32Castagnoli = Crc32WithPoly(.Castagnoli);
121121
122 testing.expect(Crc32Castagnoli.hash("") == 0x00000000);122 try testing.expect(Crc32Castagnoli.hash("") == 0x00000000);
123 testing.expect(Crc32Castagnoli.hash("a") == 0xc1d04330);123 try testing.expect(Crc32Castagnoli.hash("a") == 0xc1d04330);
124 testing.expect(Crc32Castagnoli.hash("abc") == 0x364b3fb7);124 try testing.expect(Crc32Castagnoli.hash("abc") == 0x364b3fb7);
125}125}
126126
127// half-byte lookup table implementation.127// half-byte lookup table implementation.
...@@ -177,9 +177,9 @@ test "small crc32 ieee" {...@@ -177,9 +177,9 @@ test "small crc32 ieee" {
177177
178 const Crc32Ieee = Crc32SmallWithPoly(.IEEE);178 const Crc32Ieee = Crc32SmallWithPoly(.IEEE);
179179
180 testing.expect(Crc32Ieee.hash("") == 0x00000000);180 try testing.expect(Crc32Ieee.hash("") == 0x00000000);
181 testing.expect(Crc32Ieee.hash("a") == 0xe8b7be43);181 try testing.expect(Crc32Ieee.hash("a") == 0xe8b7be43);
182 testing.expect(Crc32Ieee.hash("abc") == 0x352441c2);182 try testing.expect(Crc32Ieee.hash("abc") == 0x352441c2);
183}183}
184184
185test "small crc32 castagnoli" {185test "small crc32 castagnoli" {
...@@ -187,7 +187,7 @@ test "small crc32 castagnoli" {...@@ -187,7 +187,7 @@ test "small crc32 castagnoli" {
187187
188 const Crc32Castagnoli = Crc32SmallWithPoly(.Castagnoli);188 const Crc32Castagnoli = Crc32SmallWithPoly(.Castagnoli);
189189
190 testing.expect(Crc32Castagnoli.hash("") == 0x00000000);190 try testing.expect(Crc32Castagnoli.hash("") == 0x00000000);
191 testing.expect(Crc32Castagnoli.hash("a") == 0xc1d04330);191 try testing.expect(Crc32Castagnoli.hash("a") == 0xc1d04330);
192 testing.expect(Crc32Castagnoli.hash("abc") == 0x364b3fb7);192 try testing.expect(Crc32Castagnoli.hash("abc") == 0x364b3fb7);
193}193}
lib/std/hash/fnv.zig+8-8
...@@ -46,18 +46,18 @@ fn Fnv1a(comptime T: type, comptime prime: T, comptime offset: T) type {...@@ -46,18 +46,18 @@ fn Fnv1a(comptime T: type, comptime prime: T, comptime offset: T) type {
46}46}
4747
48test "fnv1a-32" {48test "fnv1a-32" {
49 testing.expect(Fnv1a_32.hash("") == 0x811c9dc5);49 try testing.expect(Fnv1a_32.hash("") == 0x811c9dc5);
50 testing.expect(Fnv1a_32.hash("a") == 0xe40c292c);50 try testing.expect(Fnv1a_32.hash("a") == 0xe40c292c);
51 testing.expect(Fnv1a_32.hash("foobar") == 0xbf9cf968);51 try testing.expect(Fnv1a_32.hash("foobar") == 0xbf9cf968);
52}52}
5353
54test "fnv1a-64" {54test "fnv1a-64" {
55 testing.expect(Fnv1a_64.hash("") == 0xcbf29ce484222325);55 try testing.expect(Fnv1a_64.hash("") == 0xcbf29ce484222325);
56 testing.expect(Fnv1a_64.hash("a") == 0xaf63dc4c8601ec8c);56 try testing.expect(Fnv1a_64.hash("a") == 0xaf63dc4c8601ec8c);
57 testing.expect(Fnv1a_64.hash("foobar") == 0x85944171f73967e8);57 try testing.expect(Fnv1a_64.hash("foobar") == 0x85944171f73967e8);
58}58}
5959
60test "fnv1a-128" {60test "fnv1a-128" {
61 testing.expect(Fnv1a_128.hash("") == 0x6c62272e07bb014262b821756295c58d);61 try testing.expect(Fnv1a_128.hash("") == 0x6c62272e07bb014262b821756295c58d);
62 testing.expect(Fnv1a_128.hash("a") == 0xd228cb696f1a8caf78912b704e4a8964);62 try testing.expect(Fnv1a_128.hash("a") == 0xd228cb696f1a8caf78912b704e4a8964);
63}63}
lib/std/hash/murmur.zig+9-9
...@@ -308,7 +308,7 @@ fn SMHasherTest(comptime hash_fn: anytype, comptime hashbits: u32) u32 {...@@ -308,7 +308,7 @@ fn SMHasherTest(comptime hash_fn: anytype, comptime hashbits: u32) u32 {
308}308}
309309
310test "murmur2_32" {310test "murmur2_32" {
311 testing.expectEqual(SMHasherTest(Murmur2_32.hashWithSeed, 32), 0x27864C1E);311 try testing.expectEqual(SMHasherTest(Murmur2_32.hashWithSeed, 32), 0x27864C1E);
312 var v0: u32 = 0x12345678;312 var v0: u32 = 0x12345678;
313 var v1: u64 = 0x1234567812345678;313 var v1: u64 = 0x1234567812345678;
314 var v0le: u32 = v0;314 var v0le: u32 = v0;
...@@ -317,12 +317,12 @@ test "murmur2_32" {...@@ -317,12 +317,12 @@ test "murmur2_32" {
317 v0le = @byteSwap(u32, v0le);317 v0le = @byteSwap(u32, v0le);
318 v1le = @byteSwap(u64, v1le);318 v1le = @byteSwap(u64, v1le);
319 }319 }
320 testing.expectEqual(Murmur2_32.hash(@ptrCast([*]u8, &v0le)[0..4]), Murmur2_32.hashUint32(v0));320 try 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));321 try testing.expectEqual(Murmur2_32.hash(@ptrCast([*]u8, &v1le)[0..8]), Murmur2_32.hashUint64(v1));
322}322}
323323
324test "murmur2_64" {324test "murmur2_64" {
325 std.testing.expectEqual(SMHasherTest(Murmur2_64.hashWithSeed, 64), 0x1F0D3804);325 try std.testing.expectEqual(SMHasherTest(Murmur2_64.hashWithSeed, 64), 0x1F0D3804);
326 var v0: u32 = 0x12345678;326 var v0: u32 = 0x12345678;
327 var v1: u64 = 0x1234567812345678;327 var v1: u64 = 0x1234567812345678;
328 var v0le: u32 = v0;328 var v0le: u32 = v0;
...@@ -331,12 +331,12 @@ test "murmur2_64" {...@@ -331,12 +331,12 @@ test "murmur2_64" {
331 v0le = @byteSwap(u32, v0le);331 v0le = @byteSwap(u32, v0le);
332 v1le = @byteSwap(u64, v1le);332 v1le = @byteSwap(u64, v1le);
333 }333 }
334 testing.expectEqual(Murmur2_64.hash(@ptrCast([*]u8, &v0le)[0..4]), Murmur2_64.hashUint32(v0));334 try 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));335 try testing.expectEqual(Murmur2_64.hash(@ptrCast([*]u8, &v1le)[0..8]), Murmur2_64.hashUint64(v1));
336}336}
337337
338test "murmur3_32" {338test "murmur3_32" {
339 std.testing.expectEqual(SMHasherTest(Murmur3_32.hashWithSeed, 32), 0xB0F57EE3);339 try std.testing.expectEqual(SMHasherTest(Murmur3_32.hashWithSeed, 32), 0xB0F57EE3);
340 var v0: u32 = 0x12345678;340 var v0: u32 = 0x12345678;
341 var v1: u64 = 0x1234567812345678;341 var v1: u64 = 0x1234567812345678;
342 var v0le: u32 = v0;342 var v0le: u32 = v0;
...@@ -345,6 +345,6 @@ test "murmur3_32" {...@@ -345,6 +345,6 @@ test "murmur3_32" {
345 v0le = @byteSwap(u32, v0le);345 v0le = @byteSwap(u32, v0le);
346 v1le = @byteSwap(u64, v1le);346 v1le = @byteSwap(u64, v1le);
347 }347 }
348 testing.expectEqual(Murmur3_32.hash(@ptrCast([*]u8, &v0le)[0..4]), Murmur3_32.hashUint32(v0));348 try 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));349 try testing.expectEqual(Murmur3_32.hash(@ptrCast([*]u8, &v1le)[0..8]), Murmur3_32.hashUint64(v1));
350}350}
lib/std/hash/wyhash.zig+11-11
...@@ -183,13 +183,13 @@ const expectEqual = std.testing.expectEqual;...@@ -183,13 +183,13 @@ const expectEqual = std.testing.expectEqual;
183test "test vectors" {183test "test vectors" {
184 const hash = Wyhash.hash;184 const hash = Wyhash.hash;
185185
186 expectEqual(hash(0, ""), 0x0);186 try expectEqual(hash(0, ""), 0x0);
187 expectEqual(hash(1, "a"), 0xbed235177f41d328);187 try expectEqual(hash(1, "a"), 0xbed235177f41d328);
188 expectEqual(hash(2, "abc"), 0xbe348debe59b27c3);188 try expectEqual(hash(2, "abc"), 0xbe348debe59b27c3);
189 expectEqual(hash(3, "message digest"), 0x37320f657213a290);189 try expectEqual(hash(3, "message digest"), 0x37320f657213a290);
190 expectEqual(hash(4, "abcdefghijklmnopqrstuvwxyz"), 0xd0b270e1d8a7019c);190 try expectEqual(hash(4, "abcdefghijklmnopqrstuvwxyz"), 0xd0b270e1d8a7019c);
191 expectEqual(hash(5, "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"), 0x602a1894d3bbfe7f);191 try expectEqual(hash(5, "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"), 0x602a1894d3bbfe7f);
192 expectEqual(hash(6, "12345678901234567890123456789012345678901234567890123456789012345678901234567890"), 0x829e9c148b75970e);192 try expectEqual(hash(6, "12345678901234567890123456789012345678901234567890123456789012345678901234567890"), 0x829e9c148b75970e);
193}193}
194194
195test "test vectors streaming" {195test "test vectors streaming" {
...@@ -197,19 +197,19 @@ test "test vectors streaming" {...@@ -197,19 +197,19 @@ test "test vectors streaming" {
197 for ("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789") |e| {197 for ("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789") |e| {
198 wh.update(mem.asBytes(&e));198 wh.update(mem.asBytes(&e));
199 }199 }
200 expectEqual(wh.final(), 0x602a1894d3bbfe7f);200 try expectEqual(wh.final(), 0x602a1894d3bbfe7f);
201201
202 const pattern = "1234567890";202 const pattern = "1234567890";
203 const count = 8;203 const count = 8;
204 const result = 0x829e9c148b75970e;204 const result = 0x829e9c148b75970e;
205 expectEqual(Wyhash.hash(6, pattern ** 8), result);205 try expectEqual(Wyhash.hash(6, pattern ** 8), result);
206206
207 wh = Wyhash.init(6);207 wh = Wyhash.init(6);
208 var i: u32 = 0;208 var i: u32 = 0;
209 while (i < count) : (i += 1) {209 while (i < count) : (i += 1) {
210 wh.update(pattern);210 wh.update(pattern);
211 }211 }
212 expectEqual(wh.final(), result);212 try expectEqual(wh.final(), result);
213}213}
214214
215test "iterative non-divisible update" {215test "iterative non-divisible update" {
...@@ -231,6 +231,6 @@ test "iterative non-divisible update" {...@@ -231,6 +231,6 @@ test "iterative non-divisible update" {
231 }231 }
232 const iterative_hash = wy.final();232 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);
235 }235 }
236}236}
lib/std/hash_map.zig+72-72
...@@ -823,15 +823,15 @@ test "std.hash_map basic usage" {...@@ -823,15 +823,15 @@ test "std.hash_map basic usage" {
823 while (it.next()) |kv| {823 while (it.next()) |kv| {
824 sum += kv.key;824 sum += kv.key;
825 }825 }
826 expect(sum == total);826 try expect(sum == total);
827827
828 i = 0;828 i = 0;
829 sum = 0;829 sum = 0;
830 while (i < count) : (i += 1) {830 while (i < count) : (i += 1) {
831 expectEqual(map.get(i).?, i);831 try expectEqual(map.get(i).?, i);
832 sum += map.get(i).?;832 sum += map.get(i).?;
833 }833 }
834 expectEqual(total, sum);834 try expectEqual(total, sum);
835}835}
836836
837test "std.hash_map ensureCapacity" {837test "std.hash_map ensureCapacity" {
...@@ -840,13 +840,13 @@ test "std.hash_map ensureCapacity" {...@@ -840,13 +840,13 @@ test "std.hash_map ensureCapacity" {
840840
841 try map.ensureCapacity(20);841 try map.ensureCapacity(20);
842 const initial_capacity = map.capacity();842 const initial_capacity = map.capacity();
843 testing.expect(initial_capacity >= 20);843 try testing.expect(initial_capacity >= 20);
844 var i: i32 = 0;844 var i: i32 = 0;
845 while (i < 20) : (i += 1) {845 while (i < 20) : (i += 1) {
846 testing.expect(map.fetchPutAssumeCapacity(i, i + 10) == null);846 try testing.expect(map.fetchPutAssumeCapacity(i, i + 10) == null);
847 }847 }
848 // shouldn't resize from putAssumeCapacity848 // shouldn't resize from putAssumeCapacity
849 testing.expect(initial_capacity == map.capacity());849 try testing.expect(initial_capacity == map.capacity());
850}850}
851851
852test "std.hash_map ensureCapacity with tombstones" {852test "std.hash_map ensureCapacity with tombstones" {
...@@ -869,22 +869,22 @@ test "std.hash_map clearRetainingCapacity" {...@@ -869,22 +869,22 @@ test "std.hash_map clearRetainingCapacity" {
869 map.clearRetainingCapacity();869 map.clearRetainingCapacity();
870870
871 try map.put(1, 1);871 try map.put(1, 1);
872 expectEqual(map.get(1).?, 1);872 try expectEqual(map.get(1).?, 1);
873 expectEqual(map.count(), 1);873 try expectEqual(map.count(), 1);
874874
875 map.clearRetainingCapacity();875 map.clearRetainingCapacity();
876 map.putAssumeCapacity(1, 1);876 map.putAssumeCapacity(1, 1);
877 expectEqual(map.get(1).?, 1);877 try expectEqual(map.get(1).?, 1);
878 expectEqual(map.count(), 1);878 try expectEqual(map.count(), 1);
879879
880 const cap = map.capacity();880 const cap = map.capacity();
881 expect(cap > 0);881 try expect(cap > 0);
882882
883 map.clearRetainingCapacity();883 map.clearRetainingCapacity();
884 map.clearRetainingCapacity();884 map.clearRetainingCapacity();
885 expectEqual(map.count(), 0);885 try expectEqual(map.count(), 0);
886 expectEqual(map.capacity(), cap);886 try expectEqual(map.capacity(), cap);
887 expect(!map.contains(1));887 try expect(!map.contains(1));
888}888}
889889
890test "std.hash_map grow" {890test "std.hash_map grow" {
...@@ -897,19 +897,19 @@ test "std.hash_map grow" {...@@ -897,19 +897,19 @@ test "std.hash_map grow" {
897 while (i < growTo) : (i += 1) {897 while (i < growTo) : (i += 1) {
898 try map.put(i, i);898 try map.put(i, i);
899 }899 }
900 expectEqual(map.count(), growTo);900 try expectEqual(map.count(), growTo);
901901
902 i = 0;902 i = 0;
903 var it = map.iterator();903 var it = map.iterator();
904 while (it.next()) |kv| {904 while (it.next()) |kv| {
905 expectEqual(kv.key, kv.value);905 try expectEqual(kv.key, kv.value);
906 i += 1;906 i += 1;
907 }907 }
908 expectEqual(i, growTo);908 try expectEqual(i, growTo);
909909
910 i = 0;910 i = 0;
911 while (i < growTo) : (i += 1) {911 while (i < growTo) : (i += 1) {
912 expectEqual(map.get(i).?, i);912 try expectEqual(map.get(i).?, i);
913 }913 }
914}914}
915915
...@@ -920,7 +920,7 @@ test "std.hash_map clone" {...@@ -920,7 +920,7 @@ test "std.hash_map clone" {
920 var a = try map.clone();920 var a = try map.clone();
921 defer a.deinit();921 defer a.deinit();
922922
923 expectEqual(a.count(), 0);923 try expectEqual(a.count(), 0);
924924
925 try a.put(1, 1);925 try a.put(1, 1);
926 try a.put(2, 2);926 try a.put(2, 2);
...@@ -929,10 +929,10 @@ test "std.hash_map clone" {...@@ -929,10 +929,10 @@ test "std.hash_map clone" {
929 var b = try a.clone();929 var b = try a.clone();
930 defer b.deinit();930 defer b.deinit();
931931
932 expectEqual(b.count(), 3);932 try expectEqual(b.count(), 3);
933 expectEqual(b.get(1), 1);933 try expectEqual(b.get(1), 1);
934 expectEqual(b.get(2), 2);934 try expectEqual(b.get(2), 2);
935 expectEqual(b.get(3), 3);935 try expectEqual(b.get(3), 3);
936}936}
937937
938test "std.hash_map ensureCapacity with existing elements" {938test "std.hash_map ensureCapacity with existing elements" {
...@@ -940,12 +940,12 @@ test "std.hash_map ensureCapacity with existing elements" {...@@ -940,12 +940,12 @@ test "std.hash_map ensureCapacity with existing elements" {
940 defer map.deinit();940 defer map.deinit();
941941
942 try map.put(0, 0);942 try map.put(0, 0);
943 expectEqual(map.count(), 1);943 try expectEqual(map.count(), 1);
944 expectEqual(map.capacity(), @TypeOf(map).Unmanaged.minimal_capacity);944 try expectEqual(map.capacity(), @TypeOf(map).Unmanaged.minimal_capacity);
945945
946 try map.ensureCapacity(65);946 try map.ensureCapacity(65);
947 expectEqual(map.count(), 1);947 try expectEqual(map.count(), 1);
948 expectEqual(map.capacity(), 128);948 try expectEqual(map.capacity(), 128);
949}949}
950950
951test "std.hash_map ensureCapacity satisfies max load factor" {951test "std.hash_map ensureCapacity satisfies max load factor" {
...@@ -953,7 +953,7 @@ test "std.hash_map ensureCapacity satisfies max load factor" {...@@ -953,7 +953,7 @@ test "std.hash_map ensureCapacity satisfies max load factor" {
953 defer map.deinit();953 defer map.deinit();
954954
955 try map.ensureCapacity(127);955 try map.ensureCapacity(127);
956 expectEqual(map.capacity(), 256);956 try expectEqual(map.capacity(), 256);
957}957}
958958
959test "std.hash_map remove" {959test "std.hash_map remove" {
...@@ -971,19 +971,19 @@ test "std.hash_map remove" {...@@ -971,19 +971,19 @@ test "std.hash_map remove" {
971 _ = map.remove(i);971 _ = map.remove(i);
972 }972 }
973 }973 }
974 expectEqual(map.count(), 10);974 try expectEqual(map.count(), 10);
975 var it = map.iterator();975 var it = map.iterator();
976 while (it.next()) |kv| {976 while (it.next()) |kv| {
977 expectEqual(kv.key, kv.value);977 try expectEqual(kv.key, kv.value);
978 expect(kv.key % 3 != 0);978 try expect(kv.key % 3 != 0);
979 }979 }
980980
981 i = 0;981 i = 0;
982 while (i < 16) : (i += 1) {982 while (i < 16) : (i += 1) {
983 if (i % 3 == 0) {983 if (i % 3 == 0) {
984 expect(!map.contains(i));984 try expect(!map.contains(i));
985 } else {985 } else {
986 expectEqual(map.get(i).?, i);986 try expectEqual(map.get(i).?, i);
987 }987 }
988 }988 }
989}989}
...@@ -1000,14 +1000,14 @@ test "std.hash_map reverse removes" {...@@ -1000,14 +1000,14 @@ test "std.hash_map reverse removes" {
1000 i = 16;1000 i = 16;
1001 while (i > 0) : (i -= 1) {1001 while (i > 0) : (i -= 1) {
1002 _ = map.remove(i - 1);1002 _ = map.remove(i - 1);
1003 expect(!map.contains(i - 1));1003 try expect(!map.contains(i - 1));
1004 var j: u32 = 0;1004 var j: u32 = 0;
1005 while (j < i - 1) : (j += 1) {1005 while (j < i - 1) : (j += 1) {
1006 expectEqual(map.get(j).?, j);1006 try expectEqual(map.get(j).?, j);
1007 }1007 }
1008 }1008 }
10091009
1010 expectEqual(map.count(), 0);1010 try expectEqual(map.count(), 0);
1011}1011}
10121012
1013test "std.hash_map multiple removes on same metadata" {1013test "std.hash_map multiple removes on same metadata" {
...@@ -1023,17 +1023,17 @@ test "std.hash_map multiple removes on same metadata" {...@@ -1023,17 +1023,17 @@ test "std.hash_map multiple removes on same metadata" {
1023 _ = map.remove(15);1023 _ = map.remove(15);
1024 _ = map.remove(14);1024 _ = map.remove(14);
1025 _ = map.remove(13);1025 _ = map.remove(13);
1026 expect(!map.contains(7));1026 try expect(!map.contains(7));
1027 expect(!map.contains(15));1027 try expect(!map.contains(15));
1028 expect(!map.contains(14));1028 try expect(!map.contains(14));
1029 expect(!map.contains(13));1029 try expect(!map.contains(13));
10301030
1031 i = 0;1031 i = 0;
1032 while (i < 13) : (i += 1) {1032 while (i < 13) : (i += 1) {
1033 if (i == 7) {1033 if (i == 7) {
1034 expect(!map.contains(i));1034 try expect(!map.contains(i));
1035 } else {1035 } else {
1036 expectEqual(map.get(i).?, i);1036 try expectEqual(map.get(i).?, i);
1037 }1037 }
1038 }1038 }
10391039
...@@ -1043,7 +1043,7 @@ test "std.hash_map multiple removes on same metadata" {...@@ -1043,7 +1043,7 @@ test "std.hash_map multiple removes on same metadata" {
1043 try map.put(7, 7);1043 try map.put(7, 7);
1044 i = 0;1044 i = 0;
1045 while (i < 16) : (i += 1) {1045 while (i < 16) : (i += 1) {
1046 expectEqual(map.get(i).?, i);1046 try expectEqual(map.get(i).?, i);
1047 }1047 }
1048}1048}
10491049
...@@ -1069,12 +1069,12 @@ test "std.hash_map put and remove loop in random order" {...@@ -1069,12 +1069,12 @@ test "std.hash_map put and remove loop in random order" {
1069 for (keys.items) |key| {1069 for (keys.items) |key| {
1070 try map.put(key, key);1070 try map.put(key, key);
1071 }1071 }
1072 expectEqual(map.count(), size);1072 try expectEqual(map.count(), size);
10731073
1074 for (keys.items) |key| {1074 for (keys.items) |key| {
1075 _ = map.remove(key);1075 _ = map.remove(key);
1076 }1076 }
1077 expectEqual(map.count(), 0);1077 try expectEqual(map.count(), 0);
1078 }1078 }
1079}1079}
10801080
...@@ -1118,7 +1118,7 @@ test "std.hash_map put" {...@@ -1118,7 +1118,7 @@ test "std.hash_map put" {
11181118
1119 i = 0;1119 i = 0;
1120 while (i < 16) : (i += 1) {1120 while (i < 16) : (i += 1) {
1121 expectEqual(map.get(i).?, i);1121 try expectEqual(map.get(i).?, i);
1122 }1122 }
11231123
1124 i = 0;1124 i = 0;
...@@ -1128,7 +1128,7 @@ test "std.hash_map put" {...@@ -1128,7 +1128,7 @@ test "std.hash_map put" {
11281128
1129 i = 0;1129 i = 0;
1130 while (i < 16) : (i += 1) {1130 while (i < 16) : (i += 1) {
1131 expectEqual(map.get(i).?, i * 16 + 1);1131 try expectEqual(map.get(i).?, i * 16 + 1);
1132 }1132 }
1133}1133}
11341134
...@@ -1147,7 +1147,7 @@ test "std.hash_map putAssumeCapacity" {...@@ -1147,7 +1147,7 @@ test "std.hash_map putAssumeCapacity" {
1147 while (i < 20) : (i += 1) {1147 while (i < 20) : (i += 1) {
1148 sum += map.get(i).?;1148 sum += map.get(i).?;
1149 }1149 }
1150 expectEqual(sum, 190);1150 try expectEqual(sum, 190);
11511151
1152 i = 0;1152 i = 0;
1153 while (i < 20) : (i += 1) {1153 while (i < 20) : (i += 1) {
...@@ -1159,7 +1159,7 @@ test "std.hash_map putAssumeCapacity" {...@@ -1159,7 +1159,7 @@ test "std.hash_map putAssumeCapacity" {
1159 while (i < 20) : (i += 1) {1159 while (i < 20) : (i += 1) {
1160 sum += map.get(i).?;1160 sum += map.get(i).?;
1161 }1161 }
1162 expectEqual(sum, 20);1162 try expectEqual(sum, 20);
1163}1163}
11641164
1165test "std.hash_map getOrPut" {1165test "std.hash_map getOrPut" {
...@@ -1182,49 +1182,49 @@ test "std.hash_map getOrPut" {...@@ -1182,49 +1182,49 @@ test "std.hash_map getOrPut" {
1182 sum += map.get(i).?;1182 sum += map.get(i).?;
1183 }1183 }
11841184
1185 expectEqual(sum, 30);1185 try expectEqual(sum, 30);
1186}1186}
11871187
1188test "std.hash_map basic hash map usage" {1188test "std.hash_map basic hash map usage" {
1189 var map = AutoHashMap(i32, i32).init(std.testing.allocator);1189 var map = AutoHashMap(i32, i32).init(std.testing.allocator);
1190 defer map.deinit();1190 defer map.deinit();
11911191
1192 testing.expect((try map.fetchPut(1, 11)) == null);1192 try testing.expect((try map.fetchPut(1, 11)) == null);
1193 testing.expect((try map.fetchPut(2, 22)) == null);1193 try testing.expect((try map.fetchPut(2, 22)) == null);
1194 testing.expect((try map.fetchPut(3, 33)) == null);1194 try testing.expect((try map.fetchPut(3, 33)) == null);
1195 testing.expect((try map.fetchPut(4, 44)) == null);1195 try testing.expect((try map.fetchPut(4, 44)) == null);
11961196
1197 try map.putNoClobber(5, 55);1197 try map.putNoClobber(5, 55);
1198 testing.expect((try map.fetchPut(5, 66)).?.value == 55);1198 try testing.expect((try map.fetchPut(5, 66)).?.value == 55);
1199 testing.expect((try map.fetchPut(5, 55)).?.value == 66);1199 try testing.expect((try map.fetchPut(5, 55)).?.value == 66);
12001200
1201 const gop1 = try map.getOrPut(5);1201 const gop1 = try map.getOrPut(5);
1202 testing.expect(gop1.found_existing == true);1202 try testing.expect(gop1.found_existing == true);
1203 testing.expect(gop1.entry.value == 55);1203 try testing.expect(gop1.entry.value == 55);
1204 gop1.entry.value = 77;1204 gop1.entry.value = 77;
1205 testing.expect(map.getEntry(5).?.value == 77);1205 try testing.expect(map.getEntry(5).?.value == 77);
12061206
1207 const gop2 = try map.getOrPut(99);1207 const gop2 = try map.getOrPut(99);
1208 testing.expect(gop2.found_existing == false);1208 try testing.expect(gop2.found_existing == false);
1209 gop2.entry.value = 42;1209 gop2.entry.value = 42;
1210 testing.expect(map.getEntry(99).?.value == 42);1210 try testing.expect(map.getEntry(99).?.value == 42);
12111211
1212 const gop3 = try map.getOrPutValue(5, 5);1212 const gop3 = try map.getOrPutValue(5, 5);
1213 testing.expect(gop3.value == 77);1213 try testing.expect(gop3.value == 77);
12141214
1215 const gop4 = try map.getOrPutValue(100, 41);1215 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));1218 try testing.expect(map.contains(2));
1219 testing.expect(map.getEntry(2).?.value == 22);1219 try testing.expect(map.getEntry(2).?.value == 22);
1220 testing.expect(map.get(2).? == 22);1220 try testing.expect(map.get(2).? == 22);
12211221
1222 const rmv1 = map.remove(2);1222 const rmv1 = map.remove(2);
1223 testing.expect(rmv1.?.key == 2);1223 try testing.expect(rmv1.?.key == 2);
1224 testing.expect(rmv1.?.value == 22);1224 try testing.expect(rmv1.?.value == 22);
1225 testing.expect(map.remove(2) == null);1225 try testing.expect(map.remove(2) == null);
1226 testing.expect(map.getEntry(2) == null);1226 try testing.expect(map.getEntry(2) == null);
1227 testing.expect(map.get(2) == null);1227 try testing.expect(map.get(2) == null);
12281228
1229 map.removeAssertDiscard(3);1229 map.removeAssertDiscard(3);
1230}1230}
...@@ -1243,6 +1243,6 @@ test "std.hash_map clone" {...@@ -1243,6 +1243,6 @@ test "std.hash_map clone" {
12431243
1244 i = 0;1244 i = 0;
1245 while (i < 10) : (i += 1) {1245 while (i < 10) : (i += 1) {
1246 testing.expect(copy.get(i).? == i * 10);1246 try testing.expect(copy.get(i).? == i * 10);
1247 }1247 }
1248}1248}
lib/std/heap.zig+43-43
...@@ -858,16 +858,16 @@ test "WasmPageAllocator internals" {...@@ -858,16 +858,16 @@ test "WasmPageAllocator internals" {
858 if (comptime std.Target.current.isWasm()) {858 if (comptime std.Target.current.isWasm()) {
859 const conventional_memsize = WasmPageAllocator.conventional.totalPages() * mem.page_size;859 const conventional_memsize = WasmPageAllocator.conventional.totalPages() * mem.page_size;
860 const initial = try page_allocator.alloc(u8, mem.page_size);860 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
863 var inplace = try page_allocator.realloc(initial, 1);863 var inplace = try page_allocator.realloc(initial, 1);
864 testing.expectEqual(initial.ptr, inplace.ptr);864 try testing.expectEqual(initial.ptr, inplace.ptr);
865 inplace = try page_allocator.realloc(inplace, 4);865 inplace = try page_allocator.realloc(inplace, 4);
866 testing.expectEqual(initial.ptr, inplace.ptr);866 try testing.expectEqual(initial.ptr, inplace.ptr);
867 page_allocator.free(inplace);867 page_allocator.free(inplace);
868868
869 const reuse = try page_allocator.alloc(u8, 1);869 const reuse = try page_allocator.alloc(u8, 1);
870 testing.expectEqual(initial.ptr, reuse.ptr);870 try testing.expectEqual(initial.ptr, reuse.ptr);
871 page_allocator.free(reuse);871 page_allocator.free(reuse);
872872
873 // This segment may span conventional and extended which has really complex rules so we're just ignoring it for now.873 // 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" {...@@ -875,18 +875,18 @@ test "WasmPageAllocator internals" {
875 page_allocator.free(padding);875 page_allocator.free(padding);
876876
877 const extended = try page_allocator.alloc(u8, conventional_memsize);877 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
880 const use_small = try page_allocator.alloc(u8, 1);880 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);
882 page_allocator.free(use_small);882 page_allocator.free(use_small);
883883
884 inplace = try page_allocator.realloc(extended, 1);884 inplace = try page_allocator.realloc(extended, 1);
885 testing.expectEqual(extended.ptr, inplace.ptr);885 try testing.expectEqual(extended.ptr, inplace.ptr);
886 page_allocator.free(inplace);886 page_allocator.free(inplace);
887887
888 const reuse_extended = try page_allocator.alloc(u8, conventional_memsize);888 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);
890 page_allocator.free(reuse_extended);890 page_allocator.free(reuse_extended);
891 }891 }
892}892}
...@@ -959,15 +959,15 @@ test "FixedBufferAllocator.reset" {...@@ -959,15 +959,15 @@ test "FixedBufferAllocator.reset" {
959959
960 var x = try fba.allocator.create(u64);960 var x = try fba.allocator.create(u64);
961 x.* = X;961 x.* = X;
962 testing.expectError(error.OutOfMemory, fba.allocator.create(u64));962 try testing.expectError(error.OutOfMemory, fba.allocator.create(u64));
963963
964 fba.reset();964 fba.reset();
965 var y = try fba.allocator.create(u64);965 var y = try fba.allocator.create(u64);
966 y.* = Y;966 y.* = Y;
967967
968 // we expect Y to have overwritten X.968 // we expect Y to have overwritten X.
969 testing.expect(x.* == y.*);969 try testing.expect(x.* == y.*);
970 testing.expect(y.* == Y);970 try testing.expect(y.* == Y);
971}971}
972972
973test "StackFallbackAllocator" {973test "StackFallbackAllocator" {
...@@ -987,11 +987,11 @@ test "FixedBufferAllocator Reuse memory on realloc" {...@@ -987,11 +987,11 @@ test "FixedBufferAllocator Reuse memory on realloc" {
987 var fixed_buffer_allocator = FixedBufferAllocator.init(small_fixed_buffer[0..]);987 var fixed_buffer_allocator = FixedBufferAllocator.init(small_fixed_buffer[0..]);
988988
989 var slice0 = try fixed_buffer_allocator.allocator.alloc(u8, 5);989 var slice0 = try fixed_buffer_allocator.allocator.alloc(u8, 5);
990 testing.expect(slice0.len == 5);990 try testing.expect(slice0.len == 5);
991 var slice1 = try fixed_buffer_allocator.allocator.realloc(slice0, 10);991 var slice1 = try fixed_buffer_allocator.allocator.realloc(slice0, 10);
992 testing.expect(slice1.ptr == slice0.ptr);992 try testing.expect(slice1.ptr == slice0.ptr);
993 testing.expect(slice1.len == 10);993 try testing.expect(slice1.len == 10);
994 testing.expectError(error.OutOfMemory, fixed_buffer_allocator.allocator.realloc(slice1, 11));994 try testing.expectError(error.OutOfMemory, fixed_buffer_allocator.allocator.realloc(slice1, 11));
995 }995 }
996 // check that we don't re-use the memory if it's not the most recent block996 // check that we don't re-use the memory if it's not the most recent block
997 {997 {
...@@ -1002,10 +1002,10 @@ test "FixedBufferAllocator Reuse memory on realloc" {...@@ -1002,10 +1002,10 @@ test "FixedBufferAllocator Reuse memory on realloc" {
1002 slice0[1] = 2;1002 slice0[1] = 2;
1003 var slice1 = try fixed_buffer_allocator.allocator.alloc(u8, 2);1003 var slice1 = try fixed_buffer_allocator.allocator.alloc(u8, 2);
1004 var slice2 = try fixed_buffer_allocator.allocator.realloc(slice0, 4);1004 var slice2 = try fixed_buffer_allocator.allocator.realloc(slice0, 4);
1005 testing.expect(slice0.ptr != slice2.ptr);1005 try testing.expect(slice0.ptr != slice2.ptr);
1006 testing.expect(slice1.ptr != slice2.ptr);1006 try testing.expect(slice1.ptr != slice2.ptr);
1007 testing.expect(slice2[0] == 1);1007 try testing.expect(slice2[0] == 1);
1008 testing.expect(slice2[1] == 2);1008 try testing.expect(slice2[1] == 2);
1009 }1009 }
1010}1010}
10111011
...@@ -1024,28 +1024,28 @@ pub fn testAllocator(base_allocator: *mem.Allocator) !void {...@@ -1024,28 +1024,28 @@ pub fn testAllocator(base_allocator: *mem.Allocator) !void {
1024 const allocator = &validationAllocator.allocator;1024 const allocator = &validationAllocator.allocator;
10251025
1026 var slice = try allocator.alloc(*i32, 100);1026 var slice = try allocator.alloc(*i32, 100);
1027 testing.expect(slice.len == 100);1027 try testing.expect(slice.len == 100);
1028 for (slice) |*item, i| {1028 for (slice) |*item, i| {
1029 item.* = try allocator.create(i32);1029 item.* = try allocator.create(i32);
1030 item.*.* = @intCast(i32, i);1030 item.*.* = @intCast(i32, i);
1031 }1031 }
10321032
1033 slice = try allocator.realloc(slice, 20000);1033 slice = try allocator.realloc(slice, 20000);
1034 testing.expect(slice.len == 20000);1034 try testing.expect(slice.len == 20000);
10351035
1036 for (slice[0..100]) |item, i| {1036 for (slice[0..100]) |item, i| {
1037 testing.expect(item.* == @intCast(i32, i));1037 try testing.expect(item.* == @intCast(i32, i));
1038 allocator.destroy(item);1038 allocator.destroy(item);
1039 }1039 }
10401040
1041 slice = allocator.shrink(slice, 50);1041 slice = allocator.shrink(slice, 50);
1042 testing.expect(slice.len == 50);1042 try testing.expect(slice.len == 50);
1043 slice = allocator.shrink(slice, 25);1043 slice = allocator.shrink(slice, 25);
1044 testing.expect(slice.len == 25);1044 try testing.expect(slice.len == 25);
1045 slice = allocator.shrink(slice, 0);1045 slice = allocator.shrink(slice, 0);
1046 testing.expect(slice.len == 0);1046 try testing.expect(slice.len == 0);
1047 slice = try allocator.realloc(slice, 10);1047 slice = try allocator.realloc(slice, 10);
1048 testing.expect(slice.len == 10);1048 try testing.expect(slice.len == 10);
10491049
1050 allocator.free(slice);1050 allocator.free(slice);
10511051
...@@ -1058,7 +1058,7 @@ pub fn testAllocator(base_allocator: *mem.Allocator) !void {...@@ -1058,7 +1058,7 @@ pub fn testAllocator(base_allocator: *mem.Allocator) !void {
1058 allocator.destroy(zero_bit_ptr);1058 allocator.destroy(zero_bit_ptr);
10591059
1060 const oversize = try allocator.allocAdvanced(u32, null, 5, .at_least);1060 const oversize = try allocator.allocAdvanced(u32, null, 5, .at_least);
1061 testing.expect(oversize.len >= 5);1061 try testing.expect(oversize.len >= 5);
1062 for (oversize) |*item| {1062 for (oversize) |*item| {
1063 item.* = 0xDEADBEEF;1063 item.* = 0xDEADBEEF;
1064 }1064 }
...@@ -1073,29 +1073,29 @@ pub fn testAllocatorAligned(base_allocator: *mem.Allocator) !void {...@@ -1073,29 +1073,29 @@ pub fn testAllocatorAligned(base_allocator: *mem.Allocator) !void {
1073 inline for ([_]u29{ 1, 2, 4, 8, 16, 32, 64 }) |alignment| {1073 inline for ([_]u29{ 1, 2, 4, 8, 16, 32, 64 }) |alignment| {
1074 // initial1074 // initial
1075 var slice = try allocator.alignedAlloc(u8, alignment, 10);1075 var slice = try allocator.alignedAlloc(u8, alignment, 10);
1076 testing.expect(slice.len == 10);1076 try testing.expect(slice.len == 10);
1077 // grow1077 // grow
1078 slice = try allocator.realloc(slice, 100);1078 slice = try allocator.realloc(slice, 100);
1079 testing.expect(slice.len == 100);1079 try testing.expect(slice.len == 100);
1080 // shrink1080 // shrink
1081 slice = allocator.shrink(slice, 10);1081 slice = allocator.shrink(slice, 10);
1082 testing.expect(slice.len == 10);1082 try testing.expect(slice.len == 10);
1083 // go to zero1083 // go to zero
1084 slice = allocator.shrink(slice, 0);1084 slice = allocator.shrink(slice, 0);
1085 testing.expect(slice.len == 0);1085 try testing.expect(slice.len == 0);
1086 // realloc from zero1086 // realloc from zero
1087 slice = try allocator.realloc(slice, 100);1087 slice = try allocator.realloc(slice, 100);
1088 testing.expect(slice.len == 100);1088 try testing.expect(slice.len == 100);
1089 // shrink with shrink1089 // shrink with shrink
1090 slice = allocator.shrink(slice, 10);1090 slice = allocator.shrink(slice, 10);
1091 testing.expect(slice.len == 10);1091 try testing.expect(slice.len == 10);
1092 // shrink to zero1092 // shrink to zero
1093 slice = allocator.shrink(slice, 0);1093 slice = allocator.shrink(slice, 0);
1094 testing.expect(slice.len == 0);1094 try testing.expect(slice.len == 0);
1095 }1095 }
1096}1096}
10971097
1098pub fn testAllocatorLargeAlignment(base_allocator: *mem.Allocator) mem.Allocator.Error!void {1098pub fn testAllocatorLargeAlignment(base_allocator: *mem.Allocator) !void {
1099 var validationAllocator = mem.validationWrap(base_allocator);1099 var validationAllocator = mem.validationWrap(base_allocator);
1100 const allocator = &validationAllocator.allocator;1100 const allocator = &validationAllocator.allocator;
11011101
...@@ -1110,24 +1110,24 @@ pub fn testAllocatorLargeAlignment(base_allocator: *mem.Allocator) mem.Allocator...@@ -1110,24 +1110,24 @@ pub fn testAllocatorLargeAlignment(base_allocator: *mem.Allocator) mem.Allocator
1110 _ = @shlWithOverflow(usize, ~@as(usize, 0), @as(USizeShift, @ctz(u29, large_align)), &align_mask);1110 _ = @shlWithOverflow(usize, ~@as(usize, 0), @as(USizeShift, @ctz(u29, large_align)), &align_mask);
11111111
1112 var slice = try allocator.alignedAlloc(u8, large_align, 500);1112 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
1115 slice = allocator.shrink(slice, 100);1115 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
1118 slice = try allocator.realloc(slice, 5000);1118 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
1121 slice = allocator.shrink(slice, 10);1121 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
1124 slice = try allocator.realloc(slice, 20000);1124 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
1127 allocator.free(slice);1127 allocator.free(slice);
1128}1128}
11291129
1130pub fn testAllocatorAlignedShrink(base_allocator: *mem.Allocator) mem.Allocator.Error!void {1130pub fn testAllocatorAlignedShrink(base_allocator: *mem.Allocator) !void {
1131 var validationAllocator = mem.validationWrap(base_allocator);1131 var validationAllocator = mem.validationWrap(base_allocator);
1132 const allocator = &validationAllocator.allocator;1132 const allocator = &validationAllocator.allocator;
11331133
...@@ -1155,8 +1155,8 @@ pub fn testAllocatorAlignedShrink(base_allocator: *mem.Allocator) mem.Allocator....@@ -1155,8 +1155,8 @@ pub fn testAllocatorAlignedShrink(base_allocator: *mem.Allocator) mem.Allocator.
11551155
1156 // realloc to a smaller size but with a larger alignment1156 // realloc to a smaller size but with a larger alignment
1157 slice = try allocator.reallocAdvanced(slice, mem.page_size * 32, alloc_size / 2, .exact);1157 slice = try allocator.reallocAdvanced(slice, mem.page_size * 32, alloc_size / 2, .exact);
1158 testing.expect(slice[0] == 0x12);1158 try testing.expect(slice[0] == 0x12);
1159 testing.expect(slice[60] == 0x34);1159 try testing.expect(slice[60] == 0x34);
1160}1160}
11611161
1162test "heap" {1162test "heap" {
lib/std/heap/general_purpose_allocator.zig+50-50
...@@ -697,7 +697,7 @@ const test_config = Config{};...@@ -697,7 +697,7 @@ const test_config = Config{};
697697
698test "small allocations - free in same order" {698test "small allocations - free in same order" {
699 var gpa = GeneralPurposeAllocator(test_config){};699 var gpa = GeneralPurposeAllocator(test_config){};
700 defer std.testing.expect(!gpa.deinit());700 defer std.testing.expect(!gpa.deinit()) catch @panic("leak");
701 const allocator = &gpa.allocator;701 const allocator = &gpa.allocator;
702702
703 var list = std.ArrayList(*u64).init(std.testing.allocator);703 var list = std.ArrayList(*u64).init(std.testing.allocator);
...@@ -716,7 +716,7 @@ test "small allocations - free in same order" {...@@ -716,7 +716,7 @@ test "small allocations - free in same order" {
716716
717test "small allocations - free in reverse order" {717test "small allocations - free in reverse order" {
718 var gpa = GeneralPurposeAllocator(test_config){};718 var gpa = GeneralPurposeAllocator(test_config){};
719 defer std.testing.expect(!gpa.deinit());719 defer std.testing.expect(!gpa.deinit()) catch @panic("leak");
720 const allocator = &gpa.allocator;720 const allocator = &gpa.allocator;
721721
722 var list = std.ArrayList(*u64).init(std.testing.allocator);722 var list = std.ArrayList(*u64).init(std.testing.allocator);
...@@ -735,7 +735,7 @@ test "small allocations - free in reverse order" {...@@ -735,7 +735,7 @@ test "small allocations - free in reverse order" {
735735
736test "large allocations" {736test "large allocations" {
737 var gpa = GeneralPurposeAllocator(test_config){};737 var gpa = GeneralPurposeAllocator(test_config){};
738 defer std.testing.expect(!gpa.deinit());738 defer std.testing.expect(!gpa.deinit()) catch @panic("leak");
739 const allocator = &gpa.allocator;739 const allocator = &gpa.allocator;
740740
741 const ptr1 = try allocator.alloc(u64, 42768);741 const ptr1 = try allocator.alloc(u64, 42768);
...@@ -748,7 +748,7 @@ test "large allocations" {...@@ -748,7 +748,7 @@ test "large allocations" {
748748
749test "realloc" {749test "realloc" {
750 var gpa = GeneralPurposeAllocator(test_config){};750 var gpa = GeneralPurposeAllocator(test_config){};
751 defer std.testing.expect(!gpa.deinit());751 defer std.testing.expect(!gpa.deinit()) catch @panic("leak");
752 const allocator = &gpa.allocator;752 const allocator = &gpa.allocator;
753753
754 var slice = try allocator.alignedAlloc(u8, @alignOf(u32), 1);754 var slice = try allocator.alignedAlloc(u8, @alignOf(u32), 1);
...@@ -758,19 +758,19 @@ test "realloc" {...@@ -758,19 +758,19 @@ test "realloc" {
758 // This reallocation should keep its pointer address.758 // This reallocation should keep its pointer address.
759 const old_slice = slice;759 const old_slice = slice;
760 slice = try allocator.realloc(slice, 2);760 slice = try allocator.realloc(slice, 2);
761 std.testing.expect(old_slice.ptr == slice.ptr);761 try std.testing.expect(old_slice.ptr == slice.ptr);
762 std.testing.expect(slice[0] == 0x12);762 try std.testing.expect(slice[0] == 0x12);
763 slice[1] = 0x34;763 slice[1] = 0x34;
764764
765 // This requires upgrading to a larger size class765 // This requires upgrading to a larger size class
766 slice = try allocator.realloc(slice, 17);766 slice = try allocator.realloc(slice, 17);
767 std.testing.expect(slice[0] == 0x12);767 try std.testing.expect(slice[0] == 0x12);
768 std.testing.expect(slice[1] == 0x34);768 try std.testing.expect(slice[1] == 0x34);
769}769}
770770
771test "shrink" {771test "shrink" {
772 var gpa = GeneralPurposeAllocator(test_config){};772 var gpa = GeneralPurposeAllocator(test_config){};
773 defer std.testing.expect(!gpa.deinit());773 defer std.testing.expect(!gpa.deinit()) catch @panic("leak");
774 const allocator = &gpa.allocator;774 const allocator = &gpa.allocator;
775775
776 var slice = try allocator.alloc(u8, 20);776 var slice = try allocator.alloc(u8, 20);
...@@ -781,19 +781,19 @@ test "shrink" {...@@ -781,19 +781,19 @@ test "shrink" {
781 slice = allocator.shrink(slice, 17);781 slice = allocator.shrink(slice, 17);
782782
783 for (slice) |b| {783 for (slice) |b| {
784 std.testing.expect(b == 0x11);784 try std.testing.expect(b == 0x11);
785 }785 }
786786
787 slice = allocator.shrink(slice, 16);787 slice = allocator.shrink(slice, 16);
788788
789 for (slice) |b| {789 for (slice) |b| {
790 std.testing.expect(b == 0x11);790 try std.testing.expect(b == 0x11);
791 }791 }
792}792}
793793
794test "large object - grow" {794test "large object - grow" {
795 var gpa = GeneralPurposeAllocator(test_config){};795 var gpa = GeneralPurposeAllocator(test_config){};
796 defer std.testing.expect(!gpa.deinit());796 defer std.testing.expect(!gpa.deinit()) catch @panic("leak");
797 const allocator = &gpa.allocator;797 const allocator = &gpa.allocator;
798798
799 var slice1 = try allocator.alloc(u8, page_size * 2 - 20);799 var slice1 = try allocator.alloc(u8, page_size * 2 - 20);
...@@ -801,17 +801,17 @@ test "large object - grow" {...@@ -801,17 +801,17 @@ test "large object - grow" {
801801
802 const old = slice1;802 const old = slice1;
803 slice1 = try allocator.realloc(slice1, page_size * 2 - 10);803 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
806 slice1 = try allocator.realloc(slice1, page_size * 2);806 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
809 slice1 = try allocator.realloc(slice1, page_size * 2 + 1);809 slice1 = try allocator.realloc(slice1, page_size * 2 + 1);
810}810}
811811
812test "realloc small object to large object" {812test "realloc small object to large object" {
813 var gpa = GeneralPurposeAllocator(test_config){};813 var gpa = GeneralPurposeAllocator(test_config){};
814 defer std.testing.expect(!gpa.deinit());814 defer std.testing.expect(!gpa.deinit()) catch @panic("leak");
815 const allocator = &gpa.allocator;815 const allocator = &gpa.allocator;
816816
817 var slice = try allocator.alloc(u8, 70);817 var slice = try allocator.alloc(u8, 70);
...@@ -822,13 +822,13 @@ test "realloc small object to large object" {...@@ -822,13 +822,13 @@ test "realloc small object to large object" {
822 // This requires upgrading to a large object822 // This requires upgrading to a large object
823 const large_object_size = page_size * 2 + 50;823 const large_object_size = page_size * 2 + 50;
824 slice = try allocator.realloc(slice, large_object_size);824 slice = try allocator.realloc(slice, large_object_size);
825 std.testing.expect(slice[0] == 0x12);825 try std.testing.expect(slice[0] == 0x12);
826 std.testing.expect(slice[60] == 0x34);826 try std.testing.expect(slice[60] == 0x34);
827}827}
828828
829test "shrink large object to large object" {829test "shrink large object to large object" {
830 var gpa = GeneralPurposeAllocator(test_config){};830 var gpa = GeneralPurposeAllocator(test_config){};
831 defer std.testing.expect(!gpa.deinit());831 defer std.testing.expect(!gpa.deinit()) catch @panic("leak");
832 const allocator = &gpa.allocator;832 const allocator = &gpa.allocator;
833833
834 var slice = try allocator.alloc(u8, page_size * 2 + 50);834 var slice = try allocator.alloc(u8, page_size * 2 + 50);
...@@ -837,21 +837,21 @@ test "shrink large object to large object" {...@@ -837,21 +837,21 @@ test "shrink large object to large object" {
837 slice[60] = 0x34;837 slice[60] = 0x34;
838838
839 slice = try allocator.resize(slice, page_size * 2 + 1);839 slice = try allocator.resize(slice, page_size * 2 + 1);
840 std.testing.expect(slice[0] == 0x12);840 try std.testing.expect(slice[0] == 0x12);
841 std.testing.expect(slice[60] == 0x34);841 try std.testing.expect(slice[60] == 0x34);
842842
843 slice = allocator.shrink(slice, page_size * 2 + 1);843 slice = allocator.shrink(slice, page_size * 2 + 1);
844 std.testing.expect(slice[0] == 0x12);844 try std.testing.expect(slice[0] == 0x12);
845 std.testing.expect(slice[60] == 0x34);845 try std.testing.expect(slice[60] == 0x34);
846846
847 slice = try allocator.realloc(slice, page_size * 2);847 slice = try allocator.realloc(slice, page_size * 2);
848 std.testing.expect(slice[0] == 0x12);848 try std.testing.expect(slice[0] == 0x12);
849 std.testing.expect(slice[60] == 0x34);849 try std.testing.expect(slice[60] == 0x34);
850}850}
851851
852test "shrink large object to large object with larger alignment" {852test "shrink large object to large object with larger alignment" {
853 var gpa = GeneralPurposeAllocator(test_config){};853 var gpa = GeneralPurposeAllocator(test_config){};
854 defer std.testing.expect(!gpa.deinit());854 defer std.testing.expect(!gpa.deinit()) catch @panic("leak");
855 const allocator = &gpa.allocator;855 const allocator = &gpa.allocator;
856856
857 var debug_buffer: [1000]u8 = undefined;857 var debug_buffer: [1000]u8 = undefined;
...@@ -880,13 +880,13 @@ test "shrink large object to large object with larger alignment" {...@@ -880,13 +880,13 @@ test "shrink large object to large object with larger alignment" {
880 slice[60] = 0x34;880 slice[60] = 0x34;
881881
882 slice = try allocator.reallocAdvanced(slice, big_alignment, alloc_size / 2, .exact);882 slice = try allocator.reallocAdvanced(slice, big_alignment, alloc_size / 2, .exact);
883 std.testing.expect(slice[0] == 0x12);883 try std.testing.expect(slice[0] == 0x12);
884 std.testing.expect(slice[60] == 0x34);884 try std.testing.expect(slice[60] == 0x34);
885}885}
886886
887test "realloc large object to small object" {887test "realloc large object to small object" {
888 var gpa = GeneralPurposeAllocator(test_config){};888 var gpa = GeneralPurposeAllocator(test_config){};
889 defer std.testing.expect(!gpa.deinit());889 defer std.testing.expect(!gpa.deinit()) catch @panic("leak");
890 const allocator = &gpa.allocator;890 const allocator = &gpa.allocator;
891891
892 var slice = try allocator.alloc(u8, page_size * 2 + 50);892 var slice = try allocator.alloc(u8, page_size * 2 + 50);
...@@ -895,8 +895,8 @@ test "realloc large object to small object" {...@@ -895,8 +895,8 @@ test "realloc large object to small object" {
895 slice[16] = 0x34;895 slice[16] = 0x34;
896896
897 slice = try allocator.realloc(slice, 19);897 slice = try allocator.realloc(slice, 19);
898 std.testing.expect(slice[0] == 0x12);898 try std.testing.expect(slice[0] == 0x12);
899 std.testing.expect(slice[16] == 0x34);899 try std.testing.expect(slice[16] == 0x34);
900}900}
901901
902test "overrideable mutexes" {902test "overrideable mutexes" {
...@@ -904,7 +904,7 @@ test "overrideable mutexes" {...@@ -904,7 +904,7 @@ test "overrideable mutexes" {
904 .backing_allocator = std.testing.allocator,904 .backing_allocator = std.testing.allocator,
905 .mutex = std.Thread.Mutex{},905 .mutex = std.Thread.Mutex{},
906 };906 };
907 defer std.testing.expect(!gpa.deinit());907 defer std.testing.expect(!gpa.deinit()) catch @panic("leak");
908 const allocator = &gpa.allocator;908 const allocator = &gpa.allocator;
909909
910 const ptr = try allocator.create(i32);910 const ptr = try allocator.create(i32);
...@@ -913,7 +913,7 @@ test "overrideable mutexes" {...@@ -913,7 +913,7 @@ test "overrideable mutexes" {
913913
914test "non-page-allocator backing allocator" {914test "non-page-allocator backing allocator" {
915 var gpa = GeneralPurposeAllocator(.{}){ .backing_allocator = std.testing.allocator };915 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");
917 const allocator = &gpa.allocator;917 const allocator = &gpa.allocator;
918918
919 const ptr = try allocator.create(i32);919 const ptr = try allocator.create(i32);
...@@ -922,7 +922,7 @@ test "non-page-allocator backing allocator" {...@@ -922,7 +922,7 @@ test "non-page-allocator backing allocator" {
922922
923test "realloc large object to larger alignment" {923test "realloc large object to larger alignment" {
924 var gpa = GeneralPurposeAllocator(test_config){};924 var gpa = GeneralPurposeAllocator(test_config){};
925 defer std.testing.expect(!gpa.deinit());925 defer std.testing.expect(!gpa.deinit()) catch @panic("leak");
926 const allocator = &gpa.allocator;926 const allocator = &gpa.allocator;
927927
928 var debug_buffer: [1000]u8 = undefined;928 var debug_buffer: [1000]u8 = undefined;
...@@ -948,22 +948,22 @@ test "realloc large object to larger alignment" {...@@ -948,22 +948,22 @@ test "realloc large object to larger alignment" {
948 slice[16] = 0x34;948 slice[16] = 0x34;
949949
950 slice = try allocator.reallocAdvanced(slice, 32, page_size * 2 + 100, .exact);950 slice = try allocator.reallocAdvanced(slice, 32, page_size * 2 + 100, .exact);
951 std.testing.expect(slice[0] == 0x12);951 try std.testing.expect(slice[0] == 0x12);
952 std.testing.expect(slice[16] == 0x34);952 try std.testing.expect(slice[16] == 0x34);
953953
954 slice = try allocator.reallocAdvanced(slice, 32, page_size * 2 + 25, .exact);954 slice = try allocator.reallocAdvanced(slice, 32, page_size * 2 + 25, .exact);
955 std.testing.expect(slice[0] == 0x12);955 try std.testing.expect(slice[0] == 0x12);
956 std.testing.expect(slice[16] == 0x34);956 try std.testing.expect(slice[16] == 0x34);
957957
958 slice = try allocator.reallocAdvanced(slice, big_alignment, page_size * 2 + 100, .exact);958 slice = try allocator.reallocAdvanced(slice, big_alignment, page_size * 2 + 100, .exact);
959 std.testing.expect(slice[0] == 0x12);959 try std.testing.expect(slice[0] == 0x12);
960 std.testing.expect(slice[16] == 0x34);960 try std.testing.expect(slice[16] == 0x34);
961}961}
962962
963test "large object shrinks to small but allocation fails during shrink" {963test "large object shrinks to small but allocation fails during shrink" {
964 var failing_allocator = std.testing.FailingAllocator.init(std.heap.page_allocator, 3);964 var failing_allocator = std.testing.FailingAllocator.init(std.heap.page_allocator, 3);
965 var gpa = GeneralPurposeAllocator(.{}){ .backing_allocator = &failing_allocator.allocator };965 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");
967 const allocator = &gpa.allocator;967 const allocator = &gpa.allocator;
968968
969 var slice = try allocator.alloc(u8, page_size * 2 + 50);969 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" {...@@ -974,13 +974,13 @@ test "large object shrinks to small but allocation fails during shrink" {
974 // Next allocation will fail in the backing allocator of the GeneralPurposeAllocator974 // Next allocation will fail in the backing allocator of the GeneralPurposeAllocator
975975
976 slice = allocator.shrink(slice, 4);976 slice = allocator.shrink(slice, 4);
977 std.testing.expect(slice[0] == 0x12);977 try std.testing.expect(slice[0] == 0x12);
978 std.testing.expect(slice[3] == 0x34);978 try std.testing.expect(slice[3] == 0x34);
979}979}
980980
981test "objects of size 1024 and 2048" {981test "objects of size 1024 and 2048" {
982 var gpa = GeneralPurposeAllocator(test_config){};982 var gpa = GeneralPurposeAllocator(test_config){};
983 defer std.testing.expect(!gpa.deinit());983 defer std.testing.expect(!gpa.deinit()) catch @panic("leak");
984 const allocator = &gpa.allocator;984 const allocator = &gpa.allocator;
985985
986 const slice = try allocator.alloc(u8, 1025);986 const slice = try allocator.alloc(u8, 1025);
...@@ -992,26 +992,26 @@ test "objects of size 1024 and 2048" {...@@ -992,26 +992,26 @@ test "objects of size 1024 and 2048" {
992992
993test "setting a memory cap" {993test "setting a memory cap" {
994 var gpa = GeneralPurposeAllocator(.{ .enable_memory_limit = true }){};994 var gpa = GeneralPurposeAllocator(.{ .enable_memory_limit = true }){};
995 defer std.testing.expect(!gpa.deinit());995 defer std.testing.expect(!gpa.deinit()) catch @panic("leak");
996 const allocator = &gpa.allocator;996 const allocator = &gpa.allocator;
997997
998 gpa.setRequestedMemoryLimit(1010);998 gpa.setRequestedMemoryLimit(1010);
999999
1000 const small = try allocator.create(i32);1000 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
1003 const big = try allocator.alloc(u8, 1000);1003 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
1008 allocator.destroy(small);1008 allocator.destroy(small);
1009 std.testing.expect(gpa.total_requested_bytes == 1000);1009 try std.testing.expect(gpa.total_requested_bytes == 1000);
10101010
1011 allocator.free(big);1011 allocator.free(big);
1012 std.testing.expect(gpa.total_requested_bytes == 0);1012 try std.testing.expect(gpa.total_requested_bytes == 0);
10131013
1014 const exact = try allocator.alloc(u8, 1010);1014 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);
1016 allocator.free(exact);1016 allocator.free(exact);
1017}1017}
lib/std/heap/logging_allocator.zig+3-3
...@@ -93,11 +93,11 @@ test "LoggingAllocator" {...@@ -93,11 +93,11 @@ test "LoggingAllocator" {
9393
94 var a = try allocator.alloc(u8, 10);94 var a = try allocator.alloc(u8, 10);
95 a = allocator.shrink(a, 5);95 a = allocator.shrink(a, 5);
96 std.testing.expect(a.len == 5);96 try std.testing.expect(a.len == 5);
97 std.testing.expectError(error.OutOfMemory, allocator.resize(a, 20));97 try std.testing.expectError(error.OutOfMemory, allocator.resize(a, 20));
98 allocator.free(a);98 allocator.free(a);
9999
100 std.testing.expectEqualSlices(u8,100 try std.testing.expectEqualSlices(u8,
101 \\alloc : 10 success!101 \\alloc : 10 success!
102 \\shrink: 10 to 5102 \\shrink: 10 to 5
103 \\expand: 5 to 20 failure!103 \\expand: 5 to 20 failure!
lib/std/io/bit_reader.zig+38-38
...@@ -185,64 +185,64 @@ test "api coverage" {...@@ -185,64 +185,64 @@ test "api coverage" {
185 const expect = testing.expect;185 const expect = testing.expect;
186 const expectError = testing.expectError;186 const expectError = testing.expectError;
187187
188 expect(1 == try bit_stream_be.readBits(u2, 1, &out_bits));188 try expect(1 == try bit_stream_be.readBits(u2, 1, &out_bits));
189 expect(out_bits == 1);189 try expect(out_bits == 1);
190 expect(2 == try bit_stream_be.readBits(u5, 2, &out_bits));190 try expect(2 == try bit_stream_be.readBits(u5, 2, &out_bits));
191 expect(out_bits == 2);191 try expect(out_bits == 2);
192 expect(3 == try bit_stream_be.readBits(u128, 3, &out_bits));192 try expect(3 == try bit_stream_be.readBits(u128, 3, &out_bits));
193 expect(out_bits == 3);193 try expect(out_bits == 3);
194 expect(4 == try bit_stream_be.readBits(u8, 4, &out_bits));194 try expect(4 == try bit_stream_be.readBits(u8, 4, &out_bits));
195 expect(out_bits == 4);195 try expect(out_bits == 4);
196 expect(5 == try bit_stream_be.readBits(u9, 5, &out_bits));196 try expect(5 == try bit_stream_be.readBits(u9, 5, &out_bits));
197 expect(out_bits == 5);197 try expect(out_bits == 5);
198 expect(1 == try bit_stream_be.readBits(u1, 1, &out_bits));198 try expect(1 == try bit_stream_be.readBits(u1, 1, &out_bits));
199 expect(out_bits == 1);199 try expect(out_bits == 1);
200200
201 mem_in_be.pos = 0;201 mem_in_be.pos = 0;
202 bit_stream_be.bit_count = 0;202 bit_stream_be.bit_count = 0;
203 expect(0b110011010000101 == try bit_stream_be.readBits(u15, 15, &out_bits));203 try expect(0b110011010000101 == try bit_stream_be.readBits(u15, 15, &out_bits));
204 expect(out_bits == 15);204 try expect(out_bits == 15);
205205
206 mem_in_be.pos = 0;206 mem_in_be.pos = 0;
207 bit_stream_be.bit_count = 0;207 bit_stream_be.bit_count = 0;
208 expect(0b1100110100001011 == try bit_stream_be.readBits(u16, 16, &out_bits));208 try expect(0b1100110100001011 == try bit_stream_be.readBits(u16, 16, &out_bits));
209 expect(out_bits == 16);209 try expect(out_bits == 16);
210210
211 _ = try bit_stream_be.readBits(u0, 0, &out_bits);211 _ = try bit_stream_be.readBits(u0, 0, &out_bits);
212212
213 expect(0 == try bit_stream_be.readBits(u1, 1, &out_bits));213 try expect(0 == try bit_stream_be.readBits(u1, 1, &out_bits));
214 expect(out_bits == 0);214 try expect(out_bits == 0);
215 expectError(error.EndOfStream, bit_stream_be.readBitsNoEof(u1, 1));215 try expectError(error.EndOfStream, bit_stream_be.readBitsNoEof(u1, 1));
216216
217 var mem_in_le = io.fixedBufferStream(&mem_le);217 var mem_in_le = io.fixedBufferStream(&mem_le);
218 var bit_stream_le = bitReader(.Little, mem_in_le.reader());218 var bit_stream_le = bitReader(.Little, mem_in_le.reader());
219219
220 expect(1 == try bit_stream_le.readBits(u2, 1, &out_bits));220 try expect(1 == try bit_stream_le.readBits(u2, 1, &out_bits));
221 expect(out_bits == 1);221 try expect(out_bits == 1);
222 expect(2 == try bit_stream_le.readBits(u5, 2, &out_bits));222 try expect(2 == try bit_stream_le.readBits(u5, 2, &out_bits));
223 expect(out_bits == 2);223 try expect(out_bits == 2);
224 expect(3 == try bit_stream_le.readBits(u128, 3, &out_bits));224 try expect(3 == try bit_stream_le.readBits(u128, 3, &out_bits));
225 expect(out_bits == 3);225 try expect(out_bits == 3);
226 expect(4 == try bit_stream_le.readBits(u8, 4, &out_bits));226 try expect(4 == try bit_stream_le.readBits(u8, 4, &out_bits));
227 expect(out_bits == 4);227 try expect(out_bits == 4);
228 expect(5 == try bit_stream_le.readBits(u9, 5, &out_bits));228 try expect(5 == try bit_stream_le.readBits(u9, 5, &out_bits));
229 expect(out_bits == 5);229 try expect(out_bits == 5);
230 expect(1 == try bit_stream_le.readBits(u1, 1, &out_bits));230 try expect(1 == try bit_stream_le.readBits(u1, 1, &out_bits));
231 expect(out_bits == 1);231 try expect(out_bits == 1);
232232
233 mem_in_le.pos = 0;233 mem_in_le.pos = 0;
234 bit_stream_le.bit_count = 0;234 bit_stream_le.bit_count = 0;
235 expect(0b001010100011101 == try bit_stream_le.readBits(u15, 15, &out_bits));235 try expect(0b001010100011101 == try bit_stream_le.readBits(u15, 15, &out_bits));
236 expect(out_bits == 15);236 try expect(out_bits == 15);
237237
238 mem_in_le.pos = 0;238 mem_in_le.pos = 0;
239 bit_stream_le.bit_count = 0;239 bit_stream_le.bit_count = 0;
240 expect(0b1001010100011101 == try bit_stream_le.readBits(u16, 16, &out_bits));240 try expect(0b1001010100011101 == try bit_stream_le.readBits(u16, 16, &out_bits));
241 expect(out_bits == 16);241 try expect(out_bits == 16);
242242
243 _ = try bit_stream_le.readBits(u0, 0, &out_bits);243 _ = try bit_stream_le.readBits(u0, 0, &out_bits);
244244
245 expect(0 == try bit_stream_le.readBits(u1, 1, &out_bits));245 try expect(0 == try bit_stream_le.readBits(u1, 1, &out_bits));
246 expect(out_bits == 0);246 try expect(out_bits == 0);
247 expectError(error.EndOfStream, bit_stream_le.readBitsNoEof(u1, 1));247 try expectError(error.EndOfStream, bit_stream_le.readBitsNoEof(u1, 1));
248}248}
lib/std/io/bit_writer.zig+6-6
...@@ -163,17 +163,17 @@ test "api coverage" {...@@ -163,17 +163,17 @@ test "api coverage" {
163 try bit_stream_be.writeBits(@as(u9, 5), 5);163 try bit_stream_be.writeBits(@as(u9, 5), 5);
164 try bit_stream_be.writeBits(@as(u1, 1), 1);164 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
168 mem_out_be.pos = 0;168 mem_out_be.pos = 0;
169169
170 try bit_stream_be.writeBits(@as(u15, 0b110011010000101), 15);170 try bit_stream_be.writeBits(@as(u15, 0b110011010000101), 15);
171 try bit_stream_be.flushBits();171 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
174 mem_out_be.pos = 0;174 mem_out_be.pos = 0;
175 try bit_stream_be.writeBits(@as(u32, 0b110011010000101), 16);175 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
178 try bit_stream_be.writeBits(@as(u0, 0), 0);178 try bit_stream_be.writeBits(@as(u0, 0), 0);
179179
...@@ -187,16 +187,16 @@ test "api coverage" {...@@ -187,16 +187,16 @@ test "api coverage" {
187 try bit_stream_le.writeBits(@as(u9, 5), 5);187 try bit_stream_le.writeBits(@as(u9, 5), 5);
188 try bit_stream_le.writeBits(@as(u1, 1), 1);188 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
192 mem_out_le.pos = 0;192 mem_out_le.pos = 0;
193 try bit_stream_le.writeBits(@as(u15, 0b110011010000101), 15);193 try bit_stream_le.writeBits(@as(u15, 0b110011010000101), 15);
194 try bit_stream_le.flushBits();194 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
197 mem_out_le.pos = 0;197 mem_out_le.pos = 0;
198 try bit_stream_le.writeBits(@as(u32, 0b1100110100001011), 16);198 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
201 try bit_stream_le.writeBits(@as(u0, 0), 0);201 try bit_stream_le.writeBits(@as(u0, 0), 0);
202}202}
lib/std/io/buffered_reader.zig+1-1
...@@ -87,5 +87,5 @@ test "io.BufferedReader" {...@@ -87,5 +87,5 @@ test "io.BufferedReader" {
8787
88 const res = try stream.readAllAlloc(testing.allocator, str.len + 1);88 const res = try stream.readAllAlloc(testing.allocator, str.len + 1);
89 defer testing.allocator.free(res);89 defer testing.allocator.free(res);
90 testing.expectEqualSlices(u8, str, res);90 try testing.expectEqualSlices(u8, str, res);
91}91}
lib/std/io/counting_reader.zig+2-2
...@@ -41,8 +41,8 @@ test "io.CountingReader" {...@@ -41,8 +41,8 @@ test "io.CountingReader" {
4141
42 //read and discard all bytes42 //read and discard all bytes
43 while (stream.readByte()) |_| {} else |err| {43 while (stream.readByte()) |_| {} else |err| {
44 testing.expect(err == error.EndOfStream);44 try testing.expect(err == error.EndOfStream);
45 }45 }
4646
47 testing.expect(counting_stream.bytes_read == bytes.len);47 try testing.expect(counting_stream.bytes_read == bytes.len);
48}48}
lib/std/io/counting_writer.zig+1-1
...@@ -40,5 +40,5 @@ test "io.CountingWriter" {...@@ -40,5 +40,5 @@ test "io.CountingWriter" {
4040
41 const bytes = "yay" ** 100;41 const bytes = "yay" ** 100;
42 stream.writeAll(bytes) catch unreachable;42 stream.writeAll(bytes) catch unreachable;
43 testing.expect(counting_stream.bytes_written == bytes.len);43 try testing.expect(counting_stream.bytes_written == bytes.len);
44}44}
lib/std/io/fixed_buffer_stream.zig+13-13
...@@ -134,7 +134,7 @@ test "FixedBufferStream output" {...@@ -134,7 +134,7 @@ test "FixedBufferStream output" {
134 const stream = fbs.writer();134 const stream = fbs.writer();
135135
136 try stream.print("{s}{s}!", .{ "Hello", "World" });136 try stream.print("{s}{s}!", .{ "Hello", "World" });
137 testing.expectEqualSlices(u8, "HelloWorld!", fbs.getWritten());137 try testing.expectEqualSlices(u8, "HelloWorld!", fbs.getWritten());
138}138}
139139
140test "FixedBufferStream output 2" {140test "FixedBufferStream output 2" {
...@@ -142,19 +142,19 @@ test "FixedBufferStream output 2" {...@@ -142,19 +142,19 @@ test "FixedBufferStream output 2" {
142 var fbs = fixedBufferStream(&buffer);142 var fbs = fixedBufferStream(&buffer);
143143
144 try fbs.writer().writeAll("Hello");144 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
147 try fbs.writer().writeAll("world");147 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("!"));150 try testing.expectError(error.NoSpaceLeft, fbs.writer().writeAll("!"));
151 testing.expect(mem.eql(u8, fbs.getWritten(), "Helloworld"));151 try testing.expect(mem.eql(u8, fbs.getWritten(), "Helloworld"));
152152
153 fbs.reset();153 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!"));156 try testing.expectError(error.NoSpaceLeft, fbs.writer().writeAll("Hello world!"));
157 testing.expect(mem.eql(u8, fbs.getWritten(), "Hello worl"));157 try testing.expect(mem.eql(u8, fbs.getWritten(), "Hello worl"));
158}158}
159159
160test "FixedBufferStream input" {160test "FixedBufferStream input" {
...@@ -164,13 +164,13 @@ test "FixedBufferStream input" {...@@ -164,13 +164,13 @@ test "FixedBufferStream input" {
164 var dest: [4]u8 = undefined;164 var dest: [4]u8 = undefined;
165165
166 var read = try fbs.reader().read(dest[0..4]);166 var read = try fbs.reader().read(dest[0..4]);
167 testing.expect(read == 4);167 try testing.expect(read == 4);
168 testing.expect(mem.eql(u8, dest[0..4], bytes[0..4]));168 try testing.expect(mem.eql(u8, dest[0..4], bytes[0..4]));
169169
170 read = try fbs.reader().read(dest[0..4]);170 read = try fbs.reader().read(dest[0..4]);
171 testing.expect(read == 3);171 try testing.expect(read == 3);
172 testing.expect(mem.eql(u8, dest[0..3], bytes[4..7]));172 try testing.expect(mem.eql(u8, dest[0..3], bytes[4..7]));
173173
174 read = try fbs.reader().read(dest[0..4]);174 read = try fbs.reader().read(dest[0..4]);
175 testing.expect(read == 0);175 try testing.expect(read == 0);
176}176}
lib/std/io/limited_reader.zig+4-4
...@@ -43,8 +43,8 @@ test "basic usage" {...@@ -43,8 +43,8 @@ test "basic usage" {
43 var early_stream = limitedReader(fbs.reader(), 3);43 var early_stream = limitedReader(fbs.reader(), 3);
4444
45 var buf: [5]u8 = undefined;45 var buf: [5]u8 = undefined;
46 testing.expectEqual(@as(usize, 3), try early_stream.reader().read(&buf));46 try testing.expectEqual(@as(usize, 3), try early_stream.reader().read(&buf));
47 testing.expectEqualSlices(u8, data[0..3], buf[0..3]);47 try testing.expectEqualSlices(u8, data[0..3], buf[0..3]);
48 testing.expectEqual(@as(usize, 0), try early_stream.reader().read(&buf));48 try testing.expectEqual(@as(usize, 0), try early_stream.reader().read(&buf));
49 testing.expectError(error.EndOfStream, early_stream.reader().skipBytes(10, .{}));49 try testing.expectError(error.EndOfStream, early_stream.reader().skipBytes(10, .{}));
50}50}
lib/std/io/multi_writer.zig+2-2
...@@ -52,6 +52,6 @@ test "MultiWriter" {...@@ -52,6 +52,6 @@ test "MultiWriter" {
52 var fbs2 = io.fixedBufferStream(&buf2);52 var fbs2 = io.fixedBufferStream(&buf2);
53 var stream = multiWriter(.{ fbs1.writer(), fbs2.writer() });53 var stream = multiWriter(.{ fbs1.writer(), fbs2.writer() });
54 try stream.writer().print("HI", .{});54 try stream.writer().print("HI", .{});
55 testing.expectEqualSlices(u8, "HI", fbs1.getWritten());55 try testing.expectEqualSlices(u8, "HI", fbs1.getWritten());
56 testing.expectEqualSlices(u8, "HI", fbs2.getWritten());56 try testing.expectEqualSlices(u8, "HI", fbs2.getWritten());
57}57}
lib/std/io/peek_stream.zig+11-11
...@@ -94,24 +94,24 @@ test "PeekStream" {...@@ -94,24 +94,24 @@ test "PeekStream" {
94 try ps.putBackByte(10);94 try ps.putBackByte(10);
9595
96 var read = try ps.reader().read(dest[0..4]);96 var read = try ps.reader().read(dest[0..4]);
97 testing.expect(read == 4);97 try testing.expect(read == 4);
98 testing.expect(dest[0] == 10);98 try testing.expect(dest[0] == 10);
99 testing.expect(dest[1] == 9);99 try testing.expect(dest[1] == 9);
100 testing.expect(mem.eql(u8, dest[2..4], bytes[0..2]));100 try testing.expect(mem.eql(u8, dest[2..4], bytes[0..2]));
101101
102 read = try ps.reader().read(dest[0..4]);102 read = try ps.reader().read(dest[0..4]);
103 testing.expect(read == 4);103 try testing.expect(read == 4);
104 testing.expect(mem.eql(u8, dest[0..4], bytes[2..6]));104 try testing.expect(mem.eql(u8, dest[0..4], bytes[2..6]));
105105
106 read = try ps.reader().read(dest[0..4]);106 read = try ps.reader().read(dest[0..4]);
107 testing.expect(read == 2);107 try testing.expect(read == 2);
108 testing.expect(mem.eql(u8, dest[0..2], bytes[6..8]));108 try testing.expect(mem.eql(u8, dest[0..2], bytes[6..8]));
109109
110 try ps.putBackByte(11);110 try ps.putBackByte(11);
111 try ps.putBackByte(12);111 try ps.putBackByte(12);
112112
113 read = try ps.reader().read(dest[0..4]);113 read = try ps.reader().read(dest[0..4]);
114 testing.expect(read == 2);114 try testing.expect(read == 2);
115 testing.expect(dest[0] == 12);115 try testing.expect(dest[0] == 12);
116 testing.expect(dest[1] == 11);116 try testing.expect(dest[1] == 11);
117}117}
lib/std/io/reader.zig+7-7
...@@ -329,26 +329,26 @@ pub fn Reader(...@@ -329,26 +329,26 @@ pub fn Reader(
329test "Reader" {329test "Reader" {
330 var buf = "a\x02".*;330 var buf = "a\x02".*;
331 const reader = std.io.fixedBufferStream(&buf).reader();331 const reader = std.io.fixedBufferStream(&buf).reader();
332 testing.expect((try reader.readByte()) == 'a');332 try testing.expect((try reader.readByte()) == 'a');
333 testing.expect((try reader.readEnum(enum(u8) {333 try testing.expect((try reader.readEnum(enum(u8) {
334 a = 0,334 a = 0,
335 b = 99,335 b = 99,
336 c = 2,336 c = 2,
337 d = 3,337 d = 3,
338 }, undefined)) == .c);338 }, undefined)) == .c);
339 testing.expectError(error.EndOfStream, reader.readByte());339 try testing.expectError(error.EndOfStream, reader.readByte());
340}340}
341341
342test "Reader.isBytes" {342test "Reader.isBytes" {
343 const reader = std.io.fixedBufferStream("foobar").reader();343 const reader = std.io.fixedBufferStream("foobar").reader();
344 testing.expectEqual(true, try reader.isBytes("foo"));344 try testing.expectEqual(true, try reader.isBytes("foo"));
345 testing.expectEqual(false, try reader.isBytes("qux"));345 try testing.expectEqual(false, try reader.isBytes("qux"));
346}346}
347347
348test "Reader.skipBytes" {348test "Reader.skipBytes" {
349 const reader = std.io.fixedBufferStream("foobar").reader();349 const reader = std.io.fixedBufferStream("foobar").reader();
350 try reader.skipBytes(3, .{});350 try reader.skipBytes(3, .{});
351 testing.expect(try reader.isBytes("bar"));351 try testing.expect(try reader.isBytes("bar"));
352 try reader.skipBytes(0, .{});352 try reader.skipBytes(0, .{});
353 testing.expectError(error.EndOfStream, reader.skipBytes(1, .{}));353 try testing.expectError(error.EndOfStream, reader.skipBytes(1, .{}));
354}354}
lib/std/io/test.zig+33-33
...@@ -40,7 +40,7 @@ test "write a file, read it, then delete it" {...@@ -40,7 +40,7 @@ test "write a file, read it, then delete it" {
4040
41 {41 {
42 // Make sure the exclusive flag is honored.42 // 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 }));
44 }44 }
4545
46 {46 {
...@@ -49,16 +49,16 @@ test "write a file, read it, then delete it" {...@@ -49,16 +49,16 @@ test "write a file, read it, then delete it" {
4949
50 const file_size = try file.getEndPos();50 const file_size = try file.getEndPos();
51 const expected_file_size: u64 = "begin".len + data.len + "end".len;51 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
54 var buf_stream = io.bufferedReader(file.reader());54 var buf_stream = io.bufferedReader(file.reader());
55 const st = buf_stream.reader();55 const st = buf_stream.reader();
56 const contents = try st.readAllAlloc(std.testing.allocator, 2 * 1024);56 const contents = try st.readAllAlloc(std.testing.allocator, 2 * 1024);
57 defer std.testing.allocator.free(contents);57 defer std.testing.allocator.free(contents);
5858
59 expect(mem.eql(u8, contents[0.."begin".len], "begin"));59 try expect(mem.eql(u8, contents[0.."begin".len], "begin"));
60 expect(mem.eql(u8, contents["begin".len .. contents.len - "end".len], &data));60 try expect(mem.eql(u8, contents["begin".len .. contents.len - "end".len], &data));
61 expect(mem.eql(u8, contents[contents.len - "end".len ..], "end"));61 try expect(mem.eql(u8, contents[contents.len - "end".len ..], "end"));
62 }62 }
63 try tmp.dir.deleteFile(tmp_file_name);63 try tmp.dir.deleteFile(tmp_file_name);
64}64}
...@@ -90,20 +90,20 @@ test "BitStreams with File Stream" {...@@ -90,20 +90,20 @@ test "BitStreams with File Stream" {
9090
91 var out_bits: usize = undefined;91 var out_bits: usize = undefined;
9292
93 expect(1 == try bit_stream.readBits(u2, 1, &out_bits));93 try expect(1 == try bit_stream.readBits(u2, 1, &out_bits));
94 expect(out_bits == 1);94 try expect(out_bits == 1);
95 expect(2 == try bit_stream.readBits(u5, 2, &out_bits));95 try expect(2 == try bit_stream.readBits(u5, 2, &out_bits));
96 expect(out_bits == 2);96 try expect(out_bits == 2);
97 expect(3 == try bit_stream.readBits(u128, 3, &out_bits));97 try expect(3 == try bit_stream.readBits(u128, 3, &out_bits));
98 expect(out_bits == 3);98 try expect(out_bits == 3);
99 expect(4 == try bit_stream.readBits(u8, 4, &out_bits));99 try expect(4 == try bit_stream.readBits(u8, 4, &out_bits));
100 expect(out_bits == 4);100 try expect(out_bits == 4);
101 expect(5 == try bit_stream.readBits(u9, 5, &out_bits));101 try expect(5 == try bit_stream.readBits(u9, 5, &out_bits));
102 expect(out_bits == 5);102 try expect(out_bits == 5);
103 expect(1 == try bit_stream.readBits(u1, 1, &out_bits));103 try expect(1 == try bit_stream.readBits(u1, 1, &out_bits));
104 expect(out_bits == 1);104 try expect(out_bits == 1);
105105
106 expectError(error.EndOfStream, bit_stream.readBitsNoEof(u1, 1));106 try expectError(error.EndOfStream, bit_stream.readBitsNoEof(u1, 1));
107 }107 }
108 try tmp.dir.deleteFile(tmp_file_name);108 try tmp.dir.deleteFile(tmp_file_name);
109}109}
...@@ -123,16 +123,16 @@ test "File seek ops" {...@@ -123,16 +123,16 @@ test "File seek ops" {
123123
124 // Seek to the end124 // Seek to the end
125 try file.seekFromEnd(0);125 try file.seekFromEnd(0);
126 expect((try file.getPos()) == try file.getEndPos());126 try expect((try file.getPos()) == try file.getEndPos());
127 // Negative delta127 // Negative delta
128 try file.seekBy(-4096);128 try file.seekBy(-4096);
129 expect((try file.getPos()) == 4096);129 try expect((try file.getPos()) == 4096);
130 // Positive delta130 // Positive delta
131 try file.seekBy(10);131 try file.seekBy(10);
132 expect((try file.getPos()) == 4106);132 try expect((try file.getPos()) == 4106);
133 // Absolute position133 // Absolute position
134 try file.seekTo(1234);134 try file.seekTo(1234);
135 expect((try file.getPos()) == 1234);135 try expect((try file.getPos()) == 1234);
136}136}
137137
138test "setEndPos" {138test "setEndPos" {
...@@ -147,18 +147,18 @@ test "setEndPos" {...@@ -147,18 +147,18 @@ test "setEndPos" {
147 }147 }
148148
149 // Verify that the file size changes and the file offset is not moved149 // Verify that the file size changes and the file offset is not moved
150 std.testing.expect((try file.getEndPos()) == 0);150 try std.testing.expect((try file.getEndPos()) == 0);
151 std.testing.expect((try file.getPos()) == 0);151 try std.testing.expect((try file.getPos()) == 0);
152 try file.setEndPos(8192);152 try file.setEndPos(8192);
153 std.testing.expect((try file.getEndPos()) == 8192);153 try std.testing.expect((try file.getEndPos()) == 8192);
154 std.testing.expect((try file.getPos()) == 0);154 try std.testing.expect((try file.getPos()) == 0);
155 try file.seekTo(100);155 try file.seekTo(100);
156 try file.setEndPos(4096);156 try file.setEndPos(4096);
157 std.testing.expect((try file.getEndPos()) == 4096);157 try std.testing.expect((try file.getEndPos()) == 4096);
158 std.testing.expect((try file.getPos()) == 100);158 try std.testing.expect((try file.getPos()) == 100);
159 try file.setEndPos(0);159 try file.setEndPos(0);
160 std.testing.expect((try file.getEndPos()) == 0);160 try std.testing.expect((try file.getEndPos()) == 0);
161 std.testing.expect((try file.getPos()) == 100);161 try std.testing.expect((try file.getPos()) == 100);
162}162}
163163
164test "updateTimes" {164test "updateTimes" {
...@@ -178,6 +178,6 @@ test "updateTimes" {...@@ -178,6 +178,6 @@ test "updateTimes" {
178 stat_old.mtime - 5 * std.time.ns_per_s,178 stat_old.mtime - 5 * std.time.ns_per_s,
179 );179 );
180 var stat_new = try file.stat();180 var stat_new = try file.stat();
181 expect(stat_new.atime < stat_old.atime);181 try expect(stat_new.atime < stat_old.atime);
182 expect(stat_new.mtime < stat_old.mtime);182 try expect(stat_new.mtime < stat_old.mtime);
183}183}
lib/std/json.zig+139-139
...@@ -79,18 +79,18 @@ fn encodesTo(decoded: []const u8, encoded: []const u8) bool {...@@ -79,18 +79,18 @@ fn encodesTo(decoded: []const u8, encoded: []const u8) bool {
7979
80test "encodesTo" {80test "encodesTo" {
81 // same81 // same
82 testing.expectEqual(true, encodesTo("false", "false"));82 try testing.expectEqual(true, encodesTo("false", "false"));
83 // totally different83 // totally different
84 testing.expectEqual(false, encodesTo("false", "true"));84 try testing.expectEqual(false, encodesTo("false", "true"));
85 // different lengths85 // different lengths
86 testing.expectEqual(false, encodesTo("false", "other"));86 try testing.expectEqual(false, encodesTo("false", "other"));
87 // with escape87 // with escape
88 testing.expectEqual(true, encodesTo("\\", "\\\\"));88 try testing.expectEqual(true, encodesTo("\\", "\\\\"));
89 testing.expectEqual(true, encodesTo("with\nescape", "with\\nescape"));89 try testing.expectEqual(true, encodesTo("with\nescape", "with\\nescape"));
90 // with unicode90 // with unicode
91 testing.expectEqual(true, encodesTo("ą", "\\u0105"));91 try testing.expectEqual(true, encodesTo("ą", "\\u0105"));
92 testing.expectEqual(true, encodesTo("😂", "\\ud83d\\ude02"));92 try testing.expectEqual(true, encodesTo("😂", "\\ud83d\\ude02"));
93 testing.expectEqual(true, encodesTo("withąunicode😂", "with\\u0105unicode\\ud83d\\ude02"));93 try testing.expectEqual(true, encodesTo("withąunicode😂", "with\\u0105unicode\\ud83d\\ude02"));
94}94}
9595
96/// A single token slice into the parent string.96/// A single token slice into the parent string.
...@@ -1138,9 +1138,9 @@ pub const TokenStream = struct {...@@ -1138,9 +1138,9 @@ pub const TokenStream = struct {
1138 }1138 }
1139};1139};
11401140
1141fn checkNext(p: *TokenStream, id: std.meta.Tag(Token)) void {1141fn checkNext(p: *TokenStream, id: std.meta.Tag(Token)) !void {
1142 const token = (p.next() catch unreachable).?;1142 const token = (p.next() catch unreachable).?;
1143 debug.assert(std.meta.activeTag(token) == id);1143 try testing.expect(std.meta.activeTag(token) == id);
1144}1144}
11451145
1146test "json.token" {1146test "json.token" {
...@@ -1163,46 +1163,46 @@ test "json.token" {...@@ -1163,46 +1163,46 @@ test "json.token" {
11631163
1164 var p = TokenStream.init(s);1164 var p = TokenStream.init(s);
11651165
1166 checkNext(&p, .ObjectBegin);1166 try checkNext(&p, .ObjectBegin);
1167 checkNext(&p, .String); // Image1167 try checkNext(&p, .String); // Image
1168 checkNext(&p, .ObjectBegin);1168 try checkNext(&p, .ObjectBegin);
1169 checkNext(&p, .String); // Width1169 try checkNext(&p, .String); // Width
1170 checkNext(&p, .Number);1170 try checkNext(&p, .Number);
1171 checkNext(&p, .String); // Height1171 try checkNext(&p, .String); // Height
1172 checkNext(&p, .Number);1172 try checkNext(&p, .Number);
1173 checkNext(&p, .String); // Title1173 try checkNext(&p, .String); // Title
1174 checkNext(&p, .String);1174 try checkNext(&p, .String);
1175 checkNext(&p, .String); // Thumbnail1175 try checkNext(&p, .String); // Thumbnail
1176 checkNext(&p, .ObjectBegin);1176 try checkNext(&p, .ObjectBegin);
1177 checkNext(&p, .String); // Url1177 try checkNext(&p, .String); // Url
1178 checkNext(&p, .String);1178 try checkNext(&p, .String);
1179 checkNext(&p, .String); // Height1179 try checkNext(&p, .String); // Height
1180 checkNext(&p, .Number);1180 try checkNext(&p, .Number);
1181 checkNext(&p, .String); // Width1181 try checkNext(&p, .String); // Width
1182 checkNext(&p, .Number);1182 try checkNext(&p, .Number);
1183 checkNext(&p, .ObjectEnd);1183 try checkNext(&p, .ObjectEnd);
1184 checkNext(&p, .String); // Animated1184 try checkNext(&p, .String); // Animated
1185 checkNext(&p, .False);1185 try checkNext(&p, .False);
1186 checkNext(&p, .String); // IDs1186 try checkNext(&p, .String); // IDs
1187 checkNext(&p, .ArrayBegin);1187 try checkNext(&p, .ArrayBegin);
1188 checkNext(&p, .Number);1188 try checkNext(&p, .Number);
1189 checkNext(&p, .Number);1189 try checkNext(&p, .Number);
1190 checkNext(&p, .Number);1190 try checkNext(&p, .Number);
1191 checkNext(&p, .Number);1191 try checkNext(&p, .Number);
1192 checkNext(&p, .ArrayEnd);1192 try checkNext(&p, .ArrayEnd);
1193 checkNext(&p, .ObjectEnd);1193 try checkNext(&p, .ObjectEnd);
1194 checkNext(&p, .ObjectEnd);1194 try checkNext(&p, .ObjectEnd);
11951195
1196 testing.expect((try p.next()) == null);1196 try testing.expect((try p.next()) == null);
1197}1197}
11981198
1199test "json.token mismatched close" {1199test "json.token mismatched close" {
1200 var p = TokenStream.init("[102, 111, 111 }");1200 var p = TokenStream.init("[102, 111, 111 }");
1201 checkNext(&p, .ArrayBegin);1201 try checkNext(&p, .ArrayBegin);
1202 checkNext(&p, .Number);1202 try checkNext(&p, .Number);
1203 checkNext(&p, .Number);1203 try checkNext(&p, .Number);
1204 checkNext(&p, .Number);1204 try checkNext(&p, .Number);
1205 testing.expectError(error.UnexpectedClosingBrace, p.next());1205 try testing.expectError(error.UnexpectedClosingBrace, p.next());
1206}1206}
12071207
1208/// Validate a JSON string. This does not limit number precision so a decoder may not necessarily1208/// 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 {...@@ -1223,12 +1223,12 @@ pub fn validate(s: []const u8) bool {
1223}1223}
12241224
1225test "json.validate" {1225test "json.validate" {
1226 testing.expectEqual(true, validate("{}"));1226 try testing.expectEqual(true, validate("{}"));
1227 testing.expectEqual(true, validate("[]"));1227 try testing.expectEqual(true, validate("[]"));
1228 testing.expectEqual(true, validate("[{[[[[{}]]]]}]"));1228 try testing.expectEqual(true, validate("[{[[[[{}]]]]}]"));
1229 testing.expectEqual(false, validate("{]"));1229 try testing.expectEqual(false, validate("{]"));
1230 testing.expectEqual(false, validate("[}"));1230 try testing.expectEqual(false, validate("[}"));
1231 testing.expectEqual(false, validate("{{{{[]}}}]"));1231 try testing.expectEqual(false, validate("{{{{[]}}}]"));
1232}1232}
12331233
1234const Allocator = std.mem.Allocator;1234const Allocator = std.mem.Allocator;
...@@ -1326,37 +1326,37 @@ test "Value.jsonStringify" {...@@ -1326,37 +1326,37 @@ test "Value.jsonStringify" {
1326 var buffer: [10]u8 = undefined;1326 var buffer: [10]u8 = undefined;
1327 var fbs = std.io.fixedBufferStream(&buffer);1327 var fbs = std.io.fixedBufferStream(&buffer);
1328 try @as(Value, .Null).jsonStringify(.{}, fbs.writer());1328 try @as(Value, .Null).jsonStringify(.{}, fbs.writer());
1329 testing.expectEqualSlices(u8, fbs.getWritten(), "null");1329 try testing.expectEqualSlices(u8, fbs.getWritten(), "null");
1330 }1330 }
1331 {1331 {
1332 var buffer: [10]u8 = undefined;1332 var buffer: [10]u8 = undefined;
1333 var fbs = std.io.fixedBufferStream(&buffer);1333 var fbs = std.io.fixedBufferStream(&buffer);
1334 try (Value{ .Bool = true }).jsonStringify(.{}, fbs.writer());1334 try (Value{ .Bool = true }).jsonStringify(.{}, fbs.writer());
1335 testing.expectEqualSlices(u8, fbs.getWritten(), "true");1335 try testing.expectEqualSlices(u8, fbs.getWritten(), "true");
1336 }1336 }
1337 {1337 {
1338 var buffer: [10]u8 = undefined;1338 var buffer: [10]u8 = undefined;
1339 var fbs = std.io.fixedBufferStream(&buffer);1339 var fbs = std.io.fixedBufferStream(&buffer);
1340 try (Value{ .Integer = 42 }).jsonStringify(.{}, fbs.writer());1340 try (Value{ .Integer = 42 }).jsonStringify(.{}, fbs.writer());
1341 testing.expectEqualSlices(u8, fbs.getWritten(), "42");1341 try testing.expectEqualSlices(u8, fbs.getWritten(), "42");
1342 }1342 }
1343 {1343 {
1344 var buffer: [10]u8 = undefined;1344 var buffer: [10]u8 = undefined;
1345 var fbs = std.io.fixedBufferStream(&buffer);1345 var fbs = std.io.fixedBufferStream(&buffer);
1346 try (Value{ .NumberString = "43" }).jsonStringify(.{}, fbs.writer());1346 try (Value{ .NumberString = "43" }).jsonStringify(.{}, fbs.writer());
1347 testing.expectEqualSlices(u8, fbs.getWritten(), "43");1347 try testing.expectEqualSlices(u8, fbs.getWritten(), "43");
1348 }1348 }
1349 {1349 {
1350 var buffer: [10]u8 = undefined;1350 var buffer: [10]u8 = undefined;
1351 var fbs = std.io.fixedBufferStream(&buffer);1351 var fbs = std.io.fixedBufferStream(&buffer);
1352 try (Value{ .Float = 42 }).jsonStringify(.{}, fbs.writer());1352 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");
1354 }1354 }
1355 {1355 {
1356 var buffer: [10]u8 = undefined;1356 var buffer: [10]u8 = undefined;
1357 var fbs = std.io.fixedBufferStream(&buffer);1357 var fbs = std.io.fixedBufferStream(&buffer);
1358 try (Value{ .String = "weeee" }).jsonStringify(.{}, fbs.writer());1358 try (Value{ .String = "weeee" }).jsonStringify(.{}, fbs.writer());
1359 testing.expectEqualSlices(u8, fbs.getWritten(), "\"weeee\"");1359 try testing.expectEqualSlices(u8, fbs.getWritten(), "\"weeee\"");
1360 }1360 }
1361 {1361 {
1362 var buffer: [10]u8 = undefined;1362 var buffer: [10]u8 = undefined;
...@@ -1369,7 +1369,7 @@ test "Value.jsonStringify" {...@@ -1369,7 +1369,7 @@ test "Value.jsonStringify" {
1369 try (Value{1369 try (Value{
1370 .Array = Array.fromOwnedSlice(undefined, &vals),1370 .Array = Array.fromOwnedSlice(undefined, &vals),
1371 }).jsonStringify(.{}, fbs.writer());1371 }).jsonStringify(.{}, fbs.writer());
1372 testing.expectEqualSlices(u8, fbs.getWritten(), "[1,2,3]");1372 try testing.expectEqualSlices(u8, fbs.getWritten(), "[1,2,3]");
1373 }1373 }
1374 {1374 {
1375 var buffer: [10]u8 = undefined;1375 var buffer: [10]u8 = undefined;
...@@ -1378,7 +1378,7 @@ test "Value.jsonStringify" {...@@ -1378,7 +1378,7 @@ test "Value.jsonStringify" {
1378 defer obj.deinit();1378 defer obj.deinit();
1379 try obj.putNoClobber("a", .{ .String = "b" });1379 try obj.putNoClobber("a", .{ .String = "b" });
1380 try (Value{ .Object = obj }).jsonStringify(.{}, fbs.writer());1380 try (Value{ .Object = obj }).jsonStringify(.{}, fbs.writer());
1381 testing.expectEqualSlices(u8, fbs.getWritten(), "{\"a\":\"b\"}");1381 try testing.expectEqualSlices(u8, fbs.getWritten(), "{\"a\":\"b\"}");
1382 }1382 }
1383}1383}
13841384
...@@ -1751,17 +1751,17 @@ pub fn parseFree(comptime T: type, value: T, options: ParseOptions) void {...@@ -1751,17 +1751,17 @@ pub fn parseFree(comptime T: type, value: T, options: ParseOptions) void {
1751}1751}
17521752
1753test "parse" {1753test "parse" {
1754 testing.expectEqual(false, try parse(bool, &TokenStream.init("false"), ParseOptions{}));1754 try testing.expectEqual(false, try parse(bool, &TokenStream.init("false"), ParseOptions{}));
1755 testing.expectEqual(true, try parse(bool, &TokenStream.init("true"), ParseOptions{}));1755 try testing.expectEqual(true, try parse(bool, &TokenStream.init("true"), ParseOptions{}));
1756 testing.expectEqual(@as(u1, 1), try parse(u1, &TokenStream.init("1"), ParseOptions{}));1756 try testing.expectEqual(@as(u1, 1), try parse(u1, &TokenStream.init("1"), ParseOptions{}));
1757 testing.expectError(error.Overflow, parse(u1, &TokenStream.init("50"), ParseOptions{}));1757 try testing.expectError(error.Overflow, parse(u1, &TokenStream.init("50"), ParseOptions{}));
1758 testing.expectEqual(@as(u64, 42), try parse(u64, &TokenStream.init("42"), ParseOptions{}));1758 try 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{}));1759 try 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{}));1760 try 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{}));1761 try testing.expectEqual(@as(?bool, true), try parse(?bool, &TokenStream.init("true"), ParseOptions{}));
17621762
1763 testing.expectEqual(@as([3]u8, "foo".*), try parse([3]u8, &TokenStream.init("\"foo\""), ParseOptions{}));1763 try 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{}));1764 try testing.expectEqual(@as([3]u8, "foo".*), try parse([3]u8, &TokenStream.init("[102, 111, 111]"), ParseOptions{}));
1765}1765}
17661766
1767test "parse into enum" {1767test "parse into enum" {
...@@ -1770,31 +1770,31 @@ test "parse into enum" {...@@ -1770,31 +1770,31 @@ test "parse into enum" {
1770 Bar,1770 Bar,
1771 @"with\\escape",1771 @"with\\escape",
1772 };1772 };
1773 testing.expectEqual(@as(T, .Foo), try parse(T, &TokenStream.init("\"Foo\""), ParseOptions{}));1773 try 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{}));1774 try 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{}));1775 try 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{}));1776 try testing.expectError(error.InvalidEnumTag, parse(T, &TokenStream.init("5"), ParseOptions{}));
1777 testing.expectError(error.InvalidEnumTag, parse(T, &TokenStream.init("\"Qux\""), ParseOptions{}));1777 try testing.expectError(error.InvalidEnumTag, parse(T, &TokenStream.init("\"Qux\""), ParseOptions{}));
1778}1778}
17791779
1780test "parse into that allocates a slice" {1780test "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
1783 const options = ParseOptions{ .allocator = testing.allocator };1783 const options = ParseOptions{ .allocator = testing.allocator };
1784 {1784 {
1785 const r = try parse([]u8, &TokenStream.init("\"foo\""), options);1785 const r = try parse([]u8, &TokenStream.init("\"foo\""), options);
1786 defer parseFree([]u8, r, options);1786 defer parseFree([]u8, r, options);
1787 testing.expectEqualSlices(u8, "foo", r);1787 try testing.expectEqualSlices(u8, "foo", r);
1788 }1788 }
1789 {1789 {
1790 const r = try parse([]u8, &TokenStream.init("[102, 111, 111]"), options);1790 const r = try parse([]u8, &TokenStream.init("[102, 111, 111]"), options);
1791 defer parseFree([]u8, r, options);1791 defer parseFree([]u8, r, options);
1792 testing.expectEqualSlices(u8, "foo", r);1792 try testing.expectEqualSlices(u8, "foo", r);
1793 }1793 }
1794 {1794 {
1795 const r = try parse([]u8, &TokenStream.init("\"with\\\\escape\""), options);1795 const r = try parse([]u8, &TokenStream.init("\"with\\\\escape\""), options);
1796 defer parseFree([]u8, r, options);1796 defer parseFree([]u8, r, options);
1797 testing.expectEqualSlices(u8, "with\\escape", r);1797 try testing.expectEqualSlices(u8, "with\\escape", r);
1798 }1798 }
1799}1799}
18001800
...@@ -1805,7 +1805,7 @@ test "parse into tagged union" {...@@ -1805,7 +1805,7 @@ test "parse into tagged union" {
1805 float: f64,1805 float: f64,
1806 string: []const u8,1806 string: []const u8,
1807 };1807 };
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{}));
1809 }1809 }
18101810
1811 { // failing allocations should be bubbled up instantly without trying next member1811 { // failing allocations should be bubbled up instantly without trying next member
...@@ -1816,7 +1816,7 @@ test "parse into tagged union" {...@@ -1816,7 +1816,7 @@ test "parse into tagged union" {
1816 string: []const u8,1816 string: []const u8,
1817 array: [3]u8,1817 array: [3]u8,
1818 };1818 };
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));
1820 }1820 }
18211821
1822 {1822 {
...@@ -1825,7 +1825,7 @@ test "parse into tagged union" {...@@ -1825,7 +1825,7 @@ test "parse into tagged union" {
1825 x: u8,1825 x: u8,
1826 y: u8,1826 y: u8,
1827 };1827 };
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{}));
1829 }1829 }
18301830
1831 { // needs to back out when first union member doesn't match1831 { // needs to back out when first union member doesn't match
...@@ -1833,7 +1833,7 @@ test "parse into tagged union" {...@@ -1833,7 +1833,7 @@ test "parse into tagged union" {
1833 A: struct { x: u32 },1833 A: struct { x: u32 },
1834 B: struct { y: u32 },1834 B: struct { y: u32 },
1835 };1835 };
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{}));
1837 }1837 }
1838}1838}
18391839
...@@ -1843,7 +1843,7 @@ test "parse union bubbles up AllocatorRequired" {...@@ -1843,7 +1843,7 @@ test "parse union bubbles up AllocatorRequired" {
1843 string: []const u8,1843 string: []const u8,
1844 int: i32,1844 int: i32,
1845 };1845 };
1846 testing.expectError(error.AllocatorRequired, parse(T, &TokenStream.init("42"), ParseOptions{}));1846 try testing.expectError(error.AllocatorRequired, parse(T, &TokenStream.init("42"), ParseOptions{}));
1847 }1847 }
18481848
1849 { // string member not first in union (and matching)1849 { // string member not first in union (and matching)
...@@ -1852,7 +1852,7 @@ test "parse union bubbles up AllocatorRequired" {...@@ -1852,7 +1852,7 @@ test "parse union bubbles up AllocatorRequired" {
1852 float: f64,1852 float: f64,
1853 string: []const u8,1853 string: []const u8,
1854 };1854 };
1855 testing.expectError(error.AllocatorRequired, parse(T, &TokenStream.init("\"foo\""), ParseOptions{}));1855 try testing.expectError(error.AllocatorRequired, parse(T, &TokenStream.init("\"foo\""), ParseOptions{}));
1856 }1856 }
1857}1857}
18581858
...@@ -1866,11 +1866,11 @@ test "parseFree descends into tagged union" {...@@ -1866,11 +1866,11 @@ test "parseFree descends into tagged union" {
1866 };1866 };
1867 // use a string with unicode escape so we know result can't be a reference to global constant1867 // use a string with unicode escape so we know result can't be a reference to global constant
1868 const r = try parse(T, &TokenStream.init("\"with\\u0105unicode\""), options);1868 const r = try parse(T, &TokenStream.init("\"with\\u0105unicode\""), options);
1869 testing.expectEqual(std.meta.Tag(T).string, @as(std.meta.Tag(T), r));1869 try testing.expectEqual(std.meta.Tag(T).string, @as(std.meta.Tag(T), r));
1870 testing.expectEqualSlices(u8, "withąunicode", r.string);1870 try testing.expectEqualSlices(u8, "withąunicode", r.string);
1871 testing.expectEqual(@as(usize, 0), fail_alloc.deallocations);1871 try testing.expectEqual(@as(usize, 0), fail_alloc.deallocations);
1872 parseFree(T, r, options);1872 parseFree(T, r, options);
1873 testing.expectEqual(@as(usize, 1), fail_alloc.deallocations);1873 try testing.expectEqual(@as(usize, 1), fail_alloc.deallocations);
1874}1874}
18751875
1876test "parse with comptime field" {1876test "parse with comptime field" {
...@@ -1879,7 +1879,7 @@ test "parse with comptime field" {...@@ -1879,7 +1879,7 @@ test "parse with comptime field" {
1879 comptime a: i32 = 0,1879 comptime a: i32 = 0,
1880 b: bool,1880 b: bool,
1881 };1881 };
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(
1883 \\{1883 \\{
1884 \\ "a": 0,1884 \\ "a": 0,
1885 \\ "b": true1885 \\ "b": true
...@@ -1912,7 +1912,7 @@ test "parse with comptime field" {...@@ -1912,7 +1912,7 @@ test "parse with comptime field" {
19121912
1913test "parse into struct with no fields" {1913test "parse into struct with no fields" {
1914 const T = struct {};1914 const T = struct {};
1915 testing.expectEqual(T{}, try parse(T, &TokenStream.init("{}"), ParseOptions{}));1915 try testing.expectEqual(T{}, try parse(T, &TokenStream.init("{}"), ParseOptions{}));
1916}1916}
19171917
1918test "parse into struct with misc fields" {1918test "parse into struct with misc fields" {
...@@ -1968,24 +1968,24 @@ test "parse into struct with misc fields" {...@@ -1968,24 +1968,24 @@ test "parse into struct with misc fields" {
1968 \\}1968 \\}
1969 ), options);1969 ), options);
1970 defer parseFree(T, r, options);1970 defer parseFree(T, r, options);
1971 testing.expectEqual(@as(i64, 420), r.int);1971 try testing.expectEqual(@as(i64, 420), r.int);
1972 testing.expectEqual(@as(f64, 3.14), r.float);1972 try testing.expectEqual(@as(f64, 3.14), r.float);
1973 testing.expectEqual(true, r.@"with\\escape");1973 try testing.expectEqual(true, r.@"with\\escape");
1974 testing.expectEqual(false, r.@"withąunicode😂");1974 try testing.expectEqual(false, r.@"withąunicode😂");
1975 testing.expectEqualSlices(u8, "zig", r.language);1975 try testing.expectEqualSlices(u8, "zig", r.language);
1976 testing.expectEqual(@as(?bool, null), r.optional);1976 try testing.expectEqual(@as(?bool, null), r.optional);
1977 testing.expectEqual(@as(i32, 42), r.default_field);1977 try testing.expectEqual(@as(i32, 42), r.default_field);
1978 testing.expectEqual(@as(f64, 66.6), r.static_array[0]);1978 try testing.expectEqual(@as(f64, 66.6), r.static_array[0]);
1979 testing.expectEqual(@as(f64, 420.420), r.static_array[1]);1979 try testing.expectEqual(@as(f64, 420.420), r.static_array[1]);
1980 testing.expectEqual(@as(f64, 69.69), r.static_array[2]);1980 try testing.expectEqual(@as(f64, 69.69), r.static_array[2]);
1981 testing.expectEqual(@as(usize, 3), r.dynamic_array.len);1981 try testing.expectEqual(@as(usize, 3), r.dynamic_array.len);
1982 testing.expectEqual(@as(f64, 66.6), r.dynamic_array[0]);1982 try testing.expectEqual(@as(f64, 66.6), r.dynamic_array[0]);
1983 testing.expectEqual(@as(f64, 420.420), r.dynamic_array[1]);1983 try testing.expectEqual(@as(f64, 420.420), r.dynamic_array[1]);
1984 testing.expectEqual(@as(f64, 69.69), r.dynamic_array[2]);1984 try testing.expectEqual(@as(f64, 69.69), r.dynamic_array[2]);
1985 testing.expectEqualSlices(u8, r.complex.nested, "zig");1985 try testing.expectEqualSlices(u8, r.complex.nested, "zig");
1986 testing.expectEqualSlices(u8, "zig", r.veryComplex[0].foo);1986 try testing.expectEqualSlices(u8, "zig", r.veryComplex[0].foo);
1987 testing.expectEqualSlices(u8, "rocks", r.veryComplex[1].foo);1987 try testing.expectEqualSlices(u8, "rocks", r.veryComplex[1].foo);
1988 testing.expectEqual(T.Union{ .float = 100000 }, r.a_union);1988 try testing.expectEqual(T.Union{ .float = 100000 }, r.a_union);
1989}1989}
19901990
1991/// A non-stream JSON parser which constructs a tree of Value's.1991/// A non-stream JSON parser which constructs a tree of Value's.
...@@ -2320,28 +2320,28 @@ test "json.parser.dynamic" {...@@ -2320,28 +2320,28 @@ test "json.parser.dynamic" {
2320 var image = root.Object.get("Image").?;2320 var image = root.Object.get("Image").?;
23212321
2322 const width = image.Object.get("Width").?;2322 const width = image.Object.get("Width").?;
2323 testing.expect(width.Integer == 800);2323 try testing.expect(width.Integer == 800);
23242324
2325 const height = image.Object.get("Height").?;2325 const height = image.Object.get("Height").?;
2326 testing.expect(height.Integer == 600);2326 try testing.expect(height.Integer == 600);
23272327
2328 const title = image.Object.get("Title").?;2328 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
2331 const animated = image.Object.get("Animated").?;2331 const animated = image.Object.get("Animated").?;
2332 testing.expect(animated.Bool == false);2332 try testing.expect(animated.Bool == false);
23332333
2334 const array_of_object = image.Object.get("ArrayOfObject").?;2334 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
2337 const obj0 = array_of_object.Array.items[0].Object.get("n").?;2337 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
2340 const double = image.Object.get("double").?;2340 const double = image.Object.get("double").?;
2341 testing.expect(double.Float == 1.3412);2341 try testing.expect(double.Float == 1.3412);
23422342
2343 const large_int = image.Object.get("LargeInt").?;2343 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"));
2345}2345}
23462346
2347test "import more json tests" {2347test "import more json tests" {
...@@ -2388,12 +2388,12 @@ test "write json then parse it" {...@@ -2388,12 +2388,12 @@ test "write json then parse it" {
2388 var tree = try parser.parse(fixed_buffer_stream.getWritten());2388 var tree = try parser.parse(fixed_buffer_stream.getWritten());
2389 defer tree.deinit();2389 defer tree.deinit();
23902390
2391 testing.expect(tree.root.Object.get("f").?.Bool == false);2391 try testing.expect(tree.root.Object.get("f").?.Bool == false);
2392 testing.expect(tree.root.Object.get("t").?.Bool == true);2392 try testing.expect(tree.root.Object.get("t").?.Bool == true);
2393 testing.expect(tree.root.Object.get("int").?.Integer == 1234);2393 try testing.expect(tree.root.Object.get("int").?.Integer == 1234);
2394 testing.expect(tree.root.Object.get("array").?.Array.items[0].Null == {});2394 try 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);2395 try 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"));2396 try testing.expect(mem.eql(u8, tree.root.Object.get("str").?.String, "hello"));
2397}2397}
23982398
2399fn test_parse(arena_allocator: *std.mem.Allocator, json_str: []const u8) !Value {2399fn 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...@@ -2404,7 +2404,7 @@ fn test_parse(arena_allocator: *std.mem.Allocator, json_str: []const u8) !Value
2404test "parsing empty string gives appropriate error" {2404test "parsing empty string gives appropriate error" {
2405 var arena_allocator = std.heap.ArenaAllocator.init(std.testing.allocator);2405 var arena_allocator = std.heap.ArenaAllocator.init(std.testing.allocator);
2406 defer arena_allocator.deinit();2406 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, ""));
2408}2408}
24092409
2410test "integer after float has proper type" {2410test "integer after float has proper type" {
...@@ -2416,7 +2416,7 @@ test "integer after float has proper type" {...@@ -2416,7 +2416,7 @@ test "integer after float has proper type" {
2416 \\ "ints": [1, 2, 3]2416 \\ "ints": [1, 2, 3]
2417 \\}2417 \\}
2418 );2418 );
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);
2420}2420}
24212421
2422test "escaped characters" {2422test "escaped characters" {
...@@ -2439,16 +2439,16 @@ test "escaped characters" {...@@ -2439,16 +2439,16 @@ test "escaped characters" {
24392439
2440 const obj = (try test_parse(&arena_allocator.allocator, input)).Object;2440 const obj = (try test_parse(&arena_allocator.allocator, input)).Object;
24412441
2442 testing.expectEqualSlices(u8, obj.get("backslash").?.String, "\\");2442 try testing.expectEqualSlices(u8, obj.get("backslash").?.String, "\\");
2443 testing.expectEqualSlices(u8, obj.get("forwardslash").?.String, "/");2443 try testing.expectEqualSlices(u8, obj.get("forwardslash").?.String, "/");
2444 testing.expectEqualSlices(u8, obj.get("newline").?.String, "\n");2444 try testing.expectEqualSlices(u8, obj.get("newline").?.String, "\n");
2445 testing.expectEqualSlices(u8, obj.get("carriagereturn").?.String, "\r");2445 try testing.expectEqualSlices(u8, obj.get("carriagereturn").?.String, "\r");
2446 testing.expectEqualSlices(u8, obj.get("tab").?.String, "\t");2446 try testing.expectEqualSlices(u8, obj.get("tab").?.String, "\t");
2447 testing.expectEqualSlices(u8, obj.get("formfeed").?.String, "\x0C");2447 try testing.expectEqualSlices(u8, obj.get("formfeed").?.String, "\x0C");
2448 testing.expectEqualSlices(u8, obj.get("backspace").?.String, "\x08");2448 try testing.expectEqualSlices(u8, obj.get("backspace").?.String, "\x08");
2449 testing.expectEqualSlices(u8, obj.get("doublequote").?.String, "\"");2449 try testing.expectEqualSlices(u8, obj.get("doublequote").?.String, "\"");
2450 testing.expectEqualSlices(u8, obj.get("unicode").?.String, "ą");2450 try testing.expectEqualSlices(u8, obj.get("unicode").?.String, "ą");
2451 testing.expectEqualSlices(u8, obj.get("surrogatepair").?.String, "😂");2451 try testing.expectEqualSlices(u8, obj.get("surrogatepair").?.String, "😂");
2452}2452}
24532453
2454test "string copy option" {2454test "string copy option" {
...@@ -2471,7 +2471,7 @@ test "string copy option" {...@@ -2471,7 +2471,7 @@ test "string copy option" {
2471 const obj_copy = tree_copy.root.Object;2471 const obj_copy = tree_copy.root.Object;
24722472
2473 for ([_][]const u8{ "noescape", "simple", "unicode", "surrogatepair" }) |field_name| {2473 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);
2475 }2475 }
24762476
2477 const nocopy_addr = &obj_nocopy.get("noescape").?.String[0];2477 const nocopy_addr = &obj_nocopy.get("noescape").?.String[0];
...@@ -2479,12 +2479,12 @@ test "string copy option" {...@@ -2479,12 +2479,12 @@ test "string copy option" {
24792479
2480 var found_nocopy = false;2480 var found_nocopy = false;
2481 for (input) |_, index| {2481 for (input) |_, index| {
2482 testing.expect(copy_addr != &input[index]);2482 try testing.expect(copy_addr != &input[index]);
2483 if (nocopy_addr == &input[index]) {2483 if (nocopy_addr == &input[index]) {
2484 found_nocopy = true;2484 found_nocopy = true;
2485 }2485 }
2486 }2486 }
2487 testing.expect(found_nocopy);2487 try testing.expect(found_nocopy);
2488}2488}
24892489
2490pub const StringifyOptions = struct {2490pub const StringifyOptions = struct {
lib/std/json/test.zig+275-275
...@@ -21,37 +21,37 @@ fn testNonStreaming(s: []const u8) !void {...@@ -21,37 +21,37 @@ fn testNonStreaming(s: []const u8) !void {
21}21}
2222
23fn ok(s: []const u8) !void {23fn ok(s: []const u8) !void {
24 testing.expect(json.validate(s));24 try testing.expect(json.validate(s));
2525
26 try testNonStreaming(s);26 try testNonStreaming(s);
27}27}
2828
29fn err(s: []const u8) void {29fn err(s: []const u8) !void {
30 testing.expect(!json.validate(s));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)));
33}33}
3434
35fn utf8Error(s: []const u8) void {35fn utf8Error(s: []const u8) !void {
36 testing.expect(!json.validate(s));36 try testing.expect(!json.validate(s));
3737
38 testing.expectError(error.InvalidUtf8Byte, testNonStreaming(s));38 try testing.expectError(error.InvalidUtf8Byte, testNonStreaming(s));
39}39}
4040
41fn any(s: []const u8) void {41fn any(s: []const u8) !void {
42 _ = json.validate(s);42 _ = json.validate(s);
4343
44 testNonStreaming(s) catch {};44 testNonStreaming(s) catch {};
45}45}
4646
47fn anyStreamingErrNonStreaming(s: []const u8) void {47fn anyStreamingErrNonStreaming(s: []const u8) !void {
48 _ = json.validate(s);48 _ = json.validate(s);
4949
50 testing.expect(std.meta.isError(testNonStreaming(s)));50 try testing.expect(std.meta.isError(testNonStreaming(s)));
51}51}
5252
53fn roundTrip(s: []const u8) !void {53fn roundTrip(s: []const u8) !void {
54 testing.expect(json.validate(s));54 try testing.expect(json.validate(s));
5555
56 var p = json.Parser.init(testing.allocator, false);56 var p = json.Parser.init(testing.allocator, false);
57 defer p.deinit();57 defer p.deinit();
...@@ -63,7 +63,7 @@ fn roundTrip(s: []const u8) !void {...@@ -63,7 +63,7 @@ fn roundTrip(s: []const u8) !void {
63 var fbs = std.io.fixedBufferStream(&buf);63 var fbs = std.io.fixedBufferStream(&buf);
64 try tree.root.jsonStringify(.{}, fbs.writer());64 try tree.root.jsonStringify(.{}, fbs.writer());
6565
66 testing.expectEqualStrings(s, fbs.getWritten());66 try testing.expectEqualStrings(s, fbs.getWritten());
67}67}
6868
69////////////////////////////////////////////////////////////////////////////////////////////////////69////////////////////////////////////////////////////////////////////////////////////////////////////
...@@ -642,109 +642,109 @@ test "y_structure_whitespace_array" {...@@ -642,109 +642,109 @@ test "y_structure_whitespace_array" {
642////////////////////////////////////////////////////////////////////////////////////////////////////642////////////////////////////////////////////////////////////////////////////////////////////////////
643643
644test "n_array_1_true_without_comma" {644test "n_array_1_true_without_comma" {
645 err(645 try err(
646 \\[1 true]646 \\[1 true]
647 );647 );
648}648}
649649
650test "n_array_a_invalid_utf8" {650test "n_array_a_invalid_utf8" {
651 err(651 try err(
652 \\[aå]652 \\[aå]
653 );653 );
654}654}
655655
656test "n_array_colon_instead_of_comma" {656test "n_array_colon_instead_of_comma" {
657 err(657 try err(
658 \\["": 1]658 \\["": 1]
659 );659 );
660}660}
661661
662test "n_array_comma_after_close" {662test "n_array_comma_after_close" {
663 err(663 try err(
664 \\[""],664 \\[""],
665 );665 );
666}666}
667667
668test "n_array_comma_and_number" {668test "n_array_comma_and_number" {
669 err(669 try err(
670 \\[,1]670 \\[,1]
671 );671 );
672}672}
673673
674test "n_array_double_comma" {674test "n_array_double_comma" {
675 err(675 try err(
676 \\[1,,2]676 \\[1,,2]
677 );677 );
678}678}
679679
680test "n_array_double_extra_comma" {680test "n_array_double_extra_comma" {
681 err(681 try err(
682 \\["x",,]682 \\["x",,]
683 );683 );
684}684}
685685
686test "n_array_extra_close" {686test "n_array_extra_close" {
687 err(687 try err(
688 \\["x"]]688 \\["x"]]
689 );689 );
690}690}
691691
692test "n_array_extra_comma" {692test "n_array_extra_comma" {
693 err(693 try err(
694 \\["",]694 \\["",]
695 );695 );
696}696}
697697
698test "n_array_incomplete_invalid_value" {698test "n_array_incomplete_invalid_value" {
699 err(699 try err(
700 \\[x700 \\[x
701 );701 );
702}702}
703703
704test "n_array_incomplete" {704test "n_array_incomplete" {
705 err(705 try err(
706 \\["x"706 \\["x"
707 );707 );
708}708}
709709
710test "n_array_inner_array_no_comma" {710test "n_array_inner_array_no_comma" {
711 err(711 try err(
712 \\[3[4]]712 \\[3[4]]
713 );713 );
714}714}
715715
716test "n_array_invalid_utf8" {716test "n_array_invalid_utf8" {
717 err(717 try err(
718 \\[ÿ]718 \\[ÿ]
719 );719 );
720}720}
721721
722test "n_array_items_separated_by_semicolon" {722test "n_array_items_separated_by_semicolon" {
723 err(723 try err(
724 \\[1:2]724 \\[1:2]
725 );725 );
726}726}
727727
728test "n_array_just_comma" {728test "n_array_just_comma" {
729 err(729 try err(
730 \\[,]730 \\[,]
731 );731 );
732}732}
733733
734test "n_array_just_minus" {734test "n_array_just_minus" {
735 err(735 try err(
736 \\[-]736 \\[-]
737 );737 );
738}738}
739739
740test "n_array_missing_value" {740test "n_array_missing_value" {
741 err(741 try err(
742 \\[ , ""]742 \\[ , ""]
743 );743 );
744}744}
745745
746test "n_array_newlines_unclosed" {746test "n_array_newlines_unclosed" {
747 err(747 try err(
748 \\["a",748 \\["a",
749 \\4749 \\4
750 \\,1,750 \\,1,
...@@ -752,41 +752,41 @@ test "n_array_newlines_unclosed" {...@@ -752,41 +752,41 @@ test "n_array_newlines_unclosed" {
752}752}
753753
754test "n_array_number_and_comma" {754test "n_array_number_and_comma" {
755 err(755 try err(
756 \\[1,]756 \\[1,]
757 );757 );
758}758}
759759
760test "n_array_number_and_several_commas" {760test "n_array_number_and_several_commas" {
761 err(761 try err(
762 \\[1,,]762 \\[1,,]
763 );763 );
764}764}
765765
766test "n_array_spaces_vertical_tab_formfeed" {766test "n_array_spaces_vertical_tab_formfeed" {
767 err("[\"\x0aa\"\\f]");767 try err("[\"\x0aa\"\\f]");
768}768}
769769
770test "n_array_star_inside" {770test "n_array_star_inside" {
771 err(771 try err(
772 \\[*]772 \\[*]
773 );773 );
774}774}
775775
776test "n_array_unclosed" {776test "n_array_unclosed" {
777 err(777 try err(
778 \\[""778 \\[""
779 );779 );
780}780}
781781
782test "n_array_unclosed_trailing_comma" {782test "n_array_unclosed_trailing_comma" {
783 err(783 try err(
784 \\[1,784 \\[1,
785 );785 );
786}786}
787787
788test "n_array_unclosed_with_new_lines" {788test "n_array_unclosed_with_new_lines" {
789 err(789 try err(
790 \\[1,790 \\[1,
791 \\1791 \\1
792 \\,1792 \\,1
...@@ -794,956 +794,956 @@ test "n_array_unclosed_with_new_lines" {...@@ -794,956 +794,956 @@ test "n_array_unclosed_with_new_lines" {
794}794}
795795
796test "n_array_unclosed_with_object_inside" {796test "n_array_unclosed_with_object_inside" {
797 err(797 try err(
798 \\[{}798 \\[{}
799 );799 );
800}800}
801801
802test "n_incomplete_false" {802test "n_incomplete_false" {
803 err(803 try err(
804 \\[fals]804 \\[fals]
805 );805 );
806}806}
807807
808test "n_incomplete_null" {808test "n_incomplete_null" {
809 err(809 try err(
810 \\[nul]810 \\[nul]
811 );811 );
812}812}
813813
814test "n_incomplete_true" {814test "n_incomplete_true" {
815 err(815 try err(
816 \\[tru]816 \\[tru]
817 );817 );
818}818}
819819
820test "n_multidigit_number_then_00" {820test "n_multidigit_number_then_00" {
821 err("123\x00");821 try err("123\x00");
822}822}
823823
824test "n_number_0.1.2" {824test "n_number_0.1.2" {
825 err(825 try err(
826 \\[0.1.2]826 \\[0.1.2]
827 );827 );
828}828}
829829
830test "n_number_-01" {830test "n_number_-01" {
831 err(831 try err(
832 \\[-01]832 \\[-01]
833 );833 );
834}834}
835835
836test "n_number_0.3e" {836test "n_number_0.3e" {
837 err(837 try err(
838 \\[0.3e]838 \\[0.3e]
839 );839 );
840}840}
841841
842test "n_number_0.3e+" {842test "n_number_0.3e+" {
843 err(843 try err(
844 \\[0.3e+]844 \\[0.3e+]
845 );845 );
846}846}
847847
848test "n_number_0_capital_E" {848test "n_number_0_capital_E" {
849 err(849 try err(
850 \\[0E]850 \\[0E]
851 );851 );
852}852}
853853
854test "n_number_0_capital_E+" {854test "n_number_0_capital_E+" {
855 err(855 try err(
856 \\[0E+]856 \\[0E+]
857 );857 );
858}858}
859859
860test "n_number_0.e1" {860test "n_number_0.e1" {
861 err(861 try err(
862 \\[0.e1]862 \\[0.e1]
863 );863 );
864}864}
865865
866test "n_number_0e" {866test "n_number_0e" {
867 err(867 try err(
868 \\[0e]868 \\[0e]
869 );869 );
870}870}
871871
872test "n_number_0e+" {872test "n_number_0e+" {
873 err(873 try err(
874 \\[0e+]874 \\[0e+]
875 );875 );
876}876}
877877
878test "n_number_1_000" {878test "n_number_1_000" {
879 err(879 try err(
880 \\[1 000.0]880 \\[1 000.0]
881 );881 );
882}882}
883883
884test "n_number_1.0e-" {884test "n_number_1.0e-" {
885 err(885 try err(
886 \\[1.0e-]886 \\[1.0e-]
887 );887 );
888}888}
889889
890test "n_number_1.0e" {890test "n_number_1.0e" {
891 err(891 try err(
892 \\[1.0e]892 \\[1.0e]
893 );893 );
894}894}
895895
896test "n_number_1.0e+" {896test "n_number_1.0e+" {
897 err(897 try err(
898 \\[1.0e+]898 \\[1.0e+]
899 );899 );
900}900}
901901
902test "n_number_-1.0." {902test "n_number_-1.0." {
903 err(903 try err(
904 \\[-1.0.]904 \\[-1.0.]
905 );905 );
906}906}
907907
908test "n_number_1eE2" {908test "n_number_1eE2" {
909 err(909 try err(
910 \\[1eE2]910 \\[1eE2]
911 );911 );
912}912}
913913
914test "n_number_.-1" {914test "n_number_.-1" {
915 err(915 try err(
916 \\[.-1]916 \\[.-1]
917 );917 );
918}918}
919919
920test "n_number_+1" {920test "n_number_+1" {
921 err(921 try err(
922 \\[+1]922 \\[+1]
923 );923 );
924}924}
925925
926test "n_number_.2e-3" {926test "n_number_.2e-3" {
927 err(927 try err(
928 \\[.2e-3]928 \\[.2e-3]
929 );929 );
930}930}
931931
932test "n_number_2.e-3" {932test "n_number_2.e-3" {
933 err(933 try err(
934 \\[2.e-3]934 \\[2.e-3]
935 );935 );
936}936}
937937
938test "n_number_2.e+3" {938test "n_number_2.e+3" {
939 err(939 try err(
940 \\[2.e+3]940 \\[2.e+3]
941 );941 );
942}942}
943943
944test "n_number_2.e3" {944test "n_number_2.e3" {
945 err(945 try err(
946 \\[2.e3]946 \\[2.e3]
947 );947 );
948}948}
949949
950test "n_number_-2." {950test "n_number_-2." {
951 err(951 try err(
952 \\[-2.]952 \\[-2.]
953 );953 );
954}954}
955955
956test "n_number_9.e+" {956test "n_number_9.e+" {
957 err(957 try err(
958 \\[9.e+]958 \\[9.e+]
959 );959 );
960}960}
961961
962test "n_number_expression" {962test "n_number_expression" {
963 err(963 try err(
964 \\[1+2]964 \\[1+2]
965 );965 );
966}966}
967967
968test "n_number_hex_1_digit" {968test "n_number_hex_1_digit" {
969 err(969 try err(
970 \\[0x1]970 \\[0x1]
971 );971 );
972}972}
973973
974test "n_number_hex_2_digits" {974test "n_number_hex_2_digits" {
975 err(975 try err(
976 \\[0x42]976 \\[0x42]
977 );977 );
978}978}
979979
980test "n_number_infinity" {980test "n_number_infinity" {
981 err(981 try err(
982 \\[Infinity]982 \\[Infinity]
983 );983 );
984}984}
985985
986test "n_number_+Inf" {986test "n_number_+Inf" {
987 err(987 try err(
988 \\[+Inf]988 \\[+Inf]
989 );989 );
990}990}
991991
992test "n_number_Inf" {992test "n_number_Inf" {
993 err(993 try err(
994 \\[Inf]994 \\[Inf]
995 );995 );
996}996}
997997
998test "n_number_invalid+-" {998test "n_number_invalid+-" {
999 err(999 try err(
1000 \\[0e+-1]1000 \\[0e+-1]
1001 );1001 );
1002}1002}
10031003
1004test "n_number_invalid-negative-real" {1004test "n_number_invalid-negative-real" {
1005 err(1005 try err(
1006 \\[-123.123foo]1006 \\[-123.123foo]
1007 );1007 );
1008}1008}
10091009
1010test "n_number_invalid-utf-8-in-bigger-int" {1010test "n_number_invalid-utf-8-in-bigger-int" {
1011 err(1011 try err(
1012 \\[123å]1012 \\[123å]
1013 );1013 );
1014}1014}
10151015
1016test "n_number_invalid-utf-8-in-exponent" {1016test "n_number_invalid-utf-8-in-exponent" {
1017 err(1017 try err(
1018 \\[1e1å]1018 \\[1e1å]
1019 );1019 );
1020}1020}
10211021
1022test "n_number_invalid-utf-8-in-int" {1022test "n_number_invalid-utf-8-in-int" {
1023 err(1023 try err(
1024 \\[0å]1024 \\[0å]
1025 );1025 );
1026}1026}
10271027
1028test "n_number_++" {1028test "n_number_++" {
1029 err(1029 try err(
1030 \\[++1234]1030 \\[++1234]
1031 );1031 );
1032}1032}
10331033
1034test "n_number_minus_infinity" {1034test "n_number_minus_infinity" {
1035 err(1035 try err(
1036 \\[-Infinity]1036 \\[-Infinity]
1037 );1037 );
1038}1038}
10391039
1040test "n_number_minus_sign_with_trailing_garbage" {1040test "n_number_minus_sign_with_trailing_garbage" {
1041 err(1041 try err(
1042 \\[-foo]1042 \\[-foo]
1043 );1043 );
1044}1044}
10451045
1046test "n_number_minus_space_1" {1046test "n_number_minus_space_1" {
1047 err(1047 try err(
1048 \\[- 1]1048 \\[- 1]
1049 );1049 );
1050}1050}
10511051
1052test "n_number_-NaN" {1052test "n_number_-NaN" {
1053 err(1053 try err(
1054 \\[-NaN]1054 \\[-NaN]
1055 );1055 );
1056}1056}
10571057
1058test "n_number_NaN" {1058test "n_number_NaN" {
1059 err(1059 try err(
1060 \\[NaN]1060 \\[NaN]
1061 );1061 );
1062}1062}
10631063
1064test "n_number_neg_int_starting_with_zero" {1064test "n_number_neg_int_starting_with_zero" {
1065 err(1065 try err(
1066 \\[-012]1066 \\[-012]
1067 );1067 );
1068}1068}
10691069
1070test "n_number_neg_real_without_int_part" {1070test "n_number_neg_real_without_int_part" {
1071 err(1071 try err(
1072 \\[-.123]1072 \\[-.123]
1073 );1073 );
1074}1074}
10751075
1076test "n_number_neg_with_garbage_at_end" {1076test "n_number_neg_with_garbage_at_end" {
1077 err(1077 try err(
1078 \\[-1x]1078 \\[-1x]
1079 );1079 );
1080}1080}
10811081
1082test "n_number_real_garbage_after_e" {1082test "n_number_real_garbage_after_e" {
1083 err(1083 try err(
1084 \\[1ea]1084 \\[1ea]
1085 );1085 );
1086}1086}
10871087
1088test "n_number_real_with_invalid_utf8_after_e" {1088test "n_number_real_with_invalid_utf8_after_e" {
1089 err(1089 try err(
1090 \\[1eå]1090 \\[1eå]
1091 );1091 );
1092}1092}
10931093
1094test "n_number_real_without_fractional_part" {1094test "n_number_real_without_fractional_part" {
1095 err(1095 try err(
1096 \\[1.]1096 \\[1.]
1097 );1097 );
1098}1098}
10991099
1100test "n_number_starting_with_dot" {1100test "n_number_starting_with_dot" {
1101 err(1101 try err(
1102 \\[.123]1102 \\[.123]
1103 );1103 );
1104}1104}
11051105
1106test "n_number_U+FF11_fullwidth_digit_one" {1106test "n_number_U+FF11_fullwidth_digit_one" {
1107 err(1107 try err(
1108 \\[1]1108 \\[1]
1109 );1109 );
1110}1110}
11111111
1112test "n_number_with_alpha_char" {1112test "n_number_with_alpha_char" {
1113 err(1113 try err(
1114 \\[1.8011670033376514H-308]1114 \\[1.8011670033376514H-308]
1115 );1115 );
1116}1116}
11171117
1118test "n_number_with_alpha" {1118test "n_number_with_alpha" {
1119 err(1119 try err(
1120 \\[1.2a-3]1120 \\[1.2a-3]
1121 );1121 );
1122}1122}
11231123
1124test "n_number_with_leading_zero" {1124test "n_number_with_leading_zero" {
1125 err(1125 try err(
1126 \\[012]1126 \\[012]
1127 );1127 );
1128}1128}
11291129
1130test "n_object_bad_value" {1130test "n_object_bad_value" {
1131 err(1131 try err(
1132 \\["x", truth]1132 \\["x", truth]
1133 );1133 );
1134}1134}
11351135
1136test "n_object_bracket_key" {1136test "n_object_bracket_key" {
1137 err(1137 try err(
1138 \\{[: "x"}1138 \\{[: "x"}
1139 );1139 );
1140}1140}
11411141
1142test "n_object_comma_instead_of_colon" {1142test "n_object_comma_instead_of_colon" {
1143 err(1143 try err(
1144 \\{"x", null}1144 \\{"x", null}
1145 );1145 );
1146}1146}
11471147
1148test "n_object_double_colon" {1148test "n_object_double_colon" {
1149 err(1149 try err(
1150 \\{"x"::"b"}1150 \\{"x"::"b"}
1151 );1151 );
1152}1152}
11531153
1154test "n_object_emoji" {1154test "n_object_emoji" {
1155 err(1155 try err(
1156 \\{🇨🇭}1156 \\{🇨🇭}
1157 );1157 );
1158}1158}
11591159
1160test "n_object_garbage_at_end" {1160test "n_object_garbage_at_end" {
1161 err(1161 try err(
1162 \\{"a":"a" 123}1162 \\{"a":"a" 123}
1163 );1163 );
1164}1164}
11651165
1166test "n_object_key_with_single_quotes" {1166test "n_object_key_with_single_quotes" {
1167 err(1167 try err(
1168 \\{key: 'value'}1168 \\{key: 'value'}
1169 );1169 );
1170}1170}
11711171
1172test "n_object_lone_continuation_byte_in_key_and_trailing_comma" {1172test "n_object_lone_continuation_byte_in_key_and_trailing_comma" {
1173 err(1173 try err(
1174 \\{"¹":"0",}1174 \\{"¹":"0",}
1175 );1175 );
1176}1176}
11771177
1178test "n_object_missing_colon" {1178test "n_object_missing_colon" {
1179 err(1179 try err(
1180 \\{"a" b}1180 \\{"a" b}
1181 );1181 );
1182}1182}
11831183
1184test "n_object_missing_key" {1184test "n_object_missing_key" {
1185 err(1185 try err(
1186 \\{:"b"}1186 \\{:"b"}
1187 );1187 );
1188}1188}
11891189
1190test "n_object_missing_semicolon" {1190test "n_object_missing_semicolon" {
1191 err(1191 try err(
1192 \\{"a" "b"}1192 \\{"a" "b"}
1193 );1193 );
1194}1194}
11951195
1196test "n_object_missing_value" {1196test "n_object_missing_value" {
1197 err(1197 try err(
1198 \\{"a":1198 \\{"a":
1199 );1199 );
1200}1200}
12011201
1202test "n_object_no-colon" {1202test "n_object_no-colon" {
1203 err(1203 try err(
1204 \\{"a"1204 \\{"a"
1205 );1205 );
1206}1206}
12071207
1208test "n_object_non_string_key_but_huge_number_instead" {1208test "n_object_non_string_key_but_huge_number_instead" {
1209 err(1209 try err(
1210 \\{9999E9999:1}1210 \\{9999E9999:1}
1211 );1211 );
1212}1212}
12131213
1214test "n_object_non_string_key" {1214test "n_object_non_string_key" {
1215 err(1215 try err(
1216 \\{1:1}1216 \\{1:1}
1217 );1217 );
1218}1218}
12191219
1220test "n_object_repeated_null_null" {1220test "n_object_repeated_null_null" {
1221 err(1221 try err(
1222 \\{null:null,null:null}1222 \\{null:null,null:null}
1223 );1223 );
1224}1224}
12251225
1226test "n_object_several_trailing_commas" {1226test "n_object_several_trailing_commas" {
1227 err(1227 try err(
1228 \\{"id":0,,,,,}1228 \\{"id":0,,,,,}
1229 );1229 );
1230}1230}
12311231
1232test "n_object_single_quote" {1232test "n_object_single_quote" {
1233 err(1233 try err(
1234 \\{'a':0}1234 \\{'a':0}
1235 );1235 );
1236}1236}
12371237
1238test "n_object_trailing_comma" {1238test "n_object_trailing_comma" {
1239 err(1239 try err(
1240 \\{"id":0,}1240 \\{"id":0,}
1241 );1241 );
1242}1242}
12431243
1244test "n_object_trailing_comment" {1244test "n_object_trailing_comment" {
1245 err(1245 try err(
1246 \\{"a":"b"}/**/1246 \\{"a":"b"}/**/
1247 );1247 );
1248}1248}
12491249
1250test "n_object_trailing_comment_open" {1250test "n_object_trailing_comment_open" {
1251 err(1251 try err(
1252 \\{"a":"b"}/**//1252 \\{"a":"b"}/**//
1253 );1253 );
1254}1254}
12551255
1256test "n_object_trailing_comment_slash_open_incomplete" {1256test "n_object_trailing_comment_slash_open_incomplete" {
1257 err(1257 try err(
1258 \\{"a":"b"}/1258 \\{"a":"b"}/
1259 );1259 );
1260}1260}
12611261
1262test "n_object_trailing_comment_slash_open" {1262test "n_object_trailing_comment_slash_open" {
1263 err(1263 try err(
1264 \\{"a":"b"}//1264 \\{"a":"b"}//
1265 );1265 );
1266}1266}
12671267
1268test "n_object_two_commas_in_a_row" {1268test "n_object_two_commas_in_a_row" {
1269 err(1269 try err(
1270 \\{"a":"b",,"c":"d"}1270 \\{"a":"b",,"c":"d"}
1271 );1271 );
1272}1272}
12731273
1274test "n_object_unquoted_key" {1274test "n_object_unquoted_key" {
1275 err(1275 try err(
1276 \\{a: "b"}1276 \\{a: "b"}
1277 );1277 );
1278}1278}
12791279
1280test "n_object_unterminated-value" {1280test "n_object_unterminated-value" {
1281 err(1281 try err(
1282 \\{"a":"a1282 \\{"a":"a
1283 );1283 );
1284}1284}
12851285
1286test "n_object_with_single_string" {1286test "n_object_with_single_string" {
1287 err(1287 try err(
1288 \\{ "foo" : "bar", "a" }1288 \\{ "foo" : "bar", "a" }
1289 );1289 );
1290}1290}
12911291
1292test "n_object_with_trailing_garbage" {1292test "n_object_with_trailing_garbage" {
1293 err(1293 try err(
1294 \\{"a":"b"}#1294 \\{"a":"b"}#
1295 );1295 );
1296}1296}
12971297
1298test "n_single_space" {1298test "n_single_space" {
1299 err(" ");1299 try err(" ");
1300}1300}
13011301
1302test "n_string_1_surrogate_then_escape" {1302test "n_string_1_surrogate_then_escape" {
1303 err(1303 try err(
1304 \\["\uD800\"]1304 \\["\uD800\"]
1305 );1305 );
1306}1306}
13071307
1308test "n_string_1_surrogate_then_escape_u1" {1308test "n_string_1_surrogate_then_escape_u1" {
1309 err(1309 try err(
1310 \\["\uD800\u1"]1310 \\["\uD800\u1"]
1311 );1311 );
1312}1312}
13131313
1314test "n_string_1_surrogate_then_escape_u1x" {1314test "n_string_1_surrogate_then_escape_u1x" {
1315 err(1315 try err(
1316 \\["\uD800\u1x"]1316 \\["\uD800\u1x"]
1317 );1317 );
1318}1318}
13191319
1320test "n_string_1_surrogate_then_escape_u" {1320test "n_string_1_surrogate_then_escape_u" {
1321 err(1321 try err(
1322 \\["\uD800\u"]1322 \\["\uD800\u"]
1323 );1323 );
1324}1324}
13251325
1326test "n_string_accentuated_char_no_quotes" {1326test "n_string_accentuated_char_no_quotes" {
1327 err(1327 try err(
1328 \\[é]1328 \\[é]
1329 );1329 );
1330}1330}
13311331
1332test "n_string_backslash_00" {1332test "n_string_backslash_00" {
1333 err("[\"\x00\"]");1333 try err("[\"\x00\"]");
1334}1334}
13351335
1336test "n_string_escaped_backslash_bad" {1336test "n_string_escaped_backslash_bad" {
1337 err(1337 try err(
1338 \\["\\\"]1338 \\["\\\"]
1339 );1339 );
1340}1340}
13411341
1342test "n_string_escaped_ctrl_char_tab" {1342test "n_string_escaped_ctrl_char_tab" {
1343 err("\x5b\x22\x5c\x09\x22\x5d");1343 try err("\x5b\x22\x5c\x09\x22\x5d");
1344}1344}
13451345
1346test "n_string_escaped_emoji" {1346test "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\"]");
1348}1348}
13491349
1350test "n_string_escape_x" {1350test "n_string_escape_x" {
1351 err(1351 try err(
1352 \\["\x00"]1352 \\["\x00"]
1353 );1353 );
1354}1354}
13551355
1356test "n_string_incomplete_escaped_character" {1356test "n_string_incomplete_escaped_character" {
1357 err(1357 try err(
1358 \\["\u00A"]1358 \\["\u00A"]
1359 );1359 );
1360}1360}
13611361
1362test "n_string_incomplete_escape" {1362test "n_string_incomplete_escape" {
1363 err(1363 try err(
1364 \\["\"]1364 \\["\"]
1365 );1365 );
1366}1366}
13671367
1368test "n_string_incomplete_surrogate_escape_invalid" {1368test "n_string_incomplete_surrogate_escape_invalid" {
1369 err(1369 try err(
1370 \\["\uD800\uD800\x"]1370 \\["\uD800\uD800\x"]
1371 );1371 );
1372}1372}
13731373
1374test "n_string_incomplete_surrogate" {1374test "n_string_incomplete_surrogate" {
1375 err(1375 try err(
1376 \\["\uD834\uDd"]1376 \\["\uD834\uDd"]
1377 );1377 );
1378}1378}
13791379
1380test "n_string_invalid_backslash_esc" {1380test "n_string_invalid_backslash_esc" {
1381 err(1381 try err(
1382 \\["\a"]1382 \\["\a"]
1383 );1383 );
1384}1384}
13851385
1386test "n_string_invalid_unicode_escape" {1386test "n_string_invalid_unicode_escape" {
1387 err(1387 try err(
1388 \\["\uqqqq"]1388 \\["\uqqqq"]
1389 );1389 );
1390}1390}
13911391
1392test "n_string_invalid_utf8_after_escape" {1392test "n_string_invalid_utf8_after_escape" {
1393 err("[\"\\\x75\xc3\xa5\"]");1393 try err("[\"\\\x75\xc3\xa5\"]");
1394}1394}
13951395
1396test "n_string_invalid-utf-8-in-escape" {1396test "n_string_invalid-utf-8-in-escape" {
1397 err(1397 try err(
1398 \\["\uå"]1398 \\["\uå"]
1399 );1399 );
1400}1400}
14011401
1402test "n_string_leading_uescaped_thinspace" {1402test "n_string_leading_uescaped_thinspace" {
1403 err(1403 try err(
1404 \\[\u0020"asd"]1404 \\[\u0020"asd"]
1405 );1405 );
1406}1406}
14071407
1408test "n_string_no_quotes_with_bad_escape" {1408test "n_string_no_quotes_with_bad_escape" {
1409 err(1409 try err(
1410 \\[\n]1410 \\[\n]
1411 );1411 );
1412}1412}
14131413
1414test "n_string_single_doublequote" {1414test "n_string_single_doublequote" {
1415 err(1415 try err(
1416 \\"1416 \\"
1417 );1417 );
1418}1418}
14191419
1420test "n_string_single_quote" {1420test "n_string_single_quote" {
1421 err(1421 try err(
1422 \\['single quote']1422 \\['single quote']
1423 );1423 );
1424}1424}
14251425
1426test "n_string_single_string_no_double_quotes" {1426test "n_string_single_string_no_double_quotes" {
1427 err(1427 try err(
1428 \\abc1428 \\abc
1429 );1429 );
1430}1430}
14311431
1432test "n_string_start_escape_unclosed" {1432test "n_string_start_escape_unclosed" {
1433 err(1433 try err(
1434 \\["\1434 \\["\
1435 );1435 );
1436}1436}
14371437
1438test "n_string_unescaped_crtl_char" {1438test "n_string_unescaped_crtl_char" {
1439 err("[\"a\x00a\"]");1439 try err("[\"a\x00a\"]");
1440}1440}
14411441
1442test "n_string_unescaped_newline" {1442test "n_string_unescaped_newline" {
1443 err(1443 try err(
1444 \\["new1444 \\["new
1445 \\line"]1445 \\line"]
1446 );1446 );
1447}1447}
14481448
1449test "n_string_unescaped_tab" {1449test "n_string_unescaped_tab" {
1450 err("[\"\t\"]");1450 try err("[\"\t\"]");
1451}1451}
14521452
1453test "n_string_unicode_CapitalU" {1453test "n_string_unicode_CapitalU" {
1454 err(1454 try err(
1455 \\"\UA66D"1455 \\"\UA66D"
1456 );1456 );
1457}1457}
14581458
1459test "n_string_with_trailing_garbage" {1459test "n_string_with_trailing_garbage" {
1460 err(1460 try err(
1461 \\""x1461 \\""x
1462 );1462 );
1463}1463}
14641464
1465test "n_structure_100000_opening_arrays" {1465test "n_structure_100000_opening_arrays" {
1466 err("[" ** 100000);1466 try err("[" ** 100000);
1467}1467}
14681468
1469test "n_structure_angle_bracket_." {1469test "n_structure_angle_bracket_." {
1470 err(1470 try err(
1471 \\<.>1471 \\<.>
1472 );1472 );
1473}1473}
14741474
1475test "n_structure_angle_bracket_null" {1475test "n_structure_angle_bracket_null" {
1476 err(1476 try err(
1477 \\[<null>]1477 \\[<null>]
1478 );1478 );
1479}1479}
14801480
1481test "n_structure_array_trailing_garbage" {1481test "n_structure_array_trailing_garbage" {
1482 err(1482 try err(
1483 \\[1]x1483 \\[1]x
1484 );1484 );
1485}1485}
14861486
1487test "n_structure_array_with_extra_array_close" {1487test "n_structure_array_with_extra_array_close" {
1488 err(1488 try err(
1489 \\[1]]1489 \\[1]]
1490 );1490 );
1491}1491}
14921492
1493test "n_structure_array_with_unclosed_string" {1493test "n_structure_array_with_unclosed_string" {
1494 err(1494 try err(
1495 \\["asd]1495 \\["asd]
1496 );1496 );
1497}1497}
14981498
1499test "n_structure_ascii-unicode-identifier" {1499test "n_structure_ascii-unicode-identifier" {
1500 err(1500 try err(
1501 \\aå1501 \\aå
1502 );1502 );
1503}1503}
15041504
1505test "n_structure_capitalized_True" {1505test "n_structure_capitalized_True" {
1506 err(1506 try err(
1507 \\[True]1507 \\[True]
1508 );1508 );
1509}1509}
15101510
1511test "n_structure_close_unopened_array" {1511test "n_structure_close_unopened_array" {
1512 err(1512 try err(
1513 \\1]1513 \\1]
1514 );1514 );
1515}1515}
15161516
1517test "n_structure_comma_instead_of_closing_brace" {1517test "n_structure_comma_instead_of_closing_brace" {
1518 err(1518 try err(
1519 \\{"x": true,1519 \\{"x": true,
1520 );1520 );
1521}1521}
15221522
1523test "n_structure_double_array" {1523test "n_structure_double_array" {
1524 err(1524 try err(
1525 \\[][]1525 \\[][]
1526 );1526 );
1527}1527}
15281528
1529test "n_structure_end_array" {1529test "n_structure_end_array" {
1530 err(1530 try err(
1531 \\]1531 \\]
1532 );1532 );
1533}1533}
15341534
1535test "n_structure_incomplete_UTF8_BOM" {1535test "n_structure_incomplete_UTF8_BOM" {
1536 err(1536 try err(
1537 \\ï»{}1537 \\ï»{}
1538 );1538 );
1539}1539}
15401540
1541test "n_structure_lone-invalid-utf-8" {1541test "n_structure_lone-invalid-utf-8" {
1542 err(1542 try err(
1543 \\å1543 \\å
1544 );1544 );
1545}1545}
15461546
1547test "n_structure_lone-open-bracket" {1547test "n_structure_lone-open-bracket" {
1548 err(1548 try err(
1549 \\[1549 \\[
1550 );1550 );
1551}1551}
15521552
1553test "n_structure_no_data" {1553test "n_structure_no_data" {
1554 err(1554 try err(
1555 \\1555 \\
1556 );1556 );
1557}1557}
15581558
1559test "n_structure_null-byte-outside-string" {1559test "n_structure_null-byte-outside-string" {
1560 err("[\x00]");1560 try err("[\x00]");
1561}1561}
15621562
1563test "n_structure_number_with_trailing_garbage" {1563test "n_structure_number_with_trailing_garbage" {
1564 err(1564 try err(
1565 \\2@1565 \\2@
1566 );1566 );
1567}1567}
15681568
1569test "n_structure_object_followed_by_closing_object" {1569test "n_structure_object_followed_by_closing_object" {
1570 err(1570 try err(
1571 \\{}}1571 \\{}}
1572 );1572 );
1573}1573}
15741574
1575test "n_structure_object_unclosed_no_value" {1575test "n_structure_object_unclosed_no_value" {
1576 err(1576 try err(
1577 \\{"":1577 \\{"":
1578 );1578 );
1579}1579}
15801580
1581test "n_structure_object_with_comment" {1581test "n_structure_object_with_comment" {
1582 err(1582 try err(
1583 \\{"a":/*comment*/"b"}1583 \\{"a":/*comment*/"b"}
1584 );1584 );
1585}1585}
15861586
1587test "n_structure_object_with_trailing_garbage" {1587test "n_structure_object_with_trailing_garbage" {
1588 err(1588 try err(
1589 \\{"a": true} "x"1589 \\{"a": true} "x"
1590 );1590 );
1591}1591}
15921592
1593test "n_structure_open_array_apostrophe" {1593test "n_structure_open_array_apostrophe" {
1594 err(1594 try err(
1595 \\['1595 \\['
1596 );1596 );
1597}1597}
15981598
1599test "n_structure_open_array_comma" {1599test "n_structure_open_array_comma" {
1600 err(1600 try err(
1601 \\[,1601 \\[,
1602 );1602 );
1603}1603}
16041604
1605test "n_structure_open_array_object" {1605test "n_structure_open_array_object" {
1606 err("[{\"\":" ** 50000);1606 try err("[{\"\":" ** 50000);
1607}1607}
16081608
1609test "n_structure_open_array_open_object" {1609test "n_structure_open_array_open_object" {
1610 err(1610 try err(
1611 \\[{1611 \\[{
1612 );1612 );
1613}1613}
16141614
1615test "n_structure_open_array_open_string" {1615test "n_structure_open_array_open_string" {
1616 err(1616 try err(
1617 \\["a1617 \\["a
1618 );1618 );
1619}1619}
16201620
1621test "n_structure_open_array_string" {1621test "n_structure_open_array_string" {
1622 err(1622 try err(
1623 \\["a"1623 \\["a"
1624 );1624 );
1625}1625}
16261626
1627test "n_structure_open_object_close_array" {1627test "n_structure_open_object_close_array" {
1628 err(1628 try err(
1629 \\{]1629 \\{]
1630 );1630 );
1631}1631}
16321632
1633test "n_structure_open_object_comma" {1633test "n_structure_open_object_comma" {
1634 err(1634 try err(
1635 \\{,1635 \\{,
1636 );1636 );
1637}1637}
16381638
1639test "n_structure_open_object" {1639test "n_structure_open_object" {
1640 err(1640 try err(
1641 \\{1641 \\{
1642 );1642 );
1643}1643}
16441644
1645test "n_structure_open_object_open_array" {1645test "n_structure_open_object_open_array" {
1646 err(1646 try err(
1647 \\{[1647 \\{[
1648 );1648 );
1649}1649}
16501650
1651test "n_structure_open_object_open_string" {1651test "n_structure_open_object_open_string" {
1652 err(1652 try err(
1653 \\{"a1653 \\{"a
1654 );1654 );
1655}1655}
16561656
1657test "n_structure_open_object_string_with_apostrophes" {1657test "n_structure_open_object_string_with_apostrophes" {
1658 err(1658 try err(
1659 \\{'a'1659 \\{'a'
1660 );1660 );
1661}1661}
16621662
1663test "n_structure_open_open" {1663test "n_structure_open_open" {
1664 err(1664 try err(
1665 \\["\{["\{["\{["\{1665 \\["\{["\{["\{["\{
1666 );1666 );
1667}1667}
16681668
1669test "n_structure_single_eacute" {1669test "n_structure_single_eacute" {
1670 err(1670 try err(
1671 \\é1671 \\é
1672 );1672 );
1673}1673}
16741674
1675test "n_structure_single_star" {1675test "n_structure_single_star" {
1676 err(1676 try err(
1677 \\*1677 \\*
1678 );1678 );
1679}1679}
16801680
1681test "n_structure_trailing_#" {1681test "n_structure_trailing_#" {
1682 err(1682 try err(
1683 \\{"a":"b"}#{}1683 \\{"a":"b"}#{}
1684 );1684 );
1685}1685}
16861686
1687test "n_structure_U+2060_word_joined" {1687test "n_structure_U+2060_word_joined" {
1688 err(1688 try err(
1689 \\[⁠]1689 \\[⁠]
1690 );1690 );
1691}1691}
16921692
1693test "n_structure_uescaped_LF_before_string" {1693test "n_structure_uescaped_LF_before_string" {
1694 err(1694 try err(
1695 \\[\u000A""]1695 \\[\u000A""]
1696 );1696 );
1697}1697}
16981698
1699test "n_structure_unclosed_array" {1699test "n_structure_unclosed_array" {
1700 err(1700 try err(
1701 \\[11701 \\[1
1702 );1702 );
1703}1703}
17041704
1705test "n_structure_unclosed_array_partial_null" {1705test "n_structure_unclosed_array_partial_null" {
1706 err(1706 try err(
1707 \\[ false, nul1707 \\[ false, nul
1708 );1708 );
1709}1709}
17101710
1711test "n_structure_unclosed_array_unfinished_false" {1711test "n_structure_unclosed_array_unfinished_false" {
1712 err(1712 try err(
1713 \\[ true, fals1713 \\[ true, fals
1714 );1714 );
1715}1715}
17161716
1717test "n_structure_unclosed_array_unfinished_true" {1717test "n_structure_unclosed_array_unfinished_true" {
1718 err(1718 try err(
1719 \\[ false, tru1719 \\[ false, tru
1720 );1720 );
1721}1721}
17221722
1723test "n_structure_unclosed_object" {1723test "n_structure_unclosed_object" {
1724 err(1724 try err(
1725 \\{"asd":"asd"1725 \\{"asd":"asd"
1726 );1726 );
1727}1727}
17281728
1729test "n_structure_unicode-identifier" {1729test "n_structure_unicode-identifier" {
1730 err(1730 try err(
1731 \\Ã¥1731 \\Ã¥
1732 );1732 );
1733}1733}
17341734
1735test "n_structure_UTF8_BOM_no_data" {1735test "n_structure_UTF8_BOM_no_data" {
1736 err(1736 try err(
1737 \\1737 \\
1738 );1738 );
1739}1739}
17401740
1741test "n_structure_whitespace_formfeed" {1741test "n_structure_whitespace_formfeed" {
1742 err("[\x0c]");1742 try err("[\x0c]");
1743}1743}
17441744
1745test "n_structure_whitespace_U+2060_word_joiner" {1745test "n_structure_whitespace_U+2060_word_joiner" {
1746 err(1746 try err(
1747 \\[⁠]1747 \\[⁠]
1748 );1748 );
1749}1749}
...@@ -1751,255 +1751,255 @@ test "n_structure_whitespace_U+2060_word_joiner" {...@@ -1751,255 +1751,255 @@ test "n_structure_whitespace_U+2060_word_joiner" {
1751////////////////////////////////////////////////////////////////////////////////////////////////////1751////////////////////////////////////////////////////////////////////////////////////////////////////
17521752
1753test "i_number_double_huge_neg_exp" {1753test "i_number_double_huge_neg_exp" {
1754 any(1754 try any(
1755 \\[123.456e-789]1755 \\[123.456e-789]
1756 );1756 );
1757}1757}
17581758
1759test "i_number_huge_exp" {1759test "i_number_huge_exp" {
1760 any(1760 try any(
1761 \\[0.4e00669999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999969999999006]1761 \\[0.4e00669999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999969999999006]
1762 );1762 );
1763}1763}
17641764
1765test "i_number_neg_int_huge_exp" {1765test "i_number_neg_int_huge_exp" {
1766 any(1766 try any(
1767 \\[-1e+9999]1767 \\[-1e+9999]
1768 );1768 );
1769}1769}
17701770
1771test "i_number_pos_double_huge_exp" {1771test "i_number_pos_double_huge_exp" {
1772 any(1772 try any(
1773 \\[1.5e+9999]1773 \\[1.5e+9999]
1774 );1774 );
1775}1775}
17761776
1777test "i_number_real_neg_overflow" {1777test "i_number_real_neg_overflow" {
1778 any(1778 try any(
1779 \\[-123123e100000]1779 \\[-123123e100000]
1780 );1780 );
1781}1781}
17821782
1783test "i_number_real_pos_overflow" {1783test "i_number_real_pos_overflow" {
1784 any(1784 try any(
1785 \\[123123e100000]1785 \\[123123e100000]
1786 );1786 );
1787}1787}
17881788
1789test "i_number_real_underflow" {1789test "i_number_real_underflow" {
1790 any(1790 try any(
1791 \\[123e-10000000]1791 \\[123e-10000000]
1792 );1792 );
1793}1793}
17941794
1795test "i_number_too_big_neg_int" {1795test "i_number_too_big_neg_int" {
1796 any(1796 try any(
1797 \\[-123123123123123123123123123123]1797 \\[-123123123123123123123123123123]
1798 );1798 );
1799}1799}
18001800
1801test "i_number_too_big_pos_int" {1801test "i_number_too_big_pos_int" {
1802 any(1802 try any(
1803 \\[100000000000000000000]1803 \\[100000000000000000000]
1804 );1804 );
1805}1805}
18061806
1807test "i_number_very_big_negative_int" {1807test "i_number_very_big_negative_int" {
1808 any(1808 try any(
1809 \\[-237462374673276894279832749832423479823246327846]1809 \\[-237462374673276894279832749832423479823246327846]
1810 );1810 );
1811}1811}
18121812
1813test "i_object_key_lone_2nd_surrogate" {1813test "i_object_key_lone_2nd_surrogate" {
1814 anyStreamingErrNonStreaming(1814 try anyStreamingErrNonStreaming(
1815 \\{"\uDFAA":0}1815 \\{"\uDFAA":0}
1816 );1816 );
1817}1817}
18181818
1819test "i_string_1st_surrogate_but_2nd_missing" {1819test "i_string_1st_surrogate_but_2nd_missing" {
1820 anyStreamingErrNonStreaming(1820 try anyStreamingErrNonStreaming(
1821 \\["\uDADA"]1821 \\["\uDADA"]
1822 );1822 );
1823}1823}
18241824
1825test "i_string_1st_valid_surrogate_2nd_invalid" {1825test "i_string_1st_valid_surrogate_2nd_invalid" {
1826 anyStreamingErrNonStreaming(1826 try anyStreamingErrNonStreaming(
1827 \\["\uD888\u1234"]1827 \\["\uD888\u1234"]
1828 );1828 );
1829}1829}
18301830
1831test "i_string_incomplete_surrogate_and_escape_valid" {1831test "i_string_incomplete_surrogate_and_escape_valid" {
1832 anyStreamingErrNonStreaming(1832 try anyStreamingErrNonStreaming(
1833 \\["\uD800\n"]1833 \\["\uD800\n"]
1834 );1834 );
1835}1835}
18361836
1837test "i_string_incomplete_surrogate_pair" {1837test "i_string_incomplete_surrogate_pair" {
1838 anyStreamingErrNonStreaming(1838 try anyStreamingErrNonStreaming(
1839 \\["\uDd1ea"]1839 \\["\uDd1ea"]
1840 );1840 );
1841}1841}
18421842
1843test "i_string_incomplete_surrogates_escape_valid" {1843test "i_string_incomplete_surrogates_escape_valid" {
1844 anyStreamingErrNonStreaming(1844 try anyStreamingErrNonStreaming(
1845 \\["\uD800\uD800\n"]1845 \\["\uD800\uD800\n"]
1846 );1846 );
1847}1847}
18481848
1849test "i_string_invalid_lonely_surrogate" {1849test "i_string_invalid_lonely_surrogate" {
1850 anyStreamingErrNonStreaming(1850 try anyStreamingErrNonStreaming(
1851 \\["\ud800"]1851 \\["\ud800"]
1852 );1852 );
1853}1853}
18541854
1855test "i_string_invalid_surrogate" {1855test "i_string_invalid_surrogate" {
1856 anyStreamingErrNonStreaming(1856 try anyStreamingErrNonStreaming(
1857 \\["\ud800abc"]1857 \\["\ud800abc"]
1858 );1858 );
1859}1859}
18601860
1861test "i_string_invalid_utf-8" {1861test "i_string_invalid_utf-8" {
1862 any(1862 try any(
1863 \\["ÿ"]1863 \\["ÿ"]
1864 );1864 );
1865}1865}
18661866
1867test "i_string_inverted_surrogates_U+1D11E" {1867test "i_string_inverted_surrogates_U+1D11E" {
1868 anyStreamingErrNonStreaming(1868 try anyStreamingErrNonStreaming(
1869 \\["\uDd1e\uD834"]1869 \\["\uDd1e\uD834"]
1870 );1870 );
1871}1871}
18721872
1873test "i_string_iso_latin_1" {1873test "i_string_iso_latin_1" {
1874 any(1874 try any(
1875 \\["é"]1875 \\["é"]
1876 );1876 );
1877}1877}
18781878
1879test "i_string_lone_second_surrogate" {1879test "i_string_lone_second_surrogate" {
1880 anyStreamingErrNonStreaming(1880 try anyStreamingErrNonStreaming(
1881 \\["\uDFAA"]1881 \\["\uDFAA"]
1882 );1882 );
1883}1883}
18841884
1885test "i_string_lone_utf8_continuation_byte" {1885test "i_string_lone_utf8_continuation_byte" {
1886 any(1886 try any(
1887 \\[""]1887 \\[""]
1888 );1888 );
1889}1889}
18901890
1891test "i_string_not_in_unicode_range" {1891test "i_string_not_in_unicode_range" {
1892 any(1892 try any(
1893 \\["ô¿¿¿"]1893 \\["ô¿¿¿"]
1894 );1894 );
1895}1895}
18961896
1897test "i_string_overlong_sequence_2_bytes" {1897test "i_string_overlong_sequence_2_bytes" {
1898 any(1898 try any(
1899 \\["À¯"]1899 \\["À¯"]
1900 );1900 );
1901}1901}
19021902
1903test "i_string_overlong_sequence_6_bytes" {1903test "i_string_overlong_sequence_6_bytes" {
1904 any(1904 try any(
1905 \\["üƒ¿¿¿¿"]1905 \\["üƒ¿¿¿¿"]
1906 );1906 );
1907}1907}
19081908
1909test "i_string_overlong_sequence_6_bytes_null" {1909test "i_string_overlong_sequence_6_bytes_null" {
1910 any(1910 try any(
1911 \\["ü€€€€€"]1911 \\["ü€€€€€"]
1912 );1912 );
1913}1913}
19141914
1915test "i_string_truncated-utf-8" {1915test "i_string_truncated-utf-8" {
1916 any(1916 try any(
1917 \\["àÿ"]1917 \\["àÿ"]
1918 );1918 );
1919}1919}
19201920
1921test "i_string_utf16BE_no_BOM" {1921test "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");
1923}1923}
19241924
1925test "i_string_utf16LE_no_BOM" {1925test "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");
1927}1927}
19281928
1929test "i_string_UTF-16LE_with_BOM" {1929test "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");
1931}1931}
19321932
1933test "i_string_UTF-8_invalid_sequence" {1933test "i_string_UTF-8_invalid_sequence" {
1934 any(1934 try any(
1935 \\["日шú"]1935 \\["日шú"]
1936 );1936 );
1937}1937}
19381938
1939test "i_string_UTF8_surrogate_U+D800" {1939test "i_string_UTF8_surrogate_U+D800" {
1940 any(1940 try any(
1941 \\["í €"]1941 \\["í €"]
1942 );1942 );
1943}1943}
19441944
1945test "i_structure_500_nested_arrays" {1945test "i_structure_500_nested_arrays" {
1946 any(("[" ** 500) ++ ("]" ** 500));1946 try any(("[" ** 500) ++ ("]" ** 500));
1947}1947}
19481948
1949test "i_structure_UTF-8_BOM_empty_object" {1949test "i_structure_UTF-8_BOM_empty_object" {
1950 any(1950 try any(
1951 \\{}1951 \\{}
1952 );1952 );
1953}1953}
19541954
1955test "truncated UTF-8 sequence" {1955test "truncated UTF-8 sequence" {
1956 utf8Error("\"\xc2\"");1956 try utf8Error("\"\xc2\"");
1957 utf8Error("\"\xdf\"");1957 try utf8Error("\"\xdf\"");
1958 utf8Error("\"\xed\xa0\"");1958 try utf8Error("\"\xed\xa0\"");
1959 utf8Error("\"\xf0\x80\"");1959 try utf8Error("\"\xf0\x80\"");
1960 utf8Error("\"\xf0\x80\x80\"");1960 try utf8Error("\"\xf0\x80\x80\"");
1961}1961}
19621962
1963test "invalid continuation byte" {1963test "invalid continuation byte" {
1964 utf8Error("\"\xc2\x00\"");1964 try utf8Error("\"\xc2\x00\"");
1965 utf8Error("\"\xc2\x7f\"");1965 try utf8Error("\"\xc2\x7f\"");
1966 utf8Error("\"\xc2\xc0\"");1966 try utf8Error("\"\xc2\xc0\"");
1967 utf8Error("\"\xc3\xc1\"");1967 try utf8Error("\"\xc3\xc1\"");
1968 utf8Error("\"\xc4\xf5\"");1968 try utf8Error("\"\xc4\xf5\"");
1969 utf8Error("\"\xc5\xff\"");1969 try utf8Error("\"\xc5\xff\"");
1970 utf8Error("\"\xe4\x80\x00\"");1970 try utf8Error("\"\xe4\x80\x00\"");
1971 utf8Error("\"\xe5\x80\x10\"");1971 try utf8Error("\"\xe5\x80\x10\"");
1972 utf8Error("\"\xe6\x80\xc0\"");1972 try utf8Error("\"\xe6\x80\xc0\"");
1973 utf8Error("\"\xe7\x80\xf5\"");1973 try utf8Error("\"\xe7\x80\xf5\"");
1974 utf8Error("\"\xe8\x00\x80\"");1974 try utf8Error("\"\xe8\x00\x80\"");
1975 utf8Error("\"\xf2\x00\x80\x80\"");1975 try utf8Error("\"\xf2\x00\x80\x80\"");
1976 utf8Error("\"\xf0\x80\x00\x80\"");1976 try utf8Error("\"\xf0\x80\x00\x80\"");
1977 utf8Error("\"\xf1\x80\xc0\x80\"");1977 try utf8Error("\"\xf1\x80\xc0\x80\"");
1978 utf8Error("\"\xf2\x80\x80\x00\"");1978 try utf8Error("\"\xf2\x80\x80\x00\"");
1979 utf8Error("\"\xf3\x80\x80\xc0\"");1979 try utf8Error("\"\xf3\x80\x80\xc0\"");
1980 utf8Error("\"\xf4\x80\x80\xf5\"");1980 try utf8Error("\"\xf4\x80\x80\xf5\"");
1981}1981}
19821982
1983test "disallowed overlong form" {1983test "disallowed overlong form" {
1984 utf8Error("\"\xc0\x80\"");1984 try utf8Error("\"\xc0\x80\"");
1985 utf8Error("\"\xc0\x90\"");1985 try utf8Error("\"\xc0\x90\"");
1986 utf8Error("\"\xc1\x80\"");1986 try utf8Error("\"\xc1\x80\"");
1987 utf8Error("\"\xc1\x90\"");1987 try utf8Error("\"\xc1\x90\"");
1988 utf8Error("\"\xe0\x80\x80\"");1988 try utf8Error("\"\xe0\x80\x80\"");
1989 utf8Error("\"\xf0\x80\x80\x80\"");1989 try utf8Error("\"\xf0\x80\x80\x80\"");
1990}1990}
19911991
1992test "out of UTF-16 range" {1992test "out of UTF-16 range" {
1993 utf8Error("\"\xf4\x90\x80\x80\"");1993 try utf8Error("\"\xf4\x90\x80\x80\"");
1994 utf8Error("\"\xf5\x80\x80\x80\"");1994 try utf8Error("\"\xf5\x80\x80\x80\"");
1995 utf8Error("\"\xf6\x80\x80\x80\"");1995 try utf8Error("\"\xf6\x80\x80\x80\"");
1996 utf8Error("\"\xf7\x80\x80\x80\"");1996 try utf8Error("\"\xf7\x80\x80\x80\"");
1997 utf8Error("\"\xf8\x80\x80\x80\"");1997 try utf8Error("\"\xf8\x80\x80\x80\"");
1998 utf8Error("\"\xf9\x80\x80\x80\"");1998 try utf8Error("\"\xf9\x80\x80\x80\"");
1999 utf8Error("\"\xfa\x80\x80\x80\"");1999 try utf8Error("\"\xfa\x80\x80\x80\"");
2000 utf8Error("\"\xfb\x80\x80\x80\"");2000 try utf8Error("\"\xfb\x80\x80\x80\"");
2001 utf8Error("\"\xfc\x80\x80\x80\"");2001 try utf8Error("\"\xfc\x80\x80\x80\"");
2002 utf8Error("\"\xfd\x80\x80\x80\"");2002 try utf8Error("\"\xfd\x80\x80\x80\"");
2003 utf8Error("\"\xfe\x80\x80\x80\"");2003 try utf8Error("\"\xfe\x80\x80\x80\"");
2004 utf8Error("\"\xff\x80\x80\x80\"");2004 try utf8Error("\"\xff\x80\x80\x80\"");
2005}2005}
lib/std/json/write_stream.zig+1-1
...@@ -288,7 +288,7 @@ test "json write stream" {...@@ -288,7 +288,7 @@ test "json write stream" {
288 \\ "float": 3.5e+00288 \\ "float": 3.5e+00
289 \\}289 \\}
290 ;290 ;
291 std.testing.expect(std.mem.eql(u8, expected, result));291 try std.testing.expect(std.mem.eql(u8, expected, result));
292}292}
293293
294fn getJsonObject(allocator: *std.mem.Allocator) !std.json.Value {294fn getJsonObject(allocator: *std.mem.Allocator) !std.json.Value {
lib/std/leb128.zig+68-68
...@@ -152,22 +152,22 @@ test "writeUnsignedFixed" {...@@ -152,22 +152,22 @@ test "writeUnsignedFixed" {
152 {152 {
153 var buf: [4]u8 = undefined;153 var buf: [4]u8 = undefined;
154 writeUnsignedFixed(4, &buf, 0);154 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);
156 }156 }
157 {157 {
158 var buf: [4]u8 = undefined;158 var buf: [4]u8 = undefined;
159 writeUnsignedFixed(4, &buf, 1);159 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);
161 }161 }
162 {162 {
163 var buf: [4]u8 = undefined;163 var buf: [4]u8 = undefined;
164 writeUnsignedFixed(4, &buf, 1000);164 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);
166 }166 }
167 {167 {
168 var buf: [4]u8 = undefined;168 var buf: [4]u8 = undefined;
169 writeUnsignedFixed(4, &buf, 10000000);169 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);
171 }171 }
172}172}
173173
...@@ -212,44 +212,44 @@ fn test_read_uleb128_seq(comptime T: type, comptime N: usize, encoded: []const u...@@ -212,44 +212,44 @@ fn test_read_uleb128_seq(comptime T: type, comptime N: usize, encoded: []const u
212212
213test "deserialize signed LEB128" {213test "deserialize signed LEB128" {
214 // Truncated214 // 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
217 // Overflow217 // Overflow
218 testing.expectError(error.Overflow, test_read_ileb128(i8, "\x80\x80\x40"));218 try testing.expectError(error.Overflow, test_read_ileb128(i8, "\x80\x80\x40"));
219 testing.expectError(error.Overflow, test_read_ileb128(i16, "\x80\x80\x80\x40"));219 try 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"));220 try 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"));221 try 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"));222 try testing.expectError(error.Overflow, test_read_ileb128(i8, "\xff\x7e"));
223223
224 // Decode SLEB128224 // Decode SLEB128
225 testing.expect((try test_read_ileb128(i64, "\x00")) == 0);225 try testing.expect((try test_read_ileb128(i64, "\x00")) == 0);
226 testing.expect((try test_read_ileb128(i64, "\x01")) == 1);226 try testing.expect((try test_read_ileb128(i64, "\x01")) == 1);
227 testing.expect((try test_read_ileb128(i64, "\x3f")) == 63);227 try testing.expect((try test_read_ileb128(i64, "\x3f")) == 63);
228 testing.expect((try test_read_ileb128(i64, "\x40")) == -64);228 try testing.expect((try test_read_ileb128(i64, "\x40")) == -64);
229 testing.expect((try test_read_ileb128(i64, "\x41")) == -63);229 try testing.expect((try test_read_ileb128(i64, "\x41")) == -63);
230 testing.expect((try test_read_ileb128(i64, "\x7f")) == -1);230 try testing.expect((try test_read_ileb128(i64, "\x7f")) == -1);
231 testing.expect((try test_read_ileb128(i64, "\x80\x01")) == 128);231 try testing.expect((try test_read_ileb128(i64, "\x80\x01")) == 128);
232 testing.expect((try test_read_ileb128(i64, "\x81\x01")) == 129);232 try testing.expect((try test_read_ileb128(i64, "\x81\x01")) == 129);
233 testing.expect((try test_read_ileb128(i64, "\xff\x7e")) == -129);233 try testing.expect((try test_read_ileb128(i64, "\xff\x7e")) == -129);
234 testing.expect((try test_read_ileb128(i64, "\x80\x7f")) == -128);234 try testing.expect((try test_read_ileb128(i64, "\x80\x7f")) == -128);
235 testing.expect((try test_read_ileb128(i64, "\x81\x7f")) == -127);235 try testing.expect((try test_read_ileb128(i64, "\x81\x7f")) == -127);
236 testing.expect((try test_read_ileb128(i64, "\xc0\x00")) == 64);236 try testing.expect((try test_read_ileb128(i64, "\xc0\x00")) == 64);
237 testing.expect((try test_read_ileb128(i64, "\xc7\x9f\x7f")) == -12345);237 try testing.expect((try test_read_ileb128(i64, "\xc7\x9f\x7f")) == -12345);
238 testing.expect((try test_read_ileb128(i8, "\xff\x7f")) == -1);238 try testing.expect((try test_read_ileb128(i8, "\xff\x7f")) == -1);
239 testing.expect((try test_read_ileb128(i16, "\xff\xff\x7f")) == -1);239 try 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);240 try 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);241 try 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)));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 testing.expect((try test_read_ileb128(i64, "\x80\x80\x80\x80\x80\x80\x80\x80\x40")) == -0x4000000000000000);243 try 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);244 try testing.expect((try test_read_ileb128(i64, "\x80\x80\x80\x80\x80\x80\x80\x80\x80\x7f")) == -0x8000000000000000);
245245
246 // Decode unnormalized SLEB128 with extra padding bytes.246 // Decode unnormalized SLEB128 with extra padding bytes.
247 testing.expect((try test_read_ileb128(i64, "\x80\x00")) == 0);247 try testing.expect((try test_read_ileb128(i64, "\x80\x00")) == 0);
248 testing.expect((try test_read_ileb128(i64, "\x80\x80\x00")) == 0);248 try testing.expect((try test_read_ileb128(i64, "\x80\x80\x00")) == 0);
249 testing.expect((try test_read_ileb128(i64, "\xff\x00")) == 0x7f);249 try testing.expect((try test_read_ileb128(i64, "\xff\x00")) == 0x7f);
250 testing.expect((try test_read_ileb128(i64, "\xff\x80\x00")) == 0x7f);250 try testing.expect((try test_read_ileb128(i64, "\xff\x80\x00")) == 0x7f);
251 testing.expect((try test_read_ileb128(i64, "\x80\x81\x00")) == 0x80);251 try testing.expect((try test_read_ileb128(i64, "\x80\x81\x00")) == 0x80);
252 testing.expect((try test_read_ileb128(i64, "\x80\x81\x80\x00")) == 0x80);252 try testing.expect((try test_read_ileb128(i64, "\x80\x81\x80\x00")) == 0x80);
253253
254 // Decode sequence of SLEB128 values254 // Decode sequence of SLEB128 values
255 try test_read_ileb128_seq(i64, 4, "\x81\x01\x3f\x80\x7f\x80\x80\x80\x00");255 try test_read_ileb128_seq(i64, 4, "\x81\x01\x3f\x80\x7f\x80\x80\x80\x00");
...@@ -257,39 +257,39 @@ test "deserialize signed LEB128" {...@@ -257,39 +257,39 @@ test "deserialize signed LEB128" {
257257
258test "deserialize unsigned LEB128" {258test "deserialize unsigned LEB128" {
259 // Truncated259 // 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
262 // Overflow262 // Overflow
263 testing.expectError(error.Overflow, test_read_uleb128(u8, "\x80\x02"));263 try testing.expectError(error.Overflow, test_read_uleb128(u8, "\x80\x02"));
264 testing.expectError(error.Overflow, test_read_uleb128(u8, "\x80\x80\x40"));264 try testing.expectError(error.Overflow, test_read_uleb128(u8, "\x80\x80\x40"));
265 testing.expectError(error.Overflow, test_read_uleb128(u16, "\x80\x80\x84"));265 try testing.expectError(error.Overflow, test_read_uleb128(u16, "\x80\x80\x84"));
266 testing.expectError(error.Overflow, test_read_uleb128(u16, "\x80\x80\x80\x40"));266 try 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"));267 try 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"));268 try 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"));269 try testing.expectError(error.Overflow, test_read_uleb128(u64, "\x80\x80\x80\x80\x80\x80\x80\x80\x80\x40"));
270270
271 // Decode ULEB128271 // Decode ULEB128
272 testing.expect((try test_read_uleb128(u64, "\x00")) == 0);272 try testing.expect((try test_read_uleb128(u64, "\x00")) == 0);
273 testing.expect((try test_read_uleb128(u64, "\x01")) == 1);273 try testing.expect((try test_read_uleb128(u64, "\x01")) == 1);
274 testing.expect((try test_read_uleb128(u64, "\x3f")) == 63);274 try testing.expect((try test_read_uleb128(u64, "\x3f")) == 63);
275 testing.expect((try test_read_uleb128(u64, "\x40")) == 64);275 try testing.expect((try test_read_uleb128(u64, "\x40")) == 64);
276 testing.expect((try test_read_uleb128(u64, "\x7f")) == 0x7f);276 try testing.expect((try test_read_uleb128(u64, "\x7f")) == 0x7f);
277 testing.expect((try test_read_uleb128(u64, "\x80\x01")) == 0x80);277 try testing.expect((try test_read_uleb128(u64, "\x80\x01")) == 0x80);
278 testing.expect((try test_read_uleb128(u64, "\x81\x01")) == 0x81);278 try testing.expect((try test_read_uleb128(u64, "\x81\x01")) == 0x81);
279 testing.expect((try test_read_uleb128(u64, "\x90\x01")) == 0x90);279 try testing.expect((try test_read_uleb128(u64, "\x90\x01")) == 0x90);
280 testing.expect((try test_read_uleb128(u64, "\xff\x01")) == 0xff);280 try testing.expect((try test_read_uleb128(u64, "\xff\x01")) == 0xff);
281 testing.expect((try test_read_uleb128(u64, "\x80\x02")) == 0x100);281 try testing.expect((try test_read_uleb128(u64, "\x80\x02")) == 0x100);
282 testing.expect((try test_read_uleb128(u64, "\x81\x02")) == 0x101);282 try testing.expect((try test_read_uleb128(u64, "\x81\x02")) == 0x101);
283 testing.expect((try test_read_uleb128(u64, "\x80\xc1\x80\x80\x10")) == 4294975616);283 try 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);284 try testing.expect((try test_read_uleb128(u64, "\x80\x80\x80\x80\x80\x80\x80\x80\x80\x01")) == 0x8000000000000000);
285285
286 // Decode ULEB128 with extra padding bytes286 // Decode ULEB128 with extra padding bytes
287 testing.expect((try test_read_uleb128(u64, "\x80\x00")) == 0);287 try testing.expect((try test_read_uleb128(u64, "\x80\x00")) == 0);
288 testing.expect((try test_read_uleb128(u64, "\x80\x80\x00")) == 0);288 try testing.expect((try test_read_uleb128(u64, "\x80\x80\x00")) == 0);
289 testing.expect((try test_read_uleb128(u64, "\xff\x00")) == 0x7f);289 try testing.expect((try test_read_uleb128(u64, "\xff\x00")) == 0x7f);
290 testing.expect((try test_read_uleb128(u64, "\xff\x80\x00")) == 0x7f);290 try testing.expect((try test_read_uleb128(u64, "\xff\x80\x00")) == 0x7f);
291 testing.expect((try test_read_uleb128(u64, "\x80\x81\x00")) == 0x80);291 try testing.expect((try test_read_uleb128(u64, "\x80\x81\x00")) == 0x80);
292 testing.expect((try test_read_uleb128(u64, "\x80\x81\x80\x00")) == 0x80);292 try testing.expect((try test_read_uleb128(u64, "\x80\x81\x80\x00")) == 0x80);
293293
294 // Decode sequence of ULEB128 values294 // Decode sequence of ULEB128 values
295 try test_read_uleb128_seq(u64, 4, "\x81\x01\x3f\x80\x7f\x80\x80\x80\x00");295 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 {...@@ -326,19 +326,19 @@ fn test_write_leb128(value: anytype) !void {
326 // stream write326 // stream write
327 try writeStream(fbs.writer(), value);327 try writeStream(fbs.writer(), value);
328 const w1_pos = fbs.pos;328 const w1_pos = fbs.pos;
329 testing.expect(w1_pos == bytes_needed);329 try testing.expect(w1_pos == bytes_needed);
330330
331 // stream read331 // stream read
332 fbs.pos = 0;332 fbs.pos = 0;
333 const sr = try readStream(T, fbs.reader());333 const sr = try readStream(T, fbs.reader());
334 testing.expect(fbs.pos == w1_pos);334 try testing.expect(fbs.pos == w1_pos);
335 testing.expect(sr == value);335 try testing.expect(sr == value);
336336
337 // bigger type stream read337 // bigger type stream read
338 fbs.pos = 0;338 fbs.pos = 0;
339 const bsr = try readStream(B, fbs.reader());339 const bsr = try readStream(B, fbs.reader());
340 testing.expect(fbs.pos == w1_pos);340 try testing.expect(fbs.pos == w1_pos);
341 testing.expect(bsr == value);341 try testing.expect(bsr == value);
342}342}
343343
344test "serialize unsigned LEB128" {344test "serialize unsigned LEB128" {
lib/std/linked_list.zig+20-20
...@@ -123,7 +123,7 @@ test "basic SinglyLinkedList test" {...@@ -123,7 +123,7 @@ test "basic SinglyLinkedList test" {
123 const L = SinglyLinkedList(u32);123 const L = SinglyLinkedList(u32);
124 var list = L{};124 var list = L{};
125125
126 testing.expect(list.len() == 0);126 try testing.expect(list.len() == 0);
127127
128 var one = L.Node{ .data = 1 };128 var one = L.Node{ .data = 1 };
129 var two = L.Node{ .data = 2 };129 var two = L.Node{ .data = 2 };
...@@ -137,14 +137,14 @@ test "basic SinglyLinkedList test" {...@@ -137,14 +137,14 @@ test "basic SinglyLinkedList test" {
137 two.insertAfter(&three); // {1, 2, 3, 5}137 two.insertAfter(&three); // {1, 2, 3, 5}
138 three.insertAfter(&four); // {1, 2, 3, 4, 5}138 three.insertAfter(&four); // {1, 2, 3, 4, 5}
139139
140 testing.expect(list.len() == 5);140 try testing.expect(list.len() == 5);
141141
142 // Traverse forwards.142 // Traverse forwards.
143 {143 {
144 var it = list.first;144 var it = list.first;
145 var index: u32 = 1;145 var index: u32 = 1;
146 while (it) |node| : (it = node.next) {146 while (it) |node| : (it = node.next) {
147 testing.expect(node.data == index);147 try testing.expect(node.data == index);
148 index += 1;148 index += 1;
149 }149 }
150 }150 }
...@@ -153,9 +153,9 @@ test "basic SinglyLinkedList test" {...@@ -153,9 +153,9 @@ test "basic SinglyLinkedList test" {
153 _ = list.remove(&five); // {2, 3, 4}153 _ = list.remove(&five); // {2, 3, 4}
154 _ = two.removeNext(); // {2, 4}154 _ = two.removeNext(); // {2, 4}
155155
156 testing.expect(list.first.?.data == 2);156 try testing.expect(list.first.?.data == 2);
157 testing.expect(list.first.?.next.?.data == 4);157 try testing.expect(list.first.?.next.?.data == 4);
158 testing.expect(list.first.?.next.?.next == null);158 try testing.expect(list.first.?.next.?.next == null);
159}159}
160160
161/// A tail queue is headed by a pair of pointers, one to the head of the161/// A tail queue is headed by a pair of pointers, one to the head of the
...@@ -344,7 +344,7 @@ test "basic TailQueue test" {...@@ -344,7 +344,7 @@ test "basic TailQueue test" {
344 var it = list.first;344 var it = list.first;
345 var index: u32 = 1;345 var index: u32 = 1;
346 while (it) |node| : (it = node.next) {346 while (it) |node| : (it = node.next) {
347 testing.expect(node.data == index);347 try testing.expect(node.data == index);
348 index += 1;348 index += 1;
349 }349 }
350 }350 }
...@@ -354,7 +354,7 @@ test "basic TailQueue test" {...@@ -354,7 +354,7 @@ test "basic TailQueue test" {
354 var it = list.last;354 var it = list.last;
355 var index: u32 = 1;355 var index: u32 = 1;
356 while (it) |node| : (it = node.prev) {356 while (it) |node| : (it = node.prev) {
357 testing.expect(node.data == (6 - index));357 try testing.expect(node.data == (6 - index));
358 index += 1;358 index += 1;
359 }359 }
360 }360 }
...@@ -363,9 +363,9 @@ test "basic TailQueue test" {...@@ -363,9 +363,9 @@ test "basic TailQueue test" {
363 var last = list.pop(); // {2, 3, 4}363 var last = list.pop(); // {2, 3, 4}
364 list.remove(&three); // {2, 4}364 list.remove(&three); // {2, 4}
365365
366 testing.expect(list.first.?.data == 2);366 try testing.expect(list.first.?.data == 2);
367 testing.expect(list.last.?.data == 4);367 try testing.expect(list.last.?.data == 4);
368 testing.expect(list.len == 2);368 try testing.expect(list.len == 2);
369}369}
370370
371test "TailQueue concatenation" {371test "TailQueue concatenation" {
...@@ -387,18 +387,18 @@ test "TailQueue concatenation" {...@@ -387,18 +387,18 @@ test "TailQueue concatenation" {
387387
388 list1.concatByMoving(&list2);388 list1.concatByMoving(&list2);
389389
390 testing.expect(list1.last == &five);390 try testing.expect(list1.last == &five);
391 testing.expect(list1.len == 5);391 try testing.expect(list1.len == 5);
392 testing.expect(list2.first == null);392 try testing.expect(list2.first == null);
393 testing.expect(list2.last == null);393 try testing.expect(list2.last == null);
394 testing.expect(list2.len == 0);394 try testing.expect(list2.len == 0);
395395
396 // Traverse forwards.396 // Traverse forwards.
397 {397 {
398 var it = list1.first;398 var it = list1.first;
399 var index: u32 = 1;399 var index: u32 = 1;
400 while (it) |node| : (it = node.next) {400 while (it) |node| : (it = node.next) {
401 testing.expect(node.data == index);401 try testing.expect(node.data == index);
402 index += 1;402 index += 1;
403 }403 }
404 }404 }
...@@ -408,7 +408,7 @@ test "TailQueue concatenation" {...@@ -408,7 +408,7 @@ test "TailQueue concatenation" {
408 var it = list1.last;408 var it = list1.last;
409 var index: u32 = 1;409 var index: u32 = 1;
410 while (it) |node| : (it = node.prev) {410 while (it) |node| : (it = node.prev) {
411 testing.expect(node.data == (6 - index));411 try testing.expect(node.data == (6 - index));
412 index += 1;412 index += 1;
413 }413 }
414 }414 }
...@@ -421,7 +421,7 @@ test "TailQueue concatenation" {...@@ -421,7 +421,7 @@ test "TailQueue concatenation" {
421 var it = list2.first;421 var it = list2.first;
422 var index: u32 = 1;422 var index: u32 = 1;
423 while (it) |node| : (it = node.next) {423 while (it) |node| : (it = node.next) {
424 testing.expect(node.data == index);424 try testing.expect(node.data == index);
425 index += 1;425 index += 1;
426 }426 }
427 }427 }
...@@ -431,7 +431,7 @@ test "TailQueue concatenation" {...@@ -431,7 +431,7 @@ test "TailQueue concatenation" {
431 var it = list2.last;431 var it = list2.last;
432 var index: u32 = 1;432 var index: u32 = 1;
433 while (it) |node| : (it = node.prev) {433 while (it) |node| : (it = node.prev) {
434 testing.expect(node.data == (6 - index));434 try testing.expect(node.data == (6 - index));
435 index += 1;435 index += 1;
436 }436 }
437 }437 }
lib/std/math.zig+353-353
...@@ -177,20 +177,20 @@ test "approxEqAbs and approxEqRel" {...@@ -177,20 +177,20 @@ test "approxEqAbs and approxEqRel" {
177 else => unreachable,177 else => unreachable,
178 };178 };
179179
180 testing.expect(approxEqAbs(T, 0.0, 0.0, eps_value));180 try testing.expect(approxEqAbs(T, 0.0, 0.0, eps_value));
181 testing.expect(approxEqAbs(T, -0.0, -0.0, eps_value));181 try testing.expect(approxEqAbs(T, -0.0, -0.0, eps_value));
182 testing.expect(approxEqAbs(T, 0.0, -0.0, eps_value));182 try testing.expect(approxEqAbs(T, 0.0, -0.0, eps_value));
183 testing.expect(approxEqRel(T, 1.0, 1.0, sqrt_eps_value));183 try testing.expect(approxEqRel(T, 1.0, 1.0, sqrt_eps_value));
184 testing.expect(!approxEqRel(T, 1.0, 0.0, sqrt_eps_value));184 try 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));185 try 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));186 try 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));187 try testing.expect(!approxEqRel(T, 1.0, nan_value, sqrt_eps_value));
188 testing.expect(!approxEqRel(T, nan_value, nan_value, sqrt_eps_value));188 try testing.expect(!approxEqRel(T, nan_value, nan_value, sqrt_eps_value));
189 testing.expect(approxEqRel(T, inf_value, inf_value, sqrt_eps_value));189 try testing.expect(approxEqRel(T, inf_value, inf_value, sqrt_eps_value));
190 testing.expect(approxEqRel(T, min_value, min_value, sqrt_eps_value));190 try testing.expect(approxEqRel(T, min_value, min_value, sqrt_eps_value));
191 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 testing.expect(approxEqAbs(T, min_value, 0.0, eps_value * 2));192 try testing.expect(approxEqAbs(T, min_value, 0.0, eps_value * 2));
193 testing.expect(approxEqAbs(T, -min_value, 0.0, eps_value * 2));193 try testing.expect(approxEqAbs(T, -min_value, 0.0, eps_value * 2));
194 }194 }
195}195}
196196
...@@ -349,34 +349,34 @@ pub fn min(x: anytype, y: anytype) Min(@TypeOf(x), @TypeOf(y)) {...@@ -349,34 +349,34 @@ pub fn min(x: anytype, y: anytype) Min(@TypeOf(x), @TypeOf(y)) {
349}349}
350350
351test "math.min" {351test "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);
353 {353 {
354 var a: u16 = 999;354 var a: u16 = 999;
355 var b: u32 = 10;355 var b: u32 = 10;
356 var result = min(a, b);356 var result = min(a, b);
357 testing.expect(@TypeOf(result) == u16);357 try testing.expect(@TypeOf(result) == u16);
358 testing.expect(result == 10);358 try testing.expect(result == 10);
359 }359 }
360 {360 {
361 var a: f64 = 10.34;361 var a: f64 = 10.34;
362 var b: f32 = 999.12;362 var b: f32 = 999.12;
363 var result = min(a, b);363 var result = min(a, b);
364 testing.expect(@TypeOf(result) == f64);364 try testing.expect(@TypeOf(result) == f64);
365 testing.expect(result == 10.34);365 try testing.expect(result == 10.34);
366 }366 }
367 {367 {
368 var a: i8 = -127;368 var a: i8 = -127;
369 var b: i16 = -200;369 var b: i16 = -200;
370 var result = min(a, b);370 var result = min(a, b);
371 testing.expect(@TypeOf(result) == i16);371 try testing.expect(@TypeOf(result) == i16);
372 testing.expect(result == -200);372 try testing.expect(result == -200);
373 }373 }
374 {374 {
375 const a = 10.34;375 const a = 10.34;
376 var b: f32 = 999.12;376 var b: f32 = 999.12;
377 var result = min(a, b);377 var result = min(a, b);
378 testing.expect(@TypeOf(result) == f32);378 try testing.expect(@TypeOf(result) == f32);
379 testing.expect(result == 10.34);379 try testing.expect(result == 10.34);
380 }380 }
381}381}
382382
...@@ -385,7 +385,7 @@ pub fn max(x: anytype, y: anytype) @TypeOf(x, y) {...@@ -385,7 +385,7 @@ pub fn max(x: anytype, y: anytype) @TypeOf(x, y) {
385}385}
386386
387test "math.max" {387test "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);
389}389}
390390
391pub fn clamp(val: anytype, lower: anytype, upper: anytype) @TypeOf(val, lower, upper) {391pub 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...@@ -394,19 +394,19 @@ pub fn clamp(val: anytype, lower: anytype, upper: anytype) @TypeOf(val, lower, u
394}394}
395test "math.clamp" {395test "math.clamp" {
396 // Within range396 // 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);
398 // Below398 // 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);
400 // Above400 // 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
403 // Floating point403 // Floating point
404 testing.expect(std.math.clamp(@as(f32, 1.1), @as(f32, 0.0), @as(f32, 1.0)) == 1.0);404 try 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);405 try testing.expect(std.math.clamp(@as(f32, -127.5), @as(f32, -200), @as(f32, -100)) == -127.5);
406406
407 // Mix of comptime and non-comptime407 // Mix of comptime and non-comptime
408 var i: i32 = 1;408 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);
410}410}
411411
412pub fn mul(comptime T: type, a: T, b: T) (error{Overflow}!T) {412pub 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 {...@@ -461,17 +461,17 @@ pub fn shl(comptime T: type, a: T, shift_amt: anytype) T {
461}461}
462462
463test "math.shl" {463test "math.shl" {
464 testing.expect(shl(u8, 0b11111111, @as(usize, 3)) == 0b11111000);464 try testing.expect(shl(u8, 0b11111111, @as(usize, 3)) == 0b11111000);
465 testing.expect(shl(u8, 0b11111111, @as(usize, 8)) == 0);465 try testing.expect(shl(u8, 0b11111111, @as(usize, 8)) == 0);
466 testing.expect(shl(u8, 0b11111111, @as(usize, 9)) == 0);466 try testing.expect(shl(u8, 0b11111111, @as(usize, 9)) == 0);
467 testing.expect(shl(u8, 0b11111111, @as(isize, -2)) == 0b00111111);467 try testing.expect(shl(u8, 0b11111111, @as(isize, -2)) == 0b00111111);
468 testing.expect(shl(u8, 0b11111111, 3) == 0b11111000);468 try testing.expect(shl(u8, 0b11111111, 3) == 0b11111000);
469 testing.expect(shl(u8, 0b11111111, 8) == 0);469 try testing.expect(shl(u8, 0b11111111, 8) == 0);
470 testing.expect(shl(u8, 0b11111111, 9) == 0);470 try testing.expect(shl(u8, 0b11111111, 9) == 0);
471 testing.expect(shl(u8, 0b11111111, -2) == 0b00111111);471 try 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);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 testing.expect(shl(std.meta.Vector(1, u32), std.meta.Vector(1, u32){42}, @as(isize, -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 testing.expect(shl(std.meta.Vector(1, u32), std.meta.Vector(1, u32){42}, 33)[0] == 0);474 try testing.expect(shl(std.meta.Vector(1, u32), std.meta.Vector(1, u32){42}, 33)[0] == 0);
475}475}
476476
477/// Shifts right. Overflowed bits are truncated.477/// Shifts right. Overflowed bits are truncated.
...@@ -501,17 +501,17 @@ pub fn shr(comptime T: type, a: T, shift_amt: anytype) T {...@@ -501,17 +501,17 @@ pub fn shr(comptime T: type, a: T, shift_amt: anytype) T {
501}501}
502502
503test "math.shr" {503test "math.shr" {
504 testing.expect(shr(u8, 0b11111111, @as(usize, 3)) == 0b00011111);504 try testing.expect(shr(u8, 0b11111111, @as(usize, 3)) == 0b00011111);
505 testing.expect(shr(u8, 0b11111111, @as(usize, 8)) == 0);505 try testing.expect(shr(u8, 0b11111111, @as(usize, 8)) == 0);
506 testing.expect(shr(u8, 0b11111111, @as(usize, 9)) == 0);506 try testing.expect(shr(u8, 0b11111111, @as(usize, 9)) == 0);
507 testing.expect(shr(u8, 0b11111111, @as(isize, -2)) == 0b11111100);507 try testing.expect(shr(u8, 0b11111111, @as(isize, -2)) == 0b11111100);
508 testing.expect(shr(u8, 0b11111111, 3) == 0b00011111);508 try testing.expect(shr(u8, 0b11111111, 3) == 0b00011111);
509 testing.expect(shr(u8, 0b11111111, 8) == 0);509 try testing.expect(shr(u8, 0b11111111, 8) == 0);
510 testing.expect(shr(u8, 0b11111111, 9) == 0);510 try testing.expect(shr(u8, 0b11111111, 9) == 0);
511 testing.expect(shr(u8, 0b11111111, -2) == 0b11111100);511 try 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);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 testing.expect(shr(std.meta.Vector(1, u32), std.meta.Vector(1, u32){42}, @as(isize, -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 testing.expect(shr(std.meta.Vector(1, u32), std.meta.Vector(1, u32){42}, 33)[0] == 0);514 try testing.expect(shr(std.meta.Vector(1, u32), std.meta.Vector(1, u32){42}, 33)[0] == 0);
515}515}
516516
517/// Rotates right. Only unsigned values can be rotated.517/// Rotates right. Only unsigned values can be rotated.
...@@ -533,13 +533,13 @@ pub fn rotr(comptime T: type, x: T, r: anytype) T {...@@ -533,13 +533,13 @@ pub fn rotr(comptime T: type, x: T, r: anytype) T {
533}533}
534534
535test "math.rotr" {535test "math.rotr" {
536 testing.expect(rotr(u8, 0b00000001, @as(usize, 0)) == 0b00000001);536 try testing.expect(rotr(u8, 0b00000001, @as(usize, 0)) == 0b00000001);
537 testing.expect(rotr(u8, 0b00000001, @as(usize, 9)) == 0b10000000);537 try testing.expect(rotr(u8, 0b00000001, @as(usize, 9)) == 0b10000000);
538 testing.expect(rotr(u8, 0b00000001, @as(usize, 8)) == 0b00000001);538 try testing.expect(rotr(u8, 0b00000001, @as(usize, 8)) == 0b00000001);
539 testing.expect(rotr(u8, 0b00000001, @as(usize, 4)) == 0b00010000);539 try testing.expect(rotr(u8, 0b00000001, @as(usize, 4)) == 0b00010000);
540 testing.expect(rotr(u8, 0b00000001, @as(isize, -1)) == 0b00000010);540 try 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);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 testing.expect(rotr(std.meta.Vector(1, u32), std.meta.Vector(1, u32){1}, @as(isize, -1))[0] == @as(u32, 1) << 1);542 try testing.expect(rotr(std.meta.Vector(1, u32), std.meta.Vector(1, u32){1}, @as(isize, -1))[0] == @as(u32, 1) << 1);
543}543}
544544
545/// Rotates left. Only unsigned values can be rotated.545/// Rotates left. Only unsigned values can be rotated.
...@@ -561,13 +561,13 @@ pub fn rotl(comptime T: type, x: T, r: anytype) T {...@@ -561,13 +561,13 @@ pub fn rotl(comptime T: type, x: T, r: anytype) T {
561}561}
562562
563test "math.rotl" {563test "math.rotl" {
564 testing.expect(rotl(u8, 0b00000001, @as(usize, 0)) == 0b00000001);564 try testing.expect(rotl(u8, 0b00000001, @as(usize, 0)) == 0b00000001);
565 testing.expect(rotl(u8, 0b00000001, @as(usize, 9)) == 0b00000010);565 try testing.expect(rotl(u8, 0b00000001, @as(usize, 9)) == 0b00000010);
566 testing.expect(rotl(u8, 0b00000001, @as(usize, 8)) == 0b00000001);566 try testing.expect(rotl(u8, 0b00000001, @as(usize, 8)) == 0b00000001);
567 testing.expect(rotl(u8, 0b00000001, @as(usize, 4)) == 0b00010000);567 try testing.expect(rotl(u8, 0b00000001, @as(usize, 4)) == 0b00010000);
568 testing.expect(rotl(u8, 0b00000001, @as(isize, -1)) == 0b10000000);568 try 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);569 try 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);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);
571}571}
572572
573pub fn Log2Int(comptime T: type) type {573pub fn Log2Int(comptime T: type) type {
...@@ -598,62 +598,62 @@ pub fn IntFittingRange(comptime from: comptime_int, comptime to: comptime_int) t...@@ -598,62 +598,62 @@ pub fn IntFittingRange(comptime from: comptime_int, comptime to: comptime_int) t
598}598}
599599
600test "math.IntFittingRange" {600test "math.IntFittingRange" {
601 testing.expect(IntFittingRange(0, 0) == u0);601 try testing.expect(IntFittingRange(0, 0) == u0);
602 testing.expect(IntFittingRange(0, 1) == u1);602 try testing.expect(IntFittingRange(0, 1) == u1);
603 testing.expect(IntFittingRange(0, 2) == u2);603 try testing.expect(IntFittingRange(0, 2) == u2);
604 testing.expect(IntFittingRange(0, 3) == u2);604 try testing.expect(IntFittingRange(0, 3) == u2);
605 testing.expect(IntFittingRange(0, 4) == u3);605 try testing.expect(IntFittingRange(0, 4) == u3);
606 testing.expect(IntFittingRange(0, 7) == u3);606 try testing.expect(IntFittingRange(0, 7) == u3);
607 testing.expect(IntFittingRange(0, 8) == u4);607 try testing.expect(IntFittingRange(0, 8) == u4);
608 testing.expect(IntFittingRange(0, 9) == u4);608 try testing.expect(IntFittingRange(0, 9) == u4);
609 testing.expect(IntFittingRange(0, 15) == u4);609 try testing.expect(IntFittingRange(0, 15) == u4);
610 testing.expect(IntFittingRange(0, 16) == u5);610 try testing.expect(IntFittingRange(0, 16) == u5);
611 testing.expect(IntFittingRange(0, 17) == u5);611 try testing.expect(IntFittingRange(0, 17) == u5);
612 testing.expect(IntFittingRange(0, 4095) == u12);612 try testing.expect(IntFittingRange(0, 4095) == u12);
613 testing.expect(IntFittingRange(2000, 4095) == u12);613 try testing.expect(IntFittingRange(2000, 4095) == u12);
614 testing.expect(IntFittingRange(0, 4096) == u13);614 try testing.expect(IntFittingRange(0, 4096) == u13);
615 testing.expect(IntFittingRange(2000, 4096) == u13);615 try testing.expect(IntFittingRange(2000, 4096) == u13);
616 testing.expect(IntFittingRange(0, 4097) == u13);616 try testing.expect(IntFittingRange(0, 4097) == u13);
617 testing.expect(IntFittingRange(2000, 4097) == u13);617 try testing.expect(IntFittingRange(2000, 4097) == u13);
618 testing.expect(IntFittingRange(0, 123456789123456798123456789) == u87);618 try testing.expect(IntFittingRange(0, 123456789123456798123456789) == u87);
619 testing.expect(IntFittingRange(0, 123456789123456798123456789123456789123456798123456789) == u177);619 try testing.expect(IntFittingRange(0, 123456789123456798123456789123456789123456798123456789) == u177);
620620
621 testing.expect(IntFittingRange(-1, -1) == i1);621 try testing.expect(IntFittingRange(-1, -1) == i1);
622 testing.expect(IntFittingRange(-1, 0) == i1);622 try testing.expect(IntFittingRange(-1, 0) == i1);
623 testing.expect(IntFittingRange(-1, 1) == i2);623 try testing.expect(IntFittingRange(-1, 1) == i2);
624 testing.expect(IntFittingRange(-2, -2) == i2);624 try testing.expect(IntFittingRange(-2, -2) == i2);
625 testing.expect(IntFittingRange(-2, -1) == i2);625 try testing.expect(IntFittingRange(-2, -1) == i2);
626 testing.expect(IntFittingRange(-2, 0) == i2);626 try testing.expect(IntFittingRange(-2, 0) == i2);
627 testing.expect(IntFittingRange(-2, 1) == i2);627 try testing.expect(IntFittingRange(-2, 1) == i2);
628 testing.expect(IntFittingRange(-2, 2) == i3);628 try testing.expect(IntFittingRange(-2, 2) == i3);
629 testing.expect(IntFittingRange(-1, 2) == i3);629 try testing.expect(IntFittingRange(-1, 2) == i3);
630 testing.expect(IntFittingRange(-1, 3) == i3);630 try testing.expect(IntFittingRange(-1, 3) == i3);
631 testing.expect(IntFittingRange(-1, 4) == i4);631 try testing.expect(IntFittingRange(-1, 4) == i4);
632 testing.expect(IntFittingRange(-1, 7) == i4);632 try testing.expect(IntFittingRange(-1, 7) == i4);
633 testing.expect(IntFittingRange(-1, 8) == i5);633 try testing.expect(IntFittingRange(-1, 8) == i5);
634 testing.expect(IntFittingRange(-1, 9) == i5);634 try testing.expect(IntFittingRange(-1, 9) == i5);
635 testing.expect(IntFittingRange(-1, 15) == i5);635 try testing.expect(IntFittingRange(-1, 15) == i5);
636 testing.expect(IntFittingRange(-1, 16) == i6);636 try testing.expect(IntFittingRange(-1, 16) == i6);
637 testing.expect(IntFittingRange(-1, 17) == i6);637 try testing.expect(IntFittingRange(-1, 17) == i6);
638 testing.expect(IntFittingRange(-1, 4095) == i13);638 try testing.expect(IntFittingRange(-1, 4095) == i13);
639 testing.expect(IntFittingRange(-4096, 4095) == i13);639 try testing.expect(IntFittingRange(-4096, 4095) == i13);
640 testing.expect(IntFittingRange(-1, 4096) == i14);640 try testing.expect(IntFittingRange(-1, 4096) == i14);
641 testing.expect(IntFittingRange(-4097, 4095) == i14);641 try testing.expect(IntFittingRange(-4097, 4095) == i14);
642 testing.expect(IntFittingRange(-1, 4097) == i14);642 try testing.expect(IntFittingRange(-1, 4097) == i14);
643 testing.expect(IntFittingRange(-1, 123456789123456798123456789) == i88);643 try testing.expect(IntFittingRange(-1, 123456789123456798123456789) == i88);
644 testing.expect(IntFittingRange(-1, 123456789123456798123456789123456789123456798123456789) == i178);644 try testing.expect(IntFittingRange(-1, 123456789123456798123456789123456789123456798123456789) == i178);
645}645}
646646
647test "math overflow functions" {647test "math overflow functions" {
648 testOverflow();648 try testOverflow();
649 comptime testOverflow();649 comptime try testOverflow();
650}650}
651651
652fn testOverflow() void {652fn testOverflow() !void {
653 testing.expect((mul(i32, 3, 4) catch unreachable) == 12);653 try testing.expect((mul(i32, 3, 4) catch unreachable) == 12);
654 testing.expect((add(i32, 3, 4) catch unreachable) == 7);654 try testing.expect((add(i32, 3, 4) catch unreachable) == 7);
655 testing.expect((sub(i32, 3, 4) catch unreachable) == -1);655 try testing.expect((sub(i32, 3, 4) catch unreachable) == -1);
656 testing.expect((shlExact(i32, 0b11, 4) catch unreachable) == 0b110000);656 try testing.expect((shlExact(i32, 0b11, 4) catch unreachable) == 0b110000);
657}657}
658658
659pub fn absInt(x: anytype) !@TypeOf(x) {659pub fn absInt(x: anytype) !@TypeOf(x) {
...@@ -670,23 +670,23 @@ pub fn absInt(x: anytype) !@TypeOf(x) {...@@ -670,23 +670,23 @@ pub fn absInt(x: anytype) !@TypeOf(x) {
670}670}
671671
672test "math.absInt" {672test "math.absInt" {
673 testAbsInt();673 try testAbsInt();
674 comptime testAbsInt();674 comptime try testAbsInt();
675}675}
676fn testAbsInt() void {676fn testAbsInt() !void {
677 testing.expect((absInt(@as(i32, -10)) catch unreachable) == 10);677 try testing.expect((absInt(@as(i32, -10)) catch unreachable) == 10);
678 testing.expect((absInt(@as(i32, 10)) catch unreachable) == 10);678 try testing.expect((absInt(@as(i32, 10)) catch unreachable) == 10);
679}679}
680680
681pub const absFloat = fabs;681pub const absFloat = fabs;
682682
683test "math.absFloat" {683test "math.absFloat" {
684 testAbsFloat();684 try testAbsFloat();
685 comptime testAbsFloat();685 comptime try testAbsFloat();
686}686}
687fn testAbsFloat() void {687fn testAbsFloat() !void {
688 testing.expect(absFloat(@as(f32, -10.05)) == 10.05);688 try testing.expect(absFloat(@as(f32, -10.05)) == 10.05);
689 testing.expect(absFloat(@as(f32, 10.05)) == 10.05);689 try testing.expect(absFloat(@as(f32, 10.05)) == 10.05);
690}690}
691691
692pub fn divTrunc(comptime T: type, numerator: T, denominator: T) !T {692pub 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 {...@@ -697,17 +697,17 @@ pub fn divTrunc(comptime T: type, numerator: T, denominator: T) !T {
697}697}
698698
699test "math.divTrunc" {699test "math.divTrunc" {
700 testDivTrunc();700 try testDivTrunc();
701 comptime testDivTrunc();701 comptime try testDivTrunc();
702}702}
703fn testDivTrunc() void {703fn testDivTrunc() !void {
704 testing.expect((divTrunc(i32, 5, 3) catch unreachable) == 1);704 try testing.expect((divTrunc(i32, 5, 3) catch unreachable) == 1);
705 testing.expect((divTrunc(i32, -5, 3) catch unreachable) == -1);705 try testing.expect((divTrunc(i32, -5, 3) catch unreachable) == -1);
706 testing.expectError(error.DivisionByZero, divTrunc(i8, -5, 0));706 try testing.expectError(error.DivisionByZero, divTrunc(i8, -5, 0));
707 testing.expectError(error.Overflow, divTrunc(i8, -128, -1));707 try testing.expectError(error.Overflow, divTrunc(i8, -128, -1));
708708
709 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 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);
711}711}
712712
713pub fn divFloor(comptime T: type, numerator: T, denominator: T) !T {713pub 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 {...@@ -718,17 +718,17 @@ pub fn divFloor(comptime T: type, numerator: T, denominator: T) !T {
718}718}
719719
720test "math.divFloor" {720test "math.divFloor" {
721 testDivFloor();721 try testDivFloor();
722 comptime testDivFloor();722 comptime try testDivFloor();
723}723}
724fn testDivFloor() void {724fn testDivFloor() !void {
725 testing.expect((divFloor(i32, 5, 3) catch unreachable) == 1);725 try testing.expect((divFloor(i32, 5, 3) catch unreachable) == 1);
726 testing.expect((divFloor(i32, -5, 3) catch unreachable) == -2);726 try testing.expect((divFloor(i32, -5, 3) catch unreachable) == -2);
727 testing.expectError(error.DivisionByZero, divFloor(i8, -5, 0));727 try testing.expectError(error.DivisionByZero, divFloor(i8, -5, 0));
728 testing.expectError(error.Overflow, divFloor(i8, -128, -1));728 try testing.expectError(error.Overflow, divFloor(i8, -128, -1));
729729
730 testing.expect((divFloor(f32, 5.0, 3.0) catch unreachable) == 1.0);730 try 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);731 try testing.expect((divFloor(f32, -5.0, 3.0) catch unreachable) == -2.0);
732}732}
733733
734pub fn divCeil(comptime T: type, numerator: T, denominator: T) !T {734pub 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 {...@@ -752,36 +752,36 @@ pub fn divCeil(comptime T: type, numerator: T, denominator: T) !T {
752}752}
753753
754test "math.divCeil" {754test "math.divCeil" {
755 testDivCeil();755 try testDivCeil();
756 comptime testDivCeil();756 comptime try testDivCeil();
757}757}
758fn testDivCeil() void {758fn testDivCeil() !void {
759 testing.expectEqual(@as(i32, 2), divCeil(i32, 5, 3) catch unreachable);759 try testing.expectEqual(@as(i32, 2), divCeil(i32, 5, 3) catch unreachable);
760 testing.expectEqual(@as(i32, -1), divCeil(i32, -5, 3) catch unreachable);760 try testing.expectEqual(@as(i32, -1), divCeil(i32, -5, 3) catch unreachable);
761 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 testing.expectEqual(@as(i32, 2), divCeil(i32, -5, -3) catch unreachable);762 try testing.expectEqual(@as(i32, 2), divCeil(i32, -5, -3) catch unreachable);
763 testing.expectEqual(@as(i32, 0), divCeil(i32, 0, 5) catch unreachable);763 try testing.expectEqual(@as(i32, 0), divCeil(i32, 0, 5) catch unreachable);
764 testing.expectEqual(@as(u32, 0), divCeil(u32, 0, 5) catch unreachable);764 try testing.expectEqual(@as(u32, 0), divCeil(u32, 0, 5) catch unreachable);
765 testing.expectError(error.DivisionByZero, divCeil(i8, -5, 0));765 try testing.expectError(error.DivisionByZero, divCeil(i8, -5, 0));
766 testing.expectError(error.Overflow, divCeil(i8, -128, -1));766 try testing.expectError(error.Overflow, divCeil(i8, -128, -1));
767767
768 testing.expectEqual(@as(f32, 0.0), divCeil(f32, 0.0, 5.0) catch unreachable);768 try 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);769 try 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);770 try 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);771 try 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);772 try testing.expectEqual(@as(f32, 2.0), divCeil(f32, -5.0, -3.0) catch unreachable);
773773
774 testing.expectEqual(6, divCeil(comptime_int, 23, 4) catch unreachable);774 try testing.expectEqual(6, divCeil(comptime_int, 23, 4) catch unreachable);
775 testing.expectEqual(-5, divCeil(comptime_int, -23, 4) catch unreachable);775 try testing.expectEqual(-5, divCeil(comptime_int, -23, 4) catch unreachable);
776 testing.expectEqual(-5, divCeil(comptime_int, 23, -4) catch unreachable);776 try testing.expectEqual(-5, divCeil(comptime_int, 23, -4) catch unreachable);
777 testing.expectEqual(6, divCeil(comptime_int, -23, -4) catch unreachable);777 try testing.expectEqual(6, divCeil(comptime_int, -23, -4) catch unreachable);
778 testing.expectError(error.DivisionByZero, divCeil(comptime_int, 23, 0));778 try testing.expectError(error.DivisionByZero, divCeil(comptime_int, 23, 0));
779779
780 testing.expectEqual(6.0, divCeil(comptime_float, 23.0, 4.0) catch unreachable);780 try 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);781 try 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);782 try 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);783 try 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));784 try testing.expectError(error.DivisionByZero, divCeil(comptime_float, 23.0, 0.0));
785}785}
786786
787pub fn divExact(comptime T: type, numerator: T, denominator: T) !T {787pub 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 {...@@ -794,19 +794,19 @@ pub fn divExact(comptime T: type, numerator: T, denominator: T) !T {
794}794}
795795
796test "math.divExact" {796test "math.divExact" {
797 testDivExact();797 try testDivExact();
798 comptime testDivExact();798 comptime try testDivExact();
799}799}
800fn testDivExact() void {800fn testDivExact() !void {
801 testing.expect((divExact(i32, 10, 5) catch unreachable) == 2);801 try testing.expect((divExact(i32, 10, 5) catch unreachable) == 2);
802 testing.expect((divExact(i32, -10, 5) catch unreachable) == -2);802 try testing.expect((divExact(i32, -10, 5) catch unreachable) == -2);
803 testing.expectError(error.DivisionByZero, divExact(i8, -5, 0));803 try testing.expectError(error.DivisionByZero, divExact(i8, -5, 0));
804 testing.expectError(error.Overflow, divExact(i8, -128, -1));804 try testing.expectError(error.Overflow, divExact(i8, -128, -1));
805 testing.expectError(error.UnexpectedRemainder, divExact(i32, 5, 2));805 try testing.expectError(error.UnexpectedRemainder, divExact(i32, 5, 2));
806806
807 testing.expect((divExact(f32, 10.0, 5.0) catch unreachable) == 2.0);807 try 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);808 try testing.expect((divExact(f32, -10.0, 5.0) catch unreachable) == -2.0);
809 testing.expectError(error.UnexpectedRemainder, divExact(f32, 5.0, 2.0));809 try testing.expectError(error.UnexpectedRemainder, divExact(f32, 5.0, 2.0));
810}810}
811811
812pub fn mod(comptime T: type, numerator: T, denominator: T) !T {812pub 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 {...@@ -817,19 +817,19 @@ pub fn mod(comptime T: type, numerator: T, denominator: T) !T {
817}817}
818818
819test "math.mod" {819test "math.mod" {
820 testMod();820 try testMod();
821 comptime testMod();821 comptime try testMod();
822}822}
823fn testMod() void {823fn testMod() !void {
824 testing.expect((mod(i32, -5, 3) catch unreachable) == 1);824 try testing.expect((mod(i32, -5, 3) catch unreachable) == 1);
825 testing.expect((mod(i32, 5, 3) catch unreachable) == 2);825 try testing.expect((mod(i32, 5, 3) catch unreachable) == 2);
826 testing.expectError(error.NegativeDenominator, mod(i32, 10, -1));826 try testing.expectError(error.NegativeDenominator, mod(i32, 10, -1));
827 testing.expectError(error.DivisionByZero, mod(i32, 10, 0));827 try testing.expectError(error.DivisionByZero, mod(i32, 10, 0));
828828
829 testing.expect((mod(f32, -5, 3) catch unreachable) == 1);829 try testing.expect((mod(f32, -5, 3) catch unreachable) == 1);
830 testing.expect((mod(f32, 5, 3) catch unreachable) == 2);830 try testing.expect((mod(f32, 5, 3) catch unreachable) == 2);
831 testing.expectError(error.NegativeDenominator, mod(f32, 10, -1));831 try testing.expectError(error.NegativeDenominator, mod(f32, 10, -1));
832 testing.expectError(error.DivisionByZero, mod(f32, 10, 0));832 try testing.expectError(error.DivisionByZero, mod(f32, 10, 0));
833}833}
834834
835pub fn rem(comptime T: type, numerator: T, denominator: T) !T {835pub 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 {...@@ -840,19 +840,19 @@ pub fn rem(comptime T: type, numerator: T, denominator: T) !T {
840}840}
841841
842test "math.rem" {842test "math.rem" {
843 testRem();843 try testRem();
844 comptime testRem();844 comptime try testRem();
845}845}
846fn testRem() void {846fn testRem() !void {
847 testing.expect((rem(i32, -5, 3) catch unreachable) == -2);847 try testing.expect((rem(i32, -5, 3) catch unreachable) == -2);
848 testing.expect((rem(i32, 5, 3) catch unreachable) == 2);848 try testing.expect((rem(i32, 5, 3) catch unreachable) == 2);
849 testing.expectError(error.NegativeDenominator, rem(i32, 10, -1));849 try testing.expectError(error.NegativeDenominator, rem(i32, 10, -1));
850 testing.expectError(error.DivisionByZero, rem(i32, 10, 0));850 try testing.expectError(error.DivisionByZero, rem(i32, 10, 0));
851851
852 testing.expect((rem(f32, -5, 3) catch unreachable) == -2);852 try testing.expect((rem(f32, -5, 3) catch unreachable) == -2);
853 testing.expect((rem(f32, 5, 3) catch unreachable) == 2);853 try testing.expect((rem(f32, 5, 3) catch unreachable) == 2);
854 testing.expectError(error.NegativeDenominator, rem(f32, 10, -1));854 try testing.expectError(error.NegativeDenominator, rem(f32, 10, -1));
855 testing.expectError(error.DivisionByZero, rem(f32, 10, 0));855 try testing.expectError(error.DivisionByZero, rem(f32, 10, 0));
856}856}
857857
858/// Returns the absolute value of the integer parameter.858/// Returns the absolute value of the integer parameter.
...@@ -883,11 +883,11 @@ pub fn absCast(x: anytype) switch (@typeInfo(@TypeOf(x))) {...@@ -883,11 +883,11 @@ pub fn absCast(x: anytype) switch (@typeInfo(@TypeOf(x))) {
883}883}
884884
885test "math.absCast" {885test "math.absCast" {
886 testing.expectEqual(@as(u1, 1), absCast(@as(i1, -1)));886 try testing.expectEqual(@as(u1, 1), absCast(@as(i1, -1)));
887 testing.expectEqual(@as(u32, 999), absCast(@as(i32, -999)));887 try testing.expectEqual(@as(u32, 999), absCast(@as(i32, -999)));
888 testing.expectEqual(@as(u32, 999), absCast(@as(i32, 999)));888 try testing.expectEqual(@as(u32, 999), absCast(@as(i32, 999)));
889 testing.expectEqual(@as(u32, -minInt(i32)), absCast(@as(i32, minInt(i32))));889 try testing.expectEqual(@as(u32, -minInt(i32)), absCast(@as(i32, minInt(i32))));
890 testing.expectEqual(999, absCast(-999));890 try testing.expectEqual(999, absCast(-999));
891}891}
892892
893/// Returns the negation of the integer parameter.893/// 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...@@ -904,13 +904,13 @@ pub fn negateCast(x: anytype) !std.meta.Int(.signed, std.meta.bitCount(@TypeOf(x
904}904}
905905
906test "math.negateCast" {906test "math.negateCast" {
907 testing.expect((negateCast(@as(u32, 999)) catch unreachable) == -999);907 try testing.expect((negateCast(@as(u32, 999)) catch unreachable) == -999);
908 testing.expect(@TypeOf(negateCast(@as(u32, 999)) catch unreachable) == i32);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));910 try testing.expect((negateCast(@as(u32, -minInt(i32))) catch unreachable) == minInt(i32));
911 testing.expect(@TypeOf(negateCast(@as(u32, -minInt(i32))) catch unreachable) == 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)));
914}914}
915915
916/// Cast an integer to a different integer type. If the value doesn't fit,916/// 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) {...@@ -929,13 +929,13 @@ pub fn cast(comptime T: type, x: anytype) (error{Overflow}!T) {
929}929}
930930
931test "math.cast" {931test "math.cast" {
932 testing.expectError(error.Overflow, cast(u8, @as(u32, 300)));932 try testing.expectError(error.Overflow, cast(u8, @as(u32, 300)));
933 testing.expectError(error.Overflow, cast(i8, @as(i32, -200)));933 try testing.expectError(error.Overflow, cast(i8, @as(i32, -200)));
934 testing.expectError(error.Overflow, cast(u8, @as(i8, -1)));934 try testing.expectError(error.Overflow, cast(u8, @as(i8, -1)));
935 testing.expectError(error.Overflow, cast(u64, @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));937 try testing.expect((try cast(u8, @as(u32, 255))) == @as(u8, 255));
938 testing.expect(@TypeOf(try cast(u8, @as(u32, 255))) == u8);938 try testing.expect(@TypeOf(try cast(u8, @as(u32, 255))) == u8);
939}939}
940940
941pub const AlignCastError = error{UnalignedMemory};941pub const AlignCastError = error{UnalignedMemory};
...@@ -966,17 +966,17 @@ pub fn floorPowerOfTwo(comptime T: type, value: T) T {...@@ -966,17 +966,17 @@ pub fn floorPowerOfTwo(comptime T: type, value: T) T {
966}966}
967967
968test "math.floorPowerOfTwo" {968test "math.floorPowerOfTwo" {
969 testFloorPowerOfTwo();969 try testFloorPowerOfTwo();
970 comptime testFloorPowerOfTwo();970 comptime try testFloorPowerOfTwo();
971}971}
972972
973fn testFloorPowerOfTwo() void {973fn testFloorPowerOfTwo() !void {
974 testing.expect(floorPowerOfTwo(u32, 63) == 32);974 try testing.expect(floorPowerOfTwo(u32, 63) == 32);
975 testing.expect(floorPowerOfTwo(u32, 64) == 64);975 try testing.expect(floorPowerOfTwo(u32, 64) == 64);
976 testing.expect(floorPowerOfTwo(u32, 65) == 64);976 try testing.expect(floorPowerOfTwo(u32, 65) == 64);
977 testing.expect(floorPowerOfTwo(u4, 7) == 4);977 try testing.expect(floorPowerOfTwo(u4, 7) == 4);
978 testing.expect(floorPowerOfTwo(u4, 8) == 8);978 try testing.expect(floorPowerOfTwo(u4, 8) == 8);
979 testing.expect(floorPowerOfTwo(u4, 9) == 8);979 try testing.expect(floorPowerOfTwo(u4, 9) == 8);
980}980}
981981
982/// Returns the next power of two (if the value is not already a power of two).982/// 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 {...@@ -1012,20 +1012,20 @@ pub fn ceilPowerOfTwoAssert(comptime T: type, value: T) T {
1012}1012}
10131013
1014test "math.ceilPowerOfTwoPromote" {1014test "math.ceilPowerOfTwoPromote" {
1015 testCeilPowerOfTwoPromote();1015 try testCeilPowerOfTwoPromote();
1016 comptime testCeilPowerOfTwoPromote();1016 comptime try testCeilPowerOfTwoPromote();
1017}1017}
10181018
1019fn testCeilPowerOfTwoPromote() void {1019fn testCeilPowerOfTwoPromote() !void {
1020 testing.expectEqual(@as(u33, 1), ceilPowerOfTwoPromote(u32, 1));1020 try testing.expectEqual(@as(u33, 1), ceilPowerOfTwoPromote(u32, 1));
1021 testing.expectEqual(@as(u33, 2), ceilPowerOfTwoPromote(u32, 2));1021 try testing.expectEqual(@as(u33, 2), ceilPowerOfTwoPromote(u32, 2));
1022 testing.expectEqual(@as(u33, 64), ceilPowerOfTwoPromote(u32, 63));1022 try testing.expectEqual(@as(u33, 64), ceilPowerOfTwoPromote(u32, 63));
1023 testing.expectEqual(@as(u33, 64), ceilPowerOfTwoPromote(u32, 64));1023 try testing.expectEqual(@as(u33, 64), ceilPowerOfTwoPromote(u32, 64));
1024 testing.expectEqual(@as(u33, 128), ceilPowerOfTwoPromote(u32, 65));1024 try testing.expectEqual(@as(u33, 128), ceilPowerOfTwoPromote(u32, 65));
1025 testing.expectEqual(@as(u6, 8), ceilPowerOfTwoPromote(u5, 7));1025 try testing.expectEqual(@as(u6, 8), ceilPowerOfTwoPromote(u5, 7));
1026 testing.expectEqual(@as(u6, 8), ceilPowerOfTwoPromote(u5, 8));1026 try testing.expectEqual(@as(u6, 8), ceilPowerOfTwoPromote(u5, 8));
1027 testing.expectEqual(@as(u6, 16), ceilPowerOfTwoPromote(u5, 9));1027 try testing.expectEqual(@as(u6, 16), ceilPowerOfTwoPromote(u5, 9));
1028 testing.expectEqual(@as(u5, 16), ceilPowerOfTwoPromote(u4, 9));1028 try testing.expectEqual(@as(u5, 16), ceilPowerOfTwoPromote(u4, 9));
1029}1029}
10301030
1031test "math.ceilPowerOfTwo" {1031test "math.ceilPowerOfTwo" {
...@@ -1034,15 +1034,15 @@ test "math.ceilPowerOfTwo" {...@@ -1034,15 +1034,15 @@ test "math.ceilPowerOfTwo" {
1034}1034}
10351035
1036fn testCeilPowerOfTwo() !void {1036fn testCeilPowerOfTwo() !void {
1037 testing.expectEqual(@as(u32, 1), try ceilPowerOfTwo(u32, 1));1037 try testing.expectEqual(@as(u32, 1), try ceilPowerOfTwo(u32, 1));
1038 testing.expectEqual(@as(u32, 2), try ceilPowerOfTwo(u32, 2));1038 try testing.expectEqual(@as(u32, 2), try ceilPowerOfTwo(u32, 2));
1039 testing.expectEqual(@as(u32, 64), try ceilPowerOfTwo(u32, 63));1039 try testing.expectEqual(@as(u32, 64), try ceilPowerOfTwo(u32, 63));
1040 testing.expectEqual(@as(u32, 64), try ceilPowerOfTwo(u32, 64));1040 try testing.expectEqual(@as(u32, 64), try ceilPowerOfTwo(u32, 64));
1041 testing.expectEqual(@as(u32, 128), try ceilPowerOfTwo(u32, 65));1041 try testing.expectEqual(@as(u32, 128), try ceilPowerOfTwo(u32, 65));
1042 testing.expectEqual(@as(u5, 8), try ceilPowerOfTwo(u5, 7));1042 try testing.expectEqual(@as(u5, 8), try ceilPowerOfTwo(u5, 7));
1043 testing.expectEqual(@as(u5, 8), try ceilPowerOfTwo(u5, 8));1043 try testing.expectEqual(@as(u5, 8), try ceilPowerOfTwo(u5, 8));
1044 testing.expectEqual(@as(u5, 16), try ceilPowerOfTwo(u5, 9));1044 try testing.expectEqual(@as(u5, 16), try ceilPowerOfTwo(u5, 9));
1045 testing.expectError(error.Overflow, ceilPowerOfTwo(u4, 9));1045 try testing.expectError(error.Overflow, ceilPowerOfTwo(u4, 9));
1046}1046}
10471047
1048pub fn log2_int(comptime T: type, x: T) Log2Int(T) {1048pub 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) {...@@ -1059,16 +1059,16 @@ pub fn log2_int_ceil(comptime T: type, x: T) Log2Int(T) {
1059}1059}
10601060
1061test "std.math.log2_int_ceil" {1061test "std.math.log2_int_ceil" {
1062 testing.expect(log2_int_ceil(u32, 1) == 0);1062 try testing.expect(log2_int_ceil(u32, 1) == 0);
1063 testing.expect(log2_int_ceil(u32, 2) == 1);1063 try testing.expect(log2_int_ceil(u32, 2) == 1);
1064 testing.expect(log2_int_ceil(u32, 3) == 2);1064 try testing.expect(log2_int_ceil(u32, 3) == 2);
1065 testing.expect(log2_int_ceil(u32, 4) == 2);1065 try testing.expect(log2_int_ceil(u32, 4) == 2);
1066 testing.expect(log2_int_ceil(u32, 5) == 3);1066 try testing.expect(log2_int_ceil(u32, 5) == 3);
1067 testing.expect(log2_int_ceil(u32, 6) == 3);1067 try testing.expect(log2_int_ceil(u32, 6) == 3);
1068 testing.expect(log2_int_ceil(u32, 7) == 3);1068 try testing.expect(log2_int_ceil(u32, 7) == 3);
1069 testing.expect(log2_int_ceil(u32, 8) == 3);1069 try testing.expect(log2_int_ceil(u32, 8) == 3);
1070 testing.expect(log2_int_ceil(u32, 9) == 4);1070 try testing.expect(log2_int_ceil(u32, 9) == 4);
1071 testing.expect(log2_int_ceil(u32, 10) == 4);1071 try testing.expect(log2_int_ceil(u32, 10) == 4);
1072}1072}
10731073
1074///Cast a value to a different type. If the value doesn't fit in, or can't be perfectly represented by,1074///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 {...@@ -1112,15 +1112,15 @@ pub fn lossyCast(comptime T: type, value: anytype) T {
1112}1112}
11131113
1114test "math.lossyCast" {1114test "math.lossyCast" {
1115 testing.expect(lossyCast(i16, 70000.0) == @as(i16, 32767));1115 try testing.expect(lossyCast(i16, 70000.0) == @as(i16, 32767));
1116 testing.expect(lossyCast(u32, @as(i16, -255)) == @as(u32, 0));1116 try testing.expect(lossyCast(u32, @as(i16, -255)) == @as(u32, 0));
1117 testing.expect(lossyCast(i9, @as(u32, 200)) == @as(i9, 200));1117 try testing.expect(lossyCast(i9, @as(u32, 200)) == @as(i9, 200));
1118}1118}
11191119
1120test "math.f64_min" {1120test "math.f64_min" {
1121 const f64_min_u64 = 0x0010000000000000;1121 const f64_min_u64 = 0x0010000000000000;
1122 const fmin: f64 = f64_min;1122 const fmin: f64 = f64_min;
1123 testing.expect(@bitCast(u64, fmin) == f64_min_u64);1123 try testing.expect(@bitCast(u64, fmin) == f64_min_u64);
1124}1124}
11251125
1126pub fn maxInt(comptime T: type) comptime_int {1126pub fn maxInt(comptime T: type) comptime_int {
...@@ -1139,45 +1139,45 @@ pub fn minInt(comptime T: type) comptime_int {...@@ -1139,45 +1139,45 @@ pub fn minInt(comptime T: type) comptime_int {
1139}1139}
11401140
1141test "minInt and maxInt" {1141test "minInt and maxInt" {
1142 testing.expect(maxInt(u0) == 0);1142 try testing.expect(maxInt(u0) == 0);
1143 testing.expect(maxInt(u1) == 1);1143 try testing.expect(maxInt(u1) == 1);
1144 testing.expect(maxInt(u8) == 255);1144 try testing.expect(maxInt(u8) == 255);
1145 testing.expect(maxInt(u16) == 65535);1145 try testing.expect(maxInt(u16) == 65535);
1146 testing.expect(maxInt(u32) == 4294967295);1146 try testing.expect(maxInt(u32) == 4294967295);
1147 testing.expect(maxInt(u64) == 18446744073709551615);1147 try testing.expect(maxInt(u64) == 18446744073709551615);
1148 testing.expect(maxInt(u128) == 340282366920938463463374607431768211455);1148 try testing.expect(maxInt(u128) == 340282366920938463463374607431768211455);
11491149
1150 testing.expect(maxInt(i0) == 0);1150 try testing.expect(maxInt(i0) == 0);
1151 testing.expect(maxInt(i1) == 0);1151 try testing.expect(maxInt(i1) == 0);
1152 testing.expect(maxInt(i8) == 127);1152 try testing.expect(maxInt(i8) == 127);
1153 testing.expect(maxInt(i16) == 32767);1153 try testing.expect(maxInt(i16) == 32767);
1154 testing.expect(maxInt(i32) == 2147483647);1154 try testing.expect(maxInt(i32) == 2147483647);
1155 testing.expect(maxInt(i63) == 4611686018427387903);1155 try testing.expect(maxInt(i63) == 4611686018427387903);
1156 testing.expect(maxInt(i64) == 9223372036854775807);1156 try testing.expect(maxInt(i64) == 9223372036854775807);
1157 testing.expect(maxInt(i128) == 170141183460469231731687303715884105727);1157 try testing.expect(maxInt(i128) == 170141183460469231731687303715884105727);
11581158
1159 testing.expect(minInt(u0) == 0);1159 try testing.expect(minInt(u0) == 0);
1160 testing.expect(minInt(u1) == 0);1160 try testing.expect(minInt(u1) == 0);
1161 testing.expect(minInt(u8) == 0);1161 try testing.expect(minInt(u8) == 0);
1162 testing.expect(minInt(u16) == 0);1162 try testing.expect(minInt(u16) == 0);
1163 testing.expect(minInt(u32) == 0);1163 try testing.expect(minInt(u32) == 0);
1164 testing.expect(minInt(u63) == 0);1164 try testing.expect(minInt(u63) == 0);
1165 testing.expect(minInt(u64) == 0);1165 try testing.expect(minInt(u64) == 0);
1166 testing.expect(minInt(u128) == 0);1166 try testing.expect(minInt(u128) == 0);
11671167
1168 testing.expect(minInt(i0) == 0);1168 try testing.expect(minInt(i0) == 0);
1169 testing.expect(minInt(i1) == -1);1169 try testing.expect(minInt(i1) == -1);
1170 testing.expect(minInt(i8) == -128);1170 try testing.expect(minInt(i8) == -128);
1171 testing.expect(minInt(i16) == -32768);1171 try testing.expect(minInt(i16) == -32768);
1172 testing.expect(minInt(i32) == -2147483648);1172 try testing.expect(minInt(i32) == -2147483648);
1173 testing.expect(minInt(i63) == -4611686018427387904);1173 try testing.expect(minInt(i63) == -4611686018427387904);
1174 testing.expect(minInt(i64) == -9223372036854775808);1174 try testing.expect(minInt(i64) == -9223372036854775808);
1175 testing.expect(minInt(i128) == -170141183460469231731687303715884105728);1175 try testing.expect(minInt(i128) == -170141183460469231731687303715884105728);
1176}1176}
11771177
1178test "max value type" {1178test "max value type" {
1179 const x: u32 = maxInt(i32);1179 const x: u32 = maxInt(i32);
1180 testing.expect(x == 2147483647);1180 try testing.expect(x == 2147483647);
1181}1181}
11821182
1183pub fn mulWide(comptime T: type, a: T, b: T) std.meta.Int(@typeInfo(T).Int.signedness, @typeInfo(T).Int.bits * 2) {1183pub 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...@@ -1186,9 +1186,9 @@ pub fn mulWide(comptime T: type, a: T, b: T) std.meta.Int(@typeInfo(T).Int.signe
1186}1186}
11871187
1188test "math.mulWide" {1188test "math.mulWide" {
1189 testing.expect(mulWide(u8, 5, 5) == 25);1189 try testing.expect(mulWide(u8, 5, 5) == 25);
1190 testing.expect(mulWide(i8, 5, -5) == -25);1190 try testing.expect(mulWide(i8, 5, -5) == -25);
1191 testing.expect(mulWide(u8, 100, 100) == 10000);1191 try testing.expect(mulWide(u8, 100, 100) == 10000);
1192}1192}
11931193
1194/// See also `CompareOperator`.1194/// See also `CompareOperator`.
...@@ -1284,51 +1284,51 @@ pub fn compare(a: anytype, op: CompareOperator, b: anytype) bool {...@@ -1284,51 +1284,51 @@ pub fn compare(a: anytype, op: CompareOperator, b: anytype) bool {
1284}1284}
12851285
1286test "compare between signed and unsigned" {1286test "compare between signed and unsigned" {
1287 testing.expect(compare(@as(i8, -1), .lt, @as(u8, 255)));1287 try testing.expect(compare(@as(i8, -1), .lt, @as(u8, 255)));
1288 testing.expect(compare(@as(i8, 2), .gt, @as(u8, 1)));1288 try testing.expect(compare(@as(i8, 2), .gt, @as(u8, 1)));
1289 testing.expect(!compare(@as(i8, -1), .gte, @as(u8, 255)));1289 try testing.expect(!compare(@as(i8, -1), .gte, @as(u8, 255)));
1290 testing.expect(compare(@as(u8, 255), .gt, @as(i8, -1)));1290 try testing.expect(compare(@as(u8, 255), .gt, @as(i8, -1)));
1291 testing.expect(!compare(@as(u8, 255), .lte, @as(i8, -1)));1291 try testing.expect(!compare(@as(u8, 255), .lte, @as(i8, -1)));
1292 testing.expect(compare(@as(i8, -1), .lt, @as(u9, 255)));1292 try testing.expect(compare(@as(i8, -1), .lt, @as(u9, 255)));
1293 testing.expect(!compare(@as(i8, -1), .gte, @as(u9, 255)));1293 try testing.expect(!compare(@as(i8, -1), .gte, @as(u9, 255)));
1294 testing.expect(compare(@as(u9, 255), .gt, @as(i8, -1)));1294 try testing.expect(compare(@as(u9, 255), .gt, @as(i8, -1)));
1295 testing.expect(!compare(@as(u9, 255), .lte, @as(i8, -1)));1295 try testing.expect(!compare(@as(u9, 255), .lte, @as(i8, -1)));
1296 testing.expect(compare(@as(i9, -1), .lt, @as(u8, 255)));1296 try testing.expect(compare(@as(i9, -1), .lt, @as(u8, 255)));
1297 testing.expect(!compare(@as(i9, -1), .gte, @as(u8, 255)));1297 try testing.expect(!compare(@as(i9, -1), .gte, @as(u8, 255)));
1298 testing.expect(compare(@as(u8, 255), .gt, @as(i9, -1)));1298 try testing.expect(compare(@as(u8, 255), .gt, @as(i9, -1)));
1299 testing.expect(!compare(@as(u8, 255), .lte, @as(i9, -1)));1299 try testing.expect(!compare(@as(u8, 255), .lte, @as(i9, -1)));
1300 testing.expect(compare(@as(u8, 1), .lt, @as(u8, 2)));1300 try testing.expect(compare(@as(u8, 1), .lt, @as(u8, 2)));
1301 testing.expect(@bitCast(u8, @as(i8, -1)) == @as(u8, 255));1301 try testing.expect(@bitCast(u8, @as(i8, -1)) == @as(u8, 255));
1302 testing.expect(!compare(@as(u8, 255), .eq, @as(i8, -1)));1302 try testing.expect(!compare(@as(u8, 255), .eq, @as(i8, -1)));
1303 testing.expect(compare(@as(u8, 1), .eq, @as(u8, 1)));1303 try testing.expect(compare(@as(u8, 1), .eq, @as(u8, 1)));
1304}1304}
13051305
1306test "order" {1306test "order" {
1307 testing.expect(order(0, 0) == .eq);1307 try testing.expect(order(0, 0) == .eq);
1308 testing.expect(order(1, 0) == .gt);1308 try testing.expect(order(1, 0) == .gt);
1309 testing.expect(order(-1, 0) == .lt);1309 try testing.expect(order(-1, 0) == .lt);
1310}1310}
13111311
1312test "order.invert" {1312test "order.invert" {
1313 testing.expect(Order.invert(order(0, 0)) == .eq);1313 try testing.expect(Order.invert(order(0, 0)) == .eq);
1314 testing.expect(Order.invert(order(1, 0)) == .lt);1314 try testing.expect(Order.invert(order(1, 0)) == .lt);
1315 testing.expect(Order.invert(order(-1, 0)) == .gt);1315 try testing.expect(Order.invert(order(-1, 0)) == .gt);
1316}1316}
13171317
1318test "order.compare" {1318test "order.compare" {
1319 testing.expect(order(-1, 0).compare(.lt));1319 try testing.expect(order(-1, 0).compare(.lt));
1320 testing.expect(order(-1, 0).compare(.lte));1320 try testing.expect(order(-1, 0).compare(.lte));
1321 testing.expect(order(0, 0).compare(.lte));1321 try testing.expect(order(0, 0).compare(.lte));
1322 testing.expect(order(0, 0).compare(.eq));1322 try testing.expect(order(0, 0).compare(.eq));
1323 testing.expect(order(0, 0).compare(.gte));1323 try testing.expect(order(0, 0).compare(.gte));
1324 testing.expect(order(1, 0).compare(.gte));1324 try testing.expect(order(1, 0).compare(.gte));
1325 testing.expect(order(1, 0).compare(.gt));1325 try testing.expect(order(1, 0).compare(.gt));
1326 testing.expect(order(1, 0).compare(.neq));1326 try testing.expect(order(1, 0).compare(.neq));
1327}1327}
13281328
1329test "math.comptime" {1329test "math.comptime" {
1330 const v = comptime (sin(@as(f32, 1)) + ln(@as(f32, 5)));1330 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)));
1332}1332}
13331333
1334/// Returns a mask of all ones if value is true,1334/// 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 {...@@ -1354,26 +1354,26 @@ pub fn boolMask(comptime MaskInt: type, value: bool) callconv(.Inline) MaskInt {
13541354
1355test "boolMask" {1355test "boolMask" {
1356 const runTest = struct {1356 const runTest = struct {
1357 fn runTest() void {1357 fn runTest() !void {
1358 testing.expectEqual(@as(u1, 0), boolMask(u1, false));1358 try testing.expectEqual(@as(u1, 0), boolMask(u1, false));
1359 testing.expectEqual(@as(u1, 1), boolMask(u1, true));1359 try testing.expectEqual(@as(u1, 1), boolMask(u1, true));
13601360
1361 testing.expectEqual(@as(i1, 0), boolMask(i1, false));1361 try testing.expectEqual(@as(i1, 0), boolMask(i1, false));
1362 testing.expectEqual(@as(i1, -1), boolMask(i1, true));1362 try testing.expectEqual(@as(i1, -1), boolMask(i1, true));
13631363
1364 testing.expectEqual(@as(u13, 0), boolMask(u13, false));1364 try testing.expectEqual(@as(u13, 0), boolMask(u13, false));
1365 testing.expectEqual(@as(u13, 0x1FFF), boolMask(u13, true));1365 try testing.expectEqual(@as(u13, 0x1FFF), boolMask(u13, true));
13661366
1367 testing.expectEqual(@as(i13, 0), boolMask(i13, false));1367 try testing.expectEqual(@as(i13, 0), boolMask(i13, false));
1368 testing.expectEqual(@as(i13, -1), boolMask(i13, true));1368 try testing.expectEqual(@as(i13, -1), boolMask(i13, true));
13691369
1370 testing.expectEqual(@as(u32, 0), boolMask(u32, false));1370 try testing.expectEqual(@as(u32, 0), boolMask(u32, false));
1371 testing.expectEqual(@as(u32, 0xFFFF_FFFF), boolMask(u32, true));1371 try testing.expectEqual(@as(u32, 0xFFFF_FFFF), boolMask(u32, true));
13721372
1373 testing.expectEqual(@as(i32, 0), boolMask(i32, false));1373 try testing.expectEqual(@as(i32, 0), boolMask(i32, false));
1374 testing.expectEqual(@as(i32, -1), boolMask(i32, true));1374 try testing.expectEqual(@as(i32, -1), boolMask(i32, true));
1375 }1375 }
1376 }.runTest;1376 }.runTest;
1377 runTest();1377 try runTest();
1378 comptime runTest();1378 comptime try runTest();
1379}1379}
lib/std/math/acos.zig+18-18
...@@ -154,38 +154,38 @@ fn acos64(x: f64) f64 {...@@ -154,38 +154,38 @@ fn acos64(x: f64) f64 {
154}154}
155155
156test "math.acos" {156test "math.acos" {
157 expect(acos(@as(f32, 0.0)) == acos32(0.0));157 try expect(acos(@as(f32, 0.0)) == acos32(0.0));
158 expect(acos(@as(f64, 0.0)) == acos64(0.0));158 try expect(acos(@as(f64, 0.0)) == acos64(0.0));
159}159}
160160
161test "math.acos32" {161test "math.acos32" {
162 const epsilon = 0.000001;162 const epsilon = 0.000001;
163163
164 expect(math.approxEqAbs(f32, acos32(0.0), 1.570796, epsilon));164 try expect(math.approxEqAbs(f32, acos32(0.0), 1.570796, epsilon));
165 expect(math.approxEqAbs(f32, acos32(0.2), 1.369438, epsilon));165 try expect(math.approxEqAbs(f32, acos32(0.2), 1.369438, epsilon));
166 expect(math.approxEqAbs(f32, acos32(0.3434), 1.220262, epsilon));166 try expect(math.approxEqAbs(f32, acos32(0.3434), 1.220262, epsilon));
167 expect(math.approxEqAbs(f32, acos32(0.5), 1.047198, epsilon));167 try expect(math.approxEqAbs(f32, acos32(0.5), 1.047198, epsilon));
168 expect(math.approxEqAbs(f32, acos32(0.8923), 0.468382, epsilon));168 try expect(math.approxEqAbs(f32, acos32(0.8923), 0.468382, epsilon));
169 expect(math.approxEqAbs(f32, acos32(-0.2), 1.772154, epsilon));169 try expect(math.approxEqAbs(f32, acos32(-0.2), 1.772154, epsilon));
170}170}
171171
172test "math.acos64" {172test "math.acos64" {
173 const epsilon = 0.000001;173 const epsilon = 0.000001;
174174
175 expect(math.approxEqAbs(f64, acos64(0.0), 1.570796, epsilon));175 try expect(math.approxEqAbs(f64, acos64(0.0), 1.570796, epsilon));
176 expect(math.approxEqAbs(f64, acos64(0.2), 1.369438, epsilon));176 try expect(math.approxEqAbs(f64, acos64(0.2), 1.369438, epsilon));
177 expect(math.approxEqAbs(f64, acos64(0.3434), 1.220262, epsilon));177 try expect(math.approxEqAbs(f64, acos64(0.3434), 1.220262, epsilon));
178 expect(math.approxEqAbs(f64, acos64(0.5), 1.047198, epsilon));178 try expect(math.approxEqAbs(f64, acos64(0.5), 1.047198, epsilon));
179 expect(math.approxEqAbs(f64, acos64(0.8923), 0.468382, epsilon));179 try expect(math.approxEqAbs(f64, acos64(0.8923), 0.468382, epsilon));
180 expect(math.approxEqAbs(f64, acos64(-0.2), 1.772154, epsilon));180 try expect(math.approxEqAbs(f64, acos64(-0.2), 1.772154, epsilon));
181}181}
182182
183test "math.acos32.special" {183test "math.acos32.special" {
184 expect(math.isNan(acos32(-2)));184 try expect(math.isNan(acos32(-2)));
185 expect(math.isNan(acos32(1.5)));185 try expect(math.isNan(acos32(1.5)));
186}186}
187187
188test "math.acos64.special" {188test "math.acos64.special" {
189 expect(math.isNan(acos64(-2)));189 try expect(math.isNan(acos64(-2)));
190 expect(math.isNan(acos64(1.5)));190 try expect(math.isNan(acos64(1.5)));
191}191}
lib/std/math/acosh.zig+14-14
...@@ -65,34 +65,34 @@ fn acosh64(x: f64) f64 {...@@ -65,34 +65,34 @@ fn acosh64(x: f64) f64 {
65}65}
6666
67test "math.acosh" {67test "math.acosh" {
68 expect(acosh(@as(f32, 1.5)) == acosh32(1.5));68 try expect(acosh(@as(f32, 1.5)) == acosh32(1.5));
69 expect(acosh(@as(f64, 1.5)) == acosh64(1.5));69 try expect(acosh(@as(f64, 1.5)) == acosh64(1.5));
70}70}
7171
72test "math.acosh32" {72test "math.acosh32" {
73 const epsilon = 0.000001;73 const epsilon = 0.000001;
7474
75 expect(math.approxEqAbs(f32, acosh32(1.5), 0.962424, epsilon));75 try expect(math.approxEqAbs(f32, acosh32(1.5), 0.962424, epsilon));
76 expect(math.approxEqAbs(f32, acosh32(37.45), 4.315976, epsilon));76 try expect(math.approxEqAbs(f32, acosh32(37.45), 4.315976, epsilon));
77 expect(math.approxEqAbs(f32, acosh32(89.123), 5.183133, epsilon));77 try expect(math.approxEqAbs(f32, acosh32(89.123), 5.183133, epsilon));
78 expect(math.approxEqAbs(f32, acosh32(123123.234375), 12.414088, epsilon));78 try expect(math.approxEqAbs(f32, acosh32(123123.234375), 12.414088, epsilon));
79}79}
8080
81test "math.acosh64" {81test "math.acosh64" {
82 const epsilon = 0.000001;82 const epsilon = 0.000001;
8383
84 expect(math.approxEqAbs(f64, acosh64(1.5), 0.962424, epsilon));84 try expect(math.approxEqAbs(f64, acosh64(1.5), 0.962424, epsilon));
85 expect(math.approxEqAbs(f64, acosh64(37.45), 4.315976, epsilon));85 try expect(math.approxEqAbs(f64, acosh64(37.45), 4.315976, epsilon));
86 expect(math.approxEqAbs(f64, acosh64(89.123), 5.183133, epsilon));86 try expect(math.approxEqAbs(f64, acosh64(89.123), 5.183133, epsilon));
87 expect(math.approxEqAbs(f64, acosh64(123123.234375), 12.414088, epsilon));87 try expect(math.approxEqAbs(f64, acosh64(123123.234375), 12.414088, epsilon));
88}88}
8989
90test "math.acosh32.special" {90test "math.acosh32.special" {
91 expect(math.isNan(acosh32(math.nan(f32))));91 try expect(math.isNan(acosh32(math.nan(f32))));
92 expect(math.isSignalNan(acosh32(0.5)));92 try expect(math.isSignalNan(acosh32(0.5)));
93}93}
9494
95test "math.acosh64.special" {95test "math.acosh64.special" {
96 expect(math.isNan(acosh64(math.nan(f64))));96 try expect(math.isNan(acosh64(math.nan(f64))));
97 expect(math.isSignalNan(acosh64(0.5)));97 try expect(math.isSignalNan(acosh64(0.5)));
98}98}
lib/std/math/asin.zig+22-22
...@@ -147,42 +147,42 @@ fn asin64(x: f64) f64 {...@@ -147,42 +147,42 @@ fn asin64(x: f64) f64 {
147}147}
148148
149test "math.asin" {149test "math.asin" {
150 expect(asin(@as(f32, 0.0)) == asin32(0.0));150 try expect(asin(@as(f32, 0.0)) == asin32(0.0));
151 expect(asin(@as(f64, 0.0)) == asin64(0.0));151 try expect(asin(@as(f64, 0.0)) == asin64(0.0));
152}152}
153153
154test "math.asin32" {154test "math.asin32" {
155 const epsilon = 0.000001;155 const epsilon = 0.000001;
156156
157 expect(math.approxEqAbs(f32, asin32(0.0), 0.0, epsilon));157 try expect(math.approxEqAbs(f32, asin32(0.0), 0.0, epsilon));
158 expect(math.approxEqAbs(f32, asin32(0.2), 0.201358, epsilon));158 try expect(math.approxEqAbs(f32, asin32(0.2), 0.201358, epsilon));
159 expect(math.approxEqAbs(f32, asin32(-0.2), -0.201358, epsilon));159 try expect(math.approxEqAbs(f32, asin32(-0.2), -0.201358, epsilon));
160 expect(math.approxEqAbs(f32, asin32(0.3434), 0.350535, epsilon));160 try expect(math.approxEqAbs(f32, asin32(0.3434), 0.350535, epsilon));
161 expect(math.approxEqAbs(f32, asin32(0.5), 0.523599, epsilon));161 try expect(math.approxEqAbs(f32, asin32(0.5), 0.523599, epsilon));
162 expect(math.approxEqAbs(f32, asin32(0.8923), 1.102415, epsilon));162 try expect(math.approxEqAbs(f32, asin32(0.8923), 1.102415, epsilon));
163}163}
164164
165test "math.asin64" {165test "math.asin64" {
166 const epsilon = 0.000001;166 const epsilon = 0.000001;
167167
168 expect(math.approxEqAbs(f64, asin64(0.0), 0.0, epsilon));168 try expect(math.approxEqAbs(f64, asin64(0.0), 0.0, epsilon));
169 expect(math.approxEqAbs(f64, asin64(0.2), 0.201358, epsilon));169 try expect(math.approxEqAbs(f64, asin64(0.2), 0.201358, epsilon));
170 expect(math.approxEqAbs(f64, asin64(-0.2), -0.201358, epsilon));170 try expect(math.approxEqAbs(f64, asin64(-0.2), -0.201358, epsilon));
171 expect(math.approxEqAbs(f64, asin64(0.3434), 0.350535, epsilon));171 try expect(math.approxEqAbs(f64, asin64(0.3434), 0.350535, epsilon));
172 expect(math.approxEqAbs(f64, asin64(0.5), 0.523599, epsilon));172 try expect(math.approxEqAbs(f64, asin64(0.5), 0.523599, epsilon));
173 expect(math.approxEqAbs(f64, asin64(0.8923), 1.102415, epsilon));173 try expect(math.approxEqAbs(f64, asin64(0.8923), 1.102415, epsilon));
174}174}
175175
176test "math.asin32.special" {176test "math.asin32.special" {
177 expect(asin32(0.0) == 0.0);177 try expect(asin32(0.0) == 0.0);
178 expect(asin32(-0.0) == -0.0);178 try expect(asin32(-0.0) == -0.0);
179 expect(math.isNan(asin32(-2)));179 try expect(math.isNan(asin32(-2)));
180 expect(math.isNan(asin32(1.5)));180 try expect(math.isNan(asin32(1.5)));
181}181}
182182
183test "math.asin64.special" {183test "math.asin64.special" {
184 expect(asin64(0.0) == 0.0);184 try expect(asin64(0.0) == 0.0);
185 expect(asin64(-0.0) == -0.0);185 try expect(asin64(-0.0) == -0.0);
186 expect(math.isNan(asin64(-2)));186 try expect(math.isNan(asin64(-2)));
187 expect(math.isNan(asin64(1.5)));187 try expect(math.isNan(asin64(1.5)));
188}188}
lib/std/math/asinh.zig+26-26
...@@ -94,46 +94,46 @@ fn asinh64(x: f64) f64 {...@@ -94,46 +94,46 @@ fn asinh64(x: f64) f64 {
94}94}
9595
96test "math.asinh" {96test "math.asinh" {
97 expect(asinh(@as(f32, 0.0)) == asinh32(0.0));97 try expect(asinh(@as(f32, 0.0)) == asinh32(0.0));
98 expect(asinh(@as(f64, 0.0)) == asinh64(0.0));98 try expect(asinh(@as(f64, 0.0)) == asinh64(0.0));
99}99}
100100
101test "math.asinh32" {101test "math.asinh32" {
102 const epsilon = 0.000001;102 const epsilon = 0.000001;
103103
104 expect(math.approxEqAbs(f32, asinh32(0.0), 0.0, epsilon));104 try expect(math.approxEqAbs(f32, asinh32(0.0), 0.0, epsilon));
105 expect(math.approxEqAbs(f32, asinh32(0.2), 0.198690, epsilon));105 try expect(math.approxEqAbs(f32, asinh32(0.2), 0.198690, epsilon));
106 expect(math.approxEqAbs(f32, asinh32(0.8923), 0.803133, epsilon));106 try expect(math.approxEqAbs(f32, asinh32(0.8923), 0.803133, epsilon));
107 expect(math.approxEqAbs(f32, asinh32(1.5), 1.194763, epsilon));107 try expect(math.approxEqAbs(f32, asinh32(1.5), 1.194763, epsilon));
108 expect(math.approxEqAbs(f32, asinh32(37.45), 4.316332, epsilon));108 try expect(math.approxEqAbs(f32, asinh32(37.45), 4.316332, epsilon));
109 expect(math.approxEqAbs(f32, asinh32(89.123), 5.183196, epsilon));109 try expect(math.approxEqAbs(f32, asinh32(89.123), 5.183196, epsilon));
110 expect(math.approxEqAbs(f32, asinh32(123123.234375), 12.414088, epsilon));110 try expect(math.approxEqAbs(f32, asinh32(123123.234375), 12.414088, epsilon));
111}111}
112112
113test "math.asinh64" {113test "math.asinh64" {
114 const epsilon = 0.000001;114 const epsilon = 0.000001;
115115
116 expect(math.approxEqAbs(f64, asinh64(0.0), 0.0, epsilon));116 try expect(math.approxEqAbs(f64, asinh64(0.0), 0.0, epsilon));
117 expect(math.approxEqAbs(f64, asinh64(0.2), 0.198690, epsilon));117 try expect(math.approxEqAbs(f64, asinh64(0.2), 0.198690, epsilon));
118 expect(math.approxEqAbs(f64, asinh64(0.8923), 0.803133, epsilon));118 try expect(math.approxEqAbs(f64, asinh64(0.8923), 0.803133, epsilon));
119 expect(math.approxEqAbs(f64, asinh64(1.5), 1.194763, epsilon));119 try expect(math.approxEqAbs(f64, asinh64(1.5), 1.194763, epsilon));
120 expect(math.approxEqAbs(f64, asinh64(37.45), 4.316332, epsilon));120 try expect(math.approxEqAbs(f64, asinh64(37.45), 4.316332, epsilon));
121 expect(math.approxEqAbs(f64, asinh64(89.123), 5.183196, epsilon));121 try expect(math.approxEqAbs(f64, asinh64(89.123), 5.183196, epsilon));
122 expect(math.approxEqAbs(f64, asinh64(123123.234375), 12.414088, epsilon));122 try expect(math.approxEqAbs(f64, asinh64(123123.234375), 12.414088, epsilon));
123}123}
124124
125test "math.asinh32.special" {125test "math.asinh32.special" {
126 expect(asinh32(0.0) == 0.0);126 try expect(asinh32(0.0) == 0.0);
127 expect(asinh32(-0.0) == -0.0);127 try expect(asinh32(-0.0) == -0.0);
128 expect(math.isPositiveInf(asinh32(math.inf(f32))));128 try expect(math.isPositiveInf(asinh32(math.inf(f32))));
129 expect(math.isNegativeInf(asinh32(-math.inf(f32))));129 try expect(math.isNegativeInf(asinh32(-math.inf(f32))));
130 expect(math.isNan(asinh32(math.nan(f32))));130 try expect(math.isNan(asinh32(math.nan(f32))));
131}131}
132132
133test "math.asinh64.special" {133test "math.asinh64.special" {
134 expect(asinh64(0.0) == 0.0);134 try expect(asinh64(0.0) == 0.0);
135 expect(asinh64(-0.0) == -0.0);135 try expect(asinh64(-0.0) == -0.0);
136 expect(math.isPositiveInf(asinh64(math.inf(f64))));136 try expect(math.isPositiveInf(asinh64(math.inf(f64))));
137 expect(math.isNegativeInf(asinh64(-math.inf(f64))));137 try expect(math.isNegativeInf(asinh64(-math.inf(f64))));
138 expect(math.isNan(asinh64(math.nan(f64))));138 try expect(math.isNan(asinh64(math.nan(f64))));
139}139}
lib/std/math/atan.zig+20-20
...@@ -217,44 +217,44 @@ fn atan64(x_: f64) f64 {...@@ -217,44 +217,44 @@ fn atan64(x_: f64) f64 {
217}217}
218218
219test "math.atan" {219test "math.atan" {
220 expect(@bitCast(u32, atan(@as(f32, 0.2))) == @bitCast(u32, atan32(0.2)));220 try expect(@bitCast(u32, atan(@as(f32, 0.2))) == @bitCast(u32, atan32(0.2)));
221 expect(atan(@as(f64, 0.2)) == atan64(0.2));221 try expect(atan(@as(f64, 0.2)) == atan64(0.2));
222}222}
223223
224test "math.atan32" {224test "math.atan32" {
225 const epsilon = 0.000001;225 const epsilon = 0.000001;
226226
227 expect(math.approxEqAbs(f32, atan32(0.2), 0.197396, epsilon));227 try expect(math.approxEqAbs(f32, atan32(0.2), 0.197396, epsilon));
228 expect(math.approxEqAbs(f32, atan32(-0.2), -0.197396, epsilon));228 try expect(math.approxEqAbs(f32, atan32(-0.2), -0.197396, epsilon));
229 expect(math.approxEqAbs(f32, atan32(0.3434), 0.330783, epsilon));229 try expect(math.approxEqAbs(f32, atan32(0.3434), 0.330783, epsilon));
230 expect(math.approxEqAbs(f32, atan32(0.8923), 0.728545, epsilon));230 try expect(math.approxEqAbs(f32, atan32(0.8923), 0.728545, epsilon));
231 expect(math.approxEqAbs(f32, atan32(1.5), 0.982794, epsilon));231 try expect(math.approxEqAbs(f32, atan32(1.5), 0.982794, epsilon));
232}232}
233233
234test "math.atan64" {234test "math.atan64" {
235 const epsilon = 0.000001;235 const epsilon = 0.000001;
236236
237 expect(math.approxEqAbs(f64, atan64(0.2), 0.197396, epsilon));237 try expect(math.approxEqAbs(f64, atan64(0.2), 0.197396, epsilon));
238 expect(math.approxEqAbs(f64, atan64(-0.2), -0.197396, epsilon));238 try expect(math.approxEqAbs(f64, atan64(-0.2), -0.197396, epsilon));
239 expect(math.approxEqAbs(f64, atan64(0.3434), 0.330783, epsilon));239 try expect(math.approxEqAbs(f64, atan64(0.3434), 0.330783, epsilon));
240 expect(math.approxEqAbs(f64, atan64(0.8923), 0.728545, epsilon));240 try expect(math.approxEqAbs(f64, atan64(0.8923), 0.728545, epsilon));
241 expect(math.approxEqAbs(f64, atan64(1.5), 0.982794, epsilon));241 try expect(math.approxEqAbs(f64, atan64(1.5), 0.982794, epsilon));
242}242}
243243
244test "math.atan32.special" {244test "math.atan32.special" {
245 const epsilon = 0.000001;245 const epsilon = 0.000001;
246246
247 expect(atan32(0.0) == 0.0);247 try expect(atan32(0.0) == 0.0);
248 expect(atan32(-0.0) == -0.0);248 try expect(atan32(-0.0) == -0.0);
249 expect(math.approxEqAbs(f32, atan32(math.inf(f32)), math.pi / 2.0, epsilon));249 try 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));250 try expect(math.approxEqAbs(f32, atan32(-math.inf(f32)), -math.pi / 2.0, epsilon));
251}251}
252252
253test "math.atan64.special" {253test "math.atan64.special" {
254 const epsilon = 0.000001;254 const epsilon = 0.000001;
255255
256 expect(atan64(0.0) == 0.0);256 try expect(atan64(0.0) == 0.0);
257 expect(atan64(-0.0) == -0.0);257 try expect(atan64(-0.0) == -0.0);
258 expect(math.approxEqAbs(f64, atan64(math.inf(f64)), math.pi / 2.0, epsilon));258 try 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));259 try expect(math.approxEqAbs(f64, atan64(-math.inf(f64)), -math.pi / 2.0, epsilon));
260}260}
lib/std/math/atan2.zig+52-52
...@@ -217,78 +217,78 @@ fn atan2_64(y: f64, x: f64) f64 {...@@ -217,78 +217,78 @@ fn atan2_64(y: f64, x: f64) f64 {
217}217}
218218
219test "math.atan2" {219test "math.atan2" {
220 expect(atan2(f32, 0.2, 0.21) == atan2_32(0.2, 0.21));220 try 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));221 try expect(atan2(f64, 0.2, 0.21) == atan2_64(0.2, 0.21));
222}222}
223223
224test "math.atan2_32" {224test "math.atan2_32" {
225 const epsilon = 0.000001;225 const epsilon = 0.000001;
226226
227 expect(math.approxEqAbs(f32, atan2_32(0.0, 0.0), 0.0, epsilon));227 try 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));228 try 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));229 try 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));230 try 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));231 try 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));232 try 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));233 try expect(math.approxEqAbs(f32, atan2_32(0.34, 1.243), 0.267001, epsilon));
234}234}
235235
236test "math.atan2_64" {236test "math.atan2_64" {
237 const epsilon = 0.000001;237 const epsilon = 0.000001;
238238
239 expect(math.approxEqAbs(f64, atan2_64(0.0, 0.0), 0.0, epsilon));239 try 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));240 try 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));241 try 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));242 try 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));243 try 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));244 try 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));245 try expect(math.approxEqAbs(f64, atan2_64(0.34, 1.243), 0.267001, epsilon));
246}246}
247247
248test "math.atan2_32.special" {248test "math.atan2_32.special" {
249 const epsilon = 0.000001;249 const epsilon = 0.000001;
250250
251 expect(math.isNan(atan2_32(1.0, math.nan(f32))));251 try expect(math.isNan(atan2_32(1.0, math.nan(f32))));
252 expect(math.isNan(atan2_32(math.nan(f32), 1.0)));252 try expect(math.isNan(atan2_32(math.nan(f32), 1.0)));
253 expect(atan2_32(0.0, 5.0) == 0.0);253 try expect(atan2_32(0.0, 5.0) == 0.0);
254 expect(atan2_32(-0.0, 5.0) == -0.0);254 try expect(atan2_32(-0.0, 5.0) == -0.0);
255 expect(math.approxEqAbs(f32, atan2_32(0.0, -5.0), math.pi, epsilon));255 try expect(math.approxEqAbs(f32, atan2_32(0.0, -5.0), math.pi, epsilon));
256 //expect(math.approxEqAbs(f32, atan2_32(-0.0, -5.0), -math.pi, .{.rel=0,.abs=epsilon})); TODO support negative zero?256 //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));257 try 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));258 try 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));259 try 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));260 try 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));261 try 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));262 try 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));263 try 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));264 try 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);265 try 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));266 try 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));267 try 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));268 try 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));269 try expect(math.approxEqAbs(f32, atan2_32(-math.inf(f32), 1.0), -math.pi / 2.0, epsilon));
270}270}
271271
272test "math.atan2_64.special" {272test "math.atan2_64.special" {
273 const epsilon = 0.000001;273 const epsilon = 0.000001;
274274
275 expect(math.isNan(atan2_64(1.0, math.nan(f64))));275 try expect(math.isNan(atan2_64(1.0, math.nan(f64))));
276 expect(math.isNan(atan2_64(math.nan(f64), 1.0)));276 try expect(math.isNan(atan2_64(math.nan(f64), 1.0)));
277 expect(atan2_64(0.0, 5.0) == 0.0);277 try expect(atan2_64(0.0, 5.0) == 0.0);
278 expect(atan2_64(-0.0, 5.0) == -0.0);278 try expect(atan2_64(-0.0, 5.0) == -0.0);
279 expect(math.approxEqAbs(f64, atan2_64(0.0, -5.0), math.pi, epsilon));279 try expect(math.approxEqAbs(f64, atan2_64(0.0, -5.0), math.pi, epsilon));
280 //expect(math.approxEqAbs(f64, atan2_64(-0.0, -5.0), -math.pi, .{.rel=0,.abs=epsilon})); TODO support negative zero?280 //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));281 try 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));282 try 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));283 try 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));284 try 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));285 try 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));286 try 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));287 try 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));288 try 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);289 try 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));290 try 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));291 try 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));292 try 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));293 try expect(math.approxEqAbs(f64, atan2_64(-math.inf(f64), 1.0), -math.pi / 2.0, epsilon));
294}294}
lib/std/math/atanh.zig+18-18
...@@ -89,38 +89,38 @@ fn atanh_64(x: f64) f64 {...@@ -89,38 +89,38 @@ fn atanh_64(x: f64) f64 {
89}89}
9090
91test "math.atanh" {91test "math.atanh" {
92 expect(atanh(@as(f32, 0.0)) == atanh_32(0.0));92 try expect(atanh(@as(f32, 0.0)) == atanh_32(0.0));
93 expect(atanh(@as(f64, 0.0)) == atanh_64(0.0));93 try expect(atanh(@as(f64, 0.0)) == atanh_64(0.0));
94}94}
9595
96test "math.atanh_32" {96test "math.atanh_32" {
97 const epsilon = 0.000001;97 const epsilon = 0.000001;
9898
99 expect(math.approxEqAbs(f32, atanh_32(0.0), 0.0, epsilon));99 try expect(math.approxEqAbs(f32, atanh_32(0.0), 0.0, epsilon));
100 expect(math.approxEqAbs(f32, atanh_32(0.2), 0.202733, epsilon));100 try expect(math.approxEqAbs(f32, atanh_32(0.2), 0.202733, epsilon));
101 expect(math.approxEqAbs(f32, atanh_32(0.8923), 1.433099, epsilon));101 try expect(math.approxEqAbs(f32, atanh_32(0.8923), 1.433099, epsilon));
102}102}
103103
104test "math.atanh_64" {104test "math.atanh_64" {
105 const epsilon = 0.000001;105 const epsilon = 0.000001;
106106
107 expect(math.approxEqAbs(f64, atanh_64(0.0), 0.0, epsilon));107 try expect(math.approxEqAbs(f64, atanh_64(0.0), 0.0, epsilon));
108 expect(math.approxEqAbs(f64, atanh_64(0.2), 0.202733, epsilon));108 try expect(math.approxEqAbs(f64, atanh_64(0.2), 0.202733, epsilon));
109 expect(math.approxEqAbs(f64, atanh_64(0.8923), 1.433099, epsilon));109 try expect(math.approxEqAbs(f64, atanh_64(0.8923), 1.433099, epsilon));
110}110}
111111
112test "math.atanh32.special" {112test "math.atanh32.special" {
113 expect(math.isPositiveInf(atanh_32(1)));113 try expect(math.isPositiveInf(atanh_32(1)));
114 expect(math.isNegativeInf(atanh_32(-1)));114 try expect(math.isNegativeInf(atanh_32(-1)));
115 expect(math.isSignalNan(atanh_32(1.5)));115 try expect(math.isSignalNan(atanh_32(1.5)));
116 expect(math.isSignalNan(atanh_32(-1.5)));116 try expect(math.isSignalNan(atanh_32(-1.5)));
117 expect(math.isNan(atanh_32(math.nan(f32))));117 try expect(math.isNan(atanh_32(math.nan(f32))));
118}118}
119119
120test "math.atanh64.special" {120test "math.atanh64.special" {
121 expect(math.isPositiveInf(atanh_64(1)));121 try expect(math.isPositiveInf(atanh_64(1)));
122 expect(math.isNegativeInf(atanh_64(-1)));122 try expect(math.isNegativeInf(atanh_64(-1)));
123 expect(math.isSignalNan(atanh_64(1.5)));123 try expect(math.isSignalNan(atanh_64(1.5)));
124 expect(math.isSignalNan(atanh_64(-1.5)));124 try expect(math.isSignalNan(atanh_64(-1.5)));
125 expect(math.isNan(atanh_64(math.nan(f64))));125 try expect(math.isNan(atanh_64(math.nan(f64))));
126}126}
lib/std/math/big/int_test.zig+211-211
...@@ -30,7 +30,7 @@ test "big.int comptime_int set" {...@@ -30,7 +30,7 @@ test "big.int comptime_int set" {
30 const result = @as(Limb, s & maxInt(Limb));30 const result = @as(Limb, s & maxInt(Limb));
31 s >>= @typeInfo(Limb).Int.bits / 2;31 s >>= @typeInfo(Limb).Int.bits / 2;
32 s >>= @typeInfo(Limb).Int.bits / 2;32 s >>= @typeInfo(Limb).Int.bits / 2;
33 testing.expect(a.limbs[i] == result);33 try testing.expect(a.limbs[i] == result);
34 }34 }
35}35}
3636
...@@ -38,37 +38,37 @@ test "big.int comptime_int set negative" {...@@ -38,37 +38,37 @@ test "big.int comptime_int set negative" {
38 var a = try Managed.initSet(testing.allocator, -10);38 var a = try Managed.initSet(testing.allocator, -10);
39 defer a.deinit();39 defer a.deinit();
4040
41 testing.expect(a.limbs[0] == 10);41 try testing.expect(a.limbs[0] == 10);
42 testing.expect(a.isPositive() == false);42 try testing.expect(a.isPositive() == false);
43}43}
4444
45test "big.int int set unaligned small" {45test "big.int int set unaligned small" {
46 var a = try Managed.initSet(testing.allocator, @as(u7, 45));46 var a = try Managed.initSet(testing.allocator, @as(u7, 45));
47 defer a.deinit();47 defer a.deinit();
4848
49 testing.expect(a.limbs[0] == 45);49 try testing.expect(a.limbs[0] == 45);
50 testing.expect(a.isPositive() == true);50 try testing.expect(a.isPositive() == true);
51}51}
5252
53test "big.int comptime_int to" {53test "big.int comptime_int to" {
54 var a = try Managed.initSet(testing.allocator, 0xefffffff00000001eeeeeeefaaaaaaab);54 var a = try Managed.initSet(testing.allocator, 0xefffffff00000001eeeeeeefaaaaaaab);
55 defer a.deinit();55 defer a.deinit();
5656
57 testing.expect((try a.to(u128)) == 0xefffffff00000001eeeeeeefaaaaaaab);57 try testing.expect((try a.to(u128)) == 0xefffffff00000001eeeeeeefaaaaaaab);
58}58}
5959
60test "big.int sub-limb to" {60test "big.int sub-limb to" {
61 var a = try Managed.initSet(testing.allocator, 10);61 var a = try Managed.initSet(testing.allocator, 10);
62 defer a.deinit();62 defer a.deinit();
6363
64 testing.expect((try a.to(u8)) == 10);64 try testing.expect((try a.to(u8)) == 10);
65}65}
6666
67test "big.int to target too small error" {67test "big.int to target too small error" {
68 var a = try Managed.initSet(testing.allocator, 0xffffffff);68 var a = try Managed.initSet(testing.allocator, 0xffffffff);
69 defer a.deinit();69 defer a.deinit();
7070
71 testing.expectError(error.TargetTooSmall, a.to(u8));71 try testing.expectError(error.TargetTooSmall, a.to(u8));
72}72}
7373
74test "big.int normalize" {74test "big.int normalize" {
...@@ -81,22 +81,22 @@ test "big.int normalize" {...@@ -81,22 +81,22 @@ test "big.int normalize" {
81 a.limbs[2] = 3;81 a.limbs[2] = 3;
82 a.limbs[3] = 0;82 a.limbs[3] = 0;
83 a.normalize(4);83 a.normalize(4);
84 testing.expect(a.len() == 3);84 try testing.expect(a.len() == 3);
8585
86 a.limbs[0] = 1;86 a.limbs[0] = 1;
87 a.limbs[1] = 2;87 a.limbs[1] = 2;
88 a.limbs[2] = 3;88 a.limbs[2] = 3;
89 a.normalize(3);89 a.normalize(3);
90 testing.expect(a.len() == 3);90 try testing.expect(a.len() == 3);
9191
92 a.limbs[0] = 0;92 a.limbs[0] = 0;
93 a.limbs[1] = 0;93 a.limbs[1] = 0;
94 a.normalize(2);94 a.normalize(2);
95 testing.expect(a.len() == 1);95 try testing.expect(a.len() == 1);
9696
97 a.limbs[0] = 0;97 a.limbs[0] = 0;
98 a.normalize(1);98 a.normalize(1);
99 testing.expect(a.len() == 1);99 try testing.expect(a.len() == 1);
100}100}
101101
102test "big.int normalize multi" {102test "big.int normalize multi" {
...@@ -109,24 +109,24 @@ test "big.int normalize multi" {...@@ -109,24 +109,24 @@ test "big.int normalize multi" {
109 a.limbs[2] = 0;109 a.limbs[2] = 0;
110 a.limbs[3] = 0;110 a.limbs[3] = 0;
111 a.normalize(4);111 a.normalize(4);
112 testing.expect(a.len() == 2);112 try testing.expect(a.len() == 2);
113113
114 a.limbs[0] = 1;114 a.limbs[0] = 1;
115 a.limbs[1] = 2;115 a.limbs[1] = 2;
116 a.limbs[2] = 3;116 a.limbs[2] = 3;
117 a.normalize(3);117 a.normalize(3);
118 testing.expect(a.len() == 3);118 try testing.expect(a.len() == 3);
119119
120 a.limbs[0] = 0;120 a.limbs[0] = 0;
121 a.limbs[1] = 0;121 a.limbs[1] = 0;
122 a.limbs[2] = 0;122 a.limbs[2] = 0;
123 a.limbs[3] = 0;123 a.limbs[3] = 0;
124 a.normalize(4);124 a.normalize(4);
125 testing.expect(a.len() == 1);125 try testing.expect(a.len() == 1);
126126
127 a.limbs[0] = 0;127 a.limbs[0] = 0;
128 a.normalize(1);128 a.normalize(1);
129 testing.expect(a.len() == 1);129 try testing.expect(a.len() == 1);
130}130}
131131
132test "big.int parity" {132test "big.int parity" {
...@@ -134,12 +134,12 @@ test "big.int parity" {...@@ -134,12 +134,12 @@ test "big.int parity" {
134 defer a.deinit();134 defer a.deinit();
135135
136 try a.set(0);136 try a.set(0);
137 testing.expect(a.isEven());137 try testing.expect(a.isEven());
138 testing.expect(!a.isOdd());138 try testing.expect(!a.isOdd());
139139
140 try a.set(7);140 try a.set(7);
141 testing.expect(!a.isEven());141 try testing.expect(!a.isEven());
142 testing.expect(a.isOdd());142 try testing.expect(a.isOdd());
143}143}
144144
145test "big.int bitcount + sizeInBaseUpperBound" {145test "big.int bitcount + sizeInBaseUpperBound" {
...@@ -147,27 +147,27 @@ test "big.int bitcount + sizeInBaseUpperBound" {...@@ -147,27 +147,27 @@ test "big.int bitcount + sizeInBaseUpperBound" {
147 defer a.deinit();147 defer a.deinit();
148148
149 try a.set(0b100);149 try a.set(0b100);
150 testing.expect(a.bitCountAbs() == 3);150 try testing.expect(a.bitCountAbs() == 3);
151 testing.expect(a.sizeInBaseUpperBound(2) >= 3);151 try testing.expect(a.sizeInBaseUpperBound(2) >= 3);
152 testing.expect(a.sizeInBaseUpperBound(10) >= 1);152 try testing.expect(a.sizeInBaseUpperBound(10) >= 1);
153153
154 a.negate();154 a.negate();
155 testing.expect(a.bitCountAbs() == 3);155 try testing.expect(a.bitCountAbs() == 3);
156 testing.expect(a.sizeInBaseUpperBound(2) >= 4);156 try testing.expect(a.sizeInBaseUpperBound(2) >= 4);
157 testing.expect(a.sizeInBaseUpperBound(10) >= 2);157 try testing.expect(a.sizeInBaseUpperBound(10) >= 2);
158158
159 try a.set(0xffffffff);159 try a.set(0xffffffff);
160 testing.expect(a.bitCountAbs() == 32);160 try testing.expect(a.bitCountAbs() == 32);
161 testing.expect(a.sizeInBaseUpperBound(2) >= 32);161 try testing.expect(a.sizeInBaseUpperBound(2) >= 32);
162 testing.expect(a.sizeInBaseUpperBound(10) >= 10);162 try testing.expect(a.sizeInBaseUpperBound(10) >= 10);
163163
164 try a.shiftLeft(a, 5000);164 try a.shiftLeft(a, 5000);
165 testing.expect(a.bitCountAbs() == 5032);165 try testing.expect(a.bitCountAbs() == 5032);
166 testing.expect(a.sizeInBaseUpperBound(2) >= 5032);166 try testing.expect(a.sizeInBaseUpperBound(2) >= 5032);
167 a.setSign(false);167 a.setSign(false);
168168
169 testing.expect(a.bitCountAbs() == 5032);169 try testing.expect(a.bitCountAbs() == 5032);
170 testing.expect(a.sizeInBaseUpperBound(2) >= 5033);170 try testing.expect(a.sizeInBaseUpperBound(2) >= 5033);
171}171}
172172
173test "big.int bitcount/to" {173test "big.int bitcount/to" {
...@@ -175,30 +175,30 @@ test "big.int bitcount/to" {...@@ -175,30 +175,30 @@ test "big.int bitcount/to" {
175 defer a.deinit();175 defer a.deinit();
176176
177 try a.set(0);177 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);180 try testing.expect((try a.to(u0)) == 0);
181 testing.expect((try a.to(i0)) == 0);181 try testing.expect((try a.to(i0)) == 0);
182182
183 try a.set(-1);183 try a.set(-1);
184 testing.expect(a.bitCountTwosComp() == 1);184 try testing.expect(a.bitCountTwosComp() == 1);
185 testing.expect((try a.to(i1)) == -1);185 try testing.expect((try a.to(i1)) == -1);
186186
187 try a.set(-8);187 try a.set(-8);
188 testing.expect(a.bitCountTwosComp() == 4);188 try testing.expect(a.bitCountTwosComp() == 4);
189 testing.expect((try a.to(i4)) == -8);189 try testing.expect((try a.to(i4)) == -8);
190190
191 try a.set(127);191 try a.set(127);
192 testing.expect(a.bitCountTwosComp() == 7);192 try testing.expect(a.bitCountTwosComp() == 7);
193 testing.expect((try a.to(u7)) == 127);193 try testing.expect((try a.to(u7)) == 127);
194194
195 try a.set(-128);195 try a.set(-128);
196 testing.expect(a.bitCountTwosComp() == 8);196 try testing.expect(a.bitCountTwosComp() == 8);
197 testing.expect((try a.to(i8)) == -128);197 try testing.expect((try a.to(i8)) == -128);
198198
199 try a.set(-129);199 try a.set(-129);
200 testing.expect(a.bitCountTwosComp() == 9);200 try testing.expect(a.bitCountTwosComp() == 9);
201 testing.expect((try a.to(i9)) == -129);201 try testing.expect((try a.to(i9)) == -129);
202}202}
203203
204test "big.int fits" {204test "big.int fits" {
...@@ -206,27 +206,27 @@ test "big.int fits" {...@@ -206,27 +206,27 @@ test "big.int fits" {
206 defer a.deinit();206 defer a.deinit();
207207
208 try a.set(0);208 try a.set(0);
209 testing.expect(a.fits(u0));209 try testing.expect(a.fits(u0));
210 testing.expect(a.fits(i0));210 try testing.expect(a.fits(i0));
211211
212 try a.set(255);212 try a.set(255);
213 testing.expect(!a.fits(u0));213 try testing.expect(!a.fits(u0));
214 testing.expect(!a.fits(u1));214 try testing.expect(!a.fits(u1));
215 testing.expect(!a.fits(i8));215 try testing.expect(!a.fits(i8));
216 testing.expect(a.fits(u8));216 try testing.expect(a.fits(u8));
217 testing.expect(a.fits(u9));217 try testing.expect(a.fits(u9));
218 testing.expect(a.fits(i9));218 try testing.expect(a.fits(i9));
219219
220 try a.set(-128);220 try a.set(-128);
221 testing.expect(!a.fits(i7));221 try testing.expect(!a.fits(i7));
222 testing.expect(a.fits(i8));222 try testing.expect(a.fits(i8));
223 testing.expect(a.fits(i9));223 try testing.expect(a.fits(i9));
224 testing.expect(!a.fits(u9));224 try testing.expect(!a.fits(u9));
225225
226 try a.set(0x1ffffffffeeeeeeee);226 try a.set(0x1ffffffffeeeeeeee);
227 testing.expect(!a.fits(u32));227 try testing.expect(!a.fits(u32));
228 testing.expect(!a.fits(u64));228 try testing.expect(!a.fits(u64));
229 testing.expect(a.fits(u65));229 try testing.expect(a.fits(u65));
230}230}
231231
232test "big.int string set" {232test "big.int string set" {
...@@ -234,7 +234,7 @@ test "big.int string set" {...@@ -234,7 +234,7 @@ test "big.int string set" {
234 defer a.deinit();234 defer a.deinit();
235235
236 try a.setString(10, "120317241209124781241290847124");236 try a.setString(10, "120317241209124781241290847124");
237 testing.expect((try a.to(u128)) == 120317241209124781241290847124);237 try testing.expect((try a.to(u128)) == 120317241209124781241290847124);
238}238}
239239
240test "big.int string negative" {240test "big.int string negative" {
...@@ -242,7 +242,7 @@ test "big.int string negative" {...@@ -242,7 +242,7 @@ test "big.int string negative" {
242 defer a.deinit();242 defer a.deinit();
243243
244 try a.setString(10, "-1023");244 try a.setString(10, "-1023");
245 testing.expect((try a.to(i32)) == -1023);245 try testing.expect((try a.to(i32)) == -1023);
246}246}
247247
248test "big.int string set number with underscores" {248test "big.int string set number with underscores" {
...@@ -250,7 +250,7 @@ test "big.int string set number with underscores" {...@@ -250,7 +250,7 @@ test "big.int string set number with underscores" {
250 defer a.deinit();250 defer a.deinit();
251251
252 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___");252 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);
254}254}
255255
256test "big.int string set case insensitive number" {256test "big.int string set case insensitive number" {
...@@ -258,19 +258,19 @@ test "big.int string set case insensitive number" {...@@ -258,19 +258,19 @@ test "big.int string set case insensitive number" {
258 defer a.deinit();258 defer a.deinit();
259259
260 try a.setString(16, "aB_cD_eF");260 try a.setString(16, "aB_cD_eF");
261 testing.expect((try a.to(u32)) == 0xabcdef);261 try testing.expect((try a.to(u32)) == 0xabcdef);
262}262}
263263
264test "big.int string set bad char error" {264test "big.int string set bad char error" {
265 var a = try Managed.init(testing.allocator);265 var a = try Managed.init(testing.allocator);
266 defer a.deinit();266 defer a.deinit();
267 testing.expectError(error.InvalidCharacter, a.setString(10, "x"));267 try testing.expectError(error.InvalidCharacter, a.setString(10, "x"));
268}268}
269269
270test "big.int string set bad base error" {270test "big.int string set bad base error" {
271 var a = try Managed.init(testing.allocator);271 var a = try Managed.init(testing.allocator);
272 defer a.deinit();272 defer a.deinit();
273 testing.expectError(error.InvalidBase, a.setString(45, "10"));273 try testing.expectError(error.InvalidBase, a.setString(45, "10"));
274}274}
275275
276test "big.int string to" {276test "big.int string to" {
...@@ -281,14 +281,14 @@ test "big.int string to" {...@@ -281,14 +281,14 @@ test "big.int string to" {
281 defer testing.allocator.free(as);281 defer testing.allocator.free(as);
282 const es = "120317241209124781241290847124";282 const es = "120317241209124781241290847124";
283283
284 testing.expect(mem.eql(u8, as, es));284 try testing.expect(mem.eql(u8, as, es));
285}285}
286286
287test "big.int string to base base error" {287test "big.int string to base base error" {
288 var a = try Managed.initSet(testing.allocator, 0xffffffff);288 var a = try Managed.initSet(testing.allocator, 0xffffffff);
289 defer a.deinit();289 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));
292}292}
293293
294test "big.int string to base 2" {294test "big.int string to base 2" {
...@@ -299,7 +299,7 @@ test "big.int string to base 2" {...@@ -299,7 +299,7 @@ test "big.int string to base 2" {
299 defer testing.allocator.free(as);299 defer testing.allocator.free(as);
300 const es = "-1011";300 const es = "-1011";
301301
302 testing.expect(mem.eql(u8, as, es));302 try testing.expect(mem.eql(u8, as, es));
303}303}
304304
305test "big.int string to base 16" {305test "big.int string to base 16" {
...@@ -310,7 +310,7 @@ test "big.int string to base 16" {...@@ -310,7 +310,7 @@ test "big.int string to base 16" {
310 defer testing.allocator.free(as);310 defer testing.allocator.free(as);
311 const es = "efffffff00000001eeeeeeefaaaaaaab";311 const es = "efffffff00000001eeeeeeefaaaaaaab";
312312
313 testing.expect(mem.eql(u8, as, es));313 try testing.expect(mem.eql(u8, as, es));
314}314}
315315
316test "big.int neg string to" {316test "big.int neg string to" {
...@@ -321,7 +321,7 @@ test "big.int neg string to" {...@@ -321,7 +321,7 @@ test "big.int neg string to" {
321 defer testing.allocator.free(as);321 defer testing.allocator.free(as);
322 const es = "-123907434";322 const es = "-123907434";
323323
324 testing.expect(mem.eql(u8, as, es));324 try testing.expect(mem.eql(u8, as, es));
325}325}
326326
327test "big.int zero string to" {327test "big.int zero string to" {
...@@ -332,7 +332,7 @@ test "big.int zero string to" {...@@ -332,7 +332,7 @@ test "big.int zero string to" {
332 defer testing.allocator.free(as);332 defer testing.allocator.free(as);
333 const es = "0";333 const es = "0";
334334
335 testing.expect(mem.eql(u8, as, es));335 try testing.expect(mem.eql(u8, as, es));
336}336}
337337
338test "big.int clone" {338test "big.int clone" {
...@@ -341,12 +341,12 @@ test "big.int clone" {...@@ -341,12 +341,12 @@ test "big.int clone" {
341 var b = try a.clone();341 var b = try a.clone();
342 defer b.deinit();342 defer b.deinit();
343343
344 testing.expect((try a.to(u32)) == 1234);344 try testing.expect((try a.to(u32)) == 1234);
345 testing.expect((try b.to(u32)) == 1234);345 try testing.expect((try b.to(u32)) == 1234);
346346
347 try a.set(77);347 try a.set(77);
348 testing.expect((try a.to(u32)) == 77);348 try testing.expect((try a.to(u32)) == 77);
349 testing.expect((try b.to(u32)) == 1234);349 try testing.expect((try b.to(u32)) == 1234);
350}350}
351351
352test "big.int swap" {352test "big.int swap" {
...@@ -355,20 +355,20 @@ test "big.int swap" {...@@ -355,20 +355,20 @@ test "big.int swap" {
355 var b = try Managed.initSet(testing.allocator, 5678);355 var b = try Managed.initSet(testing.allocator, 5678);
356 defer b.deinit();356 defer b.deinit();
357357
358 testing.expect((try a.to(u32)) == 1234);358 try testing.expect((try a.to(u32)) == 1234);
359 testing.expect((try b.to(u32)) == 5678);359 try testing.expect((try b.to(u32)) == 5678);
360360
361 a.swap(&b);361 a.swap(&b);
362362
363 testing.expect((try a.to(u32)) == 5678);363 try testing.expect((try a.to(u32)) == 5678);
364 testing.expect((try b.to(u32)) == 1234);364 try testing.expect((try b.to(u32)) == 1234);
365}365}
366366
367test "big.int to negative" {367test "big.int to negative" {
368 var a = try Managed.initSet(testing.allocator, -10);368 var a = try Managed.initSet(testing.allocator, -10);
369 defer a.deinit();369 defer a.deinit();
370370
371 testing.expect((try a.to(i32)) == -10);371 try testing.expect((try a.to(i32)) == -10);
372}372}
373373
374test "big.int compare" {374test "big.int compare" {
...@@ -377,8 +377,8 @@ test "big.int compare" {...@@ -377,8 +377,8 @@ test "big.int compare" {
377 var b = try Managed.initSet(testing.allocator, 10);377 var b = try Managed.initSet(testing.allocator, 10);
378 defer b.deinit();378 defer b.deinit();
379379
380 testing.expect(a.orderAbs(b) == .gt);380 try testing.expect(a.orderAbs(b) == .gt);
381 testing.expect(a.order(b) == .lt);381 try testing.expect(a.order(b) == .lt);
382}382}
383383
384test "big.int compare similar" {384test "big.int compare similar" {
...@@ -387,8 +387,8 @@ test "big.int compare similar" {...@@ -387,8 +387,8 @@ test "big.int compare similar" {
387 var b = try Managed.initSet(testing.allocator, 0xffffffffeeeeeeeeffffffffeeeeeeef);387 var b = try Managed.initSet(testing.allocator, 0xffffffffeeeeeeeeffffffffeeeeeeef);
388 defer b.deinit();388 defer b.deinit();
389389
390 testing.expect(a.orderAbs(b) == .lt);390 try testing.expect(a.orderAbs(b) == .lt);
391 testing.expect(b.orderAbs(a) == .gt);391 try testing.expect(b.orderAbs(a) == .gt);
392}392}
393393
394test "big.int compare different limb size" {394test "big.int compare different limb size" {
...@@ -397,8 +397,8 @@ test "big.int compare different limb size" {...@@ -397,8 +397,8 @@ test "big.int compare different limb size" {
397 var b = try Managed.initSet(testing.allocator, 1);397 var b = try Managed.initSet(testing.allocator, 1);
398 defer b.deinit();398 defer b.deinit();
399399
400 testing.expect(a.orderAbs(b) == .gt);400 try testing.expect(a.orderAbs(b) == .gt);
401 testing.expect(b.orderAbs(a) == .lt);401 try testing.expect(b.orderAbs(a) == .lt);
402}402}
403403
404test "big.int compare multi-limb" {404test "big.int compare multi-limb" {
...@@ -407,8 +407,8 @@ test "big.int compare multi-limb" {...@@ -407,8 +407,8 @@ test "big.int compare multi-limb" {
407 var b = try Managed.initSet(testing.allocator, 0x7777777799999999ffffeeeeffffeeeeffffeeeee);407 var b = try Managed.initSet(testing.allocator, 0x7777777799999999ffffeeeeffffeeeeffffeeeee);
408 defer b.deinit();408 defer b.deinit();
409409
410 testing.expect(a.orderAbs(b) == .gt);410 try testing.expect(a.orderAbs(b) == .gt);
411 testing.expect(a.order(b) == .lt);411 try testing.expect(a.order(b) == .lt);
412}412}
413413
414test "big.int equality" {414test "big.int equality" {
...@@ -417,8 +417,8 @@ test "big.int equality" {...@@ -417,8 +417,8 @@ test "big.int equality" {
417 var b = try Managed.initSet(testing.allocator, -0xffffffff1);417 var b = try Managed.initSet(testing.allocator, -0xffffffff1);
418 defer b.deinit();418 defer b.deinit();
419419
420 testing.expect(a.eqAbs(b));420 try testing.expect(a.eqAbs(b));
421 testing.expect(!a.eq(b));421 try testing.expect(!a.eq(b));
422}422}
423423
424test "big.int abs" {424test "big.int abs" {
...@@ -426,10 +426,10 @@ test "big.int abs" {...@@ -426,10 +426,10 @@ test "big.int abs" {
426 defer a.deinit();426 defer a.deinit();
427427
428 a.abs();428 a.abs();
429 testing.expect((try a.to(u32)) == 5);429 try testing.expect((try a.to(u32)) == 5);
430430
431 a.abs();431 a.abs();
432 testing.expect((try a.to(u32)) == 5);432 try testing.expect((try a.to(u32)) == 5);
433}433}
434434
435test "big.int negate" {435test "big.int negate" {
...@@ -437,10 +437,10 @@ test "big.int negate" {...@@ -437,10 +437,10 @@ test "big.int negate" {
437 defer a.deinit();437 defer a.deinit();
438438
439 a.negate();439 a.negate();
440 testing.expect((try a.to(i32)) == -5);440 try testing.expect((try a.to(i32)) == -5);
441441
442 a.negate();442 a.negate();
443 testing.expect((try a.to(i32)) == 5);443 try testing.expect((try a.to(i32)) == 5);
444}444}
445445
446test "big.int add single-single" {446test "big.int add single-single" {
...@@ -453,7 +453,7 @@ test "big.int add single-single" {...@@ -453,7 +453,7 @@ test "big.int add single-single" {
453 defer c.deinit();453 defer c.deinit();
454 try c.add(a.toConst(), b.toConst());454 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);
457}457}
458458
459test "big.int add multi-single" {459test "big.int add multi-single" {
...@@ -466,10 +466,10 @@ test "big.int add multi-single" {...@@ -466,10 +466,10 @@ test "big.int add multi-single" {
466 defer c.deinit();466 defer c.deinit();
467467
468 try c.add(a.toConst(), b.toConst());468 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
471 try c.add(b.toConst(), a.toConst());471 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);
473}473}
474474
475test "big.int add multi-multi" {475test "big.int add multi-multi" {
...@@ -484,7 +484,7 @@ test "big.int add multi-multi" {...@@ -484,7 +484,7 @@ test "big.int add multi-multi" {
484 defer c.deinit();484 defer c.deinit();
485 try c.add(a.toConst(), b.toConst());485 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);
488}488}
489489
490test "big.int add zero-zero" {490test "big.int add zero-zero" {
...@@ -497,7 +497,7 @@ test "big.int add zero-zero" {...@@ -497,7 +497,7 @@ test "big.int add zero-zero" {
497 defer c.deinit();497 defer c.deinit();
498 try c.add(a.toConst(), b.toConst());498 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);
501}501}
502502
503test "big.int add alias multi-limb nonzero-zero" {503test "big.int add alias multi-limb nonzero-zero" {
...@@ -509,7 +509,7 @@ test "big.int add alias multi-limb nonzero-zero" {...@@ -509,7 +509,7 @@ test "big.int add alias multi-limb nonzero-zero" {
509509
510 try a.add(a.toConst(), b.toConst());510 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);
513}513}
514514
515test "big.int add sign" {515test "big.int add sign" {
...@@ -526,16 +526,16 @@ test "big.int add sign" {...@@ -526,16 +526,16 @@ test "big.int add sign" {
526 defer neg_two.deinit();526 defer neg_two.deinit();
527527
528 try a.add(one.toConst(), two.toConst());528 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
531 try a.add(neg_one.toConst(), two.toConst());531 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
534 try a.add(one.toConst(), neg_two.toConst());534 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
537 try a.add(neg_one.toConst(), neg_two.toConst());537 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);
539}539}
540540
541test "big.int sub single-single" {541test "big.int sub single-single" {
...@@ -548,7 +548,7 @@ test "big.int sub single-single" {...@@ -548,7 +548,7 @@ test "big.int sub single-single" {
548 defer c.deinit();548 defer c.deinit();
549 try c.sub(a.toConst(), b.toConst());549 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);
552}552}
553553
554test "big.int sub multi-single" {554test "big.int sub multi-single" {
...@@ -561,7 +561,7 @@ test "big.int sub multi-single" {...@@ -561,7 +561,7 @@ test "big.int sub multi-single" {
561 defer c.deinit();561 defer c.deinit();
562 try c.sub(a.toConst(), b.toConst());562 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));
565}565}
566566
567test "big.int sub multi-multi" {567test "big.int sub multi-multi" {
...@@ -577,7 +577,7 @@ test "big.int sub multi-multi" {...@@ -577,7 +577,7 @@ test "big.int sub multi-multi" {
577 defer c.deinit();577 defer c.deinit();
578 try c.sub(a.toConst(), b.toConst());578 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);
581}581}
582582
583test "big.int sub equal" {583test "big.int sub equal" {
...@@ -590,7 +590,7 @@ test "big.int sub equal" {...@@ -590,7 +590,7 @@ test "big.int sub equal" {
590 defer c.deinit();590 defer c.deinit();
591 try c.sub(a.toConst(), b.toConst());591 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);
594}594}
595595
596test "big.int sub sign" {596test "big.int sub sign" {
...@@ -607,19 +607,19 @@ test "big.int sub sign" {...@@ -607,19 +607,19 @@ test "big.int sub sign" {
607 defer neg_two.deinit();607 defer neg_two.deinit();
608608
609 try a.sub(one.toConst(), two.toConst());609 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
612 try a.sub(neg_one.toConst(), two.toConst());612 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
615 try a.sub(one.toConst(), neg_two.toConst());615 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
618 try a.sub(neg_one.toConst(), neg_two.toConst());618 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
621 try a.sub(neg_two.toConst(), neg_one.toConst());621 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);
623}623}
624624
625test "big.int mul single-single" {625test "big.int mul single-single" {
...@@ -632,7 +632,7 @@ test "big.int mul single-single" {...@@ -632,7 +632,7 @@ test "big.int mul single-single" {
632 defer c.deinit();632 defer c.deinit();
633 try c.mul(a.toConst(), b.toConst());633 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);
636}636}
637637
638test "big.int mul multi-single" {638test "big.int mul multi-single" {
...@@ -645,7 +645,7 @@ test "big.int mul multi-single" {...@@ -645,7 +645,7 @@ test "big.int mul multi-single" {
645 defer c.deinit();645 defer c.deinit();
646 try c.mul(a.toConst(), b.toConst());646 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));
649}649}
650650
651test "big.int mul multi-multi" {651test "big.int mul multi-multi" {
...@@ -660,7 +660,7 @@ test "big.int mul multi-multi" {...@@ -660,7 +660,7 @@ test "big.int mul multi-multi" {
660 defer c.deinit();660 defer c.deinit();
661 try c.mul(a.toConst(), b.toConst());661 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);
664}664}
665665
666test "big.int mul alias r with a" {666test "big.int mul alias r with a" {
...@@ -671,7 +671,7 @@ test "big.int mul alias r with a" {...@@ -671,7 +671,7 @@ test "big.int mul alias r with a" {
671671
672 try a.mul(a.toConst(), b.toConst());672 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));
675}675}
676676
677test "big.int mul alias r with b" {677test "big.int mul alias r with b" {
...@@ -682,7 +682,7 @@ test "big.int mul alias r with b" {...@@ -682,7 +682,7 @@ test "big.int mul alias r with b" {
682682
683 try a.mul(b.toConst(), a.toConst());683 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));
686}686}
687687
688test "big.int mul alias r with a and b" {688test "big.int mul alias r with a and b" {
...@@ -691,7 +691,7 @@ test "big.int mul alias r with a and b" {...@@ -691,7 +691,7 @@ test "big.int mul alias r with a and b" {
691691
692 try a.mul(a.toConst(), a.toConst());692 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));
695}695}
696696
697test "big.int mul a*0" {697test "big.int mul a*0" {
...@@ -704,7 +704,7 @@ test "big.int mul a*0" {...@@ -704,7 +704,7 @@ test "big.int mul a*0" {
704 defer c.deinit();704 defer c.deinit();
705 try c.mul(a.toConst(), b.toConst());705 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);
708}708}
709709
710test "big.int mul 0*0" {710test "big.int mul 0*0" {
...@@ -717,7 +717,7 @@ test "big.int mul 0*0" {...@@ -717,7 +717,7 @@ test "big.int mul 0*0" {
717 defer c.deinit();717 defer c.deinit();
718 try c.mul(a.toConst(), b.toConst());718 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);
721}721}
722722
723test "big.int mul large" {723test "big.int mul large" {
...@@ -738,7 +738,7 @@ test "big.int mul large" {...@@ -738,7 +738,7 @@ test "big.int mul large" {
738 try b.mul(a.toConst(), a.toConst());738 try b.mul(a.toConst(), a.toConst());
739 try c.sqr(a.toConst());739 try c.sqr(a.toConst());
740740
741 testing.expect(b.eq(c));741 try testing.expect(b.eq(c));
742}742}
743743
744test "big.int div single-single no rem" {744test "big.int div single-single no rem" {
...@@ -753,8 +753,8 @@ test "big.int div single-single no rem" {...@@ -753,8 +753,8 @@ test "big.int div single-single no rem" {
753 defer r.deinit();753 defer r.deinit();
754 try Managed.divTrunc(&q, &r, a.toConst(), b.toConst());754 try Managed.divTrunc(&q, &r, a.toConst(), b.toConst());
755755
756 testing.expect((try q.to(u32)) == 10);756 try testing.expect((try q.to(u32)) == 10);
757 testing.expect((try r.to(u32)) == 0);757 try testing.expect((try r.to(u32)) == 0);
758}758}
759759
760test "big.int div single-single with rem" {760test "big.int div single-single with rem" {
...@@ -769,8 +769,8 @@ test "big.int div single-single with rem" {...@@ -769,8 +769,8 @@ test "big.int div single-single with rem" {
769 defer r.deinit();769 defer r.deinit();
770 try Managed.divTrunc(&q, &r, a.toConst(), b.toConst());770 try Managed.divTrunc(&q, &r, a.toConst(), b.toConst());
771771
772 testing.expect((try q.to(u32)) == 9);772 try testing.expect((try q.to(u32)) == 9);
773 testing.expect((try r.to(u32)) == 4);773 try testing.expect((try r.to(u32)) == 4);
774}774}
775775
776test "big.int div multi-single no rem" {776test "big.int div multi-single no rem" {
...@@ -788,8 +788,8 @@ test "big.int div multi-single no rem" {...@@ -788,8 +788,8 @@ test "big.int div multi-single no rem" {
788 defer r.deinit();788 defer r.deinit();
789 try Managed.divTrunc(&q, &r, a.toConst(), b.toConst());789 try Managed.divTrunc(&q, &r, a.toConst(), b.toConst());
790790
791 testing.expect((try q.to(u64)) == op1 / op2);791 try testing.expect((try q.to(u64)) == op1 / op2);
792 testing.expect((try r.to(u64)) == 0);792 try testing.expect((try r.to(u64)) == 0);
793}793}
794794
795test "big.int div multi-single with rem" {795test "big.int div multi-single with rem" {
...@@ -807,8 +807,8 @@ test "big.int div multi-single with rem" {...@@ -807,8 +807,8 @@ test "big.int div multi-single with rem" {
807 defer r.deinit();807 defer r.deinit();
808 try Managed.divTrunc(&q, &r, a.toConst(), b.toConst());808 try Managed.divTrunc(&q, &r, a.toConst(), b.toConst());
809809
810 testing.expect((try q.to(u64)) == op1 / op2);810 try testing.expect((try q.to(u64)) == op1 / op2);
811 testing.expect((try r.to(u64)) == 3);811 try testing.expect((try r.to(u64)) == 3);
812}812}
813813
814test "big.int div multi>2-single" {814test "big.int div multi>2-single" {
...@@ -826,8 +826,8 @@ test "big.int div multi>2-single" {...@@ -826,8 +826,8 @@ test "big.int div multi>2-single" {
826 defer r.deinit();826 defer r.deinit();
827 try Managed.divTrunc(&q, &r, a.toConst(), b.toConst());827 try Managed.divTrunc(&q, &r, a.toConst(), b.toConst());
828828
829 testing.expect((try q.to(u128)) == op1 / op2);829 try testing.expect((try q.to(u128)) == op1 / op2);
830 testing.expect((try r.to(u32)) == 0x3e4e);830 try testing.expect((try r.to(u32)) == 0x3e4e);
831}831}
832832
833test "big.int div single-single q < r" {833test "big.int div single-single q < r" {
...@@ -842,8 +842,8 @@ test "big.int div single-single q < r" {...@@ -842,8 +842,8 @@ test "big.int div single-single q < r" {
842 defer r.deinit();842 defer r.deinit();
843 try Managed.divTrunc(&q, &r, a.toConst(), b.toConst());843 try Managed.divTrunc(&q, &r, a.toConst(), b.toConst());
844844
845 testing.expect((try q.to(u64)) == 0);845 try testing.expect((try q.to(u64)) == 0);
846 testing.expect((try r.to(u64)) == 0x0078f432);846 try testing.expect((try r.to(u64)) == 0x0078f432);
847}847}
848848
849test "big.int div single-single q == r" {849test "big.int div single-single q == r" {
...@@ -858,8 +858,8 @@ test "big.int div single-single q == r" {...@@ -858,8 +858,8 @@ test "big.int div single-single q == r" {
858 defer r.deinit();858 defer r.deinit();
859 try Managed.divTrunc(&q, &r, a.toConst(), b.toConst());859 try Managed.divTrunc(&q, &r, a.toConst(), b.toConst());
860860
861 testing.expect((try q.to(u64)) == 1);861 try testing.expect((try q.to(u64)) == 1);
862 testing.expect((try r.to(u64)) == 0);862 try testing.expect((try r.to(u64)) == 0);
863}863}
864864
865test "big.int div q=0 alias" {865test "big.int div q=0 alias" {
...@@ -870,8 +870,8 @@ test "big.int div q=0 alias" {...@@ -870,8 +870,8 @@ test "big.int div q=0 alias" {
870870
871 try Managed.divTrunc(&a, &b, a.toConst(), b.toConst());871 try Managed.divTrunc(&a, &b, a.toConst(), b.toConst());
872872
873 testing.expect((try a.to(u64)) == 0);873 try testing.expect((try a.to(u64)) == 0);
874 testing.expect((try b.to(u64)) == 3);874 try testing.expect((try b.to(u64)) == 3);
875}875}
876876
877test "big.int div multi-multi q < r" {877test "big.int div multi-multi q < r" {
...@@ -888,8 +888,8 @@ test "big.int div multi-multi q < r" {...@@ -888,8 +888,8 @@ test "big.int div multi-multi q < r" {
888 defer r.deinit();888 defer r.deinit();
889 try Managed.divTrunc(&q, &r, a.toConst(), b.toConst());889 try Managed.divTrunc(&q, &r, a.toConst(), b.toConst());
890890
891 testing.expect((try q.to(u128)) == 0);891 try testing.expect((try q.to(u128)) == 0);
892 testing.expect((try r.to(u128)) == op1);892 try testing.expect((try r.to(u128)) == op1);
893}893}
894894
895test "big.int div trunc single-single +/+" {895test "big.int div trunc single-single +/+" {
...@@ -912,8 +912,8 @@ test "big.int div trunc single-single +/+" {...@@ -912,8 +912,8 @@ test "big.int div trunc single-single +/+" {
912 const eq = @divTrunc(u, v);912 const eq = @divTrunc(u, v);
913 const er = @mod(u, v);913 const er = @mod(u, v);
914914
915 testing.expect((try q.to(i32)) == eq);915 try testing.expect((try q.to(i32)) == eq);
916 testing.expect((try r.to(i32)) == er);916 try testing.expect((try r.to(i32)) == er);
917}917}
918918
919test "big.int div trunc single-single -/+" {919test "big.int div trunc single-single -/+" {
...@@ -936,8 +936,8 @@ test "big.int div trunc single-single -/+" {...@@ -936,8 +936,8 @@ test "big.int div trunc single-single -/+" {
936 const eq = -1;936 const eq = -1;
937 const er = -2;937 const er = -2;
938938
939 testing.expect((try q.to(i32)) == eq);939 try testing.expect((try q.to(i32)) == eq);
940 testing.expect((try r.to(i32)) == er);940 try testing.expect((try r.to(i32)) == er);
941}941}
942942
943test "big.int div trunc single-single +/-" {943test "big.int div trunc single-single +/-" {
...@@ -960,8 +960,8 @@ test "big.int div trunc single-single +/-" {...@@ -960,8 +960,8 @@ test "big.int div trunc single-single +/-" {
960 const eq = -1;960 const eq = -1;
961 const er = 2;961 const er = 2;
962962
963 testing.expect((try q.to(i32)) == eq);963 try testing.expect((try q.to(i32)) == eq);
964 testing.expect((try r.to(i32)) == er);964 try testing.expect((try r.to(i32)) == er);
965}965}
966966
967test "big.int div trunc single-single -/-" {967test "big.int div trunc single-single -/-" {
...@@ -984,8 +984,8 @@ test "big.int div trunc single-single -/-" {...@@ -984,8 +984,8 @@ test "big.int div trunc single-single -/-" {
984 const eq = 1;984 const eq = 1;
985 const er = -2;985 const er = -2;
986986
987 testing.expect((try q.to(i32)) == eq);987 try testing.expect((try q.to(i32)) == eq);
988 testing.expect((try r.to(i32)) == er);988 try testing.expect((try r.to(i32)) == er);
989}989}
990990
991test "big.int div floor single-single +/+" {991test "big.int div floor single-single +/+" {
...@@ -1008,8 +1008,8 @@ test "big.int div floor single-single +/+" {...@@ -1008,8 +1008,8 @@ test "big.int div floor single-single +/+" {
1008 const eq = 1;1008 const eq = 1;
1009 const er = 2;1009 const er = 2;
10101010
1011 testing.expect((try q.to(i32)) == eq);1011 try testing.expect((try q.to(i32)) == eq);
1012 testing.expect((try r.to(i32)) == er);1012 try testing.expect((try r.to(i32)) == er);
1013}1013}
10141014
1015test "big.int div floor single-single -/+" {1015test "big.int div floor single-single -/+" {
...@@ -1032,8 +1032,8 @@ test "big.int div floor single-single -/+" {...@@ -1032,8 +1032,8 @@ test "big.int div floor single-single -/+" {
1032 const eq = -2;1032 const eq = -2;
1033 const er = 1;1033 const er = 1;
10341034
1035 testing.expect((try q.to(i32)) == eq);1035 try testing.expect((try q.to(i32)) == eq);
1036 testing.expect((try r.to(i32)) == er);1036 try testing.expect((try r.to(i32)) == er);
1037}1037}
10381038
1039test "big.int div floor single-single +/-" {1039test "big.int div floor single-single +/-" {
...@@ -1056,8 +1056,8 @@ test "big.int div floor single-single +/-" {...@@ -1056,8 +1056,8 @@ test "big.int div floor single-single +/-" {
1056 const eq = -2;1056 const eq = -2;
1057 const er = -1;1057 const er = -1;
10581058
1059 testing.expect((try q.to(i32)) == eq);1059 try testing.expect((try q.to(i32)) == eq);
1060 testing.expect((try r.to(i32)) == er);1060 try testing.expect((try r.to(i32)) == er);
1061}1061}
10621062
1063test "big.int div floor single-single -/-" {1063test "big.int div floor single-single -/-" {
...@@ -1080,8 +1080,8 @@ test "big.int div floor single-single -/-" {...@@ -1080,8 +1080,8 @@ test "big.int div floor single-single -/-" {
1080 const eq = 1;1080 const eq = 1;
1081 const er = -2;1081 const er = -2;
10821082
1083 testing.expect((try q.to(i32)) == eq);1083 try testing.expect((try q.to(i32)) == eq);
1084 testing.expect((try r.to(i32)) == er);1084 try testing.expect((try r.to(i32)) == er);
1085}1085}
10861086
1087test "big.int div multi-multi with rem" {1087test "big.int div multi-multi with rem" {
...@@ -1096,8 +1096,8 @@ test "big.int div multi-multi with rem" {...@@ -1096,8 +1096,8 @@ test "big.int div multi-multi with rem" {
1096 defer r.deinit();1096 defer r.deinit();
1097 try Managed.divTrunc(&q, &r, a.toConst(), b.toConst());1097 try Managed.divTrunc(&q, &r, a.toConst(), b.toConst());
10981098
1099 testing.expect((try q.to(u128)) == 0xe38f38e39161aaabd03f0f1b);1099 try testing.expect((try q.to(u128)) == 0xe38f38e39161aaabd03f0f1b);
1100 testing.expect((try r.to(u128)) == 0x28de0acacd806823638);1100 try testing.expect((try r.to(u128)) == 0x28de0acacd806823638);
1101}1101}
11021102
1103test "big.int div multi-multi no rem" {1103test "big.int div multi-multi no rem" {
...@@ -1112,8 +1112,8 @@ test "big.int div multi-multi no rem" {...@@ -1112,8 +1112,8 @@ test "big.int div multi-multi no rem" {
1112 defer r.deinit();1112 defer r.deinit();
1113 try Managed.divTrunc(&q, &r, a.toConst(), b.toConst());1113 try Managed.divTrunc(&q, &r, a.toConst(), b.toConst());
11141114
1115 testing.expect((try q.to(u128)) == 0xe38f38e39161aaabd03f0f1b);1115 try testing.expect((try q.to(u128)) == 0xe38f38e39161aaabd03f0f1b);
1116 testing.expect((try r.to(u128)) == 0);1116 try testing.expect((try r.to(u128)) == 0);
1117}1117}
11181118
1119test "big.int div multi-multi (2 branch)" {1119test "big.int div multi-multi (2 branch)" {
...@@ -1128,8 +1128,8 @@ test "big.int div multi-multi (2 branch)" {...@@ -1128,8 +1128,8 @@ test "big.int div multi-multi (2 branch)" {
1128 defer r.deinit();1128 defer r.deinit();
1129 try Managed.divTrunc(&q, &r, a.toConst(), b.toConst());1129 try Managed.divTrunc(&q, &r, a.toConst(), b.toConst());
11301130
1131 testing.expect((try q.to(u128)) == 0x10000000000000000);1131 try testing.expect((try q.to(u128)) == 0x10000000000000000);
1132 testing.expect((try r.to(u128)) == 0x44444443444444431111111111111111);1132 try testing.expect((try r.to(u128)) == 0x44444443444444431111111111111111);
1133}1133}
11341134
1135test "big.int div multi-multi (3.1/3.3 branch)" {1135test "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)" {...@@ -1144,8 +1144,8 @@ test "big.int div multi-multi (3.1/3.3 branch)" {
1144 defer r.deinit();1144 defer r.deinit();
1145 try Managed.divTrunc(&q, &r, a.toConst(), b.toConst());1145 try Managed.divTrunc(&q, &r, a.toConst(), b.toConst());
11461146
1147 testing.expect((try q.to(u128)) == 0xfffffffffffffffffff);1147 try testing.expect((try q.to(u128)) == 0xfffffffffffffffffff);
1148 testing.expect((try r.to(u256)) == 0x1111111111111111111110b12222222222222222282);1148 try testing.expect((try r.to(u256)) == 0x1111111111111111111110b12222222222222222282);
1149}1149}
11501150
1151test "big.int div multi-single zero-limb trailing" {1151test "big.int div multi-single zero-limb trailing" {
...@@ -1162,8 +1162,8 @@ test "big.int div multi-single zero-limb trailing" {...@@ -1162,8 +1162,8 @@ test "big.int div multi-single zero-limb trailing" {
11621162
1163 var expected = try Managed.initSet(testing.allocator, 0x6000000000000000000000000000000000000000000000000);1163 var expected = try Managed.initSet(testing.allocator, 0x6000000000000000000000000000000000000000000000000);
1164 defer expected.deinit();1164 defer expected.deinit();
1165 testing.expect(q.eq(expected));1165 try testing.expect(q.eq(expected));
1166 testing.expect(r.eqZero());1166 try testing.expect(r.eqZero());
1167}1167}
11681168
1169test "big.int div multi-multi zero-limb trailing (with rem)" {1169test "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)" {...@@ -1178,11 +1178,11 @@ test "big.int div multi-multi zero-limb trailing (with rem)" {
1178 defer r.deinit();1178 defer r.deinit();
1179 try Managed.divTrunc(&q, &r, a.toConst(), b.toConst());1179 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
1183 const rs = try r.toString(testing.allocator, 16, false);1183 const rs = try r.toString(testing.allocator, 16, false);
1184 defer testing.allocator.free(rs);1184 defer testing.allocator.free(rs);
1185 testing.expect(std.mem.eql(u8, rs, "4444444344444443111111111111111100000000000000000000000000000000"));1185 try testing.expect(std.mem.eql(u8, rs, "4444444344444443111111111111111100000000000000000000000000000000"));
1186}1186}
11871187
1188test "big.int div multi-multi zero-limb trailing (with rem) and dividend zero-limb count > divisor zero-limb count" {1188test "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...@@ -1197,11 +1197,11 @@ test "big.int div multi-multi zero-limb trailing (with rem) and dividend zero-li
1197 defer r.deinit();1197 defer r.deinit();
1198 try Managed.divTrunc(&q, &r, a.toConst(), b.toConst());1198 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
1202 const rs = try r.toString(testing.allocator, 16, false);1202 const rs = try r.toString(testing.allocator, 16, false);
1203 defer testing.allocator.free(rs);1203 defer testing.allocator.free(rs);
1204 testing.expect(std.mem.eql(u8, rs, "444444434444444311111111111111110000000000000000"));1204 try testing.expect(std.mem.eql(u8, rs, "444444434444444311111111111111110000000000000000"));
1205}1205}
12061206
1207test "big.int div multi-multi zero-limb trailing (with rem) and dividend zero-limb count < divisor zero-limb count" {1207test "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...@@ -1218,11 +1218,11 @@ test "big.int div multi-multi zero-limb trailing (with rem) and dividend zero-li
12181218
1219 const qs = try q.toString(testing.allocator, 16, false);1219 const qs = try q.toString(testing.allocator, 16, false);
1220 defer testing.allocator.free(qs);1220 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
1223 const rs = try r.toString(testing.allocator, 16, false);1223 const rs = try r.toString(testing.allocator, 16, false);
1224 defer testing.allocator.free(rs);1224 defer testing.allocator.free(rs);
1225 testing.expect(std.mem.eql(u8, rs, "4e11f2baa5896a321d463b543d0104e30000000000000000"));1225 try testing.expect(std.mem.eql(u8, rs, "4e11f2baa5896a321d463b543d0104e30000000000000000"));
1226}1226}
12271227
1228test "big.int div multi-multi fuzz case #1" {1228test "big.int div multi-multi fuzz case #1" {
...@@ -1242,11 +1242,11 @@ test "big.int div multi-multi fuzz case #1" {...@@ -1242,11 +1242,11 @@ test "big.int div multi-multi fuzz case #1" {
12421242
1243 const qs = try q.toString(testing.allocator, 16, false);1243 const qs = try q.toString(testing.allocator, 16, false);
1244 defer testing.allocator.free(qs);1244 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
1247 const rs = try r.toString(testing.allocator, 16, false);1247 const rs = try r.toString(testing.allocator, 16, false);
1248 defer testing.allocator.free(rs);1248 defer testing.allocator.free(rs);
1249 testing.expect(std.mem.eql(u8, rs, "310d1d4c414426b4836c2635bad1df3a424e50cbdd167ffccb4dfff57d36b4aae0d6ca0910698220171a0f3373c1060a046c2812f0027e321f72979daa5e7973214170d49e885de0c0ecc167837d44502430674a82522e5df6a0759548052420b91ec1"));1249 try testing.expect(std.mem.eql(u8, rs, "310d1d4c414426b4836c2635bad1df3a424e50cbdd167ffccb4dfff57d36b4aae0d6ca0910698220171a0f3373c1060a046c2812f0027e321f72979daa5e7973214170d49e885de0c0ecc167837d44502430674a82522e5df6a0759548052420b91ec1"));
1250}1250}
12511251
1252test "big.int div multi-multi fuzz case #2" {1252test "big.int div multi-multi fuzz case #2" {
...@@ -1266,11 +1266,11 @@ test "big.int div multi-multi fuzz case #2" {...@@ -1266,11 +1266,11 @@ test "big.int div multi-multi fuzz case #2" {
12661266
1267 const qs = try q.toString(testing.allocator, 16, false);1267 const qs = try q.toString(testing.allocator, 16, false);
1268 defer testing.allocator.free(qs);1268 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
1271 const rs = try r.toString(testing.allocator, 16, false);1271 const rs = try r.toString(testing.allocator, 16, false);
1272 defer testing.allocator.free(rs);1272 defer testing.allocator.free(rs);
1273 testing.expect(std.mem.eql(u8, rs, "a900000000000000000000000000000000000000000000000000"));1273 try testing.expect(std.mem.eql(u8, rs, "a900000000000000000000000000000000000000000000000000"));
1274}1274}
12751275
1276test "big.int shift-right single" {1276test "big.int shift-right single" {
...@@ -1278,7 +1278,7 @@ test "big.int shift-right single" {...@@ -1278,7 +1278,7 @@ test "big.int shift-right single" {
1278 defer a.deinit();1278 defer a.deinit();
1279 try a.shiftRight(a, 16);1279 try a.shiftRight(a, 16);
12801280
1281 testing.expect((try a.to(u32)) == 0xffff);1281 try testing.expect((try a.to(u32)) == 0xffff);
1282}1282}
12831283
1284test "big.int shift-right multi" {1284test "big.int shift-right multi" {
...@@ -1286,13 +1286,13 @@ test "big.int shift-right multi" {...@@ -1286,13 +1286,13 @@ test "big.int shift-right multi" {
1286 defer a.deinit();1286 defer a.deinit();
1287 try a.shiftRight(a, 67);1287 try a.shiftRight(a, 67);
12881288
1289 testing.expect((try a.to(u64)) == 0x1fffe0001dddc222);1289 try testing.expect((try a.to(u64)) == 0x1fffe0001dddc222);
12901290
1291 try a.set(0xffff0000eeee1111dddd2222cccc3333);1291 try a.set(0xffff0000eeee1111dddd2222cccc3333);
1292 try a.shiftRight(a, 63);1292 try a.shiftRight(a, 63);
1293 try a.shiftRight(a, 63);1293 try a.shiftRight(a, 63);
1294 try a.shiftRight(a, 2);1294 try a.shiftRight(a, 2);
1295 testing.expect(a.eqZero());1295 try testing.expect(a.eqZero());
1296}1296}
12971297
1298test "big.int shift-left single" {1298test "big.int shift-left single" {
...@@ -1300,7 +1300,7 @@ test "big.int shift-left single" {...@@ -1300,7 +1300,7 @@ test "big.int shift-left single" {
1300 defer a.deinit();1300 defer a.deinit();
1301 try a.shiftLeft(a, 16);1301 try a.shiftLeft(a, 16);
13021302
1303 testing.expect((try a.to(u64)) == 0xffff0000);1303 try testing.expect((try a.to(u64)) == 0xffff0000);
1304}1304}
13051305
1306test "big.int shift-left multi" {1306test "big.int shift-left multi" {
...@@ -1308,7 +1308,7 @@ test "big.int shift-left multi" {...@@ -1308,7 +1308,7 @@ test "big.int shift-left multi" {
1308 defer a.deinit();1308 defer a.deinit();
1309 try a.shiftLeft(a, 67);1309 try a.shiftLeft(a, 67);
13101310
1311 testing.expect((try a.to(u128)) == 0xffff0000eeee11100000000000000000);1311 try testing.expect((try a.to(u128)) == 0xffff0000eeee11100000000000000000);
1312}1312}
13131313
1314test "big.int shift-right negative" {1314test "big.int shift-right negative" {
...@@ -1318,12 +1318,12 @@ test "big.int shift-right negative" {...@@ -1318,12 +1318,12 @@ test "big.int shift-right negative" {
1318 var arg = try Managed.initSet(testing.allocator, -20);1318 var arg = try Managed.initSet(testing.allocator, -20);
1319 defer arg.deinit();1319 defer arg.deinit();
1320 try a.shiftRight(arg, 2);1320 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
1323 var arg2 = try Managed.initSet(testing.allocator, -5);1323 var arg2 = try Managed.initSet(testing.allocator, -5);
1324 defer arg2.deinit();1324 defer arg2.deinit();
1325 try a.shiftRight(arg2, 10);1325 try a.shiftRight(arg2, 10);
1326 testing.expect((try a.to(i32)) == -5 >> 10);1326 try testing.expect((try a.to(i32)) == -5 >> 10);
1327}1327}
13281328
1329test "big.int shift-left negative" {1329test "big.int shift-left negative" {
...@@ -1333,7 +1333,7 @@ test "big.int shift-left negative" {...@@ -1333,7 +1333,7 @@ test "big.int shift-left negative" {
1333 var arg = try Managed.initSet(testing.allocator, -10);1333 var arg = try Managed.initSet(testing.allocator, -10);
1334 defer arg.deinit();1334 defer arg.deinit();
1335 try a.shiftRight(arg, 1232);1335 try a.shiftRight(arg, 1232);
1336 testing.expect((try a.to(i32)) == -10 >> 1232);1336 try testing.expect((try a.to(i32)) == -10 >> 1232);
1337}1337}
13381338
1339test "big.int bitwise and simple" {1339test "big.int bitwise and simple" {
...@@ -1344,7 +1344,7 @@ test "big.int bitwise and simple" {...@@ -1344,7 +1344,7 @@ test "big.int bitwise and simple" {
13441344
1345 try a.bitAnd(a, b);1345 try a.bitAnd(a, b);
13461346
1347 testing.expect((try a.to(u64)) == 0xeeeeeeee00000000);1347 try testing.expect((try a.to(u64)) == 0xeeeeeeee00000000);
1348}1348}
13491349
1350test "big.int bitwise and multi-limb" {1350test "big.int bitwise and multi-limb" {
...@@ -1355,7 +1355,7 @@ test "big.int bitwise and multi-limb" {...@@ -1355,7 +1355,7 @@ test "big.int bitwise and multi-limb" {
13551355
1356 try a.bitAnd(a, b);1356 try a.bitAnd(a, b);
13571357
1358 testing.expect((try a.to(u128)) == 0);1358 try testing.expect((try a.to(u128)) == 0);
1359}1359}
13601360
1361test "big.int bitwise xor simple" {1361test "big.int bitwise xor simple" {
...@@ -1366,7 +1366,7 @@ test "big.int bitwise xor simple" {...@@ -1366,7 +1366,7 @@ test "big.int bitwise xor simple" {
13661366
1367 try a.bitXor(a, b);1367 try a.bitXor(a, b);
13681368
1369 testing.expect((try a.to(u64)) == 0x1111111133333333);1369 try testing.expect((try a.to(u64)) == 0x1111111133333333);
1370}1370}
13711371
1372test "big.int bitwise xor multi-limb" {1372test "big.int bitwise xor multi-limb" {
...@@ -1377,7 +1377,7 @@ test "big.int bitwise xor multi-limb" {...@@ -1377,7 +1377,7 @@ test "big.int bitwise xor multi-limb" {
13771377
1378 try a.bitXor(a, b);1378 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));
1381}1381}
13821382
1383test "big.int bitwise or simple" {1383test "big.int bitwise or simple" {
...@@ -1388,7 +1388,7 @@ test "big.int bitwise or simple" {...@@ -1388,7 +1388,7 @@ test "big.int bitwise or simple" {
13881388
1389 try a.bitOr(a, b);1389 try a.bitOr(a, b);
13901390
1391 testing.expect((try a.to(u64)) == 0xffffffff33333333);1391 try testing.expect((try a.to(u64)) == 0xffffffff33333333);
1392}1392}
13931393
1394test "big.int bitwise or multi-limb" {1394test "big.int bitwise or multi-limb" {
...@@ -1400,7 +1400,7 @@ test "big.int bitwise or multi-limb" {...@@ -1400,7 +1400,7 @@ test "big.int bitwise or multi-limb" {
1400 try a.bitOr(a, b);1400 try a.bitOr(a, b);
14011401
1402 // TODO: big.int.cpp or is wrong on multi-limb.1402 // 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));
1404}1404}
14051405
1406test "big.int var args" {1406test "big.int var args" {
...@@ -1410,15 +1410,15 @@ test "big.int var args" {...@@ -1410,15 +1410,15 @@ test "big.int var args" {
1410 var b = try Managed.initSet(testing.allocator, 6);1410 var b = try Managed.initSet(testing.allocator, 6);
1411 defer b.deinit();1411 defer b.deinit();
1412 try a.add(a.toConst(), b.toConst());1412 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
1415 var c = try Managed.initSet(testing.allocator, 11);1415 var c = try Managed.initSet(testing.allocator, 11);
1416 defer c.deinit();1416 defer c.deinit();
1417 testing.expect(a.order(c) == .eq);1417 try testing.expect(a.order(c) == .eq);
14181418
1419 var d = try Managed.initSet(testing.allocator, 14);1419 var d = try Managed.initSet(testing.allocator, 14);
1420 defer d.deinit();1420 defer d.deinit();
1421 testing.expect(a.order(d) != .gt);1421 try testing.expect(a.order(d) != .gt);
1422}1422}
14231423
1424test "big.int gcd non-one small" {1424test "big.int gcd non-one small" {
...@@ -1431,7 +1431,7 @@ test "big.int gcd non-one small" {...@@ -1431,7 +1431,7 @@ test "big.int gcd non-one small" {
14311431
1432 try r.gcd(a, b);1432 try r.gcd(a, b);
14331433
1434 testing.expect((try r.to(u32)) == 1);1434 try testing.expect((try r.to(u32)) == 1);
1435}1435}
14361436
1437test "big.int gcd non-one small" {1437test "big.int gcd non-one small" {
...@@ -1444,7 +1444,7 @@ test "big.int gcd non-one small" {...@@ -1444,7 +1444,7 @@ test "big.int gcd non-one small" {
14441444
1445 try r.gcd(a, b);1445 try r.gcd(a, b);
14461446
1447 testing.expect((try r.to(u32)) == 38);1447 try testing.expect((try r.to(u32)) == 38);
1448}1448}
14491449
1450test "big.int gcd non-one large" {1450test "big.int gcd non-one large" {
...@@ -1457,7 +1457,7 @@ test "big.int gcd non-one large" {...@@ -1457,7 +1457,7 @@ test "big.int gcd non-one large" {
14571457
1458 try r.gcd(a, b);1458 try r.gcd(a, b);
14591459
1460 testing.expect((try r.to(u32)) == 4369);1460 try testing.expect((try r.to(u32)) == 4369);
1461}1461}
14621462
1463test "big.int gcd large multi-limb result" {1463test "big.int gcd large multi-limb result" {
...@@ -1471,7 +1471,7 @@ test "big.int gcd large multi-limb result" {...@@ -1471,7 +1471,7 @@ test "big.int gcd large multi-limb result" {
1471 try r.gcd(a, b);1471 try r.gcd(a, b);
14721472
1473 const answer = (try r.to(u256));1473 const answer = (try r.to(u256));
1474 testing.expect(answer == 0xf000000ff00000fff0000ffff000fffff00ffffff1);1474 try testing.expect(answer == 0xf000000ff00000fff0000ffff000fffff00ffffff1);
1475}1475}
14761476
1477test "big.int gcd one large" {1477test "big.int gcd one large" {
...@@ -1484,7 +1484,7 @@ test "big.int gcd one large" {...@@ -1484,7 +1484,7 @@ test "big.int gcd one large" {
14841484
1485 try r.gcd(a, b);1485 try r.gcd(a, b);
14861486
1487 testing.expect((try r.to(u64)) == 1);1487 try testing.expect((try r.to(u64)) == 1);
1488}1488}
14891489
1490test "big.int mutable to managed" {1490test "big.int mutable to managed" {
...@@ -1495,7 +1495,7 @@ test "big.int mutable to managed" {...@@ -1495,7 +1495,7 @@ test "big.int mutable to managed" {
1495 var a = Mutable.init(limbs_buf, 0xdeadbeef);1495 var a = Mutable.init(limbs_buf, 0xdeadbeef);
1496 var a_managed = a.toManaged(allocator);1496 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()));
1499}1499}
15001500
1501test "big.int const to managed" {1501test "big.int const to managed" {
...@@ -1505,7 +1505,7 @@ test "big.int const to managed" {...@@ -1505,7 +1505,7 @@ test "big.int const to managed" {
1505 var b = try a.toConst().toManaged(testing.allocator);1505 var b = try a.toConst().toManaged(testing.allocator);
1506 defer b.deinit();1506 defer b.deinit();
15071507
1508 testing.expect(a.toConst().eq(b.toConst()));1508 try testing.expect(a.toConst().eq(b.toConst()));
1509}1509}
15101510
1511test "big.int pow" {1511test "big.int pow" {
...@@ -1514,10 +1514,10 @@ test "big.int pow" {...@@ -1514,10 +1514,10 @@ test "big.int pow" {
1514 defer a.deinit();1514 defer a.deinit();
15151515
1516 try a.pow(a.toConst(), 3);1516 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
1519 try a.pow(a.toConst(), 4);1519 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));
1521 }1521 }
1522 {1522 {
1523 var a = try Managed.initSet(testing.allocator, 10);1523 var a = try Managed.initSet(testing.allocator, 10);
...@@ -1531,11 +1531,11 @@ test "big.int pow" {...@@ -1531,11 +1531,11 @@ test "big.int pow" {
1531 // y and a are aliased1531 // y and a are aliased
1532 try a.pow(a.toConst(), 123);1532 try a.pow(a.toConst(), 123);
15331533
1534 testing.expect(a.eq(y));1534 try testing.expect(a.eq(y));
15351535
1536 const ys = try y.toString(testing.allocator, 16, false);1536 const ys = try y.toString(testing.allocator, 16, false);
1537 defer testing.allocator.free(ys);1537 defer testing.allocator.free(ys);
1538 testing.expectEqualSlices(1538 try testing.expectEqualSlices(
1539 u8,1539 u8,
1540 "183425a5f872f126e00a5ad62c839075cd6846c6fb0230887c7ad7a9dc530fcb" ++1540 "183425a5f872f126e00a5ad62c839075cd6846c6fb0230887c7ad7a9dc530fcb" ++
1541 "4933f60e8000000000000000000000000000000",1541 "4933f60e8000000000000000000000000000000",
...@@ -1548,17 +1548,17 @@ test "big.int pow" {...@@ -1548,17 +1548,17 @@ test "big.int pow" {
1548 defer a.deinit();1548 defer a.deinit();
15491549
1550 try a.pow(a.toConst(), 100);1550 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
1553 try a.set(1);1553 try a.set(1);
1554 try a.pow(a.toConst(), 0);1554 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));
1556 try a.pow(a.toConst(), 100);1556 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));
1558 try a.set(-1);1558 try a.set(-1);
1559 try a.pow(a.toConst(), 15);1559 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));
1561 try a.pow(a.toConst(), 16);1561 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));
1563 }1563 }
1564}1564}
lib/std/math/big/rational.zig+67-67
...@@ -473,7 +473,7 @@ pub const Rational = struct {...@@ -473,7 +473,7 @@ pub const Rational = struct {
473};473};
474474
475fn extractLowBits(a: Int, comptime T: type) T {475fn extractLowBits(a: Int, comptime T: type) T {
476 testing.expect(@typeInfo(T) == .Int);476 debug.assert(@typeInfo(T) == .Int);
477477
478 const t_bits = @typeInfo(T).Int.bits;478 const t_bits = @typeInfo(T).Int.bits;
479 const limb_bits = @typeInfo(Limb).Int.bits;479 const limb_bits = @typeInfo(Limb).Int.bits;
...@@ -498,19 +498,19 @@ test "big.rational extractLowBits" {...@@ -498,19 +498,19 @@ test "big.rational extractLowBits" {
498 defer a.deinit();498 defer a.deinit();
499499
500 const a1 = extractLowBits(a, u8);500 const a1 = extractLowBits(a, u8);
501 testing.expect(a1 == 0x21);501 try testing.expect(a1 == 0x21);
502502
503 const a2 = extractLowBits(a, u16);503 const a2 = extractLowBits(a, u16);
504 testing.expect(a2 == 0x4321);504 try testing.expect(a2 == 0x4321);
505505
506 const a3 = extractLowBits(a, u32);506 const a3 = extractLowBits(a, u32);
507 testing.expect(a3 == 0x87654321);507 try testing.expect(a3 == 0x87654321);
508508
509 const a4 = extractLowBits(a, u64);509 const a4 = extractLowBits(a, u64);
510 testing.expect(a4 == 0x1234567887654321);510 try testing.expect(a4 == 0x1234567887654321);
511511
512 const a5 = extractLowBits(a, u128);512 const a5 = extractLowBits(a, u128);
513 testing.expect(a5 == 0x11112222333344441234567887654321);513 try testing.expect(a5 == 0x11112222333344441234567887654321);
514}514}
515515
516test "big.rational set" {516test "big.rational set" {
...@@ -518,28 +518,28 @@ test "big.rational set" {...@@ -518,28 +518,28 @@ test "big.rational set" {
518 defer a.deinit();518 defer a.deinit();
519519
520 try a.setInt(5);520 try a.setInt(5);
521 testing.expect((try a.p.to(u32)) == 5);521 try testing.expect((try a.p.to(u32)) == 5);
522 testing.expect((try a.q.to(u32)) == 1);522 try testing.expect((try a.q.to(u32)) == 1);
523523
524 try a.setRatio(7, 3);524 try a.setRatio(7, 3);
525 testing.expect((try a.p.to(u32)) == 7);525 try testing.expect((try a.p.to(u32)) == 7);
526 testing.expect((try a.q.to(u32)) == 3);526 try testing.expect((try a.q.to(u32)) == 3);
527527
528 try a.setRatio(9, 3);528 try a.setRatio(9, 3);
529 testing.expect((try a.p.to(i32)) == 3);529 try testing.expect((try a.p.to(i32)) == 3);
530 testing.expect((try a.q.to(i32)) == 1);530 try testing.expect((try a.q.to(i32)) == 1);
531531
532 try a.setRatio(-9, 3);532 try a.setRatio(-9, 3);
533 testing.expect((try a.p.to(i32)) == -3);533 try testing.expect((try a.p.to(i32)) == -3);
534 testing.expect((try a.q.to(i32)) == 1);534 try testing.expect((try a.q.to(i32)) == 1);
535535
536 try a.setRatio(9, -3);536 try a.setRatio(9, -3);
537 testing.expect((try a.p.to(i32)) == -3);537 try testing.expect((try a.p.to(i32)) == -3);
538 testing.expect((try a.q.to(i32)) == 1);538 try testing.expect((try a.q.to(i32)) == 1);
539539
540 try a.setRatio(-9, -3);540 try a.setRatio(-9, -3);
541 testing.expect((try a.p.to(i32)) == 3);541 try testing.expect((try a.p.to(i32)) == 3);
542 testing.expect((try a.q.to(i32)) == 1);542 try testing.expect((try a.q.to(i32)) == 1);
543}543}
544544
545test "big.rational setFloat" {545test "big.rational setFloat" {
...@@ -547,24 +547,24 @@ test "big.rational setFloat" {...@@ -547,24 +547,24 @@ test "big.rational setFloat" {
547 defer a.deinit();547 defer a.deinit();
548548
549 try a.setFloat(f64, 2.5);549 try a.setFloat(f64, 2.5);
550 testing.expect((try a.p.to(i32)) == 5);550 try testing.expect((try a.p.to(i32)) == 5);
551 testing.expect((try a.q.to(i32)) == 2);551 try testing.expect((try a.q.to(i32)) == 2);
552552
553 try a.setFloat(f32, -2.5);553 try a.setFloat(f32, -2.5);
554 testing.expect((try a.p.to(i32)) == -5);554 try testing.expect((try a.p.to(i32)) == -5);
555 testing.expect((try a.q.to(i32)) == 2);555 try testing.expect((try a.q.to(i32)) == 2);
556556
557 try a.setFloat(f32, 3.141593);557 try a.setFloat(f32, 3.141593);
558558
559 // = 3.14159297943115234375559 // = 3.14159297943115234375
560 testing.expect((try a.p.to(u32)) == 3294199);560 try testing.expect((try a.p.to(u32)) == 3294199);
561 testing.expect((try a.q.to(u32)) == 1048576);561 try testing.expect((try a.q.to(u32)) == 1048576);
562562
563 try a.setFloat(f64, 72.141593120712409172417410926841290461290467124);563 try a.setFloat(f64, 72.141593120712409172417410926841290461290467124);
564564
565 // = 72.1415931207124145885245525278151035308837890625565 // = 72.1415931207124145885245525278151035308837890625
566 testing.expect((try a.p.to(u128)) == 5076513310880537);566 try testing.expect((try a.p.to(u128)) == 5076513310880537);
567 testing.expect((try a.q.to(u128)) == 70368744177664);567 try testing.expect((try a.q.to(u128)) == 70368744177664);
568}568}
569569
570test "big.rational setFloatString" {570test "big.rational setFloatString" {
...@@ -574,8 +574,8 @@ test "big.rational setFloatString" {...@@ -574,8 +574,8 @@ test "big.rational setFloatString" {
574 try a.setFloatString("72.14159312071241458852455252781510353");574 try a.setFloatString("72.14159312071241458852455252781510353");
575575
576 // = 72.1415931207124145885245525278151035308837890625576 // = 72.1415931207124145885245525278151035308837890625
577 testing.expect((try a.p.to(u128)) == 7214159312071241458852455252781510353);577 try testing.expect((try a.p.to(u128)) == 7214159312071241458852455252781510353);
578 testing.expect((try a.q.to(u128)) == 100000000000000000000000000000000000);578 try testing.expect((try a.q.to(u128)) == 100000000000000000000000000000000000);
579}579}
580580
581test "big.rational toFloat" {581test "big.rational toFloat" {
...@@ -584,11 +584,11 @@ test "big.rational toFloat" {...@@ -584,11 +584,11 @@ test "big.rational toFloat" {
584584
585 // = 3.14159297943115234375585 // = 3.14159297943115234375
586 try a.setRatio(3294199, 1048576);586 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
589 // = 72.1415931207124145885245525278151035308837890625589 // = 72.1415931207124145885245525278151035308837890625
590 try a.setRatio(5076513310880537, 70368744177664);590 try a.setRatio(5076513310880537, 70368744177664);
591 testing.expect((try a.toFloat(f64)) == 72.141593120712409172417410926841290461290467124);591 try testing.expect((try a.toFloat(f64)) == 72.141593120712409172417410926841290461290467124);
592}592}
593593
594test "big.rational set/to Float round-trip" {594test "big.rational set/to Float round-trip" {
...@@ -599,7 +599,7 @@ test "big.rational set/to Float round-trip" {...@@ -599,7 +599,7 @@ test "big.rational set/to Float round-trip" {
599 while (i < 512) : (i += 1) {599 while (i < 512) : (i += 1) {
600 const r = prng.random.float(f64);600 const r = prng.random.float(f64);
601 try a.setFloat(f64, r);601 try a.setFloat(f64, r);
602 testing.expect((try a.toFloat(f64)) == r);602 try testing.expect((try a.toFloat(f64)) == r);
603 }603 }
604}604}
605605
...@@ -611,8 +611,8 @@ test "big.rational copy" {...@@ -611,8 +611,8 @@ test "big.rational copy" {
611 defer b.deinit();611 defer b.deinit();
612612
613 try a.copyInt(b);613 try a.copyInt(b);
614 testing.expect((try a.p.to(u32)) == 5);614 try testing.expect((try a.p.to(u32)) == 5);
615 testing.expect((try a.q.to(u32)) == 1);615 try testing.expect((try a.q.to(u32)) == 1);
616616
617 var c = try Int.initSet(testing.allocator, 7);617 var c = try Int.initSet(testing.allocator, 7);
618 defer c.deinit();618 defer c.deinit();
...@@ -620,8 +620,8 @@ test "big.rational copy" {...@@ -620,8 +620,8 @@ test "big.rational copy" {
620 defer d.deinit();620 defer d.deinit();
621621
622 try a.copyRatio(c, d);622 try a.copyRatio(c, d);
623 testing.expect((try a.p.to(u32)) == 7);623 try testing.expect((try a.p.to(u32)) == 7);
624 testing.expect((try a.q.to(u32)) == 3);624 try testing.expect((try a.q.to(u32)) == 3);
625625
626 var e = try Int.initSet(testing.allocator, 9);626 var e = try Int.initSet(testing.allocator, 9);
627 defer e.deinit();627 defer e.deinit();
...@@ -629,8 +629,8 @@ test "big.rational copy" {...@@ -629,8 +629,8 @@ test "big.rational copy" {
629 defer f.deinit();629 defer f.deinit();
630630
631 try a.copyRatio(e, f);631 try a.copyRatio(e, f);
632 testing.expect((try a.p.to(u32)) == 3);632 try testing.expect((try a.p.to(u32)) == 3);
633 testing.expect((try a.q.to(u32)) == 1);633 try testing.expect((try a.q.to(u32)) == 1);
634}634}
635635
636test "big.rational negate" {636test "big.rational negate" {
...@@ -638,16 +638,16 @@ test "big.rational negate" {...@@ -638,16 +638,16 @@ test "big.rational negate" {
638 defer a.deinit();638 defer a.deinit();
639639
640 try a.setInt(-50);640 try a.setInt(-50);
641 testing.expect((try a.p.to(i32)) == -50);641 try testing.expect((try a.p.to(i32)) == -50);
642 testing.expect((try a.q.to(i32)) == 1);642 try testing.expect((try a.q.to(i32)) == 1);
643643
644 a.negate();644 a.negate();
645 testing.expect((try a.p.to(i32)) == 50);645 try testing.expect((try a.p.to(i32)) == 50);
646 testing.expect((try a.q.to(i32)) == 1);646 try testing.expect((try a.q.to(i32)) == 1);
647647
648 a.negate();648 a.negate();
649 testing.expect((try a.p.to(i32)) == -50);649 try testing.expect((try a.p.to(i32)) == -50);
650 testing.expect((try a.q.to(i32)) == 1);650 try testing.expect((try a.q.to(i32)) == 1);
651}651}
652652
653test "big.rational abs" {653test "big.rational abs" {
...@@ -655,16 +655,16 @@ test "big.rational abs" {...@@ -655,16 +655,16 @@ test "big.rational abs" {
655 defer a.deinit();655 defer a.deinit();
656656
657 try a.setInt(-50);657 try a.setInt(-50);
658 testing.expect((try a.p.to(i32)) == -50);658 try testing.expect((try a.p.to(i32)) == -50);
659 testing.expect((try a.q.to(i32)) == 1);659 try testing.expect((try a.q.to(i32)) == 1);
660660
661 a.abs();661 a.abs();
662 testing.expect((try a.p.to(i32)) == 50);662 try testing.expect((try a.p.to(i32)) == 50);
663 testing.expect((try a.q.to(i32)) == 1);663 try testing.expect((try a.q.to(i32)) == 1);
664664
665 a.abs();665 a.abs();
666 testing.expect((try a.p.to(i32)) == 50);666 try testing.expect((try a.p.to(i32)) == 50);
667 testing.expect((try a.q.to(i32)) == 1);667 try testing.expect((try a.q.to(i32)) == 1);
668}668}
669669
670test "big.rational swap" {670test "big.rational swap" {
...@@ -676,19 +676,19 @@ test "big.rational swap" {...@@ -676,19 +676,19 @@ test "big.rational swap" {
676 try a.setRatio(50, 23);676 try a.setRatio(50, 23);
677 try b.setRatio(17, 3);677 try b.setRatio(17, 3);
678678
679 testing.expect((try a.p.to(u32)) == 50);679 try testing.expect((try a.p.to(u32)) == 50);
680 testing.expect((try a.q.to(u32)) == 23);680 try testing.expect((try a.q.to(u32)) == 23);
681681
682 testing.expect((try b.p.to(u32)) == 17);682 try testing.expect((try b.p.to(u32)) == 17);
683 testing.expect((try b.q.to(u32)) == 3);683 try testing.expect((try b.q.to(u32)) == 3);
684684
685 a.swap(&b);685 a.swap(&b);
686686
687 testing.expect((try a.p.to(u32)) == 17);687 try testing.expect((try a.p.to(u32)) == 17);
688 testing.expect((try a.q.to(u32)) == 3);688 try testing.expect((try a.q.to(u32)) == 3);
689689
690 testing.expect((try b.p.to(u32)) == 50);690 try testing.expect((try b.p.to(u32)) == 50);
691 testing.expect((try b.q.to(u32)) == 23);691 try testing.expect((try b.q.to(u32)) == 23);
692}692}
693693
694test "big.rational order" {694test "big.rational order" {
...@@ -699,11 +699,11 @@ test "big.rational order" {...@@ -699,11 +699,11 @@ test "big.rational order" {
699699
700 try a.setRatio(500, 231);700 try a.setRatio(500, 231);
701 try b.setRatio(18903, 8584);701 try b.setRatio(18903, 8584);
702 testing.expect((try a.order(b)) == .lt);702 try testing.expect((try a.order(b)) == .lt);
703703
704 try a.setRatio(890, 10);704 try a.setRatio(890, 10);
705 try b.setRatio(89, 1);705 try b.setRatio(89, 1);
706 testing.expect((try a.order(b)) == .eq);706 try testing.expect((try a.order(b)) == .eq);
707}707}
708708
709test "big.rational add single-limb" {709test "big.rational add single-limb" {
...@@ -714,11 +714,11 @@ test "big.rational add single-limb" {...@@ -714,11 +714,11 @@ test "big.rational add single-limb" {
714714
715 try a.setRatio(500, 231);715 try a.setRatio(500, 231);
716 try b.setRatio(18903, 8584);716 try b.setRatio(18903, 8584);
717 testing.expect((try a.order(b)) == .lt);717 try testing.expect((try a.order(b)) == .lt);
718718
719 try a.setRatio(890, 10);719 try a.setRatio(890, 10);
720 try b.setRatio(89, 1);720 try b.setRatio(89, 1);
721 testing.expect((try a.order(b)) == .eq);721 try testing.expect((try a.order(b)) == .eq);
722}722}
723723
724test "big.rational add" {724test "big.rational add" {
...@@ -734,7 +734,7 @@ test "big.rational add" {...@@ -734,7 +734,7 @@ test "big.rational add" {
734 try a.add(a, b);734 try a.add(a, b);
735735
736 try r.setRatio(984786924199, 290395044174);736 try r.setRatio(984786924199, 290395044174);
737 testing.expect((try a.order(r)) == .eq);737 try testing.expect((try a.order(r)) == .eq);
738}738}
739739
740test "big.rational sub" {740test "big.rational sub" {
...@@ -750,7 +750,7 @@ test "big.rational sub" {...@@ -750,7 +750,7 @@ test "big.rational sub" {
750 try a.sub(a, b);750 try a.sub(a, b);
751751
752 try r.setRatio(979040510045, 290395044174);752 try r.setRatio(979040510045, 290395044174);
753 testing.expect((try a.order(r)) == .eq);753 try testing.expect((try a.order(r)) == .eq);
754}754}
755755
756test "big.rational mul" {756test "big.rational mul" {
...@@ -766,7 +766,7 @@ test "big.rational mul" {...@@ -766,7 +766,7 @@ test "big.rational mul" {
766 try a.mul(a, b);766 try a.mul(a, b);
767767
768 try r.setRatio(571481443, 17082061422);768 try r.setRatio(571481443, 17082061422);
769 testing.expect((try a.order(r)) == .eq);769 try testing.expect((try a.order(r)) == .eq);
770}770}
771771
772test "big.rational div" {772test "big.rational div" {
...@@ -782,7 +782,7 @@ test "big.rational div" {...@@ -782,7 +782,7 @@ test "big.rational div" {
782 try a.div(a, b);782 try a.div(a, b);
783783
784 try r.setRatio(75531824394, 221015929);784 try r.setRatio(75531824394, 221015929);
785 testing.expect((try a.order(r)) == .eq);785 try testing.expect((try a.order(r)) == .eq);
786}786}
787787
788test "big.rational div" {788test "big.rational div" {
...@@ -795,11 +795,11 @@ test "big.rational div" {...@@ -795,11 +795,11 @@ test "big.rational div" {
795 a.invert();795 a.invert();
796796
797 try r.setRatio(23341, 78923);797 try r.setRatio(23341, 78923);
798 testing.expect((try a.order(r)) == .eq);798 try testing.expect((try a.order(r)) == .eq);
799799
800 try a.setRatio(-78923, 23341);800 try a.setRatio(-78923, 23341);
801 a.invert();801 a.invert();
802802
803 try r.setRatio(-23341, 78923);803 try r.setRatio(-23341, 78923);
804 testing.expect((try a.order(r)) == .eq);804 try testing.expect((try a.order(r)) == .eq);
805}805}
lib/std/math/cbrt.zig+24-24
...@@ -125,44 +125,44 @@ fn cbrt64(x: f64) f64 {...@@ -125,44 +125,44 @@ fn cbrt64(x: f64) f64 {
125}125}
126126
127test "math.cbrt" {127test "math.cbrt" {
128 expect(cbrt(@as(f32, 0.0)) == cbrt32(0.0));128 try expect(cbrt(@as(f32, 0.0)) == cbrt32(0.0));
129 expect(cbrt(@as(f64, 0.0)) == cbrt64(0.0));129 try expect(cbrt(@as(f64, 0.0)) == cbrt64(0.0));
130}130}
131131
132test "math.cbrt32" {132test "math.cbrt32" {
133 const epsilon = 0.000001;133 const epsilon = 0.000001;
134134
135 expect(cbrt32(0.0) == 0.0);135 try expect(cbrt32(0.0) == 0.0);
136 expect(math.approxEqAbs(f32, cbrt32(0.2), 0.584804, epsilon));136 try expect(math.approxEqAbs(f32, cbrt32(0.2), 0.584804, epsilon));
137 expect(math.approxEqAbs(f32, cbrt32(0.8923), 0.962728, epsilon));137 try expect(math.approxEqAbs(f32, cbrt32(0.8923), 0.962728, epsilon));
138 expect(math.approxEqAbs(f32, cbrt32(1.5), 1.144714, epsilon));138 try expect(math.approxEqAbs(f32, cbrt32(1.5), 1.144714, epsilon));
139 expect(math.approxEqAbs(f32, cbrt32(37.45), 3.345676, epsilon));139 try expect(math.approxEqAbs(f32, cbrt32(37.45), 3.345676, epsilon));
140 expect(math.approxEqAbs(f32, cbrt32(123123.234375), 49.748501, epsilon));140 try expect(math.approxEqAbs(f32, cbrt32(123123.234375), 49.748501, epsilon));
141}141}
142142
143test "math.cbrt64" {143test "math.cbrt64" {
144 const epsilon = 0.000001;144 const epsilon = 0.000001;
145145
146 expect(cbrt64(0.0) == 0.0);146 try expect(cbrt64(0.0) == 0.0);
147 expect(math.approxEqAbs(f64, cbrt64(0.2), 0.584804, epsilon));147 try expect(math.approxEqAbs(f64, cbrt64(0.2), 0.584804, epsilon));
148 expect(math.approxEqAbs(f64, cbrt64(0.8923), 0.962728, epsilon));148 try expect(math.approxEqAbs(f64, cbrt64(0.8923), 0.962728, epsilon));
149 expect(math.approxEqAbs(f64, cbrt64(1.5), 1.144714, epsilon));149 try expect(math.approxEqAbs(f64, cbrt64(1.5), 1.144714, epsilon));
150 expect(math.approxEqAbs(f64, cbrt64(37.45), 3.345676, epsilon));150 try expect(math.approxEqAbs(f64, cbrt64(37.45), 3.345676, epsilon));
151 expect(math.approxEqAbs(f64, cbrt64(123123.234375), 49.748501, epsilon));151 try expect(math.approxEqAbs(f64, cbrt64(123123.234375), 49.748501, epsilon));
152}152}
153153
154test "math.cbrt.special" {154test "math.cbrt.special" {
155 expect(cbrt32(0.0) == 0.0);155 try expect(cbrt32(0.0) == 0.0);
156 expect(cbrt32(-0.0) == -0.0);156 try expect(cbrt32(-0.0) == -0.0);
157 expect(math.isPositiveInf(cbrt32(math.inf(f32))));157 try expect(math.isPositiveInf(cbrt32(math.inf(f32))));
158 expect(math.isNegativeInf(cbrt32(-math.inf(f32))));158 try expect(math.isNegativeInf(cbrt32(-math.inf(f32))));
159 expect(math.isNan(cbrt32(math.nan(f32))));159 try expect(math.isNan(cbrt32(math.nan(f32))));
160}160}
161161
162test "math.cbrt64.special" {162test "math.cbrt64.special" {
163 expect(cbrt64(0.0) == 0.0);163 try expect(cbrt64(0.0) == 0.0);
164 expect(cbrt64(-0.0) == -0.0);164 try expect(cbrt64(-0.0) == -0.0);
165 expect(math.isPositiveInf(cbrt64(math.inf(f64))));165 try expect(math.isPositiveInf(cbrt64(math.inf(f64))));
166 expect(math.isNegativeInf(cbrt64(-math.inf(f64))));166 try expect(math.isNegativeInf(cbrt64(-math.inf(f64))));
167 expect(math.isNan(cbrt64(math.nan(f64))));167 try expect(math.isNan(cbrt64(math.nan(f64))));
168}168}
lib/std/math/ceil.zig+27-27
...@@ -119,49 +119,49 @@ fn ceil128(x: f128) f128 {...@@ -119,49 +119,49 @@ fn ceil128(x: f128) f128 {
119}119}
120120
121test "math.ceil" {121test "math.ceil" {
122 expect(ceil(@as(f32, 0.0)) == ceil32(0.0));122 try expect(ceil(@as(f32, 0.0)) == ceil32(0.0));
123 expect(ceil(@as(f64, 0.0)) == ceil64(0.0));123 try expect(ceil(@as(f64, 0.0)) == ceil64(0.0));
124 expect(ceil(@as(f128, 0.0)) == ceil128(0.0));124 try expect(ceil(@as(f128, 0.0)) == ceil128(0.0));
125}125}
126126
127test "math.ceil32" {127test "math.ceil32" {
128 expect(ceil32(1.3) == 2.0);128 try expect(ceil32(1.3) == 2.0);
129 expect(ceil32(-1.3) == -1.0);129 try expect(ceil32(-1.3) == -1.0);
130 expect(ceil32(0.2) == 1.0);130 try expect(ceil32(0.2) == 1.0);
131}131}
132132
133test "math.ceil64" {133test "math.ceil64" {
134 expect(ceil64(1.3) == 2.0);134 try expect(ceil64(1.3) == 2.0);
135 expect(ceil64(-1.3) == -1.0);135 try expect(ceil64(-1.3) == -1.0);
136 expect(ceil64(0.2) == 1.0);136 try expect(ceil64(0.2) == 1.0);
137}137}
138138
139test "math.ceil128" {139test "math.ceil128" {
140 expect(ceil128(1.3) == 2.0);140 try expect(ceil128(1.3) == 2.0);
141 expect(ceil128(-1.3) == -1.0);141 try expect(ceil128(-1.3) == -1.0);
142 expect(ceil128(0.2) == 1.0);142 try expect(ceil128(0.2) == 1.0);
143}143}
144144
145test "math.ceil32.special" {145test "math.ceil32.special" {
146 expect(ceil32(0.0) == 0.0);146 try expect(ceil32(0.0) == 0.0);
147 expect(ceil32(-0.0) == -0.0);147 try expect(ceil32(-0.0) == -0.0);
148 expect(math.isPositiveInf(ceil32(math.inf(f32))));148 try expect(math.isPositiveInf(ceil32(math.inf(f32))));
149 expect(math.isNegativeInf(ceil32(-math.inf(f32))));149 try expect(math.isNegativeInf(ceil32(-math.inf(f32))));
150 expect(math.isNan(ceil32(math.nan(f32))));150 try expect(math.isNan(ceil32(math.nan(f32))));
151}151}
152152
153test "math.ceil64.special" {153test "math.ceil64.special" {
154 expect(ceil64(0.0) == 0.0);154 try expect(ceil64(0.0) == 0.0);
155 expect(ceil64(-0.0) == -0.0);155 try expect(ceil64(-0.0) == -0.0);
156 expect(math.isPositiveInf(ceil64(math.inf(f64))));156 try expect(math.isPositiveInf(ceil64(math.inf(f64))));
157 expect(math.isNegativeInf(ceil64(-math.inf(f64))));157 try expect(math.isNegativeInf(ceil64(-math.inf(f64))));
158 expect(math.isNan(ceil64(math.nan(f64))));158 try expect(math.isNan(ceil64(math.nan(f64))));
159}159}
160160
161test "math.ceil128.special" {161test "math.ceil128.special" {
162 expect(ceil128(0.0) == 0.0);162 try expect(ceil128(0.0) == 0.0);
163 expect(ceil128(-0.0) == -0.0);163 try expect(ceil128(-0.0) == -0.0);
164 expect(math.isPositiveInf(ceil128(math.inf(f128))));164 try expect(math.isPositiveInf(ceil128(math.inf(f128))));
165 expect(math.isNegativeInf(ceil128(-math.inf(f128))));165 try expect(math.isNegativeInf(ceil128(-math.inf(f128))));
166 expect(math.isNan(ceil128(math.nan(f128))));166 try expect(math.isNan(ceil128(math.nan(f128))));
167}167}
lib/std/math/complex.zig+7-7
...@@ -114,7 +114,7 @@ test "complex.add" {...@@ -114,7 +114,7 @@ test "complex.add" {
114 const b = Complex(f32).new(2, 7);114 const b = Complex(f32).new(2, 7);
115 const c = a.add(b);115 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);
118}118}
119119
120test "complex.sub" {120test "complex.sub" {
...@@ -122,7 +122,7 @@ test "complex.sub" {...@@ -122,7 +122,7 @@ test "complex.sub" {
122 const b = Complex(f32).new(2, 7);122 const b = Complex(f32).new(2, 7);
123 const c = a.sub(b);123 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);
126}126}
127127
128test "complex.mul" {128test "complex.mul" {
...@@ -130,7 +130,7 @@ test "complex.mul" {...@@ -130,7 +130,7 @@ test "complex.mul" {
130 const b = Complex(f32).new(2, 7);130 const b = Complex(f32).new(2, 7);
131 const c = a.mul(b);131 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);
134}134}
135135
136test "complex.div" {136test "complex.div" {
...@@ -138,7 +138,7 @@ test "complex.div" {...@@ -138,7 +138,7 @@ test "complex.div" {
138 const b = Complex(f32).new(2, 7);138 const b = Complex(f32).new(2, 7);
139 const c = a.div(b);139 const c = a.div(b);
140140
141 testing.expect(math.approxEqAbs(f32, c.re, @as(f32, 31) / 53, epsilon) and141 try testing.expect(math.approxEqAbs(f32, c.re, @as(f32, 31) / 53, epsilon) and
142 math.approxEqAbs(f32, c.im, @as(f32, -29) / 53, epsilon));142 math.approxEqAbs(f32, c.im, @as(f32, -29) / 53, epsilon));
143}143}
144144
...@@ -146,14 +146,14 @@ test "complex.conjugate" {...@@ -146,14 +146,14 @@ test "complex.conjugate" {
146 const a = Complex(f32).new(5, 3);146 const a = Complex(f32).new(5, 3);
147 const c = a.conjugate();147 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);
150}150}
151151
152test "complex.reciprocal" {152test "complex.reciprocal" {
153 const a = Complex(f32).new(5, 3);153 const a = Complex(f32).new(5, 3);
154 const c = a.reciprocal();154 const c = a.reciprocal();
155155
156 testing.expect(math.approxEqAbs(f32, c.re, @as(f32, 5) / 34, epsilon) and156 try testing.expect(math.approxEqAbs(f32, c.re, @as(f32, 5) / 34, epsilon) and
157 math.approxEqAbs(f32, c.im, @as(f32, -3) / 34, epsilon));157 math.approxEqAbs(f32, c.im, @as(f32, -3) / 34, epsilon));
158}158}
159159
...@@ -161,7 +161,7 @@ test "complex.magnitude" {...@@ -161,7 +161,7 @@ test "complex.magnitude" {
161 const a = Complex(f32).new(5, 3);161 const a = Complex(f32).new(5, 3);
162 const c = a.magnitude();162 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));
165}165}
166166
167test "complex.cmath" {167test "complex.cmath" {
lib/std/math/complex/abs.zig+1-1
...@@ -20,5 +20,5 @@ const epsilon = 0.0001;...@@ -20,5 +20,5 @@ const epsilon = 0.0001;
20test "complex.cabs" {20test "complex.cabs" {
21 const a = Complex(f32).new(5, 3);21 const a = Complex(f32).new(5, 3);
22 const c = abs(a);22 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));
24}24}
lib/std/math/complex/acos.zig+2-2
...@@ -22,6 +22,6 @@ test "complex.cacos" {...@@ -22,6 +22,6 @@ test "complex.cacos" {
22 const a = Complex(f32).new(5, 3);22 const a = Complex(f32).new(5, 3);
23 const c = acos(a);23 const c = acos(a);
2424
25 testing.expect(math.approxEqAbs(f32, c.re, 0.546975, epsilon));25 try testing.expect(math.approxEqAbs(f32, c.re, 0.546975, epsilon));
26 testing.expect(math.approxEqAbs(f32, c.im, -2.452914, epsilon));26 try testing.expect(math.approxEqAbs(f32, c.im, -2.452914, epsilon));
27}27}
lib/std/math/complex/acosh.zig+2-2
...@@ -22,6 +22,6 @@ test "complex.cacosh" {...@@ -22,6 +22,6 @@ test "complex.cacosh" {
22 const a = Complex(f32).new(5, 3);22 const a = Complex(f32).new(5, 3);
23 const c = acosh(a);23 const c = acosh(a);
2424
25 testing.expect(math.approxEqAbs(f32, c.re, 2.452914, epsilon));25 try testing.expect(math.approxEqAbs(f32, c.re, 2.452914, epsilon));
26 testing.expect(math.approxEqAbs(f32, c.im, 0.546975, epsilon));26 try testing.expect(math.approxEqAbs(f32, c.im, 0.546975, epsilon));
27}27}
lib/std/math/complex/arg.zig+1-1
...@@ -20,5 +20,5 @@ const epsilon = 0.0001;...@@ -20,5 +20,5 @@ const epsilon = 0.0001;
20test "complex.carg" {20test "complex.carg" {
21 const a = Complex(f32).new(5, 3);21 const a = Complex(f32).new(5, 3);
22 const c = arg(a);22 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));
24}24}
lib/std/math/complex/asin.zig+2-2
...@@ -28,6 +28,6 @@ test "complex.casin" {...@@ -28,6 +28,6 @@ test "complex.casin" {
28 const a = Complex(f32).new(5, 3);28 const a = Complex(f32).new(5, 3);
29 const c = asin(a);29 const c = asin(a);
3030
31 testing.expect(math.approxEqAbs(f32, c.re, 1.023822, epsilon));31 try testing.expect(math.approxEqAbs(f32, c.re, 1.023822, epsilon));
32 testing.expect(math.approxEqAbs(f32, c.im, 2.452914, epsilon));32 try testing.expect(math.approxEqAbs(f32, c.im, 2.452914, epsilon));
33}33}
lib/std/math/complex/asinh.zig+2-2
...@@ -23,6 +23,6 @@ test "complex.casinh" {...@@ -23,6 +23,6 @@ test "complex.casinh" {
23 const a = Complex(f32).new(5, 3);23 const a = Complex(f32).new(5, 3);
24 const c = asinh(a);24 const c = asinh(a);
2525
26 testing.expect(math.approxEqAbs(f32, c.re, 2.459831, epsilon));26 try testing.expect(math.approxEqAbs(f32, c.re, 2.459831, epsilon));
27 testing.expect(math.approxEqAbs(f32, c.im, 0.533999, epsilon));27 try testing.expect(math.approxEqAbs(f32, c.im, 0.533999, epsilon));
28}28}
lib/std/math/complex/atan.zig+4-4
...@@ -129,14 +129,14 @@ test "complex.catan32" {...@@ -129,14 +129,14 @@ test "complex.catan32" {
129 const a = Complex(f32).new(5, 3);129 const a = Complex(f32).new(5, 3);
130 const c = atan(a);130 const c = atan(a);
131131
132 testing.expect(math.approxEqAbs(f32, c.re, 1.423679, epsilon));132 try testing.expect(math.approxEqAbs(f32, c.re, 1.423679, epsilon));
133 testing.expect(math.approxEqAbs(f32, c.im, 0.086569, epsilon));133 try testing.expect(math.approxEqAbs(f32, c.im, 0.086569, epsilon));
134}134}
135135
136test "complex.catan64" {136test "complex.catan64" {
137 const a = Complex(f64).new(5, 3);137 const a = Complex(f64).new(5, 3);
138 const c = atan(a);138 const c = atan(a);
139139
140 testing.expect(math.approxEqAbs(f64, c.re, 1.423679, epsilon));140 try testing.expect(math.approxEqAbs(f64, c.re, 1.423679, epsilon));
141 testing.expect(math.approxEqAbs(f64, c.im, 0.086569, epsilon));141 try testing.expect(math.approxEqAbs(f64, c.im, 0.086569, epsilon));
142}142}
lib/std/math/complex/atanh.zig+2-2
...@@ -23,6 +23,6 @@ test "complex.catanh" {...@@ -23,6 +23,6 @@ test "complex.catanh" {
23 const a = Complex(f32).new(5, 3);23 const a = Complex(f32).new(5, 3);
24 const c = atanh(a);24 const c = atanh(a);
2525
26 testing.expect(math.approxEqAbs(f32, c.re, 0.146947, epsilon));26 try testing.expect(math.approxEqAbs(f32, c.re, 0.146947, epsilon));
27 testing.expect(math.approxEqAbs(f32, c.im, 1.480870, epsilon));27 try testing.expect(math.approxEqAbs(f32, c.im, 1.480870, epsilon));
28}28}
lib/std/math/complex/conj.zig+1-1
...@@ -19,5 +19,5 @@ test "complex.conj" {...@@ -19,5 +19,5 @@ test "complex.conj" {
19 const a = Complex(f32).new(5, 3);19 const a = Complex(f32).new(5, 3);
20 const c = a.conjugate();20 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);
23}23}
lib/std/math/complex/cos.zig+2-2
...@@ -22,6 +22,6 @@ test "complex.ccos" {...@@ -22,6 +22,6 @@ test "complex.ccos" {
22 const a = Complex(f32).new(5, 3);22 const a = Complex(f32).new(5, 3);
23 const c = cos(a);23 const c = cos(a);
2424
25 testing.expect(math.approxEqAbs(f32, c.re, 2.855815, epsilon));25 try testing.expect(math.approxEqAbs(f32, c.re, 2.855815, epsilon));
26 testing.expect(math.approxEqAbs(f32, c.im, 9.606383, epsilon));26 try testing.expect(math.approxEqAbs(f32, c.im, 9.606383, epsilon));
27}27}
lib/std/math/complex/cosh.zig+4-4
...@@ -164,14 +164,14 @@ test "complex.ccosh32" {...@@ -164,14 +164,14 @@ test "complex.ccosh32" {
164 const a = Complex(f32).new(5, 3);164 const a = Complex(f32).new(5, 3);
165 const c = cosh(a);165 const c = cosh(a);
166166
167 testing.expect(math.approxEqAbs(f32, c.re, -73.467300, epsilon));167 try testing.expect(math.approxEqAbs(f32, c.re, -73.467300, epsilon));
168 testing.expect(math.approxEqAbs(f32, c.im, 10.471557, epsilon));168 try testing.expect(math.approxEqAbs(f32, c.im, 10.471557, epsilon));
169}169}
170170
171test "complex.ccosh64" {171test "complex.ccosh64" {
172 const a = Complex(f64).new(5, 3);172 const a = Complex(f64).new(5, 3);
173 const c = cosh(a);173 const c = cosh(a);
174174
175 testing.expect(math.approxEqAbs(f64, c.re, -73.467300, epsilon));175 try testing.expect(math.approxEqAbs(f64, c.re, -73.467300, epsilon));
176 testing.expect(math.approxEqAbs(f64, c.im, 10.471557, epsilon));176 try testing.expect(math.approxEqAbs(f64, c.im, 10.471557, epsilon));
177}177}
lib/std/math/complex/exp.zig+4-4
...@@ -130,14 +130,14 @@ test "complex.cexp32" {...@@ -130,14 +130,14 @@ test "complex.cexp32" {
130 const a = Complex(f32).new(5, 3);130 const a = Complex(f32).new(5, 3);
131 const c = exp(a);131 const c = exp(a);
132132
133 testing.expect(math.approxEqAbs(f32, c.re, -146.927917, epsilon));133 try testing.expect(math.approxEqAbs(f32, c.re, -146.927917, epsilon));
134 testing.expect(math.approxEqAbs(f32, c.im, 20.944065, epsilon));134 try testing.expect(math.approxEqAbs(f32, c.im, 20.944065, epsilon));
135}135}
136136
137test "complex.cexp64" {137test "complex.cexp64" {
138 const a = Complex(f64).new(5, 3);138 const a = Complex(f64).new(5, 3);
139 const c = exp(a);139 const c = exp(a);
140140
141 testing.expect(math.approxEqAbs(f64, c.re, -146.927917, epsilon));141 try testing.expect(math.approxEqAbs(f64, c.re, -146.927917, epsilon));
142 testing.expect(math.approxEqAbs(f64, c.im, 20.944065, epsilon));142 try testing.expect(math.approxEqAbs(f64, c.im, 20.944065, epsilon));
143}143}
lib/std/math/complex/log.zig+2-2
...@@ -24,6 +24,6 @@ test "complex.clog" {...@@ -24,6 +24,6 @@ test "complex.clog" {
24 const a = Complex(f32).new(5, 3);24 const a = Complex(f32).new(5, 3);
25 const c = log(a);25 const c = log(a);
2626
27 testing.expect(math.approxEqAbs(f32, c.re, 1.763180, epsilon));27 try testing.expect(math.approxEqAbs(f32, c.re, 1.763180, epsilon));
28 testing.expect(math.approxEqAbs(f32, c.im, 0.540419, epsilon));28 try testing.expect(math.approxEqAbs(f32, c.im, 0.540419, epsilon));
29}29}
lib/std/math/complex/pow.zig+2-2
...@@ -23,6 +23,6 @@ test "complex.cpow" {...@@ -23,6 +23,6 @@ test "complex.cpow" {
23 const b = Complex(f32).new(2.3, -1.3);23 const b = Complex(f32).new(2.3, -1.3);
24 const c = pow(Complex(f32), a, b);24 const c = pow(Complex(f32), a, b);
2525
26 testing.expect(math.approxEqAbs(f32, c.re, 58.049110, epsilon));26 try testing.expect(math.approxEqAbs(f32, c.re, 58.049110, epsilon));
27 testing.expect(math.approxEqAbs(f32, c.im, -101.003433, epsilon));27 try testing.expect(math.approxEqAbs(f32, c.im, -101.003433, epsilon));
28}28}
lib/std/math/complex/proj.zig+1-1
...@@ -26,5 +26,5 @@ test "complex.cproj" {...@@ -26,5 +26,5 @@ test "complex.cproj" {
26 const a = Complex(f32).new(5, 3);26 const a = Complex(f32).new(5, 3);
27 const c = proj(a);27 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);
30}30}
lib/std/math/complex/sin.zig+2-2
...@@ -23,6 +23,6 @@ test "complex.csin" {...@@ -23,6 +23,6 @@ test "complex.csin" {
23 const a = Complex(f32).new(5, 3);23 const a = Complex(f32).new(5, 3);
24 const c = sin(a);24 const c = sin(a);
2525
26 testing.expect(math.approxEqAbs(f32, c.re, -9.654126, epsilon));26 try testing.expect(math.approxEqAbs(f32, c.re, -9.654126, epsilon));
27 testing.expect(math.approxEqAbs(f32, c.im, 2.841692, epsilon));27 try testing.expect(math.approxEqAbs(f32, c.im, 2.841692, epsilon));
28}28}
lib/std/math/complex/sinh.zig+4-4
...@@ -163,14 +163,14 @@ test "complex.csinh32" {...@@ -163,14 +163,14 @@ test "complex.csinh32" {
163 const a = Complex(f32).new(5, 3);163 const a = Complex(f32).new(5, 3);
164 const c = sinh(a);164 const c = sinh(a);
165165
166 testing.expect(math.approxEqAbs(f32, c.re, -73.460617, epsilon));166 try testing.expect(math.approxEqAbs(f32, c.re, -73.460617, epsilon));
167 testing.expect(math.approxEqAbs(f32, c.im, 10.472508, epsilon));167 try testing.expect(math.approxEqAbs(f32, c.im, 10.472508, epsilon));
168}168}
169169
170test "complex.csinh64" {170test "complex.csinh64" {
171 const a = Complex(f64).new(5, 3);171 const a = Complex(f64).new(5, 3);
172 const c = sinh(a);172 const c = sinh(a);
173173
174 testing.expect(math.approxEqAbs(f64, c.re, -73.460617, epsilon));174 try testing.expect(math.approxEqAbs(f64, c.re, -73.460617, epsilon));
175 testing.expect(math.approxEqAbs(f64, c.im, 10.472508, epsilon));175 try testing.expect(math.approxEqAbs(f64, c.im, 10.472508, epsilon));
176}176}
lib/std/math/complex/sqrt.zig+4-4
...@@ -138,14 +138,14 @@ test "complex.csqrt32" {...@@ -138,14 +138,14 @@ test "complex.csqrt32" {
138 const a = Complex(f32).new(5, 3);138 const a = Complex(f32).new(5, 3);
139 const c = sqrt(a);139 const c = sqrt(a);
140140
141 testing.expect(math.approxEqAbs(f32, c.re, 2.327117, epsilon));141 try testing.expect(math.approxEqAbs(f32, c.re, 2.327117, epsilon));
142 testing.expect(math.approxEqAbs(f32, c.im, 0.644574, epsilon));142 try testing.expect(math.approxEqAbs(f32, c.im, 0.644574, epsilon));
143}143}
144144
145test "complex.csqrt64" {145test "complex.csqrt64" {
146 const a = Complex(f64).new(5, 3);146 const a = Complex(f64).new(5, 3);
147 const c = sqrt(a);147 const c = sqrt(a);
148148
149 testing.expect(math.approxEqAbs(f64, c.re, 2.3271175190399496, epsilon));149 try testing.expect(math.approxEqAbs(f64, c.re, 2.3271175190399496, epsilon));
150 testing.expect(math.approxEqAbs(f64, c.im, 0.6445742373246469, epsilon));150 try testing.expect(math.approxEqAbs(f64, c.im, 0.6445742373246469, epsilon));
151}151}
lib/std/math/complex/tan.zig+2-2
...@@ -23,6 +23,6 @@ test "complex.ctan" {...@@ -23,6 +23,6 @@ test "complex.ctan" {
23 const a = Complex(f32).new(5, 3);23 const a = Complex(f32).new(5, 3);
24 const c = tan(a);24 const c = tan(a);
2525
26 testing.expect(math.approxEqAbs(f32, c.re, -0.002708233, epsilon));26 try testing.expect(math.approxEqAbs(f32, c.re, -0.002708233, epsilon));
27 testing.expect(math.approxEqAbs(f32, c.im, 1.004165, epsilon));27 try testing.expect(math.approxEqAbs(f32, c.im, 1.004165, epsilon));
28}28}
lib/std/math/complex/tanh.zig+4-4
...@@ -112,14 +112,14 @@ test "complex.ctanh32" {...@@ -112,14 +112,14 @@ test "complex.ctanh32" {
112 const a = Complex(f32).new(5, 3);112 const a = Complex(f32).new(5, 3);
113 const c = tanh(a);113 const c = tanh(a);
114114
115 testing.expect(math.approxEqAbs(f32, c.re, 0.999913, epsilon));115 try testing.expect(math.approxEqAbs(f32, c.re, 0.999913, epsilon));
116 testing.expect(math.approxEqAbs(f32, c.im, -0.000025, epsilon));116 try testing.expect(math.approxEqAbs(f32, c.im, -0.000025, epsilon));
117}117}
118118
119test "complex.ctanh64" {119test "complex.ctanh64" {
120 const a = Complex(f64).new(5, 3);120 const a = Complex(f64).new(5, 3);
121 const c = tanh(a);121 const c = tanh(a);
122122
123 testing.expect(math.approxEqAbs(f64, c.re, 0.999913, epsilon));123 try testing.expect(math.approxEqAbs(f64, c.re, 0.999913, epsilon));
124 testing.expect(math.approxEqAbs(f64, c.im, -0.000025, epsilon));124 try testing.expect(math.approxEqAbs(f64, c.im, -0.000025, epsilon));
125}125}
lib/std/math/copysign.zig+20-20
...@@ -62,36 +62,36 @@ fn copysign128(x: f128, y: f128) f128 {...@@ -62,36 +62,36 @@ fn copysign128(x: f128, y: f128) f128 {
62}62}
6363
64test "math.copysign" {64test "math.copysign" {
65 expect(copysign(f16, 1.0, 1.0) == copysign16(1.0, 1.0));65 try 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));66 try 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));67 try 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));68 try expect(copysign(f128, 1.0, 1.0) == copysign128(1.0, 1.0));
69}69}
7070
71test "math.copysign16" {71test "math.copysign16" {
72 expect(copysign16(5.0, 1.0) == 5.0);72 try expect(copysign16(5.0, 1.0) == 5.0);
73 expect(copysign16(5.0, -1.0) == -5.0);73 try expect(copysign16(5.0, -1.0) == -5.0);
74 expect(copysign16(-5.0, -1.0) == -5.0);74 try expect(copysign16(-5.0, -1.0) == -5.0);
75 expect(copysign16(-5.0, 1.0) == 5.0);75 try expect(copysign16(-5.0, 1.0) == 5.0);
76}76}
7777
78test "math.copysign32" {78test "math.copysign32" {
79 expect(copysign32(5.0, 1.0) == 5.0);79 try expect(copysign32(5.0, 1.0) == 5.0);
80 expect(copysign32(5.0, -1.0) == -5.0);80 try expect(copysign32(5.0, -1.0) == -5.0);
81 expect(copysign32(-5.0, -1.0) == -5.0);81 try expect(copysign32(-5.0, -1.0) == -5.0);
82 expect(copysign32(-5.0, 1.0) == 5.0);82 try expect(copysign32(-5.0, 1.0) == 5.0);
83}83}
8484
85test "math.copysign64" {85test "math.copysign64" {
86 expect(copysign64(5.0, 1.0) == 5.0);86 try expect(copysign64(5.0, 1.0) == 5.0);
87 expect(copysign64(5.0, -1.0) == -5.0);87 try expect(copysign64(5.0, -1.0) == -5.0);
88 expect(copysign64(-5.0, -1.0) == -5.0);88 try expect(copysign64(-5.0, -1.0) == -5.0);
89 expect(copysign64(-5.0, 1.0) == 5.0);89 try expect(copysign64(-5.0, 1.0) == 5.0);
90}90}
9191
92test "math.copysign128" {92test "math.copysign128" {
93 expect(copysign128(5.0, 1.0) == 5.0);93 try expect(copysign128(5.0, 1.0) == 5.0);
94 expect(copysign128(5.0, -1.0) == -5.0);94 try expect(copysign128(5.0, -1.0) == -5.0);
95 expect(copysign128(-5.0, -1.0) == -5.0);95 try expect(copysign128(-5.0, -1.0) == -5.0);
96 expect(copysign128(-5.0, 1.0) == 5.0);96 try expect(copysign128(-5.0, 1.0) == 5.0);
97}97}
lib/std/math/cos.zig+22-22
...@@ -87,42 +87,42 @@ fn cos_(comptime T: type, x_: T) T {...@@ -87,42 +87,42 @@ fn cos_(comptime T: type, x_: T) T {
87}87}
8888
89test "math.cos" {89test "math.cos" {
90 expect(cos(@as(f32, 0.0)) == cos_(f32, 0.0));90 try expect(cos(@as(f32, 0.0)) == cos_(f32, 0.0));
91 expect(cos(@as(f64, 0.0)) == cos_(f64, 0.0));91 try expect(cos(@as(f64, 0.0)) == cos_(f64, 0.0));
92}92}
9393
94test "math.cos32" {94test "math.cos32" {
95 const epsilon = 0.000001;95 const epsilon = 0.000001;
9696
97 expect(math.approxEqAbs(f32, cos_(f32, 0.0), 1.0, epsilon));97 try expect(math.approxEqAbs(f32, cos_(f32, 0.0), 1.0, epsilon));
98 expect(math.approxEqAbs(f32, cos_(f32, 0.2), 0.980067, epsilon));98 try expect(math.approxEqAbs(f32, cos_(f32, 0.2), 0.980067, epsilon));
99 expect(math.approxEqAbs(f32, cos_(f32, 0.8923), 0.627623, epsilon));99 try expect(math.approxEqAbs(f32, cos_(f32, 0.8923), 0.627623, epsilon));
100 expect(math.approxEqAbs(f32, cos_(f32, 1.5), 0.070737, epsilon));100 try expect(math.approxEqAbs(f32, cos_(f32, 1.5), 0.070737, epsilon));
101 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 expect(math.approxEqAbs(f32, cos_(f32, 37.45), 0.969132, epsilon));102 try expect(math.approxEqAbs(f32, cos_(f32, 37.45), 0.969132, epsilon));
103 expect(math.approxEqAbs(f32, cos_(f32, 89.123), 0.400798, epsilon));103 try expect(math.approxEqAbs(f32, cos_(f32, 89.123), 0.400798, epsilon));
104}104}
105105
106test "math.cos64" {106test "math.cos64" {
107 const epsilon = 0.000001;107 const epsilon = 0.000001;
108108
109 expect(math.approxEqAbs(f64, cos_(f64, 0.0), 1.0, epsilon));109 try expect(math.approxEqAbs(f64, cos_(f64, 0.0), 1.0, epsilon));
110 expect(math.approxEqAbs(f64, cos_(f64, 0.2), 0.980067, epsilon));110 try expect(math.approxEqAbs(f64, cos_(f64, 0.2), 0.980067, epsilon));
111 expect(math.approxEqAbs(f64, cos_(f64, 0.8923), 0.627623, epsilon));111 try expect(math.approxEqAbs(f64, cos_(f64, 0.8923), 0.627623, epsilon));
112 expect(math.approxEqAbs(f64, cos_(f64, 1.5), 0.070737, epsilon));112 try expect(math.approxEqAbs(f64, cos_(f64, 1.5), 0.070737, epsilon));
113 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 expect(math.approxEqAbs(f64, cos_(f64, 37.45), 0.969132, epsilon));114 try expect(math.approxEqAbs(f64, cos_(f64, 37.45), 0.969132, epsilon));
115 expect(math.approxEqAbs(f64, cos_(f64, 89.123), 0.40080, epsilon));115 try expect(math.approxEqAbs(f64, cos_(f64, 89.123), 0.40080, epsilon));
116}116}
117117
118test "math.cos32.special" {118test "math.cos32.special" {
119 expect(math.isNan(cos_(f32, math.inf(f32))));119 try expect(math.isNan(cos_(f32, math.inf(f32))));
120 expect(math.isNan(cos_(f32, -math.inf(f32))));120 try expect(math.isNan(cos_(f32, -math.inf(f32))));
121 expect(math.isNan(cos_(f32, math.nan(f32))));121 try expect(math.isNan(cos_(f32, math.nan(f32))));
122}122}
123123
124test "math.cos64.special" {124test "math.cos64.special" {
125 expect(math.isNan(cos_(f64, math.inf(f64))));125 try expect(math.isNan(cos_(f64, math.inf(f64))));
126 expect(math.isNan(cos_(f64, -math.inf(f64))));126 try expect(math.isNan(cos_(f64, -math.inf(f64))));
127 expect(math.isNan(cos_(f64, math.nan(f64))));127 try expect(math.isNan(cos_(f64, math.nan(f64))));
128}128}
lib/std/math/cosh.zig+28-28
...@@ -92,48 +92,48 @@ fn cosh64(x: f64) f64 {...@@ -92,48 +92,48 @@ fn cosh64(x: f64) f64 {
92}92}
9393
94test "math.cosh" {94test "math.cosh" {
95 expect(cosh(@as(f32, 1.5)) == cosh32(1.5));95 try expect(cosh(@as(f32, 1.5)) == cosh32(1.5));
96 expect(cosh(@as(f64, 1.5)) == cosh64(1.5));96 try expect(cosh(@as(f64, 1.5)) == cosh64(1.5));
97}97}
9898
99test "math.cosh32" {99test "math.cosh32" {
100 const epsilon = 0.000001;100 const epsilon = 0.000001;
101101
102 expect(math.approxEqAbs(f32, cosh32(0.0), 1.0, epsilon));102 try expect(math.approxEqAbs(f32, cosh32(0.0), 1.0, epsilon));
103 expect(math.approxEqAbs(f32, cosh32(0.2), 1.020067, epsilon));103 try expect(math.approxEqAbs(f32, cosh32(0.2), 1.020067, epsilon));
104 expect(math.approxEqAbs(f32, cosh32(0.8923), 1.425225, epsilon));104 try expect(math.approxEqAbs(f32, cosh32(0.8923), 1.425225, epsilon));
105 expect(math.approxEqAbs(f32, cosh32(1.5), 2.352410, epsilon));105 try expect(math.approxEqAbs(f32, cosh32(1.5), 2.352410, epsilon));
106 expect(math.approxEqAbs(f32, cosh32(-0.0), 1.0, epsilon));106 try expect(math.approxEqAbs(f32, cosh32(-0.0), 1.0, epsilon));
107 expect(math.approxEqAbs(f32, cosh32(-0.2), 1.020067, epsilon));107 try expect(math.approxEqAbs(f32, cosh32(-0.2), 1.020067, epsilon));
108 expect(math.approxEqAbs(f32, cosh32(-0.8923), 1.425225, epsilon));108 try expect(math.approxEqAbs(f32, cosh32(-0.8923), 1.425225, epsilon));
109 expect(math.approxEqAbs(f32, cosh32(-1.5), 2.352410, epsilon));109 try expect(math.approxEqAbs(f32, cosh32(-1.5), 2.352410, epsilon));
110}110}
111111
112test "math.cosh64" {112test "math.cosh64" {
113 const epsilon = 0.000001;113 const epsilon = 0.000001;
114114
115 expect(math.approxEqAbs(f64, cosh64(0.0), 1.0, epsilon));115 try expect(math.approxEqAbs(f64, cosh64(0.0), 1.0, epsilon));
116 expect(math.approxEqAbs(f64, cosh64(0.2), 1.020067, epsilon));116 try expect(math.approxEqAbs(f64, cosh64(0.2), 1.020067, epsilon));
117 expect(math.approxEqAbs(f64, cosh64(0.8923), 1.425225, epsilon));117 try expect(math.approxEqAbs(f64, cosh64(0.8923), 1.425225, epsilon));
118 expect(math.approxEqAbs(f64, cosh64(1.5), 2.352410, epsilon));118 try expect(math.approxEqAbs(f64, cosh64(1.5), 2.352410, epsilon));
119 expect(math.approxEqAbs(f64, cosh64(-0.0), 1.0, epsilon));119 try expect(math.approxEqAbs(f64, cosh64(-0.0), 1.0, epsilon));
120 expect(math.approxEqAbs(f64, cosh64(-0.2), 1.020067, epsilon));120 try expect(math.approxEqAbs(f64, cosh64(-0.2), 1.020067, epsilon));
121 expect(math.approxEqAbs(f64, cosh64(-0.8923), 1.425225, epsilon));121 try expect(math.approxEqAbs(f64, cosh64(-0.8923), 1.425225, epsilon));
122 expect(math.approxEqAbs(f64, cosh64(-1.5), 2.352410, epsilon));122 try expect(math.approxEqAbs(f64, cosh64(-1.5), 2.352410, epsilon));
123}123}
124124
125test "math.cosh32.special" {125test "math.cosh32.special" {
126 expect(cosh32(0.0) == 1.0);126 try expect(cosh32(0.0) == 1.0);
127 expect(cosh32(-0.0) == 1.0);127 try expect(cosh32(-0.0) == 1.0);
128 expect(math.isPositiveInf(cosh32(math.inf(f32))));128 try expect(math.isPositiveInf(cosh32(math.inf(f32))));
129 expect(math.isPositiveInf(cosh32(-math.inf(f32))));129 try expect(math.isPositiveInf(cosh32(-math.inf(f32))));
130 expect(math.isNan(cosh32(math.nan(f32))));130 try expect(math.isNan(cosh32(math.nan(f32))));
131}131}
132132
133test "math.cosh64.special" {133test "math.cosh64.special" {
134 expect(cosh64(0.0) == 1.0);134 try expect(cosh64(0.0) == 1.0);
135 expect(cosh64(-0.0) == 1.0);135 try expect(cosh64(-0.0) == 1.0);
136 expect(math.isPositiveInf(cosh64(math.inf(f64))));136 try expect(math.isPositiveInf(cosh64(math.inf(f64))));
137 expect(math.isPositiveInf(cosh64(-math.inf(f64))));137 try expect(math.isPositiveInf(cosh64(-math.inf(f64))));
138 expect(math.isNan(cosh64(math.nan(f64))));138 try expect(math.isNan(cosh64(math.nan(f64))));
139}139}
lib/std/math/exp.zig+16-16
...@@ -187,36 +187,36 @@ fn exp64(x_: f64) f64 {...@@ -187,36 +187,36 @@ fn exp64(x_: f64) f64 {
187}187}
188188
189test "math.exp" {189test "math.exp" {
190 expect(exp(@as(f32, 0.0)) == exp32(0.0));190 try expect(exp(@as(f32, 0.0)) == exp32(0.0));
191 expect(exp(@as(f64, 0.0)) == exp64(0.0));191 try expect(exp(@as(f64, 0.0)) == exp64(0.0));
192}192}
193193
194test "math.exp32" {194test "math.exp32" {
195 const epsilon = 0.000001;195 const epsilon = 0.000001;
196196
197 expect(exp32(0.0) == 1.0);197 try expect(exp32(0.0) == 1.0);
198 expect(math.approxEqAbs(f32, exp32(0.0), 1.0, epsilon));198 try expect(math.approxEqAbs(f32, exp32(0.0), 1.0, epsilon));
199 expect(math.approxEqAbs(f32, exp32(0.2), 1.221403, epsilon));199 try expect(math.approxEqAbs(f32, exp32(0.2), 1.221403, epsilon));
200 expect(math.approxEqAbs(f32, exp32(0.8923), 2.440737, epsilon));200 try expect(math.approxEqAbs(f32, exp32(0.8923), 2.440737, epsilon));
201 expect(math.approxEqAbs(f32, exp32(1.5), 4.481689, epsilon));201 try expect(math.approxEqAbs(f32, exp32(1.5), 4.481689, epsilon));
202}202}
203203
204test "math.exp64" {204test "math.exp64" {
205 const epsilon = 0.000001;205 const epsilon = 0.000001;
206206
207 expect(exp64(0.0) == 1.0);207 try expect(exp64(0.0) == 1.0);
208 expect(math.approxEqAbs(f64, exp64(0.0), 1.0, epsilon));208 try expect(math.approxEqAbs(f64, exp64(0.0), 1.0, epsilon));
209 expect(math.approxEqAbs(f64, exp64(0.2), 1.221403, epsilon));209 try expect(math.approxEqAbs(f64, exp64(0.2), 1.221403, epsilon));
210 expect(math.approxEqAbs(f64, exp64(0.8923), 2.440737, epsilon));210 try expect(math.approxEqAbs(f64, exp64(0.8923), 2.440737, epsilon));
211 expect(math.approxEqAbs(f64, exp64(1.5), 4.481689, epsilon));211 try expect(math.approxEqAbs(f64, exp64(1.5), 4.481689, epsilon));
212}212}
213213
214test "math.exp32.special" {214test "math.exp32.special" {
215 expect(math.isPositiveInf(exp32(math.inf(f32))));215 try expect(math.isPositiveInf(exp32(math.inf(f32))));
216 expect(math.isNan(exp32(math.nan(f32))));216 try expect(math.isNan(exp32(math.nan(f32))));
217}217}
218218
219test "math.exp64.special" {219test "math.exp64.special" {
220 expect(math.isPositiveInf(exp64(math.inf(f64))));220 try expect(math.isPositiveInf(exp64(math.inf(f64))));
221 expect(math.isNan(exp64(math.nan(f64))));221 try expect(math.isNan(exp64(math.nan(f64))));
222}222}
lib/std/math/exp2.zig+15-15
...@@ -426,35 +426,35 @@ fn exp2_64(x: f64) f64 {...@@ -426,35 +426,35 @@ fn exp2_64(x: f64) f64 {
426}426}
427427
428test "math.exp2" {428test "math.exp2" {
429 expect(exp2(@as(f32, 0.8923)) == exp2_32(0.8923));429 try expect(exp2(@as(f32, 0.8923)) == exp2_32(0.8923));
430 expect(exp2(@as(f64, 0.8923)) == exp2_64(0.8923));430 try expect(exp2(@as(f64, 0.8923)) == exp2_64(0.8923));
431}431}
432432
433test "math.exp2_32" {433test "math.exp2_32" {
434 const epsilon = 0.000001;434 const epsilon = 0.000001;
435435
436 expect(exp2_32(0.0) == 1.0);436 try expect(exp2_32(0.0) == 1.0);
437 expect(math.approxEqAbs(f32, exp2_32(0.2), 1.148698, epsilon));437 try expect(math.approxEqAbs(f32, exp2_32(0.2), 1.148698, epsilon));
438 expect(math.approxEqAbs(f32, exp2_32(0.8923), 1.856133, epsilon));438 try expect(math.approxEqAbs(f32, exp2_32(0.8923), 1.856133, epsilon));
439 expect(math.approxEqAbs(f32, exp2_32(1.5), 2.828427, epsilon));439 try expect(math.approxEqAbs(f32, exp2_32(1.5), 2.828427, epsilon));
440 expect(math.approxEqAbs(f32, exp2_32(37.45), 187747237888, epsilon));440 try expect(math.approxEqAbs(f32, exp2_32(37.45), 187747237888, epsilon));
441}441}
442442
443test "math.exp2_64" {443test "math.exp2_64" {
444 const epsilon = 0.000001;444 const epsilon = 0.000001;
445445
446 expect(exp2_64(0.0) == 1.0);446 try expect(exp2_64(0.0) == 1.0);
447 expect(math.approxEqAbs(f64, exp2_64(0.2), 1.148698, epsilon));447 try expect(math.approxEqAbs(f64, exp2_64(0.2), 1.148698, epsilon));
448 expect(math.approxEqAbs(f64, exp2_64(0.8923), 1.856133, epsilon));448 try expect(math.approxEqAbs(f64, exp2_64(0.8923), 1.856133, epsilon));
449 expect(math.approxEqAbs(f64, exp2_64(1.5), 2.828427, epsilon));449 try expect(math.approxEqAbs(f64, exp2_64(1.5), 2.828427, epsilon));
450}450}
451451
452test "math.exp2_32.special" {452test "math.exp2_32.special" {
453 expect(math.isPositiveInf(exp2_32(math.inf(f32))));453 try expect(math.isPositiveInf(exp2_32(math.inf(f32))));
454 expect(math.isNan(exp2_32(math.nan(f32))));454 try expect(math.isNan(exp2_32(math.nan(f32))));
455}455}
456456
457test "math.exp2_64.special" {457test "math.exp2_64.special" {
458 expect(math.isPositiveInf(exp2_64(math.inf(f64))));458 try expect(math.isPositiveInf(exp2_64(math.inf(f64))));
459 expect(math.isNan(exp2_64(math.nan(f64))));459 try expect(math.isNan(exp2_64(math.nan(f64))));
460}460}
lib/std/math/expm1.zig+18-18
...@@ -291,42 +291,42 @@ fn expm1_64(x_: f64) f64 {...@@ -291,42 +291,42 @@ fn expm1_64(x_: f64) f64 {
291}291}
292292
293test "math.exp1m" {293test "math.exp1m" {
294 expect(expm1(@as(f32, 0.0)) == expm1_32(0.0));294 try expect(expm1(@as(f32, 0.0)) == expm1_32(0.0));
295 expect(expm1(@as(f64, 0.0)) == expm1_64(0.0));295 try expect(expm1(@as(f64, 0.0)) == expm1_64(0.0));
296}296}
297297
298test "math.expm1_32" {298test "math.expm1_32" {
299 const epsilon = 0.000001;299 const epsilon = 0.000001;
300300
301 expect(expm1_32(0.0) == 0.0);301 try expect(expm1_32(0.0) == 0.0);
302 expect(math.approxEqAbs(f32, expm1_32(0.0), 0.0, epsilon));302 try expect(math.approxEqAbs(f32, expm1_32(0.0), 0.0, epsilon));
303 expect(math.approxEqAbs(f32, expm1_32(0.2), 0.221403, epsilon));303 try expect(math.approxEqAbs(f32, expm1_32(0.2), 0.221403, epsilon));
304 expect(math.approxEqAbs(f32, expm1_32(0.8923), 1.440737, epsilon));304 try expect(math.approxEqAbs(f32, expm1_32(0.8923), 1.440737, epsilon));
305 expect(math.approxEqAbs(f32, expm1_32(1.5), 3.481689, epsilon));305 try expect(math.approxEqAbs(f32, expm1_32(1.5), 3.481689, epsilon));
306}306}
307307
308test "math.expm1_64" {308test "math.expm1_64" {
309 const epsilon = 0.000001;309 const epsilon = 0.000001;
310310
311 expect(expm1_64(0.0) == 0.0);311 try expect(expm1_64(0.0) == 0.0);
312 expect(math.approxEqAbs(f64, expm1_64(0.0), 0.0, epsilon));312 try expect(math.approxEqAbs(f64, expm1_64(0.0), 0.0, epsilon));
313 expect(math.approxEqAbs(f64, expm1_64(0.2), 0.221403, epsilon));313 try expect(math.approxEqAbs(f64, expm1_64(0.2), 0.221403, epsilon));
314 expect(math.approxEqAbs(f64, expm1_64(0.8923), 1.440737, epsilon));314 try expect(math.approxEqAbs(f64, expm1_64(0.8923), 1.440737, epsilon));
315 expect(math.approxEqAbs(f64, expm1_64(1.5), 3.481689, epsilon));315 try expect(math.approxEqAbs(f64, expm1_64(1.5), 3.481689, epsilon));
316}316}
317317
318test "math.expm1_32.special" {318test "math.expm1_32.special" {
319 const epsilon = 0.000001;319 const epsilon = 0.000001;
320320
321 expect(math.isPositiveInf(expm1_32(math.inf(f32))));321 try expect(math.isPositiveInf(expm1_32(math.inf(f32))));
322 expect(expm1_32(-math.inf(f32)) == -1.0);322 try expect(expm1_32(-math.inf(f32)) == -1.0);
323 expect(math.isNan(expm1_32(math.nan(f32))));323 try expect(math.isNan(expm1_32(math.nan(f32))));
324}324}
325325
326test "math.expm1_64.special" {326test "math.expm1_64.special" {
327 const epsilon = 0.000001;327 const epsilon = 0.000001;
328328
329 expect(math.isPositiveInf(expm1_64(math.inf(f64))));329 try expect(math.isPositiveInf(expm1_64(math.inf(f64))));
330 expect(expm1_64(-math.inf(f64)) == -1.0);330 try expect(expm1_64(-math.inf(f64)) == -1.0);
331 expect(math.isNan(expm1_64(math.nan(f64))));331 try expect(math.isNan(expm1_64(math.nan(f64))));
332}332}
lib/std/math/fabs.zig+24-24
...@@ -55,52 +55,52 @@ fn fabs128(x: f128) f128 {...@@ -55,52 +55,52 @@ fn fabs128(x: f128) f128 {
55}55}
5656
57test "math.fabs" {57test "math.fabs" {
58 expect(fabs(@as(f16, 1.0)) == fabs16(1.0));58 try expect(fabs(@as(f16, 1.0)) == fabs16(1.0));
59 expect(fabs(@as(f32, 1.0)) == fabs32(1.0));59 try expect(fabs(@as(f32, 1.0)) == fabs32(1.0));
60 expect(fabs(@as(f64, 1.0)) == fabs64(1.0));60 try expect(fabs(@as(f64, 1.0)) == fabs64(1.0));
61 expect(fabs(@as(f128, 1.0)) == fabs128(1.0));61 try expect(fabs(@as(f128, 1.0)) == fabs128(1.0));
62}62}
6363
64test "math.fabs16" {64test "math.fabs16" {
65 expect(fabs16(1.0) == 1.0);65 try expect(fabs16(1.0) == 1.0);
66 expect(fabs16(-1.0) == 1.0);66 try expect(fabs16(-1.0) == 1.0);
67}67}
6868
69test "math.fabs32" {69test "math.fabs32" {
70 expect(fabs32(1.0) == 1.0);70 try expect(fabs32(1.0) == 1.0);
71 expect(fabs32(-1.0) == 1.0);71 try expect(fabs32(-1.0) == 1.0);
72}72}
7373
74test "math.fabs64" {74test "math.fabs64" {
75 expect(fabs64(1.0) == 1.0);75 try expect(fabs64(1.0) == 1.0);
76 expect(fabs64(-1.0) == 1.0);76 try expect(fabs64(-1.0) == 1.0);
77}77}
7878
79test "math.fabs128" {79test "math.fabs128" {
80 expect(fabs128(1.0) == 1.0);80 try expect(fabs128(1.0) == 1.0);
81 expect(fabs128(-1.0) == 1.0);81 try expect(fabs128(-1.0) == 1.0);
82}82}
8383
84test "math.fabs16.special" {84test "math.fabs16.special" {
85 expect(math.isPositiveInf(fabs(math.inf(f16))));85 try expect(math.isPositiveInf(fabs(math.inf(f16))));
86 expect(math.isPositiveInf(fabs(-math.inf(f16))));86 try expect(math.isPositiveInf(fabs(-math.inf(f16))));
87 expect(math.isNan(fabs(math.nan(f16))));87 try expect(math.isNan(fabs(math.nan(f16))));
88}88}
8989
90test "math.fabs32.special" {90test "math.fabs32.special" {
91 expect(math.isPositiveInf(fabs(math.inf(f32))));91 try expect(math.isPositiveInf(fabs(math.inf(f32))));
92 expect(math.isPositiveInf(fabs(-math.inf(f32))));92 try expect(math.isPositiveInf(fabs(-math.inf(f32))));
93 expect(math.isNan(fabs(math.nan(f32))));93 try expect(math.isNan(fabs(math.nan(f32))));
94}94}
9595
96test "math.fabs64.special" {96test "math.fabs64.special" {
97 expect(math.isPositiveInf(fabs(math.inf(f64))));97 try expect(math.isPositiveInf(fabs(math.inf(f64))));
98 expect(math.isPositiveInf(fabs(-math.inf(f64))));98 try expect(math.isPositiveInf(fabs(-math.inf(f64))));
99 expect(math.isNan(fabs(math.nan(f64))));99 try expect(math.isNan(fabs(math.nan(f64))));
100}100}
101101
102test "math.fabs128.special" {102test "math.fabs128.special" {
103 expect(math.isPositiveInf(fabs(math.inf(f128))));103 try expect(math.isPositiveInf(fabs(math.inf(f128))));
104 expect(math.isPositiveInf(fabs(-math.inf(f128))));104 try expect(math.isPositiveInf(fabs(-math.inf(f128))));
105 expect(math.isNan(fabs(math.nan(f128))));105 try expect(math.isNan(fabs(math.nan(f128))));
106}106}
lib/std/math/floor.zig+36-36
...@@ -155,64 +155,64 @@ fn floor128(x: f128) f128 {...@@ -155,64 +155,64 @@ fn floor128(x: f128) f128 {
155}155}
156156
157test "math.floor" {157test "math.floor" {
158 expect(floor(@as(f16, 1.3)) == floor16(1.3));158 try expect(floor(@as(f16, 1.3)) == floor16(1.3));
159 expect(floor(@as(f32, 1.3)) == floor32(1.3));159 try expect(floor(@as(f32, 1.3)) == floor32(1.3));
160 expect(floor(@as(f64, 1.3)) == floor64(1.3));160 try expect(floor(@as(f64, 1.3)) == floor64(1.3));
161 expect(floor(@as(f128, 1.3)) == floor128(1.3));161 try expect(floor(@as(f128, 1.3)) == floor128(1.3));
162}162}
163163
164test "math.floor16" {164test "math.floor16" {
165 expect(floor16(1.3) == 1.0);165 try expect(floor16(1.3) == 1.0);
166 expect(floor16(-1.3) == -2.0);166 try expect(floor16(-1.3) == -2.0);
167 expect(floor16(0.2) == 0.0);167 try expect(floor16(0.2) == 0.0);
168}168}
169169
170test "math.floor32" {170test "math.floor32" {
171 expect(floor32(1.3) == 1.0);171 try expect(floor32(1.3) == 1.0);
172 expect(floor32(-1.3) == -2.0);172 try expect(floor32(-1.3) == -2.0);
173 expect(floor32(0.2) == 0.0);173 try expect(floor32(0.2) == 0.0);
174}174}
175175
176test "math.floor64" {176test "math.floor64" {
177 expect(floor64(1.3) == 1.0);177 try expect(floor64(1.3) == 1.0);
178 expect(floor64(-1.3) == -2.0);178 try expect(floor64(-1.3) == -2.0);
179 expect(floor64(0.2) == 0.0);179 try expect(floor64(0.2) == 0.0);
180}180}
181181
182test "math.floor128" {182test "math.floor128" {
183 expect(floor128(1.3) == 1.0);183 try expect(floor128(1.3) == 1.0);
184 expect(floor128(-1.3) == -2.0);184 try expect(floor128(-1.3) == -2.0);
185 expect(floor128(0.2) == 0.0);185 try expect(floor128(0.2) == 0.0);
186}186}
187187
188test "math.floor16.special" {188test "math.floor16.special" {
189 expect(floor16(0.0) == 0.0);189 try expect(floor16(0.0) == 0.0);
190 expect(floor16(-0.0) == -0.0);190 try expect(floor16(-0.0) == -0.0);
191 expect(math.isPositiveInf(floor16(math.inf(f16))));191 try expect(math.isPositiveInf(floor16(math.inf(f16))));
192 expect(math.isNegativeInf(floor16(-math.inf(f16))));192 try expect(math.isNegativeInf(floor16(-math.inf(f16))));
193 expect(math.isNan(floor16(math.nan(f16))));193 try expect(math.isNan(floor16(math.nan(f16))));
194}194}
195195
196test "math.floor32.special" {196test "math.floor32.special" {
197 expect(floor32(0.0) == 0.0);197 try expect(floor32(0.0) == 0.0);
198 expect(floor32(-0.0) == -0.0);198 try expect(floor32(-0.0) == -0.0);
199 expect(math.isPositiveInf(floor32(math.inf(f32))));199 try expect(math.isPositiveInf(floor32(math.inf(f32))));
200 expect(math.isNegativeInf(floor32(-math.inf(f32))));200 try expect(math.isNegativeInf(floor32(-math.inf(f32))));
201 expect(math.isNan(floor32(math.nan(f32))));201 try expect(math.isNan(floor32(math.nan(f32))));
202}202}
203203
204test "math.floor64.special" {204test "math.floor64.special" {
205 expect(floor64(0.0) == 0.0);205 try expect(floor64(0.0) == 0.0);
206 expect(floor64(-0.0) == -0.0);206 try expect(floor64(-0.0) == -0.0);
207 expect(math.isPositiveInf(floor64(math.inf(f64))));207 try expect(math.isPositiveInf(floor64(math.inf(f64))));
208 expect(math.isNegativeInf(floor64(-math.inf(f64))));208 try expect(math.isNegativeInf(floor64(-math.inf(f64))));
209 expect(math.isNan(floor64(math.nan(f64))));209 try expect(math.isNan(floor64(math.nan(f64))));
210}210}
211211
212test "math.floor128.special" {212test "math.floor128.special" {
213 expect(floor128(0.0) == 0.0);213 try expect(floor128(0.0) == 0.0);
214 expect(floor128(-0.0) == -0.0);214 try expect(floor128(-0.0) == -0.0);
215 expect(math.isPositiveInf(floor128(math.inf(f128))));215 try expect(math.isPositiveInf(floor128(math.inf(f128))));
216 expect(math.isNegativeInf(floor128(-math.inf(f128))));216 try expect(math.isNegativeInf(floor128(-math.inf(f128))));
217 expect(math.isNan(floor128(math.nan(f128))));217 try expect(math.isNan(floor128(math.nan(f128))));
218}218}
lib/std/math/fma.zig+16-16
...@@ -148,30 +148,30 @@ fn add_and_denorm(a: f64, b: f64, scale: i32) f64 {...@@ -148,30 +148,30 @@ fn add_and_denorm(a: f64, b: f64, scale: i32) f64 {
148}148}
149149
150test "math.fma" {150test "math.fma" {
151 expect(fma(f32, 0.0, 1.0, 1.0) == fma32(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 expect(fma(f64, 0.0, 1.0, 1.0) == fma64(0.0, 1.0, 1.0));152 try expect(fma(f64, 0.0, 1.0, 1.0) == fma64(0.0, 1.0, 1.0));
153}153}
154154
155test "math.fma32" {155test "math.fma32" {
156 const epsilon = 0.000001;156 const epsilon = 0.000001;
157157
158 expect(math.approxEqAbs(f32, fma32(0.0, 5.0, 9.124), 9.124, epsilon));158 try 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));159 try 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));160 try 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));161 try 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));162 try 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));163 try 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));164 try expect(math.approxEqAbs(f32, fma32(123123.234375, 5.0, 9.124), 615625.295875, epsilon));
165}165}
166166
167test "math.fma64" {167test "math.fma64" {
168 const epsilon = 0.000001;168 const epsilon = 0.000001;
169169
170 expect(math.approxEqAbs(f64, fma64(0.0, 5.0, 9.124), 9.124, epsilon));170 try 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));171 try 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));172 try 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));173 try 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));174 try 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));175 try 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));176 try expect(math.approxEqAbs(f64, fma64(123123.234375, 5.0, 9.124), 615625.295875, epsilon));
177}177}
lib/std/math/frexp.zig+16-16
...@@ -115,11 +115,11 @@ fn frexp64(x: f64) frexp64_result {...@@ -115,11 +115,11 @@ fn frexp64(x: f64) frexp64_result {
115test "math.frexp" {115test "math.frexp" {
116 const a = frexp(@as(f32, 1.3));116 const a = frexp(@as(f32, 1.3));
117 const b = frexp32(1.3);117 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
120 const c = frexp(@as(f64, 1.3));120 const c = frexp(@as(f64, 1.3));
121 const d = frexp64(1.3);121 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);
123}123}
124124
125test "math.frexp32" {125test "math.frexp32" {
...@@ -127,10 +127,10 @@ test "math.frexp32" {...@@ -127,10 +127,10 @@ test "math.frexp32" {
127 var r: frexp32_result = undefined;127 var r: frexp32_result = undefined;
128128
129 r = frexp32(1.3);129 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
132 r = frexp32(78.0234);132 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);
134}134}
135135
136test "math.frexp64" {136test "math.frexp64" {
...@@ -138,46 +138,46 @@ test "math.frexp64" {...@@ -138,46 +138,46 @@ test "math.frexp64" {
138 var r: frexp64_result = undefined;138 var r: frexp64_result = undefined;
139139
140 r = frexp64(1.3);140 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
143 r = frexp64(78.0234);143 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);
145}145}
146146
147test "math.frexp32.special" {147test "math.frexp32.special" {
148 var r: frexp32_result = undefined;148 var r: frexp32_result = undefined;
149149
150 r = frexp32(0.0);150 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
153 r = frexp32(-0.0);153 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
156 r = frexp32(math.inf(f32));156 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
159 r = frexp32(-math.inf(f32));159 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
162 r = frexp32(math.nan(f32));162 r = frexp32(math.nan(f32));
163 expect(math.isNan(r.significand));163 try expect(math.isNan(r.significand));
164}164}
165165
166test "math.frexp64.special" {166test "math.frexp64.special" {
167 var r: frexp64_result = undefined;167 var r: frexp64_result = undefined;
168168
169 r = frexp64(0.0);169 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
172 r = frexp64(-0.0);172 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
175 r = frexp64(math.inf(f64));175 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
178 r = frexp64(-math.inf(f64));178 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
181 r = frexp64(math.nan(f64));181 r = frexp64(math.nan(f64));
182 expect(math.isNan(r.significand));182 try expect(math.isNan(r.significand));
183}183}
lib/std/math/hypot.zig+28-28
...@@ -126,48 +126,48 @@ fn hypot64(x: f64, y: f64) f64 {...@@ -126,48 +126,48 @@ fn hypot64(x: f64, y: f64) f64 {
126}126}
127127
128test "math.hypot" {128test "math.hypot" {
129 expect(hypot(f32, 0.0, -1.2) == hypot32(0.0, -1.2));129 try 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));130 try expect(hypot(f64, 0.0, -1.2) == hypot64(0.0, -1.2));
131}131}
132132
133test "math.hypot32" {133test "math.hypot32" {
134 const epsilon = 0.000001;134 const epsilon = 0.000001;
135135
136 expect(math.approxEqAbs(f32, hypot32(0.0, -1.2), 1.2, epsilon));136 try 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));137 try 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));138 try 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));139 try 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));140 try 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));141 try 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));142 try expect(math.approxEqAbs(f32, hypot32(123123.234375, 529428.707813), 543556.875, epsilon));
143}143}
144144
145test "math.hypot64" {145test "math.hypot64" {
146 const epsilon = 0.000001;146 const epsilon = 0.000001;
147147
148 expect(math.approxEqAbs(f64, hypot64(0.0, -1.2), 1.2, epsilon));148 try 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));149 try 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));150 try 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));151 try 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));152 try 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));153 try 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));154 try expect(math.approxEqAbs(f64, hypot64(123123.234375, 529428.707813), 543556.885247, epsilon));
155}155}
156156
157test "math.hypot32.special" {157test "math.hypot32.special" {
158 expect(math.isPositiveInf(hypot32(math.inf(f32), 0.0)));158 try expect(math.isPositiveInf(hypot32(math.inf(f32), 0.0)));
159 expect(math.isPositiveInf(hypot32(-math.inf(f32), 0.0)));159 try expect(math.isPositiveInf(hypot32(-math.inf(f32), 0.0)));
160 expect(math.isPositiveInf(hypot32(0.0, math.inf(f32))));160 try expect(math.isPositiveInf(hypot32(0.0, math.inf(f32))));
161 expect(math.isPositiveInf(hypot32(0.0, -math.inf(f32))));161 try expect(math.isPositiveInf(hypot32(0.0, -math.inf(f32))));
162 expect(math.isNan(hypot32(math.nan(f32), 0.0)));162 try expect(math.isNan(hypot32(math.nan(f32), 0.0)));
163 expect(math.isNan(hypot32(0.0, math.nan(f32))));163 try expect(math.isNan(hypot32(0.0, math.nan(f32))));
164}164}
165165
166test "math.hypot64.special" {166test "math.hypot64.special" {
167 expect(math.isPositiveInf(hypot64(math.inf(f64), 0.0)));167 try expect(math.isPositiveInf(hypot64(math.inf(f64), 0.0)));
168 expect(math.isPositiveInf(hypot64(-math.inf(f64), 0.0)));168 try expect(math.isPositiveInf(hypot64(-math.inf(f64), 0.0)));
169 expect(math.isPositiveInf(hypot64(0.0, math.inf(f64))));169 try expect(math.isPositiveInf(hypot64(0.0, math.inf(f64))));
170 expect(math.isPositiveInf(hypot64(0.0, -math.inf(f64))));170 try expect(math.isPositiveInf(hypot64(0.0, -math.inf(f64))));
171 expect(math.isNan(hypot64(math.nan(f64), 0.0)));171 try expect(math.isNan(hypot64(math.nan(f64), 0.0)));
172 expect(math.isNan(hypot64(0.0, math.nan(f64))));172 try expect(math.isNan(hypot64(0.0, math.nan(f64))));
173}173}
lib/std/math/ilogb.zig+22-22
...@@ -106,38 +106,38 @@ fn ilogb64(x: f64) i32 {...@@ -106,38 +106,38 @@ fn ilogb64(x: f64) i32 {
106}106}
107107
108test "math.ilogb" {108test "math.ilogb" {
109 expect(ilogb(@as(f32, 0.2)) == ilogb32(0.2));109 try expect(ilogb(@as(f32, 0.2)) == ilogb32(0.2));
110 expect(ilogb(@as(f64, 0.2)) == ilogb64(0.2));110 try expect(ilogb(@as(f64, 0.2)) == ilogb64(0.2));
111}111}
112112
113test "math.ilogb32" {113test "math.ilogb32" {
114 expect(ilogb32(0.0) == fp_ilogb0);114 try expect(ilogb32(0.0) == fp_ilogb0);
115 expect(ilogb32(0.5) == -1);115 try expect(ilogb32(0.5) == -1);
116 expect(ilogb32(0.8923) == -1);116 try expect(ilogb32(0.8923) == -1);
117 expect(ilogb32(10.0) == 3);117 try expect(ilogb32(10.0) == 3);
118 expect(ilogb32(-123984) == 16);118 try expect(ilogb32(-123984) == 16);
119 expect(ilogb32(2398.23) == 11);119 try expect(ilogb32(2398.23) == 11);
120}120}
121121
122test "math.ilogb64" {122test "math.ilogb64" {
123 expect(ilogb64(0.0) == fp_ilogb0);123 try expect(ilogb64(0.0) == fp_ilogb0);
124 expect(ilogb64(0.5) == -1);124 try expect(ilogb64(0.5) == -1);
125 expect(ilogb64(0.8923) == -1);125 try expect(ilogb64(0.8923) == -1);
126 expect(ilogb64(10.0) == 3);126 try expect(ilogb64(10.0) == 3);
127 expect(ilogb64(-123984) == 16);127 try expect(ilogb64(-123984) == 16);
128 expect(ilogb64(2398.23) == 11);128 try expect(ilogb64(2398.23) == 11);
129}129}
130130
131test "math.ilogb32.special" {131test "math.ilogb32.special" {
132 expect(ilogb32(math.inf(f32)) == maxInt(i32));132 try expect(ilogb32(math.inf(f32)) == maxInt(i32));
133 expect(ilogb32(-math.inf(f32)) == maxInt(i32));133 try expect(ilogb32(-math.inf(f32)) == maxInt(i32));
134 expect(ilogb32(0.0) == minInt(i32));134 try expect(ilogb32(0.0) == minInt(i32));
135 expect(ilogb32(math.nan(f32)) == maxInt(i32));135 try expect(ilogb32(math.nan(f32)) == maxInt(i32));
136}136}
137137
138test "math.ilogb64.special" {138test "math.ilogb64.special" {
139 expect(ilogb64(math.inf(f64)) == maxInt(i32));139 try expect(ilogb64(math.inf(f64)) == maxInt(i32));
140 expect(ilogb64(-math.inf(f64)) == maxInt(i32));140 try expect(ilogb64(-math.inf(f64)) == maxInt(i32));
141 expect(ilogb64(0.0) == minInt(i32));141 try expect(ilogb64(0.0) == minInt(i32));
142 expect(ilogb64(math.nan(f64)) == maxInt(i32));142 try expect(ilogb64(math.nan(f64)) == maxInt(i32));
143}143}
lib/std/math/isfinite.zig+24-24
...@@ -35,30 +35,30 @@ pub fn isFinite(x: anytype) bool {...@@ -35,30 +35,30 @@ pub fn isFinite(x: anytype) bool {
35}35}
3636
37test "math.isFinite" {37test "math.isFinite" {
38 expect(isFinite(@as(f16, 0.0)));38 try expect(isFinite(@as(f16, 0.0)));
39 expect(isFinite(@as(f16, -0.0)));39 try expect(isFinite(@as(f16, -0.0)));
40 expect(isFinite(@as(f32, 0.0)));40 try expect(isFinite(@as(f32, 0.0)));
41 expect(isFinite(@as(f32, -0.0)));41 try expect(isFinite(@as(f32, -0.0)));
42 expect(isFinite(@as(f64, 0.0)));42 try expect(isFinite(@as(f64, 0.0)));
43 expect(isFinite(@as(f64, -0.0)));43 try expect(isFinite(@as(f64, -0.0)));
44 expect(isFinite(@as(f128, 0.0)));44 try expect(isFinite(@as(f128, 0.0)));
45 expect(isFinite(@as(f128, -0.0)));45 try expect(isFinite(@as(f128, -0.0)));
4646
47 expect(!isFinite(math.inf(f16)));47 try expect(!isFinite(math.inf(f16)));
48 expect(!isFinite(-math.inf(f16)));48 try expect(!isFinite(-math.inf(f16)));
49 expect(!isFinite(math.inf(f32)));49 try expect(!isFinite(math.inf(f32)));
50 expect(!isFinite(-math.inf(f32)));50 try expect(!isFinite(-math.inf(f32)));
51 expect(!isFinite(math.inf(f64)));51 try expect(!isFinite(math.inf(f64)));
52 expect(!isFinite(-math.inf(f64)));52 try expect(!isFinite(-math.inf(f64)));
53 expect(!isFinite(math.inf(f128)));53 try expect(!isFinite(math.inf(f128)));
54 expect(!isFinite(-math.inf(f128)));54 try expect(!isFinite(-math.inf(f128)));
5555
56 expect(!isFinite(math.nan(f16)));56 try expect(!isFinite(math.nan(f16)));
57 expect(!isFinite(-math.nan(f16)));57 try expect(!isFinite(-math.nan(f16)));
58 expect(!isFinite(math.nan(f32)));58 try expect(!isFinite(math.nan(f32)));
59 expect(!isFinite(-math.nan(f32)));59 try expect(!isFinite(-math.nan(f32)));
60 expect(!isFinite(math.nan(f64)));60 try expect(!isFinite(math.nan(f64)));
61 expect(!isFinite(-math.nan(f64)));61 try expect(!isFinite(-math.nan(f64)));
62 expect(!isFinite(math.nan(f128)));62 try expect(!isFinite(math.nan(f128)));
63 expect(!isFinite(-math.nan(f128)));63 try expect(!isFinite(-math.nan(f128)));
64}64}
lib/std/math/isinf.zig+48-48
...@@ -79,58 +79,58 @@ pub fn isNegativeInf(x: anytype) bool {...@@ -79,58 +79,58 @@ pub fn isNegativeInf(x: anytype) bool {
79}79}
8080
81test "math.isInf" {81test "math.isInf" {
82 expect(!isInf(@as(f16, 0.0)));82 try expect(!isInf(@as(f16, 0.0)));
83 expect(!isInf(@as(f16, -0.0)));83 try expect(!isInf(@as(f16, -0.0)));
84 expect(!isInf(@as(f32, 0.0)));84 try expect(!isInf(@as(f32, 0.0)));
85 expect(!isInf(@as(f32, -0.0)));85 try expect(!isInf(@as(f32, -0.0)));
86 expect(!isInf(@as(f64, 0.0)));86 try expect(!isInf(@as(f64, 0.0)));
87 expect(!isInf(@as(f64, -0.0)));87 try expect(!isInf(@as(f64, -0.0)));
88 expect(!isInf(@as(f128, 0.0)));88 try expect(!isInf(@as(f128, 0.0)));
89 expect(!isInf(@as(f128, -0.0)));89 try expect(!isInf(@as(f128, -0.0)));
90 expect(isInf(math.inf(f16)));90 try expect(isInf(math.inf(f16)));
91 expect(isInf(-math.inf(f16)));91 try expect(isInf(-math.inf(f16)));
92 expect(isInf(math.inf(f32)));92 try expect(isInf(math.inf(f32)));
93 expect(isInf(-math.inf(f32)));93 try expect(isInf(-math.inf(f32)));
94 expect(isInf(math.inf(f64)));94 try expect(isInf(math.inf(f64)));
95 expect(isInf(-math.inf(f64)));95 try expect(isInf(-math.inf(f64)));
96 expect(isInf(math.inf(f128)));96 try expect(isInf(math.inf(f128)));
97 expect(isInf(-math.inf(f128)));97 try expect(isInf(-math.inf(f128)));
98}98}
9999
100test "math.isPositiveInf" {100test "math.isPositiveInf" {
101 expect(!isPositiveInf(@as(f16, 0.0)));101 try expect(!isPositiveInf(@as(f16, 0.0)));
102 expect(!isPositiveInf(@as(f16, -0.0)));102 try expect(!isPositiveInf(@as(f16, -0.0)));
103 expect(!isPositiveInf(@as(f32, 0.0)));103 try expect(!isPositiveInf(@as(f32, 0.0)));
104 expect(!isPositiveInf(@as(f32, -0.0)));104 try expect(!isPositiveInf(@as(f32, -0.0)));
105 expect(!isPositiveInf(@as(f64, 0.0)));105 try expect(!isPositiveInf(@as(f64, 0.0)));
106 expect(!isPositiveInf(@as(f64, -0.0)));106 try expect(!isPositiveInf(@as(f64, -0.0)));
107 expect(!isPositiveInf(@as(f128, 0.0)));107 try expect(!isPositiveInf(@as(f128, 0.0)));
108 expect(!isPositiveInf(@as(f128, -0.0)));108 try expect(!isPositiveInf(@as(f128, -0.0)));
109 expect(isPositiveInf(math.inf(f16)));109 try expect(isPositiveInf(math.inf(f16)));
110 expect(!isPositiveInf(-math.inf(f16)));110 try expect(!isPositiveInf(-math.inf(f16)));
111 expect(isPositiveInf(math.inf(f32)));111 try expect(isPositiveInf(math.inf(f32)));
112 expect(!isPositiveInf(-math.inf(f32)));112 try expect(!isPositiveInf(-math.inf(f32)));
113 expect(isPositiveInf(math.inf(f64)));113 try expect(isPositiveInf(math.inf(f64)));
114 expect(!isPositiveInf(-math.inf(f64)));114 try expect(!isPositiveInf(-math.inf(f64)));
115 expect(isPositiveInf(math.inf(f128)));115 try expect(isPositiveInf(math.inf(f128)));
116 expect(!isPositiveInf(-math.inf(f128)));116 try expect(!isPositiveInf(-math.inf(f128)));
117}117}
118118
119test "math.isNegativeInf" {119test "math.isNegativeInf" {
120 expect(!isNegativeInf(@as(f16, 0.0)));120 try expect(!isNegativeInf(@as(f16, 0.0)));
121 expect(!isNegativeInf(@as(f16, -0.0)));121 try expect(!isNegativeInf(@as(f16, -0.0)));
122 expect(!isNegativeInf(@as(f32, 0.0)));122 try expect(!isNegativeInf(@as(f32, 0.0)));
123 expect(!isNegativeInf(@as(f32, -0.0)));123 try expect(!isNegativeInf(@as(f32, -0.0)));
124 expect(!isNegativeInf(@as(f64, 0.0)));124 try expect(!isNegativeInf(@as(f64, 0.0)));
125 expect(!isNegativeInf(@as(f64, -0.0)));125 try expect(!isNegativeInf(@as(f64, -0.0)));
126 expect(!isNegativeInf(@as(f128, 0.0)));126 try expect(!isNegativeInf(@as(f128, 0.0)));
127 expect(!isNegativeInf(@as(f128, -0.0)));127 try expect(!isNegativeInf(@as(f128, -0.0)));
128 expect(!isNegativeInf(math.inf(f16)));128 try expect(!isNegativeInf(math.inf(f16)));
129 expect(isNegativeInf(-math.inf(f16)));129 try expect(isNegativeInf(-math.inf(f16)));
130 expect(!isNegativeInf(math.inf(f32)));130 try expect(!isNegativeInf(math.inf(f32)));
131 expect(isNegativeInf(-math.inf(f32)));131 try expect(isNegativeInf(-math.inf(f32)));
132 expect(!isNegativeInf(math.inf(f64)));132 try expect(!isNegativeInf(math.inf(f64)));
133 expect(isNegativeInf(-math.inf(f64)));133 try expect(isNegativeInf(-math.inf(f64)));
134 expect(!isNegativeInf(math.inf(f128)));134 try expect(!isNegativeInf(math.inf(f128)));
135 expect(isNegativeInf(-math.inf(f128)));135 try expect(isNegativeInf(-math.inf(f128)));
136}136}
lib/std/math/isnan.zig+8-8
...@@ -21,12 +21,12 @@ pub fn isSignalNan(x: anytype) bool {...@@ -21,12 +21,12 @@ pub fn isSignalNan(x: anytype) bool {
21}21}
2222
23test "math.isNan" {23test "math.isNan" {
24 expect(isNan(math.nan(f16)));24 try expect(isNan(math.nan(f16)));
25 expect(isNan(math.nan(f32)));25 try expect(isNan(math.nan(f32)));
26 expect(isNan(math.nan(f64)));26 try expect(isNan(math.nan(f64)));
27 expect(isNan(math.nan(f128)));27 try expect(isNan(math.nan(f128)));
28 expect(!isNan(@as(f16, 1.0)));28 try expect(!isNan(@as(f16, 1.0)));
29 expect(!isNan(@as(f32, 1.0)));29 try expect(!isNan(@as(f32, 1.0)));
30 expect(!isNan(@as(f64, 1.0)));30 try expect(!isNan(@as(f64, 1.0)));
31 expect(!isNan(@as(f128, 1.0)));31 try expect(!isNan(@as(f128, 1.0)));
32}32}
lib/std/math/isnormal.zig+9-9
...@@ -31,13 +31,13 @@ pub fn isNormal(x: anytype) bool {...@@ -31,13 +31,13 @@ pub fn isNormal(x: anytype) bool {
31}31}
3232
33test "math.isNormal" {33test "math.isNormal" {
34 expect(!isNormal(math.nan(f16)));34 try expect(!isNormal(math.nan(f16)));
35 expect(!isNormal(math.nan(f32)));35 try expect(!isNormal(math.nan(f32)));
36 expect(!isNormal(math.nan(f64)));36 try expect(!isNormal(math.nan(f64)));
37 expect(!isNormal(@as(f16, 0)));37 try expect(!isNormal(@as(f16, 0)));
38 expect(!isNormal(@as(f32, 0)));38 try expect(!isNormal(@as(f32, 0)));
39 expect(!isNormal(@as(f64, 0)));39 try expect(!isNormal(@as(f64, 0)));
40 expect(isNormal(@as(f16, 1.0)));40 try expect(isNormal(@as(f16, 1.0)));
41 expect(isNormal(@as(f32, 1.0)));41 try expect(isNormal(@as(f32, 1.0)));
42 expect(isNormal(@as(f64, 1.0)));42 try expect(isNormal(@as(f64, 1.0)));
43}43}
lib/std/math/ln.zig+22-22
...@@ -153,42 +153,42 @@ pub fn ln_64(x_: f64) f64 {...@@ -153,42 +153,42 @@ pub fn ln_64(x_: f64) f64 {
153}153}
154154
155test "math.ln" {155test "math.ln" {
156 expect(ln(@as(f32, 0.2)) == ln_32(0.2));156 try expect(ln(@as(f32, 0.2)) == ln_32(0.2));
157 expect(ln(@as(f64, 0.2)) == ln_64(0.2));157 try expect(ln(@as(f64, 0.2)) == ln_64(0.2));
158}158}
159159
160test "math.ln32" {160test "math.ln32" {
161 const epsilon = 0.000001;161 const epsilon = 0.000001;
162162
163 expect(math.approxEqAbs(f32, ln_32(0.2), -1.609438, epsilon));163 try expect(math.approxEqAbs(f32, ln_32(0.2), -1.609438, epsilon));
164 expect(math.approxEqAbs(f32, ln_32(0.8923), -0.113953, epsilon));164 try expect(math.approxEqAbs(f32, ln_32(0.8923), -0.113953, epsilon));
165 expect(math.approxEqAbs(f32, ln_32(1.5), 0.405465, epsilon));165 try expect(math.approxEqAbs(f32, ln_32(1.5), 0.405465, epsilon));
166 expect(math.approxEqAbs(f32, ln_32(37.45), 3.623007, epsilon));166 try expect(math.approxEqAbs(f32, ln_32(37.45), 3.623007, epsilon));
167 expect(math.approxEqAbs(f32, ln_32(89.123), 4.490017, epsilon));167 try expect(math.approxEqAbs(f32, ln_32(89.123), 4.490017, epsilon));
168 expect(math.approxEqAbs(f32, ln_32(123123.234375), 11.720941, epsilon));168 try expect(math.approxEqAbs(f32, ln_32(123123.234375), 11.720941, epsilon));
169}169}
170170
171test "math.ln64" {171test "math.ln64" {
172 const epsilon = 0.000001;172 const epsilon = 0.000001;
173173
174 expect(math.approxEqAbs(f64, ln_64(0.2), -1.609438, epsilon));174 try expect(math.approxEqAbs(f64, ln_64(0.2), -1.609438, epsilon));
175 expect(math.approxEqAbs(f64, ln_64(0.8923), -0.113953, epsilon));175 try expect(math.approxEqAbs(f64, ln_64(0.8923), -0.113953, epsilon));
176 expect(math.approxEqAbs(f64, ln_64(1.5), 0.405465, epsilon));176 try expect(math.approxEqAbs(f64, ln_64(1.5), 0.405465, epsilon));
177 expect(math.approxEqAbs(f64, ln_64(37.45), 3.623007, epsilon));177 try expect(math.approxEqAbs(f64, ln_64(37.45), 3.623007, epsilon));
178 expect(math.approxEqAbs(f64, ln_64(89.123), 4.490017, epsilon));178 try expect(math.approxEqAbs(f64, ln_64(89.123), 4.490017, epsilon));
179 expect(math.approxEqAbs(f64, ln_64(123123.234375), 11.720941, epsilon));179 try expect(math.approxEqAbs(f64, ln_64(123123.234375), 11.720941, epsilon));
180}180}
181181
182test "math.ln32.special" {182test "math.ln32.special" {
183 expect(math.isPositiveInf(ln_32(math.inf(f32))));183 try expect(math.isPositiveInf(ln_32(math.inf(f32))));
184 expect(math.isNegativeInf(ln_32(0.0)));184 try expect(math.isNegativeInf(ln_32(0.0)));
185 expect(math.isNan(ln_32(-1.0)));185 try expect(math.isNan(ln_32(-1.0)));
186 expect(math.isNan(ln_32(math.nan(f32))));186 try expect(math.isNan(ln_32(math.nan(f32))));
187}187}
188188
189test "math.ln64.special" {189test "math.ln64.special" {
190 expect(math.isPositiveInf(ln_64(math.inf(f64))));190 try expect(math.isPositiveInf(ln_64(math.inf(f64))));
191 expect(math.isNegativeInf(ln_64(0.0)));191 try expect(math.isNegativeInf(ln_64(0.0)));
192 expect(math.isNan(ln_64(-1.0)));192 try expect(math.isNan(ln_64(-1.0)));
193 expect(math.isNan(ln_64(math.nan(f64))));193 try expect(math.isNan(ln_64(math.nan(f64))));
194}194}
lib/std/math/log.zig+12-12
...@@ -53,25 +53,25 @@ pub fn log(comptime T: type, base: T, x: T) T {...@@ -53,25 +53,25 @@ pub fn log(comptime T: type, base: T, x: T) T {
53}53}
5454
55test "math.log integer" {55test "math.log integer" {
56 expect(log(u8, 2, 0x1) == 0);56 try expect(log(u8, 2, 0x1) == 0);
57 expect(log(u8, 2, 0x2) == 1);57 try expect(log(u8, 2, 0x2) == 1);
58 expect(log(u16, 2, 0x72) == 6);58 try expect(log(u16, 2, 0x72) == 6);
59 expect(log(u32, 2, 0xFFFFFF) == 23);59 try expect(log(u32, 2, 0xFFFFFF) == 23);
60 expect(log(u64, 2, 0x7FF0123456789ABC) == 62);60 try expect(log(u64, 2, 0x7FF0123456789ABC) == 62);
61}61}
6262
63test "math.log float" {63test "math.log float" {
64 const epsilon = 0.000001;64 const epsilon = 0.000001;
6565
66 expect(math.approxEqAbs(f32, log(f32, 6, 0.23947), -0.797723, epsilon));66 try 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));67 try expect(math.approxEqAbs(f32, log(f32, 89, 0.23947), -0.318432, epsilon));
68 expect(math.approxEqAbs(f64, log(f64, 123897, 12389216414), 1.981724596, epsilon));68 try expect(math.approxEqAbs(f64, log(f64, 123897, 12389216414), 1.981724596, epsilon));
69}69}
7070
71test "math.log float_special" {71test "math.log float_special" {
72 expect(log(f32, 2, 0.2301974) == math.log2(@as(f32, 0.2301974)));72 try 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)));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)));75 try 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)));76 try expect(log(f64, 10, 213.23019799993) == math.log10(@as(f64, 213.23019799993)));
77}77}
lib/std/math/log10.zig+22-22
...@@ -181,42 +181,42 @@ pub fn log10_64(x_: f64) f64 {...@@ -181,42 +181,42 @@ pub fn log10_64(x_: f64) f64 {
181}181}
182182
183test "math.log10" {183test "math.log10" {
184 testing.expect(log10(@as(f32, 0.2)) == log10_32(0.2));184 try testing.expect(log10(@as(f32, 0.2)) == log10_32(0.2));
185 testing.expect(log10(@as(f64, 0.2)) == log10_64(0.2));185 try testing.expect(log10(@as(f64, 0.2)) == log10_64(0.2));
186}186}
187187
188test "math.log10_32" {188test "math.log10_32" {
189 const epsilon = 0.000001;189 const epsilon = 0.000001;
190190
191 testing.expect(math.approxEqAbs(f32, log10_32(0.2), -0.698970, epsilon));191 try 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));192 try 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));193 try 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));194 try 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));195 try 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));196 try testing.expect(math.approxEqAbs(f32, log10_32(123123.234375), 5.09034, epsilon));
197}197}
198198
199test "math.log10_64" {199test "math.log10_64" {
200 const epsilon = 0.000001;200 const epsilon = 0.000001;
201201
202 testing.expect(math.approxEqAbs(f64, log10_64(0.2), -0.698970, epsilon));202 try 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));203 try 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));204 try 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));205 try 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));206 try 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));207 try testing.expect(math.approxEqAbs(f64, log10_64(123123.234375), 5.09034, epsilon));
208}208}
209209
210test "math.log10_32.special" {210test "math.log10_32.special" {
211 testing.expect(math.isPositiveInf(log10_32(math.inf(f32))));211 try testing.expect(math.isPositiveInf(log10_32(math.inf(f32))));
212 testing.expect(math.isNegativeInf(log10_32(0.0)));212 try testing.expect(math.isNegativeInf(log10_32(0.0)));
213 testing.expect(math.isNan(log10_32(-1.0)));213 try testing.expect(math.isNan(log10_32(-1.0)));
214 testing.expect(math.isNan(log10_32(math.nan(f32))));214 try testing.expect(math.isNan(log10_32(math.nan(f32))));
215}215}
216216
217test "math.log10_64.special" {217test "math.log10_64.special" {
218 testing.expect(math.isPositiveInf(log10_64(math.inf(f64))));218 try testing.expect(math.isPositiveInf(log10_64(math.inf(f64))));
219 testing.expect(math.isNegativeInf(log10_64(0.0)));219 try testing.expect(math.isNegativeInf(log10_64(0.0)));
220 testing.expect(math.isNan(log10_64(-1.0)));220 try testing.expect(math.isNan(log10_64(-1.0)));
221 testing.expect(math.isNan(log10_64(math.nan(f64))));221 try testing.expect(math.isNan(log10_64(math.nan(f64))));
222}222}
lib/std/math/log1p.zig+28-28
...@@ -187,48 +187,48 @@ fn log1p_64(x: f64) f64 {...@@ -187,48 +187,48 @@ fn log1p_64(x: f64) f64 {
187}187}
188188
189test "math.log1p" {189test "math.log1p" {
190 expect(log1p(@as(f32, 0.0)) == log1p_32(0.0));190 try expect(log1p(@as(f32, 0.0)) == log1p_32(0.0));
191 expect(log1p(@as(f64, 0.0)) == log1p_64(0.0));191 try expect(log1p(@as(f64, 0.0)) == log1p_64(0.0));
192}192}
193193
194test "math.log1p_32" {194test "math.log1p_32" {
195 const epsilon = 0.000001;195 const epsilon = 0.000001;
196196
197 expect(math.approxEqAbs(f32, log1p_32(0.0), 0.0, epsilon));197 try expect(math.approxEqAbs(f32, log1p_32(0.0), 0.0, epsilon));
198 expect(math.approxEqAbs(f32, log1p_32(0.2), 0.182322, epsilon));198 try expect(math.approxEqAbs(f32, log1p_32(0.2), 0.182322, epsilon));
199 expect(math.approxEqAbs(f32, log1p_32(0.8923), 0.637793, epsilon));199 try expect(math.approxEqAbs(f32, log1p_32(0.8923), 0.637793, epsilon));
200 expect(math.approxEqAbs(f32, log1p_32(1.5), 0.916291, epsilon));200 try expect(math.approxEqAbs(f32, log1p_32(1.5), 0.916291, epsilon));
201 expect(math.approxEqAbs(f32, log1p_32(37.45), 3.649359, epsilon));201 try expect(math.approxEqAbs(f32, log1p_32(37.45), 3.649359, epsilon));
202 expect(math.approxEqAbs(f32, log1p_32(89.123), 4.501175, epsilon));202 try expect(math.approxEqAbs(f32, log1p_32(89.123), 4.501175, epsilon));
203 expect(math.approxEqAbs(f32, log1p_32(123123.234375), 11.720949, epsilon));203 try expect(math.approxEqAbs(f32, log1p_32(123123.234375), 11.720949, epsilon));
204}204}
205205
206test "math.log1p_64" {206test "math.log1p_64" {
207 const epsilon = 0.000001;207 const epsilon = 0.000001;
208208
209 expect(math.approxEqAbs(f64, log1p_64(0.0), 0.0, epsilon));209 try expect(math.approxEqAbs(f64, log1p_64(0.0), 0.0, epsilon));
210 expect(math.approxEqAbs(f64, log1p_64(0.2), 0.182322, epsilon));210 try expect(math.approxEqAbs(f64, log1p_64(0.2), 0.182322, epsilon));
211 expect(math.approxEqAbs(f64, log1p_64(0.8923), 0.637793, epsilon));211 try expect(math.approxEqAbs(f64, log1p_64(0.8923), 0.637793, epsilon));
212 expect(math.approxEqAbs(f64, log1p_64(1.5), 0.916291, epsilon));212 try expect(math.approxEqAbs(f64, log1p_64(1.5), 0.916291, epsilon));
213 expect(math.approxEqAbs(f64, log1p_64(37.45), 3.649359, epsilon));213 try expect(math.approxEqAbs(f64, log1p_64(37.45), 3.649359, epsilon));
214 expect(math.approxEqAbs(f64, log1p_64(89.123), 4.501175, epsilon));214 try expect(math.approxEqAbs(f64, log1p_64(89.123), 4.501175, epsilon));
215 expect(math.approxEqAbs(f64, log1p_64(123123.234375), 11.720949, epsilon));215 try expect(math.approxEqAbs(f64, log1p_64(123123.234375), 11.720949, epsilon));
216}216}
217217
218test "math.log1p_32.special" {218test "math.log1p_32.special" {
219 expect(math.isPositiveInf(log1p_32(math.inf(f32))));219 try expect(math.isPositiveInf(log1p_32(math.inf(f32))));
220 expect(log1p_32(0.0) == 0.0);220 try expect(log1p_32(0.0) == 0.0);
221 expect(log1p_32(-0.0) == -0.0);221 try expect(log1p_32(-0.0) == -0.0);
222 expect(math.isNegativeInf(log1p_32(-1.0)));222 try expect(math.isNegativeInf(log1p_32(-1.0)));
223 expect(math.isNan(log1p_32(-2.0)));223 try expect(math.isNan(log1p_32(-2.0)));
224 expect(math.isNan(log1p_32(math.nan(f32))));224 try expect(math.isNan(log1p_32(math.nan(f32))));
225}225}
226226
227test "math.log1p_64.special" {227test "math.log1p_64.special" {
228 expect(math.isPositiveInf(log1p_64(math.inf(f64))));228 try expect(math.isPositiveInf(log1p_64(math.inf(f64))));
229 expect(log1p_64(0.0) == 0.0);229 try expect(log1p_64(0.0) == 0.0);
230 expect(log1p_64(-0.0) == -0.0);230 try expect(log1p_64(-0.0) == -0.0);
231 expect(math.isNegativeInf(log1p_64(-1.0)));231 try expect(math.isNegativeInf(log1p_64(-1.0)));
232 expect(math.isNan(log1p_64(-2.0)));232 try expect(math.isNan(log1p_64(-2.0)));
233 expect(math.isNan(log1p_64(math.nan(f64))));233 try expect(math.isNan(log1p_64(math.nan(f64))));
234}234}
lib/std/math/log2.zig+20-20
...@@ -179,40 +179,40 @@ pub fn log2_64(x_: f64) f64 {...@@ -179,40 +179,40 @@ pub fn log2_64(x_: f64) f64 {
179}179}
180180
181test "math.log2" {181test "math.log2" {
182 expect(log2(@as(f32, 0.2)) == log2_32(0.2));182 try expect(log2(@as(f32, 0.2)) == log2_32(0.2));
183 expect(log2(@as(f64, 0.2)) == log2_64(0.2));183 try expect(log2(@as(f64, 0.2)) == log2_64(0.2));
184}184}
185185
186test "math.log2_32" {186test "math.log2_32" {
187 const epsilon = 0.000001;187 const epsilon = 0.000001;
188188
189 expect(math.approxEqAbs(f32, log2_32(0.2), -2.321928, epsilon));189 try expect(math.approxEqAbs(f32, log2_32(0.2), -2.321928, epsilon));
190 expect(math.approxEqAbs(f32, log2_32(0.8923), -0.164399, epsilon));190 try expect(math.approxEqAbs(f32, log2_32(0.8923), -0.164399, epsilon));
191 expect(math.approxEqAbs(f32, log2_32(1.5), 0.584962, epsilon));191 try expect(math.approxEqAbs(f32, log2_32(1.5), 0.584962, epsilon));
192 expect(math.approxEqAbs(f32, log2_32(37.45), 5.226894, epsilon));192 try expect(math.approxEqAbs(f32, log2_32(37.45), 5.226894, epsilon));
193 expect(math.approxEqAbs(f32, log2_32(123123.234375), 16.909744, epsilon));193 try expect(math.approxEqAbs(f32, log2_32(123123.234375), 16.909744, epsilon));
194}194}
195195
196test "math.log2_64" {196test "math.log2_64" {
197 const epsilon = 0.000001;197 const epsilon = 0.000001;
198198
199 expect(math.approxEqAbs(f64, log2_64(0.2), -2.321928, epsilon));199 try expect(math.approxEqAbs(f64, log2_64(0.2), -2.321928, epsilon));
200 expect(math.approxEqAbs(f64, log2_64(0.8923), -0.164399, epsilon));200 try expect(math.approxEqAbs(f64, log2_64(0.8923), -0.164399, epsilon));
201 expect(math.approxEqAbs(f64, log2_64(1.5), 0.584962, epsilon));201 try expect(math.approxEqAbs(f64, log2_64(1.5), 0.584962, epsilon));
202 expect(math.approxEqAbs(f64, log2_64(37.45), 5.226894, epsilon));202 try expect(math.approxEqAbs(f64, log2_64(37.45), 5.226894, epsilon));
203 expect(math.approxEqAbs(f64, log2_64(123123.234375), 16.909744, epsilon));203 try expect(math.approxEqAbs(f64, log2_64(123123.234375), 16.909744, epsilon));
204}204}
205205
206test "math.log2_32.special" {206test "math.log2_32.special" {
207 expect(math.isPositiveInf(log2_32(math.inf(f32))));207 try expect(math.isPositiveInf(log2_32(math.inf(f32))));
208 expect(math.isNegativeInf(log2_32(0.0)));208 try expect(math.isNegativeInf(log2_32(0.0)));
209 expect(math.isNan(log2_32(-1.0)));209 try expect(math.isNan(log2_32(-1.0)));
210 expect(math.isNan(log2_32(math.nan(f32))));210 try expect(math.isNan(log2_32(math.nan(f32))));
211}211}
212212
213test "math.log2_64.special" {213test "math.log2_64.special" {
214 expect(math.isPositiveInf(log2_64(math.inf(f64))));214 try expect(math.isPositiveInf(log2_64(math.inf(f64))));
215 expect(math.isNegativeInf(log2_64(0.0)));215 try expect(math.isNegativeInf(log2_64(0.0)));
216 expect(math.isNan(log2_64(-1.0)));216 try expect(math.isNan(log2_64(-1.0)));
217 expect(math.isNan(log2_64(math.nan(f64))));217 try expect(math.isNan(log2_64(math.nan(f64))));
218}218}
lib/std/math/modf.zig+28-28
...@@ -131,11 +131,11 @@ test "math.modf" {...@@ -131,11 +131,11 @@ test "math.modf" {
131 const a = modf(@as(f32, 1.0));131 const a = modf(@as(f32, 1.0));
132 const b = modf32(1.0);132 const b = modf32(1.0);
133 // NOTE: No struct comparison on generic return type function? non-named, makes sense, but still.133 // 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
136 const c = modf(@as(f64, 1.0));136 const c = modf(@as(f64, 1.0));
137 const d = modf64(1.0);137 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);
139}139}
140140
141test "math.modf32" {141test "math.modf32" {
...@@ -143,24 +143,24 @@ test "math.modf32" {...@@ -143,24 +143,24 @@ test "math.modf32" {
143 var r: modf32_result = undefined;143 var r: modf32_result = undefined;
144144
145 r = modf32(1.0);145 r = modf32(1.0);
146 expect(math.approxEqAbs(f32, r.ipart, 1.0, epsilon));146 try expect(math.approxEqAbs(f32, r.ipart, 1.0, epsilon));
147 expect(math.approxEqAbs(f32, r.fpart, 0.0, epsilon));147 try expect(math.approxEqAbs(f32, r.fpart, 0.0, epsilon));
148148
149 r = modf32(2.545);149 r = modf32(2.545);
150 expect(math.approxEqAbs(f32, r.ipart, 2.0, epsilon));150 try expect(math.approxEqAbs(f32, r.ipart, 2.0, epsilon));
151 expect(math.approxEqAbs(f32, r.fpart, 0.545, epsilon));151 try expect(math.approxEqAbs(f32, r.fpart, 0.545, epsilon));
152152
153 r = modf32(3.978123);153 r = modf32(3.978123);
154 expect(math.approxEqAbs(f32, r.ipart, 3.0, epsilon));154 try expect(math.approxEqAbs(f32, r.ipart, 3.0, epsilon));
155 expect(math.approxEqAbs(f32, r.fpart, 0.978123, epsilon));155 try expect(math.approxEqAbs(f32, r.fpart, 0.978123, epsilon));
156156
157 r = modf32(43874.3);157 r = modf32(43874.3);
158 expect(math.approxEqAbs(f32, r.ipart, 43874, epsilon));158 try expect(math.approxEqAbs(f32, r.ipart, 43874, epsilon));
159 expect(math.approxEqAbs(f32, r.fpart, 0.300781, epsilon));159 try expect(math.approxEqAbs(f32, r.fpart, 0.300781, epsilon));
160160
161 r = modf32(1234.340780);161 r = modf32(1234.340780);
162 expect(math.approxEqAbs(f32, r.ipart, 1234, epsilon));162 try expect(math.approxEqAbs(f32, r.ipart, 1234, epsilon));
163 expect(math.approxEqAbs(f32, r.fpart, 0.340820, epsilon));163 try expect(math.approxEqAbs(f32, r.fpart, 0.340820, epsilon));
164}164}
165165
166test "math.modf64" {166test "math.modf64" {
...@@ -168,48 +168,48 @@ test "math.modf64" {...@@ -168,48 +168,48 @@ test "math.modf64" {
168 var r: modf64_result = undefined;168 var r: modf64_result = undefined;
169169
170 r = modf64(1.0);170 r = modf64(1.0);
171 expect(math.approxEqAbs(f64, r.ipart, 1.0, epsilon));171 try expect(math.approxEqAbs(f64, r.ipart, 1.0, epsilon));
172 expect(math.approxEqAbs(f64, r.fpart, 0.0, epsilon));172 try expect(math.approxEqAbs(f64, r.fpart, 0.0, epsilon));
173173
174 r = modf64(2.545);174 r = modf64(2.545);
175 expect(math.approxEqAbs(f64, r.ipart, 2.0, epsilon));175 try expect(math.approxEqAbs(f64, r.ipart, 2.0, epsilon));
176 expect(math.approxEqAbs(f64, r.fpart, 0.545, epsilon));176 try expect(math.approxEqAbs(f64, r.fpart, 0.545, epsilon));
177177
178 r = modf64(3.978123);178 r = modf64(3.978123);
179 expect(math.approxEqAbs(f64, r.ipart, 3.0, epsilon));179 try expect(math.approxEqAbs(f64, r.ipart, 3.0, epsilon));
180 expect(math.approxEqAbs(f64, r.fpart, 0.978123, epsilon));180 try expect(math.approxEqAbs(f64, r.fpart, 0.978123, epsilon));
181181
182 r = modf64(43874.3);182 r = modf64(43874.3);
183 expect(math.approxEqAbs(f64, r.ipart, 43874, epsilon));183 try expect(math.approxEqAbs(f64, r.ipart, 43874, epsilon));
184 expect(math.approxEqAbs(f64, r.fpart, 0.3, epsilon));184 try expect(math.approxEqAbs(f64, r.fpart, 0.3, epsilon));
185185
186 r = modf64(1234.340780);186 r = modf64(1234.340780);
187 expect(math.approxEqAbs(f64, r.ipart, 1234, epsilon));187 try expect(math.approxEqAbs(f64, r.ipart, 1234, epsilon));
188 expect(math.approxEqAbs(f64, r.fpart, 0.340780, epsilon));188 try expect(math.approxEqAbs(f64, r.fpart, 0.340780, epsilon));
189}189}
190190
191test "math.modf32.special" {191test "math.modf32.special" {
192 var r: modf32_result = undefined;192 var r: modf32_result = undefined;
193193
194 r = modf32(math.inf(f32));194 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
197 r = modf32(-math.inf(f32));197 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
200 r = modf32(math.nan(f32));200 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));
202}202}
203203
204test "math.modf64.special" {204test "math.modf64.special" {
205 var r: modf64_result = undefined;205 var r: modf64_result = undefined;
206206
207 r = modf64(math.inf(f64));207 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
210 r = modf64(-math.inf(f64));210 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
213 r = modf64(math.nan(f64));213 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));
215}215}
lib/std/math/pow.zig+52-52
...@@ -190,67 +190,67 @@ fn isOddInteger(x: f64) bool {...@@ -190,67 +190,67 @@ fn isOddInteger(x: f64) bool {
190test "math.pow" {190test "math.pow" {
191 const epsilon = 0.000001;191 const epsilon = 0.000001;
192192
193 expect(math.approxEqAbs(f32, pow(f32, 0.0, 3.3), 0.0, epsilon));193 try 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));194 try 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));195 try 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));196 try 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));197 try 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));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));200 try 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));201 try 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));202 try 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));203 try 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));204 try 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));205 try expect(math.approxEqAbs(f64, pow(f64, 89.123, 3.3), 2722490.231436, epsilon));
206}206}
207207
208test "math.pow.special" {208test "math.pow.special" {
209 const epsilon = 0.000001;209 const epsilon = 0.000001;
210210
211 expect(pow(f32, 4, 0.0) == 1.0);211 try expect(pow(f32, 4, 0.0) == 1.0);
212 expect(pow(f32, 7, -0.0) == 1.0);212 try expect(pow(f32, 7, -0.0) == 1.0);
213 expect(pow(f32, 45, 1.0) == 45);213 try expect(pow(f32, 45, 1.0) == 45);
214 expect(pow(f32, -45, 1.0) == -45);214 try expect(pow(f32, -45, 1.0) == -45);
215 expect(math.isNan(pow(f32, math.nan(f32), 5.0)));215 try expect(math.isNan(pow(f32, math.nan(f32), 5.0)));
216 expect(math.isPositiveInf(pow(f32, -math.inf(f32), 0.5)));216 try expect(math.isPositiveInf(pow(f32, -math.inf(f32), 0.5)));
217 expect(math.isPositiveInf(pow(f32, -0, -0.5)));217 try expect(math.isPositiveInf(pow(f32, -0, -0.5)));
218 expect(pow(f32, -0, 0.5) == 0);218 try expect(pow(f32, -0, 0.5) == 0);
219 expect(math.isNan(pow(f32, 5.0, math.nan(f32))));219 try expect(math.isNan(pow(f32, 5.0, math.nan(f32))));
220 expect(math.isPositiveInf(pow(f32, 0.0, -1.0)));220 try expect(math.isPositiveInf(pow(f32, 0.0, -1.0)));
221 //expect(math.isNegativeInf(pow(f32, -0.0, -3.0))); TODO is this required?221 //expect(math.isNegativeInf(pow(f32, -0.0, -3.0))); TODO is this required?
222 expect(math.isPositiveInf(pow(f32, 0.0, -math.inf(f32))));222 try expect(math.isPositiveInf(pow(f32, 0.0, -math.inf(f32))));
223 expect(math.isPositiveInf(pow(f32, -0.0, -math.inf(f32))));223 try expect(math.isPositiveInf(pow(f32, -0.0, -math.inf(f32))));
224 expect(pow(f32, 0.0, math.inf(f32)) == 0.0);224 try expect(pow(f32, 0.0, math.inf(f32)) == 0.0);
225 expect(pow(f32, -0.0, math.inf(f32)) == 0.0);225 try expect(pow(f32, -0.0, math.inf(f32)) == 0.0);
226 expect(math.isPositiveInf(pow(f32, 0.0, -2.0)));226 try expect(math.isPositiveInf(pow(f32, 0.0, -2.0)));
227 expect(math.isPositiveInf(pow(f32, -0.0, -2.0)));227 try expect(math.isPositiveInf(pow(f32, -0.0, -2.0)));
228 expect(pow(f32, 0.0, 1.0) == 0.0);228 try expect(pow(f32, 0.0, 1.0) == 0.0);
229 expect(pow(f32, -0.0, 1.0) == -0.0);229 try expect(pow(f32, -0.0, 1.0) == -0.0);
230 expect(pow(f32, 0.0, 2.0) == 0.0);230 try expect(pow(f32, 0.0, 2.0) == 0.0);
231 expect(pow(f32, -0.0, 2.0) == 0.0);231 try expect(pow(f32, -0.0, 2.0) == 0.0);
232 expect(math.approxEqAbs(f32, pow(f32, -1.0, math.inf(f32)), 1.0, epsilon));232 try 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));233 try 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))));234 try expect(math.isPositiveInf(pow(f32, 1.2, math.inf(f32))));
235 expect(math.isPositiveInf(pow(f32, -1.2, math.inf(f32))));235 try expect(math.isPositiveInf(pow(f32, -1.2, math.inf(f32))));
236 expect(pow(f32, 1.2, -math.inf(f32)) == 0.0);236 try expect(pow(f32, 1.2, -math.inf(f32)) == 0.0);
237 expect(pow(f32, -1.2, -math.inf(f32)) == 0.0);237 try expect(pow(f32, -1.2, -math.inf(f32)) == 0.0);
238 expect(pow(f32, 0.2, math.inf(f32)) == 0.0);238 try expect(pow(f32, 0.2, math.inf(f32)) == 0.0);
239 expect(pow(f32, -0.2, math.inf(f32)) == 0.0);239 try expect(pow(f32, -0.2, math.inf(f32)) == 0.0);
240 expect(math.isPositiveInf(pow(f32, 0.2, -math.inf(f32))));240 try expect(math.isPositiveInf(pow(f32, 0.2, -math.inf(f32))));
241 expect(math.isPositiveInf(pow(f32, -0.2, -math.inf(f32))));241 try expect(math.isPositiveInf(pow(f32, -0.2, -math.inf(f32))));
242 expect(math.isPositiveInf(pow(f32, math.inf(f32), 1.0)));242 try expect(math.isPositiveInf(pow(f32, math.inf(f32), 1.0)));
243 expect(pow(f32, math.inf(f32), -1.0) == 0.0);243 try expect(pow(f32, math.inf(f32), -1.0) == 0.0);
244 //expect(pow(f32, -math.inf(f32), 5.0) == pow(f32, -0.0, -5.0)); TODO support negative 0?244 //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));245 try expect(pow(f32, -math.inf(f32), -5.2) == pow(f32, -0.0, 5.2));
246 expect(math.isNan(pow(f32, -1.0, 1.2)));246 try expect(math.isNan(pow(f32, -1.0, 1.2)));
247 expect(math.isNan(pow(f32, -12.4, 78.5)));247 try expect(math.isNan(pow(f32, -12.4, 78.5)));
248}248}
249249
250test "math.pow.overflow" {250test "math.pow.overflow" {
251 expect(math.isPositiveInf(pow(f64, 2, 1 << 32)));251 try expect(math.isPositiveInf(pow(f64, 2, 1 << 32)));
252 expect(pow(f64, 2, -(1 << 32)) == 0);252 try expect(pow(f64, 2, -(1 << 32)) == 0);
253 expect(math.isNegativeInf(pow(f64, -2, (1 << 32) + 1)));253 try expect(math.isNegativeInf(pow(f64, -2, (1 << 32) + 1)));
254 expect(pow(f64, 0.5, 1 << 45) == 0);254 try expect(pow(f64, 0.5, 1 << 45) == 0);
255 expect(math.isPositiveInf(pow(f64, 0.5, -(1 << 45))));255 try expect(math.isPositiveInf(pow(f64, 0.5, -(1 << 45))));
256}256}
lib/std/math/powi.zig+75-75
...@@ -111,82 +111,82 @@ pub fn powi(comptime T: type, x: T, y: T) (error{...@@ -111,82 +111,82 @@ pub fn powi(comptime T: type, x: T, y: T) (error{
111}111}
112112
113test "math.powi" {113test "math.powi" {
114 testing.expectError(error.Underflow, powi(i8, -66, 6));114 try testing.expectError(error.Underflow, powi(i8, -66, 6));
115 testing.expectError(error.Underflow, powi(i16, -13, 13));115 try testing.expectError(error.Underflow, powi(i16, -13, 13));
116 testing.expectError(error.Underflow, powi(i32, -32, 21));116 try testing.expectError(error.Underflow, powi(i32, -32, 21));
117 testing.expectError(error.Underflow, powi(i64, -24, 61));117 try testing.expectError(error.Underflow, powi(i64, -24, 61));
118 testing.expectError(error.Underflow, powi(i17, -15, 15));118 try testing.expectError(error.Underflow, powi(i17, -15, 15));
119 testing.expectError(error.Underflow, powi(i42, -6, 40));119 try testing.expectError(error.Underflow, powi(i42, -6, 40));
120120
121 testing.expect((try powi(i8, -5, 3)) == -125);121 try testing.expect((try powi(i8, -5, 3)) == -125);
122 testing.expect((try powi(i16, -16, 3)) == -4096);122 try testing.expect((try powi(i16, -16, 3)) == -4096);
123 testing.expect((try powi(i32, -91, 3)) == -753571);123 try testing.expect((try powi(i32, -91, 3)) == -753571);
124 testing.expect((try powi(i64, -36, 6)) == 2176782336);124 try testing.expect((try powi(i64, -36, 6)) == 2176782336);
125 testing.expect((try powi(i17, -2, 15)) == -32768);125 try testing.expect((try powi(i17, -2, 15)) == -32768);
126 testing.expect((try powi(i42, -5, 7)) == -78125);126 try testing.expect((try powi(i42, -5, 7)) == -78125);
127127
128 testing.expect((try powi(u8, 6, 2)) == 36);128 try testing.expect((try powi(u8, 6, 2)) == 36);
129 testing.expect((try powi(u16, 5, 4)) == 625);129 try testing.expect((try powi(u16, 5, 4)) == 625);
130 testing.expect((try powi(u32, 12, 6)) == 2985984);130 try testing.expect((try powi(u32, 12, 6)) == 2985984);
131 testing.expect((try powi(u64, 34, 2)) == 1156);131 try testing.expect((try powi(u64, 34, 2)) == 1156);
132 testing.expect((try powi(u17, 16, 3)) == 4096);132 try testing.expect((try powi(u17, 16, 3)) == 4096);
133 testing.expect((try powi(u42, 34, 6)) == 1544804416);133 try testing.expect((try powi(u42, 34, 6)) == 1544804416);
134134
135 testing.expectError(error.Overflow, powi(i8, 120, 7));135 try testing.expectError(error.Overflow, powi(i8, 120, 7));
136 testing.expectError(error.Overflow, powi(i16, 73, 15));136 try testing.expectError(error.Overflow, powi(i16, 73, 15));
137 testing.expectError(error.Overflow, powi(i32, 23, 31));137 try testing.expectError(error.Overflow, powi(i32, 23, 31));
138 testing.expectError(error.Overflow, powi(i64, 68, 61));138 try testing.expectError(error.Overflow, powi(i64, 68, 61));
139 testing.expectError(error.Overflow, powi(i17, 15, 15));139 try testing.expectError(error.Overflow, powi(i17, 15, 15));
140 testing.expectError(error.Overflow, powi(i42, 121312, 41));140 try testing.expectError(error.Overflow, powi(i42, 121312, 41));
141141
142 testing.expectError(error.Overflow, powi(u8, 123, 7));142 try testing.expectError(error.Overflow, powi(u8, 123, 7));
143 testing.expectError(error.Overflow, powi(u16, 2313, 15));143 try testing.expectError(error.Overflow, powi(u16, 2313, 15));
144 testing.expectError(error.Overflow, powi(u32, 8968, 31));144 try testing.expectError(error.Overflow, powi(u32, 8968, 31));
145 testing.expectError(error.Overflow, powi(u64, 2342, 63));145 try testing.expectError(error.Overflow, powi(u64, 2342, 63));
146 testing.expectError(error.Overflow, powi(u17, 2723, 16));146 try testing.expectError(error.Overflow, powi(u17, 2723, 16));
147 testing.expectError(error.Overflow, powi(u42, 8234, 41));147 try testing.expectError(error.Overflow, powi(u42, 8234, 41));
148}148}
149149
150test "math.powi.special" {150test "math.powi.special" {
151 testing.expectError(error.Underflow, powi(i8, -2, 8));151 try testing.expectError(error.Underflow, powi(i8, -2, 8));
152 testing.expectError(error.Underflow, powi(i16, -2, 16));152 try testing.expectError(error.Underflow, powi(i16, -2, 16));
153 testing.expectError(error.Underflow, powi(i32, -2, 32));153 try testing.expectError(error.Underflow, powi(i32, -2, 32));
154 testing.expectError(error.Underflow, powi(i64, -2, 64));154 try testing.expectError(error.Underflow, powi(i64, -2, 64));
155 testing.expectError(error.Underflow, powi(i17, -2, 17));155 try testing.expectError(error.Underflow, powi(i17, -2, 17));
156 testing.expectError(error.Underflow, powi(i42, -2, 42));156 try testing.expectError(error.Underflow, powi(i42, -2, 42));
157157
158 testing.expect((try powi(i8, -1, 3)) == -1);158 try testing.expect((try powi(i8, -1, 3)) == -1);
159 testing.expect((try powi(i16, -1, 2)) == 1);159 try testing.expect((try powi(i16, -1, 2)) == 1);
160 testing.expect((try powi(i32, -1, 16)) == 1);160 try testing.expect((try powi(i32, -1, 16)) == 1);
161 testing.expect((try powi(i64, -1, 6)) == 1);161 try testing.expect((try powi(i64, -1, 6)) == 1);
162 testing.expect((try powi(i17, -1, 15)) == -1);162 try testing.expect((try powi(i17, -1, 15)) == -1);
163 testing.expect((try powi(i42, -1, 7)) == -1);163 try testing.expect((try powi(i42, -1, 7)) == -1);
164164
165 testing.expect((try powi(u8, 1, 2)) == 1);165 try testing.expect((try powi(u8, 1, 2)) == 1);
166 testing.expect((try powi(u16, 1, 4)) == 1);166 try testing.expect((try powi(u16, 1, 4)) == 1);
167 testing.expect((try powi(u32, 1, 6)) == 1);167 try testing.expect((try powi(u32, 1, 6)) == 1);
168 testing.expect((try powi(u64, 1, 2)) == 1);168 try testing.expect((try powi(u64, 1, 2)) == 1);
169 testing.expect((try powi(u17, 1, 3)) == 1);169 try testing.expect((try powi(u17, 1, 3)) == 1);
170 testing.expect((try powi(u42, 1, 6)) == 1);170 try testing.expect((try powi(u42, 1, 6)) == 1);
171171
172 testing.expectError(error.Overflow, powi(i8, 2, 7));172 try testing.expectError(error.Overflow, powi(i8, 2, 7));
173 testing.expectError(error.Overflow, powi(i16, 2, 15));173 try testing.expectError(error.Overflow, powi(i16, 2, 15));
174 testing.expectError(error.Overflow, powi(i32, 2, 31));174 try testing.expectError(error.Overflow, powi(i32, 2, 31));
175 testing.expectError(error.Overflow, powi(i64, 2, 63));175 try testing.expectError(error.Overflow, powi(i64, 2, 63));
176 testing.expectError(error.Overflow, powi(i17, 2, 16));176 try testing.expectError(error.Overflow, powi(i17, 2, 16));
177 testing.expectError(error.Overflow, powi(i42, 2, 41));177 try testing.expectError(error.Overflow, powi(i42, 2, 41));
178178
179 testing.expectError(error.Overflow, powi(u8, 2, 8));179 try testing.expectError(error.Overflow, powi(u8, 2, 8));
180 testing.expectError(error.Overflow, powi(u16, 2, 16));180 try testing.expectError(error.Overflow, powi(u16, 2, 16));
181 testing.expectError(error.Overflow, powi(u32, 2, 32));181 try testing.expectError(error.Overflow, powi(u32, 2, 32));
182 testing.expectError(error.Overflow, powi(u64, 2, 64));182 try testing.expectError(error.Overflow, powi(u64, 2, 64));
183 testing.expectError(error.Overflow, powi(u17, 2, 17));183 try testing.expectError(error.Overflow, powi(u17, 2, 17));
184 testing.expectError(error.Overflow, powi(u42, 2, 42));184 try testing.expectError(error.Overflow, powi(u42, 2, 42));
185185
186 testing.expect((try powi(u8, 6, 0)) == 1);186 try testing.expect((try powi(u8, 6, 0)) == 1);
187 testing.expect((try powi(u16, 5, 0)) == 1);187 try testing.expect((try powi(u16, 5, 0)) == 1);
188 testing.expect((try powi(u32, 12, 0)) == 1);188 try testing.expect((try powi(u32, 12, 0)) == 1);
189 testing.expect((try powi(u64, 34, 0)) == 1);189 try testing.expect((try powi(u64, 34, 0)) == 1);
190 testing.expect((try powi(u17, 16, 0)) == 1);190 try testing.expect((try powi(u17, 16, 0)) == 1);
191 testing.expect((try powi(u42, 34, 0)) == 1);191 try testing.expect((try powi(u42, 34, 0)) == 1);
192}192}
lib/std/math/round.zig+30-30
...@@ -129,52 +129,52 @@ fn round128(x_: f128) f128 {...@@ -129,52 +129,52 @@ fn round128(x_: f128) f128 {
129}129}
130130
131test "math.round" {131test "math.round" {
132 expect(round(@as(f32, 1.3)) == round32(1.3));132 try expect(round(@as(f32, 1.3)) == round32(1.3));
133 expect(round(@as(f64, 1.3)) == round64(1.3));133 try expect(round(@as(f64, 1.3)) == round64(1.3));
134 expect(round(@as(f128, 1.3)) == round128(1.3));134 try expect(round(@as(f128, 1.3)) == round128(1.3));
135}135}
136136
137test "math.round32" {137test "math.round32" {
138 expect(round32(1.3) == 1.0);138 try expect(round32(1.3) == 1.0);
139 expect(round32(-1.3) == -1.0);139 try expect(round32(-1.3) == -1.0);
140 expect(round32(0.2) == 0.0);140 try expect(round32(0.2) == 0.0);
141 expect(round32(1.8) == 2.0);141 try expect(round32(1.8) == 2.0);
142}142}
143143
144test "math.round64" {144test "math.round64" {
145 expect(round64(1.3) == 1.0);145 try expect(round64(1.3) == 1.0);
146 expect(round64(-1.3) == -1.0);146 try expect(round64(-1.3) == -1.0);
147 expect(round64(0.2) == 0.0);147 try expect(round64(0.2) == 0.0);
148 expect(round64(1.8) == 2.0);148 try expect(round64(1.8) == 2.0);
149}149}
150150
151test "math.round128" {151test "math.round128" {
152 expect(round128(1.3) == 1.0);152 try expect(round128(1.3) == 1.0);
153 expect(round128(-1.3) == -1.0);153 try expect(round128(-1.3) == -1.0);
154 expect(round128(0.2) == 0.0);154 try expect(round128(0.2) == 0.0);
155 expect(round128(1.8) == 2.0);155 try expect(round128(1.8) == 2.0);
156}156}
157157
158test "math.round32.special" {158test "math.round32.special" {
159 expect(round32(0.0) == 0.0);159 try expect(round32(0.0) == 0.0);
160 expect(round32(-0.0) == -0.0);160 try expect(round32(-0.0) == -0.0);
161 expect(math.isPositiveInf(round32(math.inf(f32))));161 try expect(math.isPositiveInf(round32(math.inf(f32))));
162 expect(math.isNegativeInf(round32(-math.inf(f32))));162 try expect(math.isNegativeInf(round32(-math.inf(f32))));
163 expect(math.isNan(round32(math.nan(f32))));163 try expect(math.isNan(round32(math.nan(f32))));
164}164}
165165
166test "math.round64.special" {166test "math.round64.special" {
167 expect(round64(0.0) == 0.0);167 try expect(round64(0.0) == 0.0);
168 expect(round64(-0.0) == -0.0);168 try expect(round64(-0.0) == -0.0);
169 expect(math.isPositiveInf(round64(math.inf(f64))));169 try expect(math.isPositiveInf(round64(math.inf(f64))));
170 expect(math.isNegativeInf(round64(-math.inf(f64))));170 try expect(math.isNegativeInf(round64(-math.inf(f64))));
171 expect(math.isNan(round64(math.nan(f64))));171 try expect(math.isNan(round64(math.nan(f64))));
172}172}
173173
174test "math.round128.special" {174test "math.round128.special" {
175 expect(round128(0.0) == 0.0);175 try expect(round128(0.0) == 0.0);
176 expect(round128(-0.0) == -0.0);176 try expect(round128(-0.0) == -0.0);
177 expect(math.isPositiveInf(round128(math.inf(f128))));177 try expect(math.isPositiveInf(round128(math.inf(f128))));
178 expect(math.isNegativeInf(round128(-math.inf(f128))));178 try expect(math.isNegativeInf(round128(-math.inf(f128))));
179 expect(math.isNan(round128(math.nan(f128))));179 try expect(math.isNan(round128(math.nan(f128))));
180}180}
lib/std/math/scalbn.zig+4-4
...@@ -84,14 +84,14 @@ fn scalbn64(x: f64, n_: i32) f64 {...@@ -84,14 +84,14 @@ fn scalbn64(x: f64, n_: i32) f64 {
84}84}
8585
86test "math.scalbn" {86test "math.scalbn" {
87 expect(scalbn(@as(f32, 1.5), 4) == scalbn32(1.5, 4));87 try expect(scalbn(@as(f32, 1.5), 4) == scalbn32(1.5, 4));
88 expect(scalbn(@as(f64, 1.5), 4) == scalbn64(1.5, 4));88 try expect(scalbn(@as(f64, 1.5), 4) == scalbn64(1.5, 4));
89}89}
9090
91test "math.scalbn32" {91test "math.scalbn32" {
92 expect(scalbn32(1.5, 4) == 24.0);92 try expect(scalbn32(1.5, 4) == 24.0);
93}93}
9494
95test "math.scalbn64" {95test "math.scalbn64" {
96 expect(scalbn64(1.5, 4) == 24.0);96 try expect(scalbn64(1.5, 4) == 24.0);
97}97}
lib/std/math/signbit.zig+12-12
...@@ -40,28 +40,28 @@ fn signbit128(x: f128) bool {...@@ -40,28 +40,28 @@ fn signbit128(x: f128) bool {
40}40}
4141
42test "math.signbit" {42test "math.signbit" {
43 expect(signbit(@as(f16, 4.0)) == signbit16(4.0));43 try expect(signbit(@as(f16, 4.0)) == signbit16(4.0));
44 expect(signbit(@as(f32, 4.0)) == signbit32(4.0));44 try expect(signbit(@as(f32, 4.0)) == signbit32(4.0));
45 expect(signbit(@as(f64, 4.0)) == signbit64(4.0));45 try expect(signbit(@as(f64, 4.0)) == signbit64(4.0));
46 expect(signbit(@as(f128, 4.0)) == signbit128(4.0));46 try expect(signbit(@as(f128, 4.0)) == signbit128(4.0));
47}47}
4848
49test "math.signbit16" {49test "math.signbit16" {
50 expect(!signbit16(4.0));50 try expect(!signbit16(4.0));
51 expect(signbit16(-3.0));51 try expect(signbit16(-3.0));
52}52}
5353
54test "math.signbit32" {54test "math.signbit32" {
55 expect(!signbit32(4.0));55 try expect(!signbit32(4.0));
56 expect(signbit32(-3.0));56 try expect(signbit32(-3.0));
57}57}
5858
59test "math.signbit64" {59test "math.signbit64" {
60 expect(!signbit64(4.0));60 try expect(!signbit64(4.0));
61 expect(signbit64(-3.0));61 try expect(signbit64(-3.0));
62}62}
6363
64test "math.signbit128" {64test "math.signbit128" {
65 expect(!signbit128(4.0));65 try expect(!signbit128(4.0));
66 expect(signbit128(-3.0));66 try expect(signbit128(-3.0));
67}67}
lib/std/math/sin.zig+27-27
...@@ -88,47 +88,47 @@ fn sin_(comptime T: type, x_: T) T {...@@ -88,47 +88,47 @@ fn sin_(comptime T: type, x_: T) T {
88}88}
8989
90test "math.sin" {90test "math.sin" {
91 expect(sin(@as(f32, 0.0)) == sin_(f32, 0.0));91 try expect(sin(@as(f32, 0.0)) == sin_(f32, 0.0));
92 expect(sin(@as(f64, 0.0)) == sin_(f64, 0.0));92 try expect(sin(@as(f64, 0.0)) == sin_(f64, 0.0));
93 expect(comptime (math.sin(@as(f64, 2))) == math.sin(@as(f64, 2)));93 try expect(comptime (math.sin(@as(f64, 2))) == math.sin(@as(f64, 2)));
94}94}
9595
96test "math.sin32" {96test "math.sin32" {
97 const epsilon = 0.000001;97 const epsilon = 0.000001;
9898
99 expect(math.approxEqAbs(f32, sin_(f32, 0.0), 0.0, epsilon));99 try expect(math.approxEqAbs(f32, sin_(f32, 0.0), 0.0, epsilon));
100 expect(math.approxEqAbs(f32, sin_(f32, 0.2), 0.198669, epsilon));100 try expect(math.approxEqAbs(f32, sin_(f32, 0.2), 0.198669, epsilon));
101 expect(math.approxEqAbs(f32, sin_(f32, 0.8923), 0.778517, epsilon));101 try expect(math.approxEqAbs(f32, sin_(f32, 0.8923), 0.778517, epsilon));
102 expect(math.approxEqAbs(f32, sin_(f32, 1.5), 0.997495, epsilon));102 try expect(math.approxEqAbs(f32, sin_(f32, 1.5), 0.997495, epsilon));
103 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 expect(math.approxEqAbs(f32, sin_(f32, 37.45), -0.246544, epsilon));104 try expect(math.approxEqAbs(f32, sin_(f32, 37.45), -0.246544, epsilon));
105 expect(math.approxEqAbs(f32, sin_(f32, 89.123), 0.916166, epsilon));105 try expect(math.approxEqAbs(f32, sin_(f32, 89.123), 0.916166, epsilon));
106}106}
107107
108test "math.sin64" {108test "math.sin64" {
109 const epsilon = 0.000001;109 const epsilon = 0.000001;
110110
111 expect(math.approxEqAbs(f64, sin_(f64, 0.0), 0.0, epsilon));111 try expect(math.approxEqAbs(f64, sin_(f64, 0.0), 0.0, epsilon));
112 expect(math.approxEqAbs(f64, sin_(f64, 0.2), 0.198669, epsilon));112 try expect(math.approxEqAbs(f64, sin_(f64, 0.2), 0.198669, epsilon));
113 expect(math.approxEqAbs(f64, sin_(f64, 0.8923), 0.778517, epsilon));113 try expect(math.approxEqAbs(f64, sin_(f64, 0.8923), 0.778517, epsilon));
114 expect(math.approxEqAbs(f64, sin_(f64, 1.5), 0.997495, epsilon));114 try expect(math.approxEqAbs(f64, sin_(f64, 1.5), 0.997495, epsilon));
115 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 expect(math.approxEqAbs(f64, sin_(f64, 37.45), -0.246543, epsilon));116 try expect(math.approxEqAbs(f64, sin_(f64, 37.45), -0.246543, epsilon));
117 expect(math.approxEqAbs(f64, sin_(f64, 89.123), 0.916166, epsilon));117 try expect(math.approxEqAbs(f64, sin_(f64, 89.123), 0.916166, epsilon));
118}118}
119119
120test "math.sin32.special" {120test "math.sin32.special" {
121 expect(sin_(f32, 0.0) == 0.0);121 try expect(sin_(f32, 0.0) == 0.0);
122 expect(sin_(f32, -0.0) == -0.0);122 try expect(sin_(f32, -0.0) == -0.0);
123 expect(math.isNan(sin_(f32, math.inf(f32))));123 try expect(math.isNan(sin_(f32, math.inf(f32))));
124 expect(math.isNan(sin_(f32, -math.inf(f32))));124 try expect(math.isNan(sin_(f32, -math.inf(f32))));
125 expect(math.isNan(sin_(f32, math.nan(f32))));125 try expect(math.isNan(sin_(f32, math.nan(f32))));
126}126}
127127
128test "math.sin64.special" {128test "math.sin64.special" {
129 expect(sin_(f64, 0.0) == 0.0);129 try expect(sin_(f64, 0.0) == 0.0);
130 expect(sin_(f64, -0.0) == -0.0);130 try expect(sin_(f64, -0.0) == -0.0);
131 expect(math.isNan(sin_(f64, math.inf(f64))));131 try expect(math.isNan(sin_(f64, math.inf(f64))));
132 expect(math.isNan(sin_(f64, -math.inf(f64))));132 try expect(math.isNan(sin_(f64, -math.inf(f64))));
133 expect(math.isNan(sin_(f64, math.nan(f64))));133 try expect(math.isNan(sin_(f64, math.nan(f64))));
134}134}
lib/std/math/sinh.zig+28-28
...@@ -97,48 +97,48 @@ fn sinh64(x: f64) f64 {...@@ -97,48 +97,48 @@ fn sinh64(x: f64) f64 {
97}97}
9898
99test "math.sinh" {99test "math.sinh" {
100 expect(sinh(@as(f32, 1.5)) == sinh32(1.5));100 try expect(sinh(@as(f32, 1.5)) == sinh32(1.5));
101 expect(sinh(@as(f64, 1.5)) == sinh64(1.5));101 try expect(sinh(@as(f64, 1.5)) == sinh64(1.5));
102}102}
103103
104test "math.sinh32" {104test "math.sinh32" {
105 const epsilon = 0.000001;105 const epsilon = 0.000001;
106106
107 expect(math.approxEqAbs(f32, sinh32(0.0), 0.0, epsilon));107 try expect(math.approxEqAbs(f32, sinh32(0.0), 0.0, epsilon));
108 expect(math.approxEqAbs(f32, sinh32(0.2), 0.201336, epsilon));108 try expect(math.approxEqAbs(f32, sinh32(0.2), 0.201336, epsilon));
109 expect(math.approxEqAbs(f32, sinh32(0.8923), 1.015512, epsilon));109 try expect(math.approxEqAbs(f32, sinh32(0.8923), 1.015512, epsilon));
110 expect(math.approxEqAbs(f32, sinh32(1.5), 2.129279, epsilon));110 try expect(math.approxEqAbs(f32, sinh32(1.5), 2.129279, epsilon));
111 expect(math.approxEqAbs(f32, sinh32(-0.0), -0.0, epsilon));111 try expect(math.approxEqAbs(f32, sinh32(-0.0), -0.0, epsilon));
112 expect(math.approxEqAbs(f32, sinh32(-0.2), -0.201336, epsilon));112 try expect(math.approxEqAbs(f32, sinh32(-0.2), -0.201336, epsilon));
113 expect(math.approxEqAbs(f32, sinh32(-0.8923), -1.015512, epsilon));113 try expect(math.approxEqAbs(f32, sinh32(-0.8923), -1.015512, epsilon));
114 expect(math.approxEqAbs(f32, sinh32(-1.5), -2.129279, epsilon));114 try expect(math.approxEqAbs(f32, sinh32(-1.5), -2.129279, epsilon));
115}115}
116116
117test "math.sinh64" {117test "math.sinh64" {
118 const epsilon = 0.000001;118 const epsilon = 0.000001;
119119
120 expect(math.approxEqAbs(f64, sinh64(0.0), 0.0, epsilon));120 try expect(math.approxEqAbs(f64, sinh64(0.0), 0.0, epsilon));
121 expect(math.approxEqAbs(f64, sinh64(0.2), 0.201336, epsilon));121 try expect(math.approxEqAbs(f64, sinh64(0.2), 0.201336, epsilon));
122 expect(math.approxEqAbs(f64, sinh64(0.8923), 1.015512, epsilon));122 try expect(math.approxEqAbs(f64, sinh64(0.8923), 1.015512, epsilon));
123 expect(math.approxEqAbs(f64, sinh64(1.5), 2.129279, epsilon));123 try expect(math.approxEqAbs(f64, sinh64(1.5), 2.129279, epsilon));
124 expect(math.approxEqAbs(f64, sinh64(-0.0), -0.0, epsilon));124 try expect(math.approxEqAbs(f64, sinh64(-0.0), -0.0, epsilon));
125 expect(math.approxEqAbs(f64, sinh64(-0.2), -0.201336, epsilon));125 try expect(math.approxEqAbs(f64, sinh64(-0.2), -0.201336, epsilon));
126 expect(math.approxEqAbs(f64, sinh64(-0.8923), -1.015512, epsilon));126 try expect(math.approxEqAbs(f64, sinh64(-0.8923), -1.015512, epsilon));
127 expect(math.approxEqAbs(f64, sinh64(-1.5), -2.129279, epsilon));127 try expect(math.approxEqAbs(f64, sinh64(-1.5), -2.129279, epsilon));
128}128}
129129
130test "math.sinh32.special" {130test "math.sinh32.special" {
131 expect(sinh32(0.0) == 0.0);131 try expect(sinh32(0.0) == 0.0);
132 expect(sinh32(-0.0) == -0.0);132 try expect(sinh32(-0.0) == -0.0);
133 expect(math.isPositiveInf(sinh32(math.inf(f32))));133 try expect(math.isPositiveInf(sinh32(math.inf(f32))));
134 expect(math.isNegativeInf(sinh32(-math.inf(f32))));134 try expect(math.isNegativeInf(sinh32(-math.inf(f32))));
135 expect(math.isNan(sinh32(math.nan(f32))));135 try expect(math.isNan(sinh32(math.nan(f32))));
136}136}
137137
138test "math.sinh64.special" {138test "math.sinh64.special" {
139 expect(sinh64(0.0) == 0.0);139 try expect(sinh64(0.0) == 0.0);
140 expect(sinh64(-0.0) == -0.0);140 try expect(sinh64(-0.0) == -0.0);
141 expect(math.isPositiveInf(sinh64(math.inf(f64))));141 try expect(math.isPositiveInf(sinh64(math.inf(f64))));
142 expect(math.isNegativeInf(sinh64(-math.inf(f64))));142 try expect(math.isNegativeInf(sinh64(-math.inf(f64))));
143 expect(math.isNan(sinh64(math.nan(f64))));143 try expect(math.isNan(sinh64(math.nan(f64))));
144}144}
lib/std/math/sqrt.zig+8-8
...@@ -68,14 +68,14 @@ fn sqrt_int(comptime T: type, value: T) Sqrt(T) {...@@ -68,14 +68,14 @@ fn sqrt_int(comptime T: type, value: T) Sqrt(T) {
68}68}
6969
70test "math.sqrt_int" {70test "math.sqrt_int" {
71 expect(sqrt_int(u0, 0) == 0);71 try expect(sqrt_int(u0, 0) == 0);
72 expect(sqrt_int(u1, 1) == 1);72 try expect(sqrt_int(u1, 1) == 1);
73 expect(sqrt_int(u32, 3) == 1);73 try expect(sqrt_int(u32, 3) == 1);
74 expect(sqrt_int(u32, 4) == 2);74 try expect(sqrt_int(u32, 4) == 2);
75 expect(sqrt_int(u32, 5) == 2);75 try expect(sqrt_int(u32, 5) == 2);
76 expect(sqrt_int(u32, 8) == 2);76 try expect(sqrt_int(u32, 8) == 2);
77 expect(sqrt_int(u32, 9) == 3);77 try expect(sqrt_int(u32, 9) == 3);
78 expect(sqrt_int(u32, 10) == 3);78 try expect(sqrt_int(u32, 10) == 3);
79}79}
8080
81/// Returns the return type `sqrt` will return given an operand of type `T`.81/// 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 {...@@ -79,44 +79,44 @@ fn tan_(comptime T: type, x_: T) T {
79}79}
8080
81test "math.tan" {81test "math.tan" {
82 expect(tan(@as(f32, 0.0)) == tan_(f32, 0.0));82 try expect(tan(@as(f32, 0.0)) == tan_(f32, 0.0));
83 expect(tan(@as(f64, 0.0)) == tan_(f64, 0.0));83 try expect(tan(@as(f64, 0.0)) == tan_(f64, 0.0));
84}84}
8585
86test "math.tan32" {86test "math.tan32" {
87 const epsilon = 0.000001;87 const epsilon = 0.000001;
8888
89 expect(math.approxEqAbs(f32, tan_(f32, 0.0), 0.0, epsilon));89 try expect(math.approxEqAbs(f32, tan_(f32, 0.0), 0.0, epsilon));
90 expect(math.approxEqAbs(f32, tan_(f32, 0.2), 0.202710, epsilon));90 try expect(math.approxEqAbs(f32, tan_(f32, 0.2), 0.202710, epsilon));
91 expect(math.approxEqAbs(f32, tan_(f32, 0.8923), 1.240422, epsilon));91 try expect(math.approxEqAbs(f32, tan_(f32, 0.8923), 1.240422, epsilon));
92 expect(math.approxEqAbs(f32, tan_(f32, 1.5), 14.101420, epsilon));92 try expect(math.approxEqAbs(f32, tan_(f32, 1.5), 14.101420, epsilon));
93 expect(math.approxEqAbs(f32, tan_(f32, 37.45), -0.254397, epsilon));93 try expect(math.approxEqAbs(f32, tan_(f32, 37.45), -0.254397, epsilon));
94 expect(math.approxEqAbs(f32, tan_(f32, 89.123), 2.285852, epsilon));94 try expect(math.approxEqAbs(f32, tan_(f32, 89.123), 2.285852, epsilon));
95}95}
9696
97test "math.tan64" {97test "math.tan64" {
98 const epsilon = 0.000001;98 const epsilon = 0.000001;
9999
100 expect(math.approxEqAbs(f64, tan_(f64, 0.0), 0.0, epsilon));100 try expect(math.approxEqAbs(f64, tan_(f64, 0.0), 0.0, epsilon));
101 expect(math.approxEqAbs(f64, tan_(f64, 0.2), 0.202710, epsilon));101 try expect(math.approxEqAbs(f64, tan_(f64, 0.2), 0.202710, epsilon));
102 expect(math.approxEqAbs(f64, tan_(f64, 0.8923), 1.240422, epsilon));102 try expect(math.approxEqAbs(f64, tan_(f64, 0.8923), 1.240422, epsilon));
103 expect(math.approxEqAbs(f64, tan_(f64, 1.5), 14.101420, epsilon));103 try expect(math.approxEqAbs(f64, tan_(f64, 1.5), 14.101420, epsilon));
104 expect(math.approxEqAbs(f64, tan_(f64, 37.45), -0.254397, epsilon));104 try expect(math.approxEqAbs(f64, tan_(f64, 37.45), -0.254397, epsilon));
105 expect(math.approxEqAbs(f64, tan_(f64, 89.123), 2.2858376, epsilon));105 try expect(math.approxEqAbs(f64, tan_(f64, 89.123), 2.2858376, epsilon));
106}106}
107107
108test "math.tan32.special" {108test "math.tan32.special" {
109 expect(tan_(f32, 0.0) == 0.0);109 try expect(tan_(f32, 0.0) == 0.0);
110 expect(tan_(f32, -0.0) == -0.0);110 try expect(tan_(f32, -0.0) == -0.0);
111 expect(math.isNan(tan_(f32, math.inf(f32))));111 try expect(math.isNan(tan_(f32, math.inf(f32))));
112 expect(math.isNan(tan_(f32, -math.inf(f32))));112 try expect(math.isNan(tan_(f32, -math.inf(f32))));
113 expect(math.isNan(tan_(f32, math.nan(f32))));113 try expect(math.isNan(tan_(f32, math.nan(f32))));
114}114}
115115
116test "math.tan64.special" {116test "math.tan64.special" {
117 expect(tan_(f64, 0.0) == 0.0);117 try expect(tan_(f64, 0.0) == 0.0);
118 expect(tan_(f64, -0.0) == -0.0);118 try expect(tan_(f64, -0.0) == -0.0);
119 expect(math.isNan(tan_(f64, math.inf(f64))));119 try expect(math.isNan(tan_(f64, math.inf(f64))));
120 expect(math.isNan(tan_(f64, -math.inf(f64))));120 try expect(math.isNan(tan_(f64, -math.inf(f64))));
121 expect(math.isNan(tan_(f64, math.nan(f64))));121 try expect(math.isNan(tan_(f64, math.nan(f64))));
122}122}
lib/std/math/tanh.zig+22-22
...@@ -123,42 +123,42 @@ fn tanh64(x: f64) f64 {...@@ -123,42 +123,42 @@ fn tanh64(x: f64) f64 {
123}123}
124124
125test "math.tanh" {125test "math.tanh" {
126 expect(tanh(@as(f32, 1.5)) == tanh32(1.5));126 try expect(tanh(@as(f32, 1.5)) == tanh32(1.5));
127 expect(tanh(@as(f64, 1.5)) == tanh64(1.5));127 try expect(tanh(@as(f64, 1.5)) == tanh64(1.5));
128}128}
129129
130test "math.tanh32" {130test "math.tanh32" {
131 const epsilon = 0.000001;131 const epsilon = 0.000001;
132132
133 expect(math.approxEqAbs(f32, tanh32(0.0), 0.0, epsilon));133 try expect(math.approxEqAbs(f32, tanh32(0.0), 0.0, epsilon));
134 expect(math.approxEqAbs(f32, tanh32(0.2), 0.197375, epsilon));134 try expect(math.approxEqAbs(f32, tanh32(0.2), 0.197375, epsilon));
135 expect(math.approxEqAbs(f32, tanh32(0.8923), 0.712528, epsilon));135 try expect(math.approxEqAbs(f32, tanh32(0.8923), 0.712528, epsilon));
136 expect(math.approxEqAbs(f32, tanh32(1.5), 0.905148, epsilon));136 try expect(math.approxEqAbs(f32, tanh32(1.5), 0.905148, epsilon));
137 expect(math.approxEqAbs(f32, tanh32(37.45), 1.0, epsilon));137 try expect(math.approxEqAbs(f32, tanh32(37.45), 1.0, epsilon));
138}138}
139139
140test "math.tanh64" {140test "math.tanh64" {
141 const epsilon = 0.000001;141 const epsilon = 0.000001;
142142
143 expect(math.approxEqAbs(f64, tanh64(0.0), 0.0, epsilon));143 try expect(math.approxEqAbs(f64, tanh64(0.0), 0.0, epsilon));
144 expect(math.approxEqAbs(f64, tanh64(0.2), 0.197375, epsilon));144 try expect(math.approxEqAbs(f64, tanh64(0.2), 0.197375, epsilon));
145 expect(math.approxEqAbs(f64, tanh64(0.8923), 0.712528, epsilon));145 try expect(math.approxEqAbs(f64, tanh64(0.8923), 0.712528, epsilon));
146 expect(math.approxEqAbs(f64, tanh64(1.5), 0.905148, epsilon));146 try expect(math.approxEqAbs(f64, tanh64(1.5), 0.905148, epsilon));
147 expect(math.approxEqAbs(f64, tanh64(37.45), 1.0, epsilon));147 try expect(math.approxEqAbs(f64, tanh64(37.45), 1.0, epsilon));
148}148}
149149
150test "math.tanh32.special" {150test "math.tanh32.special" {
151 expect(tanh32(0.0) == 0.0);151 try expect(tanh32(0.0) == 0.0);
152 expect(tanh32(-0.0) == -0.0);152 try expect(tanh32(-0.0) == -0.0);
153 expect(tanh32(math.inf(f32)) == 1.0);153 try expect(tanh32(math.inf(f32)) == 1.0);
154 expect(tanh32(-math.inf(f32)) == -1.0);154 try expect(tanh32(-math.inf(f32)) == -1.0);
155 expect(math.isNan(tanh32(math.nan(f32))));155 try expect(math.isNan(tanh32(math.nan(f32))));
156}156}
157157
158test "math.tanh64.special" {158test "math.tanh64.special" {
159 expect(tanh64(0.0) == 0.0);159 try expect(tanh64(0.0) == 0.0);
160 expect(tanh64(-0.0) == -0.0);160 try expect(tanh64(-0.0) == -0.0);
161 expect(tanh64(math.inf(f64)) == 1.0);161 try expect(tanh64(math.inf(f64)) == 1.0);
162 expect(tanh64(-math.inf(f64)) == -1.0);162 try expect(tanh64(-math.inf(f64)) == -1.0);
163 expect(math.isNan(tanh64(math.nan(f64))));163 try expect(math.isNan(tanh64(math.nan(f64))));
164}164}
lib/std/math/trunc.zig+27-27
...@@ -94,49 +94,49 @@ fn trunc128(x: f128) f128 {...@@ -94,49 +94,49 @@ fn trunc128(x: f128) f128 {
94}94}
9595
96test "math.trunc" {96test "math.trunc" {
97 expect(trunc(@as(f32, 1.3)) == trunc32(1.3));97 try expect(trunc(@as(f32, 1.3)) == trunc32(1.3));
98 expect(trunc(@as(f64, 1.3)) == trunc64(1.3));98 try expect(trunc(@as(f64, 1.3)) == trunc64(1.3));
99 expect(trunc(@as(f128, 1.3)) == trunc128(1.3));99 try expect(trunc(@as(f128, 1.3)) == trunc128(1.3));
100}100}
101101
102test "math.trunc32" {102test "math.trunc32" {
103 expect(trunc32(1.3) == 1.0);103 try expect(trunc32(1.3) == 1.0);
104 expect(trunc32(-1.3) == -1.0);104 try expect(trunc32(-1.3) == -1.0);
105 expect(trunc32(0.2) == 0.0);105 try expect(trunc32(0.2) == 0.0);
106}106}
107107
108test "math.trunc64" {108test "math.trunc64" {
109 expect(trunc64(1.3) == 1.0);109 try expect(trunc64(1.3) == 1.0);
110 expect(trunc64(-1.3) == -1.0);110 try expect(trunc64(-1.3) == -1.0);
111 expect(trunc64(0.2) == 0.0);111 try expect(trunc64(0.2) == 0.0);
112}112}
113113
114test "math.trunc128" {114test "math.trunc128" {
115 expect(trunc128(1.3) == 1.0);115 try expect(trunc128(1.3) == 1.0);
116 expect(trunc128(-1.3) == -1.0);116 try expect(trunc128(-1.3) == -1.0);
117 expect(trunc128(0.2) == 0.0);117 try expect(trunc128(0.2) == 0.0);
118}118}
119119
120test "math.trunc32.special" {120test "math.trunc32.special" {
121 expect(trunc32(0.0) == 0.0); // 0x3F800000121 try expect(trunc32(0.0) == 0.0); // 0x3F800000
122 expect(trunc32(-0.0) == -0.0);122 try expect(trunc32(-0.0) == -0.0);
123 expect(math.isPositiveInf(trunc32(math.inf(f32))));123 try expect(math.isPositiveInf(trunc32(math.inf(f32))));
124 expect(math.isNegativeInf(trunc32(-math.inf(f32))));124 try expect(math.isNegativeInf(trunc32(-math.inf(f32))));
125 expect(math.isNan(trunc32(math.nan(f32))));125 try expect(math.isNan(trunc32(math.nan(f32))));
126}126}
127127
128test "math.trunc64.special" {128test "math.trunc64.special" {
129 expect(trunc64(0.0) == 0.0);129 try expect(trunc64(0.0) == 0.0);
130 expect(trunc64(-0.0) == -0.0);130 try expect(trunc64(-0.0) == -0.0);
131 expect(math.isPositiveInf(trunc64(math.inf(f64))));131 try expect(math.isPositiveInf(trunc64(math.inf(f64))));
132 expect(math.isNegativeInf(trunc64(-math.inf(f64))));132 try expect(math.isNegativeInf(trunc64(-math.inf(f64))));
133 expect(math.isNan(trunc64(math.nan(f64))));133 try expect(math.isNan(trunc64(math.nan(f64))));
134}134}
135135
136test "math.trunc128.special" {136test "math.trunc128.special" {
137 expect(trunc128(0.0) == 0.0);137 try expect(trunc128(0.0) == 0.0);
138 expect(trunc128(-0.0) == -0.0);138 try expect(trunc128(-0.0) == -0.0);
139 expect(math.isPositiveInf(trunc128(math.inf(f128))));139 try expect(math.isPositiveInf(trunc128(math.inf(f128))));
140 expect(math.isNegativeInf(trunc128(-math.inf(f128))));140 try expect(math.isNegativeInf(trunc128(-math.inf(f128))));
141 expect(math.isNan(trunc128(math.nan(f128))));141 try expect(math.isNan(trunc128(math.nan(f128))));
142}142}
lib/std/mem.zig+359-359
...@@ -143,8 +143,8 @@ fn failAllocatorAlloc(self: *Allocator, n: usize, alignment: u29, len_align: u29...@@ -143,8 +143,8 @@ fn failAllocatorAlloc(self: *Allocator, n: usize, alignment: u29, len_align: u29
143}143}
144144
145test "mem.Allocator basics" {145test "mem.Allocator basics" {
146 testing.expectError(error.OutOfMemory, failAllocator.alloc(u8, 1));146 try testing.expectError(error.OutOfMemory, failAllocator.alloc(u8, 1));
147 testing.expectError(error.OutOfMemory, failAllocator.allocSentinel(u8, 1, 0));147 try testing.expectError(error.OutOfMemory, failAllocator.allocSentinel(u8, 1, 0));
148}148}
149149
150/// Copy all of source into dest at position 0.150/// Copy all of source into dest at position 0.
...@@ -277,8 +277,8 @@ test "mem.zeroes" {...@@ -277,8 +277,8 @@ test "mem.zeroes" {
277 var a = zeroes(C_struct);277 var a = zeroes(C_struct);
278 a.y += 10;278 a.y += 10;
279279
280 testing.expect(a.x == 0);280 try testing.expect(a.x == 0);
281 testing.expect(a.y == 10);281 try testing.expect(a.y == 10);
282282
283 const ZigStruct = struct {283 const ZigStruct = struct {
284 integral_types: struct {284 integral_types: struct {
...@@ -315,32 +315,32 @@ test "mem.zeroes" {...@@ -315,32 +315,32 @@ test "mem.zeroes" {
315 };315 };
316316
317 const b = zeroes(ZigStruct);317 const b = zeroes(ZigStruct);
318 testing.expectEqual(@as(i8, 0), b.integral_types.integer_0);318 try testing.expectEqual(@as(i8, 0), b.integral_types.integer_0);
319 testing.expectEqual(@as(i8, 0), b.integral_types.integer_8);319 try testing.expectEqual(@as(i8, 0), b.integral_types.integer_8);
320 testing.expectEqual(@as(i16, 0), b.integral_types.integer_16);320 try testing.expectEqual(@as(i16, 0), b.integral_types.integer_16);
321 testing.expectEqual(@as(i32, 0), b.integral_types.integer_32);321 try testing.expectEqual(@as(i32, 0), b.integral_types.integer_32);
322 testing.expectEqual(@as(i64, 0), b.integral_types.integer_64);322 try testing.expectEqual(@as(i64, 0), b.integral_types.integer_64);
323 testing.expectEqual(@as(i128, 0), b.integral_types.integer_128);323 try testing.expectEqual(@as(i128, 0), b.integral_types.integer_128);
324 testing.expectEqual(@as(u8, 0), b.integral_types.unsigned_0);324 try testing.expectEqual(@as(u8, 0), b.integral_types.unsigned_0);
325 testing.expectEqual(@as(u8, 0), b.integral_types.unsigned_8);325 try testing.expectEqual(@as(u8, 0), b.integral_types.unsigned_8);
326 testing.expectEqual(@as(u16, 0), b.integral_types.unsigned_16);326 try testing.expectEqual(@as(u16, 0), b.integral_types.unsigned_16);
327 testing.expectEqual(@as(u32, 0), b.integral_types.unsigned_32);327 try testing.expectEqual(@as(u32, 0), b.integral_types.unsigned_32);
328 testing.expectEqual(@as(u64, 0), b.integral_types.unsigned_64);328 try testing.expectEqual(@as(u64, 0), b.integral_types.unsigned_64);
329 testing.expectEqual(@as(u128, 0), b.integral_types.unsigned_128);329 try testing.expectEqual(@as(u128, 0), b.integral_types.unsigned_128);
330 testing.expectEqual(@as(f32, 0), b.integral_types.float_32);330 try testing.expectEqual(@as(f32, 0), b.integral_types.float_32);
331 testing.expectEqual(@as(f64, 0), b.integral_types.float_64);331 try testing.expectEqual(@as(f64, 0), b.integral_types.float_64);
332 testing.expectEqual(@as(?*u8, null), b.pointers.optional);332 try testing.expectEqual(@as(?*u8, null), b.pointers.optional);
333 testing.expectEqual(@as([*c]u8, null), b.pointers.c_pointer);333 try testing.expectEqual(@as([*c]u8, null), b.pointers.c_pointer);
334 testing.expectEqual(@as([]u8, &[_]u8{}), b.pointers.slice);334 try testing.expectEqual(@as([]u8, &[_]u8{}), b.pointers.slice);
335 for (b.array) |e| {335 for (b.array) |e| {
336 testing.expectEqual(@as(u32, 0), e);336 try testing.expectEqual(@as(u32, 0), e);
337 }337 }
338 testing.expectEqual(@splat(2, @as(u32, 0)), b.vector_u32);338 try testing.expectEqual(@splat(2, @as(u32, 0)), b.vector_u32);
339 testing.expectEqual(@splat(2, @as(f32, 0.0)), b.vector_f32);339 try testing.expectEqual(@splat(2, @as(f32, 0.0)), b.vector_f32);
340 testing.expectEqual(@splat(2, @as(bool, false)), b.vector_bool);340 try testing.expectEqual(@splat(2, @as(bool, false)), b.vector_bool);
341 testing.expectEqual(@as(?u8, null), b.optional_int);341 try testing.expectEqual(@as(?u8, null), b.optional_int);
342 for (b.sentinel) |e| {342 for (b.sentinel) |e| {
343 testing.expectEqual(@as(u8, 0), e);343 try testing.expectEqual(@as(u8, 0), e);
344 }344 }
345345
346 const C_union = extern union {346 const C_union = extern union {
...@@ -349,7 +349,7 @@ test "mem.zeroes" {...@@ -349,7 +349,7 @@ test "mem.zeroes" {
349 };349 };
350350
351 var c = zeroes(C_union);351 var c = zeroes(C_union);
352 testing.expectEqual(@as(u8, 0), c.a);352 try testing.expectEqual(@as(u8, 0), c.a);
353}353}
354354
355/// Initializes all fields of the struct with their default value, or zero values if no default value is present.355/// 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" {...@@ -422,7 +422,7 @@ test "zeroInit" {
422 .a = 42,422 .a = 42,
423 });423 });
424424
425 testing.expectEqual(S{425 try testing.expectEqual(S{
426 .a = 42,426 .a = 42,
427 .b = null,427 .b = null,
428 .c = .{428 .c = .{
...@@ -440,7 +440,7 @@ test "zeroInit" {...@@ -440,7 +440,7 @@ test "zeroInit" {
440 };440 };
441441
442 const c = zeroInit(Color, .{ 255, 255 });442 const c = zeroInit(Color, .{ 255, 255 });
443 testing.expectEqual(Color{443 try testing.expectEqual(Color{
444 .r = 255,444 .r = 255,
445 .g = 255,445 .g = 255,
446 .b = 0,446 .b = 0,
...@@ -463,11 +463,11 @@ pub fn order(comptime T: type, lhs: []const T, rhs: []const T) math.Order {...@@ -463,11 +463,11 @@ pub fn order(comptime T: type, lhs: []const T, rhs: []const T) math.Order {
463}463}
464464
465test "order" {465test "order" {
466 testing.expect(order(u8, "abcd", "bee") == .lt);466 try testing.expect(order(u8, "abcd", "bee") == .lt);
467 testing.expect(order(u8, "abc", "abc") == .eq);467 try testing.expect(order(u8, "abc", "abc") == .eq);
468 testing.expect(order(u8, "abc", "abc0") == .lt);468 try testing.expect(order(u8, "abc", "abc0") == .lt);
469 testing.expect(order(u8, "", "") == .eq);469 try testing.expect(order(u8, "", "") == .eq);
470 testing.expect(order(u8, "", "a") == .lt);470 try testing.expect(order(u8, "", "a") == .lt);
471}471}
472472
473/// Returns true if lhs < rhs, false otherwise473/// Returns true if lhs < rhs, false otherwise
...@@ -476,11 +476,11 @@ pub fn lessThan(comptime T: type, lhs: []const T, rhs: []const T) bool {...@@ -476,11 +476,11 @@ pub fn lessThan(comptime T: type, lhs: []const T, rhs: []const T) bool {
476}476}
477477
478test "mem.lessThan" {478test "mem.lessThan" {
479 testing.expect(lessThan(u8, "abcd", "bee"));479 try testing.expect(lessThan(u8, "abcd", "bee"));
480 testing.expect(!lessThan(u8, "abc", "abc"));480 try testing.expect(!lessThan(u8, "abc", "abc"));
481 testing.expect(lessThan(u8, "abc", "abc0"));481 try testing.expect(lessThan(u8, "abc", "abc0"));
482 testing.expect(!lessThan(u8, "", ""));482 try testing.expect(!lessThan(u8, "", ""));
483 testing.expect(lessThan(u8, "", "a"));483 try testing.expect(lessThan(u8, "", "a"));
484}484}
485485
486/// Compares two slices and returns whether they are equal.486/// 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 {...@@ -505,11 +505,11 @@ pub fn indexOfDiff(comptime T: type, a: []const T, b: []const T) ?usize {
505}505}
506506
507test "indexOfDiff" {507test "indexOfDiff" {
508 testing.expectEqual(indexOfDiff(u8, "one", "one"), null);508 try testing.expectEqual(indexOfDiff(u8, "one", "one"), null);
509 testing.expectEqual(indexOfDiff(u8, "one two", "one"), 3);509 try testing.expectEqual(indexOfDiff(u8, "one two", "one"), 3);
510 testing.expectEqual(indexOfDiff(u8, "one", "one two"), 3);510 try testing.expectEqual(indexOfDiff(u8, "one", "one two"), 3);
511 testing.expectEqual(indexOfDiff(u8, "one twx", "one two"), 6);511 try testing.expectEqual(indexOfDiff(u8, "one twx", "one two"), 6);
512 testing.expectEqual(indexOfDiff(u8, "xne", "one"), 0);512 try testing.expectEqual(indexOfDiff(u8, "xne", "one"), 0);
513}513}
514514
515pub const toSliceConst = @compileError("deprecated; use std.mem.spanZ");515pub const toSliceConst = @compileError("deprecated; use std.mem.spanZ");
...@@ -549,26 +549,26 @@ pub fn Span(comptime T: type) type {...@@ -549,26 +549,26 @@ pub fn Span(comptime T: type) type {
549}549}
550550
551test "Span" {551test "Span" {
552 testing.expect(Span(*[5]u16) == []u16);552 try testing.expect(Span(*[5]u16) == []u16);
553 testing.expect(Span(?*[5]u16) == ?[]u16);553 try testing.expect(Span(?*[5]u16) == ?[]u16);
554 testing.expect(Span(*const [5]u16) == []const u16);554 try testing.expect(Span(*const [5]u16) == []const u16);
555 testing.expect(Span(?*const [5]u16) == ?[]const u16);555 try testing.expect(Span(?*const [5]u16) == ?[]const u16);
556 testing.expect(Span([]u16) == []u16);556 try testing.expect(Span([]u16) == []u16);
557 testing.expect(Span(?[]u16) == ?[]u16);557 try testing.expect(Span(?[]u16) == ?[]u16);
558 testing.expect(Span([]const u8) == []const u8);558 try testing.expect(Span([]const u8) == []const u8);
559 testing.expect(Span(?[]const u8) == ?[]const u8);559 try testing.expect(Span(?[]const u8) == ?[]const u8);
560 testing.expect(Span([:1]u16) == [:1]u16);560 try testing.expect(Span([:1]u16) == [:1]u16);
561 testing.expect(Span(?[:1]u16) == ?[:1]u16);561 try testing.expect(Span(?[:1]u16) == ?[:1]u16);
562 testing.expect(Span([:1]const u8) == [:1]const u8);562 try testing.expect(Span([:1]const u8) == [:1]const u8);
563 testing.expect(Span(?[:1]const u8) == ?[:1]const u8);563 try testing.expect(Span(?[:1]const u8) == ?[:1]const u8);
564 testing.expect(Span([*:1]u16) == [:1]u16);564 try testing.expect(Span([*:1]u16) == [:1]u16);
565 testing.expect(Span(?[*:1]u16) == ?[:1]u16);565 try testing.expect(Span(?[*:1]u16) == ?[:1]u16);
566 testing.expect(Span([*:1]const u8) == [:1]const u8);566 try testing.expect(Span([*:1]const u8) == [:1]const u8);
567 testing.expect(Span(?[*:1]const u8) == ?[:1]const u8);567 try testing.expect(Span(?[*:1]const u8) == ?[:1]const u8);
568 testing.expect(Span([*c]u16) == [:0]u16);568 try testing.expect(Span([*c]u16) == [:0]u16);
569 testing.expect(Span(?[*c]u16) == ?[:0]u16);569 try testing.expect(Span(?[*c]u16) == ?[:0]u16);
570 testing.expect(Span([*c]const u8) == [:0]const u8);570 try testing.expect(Span([*c]const u8) == [:0]const u8);
571 testing.expect(Span(?[*c]const u8) == ?[:0]const u8);571 try testing.expect(Span(?[*c]const u8) == ?[:0]const u8);
572}572}
573573
574/// Takes a pointer to an array, a sentinel-terminated pointer, or a slice, and574/// 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)) {...@@ -598,9 +598,9 @@ pub fn span(ptr: anytype) Span(@TypeOf(ptr)) {
598test "span" {598test "span" {
599 var array: [5]u16 = [_]u16{ 1, 2, 3, 4, 5 };599 var array: [5]u16 = [_]u16{ 1, 2, 3, 4, 5 };
600 const ptr = @as([*:3]u16, array[0..2 :3]);600 const ptr = @as([*:3]u16, array[0..2 :3]);
601 testing.expect(eql(u16, span(ptr), &[_]u16{ 1, 2 }));601 try testing.expect(eql(u16, span(ptr), &[_]u16{ 1, 2 }));
602 testing.expect(eql(u16, span(&array), &[_]u16{ 1, 2, 3, 4, 5 }));602 try testing.expect(eql(u16, span(&array), &[_]u16{ 1, 2, 3, 4, 5 }));
603 testing.expectEqual(@as(?[:0]u16, null), span(@as(?[*:0]u16, null)));603 try testing.expectEqual(@as(?[:0]u16, null), span(@as(?[*:0]u16, null)));
604}604}
605605
606/// Same as `span`, except when there is both a sentinel and an array606/// 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)) {...@@ -626,9 +626,9 @@ pub fn spanZ(ptr: anytype) Span(@TypeOf(ptr)) {
626test "spanZ" {626test "spanZ" {
627 var array: [5]u16 = [_]u16{ 1, 2, 3, 4, 5 };627 var array: [5]u16 = [_]u16{ 1, 2, 3, 4, 5 };
628 const ptr = @as([*:3]u16, array[0..2 :3]);628 const ptr = @as([*:3]u16, array[0..2 :3]);
629 testing.expect(eql(u16, spanZ(ptr), &[_]u16{ 1, 2 }));629 try testing.expect(eql(u16, spanZ(ptr), &[_]u16{ 1, 2 }));
630 testing.expect(eql(u16, spanZ(&array), &[_]u16{ 1, 2, 3, 4, 5 }));630 try testing.expect(eql(u16, spanZ(&array), &[_]u16{ 1, 2, 3, 4, 5 }));
631 testing.expectEqual(@as(?[:0]u16, null), spanZ(@as(?[*:0]u16, null)));631 try testing.expectEqual(@as(?[:0]u16, null), spanZ(@as(?[*:0]u16, null)));
632}632}
633633
634/// Takes a pointer to an array, an array, a vector, a sentinel-terminated pointer,634/// Takes a pointer to an array, an array, a vector, a sentinel-terminated pointer,
...@@ -662,30 +662,30 @@ pub fn len(value: anytype) usize {...@@ -662,30 +662,30 @@ pub fn len(value: anytype) usize {
662}662}
663663
664test "len" {664test "len" {
665 testing.expect(len("aoeu") == 4);665 try testing.expect(len("aoeu") == 4);
666666
667 {667 {
668 var array: [5]u16 = [_]u16{ 1, 2, 3, 4, 5 };668 var array: [5]u16 = [_]u16{ 1, 2, 3, 4, 5 };
669 testing.expect(len(&array) == 5);669 try testing.expect(len(&array) == 5);
670 testing.expect(len(array[0..3]) == 3);670 try testing.expect(len(array[0..3]) == 3);
671 array[2] = 0;671 array[2] = 0;
672 const ptr = @as([*:0]u16, array[0..2 :0]);672 const ptr = @as([*:0]u16, array[0..2 :0]);
673 testing.expect(len(ptr) == 2);673 try testing.expect(len(ptr) == 2);
674 }674 }
675 {675 {
676 var array: [5:0]u16 = [_:0]u16{ 1, 2, 3, 4, 5 };676 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);
678 array[2] = 0;678 array[2] = 0;
679 testing.expect(len(&array) == 5);679 try testing.expect(len(&array) == 5);
680 }680 }
681 {681 {
682 const vector: meta.Vector(2, u32) = [2]u32{ 1, 2 };682 const vector: meta.Vector(2, u32) = [2]u32{ 1, 2 };
683 testing.expect(len(vector) == 2);683 try testing.expect(len(vector) == 2);
684 }684 }
685 {685 {
686 const tuple = .{ 1, 2 };686 const tuple = .{ 1, 2 };
687 testing.expect(len(tuple) == 2);687 try testing.expect(len(tuple) == 2);
688 testing.expect(tuple[0] == 1);688 try testing.expect(tuple[0] == 1);
689 }689 }
690}690}
691691
...@@ -726,21 +726,21 @@ pub fn lenZ(ptr: anytype) usize {...@@ -726,21 +726,21 @@ pub fn lenZ(ptr: anytype) usize {
726}726}
727727
728test "lenZ" {728test "lenZ" {
729 testing.expect(lenZ("aoeu") == 4);729 try testing.expect(lenZ("aoeu") == 4);
730730
731 {731 {
732 var array: [5]u16 = [_]u16{ 1, 2, 3, 4, 5 };732 var array: [5]u16 = [_]u16{ 1, 2, 3, 4, 5 };
733 testing.expect(lenZ(&array) == 5);733 try testing.expect(lenZ(&array) == 5);
734 testing.expect(lenZ(array[0..3]) == 3);734 try testing.expect(lenZ(array[0..3]) == 3);
735 array[2] = 0;735 array[2] = 0;
736 const ptr = @as([*:0]u16, array[0..2 :0]);736 const ptr = @as([*:0]u16, array[0..2 :0]);
737 testing.expect(lenZ(ptr) == 2);737 try testing.expect(lenZ(ptr) == 2);
738 }738 }
739 {739 {
740 var array: [5:0]u16 = [_:0]u16{ 1, 2, 3, 4, 5 };740 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);
742 array[2] = 0;742 array[2] = 0;
743 testing.expect(lenZ(&array) == 2);743 try testing.expect(lenZ(&array) == 2);
744 }744 }
745}745}
746746
...@@ -794,10 +794,10 @@ pub fn trim(comptime T: type, slice: []const T, values_to_strip: []const T) []co...@@ -794,10 +794,10 @@ pub fn trim(comptime T: type, slice: []const T, values_to_strip: []const T) []co
794}794}
795795
796test "mem.trim" {796test "mem.trim" {
797 testing.expectEqualSlices(u8, "foo\n ", trimLeft(u8, " foo\n ", " \n"));797 try testing.expectEqualSlices(u8, "foo\n ", trimLeft(u8, " foo\n ", " \n"));
798 testing.expectEqualSlices(u8, " foo", trimRight(u8, " foo\n ", " \n"));798 try testing.expectEqualSlices(u8, " foo", trimRight(u8, " foo\n ", " \n"));
799 testing.expectEqualSlices(u8, "foo", trim(u8, " foo\n ", " \n"));799 try testing.expectEqualSlices(u8, "foo", trim(u8, " foo\n ", " \n"));
800 testing.expectEqualSlices(u8, "foo", trim(u8, "foo", " \n"));800 try testing.expectEqualSlices(u8, "foo", trim(u8, "foo", " \n"));
801}801}
802802
803/// Linear search for the index of a scalar value inside a slice.803/// 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...@@ -952,28 +952,28 @@ pub fn indexOfPos(comptime T: type, haystack: []const T, start_index: usize, nee
952}952}
953953
954test "mem.indexOf" {954test "mem.indexOf" {
955 testing.expect(indexOf(u8, "one two three four five six seven eight nine ten eleven", "three four").? == 8);955 try 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);956 try 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);957 try 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);958 try testing.expect(lastIndexOf(u8, "one two three four five six seven eight nine ten eleven", "two two") == null);
959959
960 testing.expect(indexOf(u8, "one two three four five six seven eight nine ten", "").? == 0);960 try 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);961 try testing.expect(lastIndexOf(u8, "one two three four five six seven eight nine ten", "").? == 48);
962962
963 testing.expect(indexOf(u8, "one two three four", "four").? == 14);963 try testing.expect(indexOf(u8, "one two three four", "four").? == 14);
964 testing.expect(lastIndexOf(u8, "one two three two four", "two").? == 14);964 try testing.expect(lastIndexOf(u8, "one two three two four", "two").? == 14);
965 testing.expect(indexOf(u8, "one two three four", "gour") == null);965 try testing.expect(indexOf(u8, "one two three four", "gour") == null);
966 testing.expect(lastIndexOf(u8, "one two three four", "gour") == null);966 try testing.expect(lastIndexOf(u8, "one two three four", "gour") == null);
967 testing.expect(indexOf(u8, "foo", "foo").? == 0);967 try testing.expect(indexOf(u8, "foo", "foo").? == 0);
968 testing.expect(lastIndexOf(u8, "foo", "foo").? == 0);968 try testing.expect(lastIndexOf(u8, "foo", "foo").? == 0);
969 testing.expect(indexOf(u8, "foo", "fool") == null);969 try testing.expect(indexOf(u8, "foo", "fool") == null);
970 testing.expect(lastIndexOf(u8, "foo", "lfoo") == null);970 try testing.expect(lastIndexOf(u8, "foo", "lfoo") == null);
971 testing.expect(lastIndexOf(u8, "foo", "fool") == null);971 try testing.expect(lastIndexOf(u8, "foo", "fool") == null);
972972
973 testing.expect(indexOf(u8, "foo foo", "foo").? == 0);973 try testing.expect(indexOf(u8, "foo foo", "foo").? == 0);
974 testing.expect(lastIndexOf(u8, "foo foo", "foo").? == 4);974 try testing.expect(lastIndexOf(u8, "foo foo", "foo").? == 4);
975 testing.expect(lastIndexOfAny(u8, "boo, cat", "abo").? == 6);975 try testing.expect(lastIndexOfAny(u8, "boo, cat", "abo").? == 6);
976 testing.expect(lastIndexOfScalar(u8, "boo", 'o').? == 2);976 try testing.expect(lastIndexOfScalar(u8, "boo", 'o').? == 2);
977}977}
978978
979/// Returns the number of needles inside the haystack979/// 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 {...@@ -993,17 +993,17 @@ pub fn count(comptime T: type, haystack: []const T, needle: []const T) usize {
993}993}
994994
995test "mem.count" {995test "mem.count" {
996 testing.expect(count(u8, "", "h") == 0);996 try testing.expect(count(u8, "", "h") == 0);
997 testing.expect(count(u8, "h", "h") == 1);997 try testing.expect(count(u8, "h", "h") == 1);
998 testing.expect(count(u8, "hh", "h") == 2);998 try testing.expect(count(u8, "hh", "h") == 2);
999 testing.expect(count(u8, "world!", "hello") == 0);999 try testing.expect(count(u8, "world!", "hello") == 0);
1000 testing.expect(count(u8, "hello world!", "hello") == 1);1000 try testing.expect(count(u8, "hello world!", "hello") == 1);
1001 testing.expect(count(u8, " abcabc abc", "abc") == 3);1001 try testing.expect(count(u8, " abcabc abc", "abc") == 3);
1002 testing.expect(count(u8, "udexdcbvbruhasdrw", "bruh") == 1);1002 try testing.expect(count(u8, "udexdcbvbruhasdrw", "bruh") == 1);
1003 testing.expect(count(u8, "foo bar", "o bar") == 1);1003 try testing.expect(count(u8, "foo bar", "o bar") == 1);
1004 testing.expect(count(u8, "foofoofoo", "foo") == 3);1004 try testing.expect(count(u8, "foofoofoo", "foo") == 3);
1005 testing.expect(count(u8, "fffffff", "ff") == 3);1005 try testing.expect(count(u8, "fffffff", "ff") == 3);
1006 testing.expect(count(u8, "owowowu", "owowu") == 1);1006 try testing.expect(count(u8, "owowowu", "owowu") == 1);
1007}1007}
10081008
1009/// Returns true if the haystack contains expected_count or more needles1009/// 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...@@ -1025,19 +1025,19 @@ pub fn containsAtLeast(comptime T: type, haystack: []const T, expected_count: us
1025}1025}
10261026
1027test "mem.containsAtLeast" {1027test "mem.containsAtLeast" {
1028 testing.expect(containsAtLeast(u8, "aa", 0, "a"));1028 try testing.expect(containsAtLeast(u8, "aa", 0, "a"));
1029 testing.expect(containsAtLeast(u8, "aa", 1, "a"));1029 try testing.expect(containsAtLeast(u8, "aa", 1, "a"));
1030 testing.expect(containsAtLeast(u8, "aa", 2, "a"));1030 try testing.expect(containsAtLeast(u8, "aa", 2, "a"));
1031 testing.expect(!containsAtLeast(u8, "aa", 3, "a"));1031 try testing.expect(!containsAtLeast(u8, "aa", 3, "a"));
10321032
1033 testing.expect(containsAtLeast(u8, "radaradar", 1, "radar"));1033 try testing.expect(containsAtLeast(u8, "radaradar", 1, "radar"));
1034 testing.expect(!containsAtLeast(u8, "radaradar", 2, "radar"));1034 try testing.expect(!containsAtLeast(u8, "radaradar", 2, "radar"));
10351035
1036 testing.expect(containsAtLeast(u8, "radarradaradarradar", 3, "radar"));1036 try testing.expect(containsAtLeast(u8, "radarradaradarradar", 3, "radar"));
1037 testing.expect(!containsAtLeast(u8, "radarradaradarradar", 4, "radar"));1037 try testing.expect(!containsAtLeast(u8, "radarradaradarradar", 4, "radar"));
10381038
1039 testing.expect(containsAtLeast(u8, " radar radar ", 2, "radar"));1039 try testing.expect(containsAtLeast(u8, " radar radar ", 2, "radar"));
1040 testing.expect(!containsAtLeast(u8, " radar radar ", 3, "radar"));1040 try testing.expect(!containsAtLeast(u8, " radar radar ", 3, "radar"));
1041}1041}
10421042
1043/// Reads an integer from memory with size equal to bytes.len.1043/// Reads an integer from memory with size equal to bytes.len.
...@@ -1142,34 +1142,34 @@ test "comptime read/write int" {...@@ -1142,34 +1142,34 @@ test "comptime read/write int" {
1142 var bytes: [2]u8 = undefined;1142 var bytes: [2]u8 = undefined;
1143 writeIntLittle(u16, &bytes, 0x1234);1143 writeIntLittle(u16, &bytes, 0x1234);
1144 const result = readIntBig(u16, &bytes);1144 const result = readIntBig(u16, &bytes);
1145 testing.expect(result == 0x3412);1145 try testing.expect(result == 0x3412);
1146 }1146 }
1147 comptime {1147 comptime {
1148 var bytes: [2]u8 = undefined;1148 var bytes: [2]u8 = undefined;
1149 writeIntBig(u16, &bytes, 0x1234);1149 writeIntBig(u16, &bytes, 0x1234);
1150 const result = readIntLittle(u16, &bytes);1150 const result = readIntLittle(u16, &bytes);
1151 testing.expect(result == 0x3412);1151 try testing.expect(result == 0x3412);
1152 }1152 }
1153}1153}
11541154
1155test "readIntBig and readIntLittle" {1155test "readIntBig and readIntLittle" {
1156 testing.expect(readIntSliceBig(u0, &[_]u8{}) == 0x0);1156 try testing.expect(readIntSliceBig(u0, &[_]u8{}) == 0x0);
1157 testing.expect(readIntSliceLittle(u0, &[_]u8{}) == 0x0);1157 try testing.expect(readIntSliceLittle(u0, &[_]u8{}) == 0x0);
11581158
1159 testing.expect(readIntSliceBig(u8, &[_]u8{0x32}) == 0x32);1159 try testing.expect(readIntSliceBig(u8, &[_]u8{0x32}) == 0x32);
1160 testing.expect(readIntSliceLittle(u8, &[_]u8{0x12}) == 0x12);1160 try testing.expect(readIntSliceLittle(u8, &[_]u8{0x12}) == 0x12);
11611161
1162 testing.expect(readIntSliceBig(u16, &[_]u8{ 0x12, 0x34 }) == 0x1234);1162 try testing.expect(readIntSliceBig(u16, &[_]u8{ 0x12, 0x34 }) == 0x1234);
1163 testing.expect(readIntSliceLittle(u16, &[_]u8{ 0x12, 0x34 }) == 0x3412);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);1165 try 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);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);1168 try testing.expect(readIntSliceBig(i8, &[_]u8{0xff}) == -1);
1169 testing.expect(readIntSliceLittle(i8, &[_]u8{0xfe}) == -2);1169 try testing.expect(readIntSliceLittle(i8, &[_]u8{0xfe}) == -2);
11701170
1171 testing.expect(readIntSliceBig(i16, &[_]u8{ 0xff, 0xfd }) == -3);1171 try testing.expect(readIntSliceBig(i16, &[_]u8{ 0xff, 0xfd }) == -3);
1172 testing.expect(readIntSliceLittle(i16, &[_]u8{ 0xfc, 0xff }) == -4);1172 try testing.expect(readIntSliceLittle(i16, &[_]u8{ 0xfc, 0xff }) == -4);
1173}1173}
11741174
1175/// Writes an integer to memory, storing it in twos-complement.1175/// Writes an integer to memory, storing it in twos-complement.
...@@ -1284,34 +1284,34 @@ test "writeIntBig and writeIntLittle" {...@@ -1284,34 +1284,34 @@ test "writeIntBig and writeIntLittle" {
1284 var buf9: [9]u8 = undefined;1284 var buf9: [9]u8 = undefined;
12851285
1286 writeIntBig(u0, &buf0, 0x0);1286 writeIntBig(u0, &buf0, 0x0);
1287 testing.expect(eql(u8, buf0[0..], &[_]u8{}));1287 try testing.expect(eql(u8, buf0[0..], &[_]u8{}));
1288 writeIntLittle(u0, &buf0, 0x0);1288 writeIntLittle(u0, &buf0, 0x0);
1289 testing.expect(eql(u8, buf0[0..], &[_]u8{}));1289 try testing.expect(eql(u8, buf0[0..], &[_]u8{}));
12901290
1291 writeIntBig(u8, &buf1, 0x12);1291 writeIntBig(u8, &buf1, 0x12);
1292 testing.expect(eql(u8, buf1[0..], &[_]u8{0x12}));1292 try testing.expect(eql(u8, buf1[0..], &[_]u8{0x12}));
1293 writeIntLittle(u8, &buf1, 0x34);1293 writeIntLittle(u8, &buf1, 0x34);
1294 testing.expect(eql(u8, buf1[0..], &[_]u8{0x34}));1294 try testing.expect(eql(u8, buf1[0..], &[_]u8{0x34}));
12951295
1296 writeIntBig(u16, &buf2, 0x1234);1296 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 }));
1298 writeIntLittle(u16, &buf2, 0x5678);1298 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
1301 writeIntBig(u72, &buf9, 0x123456789abcdef024);1301 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 }));
1303 writeIntLittle(u72, &buf9, 0xfedcba9876543210ec);1303 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
1306 writeIntBig(i8, &buf1, -1);1306 writeIntBig(i8, &buf1, -1);
1307 testing.expect(eql(u8, buf1[0..], &[_]u8{0xff}));1307 try testing.expect(eql(u8, buf1[0..], &[_]u8{0xff}));
1308 writeIntLittle(i8, &buf1, -2);1308 writeIntLittle(i8, &buf1, -2);
1309 testing.expect(eql(u8, buf1[0..], &[_]u8{0xfe}));1309 try testing.expect(eql(u8, buf1[0..], &[_]u8{0xfe}));
13101310
1311 writeIntBig(i16, &buf2, -3);1311 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 }));
1313 writeIntLittle(i16, &buf2, -4);1313 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 }));
1315}1315}
13161316
1317/// Returns an iterator that iterates over the slices of `buffer` that are not1317/// 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 {...@@ -1332,60 +1332,60 @@ pub fn tokenize(buffer: []const u8, delimiter_bytes: []const u8) TokenIterator {
13321332
1333test "mem.tokenize" {1333test "mem.tokenize" {
1334 var it = tokenize(" abc def ghi ", " ");1334 var it = tokenize(" abc def ghi ", " ");
1335 testing.expect(eql(u8, it.next().?, "abc"));1335 try testing.expect(eql(u8, it.next().?, "abc"));
1336 testing.expect(eql(u8, it.next().?, "def"));1336 try testing.expect(eql(u8, it.next().?, "def"));
1337 testing.expect(eql(u8, it.next().?, "ghi"));1337 try testing.expect(eql(u8, it.next().?, "ghi"));
1338 testing.expect(it.next() == null);1338 try testing.expect(it.next() == null);
13391339
1340 it = tokenize("..\\bob", "\\");1340 it = tokenize("..\\bob", "\\");
1341 testing.expect(eql(u8, it.next().?, ".."));1341 try testing.expect(eql(u8, it.next().?, ".."));
1342 testing.expect(eql(u8, "..", "..\\bob"[0..it.index]));1342 try testing.expect(eql(u8, "..", "..\\bob"[0..it.index]));
1343 testing.expect(eql(u8, it.next().?, "bob"));1343 try testing.expect(eql(u8, it.next().?, "bob"));
1344 testing.expect(it.next() == null);1344 try testing.expect(it.next() == null);
13451345
1346 it = tokenize("//a/b", "/");1346 it = tokenize("//a/b", "/");
1347 testing.expect(eql(u8, it.next().?, "a"));1347 try testing.expect(eql(u8, it.next().?, "a"));
1348 testing.expect(eql(u8, it.next().?, "b"));1348 try testing.expect(eql(u8, it.next().?, "b"));
1349 testing.expect(eql(u8, "//a/b", "//a/b"[0..it.index]));1349 try testing.expect(eql(u8, "//a/b", "//a/b"[0..it.index]));
1350 testing.expect(it.next() == null);1350 try testing.expect(it.next() == null);
13511351
1352 it = tokenize("|", "|");1352 it = tokenize("|", "|");
1353 testing.expect(it.next() == null);1353 try testing.expect(it.next() == null);
13541354
1355 it = tokenize("", "|");1355 it = tokenize("", "|");
1356 testing.expect(it.next() == null);1356 try testing.expect(it.next() == null);
13571357
1358 it = tokenize("hello", "");1358 it = tokenize("hello", "");
1359 testing.expect(eql(u8, it.next().?, "hello"));1359 try testing.expect(eql(u8, it.next().?, "hello"));
1360 testing.expect(it.next() == null);1360 try testing.expect(it.next() == null);
13611361
1362 it = tokenize("hello", " ");1362 it = tokenize("hello", " ");
1363 testing.expect(eql(u8, it.next().?, "hello"));1363 try testing.expect(eql(u8, it.next().?, "hello"));
1364 testing.expect(it.next() == null);1364 try testing.expect(it.next() == null);
1365}1365}
13661366
1367test "mem.tokenize (multibyte)" {1367test "mem.tokenize (multibyte)" {
1368 var it = tokenize("a|b,c/d e", " /,|");1368 var it = tokenize("a|b,c/d e", " /,|");
1369 testing.expect(eql(u8, it.next().?, "a"));1369 try testing.expect(eql(u8, it.next().?, "a"));
1370 testing.expect(eql(u8, it.next().?, "b"));1370 try testing.expect(eql(u8, it.next().?, "b"));
1371 testing.expect(eql(u8, it.next().?, "c"));1371 try testing.expect(eql(u8, it.next().?, "c"));
1372 testing.expect(eql(u8, it.next().?, "d"));1372 try testing.expect(eql(u8, it.next().?, "d"));
1373 testing.expect(eql(u8, it.next().?, "e"));1373 try testing.expect(eql(u8, it.next().?, "e"));
1374 testing.expect(it.next() == null);1374 try testing.expect(it.next() == null);
1375}1375}
13761376
1377test "mem.tokenize (reset)" {1377test "mem.tokenize (reset)" {
1378 var it = tokenize(" abc def ghi ", " ");1378 var it = tokenize(" abc def ghi ", " ");
1379 testing.expect(eql(u8, it.next().?, "abc"));1379 try testing.expect(eql(u8, it.next().?, "abc"));
1380 testing.expect(eql(u8, it.next().?, "def"));1380 try testing.expect(eql(u8, it.next().?, "def"));
1381 testing.expect(eql(u8, it.next().?, "ghi"));1381 try testing.expect(eql(u8, it.next().?, "ghi"));
13821382
1383 it.reset();1383 it.reset();
13841384
1385 testing.expect(eql(u8, it.next().?, "abc"));1385 try testing.expect(eql(u8, it.next().?, "abc"));
1386 testing.expect(eql(u8, it.next().?, "def"));1386 try testing.expect(eql(u8, it.next().?, "def"));
1387 testing.expect(eql(u8, it.next().?, "ghi"));1387 try testing.expect(eql(u8, it.next().?, "ghi"));
1388 testing.expect(it.next() == null);1388 try testing.expect(it.next() == null);
1389}1389}
13901390
1391/// Returns an iterator that iterates over the slices of `buffer` that1391/// 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...@@ -1409,34 +1409,34 @@ pub const separate = @compileError("deprecated: renamed to split (behavior remai
14091409
1410test "mem.split" {1410test "mem.split" {
1411 var it = split("abc|def||ghi", "|");1411 var it = split("abc|def||ghi", "|");
1412 testing.expect(eql(u8, it.next().?, "abc"));1412 try testing.expect(eql(u8, it.next().?, "abc"));
1413 testing.expect(eql(u8, it.next().?, "def"));1413 try testing.expect(eql(u8, it.next().?, "def"));
1414 testing.expect(eql(u8, it.next().?, ""));1414 try testing.expect(eql(u8, it.next().?, ""));
1415 testing.expect(eql(u8, it.next().?, "ghi"));1415 try testing.expect(eql(u8, it.next().?, "ghi"));
1416 testing.expect(it.next() == null);1416 try testing.expect(it.next() == null);
14171417
1418 it = split("", "|");1418 it = split("", "|");
1419 testing.expect(eql(u8, it.next().?, ""));1419 try testing.expect(eql(u8, it.next().?, ""));
1420 testing.expect(it.next() == null);1420 try testing.expect(it.next() == null);
14211421
1422 it = split("|", "|");1422 it = split("|", "|");
1423 testing.expect(eql(u8, it.next().?, ""));1423 try testing.expect(eql(u8, it.next().?, ""));
1424 testing.expect(eql(u8, it.next().?, ""));1424 try testing.expect(eql(u8, it.next().?, ""));
1425 testing.expect(it.next() == null);1425 try testing.expect(it.next() == null);
14261426
1427 it = split("hello", " ");1427 it = split("hello", " ");
1428 testing.expect(eql(u8, it.next().?, "hello"));1428 try testing.expect(eql(u8, it.next().?, "hello"));
1429 testing.expect(it.next() == null);1429 try testing.expect(it.next() == null);
1430}1430}
14311431
1432test "mem.split (multibyte)" {1432test "mem.split (multibyte)" {
1433 var it = split("a, b ,, c, d, e", ", ");1433 var it = split("a, b ,, c, d, e", ", ");
1434 testing.expect(eql(u8, it.next().?, "a"));1434 try testing.expect(eql(u8, it.next().?, "a"));
1435 testing.expect(eql(u8, it.next().?, "b ,"));1435 try testing.expect(eql(u8, it.next().?, "b ,"));
1436 testing.expect(eql(u8, it.next().?, "c"));1436 try testing.expect(eql(u8, it.next().?, "c"));
1437 testing.expect(eql(u8, it.next().?, "d"));1437 try testing.expect(eql(u8, it.next().?, "d"));
1438 testing.expect(eql(u8, it.next().?, "e"));1438 try testing.expect(eql(u8, it.next().?, "e"));
1439 testing.expect(it.next() == null);1439 try testing.expect(it.next() == null);
1440}1440}
14411441
1442pub fn startsWith(comptime T: type, haystack: []const T, needle: []const T) bool {1442pub 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...@@ -1444,8 +1444,8 @@ pub fn startsWith(comptime T: type, haystack: []const T, needle: []const T) bool
1444}1444}
14451445
1446test "mem.startsWith" {1446test "mem.startsWith" {
1447 testing.expect(startsWith(u8, "Bob", "Bo"));1447 try testing.expect(startsWith(u8, "Bob", "Bo"));
1448 testing.expect(!startsWith(u8, "Needle in haystack", "haystack"));1448 try testing.expect(!startsWith(u8, "Needle in haystack", "haystack"));
1449}1449}
14501450
1451pub fn endsWith(comptime T: type, haystack: []const T, needle: []const T) bool {1451pub 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 {...@@ -1453,8 +1453,8 @@ pub fn endsWith(comptime T: type, haystack: []const T, needle: []const T) bool {
1453}1453}
14541454
1455test "mem.endsWith" {1455test "mem.endsWith" {
1456 testing.expect(endsWith(u8, "Needle in haystack", "haystack"));1456 try testing.expect(endsWith(u8, "Needle in haystack", "haystack"));
1457 testing.expect(!endsWith(u8, "Bob", "Bo"));1457 try testing.expect(!endsWith(u8, "Bob", "Bo"));
1458}1458}
14591459
1460pub const TokenIterator = struct {1460pub const TokenIterator = struct {
...@@ -1572,22 +1572,22 @@ test "mem.join" {...@@ -1572,22 +1572,22 @@ test "mem.join" {
1572 {1572 {
1573 const str = try join(testing.allocator, ",", &[_][]const u8{});1573 const str = try join(testing.allocator, ",", &[_][]const u8{});
1574 defer testing.allocator.free(str);1574 defer testing.allocator.free(str);
1575 testing.expect(eql(u8, str, ""));1575 try testing.expect(eql(u8, str, ""));
1576 }1576 }
1577 {1577 {
1578 const str = try join(testing.allocator, ",", &[_][]const u8{ "a", "b", "c" });1578 const str = try join(testing.allocator, ",", &[_][]const u8{ "a", "b", "c" });
1579 defer testing.allocator.free(str);1579 defer testing.allocator.free(str);
1580 testing.expect(eql(u8, str, "a,b,c"));1580 try testing.expect(eql(u8, str, "a,b,c"));
1581 }1581 }
1582 {1582 {
1583 const str = try join(testing.allocator, ",", &[_][]const u8{"a"});1583 const str = try join(testing.allocator, ",", &[_][]const u8{"a"});
1584 defer testing.allocator.free(str);1584 defer testing.allocator.free(str);
1585 testing.expect(eql(u8, str, "a"));1585 try testing.expect(eql(u8, str, "a"));
1586 }1586 }
1587 {1587 {
1588 const str = try join(testing.allocator, ",", &[_][]const u8{ "a", "", "b", "", "c" });1588 const str = try join(testing.allocator, ",", &[_][]const u8{ "a", "", "b", "", "c" });
1589 defer testing.allocator.free(str);1589 defer testing.allocator.free(str);
1590 testing.expect(eql(u8, str, "a,,b,,c"));1590 try testing.expect(eql(u8, str, "a,,b,,c"));
1591 }1591 }
1592}1592}
15931593
...@@ -1595,26 +1595,26 @@ test "mem.joinZ" {...@@ -1595,26 +1595,26 @@ test "mem.joinZ" {
1595 {1595 {
1596 const str = try joinZ(testing.allocator, ",", &[_][]const u8{});1596 const str = try joinZ(testing.allocator, ",", &[_][]const u8{});
1597 defer testing.allocator.free(str);1597 defer testing.allocator.free(str);
1598 testing.expect(eql(u8, str, ""));1598 try testing.expect(eql(u8, str, ""));
1599 testing.expectEqual(str[str.len], 0);1599 try testing.expectEqual(str[str.len], 0);
1600 }1600 }
1601 {1601 {
1602 const str = try joinZ(testing.allocator, ",", &[_][]const u8{ "a", "b", "c" });1602 const str = try joinZ(testing.allocator, ",", &[_][]const u8{ "a", "b", "c" });
1603 defer testing.allocator.free(str);1603 defer testing.allocator.free(str);
1604 testing.expect(eql(u8, str, "a,b,c"));1604 try testing.expect(eql(u8, str, "a,b,c"));
1605 testing.expectEqual(str[str.len], 0);1605 try testing.expectEqual(str[str.len], 0);
1606 }1606 }
1607 {1607 {
1608 const str = try joinZ(testing.allocator, ",", &[_][]const u8{"a"});1608 const str = try joinZ(testing.allocator, ",", &[_][]const u8{"a"});
1609 defer testing.allocator.free(str);1609 defer testing.allocator.free(str);
1610 testing.expect(eql(u8, str, "a"));1610 try testing.expect(eql(u8, str, "a"));
1611 testing.expectEqual(str[str.len], 0);1611 try testing.expectEqual(str[str.len], 0);
1612 }1612 }
1613 {1613 {
1614 const str = try joinZ(testing.allocator, ",", &[_][]const u8{ "a", "", "b", "", "c" });1614 const str = try joinZ(testing.allocator, ",", &[_][]const u8{ "a", "", "b", "", "c" });
1615 defer testing.allocator.free(str);1615 defer testing.allocator.free(str);
1616 testing.expect(eql(u8, str, "a,,b,,c"));1616 try testing.expect(eql(u8, str, "a,,b,,c"));
1617 testing.expectEqual(str[str.len], 0);1617 try testing.expectEqual(str[str.len], 0);
1618 }1618 }
1619}1619}
16201620
...@@ -1647,7 +1647,7 @@ test "concat" {...@@ -1647,7 +1647,7 @@ test "concat" {
1647 {1647 {
1648 const str = try concat(testing.allocator, u8, &[_][]const u8{ "abc", "def", "ghi" });1648 const str = try concat(testing.allocator, u8, &[_][]const u8{ "abc", "def", "ghi" });
1649 defer testing.allocator.free(str);1649 defer testing.allocator.free(str);
1650 testing.expect(eql(u8, str, "abcdefghi"));1650 try testing.expect(eql(u8, str, "abcdefghi"));
1651 }1651 }
1652 {1652 {
1653 const str = try concat(testing.allocator, u32, &[_][]const u32{1653 const str = try concat(testing.allocator, u32, &[_][]const u32{
...@@ -1657,21 +1657,21 @@ test "concat" {...@@ -1657,21 +1657,21 @@ test "concat" {
1657 &[_]u32{5},1657 &[_]u32{5},
1658 });1658 });
1659 defer testing.allocator.free(str);1659 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 }));
1661 }1661 }
1662}1662}
16631663
1664test "testStringEquality" {1664test "testStringEquality" {
1665 testing.expect(eql(u8, "abcd", "abcd"));1665 try testing.expect(eql(u8, "abcd", "abcd"));
1666 testing.expect(!eql(u8, "abcdef", "abZdef"));1666 try testing.expect(!eql(u8, "abcdef", "abZdef"));
1667 testing.expect(!eql(u8, "abcdefg", "abcdef"));1667 try testing.expect(!eql(u8, "abcdefg", "abcdef"));
1668}1668}
16691669
1670test "testReadInt" {1670test "testReadInt" {
1671 testReadIntImpl();1671 try testReadIntImpl();
1672 comptime testReadIntImpl();1672 comptime try testReadIntImpl();
1673}1673}
1674fn testReadIntImpl() void {1674fn testReadIntImpl() !void {
1675 {1675 {
1676 const bytes = [_]u8{1676 const bytes = [_]u8{
1677 0x12,1677 0x12,
...@@ -1679,12 +1679,12 @@ fn testReadIntImpl() void {...@@ -1679,12 +1679,12 @@ fn testReadIntImpl() void {
1679 0x56,1679 0x56,
1680 0x78,1680 0x78,
1681 };1681 };
1682 testing.expect(readInt(u32, &bytes, Endian.Big) == 0x12345678);1682 try testing.expect(readInt(u32, &bytes, Endian.Big) == 0x12345678);
1683 testing.expect(readIntBig(u32, &bytes) == 0x12345678);1683 try testing.expect(readIntBig(u32, &bytes) == 0x12345678);
1684 testing.expect(readIntBig(i32, &bytes) == 0x12345678);1684 try testing.expect(readIntBig(i32, &bytes) == 0x12345678);
1685 testing.expect(readInt(u32, &bytes, Endian.Little) == 0x78563412);1685 try testing.expect(readInt(u32, &bytes, Endian.Little) == 0x78563412);
1686 testing.expect(readIntLittle(u32, &bytes) == 0x78563412);1686 try testing.expect(readIntLittle(u32, &bytes) == 0x78563412);
1687 testing.expect(readIntLittle(i32, &bytes) == 0x78563412);1687 try testing.expect(readIntLittle(i32, &bytes) == 0x78563412);
1688 }1688 }
1689 {1689 {
1690 const buf = [_]u8{1690 const buf = [_]u8{
...@@ -1694,7 +1694,7 @@ fn testReadIntImpl() void {...@@ -1694,7 +1694,7 @@ fn testReadIntImpl() void {
1694 0x34,1694 0x34,
1695 };1695 };
1696 const answer = readInt(u32, &buf, Endian.Big);1696 const answer = readInt(u32, &buf, Endian.Big);
1697 testing.expect(answer == 0x00001234);1697 try testing.expect(answer == 0x00001234);
1698 }1698 }
1699 {1699 {
1700 const buf = [_]u8{1700 const buf = [_]u8{
...@@ -1704,41 +1704,41 @@ fn testReadIntImpl() void {...@@ -1704,41 +1704,41 @@ fn testReadIntImpl() void {
1704 0x00,1704 0x00,
1705 };1705 };
1706 const answer = readInt(u32, &buf, Endian.Little);1706 const answer = readInt(u32, &buf, Endian.Little);
1707 testing.expect(answer == 0x00003412);1707 try testing.expect(answer == 0x00003412);
1708 }1708 }
1709 {1709 {
1710 const bytes = [_]u8{1710 const bytes = [_]u8{
1711 0xff,1711 0xff,
1712 0xfe,1712 0xfe,
1713 };1713 };
1714 testing.expect(readIntBig(u16, &bytes) == 0xfffe);1714 try testing.expect(readIntBig(u16, &bytes) == 0xfffe);
1715 testing.expect(readIntBig(i16, &bytes) == -0x0002);1715 try testing.expect(readIntBig(i16, &bytes) == -0x0002);
1716 testing.expect(readIntLittle(u16, &bytes) == 0xfeff);1716 try testing.expect(readIntLittle(u16, &bytes) == 0xfeff);
1717 testing.expect(readIntLittle(i16, &bytes) == -0x0101);1717 try testing.expect(readIntLittle(i16, &bytes) == -0x0101);
1718 }1718 }
1719}1719}
17201720
1721test "writeIntSlice" {1721test "writeIntSlice" {
1722 testWriteIntImpl();1722 try testWriteIntImpl();
1723 comptime testWriteIntImpl();1723 comptime try testWriteIntImpl();
1724}1724}
1725fn testWriteIntImpl() void {1725fn testWriteIntImpl() !void {
1726 var bytes: [8]u8 = undefined;1726 var bytes: [8]u8 = undefined;
17271727
1728 writeIntSlice(u0, bytes[0..], 0, Endian.Big);1728 writeIntSlice(u0, bytes[0..], 0, Endian.Big);
1729 testing.expect(eql(u8, &bytes, &[_]u8{1729 try testing.expect(eql(u8, &bytes, &[_]u8{
1730 0x00, 0x00, 0x00, 0x00,1730 0x00, 0x00, 0x00, 0x00,
1731 0x00, 0x00, 0x00, 0x00,1731 0x00, 0x00, 0x00, 0x00,
1732 }));1732 }));
17331733
1734 writeIntSlice(u0, bytes[0..], 0, Endian.Little);1734 writeIntSlice(u0, bytes[0..], 0, Endian.Little);
1735 testing.expect(eql(u8, &bytes, &[_]u8{1735 try testing.expect(eql(u8, &bytes, &[_]u8{
1736 0x00, 0x00, 0x00, 0x00,1736 0x00, 0x00, 0x00, 0x00,
1737 0x00, 0x00, 0x00, 0x00,1737 0x00, 0x00, 0x00, 0x00,
1738 }));1738 }));
17391739
1740 writeIntSlice(u64, bytes[0..], 0x12345678CAFEBABE, Endian.Big);1740 writeIntSlice(u64, bytes[0..], 0x12345678CAFEBABE, Endian.Big);
1741 testing.expect(eql(u8, &bytes, &[_]u8{1741 try testing.expect(eql(u8, &bytes, &[_]u8{
1742 0x12,1742 0x12,
1743 0x34,1743 0x34,
1744 0x56,1744 0x56,
...@@ -1750,7 +1750,7 @@ fn testWriteIntImpl() void {...@@ -1750,7 +1750,7 @@ fn testWriteIntImpl() void {
1750 }));1750 }));
17511751
1752 writeIntSlice(u64, bytes[0..], 0xBEBAFECA78563412, Endian.Little);1752 writeIntSlice(u64, bytes[0..], 0xBEBAFECA78563412, Endian.Little);
1753 testing.expect(eql(u8, &bytes, &[_]u8{1753 try testing.expect(eql(u8, &bytes, &[_]u8{
1754 0x12,1754 0x12,
1755 0x34,1755 0x34,
1756 0x56,1756 0x56,
...@@ -1762,7 +1762,7 @@ fn testWriteIntImpl() void {...@@ -1762,7 +1762,7 @@ fn testWriteIntImpl() void {
1762 }));1762 }));
17631763
1764 writeIntSlice(u32, bytes[0..], 0x12345678, Endian.Big);1764 writeIntSlice(u32, bytes[0..], 0x12345678, Endian.Big);
1765 testing.expect(eql(u8, &bytes, &[_]u8{1765 try testing.expect(eql(u8, &bytes, &[_]u8{
1766 0x00,1766 0x00,
1767 0x00,1767 0x00,
1768 0x00,1768 0x00,
...@@ -1774,7 +1774,7 @@ fn testWriteIntImpl() void {...@@ -1774,7 +1774,7 @@ fn testWriteIntImpl() void {
1774 }));1774 }));
17751775
1776 writeIntSlice(u32, bytes[0..], 0x78563412, Endian.Little);1776 writeIntSlice(u32, bytes[0..], 0x78563412, Endian.Little);
1777 testing.expect(eql(u8, &bytes, &[_]u8{1777 try testing.expect(eql(u8, &bytes, &[_]u8{
1778 0x12,1778 0x12,
1779 0x34,1779 0x34,
1780 0x56,1780 0x56,
...@@ -1786,7 +1786,7 @@ fn testWriteIntImpl() void {...@@ -1786,7 +1786,7 @@ fn testWriteIntImpl() void {
1786 }));1786 }));
17871787
1788 writeIntSlice(u16, bytes[0..], 0x1234, Endian.Big);1788 writeIntSlice(u16, bytes[0..], 0x1234, Endian.Big);
1789 testing.expect(eql(u8, &bytes, &[_]u8{1789 try testing.expect(eql(u8, &bytes, &[_]u8{
1790 0x00,1790 0x00,
1791 0x00,1791 0x00,
1792 0x00,1792 0x00,
...@@ -1798,7 +1798,7 @@ fn testWriteIntImpl() void {...@@ -1798,7 +1798,7 @@ fn testWriteIntImpl() void {
1798 }));1798 }));
17991799
1800 writeIntSlice(u16, bytes[0..], 0x1234, Endian.Little);1800 writeIntSlice(u16, bytes[0..], 0x1234, Endian.Little);
1801 testing.expect(eql(u8, &bytes, &[_]u8{1801 try testing.expect(eql(u8, &bytes, &[_]u8{
1802 0x34,1802 0x34,
1803 0x12,1803 0x12,
1804 0x00,1804 0x00,
...@@ -1821,7 +1821,7 @@ pub fn min(comptime T: type, slice: []const T) T {...@@ -1821,7 +1821,7 @@ pub fn min(comptime T: type, slice: []const T) T {
1821}1821}
18221822
1823test "mem.min" {1823test "mem.min" {
1824 testing.expect(min(u8, "abcdefg") == 'a');1824 try testing.expect(min(u8, "abcdefg") == 'a');
1825}1825}
18261826
1827/// Returns the largest number in a slice. O(n).1827/// Returns the largest number in a slice. O(n).
...@@ -1835,7 +1835,7 @@ pub fn max(comptime T: type, slice: []const T) T {...@@ -1835,7 +1835,7 @@ pub fn max(comptime T: type, slice: []const T) T {
1835}1835}
18361836
1837test "mem.max" {1837test "mem.max" {
1838 testing.expect(max(u8, "abcdefg") == 'g');1838 try testing.expect(max(u8, "abcdefg") == 'g');
1839}1839}
18401840
1841pub fn swap(comptime T: type, a: *T, b: *T) void {1841pub fn swap(comptime T: type, a: *T, b: *T) void {
...@@ -1857,7 +1857,7 @@ test "reverse" {...@@ -1857,7 +1857,7 @@ test "reverse" {
1857 var arr = [_]i32{ 5, 3, 1, 2, 4 };1857 var arr = [_]i32{ 5, 3, 1, 2, 4 };
1858 reverse(i32, arr[0..]);1858 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 }));
1861}1861}
18621862
1863/// In-place rotation of the values in an array ([0 1 2 3] becomes [1 2 3 0] if we rotate by 1)1863/// 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" {...@@ -1872,7 +1872,7 @@ test "rotate" {
1872 var arr = [_]i32{ 5, 3, 1, 2, 4 };1872 var arr = [_]i32{ 5, 3, 1, 2, 4 };
1873 rotate(i32, arr[0..], 2);1873 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 }));
1876}1876}
18771877
1878/// Replace needle with replacement as many times as possible, writing to an output buffer which is assumed to be of1878/// 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" {...@@ -1905,31 +1905,31 @@ test "replace" {
1905 var output: [29]u8 = undefined;1905 var output: [29]u8 = undefined;
1906 var replacements = replace(u8, "All your base are belong to us", "base", "Zig", output[0..]);1906 var replacements = replace(u8, "All your base are belong to us", "base", "Zig", output[0..]);
1907 var expected: []const u8 = "All your Zig are belong to us";1907 var expected: []const u8 = "All your Zig are belong to us";
1908 testing.expect(replacements == 1);1908 try testing.expect(replacements == 1);
1909 testing.expectEqualStrings(expected, output[0..expected.len]);1909 try testing.expectEqualStrings(expected, output[0..expected.len]);
19101910
1911 replacements = replace(u8, "Favor reading code over writing code.", "code", "", output[0..]);1911 replacements = replace(u8, "Favor reading code over writing code.", "code", "", output[0..]);
1912 expected = "Favor reading over writing .";1912 expected = "Favor reading over writing .";
1913 testing.expect(replacements == 2);1913 try testing.expect(replacements == 2);
1914 testing.expectEqualStrings(expected, output[0..expected.len]);1914 try testing.expectEqualStrings(expected, output[0..expected.len]);
19151915
1916 // Empty needle is not allowed but input may be empty.1916 // Empty needle is not allowed but input may be empty.
1917 replacements = replace(u8, "", "x", "y", output[0..0]);1917 replacements = replace(u8, "", "x", "y", output[0..0]);
1918 expected = "";1918 expected = "";
1919 testing.expect(replacements == 0);1919 try testing.expect(replacements == 0);
1920 testing.expectEqualStrings(expected, output[0..expected.len]);1920 try testing.expectEqualStrings(expected, output[0..expected.len]);
19211921
1922 // Adjacent replacements.1922 // Adjacent replacements.
19231923
1924 replacements = replace(u8, "\\n\\n", "\\n", "\n", output[0..]);1924 replacements = replace(u8, "\\n\\n", "\\n", "\n", output[0..]);
1925 expected = "\n\n";1925 expected = "\n\n";
1926 testing.expect(replacements == 2);1926 try testing.expect(replacements == 2);
1927 testing.expectEqualStrings(expected, output[0..expected.len]);1927 try testing.expectEqualStrings(expected, output[0..expected.len]);
19281928
1929 replacements = replace(u8, "abbba", "b", "cd", output[0..]);1929 replacements = replace(u8, "abbba", "b", "cd", output[0..]);
1930 expected = "acdcdcda";1930 expected = "acdcdcda";
1931 testing.expect(replacements == 3);1931 try testing.expect(replacements == 3);
1932 testing.expectEqualStrings(expected, output[0..expected.len]);1932 try testing.expectEqualStrings(expected, output[0..expected.len]);
1933}1933}
19341934
1935/// Calculate the size needed in an output buffer to perform a replacement.1935/// 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...@@ -1953,16 +1953,16 @@ pub fn replacementSize(comptime T: type, input: []const T, needle: []const T, re
1953}1953}
19541954
1955test "replacementSize" {1955test "replacementSize" {
1956 testing.expect(replacementSize(u8, "All your base are belong to us", "base", "Zig") == 29);1956 try 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);1957 try 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);1958 try testing.expect(replacementSize(u8, "Only one obvious way to do things.", "things.", "things in Zig.") == 41);
19591959
1960 // Empty needle is not allowed but input may be empty.1960 // 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
1963 // Adjacent replacements.1963 // Adjacent replacements.
1964 testing.expect(replacementSize(u8, "\\n\\n", "\\n", "\n") == 2);1964 try testing.expect(replacementSize(u8, "\\n\\n", "\\n", "\n") == 2);
1965 testing.expect(replacementSize(u8, "abbba", "b", "cd") == 8);1965 try testing.expect(replacementSize(u8, "abbba", "b", "cd") == 8);
1966}1966}
19671967
1968/// Perform a replacement on an allocated buffer of pre-determined size. Caller must free returned memory.1968/// Perform a replacement on an allocated buffer of pre-determined size. Caller must free returned memory.
...@@ -1977,11 +1977,11 @@ test "replaceOwned" {...@@ -1977,11 +1977,11 @@ test "replaceOwned" {
19771977
1978 const base_replace = replaceOwned(u8, allocator, "All your base are belong to us", "base", "Zig") catch unreachable;1978 const base_replace = replaceOwned(u8, allocator, "All your base are belong to us", "base", "Zig") catch unreachable;
1979 defer allocator.free(base_replace);1979 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
1982 const zen_replace = replaceOwned(u8, allocator, "Favor reading code over writing code.", " code", "") catch unreachable;1982 const zen_replace = replaceOwned(u8, allocator, "Favor reading code over writing code.", " code", "") catch unreachable;
1983 defer allocator.free(zen_replace);1983 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."));
1985}1985}
19861986
1987/// Converts a little-endian integer to host endianness.1987/// Converts a little-endian integer to host endianness.
...@@ -2069,12 +2069,12 @@ test "asBytes" {...@@ -2069,12 +2069,12 @@ test "asBytes" {
2069 .Little => "\xEF\xBE\xAD\xDE",2069 .Little => "\xEF\xBE\xAD\xDE",
2070 };2070 };
20712071
2072 testing.expect(eql(u8, asBytes(&deadbeef), deadbeef_bytes));2072 try testing.expect(eql(u8, asBytes(&deadbeef), deadbeef_bytes));
20732073
2074 var codeface = @as(u32, 0xC0DEFACE);2074 var codeface = @as(u32, 0xC0DEFACE);
2075 for (asBytes(&codeface).*) |*b|2075 for (asBytes(&codeface).*) |*b|
2076 b.* = 0;2076 b.* = 0;
2077 testing.expect(codeface == 0);2077 try testing.expect(codeface == 0);
20782078
2079 const S = packed struct {2079 const S = packed struct {
2080 a: u8,2080 a: u8,
...@@ -2089,11 +2089,11 @@ test "asBytes" {...@@ -2089,11 +2089,11 @@ test "asBytes" {
2089 .c = 0xDE,2089 .c = 0xDE,
2090 .d = 0xA1,2090 .d = 0xA1,
2091 };2091 };
2092 testing.expect(eql(u8, asBytes(&inst), "\xBE\xEF\xDE\xA1"));2092 try testing.expect(eql(u8, asBytes(&inst), "\xBE\xEF\xDE\xA1"));
20932093
2094 const ZST = struct {};2094 const ZST = struct {};
2095 const zero = ZST{};2095 const zero = ZST{};
2096 testing.expect(eql(u8, asBytes(&zero), ""));2096 try testing.expect(eql(u8, asBytes(&zero), ""));
2097}2097}
20982098
2099test "asBytes preserves pointer attributes" {2099test "asBytes preserves pointer attributes" {
...@@ -2104,10 +2104,10 @@ test "asBytes preserves pointer attributes" {...@@ -2104,10 +2104,10 @@ test "asBytes preserves pointer attributes" {
2104 const in = @typeInfo(@TypeOf(inPtr)).Pointer;2104 const in = @typeInfo(@TypeOf(inPtr)).Pointer;
2105 const out = @typeInfo(@TypeOf(outSlice)).Pointer;2105 const out = @typeInfo(@TypeOf(outSlice)).Pointer;
21062106
2107 testing.expectEqual(in.is_const, out.is_const);2107 try testing.expectEqual(in.is_const, out.is_const);
2108 testing.expectEqual(in.is_volatile, out.is_volatile);2108 try testing.expectEqual(in.is_volatile, out.is_volatile);
2109 testing.expectEqual(in.is_allowzero, out.is_allowzero);2109 try testing.expectEqual(in.is_allowzero, out.is_allowzero);
2110 testing.expectEqual(in.alignment, out.alignment);2110 try testing.expectEqual(in.alignment, out.alignment);
2111}2111}
21122112
2113/// Given any value, returns a copy of its bytes in an array.2113/// 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 {...@@ -2118,14 +2118,14 @@ pub fn toBytes(value: anytype) [@sizeOf(@TypeOf(value))]u8 {
2118test "toBytes" {2118test "toBytes" {
2119 var my_bytes = toBytes(@as(u32, 0x12345678));2119 var my_bytes = toBytes(@as(u32, 0x12345678));
2120 switch (native_endian) {2120 switch (native_endian) {
2121 .Big => testing.expect(eql(u8, &my_bytes, "\x12\x34\x56\x78")),2121 .Big => try testing.expect(eql(u8, &my_bytes, "\x12\x34\x56\x78")),
2122 .Little => testing.expect(eql(u8, &my_bytes, "\x78\x56\x34\x12")),2122 .Little => try testing.expect(eql(u8, &my_bytes, "\x78\x56\x34\x12")),
2123 }2123 }
21242124
2125 my_bytes[0] = '\x99';2125 my_bytes[0] = '\x99';
2126 switch (native_endian) {2126 switch (native_endian) {
2127 .Big => testing.expect(eql(u8, &my_bytes, "\x99\x34\x56\x78")),2127 .Big => try testing.expect(eql(u8, &my_bytes, "\x99\x34\x56\x78")),
2128 .Little => testing.expect(eql(u8, &my_bytes, "\x99\x56\x34\x12")),2128 .Little => try testing.expect(eql(u8, &my_bytes, "\x99\x56\x34\x12")),
2129 }2129 }
2130}2130}
21312131
...@@ -2155,17 +2155,17 @@ test "bytesAsValue" {...@@ -2155,17 +2155,17 @@ test "bytesAsValue" {
2155 .Little => "\xEF\xBE\xAD\xDE",2155 .Little => "\xEF\xBE\xAD\xDE",
2156 };2156 };
21572157
2158 testing.expect(deadbeef == bytesAsValue(u32, deadbeef_bytes).*);2158 try testing.expect(deadbeef == bytesAsValue(u32, deadbeef_bytes).*);
21592159
2160 var codeface_bytes: [4]u8 = switch (native_endian) {2160 var codeface_bytes: [4]u8 = switch (native_endian) {
2161 .Big => "\xC0\xDE\xFA\xCE",2161 .Big => "\xC0\xDE\xFA\xCE",
2162 .Little => "\xCE\xFA\xDE\xC0",2162 .Little => "\xCE\xFA\xDE\xC0",
2163 }.*;2163 }.*;
2164 var codeface = bytesAsValue(u32, &codeface_bytes);2164 var codeface = bytesAsValue(u32, &codeface_bytes);
2165 testing.expect(codeface.* == 0xC0DEFACE);2165 try testing.expect(codeface.* == 0xC0DEFACE);
2166 codeface.* = 0;2166 codeface.* = 0;
2167 for (codeface_bytes) |b|2167 for (codeface_bytes) |b|
2168 testing.expect(b == 0);2168 try testing.expect(b == 0);
21692169
2170 const S = packed struct {2170 const S = packed struct {
2171 a: u8,2171 a: u8,
...@@ -2182,7 +2182,7 @@ test "bytesAsValue" {...@@ -2182,7 +2182,7 @@ test "bytesAsValue" {
2182 };2182 };
2183 const inst_bytes = "\xBE\xEF\xDE\xA1";2183 const inst_bytes = "\xBE\xEF\xDE\xA1";
2184 const inst2 = bytesAsValue(S, inst_bytes);2184 const inst2 = bytesAsValue(S, inst_bytes);
2185 testing.expect(meta.eql(inst, inst2.*));2185 try testing.expect(meta.eql(inst, inst2.*));
2186}2186}
21872187
2188test "bytesAsValue preserves pointer attributes" {2188test "bytesAsValue preserves pointer attributes" {
...@@ -2193,10 +2193,10 @@ test "bytesAsValue preserves pointer attributes" {...@@ -2193,10 +2193,10 @@ test "bytesAsValue preserves pointer attributes" {
2193 const in = @typeInfo(@TypeOf(inSlice)).Pointer;2193 const in = @typeInfo(@TypeOf(inSlice)).Pointer;
2194 const out = @typeInfo(@TypeOf(outPtr)).Pointer;2194 const out = @typeInfo(@TypeOf(outPtr)).Pointer;
21952195
2196 testing.expectEqual(in.is_const, out.is_const);2196 try testing.expectEqual(in.is_const, out.is_const);
2197 testing.expectEqual(in.is_volatile, out.is_volatile);2197 try testing.expectEqual(in.is_volatile, out.is_volatile);
2198 testing.expectEqual(in.is_allowzero, out.is_allowzero);2198 try testing.expectEqual(in.is_allowzero, out.is_allowzero);
2199 testing.expectEqual(in.alignment, out.alignment);2199 try testing.expectEqual(in.alignment, out.alignment);
2200}2200}
22012201
2202/// Given a pointer to an array of bytes, returns a value of the specified type backed by a2202/// Given a pointer to an array of bytes, returns a value of the specified type backed by a
...@@ -2211,7 +2211,7 @@ test "bytesToValue" {...@@ -2211,7 +2211,7 @@ test "bytesToValue" {
2211 };2211 };
22122212
2213 const deadbeef = bytesToValue(u32, deadbeef_bytes);2213 const deadbeef = bytesToValue(u32, deadbeef_bytes);
2214 testing.expect(deadbeef == @as(u32, 0xDEADBEEF));2214 try testing.expect(deadbeef == @as(u32, 0xDEADBEEF));
2215}2215}
22162216
2217fn BytesAsSliceReturnType(comptime T: type, comptime bytesType: type) type {2217fn BytesAsSliceReturnType(comptime T: type, comptime bytesType: type) type {
...@@ -2244,17 +2244,17 @@ test "bytesAsSlice" {...@@ -2244,17 +2244,17 @@ test "bytesAsSlice" {
2244 {2244 {
2245 const bytes = [_]u8{ 0xDE, 0xAD, 0xBE, 0xEF };2245 const bytes = [_]u8{ 0xDE, 0xAD, 0xBE, 0xEF };
2246 const slice = bytesAsSlice(u16, bytes[0..]);2246 const slice = bytesAsSlice(u16, bytes[0..]);
2247 testing.expect(slice.len == 2);2247 try testing.expect(slice.len == 2);
2248 testing.expect(bigToNative(u16, slice[0]) == 0xDEAD);2248 try testing.expect(bigToNative(u16, slice[0]) == 0xDEAD);
2249 testing.expect(bigToNative(u16, slice[1]) == 0xBEEF);2249 try testing.expect(bigToNative(u16, slice[1]) == 0xBEEF);
2250 }2250 }
2251 {2251 {
2252 const bytes = [_]u8{ 0xDE, 0xAD, 0xBE, 0xEF };2252 const bytes = [_]u8{ 0xDE, 0xAD, 0xBE, 0xEF };
2253 var runtime_zero: usize = 0;2253 var runtime_zero: usize = 0;
2254 const slice = bytesAsSlice(u16, bytes[runtime_zero..]);2254 const slice = bytesAsSlice(u16, bytes[runtime_zero..]);
2255 testing.expect(slice.len == 2);2255 try testing.expect(slice.len == 2);
2256 testing.expect(bigToNative(u16, slice[0]) == 0xDEAD);2256 try testing.expect(bigToNative(u16, slice[0]) == 0xDEAD);
2257 testing.expect(bigToNative(u16, slice[1]) == 0xBEEF);2257 try testing.expect(bigToNative(u16, slice[1]) == 0xBEEF);
2258 }2258 }
2259}2259}
22602260
...@@ -2262,13 +2262,13 @@ test "bytesAsSlice keeps pointer alignment" {...@@ -2262,13 +2262,13 @@ test "bytesAsSlice keeps pointer alignment" {
2262 {2262 {
2263 var bytes = [_]u8{ 0x01, 0x02, 0x03, 0x04 };2263 var bytes = [_]u8{ 0x01, 0x02, 0x03, 0x04 };
2264 const numbers = bytesAsSlice(u32, bytes[0..]);2264 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);
2266 }2266 }
2267 {2267 {
2268 var bytes = [_]u8{ 0x01, 0x02, 0x03, 0x04 };2268 var bytes = [_]u8{ 0x01, 0x02, 0x03, 0x04 };
2269 var runtime_zero: usize = 0;2269 var runtime_zero: usize = 0;
2270 const numbers = bytesAsSlice(u32, bytes[runtime_zero..]);2270 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);
2272 }2272 }
2273}2273}
22742274
...@@ -2279,7 +2279,7 @@ test "bytesAsSlice on a packed struct" {...@@ -2279,7 +2279,7 @@ test "bytesAsSlice on a packed struct" {
22792279
2280 var b = [1]u8{9};2280 var b = [1]u8{9};
2281 var f = bytesAsSlice(F, &b);2281 var f = bytesAsSlice(F, &b);
2282 testing.expect(f[0].a == 9);2282 try testing.expect(f[0].a == 9);
2283}2283}
22842284
2285test "bytesAsSlice with specified alignment" {2285test "bytesAsSlice with specified alignment" {
...@@ -2290,7 +2290,7 @@ test "bytesAsSlice with specified alignment" {...@@ -2290,7 +2290,7 @@ test "bytesAsSlice with specified alignment" {
2290 0x33,2290 0x33,
2291 };2291 };
2292 const slice: []u32 = std.mem.bytesAsSlice(u32, bytes[0..]);2292 const slice: []u32 = std.mem.bytesAsSlice(u32, bytes[0..]);
2293 testing.expect(slice[0] == 0x33333333);2293 try testing.expect(slice[0] == 0x33333333);
2294}2294}
22952295
2296test "bytesAsSlice preserves pointer attributes" {2296test "bytesAsSlice preserves pointer attributes" {
...@@ -2301,10 +2301,10 @@ test "bytesAsSlice preserves pointer attributes" {...@@ -2301,10 +2301,10 @@ test "bytesAsSlice preserves pointer attributes" {
2301 const in = @typeInfo(@TypeOf(inSlice)).Pointer;2301 const in = @typeInfo(@TypeOf(inSlice)).Pointer;
2302 const out = @typeInfo(@TypeOf(outSlice)).Pointer;2302 const out = @typeInfo(@TypeOf(outSlice)).Pointer;
23032303
2304 testing.expectEqual(in.is_const, out.is_const);2304 try testing.expectEqual(in.is_const, out.is_const);
2305 testing.expectEqual(in.is_volatile, out.is_volatile);2305 try testing.expectEqual(in.is_volatile, out.is_volatile);
2306 testing.expectEqual(in.is_allowzero, out.is_allowzero);2306 try testing.expectEqual(in.is_allowzero, out.is_allowzero);
2307 testing.expectEqual(in.alignment, out.alignment);2307 try testing.expectEqual(in.alignment, out.alignment);
2308}2308}
23092309
2310fn SliceAsBytesReturnType(comptime sliceType: type) type {2310fn SliceAsBytesReturnType(comptime sliceType: type) type {
...@@ -2333,8 +2333,8 @@ pub fn sliceAsBytes(slice: anytype) SliceAsBytesReturnType(@TypeOf(slice)) {...@@ -2333,8 +2333,8 @@ pub fn sliceAsBytes(slice: anytype) SliceAsBytesReturnType(@TypeOf(slice)) {
2333test "sliceAsBytes" {2333test "sliceAsBytes" {
2334 const bytes = [_]u16{ 0xDEAD, 0xBEEF };2334 const bytes = [_]u16{ 0xDEAD, 0xBEEF };
2335 const slice = sliceAsBytes(bytes[0..]);2335 const slice = sliceAsBytes(bytes[0..]);
2336 testing.expect(slice.len == 4);2336 try testing.expect(slice.len == 4);
2337 testing.expect(eql(u8, slice, switch (native_endian) {2337 try testing.expect(eql(u8, slice, switch (native_endian) {
2338 .Big => "\xDE\xAD\xBE\xEF",2338 .Big => "\xDE\xAD\xBE\xEF",
2339 .Little => "\xAD\xDE\xEF\xBE",2339 .Little => "\xAD\xDE\xEF\xBE",
2340 }));2340 }));
...@@ -2343,7 +2343,7 @@ test "sliceAsBytes" {...@@ -2343,7 +2343,7 @@ test "sliceAsBytes" {
2343test "sliceAsBytes with sentinel slice" {2343test "sliceAsBytes with sentinel slice" {
2344 const empty_string: [:0]const u8 = "";2344 const empty_string: [:0]const u8 = "";
2345 const bytes = sliceAsBytes(empty_string);2345 const bytes = sliceAsBytes(empty_string);
2346 testing.expect(bytes.len == 0);2346 try testing.expect(bytes.len == 0);
2347}2347}
23482348
2349test "sliceAsBytes packed struct at runtime and comptime" {2349test "sliceAsBytes packed struct at runtime and comptime" {
...@@ -2352,49 +2352,49 @@ test "sliceAsBytes packed struct at runtime and comptime" {...@@ -2352,49 +2352,49 @@ test "sliceAsBytes packed struct at runtime and comptime" {
2352 b: u4,2352 b: u4,
2353 };2353 };
2354 const S = struct {2354 const S = struct {
2355 fn doTheTest() void {2355 fn doTheTest() !void {
2356 var foo: Foo = undefined;2356 var foo: Foo = undefined;
2357 var slice = sliceAsBytes(@as(*[1]Foo, &foo)[0..1]);2357 var slice = sliceAsBytes(@as(*[1]Foo, &foo)[0..1]);
2358 slice[0] = 0x13;2358 slice[0] = 0x13;
2359 switch (native_endian) {2359 switch (native_endian) {
2360 .Big => {2360 .Big => {
2361 testing.expect(foo.a == 0x1);2361 try testing.expect(foo.a == 0x1);
2362 testing.expect(foo.b == 0x3);2362 try testing.expect(foo.b == 0x3);
2363 },2363 },
2364 .Little => {2364 .Little => {
2365 testing.expect(foo.a == 0x3);2365 try testing.expect(foo.a == 0x3);
2366 testing.expect(foo.b == 0x1);2366 try testing.expect(foo.b == 0x1);
2367 },2367 },
2368 }2368 }
2369 }2369 }
2370 };2370 };
2371 S.doTheTest();2371 try S.doTheTest();
2372 comptime S.doTheTest();2372 comptime try S.doTheTest();
2373}2373}
23742374
2375test "sliceAsBytes and bytesAsSlice back" {2375test "sliceAsBytes and bytesAsSlice back" {
2376 testing.expect(@sizeOf(i32) == 4);2376 try testing.expect(@sizeOf(i32) == 4);
23772377
2378 var big_thing_array = [_]i32{ 1, 2, 3, 4 };2378 var big_thing_array = [_]i32{ 1, 2, 3, 4 };
2379 const big_thing_slice: []i32 = big_thing_array[0..];2379 const big_thing_slice: []i32 = big_thing_array[0..];
23802380
2381 const bytes = sliceAsBytes(big_thing_slice);2381 const bytes = sliceAsBytes(big_thing_slice);
2382 testing.expect(bytes.len == 4 * 4);2382 try testing.expect(bytes.len == 4 * 4);
23832383
2384 bytes[4] = 0;2384 bytes[4] = 0;
2385 bytes[5] = 0;2385 bytes[5] = 0;
2386 bytes[6] = 0;2386 bytes[6] = 0;
2387 bytes[7] = 0;2387 bytes[7] = 0;
2388 testing.expect(big_thing_slice[1] == 0);2388 try testing.expect(big_thing_slice[1] == 0);
23892389
2390 const big_thing_again = bytesAsSlice(i32, bytes);2390 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
2393 big_thing_again[2] = -1;2393 big_thing_again[2] = -1;
2394 testing.expect(bytes[8] == math.maxInt(u8));2394 try testing.expect(bytes[8] == math.maxInt(u8));
2395 testing.expect(bytes[9] == math.maxInt(u8));2395 try testing.expect(bytes[9] == math.maxInt(u8));
2396 testing.expect(bytes[10] == math.maxInt(u8));2396 try testing.expect(bytes[10] == math.maxInt(u8));
2397 testing.expect(bytes[11] == math.maxInt(u8));2397 try testing.expect(bytes[11] == math.maxInt(u8));
2398}2398}
23992399
2400test "sliceAsBytes preserves pointer attributes" {2400test "sliceAsBytes preserves pointer attributes" {
...@@ -2405,10 +2405,10 @@ test "sliceAsBytes preserves pointer attributes" {...@@ -2405,10 +2405,10 @@ test "sliceAsBytes preserves pointer attributes" {
2405 const in = @typeInfo(@TypeOf(inSlice)).Pointer;2405 const in = @typeInfo(@TypeOf(inSlice)).Pointer;
2406 const out = @typeInfo(@TypeOf(outSlice)).Pointer;2406 const out = @typeInfo(@TypeOf(outSlice)).Pointer;
24072407
2408 testing.expectEqual(in.is_const, out.is_const);2408 try testing.expectEqual(in.is_const, out.is_const);
2409 testing.expectEqual(in.is_volatile, out.is_volatile);2409 try testing.expectEqual(in.is_volatile, out.is_volatile);
2410 testing.expectEqual(in.is_allowzero, out.is_allowzero);2410 try testing.expectEqual(in.is_allowzero, out.is_allowzero);
2411 testing.expectEqual(in.alignment, out.alignment);2411 try testing.expectEqual(in.alignment, out.alignment);
2412}2412}
24132413
2414/// Round an address up to the nearest aligned address2414/// Round an address up to the nearest aligned address
...@@ -2435,18 +2435,18 @@ pub fn doNotOptimizeAway(val: anytype) void {...@@ -2435,18 +2435,18 @@ pub fn doNotOptimizeAway(val: anytype) void {
2435}2435}
24362436
2437test "alignForward" {2437test "alignForward" {
2438 testing.expect(alignForward(1, 1) == 1);2438 try testing.expect(alignForward(1, 1) == 1);
2439 testing.expect(alignForward(2, 1) == 2);2439 try testing.expect(alignForward(2, 1) == 2);
2440 testing.expect(alignForward(1, 2) == 2);2440 try testing.expect(alignForward(1, 2) == 2);
2441 testing.expect(alignForward(2, 2) == 2);2441 try testing.expect(alignForward(2, 2) == 2);
2442 testing.expect(alignForward(3, 2) == 4);2442 try testing.expect(alignForward(3, 2) == 4);
2443 testing.expect(alignForward(4, 2) == 4);2443 try testing.expect(alignForward(4, 2) == 4);
2444 testing.expect(alignForward(7, 8) == 8);2444 try testing.expect(alignForward(7, 8) == 8);
2445 testing.expect(alignForward(8, 8) == 8);2445 try testing.expect(alignForward(8, 8) == 8);
2446 testing.expect(alignForward(9, 8) == 16);2446 try testing.expect(alignForward(9, 8) == 16);
2447 testing.expect(alignForward(15, 8) == 16);2447 try testing.expect(alignForward(15, 8) == 16);
2448 testing.expect(alignForward(16, 8) == 16);2448 try testing.expect(alignForward(16, 8) == 16);
2449 testing.expect(alignForward(17, 8) == 24);2449 try testing.expect(alignForward(17, 8) == 24);
2450}2450}
24512451
2452/// Round an address up to the previous aligned address2452/// Round an address up to the previous aligned address
...@@ -2498,19 +2498,19 @@ pub fn isAlignedGeneric(comptime T: type, addr: T, alignment: T) bool {...@@ -2498,19 +2498,19 @@ pub fn isAlignedGeneric(comptime T: type, addr: T, alignment: T) bool {
2498}2498}
24992499
2500test "isAligned" {2500test "isAligned" {
2501 testing.expect(isAligned(0, 4));2501 try testing.expect(isAligned(0, 4));
2502 testing.expect(isAligned(1, 1));2502 try testing.expect(isAligned(1, 1));
2503 testing.expect(isAligned(2, 1));2503 try testing.expect(isAligned(2, 1));
2504 testing.expect(isAligned(2, 2));2504 try testing.expect(isAligned(2, 2));
2505 testing.expect(!isAligned(2, 4));2505 try testing.expect(!isAligned(2, 4));
2506 testing.expect(isAligned(3, 1));2506 try testing.expect(isAligned(3, 1));
2507 testing.expect(!isAligned(3, 2));2507 try testing.expect(!isAligned(3, 2));
2508 testing.expect(!isAligned(3, 4));2508 try testing.expect(!isAligned(3, 4));
2509 testing.expect(isAligned(4, 4));2509 try testing.expect(isAligned(4, 4));
2510 testing.expect(isAligned(4, 2));2510 try testing.expect(isAligned(4, 2));
2511 testing.expect(isAligned(4, 1));2511 try testing.expect(isAligned(4, 1));
2512 testing.expect(!isAligned(4, 8));2512 try testing.expect(!isAligned(4, 8));
2513 testing.expect(!isAligned(4, 16));2513 try testing.expect(!isAligned(4, 16));
2514}2514}
25152515
2516test "freeing empty string with null-terminated sentinel" {2516test "freeing empty string with null-terminated sentinel" {
lib/std/meta.zig+188-188
...@@ -47,16 +47,16 @@ test "std.meta.tagName" {...@@ -47,16 +47,16 @@ test "std.meta.tagName" {
47 var u2a = U2{ .C = 0 };47 var u2a = U2{ .C = 0 };
48 var u2b = U2{ .D = 0 };48 var u2b = U2{ .D = 0 };
4949
50 testing.expect(mem.eql(u8, tagName(E1.A), "A"));50 try testing.expect(mem.eql(u8, tagName(E1.A), "A"));
51 testing.expect(mem.eql(u8, tagName(E1.B), "B"));51 try testing.expect(mem.eql(u8, tagName(E1.B), "B"));
52 testing.expect(mem.eql(u8, tagName(E2.C), "C"));52 try testing.expect(mem.eql(u8, tagName(E2.C), "C"));
53 testing.expect(mem.eql(u8, tagName(E2.D), "D"));53 try testing.expect(mem.eql(u8, tagName(E2.D), "D"));
54 testing.expect(mem.eql(u8, tagName(error.E), "E"));54 try testing.expect(mem.eql(u8, tagName(error.E), "E"));
55 testing.expect(mem.eql(u8, tagName(error.F), "F"));55 try testing.expect(mem.eql(u8, tagName(error.F), "F"));
56 testing.expect(mem.eql(u8, tagName(u1g), "G"));56 try testing.expect(mem.eql(u8, tagName(u1g), "G"));
57 testing.expect(mem.eql(u8, tagName(u1h), "H"));57 try testing.expect(mem.eql(u8, tagName(u1h), "H"));
58 testing.expect(mem.eql(u8, tagName(u2a), "C"));58 try testing.expect(mem.eql(u8, tagName(u2a), "C"));
59 testing.expect(mem.eql(u8, tagName(u2b), "D"));59 try testing.expect(mem.eql(u8, tagName(u2b), "D"));
60}60}
6161
62pub fn stringToEnum(comptime T: type, str: []const u8) ?T {62pub fn stringToEnum(comptime T: type, str: []const u8) ?T {
...@@ -98,9 +98,9 @@ test "std.meta.stringToEnum" {...@@ -98,9 +98,9 @@ test "std.meta.stringToEnum" {
98 A,98 A,
99 B,99 B,
100 };100 };
101 testing.expect(E1.A == stringToEnum(E1, "A").?);101 try testing.expect(E1.A == stringToEnum(E1, "A").?);
102 testing.expect(E1.B == stringToEnum(E1, "B").?);102 try testing.expect(E1.B == stringToEnum(E1, "B").?);
103 testing.expect(null == stringToEnum(E1, "C"));103 try testing.expect(null == stringToEnum(E1, "C"));
104}104}
105105
106pub fn bitCount(comptime T: type) comptime_int {106pub fn bitCount(comptime T: type) comptime_int {
...@@ -113,8 +113,8 @@ pub fn bitCount(comptime T: type) comptime_int {...@@ -113,8 +113,8 @@ pub fn bitCount(comptime T: type) comptime_int {
113}113}
114114
115test "std.meta.bitCount" {115test "std.meta.bitCount" {
116 testing.expect(bitCount(u8) == 8);116 try testing.expect(bitCount(u8) == 8);
117 testing.expect(bitCount(f32) == 32);117 try testing.expect(bitCount(f32) == 32);
118}118}
119119
120/// Returns the alignment of type T.120/// Returns the alignment of type T.
...@@ -135,13 +135,13 @@ pub fn alignment(comptime T: type) comptime_int {...@@ -135,13 +135,13 @@ pub fn alignment(comptime T: type) comptime_int {
135}135}
136136
137test "std.meta.alignment" {137test "std.meta.alignment" {
138 testing.expect(alignment(u8) == 1);138 try testing.expect(alignment(u8) == 1);
139 testing.expect(alignment(*align(1) u8) == 1);139 try testing.expect(alignment(*align(1) u8) == 1);
140 testing.expect(alignment(*align(2) u8) == 2);140 try testing.expect(alignment(*align(2) u8) == 2);
141 testing.expect(alignment([]align(1) u8) == 1);141 try testing.expect(alignment([]align(1) u8) == 1);
142 testing.expect(alignment([]align(2) u8) == 2);142 try testing.expect(alignment([]align(2) u8) == 2);
143 testing.expect(alignment(fn () void) > 0);143 try testing.expect(alignment(fn () void) > 0);
144 testing.expect(alignment(fn () align(128) void) == 128);144 try testing.expect(alignment(fn () align(128) void) == 128);
145}145}
146146
147pub fn Child(comptime T: type) type {147pub fn Child(comptime T: type) type {
...@@ -155,11 +155,11 @@ pub fn Child(comptime T: type) type {...@@ -155,11 +155,11 @@ pub fn Child(comptime T: type) type {
155}155}
156156
157test "std.meta.Child" {157test "std.meta.Child" {
158 testing.expect(Child([1]u8) == u8);158 try testing.expect(Child([1]u8) == u8);
159 testing.expect(Child(*u8) == u8);159 try testing.expect(Child(*u8) == u8);
160 testing.expect(Child([]u8) == u8);160 try testing.expect(Child([]u8) == u8);
161 testing.expect(Child(?u8) == u8);161 try testing.expect(Child(?u8) == u8);
162 testing.expect(Child(Vector(2, u8)) == u8);162 try testing.expect(Child(Vector(2, u8)) == u8);
163}163}
164164
165/// Given a "memory span" type, returns the "element type".165/// Given a "memory span" type, returns the "element type".
...@@ -188,13 +188,13 @@ pub fn Elem(comptime T: type) type {...@@ -188,13 +188,13 @@ pub fn Elem(comptime T: type) type {
188}188}
189189
190test "std.meta.Elem" {190test "std.meta.Elem" {
191 testing.expect(Elem([1]u8) == u8);191 try testing.expect(Elem([1]u8) == u8);
192 testing.expect(Elem([*]u8) == u8);192 try testing.expect(Elem([*]u8) == u8);
193 testing.expect(Elem([]u8) == u8);193 try testing.expect(Elem([]u8) == u8);
194 testing.expect(Elem(*[10]u8) == u8);194 try testing.expect(Elem(*[10]u8) == u8);
195 testing.expect(Elem(Vector(2, u8)) == u8);195 try testing.expect(Elem(Vector(2, u8)) == u8);
196 testing.expect(Elem(*Vector(2, u8)) == u8);196 try testing.expect(Elem(*Vector(2, u8)) == u8);
197 testing.expect(Elem(?[*]u8) == u8);197 try testing.expect(Elem(?[*]u8) == u8);
198}198}
199199
200/// Given a type which can have a sentinel e.g. `[:0]u8`, returns the sentinel value,200/// 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) {...@@ -219,20 +219,20 @@ pub fn sentinel(comptime T: type) ?Elem(T) {
219}219}
220220
221test "std.meta.sentinel" {221test "std.meta.sentinel" {
222 testSentinel();222 try testSentinel();
223 comptime testSentinel();223 comptime try testSentinel();
224}224}
225225
226fn testSentinel() void {226fn testSentinel() !void {
227 testing.expectEqual(@as(u8, 0), sentinel([:0]u8).?);227 try testing.expectEqual(@as(u8, 0), sentinel([:0]u8).?);
228 testing.expectEqual(@as(u8, 0), sentinel([*:0]u8).?);228 try testing.expectEqual(@as(u8, 0), sentinel([*:0]u8).?);
229 testing.expectEqual(@as(u8, 0), sentinel([5:0]u8).?);229 try testing.expectEqual(@as(u8, 0), sentinel([5:0]u8).?);
230 testing.expectEqual(@as(u8, 0), sentinel(*const [5:0]u8).?);230 try testing.expectEqual(@as(u8, 0), sentinel(*const [5:0]u8).?);
231231
232 testing.expect(sentinel([]u8) == null);232 try testing.expect(sentinel([]u8) == null);
233 testing.expect(sentinel([*]u8) == null);233 try testing.expect(sentinel([*]u8) == null);
234 testing.expect(sentinel([5]u8) == null);234 try testing.expect(sentinel([5]u8) == null);
235 testing.expect(sentinel(*const [5]u8) == null);235 try testing.expect(sentinel(*const [5]u8) == null);
236}236}
237237
238/// Given a "memory span" type, returns the same type except with the given sentinel value.238/// 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...@@ -322,17 +322,17 @@ pub fn assumeSentinel(p: anytype, comptime sentinel_val: Elem(@TypeOf(p))) Senti
322}322}
323323
324test "std.meta.assumeSentinel" {324test "std.meta.assumeSentinel" {
325 testing.expect([*:0]u8 == @TypeOf(assumeSentinel(@as([*]u8, undefined), 0)));325 try testing.expect([*:0]u8 == @TypeOf(assumeSentinel(@as([*]u8, undefined), 0)));
326 testing.expect([:0]u8 == @TypeOf(assumeSentinel(@as([]u8, undefined), 0)));326 try testing.expect([:0]u8 == @TypeOf(assumeSentinel(@as([]u8, undefined), 0)));
327 testing.expect([*:0]const u8 == @TypeOf(assumeSentinel(@as([*]const u8, undefined), 0)));327 try 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)));328 try testing.expect([:0]const u8 == @TypeOf(assumeSentinel(@as([]const u8, undefined), 0)));
329 testing.expect([*:0]u16 == @TypeOf(assumeSentinel(@as([*]u16, undefined), 0)));329 try testing.expect([*:0]u16 == @TypeOf(assumeSentinel(@as([*]u16, undefined), 0)));
330 testing.expect([:0]const u16 == @TypeOf(assumeSentinel(@as([]const u16, undefined), 0)));330 try testing.expect([:0]const u16 == @TypeOf(assumeSentinel(@as([]const u16, undefined), 0)));
331 testing.expect([*:3]u8 == @TypeOf(assumeSentinel(@as([*:1]u8, undefined), 3)));331 try testing.expect([*:3]u8 == @TypeOf(assumeSentinel(@as([*:1]u8, undefined), 3)));
332 testing.expect([:null]?[*]u8 == @TypeOf(assumeSentinel(@as([]?[*]u8, undefined), null)));332 try testing.expect([:null]?[*]u8 == @TypeOf(assumeSentinel(@as([]?[*]u8, undefined), null)));
333 testing.expect([*:null]?[*]u8 == @TypeOf(assumeSentinel(@as([*]?[*]u8, undefined), null)));333 try testing.expect([*:null]?[*]u8 == @TypeOf(assumeSentinel(@as([*]?[*]u8, undefined), null)));
334 testing.expect(*[10:0]u8 == @TypeOf(assumeSentinel(@as(*[10]u8, undefined), 0)));334 try testing.expect(*[10:0]u8 == @TypeOf(assumeSentinel(@as(*[10]u8, undefined), 0)));
335 testing.expect(?[*:0]u8 == @TypeOf(assumeSentinel(@as(?[*]u8, undefined), 0)));335 try testing.expect(?[*:0]u8 == @TypeOf(assumeSentinel(@as(?[*]u8, undefined), 0)));
336}336}
337337
338pub fn containerLayout(comptime T: type) TypeInfo.ContainerLayout {338pub fn containerLayout(comptime T: type) TypeInfo.ContainerLayout {
...@@ -361,13 +361,13 @@ test "std.meta.containerLayout" {...@@ -361,13 +361,13 @@ test "std.meta.containerLayout" {
361 a: u8,361 a: u8,
362 };362 };
363363
364 testing.expect(containerLayout(E1) == .Auto);364 try testing.expect(containerLayout(E1) == .Auto);
365 testing.expect(containerLayout(S1) == .Auto);365 try testing.expect(containerLayout(S1) == .Auto);
366 testing.expect(containerLayout(S2) == .Packed);366 try testing.expect(containerLayout(S2) == .Packed);
367 testing.expect(containerLayout(S3) == .Extern);367 try testing.expect(containerLayout(S3) == .Extern);
368 testing.expect(containerLayout(U1) == .Auto);368 try testing.expect(containerLayout(U1) == .Auto);
369 testing.expect(containerLayout(U2) == .Packed);369 try testing.expect(containerLayout(U2) == .Packed);
370 testing.expect(containerLayout(U3) == .Extern);370 try testing.expect(containerLayout(U3) == .Extern);
371}371}
372372
373pub fn declarations(comptime T: type) []const TypeInfo.Declaration {373pub fn declarations(comptime T: type) []const TypeInfo.Declaration {
...@@ -406,8 +406,8 @@ test "std.meta.declarations" {...@@ -406,8 +406,8 @@ test "std.meta.declarations" {
406 };406 };
407407
408 inline for (decls) |decl| {408 inline for (decls) |decl| {
409 testing.expect(decl.len == 1);409 try testing.expect(decl.len == 1);
410 testing.expect(comptime mem.eql(u8, decl[0].name, "a"));410 try testing.expect(comptime mem.eql(u8, decl[0].name, "a"));
411 }411 }
412}412}
413413
...@@ -442,8 +442,8 @@ test "std.meta.declarationInfo" {...@@ -442,8 +442,8 @@ test "std.meta.declarationInfo" {
442 };442 };
443443
444 inline for (infos) |info| {444 inline for (infos) |info| {
445 testing.expect(comptime mem.eql(u8, info.name, "a"));445 try testing.expect(comptime mem.eql(u8, info.name, "a"));
446 testing.expect(!info.is_pub);446 try testing.expect(!info.is_pub);
447 }447 }
448}448}
449449
...@@ -480,16 +480,16 @@ test "std.meta.fields" {...@@ -480,16 +480,16 @@ test "std.meta.fields" {
480 const sf = comptime fields(S1);480 const sf = comptime fields(S1);
481 const uf = comptime fields(U1);481 const uf = comptime fields(U1);
482482
483 testing.expect(e1f.len == 1);483 try testing.expect(e1f.len == 1);
484 testing.expect(e2f.len == 1);484 try testing.expect(e2f.len == 1);
485 testing.expect(sf.len == 1);485 try testing.expect(sf.len == 1);
486 testing.expect(uf.len == 1);486 try testing.expect(uf.len == 1);
487 testing.expect(mem.eql(u8, e1f[0].name, "A"));487 try testing.expect(mem.eql(u8, e1f[0].name, "A"));
488 testing.expect(mem.eql(u8, e2f[0].name, "A"));488 try testing.expect(mem.eql(u8, e2f[0].name, "A"));
489 testing.expect(mem.eql(u8, sf[0].name, "a"));489 try testing.expect(mem.eql(u8, sf[0].name, "a"));
490 testing.expect(mem.eql(u8, uf[0].name, "a"));490 try testing.expect(mem.eql(u8, uf[0].name, "a"));
491 testing.expect(comptime sf[0].field_type == u8);491 try testing.expect(comptime sf[0].field_type == u8);
492 testing.expect(comptime uf[0].field_type == u8);492 try testing.expect(comptime uf[0].field_type == u8);
493}493}
494494
495pub fn fieldInfo(comptime T: type, comptime field: FieldEnum(T)) switch (@typeInfo(T)) {495pub fn fieldInfo(comptime T: type, comptime field: FieldEnum(T)) switch (@typeInfo(T)) {
...@@ -519,12 +519,12 @@ test "std.meta.fieldInfo" {...@@ -519,12 +519,12 @@ test "std.meta.fieldInfo" {
519 const sf = fieldInfo(S1, .a);519 const sf = fieldInfo(S1, .a);
520 const uf = fieldInfo(U1, .a);520 const uf = fieldInfo(U1, .a);
521521
522 testing.expect(mem.eql(u8, e1f.name, "A"));522 try testing.expect(mem.eql(u8, e1f.name, "A"));
523 testing.expect(mem.eql(u8, e2f.name, "A"));523 try testing.expect(mem.eql(u8, e2f.name, "A"));
524 testing.expect(mem.eql(u8, sf.name, "a"));524 try testing.expect(mem.eql(u8, sf.name, "a"));
525 testing.expect(mem.eql(u8, uf.name, "a"));525 try testing.expect(mem.eql(u8, uf.name, "a"));
526 testing.expect(comptime sf.field_type == u8);526 try testing.expect(comptime sf.field_type == u8);
527 testing.expect(comptime uf.field_type == u8);527 try testing.expect(comptime uf.field_type == u8);
528}528}
529529
530pub fn fieldNames(comptime T: type) *const [fields(T).len][]const u8 {530pub fn fieldNames(comptime T: type) *const [fields(T).len][]const u8 {
...@@ -554,16 +554,16 @@ test "std.meta.fieldNames" {...@@ -554,16 +554,16 @@ test "std.meta.fieldNames" {
554 const s1names = fieldNames(S1);554 const s1names = fieldNames(S1);
555 const u1names = fieldNames(U1);555 const u1names = fieldNames(U1);
556556
557 testing.expect(e1names.len == 2);557 try testing.expect(e1names.len == 2);
558 testing.expectEqualSlices(u8, e1names[0], "A");558 try testing.expectEqualSlices(u8, e1names[0], "A");
559 testing.expectEqualSlices(u8, e1names[1], "B");559 try testing.expectEqualSlices(u8, e1names[1], "B");
560 testing.expect(e2names.len == 1);560 try testing.expect(e2names.len == 1);
561 testing.expectEqualSlices(u8, e2names[0], "A");561 try testing.expectEqualSlices(u8, e2names[0], "A");
562 testing.expect(s1names.len == 1);562 try testing.expect(s1names.len == 1);
563 testing.expectEqualSlices(u8, s1names[0], "a");563 try testing.expectEqualSlices(u8, s1names[0], "a");
564 testing.expect(u1names.len == 2);564 try testing.expect(u1names.len == 2);
565 testing.expectEqualSlices(u8, u1names[0], "a");565 try testing.expectEqualSlices(u8, u1names[0], "a");
566 testing.expectEqualSlices(u8, u1names[1], "b");566 try testing.expectEqualSlices(u8, u1names[1], "b");
567}567}
568568
569pub fn FieldEnum(comptime T: type) type {569pub fn FieldEnum(comptime T: type) type {
...@@ -587,20 +587,20 @@ pub fn FieldEnum(comptime T: type) type {...@@ -587,20 +587,20 @@ pub fn FieldEnum(comptime T: type) type {
587 });587 });
588}588}
589589
590fn expectEqualEnum(expected: anytype, actual: @TypeOf(expected)) void {590fn expectEqualEnum(expected: anytype, actual: @TypeOf(expected)) !void {
591 // TODO: https://github.com/ziglang/zig/issues/7419591 // TODO: https://github.com/ziglang/zig/issues/7419
592 // testing.expectEqual(@typeInfo(expected).Enum, @typeInfo(actual).Enum);592 // testing.expectEqual(@typeInfo(expected).Enum, @typeInfo(actual).Enum);
593 testing.expectEqual(@typeInfo(expected).Enum.layout, @typeInfo(actual).Enum.layout);593 try testing.expectEqual(@typeInfo(expected).Enum.layout, @typeInfo(actual).Enum.layout);
594 testing.expectEqual(@typeInfo(expected).Enum.tag_type, @typeInfo(actual).Enum.tag_type);594 try 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);595 comptime try 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);596 comptime try 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);597 try testing.expectEqual(@typeInfo(expected).Enum.is_exhaustive, @typeInfo(actual).Enum.is_exhaustive);
598}598}
599599
600test "std.meta.FieldEnum" {600test "std.meta.FieldEnum" {
601 expectEqualEnum(enum { a }, FieldEnum(struct { a: u8 }));601 try expectEqualEnum(enum { a }, FieldEnum(struct { a: u8 }));
602 expectEqualEnum(enum { a, b, c }, FieldEnum(struct { a: u8, b: void, c: f32 }));602 try 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 }));603 try expectEqualEnum(enum { a, b, c }, FieldEnum(union { a: u8, b: void, c: f32 }));
604}604}
605605
606// Deprecated: use Tag606// Deprecated: use Tag
...@@ -624,8 +624,8 @@ test "std.meta.Tag" {...@@ -624,8 +624,8 @@ test "std.meta.Tag" {
624 D: u16,624 D: u16,
625 };625 };
626626
627 testing.expect(Tag(E) == u8);627 try testing.expect(Tag(E) == u8);
628 testing.expect(Tag(U) == E);628 try testing.expect(Tag(U) == E);
629}629}
630630
631///Returns the active tag of a tagged union631///Returns the active tag of a tagged union
...@@ -646,10 +646,10 @@ test "std.meta.activeTag" {...@@ -646,10 +646,10 @@ test "std.meta.activeTag" {
646 };646 };
647647
648 var u = U{ .Int = 32 };648 var u = U{ .Int = 32 };
649 testing.expect(activeTag(u) == UE.Int);649 try testing.expect(activeTag(u) == UE.Int);
650650
651 u = U{ .Float = 112.9876 };651 u = U{ .Float = 112.9876 };
652 testing.expect(activeTag(u) == UE.Float);652 try testing.expect(activeTag(u) == UE.Float);
653}653}
654654
655const TagPayloadType = TagPayload;655const TagPayloadType = TagPayload;
...@@ -657,7 +657,7 @@ const TagPayloadType = TagPayload;...@@ -657,7 +657,7 @@ const TagPayloadType = TagPayload;
657///Given a tagged union type, and an enum, return the type of the union657///Given a tagged union type, and an enum, return the type of the union
658/// field corresponding to the enum tag.658/// field corresponding to the enum tag.
659pub fn TagPayload(comptime U: type, tag: Tag(U)) type {659pub 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
662 const info = @typeInfo(U).Union;662 const info = @typeInfo(U).Union;
663 const tag_info = @typeInfo(Tag(U)).Enum;663 const tag_info = @typeInfo(Tag(U)).Enum;
...@@ -679,7 +679,7 @@ test "std.meta.TagPayload" {...@@ -679,7 +679,7 @@ test "std.meta.TagPayload" {
679 };679 };
680 const MovedEvent = TagPayload(Event, Event.Moved);680 const MovedEvent = TagPayload(Event, Event.Moved);
681 var e: Event = undefined;681 var e: Event = undefined;
682 testing.expect(MovedEvent == @TypeOf(e.Moved));682 try testing.expect(MovedEvent == @TypeOf(e.Moved));
683}683}
684684
685/// Compares two of any type for equality. Containers are compared on a field-by-field basis,685/// Compares two of any type for equality. Containers are compared on a field-by-field basis,
...@@ -779,19 +779,19 @@ test "std.meta.eql" {...@@ -779,19 +779,19 @@ test "std.meta.eql" {
779 const u_2 = U{ .s = s_1 };779 const u_2 = U{ .s = s_1 };
780 const u_3 = U{ .f = 24 };780 const u_3 = U{ .f = 24 };
781781
782 testing.expect(eql(s_1, s_3));782 try testing.expect(eql(s_1, s_3));
783 testing.expect(eql(&s_1, &s_1));783 try testing.expect(eql(&s_1, &s_1));
784 testing.expect(!eql(&s_1, &s_3));784 try testing.expect(!eql(&s_1, &s_3));
785 testing.expect(eql(u_1, u_3));785 try testing.expect(eql(u_1, u_3));
786 testing.expect(!eql(u_1, u_2));786 try testing.expect(!eql(u_1, u_2));
787787
788 var a1 = "abcdef".*;788 var a1 = "abcdef".*;
789 var a2 = "abcdef".*;789 var a2 = "abcdef".*;
790 var a3 = "ghijkl".*;790 var a3 = "ghijkl".*;
791791
792 testing.expect(eql(a1, a2));792 try testing.expect(eql(a1, a2));
793 testing.expect(!eql(a1, a3));793 try testing.expect(!eql(a1, a3));
794 testing.expect(!eql(a1[0..], a2[0..]));794 try testing.expect(!eql(a1[0..], a2[0..]));
795795
796 const EU = struct {796 const EU = struct {
797 fn tst(err: bool) !u8 {797 fn tst(err: bool) !u8 {
...@@ -800,16 +800,16 @@ test "std.meta.eql" {...@@ -800,16 +800,16 @@ test "std.meta.eql" {
800 }800 }
801 };801 };
802802
803 testing.expect(eql(EU.tst(true), EU.tst(true)));803 try testing.expect(eql(EU.tst(true), EU.tst(true)));
804 testing.expect(eql(EU.tst(false), EU.tst(false)));804 try testing.expect(eql(EU.tst(false), EU.tst(false)));
805 testing.expect(!eql(EU.tst(false), EU.tst(true)));805 try testing.expect(!eql(EU.tst(false), EU.tst(true)));
806806
807 var v1 = @splat(4, @as(u32, 1));807 var v1 = @splat(4, @as(u32, 1));
808 var v2 = @splat(4, @as(u32, 1));808 var v2 = @splat(4, @as(u32, 1));
809 var v3 = @splat(4, @as(u32, 2));809 var v3 = @splat(4, @as(u32, 2));
810810
811 testing.expect(eql(v1, v2));811 try testing.expect(eql(v1, v2));
812 testing.expect(!eql(v1, v3));812 try testing.expect(!eql(v1, v3));
813}813}
814814
815test "intToEnum with error return" {815test "intToEnum with error return" {
...@@ -823,9 +823,9 @@ test "intToEnum with error return" {...@@ -823,9 +823,9 @@ test "intToEnum with error return" {
823823
824 var zero: u8 = 0;824 var zero: u8 = 0;
825 var one: u16 = 1;825 var one: u16 = 1;
826 testing.expect(intToEnum(E1, zero) catch unreachable == E1.A);826 try testing.expect(intToEnum(E1, zero) catch unreachable == E1.A);
827 testing.expect(intToEnum(E2, one) catch unreachable == E2.B);827 try testing.expect(intToEnum(E2, one) catch unreachable == E2.B);
828 testing.expectError(error.InvalidEnumTag, intToEnum(E1, one));828 try testing.expectError(error.InvalidEnumTag, intToEnum(E1, one));
829}829}
830830
831pub const IntToEnumError = error{InvalidEnumTag};831pub const IntToEnumError = error{InvalidEnumTag};
...@@ -1000,27 +1000,27 @@ test "std.meta.cast" {...@@ -1000,27 +1000,27 @@ test "std.meta.cast" {
10001000
1001 var i = @as(i64, 10);1001 var i = @as(i64, 10);
10021002
1003 testing.expect(cast(*u8, 16) == @intToPtr(*u8, 16));1003 try testing.expect(cast(*u8, 16) == @intToPtr(*u8, 16));
1004 testing.expect(cast(*u64, &i).* == @as(u64, 10));1004 try testing.expect(cast(*u64, &i).* == @as(u64, 10));
1005 testing.expect(cast(*i64, @as(?*align(1) i64, &i)) == &i);1005 try testing.expect(cast(*i64, @as(?*align(1) i64, &i)) == &i);
10061006
1007 testing.expect(cast(?*u8, 2) == @intToPtr(*u8, 2));1007 try testing.expect(cast(?*u8, 2) == @intToPtr(*u8, 2));
1008 testing.expect(cast(?*i64, @as(*align(1) i64, &i)) == &i);1008 try testing.expect(cast(?*i64, @as(*align(1) i64, &i)) == &i);
1009 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)));1013 try testing.expectEqual(@as(u32, 4), cast(u32, @intToPtr(*u32, 4)));
1014 testing.expectEqual(@as(u32, 4), cast(u32, @intToPtr(?*u32, 4)));1014 try testing.expectEqual(@as(u32, 4), cast(u32, @intToPtr(?*u32, 4)));
1015 testing.expectEqual(@as(u32, 10), cast(u32, @as(u64, 10)));1015 try testing.expectEqual(@as(u32, 10), cast(u32, @as(u64, 10)));
1016 testing.expectEqual(@as(u8, 2), cast(u8, E.Two));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)));1020 try testing.expectEqual(@intToPtr(*u8, 2), cast(*u8, @intToPtr(*const u8, 2)));
1021 testing.expectEqual(@intToPtr(*u8, 2), cast(*u8, @intToPtr(*volatile 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
1025 const C_ENUM = enum(c_int) {1025 const C_ENUM = enum(c_int) {
1026 A = 0,1026 A = 0,
...@@ -1028,10 +1028,10 @@ test "std.meta.cast" {...@@ -1028,10 +1028,10 @@ test "std.meta.cast" {
1028 C,1028 C,
1029 _,1029 _,
1030 };1030 };
1031 testing.expectEqual(cast(C_ENUM, @as(i64, -1)), @intToEnum(C_ENUM, -1));1031 try testing.expectEqual(cast(C_ENUM, @as(i64, -1)), @intToEnum(C_ENUM, -1));
1032 testing.expectEqual(cast(C_ENUM, @as(i8, 1)), .B);1032 try testing.expectEqual(cast(C_ENUM, @as(i8, 1)), .B);
1033 testing.expectEqual(cast(C_ENUM, @as(u64, 1)), .B);1033 try testing.expectEqual(cast(C_ENUM, @as(u64, 1)), .B);
1034 testing.expectEqual(cast(C_ENUM, @as(u64, 42)), @intToEnum(C_ENUM, 42));1034 try testing.expectEqual(cast(C_ENUM, @as(u64, 42)), @intToEnum(C_ENUM, 42));
1035}1035}
10361036
1037/// Given a value returns its size as C's sizeof operator would.1037/// Given a value returns its size as C's sizeof operator would.
...@@ -1110,43 +1110,43 @@ test "sizeof" {...@@ -1110,43 +1110,43 @@ test "sizeof" {
11101110
1111 const ptr_size = @sizeOf(*c_void);1111 const ptr_size = @sizeOf(*c_void);
11121112
1113 testing.expect(sizeof(u32) == 4);1113 try testing.expect(sizeof(u32) == 4);
1114 testing.expect(sizeof(@as(u32, 2)) == 4);1114 try testing.expect(sizeof(@as(u32, 2)) == 4);
1115 testing.expect(sizeof(2) == @sizeOf(c_int));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));1119 try testing.expect(sizeof(E) == @sizeOf(c_int));
1120 testing.expect(sizeof(E.One) == @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);1124 try testing.expect(sizeof([_]u32{ 4, 5, 6 }) == 12);
1125 testing.expect(sizeof([3]u32) == 12);1125 try testing.expect(sizeof([3]u32) == 12);
1126 testing.expect(sizeof([3:0]u32) == 16);1126 try testing.expect(sizeof([3:0]u32) == 16);
1127 testing.expect(sizeof(&[_]u32{ 4, 5, 6 }) == ptr_size);1127 try testing.expect(sizeof(&[_]u32{ 4, 5, 6 }) == ptr_size);
11281128
1129 testing.expect(sizeof(*u32) == ptr_size);1129 try testing.expect(sizeof(*u32) == ptr_size);
1130 testing.expect(sizeof([*]u32) == ptr_size);1130 try testing.expect(sizeof([*]u32) == ptr_size);
1131 testing.expect(sizeof([*c]u32) == ptr_size);1131 try testing.expect(sizeof([*c]u32) == ptr_size);
1132 testing.expect(sizeof(?*u32) == ptr_size);1132 try testing.expect(sizeof(?*u32) == ptr_size);
1133 testing.expect(sizeof(?[*]u32) == ptr_size);1133 try testing.expect(sizeof(?[*]u32) == ptr_size);
1134 testing.expect(sizeof(*c_void) == ptr_size);1134 try testing.expect(sizeof(*c_void) == ptr_size);
1135 testing.expect(sizeof(*void) == ptr_size);1135 try testing.expect(sizeof(*void) == ptr_size);
1136 testing.expect(sizeof(null) == ptr_size);1136 try testing.expect(sizeof(null) == ptr_size);
11371137
1138 testing.expect(sizeof("foobar") == 7);1138 try testing.expect(sizeof("foobar") == 7);
1139 testing.expect(sizeof(&[_:0]u16{ 'f', 'o', 'o', 'b', 'a', 'r' }) == 14);1139 try testing.expect(sizeof(&[_:0]u16{ 'f', 'o', 'o', 'b', 'a', 'r' }) == 14);
1140 testing.expect(sizeof(*const [4:0]u8) == 5);1140 try testing.expect(sizeof(*const [4:0]u8) == 5);
1141 testing.expect(sizeof(*[4:0]u8) == ptr_size);1141 try testing.expect(sizeof(*[4:0]u8) == ptr_size);
1142 testing.expect(sizeof([*]const [4:0]u8) == ptr_size);1142 try testing.expect(sizeof([*]const [4:0]u8) == ptr_size);
1143 testing.expect(sizeof(*const *const [4:0]u8) == ptr_size);1143 try testing.expect(sizeof(*const *const [4:0]u8) == ptr_size);
1144 testing.expect(sizeof(*const [4]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);1148 try testing.expect(sizeof(void) == 1);
1149 testing.expect(sizeof(c_void) == 1);1149 try testing.expect(sizeof(c_void) == 1);
1150}1150}
11511151
1152pub const CIntLiteralRadix = enum { decimal, octal, hexadecimal };1152pub const CIntLiteralRadix = enum { decimal, octal, hexadecimal };
...@@ -1185,7 +1185,7 @@ pub fn promoteIntLiteral(...@@ -1185,7 +1185,7 @@ pub fn promoteIntLiteral(
11851185
1186test "promoteIntLiteral" {1186test "promoteIntLiteral" {
1187 const signed_hex = promoteIntLiteral(c_int, math.maxInt(c_int) + 1, .hexadecimal);1187 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
1190 if (math.maxInt(c_longlong) == math.maxInt(c_int)) return;1190 if (math.maxInt(c_longlong) == math.maxInt(c_int)) return;
11911191
...@@ -1193,11 +1193,11 @@ test "promoteIntLiteral" {...@@ -1193,11 +1193,11 @@ test "promoteIntLiteral" {
1193 const unsigned = promoteIntLiteral(c_uint, math.maxInt(c_uint) + 1, .hexadecimal);1193 const unsigned = promoteIntLiteral(c_uint, math.maxInt(c_uint) + 1, .hexadecimal);
11941194
1195 if (math.maxInt(c_long) > math.maxInt(c_int)) {1195 if (math.maxInt(c_long) > math.maxInt(c_int)) {
1196 testing.expectEqual(c_long, @TypeOf(signed_decimal));1196 try testing.expectEqual(c_long, @TypeOf(signed_decimal));
1197 testing.expectEqual(c_ulong, @TypeOf(unsigned));1197 try testing.expectEqual(c_ulong, @TypeOf(unsigned));
1198 } else {1198 } else {
1199 testing.expectEqual(c_longlong, @TypeOf(signed_decimal));1199 try testing.expectEqual(c_longlong, @TypeOf(signed_decimal));
1200 testing.expectEqual(c_ulonglong, @TypeOf(unsigned));1200 try testing.expectEqual(c_ulonglong, @TypeOf(unsigned));
1201 }1201 }
1202}1202}
12031203
...@@ -1339,17 +1339,17 @@ pub fn shuffleVectorIndex(comptime this_index: c_int, comptime source_vector_len...@@ -1339,17 +1339,17 @@ pub fn shuffleVectorIndex(comptime this_index: c_int, comptime source_vector_len
1339test "shuffleVectorIndex" {1339test "shuffleVectorIndex" {
1340 const vector_len: usize = 4;1340 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);1344 try testing.expect(shuffleVectorIndex(0, vector_len) == 0);
1345 testing.expect(shuffleVectorIndex(1, vector_len) == 1);1345 try testing.expect(shuffleVectorIndex(1, vector_len) == 1);
1346 testing.expect(shuffleVectorIndex(2, vector_len) == 2);1346 try testing.expect(shuffleVectorIndex(2, vector_len) == 2);
1347 testing.expect(shuffleVectorIndex(3, vector_len) == 3);1347 try testing.expect(shuffleVectorIndex(3, vector_len) == 3);
13481348
1349 testing.expect(shuffleVectorIndex(4, vector_len) == -1);1349 try testing.expect(shuffleVectorIndex(4, vector_len) == -1);
1350 testing.expect(shuffleVectorIndex(5, vector_len) == -2);1350 try testing.expect(shuffleVectorIndex(5, vector_len) == -2);
1351 testing.expect(shuffleVectorIndex(6, vector_len) == -3);1351 try testing.expect(shuffleVectorIndex(6, vector_len) == -3);
1352 testing.expect(shuffleVectorIndex(7, vector_len) == -4);1352 try testing.expect(shuffleVectorIndex(7, vector_len) == -4);
1353}1353}
13541354
1355/// Returns whether `error_union` contains an error.1355/// Returns whether `error_union` contains an error.
...@@ -1358,6 +1358,6 @@ pub fn isError(error_union: anytype) bool {...@@ -1358,6 +1358,6 @@ pub fn isError(error_union: anytype) bool {
1358}1358}
13591359
1360test "isError" {1360test "isError" {
1361 std.testing.expect(isError(math.absInt(@as(i8, -128))));1361 try std.testing.expect(isError(math.absInt(@as(i8, -128))));
1362 std.testing.expect(!isError(math.absInt(@as(i8, -127))));1362 try std.testing.expect(!isError(math.absInt(@as(i8, -127))));
1363}1363}
lib/std/meta/trailer_flags.zig+7-7
...@@ -146,7 +146,7 @@ test "TrailerFlags" {...@@ -146,7 +146,7 @@ test "TrailerFlags" {
146 b: bool,146 b: bool,
147 c: u64,147 c: u64,
148 });148 });
149 testing.expectEqual(u2, meta.Tag(Flags.FieldEnum));149 try testing.expectEqual(u2, meta.Tag(Flags.FieldEnum));
150150
151 var flags = Flags.init(.{151 var flags = Flags.init(.{
152 .b = true,152 .b = true,
...@@ -158,16 +158,16 @@ test "TrailerFlags" {...@@ -158,16 +158,16 @@ test "TrailerFlags" {
158 flags.set(slice.ptr, .b, false);158 flags.set(slice.ptr, .b, false);
159 flags.set(slice.ptr, .c, 12345678);159 flags.set(slice.ptr, .c, 12345678);
160160
161 testing.expect(flags.get(slice.ptr, .a) == null);161 try testing.expect(flags.get(slice.ptr, .a) == null);
162 testing.expect(!flags.get(slice.ptr, .b).?);162 try testing.expect(!flags.get(slice.ptr, .b).?);
163 testing.expect(flags.get(slice.ptr, .c).? == 12345678);163 try testing.expect(flags.get(slice.ptr, .c).? == 12345678);
164164
165 flags.setMany(slice.ptr, .{165 flags.setMany(slice.ptr, .{
166 .b = true,166 .b = true,
167 .c = 5678,167 .c = 5678,
168 });168 });
169169
170 testing.expect(flags.get(slice.ptr, .a) == null);170 try testing.expect(flags.get(slice.ptr, .a) == null);
171 testing.expect(flags.get(slice.ptr, .b).?);171 try testing.expect(flags.get(slice.ptr, .b).?);
172 testing.expect(flags.get(slice.ptr, .c).? == 5678);172 try testing.expect(flags.get(slice.ptr, .c).? == 5678);
173}173}
lib/std/meta/trait.zig+142-142
...@@ -45,8 +45,8 @@ test "std.meta.trait.multiTrait" {...@@ -45,8 +45,8 @@ test "std.meta.trait.multiTrait" {
45 hasField("x"),45 hasField("x"),
46 hasField("y"),46 hasField("y"),
47 });47 });
48 testing.expect(isVector(Vector2));48 try testing.expect(isVector(Vector2));
49 testing.expect(!isVector(u8));49 try testing.expect(!isVector(u8));
50}50}
5151
52pub fn hasFn(comptime name: []const u8) TraitFn {52pub fn hasFn(comptime name: []const u8) TraitFn {
...@@ -66,9 +66,9 @@ test "std.meta.trait.hasFn" {...@@ -66,9 +66,9 @@ test "std.meta.trait.hasFn" {
66 pub fn useless() void {}66 pub fn useless() void {}
67 };67 };
6868
69 testing.expect(hasFn("useless")(TestStruct));69 try testing.expect(hasFn("useless")(TestStruct));
70 testing.expect(!hasFn("append")(TestStruct));70 try testing.expect(!hasFn("append")(TestStruct));
71 testing.expect(!hasFn("useless")(u8));71 try testing.expect(!hasFn("useless")(u8));
72}72}
7373
74pub fn hasField(comptime name: []const u8) TraitFn {74pub fn hasField(comptime name: []const u8) TraitFn {
...@@ -96,11 +96,11 @@ test "std.meta.trait.hasField" {...@@ -96,11 +96,11 @@ test "std.meta.trait.hasField" {
96 value: u32,96 value: u32,
97 };97 };
9898
99 testing.expect(hasField("value")(TestStruct));99 try testing.expect(hasField("value")(TestStruct));
100 testing.expect(!hasField("value")(*TestStruct));100 try testing.expect(!hasField("value")(*TestStruct));
101 testing.expect(!hasField("x")(TestStruct));101 try testing.expect(!hasField("x")(TestStruct));
102 testing.expect(!hasField("x")(**TestStruct));102 try testing.expect(!hasField("x")(**TestStruct));
103 testing.expect(!hasField("value")(u8));103 try testing.expect(!hasField("value")(u8));
104}104}
105105
106pub fn is(comptime id: builtin.TypeId) TraitFn {106pub fn is(comptime id: builtin.TypeId) TraitFn {
...@@ -113,11 +113,11 @@ pub fn is(comptime id: builtin.TypeId) TraitFn {...@@ -113,11 +113,11 @@ pub fn is(comptime id: builtin.TypeId) TraitFn {
113}113}
114114
115test "std.meta.trait.is" {115test "std.meta.trait.is" {
116 testing.expect(is(.Int)(u8));116 try testing.expect(is(.Int)(u8));
117 testing.expect(!is(.Int)(f32));117 try testing.expect(!is(.Int)(f32));
118 testing.expect(is(.Pointer)(*u8));118 try testing.expect(is(.Pointer)(*u8));
119 testing.expect(is(.Void)(void));119 try testing.expect(is(.Void)(void));
120 testing.expect(!is(.Optional)(anyerror));120 try testing.expect(!is(.Optional)(anyerror));
121}121}
122122
123pub fn isPtrTo(comptime id: builtin.TypeId) TraitFn {123pub fn isPtrTo(comptime id: builtin.TypeId) TraitFn {
...@@ -131,9 +131,9 @@ pub fn isPtrTo(comptime id: builtin.TypeId) TraitFn {...@@ -131,9 +131,9 @@ pub fn isPtrTo(comptime id: builtin.TypeId) TraitFn {
131}131}
132132
133test "std.meta.trait.isPtrTo" {133test "std.meta.trait.isPtrTo" {
134 testing.expect(!isPtrTo(.Struct)(struct {}));134 try testing.expect(!isPtrTo(.Struct)(struct {}));
135 testing.expect(isPtrTo(.Struct)(*struct {}));135 try testing.expect(isPtrTo(.Struct)(*struct {}));
136 testing.expect(!isPtrTo(.Struct)(**struct {}));136 try testing.expect(!isPtrTo(.Struct)(**struct {}));
137}137}
138138
139pub fn isSliceOf(comptime id: builtin.TypeId) TraitFn {139pub fn isSliceOf(comptime id: builtin.TypeId) TraitFn {
...@@ -147,9 +147,9 @@ pub fn isSliceOf(comptime id: builtin.TypeId) TraitFn {...@@ -147,9 +147,9 @@ pub fn isSliceOf(comptime id: builtin.TypeId) TraitFn {
147}147}
148148
149test "std.meta.trait.isSliceOf" {149test "std.meta.trait.isSliceOf" {
150 testing.expect(!isSliceOf(.Struct)(struct {}));150 try testing.expect(!isSliceOf(.Struct)(struct {}));
151 testing.expect(isSliceOf(.Struct)([]struct {}));151 try testing.expect(isSliceOf(.Struct)([]struct {}));
152 testing.expect(!isSliceOf(.Struct)([][]struct {}));152 try testing.expect(!isSliceOf(.Struct)([][]struct {}));
153}153}
154154
155///////////Strait trait Fns155///////////Strait trait Fns
...@@ -170,9 +170,9 @@ test "std.meta.trait.isExtern" {...@@ -170,9 +170,9 @@ test "std.meta.trait.isExtern" {
170 const TestExStruct = extern struct {};170 const TestExStruct = extern struct {};
171 const TestStruct = struct {};171 const TestStruct = struct {};
172172
173 testing.expect(isExtern(TestExStruct));173 try testing.expect(isExtern(TestExStruct));
174 testing.expect(!isExtern(TestStruct));174 try testing.expect(!isExtern(TestStruct));
175 testing.expect(!isExtern(u8));175 try testing.expect(!isExtern(u8));
176}176}
177177
178pub fn isPacked(comptime T: type) bool {178pub fn isPacked(comptime T: type) bool {
...@@ -188,9 +188,9 @@ test "std.meta.trait.isPacked" {...@@ -188,9 +188,9 @@ test "std.meta.trait.isPacked" {
188 const TestPStruct = packed struct {};188 const TestPStruct = packed struct {};
189 const TestStruct = struct {};189 const TestStruct = struct {};
190190
191 testing.expect(isPacked(TestPStruct));191 try testing.expect(isPacked(TestPStruct));
192 testing.expect(!isPacked(TestStruct));192 try testing.expect(!isPacked(TestStruct));
193 testing.expect(!isPacked(u8));193 try testing.expect(!isPacked(u8));
194}194}
195195
196pub fn isUnsignedInt(comptime T: type) bool {196pub fn isUnsignedInt(comptime T: type) bool {
...@@ -201,10 +201,10 @@ pub fn isUnsignedInt(comptime T: type) bool {...@@ -201,10 +201,10 @@ pub fn isUnsignedInt(comptime T: type) bool {
201}201}
202202
203test "isUnsignedInt" {203test "isUnsignedInt" {
204 testing.expect(isUnsignedInt(u32) == true);204 try testing.expect(isUnsignedInt(u32) == true);
205 testing.expect(isUnsignedInt(comptime_int) == false);205 try testing.expect(isUnsignedInt(comptime_int) == false);
206 testing.expect(isUnsignedInt(i64) == false);206 try testing.expect(isUnsignedInt(i64) == false);
207 testing.expect(isUnsignedInt(f64) == false);207 try testing.expect(isUnsignedInt(f64) == false);
208}208}
209209
210pub fn isSignedInt(comptime T: type) bool {210pub fn isSignedInt(comptime T: type) bool {
...@@ -216,10 +216,10 @@ pub fn isSignedInt(comptime T: type) bool {...@@ -216,10 +216,10 @@ pub fn isSignedInt(comptime T: type) bool {
216}216}
217217
218test "isSignedInt" {218test "isSignedInt" {
219 testing.expect(isSignedInt(u32) == false);219 try testing.expect(isSignedInt(u32) == false);
220 testing.expect(isSignedInt(comptime_int) == true);220 try testing.expect(isSignedInt(comptime_int) == true);
221 testing.expect(isSignedInt(i64) == true);221 try testing.expect(isSignedInt(i64) == true);
222 testing.expect(isSignedInt(f64) == false);222 try testing.expect(isSignedInt(f64) == false);
223}223}
224224
225pub fn isSingleItemPtr(comptime T: type) bool {225pub fn isSingleItemPtr(comptime T: type) bool {
...@@ -231,10 +231,10 @@ pub fn isSingleItemPtr(comptime T: type) bool {...@@ -231,10 +231,10 @@ pub fn isSingleItemPtr(comptime T: type) bool {
231231
232test "std.meta.trait.isSingleItemPtr" {232test "std.meta.trait.isSingleItemPtr" {
233 const array = [_]u8{0} ** 10;233 const array = [_]u8{0} ** 10;
234 comptime testing.expect(isSingleItemPtr(@TypeOf(&array[0])));234 comptime try testing.expect(isSingleItemPtr(@TypeOf(&array[0])));
235 comptime testing.expect(!isSingleItemPtr(@TypeOf(array)));235 comptime try testing.expect(!isSingleItemPtr(@TypeOf(array)));
236 var runtime_zero: usize = 0;236 var runtime_zero: usize = 0;
237 testing.expect(!isSingleItemPtr(@TypeOf(array[runtime_zero..1])));237 try testing.expect(!isSingleItemPtr(@TypeOf(array[runtime_zero..1])));
238}238}
239239
240pub fn isManyItemPtr(comptime T: type) bool {240pub fn isManyItemPtr(comptime T: type) bool {
...@@ -247,9 +247,9 @@ pub fn isManyItemPtr(comptime T: type) bool {...@@ -247,9 +247,9 @@ pub fn isManyItemPtr(comptime T: type) bool {
247test "std.meta.trait.isManyItemPtr" {247test "std.meta.trait.isManyItemPtr" {
248 const array = [_]u8{0} ** 10;248 const array = [_]u8{0} ** 10;
249 const mip = @ptrCast([*]const u8, &array[0]);249 const mip = @ptrCast([*]const u8, &array[0]);
250 testing.expect(isManyItemPtr(@TypeOf(mip)));250 try testing.expect(isManyItemPtr(@TypeOf(mip)));
251 testing.expect(!isManyItemPtr(@TypeOf(array)));251 try testing.expect(!isManyItemPtr(@TypeOf(array)));
252 testing.expect(!isManyItemPtr(@TypeOf(array[0..1])));252 try testing.expect(!isManyItemPtr(@TypeOf(array[0..1])));
253}253}
254254
255pub fn isSlice(comptime T: type) bool {255pub fn isSlice(comptime T: type) bool {
...@@ -262,9 +262,9 @@ pub fn isSlice(comptime T: type) bool {...@@ -262,9 +262,9 @@ pub fn isSlice(comptime T: type) bool {
262test "std.meta.trait.isSlice" {262test "std.meta.trait.isSlice" {
263 const array = [_]u8{0} ** 10;263 const array = [_]u8{0} ** 10;
264 var runtime_zero: usize = 0;264 var runtime_zero: usize = 0;
265 testing.expect(isSlice(@TypeOf(array[runtime_zero..])));265 try testing.expect(isSlice(@TypeOf(array[runtime_zero..])));
266 testing.expect(!isSlice(@TypeOf(array)));266 try testing.expect(!isSlice(@TypeOf(array)));
267 testing.expect(!isSlice(@TypeOf(&array[0])));267 try testing.expect(!isSlice(@TypeOf(&array[0])));
268}268}
269269
270pub fn isIndexable(comptime T: type) bool {270pub fn isIndexable(comptime T: type) bool {
...@@ -283,12 +283,12 @@ test "std.meta.trait.isIndexable" {...@@ -283,12 +283,12 @@ test "std.meta.trait.isIndexable" {
283 const vector: meta.Vector(2, u32) = [_]u32{0} ** 2;283 const vector: meta.Vector(2, u32) = [_]u32{0} ** 2;
284 const tuple = .{ 1, 2, 3 };284 const tuple = .{ 1, 2, 3 };
285285
286 testing.expect(isIndexable(@TypeOf(array)));286 try testing.expect(isIndexable(@TypeOf(array)));
287 testing.expect(isIndexable(@TypeOf(&array)));287 try testing.expect(isIndexable(@TypeOf(&array)));
288 testing.expect(isIndexable(@TypeOf(slice)));288 try testing.expect(isIndexable(@TypeOf(slice)));
289 testing.expect(!isIndexable(meta.Child(@TypeOf(slice))));289 try testing.expect(!isIndexable(meta.Child(@TypeOf(slice))));
290 testing.expect(isIndexable(@TypeOf(vector)));290 try testing.expect(isIndexable(@TypeOf(vector)));
291 testing.expect(isIndexable(@TypeOf(tuple)));291 try testing.expect(isIndexable(@TypeOf(tuple)));
292}292}
293293
294pub fn isNumber(comptime T: type) bool {294pub fn isNumber(comptime T: type) bool {
...@@ -317,13 +317,13 @@ test "std.meta.trait.isNumber" {...@@ -317,13 +317,13 @@ test "std.meta.trait.isNumber" {
317 number: u8,317 number: u8,
318 };318 };
319319
320 testing.expect(isNumber(u32));320 try testing.expect(isNumber(u32));
321 testing.expect(isNumber(f32));321 try testing.expect(isNumber(f32));
322 testing.expect(isNumber(u64));322 try testing.expect(isNumber(u64));
323 testing.expect(isNumber(@TypeOf(102)));323 try testing.expect(isNumber(@TypeOf(102)));
324 testing.expect(isNumber(@TypeOf(102.123)));324 try testing.expect(isNumber(@TypeOf(102.123)));
325 testing.expect(!isNumber([]u8));325 try testing.expect(!isNumber([]u8));
326 testing.expect(!isNumber(NotANumber));326 try testing.expect(!isNumber(NotANumber));
327}327}
328328
329pub fn isIntegral(comptime T: type) bool {329pub fn isIntegral(comptime T: type) bool {
...@@ -334,12 +334,12 @@ pub fn isIntegral(comptime T: type) bool {...@@ -334,12 +334,12 @@ pub fn isIntegral(comptime T: type) bool {
334}334}
335335
336test "isIntegral" {336test "isIntegral" {
337 testing.expect(isIntegral(u32));337 try testing.expect(isIntegral(u32));
338 testing.expect(!isIntegral(f32));338 try testing.expect(!isIntegral(f32));
339 testing.expect(isIntegral(@TypeOf(102)));339 try testing.expect(isIntegral(@TypeOf(102)));
340 testing.expect(!isIntegral(@TypeOf(102.123)));340 try testing.expect(!isIntegral(@TypeOf(102.123)));
341 testing.expect(!isIntegral(*u8));341 try testing.expect(!isIntegral(*u8));
342 testing.expect(!isIntegral([]u8));342 try testing.expect(!isIntegral([]u8));
343}343}
344344
345pub fn isFloat(comptime T: type) bool {345pub fn isFloat(comptime T: type) bool {
...@@ -350,12 +350,12 @@ pub fn isFloat(comptime T: type) bool {...@@ -350,12 +350,12 @@ pub fn isFloat(comptime T: type) bool {
350}350}
351351
352test "isFloat" {352test "isFloat" {
353 testing.expect(!isFloat(u32));353 try testing.expect(!isFloat(u32));
354 testing.expect(isFloat(f32));354 try testing.expect(isFloat(f32));
355 testing.expect(!isFloat(@TypeOf(102)));355 try testing.expect(!isFloat(@TypeOf(102)));
356 testing.expect(isFloat(@TypeOf(102.123)));356 try testing.expect(isFloat(@TypeOf(102.123)));
357 testing.expect(!isFloat(*f64));357 try testing.expect(!isFloat(*f64));
358 testing.expect(!isFloat([]f32));358 try testing.expect(!isFloat([]f32));
359}359}
360360
361pub fn isConstPtr(comptime T: type) bool {361pub fn isConstPtr(comptime T: type) bool {
...@@ -366,10 +366,10 @@ pub fn isConstPtr(comptime T: type) bool {...@@ -366,10 +366,10 @@ pub fn isConstPtr(comptime T: type) bool {
366test "std.meta.trait.isConstPtr" {366test "std.meta.trait.isConstPtr" {
367 var t = @as(u8, 0);367 var t = @as(u8, 0);
368 const c = @as(u8, 0);368 const c = @as(u8, 0);
369 testing.expect(isConstPtr(*const @TypeOf(t)));369 try testing.expect(isConstPtr(*const @TypeOf(t)));
370 testing.expect(isConstPtr(@TypeOf(&c)));370 try testing.expect(isConstPtr(@TypeOf(&c)));
371 testing.expect(!isConstPtr(*@TypeOf(t)));371 try testing.expect(!isConstPtr(*@TypeOf(t)));
372 testing.expect(!isConstPtr(@TypeOf(6)));372 try testing.expect(!isConstPtr(@TypeOf(6)));
373}373}
374374
375pub fn isContainer(comptime T: type) bool {375pub fn isContainer(comptime T: type) bool {
...@@ -389,10 +389,10 @@ test "std.meta.trait.isContainer" {...@@ -389,10 +389,10 @@ test "std.meta.trait.isContainer" {
389 B,389 B,
390 };390 };
391391
392 testing.expect(isContainer(TestStruct));392 try testing.expect(isContainer(TestStruct));
393 testing.expect(isContainer(TestUnion));393 try testing.expect(isContainer(TestUnion));
394 testing.expect(isContainer(TestEnum));394 try testing.expect(isContainer(TestEnum));
395 testing.expect(!isContainer(u8));395 try testing.expect(!isContainer(u8));
396}396}
397397
398pub fn isTuple(comptime T: type) bool {398pub fn isTuple(comptime T: type) bool {
...@@ -403,9 +403,9 @@ test "std.meta.trait.isTuple" {...@@ -403,9 +403,9 @@ test "std.meta.trait.isTuple" {
403 const t1 = struct {};403 const t1 = struct {};
404 const t2 = .{ .a = 0 };404 const t2 = .{ .a = 0 };
405 const t3 = .{ 1, 2, 3 };405 const t3 = .{ 1, 2, 3 };
406 testing.expect(!isTuple(t1));406 try testing.expect(!isTuple(t1));
407 testing.expect(!isTuple(@TypeOf(t2)));407 try testing.expect(!isTuple(@TypeOf(t2)));
408 testing.expect(isTuple(@TypeOf(t3)));408 try testing.expect(isTuple(@TypeOf(t3)));
409}409}
410410
411/// Returns true if the passed type will coerce to []const u8.411/// Returns true if the passed type will coerce to []const u8.
...@@ -449,41 +449,41 @@ pub fn isZigString(comptime T: type) bool {...@@ -449,41 +449,41 @@ pub fn isZigString(comptime T: type) bool {
449}449}
450450
451test "std.meta.trait.isZigString" {451test "std.meta.trait.isZigString" {
452 testing.expect(isZigString([]const u8));452 try testing.expect(isZigString([]const u8));
453 testing.expect(isZigString([]u8));453 try testing.expect(isZigString([]u8));
454 testing.expect(isZigString([:0]const u8));454 try testing.expect(isZigString([:0]const u8));
455 testing.expect(isZigString([:0]u8));455 try testing.expect(isZigString([:0]u8));
456 testing.expect(isZigString([:5]const u8));456 try testing.expect(isZigString([:5]const u8));
457 testing.expect(isZigString([:5]u8));457 try testing.expect(isZigString([:5]u8));
458 testing.expect(isZigString(*const [0]u8));458 try testing.expect(isZigString(*const [0]u8));
459 testing.expect(isZigString(*[0]u8));459 try testing.expect(isZigString(*[0]u8));
460 testing.expect(isZigString(*const [0:0]u8));460 try testing.expect(isZigString(*const [0:0]u8));
461 testing.expect(isZigString(*[0:0]u8));461 try testing.expect(isZigString(*[0:0]u8));
462 testing.expect(isZigString(*const [0:5]u8));462 try testing.expect(isZigString(*const [0:5]u8));
463 testing.expect(isZigString(*[0:5]u8));463 try testing.expect(isZigString(*[0:5]u8));
464 testing.expect(isZigString(*const [10]u8));464 try testing.expect(isZigString(*const [10]u8));
465 testing.expect(isZigString(*[10]u8));465 try testing.expect(isZigString(*[10]u8));
466 testing.expect(isZigString(*const [10:0]u8));466 try testing.expect(isZigString(*const [10:0]u8));
467 testing.expect(isZigString(*[10:0]u8));467 try testing.expect(isZigString(*[10:0]u8));
468 testing.expect(isZigString(*const [10:5]u8));468 try testing.expect(isZigString(*const [10:5]u8));
469 testing.expect(isZigString(*[10:5]u8));469 try testing.expect(isZigString(*[10:5]u8));
470470
471 testing.expect(!isZigString(u8));471 try testing.expect(!isZigString(u8));
472 testing.expect(!isZigString([4]u8));472 try testing.expect(!isZigString([4]u8));
473 testing.expect(!isZigString([4:0]u8));473 try testing.expect(!isZigString([4:0]u8));
474 testing.expect(!isZigString([*]const u8));474 try testing.expect(!isZigString([*]const u8));
475 testing.expect(!isZigString([*]const [4]u8));475 try testing.expect(!isZigString([*]const [4]u8));
476 testing.expect(!isZigString([*c]const u8));476 try testing.expect(!isZigString([*c]const u8));
477 testing.expect(!isZigString([*c]const [4]u8));477 try testing.expect(!isZigString([*c]const [4]u8));
478 testing.expect(!isZigString([*:0]const u8));478 try testing.expect(!isZigString([*:0]const u8));
479 testing.expect(!isZigString([*:0]const u8));479 try testing.expect(!isZigString([*:0]const u8));
480 testing.expect(!isZigString(*[]const u8));480 try testing.expect(!isZigString(*[]const u8));
481 testing.expect(!isZigString(?[]const u8));481 try testing.expect(!isZigString(?[]const u8));
482 testing.expect(!isZigString(?*const [4]u8));482 try testing.expect(!isZigString(?*const [4]u8));
483 testing.expect(!isZigString([]allowzero u8));483 try testing.expect(!isZigString([]allowzero u8));
484 testing.expect(!isZigString([]volatile u8));484 try testing.expect(!isZigString([]volatile u8));
485 testing.expect(!isZigString(*allowzero [4]u8));485 try testing.expect(!isZigString(*allowzero [4]u8));
486 testing.expect(!isZigString(*volatile [4]u8));486 try testing.expect(!isZigString(*volatile [4]u8));
487}487}
488488
489pub fn hasDecls(comptime T: type, comptime names: anytype) bool {489pub fn hasDecls(comptime T: type, comptime names: anytype) bool {
...@@ -505,11 +505,11 @@ test "std.meta.trait.hasDecls" {...@@ -505,11 +505,11 @@ test "std.meta.trait.hasDecls" {
505505
506 const tuple = .{ "a", "b", "c" };506 const tuple = .{ "a", "b", "c" };
507507
508 testing.expect(!hasDecls(TestStruct1, .{"a"}));508 try testing.expect(!hasDecls(TestStruct1, .{"a"}));
509 testing.expect(hasDecls(TestStruct2, .{ "a", "b" }));509 try testing.expect(hasDecls(TestStruct2, .{ "a", "b" }));
510 testing.expect(hasDecls(TestStruct2, .{ "a", "b", "useless" }));510 try testing.expect(hasDecls(TestStruct2, .{ "a", "b", "useless" }));
511 testing.expect(!hasDecls(TestStruct2, .{ "a", "b", "c" }));511 try testing.expect(!hasDecls(TestStruct2, .{ "a", "b", "c" }));
512 testing.expect(!hasDecls(TestStruct2, tuple));512 try testing.expect(!hasDecls(TestStruct2, tuple));
513}513}
514514
515pub fn hasFields(comptime T: type, comptime names: anytype) bool {515pub fn hasFields(comptime T: type, comptime names: anytype) bool {
...@@ -531,11 +531,11 @@ test "std.meta.trait.hasFields" {...@@ -531,11 +531,11 @@ test "std.meta.trait.hasFields" {
531531
532 const tuple = .{ "a", "b", "c" };532 const tuple = .{ "a", "b", "c" };
533533
534 testing.expect(!hasFields(TestStruct1, .{"a"}));534 try testing.expect(!hasFields(TestStruct1, .{"a"}));
535 testing.expect(hasFields(TestStruct2, .{ "a", "b" }));535 try testing.expect(hasFields(TestStruct2, .{ "a", "b" }));
536 testing.expect(hasFields(TestStruct2, .{ "a", "b", "c" }));536 try testing.expect(hasFields(TestStruct2, .{ "a", "b", "c" }));
537 testing.expect(hasFields(TestStruct2, tuple));537 try testing.expect(hasFields(TestStruct2, tuple));
538 testing.expect(!hasFields(TestStruct2, .{ "a", "b", "useless" }));538 try testing.expect(!hasFields(TestStruct2, .{ "a", "b", "useless" }));
539}539}
540540
541pub fn hasFunctions(comptime T: type, comptime names: anytype) bool {541pub fn hasFunctions(comptime T: type, comptime names: anytype) bool {
...@@ -555,10 +555,10 @@ test "std.meta.trait.hasFunctions" {...@@ -555,10 +555,10 @@ test "std.meta.trait.hasFunctions" {
555555
556 const tuple = .{ "a", "b", "c" };556 const tuple = .{ "a", "b", "c" };
557557
558 testing.expect(!hasFunctions(TestStruct1, .{"a"}));558 try testing.expect(!hasFunctions(TestStruct1, .{"a"}));
559 testing.expect(hasFunctions(TestStruct2, .{ "a", "b" }));559 try testing.expect(hasFunctions(TestStruct2, .{ "a", "b" }));
560 testing.expect(!hasFunctions(TestStruct2, .{ "a", "b", "c" }));560 try testing.expect(!hasFunctions(TestStruct2, .{ "a", "b", "c" }));
561 testing.expect(!hasFunctions(TestStruct2, tuple));561 try testing.expect(!hasFunctions(TestStruct2, tuple));
562}562}
563563
564/// True if every value of the type `T` has a unique bit pattern representing it.564/// True if every value of the type `T` has a unique bit pattern representing it.
...@@ -606,65 +606,65 @@ test "std.meta.trait.hasUniqueRepresentation" {...@@ -606,65 +606,65 @@ test "std.meta.trait.hasUniqueRepresentation" {
606 b: u32,606 b: u32,
607 };607 };
608608
609 testing.expect(hasUniqueRepresentation(TestStruct1));609 try testing.expect(hasUniqueRepresentation(TestStruct1));
610610
611 const TestStruct2 = struct {611 const TestStruct2 = struct {
612 a: u32,612 a: u32,
613 b: u16,613 b: u16,
614 };614 };
615615
616 testing.expect(!hasUniqueRepresentation(TestStruct2));616 try testing.expect(!hasUniqueRepresentation(TestStruct2));
617617
618 const TestStruct3 = struct {618 const TestStruct3 = struct {
619 a: u32,619 a: u32,
620 b: u32,620 b: u32,
621 };621 };
622622
623 testing.expect(hasUniqueRepresentation(TestStruct3));623 try testing.expect(hasUniqueRepresentation(TestStruct3));
624624
625 const TestStruct4 = struct { a: []const u8 };625 const TestStruct4 = struct { a: []const u8 };
626626
627 testing.expect(!hasUniqueRepresentation(TestStruct4));627 try testing.expect(!hasUniqueRepresentation(TestStruct4));
628628
629 const TestStruct5 = struct { a: TestStruct4 };629 const TestStruct5 = struct { a: TestStruct4 };
630630
631 testing.expect(!hasUniqueRepresentation(TestStruct5));631 try testing.expect(!hasUniqueRepresentation(TestStruct5));
632632
633 const TestUnion1 = packed union {633 const TestUnion1 = packed union {
634 a: u32,634 a: u32,
635 b: u16,635 b: u16,
636 };636 };
637637
638 testing.expect(!hasUniqueRepresentation(TestUnion1));638 try testing.expect(!hasUniqueRepresentation(TestUnion1));
639639
640 const TestUnion2 = extern union {640 const TestUnion2 = extern union {
641 a: u32,641 a: u32,
642 b: u16,642 b: u16,
643 };643 };
644644
645 testing.expect(!hasUniqueRepresentation(TestUnion2));645 try testing.expect(!hasUniqueRepresentation(TestUnion2));
646646
647 const TestUnion3 = union {647 const TestUnion3 = union {
648 a: u32,648 a: u32,
649 b: u16,649 b: u16,
650 };650 };
651651
652 testing.expect(!hasUniqueRepresentation(TestUnion3));652 try testing.expect(!hasUniqueRepresentation(TestUnion3));
653653
654 const TestUnion4 = union(enum) {654 const TestUnion4 = union(enum) {
655 a: u32,655 a: u32,
656 b: u16,656 b: u16,
657 };657 };
658658
659 testing.expect(!hasUniqueRepresentation(TestUnion4));659 try testing.expect(!hasUniqueRepresentation(TestUnion4));
660660
661 inline for ([_]type{ i0, u8, i16, u32, i64 }) |T| {661 inline for ([_]type{ i0, u8, i16, u32, i64 }) |T| {
662 testing.expect(hasUniqueRepresentation(T));662 try testing.expect(hasUniqueRepresentation(T));
663 }663 }
664 inline for ([_]type{ i1, u9, i17, u33, i24 }) |T| {664 inline for ([_]type{ i1, u9, i17, u33, i24 }) |T| {
665 testing.expect(!hasUniqueRepresentation(T));665 try testing.expect(!hasUniqueRepresentation(T));
666 }666 }
667667
668 testing.expect(!hasUniqueRepresentation([]u8));668 try testing.expect(!hasUniqueRepresentation([]u8));
669 testing.expect(!hasUniqueRepresentation([]const u8));669 try testing.expect(!hasUniqueRepresentation([]const u8));
670}670}
lib/std/multi_array_list.zig+57-57
...@@ -312,7 +312,7 @@ test "basic usage" {...@@ -312,7 +312,7 @@ test "basic usage" {
312 var list = MultiArrayList(Foo){};312 var list = MultiArrayList(Foo){};
313 defer list.deinit(ally);313 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
317 try list.ensureTotalCapacity(ally, 2);317 try list.ensureTotalCapacity(ally, 2);
318318
...@@ -328,12 +328,12 @@ test "basic usage" {...@@ -328,12 +328,12 @@ test "basic usage" {
328 .c = 'b',328 .c = 'b',
329 });329 });
330330
331 testing.expectEqualSlices(u32, list.items(.a), &[_]u32{ 1, 2 });331 try testing.expectEqualSlices(u32, list.items(.a), &[_]u32{ 1, 2 });
332 testing.expectEqualSlices(u8, list.items(.c), &[_]u8{ 'a', 'b' });332 try testing.expectEqualSlices(u8, list.items(.c), &[_]u8{ 'a', 'b' });
333333
334 testing.expectEqual(@as(usize, 2), list.items(.b).len);334 try testing.expectEqual(@as(usize, 2), list.items(.b).len);
335 testing.expectEqualStrings("foobar", list.items(.b)[0]);335 try testing.expectEqualStrings("foobar", list.items(.b)[0]);
336 testing.expectEqualStrings("zigzag", list.items(.b)[1]);336 try testing.expectEqualStrings("zigzag", list.items(.b)[1]);
337337
338 try list.append(ally, .{338 try list.append(ally, .{
339 .a = 3,339 .a = 3,
...@@ -341,13 +341,13 @@ test "basic usage" {...@@ -341,13 +341,13 @@ test "basic usage" {
341 .c = 'c',341 .c = 'c',
342 });342 });
343343
344 testing.expectEqualSlices(u32, list.items(.a), &[_]u32{ 1, 2, 3 });344 try testing.expectEqualSlices(u32, list.items(.a), &[_]u32{ 1, 2, 3 });
345 testing.expectEqualSlices(u8, list.items(.c), &[_]u8{ 'a', 'b', 'c' });345 try testing.expectEqualSlices(u8, list.items(.c), &[_]u8{ 'a', 'b', 'c' });
346346
347 testing.expectEqual(@as(usize, 3), list.items(.b).len);347 try testing.expectEqual(@as(usize, 3), list.items(.b).len);
348 testing.expectEqualStrings("foobar", list.items(.b)[0]);348 try testing.expectEqualStrings("foobar", list.items(.b)[0]);
349 testing.expectEqualStrings("zigzag", list.items(.b)[1]);349 try testing.expectEqualStrings("zigzag", list.items(.b)[1]);
350 testing.expectEqualStrings("fizzbuzz", list.items(.b)[2]);350 try testing.expectEqualStrings("fizzbuzz", list.items(.b)[2]);
351351
352 // Add 6 more things to force a capacity increase.352 // Add 6 more things to force a capacity increase.
353 var i: usize = 0;353 var i: usize = 0;
...@@ -359,12 +359,12 @@ test "basic usage" {...@@ -359,12 +359,12 @@ test "basic usage" {
359 });359 });
360 }360 }
361361
362 testing.expectEqualSlices(362 try testing.expectEqualSlices(
363 u32,363 u32,
364 &[_]u32{ 1, 2, 3, 4, 5, 6, 7, 8, 9 },364 &[_]u32{ 1, 2, 3, 4, 5, 6, 7, 8, 9 },
365 list.items(.a),365 list.items(.a),
366 );366 );
367 testing.expectEqualSlices(367 try testing.expectEqualSlices(
368 u8,368 u8,
369 &[_]u8{ 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i' },369 &[_]u8{ 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i' },
370 list.items(.c),370 list.items(.c),
...@@ -372,13 +372,13 @@ test "basic usage" {...@@ -372,13 +372,13 @@ test "basic usage" {
372372
373 list.shrinkAndFree(ally, 3);373 list.shrinkAndFree(ally, 3);
374374
375 testing.expectEqualSlices(u32, list.items(.a), &[_]u32{ 1, 2, 3 });375 try testing.expectEqualSlices(u32, list.items(.a), &[_]u32{ 1, 2, 3 });
376 testing.expectEqualSlices(u8, list.items(.c), &[_]u8{ 'a', 'b', 'c' });376 try testing.expectEqualSlices(u8, list.items(.c), &[_]u8{ 'a', 'b', 'c' });
377377
378 testing.expectEqual(@as(usize, 3), list.items(.b).len);378 try testing.expectEqual(@as(usize, 3), list.items(.b).len);
379 testing.expectEqualStrings("foobar", list.items(.b)[0]);379 try testing.expectEqualStrings("foobar", list.items(.b)[0]);
380 testing.expectEqualStrings("zigzag", list.items(.b)[1]);380 try testing.expectEqualStrings("zigzag", list.items(.b)[1]);
381 testing.expectEqualStrings("fizzbuzz", list.items(.b)[2]);381 try testing.expectEqualStrings("fizzbuzz", list.items(.b)[2]);
382}382}
383383
384// This was observed to fail on aarch64 with LLVM 11, when the capacityInBytes384// This was observed to fail on aarch64 with LLVM 11, when the capacityInBytes
...@@ -427,37 +427,37 @@ test "regression test for @reduce bug" {...@@ -427,37 +427,37 @@ test "regression test for @reduce bug" {
427 try list.append(ally, .{ .tag = .eof, .start = 123 });427 try list.append(ally, .{ .tag = .eof, .start = 123 });
428428
429 const tags = list.items(.tag);429 const tags = list.items(.tag);
430 testing.expectEqual(tags[1], .identifier);430 try testing.expectEqual(tags[1], .identifier);
431 testing.expectEqual(tags[2], .equal);431 try testing.expectEqual(tags[2], .equal);
432 testing.expectEqual(tags[3], .builtin);432 try testing.expectEqual(tags[3], .builtin);
433 testing.expectEqual(tags[4], .l_paren);433 try testing.expectEqual(tags[4], .l_paren);
434 testing.expectEqual(tags[5], .string_literal);434 try testing.expectEqual(tags[5], .string_literal);
435 testing.expectEqual(tags[6], .r_paren);435 try testing.expectEqual(tags[6], .r_paren);
436 testing.expectEqual(tags[7], .semicolon);436 try testing.expectEqual(tags[7], .semicolon);
437 testing.expectEqual(tags[8], .keyword_pub);437 try testing.expectEqual(tags[8], .keyword_pub);
438 testing.expectEqual(tags[9], .keyword_fn);438 try testing.expectEqual(tags[9], .keyword_fn);
439 testing.expectEqual(tags[10], .identifier);439 try testing.expectEqual(tags[10], .identifier);
440 testing.expectEqual(tags[11], .l_paren);440 try testing.expectEqual(tags[11], .l_paren);
441 testing.expectEqual(tags[12], .r_paren);441 try testing.expectEqual(tags[12], .r_paren);
442 testing.expectEqual(tags[13], .identifier);442 try testing.expectEqual(tags[13], .identifier);
443 testing.expectEqual(tags[14], .bang);443 try testing.expectEqual(tags[14], .bang);
444 testing.expectEqual(tags[15], .identifier);444 try testing.expectEqual(tags[15], .identifier);
445 testing.expectEqual(tags[16], .l_brace);445 try testing.expectEqual(tags[16], .l_brace);
446 testing.expectEqual(tags[17], .identifier);446 try testing.expectEqual(tags[17], .identifier);
447 testing.expectEqual(tags[18], .period);447 try testing.expectEqual(tags[18], .period);
448 testing.expectEqual(tags[19], .identifier);448 try testing.expectEqual(tags[19], .identifier);
449 testing.expectEqual(tags[20], .period);449 try testing.expectEqual(tags[20], .period);
450 testing.expectEqual(tags[21], .identifier);450 try testing.expectEqual(tags[21], .identifier);
451 testing.expectEqual(tags[22], .l_paren);451 try testing.expectEqual(tags[22], .l_paren);
452 testing.expectEqual(tags[23], .string_literal);452 try testing.expectEqual(tags[23], .string_literal);
453 testing.expectEqual(tags[24], .comma);453 try testing.expectEqual(tags[24], .comma);
454 testing.expectEqual(tags[25], .period);454 try testing.expectEqual(tags[25], .period);
455 testing.expectEqual(tags[26], .l_brace);455 try testing.expectEqual(tags[26], .l_brace);
456 testing.expectEqual(tags[27], .r_brace);456 try testing.expectEqual(tags[27], .r_brace);
457 testing.expectEqual(tags[28], .r_paren);457 try testing.expectEqual(tags[28], .r_paren);
458 testing.expectEqual(tags[29], .semicolon);458 try testing.expectEqual(tags[29], .semicolon);
459 testing.expectEqual(tags[30], .r_brace);459 try testing.expectEqual(tags[30], .r_brace);
460 testing.expectEqual(tags[31], .eof);460 try testing.expectEqual(tags[31], .eof);
461}461}
462462
463test "ensure capacity on empty list" {463test "ensure capacity on empty list" {
...@@ -475,15 +475,15 @@ test "ensure capacity on empty list" {...@@ -475,15 +475,15 @@ test "ensure capacity on empty list" {
475 list.appendAssumeCapacity(.{ .a = 1, .b = 2 });475 list.appendAssumeCapacity(.{ .a = 1, .b = 2 });
476 list.appendAssumeCapacity(.{ .a = 3, .b = 4 });476 list.appendAssumeCapacity(.{ .a = 3, .b = 4 });
477477
478 testing.expectEqualSlices(u32, &[_]u32{ 1, 3 }, list.items(.a));478 try testing.expectEqualSlices(u32, &[_]u32{ 1, 3 }, list.items(.a));
479 testing.expectEqualSlices(u8, &[_]u8{ 2, 4 }, list.items(.b));479 try testing.expectEqualSlices(u8, &[_]u8{ 2, 4 }, list.items(.b));
480480
481 list.len = 0;481 list.len = 0;
482 list.appendAssumeCapacity(.{ .a = 5, .b = 6 });482 list.appendAssumeCapacity(.{ .a = 5, .b = 6 });
483 list.appendAssumeCapacity(.{ .a = 7, .b = 8 });483 list.appendAssumeCapacity(.{ .a = 7, .b = 8 });
484484
485 testing.expectEqualSlices(u32, &[_]u32{ 5, 7 }, list.items(.a));485 try testing.expectEqualSlices(u32, &[_]u32{ 5, 7 }, list.items(.a));
486 testing.expectEqualSlices(u8, &[_]u8{ 6, 8 }, list.items(.b));486 try testing.expectEqualSlices(u8, &[_]u8{ 6, 8 }, list.items(.b));
487487
488 list.len = 0;488 list.len = 0;
489 try list.ensureTotalCapacity(ally, 16);489 try list.ensureTotalCapacity(ally, 16);
...@@ -491,6 +491,6 @@ test "ensure capacity on empty list" {...@@ -491,6 +491,6 @@ test "ensure capacity on empty list" {
491 list.appendAssumeCapacity(.{ .a = 9, .b = 10 });491 list.appendAssumeCapacity(.{ .a = 9, .b = 10 });
492 list.appendAssumeCapacity(.{ .a = 11, .b = 12 });492 list.appendAssumeCapacity(.{ .a = 11, .b = 12 });
493493
494 testing.expectEqualSlices(u32, &[_]u32{ 9, 11 }, list.items(.a));494 try testing.expectEqualSlices(u32, &[_]u32{ 9, 11 }, list.items(.a));
495 testing.expectEqualSlices(u8, &[_]u8{ 10, 12 }, list.items(.b));495 try testing.expectEqualSlices(u8, &[_]u8{ 10, 12 }, list.items(.b));
496}496}
lib/std/net/test.zig+24-24
...@@ -38,26 +38,26 @@ test "parse and render IPv6 addresses" {...@@ -38,26 +38,26 @@ test "parse and render IPv6 addresses" {
38 for (ips) |ip, i| {38 for (ips) |ip, i| {
39 var addr = net.Address.parseIp6(ip, 0) catch unreachable;39 var addr = net.Address.parseIp6(ip, 0) catch unreachable;
40 var newIp = std.fmt.bufPrint(buffer[0..], "{}", .{addr}) catch unreachable;40 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
43 if (std.builtin.os.tag == .linux) {43 if (std.builtin.os.tag == .linux) {
44 var addr_via_resolve = net.Address.resolveIp6(ip, 0) catch unreachable;44 var addr_via_resolve = net.Address.resolveIp6(ip, 0) catch unreachable;
45 var newResolvedIp = std.fmt.bufPrint(buffer[0..], "{}", .{addr_via_resolve}) catch unreachable;45 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]));
47 }47 }
48 }48 }
4949
50 testing.expectError(error.InvalidCharacter, net.Address.parseIp6(":::", 0));50 try testing.expectError(error.InvalidCharacter, net.Address.parseIp6(":::", 0));
51 testing.expectError(error.Overflow, net.Address.parseIp6("FF001::FB", 0));51 try testing.expectError(error.Overflow, net.Address.parseIp6("FF001::FB", 0));
52 testing.expectError(error.InvalidCharacter, net.Address.parseIp6("FF01::Fb:zig", 0));52 try 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));53 try 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));54 try testing.expectError(error.Incomplete, net.Address.parseIp6("FF01:", 0));
55 testing.expectError(error.InvalidIpv4Mapping, net.Address.parseIp6("::123.123.123.123", 0));55 try testing.expectError(error.InvalidIpv4Mapping, net.Address.parseIp6("::123.123.123.123", 0));
56 // TODO Make this test pass on other operating systems.56 // TODO Make this test pass on other operating systems.
57 if (std.builtin.os.tag == .linux) {57 if (std.builtin.os.tag == .linux) {
58 testing.expectError(error.Incomplete, net.Address.resolveIp6("ff01::fb%", 0));58 try testing.expectError(error.Incomplete, net.Address.resolveIp6("ff01::fb%", 0));
59 testing.expectError(error.Overflow, net.Address.resolveIp6("ff01::fb%wlp3s0s0s0s0s0s0s0s0", 0));59 try testing.expectError(error.Overflow, net.Address.resolveIp6("ff01::fb%wlp3s0s0s0s0s0s0s0s0", 0));
60 testing.expectError(error.Overflow, net.Address.resolveIp6("ff01::fb%12345678901234", 0));60 try testing.expectError(error.Overflow, net.Address.resolveIp6("ff01::fb%12345678901234", 0));
61 }61 }
62}62}
6363
...@@ -68,7 +68,7 @@ test "invalid but parseable IPv6 scope ids" {...@@ -68,7 +68,7 @@ test "invalid but parseable IPv6 scope ids" {
68 return error.SkipZigTest;68 return error.SkipZigTest;
69 }69 }
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));
72}72}
7373
74test "parse and render IPv4 addresses" {74test "parse and render IPv4 addresses" {
...@@ -84,14 +84,14 @@ test "parse and render IPv4 addresses" {...@@ -84,14 +84,14 @@ test "parse and render IPv4 addresses" {
84 }) |ip| {84 }) |ip| {
85 var addr = net.Address.parseIp4(ip, 0) catch unreachable;85 var addr = net.Address.parseIp4(ip, 0) catch unreachable;
86 var newIp = std.fmt.bufPrint(buffer[0..], "{}", .{addr}) catch unreachable;86 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]));
88 }88 }
8989
90 testing.expectError(error.Overflow, net.Address.parseIp4("256.0.0.1", 0));90 try 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));91 try 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));92 try 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));93 try testing.expectError(error.Incomplete, net.Address.parseIp4("127.0.0.", 0));
94 testing.expectError(error.InvalidCharacter, net.Address.parseIp4("100..0.1", 0));94 try testing.expectError(error.InvalidCharacter, net.Address.parseIp4("100..0.1", 0));
95}95}
9696
97test "resolve DNS" {97test "resolve DNS" {
...@@ -169,8 +169,8 @@ test "listen on a port, send bytes, receive bytes" {...@@ -169,8 +169,8 @@ test "listen on a port, send bytes, receive bytes" {
169 var buf: [16]u8 = undefined;169 var buf: [16]u8 = undefined;
170 const n = try client.stream.reader().read(&buf);170 const n = try client.stream.reader().read(&buf);
171171
172 testing.expectEqual(@as(usize, 12), n);172 try testing.expectEqual(@as(usize, 12), n);
173 testing.expectEqualSlices(u8, "Hello world!", buf[0..n]);173 try testing.expectEqualSlices(u8, "Hello world!", buf[0..n]);
174}174}
175175
176test "listen on a port, send bytes, receive bytes" {176test "listen on a port, send bytes, receive bytes" {
...@@ -230,7 +230,7 @@ fn testClientToHost(allocator: *mem.Allocator, name: []const u8, port: u16) anye...@@ -230,7 +230,7 @@ fn testClientToHost(allocator: *mem.Allocator, name: []const u8, port: u16) anye
230 var buf: [100]u8 = undefined;230 var buf: [100]u8 = undefined;
231 const len = try connection.read(&buf);231 const len = try connection.read(&buf);
232 const msg = buf[0..len];232 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"));
234}234}
235235
236fn testClient(addr: net.Address) anyerror!void {236fn testClient(addr: net.Address) anyerror!void {
...@@ -242,7 +242,7 @@ fn testClient(addr: net.Address) anyerror!void {...@@ -242,7 +242,7 @@ fn testClient(addr: net.Address) anyerror!void {
242 var buf: [100]u8 = undefined;242 var buf: [100]u8 = undefined;
243 const len = try socket_file.read(&buf);243 const len = try socket_file.read(&buf);
244 const msg = buf[0..len];244 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"));
246}246}
247247
248fn testServer(server: *net.StreamServer) anyerror!void {248fn testServer(server: *net.StreamServer) anyerror!void {
...@@ -293,6 +293,6 @@ test "listen on a unix socket, send bytes, receive bytes" {...@@ -293,6 +293,6 @@ test "listen on a unix socket, send bytes, receive bytes" {
293 var buf: [16]u8 = undefined;293 var buf: [16]u8 = undefined;
294 const n = try client.stream.reader().read(&buf);294 const n = try client.stream.reader().read(&buf);
295295
296 testing.expectEqual(@as(usize, 12), n);296 try testing.expectEqual(@as(usize, 12), n);
297 testing.expectEqualSlices(u8, "Hello world!", buf[0..n]);297 try testing.expectEqualSlices(u8, "Hello world!", buf[0..n]);
298}298}
lib/std/once.zig+1-1
...@@ -67,5 +67,5 @@ test "Once executes its function just once" {...@@ -67,5 +67,5 @@ test "Once executes its function just once" {
67 }67 }
68 }68 }
6969
70 testing.expectEqual(@as(i32, 1), global_number);70 try testing.expectEqual(@as(i32, 1), global_number);
71}71}
lib/std/os/linux/bpf.zig+100-100
...@@ -737,11 +737,11 @@ pub const Insn = packed struct {...@@ -737,11 +737,11 @@ pub const Insn = packed struct {
737};737};
738738
739test "insn bitsize" {739test "insn bitsize" {
740 expectEqual(@bitSizeOf(Insn), 64);740 try expectEqual(@bitSizeOf(Insn), 64);
741}741}
742742
743fn expect_opcode(code: u8, insn: Insn) void {743fn expect_opcode(code: u8, insn: Insn) !void {
744 expectEqual(code, insn.code);744 try expectEqual(code, insn.code);
745}745}
746746
747// The opcodes were grabbed from https://github.com/iovisor/bpf-docs/blob/master/eBPF.md747// The opcodes were grabbed from https://github.com/iovisor/bpf-docs/blob/master/eBPF.md
...@@ -750,108 +750,108 @@ test "opcodes" {...@@ -750,108 +750,108 @@ test "opcodes" {
750 // loading 64-bit immediates (imm is only 32 bits wide)750 // loading 64-bit immediates (imm is only 32 bits wide)
751751
752 // alu instructions752 // alu instructions
753 expect_opcode(0x07, Insn.add(.r1, 0));753 try expect_opcode(0x07, Insn.add(.r1, 0));
754 expect_opcode(0x0f, Insn.add(.r1, .r2));754 try expect_opcode(0x0f, Insn.add(.r1, .r2));
755 expect_opcode(0x17, Insn.sub(.r1, 0));755 try expect_opcode(0x17, Insn.sub(.r1, 0));
756 expect_opcode(0x1f, Insn.sub(.r1, .r2));756 try expect_opcode(0x1f, Insn.sub(.r1, .r2));
757 expect_opcode(0x27, Insn.mul(.r1, 0));757 try expect_opcode(0x27, Insn.mul(.r1, 0));
758 expect_opcode(0x2f, Insn.mul(.r1, .r2));758 try expect_opcode(0x2f, Insn.mul(.r1, .r2));
759 expect_opcode(0x37, Insn.div(.r1, 0));759 try expect_opcode(0x37, Insn.div(.r1, 0));
760 expect_opcode(0x3f, Insn.div(.r1, .r2));760 try expect_opcode(0x3f, Insn.div(.r1, .r2));
761 expect_opcode(0x47, Insn.alu_or(.r1, 0));761 try expect_opcode(0x47, Insn.alu_or(.r1, 0));
762 expect_opcode(0x4f, Insn.alu_or(.r1, .r2));762 try expect_opcode(0x4f, Insn.alu_or(.r1, .r2));
763 expect_opcode(0x57, Insn.alu_and(.r1, 0));763 try expect_opcode(0x57, Insn.alu_and(.r1, 0));
764 expect_opcode(0x5f, Insn.alu_and(.r1, .r2));764 try expect_opcode(0x5f, Insn.alu_and(.r1, .r2));
765 expect_opcode(0x67, Insn.lsh(.r1, 0));765 try expect_opcode(0x67, Insn.lsh(.r1, 0));
766 expect_opcode(0x6f, Insn.lsh(.r1, .r2));766 try expect_opcode(0x6f, Insn.lsh(.r1, .r2));
767 expect_opcode(0x77, Insn.rsh(.r1, 0));767 try expect_opcode(0x77, Insn.rsh(.r1, 0));
768 expect_opcode(0x7f, Insn.rsh(.r1, .r2));768 try expect_opcode(0x7f, Insn.rsh(.r1, .r2));
769 expect_opcode(0x87, Insn.neg(.r1));769 try expect_opcode(0x87, Insn.neg(.r1));
770 expect_opcode(0x97, Insn.mod(.r1, 0));770 try expect_opcode(0x97, Insn.mod(.r1, 0));
771 expect_opcode(0x9f, Insn.mod(.r1, .r2));771 try expect_opcode(0x9f, Insn.mod(.r1, .r2));
772 expect_opcode(0xa7, Insn.xor(.r1, 0));772 try expect_opcode(0xa7, Insn.xor(.r1, 0));
773 expect_opcode(0xaf, Insn.xor(.r1, .r2));773 try expect_opcode(0xaf, Insn.xor(.r1, .r2));
774 expect_opcode(0xb7, Insn.mov(.r1, 0));774 try expect_opcode(0xb7, Insn.mov(.r1, 0));
775 expect_opcode(0xbf, Insn.mov(.r1, .r2));775 try expect_opcode(0xbf, Insn.mov(.r1, .r2));
776 expect_opcode(0xc7, Insn.arsh(.r1, 0));776 try expect_opcode(0xc7, Insn.arsh(.r1, 0));
777 expect_opcode(0xcf, Insn.arsh(.r1, .r2));777 try expect_opcode(0xcf, Insn.arsh(.r1, .r2));
778778
779 // atomic instructions: might be more of these not documented in the wild779 // 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
782 // TODO: byteswap instructions782 // TODO: byteswap instructions
783 expect_opcode(0xd4, Insn.le(.half_word, .r1));783 try expect_opcode(0xd4, Insn.le(.half_word, .r1));
784 expectEqual(@intCast(i32, 16), Insn.le(.half_word, .r1).imm);784 try expectEqual(@intCast(i32, 16), Insn.le(.half_word, .r1).imm);
785 expect_opcode(0xd4, Insn.le(.word, .r1));785 try expect_opcode(0xd4, Insn.le(.word, .r1));
786 expectEqual(@intCast(i32, 32), Insn.le(.word, .r1).imm);786 try expectEqual(@intCast(i32, 32), Insn.le(.word, .r1).imm);
787 expect_opcode(0xd4, Insn.le(.double_word, .r1));787 try expect_opcode(0xd4, Insn.le(.double_word, .r1));
788 expectEqual(@intCast(i32, 64), Insn.le(.double_word, .r1).imm);788 try expectEqual(@intCast(i32, 64), Insn.le(.double_word, .r1).imm);
789 expect_opcode(0xdc, Insn.be(.half_word, .r1));789 try expect_opcode(0xdc, Insn.be(.half_word, .r1));
790 expectEqual(@intCast(i32, 16), Insn.be(.half_word, .r1).imm);790 try expectEqual(@intCast(i32, 16), Insn.be(.half_word, .r1).imm);
791 expect_opcode(0xdc, Insn.be(.word, .r1));791 try expect_opcode(0xdc, Insn.be(.word, .r1));
792 expectEqual(@intCast(i32, 32), Insn.be(.word, .r1).imm);792 try expectEqual(@intCast(i32, 32), Insn.be(.word, .r1).imm);
793 expect_opcode(0xdc, Insn.be(.double_word, .r1));793 try expect_opcode(0xdc, Insn.be(.double_word, .r1));
794 expectEqual(@intCast(i32, 64), Insn.be(.double_word, .r1).imm);794 try expectEqual(@intCast(i32, 64), Insn.be(.double_word, .r1).imm);
795795
796 // memory instructions796 // memory instructions
797 expect_opcode(0x18, Insn.ld_dw1(.r1, 0));797 try expect_opcode(0x18, Insn.ld_dw1(.r1, 0));
798 expect_opcode(0x00, Insn.ld_dw2(0));798 try expect_opcode(0x00, Insn.ld_dw2(0));
799799
800 // loading a map fd800 // loading a map fd
801 expect_opcode(0x18, Insn.ld_map_fd1(.r1, 0));801 try expect_opcode(0x18, Insn.ld_map_fd1(.r1, 0));
802 expectEqual(@intCast(u4, PSEUDO_MAP_FD), Insn.ld_map_fd1(.r1, 0).src);802 try expectEqual(@intCast(u4, PSEUDO_MAP_FD), Insn.ld_map_fd1(.r1, 0).src);
803 expect_opcode(0x00, Insn.ld_map_fd2(0));803 try expect_opcode(0x00, Insn.ld_map_fd2(0));
804804
805 expect_opcode(0x38, Insn.ld_abs(.double_word, .r1, .r2, 0));805 try expect_opcode(0x38, Insn.ld_abs(.double_word, .r1, .r2, 0));
806 expect_opcode(0x20, Insn.ld_abs(.word, .r1, .r2, 0));806 try expect_opcode(0x20, Insn.ld_abs(.word, .r1, .r2, 0));
807 expect_opcode(0x28, Insn.ld_abs(.half_word, .r1, .r2, 0));807 try expect_opcode(0x28, Insn.ld_abs(.half_word, .r1, .r2, 0));
808 expect_opcode(0x30, Insn.ld_abs(.byte, .r1, .r2, 0));808 try expect_opcode(0x30, Insn.ld_abs(.byte, .r1, .r2, 0));
809809
810 expect_opcode(0x58, Insn.ld_ind(.double_word, .r1, .r2, 0));810 try expect_opcode(0x58, Insn.ld_ind(.double_word, .r1, .r2, 0));
811 expect_opcode(0x40, Insn.ld_ind(.word, .r1, .r2, 0));811 try expect_opcode(0x40, Insn.ld_ind(.word, .r1, .r2, 0));
812 expect_opcode(0x48, Insn.ld_ind(.half_word, .r1, .r2, 0));812 try expect_opcode(0x48, Insn.ld_ind(.half_word, .r1, .r2, 0));
813 expect_opcode(0x50, Insn.ld_ind(.byte, .r1, .r2, 0));813 try expect_opcode(0x50, Insn.ld_ind(.byte, .r1, .r2, 0));
814814
815 expect_opcode(0x79, Insn.ldx(.double_word, .r1, .r2, 0));815 try expect_opcode(0x79, Insn.ldx(.double_word, .r1, .r2, 0));
816 expect_opcode(0x61, Insn.ldx(.word, .r1, .r2, 0));816 try expect_opcode(0x61, Insn.ldx(.word, .r1, .r2, 0));
817 expect_opcode(0x69, Insn.ldx(.half_word, .r1, .r2, 0));817 try expect_opcode(0x69, Insn.ldx(.half_word, .r1, .r2, 0));
818 expect_opcode(0x71, Insn.ldx(.byte, .r1, .r2, 0));818 try expect_opcode(0x71, Insn.ldx(.byte, .r1, .r2, 0));
819819
820 expect_opcode(0x62, Insn.st(.word, .r1, 0, 0));820 try expect_opcode(0x62, Insn.st(.word, .r1, 0, 0));
821 expect_opcode(0x6a, Insn.st(.half_word, .r1, 0, 0));821 try expect_opcode(0x6a, Insn.st(.half_word, .r1, 0, 0));
822 expect_opcode(0x72, Insn.st(.byte, .r1, 0, 0));822 try expect_opcode(0x72, Insn.st(.byte, .r1, 0, 0));
823823
824 expect_opcode(0x63, Insn.stx(.word, .r1, 0, .r2));824 try expect_opcode(0x63, Insn.stx(.word, .r1, 0, .r2));
825 expect_opcode(0x6b, Insn.stx(.half_word, .r1, 0, .r2));825 try expect_opcode(0x6b, Insn.stx(.half_word, .r1, 0, .r2));
826 expect_opcode(0x73, Insn.stx(.byte, .r1, 0, .r2));826 try expect_opcode(0x73, Insn.stx(.byte, .r1, 0, .r2));
827 expect_opcode(0x7b, Insn.stx(.double_word, .r1, 0, .r2));827 try expect_opcode(0x7b, Insn.stx(.double_word, .r1, 0, .r2));
828828
829 // branch instructions829 // branch instructions
830 expect_opcode(0x05, Insn.ja(0));830 try expect_opcode(0x05, Insn.ja(0));
831 expect_opcode(0x15, Insn.jeq(.r1, 0, 0));831 try expect_opcode(0x15, Insn.jeq(.r1, 0, 0));
832 expect_opcode(0x1d, Insn.jeq(.r1, .r2, 0));832 try expect_opcode(0x1d, Insn.jeq(.r1, .r2, 0));
833 expect_opcode(0x25, Insn.jgt(.r1, 0, 0));833 try expect_opcode(0x25, Insn.jgt(.r1, 0, 0));
834 expect_opcode(0x2d, Insn.jgt(.r1, .r2, 0));834 try expect_opcode(0x2d, Insn.jgt(.r1, .r2, 0));
835 expect_opcode(0x35, Insn.jge(.r1, 0, 0));835 try expect_opcode(0x35, Insn.jge(.r1, 0, 0));
836 expect_opcode(0x3d, Insn.jge(.r1, .r2, 0));836 try expect_opcode(0x3d, Insn.jge(.r1, .r2, 0));
837 expect_opcode(0xa5, Insn.jlt(.r1, 0, 0));837 try expect_opcode(0xa5, Insn.jlt(.r1, 0, 0));
838 expect_opcode(0xad, Insn.jlt(.r1, .r2, 0));838 try expect_opcode(0xad, Insn.jlt(.r1, .r2, 0));
839 expect_opcode(0xb5, Insn.jle(.r1, 0, 0));839 try expect_opcode(0xb5, Insn.jle(.r1, 0, 0));
840 expect_opcode(0xbd, Insn.jle(.r1, .r2, 0));840 try expect_opcode(0xbd, Insn.jle(.r1, .r2, 0));
841 expect_opcode(0x45, Insn.jset(.r1, 0, 0));841 try expect_opcode(0x45, Insn.jset(.r1, 0, 0));
842 expect_opcode(0x4d, Insn.jset(.r1, .r2, 0));842 try expect_opcode(0x4d, Insn.jset(.r1, .r2, 0));
843 expect_opcode(0x55, Insn.jne(.r1, 0, 0));843 try expect_opcode(0x55, Insn.jne(.r1, 0, 0));
844 expect_opcode(0x5d, Insn.jne(.r1, .r2, 0));844 try expect_opcode(0x5d, Insn.jne(.r1, .r2, 0));
845 expect_opcode(0x65, Insn.jsgt(.r1, 0, 0));845 try expect_opcode(0x65, Insn.jsgt(.r1, 0, 0));
846 expect_opcode(0x6d, Insn.jsgt(.r1, .r2, 0));846 try expect_opcode(0x6d, Insn.jsgt(.r1, .r2, 0));
847 expect_opcode(0x75, Insn.jsge(.r1, 0, 0));847 try expect_opcode(0x75, Insn.jsge(.r1, 0, 0));
848 expect_opcode(0x7d, Insn.jsge(.r1, .r2, 0));848 try expect_opcode(0x7d, Insn.jsge(.r1, .r2, 0));
849 expect_opcode(0xc5, Insn.jslt(.r1, 0, 0));849 try expect_opcode(0xc5, Insn.jslt(.r1, 0, 0));
850 expect_opcode(0xcd, Insn.jslt(.r1, .r2, 0));850 try expect_opcode(0xcd, Insn.jslt(.r1, .r2, 0));
851 expect_opcode(0xd5, Insn.jsle(.r1, 0, 0));851 try expect_opcode(0xd5, Insn.jsle(.r1, 0, 0));
852 expect_opcode(0xdd, Insn.jsle(.r1, .r2, 0));852 try expect_opcode(0xdd, Insn.jsle(.r1, .r2, 0));
853 expect_opcode(0x85, Insn.call(.unspec));853 try expect_opcode(0x85, Insn.call(.unspec));
854 expect_opcode(0x95, Insn.exit());854 try expect_opcode(0x95, Insn.exit());
855}855}
856856
857pub const Cmd = enum(usize) {857pub const Cmd = enum(usize) {
...@@ -1596,7 +1596,7 @@ test "map lookup, update, and delete" {...@@ -1596,7 +1596,7 @@ test "map lookup, update, and delete" {
1596 var value = std.mem.zeroes([value_size]u8);1596 var value = std.mem.zeroes([value_size]u8);
15971597
1598 // fails looking up value that doesn't exist1598 // 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
1601 // succeed at updating and looking up element1601 // succeed at updating and looking up element
1602 try map_update_elem(map, &key, &value, 0);1602 try map_update_elem(map, &key, &value, 0);
...@@ -1604,14 +1604,14 @@ test "map lookup, update, and delete" {...@@ -1604,14 +1604,14 @@ test "map lookup, update, and delete" {
16041604
1605 // fails inserting more than max entries1605 // fails inserting more than max entries
1606 const second_key = [key_size]u8{ 0, 0, 0, 1 };1606 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
1609 // succeed at deleting an existing elem1609 // succeed at deleting an existing elem
1610 try map_delete_elem(map, &key);1610 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
1613 // fail at deleting a non-existing elem1613 // 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));
1615}1615}
16161616
1617pub fn prog_load(1617pub fn prog_load(
...@@ -1662,5 +1662,5 @@ test "prog_load" {...@@ -1662,5 +1662,5 @@ test "prog_load" {
1662 const prog = try prog_load(.socket_filter, &good_prog, null, "MIT", 0);1662 const prog = try prog_load(.socket_filter, &good_prog, null, "MIT", 0);
1663 defer std.os.close(prog);1663 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));
1666}1666}
lib/std/os/linux/bpf/btf.zig+1-1
...@@ -92,7 +92,7 @@ pub const IntInfo = packed struct {...@@ -92,7 +92,7 @@ pub const IntInfo = packed struct {
92};92};
9393
94test "IntInfo is 32 bits" {94test "IntInfo is 32 bits" {
95 std.testing.expectEqual(@bitSizeOf(IntInfo), 32);95 try std.testing.expectEqual(@bitSizeOf(IntInfo), 32);
96}96}
9797
98/// Enum kind is followed by this struct98/// 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(...@@ -937,16 +937,16 @@ pub fn io_uring_prep_fallocate(
937test "structs/offsets/entries" {937test "structs/offsets/entries" {
938 if (builtin.os.tag != .linux) return error.SkipZigTest;938 if (builtin.os.tag != .linux) return error.SkipZigTest;
939939
940 testing.expectEqual(@as(usize, 120), @sizeOf(io_uring_params));940 try testing.expectEqual(@as(usize, 120), @sizeOf(io_uring_params));
941 testing.expectEqual(@as(usize, 64), @sizeOf(io_uring_sqe));941 try testing.expectEqual(@as(usize, 64), @sizeOf(io_uring_sqe));
942 testing.expectEqual(@as(usize, 16), @sizeOf(io_uring_cqe));942 try testing.expectEqual(@as(usize, 16), @sizeOf(io_uring_cqe));
943943
944 testing.expectEqual(0, linux.IORING_OFF_SQ_RING);944 try testing.expectEqual(0, linux.IORING_OFF_SQ_RING);
945 testing.expectEqual(0x8000000, linux.IORING_OFF_CQ_RING);945 try testing.expectEqual(0x8000000, linux.IORING_OFF_CQ_RING);
946 testing.expectEqual(0x10000000, linux.IORING_OFF_SQES);946 try testing.expectEqual(0x10000000, linux.IORING_OFF_SQES);
947947
948 testing.expectError(error.EntriesZero, IO_Uring.init(0, 0));948 try testing.expectError(error.EntriesZero, IO_Uring.init(0, 0));
949 testing.expectError(error.EntriesNotPowerOfTwo, IO_Uring.init(3, 0));949 try testing.expectError(error.EntriesNotPowerOfTwo, IO_Uring.init(3, 0));
950}950}
951951
952test "nop" {952test "nop" {
...@@ -959,11 +959,11 @@ test "nop" {...@@ -959,11 +959,11 @@ test "nop" {
959 };959 };
960 defer {960 defer {
961 ring.deinit();961 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");
963 }963 }
964964
965 const sqe = try ring.nop(0xaaaaaaaa);965 const sqe = try ring.nop(0xaaaaaaaa);
966 testing.expectEqual(io_uring_sqe{966 try testing.expectEqual(io_uring_sqe{
967 .opcode = .NOP,967 .opcode = .NOP,
968 .flags = 0,968 .flags = 0,
969 .ioprio = 0,969 .ioprio = 0,
...@@ -979,40 +979,40 @@ test "nop" {...@@ -979,40 +979,40 @@ test "nop" {
979 .__pad2 = [2]u64{ 0, 0 },979 .__pad2 = [2]u64{ 0, 0 },
980 }, sqe.*);980 }, sqe.*);
981981
982 testing.expectEqual(@as(u32, 0), ring.sq.sqe_head);982 try testing.expectEqual(@as(u32, 0), ring.sq.sqe_head);
983 testing.expectEqual(@as(u32, 1), ring.sq.sqe_tail);983 try testing.expectEqual(@as(u32, 1), ring.sq.sqe_tail);
984 testing.expectEqual(@as(u32, 0), ring.sq.tail.*);984 try testing.expectEqual(@as(u32, 0), ring.sq.tail.*);
985 testing.expectEqual(@as(u32, 0), ring.cq.head.*);985 try testing.expectEqual(@as(u32, 0), ring.cq.head.*);
986 testing.expectEqual(@as(u32, 1), ring.sq_ready());986 try testing.expectEqual(@as(u32, 1), ring.sq_ready());
987 testing.expectEqual(@as(u32, 0), ring.cq_ready());987 try testing.expectEqual(@as(u32, 0), ring.cq_ready());
988988
989 testing.expectEqual(@as(u32, 1), try ring.submit());989 try testing.expectEqual(@as(u32, 1), try ring.submit());
990 testing.expectEqual(@as(u32, 1), ring.sq.sqe_head);990 try testing.expectEqual(@as(u32, 1), ring.sq.sqe_head);
991 testing.expectEqual(@as(u32, 1), ring.sq.sqe_tail);991 try testing.expectEqual(@as(u32, 1), ring.sq.sqe_tail);
992 testing.expectEqual(@as(u32, 1), ring.sq.tail.*);992 try testing.expectEqual(@as(u32, 1), ring.sq.tail.*);
993 testing.expectEqual(@as(u32, 0), ring.cq.head.*);993 try testing.expectEqual(@as(u32, 0), ring.cq.head.*);
994 testing.expectEqual(@as(u32, 0), ring.sq_ready());994 try testing.expectEqual(@as(u32, 0), ring.sq_ready());
995995
996 testing.expectEqual(io_uring_cqe{996 try testing.expectEqual(io_uring_cqe{
997 .user_data = 0xaaaaaaaa,997 .user_data = 0xaaaaaaaa,
998 .res = 0,998 .res = 0,
999 .flags = 0,999 .flags = 0,
1000 }, try ring.copy_cqe());1000 }, try ring.copy_cqe());
1001 testing.expectEqual(@as(u32, 1), ring.cq.head.*);1001 try testing.expectEqual(@as(u32, 1), ring.cq.head.*);
1002 testing.expectEqual(@as(u32, 0), ring.cq_ready());1002 try testing.expectEqual(@as(u32, 0), ring.cq_ready());
10031003
1004 const sqe_barrier = try ring.nop(0xbbbbbbbb);1004 const sqe_barrier = try ring.nop(0xbbbbbbbb);
1005 sqe_barrier.flags |= linux.IOSQE_IO_DRAIN;1005 sqe_barrier.flags |= linux.IOSQE_IO_DRAIN;
1006 testing.expectEqual(@as(u32, 1), try ring.submit());1006 try testing.expectEqual(@as(u32, 1), try ring.submit());
1007 testing.expectEqual(io_uring_cqe{1007 try testing.expectEqual(io_uring_cqe{
1008 .user_data = 0xbbbbbbbb,1008 .user_data = 0xbbbbbbbb,
1009 .res = 0,1009 .res = 0,
1010 .flags = 0,1010 .flags = 0,
1011 }, try ring.copy_cqe());1011 }, try ring.copy_cqe());
1012 testing.expectEqual(@as(u32, 2), ring.sq.sqe_head);1012 try testing.expectEqual(@as(u32, 2), ring.sq.sqe_head);
1013 testing.expectEqual(@as(u32, 2), ring.sq.sqe_tail);1013 try testing.expectEqual(@as(u32, 2), ring.sq.sqe_tail);
1014 testing.expectEqual(@as(u32, 2), ring.sq.tail.*);1014 try testing.expectEqual(@as(u32, 2), ring.sq.tail.*);
1015 testing.expectEqual(@as(u32, 2), ring.cq.head.*);1015 try testing.expectEqual(@as(u32, 2), ring.cq.head.*);
1016}1016}
10171017
1018test "readv" {1018test "readv" {
...@@ -1042,17 +1042,17 @@ test "readv" {...@@ -1042,17 +1042,17 @@ test "readv" {
1042 var buffer = [_]u8{42} ** 128;1042 var buffer = [_]u8{42} ** 128;
1043 var iovecs = [_]os.iovec{os.iovec{ .iov_base = &buffer, .iov_len = buffer.len }};1043 var iovecs = [_]os.iovec{os.iovec{ .iov_base = &buffer, .iov_len = buffer.len }};
1044 const sqe = try ring.readv(0xcccccccc, fd_index, iovecs[0..], 0);1044 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);
1046 sqe.flags |= linux.IOSQE_FIXED_FILE;1046 sqe.flags |= linux.IOSQE_FIXED_FILE;
10471047
1048 testing.expectError(error.SubmissionQueueFull, ring.nop(0));1048 try testing.expectError(error.SubmissionQueueFull, ring.nop(0));
1049 testing.expectEqual(@as(u32, 1), try ring.submit());1049 try testing.expectEqual(@as(u32, 1), try ring.submit());
1050 testing.expectEqual(linux.io_uring_cqe{1050 try testing.expectEqual(linux.io_uring_cqe{
1051 .user_data = 0xcccccccc,1051 .user_data = 0xcccccccc,
1052 .res = buffer.len,1052 .res = buffer.len,
1053 .flags = 0,1053 .flags = 0,
1054 }, try ring.copy_cqe());1054 }, 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
1057 try ring.unregister_files();1057 try ring.unregister_files();
1058}1058}
...@@ -1083,46 +1083,46 @@ test "writev/fsync/readv" {...@@ -1083,46 +1083,46 @@ test "writev/fsync/readv" {
1083 };1083 };
10841084
1085 const sqe_writev = try ring.writev(0xdddddddd, fd, iovecs_write[0..], 17);1085 const sqe_writev = try ring.writev(0xdddddddd, fd, iovecs_write[0..], 17);
1086 testing.expectEqual(linux.IORING_OP.WRITEV, sqe_writev.opcode);1086 try testing.expectEqual(linux.IORING_OP.WRITEV, sqe_writev.opcode);
1087 testing.expectEqual(@as(u64, 17), sqe_writev.off);1087 try testing.expectEqual(@as(u64, 17), sqe_writev.off);
1088 sqe_writev.flags |= linux.IOSQE_IO_LINK;1088 sqe_writev.flags |= linux.IOSQE_IO_LINK;
10891089
1090 const sqe_fsync = try ring.fsync(0xeeeeeeee, fd, 0);1090 const sqe_fsync = try ring.fsync(0xeeeeeeee, fd, 0);
1091 testing.expectEqual(linux.IORING_OP.FSYNC, sqe_fsync.opcode);1091 try testing.expectEqual(linux.IORING_OP.FSYNC, sqe_fsync.opcode);
1092 testing.expectEqual(fd, sqe_fsync.fd);1092 try testing.expectEqual(fd, sqe_fsync.fd);
1093 sqe_fsync.flags |= linux.IOSQE_IO_LINK;1093 sqe_fsync.flags |= linux.IOSQE_IO_LINK;
10941094
1095 const sqe_readv = try ring.readv(0xffffffff, fd, iovecs_read[0..], 17);1095 const sqe_readv = try ring.readv(0xffffffff, fd, iovecs_read[0..], 17);
1096 testing.expectEqual(linux.IORING_OP.READV, sqe_readv.opcode);1096 try testing.expectEqual(linux.IORING_OP.READV, sqe_readv.opcode);
1097 testing.expectEqual(@as(u64, 17), sqe_readv.off);1097 try testing.expectEqual(@as(u64, 17), sqe_readv.off);
10981098
1099 testing.expectEqual(@as(u32, 3), ring.sq_ready());1099 try testing.expectEqual(@as(u32, 3), ring.sq_ready());
1100 testing.expectEqual(@as(u32, 3), try ring.submit_and_wait(3));1100 try testing.expectEqual(@as(u32, 3), try ring.submit_and_wait(3));
1101 testing.expectEqual(@as(u32, 0), ring.sq_ready());1101 try testing.expectEqual(@as(u32, 0), ring.sq_ready());
1102 testing.expectEqual(@as(u32, 3), ring.cq_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{
1105 .user_data = 0xdddddddd,1105 .user_data = 0xdddddddd,
1106 .res = buffer_write.len,1106 .res = buffer_write.len,
1107 .flags = 0,1107 .flags = 0,
1108 }, try ring.copy_cqe());1108 }, 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{
1112 .user_data = 0xeeeeeeee,1112 .user_data = 0xeeeeeeee,
1113 .res = 0,1113 .res = 0,
1114 .flags = 0,1114 .flags = 0,
1115 }, try ring.copy_cqe());1115 }, 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{
1119 .user_data = 0xffffffff,1119 .user_data = 0xffffffff,
1120 .res = buffer_read.len,1120 .res = buffer_read.len,
1121 .flags = 0,1121 .flags = 0,
1122 }, try ring.copy_cqe());1122 }, 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..]);
1126}1126}
11271127
1128test "write/read" {1128test "write/read" {
...@@ -1144,13 +1144,13 @@ test "write/read" {...@@ -1144,13 +1144,13 @@ test "write/read" {
1144 const buffer_write = [_]u8{97} ** 20;1144 const buffer_write = [_]u8{97} ** 20;
1145 var buffer_read = [_]u8{98} ** 20;1145 var buffer_read = [_]u8{98} ** 20;
1146 const sqe_write = try ring.write(0x11111111, fd, buffer_write[0..], 10);1146 const sqe_write = try ring.write(0x11111111, fd, buffer_write[0..], 10);
1147 testing.expectEqual(linux.IORING_OP.WRITE, sqe_write.opcode);1147 try testing.expectEqual(linux.IORING_OP.WRITE, sqe_write.opcode);
1148 testing.expectEqual(@as(u64, 10), sqe_write.off);1148 try testing.expectEqual(@as(u64, 10), sqe_write.off);
1149 sqe_write.flags |= linux.IOSQE_IO_LINK;1149 sqe_write.flags |= linux.IOSQE_IO_LINK;
1150 const sqe_read = try ring.read(0x22222222, fd, buffer_read[0..], 10);1150 const sqe_read = try ring.read(0x22222222, fd, buffer_read[0..], 10);
1151 testing.expectEqual(linux.IORING_OP.READ, sqe_read.opcode);1151 try testing.expectEqual(linux.IORING_OP.READ, sqe_read.opcode);
1152 testing.expectEqual(@as(u64, 10), sqe_read.off);1152 try testing.expectEqual(@as(u64, 10), sqe_read.off);
1153 testing.expectEqual(@as(u32, 2), try ring.submit());1153 try testing.expectEqual(@as(u32, 2), try ring.submit());
11541154
1155 const cqe_write = try ring.copy_cqe();1155 const cqe_write = try ring.copy_cqe();
1156 const cqe_read = try ring.copy_cqe();1156 const cqe_read = try ring.copy_cqe();
...@@ -1158,17 +1158,17 @@ test "write/read" {...@@ -1158,17 +1158,17 @@ test "write/read" {
1158 // https://lwn.net/Articles/809820/1158 // https://lwn.net/Articles/809820/
1159 if (cqe_write.res == -linux.EINVAL) return error.SkipZigTest;1159 if (cqe_write.res == -linux.EINVAL) return error.SkipZigTest;
1160 if (cqe_read.res == -linux.EINVAL) return error.SkipZigTest;1160 if (cqe_read.res == -linux.EINVAL) return error.SkipZigTest;
1161 testing.expectEqual(linux.io_uring_cqe{1161 try testing.expectEqual(linux.io_uring_cqe{
1162 .user_data = 0x11111111,1162 .user_data = 0x11111111,
1163 .res = buffer_write.len,1163 .res = buffer_write.len,
1164 .flags = 0,1164 .flags = 0,
1165 }, cqe_write);1165 }, cqe_write);
1166 testing.expectEqual(linux.io_uring_cqe{1166 try testing.expectEqual(linux.io_uring_cqe{
1167 .user_data = 0x22222222,1167 .user_data = 0x22222222,
1168 .res = buffer_read.len,1168 .res = buffer_read.len,
1169 .flags = 0,1169 .flags = 0,
1170 }, cqe_read);1170 }, cqe_read);
1171 testing.expectEqualSlices(u8, buffer_write[0..], buffer_read[0..]);1171 try testing.expectEqualSlices(u8, buffer_write[0..], buffer_read[0..]);
1172}1172}
11731173
1174test "openat" {1174test "openat" {
...@@ -1187,7 +1187,7 @@ test "openat" {...@@ -1187,7 +1187,7 @@ test "openat" {
1187 const flags: u32 = os.O_CLOEXEC | os.O_RDWR | os.O_CREAT;1187 const flags: u32 = os.O_CLOEXEC | os.O_RDWR | os.O_CREAT;
1188 const mode: os.mode_t = 0o666;1188 const mode: os.mode_t = 0o666;
1189 const sqe_openat = try ring.openat(0x33333333, linux.AT_FDCWD, path, flags, mode);1189 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{
1191 .opcode = .OPENAT,1191 .opcode = .OPENAT,
1192 .flags = 0,1192 .flags = 0,
1193 .ioprio = 0,1193 .ioprio = 0,
...@@ -1202,10 +1202,10 @@ test "openat" {...@@ -1202,10 +1202,10 @@ test "openat" {
1202 .splice_fd_in = 0,1202 .splice_fd_in = 0,
1203 .__pad2 = [2]u64{ 0, 0 },1203 .__pad2 = [2]u64{ 0, 0 },
1204 }, sqe_openat.*);1204 }, sqe_openat.*);
1205 testing.expectEqual(@as(u32, 1), try ring.submit());1205 try testing.expectEqual(@as(u32, 1), try ring.submit());
12061206
1207 const cqe_openat = try ring.copy_cqe();1207 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);
1209 if (cqe_openat.res == -linux.EINVAL) return error.SkipZigTest;1209 if (cqe_openat.res == -linux.EINVAL) return error.SkipZigTest;
1210 // AT_FDCWD is not fully supported before kernel 5.6:1210 // AT_FDCWD is not fully supported before kernel 5.6:
1211 // See https://lore.kernel.org/io-uring/20200207155039.12819-1-axboe@kernel.dk/T/1211 // See https://lore.kernel.org/io-uring/20200207155039.12819-1-axboe@kernel.dk/T/
...@@ -1214,8 +1214,8 @@ test "openat" {...@@ -1214,8 +1214,8 @@ test "openat" {
1214 return error.SkipZigTest;1214 return error.SkipZigTest;
1215 }1215 }
1216 if (cqe_openat.res <= 0) std.debug.print("\ncqe_openat.res={}\n", .{cqe_openat.res});1216 if (cqe_openat.res <= 0) std.debug.print("\ncqe_openat.res={}\n", .{cqe_openat.res});
1217 testing.expect(cqe_openat.res > 0);1217 try testing.expect(cqe_openat.res > 0);
1218 testing.expectEqual(@as(u32, 0), cqe_openat.flags);1218 try testing.expectEqual(@as(u32, 0), cqe_openat.flags);
12191219
1220 os.close(cqe_openat.res);1220 os.close(cqe_openat.res);
1221}1221}
...@@ -1236,13 +1236,13 @@ test "close" {...@@ -1236,13 +1236,13 @@ test "close" {
1236 defer std.fs.cwd().deleteFile(path) catch {};1236 defer std.fs.cwd().deleteFile(path) catch {};
12371237
1238 const sqe_close = try ring.close(0x44444444, file.handle);1238 const sqe_close = try ring.close(0x44444444, file.handle);
1239 testing.expectEqual(linux.IORING_OP.CLOSE, sqe_close.opcode);1239 try testing.expectEqual(linux.IORING_OP.CLOSE, sqe_close.opcode);
1240 testing.expectEqual(file.handle, sqe_close.fd);1240 try testing.expectEqual(file.handle, sqe_close.fd);
1241 testing.expectEqual(@as(u32, 1), try ring.submit());1241 try testing.expectEqual(@as(u32, 1), try ring.submit());
12421242
1243 const cqe_close = try ring.copy_cqe();1243 const cqe_close = try ring.copy_cqe();
1244 if (cqe_close.res == -linux.EINVAL) return error.SkipZigTest;1244 if (cqe_close.res == -linux.EINVAL) return error.SkipZigTest;
1245 testing.expectEqual(linux.io_uring_cqe{1245 try testing.expectEqual(linux.io_uring_cqe{
1246 .user_data = 0x44444444,1246 .user_data = 0x44444444,
1247 .res = 0,1247 .res = 0,
1248 .flags = 0,1248 .flags = 0,
...@@ -1273,12 +1273,12 @@ test "accept/connect/send/recv" {...@@ -1273,12 +1273,12 @@ test "accept/connect/send/recv" {
1273 var accept_addr: os.sockaddr = undefined;1273 var accept_addr: os.sockaddr = undefined;
1274 var accept_addr_len: os.socklen_t = @sizeOf(@TypeOf(accept_addr));1274 var accept_addr_len: os.socklen_t = @sizeOf(@TypeOf(accept_addr));
1275 const accept = try ring.accept(0xaaaaaaaa, server, &accept_addr, &accept_addr_len, 0);1275 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
1278 const client = try os.socket(address.any.family, os.SOCK_STREAM | os.SOCK_CLOEXEC, 0);1278 const client = try os.socket(address.any.family, os.SOCK_STREAM | os.SOCK_CLOEXEC, 0);
1279 defer os.close(client);1279 defer os.close(client);
1280 const connect = try ring.connect(0xcccccccc, client, &address.any, address.getOsSockLen());1280 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
1283 var cqe_accept = try ring.copy_cqe();1283 var cqe_accept = try ring.copy_cqe();
1284 if (cqe_accept.res == -linux.EINVAL) return error.SkipZigTest;1284 if (cqe_accept.res == -linux.EINVAL) return error.SkipZigTest;
...@@ -1293,11 +1293,11 @@ test "accept/connect/send/recv" {...@@ -1293,11 +1293,11 @@ test "accept/connect/send/recv" {
1293 cqe_connect = a;1293 cqe_connect = a;
1294 }1294 }
12951295
1296 testing.expectEqual(@as(u64, 0xaaaaaaaa), cqe_accept.user_data);1296 try testing.expectEqual(@as(u64, 0xaaaaaaaa), cqe_accept.user_data);
1297 if (cqe_accept.res <= 0) std.debug.print("\ncqe_accept.res={}\n", .{cqe_accept.res});1297 if (cqe_accept.res <= 0) std.debug.print("\ncqe_accept.res={}\n", .{cqe_accept.res});
1298 testing.expect(cqe_accept.res > 0);1298 try testing.expect(cqe_accept.res > 0);
1299 testing.expectEqual(@as(u32, 0), cqe_accept.flags);1299 try testing.expectEqual(@as(u32, 0), cqe_accept.flags);
1300 testing.expectEqual(linux.io_uring_cqe{1300 try testing.expectEqual(linux.io_uring_cqe{
1301 .user_data = 0xcccccccc,1301 .user_data = 0xcccccccc,
1302 .res = 0,1302 .res = 0,
1303 .flags = 0,1303 .flags = 0,
...@@ -1306,11 +1306,11 @@ test "accept/connect/send/recv" {...@@ -1306,11 +1306,11 @@ test "accept/connect/send/recv" {
1306 const send = try ring.send(0xeeeeeeee, client, buffer_send[0..], 0);1306 const send = try ring.send(0xeeeeeeee, client, buffer_send[0..], 0);
1307 send.flags |= linux.IOSQE_IO_LINK;1307 send.flags |= linux.IOSQE_IO_LINK;
1308 const recv = try ring.recv(0xffffffff, cqe_accept.res, buffer_recv[0..], 0);1308 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
1311 const cqe_send = try ring.copy_cqe();1311 const cqe_send = try ring.copy_cqe();
1312 if (cqe_send.res == -linux.EINVAL) return error.SkipZigTest;1312 if (cqe_send.res == -linux.EINVAL) return error.SkipZigTest;
1313 testing.expectEqual(linux.io_uring_cqe{1313 try testing.expectEqual(linux.io_uring_cqe{
1314 .user_data = 0xeeeeeeee,1314 .user_data = 0xeeeeeeee,
1315 .res = buffer_send.len,1315 .res = buffer_send.len,
1316 .flags = 0,1316 .flags = 0,
...@@ -1318,13 +1318,13 @@ test "accept/connect/send/recv" {...@@ -1318,13 +1318,13 @@ test "accept/connect/send/recv" {
13181318
1319 const cqe_recv = try ring.copy_cqe();1319 const cqe_recv = try ring.copy_cqe();
1320 if (cqe_recv.res == -linux.EINVAL) return error.SkipZigTest;1320 if (cqe_recv.res == -linux.EINVAL) return error.SkipZigTest;
1321 testing.expectEqual(linux.io_uring_cqe{1321 try testing.expectEqual(linux.io_uring_cqe{
1322 .user_data = 0xffffffff,1322 .user_data = 0xffffffff,
1323 .res = buffer_recv.len,1323 .res = buffer_recv.len,
1324 .flags = 0,1324 .flags = 0,
1325 }, cqe_recv);1325 }, 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..]);
1328}1328}
13291329
1330test "timeout (after a relative time)" {1330test "timeout (after a relative time)" {
...@@ -1343,12 +1343,12 @@ test "timeout (after a relative time)" {...@@ -1343,12 +1343,12 @@ test "timeout (after a relative time)" {
13431343
1344 const started = std.time.milliTimestamp();1344 const started = std.time.milliTimestamp();
1345 const sqe = try ring.timeout(0x55555555, &ts, 0, 0);1345 const sqe = try ring.timeout(0x55555555, &ts, 0, 0);
1346 testing.expectEqual(linux.IORING_OP.TIMEOUT, sqe.opcode);1346 try testing.expectEqual(linux.IORING_OP.TIMEOUT, sqe.opcode);
1347 testing.expectEqual(@as(u32, 1), try ring.submit());1347 try testing.expectEqual(@as(u32, 1), try ring.submit());
1348 const cqe = try ring.copy_cqe();1348 const cqe = try ring.copy_cqe();
1349 const stopped = std.time.milliTimestamp();1349 const stopped = std.time.milliTimestamp();
13501350
1351 testing.expectEqual(linux.io_uring_cqe{1351 try testing.expectEqual(linux.io_uring_cqe{
1352 .user_data = 0x55555555,1352 .user_data = 0x55555555,
1353 .res = -linux.ETIME,1353 .res = -linux.ETIME,
1354 .flags = 0,1354 .flags = 0,
...@@ -1371,20 +1371,20 @@ test "timeout (after a number of completions)" {...@@ -1371,20 +1371,20 @@ test "timeout (after a number of completions)" {
1371 const ts = os.__kernel_timespec{ .tv_sec = 3, .tv_nsec = 0 };1371 const ts = os.__kernel_timespec{ .tv_sec = 3, .tv_nsec = 0 };
1372 const count_completions: u64 = 1;1372 const count_completions: u64 = 1;
1373 const sqe_timeout = try ring.timeout(0x66666666, &ts, count_completions, 0);1373 const sqe_timeout = try ring.timeout(0x66666666, &ts, count_completions, 0);
1374 testing.expectEqual(linux.IORING_OP.TIMEOUT, sqe_timeout.opcode);1374 try testing.expectEqual(linux.IORING_OP.TIMEOUT, sqe_timeout.opcode);
1375 testing.expectEqual(count_completions, sqe_timeout.off);1375 try testing.expectEqual(count_completions, sqe_timeout.off);
1376 _ = try ring.nop(0x77777777);1376 _ = try ring.nop(0x77777777);
1377 testing.expectEqual(@as(u32, 2), try ring.submit());1377 try testing.expectEqual(@as(u32, 2), try ring.submit());
13781378
1379 const cqe_nop = try ring.copy_cqe();1379 const cqe_nop = try ring.copy_cqe();
1380 testing.expectEqual(linux.io_uring_cqe{1380 try testing.expectEqual(linux.io_uring_cqe{
1381 .user_data = 0x77777777,1381 .user_data = 0x77777777,
1382 .res = 0,1382 .res = 0,
1383 .flags = 0,1383 .flags = 0,
1384 }, cqe_nop);1384 }, cqe_nop);
13851385
1386 const cqe_timeout = try ring.copy_cqe();1386 const cqe_timeout = try ring.copy_cqe();
1387 testing.expectEqual(linux.io_uring_cqe{1387 try testing.expectEqual(linux.io_uring_cqe{
1388 .user_data = 0x66666666,1388 .user_data = 0x66666666,
1389 .res = 0,1389 .res = 0,
1390 .flags = 0,1390 .flags = 0,
...@@ -1403,15 +1403,15 @@ test "timeout_remove" {...@@ -1403,15 +1403,15 @@ test "timeout_remove" {
14031403
1404 const ts = os.__kernel_timespec{ .tv_sec = 3, .tv_nsec = 0 };1404 const ts = os.__kernel_timespec{ .tv_sec = 3, .tv_nsec = 0 };
1405 const sqe_timeout = try ring.timeout(0x88888888, &ts, 0, 0);1405 const sqe_timeout = try ring.timeout(0x88888888, &ts, 0, 0);
1406 testing.expectEqual(linux.IORING_OP.TIMEOUT, sqe_timeout.opcode);1406 try testing.expectEqual(linux.IORING_OP.TIMEOUT, sqe_timeout.opcode);
1407 testing.expectEqual(@as(u64, 0x88888888), sqe_timeout.user_data);1407 try testing.expectEqual(@as(u64, 0x88888888), sqe_timeout.user_data);
14081408
1409 const sqe_timeout_remove = try ring.timeout_remove(0x99999999, 0x88888888, 0);1409 const sqe_timeout_remove = try ring.timeout_remove(0x99999999, 0x88888888, 0);
1410 testing.expectEqual(linux.IORING_OP.TIMEOUT_REMOVE, sqe_timeout_remove.opcode);1410 try testing.expectEqual(linux.IORING_OP.TIMEOUT_REMOVE, sqe_timeout_remove.opcode);
1411 testing.expectEqual(@as(u64, 0x88888888), sqe_timeout_remove.addr);1411 try testing.expectEqual(@as(u64, 0x88888888), sqe_timeout_remove.addr);
1412 testing.expectEqual(@as(u64, 0x99999999), sqe_timeout_remove.user_data);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
1416 const cqe_timeout = try ring.copy_cqe();1416 const cqe_timeout = try ring.copy_cqe();
1417 // IORING_OP_TIMEOUT_REMOVE is not supported by this kernel version:1417 // IORING_OP_TIMEOUT_REMOVE is not supported by this kernel version:
...@@ -1424,14 +1424,14 @@ test "timeout_remove" {...@@ -1424,14 +1424,14 @@ test "timeout_remove" {
1424 {1424 {
1425 return error.SkipZigTest;1425 return error.SkipZigTest;
1426 }1426 }
1427 testing.expectEqual(linux.io_uring_cqe{1427 try testing.expectEqual(linux.io_uring_cqe{
1428 .user_data = 0x88888888,1428 .user_data = 0x88888888,
1429 .res = -linux.ECANCELED,1429 .res = -linux.ECANCELED,
1430 .flags = 0,1430 .flags = 0,
1431 }, cqe_timeout);1431 }, cqe_timeout);
14321432
1433 const cqe_timeout_remove = try ring.copy_cqe();1433 const cqe_timeout_remove = try ring.copy_cqe();
1434 testing.expectEqual(linux.io_uring_cqe{1434 try testing.expectEqual(linux.io_uring_cqe{
1435 .user_data = 0x99999999,1435 .user_data = 0x99999999,
1436 .res = 0,1436 .res = 0,
1437 .flags = 0,1437 .flags = 0,
...@@ -1453,13 +1453,13 @@ test "fallocate" {...@@ -1453,13 +1453,13 @@ test "fallocate" {
1453 defer file.close();1453 defer file.close();
1454 defer std.fs.cwd().deleteFile(path) catch {};1454 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
1458 const len: u64 = 65536;1458 const len: u64 = 65536;
1459 const sqe = try ring.fallocate(0xaaaaaaaa, file.handle, 0, 0, len);1459 const sqe = try ring.fallocate(0xaaaaaaaa, file.handle, 0, 0, len);
1460 testing.expectEqual(linux.IORING_OP.FALLOCATE, sqe.opcode);1460 try testing.expectEqual(linux.IORING_OP.FALLOCATE, sqe.opcode);
1461 testing.expectEqual(file.handle, sqe.fd);1461 try testing.expectEqual(file.handle, sqe.fd);
1462 testing.expectEqual(@as(u32, 1), try ring.submit());1462 try testing.expectEqual(@as(u32, 1), try ring.submit());
14631463
1464 const cqe = try ring.copy_cqe();1464 const cqe = try ring.copy_cqe();
1465 switch (-cqe.res) {1465 switch (-cqe.res) {
...@@ -1473,11 +1473,11 @@ test "fallocate" {...@@ -1473,11 +1473,11 @@ test "fallocate" {
1473 linux.EOPNOTSUPP => return error.SkipZigTest,1473 linux.EOPNOTSUPP => return error.SkipZigTest,
1474 else => |errno| std.debug.panic("unhandled errno: {}", .{errno}),1474 else => |errno| std.debug.panic("unhandled errno: {}", .{errno}),
1475 }1475 }
1476 testing.expectEqual(linux.io_uring_cqe{1476 try testing.expectEqual(linux.io_uring_cqe{
1477 .user_data = 0xaaaaaaaa,1477 .user_data = 0xaaaaaaaa,
1478 .res = 0,1478 .res = 0,
1479 .flags = 0,1479 .flags = 0,
1480 }, cqe);1480 }, cqe);
14811481
1482 testing.expectEqual(len, (try file.stat()).size);1482 try testing.expectEqual(len, (try file.stat()).size);
1483}1483}
lib/std/os/linux/test.zig+17-17
...@@ -18,7 +18,7 @@ test "fallocate" {...@@ -18,7 +18,7 @@ test "fallocate" {
18 defer file.close();18 defer file.close();
19 defer fs.cwd().deleteFile(path) catch {};19 defer fs.cwd().deleteFile(path) catch {};
2020
21 expect((try file.stat()).size == 0);21 try expect((try file.stat()).size == 0);
2222
23 const len: u64 = 65536;23 const len: u64 = 65536;
24 switch (linux.getErrno(linux.fallocate(file.handle, 0, 0, len))) {24 switch (linux.getErrno(linux.fallocate(file.handle, 0, 0, len))) {
...@@ -28,20 +28,20 @@ test "fallocate" {...@@ -28,20 +28,20 @@ test "fallocate" {
28 else => |errno| std.debug.panic("unhandled errno: {}", .{errno}),28 else => |errno| std.debug.panic("unhandled errno: {}", .{errno}),
29 }29 }
3030
31 expect((try file.stat()).size == len);31 try expect((try file.stat()).size == len);
32}32}
3333
34test "getpid" {34test "getpid" {
35 expect(linux.getpid() != 0);35 try expect(linux.getpid() != 0);
36}36}
3737
38test "timer" {38test "timer" {
39 const epoll_fd = linux.epoll_create();39 const epoll_fd = linux.epoll_create();
40 var err: usize = linux.getErrno(epoll_fd);40 var err: usize = linux.getErrno(epoll_fd);
41 expect(err == 0);41 try expect(err == 0);
4242
43 const timer_fd = linux.timerfd_create(linux.CLOCK_MONOTONIC, 0);43 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
46 const time_interval = linux.timespec{46 const time_interval = linux.timespec{
47 .tv_sec = 0,47 .tv_sec = 0,
...@@ -54,7 +54,7 @@ test "timer" {...@@ -54,7 +54,7 @@ test "timer" {
54 };54 };
5555
56 err = linux.timerfd_settime(@intCast(i32, timer_fd), 0, &new_time, null);56 err = linux.timerfd_settime(@intCast(i32, timer_fd), 0, &new_time, null);
57 expect(err == 0);57 try expect(err == 0);
5858
59 var event = linux.epoll_event{59 var event = linux.epoll_event{
60 .events = linux.EPOLLIN | linux.EPOLLOUT | linux.EPOLLET,60 .events = linux.EPOLLIN | linux.EPOLLOUT | linux.EPOLLET,
...@@ -62,7 +62,7 @@ test "timer" {...@@ -62,7 +62,7 @@ test "timer" {
62 };62 };
6363
64 err = linux.epoll_ctl(@intCast(i32, epoll_fd), linux.EPOLL_CTL_ADD, @intCast(i32, timer_fd), &event);64 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
67 const events_one: linux.epoll_event = undefined;67 const events_one: linux.epoll_event = undefined;
68 var events = [_]linux.epoll_event{events_one} ** 8;68 var events = [_]linux.epoll_event{events_one} ** 8;
...@@ -93,18 +93,18 @@ test "statx" {...@@ -93,18 +93,18 @@ test "statx" {
93 else => unreachable,93 else => unreachable,
94 }94 }
9595
96 expect(stat_buf.mode == statx_buf.mode);96 try expect(stat_buf.mode == statx_buf.mode);
97 expect(@bitCast(u32, stat_buf.uid) == statx_buf.uid);97 try expect(@bitCast(u32, stat_buf.uid) == statx_buf.uid);
98 expect(@bitCast(u32, stat_buf.gid) == statx_buf.gid);98 try expect(@bitCast(u32, stat_buf.gid) == statx_buf.gid);
99 expect(@bitCast(u64, @as(i64, stat_buf.size)) == statx_buf.size);99 try expect(@bitCast(u64, @as(i64, stat_buf.size)) == statx_buf.size);
100 expect(@bitCast(u64, @as(i64, stat_buf.blksize)) == statx_buf.blksize);100 try expect(@bitCast(u64, @as(i64, stat_buf.blksize)) == statx_buf.blksize);
101 expect(@bitCast(u64, @as(i64, stat_buf.blocks)) == statx_buf.blocks);101 try expect(@bitCast(u64, @as(i64, stat_buf.blocks)) == statx_buf.blocks);
102}102}
103103
104test "user and group ids" {104test "user and group ids" {
105 if (builtin.link_libc) return error.SkipZigTest;105 if (builtin.link_libc) return error.SkipZigTest;
106 expectEqual(linux.getauxval(elf.AT_UID), linux.getuid());106 try expectEqual(linux.getauxval(elf.AT_UID), linux.getuid());
107 expectEqual(linux.getauxval(elf.AT_GID), linux.getgid());107 try expectEqual(linux.getauxval(elf.AT_GID), linux.getgid());
108 expectEqual(linux.getauxval(elf.AT_EUID), linux.geteuid());108 try expectEqual(linux.getauxval(elf.AT_EUID), linux.geteuid());
109 expectEqual(linux.getauxval(elf.AT_EGID), linux.getegid());109 try expectEqual(linux.getauxval(elf.AT_EGID), linux.getegid());
110}110}
lib/std/os/test.zig+51-51
...@@ -37,7 +37,7 @@ test "chdir smoke test" {...@@ -37,7 +37,7 @@ test "chdir smoke test" {
37 try os.chdir(old_cwd);37 try os.chdir(old_cwd);
38 var new_cwd_buf: [fs.MAX_PATH_BYTES]u8 = undefined;38 var new_cwd_buf: [fs.MAX_PATH_BYTES]u8 = undefined;
39 const new_cwd = try os.getcwd(new_cwd_buf[0..]);39 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));
41 }41 }
42 {42 {
43 // Next, change current working directory to one level above43 // Next, change current working directory to one level above
...@@ -47,7 +47,7 @@ test "chdir smoke test" {...@@ -47,7 +47,7 @@ test "chdir smoke test" {
47 defer os.chdir(old_cwd) catch unreachable;47 defer os.chdir(old_cwd) catch unreachable;
48 var new_cwd_buf: [fs.MAX_PATH_BYTES]u8 = undefined;48 var new_cwd_buf: [fs.MAX_PATH_BYTES]u8 = undefined;
49 const new_cwd = try os.getcwd(new_cwd_buf[0..]);49 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));
51 }51 }
52}52}
5353
...@@ -79,7 +79,7 @@ test "open smoke test" {...@@ -79,7 +79,7 @@ test "open smoke test" {
7979
80 // Try this again with the same flags. This op should fail with error.PathAlreadyExists.80 // Try this again with the same flags. This op should fail with error.PathAlreadyExists.
81 file_path = try fs.path.join(&arena.allocator, &[_][]const u8{ base_path, "some_file" });81 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
84 // Try opening without `O_EXCL` flag.84 // Try opening without `O_EXCL` flag.
85 file_path = try fs.path.join(&arena.allocator, &[_][]const u8{ base_path, "some_file" });85 file_path = try fs.path.join(&arena.allocator, &[_][]const u8{ base_path, "some_file" });
...@@ -88,7 +88,7 @@ test "open smoke test" {...@@ -88,7 +88,7 @@ test "open smoke test" {
8888
89 // Try opening as a directory which should fail.89 // Try opening as a directory which should fail.
90 file_path = try fs.path.join(&arena.allocator, &[_][]const u8{ base_path, "some_file" });90 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
93 // Create some directory93 // Create some directory
94 file_path = try fs.path.join(&arena.allocator, &[_][]const u8{ base_path, "some_dir" });94 file_path = try fs.path.join(&arena.allocator, &[_][]const u8{ base_path, "some_dir" });
...@@ -101,7 +101,7 @@ test "open smoke test" {...@@ -101,7 +101,7 @@ test "open smoke test" {
101101
102 // Try opening as file which should fail.102 // Try opening as file which should fail.
103 file_path = try fs.path.join(&arena.allocator, &[_][]const u8{ base_path, "some_dir" });103 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));
105}105}
106106
107test "openat smoke test" {107test "openat smoke test" {
...@@ -120,14 +120,14 @@ test "openat smoke test" {...@@ -120,14 +120,14 @@ test "openat smoke test" {
120 os.close(fd);120 os.close(fd);
121121
122 // Try this again with the same flags. This op should fail with error.PathAlreadyExists.122 // 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
125 // Try opening without `O_EXCL` flag.125 // Try opening without `O_EXCL` flag.
126 fd = try os.openat(tmp.dir.fd, "some_file", os.O_RDWR | os.O_CREAT, mode);126 fd = try os.openat(tmp.dir.fd, "some_file", os.O_RDWR | os.O_CREAT, mode);
127 os.close(fd);127 os.close(fd);
128128
129 // Try opening as a directory which should fail.129 // 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
132 // Create some directory132 // Create some directory
133 try os.mkdirat(tmp.dir.fd, "some_dir", mode);133 try os.mkdirat(tmp.dir.fd, "some_dir", mode);
...@@ -137,7 +137,7 @@ test "openat smoke test" {...@@ -137,7 +137,7 @@ test "openat smoke test" {
137 os.close(fd);137 os.close(fd);
138138
139 // Try opening as file which should fail.139 // 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));
141}141}
142142
143test "symlink with relative paths" {143test "symlink with relative paths" {
...@@ -171,7 +171,7 @@ test "symlink with relative paths" {...@@ -171,7 +171,7 @@ test "symlink with relative paths" {
171171
172 var buffer: [fs.MAX_PATH_BYTES]u8 = undefined;172 var buffer: [fs.MAX_PATH_BYTES]u8 = undefined;
173 const given = try os.readlink("symlinked", buffer[0..]);173 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
176 try cwd.deleteFile("file.txt");176 try cwd.deleteFile("file.txt");
177 try cwd.deleteFile("symlinked");177 try cwd.deleteFile("symlinked");
...@@ -188,7 +188,7 @@ test "readlink on Windows" {...@@ -188,7 +188,7 @@ test "readlink on Windows" {
188fn testReadlink(target_path: []const u8, symlink_path: []const u8) !void {188fn testReadlink(target_path: []const u8, symlink_path: []const u8) !void {
189 var buffer: [fs.MAX_PATH_BYTES]u8 = undefined;189 var buffer: [fs.MAX_PATH_BYTES]u8 = undefined;
190 const given = try os.readlink(symlink_path, buffer[0..]);190 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));
192}192}
193193
194test "link with relative paths" {194test "link with relative paths" {
...@@ -211,15 +211,15 @@ test "link with relative paths" {...@@ -211,15 +211,15 @@ test "link with relative paths" {
211 const estat = try os.fstat(efd.handle);211 const estat = try os.fstat(efd.handle);
212 const nstat = try os.fstat(nfd.handle);212 const nstat = try os.fstat(nfd.handle);
213213
214 testing.expectEqual(estat.ino, nstat.ino);214 try testing.expectEqual(estat.ino, nstat.ino);
215 testing.expectEqual(@as(usize, 2), nstat.nlink);215 try testing.expectEqual(@as(usize, 2), nstat.nlink);
216 }216 }
217217
218 try os.unlink("new.txt");218 try os.unlink("new.txt");
219219
220 {220 {
221 const estat = try os.fstat(efd.handle);221 const estat = try os.fstat(efd.handle);
222 testing.expectEqual(@as(usize, 1), estat.nlink);222 try testing.expectEqual(@as(usize, 1), estat.nlink);
223 }223 }
224224
225 try cwd.deleteFile("example.txt");225 try cwd.deleteFile("example.txt");
...@@ -246,15 +246,15 @@ test "linkat with different directories" {...@@ -246,15 +246,15 @@ test "linkat with different directories" {
246 const estat = try os.fstat(efd.handle);246 const estat = try os.fstat(efd.handle);
247 const nstat = try os.fstat(nfd.handle);247 const nstat = try os.fstat(nfd.handle);
248248
249 testing.expectEqual(estat.ino, nstat.ino);249 try testing.expectEqual(estat.ino, nstat.ino);
250 testing.expectEqual(@as(usize, 2), nstat.nlink);250 try testing.expectEqual(@as(usize, 2), nstat.nlink);
251 }251 }
252252
253 try os.unlinkat(tmp.dir.fd, "new.txt", 0);253 try os.unlinkat(tmp.dir.fd, "new.txt", 0);
254254
255 {255 {
256 const estat = try os.fstat(efd.handle);256 const estat = try os.fstat(efd.handle);
257 testing.expectEqual(@as(usize, 1), estat.nlink);257 try testing.expectEqual(@as(usize, 1), estat.nlink);
258 }258 }
259259
260 try cwd.deleteFile("example.txt");260 try cwd.deleteFile("example.txt");
...@@ -283,7 +283,7 @@ test "fstatat" {...@@ -283,7 +283,7 @@ test "fstatat" {
283 // now repeat but using `fstatat` instead283 // now repeat but using `fstatat` instead
284 const flags = if (builtin.os.tag == .wasi) 0x0 else os.AT_SYMLINK_NOFOLLOW;284 const flags = if (builtin.os.tag == .wasi) 0x0 else os.AT_SYMLINK_NOFOLLOW;
285 const statat = try os.fstatat(tmp.dir.fd, "file.txt", flags);285 const statat = try os.fstatat(tmp.dir.fd, "file.txt", flags);
286 expectEqual(stat, statat);286 try expectEqual(stat, statat);
287}287}
288288
289test "readlinkat" {289test "readlinkat" {
...@@ -312,7 +312,7 @@ test "readlinkat" {...@@ -312,7 +312,7 @@ test "readlinkat" {
312 // read the link312 // read the link
313 var buffer: [fs.MAX_PATH_BYTES]u8 = undefined;313 var buffer: [fs.MAX_PATH_BYTES]u8 = undefined;
314 const read_link = try os.readlinkat(tmp.dir.fd, "link", buffer[0..]);314 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));
316}316}
317317
318fn testThreadIdFn(thread_id: *Thread.Id) void {318fn testThreadIdFn(thread_id: *Thread.Id) void {
...@@ -327,13 +327,13 @@ test "std.Thread.getCurrentId" {...@@ -327,13 +327,13 @@ test "std.Thread.getCurrentId" {
327 const thread_id = thread.handle();327 const thread_id = thread.handle();
328 thread.wait();328 thread.wait();
329 if (Thread.use_pthreads) {329 if (Thread.use_pthreads) {
330 expect(thread_current_id == thread_id);330 try expect(thread_current_id == thread_id);
331 } else if (builtin.os.tag == .windows) {331 } else if (builtin.os.tag == .windows) {
332 expect(Thread.getCurrentId() != thread_current_id);332 try expect(Thread.getCurrentId() != thread_current_id);
333 } else {333 } else {
334 // If the thread completes very quickly, then thread_id can be 0. See the334 // If the thread completes very quickly, then thread_id can be 0. See the
335 // documentation comments for `std.Thread.handle`.335 // 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);
337 }337 }
338}338}
339339
...@@ -352,7 +352,7 @@ test "spawn threads" {...@@ -352,7 +352,7 @@ test "spawn threads" {
352 thread3.wait();352 thread3.wait();
353 thread4.wait();353 thread4.wait();
354354
355 expect(shared_ctx == 4);355 try expect(shared_ctx == 4);
356}356}
357357
358fn start1(ctx: void) u8 {358fn start1(ctx: void) u8 {
...@@ -368,23 +368,23 @@ test "cpu count" {...@@ -368,23 +368,23 @@ test "cpu count" {
368 if (builtin.os.tag == .wasi) return error.SkipZigTest;368 if (builtin.os.tag == .wasi) return error.SkipZigTest;
369369
370 const cpu_count = try Thread.cpuCount();370 const cpu_count = try Thread.cpuCount();
371 expect(cpu_count >= 1);371 try expect(cpu_count >= 1);
372}372}
373373
374test "thread local storage" {374test "thread local storage" {
375 if (builtin.single_threaded) return error.SkipZigTest;375 if (builtin.single_threaded) return error.SkipZigTest;
376 const thread1 = try Thread.spawn(testTls, {});376 const thread1 = try Thread.spawn(testTls, {});
377 const thread2 = try Thread.spawn(testTls, {});377 const thread2 = try Thread.spawn(testTls, {});
378 testTls({});378 try testTls({});
379 thread1.wait();379 thread1.wait();
380 thread2.wait();380 thread2.wait();
381}381}
382382
383threadlocal var x: i32 = 1234;383threadlocal var x: i32 = 1234;
384fn testTls(context: void) void {384fn testTls(context: void) !void {
385 if (x != 1234) @panic("bad start value");385 if (x != 1234) return error.TlsBadStartValue;
386 x += 1;386 x += 1;
387 if (x != 1235) @panic("bad end value");387 if (x != 1235) return error.TlsBadEndValue;
388}388}
389389
390test "getrandom" {390test "getrandom" {
...@@ -394,7 +394,7 @@ test "getrandom" {...@@ -394,7 +394,7 @@ test "getrandom" {
394 try os.getrandom(&buf_b);394 try os.getrandom(&buf_b);
395 // If this test fails the chance is significantly higher that there is a bug than395 // If this test fails the chance is significantly higher that there is a bug than
396 // that two sets of 50 bytes were equal.396 // 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));
398}398}
399399
400test "getcwd" {400test "getcwd" {
...@@ -413,7 +413,7 @@ test "sigaltstack" {...@@ -413,7 +413,7 @@ test "sigaltstack" {
413 // Setting a stack size less than MINSIGSTKSZ returns ENOMEM413 // Setting a stack size less than MINSIGSTKSZ returns ENOMEM
414 st.ss_flags = 0;414 st.ss_flags = 0;
415 st.ss_size = 1;415 st.ss_size = 1;
416 testing.expectError(error.SizeTooSmall, os.sigaltstack(&st, null));416 try testing.expectError(error.SizeTooSmall, os.sigaltstack(&st, null));
417}417}
418418
419// If the type is not available use void to avoid erroring out when `iter_fn` is419// If the type is not available use void to avoid erroring out when `iter_fn` is
...@@ -464,7 +464,7 @@ test "dl_iterate_phdr" {...@@ -464,7 +464,7 @@ test "dl_iterate_phdr" {
464464
465 var counter: usize = 0;465 var counter: usize = 0;
466 try os.dl_iterate_phdr(&counter, IterFnError, iter_fn);466 try os.dl_iterate_phdr(&counter, IterFnError, iter_fn);
467 expect(counter != 0);467 try expect(counter != 0);
468}468}
469469
470test "gethostname" {470test "gethostname" {
...@@ -473,7 +473,7 @@ test "gethostname" {...@@ -473,7 +473,7 @@ test "gethostname" {
473473
474 var buf: [os.HOST_NAME_MAX]u8 = undefined;474 var buf: [os.HOST_NAME_MAX]u8 = undefined;
475 const hostname = try os.gethostname(&buf);475 const hostname = try os.gethostname(&buf);
476 expect(hostname.len != 0);476 try expect(hostname.len != 0);
477}477}
478478
479test "pipe" {479test "pipe" {
...@@ -481,10 +481,10 @@ test "pipe" {...@@ -481,10 +481,10 @@ test "pipe" {
481 return error.SkipZigTest;481 return error.SkipZigTest;
482482
483 var fds = try os.pipe();483 var fds = try os.pipe();
484 expect((try os.write(fds[1], "hello")) == 5);484 try expect((try os.write(fds[1], "hello")) == 5);
485 var buf: [16]u8 = undefined;485 var buf: [16]u8 = undefined;
486 expect((try os.read(fds[0], buf[0..])) == 5);486 try expect((try os.read(fds[0], buf[0..])) == 5);
487 testing.expectEqualSlices(u8, buf[0..5], "hello");487 try testing.expectEqualSlices(u8, buf[0..5], "hello");
488 os.close(fds[1]);488 os.close(fds[1]);
489 os.close(fds[0]);489 os.close(fds[0]);
490}490}
...@@ -503,13 +503,13 @@ test "memfd_create" {...@@ -503,13 +503,13 @@ test "memfd_create" {
503 else => |e| return e,503 else => |e| return e,
504 };504 };
505 defer std.os.close(fd);505 defer std.os.close(fd);
506 expect((try std.os.write(fd, "test")) == 4);506 try expect((try std.os.write(fd, "test")) == 4);
507 try std.os.lseek_SET(fd, 0);507 try std.os.lseek_SET(fd, 0);
508508
509 var buf: [10]u8 = undefined;509 var buf: [10]u8 = undefined;
510 const bytes_read = try std.os.read(fd, &buf);510 const bytes_read = try std.os.read(fd, &buf);
511 expect(bytes_read == 4);511 try expect(bytes_read == 4);
512 expect(mem.eql(u8, buf[0..4], "test"));512 try expect(mem.eql(u8, buf[0..4], "test"));
513}513}
514514
515test "mmap" {515test "mmap" {
...@@ -531,14 +531,14 @@ test "mmap" {...@@ -531,14 +531,14 @@ test "mmap" {
531 );531 );
532 defer os.munmap(data);532 defer os.munmap(data);
533533
534 testing.expectEqual(@as(usize, 1234), data.len);534 try testing.expectEqual(@as(usize, 1234), data.len);
535535
536 // By definition the data returned by mmap is zero-filled536 // 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
539 // Make sure the memory is writeable as requested539 // Make sure the memory is writeable as requested
540 std.mem.set(u8, data, 0x55);540 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));
542 }542 }
543543
544 const test_out_file = "os_tmp_test";544 const test_out_file = "os_tmp_test";
...@@ -578,7 +578,7 @@ test "mmap" {...@@ -578,7 +578,7 @@ test "mmap" {
578578
579 var i: u32 = 0;579 var i: u32 = 0;
580 while (i < alloc_size / @sizeOf(u32)) : (i += 1) {580 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));
582 }582 }
583 }583 }
584584
...@@ -602,7 +602,7 @@ test "mmap" {...@@ -602,7 +602,7 @@ test "mmap" {
602602
603 var i: u32 = alloc_size / 2 / @sizeOf(u32);603 var i: u32 = alloc_size / 2 / @sizeOf(u32);
604 while (i < alloc_size / @sizeOf(u32)) : (i += 1) {604 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));
606 }606 }
607 }607 }
608608
...@@ -611,9 +611,9 @@ test "mmap" {...@@ -611,9 +611,9 @@ test "mmap" {
611611
612test "getenv" {612test "getenv" {
613 if (builtin.os.tag == .windows) {613 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);
615 } else {615 } else {
616 expect(os.getenvZ("BOGUSDOESNOTEXISTENVVAR") == null);616 try expect(os.getenvZ("BOGUSDOESNOTEXISTENVVAR") == null);
617 }617 }
618}618}
619619
...@@ -635,17 +635,17 @@ test "fcntl" {...@@ -635,17 +635,17 @@ test "fcntl" {
635 // Note: The test assumes createFile opens the file with O_CLOEXEC635 // Note: The test assumes createFile opens the file with O_CLOEXEC
636 {636 {
637 const flags = try os.fcntl(file.handle, os.F_GETFD, 0);637 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);
639 }639 }
640 {640 {
641 _ = try os.fcntl(file.handle, os.F_SETFD, 0);641 _ = try os.fcntl(file.handle, os.F_SETFD, 0);
642 const flags = try os.fcntl(file.handle, os.F_GETFD, 0);642 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);
644 }644 }
645 {645 {
646 _ = try os.fcntl(file.handle, os.F_SETFD, os.FD_CLOEXEC);646 _ = try os.fcntl(file.handle, os.F_SETFD, os.FD_CLOEXEC);
647 const flags = try os.fcntl(file.handle, os.F_GETFD, 0);647 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);
649 }649 }
650}650}
651651
...@@ -750,12 +750,12 @@ test "sigaction" {...@@ -750,12 +750,12 @@ test "sigaction" {
750 os.sigaction(os.SIGUSR1, &sa, null);750 os.sigaction(os.SIGUSR1, &sa, null);
751 // Check that we can read it back correctly.751 // Check that we can read it back correctly.
752 os.sigaction(os.SIGUSR1, null, &old_sa);752 os.sigaction(os.SIGUSR1, null, &old_sa);
753 testing.expectEqual(S.handler, old_sa.handler.sigaction.?);753 try testing.expectEqual(S.handler, old_sa.handler.sigaction.?);
754 testing.expect((old_sa.flags & os.SA_SIGINFO) != 0);754 try testing.expect((old_sa.flags & os.SA_SIGINFO) != 0);
755 // Invoke the handler.755 // Invoke the handler.
756 try os.raise(os.SIGUSR1);756 try os.raise(os.SIGUSR1);
757 testing.expect(signal_test_failed == false);757 try testing.expect(signal_test_failed == false);
758 // Check if the handler has been correctly reset to SIG_DFL758 // Check if the handler has been correctly reset to SIG_DFL
759 os.sigaction(os.SIGUSR1, null, &old_sa);759 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);
761}761}
lib/std/os/windows.zig+3-3
...@@ -997,7 +997,7 @@ test "QueryObjectName" {...@@ -997,7 +997,7 @@ test "QueryObjectName" {
997 var result_path = try QueryObjectName(handle, &out_buffer);997 var result_path = try QueryObjectName(handle, &out_buffer);
998 const required_len_in_u16 = result_path.len + @divExact(@ptrToInt(result_path.ptr) - @ptrToInt(&out_buffer), 2) + 1;998 const required_len_in_u16 = result_path.len + @divExact(@ptrToInt(result_path.ptr) - @ptrToInt(&out_buffer), 2) + 1;
999 //insufficient size999 //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]));
1001 //exactly-sufficient size1001 //exactly-sufficient size
1002 _ = try QueryObjectName(handle, out_buffer[0..required_len_in_u16]);1002 _ = try QueryObjectName(handle, out_buffer[0..required_len_in_u16]);
1003}1003}
...@@ -1155,8 +1155,8 @@ test "GetFinalPathNameByHandle" {...@@ -1155,8 +1155,8 @@ test "GetFinalPathNameByHandle" {
11551155
1156 const required_len_in_u16 = nt_path.len + @divExact(@ptrToInt(nt_path.ptr) - @ptrToInt(&buffer), 2) + 1;1156 const required_len_in_u16 = nt_path.len + @divExact(@ptrToInt(nt_path.ptr) - @ptrToInt(&buffer), 2) + 1;
1157 //check with insufficient size1157 //check with insufficient size
1158 std.testing.expectError(error.NameTooLong, GetFinalPathNameByHandle(handle, .{ .volume_name = .Nt }, 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 std.testing.expectError(error.NameTooLong, GetFinalPathNameByHandle(handle, .{ .volume_name = .Dos }, 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
1161 //check with exactly-sufficient size1161 //check with exactly-sufficient size
1162 _ = try GetFinalPathNameByHandle(handle, .{ .volume_name = .Nt }, buffer[0..required_len_in_u16]);1162 _ = 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" {...@@ -355,7 +355,7 @@ test "PackedIntArray" {
355355
356 const PackedArray = PackedIntArray(I, int_count);356 const PackedArray = PackedIntArray(I, int_count);
357 const expected_bytes = ((bits * int_count) + 7) / 8;357 const expected_bytes = ((bits * int_count) + 7) / 8;
358 testing.expect(@sizeOf(PackedArray) == expected_bytes);358 try testing.expect(@sizeOf(PackedArray) == expected_bytes);
359359
360 var data = @as(PackedArray, undefined);360 var data = @as(PackedArray, undefined);
361361
...@@ -372,7 +372,7 @@ test "PackedIntArray" {...@@ -372,7 +372,7 @@ test "PackedIntArray" {
372 count = 0;372 count = 0;
373 while (i < data.len()) : (i += 1) {373 while (i < data.len()) : (i += 1) {
374 const val = data.get(i);374 const val = data.get(i);
375 testing.expect(val == count);375 try testing.expect(val == count);
376 if (bits > 0) count +%= 1;376 if (bits > 0) count +%= 1;
377 }377 }
378 }378 }
...@@ -429,7 +429,7 @@ test "PackedIntSlice" {...@@ -429,7 +429,7 @@ test "PackedIntSlice" {
429 count = 0;429 count = 0;
430 while (i < data.len()) : (i += 1) {430 while (i < data.len()) : (i += 1) {
431 const val = data.get(i);431 const val = data.get(i);
432 testing.expect(val == count);432 try testing.expect(val == count);
433 if (bits > 0) count +%= 1;433 if (bits > 0) count +%= 1;
434 }434 }
435 }435 }
...@@ -456,48 +456,48 @@ test "PackedIntSlice of PackedInt(Array/Slice)" {...@@ -456,48 +456,48 @@ test "PackedIntSlice of PackedInt(Array/Slice)" {
456456
457 //slice of array457 //slice of array
458 var packed_slice = packed_array.slice(2, 5);458 var packed_slice = packed_array.slice(2, 5);
459 testing.expect(packed_slice.len() == 3);459 try testing.expect(packed_slice.len() == 3);
460 const ps_bit_count = (bits * packed_slice.len()) + packed_slice.bit_offset;460 const ps_bit_count = (bits * packed_slice.len()) + packed_slice.bit_offset;
461 const ps_expected_bytes = (ps_bit_count + 7) / 8;461 const ps_expected_bytes = (ps_bit_count + 7) / 8;
462 testing.expect(packed_slice.bytes.len == ps_expected_bytes);462 try testing.expect(packed_slice.bytes.len == ps_expected_bytes);
463 testing.expect(packed_slice.get(0) == 2 % limit);463 try testing.expect(packed_slice.get(0) == 2 % limit);
464 testing.expect(packed_slice.get(1) == 3 % limit);464 try testing.expect(packed_slice.get(1) == 3 % limit);
465 testing.expect(packed_slice.get(2) == 4 % limit);465 try testing.expect(packed_slice.get(2) == 4 % limit);
466 packed_slice.set(1, 7 % limit);466 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
469 //write through slice469 //write through slice
470 testing.expect(packed_array.get(3) == 7 % limit);470 try testing.expect(packed_array.get(3) == 7 % limit);
471471
472 //slice of a slice472 //slice of a slice
473 const packed_slice_two = packed_slice.slice(0, 3);473 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);
475 const ps2_bit_count = (bits * packed_slice_two.len()) + packed_slice_two.bit_offset;475 const ps2_bit_count = (bits * packed_slice_two.len()) + packed_slice_two.bit_offset;
476 const ps2_expected_bytes = (ps2_bit_count + 7) / 8;476 const ps2_expected_bytes = (ps2_bit_count + 7) / 8;
477 testing.expect(packed_slice_two.bytes.len == ps2_expected_bytes);477 try testing.expect(packed_slice_two.bytes.len == ps2_expected_bytes);
478 testing.expect(packed_slice_two.get(1) == 7 % limit);478 try testing.expect(packed_slice_two.get(1) == 7 % limit);
479 testing.expect(packed_slice_two.get(2) == 4 % limit);479 try testing.expect(packed_slice_two.get(2) == 4 % limit);
480480
481 //size one case481 //size one case
482 const packed_slice_three = packed_slice_two.slice(1, 2);482 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);
484 const ps3_bit_count = (bits * packed_slice_three.len()) + packed_slice_three.bit_offset;484 const ps3_bit_count = (bits * packed_slice_three.len()) + packed_slice_three.bit_offset;
485 const ps3_expected_bytes = (ps3_bit_count + 7) / 8;485 const ps3_expected_bytes = (ps3_bit_count + 7) / 8;
486 testing.expect(packed_slice_three.bytes.len == ps3_expected_bytes);486 try testing.expect(packed_slice_three.bytes.len == ps3_expected_bytes);
487 testing.expect(packed_slice_three.get(0) == 7 % limit);487 try testing.expect(packed_slice_three.get(0) == 7 % limit);
488488
489 //empty slice case489 //empty slice case
490 const packed_slice_empty = packed_slice.slice(0, 0);490 const packed_slice_empty = packed_slice.slice(0, 0);
491 testing.expect(packed_slice_empty.len() == 0);491 try testing.expect(packed_slice_empty.len() == 0);
492 testing.expect(packed_slice_empty.bytes.len == 0);492 try testing.expect(packed_slice_empty.bytes.len == 0);
493493
494 //slicing at byte boundaries494 //slicing at byte boundaries
495 const packed_slice_edge = packed_array.slice(8, 16);495 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);
497 const pse_bit_count = (bits * packed_slice_edge.len()) + packed_slice_edge.bit_offset;497 const pse_bit_count = (bits * packed_slice_edge.len()) + packed_slice_edge.bit_offset;
498 const pse_expected_bytes = (pse_bit_count + 7) / 8;498 const pse_expected_bytes = (pse_bit_count + 7) / 8;
499 testing.expect(packed_slice_edge.bytes.len == pse_expected_bytes);499 try testing.expect(packed_slice_edge.bytes.len == pse_expected_bytes);
500 testing.expect(packed_slice_edge.bit_offset == 0);500 try testing.expect(packed_slice_edge.bit_offset == 0);
501 }501 }
502}502}
503503
...@@ -545,7 +545,7 @@ test "PackedInt(Array/Slice) sliceCast" {...@@ -545,7 +545,7 @@ test "PackedInt(Array/Slice) sliceCast" {
545 .Big => 0b01,545 .Big => 0b01,
546 .Little => 0b10,546 .Little => 0b10,
547 };547 };
548 testing.expect(packed_slice_cast_2.get(i) == val);548 try testing.expect(packed_slice_cast_2.get(i) == val);
549 }549 }
550 i = 0;550 i = 0;
551 while (i < packed_slice_cast_4.len()) : (i += 1) {551 while (i < packed_slice_cast_4.len()) : (i += 1) {
...@@ -553,12 +553,12 @@ test "PackedInt(Array/Slice) sliceCast" {...@@ -553,12 +553,12 @@ test "PackedInt(Array/Slice) sliceCast" {
553 .Big => 0b0101,553 .Big => 0b0101,
554 .Little => 0b1010,554 .Little => 0b1010,
555 };555 };
556 testing.expect(packed_slice_cast_4.get(i) == val);556 try testing.expect(packed_slice_cast_4.get(i) == val);
557 }557 }
558 i = 0;558 i = 0;
559 while (i < packed_slice_cast_9.len()) : (i += 1) {559 while (i < packed_slice_cast_9.len()) : (i += 1) {
560 const val = 0b010101010;560 const val = 0b010101010;
561 testing.expect(packed_slice_cast_9.get(i) == val);561 try testing.expect(packed_slice_cast_9.get(i) == val);
562 packed_slice_cast_9.set(i, 0b111000111);562 packed_slice_cast_9.set(i, 0b111000111);
563 }563 }
564 i = 0;564 i = 0;
...@@ -567,7 +567,7 @@ test "PackedInt(Array/Slice) sliceCast" {...@@ -567,7 +567,7 @@ test "PackedInt(Array/Slice) sliceCast" {
567 .Big => if (i % 2 == 0) @as(u3, 0b111) else @as(u3, 0b000),567 .Big => if (i % 2 == 0) @as(u3, 0b111) else @as(u3, 0b000),
568 .Little => if (i % 2 == 0) @as(u3, 0b111) else @as(u3, 0b000),568 .Little => if (i % 2 == 0) @as(u3, 0b111) else @as(u3, 0b000),
569 };569 };
570 testing.expect(packed_slice_cast_3.get(i) == val);570 try testing.expect(packed_slice_cast_3.get(i) == val);
571 }571 }
572}572}
573573
...@@ -577,58 +577,58 @@ test "PackedInt(Array/Slice)Endian" {...@@ -577,58 +577,58 @@ test "PackedInt(Array/Slice)Endian" {
577 {577 {
578 const PackedArrayBe = PackedIntArrayEndian(u4, .Big, 8);578 const PackedArrayBe = PackedIntArrayEndian(u4, .Big, 8);
579 var packed_array_be = PackedArrayBe.init([_]u4{ 0, 1, 2, 3, 4, 5, 6, 7 });579 var packed_array_be = PackedArrayBe.init([_]u4{ 0, 1, 2, 3, 4, 5, 6, 7 });
580 testing.expect(packed_array_be.bytes[0] == 0b00000001);580 try testing.expect(packed_array_be.bytes[0] == 0b00000001);
581 testing.expect(packed_array_be.bytes[1] == 0b00100011);581 try testing.expect(packed_array_be.bytes[1] == 0b00100011);
582582
583 var i = @as(usize, 0);583 var i = @as(usize, 0);
584 while (i < packed_array_be.len()) : (i += 1) {584 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);
586 }586 }
587587
588 var packed_slice_le = packed_array_be.sliceCastEndian(u4, .Little);588 var packed_slice_le = packed_array_be.sliceCastEndian(u4, .Little);
589 i = 0;589 i = 0;
590 while (i < packed_slice_le.len()) : (i += 1) {590 while (i < packed_slice_le.len()) : (i += 1) {
591 const val = if (i % 2 == 0) i + 1 else i - 1;591 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);
593 }593 }
594594
595 var packed_slice_le_shift = packed_array_be.slice(1, 5).sliceCastEndian(u4, .Little);595 var packed_slice_le_shift = packed_array_be.slice(1, 5).sliceCastEndian(u4, .Little);
596 i = 0;596 i = 0;
597 while (i < packed_slice_le_shift.len()) : (i += 1) {597 while (i < packed_slice_le_shift.len()) : (i += 1) {
598 const val = if (i % 2 == 0) i else i + 2;598 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);
600 }600 }
601 }601 }
602602
603 {603 {
604 const PackedArrayBe = PackedIntArrayEndian(u11, .Big, 8);604 const PackedArrayBe = PackedIntArrayEndian(u11, .Big, 8);
605 var packed_array_be = PackedArrayBe.init([_]u11{ 0, 1, 2, 3, 4, 5, 6, 7 });605 var packed_array_be = PackedArrayBe.init([_]u11{ 0, 1, 2, 3, 4, 5, 6, 7 });
606 testing.expect(packed_array_be.bytes[0] == 0b00000000);606 try testing.expect(packed_array_be.bytes[0] == 0b00000000);
607 testing.expect(packed_array_be.bytes[1] == 0b00000000);607 try testing.expect(packed_array_be.bytes[1] == 0b00000000);
608 testing.expect(packed_array_be.bytes[2] == 0b00000100);608 try testing.expect(packed_array_be.bytes[2] == 0b00000100);
609 testing.expect(packed_array_be.bytes[3] == 0b00000001);609 try testing.expect(packed_array_be.bytes[3] == 0b00000001);
610 testing.expect(packed_array_be.bytes[4] == 0b00000000);610 try testing.expect(packed_array_be.bytes[4] == 0b00000000);
611611
612 var i = @as(usize, 0);612 var i = @as(usize, 0);
613 while (i < packed_array_be.len()) : (i += 1) {613 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);
615 }615 }
616616
617 var packed_slice_le = packed_array_be.sliceCastEndian(u11, .Little);617 var packed_slice_le = packed_array_be.sliceCastEndian(u11, .Little);
618 testing.expect(packed_slice_le.get(0) == 0b00000000000);618 try testing.expect(packed_slice_le.get(0) == 0b00000000000);
619 testing.expect(packed_slice_le.get(1) == 0b00010000000);619 try testing.expect(packed_slice_le.get(1) == 0b00010000000);
620 testing.expect(packed_slice_le.get(2) == 0b00000000100);620 try testing.expect(packed_slice_le.get(2) == 0b00000000100);
621 testing.expect(packed_slice_le.get(3) == 0b00000000000);621 try testing.expect(packed_slice_le.get(3) == 0b00000000000);
622 testing.expect(packed_slice_le.get(4) == 0b00010000011);622 try testing.expect(packed_slice_le.get(4) == 0b00010000011);
623 testing.expect(packed_slice_le.get(5) == 0b00000000010);623 try testing.expect(packed_slice_le.get(5) == 0b00000000010);
624 testing.expect(packed_slice_le.get(6) == 0b10000010000);624 try testing.expect(packed_slice_le.get(6) == 0b10000010000);
625 testing.expect(packed_slice_le.get(7) == 0b00000111001);625 try testing.expect(packed_slice_le.get(7) == 0b00000111001);
626626
627 var packed_slice_le_shift = packed_array_be.slice(1, 5).sliceCastEndian(u11, .Little);627 var packed_slice_le_shift = packed_array_be.slice(1, 5).sliceCastEndian(u11, .Little);
628 testing.expect(packed_slice_le_shift.get(0) == 0b00010000000);628 try testing.expect(packed_slice_le_shift.get(0) == 0b00010000000);
629 testing.expect(packed_slice_le_shift.get(1) == 0b00000000100);629 try testing.expect(packed_slice_le_shift.get(1) == 0b00000000100);
630 testing.expect(packed_slice_le_shift.get(2) == 0b00000000000);630 try testing.expect(packed_slice_le_shift.get(2) == 0b00000000000);
631 testing.expect(packed_slice_le_shift.get(3) == 0b00010000011);631 try testing.expect(packed_slice_le_shift.get(3) == 0b00010000011);
632 }632 }
633}633}
634634
lib/std/priority_dequeue.zig+89-89
...@@ -482,12 +482,12 @@ test "std.PriorityDequeue: add and remove min" {...@@ -482,12 +482,12 @@ test "std.PriorityDequeue: add and remove min" {
482 try queue.add(25);482 try queue.add(25);
483 try queue.add(13);483 try queue.add(13);
484484
485 expectEqual(@as(u32, 7), queue.removeMin());485 try expectEqual(@as(u32, 7), queue.removeMin());
486 expectEqual(@as(u32, 12), queue.removeMin());486 try expectEqual(@as(u32, 12), queue.removeMin());
487 expectEqual(@as(u32, 13), queue.removeMin());487 try expectEqual(@as(u32, 13), queue.removeMin());
488 expectEqual(@as(u32, 23), queue.removeMin());488 try expectEqual(@as(u32, 23), queue.removeMin());
489 expectEqual(@as(u32, 25), queue.removeMin());489 try expectEqual(@as(u32, 25), queue.removeMin());
490 expectEqual(@as(u32, 54), queue.removeMin());490 try expectEqual(@as(u32, 54), queue.removeMin());
491}491}
492492
493test "std.PriorityDequeue: add and remove min structs" {493test "std.PriorityDequeue: add and remove min structs" {
...@@ -508,12 +508,12 @@ test "std.PriorityDequeue: add and remove min structs" {...@@ -508,12 +508,12 @@ test "std.PriorityDequeue: add and remove min structs" {
508 try queue.add(.{ .size = 25 });508 try queue.add(.{ .size = 25 });
509 try queue.add(.{ .size = 13 });509 try queue.add(.{ .size = 13 });
510510
511 expectEqual(@as(u32, 7), queue.removeMin().size);511 try expectEqual(@as(u32, 7), queue.removeMin().size);
512 expectEqual(@as(u32, 12), queue.removeMin().size);512 try expectEqual(@as(u32, 12), queue.removeMin().size);
513 expectEqual(@as(u32, 13), queue.removeMin().size);513 try expectEqual(@as(u32, 13), queue.removeMin().size);
514 expectEqual(@as(u32, 23), queue.removeMin().size);514 try expectEqual(@as(u32, 23), queue.removeMin().size);
515 expectEqual(@as(u32, 25), queue.removeMin().size);515 try expectEqual(@as(u32, 25), queue.removeMin().size);
516 expectEqual(@as(u32, 54), queue.removeMin().size);516 try expectEqual(@as(u32, 54), queue.removeMin().size);
517}517}
518518
519test "std.PriorityDequeue: add and remove max" {519test "std.PriorityDequeue: add and remove max" {
...@@ -527,12 +527,12 @@ test "std.PriorityDequeue: add and remove max" {...@@ -527,12 +527,12 @@ test "std.PriorityDequeue: add and remove max" {
527 try queue.add(25);527 try queue.add(25);
528 try queue.add(13);528 try queue.add(13);
529529
530 expectEqual(@as(u32, 54), queue.removeMax());530 try expectEqual(@as(u32, 54), queue.removeMax());
531 expectEqual(@as(u32, 25), queue.removeMax());531 try expectEqual(@as(u32, 25), queue.removeMax());
532 expectEqual(@as(u32, 23), queue.removeMax());532 try expectEqual(@as(u32, 23), queue.removeMax());
533 expectEqual(@as(u32, 13), queue.removeMax());533 try expectEqual(@as(u32, 13), queue.removeMax());
534 expectEqual(@as(u32, 12), queue.removeMax());534 try expectEqual(@as(u32, 12), queue.removeMax());
535 expectEqual(@as(u32, 7), queue.removeMax());535 try expectEqual(@as(u32, 7), queue.removeMax());
536}536}
537537
538test "std.PriorityDequeue: add and remove same min" {538test "std.PriorityDequeue: add and remove same min" {
...@@ -546,12 +546,12 @@ test "std.PriorityDequeue: add and remove same min" {...@@ -546,12 +546,12 @@ test "std.PriorityDequeue: add and remove same min" {
546 try queue.add(1);546 try queue.add(1);
547 try queue.add(1);547 try queue.add(1);
548548
549 expectEqual(@as(u32, 1), queue.removeMin());549 try expectEqual(@as(u32, 1), queue.removeMin());
550 expectEqual(@as(u32, 1), queue.removeMin());550 try expectEqual(@as(u32, 1), queue.removeMin());
551 expectEqual(@as(u32, 1), queue.removeMin());551 try expectEqual(@as(u32, 1), queue.removeMin());
552 expectEqual(@as(u32, 1), queue.removeMin());552 try expectEqual(@as(u32, 1), queue.removeMin());
553 expectEqual(@as(u32, 2), queue.removeMin());553 try expectEqual(@as(u32, 2), queue.removeMin());
554 expectEqual(@as(u32, 2), queue.removeMin());554 try expectEqual(@as(u32, 2), queue.removeMin());
555}555}
556556
557test "std.PriorityDequeue: add and remove same max" {557test "std.PriorityDequeue: add and remove same max" {
...@@ -565,20 +565,20 @@ test "std.PriorityDequeue: add and remove same max" {...@@ -565,20 +565,20 @@ test "std.PriorityDequeue: add and remove same max" {
565 try queue.add(1);565 try queue.add(1);
566 try queue.add(1);566 try queue.add(1);
567567
568 expectEqual(@as(u32, 2), queue.removeMax());568 try expectEqual(@as(u32, 2), queue.removeMax());
569 expectEqual(@as(u32, 2), queue.removeMax());569 try expectEqual(@as(u32, 2), queue.removeMax());
570 expectEqual(@as(u32, 1), queue.removeMax());570 try expectEqual(@as(u32, 1), queue.removeMax());
571 expectEqual(@as(u32, 1), queue.removeMax());571 try expectEqual(@as(u32, 1), queue.removeMax());
572 expectEqual(@as(u32, 1), queue.removeMax());572 try expectEqual(@as(u32, 1), queue.removeMax());
573 expectEqual(@as(u32, 1), queue.removeMax());573 try expectEqual(@as(u32, 1), queue.removeMax());
574}574}
575575
576test "std.PriorityDequeue: removeOrNull empty" {576test "std.PriorityDequeue: removeOrNull empty" {
577 var queue = PDQ.init(testing.allocator, lessThanComparison);577 var queue = PDQ.init(testing.allocator, lessThanComparison);
578 defer queue.deinit();578 defer queue.deinit();
579579
580 expect(queue.removeMinOrNull() == null);580 try expect(queue.removeMinOrNull() == null);
581 expect(queue.removeMaxOrNull() == null);581 try expect(queue.removeMaxOrNull() == null);
582}582}
583583
584test "std.PriorityDequeue: edge case 3 elements" {584test "std.PriorityDequeue: edge case 3 elements" {
...@@ -589,9 +589,9 @@ test "std.PriorityDequeue: edge case 3 elements" {...@@ -589,9 +589,9 @@ test "std.PriorityDequeue: edge case 3 elements" {
589 try queue.add(3);589 try queue.add(3);
590 try queue.add(2);590 try queue.add(2);
591591
592 expectEqual(@as(u32, 2), queue.removeMin());592 try expectEqual(@as(u32, 2), queue.removeMin());
593 expectEqual(@as(u32, 3), queue.removeMin());593 try expectEqual(@as(u32, 3), queue.removeMin());
594 expectEqual(@as(u32, 9), queue.removeMin());594 try expectEqual(@as(u32, 9), queue.removeMin());
595}595}
596596
597test "std.PriorityDequeue: edge case 3 elements max" {597test "std.PriorityDequeue: edge case 3 elements max" {
...@@ -602,37 +602,37 @@ test "std.PriorityDequeue: edge case 3 elements max" {...@@ -602,37 +602,37 @@ test "std.PriorityDequeue: edge case 3 elements max" {
602 try queue.add(3);602 try queue.add(3);
603 try queue.add(2);603 try queue.add(2);
604604
605 expectEqual(@as(u32, 9), queue.removeMax());605 try expectEqual(@as(u32, 9), queue.removeMax());
606 expectEqual(@as(u32, 3), queue.removeMax());606 try expectEqual(@as(u32, 3), queue.removeMax());
607 expectEqual(@as(u32, 2), queue.removeMax());607 try expectEqual(@as(u32, 2), queue.removeMax());
608}608}
609609
610test "std.PriorityDequeue: peekMin" {610test "std.PriorityDequeue: peekMin" {
611 var queue = PDQ.init(testing.allocator, lessThanComparison);611 var queue = PDQ.init(testing.allocator, lessThanComparison);
612 defer queue.deinit();612 defer queue.deinit();
613613
614 expect(queue.peekMin() == null);614 try expect(queue.peekMin() == null);
615615
616 try queue.add(9);616 try queue.add(9);
617 try queue.add(3);617 try queue.add(3);
618 try queue.add(2);618 try queue.add(2);
619619
620 expect(queue.peekMin().? == 2);620 try expect(queue.peekMin().? == 2);
621 expect(queue.peekMin().? == 2);621 try expect(queue.peekMin().? == 2);
622}622}
623623
624test "std.PriorityDequeue: peekMax" {624test "std.PriorityDequeue: peekMax" {
625 var queue = PDQ.init(testing.allocator, lessThanComparison);625 var queue = PDQ.init(testing.allocator, lessThanComparison);
626 defer queue.deinit();626 defer queue.deinit();
627627
628 expect(queue.peekMin() == null);628 try expect(queue.peekMin() == null);
629629
630 try queue.add(9);630 try queue.add(9);
631 try queue.add(3);631 try queue.add(3);
632 try queue.add(2);632 try queue.add(2);
633633
634 expect(queue.peekMax().? == 9);634 try expect(queue.peekMax().? == 9);
635 expect(queue.peekMax().? == 9);635 try expect(queue.peekMax().? == 9);
636}636}
637637
638test "std.PriorityDequeue: sift up with odd indices" {638test "std.PriorityDequeue: sift up with odd indices" {
...@@ -645,7 +645,7 @@ test "std.PriorityDequeue: sift up with odd indices" {...@@ -645,7 +645,7 @@ test "std.PriorityDequeue: sift up with odd indices" {
645645
646 const sorted_items = [_]u32{ 1, 2, 5, 6, 7, 7, 11, 12, 13, 14, 15, 15, 16, 21, 22, 24, 24, 25 };646 const sorted_items = [_]u32{ 1, 2, 5, 6, 7, 7, 11, 12, 13, 14, 15, 15, 16, 21, 22, 24, 24, 25 };
647 for (sorted_items) |e| {647 for (sorted_items) |e| {
648 expectEqual(e, queue.removeMin());648 try expectEqual(e, queue.removeMin());
649 }649 }
650}650}
651651
...@@ -659,7 +659,7 @@ test "std.PriorityDequeue: sift up with odd indices" {...@@ -659,7 +659,7 @@ test "std.PriorityDequeue: sift up with odd indices" {
659659
660 const sorted_items = [_]u32{ 25, 24, 24, 22, 21, 16, 15, 15, 14, 13, 12, 11, 7, 7, 6, 5, 2, 1 };660 const sorted_items = [_]u32{ 25, 24, 24, 22, 21, 16, 15, 15, 14, 13, 12, 11, 7, 7, 6, 5, 2, 1 };
661 for (sorted_items) |e| {661 for (sorted_items) |e| {
662 expectEqual(e, queue.removeMax());662 try expectEqual(e, queue.removeMax());
663 }663 }
664}664}
665665
...@@ -671,7 +671,7 @@ test "std.PriorityDequeue: addSlice min" {...@@ -671,7 +671,7 @@ test "std.PriorityDequeue: addSlice min" {
671671
672 const sorted_items = [_]u32{ 1, 2, 5, 6, 7, 7, 11, 12, 13, 14, 15, 15, 16, 21, 22, 24, 24, 25 };672 const sorted_items = [_]u32{ 1, 2, 5, 6, 7, 7, 11, 12, 13, 14, 15, 15, 16, 21, 22, 24, 24, 25 };
673 for (sorted_items) |e| {673 for (sorted_items) |e| {
674 expectEqual(e, queue.removeMin());674 try expectEqual(e, queue.removeMin());
675 }675 }
676}676}
677677
...@@ -683,7 +683,7 @@ test "std.PriorityDequeue: addSlice max" {...@@ -683,7 +683,7 @@ test "std.PriorityDequeue: addSlice max" {
683683
684 const sorted_items = [_]u32{ 25, 24, 24, 22, 21, 16, 15, 15, 14, 13, 12, 11, 7, 7, 6, 5, 2, 1 };684 const sorted_items = [_]u32{ 25, 24, 24, 22, 21, 16, 15, 15, 14, 13, 12, 11, 7, 7, 6, 5, 2, 1 };
685 for (sorted_items) |e| {685 for (sorted_items) |e| {
686 expectEqual(e, queue.removeMax());686 try expectEqual(e, queue.removeMax());
687 }687 }
688}688}
689689
...@@ -692,8 +692,8 @@ test "std.PriorityDequeue: fromOwnedSlice trivial case 0" {...@@ -692,8 +692,8 @@ test "std.PriorityDequeue: fromOwnedSlice trivial case 0" {
692 const queue_items = try testing.allocator.dupe(u32, &items);692 const queue_items = try testing.allocator.dupe(u32, &items);
693 var queue = PDQ.fromOwnedSlice(testing.allocator, lessThanComparison, queue_items[0..]);693 var queue = PDQ.fromOwnedSlice(testing.allocator, lessThanComparison, queue_items[0..]);
694 defer queue.deinit();694 defer queue.deinit();
695 expectEqual(@as(usize, 0), queue.len);695 try expectEqual(@as(usize, 0), queue.len);
696 expect(queue.removeMinOrNull() == null);696 try expect(queue.removeMinOrNull() == null);
697}697}
698698
699test "std.PriorityDequeue: fromOwnedSlice trivial case 1" {699test "std.PriorityDequeue: fromOwnedSlice trivial case 1" {
...@@ -702,9 +702,9 @@ test "std.PriorityDequeue: fromOwnedSlice trivial case 1" {...@@ -702,9 +702,9 @@ test "std.PriorityDequeue: fromOwnedSlice trivial case 1" {
702 var queue = PDQ.fromOwnedSlice(testing.allocator, lessThanComparison, queue_items[0..]);702 var queue = PDQ.fromOwnedSlice(testing.allocator, lessThanComparison, queue_items[0..]);
703 defer queue.deinit();703 defer queue.deinit();
704704
705 expectEqual(@as(usize, 1), queue.len);705 try expectEqual(@as(usize, 1), queue.len);
706 expectEqual(items[0], queue.removeMin());706 try expectEqual(items[0], queue.removeMin());
707 expect(queue.removeMinOrNull() == null);707 try expect(queue.removeMinOrNull() == null);
708}708}
709709
710test "std.PriorityDequeue: fromOwnedSlice" {710test "std.PriorityDequeue: fromOwnedSlice" {
...@@ -715,7 +715,7 @@ test "std.PriorityDequeue: fromOwnedSlice" {...@@ -715,7 +715,7 @@ test "std.PriorityDequeue: fromOwnedSlice" {
715715
716 const sorted_items = [_]u32{ 1, 2, 5, 6, 7, 7, 11, 12, 13, 14, 15, 15, 16, 21, 22, 24, 24, 25 };716 const sorted_items = [_]u32{ 1, 2, 5, 6, 7, 7, 11, 12, 13, 14, 15, 15, 16, 21, 22, 24, 24, 25 };
717 for (sorted_items) |e| {717 for (sorted_items) |e| {
718 expectEqual(e, queue.removeMin());718 try expectEqual(e, queue.removeMin());
719 }719 }
720}720}
721721
...@@ -729,9 +729,9 @@ test "std.PriorityDequeue: update min queue" {...@@ -729,9 +729,9 @@ test "std.PriorityDequeue: update min queue" {
729 try queue.update(55, 5);729 try queue.update(55, 5);
730 try queue.update(44, 4);730 try queue.update(44, 4);
731 try queue.update(11, 1);731 try queue.update(11, 1);
732 expectEqual(@as(u32, 1), queue.removeMin());732 try expectEqual(@as(u32, 1), queue.removeMin());
733 expectEqual(@as(u32, 4), queue.removeMin());733 try expectEqual(@as(u32, 4), queue.removeMin());
734 expectEqual(@as(u32, 5), queue.removeMin());734 try expectEqual(@as(u32, 5), queue.removeMin());
735}735}
736736
737test "std.PriorityDequeue: update same min queue" {737test "std.PriorityDequeue: update same min queue" {
...@@ -744,10 +744,10 @@ test "std.PriorityDequeue: update same min queue" {...@@ -744,10 +744,10 @@ test "std.PriorityDequeue: update same min queue" {
744 try queue.add(2);744 try queue.add(2);
745 try queue.update(1, 5);745 try queue.update(1, 5);
746 try queue.update(2, 4);746 try queue.update(2, 4);
747 expectEqual(@as(u32, 1), queue.removeMin());747 try expectEqual(@as(u32, 1), queue.removeMin());
748 expectEqual(@as(u32, 2), queue.removeMin());748 try expectEqual(@as(u32, 2), queue.removeMin());
749 expectEqual(@as(u32, 4), queue.removeMin());749 try expectEqual(@as(u32, 4), queue.removeMin());
750 expectEqual(@as(u32, 5), queue.removeMin());750 try expectEqual(@as(u32, 5), queue.removeMin());
751}751}
752752
753test "std.PriorityDequeue: update max queue" {753test "std.PriorityDequeue: update max queue" {
...@@ -761,9 +761,9 @@ test "std.PriorityDequeue: update max queue" {...@@ -761,9 +761,9 @@ test "std.PriorityDequeue: update max queue" {
761 try queue.update(44, 1);761 try queue.update(44, 1);
762 try queue.update(11, 4);762 try queue.update(11, 4);
763763
764 expectEqual(@as(u32, 5), queue.removeMax());764 try expectEqual(@as(u32, 5), queue.removeMax());
765 expectEqual(@as(u32, 4), queue.removeMax());765 try expectEqual(@as(u32, 4), queue.removeMax());
766 expectEqual(@as(u32, 1), queue.removeMax());766 try expectEqual(@as(u32, 1), queue.removeMax());
767}767}
768768
769test "std.PriorityDequeue: update same max queue" {769test "std.PriorityDequeue: update same max queue" {
...@@ -776,10 +776,10 @@ test "std.PriorityDequeue: update same max queue" {...@@ -776,10 +776,10 @@ test "std.PriorityDequeue: update same max queue" {
776 try queue.add(2);776 try queue.add(2);
777 try queue.update(1, 5);777 try queue.update(1, 5);
778 try queue.update(2, 4);778 try queue.update(2, 4);
779 expectEqual(@as(u32, 5), queue.removeMax());779 try expectEqual(@as(u32, 5), queue.removeMax());
780 expectEqual(@as(u32, 4), queue.removeMax());780 try expectEqual(@as(u32, 4), queue.removeMax());
781 expectEqual(@as(u32, 2), queue.removeMax());781 try expectEqual(@as(u32, 2), queue.removeMax());
782 expectEqual(@as(u32, 1), queue.removeMax());782 try expectEqual(@as(u32, 1), queue.removeMax());
783}783}
784784
785test "std.PriorityDequeue: iterator" {785test "std.PriorityDequeue: iterator" {
...@@ -801,7 +801,7 @@ test "std.PriorityDequeue: iterator" {...@@ -801,7 +801,7 @@ test "std.PriorityDequeue: iterator" {
801 _ = map.remove(e);801 _ = map.remove(e);
802 }802 }
803803
804 expectEqual(@as(usize, 0), map.count());804 try expectEqual(@as(usize, 0), map.count());
805}805}
806806
807test "std.PriorityDequeue: remove at index" {807test "std.PriorityDequeue: remove at index" {
...@@ -821,10 +821,10 @@ test "std.PriorityDequeue: remove at index" {...@@ -821,10 +821,10 @@ test "std.PriorityDequeue: remove at index" {
821 idx += 1;821 idx += 1;
822 } else unreachable;822 } else unreachable;
823823
824 expectEqual(queue.removeIndex(two_idx), 2);824 try expectEqual(queue.removeIndex(two_idx), 2);
825 expectEqual(queue.removeMin(), 1);825 try expectEqual(queue.removeMin(), 1);
826 expectEqual(queue.removeMin(), 3);826 try expectEqual(queue.removeMin(), 3);
827 expectEqual(queue.removeMinOrNull(), null);827 try expectEqual(queue.removeMinOrNull(), null);
828}828}
829829
830test "std.PriorityDequeue: iterator while empty" {830test "std.PriorityDequeue: iterator while empty" {
...@@ -833,7 +833,7 @@ test "std.PriorityDequeue: iterator while empty" {...@@ -833,7 +833,7 @@ test "std.PriorityDequeue: iterator while empty" {
833833
834 var it = queue.iterator();834 var it = queue.iterator();
835835
836 expectEqual(it.next(), null);836 try expectEqual(it.next(), null);
837}837}
838838
839test "std.PriorityDequeue: shrinkRetainingCapacity and shrinkAndFree" {839test "std.PriorityDequeue: shrinkRetainingCapacity and shrinkAndFree" {
...@@ -841,26 +841,26 @@ test "std.PriorityDequeue: shrinkRetainingCapacity and shrinkAndFree" {...@@ -841,26 +841,26 @@ test "std.PriorityDequeue: shrinkRetainingCapacity and shrinkAndFree" {
841 defer queue.deinit();841 defer queue.deinit();
842842
843 try queue.ensureCapacity(4);843 try queue.ensureCapacity(4);
844 expect(queue.capacity() >= 4);844 try expect(queue.capacity() >= 4);
845845
846 try queue.add(1);846 try queue.add(1);
847 try queue.add(2);847 try queue.add(2);
848 try queue.add(3);848 try queue.add(3);
849 expect(queue.capacity() >= 4);849 try expect(queue.capacity() >= 4);
850 expectEqual(@as(usize, 3), queue.len);850 try expectEqual(@as(usize, 3), queue.len);
851851
852 queue.shrinkRetainingCapacity(3);852 queue.shrinkRetainingCapacity(3);
853 expect(queue.capacity() >= 4);853 try expect(queue.capacity() >= 4);
854 expectEqual(@as(usize, 3), queue.len);854 try expectEqual(@as(usize, 3), queue.len);
855855
856 queue.shrinkAndFree(3);856 queue.shrinkAndFree(3);
857 expectEqual(@as(usize, 3), queue.capacity());857 try expectEqual(@as(usize, 3), queue.capacity());
858 expectEqual(@as(usize, 3), queue.len);858 try expectEqual(@as(usize, 3), queue.len);
859859
860 expectEqual(@as(u32, 3), queue.removeMax());860 try expectEqual(@as(u32, 3), queue.removeMax());
861 expectEqual(@as(u32, 2), queue.removeMax());861 try expectEqual(@as(u32, 2), queue.removeMax());
862 expectEqual(@as(u32, 1), queue.removeMax());862 try expectEqual(@as(u32, 1), queue.removeMax());
863 expect(queue.removeMaxOrNull() == null);863 try expect(queue.removeMaxOrNull() == null);
864}864}
865865
866test "std.PriorityDequeue: fuzz testing min" {866test "std.PriorityDequeue: fuzz testing min" {
...@@ -885,7 +885,7 @@ fn fuzzTestMin(rng: *std.rand.Random, comptime queue_size: usize) !void {...@@ -885,7 +885,7 @@ fn fuzzTestMin(rng: *std.rand.Random, comptime queue_size: usize) !void {
885 var last_removed: ?u32 = null;885 var last_removed: ?u32 = null;
886 while (queue.removeMinOrNull()) |next| {886 while (queue.removeMinOrNull()) |next| {
887 if (last_removed) |last| {887 if (last_removed) |last| {
888 expect(last <= next);888 try expect(last <= next);
889 }889 }
890 last_removed = next;890 last_removed = next;
891 }891 }
...@@ -913,7 +913,7 @@ fn fuzzTestMax(rng: *std.rand.Random, queue_size: usize) !void {...@@ -913,7 +913,7 @@ fn fuzzTestMax(rng: *std.rand.Random, queue_size: usize) !void {
913 var last_removed: ?u32 = null;913 var last_removed: ?u32 = null;
914 while (queue.removeMaxOrNull()) |next| {914 while (queue.removeMaxOrNull()) |next| {
915 if (last_removed) |last| {915 if (last_removed) |last| {
916 expect(last >= next);916 try expect(last >= next);
917 }917 }
918 last_removed = next;918 last_removed = next;
919 }919 }
...@@ -945,13 +945,13 @@ fn fuzzTestMinMax(rng: *std.rand.Random, queue_size: usize) !void {...@@ -945,13 +945,13 @@ fn fuzzTestMinMax(rng: *std.rand.Random, queue_size: usize) !void {
945 if (i % 2 == 0) {945 if (i % 2 == 0) {
946 const next = queue.removeMin();946 const next = queue.removeMin();
947 if (last_min) |last| {947 if (last_min) |last| {
948 expect(last <= next);948 try expect(last <= next);
949 }949 }
950 last_min = next;950 last_min = next;
951 } else {951 } else {
952 const next = queue.removeMax();952 const next = queue.removeMax();
953 if (last_max) |last| {953 if (last_max) |last| {
954 expect(last >= next);954 try expect(last >= next);
955 }955 }
956 last_max = next;956 last_max = next;
957 }957 }
lib/std/priority_queue.zig+70-70
...@@ -290,12 +290,12 @@ test "std.PriorityQueue: add and remove min heap" {...@@ -290,12 +290,12 @@ test "std.PriorityQueue: add and remove min heap" {
290 try queue.add(23);290 try queue.add(23);
291 try queue.add(25);291 try queue.add(25);
292 try queue.add(13);292 try queue.add(13);
293 expectEqual(@as(u32, 7), queue.remove());293 try expectEqual(@as(u32, 7), queue.remove());
294 expectEqual(@as(u32, 12), queue.remove());294 try expectEqual(@as(u32, 12), queue.remove());
295 expectEqual(@as(u32, 13), queue.remove());295 try expectEqual(@as(u32, 13), queue.remove());
296 expectEqual(@as(u32, 23), queue.remove());296 try expectEqual(@as(u32, 23), queue.remove());
297 expectEqual(@as(u32, 25), queue.remove());297 try expectEqual(@as(u32, 25), queue.remove());
298 expectEqual(@as(u32, 54), queue.remove());298 try expectEqual(@as(u32, 54), queue.remove());
299}299}
300300
301test "std.PriorityQueue: add and remove same min heap" {301test "std.PriorityQueue: add and remove same min heap" {
...@@ -308,19 +308,19 @@ test "std.PriorityQueue: add and remove same min heap" {...@@ -308,19 +308,19 @@ test "std.PriorityQueue: add and remove same min heap" {
308 try queue.add(2);308 try queue.add(2);
309 try queue.add(1);309 try queue.add(1);
310 try queue.add(1);310 try queue.add(1);
311 expectEqual(@as(u32, 1), queue.remove());311 try expectEqual(@as(u32, 1), queue.remove());
312 expectEqual(@as(u32, 1), queue.remove());312 try expectEqual(@as(u32, 1), queue.remove());
313 expectEqual(@as(u32, 1), queue.remove());313 try expectEqual(@as(u32, 1), queue.remove());
314 expectEqual(@as(u32, 1), queue.remove());314 try expectEqual(@as(u32, 1), queue.remove());
315 expectEqual(@as(u32, 2), queue.remove());315 try expectEqual(@as(u32, 2), queue.remove());
316 expectEqual(@as(u32, 2), queue.remove());316 try expectEqual(@as(u32, 2), queue.remove());
317}317}
318318
319test "std.PriorityQueue: removeOrNull on empty" {319test "std.PriorityQueue: removeOrNull on empty" {
320 var queue = PQ.init(testing.allocator, lessThan);320 var queue = PQ.init(testing.allocator, lessThan);
321 defer queue.deinit();321 defer queue.deinit();
322322
323 expect(queue.removeOrNull() == null);323 try expect(queue.removeOrNull() == null);
324}324}
325325
326test "std.PriorityQueue: edge case 3 elements" {326test "std.PriorityQueue: edge case 3 elements" {
...@@ -330,21 +330,21 @@ test "std.PriorityQueue: edge case 3 elements" {...@@ -330,21 +330,21 @@ test "std.PriorityQueue: edge case 3 elements" {
330 try queue.add(9);330 try queue.add(9);
331 try queue.add(3);331 try queue.add(3);
332 try queue.add(2);332 try queue.add(2);
333 expectEqual(@as(u32, 2), queue.remove());333 try expectEqual(@as(u32, 2), queue.remove());
334 expectEqual(@as(u32, 3), queue.remove());334 try expectEqual(@as(u32, 3), queue.remove());
335 expectEqual(@as(u32, 9), queue.remove());335 try expectEqual(@as(u32, 9), queue.remove());
336}336}
337337
338test "std.PriorityQueue: peek" {338test "std.PriorityQueue: peek" {
339 var queue = PQ.init(testing.allocator, lessThan);339 var queue = PQ.init(testing.allocator, lessThan);
340 defer queue.deinit();340 defer queue.deinit();
341341
342 expect(queue.peek() == null);342 try expect(queue.peek() == null);
343 try queue.add(9);343 try queue.add(9);
344 try queue.add(3);344 try queue.add(3);
345 try queue.add(2);345 try queue.add(2);
346 expectEqual(@as(u32, 2), queue.peek().?);346 try expectEqual(@as(u32, 2), queue.peek().?);
347 expectEqual(@as(u32, 2), queue.peek().?);347 try expectEqual(@as(u32, 2), queue.peek().?);
348}348}
349349
350test "std.PriorityQueue: sift up with odd indices" {350test "std.PriorityQueue: sift up with odd indices" {
...@@ -357,7 +357,7 @@ test "std.PriorityQueue: sift up with odd indices" {...@@ -357,7 +357,7 @@ test "std.PriorityQueue: sift up with odd indices" {
357357
358 const sorted_items = [_]u32{ 1, 2, 5, 6, 7, 7, 11, 12, 13, 14, 15, 15, 16, 21, 22, 24, 24, 25 };358 const sorted_items = [_]u32{ 1, 2, 5, 6, 7, 7, 11, 12, 13, 14, 15, 15, 16, 21, 22, 24, 24, 25 };
359 for (sorted_items) |e| {359 for (sorted_items) |e| {
360 expectEqual(e, queue.remove());360 try expectEqual(e, queue.remove());
361 }361 }
362}362}
363363
...@@ -369,7 +369,7 @@ test "std.PriorityQueue: addSlice" {...@@ -369,7 +369,7 @@ test "std.PriorityQueue: addSlice" {
369369
370 const sorted_items = [_]u32{ 1, 2, 5, 6, 7, 7, 11, 12, 13, 14, 15, 15, 16, 21, 22, 24, 24, 25 };370 const sorted_items = [_]u32{ 1, 2, 5, 6, 7, 7, 11, 12, 13, 14, 15, 15, 16, 21, 22, 24, 24, 25 };
371 for (sorted_items) |e| {371 for (sorted_items) |e| {
372 expectEqual(e, queue.remove());372 try expectEqual(e, queue.remove());
373 }373 }
374}374}
375375
...@@ -378,8 +378,8 @@ test "std.PriorityQueue: fromOwnedSlice trivial case 0" {...@@ -378,8 +378,8 @@ test "std.PriorityQueue: fromOwnedSlice trivial case 0" {
378 const queue_items = try testing.allocator.dupe(u32, &items);378 const queue_items = try testing.allocator.dupe(u32, &items);
379 var queue = PQ.fromOwnedSlice(testing.allocator, lessThan, queue_items[0..]);379 var queue = PQ.fromOwnedSlice(testing.allocator, lessThan, queue_items[0..]);
380 defer queue.deinit();380 defer queue.deinit();
381 expectEqual(@as(usize, 0), queue.len);381 try expectEqual(@as(usize, 0), queue.len);
382 expect(queue.removeOrNull() == null);382 try expect(queue.removeOrNull() == null);
383}383}
384384
385test "std.PriorityQueue: fromOwnedSlice trivial case 1" {385test "std.PriorityQueue: fromOwnedSlice trivial case 1" {
...@@ -388,9 +388,9 @@ test "std.PriorityQueue: fromOwnedSlice trivial case 1" {...@@ -388,9 +388,9 @@ test "std.PriorityQueue: fromOwnedSlice trivial case 1" {
388 var queue = PQ.fromOwnedSlice(testing.allocator, lessThan, queue_items[0..]);388 var queue = PQ.fromOwnedSlice(testing.allocator, lessThan, queue_items[0..]);
389 defer queue.deinit();389 defer queue.deinit();
390390
391 expectEqual(@as(usize, 1), queue.len);391 try expectEqual(@as(usize, 1), queue.len);
392 expectEqual(items[0], queue.remove());392 try expectEqual(items[0], queue.remove());
393 expect(queue.removeOrNull() == null);393 try expect(queue.removeOrNull() == null);
394}394}
395395
396test "std.PriorityQueue: fromOwnedSlice" {396test "std.PriorityQueue: fromOwnedSlice" {
...@@ -401,7 +401,7 @@ test "std.PriorityQueue: fromOwnedSlice" {...@@ -401,7 +401,7 @@ test "std.PriorityQueue: fromOwnedSlice" {
401401
402 const sorted_items = [_]u32{ 1, 2, 5, 6, 7, 7, 11, 12, 13, 14, 15, 15, 16, 21, 22, 24, 24, 25 };402 const sorted_items = [_]u32{ 1, 2, 5, 6, 7, 7, 11, 12, 13, 14, 15, 15, 16, 21, 22, 24, 24, 25 };
403 for (sorted_items) |e| {403 for (sorted_items) |e| {
404 expectEqual(e, queue.remove());404 try expectEqual(e, queue.remove());
405 }405 }
406}406}
407407
...@@ -415,12 +415,12 @@ test "std.PriorityQueue: add and remove max heap" {...@@ -415,12 +415,12 @@ test "std.PriorityQueue: add and remove max heap" {
415 try queue.add(23);415 try queue.add(23);
416 try queue.add(25);416 try queue.add(25);
417 try queue.add(13);417 try queue.add(13);
418 expectEqual(@as(u32, 54), queue.remove());418 try expectEqual(@as(u32, 54), queue.remove());
419 expectEqual(@as(u32, 25), queue.remove());419 try expectEqual(@as(u32, 25), queue.remove());
420 expectEqual(@as(u32, 23), queue.remove());420 try expectEqual(@as(u32, 23), queue.remove());
421 expectEqual(@as(u32, 13), queue.remove());421 try expectEqual(@as(u32, 13), queue.remove());
422 expectEqual(@as(u32, 12), queue.remove());422 try expectEqual(@as(u32, 12), queue.remove());
423 expectEqual(@as(u32, 7), queue.remove());423 try expectEqual(@as(u32, 7), queue.remove());
424}424}
425425
426test "std.PriorityQueue: add and remove same max heap" {426test "std.PriorityQueue: add and remove same max heap" {
...@@ -433,12 +433,12 @@ test "std.PriorityQueue: add and remove same max heap" {...@@ -433,12 +433,12 @@ test "std.PriorityQueue: add and remove same max heap" {
433 try queue.add(2);433 try queue.add(2);
434 try queue.add(1);434 try queue.add(1);
435 try queue.add(1);435 try queue.add(1);
436 expectEqual(@as(u32, 2), queue.remove());436 try expectEqual(@as(u32, 2), queue.remove());
437 expectEqual(@as(u32, 2), queue.remove());437 try expectEqual(@as(u32, 2), queue.remove());
438 expectEqual(@as(u32, 1), queue.remove());438 try expectEqual(@as(u32, 1), queue.remove());
439 expectEqual(@as(u32, 1), queue.remove());439 try expectEqual(@as(u32, 1), queue.remove());
440 expectEqual(@as(u32, 1), queue.remove());440 try expectEqual(@as(u32, 1), queue.remove());
441 expectEqual(@as(u32, 1), queue.remove());441 try expectEqual(@as(u32, 1), queue.remove());
442}442}
443443
444test "std.PriorityQueue: iterator" {444test "std.PriorityQueue: iterator" {
...@@ -460,7 +460,7 @@ test "std.PriorityQueue: iterator" {...@@ -460,7 +460,7 @@ test "std.PriorityQueue: iterator" {
460 _ = map.remove(e);460 _ = map.remove(e);
461 }461 }
462462
463 expectEqual(@as(usize, 0), map.count());463 try expectEqual(@as(usize, 0), map.count());
464}464}
465465
466test "std.PriorityQueue: remove at index" {466test "std.PriorityQueue: remove at index" {
...@@ -480,10 +480,10 @@ test "std.PriorityQueue: remove at index" {...@@ -480,10 +480,10 @@ test "std.PriorityQueue: remove at index" {
480 idx += 1;480 idx += 1;
481 } else unreachable;481 } else unreachable;
482482
483 expectEqual(queue.removeIndex(two_idx), 2);483 try expectEqual(queue.removeIndex(two_idx), 2);
484 expectEqual(queue.remove(), 1);484 try expectEqual(queue.remove(), 1);
485 expectEqual(queue.remove(), 3);485 try expectEqual(queue.remove(), 3);
486 expectEqual(queue.removeOrNull(), null);486 try expectEqual(queue.removeOrNull(), null);
487}487}
488488
489test "std.PriorityQueue: iterator while empty" {489test "std.PriorityQueue: iterator while empty" {
...@@ -492,7 +492,7 @@ test "std.PriorityQueue: iterator while empty" {...@@ -492,7 +492,7 @@ test "std.PriorityQueue: iterator while empty" {
492492
493 var it = queue.iterator();493 var it = queue.iterator();
494494
495 expectEqual(it.next(), null);495 try expectEqual(it.next(), null);
496}496}
497497
498test "std.PriorityQueue: shrinkRetainingCapacity and shrinkAndFree" {498test "std.PriorityQueue: shrinkRetainingCapacity and shrinkAndFree" {
...@@ -500,26 +500,26 @@ test "std.PriorityQueue: shrinkRetainingCapacity and shrinkAndFree" {...@@ -500,26 +500,26 @@ test "std.PriorityQueue: shrinkRetainingCapacity and shrinkAndFree" {
500 defer queue.deinit();500 defer queue.deinit();
501501
502 try queue.ensureCapacity(4);502 try queue.ensureCapacity(4);
503 expect(queue.capacity() >= 4);503 try expect(queue.capacity() >= 4);
504504
505 try queue.add(1);505 try queue.add(1);
506 try queue.add(2);506 try queue.add(2);
507 try queue.add(3);507 try queue.add(3);
508 expect(queue.capacity() >= 4);508 try expect(queue.capacity() >= 4);
509 expectEqual(@as(usize, 3), queue.len);509 try expectEqual(@as(usize, 3), queue.len);
510510
511 queue.shrinkRetainingCapacity(3);511 queue.shrinkRetainingCapacity(3);
512 expect(queue.capacity() >= 4);512 try expect(queue.capacity() >= 4);
513 expectEqual(@as(usize, 3), queue.len);513 try expectEqual(@as(usize, 3), queue.len);
514514
515 queue.shrinkAndFree(3);515 queue.shrinkAndFree(3);
516 expectEqual(@as(usize, 3), queue.capacity());516 try expectEqual(@as(usize, 3), queue.capacity());
517 expectEqual(@as(usize, 3), queue.len);517 try expectEqual(@as(usize, 3), queue.len);
518518
519 expectEqual(@as(u32, 1), queue.remove());519 try expectEqual(@as(u32, 1), queue.remove());
520 expectEqual(@as(u32, 2), queue.remove());520 try expectEqual(@as(u32, 2), queue.remove());
521 expectEqual(@as(u32, 3), queue.remove());521 try expectEqual(@as(u32, 3), queue.remove());
522 expect(queue.removeOrNull() == null);522 try expect(queue.removeOrNull() == null);
523}523}
524524
525test "std.PriorityQueue: update min heap" {525test "std.PriorityQueue: update min heap" {
...@@ -532,9 +532,9 @@ test "std.PriorityQueue: update min heap" {...@@ -532,9 +532,9 @@ test "std.PriorityQueue: update min heap" {
532 try queue.update(55, 5);532 try queue.update(55, 5);
533 try queue.update(44, 4);533 try queue.update(44, 4);
534 try queue.update(11, 1);534 try queue.update(11, 1);
535 expectEqual(@as(u32, 1), queue.remove());535 try expectEqual(@as(u32, 1), queue.remove());
536 expectEqual(@as(u32, 4), queue.remove());536 try expectEqual(@as(u32, 4), queue.remove());
537 expectEqual(@as(u32, 5), queue.remove());537 try expectEqual(@as(u32, 5), queue.remove());
538}538}
539539
540test "std.PriorityQueue: update same min heap" {540test "std.PriorityQueue: update same min heap" {
...@@ -547,10 +547,10 @@ test "std.PriorityQueue: update same min heap" {...@@ -547,10 +547,10 @@ test "std.PriorityQueue: update same min heap" {
547 try queue.add(2);547 try queue.add(2);
548 try queue.update(1, 5);548 try queue.update(1, 5);
549 try queue.update(2, 4);549 try queue.update(2, 4);
550 expectEqual(@as(u32, 1), queue.remove());550 try expectEqual(@as(u32, 1), queue.remove());
551 expectEqual(@as(u32, 2), queue.remove());551 try expectEqual(@as(u32, 2), queue.remove());
552 expectEqual(@as(u32, 4), queue.remove());552 try expectEqual(@as(u32, 4), queue.remove());
553 expectEqual(@as(u32, 5), queue.remove());553 try expectEqual(@as(u32, 5), queue.remove());
554}554}
555555
556test "std.PriorityQueue: update max heap" {556test "std.PriorityQueue: update max heap" {
...@@ -563,9 +563,9 @@ test "std.PriorityQueue: update max heap" {...@@ -563,9 +563,9 @@ test "std.PriorityQueue: update max heap" {
563 try queue.update(55, 5);563 try queue.update(55, 5);
564 try queue.update(44, 1);564 try queue.update(44, 1);
565 try queue.update(11, 4);565 try queue.update(11, 4);
566 expectEqual(@as(u32, 5), queue.remove());566 try expectEqual(@as(u32, 5), queue.remove());
567 expectEqual(@as(u32, 4), queue.remove());567 try expectEqual(@as(u32, 4), queue.remove());
568 expectEqual(@as(u32, 1), queue.remove());568 try expectEqual(@as(u32, 1), queue.remove());
569}569}
570570
571test "std.PriorityQueue: update same max heap" {571test "std.PriorityQueue: update same max heap" {
...@@ -578,8 +578,8 @@ test "std.PriorityQueue: update same max heap" {...@@ -578,8 +578,8 @@ test "std.PriorityQueue: update same max heap" {
578 try queue.add(2);578 try queue.add(2);
579 try queue.update(1, 5);579 try queue.update(1, 5);
580 try queue.update(2, 4);580 try queue.update(2, 4);
581 expectEqual(@as(u32, 5), queue.remove());581 try expectEqual(@as(u32, 5), queue.remove());
582 expectEqual(@as(u32, 4), queue.remove());582 try expectEqual(@as(u32, 4), queue.remove());
583 expectEqual(@as(u32, 2), queue.remove());583 try expectEqual(@as(u32, 2), queue.remove());
584 expectEqual(@as(u32, 1), queue.remove());584 try expectEqual(@as(u32, 1), queue.remove());
585}585}
lib/std/process.zig+16-16
...@@ -181,7 +181,7 @@ pub fn getEnvVarOwned(allocator: *mem.Allocator, key: []const u8) GetEnvVarOwned...@@ -181,7 +181,7 @@ pub fn getEnvVarOwned(allocator: *mem.Allocator, key: []const u8) GetEnvVarOwned
181181
182test "os.getEnvVarOwned" {182test "os.getEnvVarOwned" {
183 var ga = std.testing.allocator;183 var ga = std.testing.allocator;
184 testing.expectError(error.EnvironmentVariableNotFound, getEnvVarOwned(ga, "BADENV"));184 try testing.expectError(error.EnvironmentVariableNotFound, getEnvVarOwned(ga, "BADENV"));
185}185}
186186
187pub const ArgIteratorPosix = struct {187pub const ArgIteratorPosix = struct {
...@@ -516,10 +516,10 @@ test "args iterator" {...@@ -516,10 +516,10 @@ test "args iterator" {
516 };516 };
517 const given_suffix = std.fs.path.basename(prog_name);517 const given_suffix = std.fs.path.basename(prog_name);
518518
519 testing.expect(mem.eql(u8, expected_suffix, given_suffix));519 try testing.expect(mem.eql(u8, expected_suffix, given_suffix));
520 testing.expect(it.skip()); // Skip over zig_exe_path, passed to the test runner520 try testing.expect(it.skip()); // Skip over zig_exe_path, passed to the test runner
521 testing.expect(it.next(ga) == null);521 try testing.expect(it.next(ga) == null);
522 testing.expect(!it.skip());522 try testing.expect(!it.skip());
523}523}
524524
525/// Caller must call argsFree on result.525/// Caller must call argsFree on result.
...@@ -575,14 +575,14 @@ pub fn argsFree(allocator: *mem.Allocator, args_alloc: []const [:0]u8) void {...@@ -575,14 +575,14 @@ pub fn argsFree(allocator: *mem.Allocator, args_alloc: []const [:0]u8) void {
575575
576test "windows arg parsing" {576test "windows arg parsing" {
577 const utf16Literal = std.unicode.utf8ToUtf16LeStringLiteral;577 const utf16Literal = std.unicode.utf8ToUtf16LeStringLiteral;
578 testWindowsCmdLine(utf16Literal("a b\tc d"), &[_][]const u8{ "a", "b", "c", "d" });578 try testWindowsCmdLine(utf16Literal("a b\tc d"), &[_][]const u8{ "a", "b", "c", "d" });
579 testWindowsCmdLine(utf16Literal("\"abc\" d e"), &[_][]const u8{ "abc", "d", "e" });579 try 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" });580 try 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" });581 try 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" });582 try 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" });583 try testWindowsCmdLine(utf16Literal("a b\tc \"d f"), &[_][]const u8{ "a", "b", "c", "d f" });
584584
585 testWindowsCmdLine(utf16Literal("\".\\..\\zig-cache\\build\" \"bin\\zig.exe\" \".\\..\" \".\\..\\zig-cache\" \"--help\""), &[_][]const u8{585 try testWindowsCmdLine(utf16Literal("\".\\..\\zig-cache\\build\" \"bin\\zig.exe\" \".\\..\" \".\\..\\zig-cache\" \"--help\""), &[_][]const u8{
586 ".\\..\\zig-cache\\build",586 ".\\..\\zig-cache\\build",
587 "bin\\zig.exe",587 "bin\\zig.exe",
588 ".\\..",588 ".\\..",
...@@ -591,14 +591,14 @@ test "windows arg parsing" {...@@ -591,14 +591,14 @@ test "windows arg parsing" {
591 });591 });
592}592}
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 {
595 var it = ArgIteratorWindows.initWithCmdLine(input_cmd_line);595 var it = ArgIteratorWindows.initWithCmdLine(input_cmd_line);
596 for (expected_args) |expected_arg| {596 for (expected_args) |expected_arg| {
597 const arg = it.next(std.testing.allocator).? catch unreachable;597 const arg = it.next(std.testing.allocator).? catch unreachable;
598 defer std.testing.allocator.free(arg);598 defer std.testing.allocator.free(arg);
599 testing.expectEqualStrings(expected_arg, arg);599 try testing.expectEqualStrings(expected_arg, arg);
600 }600 }
601 testing.expect(it.next(std.testing.allocator) == null);601 try testing.expect(it.next(std.testing.allocator) == null);
602}602}
603603
604pub const UserInfo = struct {604pub const UserInfo = struct {
lib/std/rand.zig+96-96
...@@ -319,139 +319,139 @@ const SequentialPrng = struct {...@@ -319,139 +319,139 @@ const SequentialPrng = struct {
319};319};
320320
321test "Random int" {321test "Random int" {
322 testRandomInt();322 try testRandomInt();
323 comptime testRandomInt();323 comptime try testRandomInt();
324}324}
325fn testRandomInt() void {325fn testRandomInt() !void {
326 var r = SequentialPrng.init();326 var r = SequentialPrng.init();
327327
328 expect(r.random.int(u0) == 0);328 try expect(r.random.int(u0) == 0);
329329
330 r.next_value = 0;330 r.next_value = 0;
331 expect(r.random.int(u1) == 0);331 try expect(r.random.int(u1) == 0);
332 expect(r.random.int(u1) == 1);332 try expect(r.random.int(u1) == 1);
333 expect(r.random.int(u2) == 2);333 try expect(r.random.int(u2) == 2);
334 expect(r.random.int(u2) == 3);334 try expect(r.random.int(u2) == 3);
335 expect(r.random.int(u2) == 0);335 try expect(r.random.int(u2) == 0);
336336
337 r.next_value = 0xff;337 r.next_value = 0xff;
338 expect(r.random.int(u8) == 0xff);338 try expect(r.random.int(u8) == 0xff);
339 r.next_value = 0x11;339 r.next_value = 0x11;
340 expect(r.random.int(u8) == 0x11);340 try expect(r.random.int(u8) == 0x11);
341341
342 r.next_value = 0xff;342 r.next_value = 0xff;
343 expect(r.random.int(u32) == 0xffffffff);343 try expect(r.random.int(u32) == 0xffffffff);
344 r.next_value = 0x11;344 r.next_value = 0x11;
345 expect(r.random.int(u32) == 0x11111111);345 try expect(r.random.int(u32) == 0x11111111);
346346
347 r.next_value = 0xff;347 r.next_value = 0xff;
348 expect(r.random.int(i32) == -1);348 try expect(r.random.int(i32) == -1);
349 r.next_value = 0x11;349 r.next_value = 0x11;
350 expect(r.random.int(i32) == 0x11111111);350 try expect(r.random.int(i32) == 0x11111111);
351351
352 r.next_value = 0xff;352 r.next_value = 0xff;
353 expect(r.random.int(i8) == -1);353 try expect(r.random.int(i8) == -1);
354 r.next_value = 0x11;354 r.next_value = 0x11;
355 expect(r.random.int(i8) == 0x11);355 try expect(r.random.int(i8) == 0x11);
356356
357 r.next_value = 0xff;357 r.next_value = 0xff;
358 expect(r.random.int(u33) == 0x1ffffffff);358 try expect(r.random.int(u33) == 0x1ffffffff);
359 r.next_value = 0xff;359 r.next_value = 0xff;
360 expect(r.random.int(i1) == -1);360 try expect(r.random.int(i1) == -1);
361 r.next_value = 0xff;361 r.next_value = 0xff;
362 expect(r.random.int(i2) == -1);362 try expect(r.random.int(i2) == -1);
363 r.next_value = 0xff;363 r.next_value = 0xff;
364 expect(r.random.int(i33) == -1);364 try expect(r.random.int(i33) == -1);
365}365}
366366
367test "Random boolean" {367test "Random boolean" {
368 testRandomBoolean();368 try testRandomBoolean();
369 comptime testRandomBoolean();369 comptime try testRandomBoolean();
370}370}
371fn testRandomBoolean() void {371fn testRandomBoolean() !void {
372 var r = SequentialPrng.init();372 var r = SequentialPrng.init();
373 expect(r.random.boolean() == false);373 try expect(r.random.boolean() == false);
374 expect(r.random.boolean() == true);374 try expect(r.random.boolean() == true);
375 expect(r.random.boolean() == false);375 try expect(r.random.boolean() == false);
376 expect(r.random.boolean() == true);376 try expect(r.random.boolean() == true);
377}377}
378378
379test "Random intLessThan" {379test "Random intLessThan" {
380 @setEvalBranchQuota(10000);380 @setEvalBranchQuota(10000);
381 testRandomIntLessThan();381 try testRandomIntLessThan();
382 comptime testRandomIntLessThan();382 comptime try testRandomIntLessThan();
383}383}
384fn testRandomIntLessThan() void {384fn testRandomIntLessThan() !void {
385 var r = SequentialPrng.init();385 var r = SequentialPrng.init();
386 r.next_value = 0xff;386 r.next_value = 0xff;
387 expect(r.random.uintLessThan(u8, 4) == 3);387 try expect(r.random.uintLessThan(u8, 4) == 3);
388 expect(r.next_value == 0);388 try expect(r.next_value == 0);
389 expect(r.random.uintLessThan(u8, 4) == 0);389 try expect(r.random.uintLessThan(u8, 4) == 0);
390 expect(r.next_value == 1);390 try expect(r.next_value == 1);
391391
392 r.next_value = 0;392 r.next_value = 0;
393 expect(r.random.uintLessThan(u64, 32) == 0);393 try expect(r.random.uintLessThan(u64, 32) == 0);
394394
395 // trigger the bias rejection code path395 // trigger the bias rejection code path
396 r.next_value = 0;396 r.next_value = 0;
397 expect(r.random.uintLessThan(u8, 3) == 0);397 try expect(r.random.uintLessThan(u8, 3) == 0);
398 // verify we incremented twice398 // verify we incremented twice
399 expect(r.next_value == 2);399 try expect(r.next_value == 2);
400400
401 r.next_value = 0xff;401 r.next_value = 0xff;
402 expect(r.random.intRangeLessThan(u8, 0, 0x80) == 0x7f);402 try expect(r.random.intRangeLessThan(u8, 0, 0x80) == 0x7f);
403 r.next_value = 0xff;403 r.next_value = 0xff;
404 expect(r.random.intRangeLessThan(u8, 0x7f, 0xff) == 0xfe);404 try expect(r.random.intRangeLessThan(u8, 0x7f, 0xff) == 0xfe);
405405
406 r.next_value = 0xff;406 r.next_value = 0xff;
407 expect(r.random.intRangeLessThan(i8, 0, 0x40) == 0x3f);407 try expect(r.random.intRangeLessThan(i8, 0, 0x40) == 0x3f);
408 r.next_value = 0xff;408 r.next_value = 0xff;
409 expect(r.random.intRangeLessThan(i8, -0x40, 0x40) == 0x3f);409 try expect(r.random.intRangeLessThan(i8, -0x40, 0x40) == 0x3f);
410 r.next_value = 0xff;410 r.next_value = 0xff;
411 expect(r.random.intRangeLessThan(i8, -0x80, 0) == -1);411 try expect(r.random.intRangeLessThan(i8, -0x80, 0) == -1);
412412
413 r.next_value = 0xff;413 r.next_value = 0xff;
414 expect(r.random.intRangeLessThan(i3, -4, 0) == -1);414 try expect(r.random.intRangeLessThan(i3, -4, 0) == -1);
415 r.next_value = 0xff;415 r.next_value = 0xff;
416 expect(r.random.intRangeLessThan(i3, -2, 2) == 1);416 try expect(r.random.intRangeLessThan(i3, -2, 2) == 1);
417}417}
418418
419test "Random intAtMost" {419test "Random intAtMost" {
420 @setEvalBranchQuota(10000);420 @setEvalBranchQuota(10000);
421 testRandomIntAtMost();421 try testRandomIntAtMost();
422 comptime testRandomIntAtMost();422 comptime try testRandomIntAtMost();
423}423}
424fn testRandomIntAtMost() void {424fn testRandomIntAtMost() !void {
425 var r = SequentialPrng.init();425 var r = SequentialPrng.init();
426 r.next_value = 0xff;426 r.next_value = 0xff;
427 expect(r.random.uintAtMost(u8, 3) == 3);427 try expect(r.random.uintAtMost(u8, 3) == 3);
428 expect(r.next_value == 0);428 try expect(r.next_value == 0);
429 expect(r.random.uintAtMost(u8, 3) == 0);429 try expect(r.random.uintAtMost(u8, 3) == 0);
430430
431 // trigger the bias rejection code path431 // trigger the bias rejection code path
432 r.next_value = 0;432 r.next_value = 0;
433 expect(r.random.uintAtMost(u8, 2) == 0);433 try expect(r.random.uintAtMost(u8, 2) == 0);
434 // verify we incremented twice434 // verify we incremented twice
435 expect(r.next_value == 2);435 try expect(r.next_value == 2);
436436
437 r.next_value = 0xff;437 r.next_value = 0xff;
438 expect(r.random.intRangeAtMost(u8, 0, 0x7f) == 0x7f);438 try expect(r.random.intRangeAtMost(u8, 0, 0x7f) == 0x7f);
439 r.next_value = 0xff;439 r.next_value = 0xff;
440 expect(r.random.intRangeAtMost(u8, 0x7f, 0xfe) == 0xfe);440 try expect(r.random.intRangeAtMost(u8, 0x7f, 0xfe) == 0xfe);
441441
442 r.next_value = 0xff;442 r.next_value = 0xff;
443 expect(r.random.intRangeAtMost(i8, 0, 0x3f) == 0x3f);443 try expect(r.random.intRangeAtMost(i8, 0, 0x3f) == 0x3f);
444 r.next_value = 0xff;444 r.next_value = 0xff;
445 expect(r.random.intRangeAtMost(i8, -0x40, 0x3f) == 0x3f);445 try expect(r.random.intRangeAtMost(i8, -0x40, 0x3f) == 0x3f);
446 r.next_value = 0xff;446 r.next_value = 0xff;
447 expect(r.random.intRangeAtMost(i8, -0x80, -1) == -1);447 try expect(r.random.intRangeAtMost(i8, -0x80, -1) == -1);
448448
449 r.next_value = 0xff;449 r.next_value = 0xff;
450 expect(r.random.intRangeAtMost(i3, -4, -1) == -1);450 try expect(r.random.intRangeAtMost(i3, -4, -1) == -1);
451 r.next_value = 0xff;451 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);
455}455}
456456
457test "Random Biased" {457test "Random Biased" {
...@@ -459,30 +459,30 @@ test "Random Biased" {...@@ -459,30 +459,30 @@ test "Random Biased" {
459 // Not thoroughly checking the logic here.459 // Not thoroughly checking the logic here.
460 // Just want to execute all the paths with different types.460 // Just want to execute all the paths with different types.
461461
462 expect(r.random.uintLessThanBiased(u1, 1) == 0);462 try expect(r.random.uintLessThanBiased(u1, 1) == 0);
463 expect(r.random.uintLessThanBiased(u32, 10) < 10);463 try expect(r.random.uintLessThanBiased(u32, 10) < 10);
464 expect(r.random.uintLessThanBiased(u64, 20) < 20);464 try expect(r.random.uintLessThanBiased(u64, 20) < 20);
465465
466 expect(r.random.uintAtMostBiased(u0, 0) == 0);466 try expect(r.random.uintAtMostBiased(u0, 0) == 0);
467 expect(r.random.uintAtMostBiased(u1, 0) <= 0);467 try expect(r.random.uintAtMostBiased(u1, 0) <= 0);
468 expect(r.random.uintAtMostBiased(u32, 10) <= 10);468 try expect(r.random.uintAtMostBiased(u32, 10) <= 10);
469 expect(r.random.uintAtMostBiased(u64, 20) <= 20);469 try expect(r.random.uintAtMostBiased(u64, 20) <= 20);
470470
471 expect(r.random.intRangeLessThanBiased(u1, 0, 1) == 0);471 try expect(r.random.intRangeLessThanBiased(u1, 0, 1) == 0);
472 expect(r.random.intRangeLessThanBiased(i1, -1, 0) == -1);472 try expect(r.random.intRangeLessThanBiased(i1, -1, 0) == -1);
473 expect(r.random.intRangeLessThanBiased(u32, 10, 20) >= 10);473 try expect(r.random.intRangeLessThanBiased(u32, 10, 20) >= 10);
474 expect(r.random.intRangeLessThanBiased(i32, 10, 20) >= 10);474 try expect(r.random.intRangeLessThanBiased(i32, 10, 20) >= 10);
475 expect(r.random.intRangeLessThanBiased(u64, 20, 40) >= 20);475 try expect(r.random.intRangeLessThanBiased(u64, 20, 40) >= 20);
476 expect(r.random.intRangeLessThanBiased(i64, 20, 40) >= 20);476 try expect(r.random.intRangeLessThanBiased(i64, 20, 40) >= 20);
477477
478 // uncomment for broken module error:478 // uncomment for broken module error:
479 //expect(r.random.intRangeAtMostBiased(u0, 0, 0) == 0);479 //expect(r.random.intRangeAtMostBiased(u0, 0, 0) == 0);
480 expect(r.random.intRangeAtMostBiased(u1, 0, 1) >= 0);480 try expect(r.random.intRangeAtMostBiased(u1, 0, 1) >= 0);
481 expect(r.random.intRangeAtMostBiased(i1, -1, 0) >= -1);481 try expect(r.random.intRangeAtMostBiased(i1, -1, 0) >= -1);
482 expect(r.random.intRangeAtMostBiased(u32, 10, 20) >= 10);482 try expect(r.random.intRangeAtMostBiased(u32, 10, 20) >= 10);
483 expect(r.random.intRangeAtMostBiased(i32, 10, 20) >= 10);483 try expect(r.random.intRangeAtMostBiased(i32, 10, 20) >= 10);
484 expect(r.random.intRangeAtMostBiased(u64, 20, 40) >= 20);484 try expect(r.random.intRangeAtMostBiased(u64, 20, 40) >= 20);
485 expect(r.random.intRangeAtMostBiased(i64, 20, 40) >= 20);485 try expect(r.random.intRangeAtMostBiased(i64, 20, 40) >= 20);
486}486}
487487
488// Generator to extend 64-bit seed values into longer sequences.488// Generator to extend 64-bit seed values into longer sequences.
...@@ -519,7 +519,7 @@ test "splitmix64 sequence" {...@@ -519,7 +519,7 @@ test "splitmix64 sequence" {
519 };519 };
520520
521 for (seq) |s| {521 for (seq) |s| {
522 expect(s == r.next());522 try expect(s == r.next());
523 }523 }
524}524}
525525
...@@ -530,12 +530,12 @@ test "Random float" {...@@ -530,12 +530,12 @@ test "Random float" {
530 var i: usize = 0;530 var i: usize = 0;
531 while (i < 1000) : (i += 1) {531 while (i < 1000) : (i += 1) {
532 const val1 = prng.random.float(f32);532 const val1 = prng.random.float(f32);
533 expect(val1 >= 0.0);533 try expect(val1 >= 0.0);
534 expect(val1 < 1.0);534 try expect(val1 < 1.0);
535535
536 const val2 = prng.random.float(f64);536 const val2 = prng.random.float(f64);
537 expect(val2 >= 0.0);537 try expect(val2 >= 0.0);
538 expect(val2 < 1.0);538 try expect(val2 < 1.0);
539 }539 }
540}540}
541541
...@@ -549,12 +549,12 @@ test "Random shuffle" {...@@ -549,12 +549,12 @@ test "Random shuffle" {
549 while (i < 1000) : (i += 1) {549 while (i < 1000) : (i += 1) {
550 prng.random.shuffle(u8, seq[0..]);550 prng.random.shuffle(u8, seq[0..]);
551 seen[seq[0]] = true;551 seen[seq[0]] = true;
552 expect(sumArray(seq[0..]) == 10);552 try expect(sumArray(seq[0..]) == 10);
553 }553 }
554554
555 // we should see every entry at the head at least once555 // we should see every entry at the head at least once
556 for (seen) |e| {556 for (seen) |e| {
557 expect(e == true);557 try expect(e == true);
558 }558 }
559}559}
560560
...@@ -567,17 +567,17 @@ fn sumArray(s: []const u8) u32 {...@@ -567,17 +567,17 @@ fn sumArray(s: []const u8) u32 {
567567
568test "Random range" {568test "Random range" {
569 var prng = DefaultPrng.init(0);569 var prng = DefaultPrng.init(0);
570 testRange(&prng.random, -4, 3);570 try testRange(&prng.random, -4, 3);
571 testRange(&prng.random, -4, -1);571 try testRange(&prng.random, -4, -1);
572 testRange(&prng.random, 10, 14);572 try testRange(&prng.random, 10, 14);
573 testRange(&prng.random, -0x80, 0x7f);573 try testRange(&prng.random, -0x80, 0x7f);
574}574}
575575
576fn testRange(r: *Random, start: i8, end: i8) void {576fn testRange(r: *Random, start: i8, end: i8) !void {
577 testRangeBias(r, start, end, true);577 try testRangeBias(r, start, end, true);
578 testRangeBias(r, start, end, false);578 try testRangeBias(r, start, end, false);
579}579}
580fn testRangeBias(r: *Random, start: i8, end: i8, biased: bool) void {580fn testRangeBias(r: *Random, start: i8, end: i8, biased: bool) !void {
581 const count = @intCast(usize, @as(i32, end) - @as(i32, start));581 const count = @intCast(usize, @as(i32, end) - @as(i32, start));
582 var values_buffer = [_]bool{false} ** 0x100;582 var values_buffer = [_]bool{false} ** 0x100;
583 const values = values_buffer[0..count];583 const values = values_buffer[0..count];
...@@ -599,7 +599,7 @@ test "CSPRNG" {...@@ -599,7 +599,7 @@ test "CSPRNG" {
599 const a = csprng.random.int(u64);599 const a = csprng.random.int(u64);
600 const b = csprng.random.int(u64);600 const b = csprng.random.int(u64);
601 const c = csprng.random.int(u64);601 const c = csprng.random.int(u64);
602 expect(a ^ b ^ c != 0);602 try expect(a ^ b ^ c != 0);
603}603}
604604
605test {605test {
lib/std/rand/Isaac64.zig+2-2
...@@ -205,7 +205,7 @@ test "isaac64 sequence" {...@@ -205,7 +205,7 @@ test "isaac64 sequence" {
205 };205 };
206206
207 for (seq) |s| {207 for (seq) |s| {
208 std.testing.expect(s == r.next());208 try std.testing.expect(s == r.next());
209 }209 }
210}210}
211211
...@@ -237,6 +237,6 @@ test "isaac64 fill" {...@@ -237,6 +237,6 @@ test "isaac64 fill" {
237 var buf1: [7]u8 = undefined;237 var buf1: [7]u8 = undefined;
238 std.mem.writeIntLittle(u64, &buf0, s);238 std.mem.writeIntLittle(u64, &buf0, s);
239 Isaac64.fill(&r.random, &buf1);239 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..]));
241 }241 }
242}242}
lib/std/rand/Pcg.zig+2-2
...@@ -96,7 +96,7 @@ test "pcg sequence" {...@@ -96,7 +96,7 @@ test "pcg sequence" {
96 };96 };
9797
98 for (seq) |s| {98 for (seq) |s| {
99 std.testing.expect(s == r.next());99 try std.testing.expect(s == r.next());
100 }100 }
101}101}
102102
...@@ -120,6 +120,6 @@ test "pcg fill" {...@@ -120,6 +120,6 @@ test "pcg fill" {
120 var buf1: [3]u8 = undefined;120 var buf1: [3]u8 = undefined;
121 std.mem.writeIntLittle(u32, &buf0, s);121 std.mem.writeIntLittle(u32, &buf0, s);
122 Pcg.fill(&r.random, &buf1);122 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..]));
124 }124 }
125}125}
lib/std/rand/Sfc64.zig+2-2
...@@ -103,7 +103,7 @@ test "Sfc64 sequence" {...@@ -103,7 +103,7 @@ test "Sfc64 sequence" {
103 };103 };
104104
105 for (seq) |s| {105 for (seq) |s| {
106 std.testing.expectEqual(s, r.next());106 try std.testing.expectEqual(s, r.next());
107 }107 }
108}108}
109109
...@@ -135,6 +135,6 @@ test "Sfc64 fill" {...@@ -135,6 +135,6 @@ test "Sfc64 fill" {
135 var buf1: [7]u8 = undefined;135 var buf1: [7]u8 = undefined;
136 std.mem.writeIntLittle(u64, &buf0, s);136 std.mem.writeIntLittle(u64, &buf0, s);
137 Sfc64.fill(&r.random, &buf1);137 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..]));
139 }139 }
140}140}
lib/std/rand/Xoroshiro128.zig+3-3
...@@ -113,7 +113,7 @@ test "xoroshiro sequence" {...@@ -113,7 +113,7 @@ test "xoroshiro sequence" {
113 };113 };
114114
115 for (seq1) |s| {115 for (seq1) |s| {
116 std.testing.expect(s == r.next());116 try std.testing.expect(s == r.next());
117 }117 }
118118
119 r.jump();119 r.jump();
...@@ -128,7 +128,7 @@ test "xoroshiro sequence" {...@@ -128,7 +128,7 @@ test "xoroshiro sequence" {
128 };128 };
129129
130 for (seq2) |s| {130 for (seq2) |s| {
131 std.testing.expect(s == r.next());131 try std.testing.expect(s == r.next());
132 }132 }
133}133}
134134
...@@ -151,6 +151,6 @@ test "xoroshiro fill" {...@@ -151,6 +151,6 @@ test "xoroshiro fill" {
151 var buf1: [7]u8 = undefined;151 var buf1: [7]u8 = undefined;
152 std.mem.writeIntLittle(u64, &buf0, s);152 std.mem.writeIntLittle(u64, &buf0, s);
153 Xoroshiro128.fill(&r.random, &buf1);153 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..]));
155 }155 }
156}156}
lib/std/sort.zig+65-65
...@@ -43,35 +43,35 @@ test "binarySearch" {...@@ -43,35 +43,35 @@ test "binarySearch" {
43 return math.order(lhs, rhs);43 return math.order(lhs, rhs);
44 }44 }
45 };45 };
46 testing.expectEqual(46 try testing.expectEqual(
47 @as(?usize, null),47 @as(?usize, null),
48 binarySearch(u32, 1, &[_]u32{}, {}, S.order_u32),48 binarySearch(u32, 1, &[_]u32{}, {}, S.order_u32),
49 );49 );
50 testing.expectEqual(50 try testing.expectEqual(
51 @as(?usize, 0),51 @as(?usize, 0),
52 binarySearch(u32, 1, &[_]u32{1}, {}, S.order_u32),52 binarySearch(u32, 1, &[_]u32{1}, {}, S.order_u32),
53 );53 );
54 testing.expectEqual(54 try testing.expectEqual(
55 @as(?usize, null),55 @as(?usize, null),
56 binarySearch(u32, 1, &[_]u32{0}, {}, S.order_u32),56 binarySearch(u32, 1, &[_]u32{0}, {}, S.order_u32),
57 );57 );
58 testing.expectEqual(58 try testing.expectEqual(
59 @as(?usize, null),59 @as(?usize, null),
60 binarySearch(u32, 0, &[_]u32{1}, {}, S.order_u32),60 binarySearch(u32, 0, &[_]u32{1}, {}, S.order_u32),
61 );61 );
62 testing.expectEqual(62 try testing.expectEqual(
63 @as(?usize, 4),63 @as(?usize, 4),
64 binarySearch(u32, 5, &[_]u32{ 1, 2, 3, 4, 5 }, {}, S.order_u32),64 binarySearch(u32, 5, &[_]u32{ 1, 2, 3, 4, 5 }, {}, S.order_u32),
65 );65 );
66 testing.expectEqual(66 try testing.expectEqual(
67 @as(?usize, 0),67 @as(?usize, 0),
68 binarySearch(u32, 2, &[_]u32{ 2, 4, 8, 16, 32, 64 }, {}, S.order_u32),68 binarySearch(u32, 2, &[_]u32{ 2, 4, 8, 16, 32, 64 }, {}, S.order_u32),
69 );69 );
70 testing.expectEqual(70 try testing.expectEqual(
71 @as(?usize, 1),71 @as(?usize, 1),
72 binarySearch(i32, -4, &[_]i32{ -7, -4, 0, 9, 10 }, {}, S.order_i32),72 binarySearch(i32, -4, &[_]i32{ -7, -4, 0, 9, 10 }, {}, S.order_i32),
73 );73 );
74 testing.expectEqual(74 try testing.expectEqual(
75 @as(?usize, 3),75 @as(?usize, 3),
76 binarySearch(i32, 98, &[_]i32{ -100, -25, 2, 98, 99, 100 }, {}, S.order_i32),76 binarySearch(i32, 98, &[_]i32{ -100, -25, 2, 98, 99, 100 }, {}, S.order_i32),
77 );77 );
...@@ -1152,10 +1152,10 @@ pub fn desc(comptime T: type) fn (void, T, T) bool {...@@ -1152,10 +1152,10 @@ pub fn desc(comptime T: type) fn (void, T, T) bool {
1152}1152}
11531153
1154test "stable sort" {1154test "stable sort" {
1155 testStableSort();1155 try testStableSort();
1156 comptime testStableSort();1156 comptime try testStableSort();
1157}1157}
1158fn testStableSort() void {1158fn testStableSort() !void {
1159 var expected = [_]IdAndValue{1159 var expected = [_]IdAndValue{
1160 IdAndValue{ .id = 0, .value = 0 },1160 IdAndValue{ .id = 0, .value = 0 },
1161 IdAndValue{ .id = 1, .value = 0 },1161 IdAndValue{ .id = 1, .value = 0 },
...@@ -1194,8 +1194,8 @@ fn testStableSort() void {...@@ -1194,8 +1194,8 @@ fn testStableSort() void {
1194 for (cases) |*case| {1194 for (cases) |*case| {
1195 insertionSort(IdAndValue, (case.*)[0..], {}, cmpByValue);1195 insertionSort(IdAndValue, (case.*)[0..], {}, cmpByValue);
1196 for (case.*) |item, i| {1196 for (case.*) |item, i| {
1197 testing.expect(item.id == expected[i].id);1197 try testing.expect(item.id == expected[i].id);
1198 testing.expect(item.value == expected[i].value);1198 try testing.expect(item.value == expected[i].value);
1199 }1199 }
1200 }1200 }
1201}1201}
...@@ -1245,7 +1245,7 @@ test "sort" {...@@ -1245,7 +1245,7 @@ test "sort" {
1245 const slice = buf[0..case[0].len];1245 const slice = buf[0..case[0].len];
1246 mem.copy(u8, slice, case[0]);1246 mem.copy(u8, slice, case[0]);
1247 sort(u8, slice, {}, asc_u8);1247 sort(u8, slice, {}, asc_u8);
1248 testing.expect(mem.eql(u8, slice, case[1]));1248 try testing.expect(mem.eql(u8, slice, case[1]));
1249 }1249 }
12501250
1251 const i32cases = [_][]const []const i32{1251 const i32cases = [_][]const []const i32{
...@@ -1280,7 +1280,7 @@ test "sort" {...@@ -1280,7 +1280,7 @@ test "sort" {
1280 const slice = buf[0..case[0].len];1280 const slice = buf[0..case[0].len];
1281 mem.copy(i32, slice, case[0]);1281 mem.copy(i32, slice, case[0]);
1282 sort(i32, slice, {}, asc_i32);1282 sort(i32, slice, {}, asc_i32);
1283 testing.expect(mem.eql(i32, slice, case[1]));1283 try testing.expect(mem.eql(i32, slice, case[1]));
1284 }1284 }
1285}1285}
12861286
...@@ -1317,7 +1317,7 @@ test "sort descending" {...@@ -1317,7 +1317,7 @@ test "sort descending" {
1317 const slice = buf[0..case[0].len];1317 const slice = buf[0..case[0].len];
1318 mem.copy(i32, slice, case[0]);1318 mem.copy(i32, slice, case[0]);
1319 sort(i32, slice, {}, desc_i32);1319 sort(i32, slice, {}, desc_i32);
1320 testing.expect(mem.eql(i32, slice, case[1]));1320 try testing.expect(mem.eql(i32, slice, case[1]));
1321 }1321 }
1322}1322}
13231323
...@@ -1325,7 +1325,7 @@ test "another sort case" {...@@ -1325,7 +1325,7 @@ test "another sort case" {
1325 var arr = [_]i32{ 5, 3, 1, 2, 4 };1325 var arr = [_]i32{ 5, 3, 1, 2, 4 };
1326 sort(i32, arr[0..], {}, asc_i32);1326 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 }));
1329}1329}
13301330
1331test "sort fuzz testing" {1331test "sort fuzz testing" {
...@@ -1353,9 +1353,9 @@ fn fuzzTest(rng: *std.rand.Random) !void {...@@ -1353,9 +1353,9 @@ fn fuzzTest(rng: *std.rand.Random) !void {
1353 var index: usize = 1;1353 var index: usize = 1;
1354 while (index < array.len) : (index += 1) {1354 while (index < array.len) : (index += 1) {
1355 if (array[index].value == array[index - 1].value) {1355 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);
1357 } else {1357 } else {
1358 testing.expect(array[index].value > array[index - 1].value);1358 try testing.expect(array[index].value > array[index - 1].value);
1359 }1359 }
1360 }1360 }
1361}1361}
...@@ -1383,13 +1383,13 @@ pub fn argMin(...@@ -1383,13 +1383,13 @@ pub fn argMin(
1383}1383}
13841384
1385test "argMin" {1385test "argMin" {
1386 testing.expectEqual(@as(?usize, null), argMin(i32, &[_]i32{}, {}, asc_i32));1386 try testing.expectEqual(@as(?usize, null), argMin(i32, &[_]i32{}, {}, asc_i32));
1387 testing.expectEqual(@as(?usize, 0), argMin(i32, &[_]i32{1}, {}, asc_i32));1387 try 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));1388 try 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));1389 try 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));1390 try 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));1391 try 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));1392 try testing.expectEqual(@as(?usize, 3), argMin(i32, &[_]i32{ 6, 3, 5, 7, 6 }, {}, desc_i32));
1393}1393}
13941394
1395pub fn min(1395pub fn min(
...@@ -1403,13 +1403,13 @@ pub fn min(...@@ -1403,13 +1403,13 @@ pub fn min(
1403}1403}
14041404
1405test "min" {1405test "min" {
1406 testing.expectEqual(@as(?i32, null), min(i32, &[_]i32{}, {}, asc_i32));1406 try testing.expectEqual(@as(?i32, null), min(i32, &[_]i32{}, {}, asc_i32));
1407 testing.expectEqual(@as(?i32, 1), min(i32, &[_]i32{1}, {}, asc_i32));1407 try 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));1408 try 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));1409 try 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));1410 try 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));1411 try 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));1412 try testing.expectEqual(@as(?i32, 7), min(i32, &[_]i32{ 6, 3, 5, 7, 6 }, {}, desc_i32));
1413}1413}
14141414
1415pub fn argMax(1415pub fn argMax(
...@@ -1435,13 +1435,13 @@ pub fn argMax(...@@ -1435,13 +1435,13 @@ pub fn argMax(
1435}1435}
14361436
1437test "argMax" {1437test "argMax" {
1438 testing.expectEqual(@as(?usize, null), argMax(i32, &[_]i32{}, {}, asc_i32));1438 try testing.expectEqual(@as(?usize, null), argMax(i32, &[_]i32{}, {}, asc_i32));
1439 testing.expectEqual(@as(?usize, 0), argMax(i32, &[_]i32{1}, {}, asc_i32));1439 try 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));1440 try 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));1441 try 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));1442 try 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));1443 try 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));1444 try testing.expectEqual(@as(?usize, 1), argMax(i32, &[_]i32{ 6, 3, 5, 7, 6 }, {}, desc_i32));
1445}1445}
14461446
1447pub fn max(1447pub fn max(
...@@ -1455,13 +1455,13 @@ pub fn max(...@@ -1455,13 +1455,13 @@ pub fn max(
1455}1455}
14561456
1457test "max" {1457test "max" {
1458 testing.expectEqual(@as(?i32, null), max(i32, &[_]i32{}, {}, asc_i32));1458 try testing.expectEqual(@as(?i32, null), max(i32, &[_]i32{}, {}, asc_i32));
1459 testing.expectEqual(@as(?i32, 1), max(i32, &[_]i32{1}, {}, asc_i32));1459 try 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));1460 try 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));1461 try 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));1462 try 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));1463 try 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));1464 try testing.expectEqual(@as(?i32, 3), max(i32, &[_]i32{ 6, 3, 5, 7, 6 }, {}, desc_i32));
1465}1465}
14661466
1467pub fn isSorted(1467pub fn isSorted(
...@@ -1481,28 +1481,28 @@ pub fn isSorted(...@@ -1481,28 +1481,28 @@ pub fn isSorted(
1481}1481}
14821482
1483test "isSorted" {1483test "isSorted" {
1484 testing.expect(isSorted(i32, &[_]i32{}, {}, asc_i32));1484 try testing.expect(isSorted(i32, &[_]i32{}, {}, asc_i32));
1485 testing.expect(isSorted(i32, &[_]i32{10}, {}, asc_i32));1485 try testing.expect(isSorted(i32, &[_]i32{10}, {}, asc_i32));
1486 testing.expect(isSorted(i32, &[_]i32{ 1, 2, 3, 4, 5 }, {}, asc_i32));1486 try 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));1487 try testing.expect(isSorted(i32, &[_]i32{ -10, 1, 1, 1, 10 }, {}, asc_i32));
14881488
1489 testing.expect(isSorted(i32, &[_]i32{}, {}, desc_i32));1489 try testing.expect(isSorted(i32, &[_]i32{}, {}, desc_i32));
1490 testing.expect(isSorted(i32, &[_]i32{-20}, {}, desc_i32));1490 try testing.expect(isSorted(i32, &[_]i32{-20}, {}, desc_i32));
1491 testing.expect(isSorted(i32, &[_]i32{ 3, 2, 1, 0, -1 }, {}, desc_i32));1491 try testing.expect(isSorted(i32, &[_]i32{ 3, 2, 1, 0, -1 }, {}, desc_i32));
1492 testing.expect(isSorted(i32, &[_]i32{ 10, -10 }, {}, 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));1494 try 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));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));1497 try 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));1498 try testing.expectEqual(false, isSorted(i32, &[_]i32{ 1, 2, 3, 4, 5 }, {}, desc_i32));
14991499
1500 testing.expect(isSorted(u8, "abcd", {}, asc_u8));1500 try testing.expect(isSorted(u8, "abcd", {}, asc_u8));
1501 testing.expect(isSorted(u8, "zyxw", {}, desc_u8));1501 try testing.expect(isSorted(u8, "zyxw", {}, desc_u8));
15021502
1503 testing.expectEqual(false, isSorted(u8, "abcd", {}, desc_u8));1503 try testing.expectEqual(false, isSorted(u8, "abcd", {}, desc_u8));
1504 testing.expectEqual(false, isSorted(u8, "zyxw", {}, asc_u8));1504 try testing.expectEqual(false, isSorted(u8, "zyxw", {}, asc_u8));
15051505
1506 testing.expect(isSorted(u8, "ffff", {}, asc_u8));1506 try testing.expect(isSorted(u8, "ffff", {}, asc_u8));
1507 testing.expect(isSorted(u8, "ffff", {}, desc_u8));1507 try testing.expect(isSorted(u8, "ffff", {}, desc_u8));
1508}1508}
lib/std/special/c.zig+47-47
...@@ -69,7 +69,7 @@ test "strcpy" {...@@ -69,7 +69,7 @@ test "strcpy" {
6969
70 s1[0] = 0;70 s1[0] = 0;
71 _ = strcpy(&s1, "foobarbaz");71 _ = strcpy(&s1, "foobarbaz");
72 std.testing.expectEqualSlices(u8, "foobarbaz", std.mem.spanZ(&s1));72 try std.testing.expectEqualSlices(u8, "foobarbaz", std.mem.spanZ(&s1));
73}73}
7474
75fn strncpy(dest: [*:0]u8, src: [*:0]const u8, n: usize) callconv(.C) [*:0]u8 {75fn strncpy(dest: [*:0]u8, src: [*:0]const u8, n: usize) callconv(.C) [*:0]u8 {
...@@ -89,7 +89,7 @@ test "strncpy" {...@@ -89,7 +89,7 @@ test "strncpy" {
8989
90 s1[0] = 0;90 s1[0] = 0;
91 _ = strncpy(&s1, "foobarbaz", @sizeOf(@TypeOf(s1)));91 _ = 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));
93}93}
9494
95fn strcat(dest: [*:0]u8, src: [*:0]const u8) callconv(.C) [*:0]u8 {95fn strcat(dest: [*:0]u8, src: [*:0]const u8) callconv(.C) [*:0]u8 {
...@@ -112,7 +112,7 @@ test "strcat" {...@@ -112,7 +112,7 @@ test "strcat" {
112 _ = strcat(&s1, "foo");112 _ = strcat(&s1, "foo");
113 _ = strcat(&s1, "bar");113 _ = strcat(&s1, "bar");
114 _ = strcat(&s1, "baz");114 _ = strcat(&s1, "baz");
115 std.testing.expectEqualSlices(u8, "foobarbaz", std.mem.spanZ(&s1));115 try std.testing.expectEqualSlices(u8, "foobarbaz", std.mem.spanZ(&s1));
116}116}
117117
118fn strncat(dest: [*:0]u8, src: [*:0]const u8, avail: usize) callconv(.C) [*:0]u8 {118fn strncat(dest: [*:0]u8, src: [*:0]const u8, avail: usize) callconv(.C) [*:0]u8 {
...@@ -135,7 +135,7 @@ test "strncat" {...@@ -135,7 +135,7 @@ test "strncat" {
135 _ = strncat(&s1, "foo1111", 3);135 _ = strncat(&s1, "foo1111", 3);
136 _ = strncat(&s1, "bar1111", 3);136 _ = strncat(&s1, "bar1111", 3);
137 _ = strncat(&s1, "baz1111", 3);137 _ = 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));
139}139}
140140
141fn strcmp(s1: [*:0]const u8, s2: [*:0]const u8) callconv(.C) c_int {141fn 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 {...@@ -164,10 +164,10 @@ fn strerror(errnum: c_int) callconv(.C) [*:0]const u8 {
164}164}
165165
166test "strncmp" {166test "strncmp" {
167 std.testing.expect(strncmp("a", "b", 1) == -1);167 try std.testing.expect(strncmp("a", "b", 1) == -1);
168 std.testing.expect(strncmp("a", "c", 1) == -2);168 try std.testing.expect(strncmp("a", "c", 1) == -2);
169 std.testing.expect(strncmp("b", "a", 1) == 1);169 try std.testing.expect(strncmp("b", "a", 1) == 1);
170 std.testing.expect(strncmp("\xff", "\x02", 1) == 253);170 try std.testing.expect(strncmp("\xff", "\x02", 1) == 253);
171}171}
172172
173// Avoid dragging in the runtime safety mechanisms into this .o file,173// Avoid dragging in the runtime safety mechanisms into this .o file,
...@@ -248,9 +248,9 @@ test "memcmp" {...@@ -248,9 +248,9 @@ test "memcmp" {
248 const arr2 = &[_]u8{ 1, 0, 1 };248 const arr2 = &[_]u8{ 1, 0, 1 };
249 const arr3 = &[_]u8{ 1, 2, 1 };249 const arr3 = &[_]u8{ 1, 2, 1 };
250250
251 std.testing.expect(memcmp(base_arr[0..], arr1[0..], base_arr.len) == 0);251 try 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);252 try 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);253 try std.testing.expect(memcmp(base_arr[0..], arr3[0..], base_arr.len) < 0);
254}254}
255255
256export fn bcmp(vl: [*]allowzero const u8, vr: [*]allowzero const u8, n: usize) callconv(.C) isize {256export fn bcmp(vl: [*]allowzero const u8, vr: [*]allowzero const u8, n: usize) callconv(.C) isize {
...@@ -272,9 +272,9 @@ test "bcmp" {...@@ -272,9 +272,9 @@ test "bcmp" {
272 const arr2 = &[_]u8{ 1, 0, 1 };272 const arr2 = &[_]u8{ 1, 0, 1 };
273 const arr3 = &[_]u8{ 1, 2, 1 };273 const arr3 = &[_]u8{ 1, 2, 1 };
274274
275 std.testing.expect(bcmp(base_arr[0..], arr1[0..], base_arr.len) == 0);275 try 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);276 try 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);277 try std.testing.expect(bcmp(base_arr[0..], arr3[0..], base_arr.len) != 0);
278}278}
279279
280comptime {280comptime {
...@@ -868,19 +868,19 @@ test "fmod, fmodf" {...@@ -868,19 +868,19 @@ test "fmod, fmodf" {
868 const nan_val = math.nan(T);868 const nan_val = math.nan(T);
869 const inf_val = math.inf(T);869 const inf_val = math.inf(T);
870870
871 std.testing.expect(isNan(generic_fmod(T, nan_val, 1.0)));871 try std.testing.expect(isNan(generic_fmod(T, nan_val, 1.0)));
872 std.testing.expect(isNan(generic_fmod(T, 1.0, nan_val)));872 try std.testing.expect(isNan(generic_fmod(T, 1.0, nan_val)));
873 std.testing.expect(isNan(generic_fmod(T, inf_val, 1.0)));873 try std.testing.expect(isNan(generic_fmod(T, inf_val, 1.0)));
874 std.testing.expect(isNan(generic_fmod(T, 0.0, 0.0)));874 try std.testing.expect(isNan(generic_fmod(T, 0.0, 0.0)));
875 std.testing.expect(isNan(generic_fmod(T, 1.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));877 try 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));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));880 try 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));881 try 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));882 try 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));883 try std.testing.expectEqual(@as(T, 2.0), generic_fmod(T, 32.0, -10.0));
884 }884 }
885}885}
886886
...@@ -904,12 +904,12 @@ test "fmin, fminf" {...@@ -904,12 +904,12 @@ test "fmin, fminf" {
904 inline for ([_]type{ f32, f64 }) |T| {904 inline for ([_]type{ f32, f64 }) |T| {
905 const nan_val = math.nan(T);905 const nan_val = math.nan(T);
906906
907 std.testing.expect(isNan(generic_fmin(T, nan_val, nan_val)));907 try 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));908 try 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));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));911 try 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));912 try std.testing.expectEqual(@as(T, -1.0), generic_fmin(T, 1.0, -1.0));
913 }913 }
914}914}
915915
...@@ -933,12 +933,12 @@ test "fmax, fmaxf" {...@@ -933,12 +933,12 @@ test "fmax, fmaxf" {
933 inline for ([_]type{ f32, f64 }) |T| {933 inline for ([_]type{ f32, f64 }) |T| {
934 const nan_val = math.nan(T);934 const nan_val = math.nan(T);
935935
936 std.testing.expect(isNan(generic_fmax(T, nan_val, nan_val)));936 try 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));937 try 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));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));940 try 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));941 try std.testing.expectEqual(@as(T, 1.0), generic_fmax(T, 1.0, -1.0));
942 }942 }
943}943}
944944
...@@ -1093,15 +1093,15 @@ test "sqrt" {...@@ -1093,15 +1093,15 @@ test "sqrt" {
1093 // Note that @sqrt will either generate the sqrt opcode (if supported by the1093 // Note that @sqrt will either generate the sqrt opcode (if supported by the
1094 // target ISA) or a call to `sqrtf` otherwise.1094 // target ISA) or a call to `sqrtf` otherwise.
1095 for (V) |val|1095 for (V) |val|
1096 std.testing.expectEqual(@sqrt(val), sqrt(val));1096 try std.testing.expectEqual(@sqrt(val), sqrt(val));
1097}1097}
10981098
1099test "sqrt special" {1099test "sqrt special" {
1100 std.testing.expect(std.math.isPositiveInf(sqrt(std.math.inf(f64))));1100 try std.testing.expect(std.math.isPositiveInf(sqrt(std.math.inf(f64))));
1101 std.testing.expect(sqrt(0.0) == 0.0);1101 try std.testing.expect(sqrt(0.0) == 0.0);
1102 std.testing.expect(sqrt(-0.0) == -0.0);1102 try std.testing.expect(sqrt(-0.0) == -0.0);
1103 std.testing.expect(isNan(sqrt(-1.0)));1103 try std.testing.expect(isNan(sqrt(-1.0)));
1104 std.testing.expect(isNan(sqrt(std.math.nan(f64))));1104 try std.testing.expect(isNan(sqrt(std.math.nan(f64))));
1105}1105}
11061106
1107export fn sqrtf(x: f32) f32 {1107export fn sqrtf(x: f32) f32 {
...@@ -1198,13 +1198,13 @@ test "sqrtf" {...@@ -1198,13 +1198,13 @@ test "sqrtf" {
1198 // Note that @sqrt will either generate the sqrt opcode (if supported by the1198 // Note that @sqrt will either generate the sqrt opcode (if supported by the
1199 // target ISA) or a call to `sqrtf` otherwise.1199 // target ISA) or a call to `sqrtf` otherwise.
1200 for (V) |val|1200 for (V) |val|
1201 std.testing.expectEqual(@sqrt(val), sqrtf(val));1201 try std.testing.expectEqual(@sqrt(val), sqrtf(val));
1202}1202}
12031203
1204test "sqrtf special" {1204test "sqrtf special" {
1205 std.testing.expect(std.math.isPositiveInf(sqrtf(std.math.inf(f32))));1205 try std.testing.expect(std.math.isPositiveInf(sqrtf(std.math.inf(f32))));
1206 std.testing.expect(sqrtf(0.0) == 0.0);1206 try std.testing.expect(sqrtf(0.0) == 0.0);
1207 std.testing.expect(sqrtf(-0.0) == -0.0);1207 try std.testing.expect(sqrtf(-0.0) == -0.0);
1208 std.testing.expect(isNan(sqrtf(-1.0)));1208 try std.testing.expect(isNan(sqrtf(-1.0)));
1209 std.testing.expect(isNan(sqrtf(std.math.nan(f32))));1209 try std.testing.expect(isNan(sqrtf(std.math.nan(f32))));
1210}1210}
lib/std/special/compiler_rt/addXf3_test.zig+13-13
...@@ -13,7 +13,7 @@ const inf128 = @bitCast(f128, @as(u128, 0x7fff000000000000) << 64);...@@ -13,7 +13,7 @@ const inf128 = @bitCast(f128, @as(u128, 0x7fff000000000000) << 64);
1313
14const __addtf3 = @import("addXf3.zig").__addtf3;14const __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 {
17 const x = __addtf3(a, b);17 const x = __addtf3(a, b);
1818
19 const rep = @bitCast(u128, x);19 const rep = @bitCast(u128, x);
...@@ -32,28 +32,28 @@ fn test__addtf3(a: f128, b: f128, expected_hi: u64, expected_lo: u64) void {...@@ -32,28 +32,28 @@ fn test__addtf3(a: f128, b: f128, expected_hi: u64, expected_lo: u64) void {
32 }32 }
33 }33 }
3434
35 @panic("__addtf3 test failure");35 return error.TestFailed;
36}36}
3737
38test "addtf3" {38test "addtf3" {
39 test__addtf3(qnan128, 0x1.23456789abcdefp+5, 0x7fff800000000000, 0x0);39 try test__addtf3(qnan128, 0x1.23456789abcdefp+5, 0x7fff800000000000, 0x0);
4040
41 // NaN + any = NaN41 // 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
44 // inf + inf = inf44 // inf + inf = inf
45 test__addtf3(inf128, inf128, 0x7fff000000000000, 0x0);45 try test__addtf3(inf128, inf128, 0x7fff000000000000, 0x0);
4646
47 // inf + any = inf47 // inf + any = inf
48 test__addtf3(inf128, 0x1.2335653452436234723489432abcdefp+5, 0x7fff000000000000, 0x0);48 try test__addtf3(inf128, 0x1.2335653452436234723489432abcdefp+5, 0x7fff000000000000, 0x0);
4949
50 // any + any50 // 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);
52}52}
5353
54const __subtf3 = @import("addXf3.zig").__subtf3;54const __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 {
57 const x = __subtf3(a, b);57 const x = __subtf3(a, b);
5858
59 const rep = @bitCast(u128, x);59 const rep = @bitCast(u128, x);
...@@ -72,19 +72,19 @@ fn test__subtf3(a: f128, b: f128, expected_hi: u64, expected_lo: u64) void {...@@ -72,19 +72,19 @@ fn test__subtf3(a: f128, b: f128, expected_hi: u64, expected_lo: u64) void {
72 }72 }
73 }73 }
7474
75 @panic("__subtf3 test failure");75 return error.TestFailed;
76}76}
7777
78test "subtf3" {78test "subtf3" {
79 // qNaN - any = qNaN79 // qNaN - any = qNaN
80 test__subtf3(qnan128, 0x1.23456789abcdefp+5, 0x7fff800000000000, 0x0);80 try test__subtf3(qnan128, 0x1.23456789abcdefp+5, 0x7fff800000000000, 0x0);
8181
82 // NaN + any = NaN82 // 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
85 // inf - any = inf85 // inf - any = inf
86 test__subtf3(inf128, 0x1.23456789abcdefp+5, 0x7fff000000000000, 0x0);86 try test__subtf3(inf128, 0x1.23456789abcdefp+5, 0x7fff000000000000, 0x0);
8787
88 // any + any88 // 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);
90}90}
lib/std/special/compiler_rt/ashldi3_test.zig+20-20
...@@ -6,32 +6,32 @@...@@ -6,32 +6,32 @@
6const __ashldi3 = @import("shift.zig").__ashldi3;6const __ashldi3 = @import("shift.zig").__ashldi3;
7const testing = @import("std").testing;7const 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 {
10 const x = __ashldi3(a, b);10 const x = __ashldi3(a, b);
11 testing.expectEqual(@bitCast(i64, expected), x);11 try testing.expectEqual(@bitCast(i64, expected), x);
12}12}
1313
14test "ashldi3" {14test "ashldi3" {
15 test__ashldi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 0, 0x123456789ABCDEF);15 try test__ashldi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 0, 0x123456789ABCDEF);
16 test__ashldi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 1, 0x2468ACF13579BDE);16 try test__ashldi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 1, 0x2468ACF13579BDE);
17 test__ashldi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 2, 0x48D159E26AF37BC);17 try test__ashldi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 2, 0x48D159E26AF37BC);
18 test__ashldi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 3, 0x91A2B3C4D5E6F78);18 try test__ashldi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 3, 0x91A2B3C4D5E6F78);
19 test__ashldi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 4, 0x123456789ABCDEF0);19 try test__ashldi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 4, 0x123456789ABCDEF0);
2020
21 test__ashldi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 28, 0x789ABCDEF0000000);21 try test__ashldi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 28, 0x789ABCDEF0000000);
22 test__ashldi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 29, 0xF13579BDE0000000);22 try test__ashldi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 29, 0xF13579BDE0000000);
23 test__ashldi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 30, 0xE26AF37BC0000000);23 try test__ashldi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 30, 0xE26AF37BC0000000);
24 test__ashldi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 31, 0xC4D5E6F780000000);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);28 try test__ashldi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 33, 0x13579BDE00000000);
29 test__ashldi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 34, 0x26AF37BC00000000);29 try test__ashldi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 34, 0x26AF37BC00000000);
30 test__ashldi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 35, 0x4D5E6F7800000000);30 try test__ashldi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 35, 0x4D5E6F7800000000);
31 test__ashldi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 36, 0x9ABCDEF000000000);31 try test__ashldi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 36, 0x9ABCDEF000000000);
3232
33 test__ashldi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 60, 0xF000000000000000);33 try test__ashldi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 60, 0xF000000000000000);
34 test__ashldi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 61, 0xE000000000000000);34 try test__ashldi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 61, 0xE000000000000000);
35 test__ashldi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 62, 0xC000000000000000);35 try test__ashldi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 62, 0xC000000000000000);
36 test__ashldi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 63, 0x8000000000000000);36 try test__ashldi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 63, 0x8000000000000000);
37}37}
lib/std/special/compiler_rt/ashlti3_test.zig+38-38
...@@ -6,46 +6,46 @@...@@ -6,46 +6,46 @@
6const __ashlti3 = @import("shift.zig").__ashlti3;6const __ashlti3 = @import("shift.zig").__ashlti3;
7const testing = @import("std").testing;7const 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 {
10 const x = __ashlti3(a, b);10 const x = __ashlti3(a, b);
11 testing.expectEqual(expected, x);11 try testing.expectEqual(expected, x);
12}12}
1313
14test "ashlti3" {14test "ashlti3" {
15 test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 0, @bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)));15 try 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)));16 try 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)));17 try 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)));18 try 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)));19 try 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)));20 try 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)));21 try 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)));22 try 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)));23 try 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)));24 try 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)));25 try 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)));26 try 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)));27 try 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)));28 try 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)));29 try 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)));30 try 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)));31 try 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)));32 try 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)));33 try 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)));34 try 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)));35 try 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)));36 try 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)));37 try 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)));38 try 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)));39 try 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)));40 try 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)));41 try 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)));42 try 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)));43 try 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)));44 try 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)));45 try 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)));46 try 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)));47 try 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)));48 try 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)));49 try 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)));50 try test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 127, @bitCast(i128, @intCast(u128, 0x80000000000000000000000000000000)));
51}51}
lib/std/special/compiler_rt/ashrdi3_test.zig+47-47
...@@ -6,55 +6,55 @@...@@ -6,55 +6,55 @@
6const __ashrdi3 = @import("shift.zig").__ashrdi3;6const __ashrdi3 = @import("shift.zig").__ashrdi3;
7const testing = @import("std").testing;7const 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 {
10 const x = __ashrdi3(a, b);10 const x = __ashrdi3(a, b);
11 testing.expectEqual(@bitCast(i64, expected), x);11 try testing.expectEqual(@bitCast(i64, expected), x);
12}12}
1313
14test "ashrdi3" {14test "ashrdi3" {
15 test__ashrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 0, 0x123456789ABCDEF);15 try test__ashrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 0, 0x123456789ABCDEF);
16 test__ashrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 1, 0x91A2B3C4D5E6F7);16 try test__ashrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 1, 0x91A2B3C4D5E6F7);
17 test__ashrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 2, 0x48D159E26AF37B);17 try test__ashrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 2, 0x48D159E26AF37B);
18 test__ashrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 3, 0x2468ACF13579BD);18 try test__ashrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 3, 0x2468ACF13579BD);
19 test__ashrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 4, 0x123456789ABCDE);19 try test__ashrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 4, 0x123456789ABCDE);
2020
21 test__ashrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 28, 0x12345678);21 try test__ashrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 28, 0x12345678);
22 test__ashrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 29, 0x91A2B3C);22 try test__ashrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 29, 0x91A2B3C);
23 test__ashrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 30, 0x48D159E);23 try test__ashrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 30, 0x48D159E);
24 test__ashrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 31, 0x2468ACF);24 try test__ashrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 31, 0x2468ACF);
2525
26 test__ashrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 32, 0x1234567);26 try test__ashrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 32, 0x1234567);
2727
28 test__ashrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 33, 0x91A2B3);28 try test__ashrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 33, 0x91A2B3);
29 test__ashrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 34, 0x48D159);29 try test__ashrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 34, 0x48D159);
30 test__ashrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 35, 0x2468AC);30 try test__ashrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 35, 0x2468AC);
31 test__ashrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 36, 0x123456);31 try test__ashrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 36, 0x123456);
3232
33 test__ashrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 60, 0);33 try test__ashrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 60, 0);
34 test__ashrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 61, 0);34 try test__ashrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 61, 0);
35 test__ashrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 62, 0);35 try test__ashrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 62, 0);
36 test__ashrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 63, 0);36 try test__ashrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 63, 0);
3737
38 test__ashrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 0, 0xFEDCBA9876543210);38 try test__ashrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 0, 0xFEDCBA9876543210);
39 test__ashrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 1, 0xFF6E5D4C3B2A1908);39 try test__ashrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 1, 0xFF6E5D4C3B2A1908);
40 test__ashrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 2, 0xFFB72EA61D950C84);40 try test__ashrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 2, 0xFFB72EA61D950C84);
41 test__ashrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 3, 0xFFDB97530ECA8642);41 try test__ashrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 3, 0xFFDB97530ECA8642);
42 test__ashrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 4, 0xFFEDCBA987654321);42 try test__ashrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 4, 0xFFEDCBA987654321);
4343
44 test__ashrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 28, 0xFFFFFFFFEDCBA987);44 try test__ashrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 28, 0xFFFFFFFFEDCBA987);
45 test__ashrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 29, 0xFFFFFFFFF6E5D4C3);45 try test__ashrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 29, 0xFFFFFFFFF6E5D4C3);
46 test__ashrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 30, 0xFFFFFFFFFB72EA61);46 try test__ashrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 30, 0xFFFFFFFFFB72EA61);
47 test__ashrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 31, 0xFFFFFFFFFDB97530);47 try test__ashrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 31, 0xFFFFFFFFFDB97530);
4848
49 test__ashrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 32, 0xFFFFFFFFFEDCBA98);49 try test__ashrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 32, 0xFFFFFFFFFEDCBA98);
5050
51 test__ashrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 33, 0xFFFFFFFFFF6E5D4C);51 try test__ashrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 33, 0xFFFFFFFFFF6E5D4C);
52 test__ashrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 34, 0xFFFFFFFFFFB72EA6);52 try test__ashrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 34, 0xFFFFFFFFFFB72EA6);
53 test__ashrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 35, 0xFFFFFFFFFFDB9753);53 try test__ashrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 35, 0xFFFFFFFFFFDB9753);
54 test__ashrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 36, 0xFFFFFFFFFFEDCBA9);54 try test__ashrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 36, 0xFFFFFFFFFFEDCBA9);
5555
56 test__ashrdi3(@bitCast(i64, @as(u64, 0xAEDCBA9876543210)), 60, 0xFFFFFFFFFFFFFFFA);56 try test__ashrdi3(@bitCast(i64, @as(u64, 0xAEDCBA9876543210)), 60, 0xFFFFFFFFFFFFFFFA);
57 test__ashrdi3(@bitCast(i64, @as(u64, 0xAEDCBA9876543210)), 61, 0xFFFFFFFFFFFFFFFD);57 try test__ashrdi3(@bitCast(i64, @as(u64, 0xAEDCBA9876543210)), 61, 0xFFFFFFFFFFFFFFFD);
58 test__ashrdi3(@bitCast(i64, @as(u64, 0xAEDCBA9876543210)), 62, 0xFFFFFFFFFFFFFFFE);58 try test__ashrdi3(@bitCast(i64, @as(u64, 0xAEDCBA9876543210)), 62, 0xFFFFFFFFFFFFFFFE);
59 test__ashrdi3(@bitCast(i64, @as(u64, 0xAEDCBA9876543210)), 63, 0xFFFFFFFFFFFFFFFF);59 try test__ashrdi3(@bitCast(i64, @as(u64, 0xAEDCBA9876543210)), 63, 0xFFFFFFFFFFFFFFFF);
60}60}
lib/std/special/compiler_rt/ashrti3_test.zig+48-48
...@@ -6,56 +6,56 @@...@@ -6,56 +6,56 @@
6const __ashrti3 = @import("shift.zig").__ashrti3;6const __ashrti3 = @import("shift.zig").__ashrti3;
7const testing = @import("std").testing;7const 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 {
10 const x = __ashrti3(a, b);10 const x = __ashrti3(a, b);
11 testing.expectEqual(expected, x);11 try testing.expectEqual(expected, x);
12}12}
1313
14test "ashrti3" {14test "ashrti3" {
15 test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 0, @bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)));15 try 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)));16 try 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)));17 try 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)));18 try 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)));19 try test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 4, @bitCast(i128, @intCast(u128, 0xFFEDCBA9876543215FEDCBA987654321)));
2020
21 test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 28, @bitCast(i128, @intCast(u128, 0xFFFFFFFFEDCBA9876543215FEDCBA987)));21 try 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)));22 try 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)));23 try 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)));24 try test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 31, @bitCast(i128, @intCast(u128, 0xFFFFFFFFFDB97530ECA8642BFDB97530)));
2525
26 test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 32, @bitCast(i128, @intCast(u128, 0xFFFFFFFFFEDCBA9876543215FEDCBA98)));26 try test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 32, @bitCast(i128, @intCast(u128, 0xFFFFFFFFFEDCBA9876543215FEDCBA98)));
2727
28 test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 33, @bitCast(i128, @intCast(u128, 0xFFFFFFFFFF6E5D4C3B2A190AFF6E5D4C)));28 try 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)));29 try 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)));30 try 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)));31 try test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 36, @bitCast(i128, @intCast(u128, 0xFFFFFFFFFFEDCBA9876543215FEDCBA9)));
3232
33 test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 60, @bitCast(i128, @intCast(u128, 0xFFFFFFFFFFFFFFFFEDCBA9876543215F)));33 try 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)));34 try 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)));35 try 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)));36 try test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 63, @bitCast(i128, @intCast(u128, 0xFFFFFFFFFFFFFFFFFDB97530ECA8642B)));
3737
38 test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 64, @bitCast(i128, @intCast(u128, 0xFFFFFFFFFFFFFFFFFEDCBA9876543215)));38 try test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 64, @bitCast(i128, @intCast(u128, 0xFFFFFFFFFFFFFFFFFEDCBA9876543215)));
3939
40 test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 65, @bitCast(i128, @intCast(u128, 0xFFFFFFFFFFFFFFFFFF6E5D4C3B2A190A)));40 try 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)));41 try 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)));42 try 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)));43 try test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 68, @bitCast(i128, @intCast(u128, 0xFFFFFFFFFFFFFFFFFFEDCBA987654321)));
4444
45 test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 92, @bitCast(i128, @intCast(u128, 0xFFFFFFFFFFFFFFFFFFFFFFFFEDCBA987)));45 try 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)));46 try 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)));47 try 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)));48 try test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 95, @bitCast(i128, @intCast(u128, 0xFFFFFFFFFFFFFFFFFFFFFFFFFDB97530)));
4949
50 test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 96, @bitCast(i128, @intCast(u128, 0xFFFFFFFFFFFFFFFFFFFFFFFFFEDCBA98)));50 try test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 96, @bitCast(i128, @intCast(u128, 0xFFFFFFFFFFFFFFFFFFFFFFFFFEDCBA98)));
5151
52 test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 97, @bitCast(i128, @intCast(u128, 0xFFFFFFFFFFFFFFFFFFFFFFFFFF6E5D4C)));52 try 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)));53 try 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)));54 try 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)));55 try test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 100, @bitCast(i128, @intCast(u128, 0xFFFFFFFFFFFFFFFFFFFFFFFFFFEDCBA9)));
5656
57 test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 124, @bitCast(i128, @intCast(u128, 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)));57 try 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)));58 try 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)));59 try 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)));60 try test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 127, @bitCast(i128, @intCast(u128, 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)));
61}61}
lib/std/special/compiler_rt/clzsi2_test.zig+281-281
...@@ -6,294 +6,294 @@...@@ -6,294 +6,294 @@
6const clzsi2 = @import("clzsi2.zig");6const clzsi2 = @import("clzsi2.zig");
7const testing = @import("std").testing;7const testing = @import("std").testing;
88
9fn test__clzsi2(a: u32, expected: i32) void {9fn test__clzsi2(a: u32, expected: i32) !void {
10 // XXX At high optimization levels this test may be horribly miscompiled if10 // XXX At high optimization levels this test may be horribly miscompiled if
11 // one of the naked implementations is selected.11 // one of the naked implementations is selected.
12 var nakedClzsi2 = clzsi2.__clzsi2;12 var nakedClzsi2 = clzsi2.__clzsi2;
13 var actualClzsi2 = @ptrCast(fn (a: i32) callconv(.C) i32, nakedClzsi2);13 var actualClzsi2 = @ptrCast(fn (a: i32) callconv(.C) i32, nakedClzsi2);
14 var x = @bitCast(i32, a);14 var x = @bitCast(i32, a);
15 var result = actualClzsi2(x);15 var result = actualClzsi2(x);
16 testing.expectEqual(expected, result);16 try testing.expectEqual(expected, result);
17}17}
1818
19test "clzsi2" {19test "clzsi2" {
20 test__clzsi2(0x00800000, 8);20 try test__clzsi2(0x00800000, 8);
21 test__clzsi2(0x01000000, 7);21 try test__clzsi2(0x01000000, 7);
22 test__clzsi2(0x02000000, 6);22 try test__clzsi2(0x02000000, 6);
23 test__clzsi2(0x03000000, 6);23 try test__clzsi2(0x03000000, 6);
24 test__clzsi2(0x04000000, 5);24 try test__clzsi2(0x04000000, 5);
25 test__clzsi2(0x05000000, 5);25 try test__clzsi2(0x05000000, 5);
26 test__clzsi2(0x06000000, 5);26 try test__clzsi2(0x06000000, 5);
27 test__clzsi2(0x07000000, 5);27 try test__clzsi2(0x07000000, 5);
28 test__clzsi2(0x08000000, 4);28 try test__clzsi2(0x08000000, 4);
29 test__clzsi2(0x09000000, 4);29 try test__clzsi2(0x09000000, 4);
30 test__clzsi2(0x0A000000, 4);30 try test__clzsi2(0x0A000000, 4);
31 test__clzsi2(0x0B000000, 4);31 try test__clzsi2(0x0B000000, 4);
32 test__clzsi2(0x0C000000, 4);32 try test__clzsi2(0x0C000000, 4);
33 test__clzsi2(0x0D000000, 4);33 try test__clzsi2(0x0D000000, 4);
34 test__clzsi2(0x0E000000, 4);34 try test__clzsi2(0x0E000000, 4);
35 test__clzsi2(0x0F000000, 4);35 try test__clzsi2(0x0F000000, 4);
36 test__clzsi2(0x10000000, 3);36 try test__clzsi2(0x10000000, 3);
37 test__clzsi2(0x11000000, 3);37 try test__clzsi2(0x11000000, 3);
38 test__clzsi2(0x12000000, 3);38 try test__clzsi2(0x12000000, 3);
39 test__clzsi2(0x13000000, 3);39 try test__clzsi2(0x13000000, 3);
40 test__clzsi2(0x14000000, 3);40 try test__clzsi2(0x14000000, 3);
41 test__clzsi2(0x15000000, 3);41 try test__clzsi2(0x15000000, 3);
42 test__clzsi2(0x16000000, 3);42 try test__clzsi2(0x16000000, 3);
43 test__clzsi2(0x17000000, 3);43 try test__clzsi2(0x17000000, 3);
44 test__clzsi2(0x18000000, 3);44 try test__clzsi2(0x18000000, 3);
45 test__clzsi2(0x19000000, 3);45 try test__clzsi2(0x19000000, 3);
46 test__clzsi2(0x1A000000, 3);46 try test__clzsi2(0x1A000000, 3);
47 test__clzsi2(0x1B000000, 3);47 try test__clzsi2(0x1B000000, 3);
48 test__clzsi2(0x1C000000, 3);48 try test__clzsi2(0x1C000000, 3);
49 test__clzsi2(0x1D000000, 3);49 try test__clzsi2(0x1D000000, 3);
50 test__clzsi2(0x1E000000, 3);50 try test__clzsi2(0x1E000000, 3);
51 test__clzsi2(0x1F000000, 3);51 try test__clzsi2(0x1F000000, 3);
52 test__clzsi2(0x20000000, 2);52 try test__clzsi2(0x20000000, 2);
53 test__clzsi2(0x21000000, 2);53 try test__clzsi2(0x21000000, 2);
54 test__clzsi2(0x22000000, 2);54 try test__clzsi2(0x22000000, 2);
55 test__clzsi2(0x23000000, 2);55 try test__clzsi2(0x23000000, 2);
56 test__clzsi2(0x24000000, 2);56 try test__clzsi2(0x24000000, 2);
57 test__clzsi2(0x25000000, 2);57 try test__clzsi2(0x25000000, 2);
58 test__clzsi2(0x26000000, 2);58 try test__clzsi2(0x26000000, 2);
59 test__clzsi2(0x27000000, 2);59 try test__clzsi2(0x27000000, 2);
60 test__clzsi2(0x28000000, 2);60 try test__clzsi2(0x28000000, 2);
61 test__clzsi2(0x29000000, 2);61 try test__clzsi2(0x29000000, 2);
62 test__clzsi2(0x2A000000, 2);62 try test__clzsi2(0x2A000000, 2);
63 test__clzsi2(0x2B000000, 2);63 try test__clzsi2(0x2B000000, 2);
64 test__clzsi2(0x2C000000, 2);64 try test__clzsi2(0x2C000000, 2);
65 test__clzsi2(0x2D000000, 2);65 try test__clzsi2(0x2D000000, 2);
66 test__clzsi2(0x2E000000, 2);66 try test__clzsi2(0x2E000000, 2);
67 test__clzsi2(0x2F000000, 2);67 try test__clzsi2(0x2F000000, 2);
68 test__clzsi2(0x30000000, 2);68 try test__clzsi2(0x30000000, 2);
69 test__clzsi2(0x31000000, 2);69 try test__clzsi2(0x31000000, 2);
70 test__clzsi2(0x32000000, 2);70 try test__clzsi2(0x32000000, 2);
71 test__clzsi2(0x33000000, 2);71 try test__clzsi2(0x33000000, 2);
72 test__clzsi2(0x34000000, 2);72 try test__clzsi2(0x34000000, 2);
73 test__clzsi2(0x35000000, 2);73 try test__clzsi2(0x35000000, 2);
74 test__clzsi2(0x36000000, 2);74 try test__clzsi2(0x36000000, 2);
75 test__clzsi2(0x37000000, 2);75 try test__clzsi2(0x37000000, 2);
76 test__clzsi2(0x38000000, 2);76 try test__clzsi2(0x38000000, 2);
77 test__clzsi2(0x39000000, 2);77 try test__clzsi2(0x39000000, 2);
78 test__clzsi2(0x3A000000, 2);78 try test__clzsi2(0x3A000000, 2);
79 test__clzsi2(0x3B000000, 2);79 try test__clzsi2(0x3B000000, 2);
80 test__clzsi2(0x3C000000, 2);80 try test__clzsi2(0x3C000000, 2);
81 test__clzsi2(0x3D000000, 2);81 try test__clzsi2(0x3D000000, 2);
82 test__clzsi2(0x3E000000, 2);82 try test__clzsi2(0x3E000000, 2);
83 test__clzsi2(0x3F000000, 2);83 try test__clzsi2(0x3F000000, 2);
84 test__clzsi2(0x40000000, 1);84 try test__clzsi2(0x40000000, 1);
85 test__clzsi2(0x41000000, 1);85 try test__clzsi2(0x41000000, 1);
86 test__clzsi2(0x42000000, 1);86 try test__clzsi2(0x42000000, 1);
87 test__clzsi2(0x43000000, 1);87 try test__clzsi2(0x43000000, 1);
88 test__clzsi2(0x44000000, 1);88 try test__clzsi2(0x44000000, 1);
89 test__clzsi2(0x45000000, 1);89 try test__clzsi2(0x45000000, 1);
90 test__clzsi2(0x46000000, 1);90 try test__clzsi2(0x46000000, 1);
91 test__clzsi2(0x47000000, 1);91 try test__clzsi2(0x47000000, 1);
92 test__clzsi2(0x48000000, 1);92 try test__clzsi2(0x48000000, 1);
93 test__clzsi2(0x49000000, 1);93 try test__clzsi2(0x49000000, 1);
94 test__clzsi2(0x4A000000, 1);94 try test__clzsi2(0x4A000000, 1);
95 test__clzsi2(0x4B000000, 1);95 try test__clzsi2(0x4B000000, 1);
96 test__clzsi2(0x4C000000, 1);96 try test__clzsi2(0x4C000000, 1);
97 test__clzsi2(0x4D000000, 1);97 try test__clzsi2(0x4D000000, 1);
98 test__clzsi2(0x4E000000, 1);98 try test__clzsi2(0x4E000000, 1);
99 test__clzsi2(0x4F000000, 1);99 try test__clzsi2(0x4F000000, 1);
100 test__clzsi2(0x50000000, 1);100 try test__clzsi2(0x50000000, 1);
101 test__clzsi2(0x51000000, 1);101 try test__clzsi2(0x51000000, 1);
102 test__clzsi2(0x52000000, 1);102 try test__clzsi2(0x52000000, 1);
103 test__clzsi2(0x53000000, 1);103 try test__clzsi2(0x53000000, 1);
104 test__clzsi2(0x54000000, 1);104 try test__clzsi2(0x54000000, 1);
105 test__clzsi2(0x55000000, 1);105 try test__clzsi2(0x55000000, 1);
106 test__clzsi2(0x56000000, 1);106 try test__clzsi2(0x56000000, 1);
107 test__clzsi2(0x57000000, 1);107 try test__clzsi2(0x57000000, 1);
108 test__clzsi2(0x58000000, 1);108 try test__clzsi2(0x58000000, 1);
109 test__clzsi2(0x59000000, 1);109 try test__clzsi2(0x59000000, 1);
110 test__clzsi2(0x5A000000, 1);110 try test__clzsi2(0x5A000000, 1);
111 test__clzsi2(0x5B000000, 1);111 try test__clzsi2(0x5B000000, 1);
112 test__clzsi2(0x5C000000, 1);112 try test__clzsi2(0x5C000000, 1);
113 test__clzsi2(0x5D000000, 1);113 try test__clzsi2(0x5D000000, 1);
114 test__clzsi2(0x5E000000, 1);114 try test__clzsi2(0x5E000000, 1);
115 test__clzsi2(0x5F000000, 1);115 try test__clzsi2(0x5F000000, 1);
116 test__clzsi2(0x60000000, 1);116 try test__clzsi2(0x60000000, 1);
117 test__clzsi2(0x61000000, 1);117 try test__clzsi2(0x61000000, 1);
118 test__clzsi2(0x62000000, 1);118 try test__clzsi2(0x62000000, 1);
119 test__clzsi2(0x63000000, 1);119 try test__clzsi2(0x63000000, 1);
120 test__clzsi2(0x64000000, 1);120 try test__clzsi2(0x64000000, 1);
121 test__clzsi2(0x65000000, 1);121 try test__clzsi2(0x65000000, 1);
122 test__clzsi2(0x66000000, 1);122 try test__clzsi2(0x66000000, 1);
123 test__clzsi2(0x67000000, 1);123 try test__clzsi2(0x67000000, 1);
124 test__clzsi2(0x68000000, 1);124 try test__clzsi2(0x68000000, 1);
125 test__clzsi2(0x69000000, 1);125 try test__clzsi2(0x69000000, 1);
126 test__clzsi2(0x6A000000, 1);126 try test__clzsi2(0x6A000000, 1);
127 test__clzsi2(0x6B000000, 1);127 try test__clzsi2(0x6B000000, 1);
128 test__clzsi2(0x6C000000, 1);128 try test__clzsi2(0x6C000000, 1);
129 test__clzsi2(0x6D000000, 1);129 try test__clzsi2(0x6D000000, 1);
130 test__clzsi2(0x6E000000, 1);130 try test__clzsi2(0x6E000000, 1);
131 test__clzsi2(0x6F000000, 1);131 try test__clzsi2(0x6F000000, 1);
132 test__clzsi2(0x70000000, 1);132 try test__clzsi2(0x70000000, 1);
133 test__clzsi2(0x71000000, 1);133 try test__clzsi2(0x71000000, 1);
134 test__clzsi2(0x72000000, 1);134 try test__clzsi2(0x72000000, 1);
135 test__clzsi2(0x73000000, 1);135 try test__clzsi2(0x73000000, 1);
136 test__clzsi2(0x74000000, 1);136 try test__clzsi2(0x74000000, 1);
137 test__clzsi2(0x75000000, 1);137 try test__clzsi2(0x75000000, 1);
138 test__clzsi2(0x76000000, 1);138 try test__clzsi2(0x76000000, 1);
139 test__clzsi2(0x77000000, 1);139 try test__clzsi2(0x77000000, 1);
140 test__clzsi2(0x78000000, 1);140 try test__clzsi2(0x78000000, 1);
141 test__clzsi2(0x79000000, 1);141 try test__clzsi2(0x79000000, 1);
142 test__clzsi2(0x7A000000, 1);142 try test__clzsi2(0x7A000000, 1);
143 test__clzsi2(0x7B000000, 1);143 try test__clzsi2(0x7B000000, 1);
144 test__clzsi2(0x7C000000, 1);144 try test__clzsi2(0x7C000000, 1);
145 test__clzsi2(0x7D000000, 1);145 try test__clzsi2(0x7D000000, 1);
146 test__clzsi2(0x7E000000, 1);146 try test__clzsi2(0x7E000000, 1);
147 test__clzsi2(0x7F000000, 1);147 try test__clzsi2(0x7F000000, 1);
148 test__clzsi2(0x80000000, 0);148 try test__clzsi2(0x80000000, 0);
149 test__clzsi2(0x81000000, 0);149 try test__clzsi2(0x81000000, 0);
150 test__clzsi2(0x82000000, 0);150 try test__clzsi2(0x82000000, 0);
151 test__clzsi2(0x83000000, 0);151 try test__clzsi2(0x83000000, 0);
152 test__clzsi2(0x84000000, 0);152 try test__clzsi2(0x84000000, 0);
153 test__clzsi2(0x85000000, 0);153 try test__clzsi2(0x85000000, 0);
154 test__clzsi2(0x86000000, 0);154 try test__clzsi2(0x86000000, 0);
155 test__clzsi2(0x87000000, 0);155 try test__clzsi2(0x87000000, 0);
156 test__clzsi2(0x88000000, 0);156 try test__clzsi2(0x88000000, 0);
157 test__clzsi2(0x89000000, 0);157 try test__clzsi2(0x89000000, 0);
158 test__clzsi2(0x8A000000, 0);158 try test__clzsi2(0x8A000000, 0);
159 test__clzsi2(0x8B000000, 0);159 try test__clzsi2(0x8B000000, 0);
160 test__clzsi2(0x8C000000, 0);160 try test__clzsi2(0x8C000000, 0);
161 test__clzsi2(0x8D000000, 0);161 try test__clzsi2(0x8D000000, 0);
162 test__clzsi2(0x8E000000, 0);162 try test__clzsi2(0x8E000000, 0);
163 test__clzsi2(0x8F000000, 0);163 try test__clzsi2(0x8F000000, 0);
164 test__clzsi2(0x90000000, 0);164 try test__clzsi2(0x90000000, 0);
165 test__clzsi2(0x91000000, 0);165 try test__clzsi2(0x91000000, 0);
166 test__clzsi2(0x92000000, 0);166 try test__clzsi2(0x92000000, 0);
167 test__clzsi2(0x93000000, 0);167 try test__clzsi2(0x93000000, 0);
168 test__clzsi2(0x94000000, 0);168 try test__clzsi2(0x94000000, 0);
169 test__clzsi2(0x95000000, 0);169 try test__clzsi2(0x95000000, 0);
170 test__clzsi2(0x96000000, 0);170 try test__clzsi2(0x96000000, 0);
171 test__clzsi2(0x97000000, 0);171 try test__clzsi2(0x97000000, 0);
172 test__clzsi2(0x98000000, 0);172 try test__clzsi2(0x98000000, 0);
173 test__clzsi2(0x99000000, 0);173 try test__clzsi2(0x99000000, 0);
174 test__clzsi2(0x9A000000, 0);174 try test__clzsi2(0x9A000000, 0);
175 test__clzsi2(0x9B000000, 0);175 try test__clzsi2(0x9B000000, 0);
176 test__clzsi2(0x9C000000, 0);176 try test__clzsi2(0x9C000000, 0);
177 test__clzsi2(0x9D000000, 0);177 try test__clzsi2(0x9D000000, 0);
178 test__clzsi2(0x9E000000, 0);178 try test__clzsi2(0x9E000000, 0);
179 test__clzsi2(0x9F000000, 0);179 try test__clzsi2(0x9F000000, 0);
180 test__clzsi2(0xA0000000, 0);180 try test__clzsi2(0xA0000000, 0);
181 test__clzsi2(0xA1000000, 0);181 try test__clzsi2(0xA1000000, 0);
182 test__clzsi2(0xA2000000, 0);182 try test__clzsi2(0xA2000000, 0);
183 test__clzsi2(0xA3000000, 0);183 try test__clzsi2(0xA3000000, 0);
184 test__clzsi2(0xA4000000, 0);184 try test__clzsi2(0xA4000000, 0);
185 test__clzsi2(0xA5000000, 0);185 try test__clzsi2(0xA5000000, 0);
186 test__clzsi2(0xA6000000, 0);186 try test__clzsi2(0xA6000000, 0);
187 test__clzsi2(0xA7000000, 0);187 try test__clzsi2(0xA7000000, 0);
188 test__clzsi2(0xA8000000, 0);188 try test__clzsi2(0xA8000000, 0);
189 test__clzsi2(0xA9000000, 0);189 try test__clzsi2(0xA9000000, 0);
190 test__clzsi2(0xAA000000, 0);190 try test__clzsi2(0xAA000000, 0);
191 test__clzsi2(0xAB000000, 0);191 try test__clzsi2(0xAB000000, 0);
192 test__clzsi2(0xAC000000, 0);192 try test__clzsi2(0xAC000000, 0);
193 test__clzsi2(0xAD000000, 0);193 try test__clzsi2(0xAD000000, 0);
194 test__clzsi2(0xAE000000, 0);194 try test__clzsi2(0xAE000000, 0);
195 test__clzsi2(0xAF000000, 0);195 try test__clzsi2(0xAF000000, 0);
196 test__clzsi2(0xB0000000, 0);196 try test__clzsi2(0xB0000000, 0);
197 test__clzsi2(0xB1000000, 0);197 try test__clzsi2(0xB1000000, 0);
198 test__clzsi2(0xB2000000, 0);198 try test__clzsi2(0xB2000000, 0);
199 test__clzsi2(0xB3000000, 0);199 try test__clzsi2(0xB3000000, 0);
200 test__clzsi2(0xB4000000, 0);200 try test__clzsi2(0xB4000000, 0);
201 test__clzsi2(0xB5000000, 0);201 try test__clzsi2(0xB5000000, 0);
202 test__clzsi2(0xB6000000, 0);202 try test__clzsi2(0xB6000000, 0);
203 test__clzsi2(0xB7000000, 0);203 try test__clzsi2(0xB7000000, 0);
204 test__clzsi2(0xB8000000, 0);204 try test__clzsi2(0xB8000000, 0);
205 test__clzsi2(0xB9000000, 0);205 try test__clzsi2(0xB9000000, 0);
206 test__clzsi2(0xBA000000, 0);206 try test__clzsi2(0xBA000000, 0);
207 test__clzsi2(0xBB000000, 0);207 try test__clzsi2(0xBB000000, 0);
208 test__clzsi2(0xBC000000, 0);208 try test__clzsi2(0xBC000000, 0);
209 test__clzsi2(0xBD000000, 0);209 try test__clzsi2(0xBD000000, 0);
210 test__clzsi2(0xBE000000, 0);210 try test__clzsi2(0xBE000000, 0);
211 test__clzsi2(0xBF000000, 0);211 try test__clzsi2(0xBF000000, 0);
212 test__clzsi2(0xC0000000, 0);212 try test__clzsi2(0xC0000000, 0);
213 test__clzsi2(0xC1000000, 0);213 try test__clzsi2(0xC1000000, 0);
214 test__clzsi2(0xC2000000, 0);214 try test__clzsi2(0xC2000000, 0);
215 test__clzsi2(0xC3000000, 0);215 try test__clzsi2(0xC3000000, 0);
216 test__clzsi2(0xC4000000, 0);216 try test__clzsi2(0xC4000000, 0);
217 test__clzsi2(0xC5000000, 0);217 try test__clzsi2(0xC5000000, 0);
218 test__clzsi2(0xC6000000, 0);218 try test__clzsi2(0xC6000000, 0);
219 test__clzsi2(0xC7000000, 0);219 try test__clzsi2(0xC7000000, 0);
220 test__clzsi2(0xC8000000, 0);220 try test__clzsi2(0xC8000000, 0);
221 test__clzsi2(0xC9000000, 0);221 try test__clzsi2(0xC9000000, 0);
222 test__clzsi2(0xCA000000, 0);222 try test__clzsi2(0xCA000000, 0);
223 test__clzsi2(0xCB000000, 0);223 try test__clzsi2(0xCB000000, 0);
224 test__clzsi2(0xCC000000, 0);224 try test__clzsi2(0xCC000000, 0);
225 test__clzsi2(0xCD000000, 0);225 try test__clzsi2(0xCD000000, 0);
226 test__clzsi2(0xCE000000, 0);226 try test__clzsi2(0xCE000000, 0);
227 test__clzsi2(0xCF000000, 0);227 try test__clzsi2(0xCF000000, 0);
228 test__clzsi2(0xD0000000, 0);228 try test__clzsi2(0xD0000000, 0);
229 test__clzsi2(0xD1000000, 0);229 try test__clzsi2(0xD1000000, 0);
230 test__clzsi2(0xD2000000, 0);230 try test__clzsi2(0xD2000000, 0);
231 test__clzsi2(0xD3000000, 0);231 try test__clzsi2(0xD3000000, 0);
232 test__clzsi2(0xD4000000, 0);232 try test__clzsi2(0xD4000000, 0);
233 test__clzsi2(0xD5000000, 0);233 try test__clzsi2(0xD5000000, 0);
234 test__clzsi2(0xD6000000, 0);234 try test__clzsi2(0xD6000000, 0);
235 test__clzsi2(0xD7000000, 0);235 try test__clzsi2(0xD7000000, 0);
236 test__clzsi2(0xD8000000, 0);236 try test__clzsi2(0xD8000000, 0);
237 test__clzsi2(0xD9000000, 0);237 try test__clzsi2(0xD9000000, 0);
238 test__clzsi2(0xDA000000, 0);238 try test__clzsi2(0xDA000000, 0);
239 test__clzsi2(0xDB000000, 0);239 try test__clzsi2(0xDB000000, 0);
240 test__clzsi2(0xDC000000, 0);240 try test__clzsi2(0xDC000000, 0);
241 test__clzsi2(0xDD000000, 0);241 try test__clzsi2(0xDD000000, 0);
242 test__clzsi2(0xDE000000, 0);242 try test__clzsi2(0xDE000000, 0);
243 test__clzsi2(0xDF000000, 0);243 try test__clzsi2(0xDF000000, 0);
244 test__clzsi2(0xE0000000, 0);244 try test__clzsi2(0xE0000000, 0);
245 test__clzsi2(0xE1000000, 0);245 try test__clzsi2(0xE1000000, 0);
246 test__clzsi2(0xE2000000, 0);246 try test__clzsi2(0xE2000000, 0);
247 test__clzsi2(0xE3000000, 0);247 try test__clzsi2(0xE3000000, 0);
248 test__clzsi2(0xE4000000, 0);248 try test__clzsi2(0xE4000000, 0);
249 test__clzsi2(0xE5000000, 0);249 try test__clzsi2(0xE5000000, 0);
250 test__clzsi2(0xE6000000, 0);250 try test__clzsi2(0xE6000000, 0);
251 test__clzsi2(0xE7000000, 0);251 try test__clzsi2(0xE7000000, 0);
252 test__clzsi2(0xE8000000, 0);252 try test__clzsi2(0xE8000000, 0);
253 test__clzsi2(0xE9000000, 0);253 try test__clzsi2(0xE9000000, 0);
254 test__clzsi2(0xEA000000, 0);254 try test__clzsi2(0xEA000000, 0);
255 test__clzsi2(0xEB000000, 0);255 try test__clzsi2(0xEB000000, 0);
256 test__clzsi2(0xEC000000, 0);256 try test__clzsi2(0xEC000000, 0);
257 test__clzsi2(0xED000000, 0);257 try test__clzsi2(0xED000000, 0);
258 test__clzsi2(0xEE000000, 0);258 try test__clzsi2(0xEE000000, 0);
259 test__clzsi2(0xEF000000, 0);259 try test__clzsi2(0xEF000000, 0);
260 test__clzsi2(0xF0000000, 0);260 try test__clzsi2(0xF0000000, 0);
261 test__clzsi2(0xF1000000, 0);261 try test__clzsi2(0xF1000000, 0);
262 test__clzsi2(0xF2000000, 0);262 try test__clzsi2(0xF2000000, 0);
263 test__clzsi2(0xF3000000, 0);263 try test__clzsi2(0xF3000000, 0);
264 test__clzsi2(0xF4000000, 0);264 try test__clzsi2(0xF4000000, 0);
265 test__clzsi2(0xF5000000, 0);265 try test__clzsi2(0xF5000000, 0);
266 test__clzsi2(0xF6000000, 0);266 try test__clzsi2(0xF6000000, 0);
267 test__clzsi2(0xF7000000, 0);267 try test__clzsi2(0xF7000000, 0);
268 test__clzsi2(0xF8000000, 0);268 try test__clzsi2(0xF8000000, 0);
269 test__clzsi2(0xF9000000, 0);269 try test__clzsi2(0xF9000000, 0);
270 test__clzsi2(0xFA000000, 0);270 try test__clzsi2(0xFA000000, 0);
271 test__clzsi2(0xFB000000, 0);271 try test__clzsi2(0xFB000000, 0);
272 test__clzsi2(0xFC000000, 0);272 try test__clzsi2(0xFC000000, 0);
273 test__clzsi2(0xFD000000, 0);273 try test__clzsi2(0xFD000000, 0);
274 test__clzsi2(0xFE000000, 0);274 try test__clzsi2(0xFE000000, 0);
275 test__clzsi2(0xFF000000, 0);275 try test__clzsi2(0xFF000000, 0);
276 test__clzsi2(0x00000001, 31);276 try test__clzsi2(0x00000001, 31);
277 test__clzsi2(0x00000002, 30);277 try test__clzsi2(0x00000002, 30);
278 test__clzsi2(0x00000004, 29);278 try test__clzsi2(0x00000004, 29);
279 test__clzsi2(0x00000008, 28);279 try test__clzsi2(0x00000008, 28);
280 test__clzsi2(0x00000010, 27);280 try test__clzsi2(0x00000010, 27);
281 test__clzsi2(0x00000020, 26);281 try test__clzsi2(0x00000020, 26);
282 test__clzsi2(0x00000040, 25);282 try test__clzsi2(0x00000040, 25);
283 test__clzsi2(0x00000080, 24);283 try test__clzsi2(0x00000080, 24);
284 test__clzsi2(0x00000100, 23);284 try test__clzsi2(0x00000100, 23);
285 test__clzsi2(0x00000200, 22);285 try test__clzsi2(0x00000200, 22);
286 test__clzsi2(0x00000400, 21);286 try test__clzsi2(0x00000400, 21);
287 test__clzsi2(0x00000800, 20);287 try test__clzsi2(0x00000800, 20);
288 test__clzsi2(0x00001000, 19);288 try test__clzsi2(0x00001000, 19);
289 test__clzsi2(0x00002000, 18);289 try test__clzsi2(0x00002000, 18);
290 test__clzsi2(0x00004000, 17);290 try test__clzsi2(0x00004000, 17);
291 test__clzsi2(0x00008000, 16);291 try test__clzsi2(0x00008000, 16);
292 test__clzsi2(0x00010000, 15);292 try test__clzsi2(0x00010000, 15);
293 test__clzsi2(0x00020000, 14);293 try test__clzsi2(0x00020000, 14);
294 test__clzsi2(0x00040000, 13);294 try test__clzsi2(0x00040000, 13);
295 test__clzsi2(0x00080000, 12);295 try test__clzsi2(0x00080000, 12);
296 test__clzsi2(0x00100000, 11);296 try test__clzsi2(0x00100000, 11);
297 test__clzsi2(0x00200000, 10);297 try test__clzsi2(0x00200000, 10);
298 test__clzsi2(0x00400000, 9);298 try test__clzsi2(0x00400000, 9);
299}299}
lib/std/special/compiler_rt/comparedf2_test.zig+1-1
...@@ -101,6 +101,6 @@ const test_vectors = init: {...@@ -101,6 +101,6 @@ const test_vectors = init: {
101101
102test "compare f64" {102test "compare f64" {
103 for (test_vectors) |vector, i| {103 for (test_vectors) |vector, i| {
104 std.testing.expect(test__cmpdf2(vector));104 try std.testing.expect(test__cmpdf2(vector));
105 }105 }
106}106}
lib/std/special/compiler_rt/comparesf2_test.zig+1-1
...@@ -101,6 +101,6 @@ const test_vectors = init: {...@@ -101,6 +101,6 @@ const test_vectors = init: {
101101
102test "compare f32" {102test "compare f32" {
103 for (test_vectors) |vector, i| {103 for (test_vectors) |vector, i| {
104 std.testing.expect(test__cmpsf2(vector));104 try std.testing.expect(test__cmpsf2(vector));
105 }105 }
106}106}
lib/std/special/compiler_rt/divdf3_test.zig+4-4
...@@ -27,13 +27,13 @@ fn compareResultD(result: f64, expected: u64) bool {...@@ -27,13 +27,13 @@ fn compareResultD(result: f64, expected: u64) bool {
27 return false;27 return false;
28}28}
2929
30fn test__divdf3(a: f64, b: f64, expected: u64) void {30fn test__divdf3(a: f64, b: f64, expected: u64) !void {
31 const x = __divdf3(a, b);31 const x = __divdf3(a, b);
32 const ret = compareResultD(x, expected);32 const ret = compareResultD(x, expected);
33 testing.expect(ret == true);33 try testing.expect(ret == true);
34}34}
3535
36test "divdf3" {36test "divdf3" {
37 test__divdf3(1.0, 3.0, 0x3fd5555555555555);37 try test__divdf3(1.0, 3.0, 0x3fd5555555555555);
38 test__divdf3(4.450147717014403e-308, 2.0, 0x10000000000000);38 try test__divdf3(4.450147717014403e-308, 2.0, 0x10000000000000);
39}39}
lib/std/special/compiler_rt/divsf3_test.zig+4-4
...@@ -27,13 +27,13 @@ fn compareResultF(result: f32, expected: u32) bool {...@@ -27,13 +27,13 @@ fn compareResultF(result: f32, expected: u32) bool {
27 return false;27 return false;
28}28}
2929
30fn test__divsf3(a: f32, b: f32, expected: u32) void {30fn test__divsf3(a: f32, b: f32, expected: u32) !void {
31 const x = __divsf3(a, b);31 const x = __divsf3(a, b);
32 const ret = compareResultF(x, expected);32 const ret = compareResultF(x, expected);
33 testing.expect(ret == true);33 try testing.expect(ret == true);
34}34}
3535
36test "divsf3" {36test "divsf3" {
37 test__divsf3(1.0, 3.0, 0x3EAAAAAB);37 try test__divsf3(1.0, 3.0, 0x3EAAAAAB);
38 test__divsf3(2.3509887e-38, 2.0, 0x00800000);38 try test__divsf3(2.3509887e-38, 2.0, 0x00800000);
39}39}
lib/std/special/compiler_rt/divtf3_test.zig+11-11
...@@ -28,24 +28,24 @@ fn compareResultLD(result: f128, expectedHi: u64, expectedLo: u64) bool {...@@ -28,24 +28,24 @@ fn compareResultLD(result: f128, expectedHi: u64, expectedLo: u64) bool {
28 return false;28 return false;
29}29}
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 {
32 const x = __divtf3(a, b);32 const x = __divtf3(a, b);
33 const ret = compareResultLD(x, expectedHi, expectedLo);33 const ret = compareResultLD(x, expectedHi, expectedLo);
34 testing.expect(ret == true);34 try testing.expect(ret == true);
35}35}
3636
37test "divtf3" {37test "divtf3" {
38 // qNaN / any = qNaN38 // 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);
40 // NaN / any = NaN40 // 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);
42 // inf / any = inf42 // 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);45 try test__divtf3(0x1.a23b45362464523375893ab4cdefp+5, 0x1.eedcbaba3a94546558237654321fp-1, 0x4004b0b72924d407, 0x0717e84356c6eba2);
46 test__divtf3(0x1.a2b34c56d745382f9abf2c3dfeffp-50, 0x1.ed2c3ba15935332532287654321fp-9, 0x3fd5b2af3f828c9b, 0x40e51f64cde8b1f2);46 try test__divtf3(0x1.a2b34c56d745382f9abf2c3dfeffp-50, 0x1.ed2c3ba15935332532287654321fp-9, 0x3fd5b2af3f828c9b, 0x40e51f64cde8b1f2);
47 test__divtf3(0x1.2345f6aaaa786555f42432abcdefp+456, 0x1.edacbba9874f765463544dd3621fp+6400, 0x28c62e15dc464466, 0xb5a07586348557ac);47 try test__divtf3(0x1.2345f6aaaa786555f42432abcdefp+456, 0x1.edacbba9874f765463544dd3621fp+6400, 0x28c62e15dc464466, 0xb5a07586348557ac);
48 test__divtf3(0x1.2d3456f789ba6322bc665544edefp-234, 0x1.eddcdba39f3c8b7a36564354321fp-4455, 0x507b38442b539266, 0x22ce0f1d024e1252);48 try test__divtf3(0x1.2d3456f789ba6322bc665544edefp-234, 0x1.eddcdba39f3c8b7a36564354321fp-4455, 0x507b38442b539266, 0x22ce0f1d024e1252);
49 test__divtf3(0x1.2345f6b77b7a8953365433abcdefp+234, 0x1.edcba987d6bb3aa467754354321fp-4055, 0x50bf2e02f0798d36, 0x5e6fcb6b60044078);49 try test__divtf3(0x1.2345f6b77b7a8953365433abcdefp+234, 0x1.edcba987d6bb3aa467754354321fp-4055, 0x50bf2e02f0798d36, 0x5e6fcb6b60044078);
50 test__divtf3(6.72420628622418701252535563464350521E-4932, 2.0, 0x0001000000000000, 0);50 try test__divtf3(6.72420628622418701252535563464350521E-4932, 2.0, 0x0001000000000000, 0);
51}51}
lib/std/special/compiler_rt/divti3_test.zig+12-12
...@@ -6,21 +6,21 @@...@@ -6,21 +6,21 @@
6const __divti3 = @import("divti3.zig").__divti3;6const __divti3 = @import("divti3.zig").__divti3;
7const testing = @import("std").testing;7const 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 {
10 const x = __divti3(a, b);10 const x = __divti3(a, b);
11 testing.expect(x == expected);11 try testing.expect(x == expected);
12}12}
1313
14test "divti3" {14test "divti3" {
15 test__divti3(0, 1, 0);15 try test__divti3(0, 1, 0);
16 test__divti3(0, -1, 0);16 try test__divti3(0, -1, 0);
17 test__divti3(2, 1, 2);17 try test__divti3(2, 1, 2);
18 test__divti3(2, -1, -2);18 try test__divti3(2, -1, -2);
19 test__divti3(-2, 1, -2);19 try test__divti3(-2, 1, -2);
20 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)));22 try 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)));23 try 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)));24 try 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)));25 try test__divti3(@bitCast(i128, @as(u128, 0x8 << 124)), 2, @bitCast(i128, @as(u128, 0xc << 124)));
26}26}
lib/std/special/compiler_rt/emutls.zig+11-11
...@@ -339,12 +339,12 @@ test "simple_allocator" {...@@ -339,12 +339,12 @@ test "simple_allocator" {
339339
340test "__emutls_get_address zeroed" {340test "__emutls_get_address zeroed" {
341 var ctl = emutls_control.init(usize, null);341 var ctl = emutls_control.init(usize, null);
342 expect(ctl.object.index == 0);342 try expect(ctl.object.index == 0);
343343
344 // retrieve a variable from ctl344 // retrieve a variable from ctl
345 var x = @ptrCast(*usize, @alignCast(@alignOf(usize), __emutls_get_address(&ctl)));345 var x = @ptrCast(*usize, @alignCast(@alignOf(usize), __emutls_get_address(&ctl)));
346 expect(ctl.object.index != 0); // index has been allocated for this ctl346 try expect(ctl.object.index != 0); // index has been allocated for this ctl
347 expect(x.* == 0); // storage has been zeroed347 try expect(x.* == 0); // storage has been zeroed
348348
349 // modify the storage349 // modify the storage
350 x.* = 1234;350 x.* = 1234;
...@@ -352,26 +352,26 @@ test "__emutls_get_address zeroed" {...@@ -352,26 +352,26 @@ test "__emutls_get_address zeroed" {
352 // retrieve a variable from ctl (same ctl)352 // retrieve a variable from ctl (same ctl)
353 var y = @ptrCast(*usize, @alignCast(@alignOf(usize), __emutls_get_address(&ctl)));353 var y = @ptrCast(*usize, @alignCast(@alignOf(usize), __emutls_get_address(&ctl)));
354354
355 expect(y.* == 1234); // same content that x.*355 try expect(y.* == 1234); // same content that x.*
356 expect(x == y); // same pointer356 try expect(x == y); // same pointer
357}357}
358358
359test "__emutls_get_address with default_value" {359test "__emutls_get_address with default_value" {
360 var value: usize = 5678; // default value360 var value: usize = 5678; // default value
361 var ctl = emutls_control.init(usize, &value);361 var ctl = emutls_control.init(usize, &value);
362 expect(ctl.object.index == 0);362 try expect(ctl.object.index == 0);
363363
364 var x: *usize = @ptrCast(*usize, @alignCast(@alignOf(usize), __emutls_get_address(&ctl)));364 var x: *usize = @ptrCast(*usize, @alignCast(@alignOf(usize), __emutls_get_address(&ctl)));
365 expect(ctl.object.index != 0);365 try expect(ctl.object.index != 0);
366 expect(x.* == 5678); // storage initialized with default value366 try expect(x.* == 5678); // storage initialized with default value
367367
368 // modify the storage368 // modify the storage
369 x.* = 9012;369 x.* = 9012;
370370
371 expect(value == 5678); // the default value didn't change371 try expect(value == 5678); // the default value didn't change
372372
373 var y = @ptrCast(*usize, @alignCast(@alignOf(usize), __emutls_get_address(&ctl)));373 var y = @ptrCast(*usize, @alignCast(@alignOf(usize), __emutls_get_address(&ctl)));
374 expect(y.* == 9012); // the modified storage persists374 try expect(y.* == 9012); // the modified storage persists
375}375}
376376
377test "test default_value with differents sizes" {377test "test default_value with differents sizes" {
...@@ -380,7 +380,7 @@ test "test default_value with differents sizes" {...@@ -380,7 +380,7 @@ test "test default_value with differents sizes" {
380 var def: T = value;380 var def: T = value;
381 var ctl = emutls_control.init(T, &def);381 var ctl = emutls_control.init(T, &def);
382 var x = ctl.get_typed_pointer(T);382 var x = ctl.get_typed_pointer(T);
383 expect(x.* == value);383 try expect(x.* == value);
384 }384 }
385 }._testType;385 }._testType;
386386
lib/std/special/compiler_rt/extendXfYf2_test.zig+55-55
...@@ -9,7 +9,7 @@ const __extendhftf2 = @import("extendXfYf2.zig").__extendhftf2;...@@ -9,7 +9,7 @@ const __extendhftf2 = @import("extendXfYf2.zig").__extendhftf2;
9const __extendsftf2 = @import("extendXfYf2.zig").__extendsftf2;9const __extendsftf2 = @import("extendXfYf2.zig").__extendsftf2;
10const __extenddftf2 = @import("extendXfYf2.zig").__extenddftf2;10const __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 {
13 const x = __extenddftf2(a);13 const x = __extenddftf2(a);
1414
15 const rep = @bitCast(u128, x);15 const rep = @bitCast(u128, x);
...@@ -31,7 +31,7 @@ fn test__extenddftf2(a: f64, expectedHi: u64, expectedLo: u64) void {...@@ -31,7 +31,7 @@ fn test__extenddftf2(a: f64, expectedHi: u64, expectedLo: u64) void {
31 @panic("__extenddftf2 test failure");31 @panic("__extenddftf2 test failure");
32}32}
3333
34fn test__extendhfsf2(a: u16, expected: u32) void {34fn test__extendhfsf2(a: u16, expected: u32) !void {
35 const x = __extendhfsf2(a);35 const x = __extendhfsf2(a);
36 const rep = @bitCast(u32, x);36 const rep = @bitCast(u32, x);
3737
...@@ -44,10 +44,10 @@ fn test__extendhfsf2(a: u16, expected: u32) void {...@@ -44,10 +44,10 @@ fn test__extendhfsf2(a: u16, expected: u32) void {
44 }44 }
45 }45 }
4646
47 @panic("__extendhfsf2 test failure");47 return error.TestFailure;
48}48}
4949
50fn test__extendsftf2(a: f32, expectedHi: u64, expectedLo: u64) void {50fn test__extendsftf2(a: f32, expectedHi: u64, expectedLo: u64) !void {
51 const x = __extendsftf2(a);51 const x = __extendsftf2(a);
5252
53 const rep = @bitCast(u128, x);53 const rep = @bitCast(u128, x);
...@@ -66,77 +66,77 @@ fn test__extendsftf2(a: f32, expectedHi: u64, expectedLo: u64) void {...@@ -66,77 +66,77 @@ fn test__extendsftf2(a: f32, expectedHi: u64, expectedLo: u64) void {
66 }66 }
67 }67 }
6868
69 @panic("__extendsftf2 test failure");69 return error.TestFailure;
70}70}
7171
72test "extenddftf2" {72test "extenddftf2" {
73 // qNaN73 // qNaN
74 test__extenddftf2(makeQNaN64(), 0x7fff800000000000, 0x0);74 try test__extenddftf2(makeQNaN64(), 0x7fff800000000000, 0x0);
7575
76 // NaN76 // NaN
77 test__extenddftf2(makeNaN64(0x7100000000000), 0x7fff710000000000, 0x0);77 try test__extenddftf2(makeNaN64(0x7100000000000), 0x7fff710000000000, 0x0);
7878
79 // inf79 // inf
80 test__extenddftf2(makeInf64(), 0x7fff000000000000, 0x0);80 try test__extenddftf2(makeInf64(), 0x7fff000000000000, 0x0);
8181
82 // zero82 // 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);
92}92}
9393
94test "extendhfsf2" {94test "extendhfsf2" {
95 test__extendhfsf2(0x7e00, 0x7fc00000); // qNaN95 try test__extendhfsf2(0x7e00, 0x7fc00000); // qNaN
96 test__extendhfsf2(0x7f00, 0x7fe00000); // sNaN96 try test__extendhfsf2(0x7f00, 0x7fe00000); // sNaN
97 // On x86 the NaN becomes quiet because the return is pushed on the x8797 // On x86 the NaN becomes quiet because the return is pushed on the x87
98 // stack due to ABI requirements98 // stack due to ABI requirements
99 if (builtin.arch != .i386 and builtin.os.tag == .windows)99 if (builtin.arch != .i386 and builtin.os.tag == .windows)
100 test__extendhfsf2(0x7c01, 0x7f802000); // sNaN100 try test__extendhfsf2(0x7c01, 0x7f802000); // sNaN
101101
102 test__extendhfsf2(0, 0); // 0102 try test__extendhfsf2(0, 0); // 0
103 test__extendhfsf2(0x8000, 0x80000000); // -0103 try test__extendhfsf2(0x8000, 0x80000000); // -0
104104
105 test__extendhfsf2(0x7c00, 0x7f800000); // inf105 try test__extendhfsf2(0x7c00, 0x7f800000); // inf
106 test__extendhfsf2(0xfc00, 0xff800000); // -inf106 try test__extendhfsf2(0xfc00, 0xff800000); // -inf
107107
108 test__extendhfsf2(0x0001, 0x33800000); // denormal (min), 2**-24108 try test__extendhfsf2(0x0001, 0x33800000); // denormal (min), 2**-24
109 test__extendhfsf2(0x8001, 0xb3800000); // denormal (min), -2**-24109 try test__extendhfsf2(0x8001, 0xb3800000); // denormal (min), -2**-24
110110
111 test__extendhfsf2(0x03ff, 0x387fc000); // denormal (max), 2**-14 - 2**-24111 try test__extendhfsf2(0x03ff, 0x387fc000); // denormal (max), 2**-14 - 2**-24
112 test__extendhfsf2(0x83ff, 0xb87fc000); // denormal (max), -2**-14 + 2**-24112 try test__extendhfsf2(0x83ff, 0xb87fc000); // denormal (max), -2**-14 + 2**-24
113113
114 test__extendhfsf2(0x0400, 0x38800000); // normal (min), 2**-14114 try test__extendhfsf2(0x0400, 0x38800000); // normal (min), 2**-14
115 test__extendhfsf2(0x8400, 0xb8800000); // normal (min), -2**-14115 try test__extendhfsf2(0x8400, 0xb8800000); // normal (min), -2**-14
116116
117 test__extendhfsf2(0x7bff, 0x477fe000); // normal (max), 65504117 try test__extendhfsf2(0x7bff, 0x477fe000); // normal (max), 65504
118 test__extendhfsf2(0xfbff, 0xc77fe000); // normal (max), -65504118 try test__extendhfsf2(0xfbff, 0xc77fe000); // normal (max), -65504
119119
120 test__extendhfsf2(0x3c01, 0x3f802000); // normal, 1 + 2**-10120 try test__extendhfsf2(0x3c01, 0x3f802000); // normal, 1 + 2**-10
121 test__extendhfsf2(0xbc01, 0xbf802000); // normal, -1 - 2**-10121 try test__extendhfsf2(0xbc01, 0xbf802000); // normal, -1 - 2**-10
122122
123 test__extendhfsf2(0x3555, 0x3eaaa000); // normal, approx. 1/3123 try test__extendhfsf2(0x3555, 0x3eaaa000); // normal, approx. 1/3
124 test__extendhfsf2(0xb555, 0xbeaaa000); // normal, approx. -1/3124 try test__extendhfsf2(0xb555, 0xbeaaa000); // normal, approx. -1/3
125}125}
126126
127test "extendsftf2" {127test "extendsftf2" {
128 // qNaN128 // qNaN
129 test__extendsftf2(makeQNaN32(), 0x7fff800000000000, 0x0);129 try test__extendsftf2(makeQNaN32(), 0x7fff800000000000, 0x0);
130 // NaN130 // NaN
131 test__extendsftf2(makeNaN32(0x410000), 0x7fff820000000000, 0x0);131 try test__extendsftf2(makeNaN32(0x410000), 0x7fff820000000000, 0x0);
132 // inf132 // inf
133 test__extendsftf2(makeInf32(), 0x7fff000000000000, 0x0);133 try test__extendsftf2(makeInf32(), 0x7fff000000000000, 0x0);
134 // zero134 // zero
135 test__extendsftf2(0.0, 0x0, 0x0);135 try test__extendsftf2(0.0, 0x0, 0x0);
136 test__extendsftf2(0x1.23456p+5, 0x4004234560000000, 0x0);136 try test__extendsftf2(0x1.23456p+5, 0x4004234560000000, 0x0);
137 test__extendsftf2(0x1.edcbap-9, 0x3ff6edcba0000000, 0x0);137 try test__extendsftf2(0x1.edcbap-9, 0x3ff6edcba0000000, 0x0);
138 test__extendsftf2(0x1.23456p+45, 0x402c234560000000, 0x0);138 try test__extendsftf2(0x1.23456p+45, 0x402c234560000000, 0x0);
139 test__extendsftf2(0x1.edcbap-45, 0x3fd2edcba0000000, 0x0);139 try test__extendsftf2(0x1.edcbap-45, 0x3fd2edcba0000000, 0x0);
140}140}
141141
142fn makeQNaN64() f64 {142fn makeQNaN64() f64 {
...@@ -163,7 +163,7 @@ fn makeInf32() f32 {...@@ -163,7 +163,7 @@ fn makeInf32() f32 {
163 return @bitCast(f32, @as(u32, 0x7f800000));163 return @bitCast(f32, @as(u32, 0x7f800000));
164}164}
165165
166fn test__extendhftf2(a: u16, expectedHi: u64, expectedLo: u64) void {166fn test__extendhftf2(a: u16, expectedHi: u64, expectedLo: u64) !void {
167 const x = __extendhftf2(a);167 const x = __extendhftf2(a);
168168
169 const rep = @bitCast(u128, x);169 const rep = @bitCast(u128, x);
...@@ -182,29 +182,29 @@ fn test__extendhftf2(a: u16, expectedHi: u64, expectedLo: u64) void {...@@ -182,29 +182,29 @@ fn test__extendhftf2(a: u16, expectedHi: u64, expectedLo: u64) void {
182 }182 }
183 }183 }
184184
185 @panic("__extendhftf2 test failure");185 return error.TestFailure;
186}186}
187187
188test "extendhftf2" {188test "extendhftf2" {
189 // qNaN189 // qNaN
190 test__extendhftf2(0x7e00, 0x7fff800000000000, 0x0);190 try test__extendhftf2(0x7e00, 0x7fff800000000000, 0x0);
191 // NaN191 // NaN
192 test__extendhftf2(0x7d00, 0x7fff400000000000, 0x0);192 try test__extendhftf2(0x7d00, 0x7fff400000000000, 0x0);
193 // inf193 // inf
194 test__extendhftf2(0x7c00, 0x7fff000000000000, 0x0);194 try test__extendhftf2(0x7c00, 0x7fff000000000000, 0x0);
195 test__extendhftf2(0xfc00, 0xffff000000000000, 0x0);195 try test__extendhftf2(0xfc00, 0xffff000000000000, 0x0);
196 // zero196 // zero
197 test__extendhftf2(0x0000, 0x0000000000000000, 0x0);197 try test__extendhftf2(0x0000, 0x0000000000000000, 0x0);
198 test__extendhftf2(0x8000, 0x8000000000000000, 0x0);198 try test__extendhftf2(0x8000, 0x8000000000000000, 0x0);
199 // denormal199 // denormal
200 test__extendhftf2(0x0010, 0x3feb000000000000, 0x0);200 try test__extendhftf2(0x0010, 0x3feb000000000000, 0x0);
201 test__extendhftf2(0x0001, 0x3fe7000000000000, 0x0);201 try test__extendhftf2(0x0001, 0x3fe7000000000000, 0x0);
202 test__extendhftf2(0x8001, 0xbfe7000000000000, 0x0);202 try test__extendhftf2(0x8001, 0xbfe7000000000000, 0x0);
203203
204 // pi204 // pi
205 test__extendhftf2(0x4248, 0x4000920000000000, 0x0);205 try test__extendhftf2(0x4248, 0x4000920000000000, 0x0);
206 test__extendhftf2(0xc248, 0xc000920000000000, 0x0);206 try test__extendhftf2(0xc248, 0xc000920000000000, 0x0);
207207
208 test__extendhftf2(0x508c, 0x4004230000000000, 0x0);208 try test__extendhftf2(0x508c, 0x4004230000000000, 0x0);
209 test__extendhftf2(0x1bb7, 0x3ff6edc000000000, 0x0);209 try test__extendhftf2(0x1bb7, 0x3ff6edc000000000, 0x0);
210}210}
lib/std/special/compiler_rt/fixdfdi_test.zig+42-42
...@@ -9,62 +9,62 @@ const math = std.math;...@@ -9,62 +9,62 @@ const math = std.math;
9const testing = std.testing;9const testing = std.testing;
10const warn = std.debug.warn;10const warn = std.debug.warn;
1111
12fn test__fixdfdi(a: f64, expected: i64) void {12fn test__fixdfdi(a: f64, expected: i64) !void {
13 const x = __fixdfdi(a);13 const x = __fixdfdi(a);
14 //warn("a={}:{x} x={}:{x} expected={}:{x}:@as(u64, {x})\n", .{a, @bitCast(u64, a), x, x, expected, expected, @bitCast(u64, expected)});14 //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);
16}16}
1717
18test "fixdfdi" {18test "fixdfdi" {
19 //warn("\n", .{});19 //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));22 try test__fixdfdi(-0x1.FFFFFFFFFFFFFp+1023, math.minInt(i64));
23 test__fixdfdi(-0x1.FFFFFFFFFFFFFp+1023, -0x8000000000000000);23 try test__fixdfdi(-0x1.FFFFFFFFFFFFFp+1023, -0x8000000000000000);
2424
25 test__fixdfdi(-0x1.0000000000000p+127, -0x8000000000000000);25 try test__fixdfdi(-0x1.0000000000000p+127, -0x8000000000000000);
26 test__fixdfdi(-0x1.FFFFFFFFFFFFFp+126, -0x8000000000000000);26 try test__fixdfdi(-0x1.FFFFFFFFFFFFFp+126, -0x8000000000000000);
27 test__fixdfdi(-0x1.FFFFFFFFFFFFEp+126, -0x8000000000000000);27 try test__fixdfdi(-0x1.FFFFFFFFFFFFEp+126, -0x8000000000000000);
2828
29 test__fixdfdi(-0x1.0000000000001p+63, -0x8000000000000000);29 try test__fixdfdi(-0x1.0000000000001p+63, -0x8000000000000000);
30 test__fixdfdi(-0x1.0000000000000p+63, -0x8000000000000000);30 try test__fixdfdi(-0x1.0000000000000p+63, -0x8000000000000000);
31 test__fixdfdi(-0x1.FFFFFFFFFFFFFp+62, -0x7FFFFFFFFFFFFC00);31 try test__fixdfdi(-0x1.FFFFFFFFFFFFFp+62, -0x7FFFFFFFFFFFFC00);
32 test__fixdfdi(-0x1.FFFFFFFFFFFFEp+62, -0x7FFFFFFFFFFFF800);32 try test__fixdfdi(-0x1.FFFFFFFFFFFFEp+62, -0x7FFFFFFFFFFFF800);
3333
34 test__fixdfdi(-0x1.FFFFFEp+62, -0x7fffff8000000000);34 try test__fixdfdi(-0x1.FFFFFEp+62, -0x7fffff8000000000);
35 test__fixdfdi(-0x1.FFFFFCp+62, -0x7fffff0000000000);35 try test__fixdfdi(-0x1.FFFFFCp+62, -0x7fffff0000000000);
3636
37 test__fixdfdi(-2.01, -2);37 try test__fixdfdi(-2.01, -2);
38 test__fixdfdi(-2.0, -2);38 try test__fixdfdi(-2.0, -2);
39 test__fixdfdi(-1.99, -1);39 try test__fixdfdi(-1.99, -1);
40 test__fixdfdi(-1.0, -1);40 try test__fixdfdi(-1.0, -1);
41 test__fixdfdi(-0.99, 0);41 try test__fixdfdi(-0.99, 0);
42 test__fixdfdi(-0.5, 0);42 try test__fixdfdi(-0.5, 0);
43 test__fixdfdi(-math.f64_min, 0);43 try test__fixdfdi(-math.f64_min, 0);
44 test__fixdfdi(0.0, 0);44 try test__fixdfdi(0.0, 0);
45 test__fixdfdi(math.f64_min, 0);45 try test__fixdfdi(math.f64_min, 0);
46 test__fixdfdi(0.5, 0);46 try test__fixdfdi(0.5, 0);
47 test__fixdfdi(0.99, 0);47 try test__fixdfdi(0.99, 0);
48 test__fixdfdi(1.0, 1);48 try test__fixdfdi(1.0, 1);
49 test__fixdfdi(1.5, 1);49 try test__fixdfdi(1.5, 1);
50 test__fixdfdi(1.99, 1);50 try test__fixdfdi(1.99, 1);
51 test__fixdfdi(2.0, 2);51 try test__fixdfdi(2.0, 2);
52 test__fixdfdi(2.01, 2);52 try test__fixdfdi(2.01, 2);
5353
54 test__fixdfdi(0x1.FFFFFCp+62, 0x7FFFFF0000000000);54 try test__fixdfdi(0x1.FFFFFCp+62, 0x7FFFFF0000000000);
55 test__fixdfdi(0x1.FFFFFEp+62, 0x7FFFFF8000000000);55 try test__fixdfdi(0x1.FFFFFEp+62, 0x7FFFFF8000000000);
5656
57 test__fixdfdi(0x1.FFFFFFFFFFFFEp+62, 0x7FFFFFFFFFFFF800);57 try test__fixdfdi(0x1.FFFFFFFFFFFFEp+62, 0x7FFFFFFFFFFFF800);
58 test__fixdfdi(0x1.FFFFFFFFFFFFFp+62, 0x7FFFFFFFFFFFFC00);58 try test__fixdfdi(0x1.FFFFFFFFFFFFFp+62, 0x7FFFFFFFFFFFFC00);
59 test__fixdfdi(0x1.0000000000000p+63, 0x7FFFFFFFFFFFFFFF);59 try test__fixdfdi(0x1.0000000000000p+63, 0x7FFFFFFFFFFFFFFF);
60 test__fixdfdi(0x1.0000000000001p+63, 0x7FFFFFFFFFFFFFFF);60 try test__fixdfdi(0x1.0000000000001p+63, 0x7FFFFFFFFFFFFFFF);
6161
62 test__fixdfdi(0x1.FFFFFFFFFFFFEp+126, 0x7FFFFFFFFFFFFFFF);62 try test__fixdfdi(0x1.FFFFFFFFFFFFEp+126, 0x7FFFFFFFFFFFFFFF);
63 test__fixdfdi(0x1.FFFFFFFFFFFFFp+126, 0x7FFFFFFFFFFFFFFF);63 try test__fixdfdi(0x1.FFFFFFFFFFFFFp+126, 0x7FFFFFFFFFFFFFFF);
64 test__fixdfdi(0x1.0000000000000p+127, 0x7FFFFFFFFFFFFFFF);64 try test__fixdfdi(0x1.0000000000000p+127, 0x7FFFFFFFFFFFFFFF);
6565
66 test__fixdfdi(0x1.FFFFFFFFFFFFFp+1023, 0x7FFFFFFFFFFFFFFF);66 try test__fixdfdi(0x1.FFFFFFFFFFFFFp+1023, 0x7FFFFFFFFFFFFFFF);
67 test__fixdfdi(0x1.FFFFFFFFFFFFFp+1023, math.maxInt(i64));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));
70}70}
lib/std/special/compiler_rt/fixdfsi_test.zig+48-48
...@@ -9,70 +9,70 @@ const math = std.math;...@@ -9,70 +9,70 @@ const math = std.math;
9const testing = std.testing;9const testing = std.testing;
10const warn = std.debug.warn;10const warn = std.debug.warn;
1111
12fn test__fixdfsi(a: f64, expected: i32) void {12fn test__fixdfsi(a: f64, expected: i32) !void {
13 const x = __fixdfsi(a);13 const x = __fixdfsi(a);
14 //warn("a={}:{x} x={}:{x} expected={}:{x}:@as(u64, {x})\n", .{a, @bitCast(u64, a), x, x, expected, expected, @bitCast(u32, expected)});14 //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);
16}16}
1717
18test "fixdfsi" {18test "fixdfsi" {
19 //warn("\n", .{});19 //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));22 try test__fixdfsi(-0x1.FFFFFFFFFFFFFp+1023, math.minInt(i32));
23 test__fixdfsi(-0x1.FFFFFFFFFFFFFp+1023, -0x80000000);23 try test__fixdfsi(-0x1.FFFFFFFFFFFFFp+1023, -0x80000000);
2424
25 test__fixdfsi(-0x1.0000000000000p+127, -0x80000000);25 try test__fixdfsi(-0x1.0000000000000p+127, -0x80000000);
26 test__fixdfsi(-0x1.FFFFFFFFFFFFFp+126, -0x80000000);26 try test__fixdfsi(-0x1.FFFFFFFFFFFFFp+126, -0x80000000);
27 test__fixdfsi(-0x1.FFFFFFFFFFFFEp+126, -0x80000000);27 try test__fixdfsi(-0x1.FFFFFFFFFFFFEp+126, -0x80000000);
2828
29 test__fixdfsi(-0x1.0000000000001p+63, -0x80000000);29 try test__fixdfsi(-0x1.0000000000001p+63, -0x80000000);
30 test__fixdfsi(-0x1.0000000000000p+63, -0x80000000);30 try test__fixdfsi(-0x1.0000000000000p+63, -0x80000000);
31 test__fixdfsi(-0x1.FFFFFFFFFFFFFp+62, -0x80000000);31 try test__fixdfsi(-0x1.FFFFFFFFFFFFFp+62, -0x80000000);
32 test__fixdfsi(-0x1.FFFFFFFFFFFFEp+62, -0x80000000);32 try test__fixdfsi(-0x1.FFFFFFFFFFFFEp+62, -0x80000000);
3333
34 test__fixdfsi(-0x1.FFFFFEp+62, -0x80000000);34 try test__fixdfsi(-0x1.FFFFFEp+62, -0x80000000);
35 test__fixdfsi(-0x1.FFFFFCp+62, -0x80000000);35 try test__fixdfsi(-0x1.FFFFFCp+62, -0x80000000);
3636
37 test__fixdfsi(-0x1.000000p+31, -0x80000000);37 try test__fixdfsi(-0x1.000000p+31, -0x80000000);
38 test__fixdfsi(-0x1.FFFFFFp+30, -0x7FFFFFC0);38 try test__fixdfsi(-0x1.FFFFFFp+30, -0x7FFFFFC0);
39 test__fixdfsi(-0x1.FFFFFEp+30, -0x7FFFFF80);39 try test__fixdfsi(-0x1.FFFFFEp+30, -0x7FFFFF80);
4040
41 test__fixdfsi(-2.01, -2);41 try test__fixdfsi(-2.01, -2);
42 test__fixdfsi(-2.0, -2);42 try test__fixdfsi(-2.0, -2);
43 test__fixdfsi(-1.99, -1);43 try test__fixdfsi(-1.99, -1);
44 test__fixdfsi(-1.0, -1);44 try test__fixdfsi(-1.0, -1);
45 test__fixdfsi(-0.99, 0);45 try test__fixdfsi(-0.99, 0);
46 test__fixdfsi(-0.5, 0);46 try test__fixdfsi(-0.5, 0);
47 test__fixdfsi(-math.f64_min, 0);47 try test__fixdfsi(-math.f64_min, 0);
48 test__fixdfsi(0.0, 0);48 try test__fixdfsi(0.0, 0);
49 test__fixdfsi(math.f64_min, 0);49 try test__fixdfsi(math.f64_min, 0);
50 test__fixdfsi(0.5, 0);50 try test__fixdfsi(0.5, 0);
51 test__fixdfsi(0.99, 0);51 try test__fixdfsi(0.99, 0);
52 test__fixdfsi(1.0, 1);52 try test__fixdfsi(1.0, 1);
53 test__fixdfsi(1.5, 1);53 try test__fixdfsi(1.5, 1);
54 test__fixdfsi(1.99, 1);54 try test__fixdfsi(1.99, 1);
55 test__fixdfsi(2.0, 2);55 try test__fixdfsi(2.0, 2);
56 test__fixdfsi(2.01, 2);56 try test__fixdfsi(2.01, 2);
5757
58 test__fixdfsi(0x1.FFFFFEp+30, 0x7FFFFF80);58 try test__fixdfsi(0x1.FFFFFEp+30, 0x7FFFFF80);
59 test__fixdfsi(0x1.FFFFFFp+30, 0x7FFFFFC0);59 try test__fixdfsi(0x1.FFFFFFp+30, 0x7FFFFFC0);
60 test__fixdfsi(0x1.000000p+31, 0x7FFFFFFF);60 try test__fixdfsi(0x1.000000p+31, 0x7FFFFFFF);
6161
62 test__fixdfsi(0x1.FFFFFCp+62, 0x7FFFFFFF);62 try test__fixdfsi(0x1.FFFFFCp+62, 0x7FFFFFFF);
63 test__fixdfsi(0x1.FFFFFEp+62, 0x7FFFFFFF);63 try test__fixdfsi(0x1.FFFFFEp+62, 0x7FFFFFFF);
6464
65 test__fixdfsi(0x1.FFFFFFFFFFFFEp+62, 0x7FFFFFFF);65 try test__fixdfsi(0x1.FFFFFFFFFFFFEp+62, 0x7FFFFFFF);
66 test__fixdfsi(0x1.FFFFFFFFFFFFFp+62, 0x7FFFFFFF);66 try test__fixdfsi(0x1.FFFFFFFFFFFFFp+62, 0x7FFFFFFF);
67 test__fixdfsi(0x1.0000000000000p+63, 0x7FFFFFFF);67 try test__fixdfsi(0x1.0000000000000p+63, 0x7FFFFFFF);
68 test__fixdfsi(0x1.0000000000001p+63, 0x7FFFFFFF);68 try test__fixdfsi(0x1.0000000000001p+63, 0x7FFFFFFF);
6969
70 test__fixdfsi(0x1.FFFFFFFFFFFFEp+126, 0x7FFFFFFF);70 try test__fixdfsi(0x1.FFFFFFFFFFFFEp+126, 0x7FFFFFFF);
71 test__fixdfsi(0x1.FFFFFFFFFFFFFp+126, 0x7FFFFFFF);71 try test__fixdfsi(0x1.FFFFFFFFFFFFFp+126, 0x7FFFFFFF);
72 test__fixdfsi(0x1.0000000000000p+127, 0x7FFFFFFF);72 try test__fixdfsi(0x1.0000000000000p+127, 0x7FFFFFFF);
7373
74 test__fixdfsi(0x1.FFFFFFFFFFFFFp+1023, 0x7FFFFFFF);74 try test__fixdfsi(0x1.FFFFFFFFFFFFFp+1023, 0x7FFFFFFF);
75 test__fixdfsi(0x1.FFFFFFFFFFFFFp+1023, math.maxInt(i32));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));
78}78}
lib/std/special/compiler_rt/fixdfti_test.zig+42-42
...@@ -9,62 +9,62 @@ const math = std.math;...@@ -9,62 +9,62 @@ const math = std.math;
9const testing = std.testing;9const testing = std.testing;
10const warn = std.debug.warn;10const warn = std.debug.warn;
1111
12fn test__fixdfti(a: f64, expected: i128) void {12fn test__fixdfti(a: f64, expected: i128) !void {
13 const x = __fixdfti(a);13 const x = __fixdfti(a);
14 //warn("a={}:{x} x={}:{x} expected={}:{x}:@as(u64, {x})\n", .{a, @bitCast(u64, a), x, x, expected, expected, @bitCast(u128, expected)});14 //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);
16}16}
1717
18test "fixdfti" {18test "fixdfti" {
19 //warn("\n", .{});19 //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));22 try test__fixdfti(-0x1.FFFFFFFFFFFFFp+1023, math.minInt(i128));
23 test__fixdfti(-0x1.FFFFFFFFFFFFFp+1023, -0x80000000000000000000000000000000);23 try test__fixdfti(-0x1.FFFFFFFFFFFFFp+1023, -0x80000000000000000000000000000000);
2424
25 test__fixdfti(-0x1.0000000000000p+127, -0x80000000000000000000000000000000);25 try test__fixdfti(-0x1.0000000000000p+127, -0x80000000000000000000000000000000);
26 test__fixdfti(-0x1.FFFFFFFFFFFFFp+126, -0x7FFFFFFFFFFFFC000000000000000000);26 try test__fixdfti(-0x1.FFFFFFFFFFFFFp+126, -0x7FFFFFFFFFFFFC000000000000000000);
27 test__fixdfti(-0x1.FFFFFFFFFFFFEp+126, -0x7FFFFFFFFFFFF8000000000000000000);27 try test__fixdfti(-0x1.FFFFFFFFFFFFEp+126, -0x7FFFFFFFFFFFF8000000000000000000);
2828
29 test__fixdfti(-0x1.0000000000001p+63, -0x8000000000000800);29 try test__fixdfti(-0x1.0000000000001p+63, -0x8000000000000800);
30 test__fixdfti(-0x1.0000000000000p+63, -0x8000000000000000);30 try test__fixdfti(-0x1.0000000000000p+63, -0x8000000000000000);
31 test__fixdfti(-0x1.FFFFFFFFFFFFFp+62, -0x7FFFFFFFFFFFFC00);31 try test__fixdfti(-0x1.FFFFFFFFFFFFFp+62, -0x7FFFFFFFFFFFFC00);
32 test__fixdfti(-0x1.FFFFFFFFFFFFEp+62, -0x7FFFFFFFFFFFF800);32 try test__fixdfti(-0x1.FFFFFFFFFFFFEp+62, -0x7FFFFFFFFFFFF800);
3333
34 test__fixdfti(-0x1.FFFFFEp+62, -0x7fffff8000000000);34 try test__fixdfti(-0x1.FFFFFEp+62, -0x7fffff8000000000);
35 test__fixdfti(-0x1.FFFFFCp+62, -0x7fffff0000000000);35 try test__fixdfti(-0x1.FFFFFCp+62, -0x7fffff0000000000);
3636
37 test__fixdfti(-2.01, -2);37 try test__fixdfti(-2.01, -2);
38 test__fixdfti(-2.0, -2);38 try test__fixdfti(-2.0, -2);
39 test__fixdfti(-1.99, -1);39 try test__fixdfti(-1.99, -1);
40 test__fixdfti(-1.0, -1);40 try test__fixdfti(-1.0, -1);
41 test__fixdfti(-0.99, 0);41 try test__fixdfti(-0.99, 0);
42 test__fixdfti(-0.5, 0);42 try test__fixdfti(-0.5, 0);
43 test__fixdfti(-math.f64_min, 0);43 try test__fixdfti(-math.f64_min, 0);
44 test__fixdfti(0.0, 0);44 try test__fixdfti(0.0, 0);
45 test__fixdfti(math.f64_min, 0);45 try test__fixdfti(math.f64_min, 0);
46 test__fixdfti(0.5, 0);46 try test__fixdfti(0.5, 0);
47 test__fixdfti(0.99, 0);47 try test__fixdfti(0.99, 0);
48 test__fixdfti(1.0, 1);48 try test__fixdfti(1.0, 1);
49 test__fixdfti(1.5, 1);49 try test__fixdfti(1.5, 1);
50 test__fixdfti(1.99, 1);50 try test__fixdfti(1.99, 1);
51 test__fixdfti(2.0, 2);51 try test__fixdfti(2.0, 2);
52 test__fixdfti(2.01, 2);52 try test__fixdfti(2.01, 2);
5353
54 test__fixdfti(0x1.FFFFFCp+62, 0x7FFFFF0000000000);54 try test__fixdfti(0x1.FFFFFCp+62, 0x7FFFFF0000000000);
55 test__fixdfti(0x1.FFFFFEp+62, 0x7FFFFF8000000000);55 try test__fixdfti(0x1.FFFFFEp+62, 0x7FFFFF8000000000);
5656
57 test__fixdfti(0x1.FFFFFFFFFFFFEp+62, 0x7FFFFFFFFFFFF800);57 try test__fixdfti(0x1.FFFFFFFFFFFFEp+62, 0x7FFFFFFFFFFFF800);
58 test__fixdfti(0x1.FFFFFFFFFFFFFp+62, 0x7FFFFFFFFFFFFC00);58 try test__fixdfti(0x1.FFFFFFFFFFFFFp+62, 0x7FFFFFFFFFFFFC00);
59 test__fixdfti(0x1.0000000000000p+63, 0x8000000000000000);59 try test__fixdfti(0x1.0000000000000p+63, 0x8000000000000000);
60 test__fixdfti(0x1.0000000000001p+63, 0x8000000000000800);60 try test__fixdfti(0x1.0000000000001p+63, 0x8000000000000800);
6161
62 test__fixdfti(0x1.FFFFFFFFFFFFEp+126, 0x7FFFFFFFFFFFF8000000000000000000);62 try test__fixdfti(0x1.FFFFFFFFFFFFEp+126, 0x7FFFFFFFFFFFF8000000000000000000);
63 test__fixdfti(0x1.FFFFFFFFFFFFFp+126, 0x7FFFFFFFFFFFFC000000000000000000);63 try test__fixdfti(0x1.FFFFFFFFFFFFFp+126, 0x7FFFFFFFFFFFFC000000000000000000);
64 test__fixdfti(0x1.0000000000000p+127, 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF);64 try test__fixdfti(0x1.0000000000000p+127, 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF);
6565
66 test__fixdfti(0x1.FFFFFFFFFFFFFp+1023, 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF);66 try test__fixdfti(0x1.FFFFFFFFFFFFFp+1023, 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF);
67 test__fixdfti(0x1.FFFFFFFFFFFFFp+1023, math.maxInt(i128));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));
70}70}
lib/std/special/compiler_rt/fixint_test.zig+123-123
...@@ -11,147 +11,147 @@ const warn = std.debug.warn;...@@ -11,147 +11,147 @@ const warn = std.debug.warn;
1111
12const fixint = @import("fixint.zig").fixint;12const 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 {
15 const x = fixint(fp_t, fixint_t, a);15 const x = fixint(fp_t, fixint_t, a);
16 //warn("a={} x={}:{x} expected={}:{x})\n", .{a, x, x, expected, expected});16 //warn("a={} x={}:{x} expected={}:{x})\n", .{a, x, x, expected, expected});
17 testing.expect(x == expected);17 try testing.expect(x == expected);
18}18}
1919
20test "fixint.i1" {20test "fixint.i1" {
21 test__fixint(f32, i1, -math.inf_f32, -1);21 try test__fixint(f32, i1, -math.inf_f32, -1);
22 test__fixint(f32, i1, -math.f32_max, -1);22 try test__fixint(f32, i1, -math.f32_max, -1);
23 test__fixint(f32, i1, -2.0, -1);23 try test__fixint(f32, i1, -2.0, -1);
24 test__fixint(f32, i1, -1.1, -1);24 try test__fixint(f32, i1, -1.1, -1);
25 test__fixint(f32, i1, -1.0, -1);25 try test__fixint(f32, i1, -1.0, -1);
26 test__fixint(f32, i1, -0.9, 0);26 try test__fixint(f32, i1, -0.9, 0);
27 test__fixint(f32, i1, -0.1, 0);27 try test__fixint(f32, i1, -0.1, 0);
28 test__fixint(f32, i1, -math.f32_min, 0);28 try test__fixint(f32, i1, -math.f32_min, 0);
29 test__fixint(f32, i1, -0.0, 0);29 try test__fixint(f32, i1, -0.0, 0);
30 test__fixint(f32, i1, 0.0, 0);30 try test__fixint(f32, i1, 0.0, 0);
31 test__fixint(f32, i1, math.f32_min, 0);31 try test__fixint(f32, i1, math.f32_min, 0);
32 test__fixint(f32, i1, 0.1, 0);32 try test__fixint(f32, i1, 0.1, 0);
33 test__fixint(f32, i1, 0.9, 0);33 try test__fixint(f32, i1, 0.9, 0);
34 test__fixint(f32, i1, 1.0, 0);34 try test__fixint(f32, i1, 1.0, 0);
35 test__fixint(f32, i1, 2.0, 0);35 try test__fixint(f32, i1, 2.0, 0);
36 test__fixint(f32, i1, math.f32_max, 0);36 try test__fixint(f32, i1, math.f32_max, 0);
37 test__fixint(f32, i1, math.inf_f32, 0);37 try test__fixint(f32, i1, math.inf_f32, 0);
38}38}
3939
40test "fixint.i2" {40test "fixint.i2" {
41 test__fixint(f32, i2, -math.inf_f32, -2);41 try test__fixint(f32, i2, -math.inf_f32, -2);
42 test__fixint(f32, i2, -math.f32_max, -2);42 try test__fixint(f32, i2, -math.f32_max, -2);
43 test__fixint(f32, i2, -2.0, -2);43 try test__fixint(f32, i2, -2.0, -2);
44 test__fixint(f32, i2, -1.9, -1);44 try test__fixint(f32, i2, -1.9, -1);
45 test__fixint(f32, i2, -1.1, -1);45 try test__fixint(f32, i2, -1.1, -1);
46 test__fixint(f32, i2, -1.0, -1);46 try test__fixint(f32, i2, -1.0, -1);
47 test__fixint(f32, i2, -0.9, 0);47 try test__fixint(f32, i2, -0.9, 0);
48 test__fixint(f32, i2, -0.1, 0);48 try test__fixint(f32, i2, -0.1, 0);
49 test__fixint(f32, i2, -math.f32_min, 0);49 try test__fixint(f32, i2, -math.f32_min, 0);
50 test__fixint(f32, i2, -0.0, 0);50 try test__fixint(f32, i2, -0.0, 0);
51 test__fixint(f32, i2, 0.0, 0);51 try test__fixint(f32, i2, 0.0, 0);
52 test__fixint(f32, i2, math.f32_min, 0);52 try test__fixint(f32, i2, math.f32_min, 0);
53 test__fixint(f32, i2, 0.1, 0);53 try test__fixint(f32, i2, 0.1, 0);
54 test__fixint(f32, i2, 0.9, 0);54 try test__fixint(f32, i2, 0.9, 0);
55 test__fixint(f32, i2, 1.0, 1);55 try test__fixint(f32, i2, 1.0, 1);
56 test__fixint(f32, i2, 2.0, 1);56 try test__fixint(f32, i2, 2.0, 1);
57 test__fixint(f32, i2, math.f32_max, 1);57 try test__fixint(f32, i2, math.f32_max, 1);
58 test__fixint(f32, i2, math.inf_f32, 1);58 try test__fixint(f32, i2, math.inf_f32, 1);
59}59}
6060
61test "fixint.i3" {61test "fixint.i3" {
62 test__fixint(f32, i3, -math.inf_f32, -4);62 try test__fixint(f32, i3, -math.inf_f32, -4);
63 test__fixint(f32, i3, -math.f32_max, -4);63 try test__fixint(f32, i3, -math.f32_max, -4);
64 test__fixint(f32, i3, -4.0, -4);64 try test__fixint(f32, i3, -4.0, -4);
65 test__fixint(f32, i3, -3.0, -3);65 try test__fixint(f32, i3, -3.0, -3);
66 test__fixint(f32, i3, -2.0, -2);66 try test__fixint(f32, i3, -2.0, -2);
67 test__fixint(f32, i3, -1.9, -1);67 try test__fixint(f32, i3, -1.9, -1);
68 test__fixint(f32, i3, -1.1, -1);68 try test__fixint(f32, i3, -1.1, -1);
69 test__fixint(f32, i3, -1.0, -1);69 try test__fixint(f32, i3, -1.0, -1);
70 test__fixint(f32, i3, -0.9, 0);70 try test__fixint(f32, i3, -0.9, 0);
71 test__fixint(f32, i3, -0.1, 0);71 try test__fixint(f32, i3, -0.1, 0);
72 test__fixint(f32, i3, -math.f32_min, 0);72 try test__fixint(f32, i3, -math.f32_min, 0);
73 test__fixint(f32, i3, -0.0, 0);73 try test__fixint(f32, i3, -0.0, 0);
74 test__fixint(f32, i3, 0.0, 0);74 try test__fixint(f32, i3, 0.0, 0);
75 test__fixint(f32, i3, math.f32_min, 0);75 try test__fixint(f32, i3, math.f32_min, 0);
76 test__fixint(f32, i3, 0.1, 0);76 try test__fixint(f32, i3, 0.1, 0);
77 test__fixint(f32, i3, 0.9, 0);77 try test__fixint(f32, i3, 0.9, 0);
78 test__fixint(f32, i3, 1.0, 1);78 try test__fixint(f32, i3, 1.0, 1);
79 test__fixint(f32, i3, 2.0, 2);79 try test__fixint(f32, i3, 2.0, 2);
80 test__fixint(f32, i3, 3.0, 3);80 try test__fixint(f32, i3, 3.0, 3);
81 test__fixint(f32, i3, 4.0, 3);81 try test__fixint(f32, i3, 4.0, 3);
82 test__fixint(f32, i3, math.f32_max, 3);82 try test__fixint(f32, i3, math.f32_max, 3);
83 test__fixint(f32, i3, math.inf_f32, 3);83 try test__fixint(f32, i3, math.inf_f32, 3);
84}84}
8585
86test "fixint.i32" {86test "fixint.i32" {
87 test__fixint(f64, i32, -math.inf_f64, math.minInt(i32));87 try test__fixint(f64, i32, -math.inf_f64, math.minInt(i32));
88 test__fixint(f64, i32, -math.f64_max, math.minInt(i32));88 try test__fixint(f64, i32, -math.f64_max, math.minInt(i32));
89 test__fixint(f64, i32, @as(f64, math.minInt(i32)), math.minInt(i32));89 try 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);90 try test__fixint(f64, i32, @as(f64, math.minInt(i32)) + 1, math.minInt(i32) + 1);
91 test__fixint(f64, i32, -2.0, -2);91 try test__fixint(f64, i32, -2.0, -2);
92 test__fixint(f64, i32, -1.9, -1);92 try test__fixint(f64, i32, -1.9, -1);
93 test__fixint(f64, i32, -1.1, -1);93 try test__fixint(f64, i32, -1.1, -1);
94 test__fixint(f64, i32, -1.0, -1);94 try test__fixint(f64, i32, -1.0, -1);
95 test__fixint(f64, i32, -0.9, 0);95 try test__fixint(f64, i32, -0.9, 0);
96 test__fixint(f64, i32, -0.1, 0);96 try test__fixint(f64, i32, -0.1, 0);
97 test__fixint(f64, i32, -math.f32_min, 0);97 try test__fixint(f64, i32, -math.f32_min, 0);
98 test__fixint(f64, i32, -0.0, 0);98 try test__fixint(f64, i32, -0.0, 0);
99 test__fixint(f64, i32, 0.0, 0);99 try test__fixint(f64, i32, 0.0, 0);
100 test__fixint(f64, i32, math.f32_min, 0);100 try test__fixint(f64, i32, math.f32_min, 0);
101 test__fixint(f64, i32, 0.1, 0);101 try test__fixint(f64, i32, 0.1, 0);
102 test__fixint(f64, i32, 0.9, 0);102 try test__fixint(f64, i32, 0.9, 0);
103 test__fixint(f64, i32, 1.0, 1);103 try test__fixint(f64, i32, 1.0, 1);
104 test__fixint(f64, i32, @as(f64, math.maxInt(i32)) - 1, math.maxInt(i32) - 1);104 try 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));105 try test__fixint(f64, i32, @as(f64, math.maxInt(i32)), math.maxInt(i32));
106 test__fixint(f64, i32, math.f64_max, math.maxInt(i32));106 try test__fixint(f64, i32, math.f64_max, math.maxInt(i32));
107 test__fixint(f64, i32, math.inf_f64, math.maxInt(i32));107 try test__fixint(f64, i32, math.inf_f64, math.maxInt(i32));
108}108}
109109
110test "fixint.i64" {110test "fixint.i64" {
111 test__fixint(f64, i64, -math.inf_f64, math.minInt(i64));111 try test__fixint(f64, i64, -math.inf_f64, math.minInt(i64));
112 test__fixint(f64, i64, -math.f64_max, math.minInt(i64));112 try test__fixint(f64, i64, -math.f64_max, math.minInt(i64));
113 test__fixint(f64, i64, @as(f64, math.minInt(i64)), math.minInt(i64));113 try 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));114 try 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);115 try test__fixint(f64, i64, @as(f64, math.minInt(i64) / 2), math.minInt(i64) / 2);
116 test__fixint(f64, i64, -2.0, -2);116 try test__fixint(f64, i64, -2.0, -2);
117 test__fixint(f64, i64, -1.9, -1);117 try test__fixint(f64, i64, -1.9, -1);
118 test__fixint(f64, i64, -1.1, -1);118 try test__fixint(f64, i64, -1.1, -1);
119 test__fixint(f64, i64, -1.0, -1);119 try test__fixint(f64, i64, -1.0, -1);
120 test__fixint(f64, i64, -0.9, 0);120 try test__fixint(f64, i64, -0.9, 0);
121 test__fixint(f64, i64, -0.1, 0);121 try test__fixint(f64, i64, -0.1, 0);
122 test__fixint(f64, i64, -math.f32_min, 0);122 try test__fixint(f64, i64, -math.f32_min, 0);
123 test__fixint(f64, i64, -0.0, 0);123 try test__fixint(f64, i64, -0.0, 0);
124 test__fixint(f64, i64, 0.0, 0);124 try test__fixint(f64, i64, 0.0, 0);
125 test__fixint(f64, i64, math.f32_min, 0);125 try test__fixint(f64, i64, math.f32_min, 0);
126 test__fixint(f64, i64, 0.1, 0);126 try test__fixint(f64, i64, 0.1, 0);
127 test__fixint(f64, i64, 0.9, 0);127 try test__fixint(f64, i64, 0.9, 0);
128 test__fixint(f64, i64, 1.0, 1);128 try test__fixint(f64, i64, 1.0, 1);
129 test__fixint(f64, i64, @as(f64, math.maxInt(i64)) - 1, math.maxInt(i64));129 try 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));130 try test__fixint(f64, i64, @as(f64, math.maxInt(i64)), math.maxInt(i64));
131 test__fixint(f64, i64, math.f64_max, math.maxInt(i64));131 try test__fixint(f64, i64, math.f64_max, math.maxInt(i64));
132 test__fixint(f64, i64, math.inf_f64, math.maxInt(i64));132 try test__fixint(f64, i64, math.inf_f64, math.maxInt(i64));
133}133}
134134
135test "fixint.i128" {135test "fixint.i128" {
136 test__fixint(f64, i128, -math.inf_f64, math.minInt(i128));136 try test__fixint(f64, i128, -math.inf_f64, math.minInt(i128));
137 test__fixint(f64, i128, -math.f64_max, math.minInt(i128));137 try test__fixint(f64, i128, -math.f64_max, math.minInt(i128));
138 test__fixint(f64, i128, @as(f64, math.minInt(i128)), math.minInt(i128));138 try 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));139 try test__fixint(f64, i128, @as(f64, math.minInt(i128)) + 1, math.minInt(i128));
140 test__fixint(f64, i128, -2.0, -2);140 try test__fixint(f64, i128, -2.0, -2);
141 test__fixint(f64, i128, -1.9, -1);141 try test__fixint(f64, i128, -1.9, -1);
142 test__fixint(f64, i128, -1.1, -1);142 try test__fixint(f64, i128, -1.1, -1);
143 test__fixint(f64, i128, -1.0, -1);143 try test__fixint(f64, i128, -1.0, -1);
144 test__fixint(f64, i128, -0.9, 0);144 try test__fixint(f64, i128, -0.9, 0);
145 test__fixint(f64, i128, -0.1, 0);145 try test__fixint(f64, i128, -0.1, 0);
146 test__fixint(f64, i128, -math.f32_min, 0);146 try test__fixint(f64, i128, -math.f32_min, 0);
147 test__fixint(f64, i128, -0.0, 0);147 try test__fixint(f64, i128, -0.0, 0);
148 test__fixint(f64, i128, 0.0, 0);148 try test__fixint(f64, i128, 0.0, 0);
149 test__fixint(f64, i128, math.f32_min, 0);149 try test__fixint(f64, i128, math.f32_min, 0);
150 test__fixint(f64, i128, 0.1, 0);150 try test__fixint(f64, i128, 0.1, 0);
151 test__fixint(f64, i128, 0.9, 0);151 try test__fixint(f64, i128, 0.9, 0);
152 test__fixint(f64, i128, 1.0, 1);152 try test__fixint(f64, i128, 1.0, 1);
153 test__fixint(f64, i128, @as(f64, math.maxInt(i128)) - 1, math.maxInt(i128));153 try 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));154 try test__fixint(f64, i128, @as(f64, math.maxInt(i128)), math.maxInt(i128));
155 test__fixint(f64, i128, math.f64_max, math.maxInt(i128));155 try test__fixint(f64, i128, math.f64_max, math.maxInt(i128));
156 test__fixint(f64, i128, math.inf_f64, math.maxInt(i128));156 try test__fixint(f64, i128, math.inf_f64, math.maxInt(i128));
157}157}
lib/std/special/compiler_rt/fixsfdi_test.zig+44-44
...@@ -9,64 +9,64 @@ const math = std.math;...@@ -9,64 +9,64 @@ const math = std.math;
9const testing = std.testing;9const testing = std.testing;
10const warn = std.debug.warn;10const warn = std.debug.warn;
1111
12fn test__fixsfdi(a: f32, expected: i64) void {12fn test__fixsfdi(a: f32, expected: i64) !void {
13 const x = __fixsfdi(a);13 const x = __fixsfdi(a);
14 //warn("a={}:{x} x={}:{x} expected={}:{x}:@as(u32, {x})\n", .{a, @bitCast(u32, a), x, x, expected, expected, @bitCast(u64, expected)});14 //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);
16}16}
1717
18test "fixsfdi" {18test "fixsfdi" {
19 //warn("\n", .{});19 //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));22 try test__fixsfdi(-0x1.FFFFFFFFFFFFFp+1023, math.minInt(i64));
23 test__fixsfdi(-0x1.FFFFFFFFFFFFFp+1023, -0x8000000000000000);23 try test__fixsfdi(-0x1.FFFFFFFFFFFFFp+1023, -0x8000000000000000);
2424
25 test__fixsfdi(-0x1.0000000000000p+127, -0x8000000000000000);25 try test__fixsfdi(-0x1.0000000000000p+127, -0x8000000000000000);
26 test__fixsfdi(-0x1.FFFFFFFFFFFFFp+126, -0x8000000000000000);26 try test__fixsfdi(-0x1.FFFFFFFFFFFFFp+126, -0x8000000000000000);
27 test__fixsfdi(-0x1.FFFFFFFFFFFFEp+126, -0x8000000000000000);27 try test__fixsfdi(-0x1.FFFFFFFFFFFFEp+126, -0x8000000000000000);
2828
29 test__fixsfdi(-0x1.0000000000001p+63, -0x8000000000000000);29 try test__fixsfdi(-0x1.0000000000001p+63, -0x8000000000000000);
30 test__fixsfdi(-0x1.0000000000000p+63, -0x8000000000000000);30 try test__fixsfdi(-0x1.0000000000000p+63, -0x8000000000000000);
31 test__fixsfdi(-0x1.FFFFFFFFFFFFFp+62, -0x8000000000000000);31 try test__fixsfdi(-0x1.FFFFFFFFFFFFFp+62, -0x8000000000000000);
32 test__fixsfdi(-0x1.FFFFFFFFFFFFEp+62, -0x8000000000000000);32 try test__fixsfdi(-0x1.FFFFFFFFFFFFEp+62, -0x8000000000000000);
3333
34 test__fixsfdi(-0x1.FFFFFFp+62, -0x8000000000000000);34 try test__fixsfdi(-0x1.FFFFFFp+62, -0x8000000000000000);
35 test__fixsfdi(-0x1.FFFFFEp+62, -0x7fffff8000000000);35 try test__fixsfdi(-0x1.FFFFFEp+62, -0x7fffff8000000000);
36 test__fixsfdi(-0x1.FFFFFCp+62, -0x7fffff0000000000);36 try test__fixsfdi(-0x1.FFFFFCp+62, -0x7fffff0000000000);
3737
38 test__fixsfdi(-2.01, -2);38 try test__fixsfdi(-2.01, -2);
39 test__fixsfdi(-2.0, -2);39 try test__fixsfdi(-2.0, -2);
40 test__fixsfdi(-1.99, -1);40 try test__fixsfdi(-1.99, -1);
41 test__fixsfdi(-1.0, -1);41 try test__fixsfdi(-1.0, -1);
42 test__fixsfdi(-0.99, 0);42 try test__fixsfdi(-0.99, 0);
43 test__fixsfdi(-0.5, 0);43 try test__fixsfdi(-0.5, 0);
44 test__fixsfdi(-math.f32_min, 0);44 try test__fixsfdi(-math.f32_min, 0);
45 test__fixsfdi(0.0, 0);45 try test__fixsfdi(0.0, 0);
46 test__fixsfdi(math.f32_min, 0);46 try test__fixsfdi(math.f32_min, 0);
47 test__fixsfdi(0.5, 0);47 try test__fixsfdi(0.5, 0);
48 test__fixsfdi(0.99, 0);48 try test__fixsfdi(0.99, 0);
49 test__fixsfdi(1.0, 1);49 try test__fixsfdi(1.0, 1);
50 test__fixsfdi(1.5, 1);50 try test__fixsfdi(1.5, 1);
51 test__fixsfdi(1.99, 1);51 try test__fixsfdi(1.99, 1);
52 test__fixsfdi(2.0, 2);52 try test__fixsfdi(2.0, 2);
53 test__fixsfdi(2.01, 2);53 try test__fixsfdi(2.01, 2);
5454
55 test__fixsfdi(0x1.FFFFFCp+62, 0x7FFFFF0000000000);55 try test__fixsfdi(0x1.FFFFFCp+62, 0x7FFFFF0000000000);
56 test__fixsfdi(0x1.FFFFFEp+62, 0x7FFFFF8000000000);56 try test__fixsfdi(0x1.FFFFFEp+62, 0x7FFFFF8000000000);
57 test__fixsfdi(0x1.FFFFFFp+62, 0x7FFFFFFFFFFFFFFF);57 try test__fixsfdi(0x1.FFFFFFp+62, 0x7FFFFFFFFFFFFFFF);
5858
59 test__fixsfdi(0x1.FFFFFFFFFFFFEp+62, 0x7FFFFFFFFFFFFFFF);59 try test__fixsfdi(0x1.FFFFFFFFFFFFEp+62, 0x7FFFFFFFFFFFFFFF);
60 test__fixsfdi(0x1.FFFFFFFFFFFFFp+62, 0x7FFFFFFFFFFFFFFF);60 try test__fixsfdi(0x1.FFFFFFFFFFFFFp+62, 0x7FFFFFFFFFFFFFFF);
61 test__fixsfdi(0x1.0000000000000p+63, 0x7FFFFFFFFFFFFFFF);61 try test__fixsfdi(0x1.0000000000000p+63, 0x7FFFFFFFFFFFFFFF);
62 test__fixsfdi(0x1.0000000000001p+63, 0x7FFFFFFFFFFFFFFF);62 try test__fixsfdi(0x1.0000000000001p+63, 0x7FFFFFFFFFFFFFFF);
6363
64 test__fixsfdi(0x1.FFFFFFFFFFFFEp+126, 0x7FFFFFFFFFFFFFFF);64 try test__fixsfdi(0x1.FFFFFFFFFFFFEp+126, 0x7FFFFFFFFFFFFFFF);
65 test__fixsfdi(0x1.FFFFFFFFFFFFFp+126, 0x7FFFFFFFFFFFFFFF);65 try test__fixsfdi(0x1.FFFFFFFFFFFFFp+126, 0x7FFFFFFFFFFFFFFF);
66 test__fixsfdi(0x1.0000000000000p+127, 0x7FFFFFFFFFFFFFFF);66 try test__fixsfdi(0x1.0000000000000p+127, 0x7FFFFFFFFFFFFFFF);
6767
68 test__fixsfdi(0x1.FFFFFFFFFFFFFp+1023, 0x7FFFFFFFFFFFFFFF);68 try test__fixsfdi(0x1.FFFFFFFFFFFFFp+1023, 0x7FFFFFFFFFFFFFFF);
69 test__fixsfdi(0x1.FFFFFFFFFFFFFp+1023, math.maxInt(i64));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));
72}72}
lib/std/special/compiler_rt/fixsfsi_test.zig+50-50
...@@ -9,72 +9,72 @@ const math = std.math;...@@ -9,72 +9,72 @@ const math = std.math;
9const testing = std.testing;9const testing = std.testing;
10const warn = std.debug.warn;10const warn = std.debug.warn;
1111
12fn test__fixsfsi(a: f32, expected: i32) void {12fn test__fixsfsi(a: f32, expected: i32) !void {
13 const x = __fixsfsi(a);13 const x = __fixsfsi(a);
14 //warn("a={}:{x} x={}:{x} expected={}:{x}:@as(u32, {x})\n", .{a, @bitCast(u32, a), x, x, expected, expected, @bitCast(u32, expected)});14 //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);
16}16}
1717
18test "fixsfsi" {18test "fixsfsi" {
19 //warn("\n", .{});19 //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));22 try test__fixsfsi(-0x1.FFFFFFFFFFFFFp+1023, math.minInt(i32));
23 test__fixsfsi(-0x1.FFFFFFFFFFFFFp+1023, -0x80000000);23 try test__fixsfsi(-0x1.FFFFFFFFFFFFFp+1023, -0x80000000);
2424
25 test__fixsfsi(-0x1.0000000000000p+127, -0x80000000);25 try test__fixsfsi(-0x1.0000000000000p+127, -0x80000000);
26 test__fixsfsi(-0x1.FFFFFFFFFFFFFp+126, -0x80000000);26 try test__fixsfsi(-0x1.FFFFFFFFFFFFFp+126, -0x80000000);
27 test__fixsfsi(-0x1.FFFFFFFFFFFFEp+126, -0x80000000);27 try test__fixsfsi(-0x1.FFFFFFFFFFFFEp+126, -0x80000000);
2828
29 test__fixsfsi(-0x1.0000000000001p+63, -0x80000000);29 try test__fixsfsi(-0x1.0000000000001p+63, -0x80000000);
30 test__fixsfsi(-0x1.0000000000000p+63, -0x80000000);30 try test__fixsfsi(-0x1.0000000000000p+63, -0x80000000);
31 test__fixsfsi(-0x1.FFFFFFFFFFFFFp+62, -0x80000000);31 try test__fixsfsi(-0x1.FFFFFFFFFFFFFp+62, -0x80000000);
32 test__fixsfsi(-0x1.FFFFFFFFFFFFEp+62, -0x80000000);32 try test__fixsfsi(-0x1.FFFFFFFFFFFFEp+62, -0x80000000);
3333
34 test__fixsfsi(-0x1.FFFFFEp+62, -0x80000000);34 try test__fixsfsi(-0x1.FFFFFEp+62, -0x80000000);
35 test__fixsfsi(-0x1.FFFFFCp+62, -0x80000000);35 try test__fixsfsi(-0x1.FFFFFCp+62, -0x80000000);
3636
37 test__fixsfsi(-0x1.000000p+31, -0x80000000);37 try test__fixsfsi(-0x1.000000p+31, -0x80000000);
38 test__fixsfsi(-0x1.FFFFFFp+30, -0x80000000);38 try test__fixsfsi(-0x1.FFFFFFp+30, -0x80000000);
39 test__fixsfsi(-0x1.FFFFFEp+30, -0x7FFFFF80);39 try test__fixsfsi(-0x1.FFFFFEp+30, -0x7FFFFF80);
40 test__fixsfsi(-0x1.FFFFFCp+30, -0x7FFFFF00);40 try test__fixsfsi(-0x1.FFFFFCp+30, -0x7FFFFF00);
4141
42 test__fixsfsi(-2.01, -2);42 try test__fixsfsi(-2.01, -2);
43 test__fixsfsi(-2.0, -2);43 try test__fixsfsi(-2.0, -2);
44 test__fixsfsi(-1.99, -1);44 try test__fixsfsi(-1.99, -1);
45 test__fixsfsi(-1.0, -1);45 try test__fixsfsi(-1.0, -1);
46 test__fixsfsi(-0.99, 0);46 try test__fixsfsi(-0.99, 0);
47 test__fixsfsi(-0.5, 0);47 try test__fixsfsi(-0.5, 0);
48 test__fixsfsi(-math.f32_min, 0);48 try test__fixsfsi(-math.f32_min, 0);
49 test__fixsfsi(0.0, 0);49 try test__fixsfsi(0.0, 0);
50 test__fixsfsi(math.f32_min, 0);50 try test__fixsfsi(math.f32_min, 0);
51 test__fixsfsi(0.5, 0);51 try test__fixsfsi(0.5, 0);
52 test__fixsfsi(0.99, 0);52 try test__fixsfsi(0.99, 0);
53 test__fixsfsi(1.0, 1);53 try test__fixsfsi(1.0, 1);
54 test__fixsfsi(1.5, 1);54 try test__fixsfsi(1.5, 1);
55 test__fixsfsi(1.99, 1);55 try test__fixsfsi(1.99, 1);
56 test__fixsfsi(2.0, 2);56 try test__fixsfsi(2.0, 2);
57 test__fixsfsi(2.01, 2);57 try test__fixsfsi(2.01, 2);
5858
59 test__fixsfsi(0x1.FFFFFCp+30, 0x7FFFFF00);59 try test__fixsfsi(0x1.FFFFFCp+30, 0x7FFFFF00);
60 test__fixsfsi(0x1.FFFFFEp+30, 0x7FFFFF80);60 try test__fixsfsi(0x1.FFFFFEp+30, 0x7FFFFF80);
61 test__fixsfsi(0x1.FFFFFFp+30, 0x7FFFFFFF);61 try test__fixsfsi(0x1.FFFFFFp+30, 0x7FFFFFFF);
62 test__fixsfsi(0x1.000000p+31, 0x7FFFFFFF);62 try test__fixsfsi(0x1.000000p+31, 0x7FFFFFFF);
6363
64 test__fixsfsi(0x1.FFFFFCp+62, 0x7FFFFFFF);64 try test__fixsfsi(0x1.FFFFFCp+62, 0x7FFFFFFF);
65 test__fixsfsi(0x1.FFFFFEp+62, 0x7FFFFFFF);65 try test__fixsfsi(0x1.FFFFFEp+62, 0x7FFFFFFF);
6666
67 test__fixsfsi(0x1.FFFFFFFFFFFFEp+62, 0x7FFFFFFF);67 try test__fixsfsi(0x1.FFFFFFFFFFFFEp+62, 0x7FFFFFFF);
68 test__fixsfsi(0x1.FFFFFFFFFFFFFp+62, 0x7FFFFFFF);68 try test__fixsfsi(0x1.FFFFFFFFFFFFFp+62, 0x7FFFFFFF);
69 test__fixsfsi(0x1.0000000000000p+63, 0x7FFFFFFF);69 try test__fixsfsi(0x1.0000000000000p+63, 0x7FFFFFFF);
70 test__fixsfsi(0x1.0000000000001p+63, 0x7FFFFFFF);70 try test__fixsfsi(0x1.0000000000001p+63, 0x7FFFFFFF);
7171
72 test__fixsfsi(0x1.FFFFFFFFFFFFEp+126, 0x7FFFFFFF);72 try test__fixsfsi(0x1.FFFFFFFFFFFFEp+126, 0x7FFFFFFF);
73 test__fixsfsi(0x1.FFFFFFFFFFFFFp+126, 0x7FFFFFFF);73 try test__fixsfsi(0x1.FFFFFFFFFFFFFp+126, 0x7FFFFFFF);
74 test__fixsfsi(0x1.0000000000000p+127, 0x7FFFFFFF);74 try test__fixsfsi(0x1.0000000000000p+127, 0x7FFFFFFF);
7575
76 test__fixsfsi(0x1.FFFFFFFFFFFFFp+1023, 0x7FFFFFFF);76 try test__fixsfsi(0x1.FFFFFFFFFFFFFp+1023, 0x7FFFFFFF);
77 test__fixsfsi(0x1.FFFFFFFFFFFFFp+1023, math.maxInt(i32));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));
80}80}
lib/std/special/compiler_rt/fixsfti_test.zig+58-58
...@@ -9,80 +9,80 @@ const math = std.math;...@@ -9,80 +9,80 @@ const math = std.math;
9const testing = std.testing;9const testing = std.testing;
10const warn = std.debug.warn;10const warn = std.debug.warn;
1111
12fn test__fixsfti(a: f32, expected: i128) void {12fn test__fixsfti(a: f32, expected: i128) !void {
13 const x = __fixsfti(a);13 const x = __fixsfti(a);
14 //warn("a={}:{x} x={}:{x} expected={}:{x}:@as(u128, {x})\n", .{a, @bitCast(u32, a), x, x, expected, expected, @bitCast(u128, expected)});14 //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);
16}16}
1717
18test "fixsfti" {18test "fixsfti" {
19 //warn("\n", .{});19 //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));22 try test__fixsfti(-0x1.FFFFFFFFFFFFFp+1023, math.minInt(i128));
23 test__fixsfti(-0x1.FFFFFFFFFFFFFp+1023, -0x80000000000000000000000000000000);23 try test__fixsfti(-0x1.FFFFFFFFFFFFFp+1023, -0x80000000000000000000000000000000);
2424
25 test__fixsfti(-0x1.0000000000000p+127, -0x80000000000000000000000000000000);25 try test__fixsfti(-0x1.0000000000000p+127, -0x80000000000000000000000000000000);
26 test__fixsfti(-0x1.FFFFFFFFFFFFFp+126, -0x80000000000000000000000000000000);26 try test__fixsfti(-0x1.FFFFFFFFFFFFFp+126, -0x80000000000000000000000000000000);
27 test__fixsfti(-0x1.FFFFFFFFFFFFEp+126, -0x80000000000000000000000000000000);27 try test__fixsfti(-0x1.FFFFFFFFFFFFEp+126, -0x80000000000000000000000000000000);
28 test__fixsfti(-0x1.FFFFFF0000000p+126, -0x80000000000000000000000000000000);28 try test__fixsfti(-0x1.FFFFFF0000000p+126, -0x80000000000000000000000000000000);
29 test__fixsfti(-0x1.FFFFFE0000000p+126, -0x7FFFFF80000000000000000000000000);29 try test__fixsfti(-0x1.FFFFFE0000000p+126, -0x7FFFFF80000000000000000000000000);
30 test__fixsfti(-0x1.FFFFFC0000000p+126, -0x7FFFFF00000000000000000000000000);30 try test__fixsfti(-0x1.FFFFFC0000000p+126, -0x7FFFFF00000000000000000000000000);
3131
32 test__fixsfti(-0x1.0000000000001p+63, -0x8000000000000000);32 try test__fixsfti(-0x1.0000000000001p+63, -0x8000000000000000);
33 test__fixsfti(-0x1.0000000000000p+63, -0x8000000000000000);33 try test__fixsfti(-0x1.0000000000000p+63, -0x8000000000000000);
34 test__fixsfti(-0x1.FFFFFFFFFFFFFp+62, -0x8000000000000000);34 try test__fixsfti(-0x1.FFFFFFFFFFFFFp+62, -0x8000000000000000);
35 test__fixsfti(-0x1.FFFFFFFFFFFFEp+62, -0x8000000000000000);35 try test__fixsfti(-0x1.FFFFFFFFFFFFEp+62, -0x8000000000000000);
3636
37 test__fixsfti(-0x1.FFFFFFp+62, -0x8000000000000000);37 try test__fixsfti(-0x1.FFFFFFp+62, -0x8000000000000000);
38 test__fixsfti(-0x1.FFFFFEp+62, -0x7fffff8000000000);38 try test__fixsfti(-0x1.FFFFFEp+62, -0x7fffff8000000000);
39 test__fixsfti(-0x1.FFFFFCp+62, -0x7fffff0000000000);39 try test__fixsfti(-0x1.FFFFFCp+62, -0x7fffff0000000000);
4040
41 test__fixsfti(-0x1.000000p+31, -0x80000000);41 try test__fixsfti(-0x1.000000p+31, -0x80000000);
42 test__fixsfti(-0x1.FFFFFFp+30, -0x80000000);42 try test__fixsfti(-0x1.FFFFFFp+30, -0x80000000);
43 test__fixsfti(-0x1.FFFFFEp+30, -0x7FFFFF80);43 try test__fixsfti(-0x1.FFFFFEp+30, -0x7FFFFF80);
44 test__fixsfti(-0x1.FFFFFCp+30, -0x7FFFFF00);44 try test__fixsfti(-0x1.FFFFFCp+30, -0x7FFFFF00);
4545
46 test__fixsfti(-2.01, -2);46 try test__fixsfti(-2.01, -2);
47 test__fixsfti(-2.0, -2);47 try test__fixsfti(-2.0, -2);
48 test__fixsfti(-1.99, -1);48 try test__fixsfti(-1.99, -1);
49 test__fixsfti(-1.0, -1);49 try test__fixsfti(-1.0, -1);
50 test__fixsfti(-0.99, 0);50 try test__fixsfti(-0.99, 0);
51 test__fixsfti(-0.5, 0);51 try test__fixsfti(-0.5, 0);
52 test__fixsfti(-math.f32_min, 0);52 try test__fixsfti(-math.f32_min, 0);
53 test__fixsfti(0.0, 0);53 try test__fixsfti(0.0, 0);
54 test__fixsfti(math.f32_min, 0);54 try test__fixsfti(math.f32_min, 0);
55 test__fixsfti(0.5, 0);55 try test__fixsfti(0.5, 0);
56 test__fixsfti(0.99, 0);56 try test__fixsfti(0.99, 0);
57 test__fixsfti(1.0, 1);57 try test__fixsfti(1.0, 1);
58 test__fixsfti(1.5, 1);58 try test__fixsfti(1.5, 1);
59 test__fixsfti(1.99, 1);59 try test__fixsfti(1.99, 1);
60 test__fixsfti(2.0, 2);60 try test__fixsfti(2.0, 2);
61 test__fixsfti(2.01, 2);61 try test__fixsfti(2.01, 2);
6262
63 test__fixsfti(0x1.FFFFFCp+30, 0x7FFFFF00);63 try test__fixsfti(0x1.FFFFFCp+30, 0x7FFFFF00);
64 test__fixsfti(0x1.FFFFFEp+30, 0x7FFFFF80);64 try test__fixsfti(0x1.FFFFFEp+30, 0x7FFFFF80);
65 test__fixsfti(0x1.FFFFFFp+30, 0x80000000);65 try test__fixsfti(0x1.FFFFFFp+30, 0x80000000);
66 test__fixsfti(0x1.000000p+31, 0x80000000);66 try test__fixsfti(0x1.000000p+31, 0x80000000);
6767
68 test__fixsfti(0x1.FFFFFCp+62, 0x7FFFFF0000000000);68 try test__fixsfti(0x1.FFFFFCp+62, 0x7FFFFF0000000000);
69 test__fixsfti(0x1.FFFFFEp+62, 0x7FFFFF8000000000);69 try test__fixsfti(0x1.FFFFFEp+62, 0x7FFFFF8000000000);
70 test__fixsfti(0x1.FFFFFFp+62, 0x8000000000000000);70 try test__fixsfti(0x1.FFFFFFp+62, 0x8000000000000000);
7171
72 test__fixsfti(0x1.FFFFFFFFFFFFEp+62, 0x8000000000000000);72 try test__fixsfti(0x1.FFFFFFFFFFFFEp+62, 0x8000000000000000);
73 test__fixsfti(0x1.FFFFFFFFFFFFFp+62, 0x8000000000000000);73 try test__fixsfti(0x1.FFFFFFFFFFFFFp+62, 0x8000000000000000);
74 test__fixsfti(0x1.0000000000000p+63, 0x8000000000000000);74 try test__fixsfti(0x1.0000000000000p+63, 0x8000000000000000);
75 test__fixsfti(0x1.0000000000001p+63, 0x8000000000000000);75 try test__fixsfti(0x1.0000000000001p+63, 0x8000000000000000);
7676
77 test__fixsfti(0x1.FFFFFC0000000p+126, 0x7FFFFF00000000000000000000000000);77 try test__fixsfti(0x1.FFFFFC0000000p+126, 0x7FFFFF00000000000000000000000000);
78 test__fixsfti(0x1.FFFFFE0000000p+126, 0x7FFFFF80000000000000000000000000);78 try test__fixsfti(0x1.FFFFFE0000000p+126, 0x7FFFFF80000000000000000000000000);
79 test__fixsfti(0x1.FFFFFF0000000p+126, 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF);79 try test__fixsfti(0x1.FFFFFF0000000p+126, 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF);
80 test__fixsfti(0x1.FFFFFFFFFFFFEp+126, 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF);80 try test__fixsfti(0x1.FFFFFFFFFFFFEp+126, 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF);
81 test__fixsfti(0x1.FFFFFFFFFFFFFp+126, 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF);81 try test__fixsfti(0x1.FFFFFFFFFFFFFp+126, 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF);
82 test__fixsfti(0x1.0000000000000p+127, 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF);82 try test__fixsfti(0x1.0000000000000p+127, 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF);
8383
84 test__fixsfti(0x1.FFFFFFFFFFFFFp+1023, 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF);84 try test__fixsfti(0x1.FFFFFFFFFFFFFp+1023, 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF);
85 test__fixsfti(0x1.FFFFFFFFFFFFFp+1023, math.maxInt(i128));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));
88}88}
lib/std/special/compiler_rt/fixtfdi_test.zig+50-50
...@@ -9,72 +9,72 @@ const math = std.math;...@@ -9,72 +9,72 @@ const math = std.math;
9const testing = std.testing;9const testing = std.testing;
10const warn = std.debug.warn;10const warn = std.debug.warn;
1111
12fn test__fixtfdi(a: f128, expected: i64) void {12fn test__fixtfdi(a: f128, expected: i64) !void {
13 const x = __fixtfdi(a);13 const x = __fixtfdi(a);
14 //warn("a={}:{x} x={}:{x} expected={}:{x}:@as(u64, {x})\n", .{a, @bitCast(u128, a), x, x, expected, expected, @bitCast(u64, expected)});14 //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);
16}16}
1717
18test "fixtfdi" {18test "fixtfdi" {
19 //warn("\n", .{});19 //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));22 try test__fixtfdi(-0x1.FFFFFFFFFFFFFp+1023, math.minInt(i64));
23 test__fixtfdi(-0x1.FFFFFFFFFFFFFp+1023, -0x8000000000000000);23 try test__fixtfdi(-0x1.FFFFFFFFFFFFFp+1023, -0x8000000000000000);
2424
25 test__fixtfdi(-0x1.0000000000000p+127, -0x8000000000000000);25 try test__fixtfdi(-0x1.0000000000000p+127, -0x8000000000000000);
26 test__fixtfdi(-0x1.FFFFFFFFFFFFFp+126, -0x8000000000000000);26 try test__fixtfdi(-0x1.FFFFFFFFFFFFFp+126, -0x8000000000000000);
27 test__fixtfdi(-0x1.FFFFFFFFFFFFEp+126, -0x8000000000000000);27 try test__fixtfdi(-0x1.FFFFFFFFFFFFEp+126, -0x8000000000000000);
2828
29 test__fixtfdi(-0x1.0000000000001p+63, -0x8000000000000000);29 try test__fixtfdi(-0x1.0000000000001p+63, -0x8000000000000000);
30 test__fixtfdi(-0x1.0000000000000p+63, -0x8000000000000000);30 try test__fixtfdi(-0x1.0000000000000p+63, -0x8000000000000000);
31 test__fixtfdi(-0x1.FFFFFFFFFFFFFp+62, -0x7FFFFFFFFFFFFC00);31 try test__fixtfdi(-0x1.FFFFFFFFFFFFFp+62, -0x7FFFFFFFFFFFFC00);
32 test__fixtfdi(-0x1.FFFFFFFFFFFFEp+62, -0x7FFFFFFFFFFFF800);32 try test__fixtfdi(-0x1.FFFFFFFFFFFFEp+62, -0x7FFFFFFFFFFFF800);
3333
34 test__fixtfdi(-0x1.FFFFFEp+62, -0x7FFFFF8000000000);34 try test__fixtfdi(-0x1.FFFFFEp+62, -0x7FFFFF8000000000);
35 test__fixtfdi(-0x1.FFFFFCp+62, -0x7FFFFF0000000000);35 try test__fixtfdi(-0x1.FFFFFCp+62, -0x7FFFFF0000000000);
3636
37 test__fixtfdi(-0x1.000000p+31, -0x80000000);37 try test__fixtfdi(-0x1.000000p+31, -0x80000000);
38 test__fixtfdi(-0x1.FFFFFFp+30, -0x7FFFFFC0);38 try test__fixtfdi(-0x1.FFFFFFp+30, -0x7FFFFFC0);
39 test__fixtfdi(-0x1.FFFFFEp+30, -0x7FFFFF80);39 try test__fixtfdi(-0x1.FFFFFEp+30, -0x7FFFFF80);
40 test__fixtfdi(-0x1.FFFFFCp+30, -0x7FFFFF00);40 try test__fixtfdi(-0x1.FFFFFCp+30, -0x7FFFFF00);
4141
42 test__fixtfdi(-2.01, -2);42 try test__fixtfdi(-2.01, -2);
43 test__fixtfdi(-2.0, -2);43 try test__fixtfdi(-2.0, -2);
44 test__fixtfdi(-1.99, -1);44 try test__fixtfdi(-1.99, -1);
45 test__fixtfdi(-1.0, -1);45 try test__fixtfdi(-1.0, -1);
46 test__fixtfdi(-0.99, 0);46 try test__fixtfdi(-0.99, 0);
47 test__fixtfdi(-0.5, 0);47 try test__fixtfdi(-0.5, 0);
48 test__fixtfdi(-math.f64_min, 0);48 try test__fixtfdi(-math.f64_min, 0);
49 test__fixtfdi(0.0, 0);49 try test__fixtfdi(0.0, 0);
50 test__fixtfdi(math.f64_min, 0);50 try test__fixtfdi(math.f64_min, 0);
51 test__fixtfdi(0.5, 0);51 try test__fixtfdi(0.5, 0);
52 test__fixtfdi(0.99, 0);52 try test__fixtfdi(0.99, 0);
53 test__fixtfdi(1.0, 1);53 try test__fixtfdi(1.0, 1);
54 test__fixtfdi(1.5, 1);54 try test__fixtfdi(1.5, 1);
55 test__fixtfdi(1.99, 1);55 try test__fixtfdi(1.99, 1);
56 test__fixtfdi(2.0, 2);56 try test__fixtfdi(2.0, 2);
57 test__fixtfdi(2.01, 2);57 try test__fixtfdi(2.01, 2);
5858
59 test__fixtfdi(0x1.FFFFFCp+30, 0x7FFFFF00);59 try test__fixtfdi(0x1.FFFFFCp+30, 0x7FFFFF00);
60 test__fixtfdi(0x1.FFFFFEp+30, 0x7FFFFF80);60 try test__fixtfdi(0x1.FFFFFEp+30, 0x7FFFFF80);
61 test__fixtfdi(0x1.FFFFFFp+30, 0x7FFFFFC0);61 try test__fixtfdi(0x1.FFFFFFp+30, 0x7FFFFFC0);
62 test__fixtfdi(0x1.000000p+31, 0x80000000);62 try test__fixtfdi(0x1.000000p+31, 0x80000000);
6363
64 test__fixtfdi(0x1.FFFFFCp+62, 0x7FFFFF0000000000);64 try test__fixtfdi(0x1.FFFFFCp+62, 0x7FFFFF0000000000);
65 test__fixtfdi(0x1.FFFFFEp+62, 0x7FFFFF8000000000);65 try test__fixtfdi(0x1.FFFFFEp+62, 0x7FFFFF8000000000);
6666
67 test__fixtfdi(0x1.FFFFFFFFFFFFEp+62, 0x7FFFFFFFFFFFF800);67 try test__fixtfdi(0x1.FFFFFFFFFFFFEp+62, 0x7FFFFFFFFFFFF800);
68 test__fixtfdi(0x1.FFFFFFFFFFFFFp+62, 0x7FFFFFFFFFFFFC00);68 try test__fixtfdi(0x1.FFFFFFFFFFFFFp+62, 0x7FFFFFFFFFFFFC00);
69 test__fixtfdi(0x1.0000000000000p+63, 0x7FFFFFFFFFFFFFFF);69 try test__fixtfdi(0x1.0000000000000p+63, 0x7FFFFFFFFFFFFFFF);
70 test__fixtfdi(0x1.0000000000001p+63, 0x7FFFFFFFFFFFFFFF);70 try test__fixtfdi(0x1.0000000000001p+63, 0x7FFFFFFFFFFFFFFF);
7171
72 test__fixtfdi(0x1.FFFFFFFFFFFFEp+126, 0x7FFFFFFFFFFFFFFF);72 try test__fixtfdi(0x1.FFFFFFFFFFFFEp+126, 0x7FFFFFFFFFFFFFFF);
73 test__fixtfdi(0x1.FFFFFFFFFFFFFp+126, 0x7FFFFFFFFFFFFFFF);73 try test__fixtfdi(0x1.FFFFFFFFFFFFFp+126, 0x7FFFFFFFFFFFFFFF);
74 test__fixtfdi(0x1.0000000000000p+127, 0x7FFFFFFFFFFFFFFF);74 try test__fixtfdi(0x1.0000000000000p+127, 0x7FFFFFFFFFFFFFFF);
7575
76 test__fixtfdi(0x1.FFFFFFFFFFFFFp+1023, 0x7FFFFFFFFFFFFFFF);76 try test__fixtfdi(0x1.FFFFFFFFFFFFFp+1023, 0x7FFFFFFFFFFFFFFF);
77 test__fixtfdi(0x1.FFFFFFFFFFFFFp+1023, math.maxInt(i64));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));
80}80}
lib/std/special/compiler_rt/fixtfsi_test.zig+50-50
...@@ -9,72 +9,72 @@ const math = std.math;...@@ -9,72 +9,72 @@ const math = std.math;
9const testing = std.testing;9const testing = std.testing;
10const warn = std.debug.warn;10const warn = std.debug.warn;
1111
12fn test__fixtfsi(a: f128, expected: i32) void {12fn test__fixtfsi(a: f128, expected: i32) !void {
13 const x = __fixtfsi(a);13 const x = __fixtfsi(a);
14 //warn("a={}:{x} x={}:{x} expected={}:{x}:@as(u32, {x})\n", .{a, @bitCast(u128, a), x, x, expected, expected, @bitCast(u32, expected)});14 //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);
16}16}
1717
18test "fixtfsi" {18test "fixtfsi" {
19 //warn("\n", .{});19 //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));22 try test__fixtfsi(-0x1.FFFFFFFFFFFFFp+1023, math.minInt(i32));
23 test__fixtfsi(-0x1.FFFFFFFFFFFFFp+1023, -0x80000000);23 try test__fixtfsi(-0x1.FFFFFFFFFFFFFp+1023, -0x80000000);
2424
25 test__fixtfsi(-0x1.0000000000000p+127, -0x80000000);25 try test__fixtfsi(-0x1.0000000000000p+127, -0x80000000);
26 test__fixtfsi(-0x1.FFFFFFFFFFFFFp+126, -0x80000000);26 try test__fixtfsi(-0x1.FFFFFFFFFFFFFp+126, -0x80000000);
27 test__fixtfsi(-0x1.FFFFFFFFFFFFEp+126, -0x80000000);27 try test__fixtfsi(-0x1.FFFFFFFFFFFFEp+126, -0x80000000);
2828
29 test__fixtfsi(-0x1.0000000000001p+63, -0x80000000);29 try test__fixtfsi(-0x1.0000000000001p+63, -0x80000000);
30 test__fixtfsi(-0x1.0000000000000p+63, -0x80000000);30 try test__fixtfsi(-0x1.0000000000000p+63, -0x80000000);
31 test__fixtfsi(-0x1.FFFFFFFFFFFFFp+62, -0x80000000);31 try test__fixtfsi(-0x1.FFFFFFFFFFFFFp+62, -0x80000000);
32 test__fixtfsi(-0x1.FFFFFFFFFFFFEp+62, -0x80000000);32 try test__fixtfsi(-0x1.FFFFFFFFFFFFEp+62, -0x80000000);
3333
34 test__fixtfsi(-0x1.FFFFFEp+62, -0x80000000);34 try test__fixtfsi(-0x1.FFFFFEp+62, -0x80000000);
35 test__fixtfsi(-0x1.FFFFFCp+62, -0x80000000);35 try test__fixtfsi(-0x1.FFFFFCp+62, -0x80000000);
3636
37 test__fixtfsi(-0x1.000000p+31, -0x80000000);37 try test__fixtfsi(-0x1.000000p+31, -0x80000000);
38 test__fixtfsi(-0x1.FFFFFFp+30, -0x7FFFFFC0);38 try test__fixtfsi(-0x1.FFFFFFp+30, -0x7FFFFFC0);
39 test__fixtfsi(-0x1.FFFFFEp+30, -0x7FFFFF80);39 try test__fixtfsi(-0x1.FFFFFEp+30, -0x7FFFFF80);
40 test__fixtfsi(-0x1.FFFFFCp+30, -0x7FFFFF00);40 try test__fixtfsi(-0x1.FFFFFCp+30, -0x7FFFFF00);
4141
42 test__fixtfsi(-2.01, -2);42 try test__fixtfsi(-2.01, -2);
43 test__fixtfsi(-2.0, -2);43 try test__fixtfsi(-2.0, -2);
44 test__fixtfsi(-1.99, -1);44 try test__fixtfsi(-1.99, -1);
45 test__fixtfsi(-1.0, -1);45 try test__fixtfsi(-1.0, -1);
46 test__fixtfsi(-0.99, 0);46 try test__fixtfsi(-0.99, 0);
47 test__fixtfsi(-0.5, 0);47 try test__fixtfsi(-0.5, 0);
48 test__fixtfsi(-math.f32_min, 0);48 try test__fixtfsi(-math.f32_min, 0);
49 test__fixtfsi(0.0, 0);49 try test__fixtfsi(0.0, 0);
50 test__fixtfsi(math.f32_min, 0);50 try test__fixtfsi(math.f32_min, 0);
51 test__fixtfsi(0.5, 0);51 try test__fixtfsi(0.5, 0);
52 test__fixtfsi(0.99, 0);52 try test__fixtfsi(0.99, 0);
53 test__fixtfsi(1.0, 1);53 try test__fixtfsi(1.0, 1);
54 test__fixtfsi(1.5, 1);54 try test__fixtfsi(1.5, 1);
55 test__fixtfsi(1.99, 1);55 try test__fixtfsi(1.99, 1);
56 test__fixtfsi(2.0, 2);56 try test__fixtfsi(2.0, 2);
57 test__fixtfsi(2.01, 2);57 try test__fixtfsi(2.01, 2);
5858
59 test__fixtfsi(0x1.FFFFFCp+30, 0x7FFFFF00);59 try test__fixtfsi(0x1.FFFFFCp+30, 0x7FFFFF00);
60 test__fixtfsi(0x1.FFFFFEp+30, 0x7FFFFF80);60 try test__fixtfsi(0x1.FFFFFEp+30, 0x7FFFFF80);
61 test__fixtfsi(0x1.FFFFFFp+30, 0x7FFFFFC0);61 try test__fixtfsi(0x1.FFFFFFp+30, 0x7FFFFFC0);
62 test__fixtfsi(0x1.000000p+31, 0x7FFFFFFF);62 try test__fixtfsi(0x1.000000p+31, 0x7FFFFFFF);
6363
64 test__fixtfsi(0x1.FFFFFCp+62, 0x7FFFFFFF);64 try test__fixtfsi(0x1.FFFFFCp+62, 0x7FFFFFFF);
65 test__fixtfsi(0x1.FFFFFEp+62, 0x7FFFFFFF);65 try test__fixtfsi(0x1.FFFFFEp+62, 0x7FFFFFFF);
6666
67 test__fixtfsi(0x1.FFFFFFFFFFFFEp+62, 0x7FFFFFFF);67 try test__fixtfsi(0x1.FFFFFFFFFFFFEp+62, 0x7FFFFFFF);
68 test__fixtfsi(0x1.FFFFFFFFFFFFFp+62, 0x7FFFFFFF);68 try test__fixtfsi(0x1.FFFFFFFFFFFFFp+62, 0x7FFFFFFF);
69 test__fixtfsi(0x1.0000000000000p+63, 0x7FFFFFFF);69 try test__fixtfsi(0x1.0000000000000p+63, 0x7FFFFFFF);
70 test__fixtfsi(0x1.0000000000001p+63, 0x7FFFFFFF);70 try test__fixtfsi(0x1.0000000000001p+63, 0x7FFFFFFF);
7171
72 test__fixtfsi(0x1.FFFFFFFFFFFFEp+126, 0x7FFFFFFF);72 try test__fixtfsi(0x1.FFFFFFFFFFFFEp+126, 0x7FFFFFFF);
73 test__fixtfsi(0x1.FFFFFFFFFFFFFp+126, 0x7FFFFFFF);73 try test__fixtfsi(0x1.FFFFFFFFFFFFFp+126, 0x7FFFFFFF);
74 test__fixtfsi(0x1.0000000000000p+127, 0x7FFFFFFF);74 try test__fixtfsi(0x1.0000000000000p+127, 0x7FFFFFFF);
7575
76 test__fixtfsi(0x1.FFFFFFFFFFFFFp+1023, 0x7FFFFFFF);76 try test__fixtfsi(0x1.FFFFFFFFFFFFFp+1023, 0x7FFFFFFF);
77 test__fixtfsi(0x1.FFFFFFFFFFFFFp+1023, math.maxInt(i32));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));
80}80}
lib/std/special/compiler_rt/fixtfti_test.zig+42-42
...@@ -9,62 +9,62 @@ const math = std.math;...@@ -9,62 +9,62 @@ const math = std.math;
9const testing = std.testing;9const testing = std.testing;
10const warn = std.debug.warn;10const warn = std.debug.warn;
1111
12fn test__fixtfti(a: f128, expected: i128) void {12fn test__fixtfti(a: f128, expected: i128) !void {
13 const x = __fixtfti(a);13 const x = __fixtfti(a);
14 //warn("a={}:{x} x={}:{x} expected={}:{x}:@as(u128, {x})\n", .{a, @bitCast(u128, a), x, x, expected, expected, @bitCast(u128, expected)});14 //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);
16}16}
1717
18test "fixtfti" {18test "fixtfti" {
19 //warn("\n", .{});19 //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));22 try test__fixtfti(-0x1.FFFFFFFFFFFFFp+1023, math.minInt(i128));
23 test__fixtfti(-0x1.FFFFFFFFFFFFFp+1023, -0x80000000000000000000000000000000);23 try test__fixtfti(-0x1.FFFFFFFFFFFFFp+1023, -0x80000000000000000000000000000000);
2424
25 test__fixtfti(-0x1.0000000000000p+127, -0x80000000000000000000000000000000);25 try test__fixtfti(-0x1.0000000000000p+127, -0x80000000000000000000000000000000);
26 test__fixtfti(-0x1.FFFFFFFFFFFFFp+126, -0x7FFFFFFFFFFFFC000000000000000000);26 try test__fixtfti(-0x1.FFFFFFFFFFFFFp+126, -0x7FFFFFFFFFFFFC000000000000000000);
27 test__fixtfti(-0x1.FFFFFFFFFFFFEp+126, -0x7FFFFFFFFFFFF8000000000000000000);27 try test__fixtfti(-0x1.FFFFFFFFFFFFEp+126, -0x7FFFFFFFFFFFF8000000000000000000);
2828
29 test__fixtfti(-0x1.0000000000001p+63, -0x8000000000000800);29 try test__fixtfti(-0x1.0000000000001p+63, -0x8000000000000800);
30 test__fixtfti(-0x1.0000000000000p+63, -0x8000000000000000);30 try test__fixtfti(-0x1.0000000000000p+63, -0x8000000000000000);
31 test__fixtfti(-0x1.FFFFFFFFFFFFFp+62, -0x7FFFFFFFFFFFFC00);31 try test__fixtfti(-0x1.FFFFFFFFFFFFFp+62, -0x7FFFFFFFFFFFFC00);
32 test__fixtfti(-0x1.FFFFFFFFFFFFEp+62, -0x7FFFFFFFFFFFF800);32 try test__fixtfti(-0x1.FFFFFFFFFFFFEp+62, -0x7FFFFFFFFFFFF800);
3333
34 test__fixtfti(-0x1.FFFFFEp+62, -0x7fffff8000000000);34 try test__fixtfti(-0x1.FFFFFEp+62, -0x7fffff8000000000);
35 test__fixtfti(-0x1.FFFFFCp+62, -0x7fffff0000000000);35 try test__fixtfti(-0x1.FFFFFCp+62, -0x7fffff0000000000);
3636
37 test__fixtfti(-2.01, -2);37 try test__fixtfti(-2.01, -2);
38 test__fixtfti(-2.0, -2);38 try test__fixtfti(-2.0, -2);
39 test__fixtfti(-1.99, -1);39 try test__fixtfti(-1.99, -1);
40 test__fixtfti(-1.0, -1);40 try test__fixtfti(-1.0, -1);
41 test__fixtfti(-0.99, 0);41 try test__fixtfti(-0.99, 0);
42 test__fixtfti(-0.5, 0);42 try test__fixtfti(-0.5, 0);
43 test__fixtfti(-math.f128_min, 0);43 try test__fixtfti(-math.f128_min, 0);
44 test__fixtfti(0.0, 0);44 try test__fixtfti(0.0, 0);
45 test__fixtfti(math.f128_min, 0);45 try test__fixtfti(math.f128_min, 0);
46 test__fixtfti(0.5, 0);46 try test__fixtfti(0.5, 0);
47 test__fixtfti(0.99, 0);47 try test__fixtfti(0.99, 0);
48 test__fixtfti(1.0, 1);48 try test__fixtfti(1.0, 1);
49 test__fixtfti(1.5, 1);49 try test__fixtfti(1.5, 1);
50 test__fixtfti(1.99, 1);50 try test__fixtfti(1.99, 1);
51 test__fixtfti(2.0, 2);51 try test__fixtfti(2.0, 2);
52 test__fixtfti(2.01, 2);52 try test__fixtfti(2.01, 2);
5353
54 test__fixtfti(0x1.FFFFFCp+62, 0x7FFFFF0000000000);54 try test__fixtfti(0x1.FFFFFCp+62, 0x7FFFFF0000000000);
55 test__fixtfti(0x1.FFFFFEp+62, 0x7FFFFF8000000000);55 try test__fixtfti(0x1.FFFFFEp+62, 0x7FFFFF8000000000);
5656
57 test__fixtfti(0x1.FFFFFFFFFFFFEp+62, 0x7FFFFFFFFFFFF800);57 try test__fixtfti(0x1.FFFFFFFFFFFFEp+62, 0x7FFFFFFFFFFFF800);
58 test__fixtfti(0x1.FFFFFFFFFFFFFp+62, 0x7FFFFFFFFFFFFC00);58 try test__fixtfti(0x1.FFFFFFFFFFFFFp+62, 0x7FFFFFFFFFFFFC00);
59 test__fixtfti(0x1.0000000000000p+63, 0x8000000000000000);59 try test__fixtfti(0x1.0000000000000p+63, 0x8000000000000000);
60 test__fixtfti(0x1.0000000000001p+63, 0x8000000000000800);60 try test__fixtfti(0x1.0000000000001p+63, 0x8000000000000800);
6161
62 test__fixtfti(0x1.FFFFFFFFFFFFEp+126, 0x7FFFFFFFFFFFF8000000000000000000);62 try test__fixtfti(0x1.FFFFFFFFFFFFEp+126, 0x7FFFFFFFFFFFF8000000000000000000);
63 test__fixtfti(0x1.FFFFFFFFFFFFFp+126, 0x7FFFFFFFFFFFFC000000000000000000);63 try test__fixtfti(0x1.FFFFFFFFFFFFFp+126, 0x7FFFFFFFFFFFFC000000000000000000);
64 test__fixtfti(0x1.0000000000000p+127, 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF);64 try test__fixtfti(0x1.0000000000000p+127, 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF);
6565
66 test__fixtfti(0x1.FFFFFFFFFFFFFp+1023, 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF);66 try test__fixtfti(0x1.FFFFFFFFFFFFFp+1023, 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF);
67 test__fixtfti(0x1.FFFFFFFFFFFFFp+1023, math.maxInt(i128));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));
70}70}
lib/std/special/compiler_rt/fixunsdfdi_test.zig+24-24
...@@ -6,39 +6,39 @@...@@ -6,39 +6,39 @@
6const __fixunsdfdi = @import("fixunsdfdi.zig").__fixunsdfdi;6const __fixunsdfdi = @import("fixunsdfdi.zig").__fixunsdfdi;
7const testing = @import("std").testing;7const testing = @import("std").testing;
88
9fn test__fixunsdfdi(a: f64, expected: u64) void {9fn test__fixunsdfdi(a: f64, expected: u64) !void {
10 const x = __fixunsdfdi(a);10 const x = __fixunsdfdi(a);
11 testing.expect(x == expected);11 try testing.expect(x == expected);
12}12}
1313
14test "fixunsdfdi" {14test "fixunsdfdi" {
15 //test__fixunsdfdi(0.0, 0);15 //test__fixunsdfdi(0.0, 0);
16 //test__fixunsdfdi(0.5, 0);16 //test__fixunsdfdi(0.5, 0);
17 //test__fixunsdfdi(0.99, 0);17 //test__fixunsdfdi(0.99, 0);
18 test__fixunsdfdi(1.0, 1);18 try test__fixunsdfdi(1.0, 1);
19 test__fixunsdfdi(1.5, 1);19 try test__fixunsdfdi(1.5, 1);
20 test__fixunsdfdi(1.99, 1);20 try test__fixunsdfdi(1.99, 1);
21 test__fixunsdfdi(2.0, 2);21 try test__fixunsdfdi(2.0, 2);
22 test__fixunsdfdi(2.01, 2);22 try test__fixunsdfdi(2.01, 2);
23 test__fixunsdfdi(-0.5, 0);23 try test__fixunsdfdi(-0.5, 0);
24 test__fixunsdfdi(-0.99, 0);24 try test__fixunsdfdi(-0.99, 0);
25 test__fixunsdfdi(-1.0, 0);25 try test__fixunsdfdi(-1.0, 0);
26 test__fixunsdfdi(-1.5, 0);26 try test__fixunsdfdi(-1.5, 0);
27 test__fixunsdfdi(-1.99, 0);27 try test__fixunsdfdi(-1.99, 0);
28 test__fixunsdfdi(-2.0, 0);28 try test__fixunsdfdi(-2.0, 0);
29 test__fixunsdfdi(-2.01, 0);29 try test__fixunsdfdi(-2.01, 0);
3030
31 test__fixunsdfdi(0x1.FFFFFEp+62, 0x7FFFFF8000000000);31 try test__fixunsdfdi(0x1.FFFFFEp+62, 0x7FFFFF8000000000);
32 test__fixunsdfdi(0x1.FFFFFCp+62, 0x7FFFFF0000000000);32 try test__fixunsdfdi(0x1.FFFFFCp+62, 0x7FFFFF0000000000);
3333
34 test__fixunsdfdi(-0x1.FFFFFEp+62, 0);34 try test__fixunsdfdi(-0x1.FFFFFEp+62, 0);
35 test__fixunsdfdi(-0x1.FFFFFCp+62, 0);35 try test__fixunsdfdi(-0x1.FFFFFCp+62, 0);
3636
37 test__fixunsdfdi(0x1.FFFFFFFFFFFFFp+63, 0xFFFFFFFFFFFFF800);37 try test__fixunsdfdi(0x1.FFFFFFFFFFFFFp+63, 0xFFFFFFFFFFFFF800);
38 test__fixunsdfdi(0x1.0000000000000p+63, 0x8000000000000000);38 try test__fixunsdfdi(0x1.0000000000000p+63, 0x8000000000000000);
39 test__fixunsdfdi(0x1.FFFFFFFFFFFFFp+62, 0x7FFFFFFFFFFFFC00);39 try test__fixunsdfdi(0x1.FFFFFFFFFFFFFp+62, 0x7FFFFFFFFFFFFC00);
40 test__fixunsdfdi(0x1.FFFFFFFFFFFFEp+62, 0x7FFFFFFFFFFFF800);40 try test__fixunsdfdi(0x1.FFFFFFFFFFFFEp+62, 0x7FFFFFFFFFFFF800);
4141
42 test__fixunsdfdi(-0x1.FFFFFFFFFFFFFp+62, 0);42 try test__fixunsdfdi(-0x1.FFFFFFFFFFFFFp+62, 0);
43 test__fixunsdfdi(-0x1.FFFFFFFFFFFFEp+62, 0);43 try test__fixunsdfdi(-0x1.FFFFFFFFFFFFEp+62, 0);
44}44}
lib/std/special/compiler_rt/fixunsdfsi_test.zig+27-27
...@@ -6,39 +6,39 @@...@@ -6,39 +6,39 @@
6const __fixunsdfsi = @import("fixunsdfsi.zig").__fixunsdfsi;6const __fixunsdfsi = @import("fixunsdfsi.zig").__fixunsdfsi;
7const testing = @import("std").testing;7const testing = @import("std").testing;
88
9fn test__fixunsdfsi(a: f64, expected: u32) void {9fn test__fixunsdfsi(a: f64, expected: u32) !void {
10 const x = __fixunsdfsi(a);10 const x = __fixunsdfsi(a);
11 testing.expect(x == expected);11 try testing.expect(x == expected);
12}12}
1313
14test "fixunsdfsi" {14test "fixunsdfsi" {
15 test__fixunsdfsi(0.0, 0);15 try test__fixunsdfsi(0.0, 0);
1616
17 test__fixunsdfsi(0.5, 0);17 try test__fixunsdfsi(0.5, 0);
18 test__fixunsdfsi(0.99, 0);18 try test__fixunsdfsi(0.99, 0);
19 test__fixunsdfsi(1.0, 1);19 try test__fixunsdfsi(1.0, 1);
20 test__fixunsdfsi(1.5, 1);20 try test__fixunsdfsi(1.5, 1);
21 test__fixunsdfsi(1.99, 1);21 try test__fixunsdfsi(1.99, 1);
22 test__fixunsdfsi(2.0, 2);22 try test__fixunsdfsi(2.0, 2);
23 test__fixunsdfsi(2.01, 2);23 try test__fixunsdfsi(2.01, 2);
24 test__fixunsdfsi(-0.5, 0);24 try test__fixunsdfsi(-0.5, 0);
25 test__fixunsdfsi(-0.99, 0);25 try test__fixunsdfsi(-0.99, 0);
26 test__fixunsdfsi(-1.0, 0);26 try test__fixunsdfsi(-1.0, 0);
27 test__fixunsdfsi(-1.5, 0);27 try test__fixunsdfsi(-1.5, 0);
28 test__fixunsdfsi(-1.99, 0);28 try test__fixunsdfsi(-1.99, 0);
29 test__fixunsdfsi(-2.0, 0);29 try test__fixunsdfsi(-2.0, 0);
30 test__fixunsdfsi(-2.01, 0);30 try test__fixunsdfsi(-2.01, 0);
3131
32 test__fixunsdfsi(0x1.000000p+31, 0x80000000);32 try test__fixunsdfsi(0x1.000000p+31, 0x80000000);
33 test__fixunsdfsi(0x1.000000p+32, 0xFFFFFFFF);33 try test__fixunsdfsi(0x1.000000p+32, 0xFFFFFFFF);
34 test__fixunsdfsi(0x1.FFFFFEp+31, 0xFFFFFF00);34 try test__fixunsdfsi(0x1.FFFFFEp+31, 0xFFFFFF00);
35 test__fixunsdfsi(0x1.FFFFFEp+30, 0x7FFFFF80);35 try test__fixunsdfsi(0x1.FFFFFEp+30, 0x7FFFFF80);
36 test__fixunsdfsi(0x1.FFFFFCp+30, 0x7FFFFF00);36 try test__fixunsdfsi(0x1.FFFFFCp+30, 0x7FFFFF00);
3737
38 test__fixunsdfsi(-0x1.FFFFFEp+30, 0);38 try test__fixunsdfsi(-0x1.FFFFFEp+30, 0);
39 test__fixunsdfsi(-0x1.FFFFFCp+30, 0);39 try test__fixunsdfsi(-0x1.FFFFFCp+30, 0);
4040
41 test__fixunsdfsi(0x1.FFFFFFFEp+31, 0xFFFFFFFF);41 try test__fixunsdfsi(0x1.FFFFFFFEp+31, 0xFFFFFFFF);
42 test__fixunsdfsi(0x1.FFFFFFFC00000p+30, 0x7FFFFFFF);42 try test__fixunsdfsi(0x1.FFFFFFFC00000p+30, 0x7FFFFFFF);
43 test__fixunsdfsi(0x1.FFFFFFF800000p+30, 0x7FFFFFFE);43 try test__fixunsdfsi(0x1.FFFFFFF800000p+30, 0x7FFFFFFE);
44}44}
lib/std/special/compiler_rt/fixunsdfti_test.zig+38-38
...@@ -6,46 +6,46 @@...@@ -6,46 +6,46 @@
6const __fixunsdfti = @import("fixunsdfti.zig").__fixunsdfti;6const __fixunsdfti = @import("fixunsdfti.zig").__fixunsdfti;
7const testing = @import("std").testing;7const testing = @import("std").testing;
88
9fn test__fixunsdfti(a: f64, expected: u128) void {9fn test__fixunsdfti(a: f64, expected: u128) !void {
10 const x = __fixunsdfti(a);10 const x = __fixunsdfti(a);
11 testing.expect(x == expected);11 try testing.expect(x == expected);
12}12}
1313
14test "fixunsdfti" {14test "fixunsdfti" {
15 test__fixunsdfti(0.0, 0);15 try test__fixunsdfti(0.0, 0);
1616
17 test__fixunsdfti(0.5, 0);17 try test__fixunsdfti(0.5, 0);
18 test__fixunsdfti(0.99, 0);18 try test__fixunsdfti(0.99, 0);
19 test__fixunsdfti(1.0, 1);19 try test__fixunsdfti(1.0, 1);
20 test__fixunsdfti(1.5, 1);20 try test__fixunsdfti(1.5, 1);
21 test__fixunsdfti(1.99, 1);21 try test__fixunsdfti(1.99, 1);
22 test__fixunsdfti(2.0, 2);22 try test__fixunsdfti(2.0, 2);
23 test__fixunsdfti(2.01, 2);23 try test__fixunsdfti(2.01, 2);
24 test__fixunsdfti(-0.5, 0);24 try test__fixunsdfti(-0.5, 0);
25 test__fixunsdfti(-0.99, 0);25 try test__fixunsdfti(-0.99, 0);
26 test__fixunsdfti(-1.0, 0);26 try test__fixunsdfti(-1.0, 0);
27 test__fixunsdfti(-1.5, 0);27 try test__fixunsdfti(-1.5, 0);
28 test__fixunsdfti(-1.99, 0);28 try test__fixunsdfti(-1.99, 0);
29 test__fixunsdfti(-2.0, 0);29 try test__fixunsdfti(-2.0, 0);
30 test__fixunsdfti(-2.01, 0);30 try test__fixunsdfti(-2.01, 0);
3131
32 test__fixunsdfti(0x1.FFFFFEp+62, 0x7FFFFF8000000000);32 try test__fixunsdfti(0x1.FFFFFEp+62, 0x7FFFFF8000000000);
33 test__fixunsdfti(0x1.FFFFFCp+62, 0x7FFFFF0000000000);33 try test__fixunsdfti(0x1.FFFFFCp+62, 0x7FFFFF0000000000);
3434
35 test__fixunsdfti(-0x1.FFFFFEp+62, 0);35 try test__fixunsdfti(-0x1.FFFFFEp+62, 0);
36 test__fixunsdfti(-0x1.FFFFFCp+62, 0);36 try test__fixunsdfti(-0x1.FFFFFCp+62, 0);
3737
38 test__fixunsdfti(0x1.FFFFFFFFFFFFFp+63, 0xFFFFFFFFFFFFF800);38 try test__fixunsdfti(0x1.FFFFFFFFFFFFFp+63, 0xFFFFFFFFFFFFF800);
39 test__fixunsdfti(0x1.0000000000000p+63, 0x8000000000000000);39 try test__fixunsdfti(0x1.0000000000000p+63, 0x8000000000000000);
40 test__fixunsdfti(0x1.FFFFFFFFFFFFFp+62, 0x7FFFFFFFFFFFFC00);40 try test__fixunsdfti(0x1.FFFFFFFFFFFFFp+62, 0x7FFFFFFFFFFFFC00);
41 test__fixunsdfti(0x1.FFFFFFFFFFFFEp+62, 0x7FFFFFFFFFFFF800);41 try test__fixunsdfti(0x1.FFFFFFFFFFFFEp+62, 0x7FFFFFFFFFFFF800);
4242
43 test__fixunsdfti(0x1.FFFFFFFFFFFFFp+127, 0xFFFFFFFFFFFFF8000000000000000000);43 try test__fixunsdfti(0x1.FFFFFFFFFFFFFp+127, 0xFFFFFFFFFFFFF8000000000000000000);
44 test__fixunsdfti(0x1.0000000000000p+127, 0x80000000000000000000000000000000);44 try test__fixunsdfti(0x1.0000000000000p+127, 0x80000000000000000000000000000000);
45 test__fixunsdfti(0x1.FFFFFFFFFFFFFp+126, 0x7FFFFFFFFFFFFC000000000000000000);45 try test__fixunsdfti(0x1.FFFFFFFFFFFFFp+126, 0x7FFFFFFFFFFFFC000000000000000000);
46 test__fixunsdfti(0x1.FFFFFFFFFFFFEp+126, 0x7FFFFFFFFFFFF8000000000000000000);46 try test__fixunsdfti(0x1.FFFFFFFFFFFFEp+126, 0x7FFFFFFFFFFFF8000000000000000000);
47 test__fixunsdfti(0x1.0000000000000p+128, 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF);47 try test__fixunsdfti(0x1.0000000000000p+128, 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF);
4848
49 test__fixunsdfti(-0x1.FFFFFFFFFFFFFp+62, 0);49 try test__fixunsdfti(-0x1.FFFFFFFFFFFFFp+62, 0);
50 test__fixunsdfti(-0x1.FFFFFFFFFFFFEp+62, 0);50 try test__fixunsdfti(-0x1.FFFFFFFFFFFFEp+62, 0);
51}51}
lib/std/special/compiler_rt/fixunssfdi_test.zig+23-23
...@@ -6,35 +6,35 @@...@@ -6,35 +6,35 @@
6const __fixunssfdi = @import("fixunssfdi.zig").__fixunssfdi;6const __fixunssfdi = @import("fixunssfdi.zig").__fixunssfdi;
7const testing = @import("std").testing;7const testing = @import("std").testing;
88
9fn test__fixunssfdi(a: f32, expected: u64) void {9fn test__fixunssfdi(a: f32, expected: u64) !void {
10 const x = __fixunssfdi(a);10 const x = __fixunssfdi(a);
11 testing.expect(x == expected);11 try testing.expect(x == expected);
12}12}
1313
14test "fixunssfdi" {14test "fixunssfdi" {
15 test__fixunssfdi(0.0, 0);15 try test__fixunssfdi(0.0, 0);
1616
17 test__fixunssfdi(0.5, 0);17 try test__fixunssfdi(0.5, 0);
18 test__fixunssfdi(0.99, 0);18 try test__fixunssfdi(0.99, 0);
19 test__fixunssfdi(1.0, 1);19 try test__fixunssfdi(1.0, 1);
20 test__fixunssfdi(1.5, 1);20 try test__fixunssfdi(1.5, 1);
21 test__fixunssfdi(1.99, 1);21 try test__fixunssfdi(1.99, 1);
22 test__fixunssfdi(2.0, 2);22 try test__fixunssfdi(2.0, 2);
23 test__fixunssfdi(2.01, 2);23 try test__fixunssfdi(2.01, 2);
24 test__fixunssfdi(-0.5, 0);24 try test__fixunssfdi(-0.5, 0);
25 test__fixunssfdi(-0.99, 0);25 try test__fixunssfdi(-0.99, 0);
2626
27 test__fixunssfdi(-1.0, 0);27 try test__fixunssfdi(-1.0, 0);
28 test__fixunssfdi(-1.5, 0);28 try test__fixunssfdi(-1.5, 0);
29 test__fixunssfdi(-1.99, 0);29 try test__fixunssfdi(-1.99, 0);
30 test__fixunssfdi(-2.0, 0);30 try test__fixunssfdi(-2.0, 0);
31 test__fixunssfdi(-2.01, 0);31 try test__fixunssfdi(-2.01, 0);
3232
33 test__fixunssfdi(0x1.FFFFFEp+63, 0xFFFFFF0000000000);33 try test__fixunssfdi(0x1.FFFFFEp+63, 0xFFFFFF0000000000);
34 test__fixunssfdi(0x1.000000p+63, 0x8000000000000000);34 try test__fixunssfdi(0x1.000000p+63, 0x8000000000000000);
35 test__fixunssfdi(0x1.FFFFFEp+62, 0x7FFFFF8000000000);35 try test__fixunssfdi(0x1.FFFFFEp+62, 0x7FFFFF8000000000);
36 test__fixunssfdi(0x1.FFFFFCp+62, 0x7FFFFF0000000000);36 try test__fixunssfdi(0x1.FFFFFCp+62, 0x7FFFFF0000000000);
3737
38 test__fixunssfdi(-0x1.FFFFFEp+62, 0x0000000000000000);38 try test__fixunssfdi(-0x1.FFFFFEp+62, 0x0000000000000000);
39 test__fixunssfdi(-0x1.FFFFFCp+62, 0x0000000000000000);39 try test__fixunssfdi(-0x1.FFFFFCp+62, 0x0000000000000000);
40}40}
lib/std/special/compiler_rt/fixunssfsi_test.zig+24-24
...@@ -6,36 +6,36 @@...@@ -6,36 +6,36 @@
6const __fixunssfsi = @import("fixunssfsi.zig").__fixunssfsi;6const __fixunssfsi = @import("fixunssfsi.zig").__fixunssfsi;
7const testing = @import("std").testing;7const testing = @import("std").testing;
88
9fn test__fixunssfsi(a: f32, expected: u32) void {9fn test__fixunssfsi(a: f32, expected: u32) !void {
10 const x = __fixunssfsi(a);10 const x = __fixunssfsi(a);
11 testing.expect(x == expected);11 try testing.expect(x == expected);
12}12}
1313
14test "fixunssfsi" {14test "fixunssfsi" {
15 test__fixunssfsi(0.0, 0);15 try test__fixunssfsi(0.0, 0);
1616
17 test__fixunssfsi(0.5, 0);17 try test__fixunssfsi(0.5, 0);
18 test__fixunssfsi(0.99, 0);18 try test__fixunssfsi(0.99, 0);
19 test__fixunssfsi(1.0, 1);19 try test__fixunssfsi(1.0, 1);
20 test__fixunssfsi(1.5, 1);20 try test__fixunssfsi(1.5, 1);
21 test__fixunssfsi(1.99, 1);21 try test__fixunssfsi(1.99, 1);
22 test__fixunssfsi(2.0, 2);22 try test__fixunssfsi(2.0, 2);
23 test__fixunssfsi(2.01, 2);23 try test__fixunssfsi(2.01, 2);
24 test__fixunssfsi(-0.5, 0);24 try test__fixunssfsi(-0.5, 0);
25 test__fixunssfsi(-0.99, 0);25 try test__fixunssfsi(-0.99, 0);
2626
27 test__fixunssfsi(-1.0, 0);27 try test__fixunssfsi(-1.0, 0);
28 test__fixunssfsi(-1.5, 0);28 try test__fixunssfsi(-1.5, 0);
29 test__fixunssfsi(-1.99, 0);29 try test__fixunssfsi(-1.99, 0);
30 test__fixunssfsi(-2.0, 0);30 try test__fixunssfsi(-2.0, 0);
31 test__fixunssfsi(-2.01, 0);31 try test__fixunssfsi(-2.01, 0);
3232
33 test__fixunssfsi(0x1.000000p+31, 0x80000000);33 try test__fixunssfsi(0x1.000000p+31, 0x80000000);
34 test__fixunssfsi(0x1.000000p+32, 0xFFFFFFFF);34 try test__fixunssfsi(0x1.000000p+32, 0xFFFFFFFF);
35 test__fixunssfsi(0x1.FFFFFEp+31, 0xFFFFFF00);35 try test__fixunssfsi(0x1.FFFFFEp+31, 0xFFFFFF00);
36 test__fixunssfsi(0x1.FFFFFEp+30, 0x7FFFFF80);36 try test__fixunssfsi(0x1.FFFFFEp+30, 0x7FFFFF80);
37 test__fixunssfsi(0x1.FFFFFCp+30, 0x7FFFFF00);37 try test__fixunssfsi(0x1.FFFFFCp+30, 0x7FFFFF00);
3838
39 test__fixunssfsi(-0x1.FFFFFEp+30, 0);39 try test__fixunssfsi(-0x1.FFFFFEp+30, 0);
40 test__fixunssfsi(-0x1.FFFFFCp+30, 0);40 try test__fixunssfsi(-0x1.FFFFFCp+30, 0);
41}41}
lib/std/special/compiler_rt/fixunssfti_test.zig+29-29
...@@ -6,41 +6,41 @@...@@ -6,41 +6,41 @@
6const __fixunssfti = @import("fixunssfti.zig").__fixunssfti;6const __fixunssfti = @import("fixunssfti.zig").__fixunssfti;
7const testing = @import("std").testing;7const testing = @import("std").testing;
88
9fn test__fixunssfti(a: f32, expected: u128) void {9fn test__fixunssfti(a: f32, expected: u128) !void {
10 const x = __fixunssfti(a);10 const x = __fixunssfti(a);
11 testing.expect(x == expected);11 try testing.expect(x == expected);
12}12}
1313
14test "fixunssfti" {14test "fixunssfti" {
15 test__fixunssfti(0.0, 0);15 try test__fixunssfti(0.0, 0);
1616
17 test__fixunssfti(0.5, 0);17 try test__fixunssfti(0.5, 0);
18 test__fixunssfti(0.99, 0);18 try test__fixunssfti(0.99, 0);
19 test__fixunssfti(1.0, 1);19 try test__fixunssfti(1.0, 1);
20 test__fixunssfti(1.5, 1);20 try test__fixunssfti(1.5, 1);
21 test__fixunssfti(1.99, 1);21 try test__fixunssfti(1.99, 1);
22 test__fixunssfti(2.0, 2);22 try test__fixunssfti(2.0, 2);
23 test__fixunssfti(2.01, 2);23 try test__fixunssfti(2.01, 2);
24 test__fixunssfti(-0.5, 0);24 try test__fixunssfti(-0.5, 0);
25 test__fixunssfti(-0.99, 0);25 try test__fixunssfti(-0.99, 0);
2626
27 test__fixunssfti(-1.0, 0);27 try test__fixunssfti(-1.0, 0);
28 test__fixunssfti(-1.5, 0);28 try test__fixunssfti(-1.5, 0);
29 test__fixunssfti(-1.99, 0);29 try test__fixunssfti(-1.99, 0);
30 test__fixunssfti(-2.0, 0);30 try test__fixunssfti(-2.0, 0);
31 test__fixunssfti(-2.01, 0);31 try test__fixunssfti(-2.01, 0);
3232
33 test__fixunssfti(0x1.FFFFFEp+63, 0xFFFFFF0000000000);33 try test__fixunssfti(0x1.FFFFFEp+63, 0xFFFFFF0000000000);
34 test__fixunssfti(0x1.000000p+63, 0x8000000000000000);34 try test__fixunssfti(0x1.000000p+63, 0x8000000000000000);
35 test__fixunssfti(0x1.FFFFFEp+62, 0x7FFFFF8000000000);35 try test__fixunssfti(0x1.FFFFFEp+62, 0x7FFFFF8000000000);
36 test__fixunssfti(0x1.FFFFFCp+62, 0x7FFFFF0000000000);36 try test__fixunssfti(0x1.FFFFFCp+62, 0x7FFFFF0000000000);
37 test__fixunssfti(0x1.FFFFFEp+127, 0xFFFFFF00000000000000000000000000);37 try test__fixunssfti(0x1.FFFFFEp+127, 0xFFFFFF00000000000000000000000000);
38 test__fixunssfti(0x1.000000p+127, 0x80000000000000000000000000000000);38 try test__fixunssfti(0x1.000000p+127, 0x80000000000000000000000000000000);
39 test__fixunssfti(0x1.FFFFFEp+126, 0x7FFFFF80000000000000000000000000);39 try test__fixunssfti(0x1.FFFFFEp+126, 0x7FFFFF80000000000000000000000000);
40 test__fixunssfti(0x1.FFFFFCp+126, 0x7FFFFF00000000000000000000000000);40 try test__fixunssfti(0x1.FFFFFCp+126, 0x7FFFFF00000000000000000000000000);
4141
42 test__fixunssfti(-0x1.FFFFFEp+62, 0x0000000000000000);42 try test__fixunssfti(-0x1.FFFFFEp+62, 0x0000000000000000);
43 test__fixunssfti(-0x1.FFFFFCp+62, 0x0000000000000000);43 try test__fixunssfti(-0x1.FFFFFCp+62, 0x0000000000000000);
44 test__fixunssfti(-0x1.FFFFFEp+126, 0x0000000000000000);44 try test__fixunssfti(-0x1.FFFFFEp+126, 0x0000000000000000);
45 test__fixunssfti(-0x1.FFFFFCp+126, 0x0000000000000000);45 try test__fixunssfti(-0x1.FFFFFCp+126, 0x0000000000000000);
46}46}
lib/std/special/compiler_rt/fixunstfdi_test.zig+41-41
...@@ -6,49 +6,49 @@...@@ -6,49 +6,49 @@
6const __fixunstfdi = @import("fixunstfdi.zig").__fixunstfdi;6const __fixunstfdi = @import("fixunstfdi.zig").__fixunstfdi;
7const testing = @import("std").testing;7const testing = @import("std").testing;
88
9fn test__fixunstfdi(a: f128, expected: u64) void {9fn test__fixunstfdi(a: f128, expected: u64) !void {
10 const x = __fixunstfdi(a);10 const x = __fixunstfdi(a);
11 testing.expect(x == expected);11 try testing.expect(x == expected);
12}12}
1313
14test "fixunstfdi" {14test "fixunstfdi" {
15 test__fixunstfdi(0.0, 0);15 try test__fixunstfdi(0.0, 0);
1616
17 test__fixunstfdi(0.5, 0);17 try test__fixunstfdi(0.5, 0);
18 test__fixunstfdi(0.99, 0);18 try test__fixunstfdi(0.99, 0);
19 test__fixunstfdi(1.0, 1);19 try test__fixunstfdi(1.0, 1);
20 test__fixunstfdi(1.5, 1);20 try test__fixunstfdi(1.5, 1);
21 test__fixunstfdi(1.99, 1);21 try test__fixunstfdi(1.99, 1);
22 test__fixunstfdi(2.0, 2);22 try test__fixunstfdi(2.0, 2);
23 test__fixunstfdi(2.01, 2);23 try test__fixunstfdi(2.01, 2);
24 test__fixunstfdi(-0.5, 0);24 try test__fixunstfdi(-0.5, 0);
25 test__fixunstfdi(-0.99, 0);25 try test__fixunstfdi(-0.99, 0);
26 test__fixunstfdi(-1.0, 0);26 try test__fixunstfdi(-1.0, 0);
27 test__fixunstfdi(-1.5, 0);27 try test__fixunstfdi(-1.5, 0);
28 test__fixunstfdi(-1.99, 0);28 try test__fixunstfdi(-1.99, 0);
29 test__fixunstfdi(-2.0, 0);29 try test__fixunstfdi(-2.0, 0);
30 test__fixunstfdi(-2.01, 0);30 try test__fixunstfdi(-2.01, 0);
3131
32 test__fixunstfdi(0x1.FFFFFEp+62, 0x7FFFFF8000000000);32 try test__fixunstfdi(0x1.FFFFFEp+62, 0x7FFFFF8000000000);
33 test__fixunstfdi(0x1.FFFFFCp+62, 0x7FFFFF0000000000);33 try test__fixunstfdi(0x1.FFFFFCp+62, 0x7FFFFF0000000000);
3434
35 test__fixunstfdi(-0x1.FFFFFEp+62, 0);35 try test__fixunstfdi(-0x1.FFFFFEp+62, 0);
36 test__fixunstfdi(-0x1.FFFFFCp+62, 0);36 try test__fixunstfdi(-0x1.FFFFFCp+62, 0);
3737
38 test__fixunstfdi(0x1.FFFFFFFFFFFFFp+62, 0x7FFFFFFFFFFFFC00);38 try test__fixunstfdi(0x1.FFFFFFFFFFFFFp+62, 0x7FFFFFFFFFFFFC00);
39 test__fixunstfdi(0x1.FFFFFFFFFFFFEp+62, 0x7FFFFFFFFFFFF800);39 try test__fixunstfdi(0x1.FFFFFFFFFFFFEp+62, 0x7FFFFFFFFFFFF800);
4040
41 test__fixunstfdi(-0x1.FFFFFFFFFFFFFp+62, 0);41 try test__fixunstfdi(-0x1.FFFFFFFFFFFFFp+62, 0);
42 test__fixunstfdi(-0x1.FFFFFFFFFFFFEp+62, 0);42 try test__fixunstfdi(-0x1.FFFFFFFFFFFFEp+62, 0);
4343
44 test__fixunstfdi(0x1.FFFFFFFFFFFFFFFEp+63, 0xFFFFFFFFFFFFFFFF);44 try test__fixunstfdi(0x1.FFFFFFFFFFFFFFFEp+63, 0xFFFFFFFFFFFFFFFF);
45 test__fixunstfdi(0x1.0000000000000002p+63, 0x8000000000000001);45 try test__fixunstfdi(0x1.0000000000000002p+63, 0x8000000000000001);
46 test__fixunstfdi(0x1.0000000000000000p+63, 0x8000000000000000);46 try test__fixunstfdi(0x1.0000000000000000p+63, 0x8000000000000000);
47 test__fixunstfdi(0x1.FFFFFFFFFFFFFFFCp+62, 0x7FFFFFFFFFFFFFFF);47 try test__fixunstfdi(0x1.FFFFFFFFFFFFFFFCp+62, 0x7FFFFFFFFFFFFFFF);
48 test__fixunstfdi(0x1.FFFFFFFFFFFFFFF8p+62, 0x7FFFFFFFFFFFFFFE);48 try test__fixunstfdi(0x1.FFFFFFFFFFFFFFF8p+62, 0x7FFFFFFFFFFFFFFE);
49 test__fixunstfdi(0x1.p+64, 0xFFFFFFFFFFFFFFFF);49 try test__fixunstfdi(0x1.p+64, 0xFFFFFFFFFFFFFFFF);
5050
51 test__fixunstfdi(-0x1.0000000000000000p+63, 0);51 try test__fixunstfdi(-0x1.0000000000000000p+63, 0);
52 test__fixunstfdi(-0x1.FFFFFFFFFFFFFFFCp+62, 0);52 try test__fixunstfdi(-0x1.FFFFFFFFFFFFFFFCp+62, 0);
53 test__fixunstfdi(-0x1.FFFFFFFFFFFFFFF8p+62, 0);53 try test__fixunstfdi(-0x1.FFFFFFFFFFFFFFF8p+62, 0);
54}54}
lib/std/special/compiler_rt/fixunstfsi_test.zig+11-11
...@@ -6,22 +6,22 @@...@@ -6,22 +6,22 @@
6const __fixunstfsi = @import("fixunstfsi.zig").__fixunstfsi;6const __fixunstfsi = @import("fixunstfsi.zig").__fixunstfsi;
7const testing = @import("std").testing;7const testing = @import("std").testing;
88
9fn test__fixunstfsi(a: f128, expected: u32) void {9fn test__fixunstfsi(a: f128, expected: u32) !void {
10 const x = __fixunstfsi(a);10 const x = __fixunstfsi(a);
11 testing.expect(x == expected);11 try testing.expect(x == expected);
12}12}
1313
14const inf128 = @bitCast(f128, @as(u128, 0x7fff0000000000000000000000000000));14const inf128 = @bitCast(f128, @as(u128, 0x7fff0000000000000000000000000000));
1515
16test "fixunstfsi" {16test "fixunstfsi" {
17 test__fixunstfsi(inf128, 0xffffffff);17 try test__fixunstfsi(inf128, 0xffffffff);
18 test__fixunstfsi(0, 0x0);18 try test__fixunstfsi(0, 0x0);
19 test__fixunstfsi(0x1.23456789abcdefp+5, 0x24);19 try test__fixunstfsi(0x1.23456789abcdefp+5, 0x24);
20 test__fixunstfsi(0x1.23456789abcdefp-3, 0x0);20 try test__fixunstfsi(0x1.23456789abcdefp-3, 0x0);
21 test__fixunstfsi(0x1.23456789abcdefp+20, 0x123456);21 try test__fixunstfsi(0x1.23456789abcdefp+20, 0x123456);
22 test__fixunstfsi(0x1.23456789abcdefp+40, 0xffffffff);22 try test__fixunstfsi(0x1.23456789abcdefp+40, 0xffffffff);
23 test__fixunstfsi(0x1.23456789abcdefp+256, 0xffffffff);23 try test__fixunstfsi(0x1.23456789abcdefp+256, 0xffffffff);
24 test__fixunstfsi(-0x1.23456789abcdefp+3, 0x0);24 try test__fixunstfsi(-0x1.23456789abcdefp+3, 0x0);
2525
26 test__fixunstfsi(0x1.p+32, 0xFFFFFFFF);26 try test__fixunstfsi(0x1.p+32, 0xFFFFFFFF);
27}27}
lib/std/special/compiler_rt/fixunstfti_test.zig+18-18
...@@ -6,32 +6,32 @@...@@ -6,32 +6,32 @@
6const __fixunstfti = @import("fixunstfti.zig").__fixunstfti;6const __fixunstfti = @import("fixunstfti.zig").__fixunstfti;
7const testing = @import("std").testing;7const testing = @import("std").testing;
88
9fn test__fixunstfti(a: f128, expected: u128) void {9fn test__fixunstfti(a: f128, expected: u128) !void {
10 const x = __fixunstfti(a);10 const x = __fixunstfti(a);
11 testing.expect(x == expected);11 try testing.expect(x == expected);
12}12}
1313
14const inf128 = @bitCast(f128, @as(u128, 0x7fff0000000000000000000000000000));14const inf128 = @bitCast(f128, @as(u128, 0x7fff0000000000000000000000000000));
1515
16test "fixunstfti" {16test "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);21 try test__fixunstfti(0.5, 0);
22 test__fixunstfti(0.99, 0);22 try test__fixunstfti(0.99, 0);
23 test__fixunstfti(1.0, 1);23 try test__fixunstfti(1.0, 1);
24 test__fixunstfti(1.5, 1);24 try test__fixunstfti(1.5, 1);
25 test__fixunstfti(1.99, 1);25 try test__fixunstfti(1.99, 1);
26 test__fixunstfti(2.0, 2);26 try test__fixunstfti(2.0, 2);
27 test__fixunstfti(2.01, 2);27 try test__fixunstfti(2.01, 2);
28 test__fixunstfti(-0.01, 0);28 try test__fixunstfti(-0.01, 0);
29 test__fixunstfti(-0.99, 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);33 try test__fixunstfti(0x1.FFFFFEp+126, 0x7fffff80000000000000000000000000);
34 test__fixunstfti(0x1.FFFFFEp+127, 0xffffff00000000000000000000000000);34 try test__fixunstfti(0x1.FFFFFEp+127, 0xffffff00000000000000000000000000);
35 test__fixunstfti(0x1.FFFFFEp+128, 0xffffffffffffffffffffffffffffffff);35 try test__fixunstfti(0x1.FFFFFEp+128, 0xffffffffffffffffffffffffffffffff);
36 test__fixunstfti(0x1.FFFFFEp+129, 0xffffffffffffffffffffffffffffffff);36 try test__fixunstfti(0x1.FFFFFEp+129, 0xffffffffffffffffffffffffffffffff);
37}37}
lib/std/special/compiler_rt/floatdidf_test.zig+45-45
...@@ -6,53 +6,53 @@...@@ -6,53 +6,53 @@
6const __floatdidf = @import("floatdidf.zig").__floatdidf;6const __floatdidf = @import("floatdidf.zig").__floatdidf;
7const testing = @import("std").testing;7const testing = @import("std").testing;
88
9fn test__floatdidf(a: i64, expected: f64) void {9fn test__floatdidf(a: i64, expected: f64) !void {
10 const r = __floatdidf(a);10 const r = __floatdidf(a);
11 testing.expect(r == expected);11 try testing.expect(r == expected);
12}12}
1313
14test "floatdidf" {14test "floatdidf" {
15 test__floatdidf(0, 0.0);15 try test__floatdidf(0, 0.0);
16 test__floatdidf(1, 1.0);16 try test__floatdidf(1, 1.0);
17 test__floatdidf(2, 2.0);17 try test__floatdidf(2, 2.0);
18 test__floatdidf(20, 20.0);18 try test__floatdidf(20, 20.0);
19 test__floatdidf(-1, -1.0);19 try test__floatdidf(-1, -1.0);
20 test__floatdidf(-2, -2.0);20 try test__floatdidf(-2, -2.0);
21 test__floatdidf(-20, -20.0);21 try test__floatdidf(-20, -20.0);
22 test__floatdidf(0x7FFFFF8000000000, 0x1.FFFFFEp+62);22 try test__floatdidf(0x7FFFFF8000000000, 0x1.FFFFFEp+62);
23 test__floatdidf(0x7FFFFFFFFFFFF800, 0x1.FFFFFFFFFFFFEp+62);23 try test__floatdidf(0x7FFFFFFFFFFFF800, 0x1.FFFFFFFFFFFFEp+62);
24 test__floatdidf(0x7FFFFF0000000000, 0x1.FFFFFCp+62);24 try test__floatdidf(0x7FFFFF0000000000, 0x1.FFFFFCp+62);
25 test__floatdidf(0x7FFFFFFFFFFFF000, 0x1.FFFFFFFFFFFFCp+62);25 try test__floatdidf(0x7FFFFFFFFFFFF000, 0x1.FFFFFFFFFFFFCp+62);
26 test__floatdidf(@bitCast(i64, @intCast(u64, 0x8000008000000000)), -0x1.FFFFFEp+62);26 try test__floatdidf(@bitCast(i64, @intCast(u64, 0x8000008000000000)), -0x1.FFFFFEp+62);
27 test__floatdidf(@bitCast(i64, @intCast(u64, 0x8000000000000800)), -0x1.FFFFFFFFFFFFEp+62);27 try test__floatdidf(@bitCast(i64, @intCast(u64, 0x8000000000000800)), -0x1.FFFFFFFFFFFFEp+62);
28 test__floatdidf(@bitCast(i64, @intCast(u64, 0x8000010000000000)), -0x1.FFFFFCp+62);28 try test__floatdidf(@bitCast(i64, @intCast(u64, 0x8000010000000000)), -0x1.FFFFFCp+62);
29 test__floatdidf(@bitCast(i64, @intCast(u64, 0x8000000000001000)), -0x1.FFFFFFFFFFFFCp+62);29 try test__floatdidf(@bitCast(i64, @intCast(u64, 0x8000000000001000)), -0x1.FFFFFFFFFFFFCp+62);
30 test__floatdidf(@bitCast(i64, @intCast(u64, 0x8000000000000000)), -0x1.000000p+63);30 try test__floatdidf(@bitCast(i64, @intCast(u64, 0x8000000000000000)), -0x1.000000p+63);
31 test__floatdidf(@bitCast(i64, @intCast(u64, 0x8000000000000001)), -0x1.000000p+63);31 try test__floatdidf(@bitCast(i64, @intCast(u64, 0x8000000000000001)), -0x1.000000p+63);
32 test__floatdidf(0x0007FB72E8000000, 0x1.FEDCBAp+50);32 try test__floatdidf(0x0007FB72E8000000, 0x1.FEDCBAp+50);
33 test__floatdidf(0x0007FB72EA000000, 0x1.FEDCBA8p+50);33 try test__floatdidf(0x0007FB72EA000000, 0x1.FEDCBA8p+50);
34 test__floatdidf(0x0007FB72EB000000, 0x1.FEDCBACp+50);34 try test__floatdidf(0x0007FB72EB000000, 0x1.FEDCBACp+50);
35 test__floatdidf(0x0007FB72EBFFFFFF, 0x1.FEDCBAFFFFFFCp+50);35 try test__floatdidf(0x0007FB72EBFFFFFF, 0x1.FEDCBAFFFFFFCp+50);
36 test__floatdidf(0x0007FB72EC000000, 0x1.FEDCBBp+50);36 try test__floatdidf(0x0007FB72EC000000, 0x1.FEDCBBp+50);
37 test__floatdidf(0x0007FB72E8000001, 0x1.FEDCBA0000004p+50);37 try test__floatdidf(0x0007FB72E8000001, 0x1.FEDCBA0000004p+50);
38 test__floatdidf(0x0007FB72E6000000, 0x1.FEDCB98p+50);38 try test__floatdidf(0x0007FB72E6000000, 0x1.FEDCB98p+50);
39 test__floatdidf(0x0007FB72E7000000, 0x1.FEDCB9Cp+50);39 try test__floatdidf(0x0007FB72E7000000, 0x1.FEDCB9Cp+50);
40 test__floatdidf(0x0007FB72E7FFFFFF, 0x1.FEDCB9FFFFFFCp+50);40 try test__floatdidf(0x0007FB72E7FFFFFF, 0x1.FEDCB9FFFFFFCp+50);
41 test__floatdidf(0x0007FB72E4000001, 0x1.FEDCB90000004p+50);41 try test__floatdidf(0x0007FB72E4000001, 0x1.FEDCB90000004p+50);
42 test__floatdidf(0x0007FB72E4000000, 0x1.FEDCB9p+50);42 try test__floatdidf(0x0007FB72E4000000, 0x1.FEDCB9p+50);
43 test__floatdidf(0x023479FD0E092DC0, 0x1.1A3CFE870496Ep+57);43 try test__floatdidf(0x023479FD0E092DC0, 0x1.1A3CFE870496Ep+57);
44 test__floatdidf(0x023479FD0E092DA1, 0x1.1A3CFE870496Dp+57);44 try test__floatdidf(0x023479FD0E092DA1, 0x1.1A3CFE870496Dp+57);
45 test__floatdidf(0x023479FD0E092DB0, 0x1.1A3CFE870496Ep+57);45 try test__floatdidf(0x023479FD0E092DB0, 0x1.1A3CFE870496Ep+57);
46 test__floatdidf(0x023479FD0E092DB8, 0x1.1A3CFE870496Ep+57);46 try test__floatdidf(0x023479FD0E092DB8, 0x1.1A3CFE870496Ep+57);
47 test__floatdidf(0x023479FD0E092DB6, 0x1.1A3CFE870496Ep+57);47 try test__floatdidf(0x023479FD0E092DB6, 0x1.1A3CFE870496Ep+57);
48 test__floatdidf(0x023479FD0E092DBF, 0x1.1A3CFE870496Ep+57);48 try test__floatdidf(0x023479FD0E092DBF, 0x1.1A3CFE870496Ep+57);
49 test__floatdidf(0x023479FD0E092DC1, 0x1.1A3CFE870496Ep+57);49 try test__floatdidf(0x023479FD0E092DC1, 0x1.1A3CFE870496Ep+57);
50 test__floatdidf(0x023479FD0E092DC7, 0x1.1A3CFE870496Ep+57);50 try test__floatdidf(0x023479FD0E092DC7, 0x1.1A3CFE870496Ep+57);
51 test__floatdidf(0x023479FD0E092DC8, 0x1.1A3CFE870496Ep+57);51 try test__floatdidf(0x023479FD0E092DC8, 0x1.1A3CFE870496Ep+57);
52 test__floatdidf(0x023479FD0E092DCF, 0x1.1A3CFE870496Ep+57);52 try test__floatdidf(0x023479FD0E092DCF, 0x1.1A3CFE870496Ep+57);
53 test__floatdidf(0x023479FD0E092DD0, 0x1.1A3CFE870496Ep+57);53 try test__floatdidf(0x023479FD0E092DD0, 0x1.1A3CFE870496Ep+57);
54 test__floatdidf(0x023479FD0E092DD1, 0x1.1A3CFE870496Fp+57);54 try test__floatdidf(0x023479FD0E092DD1, 0x1.1A3CFE870496Fp+57);
55 test__floatdidf(0x023479FD0E092DD8, 0x1.1A3CFE870496Fp+57);55 try test__floatdidf(0x023479FD0E092DD8, 0x1.1A3CFE870496Fp+57);
56 test__floatdidf(0x023479FD0E092DDF, 0x1.1A3CFE870496Fp+57);56 try test__floatdidf(0x023479FD0E092DDF, 0x1.1A3CFE870496Fp+57);
57 test__floatdidf(0x023479FD0E092DE0, 0x1.1A3CFE870496Fp+57);57 try test__floatdidf(0x023479FD0E092DE0, 0x1.1A3CFE870496Fp+57);
58}58}
lib/std/special/compiler_rt/floatdisf_test.zig+24-24
...@@ -6,32 +6,32 @@...@@ -6,32 +6,32 @@
6const __floatdisf = @import("floatXisf.zig").__floatdisf;6const __floatdisf = @import("floatXisf.zig").__floatdisf;
7const testing = @import("std").testing;7const testing = @import("std").testing;
88
9fn test__floatdisf(a: i64, expected: f32) void {9fn test__floatdisf(a: i64, expected: f32) !void {
10 const x = __floatdisf(a);10 const x = __floatdisf(a);
11 testing.expect(x == expected);11 try testing.expect(x == expected);
12}12}
1313
14test "floatdisf" {14test "floatdisf" {
15 test__floatdisf(0, 0.0);15 try test__floatdisf(0, 0.0);
16 test__floatdisf(1, 1.0);16 try test__floatdisf(1, 1.0);
17 test__floatdisf(2, 2.0);17 try test__floatdisf(2, 2.0);
18 test__floatdisf(-1, -1.0);18 try test__floatdisf(-1, -1.0);
19 test__floatdisf(-2, -2.0);19 try test__floatdisf(-2, -2.0);
20 test__floatdisf(0x7FFFFF8000000000, 0x1.FFFFFEp+62);20 try test__floatdisf(0x7FFFFF8000000000, 0x1.FFFFFEp+62);
21 test__floatdisf(0x7FFFFF0000000000, 0x1.FFFFFCp+62);21 try test__floatdisf(0x7FFFFF0000000000, 0x1.FFFFFCp+62);
22 test__floatdisf(0x8000008000000000, -0x1.FFFFFEp+62);22 try test__floatdisf(0x8000008000000000, -0x1.FFFFFEp+62);
23 test__floatdisf(0x8000010000000000, -0x1.FFFFFCp+62);23 try test__floatdisf(0x8000010000000000, -0x1.FFFFFCp+62);
24 test__floatdisf(0x8000000000000000, -0x1.000000p+63);24 try test__floatdisf(0x8000000000000000, -0x1.000000p+63);
25 test__floatdisf(0x8000000000000001, -0x1.000000p+63);25 try test__floatdisf(0x8000000000000001, -0x1.000000p+63);
26 test__floatdisf(0x0007FB72E8000000, 0x1.FEDCBAp+50);26 try test__floatdisf(0x0007FB72E8000000, 0x1.FEDCBAp+50);
27 test__floatdisf(0x0007FB72EA000000, 0x1.FEDCBAp+50);27 try test__floatdisf(0x0007FB72EA000000, 0x1.FEDCBAp+50);
28 test__floatdisf(0x0007FB72EB000000, 0x1.FEDCBAp+50);28 try test__floatdisf(0x0007FB72EB000000, 0x1.FEDCBAp+50);
29 test__floatdisf(0x0007FB72EBFFFFFF, 0x1.FEDCBAp+50);29 try test__floatdisf(0x0007FB72EBFFFFFF, 0x1.FEDCBAp+50);
30 test__floatdisf(0x0007FB72EC000000, 0x1.FEDCBCp+50);30 try test__floatdisf(0x0007FB72EC000000, 0x1.FEDCBCp+50);
31 test__floatdisf(0x0007FB72E8000001, 0x1.FEDCBAp+50);31 try test__floatdisf(0x0007FB72E8000001, 0x1.FEDCBAp+50);
32 test__floatdisf(0x0007FB72E6000000, 0x1.FEDCBAp+50);32 try test__floatdisf(0x0007FB72E6000000, 0x1.FEDCBAp+50);
33 test__floatdisf(0x0007FB72E7000000, 0x1.FEDCBAp+50);33 try test__floatdisf(0x0007FB72E7000000, 0x1.FEDCBAp+50);
34 test__floatdisf(0x0007FB72E7FFFFFF, 0x1.FEDCBAp+50);34 try test__floatdisf(0x0007FB72E7FFFFFF, 0x1.FEDCBAp+50);
35 test__floatdisf(0x0007FB72E4000001, 0x1.FEDCBAp+50);35 try test__floatdisf(0x0007FB72E4000001, 0x1.FEDCBAp+50);
36 test__floatdisf(0x0007FB72E4000000, 0x1.FEDCB8p+50);36 try test__floatdisf(0x0007FB72E4000000, 0x1.FEDCB8p+50);
37}37}
lib/std/special/compiler_rt/floatditf_test.zig+11-11
...@@ -6,21 +6,21 @@...@@ -6,21 +6,21 @@
6const __floatditf = @import("floatditf.zig").__floatditf;6const __floatditf = @import("floatditf.zig").__floatditf;
7const testing = @import("std").testing;7const testing = @import("std").testing;
88
9fn test__floatditf(a: i64, expected: f128) void {9fn test__floatditf(a: i64, expected: f128) !void {
10 const x = __floatditf(a);10 const x = __floatditf(a);
11 testing.expect(x == expected);11 try testing.expect(x == expected);
12}12}
1313
14test "floatditf" {14test "floatditf" {
15 test__floatditf(0x7fffffffffffffff, make_ti(0x403dffffffffffff, 0xfffc000000000000));15 try test__floatditf(0x7fffffffffffffff, make_ti(0x403dffffffffffff, 0xfffc000000000000));
16 test__floatditf(0x123456789abcdef1, make_ti(0x403b23456789abcd, 0xef10000000000000));16 try test__floatditf(0x123456789abcdef1, make_ti(0x403b23456789abcd, 0xef10000000000000));
17 test__floatditf(0x2, make_ti(0x4000000000000000, 0x0));17 try test__floatditf(0x2, make_ti(0x4000000000000000, 0x0));
18 test__floatditf(0x1, make_ti(0x3fff000000000000, 0x0));18 try test__floatditf(0x1, make_ti(0x3fff000000000000, 0x0));
19 test__floatditf(0x0, make_ti(0x0, 0x0));19 try test__floatditf(0x0, make_ti(0x0, 0x0));
20 test__floatditf(@bitCast(i64, @as(u64, 0xffffffffffffffff)), make_ti(0xbfff000000000000, 0x0));20 try test__floatditf(@bitCast(i64, @as(u64, 0xffffffffffffffff)), make_ti(0xbfff000000000000, 0x0));
21 test__floatditf(@bitCast(i64, @as(u64, 0xfffffffffffffffe)), make_ti(0xc000000000000000, 0x0));21 try test__floatditf(@bitCast(i64, @as(u64, 0xfffffffffffffffe)), make_ti(0xc000000000000000, 0x0));
22 test__floatditf(-0x123456789abcdef1, make_ti(0xc03b23456789abcd, 0xef10000000000000));22 try test__floatditf(-0x123456789abcdef1, make_ti(0xc03b23456789abcd, 0xef10000000000000));
23 test__floatditf(@bitCast(i64, @as(u64, 0x8000000000000000)), make_ti(0xc03e000000000000, 0x0));23 try test__floatditf(@bitCast(i64, @as(u64, 0x8000000000000000)), make_ti(0xc03e000000000000, 0x0));
24}24}
2525
26fn make_ti(high: u64, low: u64) f128 {26fn 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 {...@@ -84,42 +84,42 @@ pub fn __aeabi_i2f(arg: i32) callconv(.AAPCS) f32 {
84 return @call(.{ .modifier = .always_inline }, __floatsisf, .{arg});84 return @call(.{ .modifier = .always_inline }, __floatsisf, .{arg});
85}85}
8686
87fn test_one_floatsitf(a: i32, expected: u128) void {87fn test_one_floatsitf(a: i32, expected: u128) !void {
88 const r = __floatsitf(a);88 const r = __floatsitf(a);
89 std.testing.expect(@bitCast(u128, r) == expected);89 try std.testing.expect(@bitCast(u128, r) == expected);
90}90}
9191
92fn test_one_floatsidf(a: i32, expected: u64) void {92fn test_one_floatsidf(a: i32, expected: u64) !void {
93 const r = __floatsidf(a);93 const r = __floatsidf(a);
94 std.testing.expect(@bitCast(u64, r) == expected);94 try std.testing.expect(@bitCast(u64, r) == expected);
95}95}
9696
97fn test_one_floatsisf(a: i32, expected: u32) void {97fn test_one_floatsisf(a: i32, expected: u32) !void {
98 const r = __floatsisf(a);98 const r = __floatsisf(a);
99 std.testing.expect(@bitCast(u32, r) == expected);99 try std.testing.expect(@bitCast(u32, r) == expected);
100}100}
101101
102test "floatsidf" {102test "floatsidf" {
103 test_one_floatsidf(0, 0x0000000000000000);103 try test_one_floatsidf(0, 0x0000000000000000);
104 test_one_floatsidf(1, 0x3ff0000000000000);104 try test_one_floatsidf(1, 0x3ff0000000000000);
105 test_one_floatsidf(-1, 0xbff0000000000000);105 try test_one_floatsidf(-1, 0xbff0000000000000);
106 test_one_floatsidf(0x7FFFFFFF, 0x41dfffffffc00000);106 try test_one_floatsidf(0x7FFFFFFF, 0x41dfffffffc00000);
107 test_one_floatsidf(@bitCast(i32, @intCast(u32, 0x80000000)), 0xc1e0000000000000);107 try test_one_floatsidf(@bitCast(i32, @intCast(u32, 0x80000000)), 0xc1e0000000000000);
108}108}
109109
110test "floatsisf" {110test "floatsisf" {
111 test_one_floatsisf(0, 0x00000000);111 try test_one_floatsisf(0, 0x00000000);
112 test_one_floatsisf(1, 0x3f800000);112 try test_one_floatsisf(1, 0x3f800000);
113 test_one_floatsisf(-1, 0xbf800000);113 try test_one_floatsisf(-1, 0xbf800000);
114 test_one_floatsisf(0x7FFFFFFF, 0x4f000000);114 try test_one_floatsisf(0x7FFFFFFF, 0x4f000000);
115 test_one_floatsisf(@bitCast(i32, @intCast(u32, 0x80000000)), 0xcf000000);115 try test_one_floatsisf(@bitCast(i32, @intCast(u32, 0x80000000)), 0xcf000000);
116}116}
117117
118test "floatsitf" {118test "floatsitf" {
119 test_one_floatsitf(0, 0);119 try test_one_floatsitf(0, 0);
120 test_one_floatsitf(0x7FFFFFFF, 0x401dfffffffc00000000000000000000);120 try test_one_floatsitf(0x7FFFFFFF, 0x401dfffffffc00000000000000000000);
121 test_one_floatsitf(0x12345678, 0x401b2345678000000000000000000000);121 try test_one_floatsitf(0x12345678, 0x401b2345678000000000000000000000);
122 test_one_floatsitf(-0x12345678, 0xc01b2345678000000000000000000000);122 try test_one_floatsitf(-0x12345678, 0xc01b2345678000000000000000000000);
123 test_one_floatsitf(@bitCast(i32, @intCast(u32, 0xffffffff)), 0xbfff0000000000000000000000000000);123 try test_one_floatsitf(@bitCast(i32, @intCast(u32, 0xffffffff)), 0xbfff0000000000000000000000000000);
124 test_one_floatsitf(@bitCast(i32, @intCast(u32, 0x80000000)), 0xc01e0000000000000000000000000000);124 try test_one_floatsitf(@bitCast(i32, @intCast(u32, 0x80000000)), 0xc01e0000000000000000000000000000);
125}125}
lib/std/special/compiler_rt/floattidf_test.zig+60-60
...@@ -6,79 +6,79 @@...@@ -6,79 +6,79 @@
6const __floattidf = @import("floattidf.zig").__floattidf;6const __floattidf = @import("floattidf.zig").__floattidf;
7const testing = @import("std").testing;7const testing = @import("std").testing;
88
9fn test__floattidf(a: i128, expected: f64) void {9fn test__floattidf(a: i128, expected: f64) !void {
10 const x = __floattidf(a);10 const x = __floattidf(a);
11 testing.expect(x == expected);11 try testing.expect(x == expected);
12}12}
1313
14test "floattidf" {14test "floattidf" {
15 test__floattidf(0, 0.0);15 try test__floattidf(0, 0.0);
1616
17 test__floattidf(1, 1.0);17 try test__floattidf(1, 1.0);
18 test__floattidf(2, 2.0);18 try test__floattidf(2, 2.0);
19 test__floattidf(20, 20.0);19 try test__floattidf(20, 20.0);
20 test__floattidf(-1, -1.0);20 try test__floattidf(-1, -1.0);
21 test__floattidf(-2, -2.0);21 try test__floattidf(-2, -2.0);
22 test__floattidf(-20, -20.0);22 try test__floattidf(-20, -20.0);
2323
24 test__floattidf(0x7FFFFF8000000000, 0x1.FFFFFEp+62);24 try test__floattidf(0x7FFFFF8000000000, 0x1.FFFFFEp+62);
25 test__floattidf(0x7FFFFFFFFFFFF800, 0x1.FFFFFFFFFFFFEp+62);25 try test__floattidf(0x7FFFFFFFFFFFF800, 0x1.FFFFFFFFFFFFEp+62);
26 test__floattidf(0x7FFFFF0000000000, 0x1.FFFFFCp+62);26 try test__floattidf(0x7FFFFF0000000000, 0x1.FFFFFCp+62);
27 test__floattidf(0x7FFFFFFFFFFFF000, 0x1.FFFFFFFFFFFFCp+62);27 try test__floattidf(0x7FFFFFFFFFFFF000, 0x1.FFFFFFFFFFFFCp+62);
2828
29 test__floattidf(make_ti(0x8000008000000000, 0), -0x1.FFFFFEp+126);29 try test__floattidf(make_ti(0x8000008000000000, 0), -0x1.FFFFFEp+126);
30 test__floattidf(make_ti(0x8000000000000800, 0), -0x1.FFFFFFFFFFFFEp+126);30 try test__floattidf(make_ti(0x8000000000000800, 0), -0x1.FFFFFFFFFFFFEp+126);
31 test__floattidf(make_ti(0x8000010000000000, 0), -0x1.FFFFFCp+126);31 try test__floattidf(make_ti(0x8000010000000000, 0), -0x1.FFFFFCp+126);
32 test__floattidf(make_ti(0x8000000000001000, 0), -0x1.FFFFFFFFFFFFCp+126);32 try test__floattidf(make_ti(0x8000000000001000, 0), -0x1.FFFFFFFFFFFFCp+126);
3333
34 test__floattidf(make_ti(0x8000000000000000, 0), -0x1.000000p+127);34 try test__floattidf(make_ti(0x8000000000000000, 0), -0x1.000000p+127);
35 test__floattidf(make_ti(0x8000000000000001, 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);39 try test__floattidf(0x0007FB72EA000000, 0x1.FEDCBA8p+50);
40 test__floattidf(0x0007FB72EB000000, 0x1.FEDCBACp+50);40 try test__floattidf(0x0007FB72EB000000, 0x1.FEDCBACp+50);
41 test__floattidf(0x0007FB72EBFFFFFF, 0x1.FEDCBAFFFFFFCp+50);41 try test__floattidf(0x0007FB72EBFFFFFF, 0x1.FEDCBAFFFFFFCp+50);
42 test__floattidf(0x0007FB72EC000000, 0x1.FEDCBBp+50);42 try test__floattidf(0x0007FB72EC000000, 0x1.FEDCBBp+50);
43 test__floattidf(0x0007FB72E8000001, 0x1.FEDCBA0000004p+50);43 try test__floattidf(0x0007FB72E8000001, 0x1.FEDCBA0000004p+50);
4444
45 test__floattidf(0x0007FB72E6000000, 0x1.FEDCB98p+50);45 try test__floattidf(0x0007FB72E6000000, 0x1.FEDCB98p+50);
46 test__floattidf(0x0007FB72E7000000, 0x1.FEDCB9Cp+50);46 try test__floattidf(0x0007FB72E7000000, 0x1.FEDCB9Cp+50);
47 test__floattidf(0x0007FB72E7FFFFFF, 0x1.FEDCB9FFFFFFCp+50);47 try test__floattidf(0x0007FB72E7FFFFFF, 0x1.FEDCB9FFFFFFCp+50);
48 test__floattidf(0x0007FB72E4000001, 0x1.FEDCB90000004p+50);48 try test__floattidf(0x0007FB72E4000001, 0x1.FEDCB90000004p+50);
49 test__floattidf(0x0007FB72E4000000, 0x1.FEDCB9p+50);49 try test__floattidf(0x0007FB72E4000000, 0x1.FEDCB9p+50);
5050
51 test__floattidf(0x023479FD0E092DC0, 0x1.1A3CFE870496Ep+57);51 try test__floattidf(0x023479FD0E092DC0, 0x1.1A3CFE870496Ep+57);
52 test__floattidf(0x023479FD0E092DA1, 0x1.1A3CFE870496Dp+57);52 try test__floattidf(0x023479FD0E092DA1, 0x1.1A3CFE870496Dp+57);
53 test__floattidf(0x023479FD0E092DB0, 0x1.1A3CFE870496Ep+57);53 try test__floattidf(0x023479FD0E092DB0, 0x1.1A3CFE870496Ep+57);
54 test__floattidf(0x023479FD0E092DB8, 0x1.1A3CFE870496Ep+57);54 try test__floattidf(0x023479FD0E092DB8, 0x1.1A3CFE870496Ep+57);
55 test__floattidf(0x023479FD0E092DB6, 0x1.1A3CFE870496Ep+57);55 try test__floattidf(0x023479FD0E092DB6, 0x1.1A3CFE870496Ep+57);
56 test__floattidf(0x023479FD0E092DBF, 0x1.1A3CFE870496Ep+57);56 try test__floattidf(0x023479FD0E092DBF, 0x1.1A3CFE870496Ep+57);
57 test__floattidf(0x023479FD0E092DC1, 0x1.1A3CFE870496Ep+57);57 try test__floattidf(0x023479FD0E092DC1, 0x1.1A3CFE870496Ep+57);
58 test__floattidf(0x023479FD0E092DC7, 0x1.1A3CFE870496Ep+57);58 try test__floattidf(0x023479FD0E092DC7, 0x1.1A3CFE870496Ep+57);
59 test__floattidf(0x023479FD0E092DC8, 0x1.1A3CFE870496Ep+57);59 try test__floattidf(0x023479FD0E092DC8, 0x1.1A3CFE870496Ep+57);
60 test__floattidf(0x023479FD0E092DCF, 0x1.1A3CFE870496Ep+57);60 try test__floattidf(0x023479FD0E092DCF, 0x1.1A3CFE870496Ep+57);
61 test__floattidf(0x023479FD0E092DD0, 0x1.1A3CFE870496Ep+57);61 try test__floattidf(0x023479FD0E092DD0, 0x1.1A3CFE870496Ep+57);
62 test__floattidf(0x023479FD0E092DD1, 0x1.1A3CFE870496Fp+57);62 try test__floattidf(0x023479FD0E092DD1, 0x1.1A3CFE870496Fp+57);
63 test__floattidf(0x023479FD0E092DD8, 0x1.1A3CFE870496Fp+57);63 try test__floattidf(0x023479FD0E092DD8, 0x1.1A3CFE870496Fp+57);
64 test__floattidf(0x023479FD0E092DDF, 0x1.1A3CFE870496Fp+57);64 try test__floattidf(0x023479FD0E092DDF, 0x1.1A3CFE870496Fp+57);
65 test__floattidf(0x023479FD0E092DE0, 0x1.1A3CFE870496Fp+57);65 try test__floattidf(0x023479FD0E092DE0, 0x1.1A3CFE870496Fp+57);
6666
67 test__floattidf(make_ti(0x023479FD0E092DC0, 0), 0x1.1A3CFE870496Ep+121);67 try test__floattidf(make_ti(0x023479FD0E092DC0, 0), 0x1.1A3CFE870496Ep+121);
68 test__floattidf(make_ti(0x023479FD0E092DA1, 1), 0x1.1A3CFE870496Dp+121);68 try test__floattidf(make_ti(0x023479FD0E092DA1, 1), 0x1.1A3CFE870496Dp+121);
69 test__floattidf(make_ti(0x023479FD0E092DB0, 2), 0x1.1A3CFE870496Ep+121);69 try test__floattidf(make_ti(0x023479FD0E092DB0, 2), 0x1.1A3CFE870496Ep+121);
70 test__floattidf(make_ti(0x023479FD0E092DB8, 3), 0x1.1A3CFE870496Ep+121);70 try test__floattidf(make_ti(0x023479FD0E092DB8, 3), 0x1.1A3CFE870496Ep+121);
71 test__floattidf(make_ti(0x023479FD0E092DB6, 4), 0x1.1A3CFE870496Ep+121);71 try test__floattidf(make_ti(0x023479FD0E092DB6, 4), 0x1.1A3CFE870496Ep+121);
72 test__floattidf(make_ti(0x023479FD0E092DBF, 5), 0x1.1A3CFE870496Ep+121);72 try test__floattidf(make_ti(0x023479FD0E092DBF, 5), 0x1.1A3CFE870496Ep+121);
73 test__floattidf(make_ti(0x023479FD0E092DC1, 6), 0x1.1A3CFE870496Ep+121);73 try test__floattidf(make_ti(0x023479FD0E092DC1, 6), 0x1.1A3CFE870496Ep+121);
74 test__floattidf(make_ti(0x023479FD0E092DC7, 7), 0x1.1A3CFE870496Ep+121);74 try test__floattidf(make_ti(0x023479FD0E092DC7, 7), 0x1.1A3CFE870496Ep+121);
75 test__floattidf(make_ti(0x023479FD0E092DC8, 8), 0x1.1A3CFE870496Ep+121);75 try test__floattidf(make_ti(0x023479FD0E092DC8, 8), 0x1.1A3CFE870496Ep+121);
76 test__floattidf(make_ti(0x023479FD0E092DCF, 9), 0x1.1A3CFE870496Ep+121);76 try test__floattidf(make_ti(0x023479FD0E092DCF, 9), 0x1.1A3CFE870496Ep+121);
77 test__floattidf(make_ti(0x023479FD0E092DD0, 0), 0x1.1A3CFE870496Ep+121);77 try test__floattidf(make_ti(0x023479FD0E092DD0, 0), 0x1.1A3CFE870496Ep+121);
78 test__floattidf(make_ti(0x023479FD0E092DD1, 11), 0x1.1A3CFE870496Fp+121);78 try test__floattidf(make_ti(0x023479FD0E092DD1, 11), 0x1.1A3CFE870496Fp+121);
79 test__floattidf(make_ti(0x023479FD0E092DD8, 12), 0x1.1A3CFE870496Fp+121);79 try test__floattidf(make_ti(0x023479FD0E092DD8, 12), 0x1.1A3CFE870496Fp+121);
80 test__floattidf(make_ti(0x023479FD0E092DDF, 13), 0x1.1A3CFE870496Fp+121);80 try test__floattidf(make_ti(0x023479FD0E092DDF, 13), 0x1.1A3CFE870496Fp+121);
81 test__floattidf(make_ti(0x023479FD0E092DE0, 14), 0x1.1A3CFE870496Fp+121);81 try test__floattidf(make_ti(0x023479FD0E092DE0, 14), 0x1.1A3CFE870496Fp+121);
82}82}
8383
84fn make_ti(high: u64, low: u64) i128 {84fn make_ti(high: u64, low: u64) i128 {
lib/std/special/compiler_rt/floattisf_test.zig+35-35
...@@ -6,55 +6,55 @@...@@ -6,55 +6,55 @@
6const __floattisf = @import("floatXisf.zig").__floattisf;6const __floattisf = @import("floatXisf.zig").__floattisf;
7const testing = @import("std").testing;7const testing = @import("std").testing;
88
9fn test__floattisf(a: i128, expected: f32) void {9fn test__floattisf(a: i128, expected: f32) !void {
10 const x = __floattisf(a);10 const x = __floattisf(a);
11 testing.expect(x == expected);11 try testing.expect(x == expected);
12}12}
1313
14test "floattisf" {14test "floattisf" {
15 test__floattisf(0, 0.0);15 try test__floattisf(0, 0.0);
1616
17 test__floattisf(1, 1.0);17 try test__floattisf(1, 1.0);
18 test__floattisf(2, 2.0);18 try test__floattisf(2, 2.0);
19 test__floattisf(-1, -1.0);19 try test__floattisf(-1, -1.0);
20 test__floattisf(-2, -2.0);20 try test__floattisf(-2, -2.0);
2121
22 test__floattisf(0x7FFFFF8000000000, 0x1.FFFFFEp+62);22 try test__floattisf(0x7FFFFF8000000000, 0x1.FFFFFEp+62);
23 test__floattisf(0x7FFFFF0000000000, 0x1.FFFFFCp+62);23 try test__floattisf(0x7FFFFF0000000000, 0x1.FFFFFCp+62);
2424
25 test__floattisf(make_ti(0xFFFFFFFFFFFFFFFF, 0x8000008000000000), -0x1.FFFFFEp+62);25 try test__floattisf(make_ti(0xFFFFFFFFFFFFFFFF, 0x8000008000000000), -0x1.FFFFFEp+62);
26 test__floattisf(make_ti(0xFFFFFFFFFFFFFFFF, 0x8000010000000000), -0x1.FFFFFCp+62);26 try test__floattisf(make_ti(0xFFFFFFFFFFFFFFFF, 0x8000010000000000), -0x1.FFFFFCp+62);
2727
28 test__floattisf(make_ti(0xFFFFFFFFFFFFFFFF, 0x8000000000000000), -0x1.000000p+63);28 try test__floattisf(make_ti(0xFFFFFFFFFFFFFFFF, 0x8000000000000000), -0x1.000000p+63);
29 test__floattisf(make_ti(0xFFFFFFFFFFFFFFFF, 0x8000000000000001), -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);33 try test__floattisf(0x0007FB72EA000000, 0x1.FEDCBAp+50);
34 test__floattisf(0x0007FB72EB000000, 0x1.FEDCBAp+50);34 try test__floattisf(0x0007FB72EB000000, 0x1.FEDCBAp+50);
35 test__floattisf(0x0007FB72EBFFFFFF, 0x1.FEDCBAp+50);35 try test__floattisf(0x0007FB72EBFFFFFF, 0x1.FEDCBAp+50);
36 test__floattisf(0x0007FB72EC000000, 0x1.FEDCBCp+50);36 try test__floattisf(0x0007FB72EC000000, 0x1.FEDCBCp+50);
37 test__floattisf(0x0007FB72E8000001, 0x1.FEDCBAp+50);37 try test__floattisf(0x0007FB72E8000001, 0x1.FEDCBAp+50);
3838
39 test__floattisf(0x0007FB72E6000000, 0x1.FEDCBAp+50);39 try test__floattisf(0x0007FB72E6000000, 0x1.FEDCBAp+50);
40 test__floattisf(0x0007FB72E7000000, 0x1.FEDCBAp+50);40 try test__floattisf(0x0007FB72E7000000, 0x1.FEDCBAp+50);
41 test__floattisf(0x0007FB72E7FFFFFF, 0x1.FEDCBAp+50);41 try test__floattisf(0x0007FB72E7FFFFFF, 0x1.FEDCBAp+50);
42 test__floattisf(0x0007FB72E4000001, 0x1.FEDCBAp+50);42 try test__floattisf(0x0007FB72E4000001, 0x1.FEDCBAp+50);
43 test__floattisf(0x0007FB72E4000000, 0x1.FEDCB8p+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);47 try test__floattisf(make_ti(0x0007FB72EA000000, 0), 0x1.FEDCBAp+114);
48 test__floattisf(make_ti(0x0007FB72EB000000, 0), 0x1.FEDCBAp+114);48 try test__floattisf(make_ti(0x0007FB72EB000000, 0), 0x1.FEDCBAp+114);
49 test__floattisf(make_ti(0x0007FB72EBFFFFFF, 0), 0x1.FEDCBAp+114);49 try test__floattisf(make_ti(0x0007FB72EBFFFFFF, 0), 0x1.FEDCBAp+114);
50 test__floattisf(make_ti(0x0007FB72EC000000, 0), 0x1.FEDCBCp+114);50 try test__floattisf(make_ti(0x0007FB72EC000000, 0), 0x1.FEDCBCp+114);
51 test__floattisf(make_ti(0x0007FB72E8000001, 0), 0x1.FEDCBAp+114);51 try test__floattisf(make_ti(0x0007FB72E8000001, 0), 0x1.FEDCBAp+114);
5252
53 test__floattisf(make_ti(0x0007FB72E6000000, 0), 0x1.FEDCBAp+114);53 try test__floattisf(make_ti(0x0007FB72E6000000, 0), 0x1.FEDCBAp+114);
54 test__floattisf(make_ti(0x0007FB72E7000000, 0), 0x1.FEDCBAp+114);54 try test__floattisf(make_ti(0x0007FB72E7000000, 0), 0x1.FEDCBAp+114);
55 test__floattisf(make_ti(0x0007FB72E7FFFFFF, 0), 0x1.FEDCBAp+114);55 try test__floattisf(make_ti(0x0007FB72E7FFFFFF, 0), 0x1.FEDCBAp+114);
56 test__floattisf(make_ti(0x0007FB72E4000001, 0), 0x1.FEDCBAp+114);56 try test__floattisf(make_ti(0x0007FB72E4000001, 0), 0x1.FEDCBAp+114);
57 test__floattisf(make_ti(0x0007FB72E4000000, 0), 0x1.FEDCB8p+114);57 try test__floattisf(make_ti(0x0007FB72E4000000, 0), 0x1.FEDCB8p+114);
58}58}
5959
60fn make_ti(high: u64, low: u64) i128 {60fn make_ti(high: u64, low: u64) i128 {
lib/std/special/compiler_rt/floattitf_test.zig+70-70
...@@ -6,91 +6,91 @@...@@ -6,91 +6,91 @@
6const __floattitf = @import("floattitf.zig").__floattitf;6const __floattitf = @import("floattitf.zig").__floattitf;
7const testing = @import("std").testing;7const testing = @import("std").testing;
88
9fn test__floattitf(a: i128, expected: f128) void {9fn test__floattitf(a: i128, expected: f128) !void {
10 const x = __floattitf(a);10 const x = __floattitf(a);
11 testing.expect(x == expected);11 try testing.expect(x == expected);
12}12}
1313
14test "floattitf" {14test "floattitf" {
15 test__floattitf(0, 0.0);15 try test__floattitf(0, 0.0);
1616
17 test__floattitf(1, 1.0);17 try test__floattitf(1, 1.0);
18 test__floattitf(2, 2.0);18 try test__floattitf(2, 2.0);
19 test__floattitf(20, 20.0);19 try test__floattitf(20, 20.0);
20 test__floattitf(-1, -1.0);20 try test__floattitf(-1, -1.0);
21 test__floattitf(-2, -2.0);21 try test__floattitf(-2, -2.0);
22 test__floattitf(-20, -20.0);22 try test__floattitf(-20, -20.0);
2323
24 test__floattitf(0x7FFFFF8000000000, 0x1.FFFFFEp+62);24 try test__floattitf(0x7FFFFF8000000000, 0x1.FFFFFEp+62);
25 test__floattitf(0x7FFFFFFFFFFFF800, 0x1.FFFFFFFFFFFFEp+62);25 try test__floattitf(0x7FFFFFFFFFFFF800, 0x1.FFFFFFFFFFFFEp+62);
26 test__floattitf(0x7FFFFF0000000000, 0x1.FFFFFCp+62);26 try test__floattitf(0x7FFFFF0000000000, 0x1.FFFFFCp+62);
27 test__floattitf(0x7FFFFFFFFFFFF000, 0x1.FFFFFFFFFFFFCp+62);27 try test__floattitf(0x7FFFFFFFFFFFF000, 0x1.FFFFFFFFFFFFCp+62);
2828
29 test__floattitf(make_ti(0x8000008000000000, 0), -0x1.FFFFFEp+126);29 try test__floattitf(make_ti(0x8000008000000000, 0), -0x1.FFFFFEp+126);
30 test__floattitf(make_ti(0x8000000000000800, 0), -0x1.FFFFFFFFFFFFEp+126);30 try test__floattitf(make_ti(0x8000000000000800, 0), -0x1.FFFFFFFFFFFFEp+126);
31 test__floattitf(make_ti(0x8000010000000000, 0), -0x1.FFFFFCp+126);31 try test__floattitf(make_ti(0x8000010000000000, 0), -0x1.FFFFFCp+126);
32 test__floattitf(make_ti(0x8000000000001000, 0), -0x1.FFFFFFFFFFFFCp+126);32 try test__floattitf(make_ti(0x8000000000001000, 0), -0x1.FFFFFFFFFFFFCp+126);
3333
34 test__floattitf(make_ti(0x8000000000000000, 0), -0x1.000000p+127);34 try test__floattitf(make_ti(0x8000000000000000, 0), -0x1.000000p+127);
35 test__floattitf(make_ti(0x8000000000000001, 0), -0x1.FFFFFFFFFFFFFFFCp+126);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);39 try test__floattitf(0x0007FB72EA000000, 0x1.FEDCBA8p+50);
40 test__floattitf(0x0007FB72EB000000, 0x1.FEDCBACp+50);40 try test__floattitf(0x0007FB72EB000000, 0x1.FEDCBACp+50);
41 test__floattitf(0x0007FB72EBFFFFFF, 0x1.FEDCBAFFFFFFCp+50);41 try test__floattitf(0x0007FB72EBFFFFFF, 0x1.FEDCBAFFFFFFCp+50);
42 test__floattitf(0x0007FB72EC000000, 0x1.FEDCBBp+50);42 try test__floattitf(0x0007FB72EC000000, 0x1.FEDCBBp+50);
43 test__floattitf(0x0007FB72E8000001, 0x1.FEDCBA0000004p+50);43 try test__floattitf(0x0007FB72E8000001, 0x1.FEDCBA0000004p+50);
4444
45 test__floattitf(0x0007FB72E6000000, 0x1.FEDCB98p+50);45 try test__floattitf(0x0007FB72E6000000, 0x1.FEDCB98p+50);
46 test__floattitf(0x0007FB72E7000000, 0x1.FEDCB9Cp+50);46 try test__floattitf(0x0007FB72E7000000, 0x1.FEDCB9Cp+50);
47 test__floattitf(0x0007FB72E7FFFFFF, 0x1.FEDCB9FFFFFFCp+50);47 try test__floattitf(0x0007FB72E7FFFFFF, 0x1.FEDCB9FFFFFFCp+50);
48 test__floattitf(0x0007FB72E4000001, 0x1.FEDCB90000004p+50);48 try test__floattitf(0x0007FB72E4000001, 0x1.FEDCB90000004p+50);
49 test__floattitf(0x0007FB72E4000000, 0x1.FEDCB9p+50);49 try test__floattitf(0x0007FB72E4000000, 0x1.FEDCB9p+50);
5050
51 test__floattitf(0x023479FD0E092DC0, 0x1.1A3CFE870496Ep+57);51 try test__floattitf(0x023479FD0E092DC0, 0x1.1A3CFE870496Ep+57);
52 test__floattitf(0x023479FD0E092DA1, 0x1.1A3CFE870496D08p+57);52 try test__floattitf(0x023479FD0E092DA1, 0x1.1A3CFE870496D08p+57);
53 test__floattitf(0x023479FD0E092DB0, 0x1.1A3CFE870496D8p+57);53 try test__floattitf(0x023479FD0E092DB0, 0x1.1A3CFE870496D8p+57);
54 test__floattitf(0x023479FD0E092DB8, 0x1.1A3CFE870496DCp+57);54 try test__floattitf(0x023479FD0E092DB8, 0x1.1A3CFE870496DCp+57);
55 test__floattitf(0x023479FD0E092DB6, 0x1.1A3CFE870496DBp+57);55 try test__floattitf(0x023479FD0E092DB6, 0x1.1A3CFE870496DBp+57);
56 test__floattitf(0x023479FD0E092DBF, 0x1.1A3CFE870496DF8p+57);56 try test__floattitf(0x023479FD0E092DBF, 0x1.1A3CFE870496DF8p+57);
57 test__floattitf(0x023479FD0E092DC1, 0x1.1A3CFE870496E08p+57);57 try test__floattitf(0x023479FD0E092DC1, 0x1.1A3CFE870496E08p+57);
58 test__floattitf(0x023479FD0E092DC7, 0x1.1A3CFE870496E38p+57);58 try test__floattitf(0x023479FD0E092DC7, 0x1.1A3CFE870496E38p+57);
59 test__floattitf(0x023479FD0E092DC8, 0x1.1A3CFE870496E4p+57);59 try test__floattitf(0x023479FD0E092DC8, 0x1.1A3CFE870496E4p+57);
60 test__floattitf(0x023479FD0E092DCF, 0x1.1A3CFE870496E78p+57);60 try test__floattitf(0x023479FD0E092DCF, 0x1.1A3CFE870496E78p+57);
61 test__floattitf(0x023479FD0E092DD0, 0x1.1A3CFE870496E8p+57);61 try test__floattitf(0x023479FD0E092DD0, 0x1.1A3CFE870496E8p+57);
62 test__floattitf(0x023479FD0E092DD1, 0x1.1A3CFE870496E88p+57);62 try test__floattitf(0x023479FD0E092DD1, 0x1.1A3CFE870496E88p+57);
63 test__floattitf(0x023479FD0E092DD8, 0x1.1A3CFE870496ECp+57);63 try test__floattitf(0x023479FD0E092DD8, 0x1.1A3CFE870496ECp+57);
64 test__floattitf(0x023479FD0E092DDF, 0x1.1A3CFE870496EF8p+57);64 try test__floattitf(0x023479FD0E092DDF, 0x1.1A3CFE870496EF8p+57);
65 test__floattitf(0x023479FD0E092DE0, 0x1.1A3CFE870496Fp+57);65 try test__floattitf(0x023479FD0E092DE0, 0x1.1A3CFE870496Fp+57);
6666
67 test__floattitf(make_ti(0x023479FD0E092DC0, 0), 0x1.1A3CFE870496Ep+121);67 try test__floattitf(make_ti(0x023479FD0E092DC0, 0), 0x1.1A3CFE870496Ep+121);
68 test__floattitf(make_ti(0x023479FD0E092DA1, 1), 0x1.1A3CFE870496D08p+121);68 try test__floattitf(make_ti(0x023479FD0E092DA1, 1), 0x1.1A3CFE870496D08p+121);
69 test__floattitf(make_ti(0x023479FD0E092DB0, 2), 0x1.1A3CFE870496D8p+121);69 try test__floattitf(make_ti(0x023479FD0E092DB0, 2), 0x1.1A3CFE870496D8p+121);
70 test__floattitf(make_ti(0x023479FD0E092DB8, 3), 0x1.1A3CFE870496DCp+121);70 try test__floattitf(make_ti(0x023479FD0E092DB8, 3), 0x1.1A3CFE870496DCp+121);
71 test__floattitf(make_ti(0x023479FD0E092DB6, 4), 0x1.1A3CFE870496DBp+121);71 try test__floattitf(make_ti(0x023479FD0E092DB6, 4), 0x1.1A3CFE870496DBp+121);
72 test__floattitf(make_ti(0x023479FD0E092DBF, 5), 0x1.1A3CFE870496DF8p+121);72 try test__floattitf(make_ti(0x023479FD0E092DBF, 5), 0x1.1A3CFE870496DF8p+121);
73 test__floattitf(make_ti(0x023479FD0E092DC1, 6), 0x1.1A3CFE870496E08p+121);73 try test__floattitf(make_ti(0x023479FD0E092DC1, 6), 0x1.1A3CFE870496E08p+121);
74 test__floattitf(make_ti(0x023479FD0E092DC7, 7), 0x1.1A3CFE870496E38p+121);74 try test__floattitf(make_ti(0x023479FD0E092DC7, 7), 0x1.1A3CFE870496E38p+121);
75 test__floattitf(make_ti(0x023479FD0E092DC8, 8), 0x1.1A3CFE870496E4p+121);75 try test__floattitf(make_ti(0x023479FD0E092DC8, 8), 0x1.1A3CFE870496E4p+121);
76 test__floattitf(make_ti(0x023479FD0E092DCF, 9), 0x1.1A3CFE870496E78p+121);76 try test__floattitf(make_ti(0x023479FD0E092DCF, 9), 0x1.1A3CFE870496E78p+121);
77 test__floattitf(make_ti(0x023479FD0E092DD0, 0), 0x1.1A3CFE870496E8p+121);77 try test__floattitf(make_ti(0x023479FD0E092DD0, 0), 0x1.1A3CFE870496E8p+121);
78 test__floattitf(make_ti(0x023479FD0E092DD1, 11), 0x1.1A3CFE870496E88p+121);78 try test__floattitf(make_ti(0x023479FD0E092DD1, 11), 0x1.1A3CFE870496E88p+121);
79 test__floattitf(make_ti(0x023479FD0E092DD8, 12), 0x1.1A3CFE870496ECp+121);79 try test__floattitf(make_ti(0x023479FD0E092DD8, 12), 0x1.1A3CFE870496ECp+121);
80 test__floattitf(make_ti(0x023479FD0E092DDF, 13), 0x1.1A3CFE870496EF8p+121);80 try test__floattitf(make_ti(0x023479FD0E092DDF, 13), 0x1.1A3CFE870496EF8p+121);
81 test__floattitf(make_ti(0x023479FD0E092DE0, 14), 0x1.1A3CFE870496Fp+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);85 try test__floattitf(make_ti(0x123456789ABCDEF0, 0x123456789ABC2801), 0x1.23456789ABCDEF0123456789ABC3p+124);
86 test__floattitf(make_ti(0x123456789ABCDEF0, 0x123456789ABC3000), 0x1.23456789ABCDEF0123456789ABC3p+124);86 try test__floattitf(make_ti(0x123456789ABCDEF0, 0x123456789ABC3000), 0x1.23456789ABCDEF0123456789ABC3p+124);
87 test__floattitf(make_ti(0x123456789ABCDEF0, 0x123456789ABC37FF), 0x1.23456789ABCDEF0123456789ABC3p+124);87 try test__floattitf(make_ti(0x123456789ABCDEF0, 0x123456789ABC37FF), 0x1.23456789ABCDEF0123456789ABC3p+124);
88 test__floattitf(make_ti(0x123456789ABCDEF0, 0x123456789ABC3800), 0x1.23456789ABCDEF0123456789ABC4p+124);88 try test__floattitf(make_ti(0x123456789ABCDEF0, 0x123456789ABC3800), 0x1.23456789ABCDEF0123456789ABC4p+124);
89 test__floattitf(make_ti(0x123456789ABCDEF0, 0x123456789ABC4000), 0x1.23456789ABCDEF0123456789ABC4p+124);89 try test__floattitf(make_ti(0x123456789ABCDEF0, 0x123456789ABC4000), 0x1.23456789ABCDEF0123456789ABC4p+124);
90 test__floattitf(make_ti(0x123456789ABCDEF0, 0x123456789ABC47FF), 0x1.23456789ABCDEF0123456789ABC4p+124);90 try test__floattitf(make_ti(0x123456789ABCDEF0, 0x123456789ABC47FF), 0x1.23456789ABCDEF0123456789ABC4p+124);
91 test__floattitf(make_ti(0x123456789ABCDEF0, 0x123456789ABC4800), 0x1.23456789ABCDEF0123456789ABC4p+124);91 try test__floattitf(make_ti(0x123456789ABCDEF0, 0x123456789ABC4800), 0x1.23456789ABCDEF0123456789ABC4p+124);
92 test__floattitf(make_ti(0x123456789ABCDEF0, 0x123456789ABC4801), 0x1.23456789ABCDEF0123456789ABC5p+124);92 try test__floattitf(make_ti(0x123456789ABCDEF0, 0x123456789ABC4801), 0x1.23456789ABCDEF0123456789ABC5p+124);
93 test__floattitf(make_ti(0x123456789ABCDEF0, 0x123456789ABC57FF), 0x1.23456789ABCDEF0123456789ABC5p+124);93 try test__floattitf(make_ti(0x123456789ABCDEF0, 0x123456789ABC57FF), 0x1.23456789ABCDEF0123456789ABC5p+124);
94}94}
9595
96fn make_ti(high: u64, low: u64) i128 {96fn make_ti(high: u64, low: u64) i128 {
lib/std/special/compiler_rt/floatundidf_test.zig+42-42
...@@ -6,50 +6,50 @@...@@ -6,50 +6,50 @@
6const __floatundidf = @import("floatundidf.zig").__floatundidf;6const __floatundidf = @import("floatundidf.zig").__floatundidf;
7const testing = @import("std").testing;7const testing = @import("std").testing;
88
9fn test__floatundidf(a: u64, expected: f64) void {9fn test__floatundidf(a: u64, expected: f64) !void {
10 const r = __floatundidf(a);10 const r = __floatundidf(a);
11 testing.expect(r == expected);11 try testing.expect(r == expected);
12}12}
1313
14test "floatundidf" {14test "floatundidf" {
15 test__floatundidf(0, 0.0);15 try test__floatundidf(0, 0.0);
16 test__floatundidf(1, 1.0);16 try test__floatundidf(1, 1.0);
17 test__floatundidf(2, 2.0);17 try test__floatundidf(2, 2.0);
18 test__floatundidf(20, 20.0);18 try test__floatundidf(20, 20.0);
19 test__floatundidf(0x7FFFFF8000000000, 0x1.FFFFFEp+62);19 try test__floatundidf(0x7FFFFF8000000000, 0x1.FFFFFEp+62);
20 test__floatundidf(0x7FFFFFFFFFFFF800, 0x1.FFFFFFFFFFFFEp+62);20 try test__floatundidf(0x7FFFFFFFFFFFF800, 0x1.FFFFFFFFFFFFEp+62);
21 test__floatundidf(0x7FFFFF0000000000, 0x1.FFFFFCp+62);21 try test__floatundidf(0x7FFFFF0000000000, 0x1.FFFFFCp+62);
22 test__floatundidf(0x7FFFFFFFFFFFF000, 0x1.FFFFFFFFFFFFCp+62);22 try test__floatundidf(0x7FFFFFFFFFFFF000, 0x1.FFFFFFFFFFFFCp+62);
23 test__floatundidf(0x8000008000000000, 0x1.000001p+63);23 try test__floatundidf(0x8000008000000000, 0x1.000001p+63);
24 test__floatundidf(0x8000000000000800, 0x1.0000000000001p+63);24 try test__floatundidf(0x8000000000000800, 0x1.0000000000001p+63);
25 test__floatundidf(0x8000010000000000, 0x1.000002p+63);25 try test__floatundidf(0x8000010000000000, 0x1.000002p+63);
26 test__floatundidf(0x8000000000001000, 0x1.0000000000002p+63);26 try test__floatundidf(0x8000000000001000, 0x1.0000000000002p+63);
27 test__floatundidf(0x8000000000000000, 0x1p+63);27 try test__floatundidf(0x8000000000000000, 0x1p+63);
28 test__floatundidf(0x8000000000000001, 0x1p+63);28 try test__floatundidf(0x8000000000000001, 0x1p+63);
29 test__floatundidf(0x0007FB72E8000000, 0x1.FEDCBAp+50);29 try test__floatundidf(0x0007FB72E8000000, 0x1.FEDCBAp+50);
30 test__floatundidf(0x0007FB72EA000000, 0x1.FEDCBA8p+50);30 try test__floatundidf(0x0007FB72EA000000, 0x1.FEDCBA8p+50);
31 test__floatundidf(0x0007FB72EB000000, 0x1.FEDCBACp+50);31 try test__floatundidf(0x0007FB72EB000000, 0x1.FEDCBACp+50);
32 test__floatundidf(0x0007FB72EBFFFFFF, 0x1.FEDCBAFFFFFFCp+50);32 try test__floatundidf(0x0007FB72EBFFFFFF, 0x1.FEDCBAFFFFFFCp+50);
33 test__floatundidf(0x0007FB72EC000000, 0x1.FEDCBBp+50);33 try test__floatundidf(0x0007FB72EC000000, 0x1.FEDCBBp+50);
34 test__floatundidf(0x0007FB72E8000001, 0x1.FEDCBA0000004p+50);34 try test__floatundidf(0x0007FB72E8000001, 0x1.FEDCBA0000004p+50);
35 test__floatundidf(0x0007FB72E6000000, 0x1.FEDCB98p+50);35 try test__floatundidf(0x0007FB72E6000000, 0x1.FEDCB98p+50);
36 test__floatundidf(0x0007FB72E7000000, 0x1.FEDCB9Cp+50);36 try test__floatundidf(0x0007FB72E7000000, 0x1.FEDCB9Cp+50);
37 test__floatundidf(0x0007FB72E7FFFFFF, 0x1.FEDCB9FFFFFFCp+50);37 try test__floatundidf(0x0007FB72E7FFFFFF, 0x1.FEDCB9FFFFFFCp+50);
38 test__floatundidf(0x0007FB72E4000001, 0x1.FEDCB90000004p+50);38 try test__floatundidf(0x0007FB72E4000001, 0x1.FEDCB90000004p+50);
39 test__floatundidf(0x0007FB72E4000000, 0x1.FEDCB9p+50);39 try test__floatundidf(0x0007FB72E4000000, 0x1.FEDCB9p+50);
40 test__floatundidf(0x023479FD0E092DC0, 0x1.1A3CFE870496Ep+57);40 try test__floatundidf(0x023479FD0E092DC0, 0x1.1A3CFE870496Ep+57);
41 test__floatundidf(0x023479FD0E092DA1, 0x1.1A3CFE870496Dp+57);41 try test__floatundidf(0x023479FD0E092DA1, 0x1.1A3CFE870496Dp+57);
42 test__floatundidf(0x023479FD0E092DB0, 0x1.1A3CFE870496Ep+57);42 try test__floatundidf(0x023479FD0E092DB0, 0x1.1A3CFE870496Ep+57);
43 test__floatundidf(0x023479FD0E092DB8, 0x1.1A3CFE870496Ep+57);43 try test__floatundidf(0x023479FD0E092DB8, 0x1.1A3CFE870496Ep+57);
44 test__floatundidf(0x023479FD0E092DB6, 0x1.1A3CFE870496Ep+57);44 try test__floatundidf(0x023479FD0E092DB6, 0x1.1A3CFE870496Ep+57);
45 test__floatundidf(0x023479FD0E092DBF, 0x1.1A3CFE870496Ep+57);45 try test__floatundidf(0x023479FD0E092DBF, 0x1.1A3CFE870496Ep+57);
46 test__floatundidf(0x023479FD0E092DC1, 0x1.1A3CFE870496Ep+57);46 try test__floatundidf(0x023479FD0E092DC1, 0x1.1A3CFE870496Ep+57);
47 test__floatundidf(0x023479FD0E092DC7, 0x1.1A3CFE870496Ep+57);47 try test__floatundidf(0x023479FD0E092DC7, 0x1.1A3CFE870496Ep+57);
48 test__floatundidf(0x023479FD0E092DC8, 0x1.1A3CFE870496Ep+57);48 try test__floatundidf(0x023479FD0E092DC8, 0x1.1A3CFE870496Ep+57);
49 test__floatundidf(0x023479FD0E092DCF, 0x1.1A3CFE870496Ep+57);49 try test__floatundidf(0x023479FD0E092DCF, 0x1.1A3CFE870496Ep+57);
50 test__floatundidf(0x023479FD0E092DD0, 0x1.1A3CFE870496Ep+57);50 try test__floatundidf(0x023479FD0E092DD0, 0x1.1A3CFE870496Ep+57);
51 test__floatundidf(0x023479FD0E092DD1, 0x1.1A3CFE870496Fp+57);51 try test__floatundidf(0x023479FD0E092DD1, 0x1.1A3CFE870496Fp+57);
52 test__floatundidf(0x023479FD0E092DD8, 0x1.1A3CFE870496Fp+57);52 try test__floatundidf(0x023479FD0E092DD8, 0x1.1A3CFE870496Fp+57);
53 test__floatundidf(0x023479FD0E092DDF, 0x1.1A3CFE870496Fp+57);53 try test__floatundidf(0x023479FD0E092DDF, 0x1.1A3CFE870496Fp+57);
54 test__floatundidf(0x023479FD0E092DE0, 0x1.1A3CFE870496Fp+57);54 try test__floatundidf(0x023479FD0E092DE0, 0x1.1A3CFE870496Fp+57);
55}55}
lib/std/special/compiler_rt/floatundisf.zig+24-24
...@@ -66,31 +66,31 @@ pub fn __aeabi_ul2f(arg: u64) callconv(.AAPCS) f32 {...@@ -66,31 +66,31 @@ pub fn __aeabi_ul2f(arg: u64) callconv(.AAPCS) f32 {
66 return @call(.{ .modifier = .always_inline }, __floatundisf, .{arg});66 return @call(.{ .modifier = .always_inline }, __floatundisf, .{arg});
67}67}
6868
69fn test__floatundisf(a: u64, expected: f32) void {69fn test__floatundisf(a: u64, expected: f32) !void {
70 std.testing.expectEqual(expected, __floatundisf(a));70 try std.testing.expectEqual(expected, __floatundisf(a));
71}71}
7272
73test "floatundisf" {73test "floatundisf" {
74 test__floatundisf(0, 0.0);74 try test__floatundisf(0, 0.0);
75 test__floatundisf(1, 1.0);75 try test__floatundisf(1, 1.0);
76 test__floatundisf(2, 2.0);76 try test__floatundisf(2, 2.0);
77 test__floatundisf(0x7FFFFF8000000000, 0x1.FFFFFEp+62);77 try test__floatundisf(0x7FFFFF8000000000, 0x1.FFFFFEp+62);
78 test__floatundisf(0x7FFFFF0000000000, 0x1.FFFFFCp+62);78 try test__floatundisf(0x7FFFFF0000000000, 0x1.FFFFFCp+62);
79 test__floatundisf(0x8000008000000000, 0x1p+63);79 try test__floatundisf(0x8000008000000000, 0x1p+63);
80 test__floatundisf(0x8000010000000000, 0x1.000002p+63);80 try test__floatundisf(0x8000010000000000, 0x1.000002p+63);
81 test__floatundisf(0x8000000000000000, 0x1p+63);81 try test__floatundisf(0x8000000000000000, 0x1p+63);
82 test__floatundisf(0x8000000000000001, 0x1p+63);82 try test__floatundisf(0x8000000000000001, 0x1p+63);
83 test__floatundisf(0xFFFFFFFFFFFFFFFE, 0x1p+64);83 try test__floatundisf(0xFFFFFFFFFFFFFFFE, 0x1p+64);
84 test__floatundisf(0xFFFFFFFFFFFFFFFF, 0x1p+64);84 try test__floatundisf(0xFFFFFFFFFFFFFFFF, 0x1p+64);
85 test__floatundisf(0x0007FB72E8000000, 0x1.FEDCBAp+50);85 try test__floatundisf(0x0007FB72E8000000, 0x1.FEDCBAp+50);
86 test__floatundisf(0x0007FB72EA000000, 0x1.FEDCBAp+50);86 try test__floatundisf(0x0007FB72EA000000, 0x1.FEDCBAp+50);
87 test__floatundisf(0x0007FB72EB000000, 0x1.FEDCBAp+50);87 try test__floatundisf(0x0007FB72EB000000, 0x1.FEDCBAp+50);
88 test__floatundisf(0x0007FB72EBFFFFFF, 0x1.FEDCBAp+50);88 try test__floatundisf(0x0007FB72EBFFFFFF, 0x1.FEDCBAp+50);
89 test__floatundisf(0x0007FB72EC000000, 0x1.FEDCBCp+50);89 try test__floatundisf(0x0007FB72EC000000, 0x1.FEDCBCp+50);
90 test__floatundisf(0x0007FB72E8000001, 0x1.FEDCBAp+50);90 try test__floatundisf(0x0007FB72E8000001, 0x1.FEDCBAp+50);
91 test__floatundisf(0x0007FB72E6000000, 0x1.FEDCBAp+50);91 try test__floatundisf(0x0007FB72E6000000, 0x1.FEDCBAp+50);
92 test__floatundisf(0x0007FB72E7000000, 0x1.FEDCBAp+50);92 try test__floatundisf(0x0007FB72E7000000, 0x1.FEDCBAp+50);
93 test__floatundisf(0x0007FB72E7FFFFFF, 0x1.FEDCBAp+50);93 try test__floatundisf(0x0007FB72E7FFFFFF, 0x1.FEDCBAp+50);
94 test__floatundisf(0x0007FB72E4000001, 0x1.FEDCBAp+50);94 try test__floatundisf(0x0007FB72E4000001, 0x1.FEDCBAp+50);
95 test__floatundisf(0x0007FB72E4000000, 0x1.FEDCB8p+50);95 try test__floatundisf(0x0007FB72E4000000, 0x1.FEDCB8p+50);
96}96}
lib/std/special/compiler_rt/floatunditf_test.zig+9-9
...@@ -5,7 +5,7 @@...@@ -5,7 +5,7 @@
5// and substantial portions of the software.5// and substantial portions of the software.
6const __floatunditf = @import("floatunditf.zig").__floatunditf;6const __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 {
9 const x = __floatunditf(a);9 const x = __floatunditf(a);
1010
11 const x_repr = @bitCast(u128, x);11 const x_repr = @bitCast(u128, x);
...@@ -26,12 +26,12 @@ fn test__floatunditf(a: u64, expected_hi: u64, expected_lo: u64) void {...@@ -26,12 +26,12 @@ fn test__floatunditf(a: u64, expected_hi: u64, expected_lo: u64) void {
26}26}
2727
28test "floatunditf" {28test "floatunditf" {
29 test__floatunditf(0xffffffffffffffff, 0x403effffffffffff, 0xfffe000000000000);29 try test__floatunditf(0xffffffffffffffff, 0x403effffffffffff, 0xfffe000000000000);
30 test__floatunditf(0xfffffffffffffffe, 0x403effffffffffff, 0xfffc000000000000);30 try test__floatunditf(0xfffffffffffffffe, 0x403effffffffffff, 0xfffc000000000000);
31 test__floatunditf(0x8000000000000000, 0x403e000000000000, 0x0);31 try test__floatunditf(0x8000000000000000, 0x403e000000000000, 0x0);
32 test__floatunditf(0x7fffffffffffffff, 0x403dffffffffffff, 0xfffc000000000000);32 try test__floatunditf(0x7fffffffffffffff, 0x403dffffffffffff, 0xfffc000000000000);
33 test__floatunditf(0x123456789abcdef1, 0x403b23456789abcd, 0xef10000000000000);33 try test__floatunditf(0x123456789abcdef1, 0x403b23456789abcd, 0xef10000000000000);
34 test__floatunditf(0x2, 0x4000000000000000, 0x0);34 try test__floatunditf(0x2, 0x4000000000000000, 0x0);
35 test__floatunditf(0x1, 0x3fff000000000000, 0x0);35 try test__floatunditf(0x1, 0x3fff000000000000, 0x0);
36 test__floatunditf(0x0, 0x0, 0x0);36 try test__floatunditf(0x0, 0x0, 0x0);
37}37}
lib/std/special/compiler_rt/floatunsidf.zig+7-7
...@@ -28,16 +28,16 @@ pub fn __aeabi_ui2d(arg: u32) callconv(.AAPCS) f64 {...@@ -28,16 +28,16 @@ pub fn __aeabi_ui2d(arg: u32) callconv(.AAPCS) f64 {
28 return @call(.{ .modifier = .always_inline }, __floatunsidf, .{arg});28 return @call(.{ .modifier = .always_inline }, __floatunsidf, .{arg});
29}29}
3030
31fn test_one_floatunsidf(a: u32, expected: u64) void {31fn test_one_floatunsidf(a: u32, expected: u64) !void {
32 const r = __floatunsidf(a);32 const r = __floatunsidf(a);
33 std.testing.expect(@bitCast(u64, r) == expected);33 try std.testing.expect(@bitCast(u64, r) == expected);
34}34}
3535
36test "floatsidf" {36test "floatsidf" {
37 // Test the produced bit pattern37 // Test the produced bit pattern
38 test_one_floatunsidf(0, 0x0000000000000000);38 try test_one_floatunsidf(0, 0x0000000000000000);
39 test_one_floatunsidf(1, 0x3ff0000000000000);39 try test_one_floatunsidf(1, 0x3ff0000000000000);
40 test_one_floatunsidf(0x7FFFFFFF, 0x41dfffffffc00000);40 try test_one_floatunsidf(0x7FFFFFFF, 0x41dfffffffc00000);
41 test_one_floatunsidf(@intCast(u32, 0x80000000), 0x41e0000000000000);41 try test_one_floatunsidf(@intCast(u32, 0x80000000), 0x41e0000000000000);
42 test_one_floatunsidf(@intCast(u32, 0xFFFFFFFF), 0x41efffffffe00000);42 try test_one_floatunsidf(@intCast(u32, 0xFFFFFFFF), 0x41efffffffe00000);
43}43}
lib/std/special/compiler_rt/floatunsisf.zig+7-7
...@@ -48,16 +48,16 @@ pub fn __aeabi_ui2f(arg: u32) callconv(.AAPCS) f32 {...@@ -48,16 +48,16 @@ pub fn __aeabi_ui2f(arg: u32) callconv(.AAPCS) f32 {
48 return @call(.{ .modifier = .always_inline }, __floatunsisf, .{arg});48 return @call(.{ .modifier = .always_inline }, __floatunsisf, .{arg});
49}49}
5050
51fn test_one_floatunsisf(a: u32, expected: u32) void {51fn test_one_floatunsisf(a: u32, expected: u32) !void {
52 const r = __floatunsisf(a);52 const r = __floatunsisf(a);
53 std.testing.expect(@bitCast(u32, r) == expected);53 try std.testing.expect(@bitCast(u32, r) == expected);
54}54}
5555
56test "floatunsisf" {56test "floatunsisf" {
57 // Test the produced bit pattern57 // Test the produced bit pattern
58 test_one_floatunsisf(0, 0);58 try test_one_floatunsisf(0, 0);
59 test_one_floatunsisf(1, 0x3f800000);59 try test_one_floatunsisf(1, 0x3f800000);
60 test_one_floatunsisf(0x7FFFFFFF, 0x4f000000);60 try test_one_floatunsisf(0x7FFFFFFF, 0x4f000000);
61 test_one_floatunsisf(0x80000000, 0x4f000000);61 try test_one_floatunsisf(0x80000000, 0x4f000000);
62 test_one_floatunsisf(0xFFFFFFFF, 0x4f800000);62 try test_one_floatunsisf(0xFFFFFFFF, 0x4f800000);
63}63}
lib/std/special/compiler_rt/floatunsitf_test.zig+5-5
...@@ -5,7 +5,7 @@...@@ -5,7 +5,7 @@
5// and substantial portions of the software.5// and substantial portions of the software.
6const __floatunsitf = @import("floatunsitf.zig").__floatunsitf;6const __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 {
9 const x = __floatunsitf(a);9 const x = __floatunsitf(a);
1010
11 const x_repr = @bitCast(u128, x);11 const x_repr = @bitCast(u128, x);
...@@ -26,8 +26,8 @@ fn test__floatunsitf(a: u64, expected_hi: u64, expected_lo: u64) void {...@@ -26,8 +26,8 @@ fn test__floatunsitf(a: u64, expected_hi: u64, expected_lo: u64) void {
26}26}
2727
28test "floatunsitf" {28test "floatunsitf" {
29 test__floatunsitf(0x7fffffff, 0x401dfffffffc0000, 0x0);29 try test__floatunsitf(0x7fffffff, 0x401dfffffffc0000, 0x0);
30 test__floatunsitf(0, 0x0, 0x0);30 try test__floatunsitf(0, 0x0, 0x0);
31 test__floatunsitf(0xffffffff, 0x401efffffffe0000, 0x0);31 try test__floatunsitf(0xffffffff, 0x401efffffffe0000, 0x0);
32 test__floatunsitf(0x12345678, 0x401b234567800000, 0x0);32 try test__floatunsitf(0x12345678, 0x401b234567800000, 0x0);
33}33}
lib/std/special/compiler_rt/floatuntidf_test.zig+57-57
...@@ -6,76 +6,76 @@...@@ -6,76 +6,76 @@
6const __floatuntidf = @import("floatuntidf.zig").__floatuntidf;6const __floatuntidf = @import("floatuntidf.zig").__floatuntidf;
7const testing = @import("std").testing;7const testing = @import("std").testing;
88
9fn test__floatuntidf(a: u128, expected: f64) void {9fn test__floatuntidf(a: u128, expected: f64) !void {
10 const x = __floatuntidf(a);10 const x = __floatuntidf(a);
11 testing.expect(x == expected);11 try testing.expect(x == expected);
12}12}
1313
14test "floatuntidf" {14test "floatuntidf" {
15 test__floatuntidf(0, 0.0);15 try test__floatuntidf(0, 0.0);
1616
17 test__floatuntidf(1, 1.0);17 try test__floatuntidf(1, 1.0);
18 test__floatuntidf(2, 2.0);18 try test__floatuntidf(2, 2.0);
19 test__floatuntidf(20, 20.0);19 try test__floatuntidf(20, 20.0);
2020
21 test__floatuntidf(0x7FFFFF8000000000, 0x1.FFFFFEp+62);21 try test__floatuntidf(0x7FFFFF8000000000, 0x1.FFFFFEp+62);
22 test__floatuntidf(0x7FFFFFFFFFFFF800, 0x1.FFFFFFFFFFFFEp+62);22 try test__floatuntidf(0x7FFFFFFFFFFFF800, 0x1.FFFFFFFFFFFFEp+62);
23 test__floatuntidf(0x7FFFFF0000000000, 0x1.FFFFFCp+62);23 try test__floatuntidf(0x7FFFFF0000000000, 0x1.FFFFFCp+62);
24 test__floatuntidf(0x7FFFFFFFFFFFF000, 0x1.FFFFFFFFFFFFCp+62);24 try test__floatuntidf(0x7FFFFFFFFFFFF000, 0x1.FFFFFFFFFFFFCp+62);
2525
26 test__floatuntidf(make_ti(0x8000008000000000, 0), 0x1.000001p+127);26 try test__floatuntidf(make_ti(0x8000008000000000, 0), 0x1.000001p+127);
27 test__floatuntidf(make_ti(0x8000000000000800, 0), 0x1.0000000000001p+127);27 try test__floatuntidf(make_ti(0x8000000000000800, 0), 0x1.0000000000001p+127);
28 test__floatuntidf(make_ti(0x8000010000000000, 0), 0x1.000002p+127);28 try test__floatuntidf(make_ti(0x8000010000000000, 0), 0x1.000002p+127);
29 test__floatuntidf(make_ti(0x8000000000001000, 0), 0x1.0000000000002p+127);29 try test__floatuntidf(make_ti(0x8000000000001000, 0), 0x1.0000000000002p+127);
3030
31 test__floatuntidf(make_ti(0x8000000000000000, 0), 0x1.000000p+127);31 try test__floatuntidf(make_ti(0x8000000000000000, 0), 0x1.000000p+127);
32 test__floatuntidf(make_ti(0x8000000000000001, 0), 0x1.0000000000000002p+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);36 try test__floatuntidf(0x0007FB72EA000000, 0x1.FEDCBA8p+50);
37 test__floatuntidf(0x0007FB72EB000000, 0x1.FEDCBACp+50);37 try test__floatuntidf(0x0007FB72EB000000, 0x1.FEDCBACp+50);
38 test__floatuntidf(0x0007FB72EBFFFFFF, 0x1.FEDCBAFFFFFFCp+50);38 try test__floatuntidf(0x0007FB72EBFFFFFF, 0x1.FEDCBAFFFFFFCp+50);
39 test__floatuntidf(0x0007FB72EC000000, 0x1.FEDCBBp+50);39 try test__floatuntidf(0x0007FB72EC000000, 0x1.FEDCBBp+50);
40 test__floatuntidf(0x0007FB72E8000001, 0x1.FEDCBA0000004p+50);40 try test__floatuntidf(0x0007FB72E8000001, 0x1.FEDCBA0000004p+50);
4141
42 test__floatuntidf(0x0007FB72E6000000, 0x1.FEDCB98p+50);42 try test__floatuntidf(0x0007FB72E6000000, 0x1.FEDCB98p+50);
43 test__floatuntidf(0x0007FB72E7000000, 0x1.FEDCB9Cp+50);43 try test__floatuntidf(0x0007FB72E7000000, 0x1.FEDCB9Cp+50);
44 test__floatuntidf(0x0007FB72E7FFFFFF, 0x1.FEDCB9FFFFFFCp+50);44 try test__floatuntidf(0x0007FB72E7FFFFFF, 0x1.FEDCB9FFFFFFCp+50);
45 test__floatuntidf(0x0007FB72E4000001, 0x1.FEDCB90000004p+50);45 try test__floatuntidf(0x0007FB72E4000001, 0x1.FEDCB90000004p+50);
46 test__floatuntidf(0x0007FB72E4000000, 0x1.FEDCB9p+50);46 try test__floatuntidf(0x0007FB72E4000000, 0x1.FEDCB9p+50);
4747
48 test__floatuntidf(0x023479FD0E092DC0, 0x1.1A3CFE870496Ep+57);48 try test__floatuntidf(0x023479FD0E092DC0, 0x1.1A3CFE870496Ep+57);
49 test__floatuntidf(0x023479FD0E092DA1, 0x1.1A3CFE870496Dp+57);49 try test__floatuntidf(0x023479FD0E092DA1, 0x1.1A3CFE870496Dp+57);
50 test__floatuntidf(0x023479FD0E092DB0, 0x1.1A3CFE870496Ep+57);50 try test__floatuntidf(0x023479FD0E092DB0, 0x1.1A3CFE870496Ep+57);
51 test__floatuntidf(0x023479FD0E092DB8, 0x1.1A3CFE870496Ep+57);51 try test__floatuntidf(0x023479FD0E092DB8, 0x1.1A3CFE870496Ep+57);
52 test__floatuntidf(0x023479FD0E092DB6, 0x1.1A3CFE870496Ep+57);52 try test__floatuntidf(0x023479FD0E092DB6, 0x1.1A3CFE870496Ep+57);
53 test__floatuntidf(0x023479FD0E092DBF, 0x1.1A3CFE870496Ep+57);53 try test__floatuntidf(0x023479FD0E092DBF, 0x1.1A3CFE870496Ep+57);
54 test__floatuntidf(0x023479FD0E092DC1, 0x1.1A3CFE870496Ep+57);54 try test__floatuntidf(0x023479FD0E092DC1, 0x1.1A3CFE870496Ep+57);
55 test__floatuntidf(0x023479FD0E092DC7, 0x1.1A3CFE870496Ep+57);55 try test__floatuntidf(0x023479FD0E092DC7, 0x1.1A3CFE870496Ep+57);
56 test__floatuntidf(0x023479FD0E092DC8, 0x1.1A3CFE870496Ep+57);56 try test__floatuntidf(0x023479FD0E092DC8, 0x1.1A3CFE870496Ep+57);
57 test__floatuntidf(0x023479FD0E092DCF, 0x1.1A3CFE870496Ep+57);57 try test__floatuntidf(0x023479FD0E092DCF, 0x1.1A3CFE870496Ep+57);
58 test__floatuntidf(0x023479FD0E092DD0, 0x1.1A3CFE870496Ep+57);58 try test__floatuntidf(0x023479FD0E092DD0, 0x1.1A3CFE870496Ep+57);
59 test__floatuntidf(0x023479FD0E092DD1, 0x1.1A3CFE870496Fp+57);59 try test__floatuntidf(0x023479FD0E092DD1, 0x1.1A3CFE870496Fp+57);
60 test__floatuntidf(0x023479FD0E092DD8, 0x1.1A3CFE870496Fp+57);60 try test__floatuntidf(0x023479FD0E092DD8, 0x1.1A3CFE870496Fp+57);
61 test__floatuntidf(0x023479FD0E092DDF, 0x1.1A3CFE870496Fp+57);61 try test__floatuntidf(0x023479FD0E092DDF, 0x1.1A3CFE870496Fp+57);
62 test__floatuntidf(0x023479FD0E092DE0, 0x1.1A3CFE870496Fp+57);62 try test__floatuntidf(0x023479FD0E092DE0, 0x1.1A3CFE870496Fp+57);
6363
64 test__floatuntidf(make_ti(0x023479FD0E092DC0, 0), 0x1.1A3CFE870496Ep+121);64 try test__floatuntidf(make_ti(0x023479FD0E092DC0, 0), 0x1.1A3CFE870496Ep+121);
65 test__floatuntidf(make_ti(0x023479FD0E092DA1, 1), 0x1.1A3CFE870496Dp+121);65 try test__floatuntidf(make_ti(0x023479FD0E092DA1, 1), 0x1.1A3CFE870496Dp+121);
66 test__floatuntidf(make_ti(0x023479FD0E092DB0, 2), 0x1.1A3CFE870496Ep+121);66 try test__floatuntidf(make_ti(0x023479FD0E092DB0, 2), 0x1.1A3CFE870496Ep+121);
67 test__floatuntidf(make_ti(0x023479FD0E092DB8, 3), 0x1.1A3CFE870496Ep+121);67 try test__floatuntidf(make_ti(0x023479FD0E092DB8, 3), 0x1.1A3CFE870496Ep+121);
68 test__floatuntidf(make_ti(0x023479FD0E092DB6, 4), 0x1.1A3CFE870496Ep+121);68 try test__floatuntidf(make_ti(0x023479FD0E092DB6, 4), 0x1.1A3CFE870496Ep+121);
69 test__floatuntidf(make_ti(0x023479FD0E092DBF, 5), 0x1.1A3CFE870496Ep+121);69 try test__floatuntidf(make_ti(0x023479FD0E092DBF, 5), 0x1.1A3CFE870496Ep+121);
70 test__floatuntidf(make_ti(0x023479FD0E092DC1, 6), 0x1.1A3CFE870496Ep+121);70 try test__floatuntidf(make_ti(0x023479FD0E092DC1, 6), 0x1.1A3CFE870496Ep+121);
71 test__floatuntidf(make_ti(0x023479FD0E092DC7, 7), 0x1.1A3CFE870496Ep+121);71 try test__floatuntidf(make_ti(0x023479FD0E092DC7, 7), 0x1.1A3CFE870496Ep+121);
72 test__floatuntidf(make_ti(0x023479FD0E092DC8, 8), 0x1.1A3CFE870496Ep+121);72 try test__floatuntidf(make_ti(0x023479FD0E092DC8, 8), 0x1.1A3CFE870496Ep+121);
73 test__floatuntidf(make_ti(0x023479FD0E092DCF, 9), 0x1.1A3CFE870496Ep+121);73 try test__floatuntidf(make_ti(0x023479FD0E092DCF, 9), 0x1.1A3CFE870496Ep+121);
74 test__floatuntidf(make_ti(0x023479FD0E092DD0, 0), 0x1.1A3CFE870496Ep+121);74 try test__floatuntidf(make_ti(0x023479FD0E092DD0, 0), 0x1.1A3CFE870496Ep+121);
75 test__floatuntidf(make_ti(0x023479FD0E092DD1, 11), 0x1.1A3CFE870496Fp+121);75 try test__floatuntidf(make_ti(0x023479FD0E092DD1, 11), 0x1.1A3CFE870496Fp+121);
76 test__floatuntidf(make_ti(0x023479FD0E092DD8, 12), 0x1.1A3CFE870496Fp+121);76 try test__floatuntidf(make_ti(0x023479FD0E092DD8, 12), 0x1.1A3CFE870496Fp+121);
77 test__floatuntidf(make_ti(0x023479FD0E092DDF, 13), 0x1.1A3CFE870496Fp+121);77 try test__floatuntidf(make_ti(0x023479FD0E092DDF, 13), 0x1.1A3CFE870496Fp+121);
78 test__floatuntidf(make_ti(0x023479FD0E092DE0, 14), 0x1.1A3CFE870496Fp+121);78 try test__floatuntidf(make_ti(0x023479FD0E092DE0, 14), 0x1.1A3CFE870496Fp+121);
79}79}
8080
81fn make_ti(high: u64, low: u64) u128 {81fn make_ti(high: u64, low: u64) u128 {
lib/std/special/compiler_rt/floatuntisf_test.zig+44-44
...@@ -6,67 +6,67 @@...@@ -6,67 +6,67 @@
6const __floatuntisf = @import("floatuntisf.zig").__floatuntisf;6const __floatuntisf = @import("floatuntisf.zig").__floatuntisf;
7const testing = @import("std").testing;7const testing = @import("std").testing;
88
9fn test__floatuntisf(a: u128, expected: f32) void {9fn test__floatuntisf(a: u128, expected: f32) !void {
10 const x = __floatuntisf(a);10 const x = __floatuntisf(a);
11 testing.expect(x == expected);11 try testing.expect(x == expected);
12}12}
1313
14test "floatuntisf" {14test "floatuntisf" {
15 test__floatuntisf(0, 0.0);15 try test__floatuntisf(0, 0.0);
1616
17 test__floatuntisf(1, 1.0);17 try test__floatuntisf(1, 1.0);
18 test__floatuntisf(2, 2.0);18 try test__floatuntisf(2, 2.0);
19 test__floatuntisf(20, 20.0);19 try test__floatuntisf(20, 20.0);
2020
21 test__floatuntisf(0x7FFFFF8000000000, 0x1.FFFFFEp+62);21 try test__floatuntisf(0x7FFFFF8000000000, 0x1.FFFFFEp+62);
22 test__floatuntisf(0x7FFFFF0000000000, 0x1.FFFFFCp+62);22 try test__floatuntisf(0x7FFFFF0000000000, 0x1.FFFFFCp+62);
2323
24 test__floatuntisf(make_ti(0x8000008000000000, 0), 0x1.000001p+127);24 try test__floatuntisf(make_ti(0x8000008000000000, 0), 0x1.000001p+127);
25 test__floatuntisf(make_ti(0x8000000000000800, 0), 0x1.0p+127);25 try test__floatuntisf(make_ti(0x8000000000000800, 0), 0x1.0p+127);
26 test__floatuntisf(make_ti(0x8000010000000000, 0), 0x1.000002p+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);32 try test__floatuntisf(0x0007FB72EA000000, 0x1.FEDCBA8p+50);
33 test__floatuntisf(0x0007FB72EB000000, 0x1.FEDCBACp+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);37 try test__floatuntisf(0x0007FB72E6000000, 0x1.FEDCB98p+50);
38 test__floatuntisf(0x0007FB72E7000000, 0x1.FEDCB9Cp+50);38 try test__floatuntisf(0x0007FB72E7000000, 0x1.FEDCB9Cp+50);
39 test__floatuntisf(0x0007FB72E4000000, 0x1.FEDCB9p+50);39 try test__floatuntisf(0x0007FB72E4000000, 0x1.FEDCB9p+50);
4040
41 test__floatuntisf(0xFFFFFFFFFFFFFFFE, 0x1p+64);41 try test__floatuntisf(0xFFFFFFFFFFFFFFFE, 0x1p+64);
42 test__floatuntisf(0xFFFFFFFFFFFFFFFF, 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);46 try test__floatuntisf(0x0007FB72EA000000, 0x1.FEDCBAp+50);
47 test__floatuntisf(0x0007FB72EB000000, 0x1.FEDCBAp+50);47 try test__floatuntisf(0x0007FB72EB000000, 0x1.FEDCBAp+50);
48 test__floatuntisf(0x0007FB72EBFFFFFF, 0x1.FEDCBAp+50);48 try test__floatuntisf(0x0007FB72EBFFFFFF, 0x1.FEDCBAp+50);
49 test__floatuntisf(0x0007FB72EC000000, 0x1.FEDCBCp+50);49 try test__floatuntisf(0x0007FB72EC000000, 0x1.FEDCBCp+50);
50 test__floatuntisf(0x0007FB72E8000001, 0x1.FEDCBAp+50);50 try test__floatuntisf(0x0007FB72E8000001, 0x1.FEDCBAp+50);
5151
52 test__floatuntisf(0x0007FB72E6000000, 0x1.FEDCBAp+50);52 try test__floatuntisf(0x0007FB72E6000000, 0x1.FEDCBAp+50);
53 test__floatuntisf(0x0007FB72E7000000, 0x1.FEDCBAp+50);53 try test__floatuntisf(0x0007FB72E7000000, 0x1.FEDCBAp+50);
54 test__floatuntisf(0x0007FB72E7FFFFFF, 0x1.FEDCBAp+50);54 try test__floatuntisf(0x0007FB72E7FFFFFF, 0x1.FEDCBAp+50);
55 test__floatuntisf(0x0007FB72E4000001, 0x1.FEDCBAp+50);55 try test__floatuntisf(0x0007FB72E4000001, 0x1.FEDCBAp+50);
56 test__floatuntisf(0x0007FB72E4000000, 0x1.FEDCB8p+50);56 try test__floatuntisf(0x0007FB72E4000000, 0x1.FEDCB8p+50);
5757
58 test__floatuntisf(make_ti(0x0000000000001FED, 0xCB90000000000001), 0x1.FEDCBAp+76);58 try test__floatuntisf(make_ti(0x0000000000001FED, 0xCB90000000000001), 0x1.FEDCBAp+76);
59 test__floatuntisf(make_ti(0x0000000000001FED, 0xCBA0000000000000), 0x1.FEDCBAp+76);59 try test__floatuntisf(make_ti(0x0000000000001FED, 0xCBA0000000000000), 0x1.FEDCBAp+76);
60 test__floatuntisf(make_ti(0x0000000000001FED, 0xCBAFFFFFFFFFFFFF), 0x1.FEDCBAp+76);60 try test__floatuntisf(make_ti(0x0000000000001FED, 0xCBAFFFFFFFFFFFFF), 0x1.FEDCBAp+76);
61 test__floatuntisf(make_ti(0x0000000000001FED, 0xCBB0000000000000), 0x1.FEDCBCp+76);61 try test__floatuntisf(make_ti(0x0000000000001FED, 0xCBB0000000000000), 0x1.FEDCBCp+76);
62 test__floatuntisf(make_ti(0x0000000000001FED, 0xCBB0000000000001), 0x1.FEDCBCp+76);62 try test__floatuntisf(make_ti(0x0000000000001FED, 0xCBB0000000000001), 0x1.FEDCBCp+76);
63 test__floatuntisf(make_ti(0x0000000000001FED, 0xCBBFFFFFFFFFFFFF), 0x1.FEDCBCp+76);63 try test__floatuntisf(make_ti(0x0000000000001FED, 0xCBBFFFFFFFFFFFFF), 0x1.FEDCBCp+76);
64 test__floatuntisf(make_ti(0x0000000000001FED, 0xCBC0000000000000), 0x1.FEDCBCp+76);64 try test__floatuntisf(make_ti(0x0000000000001FED, 0xCBC0000000000000), 0x1.FEDCBCp+76);
65 test__floatuntisf(make_ti(0x0000000000001FED, 0xCBC0000000000001), 0x1.FEDCBCp+76);65 try test__floatuntisf(make_ti(0x0000000000001FED, 0xCBC0000000000001), 0x1.FEDCBCp+76);
66 test__floatuntisf(make_ti(0x0000000000001FED, 0xCBD0000000000000), 0x1.FEDCBCp+76);66 try test__floatuntisf(make_ti(0x0000000000001FED, 0xCBD0000000000000), 0x1.FEDCBCp+76);
67 test__floatuntisf(make_ti(0x0000000000001FED, 0xCBD0000000000001), 0x1.FEDCBEp+76);67 try test__floatuntisf(make_ti(0x0000000000001FED, 0xCBD0000000000001), 0x1.FEDCBEp+76);
68 test__floatuntisf(make_ti(0x0000000000001FED, 0xCBDFFFFFFFFFFFFF), 0x1.FEDCBEp+76);68 try test__floatuntisf(make_ti(0x0000000000001FED, 0xCBDFFFFFFFFFFFFF), 0x1.FEDCBEp+76);
69 test__floatuntisf(make_ti(0x0000000000001FED, 0xCBE0000000000000), 0x1.FEDCBEp+76);69 try test__floatuntisf(make_ti(0x0000000000001FED, 0xCBE0000000000000), 0x1.FEDCBEp+76);
70}70}
7171
72fn make_ti(high: u64, low: u64) u128 {72fn make_ti(high: u64, low: u64) u128 {
lib/std/special/compiler_rt/floatuntitf_test.zig+72-72
...@@ -6,94 +6,94 @@...@@ -6,94 +6,94 @@
6const __floatuntitf = @import("floatuntitf.zig").__floatuntitf;6const __floatuntitf = @import("floatuntitf.zig").__floatuntitf;
7const testing = @import("std").testing;7const testing = @import("std").testing;
88
9fn test__floatuntitf(a: u128, expected: f128) void {9fn test__floatuntitf(a: u128, expected: f128) !void {
10 const x = __floatuntitf(a);10 const x = __floatuntitf(a);
11 testing.expect(x == expected);11 try testing.expect(x == expected);
12}12}
1313
14test "floatuntitf" {14test "floatuntitf" {
15 test__floatuntitf(0, 0.0);15 try test__floatuntitf(0, 0.0);
1616
17 test__floatuntitf(1, 1.0);17 try test__floatuntitf(1, 1.0);
18 test__floatuntitf(2, 2.0);18 try test__floatuntitf(2, 2.0);
19 test__floatuntitf(20, 20.0);19 try test__floatuntitf(20, 20.0);
2020
21 test__floatuntitf(0x7FFFFF8000000000, 0x1.FFFFFEp+62);21 try test__floatuntitf(0x7FFFFF8000000000, 0x1.FFFFFEp+62);
22 test__floatuntitf(0x7FFFFFFFFFFFF800, 0x1.FFFFFFFFFFFFEp+62);22 try test__floatuntitf(0x7FFFFFFFFFFFF800, 0x1.FFFFFFFFFFFFEp+62);
23 test__floatuntitf(0x7FFFFF0000000000, 0x1.FFFFFCp+62);23 try test__floatuntitf(0x7FFFFF0000000000, 0x1.FFFFFCp+62);
24 test__floatuntitf(0x7FFFFFFFFFFFF000, 0x1.FFFFFFFFFFFFCp+62);24 try test__floatuntitf(0x7FFFFFFFFFFFF000, 0x1.FFFFFFFFFFFFCp+62);
25 test__floatuntitf(0x7FFFFFFFFFFFFFFF, 0xF.FFFFFFFFFFFFFFEp+59);25 try test__floatuntitf(0x7FFFFFFFFFFFFFFF, 0xF.FFFFFFFFFFFFFFEp+59);
26 test__floatuntitf(0xFFFFFFFFFFFFFFFE, 0xF.FFFFFFFFFFFFFFEp+60);26 try test__floatuntitf(0xFFFFFFFFFFFFFFFE, 0xF.FFFFFFFFFFFFFFEp+60);
27 test__floatuntitf(0xFFFFFFFFFFFFFFFF, 0xF.FFFFFFFFFFFFFFFp+60);27 try test__floatuntitf(0xFFFFFFFFFFFFFFFF, 0xF.FFFFFFFFFFFFFFFp+60);
2828
29 test__floatuntitf(0x8000008000000000, 0x8.000008p+60);29 try test__floatuntitf(0x8000008000000000, 0x8.000008p+60);
30 test__floatuntitf(0x8000000000000800, 0x8.0000000000008p+60);30 try test__floatuntitf(0x8000000000000800, 0x8.0000000000008p+60);
31 test__floatuntitf(0x8000010000000000, 0x8.00001p+60);31 try test__floatuntitf(0x8000010000000000, 0x8.00001p+60);
32 test__floatuntitf(0x8000000000001000, 0x8.000000000001p+60);32 try test__floatuntitf(0x8000000000001000, 0x8.000000000001p+60);
3333
34 test__floatuntitf(0x8000000000000000, 0x8p+60);34 try test__floatuntitf(0x8000000000000000, 0x8p+60);
35 test__floatuntitf(0x8000000000000001, 0x8.000000000000001p+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);39 try test__floatuntitf(0x0007FB72EA000000, 0x1.FEDCBA8p+50);
40 test__floatuntitf(0x0007FB72EB000000, 0x1.FEDCBACp+50);40 try test__floatuntitf(0x0007FB72EB000000, 0x1.FEDCBACp+50);
41 test__floatuntitf(0x0007FB72EBFFFFFF, 0x1.FEDCBAFFFFFFCp+50);41 try test__floatuntitf(0x0007FB72EBFFFFFF, 0x1.FEDCBAFFFFFFCp+50);
42 test__floatuntitf(0x0007FB72EC000000, 0x1.FEDCBBp+50);42 try test__floatuntitf(0x0007FB72EC000000, 0x1.FEDCBBp+50);
43 test__floatuntitf(0x0007FB72E8000001, 0x1.FEDCBA0000004p+50);43 try test__floatuntitf(0x0007FB72E8000001, 0x1.FEDCBA0000004p+50);
4444
45 test__floatuntitf(0x0007FB72E6000000, 0x1.FEDCB98p+50);45 try test__floatuntitf(0x0007FB72E6000000, 0x1.FEDCB98p+50);
46 test__floatuntitf(0x0007FB72E7000000, 0x1.FEDCB9Cp+50);46 try test__floatuntitf(0x0007FB72E7000000, 0x1.FEDCB9Cp+50);
47 test__floatuntitf(0x0007FB72E7FFFFFF, 0x1.FEDCB9FFFFFFCp+50);47 try test__floatuntitf(0x0007FB72E7FFFFFF, 0x1.FEDCB9FFFFFFCp+50);
48 test__floatuntitf(0x0007FB72E4000001, 0x1.FEDCB90000004p+50);48 try test__floatuntitf(0x0007FB72E4000001, 0x1.FEDCB90000004p+50);
49 test__floatuntitf(0x0007FB72E4000000, 0x1.FEDCB9p+50);49 try test__floatuntitf(0x0007FB72E4000000, 0x1.FEDCB9p+50);
5050
51 test__floatuntitf(0x023479FD0E092DC0, 0x1.1A3CFE870496Ep+57);51 try test__floatuntitf(0x023479FD0E092DC0, 0x1.1A3CFE870496Ep+57);
52 test__floatuntitf(0x023479FD0E092DA1, 0x1.1A3CFE870496D08p+57);52 try test__floatuntitf(0x023479FD0E092DA1, 0x1.1A3CFE870496D08p+57);
53 test__floatuntitf(0x023479FD0E092DB0, 0x1.1A3CFE870496D8p+57);53 try test__floatuntitf(0x023479FD0E092DB0, 0x1.1A3CFE870496D8p+57);
54 test__floatuntitf(0x023479FD0E092DB8, 0x1.1A3CFE870496DCp+57);54 try test__floatuntitf(0x023479FD0E092DB8, 0x1.1A3CFE870496DCp+57);
55 test__floatuntitf(0x023479FD0E092DB6, 0x1.1A3CFE870496DBp+57);55 try test__floatuntitf(0x023479FD0E092DB6, 0x1.1A3CFE870496DBp+57);
56 test__floatuntitf(0x023479FD0E092DBF, 0x1.1A3CFE870496DF8p+57);56 try test__floatuntitf(0x023479FD0E092DBF, 0x1.1A3CFE870496DF8p+57);
57 test__floatuntitf(0x023479FD0E092DC1, 0x1.1A3CFE870496E08p+57);57 try test__floatuntitf(0x023479FD0E092DC1, 0x1.1A3CFE870496E08p+57);
58 test__floatuntitf(0x023479FD0E092DC7, 0x1.1A3CFE870496E38p+57);58 try test__floatuntitf(0x023479FD0E092DC7, 0x1.1A3CFE870496E38p+57);
59 test__floatuntitf(0x023479FD0E092DC8, 0x1.1A3CFE870496E4p+57);59 try test__floatuntitf(0x023479FD0E092DC8, 0x1.1A3CFE870496E4p+57);
60 test__floatuntitf(0x023479FD0E092DCF, 0x1.1A3CFE870496E78p+57);60 try test__floatuntitf(0x023479FD0E092DCF, 0x1.1A3CFE870496E78p+57);
61 test__floatuntitf(0x023479FD0E092DD0, 0x1.1A3CFE870496E8p+57);61 try test__floatuntitf(0x023479FD0E092DD0, 0x1.1A3CFE870496E8p+57);
62 test__floatuntitf(0x023479FD0E092DD1, 0x1.1A3CFE870496E88p+57);62 try test__floatuntitf(0x023479FD0E092DD1, 0x1.1A3CFE870496E88p+57);
63 test__floatuntitf(0x023479FD0E092DD8, 0x1.1A3CFE870496ECp+57);63 try test__floatuntitf(0x023479FD0E092DD8, 0x1.1A3CFE870496ECp+57);
64 test__floatuntitf(0x023479FD0E092DDF, 0x1.1A3CFE870496EF8p+57);64 try test__floatuntitf(0x023479FD0E092DDF, 0x1.1A3CFE870496EF8p+57);
65 test__floatuntitf(0x023479FD0E092DE0, 0x1.1A3CFE870496Fp+57);65 try test__floatuntitf(0x023479FD0E092DE0, 0x1.1A3CFE870496Fp+57);
6666
67 test__floatuntitf(make_ti(0x023479FD0E092DC0, 0), 0x1.1A3CFE870496Ep+121);67 try test__floatuntitf(make_ti(0x023479FD0E092DC0, 0), 0x1.1A3CFE870496Ep+121);
68 test__floatuntitf(make_ti(0x023479FD0E092DA1, 1), 0x1.1A3CFE870496D08p+121);68 try test__floatuntitf(make_ti(0x023479FD0E092DA1, 1), 0x1.1A3CFE870496D08p+121);
69 test__floatuntitf(make_ti(0x023479FD0E092DB0, 2), 0x1.1A3CFE870496D8p+121);69 try test__floatuntitf(make_ti(0x023479FD0E092DB0, 2), 0x1.1A3CFE870496D8p+121);
70 test__floatuntitf(make_ti(0x023479FD0E092DB8, 3), 0x1.1A3CFE870496DCp+121);70 try test__floatuntitf(make_ti(0x023479FD0E092DB8, 3), 0x1.1A3CFE870496DCp+121);
71 test__floatuntitf(make_ti(0x023479FD0E092DB6, 4), 0x1.1A3CFE870496DBp+121);71 try test__floatuntitf(make_ti(0x023479FD0E092DB6, 4), 0x1.1A3CFE870496DBp+121);
72 test__floatuntitf(make_ti(0x023479FD0E092DBF, 5), 0x1.1A3CFE870496DF8p+121);72 try test__floatuntitf(make_ti(0x023479FD0E092DBF, 5), 0x1.1A3CFE870496DF8p+121);
73 test__floatuntitf(make_ti(0x023479FD0E092DC1, 6), 0x1.1A3CFE870496E08p+121);73 try test__floatuntitf(make_ti(0x023479FD0E092DC1, 6), 0x1.1A3CFE870496E08p+121);
74 test__floatuntitf(make_ti(0x023479FD0E092DC7, 7), 0x1.1A3CFE870496E38p+121);74 try test__floatuntitf(make_ti(0x023479FD0E092DC7, 7), 0x1.1A3CFE870496E38p+121);
75 test__floatuntitf(make_ti(0x023479FD0E092DC8, 8), 0x1.1A3CFE870496E4p+121);75 try test__floatuntitf(make_ti(0x023479FD0E092DC8, 8), 0x1.1A3CFE870496E4p+121);
76 test__floatuntitf(make_ti(0x023479FD0E092DCF, 9), 0x1.1A3CFE870496E78p+121);76 try test__floatuntitf(make_ti(0x023479FD0E092DCF, 9), 0x1.1A3CFE870496E78p+121);
77 test__floatuntitf(make_ti(0x023479FD0E092DD0, 0), 0x1.1A3CFE870496E8p+121);77 try test__floatuntitf(make_ti(0x023479FD0E092DD0, 0), 0x1.1A3CFE870496E8p+121);
78 test__floatuntitf(make_ti(0x023479FD0E092DD1, 11), 0x1.1A3CFE870496E88p+121);78 try test__floatuntitf(make_ti(0x023479FD0E092DD1, 11), 0x1.1A3CFE870496E88p+121);
79 test__floatuntitf(make_ti(0x023479FD0E092DD8, 12), 0x1.1A3CFE870496ECp+121);79 try test__floatuntitf(make_ti(0x023479FD0E092DD8, 12), 0x1.1A3CFE870496ECp+121);
80 test__floatuntitf(make_ti(0x023479FD0E092DDF, 13), 0x1.1A3CFE870496EF8p+121);80 try test__floatuntitf(make_ti(0x023479FD0E092DDF, 13), 0x1.1A3CFE870496EF8p+121);
81 test__floatuntitf(make_ti(0x023479FD0E092DE0, 14), 0x1.1A3CFE870496Fp+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);85 try test__floatuntitf(make_ti(0xFFFFFFFFFFFFFFFF, 0x0000000000000000), 0x1.FFFFFFFFFFFFFFFEp+127);
86 test__floatuntitf(make_ti(0xFFFFFFFFFFFFFFFF, 0xFFFFFFFFFFFFFFFF), 0x1.0000000000000000p+128);86 try test__floatuntitf(make_ti(0xFFFFFFFFFFFFFFFF, 0xFFFFFFFFFFFFFFFF), 0x1.0000000000000000p+128);
8787
88 test__floatuntitf(make_ti(0x123456789ABCDEF0, 0x123456789ABC2801), 0x1.23456789ABCDEF0123456789ABC3p+124);88 try test__floatuntitf(make_ti(0x123456789ABCDEF0, 0x123456789ABC2801), 0x1.23456789ABCDEF0123456789ABC3p+124);
89 test__floatuntitf(make_ti(0x123456789ABCDEF0, 0x123456789ABC3000), 0x1.23456789ABCDEF0123456789ABC3p+124);89 try test__floatuntitf(make_ti(0x123456789ABCDEF0, 0x123456789ABC3000), 0x1.23456789ABCDEF0123456789ABC3p+124);
90 test__floatuntitf(make_ti(0x123456789ABCDEF0, 0x123456789ABC37FF), 0x1.23456789ABCDEF0123456789ABC3p+124);90 try test__floatuntitf(make_ti(0x123456789ABCDEF0, 0x123456789ABC37FF), 0x1.23456789ABCDEF0123456789ABC3p+124);
91 test__floatuntitf(make_ti(0x123456789ABCDEF0, 0x123456789ABC3800), 0x1.23456789ABCDEF0123456789ABC4p+124);91 try test__floatuntitf(make_ti(0x123456789ABCDEF0, 0x123456789ABC3800), 0x1.23456789ABCDEF0123456789ABC4p+124);
92 test__floatuntitf(make_ti(0x123456789ABCDEF0, 0x123456789ABC4000), 0x1.23456789ABCDEF0123456789ABC4p+124);92 try test__floatuntitf(make_ti(0x123456789ABCDEF0, 0x123456789ABC4000), 0x1.23456789ABCDEF0123456789ABC4p+124);
93 test__floatuntitf(make_ti(0x123456789ABCDEF0, 0x123456789ABC47FF), 0x1.23456789ABCDEF0123456789ABC4p+124);93 try test__floatuntitf(make_ti(0x123456789ABCDEF0, 0x123456789ABC47FF), 0x1.23456789ABCDEF0123456789ABC4p+124);
94 test__floatuntitf(make_ti(0x123456789ABCDEF0, 0x123456789ABC4800), 0x1.23456789ABCDEF0123456789ABC4p+124);94 try test__floatuntitf(make_ti(0x123456789ABCDEF0, 0x123456789ABC4800), 0x1.23456789ABCDEF0123456789ABC4p+124);
95 test__floatuntitf(make_ti(0x123456789ABCDEF0, 0x123456789ABC4801), 0x1.23456789ABCDEF0123456789ABC5p+124);95 try test__floatuntitf(make_ti(0x123456789ABCDEF0, 0x123456789ABC4801), 0x1.23456789ABCDEF0123456789ABC5p+124);
96 test__floatuntitf(make_ti(0x123456789ABCDEF0, 0x123456789ABC57FF), 0x1.23456789ABCDEF0123456789ABC5p+124);96 try test__floatuntitf(make_ti(0x123456789ABCDEF0, 0x123456789ABC57FF), 0x1.23456789ABCDEF0123456789ABC5p+124);
97}97}
9898
99fn make_ti(high: u64, low: u64) u128 {99fn make_ti(high: u64, low: u64) u128 {
lib/std/special/compiler_rt/int.zig+65-65
...@@ -58,13 +58,13 @@ test "test_divdi3" {...@@ -58,13 +58,13 @@ test "test_divdi3" {
58 };58 };
5959
60 for (cases) |case| {60 for (cases) |case| {
61 test_one_divdi3(case[0], case[1], case[2]);61 try test_one_divdi3(case[0], case[1], case[2]);
62 }62 }
63}63}
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 {
66 const q: i64 = __divdi3(a, b);66 const q: i64 = __divdi3(a, b);
67 testing.expect(q == expected_q);67 try testing.expect(q == expected_q);
68}68}
6969
70pub fn __moddi3(a: i64, b: i64) callconv(.C) i64 {70pub fn __moddi3(a: i64, b: i64) callconv(.C) i64 {
...@@ -98,13 +98,13 @@ test "test_moddi3" {...@@ -98,13 +98,13 @@ test "test_moddi3" {
98 };98 };
9999
100 for (cases) |case| {100 for (cases) |case| {
101 test_one_moddi3(case[0], case[1], case[2]);101 try test_one_moddi3(case[0], case[1], case[2]);
102 }102 }
103}103}
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 {
106 const r: i64 = __moddi3(a, b);106 const r: i64 = __moddi3(a, b);
107 testing.expect(r == expected_r);107 try testing.expect(r == expected_r);
108}108}
109109
110pub fn __udivdi3(a: u64, b: u64) callconv(.C) u64 {110pub fn __udivdi3(a: u64, b: u64) callconv(.C) u64 {
...@@ -121,16 +121,16 @@ pub fn __umoddi3(a: u64, b: u64) callconv(.C) u64 {...@@ -121,16 +121,16 @@ pub fn __umoddi3(a: u64, b: u64) callconv(.C) u64 {
121}121}
122122
123test "test_umoddi3" {123test "test_umoddi3" {
124 test_one_umoddi3(0, 1, 0);124 try test_one_umoddi3(0, 1, 0);
125 test_one_umoddi3(2, 1, 0);125 try test_one_umoddi3(2, 1, 0);
126 test_one_umoddi3(0x8000000000000000, 1, 0x0);126 try test_one_umoddi3(0x8000000000000000, 1, 0x0);
127 test_one_umoddi3(0x8000000000000000, 2, 0x0);127 try test_one_umoddi3(0x8000000000000000, 2, 0x0);
128 test_one_umoddi3(0xFFFFFFFFFFFFFFFF, 2, 0x1);128 try test_one_umoddi3(0xFFFFFFFFFFFFFFFF, 2, 0x1);
129}129}
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 {
132 const r = __umoddi3(a, b);132 const r = __umoddi3(a, b);
133 testing.expect(r == expected_r);133 try testing.expect(r == expected_r);
134}134}
135135
136pub fn __divmodsi4(a: i32, b: i32, rem: *i32) callconv(.C) i32 {136pub fn __divmodsi4(a: i32, b: i32, rem: *i32) callconv(.C) i32 {
...@@ -159,14 +159,14 @@ test "test_divmodsi4" {...@@ -159,14 +159,14 @@ test "test_divmodsi4" {
159 };159 };
160160
161 for (cases) |case| {161 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]);
163 }163 }
164}164}
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 {
167 var r: i32 = undefined;167 var r: i32 = undefined;
168 const q: i32 = __divmodsi4(a, b, &r);168 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);
170}170}
171171
172pub fn __udivmodsi4(a: u32, b: u32, rem: *u32) callconv(.C) u32 {172pub fn __udivmodsi4(a: u32, b: u32, rem: *u32) callconv(.C) u32 {
...@@ -207,13 +207,13 @@ test "test_divsi3" {...@@ -207,13 +207,13 @@ test "test_divsi3" {
207 };207 };
208208
209 for (cases) |case| {209 for (cases) |case| {
210 test_one_divsi3(case[0], case[1], case[2]);210 try test_one_divsi3(case[0], case[1], case[2]);
211 }211 }
212}212}
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 {
215 const q: i32 = __divsi3(a, b);215 const q: i32 = __divsi3(a, b);
216 testing.expect(q == expected_q);216 try testing.expect(q == expected_q);
217}217}
218218
219pub fn __udivsi3(n: u32, d: u32) callconv(.C) u32 {219pub fn __udivsi3(n: u32, d: u32) callconv(.C) u32 {
...@@ -394,13 +394,13 @@ test "test_udivsi3" {...@@ -394,13 +394,13 @@ test "test_udivsi3" {
394 };394 };
395395
396 for (cases) |case| {396 for (cases) |case| {
397 test_one_udivsi3(case[0], case[1], case[2]);397 try test_one_udivsi3(case[0], case[1], case[2]);
398 }398 }
399}399}
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 {
402 const q: u32 = __udivsi3(a, b);402 const q: u32 = __udivsi3(a, b);
403 testing.expect(q == expected_q);403 try testing.expect(q == expected_q);
404}404}
405405
406pub fn __modsi3(n: i32, d: i32) callconv(.C) i32 {406pub fn __modsi3(n: i32, d: i32) callconv(.C) i32 {
...@@ -425,13 +425,13 @@ test "test_modsi3" {...@@ -425,13 +425,13 @@ test "test_modsi3" {
425 };425 };
426426
427 for (cases) |case| {427 for (cases) |case| {
428 test_one_modsi3(case[0], case[1], case[2]);428 try test_one_modsi3(case[0], case[1], case[2]);
429 }429 }
430}430}
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 {
433 const r: i32 = __modsi3(a, b);433 const r: i32 = __modsi3(a, b);
434 testing.expect(r == expected_r);434 try testing.expect(r == expected_r);
435}435}
436436
437pub fn __umodsi3(n: u32, d: u32) callconv(.C) u32 {437pub fn __umodsi3(n: u32, d: u32) callconv(.C) u32 {
...@@ -577,13 +577,13 @@ test "test_umodsi3" {...@@ -577,13 +577,13 @@ test "test_umodsi3" {
577 };577 };
578578
579 for (cases) |case| {579 for (cases) |case| {
580 test_one_umodsi3(case[0], case[1], case[2]);580 try test_one_umodsi3(case[0], case[1], case[2]);
581 }581 }
582}582}
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 {
585 const r: u32 = __umodsi3(a, b);585 const r: u32 = __umodsi3(a, b);
586 testing.expect(r == expected_r);586 try testing.expect(r == expected_r);
587}587}
588588
589pub fn __mulsi3(a: i32, b: i32) callconv(.C) i32 {589pub fn __mulsi3(a: i32, b: i32) callconv(.C) i32 {
...@@ -602,44 +602,44 @@ pub fn __mulsi3(a: i32, b: i32) callconv(.C) i32 {...@@ -602,44 +602,44 @@ pub fn __mulsi3(a: i32, b: i32) callconv(.C) i32 {
602 return @bitCast(i32, r);602 return @bitCast(i32, r);
603}603}
604604
605fn test_one_mulsi3(a: i32, b: i32, result: i32) void {605fn test_one_mulsi3(a: i32, b: i32, result: i32) !void {
606 testing.expectEqual(result, __mulsi3(a, b));606 try testing.expectEqual(result, __mulsi3(a, b));
607}607}
608608
609test "mulsi3" {609test "mulsi3" {
610 test_one_mulsi3(0, 0, 0);610 try test_one_mulsi3(0, 0, 0);
611 test_one_mulsi3(0, 1, 0);611 try test_one_mulsi3(0, 1, 0);
612 test_one_mulsi3(1, 0, 0);612 try test_one_mulsi3(1, 0, 0);
613 test_one_mulsi3(0, 10, 0);613 try test_one_mulsi3(0, 10, 0);
614 test_one_mulsi3(10, 0, 0);614 try test_one_mulsi3(10, 0, 0);
615 test_one_mulsi3(0, maxInt(i32), 0);615 try test_one_mulsi3(0, maxInt(i32), 0);
616 test_one_mulsi3(maxInt(i32), 0, 0);616 try test_one_mulsi3(maxInt(i32), 0, 0);
617 test_one_mulsi3(0, -1, 0);617 try test_one_mulsi3(0, -1, 0);
618 test_one_mulsi3(-1, 0, 0);618 try test_one_mulsi3(-1, 0, 0);
619 test_one_mulsi3(0, -10, 0);619 try test_one_mulsi3(0, -10, 0);
620 test_one_mulsi3(-10, 0, 0);620 try test_one_mulsi3(-10, 0, 0);
621 test_one_mulsi3(0, minInt(i32), 0);621 try test_one_mulsi3(0, minInt(i32), 0);
622 test_one_mulsi3(minInt(i32), 0, 0);622 try test_one_mulsi3(minInt(i32), 0, 0);
623 test_one_mulsi3(1, 1, 1);623 try test_one_mulsi3(1, 1, 1);
624 test_one_mulsi3(1, 10, 10);624 try test_one_mulsi3(1, 10, 10);
625 test_one_mulsi3(10, 1, 10);625 try test_one_mulsi3(10, 1, 10);
626 test_one_mulsi3(1, maxInt(i32), maxInt(i32));626 try test_one_mulsi3(1, maxInt(i32), maxInt(i32));
627 test_one_mulsi3(maxInt(i32), 1, maxInt(i32));627 try test_one_mulsi3(maxInt(i32), 1, maxInt(i32));
628 test_one_mulsi3(1, -1, -1);628 try test_one_mulsi3(1, -1, -1);
629 test_one_mulsi3(1, -10, -10);629 try test_one_mulsi3(1, -10, -10);
630 test_one_mulsi3(-10, 1, -10);630 try test_one_mulsi3(-10, 1, -10);
631 test_one_mulsi3(1, minInt(i32), minInt(i32));631 try test_one_mulsi3(1, minInt(i32), minInt(i32));
632 test_one_mulsi3(minInt(i32), 1, minInt(i32));632 try test_one_mulsi3(minInt(i32), 1, minInt(i32));
633 test_one_mulsi3(46340, 46340, 2147395600);633 try test_one_mulsi3(46340, 46340, 2147395600);
634 test_one_mulsi3(-46340, 46340, -2147395600);634 try test_one_mulsi3(-46340, 46340, -2147395600);
635 test_one_mulsi3(46340, -46340, -2147395600);635 try test_one_mulsi3(46340, -46340, -2147395600);
636 test_one_mulsi3(-46340, -46340, 2147395600);636 try test_one_mulsi3(-46340, -46340, 2147395600);
637 test_one_mulsi3(4194303, 8192, @truncate(i32, 34359730176));637 try test_one_mulsi3(4194303, 8192, @truncate(i32, 34359730176));
638 test_one_mulsi3(-4194303, 8192, @truncate(i32, -34359730176));638 try test_one_mulsi3(-4194303, 8192, @truncate(i32, -34359730176));
639 test_one_mulsi3(4194303, -8192, @truncate(i32, -34359730176));639 try test_one_mulsi3(4194303, -8192, @truncate(i32, -34359730176));
640 test_one_mulsi3(-4194303, -8192, @truncate(i32, 34359730176));640 try test_one_mulsi3(-4194303, -8192, @truncate(i32, 34359730176));
641 test_one_mulsi3(8192, 4194303, @truncate(i32, 34359730176));641 try test_one_mulsi3(8192, 4194303, @truncate(i32, 34359730176));
642 test_one_mulsi3(-8192, 4194303, @truncate(i32, -34359730176));642 try test_one_mulsi3(-8192, 4194303, @truncate(i32, -34359730176));
643 test_one_mulsi3(8192, -4194303, @truncate(i32, -34359730176));643 try test_one_mulsi3(8192, -4194303, @truncate(i32, -34359730176));
644 test_one_mulsi3(-8192, -4194303, @truncate(i32, 34359730176));644 try test_one_mulsi3(-8192, -4194303, @truncate(i32, 34359730176));
645}645}
lib/std/special/compiler_rt/lshrdi3_test.zig+47-47
...@@ -6,55 +6,55 @@...@@ -6,55 +6,55 @@
6const __lshrdi3 = @import("shift.zig").__lshrdi3;6const __lshrdi3 = @import("shift.zig").__lshrdi3;
7const testing = @import("std").testing;7const 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 {
10 const x = __lshrdi3(a, b);10 const x = __lshrdi3(a, b);
11 testing.expectEqual(@bitCast(i64, expected), x);11 try testing.expectEqual(@bitCast(i64, expected), x);
12}12}
1313
14test "lshrdi3" {14test "lshrdi3" {
15 test__lshrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 0, 0x123456789ABCDEF);15 try test__lshrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 0, 0x123456789ABCDEF);
16 test__lshrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 1, 0x91A2B3C4D5E6F7);16 try test__lshrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 1, 0x91A2B3C4D5E6F7);
17 test__lshrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 2, 0x48D159E26AF37B);17 try test__lshrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 2, 0x48D159E26AF37B);
18 test__lshrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 3, 0x2468ACF13579BD);18 try test__lshrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 3, 0x2468ACF13579BD);
19 test__lshrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 4, 0x123456789ABCDE);19 try test__lshrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 4, 0x123456789ABCDE);
2020
21 test__lshrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 28, 0x12345678);21 try test__lshrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 28, 0x12345678);
22 test__lshrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 29, 0x91A2B3C);22 try test__lshrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 29, 0x91A2B3C);
23 test__lshrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 30, 0x48D159E);23 try test__lshrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 30, 0x48D159E);
24 test__lshrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 31, 0x2468ACF);24 try test__lshrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 31, 0x2468ACF);
2525
26 test__lshrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 32, 0x1234567);26 try test__lshrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 32, 0x1234567);
2727
28 test__lshrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 33, 0x91A2B3);28 try test__lshrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 33, 0x91A2B3);
29 test__lshrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 34, 0x48D159);29 try test__lshrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 34, 0x48D159);
30 test__lshrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 35, 0x2468AC);30 try test__lshrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 35, 0x2468AC);
31 test__lshrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 36, 0x123456);31 try test__lshrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 36, 0x123456);
3232
33 test__lshrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 60, 0);33 try test__lshrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 60, 0);
34 test__lshrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 61, 0);34 try test__lshrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 61, 0);
35 test__lshrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 62, 0);35 try test__lshrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 62, 0);
36 test__lshrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 63, 0);36 try test__lshrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 63, 0);
3737
38 test__lshrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 0, 0xFEDCBA9876543210);38 try test__lshrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 0, 0xFEDCBA9876543210);
39 test__lshrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 1, 0x7F6E5D4C3B2A1908);39 try test__lshrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 1, 0x7F6E5D4C3B2A1908);
40 test__lshrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 2, 0x3FB72EA61D950C84);40 try test__lshrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 2, 0x3FB72EA61D950C84);
41 test__lshrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 3, 0x1FDB97530ECA8642);41 try test__lshrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 3, 0x1FDB97530ECA8642);
42 test__lshrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 4, 0xFEDCBA987654321);42 try test__lshrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 4, 0xFEDCBA987654321);
4343
44 test__lshrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 28, 0xFEDCBA987);44 try test__lshrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 28, 0xFEDCBA987);
45 test__lshrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 29, 0x7F6E5D4C3);45 try test__lshrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 29, 0x7F6E5D4C3);
46 test__lshrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 30, 0x3FB72EA61);46 try test__lshrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 30, 0x3FB72EA61);
47 test__lshrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 31, 0x1FDB97530);47 try test__lshrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 31, 0x1FDB97530);
4848
49 test__lshrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 32, 0xFEDCBA98);49 try test__lshrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 32, 0xFEDCBA98);
5050
51 test__lshrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 33, 0x7F6E5D4C);51 try test__lshrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 33, 0x7F6E5D4C);
52 test__lshrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 34, 0x3FB72EA6);52 try test__lshrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 34, 0x3FB72EA6);
53 test__lshrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 35, 0x1FDB9753);53 try test__lshrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 35, 0x1FDB9753);
54 test__lshrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 36, 0xFEDCBA9);54 try test__lshrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 36, 0xFEDCBA9);
5555
56 test__lshrdi3(@bitCast(i64, @as(u64, 0xAEDCBA9876543210)), 60, 0xA);56 try test__lshrdi3(@bitCast(i64, @as(u64, 0xAEDCBA9876543210)), 60, 0xA);
57 test__lshrdi3(@bitCast(i64, @as(u64, 0xAEDCBA9876543210)), 61, 0x5);57 try test__lshrdi3(@bitCast(i64, @as(u64, 0xAEDCBA9876543210)), 61, 0x5);
58 test__lshrdi3(@bitCast(i64, @as(u64, 0xAEDCBA9876543210)), 62, 0x2);58 try test__lshrdi3(@bitCast(i64, @as(u64, 0xAEDCBA9876543210)), 62, 0x2);
59 test__lshrdi3(@bitCast(i64, @as(u64, 0xAEDCBA9876543210)), 63, 0x1);59 try test__lshrdi3(@bitCast(i64, @as(u64, 0xAEDCBA9876543210)), 63, 0x1);
60}60}
lib/std/special/compiler_rt/lshrti3_test.zig+38-38
...@@ -6,46 +6,46 @@...@@ -6,46 +6,46 @@
6const __lshrti3 = @import("shift.zig").__lshrti3;6const __lshrti3 = @import("shift.zig").__lshrti3;
7const testing = @import("std").testing;7const 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 {
10 const x = __lshrti3(a, b);10 const x = __lshrti3(a, b);
11 testing.expectEqual(expected, x);11 try testing.expectEqual(expected, x);
12}12}
1313
14test "lshrti3" {14test "lshrti3" {
15 test__lshrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 0, @bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)));15 try 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)));16 try 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)));17 try 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)));18 try 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)));19 try 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)));20 try 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)));21 try 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)));22 try 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)));23 try 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)));24 try 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)));25 try 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)));26 try 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)));27 try 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)));28 try 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)));29 try 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)));30 try 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)));31 try 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)));32 try 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)));33 try 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)));34 try 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)));35 try 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)));36 try 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)));37 try 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)));38 try 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)));39 try 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)));40 try 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)));41 try 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)));42 try 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)));43 try 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)));44 try 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)));45 try 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)));46 try 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)));47 try 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)));48 try 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)));49 try 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)));50 try test__lshrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 127, @bitCast(i128, @intCast(u128, 0x00000000000000000000000000000001)));
51}51}
lib/std/special/compiler_rt/modti3_test.zig+20-20
...@@ -6,32 +6,32 @@...@@ -6,32 +6,32 @@
6const __modti3 = @import("modti3.zig").__modti3;6const __modti3 = @import("modti3.zig").__modti3;
7const testing = @import("std").testing;7const 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 {
10 const x = __modti3(a, b);10 const x = __modti3(a, b);
11 testing.expect(x == expected);11 try testing.expect(x == expected);
12}12}
1313
14test "modti3" {14test "modti3" {
15 test__modti3(0, 1, 0);15 try test__modti3(0, 1, 0);
16 test__modti3(0, -1, 0);16 try test__modti3(0, -1, 0);
17 test__modti3(5, 3, 2);17 try test__modti3(5, 3, 2);
18 test__modti3(5, -3, 2);18 try test__modti3(5, -3, 2);
19 test__modti3(-5, 3, -2);19 try test__modti3(-5, 3, -2);
20 test__modti3(-5, -3, -2);20 try test__modti3(-5, -3, -2);
2121
22 test__modti3(0x8000000000000000, 1, 0x0);22 try test__modti3(0x8000000000000000, 1, 0x0);
23 test__modti3(0x8000000000000000, -1, 0x0);23 try test__modti3(0x8000000000000000, -1, 0x0);
24 test__modti3(0x8000000000000000, 2, 0x0);24 try test__modti3(0x8000000000000000, 2, 0x0);
25 test__modti3(0x8000000000000000, -2, 0x0);25 try test__modti3(0x8000000000000000, -2, 0x0);
26 test__modti3(0x8000000000000000, 3, 2);26 try test__modti3(0x8000000000000000, 3, 2);
27 test__modti3(0x8000000000000000, -3, 2);27 try test__modti3(0x8000000000000000, -3, 2);
2828
29 test__modti3(make_ti(0x8000000000000000, 0), 1, 0x0);29 try test__modti3(make_ti(0x8000000000000000, 0), 1, 0x0);
30 test__modti3(make_ti(0x8000000000000000, 0), -1, 0x0);30 try test__modti3(make_ti(0x8000000000000000, 0), -1, 0x0);
31 test__modti3(make_ti(0x8000000000000000, 0), 2, 0x0);31 try test__modti3(make_ti(0x8000000000000000, 0), 2, 0x0);
32 test__modti3(make_ti(0x8000000000000000, 0), -2, 0x0);32 try test__modti3(make_ti(0x8000000000000000, 0), -2, 0x0);
33 test__modti3(make_ti(0x8000000000000000, 0), 3, -2);33 try test__modti3(make_ti(0x8000000000000000, 0), 3, -2);
34 test__modti3(make_ti(0x8000000000000000, 0), -3, -2);34 try test__modti3(make_ti(0x8000000000000000, 0), -3, -2);
35}35}
3636
37fn make_ti(high: u64, low: u64) i128 {37fn 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 {...@@ -34,7 +34,7 @@ fn compareResultLD(result: f128, expectedHi: u64, expectedLo: u64) bool {
34 return false;34 return false;
35}35}
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 {
38 const x = __multf3(a, b);38 const x = __multf3(a, b);
3939
40 if (compareResultLD(x, expected_hi, expected_lo))40 if (compareResultLD(x, expected_hi, expected_lo))
...@@ -50,42 +50,42 @@ fn makeNaN128(rand: u64) f128 {...@@ -50,42 +50,42 @@ fn makeNaN128(rand: u64) f128 {
50}50}
51test "multf3" {51test "multf3" {
52 // qNaN * any = qNaN52 // qNaN * any = qNaN
53 test__multf3(qnan128, 0x1.23456789abcdefp+5, 0x7fff800000000000, 0x0);53 try test__multf3(qnan128, 0x1.23456789abcdefp+5, 0x7fff800000000000, 0x0);
5454
55 // NaN * any = NaN55 // NaN * any = NaN
56 const a = makeNaN128(0x800030000000);56 const a = makeNaN128(0x800030000000);
57 test__multf3(a, 0x1.23456789abcdefp+5, 0x7fff800000000000, 0x0);57 try test__multf3(a, 0x1.23456789abcdefp+5, 0x7fff800000000000, 0x0);
58 // inf * any = inf58 // inf * any = inf
59 test__multf3(inf128, 0x1.23456789abcdefp+5, 0x7fff000000000000, 0x0);59 try test__multf3(inf128, 0x1.23456789abcdefp+5, 0x7fff000000000000, 0x0);
6060
61 // any * any61 // any * any
62 test__multf3(62 try test__multf3(
63 @bitCast(f128, @as(u128, 0x40042eab345678439abcdefea5678234)),63 @bitCast(f128, @as(u128, 0x40042eab345678439abcdefea5678234)),
64 @bitCast(f128, @as(u128, 0x3ffeedcb34a235253948765432134675)),64 @bitCast(f128, @as(u128, 0x3ffeedcb34a235253948765432134675)),
65 0x400423e7f9e3c9fc,65 0x400423e7f9e3c9fc,
66 0xd906c2c2a85777c4,66 0xd906c2c2a85777c4,
67 );67 );
6868
69 test__multf3(69 try test__multf3(
70 @bitCast(f128, @as(u128, 0x3fcd353e45674d89abacc3a2ebf3ff50)),70 @bitCast(f128, @as(u128, 0x3fcd353e45674d89abacc3a2ebf3ff50)),
71 @bitCast(f128, @as(u128, 0x3ff6ed8764648369535adf4be3214568)),71 @bitCast(f128, @as(u128, 0x3ff6ed8764648369535adf4be3214568)),
72 0x3fc52a163c6223fc,72 0x3fc52a163c6223fc,
73 0xc94c4bf0430768b4,73 0xc94c4bf0430768b4,
74 );74 );
7575
76 test__multf3(76 try test__multf3(
77 0x1.234425696abcad34a35eeffefdcbap+456,77 0x1.234425696abcad34a35eeffefdcbap+456,
78 0x451.ed98d76e5d46e5f24323dff21ffp+600,78 0x451.ed98d76e5d46e5f24323dff21ffp+600,
79 0x44293a91de5e0e94,79 0x44293a91de5e0e94,
80 0xe8ed17cc2cdf64ac,80 0xe8ed17cc2cdf64ac,
81 );81 );
8282
83 test__multf3(83 try test__multf3(
84 @bitCast(f128, @as(u128, 0x3f154356473c82a9fabf2d22ace345df)),84 @bitCast(f128, @as(u128, 0x3f154356473c82a9fabf2d22ace345df)),
85 @bitCast(f128, @as(u128, 0x3e38eda98765476743ab21da23d45679)),85 @bitCast(f128, @as(u128, 0x3e38eda98765476743ab21da23d45679)),
86 0x3d4f37c1a3137cae,86 0x3d4f37c1a3137cae,
87 0xfc6807048bc2836a,87 0xfc6807048bc2836a,
88 );88 );
8989
90 test__multf3(0x1.23456734245345p-10000, 0x1.edcba524498724p-6497, 0x0, 0x0);90 try test__multf3(0x1.23456734245345p-10000, 0x1.edcba524498724p-6497, 0x0, 0x0);
91}91}
lib/std/special/compiler_rt/muldi3_test.zig+43-43
...@@ -6,51 +6,51 @@...@@ -6,51 +6,51 @@
6const __muldi3 = @import("muldi3.zig").__muldi3;6const __muldi3 = @import("muldi3.zig").__muldi3;
7const testing = @import("std").testing;7const 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 {
10 const x = __muldi3(a, b);10 const x = __muldi3(a, b);
11 testing.expect(x == expected);11 try testing.expect(x == expected);
12}12}
1313
14test "muldi3" {14test "muldi3" {
15 test__muldi3(0, 0, 0);15 try test__muldi3(0, 0, 0);
16 test__muldi3(0, 1, 0);16 try test__muldi3(0, 1, 0);
17 test__muldi3(1, 0, 0);17 try test__muldi3(1, 0, 0);
18 test__muldi3(0, 10, 0);18 try test__muldi3(0, 10, 0);
19 test__muldi3(10, 0, 0);19 try test__muldi3(10, 0, 0);
20 test__muldi3(0, 81985529216486895, 0);20 try test__muldi3(0, 81985529216486895, 0);
21 test__muldi3(81985529216486895, 0, 0);21 try test__muldi3(81985529216486895, 0, 0);
2222
23 test__muldi3(0, -1, 0);23 try test__muldi3(0, -1, 0);
24 test__muldi3(-1, 0, 0);24 try test__muldi3(-1, 0, 0);
25 test__muldi3(0, -10, 0);25 try test__muldi3(0, -10, 0);
26 test__muldi3(-10, 0, 0);26 try test__muldi3(-10, 0, 0);
27 test__muldi3(0, -81985529216486895, 0);27 try test__muldi3(0, -81985529216486895, 0);
28 test__muldi3(-81985529216486895, 0, 0);28 try test__muldi3(-81985529216486895, 0, 0);
2929
30 test__muldi3(1, 1, 1);30 try test__muldi3(1, 1, 1);
31 test__muldi3(1, 10, 10);31 try test__muldi3(1, 10, 10);
32 test__muldi3(10, 1, 10);32 try test__muldi3(10, 1, 10);
33 test__muldi3(1, 81985529216486895, 81985529216486895);33 try test__muldi3(1, 81985529216486895, 81985529216486895);
34 test__muldi3(81985529216486895, 1, 81985529216486895);34 try test__muldi3(81985529216486895, 1, 81985529216486895);
3535
36 test__muldi3(1, -1, -1);36 try test__muldi3(1, -1, -1);
37 test__muldi3(1, -10, -10);37 try test__muldi3(1, -10, -10);
38 test__muldi3(-10, 1, -10);38 try test__muldi3(-10, 1, -10);
39 test__muldi3(1, -81985529216486895, -81985529216486895);39 try test__muldi3(1, -81985529216486895, -81985529216486895);
40 test__muldi3(-81985529216486895, 1, -81985529216486895);40 try test__muldi3(-81985529216486895, 1, -81985529216486895);
4141
42 test__muldi3(3037000499, 3037000499, 9223372030926249001);42 try test__muldi3(3037000499, 3037000499, 9223372030926249001);
43 test__muldi3(-3037000499, 3037000499, -9223372030926249001);43 try test__muldi3(-3037000499, 3037000499, -9223372030926249001);
44 test__muldi3(3037000499, -3037000499, -9223372030926249001);44 try test__muldi3(3037000499, -3037000499, -9223372030926249001);
45 test__muldi3(-3037000499, -3037000499, 9223372030926249001);45 try test__muldi3(-3037000499, -3037000499, 9223372030926249001);
4646
47 test__muldi3(4398046511103, 2097152, 9223372036852678656);47 try test__muldi3(4398046511103, 2097152, 9223372036852678656);
48 test__muldi3(-4398046511103, 2097152, -9223372036852678656);48 try test__muldi3(-4398046511103, 2097152, -9223372036852678656);
49 test__muldi3(4398046511103, -2097152, -9223372036852678656);49 try test__muldi3(4398046511103, -2097152, -9223372036852678656);
50 test__muldi3(-4398046511103, -2097152, 9223372036852678656);50 try test__muldi3(-4398046511103, -2097152, 9223372036852678656);
5151
52 test__muldi3(2097152, 4398046511103, 9223372036852678656);52 try test__muldi3(2097152, 4398046511103, 9223372036852678656);
53 test__muldi3(-2097152, 4398046511103, -9223372036852678656);53 try test__muldi3(-2097152, 4398046511103, -9223372036852678656);
54 test__muldi3(2097152, -4398046511103, -9223372036852678656);54 try test__muldi3(2097152, -4398046511103, -9223372036852678656);
55 test__muldi3(-2097152, -4398046511103, 9223372036852678656);55 try test__muldi3(-2097152, -4398046511103, 9223372036852678656);
56}56}
lib/std/special/compiler_rt/mulodi4_test.zig+67-67
...@@ -6,85 +6,85 @@...@@ -6,85 +6,85 @@
6const __mulodi4 = @import("mulodi4.zig").__mulodi4;6const __mulodi4 = @import("mulodi4.zig").__mulodi4;
7const testing = @import("std").testing;7const 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 {
10 var overflow: c_int = undefined;10 var overflow: c_int = undefined;
11 const x = __mulodi4(a, b, &overflow);11 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));
13}13}
1414
15test "mulodi4" {15test "mulodi4" {
16 test__mulodi4(0, 0, 0, 0);16 try test__mulodi4(0, 0, 0, 0);
17 test__mulodi4(0, 1, 0, 0);17 try test__mulodi4(0, 1, 0, 0);
18 test__mulodi4(1, 0, 0, 0);18 try test__mulodi4(1, 0, 0, 0);
19 test__mulodi4(0, 10, 0, 0);19 try test__mulodi4(0, 10, 0, 0);
20 test__mulodi4(10, 0, 0, 0);20 try test__mulodi4(10, 0, 0, 0);
21 test__mulodi4(0, 81985529216486895, 0, 0);21 try test__mulodi4(0, 81985529216486895, 0, 0);
22 test__mulodi4(81985529216486895, 0, 0, 0);22 try test__mulodi4(81985529216486895, 0, 0, 0);
2323
24 test__mulodi4(0, -1, 0, 0);24 try test__mulodi4(0, -1, 0, 0);
25 test__mulodi4(-1, 0, 0, 0);25 try test__mulodi4(-1, 0, 0, 0);
26 test__mulodi4(0, -10, 0, 0);26 try test__mulodi4(0, -10, 0, 0);
27 test__mulodi4(-10, 0, 0, 0);27 try test__mulodi4(-10, 0, 0, 0);
28 test__mulodi4(0, -81985529216486895, 0, 0);28 try test__mulodi4(0, -81985529216486895, 0, 0);
29 test__mulodi4(-81985529216486895, 0, 0, 0);29 try test__mulodi4(-81985529216486895, 0, 0, 0);
3030
31 test__mulodi4(1, 1, 1, 0);31 try test__mulodi4(1, 1, 1, 0);
32 test__mulodi4(1, 10, 10, 0);32 try test__mulodi4(1, 10, 10, 0);
33 test__mulodi4(10, 1, 10, 0);33 try test__mulodi4(10, 1, 10, 0);
34 test__mulodi4(1, 81985529216486895, 81985529216486895, 0);34 try test__mulodi4(1, 81985529216486895, 81985529216486895, 0);
35 test__mulodi4(81985529216486895, 1, 81985529216486895, 0);35 try test__mulodi4(81985529216486895, 1, 81985529216486895, 0);
3636
37 test__mulodi4(1, -1, -1, 0);37 try test__mulodi4(1, -1, -1, 0);
38 test__mulodi4(1, -10, -10, 0);38 try test__mulodi4(1, -10, -10, 0);
39 test__mulodi4(-10, 1, -10, 0);39 try test__mulodi4(-10, 1, -10, 0);
40 test__mulodi4(1, -81985529216486895, -81985529216486895, 0);40 try test__mulodi4(1, -81985529216486895, -81985529216486895, 0);
41 test__mulodi4(-81985529216486895, 1, -81985529216486895, 0);41 try test__mulodi4(-81985529216486895, 1, -81985529216486895, 0);
4242
43 test__mulodi4(3037000499, 3037000499, 9223372030926249001, 0);43 try test__mulodi4(3037000499, 3037000499, 9223372030926249001, 0);
44 test__mulodi4(-3037000499, 3037000499, -9223372030926249001, 0);44 try test__mulodi4(-3037000499, 3037000499, -9223372030926249001, 0);
45 test__mulodi4(3037000499, -3037000499, -9223372030926249001, 0);45 try test__mulodi4(3037000499, -3037000499, -9223372030926249001, 0);
46 test__mulodi4(-3037000499, -3037000499, 9223372030926249001, 0);46 try test__mulodi4(-3037000499, -3037000499, 9223372030926249001, 0);
4747
48 test__mulodi4(4398046511103, 2097152, 9223372036852678656, 0);48 try test__mulodi4(4398046511103, 2097152, 9223372036852678656, 0);
49 test__mulodi4(-4398046511103, 2097152, -9223372036852678656, 0);49 try test__mulodi4(-4398046511103, 2097152, -9223372036852678656, 0);
50 test__mulodi4(4398046511103, -2097152, -9223372036852678656, 0);50 try test__mulodi4(4398046511103, -2097152, -9223372036852678656, 0);
51 test__mulodi4(-4398046511103, -2097152, 9223372036852678656, 0);51 try test__mulodi4(-4398046511103, -2097152, 9223372036852678656, 0);
5252
53 test__mulodi4(2097152, 4398046511103, 9223372036852678656, 0);53 try test__mulodi4(2097152, 4398046511103, 9223372036852678656, 0);
54 test__mulodi4(-2097152, 4398046511103, -9223372036852678656, 0);54 try test__mulodi4(-2097152, 4398046511103, -9223372036852678656, 0);
55 test__mulodi4(2097152, -4398046511103, -9223372036852678656, 0);55 try test__mulodi4(2097152, -4398046511103, -9223372036852678656, 0);
56 test__mulodi4(-2097152, -4398046511103, 9223372036852678656, 0);56 try test__mulodi4(-2097152, -4398046511103, 9223372036852678656, 0);
5757
58 test__mulodi4(0x7FFFFFFFFFFFFFFF, -2, 2, 1);58 try test__mulodi4(0x7FFFFFFFFFFFFFFF, -2, 2, 1);
59 test__mulodi4(-2, 0x7FFFFFFFFFFFFFFF, 2, 1);59 try test__mulodi4(-2, 0x7FFFFFFFFFFFFFFF, 2, 1);
60 test__mulodi4(0x7FFFFFFFFFFFFFFF, -1, @bitCast(i64, @as(u64, 0x8000000000000001)), 0);60 try test__mulodi4(0x7FFFFFFFFFFFFFFF, -1, @bitCast(i64, @as(u64, 0x8000000000000001)), 0);
61 test__mulodi4(-1, 0x7FFFFFFFFFFFFFFF, @bitCast(i64, @as(u64, 0x8000000000000001)), 0);61 try test__mulodi4(-1, 0x7FFFFFFFFFFFFFFF, @bitCast(i64, @as(u64, 0x8000000000000001)), 0);
62 test__mulodi4(0x7FFFFFFFFFFFFFFF, 0, 0, 0);62 try test__mulodi4(0x7FFFFFFFFFFFFFFF, 0, 0, 0);
63 test__mulodi4(0, 0x7FFFFFFFFFFFFFFF, 0, 0);63 try test__mulodi4(0, 0x7FFFFFFFFFFFFFFF, 0, 0);
64 test__mulodi4(0x7FFFFFFFFFFFFFFF, 1, 0x7FFFFFFFFFFFFFFF, 0);64 try test__mulodi4(0x7FFFFFFFFFFFFFFF, 1, 0x7FFFFFFFFFFFFFFF, 0);
65 test__mulodi4(1, 0x7FFFFFFFFFFFFFFF, 0x7FFFFFFFFFFFFFFF, 0);65 try test__mulodi4(1, 0x7FFFFFFFFFFFFFFF, 0x7FFFFFFFFFFFFFFF, 0);
66 test__mulodi4(0x7FFFFFFFFFFFFFFF, 2, @bitCast(i64, @as(u64, 0x8000000000000001)), 1);66 try test__mulodi4(0x7FFFFFFFFFFFFFFF, 2, @bitCast(i64, @as(u64, 0x8000000000000001)), 1);
67 test__mulodi4(2, 0x7FFFFFFFFFFFFFFF, @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);69 try 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);70 try 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);71 try 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);72 try 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);73 try test__mulodi4(@bitCast(i64, @as(u64, 0x8000000000000000)), 0, 0, 0);
74 test__mulodi4(0, @bitCast(i64, @as(u64, 0x8000000000000000)), 0, 0);74 try 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);75 try 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);76 try 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);77 try 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);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);80 try 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);81 try 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);82 try test__mulodi4(@bitCast(i64, @as(u64, 0x8000000000000001)), -1, 0x7FFFFFFFFFFFFFFF, 0);
83 test__mulodi4(-1, @bitCast(i64, @as(u64, 0x8000000000000001)), 0x7FFFFFFFFFFFFFFF, 0);83 try test__mulodi4(-1, @bitCast(i64, @as(u64, 0x8000000000000001)), 0x7FFFFFFFFFFFFFFF, 0);
84 test__mulodi4(@bitCast(i64, @as(u64, 0x8000000000000001)), 0, 0, 0);84 try test__mulodi4(@bitCast(i64, @as(u64, 0x8000000000000001)), 0, 0, 0);
85 test__mulodi4(0, @bitCast(i64, @as(u64, 0x8000000000000001)), 0, 0);85 try 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);86 try 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);87 try 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);88 try 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);89 try test__mulodi4(2, @bitCast(i64, @as(u64, 0x8000000000000001)), @bitCast(i64, @as(u64, 0x8000000000000000)), 1);
90}90}
lib/std/special/compiler_rt/muloti4_test.zig+58-58
...@@ -6,76 +6,76 @@...@@ -6,76 +6,76 @@
6const __muloti4 = @import("muloti4.zig").__muloti4;6const __muloti4 = @import("muloti4.zig").__muloti4;
7const testing = @import("std").testing;7const 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 {
10 var overflow: c_int = undefined;10 var overflow: c_int = undefined;
11 const x = __muloti4(a, b, &overflow);11 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));
13}13}
1414
15test "muloti4" {15test "muloti4" {
16 test__muloti4(0, 0, 0, 0);16 try test__muloti4(0, 0, 0, 0);
17 test__muloti4(0, 1, 0, 0);17 try test__muloti4(0, 1, 0, 0);
18 test__muloti4(1, 0, 0, 0);18 try test__muloti4(1, 0, 0, 0);
19 test__muloti4(0, 10, 0, 0);19 try test__muloti4(0, 10, 0, 0);
20 test__muloti4(10, 0, 0, 0);20 try test__muloti4(10, 0, 0, 0);
2121
22 test__muloti4(0, 81985529216486895, 0, 0);22 try test__muloti4(0, 81985529216486895, 0, 0);
23 test__muloti4(81985529216486895, 0, 0, 0);23 try test__muloti4(81985529216486895, 0, 0, 0);
2424
25 test__muloti4(0, -1, 0, 0);25 try test__muloti4(0, -1, 0, 0);
26 test__muloti4(-1, 0, 0, 0);26 try test__muloti4(-1, 0, 0, 0);
27 test__muloti4(0, -10, 0, 0);27 try test__muloti4(0, -10, 0, 0);
28 test__muloti4(-10, 0, 0, 0);28 try test__muloti4(-10, 0, 0, 0);
29 test__muloti4(0, -81985529216486895, 0, 0);29 try test__muloti4(0, -81985529216486895, 0, 0);
30 test__muloti4(-81985529216486895, 0, 0, 0);30 try test__muloti4(-81985529216486895, 0, 0, 0);
3131
32 test__muloti4(3037000499, 3037000499, 9223372030926249001, 0);32 try test__muloti4(3037000499, 3037000499, 9223372030926249001, 0);
33 test__muloti4(-3037000499, 3037000499, -9223372030926249001, 0);33 try test__muloti4(-3037000499, 3037000499, -9223372030926249001, 0);
34 test__muloti4(3037000499, -3037000499, -9223372030926249001, 0);34 try test__muloti4(3037000499, -3037000499, -9223372030926249001, 0);
35 test__muloti4(-3037000499, -3037000499, 9223372030926249001, 0);35 try test__muloti4(-3037000499, -3037000499, 9223372030926249001, 0);
3636
37 test__muloti4(4398046511103, 2097152, 9223372036852678656, 0);37 try test__muloti4(4398046511103, 2097152, 9223372036852678656, 0);
38 test__muloti4(-4398046511103, 2097152, -9223372036852678656, 0);38 try test__muloti4(-4398046511103, 2097152, -9223372036852678656, 0);
39 test__muloti4(4398046511103, -2097152, -9223372036852678656, 0);39 try test__muloti4(4398046511103, -2097152, -9223372036852678656, 0);
40 test__muloti4(-4398046511103, -2097152, 9223372036852678656, 0);40 try test__muloti4(-4398046511103, -2097152, 9223372036852678656, 0);
4141
42 test__muloti4(2097152, 4398046511103, 9223372036852678656, 0);42 try test__muloti4(2097152, 4398046511103, 9223372036852678656, 0);
43 test__muloti4(-2097152, 4398046511103, -9223372036852678656, 0);43 try test__muloti4(-2097152, 4398046511103, -9223372036852678656, 0);
44 test__muloti4(2097152, -4398046511103, -9223372036852678656, 0);44 try test__muloti4(2097152, -4398046511103, -9223372036852678656, 0);
45 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);47 try 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);48 try 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);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);51 try 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);52 try 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);53 try test__muloti4(@bitCast(i128, @as(u128, 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)), 0, 0, 0);
54 test__muloti4(0, @bitCast(i128, @as(u128, 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)), 0, 0);54 try 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);55 try 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);56 try 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);57 try 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);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);60 try 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);61 try 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);62 try 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);63 try 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);64 try test__muloti4(@bitCast(i128, @as(u128, 0x80000000000000000000000000000000)), 0, 0, 0);
65 test__muloti4(0, @bitCast(i128, @as(u128, 0x80000000000000000000000000000000)), 0, 0);65 try 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);66 try 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);67 try 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);68 try 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);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);71 try 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);72 try 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);73 try 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);74 try 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);75 try test__muloti4(@bitCast(i128, @as(u128, 0x80000000000000000000000000000001)), 0, 0, 0);
76 test__muloti4(0, @bitCast(i128, @as(u128, 0x80000000000000000000000000000001)), 0, 0);76 try 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);77 try 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);78 try 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);79 try 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);80 try test__muloti4(2, @bitCast(i128, @as(u128, 0x80000000000000000000000000000001)), @bitCast(i128, @as(u128, 0x80000000000000000000000000000000)), 1);
81}81}
lib/std/special/compiler_rt/multi3_test.zig+45-45
...@@ -6,53 +6,53 @@...@@ -6,53 +6,53 @@
6const __multi3 = @import("multi3.zig").__multi3;6const __multi3 = @import("multi3.zig").__multi3;
7const testing = @import("std").testing;7const 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 {
10 const x = __multi3(a, b);10 const x = __multi3(a, b);
11 testing.expect(x == expected);11 try testing.expect(x == expected);
12}12}
1313
14test "multi3" {14test "multi3" {
15 test__multi3(0, 0, 0);15 try test__multi3(0, 0, 0);
16 test__multi3(0, 1, 0);16 try test__multi3(0, 1, 0);
17 test__multi3(1, 0, 0);17 try test__multi3(1, 0, 0);
18 test__multi3(0, 10, 0);18 try test__multi3(0, 10, 0);
19 test__multi3(10, 0, 0);19 try test__multi3(10, 0, 0);
20 test__multi3(0, 81985529216486895, 0);20 try test__multi3(0, 81985529216486895, 0);
21 test__multi3(81985529216486895, 0, 0);21 try test__multi3(81985529216486895, 0, 0);
2222
23 test__multi3(0, -1, 0);23 try test__multi3(0, -1, 0);
24 test__multi3(-1, 0, 0);24 try test__multi3(-1, 0, 0);
25 test__multi3(0, -10, 0);25 try test__multi3(0, -10, 0);
26 test__multi3(-10, 0, 0);26 try test__multi3(-10, 0, 0);
27 test__multi3(0, -81985529216486895, 0);27 try test__multi3(0, -81985529216486895, 0);
28 test__multi3(-81985529216486895, 0, 0);28 try test__multi3(-81985529216486895, 0, 0);
2929
30 test__multi3(1, 1, 1);30 try test__multi3(1, 1, 1);
31 test__multi3(1, 10, 10);31 try test__multi3(1, 10, 10);
32 test__multi3(10, 1, 10);32 try test__multi3(10, 1, 10);
33 test__multi3(1, 81985529216486895, 81985529216486895);33 try test__multi3(1, 81985529216486895, 81985529216486895);
34 test__multi3(81985529216486895, 1, 81985529216486895);34 try test__multi3(81985529216486895, 1, 81985529216486895);
3535
36 test__multi3(1, -1, -1);36 try test__multi3(1, -1, -1);
37 test__multi3(1, -10, -10);37 try test__multi3(1, -10, -10);
38 test__multi3(-10, 1, -10);38 try test__multi3(-10, 1, -10);
39 test__multi3(1, -81985529216486895, -81985529216486895);39 try test__multi3(1, -81985529216486895, -81985529216486895);
40 test__multi3(-81985529216486895, 1, -81985529216486895);40 try test__multi3(-81985529216486895, 1, -81985529216486895);
4141
42 test__multi3(3037000499, 3037000499, 9223372030926249001);42 try test__multi3(3037000499, 3037000499, 9223372030926249001);
43 test__multi3(-3037000499, 3037000499, -9223372030926249001);43 try test__multi3(-3037000499, 3037000499, -9223372030926249001);
44 test__multi3(3037000499, -3037000499, -9223372030926249001);44 try test__multi3(3037000499, -3037000499, -9223372030926249001);
45 test__multi3(-3037000499, -3037000499, 9223372030926249001);45 try test__multi3(-3037000499, -3037000499, 9223372030926249001);
4646
47 test__multi3(4398046511103, 2097152, 9223372036852678656);47 try test__multi3(4398046511103, 2097152, 9223372036852678656);
48 test__multi3(-4398046511103, 2097152, -9223372036852678656);48 try test__multi3(-4398046511103, 2097152, -9223372036852678656);
49 test__multi3(4398046511103, -2097152, -9223372036852678656);49 try test__multi3(4398046511103, -2097152, -9223372036852678656);
50 test__multi3(-4398046511103, -2097152, 9223372036852678656);50 try test__multi3(-4398046511103, -2097152, 9223372036852678656);
5151
52 test__multi3(2097152, 4398046511103, 9223372036852678656);52 try test__multi3(2097152, 4398046511103, 9223372036852678656);
53 test__multi3(-2097152, 4398046511103, -9223372036852678656);53 try test__multi3(-2097152, 4398046511103, -9223372036852678656);
54 test__multi3(2097152, -4398046511103, -9223372036852678656);54 try test__multi3(2097152, -4398046511103, -9223372036852678656);
55 test__multi3(-2097152, -4398046511103, 9223372036852678656);55 try test__multi3(-2097152, -4398046511103, 9223372036852678656);
5656
57 test__multi3(0x00000000000000B504F333F9DE5BE000, 0x000000000000000000B504F333F9DE5B, 0x7FFFFFFFFFFFF328DF915DA296E8A000);57 try test__multi3(0x00000000000000B504F333F9DE5BE000, 0x000000000000000000B504F333F9DE5B, 0x7FFFFFFFFFFFF328DF915DA296E8A000);
58}58}
lib/std/special/compiler_rt/popcountdi2_test.zig+8-8
...@@ -15,18 +15,18 @@ fn naive_popcount(a_param: i64) i32 {...@@ -15,18 +15,18 @@ fn naive_popcount(a_param: i64) i32 {
15 return r;15 return r;
16}16}
1717
18fn test__popcountdi2(a: i64) void {18fn test__popcountdi2(a: i64) !void {
19 const x = __popcountdi2(a);19 const x = __popcountdi2(a);
20 const expected = naive_popcount(a);20 const expected = naive_popcount(a);
21 testing.expect(expected == x);21 try testing.expect(expected == x);
22}22}
2323
24test "popcountdi2" {24test "popcountdi2" {
25 test__popcountdi2(0);25 try test__popcountdi2(0);
26 test__popcountdi2(1);26 try test__popcountdi2(1);
27 test__popcountdi2(2);27 try test__popcountdi2(2);
28 test__popcountdi2(@bitCast(i64, @as(u64, 0xFFFFFFFFFFFFFFFD)));28 try test__popcountdi2(@bitCast(i64, @as(u64, 0xFFFFFFFFFFFFFFFD)));
29 test__popcountdi2(@bitCast(i64, @as(u64, 0xFFFFFFFFFFFFFFFE)));29 try test__popcountdi2(@bitCast(i64, @as(u64, 0xFFFFFFFFFFFFFFFE)));
30 test__popcountdi2(@bitCast(i64, @as(u64, 0xFFFFFFFFFFFFFFFF)));30 try test__popcountdi2(@bitCast(i64, @as(u64, 0xFFFFFFFFFFFFFFFF)));
31 // TODO some fuzz testing31 // TODO some fuzz testing
32}32}
lib/std/special/compiler_rt/truncXfYf2_test.zig+36-36
...@@ -5,67 +5,67 @@...@@ -5,67 +5,67 @@
5// and substantial portions of the software.5// and substantial portions of the software.
6const __truncsfhf2 = @import("truncXfYf2.zig").__truncsfhf2;6const __truncsfhf2 = @import("truncXfYf2.zig").__truncsfhf2;
77
8fn test__truncsfhf2(a: u32, expected: u16) void {8fn test__truncsfhf2(a: u32, expected: u16) !void {
9 const actual = __truncsfhf2(@bitCast(f32, a));9 const actual = __truncsfhf2(@bitCast(f32, a));
1010
11 if (actual == expected) {11 if (actual == expected) {
12 return;12 return;
13 }13 }
1414
15 @panic("__truncsfhf2 test failure");15 return error.TestFailure;
16}16}
1717
18test "truncsfhf2" {18test "truncsfhf2" {
19 test__truncsfhf2(0x7fc00000, 0x7e00); // qNaN19 try test__truncsfhf2(0x7fc00000, 0x7e00); // qNaN
20 test__truncsfhf2(0x7fe00000, 0x7f00); // sNaN20 try test__truncsfhf2(0x7fe00000, 0x7f00); // sNaN
2121
22 test__truncsfhf2(0, 0); // 022 try test__truncsfhf2(0, 0); // 0
23 test__truncsfhf2(0x80000000, 0x8000); // -023 try test__truncsfhf2(0x80000000, 0x8000); // -0
2424
25 test__truncsfhf2(0x7f800000, 0x7c00); // inf25 try test__truncsfhf2(0x7f800000, 0x7c00); // inf
26 test__truncsfhf2(0xff800000, 0xfc00); // -inf26 try test__truncsfhf2(0xff800000, 0xfc00); // -inf
2727
28 test__truncsfhf2(0x477ff000, 0x7c00); // 65520 -> inf28 try test__truncsfhf2(0x477ff000, 0x7c00); // 65520 -> inf
29 test__truncsfhf2(0xc77ff000, 0xfc00); // -65520 -> -inf29 try test__truncsfhf2(0xc77ff000, 0xfc00); // -65520 -> -inf
3030
31 test__truncsfhf2(0x71cc3892, 0x7c00); // 0x1.987124876876324p+100 -> inf31 try test__truncsfhf2(0x71cc3892, 0x7c00); // 0x1.987124876876324p+100 -> inf
32 test__truncsfhf2(0xf1cc3892, 0xfc00); // -0x1.987124876876324p+100 -> -inf32 try test__truncsfhf2(0xf1cc3892, 0xfc00); // -0x1.987124876876324p+100 -> -inf
3333
34 test__truncsfhf2(0x38800000, 0x0400); // normal (min), 2**-1434 try test__truncsfhf2(0x38800000, 0x0400); // normal (min), 2**-14
35 test__truncsfhf2(0xb8800000, 0x8400); // normal (min), -2**-1435 try test__truncsfhf2(0xb8800000, 0x8400); // normal (min), -2**-14
3636
37 test__truncsfhf2(0x477fe000, 0x7bff); // normal (max), 6550437 try test__truncsfhf2(0x477fe000, 0x7bff); // normal (max), 65504
38 test__truncsfhf2(0xc77fe000, 0xfbff); // normal (max), -6550438 try test__truncsfhf2(0xc77fe000, 0xfbff); // normal (max), -65504
3939
40 test__truncsfhf2(0x477fe100, 0x7bff); // normal, 65505 -> 6550440 try test__truncsfhf2(0x477fe100, 0x7bff); // normal, 65505 -> 65504
41 test__truncsfhf2(0xc77fe100, 0xfbff); // normal, -65505 -> -6550441 try test__truncsfhf2(0xc77fe100, 0xfbff); // normal, -65505 -> -65504
4242
43 test__truncsfhf2(0x477fef00, 0x7bff); // normal, 65519 -> 6550443 try test__truncsfhf2(0x477fef00, 0x7bff); // normal, 65519 -> 65504
44 test__truncsfhf2(0xc77fef00, 0xfbff); // normal, -65519 -> -6550444 try test__truncsfhf2(0xc77fef00, 0xfbff); // normal, -65519 -> -65504
4545
46 test__truncsfhf2(0x3f802000, 0x3c01); // normal, 1 + 2**-1046 try test__truncsfhf2(0x3f802000, 0x3c01); // normal, 1 + 2**-10
47 test__truncsfhf2(0xbf802000, 0xbc01); // normal, -1 - 2**-1047 try test__truncsfhf2(0xbf802000, 0xbc01); // normal, -1 - 2**-10
4848
49 test__truncsfhf2(0x3eaaa000, 0x3555); // normal, approx. 1/349 try test__truncsfhf2(0x3eaaa000, 0x3555); // normal, approx. 1/3
50 test__truncsfhf2(0xbeaaa000, 0xb555); // normal, approx. -1/350 try test__truncsfhf2(0xbeaaa000, 0xb555); // normal, approx. -1/3
5151
52 test__truncsfhf2(0x40490fdb, 0x4248); // normal, 3.141592653552 try test__truncsfhf2(0x40490fdb, 0x4248); // normal, 3.1415926535
53 test__truncsfhf2(0xc0490fdb, 0xc248); // normal, -3.141592653553 try test__truncsfhf2(0xc0490fdb, 0xc248); // normal, -3.1415926535
5454
55 test__truncsfhf2(0x45cc3892, 0x6e62); // normal, 0x1.987124876876324p+1255 try test__truncsfhf2(0x45cc3892, 0x6e62); // normal, 0x1.987124876876324p+12
5656
57 test__truncsfhf2(0x3f800000, 0x3c00); // normal, 157 try test__truncsfhf2(0x3f800000, 0x3c00); // normal, 1
58 test__truncsfhf2(0x38800000, 0x0400); // normal, 0x1.0p-1458 try test__truncsfhf2(0x38800000, 0x0400); // normal, 0x1.0p-14
5959
60 test__truncsfhf2(0x33800000, 0x0001); // denormal (min), 2**-2460 try test__truncsfhf2(0x33800000, 0x0001); // denormal (min), 2**-24
61 test__truncsfhf2(0xb3800000, 0x8001); // denormal (min), -2**-2461 try test__truncsfhf2(0xb3800000, 0x8001); // denormal (min), -2**-24
6262
63 test__truncsfhf2(0x387fc000, 0x03ff); // denormal (max), 2**-14 - 2**-2463 try test__truncsfhf2(0x387fc000, 0x03ff); // denormal (max), 2**-14 - 2**-24
64 test__truncsfhf2(0xb87fc000, 0x83ff); // denormal (max), -2**-14 + 2**-2464 try test__truncsfhf2(0xb87fc000, 0x83ff); // denormal (max), -2**-14 + 2**-24
6565
66 test__truncsfhf2(0x35800000, 0x0010); // denormal, 0x1.0p-2066 try test__truncsfhf2(0x35800000, 0x0010); // denormal, 0x1.0p-20
67 test__truncsfhf2(0x33280000, 0x0001); // denormal, 0x1.5p-25 -> 0x1.0p-2467 try test__truncsfhf2(0x33280000, 0x0001); // denormal, 0x1.5p-25 -> 0x1.0p-24
68 test__truncsfhf2(0x33000000, 0x0000); // 0x1.0p-25 -> zero68 try test__truncsfhf2(0x33000000, 0x0000); // 0x1.0p-25 -> zero
69}69}
7070
71const __truncdfhf2 = @import("truncXfYf2.zig").__truncdfhf2;71const __truncdfhf2 = @import("truncXfYf2.zig").__truncdfhf2;
lib/std/special/compiler_rt/udivmoddi4_test.zig+4-4
...@@ -8,16 +8,16 @@...@@ -8,16 +8,16 @@
8const __udivmoddi4 = @import("int.zig").__udivmoddi4;8const __udivmoddi4 = @import("int.zig").__udivmoddi4;
9const testing = @import("std").testing;9const 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 {
12 var r: u64 = undefined;12 var r: u64 = undefined;
13 const q = __udivmoddi4(a, b, &r);13 const q = __udivmoddi4(a, b, &r);
14 testing.expect(q == expected_q);14 try testing.expect(q == expected_q);
15 testing.expect(r == expected_r);15 try testing.expect(r == expected_r);
16}16}
1717
18test "udivmoddi4" {18test "udivmoddi4" {
19 for (cases) |case| {19 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]);
21 }21 }
22}22}
2323
lib/std/special/compiler_rt/udivmodti4_test.zig+4-4
...@@ -8,16 +8,16 @@...@@ -8,16 +8,16 @@
8const __udivmodti4 = @import("udivmodti4.zig").__udivmodti4;8const __udivmodti4 = @import("udivmodti4.zig").__udivmodti4;
9const testing = @import("std").testing;9const 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 {
12 var r: u128 = undefined;12 var r: u128 = undefined;
13 const q = __udivmodti4(a, b, &r);13 const q = __udivmodti4(a, b, &r);
14 testing.expect(q == expected_q);14 try testing.expect(q == expected_q);
15 testing.expect(r == expected_r);15 try testing.expect(r == expected_r);
16}16}
1717
18test "udivmodti4" {18test "udivmodti4" {
19 for (cases) |case| {19 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]);
21 }21 }
22}22}
2323
lib/std/special/init-lib/src/main.zig+1-1
...@@ -6,5 +6,5 @@ export fn add(a: i32, b: i32) i32 {...@@ -6,5 +6,5 @@ export fn add(a: i32, b: i32) i32 {
6}6}
77
8test "basic add functionality" {8test "basic add functionality" {
9 testing.expect(add(3, 7) == 10);9 try testing.expect(add(3, 7) == 10);
10}10}
lib/std/special/test_runner.zig+9-6
...@@ -23,6 +23,7 @@ pub fn main() anyerror!void {...@@ -23,6 +23,7 @@ pub fn main() anyerror!void {
23 const test_fn_list = builtin.test_functions;23 const test_fn_list = builtin.test_functions;
24 var ok_count: usize = 0;24 var ok_count: usize = 0;
25 var skip_count: usize = 0;25 var skip_count: usize = 0;
26 var fail_count: usize = 0;
26 var progress = std.Progress{};27 var progress = std.Progress{};
27 const root_node = progress.start("Test", test_fn_list.len) catch |err| switch (err) {28 const root_node = progress.start("Test", test_fn_list.len) catch |err| switch (err) {
28 // TODO still run tests in this case29 // TODO still run tests in this case
...@@ -62,7 +63,7 @@ pub fn main() anyerror!void {...@@ -62,7 +63,7 @@ pub fn main() anyerror!void {
62 .blocking => {63 .blocking => {
63 skip_count += 1;64 skip_count += 1;
64 test_node.end();65 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});
66 if (progress.terminal == null) std.debug.print("SKIP (async test)\n", .{});67 if (progress.terminal == null) std.debug.print("SKIP (async test)\n", .{});
67 continue;68 continue;
68 },69 },
...@@ -75,12 +76,14 @@ pub fn main() anyerror!void {...@@ -75,12 +76,14 @@ pub fn main() anyerror!void {
75 error.SkipZigTest => {76 error.SkipZigTest => {
76 skip_count += 1;77 skip_count += 1;
77 test_node.end();78 test_node.end();
78 progress.log("{s}...SKIP\n", .{test_fn.name});79 progress.log("{s}... SKIP\n", .{test_fn.name});
79 if (progress.terminal == null) std.debug.print("SKIP\n", .{});80 if (progress.terminal == null) std.debug.print("SKIP\n", .{});
80 },81 },
81 else => {82 else => {
82 progress.log("", .{});83 fail_count += 1;
83 return err;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)});
84 },87 },
85 }88 }
86 }89 }
...@@ -88,7 +91,7 @@ pub fn main() anyerror!void {...@@ -88,7 +91,7 @@ pub fn main() anyerror!void {
88 if (ok_count == test_fn_list.len) {91 if (ok_count == test_fn_list.len) {
89 std.debug.print("All {d} tests passed.\n", .{ok_count});92 std.debug.print("All {d} tests passed.\n", .{ok_count});
90 } else {93 } 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 });
92 }95 }
93 if (log_err_count != 0) {96 if (log_err_count != 0) {
94 std.debug.print("{d} errors were logged.\n", .{log_err_count});97 std.debug.print("{d} errors were logged.\n", .{log_err_count});
...@@ -96,7 +99,7 @@ pub fn main() anyerror!void {...@@ -96,7 +99,7 @@ pub fn main() anyerror!void {
96 if (leaks != 0) {99 if (leaks != 0) {
97 std.debug.print("{d} tests leaked memory.\n", .{leaks});100 std.debug.print("{d} tests leaked memory.\n", .{leaks});
98 }101 }
99 if (leaks != 0 or log_err_count != 0) {102 if (leaks != 0 or log_err_count != 0 or fail_count != 0) {
100 std.process.exit(1);103 std.process.exit(1);
101 }104 }
102}105}
lib/std/testing.zig+63-45
...@@ -27,15 +27,17 @@ pub var zig_exe_path: []const u8 = undefined;...@@ -27,15 +27,17 @@ pub var zig_exe_path: []const u8 = undefined;
2727
28/// This function is intended to be used only in tests. It prints diagnostics to stderr28/// This function is intended to be used only in tests. It prints diagnostics to stderr
29/// and then aborts when actual_error_union is not expected_error.29/// 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 {
31 if (actual_error_union) |actual_payload| {31 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;
33 } else |actual_error| {34 } else |actual_error| {
34 if (expected_error != actual_error) {35 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}", .{
36 @errorName(expected_error),37 @errorName(expected_error),
37 @errorName(actual_error),38 @errorName(actual_error),
38 });39 });
40 return error.TestExpectedError;
39 }41 }
40 }42 }
41}43}
...@@ -44,7 +46,7 @@ pub fn expectError(expected_error: anyerror, actual_error_union: anytype) void {...@@ -44,7 +46,7 @@ pub fn expectError(expected_error: anyerror, actual_error_union: anytype) void {
44/// equal, prints diagnostics to stderr to show exactly how they are not equal,46/// equal, prints diagnostics to stderr to show exactly how they are not equal,
45/// then aborts.47/// then aborts.
46/// `actual` is casted to the type of `expected`.48/// `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 {
48 switch (@typeInfo(@TypeOf(actual))) {50 switch (@typeInfo(@TypeOf(actual))) {
49 .NoReturn,51 .NoReturn,
50 .BoundFn,52 .BoundFn,
...@@ -60,7 +62,8 @@ pub fn expectEqual(expected: anytype, actual: @TypeOf(expected)) void {...@@ -60,7 +62,8 @@ pub fn expectEqual(expected: anytype, actual: @TypeOf(expected)) void {
6062
61 .Type => {63 .Type => {
62 if (actual != expected) {64 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;
64 }67 }
65 },68 },
6669
...@@ -75,7 +78,8 @@ pub fn expectEqual(expected: anytype, actual: @TypeOf(expected)) void {...@@ -75,7 +78,8 @@ pub fn expectEqual(expected: anytype, actual: @TypeOf(expected)) void {
75 .ErrorSet,78 .ErrorSet,
76 => {79 => {
77 if (actual != expected) {80 if (actual != expected) {
78 std.debug.panic("expected {}, found {}", .{ expected, actual });81 std.debug.print("expected {}, found {}", .{ expected, actual });
82 return error.TestExpectedEqual;
79 }83 }
80 },84 },
8185
...@@ -83,34 +87,38 @@ pub fn expectEqual(expected: anytype, actual: @TypeOf(expected)) void {...@@ -83,34 +87,38 @@ pub fn expectEqual(expected: anytype, actual: @TypeOf(expected)) void {
83 switch (pointer.size) {87 switch (pointer.size) {
84 .One, .Many, .C => {88 .One, .Many, .C => {
85 if (actual != expected) {89 if (actual != expected) {
86 std.debug.panic("expected {*}, found {*}", .{ expected, actual });90 std.debug.print("expected {*}, found {*}", .{ expected, actual });
91 return error.TestExpectedEqual;
87 }92 }
88 },93 },
89 .Slice => {94 .Slice => {
90 if (actual.ptr != expected.ptr) {95 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;
92 }98 }
93 if (actual.len != expected.len) {99 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;
95 }102 }
96 },103 },
97 }104 }
98 },105 },
99106
100 .Array => |array| expectEqualSlices(array.child, &expected, &actual),107 .Array => |array| try expectEqualSlices(array.child, &expected, &actual),
101108
102 .Vector => |vectorType| {109 .Vector => |vectorType| {
103 var i: usize = 0;110 var i: usize = 0;
104 while (i < vectorType.len) : (i += 1) {111 while (i < vectorType.len) : (i += 1) {
105 if (!std.meta.eql(expected[i], actual[i])) {112 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;
107 }115 }
108 }116 }
109 },117 },
110118
111 .Struct => |structType| {119 .Struct => |structType| {
112 inline for (structType.fields) |field| {120 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));
114 }122 }
115 },123 },
116124
...@@ -124,12 +132,12 @@ pub fn expectEqual(expected: anytype, actual: @TypeOf(expected)) void {...@@ -124,12 +132,12 @@ pub fn expectEqual(expected: anytype, actual: @TypeOf(expected)) void {
124 const expectedTag = @as(Tag, expected);132 const expectedTag = @as(Tag, expected);
125 const actualTag = @as(Tag, actual);133 const actualTag = @as(Tag, actual);
126134
127 expectEqual(expectedTag, actualTag);135 try expectEqual(expectedTag, actualTag);
128136
129 // we only reach this loop if the tags are equal137 // we only reach this loop if the tags are equal
130 inline for (std.meta.fields(@TypeOf(actual))) |fld| {138 inline for (std.meta.fields(@TypeOf(actual))) |fld| {
131 if (std.mem.eql(u8, fld.name, @tagName(actualTag))) {139 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));
133 return;141 return;
134 }142 }
135 }143 }
...@@ -143,13 +151,15 @@ pub fn expectEqual(expected: anytype, actual: @TypeOf(expected)) void {...@@ -143,13 +151,15 @@ pub fn expectEqual(expected: anytype, actual: @TypeOf(expected)) void {
143 .Optional => {151 .Optional => {
144 if (expected) |expected_payload| {152 if (expected) |expected_payload| {
145 if (actual) |actual_payload| {153 if (actual) |actual_payload| {
146 expectEqual(expected_payload, actual_payload);154 try expectEqual(expected_payload, actual_payload);
147 } else {155 } 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;
149 }158 }
150 } else {159 } else {
151 if (actual) |actual_payload| {160 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;
153 }163 }
154 }164 }
155 },165 },
...@@ -157,15 +167,17 @@ pub fn expectEqual(expected: anytype, actual: @TypeOf(expected)) void {...@@ -157,15 +167,17 @@ pub fn expectEqual(expected: anytype, actual: @TypeOf(expected)) void {
157 .ErrorUnion => {167 .ErrorUnion => {
158 if (expected) |expected_payload| {168 if (expected) |expected_payload| {
159 if (actual) |actual_payload| {169 if (actual) |actual_payload| {
160 expectEqual(expected_payload, actual_payload);170 try expectEqual(expected_payload, actual_payload);
161 } else |actual_err| {171 } 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;
163 }174 }
164 } else |expected_err| {175 } else |expected_err| {
165 if (actual) |actual_payload| {176 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;
167 } else |actual_err| {179 } else |actual_err| {
168 expectEqual(expected_err, actual_err);180 try expectEqual(expected_err, actual_err);
169 }181 }
170 }182 }
171 },183 },
...@@ -181,7 +193,7 @@ test "expectEqual.union(enum)" {...@@ -181,7 +193,7 @@ test "expectEqual.union(enum)" {
181 const a10 = T{ .a = 10 };193 const a10 = T{ .a = 10 };
182 const a20 = T{ .a = 20 };194 const a20 = T{ .a = 20 };
183195
184 expectEqual(a10, a10);196 try expectEqual(a10, a10);
185}197}
186198
187/// This function is intended to be used only in tests. When the formatted result of the template199/// 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...@@ -197,7 +209,7 @@ pub fn expectFmt(expected: []const u8, comptime template: []const u8, args: anyt
197 print("\n======== instead found this: =========\n", .{});209 print("\n======== instead found this: =========\n", .{});
198 print("{s}", .{result});210 print("{s}", .{result});
199 print("\n======================================\n", .{});211 print("\n======================================\n", .{});
200 return error.TestFailed;212 return error.TestExpectedFmt;
201}213}
202214
203pub const expectWithinMargin = @compileError("expectWithinMargin is deprecated, use expectApproxEqAbs or expectApproxEqRel");215pub const expectWithinMargin = @compileError("expectWithinMargin is deprecated, use expectApproxEqAbs or expectApproxEqRel");
...@@ -208,12 +220,14 @@ pub const expectWithinEpsilon = @compileError("expectWithinEpsilon is deprecated...@@ -208,12 +220,14 @@ pub const expectWithinEpsilon = @compileError("expectWithinEpsilon is deprecated
208/// to show exactly how they are not equal, then aborts.220/// to show exactly how they are not equal, then aborts.
209/// See `math.approxEqAbs` for more informations on the tolerance parameter.221/// See `math.approxEqAbs` for more informations on the tolerance parameter.
210/// The types must be floating point222/// 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 {
212 const T = @TypeOf(expected);224 const T = @TypeOf(expected);
213225
214 switch (@typeInfo(T)) {226 switch (@typeInfo(T)) {
215 .Float => if (!math.approxEqAbs(T, expected, actual, tolerance))227 .Float => if (!math.approxEqAbs(T, expected, actual, tolerance)) {
216 std.debug.panic("actual {}, not within absolute tolerance {} of expected {}", .{ actual, tolerance, expected }),228 std.debug.print("actual {}, not within absolute tolerance {} of expected {}", .{ actual, tolerance, expected });
229 return error.TestExpectedApproxEqAbs;
230 },
217231
218 .ComptimeFloat => @compileError("Cannot approximately compare two comptime_float values"),232 .ComptimeFloat => @compileError("Cannot approximately compare two comptime_float values"),
219233
...@@ -228,8 +242,8 @@ test "expectApproxEqAbs" {...@@ -228,8 +242,8 @@ test "expectApproxEqAbs" {
228 const neg_x: T = -12.0;242 const neg_x: T = -12.0;
229 const neg_y: T = -12.06;243 const neg_y: T = -12.06;
230244
231 expectApproxEqAbs(pos_x, pos_y, 0.1);245 try expectApproxEqAbs(pos_x, pos_y, 0.1);
232 expectApproxEqAbs(neg_x, neg_y, 0.1);246 try expectApproxEqAbs(neg_x, neg_y, 0.1);
233 }247 }
234}248}
235249
...@@ -238,12 +252,14 @@ test "expectApproxEqAbs" {...@@ -238,12 +252,14 @@ test "expectApproxEqAbs" {
238/// to show exactly how they are not equal, then aborts.252/// to show exactly how they are not equal, then aborts.
239/// See `math.approxEqRel` for more informations on the tolerance parameter.253/// See `math.approxEqRel` for more informations on the tolerance parameter.
240/// The types must be floating point254/// 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 {
242 const T = @TypeOf(expected);256 const T = @TypeOf(expected);
243257
244 switch (@typeInfo(T)) {258 switch (@typeInfo(T)) {
245 .Float => if (!math.approxEqRel(T, expected, actual, tolerance))259 .Float => if (!math.approxEqRel(T, expected, actual, tolerance)) {
246 std.debug.panic("actual {}, not within relative tolerance {} of expected {}", .{ actual, tolerance, expected }),260 std.debug.print("actual {}, not within relative tolerance {} of expected {}", .{ actual, tolerance, expected });
261 return error.TestExpectedApproxEqRel;
262 },
247263
248 .ComptimeFloat => @compileError("Cannot approximately compare two comptime_float values"),264 .ComptimeFloat => @compileError("Cannot approximately compare two comptime_float values"),
249265
...@@ -261,8 +277,8 @@ test "expectApproxEqRel" {...@@ -261,8 +277,8 @@ test "expectApproxEqRel" {
261 const neg_x: T = -12.0;277 const neg_x: T = -12.0;
262 const neg_y: T = neg_x - 2 * eps_value;278 const neg_y: T = neg_x - 2 * eps_value;
263279
264 expectApproxEqRel(pos_x, pos_y, sqrt_eps_value);280 try expectApproxEqRel(pos_x, pos_y, sqrt_eps_value);
265 expectApproxEqRel(neg_x, neg_y, sqrt_eps_value);281 try expectApproxEqRel(neg_x, neg_y, sqrt_eps_value);
266 }282 }
267}283}
268284
...@@ -270,26 +286,28 @@ test "expectApproxEqRel" {...@@ -270,26 +286,28 @@ test "expectApproxEqRel" {
270/// equal, prints diagnostics to stderr to show exactly how they are not equal,286/// equal, prints diagnostics to stderr to show exactly how they are not equal,
271/// then aborts.287/// then aborts.
272/// If your inputs are UTF-8 encoded strings, consider calling `expectEqualStrings` instead.288/// 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 {
274 // TODO better printing of the difference290 // TODO better printing of the difference
275 // If the arrays are small enough we could print the whole thing291 // If the arrays are small enough we could print the whole thing
276 // If the child type is u8 and no weird bytes, we could print it as strings292 // If the child type is u8 and no weird bytes, we could print it as strings
277 // Even for the length difference, it would be useful to see the values of the slices probably.293 // Even for the length difference, it would be useful to see the values of the slices probably.
278 if (expected.len != actual.len) {294 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;
280 }297 }
281 var i: usize = 0;298 var i: usize = 0;
282 while (i < expected.len) : (i += 1) {299 while (i < expected.len) : (i += 1) {
283 if (!std.meta.eql(expected[i], actual[i])) {300 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;
285 }303 }
286 }304 }
287}305}
288306
289/// This function is intended to be used only in tests. When `ok` is false, the test fails.307/// This function is intended to be used only in tests. When `ok` is false, the test fails.
290/// A message is printed to stderr and then abort is called.308/// A message is printed to stderr and then abort is called.
291pub fn expect(ok: bool) void {309pub fn expect(ok: bool) !void {
292 if (!ok) @panic("test failure");310 if (!ok) return error.TestUnexpectedResult;
293}311}
294312
295pub const TmpDir = struct {313pub const TmpDir = struct {
...@@ -356,17 +374,17 @@ test "expectEqual nested array" {...@@ -356,17 +374,17 @@ test "expectEqual nested array" {
356 [_]f32{ 0.0, 1.0 },374 [_]f32{ 0.0, 1.0 },
357 };375 };
358376
359 expectEqual(a, b);377 try expectEqual(a, b);
360}378}
361379
362test "expectEqual vector" {380test "expectEqual vector" {
363 var a = @splat(4, @as(u32, 4));381 var a = @splat(4, @as(u32, 4));
364 var b = @splat(4, @as(u32, 4));382 var b = @splat(4, @as(u32, 4));
365383
366 expectEqual(a, b);384 try expectEqual(a, b);
367}385}
368386
369pub fn expectEqualStrings(expected: []const u8, actual: []const u8) void {387pub fn expectEqualStrings(expected: []const u8, actual: []const u8) !void {
370 if (std.mem.indexOfDiff(u8, actual, expected)) |diff_index| {388 if (std.mem.indexOfDiff(u8, actual, expected)) |diff_index| {
371 print("\n====== expected this output: =========\n", .{});389 print("\n====== expected this output: =========\n", .{});
372 printWithVisibleNewlines(expected);390 printWithVisibleNewlines(expected);
...@@ -386,11 +404,11 @@ pub fn expectEqualStrings(expected: []const u8, actual: []const u8) void {...@@ -386,11 +404,11 @@ pub fn expectEqualStrings(expected: []const u8, actual: []const u8) void {
386 print("found:\n", .{});404 print("found:\n", .{});
387 printIndicatorLine(actual, diff_index);405 printIndicatorLine(actual, diff_index);
388406
389 @panic("test failure");407 return error.TestExpectedEqual;
390 }408 }
391}409}
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 {
394 if (std.mem.endsWith(u8, actual, expected_ends_with))412 if (std.mem.endsWith(u8, actual, expected_ends_with))
395 return;413 return;
396414
...@@ -407,7 +425,7 @@ pub fn expectStringEndsWith(actual: []const u8, expected_ends_with: []const u8)...@@ -407,7 +425,7 @@ pub fn expectStringEndsWith(actual: []const u8, expected_ends_with: []const u8)
407 printWithVisibleNewlines(actual);425 printWithVisibleNewlines(actual);
408 print("\n======================================\n", .{});426 print("\n======================================\n", .{});
409427
410 @panic("test failure");428 return error.TestExpectedEndsWith;
411}429}
412430
413fn printIndicatorLine(source: []const u8, indicator_index: usize) void {431fn printIndicatorLine(source: []const u8, indicator_index: usize) void {
...@@ -446,7 +464,7 @@ fn printLine(line: []const u8) void {...@@ -446,7 +464,7 @@ fn printLine(line: []const u8) void {
446}464}
447465
448test {466test {
449 expectEqualStrings("foo", "foo");467 try expectEqualStrings("foo", "foo");
450}468}
451469
452/// Given a type, reference all the declarations inside, so that the semantic analyzer sees them.470/// 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" {...@@ -271,7 +271,7 @@ test "timestamp" {
271 sleep(ns_per_ms);271 sleep(ns_per_ms);
272 const time_1 = milliTimestamp();272 const time_1 = milliTimestamp();
273 const interval = time_1 - time_0;273 const interval = time_1 - time_0;
274 testing.expect(interval > 0);274 try testing.expect(interval > 0);
275 // Tests should not depend on timings: skip test if outside margin.275 // Tests should not depend on timings: skip test if outside margin.
276 if (!(interval < margin)) return error.SkipZigTest;276 if (!(interval < margin)) return error.SkipZigTest;
277}277}
...@@ -282,13 +282,13 @@ test "Timer" {...@@ -282,13 +282,13 @@ test "Timer" {
282 var timer = try Timer.start();282 var timer = try Timer.start();
283 sleep(10 * ns_per_ms);283 sleep(10 * ns_per_ms);
284 const time_0 = timer.read();284 const time_0 = timer.read();
285 testing.expect(time_0 > 0);285 try testing.expect(time_0 > 0);
286 // Tests should not depend on timings: skip test if outside margin.286 // Tests should not depend on timings: skip test if outside margin.
287 if (!(time_0 < margin)) return error.SkipZigTest;287 if (!(time_0 < margin)) return error.SkipZigTest;
288288
289 const time_1 = timer.lap();289 const time_1 = timer.lap();
290 testing.expect(time_1 >= time_0);290 try testing.expect(time_1 >= time_0);
291291
292 timer.reset();292 timer.reset();
293 testing.expect(timer.read() < time_1);293 try testing.expect(timer.read() < time_1);
294}294}
lib/std/unicode.zig+172-172
...@@ -336,224 +336,224 @@ pub const Utf16LeIterator = struct {...@@ -336,224 +336,224 @@ pub const Utf16LeIterator = struct {
336};336};
337337
338test "utf8 encode" {338test "utf8 encode" {
339 comptime testUtf8Encode() catch unreachable;339 comptime try testUtf8Encode();
340 try testUtf8Encode();340 try testUtf8Encode();
341}341}
342fn testUtf8Encode() !void {342fn testUtf8Encode() !void {
343 // A few taken from wikipedia a few taken elsewhere343 // A few taken from wikipedia a few taken elsewhere
344 var array: [4]u8 = undefined;344 var array: [4]u8 = undefined;
345 testing.expect((try utf8Encode(try utf8Decode("€"), array[0..])) == 3);345 try testing.expect((try utf8Encode(try utf8Decode("€"), array[0..])) == 3);
346 testing.expect(array[0] == 0b11100010);346 try testing.expect(array[0] == 0b11100010);
347 testing.expect(array[1] == 0b10000010);347 try testing.expect(array[1] == 0b10000010);
348 testing.expect(array[2] == 0b10101100);348 try testing.expect(array[2] == 0b10101100);
349349
350 testing.expect((try utf8Encode(try utf8Decode("$"), array[0..])) == 1);350 try testing.expect((try utf8Encode(try utf8Decode("$"), array[0..])) == 1);
351 testing.expect(array[0] == 0b00100100);351 try testing.expect(array[0] == 0b00100100);
352352
353 testing.expect((try utf8Encode(try utf8Decode("¢"), array[0..])) == 2);353 try testing.expect((try utf8Encode(try utf8Decode("¢"), array[0..])) == 2);
354 testing.expect(array[0] == 0b11000010);354 try testing.expect(array[0] == 0b11000010);
355 testing.expect(array[1] == 0b10100010);355 try testing.expect(array[1] == 0b10100010);
356356
357 testing.expect((try utf8Encode(try utf8Decode("𐍈"), array[0..])) == 4);357 try testing.expect((try utf8Encode(try utf8Decode("𐍈"), array[0..])) == 4);
358 testing.expect(array[0] == 0b11110000);358 try testing.expect(array[0] == 0b11110000);
359 testing.expect(array[1] == 0b10010000);359 try testing.expect(array[1] == 0b10010000);
360 testing.expect(array[2] == 0b10001101);360 try testing.expect(array[2] == 0b10001101);
361 testing.expect(array[3] == 0b10001000);361 try testing.expect(array[3] == 0b10001000);
362}362}
363363
364test "utf8 encode error" {364test "utf8 encode error" {
365 comptime testUtf8EncodeError();365 comptime try testUtf8EncodeError();
366 testUtf8EncodeError();366 try testUtf8EncodeError();
367}367}
368fn testUtf8EncodeError() void {368fn testUtf8EncodeError() !void {
369 var array: [4]u8 = undefined;369 var array: [4]u8 = undefined;
370 testErrorEncode(0xd800, array[0..], error.Utf8CannotEncodeSurrogateHalf);370 try testErrorEncode(0xd800, array[0..], error.Utf8CannotEncodeSurrogateHalf);
371 testErrorEncode(0xdfff, array[0..], error.Utf8CannotEncodeSurrogateHalf);371 try testErrorEncode(0xdfff, array[0..], error.Utf8CannotEncodeSurrogateHalf);
372 testErrorEncode(0x110000, array[0..], error.CodepointTooLarge);372 try testErrorEncode(0x110000, array[0..], error.CodepointTooLarge);
373 testErrorEncode(0x1fffff, array[0..], error.CodepointTooLarge);373 try testErrorEncode(0x1fffff, array[0..], error.CodepointTooLarge);
374}374}
375375
376fn testErrorEncode(codePoint: u21, array: []u8, expectedErr: anyerror) void {376fn testErrorEncode(codePoint: u21, array: []u8, expectedErr: anyerror) !void {
377 testing.expectError(expectedErr, utf8Encode(codePoint, array));377 try testing.expectError(expectedErr, utf8Encode(codePoint, array));
378}378}
379379
380test "utf8 iterator on ascii" {380test "utf8 iterator on ascii" {
381 comptime testUtf8IteratorOnAscii();381 comptime try testUtf8IteratorOnAscii();
382 testUtf8IteratorOnAscii();382 try testUtf8IteratorOnAscii();
383}383}
384fn testUtf8IteratorOnAscii() void {384fn testUtf8IteratorOnAscii() !void {
385 const s = Utf8View.initComptime("abc");385 const s = Utf8View.initComptime("abc");
386386
387 var it1 = s.iterator();387 var it1 = s.iterator();
388 testing.expect(std.mem.eql(u8, "a", it1.nextCodepointSlice().?));388 try testing.expect(std.mem.eql(u8, "a", it1.nextCodepointSlice().?));
389 testing.expect(std.mem.eql(u8, "b", it1.nextCodepointSlice().?));389 try testing.expect(std.mem.eql(u8, "b", it1.nextCodepointSlice().?));
390 testing.expect(std.mem.eql(u8, "c", it1.nextCodepointSlice().?));390 try testing.expect(std.mem.eql(u8, "c", it1.nextCodepointSlice().?));
391 testing.expect(it1.nextCodepointSlice() == null);391 try testing.expect(it1.nextCodepointSlice() == null);
392392
393 var it2 = s.iterator();393 var it2 = s.iterator();
394 testing.expect(it2.nextCodepoint().? == 'a');394 try testing.expect(it2.nextCodepoint().? == 'a');
395 testing.expect(it2.nextCodepoint().? == 'b');395 try testing.expect(it2.nextCodepoint().? == 'b');
396 testing.expect(it2.nextCodepoint().? == 'c');396 try testing.expect(it2.nextCodepoint().? == 'c');
397 testing.expect(it2.nextCodepoint() == null);397 try testing.expect(it2.nextCodepoint() == null);
398}398}
399399
400test "utf8 view bad" {400test "utf8 view bad" {
401 comptime testUtf8ViewBad();401 comptime try testUtf8ViewBad();
402 testUtf8ViewBad();402 try testUtf8ViewBad();
403}403}
404fn testUtf8ViewBad() void {404fn testUtf8ViewBad() !void {
405 // Compile-time error.405 // Compile-time error.
406 // const s3 = Utf8View.initComptime("\xfe\xf2");406 // 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"));
408}408}
409409
410test "utf8 view ok" {410test "utf8 view ok" {
411 comptime testUtf8ViewOk();411 comptime try testUtf8ViewOk();
412 testUtf8ViewOk();412 try testUtf8ViewOk();
413}413}
414fn testUtf8ViewOk() void {414fn testUtf8ViewOk() !void {
415 const s = Utf8View.initComptime("東京市");415 const s = Utf8View.initComptime("東京市");
416416
417 var it1 = s.iterator();417 var it1 = s.iterator();
418 testing.expect(std.mem.eql(u8, "東", it1.nextCodepointSlice().?));418 try testing.expect(std.mem.eql(u8, "東", it1.nextCodepointSlice().?));
419 testing.expect(std.mem.eql(u8, "京", it1.nextCodepointSlice().?));419 try testing.expect(std.mem.eql(u8, "京", it1.nextCodepointSlice().?));
420 testing.expect(std.mem.eql(u8, "市", it1.nextCodepointSlice().?));420 try testing.expect(std.mem.eql(u8, "市", it1.nextCodepointSlice().?));
421 testing.expect(it1.nextCodepointSlice() == null);421 try testing.expect(it1.nextCodepointSlice() == null);
422422
423 var it2 = s.iterator();423 var it2 = s.iterator();
424 testing.expect(it2.nextCodepoint().? == 0x6771);424 try testing.expect(it2.nextCodepoint().? == 0x6771);
425 testing.expect(it2.nextCodepoint().? == 0x4eac);425 try testing.expect(it2.nextCodepoint().? == 0x4eac);
426 testing.expect(it2.nextCodepoint().? == 0x5e02);426 try testing.expect(it2.nextCodepoint().? == 0x5e02);
427 testing.expect(it2.nextCodepoint() == null);427 try testing.expect(it2.nextCodepoint() == null);
428}428}
429429
430test "bad utf8 slice" {430test "bad utf8 slice" {
431 comptime testBadUtf8Slice();431 comptime try testBadUtf8Slice();
432 testBadUtf8Slice();432 try testBadUtf8Slice();
433}433}
434fn testBadUtf8Slice() void {434fn testBadUtf8Slice() !void {
435 testing.expect(utf8ValidateSlice("abc"));435 try testing.expect(utf8ValidateSlice("abc"));
436 testing.expect(!utf8ValidateSlice("abc\xc0"));436 try testing.expect(!utf8ValidateSlice("abc\xc0"));
437 testing.expect(!utf8ValidateSlice("abc\xc0abc"));437 try testing.expect(!utf8ValidateSlice("abc\xc0abc"));
438 testing.expect(utf8ValidateSlice("abc\xdf\xbf"));438 try testing.expect(utf8ValidateSlice("abc\xdf\xbf"));
439}439}
440440
441test "valid utf8" {441test "valid utf8" {
442 comptime testValidUtf8();442 comptime try testValidUtf8();
443 testValidUtf8();443 try testValidUtf8();
444}444}
445fn testValidUtf8() void {445fn testValidUtf8() !void {
446 testValid("\x00", 0x0);446 try testValid("\x00", 0x0);
447 testValid("\x20", 0x20);447 try testValid("\x20", 0x20);
448 testValid("\x7f", 0x7f);448 try testValid("\x7f", 0x7f);
449 testValid("\xc2\x80", 0x80);449 try testValid("\xc2\x80", 0x80);
450 testValid("\xdf\xbf", 0x7ff);450 try testValid("\xdf\xbf", 0x7ff);
451 testValid("\xe0\xa0\x80", 0x800);451 try testValid("\xe0\xa0\x80", 0x800);
452 testValid("\xe1\x80\x80", 0x1000);452 try testValid("\xe1\x80\x80", 0x1000);
453 testValid("\xef\xbf\xbf", 0xffff);453 try testValid("\xef\xbf\xbf", 0xffff);
454 testValid("\xf0\x90\x80\x80", 0x10000);454 try testValid("\xf0\x90\x80\x80", 0x10000);
455 testValid("\xf1\x80\x80\x80", 0x40000);455 try testValid("\xf1\x80\x80\x80", 0x40000);
456 testValid("\xf3\xbf\xbf\xbf", 0xfffff);456 try testValid("\xf3\xbf\xbf\xbf", 0xfffff);
457 testValid("\xf4\x8f\xbf\xbf", 0x10ffff);457 try testValid("\xf4\x8f\xbf\xbf", 0x10ffff);
458}458}
459459
460test "invalid utf8 continuation bytes" {460test "invalid utf8 continuation bytes" {
461 comptime testInvalidUtf8ContinuationBytes();461 comptime try testInvalidUtf8ContinuationBytes();
462 testInvalidUtf8ContinuationBytes();462 try testInvalidUtf8ContinuationBytes();
463}463}
464fn testInvalidUtf8ContinuationBytes() void {464fn testInvalidUtf8ContinuationBytes() !void {
465 // unexpected continuation465 // unexpected continuation
466 testError("\x80", error.Utf8InvalidStartByte);466 try testError("\x80", error.Utf8InvalidStartByte);
467 testError("\xbf", error.Utf8InvalidStartByte);467 try testError("\xbf", error.Utf8InvalidStartByte);
468 // too many leading 1's468 // too many leading 1's
469 testError("\xf8", error.Utf8InvalidStartByte);469 try testError("\xf8", error.Utf8InvalidStartByte);
470 testError("\xff", error.Utf8InvalidStartByte);470 try testError("\xff", error.Utf8InvalidStartByte);
471 // expected continuation for 2 byte sequences471 // expected continuation for 2 byte sequences
472 testError("\xc2", error.UnexpectedEof);472 try testError("\xc2", error.UnexpectedEof);
473 testError("\xc2\x00", error.Utf8ExpectedContinuation);473 try testError("\xc2\x00", error.Utf8ExpectedContinuation);
474 testError("\xc2\xc0", error.Utf8ExpectedContinuation);474 try testError("\xc2\xc0", error.Utf8ExpectedContinuation);
475 // expected continuation for 3 byte sequences475 // expected continuation for 3 byte sequences
476 testError("\xe0", error.UnexpectedEof);476 try testError("\xe0", error.UnexpectedEof);
477 testError("\xe0\x00", error.UnexpectedEof);477 try testError("\xe0\x00", error.UnexpectedEof);
478 testError("\xe0\xc0", error.UnexpectedEof);478 try testError("\xe0\xc0", error.UnexpectedEof);
479 testError("\xe0\xa0", error.UnexpectedEof);479 try testError("\xe0\xa0", error.UnexpectedEof);
480 testError("\xe0\xa0\x00", error.Utf8ExpectedContinuation);480 try testError("\xe0\xa0\x00", error.Utf8ExpectedContinuation);
481 testError("\xe0\xa0\xc0", error.Utf8ExpectedContinuation);481 try testError("\xe0\xa0\xc0", error.Utf8ExpectedContinuation);
482 // expected continuation for 4 byte sequences482 // expected continuation for 4 byte sequences
483 testError("\xf0", error.UnexpectedEof);483 try testError("\xf0", error.UnexpectedEof);
484 testError("\xf0\x00", error.UnexpectedEof);484 try testError("\xf0\x00", error.UnexpectedEof);
485 testError("\xf0\xc0", error.UnexpectedEof);485 try testError("\xf0\xc0", error.UnexpectedEof);
486 testError("\xf0\x90\x00", error.UnexpectedEof);486 try testError("\xf0\x90\x00", error.UnexpectedEof);
487 testError("\xf0\x90\xc0", error.UnexpectedEof);487 try testError("\xf0\x90\xc0", error.UnexpectedEof);
488 testError("\xf0\x90\x80\x00", error.Utf8ExpectedContinuation);488 try testError("\xf0\x90\x80\x00", error.Utf8ExpectedContinuation);
489 testError("\xf0\x90\x80\xc0", error.Utf8ExpectedContinuation);489 try testError("\xf0\x90\x80\xc0", error.Utf8ExpectedContinuation);
490}490}
491491
492test "overlong utf8 codepoint" {492test "overlong utf8 codepoint" {
493 comptime testOverlongUtf8Codepoint();493 comptime try testOverlongUtf8Codepoint();
494 testOverlongUtf8Codepoint();494 try testOverlongUtf8Codepoint();
495}495}
496fn testOverlongUtf8Codepoint() void {496fn testOverlongUtf8Codepoint() !void {
497 testError("\xc0\x80", error.Utf8OverlongEncoding);497 try testError("\xc0\x80", error.Utf8OverlongEncoding);
498 testError("\xc1\xbf", error.Utf8OverlongEncoding);498 try testError("\xc1\xbf", error.Utf8OverlongEncoding);
499 testError("\xe0\x80\x80", error.Utf8OverlongEncoding);499 try testError("\xe0\x80\x80", error.Utf8OverlongEncoding);
500 testError("\xe0\x9f\xbf", error.Utf8OverlongEncoding);500 try testError("\xe0\x9f\xbf", error.Utf8OverlongEncoding);
501 testError("\xf0\x80\x80\x80", error.Utf8OverlongEncoding);501 try testError("\xf0\x80\x80\x80", error.Utf8OverlongEncoding);
502 testError("\xf0\x8f\xbf\xbf", error.Utf8OverlongEncoding);502 try testError("\xf0\x8f\xbf\xbf", error.Utf8OverlongEncoding);
503}503}
504504
505test "misc invalid utf8" {505test "misc invalid utf8" {
506 comptime testMiscInvalidUtf8();506 comptime try testMiscInvalidUtf8();
507 testMiscInvalidUtf8();507 try testMiscInvalidUtf8();
508}508}
509fn testMiscInvalidUtf8() void {509fn testMiscInvalidUtf8() !void {
510 // codepoint out of bounds510 // codepoint out of bounds
511 testError("\xf4\x90\x80\x80", error.Utf8CodepointTooLarge);511 try testError("\xf4\x90\x80\x80", error.Utf8CodepointTooLarge);
512 testError("\xf7\xbf\xbf\xbf", error.Utf8CodepointTooLarge);512 try testError("\xf7\xbf\xbf\xbf", error.Utf8CodepointTooLarge);
513 // surrogate halves513 // surrogate halves
514 testValid("\xed\x9f\xbf", 0xd7ff);514 try testValid("\xed\x9f\xbf", 0xd7ff);
515 testError("\xed\xa0\x80", error.Utf8EncodesSurrogateHalf);515 try testError("\xed\xa0\x80", error.Utf8EncodesSurrogateHalf);
516 testError("\xed\xbf\xbf", error.Utf8EncodesSurrogateHalf);516 try testError("\xed\xbf\xbf", error.Utf8EncodesSurrogateHalf);
517 testValid("\xee\x80\x80", 0xe000);517 try testValid("\xee\x80\x80", 0xe000);
518}518}
519519
520test "utf8 iterator peeking" {520test "utf8 iterator peeking" {
521 comptime testUtf8Peeking();521 comptime try testUtf8Peeking();
522 testUtf8Peeking();522 try testUtf8Peeking();
523}523}
524524
525fn testUtf8Peeking() void {525fn testUtf8Peeking() !void {
526 const s = Utf8View.initComptime("noël");526 const s = Utf8View.initComptime("noël");
527 var it = s.iterator();527 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)));531 try testing.expect(std.mem.eql(u8, "o", it.peek(1)));
532 testing.expect(std.mem.eql(u8, "oë", it.peek(2)));532 try testing.expect(std.mem.eql(u8, "oë", it.peek(2)));
533 testing.expect(std.mem.eql(u8, "oël", it.peek(3)));533 try testing.expect(std.mem.eql(u8, "oël", it.peek(3)));
534 testing.expect(std.mem.eql(u8, "oël", it.peek(4)));534 try testing.expect(std.mem.eql(u8, "oël", it.peek(4)));
535 testing.expect(std.mem.eql(u8, "oël", it.peek(10)));535 try testing.expect(std.mem.eql(u8, "oël", it.peek(10)));
536536
537 testing.expect(std.mem.eql(u8, "o", it.nextCodepointSlice().?));537 try testing.expect(std.mem.eql(u8, "o", it.nextCodepointSlice().?));
538 testing.expect(std.mem.eql(u8, "ë", it.nextCodepointSlice().?));538 try testing.expect(std.mem.eql(u8, "ë", it.nextCodepointSlice().?));
539 testing.expect(std.mem.eql(u8, "l", it.nextCodepointSlice().?));539 try testing.expect(std.mem.eql(u8, "l", it.nextCodepointSlice().?));
540 testing.expect(it.nextCodepointSlice() == null);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)));
543}543}
544544
545fn testError(bytes: []const u8, expected_err: anyerror) void {545fn testError(bytes: []const u8, expected_err: anyerror) !void {
546 testing.expectError(expected_err, testDecode(bytes));546 try testing.expectError(expected_err, testDecode(bytes));
547}547}
548548
549fn testValid(bytes: []const u8, expected_codepoint: u21) void {549fn testValid(bytes: []const u8, expected_codepoint: u21) !void {
550 testing.expect((testDecode(bytes) catch unreachable) == expected_codepoint);550 try testing.expect((testDecode(bytes) catch unreachable) == expected_codepoint);
551}551}
552552
553fn testDecode(bytes: []const u8) !u21 {553fn testDecode(bytes: []const u8) !u21 {
554 const length = try utf8ByteSequenceLength(bytes[0]);554 const length = try utf8ByteSequenceLength(bytes[0]);
555 if (bytes.len < length) return error.UnexpectedEof;555 if (bytes.len < length) return error.UnexpectedEof;
556 testing.expect(bytes.len == length);556 try testing.expect(bytes.len == length);
557 return utf8Decode(bytes);557 return utf8Decode(bytes);
558}558}
559559
...@@ -615,7 +615,7 @@ test "utf16leToUtf8" {...@@ -615,7 +615,7 @@ test "utf16leToUtf8" {
615 mem.writeIntSliceLittle(u16, utf16le_as_bytes[2..], 'a');615 mem.writeIntSliceLittle(u16, utf16le_as_bytes[2..], 'a');
616 const utf8 = try utf16leToUtf8Alloc(std.testing.allocator, &utf16le);616 const utf8 = try utf16leToUtf8Alloc(std.testing.allocator, &utf16le);
617 defer std.testing.allocator.free(utf8);617 defer std.testing.allocator.free(utf8);
618 testing.expect(mem.eql(u8, utf8, "Aa"));618 try testing.expect(mem.eql(u8, utf8, "Aa"));
619 }619 }
620620
621 {621 {
...@@ -623,7 +623,7 @@ test "utf16leToUtf8" {...@@ -623,7 +623,7 @@ test "utf16leToUtf8" {
623 mem.writeIntSliceLittle(u16, utf16le_as_bytes[2..], 0xffff);623 mem.writeIntSliceLittle(u16, utf16le_as_bytes[2..], 0xffff);
624 const utf8 = try utf16leToUtf8Alloc(std.testing.allocator, &utf16le);624 const utf8 = try utf16leToUtf8Alloc(std.testing.allocator, &utf16le);
625 defer std.testing.allocator.free(utf8);625 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"));
627 }627 }
628628
629 {629 {
...@@ -632,7 +632,7 @@ test "utf16leToUtf8" {...@@ -632,7 +632,7 @@ test "utf16leToUtf8" {
632 mem.writeIntSliceLittle(u16, utf16le_as_bytes[2..], 0xe000);632 mem.writeIntSliceLittle(u16, utf16le_as_bytes[2..], 0xe000);
633 const utf8 = try utf16leToUtf8Alloc(std.testing.allocator, &utf16le);633 const utf8 = try utf16leToUtf8Alloc(std.testing.allocator, &utf16le);
634 defer std.testing.allocator.free(utf8);634 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"));
636 }636 }
637637
638 {638 {
...@@ -641,7 +641,7 @@ test "utf16leToUtf8" {...@@ -641,7 +641,7 @@ test "utf16leToUtf8" {
641 mem.writeIntSliceLittle(u16, utf16le_as_bytes[2..], 0xdc00);641 mem.writeIntSliceLittle(u16, utf16le_as_bytes[2..], 0xdc00);
642 const utf8 = try utf16leToUtf8Alloc(std.testing.allocator, &utf16le);642 const utf8 = try utf16leToUtf8Alloc(std.testing.allocator, &utf16le);
643 defer std.testing.allocator.free(utf8);643 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"));
645 }645 }
646646
647 {647 {
...@@ -650,7 +650,7 @@ test "utf16leToUtf8" {...@@ -650,7 +650,7 @@ test "utf16leToUtf8" {
650 mem.writeIntSliceLittle(u16, utf16le_as_bytes[2..], 0xdfff);650 mem.writeIntSliceLittle(u16, utf16le_as_bytes[2..], 0xdfff);
651 const utf8 = try utf16leToUtf8Alloc(std.testing.allocator, &utf16le);651 const utf8 = try utf16leToUtf8Alloc(std.testing.allocator, &utf16le);
652 defer std.testing.allocator.free(utf8);652 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"));
654 }654 }
655655
656 {656 {
...@@ -658,7 +658,7 @@ test "utf16leToUtf8" {...@@ -658,7 +658,7 @@ test "utf16leToUtf8" {
658 mem.writeIntSliceLittle(u16, utf16le_as_bytes[2..], 0xdc00);658 mem.writeIntSliceLittle(u16, utf16le_as_bytes[2..], 0xdc00);
659 const utf8 = try utf16leToUtf8Alloc(std.testing.allocator, &utf16le);659 const utf8 = try utf16leToUtf8Alloc(std.testing.allocator, &utf16le);
660 defer std.testing.allocator.free(utf8);660 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"));
662 }662 }
663}663}
664664
...@@ -717,13 +717,13 @@ test "utf8ToUtf16Le" {...@@ -717,13 +717,13 @@ test "utf8ToUtf16Le" {
717 var utf16le: [2]u16 = [_]u16{0} ** 2;717 var utf16le: [2]u16 = [_]u16{0} ** 2;
718 {718 {
719 const length = try utf8ToUtf16Le(utf16le[0..], "𐐷");719 const length = try utf8ToUtf16Le(utf16le[0..], "𐐷");
720 testing.expectEqual(@as(usize, 2), length);720 try testing.expectEqual(@as(usize, 2), length);
721 testing.expectEqualSlices(u8, "\x01\xd8\x37\xdc", mem.sliceAsBytes(utf16le[0..]));721 try testing.expectEqualSlices(u8, "\x01\xd8\x37\xdc", mem.sliceAsBytes(utf16le[0..]));
722 }722 }
723 {723 {
724 const length = try utf8ToUtf16Le(utf16le[0..], "\u{10FFFF}");724 const length = try utf8ToUtf16Le(utf16le[0..], "\u{10FFFF}");
725 testing.expectEqual(@as(usize, 2), length);725 try testing.expectEqual(@as(usize, 2), length);
726 testing.expectEqualSlices(u8, "\xff\xdb\xff\xdf", mem.sliceAsBytes(utf16le[0..]));726 try testing.expectEqualSlices(u8, "\xff\xdb\xff\xdf", mem.sliceAsBytes(utf16le[0..]));
727 }727 }
728}728}
729729
...@@ -731,14 +731,14 @@ test "utf8ToUtf16LeWithNull" {...@@ -731,14 +731,14 @@ test "utf8ToUtf16LeWithNull" {
731 {731 {
732 const utf16 = try utf8ToUtf16LeWithNull(testing.allocator, "𐐷");732 const utf16 = try utf8ToUtf16LeWithNull(testing.allocator, "𐐷");
733 defer testing.allocator.free(utf16);733 defer testing.allocator.free(utf16);
734 testing.expectEqualSlices(u8, "\x01\xd8\x37\xdc", mem.sliceAsBytes(utf16[0..]));734 try testing.expectEqualSlices(u8, "\x01\xd8\x37\xdc", mem.sliceAsBytes(utf16[0..]));
735 testing.expect(utf16[2] == 0);735 try testing.expect(utf16[2] == 0);
736 }736 }
737 {737 {
738 const utf16 = try utf8ToUtf16LeWithNull(testing.allocator, "\u{10FFFF}");738 const utf16 = try utf8ToUtf16LeWithNull(testing.allocator, "\u{10FFFF}");
739 defer testing.allocator.free(utf16);739 defer testing.allocator.free(utf16);
740 testing.expectEqualSlices(u8, "\xff\xdb\xff\xdf", mem.sliceAsBytes(utf16[0..]));740 try testing.expectEqualSlices(u8, "\xff\xdb\xff\xdf", mem.sliceAsBytes(utf16[0..]));
741 testing.expect(utf16[2] == 0);741 try testing.expect(utf16[2] == 0);
742 }742 }
743}743}
744744
...@@ -776,8 +776,8 @@ test "utf8ToUtf16LeStringLiteral" {...@@ -776,8 +776,8 @@ test "utf8ToUtf16LeStringLiteral" {
776 mem.nativeToLittle(u16, 0x41),776 mem.nativeToLittle(u16, 0x41),
777 };777 };
778 const utf16 = utf8ToUtf16LeStringLiteral("A");778 const utf16 = utf8ToUtf16LeStringLiteral("A");
779 testing.expectEqualSlices(u16, &bytes, utf16);779 try testing.expectEqualSlices(u16, &bytes, utf16);
780 testing.expect(utf16[1] == 0);780 try testing.expect(utf16[1] == 0);
781 }781 }
782 {782 {
783 const bytes = [_:0]u16{783 const bytes = [_:0]u16{
...@@ -785,32 +785,32 @@ test "utf8ToUtf16LeStringLiteral" {...@@ -785,32 +785,32 @@ test "utf8ToUtf16LeStringLiteral" {
785 mem.nativeToLittle(u16, 0xDC37),785 mem.nativeToLittle(u16, 0xDC37),
786 };786 };
787 const utf16 = utf8ToUtf16LeStringLiteral("𐐷");787 const utf16 = utf8ToUtf16LeStringLiteral("𐐷");
788 testing.expectEqualSlices(u16, &bytes, utf16);788 try testing.expectEqualSlices(u16, &bytes, utf16);
789 testing.expect(utf16[2] == 0);789 try testing.expect(utf16[2] == 0);
790 }790 }
791 {791 {
792 const bytes = [_:0]u16{792 const bytes = [_:0]u16{
793 mem.nativeToLittle(u16, 0x02FF),793 mem.nativeToLittle(u16, 0x02FF),
794 };794 };
795 const utf16 = utf8ToUtf16LeStringLiteral("\u{02FF}");795 const utf16 = utf8ToUtf16LeStringLiteral("\u{02FF}");
796 testing.expectEqualSlices(u16, &bytes, utf16);796 try testing.expectEqualSlices(u16, &bytes, utf16);
797 testing.expect(utf16[1] == 0);797 try testing.expect(utf16[1] == 0);
798 }798 }
799 {799 {
800 const bytes = [_:0]u16{800 const bytes = [_:0]u16{
801 mem.nativeToLittle(u16, 0x7FF),801 mem.nativeToLittle(u16, 0x7FF),
802 };802 };
803 const utf16 = utf8ToUtf16LeStringLiteral("\u{7FF}");803 const utf16 = utf8ToUtf16LeStringLiteral("\u{7FF}");
804 testing.expectEqualSlices(u16, &bytes, utf16);804 try testing.expectEqualSlices(u16, &bytes, utf16);
805 testing.expect(utf16[1] == 0);805 try testing.expect(utf16[1] == 0);
806 }806 }
807 {807 {
808 const bytes = [_:0]u16{808 const bytes = [_:0]u16{
809 mem.nativeToLittle(u16, 0x801),809 mem.nativeToLittle(u16, 0x801),
810 };810 };
811 const utf16 = utf8ToUtf16LeStringLiteral("\u{801}");811 const utf16 = utf8ToUtf16LeStringLiteral("\u{801}");
812 testing.expectEqualSlices(u16, &bytes, utf16);812 try testing.expectEqualSlices(u16, &bytes, utf16);
813 testing.expect(utf16[1] == 0);813 try testing.expect(utf16[1] == 0);
814 }814 }
815 {815 {
816 const bytes = [_:0]u16{816 const bytes = [_:0]u16{
...@@ -818,35 +818,35 @@ test "utf8ToUtf16LeStringLiteral" {...@@ -818,35 +818,35 @@ test "utf8ToUtf16LeStringLiteral" {
818 mem.nativeToLittle(u16, 0xDFFF),818 mem.nativeToLittle(u16, 0xDFFF),
819 };819 };
820 const utf16 = utf8ToUtf16LeStringLiteral("\u{10FFFF}");820 const utf16 = utf8ToUtf16LeStringLiteral("\u{10FFFF}");
821 testing.expectEqualSlices(u16, &bytes, utf16);821 try testing.expectEqualSlices(u16, &bytes, utf16);
822 testing.expect(utf16[2] == 0);822 try testing.expect(utf16[2] == 0);
823 }823 }
824}824}
825825
826fn testUtf8CountCodepoints() !void {826fn testUtf8CountCodepoints() !void {
827 testing.expectEqual(@as(usize, 10), try utf8CountCodepoints("abcdefghij"));827 try testing.expectEqual(@as(usize, 10), try utf8CountCodepoints("abcdefghij"));
828 testing.expectEqual(@as(usize, 10), try utf8CountCodepoints("äåéëþüúíóö"));828 try testing.expectEqual(@as(usize, 10), try utf8CountCodepoints("äåéëþüúíóö"));
829 testing.expectEqual(@as(usize, 5), try utf8CountCodepoints("こんにちは"));829 try testing.expectEqual(@as(usize, 5), try utf8CountCodepoints("こんにちは"));
830 // testing.expectError(error.Utf8EncodesSurrogateHalf, utf8CountCodepoints("\xED\xA0\x80"));830 // testing.expectError(error.Utf8EncodesSurrogateHalf, utf8CountCodepoints("\xED\xA0\x80"));
831}831}
832832
833test "utf8 count codepoints" {833test "utf8 count codepoints" {
834 try testUtf8CountCodepoints();834 try testUtf8CountCodepoints();
835 comptime testUtf8CountCodepoints() catch unreachable;835 comptime try testUtf8CountCodepoints();
836}836}
837837
838fn testUtf8ValidCodepoint() !void {838fn testUtf8ValidCodepoint() !void {
839 testing.expect(utf8ValidCodepoint('e'));839 try testing.expect(utf8ValidCodepoint('e'));
840 testing.expect(utf8ValidCodepoint('ë'));840 try testing.expect(utf8ValidCodepoint('ë'));
841 testing.expect(utf8ValidCodepoint('は'));841 try testing.expect(utf8ValidCodepoint('は'));
842 testing.expect(utf8ValidCodepoint(0xe000));842 try testing.expect(utf8ValidCodepoint(0xe000));
843 testing.expect(utf8ValidCodepoint(0x10ffff));843 try testing.expect(utf8ValidCodepoint(0x10ffff));
844 testing.expect(!utf8ValidCodepoint(0xd800));844 try testing.expect(!utf8ValidCodepoint(0xd800));
845 testing.expect(!utf8ValidCodepoint(0xdfff));845 try testing.expect(!utf8ValidCodepoint(0xdfff));
846 testing.expect(!utf8ValidCodepoint(0x110000));846 try testing.expect(!utf8ValidCodepoint(0x110000));
847}847}
848848
849test "utf8 valid codepoint" {849test "utf8 valid codepoint" {
850 try testUtf8ValidCodepoint();850 try testUtf8ValidCodepoint();
851 comptime testUtf8ValidCodepoint() catch unreachable;851 comptime try testUtf8ValidCodepoint();
852}852}
lib/std/valgrind/memcheck.zig+2-2
...@@ -149,7 +149,7 @@ pub fn countLeaks() CountResult {...@@ -149,7 +149,7 @@ pub fn countLeaks() CountResult {
149}149}
150150
151test "countLeaks" {151test "countLeaks" {
152 testing.expectEqual(152 try testing.expectEqual(
153 @as(CountResult, .{153 @as(CountResult, .{
154 .leaked = 0,154 .leaked = 0,
155 .dubious = 0,155 .dubious = 0,
...@@ -179,7 +179,7 @@ pub fn countLeakBlocks() CountResult {...@@ -179,7 +179,7 @@ pub fn countLeakBlocks() CountResult {
179}179}
180180
181test "countLeakBlocks" {181test "countLeakBlocks" {
182 testing.expectEqual(182 try testing.expectEqual(
183 @as(CountResult, .{183 @as(CountResult, .{
184 .leaked = 0,184 .leaked = 0,
185 .dubious = 0,185 .dubious = 0,
lib/std/wasm.zig+9-9
...@@ -200,11 +200,11 @@ test "Wasm - opcodes" {...@@ -200,11 +200,11 @@ test "Wasm - opcodes" {
200 const local_get = opcode(.local_get);200 const local_get = opcode(.local_get);
201 const i64_extend32_s = opcode(.i64_extend32_s);201 const i64_extend32_s = opcode(.i64_extend32_s);
202202
203 testing.expectEqual(@as(u16, 0x41), i32_const);203 try testing.expectEqual(@as(u16, 0x41), i32_const);
204 testing.expectEqual(@as(u16, 0x0B), end);204 try testing.expectEqual(@as(u16, 0x0B), end);
205 testing.expectEqual(@as(u16, 0x1A), drop);205 try testing.expectEqual(@as(u16, 0x1A), drop);
206 testing.expectEqual(@as(u16, 0x20), local_get);206 try testing.expectEqual(@as(u16, 0x20), local_get);
207 testing.expectEqual(@as(u16, 0xC4), i64_extend32_s);207 try testing.expectEqual(@as(u16, 0xC4), i64_extend32_s);
208}208}
209209
210/// Enum representing all Wasm value types as per spec:210/// Enum representing all Wasm value types as per spec:
...@@ -227,10 +227,10 @@ test "Wasm - valtypes" {...@@ -227,10 +227,10 @@ test "Wasm - valtypes" {
227 const _f32 = valtype(.f32);227 const _f32 = valtype(.f32);
228 const _f64 = valtype(.f64);228 const _f64 = valtype(.f64);
229229
230 testing.expectEqual(@as(u8, 0x7F), _i32);230 try testing.expectEqual(@as(u8, 0x7F), _i32);
231 testing.expectEqual(@as(u8, 0x7E), _i64);231 try testing.expectEqual(@as(u8, 0x7E), _i64);
232 testing.expectEqual(@as(u8, 0x7D), _f32);232 try testing.expectEqual(@as(u8, 0x7D), _f32);
233 testing.expectEqual(@as(u8, 0x7C), _f64);233 try testing.expectEqual(@as(u8, 0x7C), _f64);
234}234}
235235
236/// Wasm module sections as per spec:236/// 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" {...@@ -322,7 +322,7 @@ test "tcp/client: set read timeout of 1 millisecond on blocking client" {
322 defer conn.deinit();322 defer conn.deinit();
323323
324 var buf: [1]u8 = undefined;324 var buf: [1]u8 = undefined;
325 testing.expectError(error.WouldBlock, client.read(&buf));325 try testing.expectError(error.WouldBlock, client.read(&buf));
326}326}
327327
328test "tcp/listener: bind to unspecified ipv4 address" {328test "tcp/listener: bind to unspecified ipv4 address" {
...@@ -335,7 +335,7 @@ test "tcp/listener: bind to unspecified ipv4 address" {...@@ -335,7 +335,7 @@ test "tcp/listener: bind to unspecified ipv4 address" {
335 try listener.listen(128);335 try listener.listen(128);
336336
337 const address = try listener.getLocalAddress();337 const address = try listener.getLocalAddress();
338 testing.expect(address == .ipv4);338 try testing.expect(address == .ipv4);
339}339}
340340
341test "tcp/listener: bind to unspecified ipv6 address" {341test "tcp/listener: bind to unspecified ipv6 address" {
...@@ -348,5 +348,5 @@ test "tcp/listener: bind to unspecified ipv6 address" {...@@ -348,5 +348,5 @@ test "tcp/listener: bind to unspecified ipv6 address" {
348 try listener.listen(128);348 try listener.listen(128);
349349
350 const address = try listener.getLocalAddress();350 const address = try listener.getLocalAddress();
351 testing.expect(address == .ipv6);351 try testing.expect(address == .ipv6);
352}352}
lib/std/x/os/net.zig+3-3
...@@ -499,12 +499,12 @@ test {...@@ -499,12 +499,12 @@ test {
499499
500test "ip: convert to and from ipv6" {500test "ip: convert to and from ipv6" {
501 try testing.expectFmt("::7f00:1", "{}", .{IPv4.localhost.toIPv6()});501 try testing.expectFmt("::7f00:1", "{}", .{IPv4.localhost.toIPv6()});
502 testing.expect(!IPv4.localhost.toIPv6().mapsToIPv4());502 try testing.expect(!IPv4.localhost.toIPv6().mapsToIPv4());
503503
504 try testing.expectFmt("::ffff:127.0.0.1", "{}", .{IPv4.localhost.mapToIPv6()});504 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);
508 try testing.expectFmt("127.0.0.1", "{}", .{IPv4.localhost.mapToIPv6().toIPv4()});508 try testing.expectFmt("127.0.0.1", "{}", .{IPv4.localhost.mapToIPv6().toIPv4()});
509}509}
510510
lib/std/zig.zig+19-19
...@@ -257,26 +257,26 @@ pub fn parseCharLiteral(...@@ -257,26 +257,26 @@ pub fn parseCharLiteral(
257257
258test "parseCharLiteral" {258test "parseCharLiteral" {
259 var bad_index: usize = undefined;259 var bad_index: usize = undefined;
260 std.testing.expectEqual(try parseCharLiteral("'a'", &bad_index), 'a');260 try std.testing.expectEqual(try parseCharLiteral("'a'", &bad_index), 'a');
261 std.testing.expectEqual(try parseCharLiteral("'ä'", &bad_index), 'ä');261 try std.testing.expectEqual(try parseCharLiteral("'ä'", &bad_index), 'ä');
262 std.testing.expectEqual(try parseCharLiteral("'\\x00'", &bad_index), 0);262 try std.testing.expectEqual(try parseCharLiteral("'\\x00'", &bad_index), 0);
263 std.testing.expectEqual(try parseCharLiteral("'\\x4f'", &bad_index), 0x4f);263 try std.testing.expectEqual(try parseCharLiteral("'\\x4f'", &bad_index), 0x4f);
264 std.testing.expectEqual(try parseCharLiteral("'\\x4F'", &bad_index), 0x4f);264 try std.testing.expectEqual(try parseCharLiteral("'\\x4F'", &bad_index), 0x4f);
265 std.testing.expectEqual(try parseCharLiteral("'ぁ'", &bad_index), 0x3041);265 try std.testing.expectEqual(try parseCharLiteral("'ぁ'", &bad_index), 0x3041);
266 std.testing.expectEqual(try parseCharLiteral("'\\u{0}'", &bad_index), 0);266 try std.testing.expectEqual(try parseCharLiteral("'\\u{0}'", &bad_index), 0);
267 std.testing.expectEqual(try parseCharLiteral("'\\u{3041}'", &bad_index), 0x3041);267 try std.testing.expectEqual(try parseCharLiteral("'\\u{3041}'", &bad_index), 0x3041);
268 std.testing.expectEqual(try parseCharLiteral("'\\u{7f}'", &bad_index), 0x7f);268 try std.testing.expectEqual(try parseCharLiteral("'\\u{7f}'", &bad_index), 0x7f);
269 std.testing.expectEqual(try parseCharLiteral("'\\u{7FFF}'", &bad_index), 0x7FFF);269 try std.testing.expectEqual(try parseCharLiteral("'\\u{7FFF}'", &bad_index), 0x7FFF);
270270
271 std.testing.expectError(error.InvalidCharacter, parseCharLiteral("'\\x0'", &bad_index));271 try std.testing.expectError(error.InvalidCharacter, parseCharLiteral("'\\x0'", &bad_index));
272 std.testing.expectError(error.InvalidCharacter, parseCharLiteral("'\\x000'", &bad_index));272 try std.testing.expectError(error.InvalidCharacter, parseCharLiteral("'\\x000'", &bad_index));
273 std.testing.expectError(error.InvalidCharacter, parseCharLiteral("'\\y'", &bad_index));273 try std.testing.expectError(error.InvalidCharacter, parseCharLiteral("'\\y'", &bad_index));
274 std.testing.expectError(error.InvalidCharacter, parseCharLiteral("'\\u'", &bad_index));274 try std.testing.expectError(error.InvalidCharacter, parseCharLiteral("'\\u'", &bad_index));
275 std.testing.expectError(error.InvalidCharacter, parseCharLiteral("'\\uFFFF'", &bad_index));275 try std.testing.expectError(error.InvalidCharacter, parseCharLiteral("'\\uFFFF'", &bad_index));
276 std.testing.expectError(error.InvalidCharacter, parseCharLiteral("'\\u{}'", &bad_index));276 try std.testing.expectError(error.InvalidCharacter, parseCharLiteral("'\\u{}'", &bad_index));
277 std.testing.expectError(error.InvalidCharacter, parseCharLiteral("'\\u{FFFFFF}'", &bad_index));277 try std.testing.expectError(error.InvalidCharacter, parseCharLiteral("'\\u{FFFFFF}'", &bad_index));
278 std.testing.expectError(error.InvalidCharacter, parseCharLiteral("'\\u{FFFF'", &bad_index));278 try std.testing.expectError(error.InvalidCharacter, parseCharLiteral("'\\u{FFFF'", &bad_index));
279 std.testing.expectError(error.InvalidCharacter, parseCharLiteral("'\\u{FFFF}x'", &bad_index));279 try std.testing.expectError(error.InvalidCharacter, parseCharLiteral("'\\u{FFFF}x'", &bad_index));
280}280}
281281
282test {282test {
lib/std/zig/cross_target.zig+38-38
...@@ -800,7 +800,7 @@ test "CrossTarget.parse" {...@@ -800,7 +800,7 @@ test "CrossTarget.parse" {
800 .{@tagName(std.Target.current.abi)},800 .{@tagName(std.Target.current.abi)},
801 ) catch unreachable;801 ) catch unreachable;
802802
803 std.testing.expectEqualSlices(u8, triple, text);803 try std.testing.expectEqualSlices(u8, triple, text);
804 }804 }
805 {805 {
806 const cross_target = try CrossTarget.parse(.{806 const cross_target = try CrossTarget.parse(.{
...@@ -808,18 +808,18 @@ test "CrossTarget.parse" {...@@ -808,18 +808,18 @@ test "CrossTarget.parse" {
808 .cpu_features = "native",808 .cpu_features = "native",
809 });809 });
810810
811 std.testing.expect(cross_target.cpu_arch.? == .aarch64);811 try std.testing.expect(cross_target.cpu_arch.? == .aarch64);
812 std.testing.expect(cross_target.cpu_model == .native);812 try std.testing.expect(cross_target.cpu_model == .native);
813 }813 }
814 {814 {
815 const cross_target = try CrossTarget.parse(.{ .arch_os_abi = "native" });815 const cross_target = try CrossTarget.parse(.{ .arch_os_abi = "native" });
816816
817 std.testing.expect(cross_target.cpu_arch == null);817 try std.testing.expect(cross_target.cpu_arch == null);
818 std.testing.expect(cross_target.isNative());818 try std.testing.expect(cross_target.isNative());
819819
820 const text = try cross_target.zigTriple(std.testing.allocator);820 const text = try cross_target.zigTriple(std.testing.allocator);
821 defer std.testing.allocator.free(text);821 defer std.testing.allocator.free(text);
822 std.testing.expectEqualSlices(u8, "native", text);822 try std.testing.expectEqualSlices(u8, "native", text);
823 }823 }
824 {824 {
825 const cross_target = try CrossTarget.parse(.{825 const cross_target = try CrossTarget.parse(.{
...@@ -828,23 +828,23 @@ test "CrossTarget.parse" {...@@ -828,23 +828,23 @@ test "CrossTarget.parse" {
828 });828 });
829 const target = cross_target.toTarget();829 const target = cross_target.toTarget();
830830
831 std.testing.expect(target.os.tag == .linux);831 try std.testing.expect(target.os.tag == .linux);
832 std.testing.expect(target.abi == .gnu);832 try std.testing.expect(target.abi == .gnu);
833 std.testing.expect(target.cpu.arch == .x86_64);833 try std.testing.expect(target.cpu.arch == .x86_64);
834 std.testing.expect(!Target.x86.featureSetHas(target.cpu.features, .sse));834 try std.testing.expect(!Target.x86.featureSetHas(target.cpu.features, .sse));
835 std.testing.expect(!Target.x86.featureSetHas(target.cpu.features, .avx));835 try std.testing.expect(!Target.x86.featureSetHas(target.cpu.features, .avx));
836 std.testing.expect(!Target.x86.featureSetHas(target.cpu.features, .cx8));836 try std.testing.expect(!Target.x86.featureSetHas(target.cpu.features, .cx8));
837 std.testing.expect(Target.x86.featureSetHas(target.cpu.features, .cmov));837 try std.testing.expect(Target.x86.featureSetHas(target.cpu.features, .cmov));
838 std.testing.expect(Target.x86.featureSetHas(target.cpu.features, .fxsr));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 }));840 try std.testing.expect(Target.x86.featureSetHasAny(target.cpu.features, .{ .sse, .avx, .cmov }));
841 std.testing.expect(!Target.x86.featureSetHasAny(target.cpu.features, .{ .sse, .avx }));841 try std.testing.expect(!Target.x86.featureSetHasAny(target.cpu.features, .{ .sse, .avx }));
842 std.testing.expect(Target.x86.featureSetHasAll(target.cpu.features, .{ .mmx, .x87 }));842 try std.testing.expect(Target.x86.featureSetHasAll(target.cpu.features, .{ .mmx, .x87 }));
843 std.testing.expect(!Target.x86.featureSetHasAll(target.cpu.features, .{ .mmx, .x87, .sse }));843 try std.testing.expect(!Target.x86.featureSetHasAll(target.cpu.features, .{ .mmx, .x87, .sse }));
844844
845 const text = try cross_target.zigTriple(std.testing.allocator);845 const text = try cross_target.zigTriple(std.testing.allocator);
846 defer std.testing.allocator.free(text);846 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);
848 }848 }
849 {849 {
850 const cross_target = try CrossTarget.parse(.{850 const cross_target = try CrossTarget.parse(.{
...@@ -853,15 +853,15 @@ test "CrossTarget.parse" {...@@ -853,15 +853,15 @@ test "CrossTarget.parse" {
853 });853 });
854 const target = cross_target.toTarget();854 const target = cross_target.toTarget();
855855
856 std.testing.expect(target.os.tag == .linux);856 try std.testing.expect(target.os.tag == .linux);
857 std.testing.expect(target.abi == .musleabihf);857 try std.testing.expect(target.abi == .musleabihf);
858 std.testing.expect(target.cpu.arch == .arm);858 try std.testing.expect(target.cpu.arch == .arm);
859 std.testing.expect(target.cpu.model == &Target.arm.cpu.generic);859 try std.testing.expect(target.cpu.model == &Target.arm.cpu.generic);
860 std.testing.expect(Target.arm.featureSetHas(target.cpu.features, .v8a));860 try std.testing.expect(Target.arm.featureSetHas(target.cpu.features, .v8a));
861861
862 const text = try cross_target.zigTriple(std.testing.allocator);862 const text = try cross_target.zigTriple(std.testing.allocator);
863 defer std.testing.allocator.free(text);863 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);
865 }865 }
866 {866 {
867 const cross_target = try CrossTarget.parse(.{867 const cross_target = try CrossTarget.parse(.{
...@@ -870,21 +870,21 @@ test "CrossTarget.parse" {...@@ -870,21 +870,21 @@ test "CrossTarget.parse" {
870 });870 });
871 const target = cross_target.toTarget();871 const target = cross_target.toTarget();
872872
873 std.testing.expect(target.cpu.arch == .aarch64);873 try std.testing.expect(target.cpu.arch == .aarch64);
874 std.testing.expect(target.os.tag == .linux);874 try std.testing.expect(target.os.tag == .linux);
875 std.testing.expect(target.os.version_range.linux.range.min.major == 3);875 try 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);876 try 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);877 try 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);878 try 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);879 try 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);880 try std.testing.expect(target.os.version_range.linux.range.max.patch == 1);
881 std.testing.expect(target.os.version_range.linux.glibc.major == 2);881 try std.testing.expect(target.os.version_range.linux.glibc.major == 2);
882 std.testing.expect(target.os.version_range.linux.glibc.minor == 27);882 try std.testing.expect(target.os.version_range.linux.glibc.minor == 27);
883 std.testing.expect(target.os.version_range.linux.glibc.patch == 0);883 try std.testing.expect(target.os.version_range.linux.glibc.patch == 0);
884 std.testing.expect(target.abi == .gnu);884 try std.testing.expect(target.abi == .gnu);
885885
886 const text = try cross_target.zigTriple(std.testing.allocator);886 const text = try cross_target.zigTriple(std.testing.allocator);
887 defer std.testing.allocator.free(text);887 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);
889 }889 }
890}890}
lib/std/zig/parser_test.zig+9-10
...@@ -988,7 +988,7 @@ test "zig fmt: while else err prong with no block" {...@@ -988,7 +988,7 @@ test "zig fmt: while else err prong with no block" {
988 \\ const result = while (returnError()) |value| {988 \\ const result = while (returnError()) |value| {
989 \\ break value;989 \\ break value;
990 \\ } else |err| @as(i32, 2);990 \\ } else |err| @as(i32, 2);
991 \\ expect(result == 2);991 \\ try expect(result == 2);
992 \\}992 \\}
993 \\993 \\
994 );994 );
...@@ -5135,7 +5135,7 @@ test "recovery: missing while rbrace" {...@@ -5135,7 +5135,7 @@ test "recovery: missing while rbrace" {
51355135
5136const std = @import("std");5136const std = @import("std");
5137const mem = std.mem;5137const mem = std.mem;
5138const warn = std.debug.warn;5138const print = std.debug.print;
5139const io = std.io;5139const io = std.io;
5140const maxInt = std.math.maxInt;5140const maxInt = std.math.maxInt;
51415141
...@@ -5177,13 +5177,13 @@ fn testTransform(source: []const u8, expected_source: []const u8) !void {...@@ -5177,13 +5177,13 @@ fn testTransform(source: []const u8, expected_source: []const u8) !void {
5177 var failing_allocator = std.testing.FailingAllocator.init(&fixed_allocator.allocator, maxInt(usize));5177 var failing_allocator = std.testing.FailingAllocator.init(&fixed_allocator.allocator, maxInt(usize));
5178 var anything_changed: bool = undefined;5178 var anything_changed: bool = undefined;
5179 const result_source = try testParse(source, &failing_allocator.allocator, &anything_changed);5179 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);
5181 const changes_expected = source.ptr != expected_source.ptr;5181 const changes_expected = source.ptr != expected_source.ptr;
5182 if (anything_changed != changes_expected) {5182 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 });
5184 return error.TestFailed;5184 return error.TestFailed;
5185 }5185 }
5186 std.testing.expect(anything_changed == changes_expected);5186 try std.testing.expect(anything_changed == changes_expected);
5187 failing_allocator.allocator.free(result_source);5187 failing_allocator.allocator.free(result_source);
5188 break :x failing_allocator.index;5188 break :x failing_allocator.index;
5189 };5189 };
...@@ -5198,7 +5198,7 @@ fn testTransform(source: []const u8, expected_source: []const u8) !void {...@@ -5198,7 +5198,7 @@ fn testTransform(source: []const u8, expected_source: []const u8) !void {
5198 } else |err| switch (err) {5198 } else |err| switch (err) {
5199 error.OutOfMemory => {5199 error.OutOfMemory => {
5200 if (failing_allocator.allocated_bytes != failing_allocator.freed_bytes) {5200 if (failing_allocator.allocated_bytes != failing_allocator.freed_bytes) {
5201 warn(5201 print(
5202 "\nfail_index: {d}/{d}\nallocated bytes: {d}\nfreed bytes: {d}\nallocations: {d}\ndeallocations: {d}\n",5202 "\nfail_index: {d}/{d}\nallocated bytes: {d}\nfreed bytes: {d}\nallocations: {d}\ndeallocations: {d}\n",
5203 .{5203 .{
5204 fail_index,5204 fail_index,
...@@ -5212,8 +5212,7 @@ fn testTransform(source: []const u8, expected_source: []const u8) !void {...@@ -5212,8 +5212,7 @@ fn testTransform(source: []const u8, expected_source: []const u8) !void {
5212 return error.MemoryLeakDetected;5212 return error.MemoryLeakDetected;
5213 }5213 }
5214 },5214 },
5215 error.ParseError => @panic("test failed"),5215 else => return err,
5216 else => @panic("test failed"),
5217 }5216 }
5218 }5217 }
5219}5218}
...@@ -5227,8 +5226,8 @@ fn testError(source: []const u8, expected_errors: []const Error) !void {...@@ -5227,8 +5226,8 @@ fn testError(source: []const u8, expected_errors: []const Error) !void {
5227 var tree = try std.zig.parse(std.testing.allocator, source);5226 var tree = try std.zig.parse(std.testing.allocator, source);
5228 defer tree.deinit(std.testing.allocator);5227 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);
5231 for (expected_errors) |expected, i| {5230 for (expected_errors) |expected, i| {
5232 std.testing.expectEqual(expected, tree.errors[i].tag);5231 try std.testing.expectEqual(expected, tree.errors[i].tag);
5233 }5232 }
5234}5233}
lib/std/zig/string_literal.zig+3-3
...@@ -153,7 +153,7 @@ test "parse" {...@@ -153,7 +153,7 @@ test "parse" {
153 var fixed_buf_alloc = std.heap.FixedBufferAllocator.init(fixed_buf_mem[0..]);153 var fixed_buf_alloc = std.heap.FixedBufferAllocator.init(fixed_buf_mem[0..]);
154 var alloc = &fixed_buf_alloc.allocator;154 var alloc = &fixed_buf_alloc.allocator;
155155
156 expect(eql(u8, "foo", try parseAlloc(alloc, "\"foo\"")));156 try expect(eql(u8, "foo", try parseAlloc(alloc, "\"foo\"")));
157 expect(eql(u8, "foo", try parseAlloc(alloc, "\"f\x6f\x6f\"")));157 try expect(eql(u8, "foo", try parseAlloc(alloc, "\"f\x6f\x6f\"")));
158 expect(eql(u8, "f💯", try parseAlloc(alloc, "\"f\u{1f4af}\"")));158 try expect(eql(u8, "f💯", try parseAlloc(alloc, "\"f\u{1f4af}\"")));
159}159}
lib/std/zig/system/linux.zig+2-2
...@@ -414,8 +414,8 @@ fn testParser(...@@ -414,8 +414,8 @@ fn testParser(
414) !void {414) !void {
415 var fbs = io.fixedBufferStream(input);415 var fbs = io.fixedBufferStream(input);
416 const result = try parser.parse(arch, fbs.reader());416 const result = try parser.parse(arch, fbs.reader());
417 testing.expectEqual(expected_model, result.?.model);417 try testing.expectEqual(expected_model, result.?.model);
418 testing.expect(expected_model.features.eql(result.?.features));418 try testing.expect(expected_model.features.eql(result.?.features));
419}419}
420420
421// The generic implementation of a /proc/cpuinfo parser.421// 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)...@@ -402,7 +402,7 @@ fn testVersionEquality(expected: std.builtin.Version, got: std.builtin.Version)
402 var b_got: [64]u8 = undefined;402 var b_got: [64]u8 = undefined;
403 const s_got: []const u8 = try std.fmt.bufPrint(b_got[0..], "{}", .{got});403 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);
406}406}
407407
408/// Detect SDK path on Darwin.408/// Detect SDK path on Darwin.
lib/std/zig/tokenizer.zig+294-294
...@@ -1503,11 +1503,11 @@ pub const Tokenizer = struct {...@@ -1503,11 +1503,11 @@ pub const Tokenizer = struct {
1503};1503};
15041504
1505test "tokenizer" {1505test "tokenizer" {
1506 testTokenize("test", &.{.keyword_test});1506 try testTokenize("test", &.{.keyword_test});
1507}1507}
15081508
1509test "line comment followed by top-level comptime" {1509test "line comment followed by top-level comptime" {
1510 testTokenize(1510 try testTokenize(
1511 \\// line comment1511 \\// line comment
1512 \\comptime {}1512 \\comptime {}
1513 \\1513 \\
...@@ -1519,7 +1519,7 @@ test "line comment followed by top-level comptime" {...@@ -1519,7 +1519,7 @@ test "line comment followed by top-level comptime" {
1519}1519}
15201520
1521test "tokenizer - unknown length pointer and then c pointer" {1521test "tokenizer - unknown length pointer and then c pointer" {
1522 testTokenize(1522 try testTokenize(
1523 \\[*]u81523 \\[*]u8
1524 \\[*c]u81524 \\[*c]u8
1525 , &.{1525 , &.{
...@@ -1536,72 +1536,72 @@ test "tokenizer - unknown length pointer and then c pointer" {...@@ -1536,72 +1536,72 @@ test "tokenizer - unknown length pointer and then c pointer" {
1536}1536}
15371537
1538test "tokenizer - code point literal with hex escape" {1538test "tokenizer - code point literal with hex escape" {
1539 testTokenize(1539 try testTokenize(
1540 \\'\x1b'1540 \\'\x1b'
1541 , &.{.char_literal});1541 , &.{.char_literal});
1542 testTokenize(1542 try testTokenize(
1543 \\'\x1'1543 \\'\x1'
1544 , &.{ .invalid, .invalid });1544 , &.{ .invalid, .invalid });
1545}1545}
15461546
1547test "tokenizer - code point literal with unicode escapes" {1547test "tokenizer - code point literal with unicode escapes" {
1548 // Valid unicode escapes1548 // Valid unicode escapes
1549 testTokenize(1549 try testTokenize(
1550 \\'\u{3}'1550 \\'\u{3}'
1551 , &.{.char_literal});1551 , &.{.char_literal});
1552 testTokenize(1552 try testTokenize(
1553 \\'\u{01}'1553 \\'\u{01}'
1554 , &.{.char_literal});1554 , &.{.char_literal});
1555 testTokenize(1555 try testTokenize(
1556 \\'\u{2a}'1556 \\'\u{2a}'
1557 , &.{.char_literal});1557 , &.{.char_literal});
1558 testTokenize(1558 try testTokenize(
1559 \\'\u{3f9}'1559 \\'\u{3f9}'
1560 , &.{.char_literal});1560 , &.{.char_literal});
1561 testTokenize(1561 try testTokenize(
1562 \\'\u{6E09aBc1523}'1562 \\'\u{6E09aBc1523}'
1563 , &.{.char_literal});1563 , &.{.char_literal});
1564 testTokenize(1564 try testTokenize(
1565 \\"\u{440}"1565 \\"\u{440}"
1566 , &.{.string_literal});1566 , &.{.string_literal});
15671567
1568 // Invalid unicode escapes1568 // Invalid unicode escapes
1569 testTokenize(1569 try testTokenize(
1570 \\'\u'1570 \\'\u'
1571 , &.{.invalid});1571 , &.{.invalid});
1572 testTokenize(1572 try testTokenize(
1573 \\'\u{{'1573 \\'\u{{'
1574 , &.{ .invalid, .invalid });1574 , &.{ .invalid, .invalid });
1575 testTokenize(1575 try testTokenize(
1576 \\'\u{}'1576 \\'\u{}'
1577 , &.{ .invalid, .invalid });1577 , &.{ .invalid, .invalid });
1578 testTokenize(1578 try testTokenize(
1579 \\'\u{s}'1579 \\'\u{s}'
1580 , &.{ .invalid, .invalid });1580 , &.{ .invalid, .invalid });
1581 testTokenize(1581 try testTokenize(
1582 \\'\u{2z}'1582 \\'\u{2z}'
1583 , &.{ .invalid, .invalid });1583 , &.{ .invalid, .invalid });
1584 testTokenize(1584 try testTokenize(
1585 \\'\u{4a'1585 \\'\u{4a'
1586 , &.{.invalid});1586 , &.{.invalid});
15871587
1588 // Test old-style unicode literals1588 // Test old-style unicode literals
1589 testTokenize(1589 try testTokenize(
1590 \\'\u0333'1590 \\'\u0333'
1591 , &.{ .invalid, .invalid });1591 , &.{ .invalid, .invalid });
1592 testTokenize(1592 try testTokenize(
1593 \\'\U0333'1593 \\'\U0333'
1594 , &.{ .invalid, .integer_literal, .invalid });1594 , &.{ .invalid, .integer_literal, .invalid });
1595}1595}
15961596
1597test "tokenizer - code point literal with unicode code point" {1597test "tokenizer - code point literal with unicode code point" {
1598 testTokenize(1598 try testTokenize(
1599 \\'💩'1599 \\'💩'
1600 , &.{.char_literal});1600 , &.{.char_literal});
1601}1601}
16021602
1603test "tokenizer - float literal e exponent" {1603test "tokenizer - float literal e exponent" {
1604 testTokenize("a = 4.94065645841246544177e-324;\n", &.{1604 try testTokenize("a = 4.94065645841246544177e-324;\n", &.{
1605 .identifier,1605 .identifier,
1606 .equal,1606 .equal,
1607 .float_literal,1607 .float_literal,
...@@ -1610,7 +1610,7 @@ test "tokenizer - float literal e exponent" {...@@ -1610,7 +1610,7 @@ test "tokenizer - float literal e exponent" {
1610}1610}
16111611
1612test "tokenizer - float literal p exponent" {1612test "tokenizer - float literal p exponent" {
1613 testTokenize("a = 0x1.a827999fcef32p+1022;\n", &.{1613 try testTokenize("a = 0x1.a827999fcef32p+1022;\n", &.{
1614 .identifier,1614 .identifier,
1615 .equal,1615 .equal,
1616 .float_literal,1616 .float_literal,
...@@ -1619,84 +1619,84 @@ test "tokenizer - float literal p exponent" {...@@ -1619,84 +1619,84 @@ test "tokenizer - float literal p exponent" {
1619}1619}
16201620
1621test "tokenizer - chars" {1621test "tokenizer - chars" {
1622 testTokenize("'c'", &.{.char_literal});1622 try testTokenize("'c'", &.{.char_literal});
1623}1623}
16241624
1625test "tokenizer - invalid token characters" {1625test "tokenizer - invalid token characters" {
1626 testTokenize("#", &.{.invalid});1626 try testTokenize("#", &.{.invalid});
1627 testTokenize("`", &.{.invalid});1627 try testTokenize("`", &.{.invalid});
1628 testTokenize("'c", &.{.invalid});1628 try testTokenize("'c", &.{.invalid});
1629 testTokenize("'", &.{.invalid});1629 try testTokenize("'", &.{.invalid});
1630 testTokenize("''", &.{ .invalid, .invalid });1630 try testTokenize("''", &.{ .invalid, .invalid });
1631}1631}
16321632
1633test "tokenizer - invalid literal/comment characters" {1633test "tokenizer - invalid literal/comment characters" {
1634 testTokenize("\"\x00\"", &.{1634 try testTokenize("\"\x00\"", &.{
1635 .string_literal,1635 .string_literal,
1636 .invalid,1636 .invalid,
1637 });1637 });
1638 testTokenize("//\x00", &.{1638 try testTokenize("//\x00", &.{
1639 .invalid,1639 .invalid,
1640 });1640 });
1641 testTokenize("//\x1f", &.{1641 try testTokenize("//\x1f", &.{
1642 .invalid,1642 .invalid,
1643 });1643 });
1644 testTokenize("//\x7f", &.{1644 try testTokenize("//\x7f", &.{
1645 .invalid,1645 .invalid,
1646 });1646 });
1647}1647}
16481648
1649test "tokenizer - utf8" {1649test "tokenizer - utf8" {
1650 testTokenize("//\xc2\x80", &.{});1650 try testTokenize("//\xc2\x80", &.{});
1651 testTokenize("//\xf4\x8f\xbf\xbf", &.{});1651 try testTokenize("//\xf4\x8f\xbf\xbf", &.{});
1652}1652}
16531653
1654test "tokenizer - invalid utf8" {1654test "tokenizer - invalid utf8" {
1655 testTokenize("//\x80", &.{1655 try testTokenize("//\x80", &.{
1656 .invalid,1656 .invalid,
1657 });1657 });
1658 testTokenize("//\xbf", &.{1658 try testTokenize("//\xbf", &.{
1659 .invalid,1659 .invalid,
1660 });1660 });
1661 testTokenize("//\xf8", &.{1661 try testTokenize("//\xf8", &.{
1662 .invalid,1662 .invalid,
1663 });1663 });
1664 testTokenize("//\xff", &.{1664 try testTokenize("//\xff", &.{
1665 .invalid,1665 .invalid,
1666 });1666 });
1667 testTokenize("//\xc2\xc0", &.{1667 try testTokenize("//\xc2\xc0", &.{
1668 .invalid,1668 .invalid,
1669 });1669 });
1670 testTokenize("//\xe0", &.{1670 try testTokenize("//\xe0", &.{
1671 .invalid,1671 .invalid,
1672 });1672 });
1673 testTokenize("//\xf0", &.{1673 try testTokenize("//\xf0", &.{
1674 .invalid,1674 .invalid,
1675 });1675 });
1676 testTokenize("//\xf0\x90\x80\xc0", &.{1676 try testTokenize("//\xf0\x90\x80\xc0", &.{
1677 .invalid,1677 .invalid,
1678 });1678 });
1679}1679}
16801680
1681test "tokenizer - illegal unicode codepoints" {1681test "tokenizer - illegal unicode codepoints" {
1682 // unicode newline characters.U+0085, U+2028, U+20291682 // unicode newline characters.U+0085, U+2028, U+2029
1683 testTokenize("//\xc2\x84", &.{});1683 try testTokenize("//\xc2\x84", &.{});
1684 testTokenize("//\xc2\x85", &.{1684 try testTokenize("//\xc2\x85", &.{
1685 .invalid,1685 .invalid,
1686 });1686 });
1687 testTokenize("//\xc2\x86", &.{});1687 try testTokenize("//\xc2\x86", &.{});
1688 testTokenize("//\xe2\x80\xa7", &.{});1688 try testTokenize("//\xe2\x80\xa7", &.{});
1689 testTokenize("//\xe2\x80\xa8", &.{1689 try testTokenize("//\xe2\x80\xa8", &.{
1690 .invalid,1690 .invalid,
1691 });1691 });
1692 testTokenize("//\xe2\x80\xa9", &.{1692 try testTokenize("//\xe2\x80\xa9", &.{
1693 .invalid,1693 .invalid,
1694 });1694 });
1695 testTokenize("//\xe2\x80\xaa", &.{});1695 try testTokenize("//\xe2\x80\xaa", &.{});
1696}1696}
16971697
1698test "tokenizer - string identifier and builtin fns" {1698test "tokenizer - string identifier and builtin fns" {
1699 testTokenize(1699 try testTokenize(
1700 \\const @"if" = @import("std");1700 \\const @"if" = @import("std");
1701 , &.{1701 , &.{
1702 .keyword_const,1702 .keyword_const,
...@@ -1711,7 +1711,7 @@ test "tokenizer - string identifier and builtin fns" {...@@ -1711,7 +1711,7 @@ test "tokenizer - string identifier and builtin fns" {
1711}1711}
17121712
1713test "tokenizer - multiline string literal with literal tab" {1713test "tokenizer - multiline string literal with literal tab" {
1714 testTokenize(1714 try testTokenize(
1715 \\\\foo bar1715 \\\\foo bar
1716 , &.{1716 , &.{
1717 .multiline_string_literal_line,1717 .multiline_string_literal_line,
...@@ -1719,7 +1719,7 @@ test "tokenizer - multiline string literal with literal tab" {...@@ -1719,7 +1719,7 @@ test "tokenizer - multiline string literal with literal tab" {
1719}1719}
17201720
1721test "tokenizer - comments with literal tab" {1721test "tokenizer - comments with literal tab" {
1722 testTokenize(1722 try testTokenize(
1723 \\//foo bar1723 \\//foo bar
1724 \\//!foo bar1724 \\//!foo bar
1725 \\///foo bar1725 \\///foo bar
...@@ -1735,25 +1735,25 @@ test "tokenizer - comments with literal tab" {...@@ -1735,25 +1735,25 @@ test "tokenizer - comments with literal tab" {
1735}1735}
17361736
1737test "tokenizer - pipe and then invalid" {1737test "tokenizer - pipe and then invalid" {
1738 testTokenize("||=", &.{1738 try testTokenize("||=", &.{
1739 .pipe_pipe,1739 .pipe_pipe,
1740 .equal,1740 .equal,
1741 });1741 });
1742}1742}
17431743
1744test "tokenizer - line comment and doc comment" {1744test "tokenizer - line comment and doc comment" {
1745 testTokenize("//", &.{});1745 try testTokenize("//", &.{});
1746 testTokenize("// a / b", &.{});1746 try testTokenize("// a / b", &.{});
1747 testTokenize("// /", &.{});1747 try testTokenize("// /", &.{});
1748 testTokenize("/// a", &.{.doc_comment});1748 try testTokenize("/// a", &.{.doc_comment});
1749 testTokenize("///", &.{.doc_comment});1749 try testTokenize("///", &.{.doc_comment});
1750 testTokenize("////", &.{});1750 try testTokenize("////", &.{});
1751 testTokenize("//!", &.{.container_doc_comment});1751 try testTokenize("//!", &.{.container_doc_comment});
1752 testTokenize("//!!", &.{.container_doc_comment});1752 try testTokenize("//!!", &.{.container_doc_comment});
1753}1753}
17541754
1755test "tokenizer - line comment followed by identifier" {1755test "tokenizer - line comment followed by identifier" {
1756 testTokenize(1756 try testTokenize(
1757 \\ Unexpected,1757 \\ Unexpected,
1758 \\ // another1758 \\ // another
1759 \\ Another,1759 \\ Another,
...@@ -1766,14 +1766,14 @@ test "tokenizer - line comment followed by identifier" {...@@ -1766,14 +1766,14 @@ test "tokenizer - line comment followed by identifier" {
1766}1766}
17671767
1768test "tokenizer - UTF-8 BOM is recognized and skipped" {1768test "tokenizer - UTF-8 BOM is recognized and skipped" {
1769 testTokenize("\xEF\xBB\xBFa;\n", &.{1769 try testTokenize("\xEF\xBB\xBFa;\n", &.{
1770 .identifier,1770 .identifier,
1771 .semicolon,1771 .semicolon,
1772 });1772 });
1773}1773}
17741774
1775test "correctly parse pointer assignment" {1775test "correctly parse pointer assignment" {
1776 testTokenize("b.*=3;\n", &.{1776 try testTokenize("b.*=3;\n", &.{
1777 .identifier,1777 .identifier,
1778 .period_asterisk,1778 .period_asterisk,
1779 .equal,1779 .equal,
...@@ -1783,14 +1783,14 @@ test "correctly parse pointer assignment" {...@@ -1783,14 +1783,14 @@ test "correctly parse pointer assignment" {
1783}1783}
17841784
1785test "correctly parse pointer dereference followed by asterisk" {1785test "correctly parse pointer dereference followed by asterisk" {
1786 testTokenize("\"b\".* ** 10", &.{1786 try testTokenize("\"b\".* ** 10", &.{
1787 .string_literal,1787 .string_literal,
1788 .period_asterisk,1788 .period_asterisk,
1789 .asterisk_asterisk,1789 .asterisk_asterisk,
1790 .integer_literal,1790 .integer_literal,
1791 });1791 });
17921792
1793 testTokenize("(\"b\".*)** 10", &.{1793 try testTokenize("(\"b\".*)** 10", &.{
1794 .l_paren,1794 .l_paren,
1795 .string_literal,1795 .string_literal,
1796 .period_asterisk,1796 .period_asterisk,
...@@ -1799,7 +1799,7 @@ test "correctly parse pointer dereference followed by asterisk" {...@@ -1799,7 +1799,7 @@ test "correctly parse pointer dereference followed by asterisk" {
1799 .integer_literal,1799 .integer_literal,
1800 });1800 });
18011801
1802 testTokenize("\"b\".*** 10", &.{1802 try testTokenize("\"b\".*** 10", &.{
1803 .string_literal,1803 .string_literal,
1804 .invalid_periodasterisks,1804 .invalid_periodasterisks,
1805 .asterisk_asterisk,1805 .asterisk_asterisk,
...@@ -1808,245 +1808,245 @@ test "correctly parse pointer dereference followed by asterisk" {...@@ -1808,245 +1808,245 @@ test "correctly parse pointer dereference followed by asterisk" {
1808}1808}
18091809
1810test "tokenizer - range literals" {1810test "tokenizer - range literals" {
1811 testTokenize("0...9", &.{ .integer_literal, .ellipsis3, .integer_literal });1811 try testTokenize("0...9", &.{ .integer_literal, .ellipsis3, .integer_literal });
1812 testTokenize("'0'...'9'", &.{ .char_literal, .ellipsis3, .char_literal });1812 try testTokenize("'0'...'9'", &.{ .char_literal, .ellipsis3, .char_literal });
1813 testTokenize("0x00...0x09", &.{ .integer_literal, .ellipsis3, .integer_literal });1813 try testTokenize("0x00...0x09", &.{ .integer_literal, .ellipsis3, .integer_literal });
1814 testTokenize("0b00...0b11", &.{ .integer_literal, .ellipsis3, .integer_literal });1814 try testTokenize("0b00...0b11", &.{ .integer_literal, .ellipsis3, .integer_literal });
1815 testTokenize("0o00...0o11", &.{ .integer_literal, .ellipsis3, .integer_literal });1815 try testTokenize("0o00...0o11", &.{ .integer_literal, .ellipsis3, .integer_literal });
1816}1816}
18171817
1818test "tokenizer - number literals decimal" {1818test "tokenizer - number literals decimal" {
1819 testTokenize("0", &.{.integer_literal});1819 try testTokenize("0", &.{.integer_literal});
1820 testTokenize("1", &.{.integer_literal});1820 try testTokenize("1", &.{.integer_literal});
1821 testTokenize("2", &.{.integer_literal});1821 try testTokenize("2", &.{.integer_literal});
1822 testTokenize("3", &.{.integer_literal});1822 try testTokenize("3", &.{.integer_literal});
1823 testTokenize("4", &.{.integer_literal});1823 try testTokenize("4", &.{.integer_literal});
1824 testTokenize("5", &.{.integer_literal});1824 try testTokenize("5", &.{.integer_literal});
1825 testTokenize("6", &.{.integer_literal});1825 try testTokenize("6", &.{.integer_literal});
1826 testTokenize("7", &.{.integer_literal});1826 try testTokenize("7", &.{.integer_literal});
1827 testTokenize("8", &.{.integer_literal});1827 try testTokenize("8", &.{.integer_literal});
1828 testTokenize("9", &.{.integer_literal});1828 try testTokenize("9", &.{.integer_literal});
1829 testTokenize("1..", &.{ .integer_literal, .ellipsis2 });1829 try testTokenize("1..", &.{ .integer_literal, .ellipsis2 });
1830 testTokenize("0a", &.{ .invalid, .identifier });1830 try testTokenize("0a", &.{ .invalid, .identifier });
1831 testTokenize("9b", &.{ .invalid, .identifier });1831 try testTokenize("9b", &.{ .invalid, .identifier });
1832 testTokenize("1z", &.{ .invalid, .identifier });1832 try testTokenize("1z", &.{ .invalid, .identifier });
1833 testTokenize("1z_1", &.{ .invalid, .identifier });1833 try testTokenize("1z_1", &.{ .invalid, .identifier });
1834 testTokenize("9z3", &.{ .invalid, .identifier });1834 try testTokenize("9z3", &.{ .invalid, .identifier });
18351835
1836 testTokenize("0_0", &.{.integer_literal});1836 try testTokenize("0_0", &.{.integer_literal});
1837 testTokenize("0001", &.{.integer_literal});1837 try testTokenize("0001", &.{.integer_literal});
1838 testTokenize("01234567890", &.{.integer_literal});1838 try testTokenize("01234567890", &.{.integer_literal});
1839 testTokenize("012_345_6789_0", &.{.integer_literal});1839 try testTokenize("012_345_6789_0", &.{.integer_literal});
1840 testTokenize("0_1_2_3_4_5_6_7_8_9_0", &.{.integer_literal});1840 try testTokenize("0_1_2_3_4_5_6_7_8_9_0", &.{.integer_literal});
18411841
1842 testTokenize("00_", &.{.invalid});1842 try testTokenize("00_", &.{.invalid});
1843 testTokenize("0_0_", &.{.invalid});1843 try testTokenize("0_0_", &.{.invalid});
1844 testTokenize("0__0", &.{ .invalid, .identifier });1844 try testTokenize("0__0", &.{ .invalid, .identifier });
1845 testTokenize("0_0f", &.{ .invalid, .identifier });1845 try testTokenize("0_0f", &.{ .invalid, .identifier });
1846 testTokenize("0_0_f", &.{ .invalid, .identifier });1846 try testTokenize("0_0_f", &.{ .invalid, .identifier });
1847 testTokenize("0_0_f_00", &.{ .invalid, .identifier });1847 try testTokenize("0_0_f_00", &.{ .invalid, .identifier });
1848 testTokenize("1_,", &.{ .invalid, .comma });1848 try testTokenize("1_,", &.{ .invalid, .comma });
18491849
1850 testTokenize("1.", &.{.float_literal});1850 try testTokenize("1.", &.{.float_literal});
1851 testTokenize("0.0", &.{.float_literal});1851 try testTokenize("0.0", &.{.float_literal});
1852 testTokenize("1.0", &.{.float_literal});1852 try testTokenize("1.0", &.{.float_literal});
1853 testTokenize("10.0", &.{.float_literal});1853 try testTokenize("10.0", &.{.float_literal});
1854 testTokenize("0e0", &.{.float_literal});1854 try testTokenize("0e0", &.{.float_literal});
1855 testTokenize("1e0", &.{.float_literal});1855 try testTokenize("1e0", &.{.float_literal});
1856 testTokenize("1e100", &.{.float_literal});1856 try testTokenize("1e100", &.{.float_literal});
1857 testTokenize("1.e100", &.{.float_literal});1857 try testTokenize("1.e100", &.{.float_literal});
1858 testTokenize("1.0e100", &.{.float_literal});1858 try testTokenize("1.0e100", &.{.float_literal});
1859 testTokenize("1.0e+100", &.{.float_literal});1859 try testTokenize("1.0e+100", &.{.float_literal});
1860 testTokenize("1.0e-100", &.{.float_literal});1860 try testTokenize("1.0e-100", &.{.float_literal});
1861 testTokenize("1_0_0_0.0_0_0_0_0_1e1_0_0_0", &.{.float_literal});1861 try testTokenize("1_0_0_0.0_0_0_0_0_1e1_0_0_0", &.{.float_literal});
1862 testTokenize("1.+", &.{ .float_literal, .plus });1862 try testTokenize("1.+", &.{ .float_literal, .plus });
18631863
1864 testTokenize("1e", &.{.invalid});1864 try testTokenize("1e", &.{.invalid});
1865 testTokenize("1.0e1f0", &.{ .invalid, .identifier });1865 try testTokenize("1.0e1f0", &.{ .invalid, .identifier });
1866 testTokenize("1.0p100", &.{ .invalid, .identifier });1866 try testTokenize("1.0p100", &.{ .invalid, .identifier });
1867 testTokenize("1.0p-100", &.{ .invalid, .identifier, .minus, .integer_literal });1867 try testTokenize("1.0p-100", &.{ .invalid, .identifier, .minus, .integer_literal });
1868 testTokenize("1.0p1f0", &.{ .invalid, .identifier });1868 try testTokenize("1.0p1f0", &.{ .invalid, .identifier });
1869 testTokenize("1.0_,", &.{ .invalid, .comma });1869 try testTokenize("1.0_,", &.{ .invalid, .comma });
1870 testTokenize("1_.0", &.{ .invalid, .period, .integer_literal });1870 try testTokenize("1_.0", &.{ .invalid, .period, .integer_literal });
1871 testTokenize("1._", &.{ .invalid, .identifier });1871 try testTokenize("1._", &.{ .invalid, .identifier });
1872 testTokenize("1.a", &.{ .invalid, .identifier });1872 try testTokenize("1.a", &.{ .invalid, .identifier });
1873 testTokenize("1.z", &.{ .invalid, .identifier });1873 try testTokenize("1.z", &.{ .invalid, .identifier });
1874 testTokenize("1._0", &.{ .invalid, .identifier });1874 try testTokenize("1._0", &.{ .invalid, .identifier });
1875 testTokenize("1._+", &.{ .invalid, .identifier, .plus });1875 try testTokenize("1._+", &.{ .invalid, .identifier, .plus });
1876 testTokenize("1._e", &.{ .invalid, .identifier });1876 try testTokenize("1._e", &.{ .invalid, .identifier });
1877 testTokenize("1.0e", &.{.invalid});1877 try testTokenize("1.0e", &.{.invalid});
1878 testTokenize("1.0e,", &.{ .invalid, .comma });1878 try testTokenize("1.0e,", &.{ .invalid, .comma });
1879 testTokenize("1.0e_", &.{ .invalid, .identifier });1879 try testTokenize("1.0e_", &.{ .invalid, .identifier });
1880 testTokenize("1.0e+_", &.{ .invalid, .identifier });1880 try testTokenize("1.0e+_", &.{ .invalid, .identifier });
1881 testTokenize("1.0e-_", &.{ .invalid, .identifier });1881 try testTokenize("1.0e-_", &.{ .invalid, .identifier });
1882 testTokenize("1.0e0_+", &.{ .invalid, .plus });1882 try testTokenize("1.0e0_+", &.{ .invalid, .plus });
1883}1883}
18841884
1885test "tokenizer - number literals binary" {1885test "tokenizer - number literals binary" {
1886 testTokenize("0b0", &.{.integer_literal});1886 try testTokenize("0b0", &.{.integer_literal});
1887 testTokenize("0b1", &.{.integer_literal});1887 try testTokenize("0b1", &.{.integer_literal});
1888 testTokenize("0b2", &.{ .invalid, .integer_literal });1888 try testTokenize("0b2", &.{ .invalid, .integer_literal });
1889 testTokenize("0b3", &.{ .invalid, .integer_literal });1889 try testTokenize("0b3", &.{ .invalid, .integer_literal });
1890 testTokenize("0b4", &.{ .invalid, .integer_literal });1890 try testTokenize("0b4", &.{ .invalid, .integer_literal });
1891 testTokenize("0b5", &.{ .invalid, .integer_literal });1891 try testTokenize("0b5", &.{ .invalid, .integer_literal });
1892 testTokenize("0b6", &.{ .invalid, .integer_literal });1892 try testTokenize("0b6", &.{ .invalid, .integer_literal });
1893 testTokenize("0b7", &.{ .invalid, .integer_literal });1893 try testTokenize("0b7", &.{ .invalid, .integer_literal });
1894 testTokenize("0b8", &.{ .invalid, .integer_literal });1894 try testTokenize("0b8", &.{ .invalid, .integer_literal });
1895 testTokenize("0b9", &.{ .invalid, .integer_literal });1895 try testTokenize("0b9", &.{ .invalid, .integer_literal });
1896 testTokenize("0ba", &.{ .invalid, .identifier });1896 try testTokenize("0ba", &.{ .invalid, .identifier });
1897 testTokenize("0bb", &.{ .invalid, .identifier });1897 try testTokenize("0bb", &.{ .invalid, .identifier });
1898 testTokenize("0bc", &.{ .invalid, .identifier });1898 try testTokenize("0bc", &.{ .invalid, .identifier });
1899 testTokenize("0bd", &.{ .invalid, .identifier });1899 try testTokenize("0bd", &.{ .invalid, .identifier });
1900 testTokenize("0be", &.{ .invalid, .identifier });1900 try testTokenize("0be", &.{ .invalid, .identifier });
1901 testTokenize("0bf", &.{ .invalid, .identifier });1901 try testTokenize("0bf", &.{ .invalid, .identifier });
1902 testTokenize("0bz", &.{ .invalid, .identifier });1902 try testTokenize("0bz", &.{ .invalid, .identifier });
19031903
1904 testTokenize("0b0000_0000", &.{.integer_literal});1904 try testTokenize("0b0000_0000", &.{.integer_literal});
1905 testTokenize("0b1111_1111", &.{.integer_literal});1905 try testTokenize("0b1111_1111", &.{.integer_literal});
1906 testTokenize("0b10_10_10_10", &.{.integer_literal});1906 try testTokenize("0b10_10_10_10", &.{.integer_literal});
1907 testTokenize("0b0_1_0_1_0_1_0_1", &.{.integer_literal});1907 try testTokenize("0b0_1_0_1_0_1_0_1", &.{.integer_literal});
1908 testTokenize("0b1.", &.{ .integer_literal, .period });1908 try testTokenize("0b1.", &.{ .integer_literal, .period });
1909 testTokenize("0b1.0", &.{ .integer_literal, .period, .integer_literal });1909 try testTokenize("0b1.0", &.{ .integer_literal, .period, .integer_literal });
19101910
1911 testTokenize("0B0", &.{ .invalid, .identifier });1911 try testTokenize("0B0", &.{ .invalid, .identifier });
1912 testTokenize("0b_", &.{ .invalid, .identifier });1912 try testTokenize("0b_", &.{ .invalid, .identifier });
1913 testTokenize("0b_0", &.{ .invalid, .identifier });1913 try testTokenize("0b_0", &.{ .invalid, .identifier });
1914 testTokenize("0b1_", &.{.invalid});1914 try testTokenize("0b1_", &.{.invalid});
1915 testTokenize("0b0__1", &.{ .invalid, .identifier });1915 try testTokenize("0b0__1", &.{ .invalid, .identifier });
1916 testTokenize("0b0_1_", &.{.invalid});1916 try testTokenize("0b0_1_", &.{.invalid});
1917 testTokenize("0b1e", &.{ .invalid, .identifier });1917 try testTokenize("0b1e", &.{ .invalid, .identifier });
1918 testTokenize("0b1p", &.{ .invalid, .identifier });1918 try testTokenize("0b1p", &.{ .invalid, .identifier });
1919 testTokenize("0b1e0", &.{ .invalid, .identifier });1919 try testTokenize("0b1e0", &.{ .invalid, .identifier });
1920 testTokenize("0b1p0", &.{ .invalid, .identifier });1920 try testTokenize("0b1p0", &.{ .invalid, .identifier });
1921 testTokenize("0b1_,", &.{ .invalid, .comma });1921 try testTokenize("0b1_,", &.{ .invalid, .comma });
1922}1922}
19231923
1924test "tokenizer - number literals octal" {1924test "tokenizer - number literals octal" {
1925 testTokenize("0o0", &.{.integer_literal});1925 try testTokenize("0o0", &.{.integer_literal});
1926 testTokenize("0o1", &.{.integer_literal});1926 try testTokenize("0o1", &.{.integer_literal});
1927 testTokenize("0o2", &.{.integer_literal});1927 try testTokenize("0o2", &.{.integer_literal});
1928 testTokenize("0o3", &.{.integer_literal});1928 try testTokenize("0o3", &.{.integer_literal});
1929 testTokenize("0o4", &.{.integer_literal});1929 try testTokenize("0o4", &.{.integer_literal});
1930 testTokenize("0o5", &.{.integer_literal});1930 try testTokenize("0o5", &.{.integer_literal});
1931 testTokenize("0o6", &.{.integer_literal});1931 try testTokenize("0o6", &.{.integer_literal});
1932 testTokenize("0o7", &.{.integer_literal});1932 try testTokenize("0o7", &.{.integer_literal});
1933 testTokenize("0o8", &.{ .invalid, .integer_literal });1933 try testTokenize("0o8", &.{ .invalid, .integer_literal });
1934 testTokenize("0o9", &.{ .invalid, .integer_literal });1934 try testTokenize("0o9", &.{ .invalid, .integer_literal });
1935 testTokenize("0oa", &.{ .invalid, .identifier });1935 try testTokenize("0oa", &.{ .invalid, .identifier });
1936 testTokenize("0ob", &.{ .invalid, .identifier });1936 try testTokenize("0ob", &.{ .invalid, .identifier });
1937 testTokenize("0oc", &.{ .invalid, .identifier });1937 try testTokenize("0oc", &.{ .invalid, .identifier });
1938 testTokenize("0od", &.{ .invalid, .identifier });1938 try testTokenize("0od", &.{ .invalid, .identifier });
1939 testTokenize("0oe", &.{ .invalid, .identifier });1939 try testTokenize("0oe", &.{ .invalid, .identifier });
1940 testTokenize("0of", &.{ .invalid, .identifier });1940 try testTokenize("0of", &.{ .invalid, .identifier });
1941 testTokenize("0oz", &.{ .invalid, .identifier });1941 try testTokenize("0oz", &.{ .invalid, .identifier });
19421942
1943 testTokenize("0o01234567", &.{.integer_literal});1943 try testTokenize("0o01234567", &.{.integer_literal});
1944 testTokenize("0o0123_4567", &.{.integer_literal});1944 try testTokenize("0o0123_4567", &.{.integer_literal});
1945 testTokenize("0o01_23_45_67", &.{.integer_literal});1945 try testTokenize("0o01_23_45_67", &.{.integer_literal});
1946 testTokenize("0o0_1_2_3_4_5_6_7", &.{.integer_literal});1946 try testTokenize("0o0_1_2_3_4_5_6_7", &.{.integer_literal});
1947 testTokenize("0o7.", &.{ .integer_literal, .period });1947 try testTokenize("0o7.", &.{ .integer_literal, .period });
1948 testTokenize("0o7.0", &.{ .integer_literal, .period, .integer_literal });1948 try testTokenize("0o7.0", &.{ .integer_literal, .period, .integer_literal });
19491949
1950 testTokenize("0O0", &.{ .invalid, .identifier });1950 try testTokenize("0O0", &.{ .invalid, .identifier });
1951 testTokenize("0o_", &.{ .invalid, .identifier });1951 try testTokenize("0o_", &.{ .invalid, .identifier });
1952 testTokenize("0o_0", &.{ .invalid, .identifier });1952 try testTokenize("0o_0", &.{ .invalid, .identifier });
1953 testTokenize("0o1_", &.{.invalid});1953 try testTokenize("0o1_", &.{.invalid});
1954 testTokenize("0o0__1", &.{ .invalid, .identifier });1954 try testTokenize("0o0__1", &.{ .invalid, .identifier });
1955 testTokenize("0o0_1_", &.{.invalid});1955 try testTokenize("0o0_1_", &.{.invalid});
1956 testTokenize("0o1e", &.{ .invalid, .identifier });1956 try testTokenize("0o1e", &.{ .invalid, .identifier });
1957 testTokenize("0o1p", &.{ .invalid, .identifier });1957 try testTokenize("0o1p", &.{ .invalid, .identifier });
1958 testTokenize("0o1e0", &.{ .invalid, .identifier });1958 try testTokenize("0o1e0", &.{ .invalid, .identifier });
1959 testTokenize("0o1p0", &.{ .invalid, .identifier });1959 try testTokenize("0o1p0", &.{ .invalid, .identifier });
1960 testTokenize("0o_,", &.{ .invalid, .identifier, .comma });1960 try testTokenize("0o_,", &.{ .invalid, .identifier, .comma });
1961}1961}
19621962
1963test "tokenizer - number literals hexadeciaml" {1963test "tokenizer - number literals hexadeciaml" {
1964 testTokenize("0x0", &.{.integer_literal});1964 try testTokenize("0x0", &.{.integer_literal});
1965 testTokenize("0x1", &.{.integer_literal});1965 try testTokenize("0x1", &.{.integer_literal});
1966 testTokenize("0x2", &.{.integer_literal});1966 try testTokenize("0x2", &.{.integer_literal});
1967 testTokenize("0x3", &.{.integer_literal});1967 try testTokenize("0x3", &.{.integer_literal});
1968 testTokenize("0x4", &.{.integer_literal});1968 try testTokenize("0x4", &.{.integer_literal});
1969 testTokenize("0x5", &.{.integer_literal});1969 try testTokenize("0x5", &.{.integer_literal});
1970 testTokenize("0x6", &.{.integer_literal});1970 try testTokenize("0x6", &.{.integer_literal});
1971 testTokenize("0x7", &.{.integer_literal});1971 try testTokenize("0x7", &.{.integer_literal});
1972 testTokenize("0x8", &.{.integer_literal});1972 try testTokenize("0x8", &.{.integer_literal});
1973 testTokenize("0x9", &.{.integer_literal});1973 try testTokenize("0x9", &.{.integer_literal});
1974 testTokenize("0xa", &.{.integer_literal});1974 try testTokenize("0xa", &.{.integer_literal});
1975 testTokenize("0xb", &.{.integer_literal});1975 try testTokenize("0xb", &.{.integer_literal});
1976 testTokenize("0xc", &.{.integer_literal});1976 try testTokenize("0xc", &.{.integer_literal});
1977 testTokenize("0xd", &.{.integer_literal});1977 try testTokenize("0xd", &.{.integer_literal});
1978 testTokenize("0xe", &.{.integer_literal});1978 try testTokenize("0xe", &.{.integer_literal});
1979 testTokenize("0xf", &.{.integer_literal});1979 try testTokenize("0xf", &.{.integer_literal});
1980 testTokenize("0xA", &.{.integer_literal});1980 try testTokenize("0xA", &.{.integer_literal});
1981 testTokenize("0xB", &.{.integer_literal});1981 try testTokenize("0xB", &.{.integer_literal});
1982 testTokenize("0xC", &.{.integer_literal});1982 try testTokenize("0xC", &.{.integer_literal});
1983 testTokenize("0xD", &.{.integer_literal});1983 try testTokenize("0xD", &.{.integer_literal});
1984 testTokenize("0xE", &.{.integer_literal});1984 try testTokenize("0xE", &.{.integer_literal});
1985 testTokenize("0xF", &.{.integer_literal});1985 try testTokenize("0xF", &.{.integer_literal});
1986 testTokenize("0x0z", &.{ .invalid, .identifier });1986 try testTokenize("0x0z", &.{ .invalid, .identifier });
1987 testTokenize("0xz", &.{ .invalid, .identifier });1987 try testTokenize("0xz", &.{ .invalid, .identifier });
19881988
1989 testTokenize("0x0123456789ABCDEF", &.{.integer_literal});1989 try testTokenize("0x0123456789ABCDEF", &.{.integer_literal});
1990 testTokenize("0x0123_4567_89AB_CDEF", &.{.integer_literal});1990 try testTokenize("0x0123_4567_89AB_CDEF", &.{.integer_literal});
1991 testTokenize("0x01_23_45_67_89AB_CDE_F", &.{.integer_literal});1991 try 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});1992 try testTokenize("0x0_1_2_3_4_5_6_7_8_9_A_B_C_D_E_F", &.{.integer_literal});
19931993
1994 testTokenize("0X0", &.{ .invalid, .identifier });1994 try testTokenize("0X0", &.{ .invalid, .identifier });
1995 testTokenize("0x_", &.{ .invalid, .identifier });1995 try testTokenize("0x_", &.{ .invalid, .identifier });
1996 testTokenize("0x_1", &.{ .invalid, .identifier });1996 try testTokenize("0x_1", &.{ .invalid, .identifier });
1997 testTokenize("0x1_", &.{.invalid});1997 try testTokenize("0x1_", &.{.invalid});
1998 testTokenize("0x0__1", &.{ .invalid, .identifier });1998 try testTokenize("0x0__1", &.{ .invalid, .identifier });
1999 testTokenize("0x0_1_", &.{.invalid});1999 try testTokenize("0x0_1_", &.{.invalid});
2000 testTokenize("0x_,", &.{ .invalid, .identifier, .comma });2000 try testTokenize("0x_,", &.{ .invalid, .identifier, .comma });
20012001
2002 testTokenize("0x1.", &.{.float_literal});2002 try testTokenize("0x1.", &.{.float_literal});
2003 testTokenize("0x1.0", &.{.float_literal});2003 try testTokenize("0x1.0", &.{.float_literal});
2004 testTokenize("0xF.", &.{.float_literal});2004 try testTokenize("0xF.", &.{.float_literal});
2005 testTokenize("0xF.0", &.{.float_literal});2005 try testTokenize("0xF.0", &.{.float_literal});
2006 testTokenize("0xF.F", &.{.float_literal});2006 try testTokenize("0xF.F", &.{.float_literal});
2007 testTokenize("0xF.Fp0", &.{.float_literal});2007 try testTokenize("0xF.Fp0", &.{.float_literal});
2008 testTokenize("0xF.FP0", &.{.float_literal});2008 try testTokenize("0xF.FP0", &.{.float_literal});
2009 testTokenize("0x1p0", &.{.float_literal});2009 try testTokenize("0x1p0", &.{.float_literal});
2010 testTokenize("0xfp0", &.{.float_literal});2010 try testTokenize("0xfp0", &.{.float_literal});
2011 testTokenize("0x1.+0xF.", &.{ .float_literal, .plus, .float_literal });2011 try testTokenize("0x1.+0xF.", &.{ .float_literal, .plus, .float_literal });
20122012
2013 testTokenize("0x0123456.789ABCDEF", &.{.float_literal});2013 try testTokenize("0x0123456.789ABCDEF", &.{.float_literal});
2014 testTokenize("0x0_123_456.789_ABC_DEF", &.{.float_literal});2014 try 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});2015 try testTokenize("0x0_1_2_3_4_5_6.7_8_9_A_B_C_D_E_F", &.{.float_literal});
2016 testTokenize("0x0p0", &.{.float_literal});2016 try testTokenize("0x0p0", &.{.float_literal});
2017 testTokenize("0x0.0p0", &.{.float_literal});2017 try testTokenize("0x0.0p0", &.{.float_literal});
2018 testTokenize("0xff.ffp10", &.{.float_literal});2018 try testTokenize("0xff.ffp10", &.{.float_literal});
2019 testTokenize("0xff.ffP10", &.{.float_literal});2019 try testTokenize("0xff.ffP10", &.{.float_literal});
2020 testTokenize("0xff.p10", &.{.float_literal});2020 try testTokenize("0xff.p10", &.{.float_literal});
2021 testTokenize("0xffp10", &.{.float_literal});2021 try testTokenize("0xffp10", &.{.float_literal});
2022 testTokenize("0xff_ff.ff_ffp1_0_0_0", &.{.float_literal});2022 try testTokenize("0xff_ff.ff_ffp1_0_0_0", &.{.float_literal});
2023 testTokenize("0xf_f_f_f.f_f_f_fp+1_000", &.{.float_literal});2023 try 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});2024 try testTokenize("0xf_f_f_f.f_f_f_fp-1_00_0", &.{.float_literal});
20252025
2026 testTokenize("0x1e", &.{.integer_literal});2026 try testTokenize("0x1e", &.{.integer_literal});
2027 testTokenize("0x1e0", &.{.integer_literal});2027 try testTokenize("0x1e0", &.{.integer_literal});
2028 testTokenize("0x1p", &.{.invalid});2028 try testTokenize("0x1p", &.{.invalid});
2029 testTokenize("0xfp0z1", &.{ .invalid, .identifier });2029 try testTokenize("0xfp0z1", &.{ .invalid, .identifier });
2030 testTokenize("0xff.ffpff", &.{ .invalid, .identifier });2030 try testTokenize("0xff.ffpff", &.{ .invalid, .identifier });
2031 testTokenize("0x0.p", &.{.invalid});2031 try testTokenize("0x0.p", &.{.invalid});
2032 testTokenize("0x0.z", &.{ .invalid, .identifier });2032 try testTokenize("0x0.z", &.{ .invalid, .identifier });
2033 testTokenize("0x0._", &.{ .invalid, .identifier });2033 try testTokenize("0x0._", &.{ .invalid, .identifier });
2034 testTokenize("0x0_.0", &.{ .invalid, .period, .integer_literal });2034 try testTokenize("0x0_.0", &.{ .invalid, .period, .integer_literal });
2035 testTokenize("0x0_.0.0", &.{ .invalid, .period, .float_literal });2035 try testTokenize("0x0_.0.0", &.{ .invalid, .period, .float_literal });
2036 testTokenize("0x0._0", &.{ .invalid, .identifier });2036 try testTokenize("0x0._0", &.{ .invalid, .identifier });
2037 testTokenize("0x0.0_", &.{.invalid});2037 try testTokenize("0x0.0_", &.{.invalid});
2038 testTokenize("0x0_p0", &.{ .invalid, .identifier });2038 try testTokenize("0x0_p0", &.{ .invalid, .identifier });
2039 testTokenize("0x0_.p0", &.{ .invalid, .period, .identifier });2039 try testTokenize("0x0_.p0", &.{ .invalid, .period, .identifier });
2040 testTokenize("0x0._p0", &.{ .invalid, .identifier });2040 try testTokenize("0x0._p0", &.{ .invalid, .identifier });
2041 testTokenize("0x0.0_p0", &.{ .invalid, .identifier });2041 try testTokenize("0x0.0_p0", &.{ .invalid, .identifier });
2042 testTokenize("0x0._0p0", &.{ .invalid, .identifier });2042 try testTokenize("0x0._0p0", &.{ .invalid, .identifier });
2043 testTokenize("0x0.0p_0", &.{ .invalid, .identifier });2043 try testTokenize("0x0.0p_0", &.{ .invalid, .identifier });
2044 testTokenize("0x0.0p+_0", &.{ .invalid, .identifier });2044 try testTokenize("0x0.0p+_0", &.{ .invalid, .identifier });
2045 testTokenize("0x0.0p-_0", &.{ .invalid, .identifier });2045 try testTokenize("0x0.0p-_0", &.{ .invalid, .identifier });
2046 testTokenize("0x0.0p0_", &.{ .invalid, .eof });2046 try testTokenize("0x0.0p0_", &.{ .invalid, .eof });
2047}2047}
20482048
2049fn testTokenize(source: []const u8, expected_tokens: []const Token.Tag) void {2049fn testTokenize(source: []const u8, expected_tokens: []const Token.Tag) !void {
2050 var tokenizer = Tokenizer.init(source);2050 var tokenizer = Tokenizer.init(source);
2051 for (expected_tokens) |expected_token_id| {2051 for (expected_tokens) |expected_token_id| {
2052 const token = tokenizer.next();2052 const token = tokenizer.next();
...@@ -2055,6 +2055,6 @@ fn testTokenize(source: []const u8, expected_tokens: []const Token.Tag) void {...@@ -2055,6 +2055,6 @@ fn testTokenize(source: []const u8, expected_tokens: []const Token.Tag) void {
2055 }2055 }
2056 }2056 }
2057 const last_token = tokenizer.next();2057 const last_token = tokenizer.next();
2058 std.testing.expect(last_token.tag == .eof);2058 try std.testing.expect(last_token.tag == .eof);
2059 std.testing.expect(last_token.loc.start == source.len);2059 try std.testing.expect(last_token.loc.start == source.len);
2060}2060}
src/Cache.zig+18-18
...@@ -727,7 +727,7 @@ test "cache file and then recall it" {...@@ -727,7 +727,7 @@ test "cache file and then recall it" {
727 _ = try ch.addFile(temp_file, null);727 _ = try ch.addFile(temp_file, null);
728728
729 // There should be nothing in the cache729 // There should be nothing in the cache
730 testing.expectEqual(false, try ch.hit());730 try testing.expectEqual(false, try ch.hit());
731731
732 digest1 = ch.final();732 digest1 = ch.final();
733 try ch.writeManifest();733 try ch.writeManifest();
...@@ -742,13 +742,13 @@ test "cache file and then recall it" {...@@ -742,13 +742,13 @@ test "cache file and then recall it" {
742 _ = try ch.addFile(temp_file, null);742 _ = try ch.addFile(temp_file, null);
743743
744 // Cache hit! We just "built" the same file744 // Cache hit! We just "built" the same file
745 testing.expect(try ch.hit());745 try testing.expect(try ch.hit());
746 digest2 = ch.final();746 digest2 = ch.final();
747747
748 try ch.writeManifest();748 try ch.writeManifest();
749 }749 }
750750
751 testing.expectEqual(digest1, digest2);751 try testing.expectEqual(digest1, digest2);
752 }752 }
753753
754 try cwd.deleteTree(temp_manifest_dir);754 try cwd.deleteTree(temp_manifest_dir);
...@@ -760,11 +760,11 @@ test "give problematic timestamp" {...@@ -760,11 +760,11 @@ test "give problematic timestamp" {
760 // to make it problematic, we make it only accurate to the second760 // to make it problematic, we make it only accurate to the second
761 fs_clock = @divTrunc(fs_clock, std.time.ns_per_s);761 fs_clock = @divTrunc(fs_clock, std.time.ns_per_s);
762 fs_clock *= std.time.ns_per_s;762 fs_clock *= std.time.ns_per_s;
763 testing.expect(isProblematicTimestamp(fs_clock));763 try testing.expect(isProblematicTimestamp(fs_clock));
764}764}
765765
766test "give nonproblematic timestamp" {766test "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));
768}768}
769769
770test "check that changing a file makes cache fail" {770test "check that changing a file makes cache fail" {
...@@ -807,9 +807,9 @@ test "check that changing a file makes cache fail" {...@@ -807,9 +807,9 @@ test "check that changing a file makes cache fail" {
807 const temp_file_idx = try ch.addFile(temp_file, 100);807 const temp_file_idx = try ch.addFile(temp_file, 100);
808808
809 // There should be nothing in the cache809 // 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
814 digest1 = ch.final();814 digest1 = ch.final();
815815
...@@ -826,17 +826,17 @@ test "check that changing a file makes cache fail" {...@@ -826,17 +826,17 @@ test "check that changing a file makes cache fail" {
826 const temp_file_idx = try ch.addFile(temp_file, 100);826 const temp_file_idx = try ch.addFile(temp_file, 100);
827827
828 // A file that we depend on has been updated, so the cache should not contain an entry for it828 // 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
831 // The cache system does not keep the contents of re-hashed input files.831 // 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
834 digest2 = ch.final();834 digest2 = ch.final();
835835
836 try ch.writeManifest();836 try ch.writeManifest();
837 }837 }
838838
839 testing.expect(!mem.eql(u8, digest1[0..], digest2[0..]));839 try testing.expect(!mem.eql(u8, digest1[0..], digest2[0..]));
840 }840 }
841841
842 try cwd.deleteTree(temp_manifest_dir);842 try cwd.deleteTree(temp_manifest_dir);
...@@ -868,7 +868,7 @@ test "no file inputs" {...@@ -868,7 +868,7 @@ test "no file inputs" {
868 ch.hash.addBytes("1234");868 ch.hash.addBytes("1234");
869869
870 // There should be nothing in the cache870 // There should be nothing in the cache
871 testing.expectEqual(false, try ch.hit());871 try testing.expectEqual(false, try ch.hit());
872872
873 digest1 = ch.final();873 digest1 = ch.final();
874874
...@@ -880,12 +880,12 @@ test "no file inputs" {...@@ -880,12 +880,12 @@ test "no file inputs" {
880880
881 ch.hash.addBytes("1234");881 ch.hash.addBytes("1234");
882882
883 testing.expect(try ch.hit());883 try testing.expect(try ch.hit());
884 digest2 = ch.final();884 digest2 = ch.final();
885 try ch.writeManifest();885 try ch.writeManifest();
886 }886 }
887887
888 testing.expectEqual(digest1, digest2);888 try testing.expectEqual(digest1, digest2);
889}889}
890890
891test "Manifest with files added after initial hash work" {891test "Manifest with files added after initial hash work" {
...@@ -926,7 +926,7 @@ test "Manifest with files added after initial hash work" {...@@ -926,7 +926,7 @@ test "Manifest with files added after initial hash work" {
926 _ = try ch.addFile(temp_file1, null);926 _ = try ch.addFile(temp_file1, null);
927927
928 // There should be nothing in the cache928 // There should be nothing in the cache
929 testing.expectEqual(false, try ch.hit());929 try testing.expectEqual(false, try ch.hit());
930930
931 _ = try ch.addFilePost(temp_file2);931 _ = try ch.addFilePost(temp_file2);
932932
...@@ -940,12 +940,12 @@ test "Manifest with files added after initial hash work" {...@@ -940,12 +940,12 @@ test "Manifest with files added after initial hash work" {
940 ch.hash.addBytes("1234");940 ch.hash.addBytes("1234");
941 _ = try ch.addFile(temp_file1, null);941 _ = try ch.addFile(temp_file1, null);
942942
943 testing.expect(try ch.hit());943 try testing.expect(try ch.hit());
944 digest2 = ch.final();944 digest2 = ch.final();
945945
946 try ch.writeManifest();946 try ch.writeManifest();
947 }947 }
948 testing.expect(mem.eql(u8, &digest1, &digest2));948 try testing.expect(mem.eql(u8, &digest1, &digest2));
949949
950 // Modify the file added after initial hash950 // Modify the file added after initial hash
951 const ts2 = std.time.nanoTimestamp();951 const ts2 = std.time.nanoTimestamp();
...@@ -963,7 +963,7 @@ test "Manifest with files added after initial hash work" {...@@ -963,7 +963,7 @@ test "Manifest with files added after initial hash work" {
963 _ = try ch.addFile(temp_file1, null);963 _ = try ch.addFile(temp_file1, null);
964964
965 // A file that we depend on has been updated, so the cache should not contain an entry for it965 // 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
968 _ = try ch.addFilePost(temp_file2);968 _ = try ch.addFilePost(temp_file2);
969969
...@@ -972,7 +972,7 @@ test "Manifest with files added after initial hash work" {...@@ -972,7 +972,7 @@ test "Manifest with files added after initial hash work" {
972 try ch.writeManifest();972 try ch.writeManifest();
973 }973 }
974974
975 testing.expect(!mem.eql(u8, &digest1, &digest3));975 try testing.expect(!mem.eql(u8, &digest1, &digest3));
976 }976 }
977977
978 try cwd.deleteTree(temp_manifest_dir);978 try cwd.deleteTree(temp_manifest_dir);
src/Compilation.zig+8-8
...@@ -3093,14 +3093,14 @@ pub fn classifyFileExt(filename: []const u8) FileExt {...@@ -3093,14 +3093,14 @@ pub fn classifyFileExt(filename: []const u8) FileExt {
3093}3093}
30943094
3095test "classifyFileExt" {3095test "classifyFileExt" {
3096 std.testing.expectEqual(FileExt.cpp, classifyFileExt("foo.cc"));3096 try std.testing.expectEqual(FileExt.cpp, classifyFileExt("foo.cc"));
3097 std.testing.expectEqual(FileExt.unknown, classifyFileExt("foo.nim"));3097 try std.testing.expectEqual(FileExt.unknown, classifyFileExt("foo.nim"));
3098 std.testing.expectEqual(FileExt.shared_library, classifyFileExt("foo.so"));3098 try std.testing.expectEqual(FileExt.shared_library, classifyFileExt("foo.so"));
3099 std.testing.expectEqual(FileExt.shared_library, classifyFileExt("foo.so.1"));3099 try std.testing.expectEqual(FileExt.shared_library, classifyFileExt("foo.so.1"));
3100 std.testing.expectEqual(FileExt.shared_library, classifyFileExt("foo.so.1.2"));3100 try std.testing.expectEqual(FileExt.shared_library, classifyFileExt("foo.so.1.2"));
3101 std.testing.expectEqual(FileExt.shared_library, classifyFileExt("foo.so.1.2.3"));3101 try std.testing.expectEqual(FileExt.shared_library, classifyFileExt("foo.so.1.2.3"));
3102 std.testing.expectEqual(FileExt.unknown, classifyFileExt("foo.so.1.2.3~"));3102 try std.testing.expectEqual(FileExt.unknown, classifyFileExt("foo.so.1.2.3~"));
3103 std.testing.expectEqual(FileExt.zig, classifyFileExt("foo.zig"));3103 try std.testing.expectEqual(FileExt.zig, classifyFileExt("foo.zig"));
3104}3104}
31053105
3106fn haveFramePointer(comp: *const Compilation) bool {3106fn haveFramePointer(comp: *const Compilation) bool {
src/DepTokenizer.zig+2-2
...@@ -918,7 +918,7 @@ fn depTokenizer(input: []const u8, expect: []const u8) !void {...@@ -918,7 +918,7 @@ fn depTokenizer(input: []const u8, expect: []const u8) !void {
918 }918 }
919919
920 if (std.mem.eql(u8, expect, buffer.items)) {920 if (std.mem.eql(u8, expect, buffer.items)) {
921 testing.expect(true);921 try testing.expect(true);
922 return;922 return;
923 }923 }
924924
...@@ -930,7 +930,7 @@ fn depTokenizer(input: []const u8, expect: []const u8) !void {...@@ -930,7 +930,7 @@ fn depTokenizer(input: []const u8, expect: []const u8) !void {
930 try printSection(out, ">>>> got", buffer.items);930 try printSection(out, ">>>> got", buffer.items);
931 try printRuler(out);931 try printRuler(out);
932932
933 testing.expect(false);933 try testing.expect(false);
934}934}
935935
936fn printSection(out: anytype, label: []const u8, bytes: []const u8) !void {936fn 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,...@@ -67,27 +67,27 @@ pub const c_abi_int_param_regs = [_]Register{ .x0, .x1, .x2, .x3, .x4, .x5, .x6,
67pub const c_abi_int_return_regs = [_]Register{ .x0, .x1, .x2, .x3, .x4, .x5, .x6, .x7 };67pub const c_abi_int_return_regs = [_]Register{ .x0, .x1, .x2, .x3, .x4, .x5, .x6, .x7 };
6868
69test "Register.id" {69test "Register.id" {
70 testing.expectEqual(@as(u5, 0), Register.x0.id());70 try testing.expectEqual(@as(u5, 0), Register.x0.id());
71 testing.expectEqual(@as(u5, 0), Register.w0.id());71 try testing.expectEqual(@as(u5, 0), Register.w0.id());
7272
73 testing.expectEqual(@as(u5, 31), Register.xzr.id());73 try testing.expectEqual(@as(u5, 31), Register.xzr.id());
74 testing.expectEqual(@as(u5, 31), Register.wzr.id());74 try testing.expectEqual(@as(u5, 31), Register.wzr.id());
7575
76 testing.expectEqual(@as(u5, 31), Register.sp.id());76 try testing.expectEqual(@as(u5, 31), Register.sp.id());
77 testing.expectEqual(@as(u5, 31), Register.sp.id());77 try testing.expectEqual(@as(u5, 31), Register.sp.id());
78}78}
7979
80test "Register.size" {80test "Register.size" {
81 testing.expectEqual(@as(u7, 64), Register.x19.size());81 try testing.expectEqual(@as(u7, 64), Register.x19.size());
82 testing.expectEqual(@as(u7, 32), Register.w3.size());82 try testing.expectEqual(@as(u7, 32), Register.w3.size());
83}83}
8484
85test "Register.to64/to32" {85test "Register.to64/to32" {
86 testing.expectEqual(Register.x0, Register.w0.to64());86 try testing.expectEqual(Register.x0, Register.w0.to64());
87 testing.expectEqual(Register.x0, Register.x0.to64());87 try testing.expectEqual(Register.x0, Register.x0.to64());
8888
89 testing.expectEqual(Register.w3, Register.w3.to32());89 try testing.expectEqual(Register.w3, Register.w3.to32());
90 testing.expectEqual(Register.w3, Register.x3.to32());90 try testing.expectEqual(Register.w3, Register.x3.to32());
91}91}
9292
93// zig fmt: off93// zig fmt: off
...@@ -169,33 +169,33 @@ pub const FloatingPointRegister = enum(u8) {...@@ -169,33 +169,33 @@ pub const FloatingPointRegister = enum(u8) {
169// zig fmt: on169// zig fmt: on
170170
171test "FloatingPointRegister.id" {171test "FloatingPointRegister.id" {
172 testing.expectEqual(@as(u5, 0), FloatingPointRegister.b0.id());172 try testing.expectEqual(@as(u5, 0), FloatingPointRegister.b0.id());
173 testing.expectEqual(@as(u5, 0), FloatingPointRegister.h0.id());173 try testing.expectEqual(@as(u5, 0), FloatingPointRegister.h0.id());
174 testing.expectEqual(@as(u5, 0), FloatingPointRegister.s0.id());174 try testing.expectEqual(@as(u5, 0), FloatingPointRegister.s0.id());
175 testing.expectEqual(@as(u5, 0), FloatingPointRegister.d0.id());175 try testing.expectEqual(@as(u5, 0), FloatingPointRegister.d0.id());
176 testing.expectEqual(@as(u5, 0), FloatingPointRegister.q0.id());176 try testing.expectEqual(@as(u5, 0), FloatingPointRegister.q0.id());
177177
178 testing.expectEqual(@as(u5, 2), FloatingPointRegister.q2.id());178 try testing.expectEqual(@as(u5, 2), FloatingPointRegister.q2.id());
179 testing.expectEqual(@as(u5, 31), FloatingPointRegister.d31.id());179 try testing.expectEqual(@as(u5, 31), FloatingPointRegister.d31.id());
180}180}
181181
182test "FloatingPointRegister.size" {182test "FloatingPointRegister.size" {
183 testing.expectEqual(@as(u8, 128), FloatingPointRegister.q1.size());183 try testing.expectEqual(@as(u8, 128), FloatingPointRegister.q1.size());
184 testing.expectEqual(@as(u8, 64), FloatingPointRegister.d2.size());184 try testing.expectEqual(@as(u8, 64), FloatingPointRegister.d2.size());
185 testing.expectEqual(@as(u8, 32), FloatingPointRegister.s3.size());185 try testing.expectEqual(@as(u8, 32), FloatingPointRegister.s3.size());
186 testing.expectEqual(@as(u8, 16), FloatingPointRegister.h4.size());186 try testing.expectEqual(@as(u8, 16), FloatingPointRegister.h4.size());
187 testing.expectEqual(@as(u8, 8), FloatingPointRegister.b5.size());187 try testing.expectEqual(@as(u8, 8), FloatingPointRegister.b5.size());
188}188}
189189
190test "FloatingPointRegister.toX" {190test "FloatingPointRegister.toX" {
191 testing.expectEqual(FloatingPointRegister.q1, FloatingPointRegister.q1.to128());191 try testing.expectEqual(FloatingPointRegister.q1, FloatingPointRegister.q1.to128());
192 testing.expectEqual(FloatingPointRegister.q2, FloatingPointRegister.b2.to128());192 try testing.expectEqual(FloatingPointRegister.q2, FloatingPointRegister.b2.to128());
193 testing.expectEqual(FloatingPointRegister.q3, FloatingPointRegister.h3.to128());193 try testing.expectEqual(FloatingPointRegister.q3, FloatingPointRegister.h3.to128());
194194
195 testing.expectEqual(FloatingPointRegister.d0, FloatingPointRegister.q0.to64());195 try testing.expectEqual(FloatingPointRegister.d0, FloatingPointRegister.q0.to64());
196 testing.expectEqual(FloatingPointRegister.s1, FloatingPointRegister.d1.to32());196 try testing.expectEqual(FloatingPointRegister.s1, FloatingPointRegister.d1.to32());
197 testing.expectEqual(FloatingPointRegister.h2, FloatingPointRegister.s2.to16());197 try testing.expectEqual(FloatingPointRegister.h2, FloatingPointRegister.s2.to16());
198 testing.expectEqual(FloatingPointRegister.b3, FloatingPointRegister.h3.to8());198 try testing.expectEqual(FloatingPointRegister.b3, FloatingPointRegister.h3.to8());
199}199}
200200
201/// Represents an instruction in the AArch64 instruction set201/// Represents an instruction in the AArch64 instruction set
...@@ -1225,6 +1225,6 @@ test "serialize instructions" {...@@ -1225,6 +1225,6 @@ test "serialize instructions" {
12251225
1226 for (testcases) |case| {1226 for (testcases) |case| {
1227 const actual = case.inst.toU32();1227 const actual = case.inst.toU32();
1228 testing.expectEqual(case.expected, actual);1228 try testing.expectEqual(case.expected, actual);
1229 }1229 }
1230}1230}
src/codegen/arm.zig+12-12
...@@ -88,19 +88,19 @@ pub const Condition = enum(u4) {...@@ -88,19 +88,19 @@ pub const Condition = enum(u4) {
88};88};
8989
90test "condition from CompareOperator" {90test "condition from CompareOperator" {
91 testing.expectEqual(@as(Condition, .eq), Condition.fromCompareOperatorSigned(.eq));91 try testing.expectEqual(@as(Condition, .eq), Condition.fromCompareOperatorSigned(.eq));
92 testing.expectEqual(@as(Condition, .eq), Condition.fromCompareOperatorUnsigned(.eq));92 try testing.expectEqual(@as(Condition, .eq), Condition.fromCompareOperatorUnsigned(.eq));
9393
94 testing.expectEqual(@as(Condition, .gt), Condition.fromCompareOperatorSigned(.gt));94 try testing.expectEqual(@as(Condition, .gt), Condition.fromCompareOperatorSigned(.gt));
95 testing.expectEqual(@as(Condition, .hi), Condition.fromCompareOperatorUnsigned(.gt));95 try testing.expectEqual(@as(Condition, .hi), Condition.fromCompareOperatorUnsigned(.gt));
9696
97 testing.expectEqual(@as(Condition, .le), Condition.fromCompareOperatorSigned(.lte));97 try testing.expectEqual(@as(Condition, .le), Condition.fromCompareOperatorSigned(.lte));
98 testing.expectEqual(@as(Condition, .ls), Condition.fromCompareOperatorUnsigned(.lte));98 try testing.expectEqual(@as(Condition, .ls), Condition.fromCompareOperatorUnsigned(.lte));
99}99}
100100
101test "negate condition" {101test "negate condition" {
102 testing.expectEqual(@as(Condition, .eq), Condition.ne.negate());102 try testing.expectEqual(@as(Condition, .eq), Condition.ne.negate());
103 testing.expectEqual(@as(Condition, .ne), Condition.eq.negate());103 try testing.expectEqual(@as(Condition, .ne), Condition.eq.negate());
104}104}
105105
106/// Represents a register in the ARM instruction set architecture106/// Represents a register in the ARM instruction set architecture
...@@ -175,8 +175,8 @@ pub const Register = enum(u5) {...@@ -175,8 +175,8 @@ pub const Register = enum(u5) {
175};175};
176176
177test "Register.id" {177test "Register.id" {
178 testing.expectEqual(@as(u4, 15), Register.r15.id());178 try testing.expectEqual(@as(u4, 15), Register.r15.id());
179 testing.expectEqual(@as(u4, 15), Register.pc.id());179 try testing.expectEqual(@as(u4, 15), Register.pc.id());
180}180}
181181
182/// Program status registers containing flags, mode bits and other182/// Program status registers containing flags, mode bits and other
...@@ -1225,7 +1225,7 @@ test "serialize instructions" {...@@ -1225,7 +1225,7 @@ test "serialize instructions" {
12251225
1226 for (testcases) |case| {1226 for (testcases) |case| {
1227 const actual = case.inst.toU32();1227 const actual = case.inst.toU32();
1228 testing.expectEqual(case.expected, actual);1228 try testing.expectEqual(case.expected, actual);
1229 }1229 }
1230}1230}
12311231
...@@ -1265,6 +1265,6 @@ test "aliases" {...@@ -1265,6 +1265,6 @@ test "aliases" {
1265 };1265 };
12661266
1267 for (testcases) |case| {1267 for (testcases) |case| {
1268 testing.expectEqual(case.expected.toU32(), case.actual.toU32());1268 try testing.expectEqual(case.expected.toU32(), case.actual.toU32());
1269 }1269 }
1270}1270}
src/codegen/riscv64.zig+1-1
...@@ -465,6 +465,6 @@ test "serialize instructions" {...@@ -465,6 +465,6 @@ test "serialize instructions" {
465465
466 for (testcases) |case| {466 for (testcases) |case| {
467 const actual = case.inst.toU32();467 const actual = case.inst.toU32();
468 testing.expectEqual(case.expected, actual);468 try testing.expectEqual(case.expected, actual);
469 }469 }
470}470}
src/codegen/wasm.zig+5-5
...@@ -463,11 +463,11 @@ test "Wasm - buildOpcode" {...@@ -463,11 +463,11 @@ test "Wasm - buildOpcode" {
463 const i64_extend32_s = buildOpcode(.{ .op = .extend, .valtype1 = .i64, .width = 32, .signedness = .signed });463 const i64_extend32_s = buildOpcode(.{ .op = .extend, .valtype1 = .i64, .width = 32, .signedness = .signed });
464 const f64_reinterpret_i64 = buildOpcode(.{ .op = .reinterpret, .valtype1 = .f64, .valtype2 = .i64 });464 const f64_reinterpret_i64 = buildOpcode(.{ .op = .reinterpret, .valtype1 = .f64, .valtype2 = .i64 });
465465
466 testing.expectEqual(@as(wasm.Opcode, .i32_const), i32_const);466 try testing.expectEqual(@as(wasm.Opcode, .i32_const), i32_const);
467 testing.expectEqual(@as(wasm.Opcode, .end), end);467 try testing.expectEqual(@as(wasm.Opcode, .end), end);
468 testing.expectEqual(@as(wasm.Opcode, .local_get), local_get);468 try testing.expectEqual(@as(wasm.Opcode, .local_get), local_get);
469 testing.expectEqual(@as(wasm.Opcode, .i64_extend32_s), i64_extend32_s);469 try testing.expectEqual(@as(wasm.Opcode, .i64_extend32_s), i64_extend32_s);
470 testing.expectEqual(@as(wasm.Opcode, .f64_reinterpret_i64), f64_reinterpret_i64);470 try testing.expectEqual(@as(wasm.Opcode, .f64_reinterpret_i64), f64_reinterpret_i64);
471}471}
472472
473pub const Result = union(enum) {473pub const Result = union(enum) {
src/link/MachO.zig+1-4
...@@ -687,10 +687,7 @@ fn linkWithLLD(self: *MachO, comp: *Compilation) !void {...@@ -687,10 +687,7 @@ fn linkWithLLD(self: *MachO, comp: *Compilation) !void {
687 try argv.append("zig");687 try argv.append("zig");
688 try argv.append("ld");688 try argv.append("ld");
689689
690 try argv.ensureCapacity(input_files.items.len);690 try argv.appendSlice(input_files.items);
691 for (input_files.items) |f| {
692 argv.appendAssumeCapacity(f);
693 }
694691
695 try argv.append("-o");692 try argv.append("-o");
696 try argv.append(full_out_path);693 try argv.append(full_out_path);
src/link/MachO/CodeSignature.zig+1-1
...@@ -182,7 +182,7 @@ test "CodeSignature header" {...@@ -182,7 +182,7 @@ test "CodeSignature header" {
182 try code_sig.writeHeader(stream.writer());182 try code_sig.writeHeader(stream.writer());
183183
184 const expected = &[_]u8{ 0xfa, 0xde, 0x0c, 0xc0, 0x0, 0x0, 0x0, 0xc, 0x0, 0x0, 0x0, 0x0 };184 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));
186}186}
187187
188pub fn calcCodeSignaturePaddingSize(id: []const u8, file_size: u64, page_size: u16) u32 {188pub 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" {...@@ -404,15 +404,15 @@ test "Trie node count" {
404 var trie = Trie.init(gpa);404 var trie = Trie.init(gpa);
405 defer trie.deinit();405 defer trie.deinit();
406406
407 testing.expectEqual(trie.node_count, 0);407 try testing.expectEqual(trie.node_count, 0);
408 testing.expect(trie.root == null);408 try testing.expect(trie.root == null);
409409
410 try trie.put(.{410 try trie.put(.{
411 .name = "_main",411 .name = "_main",
412 .vmaddr_offset = 0,412 .vmaddr_offset = 0,
413 .export_flags = 0,413 .export_flags = 0,
414 });414 });
415 testing.expectEqual(trie.node_count, 2);415 try testing.expectEqual(trie.node_count, 2);
416416
417 // Inserting the same node shouldn't update the trie.417 // Inserting the same node shouldn't update the trie.
418 try trie.put(.{418 try trie.put(.{
...@@ -420,14 +420,14 @@ test "Trie node count" {...@@ -420,14 +420,14 @@ test "Trie node count" {
420 .vmaddr_offset = 0,420 .vmaddr_offset = 0,
421 .export_flags = 0,421 .export_flags = 0,
422 });422 });
423 testing.expectEqual(trie.node_count, 2);423 try testing.expectEqual(trie.node_count, 2);
424424
425 try trie.put(.{425 try trie.put(.{
426 .name = "__mh_execute_header",426 .name = "__mh_execute_header",
427 .vmaddr_offset = 0x1000,427 .vmaddr_offset = 0x1000,
428 .export_flags = 0,428 .export_flags = 0,
429 });429 });
430 testing.expectEqual(trie.node_count, 4);430 try testing.expectEqual(trie.node_count, 4);
431431
432 // Inserting the same node shouldn't update the trie.432 // Inserting the same node shouldn't update the trie.
433 try trie.put(.{433 try trie.put(.{
...@@ -435,13 +435,13 @@ test "Trie node count" {...@@ -435,13 +435,13 @@ test "Trie node count" {
435 .vmaddr_offset = 0x1000,435 .vmaddr_offset = 0x1000,
436 .export_flags = 0,436 .export_flags = 0,
437 });437 });
438 testing.expectEqual(trie.node_count, 4);438 try testing.expectEqual(trie.node_count, 4);
439 try trie.put(.{439 try trie.put(.{
440 .name = "_main",440 .name = "_main",
441 .vmaddr_offset = 0,441 .vmaddr_offset = 0,
442 .export_flags = 0,442 .export_flags = 0,
443 });443 });
444 testing.expectEqual(trie.node_count, 4);444 try testing.expectEqual(trie.node_count, 4);
445}445}
446446
447test "Trie basic" {447test "Trie basic" {
...@@ -455,8 +455,8 @@ test "Trie basic" {...@@ -455,8 +455,8 @@ test "Trie basic" {
455 .vmaddr_offset = 0,455 .vmaddr_offset = 0,
456 .export_flags = 0,456 .export_flags = 0,
457 });457 });
458 testing.expect(trie.root.?.edges.items.len == 1);458 try testing.expect(trie.root.?.edges.items.len == 1);
459 testing.expect(mem.eql(u8, trie.root.?.edges.items[0].label, "_st"));459 try testing.expect(mem.eql(u8, trie.root.?.edges.items[0].label, "_st"));
460460
461 {461 {
462 // root --- _st ---> node --- art ---> node462 // root --- _st ---> node --- art ---> node
...@@ -465,12 +465,12 @@ test "Trie basic" {...@@ -465,12 +465,12 @@ test "Trie basic" {
465 .vmaddr_offset = 0,465 .vmaddr_offset = 0,
466 .export_flags = 0,466 .export_flags = 0,
467 });467 });
468 testing.expect(trie.root.?.edges.items.len == 1);468 try testing.expect(trie.root.?.edges.items.len == 1);
469469
470 const nextEdge = &trie.root.?.edges.items[0];470 const nextEdge = &trie.root.?.edges.items[0];
471 testing.expect(mem.eql(u8, nextEdge.label, "_st"));471 try testing.expect(mem.eql(u8, nextEdge.label, "_st"));
472 testing.expect(nextEdge.to.edges.items.len == 1);472 try testing.expect(nextEdge.to.edges.items.len == 1);
473 testing.expect(mem.eql(u8, nextEdge.to.edges.items[0].label, "art"));473 try testing.expect(mem.eql(u8, nextEdge.to.edges.items[0].label, "art"));
474 }474 }
475 {475 {
476 // root --- _ ---> node --- st ---> node --- art ---> node476 // root --- _ ---> node --- st ---> node --- art ---> node
...@@ -481,16 +481,16 @@ test "Trie basic" {...@@ -481,16 +481,16 @@ test "Trie basic" {
481 .vmaddr_offset = 0,481 .vmaddr_offset = 0,
482 .export_flags = 0,482 .export_flags = 0,
483 });483 });
484 testing.expect(trie.root.?.edges.items.len == 1);484 try testing.expect(trie.root.?.edges.items.len == 1);
485485
486 const nextEdge = &trie.root.?.edges.items[0];486 const nextEdge = &trie.root.?.edges.items[0];
487 testing.expect(mem.eql(u8, nextEdge.label, "_"));487 try testing.expect(mem.eql(u8, nextEdge.label, "_"));
488 testing.expect(nextEdge.to.edges.items.len == 2);488 try testing.expect(nextEdge.to.edges.items.len == 2);
489 testing.expect(mem.eql(u8, nextEdge.to.edges.items[0].label, "st"));489 try 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"));490 try testing.expect(mem.eql(u8, nextEdge.to.edges.items[1].label, "main"));
491491
492 const nextNextEdge = &nextEdge.to.edges.items[0];492 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"));
494 }494 }
495}495}
496496
...@@ -529,15 +529,15 @@ test "write Trie to a byte stream" {...@@ -529,15 +529,15 @@ test "write Trie to a byte stream" {
529 var stream = std.io.fixedBufferStream(buffer);529 var stream = std.io.fixedBufferStream(buffer);
530 {530 {
531 const nwritten = try trie.write(stream.writer());531 const nwritten = try trie.write(stream.writer());
532 testing.expect(nwritten == trie.size);532 try testing.expect(nwritten == trie.size);
533 testing.expect(mem.eql(u8, buffer, &exp_buffer));533 try testing.expect(mem.eql(u8, buffer, &exp_buffer));
534 }534 }
535 {535 {
536 // Writing finalized trie again should yield the same result.536 // Writing finalized trie again should yield the same result.
537 try stream.seekTo(0);537 try stream.seekTo(0);
538 const nwritten = try trie.write(stream.writer());538 const nwritten = try trie.write(stream.writer());
539 testing.expect(nwritten == trie.size);539 try testing.expect(nwritten == trie.size);
540 testing.expect(mem.eql(u8, buffer, &exp_buffer));540 try testing.expect(mem.eql(u8, buffer, &exp_buffer));
541 }541 }
542}542}
543543
...@@ -560,7 +560,7 @@ test "parse Trie from byte stream" {...@@ -560,7 +560,7 @@ test "parse Trie from byte stream" {
560 defer trie.deinit();560 defer trie.deinit();
561 const nread = try trie.read(in_stream.reader());561 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
565 try trie.finalize();565 try trie.finalize();
566566
...@@ -569,6 +569,6 @@ test "parse Trie from byte stream" {...@@ -569,6 +569,6 @@ test "parse Trie from byte stream" {
569 var out_stream = std.io.fixedBufferStream(out_buffer);569 var out_stream = std.io.fixedBufferStream(out_buffer);
570 const nwritten = try trie.write(out_stream.writer());570 const nwritten = try trie.write(out_stream.writer());
571571
572 testing.expect(nwritten == trie.size);572 try testing.expect(nwritten == trie.size);
573 testing.expect(mem.eql(u8, &in_buffer, out_buffer));573 try testing.expect(mem.eql(u8, &in_buffer, out_buffer));
574}574}
src/link/MachO/commands.zig+2-2
...@@ -286,13 +286,13 @@ fn testRead(allocator: *Allocator, buffer: []const u8, expected: anytype) !void...@@ -286,13 +286,13 @@ fn testRead(allocator: *Allocator, buffer: []const u8, expected: anytype) !void
286 var stream = io.fixedBufferStream(buffer);286 var stream = io.fixedBufferStream(buffer);
287 var given = try LoadCommand.read(allocator, stream.reader());287 var given = try LoadCommand.read(allocator, stream.reader());
288 defer given.deinit(allocator);288 defer given.deinit(allocator);
289 testing.expect(expected.eql(given));289 try testing.expect(expected.eql(given));
290}290}
291291
292fn testWrite(buffer: []u8, cmd: LoadCommand, expected: []const u8) !void {292fn testWrite(buffer: []u8, cmd: LoadCommand, expected: []const u8) !void {
293 var stream = io.fixedBufferStream(buffer);293 var stream = io.fixedBufferStream(buffer);
294 try cmd.write(stream.writer());294 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]));
296}296}
297297
298test "read-write segment command" {298test "read-write segment command" {
src/register_manager.zig+24-24
...@@ -267,21 +267,21 @@ test "tryAllocReg: no spilling" {...@@ -267,21 +267,21 @@ test "tryAllocReg: no spilling" {
267 .src = .unneeded,267 .src = .unneeded,
268 };268 };
269269
270 std.testing.expect(!function.register_manager.isRegAllocated(.r2));270 try std.testing.expect(!function.register_manager.isRegAllocated(.r2));
271 std.testing.expect(!function.register_manager.isRegAllocated(.r3));271 try std.testing.expect(!function.register_manager.isRegAllocated(.r3));
272272
273 std.testing.expectEqual(@as(?MockRegister, .r2), function.register_manager.tryAllocReg(&mock_instruction));273 try 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));274 try 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));275 try std.testing.expectEqual(@as(?MockRegister, null), function.register_manager.tryAllocReg(&mock_instruction));
276276
277 std.testing.expect(function.register_manager.isRegAllocated(.r2));277 try std.testing.expect(function.register_manager.isRegAllocated(.r2));
278 std.testing.expect(function.register_manager.isRegAllocated(.r3));278 try std.testing.expect(function.register_manager.isRegAllocated(.r3));
279279
280 function.register_manager.freeReg(.r2);280 function.register_manager.freeReg(.r2);
281 function.register_manager.freeReg(.r3);281 function.register_manager.freeReg(.r3);
282282
283 std.testing.expect(function.register_manager.isRegAllocated(.r2));283 try std.testing.expect(function.register_manager.isRegAllocated(.r2));
284 std.testing.expect(function.register_manager.isRegAllocated(.r3));284 try std.testing.expect(function.register_manager.isRegAllocated(.r3));
285}285}
286286
287test "allocReg: spilling" {287test "allocReg: spilling" {
...@@ -298,20 +298,20 @@ test "allocReg: spilling" {...@@ -298,20 +298,20 @@ test "allocReg: spilling" {
298 .src = .unneeded,298 .src = .unneeded,
299 };299 };
300300
301 std.testing.expect(!function.register_manager.isRegAllocated(.r2));301 try std.testing.expect(!function.register_manager.isRegAllocated(.r2));
302 std.testing.expect(!function.register_manager.isRegAllocated(.r3));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));304 try 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));305 try std.testing.expectEqual(@as(?MockRegister, .r3), try function.register_manager.allocReg(&mock_instruction));
306306
307 // Spill a register307 // Spill a register
308 std.testing.expectEqual(@as(?MockRegister, .r2), try function.register_manager.allocReg(&mock_instruction));308 try std.testing.expectEqual(@as(?MockRegister, .r2), try function.register_manager.allocReg(&mock_instruction));
309 std.testing.expectEqualSlices(MockRegister, &[_]MockRegister{.r2}, function.spilled.items);309 try std.testing.expectEqualSlices(MockRegister, &[_]MockRegister{.r2}, function.spilled.items);
310310
311 // No spilling necessary311 // No spilling necessary
312 function.register_manager.freeReg(.r3);312 function.register_manager.freeReg(.r3);
313 std.testing.expectEqual(@as(?MockRegister, .r3), try function.register_manager.allocReg(&mock_instruction));313 try std.testing.expectEqual(@as(?MockRegister, .r3), try function.register_manager.allocReg(&mock_instruction));
314 std.testing.expectEqualSlices(MockRegister, &[_]MockRegister{.r2}, function.spilled.items);314 try std.testing.expectEqualSlices(MockRegister, &[_]MockRegister{.r2}, function.spilled.items);
315}315}
316316
317test "getReg" {317test "getReg" {
...@@ -328,18 +328,18 @@ test "getReg" {...@@ -328,18 +328,18 @@ test "getReg" {
328 .src = .unneeded,328 .src = .unneeded,
329 };329 };
330330
331 std.testing.expect(!function.register_manager.isRegAllocated(.r2));331 try std.testing.expect(!function.register_manager.isRegAllocated(.r2));
332 std.testing.expect(!function.register_manager.isRegAllocated(.r3));332 try std.testing.expect(!function.register_manager.isRegAllocated(.r3));
333333
334 try function.register_manager.getReg(.r3, &mock_instruction);334 try function.register_manager.getReg(.r3, &mock_instruction);
335335
336 std.testing.expect(!function.register_manager.isRegAllocated(.r2));336 try std.testing.expect(!function.register_manager.isRegAllocated(.r2));
337 std.testing.expect(function.register_manager.isRegAllocated(.r3));337 try std.testing.expect(function.register_manager.isRegAllocated(.r3));
338338
339 // Spill r3339 // Spill r3
340 try function.register_manager.getReg(.r3, &mock_instruction);340 try function.register_manager.getReg(.r3, &mock_instruction);
341341
342 std.testing.expect(!function.register_manager.isRegAllocated(.r2));342 try std.testing.expect(!function.register_manager.isRegAllocated(.r2));
343 std.testing.expect(function.register_manager.isRegAllocated(.r3));343 try std.testing.expect(function.register_manager.isRegAllocated(.r3));
344 std.testing.expectEqualSlices(MockRegister, &[_]MockRegister{.r3}, function.spilled.items);344 try std.testing.expectEqualSlices(MockRegister, &[_]MockRegister{.r3}, function.spilled.items);
345}345}
src/test.zig+3-3
...@@ -704,14 +704,14 @@ pub const TestContext = struct {...@@ -704,14 +704,14 @@ pub const TestContext = struct {
704 defer file.close();704 defer file.close();
705 const out = try file.reader().readAllAlloc(arena, 5 * 1024 * 1024);705 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);
708 },708 },
709 .CompareObjectFile => |expected_output| {709 .CompareObjectFile => |expected_output| {
710 var file = try tmp.dir.openFile(bin_name, .{ .read = true });710 var file = try tmp.dir.openFile(bin_name, .{ .read = true });
711 defer file.close();711 defer file.close();
712 const out = try file.reader().readAllAlloc(arena, 5 * 1024 * 1024);712 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);
715 },715 },
716 .Error => |case_error_list| {716 .Error => |case_error_list| {
717 var test_node = update_node.start("assert", 0);717 var test_node = update_node.start("assert", 0);
...@@ -938,7 +938,7 @@ pub const TestContext = struct {...@@ -938,7 +938,7 @@ pub const TestContext = struct {
938 return error.ZigTestFailed;938 return error.ZigTestFailed;
939 },939 },
940 }940 }
941 std.testing.expectEqualStrings(expected_stdout, exec_result.stdout);941 try std.testing.expectEqualStrings(expected_stdout, exec_result.stdout);
942 // We allow stderr to have garbage in it because wasmtime prints a942 // We allow stderr to have garbage in it because wasmtime prints a
943 // warning about --invoke even though we don't pass it.943 // warning about --invoke even though we don't pass it.
944 //std.testing.expectEqualStrings("", exec_result.stderr);944 //std.testing.expectEqualStrings("", exec_result.stderr);
src/value.zig+3-3
...@@ -1650,19 +1650,19 @@ test "hash same value different representation" {...@@ -1650,19 +1650,19 @@ test "hash same value different representation" {
1650 .data = 0,1650 .data = 0,
1651 };1651 };
1652 const zero_2 = Value.initPayload(&payload_1.base);1652 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
1655 var payload_2 = Value.Payload.I64{1655 var payload_2 = Value.Payload.I64{
1656 .base = .{ .tag = .int_i64 },1656 .base = .{ .tag = .int_i64 },
1657 .data = 0,1657 .data = 0,
1658 };1658 };
1659 const zero_3 = Value.initPayload(&payload_2.base);1659 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
1662 var payload_3 = Value.Payload.BigInt{1662 var payload_3 = Value.Payload.BigInt{
1663 .base = .{ .tag = .int_big_negative },1663 .base = .{ .tag = .int_big_negative },
1664 .data = &[_]std.math.big.Limb{0},1664 .data = &[_]std.math.big.Limb{0},
1665 };1665 };
1666 const zero_4 = Value.initPayload(&payload_3.base);1666 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());
1668}1668}
test/behavior/align.zig+66-66
...@@ -6,16 +6,16 @@ const native_arch = builtin.target.cpu.arch;...@@ -6,16 +6,16 @@ const native_arch = builtin.target.cpu.arch;
6var foo: u8 align(4) = 100;6var foo: u8 align(4) = 100;
77
8test "global variable alignment" {8test "global variable alignment" {
9 comptime expect(@typeInfo(@TypeOf(&foo)).Pointer.alignment == 4);9 comptime try expect(@typeInfo(@TypeOf(&foo)).Pointer.alignment == 4);
10 comptime expect(@TypeOf(&foo) == *align(4) u8);10 comptime try expect(@TypeOf(&foo) == *align(4) u8);
11 {11 {
12 const slice = @as(*[1]u8, &foo)[0..];12 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);
14 }14 }
15 {15 {
16 var runtime_zero: usize = 0;16 var runtime_zero: usize = 0;
17 const slice = @as(*[1]u8, &foo)[runtime_zero..];17 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);
19 }19 }
20}20}
2121
...@@ -29,9 +29,9 @@ test "function alignment" {...@@ -29,9 +29,9 @@ test "function alignment" {
29 // function alignment is a compile error on wasm32/wasm6429 // function alignment is a compile error on wasm32/wasm64
30 if (native_arch == .wasm32 or native_arch == .wasm64) return error.SkipZigTest;30 if (native_arch == .wasm32 or native_arch == .wasm64) return error.SkipZigTest;
3131
32 expect(derp() == 1234);32 try expect(derp() == 1234);
33 expect(@TypeOf(noop1) == fn () align(1) void);33 try expect(@TypeOf(noop1) == fn () align(1) void);
34 expect(@TypeOf(noop4) == fn () align(4) void);34 try expect(@TypeOf(noop4) == fn () align(4) void);
35 noop1();35 noop1();
36 noop4();36 noop4();
37}37}
...@@ -42,7 +42,7 @@ var baz: packed struct {...@@ -42,7 +42,7 @@ var baz: packed struct {
42} = undefined;42} = undefined;
4343
44test "packed struct alignment" {44test "packed struct alignment" {
45 expect(@TypeOf(&baz.b) == *align(1) u32);45 try expect(@TypeOf(&baz.b) == *align(1) u32);
46}46}
4747
48const blah: packed struct {48const blah: packed struct {
...@@ -52,17 +52,17 @@ const blah: packed struct {...@@ -52,17 +52,17 @@ const blah: packed struct {
52} = undefined;52} = undefined;
5353
54test "bit field alignment" {54test "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);
56}56}
5757
58test "default alignment allows unspecified in type syntax" {58test "default alignment allows unspecified in type syntax" {
59 expect(*u32 == *align(@alignOf(u32)) u32);59 try expect(*u32 == *align(@alignOf(u32)) u32);
60}60}
6161
62test "implicitly decreasing pointer alignment" {62test "implicitly decreasing pointer alignment" {
63 const a: u32 align(4) = 3;63 const a: u32 align(4) = 3;
64 const b: u32 align(8) = 4;64 const b: u32 align(8) = 4;
65 expect(addUnaligned(&a, &b) == 7);65 try expect(addUnaligned(&a, &b) == 7);
66}66}
6767
68fn addUnaligned(a: *align(1) const u32, b: *align(1) const u32) u32 {68fn 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 {...@@ -72,16 +72,16 @@ fn addUnaligned(a: *align(1) const u32, b: *align(1) const u32) u32 {
72test "implicitly decreasing slice alignment" {72test "implicitly decreasing slice alignment" {
73 const a: u32 align(4) = 3;73 const a: u32 align(4) = 3;
74 const b: u32 align(8) = 4;74 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);
76}76}
77fn addUnalignedSlice(a: []align(1) const u32, b: []align(1) const u32) u32 {77fn addUnalignedSlice(a: []align(1) const u32, b: []align(1) const u32) u32 {
78 return a[0] + b[0];78 return a[0] + b[0];
79}79}
8080
81test "specifying alignment allows pointer cast" {81test "specifying alignment allows pointer cast" {
82 testBytesAlign(0x33);82 try testBytesAlign(0x33);
83}83}
84fn testBytesAlign(b: u8) void {84fn testBytesAlign(b: u8) !void {
85 var bytes align(4) = [_]u8{85 var bytes align(4) = [_]u8{
86 b,86 b,
87 b,87 b,
...@@ -89,13 +89,13 @@ fn testBytesAlign(b: u8) void {...@@ -89,13 +89,13 @@ fn testBytesAlign(b: u8) void {
89 b,89 b,
90 };90 };
91 const ptr = @ptrCast(*u32, &bytes[0]);91 const ptr = @ptrCast(*u32, &bytes[0]);
92 expect(ptr.* == 0x33333333);92 try expect(ptr.* == 0x33333333);
93}93}
9494
95test "@alignCast pointers" {95test "@alignCast pointers" {
96 var x: u32 align(4) = 1;96 var x: u32 align(4) = 1;
97 expectsOnly1(&x);97 expectsOnly1(&x);
98 expect(x == 2);98 try expect(x == 2);
99}99}
100fn expectsOnly1(x: *align(1) u32) void {100fn expectsOnly1(x: *align(1) u32) void {
101 expects4(@alignCast(4, x));101 expects4(@alignCast(4, x));
...@@ -111,7 +111,7 @@ test "@alignCast slices" {...@@ -111,7 +111,7 @@ test "@alignCast slices" {
111 };111 };
112 const slice = array[0..];112 const slice = array[0..];
113 sliceExpectsOnly1(slice);113 sliceExpectsOnly1(slice);
114 expect(slice[0] == 2);114 try expect(slice[0] == 2);
115}115}
116fn sliceExpectsOnly1(slice: []align(1) u32) void {116fn sliceExpectsOnly1(slice: []align(1) u32) void {
117 sliceExpects4(@alignCast(4, slice));117 sliceExpects4(@alignCast(4, slice));
...@@ -124,12 +124,12 @@ test "implicitly decreasing fn alignment" {...@@ -124,12 +124,12 @@ test "implicitly decreasing fn alignment" {
124 // function alignment is a compile error on wasm32/wasm64124 // function alignment is a compile error on wasm32/wasm64
125 if (native_arch == .wasm32 or native_arch == .wasm64) return error.SkipZigTest;125 if (native_arch == .wasm32 or native_arch == .wasm64) return error.SkipZigTest;
126126
127 testImplicitlyDecreaseFnAlign(alignedSmall, 1234);127 try testImplicitlyDecreaseFnAlign(alignedSmall, 1234);
128 testImplicitlyDecreaseFnAlign(alignedBig, 5678);128 try testImplicitlyDecreaseFnAlign(alignedBig, 5678);
129}129}
130130
131fn testImplicitlyDecreaseFnAlign(ptr: fn () align(1) i32, answer: i32) void {131fn testImplicitlyDecreaseFnAlign(ptr: fn () align(1) i32, answer: i32) !void {
132 expect(ptr() == answer);132 try expect(ptr() == answer);
133}133}
134134
135fn alignedSmall() align(8) i32 {135fn alignedSmall() align(8) i32 {
...@@ -144,7 +144,7 @@ test "@alignCast functions" {...@@ -144,7 +144,7 @@ test "@alignCast functions" {
144 if (native_arch == .wasm32 or native_arch == .wasm64) return error.SkipZigTest;144 if (native_arch == .wasm32 or native_arch == .wasm64) return error.SkipZigTest;
145 if (native_arch == .thumb) return error.SkipZigTest;145 if (native_arch == .thumb) return error.SkipZigTest;
146146
147 expect(fnExpectsOnly1(simple4) == 0x19);147 try expect(fnExpectsOnly1(simple4) == 0x19);
148}148}
149fn fnExpectsOnly1(ptr: fn () align(1) i32) i32 {149fn fnExpectsOnly1(ptr: fn () align(1) i32) i32 {
150 return fnExpects4(@alignCast(4, ptr));150 return fnExpects4(@alignCast(4, ptr));
...@@ -161,9 +161,9 @@ test "generic function with align param" {...@@ -161,9 +161,9 @@ test "generic function with align param" {
161 if (native_arch == .wasm32 or native_arch == .wasm64) return error.SkipZigTest;161 if (native_arch == .wasm32 or native_arch == .wasm64) return error.SkipZigTest;
162 if (native_arch == .thumb) return error.SkipZigTest;162 if (native_arch == .thumb) return error.SkipZigTest;
163163
164 expect(whyWouldYouEverDoThis(1) == 0x1);164 try expect(whyWouldYouEverDoThis(1) == 0x1);
165 expect(whyWouldYouEverDoThis(4) == 0x1);165 try expect(whyWouldYouEverDoThis(4) == 0x1);
166 expect(whyWouldYouEverDoThis(8) == 0x1);166 try expect(whyWouldYouEverDoThis(8) == 0x1);
167}167}
168168
169fn whyWouldYouEverDoThis(comptime align_bytes: u8) align(align_bytes) u8 {169fn whyWouldYouEverDoThis(comptime align_bytes: u8) align(align_bytes) u8 {
...@@ -173,49 +173,49 @@ fn whyWouldYouEverDoThis(comptime align_bytes: u8) align(align_bytes) u8 {...@@ -173,49 +173,49 @@ fn whyWouldYouEverDoThis(comptime align_bytes: u8) align(align_bytes) u8 {
173test "@ptrCast preserves alignment of bigger source" {173test "@ptrCast preserves alignment of bigger source" {
174 var x: u32 align(16) = 1234;174 var x: u32 align(16) = 1234;
175 const ptr = @ptrCast(*u8, &x);175 const ptr = @ptrCast(*u8, &x);
176 expect(@TypeOf(ptr) == *align(16) u8);176 try expect(@TypeOf(ptr) == *align(16) u8);
177}177}
178178
179test "runtime known array index has best alignment possible" {179test "runtime known array index has best alignment possible" {
180 // take full advantage of over-alignment180 // take full advantage of over-alignment
181 var array align(4) = [_]u8{ 1, 2, 3, 4 };181 var array align(4) = [_]u8{ 1, 2, 3, 4 };
182 expect(@TypeOf(&array[0]) == *align(4) u8);182 try expect(@TypeOf(&array[0]) == *align(4) u8);
183 expect(@TypeOf(&array[1]) == *u8);183 try expect(@TypeOf(&array[1]) == *u8);
184 expect(@TypeOf(&array[2]) == *align(2) u8);184 try expect(@TypeOf(&array[2]) == *align(2) u8);
185 expect(@TypeOf(&array[3]) == *u8);185 try expect(@TypeOf(&array[3]) == *u8);
186186
187 // because align is too small but we still figure out to use 2187 // because align is too small but we still figure out to use 2
188 var bigger align(2) = [_]u64{ 1, 2, 3, 4 };188 var bigger align(2) = [_]u64{ 1, 2, 3, 4 };
189 expect(@TypeOf(&bigger[0]) == *align(2) u64);189 try expect(@TypeOf(&bigger[0]) == *align(2) u64);
190 expect(@TypeOf(&bigger[1]) == *align(2) u64);190 try expect(@TypeOf(&bigger[1]) == *align(2) u64);
191 expect(@TypeOf(&bigger[2]) == *align(2) u64);191 try expect(@TypeOf(&bigger[2]) == *align(2) u64);
192 expect(@TypeOf(&bigger[3]) == *align(2) u64);192 try expect(@TypeOf(&bigger[3]) == *align(2) u64);
193193
194 // because pointer is align 2 and u32 align % 2 == 0 we can assume align 2194 // because pointer is align 2 and u32 align % 2 == 0 we can assume align 2
195 var smaller align(2) = [_]u32{ 1, 2, 3, 4 };195 var smaller align(2) = [_]u32{ 1, 2, 3, 4 };
196 var runtime_zero: usize = 0;196 var runtime_zero: usize = 0;
197 comptime expect(@TypeOf(smaller[runtime_zero..]) == []align(2) u32);197 comptime try expect(@TypeOf(smaller[runtime_zero..]) == []align(2) u32);
198 comptime expect(@TypeOf(smaller[runtime_zero..].ptr) == [*]align(2) u32);198 comptime try expect(@TypeOf(smaller[runtime_zero..].ptr) == [*]align(2) u32);
199 testIndex(smaller[runtime_zero..].ptr, 0, *align(2) u32);199 try testIndex(smaller[runtime_zero..].ptr, 0, *align(2) u32);
200 testIndex(smaller[runtime_zero..].ptr, 1, *align(2) u32);200 try testIndex(smaller[runtime_zero..].ptr, 1, *align(2) u32);
201 testIndex(smaller[runtime_zero..].ptr, 2, *align(2) u32);201 try testIndex(smaller[runtime_zero..].ptr, 2, *align(2) u32);
202 testIndex(smaller[runtime_zero..].ptr, 3, *align(2) u32);202 try testIndex(smaller[runtime_zero..].ptr, 3, *align(2) u32);
203203
204 // has to use ABI alignment because index known at runtime only204 // has to use ABI alignment because index known at runtime only
205 testIndex2(array[runtime_zero..].ptr, 0, *u8);205 try testIndex2(array[runtime_zero..].ptr, 0, *u8);
206 testIndex2(array[runtime_zero..].ptr, 1, *u8);206 try testIndex2(array[runtime_zero..].ptr, 1, *u8);
207 testIndex2(array[runtime_zero..].ptr, 2, *u8);207 try testIndex2(array[runtime_zero..].ptr, 2, *u8);
208 testIndex2(array[runtime_zero..].ptr, 3, *u8);208 try testIndex2(array[runtime_zero..].ptr, 3, *u8);
209}209}
210fn testIndex(smaller: [*]align(2) u32, index: usize, comptime T: type) void {210fn testIndex(smaller: [*]align(2) u32, index: usize, comptime T: type) !void {
211 comptime expect(@TypeOf(&smaller[index]) == T);211 comptime try expect(@TypeOf(&smaller[index]) == T);
212}212}
213fn testIndex2(ptr: [*]align(4) u8, index: usize, comptime T: type) void {213fn testIndex2(ptr: [*]align(4) u8, index: usize, comptime T: type) !void {
214 comptime expect(@TypeOf(&ptr[index]) == T);214 comptime try expect(@TypeOf(&ptr[index]) == T);
215}215}
216216
217test "alignstack" {217test "alignstack" {
218 expect(fnWithAlignedStack() == 1234);218 try expect(fnWithAlignedStack() == 1234);
219}219}
220220
221fn fnWithAlignedStack() i32 {221fn fnWithAlignedStack() i32 {
...@@ -224,7 +224,7 @@ fn fnWithAlignedStack() i32 {...@@ -224,7 +224,7 @@ fn fnWithAlignedStack() i32 {
224}224}
225225
226test "alignment of structs" {226test "alignment of structs" {
227 expect(@alignOf(struct {227 try expect(@alignOf(struct {
228 a: i32,228 a: i32,
229 b: *i32,229 b: *i32,
230 }) == @alignOf(usize));230 }) == @alignOf(usize));
...@@ -240,37 +240,37 @@ test "alignment of function with c calling convention" {...@@ -240,37 +240,37 @@ test "alignment of function with c calling convention" {
240fn nothing() callconv(.C) void {}240fn nothing() callconv(.C) void {}
241241
242test "return error union with 128-bit integer" {242test "return error union with 128-bit integer" {
243 expect(3 == try give());243 try expect(3 == try give());
244}244}
245fn give() anyerror!u128 {245fn give() anyerror!u128 {
246 return 3;246 return 3;
247}247}
248248
249test "alignment of >= 128-bit integer type" {249test "alignment of >= 128-bit integer type" {
250 expect(@alignOf(u128) == 16);250 try expect(@alignOf(u128) == 16);
251 expect(@alignOf(u129) == 16);251 try expect(@alignOf(u129) == 16);
252}252}
253253
254test "alignment of struct with 128-bit field" {254test "alignment of struct with 128-bit field" {
255 expect(@alignOf(struct {255 try expect(@alignOf(struct {
256 x: u128,256 x: u128,
257 }) == 16);257 }) == 16);
258258
259 comptime {259 comptime {
260 expect(@alignOf(struct {260 try expect(@alignOf(struct {
261 x: u128,261 x: u128,
262 }) == 16);262 }) == 16);
263 }263 }
264}264}
265265
266test "size of extern struct with 128-bit field" {266test "size of extern struct with 128-bit field" {
267 expect(@sizeOf(extern struct {267 try expect(@sizeOf(extern struct {
268 x: u128,268 x: u128,
269 y: u8,269 y: u8,
270 }) == 32);270 }) == 32);
271271
272 comptime {272 comptime {
273 expect(@sizeOf(extern struct {273 try expect(@sizeOf(extern struct {
274 x: u128,274 x: u128,
275 y: u8,275 y: u8,
276 }) == 32);276 }) == 32);
...@@ -287,8 +287,8 @@ test "read 128-bit field from default aligned struct in stack memory" {...@@ -287,8 +287,8 @@ test "read 128-bit field from default aligned struct in stack memory" {
287 .nevermind = 1,287 .nevermind = 1,
288 .badguy = 12,288 .badguy = 12,
289 };289 };
290 expect((@ptrToInt(&default_aligned.badguy) % 16) == 0);290 try expect((@ptrToInt(&default_aligned.badguy) % 16) == 0);
291 expect(12 == default_aligned.badguy);291 try expect(12 == default_aligned.badguy);
292}292}
293293
294var default_aligned_global = DefaultAligned{294var default_aligned_global = DefaultAligned{
...@@ -297,8 +297,8 @@ var default_aligned_global = DefaultAligned{...@@ -297,8 +297,8 @@ var default_aligned_global = DefaultAligned{
297};297};
298298
299test "read 128-bit field from default aligned struct in global memory" {299test "read 128-bit field from default aligned struct in global memory" {
300 expect((@ptrToInt(&default_aligned_global.badguy) % 16) == 0);300 try expect((@ptrToInt(&default_aligned_global.badguy) % 16) == 0);
301 expect(12 == default_aligned_global.badguy);301 try expect(12 == default_aligned_global.badguy);
302}302}
303303
304test "struct field explicit alignment" {304test "struct field explicit alignment" {
...@@ -311,9 +311,9 @@ test "struct field explicit alignment" {...@@ -311,9 +311,9 @@ test "struct field explicit alignment" {
311311
312 var node: S.Node = undefined;312 var node: S.Node = undefined;
313 node.massive_byte = 100;313 node.massive_byte = 100;
314 expect(node.massive_byte == 100);314 try expect(node.massive_byte == 100);
315 comptime expect(@TypeOf(&node.massive_byte) == *align(64) u8);315 comptime try expect(@TypeOf(&node.massive_byte) == *align(64) u8);
316 expect(@ptrToInt(&node.massive_byte) % 64 == 0);316 try expect(@ptrToInt(&node.massive_byte) % 64 == 0);
317}317}
318318
319test "align(@alignOf(T)) T does not force resolution of T" {319test "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" {...@@ -335,7 +335,7 @@ test "align(@alignOf(T)) T does not force resolution of T" {
335 var ok = false;335 var ok = false;
336 };336 };
337 _ = async S.doTheTest();337 _ = async S.doTheTest();
338 expect(S.ok);338 try expect(S.ok);
339}339}
340340
341test "align(N) on functions" {341test "align(N) on functions" {
...@@ -343,7 +343,7 @@ test "align(N) on functions" {...@@ -343,7 +343,7 @@ test "align(N) on functions" {
343 if (native_arch == .wasm32 or native_arch == .wasm64) return error.SkipZigTest;343 if (native_arch == .wasm32 or native_arch == .wasm64) return error.SkipZigTest;
344 if (native_arch == .thumb) return error.SkipZigTest;344 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);
347}347}
348fn overaligned_fn() align(0x1000) i32 {348fn overaligned_fn() align(0x1000) i32 {
349 return 42;349 return 42;
test/behavior/alignof.zig+14-14
...@@ -11,29 +11,29 @@ const Foo = struct {...@@ -11,29 +11,29 @@ const Foo = struct {
11};11};
1212
13test "@alignOf(T) before referencing T" {13test "@alignOf(T) before referencing T" {
14 comptime expect(@alignOf(Foo) != maxInt(usize));14 comptime try expect(@alignOf(Foo) != maxInt(usize));
15 if (native_arch == .x86_64) {15 if (native_arch == .x86_64) {
16 comptime expect(@alignOf(Foo) == 4);16 comptime try expect(@alignOf(Foo) == 4);
17 }17 }
18}18}
1919
20test "comparison of @alignOf(T) against zero" {20test "comparison of @alignOf(T) against zero" {
21 {21 {
22 const T = struct { x: u32 };22 const T = struct { x: u32 };
23 expect(!(@alignOf(T) == 0));23 try expect(!(@alignOf(T) == 0));
24 expect(@alignOf(T) != 0);24 try expect(@alignOf(T) != 0);
25 expect(!(@alignOf(T) < 0));25 try expect(!(@alignOf(T) < 0));
26 expect(!(@alignOf(T) <= 0));26 try expect(!(@alignOf(T) <= 0));
27 expect(@alignOf(T) > 0);27 try expect(@alignOf(T) > 0);
28 expect(@alignOf(T) >= 0);28 try expect(@alignOf(T) >= 0);
29 }29 }
30 {30 {
31 const T = struct {};31 const T = struct {};
32 expect(@alignOf(T) == 0);32 try expect(@alignOf(T) == 0);
33 expect(!(@alignOf(T) != 0));33 try expect(!(@alignOf(T) != 0));
34 expect(!(@alignOf(T) < 0));34 try expect(!(@alignOf(T) < 0));
35 expect(@alignOf(T) <= 0);35 try expect(@alignOf(T) <= 0);
36 expect(!(@alignOf(T) > 0));36 try expect(!(@alignOf(T) > 0));
37 expect(@alignOf(T) >= 0);37 try expect(@alignOf(T) >= 0);
38 }38 }
39}39}
test/behavior/array.zig+141-141
...@@ -21,8 +21,8 @@ test "arrays" {...@@ -21,8 +21,8 @@ test "arrays" {
21 i += 1;21 i += 1;
22 }22 }
2323
24 expect(accumulator == 15);24 try expect(accumulator == 15);
25 expect(getArrayLen(&array) == 5);25 try expect(getArrayLen(&array) == 5);
26}26}
27fn getArrayLen(a: []const u32) usize {27fn getArrayLen(a: []const u32) usize {
28 return a.len;28 return a.len;
...@@ -30,37 +30,37 @@ fn getArrayLen(a: []const u32) usize {...@@ -30,37 +30,37 @@ fn getArrayLen(a: []const u32) usize {
3030
31test "array with sentinels" {31test "array with sentinels" {
32 const S = struct {32 const S = struct {
33 fn doTheTest(is_ct: bool) void {33 fn doTheTest(is_ct: bool) !void {
34 if (is_ct) {34 if (is_ct) {
35 var zero_sized: [0:0xde]u8 = [_:0xde]u8{};35 var zero_sized: [0:0xde]u8 = [_:0xde]u8{};
36 // Disabled at runtime because of36 // Disabled at runtime because of
37 // https://github.com/ziglang/zig/issues/437237 // https://github.com/ziglang/zig/issues/4372
38 expectEqual(@as(u8, 0xde), zero_sized[0]);38 try expectEqual(@as(u8, 0xde), zero_sized[0]);
39 var reinterpreted = @ptrCast(*[1]u8, &zero_sized);39 var reinterpreted = @ptrCast(*[1]u8, &zero_sized);
40 expectEqual(@as(u8, 0xde), reinterpreted[0]);40 try expectEqual(@as(u8, 0xde), reinterpreted[0]);
41 }41 }
42 var arr: [3:0x55]u8 = undefined;42 var arr: [3:0x55]u8 = undefined;
43 // Make sure the sentinel pointer is pointing after the last element43 // Make sure the sentinel pointer is pointing after the last element
44 if (!is_ct) {44 if (!is_ct) {
45 const sentinel_ptr = @ptrToInt(&arr[3]);45 const sentinel_ptr = @ptrToInt(&arr[3]);
46 const last_elem_ptr = @ptrToInt(&arr[2]);46 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);
48 }48 }
49 // Make sure the sentinel is writeable49 // Make sure the sentinel is writeable
50 arr[3] = 0x55;50 arr[3] = 0x55;
51 }51 }
52 };52 };
5353
54 S.doTheTest(false);54 try S.doTheTest(false);
55 comptime S.doTheTest(true);55 comptime try S.doTheTest(true);
56}56}
5757
58test "void arrays" {58test "void arrays" {
59 var array: [4]void = undefined;59 var array: [4]void = undefined;
60 array[0] = void{};60 array[0] = void{};
61 array[1] = array[2];61 array[1] = array[2];
62 expect(@sizeOf(@TypeOf(array)) == 0);62 try expect(@sizeOf(@TypeOf(array)) == 0);
63 expect(array.len == 4);63 try expect(array.len == 4);
64}64}
6565
66test "array literal" {66test "array literal" {
...@@ -71,12 +71,12 @@ test "array literal" {...@@ -71,12 +71,12 @@ test "array literal" {
71 1,71 1,
72 };72 };
7373
74 expect(hex_mult.len == 4);74 try expect(hex_mult.len == 4);
75 expect(hex_mult[1] == 256);75 try expect(hex_mult[1] == 256);
76}76}
7777
78test "array dot len const expr" {78test "array dot len const expr" {
79 expect(comptime x: {79 try expect(comptime x: {
80 break :x some_array.len == 4;80 break :x some_array.len == 4;
81 });81 });
82}82}
...@@ -100,11 +100,11 @@ test "nested arrays" {...@@ -100,11 +100,11 @@ test "nested arrays" {
100 "thing",100 "thing",
101 };101 };
102 for (array_of_strings) |s, i| {102 for (array_of_strings) |s, i| {
103 if (i == 0) expect(mem.eql(u8, s, "hello"));103 if (i == 0) try expect(mem.eql(u8, s, "hello"));
104 if (i == 1) expect(mem.eql(u8, s, "this"));104 if (i == 1) try expect(mem.eql(u8, s, "this"));
105 if (i == 2) expect(mem.eql(u8, s, "is"));105 if (i == 2) try expect(mem.eql(u8, s, "is"));
106 if (i == 3) expect(mem.eql(u8, s, "my"));106 if (i == 3) try expect(mem.eql(u8, s, "my"));
107 if (i == 4) expect(mem.eql(u8, s, "thing"));107 if (i == 4) try expect(mem.eql(u8, s, "thing"));
108 }108 }
109}109}
110110
...@@ -122,9 +122,9 @@ test "set global var array via slice embedded in struct" {...@@ -122,9 +122,9 @@ test "set global var array via slice embedded in struct" {
122 s.a[1].b = 2;122 s.a[1].b = 2;
123 s.a[2].b = 3;123 s.a[2].b = 3;
124124
125 expect(s_array[0].b == 1);125 try expect(s_array[0].b == 1);
126 expect(s_array[1].b == 2);126 try expect(s_array[1].b == 2);
127 expect(s_array[2].b == 3);127 try expect(s_array[2].b == 3);
128}128}
129129
130test "array literal with specified size" {130test "array literal with specified size" {
...@@ -132,34 +132,34 @@ test "array literal with specified size" {...@@ -132,34 +132,34 @@ test "array literal with specified size" {
132 1,132 1,
133 2,133 2,
134 };134 };
135 expect(array[0] == 1);135 try expect(array[0] == 1);
136 expect(array[1] == 2);136 try expect(array[1] == 2);
137}137}
138138
139test "array len field" {139test "array len field" {
140 var arr = [4]u8{ 0, 0, 0, 0 };140 var arr = [4]u8{ 0, 0, 0, 0 };
141 var ptr = &arr;141 var ptr = &arr;
142 expect(arr.len == 4);142 try expect(arr.len == 4);
143 comptime expect(arr.len == 4);143 comptime try expect(arr.len == 4);
144 expect(ptr.len == 4);144 try expect(ptr.len == 4);
145 comptime expect(ptr.len == 4);145 comptime try expect(ptr.len == 4);
146}146}
147147
148test "single-item pointer to array indexing and slicing" {148test "single-item pointer to array indexing and slicing" {
149 testSingleItemPtrArrayIndexSlice();149 try testSingleItemPtrArrayIndexSlice();
150 comptime testSingleItemPtrArrayIndexSlice();150 comptime try testSingleItemPtrArrayIndexSlice();
151}151}
152152
153fn testSingleItemPtrArrayIndexSlice() void {153fn testSingleItemPtrArrayIndexSlice() !void {
154 {154 {
155 var array: [4]u8 = "aaaa".*;155 var array: [4]u8 = "aaaa".*;
156 doSomeMangling(&array);156 doSomeMangling(&array);
157 expect(mem.eql(u8, "azya", &array));157 try expect(mem.eql(u8, "azya", &array));
158 }158 }
159 {159 {
160 var array = "aaaa".*;160 var array = "aaaa".*;
161 doSomeMangling(&array);161 doSomeMangling(&array);
162 expect(mem.eql(u8, "azya", &array));162 try expect(mem.eql(u8, "azya", &array));
163 }163 }
164}164}
165165
...@@ -169,15 +169,15 @@ fn doSomeMangling(array: *[4]u8) void {...@@ -169,15 +169,15 @@ fn doSomeMangling(array: *[4]u8) void {
169}169}
170170
171test "implicit cast single-item pointer" {171test "implicit cast single-item pointer" {
172 testImplicitCastSingleItemPtr();172 try testImplicitCastSingleItemPtr();
173 comptime testImplicitCastSingleItemPtr();173 comptime try testImplicitCastSingleItemPtr();
174}174}
175175
176fn testImplicitCastSingleItemPtr() void {176fn testImplicitCastSingleItemPtr() !void {
177 var byte: u8 = 100;177 var byte: u8 = 100;
178 const slice = @as(*[1]u8, &byte)[0..];178 const slice = @as(*[1]u8, &byte)[0..];
179 slice[0] += 1;179 slice[0] += 1;
180 expect(byte == 101);180 try expect(byte == 101);
181}181}
182182
183fn testArrayByValAtComptime(b: [2]u8) u8 {183fn testArrayByValAtComptime(b: [2]u8) u8 {
...@@ -192,7 +192,7 @@ test "comptime evalutating function that takes array by value" {...@@ -192,7 +192,7 @@ test "comptime evalutating function that takes array by value" {
192192
193test "implicit comptime in array type size" {193test "implicit comptime in array type size" {
194 var arr: [plusOne(10)]bool = undefined;194 var arr: [plusOne(10)]bool = undefined;
195 expect(arr.len == 11);195 try expect(arr.len == 11);
196}196}
197197
198fn plusOne(x: u32) u32 {198fn plusOne(x: u32) u32 {
...@@ -202,52 +202,52 @@ fn plusOne(x: u32) u32 {...@@ -202,52 +202,52 @@ fn plusOne(x: u32) u32 {
202test "runtime initialize array elem and then implicit cast to slice" {202test "runtime initialize array elem and then implicit cast to slice" {
203 var two: i32 = 2;203 var two: i32 = 2;
204 const x: []const i32 = &[_]i32{two};204 const x: []const i32 = &[_]i32{two};
205 expect(x[0] == 2);205 try expect(x[0] == 2);
206}206}
207207
208test "array literal as argument to function" {208test "array literal as argument to function" {
209 const S = struct {209 const S = struct {
210 fn entry(two: i32) void {210 fn entry(two: i32) !void {
211 foo(&[_]i32{211 try foo(&[_]i32{
212 1,212 1,
213 2,213 2,
214 3,214 3,
215 });215 });
216 foo(&[_]i32{216 try foo(&[_]i32{
217 1,217 1,
218 two,218 two,
219 3,219 3,
220 });220 });
221 foo2(true, &[_]i32{221 try foo2(true, &[_]i32{
222 1,222 1,
223 2,223 2,
224 3,224 3,
225 });225 });
226 foo2(true, &[_]i32{226 try foo2(true, &[_]i32{
227 1,227 1,
228 two,228 two,
229 3,229 3,
230 });230 });
231 }231 }
232 fn foo(x: []const i32) void {232 fn foo(x: []const i32) !void {
233 expect(x[0] == 1);233 try expect(x[0] == 1);
234 expect(x[1] == 2);234 try expect(x[1] == 2);
235 expect(x[2] == 3);235 try expect(x[2] == 3);
236 }236 }
237 fn foo2(trash: bool, x: []const i32) void {237 fn foo2(trash: bool, x: []const i32) !void {
238 expect(trash);238 try expect(trash);
239 expect(x[0] == 1);239 try expect(x[0] == 1);
240 expect(x[1] == 2);240 try expect(x[1] == 2);
241 expect(x[2] == 3);241 try expect(x[2] == 3);
242 }242 }
243 };243 };
244 S.entry(2);244 try S.entry(2);
245 comptime S.entry(2);245 comptime try S.entry(2);
246}246}
247247
248test "double nested array to const slice cast in array literal" {248test "double nested array to const slice cast in array literal" {
249 const S = struct {249 const S = struct {
250 fn entry(two: i32) void {250 fn entry(two: i32) !void {
251 const cases = [_][]const []const i32{251 const cases = [_][]const []const i32{
252 &[_][]const i32{&[_]i32{1}},252 &[_][]const i32{&[_]i32{1}},
253 &[_][]const i32{&[_]i32{ 2, 3 }},253 &[_][]const i32{&[_]i32{ 2, 3 }},
...@@ -256,18 +256,18 @@ test "double nested array to const slice cast in array literal" {...@@ -256,18 +256,18 @@ test "double nested array to const slice cast in array literal" {
256 &[_]i32{ 5, 6, 7 },256 &[_]i32{ 5, 6, 7 },
257 },257 },
258 };258 };
259 check(&cases);259 try check(&cases);
260260
261 const cases2 = [_][]const i32{261 const cases2 = [_][]const i32{
262 &[_]i32{1},262 &[_]i32{1},
263 &[_]i32{ two, 3 },263 &[_]i32{ two, 3 },
264 };264 };
265 expect(cases2.len == 2);265 try expect(cases2.len == 2);
266 expect(cases2[0].len == 1);266 try expect(cases2[0].len == 1);
267 expect(cases2[0][0] == 1);267 try expect(cases2[0][0] == 1);
268 expect(cases2[1].len == 2);268 try expect(cases2[1].len == 2);
269 expect(cases2[1][0] == 2);269 try expect(cases2[1][0] == 2);
270 expect(cases2[1][1] == 3);270 try expect(cases2[1][1] == 3);
271271
272 const cases3 = [_][]const []const i32{272 const cases3 = [_][]const []const i32{
273 &[_][]const i32{&[_]i32{1}},273 &[_][]const i32{&[_]i32{1}},
...@@ -277,37 +277,37 @@ test "double nested array to const slice cast in array literal" {...@@ -277,37 +277,37 @@ test "double nested array to const slice cast in array literal" {
277 &[_]i32{ 5, 6, 7 },277 &[_]i32{ 5, 6, 7 },
278 },278 },
279 };279 };
280 check(&cases3);280 try check(&cases3);
281 }281 }
282282
283 fn check(cases: []const []const []const i32) void {283 fn check(cases: []const []const []const i32) !void {
284 expect(cases.len == 3);284 try expect(cases.len == 3);
285 expect(cases[0].len == 1);285 try expect(cases[0].len == 1);
286 expect(cases[0][0].len == 1);286 try expect(cases[0][0].len == 1);
287 expect(cases[0][0][0] == 1);287 try expect(cases[0][0][0] == 1);
288 expect(cases[1].len == 1);288 try expect(cases[1].len == 1);
289 expect(cases[1][0].len == 2);289 try expect(cases[1][0].len == 2);
290 expect(cases[1][0][0] == 2);290 try expect(cases[1][0][0] == 2);
291 expect(cases[1][0][1] == 3);291 try expect(cases[1][0][1] == 3);
292 expect(cases[2].len == 2);292 try expect(cases[2].len == 2);
293 expect(cases[2][0].len == 1);293 try expect(cases[2][0].len == 1);
294 expect(cases[2][0][0] == 4);294 try expect(cases[2][0][0] == 4);
295 expect(cases[2][1].len == 3);295 try expect(cases[2][1].len == 3);
296 expect(cases[2][1][0] == 5);296 try expect(cases[2][1][0] == 5);
297 expect(cases[2][1][1] == 6);297 try expect(cases[2][1][1] == 6);
298 expect(cases[2][1][2] == 7);298 try expect(cases[2][1][2] == 7);
299 }299 }
300 };300 };
301 S.entry(2);301 try S.entry(2);
302 comptime S.entry(2);302 comptime try S.entry(2);
303}303}
304304
305test "read/write through global variable array of struct fields initialized via array mult" {305test "read/write through global variable array of struct fields initialized via array mult" {
306 const S = struct {306 const S = struct {
307 fn doTheTest() void {307 fn doTheTest() !void {
308 expect(storage[0].term == 1);308 try expect(storage[0].term == 1);
309 storage[0] = MyStruct{ .term = 123 };309 storage[0] = MyStruct{ .term = 123 };
310 expect(storage[0].term == 123);310 try expect(storage[0].term == 123);
311 }311 }
312312
313 pub const MyStruct = struct {313 pub const MyStruct = struct {
...@@ -316,34 +316,34 @@ test "read/write through global variable array of struct fields initialized via...@@ -316,34 +316,34 @@ test "read/write through global variable array of struct fields initialized via
316316
317 var storage: [1]MyStruct = [_]MyStruct{MyStruct{ .term = 1 }} ** 1;317 var storage: [1]MyStruct = [_]MyStruct{MyStruct{ .term = 1 }} ** 1;
318 };318 };
319 S.doTheTest();319 try S.doTheTest();
320}320}
321321
322test "implicit cast zero sized array ptr to slice" {322test "implicit cast zero sized array ptr to slice" {
323 {323 {
324 var b = "".*;324 var b = "".*;
325 const c: []const u8 = &b;325 const c: []const u8 = &b;
326 expect(c.len == 0);326 try expect(c.len == 0);
327 }327 }
328 {328 {
329 var b: [0]u8 = "".*;329 var b: [0]u8 = "".*;
330 const c: []const u8 = &b;330 const c: []const u8 = &b;
331 expect(c.len == 0);331 try expect(c.len == 0);
332 }332 }
333}333}
334334
335test "anonymous list literal syntax" {335test "anonymous list literal syntax" {
336 const S = struct {336 const S = struct {
337 fn doTheTest() void {337 fn doTheTest() !void {
338 var array: [4]u8 = .{ 1, 2, 3, 4 };338 var array: [4]u8 = .{ 1, 2, 3, 4 };
339 expect(array[0] == 1);339 try expect(array[0] == 1);
340 expect(array[1] == 2);340 try expect(array[1] == 2);
341 expect(array[2] == 3);341 try expect(array[2] == 3);
342 expect(array[3] == 4);342 try expect(array[3] == 4);
343 }343 }
344 };344 };
345 S.doTheTest();345 try S.doTheTest();
346 comptime S.doTheTest();346 comptime try S.doTheTest();
347}347}
348348
349test "anonymous literal in array" {349test "anonymous literal in array" {
...@@ -352,51 +352,51 @@ test "anonymous literal in array" {...@@ -352,51 +352,51 @@ test "anonymous literal in array" {
352 a: usize = 2,352 a: usize = 2,
353 b: usize = 4,353 b: usize = 4,
354 };354 };
355 fn doTheTest() void {355 fn doTheTest() !void {
356 var array: [2]Foo = .{356 var array: [2]Foo = .{
357 .{ .a = 3 },357 .{ .a = 3 },
358 .{ .b = 3 },358 .{ .b = 3 },
359 };359 };
360 expect(array[0].a == 3);360 try expect(array[0].a == 3);
361 expect(array[0].b == 4);361 try expect(array[0].b == 4);
362 expect(array[1].a == 2);362 try expect(array[1].a == 2);
363 expect(array[1].b == 3);363 try expect(array[1].b == 3);
364 }364 }
365 };365 };
366 S.doTheTest();366 try S.doTheTest();
367 comptime S.doTheTest();367 comptime try S.doTheTest();
368}368}
369369
370test "access the null element of a null terminated array" {370test "access the null element of a null terminated array" {
371 const S = struct {371 const S = struct {
372 fn doTheTest() void {372 fn doTheTest() !void {
373 var array: [4:0]u8 = .{ 'a', 'o', 'e', 'u' };373 var array: [4:0]u8 = .{ 'a', 'o', 'e', 'u' };
374 expect(array[4] == 0);374 try expect(array[4] == 0);
375 var len: usize = 4;375 var len: usize = 4;
376 expect(array[len] == 0);376 try expect(array[len] == 0);
377 }377 }
378 };378 };
379 S.doTheTest();379 try S.doTheTest();
380 comptime S.doTheTest();380 comptime try S.doTheTest();
381}381}
382382
383test "type deduction for array subscript expression" {383test "type deduction for array subscript expression" {
384 const S = struct {384 const S = struct {
385 fn doTheTest() void {385 fn doTheTest() !void {
386 var array = [_]u8{ 0x55, 0xAA };386 var array = [_]u8{ 0x55, 0xAA };
387 var v0 = true;387 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]);
389 var v1 = false;389 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]);
391 }391 }
392 };392 };
393 S.doTheTest();393 try S.doTheTest();
394 comptime S.doTheTest();394 comptime try S.doTheTest();
395}395}
396396
397test "sentinel element count towards the ABI size calculation" {397test "sentinel element count towards the ABI size calculation" {
398 const S = struct {398 const S = struct {
399 fn doTheTest() void {399 fn doTheTest() !void {
400 const T = packed struct {400 const T = packed struct {
401 fill_pre: u8 = 0x55,401 fill_pre: u8 = 0x55,
402 data: [0:0]u8 = undefined,402 data: [0:0]u8 = undefined,
...@@ -404,14 +404,14 @@ test "sentinel element count towards the ABI size calculation" {...@@ -404,14 +404,14 @@ test "sentinel element count towards the ABI size calculation" {
404 };404 };
405 var x = T{};405 var x = T{};
406 var as_slice = mem.asBytes(&x);406 var as_slice = mem.asBytes(&x);
407 expectEqual(@as(usize, 3), as_slice.len);407 try expectEqual(@as(usize, 3), as_slice.len);
408 expectEqual(@as(u8, 0x55), as_slice[0]);408 try expectEqual(@as(u8, 0x55), as_slice[0]);
409 expectEqual(@as(u8, 0xAA), as_slice[2]);409 try expectEqual(@as(u8, 0xAA), as_slice[2]);
410 }410 }
411 };411 };
412412
413 S.doTheTest();413 try S.doTheTest();
414 comptime S.doTheTest();414 comptime try S.doTheTest();
415}415}
416416
417test "zero-sized array with recursive type definition" {417test "zero-sized array with recursive type definition" {
...@@ -429,61 +429,61 @@ test "zero-sized array with recursive type definition" {...@@ -429,61 +429,61 @@ test "zero-sized array with recursive type definition" {
429 };429 };
430430
431 var t: S = .{ .list = .{ .s = undefined } };431 var t: S = .{ .list = .{ .s = undefined } };
432 expectEqual(@as(usize, 0), t.list.x);432 try expectEqual(@as(usize, 0), t.list.x);
433}433}
434434
435test "type coercion of anon struct literal to array" {435test "type coercion of anon struct literal to array" {
436 const S = struct {436 const S = struct {
437 const U = union{437 const U = union {
438 a: u32,438 a: u32,
439 b: bool,439 b: bool,
440 c: []const u8,440 c: []const u8,
441 };441 };
442442
443 fn doTheTest() void {443 fn doTheTest() !void {
444 var x1: u8 = 42;444 var x1: u8 = 42;
445 const t1 = .{ x1, 56, 54 };445 const t1 = .{ x1, 56, 54 };
446 var arr1: [3]u8 = t1;446 var arr1: [3]u8 = t1;
447 expect(arr1[0] == 42);447 try expect(arr1[0] == 42);
448 expect(arr1[1] == 56);448 try expect(arr1[1] == 56);
449 expect(arr1[2] == 54);449 try expect(arr1[2] == 54);
450 450
451 var x2: U = .{ .a = 42 };451 var x2: U = .{ .a = 42 };
452 const t2 = .{ x2, .{ .b = true }, .{ .c = "hello" } };452 const t2 = .{ x2, .{ .b = true }, .{ .c = "hello" } };
453 var arr2: [3]U = t2;453 var arr2: [3]U = t2;
454 expect(arr2[0].a == 42);454 try expect(arr2[0].a == 42);
455 expect(arr2[1].b == true);455 try expect(arr2[1].b == true);
456 expect(mem.eql(u8, arr2[2].c, "hello"));456 try expect(mem.eql(u8, arr2[2].c, "hello"));
457 }457 }
458 };458 };
459 S.doTheTest();459 try S.doTheTest();
460 comptime S.doTheTest();460 comptime try S.doTheTest();
461}461}
462462
463test "type coercion of pointer to anon struct literal to pointer to array" {463test "type coercion of pointer to anon struct literal to pointer to array" {
464 const S = struct {464 const S = struct {
465 const U = union{465 const U = union {
466 a: u32,466 a: u32,
467 b: bool,467 b: bool,
468 c: []const u8,468 c: []const u8,
469 };469 };
470470
471 fn doTheTest() void {471 fn doTheTest() !void {
472 var x1: u8 = 42;472 var x1: u8 = 42;
473 const t1 = &.{ x1, 56, 54 };473 const t1 = &.{ x1, 56, 54 };
474 var arr1: *const[3]u8 = t1;474 var arr1: *const [3]u8 = t1;
475 expect(arr1[0] == 42);475 try expect(arr1[0] == 42);
476 expect(arr1[1] == 56);476 try expect(arr1[1] == 56);
477 expect(arr1[2] == 54);477 try expect(arr1[2] == 54);
478 478
479 var x2: U = .{ .a = 42 };479 var x2: U = .{ .a = 42 };
480 const t2 = &.{ x2, .{ .b = true }, .{ .c = "hello" } };480 const t2 = &.{ x2, .{ .b = true }, .{ .c = "hello" } };
481 var arr2: *const [3]U = t2;481 var arr2: *const [3]U = t2;
482 expect(arr2[0].a == 42);482 try expect(arr2[0].a == 42);
483 expect(arr2[1].b == true);483 try expect(arr2[1].b == true);
484 expect(mem.eql(u8, arr2[2].c, "hello"));484 try expect(mem.eql(u8, arr2[2].c, "hello"));
485 }485 }
486 };486 };
487 S.doTheTest();487 try S.doTheTest();
488 comptime S.doTheTest();488 comptime try S.doTheTest();
489}489}
test/behavior/asm.zig+1-1
...@@ -15,7 +15,7 @@ comptime {...@@ -15,7 +15,7 @@ comptime {
1515
16test "module level assembly" {16test "module level assembly" {
17 if (is_x86_64_linux) {17 if (is_x86_64_linux) {
18 expect(this_is_my_alias() == 1234);18 try expect(this_is_my_alias() == 1234);
19 }19 }
20}20}
2121
test/behavior/async_fn.zig+165-165
...@@ -9,12 +9,12 @@ var global_x: i32 = 1;...@@ -9,12 +9,12 @@ var global_x: i32 = 1;
99
10test "simple coroutine suspend and resume" {10test "simple coroutine suspend and resume" {
11 var frame = async simpleAsyncFn();11 var frame = async simpleAsyncFn();
12 expect(global_x == 2);12 try expect(global_x == 2);
13 resume frame;13 resume frame;
14 expect(global_x == 3);14 try expect(global_x == 3);
15 const af: anyframe->void = &frame;15 const af: anyframe->void = &frame;
16 resume frame;16 resume frame;
17 expect(global_x == 4);17 try expect(global_x == 4);
18}18}
19fn simpleAsyncFn() void {19fn simpleAsyncFn() void {
20 global_x += 1;20 global_x += 1;
...@@ -28,9 +28,9 @@ var global_y: i32 = 1;...@@ -28,9 +28,9 @@ var global_y: i32 = 1;
2828
29test "pass parameter to coroutine" {29test "pass parameter to coroutine" {
30 var p = async simpleAsyncFnWithArg(2);30 var p = async simpleAsyncFnWithArg(2);
31 expect(global_y == 3);31 try expect(global_y == 3);
32 resume p;32 resume p;
33 expect(global_y == 5);33 try expect(global_y == 5);
34}34}
35fn simpleAsyncFnWithArg(delta: i32) void {35fn simpleAsyncFnWithArg(delta: i32) void {
36 global_y += delta;36 global_y += delta;
...@@ -42,10 +42,10 @@ test "suspend at end of function" {...@@ -42,10 +42,10 @@ test "suspend at end of function" {
42 const S = struct {42 const S = struct {
43 var x: i32 = 1;43 var x: i32 = 1;
4444
45 fn doTheTest() void {45 fn doTheTest() !void {
46 expect(x == 1);46 try expect(x == 1);
47 const p = async suspendAtEnd();47 const p = async suspendAtEnd();
48 expect(x == 2);48 try expect(x == 2);
49 }49 }
5050
51 fn suspendAtEnd() void {51 fn suspendAtEnd() void {
...@@ -53,23 +53,23 @@ test "suspend at end of function" {...@@ -53,23 +53,23 @@ test "suspend at end of function" {
53 suspend {}53 suspend {}
54 }54 }
55 };55 };
56 S.doTheTest();56 try S.doTheTest();
57}57}
5858
59test "local variable in async function" {59test "local variable in async function" {
60 const S = struct {60 const S = struct {
61 var x: i32 = 0;61 var x: i32 = 0;
6262
63 fn doTheTest() void {63 fn doTheTest() !void {
64 expect(x == 0);64 try expect(x == 0);
65 var p = async add(1, 2);65 var p = async add(1, 2);
66 expect(x == 0);66 try expect(x == 0);
67 resume p;67 resume p;
68 expect(x == 0);68 try expect(x == 0);
69 resume p;69 resume p;
70 expect(x == 0);70 try expect(x == 0);
71 resume p;71 resume p;
72 expect(x == 3);72 try expect(x == 3);
73 }73 }
7474
75 fn add(a: i32, b: i32) void {75 fn add(a: i32, b: i32) void {
...@@ -82,7 +82,7 @@ test "local variable in async function" {...@@ -82,7 +82,7 @@ test "local variable in async function" {
82 x = accum;82 x = accum;
83 }83 }
84 };84 };
85 S.doTheTest();85 try S.doTheTest();
86}86}
8787
88test "calling an inferred async function" {88test "calling an inferred async function" {
...@@ -90,11 +90,11 @@ test "calling an inferred async function" {...@@ -90,11 +90,11 @@ test "calling an inferred async function" {
90 var x: i32 = 1;90 var x: i32 = 1;
91 var other_frame: *@Frame(other) = undefined;91 var other_frame: *@Frame(other) = undefined;
9292
93 fn doTheTest() void {93 fn doTheTest() !void {
94 _ = async first();94 _ = async first();
95 expect(x == 1);95 try expect(x == 1);
96 resume other_frame.*;96 resume other_frame.*;
97 expect(x == 2);97 try expect(x == 2);
98 }98 }
9999
100 fn first() void {100 fn first() void {
...@@ -106,7 +106,7 @@ test "calling an inferred async function" {...@@ -106,7 +106,7 @@ test "calling an inferred async function" {
106 x += 1;106 x += 1;
107 }107 }
108 };108 };
109 S.doTheTest();109 try S.doTheTest();
110}110}
111111
112test "@frameSize" {112test "@frameSize" {
...@@ -114,16 +114,16 @@ test "@frameSize" {...@@ -114,16 +114,16 @@ test "@frameSize" {
114 return error.SkipZigTest;114 return error.SkipZigTest;
115115
116 const S = struct {116 const S = struct {
117 fn doTheTest() void {117 fn doTheTest() !void {
118 {118 {
119 var ptr = @ptrCast(fn (i32) callconv(.Async) void, other);119 var ptr = @ptrCast(fn (i32) callconv(.Async) void, other);
120 const size = @frameSize(ptr);120 const size = @frameSize(ptr);
121 expect(size == @sizeOf(@Frame(other)));121 try expect(size == @sizeOf(@Frame(other)));
122 }122 }
123 {123 {
124 var ptr = @ptrCast(fn () callconv(.Async) void, first);124 var ptr = @ptrCast(fn () callconv(.Async) void, first);
125 const size = @frameSize(ptr);125 const size = @frameSize(ptr);
126 expect(size == @sizeOf(@Frame(first)));126 try expect(size == @sizeOf(@Frame(first)));
127 }127 }
128 }128 }
129129
...@@ -135,20 +135,20 @@ test "@frameSize" {...@@ -135,20 +135,20 @@ test "@frameSize" {
135 suspend {}135 suspend {}
136 }136 }
137 };137 };
138 S.doTheTest();138 try S.doTheTest();
139}139}
140140
141test "coroutine suspend, resume" {141test "coroutine suspend, resume" {
142 const S = struct {142 const S = struct {
143 var frame: anyframe = undefined;143 var frame: anyframe = undefined;
144144
145 fn doTheTest() void {145 fn doTheTest() !void {
146 _ = async amain();146 _ = async amain();
147 seq('d');147 seq('d');
148 resume frame;148 resume frame;
149 seq('h');149 seq('h');
150150
151 expect(std.mem.eql(u8, &points, "abcdefgh"));151 try expect(std.mem.eql(u8, &points, "abcdefgh"));
152 }152 }
153153
154 fn amain() void {154 fn amain() void {
...@@ -176,27 +176,27 @@ test "coroutine suspend, resume" {...@@ -176,27 +176,27 @@ test "coroutine suspend, resume" {
176 index += 1;176 index += 1;
177 }177 }
178 };178 };
179 S.doTheTest();179 try S.doTheTest();
180}180}
181181
182test "coroutine suspend with block" {182test "coroutine suspend with block" {
183 const p = async testSuspendBlock();183 const p = async testSuspendBlock();
184 expect(!global_result);184 try expect(!global_result);
185 resume a_promise;185 resume a_promise;
186 expect(global_result);186 try expect(global_result);
187}187}
188188
189var a_promise: anyframe = undefined;189var a_promise: anyframe = undefined;
190var global_result = false;190var global_result = false;
191fn testSuspendBlock() callconv(.Async) void {191fn testSuspendBlock() callconv(.Async) void {
192 suspend {192 suspend {
193 comptime expect(@TypeOf(@frame()) == *@Frame(testSuspendBlock));193 comptime expect(@TypeOf(@frame()) == *@Frame(testSuspendBlock)) catch unreachable;
194 a_promise = @frame();194 a_promise = @frame();
195 }195 }
196196
197 // Test to make sure that @frame() works as advertised (issue #1296)197 // Test to make sure that @frame() works as advertised (issue #1296)
198 // var our_handle: anyframe = @frame();198 // var our_handle: anyframe = @frame();
199 expect(a_promise == @as(anyframe, @frame()));199 expect(a_promise == @as(anyframe, @frame())) catch @panic("test failed");
200200
201 global_result = true;201 global_result = true;
202}202}
...@@ -210,8 +210,8 @@ test "coroutine await" {...@@ -210,8 +210,8 @@ test "coroutine await" {
210 await_seq('f');210 await_seq('f');
211 resume await_a_promise;211 resume await_a_promise;
212 await_seq('i');212 await_seq('i');
213 expect(await_final_result == 1234);213 try expect(await_final_result == 1234);
214 expect(std.mem.eql(u8, &await_points, "abcdefghi"));214 try expect(std.mem.eql(u8, &await_points, "abcdefghi"));
215}215}
216fn await_amain() callconv(.Async) void {216fn await_amain() callconv(.Async) void {
217 await_seq('b');217 await_seq('b');
...@@ -244,8 +244,8 @@ test "coroutine await early return" {...@@ -244,8 +244,8 @@ test "coroutine await early return" {
244 early_seq('a');244 early_seq('a');
245 var p = async early_amain();245 var p = async early_amain();
246 early_seq('f');246 early_seq('f');
247 expect(early_final_result == 1234);247 try expect(early_final_result == 1234);
248 expect(std.mem.eql(u8, &early_points, "abcdef"));248 try expect(std.mem.eql(u8, &early_points, "abcdef"));
249}249}
250fn early_amain() callconv(.Async) void {250fn early_amain() callconv(.Async) void {
251 early_seq('b');251 early_seq('b');
...@@ -276,7 +276,7 @@ test "async function with dot syntax" {...@@ -276,7 +276,7 @@ test "async function with dot syntax" {
276 }276 }
277 };277 };
278 const p = async S.foo();278 const p = async S.foo();
279 expect(S.y == 2);279 try expect(S.y == 2);
280}280}
281281
282test "async fn pointer in a struct field" {282test "async fn pointer in a struct field" {
...@@ -287,12 +287,12 @@ test "async fn pointer in a struct field" {...@@ -287,12 +287,12 @@ test "async fn pointer in a struct field" {
287 var foo = Foo{ .bar = simpleAsyncFn2 };287 var foo = Foo{ .bar = simpleAsyncFn2 };
288 var bytes: [64]u8 align(16) = undefined;288 var bytes: [64]u8 align(16) = undefined;
289 const f = @asyncCall(&bytes, {}, foo.bar, .{&data});289 const f = @asyncCall(&bytes, {}, foo.bar, .{&data});
290 comptime expect(@TypeOf(f) == anyframe->void);290 comptime try expect(@TypeOf(f) == anyframe->void);
291 expect(data == 2);291 try expect(data == 2);
292 resume f;292 resume f;
293 expect(data == 4);293 try expect(data == 4);
294 _ = async doTheAwait(f);294 _ = async doTheAwait(f);
295 expect(data == 4);295 try expect(data == 4);
296}296}
297297
298fn doTheAwait(f: anyframe->void) void {298fn doTheAwait(f: anyframe->void) void {
...@@ -323,22 +323,22 @@ test "@asyncCall with return type" {...@@ -323,22 +323,22 @@ test "@asyncCall with return type" {
323 var bytes: [150]u8 align(16) = undefined;323 var bytes: [150]u8 align(16) = undefined;
324 var aresult: i32 = 0;324 var aresult: i32 = 0;
325 _ = @asyncCall(&bytes, &aresult, foo.bar, .{});325 _ = @asyncCall(&bytes, &aresult, foo.bar, .{});
326 expect(aresult == 0);326 try expect(aresult == 0);
327 resume Foo.global_frame;327 resume Foo.global_frame;
328 expect(aresult == 1234);328 try expect(aresult == 1234);
329}329}
330330
331test "async fn with inferred error set" {331test "async fn with inferred error set" {
332 const S = struct {332 const S = struct {
333 var global_frame: anyframe = undefined;333 var global_frame: anyframe = undefined;
334334
335 fn doTheTest() void {335 fn doTheTest() !void {
336 var frame: [1]@Frame(middle) = undefined;336 var frame: [1]@Frame(middle) = undefined;
337 var fn_ptr = middle;337 var fn_ptr = middle;
338 var result: @typeInfo(@typeInfo(@TypeOf(fn_ptr)).Fn.return_type.?).ErrorUnion.error_set!void = undefined;338 var result: @typeInfo(@typeInfo(@TypeOf(fn_ptr)).Fn.return_type.?).ErrorUnion.error_set!void = undefined;
339 _ = @asyncCall(std.mem.sliceAsBytes(frame[0..]), &result, fn_ptr, .{});339 _ = @asyncCall(std.mem.sliceAsBytes(frame[0..]), &result, fn_ptr, .{});
340 resume global_frame;340 resume global_frame;
341 std.testing.expectError(error.Fail, result);341 try std.testing.expectError(error.Fail, result);
342 }342 }
343 fn middle() callconv(.Async) !void {343 fn middle() callconv(.Async) !void {
344 var f = async middle2();344 var f = async middle2();
...@@ -355,7 +355,7 @@ test "async fn with inferred error set" {...@@ -355,7 +355,7 @@ test "async fn with inferred error set" {
355 return error.Fail;355 return error.Fail;
356 }356 }
357 };357 };
358 S.doTheTest();358 try S.doTheTest();
359}359}
360360
361test "error return trace across suspend points - early return" {361test "error return trace across suspend points - early return" {
...@@ -383,9 +383,9 @@ fn suspendThenFail() callconv(.Async) anyerror!void {...@@ -383,9 +383,9 @@ fn suspendThenFail() callconv(.Async) anyerror!void {
383}383}
384fn printTrace(p: anyframe->(anyerror!void)) callconv(.Async) void {384fn printTrace(p: anyframe->(anyerror!void)) callconv(.Async) void {
385 (await p) catch |e| {385 (await p) catch |e| {
386 std.testing.expect(e == error.Fail);386 std.testing.expect(e == error.Fail) catch @panic("test failure");
387 if (@errorReturnTrace()) |trace| {387 if (@errorReturnTrace()) |trace| {
388 expect(trace.index == 1);388 expect(trace.index == 1) catch @panic("test failure");
389 } else switch (builtin.mode) {389 } else switch (builtin.mode) {
390 .Debug, .ReleaseSafe => @panic("expected return trace"),390 .Debug, .ReleaseSafe => @panic("expected return trace"),
391 .ReleaseFast, .ReleaseSmall => {},391 .ReleaseFast, .ReleaseSmall => {},
...@@ -396,7 +396,7 @@ fn printTrace(p: anyframe->(anyerror!void)) callconv(.Async) void {...@@ -396,7 +396,7 @@ fn printTrace(p: anyframe->(anyerror!void)) callconv(.Async) void {
396test "break from suspend" {396test "break from suspend" {
397 var my_result: i32 = 1;397 var my_result: i32 = 1;
398 const p = async testBreakFromSuspend(&my_result);398 const p = async testBreakFromSuspend(&my_result);
399 std.testing.expect(my_result == 2);399 try std.testing.expect(my_result == 2);
400}400}
401fn testBreakFromSuspend(my_result: *i32) callconv(.Async) void {401fn testBreakFromSuspend(my_result: *i32) callconv(.Async) void {
402 suspend {402 suspend {
...@@ -415,11 +415,11 @@ test "heap allocated async function frame" {...@@ -415,11 +415,11 @@ test "heap allocated async function frame" {
415 const frame = try std.testing.allocator.create(@Frame(someFunc));415 const frame = try std.testing.allocator.create(@Frame(someFunc));
416 defer std.testing.allocator.destroy(frame);416 defer std.testing.allocator.destroy(frame);
417417
418 expect(x == 42);418 try expect(x == 42);
419 frame.* = async someFunc();419 frame.* = async someFunc();
420 expect(x == 43);420 try expect(x == 43);
421 resume frame;421 resume frame;
422 expect(x == 44);422 try expect(x == 44);
423 }423 }
424424
425 fn someFunc() void {425 fn someFunc() void {
...@@ -436,15 +436,15 @@ test "async function call return value" {...@@ -436,15 +436,15 @@ test "async function call return value" {
436 var frame: anyframe = undefined;436 var frame: anyframe = undefined;
437 var pt = Point{ .x = 10, .y = 11 };437 var pt = Point{ .x = 10, .y = 11 };
438438
439 fn doTheTest() void {439 fn doTheTest() !void {
440 expectEqual(pt.x, 10);440 try expectEqual(pt.x, 10);
441 expectEqual(pt.y, 11);441 try expectEqual(pt.y, 11);
442 _ = async first();442 _ = async first();
443 expectEqual(pt.x, 10);443 try expectEqual(pt.x, 10);
444 expectEqual(pt.y, 11);444 try expectEqual(pt.y, 11);
445 resume frame;445 resume frame;
446 expectEqual(pt.x, 1);446 try expectEqual(pt.x, 1);
447 expectEqual(pt.y, 2);447 try expectEqual(pt.y, 2);
448 }448 }
449449
450 fn first() void {450 fn first() void {
...@@ -469,23 +469,23 @@ test "async function call return value" {...@@ -469,23 +469,23 @@ test "async function call return value" {
469 y: i32,469 y: i32,
470 };470 };
471 };471 };
472 S.doTheTest();472 try S.doTheTest();
473}473}
474474
475test "suspension points inside branching control flow" {475test "suspension points inside branching control flow" {
476 const S = struct {476 const S = struct {
477 var result: i32 = 10;477 var result: i32 = 10;
478478
479 fn doTheTest() void {479 fn doTheTest() !void {
480 expect(10 == result);480 try expect(10 == result);
481 var frame = async func(true);481 var frame = async func(true);
482 expect(10 == result);482 try expect(10 == result);
483 resume frame;483 resume frame;
484 expect(11 == result);484 try expect(11 == result);
485 resume frame;485 resume frame;
486 expect(12 == result);486 try expect(12 == result);
487 resume frame;487 resume frame;
488 expect(13 == result);488 try expect(13 == result);
489 }489 }
490490
491 fn func(b: bool) void {491 fn func(b: bool) void {
...@@ -495,7 +495,7 @@ test "suspension points inside branching control flow" {...@@ -495,7 +495,7 @@ test "suspension points inside branching control flow" {
495 }495 }
496 }496 }
497 };497 };
498 S.doTheTest();498 try S.doTheTest();
499}499}
500500
501test "call async function which has struct return type" {501test "call async function which has struct return type" {
...@@ -509,8 +509,8 @@ test "call async function which has struct return type" {...@@ -509,8 +509,8 @@ test "call async function which has struct return type" {
509509
510 fn atest() void {510 fn atest() void {
511 const result = func();511 const result = func();
512 expect(result.x == 5);512 expect(result.x == 5) catch @panic("test failed");
513 expect(result.y == 6);513 expect(result.y == 6) catch @panic("test failed");
514 }514 }
515515
516 const Point = struct {516 const Point = struct {
...@@ -536,27 +536,27 @@ test "pass string literal to async function" {...@@ -536,27 +536,27 @@ test "pass string literal to async function" {
536 var frame: anyframe = undefined;536 var frame: anyframe = undefined;
537 var ok: bool = false;537 var ok: bool = false;
538538
539 fn doTheTest() void {539 fn doTheTest() !void {
540 _ = async hello("hello");540 _ = async hello("hello");
541 resume frame;541 resume frame;
542 expect(ok);542 try expect(ok);
543 }543 }
544544
545 fn hello(msg: []const u8) void {545 fn hello(msg: []const u8) void {
546 frame = @frame();546 frame = @frame();
547 suspend {}547 suspend {}
548 expectEqualStrings("hello", msg);548 expectEqualStrings("hello", msg) catch @panic("test failed");
549 ok = true;549 ok = true;
550 }550 }
551 };551 };
552 S.doTheTest();552 try S.doTheTest();
553}553}
554554
555test "await inside an errdefer" {555test "await inside an errdefer" {
556 const S = struct {556 const S = struct {
557 var frame: anyframe = undefined;557 var frame: anyframe = undefined;
558558
559 fn doTheTest() void {559 fn doTheTest() !void {
560 _ = async amainWrap();560 _ = async amainWrap();
561 resume frame;561 resume frame;
562 }562 }
...@@ -572,7 +572,7 @@ test "await inside an errdefer" {...@@ -572,7 +572,7 @@ test "await inside an errdefer" {
572 suspend {}572 suspend {}
573 }573 }
574 };574 };
575 S.doTheTest();575 try S.doTheTest();
576}576}
577577
578test "try in an async function with error union and non-zero-bit payload" {578test "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" {...@@ -580,14 +580,14 @@ test "try in an async function with error union and non-zero-bit payload" {
580 var frame: anyframe = undefined;580 var frame: anyframe = undefined;
581 var ok = false;581 var ok = false;
582582
583 fn doTheTest() void {583 fn doTheTest() !void {
584 _ = async amain();584 _ = async amain();
585 resume frame;585 resume frame;
586 expect(ok);586 try expect(ok);
587 }587 }
588588
589 fn amain() void {589 fn amain() void {
590 std.testing.expectError(error.Bad, theProblem());590 std.testing.expectError(error.Bad, theProblem()) catch @panic("test failed");
591 ok = true;591 ok = true;
592 }592 }
593593
...@@ -602,7 +602,7 @@ test "try in an async function with error union and non-zero-bit payload" {...@@ -602,7 +602,7 @@ test "try in an async function with error union and non-zero-bit payload" {
602 return error.Bad;602 return error.Bad;
603 }603 }
604 };604 };
605 S.doTheTest();605 try S.doTheTest();
606}606}
607607
608test "returning a const error from async function" {608test "returning a const error from async function" {
...@@ -610,10 +610,10 @@ test "returning a const error from async function" {...@@ -610,10 +610,10 @@ test "returning a const error from async function" {
610 var frame: anyframe = undefined;610 var frame: anyframe = undefined;
611 var ok = false;611 var ok = false;
612612
613 fn doTheTest() void {613 fn doTheTest() !void {
614 _ = async amain();614 _ = async amain();
615 resume frame;615 resume frame;
616 expect(ok);616 try expect(ok);
617 }617 }
618618
619 fn amain() !void {619 fn amain() !void {
...@@ -630,7 +630,7 @@ test "returning a const error from async function" {...@@ -630,7 +630,7 @@ test "returning a const error from async function" {
630 return error.OutOfMemory;630 return error.OutOfMemory;
631 }631 }
632 };632 };
633 S.doTheTest();633 try S.doTheTest();
634}634}
635635
636test "async/await typical usage" {636test "async/await typical usage" {
...@@ -663,11 +663,11 @@ fn testAsyncAwaitTypicalUsage(...@@ -663,11 +663,11 @@ fn testAsyncAwaitTypicalUsage(
663 }663 }
664 fn amainWrap() void {664 fn amainWrap() void {
665 if (amain()) |_| {665 if (amain()) |_| {
666 expect(!simulate_fail_download);666 expect(!simulate_fail_download) catch @panic("test failure");
667 expect(!simulate_fail_file);667 expect(!simulate_fail_file) catch @panic("test failure");
668 } else |e| switch (e) {668 } else |e| switch (e) {
669 error.NoResponse => expect(simulate_fail_download),669 error.NoResponse => expect(simulate_fail_download) catch @panic("test failure"),
670 error.FileNotFound => expect(simulate_fail_file),670 error.FileNotFound => expect(simulate_fail_file) catch @panic("test failure"),
671 else => @panic("test failure"),671 else => @panic("test failure"),
672 }672 }
673 }673 }
...@@ -694,8 +694,8 @@ fn testAsyncAwaitTypicalUsage(...@@ -694,8 +694,8 @@ fn testAsyncAwaitTypicalUsage(
694 const file_text = try await file_frame;694 const file_text = try await file_frame;
695 defer allocator.free(file_text);695 defer allocator.free(file_text);
696696
697 expect(std.mem.eql(u8, "expected download text", download_text));697 try expect(std.mem.eql(u8, "expected download text", download_text));
698 expect(std.mem.eql(u8, "expected file text", file_text));698 try expect(std.mem.eql(u8, "expected file text", file_text));
699 }699 }
700700
701 var global_download_frame: anyframe = undefined;701 var global_download_frame: anyframe = undefined;
...@@ -728,13 +728,13 @@ fn testAsyncAwaitTypicalUsage(...@@ -728,13 +728,13 @@ fn testAsyncAwaitTypicalUsage(
728728
729test "alignment of local variables in async functions" {729test "alignment of local variables in async functions" {
730 const S = struct {730 const S = struct {
731 fn doTheTest() void {731 fn doTheTest() !void {
732 var y: u8 = 123;732 var y: u8 = 123;
733 var x: u8 align(128) = 1;733 var x: u8 align(128) = 1;
734 expect(@ptrToInt(&x) % 128 == 0);734 try expect(@ptrToInt(&x) % 128 == 0);
735 }735 }
736 };736 };
737 S.doTheTest();737 try S.doTheTest();
738}738}
739739
740test "no reason to resolve frame still works" {740test "no reason to resolve frame still works" {
...@@ -746,10 +746,10 @@ fn simpleNothing() void {...@@ -746,10 +746,10 @@ fn simpleNothing() void {
746746
747test "async call a generic function" {747test "async call a generic function" {
748 const S = struct {748 const S = struct {
749 fn doTheTest() void {749 fn doTheTest() !void {
750 var f = async func(i32, 2);750 var f = async func(i32, 2);
751 const result = await f;751 const result = await f;
752 expect(result == 3);752 try expect(result == 3);
753 }753 }
754754
755 fn func(comptime T: type, inc: T) T {755 fn func(comptime T: type, inc: T) T {
...@@ -766,8 +766,8 @@ test "async call a generic function" {...@@ -766,8 +766,8 @@ test "async call a generic function" {
766766
767test "return from suspend block" {767test "return from suspend block" {
768 const S = struct {768 const S = struct {
769 fn doTheTest() void {769 fn doTheTest() !void {
770 expect(func() == 1234);770 expect(func() == 1234) catch @panic("test failure");
771 }771 }
772 fn func() i32 {772 fn func() i32 {
773 suspend {773 suspend {
...@@ -808,7 +808,7 @@ test "struct parameter to async function is copied to the frame" {...@@ -808,7 +808,7 @@ test "struct parameter to async function is copied to the frame" {
808 var pt = Point{ .x = 1, .y = 2 };808 var pt = Point{ .x = 1, .y = 2 };
809 f.* = async foo(pt);809 f.* = async foo(pt);
810 var result = await f;810 var result = await f;
811 expect(result == 1);811 expect(result == 1) catch @panic("test failure");
812 }812 }
813813
814 fn foo(point: Point) i32 {814 fn foo(point: Point) i32 {
...@@ -833,7 +833,7 @@ test "cast fn to async fn when it is inferred to be async" {...@@ -833,7 +833,7 @@ test "cast fn to async fn when it is inferred to be async" {
833 var result: i32 = undefined;833 var result: i32 = undefined;
834 const f = @asyncCall(&buf, &result, ptr, .{});834 const f = @asyncCall(&buf, &result, ptr, .{});
835 _ = await f;835 _ = await f;
836 expect(result == 1234);836 expect(result == 1234) catch @panic("test failure");
837 ok = true;837 ok = true;
838 }838 }
839839
...@@ -846,7 +846,7 @@ test "cast fn to async fn when it is inferred to be async" {...@@ -846,7 +846,7 @@ test "cast fn to async fn when it is inferred to be async" {
846 };846 };
847 _ = async S.doTheTest();847 _ = async S.doTheTest();
848 resume S.frame;848 resume S.frame;
849 expect(S.ok);849 try expect(S.ok);
850}850}
851851
852test "cast fn to async fn when it is inferred to be async, awaited directly" {852test "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" {...@@ -860,7 +860,7 @@ test "cast fn to async fn when it is inferred to be async, awaited directly" {
860 var buf: [100]u8 align(16) = undefined;860 var buf: [100]u8 align(16) = undefined;
861 var result: i32 = undefined;861 var result: i32 = undefined;
862 _ = await @asyncCall(&buf, &result, ptr, .{});862 _ = await @asyncCall(&buf, &result, ptr, .{});
863 expect(result == 1234);863 expect(result == 1234) catch @panic("test failure");
864 ok = true;864 ok = true;
865 }865 }
866866
...@@ -873,7 +873,7 @@ test "cast fn to async fn when it is inferred to be async, awaited directly" {...@@ -873,7 +873,7 @@ test "cast fn to async fn when it is inferred to be async, awaited directly" {
873 };873 };
874 _ = async S.doTheTest();874 _ = async S.doTheTest();
875 resume S.frame;875 resume S.frame;
876 expect(S.ok);876 try expect(S.ok);
877}877}
878878
879test "await does not force async if callee is blocking" {879test "await does not force async if callee is blocking" {
...@@ -883,12 +883,12 @@ test "await does not force async if callee is blocking" {...@@ -883,12 +883,12 @@ test "await does not force async if callee is blocking" {
883 }883 }
884 };884 };
885 var x = async S.simple();885 var x = async S.simple();
886 expect(await x == 1234);886 try expect(await x == 1234);
887}887}
888888
889test "recursive async function" {889test "recursive async function" {
890 expect(recursiveAsyncFunctionTest(false).doTheTest() == 55);890 try expect(recursiveAsyncFunctionTest(false).doTheTest() == 55);
891 expect(recursiveAsyncFunctionTest(true).doTheTest() == 55);891 try expect(recursiveAsyncFunctionTest(true).doTheTest() == 55);
892}892}
893893
894fn recursiveAsyncFunctionTest(comptime suspending_implementation: bool) type {894fn recursiveAsyncFunctionTest(comptime suspending_implementation: bool) type {
...@@ -952,12 +952,12 @@ test "@asyncCall with comptime-known function, but not awaited directly" {...@@ -952,12 +952,12 @@ test "@asyncCall with comptime-known function, but not awaited directly" {
952 const S = struct {952 const S = struct {
953 var global_frame: anyframe = undefined;953 var global_frame: anyframe = undefined;
954954
955 fn doTheTest() void {955 fn doTheTest() !void {
956 var frame: [1]@Frame(middle) = undefined;956 var frame: [1]@Frame(middle) = undefined;
957 var result: @typeInfo(@typeInfo(@TypeOf(middle)).Fn.return_type.?).ErrorUnion.error_set!void = undefined;957 var result: @typeInfo(@typeInfo(@TypeOf(middle)).Fn.return_type.?).ErrorUnion.error_set!void = undefined;
958 _ = @asyncCall(std.mem.sliceAsBytes(frame[0..]), &result, middle, .{});958 _ = @asyncCall(std.mem.sliceAsBytes(frame[0..]), &result, middle, .{});
959 resume global_frame;959 resume global_frame;
960 std.testing.expectError(error.Fail, result);960 try std.testing.expectError(error.Fail, result);
961 }961 }
962 fn middle() callconv(.Async) !void {962 fn middle() callconv(.Async) !void {
963 var f = async middle2();963 var f = async middle2();
...@@ -974,7 +974,7 @@ test "@asyncCall with comptime-known function, but not awaited directly" {...@@ -974,7 +974,7 @@ test "@asyncCall with comptime-known function, but not awaited directly" {
974 return error.Fail;974 return error.Fail;
975 }975 }
976 };976 };
977 S.doTheTest();977 try S.doTheTest();
978}978}
979979
980test "@asyncCall with actual frame instead of byte buffer" {980test "@asyncCall with actual frame instead of byte buffer" {
...@@ -988,7 +988,7 @@ test "@asyncCall with actual frame instead of byte buffer" {...@@ -988,7 +988,7 @@ test "@asyncCall with actual frame instead of byte buffer" {
988 var result: i32 = undefined;988 var result: i32 = undefined;
989 const ptr = @asyncCall(&frame, &result, S.func, .{});989 const ptr = @asyncCall(&frame, &result, S.func, .{});
990 resume ptr;990 resume ptr;
991 expect(result == 1234);991 try expect(result == 1234);
992}992}
993993
994test "@asyncCall using the result location inside the frame" {994test "@asyncCall using the result location inside the frame" {
...@@ -1010,19 +1010,19 @@ test "@asyncCall using the result location inside the frame" {...@@ -1010,19 +1010,19 @@ test "@asyncCall using the result location inside the frame" {
1010 var foo = Foo{ .bar = S.simple2 };1010 var foo = Foo{ .bar = S.simple2 };
1011 var bytes: [64]u8 align(16) = undefined;1011 var bytes: [64]u8 align(16) = undefined;
1012 const f = @asyncCall(&bytes, {}, foo.bar, .{&data});1012 const f = @asyncCall(&bytes, {}, foo.bar, .{&data});
1013 comptime expect(@TypeOf(f) == anyframe->i32);1013 comptime try expect(@TypeOf(f) == anyframe->i32);
1014 expect(data == 2);1014 try expect(data == 2);
1015 resume f;1015 resume f;
1016 expect(data == 4);1016 try expect(data == 4);
1017 _ = async S.getAnswer(f, &data);1017 _ = async S.getAnswer(f, &data);
1018 expect(data == 1234);1018 try expect(data == 1234);
1019}1019}
10201020
1021test "@TypeOf an async function call of generic fn with error union type" {1021test "@TypeOf an async function call of generic fn with error union type" {
1022 const S = struct {1022 const S = struct {
1023 fn func(comptime x: anytype) anyerror!i32 {1023 fn func(comptime x: anytype) anyerror!i32 {
1024 const T = @TypeOf(async func(x));1024 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);
1026 return undefined;1026 return undefined;
1027 }1027 }
1028 };1028 };
...@@ -1051,7 +1051,7 @@ test "using @TypeOf on a generic function call" {...@@ -1051,7 +1051,7 @@ test "using @TypeOf on a generic function call" {
1051 };1051 };
1052 _ = async S.amain(@as(u32, 1));1052 _ = async S.amain(@as(u32, 1));
1053 resume S.global_frame;1053 resume S.global_frame;
1054 expect(S.global_ok);1054 try expect(S.global_ok);
1055}1055}
10561056
1057test "recursive call of await @asyncCall with struct return type" {1057test "recursive call of await @asyncCall with struct return type" {
...@@ -1084,17 +1084,17 @@ test "recursive call of await @asyncCall with struct return type" {...@@ -1084,17 +1084,17 @@ test "recursive call of await @asyncCall with struct return type" {
1084 var frame: @TypeOf(async S.amain(@as(u32, 1))) = undefined;1084 var frame: @TypeOf(async S.amain(@as(u32, 1))) = undefined;
1085 _ = @asyncCall(&frame, &res, S.amain, .{@as(u32, 1)});1085 _ = @asyncCall(&frame, &res, S.amain, .{@as(u32, 1)});
1086 resume S.global_frame;1086 resume S.global_frame;
1087 expect(S.global_ok);1087 try expect(S.global_ok);
1088 expect(res.x == 1);1088 try expect(res.x == 1);
1089 expect(res.y == 2);1089 try expect(res.y == 2);
1090 expect(res.z == 3);1090 try expect(res.z == 3);
1091}1091}
10921092
1093test "nosuspend function call" {1093test "nosuspend function call" {
1094 const S = struct {1094 const S = struct {
1095 fn doTheTest() void {1095 fn doTheTest() !void {
1096 const result = nosuspend add(50, 100);1096 const result = nosuspend add(50, 100);
1097 expect(result == 150);1097 try expect(result == 150);
1098 }1098 }
1099 fn add(a: i32, b: i32) i32 {1099 fn add(a: i32, b: i32) i32 {
1100 if (a > 100) {1100 if (a > 100) {
...@@ -1103,7 +1103,7 @@ test "nosuspend function call" {...@@ -1103,7 +1103,7 @@ test "nosuspend function call" {
1103 return a + b;1103 return a + b;
1104 }1104 }
1105 };1105 };
1106 S.doTheTest();1106 try S.doTheTest();
1107}1107}
11081108
1109test "await used in expression and awaiting fn with no suspend but async calling convention" {1109test "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...@@ -1113,7 +1113,7 @@ test "await used in expression and awaiting fn with no suspend but async calling
1113 var f2 = async add(3, 4);1113 var f2 = async add(3, 4);
11141114
1115 const sum = (await f1) + (await f2);1115 const sum = (await f1) + (await f2);
1116 expect(sum == 10);1116 expect(sum == 10) catch @panic("test failure");
1117 }1117 }
1118 fn add(a: i32, b: i32) callconv(.Async) i32 {1118 fn add(a: i32, b: i32) callconv(.Async) i32 {
1119 return a + b;1119 return a + b;
...@@ -1128,7 +1128,7 @@ test "await used in expression after a fn call" {...@@ -1128,7 +1128,7 @@ test "await used in expression after a fn call" {
1128 var f1 = async add(3, 4);1128 var f1 = async add(3, 4);
1129 var sum: i32 = 0;1129 var sum: i32 = 0;
1130 sum = foo() + await f1;1130 sum = foo() + await f1;
1131 expect(sum == 8);1131 expect(sum == 8) catch @panic("test failure");
1132 }1132 }
1133 fn add(a: i32, b: i32) callconv(.Async) i32 {1133 fn add(a: i32, b: i32) callconv(.Async) i32 {
1134 return a + b;1134 return a + b;
...@@ -1145,7 +1145,7 @@ test "async fn call used in expression after a fn call" {...@@ -1145,7 +1145,7 @@ test "async fn call used in expression after a fn call" {
1145 fn atest() void {1145 fn atest() void {
1146 var sum: i32 = 0;1146 var sum: i32 = 0;
1147 sum = foo() + add(3, 4);1147 sum = foo() + add(3, 4);
1148 expect(sum == 8);1148 expect(sum == 8) catch @panic("test failure");
1149 }1149 }
1150 fn add(a: i32, b: i32) callconv(.Async) i32 {1150 fn add(a: i32, b: i32) callconv(.Async) i32 {
1151 return a + b;1151 return a + b;
...@@ -1167,7 +1167,7 @@ test "suspend in for loop" {...@@ -1167,7 +1167,7 @@ test "suspend in for loop" {
1167 }1167 }
11681168
1169 fn atest() void {1169 fn atest() void {
1170 expect(func(&[_]u8{ 1, 2, 3 }) == 6);1170 expect(func(&[_]u8{ 1, 2, 3 }) == 6) catch @panic("test failure");
1171 }1171 }
1172 fn func(stuff: []const u8) u32 {1172 fn func(stuff: []const u8) u32 {
1173 global_frame = @frame();1173 global_frame = @frame();
...@@ -1193,8 +1193,8 @@ test "suspend in while loop" {...@@ -1193,8 +1193,8 @@ test "suspend in while loop" {
1193 }1193 }
11941194
1195 fn atest() void {1195 fn atest() void {
1196 expect(optional(6) == 6);1196 expect(optional(6) == 6) catch @panic("test failure");
1197 expect(errunion(6) == 6);1197 expect(errunion(6) == 6) catch @panic("test failure");
1198 }1198 }
1199 fn optional(stuff: ?u32) u32 {1199 fn optional(stuff: ?u32) u32 {
1200 global_frame = @frame();1200 global_frame = @frame();
...@@ -1223,8 +1223,8 @@ test "correctly spill when returning the error union result of another async fn"...@@ -1223,8 +1223,8 @@ test "correctly spill when returning the error union result of another async fn"
1223 const S = struct {1223 const S = struct {
1224 var global_frame: anyframe = undefined;1224 var global_frame: anyframe = undefined;
12251225
1226 fn doTheTest() void {1226 fn doTheTest() !void {
1227 expect((atest() catch unreachable) == 1234);1227 expect((atest() catch unreachable) == 1234) catch @panic("test failure");
1228 }1228 }
12291229
1230 fn atest() !i32 {1230 fn atest() !i32 {
...@@ -1246,11 +1246,11 @@ test "spill target expr in a for loop" {...@@ -1246,11 +1246,11 @@ test "spill target expr in a for loop" {
1246 const S = struct {1246 const S = struct {
1247 var global_frame: anyframe = undefined;1247 var global_frame: anyframe = undefined;
12481248
1249 fn doTheTest() void {1249 fn doTheTest() !void {
1250 var foo = Foo{1250 var foo = Foo{
1251 .slice = &[_]i32{ 1, 2 },1251 .slice = &[_]i32{ 1, 2 },
1252 };1252 };
1253 expect(atest(&foo) == 3);1253 expect(atest(&foo) == 3) catch @panic("test failure");
1254 }1254 }
12551255
1256 const Foo = struct {1256 const Foo = struct {
...@@ -1277,11 +1277,11 @@ test "spill target expr in a for loop, with a var decl in the loop body" {...@@ -1277,11 +1277,11 @@ test "spill target expr in a for loop, with a var decl in the loop body" {
1277 const S = struct {1277 const S = struct {
1278 var global_frame: anyframe = undefined;1278 var global_frame: anyframe = undefined;
12791279
1280 fn doTheTest() void {1280 fn doTheTest() !void {
1281 var foo = Foo{1281 var foo = Foo{
1282 .slice = &[_]i32{ 1, 2 },1282 .slice = &[_]i32{ 1, 2 },
1283 };1283 };
1284 expect(atest(&foo) == 3);1284 expect(atest(&foo) == 3) catch @panic("test failure");
1285 }1285 }
12861286
1287 const Foo = struct {1287 const Foo = struct {
...@@ -1319,7 +1319,7 @@ test "async call with @call" {...@@ -1319,7 +1319,7 @@ test "async call with @call" {
1319 fn atest() void {1319 fn atest() void {
1320 var frame = @call(.{ .modifier = .async_kw }, afoo, .{});1320 var frame = @call(.{ .modifier = .async_kw }, afoo, .{});
1321 const res = await frame;1321 const res = await frame;
1322 expect(res == 42);1322 expect(res == 42) catch @panic("test failure");
1323 }1323 }
1324 fn afoo() i32 {1324 fn afoo() i32 {
1325 suspend {1325 suspend {
...@@ -1348,7 +1348,7 @@ test "async function passed 0-bit arg after non-0-bit arg" {...@@ -1348,7 +1348,7 @@ test "async function passed 0-bit arg after non-0-bit arg" {
1348 };1348 };
1349 _ = async S.foo();1349 _ = async S.foo();
1350 resume S.global_frame;1350 resume S.global_frame;
1351 expect(S.global_int == 1);1351 try expect(S.global_int == 1);
1352}1352}
13531353
1354test "async function passed align(16) arg after align(8) arg" {1354test "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" {...@@ -1362,7 +1362,7 @@ test "async function passed align(16) arg after align(8) arg" {
1362 }1362 }
13631363
1364 fn bar(x: u64, args: anytype) anyerror!void {1364 fn bar(x: u64, args: anytype) anyerror!void {
1365 expect(x == 10);1365 try expect(x == 10);
1366 global_frame = @frame();1366 global_frame = @frame();
1367 suspend {}1367 suspend {}
1368 global_int = args[0];1368 global_int = args[0];
...@@ -1370,7 +1370,7 @@ test "async function passed align(16) arg after align(8) arg" {...@@ -1370,7 +1370,7 @@ test "async function passed align(16) arg after align(8) arg" {
1370 };1370 };
1371 _ = async S.foo();1371 _ = async S.foo();
1372 resume S.global_frame;1372 resume S.global_frame;
1373 expect(S.global_int == 99);1373 try expect(S.global_int == 99);
1374}1374}
13751375
1376test "async function call resolves target fn frame, comptime func" {1376test "async function call resolves target fn frame, comptime func" {
...@@ -1392,7 +1392,7 @@ test "async function call resolves target fn frame, comptime func" {...@@ -1392,7 +1392,7 @@ test "async function call resolves target fn frame, comptime func" {
1392 };1392 };
1393 _ = async S.foo();1393 _ = async S.foo();
1394 resume S.global_frame;1394 resume S.global_frame;
1395 expect(S.global_int == 10);1395 try expect(S.global_int == 10);
1396}1396}
13971397
1398test "async function call resolves target fn frame, runtime func" {1398test "async function call resolves target fn frame, runtime func" {
...@@ -1415,7 +1415,7 @@ test "async function call resolves target fn frame, runtime func" {...@@ -1415,7 +1415,7 @@ test "async function call resolves target fn frame, runtime func" {
1415 };1415 };
1416 _ = async S.foo();1416 _ = async S.foo();
1417 resume S.global_frame;1417 resume S.global_frame;
1418 expect(S.global_int == 10);1418 try expect(S.global_int == 10);
1419}1419}
14201420
1421test "properly spill optional payload capture value" {1421test "properly spill optional payload capture value" {
...@@ -1439,7 +1439,7 @@ test "properly spill optional payload capture value" {...@@ -1439,7 +1439,7 @@ test "properly spill optional payload capture value" {
1439 };1439 };
1440 _ = async S.foo();1440 _ = async S.foo();
1441 resume S.global_frame;1441 resume S.global_frame;
1442 expect(S.global_int == 1237);1442 try expect(S.global_int == 1237);
1443}1443}
14441444
1445test "handle defer interfering with return value spill" {1445test "handle defer interfering with return value spill" {
...@@ -1449,16 +1449,16 @@ test "handle defer interfering with return value spill" {...@@ -1449,16 +1449,16 @@ test "handle defer interfering with return value spill" {
1449 var finished = false;1449 var finished = false;
1450 var baz_happened = false;1450 var baz_happened = false;
14511451
1452 fn doTheTest() void {1452 fn doTheTest() !void {
1453 _ = async testFoo();1453 _ = async testFoo();
1454 resume global_frame1;1454 resume global_frame1;
1455 resume global_frame2;1455 resume global_frame2;
1456 expect(baz_happened);1456 try expect(baz_happened);
1457 expect(finished);1457 try expect(finished);
1458 }1458 }
14591459
1460 fn testFoo() void {1460 fn testFoo() void {
1461 expectError(error.Bad, foo());1461 expectError(error.Bad, foo()) catch @panic("test failure");
1462 finished = true;1462 finished = true;
1463 }1463 }
14641464
...@@ -1479,7 +1479,7 @@ test "handle defer interfering with return value spill" {...@@ -1479,7 +1479,7 @@ test "handle defer interfering with return value spill" {
1479 baz_happened = true;1479 baz_happened = true;
1480 }1480 }
1481 };1481 };
1482 S.doTheTest();1482 try S.doTheTest();
1483}1483}
14841484
1485test "take address of temporary async frame" {1485test "take address of temporary async frame" {
...@@ -1487,14 +1487,14 @@ test "take address of temporary async frame" {...@@ -1487,14 +1487,14 @@ test "take address of temporary async frame" {
1487 var global_frame: anyframe = undefined;1487 var global_frame: anyframe = undefined;
1488 var finished = false;1488 var finished = false;
14891489
1490 fn doTheTest() void {1490 fn doTheTest() !void {
1491 _ = async asyncDoTheTest();1491 _ = async asyncDoTheTest();
1492 resume global_frame;1492 resume global_frame;
1493 expect(finished);1493 try expect(finished);
1494 }1494 }
14951495
1496 fn asyncDoTheTest() void {1496 fn asyncDoTheTest() void {
1497 expect(finishIt(&async foo(10)) == 1245);1497 expect(finishIt(&async foo(10)) == 1245) catch @panic("test failure");
1498 finished = true;1498 finished = true;
1499 }1499 }
15001500
...@@ -1508,16 +1508,16 @@ test "take address of temporary async frame" {...@@ -1508,16 +1508,16 @@ test "take address of temporary async frame" {
1508 return (await frame) + 1;1508 return (await frame) + 1;
1509 }1509 }
1510 };1510 };
1511 S.doTheTest();1511 try S.doTheTest();
1512}1512}
15131513
1514test "nosuspend await" {1514test "nosuspend await" {
1515 const S = struct {1515 const S = struct {
1516 var finished = false;1516 var finished = false;
15171517
1518 fn doTheTest() void {1518 fn doTheTest() !void {
1519 var frame = async foo(false);1519 var frame = async foo(false);
1520 expect(nosuspend await frame == 42);1520 try expect(nosuspend await frame == 42);
1521 finished = true;1521 finished = true;
1522 }1522 }
15231523
...@@ -1528,8 +1528,8 @@ test "nosuspend await" {...@@ -1528,8 +1528,8 @@ test "nosuspend await" {
1528 return 42;1528 return 42;
1529 }1529 }
1530 };1530 };
1531 S.doTheTest();1531 try S.doTheTest();
1532 expect(S.finished);1532 try expect(S.finished);
1533}1533}
15341534
1535test "nosuspend on function calls" {1535test "nosuspend on function calls" {
...@@ -1544,8 +1544,8 @@ test "nosuspend on function calls" {...@@ -1544,8 +1544,8 @@ test "nosuspend on function calls" {
1544 return S0{};1544 return S0{};
1545 }1545 }
1546 };1546 };
1547 expectEqual(@as(i32, 42), nosuspend S1.c().b);1547 try expectEqual(@as(i32, 42), nosuspend S1.c().b);
1548 expectEqual(@as(i32, 42), (try nosuspend S1.d()).b);1548 try expectEqual(@as(i32, 42), (try nosuspend S1.d()).b);
1549}1549}
15501550
1551test "nosuspend on async function calls" {1551test "nosuspend on async function calls" {
...@@ -1561,9 +1561,9 @@ test "nosuspend on async function calls" {...@@ -1561,9 +1561,9 @@ test "nosuspend on async function calls" {
1561 }1561 }
1562 };1562 };
1563 var frame_c = nosuspend async S1.c();1563 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);
1565 var frame_d = nosuspend async S1.d();1565 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);
1567}1567}
15681568
1569// test "resume nosuspend async function calls" {1569// test "resume nosuspend async function calls" {
...@@ -1582,10 +1582,10 @@ test "nosuspend on async function calls" {...@@ -1582,10 +1582,10 @@ test "nosuspend on async function calls" {
1582// };1582// };
1583// var frame_c = nosuspend async S1.c();1583// var frame_c = nosuspend async S1.c();
1584// resume frame_c;1584// resume frame_c;
1585// expectEqual(@as(i32, 42), (await frame_c).b);1585// try expectEqual(@as(i32, 42), (await frame_c).b);
1586// var frame_d = nosuspend async S1.d();1586// var frame_d = nosuspend async S1.d();
1587// resume frame_d;1587// resume frame_d;
1588// expectEqual(@as(i32, 42), (try await frame_d).b);1588// try expectEqual(@as(i32, 42), (try await frame_d).b);
1589// }1589// }
15901590
1591test "nosuspend resume async function calls" {1591test "nosuspend resume async function calls" {
...@@ -1604,10 +1604,10 @@ test "nosuspend resume async function calls" {...@@ -1604,10 +1604,10 @@ test "nosuspend resume async function calls" {
1604 };1604 };
1605 var frame_c = async S1.c();1605 var frame_c = async S1.c();
1606 nosuspend resume frame_c;1606 nosuspend resume frame_c;
1607 expectEqual(@as(i32, 42), (await frame_c).b);1607 try expectEqual(@as(i32, 42), (await frame_c).b);
1608 var frame_d = async S1.d();1608 var frame_d = async S1.d();
1609 nosuspend resume frame_d;1609 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);
1611}1611}
16121612
1613test "avoid forcing frame alignment resolution implicit cast to *c_void" {1613test "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" {...@@ -1623,7 +1623,7 @@ test "avoid forcing frame alignment resolution implicit cast to *c_void" {
1623 };1623 };
1624 var frame = async S.foo();1624 var frame = async S.foo();
1625 resume @ptrCast(anyframe->bool, @alignCast(@alignOf(@Frame(S.foo)), S.x));1625 resume @ptrCast(anyframe->bool, @alignCast(@alignOf(@Frame(S.foo)), S.x));
1626 expect(nosuspend await frame);1626 try expect(nosuspend await frame);
1627}1627}
16281628
1629test "@asyncCall with pass-by-value arguments" {1629test "@asyncCall with pass-by-value arguments" {
...@@ -1638,9 +1638,9 @@ test "@asyncCall with pass-by-value arguments" {...@@ -1638,9 +1638,9 @@ test "@asyncCall with pass-by-value arguments" {
1638 pub fn f(_fill0: u64, s: ST, _fill1: u64, a: AT, _fill2: u64) callconv(.Async) void {1638 pub fn f(_fill0: u64, s: ST, _fill1: u64, a: AT, _fill2: u64) callconv(.Async) void {
1639 // Check that the array and struct arguments passed by value don't1639 // Check that the array and struct arguments passed by value don't
1640 // end up overflowing the adjacent fields in the frame structure.1640 // end up overflowing the adjacent fields in the frame structure.
1641 expectEqual(F0, _fill0);1641 expectEqual(F0, _fill0) catch @panic("test failure");
1642 expectEqual(F1, _fill1);1642 expectEqual(F1, _fill1) catch @panic("test failure");
1643 expectEqual(F2, _fill2);1643 expectEqual(F2, _fill2) catch @panic("test failure");
1644 }1644 }
1645 };1645 };
16461646
...@@ -1664,8 +1664,8 @@ test "@asyncCall with arguments having non-standard alignment" {...@@ -1664,8 +1664,8 @@ test "@asyncCall with arguments having non-standard alignment" {
1664 pub fn f(_fill0: u32, s: struct { x: u64 align(16) }, _fill1: u64) callconv(.Async) void {1664 pub fn f(_fill0: u32, s: struct { x: u64 align(16) }, _fill1: u64) callconv(.Async) void {
1665 // The compiler inserts extra alignment for s, check that the1665 // The compiler inserts extra alignment for s, check that the
1666 // generated code picks the right slot for fill1.1666 // generated code picks the right slot for fill1.
1667 expectEqual(F0, _fill0);1667 expectEqual(F0, _fill0) catch @panic("test failure");
1668 expectEqual(F1, _fill1);1668 expectEqual(F1, _fill1) catch @panic("test failure");
1669 }1669 }
1670 };1670 };
16711671
test/behavior/atomics.zig+69-69
...@@ -4,25 +4,25 @@ const expectEqual = std.testing.expectEqual;...@@ -4,25 +4,25 @@ const expectEqual = std.testing.expectEqual;
4const builtin = @import("builtin");4const builtin = @import("builtin");
55
6test "cmpxchg" {6test "cmpxchg" {
7 testCmpxchg();7 try testCmpxchg();
8 comptime testCmpxchg();8 comptime try testCmpxchg();
9}9}
1010
11fn testCmpxchg() void {11fn testCmpxchg() !void {
12 var x: i32 = 1234;12 var x: i32 = 1234;
13 if (@cmpxchgWeak(i32, &x, 99, 5678, .SeqCst, .SeqCst)) |x1| {13 if (@cmpxchgWeak(i32, &x, 99, 5678, .SeqCst, .SeqCst)) |x1| {
14 expect(x1 == 1234);14 try expect(x1 == 1234);
15 } else {15 } else {
16 @panic("cmpxchg should have failed");16 @panic("cmpxchg should have failed");
17 }17 }
1818
19 while (@cmpxchgWeak(i32, &x, 1234, 5678, .SeqCst, .SeqCst)) |x1| {19 while (@cmpxchgWeak(i32, &x, 1234, 5678, .SeqCst, .SeqCst)) |x1| {
20 expect(x1 == 1234);20 try expect(x1 == 1234);
21 }21 }
22 expect(x == 5678);22 try expect(x == 5678);
2323
24 expect(@cmpxchgStrong(i32, &x, 5678, 42, .SeqCst, .SeqCst) == null);24 try expect(@cmpxchgStrong(i32, &x, 5678, 42, .SeqCst, .SeqCst) == null);
25 expect(x == 42);25 try expect(x == 42);
26}26}
2727
28test "fence" {28test "fence" {
...@@ -33,25 +33,25 @@ test "fence" {...@@ -33,25 +33,25 @@ test "fence" {
3333
34test "atomicrmw and atomicload" {34test "atomicrmw and atomicload" {
35 var data: u8 = 200;35 var data: u8 = 200;
36 testAtomicRmw(&data);36 try testAtomicRmw(&data);
37 expect(data == 42);37 try expect(data == 42);
38 testAtomicLoad(&data);38 try testAtomicLoad(&data);
39}39}
4040
41fn testAtomicRmw(ptr: *u8) void {41fn testAtomicRmw(ptr: *u8) !void {
42 const prev_value = @atomicRmw(u8, ptr, .Xchg, 42, .SeqCst);42 const prev_value = @atomicRmw(u8, ptr, .Xchg, 42, .SeqCst);
43 expect(prev_value == 200);43 try expect(prev_value == 200);
44 comptime {44 comptime {
45 var x: i32 = 1234;45 var x: i32 = 1234;
46 const y: i32 = 12345;46 const y: i32 = 12345;
47 expect(@atomicLoad(i32, &x, .SeqCst) == 1234);47 try expect(@atomicLoad(i32, &x, .SeqCst) == 1234);
48 expect(@atomicLoad(i32, &y, .SeqCst) == 12345);48 try expect(@atomicLoad(i32, &y, .SeqCst) == 12345);
49 }49 }
50}50}
5151
52fn testAtomicLoad(ptr: *u8) void {52fn testAtomicLoad(ptr: *u8) !void {
53 const x = @atomicLoad(u8, ptr, .SeqCst);53 const x = @atomicLoad(u8, ptr, .SeqCst);
54 expect(x == 42);54 try expect(x == 42);
55}55}
5656
57test "cmpxchg with ptr" {57test "cmpxchg with ptr" {
...@@ -60,18 +60,18 @@ test "cmpxchg with ptr" {...@@ -60,18 +60,18 @@ test "cmpxchg with ptr" {
60 var data3: i32 = 9101;60 var data3: i32 = 9101;
61 var x: *i32 = &data1;61 var x: *i32 = &data1;
62 if (@cmpxchgWeak(*i32, &x, &data2, &data3, .SeqCst, .SeqCst)) |x1| {62 if (@cmpxchgWeak(*i32, &x, &data2, &data3, .SeqCst, .SeqCst)) |x1| {
63 expect(x1 == &data1);63 try expect(x1 == &data1);
64 } else {64 } else {
65 @panic("cmpxchg should have failed");65 @panic("cmpxchg should have failed");
66 }66 }
6767
68 while (@cmpxchgWeak(*i32, &x, &data1, &data3, .SeqCst, .SeqCst)) |x1| {68 while (@cmpxchgWeak(*i32, &x, &data1, &data3, .SeqCst, .SeqCst)) |x1| {
69 expect(x1 == &data1);69 try expect(x1 == &data1);
70 }70 }
71 expect(x == &data3);71 try expect(x == &data3);
7272
73 expect(@cmpxchgStrong(*i32, &x, &data3, &data2, .SeqCst, .SeqCst) == null);73 try expect(@cmpxchgStrong(*i32, &x, &data3, &data2, .SeqCst, .SeqCst) == null);
74 expect(x == &data2);74 try expect(x == &data2);
75}75}
7676
77// TODO this test is disabled until this issue is resolved:77// TODO this test is disabled until this issue is resolved:
...@@ -81,18 +81,18 @@ test "cmpxchg with ptr" {...@@ -81,18 +81,18 @@ test "cmpxchg with ptr" {
81//test "128-bit cmpxchg" {81//test "128-bit cmpxchg" {
82// var x: u128 align(16) = 1234; // TODO: https://github.com/ziglang/zig/issues/298782// var x: u128 align(16) = 1234; // TODO: https://github.com/ziglang/zig/issues/2987
83// if (@cmpxchgWeak(u128, &x, 99, 5678, .SeqCst, .SeqCst)) |x1| {83// if (@cmpxchgWeak(u128, &x, 99, 5678, .SeqCst, .SeqCst)) |x1| {
84// expect(x1 == 1234);84// try expect(x1 == 1234);
85// } else {85// } else {
86// @panic("cmpxchg should have failed");86// @panic("cmpxchg should have failed");
87// }87// }
88//88//
89// while (@cmpxchgWeak(u128, &x, 1234, 5678, .SeqCst, .SeqCst)) |x1| {89// while (@cmpxchgWeak(u128, &x, 1234, 5678, .SeqCst, .SeqCst)) |x1| {
90// expect(x1 == 1234);90// try expect(x1 == 1234);
91// }91// }
92// expect(x == 5678);92// try expect(x == 5678);
93//93//
94// expect(@cmpxchgStrong(u128, &x, 5678, 42, .SeqCst, .SeqCst) == null);94// try expect(@cmpxchgStrong(u128, &x, 5678, 42, .SeqCst, .SeqCst) == null);
95// expect(x == 42);95// try expect(x == 42);
96//}96//}
9797
98test "cmpxchg with ignored result" {98test "cmpxchg with ignored result" {
...@@ -101,14 +101,14 @@ test "cmpxchg with ignored result" {...@@ -101,14 +101,14 @@ test "cmpxchg with ignored result" {
101101
102 _ = @cmpxchgStrong(i32, &x, 1234, 5678, .Monotonic, .Monotonic);102 _ = @cmpxchgStrong(i32, &x, 1234, 5678, .Monotonic, .Monotonic);
103103
104 expectEqual(@as(i32, 5678), x);104 try expectEqual(@as(i32, 5678), x);
105}105}
106106
107var a_global_variable = @as(u32, 1234);107var a_global_variable = @as(u32, 1234);
108108
109test "cmpxchg on a global variable" {109test "cmpxchg on a global variable" {
110 _ = @cmpxchgWeak(u32, &a_global_variable, 1234, 42, .Acquire, .Monotonic);110 _ = @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);
112}112}
113113
114test "atomic load and rmw with enum" {114test "atomic load and rmw with enum" {
...@@ -119,33 +119,33 @@ test "atomic load and rmw with enum" {...@@ -119,33 +119,33 @@ test "atomic load and rmw with enum" {
119 };119 };
120 var x = Value.a;120 var x = Value.a;
121121
122 expect(@atomicLoad(Value, &x, .SeqCst) != .b);122 try expect(@atomicLoad(Value, &x, .SeqCst) != .b);
123123
124 _ = @atomicRmw(Value, &x, .Xchg, .c, .SeqCst);124 _ = @atomicRmw(Value, &x, .Xchg, .c, .SeqCst);
125 expect(@atomicLoad(Value, &x, .SeqCst) == .c);125 try expect(@atomicLoad(Value, &x, .SeqCst) == .c);
126 expect(@atomicLoad(Value, &x, .SeqCst) != .a);126 try expect(@atomicLoad(Value, &x, .SeqCst) != .a);
127 expect(@atomicLoad(Value, &x, .SeqCst) != .b);127 try expect(@atomicLoad(Value, &x, .SeqCst) != .b);
128}128}
129129
130test "atomic store" {130test "atomic store" {
131 var x: u32 = 0;131 var x: u32 = 0;
132 @atomicStore(u32, &x, 1, .SeqCst);132 @atomicStore(u32, &x, 1, .SeqCst);
133 expect(@atomicLoad(u32, &x, .SeqCst) == 1);133 try expect(@atomicLoad(u32, &x, .SeqCst) == 1);
134 @atomicStore(u32, &x, 12345678, .SeqCst);134 @atomicStore(u32, &x, 12345678, .SeqCst);
135 expect(@atomicLoad(u32, &x, .SeqCst) == 12345678);135 try expect(@atomicLoad(u32, &x, .SeqCst) == 12345678);
136}136}
137137
138test "atomic store comptime" {138test "atomic store comptime" {
139 comptime testAtomicStore();139 comptime try testAtomicStore();
140 testAtomicStore();140 try testAtomicStore();
141}141}
142142
143fn testAtomicStore() void {143fn testAtomicStore() !void {
144 var x: u32 = 0;144 var x: u32 = 0;
145 @atomicStore(u32, &x, 1, .SeqCst);145 @atomicStore(u32, &x, 1, .SeqCst);
146 expect(@atomicLoad(u32, &x, .SeqCst) == 1);146 try expect(@atomicLoad(u32, &x, .SeqCst) == 1);
147 @atomicStore(u32, &x, 12345678, .SeqCst);147 @atomicStore(u32, &x, 12345678, .SeqCst);
148 expect(@atomicLoad(u32, &x, .SeqCst) == 12345678);148 try expect(@atomicLoad(u32, &x, .SeqCst) == 12345678);
149}149}
150150
151test "atomicrmw with floats" {151test "atomicrmw with floats" {
...@@ -154,66 +154,66 @@ test "atomicrmw with floats" {...@@ -154,66 +154,66 @@ test "atomicrmw with floats" {
154 .aarch64, .arm, .thumb, .riscv64 => return error.SkipZigTest,154 .aarch64, .arm, .thumb, .riscv64 => return error.SkipZigTest,
155 else => {},155 else => {},
156 }156 }
157 testAtomicRmwFloat();157 try testAtomicRmwFloat();
158 comptime testAtomicRmwFloat();158 comptime try testAtomicRmwFloat();
159}159}
160160
161fn testAtomicRmwFloat() void {161fn testAtomicRmwFloat() !void {
162 var x: f32 = 0;162 var x: f32 = 0;
163 expect(x == 0);163 try expect(x == 0);
164 _ = @atomicRmw(f32, &x, .Xchg, 1, .SeqCst);164 _ = @atomicRmw(f32, &x, .Xchg, 1, .SeqCst);
165 expect(x == 1);165 try expect(x == 1);
166 _ = @atomicRmw(f32, &x, .Add, 5, .SeqCst);166 _ = @atomicRmw(f32, &x, .Add, 5, .SeqCst);
167 expect(x == 6);167 try expect(x == 6);
168 _ = @atomicRmw(f32, &x, .Sub, 2, .SeqCst);168 _ = @atomicRmw(f32, &x, .Sub, 2, .SeqCst);
169 expect(x == 4);169 try expect(x == 4);
170}170}
171171
172test "atomicrmw with ints" {172test "atomicrmw with ints" {
173 testAtomicRmwInt();173 try testAtomicRmwInt();
174 comptime testAtomicRmwInt();174 comptime try testAtomicRmwInt();
175}175}
176176
177fn testAtomicRmwInt() void {177fn testAtomicRmwInt() !void {
178 var x: u8 = 1;178 var x: u8 = 1;
179 var res = @atomicRmw(u8, &x, .Xchg, 3, .SeqCst);179 var res = @atomicRmw(u8, &x, .Xchg, 3, .SeqCst);
180 expect(x == 3 and res == 1);180 try expect(x == 3 and res == 1);
181 _ = @atomicRmw(u8, &x, .Add, 3, .SeqCst);181 _ = @atomicRmw(u8, &x, .Add, 3, .SeqCst);
182 expect(x == 6);182 try expect(x == 6);
183 _ = @atomicRmw(u8, &x, .Sub, 1, .SeqCst);183 _ = @atomicRmw(u8, &x, .Sub, 1, .SeqCst);
184 expect(x == 5);184 try expect(x == 5);
185 _ = @atomicRmw(u8, &x, .And, 4, .SeqCst);185 _ = @atomicRmw(u8, &x, .And, 4, .SeqCst);
186 expect(x == 4);186 try expect(x == 4);
187 _ = @atomicRmw(u8, &x, .Nand, 4, .SeqCst);187 _ = @atomicRmw(u8, &x, .Nand, 4, .SeqCst);
188 expect(x == 0xfb);188 try expect(x == 0xfb);
189 _ = @atomicRmw(u8, &x, .Or, 6, .SeqCst);189 _ = @atomicRmw(u8, &x, .Or, 6, .SeqCst);
190 expect(x == 0xff);190 try expect(x == 0xff);
191 _ = @atomicRmw(u8, &x, .Xor, 2, .SeqCst);191 _ = @atomicRmw(u8, &x, .Xor, 2, .SeqCst);
192 expect(x == 0xfd);192 try expect(x == 0xfd);
193193
194 _ = @atomicRmw(u8, &x, .Max, 1, .SeqCst);194 _ = @atomicRmw(u8, &x, .Max, 1, .SeqCst);
195 expect(x == 0xfd);195 try expect(x == 0xfd);
196 _ = @atomicRmw(u8, &x, .Min, 1, .SeqCst);196 _ = @atomicRmw(u8, &x, .Min, 1, .SeqCst);
197 expect(x == 1);197 try expect(x == 1);
198}198}
199199
200test "atomics with different types" {200test "atomics with different types" {
201 testAtomicsWithType(bool, true, false);201 try testAtomicsWithType(bool, true, false);
202 inline for (.{ u1, i5, u15 }) |T| {202 inline for (.{ u1, i5, u15 }) |T| {
203 var x: T = 0;203 var x: T = 0;
204 testAtomicsWithType(T, 0, 1);204 try testAtomicsWithType(T, 0, 1);
205 }205 }
206 testAtomicsWithType(u0, 0, 0);206 try testAtomicsWithType(u0, 0, 0);
207 testAtomicsWithType(i0, 0, 0);207 try testAtomicsWithType(i0, 0, 0);
208}208}
209209
210fn testAtomicsWithType(comptime T: type, a: T, b: T) void {210fn testAtomicsWithType(comptime T: type, a: T, b: T) !void {
211 var x: T = b;211 var x: T = b;
212 @atomicStore(T, &x, a, .SeqCst);212 @atomicStore(T, &x, a, .SeqCst);
213 expect(x == a);213 try expect(x == a);
214 expect(@atomicLoad(T, &x, .SeqCst) == a);214 try expect(@atomicLoad(T, &x, .SeqCst) == a);
215 expect(@atomicRmw(T, &x, .Xchg, b, .SeqCst) == a);215 try expect(@atomicRmw(T, &x, .Xchg, b, .SeqCst) == a);
216 expect(@cmpxchgStrong(T, &x, b, a, .SeqCst, .SeqCst) == null);216 try expect(@cmpxchgStrong(T, &x, b, a, .SeqCst, .SeqCst) == null);
217 if (@sizeOf(T) != 0)217 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);
219}219}
test/behavior/await_struct.zig+2-2
...@@ -15,8 +15,8 @@ test "coroutine await struct" {...@@ -15,8 +15,8 @@ test "coroutine await struct" {
15 await_seq('f');15 await_seq('f');
16 resume await_a_promise;16 resume await_a_promise;
17 await_seq('i');17 await_seq('i');
18 expect(await_final_result.x == 1234);18 try expect(await_final_result.x == 1234);
19 expect(std.mem.eql(u8, &await_points, "abcdefghi"));19 try expect(std.mem.eql(u8, &await_points, "abcdefghi"));
20}20}
21fn await_amain() callconv(.Async) void {21fn await_amain() callconv(.Async) void {
22 await_seq('b');22 await_seq('b');
test/behavior/bit_shifting.zig+14-14
...@@ -3,8 +3,8 @@ const expect = std.testing.expect;...@@ -3,8 +3,8 @@ const expect = std.testing.expect;
33
4fn ShardedTable(comptime Key: type, comptime mask_bit_count: comptime_int, comptime V: type) type {4fn ShardedTable(comptime Key: type, comptime mask_bit_count: comptime_int, comptime V: type) type {
5 const key_bits = @typeInfo(Key).Int.bits;5 const key_bits = @typeInfo(Key).Int.bits;
6 expect(Key == std.meta.Int(.unsigned, key_bits));6 std.debug.assert(Key == std.meta.Int(.unsigned, key_bits));
7 expect(key_bits >= mask_bit_count);7 std.debug.assert(key_bits >= mask_bit_count);
8 const shard_key_bits = mask_bit_count;8 const shard_key_bits = mask_bit_count;
9 const ShardKey = std.meta.Int(.unsigned, mask_bit_count);9 const ShardKey = std.meta.Int(.unsigned, mask_bit_count);
10 const shift_amount = key_bits - shard_key_bits;10 const shift_amount = key_bits - shard_key_bits;
...@@ -61,31 +61,31 @@ fn ShardedTable(comptime Key: type, comptime mask_bit_count: comptime_int, compt...@@ -61,31 +61,31 @@ fn ShardedTable(comptime Key: type, comptime mask_bit_count: comptime_int, compt
6161
62test "sharded table" {62test "sharded table" {
63 // realistic 16-way sharding63 // realistic 16-way sharding
64 testShardedTable(u32, 4, 8);64 try testShardedTable(u32, 4, 8);
6565
66 testShardedTable(u5, 0, 32); // ShardKey == u066 try testShardedTable(u5, 0, 32); // ShardKey == u0
67 testShardedTable(u5, 2, 32);67 try testShardedTable(u5, 2, 32);
68 testShardedTable(u5, 5, 32);68 try testShardedTable(u5, 5, 32);
6969
70 testShardedTable(u1, 0, 2);70 try testShardedTable(u1, 0, 2);
71 testShardedTable(u1, 1, 2); // this does u1 >> u071 try testShardedTable(u1, 1, 2); // this does u1 >> u0
7272
73 testShardedTable(u0, 0, 1);73 try testShardedTable(u0, 0, 1);
74}74}
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 {
76 const Table = ShardedTable(Key, mask_bit_count, void);76 const Table = ShardedTable(Key, mask_bit_count, void);
7777
78 var table = Table.create();78 var table = Table.create();
79 var node_buffer: [node_count]Table.Node = undefined;79 var node_buffer: [node_count]Table.Node = undefined;
80 for (node_buffer) |*node, i| {80 for (node_buffer) |*node, i| {
81 const key = @intCast(Key, i);81 const key = @intCast(Key, i);
82 expect(table.get(key) == null);82 try expect(table.get(key) == null);
83 node.init(key, {});83 node.init(key, {});
84 table.put(node);84 table.put(node);
85 }85 }
8686
87 for (node_buffer) |*node, i| {87 for (node_buffer) |*node, i| {
88 expect(table.get(@intCast(Key, i)) == node);88 try expect(table.get(@intCast(Key, i)) == node);
89 }89 }
90}90}
9191
...@@ -93,9 +93,9 @@ fn testShardedTable(comptime Key: type, comptime mask_bit_count: comptime_int, c...@@ -93,9 +93,9 @@ fn testShardedTable(comptime Key: type, comptime mask_bit_count: comptime_int, c
93test "comptime shr of BigInt" {93test "comptime shr of BigInt" {
94 comptime {94 comptime {
95 var n0 = 0xdeadbeef0000000000000000;95 var n0 = 0xdeadbeef0000000000000000;
96 std.debug.assert(n0 >> 64 == 0xdeadbeef);96 try expect(n0 >> 64 == 0xdeadbeef);
97 var n1 = 17908056155735594659;97 var n1 = 17908056155735594659;
98 std.debug.assert(n1 >> 64 == 0);98 try expect(n1 >> 64 == 0);
99 }99 }
100}100}
101101
test/behavior/bitcast.zig+52-52
...@@ -6,13 +6,13 @@ const maxInt = std.math.maxInt;...@@ -6,13 +6,13 @@ const maxInt = std.math.maxInt;
6const native_endian = builtin.target.cpu.arch.endian();6const native_endian = builtin.target.cpu.arch.endian();
77
8test "@bitCast i32 -> u32" {8test "@bitCast i32 -> u32" {
9 testBitCast_i32_u32();9 try testBitCast_i32_u32();
10 comptime testBitCast_i32_u32();10 comptime try testBitCast_i32_u32();
11}11}
1212
13fn testBitCast_i32_u32() void {13fn testBitCast_i32_u32() !void {
14 expect(conv(-1) == maxInt(u32));14 try expect(conv(-1) == maxInt(u32));
15 expect(conv2(maxInt(u32)) == -1);15 try expect(conv2(maxInt(u32)) == -1);
16}16}
1717
18fn conv(x: i32) u32 {18fn conv(x: i32) u32 {
...@@ -27,15 +27,15 @@ test "@bitCast extern enum to its integer type" {...@@ -27,15 +27,15 @@ test "@bitCast extern enum to its integer type" {
27 A,27 A,
28 B,28 B,
2929
30 fn testBitCastExternEnum() void {30 fn testBitCastExternEnum() !void {
31 var SOCK_DGRAM = @This().B;31 var SOCK_DGRAM = @This().B;
32 var sock_dgram = @bitCast(c_int, SOCK_DGRAM);32 var sock_dgram = @bitCast(c_int, SOCK_DGRAM);
33 expect(sock_dgram == 1);33 try expect(sock_dgram == 1);
34 }34 }
35 };35 };
3636
37 SOCK.testBitCastExternEnum();37 try SOCK.testBitCastExternEnum();
38 comptime SOCK.testBitCastExternEnum();38 comptime try SOCK.testBitCastExternEnum();
39}39}
4040
41test "@bitCast packed structs at runtime and comptime" {41test "@bitCast packed structs at runtime and comptime" {
...@@ -48,25 +48,25 @@ test "@bitCast packed structs at runtime and comptime" {...@@ -48,25 +48,25 @@ test "@bitCast packed structs at runtime and comptime" {
48 quarter4: u4,48 quarter4: u4,
49 };49 };
50 const S = struct {50 const S = struct {
51 fn doTheTest() void {51 fn doTheTest() !void {
52 var full = Full{ .number = 0x1234 };52 var full = Full{ .number = 0x1234 };
53 var two_halves = @bitCast(Divided, full);53 var two_halves = @bitCast(Divided, full);
54 switch (native_endian) {54 switch (native_endian) {
55 .Big => {55 .Big => {
56 expect(two_halves.half1 == 0x12);56 try expect(two_halves.half1 == 0x12);
57 expect(two_halves.quarter3 == 0x3);57 try expect(two_halves.quarter3 == 0x3);
58 expect(two_halves.quarter4 == 0x4);58 try expect(two_halves.quarter4 == 0x4);
59 },59 },
60 .Little => {60 .Little => {
61 expect(two_halves.half1 == 0x34);61 try expect(two_halves.half1 == 0x34);
62 expect(two_halves.quarter3 == 0x2);62 try expect(two_halves.quarter3 == 0x2);
63 expect(two_halves.quarter4 == 0x1);63 try expect(two_halves.quarter4 == 0x1);
64 },64 },
65 }65 }
66 }66 }
67 };67 };
68 S.doTheTest();68 try S.doTheTest();
69 comptime S.doTheTest();69 comptime try S.doTheTest();
70}70}
7171
72test "@bitCast extern structs at runtime and comptime" {72test "@bitCast extern structs at runtime and comptime" {
...@@ -78,23 +78,23 @@ test "@bitCast extern structs at runtime and comptime" {...@@ -78,23 +78,23 @@ test "@bitCast extern structs at runtime and comptime" {
78 half2: u8,78 half2: u8,
79 };79 };
80 const S = struct {80 const S = struct {
81 fn doTheTest() void {81 fn doTheTest() !void {
82 var full = Full{ .number = 0x1234 };82 var full = Full{ .number = 0x1234 };
83 var two_halves = @bitCast(TwoHalves, full);83 var two_halves = @bitCast(TwoHalves, full);
84 switch (native_endian) {84 switch (native_endian) {
85 .Big => {85 .Big => {
86 expect(two_halves.half1 == 0x12);86 try expect(two_halves.half1 == 0x12);
87 expect(two_halves.half2 == 0x34);87 try expect(two_halves.half2 == 0x34);
88 },88 },
89 .Little => {89 .Little => {
90 expect(two_halves.half1 == 0x34);90 try expect(two_halves.half1 == 0x34);
91 expect(two_halves.half2 == 0x12);91 try expect(two_halves.half2 == 0x12);
92 },92 },
93 }93 }
94 }94 }
95 };95 };
96 S.doTheTest();96 try S.doTheTest();
97 comptime S.doTheTest();97 comptime try S.doTheTest();
98}98}
9999
100test "bitcast packed struct to integer and back" {100test "bitcast packed struct to integer and back" {
...@@ -103,35 +103,35 @@ test "bitcast packed struct to integer and back" {...@@ -103,35 +103,35 @@ test "bitcast packed struct to integer and back" {
103 level: u7,103 level: u7,
104 };104 };
105 const S = struct {105 const S = struct {
106 fn doTheTest() void {106 fn doTheTest() !void {
107 var move = LevelUpMove{ .move_id = 1, .level = 2 };107 var move = LevelUpMove{ .move_id = 1, .level = 2 };
108 var v = @bitCast(u16, move);108 var v = @bitCast(u16, move);
109 var back_to_a_move = @bitCast(LevelUpMove, v);109 var back_to_a_move = @bitCast(LevelUpMove, v);
110 expect(back_to_a_move.move_id == 1);110 try expect(back_to_a_move.move_id == 1);
111 expect(back_to_a_move.level == 2);111 try expect(back_to_a_move.level == 2);
112 }112 }
113 };113 };
114 S.doTheTest();114 try S.doTheTest();
115 comptime S.doTheTest();115 comptime try S.doTheTest();
116}116}
117117
118test "implicit cast to error union by returning" {118test "implicit cast to error union by returning" {
119 const S = struct {119 const S = struct {
120 fn entry() void {120 fn entry() !void {
121 expect((func(-1) catch unreachable) == maxInt(u64));121 try expect((func(-1) catch unreachable) == maxInt(u64));
122 }122 }
123 pub fn func(sz: i64) anyerror!u64 {123 pub fn func(sz: i64) anyerror!u64 {
124 return @bitCast(u64, sz);124 return @bitCast(u64, sz);
125 }125 }
126 };126 };
127 S.entry();127 try S.entry();
128 comptime S.entry();128 comptime try S.entry();
129}129}
130130
131// issue #3010: compiler segfault131// issue #3010: compiler segfault
132test "bitcast literal [4]u8 param to u32" {132test "bitcast literal [4]u8 param to u32" {
133 const ip = @bitCast(u32, [_]u8{ 255, 255, 255, 255 });133 const ip = @bitCast(u32, [_]u8{ 255, 255, 255, 255 });
134 expect(ip == maxInt(u32));134 try expect(ip == maxInt(u32));
135}135}
136136
137test "bitcast packed struct literal to byte" {137test "bitcast packed struct literal to byte" {
...@@ -139,14 +139,14 @@ test "bitcast packed struct literal to byte" {...@@ -139,14 +139,14 @@ test "bitcast packed struct literal to byte" {
139 value: u8,139 value: u8,
140 };140 };
141 const casted = @bitCast(u8, Foo{ .value = 0xF });141 const casted = @bitCast(u8, Foo{ .value = 0xF });
142 expect(casted == 0xf);142 try expect(casted == 0xf);
143}143}
144144
145test "comptime bitcast used in expression has the correct type" {145test "comptime bitcast used in expression has the correct type" {
146 const Foo = packed struct {146 const Foo = packed struct {
147 value: u8,147 value: u8,
148 };148 };
149 expect(@bitCast(u8, Foo{ .value = 0xF }) == 0xf);149 try expect(@bitCast(u8, Foo{ .value = 0xF }) == 0xf);
150}150}
151151
152test "bitcast result to _" {152test "bitcast result to _" {
...@@ -155,43 +155,43 @@ test "bitcast result to _" {...@@ -155,43 +155,43 @@ test "bitcast result to _" {
155155
156test "nested bitcast" {156test "nested bitcast" {
157 const S = struct {157 const S = struct {
158 fn moo(x: isize) void {158 fn moo(x: isize) !void {
159 @import("std").testing.expectEqual(@intCast(isize, 42), x);159 try @import("std").testing.expectEqual(@intCast(isize, 42), x);
160 }160 }
161161
162 fn foo(x: isize) void {162 fn foo(x: isize) !void {
163 @This().moo(163 try @This().moo(
164 @bitCast(isize, if (x != 0) @bitCast(usize, x) else @bitCast(usize, x)),164 @bitCast(isize, if (x != 0) @bitCast(usize, x) else @bitCast(usize, x)),
165 );165 );
166 }166 }
167 };167 };
168168
169 S.foo(42);169 try S.foo(42);
170 comptime S.foo(42);170 comptime try S.foo(42);
171}171}
172172
173test "bitcast passed as tuple element" {173test "bitcast passed as tuple element" {
174 const S = struct {174 const S = struct {
175 fn foo(args: anytype) void {175 fn foo(args: anytype) !void {
176 comptime expect(@TypeOf(args[0]) == f32);176 comptime try expect(@TypeOf(args[0]) == f32);
177 expect(args[0] == 12.34);177 try expect(args[0] == 12.34);
178 }178 }
179 };179 };
180 S.foo(.{@bitCast(f32, @as(u32, 0x414570A4))});180 try S.foo(.{@bitCast(f32, @as(u32, 0x414570A4))});
181}181}
182182
183test "triple level result location with bitcast sandwich passed as tuple element" {183test "triple level result location with bitcast sandwich passed as tuple element" {
184 const S = struct {184 const S = struct {
185 fn foo(args: anytype) void {185 fn foo(args: anytype) !void {
186 comptime expect(@TypeOf(args[0]) == f64);186 comptime try expect(@TypeOf(args[0]) == f64);
187 expect(args[0] > 12.33 and args[0] < 12.35);187 try expect(args[0] > 12.33 and args[0] < 12.35);
188 }188 }
189 };189 };
190 S.foo(.{@as(f64, @bitCast(f32, @as(u32, 0x414570A4)))});190 try S.foo(.{@as(f64, @bitCast(f32, @as(u32, 0x414570A4)))});
191}191}
192192
193test "bitcast generates a temporary value" {193test "bitcast generates a temporary value" {
194 var y = @as(u16, 0x55AA);194 var y = @as(u16, 0x55AA);
195 const x = @bitCast(u16, @bitCast([2]u8, y));195 const x = @bitCast(u16, @bitCast([2]u8, y));
196 expectEqual(y, x);196 try expectEqual(y, x);
197}197}
test/behavior/bitreverse.zig+39-39
...@@ -3,67 +3,67 @@ const expect = std.testing.expect;...@@ -3,67 +3,67 @@ const expect = std.testing.expect;
3const minInt = std.math.minInt;3const minInt = std.math.minInt;
44
5test "@bitReverse" {5test "@bitReverse" {
6 comptime testBitReverse();6 comptime try testBitReverse();
7 testBitReverse();7 try testBitReverse();
8}8}
99
10fn testBitReverse() void {10fn testBitReverse() !void {
11 // using comptime_ints, unsigned11 // using comptime_ints, unsigned
12 expect(@bitReverse(u0, 0) == 0);12 try expect(@bitReverse(u0, 0) == 0);
13 expect(@bitReverse(u5, 0x12) == 0x9);13 try expect(@bitReverse(u5, 0x12) == 0x9);
14 expect(@bitReverse(u8, 0x12) == 0x48);14 try expect(@bitReverse(u8, 0x12) == 0x48);
15 expect(@bitReverse(u16, 0x1234) == 0x2c48);15 try expect(@bitReverse(u16, 0x1234) == 0x2c48);
16 expect(@bitReverse(u24, 0x123456) == 0x6a2c48);16 try expect(@bitReverse(u24, 0x123456) == 0x6a2c48);
17 expect(@bitReverse(u32, 0x12345678) == 0x1e6a2c48);17 try expect(@bitReverse(u32, 0x12345678) == 0x1e6a2c48);
18 expect(@bitReverse(u40, 0x123456789a) == 0x591e6a2c48);18 try expect(@bitReverse(u40, 0x123456789a) == 0x591e6a2c48);
19 expect(@bitReverse(u48, 0x123456789abc) == 0x3d591e6a2c48);19 try expect(@bitReverse(u48, 0x123456789abc) == 0x3d591e6a2c48);
20 expect(@bitReverse(u56, 0x123456789abcde) == 0x7b3d591e6a2c48);20 try expect(@bitReverse(u56, 0x123456789abcde) == 0x7b3d591e6a2c48);
21 expect(@bitReverse(u64, 0x123456789abcdef1) == 0x8f7b3d591e6a2c48);21 try expect(@bitReverse(u64, 0x123456789abcdef1) == 0x8f7b3d591e6a2c48);
22 expect(@bitReverse(u128, 0x123456789abcdef11121314151617181) == 0x818e868a828c84888f7b3d591e6a2c48);22 try expect(@bitReverse(u128, 0x123456789abcdef11121314151617181) == 0x818e868a828c84888f7b3d591e6a2c48);
2323
24 // using runtime uints, unsigned24 // using runtime uints, unsigned
25 var num0: u0 = 0;25 var num0: u0 = 0;
26 expect(@bitReverse(u0, num0) == 0);26 try expect(@bitReverse(u0, num0) == 0);
27 var num5: u5 = 0x12;27 var num5: u5 = 0x12;
28 expect(@bitReverse(u5, num5) == 0x9);28 try expect(@bitReverse(u5, num5) == 0x9);
29 var num8: u8 = 0x12;29 var num8: u8 = 0x12;
30 expect(@bitReverse(u8, num8) == 0x48);30 try expect(@bitReverse(u8, num8) == 0x48);
31 var num16: u16 = 0x1234;31 var num16: u16 = 0x1234;
32 expect(@bitReverse(u16, num16) == 0x2c48);32 try expect(@bitReverse(u16, num16) == 0x2c48);
33 var num24: u24 = 0x123456;33 var num24: u24 = 0x123456;
34 expect(@bitReverse(u24, num24) == 0x6a2c48);34 try expect(@bitReverse(u24, num24) == 0x6a2c48);
35 var num32: u32 = 0x12345678;35 var num32: u32 = 0x12345678;
36 expect(@bitReverse(u32, num32) == 0x1e6a2c48);36 try expect(@bitReverse(u32, num32) == 0x1e6a2c48);
37 var num40: u40 = 0x123456789a;37 var num40: u40 = 0x123456789a;
38 expect(@bitReverse(u40, num40) == 0x591e6a2c48);38 try expect(@bitReverse(u40, num40) == 0x591e6a2c48);
39 var num48: u48 = 0x123456789abc;39 var num48: u48 = 0x123456789abc;
40 expect(@bitReverse(u48, num48) == 0x3d591e6a2c48);40 try expect(@bitReverse(u48, num48) == 0x3d591e6a2c48);
41 var num56: u56 = 0x123456789abcde;41 var num56: u56 = 0x123456789abcde;
42 expect(@bitReverse(u56, num56) == 0x7b3d591e6a2c48);42 try expect(@bitReverse(u56, num56) == 0x7b3d591e6a2c48);
43 var num64: u64 = 0x123456789abcdef1;43 var num64: u64 = 0x123456789abcdef1;
44 expect(@bitReverse(u64, num64) == 0x8f7b3d591e6a2c48);44 try expect(@bitReverse(u64, num64) == 0x8f7b3d591e6a2c48);
45 var num128: u128 = 0x123456789abcdef11121314151617181;45 var num128: u128 = 0x123456789abcdef11121314151617181;
46 expect(@bitReverse(u128, num128) == 0x818e868a828c84888f7b3d591e6a2c48);46 try expect(@bitReverse(u128, num128) == 0x818e868a828c84888f7b3d591e6a2c48);
4747
48 // using comptime_ints, signed, positive48 // using comptime_ints, signed, positive
49 expect(@bitReverse(u8, @as(u8, 0)) == 0);49 try expect(@bitReverse(u8, @as(u8, 0)) == 0);
50 expect(@bitReverse(i8, @bitCast(i8, @as(u8, 0x92))) == @bitCast(i8, @as(u8, 0x49)));50 try 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)));51 try 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)));52 try 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)));53 try 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)));54 try 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)));55 try 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)));56 try 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)));57 try 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)));58 try expect(@bitReverse(i128, @bitCast(i128, @as(u128, 0x123456789abcdef11121314151617181))) == @bitCast(i128, @as(u128, 0x818e868a828c84888f7b3d591e6a2c48)));
5959
60 // using signed, negative. Compare to runtime ints returned from llvm.60 // using signed, negative. Compare to runtime ints returned from llvm.
61 var neg8: i8 = -18;61 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));
63 var neg16: i16 = -32694;63 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));
65 var neg24: i24 = -6773785;65 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));
67 var neg32: i32 = -16773785;67 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));
69}69}
test/behavior/bool.zig+11-11
...@@ -1,25 +1,25 @@...@@ -1,25 +1,25 @@
1const expect = @import("std").testing.expect;1const expect = @import("std").testing.expect;
22
3test "bool literals" {3test "bool literals" {
4 expect(true);4 try expect(true);
5 expect(!false);5 try expect(!false);
6}6}
77
8test "cast bool to int" {8test "cast bool to int" {
9 const t = true;9 const t = true;
10 const f = false;10 const f = false;
11 expect(@boolToInt(t) == @as(u32, 1));11 try expect(@boolToInt(t) == @as(u32, 1));
12 expect(@boolToInt(f) == @as(u32, 0));12 try expect(@boolToInt(f) == @as(u32, 0));
13 nonConstCastBoolToInt(t, f);13 try nonConstCastBoolToInt(t, f);
14}14}
1515
16fn nonConstCastBoolToInt(t: bool, f: bool) void {16fn nonConstCastBoolToInt(t: bool, f: bool) !void {
17 expect(@boolToInt(t) == @as(u32, 1));17 try expect(@boolToInt(t) == @as(u32, 1));
18 expect(@boolToInt(f) == @as(u32, 0));18 try expect(@boolToInt(f) == @as(u32, 0));
19}19}
2020
21test "bool cmp" {21test "bool cmp" {
22 expect(testBoolCmp(true, false) == false);22 try expect(testBoolCmp(true, false) == false);
23}23}
24fn testBoolCmp(a: bool, b: bool) bool {24fn testBoolCmp(a: bool, b: bool) bool {
25 return a == b;25 return a == b;
...@@ -30,6 +30,6 @@ const global_t = true;...@@ -30,6 +30,6 @@ const global_t = true;
30const not_global_f = !global_f;30const not_global_f = !global_f;
31const not_global_t = !global_t;31const not_global_t = !global_t;
32test "compile time bool not" {32test "compile time bool not" {
33 expect(not_global_f);33 try expect(not_global_f);
34 expect(!not_global_t);34 try expect(!not_global_t);
35}35}
test/behavior/bugs/1025.zig+1-1
...@@ -8,5 +8,5 @@ fn getA() A {...@@ -8,5 +8,5 @@ fn getA() A {
88
9test "bug 1025" {9test "bug 1025" {
10 const a = getA();10 const a = getA();
11 @import("std").testing.expect(a.B == u8);11 try @import("std").testing.expect(a.B == u8);
12}12}
test/behavior/bugs/1076.zig+5-5
...@@ -3,21 +3,21 @@ const mem = std.mem;...@@ -3,21 +3,21 @@ const mem = std.mem;
3const expect = std.testing.expect;3const expect = std.testing.expect;
44
5test "comptime code should not modify constant data" {5test "comptime code should not modify constant data" {
6 testCastPtrOfArrayToSliceAndPtr();6 try testCastPtrOfArrayToSliceAndPtr();
7 comptime testCastPtrOfArrayToSliceAndPtr();7 comptime try testCastPtrOfArrayToSliceAndPtr();
8}8}
99
10fn testCastPtrOfArrayToSliceAndPtr() void {10fn testCastPtrOfArrayToSliceAndPtr() !void {
11 {11 {
12 var array = "aoeu".*;12 var array = "aoeu".*;
13 const x: [*]u8 = &array;13 const x: [*]u8 = &array;
14 x[0] += 1;14 x[0] += 1;
15 expect(mem.eql(u8, array[0..], "boeu"));15 try expect(mem.eql(u8, array[0..], "boeu"));
16 }16 }
17 {17 {
18 var array: [4]u8 = "aoeu".*;18 var array: [4]u8 = "aoeu".*;
19 const x: [*]u8 = &array;19 const x: [*]u8 = &array;
20 x[0] += 1;20 x[0] += 1;
21 expect(mem.eql(u8, array[0..], "boeu"));21 try expect(mem.eql(u8, array[0..], "boeu"));
22 }22 }
23}23}
test/behavior/bugs/1120.zig+1-1
...@@ -19,5 +19,5 @@ test "bug 1120" {...@@ -19,5 +19,5 @@ test "bug 1120" {
19 1 => &b.a,19 1 => &b.a,
20 else => unreachable,20 else => unreachable,
21 };21 };
22 expect(ptr.* == 2);22 try expect(ptr.* == 2);
23}23}
test/behavior/bugs/1277.zig+1-1
...@@ -11,5 +11,5 @@ fn f() i32 {...@@ -11,5 +11,5 @@ fn f() i32 {
11}11}
1212
13test "don't emit an LLVM global for a const function when it's in an optional in a struct" {13test "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);
15}15}
test/behavior/bugs/1310.zig+1-1
...@@ -20,5 +20,5 @@ fn agent_callback(_vm: [*]VM, options: [*]u8) callconv(.C) i32 {...@@ -20,5 +20,5 @@ fn agent_callback(_vm: [*]VM, options: [*]u8) callconv(.C) i32 {
20}20}
2121
22test "fixed" {22test "fixed" {
23 expect(agent_callback(undefined, undefined) == 11);23 try expect(agent_callback(undefined, undefined) == 11);
24}24}
test/behavior/bugs/1322.zig+2-2
...@@ -13,7 +13,7 @@ const C = struct {};...@@ -13,7 +13,7 @@ const C = struct {};
1313
14test "tagged union with all void fields but a meaningful tag" {14test "tagged union with all void fields but a meaningful tag" {
15 var a: A = A{ .b = B{ .c = C{} } };15 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);
17 a = A{ .b = B.None };17 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);
19}19}
test/behavior/bugs/1381.zig+1-1
...@@ -17,5 +17,5 @@ test "union that needs padding bytes inside an array" {...@@ -17,5 +17,5 @@ test "union that needs padding bytes inside an array" {
17 };17 };
1818
19 const a = as[0].B;19 const a = as[0].B;
20 std.testing.expect(a.D == 1);20 try std.testing.expect(a.D == 1);
21}21}
test/behavior/bugs/1421.zig+1-1
...@@ -9,5 +9,5 @@ const S = struct {...@@ -9,5 +9,5 @@ const S = struct {
99
10test "functions with return type required to be comptime are generic" {10test "functions with return type required to be comptime are generic" {
11 const ti = S.method();11 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);
13}13}
test/behavior/bugs/1442.zig+1-1
...@@ -7,5 +7,5 @@ const Union = union(enum) {...@@ -7,5 +7,5 @@ const Union = union(enum) {
77
8test "const error union field alignment" {8test "const error union field alignment" {
9 var union_or_err: anyerror!Union = Union{ .Color = 1234 };9 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);
11}11}
test/behavior/bugs/1486.zig+2-2
...@@ -5,6 +5,6 @@ var global: u64 = 123;...@@ -5,6 +5,6 @@ var global: u64 = 123;
55
6test "constant pointer to global variable causes runtime load" {6test "constant pointer to global variable causes runtime load" {
7 global = 1234;7 global = 1234;
8 expect(&global == ptr);8 try expect(&global == ptr);
9 expect(ptr.* == 1234);9 try expect(ptr.* == 1234);
10}10}
test/behavior/bugs/1607.zig+4-4
...@@ -3,13 +3,13 @@ const testing = std.testing;...@@ -3,13 +3,13 @@ const testing = std.testing;
33
4const a = [_]u8{ 1, 2, 3 };4const a = [_]u8{ 1, 2, 3 };
55
6fn checkAddress(s: []const u8) void {6fn checkAddress(s: []const u8) !void {
7 for (s) |*i, j| {7 for (s) |*i, j| {
8 testing.expect(i == &a[j]);8 try testing.expect(i == &a[j]);
9 }9 }
10}10}
1111
12test "slices pointing at the same address as global array." {12test "slices pointing at the same address as global array." {
13 checkAddress(&a);13 try checkAddress(&a);
14 comptime checkAddress(&a);14 comptime try checkAddress(&a);
15}15}
test/behavior/bugs/1735.zig+1-1
...@@ -42,5 +42,5 @@ const a = struct {...@@ -42,5 +42,5 @@ const a = struct {
4242
43test "intialization" {43test "intialization" {
44 var t = a.init();44 var t = a.init();
45 std.testing.expect(t.foo.len == 0);45 try std.testing.expect(t.foo.len == 0);
46}46}
test/behavior/bugs/1741.zig+1-1
...@@ -2,5 +2,5 @@ const std = @import("std");...@@ -2,5 +2,5 @@ const std = @import("std");
22
3test "fixed" {3test "fixed" {
4 const x: f32 align(128) = 12.34;4 const x: f32 align(128) = 12.34;
5 std.testing.expect(@ptrToInt(&x) % 128 == 0);5 try std.testing.expect(@ptrToInt(&x) % 128 == 0);
6}6}
test/behavior/bugs/1851.zig+9-9
...@@ -2,25 +2,25 @@ const std = @import("std");...@@ -2,25 +2,25 @@ const std = @import("std");
2const expect = std.testing.expect;2const expect = std.testing.expect;
33
4test "allocation and looping over 3-byte integer" {4test "allocation and looping over 3-byte integer" {
5 expect(@sizeOf(u24) == 4);5 try expect(@sizeOf(u24) == 4);
6 expect(@sizeOf([1]u24) == 4);6 try expect(@sizeOf([1]u24) == 4);
7 expect(@alignOf(u24) == 4);7 try expect(@alignOf(u24) == 4);
8 expect(@alignOf([1]u24) == 4);8 try expect(@alignOf([1]u24) == 4);
99
10 var x = try std.testing.allocator.alloc(u24, 2);10 var x = try std.testing.allocator.alloc(u24, 2);
11 defer std.testing.allocator.free(x);11 defer std.testing.allocator.free(x);
12 expect(x.len == 2);12 try expect(x.len == 2);
13 x[0] = 0xFFFFFF;13 x[0] = 0xFFFFFF;
14 x[1] = 0xFFFFFF;14 x[1] = 0xFFFFFF;
1515
16 const bytes = std.mem.sliceAsBytes(x);16 const bytes = std.mem.sliceAsBytes(x);
17 expect(@TypeOf(bytes) == []align(4) u8);17 try expect(@TypeOf(bytes) == []align(4) u8);
18 expect(bytes.len == 8);18 try expect(bytes.len == 8);
1919
20 for (bytes) |*b| {20 for (bytes) |*b| {
21 b.* = 0x00;21 b.* = 0x00;
22 }22 }
2323
24 expect(x[0] == 0x00);24 try expect(x[0] == 0x00);
25 expect(x[1] == 0x00);25 try expect(x[1] == 0x00);
26}26}
test/behavior/bugs/2006.zig+2-2
...@@ -7,6 +7,6 @@ const S = struct {...@@ -7,6 +7,6 @@ const S = struct {
7test "bug 2006" {7test "bug 2006" {
8 var a: S = undefined;8 var a: S = undefined;
9 a = S{ .p = undefined };9 a = S{ .p = undefined };
10 expect(@sizeOf(S) != 0);10 try expect(@sizeOf(S) != 0);
11 expect(@sizeOf(*void) == 0);11 try expect(@sizeOf(*void) == 0);
12}12}
test/behavior/bugs/2114.zig+7-7
...@@ -7,13 +7,13 @@ fn ctz(x: anytype) usize {...@@ -7,13 +7,13 @@ fn ctz(x: anytype) usize {
7}7}
88
9test "fixed" {9test "fixed" {
10 testClz();10 try testClz();
11 comptime testClz();11 comptime try testClz();
12}12}
1313
14fn testClz() void {14fn testClz() !void {
15 expect(ctz(@as(u128, 0x40000000000000000000000000000000)) == 126);15 try expect(ctz(@as(u128, 0x40000000000000000000000000000000)) == 126);
16 expect(math.rotl(u128, @as(u128, 0x40000000000000000000000000000000), @as(u8, 1)) == @as(u128, 0x80000000000000000000000000000000));16 try expect(math.rotl(u128, @as(u128, 0x40000000000000000000000000000000), @as(u8, 1)) == @as(u128, 0x80000000000000000000000000000000));
17 expect(ctz(@as(u128, 0x80000000000000000000000000000000)) == 127);17 try expect(ctz(@as(u128, 0x80000000000000000000000000000000)) == 127);
18 expect(ctz(math.rotl(u128, @as(u128, 0x40000000000000000000000000000000), @as(u8, 1))) == 127);18 try expect(ctz(math.rotl(u128, @as(u128, 0x40000000000000000000000000000000), @as(u8, 1))) == 127);
19}19}
test/behavior/bugs/2889.zig+1-1
...@@ -27,5 +27,5 @@ fn parseNote() ?i32 {...@@ -27,5 +27,5 @@ fn parseNote() ?i32 {
2727
28test "fixed" {28test "fixed" {
29 const result = parseNote();29 const result = parseNote();
30 std.testing.expect(result.? == 9);30 try std.testing.expect(result.? == 9);
31}31}
test/behavior/bugs/3007.zig+1-1
...@@ -19,5 +19,5 @@ fn get_foo() Foo.FooError!*Foo {...@@ -19,5 +19,5 @@ fn get_foo() Foo.FooError!*Foo {
1919
20test "fixed" {20test "fixed" {
21 default_foo = get_foo() catch null; // This Line21 default_foo = get_foo() catch null; // This Line
22 std.testing.expect(!default_foo.?.free);22 try std.testing.expect(!default_foo.?.free);
23}23}
test/behavior/bugs/3046.zig+1-1
...@@ -15,5 +15,5 @@ test "fixed" {...@@ -15,5 +15,5 @@ test "fixed" {
15 some_struct = SomeStruct{15 some_struct = SomeStruct{
16 .field = couldFail() catch |_| @as(i32, 0),16 .field = couldFail() catch |_| @as(i32, 0),
17 };17 };
18 expect(some_struct.field == 1);18 try expect(some_struct.field == 1);
19}19}
test/behavior/bugs/3112.zig+1-1
...@@ -7,7 +7,7 @@ const State = struct {...@@ -7,7 +7,7 @@ const State = struct {
7};7};
88
9fn prev(p: ?State) void {9fn prev(p: ?State) void {
10 expect(p == null);10 expect(p == null) catch @panic("test failure");
11}11}
1212
13test "zig test crash" {13test "zig test crash" {
test/behavior/bugs/3384.zig+6-6
...@@ -2,10 +2,10 @@ const std = @import("std");...@@ -2,10 +2,10 @@ const std = @import("std");
2const expect = std.testing.expect;2const expect = std.testing.expect;
33
4test "resolve array slice using builtin" {4test "resolve array slice using builtin" {
5 expect(@hasDecl(@This(), "std") == true);5 try expect(@hasDecl(@This(), "std") == true);
6 expect(@hasDecl(@This(), "std"[0..0]) == false);6 try expect(@hasDecl(@This(), "std"[0..0]) == false);
7 expect(@hasDecl(@This(), "std"[0..1]) == false);7 try expect(@hasDecl(@This(), "std"[0..1]) == false);
8 expect(@hasDecl(@This(), "std"[0..2]) == false);8 try expect(@hasDecl(@This(), "std"[0..2]) == false);
9 expect(@hasDecl(@This(), "std"[0..3]) == true);9 try expect(@hasDecl(@This(), "std"[0..3]) == true);
10 expect(@hasDecl(@This(), "std"[0..]) == true);10 try expect(@hasDecl(@This(), "std"[0..]) == true);
11}11}
test/behavior/bugs/394.zig+1-1
...@@ -14,5 +14,5 @@ test "bug 394 fixed" {...@@ -14,5 +14,5 @@ test "bug 394 fixed" {
14 .x = 3,14 .x = 3,
15 .y = E{ .B = 1 },15 .y = E{ .B = 1 },
16 };16 };
17 expect(x.x == 3);17 try expect(x.x == 3);
18}18}
test/behavior/bugs/421.zig+4-4
...@@ -1,12 +1,12 @@...@@ -1,12 +1,12 @@
1const expect = @import("std").testing.expect;1const expect = @import("std").testing.expect;
22
3test "bitCast to array" {3test "bitCast to array" {
4 comptime testBitCastArray();4 comptime try testBitCastArray();
5 testBitCastArray();5 try testBitCastArray();
6}6}
77
8fn testBitCastArray() void {8fn testBitCastArray() !void {
9 expect(extractOne64(0x0123456789abcdef0123456789abcdef) == 0x0123456789abcdef);9 try expect(extractOne64(0x0123456789abcdef0123456789abcdef) == 0x0123456789abcdef);
10}10}
1111
12fn extractOne64(a: u128) u64 {12fn extractOne64(a: u128) u64 {
test/behavior/bugs/4328.zig+14-14
...@@ -25,14 +25,14 @@ test "Extern function calls in @TypeOf" {...@@ -25,14 +25,14 @@ test "Extern function calls in @TypeOf" {
25 return 1;25 return 1;
26 }26 }
2727
28 fn doTheTest() void {28 fn doTheTest() !void {
29 expectEqual(c_int, @TypeOf(test_fn_1(0, 42)));29 try expectEqual(c_int, @TypeOf(test_fn_1(0, 42)));
30 expectEqual(c_short, @TypeOf(test_fn_2(0)));30 try expectEqual(c_short, @TypeOf(test_fn_2(0)));
31 }31 }
32 };32 };
3333
34 Test.doTheTest();34 try Test.doTheTest();
35 comptime Test.doTheTest();35 comptime try Test.doTheTest();
36}36}
3737
38test "Peer resolution of extern function calls in @TypeOf" {38test "Peer resolution of extern function calls in @TypeOf" {
...@@ -41,13 +41,13 @@ test "Peer resolution of extern function calls in @TypeOf" {...@@ -41,13 +41,13 @@ test "Peer resolution of extern function calls in @TypeOf" {
41 return 0;41 return 0;
42 }42 }
4343
44 fn doTheTest() void {44 fn doTheTest() !void {
45 expectEqual(c_long, @TypeOf(test_fn()));45 try expectEqual(c_long, @TypeOf(test_fn()));
46 }46 }
47 };47 };
4848
49 Test.doTheTest();49 try Test.doTheTest();
50 comptime Test.doTheTest();50 comptime try Test.doTheTest();
51}51}
5252
53test "Extern function calls, dereferences and field access in @TypeOf" {53test "Extern function calls, dereferences and field access in @TypeOf" {
...@@ -60,12 +60,12 @@ test "Extern function calls, dereferences and field access in @TypeOf" {...@@ -60,12 +60,12 @@ test "Extern function calls, dereferences and field access in @TypeOf" {
60 return 255;60 return 255;
61 }61 }
6262
63 fn doTheTest() void {63 fn doTheTest() !void {
64 expectEqual(FILE, @TypeOf(test_fn_1(0)));64 try expectEqual(FILE, @TypeOf(test_fn_1(0)));
65 expectEqual(u8, @TypeOf(test_fn_2(0)));65 try expectEqual(u8, @TypeOf(test_fn_2(0)));
66 }66 }
67 };67 };
6868
69 Test.doTheTest();69 try Test.doTheTest();
70 comptime Test.doTheTest();70 comptime try Test.doTheTest();
71}71}
test/behavior/bugs/4560.zig+3-3
...@@ -8,9 +8,9 @@ test "fixed" {...@@ -8,9 +8,9 @@ test "fixed" {
8 .max_distance_from_start_index = 456,8 .max_distance_from_start_index = 456,
9 },9 },
10 };10 };
11 std.testing.expect(s.a == 1);11 try std.testing.expect(s.a == 1);
12 std.testing.expect(s.b.size == 123);12 try std.testing.expect(s.b.size == 123);
13 std.testing.expect(s.b.max_distance_from_start_index == 456);13 try std.testing.expect(s.b.max_distance_from_start_index == 456);
14}14}
1515
16const S = struct {16const S = struct {
test/behavior/bugs/4769_a.zig+1-1
...@@ -1 +1 @@...@@ -1 +1 @@
1//
\ No newline at end of file
1//
test/behavior/bugs/4769_b.zig+1-1
...@@ -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" {...@@ -25,7 +25,7 @@ test "assignment of field with padding" {
25 .emits_shadows = false,25 .emits_shadows = false,
26 },26 },
27 };27 };
28 testing.expectEqual(false, renderable.material.transparent);28 try testing.expectEqual(false, renderable.material.transparent);
29 testing.expectEqual(false, renderable.material.emits_shadows);29 try testing.expectEqual(false, renderable.material.emits_shadows);
30 testing.expectEqual(true, renderable.material.render_color);30 try testing.expectEqual(true, renderable.material.render_color);
31}31}
test/behavior/bugs/5413.zig+2-2
...@@ -1,6 +1,6 @@...@@ -1,6 +1,6 @@
1const expect = @import("std").testing.expect;1const expect = @import("std").testing.expect;
22
3test "Peer type resolution with string literals and unknown length u8 pointers" {3test "Peer type resolution with string literals and unknown length u8 pointers" {
4 expect(@TypeOf("", "a", @as([*:0]const u8, "")) == [*:0]const u8);4 try expect(@TypeOf("", "a", @as([*:0]const u8, "")) == [*:0]const u8);
5 expect(@TypeOf(@as([*:0]const u8, "baz"), "foo", "bar") == [*:0]const u8);5 try expect(@TypeOf(@as([*:0]const u8, "baz"), "foo", "bar") == [*:0]const u8);
6}6}
test/behavior/bugs/5474.zig+9-9
...@@ -25,33 +25,33 @@ const Box2 = struct {...@@ -25,33 +25,33 @@ const Box2 = struct {
25 };25 };
26};26};
2727
28fn doTest() void {28fn doTest() !void {
29 // var29 // var
30 {30 {
31 var box0: Box0 = .{ .items = undefined };31 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
34 var box1: Box1 = .{ .items = undefined };34 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
37 var box2: Box2 = .{ .items = undefined };37 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);
39 }39 }
4040
41 // const41 // const
42 {42 {
43 const box0: Box0 = .{ .items = undefined };43 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
46 const box1: Box1 = .{ .items = undefined };46 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
49 const box2: Box2 = .{ .items = undefined };49 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);
51 }51 }
52}52}
5353
54test "pointer-to-array constness for zero-size elements" {54test "pointer-to-array constness for zero-size elements" {
55 doTest();55 try doTest();
56 comptime doTest();56 comptime try doTest();
57}57}
test/behavior/bugs/624.zig+1-1
...@@ -19,5 +19,5 @@ fn MemoryPool(comptime T: type) type {...@@ -19,5 +19,5 @@ fn MemoryPool(comptime T: type) type {
1919
20test "foo" {20test "foo" {
21 var allocator = ContextAllocator{ .n = 10 };21 var allocator = ContextAllocator{ .n = 10 };
22 expect(allocator.n == 10);22 try expect(allocator.n == 10);
23}23}
test/behavior/bugs/6456.zig+4-4
...@@ -34,9 +34,9 @@ test "issue 6456" {...@@ -34,9 +34,9 @@ test "issue 6456" {
34 });34 });
3535
36 const gen_fields = @typeInfo(T).Struct.fields;36 const gen_fields = @typeInfo(T).Struct.fields;
37 testing.expectEqual(3, gen_fields.len);37 try testing.expectEqual(3, gen_fields.len);
38 testing.expectEqualStrings("f1", gen_fields[0].name);38 try testing.expectEqualStrings("f1", gen_fields[0].name);
39 testing.expectEqualStrings("f2", gen_fields[1].name);39 try testing.expectEqualStrings("f2", gen_fields[1].name);
40 testing.expectEqualStrings("f3", gen_fields[2].name);40 try testing.expectEqualStrings("f3", gen_fields[2].name);
41 }41 }
42}42}
test/behavior/bugs/655.zig+4-4
...@@ -3,10 +3,10 @@ const other_file = @import("655_other_file.zig");...@@ -3,10 +3,10 @@ const other_file = @import("655_other_file.zig");
33
4test "function with *const parameter with type dereferenced by namespace" {4test "function with *const parameter with type dereferenced by namespace" {
5 const x: other_file.Integer = 1234;5 const x: other_file.Integer = 1234;
6 comptime std.testing.expect(@TypeOf(&x) == *const other_file.Integer);6 comptime try std.testing.expect(@TypeOf(&x) == *const other_file.Integer);
7 foo(&x);7 try foo(&x);
8}8}
99
10fn foo(x: *const other_file.Integer) void {10fn foo(x: *const other_file.Integer) !void {
11 std.testing.expect(x.* == 1234);11 try std.testing.expect(x.* == 1234);
12}12}
test/behavior/bugs/656.zig+3-3
...@@ -10,10 +10,10 @@ const Value = struct {...@@ -10,10 +10,10 @@ const Value = struct {
10};10};
1111
12test "optional if after an if in a switch prong of a switch with 2 prongs in an else" {12test "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);
14}14}
1515
16fn foo(a: bool, b: bool) void {16fn foo(a: bool, b: bool) !void {
17 var prefix_op = PrefixOp{17 var prefix_op = PrefixOp{
18 .AddrOf = Value{ .align_expr = 1234 },18 .AddrOf = Value{ .align_expr = 1234 },
19 };19 };
...@@ -22,7 +22,7 @@ fn foo(a: bool, b: bool) void {...@@ -22,7 +22,7 @@ fn foo(a: bool, b: bool) void {
22 PrefixOp.AddrOf => |addr_of_info| {22 PrefixOp.AddrOf => |addr_of_info| {
23 if (b) {}23 if (b) {}
24 if (addr_of_info.align_expr) |align_expr| {24 if (addr_of_info.align_expr) |align_expr| {
25 expect(align_expr == 1234);25 try expect(align_expr == 1234);
26 }26 }
27 },27 },
28 PrefixOp.Return => {},28 PrefixOp.Return => {},
test/behavior/bugs/679.zig+1-1
...@@ -13,5 +13,5 @@ const Element = struct {...@@ -13,5 +13,5 @@ const Element = struct {
13test "false dependency loop in struct definition" {13test "false dependency loop in struct definition" {
14 const listType = ElementList;14 const listType = ElementList;
15 var x: listType = 42;15 var x: listType = 42;
16 expect(x == 42);16 try expect(x == 42);
17}17}
test/behavior/bugs/6850.zig+1-1
...@@ -4,7 +4,7 @@ test "lazy sizeof comparison with zero" {...@@ -4,7 +4,7 @@ test "lazy sizeof comparison with zero" {
4 const Empty = struct {};4 const Empty = struct {};
5 const T = *Empty;5 const T = *Empty;
66
7 std.testing.expect(hasNoBits(T));7 try std.testing.expect(hasNoBits(T));
8}8}
99
10fn hasNoBits(comptime T: type) bool {10fn hasNoBits(comptime T: type) bool {
test/behavior/bugs/7047.zig+2-2
...@@ -15,8 +15,8 @@ fn S(comptime query: U) type {...@@ -15,8 +15,8 @@ fn S(comptime query: U) type {
1515
16test "compiler doesn't consider equal unions with different 'type' payload" {16test "compiler doesn't consider equal unions with different 'type' payload" {
17 const s1 = S(U{ .T = u32 }).tag();17 const s1 = S(U{ .T = u32 }).tag();
18 std.testing.expectEqual(u32, s1);18 try std.testing.expectEqual(u32, s1);
1919
20 const s2 = S(U{ .T = u64 }).tag();20 const s2 = S(U{ .T = u64 }).tag();
21 std.testing.expectEqual(u64, s2);21 try std.testing.expectEqual(u64, s2);
22}22}
test/behavior/bugs/718.zig+4-4
...@@ -10,8 +10,8 @@ const Keys = struct {...@@ -10,8 +10,8 @@ const Keys = struct {
10var keys: Keys = undefined;10var keys: Keys = undefined;
11test "zero keys with @memset" {11test "zero keys with @memset" {
12 @memset(@ptrCast([*]u8, &keys), 0, @sizeOf(@TypeOf(keys)));12 @memset(@ptrCast([*]u8, &keys), 0, @sizeOf(@TypeOf(keys)));
13 expect(!keys.up);13 try expect(!keys.up);
14 expect(!keys.down);14 try expect(!keys.down);
15 expect(!keys.left);15 try expect(!keys.left);
16 expect(!keys.right);16 try expect(!keys.right);
17}17}
test/behavior/bugs/726.zig+2-2
...@@ -3,7 +3,7 @@ const expect = @import("std").testing.expect;...@@ -3,7 +3,7 @@ const expect = @import("std").testing.expect;
3test "@ptrCast from const to nullable" {3test "@ptrCast from const to nullable" {
4 const c: u8 = 4;4 const c: u8 = 4;
5 var x: ?*const u8 = @ptrCast(?*const u8, &c);5 var x: ?*const u8 = @ptrCast(?*const u8, &c);
6 expect(x.?.* == 4);6 try expect(x.?.* == 4);
7}7}
88
9test "@ptrCast from var in empty struct to nullable" {9test "@ptrCast from var in empty struct to nullable" {
...@@ -11,5 +11,5 @@ test "@ptrCast from var in empty struct to nullable" {...@@ -11,5 +11,5 @@ test "@ptrCast from var in empty struct to nullable" {
11 var c: u8 = 4;11 var c: u8 = 4;
12 };12 };
13 var x: ?*const u8 = @ptrCast(?*const u8, &container.c);13 var x: ?*const u8 = @ptrCast(?*const u8, &container.c);
14 expect(x.?.* == 4);14 try expect(x.?.* == 4);
15}15}
test/behavior/bugs/920.zig+1-1
...@@ -60,6 +60,6 @@ test "bug 920 fixed" {...@@ -60,6 +60,6 @@ test "bug 920 fixed" {
60 };60 };
6161
62 for (NormalDist1.f) |_, i| {62 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]);
64 }64 }
65}65}
test/behavior/byteswap.zig+33-33
...@@ -3,39 +3,39 @@ const expect = std.testing.expect;...@@ -3,39 +3,39 @@ const expect = std.testing.expect;
33
4test "@byteSwap integers" {4test "@byteSwap integers" {
5 const ByteSwapIntTest = struct {5 const ByteSwapIntTest = struct {
6 fn run() void {6 fn run() !void {
7 t(u0, 0, 0);7 try t(u0, 0, 0);
8 t(u8, 0x12, 0x12);8 try t(u8, 0x12, 0x12);
9 t(u16, 0x1234, 0x3412);9 try t(u16, 0x1234, 0x3412);
10 t(u24, 0x123456, 0x563412);10 try t(u24, 0x123456, 0x563412);
11 t(u32, 0x12345678, 0x78563412);11 try t(u32, 0x12345678, 0x78563412);
12 t(u40, 0x123456789a, 0x9a78563412);12 try t(u40, 0x123456789a, 0x9a78563412);
13 t(i48, 0x123456789abc, @bitCast(i48, @as(u48, 0xbc9a78563412)));13 try t(i48, 0x123456789abc, @bitCast(i48, @as(u48, 0xbc9a78563412)));
14 t(u56, 0x123456789abcde, 0xdebc9a78563412);14 try t(u56, 0x123456789abcde, 0xdebc9a78563412);
15 t(u64, 0x123456789abcdef1, 0xf1debc9a78563412);15 try t(u64, 0x123456789abcdef1, 0xf1debc9a78563412);
16 t(u128, 0x123456789abcdef11121314151617181, 0x8171615141312111f1debc9a78563412);16 try t(u128, 0x123456789abcdef11121314151617181, 0x8171615141312111f1debc9a78563412);
1717
18 t(u0, @as(u0, 0), 0);18 try t(u0, @as(u0, 0), 0);
19 t(i8, @as(i8, -50), -50);19 try t(i8, @as(i8, -50), -50);
20 t(i16, @bitCast(i16, @as(u16, 0x1234)), @bitCast(i16, @as(u16, 0x3412)));20 try 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)));21 try 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)));22 try t(i32, @bitCast(i32, @as(u32, 0x12345678)), @bitCast(i32, @as(u32, 0x78563412)));
23 t(u40, @bitCast(i40, @as(u40, 0x123456789a)), @as(u40, 0x9a78563412));23 try t(u40, @bitCast(i40, @as(u40, 0x123456789a)), @as(u40, 0x9a78563412));
24 t(i48, @bitCast(i48, @as(u48, 0x123456789abc)), @bitCast(i48, @as(u48, 0xbc9a78563412)));24 try 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)));25 try 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)));26 try t(i64, @bitCast(i64, @as(u64, 0x123456789abcdef1)), @bitCast(i64, @as(u64, 0xf1debc9a78563412)));
27 t(27 try t(
28 i128,28 i128,
29 @bitCast(i128, @as(u128, 0x123456789abcdef11121314151617181)),29 @bitCast(i128, @as(u128, 0x123456789abcdef11121314151617181)),
30 @bitCast(i128, @as(u128, 0x8171615141312111f1debc9a78563412)),30 @bitCast(i128, @as(u128, 0x8171615141312111f1debc9a78563412)),
31 );31 );
32 }32 }
33 fn t(comptime I: type, input: I, expected_output: I) void {33 fn t(comptime I: type, input: I, expected_output: I) !void {
34 std.testing.expectEqual(expected_output, @byteSwap(I, input));34 try std.testing.expectEqual(expected_output, @byteSwap(I, input));
35 }35 }
36 };36 };
37 comptime ByteSwapIntTest.run();37 comptime try ByteSwapIntTest.run();
38 ByteSwapIntTest.run();38 try ByteSwapIntTest.run();
39}39}
4040
41test "@byteSwap vectors" {41test "@byteSwap vectors" {
...@@ -46,10 +46,10 @@ test "@byteSwap vectors" {...@@ -46,10 +46,10 @@ test "@byteSwap vectors" {
46 if (std.Target.current.cpu.arch == .mipsel or std.Target.current.cpu.arch == .mips) return error.SkipZigTest;46 if (std.Target.current.cpu.arch == .mipsel or std.Target.current.cpu.arch == .mips) return error.SkipZigTest;
4747
48 const ByteSwapVectorTest = struct {48 const ByteSwapVectorTest = struct {
49 fn run() void {49 fn run() !void {
50 t(u8, 2, [_]u8{ 0x12, 0x13 }, [_]u8{ 0x12, 0x13 });50 try t(u8, 2, [_]u8{ 0x12, 0x13 }, [_]u8{ 0x12, 0x13 });
51 t(u16, 2, [_]u16{ 0x1234, 0x2345 }, [_]u16{ 0x3412, 0x4523 });51 try t(u16, 2, [_]u16{ 0x1234, 0x2345 }, [_]u16{ 0x3412, 0x4523 });
52 t(u24, 2, [_]u24{ 0x123456, 0x234567 }, [_]u24{ 0x563412, 0x674523 });52 try t(u24, 2, [_]u24{ 0x123456, 0x234567 }, [_]u24{ 0x563412, 0x674523 });
53 }53 }
5454
55 fn t(55 fn t(
...@@ -57,12 +57,12 @@ test "@byteSwap vectors" {...@@ -57,12 +57,12 @@ test "@byteSwap vectors" {
57 comptime n: comptime_int,57 comptime n: comptime_int,
58 input: std.meta.Vector(n, I),58 input: std.meta.Vector(n, I),
59 expected_vector: std.meta.Vector(n, I),59 expected_vector: std.meta.Vector(n, I),
60 ) void {60 ) !void {
61 const actual_output: [n]I = @byteSwap(I, input);61 const actual_output: [n]I = @byteSwap(I, input);
62 const expected_output: [n]I = expected_vector;62 const expected_output: [n]I = expected_vector;
63 std.testing.expectEqual(expected_output, actual_output);63 try std.testing.expectEqual(expected_output, actual_output);
64 }64 }
65 };65 };
66 comptime ByteSwapVectorTest.run();66 comptime try ByteSwapVectorTest.run();
67 ByteSwapVectorTest.run();67 try ByteSwapVectorTest.run();
68}68}
test/behavior/byval_arg_var.zig+1-1
...@@ -6,7 +6,7 @@ test "pass string literal byvalue to a generic var param" {...@@ -6,7 +6,7 @@ test "pass string literal byvalue to a generic var param" {
6 start();6 start();
7 blowUpStack(10);7 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"));
10}10}
1111
12fn start() void {12fn start() void {
test/behavior/call.zig+19-19
...@@ -8,25 +8,25 @@ test "basic invocations" {...@@ -8,25 +8,25 @@ test "basic invocations" {
8 return 1234;8 return 1234;
9 }9 }
10 }.foo;10 }.foo;
11 expect(@call(.{}, foo, .{}) == 1234);11 try expect(@call(.{}, foo, .{}) == 1234);
12 comptime {12 comptime {
13 // modifiers that allow comptime calls13 // modifiers that allow comptime calls
14 expect(@call(.{}, foo, .{}) == 1234);14 try expect(@call(.{}, foo, .{}) == 1234);
15 expect(@call(.{ .modifier = .no_async }, foo, .{}) == 1234);15 try expect(@call(.{ .modifier = .no_async }, foo, .{}) == 1234);
16 expect(@call(.{ .modifier = .always_tail }, foo, .{}) == 1234);16 try expect(@call(.{ .modifier = .always_tail }, foo, .{}) == 1234);
17 expect(@call(.{ .modifier = .always_inline }, foo, .{}) == 1234);17 try expect(@call(.{ .modifier = .always_inline }, foo, .{}) == 1234);
18 }18 }
19 {19 {
20 // comptime call without comptime keyword20 // comptime call without comptime keyword
21 const result = @call(.{ .modifier = .compile_time }, foo, .{}) == 1234;21 const result = @call(.{ .modifier = .compile_time }, foo, .{}) == 1234;
22 comptime expect(result);22 comptime try expect(result);
23 }23 }
24 {24 {
25 // call of non comptime-known function25 // call of non comptime-known function
26 var alias_foo = foo;26 var alias_foo = foo;
27 expect(@call(.{ .modifier = .no_async }, alias_foo, .{}) == 1234);27 try expect(@call(.{ .modifier = .no_async }, alias_foo, .{}) == 1234);
28 expect(@call(.{ .modifier = .never_tail }, alias_foo, .{}) == 1234);28 try expect(@call(.{ .modifier = .never_tail }, alias_foo, .{}) == 1234);
29 expect(@call(.{ .modifier = .never_inline }, alias_foo, .{}) == 1234);29 try expect(@call(.{ .modifier = .never_inline }, alias_foo, .{}) == 1234);
30 }30 }
31}31}
3232
...@@ -38,20 +38,20 @@ test "tuple parameters" {...@@ -38,20 +38,20 @@ test "tuple parameters" {
38 }.add;38 }.add;
39 var a: i32 = 12;39 var a: i32 = 12;
40 var b: i32 = 34;40 var b: i32 = 34;
41 expect(@call(.{}, add, .{ a, 34 }) == 46);41 try expect(@call(.{}, add, .{ a, 34 }) == 46);
42 expect(@call(.{}, add, .{ 12, b }) == 46);42 try expect(@call(.{}, add, .{ 12, b }) == 46);
43 expect(@call(.{}, add, .{ a, b }) == 46);43 try expect(@call(.{}, add, .{ a, b }) == 46);
44 expect(@call(.{}, add, .{ 12, 34 }) == 46);44 try expect(@call(.{}, add, .{ 12, 34 }) == 46);
45 comptime expect(@call(.{}, add, .{ 12, 34 }) == 46);45 comptime try expect(@call(.{}, add, .{ 12, 34 }) == 46);
46 {46 {
47 const separate_args0 = .{ a, b };47 const separate_args0 = .{ a, b };
48 const separate_args1 = .{ a, 34 };48 const separate_args1 = .{ a, 34 };
49 const separate_args2 = .{ 12, 34 };49 const separate_args2 = .{ 12, 34 };
50 const separate_args3 = .{ 12, b };50 const separate_args3 = .{ 12, b };
51 expect(@call(.{ .modifier = .always_inline }, add, separate_args0) == 46);51 try expect(@call(.{ .modifier = .always_inline }, add, separate_args0) == 46);
52 expect(@call(.{ .modifier = .always_inline }, add, separate_args1) == 46);52 try expect(@call(.{ .modifier = .always_inline }, add, separate_args1) == 46);
53 expect(@call(.{ .modifier = .always_inline }, add, separate_args2) == 46);53 try expect(@call(.{ .modifier = .always_inline }, add, separate_args2) == 46);
54 expect(@call(.{ .modifier = .always_inline }, add, separate_args3) == 46);54 try expect(@call(.{ .modifier = .always_inline }, add, separate_args3) == 46);
55 }55 }
56}56}
5757
...@@ -70,5 +70,5 @@ test "comptime call with bound function as parameter" {...@@ -70,5 +70,5 @@ test "comptime call with bound function as parameter" {
70 };70 };
7171
72 var inst: S = undefined;72 var inst: S = undefined;
73 expectEqual(?i32, S.ReturnType(inst.call_me_maybe));73 try expectEqual(?i32, S.ReturnType(inst.call_me_maybe));
74}74}
test/behavior/cast.zig+226-226
...@@ -9,12 +9,12 @@ test "int to ptr cast" {...@@ -9,12 +9,12 @@ test "int to ptr cast" {
9 const x = @as(usize, 13);9 const x = @as(usize, 13);
10 const y = @intToPtr(*u8, x);10 const y = @intToPtr(*u8, x);
11 const z = @ptrToInt(y);11 const z = @ptrToInt(y);
12 expect(z == 13);12 try expect(z == 13);
13}13}
1414
15test "integer literal to pointer cast" {15test "integer literal to pointer cast" {
16 const vga_mem = @intToPtr(*u16, 0xB8000);16 const vga_mem = @intToPtr(*u16, 0xB8000);
17 expect(@ptrToInt(vga_mem) == 0xB8000);17 try expect(@ptrToInt(vga_mem) == 0xB8000);
18}18}
1919
20test "pointer reinterpret const float to int" {20test "pointer reinterpret const float to int" {
...@@ -24,9 +24,9 @@ test "pointer reinterpret const float to int" {...@@ -24,9 +24,9 @@ test "pointer reinterpret const float to int" {
24 const int_ptr = @ptrCast(*const i32, float_ptr);24 const int_ptr = @ptrCast(*const i32, float_ptr);
25 const int_val = int_ptr.*;25 const int_val = int_ptr.*;
26 if (native_endian == .Little)26 if (native_endian == .Little)
27 expect(int_val == 0x33333303)27 try expect(int_val == 0x33333303)
28 else28 else
29 expect(int_val == 0x3fe33333);29 try expect(int_val == 0x3fe33333);
30}30}
3131
32test "implicitly cast indirect pointer to maybe-indirect pointer" {32test "implicitly cast indirect pointer to maybe-indirect pointer" {
...@@ -50,62 +50,62 @@ test "implicitly cast indirect pointer to maybe-indirect pointer" {...@@ -50,62 +50,62 @@ test "implicitly cast indirect pointer to maybe-indirect pointer" {
50 const p = &s;50 const p = &s;
51 const q = &p;51 const q = &p;
52 const r = &q;52 const r = &q;
53 expect(42 == S.constConst(q));53 try expect(42 == S.constConst(q));
54 expect(42 == S.maybeConstConst(q));54 try expect(42 == S.maybeConstConst(q));
55 expect(42 == S.constConstConst(r));55 try expect(42 == S.constConstConst(r));
56 expect(42 == S.maybeConstConstConst(r));56 try expect(42 == S.maybeConstConstConst(r));
57}57}
5858
59test "explicit cast from integer to error type" {59test "explicit cast from integer to error type" {
60 testCastIntToErr(error.ItBroke);60 try testCastIntToErr(error.ItBroke);
61 comptime testCastIntToErr(error.ItBroke);61 comptime try testCastIntToErr(error.ItBroke);
62}62}
63fn testCastIntToErr(err: anyerror) void {63fn testCastIntToErr(err: anyerror) !void {
64 const x = @errorToInt(err);64 const x = @errorToInt(err);
65 const y = @intToError(x);65 const y = @intToError(x);
66 expect(error.ItBroke == y);66 try expect(error.ItBroke == y);
67}67}
6868
69test "peer resolve arrays of different size to const slice" {69test "peer resolve arrays of different size to const slice" {
70 expect(mem.eql(u8, boolToStr(true), "true"));70 try expect(mem.eql(u8, boolToStr(true), "true"));
71 expect(mem.eql(u8, boolToStr(false), "false"));71 try expect(mem.eql(u8, boolToStr(false), "false"));
72 comptime expect(mem.eql(u8, boolToStr(true), "true"));72 comptime try expect(mem.eql(u8, boolToStr(true), "true"));
73 comptime expect(mem.eql(u8, boolToStr(false), "false"));73 comptime try expect(mem.eql(u8, boolToStr(false), "false"));
74}74}
75fn boolToStr(b: bool) []const u8 {75fn boolToStr(b: bool) []const u8 {
76 return if (b) "true" else "false";76 return if (b) "true" else "false";
77}77}
7878
79test "peer resolve array and const slice" {79test "peer resolve array and const slice" {
80 testPeerResolveArrayConstSlice(true);80 try testPeerResolveArrayConstSlice(true);
81 comptime testPeerResolveArrayConstSlice(true);81 comptime try testPeerResolveArrayConstSlice(true);
82}82}
83fn testPeerResolveArrayConstSlice(b: bool) void {83fn testPeerResolveArrayConstSlice(b: bool) !void {
84 const value1 = if (b) "aoeu" else @as([]const u8, "zz");84 const value1 = if (b) "aoeu" else @as([]const u8, "zz");
85 const value2 = if (b) @as([]const u8, "zz") else "aoeu";85 const value2 = if (b) @as([]const u8, "zz") else "aoeu";
86 expect(mem.eql(u8, value1, "aoeu"));86 try expect(mem.eql(u8, value1, "aoeu"));
87 expect(mem.eql(u8, value2, "zz"));87 try expect(mem.eql(u8, value2, "zz"));
88}88}
8989
90test "implicitly cast from T to anyerror!?T" {90test "implicitly cast from T to anyerror!?T" {
91 castToOptionalTypeError(1);91 try castToOptionalTypeError(1);
92 comptime castToOptionalTypeError(1);92 comptime try castToOptionalTypeError(1);
93}93}
9494
95const A = struct {95const A = struct {
96 a: i32,96 a: i32,
97};97};
98fn castToOptionalTypeError(z: i32) void {98fn castToOptionalTypeError(z: i32) !void {
99 const x = @as(i32, 1);99 const x = @as(i32, 1);
100 const y: anyerror!?i32 = x;100 const y: anyerror!?i32 = x;
101 expect((try y).? == 1);101 try expect((try y).? == 1);
102102
103 const f = z;103 const f = z;
104 const g: anyerror!?i32 = f;104 const g: anyerror!?i32 = f;
105105
106 const a = A{ .a = z };106 const a = A{ .a = z };
107 const b: anyerror!?A = a;107 const b: anyerror!?A = a;
108 expect((b catch unreachable).?.a == 1);108 try expect((b catch unreachable).?.a == 1);
109}109}
110110
111test "implicitly cast from int to anyerror!?T" {111test "implicitly cast from int to anyerror!?T" {
...@@ -120,7 +120,7 @@ fn implicitIntLitToOptional() void {...@@ -120,7 +120,7 @@ fn implicitIntLitToOptional() void {
120test "return null from fn() anyerror!?&T" {120test "return null from fn() anyerror!?&T" {
121 const a = returnNullFromOptionalTypeErrorRef();121 const a = returnNullFromOptionalTypeErrorRef();
122 const b = returnNullLitFromOptionalTypeErrorRef();122 const b = returnNullLitFromOptionalTypeErrorRef();
123 expect((try a) == null and (try b) == null);123 try expect((try a) == null and (try b) == null);
124}124}
125fn returnNullFromOptionalTypeErrorRef() anyerror!?*A {125fn returnNullFromOptionalTypeErrorRef() anyerror!?*A {
126 const a: ?*A = null;126 const a: ?*A = null;
...@@ -131,11 +131,11 @@ fn returnNullLitFromOptionalTypeErrorRef() anyerror!?*A {...@@ -131,11 +131,11 @@ fn returnNullLitFromOptionalTypeErrorRef() anyerror!?*A {
131}131}
132132
133test "peer type resolution: ?T and T" {133test "peer type resolution: ?T and T" {
134 expect(peerTypeTAndOptionalT(true, false).? == 0);134 try expect(peerTypeTAndOptionalT(true, false).? == 0);
135 expect(peerTypeTAndOptionalT(false, false).? == 3);135 try expect(peerTypeTAndOptionalT(false, false).? == 3);
136 comptime {136 comptime {
137 expect(peerTypeTAndOptionalT(true, false).? == 0);137 try expect(peerTypeTAndOptionalT(true, false).? == 0);
138 expect(peerTypeTAndOptionalT(false, false).? == 3);138 try expect(peerTypeTAndOptionalT(false, false).? == 3);
139 }139 }
140}140}
141fn peerTypeTAndOptionalT(c: bool, b: bool) ?usize {141fn peerTypeTAndOptionalT(c: bool, b: bool) ?usize {
...@@ -147,11 +147,11 @@ fn peerTypeTAndOptionalT(c: bool, b: bool) ?usize {...@@ -147,11 +147,11 @@ fn peerTypeTAndOptionalT(c: bool, b: bool) ?usize {
147}147}
148148
149test "peer type resolution: [0]u8 and []const u8" {149test "peer type resolution: [0]u8 and []const u8" {
150 expect(peerTypeEmptyArrayAndSlice(true, "hi").len == 0);150 try expect(peerTypeEmptyArrayAndSlice(true, "hi").len == 0);
151 expect(peerTypeEmptyArrayAndSlice(false, "hi").len == 1);151 try expect(peerTypeEmptyArrayAndSlice(false, "hi").len == 1);
152 comptime {152 comptime {
153 expect(peerTypeEmptyArrayAndSlice(true, "hi").len == 0);153 try expect(peerTypeEmptyArrayAndSlice(true, "hi").len == 0);
154 expect(peerTypeEmptyArrayAndSlice(false, "hi").len == 1);154 try expect(peerTypeEmptyArrayAndSlice(false, "hi").len == 1);
155 }155 }
156}156}
157fn peerTypeEmptyArrayAndSlice(a: bool, slice: []const u8) []const u8 {157fn peerTypeEmptyArrayAndSlice(a: bool, slice: []const u8) []const u8 {
...@@ -163,8 +163,8 @@ fn peerTypeEmptyArrayAndSlice(a: bool, slice: []const u8) []const u8 {...@@ -163,8 +163,8 @@ fn peerTypeEmptyArrayAndSlice(a: bool, slice: []const u8) []const u8 {
163}163}
164164
165test "implicitly cast from [N]T to ?[]const T" {165test "implicitly cast from [N]T to ?[]const T" {
166 expect(mem.eql(u8, castToOptionalSlice().?, "hi"));166 try expect(mem.eql(u8, castToOptionalSlice().?, "hi"));
167 comptime expect(mem.eql(u8, castToOptionalSlice().?, "hi"));167 comptime try expect(mem.eql(u8, castToOptionalSlice().?, "hi"));
168}168}
169169
170fn castToOptionalSlice() ?[]const u8 {170fn castToOptionalSlice() ?[]const u8 {
...@@ -172,12 +172,12 @@ fn castToOptionalSlice() ?[]const u8 {...@@ -172,12 +172,12 @@ fn castToOptionalSlice() ?[]const u8 {
172}172}
173173
174test "implicitly cast from [0]T to anyerror![]T" {174test "implicitly cast from [0]T to anyerror![]T" {
175 testCastZeroArrayToErrSliceMut();175 try testCastZeroArrayToErrSliceMut();
176 comptime testCastZeroArrayToErrSliceMut();176 comptime try testCastZeroArrayToErrSliceMut();
177}177}
178178
179fn testCastZeroArrayToErrSliceMut() void {179fn testCastZeroArrayToErrSliceMut() !void {
180 expect((gimmeErrOrSlice() catch unreachable).len == 0);180 try expect((gimmeErrOrSlice() catch unreachable).len == 0);
181}181}
182182
183fn gimmeErrOrSlice() anyerror![]u8 {183fn gimmeErrOrSlice() anyerror![]u8 {
...@@ -190,19 +190,19 @@ test "peer type resolution: [0]u8, []const u8, and anyerror![]u8" {...@@ -190,19 +190,19 @@ test "peer type resolution: [0]u8, []const u8, and anyerror![]u8" {
190 {190 {
191 var data = "hi".*;191 var data = "hi".*;
192 const slice = data[0..];192 const slice = data[0..];
193 expect((try peerTypeEmptyArrayAndSliceAndError(true, slice)).len == 0);193 try expect((try peerTypeEmptyArrayAndSliceAndError(true, slice)).len == 0);
194 expect((try peerTypeEmptyArrayAndSliceAndError(false, slice)).len == 1);194 try expect((try peerTypeEmptyArrayAndSliceAndError(false, slice)).len == 1);
195 }195 }
196 {196 {
197 var data: [2]u8 = "hi".*;197 var data: [2]u8 = "hi".*;
198 const slice = data[0..];198 const slice = data[0..];
199 expect((try peerTypeEmptyArrayAndSliceAndError(true, slice)).len == 0);199 try expect((try peerTypeEmptyArrayAndSliceAndError(true, slice)).len == 0);
200 expect((try peerTypeEmptyArrayAndSliceAndError(false, slice)).len == 1);200 try expect((try peerTypeEmptyArrayAndSliceAndError(false, slice)).len == 1);
201 }201 }
202 }202 }
203 };203 };
204 try S.doTheTest();204 try S.doTheTest();
205 try comptime S.doTheTest();205 comptime try S.doTheTest();
206}206}
207fn peerTypeEmptyArrayAndSliceAndError(a: bool, slice: []u8) anyerror![]u8 {207fn peerTypeEmptyArrayAndSliceAndError(a: bool, slice: []u8) anyerror![]u8 {
208 if (a) {208 if (a) {
...@@ -213,43 +213,43 @@ fn peerTypeEmptyArrayAndSliceAndError(a: bool, slice: []u8) anyerror![]u8 {...@@ -213,43 +213,43 @@ fn peerTypeEmptyArrayAndSliceAndError(a: bool, slice: []u8) anyerror![]u8 {
213}213}
214214
215test "resolve undefined with integer" {215test "resolve undefined with integer" {
216 testResolveUndefWithInt(true, 1234);216 try testResolveUndefWithInt(true, 1234);
217 comptime testResolveUndefWithInt(true, 1234);217 comptime try testResolveUndefWithInt(true, 1234);
218}218}
219fn testResolveUndefWithInt(b: bool, x: i32) void {219fn testResolveUndefWithInt(b: bool, x: i32) !void {
220 const value = if (b) x else undefined;220 const value = if (b) x else undefined;
221 if (b) {221 if (b) {
222 expect(value == x);222 try expect(value == x);
223 }223 }
224}224}
225225
226test "implicit cast from &const [N]T to []const T" {226test "implicit cast from &const [N]T to []const T" {
227 testCastConstArrayRefToConstSlice();227 try testCastConstArrayRefToConstSlice();
228 comptime testCastConstArrayRefToConstSlice();228 comptime try testCastConstArrayRefToConstSlice();
229}229}
230230
231fn testCastConstArrayRefToConstSlice() void {231fn testCastConstArrayRefToConstSlice() !void {
232 {232 {
233 const blah = "aoeu".*;233 const blah = "aoeu".*;
234 const const_array_ref = &blah;234 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);
236 const slice: []const u8 = const_array_ref;236 const slice: []const u8 = const_array_ref;
237 expect(mem.eql(u8, slice, "aoeu"));237 try expect(mem.eql(u8, slice, "aoeu"));
238 }238 }
239 {239 {
240 const blah: [4]u8 = "aoeu".*;240 const blah: [4]u8 = "aoeu".*;
241 const const_array_ref = &blah;241 const const_array_ref = &blah;
242 expect(@TypeOf(const_array_ref) == *const [4]u8);242 try expect(@TypeOf(const_array_ref) == *const [4]u8);
243 const slice: []const u8 = const_array_ref;243 const slice: []const u8 = const_array_ref;
244 expect(mem.eql(u8, slice, "aoeu"));244 try expect(mem.eql(u8, slice, "aoeu"));
245 }245 }
246}246}
247247
248test "peer type resolution: error and [N]T" {248test "peer type resolution: error and [N]T" {
249 expect(mem.eql(u8, try testPeerErrorAndArray(0), "OK"));249 try expect(mem.eql(u8, try testPeerErrorAndArray(0), "OK"));
250 comptime expect(mem.eql(u8, try testPeerErrorAndArray(0), "OK"));250 comptime try expect(mem.eql(u8, try testPeerErrorAndArray(0), "OK"));
251 expect(mem.eql(u8, try testPeerErrorAndArray2(1), "OKK"));251 try expect(mem.eql(u8, try testPeerErrorAndArray2(1), "OKK"));
252 comptime expect(mem.eql(u8, try testPeerErrorAndArray2(1), "OKK"));252 comptime try expect(mem.eql(u8, try testPeerErrorAndArray2(1), "OKK"));
253}253}
254254
255fn testPeerErrorAndArray(x: u8) anyerror![]const u8 {255fn testPeerErrorAndArray(x: u8) anyerror![]const u8 {
...@@ -267,35 +267,35 @@ fn testPeerErrorAndArray2(x: u8) anyerror![]const u8 {...@@ -267,35 +267,35 @@ fn testPeerErrorAndArray2(x: u8) anyerror![]const u8 {
267}267}
268268
269test "@floatToInt" {269test "@floatToInt" {
270 testFloatToInts();270 try testFloatToInts();
271 comptime testFloatToInts();271 comptime try testFloatToInts();
272}272}
273273
274fn testFloatToInts() void {274fn testFloatToInts() !void {
275 const x = @as(i32, 1e4);275 const x = @as(i32, 1e4);
276 expect(x == 10000);276 try expect(x == 10000);
277 const y = @floatToInt(i32, @as(f32, 1e4));277 const y = @floatToInt(i32, @as(f32, 1e4));
278 expect(y == 10000);278 try expect(y == 10000);
279 expectFloatToInt(f16, 255.1, u8, 255);279 try expectFloatToInt(f16, 255.1, u8, 255);
280 expectFloatToInt(f16, 127.2, i8, 127);280 try expectFloatToInt(f16, 127.2, i8, 127);
281 expectFloatToInt(f16, -128.2, i8, -128);281 try expectFloatToInt(f16, -128.2, i8, -128);
282 expectFloatToInt(f32, 255.1, u8, 255);282 try expectFloatToInt(f32, 255.1, u8, 255);
283 expectFloatToInt(f32, 127.2, i8, 127);283 try expectFloatToInt(f32, 127.2, i8, 127);
284 expectFloatToInt(f32, -128.2, i8, -128);284 try expectFloatToInt(f32, -128.2, i8, -128);
285 expectFloatToInt(comptime_int, 1234, i16, 1234);285 try expectFloatToInt(comptime_int, 1234, i16, 1234);
286}286}
287287
288fn expectFloatToInt(comptime F: type, f: F, comptime I: type, i: I) void {288fn expectFloatToInt(comptime F: type, f: F, comptime I: type, i: I) !void {
289 expect(@floatToInt(I, f) == i);289 try expect(@floatToInt(I, f) == i);
290}290}
291291
292test "cast u128 to f128 and back" {292test "cast u128 to f128 and back" {
293 comptime testCast128();293 comptime try testCast128();
294 testCast128();294 try testCast128();
295}295}
296296
297fn testCast128() void {297fn testCast128() !void {
298 expect(cast128Int(cast128Float(0x7fff0000000000000000000000000000)) == 0x7fff0000000000000000000000000000);298 try expect(cast128Int(cast128Float(0x7fff0000000000000000000000000000)) == 0x7fff0000000000000000000000000000);
299}299}
300300
301fn cast128Int(x: f128) u128 {301fn cast128Int(x: f128) u128 {
...@@ -307,69 +307,69 @@ fn cast128Float(x: u128) f128 {...@@ -307,69 +307,69 @@ fn cast128Float(x: u128) f128 {
307}307}
308308
309test "single-item pointer of array to slice and to unknown length pointer" {309test "single-item pointer of array to slice and to unknown length pointer" {
310 testCastPtrOfArrayToSliceAndPtr();310 try testCastPtrOfArrayToSliceAndPtr();
311 comptime testCastPtrOfArrayToSliceAndPtr();311 comptime try testCastPtrOfArrayToSliceAndPtr();
312}312}
313313
314fn testCastPtrOfArrayToSliceAndPtr() void {314fn testCastPtrOfArrayToSliceAndPtr() !void {
315 {315 {
316 var array = "aoeu".*;316 var array = "aoeu".*;
317 const x: [*]u8 = &array;317 const x: [*]u8 = &array;
318 x[0] += 1;318 x[0] += 1;
319 expect(mem.eql(u8, array[0..], "boeu"));319 try expect(mem.eql(u8, array[0..], "boeu"));
320 const y: []u8 = &array;320 const y: []u8 = &array;
321 y[0] += 1;321 y[0] += 1;
322 expect(mem.eql(u8, array[0..], "coeu"));322 try expect(mem.eql(u8, array[0..], "coeu"));
323 }323 }
324 {324 {
325 var array: [4]u8 = "aoeu".*;325 var array: [4]u8 = "aoeu".*;
326 const x: [*]u8 = &array;326 const x: [*]u8 = &array;
327 x[0] += 1;327 x[0] += 1;
328 expect(mem.eql(u8, array[0..], "boeu"));328 try expect(mem.eql(u8, array[0..], "boeu"));
329 const y: []u8 = &array;329 const y: []u8 = &array;
330 y[0] += 1;330 y[0] += 1;
331 expect(mem.eql(u8, array[0..], "coeu"));331 try expect(mem.eql(u8, array[0..], "coeu"));
332 }332 }
333}333}
334334
335test "cast *[1][*]const u8 to [*]const ?[*]const u8" {335test "cast *[1][*]const u8 to [*]const ?[*]const u8" {
336 const window_name = [1][*]const u8{"window name"};336 const window_name = [1][*]const u8{"window name"};
337 const x: [*]const ?[*]const u8 = &window_name;337 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"));
339}339}
340340
341test "@intCast comptime_int" {341test "@intCast comptime_int" {
342 const result = @intCast(i32, 1234);342 const result = @intCast(i32, 1234);
343 expect(@TypeOf(result) == i32);343 try expect(@TypeOf(result) == i32);
344 expect(result == 1234);344 try expect(result == 1234);
345}345}
346346
347test "@floatCast comptime_int and comptime_float" {347test "@floatCast comptime_int and comptime_float" {
348 {348 {
349 const result = @floatCast(f16, 1234);349 const result = @floatCast(f16, 1234);
350 expect(@TypeOf(result) == f16);350 try expect(@TypeOf(result) == f16);
351 expect(result == 1234.0);351 try expect(result == 1234.0);
352 }352 }
353 {353 {
354 const result = @floatCast(f16, 1234.0);354 const result = @floatCast(f16, 1234.0);
355 expect(@TypeOf(result) == f16);355 try expect(@TypeOf(result) == f16);
356 expect(result == 1234.0);356 try expect(result == 1234.0);
357 }357 }
358 {358 {
359 const result = @floatCast(f32, 1234);359 const result = @floatCast(f32, 1234);
360 expect(@TypeOf(result) == f32);360 try expect(@TypeOf(result) == f32);
361 expect(result == 1234.0);361 try expect(result == 1234.0);
362 }362 }
363 {363 {
364 const result = @floatCast(f32, 1234.0);364 const result = @floatCast(f32, 1234.0);
365 expect(@TypeOf(result) == f32);365 try expect(@TypeOf(result) == f32);
366 expect(result == 1234.0);366 try expect(result == 1234.0);
367 }367 }
368}368}
369369
370test "vector casts" {370test "vector casts" {
371 const S = struct {371 const S = struct {
372 fn doTheTest() void {372 fn doTheTest() !void {
373 // Upcast (implicit, equivalent to @intCast)373 // Upcast (implicit, equivalent to @intCast)
374 var up0: Vector(2, u8) = [_]u8{ 0x55, 0xaa };374 var up0: Vector(2, u8) = [_]u8{ 0x55, 0xaa };
375 var up1 = @as(Vector(2, u16), up0);375 var up1 = @as(Vector(2, u16), up0);
...@@ -381,55 +381,55 @@ test "vector casts" {...@@ -381,55 +381,55 @@ test "vector casts" {
381 var down2 = @intCast(Vector(2, u16), down0);381 var down2 = @intCast(Vector(2, u16), down0);
382 var down3 = @intCast(Vector(2, u8), down0);382 var down3 = @intCast(Vector(2, u8), down0);
383383
384 expect(mem.eql(u16, &@as([2]u16, up1), &[2]u16{ 0x55, 0xaa }));384 try 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 }));385 try 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 }));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 }));388 try 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 }));389 try 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 }));390 try expect(mem.eql(u8, &@as([2]u8, down3), &[2]u8{ 0x55, 0xaa }));
391 }391 }
392392
393 fn doTheTestFloat() void {393 fn doTheTestFloat() !void {
394 var vec = @splat(2, @as(f32, 1234.0));394 var vec = @splat(2, @as(f32, 1234.0));
395 var wider: Vector(2, f64) = vec;395 var wider: Vector(2, f64) = vec;
396 expect(wider[0] == 1234.0);396 try expect(wider[0] == 1234.0);
397 expect(wider[1] == 1234.0);397 try expect(wider[1] == 1234.0);
398 }398 }
399 };399 };
400400
401 S.doTheTest();401 try S.doTheTest();
402 comptime S.doTheTest();402 comptime try S.doTheTest();
403 S.doTheTestFloat();403 try S.doTheTestFloat();
404 comptime S.doTheTestFloat();404 comptime try S.doTheTestFloat();
405}405}
406406
407test "comptime_int @intToFloat" {407test "comptime_int @intToFloat" {
408 {408 {
409 const result = @intToFloat(f16, 1234);409 const result = @intToFloat(f16, 1234);
410 expect(@TypeOf(result) == f16);410 try expect(@TypeOf(result) == f16);
411 expect(result == 1234.0);411 try expect(result == 1234.0);
412 }412 }
413 {413 {
414 const result = @intToFloat(f32, 1234);414 const result = @intToFloat(f32, 1234);
415 expect(@TypeOf(result) == f32);415 try expect(@TypeOf(result) == f32);
416 expect(result == 1234.0);416 try expect(result == 1234.0);
417 }417 }
418 {418 {
419 const result = @intToFloat(f64, 1234);419 const result = @intToFloat(f64, 1234);
420 expect(@TypeOf(result) == f64);420 try expect(@TypeOf(result) == f64);
421 expect(result == 1234.0);421 try expect(result == 1234.0);
422 }422 }
423 {423 {
424 const result = @intToFloat(f128, 1234);424 const result = @intToFloat(f128, 1234);
425 expect(@TypeOf(result) == f128);425 try expect(@TypeOf(result) == f128);
426 expect(result == 1234.0);426 try expect(result == 1234.0);
427 }427 }
428 // big comptime_int (> 64 bits) to f128 conversion428 // big comptime_int (> 64 bits) to f128 conversion
429 {429 {
430 const result = @intToFloat(f128, 0x1_0000_0000_0000_0000);430 const result = @intToFloat(f128, 0x1_0000_0000_0000_0000);
431 expect(@TypeOf(result) == f128);431 try expect(@TypeOf(result) == f128);
432 expect(result == 0x1_0000_0000_0000_0000.0);432 try expect(result == 0x1_0000_0000_0000_0000.0);
433 }433 }
434}434}
435435
...@@ -437,25 +437,25 @@ test "@intCast i32 to u7" {...@@ -437,25 +437,25 @@ test "@intCast i32 to u7" {
437 var x: u128 = maxInt(u128);437 var x: u128 = maxInt(u128);
438 var y: i32 = 120;438 var y: i32 = 120;
439 var z = x >> @intCast(u7, y);439 var z = x >> @intCast(u7, y);
440 expect(z == 0xff);440 try expect(z == 0xff);
441}441}
442442
443test "@floatCast cast down" {443test "@floatCast cast down" {
444 {444 {
445 var double: f64 = 0.001534;445 var double: f64 = 0.001534;
446 var single = @floatCast(f32, double);446 var single = @floatCast(f32, double);
447 expect(single == 0.001534);447 try expect(single == 0.001534);
448 }448 }
449 {449 {
450 const double: f64 = 0.001534;450 const double: f64 = 0.001534;
451 const single = @floatCast(f32, double);451 const single = @floatCast(f32, double);
452 expect(single == 0.001534);452 try expect(single == 0.001534);
453 }453 }
454}454}
455455
456test "implicit cast undefined to optional" {456test "implicit cast undefined to optional" {
457 expect(MakeType(void).getNull() == null);457 try expect(MakeType(void).getNull() == null);
458 expect(MakeType(void).getNonNull() != null);458 try expect(MakeType(void).getNonNull() != null);
459}459}
460460
461fn MakeType(comptime T: type) type {461fn MakeType(comptime T: type) type {
...@@ -475,26 +475,26 @@ test "implicit cast from *[N]T to ?[*]T" {...@@ -475,26 +475,26 @@ test "implicit cast from *[N]T to ?[*]T" {
475 var y: [4]u16 = [4]u16{ 0, 1, 2, 3 };475 var y: [4]u16 = [4]u16{ 0, 1, 2, 3 };
476476
477 x = &y;477 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]));
479 x.?[0] = 8;479 x.?[0] = 8;
480 y[3] = 6;480 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]));
482}482}
483483
484test "implicit cast from *[N]T to [*c]T" {484test "implicit cast from *[N]T to [*c]T" {
485 var x: [4]u16 = [4]u16{ 0, 1, 2, 3 };485 var x: [4]u16 = [4]u16{ 0, 1, 2, 3 };
486 var y: [*c]u16 = &x;486 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]));
489 x[0] = 8;489 x[0] = 8;
490 y[3] = 6;490 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]));
492}492}
493493
494test "implicit cast from *T to ?*c_void" {494test "implicit cast from *T to ?*c_void" {
495 var a: u8 = 1;495 var a: u8 = 1;
496 incrementVoidPtrValue(&a);496 incrementVoidPtrValue(&a);
497 std.testing.expect(a == 2);497 try std.testing.expect(a == 2);
498}498}
499499
500fn incrementVoidPtrValue(value: ?*c_void) void {500fn incrementVoidPtrValue(value: ?*c_void) void {
...@@ -505,7 +505,7 @@ test "implicit cast from [*]T to ?*c_void" {...@@ -505,7 +505,7 @@ test "implicit cast from [*]T to ?*c_void" {
505 var a = [_]u8{ 3, 2, 1 };505 var a = [_]u8{ 3, 2, 1 };
506 var runtime_zero: usize = 0;506 var runtime_zero: usize = 0;
507 incrementVoidPtrArray(a[runtime_zero..].ptr, 3);507 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 }));
509}509}
510510
511fn incrementVoidPtrArray(array: ?*c_void, len: usize) void {511fn incrementVoidPtrArray(array: ?*c_void, len: usize) void {
...@@ -522,34 +522,34 @@ test "*usize to *void" {...@@ -522,34 +522,34 @@ test "*usize to *void" {
522}522}
523523
524test "compile time int to ptr of function" {524test "compile time int to ptr of function" {
525 foobar(FUNCTION_CONSTANT);525 try foobar(FUNCTION_CONSTANT);
526}526}
527527
528pub const FUNCTION_CONSTANT = @intToPtr(PFN_void, maxInt(usize));528pub const FUNCTION_CONSTANT = @intToPtr(PFN_void, maxInt(usize));
529pub const PFN_void = fn (*c_void) callconv(.C) void;529pub const PFN_void = fn (*c_void) callconv(.C) void;
530530
531fn foobar(func: PFN_void) void {531fn foobar(func: PFN_void) !void {
532 std.testing.expect(@ptrToInt(func) == maxInt(usize));532 try std.testing.expect(@ptrToInt(func) == maxInt(usize));
533}533}
534534
535test "implicit ptr to *c_void" {535test "implicit ptr to *c_void" {
536 var a: u32 = 1;536 var a: u32 = 1;
537 var ptr: *align(@alignOf(u32)) c_void = &a;537 var ptr: *align(@alignOf(u32)) c_void = &a;
538 var b: *u32 = @ptrCast(*u32, ptr);538 var b: *u32 = @ptrCast(*u32, ptr);
539 expect(b.* == 1);539 try expect(b.* == 1);
540 var ptr2: ?*align(@alignOf(u32)) c_void = &a;540 var ptr2: ?*align(@alignOf(u32)) c_void = &a;
541 var c: *u32 = @ptrCast(*u32, ptr2.?);541 var c: *u32 = @ptrCast(*u32, ptr2.?);
542 expect(c.* == 1);542 try expect(c.* == 1);
543}543}
544544
545test "@intCast to comptime_int" {545test "@intCast to comptime_int" {
546 expect(@intCast(comptime_int, 0) == 0);546 try expect(@intCast(comptime_int, 0) == 0);
547}547}
548548
549test "implicit cast comptime numbers to any type when the value fits" {549test "implicit cast comptime numbers to any type when the value fits" {
550 const a: u64 = 255;550 const a: u64 = 255;
551 var b: u8 = a;551 var b: u8 = a;
552 expect(b == 255);552 try expect(b == 255);
553}553}
554554
555test "@intToEnum passed a comptime_int to an enum with one item" {555test "@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" {...@@ -557,7 +557,7 @@ test "@intToEnum passed a comptime_int to an enum with one item" {
557 A,557 A,
558 };558 };
559 const x = @intToEnum(E, 0);559 const x = @intToEnum(E, 0);
560 expect(x == E.A);560 try expect(x == E.A);
561}561}
562562
563test "@intToEnum runtime to an extern enum with duplicate values" {563test "@intToEnum runtime to an extern enum with duplicate values" {
...@@ -567,33 +567,33 @@ test "@intToEnum runtime to an extern enum with duplicate values" {...@@ -567,33 +567,33 @@ test "@intToEnum runtime to an extern enum with duplicate values" {
567 };567 };
568 var a: u8 = 1;568 var a: u8 = 1;
569 var x = @intToEnum(E, a);569 var x = @intToEnum(E, a);
570 expect(x == E.A);570 try expect(x == E.A);
571 expect(x == E.B);571 try expect(x == E.B);
572}572}
573573
574test "@intCast to u0 and use the result" {574test "@intCast to u0 and use the result" {
575 const S = struct {575 const S = struct {
576 fn doTheTest(zero: u1, one: u1, bigzero: i32) void {576 fn doTheTest(zero: u1, one: u1, bigzero: i32) !void {
577 expect((one << @intCast(u0, bigzero)) == 1);577 try expect((one << @intCast(u0, bigzero)) == 1);
578 expect((zero << @intCast(u0, bigzero)) == 0);578 try expect((zero << @intCast(u0, bigzero)) == 0);
579 }579 }
580 };580 };
581 S.doTheTest(0, 1, 0);581 try S.doTheTest(0, 1, 0);
582 comptime S.doTheTest(0, 1, 0);582 comptime try S.doTheTest(0, 1, 0);
583}583}
584584
585test "peer type resolution: unreachable, null, slice" {585test "peer type resolution: unreachable, null, slice" {
586 const S = struct {586 const S = struct {
587 fn doTheTest(num: usize, word: []const u8) void {587 fn doTheTest(num: usize, word: []const u8) !void {
588 const result = switch (num) {588 const result = switch (num) {
589 0 => null,589 0 => null,
590 1 => word,590 1 => word,
591 else => unreachable,591 else => unreachable,
592 };592 };
593 expect(mem.eql(u8, result.?, "hi"));593 try expect(mem.eql(u8, result.?, "hi"));
594 }594 }
595 };595 };
596 S.doTheTest(1, "hi");596 try S.doTheTest(1, "hi");
597}597}
598598
599test "peer type resolution: unreachable, error set, unreachable" {599test "peer type resolution: unreachable, error set, unreachable" {
...@@ -616,17 +616,17 @@ test "peer type resolution: unreachable, error set, unreachable" {...@@ -616,17 +616,17 @@ test "peer type resolution: unreachable, error set, unreachable" {
616 error.FileDescriptorIncompatibleWithEpoll => unreachable,616 error.FileDescriptorIncompatibleWithEpoll => unreachable,
617 error.Unexpected => unreachable,617 error.Unexpected => unreachable,
618 };618 };
619 expect(transformed_err == error.SystemResources);619 try expect(transformed_err == error.SystemResources);
620}620}
621621
622test "implicit cast comptime_int to comptime_float" {622test "implicit cast comptime_int to comptime_float" {
623 comptime expect(@as(comptime_float, 10) == @as(f32, 10));623 comptime try expect(@as(comptime_float, 10) == @as(f32, 10));
624 expect(2 == 2.0);624 try expect(2 == 2.0);
625}625}
626626
627test "implicit cast *[0]T to E![]const u8" {627test "implicit cast *[0]T to E![]const u8" {
628 var x = @as(anyerror![]const u8, &[0]u8{});628 var x = @as(anyerror![]const u8, &[0]u8{});
629 expect((x catch unreachable).len == 0);629 try expect((x catch unreachable).len == 0);
630}630}
631631
632test "peer cast *[0]T to E![]const T" {632test "peer cast *[0]T to E![]const T" {
...@@ -634,7 +634,7 @@ test "peer cast *[0]T to E![]const T" {...@@ -634,7 +634,7 @@ test "peer cast *[0]T to E![]const T" {
634 var buf: anyerror![]const u8 = buffer[0..];634 var buf: anyerror![]const u8 = buffer[0..];
635 var b = false;635 var b = false;
636 var y = if (b) &[0]u8{} else buf;636 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));
638}638}
639639
640test "peer cast *[0]T to []const T" {640test "peer cast *[0]T to []const T" {
...@@ -642,25 +642,25 @@ test "peer cast *[0]T to []const T" {...@@ -642,25 +642,25 @@ test "peer cast *[0]T to []const T" {
642 var buf: []const u8 = buffer[0..];642 var buf: []const u8 = buffer[0..];
643 var b = false;643 var b = false;
644 var y = if (b) &[0]u8{} else buf;644 var y = if (b) &[0]u8{} else buf;
645 expect(mem.eql(u8, "abcde", y));645 try expect(mem.eql(u8, "abcde", y));
646}646}
647647
648var global_array: [4]u8 = undefined;648var global_array: [4]u8 = undefined;
649test "cast from array reference to fn" {649test "cast from array reference to fn" {
650 const f = @ptrCast(fn () callconv(.C) void, &global_array);650 const f = @ptrCast(fn () callconv(.C) void, &global_array);
651 expect(@ptrToInt(f) == @ptrToInt(&global_array));651 try expect(@ptrToInt(f) == @ptrToInt(&global_array));
652}652}
653653
654test "*const [N]null u8 to ?[]const u8" {654test "*const [N]null u8 to ?[]const u8" {
655 const S = struct {655 const S = struct {
656 fn doTheTest() void {656 fn doTheTest() !void {
657 var a = "Hello";657 var a = "Hello";
658 var b: ?[]const u8 = a;658 var b: ?[]const u8 = a;
659 expect(mem.eql(u8, b.?, "Hello"));659 try expect(mem.eql(u8, b.?, "Hello"));
660 }660 }
661 };661 };
662 S.doTheTest();662 try S.doTheTest();
663 comptime S.doTheTest();663 comptime try S.doTheTest();
664}664}
665665
666test "peer resolution of string literals" {666test "peer resolution of string literals" {
...@@ -672,54 +672,54 @@ test "peer resolution of string literals" {...@@ -672,54 +672,54 @@ test "peer resolution of string literals" {
672 d,672 d,
673 };673 };
674674
675 fn doTheTest(e: E) void {675 fn doTheTest(e: E) !void {
676 const cmd = switch (e) {676 const cmd = switch (e) {
677 .a => "one",677 .a => "one",
678 .b => "two",678 .b => "two",
679 .c => "three",679 .c => "three",
680 .d => "four",680 .d => "four",
681 };681 };
682 expect(mem.eql(u8, cmd, "two"));682 try expect(mem.eql(u8, cmd, "two"));
683 }683 }
684 };684 };
685 S.doTheTest(.b);685 try S.doTheTest(.b);
686 comptime S.doTheTest(.b);686 comptime try S.doTheTest(.b);
687}687}
688688
689test "type coercion related to sentinel-termination" {689test "type coercion related to sentinel-termination" {
690 const S = struct {690 const S = struct {
691 fn doTheTest() void {691 fn doTheTest() !void {
692 // [:x]T to []T692 // [:x]T to []T
693 {693 {
694 var array = [4:0]i32{ 1, 2, 3, 4 };694 var array = [4:0]i32{ 1, 2, 3, 4 };
695 var slice: [:0]i32 = &array;695 var slice: [:0]i32 = &array;
696 var dest: []i32 = slice;696 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 }));
698 }698 }
699699
700 // [*:x]T to [*]T700 // [*:x]T to [*]T
701 {701 {
702 var array = [4:99]i32{ 1, 2, 3, 4 };702 var array = [4:99]i32{ 1, 2, 3, 4 };
703 var dest: [*]i32 = &array;703 var dest: [*]i32 = &array;
704 expect(dest[0] == 1);704 try expect(dest[0] == 1);
705 expect(dest[1] == 2);705 try expect(dest[1] == 2);
706 expect(dest[2] == 3);706 try expect(dest[2] == 3);
707 expect(dest[3] == 4);707 try expect(dest[3] == 4);
708 expect(dest[4] == 99);708 try expect(dest[4] == 99);
709 }709 }
710710
711 // [N:x]T to [N]T711 // [N:x]T to [N]T
712 {712 {
713 var array = [4:0]i32{ 1, 2, 3, 4 };713 var array = [4:0]i32{ 1, 2, 3, 4 };
714 var dest: [4]i32 = array;714 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 }));
716 }716 }
717717
718 // *[N:x]T to *[N]T718 // *[N:x]T to *[N]T
719 {719 {
720 var array = [4:0]i32{ 1, 2, 3, 4 };720 var array = [4:0]i32{ 1, 2, 3, 4 };
721 var dest: *[4]i32 = &array;721 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 }));
723 }723 }
724724
725 // [:x]T to [*:x]T725 // [:x]T to [*:x]T
...@@ -727,24 +727,24 @@ test "type coercion related to sentinel-termination" {...@@ -727,24 +727,24 @@ test "type coercion related to sentinel-termination" {
727 var array = [4:0]i32{ 1, 2, 3, 4 };727 var array = [4:0]i32{ 1, 2, 3, 4 };
728 var slice: [:0]i32 = &array;728 var slice: [:0]i32 = &array;
729 var dest: [*:0]i32 = slice;729 var dest: [*:0]i32 = slice;
730 expect(dest[0] == 1);730 try expect(dest[0] == 1);
731 expect(dest[1] == 2);731 try expect(dest[1] == 2);
732 expect(dest[2] == 3);732 try expect(dest[2] == 3);
733 expect(dest[3] == 4);733 try expect(dest[3] == 4);
734 expect(dest[4] == 0);734 try expect(dest[4] == 0);
735 }735 }
736 }736 }
737 };737 };
738 S.doTheTest();738 try S.doTheTest();
739 comptime S.doTheTest();739 comptime try S.doTheTest();
740}740}
741741
742test "cast i8 fn call peers to i32 result" {742test "cast i8 fn call peers to i32 result" {
743 const S = struct {743 const S = struct {
744 fn doTheTest() void {744 fn doTheTest() !void {
745 var cond = true;745 var cond = true;
746 const value: i32 = if (cond) smallBoi() else bigBoi();746 const value: i32 = if (cond) smallBoi() else bigBoi();
747 expect(value == 123);747 try expect(value == 123);
748 }748 }
749 fn smallBoi() i8 {749 fn smallBoi() i8 {
750 return 123;750 return 123;
...@@ -753,21 +753,21 @@ test "cast i8 fn call peers to i32 result" {...@@ -753,21 +753,21 @@ test "cast i8 fn call peers to i32 result" {
753 return 1234;753 return 1234;
754 }754 }
755 };755 };
756 S.doTheTest();756 try S.doTheTest();
757 comptime S.doTheTest();757 comptime try S.doTheTest();
758}758}
759759
760test "return u8 coercing into ?u32 return type" {760test "return u8 coercing into ?u32 return type" {
761 const S = struct {761 const S = struct {
762 fn doTheTest() void {762 fn doTheTest() !void {
763 expect(foo(123).? == 123);763 try expect(foo(123).? == 123);
764 }764 }
765 fn foo(arg: u8) ?u32 {765 fn foo(arg: u8) ?u32 {
766 return arg;766 return arg;
767 }767 }
768 };768 };
769 S.doTheTest();769 try S.doTheTest();
770 comptime S.doTheTest();770 comptime try S.doTheTest();
771}771}
772772
773test "peer result null and comptime_int" {773test "peer result null and comptime_int" {
...@@ -783,17 +783,17 @@ test "peer result null and comptime_int" {...@@ -783,17 +783,17 @@ test "peer result null and comptime_int" {
783 }783 }
784 };784 };
785785
786 expect(S.blah(0) == null);786 try expect(S.blah(0) == null);
787 comptime expect(S.blah(0) == null);787 comptime try expect(S.blah(0) == null);
788 expect(S.blah(10).? == 1);788 try expect(S.blah(10).? == 1);
789 comptime expect(S.blah(10).? == 1);789 comptime try expect(S.blah(10).? == 1);
790 expect(S.blah(-10).? == -1);790 try expect(S.blah(-10).? == -1);
791 comptime expect(S.blah(-10).? == -1);791 comptime try expect(S.blah(-10).? == -1);
792}792}
793793
794test "peer type resolution implicit cast to return type" {794test "peer type resolution implicit cast to return type" {
795 const S = struct {795 const S = struct {
796 fn doTheTest() void {796 fn doTheTest() !void {
797 for ("hello") |c| _ = f(c);797 for ("hello") |c| _ = f(c);
798 }798 }
799 fn f(c: u8) []const u8 {799 fn f(c: u8) []const u8 {
...@@ -804,13 +804,13 @@ test "peer type resolution implicit cast to return type" {...@@ -804,13 +804,13 @@ test "peer type resolution implicit cast to return type" {
804 };804 };
805 }805 }
806 };806 };
807 S.doTheTest();807 try S.doTheTest();
808 comptime S.doTheTest();808 comptime try S.doTheTest();
809}809}
810810
811test "peer type resolution implicit cast to variable type" {811test "peer type resolution implicit cast to variable type" {
812 const S = struct {812 const S = struct {
813 fn doTheTest() void {813 fn doTheTest() !void {
814 var x: []const u8 = undefined;814 var x: []const u8 = undefined;
815 for ("hello") |c| x = switch (c) {815 for ("hello") |c| x = switch (c) {
816 'h', 'e' => &[_]u8{c}, // should cast to slice816 'h', 'e' => &[_]u8{c}, // should cast to slice
...@@ -819,14 +819,14 @@ test "peer type resolution implicit cast to variable type" {...@@ -819,14 +819,14 @@ test "peer type resolution implicit cast to variable type" {
819 };819 };
820 }820 }
821 };821 };
822 S.doTheTest();822 try S.doTheTest();
823 comptime S.doTheTest();823 comptime try S.doTheTest();
824}824}
825825
826test "variable initialization uses result locations properly with regards to the type" {826test "variable initialization uses result locations properly with regards to the type" {
827 var b = true;827 var b = true;
828 const x: i32 = if (b) 1 else 2;828 const x: i32 = if (b) 1 else 2;
829 expect(x == 1);829 try expect(x == 1);
830}830}
831831
832test "cast between [*c]T and ?[*:0]T on fn parameter" {832test "cast between [*c]T and ?[*:0]T on fn parameter" {
...@@ -848,27 +848,27 @@ test "cast between C pointer with different but compatible types" {...@@ -848,27 +848,27 @@ test "cast between C pointer with different but compatible types" {
848 fn foo(arg: [*]c_ushort) u16 {848 fn foo(arg: [*]c_ushort) u16 {
849 return arg[0];849 return arg[0];
850 }850 }
851 fn doTheTest() void {851 fn doTheTest() !void {
852 var x = [_]u16{ 4, 2, 1, 3 };852 var x = [_]u16{ 4, 2, 1, 3 };
853 expect(foo(@ptrCast([*]u16, &x)) == 4);853 try expect(foo(@ptrCast([*]u16, &x)) == 4);
854 }854 }
855 };855 };
856 S.doTheTest();856 try S.doTheTest();
857}857}
858858
859var global_struct: struct { f0: usize } = undefined;859var global_struct: struct { f0: usize } = undefined;
860860
861test "assignment to optional pointer result loc" {861test "assignment to optional pointer result loc" {
862 var foo: struct { ptr: ?*c_void } = .{ .ptr = &global_struct };862 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));
864}864}
865865
866test "peer type resolve string lit with sentinel-terminated mutable slice" {866test "peer type resolve string lit with sentinel-terminated mutable slice" {
867 var array: [4:0]u8 = undefined;867 var array: [4:0]u8 = undefined;
868 array[4] = 0; // TODO remove this when #4372 is solved868 array[4] = 0; // TODO remove this when #4372 is solved
869 var slice: [:0]u8 = array[0..4 :0];869 var slice: [:0]u8 = array[0..4 :0];
870 comptime expect(@TypeOf(slice, "hi") == [:0]const u8);870 comptime try expect(@TypeOf(slice, "hi") == [:0]const u8);
871 comptime expect(@TypeOf("hi", slice) == [:0]const u8);871 comptime try expect(@TypeOf("hi", slice) == [:0]const u8);
872}872}
873873
874test "peer type unsigned int to signed" {874test "peer type unsigned int to signed" {
...@@ -876,15 +876,15 @@ test "peer type unsigned int to signed" {...@@ -876,15 +876,15 @@ test "peer type unsigned int to signed" {
876 var x: u8 = 7;876 var x: u8 = 7;
877 var y: i32 = -5;877 var y: i32 = -5;
878 var a = w + y + x;878 var a = w + y + x;
879 comptime expect(@TypeOf(a) == i32);879 comptime try expect(@TypeOf(a) == i32);
880 expect(a == 7);880 try expect(a == 7);
881}881}
882882
883test "peer type resolve array pointers, one of them const" {883test "peer type resolve array pointers, one of them const" {
884 var array1: [4]u8 = undefined;884 var array1: [4]u8 = undefined;
885 const array2: [5]u8 = undefined;885 const array2: [5]u8 = undefined;
886 comptime expect(@TypeOf(&array1, &array2) == []const u8);886 comptime try expect(@TypeOf(&array1, &array2) == []const u8);
887 comptime expect(@TypeOf(&array2, &array1) == []const u8);887 comptime try expect(@TypeOf(&array2, &array1) == []const u8);
888}888}
889889
890test "peer type resolve array pointer and unknown pointer" {890test "peer type resolve array pointer and unknown pointer" {
...@@ -893,35 +893,35 @@ test "peer type resolve array pointer and unknown pointer" {...@@ -893,35 +893,35 @@ test "peer type resolve array pointer and unknown pointer" {
893 var const_ptr: [*]const u8 = undefined;893 var const_ptr: [*]const u8 = undefined;
894 var ptr: [*]u8 = undefined;894 var ptr: [*]u8 = undefined;
895895
896 comptime expect(@TypeOf(&array, ptr) == [*]u8);896 comptime try expect(@TypeOf(&array, ptr) == [*]u8);
897 comptime expect(@TypeOf(ptr, &array) == [*]u8);897 comptime try expect(@TypeOf(ptr, &array) == [*]u8);
898898
899 comptime expect(@TypeOf(&const_array, ptr) == [*]const u8);899 comptime try expect(@TypeOf(&const_array, ptr) == [*]const u8);
900 comptime expect(@TypeOf(ptr, &const_array) == [*]const u8);900 comptime try expect(@TypeOf(ptr, &const_array) == [*]const u8);
901901
902 comptime expect(@TypeOf(&array, const_ptr) == [*]const u8);902 comptime try expect(@TypeOf(&array, const_ptr) == [*]const u8);
903 comptime expect(@TypeOf(const_ptr, &array) == [*]const u8);903 comptime try expect(@TypeOf(const_ptr, &array) == [*]const u8);
904904
905 comptime expect(@TypeOf(&const_array, const_ptr) == [*]const u8);905 comptime try expect(@TypeOf(&const_array, const_ptr) == [*]const u8);
906 comptime expect(@TypeOf(const_ptr, &const_array) == [*]const u8);906 comptime try expect(@TypeOf(const_ptr, &const_array) == [*]const u8);
907}907}
908908
909test "comptime float casts" {909test "comptime float casts" {
910 const a = @intToFloat(comptime_float, 1);910 const a = @intToFloat(comptime_float, 1);
911 expect(a == 1);911 try expect(a == 1);
912 expect(@TypeOf(a) == comptime_float);912 try expect(@TypeOf(a) == comptime_float);
913 const b = @floatToInt(comptime_int, 2);913 const b = @floatToInt(comptime_int, 2);
914 expect(b == 2);914 try expect(b == 2);
915 expect(@TypeOf(b) == comptime_int);915 try expect(@TypeOf(b) == comptime_int);
916}916}
917917
918test "cast from ?[*]T to ??[*]T" {918test "cast from ?[*]T to ??[*]T" {
919 const a: ??[*]u8 = @as(?[*]u8, null);919 const a: ??[*]u8 = @as(?[*]u8, null);
920 expect(a != null and a.? == null);920 try expect(a != null and a.? == null);
921}921}
922922
923test "cast between *[N]void and []void" {923test "cast between *[N]void and []void" {
924 var a: [4]void = undefined;924 var a: [4]void = undefined;
925 var b: []void = &a;925 var b: []void = &a;
926 expect(b.len == 4);926 try expect(b.len == 4);
927}927}
test/behavior/const_slice_child.zig+8-8
...@@ -12,24 +12,24 @@ test "const slice child" {...@@ -12,24 +12,24 @@ test "const slice child" {
12 "three",12 "three",
13 };13 };
14 argv = &strs;14 argv = &strs;
15 bar(strs.len);15 try bar(strs.len);
16}16}
1717
18fn foo(args: [][]const u8) void {18fn foo(args: [][]const u8) !void {
19 expect(args.len == 3);19 try expect(args.len == 3);
20 expect(streql(args[0], "one"));20 try expect(streql(args[0], "one"));
21 expect(streql(args[1], "two"));21 try expect(streql(args[1], "two"));
22 expect(streql(args[2], "three"));22 try expect(streql(args[2], "three"));
23}23}
2424
25fn bar(argc: usize) void {25fn bar(argc: usize) !void {
26 const args = testing.allocator.alloc([]const u8, argc) catch unreachable;26 const args = testing.allocator.alloc([]const u8, argc) catch unreachable;
27 defer testing.allocator.free(args);27 defer testing.allocator.free(args);
28 for (args) |_, i| {28 for (args) |_, i| {
29 const ptr = argv[i];29 const ptr = argv[i];
30 args[i] = ptr[0..strlen(ptr)];30 args[i] = ptr[0..strlen(ptr)];
31 }31 }
32 foo(args);32 try foo(args);
33}33}
3434
35fn strlen(ptr: [*]const u8) usize {35fn strlen(ptr: [*]const u8) usize {
test/behavior/defer.zig+20-20
...@@ -24,18 +24,18 @@ fn runSomeErrorDefers(x: bool) !bool {...@@ -24,18 +24,18 @@ fn runSomeErrorDefers(x: bool) !bool {
24}24}
2525
26test "mixing normal and error defers" {26test "mixing normal and error defers" {
27 expect(runSomeErrorDefers(true) catch unreachable);27 try expect(runSomeErrorDefers(true) catch unreachable);
28 expect(result[0] == 'c');28 try expect(result[0] == 'c');
29 expect(result[1] == 'a');29 try expect(result[1] == 'a');
3030
31 const ok = runSomeErrorDefers(false) catch |err| x: {31 const ok = runSomeErrorDefers(false) catch |err| x: {
32 expect(err == error.FalseNotAllowed);32 try expect(err == error.FalseNotAllowed);
33 break :x true;33 break :x true;
34 };34 };
35 expect(ok);35 try expect(ok);
36 expect(result[0] == 'c');36 try expect(result[0] == 'c');
37 expect(result[1] == 'b');37 try expect(result[1] == 'b');
38 expect(result[2] == 'a');38 try expect(result[2] == 'a');
39}39}
4040
41test "break and continue inside loop inside defer expression" {41test "break and continue inside loop inside defer expression" {
...@@ -50,7 +50,7 @@ fn testBreakContInDefer(x: usize) void {...@@ -50,7 +50,7 @@ fn testBreakContInDefer(x: usize) void {
50 if (i < 5) continue;50 if (i < 5) continue;
51 if (i == 5) break;51 if (i == 5) break;
52 }52 }
53 expect(i == 5);53 expect(i == 5) catch @panic("test failure");
54 }54 }
55}55}
5656
...@@ -62,11 +62,11 @@ test "defer and labeled break" {...@@ -62,11 +62,11 @@ test "defer and labeled break" {
62 break :blk;62 break :blk;
63 }63 }
6464
65 expect(i == 1);65 try expect(i == 1);
66}66}
6767
68test "errdefer does not apply to fn inside fn" {68test "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);
70}70}
7171
72fn testNestedFnErrDefer() anyerror!void {72fn testNestedFnErrDefer() anyerror!void {
...@@ -82,8 +82,8 @@ fn testNestedFnErrDefer() anyerror!void {...@@ -82,8 +82,8 @@ fn testNestedFnErrDefer() anyerror!void {
8282
83test "return variable while defer expression in scope to modify it" {83test "return variable while defer expression in scope to modify it" {
84 const S = struct {84 const S = struct {
85 fn doTheTest() void {85 fn doTheTest() !void {
86 expect(notNull().? == 1);86 try expect(notNull().? == 1);
87 }87 }
8888
89 fn notNull() ?u8 {89 fn notNull() ?u8 {
...@@ -93,22 +93,22 @@ test "return variable while defer expression in scope to modify it" {...@@ -93,22 +93,22 @@ test "return variable while defer expression in scope to modify it" {
93 }93 }
94 };94 };
9595
96 S.doTheTest();96 try S.doTheTest();
97 comptime S.doTheTest();97 comptime try S.doTheTest();
98}98}
9999
100test "errdefer with payload" {100test "errdefer with payload" {
101 const S = struct {101 const S = struct {
102 fn foo() !i32 {102 fn foo() !i32 {
103 errdefer |a| {103 errdefer |a| {
104 expectEqual(error.One, a);104 expectEqual(error.One, a) catch @panic("test failure");
105 }105 }
106 return error.One;106 return error.One;
107 }107 }
108 fn doTheTest() void {108 fn doTheTest() !void {
109 expectError(error.One, foo());109 try expectError(error.One, foo());
110 }110 }
111 };111 };
112 S.doTheTest();112 try S.doTheTest();
113 comptime S.doTheTest();113 comptime try S.doTheTest();
114}114}
test/behavior/enum.zig+112-112
...@@ -29,41 +29,41 @@ test "non-exhaustive enum" {...@@ -29,41 +29,41 @@ test "non-exhaustive enum" {
29 b,29 b,
30 _,30 _,
31 };31 };
32 fn doTheTest(y: u8) void {32 fn doTheTest(y: u8) !void {
33 var e: E = .b;33 var e: E = .b;
34 expect(switch (e) {34 try expect(switch (e) {
35 .a => false,35 .a => false,
36 .b => true,36 .b => true,
37 _ => false,37 _ => false,
38 });38 });
39 e = @intToEnum(E, 12);39 e = @intToEnum(E, 12);
40 expect(switch (e) {40 try expect(switch (e) {
41 .a => false,41 .a => false,
42 .b => false,42 .b => false,
43 _ => true,43 _ => true,
44 });44 });
4545
46 expect(switch (e) {46 try expect(switch (e) {
47 .a => false,47 .a => false,
48 .b => false,48 .b => false,
49 else => true,49 else => true,
50 });50 });
51 e = .b;51 e = .b;
52 expect(switch (e) {52 try expect(switch (e) {
53 .a => false,53 .a => false,
54 else => true,54 else => true,
55 });55 });
5656
57 expect(@typeInfo(E).Enum.fields.len == 2);57 try expect(@typeInfo(E).Enum.fields.len == 2);
58 e = @intToEnum(E, 12);58 e = @intToEnum(E, 12);
59 expect(@enumToInt(e) == 12);59 try expect(@enumToInt(e) == 12);
60 e = @intToEnum(E, y);60 e = @intToEnum(E, y);
61 expect(@enumToInt(e) == 52);61 try expect(@enumToInt(e) == 52);
62 expect(@typeInfo(E).Enum.is_exhaustive == false);62 try expect(@typeInfo(E).Enum.is_exhaustive == false);
63 }63 }
64 };64 };
65 S.doTheTest(52);65 try S.doTheTest(52);
66 comptime S.doTheTest(52);66 comptime try S.doTheTest(52);
67}67}
6868
69test "empty non-exhaustive enum" {69test "empty non-exhaustive enum" {
...@@ -71,19 +71,19 @@ test "empty non-exhaustive enum" {...@@ -71,19 +71,19 @@ test "empty non-exhaustive enum" {
71 const E = enum(u8) {71 const E = enum(u8) {
72 _,72 _,
73 };73 };
74 fn doTheTest(y: u8) void {74 fn doTheTest(y: u8) !void {
75 var e = @intToEnum(E, y);75 var e = @intToEnum(E, y);
76 expect(switch (e) {76 try expect(switch (e) {
77 _ => true,77 _ => true,
78 });78 });
79 expect(@enumToInt(e) == y);79 try expect(@enumToInt(e) == y);
8080
81 expect(@typeInfo(E).Enum.fields.len == 0);81 try expect(@typeInfo(E).Enum.fields.len == 0);
82 expect(@typeInfo(E).Enum.is_exhaustive == false);82 try expect(@typeInfo(E).Enum.is_exhaustive == false);
83 }83 }
84 };84 };
85 S.doTheTest(42);85 try S.doTheTest(42);
86 comptime S.doTheTest(42);86 comptime try S.doTheTest(42);
87}87}
8888
89test "single field non-exhaustive enum" {89test "single field non-exhaustive enum" {
...@@ -92,35 +92,35 @@ test "single field non-exhaustive enum" {...@@ -92,35 +92,35 @@ test "single field non-exhaustive enum" {
92 a,92 a,
93 _,93 _,
94 };94 };
95 fn doTheTest(y: u8) void {95 fn doTheTest(y: u8) !void {
96 var e: E = .a;96 var e: E = .a;
97 expect(switch (e) {97 try expect(switch (e) {
98 .a => true,98 .a => true,
99 _ => false,99 _ => false,
100 });100 });
101 e = @intToEnum(E, 12);101 e = @intToEnum(E, 12);
102 expect(switch (e) {102 try expect(switch (e) {
103 .a => false,103 .a => false,
104 _ => true,104 _ => true,
105 });105 });
106106
107 expect(switch (e) {107 try expect(switch (e) {
108 .a => false,108 .a => false,
109 else => true,109 else => true,
110 });110 });
111 e = .a;111 e = .a;
112 expect(switch (e) {112 try expect(switch (e) {
113 .a => true,113 .a => true,
114 else => false,114 else => false,
115 });115 });
116116
117 expect(@enumToInt(@intToEnum(E, y)) == y);117 try expect(@enumToInt(@intToEnum(E, y)) == y);
118 expect(@typeInfo(E).Enum.fields.len == 1);118 try expect(@typeInfo(E).Enum.fields.len == 1);
119 expect(@typeInfo(E).Enum.is_exhaustive == false);119 try expect(@typeInfo(E).Enum.is_exhaustive == false);
120 }120 }
121 };121 };
122 S.doTheTest(23);122 try S.doTheTest(23);
123 comptime S.doTheTest(23);123 comptime try S.doTheTest(23);
124}124}
125125
126test "enum type" {126test "enum type" {
...@@ -133,16 +133,16 @@ test "enum type" {...@@ -133,16 +133,16 @@ test "enum type" {
133 };133 };
134 const bar = Bar.B;134 const bar = Bar.B;
135135
136 expect(bar == Bar.B);136 try expect(bar == Bar.B);
137 expect(@typeInfo(Foo).Union.fields.len == 3);137 try expect(@typeInfo(Foo).Union.fields.len == 3);
138 expect(@typeInfo(Bar).Enum.fields.len == 4);138 try expect(@typeInfo(Bar).Enum.fields.len == 4);
139 expect(@sizeOf(Foo) == @sizeOf(FooNoVoid));139 try expect(@sizeOf(Foo) == @sizeOf(FooNoVoid));
140 expect(@sizeOf(Bar) == 1);140 try expect(@sizeOf(Bar) == 1);
141}141}
142142
143test "enum as return value" {143test "enum as return value" {
144 switch (returnAnInt(13)) {144 switch (returnAnInt(13)) {
145 Foo.One => |value| expect(value == 13),145 Foo.One => |value| try expect(value == 13),
146 else => unreachable,146 else => unreachable,
147 }147 }
148}148}
...@@ -206,22 +206,22 @@ const Number = enum {...@@ -206,22 +206,22 @@ const Number = enum {
206};206};
207207
208test "enum to int" {208test "enum to int" {
209 shouldEqual(Number.Zero, 0);209 try shouldEqual(Number.Zero, 0);
210 shouldEqual(Number.One, 1);210 try shouldEqual(Number.One, 1);
211 shouldEqual(Number.Two, 2);211 try shouldEqual(Number.Two, 2);
212 shouldEqual(Number.Three, 3);212 try shouldEqual(Number.Three, 3);
213 shouldEqual(Number.Four, 4);213 try shouldEqual(Number.Four, 4);
214}214}
215215
216fn shouldEqual(n: Number, expected: u3) void {216fn shouldEqual(n: Number, expected: u3) !void {
217 expect(@enumToInt(n) == expected);217 try expect(@enumToInt(n) == expected);
218}218}
219219
220test "int to enum" {220test "int to enum" {
221 testIntToEnumEval(3);221 try testIntToEnumEval(3);
222}222}
223fn testIntToEnumEval(x: i32) void {223fn testIntToEnumEval(x: i32) !void {
224 expect(@intToEnum(IntToEnumNumber, @intCast(u3, x)) == IntToEnumNumber.Three);224 try expect(@intToEnum(IntToEnumNumber, @intCast(u3, x)) == IntToEnumNumber.Three);
225}225}
226const IntToEnumNumber = enum {226const IntToEnumNumber = enum {
227 Zero,227 Zero,
...@@ -232,18 +232,18 @@ const IntToEnumNumber = enum {...@@ -232,18 +232,18 @@ const IntToEnumNumber = enum {
232};232};
233233
234test "@tagName" {234test "@tagName" {
235 expect(mem.eql(u8, testEnumTagNameBare(BareNumber.Three), "Three"));235 try expect(mem.eql(u8, testEnumTagNameBare(BareNumber.Three), "Three"));
236 comptime expect(mem.eql(u8, testEnumTagNameBare(BareNumber.Three), "Three"));236 comptime try expect(mem.eql(u8, testEnumTagNameBare(BareNumber.Three), "Three"));
237}237}
238238
239test "@tagName extern enum with duplicates" {239test "@tagName extern enum with duplicates" {
240 expect(mem.eql(u8, testEnumTagNameBare(ExternDuplicates.B), "A"));240 try expect(mem.eql(u8, testEnumTagNameBare(ExternDuplicates.B), "A"));
241 comptime expect(mem.eql(u8, testEnumTagNameBare(ExternDuplicates.B), "A"));241 comptime try expect(mem.eql(u8, testEnumTagNameBare(ExternDuplicates.B), "A"));
242}242}
243243
244test "@tagName non-exhaustive enum" {244test "@tagName non-exhaustive enum" {
245 expect(mem.eql(u8, testEnumTagNameBare(NonExhaustive.B), "B"));245 try expect(mem.eql(u8, testEnumTagNameBare(NonExhaustive.B), "B"));
246 comptime expect(mem.eql(u8, testEnumTagNameBare(NonExhaustive.B), "B"));246 comptime try expect(mem.eql(u8, testEnumTagNameBare(NonExhaustive.B), "B"));
247}247}
248248
249fn testEnumTagNameBare(n: anytype) []const u8 {249fn testEnumTagNameBare(n: anytype) []const u8 {
...@@ -269,8 +269,8 @@ const NonExhaustive = enum(u8) {...@@ -269,8 +269,8 @@ const NonExhaustive = enum(u8) {
269269
270test "enum alignment" {270test "enum alignment" {
271 comptime {271 comptime {
272 expect(@alignOf(AlignTestEnum) >= @alignOf([9]u8));272 try expect(@alignOf(AlignTestEnum) >= @alignOf([9]u8));
273 expect(@alignOf(AlignTestEnum) >= @alignOf(u64));273 try expect(@alignOf(AlignTestEnum) >= @alignOf(u64));
274 }274 }
275}275}
276276
...@@ -806,10 +806,10 @@ const ValueCount257 = enum {...@@ -806,10 +806,10 @@ const ValueCount257 = enum {
806806
807test "enum sizes" {807test "enum sizes" {
808 comptime {808 comptime {
809 expect(@sizeOf(ValueCount1) == 0);809 try expect(@sizeOf(ValueCount1) == 0);
810 expect(@sizeOf(ValueCount2) == 1);810 try expect(@sizeOf(ValueCount2) == 1);
811 expect(@sizeOf(ValueCount256) == 1);811 try expect(@sizeOf(ValueCount256) == 1);
812 expect(@sizeOf(ValueCount257) == 2);812 try expect(@sizeOf(ValueCount257) == 2);
813 }813 }
814}814}
815815
...@@ -828,12 +828,12 @@ test "set enum tag type" {...@@ -828,12 +828,12 @@ test "set enum tag type" {
828 {828 {
829 var x = Small.One;829 var x = Small.One;
830 x = Small.Two;830 x = Small.Two;
831 comptime expect(Tag(Small) == u2);831 comptime try expect(Tag(Small) == u2);
832 }832 }
833 {833 {
834 var x = Small2.One;834 var x = Small2.One;
835 x = Small2.Two;835 x = Small2.Two;
836 comptime expect(Tag(Small2) == u2);836 comptime try expect(Tag(Small2) == u2);
837 }837 }
838}838}
839839
...@@ -880,17 +880,17 @@ const bit_field_1 = BitFieldOfEnums{...@@ -880,17 +880,17 @@ const bit_field_1 = BitFieldOfEnums{
880880
881test "bit field access with enum fields" {881test "bit field access with enum fields" {
882 var data = bit_field_1;882 var data = bit_field_1;
883 expect(getA(&data) == A.Two);883 try expect(getA(&data) == A.Two);
884 expect(getB(&data) == B.Three3);884 try expect(getB(&data) == B.Three3);
885 expect(getC(&data) == C.Four4);885 try expect(getC(&data) == C.Four4);
886 comptime expect(@sizeOf(BitFieldOfEnums) == 1);886 comptime try expect(@sizeOf(BitFieldOfEnums) == 1);
887887
888 data.b = B.Four3;888 data.b = B.Four3;
889 expect(data.b == B.Four3);889 try expect(data.b == B.Four3);
890890
891 data.a = A.Three;891 data.a = A.Three;
892 expect(data.a == A.Three);892 try expect(data.a == A.Three);
893 expect(data.b == B.Four3);893 try expect(data.b == B.Four3);
894}894}
895895
896fn getA(data: *const BitFieldOfEnums) A {896fn getA(data: *const BitFieldOfEnums) A {
...@@ -906,12 +906,12 @@ fn getC(data: *const BitFieldOfEnums) C {...@@ -906,12 +906,12 @@ fn getC(data: *const BitFieldOfEnums) C {
906}906}
907907
908test "casting enum to its tag type" {908test "casting enum to its tag type" {
909 testCastEnumTag(Small2.Two);909 try testCastEnumTag(Small2.Two);
910 comptime testCastEnumTag(Small2.Two);910 comptime try testCastEnumTag(Small2.Two);
911}911}
912912
913fn testCastEnumTag(value: Small2) void {913fn testCastEnumTag(value: Small2) !void {
914 expect(@enumToInt(value) == 1);914 try expect(@enumToInt(value) == 1);
915}915}
916916
917const MultipleChoice = enum(u32) {917const MultipleChoice = enum(u32) {
...@@ -922,13 +922,13 @@ const MultipleChoice = enum(u32) {...@@ -922,13 +922,13 @@ const MultipleChoice = enum(u32) {
922};922};
923923
924test "enum with specified tag values" {924test "enum with specified tag values" {
925 testEnumWithSpecifiedTagValues(MultipleChoice.C);925 try testEnumWithSpecifiedTagValues(MultipleChoice.C);
926 comptime testEnumWithSpecifiedTagValues(MultipleChoice.C);926 comptime try testEnumWithSpecifiedTagValues(MultipleChoice.C);
927}927}
928928
929fn testEnumWithSpecifiedTagValues(x: MultipleChoice) void {929fn testEnumWithSpecifiedTagValues(x: MultipleChoice) !void {
930 expect(@enumToInt(x) == 60);930 try expect(@enumToInt(x) == 60);
931 expect(1234 == switch (x) {931 try expect(1234 == switch (x) {
932 MultipleChoice.A => 1,932 MultipleChoice.A => 1,
933 MultipleChoice.B => 2,933 MultipleChoice.B => 2,
934 MultipleChoice.C => @as(u32, 1234),934 MultipleChoice.C => @as(u32, 1234),
...@@ -949,13 +949,13 @@ const MultipleChoice2 = enum(u32) {...@@ -949,13 +949,13 @@ const MultipleChoice2 = enum(u32) {
949};949};
950950
951test "enum with specified and unspecified tag values" {951test "enum with specified and unspecified tag values" {
952 testEnumWithSpecifiedAndUnspecifiedTagValues(MultipleChoice2.D);952 try testEnumWithSpecifiedAndUnspecifiedTagValues(MultipleChoice2.D);
953 comptime testEnumWithSpecifiedAndUnspecifiedTagValues(MultipleChoice2.D);953 comptime try testEnumWithSpecifiedAndUnspecifiedTagValues(MultipleChoice2.D);
954}954}
955955
956fn testEnumWithSpecifiedAndUnspecifiedTagValues(x: MultipleChoice2) void {956fn testEnumWithSpecifiedAndUnspecifiedTagValues(x: MultipleChoice2) !void {
957 expect(@enumToInt(x) == 1000);957 try expect(@enumToInt(x) == 1000);
958 expect(1234 == switch (x) {958 try expect(1234 == switch (x) {
959 MultipleChoice2.A => 1,959 MultipleChoice2.A => 1,
960 MultipleChoice2.B => 2,960 MultipleChoice2.B => 2,
961 MultipleChoice2.C => 3,961 MultipleChoice2.C => 3,
...@@ -969,8 +969,8 @@ fn testEnumWithSpecifiedAndUnspecifiedTagValues(x: MultipleChoice2) void {...@@ -969,8 +969,8 @@ fn testEnumWithSpecifiedAndUnspecifiedTagValues(x: MultipleChoice2) void {
969}969}
970970
971test "cast integer literal to enum" {971test "cast integer literal to enum" {
972 expect(@intToEnum(MultipleChoice2, 0) == MultipleChoice2.Unspecified1);972 try expect(@intToEnum(MultipleChoice2, 0) == MultipleChoice2.Unspecified1);
973 expect(@intToEnum(MultipleChoice2, 40) == MultipleChoice2.B);973 try expect(@intToEnum(MultipleChoice2, 40) == MultipleChoice2.B);
974}974}
975975
976const EnumWithOneMember = enum {976const EnumWithOneMember = enum {
...@@ -1008,14 +1008,14 @@ const EnumWithTagValues = enum(u4) {...@@ -1008,14 +1008,14 @@ const EnumWithTagValues = enum(u4) {
1008 D = 1 << 3,1008 D = 1 << 3,
1009};1009};
1010test "enum with tag values don't require parens" {1010test "enum with tag values don't require parens" {
1011 expect(@enumToInt(EnumWithTagValues.C) == 0b0100);1011 try expect(@enumToInt(EnumWithTagValues.C) == 0b0100);
1012}1012}
10131013
1014test "enum with 1 field but explicit tag type should still have the tag type" {1014test "enum with 1 field but explicit tag type should still have the tag type" {
1015 const Enum = enum(u8) {1015 const Enum = enum(u8) {
1016 B = 2,1016 B = 2,
1017 };1017 };
1018 comptime @import("std").testing.expect(@sizeOf(Enum) == @sizeOf(u8));1018 comptime try expect(@sizeOf(Enum) == @sizeOf(u8));
1019}1019}
10201020
1021test "empty extern enum with members" {1021test "empty extern enum with members" {
...@@ -1024,7 +1024,7 @@ test "empty extern enum with members" {...@@ -1024,7 +1024,7 @@ test "empty extern enum with members" {
1024 B,1024 B,
1025 C,1025 C,
1026 };1026 };
1027 expect(@sizeOf(E) == @sizeOf(c_int));1027 try expect(@sizeOf(E) == @sizeOf(c_int));
1028}1028}
10291029
1030test "tag name with assigned enum values" {1030test "tag name with assigned enum values" {
...@@ -1033,7 +1033,7 @@ test "tag name with assigned enum values" {...@@ -1033,7 +1033,7 @@ test "tag name with assigned enum values" {
1033 B = 0,1033 B = 0,
1034 };1034 };
1035 var b = LocalFoo.B;1035 var b = LocalFoo.B;
1036 expect(mem.eql(u8, @tagName(b), "B"));1036 try expect(mem.eql(u8, @tagName(b), "B"));
1037}1037}
10381038
1039test "enum literal equality" {1039test "enum literal equality" {
...@@ -1041,8 +1041,8 @@ test "enum literal equality" {...@@ -1041,8 +1041,8 @@ test "enum literal equality" {
1041 const y = .ok;1041 const y = .ok;
1042 const z = .hi;1042 const z = .hi;
10431043
1044 expect(x != y);1044 try expect(x != y);
1045 expect(x == z);1045 try expect(x == z);
1046}1046}
10471047
1048test "enum literal cast to enum" {1048test "enum literal cast to enum" {
...@@ -1054,7 +1054,7 @@ test "enum literal cast to enum" {...@@ -1054,7 +1054,7 @@ test "enum literal cast to enum" {
10541054
1055 var color1: Color = .Auto;1055 var color1: Color = .Auto;
1056 var color2 = Color.Auto;1056 var color2 = Color.Auto;
1057 expect(color1 == color2);1057 try expect(color1 == color2);
1058}1058}
10591059
1060test "peer type resolution with enum literal" {1060test "peer type resolution with enum literal" {
...@@ -1063,8 +1063,8 @@ test "peer type resolution with enum literal" {...@@ -1063,8 +1063,8 @@ test "peer type resolution with enum literal" {
1063 two,1063 two,
1064 };1064 };
10651065
1066 expect(Items.two == .two);1066 try expect(Items.two == .two);
1067 expect(.two == Items.two);1067 try expect(.two == Items.two);
1068}1068}
10691069
1070test "enum literal in array literal" {1070test "enum literal in array literal" {
...@@ -1078,8 +1078,8 @@ test "enum literal in array literal" {...@@ -1078,8 +1078,8 @@ test "enum literal in array literal" {
1078 .two,1078 .two,
1079 };1079 };
10801080
1081 expect(array[0] == .one);1081 try expect(array[0] == .one);
1082 expect(array[1] == .two);1082 try expect(array[1] == .two);
1083}1083}
10841084
1085test "signed integer as enum tag" {1085test "signed integer as enum tag" {
...@@ -1089,9 +1089,9 @@ test "signed integer as enum tag" {...@@ -1089,9 +1089,9 @@ test "signed integer as enum tag" {
1089 A2 = 1,1089 A2 = 1,
1090 };1090 };
10911091
1092 expect(@enumToInt(SignedEnum.A0) == -1);1092 try expect(@enumToInt(SignedEnum.A0) == -1);
1093 expect(@enumToInt(SignedEnum.A1) == 0);1093 try expect(@enumToInt(SignedEnum.A1) == 0);
1094 expect(@enumToInt(SignedEnum.A2) == 1);1094 try expect(@enumToInt(SignedEnum.A2) == 1);
1095}1095}
10961096
1097test "enum value allocation" {1097test "enum value allocation" {
...@@ -1101,9 +1101,9 @@ test "enum value allocation" {...@@ -1101,9 +1101,9 @@ test "enum value allocation" {
1101 A2,1101 A2,
1102 };1102 };
11031103
1104 expect(@enumToInt(LargeEnum.A0) == 0x80000000);1104 try expect(@enumToInt(LargeEnum.A0) == 0x80000000);
1105 expect(@enumToInt(LargeEnum.A1) == 0x80000001);1105 try expect(@enumToInt(LargeEnum.A1) == 0x80000001);
1106 expect(@enumToInt(LargeEnum.A2) == 0x80000002);1106 try expect(@enumToInt(LargeEnum.A2) == 0x80000002);
1107}1107}
11081108
1109test "enum literal casting to tagged union" {1109test "enum literal casting to tagged union" {
...@@ -1130,32 +1130,32 @@ test "enum with one member and custom tag type" {...@@ -1130,32 +1130,32 @@ test "enum with one member and custom tag type" {
1130 const E = enum(u2) {1130 const E = enum(u2) {
1131 One,1131 One,
1132 };1132 };
1133 expect(@enumToInt(E.One) == 0);1133 try expect(@enumToInt(E.One) == 0);
1134 const E2 = enum(u2) {1134 const E2 = enum(u2) {
1135 One = 2,1135 One = 2,
1136 };1136 };
1137 expect(@enumToInt(E2.One) == 2);1137 try expect(@enumToInt(E2.One) == 2);
1138}1138}
11391139
1140test "enum literal casting to optional" {1140test "enum literal casting to optional" {
1141 var bar: ?Bar = undefined;1141 var bar: ?Bar = undefined;
1142 bar = .B;1142 bar = .B;
11431143
1144 expect(bar.? == Bar.B);1144 try expect(bar.? == Bar.B);
1145}1145}
11461146
1147test "enum literal casting to error union with payload enum" {1147test "enum literal casting to error union with payload enum" {
1148 var bar: error{B}!Bar = undefined;1148 var bar: error{B}!Bar = undefined;
1149 bar = .B; // should never cast to the error set1149 bar = .B; // should never cast to the error set
11501150
1151 expect((try bar) == Bar.B);1151 try expect((try bar) == Bar.B);
1152}1152}
11531153
1154test "enum with one member and u1 tag type @enumToInt" {1154test "enum with one member and u1 tag type @enumToInt" {
1155 const Enum = enum(u1) {1155 const Enum = enum(u1) {
1156 Test,1156 Test,
1157 };1157 };
1158 expect(@enumToInt(Enum.Test) == 0);1158 try expect(@enumToInt(Enum.Test) == 0);
1159}1159}
11601160
1161test "enum with comptime_int tag type" {1161test "enum with comptime_int tag type" {
...@@ -1164,19 +1164,19 @@ test "enum with comptime_int tag type" {...@@ -1164,19 +1164,19 @@ test "enum with comptime_int tag type" {
1164 Two = 2,1164 Two = 2,
1165 Three = 1,1165 Three = 1,
1166 };1166 };
1167 comptime expect(Tag(Enum) == comptime_int);1167 comptime try expect(Tag(Enum) == comptime_int);
1168}1168}
11691169
1170test "enum with one member default to u0 tag type" {1170test "enum with one member default to u0 tag type" {
1171 const E0 = enum {1171 const E0 = enum {
1172 X,1172 X,
1173 };1173 };
1174 comptime expect(Tag(E0) == u0);1174 comptime try expect(Tag(E0) == u0);
1175}1175}
11761176
1177test "tagName on enum literals" {1177test "tagName on enum literals" {
1178 expect(mem.eql(u8, @tagName(.FooBar), "FooBar"));1178 try expect(mem.eql(u8, @tagName(.FooBar), "FooBar"));
1179 comptime expect(mem.eql(u8, @tagName(.FooBar), "FooBar"));1179 comptime try expect(mem.eql(u8, @tagName(.FooBar), "FooBar"));
1180}1180}
11811181
1182test "method call on an enum" {1182test "method call on an enum" {
...@@ -1193,12 +1193,12 @@ test "method call on an enum" {...@@ -1193,12 +1193,12 @@ test "method call on an enum" {
1193 return self.* == .two and foo == bool;1193 return self.* == .two and foo == bool;
1194 }1194 }
1195 };1195 };
1196 fn doTheTest() void {1196 fn doTheTest() !void {
1197 var e = E.two;1197 var e = E.two;
1198 expect(e.method());1198 try expect(e.method());
1199 expect(e.generic_method(bool));1199 try expect(e.generic_method(bool));
1200 }1200 }
1201 };1201 };
1202 S.doTheTest();1202 try S.doTheTest();
1203 comptime S.doTheTest();1203 comptime try S.doTheTest();
1204}1204}
test/behavior/enum_with_members.zig+4-4
...@@ -19,9 +19,9 @@ test "enum with members" {...@@ -19,9 +19,9 @@ test "enum with members" {
19 const b = ET{ .UINT = 42 };19 const b = ET{ .UINT = 42 };
20 var buf: [20]u8 = undefined;20 var buf: [20]u8 = undefined;
2121
22 expect((a.print(buf[0..]) catch unreachable) == 3);22 try expect((a.print(buf[0..]) catch unreachable) == 3);
23 expect(mem.eql(u8, buf[0..3], "-42"));23 try expect(mem.eql(u8, buf[0..3], "-42"));
2424
25 expect((b.print(buf[0..]) catch unreachable) == 2);25 try expect((b.print(buf[0..]) catch unreachable) == 2);
26 expect(mem.eql(u8, buf[0..2], "42"));26 try expect(mem.eql(u8, buf[0..2], "42"));
27}27}
test/behavior/error.zig+60-60
...@@ -19,7 +19,7 @@ pub fn baz() anyerror!i32 {...@@ -19,7 +19,7 @@ pub fn baz() anyerror!i32 {
19}19}
2020
21test "error wrapping" {21test "error wrapping" {
22 expect((baz() catch unreachable) == 15);22 try expect((baz() catch unreachable) == 15);
23}23}
2424
25fn gimmeItBroke() []const u8 {25fn gimmeItBroke() []const u8 {
...@@ -27,14 +27,14 @@ fn gimmeItBroke() []const u8 {...@@ -27,14 +27,14 @@ fn gimmeItBroke() []const u8 {
27}27}
2828
29test "@errorName" {29test "@errorName" {
30 expect(mem.eql(u8, @errorName(error.AnError), "AnError"));30 try expect(mem.eql(u8, @errorName(error.AnError), "AnError"));
31 expect(mem.eql(u8, @errorName(error.ALongerErrorName), "ALongerErrorName"));31 try expect(mem.eql(u8, @errorName(error.ALongerErrorName), "ALongerErrorName"));
32}32}
3333
34test "error values" {34test "error values" {
35 const a = @errorToInt(error.err1);35 const a = @errorToInt(error.err1);
36 const b = @errorToInt(error.err2);36 const b = @errorToInt(error.err2);
37 expect(a != b);37 try expect(a != b);
38}38}
3939
40test "redefinition of error values allowed" {40test "redefinition of error values allowed" {
...@@ -47,8 +47,8 @@ fn shouldBeNotEqual(a: anyerror, b: anyerror) void {...@@ -47,8 +47,8 @@ fn shouldBeNotEqual(a: anyerror, b: anyerror) void {
47test "error binary operator" {47test "error binary operator" {
48 const a = errBinaryOperatorG(true) catch 3;48 const a = errBinaryOperatorG(true) catch 3;
49 const b = errBinaryOperatorG(false) catch 3;49 const b = errBinaryOperatorG(false) catch 3;
50 expect(a == 3);50 try expect(a == 3);
51 expect(b == 10);51 try expect(b == 10);
52}52}
53fn errBinaryOperatorG(x: bool) anyerror!isize {53fn errBinaryOperatorG(x: bool) anyerror!isize {
54 return if (x) error.ItBroke else @as(isize, 10);54 return if (x) error.ItBroke else @as(isize, 10);
...@@ -56,7 +56,7 @@ fn errBinaryOperatorG(x: bool) anyerror!isize {...@@ -56,7 +56,7 @@ fn errBinaryOperatorG(x: bool) anyerror!isize {
5656
57test "unwrap simple value from error" {57test "unwrap simple value from error" {
58 const i = unwrapSimpleValueFromErrorDo() catch unreachable;58 const i = unwrapSimpleValueFromErrorDo() catch unreachable;
59 expect(i == 13);59 try expect(i == 13);
60}60}
61fn unwrapSimpleValueFromErrorDo() anyerror!isize {61fn unwrapSimpleValueFromErrorDo() anyerror!isize {
62 return 13;62 return 13;
...@@ -76,21 +76,21 @@ fn makeANonErr() anyerror!i32 {...@@ -76,21 +76,21 @@ fn makeANonErr() anyerror!i32 {
76}76}
7777
78test "error union type " {78test "error union type " {
79 testErrorUnionType();79 try testErrorUnionType();
80 comptime testErrorUnionType();80 comptime try testErrorUnionType();
81}81}
8282
83fn testErrorUnionType() void {83fn testErrorUnionType() !void {
84 const x: anyerror!i32 = 1234;84 const x: anyerror!i32 = 1234;
85 if (x) |value| expect(value == 1234) else |_| unreachable;85 if (x) |value| try expect(value == 1234) else |_| unreachable;
86 expect(@typeInfo(@TypeOf(x)) == .ErrorUnion);86 try expect(@typeInfo(@TypeOf(x)) == .ErrorUnion);
87 expect(@typeInfo(@typeInfo(@TypeOf(x)).ErrorUnion.error_set) == .ErrorSet);87 try expect(@typeInfo(@typeInfo(@TypeOf(x)).ErrorUnion.error_set) == .ErrorSet);
88 expect(@typeInfo(@TypeOf(x)).ErrorUnion.error_set == anyerror);88 try expect(@typeInfo(@TypeOf(x)).ErrorUnion.error_set == anyerror);
89}89}
9090
91test "error set type" {91test "error set type" {
92 testErrorSetType();92 try testErrorSetType();
93 comptime testErrorSetType();93 comptime try testErrorSetType();
94}94}
9595
96const MyErrSet = error{96const MyErrSet = error{
...@@ -98,21 +98,21 @@ const MyErrSet = error{...@@ -98,21 +98,21 @@ const MyErrSet = error{
98 FileNotFound,98 FileNotFound,
99};99};
100100
101fn testErrorSetType() void {101fn testErrorSetType() !void {
102 expect(@typeInfo(MyErrSet).ErrorSet.?.len == 2);102 try expect(@typeInfo(MyErrSet).ErrorSet.?.len == 2);
103103
104 const a: MyErrSet!i32 = 5678;104 const a: MyErrSet!i32 = 5678;
105 const b: MyErrSet!i32 = MyErrSet.OutOfMemory;105 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) {
108 error.OutOfMemory => unreachable,108 error.OutOfMemory => unreachable,
109 error.FileNotFound => unreachable,109 error.FileNotFound => unreachable,
110 }110 }
111}111}
112112
113test "explicit error set cast" {113test "explicit error set cast" {
114 testExplicitErrorSetCast(Set1.A);114 try testExplicitErrorSetCast(Set1.A);
115 comptime testExplicitErrorSetCast(Set1.A);115 comptime try testExplicitErrorSetCast(Set1.A);
116}116}
117117
118const Set1 = error{118const Set1 = error{
...@@ -124,26 +124,26 @@ const Set2 = error{...@@ -124,26 +124,26 @@ const Set2 = error{
124 C,124 C,
125};125};
126126
127fn testExplicitErrorSetCast(set1: Set1) void {127fn testExplicitErrorSetCast(set1: Set1) !void {
128 var x = @errSetCast(Set2, set1);128 var x = @errSetCast(Set2, set1);
129 var y = @errSetCast(Set1, x);129 var y = @errSetCast(Set1, x);
130 expect(y == error.A);130 try expect(y == error.A);
131}131}
132132
133test "comptime test error for empty error set" {133test "comptime test error for empty error set" {
134 testComptimeTestErrorEmptySet(1234);134 try testComptimeTestErrorEmptySet(1234);
135 comptime testComptimeTestErrorEmptySet(1234);135 comptime try testComptimeTestErrorEmptySet(1234);
136}136}
137137
138const EmptyErrorSet = error{};138const EmptyErrorSet = error{};
139139
140fn testComptimeTestErrorEmptySet(x: EmptyErrorSet!i32) void {140fn testComptimeTestErrorEmptySet(x: EmptyErrorSet!i32) !void {
141 if (x) |v| expect(v == 1234) else |err| @compileError("bad");141 if (x) |v| try expect(v == 1234) else |err| @compileError("bad");
142}142}
143143
144test "syntax: optional operator in front of error union operator" {144test "syntax: optional operator in front of error union operator" {
145 comptime {145 comptime {
146 expect(?(anyerror!i32) == ?(anyerror!i32));146 try expect(?(anyerror!i32) == ?(anyerror!i32));
147 }147 }
148}148}
149149
...@@ -165,10 +165,10 @@ test "empty error union" {...@@ -165,10 +165,10 @@ test "empty error union" {
165}165}
166166
167test "error union peer type resolution" {167test "error union peer type resolution" {
168 testErrorUnionPeerTypeResolution(1);168 try testErrorUnionPeerTypeResolution(1);
169}169}
170170
171fn testErrorUnionPeerTypeResolution(x: i32) void {171fn testErrorUnionPeerTypeResolution(x: i32) !void {
172 const y = switch (x) {172 const y = switch (x) {
173 1 => bar_1(),173 1 => bar_1(),
174 2 => baz_1(),174 2 => baz_1(),
...@@ -177,7 +177,7 @@ fn testErrorUnionPeerTypeResolution(x: i32) void {...@@ -177,7 +177,7 @@ fn testErrorUnionPeerTypeResolution(x: i32) void {
177 if (y) |_| {177 if (y) |_| {
178 @panic("expected error");178 @panic("expected error");
179 } else |e| {179 } else |e| {
180 expect(e == error.A);180 try expect(e == error.A);
181 }181 }
182}182}
183183
...@@ -286,13 +286,13 @@ test "nested error union function call in optional unwrap" {...@@ -286,13 +286,13 @@ test "nested error union function call in optional unwrap" {
286 return null;286 return null;
287 }287 }
288 };288 };
289 expect((try S.errorable()) == 1234);289 try expect((try S.errorable()) == 1234);
290 expectError(error.Failure, S.errorable2());290 try expectError(error.Failure, S.errorable2());
291 expectError(error.Other, S.errorable3());291 try expectError(error.Other, S.errorable3());
292 comptime {292 comptime {
293 expect((try S.errorable()) == 1234);293 try expect((try S.errorable()) == 1234);
294 expectError(error.Failure, S.errorable2());294 try expectError(error.Failure, S.errorable2());
295 expectError(error.Other, S.errorable3());295 try expectError(error.Other, S.errorable3());
296 }296 }
297}297}
298298
...@@ -307,7 +307,7 @@ test "widen cast integer payload of error union function call" {...@@ -307,7 +307,7 @@ test "widen cast integer payload of error union function call" {
307 return 1234;307 return 1234;
308 }308 }
309 };309 };
310 expect((try S.errorable()) == 1234);310 try expect((try S.errorable()) == 1234);
311}311}
312312
313test "return function call to error set from error union function" {313test "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" {...@@ -320,19 +320,19 @@ test "return function call to error set from error union function" {
320 return error.Failure;320 return error.Failure;
321 }321 }
322 };322 };
323 expectError(error.Failure, S.errorable());323 try expectError(error.Failure, S.errorable());
324 comptime expectError(error.Failure, S.errorable());324 comptime try expectError(error.Failure, S.errorable());
325}325}
326326
327test "optional error set is the same size as error set" {327test "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));
329 const S = struct {329 const S = struct {
330 fn returnsOptErrSet() ?anyerror {330 fn returnsOptErrSet() ?anyerror {
331 return null;331 return null;
332 }332 }
333 };333 };
334 expect(S.returnsOptErrSet() == null);334 try expect(S.returnsOptErrSet() == null);
335 comptime expect(S.returnsOptErrSet() == null);335 comptime try expect(S.returnsOptErrSet() == null);
336}336}
337337
338test "debug info for optional error set" {338test "debug info for optional error set" {
...@@ -342,8 +342,8 @@ test "debug info for optional error set" {...@@ -342,8 +342,8 @@ test "debug info for optional error set" {
342342
343test "nested catch" {343test "nested catch" {
344 const S = struct {344 const S = struct {
345 fn entry() void {345 fn entry() !void {
346 expectError(error.Bad, func());346 try expectError(error.Bad, func());
347 }347 }
348 fn fail() anyerror!Foo {348 fn fail() anyerror!Foo {
349 return error.Wrong;349 return error.Wrong;
...@@ -358,16 +358,16 @@ test "nested catch" {...@@ -358,16 +358,16 @@ test "nested catch" {
358 field: i32,358 field: i32,
359 };359 };
360 };360 };
361 S.entry();361 try S.entry();
362 comptime S.entry();362 comptime try S.entry();
363}363}
364364
365test "implicit cast to optional to error union to return result loc" {365test "implicit cast to optional to error union to return result loc" {
366 const S = struct {366 const S = struct {
367 fn entry() void {367 fn entry() !void {
368 var x: Foo = undefined;368 var x: Foo = undefined;
369 if (func(&x)) |opt| {369 if (func(&x)) |opt| {
370 expect(opt != null);370 try expect(opt != null);
371 } else |_| @panic("expected non error");371 } else |_| @panic("expected non error");
372 }372 }
373 fn func(f: *Foo) anyerror!?*Foo {373 fn func(f: *Foo) anyerror!?*Foo {
...@@ -377,7 +377,7 @@ test "implicit cast to optional to error union to return result loc" {...@@ -377,7 +377,7 @@ test "implicit cast to optional to error union to return result loc" {
377 field: i32,377 field: i32,
378 };378 };
379 };379 };
380 S.entry();380 try S.entry();
381 //comptime S.entry(); TODO381 //comptime S.entry(); TODO
382}382}
383383
...@@ -393,23 +393,23 @@ test "function pointer with return type that is error union with payload which i...@@ -393,23 +393,23 @@ test "function pointer with return type that is error union with payload which i
393 return Err.UnspecifiedErr;393 return Err.UnspecifiedErr;
394 }394 }
395395
396 fn doTheTest() void {396 fn doTheTest() !void {
397 var x = Foo{ .fun = bar };397 var x = Foo{ .fun = bar };
398 expectError(error.UnspecifiedErr, x.fun(1));398 try expectError(error.UnspecifiedErr, x.fun(1));
399 }399 }
400 };400 };
401 S.doTheTest();401 try S.doTheTest();
402}402}
403403
404test "return result loc as peer result loc in inferred error set function" {404test "return result loc as peer result loc in inferred error set function" {
405 const S = struct {405 const S = struct {
406 fn doTheTest() void {406 fn doTheTest() !void {
407 if (foo(2)) |x| {407 if (foo(2)) |x| {
408 expect(x.Two);408 try expect(x.Two);
409 } else |e| switch (e) {409 } else |e| switch (e) {
410 error.Whatever => @panic("fail"),410 error.Whatever => @panic("fail"),
411 }411 }
412 expectError(error.Whatever, foo(99));412 try expectError(error.Whatever, foo(99));
413 }413 }
414 const FormValue = union(enum) {414 const FormValue = union(enum) {
415 One: void,415 One: void,
...@@ -424,8 +424,8 @@ test "return result loc as peer result loc in inferred error set function" {...@@ -424,8 +424,8 @@ test "return result loc as peer result loc in inferred error set function" {
424 };424 };
425 }425 }
426 };426 };
427 S.doTheTest();427 try S.doTheTest();
428 comptime S.doTheTest();428 comptime try S.doTheTest();
429}429}
430430
431test "error payload type is correctly resolved" {431test "error payload type is correctly resolved" {
...@@ -439,7 +439,7 @@ test "error payload type is correctly resolved" {...@@ -439,7 +439,7 @@ test "error payload type is correctly resolved" {
439 }439 }
440 };440 };
441441
442 expectEqual(MyIntWrapper{ .x = 42 }, try MyIntWrapper.create());442 try expectEqual(MyIntWrapper{ .x = 42 }, try MyIntWrapper.create());
443}443}
444444
445test "error union comptime caching" {445test "error union comptime caching" {
...@@ -449,4 +449,4 @@ test "error union comptime caching" {...@@ -449,4 +449,4 @@ test "error union comptime caching" {
449449
450 S.foo(@as(anyerror!void, {}));450 S.foo(@as(anyerror!void, {}));
451 S.foo(@as(anyerror!void, {}));451 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;...@@ -3,7 +3,7 @@ const expect = std.testing.expect;
3const expectEqual = std.testing.expectEqual;3const expectEqual = std.testing.expectEqual;
44
5test "compile time recursion" {5test "compile time recursion" {
6 expect(some_data.len == 21);6 try expect(some_data.len == 21);
7}7}
8var some_data: [@intCast(usize, fibonacci(7))]u8 = undefined;8var some_data: [@intCast(usize, fibonacci(7))]u8 = undefined;
9fn fibonacci(x: i32) i32 {9fn fibonacci(x: i32) i32 {
...@@ -16,7 +16,7 @@ fn unwrapAndAddOne(blah: ?i32) i32 {...@@ -16,7 +16,7 @@ fn unwrapAndAddOne(blah: ?i32) i32 {
16}16}
17const should_be_1235 = unwrapAndAddOne(1234);17const should_be_1235 = unwrapAndAddOne(1234);
18test "static add one" {18test "static add one" {
19 expect(should_be_1235 == 1235);19 try expect(should_be_1235 == 1235);
20}20}
2121
22test "inlined loop" {22test "inlined loop" {
...@@ -24,7 +24,7 @@ test "inlined loop" {...@@ -24,7 +24,7 @@ test "inlined loop" {
24 comptime var sum = 0;24 comptime var sum = 0;
25 inline while (i <= 5) : (i += 1)25 inline while (i <= 5) : (i += 1)
26 sum += i;26 sum += i;
27 expect(sum == 15);27 try expect(sum == 15);
28}28}
2929
30fn gimme1or2(comptime a: bool) i32 {30fn gimme1or2(comptime a: bool) i32 {
...@@ -34,12 +34,12 @@ fn gimme1or2(comptime a: bool) i32 {...@@ -34,12 +34,12 @@ fn gimme1or2(comptime a: bool) i32 {
34 return z;34 return z;
35}35}
36test "inline variable gets result of const if" {36test "inline variable gets result of const if" {
37 expect(gimme1or2(true) == 1);37 try expect(gimme1or2(true) == 1);
38 expect(gimme1or2(false) == 2);38 try expect(gimme1or2(false) == 2);
39}39}
4040
41test "static function evaluation" {41test "static function evaluation" {
42 expect(statically_added_number == 3);42 try expect(statically_added_number == 3);
43}43}
44const statically_added_number = staticAdd(1, 2);44const statically_added_number = staticAdd(1, 2);
45fn staticAdd(a: i32, b: i32) i32 {45fn staticAdd(a: i32, b: i32) i32 {
...@@ -47,8 +47,8 @@ fn staticAdd(a: i32, b: i32) i32 {...@@ -47,8 +47,8 @@ fn staticAdd(a: i32, b: i32) i32 {
47}47}
4848
49test "const expr eval on single expr blocks" {49test "const expr eval on single expr blocks" {
50 expect(constExprEvalOnSingleExprBlocksFn(1, true) == 3);50 try expect(constExprEvalOnSingleExprBlocksFn(1, true) == 3);
51 comptime expect(constExprEvalOnSingleExprBlocksFn(1, true) == 3);51 comptime try expect(constExprEvalOnSingleExprBlocksFn(1, true) == 3);
52}52}
5353
54fn constExprEvalOnSingleExprBlocksFn(x: i32, b: bool) i32 {54fn constExprEvalOnSingleExprBlocksFn(x: i32, b: bool) i32 {
...@@ -64,10 +64,10 @@ fn constExprEvalOnSingleExprBlocksFn(x: i32, b: bool) i32 {...@@ -64,10 +64,10 @@ fn constExprEvalOnSingleExprBlocksFn(x: i32, b: bool) i32 {
64}64}
6565
66test "statically initialized list" {66test "statically initialized list" {
67 expect(static_point_list[0].x == 1);67 try expect(static_point_list[0].x == 1);
68 expect(static_point_list[0].y == 2);68 try expect(static_point_list[0].y == 2);
69 expect(static_point_list[1].x == 3);69 try expect(static_point_list[1].x == 3);
70 expect(static_point_list[1].y == 4);70 try expect(static_point_list[1].y == 4);
71}71}
72const Point = struct {72const Point = struct {
73 x: i32,73 x: i32,
...@@ -85,8 +85,8 @@ fn makePoint(x: i32, y: i32) Point {...@@ -85,8 +85,8 @@ fn makePoint(x: i32, y: i32) Point {
85}85}
8686
87test "static eval list init" {87test "static eval list init" {
88 expect(static_vec3.data[2] == 1.0);88 try expect(static_vec3.data[2] == 1.0);
89 expect(vec3(0.0, 0.0, 3.0).data[2] == 3.0);89 try expect(vec3(0.0, 0.0, 3.0).data[2] == 3.0);
90}90}
91const static_vec3 = vec3(0.0, 0.0, 1.0);91const static_vec3 = vec3(0.0, 0.0, 1.0);
92pub const Vec3 = struct {92pub const Vec3 = struct {
...@@ -104,12 +104,12 @@ pub fn vec3(x: f32, y: f32, z: f32) Vec3 {...@@ -104,12 +104,12 @@ pub fn vec3(x: f32, y: f32, z: f32) Vec3 {
104104
105test "constant expressions" {105test "constant expressions" {
106 var array: [array_size]u8 = undefined;106 var array: [array_size]u8 = undefined;
107 expect(@sizeOf(@TypeOf(array)) == 20);107 try expect(@sizeOf(@TypeOf(array)) == 20);
108}108}
109const array_size: u8 = 20;109const array_size: u8 = 20;
110110
111test "constant struct with negation" {111test "constant struct with negation" {
112 expect(vertices[0].x == -0.6);112 try expect(vertices[0].x == -0.6);
113}113}
114const Vertex = struct {114const Vertex = struct {
115 x: f32,115 x: f32,
...@@ -144,7 +144,7 @@ const vertices = [_]Vertex{...@@ -144,7 +144,7 @@ const vertices = [_]Vertex{
144144
145test "statically initialized struct" {145test "statically initialized struct" {
146 st_init_str_foo.x += 1;146 st_init_str_foo.x += 1;
147 expect(st_init_str_foo.x == 14);147 try expect(st_init_str_foo.x == 14);
148}148}
149const StInitStrFoo = struct {149const StInitStrFoo = struct {
150 x: i32,150 x: i32,
...@@ -157,7 +157,7 @@ var st_init_str_foo = StInitStrFoo{...@@ -157,7 +157,7 @@ var st_init_str_foo = StInitStrFoo{
157157
158test "statically initalized array literal" {158test "statically initalized array literal" {
159 const y: [4]u8 = st_init_arr_lit_x;159 const y: [4]u8 = st_init_arr_lit_x;
160 expect(y[3] == 4);160 try expect(y[3] == 4);
161}161}
162const st_init_arr_lit_x = [_]u8{162const st_init_arr_lit_x = [_]u8{
163 1,163 1,
...@@ -169,15 +169,15 @@ const st_init_arr_lit_x = [_]u8{...@@ -169,15 +169,15 @@ const st_init_arr_lit_x = [_]u8{
169test "const slice" {169test "const slice" {
170 comptime {170 comptime {
171 const a = "1234567890";171 const a = "1234567890";
172 expect(a.len == 10);172 try expect(a.len == 10);
173 const b = a[1..2];173 const b = a[1..2];
174 expect(b.len == 1);174 try expect(b.len == 1);
175 expect(b[0] == '2');175 try expect(b[0] == '2');
176 }176 }
177}177}
178178
179test "try to trick eval with runtime if" {179test "try to trick eval with runtime if" {
180 expect(testTryToTrickEvalWithRuntimeIf(true) == 10);180 try expect(testTryToTrickEvalWithRuntimeIf(true) == 10);
181}181}
182182
183fn testTryToTrickEvalWithRuntimeIf(b: bool) usize {183fn testTryToTrickEvalWithRuntimeIf(b: bool) usize {
...@@ -197,7 +197,7 @@ test "inlined loop has array literal with elided runtime scope on first iteratio...@@ -197,7 +197,7 @@ test "inlined loop has array literal with elided runtime scope on first iteratio
197 const result = if (i == 0) [1]i32{2} else runtime;197 const result = if (i == 0) [1]i32{2} else runtime;
198 }198 }
199 comptime {199 comptime {
200 expect(i == 2);200 try expect(i == 2);
201 }201 }
202}202}
203203
...@@ -214,16 +214,16 @@ fn letsTryToCompareBools(a: bool, b: bool) bool {...@@ -214,16 +214,16 @@ fn letsTryToCompareBools(a: bool, b: bool) bool {
214 return max(bool, a, b);214 return max(bool, a, b);
215}215}
216test "inlined block and runtime block phi" {216test "inlined block and runtime block phi" {
217 expect(letsTryToCompareBools(true, true));217 try expect(letsTryToCompareBools(true, true));
218 expect(letsTryToCompareBools(true, false));218 try expect(letsTryToCompareBools(true, false));
219 expect(letsTryToCompareBools(false, true));219 try expect(letsTryToCompareBools(false, true));
220 expect(!letsTryToCompareBools(false, false));220 try expect(!letsTryToCompareBools(false, false));
221221
222 comptime {222 comptime {
223 expect(letsTryToCompareBools(true, true));223 try expect(letsTryToCompareBools(true, true));
224 expect(letsTryToCompareBools(true, false));224 try expect(letsTryToCompareBools(true, false));
225 expect(letsTryToCompareBools(false, true));225 try expect(letsTryToCompareBools(false, true));
226 expect(!letsTryToCompareBools(false, false));226 try expect(!letsTryToCompareBools(false, false));
227 }227 }
228}228}
229229
...@@ -268,14 +268,14 @@ fn performFn(comptime prefix_char: u8, start_value: i32) i32 {...@@ -268,14 +268,14 @@ fn performFn(comptime prefix_char: u8, start_value: i32) i32 {
268}268}
269269
270test "comptime iterate over fn ptr list" {270test "comptime iterate over fn ptr list" {
271 expect(performFn('t', 1) == 6);271 try expect(performFn('t', 1) == 6);
272 expect(performFn('o', 0) == 1);272 try expect(performFn('o', 0) == 1);
273 expect(performFn('w', 99) == 99);273 try expect(performFn('w', 99) == 99);
274}274}
275275
276test "eval @setRuntimeSafety at compile-time" {276test "eval @setRuntimeSafety at compile-time" {
277 const result = comptime fnWithSetRuntimeSafety();277 const result = comptime fnWithSetRuntimeSafety();
278 expect(result == 1234);278 try expect(result == 1234);
279}279}
280280
281fn fnWithSetRuntimeSafety() i32 {281fn fnWithSetRuntimeSafety() i32 {
...@@ -285,7 +285,7 @@ fn fnWithSetRuntimeSafety() i32 {...@@ -285,7 +285,7 @@ fn fnWithSetRuntimeSafety() i32 {
285285
286test "eval @setFloatMode at compile-time" {286test "eval @setFloatMode at compile-time" {
287 const result = comptime fnWithFloatMode();287 const result = comptime fnWithFloatMode();
288 expect(result == 1234.0);288 try expect(result == 1234.0);
289}289}
290290
291fn fnWithFloatMode() f32 {291fn fnWithFloatMode() f32 {
...@@ -306,15 +306,15 @@ var simple_struct = SimpleStruct{ .field = 1234 };...@@ -306,15 +306,15 @@ var simple_struct = SimpleStruct{ .field = 1234 };
306const bound_fn = simple_struct.method;306const bound_fn = simple_struct.method;
307307
308test "call method on bound fn referring to var instance" {308test "call method on bound fn referring to var instance" {
309 expect(bound_fn() == 1237);309 try expect(bound_fn() == 1237);
310}310}
311311
312test "ptr to local array argument at comptime" {312test "ptr to local array argument at comptime" {
313 comptime {313 comptime {
314 var bytes: [10]u8 = undefined;314 var bytes: [10]u8 = undefined;
315 modifySomeBytes(bytes[0..]);315 modifySomeBytes(bytes[0..]);
316 expect(bytes[0] == 'a');316 try expect(bytes[0] == 'a');
317 expect(bytes[9] == 'b');317 try expect(bytes[9] == 'b');
318 }318 }
319}319}
320320
...@@ -342,9 +342,9 @@ fn testCompTimeUIntComparisons(x: u32) void {...@@ -342,9 +342,9 @@ fn testCompTimeUIntComparisons(x: u32) void {
342}342}
343343
344test "const ptr to variable data changes at runtime" {344test "const ptr to variable data changes at runtime" {
345 expect(foo_ref.name[0] == 'a');345 try expect(foo_ref.name[0] == 'a');
346 foo_ref.name = "b";346 foo_ref.name = "b";
347 expect(foo_ref.name[0] == 'b');347 try expect(foo_ref.name[0] == 'b');
348}348}
349349
350const Foo = struct {350const Foo = struct {
...@@ -355,8 +355,8 @@ var foo_contents = Foo{ .name = "a" };...@@ -355,8 +355,8 @@ var foo_contents = Foo{ .name = "a" };
355const foo_ref = &foo_contents;355const foo_ref = &foo_contents;
356356
357test "create global array with for loop" {357test "create global array with for loop" {
358 expect(global_array[5] == 5 * 5);358 try expect(global_array[5] == 5 * 5);
359 expect(global_array[9] == 9 * 9);359 try expect(global_array[9] == 9 * 9);
360}360}
361361
362const global_array = x: {362const global_array = x: {
...@@ -371,18 +371,18 @@ test "compile-time downcast when the bits fit" {...@@ -371,18 +371,18 @@ test "compile-time downcast when the bits fit" {
371 comptime {371 comptime {
372 const spartan_count: u16 = 255;372 const spartan_count: u16 = 255;
373 const byte = @intCast(u8, spartan_count);373 const byte = @intCast(u8, spartan_count);
374 expect(byte == 255);374 try expect(byte == 255);
375 }375 }
376}376}
377377
378const hi1 = "hi";378const hi1 = "hi";
379const hi2 = hi1;379const hi2 = hi1;
380test "const global shares pointer with other same one" {380test "const global shares pointer with other same one" {
381 assertEqualPtrs(&hi1[0], &hi2[0]);381 try assertEqualPtrs(&hi1[0], &hi2[0]);
382 comptime expect(&hi1[0] == &hi2[0]);382 comptime try expect(&hi1[0] == &hi2[0]);
383}383}
384fn assertEqualPtrs(ptr1: *const u8, ptr2: *const u8) void {384fn assertEqualPtrs(ptr1: *const u8, ptr2: *const u8) !void {
385 expect(ptr1 == ptr2);385 try expect(ptr1 == ptr2);
386}386}
387387
388test "@setEvalBranchQuota" {388test "@setEvalBranchQuota" {
...@@ -394,29 +394,29 @@ test "@setEvalBranchQuota" {...@@ -394,29 +394,29 @@ test "@setEvalBranchQuota" {
394 while (i < 1001) : (i += 1) {394 while (i < 1001) : (i += 1) {
395 sum += i;395 sum += i;
396 }396 }
397 expect(sum == 500500);397 try expect(sum == 500500);
398 }398 }
399}399}
400400
401test "float literal at compile time not lossy" {401test "float literal at compile time not lossy" {
402 expect(16777216.0 + 1.0 == 16777217.0);402 try expect(16777216.0 + 1.0 == 16777217.0);
403 expect(9007199254740992.0 + 1.0 == 9007199254740993.0);403 try expect(9007199254740992.0 + 1.0 == 9007199254740993.0);
404}404}
405405
406test "f32 at compile time is lossy" {406test "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);
408}408}
409409
410test "f64 at compile time is lossy" {410test "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);
412}412}
413413
414test "f128 at compile time is lossy" {414test "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);
416}416}
417417
418comptime {418comptime {
419 expect(@as(f128, 1 << 113) == 10384593717069655257060992658440192);419 try expect(@as(f128, 1 << 113) == 10384593717069655257060992658440192);
420}420}
421421
422pub fn TypeWithCompTimeSlice(comptime field_name: []const u8) type {422pub fn TypeWithCompTimeSlice(comptime field_name: []const u8) type {
...@@ -428,15 +428,15 @@ pub fn TypeWithCompTimeSlice(comptime field_name: []const u8) type {...@@ -428,15 +428,15 @@ pub fn TypeWithCompTimeSlice(comptime field_name: []const u8) type {
428test "string literal used as comptime slice is memoized" {428test "string literal used as comptime slice is memoized" {
429 const a = "link";429 const a = "link";
430 const b = "link";430 const b = "link";
431 comptime expect(TypeWithCompTimeSlice(a).Node == TypeWithCompTimeSlice(b).Node);431 comptime try expect(TypeWithCompTimeSlice(a).Node == TypeWithCompTimeSlice(b).Node);
432 comptime expect(TypeWithCompTimeSlice("link").Node == TypeWithCompTimeSlice("link").Node);432 comptime try expect(TypeWithCompTimeSlice("link").Node == TypeWithCompTimeSlice("link").Node);
433}433}
434434
435test "comptime slice of undefined pointer of length 0" {435test "comptime slice of undefined pointer of length 0" {
436 const slice1 = @as([*]i32, undefined)[0..0];436 const slice1 = @as([*]i32, undefined)[0..0];
437 expect(slice1.len == 0);437 try expect(slice1.len == 0);
438 const slice2 = @as([*]i32, undefined)[100..100];438 const slice2 = @as([*]i32, undefined)[100..100];
439 expect(slice2.len == 0);439 try expect(slice2.len == 0);
440}440}
441441
442fn copyWithPartialInline(s: []u32, b: []u8) void {442fn copyWithPartialInline(s: []u32, b: []u8) void {
...@@ -458,16 +458,16 @@ test "binary math operator in partially inlined function" {...@@ -458,16 +458,16 @@ test "binary math operator in partially inlined function" {
458 r.* = @intCast(u8, i + 1);458 r.* = @intCast(u8, i + 1);
459459
460 copyWithPartialInline(s[0..], b[0..]);460 copyWithPartialInline(s[0..], b[0..]);
461 expect(s[0] == 0x1020304);461 try expect(s[0] == 0x1020304);
462 expect(s[1] == 0x5060708);462 try expect(s[1] == 0x5060708);
463 expect(s[2] == 0x90a0b0c);463 try expect(s[2] == 0x90a0b0c);
464 expect(s[3] == 0xd0e0f10);464 try expect(s[3] == 0xd0e0f10);
465}465}
466466
467test "comptime function with the same args is memoized" {467test "comptime function with the same args is memoized" {
468 comptime {468 comptime {
469 expect(MakeType(i32) == MakeType(i32));469 try expect(MakeType(i32) == MakeType(i32));
470 expect(MakeType(i32) != MakeType(f64));470 try expect(MakeType(i32) != MakeType(f64));
471 }471 }
472}472}
473473
...@@ -483,7 +483,7 @@ test "comptime function with mutable pointer is not memoized" {...@@ -483,7 +483,7 @@ test "comptime function with mutable pointer is not memoized" {
483 const ptr = &x;483 const ptr = &x;
484 increment(ptr);484 increment(ptr);
485 increment(ptr);485 increment(ptr);
486 expect(x == 3);486 try expect(x == 3);
487 }487 }
488}488}
489489
...@@ -509,14 +509,14 @@ fn doesAlotT(comptime T: type, value: usize) T {...@@ -509,14 +509,14 @@ fn doesAlotT(comptime T: type, value: usize) T {
509}509}
510510
511test "@setEvalBranchQuota at same scope as generic function call" {511test "@setEvalBranchQuota at same scope as generic function call" {
512 expect(doesAlotT(u32, 2) == 2);512 try expect(doesAlotT(u32, 2) == 2);
513}513}
514514
515test "comptime slice of slice preserves comptime var" {515test "comptime slice of slice preserves comptime var" {
516 comptime {516 comptime {
517 var buff: [10]u8 = undefined;517 var buff: [10]u8 = undefined;
518 buff[0..][0..][0] = 1;518 buff[0..][0..][0] = 1;
519 expect(buff[0..][0..][0] == 1);519 try expect(buff[0..][0..][0] == 1);
520 }520 }
521}521}
522522
...@@ -525,7 +525,7 @@ test "comptime slice of pointer preserves comptime var" {...@@ -525,7 +525,7 @@ test "comptime slice of pointer preserves comptime var" {
525 var buff: [10]u8 = undefined;525 var buff: [10]u8 = undefined;
526 var a = @ptrCast([*]u8, &buff);526 var a = @ptrCast([*]u8, &buff);
527 a[0..1][0] = 1;527 a[0..1][0] = 1;
528 expect(buff[0..][0..][0] == 1);528 try expect(buff[0..][0..][0] == 1);
529 }529 }
530}530}
531531
...@@ -539,9 +539,9 @@ const SingleFieldStruct = struct {...@@ -539,9 +539,9 @@ const SingleFieldStruct = struct {
539test "const ptr to comptime mutable data is not memoized" {539test "const ptr to comptime mutable data is not memoized" {
540 comptime {540 comptime {
541 var foo = SingleFieldStruct{ .x = 1 };541 var foo = SingleFieldStruct{ .x = 1 };
542 expect(foo.read_x() == 1);542 try expect(foo.read_x() == 1);
543 foo.x = 2;543 foo.x = 2;
544 expect(foo.read_x() == 2);544 try expect(foo.read_x() == 2);
545 }545 }
546}546}
547547
...@@ -550,7 +550,7 @@ test "array concat of slices gives slice" {...@@ -550,7 +550,7 @@ test "array concat of slices gives slice" {
550 var a: []const u8 = "aoeu";550 var a: []const u8 = "aoeu";
551 var b: []const u8 = "asdf";551 var b: []const u8 = "asdf";
552 const c = a ++ b;552 const c = a ++ b;
553 expect(std.mem.eql(u8, c, "aoeuasdf"));553 try expect(std.mem.eql(u8, c, "aoeuasdf"));
554 }554 }
555}555}
556556
...@@ -567,14 +567,14 @@ test "comptime shlWithOverflow" {...@@ -567,14 +567,14 @@ test "comptime shlWithOverflow" {
567 break :amt amt;567 break :amt amt;
568 };568 };
569569
570 expect(ct_shifted == rt_shifted);570 try expect(ct_shifted == rt_shifted);
571}571}
572572
573test "runtime 128 bit integer division" {573test "runtime 128 bit integer division" {
574 var a: u128 = 152313999999999991610955792383;574 var a: u128 = 152313999999999991610955792383;
575 var b: u128 = 10000000000000000000;575 var b: u128 = 10000000000000000000;
576 var c = a / b;576 var c = a / b;
577 expect(c == 15231399999);577 try expect(c == 15231399999);
578}578}
579579
580pub const Info = struct {580pub const Info = struct {
...@@ -587,20 +587,20 @@ test "comptime modification of const struct field" {...@@ -587,20 +587,20 @@ test "comptime modification of const struct field" {
587 comptime {587 comptime {
588 var res = diamond_info;588 var res = diamond_info;
589 res.version = 1;589 res.version = 1;
590 expect(diamond_info.version == 0);590 try expect(diamond_info.version == 0);
591 expect(res.version == 1);591 try expect(res.version == 1);
592 }592 }
593}593}
594594
595test "pointer to type" {595test "pointer to type" {
596 comptime {596 comptime {
597 var T: type = i32;597 var T: type = i32;
598 expect(T == i32);598 try expect(T == i32);
599 var ptr = &T;599 var ptr = &T;
600 expect(@TypeOf(ptr) == *type);600 try expect(@TypeOf(ptr) == *type);
601 ptr.* = f32;601 ptr.* = f32;
602 expect(T == f32);602 try expect(T == f32);
603 expect(*T == *f32);603 try expect(*T == *f32);
604 }604 }
605}605}
606606
...@@ -609,17 +609,17 @@ test "slice of type" {...@@ -609,17 +609,17 @@ test "slice of type" {
609 var types_array = [_]type{ i32, f64, type };609 var types_array = [_]type{ i32, f64, type };
610 for (types_array) |T, i| {610 for (types_array) |T, i| {
611 switch (i) {611 switch (i) {
612 0 => expect(T == i32),612 0 => try expect(T == i32),
613 1 => expect(T == f64),613 1 => try expect(T == f64),
614 2 => expect(T == type),614 2 => try expect(T == type),
615 else => unreachable,615 else => unreachable,
616 }616 }
617 }617 }
618 for (types_array[0..]) |T, i| {618 for (types_array[0..]) |T, i| {
619 switch (i) {619 switch (i) {
620 0 => expect(T == i32),620 0 => try expect(T == i32),
621 1 => expect(T == f64),621 1 => try expect(T == f64),
622 2 => expect(T == type),622 2 => try expect(T == type),
623 else => unreachable,623 else => unreachable,
624 }624 }
625 }625 }
...@@ -636,7 +636,7 @@ fn wrap(comptime T: type) Wrapper {...@@ -636,7 +636,7 @@ fn wrap(comptime T: type) Wrapper {
636636
637test "function which returns struct with type field causes implicit comptime" {637test "function which returns struct with type field causes implicit comptime" {
638 const ty = wrap(i32).T;638 const ty = wrap(i32).T;
639 expect(ty == i32);639 try expect(ty == i32);
640}640}
641641
642test "call method with comptime pass-by-non-copying-value self parameter" {642test "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" {...@@ -650,12 +650,12 @@ test "call method with comptime pass-by-non-copying-value self parameter" {
650650
651 const s = S{ .a = 2 };651 const s = S{ .a = 2 };
652 var b = s.b();652 var b = s.b();
653 expect(b == 2);653 try expect(b == 2);
654}654}
655655
656test "@tagName of @typeInfo" {656test "@tagName of @typeInfo" {
657 const str = @tagName(@typeInfo(u8));657 const str = @tagName(@typeInfo(u8));
658 expect(std.mem.eql(u8, str, "Int"));658 try expect(std.mem.eql(u8, str, "Int"));
659}659}
660660
661test "setting backward branch quota just before a generic fn call" {661test "setting backward branch quota just before a generic fn call" {
...@@ -669,15 +669,15 @@ fn loopNTimes(comptime n: usize) void {...@@ -669,15 +669,15 @@ fn loopNTimes(comptime n: usize) void {
669}669}
670670
671test "variable inside inline loop that has different types on different iterations" {671test "variable inside inline loop that has different types on different iterations" {
672 testVarInsideInlineLoop(.{ true, @as(u32, 42) });672 try testVarInsideInlineLoop(.{ true, @as(u32, 42) });
673}673}
674674
675fn testVarInsideInlineLoop(args: anytype) void {675fn testVarInsideInlineLoop(args: anytype) !void {
676 comptime var i = 0;676 comptime var i = 0;
677 inline while (i < args.len) : (i += 1) {677 inline while (i < args.len) : (i += 1) {
678 const x = args[i];678 const x = args[i];
679 if (i == 0) expect(x);679 if (i == 0) try expect(x);
680 if (i == 1) expect(x == 42);680 if (i == 1) try expect(x == 42);
681 }681 }
682}682}
683683
...@@ -687,7 +687,7 @@ test "inline for with same type but different values" {...@@ -687,7 +687,7 @@ test "inline for with same type but different values" {
687 var a: T = undefined;687 var a: T = undefined;
688 res += a.len;688 res += a.len;
689 }689 }
690 expect(res == 5);690 try expect(res == 5);
691}691}
692692
693test "refer to the type of a generic function" {693test "refer to the type of a generic function" {
...@@ -701,13 +701,13 @@ fn doNothingWithType(comptime T: type) void {}...@@ -701,13 +701,13 @@ fn doNothingWithType(comptime T: type) void {}
701test "zero extend from u0 to u1" {701test "zero extend from u0 to u1" {
702 var zero_u0: u0 = 0;702 var zero_u0: u0 = 0;
703 var zero_u1: u1 = zero_u0;703 var zero_u1: u1 = zero_u0;
704 expect(zero_u1 == 0);704 try expect(zero_u1 == 0);
705}705}
706706
707test "bit shift a u1" {707test "bit shift a u1" {
708 var x: u1 = 1;708 var x: u1 = 1;
709 var y = x << 0;709 var y = x << 0;
710 expect(y == 1);710 try expect(y == 1);
711}711}
712712
713test "comptime pointer cast array and then slice" {713test "comptime pointer cast array and then slice" {
...@@ -719,8 +719,8 @@ test "comptime pointer cast array and then slice" {...@@ -719,8 +719,8 @@ test "comptime pointer cast array and then slice" {
719 const ptrB: [*]const u8 = &array;719 const ptrB: [*]const u8 = &array;
720 const sliceB: []const u8 = ptrB[0..2];720 const sliceB: []const u8 = ptrB[0..2];
721721
722 expect(sliceA[1] == 2);722 try expect(sliceA[1] == 2);
723 expect(sliceB[1] == 2);723 try expect(sliceB[1] == 2);
724}724}
725725
726test "slice bounds in comptime concatenation" {726test "slice bounds in comptime concatenation" {
...@@ -729,46 +729,46 @@ test "slice bounds in comptime concatenation" {...@@ -729,46 +729,46 @@ test "slice bounds in comptime concatenation" {
729 break :blk b[8..9];729 break :blk b[8..9];
730 };730 };
731 const str = "" ++ bs;731 const str = "" ++ bs;
732 expect(str.len == 1);732 try expect(str.len == 1);
733 expect(std.mem.eql(u8, str, "1"));733 try expect(std.mem.eql(u8, str, "1"));
734734
735 const str2 = bs ++ "";735 const str2 = bs ++ "";
736 expect(str2.len == 1);736 try expect(str2.len == 1);
737 expect(std.mem.eql(u8, str2, "1"));737 try expect(std.mem.eql(u8, str2, "1"));
738}738}
739739
740test "comptime bitwise operators" {740test "comptime bitwise operators" {
741 comptime {741 comptime {
742 expect(3 & 1 == 1);742 try expect(3 & 1 == 1);
743 expect(3 & -1 == 3);743 try expect(3 & -1 == 3);
744 expect(-3 & -1 == -3);744 try expect(-3 & -1 == -3);
745 expect(3 | -1 == -1);745 try expect(3 | -1 == -1);
746 expect(-3 | -1 == -1);746 try expect(-3 | -1 == -1);
747 expect(3 ^ -1 == -4);747 try expect(3 ^ -1 == -4);
748 expect(-3 ^ -1 == 2);748 try expect(-3 ^ -1 == 2);
749 expect(~@as(i8, -1) == 0);749 try expect(~@as(i8, -1) == 0);
750 expect(~@as(i128, -1) == 0);750 try expect(~@as(i128, -1) == 0);
751 expect(18446744073709551615 & 18446744073709551611 == 18446744073709551611);751 try expect(18446744073709551615 & 18446744073709551611 == 18446744073709551611);
752 expect(-18446744073709551615 & -18446744073709551611 == -18446744073709551615);752 try expect(-18446744073709551615 & -18446744073709551611 == -18446744073709551615);
753 expect(~@as(u128, 0) == 0xffffffffffffffffffffffffffffffff);753 try expect(~@as(u128, 0) == 0xffffffffffffffffffffffffffffffff);
754 }754 }
755}755}
756756
757test "*align(1) u16 is the same as *align(1:0:2) u16" {757test "*align(1) u16 is the same as *align(1:0:2) u16" {
758 comptime {758 comptime {
759 expect(*align(1:0:2) u16 == *align(1) u16);759 try expect(*align(1:0:2) u16 == *align(1) u16);
760 expect(*align(2:0:2) u16 == *u16);760 try expect(*align(2:0:2) u16 == *u16);
761 }761 }
762}762}
763763
764test "array concatenation forces comptime" {764test "array concatenation forces comptime" {
765 var a = oneItem(3) ++ oneItem(4);765 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 }));
767}767}
768768
769test "array multiplication forces comptime" {769test "array multiplication forces comptime" {
770 var a = oneItem(3) ** scalar(2);770 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 }));
772}772}
773773
774fn oneItem(x: i32) [1]i32 {774fn oneItem(x: i32) [1]i32 {
...@@ -790,7 +790,7 @@ test "comptime assign int to optional int" {...@@ -790,7 +790,7 @@ test "comptime assign int to optional int" {
790 var x: ?i32 = null;790 var x: ?i32 = null;
791 x = 2;791 x = 2;
792 x.? *= 10;792 x.? *= 10;
793 expectEqual(20, x.?);793 try expectEqual(20, x.?);
794 }794 }
795}795}
796796
test/behavior/field_parent_ptr.zig+12-12
...@@ -1,13 +1,13 @@...@@ -1,13 +1,13 @@
1const expect = @import("std").testing.expect;1const expect = @import("std").testing.expect;
22
3test "@fieldParentPtr non-first field" {3test "@fieldParentPtr non-first field" {
4 testParentFieldPtr(&foo.c);4 try testParentFieldPtr(&foo.c);
5 comptime testParentFieldPtr(&foo.c);5 comptime try testParentFieldPtr(&foo.c);
6}6}
77
8test "@fieldParentPtr first field" {8test "@fieldParentPtr first field" {
9 testParentFieldPtrFirst(&foo.a);9 try testParentFieldPtrFirst(&foo.a);
10 comptime testParentFieldPtrFirst(&foo.a);10 comptime try testParentFieldPtrFirst(&foo.a);
11}11}
1212
13const Foo = struct {13const Foo = struct {
...@@ -24,18 +24,18 @@ const foo = Foo{...@@ -24,18 +24,18 @@ const foo = Foo{
24 .d = -10,24 .d = -10,
25};25};
2626
27fn testParentFieldPtr(c: *const i32) void {27fn testParentFieldPtr(c: *const i32) !void {
28 expect(c == &foo.c);28 try expect(c == &foo.c);
2929
30 const base = @fieldParentPtr(Foo, "c", c);30 const base = @fieldParentPtr(Foo, "c", c);
31 expect(base == &foo);31 try expect(base == &foo);
32 expect(&base.c == c);32 try expect(&base.c == c);
33}33}
3434
35fn testParentFieldPtrFirst(a: *const bool) void {35fn testParentFieldPtrFirst(a: *const bool) !void {
36 expect(a == &foo.a);36 try expect(a == &foo.a);
3737
38 const base = @fieldParentPtr(Foo, "a", a);38 const base = @fieldParentPtr(Foo, "a", a);
39 expect(base == &foo);39 try expect(base == &foo);
40 expect(&base.a == a);40 try expect(&base.a == a);
41}41}
test/behavior/floatop.zig+161-161
...@@ -8,441 +8,441 @@ const Vector = std.meta.Vector;...@@ -8,441 +8,441 @@ const Vector = std.meta.Vector;
8const epsilon = 0.000001;8const epsilon = 0.000001;
99
10test "@sqrt" {10test "@sqrt" {
11 comptime testSqrt();11 comptime try testSqrt();
12 testSqrt();12 try testSqrt();
13}13}
1414
15fn testSqrt() void {15fn testSqrt() !void {
16 {16 {
17 var a: f16 = 4;17 var a: f16 = 4;
18 expect(@sqrt(a) == 2);18 try expect(@sqrt(a) == 2);
19 }19 }
20 {20 {
21 var a: f32 = 9;21 var a: f32 = 9;
22 expect(@sqrt(a) == 3);22 try expect(@sqrt(a) == 3);
23 var b: f32 = 1.1;23 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));
25 }25 }
26 {26 {
27 var a: f64 = 25;27 var a: f64 = 25;
28 expect(@sqrt(a) == 5);28 try expect(@sqrt(a) == 5);
29 }29 }
30 {30 {
31 const a: comptime_float = 25.0;31 const a: comptime_float = 25.0;
32 expect(@sqrt(a) == 5.0);32 try expect(@sqrt(a) == 5.0);
33 }33 }
34 // TODO https://github.com/ziglang/zig/issues/402634 // TODO https://github.com/ziglang/zig/issues/4026
35 //{35 //{
36 // var a: f128 = 49;36 // var a: f128 = 49;
37 // expect(@sqrt(a) == 7);37 //try expect(@sqrt(a) == 7);
38 //}38 //}
39 {39 {
40 var v: Vector(4, f32) = [_]f32{ 1.1, 2.2, 3.3, 4.4 };40 var v: Vector(4, f32) = [_]f32{ 1.1, 2.2, 3.3, 4.4 };
41 var result = @sqrt(v);41 var result = @sqrt(v);
42 expect(math.approxEqAbs(f32, @sqrt(@as(f32, 1.1)), result[0], epsilon));42 try 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));43 try 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));44 try 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));45 try expect(math.approxEqAbs(f32, @sqrt(@as(f32, 4.4)), result[3], epsilon));
46 }46 }
47}47}
4848
49test "more @sqrt f16 tests" {49test "more @sqrt f16 tests" {
50 // TODO these are not all passing at comptime50 // TODO these are not all passing at comptime
51 expect(@sqrt(@as(f16, 0.0)) == 0.0);51 try expect(@sqrt(@as(f16, 0.0)) == 0.0);
52 expect(math.approxEqAbs(f16, @sqrt(@as(f16, 2.0)), 1.414214, epsilon));52 try 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));53 try expect(math.approxEqAbs(f16, @sqrt(@as(f16, 3.6)), 1.897367, epsilon));
54 expect(@sqrt(@as(f16, 4.0)) == 2.0);54 try expect(@sqrt(@as(f16, 4.0)) == 2.0);
55 expect(math.approxEqAbs(f16, @sqrt(@as(f16, 7.539840)), 2.745877, epsilon));55 try 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));56 try expect(math.approxEqAbs(f16, @sqrt(@as(f16, 19.230934)), 4.385309, epsilon));
57 expect(@sqrt(@as(f16, 64.0)) == 8.0);57 try expect(@sqrt(@as(f16, 64.0)) == 8.0);
58 expect(math.approxEqAbs(f16, @sqrt(@as(f16, 64.1)), 8.006248, epsilon));58 try 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));59 try expect(math.approxEqAbs(f16, @sqrt(@as(f16, 8942.230469)), 94.563370, epsilon));
6060
61 // special cases61 // special cases
62 expect(math.isPositiveInf(@sqrt(@as(f16, math.inf(f16)))));62 try expect(math.isPositiveInf(@sqrt(@as(f16, math.inf(f16)))));
63 expect(@sqrt(@as(f16, 0.0)) == 0.0);63 try expect(@sqrt(@as(f16, 0.0)) == 0.0);
64 expect(@sqrt(@as(f16, -0.0)) == -0.0);64 try expect(@sqrt(@as(f16, -0.0)) == -0.0);
65 expect(math.isNan(@sqrt(@as(f16, -1.0))));65 try expect(math.isNan(@sqrt(@as(f16, -1.0))));
66 expect(math.isNan(@sqrt(@as(f16, math.nan(f16)))));66 try expect(math.isNan(@sqrt(@as(f16, math.nan(f16)))));
67}67}
6868
69test "@sin" {69test "@sin" {
70 comptime testSin();70 comptime try testSin();
71 testSin();71 try testSin();
72}72}
7373
74fn testSin() void {74fn testSin() !void {
75 // TODO test f128, and c_longdouble75 // TODO test f128, and c_longdouble
76 // https://github.com/ziglang/zig/issues/402676 // https://github.com/ziglang/zig/issues/4026
77 {77 {
78 var a: f16 = 0;78 var a: f16 = 0;
79 expect(@sin(a) == 0);79 try expect(@sin(a) == 0);
80 }80 }
81 {81 {
82 var a: f32 = 0;82 var a: f32 = 0;
83 expect(@sin(a) == 0);83 try expect(@sin(a) == 0);
84 }84 }
85 {85 {
86 var a: f64 = 0;86 var a: f64 = 0;
87 expect(@sin(a) == 0);87 try expect(@sin(a) == 0);
88 }88 }
89 {89 {
90 var v: Vector(4, f32) = [_]f32{ 1.1, 2.2, 3.3, 4.4 };90 var v: Vector(4, f32) = [_]f32{ 1.1, 2.2, 3.3, 4.4 };
91 var result = @sin(v);91 var result = @sin(v);
92 expect(math.approxEqAbs(f32, @sin(@as(f32, 1.1)), result[0], epsilon));92 try 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));93 try 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));94 try 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));95 try expect(math.approxEqAbs(f32, @sin(@as(f32, 4.4)), result[3], epsilon));
96 }96 }
97}97}
9898
99test "@cos" {99test "@cos" {
100 comptime testCos();100 comptime try testCos();
101 testCos();101 try testCos();
102}102}
103103
104fn testCos() void {104fn testCos() !void {
105 // TODO test f128, and c_longdouble105 // TODO test f128, and c_longdouble
106 // https://github.com/ziglang/zig/issues/4026106 // https://github.com/ziglang/zig/issues/4026
107 {107 {
108 var a: f16 = 0;108 var a: f16 = 0;
109 expect(@cos(a) == 1);109 try expect(@cos(a) == 1);
110 }110 }
111 {111 {
112 var a: f32 = 0;112 var a: f32 = 0;
113 expect(@cos(a) == 1);113 try expect(@cos(a) == 1);
114 }114 }
115 {115 {
116 var a: f64 = 0;116 var a: f64 = 0;
117 expect(@cos(a) == 1);117 try expect(@cos(a) == 1);
118 }118 }
119 {119 {
120 var v: Vector(4, f32) = [_]f32{ 1.1, 2.2, 3.3, 4.4 };120 var v: Vector(4, f32) = [_]f32{ 1.1, 2.2, 3.3, 4.4 };
121 var result = @cos(v);121 var result = @cos(v);
122 expect(math.approxEqAbs(f32, @cos(@as(f32, 1.1)), result[0], epsilon));122 try 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));123 try 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));124 try 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));125 try expect(math.approxEqAbs(f32, @cos(@as(f32, 4.4)), result[3], epsilon));
126 }126 }
127}127}
128128
129test "@exp" {129test "@exp" {
130 comptime testExp();130 comptime try testExp();
131 testExp();131 try testExp();
132}132}
133133
134fn testExp() void {134fn testExp() !void {
135 // TODO test f128, and c_longdouble135 // TODO test f128, and c_longdouble
136 // https://github.com/ziglang/zig/issues/4026136 // https://github.com/ziglang/zig/issues/4026
137 {137 {
138 var a: f16 = 0;138 var a: f16 = 0;
139 expect(@exp(a) == 1);139 try expect(@exp(a) == 1);
140 }140 }
141 {141 {
142 var a: f32 = 0;142 var a: f32 = 0;
143 expect(@exp(a) == 1);143 try expect(@exp(a) == 1);
144 }144 }
145 {145 {
146 var a: f64 = 0;146 var a: f64 = 0;
147 expect(@exp(a) == 1);147 try expect(@exp(a) == 1);
148 }148 }
149 {149 {
150 var v: Vector(4, f32) = [_]f32{ 1.1, 2.2, 0.3, 0.4 };150 var v: Vector(4, f32) = [_]f32{ 1.1, 2.2, 0.3, 0.4 };
151 var result = @exp(v);151 var result = @exp(v);
152 expect(math.approxEqAbs(f32, @exp(@as(f32, 1.1)), result[0], epsilon));152 try 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));153 try 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));154 try 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));155 try expect(math.approxEqAbs(f32, @exp(@as(f32, 0.4)), result[3], epsilon));
156 }156 }
157}157}
158158
159test "@exp2" {159test "@exp2" {
160 comptime testExp2();160 comptime try testExp2();
161 testExp2();161 try testExp2();
162}162}
163163
164fn testExp2() void {164fn testExp2() !void {
165 // TODO test f128, and c_longdouble165 // TODO test f128, and c_longdouble
166 // https://github.com/ziglang/zig/issues/4026166 // https://github.com/ziglang/zig/issues/4026
167 {167 {
168 var a: f16 = 2;168 var a: f16 = 2;
169 expect(@exp2(a) == 4);169 try expect(@exp2(a) == 4);
170 }170 }
171 {171 {
172 var a: f32 = 2;172 var a: f32 = 2;
173 expect(@exp2(a) == 4);173 try expect(@exp2(a) == 4);
174 }174 }
175 {175 {
176 var a: f64 = 2;176 var a: f64 = 2;
177 expect(@exp2(a) == 4);177 try expect(@exp2(a) == 4);
178 }178 }
179 {179 {
180 var v: Vector(4, f32) = [_]f32{ 1.1, 2.2, 0.3, 0.4 };180 var v: Vector(4, f32) = [_]f32{ 1.1, 2.2, 0.3, 0.4 };
181 var result = @exp2(v);181 var result = @exp2(v);
182 expect(math.approxEqAbs(f32, @exp2(@as(f32, 1.1)), result[0], epsilon));182 try 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));183 try 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));184 try 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));185 try expect(math.approxEqAbs(f32, @exp2(@as(f32, 0.4)), result[3], epsilon));
186 }186 }
187}187}
188188
189test "@log" {189test "@log" {
190 // Old musl (and glibc?), and our current math.ln implementation do not return 1190 // Old musl (and glibc?), and our current math.ln implementation do not return 1
191 // so also accept those values.191 // so also accept those values.
192 comptime testLog();192 comptime try testLog();
193 testLog();193 try testLog();
194}194}
195195
196fn testLog() void {196fn testLog() !void {
197 // TODO test f128, and c_longdouble197 // TODO test f128, and c_longdouble
198 // https://github.com/ziglang/zig/issues/4026198 // https://github.com/ziglang/zig/issues/4026
199 {199 {
200 var a: f16 = e;200 var a: f16 = e;
201 expect(math.approxEqAbs(f16, @log(a), 1, epsilon));201 try expect(math.approxEqAbs(f16, @log(a), 1, epsilon));
202 }202 }
203 {203 {
204 var a: f32 = e;204 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)));
206 }206 }
207 {207 {
208 var a: f64 = e;208 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)));
210 }210 }
211 {211 {
212 var v: Vector(4, f32) = [_]f32{ 1.1, 2.2, 0.3, 0.4 };212 var v: Vector(4, f32) = [_]f32{ 1.1, 2.2, 0.3, 0.4 };
213 var result = @log(v);213 var result = @log(v);
214 expect(math.approxEqAbs(f32, @log(@as(f32, 1.1)), result[0], epsilon));214 try 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));215 try 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));216 try 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));217 try expect(math.approxEqAbs(f32, @log(@as(f32, 0.4)), result[3], epsilon));
218 }218 }
219}219}
220220
221test "@log2" {221test "@log2" {
222 comptime testLog2();222 comptime try testLog2();
223 testLog2();223 try testLog2();
224}224}
225225
226fn testLog2() void {226fn testLog2() !void {
227 // TODO test f128, and c_longdouble227 // TODO test f128, and c_longdouble
228 // https://github.com/ziglang/zig/issues/4026228 // https://github.com/ziglang/zig/issues/4026
229 {229 {
230 var a: f16 = 4;230 var a: f16 = 4;
231 expect(@log2(a) == 2);231 try expect(@log2(a) == 2);
232 }232 }
233 {233 {
234 var a: f32 = 4;234 var a: f32 = 4;
235 expect(@log2(a) == 2);235 try expect(@log2(a) == 2);
236 }236 }
237 {237 {
238 var a: f64 = 4;238 var a: f64 = 4;
239 expect(@log2(a) == 2);239 try expect(@log2(a) == 2);
240 }240 }
241 {241 {
242 var v: Vector(4, f32) = [_]f32{ 1.1, 2.2, 0.3, 0.4 };242 var v: Vector(4, f32) = [_]f32{ 1.1, 2.2, 0.3, 0.4 };
243 var result = @log2(v);243 var result = @log2(v);
244 expect(math.approxEqAbs(f32, @log2(@as(f32, 1.1)), result[0], epsilon));244 try 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));245 try 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));246 try 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));247 try expect(math.approxEqAbs(f32, @log2(@as(f32, 0.4)), result[3], epsilon));
248 }248 }
249}249}
250250
251test "@log10" {251test "@log10" {
252 comptime testLog10();252 comptime try testLog10();
253 testLog10();253 try testLog10();
254}254}
255255
256fn testLog10() void {256fn testLog10() !void {
257 // TODO test f128, and c_longdouble257 // TODO test f128, and c_longdouble
258 // https://github.com/ziglang/zig/issues/4026258 // https://github.com/ziglang/zig/issues/4026
259 {259 {
260 var a: f16 = 100;260 var a: f16 = 100;
261 expect(@log10(a) == 2);261 try expect(@log10(a) == 2);
262 }262 }
263 {263 {
264 var a: f32 = 100;264 var a: f32 = 100;
265 expect(@log10(a) == 2);265 try expect(@log10(a) == 2);
266 }266 }
267 {267 {
268 var a: f64 = 1000;268 var a: f64 = 1000;
269 expect(@log10(a) == 3);269 try expect(@log10(a) == 3);
270 }270 }
271 {271 {
272 var v: Vector(4, f32) = [_]f32{ 1.1, 2.2, 0.3, 0.4 };272 var v: Vector(4, f32) = [_]f32{ 1.1, 2.2, 0.3, 0.4 };
273 var result = @log10(v);273 var result = @log10(v);
274 expect(math.approxEqAbs(f32, @log10(@as(f32, 1.1)), result[0], epsilon));274 try 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));275 try 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));276 try 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));277 try expect(math.approxEqAbs(f32, @log10(@as(f32, 0.4)), result[3], epsilon));
278 }278 }
279}279}
280280
281test "@fabs" {281test "@fabs" {
282 comptime testFabs();282 comptime try testFabs();
283 testFabs();283 try testFabs();
284}284}
285285
286fn testFabs() void {286fn testFabs() !void {
287 // TODO test f128, and c_longdouble287 // TODO test f128, and c_longdouble
288 // https://github.com/ziglang/zig/issues/4026288 // https://github.com/ziglang/zig/issues/4026
289 {289 {
290 var a: f16 = -2.5;290 var a: f16 = -2.5;
291 var b: f16 = 2.5;291 var b: f16 = 2.5;
292 expect(@fabs(a) == 2.5);292 try expect(@fabs(a) == 2.5);
293 expect(@fabs(b) == 2.5);293 try expect(@fabs(b) == 2.5);
294 }294 }
295 {295 {
296 var a: f32 = -2.5;296 var a: f32 = -2.5;
297 var b: f32 = 2.5;297 var b: f32 = 2.5;
298 expect(@fabs(a) == 2.5);298 try expect(@fabs(a) == 2.5);
299 expect(@fabs(b) == 2.5);299 try expect(@fabs(b) == 2.5);
300 }300 }
301 {301 {
302 var a: f64 = -2.5;302 var a: f64 = -2.5;
303 var b: f64 = 2.5;303 var b: f64 = 2.5;
304 expect(@fabs(a) == 2.5);304 try expect(@fabs(a) == 2.5);
305 expect(@fabs(b) == 2.5);305 try expect(@fabs(b) == 2.5);
306 }306 }
307 {307 {
308 var v: Vector(4, f32) = [_]f32{ 1.1, -2.2, 0.3, -0.4 };308 var v: Vector(4, f32) = [_]f32{ 1.1, -2.2, 0.3, -0.4 };
309 var result = @fabs(v);309 var result = @fabs(v);
310 expect(math.approxEqAbs(f32, @fabs(@as(f32, 1.1)), result[0], epsilon));310 try 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));311 try 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));312 try 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));313 try expect(math.approxEqAbs(f32, @fabs(@as(f32, -0.4)), result[3], epsilon));
314 }314 }
315}315}
316316
317test "@floor" {317test "@floor" {
318 comptime testFloor();318 comptime try testFloor();
319 testFloor();319 try testFloor();
320}320}
321321
322fn testFloor() void {322fn testFloor() !void {
323 // TODO test f128, and c_longdouble323 // TODO test f128, and c_longdouble
324 // https://github.com/ziglang/zig/issues/4026324 // https://github.com/ziglang/zig/issues/4026
325 {325 {
326 var a: f16 = 2.1;326 var a: f16 = 2.1;
327 expect(@floor(a) == 2);327 try expect(@floor(a) == 2);
328 }328 }
329 {329 {
330 var a: f32 = 2.1;330 var a: f32 = 2.1;
331 expect(@floor(a) == 2);331 try expect(@floor(a) == 2);
332 }332 }
333 {333 {
334 var a: f64 = 3.5;334 var a: f64 = 3.5;
335 expect(@floor(a) == 3);335 try expect(@floor(a) == 3);
336 }336 }
337 {337 {
338 var v: Vector(4, f32) = [_]f32{ 1.1, -2.2, 0.3, -0.4 };338 var v: Vector(4, f32) = [_]f32{ 1.1, -2.2, 0.3, -0.4 };
339 var result = @floor(v);339 var result = @floor(v);
340 expect(math.approxEqAbs(f32, @floor(@as(f32, 1.1)), result[0], epsilon));340 try 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));341 try 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));342 try 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));343 try expect(math.approxEqAbs(f32, @floor(@as(f32, -0.4)), result[3], epsilon));
344 }344 }
345}345}
346346
347test "@ceil" {347test "@ceil" {
348 comptime testCeil();348 comptime try testCeil();
349 testCeil();349 try testCeil();
350}350}
351351
352fn testCeil() void {352fn testCeil() !void {
353 // TODO test f128, and c_longdouble353 // TODO test f128, and c_longdouble
354 // https://github.com/ziglang/zig/issues/4026354 // https://github.com/ziglang/zig/issues/4026
355 {355 {
356 var a: f16 = 2.1;356 var a: f16 = 2.1;
357 expect(@ceil(a) == 3);357 try expect(@ceil(a) == 3);
358 }358 }
359 {359 {
360 var a: f32 = 2.1;360 var a: f32 = 2.1;
361 expect(@ceil(a) == 3);361 try expect(@ceil(a) == 3);
362 }362 }
363 {363 {
364 var a: f64 = 3.5;364 var a: f64 = 3.5;
365 expect(@ceil(a) == 4);365 try expect(@ceil(a) == 4);
366 }366 }
367 {367 {
368 var v: Vector(4, f32) = [_]f32{ 1.1, -2.2, 0.3, -0.4 };368 var v: Vector(4, f32) = [_]f32{ 1.1, -2.2, 0.3, -0.4 };
369 var result = @ceil(v);369 var result = @ceil(v);
370 expect(math.approxEqAbs(f32, @ceil(@as(f32, 1.1)), result[0], epsilon));370 try 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));371 try 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));372 try 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));373 try expect(math.approxEqAbs(f32, @ceil(@as(f32, -0.4)), result[3], epsilon));
374 }374 }
375}375}
376376
377test "@trunc" {377test "@trunc" {
378 comptime testTrunc();378 comptime try testTrunc();
379 testTrunc();379 try testTrunc();
380}380}
381381
382fn testTrunc() void {382fn testTrunc() !void {
383 // TODO test f128, and c_longdouble383 // TODO test f128, and c_longdouble
384 // https://github.com/ziglang/zig/issues/4026384 // https://github.com/ziglang/zig/issues/4026
385 {385 {
386 var a: f16 = 2.1;386 var a: f16 = 2.1;
387 expect(@trunc(a) == 2);387 try expect(@trunc(a) == 2);
388 }388 }
389 {389 {
390 var a: f32 = 2.1;390 var a: f32 = 2.1;
391 expect(@trunc(a) == 2);391 try expect(@trunc(a) == 2);
392 }392 }
393 {393 {
394 var a: f64 = -3.5;394 var a: f64 = -3.5;
395 expect(@trunc(a) == -3);395 try expect(@trunc(a) == -3);
396 }396 }
397 {397 {
398 var v: Vector(4, f32) = [_]f32{ 1.1, -2.2, 0.3, -0.4 };398 var v: Vector(4, f32) = [_]f32{ 1.1, -2.2, 0.3, -0.4 };
399 var result = @trunc(v);399 var result = @trunc(v);
400 expect(math.approxEqAbs(f32, @trunc(@as(f32, 1.1)), result[0], epsilon));400 try 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));401 try 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));402 try 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));403 try expect(math.approxEqAbs(f32, @trunc(@as(f32, -0.4)), result[3], epsilon));
404 }404 }
405}405}
406406
407test "floating point comparisons" {407test "floating point comparisons" {
408 testFloatComparisons();408 try testFloatComparisons();
409 comptime testFloatComparisons();409 comptime try testFloatComparisons();
410}410}
411411
412fn testFloatComparisons() void {412fn testFloatComparisons() !void {
413 inline for ([_]type{ f16, f32, f64, f128 }) |ty| {413 inline for ([_]type{ f16, f32, f64, f128 }) |ty| {
414 // No decimal part414 // No decimal part
415 {415 {
416 const x: ty = 1.0;416 const x: ty = 1.0;
417 expect(x == 1);417 try expect(x == 1);
418 expect(x != 0);418 try expect(x != 0);
419 expect(x > 0);419 try expect(x > 0);
420 expect(x < 2);420 try expect(x < 2);
421 expect(x >= 1);421 try expect(x >= 1);
422 expect(x <= 1);422 try expect(x <= 1);
423 }423 }
424 // Non-zero decimal part424 // Non-zero decimal part
425 {425 {
426 const x: ty = 1.5;426 const x: ty = 1.5;
427 expect(x != 1);427 try expect(x != 1);
428 expect(x != 2);428 try expect(x != 2);
429 expect(x > 1);429 try expect(x > 1);
430 expect(x < 2);430 try expect(x < 2);
431 expect(x >= 1);431 try expect(x >= 1);
432 expect(x <= 2);432 try expect(x <= 2);
433 }433 }
434 }434 }
435}435}
436436
437test "different sized float comparisons" {437test "different sized float comparisons" {
438 testDifferentSizedFloatComparisons();438 try testDifferentSizedFloatComparisons();
439 comptime testDifferentSizedFloatComparisons();439 comptime try testDifferentSizedFloatComparisons();
440}440}
441441
442fn testDifferentSizedFloatComparisons() void {442fn testDifferentSizedFloatComparisons() !void {
443 var a: f16 = 1;443 var a: f16 = 1;
444 var b: f64 = 2;444 var b: f64 = 2;
445 expect(a < b);445 try expect(a < b);
446}446}
447447
448// TODO This is waiting on library support for the Windows build (not sure why the other's don't need it)448// 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 {...@@ -456,10 +456,10 @@ fn testDifferentSizedFloatComparisons() void {
456// // https://github.com/ziglang/zig/issues/4026456// // https://github.com/ziglang/zig/issues/4026
457// {457// {
458// var a: f32 = 2.1;458// var a: f32 = 2.1;
459// expect(@nearbyint(a) == 2);459// try expect(@nearbyint(a) == 2);
460// }460// }
461// {461// {
462// var a: f64 = -3.75;462// var a: f64 = -3.75;
463// expect(@nearbyint(a) == -4);463// try expect(@nearbyint(a) == -4);
464// }464// }
465//}465//}
test/behavior/fn.zig+41-41
...@@ -5,7 +5,7 @@ const expect = testing.expect;...@@ -5,7 +5,7 @@ const expect = testing.expect;
5const expectEqual = testing.expectEqual;5const expectEqual = testing.expectEqual;
66
7test "params" {7test "params" {
8 expect(testParamsAdd(22, 11) == 33);8 try expect(testParamsAdd(22, 11) == 33);
9}9}
10fn testParamsAdd(a: i32, b: i32) i32 {10fn testParamsAdd(a: i32, b: i32) i32 {
11 return a + b;11 return a + b;
...@@ -20,37 +20,37 @@ fn testLocVars(b: i32) void {...@@ -20,37 +20,37 @@ fn testLocVars(b: i32) void {
20}20}
2121
22test "void parameters" {22test "void parameters" {
23 voidFun(1, void{}, 2, {});23 try voidFun(1, void{}, 2, {});
24}24}
25fn voidFun(a: i32, b: void, c: i32, d: void) void {25fn voidFun(a: i32, b: void, c: i32, d: void) !void {
26 const v = b;26 const v = b;
27 const vv: void = if (a == 1) v else {};27 const vv: void = if (a == 1) v else {};
28 expect(a + c == 3);28 try expect(a + c == 3);
29 return vv;29 return vv;
30}30}
3131
32test "mutable local variables" {32test "mutable local variables" {
33 var zero: i32 = 0;33 var zero: i32 = 0;
34 expect(zero == 0);34 try expect(zero == 0);
3535
36 var i = @as(i32, 0);36 var i = @as(i32, 0);
37 while (i != 3) {37 while (i != 3) {
38 i += 1;38 i += 1;
39 }39 }
40 expect(i == 3);40 try expect(i == 3);
41}41}
4242
43test "separate block scopes" {43test "separate block scopes" {
44 {44 {
45 const no_conflict: i32 = 5;45 const no_conflict: i32 = 5;
46 expect(no_conflict == 5);46 try expect(no_conflict == 5);
47 }47 }
4848
49 const c = x: {49 const c = x: {
50 const no_conflict = @as(i32, 10);50 const no_conflict = @as(i32, 10);
51 break :x no_conflict;51 break :x no_conflict;
52 };52 };
53 expect(c == 10);53 try expect(c == 10);
54}54}
5555
56test "call function with empty string" {56test "call function with empty string" {
...@@ -63,7 +63,7 @@ fn @"weird function name"() i32 {...@@ -63,7 +63,7 @@ fn @"weird function name"() i32 {
63 return 1234;63 return 1234;
64}64}
65test "weird function name" {65test "weird function name" {
66 expect(@"weird function name"() == 1234);66 try expect(@"weird function name"() == 1234);
67}67}
6868
69test "implicit cast function unreachable return" {69test "implicit cast function unreachable return" {
...@@ -84,7 +84,7 @@ test "function pointers" {...@@ -84,7 +84,7 @@ test "function pointers" {
84 fn4,84 fn4,
85 };85 };
86 for (fns) |f, i| {86 for (fns) |f, i| {
87 expect(f() == @intCast(u32, i) + 5);87 try expect(f() == @intCast(u32, i) + 5);
88 }88 }
89}89}
90fn fn1() u32 {90fn fn1() u32 {
...@@ -101,12 +101,12 @@ fn fn4() u32 {...@@ -101,12 +101,12 @@ fn fn4() u32 {
101}101}
102102
103test "number literal as an argument" {103test "number literal as an argument" {
104 numberLiteralArg(3);104 try numberLiteralArg(3);
105 comptime numberLiteralArg(3);105 comptime try numberLiteralArg(3);
106}106}
107107
108fn numberLiteralArg(a: anytype) void {108fn numberLiteralArg(a: anytype) !void {
109 expect(a == 3);109 try expect(a == 3);
110}110}
111111
112test "assign inline fn to const variable" {112test "assign inline fn to const variable" {
...@@ -117,7 +117,7 @@ test "assign inline fn to const variable" {...@@ -117,7 +117,7 @@ test "assign inline fn to const variable" {
117fn inlineFn() callconv(.Inline) void {}117fn inlineFn() callconv(.Inline) void {}
118118
119test "pass by non-copying value" {119test "pass by non-copying value" {
120 expect(addPointCoords(Point{ .x = 1, .y = 2 }) == 3);120 try expect(addPointCoords(Point{ .x = 1, .y = 2 }) == 3);
121}121}
122122
123const Point = struct {123const Point = struct {
...@@ -130,17 +130,17 @@ fn addPointCoords(pt: Point) i32 {...@@ -130,17 +130,17 @@ fn addPointCoords(pt: Point) i32 {
130}130}
131131
132test "pass by non-copying value through var arg" {132test "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);
134}134}
135135
136fn addPointCoordsVar(pt: anytype) i32 {136fn addPointCoordsVar(pt: anytype) !i32 {
137 comptime expect(@TypeOf(pt) == Point);137 comptime try expect(@TypeOf(pt) == Point);
138 return pt.x + pt.y;138 return pt.x + pt.y;
139}139}
140140
141test "pass by non-copying value as method" {141test "pass by non-copying value as method" {
142 var pt = Point2{ .x = 1, .y = 2 };142 var pt = Point2{ .x = 1, .y = 2 };
143 expect(pt.addPointCoords() == 3);143 try expect(pt.addPointCoords() == 3);
144}144}
145145
146const Point2 = struct {146const Point2 = struct {
...@@ -154,7 +154,7 @@ const Point2 = struct {...@@ -154,7 +154,7 @@ const Point2 = struct {
154154
155test "pass by non-copying value as method, which is generic" {155test "pass by non-copying value as method, which is generic" {
156 var pt = Point3{ .x = 1, .y = 2 };156 var pt = Point3{ .x = 1, .y = 2 };
157 expect(pt.addPointCoords(i32) == 3);157 try expect(pt.addPointCoords(i32) == 3);
158}158}
159159
160const Point3 = struct {160const Point3 = struct {
...@@ -169,7 +169,7 @@ const Point3 = struct {...@@ -169,7 +169,7 @@ const Point3 = struct {
169test "pass by non-copying value as method, at comptime" {169test "pass by non-copying value as method, at comptime" {
170 comptime {170 comptime {
171 var pt = Point2{ .x = 1, .y = 2 };171 var pt = Point2{ .x = 1, .y = 2 };
172 expect(pt.addPointCoords() == 3);172 try expect(pt.addPointCoords() == 3);
173 }173 }
174}174}
175175
...@@ -185,7 +185,7 @@ fn outer(y: u32) fn (u32) u32 {...@@ -185,7 +185,7 @@ fn outer(y: u32) fn (u32) u32 {
185185
186test "return inner function which references comptime variable of outer function" {186test "return inner function which references comptime variable of outer function" {
187 var func = outer(10);187 var func = outer(10);
188 expect(func(3) == 7);188 try expect(func(3) == 7);
189}189}
190190
191test "extern struct with stdcallcc fn pointer" {191test "extern struct with stdcallcc fn pointer" {
...@@ -199,16 +199,16 @@ test "extern struct with stdcallcc fn pointer" {...@@ -199,16 +199,16 @@ test "extern struct with stdcallcc fn pointer" {
199199
200 var s: S = undefined;200 var s: S = undefined;
201 s.ptr = S.foo;201 s.ptr = S.foo;
202 expect(s.ptr() == 1234);202 try expect(s.ptr() == 1234);
203}203}
204204
205test "implicit cast fn call result to optional in field result" {205test "implicit cast fn call result to optional in field result" {
206 const S = struct {206 const S = struct {
207 fn entry() void {207 fn entry() !void {
208 var x = Foo{208 var x = Foo{
209 .field = optionalPtr(),209 .field = optionalPtr(),
210 };210 };
211 expect(x.field.?.* == 999);211 try expect(x.field.?.* == 999);
212 }212 }
213213
214 const glob: i32 = 999;214 const glob: i32 = 999;
...@@ -221,8 +221,8 @@ test "implicit cast fn call result to optional in field result" {...@@ -221,8 +221,8 @@ test "implicit cast fn call result to optional in field result" {
221 field: ?*const i32,221 field: ?*const i32,
222 };222 };
223 };223 };
224 S.entry();224 try S.entry();
225 comptime S.entry();225 comptime try S.entry();
226}226}
227227
228test "discard the result of a function that returns a struct" {228test "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" {...@@ -246,26 +246,26 @@ test "discard the result of a function that returns a struct" {
246246
247test "function call with anon list literal" {247test "function call with anon list literal" {
248 const S = struct {248 const S = struct {
249 fn doTheTest() void {249 fn doTheTest() !void {
250 consumeVec(.{ 9, 8, 7 });250 try consumeVec(.{ 9, 8, 7 });
251 }251 }
252252
253 fn consumeVec(vec: [3]f32) void {253 fn consumeVec(vec: [3]f32) !void {
254 expect(vec[0] == 9);254 try expect(vec[0] == 9);
255 expect(vec[1] == 8);255 try expect(vec[1] == 8);
256 expect(vec[2] == 7);256 try expect(vec[2] == 7);
257 }257 }
258 };258 };
259 S.doTheTest();259 try S.doTheTest();
260 comptime S.doTheTest();260 comptime try S.doTheTest();
261}261}
262262
263test "ability to give comptime types and non comptime types to same parameter" {263test "ability to give comptime types and non comptime types to same parameter" {
264 const S = struct {264 const S = struct {
265 fn doTheTest() void {265 fn doTheTest() !void {
266 var x: i32 = 1;266 var x: i32 = 1;
267 expect(foo(x) == 10);267 try expect(foo(x) == 10);
268 expect(foo(i32) == 20);268 try expect(foo(i32) == 20);
269 }269 }
270270
271 fn foo(arg: anytype) i32 {271 fn foo(arg: anytype) i32 {
...@@ -273,8 +273,8 @@ test "ability to give comptime types and non comptime types to same parameter" {...@@ -273,8 +273,8 @@ test "ability to give comptime types and non comptime types to same parameter" {
273 return 9 + arg;273 return 9 + arg;
274 }274 }
275 };275 };
276 S.doTheTest();276 try S.doTheTest();
277 comptime S.doTheTest();277 comptime try S.doTheTest();
278}278}
279279
280test "function with inferred error set but returning no error" {280test "function with inferred error set but returning no error" {
...@@ -283,5 +283,5 @@ test "function with inferred error set but returning no error" {...@@ -283,5 +283,5 @@ test "function with inferred error set but returning no error" {
283 };283 };
284284
285 const return_ty = @typeInfo(@TypeOf(S.foo)).Fn.return_type.?;285 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);
287}287}
test/behavior/fn_delegation.zig+4-4
...@@ -32,8 +32,8 @@ fn custom(comptime T: type, comptime num: u64) fn (T) u64 {...@@ -32,8 +32,8 @@ fn custom(comptime T: type, comptime num: u64) fn (T) u64 {
3232
33test "fn delegation" {33test "fn delegation" {
34 const foo = Foo{};34 const foo = Foo{};
35 expect(foo.one() == 11);35 try expect(foo.one() == 11);
36 expect(foo.two() == 12);36 try expect(foo.two() == 12);
37 expect(foo.three() == 13);37 try expect(foo.three() == 13);
38 expect(foo.four() == 14);38 try expect(foo.four() == 14);
39}39}
test/behavior/fn_in_struct_in_comptime.zig+1-1
...@@ -13,5 +13,5 @@ fn get_foo() fn (*u8) usize {...@@ -13,5 +13,5 @@ fn get_foo() fn (*u8) usize {
1313
14test "define a function in an anonymous struct in comptime" {14test "define a function in an anonymous struct in comptime" {
15 const foo = get_foo();15 const foo = get_foo();
16 expect(foo(@intToPtr(*u8, 12345)) == 12345);16 try expect(foo(@intToPtr(*u8, 12345)) == 12345);
17}17}
test/behavior/for.zig+28-28
...@@ -27,12 +27,12 @@ test "for loop with pointer elem var" {...@@ -27,12 +27,12 @@ test "for loop with pointer elem var" {
27 var target: [source.len]u8 = undefined;27 var target: [source.len]u8 = undefined;
28 mem.copy(u8, target[0..], source);28 mem.copy(u8, target[0..], source);
29 mangleString(target[0..]);29 mangleString(target[0..]);
30 expect(mem.eql(u8, &target, "bcdefgh"));30 try expect(mem.eql(u8, &target, "bcdefgh"));
3131
32 for (source) |*c, i|32 for (source) |*c, i|
33 expect(@TypeOf(c) == *const u8);33 try expect(@TypeOf(c) == *const u8);
34 for (target) |*c, i|34 for (target) |*c, i|
35 expect(@TypeOf(c) == *u8);35 try expect(@TypeOf(c) == *u8);
36}36}
3737
38fn mangleString(s: []u8) void {38fn mangleString(s: []u8) void {
...@@ -75,15 +75,15 @@ test "basic for loop" {...@@ -75,15 +75,15 @@ test "basic for loop" {
75 buf_index += 1;75 buf_index += 1;
76 }76 }
7777
78 expect(mem.eql(u8, buffer[0..buf_index], &expected_result));78 try expect(mem.eql(u8, buffer[0..buf_index], &expected_result));
79}79}
8080
81test "break from outer for loop" {81test "break from outer for loop" {
82 testBreakOuter();82 try testBreakOuter();
83 comptime testBreakOuter();83 comptime try testBreakOuter();
84}84}
8585
86fn testBreakOuter() void {86fn testBreakOuter() !void {
87 var array = "aoeu";87 var array = "aoeu";
88 var count: usize = 0;88 var count: usize = 0;
89 outer: for (array) |_| {89 outer: for (array) |_| {
...@@ -92,15 +92,15 @@ fn testBreakOuter() void {...@@ -92,15 +92,15 @@ fn testBreakOuter() void {
92 break :outer;92 break :outer;
93 }93 }
94 }94 }
95 expect(count == 1);95 try expect(count == 1);
96}96}
9797
98test "continue outer for loop" {98test "continue outer for loop" {
99 testContinueOuter();99 try testContinueOuter();
100 comptime testContinueOuter();100 comptime try testContinueOuter();
101}101}
102102
103fn testContinueOuter() void {103fn testContinueOuter() !void {
104 var array = "aoeu";104 var array = "aoeu";
105 var counter: usize = 0;105 var counter: usize = 0;
106 outer: for (array) |_| {106 outer: for (array) |_| {
...@@ -109,28 +109,28 @@ fn testContinueOuter() void {...@@ -109,28 +109,28 @@ fn testContinueOuter() void {
109 continue :outer;109 continue :outer;
110 }110 }
111 }111 }
112 expect(counter == array.len);112 try expect(counter == array.len);
113}113}
114114
115test "2 break statements and an else" {115test "2 break statements and an else" {
116 const S = struct {116 const S = struct {
117 fn entry(t: bool, f: bool) void {117 fn entry(t: bool, f: bool) !void {
118 var buf: [10]u8 = undefined;118 var buf: [10]u8 = undefined;
119 var ok = false;119 var ok = false;
120 ok = for (buf) |item| {120 ok = for (buf) |item| {
121 if (f) break false;121 if (f) break false;
122 if (t) break true;122 if (t) break true;
123 } else false;123 } else false;
124 expect(ok);124 try expect(ok);
125 }125 }
126 };126 };
127 S.entry(true, false);127 try S.entry(true, false);
128 comptime S.entry(true, false);128 comptime try S.entry(true, false);
129}129}
130130
131test "for with null and T peer types and inferred result location type" {131test "for with null and T peer types and inferred result location type" {
132 const S = struct {132 const S = struct {
133 fn doTheTest(slice: []const u8) void {133 fn doTheTest(slice: []const u8) !void {
134 if (for (slice) |item| {134 if (for (slice) |item| {
135 if (item == 10) {135 if (item == 10) {
136 break item;136 break item;
...@@ -140,33 +140,33 @@ test "for with null and T peer types and inferred result location type" {...@@ -140,33 +140,33 @@ test "for with null and T peer types and inferred result location type" {
140 }140 }
141 }141 }
142 };142 };
143 S.doTheTest(&[_]u8{ 1, 2 });143 try S.doTheTest(&[_]u8{ 1, 2 });
144 comptime S.doTheTest(&[_]u8{ 1, 2 });144 comptime try S.doTheTest(&[_]u8{ 1, 2 });
145}145}
146146
147test "for copies its payload" {147test "for copies its payload" {
148 const S = struct {148 const S = struct {
149 fn doTheTest() void {149 fn doTheTest() !void {
150 var x = [_]usize{ 1, 2, 3 };150 var x = [_]usize{ 1, 2, 3 };
151 for (x) |value, i| {151 for (x) |value, i| {
152 // Modify the original array152 // Modify the original array
153 x[i] += 99;153 x[i] += 99;
154 expectEqual(value, i + 1);154 try expectEqual(value, i + 1);
155 }155 }
156 }156 }
157 };157 };
158 S.doTheTest();158 try S.doTheTest();
159 comptime S.doTheTest();159 comptime try S.doTheTest();
160}160}
161161
162test "for on slice with allowzero ptr" {162test "for on slice with allowzero ptr" {
163 const S = struct {163 const S = struct {
164 fn doTheTest(slice: []const u8) void {164 fn doTheTest(slice: []const u8) !void {
165 var ptr = @ptrCast([*]allowzero const u8, slice.ptr)[0..slice.len];165 var ptr = @ptrCast([*]allowzero const u8, slice.ptr)[0..slice.len];
166 for (ptr) |x, i| expect(x == i + 1);166 for (ptr) |x, i| try expect(x == i + 1);
167 for (ptr) |*x, i| expect(x.* == i + 1);167 for (ptr) |*x, i| try expect(x.* == i + 1);
168 }168 }
169 };169 };
170 S.doTheTest(&[_]u8{ 1, 2, 3, 4 });170 try S.doTheTest(&[_]u8{ 1, 2, 3, 4 });
171 comptime S.doTheTest(&[_]u8{ 1, 2, 3, 4 });171 comptime try S.doTheTest(&[_]u8{ 1, 2, 3, 4 });
172}172}
test/behavior/generics.zig+25-25
...@@ -4,9 +4,9 @@ const expect = testing.expect;...@@ -4,9 +4,9 @@ const expect = testing.expect;
4const expectEqual = testing.expectEqual;4const expectEqual = testing.expectEqual;
55
6test "simple generic fn" {6test "simple generic fn" {
7 expect(max(i32, 3, -1) == 3);7 try expect(max(i32, 3, -1) == 3);
8 expect(max(f32, 0.123, 0.456) == 0.456);8 try expect(max(f32, 0.123, 0.456) == 0.456);
9 expect(add(2, 3) == 5);9 try expect(add(2, 3) == 5);
10}10}
1111
12fn max(comptime T: type, a: T, b: T) T {12fn max(comptime T: type, a: T, b: T) T {
...@@ -19,7 +19,7 @@ fn add(comptime a: i32, b: i32) i32 {...@@ -19,7 +19,7 @@ fn add(comptime a: i32, b: i32) i32 {
1919
20const the_max = max(u32, 1234, 5678);20const the_max = max(u32, 1234, 5678);
21test "compile time generic eval" {21test "compile time generic eval" {
22 expect(the_max == 5678);22 try expect(the_max == 5678);
23}23}
2424
25fn gimmeTheBigOne(a: u32, b: u32) u32 {25fn gimmeTheBigOne(a: u32, b: u32) u32 {
...@@ -35,19 +35,19 @@ fn sameButWithFloats(a: f64, b: f64) f64 {...@@ -35,19 +35,19 @@ fn sameButWithFloats(a: f64, b: f64) f64 {
35}35}
3636
37test "fn with comptime args" {37test "fn with comptime args" {
38 expect(gimmeTheBigOne(1234, 5678) == 5678);38 try expect(gimmeTheBigOne(1234, 5678) == 5678);
39 expect(shouldCallSameInstance(34, 12) == 34);39 try expect(shouldCallSameInstance(34, 12) == 34);
40 expect(sameButWithFloats(0.43, 0.49) == 0.49);40 try expect(sameButWithFloats(0.43, 0.49) == 0.49);
41}41}
4242
43test "var params" {43test "var params" {
44 expect(max_i32(12, 34) == 34);44 try expect(max_i32(12, 34) == 34);
45 expect(max_f64(1.2, 3.4) == 3.4);45 try expect(max_f64(1.2, 3.4) == 3.4);
46}46}
4747
48comptime {48comptime {
49 expect(max_i32(12, 34) == 34);49 try expect(max_i32(12, 34) == 34);
50 expect(max_f64(1.2, 3.4) == 3.4);50 try expect(max_f64(1.2, 3.4) == 3.4);
51}51}
5252
53fn max_var(a: anytype, b: anytype) @TypeOf(a + b) {53fn max_var(a: anytype, b: anytype) @TypeOf(a + b) {
...@@ -79,8 +79,8 @@ test "function with return type type" {...@@ -79,8 +79,8 @@ test "function with return type type" {
79 var list2: List(i32) = undefined;79 var list2: List(i32) = undefined;
80 list.length = 10;80 list.length = 10;
81 list2.length = 10;81 list2.length = 10;
82 expect(list.prealloc_items.len == 8);82 try expect(list.prealloc_items.len == 8);
83 expect(list2.prealloc_items.len == 8);83 try expect(list2.prealloc_items.len == 8);
84}84}
8585
86test "generic struct" {86test "generic struct" {
...@@ -92,9 +92,9 @@ test "generic struct" {...@@ -92,9 +92,9 @@ test "generic struct" {
92 .value = true,92 .value = true,
93 .next = null,93 .next = null,
94 };94 };
95 expect(a1.value == 13);95 try expect(a1.value == 13);
96 expect(a1.value == a1.getVal());96 try expect(a1.value == a1.getVal());
97 expect(b1.getVal());97 try expect(b1.getVal());
98}98}
99fn GenNode(comptime T: type) type {99fn GenNode(comptime T: type) type {
100 return struct {100 return struct {
...@@ -107,7 +107,7 @@ fn GenNode(comptime T: type) type {...@@ -107,7 +107,7 @@ fn GenNode(comptime T: type) type {
107}107}
108108
109test "const decls in struct" {109test "const decls in struct" {
110 expect(GenericDataThing(3).count_plus_one == 4);110 try expect(GenericDataThing(3).count_plus_one == 4);
111}111}
112fn GenericDataThing(comptime count: isize) type {112fn GenericDataThing(comptime count: isize) type {
113 return struct {113 return struct {
...@@ -116,15 +116,15 @@ fn GenericDataThing(comptime count: isize) type {...@@ -116,15 +116,15 @@ fn GenericDataThing(comptime count: isize) type {
116}116}
117117
118test "use generic param in generic param" {118test "use generic param in generic param" {
119 expect(aGenericFn(i32, 3, 4) == 7);119 try expect(aGenericFn(i32, 3, 4) == 7);
120}120}
121fn aGenericFn(comptime T: type, comptime a: T, b: T) T {121fn aGenericFn(comptime T: type, comptime a: T, b: T) T {
122 return a + b;122 return a + b;
123}123}
124124
125test "generic fn with implicit cast" {125test "generic fn with implicit cast" {
126 expect(getFirstByte(u8, &[_]u8{13}) == 13);126 try expect(getFirstByte(u8, &[_]u8{13}) == 13);
127 expect(getFirstByte(u16, &[_]u16{127 try expect(getFirstByte(u16, &[_]u16{
128 0,128 0,
129 13,129 13,
130 }) == 0);130 }) == 0);
...@@ -149,21 +149,21 @@ fn foo2(arg: anytype) bool {...@@ -149,21 +149,21 @@ fn foo2(arg: anytype) bool {
149}149}
150150
151test "array of generic fns" {151test "array of generic fns" {
152 expect(foos[0](true));152 try expect(foos[0](true));
153 expect(!foos[1](true));153 try expect(!foos[1](true));
154}154}
155155
156test "generic fn keeps non-generic parameter types" {156test "generic fn keeps non-generic parameter types" {
157 const A = 128;157 const A = 128;
158158
159 const S = struct {159 const S = struct {
160 fn f(comptime T: type, s: []T) void {160 fn f(comptime T: type, s: []T) !void {
161 expect(A != @typeInfo(@TypeOf(s)).Pointer.alignment);161 try expect(A != @typeInfo(@TypeOf(s)).Pointer.alignment);
162 }162 }
163 };163 };
164164
165 // The compiler monomorphizes `S.f` for `T=u8` on its first use, check that165 // The compiler monomorphizes `S.f` for `T=u8` on its first use, check that
166 // `x` type not affect `s` parameter type.166 // `x` type not affect `s` parameter type.
167 var x: [16]u8 align(A) = undefined;167 var x: [16]u8 align(A) = undefined;
168 S.f(u8, &x);168 try S.f(u8, &x);
169}169}
test/behavior/hasdecl.zig+6-6
...@@ -11,11 +11,11 @@ const Bar = struct {...@@ -11,11 +11,11 @@ const Bar = struct {
11};11};
1212
13test "@hasDecl" {13test "@hasDecl" {
14 expect(@hasDecl(Foo, "public_thing"));14 try expect(@hasDecl(Foo, "public_thing"));
15 expect(!@hasDecl(Foo, "private_thing"));15 try expect(!@hasDecl(Foo, "private_thing"));
16 expect(!@hasDecl(Foo, "no_thing"));16 try expect(!@hasDecl(Foo, "no_thing"));
1717
18 expect(@hasDecl(Bar, "hi"));18 try expect(@hasDecl(Bar, "hi"));
19 expect(@hasDecl(Bar, "blah"));19 try expect(@hasDecl(Bar, "blah"));
20 expect(!@hasDecl(Bar, "nope"));20 try expect(!@hasDecl(Bar, "nope"));
21}21}
test/behavior/hasfield.zig+12-12
...@@ -8,10 +8,10 @@ test "@hasField" {...@@ -8,10 +8,10 @@ test "@hasField" {
88
9 pub const nope = 1;9 pub const nope = 1;
10 };10 };
11 expect(@hasField(struc, "a") == true);11 try expect(@hasField(struc, "a") == true);
12 expect(@hasField(struc, "b") == true);12 try expect(@hasField(struc, "b") == true);
13 expect(@hasField(struc, "non-existant") == false);13 try expect(@hasField(struc, "non-existant") == false);
14 expect(@hasField(struc, "nope") == false);14 try expect(@hasField(struc, "nope") == false);
1515
16 const unin = union {16 const unin = union {
17 a: u64,17 a: u64,
...@@ -19,10 +19,10 @@ test "@hasField" {...@@ -19,10 +19,10 @@ test "@hasField" {
1919
20 pub const nope = 1;20 pub const nope = 1;
21 };21 };
22 expect(@hasField(unin, "a") == true);22 try expect(@hasField(unin, "a") == true);
23 expect(@hasField(unin, "b") == true);23 try expect(@hasField(unin, "b") == true);
24 expect(@hasField(unin, "non-existant") == false);24 try expect(@hasField(unin, "non-existant") == false);
25 expect(@hasField(unin, "nope") == false);25 try expect(@hasField(unin, "nope") == false);
2626
27 const enm = enum {27 const enm = enum {
28 a,28 a,
...@@ -30,8 +30,8 @@ test "@hasField" {...@@ -30,8 +30,8 @@ test "@hasField" {
3030
31 pub const nope = 1;31 pub const nope = 1;
32 };32 };
33 expect(@hasField(enm, "a") == true);33 try expect(@hasField(enm, "a") == true);
34 expect(@hasField(enm, "b") == true);34 try expect(@hasField(enm, "b") == true);
35 expect(@hasField(enm, "non-existant") == false);35 try expect(@hasField(enm, "non-existant") == false);
36 expect(@hasField(enm, "nope") == false);36 try expect(@hasField(enm, "nope") == false);
37}37}
test/behavior/if.zig+14-14
...@@ -26,7 +26,7 @@ fn firstEqlThird(a: i32, b: i32, c: i32) void {...@@ -26,7 +26,7 @@ fn firstEqlThird(a: i32, b: i32, c: i32) void {
26}26}
2727
28test "else if expression" {28test "else if expression" {
29 expect(elseIfExpressionF(1) == 1);29 try expect(elseIfExpressionF(1) == 1);
30}30}
31fn elseIfExpressionF(c: u8) u8 {31fn elseIfExpressionF(c: u8) u8 {
32 if (c == 0) {32 if (c == 0) {
...@@ -44,14 +44,14 @@ var global_with_err: anyerror!u32 = error.SomeError;...@@ -44,14 +44,14 @@ var global_with_err: anyerror!u32 = error.SomeError;
4444
45test "unwrap mutable global var" {45test "unwrap mutable global var" {
46 if (global_with_val) |v| {46 if (global_with_val) |v| {
47 expect(v == 0);47 try expect(v == 0);
48 } else |e| {48 } else |e| {
49 unreachable;49 unreachable;
50 }50 }
51 if (global_with_err) |_| {51 if (global_with_err) |_| {
52 unreachable;52 unreachable;
53 } else |e| {53 } else |e| {
54 expect(e == error.SomeError);54 try expect(e == error.SomeError);
55 }55 }
56}56}
5757
...@@ -63,7 +63,7 @@ test "labeled break inside comptime if inside runtime if" {...@@ -63,7 +63,7 @@ test "labeled break inside comptime if inside runtime if" {
63 break :blk @as(i32, 42);63 break :blk @as(i32, 42);
64 };64 };
65 }65 }
66 expect(answer == 42);66 try expect(answer == 42);
67}67}
6868
69test "const result loc, runtime if cond, else unreachable" {69test "const result loc, runtime if cond, else unreachable" {
...@@ -74,36 +74,36 @@ test "const result loc, runtime if cond, else unreachable" {...@@ -74,36 +74,36 @@ test "const result loc, runtime if cond, else unreachable" {
7474
75 var t = true;75 var t = true;
76 const x = if (t) Num.Two else unreachable;76 const x = if (t) Num.Two else unreachable;
77 expect(x == .Two);77 try expect(x == .Two);
78}78}
7979
80test "if prongs cast to expected type instead of peer type resolution" {80test "if prongs cast to expected type instead of peer type resolution" {
81 const S = struct {81 const S = struct {
82 fn doTheTest(f: bool) void {82 fn doTheTest(f: bool) !void {
83 var x: i32 = 0;83 var x: i32 = 0;
84 x = if (f) 1 else 2;84 x = if (f) 1 else 2;
85 expect(x == 2);85 try expect(x == 2);
8686
87 var b = true;87 var b = true;
88 const y: i32 = if (b) 1 else 2;88 const y: i32 = if (b) 1 else 2;
89 expect(y == 1);89 try expect(y == 1);
90 }90 }
91 };91 };
92 S.doTheTest(false);92 try S.doTheTest(false);
93 comptime S.doTheTest(false);93 comptime try S.doTheTest(false);
94}94}
9595
96test "while copies its payload" {96test "while copies its payload" {
97 const S = struct {97 const S = struct {
98 fn doTheTest() void {98 fn doTheTest() !void {
99 var tmp: ?i32 = 10;99 var tmp: ?i32 = 10;
100 if (tmp) |value| {100 if (tmp) |value| {
101 // Modify the original variable101 // Modify the original variable
102 tmp = null;102 tmp = null;
103 expectEqual(@as(i32, 10), value);103 try expectEqual(@as(i32, 10), value);
104 } else unreachable;104 } else unreachable;
105 }105 }
106 };106 };
107 S.doTheTest();107 try S.doTheTest();
108 comptime S.doTheTest();108 comptime try S.doTheTest();
109}109}
test/behavior/import.zig+3-3
...@@ -3,18 +3,18 @@ const expectEqual = @import("std").testing.expectEqual;...@@ -3,18 +3,18 @@ const expectEqual = @import("std").testing.expectEqual;
3const a_namespace = @import("import/a_namespace.zig");3const a_namespace = @import("import/a_namespace.zig");
44
5test "call fn via namespace lookup" {5test "call fn via namespace lookup" {
6 expectEqual(@as(i32, 1234), a_namespace.foo());6 try expectEqual(@as(i32, 1234), a_namespace.foo());
7}7}
88
9test "importing the same thing gives the same import" {9test "importing the same thing gives the same import" {
10 expect(@import("std") == @import("std"));10 try expect(@import("std") == @import("std"));
11}11}
1212
13test "import in non-toplevel scope" {13test "import in non-toplevel scope" {
14 const S = struct {14 const S = struct {
15 usingnamespace @import("import/a_namespace.zig");15 usingnamespace @import("import/a_namespace.zig");
16 };16 };
17 expectEqual(@as(i32, 1234), S.foo());17 try expectEqual(@as(i32, 1234), S.foo());
18}18}
1919
20test "import empty file" {20test "import empty file" {
test/behavior/incomplete_struct_param_tld.zig+1-1
...@@ -26,5 +26,5 @@ test "incomplete struct param top level declaration" {...@@ -26,5 +26,5 @@ test "incomplete struct param top level declaration" {
26 .c = C{ .x = 13 },26 .c = C{ .x = 13 },
27 },27 },
28 };28 };
29 expect(foo(a) == 13);29 try expect(foo(a) == 13);
30}30}
test/behavior/inttoptr.zig-4
...@@ -1,7 +1,3 @@...@@ -1,7 +1,3 @@
1const builtin = @import("builtin");
2const std = @import("std");
3const expect = std.testing.expect;
4
5test "casting random address to function pointer" {1test "casting random address to function pointer" {
6 randomAddressToFunction();2 randomAddressToFunction();
7 comptime randomAddressToFunction();3 comptime randomAddressToFunction();
test/behavior/ir_block_deps.zig+2-2
...@@ -16,6 +16,6 @@ fn getErrInt() anyerror!i32 {...@@ -16,6 +16,6 @@ fn getErrInt() anyerror!i32 {
16}16}
1717
18test "ir block deps" {18test "ir block deps" {
19 expect((foo(1) catch unreachable) == 0);19 try expect((foo(1) catch unreachable) == 0);
20 expect((foo(2) catch unreachable) == 0);20 try expect((foo(2) catch unreachable) == 0);
21}21}
test/behavior/math.zig+357-357
...@@ -7,71 +7,71 @@ const minInt = std.math.minInt;...@@ -7,71 +7,71 @@ const minInt = std.math.minInt;
7const mem = std.mem;7const mem = std.mem;
88
9test "division" {9test "division" {
10 testDivision();10 try testDivision();
11 comptime testDivision();11 comptime try testDivision();
12}12}
13fn testDivision() void {13fn testDivision() !void {
14 expect(div(u32, 13, 3) == 4);14 try expect(div(u32, 13, 3) == 4);
15 expect(div(f16, 1.0, 2.0) == 0.5);15 try expect(div(f16, 1.0, 2.0) == 0.5);
16 expect(div(f32, 1.0, 2.0) == 0.5);16 try expect(div(f32, 1.0, 2.0) == 0.5);
1717
18 expect(divExact(u32, 55, 11) == 5);18 try expect(divExact(u32, 55, 11) == 5);
19 expect(divExact(i32, -55, 11) == -5);19 try expect(divExact(i32, -55, 11) == -5);
20 expect(divExact(f16, 55.0, 11.0) == 5.0);20 try expect(divExact(f16, 55.0, 11.0) == 5.0);
21 expect(divExact(f16, -55.0, 11.0) == -5.0);21 try expect(divExact(f16, -55.0, 11.0) == -5.0);
22 expect(divExact(f32, 55.0, 11.0) == 5.0);22 try expect(divExact(f32, 55.0, 11.0) == 5.0);
23 expect(divExact(f32, -55.0, 11.0) == -5.0);23 try expect(divExact(f32, -55.0, 11.0) == -5.0);
2424
25 expect(divFloor(i32, 5, 3) == 1);25 try expect(divFloor(i32, 5, 3) == 1);
26 expect(divFloor(i32, -5, 3) == -2);26 try expect(divFloor(i32, -5, 3) == -2);
27 expect(divFloor(f16, 5.0, 3.0) == 1.0);27 try expect(divFloor(f16, 5.0, 3.0) == 1.0);
28 expect(divFloor(f16, -5.0, 3.0) == -2.0);28 try expect(divFloor(f16, -5.0, 3.0) == -2.0);
29 expect(divFloor(f32, 5.0, 3.0) == 1.0);29 try expect(divFloor(f32, 5.0, 3.0) == 1.0);
30 expect(divFloor(f32, -5.0, 3.0) == -2.0);30 try expect(divFloor(f32, -5.0, 3.0) == -2.0);
31 expect(divFloor(i32, -0x80000000, -2) == 0x40000000);31 try expect(divFloor(i32, -0x80000000, -2) == 0x40000000);
32 expect(divFloor(i32, 0, -0x80000000) == 0);32 try expect(divFloor(i32, 0, -0x80000000) == 0);
33 expect(divFloor(i32, -0x40000001, 0x40000000) == -2);33 try expect(divFloor(i32, -0x40000001, 0x40000000) == -2);
34 expect(divFloor(i32, -0x80000000, 1) == -0x80000000);34 try expect(divFloor(i32, -0x80000000, 1) == -0x80000000);
35 expect(divFloor(i32, 10, 12) == 0);35 try expect(divFloor(i32, 10, 12) == 0);
36 expect(divFloor(i32, -14, 12) == -2);36 try expect(divFloor(i32, -14, 12) == -2);
37 expect(divFloor(i32, -2, 12) == -1);37 try expect(divFloor(i32, -2, 12) == -1);
3838
39 expect(divTrunc(i32, 5, 3) == 1);39 try expect(divTrunc(i32, 5, 3) == 1);
40 expect(divTrunc(i32, -5, 3) == -1);40 try expect(divTrunc(i32, -5, 3) == -1);
41 expect(divTrunc(f16, 5.0, 3.0) == 1.0);41 try expect(divTrunc(f16, 5.0, 3.0) == 1.0);
42 expect(divTrunc(f16, -5.0, 3.0) == -1.0);42 try expect(divTrunc(f16, -5.0, 3.0) == -1.0);
43 expect(divTrunc(f32, 5.0, 3.0) == 1.0);43 try expect(divTrunc(f32, 5.0, 3.0) == 1.0);
44 expect(divTrunc(f32, -5.0, 3.0) == -1.0);44 try expect(divTrunc(f32, -5.0, 3.0) == -1.0);
45 expect(divTrunc(f64, 5.0, 3.0) == 1.0);45 try expect(divTrunc(f64, 5.0, 3.0) == 1.0);
46 expect(divTrunc(f64, -5.0, 3.0) == -1.0);46 try expect(divTrunc(f64, -5.0, 3.0) == -1.0);
47 expect(divTrunc(i32, 10, 12) == 0);47 try expect(divTrunc(i32, 10, 12) == 0);
48 expect(divTrunc(i32, -14, 12) == -1);48 try expect(divTrunc(i32, -14, 12) == -1);
49 expect(divTrunc(i32, -2, 12) == 0);49 try expect(divTrunc(i32, -2, 12) == 0);
5050
51 expect(mod(i32, 10, 12) == 10);51 try expect(mod(i32, 10, 12) == 10);
52 expect(mod(i32, -14, 12) == 10);52 try expect(mod(i32, -14, 12) == 10);
53 expect(mod(i32, -2, 12) == 10);53 try expect(mod(i32, -2, 12) == 10);
5454
55 comptime {55 comptime {
56 expect(56 try expect(
57 1194735857077236777412821811143690633098347576 % 508740759824825164163191790951174292733114988 == 177254337427586449086438229241342047632117600,57 1194735857077236777412821811143690633098347576 % 508740759824825164163191790951174292733114988 == 177254337427586449086438229241342047632117600,
58 );58 );
59 expect(59 try expect(
60 @rem(-1194735857077236777412821811143690633098347576, 508740759824825164163191790951174292733114988) == -177254337427586449086438229241342047632117600,60 @rem(-1194735857077236777412821811143690633098347576, 508740759824825164163191790951174292733114988) == -177254337427586449086438229241342047632117600,
61 );61 );
62 expect(62 try expect(
63 1194735857077236777412821811143690633098347576 / 508740759824825164163191790951174292733114988 == 2,63 1194735857077236777412821811143690633098347576 / 508740759824825164163191790951174292733114988 == 2,
64 );64 );
65 expect(65 try expect(
66 @divTrunc(-1194735857077236777412821811143690633098347576, 508740759824825164163191790951174292733114988) == -2,66 @divTrunc(-1194735857077236777412821811143690633098347576, 508740759824825164163191790951174292733114988) == -2,
67 );67 );
68 expect(68 try expect(
69 @divTrunc(1194735857077236777412821811143690633098347576, -508740759824825164163191790951174292733114988) == -2,69 @divTrunc(1194735857077236777412821811143690633098347576, -508740759824825164163191790951174292733114988) == -2,
70 );70 );
71 expect(71 try expect(
72 @divTrunc(-1194735857077236777412821811143690633098347576, -508740759824825164163191790951174292733114988) == 2,72 @divTrunc(-1194735857077236777412821811143690633098347576, -508740759824825164163191790951174292733114988) == 2,
73 );73 );
74 expect(74 try expect(
75 4126227191251978491697987544882340798050766755606969681711 % 10 == 1,75 4126227191251978491697987544882340798050766755606969681711 % 10 == 1,
76 );76 );
77 }77 }
...@@ -94,9 +94,9 @@ fn mod(comptime T: type, a: T, b: T) T {...@@ -94,9 +94,9 @@ fn mod(comptime T: type, a: T, b: T) T {
9494
95test "@addWithOverflow" {95test "@addWithOverflow" {
96 var result: u8 = undefined;96 var result: u8 = undefined;
97 expect(@addWithOverflow(u8, 250, 100, &result));97 try expect(@addWithOverflow(u8, 250, 100, &result));
98 expect(!@addWithOverflow(u8, 100, 150, &result));98 try expect(!@addWithOverflow(u8, 100, 150, &result));
99 expect(result == 250);99 try expect(result == 250);
100}100}
101101
102// TODO test mulWithOverflow102// TODO test mulWithOverflow
...@@ -104,31 +104,31 @@ test "@addWithOverflow" {...@@ -104,31 +104,31 @@ test "@addWithOverflow" {
104104
105test "@shlWithOverflow" {105test "@shlWithOverflow" {
106 var result: u16 = undefined;106 var result: u16 = undefined;
107 expect(@shlWithOverflow(u16, 0b0010111111111111, 3, &result));107 try expect(@shlWithOverflow(u16, 0b0010111111111111, 3, &result));
108 expect(!@shlWithOverflow(u16, 0b0010111111111111, 2, &result));108 try expect(!@shlWithOverflow(u16, 0b0010111111111111, 2, &result));
109 expect(result == 0b1011111111111100);109 try expect(result == 0b1011111111111100);
110}110}
111111
112test "@*WithOverflow with u0 values" {112test "@*WithOverflow with u0 values" {
113 var result: u0 = undefined;113 var result: u0 = undefined;
114 expect(!@addWithOverflow(u0, 0, 0, &result));114 try expect(!@addWithOverflow(u0, 0, 0, &result));
115 expect(!@subWithOverflow(u0, 0, 0, &result));115 try expect(!@subWithOverflow(u0, 0, 0, &result));
116 expect(!@mulWithOverflow(u0, 0, 0, &result));116 try expect(!@mulWithOverflow(u0, 0, 0, &result));
117 expect(!@shlWithOverflow(u0, 0, 0, &result));117 try expect(!@shlWithOverflow(u0, 0, 0, &result));
118}118}
119119
120test "@clz" {120test "@clz" {
121 testClz();121 try testClz();
122 comptime testClz();122 comptime try testClz();
123}123}
124124
125fn testClz() void {125fn testClz() !void {
126 expect(clz(u8, 0b10001010) == 0);126 try expect(clz(u8, 0b10001010) == 0);
127 expect(clz(u8, 0b00001010) == 4);127 try expect(clz(u8, 0b00001010) == 4);
128 expect(clz(u8, 0b00011010) == 3);128 try expect(clz(u8, 0b00011010) == 3);
129 expect(clz(u8, 0b00000000) == 8);129 try expect(clz(u8, 0b00000000) == 8);
130 expect(clz(u128, 0xffffffffffffffff) == 64);130 try expect(clz(u128, 0xffffffffffffffff) == 64);
131 expect(clz(u128, 0x10000000000000000) == 63);131 try expect(clz(u128, 0x10000000000000000) == 63);
132}132}
133133
134fn clz(comptime T: type, x: T) usize {134fn clz(comptime T: type, x: T) usize {
...@@ -136,15 +136,15 @@ fn clz(comptime T: type, x: T) usize {...@@ -136,15 +136,15 @@ fn clz(comptime T: type, x: T) usize {
136}136}
137137
138test "@ctz" {138test "@ctz" {
139 testCtz();139 try testCtz();
140 comptime testCtz();140 comptime try testCtz();
141}141}
142142
143fn testCtz() void {143fn testCtz() !void {
144 expect(ctz(u8, 0b10100000) == 5);144 try expect(ctz(u8, 0b10100000) == 5);
145 expect(ctz(u8, 0b10001010) == 1);145 try expect(ctz(u8, 0b10001010) == 1);
146 expect(ctz(u8, 0b00000000) == 8);146 try expect(ctz(u8, 0b00000000) == 8);
147 expect(ctz(u16, 0b00000000) == 16);147 try expect(ctz(u16, 0b00000000) == 16);
148}148}
149149
150fn ctz(comptime T: type, x: T) usize {150fn ctz(comptime T: type, x: T) usize {
...@@ -154,109 +154,109 @@ fn ctz(comptime T: type, x: T) usize {...@@ -154,109 +154,109 @@ fn ctz(comptime T: type, x: T) usize {
154test "assignment operators" {154test "assignment operators" {
155 var i: u32 = 0;155 var i: u32 = 0;
156 i += 5;156 i += 5;
157 expect(i == 5);157 try expect(i == 5);
158 i -= 2;158 i -= 2;
159 expect(i == 3);159 try expect(i == 3);
160 i *= 20;160 i *= 20;
161 expect(i == 60);161 try expect(i == 60);
162 i /= 3;162 i /= 3;
163 expect(i == 20);163 try expect(i == 20);
164 i %= 11;164 i %= 11;
165 expect(i == 9);165 try expect(i == 9);
166 i <<= 1;166 i <<= 1;
167 expect(i == 18);167 try expect(i == 18);
168 i >>= 2;168 i >>= 2;
169 expect(i == 4);169 try expect(i == 4);
170 i = 6;170 i = 6;
171 i &= 5;171 i &= 5;
172 expect(i == 4);172 try expect(i == 4);
173 i ^= 6;173 i ^= 6;
174 expect(i == 2);174 try expect(i == 2);
175 i = 6;175 i = 6;
176 i |= 3;176 i |= 3;
177 expect(i == 7);177 try expect(i == 7);
178}178}
179179
180test "three expr in a row" {180test "three expr in a row" {
181 testThreeExprInARow(false, true);181 try testThreeExprInARow(false, true);
182 comptime testThreeExprInARow(false, true);182 comptime try testThreeExprInARow(false, true);
183}183}
184fn testThreeExprInARow(f: bool, t: bool) void {184fn testThreeExprInARow(f: bool, t: bool) !void {
185 assertFalse(f or f or f);185 try assertFalse(f or f or f);
186 assertFalse(t and t and f);186 try assertFalse(t and t and f);
187 assertFalse(1 | 2 | 4 != 7);187 try assertFalse(1 | 2 | 4 != 7);
188 assertFalse(3 ^ 6 ^ 8 != 13);188 try assertFalse(3 ^ 6 ^ 8 != 13);
189 assertFalse(7 & 14 & 28 != 4);189 try assertFalse(7 & 14 & 28 != 4);
190 assertFalse(9 << 1 << 2 != 9 << 3);190 try assertFalse(9 << 1 << 2 != 9 << 3);
191 assertFalse(90 >> 1 >> 2 != 90 >> 3);191 try assertFalse(90 >> 1 >> 2 != 90 >> 3);
192 assertFalse(100 - 1 + 1000 != 1099);192 try assertFalse(100 - 1 + 1000 != 1099);
193 assertFalse(5 * 4 / 2 % 3 != 1);193 try assertFalse(5 * 4 / 2 % 3 != 1);
194 assertFalse(@as(i32, @as(i32, 5)) != 5);194 try assertFalse(@as(i32, @as(i32, 5)) != 5);
195 assertFalse(!!false);195 try assertFalse(!!false);
196 assertFalse(@as(i32, 7) != --(@as(i32, 7)));196 try assertFalse(@as(i32, 7) != --(@as(i32, 7)));
197}197}
198fn assertFalse(b: bool) void {198fn assertFalse(b: bool) !void {
199 expect(!b);199 try expect(!b);
200}200}
201201
202test "const number literal" {202test "const number literal" {
203 const one = 1;203 const one = 1;
204 const eleven = ten + one;204 const eleven = ten + one;
205205
206 expect(eleven == 11);206 try expect(eleven == 11);
207}207}
208const ten = 10;208const ten = 10;
209209
210test "unsigned wrapping" {210test "unsigned wrapping" {
211 testUnsignedWrappingEval(maxInt(u32));211 try testUnsignedWrappingEval(maxInt(u32));
212 comptime testUnsignedWrappingEval(maxInt(u32));212 comptime try testUnsignedWrappingEval(maxInt(u32));
213}213}
214fn testUnsignedWrappingEval(x: u32) void {214fn testUnsignedWrappingEval(x: u32) !void {
215 const zero = x +% 1;215 const zero = x +% 1;
216 expect(zero == 0);216 try expect(zero == 0);
217 const orig = zero -% 1;217 const orig = zero -% 1;
218 expect(orig == maxInt(u32));218 try expect(orig == maxInt(u32));
219}219}
220220
221test "signed wrapping" {221test "signed wrapping" {
222 testSignedWrappingEval(maxInt(i32));222 try testSignedWrappingEval(maxInt(i32));
223 comptime testSignedWrappingEval(maxInt(i32));223 comptime try testSignedWrappingEval(maxInt(i32));
224}224}
225fn testSignedWrappingEval(x: i32) void {225fn testSignedWrappingEval(x: i32) !void {
226 const min_val = x +% 1;226 const min_val = x +% 1;
227 expect(min_val == minInt(i32));227 try expect(min_val == minInt(i32));
228 const max_val = min_val -% 1;228 const max_val = min_val -% 1;
229 expect(max_val == maxInt(i32));229 try expect(max_val == maxInt(i32));
230}230}
231231
232test "signed negation wrapping" {232test "signed negation wrapping" {
233 testSignedNegationWrappingEval(minInt(i16));233 try testSignedNegationWrappingEval(minInt(i16));
234 comptime testSignedNegationWrappingEval(minInt(i16));234 comptime try testSignedNegationWrappingEval(minInt(i16));
235}235}
236fn testSignedNegationWrappingEval(x: i16) void {236fn testSignedNegationWrappingEval(x: i16) !void {
237 expect(x == -32768);237 try expect(x == -32768);
238 const neg = -%x;238 const neg = -%x;
239 expect(neg == -32768);239 try expect(neg == -32768);
240}240}
241241
242test "unsigned negation wrapping" {242test "unsigned negation wrapping" {
243 testUnsignedNegationWrappingEval(1);243 try testUnsignedNegationWrappingEval(1);
244 comptime testUnsignedNegationWrappingEval(1);244 comptime try testUnsignedNegationWrappingEval(1);
245}245}
246fn testUnsignedNegationWrappingEval(x: u16) void {246fn testUnsignedNegationWrappingEval(x: u16) !void {
247 expect(x == 1);247 try expect(x == 1);
248 const neg = -%x;248 const neg = -%x;
249 expect(neg == maxInt(u16));249 try expect(neg == maxInt(u16));
250}250}
251251
252test "unsigned 64-bit division" {252test "unsigned 64-bit division" {
253 test_u64_div();253 try test_u64_div();
254 comptime test_u64_div();254 comptime try test_u64_div();
255}255}
256fn test_u64_div() void {256fn test_u64_div() !void {
257 const result = divWithResult(1152921504606846976, 34359738365);257 const result = divWithResult(1152921504606846976, 34359738365);
258 expect(result.quotient == 33554432);258 try expect(result.quotient == 33554432);
259 expect(result.remainder == 100663296);259 try expect(result.remainder == 100663296);
260}260}
261fn divWithResult(a: u64, b: u64) DivResult {261fn divWithResult(a: u64, b: u64) DivResult {
262 return DivResult{262 return DivResult{
...@@ -270,62 +270,62 @@ const DivResult = struct {...@@ -270,62 +270,62 @@ const DivResult = struct {
270};270};
271271
272test "binary not" {272test "binary not" {
273 expect(comptime x: {273 try expect(comptime x: {
274 break :x ~@as(u16, 0b1010101010101010) == 0b0101010101010101;274 break :x ~@as(u16, 0b1010101010101010) == 0b0101010101010101;
275 });275 });
276 expect(comptime x: {276 try expect(comptime x: {
277 break :x ~@as(u64, 2147483647) == 18446744071562067968;277 break :x ~@as(u64, 2147483647) == 18446744071562067968;
278 });278 });
279 testBinaryNot(0b1010101010101010);279 try testBinaryNot(0b1010101010101010);
280}280}
281281
282fn testBinaryNot(x: u16) void {282fn testBinaryNot(x: u16) !void {
283 expect(~x == 0b0101010101010101);283 try expect(~x == 0b0101010101010101);
284}284}
285285
286test "small int addition" {286test "small int addition" {
287 var x: u2 = 0;287 var x: u2 = 0;
288 expect(x == 0);288 try expect(x == 0);
289289
290 x += 1;290 x += 1;
291 expect(x == 1);291 try expect(x == 1);
292292
293 x += 1;293 x += 1;
294 expect(x == 2);294 try expect(x == 2);
295295
296 x += 1;296 x += 1;
297 expect(x == 3);297 try expect(x == 3);
298298
299 var result: @TypeOf(x) = 3;299 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);
303}303}
304304
305test "float equality" {305test "float equality" {
306 const x: f64 = 0.012;306 const x: f64 = 0.012;
307 const y: f64 = x + 1.0;307 const y: f64 = x + 1.0;
308308
309 testFloatEqualityImpl(x, y);309 try testFloatEqualityImpl(x, y);
310 comptime testFloatEqualityImpl(x, y);310 comptime try testFloatEqualityImpl(x, y);
311}311}
312312
313fn testFloatEqualityImpl(x: f64, y: f64) void {313fn testFloatEqualityImpl(x: f64, y: f64) !void {
314 const y2 = x + 1.0;314 const y2 = x + 1.0;
315 expect(y == y2);315 try expect(y == y2);
316}316}
317317
318test "allow signed integer division/remainder when values are comptime known and positive or exact" {318test "allow signed integer division/remainder when values are comptime known and positive or exact" {
319 expect(5 / 3 == 1);319 try expect(5 / 3 == 1);
320 expect(-5 / -3 == 1);320 try expect(-5 / -3 == 1);
321 expect(-6 / 3 == -2);321 try expect(-6 / 3 == -2);
322322
323 expect(5 % 3 == 2);323 try expect(5 % 3 == 2);
324 expect(-6 % 3 == 0);324 try expect(-6 % 3 == 0);
325}325}
326326
327test "hex float literal parsing" {327test "hex float literal parsing" {
328 comptime expect(0x1.0 == 1.0);328 comptime try expect(0x1.0 == 1.0);
329}329}
330330
331test "quad hex float literal parsing in range" {331test "quad hex float literal parsing in range" {
...@@ -340,29 +340,29 @@ test "quad hex float literal parsing accurate" {...@@ -340,29 +340,29 @@ test "quad hex float literal parsing accurate" {
340340
341 // implied 1 is dropped, with an exponent of 0 (0x3fff) after biasing.341 // implied 1 is dropped, with an exponent of 0 (0x3fff) after biasing.
342 const expected: u128 = 0x3fff1111222233334444555566667777;342 const expected: u128 = 0x3fff1111222233334444555566667777;
343 expect(@bitCast(u128, a) == expected);343 try expect(@bitCast(u128, a) == expected);
344344
345 // non-normalized345 // non-normalized
346 const b: f128 = 0x11.111222233334444555566667777p-4;346 const b: f128 = 0x11.111222233334444555566667777p-4;
347 expect(@bitCast(u128, b) == expected);347 try expect(@bitCast(u128, b) == expected);
348348
349 const S = struct {349 const S = struct {
350 fn doTheTest() void {350 fn doTheTest() !void {
351 {351 {
352 var f: f128 = 0x1.2eab345678439abcdefea56782346p+5;352 var f: f128 = 0x1.2eab345678439abcdefea56782346p+5;
353 expect(@bitCast(u128, f) == 0x40042eab345678439abcdefea5678234);353 try expect(@bitCast(u128, f) == 0x40042eab345678439abcdefea5678234);
354 }354 }
355 {355 {
356 var f: f128 = 0x1.edcb34a235253948765432134674fp-1;356 var f: f128 = 0x1.edcb34a235253948765432134674fp-1;
357 expect(@bitCast(u128, f) == 0x3ffeedcb34a235253948765432134674);357 try expect(@bitCast(u128, f) == 0x3ffeedcb34a235253948765432134674);
358 }358 }
359 {359 {
360 var f: f128 = 0x1.353e45674d89abacc3a2ebf3ff4ffp-50;360 var f: f128 = 0x1.353e45674d89abacc3a2ebf3ff4ffp-50;
361 expect(@bitCast(u128, f) == 0x3fcd353e45674d89abacc3a2ebf3ff50);361 try expect(@bitCast(u128, f) == 0x3fcd353e45674d89abacc3a2ebf3ff50);
362 }362 }
363 {363 {
364 var f: f128 = 0x1.ed8764648369535adf4be3214567fp-9;364 var f: f128 = 0x1.ed8764648369535adf4be3214567fp-9;
365 expect(@bitCast(u128, f) == 0x3ff6ed8764648369535adf4be3214568);365 try expect(@bitCast(u128, f) == 0x3ff6ed8764648369535adf4be3214568);
366 }366 }
367 const exp2ft = [_]f64{367 const exp2ft = [_]f64{
368 0x1.6a09e667f3bcdp-1,368 0x1.6a09e667f3bcdp-1,
...@@ -417,40 +417,40 @@ test "quad hex float literal parsing accurate" {...@@ -417,40 +417,40 @@ test "quad hex float literal parsing accurate" {
417 };417 };
418418
419 for (exp2ft) |x, i| {419 for (exp2ft) |x, i| {
420 expect(@bitCast(u64, x) == answers[i]);420 try expect(@bitCast(u64, x) == answers[i]);
421 }421 }
422 }422 }
423 };423 };
424 S.doTheTest();424 try S.doTheTest();
425 comptime S.doTheTest();425 comptime try S.doTheTest();
426}426}
427427
428test "underscore separator parsing" {428test "underscore separator parsing" {
429 expect(0_0_0_0 == 0);429 try expect(0_0_0_0 == 0);
430 expect(1_234_567 == 1234567);430 try expect(1_234_567 == 1234567);
431 expect(001_234_567 == 1234567);431 try expect(001_234_567 == 1234567);
432 expect(0_0_1_2_3_4_5_6_7 == 1234567);432 try expect(0_0_1_2_3_4_5_6_7 == 1234567);
433433
434 expect(0b0_0_0_0 == 0);434 try expect(0b0_0_0_0 == 0);
435 expect(0b1010_1010 == 0b10101010);435 try expect(0b1010_1010 == 0b10101010);
436 expect(0b0000_1010_1010 == 0b10101010);436 try expect(0b0000_1010_1010 == 0b10101010);
437 expect(0b1_0_1_0_1_0_1_0 == 0b10101010);437 try expect(0b1_0_1_0_1_0_1_0 == 0b10101010);
438438
439 expect(0o0_0_0_0 == 0);439 try expect(0o0_0_0_0 == 0);
440 expect(0o1010_1010 == 0o10101010);440 try expect(0o1010_1010 == 0o10101010);
441 expect(0o0000_1010_1010 == 0o10101010);441 try expect(0o0000_1010_1010 == 0o10101010);
442 expect(0o1_0_1_0_1_0_1_0 == 0o10101010);442 try expect(0o1_0_1_0_1_0_1_0 == 0o10101010);
443443
444 expect(0x0_0_0_0 == 0);444 try expect(0x0_0_0_0 == 0);
445 expect(0x1010_1010 == 0x10101010);445 try expect(0x1010_1010 == 0x10101010);
446 expect(0x0000_1010_1010 == 0x10101010);446 try expect(0x0000_1010_1010 == 0x10101010);
447 expect(0x1_0_1_0_1_0_1_0 == 0x10101010);447 try expect(0x1_0_1_0_1_0_1_0 == 0x10101010);
448448
449 expect(123_456.789_000e1_0 == 123456.789000e10);449 try 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);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);452 try 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);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);
454}454}
455455
456test "hex float literal within range" {456test "hex float literal within range" {
...@@ -460,73 +460,73 @@ test "hex float literal within range" {...@@ -460,73 +460,73 @@ test "hex float literal within range" {
460}460}
461461
462test "truncating shift left" {462test "truncating shift left" {
463 testShlTrunc(maxInt(u16));463 try testShlTrunc(maxInt(u16));
464 comptime testShlTrunc(maxInt(u16));464 comptime try testShlTrunc(maxInt(u16));
465}465}
466fn testShlTrunc(x: u16) void {466fn testShlTrunc(x: u16) !void {
467 const shifted = x << 1;467 const shifted = x << 1;
468 expect(shifted == 65534);468 try expect(shifted == 65534);
469}469}
470470
471test "truncating shift right" {471test "truncating shift right" {
472 testShrTrunc(maxInt(u16));472 try testShrTrunc(maxInt(u16));
473 comptime testShrTrunc(maxInt(u16));473 comptime try testShrTrunc(maxInt(u16));
474}474}
475fn testShrTrunc(x: u16) void {475fn testShrTrunc(x: u16) !void {
476 const shifted = x >> 1;476 const shifted = x >> 1;
477 expect(shifted == 32767);477 try expect(shifted == 32767);
478}478}
479479
480test "exact shift left" {480test "exact shift left" {
481 testShlExact(0b00110101);481 try testShlExact(0b00110101);
482 comptime testShlExact(0b00110101);482 comptime try testShlExact(0b00110101);
483}483}
484fn testShlExact(x: u8) void {484fn testShlExact(x: u8) !void {
485 const shifted = @shlExact(x, 2);485 const shifted = @shlExact(x, 2);
486 expect(shifted == 0b11010100);486 try expect(shifted == 0b11010100);
487}487}
488488
489test "exact shift right" {489test "exact shift right" {
490 testShrExact(0b10110100);490 try testShrExact(0b10110100);
491 comptime testShrExact(0b10110100);491 comptime try testShrExact(0b10110100);
492}492}
493fn testShrExact(x: u8) void {493fn testShrExact(x: u8) !void {
494 const shifted = @shrExact(x, 2);494 const shifted = @shrExact(x, 2);
495 expect(shifted == 0b00101101);495 try expect(shifted == 0b00101101);
496}496}
497497
498test "shift left/right on u0 operand" {498test "shift left/right on u0 operand" {
499 const S = struct {499 const S = struct {
500 fn doTheTest() void {500 fn doTheTest() !void {
501 var x: u0 = 0;501 var x: u0 = 0;
502 var y: u0 = 0;502 var y: u0 = 0;
503 expectEqual(@as(u0, 0), x << 0);503 try expectEqual(@as(u0, 0), x << 0);
504 expectEqual(@as(u0, 0), x >> 0);504 try expectEqual(@as(u0, 0), x >> 0);
505 expectEqual(@as(u0, 0), x << y);505 try expectEqual(@as(u0, 0), x << y);
506 expectEqual(@as(u0, 0), x >> y);506 try expectEqual(@as(u0, 0), x >> y);
507 expectEqual(@as(u0, 0), @shlExact(x, 0));507 try expectEqual(@as(u0, 0), @shlExact(x, 0));
508 expectEqual(@as(u0, 0), @shrExact(x, 0));508 try expectEqual(@as(u0, 0), @shrExact(x, 0));
509 expectEqual(@as(u0, 0), @shlExact(x, y));509 try expectEqual(@as(u0, 0), @shlExact(x, y));
510 expectEqual(@as(u0, 0), @shrExact(x, y));510 try expectEqual(@as(u0, 0), @shrExact(x, y));
511 }511 }
512 };512 };
513 S.doTheTest();513 try S.doTheTest();
514 comptime S.doTheTest();514 comptime try S.doTheTest();
515}515}
516516
517test "comptime_int addition" {517test "comptime_int addition" {
518 comptime {518 comptime {
519 expect(35361831660712422535336160538497375248 + 101752735581729509668353361206450473702 == 137114567242441932203689521744947848950);519 try expect(35361831660712422535336160538497375248 + 101752735581729509668353361206450473702 == 137114567242441932203689521744947848950);
520 expect(594491908217841670578297176641415611445982232488944558774612 + 390603545391089362063884922208143568023166603618446395589768 == 985095453608931032642182098849559179469148836107390954364380);520 try expect(594491908217841670578297176641415611445982232488944558774612 + 390603545391089362063884922208143568023166603618446395589768 == 985095453608931032642182098849559179469148836107390954364380);
521 }521 }
522}522}
523523
524test "comptime_int multiplication" {524test "comptime_int multiplication" {
525 comptime {525 comptime {
526 expect(526 try expect(
527 45960427431263824329884196484953148229 * 128339149605334697009938835852565949723 == 5898522172026096622534201617172456926982464453350084962781392314016180490567,527 45960427431263824329884196484953148229 * 128339149605334697009938835852565949723 == 5898522172026096622534201617172456926982464453350084962781392314016180490567,
528 );528 );
529 expect(529 try expect(
530 594491908217841670578297176641415611445982232488944558774612 * 390603545391089362063884922208143568023166603618446395589768 == 232210647056203049913662402532976186578842425262306016094292237500303028346593132411865381225871291702600263463125370016,530 594491908217841670578297176641415611445982232488944558774612 * 390603545391089362063884922208143568023166603618446395589768 == 232210647056203049913662402532976186578842425262306016094292237500303028346593132411865381225871291702600263463125370016,
531 );531 );
532 }532 }
...@@ -534,7 +534,7 @@ test "comptime_int multiplication" {...@@ -534,7 +534,7 @@ test "comptime_int multiplication" {
534534
535test "comptime_int shifting" {535test "comptime_int shifting" {
536 comptime {536 comptime {
537 expect((@as(u128, 1) << 127) == 0x80000000000000000000000000000000);537 try expect((@as(u128, 1) << 127) == 0x80000000000000000000000000000000);
538 }538 }
539}539}
540540
...@@ -542,16 +542,16 @@ test "comptime_int multi-limb shift and mask" {...@@ -542,16 +542,16 @@ test "comptime_int multi-limb shift and mask" {
542 comptime {542 comptime {
543 var a = 0xefffffffa0000001eeeeeeefaaaaaaab;543 var a = 0xefffffffa0000001eeeeeeefaaaaaaab;
544544
545 expect(@as(u32, a & 0xffffffff) == 0xaaaaaaab);545 try expect(@as(u32, a & 0xffffffff) == 0xaaaaaaab);
546 a >>= 32;546 a >>= 32;
547 expect(@as(u32, a & 0xffffffff) == 0xeeeeeeef);547 try expect(@as(u32, a & 0xffffffff) == 0xeeeeeeef);
548 a >>= 32;548 a >>= 32;
549 expect(@as(u32, a & 0xffffffff) == 0xa0000001);549 try expect(@as(u32, a & 0xffffffff) == 0xa0000001);
550 a >>= 32;550 a >>= 32;
551 expect(@as(u32, a & 0xffffffff) == 0xefffffff);551 try expect(@as(u32, a & 0xffffffff) == 0xefffffff);
552 a >>= 32;552 a >>= 32;
553553
554 expect(a == 0);554 try expect(a == 0);
555 }555 }
556}556}
557557
...@@ -559,227 +559,227 @@ test "comptime_int multi-limb partial shift right" {...@@ -559,227 +559,227 @@ test "comptime_int multi-limb partial shift right" {
559 comptime {559 comptime {
560 var a = 0x1ffffffffeeeeeeee;560 var a = 0x1ffffffffeeeeeeee;
561 a >>= 16;561 a >>= 16;
562 expect(a == 0x1ffffffffeeee);562 try expect(a == 0x1ffffffffeeee);
563 }563 }
564}564}
565565
566test "xor" {566test "xor" {
567 test_xor();567 try test_xor();
568 comptime test_xor();568 comptime try test_xor();
569}569}
570570
571fn test_xor() void {571fn test_xor() !void {
572 expect(0xFF ^ 0x00 == 0xFF);572 try expect(0xFF ^ 0x00 == 0xFF);
573 expect(0xF0 ^ 0x0F == 0xFF);573 try expect(0xF0 ^ 0x0F == 0xFF);
574 expect(0xFF ^ 0xF0 == 0x0F);574 try expect(0xFF ^ 0xF0 == 0x0F);
575 expect(0xFF ^ 0x0F == 0xF0);575 try expect(0xFF ^ 0x0F == 0xF0);
576 expect(0xFF ^ 0xFF == 0x00);576 try expect(0xFF ^ 0xFF == 0x00);
577}577}
578578
579test "comptime_int xor" {579test "comptime_int xor" {
580 comptime {580 comptime {
581 expect(0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF ^ 0x00000000000000000000000000000000 == 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF);581 try expect(0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF ^ 0x00000000000000000000000000000000 == 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF);
582 expect(0xFFFFFFFFFFFFFFFF0000000000000000 ^ 0x0000000000000000FFFFFFFFFFFFFFFF == 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF);582 try expect(0xFFFFFFFFFFFFFFFF0000000000000000 ^ 0x0000000000000000FFFFFFFFFFFFFFFF == 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF);
583 expect(0xFFFFFFFFFFFFFFFF0000000000000000 ^ 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF == 0x0000000000000000FFFFFFFFFFFFFFFF);583 try expect(0xFFFFFFFFFFFFFFFF0000000000000000 ^ 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF == 0x0000000000000000FFFFFFFFFFFFFFFF);
584 expect(0x0000000000000000FFFFFFFFFFFFFFFF ^ 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF == 0xFFFFFFFFFFFFFFFF0000000000000000);584 try expect(0x0000000000000000FFFFFFFFFFFFFFFF ^ 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF == 0xFFFFFFFFFFFFFFFF0000000000000000);
585 expect(0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF ^ 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF == 0x00000000000000000000000000000000);585 try expect(0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF ^ 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF == 0x00000000000000000000000000000000);
586 expect(0xFFFFFFFF00000000FFFFFFFF00000000 ^ 0x00000000FFFFFFFF00000000FFFFFFFF == 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF);586 try expect(0xFFFFFFFF00000000FFFFFFFF00000000 ^ 0x00000000FFFFFFFF00000000FFFFFFFF == 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF);
587 expect(0xFFFFFFFF00000000FFFFFFFF00000000 ^ 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF == 0x00000000FFFFFFFF00000000FFFFFFFF);587 try expect(0xFFFFFFFF00000000FFFFFFFF00000000 ^ 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF == 0x00000000FFFFFFFF00000000FFFFFFFF);
588 expect(0x00000000FFFFFFFF00000000FFFFFFFF ^ 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF == 0xFFFFFFFF00000000FFFFFFFF00000000);588 try expect(0x00000000FFFFFFFF00000000FFFFFFFF ^ 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF == 0xFFFFFFFF00000000FFFFFFFF00000000);
589 }589 }
590}590}
591591
592test "f128" {592test "f128" {
593 test_f128();593 try test_f128();
594 comptime test_f128();594 comptime try test_f128();
595}595}
596596
597fn make_f128(x: f128) f128 {597fn make_f128(x: f128) f128 {
598 return x;598 return x;
599}599}
600600
601fn test_f128() void {601fn test_f128() !void {
602 expect(@sizeOf(f128) == 16);602 try expect(@sizeOf(f128) == 16);
603 expect(make_f128(1.0) == 1.0);603 try expect(make_f128(1.0) == 1.0);
604 expect(make_f128(1.0) != 1.1);604 try expect(make_f128(1.0) != 1.1);
605 expect(make_f128(1.0) > 0.9);605 try expect(make_f128(1.0) > 0.9);
606 expect(make_f128(1.0) >= 0.9);606 try expect(make_f128(1.0) >= 0.9);
607 expect(make_f128(1.0) >= 1.0);607 try expect(make_f128(1.0) >= 1.0);
608 should_not_be_zero(1.0);608 try should_not_be_zero(1.0);
609}609}
610610
611fn should_not_be_zero(x: f128) void {611fn should_not_be_zero(x: f128) !void {
612 expect(x != 0.0);612 try expect(x != 0.0);
613}613}
614614
615test "comptime float rem int" {615test "comptime float rem int" {
616 comptime {616 comptime {
617 var x = @as(f32, 1) % 2;617 var x = @as(f32, 1) % 2;
618 expect(x == 1.0);618 try expect(x == 1.0);
619 }619 }
620}620}
621621
622test "remainder division" {622test "remainder division" {
623 comptime remdiv(f16);623 comptime try remdiv(f16);
624 comptime remdiv(f32);624 comptime try remdiv(f32);
625 comptime remdiv(f64);625 comptime try remdiv(f64);
626 comptime remdiv(f128);626 comptime try remdiv(f128);
627 remdiv(f16);627 try remdiv(f16);
628 remdiv(f64);628 try remdiv(f64);
629 remdiv(f128);629 try remdiv(f128);
630}630}
631631
632fn remdiv(comptime T: type) void {632fn remdiv(comptime T: type) !void {
633 expect(@as(T, 1) == @as(T, 1) % @as(T, 2));633 try expect(@as(T, 1) == @as(T, 1) % @as(T, 2));
634 expect(@as(T, 1) == @as(T, 7) % @as(T, 3));634 try expect(@as(T, 1) == @as(T, 7) % @as(T, 3));
635}635}
636636
637test "@sqrt" {637test "@sqrt" {
638 testSqrt(f64, 12.0);638 try testSqrt(f64, 12.0);
639 comptime testSqrt(f64, 12.0);639 comptime try testSqrt(f64, 12.0);
640 testSqrt(f32, 13.0);640 try testSqrt(f32, 13.0);
641 comptime testSqrt(f32, 13.0);641 comptime try testSqrt(f32, 13.0);
642 testSqrt(f16, 13.0);642 try testSqrt(f16, 13.0);
643 comptime testSqrt(f16, 13.0);643 comptime try testSqrt(f16, 13.0);
644644
645 const x = 14.0;645 const x = 14.0;
646 const y = x * x;646 const y = x * x;
647 const z = @sqrt(y);647 const z = @sqrt(y);
648 comptime expect(z == x);648 comptime try expect(z == x);
649}649}
650650
651fn testSqrt(comptime T: type, x: T) void {651fn testSqrt(comptime T: type, x: T) !void {
652 expect(@sqrt(x * x) == x);652 try expect(@sqrt(x * x) == x);
653}653}
654654
655test "@fabs" {655test "@fabs" {
656 testFabs(f128, 12.0);656 try testFabs(f128, 12.0);
657 comptime testFabs(f128, 12.0);657 comptime try testFabs(f128, 12.0);
658 testFabs(f64, 12.0);658 try testFabs(f64, 12.0);
659 comptime testFabs(f64, 12.0);659 comptime try testFabs(f64, 12.0);
660 testFabs(f32, 12.0);660 try testFabs(f32, 12.0);
661 comptime testFabs(f32, 12.0);661 comptime try testFabs(f32, 12.0);
662 testFabs(f16, 12.0);662 try testFabs(f16, 12.0);
663 comptime testFabs(f16, 12.0);663 comptime try testFabs(f16, 12.0);
664664
665 const x = 14.0;665 const x = 14.0;
666 const y = -x;666 const y = -x;
667 const z = @fabs(y);667 const z = @fabs(y);
668 comptime expectEqual(x, z);668 comptime try expectEqual(x, z);
669}669}
670670
671fn testFabs(comptime T: type, x: T) void {671fn testFabs(comptime T: type, x: T) !void {
672 const y = -x;672 const y = -x;
673 const z = @fabs(y);673 const z = @fabs(y);
674 expectEqual(x, z);674 try expectEqual(x, z);
675}675}
676676
677test "@floor" {677test "@floor" {
678 // FIXME: Generates a floorl function call678 // FIXME: Generates a floorl function call
679 // testFloor(f128, 12.0);679 // testFloor(f128, 12.0);
680 comptime testFloor(f128, 12.0);680 comptime try testFloor(f128, 12.0);
681 testFloor(f64, 12.0);681 try testFloor(f64, 12.0);
682 comptime testFloor(f64, 12.0);682 comptime try testFloor(f64, 12.0);
683 testFloor(f32, 12.0);683 try testFloor(f32, 12.0);
684 comptime testFloor(f32, 12.0);684 comptime try testFloor(f32, 12.0);
685 testFloor(f16, 12.0);685 try testFloor(f16, 12.0);
686 comptime testFloor(f16, 12.0);686 comptime try testFloor(f16, 12.0);
687687
688 const x = 14.0;688 const x = 14.0;
689 const y = x + 0.7;689 const y = x + 0.7;
690 const z = @floor(y);690 const z = @floor(y);
691 comptime expectEqual(x, z);691 comptime try expectEqual(x, z);
692}692}
693693
694fn testFloor(comptime T: type, x: T) void {694fn testFloor(comptime T: type, x: T) !void {
695 const y = x + 0.6;695 const y = x + 0.6;
696 const z = @floor(y);696 const z = @floor(y);
697 expectEqual(x, z);697 try expectEqual(x, z);
698}698}
699699
700test "@ceil" {700test "@ceil" {
701 // FIXME: Generates a ceill function call701 // FIXME: Generates a ceill function call
702 //testCeil(f128, 12.0);702 //testCeil(f128, 12.0);
703 comptime testCeil(f128, 12.0);703 comptime try testCeil(f128, 12.0);
704 testCeil(f64, 12.0);704 try testCeil(f64, 12.0);
705 comptime testCeil(f64, 12.0);705 comptime try testCeil(f64, 12.0);
706 testCeil(f32, 12.0);706 try testCeil(f32, 12.0);
707 comptime testCeil(f32, 12.0);707 comptime try testCeil(f32, 12.0);
708 testCeil(f16, 12.0);708 try testCeil(f16, 12.0);
709 comptime testCeil(f16, 12.0);709 comptime try testCeil(f16, 12.0);
710710
711 const x = 14.0;711 const x = 14.0;
712 const y = x - 0.7;712 const y = x - 0.7;
713 const z = @ceil(y);713 const z = @ceil(y);
714 comptime expectEqual(x, z);714 comptime try expectEqual(x, z);
715}715}
716716
717fn testCeil(comptime T: type, x: T) void {717fn testCeil(comptime T: type, x: T) !void {
718 const y = x - 0.8;718 const y = x - 0.8;
719 const z = @ceil(y);719 const z = @ceil(y);
720 expectEqual(x, z);720 try expectEqual(x, z);
721}721}
722722
723test "@trunc" {723test "@trunc" {
724 // FIXME: Generates a truncl function call724 // FIXME: Generates a truncl function call
725 //testTrunc(f128, 12.0);725 //testTrunc(f128, 12.0);
726 comptime testTrunc(f128, 12.0);726 comptime try testTrunc(f128, 12.0);
727 testTrunc(f64, 12.0);727 try testTrunc(f64, 12.0);
728 comptime testTrunc(f64, 12.0);728 comptime try testTrunc(f64, 12.0);
729 testTrunc(f32, 12.0);729 try testTrunc(f32, 12.0);
730 comptime testTrunc(f32, 12.0);730 comptime try testTrunc(f32, 12.0);
731 testTrunc(f16, 12.0);731 try testTrunc(f16, 12.0);
732 comptime testTrunc(f16, 12.0);732 comptime try testTrunc(f16, 12.0);
733733
734 const x = 14.0;734 const x = 14.0;
735 const y = x + 0.7;735 const y = x + 0.7;
736 const z = @trunc(y);736 const z = @trunc(y);
737 comptime expectEqual(x, z);737 comptime try expectEqual(x, z);
738}738}
739739
740fn testTrunc(comptime T: type, x: T) void {740fn testTrunc(comptime T: type, x: T) !void {
741 {741 {
742 const y = x + 0.8;742 const y = x + 0.8;
743 const z = @trunc(y);743 const z = @trunc(y);
744 expectEqual(x, z);744 try expectEqual(x, z);
745 }745 }
746746
747 {747 {
748 const y = -x - 0.8;748 const y = -x - 0.8;
749 const z = @trunc(y);749 const z = @trunc(y);
750 expectEqual(-x, z);750 try expectEqual(-x, z);
751 }751 }
752}752}
753753
754test "@round" {754test "@round" {
755 // FIXME: Generates a roundl function call755 // FIXME: Generates a roundl function call
756 //testRound(f128, 12.0);756 //testRound(f128, 12.0);
757 comptime testRound(f128, 12.0);757 comptime try testRound(f128, 12.0);
758 testRound(f64, 12.0);758 try testRound(f64, 12.0);
759 comptime testRound(f64, 12.0);759 comptime try testRound(f64, 12.0);
760 testRound(f32, 12.0);760 try testRound(f32, 12.0);
761 comptime testRound(f32, 12.0);761 comptime try testRound(f32, 12.0);
762 testRound(f16, 12.0);762 try testRound(f16, 12.0);
763 comptime testRound(f16, 12.0);763 comptime try testRound(f16, 12.0);
764764
765 const x = 14.0;765 const x = 14.0;
766 const y = x + 0.4;766 const y = x + 0.4;
767 const z = @round(y);767 const z = @round(y);
768 comptime expectEqual(x, z);768 comptime try expectEqual(x, z);
769}769}
770770
771fn testRound(comptime T: type, x: T) void {771fn testRound(comptime T: type, x: T) !void {
772 const y = x - 0.5;772 const y = x - 0.5;
773 const z = @round(y);773 const z = @round(y);
774 expectEqual(x, z);774 try expectEqual(x, z);
775}775}
776776
777test "comptime_int param and return" {777test "comptime_int param and return" {
778 const a = comptimeAdd(35361831660712422535336160538497375248, 101752735581729509668353361206450473702);778 const a = comptimeAdd(35361831660712422535336160538497375248, 101752735581729509668353361206450473702);
779 expect(a == 137114567242441932203689521744947848950);779 try expect(a == 137114567242441932203689521744947848950);
780780
781 const b = comptimeAdd(594491908217841670578297176641415611445982232488944558774612, 390603545391089362063884922208143568023166603618446395589768);781 const b = comptimeAdd(594491908217841670578297176641415611445982232488944558774612, 390603545391089362063884922208143568023166603618446395589768);
782 expect(b == 985095453608931032642182098849559179469148836107390954364380);782 try expect(b == 985095453608931032642182098849559179469148836107390954364380);
783}783}
784784
785fn comptimeAdd(comptime a: comptime_int, comptime b: comptime_int) comptime_int {785fn 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...@@ -788,85 +788,85 @@ fn comptimeAdd(comptime a: comptime_int, comptime b: comptime_int) comptime_int
788788
789test "vector integer addition" {789test "vector integer addition" {
790 const S = struct {790 const S = struct {
791 fn doTheTest() void {791 fn doTheTest() !void {
792 var a: std.meta.Vector(4, i32) = [_]i32{ 1, 2, 3, 4 };792 var a: std.meta.Vector(4, i32) = [_]i32{ 1, 2, 3, 4 };
793 var b: std.meta.Vector(4, i32) = [_]i32{ 5, 6, 7, 8 };793 var b: std.meta.Vector(4, i32) = [_]i32{ 5, 6, 7, 8 };
794 var result = a + b;794 var result = a + b;
795 var result_array: [4]i32 = result;795 var result_array: [4]i32 = result;
796 const expected = [_]i32{ 6, 8, 10, 12 };796 const expected = [_]i32{ 6, 8, 10, 12 };
797 expectEqualSlices(i32, &expected, &result_array);797 try expectEqualSlices(i32, &expected, &result_array);
798 }798 }
799 };799 };
800 S.doTheTest();800 try S.doTheTest();
801 comptime S.doTheTest();801 comptime try S.doTheTest();
802}802}
803803
804test "NaN comparison" {804test "NaN comparison" {
805 testNanEqNan(f16);805 try testNanEqNan(f16);
806 testNanEqNan(f32);806 try testNanEqNan(f32);
807 testNanEqNan(f64);807 try testNanEqNan(f64);
808 testNanEqNan(f128);808 try testNanEqNan(f128);
809 comptime testNanEqNan(f16);809 comptime try testNanEqNan(f16);
810 comptime testNanEqNan(f32);810 comptime try testNanEqNan(f32);
811 comptime testNanEqNan(f64);811 comptime try testNanEqNan(f64);
812 comptime testNanEqNan(f128);812 comptime try testNanEqNan(f128);
813}813}
814814
815fn testNanEqNan(comptime F: type) void {815fn testNanEqNan(comptime F: type) !void {
816 var nan1 = std.math.nan(F);816 var nan1 = std.math.nan(F);
817 var nan2 = std.math.nan(F);817 var nan2 = std.math.nan(F);
818 expect(nan1 != nan2);818 try expect(nan1 != nan2);
819 expect(!(nan1 == nan2));819 try expect(!(nan1 == nan2));
820 expect(!(nan1 > nan2));820 try expect(!(nan1 > nan2));
821 expect(!(nan1 >= nan2));821 try expect(!(nan1 >= nan2));
822 expect(!(nan1 < nan2));822 try expect(!(nan1 < nan2));
823 expect(!(nan1 <= nan2));823 try expect(!(nan1 <= nan2));
824}824}
825825
826test "128-bit multiplication" {826test "128-bit multiplication" {
827 var a: i128 = 3;827 var a: i128 = 3;
828 var b: i128 = 2;828 var b: i128 = 2;
829 var c = a * b;829 var c = a * b;
830 expect(c == 6);830 try expect(c == 6);
831}831}
832832
833test "vector comparison" {833test "vector comparison" {
834 const S = struct {834 const S = struct {
835 fn doTheTest() void {835 fn doTheTest() !void {
836 var a: std.meta.Vector(6, i32) = [_]i32{ 1, 3, -1, 5, 7, 9 };836 var a: std.meta.Vector(6, i32) = [_]i32{ 1, 3, -1, 5, 7, 9 };
837 var b: std.meta.Vector(6, i32) = [_]i32{ -1, 3, 0, 6, 10, -10 };837 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 }));838 try 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 }));839 try 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 }));840 try 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 }));841 try 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 }));842 try 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 }));843 try expect(mem.eql(bool, &@as([6]bool, a >= b), &[_]bool{ true, true, false, false, false, true }));
844 }844 }
845 };845 };
846 S.doTheTest();846 try S.doTheTest();
847 comptime S.doTheTest();847 comptime try S.doTheTest();
848}848}
849849
850test "compare undefined literal with comptime_int" {850test "compare undefined literal with comptime_int" {
851 var x = undefined == 1;851 var x = undefined == 1;
852 // x is now undefined with type bool852 // x is now undefined with type bool
853 x = true;853 x = true;
854 expect(x);854 try expect(x);
855}855}
856856
857test "signed zeros are represented properly" {857test "signed zeros are represented properly" {
858 const S = struct {858 const S = struct {
859 fn doTheTest() void {859 fn doTheTest() !void {
860 inline for ([_]type{ f16, f32, f64, f128 }) |T| {860 inline for ([_]type{ f16, f32, f64, f128 }) |T| {
861 const ST = std.meta.Int(.unsigned, @typeInfo(T).Float.bits);861 const ST = std.meta.Int(.unsigned, @typeInfo(T).Float.bits);
862 var as_fp_val = -@as(T, 0.0);862 var as_fp_val = -@as(T, 0.0);
863 var as_uint_val = @bitCast(ST, as_fp_val);863 var as_uint_val = @bitCast(ST, as_fp_val);
864 // Ensure the sign bit is set.864 // 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);
866 }866 }
867 }867 }
868 };868 };
869869
870 S.doTheTest();870 try S.doTheTest();
871 comptime S.doTheTest();871 comptime try S.doTheTest();
872}872}
test/behavior/misc.zig+107-107
...@@ -25,18 +25,18 @@ test "call disabled extern fn" {...@@ -25,18 +25,18 @@ test "call disabled extern fn" {
25}25}
2626
27test "short circuit" {27test "short circuit" {
28 testShortCircuit(false, true);28 try testShortCircuit(false, true);
29 comptime testShortCircuit(false, true);29 comptime try testShortCircuit(false, true);
30}30}
3131
32fn testShortCircuit(f: bool, t: bool) void {32fn testShortCircuit(f: bool, t: bool) !void {
33 var hit_1 = f;33 var hit_1 = f;
34 var hit_2 = f;34 var hit_2 = f;
35 var hit_3 = f;35 var hit_3 = f;
36 var hit_4 = f;36 var hit_4 = f;
3737
38 if (t or x: {38 if (t or x: {
39 expect(f);39 try expect(f);
40 break :x f;40 break :x f;
41 }) {41 }) {
42 hit_1 = t;42 hit_1 = t;
...@@ -45,31 +45,31 @@ fn testShortCircuit(f: bool, t: bool) void {...@@ -45,31 +45,31 @@ fn testShortCircuit(f: bool, t: bool) void {
45 hit_2 = t;45 hit_2 = t;
46 break :x f;46 break :x f;
47 }) {47 }) {
48 expect(f);48 try expect(f);
49 }49 }
5050
51 if (t and x: {51 if (t and x: {
52 hit_3 = t;52 hit_3 = t;
53 break :x f;53 break :x f;
54 }) {54 }) {
55 expect(f);55 try expect(f);
56 }56 }
57 if (f and x: {57 if (f and x: {
58 expect(f);58 try expect(f);
59 break :x f;59 break :x f;
60 }) {60 }) {
61 expect(f);61 try expect(f);
62 } else {62 } else {
63 hit_4 = t;63 hit_4 = t;
64 }64 }
65 expect(hit_1);65 try expect(hit_1);
66 expect(hit_2);66 try expect(hit_2);
67 expect(hit_3);67 try expect(hit_3);
68 expect(hit_4);68 try expect(hit_4);
69}69}
7070
71test "truncate" {71test "truncate" {
72 expect(testTruncate(0x10fd) == 0xfd);72 try expect(testTruncate(0x10fd) == 0xfd);
73}73}
74fn testTruncate(x: u32) u8 {74fn testTruncate(x: u32) u8 {
75 return @truncate(u8, x);75 return @truncate(u8, x);
...@@ -80,16 +80,16 @@ fn first4KeysOfHomeRow() []const u8 {...@@ -80,16 +80,16 @@ fn first4KeysOfHomeRow() []const u8 {
80}80}
8181
82test "return string from function" {82test "return string from function" {
83 expect(mem.eql(u8, first4KeysOfHomeRow(), "aoeu"));83 try expect(mem.eql(u8, first4KeysOfHomeRow(), "aoeu"));
84}84}
8585
86const g1: i32 = 1233 + 1;86const g1: i32 = 1233 + 1;
87var g2: i32 = 0;87var g2: i32 = 0;
8888
89test "global variables" {89test "global variables" {
90 expect(g2 == 0);90 try expect(g2 == 0);
91 g2 = g1;91 g2 = g1;
92 expect(g2 == 1234);92 try expect(g2 == 1234);
93}93}
9494
95test "memcpy and memset intrinsics" {95test "memcpy and memset intrinsics" {
...@@ -106,7 +106,7 @@ test "builtin static eval" {...@@ -106,7 +106,7 @@ test "builtin static eval" {
106 const x: i32 = comptime x: {106 const x: i32 = comptime x: {
107 break :x 1 + 2 + 3;107 break :x 1 + 2 + 3;
108 };108 };
109 expect(x == comptime 6);109 try expect(x == comptime 6);
110}110}
111111
112test "slicing" {112test "slicing" {
...@@ -127,7 +127,7 @@ test "slicing" {...@@ -127,7 +127,7 @@ test "slicing" {
127127
128test "constant equal function pointers" {128test "constant equal function pointers" {
129 const alias = emptyFn;129 const alias = emptyFn;
130 expect(comptime x: {130 try expect(comptime x: {
131 break :x emptyFn == alias;131 break :x emptyFn == alias;
132 });132 });
133}133}
...@@ -135,25 +135,25 @@ test "constant equal function pointers" {...@@ -135,25 +135,25 @@ test "constant equal function pointers" {
135fn emptyFn() void {}135fn emptyFn() void {}
136136
137test "hex escape" {137test "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"));
139}139}
140140
141test "string concatenation" {141test "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"));
143}143}
144144
145test "array mult operator" {145test "array mult operator" {
146 expect(mem.eql(u8, "ab" ** 5, "ababababab"));146 try expect(mem.eql(u8, "ab" ** 5, "ababababab"));
147}147}
148148
149test "string escapes" {149test "string escapes" {
150 expect(mem.eql(u8, "\"", "\x22"));150 try expect(mem.eql(u8, "\"", "\x22"));
151 expect(mem.eql(u8, "\'", "\x27"));151 try expect(mem.eql(u8, "\'", "\x27"));
152 expect(mem.eql(u8, "\n", "\x0a"));152 try expect(mem.eql(u8, "\n", "\x0a"));
153 expect(mem.eql(u8, "\r", "\x0d"));153 try expect(mem.eql(u8, "\r", "\x0d"));
154 expect(mem.eql(u8, "\t", "\x09"));154 try expect(mem.eql(u8, "\t", "\x09"));
155 expect(mem.eql(u8, "\\", "\x5c"));155 try expect(mem.eql(u8, "\\", "\x5c"));
156 expect(mem.eql(u8, "\u{1234}\u{069}\u{1}", "\xe1\x88\xb4\x69\x01"));156 try expect(mem.eql(u8, "\u{1234}\u{069}\u{1}", "\xe1\x88\xb4\x69\x01"));
157}157}
158158
159test "multiline string" {159test "multiline string" {
...@@ -163,7 +163,7 @@ test "multiline string" {...@@ -163,7 +163,7 @@ test "multiline string" {
163 \\three163 \\three
164 ;164 ;
165 const s2 = "one\ntwo)\nthree";165 const s2 = "one\ntwo)\nthree";
166 expect(mem.eql(u8, s1, s2));166 try expect(mem.eql(u8, s1, s2));
167}167}
168168
169test "multiline string comments at start" {169test "multiline string comments at start" {
...@@ -173,7 +173,7 @@ test "multiline string comments at start" {...@@ -173,7 +173,7 @@ test "multiline string comments at start" {
173 \\three173 \\three
174 ;174 ;
175 const s2 = "two)\nthree";175 const s2 = "two)\nthree";
176 expect(mem.eql(u8, s1, s2));176 try expect(mem.eql(u8, s1, s2));
177}177}
178178
179test "multiline string comments at end" {179test "multiline string comments at end" {
...@@ -183,7 +183,7 @@ test "multiline string comments at end" {...@@ -183,7 +183,7 @@ test "multiline string comments at end" {
183 //\\three183 //\\three
184 ;184 ;
185 const s2 = "one\ntwo)";185 const s2 = "one\ntwo)";
186 expect(mem.eql(u8, s1, s2));186 try expect(mem.eql(u8, s1, s2));
187}187}
188188
189test "multiline string comments in middle" {189test "multiline string comments in middle" {
...@@ -193,7 +193,7 @@ test "multiline string comments in middle" {...@@ -193,7 +193,7 @@ test "multiline string comments in middle" {
193 \\three193 \\three
194 ;194 ;
195 const s2 = "one\nthree";195 const s2 = "one\nthree";
196 expect(mem.eql(u8, s1, s2));196 try expect(mem.eql(u8, s1, s2));
197}197}
198198
199test "multiline string comments at multiple places" {199test "multiline string comments at multiple places" {
...@@ -205,7 +205,7 @@ test "multiline string comments at multiple places" {...@@ -205,7 +205,7 @@ test "multiline string comments at multiple places" {
205 \\five205 \\five
206 ;206 ;
207 const s2 = "one\nthree\nfive";207 const s2 = "one\nthree\nfive";
208 expect(mem.eql(u8, s1, s2));208 try expect(mem.eql(u8, s1, s2));
209}209}
210210
211test "multiline C string" {211test "multiline C string" {
...@@ -215,11 +215,11 @@ test "multiline C string" {...@@ -215,11 +215,11 @@ test "multiline C string" {
215 \\three215 \\three
216 ;216 ;
217 const s2 = "one\ntwo)\nthree";217 const s2 = "one\ntwo)\nthree";
218 expect(std.cstr.cmp(s1, s2) == 0);218 try expect(std.cstr.cmp(s1, s2) == 0);
219}219}
220220
221test "type equality" {221test "type equality" {
222 expect(*const u8 != *u8);222 try expect(*const u8 != *u8);
223}223}
224224
225const global_a: i32 = 1234;225const global_a: i32 = 1234;
...@@ -227,7 +227,7 @@ const global_b: *const i32 = &global_a;...@@ -227,7 +227,7 @@ const global_b: *const i32 = &global_a;
227const global_c: *const f32 = @ptrCast(*const f32, global_b);227const global_c: *const f32 = @ptrCast(*const f32, global_b);
228test "compile time global reinterpret" {228test "compile time global reinterpret" {
229 const d = @ptrCast(*const i32, global_c);229 const d = @ptrCast(*const i32, global_c);
230 expect(d.* == 1234);230 try expect(d.* == 1234);
231}231}
232232
233test "explicit cast maybe pointers" {233test "explicit cast maybe pointers" {
...@@ -253,8 +253,8 @@ test "cast undefined" {...@@ -253,8 +253,8 @@ test "cast undefined" {
253fn testCastUndefined(x: []const u8) void {}253fn testCastUndefined(x: []const u8) void {}
254254
255test "cast small unsigned to larger signed" {255test "cast small unsigned to larger signed" {
256 expect(castSmallUnsignedToLargerSigned1(200) == @as(i16, 200));256 try expect(castSmallUnsignedToLargerSigned1(200) == @as(i16, 200));
257 expect(castSmallUnsignedToLargerSigned2(9999) == @as(i64, 9999));257 try expect(castSmallUnsignedToLargerSigned2(9999) == @as(i64, 9999));
258}258}
259fn castSmallUnsignedToLargerSigned1(x: u8) i16 {259fn castSmallUnsignedToLargerSigned1(x: u8) i16 {
260 return x;260 return x;
...@@ -264,7 +264,7 @@ fn castSmallUnsignedToLargerSigned2(x: u16) i64 {...@@ -264,7 +264,7 @@ fn castSmallUnsignedToLargerSigned2(x: u16) i64 {
264}264}
265265
266test "implicit cast after unreachable" {266test "implicit cast after unreachable" {
267 expect(outer() == 1234);267 try expect(outer() == 1234);
268}268}
269fn inner() i32 {269fn inner() i32 {
270 return 1234;270 return 1234;
...@@ -279,13 +279,13 @@ test "pointer dereferencing" {...@@ -279,13 +279,13 @@ test "pointer dereferencing" {
279279
280 y.* += 1;280 y.* += 1;
281281
282 expect(x == 4);282 try expect(x == 4);
283 expect(y.* == 4);283 try expect(y.* == 4);
284}284}
285285
286test "call result of if else expression" {286test "call result of if else expression" {
287 expect(mem.eql(u8, f2(true), "a"));287 try expect(mem.eql(u8, f2(true), "a"));
288 expect(mem.eql(u8, f2(false), "b"));288 try expect(mem.eql(u8, f2(false), "b"));
289}289}
290fn f2(x: bool) []const u8 {290fn f2(x: bool) []const u8 {
291 return (if (x) fA else fB)();291 return (if (x) fA else fB)();
...@@ -305,8 +305,8 @@ test "const expression eval handling of variables" {...@@ -305,8 +305,8 @@ test "const expression eval handling of variables" {
305}305}
306306
307test "constant enum initialization with differing sizes" {307test "constant enum initialization with differing sizes" {
308 test3_1(test3_foo);308 try test3_1(test3_foo);
309 test3_2(test3_bar);309 try test3_2(test3_bar);
310}310}
311const Test3Foo = union(enum) {311const Test3Foo = union(enum) {
312 One: void,312 One: void,
...@@ -324,41 +324,41 @@ const test3_foo = Test3Foo{...@@ -324,41 +324,41 @@ const test3_foo = Test3Foo{
324 },324 },
325};325};
326const test3_bar = Test3Foo{ .Two = 13 };326const test3_bar = Test3Foo{ .Two = 13 };
327fn test3_1(f: Test3Foo) void {327fn test3_1(f: Test3Foo) !void {
328 switch (f) {328 switch (f) {
329 Test3Foo.Three => |pt| {329 Test3Foo.Three => |pt| {
330 expect(pt.x == 3);330 try expect(pt.x == 3);
331 expect(pt.y == 4);331 try expect(pt.y == 4);
332 },332 },
333 else => unreachable,333 else => unreachable,
334 }334 }
335}335}
336fn test3_2(f: Test3Foo) void {336fn test3_2(f: Test3Foo) !void {
337 switch (f) {337 switch (f) {
338 Test3Foo.Two => |x| {338 Test3Foo.Two => |x| {
339 expect(x == 13);339 try expect(x == 13);
340 },340 },
341 else => unreachable,341 else => unreachable,
342 }342 }
343}343}
344344
345test "character literals" {345test "character literals" {
346 expect('\'' == single_quote);346 try expect('\'' == single_quote);
347}347}
348const single_quote = '\'';348const single_quote = '\'';
349349
350test "take address of parameter" {350test "take address of parameter" {
351 testTakeAddressOfParameter(12.34);351 try testTakeAddressOfParameter(12.34);
352}352}
353fn testTakeAddressOfParameter(f: f32) void {353fn testTakeAddressOfParameter(f: f32) !void {
354 const f_ptr = &f;354 const f_ptr = &f;
355 expect(f_ptr.* == 12.34);355 try expect(f_ptr.* == 12.34);
356}356}
357357
358test "pointer comparison" {358test "pointer comparison" {
359 const a = @as([]const u8, "a");359 const a = @as([]const u8, "a");
360 const b = &a;360 const b = &a;
361 expect(ptrEql(b, b));361 try expect(ptrEql(b, b));
362}362}
363fn ptrEql(a: *const []const u8, b: *const []const u8) bool {363fn ptrEql(a: *const []const u8, b: *const []const u8) bool {
364 return a == b;364 return a == b;
...@@ -368,19 +368,19 @@ test "string concatenation" {...@@ -368,19 +368,19 @@ test "string concatenation" {
368 const a = "OK" ++ " IT " ++ "WORKED";368 const a = "OK" ++ " IT " ++ "WORKED";
369 const b = "OK IT WORKED";369 const b = "OK IT WORKED";
370370
371 comptime expect(@TypeOf(a) == *const [12:0]u8);371 comptime try expect(@TypeOf(a) == *const [12:0]u8);
372 comptime expect(@TypeOf(b) == *const [12:0]u8);372 comptime try expect(@TypeOf(b) == *const [12:0]u8);
373373
374 const len = mem.len(b);374 const len = mem.len(b);
375 const len_with_null = len + 1;375 const len_with_null = len + 1;
376 {376 {
377 var i: u32 = 0;377 var i: u32 = 0;
378 while (i < len_with_null) : (i += 1) {378 while (i < len_with_null) : (i += 1) {
379 expect(a[i] == b[i]);379 try expect(a[i] == b[i]);
380 }380 }
381 }381 }
382 expect(a[len] == 0);382 try expect(a[len] == 0);
383 expect(b[len] == 0);383 try expect(b[len] == 0);
384}384}
385385
386test "pointer to void return type" {386test "pointer to void return type" {
...@@ -397,7 +397,7 @@ fn testPointerToVoidReturnType2() *const void {...@@ -397,7 +397,7 @@ fn testPointerToVoidReturnType2() *const void {
397397
398test "non const ptr to aliased type" {398test "non const ptr to aliased type" {
399 const int = i32;399 const int = i32;
400 expect(?*int == ?*i32);400 try expect(?*int == ?*i32);
401}401}
402402
403test "array 2D const double ptr" {403test "array 2D const double ptr" {
...@@ -405,13 +405,13 @@ test "array 2D const double ptr" {...@@ -405,13 +405,13 @@ test "array 2D const double ptr" {
405 [_]f32{1.0},405 [_]f32{1.0},
406 [_]f32{2.0},406 [_]f32{2.0},
407 };407 };
408 testArray2DConstDoublePtr(&rect_2d_vertexes[0][0]);408 try testArray2DConstDoublePtr(&rect_2d_vertexes[0][0]);
409}409}
410410
411fn testArray2DConstDoublePtr(ptr: *const f32) void {411fn testArray2DConstDoublePtr(ptr: *const f32) !void {
412 const ptr2 = @ptrCast([*]const f32, ptr);412 const ptr2 = @ptrCast([*]const f32, ptr);
413 expect(ptr2[0] == 1.0);413 try expect(ptr2[0] == 1.0);
414 expect(ptr2[1] == 2.0);414 try expect(ptr2[1] == 2.0);
415}415}
416416
417const AStruct = struct {417const AStruct = struct {
...@@ -439,13 +439,13 @@ test "@typeName" {...@@ -439,13 +439,13 @@ test "@typeName" {
439 Unused,439 Unused,
440 };440 };
441 comptime {441 comptime {
442 expect(mem.eql(u8, @typeName(i64), "i64"));442 try expect(mem.eql(u8, @typeName(i64), "i64"));
443 expect(mem.eql(u8, @typeName(*usize), "*usize"));443 try expect(mem.eql(u8, @typeName(*usize), "*usize"));
444 // https://github.com/ziglang/zig/issues/675444 // https://github.com/ziglang/zig/issues/675
445 expect(mem.eql(u8, "behavior.misc.TypeFromFn(u8)", @typeName(TypeFromFn(u8))));445 try expect(mem.eql(u8, "behavior.misc.TypeFromFn(u8)", @typeName(TypeFromFn(u8))));
446 expect(mem.eql(u8, @typeName(Struct), "Struct"));446 try expect(mem.eql(u8, @typeName(Struct), "Struct"));
447 expect(mem.eql(u8, @typeName(Union), "Union"));447 try expect(mem.eql(u8, @typeName(Union), "Union"));
448 expect(mem.eql(u8, @typeName(Enum), "Enum"));448 try expect(mem.eql(u8, @typeName(Enum), "Enum"));
449 }449 }
450}450}
451451
...@@ -455,14 +455,14 @@ fn TypeFromFn(comptime T: type) type {...@@ -455,14 +455,14 @@ fn TypeFromFn(comptime T: type) type {
455455
456test "double implicit cast in same expression" {456test "double implicit cast in same expression" {
457 var x = @as(i32, @as(u16, nine()));457 var x = @as(i32, @as(u16, nine()));
458 expect(x == 9);458 try expect(x == 9);
459}459}
460fn nine() u8 {460fn nine() u8 {
461 return 9;461 return 9;
462}462}
463463
464test "global variable initialized to global variable array element" {464test "global variable initialized to global variable array element" {
465 expect(global_ptr == &gdt[0]);465 try expect(global_ptr == &gdt[0]);
466}466}
467const GDTEntry = struct {467const GDTEntry = struct {
468 field: i32,468 field: i32,
...@@ -483,9 +483,9 @@ export fn writeToVRam() void {...@@ -483,9 +483,9 @@ export fn writeToVRam() void {
483const OpaqueA = opaque {};483const OpaqueA = opaque {};
484const OpaqueB = opaque {};484const OpaqueB = opaque {};
485test "opaque types" {485test "opaque types" {
486 expect(*OpaqueA != *OpaqueB);486 try expect(*OpaqueA != *OpaqueB);
487 expect(mem.eql(u8, @typeName(OpaqueA), "OpaqueA"));487 try expect(mem.eql(u8, @typeName(OpaqueA), "OpaqueA"));
488 expect(mem.eql(u8, @typeName(OpaqueB), "OpaqueB"));488 try expect(mem.eql(u8, @typeName(OpaqueB), "OpaqueB"));
489}489}
490490
491test "variable is allowed to be a pointer to an opaque type" {491test "variable is allowed to be a pointer to an opaque type" {
...@@ -525,7 +525,7 @@ fn fnThatClosesOverLocalConst() type {...@@ -525,7 +525,7 @@ fn fnThatClosesOverLocalConst() type {
525525
526test "function closes over local const" {526test "function closes over local const" {
527 const x = fnThatClosesOverLocalConst().g();527 const x = fnThatClosesOverLocalConst().g();
528 expect(x == 1);528 try expect(x == 1);
529}529}
530530
531test "cold function" {531test "cold function" {
...@@ -562,21 +562,21 @@ export fn testPackedStuff(a: *const PackedStruct, b: *const PackedUnion, c: Pack...@@ -562,21 +562,21 @@ export fn testPackedStuff(a: *const PackedStruct, b: *const PackedUnion, c: Pack
562test "slicing zero length array" {562test "slicing zero length array" {
563 const s1 = ""[0..];563 const s1 = ""[0..];
564 const s2 = ([_]u32{})[0..];564 const s2 = ([_]u32{})[0..];
565 expect(s1.len == 0);565 try expect(s1.len == 0);
566 expect(s2.len == 0);566 try expect(s2.len == 0);
567 expect(mem.eql(u8, s1, ""));567 try expect(mem.eql(u8, s1, ""));
568 expect(mem.eql(u32, s2, &[_]u32{}));568 try expect(mem.eql(u32, s2, &[_]u32{}));
569}569}
570570
571const addr1 = @ptrCast(*const u8, emptyFn);571const addr1 = @ptrCast(*const u8, emptyFn);
572test "comptime cast fn to ptr" {572test "comptime cast fn to ptr" {
573 const addr2 = @ptrCast(*const u8, emptyFn);573 const addr2 = @ptrCast(*const u8, emptyFn);
574 comptime expect(addr1 == addr2);574 comptime try expect(addr1 == addr2);
575}575}
576576
577test "equality compare fn ptrs" {577test "equality compare fn ptrs" {
578 var a = emptyFn;578 var a = emptyFn;
579 expect(a == a);579 try expect(a == a);
580}580}
581581
582test "self reference through fn ptr field" {582test "self reference through fn ptr field" {
...@@ -591,34 +591,34 @@ test "self reference through fn ptr field" {...@@ -591,34 +591,34 @@ test "self reference through fn ptr field" {
591 };591 };
592 var a: S.A = undefined;592 var a: S.A = undefined;
593 a.f = S.foo;593 a.f = S.foo;
594 expect(a.f(a) == 12);594 try expect(a.f(a) == 12);
595}595}
596596
597test "volatile load and store" {597test "volatile load and store" {
598 var number: i32 = 1234;598 var number: i32 = 1234;
599 const ptr = @as(*volatile i32, &number);599 const ptr = @as(*volatile i32, &number);
600 ptr.* += 1;600 ptr.* += 1;
601 expect(ptr.* == 1235);601 try expect(ptr.* == 1235);
602}602}
603603
604test "slice string literal has correct type" {604test "slice string literal has correct type" {
605 comptime {605 comptime {
606 expect(@TypeOf("aoeu"[0..]) == *const [4:0]u8);606 try expect(@TypeOf("aoeu"[0..]) == *const [4:0]u8);
607 const array = [_]i32{ 1, 2, 3, 4 };607 const array = [_]i32{ 1, 2, 3, 4 };
608 expect(@TypeOf(array[0..]) == *const [4]i32);608 try expect(@TypeOf(array[0..]) == *const [4]i32);
609 }609 }
610 var runtime_zero: usize = 0;610 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);
612 const array = [_]i32{ 1, 2, 3, 4 };612 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);
614}614}
615615
616test "struct inside function" {616test "struct inside function" {
617 testStructInFn();617 try testStructInFn();
618 comptime testStructInFn();618 comptime try testStructInFn();
619}619}
620620
621fn testStructInFn() void {621fn testStructInFn() !void {
622 const BlockKind = u32;622 const BlockKind = u32;
623623
624 const Block = struct {624 const Block = struct {
...@@ -629,11 +629,11 @@ fn testStructInFn() void {...@@ -629,11 +629,11 @@ fn testStructInFn() void {
629629
630 block.kind += 1;630 block.kind += 1;
631631
632 expect(block.kind == 1235);632 try expect(block.kind == 1235);
633}633}
634634
635test "fn call returning scalar optional in equality expression" {635test "fn call returning scalar optional in equality expression" {
636 expect(getNull() == null);636 try expect(getNull() == null);
637}637}
638638
639fn getNull() ?*i32 {639fn getNull() ?*i32 {
...@@ -645,16 +645,16 @@ test "thread local variable" {...@@ -645,16 +645,16 @@ test "thread local variable" {
645 threadlocal var t: i32 = 1234;645 threadlocal var t: i32 = 1234;
646 };646 };
647 S.t += 1;647 S.t += 1;
648 expect(S.t == 1235);648 try expect(S.t == 1235);
649}649}
650650
651test "unicode escape in character literal" {651test "unicode escape in character literal" {
652 var a: u24 = '\u{01f4a9}';652 var a: u24 = '\u{01f4a9}';
653 expect(a == 128169);653 try expect(a == 128169);
654}654}
655655
656test "unicode character in character literal" {656test "unicode character in character literal" {
657 expect('💩' == 128169);657 try expect('💩' == 128169);
658}658}
659659
660test "result location zero sized array inside struct field implicit cast to slice" {660test "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...@@ -662,7 +662,7 @@ test "result location zero sized array inside struct field implicit cast to slic
662 entries: []u32,662 entries: []u32,
663 };663 };
664 var foo = E{ .entries = &[_]u32{} };664 var foo = E{ .entries = &[_]u32{} };
665 expect(foo.entries.len == 0);665 try expect(foo.entries.len == 0);
666}666}
667667
668var global_foo: *i32 = undefined;668var global_foo: *i32 = undefined;
...@@ -677,7 +677,7 @@ test "global variable assignment with optional unwrapping with var initialized t...@@ -677,7 +677,7 @@ test "global variable assignment with optional unwrapping with var initialized t
677 global_foo = S.foo() orelse {677 global_foo = S.foo() orelse {
678 @panic("bad");678 @panic("bad");
679 };679 };
680 expect(global_foo.* == 1234);680 try expect(global_foo.* == 1234);
681}681}
682682
683test "peer result location with typed parent, runtime condition, comptime prongs" {683test "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...@@ -696,8 +696,8 @@ test "peer result location with typed parent, runtime condition, comptime prongs
696 bleh: i32,696 bleh: i32,
697 };697 };
698 };698 };
699 expect(S.doTheTest(0) == 1234);699 try expect(S.doTheTest(0) == 1234);
700 expect(S.doTheTest(1) == 1234);700 try expect(S.doTheTest(1) == 1234);
701}701}
702702
703test "nested optional field in struct" {703test "nested optional field in struct" {
...@@ -710,7 +710,7 @@ test "nested optional field in struct" {...@@ -710,7 +710,7 @@ test "nested optional field in struct" {
710 var s = S1{710 var s = S1{
711 .x = S2{ .y = 127 },711 .x = S2{ .y = 127 },
712 };712 };
713 expect(s.x.?.y == 127);713 try expect(s.x.?.y == 127);
714}714}
715715
716fn maybe(x: bool) anyerror!?u32 {716fn maybe(x: bool) anyerror!?u32 {
...@@ -722,7 +722,7 @@ fn maybe(x: bool) anyerror!?u32 {...@@ -722,7 +722,7 @@ fn maybe(x: bool) anyerror!?u32 {
722722
723test "result location is optional inside error union" {723test "result location is optional inside error union" {
724 const x = maybe(true) catch unreachable;724 const x = maybe(true) catch unreachable;
725 expect(x.? == 42);725 try expect(x.? == 42);
726}726}
727727
728threadlocal var buffer: [11]u8 = undefined;728threadlocal var buffer: [11]u8 = undefined;
...@@ -730,7 +730,7 @@ threadlocal var buffer: [11]u8 = undefined;...@@ -730,7 +730,7 @@ threadlocal var buffer: [11]u8 = undefined;
730test "pointer to thread local array" {730test "pointer to thread local array" {
731 const s = "Hello world";731 const s = "Hello world";
732 std.mem.copy(u8, buffer[0..], s);732 std.mem.copy(u8, buffer[0..], s);
733 std.testing.expectEqualSlices(u8, buffer[0..], s);733 try std.testing.expectEqualSlices(u8, buffer[0..], s);
734}734}
735735
736test "auto created variables have correct alignment" {736test "auto created variables have correct alignment" {
...@@ -742,15 +742,15 @@ test "auto created variables have correct alignment" {...@@ -742,15 +742,15 @@ test "auto created variables have correct alignment" {
742 return 0;742 return 0;
743 }743 }
744 };744 };
745 expect(S.foo("\x7a\x7a\x7a\x7a") == 0x7a7a7a7a);745 try expect(S.foo("\x7a\x7a\x7a\x7a") == 0x7a7a7a7a);
746 comptime expect(S.foo("\x7a\x7a\x7a\x7a") == 0x7a7a7a7a);746 comptime try expect(S.foo("\x7a\x7a\x7a\x7a") == 0x7a7a7a7a);
747}747}
748748
749extern var opaque_extern_var: opaque {};749extern var opaque_extern_var: opaque {};
750var var_to_export: u32 = 42;750var var_to_export: u32 = 42;
751test "extern variable with non-pointer opaque type" {751test "extern variable with non-pointer opaque type" {
752 @export(var_to_export, .{ .name = "opaque_extern_var" });752 @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);
754}754}
755755
756test "lazy typeInfo value as generic parameter" {756test "lazy typeInfo value as generic parameter" {
test/behavior/muladd.zig+7-7
...@@ -1,34 +1,34 @@...@@ -1,34 +1,34 @@
1const expect = @import("std").testing.expect;1const expect = @import("std").testing.expect;
22
3test "@mulAdd" {3test "@mulAdd" {
4 comptime testMulAdd();4 comptime try testMulAdd();
5 testMulAdd();5 try testMulAdd();
6}6}
77
8fn testMulAdd() void {8fn testMulAdd() !void {
9 {9 {
10 var a: f16 = 5.5;10 var a: f16 = 5.5;
11 var b: f16 = 2.5;11 var b: f16 = 2.5;
12 var c: f16 = 6.25;12 var c: f16 = 6.25;
13 expect(@mulAdd(f16, a, b, c) == 20);13 try expect(@mulAdd(f16, a, b, c) == 20);
14 }14 }
15 {15 {
16 var a: f32 = 5.5;16 var a: f32 = 5.5;
17 var b: f32 = 2.5;17 var b: f32 = 2.5;
18 var c: f32 = 6.25;18 var c: f32 = 6.25;
19 expect(@mulAdd(f32, a, b, c) == 20);19 try expect(@mulAdd(f32, a, b, c) == 20);
20 }20 }
21 {21 {
22 var a: f64 = 5.5;22 var a: f64 = 5.5;
23 var b: f64 = 2.5;23 var b: f64 = 2.5;
24 var c: f64 = 6.25;24 var c: f64 = 6.25;
25 expect(@mulAdd(f64, a, b, c) == 20);25 try expect(@mulAdd(f64, a, b, c) == 20);
26 }26 }
27 // Awaits implementation in libm.zig27 // Awaits implementation in libm.zig
28 //{28 //{
29 // var a: f16 = 5.5;29 // var a: f16 = 5.5;
30 // var b: f128 = 2.5;30 // var b: f128 = 2.5;
31 // var c: f128 = 6.25;31 // var c: f128 = 6.25;
32 // expect(@mulAdd(f128, a, b, c) == 20);32 //try expect(@mulAdd(f128, a, b, c) == 20);
33 //}33 //}
34}34}
test/behavior/namespace_depends_on_compile_var.zig+2-2
...@@ -3,9 +3,9 @@ const expect = std.testing.expect;...@@ -3,9 +3,9 @@ const expect = std.testing.expect;
33
4test "namespace depends on compile var" {4test "namespace depends on compile var" {
5 if (some_namespace.a_bool) {5 if (some_namespace.a_bool) {
6 expect(some_namespace.a_bool);6 try expect(some_namespace.a_bool);
7 } else {7 } else {
8 expect(!some_namespace.a_bool);8 try expect(!some_namespace.a_bool);
9 }9 }
10}10}
11const some_namespace = switch (std.builtin.os.tag) {11const some_namespace = switch (std.builtin.os.tag) {
test/behavior/null.zig+24-24
...@@ -17,13 +17,13 @@ test "optional type" {...@@ -17,13 +17,13 @@ test "optional type" {
1717
18 const z = next_x orelse 1234;18 const z = next_x orelse 1234;
1919
20 expect(z == 1234);20 try expect(z == 1234);
2121
22 const final_x: ?i32 = 13;22 const final_x: ?i32 = 13;
2323
24 const num = final_x orelse unreachable;24 const num = final_x orelse unreachable;
2525
26 expect(num == 13);26 try expect(num == 13);
27}27}
2828
29test "test maybe object and get a pointer to the inner value" {29test "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" {...@@ -33,7 +33,7 @@ test "test maybe object and get a pointer to the inner value" {
33 b.* = false;33 b.* = false;
34 }34 }
3535
36 expect(maybe_bool.? == false);36 try expect(maybe_bool.? == false);
37}37}
3838
39test "rhs maybe unwrap return" {39test "rhs maybe unwrap return" {
...@@ -42,14 +42,14 @@ test "rhs maybe unwrap return" {...@@ -42,14 +42,14 @@ test "rhs maybe unwrap return" {
42}42}
4343
44test "maybe return" {44test "maybe return" {
45 maybeReturnImpl();45 try maybeReturnImpl();
46 comptime maybeReturnImpl();46 comptime try maybeReturnImpl();
47}47}
4848
49fn maybeReturnImpl() void {49fn maybeReturnImpl() !void {
50 expect(foo(1235).?);50 try expect(foo(1235).?);
51 if (foo(null) != null) unreachable;51 if (foo(null) != null) unreachable;
52 expect(!foo(1234).?);52 try expect(!foo(1234).?);
53}53}
5454
55fn foo(x: ?i32) ?bool {55fn foo(x: ?i32) ?bool {
...@@ -58,7 +58,7 @@ fn foo(x: ?i32) ?bool {...@@ -58,7 +58,7 @@ fn foo(x: ?i32) ?bool {
58}58}
5959
60test "if var maybe pointer" {60test "if var maybe pointer" {
61 expect(shouldBeAPlus1(Particle{61 try expect(shouldBeAPlus1(Particle{
62 .a = 14,62 .a = 14,
63 .b = 1,63 .b = 1,
64 .c = 1,64 .c = 1,
...@@ -84,10 +84,10 @@ const Particle = struct {...@@ -84,10 +84,10 @@ const Particle = struct {
8484
85test "null literal outside function" {85test "null literal outside function" {
86 const is_null = here_is_a_null_literal.context == null;86 const is_null = here_is_a_null_literal.context == null;
87 expect(is_null);87 try expect(is_null);
8888
89 const is_non_null = here_is_a_null_literal.context != null;89 const is_non_null = here_is_a_null_literal.context != null;
90 expect(!is_non_null);90 try expect(!is_non_null);
91}91}
92const SillyStruct = struct {92const SillyStruct = struct {
93 context: ?i32,93 context: ?i32,
...@@ -95,21 +95,21 @@ const SillyStruct = struct {...@@ -95,21 +95,21 @@ const SillyStruct = struct {
95const here_is_a_null_literal = SillyStruct{ .context = null };95const here_is_a_null_literal = SillyStruct{ .context = null };
9696
97test "test null runtime" {97test "test null runtime" {
98 testTestNullRuntime(null);98 try testTestNullRuntime(null);
99}99}
100fn testTestNullRuntime(x: ?i32) void {100fn testTestNullRuntime(x: ?i32) !void {
101 expect(x == null);101 try expect(x == null);
102 expect(!(x != null));102 try expect(!(x != null));
103}103}
104104
105test "optional void" {105test "optional void" {
106 optionalVoidImpl();106 try optionalVoidImpl();
107 comptime optionalVoidImpl();107 comptime try optionalVoidImpl();
108}108}
109109
110fn optionalVoidImpl() void {110fn optionalVoidImpl() !void {
111 expect(bar(null) == null);111 try expect(bar(null) == null);
112 expect(bar({}) != null);112 try expect(bar({}) != null);
113}113}
114114
115fn bar(x: ?void) ?void {115fn bar(x: ?void) ?void {
...@@ -133,7 +133,7 @@ test "unwrap optional which is field of global var" {...@@ -133,7 +133,7 @@ test "unwrap optional which is field of global var" {
133 }133 }
134 struct_with_optional.field = 1234;134 struct_with_optional.field = 1234;
135 if (struct_with_optional.field) |payload| {135 if (struct_with_optional.field) |payload| {
136 expect(payload == 1234);136 try expect(payload == 1234);
137 } else {137 } else {
138 unreachable;138 unreachable;
139 }139 }
...@@ -141,13 +141,13 @@ test "unwrap optional which is field of global var" {...@@ -141,13 +141,13 @@ test "unwrap optional which is field of global var" {
141141
142test "null with default unwrap" {142test "null with default unwrap" {
143 const x: i32 = null orelse 1;143 const x: i32 = null orelse 1;
144 expect(x == 1);144 try expect(x == 1);
145}145}
146146
147test "optional types" {147test "optional types" {
148 comptime {148 comptime {
149 const opt_type_struct = StructWithOptionalType{ .t = u8 };149 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);
151 }151 }
152}152}
153153
...@@ -158,5 +158,5 @@ const StructWithOptionalType = struct {...@@ -158,5 +158,5 @@ const StructWithOptionalType = struct {
158test "optional pointer to 0 bit type null value at runtime" {158test "optional pointer to 0 bit type null value at runtime" {
159 const EmptyStruct = struct {};159 const EmptyStruct = struct {};
160 var x: ?*EmptyStruct = null;160 var x: ?*EmptyStruct = null;
161 expect(x == null);161 try expect(x == null);
162}162}
test/behavior/optional.zig+51-51
...@@ -8,28 +8,28 @@ pub const EmptyStruct = struct {};...@@ -8,28 +8,28 @@ pub const EmptyStruct = struct {};
8test "optional pointer to size zero struct" {8test "optional pointer to size zero struct" {
9 var e = EmptyStruct{};9 var e = EmptyStruct{};
10 var o: ?*EmptyStruct = &e;10 var o: ?*EmptyStruct = &e;
11 expect(o != null);11 try expect(o != null);
12}12}
1313
14test "equality compare nullable pointers" {14test "equality compare nullable pointers" {
15 testNullPtrsEql();15 try testNullPtrsEql();
16 comptime testNullPtrsEql();16 comptime try testNullPtrsEql();
17}17}
1818
19fn testNullPtrsEql() void {19fn testNullPtrsEql() !void {
20 var number: i32 = 1234;20 var number: i32 = 1234;
2121
22 var x: ?*i32 = null;22 var x: ?*i32 = null;
23 var y: ?*i32 = null;23 var y: ?*i32 = null;
24 expect(x == y);24 try expect(x == y);
25 y = &number;25 y = &number;
26 expect(x != y);26 try expect(x != y);
27 expect(x != &number);27 try expect(x != &number);
28 expect(&number != x);28 try expect(&number != x);
29 x = &number;29 x = &number;
30 expect(x == y);30 try expect(x == y);
31 expect(x == &number);31 try expect(x == &number);
32 expect(&number == x);32 try expect(&number == x);
33}33}
3434
35test "address of unwrap optional" {35test "address of unwrap optional" {
...@@ -46,23 +46,23 @@ test "address of unwrap optional" {...@@ -46,23 +46,23 @@ test "address of unwrap optional" {
46 };46 };
47 S.global = S.Foo{ .a = 1234 };47 S.global = S.Foo{ .a = 1234 };
48 const foo = S.getFoo() catch unreachable;48 const foo = S.getFoo() catch unreachable;
49 expect(foo.a == 1234);49 try expect(foo.a == 1234);
50}50}
5151
52test "equality compare optional with non-optional" {52test "equality compare optional with non-optional" {
53 test_cmp_optional_non_optional();53 try test_cmp_optional_non_optional();
54 comptime test_cmp_optional_non_optional();54 comptime try test_cmp_optional_non_optional();
55}55}
5656
57fn test_cmp_optional_non_optional() void {57fn test_cmp_optional_non_optional() !void {
58 var ten: i32 = 10;58 var ten: i32 = 10;
59 var opt_ten: ?i32 = 10;59 var opt_ten: ?i32 = 10;
60 var five: i32 = 5;60 var five: i32 = 5;
61 var int_n: ?i32 = null;61 var int_n: ?i32 = null;
6262
63 expect(int_n != ten);63 try expect(int_n != ten);
64 expect(opt_ten == ten);64 try expect(opt_ten == ten);
65 expect(opt_ten != five);65 try expect(opt_ten != five);
6666
67 // test evaluation is always lexical67 // test evaluation is always lexical
68 // ensure that the optional isn't always computed before the non-optional68 // ensure that the optional isn't always computed before the non-optional
...@@ -71,14 +71,14 @@ fn test_cmp_optional_non_optional() void {...@@ -71,14 +71,14 @@ fn test_cmp_optional_non_optional() void {
71 mutable_state += 1;71 mutable_state += 1;
72 break :blk1 @as(?f64, 10.0);72 break :blk1 @as(?f64, 10.0);
73 } != blk2: {73 } != blk2: {
74 expect(mutable_state == 1);74 try expect(mutable_state == 1);
75 break :blk2 @as(f64, 5.0);75 break :blk2 @as(f64, 5.0);
76 };76 };
77 _ = blk1: {77 _ = blk1: {
78 mutable_state += 1;78 mutable_state += 1;
79 break :blk1 @as(f64, 10.0);79 break :blk1 @as(f64, 10.0);
80 } != blk2: {80 } != blk2: {
81 expect(mutable_state == 2);81 try expect(mutable_state == 2);
82 break :blk2 @as(?f64, 5.0);82 break :blk2 @as(?f64, 5.0);
83 };83 };
84}84}
...@@ -94,15 +94,15 @@ test "passing an optional integer as a parameter" {...@@ -94,15 +94,15 @@ test "passing an optional integer as a parameter" {
94 return x.? == 1234;94 return x.? == 1234;
95 }95 }
96 };96 };
97 expect(S.entry());97 try expect(S.entry());
98 comptime expect(S.entry());98 comptime try expect(S.entry());
99}99}
100100
101test "unwrap function call with optional pointer return value" {101test "unwrap function call with optional pointer return value" {
102 const S = struct {102 const S = struct {
103 fn entry() void {103 fn entry() !void {
104 expect(foo().?.* == 1234);104 try expect(foo().?.* == 1234);
105 expect(bar() == null);105 try expect(bar() == null);
106 }106 }
107 const global: i32 = 1234;107 const global: i32 = 1234;
108 fn foo() ?*const i32 {108 fn foo() ?*const i32 {
...@@ -112,14 +112,14 @@ test "unwrap function call with optional pointer return value" {...@@ -112,14 +112,14 @@ test "unwrap function call with optional pointer return value" {
112 return null;112 return null;
113 }113 }
114 };114 };
115 S.entry();115 try S.entry();
116 comptime S.entry();116 comptime try S.entry();
117}117}
118118
119test "nested orelse" {119test "nested orelse" {
120 const S = struct {120 const S = struct {
121 fn entry() void {121 fn entry() !void {
122 expect(func() == null);122 try expect(func() == null);
123 }123 }
124 fn maybe() ?Foo {124 fn maybe() ?Foo {
125 return null;125 return null;
...@@ -134,8 +134,8 @@ test "nested orelse" {...@@ -134,8 +134,8 @@ test "nested orelse" {
134 field: i32,134 field: i32,
135 };135 };
136 };136 };
137 S.entry();137 try S.entry();
138 comptime S.entry();138 comptime try S.entry();
139}139}
140140
141test "self-referential struct through a slice of optional" {141test "self-referential struct through a slice of optional" {
...@@ -154,7 +154,7 @@ test "self-referential struct through a slice of optional" {...@@ -154,7 +154,7 @@ test "self-referential struct through a slice of optional" {
154 };154 };
155155
156 var n = S.Node.new();156 var n = S.Node.new();
157 expect(n.data == null);157 try expect(n.data == null);
158}158}
159159
160test "assigning to an unwrapped optional field in an inline loop" {160test "assigning to an unwrapped optional field in an inline loop" {
...@@ -173,14 +173,14 @@ test "coerce an anon struct literal to optional struct" {...@@ -173,14 +173,14 @@ test "coerce an anon struct literal to optional struct" {
173 const Struct = struct {173 const Struct = struct {
174 field: u32,174 field: u32,
175 };175 };
176 export fn doTheTest() void {176 fn doTheTest() !void {
177 var maybe_dims: ?Struct = null;177 var maybe_dims: ?Struct = null;
178 maybe_dims = .{ .field = 1 };178 maybe_dims = .{ .field = 1 };
179 expect(maybe_dims.?.field == 1);179 try expect(maybe_dims.?.field == 1);
180 }180 }
181 };181 };
182 S.doTheTest();182 try S.doTheTest();
183 comptime S.doTheTest();183 comptime try S.doTheTest();
184}184}
185185
186test "optional with void type" {186test "optional with void type" {
...@@ -188,15 +188,15 @@ test "optional with void type" {...@@ -188,15 +188,15 @@ test "optional with void type" {
188 x: ?void,188 x: ?void,
189 };189 };
190 var x = Foo{ .x = null };190 var x = Foo{ .x = null };
191 expect(x.x == null);191 try expect(x.x == null);
192}192}
193193
194test "0-bit child type coerced to optional return ptr result location" {194test "0-bit child type coerced to optional return ptr result location" {
195 const S = struct {195 const S = struct {
196 fn doTheTest() void {196 fn doTheTest() !void {
197 var y = Foo{};197 var y = Foo{};
198 var z = y.thing();198 var z = y.thing();
199 expect(z != null);199 try expect(z != null);
200 }200 }
201201
202 const Foo = struct {202 const Foo = struct {
...@@ -209,17 +209,17 @@ test "0-bit child type coerced to optional return ptr result location" {...@@ -209,17 +209,17 @@ test "0-bit child type coerced to optional return ptr result location" {
209 }209 }
210 };210 };
211 };211 };
212 S.doTheTest();212 try S.doTheTest();
213 comptime S.doTheTest();213 comptime try S.doTheTest();
214}214}
215215
216test "0-bit child type coerced to optional" {216test "0-bit child type coerced to optional" {
217 const S = struct {217 const S = struct {
218 fn doTheTest() void {218 fn doTheTest() !void {
219 var it: Foo = .{219 var it: Foo = .{
220 .list = undefined,220 .list = undefined,
221 };221 };
222 expect(it.foo() != null);222 try expect(it.foo() != null);
223 }223 }
224224
225 const Empty = struct {};225 const Empty = struct {};
...@@ -232,8 +232,8 @@ test "0-bit child type coerced to optional" {...@@ -232,8 +232,8 @@ test "0-bit child type coerced to optional" {
232 }232 }
233 };233 };
234 };234 };
235 S.doTheTest();235 try S.doTheTest();
236 comptime S.doTheTest();236 comptime try S.doTheTest();
237}237}
238238
239test "array of optional unaligned types" {239test "array of optional unaligned types" {
...@@ -255,15 +255,15 @@ test "array of optional unaligned types" {...@@ -255,15 +255,15 @@ test "array of optional unaligned types" {
255255
256 // The index must be a runtime value256 // The index must be a runtime value
257 var i: usize = 0;257 var i: usize = 0;
258 expectEqual(Enum.one, values[i].?.Num);258 try expectEqual(Enum.one, values[i].?.Num);
259 i += 1;259 i += 1;
260 expectEqual(Enum.two, values[i].?.Num);260 try expectEqual(Enum.two, values[i].?.Num);
261 i += 1;261 i += 1;
262 expectEqual(Enum.three, values[i].?.Num);262 try expectEqual(Enum.three, values[i].?.Num);
263 i += 1;263 i += 1;
264 expectEqual(Enum.one, values[i].?.Num);264 try expectEqual(Enum.one, values[i].?.Num);
265 i += 1;265 i += 1;
266 expectEqual(Enum.two, values[i].?.Num);266 try expectEqual(Enum.two, values[i].?.Num);
267 i += 1;267 i += 1;
268 expectEqual(Enum.three, values[i].?.Num);268 try expectEqual(Enum.three, values[i].?.Num);
269}269}
test/behavior/pointers.zig+108-108
...@@ -4,15 +4,15 @@ const expect = testing.expect;...@@ -4,15 +4,15 @@ const expect = testing.expect;
4const expectError = testing.expectError;4const expectError = testing.expectError;
55
6test "dereference pointer" {6test "dereference pointer" {
7 comptime testDerefPtr();7 comptime try testDerefPtr();
8 testDerefPtr();8 try testDerefPtr();
9}9}
1010
11fn testDerefPtr() void {11fn testDerefPtr() !void {
12 var x: i32 = 1234;12 var x: i32 = 1234;
13 var y = &x;13 var y = &x;
14 y.* += 1;14 y.* += 1;
15 expect(x == 1235);15 try expect(x == 1235);
16}16}
1717
18const Foo1 = struct {18const Foo1 = struct {
...@@ -20,41 +20,41 @@ const Foo1 = struct {...@@ -20,41 +20,41 @@ const Foo1 = struct {
20};20};
2121
22test "dereference pointer again" {22test "dereference pointer again" {
23 testDerefPtrOneVal();23 try testDerefPtrOneVal();
24 comptime testDerefPtrOneVal();24 comptime try testDerefPtrOneVal();
25}25}
2626
27fn testDerefPtrOneVal() void {27fn testDerefPtrOneVal() !void {
28 // Foo1 satisfies the OnePossibleValueYes criteria28 // Foo1 satisfies the OnePossibleValueYes criteria
29 const x = &Foo1{ .x = {} };29 const x = &Foo1{ .x = {} };
30 const y = x.*;30 const y = x.*;
31 expect(@TypeOf(y.x) == void);31 try expect(@TypeOf(y.x) == void);
32}32}
3333
34test "pointer arithmetic" {34test "pointer arithmetic" {
35 var ptr: [*]const u8 = "abcd";35 var ptr: [*]const u8 = "abcd";
3636
37 expect(ptr[0] == 'a');37 try expect(ptr[0] == 'a');
38 ptr += 1;38 ptr += 1;
39 expect(ptr[0] == 'b');39 try expect(ptr[0] == 'b');
40 ptr += 1;40 ptr += 1;
41 expect(ptr[0] == 'c');41 try expect(ptr[0] == 'c');
42 ptr += 1;42 ptr += 1;
43 expect(ptr[0] == 'd');43 try expect(ptr[0] == 'd');
44 ptr += 1;44 ptr += 1;
45 expect(ptr[0] == 0);45 try expect(ptr[0] == 0);
46 ptr -= 1;46 ptr -= 1;
47 expect(ptr[0] == 'd');47 try expect(ptr[0] == 'd');
48 ptr -= 1;48 ptr -= 1;
49 expect(ptr[0] == 'c');49 try expect(ptr[0] == 'c');
50 ptr -= 1;50 ptr -= 1;
51 expect(ptr[0] == 'b');51 try expect(ptr[0] == 'b');
52 ptr -= 1;52 ptr -= 1;
53 expect(ptr[0] == 'a');53 try expect(ptr[0] == 'a');
54}54}
5555
56test "double pointer parsing" {56test "double pointer parsing" {
57 comptime expect(PtrOf(PtrOf(i32)) == **i32);57 comptime try expect(PtrOf(PtrOf(i32)) == **i32);
58}58}
5959
60fn PtrOf(comptime T: type) type {60fn PtrOf(comptime T: type) type {
...@@ -72,33 +72,33 @@ test "implicit cast single item pointer to C pointer and back" {...@@ -72,33 +72,33 @@ test "implicit cast single item pointer to C pointer and back" {
72 var x: [*c]u8 = &y;72 var x: [*c]u8 = &y;
73 var z: *u8 = x;73 var z: *u8 = x;
74 z.* += 1;74 z.* += 1;
75 expect(y == 12);75 try expect(y == 12);
76}76}
7777
78test "C pointer comparison and arithmetic" {78test "C pointer comparison and arithmetic" {
79 const S = struct {79 const S = struct {
80 fn doTheTest() void {80 fn doTheTest() !void {
81 var one: usize = 1;81 var one: usize = 1;
82 var ptr1: [*c]u32 = 0;82 var ptr1: [*c]u32 = 0;
83 var ptr2 = ptr1 + 10;83 var ptr2 = ptr1 + 10;
84 expect(ptr1 == 0);84 try expect(ptr1 == 0);
85 expect(ptr1 >= 0);85 try expect(ptr1 >= 0);
86 expect(ptr1 <= 0);86 try expect(ptr1 <= 0);
87 // expect(ptr1 < 1);87 // expect(ptr1 < 1);
88 // expect(ptr1 < one);88 // expect(ptr1 < one);
89 // expect(1 > ptr1);89 // expect(1 > ptr1);
90 // expect(one > ptr1);90 // expect(one > ptr1);
91 expect(ptr1 < ptr2);91 try expect(ptr1 < ptr2);
92 expect(ptr2 > ptr1);92 try expect(ptr2 > ptr1);
93 expect(ptr2 >= 40);93 try expect(ptr2 >= 40);
94 expect(ptr2 == 40);94 try expect(ptr2 == 40);
95 expect(ptr2 <= 40);95 try expect(ptr2 <= 40);
96 ptr2 -= 10;96 ptr2 -= 10;
97 expect(ptr1 == ptr2);97 try expect(ptr1 == ptr2);
98 }98 }
99 };99 };
100 S.doTheTest();100 try S.doTheTest();
101 comptime S.doTheTest();101 comptime try S.doTheTest();
102}102}
103103
104test "peer type resolution with C pointers" {104test "peer type resolution with C pointers" {
...@@ -110,10 +110,10 @@ test "peer type resolution with C pointers" {...@@ -110,10 +110,10 @@ test "peer type resolution with C pointers" {
110 var x2 = if (t) ptr_many else ptr_c;110 var x2 = if (t) ptr_many else ptr_c;
111 var x3 = if (t) ptr_c else ptr_one;111 var x3 = if (t) ptr_c else ptr_one;
112 var x4 = if (t) ptr_c else ptr_many;112 var x4 = if (t) ptr_c else ptr_many;
113 expect(@TypeOf(x1) == [*c]u8);113 try expect(@TypeOf(x1) == [*c]u8);
114 expect(@TypeOf(x2) == [*c]u8);114 try expect(@TypeOf(x2) == [*c]u8);
115 expect(@TypeOf(x3) == [*c]u8);115 try expect(@TypeOf(x3) == [*c]u8);
116 expect(@TypeOf(x4) == [*c]u8);116 try expect(@TypeOf(x4) == [*c]u8);
117}117}
118118
119test "implicit casting between C pointer and optional non-C pointer" {119test "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" {...@@ -121,15 +121,15 @@ test "implicit casting between C pointer and optional non-C pointer" {
121 const opt_many_ptr: ?[*]const u8 = slice.ptr;121 const opt_many_ptr: ?[*]const u8 = slice.ptr;
122 var ptr_opt_many_ptr = &opt_many_ptr;122 var ptr_opt_many_ptr = &opt_many_ptr;
123 var c_ptr: [*c]const [*c]const u8 = ptr_opt_many_ptr;123 var c_ptr: [*c]const [*c]const u8 = ptr_opt_many_ptr;
124 expect(c_ptr.*.* == 'a');124 try expect(c_ptr.*.* == 'a');
125 ptr_opt_many_ptr = c_ptr;125 ptr_opt_many_ptr = c_ptr;
126 expect(ptr_opt_many_ptr.*.?[1] == 'o');126 try expect(ptr_opt_many_ptr.*.?[1] == 'o');
127}127}
128128
129test "implicit cast error unions with non-optional to optional pointer" {129test "implicit cast error unions with non-optional to optional pointer" {
130 const S = struct {130 const S = struct {
131 fn doTheTest() void {131 fn doTheTest() !void {
132 expectError(error.Fail, foo());132 try expectError(error.Fail, foo());
133 }133 }
134 fn foo() anyerror!?*u8 {134 fn foo() anyerror!?*u8 {
135 return bar() orelse error.Fail;135 return bar() orelse error.Fail;
...@@ -138,111 +138,111 @@ test "implicit cast error unions with non-optional to optional pointer" {...@@ -138,111 +138,111 @@ test "implicit cast error unions with non-optional to optional pointer" {
138 return null;138 return null;
139 }139 }
140 };140 };
141 S.doTheTest();141 try S.doTheTest();
142 comptime S.doTheTest();142 comptime try S.doTheTest();
143}143}
144144
145test "initialize const optional C pointer to null" {145test "initialize const optional C pointer to null" {
146 const a: ?[*c]i32 = null;146 const a: ?[*c]i32 = null;
147 expect(a == null);147 try expect(a == null);
148 comptime expect(a == null);148 comptime try expect(a == null);
149}149}
150150
151test "compare equality of optional and non-optional pointer" {151test "compare equality of optional and non-optional pointer" {
152 const a = @intToPtr(*const usize, 0x12345678);152 const a = @intToPtr(*const usize, 0x12345678);
153 const b = @intToPtr(?*usize, 0x12345678);153 const b = @intToPtr(?*usize, 0x12345678);
154 expect(a == b);154 try expect(a == b);
155 expect(b == a);155 try expect(b == a);
156}156}
157157
158test "allowzero pointer and slice" {158test "allowzero pointer and slice" {
159 var ptr = @intToPtr([*]allowzero i32, 0);159 var ptr = @intToPtr([*]allowzero i32, 0);
160 var opt_ptr: ?[*]allowzero i32 = ptr;160 var opt_ptr: ?[*]allowzero i32 = ptr;
161 expect(opt_ptr != null);161 try expect(opt_ptr != null);
162 expect(@ptrToInt(ptr) == 0);162 try expect(@ptrToInt(ptr) == 0);
163 var runtime_zero: usize = 0;163 var runtime_zero: usize = 0;
164 var slice = ptr[runtime_zero..10];164 var slice = ptr[runtime_zero..10];
165 comptime expect(@TypeOf(slice) == []allowzero i32);165 comptime try expect(@TypeOf(slice) == []allowzero i32);
166 expect(@ptrToInt(&slice[5]) == 20);166 try expect(@ptrToInt(&slice[5]) == 20);
167167
168 comptime expect(@typeInfo(@TypeOf(ptr)).Pointer.is_allowzero);168 comptime try expect(@typeInfo(@TypeOf(ptr)).Pointer.is_allowzero);
169 comptime expect(@typeInfo(@TypeOf(slice)).Pointer.is_allowzero);169 comptime try expect(@typeInfo(@TypeOf(slice)).Pointer.is_allowzero);
170}170}
171171
172test "assign null directly to C pointer and test null equality" {172test "assign null directly to C pointer and test null equality" {
173 var x: [*c]i32 = null;173 var x: [*c]i32 = null;
174 expect(x == null);174 try expect(x == null);
175 expect(null == x);175 try expect(null == x);
176 expect(!(x != null));176 try expect(!(x != null));
177 expect(!(null != x));177 try expect(!(null != x));
178 if (x) |same_x| {178 if (x) |same_x| {
179 @panic("fail");179 @panic("fail");
180 }180 }
181 var otherx: i32 = undefined;181 var otherx: i32 = undefined;
182 expect((x orelse &otherx) == &otherx);182 try expect((x orelse &otherx) == &otherx);
183183
184 const y: [*c]i32 = null;184 const y: [*c]i32 = null;
185 comptime expect(y == null);185 comptime try expect(y == null);
186 comptime expect(null == y);186 comptime try expect(null == y);
187 comptime expect(!(y != null));187 comptime try expect(!(y != null));
188 comptime expect(!(null != y));188 comptime try expect(!(null != y));
189 if (y) |same_y| @panic("fail");189 if (y) |same_y| @panic("fail");
190 const othery: i32 = undefined;190 const othery: i32 = undefined;
191 comptime expect((y orelse &othery) == &othery);191 comptime try expect((y orelse &othery) == &othery);
192192
193 var n: i32 = 1234;193 var n: i32 = 1234;
194 var x1: [*c]i32 = &n;194 var x1: [*c]i32 = &n;
195 expect(!(x1 == null));195 try expect(!(x1 == null));
196 expect(!(null == x1));196 try expect(!(null == x1));
197 expect(x1 != null);197 try expect(x1 != null);
198 expect(null != x1);198 try expect(null != x1);
199 expect(x1.?.* == 1234);199 try expect(x1.?.* == 1234);
200 if (x1) |same_x1| {200 if (x1) |same_x1| {
201 expect(same_x1.* == 1234);201 try expect(same_x1.* == 1234);
202 } else {202 } else {
203 @panic("fail");203 @panic("fail");
204 }204 }
205 expect((x1 orelse &otherx) == x1);205 try expect((x1 orelse &otherx) == x1);
206206
207 const nc: i32 = 1234;207 const nc: i32 = 1234;
208 const y1: [*c]const i32 = &nc;208 const y1: [*c]const i32 = &nc;
209 comptime expect(!(y1 == null));209 comptime try expect(!(y1 == null));
210 comptime expect(!(null == y1));210 comptime try expect(!(null == y1));
211 comptime expect(y1 != null);211 comptime try expect(y1 != null);
212 comptime expect(null != y1);212 comptime try expect(null != y1);
213 comptime expect(y1.?.* == 1234);213 comptime try expect(y1.?.* == 1234);
214 if (y1) |same_y1| {214 if (y1) |same_y1| {
215 expect(same_y1.* == 1234);215 try expect(same_y1.* == 1234);
216 } else {216 } else {
217 @compileError("fail");217 @compileError("fail");
218 }218 }
219 comptime expect((y1 orelse &othery) == y1);219 comptime try expect((y1 orelse &othery) == y1);
220}220}
221221
222test "null terminated pointer" {222test "null terminated pointer" {
223 const S = struct {223 const S = struct {
224 fn doTheTest() void {224 fn doTheTest() !void {
225 var array_with_zero = [_:0]u8{ 'h', 'e', 'l', 'l', 'o' };225 var array_with_zero = [_:0]u8{ 'h', 'e', 'l', 'l', 'o' };
226 var zero_ptr: [*:0]const u8 = @ptrCast([*:0]const u8, &array_with_zero);226 var zero_ptr: [*:0]const u8 = @ptrCast([*:0]const u8, &array_with_zero);
227 var no_zero_ptr: [*]const u8 = zero_ptr;227 var no_zero_ptr: [*]const u8 = zero_ptr;
228 var zero_ptr_again = @ptrCast([*:0]const u8, no_zero_ptr);228 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"));
230 }230 }
231 };231 };
232 S.doTheTest();232 try S.doTheTest();
233 comptime S.doTheTest();233 comptime try S.doTheTest();
234}234}
235235
236test "allow any sentinel" {236test "allow any sentinel" {
237 const S = struct {237 const S = struct {
238 fn doTheTest() void {238 fn doTheTest() !void {
239 var array = [_:std.math.minInt(i32)]i32{ 1, 2, 3, 4 };239 var array = [_:std.math.minInt(i32)]i32{ 1, 2, 3, 4 };
240 var ptr: [*:std.math.minInt(i32)]i32 = &array;240 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));
242 }242 }
243 };243 };
244 S.doTheTest();244 try S.doTheTest();
245 comptime S.doTheTest();245 comptime try S.doTheTest();
246}246}
247247
248test "pointer sentinel with enums" {248test "pointer sentinel with enums" {
...@@ -253,42 +253,42 @@ test "pointer sentinel with enums" {...@@ -253,42 +253,42 @@ test "pointer sentinel with enums" {
253 sentinel,253 sentinel,
254 };254 };
255255
256 fn doTheTest() void {256 fn doTheTest() !void {
257 var ptr: [*:.sentinel]const Number = &[_:.sentinel]Number{ .one, .two, .two, .one };257 var ptr: [*:.sentinel]const Number = &[_:.sentinel]Number{ .one, .two, .two, .one };
258 expect(ptr[4] == .sentinel); // TODO this should be comptime expect, see #3731258 try expect(ptr[4] == .sentinel); // TODO this should be comptime try expect, see #3731
259 }259 }
260 };260 };
261 S.doTheTest();261 try S.doTheTest();
262 comptime S.doTheTest();262 comptime try S.doTheTest();
263}263}
264264
265test "pointer sentinel with optional element" {265test "pointer sentinel with optional element" {
266 const S = struct {266 const S = struct {
267 fn doTheTest() void {267 fn doTheTest() !void {
268 var ptr: [*:null]const ?i32 = &[_:null]?i32{ 1, 2, 3, 4 };268 var ptr: [*:null]const ?i32 = &[_:null]?i32{ 1, 2, 3, 4 };
269 expect(ptr[4] == null); // TODO this should be comptime expect, see #3731269 try expect(ptr[4] == null); // TODO this should be comptime try expect, see #3731
270 }270 }
271 };271 };
272 S.doTheTest();272 try S.doTheTest();
273 comptime S.doTheTest();273 comptime try S.doTheTest();
274}274}
275275
276test "pointer sentinel with +inf" {276test "pointer sentinel with +inf" {
277 const S = struct {277 const S = struct {
278 fn doTheTest() void {278 fn doTheTest() !void {
279 const inf = std.math.inf_f32;279 const inf = std.math.inf_f32;
280 var ptr: [*:inf]const f32 = &[_:inf]f32{ 1.1, 2.2, 3.3, 4.4 };280 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 #3731281 try expect(ptr[4] == inf); // TODO this should be comptime try expect, see #3731
282 }282 }
283 };283 };
284 S.doTheTest();284 try S.doTheTest();
285 comptime S.doTheTest();285 comptime try S.doTheTest();
286}286}
287287
288test "pointer to array at fixed address" {288test "pointer to array at fixed address" {
289 const array = @intToPtr(*volatile [1]u32, 0x10);289 const array = @intToPtr(*volatile [1]u32, 0x10);
290 // Silly check just to reference `array`290 // Silly check just to reference `array`
291 expect(@ptrToInt(&array[0]) == 0x10);291 try expect(@ptrToInt(&array[0]) == 0x10);
292}292}
293293
294test "pointer arithmetic affects the alignment" {294test "pointer arithmetic affects the alignment" {
...@@ -296,28 +296,28 @@ test "pointer arithmetic affects the alignment" {...@@ -296,28 +296,28 @@ test "pointer arithmetic affects the alignment" {
296 var ptr: [*]align(8) u32 = undefined;296 var ptr: [*]align(8) u32 = undefined;
297 var x: usize = 1;297 var x: usize = 1;
298298
299 expect(@typeInfo(@TypeOf(ptr)).Pointer.alignment == 8);299 try expect(@typeInfo(@TypeOf(ptr)).Pointer.alignment == 8);
300 const ptr1 = ptr + 1; // 1 * 4 = 4 -> lcd(4,8) = 4300 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);
302 const ptr2 = ptr + 4; // 4 * 4 = 16 -> lcd(16,8) = 8302 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);
304 const ptr3 = ptr + 0; // no-op304 const ptr3 = ptr + 0; // no-op
305 expect(@typeInfo(@TypeOf(ptr3)).Pointer.alignment == 8);305 try expect(@typeInfo(@TypeOf(ptr3)).Pointer.alignment == 8);
306 const ptr4 = ptr + x; // runtime-known addend306 const ptr4 = ptr + x; // runtime-known addend
307 expect(@typeInfo(@TypeOf(ptr4)).Pointer.alignment == 4);307 try expect(@typeInfo(@TypeOf(ptr4)).Pointer.alignment == 4);
308 }308 }
309 {309 {
310 var ptr: [*]align(8) [3]u8 = undefined;310 var ptr: [*]align(8) [3]u8 = undefined;
311 var x: usize = 1;311 var x: usize = 1;
312312
313 const ptr1 = ptr + 17; // 3 * 17 = 51313 const ptr1 = ptr + 17; // 3 * 17 = 51
314 expect(@typeInfo(@TypeOf(ptr1)).Pointer.alignment == 1);314 try expect(@typeInfo(@TypeOf(ptr1)).Pointer.alignment == 1);
315 const ptr2 = ptr + x; // runtime-known addend315 const ptr2 = ptr + x; // runtime-known addend
316 expect(@typeInfo(@TypeOf(ptr2)).Pointer.alignment == 1);316 try expect(@typeInfo(@TypeOf(ptr2)).Pointer.alignment == 1);
317 const ptr3 = ptr + 8; // 3 * 8 = 24 -> lcd(8,24) = 8317 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);
319 const ptr4 = ptr + 4; // 3 * 4 = 12 -> lcd(8,12) = 4319 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);
321 }321 }
322}322}
323323
...@@ -325,15 +325,15 @@ test "@ptrToInt on null optional at comptime" {...@@ -325,15 +325,15 @@ test "@ptrToInt on null optional at comptime" {
325 {325 {
326 const pointer = @intToPtr(?*u8, 0x000);326 const pointer = @intToPtr(?*u8, 0x000);
327 const x = @ptrToInt(pointer);327 const x = @ptrToInt(pointer);
328 comptime expect(0 == @ptrToInt(pointer));328 comptime try expect(0 == @ptrToInt(pointer));
329 }329 }
330 {330 {
331 const pointer = @intToPtr(?*u8, 0xf00);331 const pointer = @intToPtr(?*u8, 0xf00);
332 comptime expect(0xf00 == @ptrToInt(pointer));332 comptime try expect(0xf00 == @ptrToInt(pointer));
333 }333 }
334}334}
335335
336test "indexing array with sentinel returns correct type" {336test "indexing array with sentinel returns correct type" {
337 var s: [:0]const u8 = "abc";337 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])));
339}339}
test/behavior/popcount.zig+12-12
...@@ -1,43 +1,43 @@...@@ -1,43 +1,43 @@
1const expect = @import("std").testing.expect;1const expect = @import("std").testing.expect;
22
3test "@popCount" {3test "@popCount" {
4 comptime testPopCount();4 comptime try testPopCount();
5 testPopCount();5 try testPopCount();
6}6}
77
8fn testPopCount() void {8fn testPopCount() !void {
9 {9 {
10 var x: u32 = 0xffffffff;10 var x: u32 = 0xffffffff;
11 expect(@popCount(u32, x) == 32);11 try expect(@popCount(u32, x) == 32);
12 }12 }
13 {13 {
14 var x: u5 = 0x1f;14 var x: u5 = 0x1f;
15 expect(@popCount(u5, x) == 5);15 try expect(@popCount(u5, x) == 5);
16 }16 }
17 {17 {
18 var x: u32 = 0xaa;18 var x: u32 = 0xaa;
19 expect(@popCount(u32, x) == 4);19 try expect(@popCount(u32, x) == 4);
20 }20 }
21 {21 {
22 var x: u32 = 0xaaaaaaaa;22 var x: u32 = 0xaaaaaaaa;
23 expect(@popCount(u32, x) == 16);23 try expect(@popCount(u32, x) == 16);
24 }24 }
25 {25 {
26 var x: u32 = 0xaaaaaaaa;26 var x: u32 = 0xaaaaaaaa;
27 expect(@popCount(u32, x) == 16);27 try expect(@popCount(u32, x) == 16);
28 }28 }
29 {29 {
30 var x: i16 = -1;30 var x: i16 = -1;
31 expect(@popCount(i16, x) == 16);31 try expect(@popCount(i16, x) == 16);
32 }32 }
33 {33 {
34 var x: i8 = -120;34 var x: i8 = -120;
35 expect(@popCount(i8, x) == 2);35 try expect(@popCount(i8, x) == 2);
36 }36 }
37 comptime {37 comptime {
38 expect(@popCount(u8, @bitCast(u8, @as(i8, -120))) == 2);38 try expect(@popCount(u8, @bitCast(u8, @as(i8, -120))) == 2);
39 }39 }
40 comptime {40 comptime {
41 expect(@popCount(i128, 0b11111111000110001100010000100001000011000011100101010001) == 24);41 try expect(@popCount(i128, 0b11111111000110001100010000100001000011000011100101010001) == 24);
42 }42 }
43}43}
test/behavior/ptrcast.zig+12-12
...@@ -4,25 +4,25 @@ const expect = std.testing.expect;...@@ -4,25 +4,25 @@ const expect = std.testing.expect;
4const native_endian = builtin.target.cpu.arch.endian();4const native_endian = builtin.target.cpu.arch.endian();
55
6test "reinterpret bytes as integer with nonzero offset" {6test "reinterpret bytes as integer with nonzero offset" {
7 testReinterpretBytesAsInteger();7 try testReinterpretBytesAsInteger();
8 comptime testReinterpretBytesAsInteger();8 comptime try testReinterpretBytesAsInteger();
9}9}
1010
11fn testReinterpretBytesAsInteger() void {11fn testReinterpretBytesAsInteger() !void {
12 const bytes = "\x12\x34\x56\x78\xab";12 const bytes = "\x12\x34\x56\x78\xab";
13 const expected = switch (native_endian) {13 const expected = switch (native_endian) {
14 .Little => 0xab785634,14 .Little => 0xab785634,
15 .Big => 0x345678ab,15 .Big => 0x345678ab,
16 };16 };
17 expect(@ptrCast(*align(1) const u32, bytes[1..5]).* == expected);17 try expect(@ptrCast(*align(1) const u32, bytes[1..5]).* == expected);
18}18}
1919
20test "reinterpret bytes of an array into an extern struct" {20test "reinterpret bytes of an array into an extern struct" {
21 testReinterpretBytesAsExternStruct();21 try testReinterpretBytesAsExternStruct();
22 comptime testReinterpretBytesAsExternStruct();22 comptime try testReinterpretBytesAsExternStruct();
23}23}
2424
25fn testReinterpretBytesAsExternStruct() void {25fn testReinterpretBytesAsExternStruct() !void {
26 var bytes align(2) = [_]u8{ 1, 2, 3, 4, 5, 6 };26 var bytes align(2) = [_]u8{ 1, 2, 3, 4, 5, 6 };
2727
28 const S = extern struct {28 const S = extern struct {
...@@ -33,15 +33,15 @@ fn testReinterpretBytesAsExternStruct() void {...@@ -33,15 +33,15 @@ fn testReinterpretBytesAsExternStruct() void {
3333
34 var ptr = @ptrCast(*const S, &bytes);34 var ptr = @ptrCast(*const S, &bytes);
35 var val = ptr.c;35 var val = ptr.c;
36 expect(val == 5);36 try expect(val == 5);
37}37}
3838
39test "reinterpret struct field at comptime" {39test "reinterpret struct field at comptime" {
40 const numNative = comptime Bytes.init(0x12345678);40 const numNative = comptime Bytes.init(0x12345678);
41 if (native_endian != .Little) {41 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));
43 } else {43 } 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));
45 }45 }
46}46}
4747
...@@ -60,7 +60,7 @@ test "comptime ptrcast keeps larger alignment" {...@@ -60,7 +60,7 @@ test "comptime ptrcast keeps larger alignment" {
60 comptime {60 comptime {
61 const a: u32 = 1234;61 const a: u32 = 1234;
62 const p = @ptrCast([*]const u8, &a);62 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);
64 }64 }
65}65}
6666
...@@ -69,5 +69,5 @@ test "implicit optional pointer to optional c_void pointer" {...@@ -69,5 +69,5 @@ test "implicit optional pointer to optional c_void pointer" {
69 var x: ?[*]u8 = &buf;69 var x: ?[*]u8 = &buf;
70 var y: ?*c_void = x;70 var y: ?*c_void = x;
71 var z = @ptrCast(*[4]u8, y);71 var z = @ptrCast(*[4]u8, y);
72 expect(std.mem.eql(u8, z, "aoeu"));72 try expect(std.mem.eql(u8, z, "aoeu"));
73}73}
test/behavior/pub_enum.zig+4-4
...@@ -2,12 +2,12 @@ const other = @import("pub_enum/other.zig");...@@ -2,12 +2,12 @@ const other = @import("pub_enum/other.zig");
2const expect = @import("std").testing.expect;2const expect = @import("std").testing.expect;
33
4test "pub enum" {4test "pub enum" {
5 pubEnumTest(other.APubEnum.Two);5 try pubEnumTest(other.APubEnum.Two);
6}6}
7fn pubEnumTest(foo: other.APubEnum) void {7fn pubEnumTest(foo: other.APubEnum) !void {
8 expect(foo == other.APubEnum.Two);8 try expect(foo == other.APubEnum.Two);
9}9}
1010
11test "cast with imported symbol" {11test "cast with imported symbol" {
12 expect(@as(other.size_t, 42) == 42);12 try expect(@as(other.size_t, 42) == 42);
13}13}
test/behavior/ref_var_in_if_after_if_2nd_switch_prong.zig+10-10
...@@ -3,12 +3,12 @@ const mem = @import("std").mem;...@@ -3,12 +3,12 @@ const mem = @import("std").mem;
33
4var ok: bool = false;4var ok: bool = false;
5test "reference a variable in an if after an if in the 2nd switch prong" {5test "reference a variable in an if after an if in the 2nd switch prong" {
6 foo(true, Num.Two, false, "aoeu");6 try foo(true, Num.Two, false, "aoeu");
7 expect(!ok);7 try expect(!ok);
8 foo(false, Num.One, false, "aoeu");8 try foo(false, Num.One, false, "aoeu");
9 expect(!ok);9 try expect(!ok);
10 foo(true, Num.One, false, "aoeu");10 try foo(true, Num.One, false, "aoeu");
11 expect(ok);11 try expect(ok);
12}12}
1313
14const Num = enum {14const Num = enum {
...@@ -16,7 +16,7 @@ const Num = enum {...@@ -16,7 +16,7 @@ const Num = enum {
16 Two,16 Two,
17};17};
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 {
20 switch (k) {20 switch (k) {
21 Num.Two => {},21 Num.Two => {},
22 Num.One => {22 Num.One => {
...@@ -25,13 +25,13 @@ fn foo(c: bool, k: Num, c2: bool, b: []const u8) void {...@@ -25,13 +25,13 @@ fn foo(c: bool, k: Num, c2: bool, b: []const u8) void {
2525
26 if (c2) {}26 if (c2) {}
2727
28 a(output_path);28 try a(output_path);
29 }29 }
30 },30 },
31 }31 }
32}32}
3333
34fn a(x: []const u8) void {34fn a(x: []const u8) !void {
35 expect(mem.eql(u8, x, "aoeu"));35 try expect(mem.eql(u8, x, "aoeu"));
36 ok = true;36 ok = true;
37}37}
test/behavior/reflection.zig+17-17
...@@ -5,12 +5,12 @@ const reflection = @This();...@@ -5,12 +5,12 @@ const reflection = @This();
5test "reflection: function return type, var args, and param types" {5test "reflection: function return type, var args, and param types" {
6 comptime {6 comptime {
7 const info = @typeInfo(@TypeOf(dummy)).Fn;7 const info = @typeInfo(@TypeOf(dummy)).Fn;
8 expect(info.return_type.? == i32);8 try expect(info.return_type.? == i32);
9 expect(!info.is_var_args);9 try expect(!info.is_var_args);
10 expect(info.args.len == 3);10 try expect(info.args.len == 3);
11 expect(info.args[0].arg_type.? == bool);11 try expect(info.args[0].arg_type.? == bool);
12 expect(info.args[1].arg_type.? == i32);12 try expect(info.args[1].arg_type.? == i32);
13 expect(info.args[2].arg_type.? == f32);13 try expect(info.args[2].arg_type.? == f32);
14 }14 }
15}15}
1616
...@@ -25,18 +25,18 @@ test "reflection: @field" {...@@ -25,18 +25,18 @@ test "reflection: @field" {
25 .three = void{},25 .three = void{},
26 };26 };
2727
28 expect(f.one == f.one);28 try expect(f.one == f.one);
29 expect(@field(f, "o" ++ "ne") == f.one);29 try expect(@field(f, "o" ++ "ne") == f.one);
30 expect(@field(f, "t" ++ "wo") == f.two);30 try expect(@field(f, "t" ++ "wo") == f.two);
31 expect(@field(f, "th" ++ "ree") == f.three);31 try expect(@field(f, "th" ++ "ree") == f.three);
32 expect(@field(Foo, "const" ++ "ant") == Foo.constant);32 try expect(@field(Foo, "const" ++ "ant") == Foo.constant);
33 expect(@field(Bar, "O" ++ "ne") == Bar.One);33 try expect(@field(Bar, "O" ++ "ne") == Bar.One);
34 expect(@field(Bar, "T" ++ "wo") == Bar.Two);34 try expect(@field(Bar, "T" ++ "wo") == Bar.Two);
35 expect(@field(Bar, "Th" ++ "ree") == Bar.Three);35 try expect(@field(Bar, "Th" ++ "ree") == Bar.Three);
36 expect(@field(Bar, "F" ++ "our") == Bar.Four);36 try expect(@field(Bar, "F" ++ "our") == Bar.Four);
37 expect(@field(reflection, "dum" ++ "my")(true, 1, 2) == dummy(true, 1, 2));37 try expect(@field(reflection, "dum" ++ "my")(true, 1, 2) == dummy(true, 1, 2));
38 @field(f, "o" ++ "ne") = 4;38 @field(f, "o" ++ "ne") = 4;
39 expect(f.one == 4);39 try expect(f.one == 4);
40}40}
4141
42const Foo = struct {42const Foo = struct {
test/behavior/shuffle.zig+10-10
...@@ -9,33 +9,33 @@ test "@shuffle" {...@@ -9,33 +9,33 @@ test "@shuffle" {
9 if (builtin.os.tag == .wasi) return error.SkipZigTest;9 if (builtin.os.tag == .wasi) return error.SkipZigTest;
1010
11 const S = struct {11 const S = struct {
12 fn doTheTest() void {12 fn doTheTest() !void {
13 var v: Vector(4, i32) = [4]i32{ 2147483647, -2, 30, 40 };13 var v: Vector(4, i32) = [4]i32{ 2147483647, -2, 30, 40 };
14 var x: Vector(4, i32) = [4]i32{ 1, 2147483647, 3, 4 };14 var x: Vector(4, i32) = [4]i32{ 1, 2147483647, 3, 4 };
15 const mask: Vector(4, i32) = [4]i32{ 0, ~@as(i32, 2), 3, ~@as(i32, 3) };15 const mask: Vector(4, i32) = [4]i32{ 0, ~@as(i32, 2), 3, ~@as(i32, 3) };
16 var res = @shuffle(i32, v, x, mask);16 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
19 // Implicit cast from array (of mask)19 // Implicit cast from array (of mask)
20 res = @shuffle(i32, v, x, [4]i32{ 0, ~@as(i32, 2), 3, ~@as(i32, 3) });20 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
23 // Undefined23 // Undefined
24 const mask2: Vector(4, i32) = [4]i32{ 3, 1, 2, 0 };24 const mask2: Vector(4, i32) = [4]i32{ 3, 1, 2, 0 };
25 res = @shuffle(i32, v, undefined, mask2);25 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
28 // Upcasting of b28 // Upcasting of b
29 var v2: Vector(2, i32) = [2]i32{ 2147483647, undefined };29 var v2: Vector(2, i32) = [2]i32{ 2147483647, undefined };
30 const mask3: Vector(4, i32) = [4]i32{ ~@as(i32, 0), 2, ~@as(i32, 0), 3 };30 const mask3: Vector(4, i32) = [4]i32{ ~@as(i32, 0), 2, ~@as(i32, 0), 3 };
31 res = @shuffle(i32, x, v2, mask3);31 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
34 // Upcasting of a34 // Upcasting of a
35 var v3: Vector(2, i32) = [2]i32{ 2147483647, -2 };35 var v3: Vector(2, i32) = [2]i32{ 2147483647, -2 };
36 const mask4: Vector(4, i32) = [4]i32{ 0, ~@as(i32, 2), 1, ~@as(i32, 3) };36 const mask4: Vector(4, i32) = [4]i32{ 0, ~@as(i32, 2), 1, ~@as(i32, 3) };
37 res = @shuffle(i32, v3, x, mask4);37 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
40 // bool40 // bool
41 // https://github.com/ziglang/zig/issues/331741 // https://github.com/ziglang/zig/issues/3317
...@@ -44,7 +44,7 @@ test "@shuffle" {...@@ -44,7 +44,7 @@ test "@shuffle" {
44 var v4: Vector(2, bool) = [2]bool{ true, false };44 var v4: Vector(2, bool) = [2]bool{ true, false };
45 const mask5: Vector(4, i32) = [4]i32{ 0, ~@as(i32, 1), 1, 2 };45 const mask5: Vector(4, i32) = [4]i32{ 0, ~@as(i32, 1), 1, 2 };
46 var res2 = @shuffle(bool, x2, v4, mask5);46 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 }));
48 }48 }
4949
50 // TODO re-enable when LLVM codegen is fixed50 // TODO re-enable when LLVM codegen is fixed
...@@ -54,10 +54,10 @@ test "@shuffle" {...@@ -54,10 +54,10 @@ test "@shuffle" {
54 var v4: Vector(2, bool) = [2]bool{ true, false };54 var v4: Vector(2, bool) = [2]bool{ true, false };
55 const mask5: Vector(4, i32) = [4]i32{ 0, ~@as(i32, 1), 1, 2 };55 const mask5: Vector(4, i32) = [4]i32{ 0, ~@as(i32, 1), 1, 2 };
56 var res2 = @shuffle(bool, x2, v4, mask5);56 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 }));
58 }58 }
59 }59 }
60 };60 };
61 S.doTheTest();61 try S.doTheTest();
62 comptime S.doTheTest();62 comptime try S.doTheTest();
63}63}
test/behavior/sizeof_and_typeof.zig+75-75
...@@ -5,7 +5,7 @@ const expectEqual = std.testing.expectEqual;...@@ -5,7 +5,7 @@ const expectEqual = std.testing.expectEqual;
55
6test "@sizeOf and @TypeOf" {6test "@sizeOf and @TypeOf" {
7 const y: @TypeOf(x) = 120;7 const y: @TypeOf(x) = 120;
8 expect(@sizeOf(@TypeOf(y)) == 2);8 try expect(@sizeOf(@TypeOf(y)) == 2);
9}9}
10const x: u16 = 13;10const x: u16 = 13;
11const z: @TypeOf(x) = 19;11const z: @TypeOf(x) = 19;
...@@ -36,27 +36,27 @@ const P = packed struct {...@@ -36,27 +36,27 @@ const P = packed struct {
3636
37test "@byteOffsetOf" {37test "@byteOffsetOf" {
38 // Packed structs have fixed memory layout38 // Packed structs have fixed memory layout
39 expect(@byteOffsetOf(P, "a") == 0);39 try expect(@byteOffsetOf(P, "a") == 0);
40 expect(@byteOffsetOf(P, "b") == 1);40 try expect(@byteOffsetOf(P, "b") == 1);
41 expect(@byteOffsetOf(P, "c") == 5);41 try expect(@byteOffsetOf(P, "c") == 5);
42 expect(@byteOffsetOf(P, "d") == 6);42 try expect(@byteOffsetOf(P, "d") == 6);
43 expect(@byteOffsetOf(P, "e") == 6);43 try expect(@byteOffsetOf(P, "e") == 6);
44 expect(@byteOffsetOf(P, "f") == 7);44 try expect(@byteOffsetOf(P, "f") == 7);
45 expect(@byteOffsetOf(P, "g") == 9);45 try expect(@byteOffsetOf(P, "g") == 9);
46 expect(@byteOffsetOf(P, "h") == 11);46 try expect(@byteOffsetOf(P, "h") == 11);
47 expect(@byteOffsetOf(P, "i") == 12);47 try expect(@byteOffsetOf(P, "i") == 12);
4848
49 // Normal struct fields can be moved/padded49 // Normal struct fields can be moved/padded
50 var a: A = undefined;50 var a: A = undefined;
51 expect(@ptrToInt(&a.a) - @ptrToInt(&a) == @byteOffsetOf(A, "a"));51 try expect(@ptrToInt(&a.a) - @ptrToInt(&a) == @byteOffsetOf(A, "a"));
52 expect(@ptrToInt(&a.b) - @ptrToInt(&a) == @byteOffsetOf(A, "b"));52 try expect(@ptrToInt(&a.b) - @ptrToInt(&a) == @byteOffsetOf(A, "b"));
53 expect(@ptrToInt(&a.c) - @ptrToInt(&a) == @byteOffsetOf(A, "c"));53 try expect(@ptrToInt(&a.c) - @ptrToInt(&a) == @byteOffsetOf(A, "c"));
54 expect(@ptrToInt(&a.d) - @ptrToInt(&a) == @byteOffsetOf(A, "d"));54 try expect(@ptrToInt(&a.d) - @ptrToInt(&a) == @byteOffsetOf(A, "d"));
55 expect(@ptrToInt(&a.e) - @ptrToInt(&a) == @byteOffsetOf(A, "e"));55 try expect(@ptrToInt(&a.e) - @ptrToInt(&a) == @byteOffsetOf(A, "e"));
56 expect(@ptrToInt(&a.f) - @ptrToInt(&a) == @byteOffsetOf(A, "f"));56 try expect(@ptrToInt(&a.f) - @ptrToInt(&a) == @byteOffsetOf(A, "f"));
57 expect(@ptrToInt(&a.g) - @ptrToInt(&a) == @byteOffsetOf(A, "g"));57 try expect(@ptrToInt(&a.g) - @ptrToInt(&a) == @byteOffsetOf(A, "g"));
58 expect(@ptrToInt(&a.h) - @ptrToInt(&a) == @byteOffsetOf(A, "h"));58 try expect(@ptrToInt(&a.h) - @ptrToInt(&a) == @byteOffsetOf(A, "h"));
59 expect(@ptrToInt(&a.i) - @ptrToInt(&a) == @byteOffsetOf(A, "i"));59 try expect(@ptrToInt(&a.i) - @ptrToInt(&a) == @byteOffsetOf(A, "i"));
60}60}
6161
62test "@byteOffsetOf packed struct, array length not power of 2 or multiple of native pointer width in bytes" {62test "@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...@@ -65,68 +65,68 @@ test "@byteOffsetOf packed struct, array length not power of 2 or multiple of na
65 a: [p3a_len]u8,65 a: [p3a_len]u8,
66 b: usize,66 b: usize,
67 };67 };
68 std.testing.expectEqual(0, @byteOffsetOf(P3, "a"));68 try std.testing.expectEqual(0, @byteOffsetOf(P3, "a"));
69 std.testing.expectEqual(p3a_len, @byteOffsetOf(P3, "b"));69 try std.testing.expectEqual(p3a_len, @byteOffsetOf(P3, "b"));
7070
71 const p5a_len = 5;71 const p5a_len = 5;
72 const P5 = packed struct {72 const P5 = packed struct {
73 a: [p5a_len]u8,73 a: [p5a_len]u8,
74 b: usize,74 b: usize,
75 };75 };
76 std.testing.expectEqual(0, @byteOffsetOf(P5, "a"));76 try std.testing.expectEqual(0, @byteOffsetOf(P5, "a"));
77 std.testing.expectEqual(p5a_len, @byteOffsetOf(P5, "b"));77 try std.testing.expectEqual(p5a_len, @byteOffsetOf(P5, "b"));
7878
79 const p6a_len = 6;79 const p6a_len = 6;
80 const P6 = packed struct {80 const P6 = packed struct {
81 a: [p6a_len]u8,81 a: [p6a_len]u8,
82 b: usize,82 b: usize,
83 };83 };
84 std.testing.expectEqual(0, @byteOffsetOf(P6, "a"));84 try std.testing.expectEqual(0, @byteOffsetOf(P6, "a"));
85 std.testing.expectEqual(p6a_len, @byteOffsetOf(P6, "b"));85 try std.testing.expectEqual(p6a_len, @byteOffsetOf(P6, "b"));
8686
87 const p7a_len = 7;87 const p7a_len = 7;
88 const P7 = packed struct {88 const P7 = packed struct {
89 a: [p7a_len]u8,89 a: [p7a_len]u8,
90 b: usize,90 b: usize,
91 };91 };
92 std.testing.expectEqual(0, @byteOffsetOf(P7, "a"));92 try std.testing.expectEqual(0, @byteOffsetOf(P7, "a"));
93 std.testing.expectEqual(p7a_len, @byteOffsetOf(P7, "b"));93 try std.testing.expectEqual(p7a_len, @byteOffsetOf(P7, "b"));
9494
95 const p9a_len = 9;95 const p9a_len = 9;
96 const P9 = packed struct {96 const P9 = packed struct {
97 a: [p9a_len]u8,97 a: [p9a_len]u8,
98 b: usize,98 b: usize,
99 };99 };
100 std.testing.expectEqual(0, @byteOffsetOf(P9, "a"));100 try std.testing.expectEqual(0, @byteOffsetOf(P9, "a"));
101 std.testing.expectEqual(p9a_len, @byteOffsetOf(P9, "b"));101 try std.testing.expectEqual(p9a_len, @byteOffsetOf(P9, "b"));
102102
103 // 10, 11, 12, 13, 14, 15, 17, 18, 19, 20, 21, 22, 23, 25 etc. are further cases103 // 10, 11, 12, 13, 14, 15, 17, 18, 19, 20, 21, 22, 23, 25 etc. are further cases
104}104}
105105
106test "@bitOffsetOf" {106test "@bitOffsetOf" {
107 // Packed structs have fixed memory layout107 // Packed structs have fixed memory layout
108 expect(@bitOffsetOf(P, "a") == 0);108 try expect(@bitOffsetOf(P, "a") == 0);
109 expect(@bitOffsetOf(P, "b") == 8);109 try expect(@bitOffsetOf(P, "b") == 8);
110 expect(@bitOffsetOf(P, "c") == 40);110 try expect(@bitOffsetOf(P, "c") == 40);
111 expect(@bitOffsetOf(P, "d") == 48);111 try expect(@bitOffsetOf(P, "d") == 48);
112 expect(@bitOffsetOf(P, "e") == 51);112 try expect(@bitOffsetOf(P, "e") == 51);
113 expect(@bitOffsetOf(P, "f") == 56);113 try expect(@bitOffsetOf(P, "f") == 56);
114 expect(@bitOffsetOf(P, "g") == 72);114 try expect(@bitOffsetOf(P, "g") == 72);
115115
116 expect(@byteOffsetOf(A, "a") * 8 == @bitOffsetOf(A, "a"));116 try expect(@byteOffsetOf(A, "a") * 8 == @bitOffsetOf(A, "a"));
117 expect(@byteOffsetOf(A, "b") * 8 == @bitOffsetOf(A, "b"));117 try expect(@byteOffsetOf(A, "b") * 8 == @bitOffsetOf(A, "b"));
118 expect(@byteOffsetOf(A, "c") * 8 == @bitOffsetOf(A, "c"));118 try expect(@byteOffsetOf(A, "c") * 8 == @bitOffsetOf(A, "c"));
119 expect(@byteOffsetOf(A, "d") * 8 == @bitOffsetOf(A, "d"));119 try expect(@byteOffsetOf(A, "d") * 8 == @bitOffsetOf(A, "d"));
120 expect(@byteOffsetOf(A, "e") * 8 == @bitOffsetOf(A, "e"));120 try expect(@byteOffsetOf(A, "e") * 8 == @bitOffsetOf(A, "e"));
121 expect(@byteOffsetOf(A, "f") * 8 == @bitOffsetOf(A, "f"));121 try expect(@byteOffsetOf(A, "f") * 8 == @bitOffsetOf(A, "f"));
122 expect(@byteOffsetOf(A, "g") * 8 == @bitOffsetOf(A, "g"));122 try expect(@byteOffsetOf(A, "g") * 8 == @bitOffsetOf(A, "g"));
123}123}
124124
125test "@sizeOf on compile-time types" {125test "@sizeOf on compile-time types" {
126 expect(@sizeOf(comptime_int) == 0);126 try expect(@sizeOf(comptime_int) == 0);
127 expect(@sizeOf(comptime_float) == 0);127 try expect(@sizeOf(comptime_float) == 0);
128 expect(@sizeOf(@TypeOf(.hi)) == 0);128 try expect(@sizeOf(@TypeOf(.hi)) == 0);
129 expect(@sizeOf(@TypeOf(type)) == 0);129 try expect(@sizeOf(@TypeOf(type)) == 0);
130}130}
131131
132test "@sizeOf(T) == 0 doesn't force resolving struct size" {132test "@sizeOf(T) == 0 doesn't force resolving struct size" {
...@@ -140,8 +140,8 @@ test "@sizeOf(T) == 0 doesn't force resolving struct size" {...@@ -140,8 +140,8 @@ test "@sizeOf(T) == 0 doesn't force resolving struct size" {
140 };140 };
141 };141 };
142142
143 expect(@sizeOf(S.Foo) == 4);143 try expect(@sizeOf(S.Foo) == 4);
144 expect(@sizeOf(S.Bar) == 8);144 try expect(@sizeOf(S.Bar) == 8);
145}145}
146146
147test "@TypeOf() has no runtime side effects" {147test "@TypeOf() has no runtime side effects" {
...@@ -153,8 +153,8 @@ test "@TypeOf() has no runtime side effects" {...@@ -153,8 +153,8 @@ test "@TypeOf() has no runtime side effects" {
153 };153 };
154 var data: i32 = 0;154 var data: i32 = 0;
155 const T = @TypeOf(S.foo(i32, &data));155 const T = @TypeOf(S.foo(i32, &data));
156 comptime expect(T == i32);156 comptime try expect(T == i32);
157 expect(data == 0);157 try expect(data == 0);
158}158}
159159
160test "@TypeOf() with multiple arguments" {160test "@TypeOf() with multiple arguments" {
...@@ -162,21 +162,21 @@ test "@TypeOf() with multiple arguments" {...@@ -162,21 +162,21 @@ test "@TypeOf() with multiple arguments" {
162 var var_1: u32 = undefined;162 var var_1: u32 = undefined;
163 var var_2: u8 = undefined;163 var var_2: u8 = undefined;
164 var var_3: u64 = undefined;164 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);
166 }166 }
167 {167 {
168 var var_1: f16 = undefined;168 var var_1: f16 = undefined;
169 var var_2: f32 = undefined;169 var var_2: f32 = undefined;
170 var var_3: f64 = undefined;170 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);
172 }172 }
173 {173 {
174 var var_1: u16 = undefined;174 var var_1: u16 = undefined;
175 comptime expect(@TypeOf(var_1, 0xffff) == u16);175 comptime try expect(@TypeOf(var_1, 0xffff) == u16);
176 }176 }
177 {177 {
178 var var_1: f32 = undefined;178 var var_1: f32 = undefined;
179 comptime expect(@TypeOf(var_1, 3.1415) == f32);179 comptime try expect(@TypeOf(var_1, 3.1415) == f32);
180 }180 }
181}181}
182182
...@@ -189,8 +189,8 @@ test "branching logic inside @TypeOf" {...@@ -189,8 +189,8 @@ test "branching logic inside @TypeOf" {
189 }189 }
190 };190 };
191 const T = @TypeOf(S.foo() catch undefined);191 const T = @TypeOf(S.foo() catch undefined);
192 comptime expect(T == i32);192 comptime try expect(T == i32);
193 expect(S.data == 0);193 try expect(S.data == 0);
194}194}
195195
196fn fn1(alpha: bool) void {196fn fn1(alpha: bool) void {
...@@ -203,12 +203,12 @@ test "lazy @sizeOf result is checked for definedness" {...@@ -203,12 +203,12 @@ test "lazy @sizeOf result is checked for definedness" {
203}203}
204204
205test "@bitSizeOf" {205test "@bitSizeOf" {
206 expect(@bitSizeOf(u2) == 2);206 try expect(@bitSizeOf(u2) == 2);
207 expect(@bitSizeOf(u8) == @sizeOf(u8) * 8);207 try expect(@bitSizeOf(u8) == @sizeOf(u8) * 8);
208 expect(@bitSizeOf(struct {208 try expect(@bitSizeOf(struct {
209 a: u2,209 a: u2,
210 }) == 8);210 }) == 8);
211 expect(@bitSizeOf(packed struct {211 try expect(@bitSizeOf(packed struct {
212 a: u2,212 a: u2,
213 }) == 2);213 }) == 2);
214}214}
...@@ -241,24 +241,24 @@ test "@sizeOf comparison against zero" {...@@ -241,24 +241,24 @@ test "@sizeOf comparison against zero" {
241 f2: H(***@This()),241 f2: H(***@This()),
242 };242 };
243 const S = struct {243 const S = struct {
244 fn doTheTest(comptime T: type, comptime result: bool) void {244 fn doTheTest(comptime T: type, comptime result: bool) !void {
245 expectEqual(result, @sizeOf(T) > 0);245 try expectEqual(result, @sizeOf(T) > 0);
246 }246 }
247 };247 };
248 // Zero-sized type248 // Zero-sized type
249 S.doTheTest(u0, false);249 try S.doTheTest(u0, false);
250 S.doTheTest(*u0, false);250 try S.doTheTest(*u0, false);
251 // Non byte-sized type251 // Non byte-sized type
252 S.doTheTest(u1, true);252 try S.doTheTest(u1, true);
253 S.doTheTest(*u1, true);253 try S.doTheTest(*u1, true);
254 // Regular type254 // Regular type
255 S.doTheTest(u8, true);255 try S.doTheTest(u8, true);
256 S.doTheTest(*u8, true);256 try S.doTheTest(*u8, true);
257 S.doTheTest(f32, true);257 try S.doTheTest(f32, true);
258 S.doTheTest(*f32, true);258 try S.doTheTest(*f32, true);
259 // Container with ptr pointing to themselves259 // Container with ptr pointing to themselves
260 S.doTheTest(S0, true);260 try S.doTheTest(S0, true);
261 S.doTheTest(U0, true);261 try S.doTheTest(U0, true);
262 S.doTheTest(S1, true);262 try S.doTheTest(S1, true);
263 S.doTheTest(U1, true);263 try S.doTheTest(U1, true);
264}264}
test/behavior/slice.zig+119-119
...@@ -7,11 +7,11 @@ const mem = std.mem;...@@ -7,11 +7,11 @@ const mem = std.mem;
7const x = @intToPtr([*]i32, 0x1000)[0..0x500];7const x = @intToPtr([*]i32, 0x1000)[0..0x500];
8const y = x[0x100..];8const y = x[0x100..];
9test "compile time slice of pointer to hard coded address" {9test "compile time slice of pointer to hard coded address" {
10 expect(@ptrToInt(x) == 0x1000);10 try expect(@ptrToInt(x) == 0x1000);
11 expect(x.len == 0x500);11 try expect(x.len == 0x500);
1212
13 expect(@ptrToInt(y) == 0x1100);13 try expect(@ptrToInt(y) == 0x1100);
14 expect(y.len == 0x400);14 try expect(y.len == 0x400);
15}15}
1616
17test "runtime safety lets us slice from len..len" {17test "runtime safety lets us slice from len..len" {
...@@ -20,7 +20,7 @@ test "runtime safety lets us slice from len..len" {...@@ -20,7 +20,7 @@ test "runtime safety lets us slice from len..len" {
20 2,20 2,
21 3,21 3,
22 };22 };
23 expect(mem.eql(u8, sliceFromLenToLen(an_array[0..], 3, 3), ""));23 try expect(mem.eql(u8, sliceFromLenToLen(an_array[0..], 3, 3), ""));
24}24}
2525
26fn sliceFromLenToLen(a_slice: []u8, start: usize, end: usize) []u8 {26fn sliceFromLenToLen(a_slice: []u8, start: usize, end: usize) []u8 {
...@@ -29,18 +29,18 @@ fn sliceFromLenToLen(a_slice: []u8, start: usize, end: usize) []u8 {...@@ -29,18 +29,18 @@ fn sliceFromLenToLen(a_slice: []u8, start: usize, end: usize) []u8 {
2929
30test "implicitly cast array of size 0 to slice" {30test "implicitly cast array of size 0 to slice" {
31 var msg = [_]u8{};31 var msg = [_]u8{};
32 assertLenIsZero(&msg);32 try assertLenIsZero(&msg);
33}33}
3434
35fn assertLenIsZero(msg: []const u8) void {35fn assertLenIsZero(msg: []const u8) !void {
36 expect(msg.len == 0);36 try expect(msg.len == 0);
37}37}
3838
39test "C pointer" {39test "C pointer" {
40 var buf: [*c]const u8 = "kjdhfkjdhfdkjhfkfjhdfkjdhfkdjhfdkjhf";40 var buf: [*c]const u8 = "kjdhfkjdhfdkjhfkfjhdfkjdhfkdjhfdkjhf";
41 var len: u32 = 10;41 var len: u32 = 10;
42 var slice = buf[0..len];42 var slice = buf[0..len];
43 expectEqualSlices(u8, "kjdhfkjdhf", slice);43 try expectEqualSlices(u8, "kjdhfkjdhf", slice);
44}44}
4545
46test "C pointer slice access" {46test "C pointer slice access" {
...@@ -48,11 +48,11 @@ test "C pointer slice access" {...@@ -48,11 +48,11 @@ test "C pointer slice access" {
48 const c_ptr = @ptrCast([*c]const u32, &buf);48 const c_ptr = @ptrCast([*c]const u32, &buf);
4949
50 var runtime_zero: usize = 0;50 var runtime_zero: usize = 0;
51 comptime expectEqual([]const u32, @TypeOf(c_ptr[runtime_zero..1]));51 comptime try expectEqual([]const u32, @TypeOf(c_ptr[runtime_zero..1]));
52 comptime expectEqual(*const [1]u32, @TypeOf(c_ptr[0..1]));52 comptime try expectEqual(*const [1]u32, @TypeOf(c_ptr[0..1]));
5353
54 for (c_ptr[0..5]) |*cl| {54 for (c_ptr[0..5]) |*cl| {
55 expectEqual(@as(u32, 42), cl.*);55 try expectEqual(@as(u32, 42), cl.*);
56 }56 }
57}57}
5858
...@@ -65,8 +65,8 @@ fn sliceSum(comptime q: []const u8) i32 {...@@ -65,8 +65,8 @@ fn sliceSum(comptime q: []const u8) i32 {
65}65}
6666
67test "comptime slices are disambiguated" {67test "comptime slices are disambiguated" {
68 expect(sliceSum(&[_]u8{ 1, 2 }) == 3);68 try expect(sliceSum(&[_]u8{ 1, 2 }) == 3);
69 expect(sliceSum(&[_]u8{ 3, 4 }) == 7);69 try expect(sliceSum(&[_]u8{ 3, 4 }) == 7);
70}70}
7171
72test "slice type with custom alignment" {72test "slice type with custom alignment" {
...@@ -77,20 +77,20 @@ test "slice type with custom alignment" {...@@ -77,20 +77,20 @@ test "slice type with custom alignment" {
77 var array: [10]LazilyResolvedType align(32) = undefined;77 var array: [10]LazilyResolvedType align(32) = undefined;
78 slice = &array;78 slice = &array;
79 slice[1].anything = 42;79 slice[1].anything = 42;
80 expect(array[1].anything == 42);80 try expect(array[1].anything == 42);
81}81}
8282
83test "access len index of sentinel-terminated slice" {83test "access len index of sentinel-terminated slice" {
84 const S = struct {84 const S = struct {
85 fn doTheTest() void {85 fn doTheTest() !void {
86 var slice: [:0]const u8 = "hello";86 var slice: [:0]const u8 = "hello";
8787
88 expect(slice.len == 5);88 try expect(slice.len == 5);
89 expect(slice[5] == 0);89 try expect(slice[5] == 0);
90 }90 }
91 };91 };
92 S.doTheTest();92 try S.doTheTest();
93 comptime S.doTheTest();93 comptime try S.doTheTest();
94}94}
9595
96test "obtaining a null terminated slice" {96test "obtaining a null terminated slice" {
...@@ -108,230 +108,230 @@ test "obtaining a null terminated slice" {...@@ -108,230 +108,230 @@ test "obtaining a null terminated slice" {
108 var runtime_len: usize = 3;108 var runtime_len: usize = 3;
109 const ptr2 = buf[0..runtime_len :0];109 const ptr2 = buf[0..runtime_len :0];
110 // ptr2 is a null-terminated slice110 // ptr2 is a null-terminated slice
111 comptime expect(@TypeOf(ptr2) == [:0]u8);111 comptime try expect(@TypeOf(ptr2) == [:0]u8);
112 comptime expect(@TypeOf(ptr2[0..2]) == *[2]u8);112 comptime try expect(@TypeOf(ptr2[0..2]) == *[2]u8);
113 var runtime_zero: usize = 0;113 var runtime_zero: usize = 0;
114 comptime expect(@TypeOf(ptr2[runtime_zero..2]) == []u8);114 comptime try expect(@TypeOf(ptr2[runtime_zero..2]) == []u8);
115}115}
116116
117test "empty array to slice" {117test "empty array to slice" {
118 const S = struct {118 const S = struct {
119 fn doTheTest() void {119 fn doTheTest() !void {
120 const empty: []align(16) u8 = &[_]u8{};120 const empty: []align(16) u8 = &[_]u8{};
121 const align_1: []align(1) u8 = empty;121 const align_1: []align(1) u8 = empty;
122 const align_4: []align(4) u8 = empty;122 const align_4: []align(4) u8 = empty;
123 const align_16: []align(16) u8 = empty;123 const align_16: []align(16) u8 = empty;
124 expectEqual(1, @typeInfo(@TypeOf(align_1)).Pointer.alignment);124 try expectEqual(1, @typeInfo(@TypeOf(align_1)).Pointer.alignment);
125 expectEqual(4, @typeInfo(@TypeOf(align_4)).Pointer.alignment);125 try expectEqual(4, @typeInfo(@TypeOf(align_4)).Pointer.alignment);
126 expectEqual(16, @typeInfo(@TypeOf(align_16)).Pointer.alignment);126 try expectEqual(16, @typeInfo(@TypeOf(align_16)).Pointer.alignment);
127 }127 }
128 };128 };
129129
130 S.doTheTest();130 try S.doTheTest();
131 comptime S.doTheTest();131 comptime try S.doTheTest();
132}132}
133133
134test "@ptrCast slice to pointer" {134test "@ptrCast slice to pointer" {
135 const S = struct {135 const S = struct {
136 fn doTheTest() void {136 fn doTheTest() !void {
137 var array align(@alignOf(u16)) = [5]u8{ 0xff, 0xff, 0xff, 0xff, 0xff };137 var array align(@alignOf(u16)) = [5]u8{ 0xff, 0xff, 0xff, 0xff, 0xff };
138 var slice: []u8 = &array;138 var slice: []u8 = &array;
139 var ptr = @ptrCast(*u16, slice);139 var ptr = @ptrCast(*u16, slice);
140 expect(ptr.* == 65535);140 try expect(ptr.* == 65535);
141 }141 }
142 };142 };
143143
144 S.doTheTest();144 try S.doTheTest();
145 comptime S.doTheTest();145 comptime try S.doTheTest();
146}146}
147147
148test "slice syntax resulting in pointer-to-array" {148test "slice syntax resulting in pointer-to-array" {
149 const S = struct {149 const S = struct {
150 fn doTheTest() void {150 fn doTheTest() !void {
151 testArray();151 try testArray();
152 testArrayZ();152 try testArrayZ();
153 testArray0();153 try testArray0();
154 testArrayAlign();154 try testArrayAlign();
155 testPointer();155 try testPointer();
156 testPointerZ();156 try testPointerZ();
157 testPointer0();157 try testPointer0();
158 testPointerAlign();158 try testPointerAlign();
159 testSlice();159 try testSlice();
160 testSliceZ();160 try testSliceZ();
161 testSlice0();161 try testSlice0();
162 testSliceOpt();162 try testSliceOpt();
163 testSliceAlign();163 try testSliceAlign();
164 }164 }
165165
166 fn testArray() void {166 fn testArray() !void {
167 var array = [5]u8{ 1, 2, 3, 4, 5 };167 var array = [5]u8{ 1, 2, 3, 4, 5 };
168 var slice = array[1..3];168 var slice = array[1..3];
169 comptime expect(@TypeOf(slice) == *[2]u8);169 comptime try expect(@TypeOf(slice) == *[2]u8);
170 expect(slice[0] == 2);170 try expect(slice[0] == 2);
171 expect(slice[1] == 3);171 try expect(slice[1] == 3);
172 }172 }
173173
174 fn testArrayZ() void {174 fn testArrayZ() !void {
175 var array = [5:0]u8{ 1, 2, 3, 4, 5 };175 var array = [5:0]u8{ 1, 2, 3, 4, 5 };
176 comptime expect(@TypeOf(array[1..3]) == *[2]u8);176 comptime try expect(@TypeOf(array[1..3]) == *[2]u8);
177 comptime expect(@TypeOf(array[1..5]) == *[4:0]u8);177 comptime try expect(@TypeOf(array[1..5]) == *[4:0]u8);
178 comptime expect(@TypeOf(array[1..]) == *[4:0]u8);178 comptime try expect(@TypeOf(array[1..]) == *[4:0]u8);
179 comptime expect(@TypeOf(array[1..3 :4]) == *[2:4]u8);179 comptime try expect(@TypeOf(array[1..3 :4]) == *[2:4]u8);
180 }180 }
181181
182 fn testArray0() void {182 fn testArray0() !void {
183 {183 {
184 var array = [0]u8{};184 var array = [0]u8{};
185 var slice = array[0..0];185 var slice = array[0..0];
186 comptime expect(@TypeOf(slice) == *[0]u8);186 comptime try expect(@TypeOf(slice) == *[0]u8);
187 }187 }
188 {188 {
189 var array = [0:0]u8{};189 var array = [0:0]u8{};
190 var slice = array[0..0];190 var slice = array[0..0];
191 comptime expect(@TypeOf(slice) == *[0:0]u8);191 comptime try expect(@TypeOf(slice) == *[0:0]u8);
192 expect(slice[0] == 0);192 try expect(slice[0] == 0);
193 }193 }
194 }194 }
195195
196 fn testArrayAlign() void {196 fn testArrayAlign() !void {
197 var array align(4) = [5]u8{ 1, 2, 3, 4, 5 };197 var array align(4) = [5]u8{ 1, 2, 3, 4, 5 };
198 var slice = array[4..5];198 var slice = array[4..5];
199 comptime expect(@TypeOf(slice) == *align(4) [1]u8);199 comptime try expect(@TypeOf(slice) == *align(4) [1]u8);
200 expect(slice[0] == 5);200 try expect(slice[0] == 5);
201 comptime expect(@TypeOf(array[0..2]) == *align(4) [2]u8);201 comptime try expect(@TypeOf(array[0..2]) == *align(4) [2]u8);
202 }202 }
203203
204 fn testPointer() void {204 fn testPointer() !void {
205 var array = [5]u8{ 1, 2, 3, 4, 5 };205 var array = [5]u8{ 1, 2, 3, 4, 5 };
206 var pointer: [*]u8 = &array;206 var pointer: [*]u8 = &array;
207 var slice = pointer[1..3];207 var slice = pointer[1..3];
208 comptime expect(@TypeOf(slice) == *[2]u8);208 comptime try expect(@TypeOf(slice) == *[2]u8);
209 expect(slice[0] == 2);209 try expect(slice[0] == 2);
210 expect(slice[1] == 3);210 try expect(slice[1] == 3);
211 }211 }
212212
213 fn testPointerZ() void {213 fn testPointerZ() !void {
214 var array = [5:0]u8{ 1, 2, 3, 4, 5 };214 var array = [5:0]u8{ 1, 2, 3, 4, 5 };
215 var pointer: [*:0]u8 = &array;215 var pointer: [*:0]u8 = &array;
216 comptime expect(@TypeOf(pointer[1..3]) == *[2]u8);216 comptime try expect(@TypeOf(pointer[1..3]) == *[2]u8);
217 comptime expect(@TypeOf(pointer[1..3 :4]) == *[2:4]u8);217 comptime try expect(@TypeOf(pointer[1..3 :4]) == *[2:4]u8);
218 }218 }
219219
220 fn testPointer0() void {220 fn testPointer0() !void {
221 var pointer: [*]const u0 = &[1]u0{0};221 var pointer: [*]const u0 = &[1]u0{0};
222 var slice = pointer[0..1];222 var slice = pointer[0..1];
223 comptime expect(@TypeOf(slice) == *const [1]u0);223 comptime try expect(@TypeOf(slice) == *const [1]u0);
224 expect(slice[0] == 0);224 try expect(slice[0] == 0);
225 }225 }
226226
227 fn testPointerAlign() void {227 fn testPointerAlign() !void {
228 var array align(4) = [5]u8{ 1, 2, 3, 4, 5 };228 var array align(4) = [5]u8{ 1, 2, 3, 4, 5 };
229 var pointer: [*]align(4) u8 = &array;229 var pointer: [*]align(4) u8 = &array;
230 var slice = pointer[4..5];230 var slice = pointer[4..5];
231 comptime expect(@TypeOf(slice) == *align(4) [1]u8);231 comptime try expect(@TypeOf(slice) == *align(4) [1]u8);
232 expect(slice[0] == 5);232 try expect(slice[0] == 5);
233 comptime expect(@TypeOf(pointer[0..2]) == *align(4) [2]u8);233 comptime try expect(@TypeOf(pointer[0..2]) == *align(4) [2]u8);
234 }234 }
235235
236 fn testSlice() void {236 fn testSlice() !void {
237 var array = [5]u8{ 1, 2, 3, 4, 5 };237 var array = [5]u8{ 1, 2, 3, 4, 5 };
238 var src_slice: []u8 = &array;238 var src_slice: []u8 = &array;
239 var slice = src_slice[1..3];239 var slice = src_slice[1..3];
240 comptime expect(@TypeOf(slice) == *[2]u8);240 comptime try expect(@TypeOf(slice) == *[2]u8);
241 expect(slice[0] == 2);241 try expect(slice[0] == 2);
242 expect(slice[1] == 3);242 try expect(slice[1] == 3);
243 }243 }
244244
245 fn testSliceZ() void {245 fn testSliceZ() !void {
246 var array = [5:0]u8{ 1, 2, 3, 4, 5 };246 var array = [5:0]u8{ 1, 2, 3, 4, 5 };
247 var slice: [:0]u8 = &array;247 var slice: [:0]u8 = &array;
248 comptime expect(@TypeOf(slice[1..3]) == *[2]u8);248 comptime try expect(@TypeOf(slice[1..3]) == *[2]u8);
249 comptime expect(@TypeOf(slice[1..]) == [:0]u8);249 comptime try expect(@TypeOf(slice[1..]) == [:0]u8);
250 comptime expect(@TypeOf(slice[1..3 :4]) == *[2:4]u8);250 comptime try expect(@TypeOf(slice[1..3 :4]) == *[2:4]u8);
251 }251 }
252252
253 fn testSliceOpt() void {253 fn testSliceOpt() !void {
254 var array: [2]u8 = [2]u8{ 1, 2 };254 var array: [2]u8 = [2]u8{ 1, 2 };
255 var slice: ?[]u8 = &array;255 var slice: ?[]u8 = &array;
256 comptime expect(@TypeOf(&array, slice) == ?[]u8);256 comptime try expect(@TypeOf(&array, slice) == ?[]u8);
257 comptime expect(@TypeOf(slice.?[0..2]) == *[2]u8);257 comptime try expect(@TypeOf(slice.?[0..2]) == *[2]u8);
258 }258 }
259259
260 fn testSlice0() void {260 fn testSlice0() !void {
261 {261 {
262 var array = [0]u8{};262 var array = [0]u8{};
263 var src_slice: []u8 = &array;263 var src_slice: []u8 = &array;
264 var slice = src_slice[0..0];264 var slice = src_slice[0..0];
265 comptime expect(@TypeOf(slice) == *[0]u8);265 comptime try expect(@TypeOf(slice) == *[0]u8);
266 }266 }
267 {267 {
268 var array = [0:0]u8{};268 var array = [0:0]u8{};
269 var src_slice: [:0]u8 = &array;269 var src_slice: [:0]u8 = &array;
270 var slice = src_slice[0..0];270 var slice = src_slice[0..0];
271 comptime expect(@TypeOf(slice) == *[0]u8);271 comptime try expect(@TypeOf(slice) == *[0]u8);
272 }272 }
273 }273 }
274274
275 fn testSliceAlign() void {275 fn testSliceAlign() !void {
276 var array align(4) = [5]u8{ 1, 2, 3, 4, 5 };276 var array align(4) = [5]u8{ 1, 2, 3, 4, 5 };
277 var src_slice: []align(4) u8 = &array;277 var src_slice: []align(4) u8 = &array;
278 var slice = src_slice[4..5];278 var slice = src_slice[4..5];
279 comptime expect(@TypeOf(slice) == *align(4) [1]u8);279 comptime try expect(@TypeOf(slice) == *align(4) [1]u8);
280 expect(slice[0] == 5);280 try expect(slice[0] == 5);
281 comptime expect(@TypeOf(src_slice[0..2]) == *align(4) [2]u8);281 comptime try expect(@TypeOf(src_slice[0..2]) == *align(4) [2]u8);
282 }282 }
283283
284 fn testConcatStrLiterals() void {284 fn testConcatStrLiterals() !void {
285 expectEqualSlices("a"[0..] ++ "b"[0..], "ab");285 try expectEqualSlices("a"[0..] ++ "b"[0..], "ab");
286 expectEqualSlices("a"[0..:0] ++ "b"[0..:0], "ab");286 try expectEqualSlices("a"[0.. :0] ++ "b"[0.. :0], "ab");
287 }287 }
288 };288 };
289289
290 S.doTheTest();290 try S.doTheTest();
291 comptime S.doTheTest();291 comptime try S.doTheTest();
292}292}
293293
294test "slice of hardcoded address to pointer" {294test "slice of hardcoded address to pointer" {
295 const S = struct {295 const S = struct {
296 fn doTheTest() void {296 fn doTheTest() !void {
297 const pointer = @intToPtr([*]u8, 0x04)[0..2];297 const pointer = @intToPtr([*]u8, 0x04)[0..2];
298 comptime expect(@TypeOf(pointer) == *[2]u8);298 comptime try expect(@TypeOf(pointer) == *[2]u8);
299 const slice: []const u8 = pointer;299 const slice: []const u8 = pointer;
300 expect(@ptrToInt(slice.ptr) == 4);300 try expect(@ptrToInt(slice.ptr) == 4);
301 expect(slice.len == 2);301 try expect(slice.len == 2);
302 }302 }
303 };303 };
304304
305 S.doTheTest();305 try S.doTheTest();
306}306}
307307
308test "type coercion of pointer to anon struct literal to pointer to slice" {308test "type coercion of pointer to anon struct literal to pointer to slice" {
309 const S = struct {309 const S = struct {
310 const U = union{310 const U = union {
311 a: u32,311 a: u32,
312 b: bool,312 b: bool,
313 c: []const u8,313 c: []const u8,
314 };314 };
315315
316 fn doTheTest() void {316 fn doTheTest() !void {
317 var x1: u8 = 42;317 var x1: u8 = 42;
318 const t1 = &.{ x1, 56, 54 };318 const t1 = &.{ x1, 56, 54 };
319 var slice1: []const u8 = t1;319 var slice1: []const u8 = t1;
320 expect(slice1.len == 3);320 try expect(slice1.len == 3);
321 expect(slice1[0] == 42);321 try expect(slice1[0] == 42);
322 expect(slice1[1] == 56);322 try expect(slice1[1] == 56);
323 expect(slice1[2] == 54);323 try expect(slice1[2] == 54);
324 324
325 var x2: []const u8 = "hello";325 var x2: []const u8 = "hello";
326 const t2 = &.{ x2, ", ", "world!" };326 const t2 = &.{ x2, ", ", "world!" };
327 // @compileLog(@TypeOf(t2));327 // @compileLog(@TypeOf(t2));
328 var slice2: []const []const u8 = t2;328 var slice2: []const []const u8 = t2;
329 expect(slice2.len == 3);329 try expect(slice2.len == 3);
330 expect(mem.eql(u8, slice2[0], "hello"));330 try expect(mem.eql(u8, slice2[0], "hello"));
331 expect(mem.eql(u8, slice2[1], ", "));331 try expect(mem.eql(u8, slice2[1], ", "));
332 expect(mem.eql(u8, slice2[2], "world!"));332 try expect(mem.eql(u8, slice2[2], "world!"));
333 }333 }
334 };334 };
335 // S.doTheTest();335 // try S.doTheTest();
336 comptime S.doTheTest();336 comptime try S.doTheTest();
337}337}
test/behavior/src.zig+8-8
...@@ -2,16 +2,16 @@ const std = @import("std");...@@ -2,16 +2,16 @@ const std = @import("std");
2const expect = std.testing.expect;2const expect = std.testing.expect;
33
4test "@src" {4test "@src" {
5 doTheTest();5 try doTheTest();
6}6}
77
8fn doTheTest() void {8fn doTheTest() !void {
9 const src = @src();9 const src = @src();
1010
11 expect(src.line == 9);11 try expect(src.line == 9);
12 expect(src.column == 17);12 try expect(src.column == 17);
13 expect(std.mem.endsWith(u8, src.fn_name, "doTheTest"));13 try expect(std.mem.endsWith(u8, src.fn_name, "doTheTest"));
14 expect(std.mem.endsWith(u8, src.file, "src.zig"));14 try expect(std.mem.endsWith(u8, src.file, "src.zig"));
15 expect(src.fn_name[src.fn_name.len] == 0);15 try expect(src.fn_name[src.fn_name.len] == 0);
16 expect(src.file[src.file.len] == 0);16 try expect(src.file[src.file.len] == 0);
17}17}
test/behavior/struct.zig+191-190
...@@ -19,12 +19,12 @@ test "top level fields" {...@@ -19,12 +19,12 @@ test "top level fields" {
19 .top_level_field = 1234,19 .top_level_field = 1234,
20 };20 };
21 instance.top_level_field += 1;21 instance.top_level_field += 1;
22 expectEqual(@as(i32, 1235), instance.top_level_field);22 try expectEqual(@as(i32, 1235), instance.top_level_field);
23}23}
2424
25test "call struct static method" {25test "call struct static method" {
26 const result = StructWithNoFields.add(3, 4);26 const result = StructWithNoFields.add(3, 4);
27 expect(result == 7);27 try expect(result == 7);
28}28}
2929
30test "return empty struct instance" {30test "return empty struct instance" {
...@@ -37,7 +37,7 @@ fn returnEmptyStructInstance() StructWithNoFields {...@@ -37,7 +37,7 @@ fn returnEmptyStructInstance() StructWithNoFields {
37const should_be_11 = StructWithNoFields.add(5, 6);37const should_be_11 = StructWithNoFields.add(5, 6);
3838
39test "invoke static method in global scope" {39test "invoke static method in global scope" {
40 expect(should_be_11 == 11);40 try expect(should_be_11 == 11);
41}41}
4242
43test "void struct fields" {43test "void struct fields" {
...@@ -46,8 +46,8 @@ test "void struct fields" {...@@ -46,8 +46,8 @@ test "void struct fields" {
46 .b = 1,46 .b = 1,
47 .c = void{},47 .c = void{},
48 };48 };
49 expect(foo.b == 1);49 try expect(foo.b == 1);
50 expect(@sizeOf(VoidStructFieldsFoo) == 4);50 try expect(@sizeOf(VoidStructFieldsFoo) == 4);
51}51}
52const VoidStructFieldsFoo = struct {52const VoidStructFieldsFoo = struct {
53 a: void,53 a: void,
...@@ -60,17 +60,17 @@ test "structs" {...@@ -60,17 +60,17 @@ test "structs" {
60 @memset(@ptrCast([*]u8, &foo), 0, @sizeOf(StructFoo));60 @memset(@ptrCast([*]u8, &foo), 0, @sizeOf(StructFoo));
61 foo.a += 1;61 foo.a += 1;
62 foo.b = foo.a == 1;62 foo.b = foo.a == 1;
63 testFoo(foo);63 try testFoo(foo);
64 testMutation(&foo);64 testMutation(&foo);
65 expect(foo.c == 100);65 try expect(foo.c == 100);
66}66}
67const StructFoo = struct {67const StructFoo = struct {
68 a: i32,68 a: i32,
69 b: bool,69 b: bool,
70 c: f32,70 c: f32,
71};71};
72fn testFoo(foo: StructFoo) void {72fn testFoo(foo: StructFoo) !void {
73 expect(foo.b);73 try expect(foo.b);
74}74}
75fn testMutation(foo: *StructFoo) void {75fn testMutation(foo: *StructFoo) void {
76 foo.c = 100;76 foo.c = 100;
...@@ -95,7 +95,7 @@ test "struct point to self" {...@@ -95,7 +95,7 @@ test "struct point to self" {
9595
96 root.next = &node;96 root.next = &node;
9797
98 expect(node.next.next.next.val.x == 1);98 try expect(node.next.next.next.val.x == 1);
99}99}
100100
101test "struct byval assign" {101test "struct byval assign" {
...@@ -104,14 +104,14 @@ test "struct byval assign" {...@@ -104,14 +104,14 @@ test "struct byval assign" {
104104
105 foo1.a = 1234;105 foo1.a = 1234;
106 foo2.a = 0;106 foo2.a = 0;
107 expect(foo2.a == 0);107 try expect(foo2.a == 0);
108 foo2 = foo1;108 foo2 = foo1;
109 expect(foo2.a == 1234);109 try expect(foo2.a == 1234);
110}110}
111111
112fn structInitializer() void {112fn structInitializer() void {
113 const val = Val{ .x = 42 };113 const val = Val{ .x = 42 };
114 expect(val.x == 42);114 try expect(val.x == 42);
115}115}
116116
117test "fn call of struct field" {117test "fn call of struct field" {
...@@ -128,14 +128,14 @@ test "fn call of struct field" {...@@ -128,14 +128,14 @@ test "fn call of struct field" {
128 }128 }
129 };129 };
130130
131 expect(S.callStructField(Foo{ .ptr = S.aFunc }) == 13);131 try expect(S.callStructField(Foo{ .ptr = S.aFunc }) == 13);
132}132}
133133
134test "store member function in variable" {134test "store member function in variable" {
135 const instance = MemberFnTestFoo{ .x = 1234 };135 const instance = MemberFnTestFoo{ .x = 1234 };
136 const memberFn = MemberFnTestFoo.member;136 const memberFn = MemberFnTestFoo.member;
137 const result = memberFn(instance);137 const result = memberFn(instance);
138 expect(result == 1234);138 try expect(result == 1234);
139}139}
140const MemberFnTestFoo = struct {140const MemberFnTestFoo = struct {
141 x: i32,141 x: i32,
...@@ -147,12 +147,12 @@ const MemberFnTestFoo = struct {...@@ -147,12 +147,12 @@ const MemberFnTestFoo = struct {
147test "call member function directly" {147test "call member function directly" {
148 const instance = MemberFnTestFoo{ .x = 1234 };148 const instance = MemberFnTestFoo{ .x = 1234 };
149 const result = MemberFnTestFoo.member(instance);149 const result = MemberFnTestFoo.member(instance);
150 expect(result == 1234);150 try expect(result == 1234);
151}151}
152152
153test "member functions" {153test "member functions" {
154 const r = MemberFnRand{ .seed = 1234 };154 const r = MemberFnRand{ .seed = 1234 };
155 expect(r.getSeed() == 1234);155 try expect(r.getSeed() == 1234);
156}156}
157const MemberFnRand = struct {157const MemberFnRand = struct {
158 seed: u32,158 seed: u32,
...@@ -163,7 +163,7 @@ const MemberFnRand = struct {...@@ -163,7 +163,7 @@ const MemberFnRand = struct {
163163
164test "return struct byval from function" {164test "return struct byval from function" {
165 const bar = makeBar(1234, 5678);165 const bar = makeBar(1234, 5678);
166 expect(bar.y == 5678);166 try expect(bar.y == 5678);
167}167}
168const Bar = struct {168const Bar = struct {
169 x: i32,169 x: i32,
...@@ -178,7 +178,7 @@ fn makeBar(x: i32, y: i32) Bar {...@@ -178,7 +178,7 @@ fn makeBar(x: i32, y: i32) Bar {
178178
179test "empty struct method call" {179test "empty struct method call" {
180 const es = EmptyStruct{};180 const es = EmptyStruct{};
181 expect(es.method() == 1234);181 try expect(es.method() == 1234);
182}182}
183const EmptyStruct = struct {183const EmptyStruct = struct {
184 fn method(es: *const EmptyStruct) i32 {184 fn method(es: *const EmptyStruct) i32 {
...@@ -195,7 +195,7 @@ fn testReturnEmptyStructFromFn() EmptyStruct2 {...@@ -195,7 +195,7 @@ fn testReturnEmptyStructFromFn() EmptyStruct2 {
195}195}
196196
197test "pass slice of empty struct to fn" {197test "pass slice of empty struct to fn" {
198 expect(testPassSliceOfEmptyStructToFn(&[_]EmptyStruct2{EmptyStruct2{}}) == 1);198 try expect(testPassSliceOfEmptyStructToFn(&[_]EmptyStruct2{EmptyStruct2{}}) == 1);
199}199}
200fn testPassSliceOfEmptyStructToFn(slice: []const EmptyStruct2) usize {200fn testPassSliceOfEmptyStructToFn(slice: []const EmptyStruct2) usize {
201 return slice.len;201 return slice.len;
...@@ -213,7 +213,7 @@ test "packed struct" {...@@ -213,7 +213,7 @@ test "packed struct" {
213 };213 };
214 foo.y += 1;214 foo.y += 1;
215 const four = foo.x + foo.y;215 const four = foo.x + foo.y;
216 expect(four == 4);216 try expect(four == 4);
217}217}
218218
219const BitField1 = packed struct {219const BitField1 = packed struct {
...@@ -230,17 +230,17 @@ const bit_field_1 = BitField1{...@@ -230,17 +230,17 @@ const bit_field_1 = BitField1{
230230
231test "bit field access" {231test "bit field access" {
232 var data = bit_field_1;232 var data = bit_field_1;
233 expect(getA(&data) == 1);233 try expect(getA(&data) == 1);
234 expect(getB(&data) == 2);234 try expect(getB(&data) == 2);
235 expect(getC(&data) == 3);235 try expect(getC(&data) == 3);
236 comptime expect(@sizeOf(BitField1) == 1);236 comptime try expect(@sizeOf(BitField1) == 1);
237237
238 data.b += 1;238 data.b += 1;
239 expect(data.b == 3);239 try expect(data.b == 3);
240240
241 data.a += 1;241 data.a += 1;
242 expect(data.a == 2);242 try expect(data.a == 2);
243 expect(data.b == 3);243 try expect(data.b == 3);
244}244}
245245
246fn getA(data: *const BitField1) u3 {246fn getA(data: *const BitField1) u3 {
...@@ -267,11 +267,11 @@ const Foo96Bits = packed struct {...@@ -267,11 +267,11 @@ const Foo96Bits = packed struct {
267267
268test "packed struct 24bits" {268test "packed struct 24bits" {
269 comptime {269 comptime {
270 expect(@sizeOf(Foo24Bits) == 4);270 try expect(@sizeOf(Foo24Bits) == 4);
271 if (@sizeOf(usize) == 4) {271 if (@sizeOf(usize) == 4) {
272 expect(@sizeOf(Foo96Bits) == 12);272 try expect(@sizeOf(Foo96Bits) == 12);
273 } else {273 } else {
274 expect(@sizeOf(Foo96Bits) == 16);274 try expect(@sizeOf(Foo96Bits) == 16);
275 }275 }
276 }276 }
277277
...@@ -282,28 +282,28 @@ test "packed struct 24bits" {...@@ -282,28 +282,28 @@ test "packed struct 24bits" {
282 .d = 0,282 .d = 0,
283 };283 };
284 value.a += 1;284 value.a += 1;
285 expect(value.a == 1);285 try expect(value.a == 1);
286 expect(value.b == 0);286 try expect(value.b == 0);
287 expect(value.c == 0);287 try expect(value.c == 0);
288 expect(value.d == 0);288 try expect(value.d == 0);
289289
290 value.b += 1;290 value.b += 1;
291 expect(value.a == 1);291 try expect(value.a == 1);
292 expect(value.b == 1);292 try expect(value.b == 1);
293 expect(value.c == 0);293 try expect(value.c == 0);
294 expect(value.d == 0);294 try expect(value.d == 0);
295295
296 value.c += 1;296 value.c += 1;
297 expect(value.a == 1);297 try expect(value.a == 1);
298 expect(value.b == 1);298 try expect(value.b == 1);
299 expect(value.c == 1);299 try expect(value.c == 1);
300 expect(value.d == 0);300 try expect(value.d == 0);
301301
302 value.d += 1;302 value.d += 1;
303 expect(value.a == 1);303 try expect(value.a == 1);
304 expect(value.b == 1);304 try expect(value.b == 1);
305 expect(value.c == 1);305 try expect(value.c == 1);
306 expect(value.d == 1);306 try expect(value.d == 1);
307}307}
308308
309const Foo32Bits = packed struct {309const Foo32Bits = packed struct {
...@@ -320,43 +320,43 @@ const FooArray24Bits = packed struct {...@@ -320,43 +320,43 @@ const FooArray24Bits = packed struct {
320// TODO revisit this test when doing https://github.com/ziglang/zig/issues/1512320// TODO revisit this test when doing https://github.com/ziglang/zig/issues/1512
321test "packed array 24bits" {321test "packed array 24bits" {
322 comptime {322 comptime {
323 expect(@sizeOf([9]Foo32Bits) == 9 * 4);323 try expect(@sizeOf([9]Foo32Bits) == 9 * 4);
324 expect(@sizeOf(FooArray24Bits) == 2 + 2 * 4 + 2);324 try expect(@sizeOf(FooArray24Bits) == 2 + 2 * 4 + 2);
325 }325 }
326326
327 var bytes = [_]u8{0} ** (@sizeOf(FooArray24Bits) + 1);327 var bytes = [_]u8{0} ** (@sizeOf(FooArray24Bits) + 1);
328 bytes[bytes.len - 1] = 0xaa;328 bytes[bytes.len - 1] = 0xaa;
329 const ptr = &std.mem.bytesAsSlice(FooArray24Bits, bytes[0 .. bytes.len - 1])[0];329 const ptr = &std.mem.bytesAsSlice(FooArray24Bits, bytes[0 .. bytes.len - 1])[0];
330 expect(ptr.a == 0);330 try expect(ptr.a == 0);
331 expect(ptr.b[0].field == 0);331 try expect(ptr.b[0].field == 0);
332 expect(ptr.b[1].field == 0);332 try expect(ptr.b[1].field == 0);
333 expect(ptr.c == 0);333 try expect(ptr.c == 0);
334334
335 ptr.a = maxInt(u16);335 ptr.a = maxInt(u16);
336 expect(ptr.a == maxInt(u16));336 try expect(ptr.a == maxInt(u16));
337 expect(ptr.b[0].field == 0);337 try expect(ptr.b[0].field == 0);
338 expect(ptr.b[1].field == 0);338 try expect(ptr.b[1].field == 0);
339 expect(ptr.c == 0);339 try expect(ptr.c == 0);
340340
341 ptr.b[0].field = maxInt(u24);341 ptr.b[0].field = maxInt(u24);
342 expect(ptr.a == maxInt(u16));342 try expect(ptr.a == maxInt(u16));
343 expect(ptr.b[0].field == maxInt(u24));343 try expect(ptr.b[0].field == maxInt(u24));
344 expect(ptr.b[1].field == 0);344 try expect(ptr.b[1].field == 0);
345 expect(ptr.c == 0);345 try expect(ptr.c == 0);
346346
347 ptr.b[1].field = maxInt(u24);347 ptr.b[1].field = maxInt(u24);
348 expect(ptr.a == maxInt(u16));348 try expect(ptr.a == maxInt(u16));
349 expect(ptr.b[0].field == maxInt(u24));349 try expect(ptr.b[0].field == maxInt(u24));
350 expect(ptr.b[1].field == maxInt(u24));350 try expect(ptr.b[1].field == maxInt(u24));
351 expect(ptr.c == 0);351 try expect(ptr.c == 0);
352352
353 ptr.c = maxInt(u16);353 ptr.c = maxInt(u16);
354 expect(ptr.a == maxInt(u16));354 try expect(ptr.a == maxInt(u16));
355 expect(ptr.b[0].field == maxInt(u24));355 try expect(ptr.b[0].field == maxInt(u24));
356 expect(ptr.b[1].field == maxInt(u24));356 try expect(ptr.b[1].field == maxInt(u24));
357 expect(ptr.c == maxInt(u16));357 try expect(ptr.c == maxInt(u16));
358358
359 expect(bytes[bytes.len - 1] == 0xaa);359 try expect(bytes[bytes.len - 1] == 0xaa);
360}360}
361361
362const FooStructAligned = packed struct {362const FooStructAligned = packed struct {
...@@ -370,17 +370,17 @@ const FooArrayOfAligned = packed struct {...@@ -370,17 +370,17 @@ const FooArrayOfAligned = packed struct {
370370
371test "aligned array of packed struct" {371test "aligned array of packed struct" {
372 comptime {372 comptime {
373 expect(@sizeOf(FooStructAligned) == 2);373 try expect(@sizeOf(FooStructAligned) == 2);
374 expect(@sizeOf(FooArrayOfAligned) == 2 * 2);374 try expect(@sizeOf(FooArrayOfAligned) == 2 * 2);
375 }375 }
376376
377 var bytes = [_]u8{0xbb} ** @sizeOf(FooArrayOfAligned);377 var bytes = [_]u8{0xbb} ** @sizeOf(FooArrayOfAligned);
378 const ptr = &std.mem.bytesAsSlice(FooArrayOfAligned, bytes[0..])[0];378 const ptr = &std.mem.bytesAsSlice(FooArrayOfAligned, bytes[0..])[0];
379379
380 expect(ptr.a[0].a == 0xbb);380 try expect(ptr.a[0].a == 0xbb);
381 expect(ptr.a[0].b == 0xbb);381 try expect(ptr.a[0].b == 0xbb);
382 expect(ptr.a[1].a == 0xbb);382 try expect(ptr.a[1].a == 0xbb);
383 expect(ptr.a[1].b == 0xbb);383 try expect(ptr.a[1].b == 0xbb);
384}384}
385385
386test "runtime struct initialization of bitfield" {386test "runtime struct initialization of bitfield" {
...@@ -393,10 +393,10 @@ test "runtime struct initialization of bitfield" {...@@ -393,10 +393,10 @@ test "runtime struct initialization of bitfield" {
393 .y = @intCast(u4, x2),393 .y = @intCast(u4, x2),
394 };394 };
395395
396 expect(s1.x == x1);396 try expect(s1.x == x1);
397 expect(s1.y == x1);397 try expect(s1.y == x1);
398 expect(s2.x == @intCast(u4, x2));398 try expect(s2.x == @intCast(u4, x2));
399 expect(s2.y == @intCast(u4, x2));399 try expect(s2.y == @intCast(u4, x2));
400}400}
401401
402var x1 = @as(u4, 1);402var x1 = @as(u4, 1);
...@@ -426,18 +426,18 @@ test "native bit field understands endianness" {...@@ -426,18 +426,18 @@ test "native bit field understands endianness" {
426 @memcpy(&bytes, @ptrCast([*]u8, &all), 8);426 @memcpy(&bytes, @ptrCast([*]u8, &all), 8);
427 var bitfields = @ptrCast(*Bitfields, &bytes).*;427 var bitfields = @ptrCast(*Bitfields, &bytes).*;
428428
429 expect(bitfields.f1 == 0x1111);429 try expect(bitfields.f1 == 0x1111);
430 expect(bitfields.f2 == 0x2222);430 try expect(bitfields.f2 == 0x2222);
431 expect(bitfields.f3 == 0x33);431 try expect(bitfields.f3 == 0x33);
432 expect(bitfields.f4 == 0x44);432 try expect(bitfields.f4 == 0x44);
433 expect(bitfields.f5 == 0x5);433 try expect(bitfields.f5 == 0x5);
434 expect(bitfields.f6 == 0x6);434 try expect(bitfields.f6 == 0x6);
435 expect(bitfields.f7 == 0x77);435 try expect(bitfields.f7 == 0x77);
436}436}
437437
438test "align 1 field before self referential align 8 field as slice return type" {438test "align 1 field before self referential align 8 field as slice return type" {
439 const result = alloc(Expr);439 const result = alloc(Expr);
440 expect(result.len == 0);440 try expect(result.len == 0);
441}441}
442442
443const Expr = union(enum) {443const Expr = union(enum) {
...@@ -460,10 +460,10 @@ test "call method with mutable reference to struct with no fields" {...@@ -460,10 +460,10 @@ test "call method with mutable reference to struct with no fields" {
460 };460 };
461461
462 var s = S{};462 var s = S{};
463 expect(S.doC(&s));463 try expect(S.doC(&s));
464 expect(s.doC());464 try expect(s.doC());
465 expect(S.do(&s));465 try expect(S.do(&s));
466 expect(s.do());466 try expect(s.do());
467}467}
468468
469test "implicit cast packed struct field to const ptr" {469test "implicit cast packed struct field to const ptr" {
...@@ -479,7 +479,7 @@ test "implicit cast packed struct field to const ptr" {...@@ -479,7 +479,7 @@ test "implicit cast packed struct field to const ptr" {
479 var lup: LevelUpMove = undefined;479 var lup: LevelUpMove = undefined;
480 lup.level = 12;480 lup.level = 12;
481 const res = LevelUpMove.toInt(lup.level);481 const res = LevelUpMove.toInt(lup.level);
482 expect(res == 12);482 try expect(res == 12);
483}483}
484484
485test "pointer to packed struct member in a stack variable" {485test "pointer to packed struct member in a stack variable" {
...@@ -490,9 +490,9 @@ test "pointer to packed struct member in a stack variable" {...@@ -490,9 +490,9 @@ test "pointer to packed struct member in a stack variable" {
490490
491 var s = S{ .a = 2, .b = 0 };491 var s = S{ .a = 2, .b = 0 };
492 var b_ptr = &s.b;492 var b_ptr = &s.b;
493 expect(s.b == 0);493 try expect(s.b == 0);
494 b_ptr.* = 2;494 b_ptr.* = 2;
495 expect(s.b == 2);495 try expect(s.b == 2);
496}496}
497497
498test "non-byte-aligned array inside packed struct" {498test "non-byte-aligned array inside packed struct" {
...@@ -501,20 +501,20 @@ test "non-byte-aligned array inside packed struct" {...@@ -501,20 +501,20 @@ test "non-byte-aligned array inside packed struct" {
501 b: [0x16]u8,501 b: [0x16]u8,
502 };502 };
503 const S = struct {503 const S = struct {
504 fn bar(slice: []const u8) void {504 fn bar(slice: []const u8) !void {
505 expectEqualSlices(u8, slice, "abcdefghijklmnopqurstu");505 try expectEqualSlices(u8, slice, "abcdefghijklmnopqurstu");
506 }506 }
507 fn doTheTest() void {507 fn doTheTest() !void {
508 var foo = Foo{508 var foo = Foo{
509 .a = true,509 .a = true,
510 .b = "abcdefghijklmnopqurstu".*,510 .b = "abcdefghijklmnopqurstu".*,
511 };511 };
512 const value = foo.b;512 const value = foo.b;
513 bar(&value);513 try bar(&value);
514 }514 }
515 };515 };
516 S.doTheTest();516 try S.doTheTest();
517 comptime S.doTheTest();517 comptime try S.doTheTest();
518}518}
519519
520test "packed struct with u0 field access" {520test "packed struct with u0 field access" {
...@@ -522,7 +522,7 @@ test "packed struct with u0 field access" {...@@ -522,7 +522,7 @@ test "packed struct with u0 field access" {
522 f0: u0,522 f0: u0,
523 };523 };
524 var s = S{ .f0 = 0 };524 var s = S{ .f0 = 0 };
525 comptime expect(s.f0 == 0);525 comptime try expect(s.f0 == 0);
526}526}
527527
528const S0 = struct {528const S0 = struct {
...@@ -541,7 +541,7 @@ var g_foo: S0 = S0.init();...@@ -541,7 +541,7 @@ var g_foo: S0 = S0.init();
541541
542test "access to global struct fields" {542test "access to global struct fields" {
543 g_foo.bar.value = 42;543 g_foo.bar.value = 42;
544 expect(g_foo.bar.value == 42);544 try expect(g_foo.bar.value == 42);
545}545}
546546
547test "packed struct with fp fields" {547test "packed struct with fp fields" {
...@@ -560,9 +560,9 @@ test "packed struct with fp fields" {...@@ -560,9 +560,9 @@ test "packed struct with fp fields" {
560 s.data[1] = 2.0;560 s.data[1] = 2.0;
561 s.data[2] = 3.0;561 s.data[2] = 3.0;
562 s.frob();562 s.frob();
563 expectEqual(@as(f32, 6.0), s.data[0]);563 try expectEqual(@as(f32, 6.0), s.data[0]);
564 expectEqual(@as(f32, 11.0), s.data[1]);564 try expectEqual(@as(f32, 11.0), s.data[1]);
565 expectEqual(@as(f32, 20.0), s.data[2]);565 try expectEqual(@as(f32, 20.0), s.data[2]);
566}566}
567567
568test "use within struct scope" {568test "use within struct scope" {
...@@ -573,7 +573,7 @@ test "use within struct scope" {...@@ -573,7 +573,7 @@ test "use within struct scope" {
573 }573 }
574 };574 };
575 };575 };
576 expectEqual(@as(i32, 42), S.inner());576 try expectEqual(@as(i32, 42), S.inner());
577}577}
578578
579test "default struct initialization fields" {579test "default struct initialization fields" {
...@@ -591,14 +591,14 @@ test "default struct initialization fields" {...@@ -591,14 +591,14 @@ test "default struct initialization fields" {
591 const y = S{591 const y = S{
592 .b = five,592 .b = five,
593 };593 };
594 expectEqual(1239, x.a + x.b);594 try expectEqual(1239, x.a + x.b);
595}595}
596596
597test "fn with C calling convention returns struct by value" {597test "fn with C calling convention returns struct by value" {
598 const S = struct {598 const S = struct {
599 fn entry() void {599 fn entry() !void {
600 var x = makeBar(10);600 var x = makeBar(10);
601 expectEqual(@as(i32, 10), x.handle);601 try expectEqual(@as(i32, 10), x.handle);
602 }602 }
603603
604 const ExternBar = extern struct {604 const ExternBar = extern struct {
...@@ -611,8 +611,8 @@ test "fn with C calling convention returns struct by value" {...@@ -611,8 +611,8 @@ test "fn with C calling convention returns struct by value" {
611 };611 };
612 }612 }
613 };613 };
614 S.entry();614 try S.entry();
615 comptime S.entry();615 comptime try S.entry();
616}616}
617617
618test "for loop over pointers to struct, getting field from struct pointer" {618test "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" {...@@ -633,7 +633,7 @@ test "for loop over pointers to struct, getting field from struct pointer" {
633 }633 }
634 };634 };
635635
636 fn doTheTest() void {636 fn doTheTest() !void {
637 var objects: ArrayList = undefined;637 var objects: ArrayList = undefined;
638638
639 for (objects.toSlice()) |obj| {639 for (objects.toSlice()) |obj| {
...@@ -642,10 +642,10 @@ test "for loop over pointers to struct, getting field from struct pointer" {...@@ -642,10 +642,10 @@ test "for loop over pointers to struct, getting field from struct pointer" {
642 }642 }
643 }643 }
644644
645 expect(ok);645 try expect(ok);
646 }646 }
647 };647 };
648 S.doTheTest();648 try S.doTheTest();
649}649}
650650
651test "zero-bit field in packed struct" {651test "zero-bit field in packed struct" {
...@@ -658,20 +658,20 @@ test "zero-bit field in packed struct" {...@@ -658,20 +658,20 @@ test "zero-bit field in packed struct" {
658658
659test "struct field init with catch" {659test "struct field init with catch" {
660 const S = struct {660 const S = struct {
661 fn doTheTest() void {661 fn doTheTest() !void {
662 var x: anyerror!isize = 1;662 var x: anyerror!isize = 1;
663 var req = Foo{663 var req = Foo{
664 .field = x catch undefined,664 .field = x catch undefined,
665 };665 };
666 expect(req.field == 1);666 try expect(req.field == 1);
667 }667 }
668668
669 pub const Foo = extern struct {669 pub const Foo = extern struct {
670 field: isize,670 field: isize,
671 };671 };
672 };672 };
673 S.doTheTest();673 try S.doTheTest();
674 comptime S.doTheTest();674 comptime try S.doTheTest();
675}675}
676676
677test "packed struct with non-ABI-aligned field" {677test "packed struct with non-ABI-aligned field" {
...@@ -682,8 +682,8 @@ test "packed struct with non-ABI-aligned field" {...@@ -682,8 +682,8 @@ test "packed struct with non-ABI-aligned field" {
682 var s: S = undefined;682 var s: S = undefined;
683 s.x = 1;683 s.x = 1;
684 s.y = 42;684 s.y = 42;
685 expect(s.x == 1);685 try expect(s.x == 1);
686 expect(s.y == 42);686 try expect(s.y == 42);
687}687}
688688
689test "non-packed struct with u128 entry in union" {689test "non-packed struct with u128 entry in union" {
...@@ -699,10 +699,10 @@ test "non-packed struct with u128 entry in union" {...@@ -699,10 +699,10 @@ test "non-packed struct with u128 entry in union" {
699699
700 var sx: S = undefined;700 var sx: S = undefined;
701 var s = &sx;701 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"));
703 var v2 = U{ .Num = 123 };703 var v2 = U{ .Num = 123 };
704 s.f2 = v2;704 s.f2 = v2;
705 std.testing.expect(s.f2.Num == 123);705 try std.testing.expect(s.f2.Num == 123);
706}706}
707707
708test "packed struct field passed to generic function" {708test "packed struct field passed to generic function" {
...@@ -722,7 +722,7 @@ test "packed struct field passed to generic function" {...@@ -722,7 +722,7 @@ test "packed struct field passed to generic function" {
722 var p: S.P = undefined;722 var p: S.P = undefined;
723 p.b = 29;723 p.b = 29;
724 var loaded = S.genericReadPackedField(&p.b);724 var loaded = S.genericReadPackedField(&p.b);
725 expect(loaded == 29);725 try expect(loaded == 29);
726}726}
727727
728test "anonymous struct literal syntax" {728test "anonymous struct literal syntax" {
...@@ -732,63 +732,63 @@ test "anonymous struct literal syntax" {...@@ -732,63 +732,63 @@ test "anonymous struct literal syntax" {
732 y: i32,732 y: i32,
733 };733 };
734734
735 fn doTheTest() void {735 fn doTheTest() !void {
736 var p: Point = .{736 var p: Point = .{
737 .x = 1,737 .x = 1,
738 .y = 2,738 .y = 2,
739 };739 };
740 expect(p.x == 1);740 try expect(p.x == 1);
741 expect(p.y == 2);741 try expect(p.y == 2);
742 }742 }
743 };743 };
744 S.doTheTest();744 try S.doTheTest();
745 comptime S.doTheTest();745 comptime try S.doTheTest();
746}746}
747747
748test "fully anonymous struct" {748test "fully anonymous struct" {
749 const S = struct {749 const S = struct {
750 fn doTheTest() void {750 fn doTheTest() !void {
751 dump(.{751 try dump(.{
752 .int = @as(u32, 1234),752 .int = @as(u32, 1234),
753 .float = @as(f64, 12.34),753 .float = @as(f64, 12.34),
754 .b = true,754 .b = true,
755 .s = "hi",755 .s = "hi",
756 });756 });
757 }757 }
758 fn dump(args: anytype) void {758 fn dump(args: anytype) !void {
759 expect(args.int == 1234);759 try expect(args.int == 1234);
760 expect(args.float == 12.34);760 try expect(args.float == 12.34);
761 expect(args.b);761 try expect(args.b);
762 expect(args.s[0] == 'h');762 try expect(args.s[0] == 'h');
763 expect(args.s[1] == 'i');763 try expect(args.s[1] == 'i');
764 }764 }
765 };765 };
766 S.doTheTest();766 try S.doTheTest();
767 comptime S.doTheTest();767 comptime try S.doTheTest();
768}768}
769769
770test "fully anonymous list literal" {770test "fully anonymous list literal" {
771 const S = struct {771 const S = struct {
772 fn doTheTest() void {772 fn doTheTest() !void {
773 dump(.{ @as(u32, 1234), @as(f64, 12.34), true, "hi" });773 try dump(.{ @as(u32, 1234), @as(f64, 12.34), true, "hi" });
774 }774 }
775 fn dump(args: anytype) void {775 fn dump(args: anytype) !void {
776 expect(args.@"0" == 1234);776 try expect(args.@"0" == 1234);
777 expect(args.@"1" == 12.34);777 try expect(args.@"1" == 12.34);
778 expect(args.@"2");778 try expect(args.@"2");
779 expect(args.@"3"[0] == 'h');779 try expect(args.@"3"[0] == 'h');
780 expect(args.@"3"[1] == 'i');780 try expect(args.@"3"[1] == 'i');
781 }781 }
782 };782 };
783 S.doTheTest();783 try S.doTheTest();
784 comptime S.doTheTest();784 comptime try S.doTheTest();
785}785}
786786
787test "anonymous struct literal assigned to variable" {787test "anonymous struct literal assigned to variable" {
788 var vec = .{ @as(i32, 22), @as(i32, 55), @as(i32, 99) };788 var vec = .{ @as(i32, 22), @as(i32, 55), @as(i32, 99) };
789 expect(vec.@"0" == 22);789 try expect(vec.@"0" == 22);
790 expect(vec.@"1" == 55);790 try expect(vec.@"1" == 55);
791 expect(vec.@"2" == 99);791 try expect(vec.@"2" == 99);
792}792}
793793
794test "struct with var field" {794test "struct with var field" {
...@@ -800,8 +800,8 @@ test "struct with var field" {...@@ -800,8 +800,8 @@ test "struct with var field" {
800 .x = 1,800 .x = 1,
801 .y = 2,801 .y = 2,
802 };802 };
803 expect(pt.x == 1);803 try expect(pt.x == 1);
804 expect(pt.y == 2);804 try expect(pt.y == 2);
805}805}
806806
807test "comptime struct field" {807test "comptime struct field" {
...@@ -811,21 +811,21 @@ test "comptime struct field" {...@@ -811,21 +811,21 @@ test "comptime struct field" {
811 };811 };
812812
813 var foo: T = undefined;813 var foo: T = undefined;
814 comptime expect(foo.b == 1234);814 comptime try expect(foo.b == 1234);
815}815}
816816
817test "anon struct literal field value initialized with fn call" {817test "anon struct literal field value initialized with fn call" {
818 const S = struct {818 const S = struct {
819 fn doTheTest() void {819 fn doTheTest() !void {
820 var x = .{foo()};820 var x = .{foo()};
821 expectEqualSlices(u8, x[0], "hi");821 try expectEqualSlices(u8, x[0], "hi");
822 }822 }
823 fn foo() []const u8 {823 fn foo() []const u8 {
824 return "hi";824 return "hi";
825 }825 }
826 };826 };
827 S.doTheTest();827 try S.doTheTest();
828 comptime S.doTheTest();828 comptime try S.doTheTest();
829}829}
830830
831test "self-referencing struct via array member" {831test "self-referencing struct via array member" {
...@@ -834,7 +834,7 @@ test "self-referencing struct via array member" {...@@ -834,7 +834,7 @@ test "self-referencing struct via array member" {
834 };834 };
835 var x: T = undefined;835 var x: T = undefined;
836 x = T{ .children = .{&x} };836 x = T{ .children = .{&x} };
837 expect(x.children[0] == &x);837 try expect(x.children[0] == &x);
838}838}
839839
840test "struct with union field" {840test "struct with union field" {
...@@ -849,8 +849,8 @@ test "struct with union field" {...@@ -849,8 +849,8 @@ test "struct with union field" {
849 var True = Value{849 var True = Value{
850 .kind = .{ .Bool = true },850 .kind = .{ .Bool = true },
851 };851 };
852 expectEqual(@as(u32, 2), True.ref);852 try expectEqual(@as(u32, 2), True.ref);
853 expectEqual(true, True.kind.Bool);853 try expectEqual(true, True.kind.Bool);
854}854}
855855
856test "type coercion of anon struct literal to struct" {856test "type coercion of anon struct literal to struct" {
...@@ -866,24 +866,24 @@ test "type coercion of anon struct literal to struct" {...@@ -866,24 +866,24 @@ test "type coercion of anon struct literal to struct" {
866 field: i32 = 1234,866 field: i32 = 1234,
867 };867 };
868868
869 fn doTheTest() void {869 fn doTheTest() !void {
870 var y: u32 = 42;870 var y: u32 = 42;
871 const t0 = .{ .A = 123, .B = "foo", .C = {} };871 const t0 = .{ .A = 123, .B = "foo", .C = {} };
872 const t1 = .{ .A = y, .B = "foo", .C = {} };872 const t1 = .{ .A = y, .B = "foo", .C = {} };
873 const y0: S2 = t0;873 const y0: S2 = t0;
874 var y1: S2 = t1;874 var y1: S2 = t1;
875 expect(y0.A == 123);875 try expect(y0.A == 123);
876 expect(std.mem.eql(u8, y0.B, "foo"));876 try expect(std.mem.eql(u8, y0.B, "foo"));
877 expect(y0.C == {});877 try expect(y0.C == {});
878 expect(y0.D.field == 1234);878 try expect(y0.D.field == 1234);
879 expect(y1.A == y);879 try expect(y1.A == y);
880 expect(std.mem.eql(u8, y1.B, "foo"));880 try expect(std.mem.eql(u8, y1.B, "foo"));
881 expect(y1.C == {});881 try expect(y1.C == {});
882 expect(y1.D.field == 1234);882 try expect(y1.D.field == 1234);
883 }883 }
884 };884 };
885 S.doTheTest();885 try S.doTheTest();
886 comptime S.doTheTest();886 comptime try S.doTheTest();
887}887}
888888
889test "type coercion of pointer to anon struct literal to pointer to struct" {889test "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" {...@@ -899,24 +899,24 @@ test "type coercion of pointer to anon struct literal to pointer to struct" {
899 field: i32 = 1234,899 field: i32 = 1234,
900 };900 };
901901
902 fn doTheTest() void {902 fn doTheTest() !void {
903 var y: u32 = 42;903 var y: u32 = 42;
904 const t0 = &.{ .A = 123, .B = "foo", .C = {} };904 const t0 = &.{ .A = 123, .B = "foo", .C = {} };
905 const t1 = &.{ .A = y, .B = "foo", .C = {} };905 const t1 = &.{ .A = y, .B = "foo", .C = {} };
906 const y0: *const S2 = t0;906 const y0: *const S2 = t0;
907 var y1: *const S2 = t1;907 var y1: *const S2 = t1;
908 expect(y0.A == 123);908 try expect(y0.A == 123);
909 expect(std.mem.eql(u8, y0.B, "foo"));909 try expect(std.mem.eql(u8, y0.B, "foo"));
910 expect(y0.C == {});910 try expect(y0.C == {});
911 expect(y0.D.field == 1234);911 try expect(y0.D.field == 1234);
912 expect(y1.A == y);912 try expect(y1.A == y);
913 expect(std.mem.eql(u8, y1.B, "foo"));913 try expect(std.mem.eql(u8, y1.B, "foo"));
914 expect(y1.C == {});914 try expect(y1.C == {});
915 expect(y1.D.field == 1234);915 try expect(y1.D.field == 1234);
916 }916 }
917 };917 };
918 S.doTheTest();918 try S.doTheTest();
919 comptime S.doTheTest();919 comptime try S.doTheTest();
920}920}
921921
922test "packed struct with undefined initializers" {922test "packed struct with undefined initializers" {
...@@ -930,16 +930,17 @@ test "packed struct with undefined initializers" {...@@ -930,16 +930,17 @@ test "packed struct with undefined initializers" {
930 _c: u3 = undefined,930 _c: u3 = undefined,
931 };931 };
932932
933 fn doTheTest() void {933 fn doTheTest() !void {
934 var p: P = undefined;934 var p: P = undefined;
935 p = P{ .a = 2, .b = 4, .c = 6 };935 p = P{ .a = 2, .b = 4, .c = 6 };
936 // Make sure the compiler doesn't touch the unprefixed fields.936 // Make sure the compiler doesn't touch the unprefixed fields.
937 expectEqual(@as(u3, 2), p.a);937 // Use expect since i386-linux doesn't like expectEqual
938 expectEqual(@as(u3, 4), p.b);938 try expect(p.a == 2);
939 expectEqual(@as(u3, 6), p.c);939 try expect(p.b == 4);
940 try expect(p.c == 6);
940 }941 }
941 };942 };
942943
943 S.doTheTest();944 try S.doTheTest();
944 comptime S.doTheTest();945 comptime try S.doTheTest();
945}946}
test/behavior/struct_contains_null_ptr_itself.zig+1-1
...@@ -3,7 +3,7 @@ const expect = std.testing.expect;...@@ -3,7 +3,7 @@ const expect = std.testing.expect;
33
4test "struct contains null pointer which contains original struct" {4test "struct contains null pointer which contains original struct" {
5 var x: ?*NodeLineComment = null;5 var x: ?*NodeLineComment = null;
6 expect(x == null);6 try expect(x == null);
7}7}
88
9pub const Node = struct {9pub const Node = struct {
test/behavior/struct_contains_slice_of_itself.zig+12-12
...@@ -39,12 +39,12 @@ test "struct contains slice of itself" {...@@ -39,12 +39,12 @@ test "struct contains slice of itself" {
39 .payload = 1234,39 .payload = 1234,
40 .children = nodes[0..],40 .children = nodes[0..],
41 };41 };
42 expect(root.payload == 1234);42 try expect(root.payload == 1234);
43 expect(root.children[0].payload == 1);43 try expect(root.children[0].payload == 1);
44 expect(root.children[1].payload == 2);44 try expect(root.children[1].payload == 2);
45 expect(root.children[2].payload == 3);45 try expect(root.children[2].payload == 3);
46 expect(root.children[2].children[0].payload == 31);46 try expect(root.children[2].children[0].payload == 31);
47 expect(root.children[2].children[1].payload == 32);47 try expect(root.children[2].children[1].payload == 32);
48}48}
4949
50test "struct contains aligned slice of itself" {50test "struct contains aligned slice of itself" {
...@@ -76,10 +76,10 @@ test "struct contains aligned slice of itself" {...@@ -76,10 +76,10 @@ test "struct contains aligned slice of itself" {
76 .payload = 1234,76 .payload = 1234,
77 .children = nodes[0..],77 .children = nodes[0..],
78 };78 };
79 expect(root.payload == 1234);79 try expect(root.payload == 1234);
80 expect(root.children[0].payload == 1);80 try expect(root.children[0].payload == 1);
81 expect(root.children[1].payload == 2);81 try expect(root.children[1].payload == 2);
82 expect(root.children[2].payload == 3);82 try expect(root.children[2].payload == 3);
83 expect(root.children[2].children[0].payload == 31);83 try expect(root.children[2].children[0].payload == 31);
84 expect(root.children[2].children[1].payload == 32);84 try expect(root.children[2].children[1].payload == 32);
85}85}
test/behavior/switch.zig+104-104
...@@ -4,23 +4,23 @@ const expectError = std.testing.expectError;...@@ -4,23 +4,23 @@ const expectError = std.testing.expectError;
4const expectEqual = std.testing.expectEqual;4const expectEqual = std.testing.expectEqual;
55
6test "switch with numbers" {6test "switch with numbers" {
7 testSwitchWithNumbers(13);7 try testSwitchWithNumbers(13);
8}8}
99
10fn testSwitchWithNumbers(x: u32) void {10fn testSwitchWithNumbers(x: u32) !void {
11 const result = switch (x) {11 const result = switch (x) {
12 1, 2, 3, 4...8 => false,12 1, 2, 3, 4...8 => false,
13 13 => true,13 13 => true,
14 else => false,14 else => false,
15 };15 };
16 expect(result);16 try expect(result);
17}17}
1818
19test "switch with all ranges" {19test "switch with all ranges" {
20 expect(testSwitchWithAllRanges(50, 3) == 1);20 try expect(testSwitchWithAllRanges(50, 3) == 1);
21 expect(testSwitchWithAllRanges(101, 0) == 2);21 try expect(testSwitchWithAllRanges(101, 0) == 2);
22 expect(testSwitchWithAllRanges(300, 5) == 3);22 try expect(testSwitchWithAllRanges(300, 5) == 3);
23 expect(testSwitchWithAllRanges(301, 6) == 6);23 try expect(testSwitchWithAllRanges(301, 6) == 6);
24}24}
2525
26fn testSwitchWithAllRanges(x: u32, y: u32) u32 {26fn testSwitchWithAllRanges(x: u32, y: u32) u32 {
...@@ -43,7 +43,7 @@ test "implicit comptime switch" {...@@ -43,7 +43,7 @@ test "implicit comptime switch" {
43 };43 };
4444
45 comptime {45 comptime {
46 expect(result + 1 == 14);46 try expect(result + 1 == 14);
47 }47 }
48}48}
4949
...@@ -65,16 +65,16 @@ fn nonConstSwitchOnEnum(fruit: Fruit) void {...@@ -65,16 +65,16 @@ fn nonConstSwitchOnEnum(fruit: Fruit) void {
65}65}
6666
67test "switch statement" {67test "switch statement" {
68 nonConstSwitch(SwitchStatmentFoo.C);68 try nonConstSwitch(SwitchStatmentFoo.C);
69}69}
70fn nonConstSwitch(foo: SwitchStatmentFoo) void {70fn nonConstSwitch(foo: SwitchStatmentFoo) !void {
71 const val = switch (foo) {71 const val = switch (foo) {
72 SwitchStatmentFoo.A => @as(i32, 1),72 SwitchStatmentFoo.A => @as(i32, 1),
73 SwitchStatmentFoo.B => 2,73 SwitchStatmentFoo.B => 2,
74 SwitchStatmentFoo.C => 3,74 SwitchStatmentFoo.C => 3,
75 SwitchStatmentFoo.D => 4,75 SwitchStatmentFoo.D => 4,
76 };76 };
77 expect(val == 3);77 try expect(val == 3);
78}78}
79const SwitchStatmentFoo = enum {79const SwitchStatmentFoo = enum {
80 A,80 A,
...@@ -84,22 +84,22 @@ const SwitchStatmentFoo = enum {...@@ -84,22 +84,22 @@ const SwitchStatmentFoo = enum {
84};84};
8585
86test "switch prong with variable" {86test "switch prong with variable" {
87 switchProngWithVarFn(SwitchProngWithVarEnum{ .One = 13 });87 try switchProngWithVarFn(SwitchProngWithVarEnum{ .One = 13 });
88 switchProngWithVarFn(SwitchProngWithVarEnum{ .Two = 13.0 });88 try switchProngWithVarFn(SwitchProngWithVarEnum{ .Two = 13.0 });
89 switchProngWithVarFn(SwitchProngWithVarEnum{ .Meh = {} });89 try switchProngWithVarFn(SwitchProngWithVarEnum{ .Meh = {} });
90}90}
91const SwitchProngWithVarEnum = union(enum) {91const SwitchProngWithVarEnum = union(enum) {
92 One: i32,92 One: i32,
93 Two: f32,93 Two: f32,
94 Meh: void,94 Meh: void,
95};95};
96fn switchProngWithVarFn(a: SwitchProngWithVarEnum) void {96fn switchProngWithVarFn(a: SwitchProngWithVarEnum) !void {
97 switch (a) {97 switch (a) {
98 SwitchProngWithVarEnum.One => |x| {98 SwitchProngWithVarEnum.One => |x| {
99 expect(x == 13);99 try expect(x == 13);
100 },100 },
101 SwitchProngWithVarEnum.Two => |x| {101 SwitchProngWithVarEnum.Two => |x| {
102 expect(x == 13.0);102 try expect(x == 13.0);
103 },103 },
104 SwitchProngWithVarEnum.Meh => |x| {104 SwitchProngWithVarEnum.Meh => |x| {
105 const v: void = x;105 const v: void = x;
...@@ -108,18 +108,18 @@ fn switchProngWithVarFn(a: SwitchProngWithVarEnum) void {...@@ -108,18 +108,18 @@ fn switchProngWithVarFn(a: SwitchProngWithVarEnum) void {
108}108}
109109
110test "switch on enum using pointer capture" {110test "switch on enum using pointer capture" {
111 testSwitchEnumPtrCapture();111 try testSwitchEnumPtrCapture();
112 comptime testSwitchEnumPtrCapture();112 comptime try testSwitchEnumPtrCapture();
113}113}
114114
115fn testSwitchEnumPtrCapture() void {115fn testSwitchEnumPtrCapture() !void {
116 var value = SwitchProngWithVarEnum{ .One = 1234 };116 var value = SwitchProngWithVarEnum{ .One = 1234 };
117 switch (value) {117 switch (value) {
118 SwitchProngWithVarEnum.One => |*x| x.* += 1,118 SwitchProngWithVarEnum.One => |*x| x.* += 1,
119 else => unreachable,119 else => unreachable,
120 }120 }
121 switch (value) {121 switch (value) {
122 SwitchProngWithVarEnum.One => |x| expect(x == 1235),122 SwitchProngWithVarEnum.One => |x| try expect(x == 1235),
123 else => unreachable,123 else => unreachable,
124 }124 }
125}125}
...@@ -130,7 +130,7 @@ test "switch with multiple expressions" {...@@ -130,7 +130,7 @@ test "switch with multiple expressions" {
130 4, 5, 6 => 2,130 4, 5, 6 => 2,
131 else => @as(i32, 3),131 else => @as(i32, 3),
132 };132 };
133 expect(x == 2);133 try expect(x == 2);
134}134}
135fn returnsFive() i32 {135fn returnsFive() i32 {
136 return 5;136 return 5;
...@@ -152,12 +152,12 @@ fn returnsFalse() bool {...@@ -152,12 +152,12 @@ fn returnsFalse() bool {
152 }152 }
153}153}
154test "switch on const enum with var" {154test "switch on const enum with var" {
155 expect(!returnsFalse());155 try expect(!returnsFalse());
156}156}
157157
158test "switch on type" {158test "switch on type" {
159 expect(trueIfBoolFalseOtherwise(bool));159 try expect(trueIfBoolFalseOtherwise(bool));
160 expect(!trueIfBoolFalseOtherwise(i32));160 try expect(!trueIfBoolFalseOtherwise(i32));
161}161}
162162
163fn trueIfBoolFalseOtherwise(comptime T: type) bool {163fn trueIfBoolFalseOtherwise(comptime T: type) bool {
...@@ -168,21 +168,21 @@ fn trueIfBoolFalseOtherwise(comptime T: type) bool {...@@ -168,21 +168,21 @@ fn trueIfBoolFalseOtherwise(comptime T: type) bool {
168}168}
169169
170test "switch handles all cases of number" {170test "switch handles all cases of number" {
171 testSwitchHandleAllCases();171 try testSwitchHandleAllCases();
172 comptime testSwitchHandleAllCases();172 comptime try testSwitchHandleAllCases();
173}173}
174174
175fn testSwitchHandleAllCases() void {175fn testSwitchHandleAllCases() !void {
176 expect(testSwitchHandleAllCasesExhaustive(0) == 3);176 try expect(testSwitchHandleAllCasesExhaustive(0) == 3);
177 expect(testSwitchHandleAllCasesExhaustive(1) == 2);177 try expect(testSwitchHandleAllCasesExhaustive(1) == 2);
178 expect(testSwitchHandleAllCasesExhaustive(2) == 1);178 try expect(testSwitchHandleAllCasesExhaustive(2) == 1);
179 expect(testSwitchHandleAllCasesExhaustive(3) == 0);179 try expect(testSwitchHandleAllCasesExhaustive(3) == 0);
180180
181 expect(testSwitchHandleAllCasesRange(100) == 0);181 try expect(testSwitchHandleAllCasesRange(100) == 0);
182 expect(testSwitchHandleAllCasesRange(200) == 1);182 try expect(testSwitchHandleAllCasesRange(200) == 1);
183 expect(testSwitchHandleAllCasesRange(201) == 2);183 try expect(testSwitchHandleAllCasesRange(201) == 2);
184 expect(testSwitchHandleAllCasesRange(202) == 4);184 try expect(testSwitchHandleAllCasesRange(202) == 4);
185 expect(testSwitchHandleAllCasesRange(230) == 3);185 try expect(testSwitchHandleAllCasesRange(230) == 3);
186}186}
187187
188fn testSwitchHandleAllCasesExhaustive(x: u2) u2 {188fn testSwitchHandleAllCasesExhaustive(x: u2) u2 {
...@@ -205,13 +205,13 @@ fn testSwitchHandleAllCasesRange(x: u8) u8 {...@@ -205,13 +205,13 @@ fn testSwitchHandleAllCasesRange(x: u8) u8 {
205}205}
206206
207test "switch all prongs unreachable" {207test "switch all prongs unreachable" {
208 testAllProngsUnreachable();208 try testAllProngsUnreachable();
209 comptime testAllProngsUnreachable();209 comptime try testAllProngsUnreachable();
210}210}
211211
212fn testAllProngsUnreachable() void {212fn testAllProngsUnreachable() !void {
213 expect(switchWithUnreachable(1) == 2);213 try expect(switchWithUnreachable(1) == 2);
214 expect(switchWithUnreachable(2) == 10);214 try expect(switchWithUnreachable(2) == 10);
215}215}
216216
217fn switchWithUnreachable(x: i32) i32 {217fn switchWithUnreachable(x: i32) i32 {
...@@ -233,23 +233,23 @@ test "capture value of switch with all unreachable prongs" {...@@ -233,23 +233,23 @@ test "capture value of switch with all unreachable prongs" {
233 const x = return_a_number() catch |err| switch (err) {233 const x = return_a_number() catch |err| switch (err) {
234 else => unreachable,234 else => unreachable,
235 };235 };
236 expect(x == 1);236 try expect(x == 1);
237}237}
238238
239test "switching on booleans" {239test "switching on booleans" {
240 testSwitchOnBools();240 try testSwitchOnBools();
241 comptime testSwitchOnBools();241 comptime try testSwitchOnBools();
242}242}
243243
244fn testSwitchOnBools() void {244fn testSwitchOnBools() !void {
245 expect(testSwitchOnBoolsTrueAndFalse(true) == false);245 try expect(testSwitchOnBoolsTrueAndFalse(true) == false);
246 expect(testSwitchOnBoolsTrueAndFalse(false) == true);246 try expect(testSwitchOnBoolsTrueAndFalse(false) == true);
247247
248 expect(testSwitchOnBoolsTrueWithElse(true) == false);248 try expect(testSwitchOnBoolsTrueWithElse(true) == false);
249 expect(testSwitchOnBoolsTrueWithElse(false) == true);249 try expect(testSwitchOnBoolsTrueWithElse(false) == true);
250250
251 expect(testSwitchOnBoolsFalseWithElse(true) == false);251 try expect(testSwitchOnBoolsFalseWithElse(true) == false);
252 expect(testSwitchOnBoolsFalseWithElse(false) == true);252 try expect(testSwitchOnBoolsFalseWithElse(false) == true);
253}253}
254254
255fn testSwitchOnBoolsTrueAndFalse(x: bool) bool {255fn testSwitchOnBoolsTrueAndFalse(x: bool) bool {
...@@ -276,14 +276,14 @@ fn testSwitchOnBoolsFalseWithElse(x: bool) bool {...@@ -276,14 +276,14 @@ fn testSwitchOnBoolsFalseWithElse(x: bool) bool {
276test "u0" {276test "u0" {
277 var val: u0 = 0;277 var val: u0 = 0;
278 switch (val) {278 switch (val) {
279 0 => expect(val == 0),279 0 => try expect(val == 0),
280 }280 }
281}281}
282282
283test "undefined.u0" {283test "undefined.u0" {
284 var val: u0 = undefined;284 var val: u0 = undefined;
285 switch (val) {285 switch (val) {
286 0 => expect(val == 0),286 0 => try expect(val == 0),
287 }287 }
288}288}
289289
...@@ -295,15 +295,15 @@ test "anon enum literal used in switch on union enum" {...@@ -295,15 +295,15 @@ test "anon enum literal used in switch on union enum" {
295 var foo = Foo{ .a = 1234 };295 var foo = Foo{ .a = 1234 };
296 switch (foo) {296 switch (foo) {
297 .a => |x| {297 .a => |x| {
298 expect(x == 1234);298 try expect(x == 1234);
299 },299 },
300 }300 }
301}301}
302302
303test "else prong of switch on error set excludes other cases" {303test "else prong of switch on error set excludes other cases" {
304 const S = struct {304 const S = struct {
305 fn doTheTest() void {305 fn doTheTest() !void {
306 expectError(error.C, bar());306 try expectError(error.C, bar());
307 }307 }
308 const E = error{308 const E = error{
309 A,309 A,
...@@ -326,14 +326,14 @@ test "else prong of switch on error set excludes other cases" {...@@ -326,14 +326,14 @@ test "else prong of switch on error set excludes other cases" {
326 };326 };
327 }327 }
328 };328 };
329 S.doTheTest();329 try S.doTheTest();
330 comptime S.doTheTest();330 comptime try S.doTheTest();
331}331}
332332
333test "switch prongs with error set cases make a new error set type for capture value" {333test "switch prongs with error set cases make a new error set type for capture value" {
334 const S = struct {334 const S = struct {
335 fn doTheTest() void {335 fn doTheTest() !void {
336 expectError(error.B, bar());336 try expectError(error.B, bar());
337 }337 }
338 const E = E1 || E2;338 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...@@ -358,14 +358,14 @@ test "switch prongs with error set cases make a new error set type for capture v
358 };358 };
359 }359 }
360 };360 };
361 S.doTheTest();361 try S.doTheTest();
362 comptime S.doTheTest();362 comptime try S.doTheTest();
363}363}
364364
365test "return result loc and then switch with range implicit casted to error union" {365test "return result loc and then switch with range implicit casted to error union" {
366 const S = struct {366 const S = struct {
367 fn doTheTest() void {367 fn doTheTest() !void {
368 expect((func(0xb) catch unreachable) == 0xb);368 try expect((func(0xb) catch unreachable) == 0xb);
369 }369 }
370 fn func(d: u8) anyerror!u8 {370 fn func(d: u8) anyerror!u8 {
371 return switch (d) {371 return switch (d) {
...@@ -374,13 +374,13 @@ test "return result loc and then switch with range implicit casted to error unio...@@ -374,13 +374,13 @@ test "return result loc and then switch with range implicit casted to error unio
374 };374 };
375 }375 }
376 };376 };
377 S.doTheTest();377 try S.doTheTest();
378 comptime S.doTheTest();378 comptime try S.doTheTest();
379}379}
380380
381test "switch with null and T peer types and inferred result location type" {381test "switch with null and T peer types and inferred result location type" {
382 const S = struct {382 const S = struct {
383 fn doTheTest(c: u8) void {383 fn doTheTest(c: u8) !void {
384 if (switch (c) {384 if (switch (c) {
385 0 => true,385 0 => true,
386 else => null,386 else => null,
...@@ -389,8 +389,8 @@ test "switch with null and T peer types and inferred result location type" {...@@ -389,8 +389,8 @@ test "switch with null and T peer types and inferred result location type" {
389 }389 }
390 }390 }
391 };391 };
392 S.doTheTest(1);392 try S.doTheTest(1);
393 comptime S.doTheTest(1);393 comptime try S.doTheTest(1);
394}394}
395395
396test "switch prongs with cases with identical payload types" {396test "switch prongs with cases with identical payload types" {
...@@ -400,31 +400,31 @@ test "switch prongs with cases with identical payload types" {...@@ -400,31 +400,31 @@ test "switch prongs with cases with identical payload types" {
400 C: usize,400 C: usize,
401 };401 };
402 const S = struct {402 const S = struct {
403 fn doTheTest() void {403 fn doTheTest() !void {
404 doTheSwitch1(Union{ .A = 8 });404 try doTheSwitch1(Union{ .A = 8 });
405 doTheSwitch2(Union{ .B = -8 });405 try doTheSwitch2(Union{ .B = -8 });
406 }406 }
407 fn doTheSwitch1(u: Union) void {407 fn doTheSwitch1(u: Union) !void {
408 switch (u) {408 switch (u) {
409 .A, .C => |e| {409 .A, .C => |e| {
410 expect(@TypeOf(e) == usize);410 try expect(@TypeOf(e) == usize);
411 expect(e == 8);411 try expect(e == 8);
412 },412 },
413 .B => |e| @panic("fail"),413 .B => |e| @panic("fail"),
414 }414 }
415 }415 }
416 fn doTheSwitch2(u: Union) void {416 fn doTheSwitch2(u: Union) !void {
417 switch (u) {417 switch (u) {
418 .A, .C => |e| @panic("fail"),418 .A, .C => |e| @panic("fail"),
419 .B => |e| {419 .B => |e| {
420 expect(@TypeOf(e) == isize);420 try expect(@TypeOf(e) == isize);
421 expect(e == -8);421 try expect(e == -8);
422 },422 },
423 }423 }
424 }424 }
425 };425 };
426 S.doTheTest();426 try S.doTheTest();
427 comptime S.doTheTest();427 comptime try S.doTheTest();
428}428}
429429
430test "switch with disjoint range" {430test "switch with disjoint range" {
...@@ -438,19 +438,19 @@ test "switch with disjoint range" {...@@ -438,19 +438,19 @@ test "switch with disjoint range" {
438438
439test "switch variable for range and multiple prongs" {439test "switch variable for range and multiple prongs" {
440 const S = struct {440 const S = struct {
441 fn doTheTest() void {441 fn doTheTest() !void {
442 var u: u8 = 16;442 var u: u8 = 16;
443 doTheSwitch(u);443 try doTheSwitch(u);
444 comptime doTheSwitch(u);444 comptime try doTheSwitch(u);
445 var v: u8 = 42;445 var v: u8 = 42;
446 doTheSwitch(v);446 try doTheSwitch(v);
447 comptime doTheSwitch(v);447 comptime try doTheSwitch(v);
448 }448 }
449 fn doTheSwitch(q: u8) void {449 fn doTheSwitch(q: u8) !void {
450 switch (q) {450 switch (q) {
451 0...40 => |x| expect(x == 16),451 0...40 => |x| try expect(x == 16),
452 41, 42, 43 => |x| expect(x == 42),452 41, 42, 43 => |x| try expect(x == 42),
453 else => expect(false),453 else => try expect(false),
454 }454 }
455 }455 }
456 };456 };
...@@ -493,31 +493,31 @@ test "switch on pointer type" {...@@ -493,31 +493,31 @@ test "switch on pointer type" {
493 }493 }
494 };494 };
495495
496 expect(1 == S.doTheTest(S.P1));496 try expect(1 == S.doTheTest(S.P1));
497 expect(2 == S.doTheTest(S.P2));497 try expect(2 == S.doTheTest(S.P2));
498 expect(3 == S.doTheTest(S.P3));498 try expect(3 == S.doTheTest(S.P3));
499 comptime expect(1 == S.doTheTest(S.P1));499 comptime try expect(1 == S.doTheTest(S.P1));
500 comptime expect(2 == S.doTheTest(S.P2));500 comptime try expect(2 == S.doTheTest(S.P2));
501 comptime expect(3 == S.doTheTest(S.P3));501 comptime try expect(3 == S.doTheTest(S.P3));
502}502}
503503
504test "switch on error set with single else" {504test "switch on error set with single else" {
505 const S = struct {505 const S = struct {
506 fn doTheTest() void {506 fn doTheTest() !void {
507 var some: error{Foo} = error.Foo;507 var some: error{Foo} = error.Foo;
508 expect(switch (some) {508 try expect(switch (some) {
509 else => |a| true,509 else => |a| true,
510 });510 });
511 }511 }
512 };512 };
513513
514 S.doTheTest();514 try S.doTheTest();
515 comptime S.doTheTest();515 comptime try S.doTheTest();
516}516}
517517
518test "while copies its payload" {518test "while copies its payload" {
519 const S = struct {519 const S = struct {
520 fn doTheTest() void {520 fn doTheTest() !void {
521 var tmp: union(enum) {521 var tmp: union(enum) {
522 A: u8,522 A: u8,
523 B: u32,523 B: u32,
...@@ -526,12 +526,12 @@ test "while copies its payload" {...@@ -526,12 +526,12 @@ test "while copies its payload" {
526 .A => |value| {526 .A => |value| {
527 // Modify the original union527 // Modify the original union
528 tmp = .{ .B = 0x10101010 };528 tmp = .{ .B = 0x10101010 };
529 expectEqual(@as(u8, 42), value);529 try expectEqual(@as(u8, 42), value);
530 },530 },
531 else => unreachable,531 else => unreachable,
532 }532 }
533 }533 }
534 };534 };
535 S.doTheTest();535 try S.doTheTest();
536 comptime S.doTheTest();536 comptime try S.doTheTest();
537}537}
test/behavior/switch_prong_err_enum.zig+2-2
...@@ -22,9 +22,9 @@ fn doThing(form_id: u64) anyerror!FormValue {...@@ -22,9 +22,9 @@ fn doThing(form_id: u64) anyerror!FormValue {
22test "switch prong returns error enum" {22test "switch prong returns error enum" {
23 switch (doThing(17) catch unreachable) {23 switch (doThing(17) catch unreachable) {
24 FormValue.Address => |payload| {24 FormValue.Address => |payload| {
25 expect(payload == 1);25 try expect(payload == 1);
26 },26 },
27 else => unreachable,27 else => unreachable,
28 }28 }
29 expect(read_count == 1);29 try expect(read_count == 1);
30}30}
test/behavior/switch_prong_implicit_cast.zig+1-1
...@@ -18,5 +18,5 @@ test "switch prong implicit cast" {...@@ -18,5 +18,5 @@ test "switch prong implicit cast" {
18 FormValue.One => false,18 FormValue.One => false,
19 FormValue.Two => |x| x,19 FormValue.Two => |x| x,
20 };20 };
21 expect(result);21 try expect(result);
22}22}
test/behavior/this.zig+3-3
...@@ -20,7 +20,7 @@ fn add(x: i32, y: i32) i32 {...@@ -20,7 +20,7 @@ fn add(x: i32, y: i32) i32 {
20}20}
2121
22test "this refer to module call private fn" {22test "this refer to module call private fn" {
23 expect(module.add(1, 2) == 3);23 try expect(module.add(1, 2) == 3);
24}24}
2525
26test "this refer to container" {26test "this refer to container" {
...@@ -29,6 +29,6 @@ test "this refer to container" {...@@ -29,6 +29,6 @@ test "this refer to container" {
29 .y = 34,29 .y = 34,
30 };30 };
31 pt.addOne();31 pt.addOne();
32 expect(pt.x == 13);32 try expect(pt.x == 13);
33 expect(pt.y == 35);33 try expect(pt.y == 35);
34}34}
test/behavior/translate_c_macros.zig+4-4
...@@ -4,7 +4,7 @@ const expectEqual = @import("std").testing.expectEqual;...@@ -4,7 +4,7 @@ const expectEqual = @import("std").testing.expectEqual;
4const h = @cImport(@cInclude("behavior/translate_c_macros.h"));4const h = @cImport(@cInclude("behavior/translate_c_macros.h"));
55
6test "initializer list expression" {6test "initializer list expression" {
7 expectEqual(h.Color{7 try expectEqual(h.Color{
8 .r = 200,8 .r = 200,
9 .g = 200,9 .g = 200,
10 .b = 200,10 .b = 200,
...@@ -13,10 +13,10 @@ test "initializer list expression" {...@@ -13,10 +13,10 @@ test "initializer list expression" {
13}13}
1414
15test "sizeof in macros" {15test "sizeof in macros" {
16 expectEqual(@as(c_int, @sizeOf(u32)), h.MY_SIZEOF(u32));16 try expectEqual(@as(c_int, @sizeOf(u32)), h.MY_SIZEOF(u32));
17 expectEqual(@as(c_int, @sizeOf(u32)), h.MY_SIZEOF2(u32));17 try expectEqual(@as(c_int, @sizeOf(u32)), h.MY_SIZEOF2(u32));
18}18}
1919
20test "reference to a struct type" {20test "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);
22}22}
test/behavior/truncate.zig+6-6
...@@ -4,33 +4,33 @@ const expect = std.testing.expect;...@@ -4,33 +4,33 @@ const expect = std.testing.expect;
4test "truncate u0 to larger integer allowed and has comptime known result" {4test "truncate u0 to larger integer allowed and has comptime known result" {
5 var x: u0 = 0;5 var x: u0 = 0;
6 const y = @truncate(u8, x);6 const y = @truncate(u8, x);
7 comptime expect(y == 0);7 comptime try expect(y == 0);
8}8}
99
10test "truncate.u0.literal" {10test "truncate.u0.literal" {
11 var z = @truncate(u0, 0);11 var z = @truncate(u0, 0);
12 expect(z == 0);12 try expect(z == 0);
13}13}
1414
15test "truncate.u0.const" {15test "truncate.u0.const" {
16 const c0: usize = 0;16 const c0: usize = 0;
17 var z = @truncate(u0, c0);17 var z = @truncate(u0, c0);
18 expect(z == 0);18 try expect(z == 0);
19}19}
2020
21test "truncate.u0.var" {21test "truncate.u0.var" {
22 var d: u8 = 2;22 var d: u8 = 2;
23 var z = @truncate(u0, d);23 var z = @truncate(u0, d);
24 expect(z == 0);24 try expect(z == 0);
25}25}
2626
27test "truncate sign mismatch but comptime known so it works anyway" {27test "truncate sign mismatch but comptime known so it works anyway" {
28 const x: u32 = 10;28 const x: u32 = 10;
29 var result = @truncate(i8, x);29 var result = @truncate(i8, x);
30 expect(result == 10);30 try expect(result == 10);
31}31}
3232
33test "truncate on comptime integer" {33test "truncate on comptime integer" {
34 var x = @truncate(u16, 9999);34 var x = @truncate(u16, 9999);
35 expect(x == 9999);35 try expect(x == 9999);
36}36}
test/behavior/try.zig+7-7
...@@ -1,17 +1,17 @@...@@ -1,17 +1,17 @@
1const expect = @import("std").testing.expect;1const expect = @import("std").testing.expect;
22
3test "try on error union" {3test "try on error union" {
4 tryOnErrorUnionImpl();4 try tryOnErrorUnionImpl();
5 comptime tryOnErrorUnionImpl();5 comptime try tryOnErrorUnionImpl();
6}6}
77
8fn tryOnErrorUnionImpl() void {8fn tryOnErrorUnionImpl() !void {
9 const x = if (returnsTen()) |val| val + 1 else |err| switch (err) {9 const x = if (returnsTen()) |val| val + 1 else |err| switch (err) {
10 error.ItBroke, error.NoMem => 1,10 error.ItBroke, error.NoMem => 1,
11 error.CrappedOut => @as(i32, 2),11 error.CrappedOut => @as(i32, 2),
12 else => unreachable,12 else => unreachable,
13 };13 };
14 expect(x == 11);14 try expect(x == 11);
15}15}
1616
17fn returnsTen() anyerror!i32 {17fn returnsTen() anyerror!i32 {
...@@ -20,10 +20,10 @@ fn returnsTen() anyerror!i32 {...@@ -20,10 +20,10 @@ fn returnsTen() anyerror!i32 {
2020
21test "try without vars" {21test "try without vars" {
22 const result1 = if (failIfTrue(true)) 1 else |_| @as(i32, 2);22 const result1 = if (failIfTrue(true)) 1 else |_| @as(i32, 2);
23 expect(result1 == 2);23 try expect(result1 == 2);
2424
25 const result2 = if (failIfTrue(false)) 1 else |_| @as(i32, 2);25 const result2 = if (failIfTrue(false)) 1 else |_| @as(i32, 2);
26 expect(result2 == 1);26 try expect(result2 == 1);
27}27}
2828
29fn failIfTrue(ok: bool) anyerror!void {29fn failIfTrue(ok: bool) anyerror!void {
...@@ -38,6 +38,6 @@ test "try then not executed with assignment" {...@@ -38,6 +38,6 @@ test "try then not executed with assignment" {
38 if (failIfTrue(true)) {38 if (failIfTrue(true)) {
39 unreachable;39 unreachable;
40 } else |err| {40 } else |err| {
41 expect(err == error.ItBroke);41 try expect(err == error.ItBroke);
42 }42 }
43}43}
test/behavior/tuple.zig+44-44
...@@ -5,93 +5,93 @@ const expectEqual = testing.expectEqual;...@@ -5,93 +5,93 @@ const expectEqual = testing.expectEqual;
55
6test "tuple concatenation" {6test "tuple concatenation" {
7 const S = struct {7 const S = struct {
8 fn doTheTest() void {8 fn doTheTest() !void {
9 var a: i32 = 1;9 var a: i32 = 1;
10 var b: i32 = 2;10 var b: i32 = 2;
11 var x = .{a};11 var x = .{a};
12 var y = .{b};12 var y = .{b};
13 var c = x ++ y;13 var c = x ++ y;
14 expectEqual(@as(i32, 1), c[0]);14 try expectEqual(@as(i32, 1), c[0]);
15 expectEqual(@as(i32, 2), c[1]);15 try expectEqual(@as(i32, 2), c[1]);
16 }16 }
17 };17 };
18 S.doTheTest();18 try S.doTheTest();
19 comptime S.doTheTest();19 comptime try S.doTheTest();
20}20}
2121
22test "tuple multiplication" {22test "tuple multiplication" {
23 const S = struct {23 const S = struct {
24 fn doTheTest() void {24 fn doTheTest() !void {
25 {25 {
26 const t = .{} ** 4;26 const t = .{} ** 4;
27 expectEqual(0, @typeInfo(@TypeOf(t)).Struct.fields.len);27 try expectEqual(0, @typeInfo(@TypeOf(t)).Struct.fields.len);
28 }28 }
29 {29 {
30 const t = .{'a'} ** 4;30 const t = .{'a'} ** 4;
31 expectEqual(4, @typeInfo(@TypeOf(t)).Struct.fields.len);31 try expectEqual(4, @typeInfo(@TypeOf(t)).Struct.fields.len);
32 inline for (t) |x| expectEqual('a', x);32 inline for (t) |x| try expectEqual('a', x);
33 }33 }
34 {34 {
35 const t = .{ 1, 2, 3 } ** 4;35 const t = .{ 1, 2, 3 } ** 4;
36 expectEqual(12, @typeInfo(@TypeOf(t)).Struct.fields.len);36 try expectEqual(12, @typeInfo(@TypeOf(t)).Struct.fields.len);
37 inline for (t) |x, i| expectEqual(1 + i % 3, x);37 inline for (t) |x, i| try expectEqual(1 + i % 3, x);
38 }38 }
39 }39 }
40 };40 };
41 S.doTheTest();41 try S.doTheTest();
42 comptime S.doTheTest();42 comptime try S.doTheTest();
4343
44 const T = struct {44 const T = struct {
45 fn consume_tuple(tuple: anytype, len: usize) void {45 fn consume_tuple(tuple: anytype, len: usize) !void {
46 expect(tuple.len == len);46 try expect(tuple.len == len);
47 }47 }
4848
49 fn doTheTest() void {49 fn doTheTest() !void {
50 const t1 = .{};50 const t1 = .{};
5151
52 var rt_var: u8 = 42;52 var rt_var: u8 = 42;
53 const t2 = .{rt_var} ++ .{};53 const t2 = .{rt_var} ++ .{};
5454
55 expect(t2.len == 1);55 try expect(t2.len == 1);
56 expect(t2.@"0" == rt_var);56 try expect(t2.@"0" == rt_var);
57 expect(t2.@"0" == 42);57 try expect(t2.@"0" == 42);
58 expect(&t2.@"0" != &rt_var);58 try expect(&t2.@"0" != &rt_var);
5959
60 consume_tuple(t1 ++ t1, 0);60 try consume_tuple(t1 ++ t1, 0);
61 consume_tuple(.{} ++ .{}, 0);61 try consume_tuple(.{} ++ .{}, 0);
62 consume_tuple(.{0} ++ .{}, 1);62 try consume_tuple(.{0} ++ .{}, 1);
63 consume_tuple(.{0} ++ .{1}, 2);63 try consume_tuple(.{0} ++ .{1}, 2);
64 consume_tuple(.{ 0, 1, 2 } ++ .{ u8, 1, noreturn }, 6);64 try consume_tuple(.{ 0, 1, 2 } ++ .{ u8, 1, noreturn }, 6);
65 consume_tuple(t2 ++ t1, 1);65 try consume_tuple(t2 ++ t1, 1);
66 consume_tuple(t1 ++ t2, 1);66 try consume_tuple(t1 ++ t2, 1);
67 consume_tuple(t2 ++ t2, 2);67 try consume_tuple(t2 ++ t2, 2);
68 consume_tuple(.{rt_var} ++ .{}, 1);68 try consume_tuple(.{rt_var} ++ .{}, 1);
69 consume_tuple(.{rt_var} ++ t1, 1);69 try consume_tuple(.{rt_var} ++ t1, 1);
70 consume_tuple(.{} ++ .{rt_var}, 1);70 try consume_tuple(.{} ++ .{rt_var}, 1);
71 consume_tuple(t2 ++ .{void}, 2);71 try consume_tuple(t2 ++ .{void}, 2);
72 consume_tuple(t2 ++ .{0}, 2);72 try consume_tuple(t2 ++ .{0}, 2);
73 consume_tuple(.{0} ++ t2, 2);73 try consume_tuple(.{0} ++ t2, 2);
74 consume_tuple(.{void} ++ t2, 2);74 try consume_tuple(.{void} ++ t2, 2);
75 consume_tuple(.{u8} ++ .{rt_var} ++ .{true}, 3);75 try consume_tuple(.{u8} ++ .{rt_var} ++ .{true}, 3);
76 }76 }
77 };77 };
7878
79 T.doTheTest();79 try T.doTheTest();
80 comptime T.doTheTest();80 comptime try T.doTheTest();
81}81}
8282
83test "pass tuple to comptime var parameter" {83test "pass tuple to comptime var parameter" {
84 const S = struct {84 const S = struct {
85 fn Foo(comptime args: anytype) void {85 fn Foo(comptime args: anytype) !void {
86 expect(args[0] == 1);86 try expect(args[0] == 1);
87 }87 }
8888
89 fn doTheTest() void {89 fn doTheTest() !void {
90 Foo(.{1});90 try Foo(.{1});
91 }91 }
92 };92 };
93 S.doTheTest();93 try S.doTheTest();
94 comptime S.doTheTest();94 comptime try S.doTheTest();
95}95}
9696
97test "tuple initializer for var" {97test "tuple initializer for var" {
test/behavior/type.zig+84-84
...@@ -3,52 +3,52 @@ const builtin = @import("builtin");...@@ -3,52 +3,52 @@ const builtin = @import("builtin");
3const TypeInfo = std.builtin.TypeInfo;3const TypeInfo = std.builtin.TypeInfo;
4const testing = std.testing;4const testing = std.testing;
55
6fn testTypes(comptime types: []const type) void {6fn testTypes(comptime types: []const type) !void {
7 inline for (types) |testType| {7 inline for (types) |testType| {
8 testing.expect(testType == @Type(@typeInfo(testType)));8 try testing.expect(testType == @Type(@typeInfo(testType)));
9 }9 }
10}10}
1111
12test "Type.MetaType" {12test "Type.MetaType" {
13 testing.expect(type == @Type(TypeInfo{ .Type = undefined }));13 try testing.expect(type == @Type(TypeInfo{ .Type = undefined }));
14 testTypes(&[_]type{type});14 try testTypes(&[_]type{type});
15}15}
1616
17test "Type.Void" {17test "Type.Void" {
18 testing.expect(void == @Type(TypeInfo{ .Void = undefined }));18 try testing.expect(void == @Type(TypeInfo{ .Void = undefined }));
19 testTypes(&[_]type{void});19 try testTypes(&[_]type{void});
20}20}
2121
22test "Type.Bool" {22test "Type.Bool" {
23 testing.expect(bool == @Type(TypeInfo{ .Bool = undefined }));23 try testing.expect(bool == @Type(TypeInfo{ .Bool = undefined }));
24 testTypes(&[_]type{bool});24 try testTypes(&[_]type{bool});
25}25}
2626
27test "Type.NoReturn" {27test "Type.NoReturn" {
28 testing.expect(noreturn == @Type(TypeInfo{ .NoReturn = undefined }));28 try testing.expect(noreturn == @Type(TypeInfo{ .NoReturn = undefined }));
29 testTypes(&[_]type{noreturn});29 try testTypes(&[_]type{noreturn});
30}30}
3131
32test "Type.Int" {32test "Type.Int" {
33 testing.expect(u1 == @Type(TypeInfo{ .Int = TypeInfo.Int{ .signedness = .unsigned, .bits = 1 } }));33 try 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 } }));34 try 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 } }));35 try 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 } }));36 try 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 } }));37 try 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 } }));38 try testing.expect(i64 == @Type(TypeInfo{ .Int = TypeInfo.Int{ .signedness = .signed, .bits = 64 } }));
39 testTypes(&[_]type{ u8, u32, i64 });39 try testTypes(&[_]type{ u8, u32, i64 });
40}40}
4141
42test "Type.Float" {42test "Type.Float" {
43 testing.expect(f16 == @Type(TypeInfo{ .Float = TypeInfo.Float{ .bits = 16 } }));43 try testing.expect(f16 == @Type(TypeInfo{ .Float = TypeInfo.Float{ .bits = 16 } }));
44 testing.expect(f32 == @Type(TypeInfo{ .Float = TypeInfo.Float{ .bits = 32 } }));44 try testing.expect(f32 == @Type(TypeInfo{ .Float = TypeInfo.Float{ .bits = 32 } }));
45 testing.expect(f64 == @Type(TypeInfo{ .Float = TypeInfo.Float{ .bits = 64 } }));45 try testing.expect(f64 == @Type(TypeInfo{ .Float = TypeInfo.Float{ .bits = 64 } }));
46 testing.expect(f128 == @Type(TypeInfo{ .Float = TypeInfo.Float{ .bits = 128 } }));46 try testing.expect(f128 == @Type(TypeInfo{ .Float = TypeInfo.Float{ .bits = 128 } }));
47 testTypes(&[_]type{ f16, f32, f64, f128 });47 try testTypes(&[_]type{ f16, f32, f64, f128 });
48}48}
4949
50test "Type.Pointer" {50test "Type.Pointer" {
51 testTypes(&[_]type{51 try testTypes(&[_]type{
52 // One Value Pointer Types52 // One Value Pointer Types
53 *u8, *const u8,53 *u8, *const u8,
54 *volatile u8, *const volatile u8,54 *volatile u8, *const volatile u8,
...@@ -93,41 +93,41 @@ test "Type.Pointer" {...@@ -93,41 +93,41 @@ test "Type.Pointer" {
93}93}
9494
95test "Type.Array" {95test "Type.Array" {
96 testing.expect([123]u8 == @Type(TypeInfo{96 try testing.expect([123]u8 == @Type(TypeInfo{
97 .Array = TypeInfo.Array{97 .Array = TypeInfo.Array{
98 .len = 123,98 .len = 123,
99 .child = u8,99 .child = u8,
100 .sentinel = null,100 .sentinel = null,
101 },101 },
102 }));102 }));
103 testing.expect([2]u32 == @Type(TypeInfo{103 try testing.expect([2]u32 == @Type(TypeInfo{
104 .Array = TypeInfo.Array{104 .Array = TypeInfo.Array{
105 .len = 2,105 .len = 2,
106 .child = u32,106 .child = u32,
107 .sentinel = null,107 .sentinel = null,
108 },108 },
109 }));109 }));
110 testing.expect([2:0]u32 == @Type(TypeInfo{110 try testing.expect([2:0]u32 == @Type(TypeInfo{
111 .Array = TypeInfo.Array{111 .Array = TypeInfo.Array{
112 .len = 2,112 .len = 2,
113 .child = u32,113 .child = u32,
114 .sentinel = 0,114 .sentinel = 0,
115 },115 },
116 }));116 }));
117 testTypes(&[_]type{ [1]u8, [30]usize, [7]bool });117 try testTypes(&[_]type{ [1]u8, [30]usize, [7]bool });
118}118}
119119
120test "Type.ComptimeFloat" {120test "Type.ComptimeFloat" {
121 testTypes(&[_]type{comptime_float});121 try testTypes(&[_]type{comptime_float});
122}122}
123test "Type.ComptimeInt" {123test "Type.ComptimeInt" {
124 testTypes(&[_]type{comptime_int});124 try testTypes(&[_]type{comptime_int});
125}125}
126test "Type.Undefined" {126test "Type.Undefined" {
127 testTypes(&[_]type{@TypeOf(undefined)});127 try testTypes(&[_]type{@TypeOf(undefined)});
128}128}
129test "Type.Null" {129test "Type.Null" {
130 testTypes(&[_]type{@TypeOf(null)});130 try testTypes(&[_]type{@TypeOf(null)});
131}131}
132test "@Type create slice with null sentinel" {132test "@Type create slice with null sentinel" {
133 const Slice = @Type(TypeInfo{133 const Slice = @Type(TypeInfo{
...@@ -141,10 +141,10 @@ test "@Type create slice with null sentinel" {...@@ -141,10 +141,10 @@ test "@Type create slice with null sentinel" {
141 .sentinel = null,141 .sentinel = null,
142 },142 },
143 });143 });
144 testing.expect(Slice == []align(8) const *i32);144 try testing.expect(Slice == []align(8) const *i32);
145}145}
146test "@Type picks up the sentinel value from TypeInfo" {146test "@Type picks up the sentinel value from TypeInfo" {
147 testTypes(&[_]type{147 try testTypes(&[_]type{
148 [11:0]u8, [4:10]u8,148 [11:0]u8, [4:10]u8,
149 [*:0]u8, [*:0]const u8,149 [*:0]u8, [*:0]const u8,
150 [*:0]volatile u8, [*:0]const volatile u8,150 [*:0]volatile u8, [*:0]const volatile u8,
...@@ -172,7 +172,7 @@ test "@Type picks up the sentinel value from TypeInfo" {...@@ -172,7 +172,7 @@ test "@Type picks up the sentinel value from TypeInfo" {
172}172}
173173
174test "Type.Optional" {174test "Type.Optional" {
175 testTypes(&[_]type{175 try testTypes(&[_]type{
176 ?u8,176 ?u8,
177 ?*u8,177 ?*u8,
178 ?[]u8,178 ?[]u8,
...@@ -182,7 +182,7 @@ test "Type.Optional" {...@@ -182,7 +182,7 @@ test "Type.Optional" {
182}182}
183183
184test "Type.ErrorUnion" {184test "Type.ErrorUnion" {
185 testTypes(&[_]type{185 try testTypes(&[_]type{
186 error{}!void,186 error{}!void,
187 error{Error}!void,187 error{Error}!void,
188 });188 });
...@@ -194,8 +194,8 @@ test "Type.Opaque" {...@@ -194,8 +194,8 @@ test "Type.Opaque" {
194 .decls = &[_]TypeInfo.Declaration{},194 .decls = &[_]TypeInfo.Declaration{},
195 },195 },
196 });196 });
197 testing.expect(Opaque != opaque {});197 try testing.expect(Opaque != opaque {});
198 testing.expectEqualSlices(198 try testing.expectEqualSlices(
199 TypeInfo.Declaration,199 TypeInfo.Declaration,
200 &[_]TypeInfo.Declaration{},200 &[_]TypeInfo.Declaration{},
201 @typeInfo(Opaque).Opaque.decls,201 @typeInfo(Opaque).Opaque.decls,
...@@ -203,7 +203,7 @@ test "Type.Opaque" {...@@ -203,7 +203,7 @@ test "Type.Opaque" {
203}203}
204204
205test "Type.Vector" {205test "Type.Vector" {
206 testTypes(&[_]type{206 try testTypes(&[_]type{
207 @Vector(0, u8),207 @Vector(0, u8),
208 @Vector(4, u8),208 @Vector(4, u8),
209 @Vector(8, *u8),209 @Vector(8, *u8),
...@@ -214,7 +214,7 @@ test "Type.Vector" {...@@ -214,7 +214,7 @@ test "Type.Vector" {
214}214}
215215
216test "Type.AnyFrame" {216test "Type.AnyFrame" {
217 testTypes(&[_]type{217 try testTypes(&[_]type{
218 anyframe,218 anyframe,
219 anyframe->u8,219 anyframe->u8,
220 anyframe->anyframe->u8,220 anyframe->anyframe->u8,
...@@ -222,7 +222,7 @@ test "Type.AnyFrame" {...@@ -222,7 +222,7 @@ test "Type.AnyFrame" {
222}222}
223223
224test "Type.EnumLiteral" {224test "Type.EnumLiteral" {
225 testTypes(&[_]type{225 try testTypes(&[_]type{
226 @TypeOf(.Dummy),226 @TypeOf(.Dummy),
227 });227 });
228}228}
...@@ -232,7 +232,7 @@ fn add(a: i32, b: i32) i32 {...@@ -232,7 +232,7 @@ fn add(a: i32, b: i32) i32 {
232}232}
233233
234test "Type.Frame" {234test "Type.Frame" {
235 testTypes(&[_]type{235 try testTypes(&[_]type{
236 @Frame(add),236 @Frame(add),
237 });237 });
238}238}
...@@ -247,45 +247,45 @@ test "Type.ErrorSet" {...@@ -247,45 +247,45 @@ test "Type.ErrorSet" {
247test "Type.Struct" {247test "Type.Struct" {
248 const A = @Type(@typeInfo(struct { x: u8, y: u32 }));248 const A = @Type(@typeInfo(struct { x: u8, y: u32 }));
249 const infoA = @typeInfo(A).Struct;249 const infoA = @typeInfo(A).Struct;
250 testing.expectEqual(TypeInfo.ContainerLayout.Auto, infoA.layout);250 try testing.expectEqual(TypeInfo.ContainerLayout.Auto, infoA.layout);
251 testing.expectEqualSlices(u8, "x", infoA.fields[0].name);251 try testing.expectEqualSlices(u8, "x", infoA.fields[0].name);
252 testing.expectEqual(u8, infoA.fields[0].field_type);252 try testing.expectEqual(u8, infoA.fields[0].field_type);
253 testing.expectEqual(@as(?u8, null), infoA.fields[0].default_value);253 try testing.expectEqual(@as(?u8, null), infoA.fields[0].default_value);
254 testing.expectEqualSlices(u8, "y", infoA.fields[1].name);254 try testing.expectEqualSlices(u8, "y", infoA.fields[1].name);
255 testing.expectEqual(u32, infoA.fields[1].field_type);255 try testing.expectEqual(u32, infoA.fields[1].field_type);
256 testing.expectEqual(@as(?u32, null), infoA.fields[1].default_value);256 try testing.expectEqual(@as(?u32, null), infoA.fields[1].default_value);
257 testing.expectEqualSlices(TypeInfo.Declaration, &[_]TypeInfo.Declaration{}, infoA.decls);257 try testing.expectEqualSlices(TypeInfo.Declaration, &[_]TypeInfo.Declaration{}, infoA.decls);
258 testing.expectEqual(@as(bool, false), infoA.is_tuple);258 try testing.expectEqual(@as(bool, false), infoA.is_tuple);
259259
260 var a = A{ .x = 0, .y = 1 };260 var a = A{ .x = 0, .y = 1 };
261 testing.expectEqual(@as(u8, 0), a.x);261 try testing.expectEqual(@as(u8, 0), a.x);
262 testing.expectEqual(@as(u32, 1), a.y);262 try testing.expectEqual(@as(u32, 1), a.y);
263 a.y += 1;263 a.y += 1;
264 testing.expectEqual(@as(u32, 2), a.y);264 try testing.expectEqual(@as(u32, 2), a.y);
265265
266 const B = @Type(@typeInfo(extern struct { x: u8, y: u32 = 5 }));266 const B = @Type(@typeInfo(extern struct { x: u8, y: u32 = 5 }));
267 const infoB = @typeInfo(B).Struct;267 const infoB = @typeInfo(B).Struct;
268 testing.expectEqual(TypeInfo.ContainerLayout.Extern, infoB.layout);268 try testing.expectEqual(TypeInfo.ContainerLayout.Extern, infoB.layout);
269 testing.expectEqualSlices(u8, "x", infoB.fields[0].name);269 try testing.expectEqualSlices(u8, "x", infoB.fields[0].name);
270 testing.expectEqual(u8, infoB.fields[0].field_type);270 try testing.expectEqual(u8, infoB.fields[0].field_type);
271 testing.expectEqual(@as(?u8, null), infoB.fields[0].default_value);271 try testing.expectEqual(@as(?u8, null), infoB.fields[0].default_value);
272 testing.expectEqualSlices(u8, "y", infoB.fields[1].name);272 try testing.expectEqualSlices(u8, "y", infoB.fields[1].name);
273 testing.expectEqual(u32, infoB.fields[1].field_type);273 try testing.expectEqual(u32, infoB.fields[1].field_type);
274 testing.expectEqual(@as(?u32, 5), infoB.fields[1].default_value);274 try testing.expectEqual(@as(?u32, 5), infoB.fields[1].default_value);
275 testing.expectEqual(@as(usize, 0), infoB.decls.len);275 try testing.expectEqual(@as(usize, 0), infoB.decls.len);
276 testing.expectEqual(@as(bool, false), infoB.is_tuple);276 try testing.expectEqual(@as(bool, false), infoB.is_tuple);
277277
278 const C = @Type(@typeInfo(packed struct { x: u8 = 3, y: u32 = 5 }));278 const C = @Type(@typeInfo(packed struct { x: u8 = 3, y: u32 = 5 }));
279 const infoC = @typeInfo(C).Struct;279 const infoC = @typeInfo(C).Struct;
280 testing.expectEqual(TypeInfo.ContainerLayout.Packed, infoC.layout);280 try testing.expectEqual(TypeInfo.ContainerLayout.Packed, infoC.layout);
281 testing.expectEqualSlices(u8, "x", infoC.fields[0].name);281 try testing.expectEqualSlices(u8, "x", infoC.fields[0].name);
282 testing.expectEqual(u8, infoC.fields[0].field_type);282 try testing.expectEqual(u8, infoC.fields[0].field_type);
283 testing.expectEqual(@as(?u8, 3), infoC.fields[0].default_value);283 try testing.expectEqual(@as(?u8, 3), infoC.fields[0].default_value);
284 testing.expectEqualSlices(u8, "y", infoC.fields[1].name);284 try testing.expectEqualSlices(u8, "y", infoC.fields[1].name);
285 testing.expectEqual(u32, infoC.fields[1].field_type);285 try testing.expectEqual(u32, infoC.fields[1].field_type);
286 testing.expectEqual(@as(?u32, 5), infoC.fields[1].default_value);286 try testing.expectEqual(@as(?u32, 5), infoC.fields[1].default_value);
287 testing.expectEqual(@as(usize, 0), infoC.decls.len);287 try testing.expectEqual(@as(usize, 0), infoC.decls.len);
288 testing.expectEqual(@as(bool, false), infoC.is_tuple);288 try testing.expectEqual(@as(bool, false), infoC.is_tuple);
289}289}
290290
291test "Type.Enum" {291test "Type.Enum" {
...@@ -301,9 +301,9 @@ test "Type.Enum" {...@@ -301,9 +301,9 @@ test "Type.Enum" {
301 .is_exhaustive = true,301 .is_exhaustive = true,
302 },302 },
303 });303 });
304 testing.expectEqual(true, @typeInfo(Foo).Enum.is_exhaustive);304 try testing.expectEqual(true, @typeInfo(Foo).Enum.is_exhaustive);
305 testing.expectEqual(@as(u8, 1), @enumToInt(Foo.a));305 try testing.expectEqual(@as(u8, 1), @enumToInt(Foo.a));
306 testing.expectEqual(@as(u8, 5), @enumToInt(Foo.b));306 try testing.expectEqual(@as(u8, 5), @enumToInt(Foo.b));
307 const Bar = @Type(.{307 const Bar = @Type(.{
308 .Enum = .{308 .Enum = .{
309 .layout = .Extern,309 .layout = .Extern,
...@@ -316,10 +316,10 @@ test "Type.Enum" {...@@ -316,10 +316,10 @@ test "Type.Enum" {
316 .is_exhaustive = false,316 .is_exhaustive = false,
317 },317 },
318 });318 });
319 testing.expectEqual(false, @typeInfo(Bar).Enum.is_exhaustive);319 try testing.expectEqual(false, @typeInfo(Bar).Enum.is_exhaustive);
320 testing.expectEqual(@as(u32, 1), @enumToInt(Bar.a));320 try testing.expectEqual(@as(u32, 1), @enumToInt(Bar.a));
321 testing.expectEqual(@as(u32, 5), @enumToInt(Bar.b));321 try testing.expectEqual(@as(u32, 5), @enumToInt(Bar.b));
322 testing.expectEqual(@as(u32, 6), @enumToInt(@intToEnum(Bar, 6)));322 try testing.expectEqual(@as(u32, 6), @enumToInt(@intToEnum(Bar, 6)));
323}323}
324324
325test "Type.Union" {325test "Type.Union" {
...@@ -337,7 +337,7 @@ test "Type.Union" {...@@ -337,7 +337,7 @@ test "Type.Union" {
337 var untagged = Untagged{ .int = 1 };337 var untagged = Untagged{ .int = 1 };
338 untagged.float = 2.0;338 untagged.float = 2.0;
339 untagged.int = 3;339 untagged.int = 3;
340 testing.expectEqual(@as(i32, 3), untagged.int);340 try testing.expectEqual(@as(i32, 3), untagged.int);
341341
342 const PackedUntagged = @Type(.{342 const PackedUntagged = @Type(.{
343 .Union = .{343 .Union = .{
...@@ -351,8 +351,8 @@ test "Type.Union" {...@@ -351,8 +351,8 @@ test "Type.Union" {
351 },351 },
352 });352 });
353 var packed_untagged = PackedUntagged{ .signed = -1 };353 var packed_untagged = PackedUntagged{ .signed = -1 };
354 testing.expectEqual(@as(i32, -1), packed_untagged.signed);354 try testing.expectEqual(@as(i32, -1), packed_untagged.signed);
355 testing.expectEqual(~@as(u32, 0), packed_untagged.unsigned);355 try testing.expectEqual(~@as(u32, 0), packed_untagged.unsigned);
356356
357 const Tag = @Type(.{357 const Tag = @Type(.{
358 .Enum = .{358 .Enum = .{
...@@ -378,9 +378,9 @@ test "Type.Union" {...@@ -378,9 +378,9 @@ test "Type.Union" {
378 },378 },
379 });379 });
380 var tagged = Tagged{ .signed = -1 };380 var tagged = Tagged{ .signed = -1 };
381 testing.expectEqual(Tag.signed, tagged);381 try testing.expectEqual(Tag.signed, tagged);
382 tagged = .{ .unsigned = 1 };382 tagged = .{ .unsigned = 1 };
383 testing.expectEqual(Tag.unsigned, tagged);383 try testing.expectEqual(Tag.unsigned, tagged);
384}384}
385385
386test "Type.Union from Type.Enum" {386test "Type.Union from Type.Enum" {
...@@ -446,7 +446,7 @@ test "Type.BoundFn" {...@@ -446,7 +446,7 @@ test "Type.BoundFn" {
446 pub fn foo(self: *const @This()) align(4) callconv(.Unspecified) void {}446 pub fn foo(self: *const @This()) align(4) callconv(.Unspecified) void {}
447 };447 };
448 const test_instance: TestStruct = undefined;448 const test_instance: TestStruct = undefined;
449 testing.expect(std.meta.eql(449 try testing.expect(std.meta.eql(
450 @typeName(@TypeOf(test_instance.foo)),450 @typeName(@TypeOf(test_instance.foo)),
451 @typeName(@Type(@typeInfo(@TypeOf(test_instance.foo)))),451 @typeName(@Type(@typeInfo(@TypeOf(test_instance.foo)))),
452 ));452 ));
test/behavior/type_info.zig+187-187
...@@ -9,151 +9,151 @@ const expect = std.testing.expect;...@@ -9,151 +9,151 @@ const expect = std.testing.expect;
9const expectEqualStrings = std.testing.expectEqualStrings;9const expectEqualStrings = std.testing.expectEqualStrings;
1010
11test "type info: tag type, void info" {11test "type info: tag type, void info" {
12 testBasic();12 try testBasic();
13 comptime testBasic();13 comptime try testBasic();
14}14}
1515
16fn testBasic() void {16fn testBasic() !void {
17 expect(@typeInfo(TypeInfo).Union.tag_type == TypeId);17 try expect(@typeInfo(TypeInfo).Union.tag_type == TypeId);
18 const void_info = @typeInfo(void);18 const void_info = @typeInfo(void);
19 expect(void_info == TypeId.Void);19 try expect(void_info == TypeId.Void);
20 expect(void_info.Void == {});20 try expect(void_info.Void == {});
21}21}
2222
23test "type info: integer, floating point type info" {23test "type info: integer, floating point type info" {
24 testIntFloat();24 try testIntFloat();
25 comptime testIntFloat();25 comptime try testIntFloat();
26}26}
2727
28fn testIntFloat() void {28fn testIntFloat() !void {
29 const u8_info = @typeInfo(u8);29 const u8_info = @typeInfo(u8);
30 expect(u8_info == .Int);30 try expect(u8_info == .Int);
31 expect(u8_info.Int.signedness == .unsigned);31 try expect(u8_info.Int.signedness == .unsigned);
32 expect(u8_info.Int.bits == 8);32 try expect(u8_info.Int.bits == 8);
3333
34 const f64_info = @typeInfo(f64);34 const f64_info = @typeInfo(f64);
35 expect(f64_info == .Float);35 try expect(f64_info == .Float);
36 expect(f64_info.Float.bits == 64);36 try expect(f64_info.Float.bits == 64);
37}37}
3838
39test "type info: pointer type info" {39test "type info: pointer type info" {
40 testPointer();40 try testPointer();
41 comptime testPointer();41 comptime try testPointer();
42}42}
4343
44fn testPointer() void {44fn testPointer() !void {
45 const u32_ptr_info = @typeInfo(*u32);45 const u32_ptr_info = @typeInfo(*u32);
46 expect(u32_ptr_info == .Pointer);46 try expect(u32_ptr_info == .Pointer);
47 expect(u32_ptr_info.Pointer.size == TypeInfo.Pointer.Size.One);47 try expect(u32_ptr_info.Pointer.size == TypeInfo.Pointer.Size.One);
48 expect(u32_ptr_info.Pointer.is_const == false);48 try expect(u32_ptr_info.Pointer.is_const == false);
49 expect(u32_ptr_info.Pointer.is_volatile == false);49 try expect(u32_ptr_info.Pointer.is_volatile == false);
50 expect(u32_ptr_info.Pointer.alignment == @alignOf(u32));50 try expect(u32_ptr_info.Pointer.alignment == @alignOf(u32));
51 expect(u32_ptr_info.Pointer.child == u32);51 try expect(u32_ptr_info.Pointer.child == u32);
52 expect(u32_ptr_info.Pointer.sentinel == null);52 try expect(u32_ptr_info.Pointer.sentinel == null);
53}53}
5454
55test "type info: unknown length pointer type info" {55test "type info: unknown length pointer type info" {
56 testUnknownLenPtr();56 try testUnknownLenPtr();
57 comptime testUnknownLenPtr();57 comptime try testUnknownLenPtr();
58}58}
5959
60fn testUnknownLenPtr() void {60fn testUnknownLenPtr() !void {
61 const u32_ptr_info = @typeInfo([*]const volatile f64);61 const u32_ptr_info = @typeInfo([*]const volatile f64);
62 expect(u32_ptr_info == .Pointer);62 try expect(u32_ptr_info == .Pointer);
63 expect(u32_ptr_info.Pointer.size == TypeInfo.Pointer.Size.Many);63 try expect(u32_ptr_info.Pointer.size == TypeInfo.Pointer.Size.Many);
64 expect(u32_ptr_info.Pointer.is_const == true);64 try expect(u32_ptr_info.Pointer.is_const == true);
65 expect(u32_ptr_info.Pointer.is_volatile == true);65 try expect(u32_ptr_info.Pointer.is_volatile == true);
66 expect(u32_ptr_info.Pointer.sentinel == null);66 try expect(u32_ptr_info.Pointer.sentinel == null);
67 expect(u32_ptr_info.Pointer.alignment == @alignOf(f64));67 try expect(u32_ptr_info.Pointer.alignment == @alignOf(f64));
68 expect(u32_ptr_info.Pointer.child == f64);68 try expect(u32_ptr_info.Pointer.child == f64);
69}69}
7070
71test "type info: null terminated pointer type info" {71test "type info: null terminated pointer type info" {
72 testNullTerminatedPtr();72 try testNullTerminatedPtr();
73 comptime testNullTerminatedPtr();73 comptime try testNullTerminatedPtr();
74}74}
7575
76fn testNullTerminatedPtr() void {76fn testNullTerminatedPtr() !void {
77 const ptr_info = @typeInfo([*:0]u8);77 const ptr_info = @typeInfo([*:0]u8);
78 expect(ptr_info == .Pointer);78 try expect(ptr_info == .Pointer);
79 expect(ptr_info.Pointer.size == TypeInfo.Pointer.Size.Many);79 try expect(ptr_info.Pointer.size == TypeInfo.Pointer.Size.Many);
80 expect(ptr_info.Pointer.is_const == false);80 try expect(ptr_info.Pointer.is_const == false);
81 expect(ptr_info.Pointer.is_volatile == false);81 try expect(ptr_info.Pointer.is_volatile == false);
82 expect(ptr_info.Pointer.sentinel.? == 0);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);
85}85}
8686
87test "type info: C pointer type info" {87test "type info: C pointer type info" {
88 testCPtr();88 try testCPtr();
89 comptime testCPtr();89 comptime try testCPtr();
90}90}
9191
92fn testCPtr() void {92fn testCPtr() !void {
93 const ptr_info = @typeInfo([*c]align(4) const i8);93 const ptr_info = @typeInfo([*c]align(4) const i8);
94 expect(ptr_info == .Pointer);94 try expect(ptr_info == .Pointer);
95 expect(ptr_info.Pointer.size == .C);95 try expect(ptr_info.Pointer.size == .C);
96 expect(ptr_info.Pointer.is_const);96 try expect(ptr_info.Pointer.is_const);
97 expect(!ptr_info.Pointer.is_volatile);97 try expect(!ptr_info.Pointer.is_volatile);
98 expect(ptr_info.Pointer.alignment == 4);98 try expect(ptr_info.Pointer.alignment == 4);
99 expect(ptr_info.Pointer.child == i8);99 try expect(ptr_info.Pointer.child == i8);
100}100}
101101
102test "type info: slice type info" {102test "type info: slice type info" {
103 testSlice();103 try testSlice();
104 comptime testSlice();104 comptime try testSlice();
105}105}
106106
107fn testSlice() void {107fn testSlice() !void {
108 const u32_slice_info = @typeInfo([]u32);108 const u32_slice_info = @typeInfo([]u32);
109 expect(u32_slice_info == .Pointer);109 try expect(u32_slice_info == .Pointer);
110 expect(u32_slice_info.Pointer.size == .Slice);110 try expect(u32_slice_info.Pointer.size == .Slice);
111 expect(u32_slice_info.Pointer.is_const == false);111 try expect(u32_slice_info.Pointer.is_const == false);
112 expect(u32_slice_info.Pointer.is_volatile == false);112 try expect(u32_slice_info.Pointer.is_volatile == false);
113 expect(u32_slice_info.Pointer.alignment == 4);113 try expect(u32_slice_info.Pointer.alignment == 4);
114 expect(u32_slice_info.Pointer.child == u32);114 try expect(u32_slice_info.Pointer.child == u32);
115}115}
116116
117test "type info: array type info" {117test "type info: array type info" {
118 testArray();118 try testArray();
119 comptime testArray();119 comptime try testArray();
120}120}
121121
122fn testArray() void {122fn testArray() !void {
123 {123 {
124 const info = @typeInfo([42]u8);124 const info = @typeInfo([42]u8);
125 expect(info == .Array);125 try expect(info == .Array);
126 expect(info.Array.len == 42);126 try expect(info.Array.len == 42);
127 expect(info.Array.child == u8);127 try expect(info.Array.child == u8);
128 expect(info.Array.sentinel == null);128 try expect(info.Array.sentinel == null);
129 }129 }
130130
131 {131 {
132 const info = @typeInfo([10:0]u8);132 const info = @typeInfo([10:0]u8);
133 expect(info.Array.len == 10);133 try expect(info.Array.len == 10);
134 expect(info.Array.child == u8);134 try expect(info.Array.child == u8);
135 expect(info.Array.sentinel.? == @as(u8, 0));135 try expect(info.Array.sentinel.? == @as(u8, 0));
136 expect(@sizeOf([10:0]u8) == info.Array.len + 1);136 try expect(@sizeOf([10:0]u8) == info.Array.len + 1);
137 }137 }
138}138}
139139
140test "type info: optional type info" {140test "type info: optional type info" {
141 testOptional();141 try testOptional();
142 comptime testOptional();142 comptime try testOptional();
143}143}
144144
145fn testOptional() void {145fn testOptional() !void {
146 const null_info = @typeInfo(?void);146 const null_info = @typeInfo(?void);
147 expect(null_info == .Optional);147 try expect(null_info == .Optional);
148 expect(null_info.Optional.child == void);148 try expect(null_info.Optional.child == void);
149}149}
150150
151test "type info: error set, error union info" {151test "type info: error set, error union info" {
152 testErrorSet();152 try testErrorSet();
153 comptime testErrorSet();153 comptime try testErrorSet();
154}154}
155155
156fn testErrorSet() void {156fn testErrorSet() !void {
157 const TestErrorSet = error{157 const TestErrorSet = error{
158 First,158 First,
159 Second,159 Second,
...@@ -161,26 +161,26 @@ fn testErrorSet() void {...@@ -161,26 +161,26 @@ fn testErrorSet() void {
161 };161 };
162162
163 const error_set_info = @typeInfo(TestErrorSet);163 const error_set_info = @typeInfo(TestErrorSet);
164 expect(error_set_info == .ErrorSet);164 try expect(error_set_info == .ErrorSet);
165 expect(error_set_info.ErrorSet.?.len == 3);165 try expect(error_set_info.ErrorSet.?.len == 3);
166 expect(mem.eql(u8, error_set_info.ErrorSet.?[0].name, "First"));166 try expect(mem.eql(u8, error_set_info.ErrorSet.?[0].name, "First"));
167167
168 const error_union_info = @typeInfo(TestErrorSet!usize);168 const error_union_info = @typeInfo(TestErrorSet!usize);
169 expect(error_union_info == .ErrorUnion);169 try expect(error_union_info == .ErrorUnion);
170 expect(error_union_info.ErrorUnion.error_set == TestErrorSet);170 try expect(error_union_info.ErrorUnion.error_set == TestErrorSet);
171 expect(error_union_info.ErrorUnion.payload == usize);171 try expect(error_union_info.ErrorUnion.payload == usize);
172172
173 const global_info = @typeInfo(anyerror);173 const global_info = @typeInfo(anyerror);
174 expect(global_info == .ErrorSet);174 try expect(global_info == .ErrorSet);
175 expect(global_info.ErrorSet == null);175 try expect(global_info.ErrorSet == null);
176}176}
177177
178test "type info: enum info" {178test "type info: enum info" {
179 testEnum();179 try testEnum();
180 comptime testEnum();180 comptime try testEnum();
181}181}
182182
183fn testEnum() void {183fn testEnum() !void {
184 const Os = enum {184 const Os = enum {
185 Windows,185 Windows,
186 Macos,186 Macos,
...@@ -189,28 +189,28 @@ fn testEnum() void {...@@ -189,28 +189,28 @@ fn testEnum() void {
189 };189 };
190190
191 const os_info = @typeInfo(Os);191 const os_info = @typeInfo(Os);
192 expect(os_info == .Enum);192 try expect(os_info == .Enum);
193 expect(os_info.Enum.layout == .Auto);193 try expect(os_info.Enum.layout == .Auto);
194 expect(os_info.Enum.fields.len == 4);194 try expect(os_info.Enum.fields.len == 4);
195 expect(mem.eql(u8, os_info.Enum.fields[1].name, "Macos"));195 try expect(mem.eql(u8, os_info.Enum.fields[1].name, "Macos"));
196 expect(os_info.Enum.fields[3].value == 3);196 try expect(os_info.Enum.fields[3].value == 3);
197 expect(os_info.Enum.tag_type == u2);197 try expect(os_info.Enum.tag_type == u2);
198 expect(os_info.Enum.decls.len == 0);198 try expect(os_info.Enum.decls.len == 0);
199}199}
200200
201test "type info: union info" {201test "type info: union info" {
202 testUnion();202 try testUnion();
203 comptime testUnion();203 comptime try testUnion();
204}204}
205205
206fn testUnion() void {206fn testUnion() !void {
207 const typeinfo_info = @typeInfo(TypeInfo);207 const typeinfo_info = @typeInfo(TypeInfo);
208 expect(typeinfo_info == .Union);208 try expect(typeinfo_info == .Union);
209 expect(typeinfo_info.Union.layout == .Auto);209 try expect(typeinfo_info.Union.layout == .Auto);
210 expect(typeinfo_info.Union.tag_type.? == TypeId);210 try expect(typeinfo_info.Union.tag_type.? == TypeId);
211 expect(typeinfo_info.Union.fields.len == 25);211 try expect(typeinfo_info.Union.fields.len == 25);
212 expect(typeinfo_info.Union.fields[4].field_type == @TypeOf(@typeInfo(u8).Int));212 try expect(typeinfo_info.Union.fields[4].field_type == @TypeOf(@typeInfo(u8).Int));
213 expect(typeinfo_info.Union.decls.len == 22);213 try expect(typeinfo_info.Union.decls.len == 22);
214214
215 const TestNoTagUnion = union {215 const TestNoTagUnion = union {
216 Foo: void,216 Foo: void,
...@@ -218,52 +218,52 @@ fn testUnion() void {...@@ -218,52 +218,52 @@ fn testUnion() void {
218 };218 };
219219
220 const notag_union_info = @typeInfo(TestNoTagUnion);220 const notag_union_info = @typeInfo(TestNoTagUnion);
221 expect(notag_union_info == .Union);221 try expect(notag_union_info == .Union);
222 expect(notag_union_info.Union.tag_type == null);222 try expect(notag_union_info.Union.tag_type == null);
223 expect(notag_union_info.Union.layout == .Auto);223 try expect(notag_union_info.Union.layout == .Auto);
224 expect(notag_union_info.Union.fields.len == 2);224 try expect(notag_union_info.Union.fields.len == 2);
225 expect(notag_union_info.Union.fields[0].alignment == @alignOf(void));225 try expect(notag_union_info.Union.fields[0].alignment == @alignOf(void));
226 expect(notag_union_info.Union.fields[1].field_type == u32);226 try expect(notag_union_info.Union.fields[1].field_type == u32);
227 expect(notag_union_info.Union.fields[1].alignment == @alignOf(u32));227 try expect(notag_union_info.Union.fields[1].alignment == @alignOf(u32));
228228
229 const TestExternUnion = extern union {229 const TestExternUnion = extern union {
230 foo: *c_void,230 foo: *c_void,
231 };231 };
232232
233 const extern_union_info = @typeInfo(TestExternUnion);233 const extern_union_info = @typeInfo(TestExternUnion);
234 expect(extern_union_info.Union.layout == .Extern);234 try expect(extern_union_info.Union.layout == .Extern);
235 expect(extern_union_info.Union.tag_type == null);235 try expect(extern_union_info.Union.tag_type == null);
236 expect(extern_union_info.Union.fields[0].field_type == *c_void);236 try expect(extern_union_info.Union.fields[0].field_type == *c_void);
237}237}
238238
239test "type info: struct info" {239test "type info: struct info" {
240 testStruct();240 try testStruct();
241 comptime testStruct();241 comptime try testStruct();
242}242}
243243
244fn testStruct() void {244fn testStruct() !void {
245 const unpacked_struct_info = @typeInfo(TestUnpackedStruct);245 const unpacked_struct_info = @typeInfo(TestUnpackedStruct);
246 expect(unpacked_struct_info.Struct.is_tuple == false);246 try expect(unpacked_struct_info.Struct.is_tuple == false);
247 expect(unpacked_struct_info.Struct.fields[0].alignment == @alignOf(u32));247 try expect(unpacked_struct_info.Struct.fields[0].alignment == @alignOf(u32));
248 expect(unpacked_struct_info.Struct.fields[0].default_value.? == 4);248 try expect(unpacked_struct_info.Struct.fields[0].default_value.? == 4);
249 expectEqualStrings("foobar", unpacked_struct_info.Struct.fields[1].default_value.?);249 try expectEqualStrings("foobar", unpacked_struct_info.Struct.fields[1].default_value.?);
250250
251 const struct_info = @typeInfo(TestStruct);251 const struct_info = @typeInfo(TestStruct);
252 expect(struct_info == .Struct);252 try expect(struct_info == .Struct);
253 expect(struct_info.Struct.is_tuple == false);253 try expect(struct_info.Struct.is_tuple == false);
254 expect(struct_info.Struct.layout == .Packed);254 try expect(struct_info.Struct.layout == .Packed);
255 expect(struct_info.Struct.fields.len == 4);255 try expect(struct_info.Struct.fields.len == 4);
256 expect(struct_info.Struct.fields[0].alignment == 2 * @alignOf(usize));256 try expect(struct_info.Struct.fields[0].alignment == 2 * @alignOf(usize));
257 expect(struct_info.Struct.fields[2].field_type == *TestStruct);257 try expect(struct_info.Struct.fields[2].field_type == *TestStruct);
258 expect(struct_info.Struct.fields[2].default_value == null);258 try expect(struct_info.Struct.fields[2].default_value == null);
259 expect(struct_info.Struct.fields[3].default_value.? == 4);259 try expect(struct_info.Struct.fields[3].default_value.? == 4);
260 expect(struct_info.Struct.fields[3].alignment == 1);260 try expect(struct_info.Struct.fields[3].alignment == 1);
261 expect(struct_info.Struct.decls.len == 2);261 try expect(struct_info.Struct.decls.len == 2);
262 expect(struct_info.Struct.decls[0].is_pub);262 try expect(struct_info.Struct.decls[0].is_pub);
263 expect(!struct_info.Struct.decls[0].data.Fn.is_extern);263 try expect(!struct_info.Struct.decls[0].data.Fn.is_extern);
264 expect(struct_info.Struct.decls[0].data.Fn.lib_name == null);264 try expect(struct_info.Struct.decls[0].data.Fn.lib_name == null);
265 expect(struct_info.Struct.decls[0].data.Fn.return_type == void);265 try 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);266 try expect(struct_info.Struct.decls[0].data.Fn.fn_type == fn (*const TestStruct) void);
267}267}
268268
269const TestUnpackedStruct = struct {269const TestUnpackedStruct = struct {
...@@ -282,44 +282,44 @@ const TestStruct = packed struct {...@@ -282,44 +282,44 @@ const TestStruct = packed struct {
282};282};
283283
284test "type info: opaque info" {284test "type info: opaque info" {
285 testOpaque();285 try testOpaque();
286 comptime testOpaque();286 comptime try testOpaque();
287}287}
288288
289fn testOpaque() void {289fn testOpaque() !void {
290 const Foo = opaque {290 const Foo = opaque {
291 const A = 1;291 const A = 1;
292 fn b() void {}292 fn b() void {}
293 };293 };
294294
295 const foo_info = @typeInfo(Foo);295 const foo_info = @typeInfo(Foo);
296 expect(foo_info.Opaque.decls.len == 2);296 try expect(foo_info.Opaque.decls.len == 2);
297}297}
298298
299test "type info: function type info" {299test "type info: function type info" {
300 // wasm doesn't support align attributes on functions300 // wasm doesn't support align attributes on functions
301 if (builtin.target.cpu.arch == .wasm32 or builtin.target.cpu.arch == .wasm64) return error.SkipZigTest;301 if (builtin.target.cpu.arch == .wasm32 or builtin.target.cpu.arch == .wasm64) return error.SkipZigTest;
302 testFunction();302 try testFunction();
303 comptime testFunction();303 comptime try testFunction();
304}304}
305305
306fn testFunction() void {306fn testFunction() !void {
307 const fn_info = @typeInfo(@TypeOf(foo));307 const fn_info = @typeInfo(@TypeOf(foo));
308 expect(fn_info == .Fn);308 try expect(fn_info == .Fn);
309 // TODO Fix this before merging the branch309 // TODO Fix this before merging the branch
310 //expect(fn_info.Fn.alignment > 0);310 //try expect(fn_info.Fn.alignment > 0);
311 expect(fn_info.Fn.calling_convention == .C);311 try expect(fn_info.Fn.calling_convention == .C);
312 expect(!fn_info.Fn.is_generic);312 try expect(!fn_info.Fn.is_generic);
313 expect(fn_info.Fn.args.len == 2);313 try expect(fn_info.Fn.args.len == 2);
314 expect(fn_info.Fn.is_var_args);314 try expect(fn_info.Fn.is_var_args);
315 expect(fn_info.Fn.return_type.? == usize);315 try expect(fn_info.Fn.return_type.? == usize);
316 const fn_aligned_info = @typeInfo(@TypeOf(fooAligned));316 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
319 const test_instance: TestStruct = undefined;319 const test_instance: TestStruct = undefined;
320 const bound_fn_info = @typeInfo(@TypeOf(test_instance.foo));320 const bound_fn_info = @typeInfo(@TypeOf(test_instance.foo));
321 expect(bound_fn_info == .BoundFn);321 try expect(bound_fn_info == .BoundFn);
322 expect(bound_fn_info.BoundFn.args[0].arg_type.? == *const TestStruct);322 try expect(bound_fn_info.BoundFn.args[0].arg_type.? == *const TestStruct);
323}323}
324324
325extern fn foo(a: usize, b: bool, ...) callconv(.C) usize;325extern fn foo(a: usize, b: bool, ...) callconv(.C) usize;
...@@ -333,33 +333,33 @@ test "typeInfo with comptime parameter in struct fn def" {...@@ -333,33 +333,33 @@ test "typeInfo with comptime parameter in struct fn def" {
333}333}
334334
335test "type info: vectors" {335test "type info: vectors" {
336 testVector();336 try testVector();
337 comptime testVector();337 comptime try testVector();
338}338}
339339
340fn testVector() void {340fn testVector() !void {
341 const vec_info = @typeInfo(std.meta.Vector(4, i32));341 const vec_info = @typeInfo(std.meta.Vector(4, i32));
342 expect(vec_info == .Vector);342 try expect(vec_info == .Vector);
343 expect(vec_info.Vector.len == 4);343 try expect(vec_info.Vector.len == 4);
344 expect(vec_info.Vector.child == i32);344 try expect(vec_info.Vector.child == i32);
345}345}
346346
347test "type info: anyframe and anyframe->T" {347test "type info: anyframe and anyframe->T" {
348 testAnyFrame();348 try testAnyFrame();
349 comptime testAnyFrame();349 comptime try testAnyFrame();
350}350}
351351
352fn testAnyFrame() void {352fn testAnyFrame() !void {
353 {353 {
354 const anyframe_info = @typeInfo(anyframe->i32);354 const anyframe_info = @typeInfo(anyframe->i32);
355 expect(anyframe_info == .AnyFrame);355 try expect(anyframe_info == .AnyFrame);
356 expect(anyframe_info.AnyFrame.child.? == i32);356 try expect(anyframe_info.AnyFrame.child.? == i32);
357 }357 }
358358
359 {359 {
360 const anyframe_info = @typeInfo(anyframe);360 const anyframe_info = @typeInfo(anyframe);
361 expect(anyframe_info == .AnyFrame);361 try expect(anyframe_info == .AnyFrame);
362 expect(anyframe_info.AnyFrame.child == null);362 try expect(anyframe_info.AnyFrame.child == null);
363 }363 }
364}364}
365365
...@@ -386,9 +386,9 @@ test "type info: extern fns with and without lib names" {...@@ -386,9 +386,9 @@ test "type info: extern fns with and without lib names" {
386 comptime {386 comptime {
387 for (info.Struct.decls) |decl| {387 for (info.Struct.decls) |decl| {
388 if (std.mem.eql(u8, decl.name, "bar1")) {388 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);
390 } else {390 } else {
391 expectEqualStrings("cool", decl.data.Fn.lib_name.?);391 try expectEqualStrings("cool", decl.data.Fn.lib_name.?);
392 }392 }
393 }393 }
394 }394 }
...@@ -398,12 +398,12 @@ test "data field is a compile-time value" {...@@ -398,12 +398,12 @@ test "data field is a compile-time value" {
398 const S = struct {398 const S = struct {
399 const Bar = @as(isize, -1);399 const Bar = @as(isize, -1);
400 };400 };
401 comptime expect(@typeInfo(S).Struct.decls[0].data.Var == isize);401 comptime try expect(@typeInfo(S).Struct.decls[0].data.Var == isize);
402}402}
403403
404test "sentinel of opaque pointer type" {404test "sentinel of opaque pointer type" {
405 const c_void_info = @typeInfo(*c_void);405 const c_void_info = @typeInfo(*c_void);
406 expect(c_void_info.Pointer.sentinel == null);406 try expect(c_void_info.Pointer.sentinel == null);
407}407}
408408
409test "@typeInfo does not force declarations into existence" {409test "@typeInfo does not force declarations into existence" {
...@@ -414,12 +414,12 @@ test "@typeInfo does not force declarations into existence" {...@@ -414,12 +414,12 @@ test "@typeInfo does not force declarations into existence" {
414 @compileError("test failed");414 @compileError("test failed");
415 }415 }
416 };416 };
417 comptime expect(@typeInfo(S).Struct.fields.len == 1);417 comptime try expect(@typeInfo(S).Struct.fields.len == 1);
418}418}
419419
420test "defaut value for a var-typed field" {420test "defaut value for a var-typed field" {
421 const S = struct { x: anytype };421 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);
423}423}
424424
425fn add(a: i32, b: i32) i32 {425fn add(a: i32, b: i32) i32 {
...@@ -429,7 +429,7 @@ fn add(a: i32, b: i32) i32 {...@@ -429,7 +429,7 @@ fn add(a: i32, b: i32) i32 {
429test "type info for async frames" {429test "type info for async frames" {
430 switch (@typeInfo(@Frame(add))) {430 switch (@typeInfo(@Frame(add))) {
431 .Frame => |frame| {431 .Frame => |frame| {
432 expect(frame.function == add);432 try expect(frame.function == add);
433 },433 },
434 else => unreachable,434 else => unreachable,
435 }435 }
...@@ -439,7 +439,7 @@ test "type info: value is correctly copied" {...@@ -439,7 +439,7 @@ test "type info: value is correctly copied" {
439 comptime {439 comptime {
440 var ptrInfo = @typeInfo([]u32);440 var ptrInfo = @typeInfo([]u32);
441 ptrInfo.Pointer.size = .One;441 ptrInfo.Pointer.size = .One;
442 expect(@typeInfo([]u32).Pointer.size == .Slice);442 try expect(@typeInfo([]u32).Pointer.size == .Slice);
443 }443 }
444}444}
445445
...@@ -452,22 +452,22 @@ test "Declarations are returned in declaration order" {...@@ -452,22 +452,22 @@ test "Declarations are returned in declaration order" {
452 const e = 5;452 const e = 5;
453 };453 };
454 const d = @typeInfo(S).Struct.decls;454 const d = @typeInfo(S).Struct.decls;
455 expect(std.mem.eql(u8, d[0].name, "a"));455 try expect(std.mem.eql(u8, d[0].name, "a"));
456 expect(std.mem.eql(u8, d[1].name, "b"));456 try expect(std.mem.eql(u8, d[1].name, "b"));
457 expect(std.mem.eql(u8, d[2].name, "c"));457 try expect(std.mem.eql(u8, d[2].name, "c"));
458 expect(std.mem.eql(u8, d[3].name, "d"));458 try expect(std.mem.eql(u8, d[3].name, "d"));
459 expect(std.mem.eql(u8, d[4].name, "e"));459 try expect(std.mem.eql(u8, d[4].name, "e"));
460}460}
461461
462test "Struct.is_tuple" {462test "Struct.is_tuple" {
463 expect(@typeInfo(@TypeOf(.{0})).Struct.is_tuple);463 try expect(@typeInfo(@TypeOf(.{0})).Struct.is_tuple);
464 expect(!@typeInfo(@TypeOf(.{ .a = 0 })).Struct.is_tuple);464 try expect(!@typeInfo(@TypeOf(.{ .a = 0 })).Struct.is_tuple);
465}465}
466466
467test "StructField.is_comptime" {467test "StructField.is_comptime" {
468 const info = @typeInfo(struct { x: u8 = 3, comptime y: u32 = 5 }).Struct;468 const info = @typeInfo(struct { x: u8 = 3, comptime y: u32 = 5 }).Struct;
469 expect(!info.fields[0].is_comptime);469 try expect(!info.fields[0].is_comptime);
470 expect(info.fields[1].is_comptime);470 try expect(info.fields[1].is_comptime);
471}471}
472472
473test "typeInfo resolves usingnamespace declarations" {473test "typeInfo resolves usingnamespace declarations" {
...@@ -480,6 +480,6 @@ test "typeInfo resolves usingnamespace declarations" {...@@ -480,6 +480,6 @@ test "typeInfo resolves usingnamespace declarations" {
480 usingnamespace A;480 usingnamespace A;
481 };481 };
482482
483 expect(@typeInfo(B).Struct.decls.len == 2);483 try expect(@typeInfo(B).Struct.decls.len == 2);
484 //a484 //a
485}485}
test/behavior/typename.zig+1-1
...@@ -3,5 +3,5 @@ const expect = std.testing.expect;...@@ -3,5 +3,5 @@ const expect = std.testing.expect;
3const expectEqualSlices = std.testing.expectEqualSlices;3const expectEqualSlices = std.testing.expectEqualSlices;
44
5test "slice" {5test "slice" {
6 expectEqualSlices(u8, "[]u8", @typeName([]u8));6 try expectEqualSlices(u8, "[]u8", @typeName([]u8));
7}7}
test/behavior/undefined.zig+13-13
...@@ -12,16 +12,16 @@ fn initStaticArray() [10]i32 {...@@ -12,16 +12,16 @@ fn initStaticArray() [10]i32 {
12}12}
13const static_array = initStaticArray();13const static_array = initStaticArray();
14test "init static array to undefined" {14test "init static array to undefined" {
15 expect(static_array[0] == 1);15 try expect(static_array[0] == 1);
16 expect(static_array[4] == 2);16 try expect(static_array[4] == 2);
17 expect(static_array[7] == 3);17 try expect(static_array[7] == 3);
18 expect(static_array[9] == 4);18 try expect(static_array[9] == 4);
1919
20 comptime {20 comptime {
21 expect(static_array[0] == 1);21 try expect(static_array[0] == 1);
22 expect(static_array[4] == 2);22 try expect(static_array[4] == 2);
23 expect(static_array[7] == 3);23 try expect(static_array[7] == 3);
24 expect(static_array[9] == 4);24 try expect(static_array[9] == 4);
25 }25 }
26}26}
2727
...@@ -41,12 +41,12 @@ test "assign undefined to struct" {...@@ -41,12 +41,12 @@ test "assign undefined to struct" {
41 comptime {41 comptime {
42 var foo: Foo = undefined;42 var foo: Foo = undefined;
43 setFooX(&foo);43 setFooX(&foo);
44 expect(foo.x == 2);44 try expect(foo.x == 2);
45 }45 }
46 {46 {
47 var foo: Foo = undefined;47 var foo: Foo = undefined;
48 setFooX(&foo);48 setFooX(&foo);
49 expect(foo.x == 2);49 try expect(foo.x == 2);
50 }50 }
51}51}
5252
...@@ -54,16 +54,16 @@ test "assign undefined to struct with method" {...@@ -54,16 +54,16 @@ test "assign undefined to struct with method" {
54 comptime {54 comptime {
55 var foo: Foo = undefined;55 var foo: Foo = undefined;
56 foo.setFooXMethod();56 foo.setFooXMethod();
57 expect(foo.x == 3);57 try expect(foo.x == 3);
58 }58 }
59 {59 {
60 var foo: Foo = undefined;60 var foo: Foo = undefined;
61 foo.setFooXMethod();61 foo.setFooXMethod();
62 expect(foo.x == 3);62 try expect(foo.x == 3);
63 }63 }
64}64}
6565
66test "type name of undefined" {66test "type name of undefined" {
67 const x = undefined;67 const x = undefined;
68 expect(mem.eql(u8, @typeName(@TypeOf(x)), "(undefined)"));68 try expect(mem.eql(u8, @typeName(@TypeOf(x)), "(undefined)"));
69}69}
test/behavior/union.zig+142-142
...@@ -30,11 +30,11 @@ const array = [_]Value{...@@ -30,11 +30,11 @@ const array = [_]Value{
3030
31test "unions embedded in aggregate types" {31test "unions embedded in aggregate types" {
32 switch (array[1]) {32 switch (array[1]) {
33 Value.Array => |arr| expect(arr[4] == 3),33 Value.Array => |arr| try expect(arr[4] == 3),
34 else => unreachable,34 else => unreachable,
35 }35 }
36 switch ((err catch unreachable).val1) {36 switch ((err catch unreachable).val1) {
37 Value.Int => |x| expect(x == 1234),37 Value.Int => |x| try expect(x == 1234),
38 else => unreachable,38 else => unreachable,
39 }39 }
40}40}
...@@ -46,18 +46,18 @@ const Foo = union {...@@ -46,18 +46,18 @@ const Foo = union {
4646
47test "basic unions" {47test "basic unions" {
48 var foo = Foo{ .int = 1 };48 var foo = Foo{ .int = 1 };
49 expect(foo.int == 1);49 try expect(foo.int == 1);
50 foo = Foo{ .float = 12.34 };50 foo = Foo{ .float = 12.34 };
51 expect(foo.float == 12.34);51 try expect(foo.float == 12.34);
52}52}
5353
54test "comptime union field access" {54test "comptime union field access" {
55 comptime {55 comptime {
56 var foo = Foo{ .int = 0 };56 var foo = Foo{ .int = 0 };
57 expect(foo.int == 0);57 try expect(foo.int == 0);
5858
59 foo = Foo{ .float = 42.42 };59 foo = Foo{ .float = 42.42 };
60 expect(foo.float == 42.42);60 try expect(foo.float == 42.42);
61 }61 }
62}62}
6363
...@@ -65,10 +65,10 @@ test "init union with runtime value" {...@@ -65,10 +65,10 @@ test "init union with runtime value" {
65 var foo: Foo = undefined;65 var foo: Foo = undefined;
6666
67 setFloat(&foo, 12.34);67 setFloat(&foo, 12.34);
68 expect(foo.float == 12.34);68 try expect(foo.float == 12.34);
6969
70 setInt(&foo, 42);70 setInt(&foo, 42);
71 expect(foo.int == 42);71 try expect(foo.int == 42);
72}72}
7373
74fn setFloat(foo: *Foo, x: f64) void {74fn setFloat(foo: *Foo, x: f64) void {
...@@ -86,9 +86,9 @@ const FooExtern = extern union {...@@ -86,9 +86,9 @@ const FooExtern = extern union {
8686
87test "basic extern unions" {87test "basic extern unions" {
88 var foo = FooExtern{ .int = 1 };88 var foo = FooExtern{ .int = 1 };
89 expect(foo.int == 1);89 try expect(foo.int == 1);
90 foo.float = 12.34;90 foo.float = 12.34;
91 expect(foo.float == 12.34);91 try expect(foo.float == 12.34);
92}92}
9393
94const Letter = enum {94const Letter = enum {
...@@ -103,16 +103,16 @@ const Payload = union(Letter) {...@@ -103,16 +103,16 @@ const Payload = union(Letter) {
103};103};
104104
105test "union with specified enum tag" {105test "union with specified enum tag" {
106 doTest();106 try doTest();
107 comptime doTest();107 comptime try doTest();
108}108}
109109
110fn doTest() void {110fn doTest() !void {
111 expect(bar(Payload{ .A = 1234 }) == -10);111 try expect((try bar(Payload{ .A = 1234 })) == -10);
112}112}
113113
114fn bar(value: Payload) i32 {114fn bar(value: Payload) !i32 {
115 expect(@as(Letter, value) == Letter.A);115 try expect(@as(Letter, value) == Letter.A);
116 return switch (value) {116 return switch (value) {
117 Payload.A => |x| return x - 1244,117 Payload.A => |x| return x - 1244,
118 Payload.B => |x| if (x == 12.34) @as(i32, 20) else 21,118 Payload.B => |x| if (x == 12.34) @as(i32, 20) else 21,
...@@ -128,8 +128,8 @@ const MultipleChoice = union(enum(u32)) {...@@ -128,8 +128,8 @@ const MultipleChoice = union(enum(u32)) {
128};128};
129test "simple union(enum(u32))" {129test "simple union(enum(u32))" {
130 var x = MultipleChoice.C;130 var x = MultipleChoice.C;
131 expect(x == MultipleChoice.C);131 try expect(x == MultipleChoice.C);
132 expect(@enumToInt(@as(Tag(MultipleChoice), x)) == 60);132 try expect(@enumToInt(@as(Tag(MultipleChoice), x)) == 60);
133}133}
134134
135const MultipleChoice2 = union(enum(u32)) {135const MultipleChoice2 = union(enum(u32)) {
...@@ -145,14 +145,14 @@ const MultipleChoice2 = union(enum(u32)) {...@@ -145,14 +145,14 @@ const MultipleChoice2 = union(enum(u32)) {
145};145};
146146
147test "union(enum(u32)) with specified and unspecified tag values" {147test "union(enum(u32)) with specified and unspecified tag values" {
148 comptime expect(Tag(Tag(MultipleChoice2)) == u32);148 comptime try expect(Tag(Tag(MultipleChoice2)) == u32);
149 testEnumWithSpecifiedAndUnspecifiedTagValues(MultipleChoice2{ .C = 123 });149 try testEnumWithSpecifiedAndUnspecifiedTagValues(MultipleChoice2{ .C = 123 });
150 comptime testEnumWithSpecifiedAndUnspecifiedTagValues(MultipleChoice2{ .C = 123 });150 comptime try testEnumWithSpecifiedAndUnspecifiedTagValues(MultipleChoice2{ .C = 123 });
151}151}
152152
153fn testEnumWithSpecifiedAndUnspecifiedTagValues(x: MultipleChoice2) void {153fn testEnumWithSpecifiedAndUnspecifiedTagValues(x: MultipleChoice2) !void {
154 expect(@enumToInt(@as(Tag(MultipleChoice2), x)) == 60);154 try expect(@enumToInt(@as(Tag(MultipleChoice2), x)) == 60);
155 expect(1123 == switch (x) {155 try expect(1123 == switch (x) {
156 MultipleChoice2.A => 1,156 MultipleChoice2.A => 1,
157 MultipleChoice2.B => 2,157 MultipleChoice2.B => 2,
158 MultipleChoice2.C => |v| @as(i32, 1000) + v,158 MultipleChoice2.C => |v| @as(i32, 1000) + v,
...@@ -170,7 +170,7 @@ const ExternPtrOrInt = extern union {...@@ -170,7 +170,7 @@ const ExternPtrOrInt = extern union {
170 int: u64,170 int: u64,
171};171};
172test "extern union size" {172test "extern union size" {
173 comptime expect(@sizeOf(ExternPtrOrInt) == 8);173 comptime try expect(@sizeOf(ExternPtrOrInt) == 8);
174}174}
175175
176const PackedPtrOrInt = packed union {176const PackedPtrOrInt = packed union {
...@@ -178,14 +178,14 @@ const PackedPtrOrInt = packed union {...@@ -178,14 +178,14 @@ const PackedPtrOrInt = packed union {
178 int: u64,178 int: u64,
179};179};
180test "extern union size" {180test "extern union size" {
181 comptime expect(@sizeOf(PackedPtrOrInt) == 8);181 comptime try expect(@sizeOf(PackedPtrOrInt) == 8);
182}182}
183183
184const ZeroBits = union {184const ZeroBits = union {
185 OnlyField: void,185 OnlyField: void,
186};186};
187test "union with only 1 field which is void should be zero bits" {187test "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);
189}189}
190190
191const TheTag = enum {191const TheTag = enum {
...@@ -199,23 +199,23 @@ const TheUnion = union(TheTag) {...@@ -199,23 +199,23 @@ const TheUnion = union(TheTag) {
199 C: i32,199 C: i32,
200};200};
201test "union field access gives the enum values" {201test "union field access gives the enum values" {
202 expect(TheUnion.A == TheTag.A);202 try expect(TheUnion.A == TheTag.A);
203 expect(TheUnion.B == TheTag.B);203 try expect(TheUnion.B == TheTag.B);
204 expect(TheUnion.C == TheTag.C);204 try expect(TheUnion.C == TheTag.C);
205}205}
206206
207test "cast union to tag type of union" {207test "cast union to tag type of union" {
208 testCastUnionToTag(TheUnion{ .B = 1234 });208 try testCastUnionToTag(TheUnion{ .B = 1234 });
209 comptime testCastUnionToTag(TheUnion{ .B = 1234 });209 comptime try testCastUnionToTag(TheUnion{ .B = 1234 });
210}210}
211211
212fn testCastUnionToTag(x: TheUnion) void {212fn testCastUnionToTag(x: TheUnion) !void {
213 expect(@as(TheTag, x) == TheTag.B);213 try expect(@as(TheTag, x) == TheTag.B);
214}214}
215215
216test "cast tag type of union to union" {216test "cast tag type of union to union" {
217 var x: Value2 = Letter2.B;217 var x: Value2 = Letter2.B;
218 expect(@as(Letter2, x) == Letter2.B);218 try expect(@as(Letter2, x) == Letter2.B);
219}219}
220const Letter2 = enum {220const Letter2 = enum {
221 A,221 A,
...@@ -230,11 +230,11 @@ const Value2 = union(Letter2) {...@@ -230,11 +230,11 @@ const Value2 = union(Letter2) {
230230
231test "implicit cast union to its tag type" {231test "implicit cast union to its tag type" {
232 var x: Value2 = Letter2.B;232 var x: Value2 = Letter2.B;
233 expect(x == Letter2.B);233 try expect(x == Letter2.B);
234 giveMeLetterB(x);234 try giveMeLetterB(x);
235}235}
236fn giveMeLetterB(x: Letter2) void {236fn giveMeLetterB(x: Letter2) !void {
237 expect(x == Value2.B);237 try expect(x == Value2.B);
238}238}
239239
240pub const PackThis = union(enum) {240pub const PackThis = union(enum) {
...@@ -243,11 +243,11 @@ pub const PackThis = union(enum) {...@@ -243,11 +243,11 @@ pub const PackThis = union(enum) {
243};243};
244244
245test "constant packed union" {245test "constant packed union" {
246 testConstPackedUnion(&[_]PackThis{PackThis{ .StringLiteral = 1 }});246 try testConstPackedUnion(&[_]PackThis{PackThis{ .StringLiteral = 1 }});
247}247}
248248
249fn testConstPackedUnion(expected_tokens: []const PackThis) void {249fn testConstPackedUnion(expected_tokens: []const PackThis) !void {
250 expect(expected_tokens[0].StringLiteral == 1);250 try expect(expected_tokens[0].StringLiteral == 1);
251}251}
252252
253test "switch on union with only 1 field" {253test "switch on union with only 1 field" {
...@@ -259,7 +259,7 @@ test "switch on union with only 1 field" {...@@ -259,7 +259,7 @@ test "switch on union with only 1 field" {
259 z = PartialInstWithPayload{ .Compiled = 1234 };259 z = PartialInstWithPayload{ .Compiled = 1234 };
260 switch (z) {260 switch (z) {
261 PartialInstWithPayload.Compiled => |x| {261 PartialInstWithPayload.Compiled => |x| {
262 expect(x == 1234);262 try expect(x == 1234);
263 return;263 return;
264 },264 },
265 }265 }
...@@ -285,11 +285,11 @@ test "access a member of tagged union with conflicting enum tag name" {...@@ -285,11 +285,11 @@ test "access a member of tagged union with conflicting enum tag name" {
285 const B = void;285 const B = void;
286 };286 };
287287
288 comptime expect(Bar.A == u8);288 comptime try expect(Bar.A == u8);
289}289}
290290
291test "tagged union initialization with runtime void" {291test "tagged union initialization with runtime void" {
292 expect(testTaggedUnionInit({}));292 try expect(testTaggedUnionInit({}));
293}293}
294294
295const TaggedUnionWithAVoid = union(enum) {295const TaggedUnionWithAVoid = union(enum) {
...@@ -327,9 +327,9 @@ test "union with only 1 field casted to its enum type" {...@@ -327,9 +327,9 @@ test "union with only 1 field casted to its enum type" {
327327
328 var e = Expr{ .Literal = Literal{ .Bool = true } };328 var e = Expr{ .Literal = Literal{ .Bool = true } };
329 const ExprTag = Tag(Expr);329 const ExprTag = Tag(Expr);
330 comptime expect(Tag(ExprTag) == u0);330 comptime try expect(Tag(ExprTag) == u0);
331 var t = @as(ExprTag, e);331 var t = @as(ExprTag, e);
332 expect(t == Expr.Literal);332 try expect(t == Expr.Literal);
333}333}
334334
335test "union with only 1 field casted to its enum type which has enum value specified" {335test "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...@@ -347,11 +347,11 @@ test "union with only 1 field casted to its enum type which has enum value speci
347 };347 };
348348
349 var e = Expr{ .Literal = Literal{ .Bool = true } };349 var e = Expr{ .Literal = Literal{ .Bool = true } };
350 comptime expect(Tag(ExprTag) == comptime_int);350 comptime try expect(Tag(ExprTag) == comptime_int);
351 var t = @as(ExprTag, e);351 var t = @as(ExprTag, e);
352 expect(t == Expr.Literal);352 try expect(t == Expr.Literal);
353 expect(@enumToInt(t) == 33);353 try expect(@enumToInt(t) == 33);
354 comptime expect(@enumToInt(t) == 33);354 comptime try expect(@enumToInt(t) == 33);
355}355}
356356
357test "@enumToInt works on unions" {357test "@enumToInt works on unions" {
...@@ -364,9 +364,9 @@ test "@enumToInt works on unions" {...@@ -364,9 +364,9 @@ test "@enumToInt works on unions" {
364 const a = Bar{ .A = true };364 const a = Bar{ .A = true };
365 var b = Bar{ .B = undefined };365 var b = Bar{ .B = undefined };
366 var c = Bar.C;366 var c = Bar.C;
367 expect(@enumToInt(a) == 0);367 try expect(@enumToInt(a) == 0);
368 expect(@enumToInt(b) == 1);368 try expect(@enumToInt(b) == 1);
369 expect(@enumToInt(c) == 2);369 try expect(@enumToInt(c) == 2);
370}370}
371371
372const Attribute = union(enum) {372const Attribute = union(enum) {
...@@ -393,23 +393,23 @@ test "comptime union field value equality" {...@@ -393,23 +393,23 @@ test "comptime union field value equality" {
393 const b1 = Setter(Attribute{ .B = 9 });393 const b1 = Setter(Attribute{ .B = 9 });
394 const b2 = Setter(Attribute{ .B = 5 });394 const b2 = Setter(Attribute{ .B = 5 });
395395
396 expect(a0 == a0);396 try expect(a0 == a0);
397 expect(a1 == a1);397 try expect(a1 == a1);
398 expect(a0 == a2);398 try expect(a0 == a2);
399399
400 expect(b0 == b0);400 try expect(b0 == b0);
401 expect(b1 == b1);401 try expect(b1 == b1);
402 expect(b0 == b2);402 try expect(b0 == b2);
403403
404 expect(a0 != b0);404 try expect(a0 != b0);
405 expect(a0 != a1);405 try expect(a0 != a1);
406 expect(b0 != b1);406 try expect(b0 != b1);
407}407}
408408
409test "return union init with void payload" {409test "return union init with void payload" {
410 const S = struct {410 const S = struct {
411 fn entry() void {411 fn entry() !void {
412 expect(func().state == State.one);412 try expect(func().state == State.one);
413 }413 }
414 const Outer = union(enum) {414 const Outer = union(enum) {
415 state: State,415 state: State,
...@@ -422,8 +422,8 @@ test "return union init with void payload" {...@@ -422,8 +422,8 @@ test "return union init with void payload" {
422 return Outer{ .state = State{ .one = {} } };422 return Outer{ .state = State{ .one = {} } };
423 }423 }
424 };424 };
425 S.entry();425 try S.entry();
426 comptime S.entry();426 comptime try S.entry();
427}427}
428428
429test "@unionInit can modify a union type" {429test "@unionInit can modify a union type" {
...@@ -435,14 +435,14 @@ test "@unionInit can modify a union type" {...@@ -435,14 +435,14 @@ test "@unionInit can modify a union type" {
435 var value: UnionInitEnum = undefined;435 var value: UnionInitEnum = undefined;
436436
437 value = @unionInit(UnionInitEnum, "Boolean", true);437 value = @unionInit(UnionInitEnum, "Boolean", true);
438 expect(value.Boolean == true);438 try expect(value.Boolean == true);
439 value.Boolean = false;439 value.Boolean = false;
440 expect(value.Boolean == false);440 try expect(value.Boolean == false);
441441
442 value = @unionInit(UnionInitEnum, "Byte", 2);442 value = @unionInit(UnionInitEnum, "Byte", 2);
443 expect(value.Byte == 2);443 try expect(value.Byte == 2);
444 value.Byte = 3;444 value.Byte = 3;
445 expect(value.Byte == 3);445 try expect(value.Byte == 3);
446}446}
447447
448test "@unionInit can modify a pointer value" {448test "@unionInit can modify a pointer value" {
...@@ -455,10 +455,10 @@ test "@unionInit can modify a pointer value" {...@@ -455,10 +455,10 @@ test "@unionInit can modify a pointer value" {
455 var value_ptr = &value;455 var value_ptr = &value;
456456
457 value_ptr.* = @unionInit(UnionInitEnum, "Boolean", true);457 value_ptr.* = @unionInit(UnionInitEnum, "Boolean", true);
458 expect(value.Boolean == true);458 try expect(value.Boolean == true);
459459
460 value_ptr.* = @unionInit(UnionInitEnum, "Byte", 2);460 value_ptr.* = @unionInit(UnionInitEnum, "Byte", 2);
461 expect(value.Byte == 2);461 try expect(value.Byte == 2);
462}462}
463463
464test "union no tag with struct member" {464test "union no tag with struct member" {
...@@ -471,38 +471,38 @@ test "union no tag with struct member" {...@@ -471,38 +471,38 @@ test "union no tag with struct member" {
471 u.foo();471 u.foo();
472}472}
473473
474fn testComparison() void {474fn testComparison() !void {
475 var x = Payload{ .A = 42 };475 var x = Payload{ .A = 42 };
476 expect(x == .A);476 try expect(x == .A);
477 expect(x != .B);477 try expect(x != .B);
478 expect(x != .C);478 try expect(x != .C);
479 expect((x == .B) == false);479 try expect((x == .B) == false);
480 expect((x == .C) == false);480 try expect((x == .C) == false);
481 expect((x != .A) == false);481 try expect((x != .A) == false);
482}482}
483483
484test "comparison between union and enum literal" {484test "comparison between union and enum literal" {
485 testComparison();485 try testComparison();
486 comptime testComparison();486 comptime try testComparison();
487}487}
488488
489test "packed union generates correctly aligned LLVM type" {489test "packed union generates correctly aligned LLVM type" {
490 const U = packed union {490 const U = packed union {
491 f1: fn () void,491 f1: fn () error{TestUnexpectedResult}!void,
492 f2: u32,492 f2: u32,
493 };493 };
494 var foo = [_]U{494 var foo = [_]U{
495 U{ .f1 = doTest },495 U{ .f1 = doTest },
496 U{ .f2 = 0 },496 U{ .f2 = 0 },
497 };497 };
498 foo[0].f1();498 try foo[0].f1();
499}499}
500500
501test "union with one member defaults to u0 tag type" {501test "union with one member defaults to u0 tag type" {
502 const U0 = union(enum) {502 const U0 = union(enum) {
503 X: u32,503 X: u32,
504 };504 };
505 comptime expect(Tag(Tag(U0)) == u0);505 comptime try expect(Tag(Tag(U0)) == u0);
506}506}
507507
508test "union with comptime_int tag" {508test "union with comptime_int tag" {
...@@ -511,7 +511,7 @@ test "union with comptime_int tag" {...@@ -511,7 +511,7 @@ test "union with comptime_int tag" {
511 Y: u16,511 Y: u16,
512 Z: u8,512 Z: u8,
513 };513 };
514 comptime expect(Tag(Tag(Union)) == comptime_int);514 comptime try expect(Tag(Tag(Union)) == comptime_int);
515}515}
516516
517test "extern union doesn't trigger field check at comptime" {517test "extern union doesn't trigger field check at comptime" {
...@@ -521,7 +521,7 @@ test "extern union doesn't trigger field check at comptime" {...@@ -521,7 +521,7 @@ test "extern union doesn't trigger field check at comptime" {
521 };521 };
522522
523 const x = U{ .x = 0x55AAAA55 };523 const x = U{ .x = 0x55AAAA55 };
524 comptime expect(x.y == 0x55);524 comptime try expect(x.y == 0x55);
525}525}
526526
527const Foo1 = union(enum) {527const Foo1 = union(enum) {
...@@ -535,7 +535,7 @@ test "global union with single field is correctly initialized" {...@@ -535,7 +535,7 @@ test "global union with single field is correctly initialized" {
535 glbl = Foo1{535 glbl = Foo1{
536 .f = @typeInfo(Foo1).Union.fields[0].field_type{ .x = 123 },536 .f = @typeInfo(Foo1).Union.fields[0].field_type{ .x = 123 },
537 };537 };
538 expect(glbl.f.x == 123);538 try expect(glbl.f.x == 123);
539}539}
540540
541pub const FooUnion = union(enum) {541pub const FooUnion = union(enum) {
...@@ -548,8 +548,8 @@ var glbl_array: [2]FooUnion = undefined;...@@ -548,8 +548,8 @@ var glbl_array: [2]FooUnion = undefined;
548test "initialize global array of union" {548test "initialize global array of union" {
549 glbl_array[1] = FooUnion{ .U1 = 2 };549 glbl_array[1] = FooUnion{ .U1 = 2 };
550 glbl_array[0] = FooUnion{ .U0 = 1 };550 glbl_array[0] = FooUnion{ .U0 = 1 };
551 expect(glbl_array[0].U0 == 1);551 try expect(glbl_array[0].U0 == 1);
552 expect(glbl_array[1].U1 == 2);552 try expect(glbl_array[1].U1 == 2);
553}553}
554554
555test "anonymous union literal syntax" {555test "anonymous union literal syntax" {
...@@ -559,19 +559,19 @@ test "anonymous union literal syntax" {...@@ -559,19 +559,19 @@ test "anonymous union literal syntax" {
559 float: f64,559 float: f64,
560 };560 };
561561
562 fn doTheTest() void {562 fn doTheTest() !void {
563 var i: Number = .{ .int = 42 };563 var i: Number = .{ .int = 42 };
564 var f = makeNumber();564 var f = makeNumber();
565 expect(i.int == 42);565 try expect(i.int == 42);
566 expect(f.float == 12.34);566 try expect(f.float == 12.34);
567 }567 }
568568
569 fn makeNumber() Number {569 fn makeNumber() Number {
570 return .{ .float = 12.34 };570 return .{ .float = 12.34 };
571 }571 }
572 };572 };
573 S.doTheTest();573 try S.doTheTest();
574 comptime S.doTheTest();574 comptime try S.doTheTest();
575}575}
576576
577test "update the tag value for zero-sized unions" {577test "update the tag value for zero-sized unions" {
...@@ -580,9 +580,9 @@ test "update the tag value for zero-sized unions" {...@@ -580,9 +580,9 @@ test "update the tag value for zero-sized unions" {
580 U1: void,580 U1: void,
581 };581 };
582 var x = S{ .U0 = {} };582 var x = S{ .U0 = {} };
583 expect(x == .U0);583 try expect(x == .U0);
584 x = S{ .U1 = {} };584 x = S{ .U1 = {} };
585 expect(x == .U1);585 try expect(x == .U1);
586}586}
587587
588test "function call result coerces from tagged union to the tag" {588test "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" {...@@ -594,12 +594,12 @@ test "function call result coerces from tagged union to the tag" {
594594
595 const ArchTag = Tag(Arch);595 const ArchTag = Tag(Arch);
596596
597 fn doTheTest() void {597 fn doTheTest() !void {
598 var x: ArchTag = getArch1();598 var x: ArchTag = getArch1();
599 expect(x == .One);599 try expect(x == .One);
600600
601 var y: ArchTag = getArch2();601 var y: ArchTag = getArch2();
602 expect(y == .Two);602 try expect(y == .Two);
603 }603 }
604604
605 pub fn getArch1() Arch {605 pub fn getArch1() Arch {
...@@ -610,8 +610,8 @@ test "function call result coerces from tagged union to the tag" {...@@ -610,8 +610,8 @@ test "function call result coerces from tagged union to the tag" {
610 return .{ .Two = 99 };610 return .{ .Two = 99 };
611 }611 }
612 };612 };
613 S.doTheTest();613 try S.doTheTest();
614 comptime S.doTheTest();614 comptime try S.doTheTest();
615}615}
616616
617test "0-sized extern union definition" {617test "0-sized extern union definition" {
...@@ -620,7 +620,7 @@ test "0-sized extern union definition" {...@@ -620,7 +620,7 @@ test "0-sized extern union definition" {
620 const f = 1;620 const f = 1;
621 };621 };
622622
623 expect(U.f == 1);623 try expect(U.f == 1);
624}624}
625625
626test "union initializer generates padding only if needed" {626test "union initializer generates padding only if needed" {
...@@ -629,7 +629,7 @@ test "union initializer generates padding only if needed" {...@@ -629,7 +629,7 @@ test "union initializer generates padding only if needed" {
629 };629 };
630630
631 var v = U{ .A = 532 };631 var v = U{ .A = 532 };
632 expect(v.A == 532);632 try expect(v.A == 532);
633}633}
634634
635test "runtime tag name with single field" {635test "runtime tag name with single field" {
...@@ -638,7 +638,7 @@ test "runtime tag name with single field" {...@@ -638,7 +638,7 @@ test "runtime tag name with single field" {
638 };638 };
639639
640 var v = U{ .A = 42 };640 var v = U{ .A = 42 };
641 expect(std.mem.eql(u8, @tagName(v), "A"));641 try expect(std.mem.eql(u8, @tagName(v), "A"));
642}642}
643643
644test "cast from anonymous struct to union" {644test "cast from anonymous struct to union" {
...@@ -648,7 +648,7 @@ test "cast from anonymous struct to union" {...@@ -648,7 +648,7 @@ test "cast from anonymous struct to union" {
648 B: []const u8,648 B: []const u8,
649 C: void,649 C: void,
650 };650 };
651 fn doTheTest() void {651 fn doTheTest() !void {
652 var y: u32 = 42;652 var y: u32 = 42;
653 const t0 = .{ .A = 123 };653 const t0 = .{ .A = 123 };
654 const t1 = .{ .B = "foo" };654 const t1 = .{ .B = "foo" };
...@@ -658,14 +658,14 @@ test "cast from anonymous struct to union" {...@@ -658,14 +658,14 @@ test "cast from anonymous struct to union" {
658 var x1: U = t1;658 var x1: U = t1;
659 const x2: U = t2;659 const x2: U = t2;
660 var x3: U = t3;660 var x3: U = t3;
661 expect(x0.A == 123);661 try expect(x0.A == 123);
662 expect(std.mem.eql(u8, x1.B, "foo"));662 try expect(std.mem.eql(u8, x1.B, "foo"));
663 expect(x2 == .C);663 try expect(x2 == .C);
664 expect(x3.A == y);664 try expect(x3.A == y);
665 }665 }
666 };666 };
667 S.doTheTest();667 try S.doTheTest();
668 comptime S.doTheTest();668 comptime try S.doTheTest();
669}669}
670670
671test "cast from pointer to anonymous struct to pointer to union" {671test "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" {...@@ -675,7 +675,7 @@ test "cast from pointer to anonymous struct to pointer to union" {
675 B: []const u8,675 B: []const u8,
676 C: void,676 C: void,
677 };677 };
678 fn doTheTest() void {678 fn doTheTest() !void {
679 var y: u32 = 42;679 var y: u32 = 42;
680 const t0 = &.{ .A = 123 };680 const t0 = &.{ .A = 123 };
681 const t1 = &.{ .B = "foo" };681 const t1 = &.{ .B = "foo" };
...@@ -685,14 +685,14 @@ test "cast from pointer to anonymous struct to pointer to union" {...@@ -685,14 +685,14 @@ test "cast from pointer to anonymous struct to pointer to union" {
685 var x1: *const U = t1;685 var x1: *const U = t1;
686 const x2: *const U = t2;686 const x2: *const U = t2;
687 var x3: *const U = t3;687 var x3: *const U = t3;
688 expect(x0.A == 123);688 try expect(x0.A == 123);
689 expect(std.mem.eql(u8, x1.B, "foo"));689 try expect(std.mem.eql(u8, x1.B, "foo"));
690 expect(x2.* == .C);690 try expect(x2.* == .C);
691 expect(x3.A == y);691 try expect(x3.A == y);
692 }692 }
693 };693 };
694 S.doTheTest();694 try S.doTheTest();
695 comptime S.doTheTest();695 comptime try S.doTheTest();
696}696}
697697
698test "method call on an empty union" {698test "method call on an empty union" {
...@@ -707,13 +707,13 @@ test "method call on an empty union" {...@@ -707,13 +707,13 @@ test "method call on an empty union" {
707 }707 }
708 };708 };
709709
710 fn doTheTest() void {710 fn doTheTest() !void {
711 var u = MyUnion{ .X1 = [0]u8{} };711 var u = MyUnion{ .X1 = [0]u8{} };
712 expect(u.useIt());712 try expect(u.useIt());
713 }713 }
714 };714 };
715 S.doTheTest();715 try S.doTheTest();
716 comptime S.doTheTest();716 comptime try S.doTheTest();
717}717}
718718
719test "switching on non exhaustive union" {719test "switching on non exhaustive union" {
...@@ -727,16 +727,16 @@ test "switching on non exhaustive union" {...@@ -727,16 +727,16 @@ test "switching on non exhaustive union" {
727 a: i32,727 a: i32,
728 b: u32,728 b: u32,
729 };729 };
730 fn doTheTest() void {730 fn doTheTest() !void {
731 var a = U{ .a = 2 };731 var a = U{ .a = 2 };
732 switch (a) {732 switch (a) {
733 .a => |val| expect(val == 2),733 .a => |val| try expect(val == 2),
734 .b => unreachable,734 .b => unreachable,
735 }735 }
736 }736 }
737 };737 };
738 S.doTheTest();738 try S.doTheTest();
739 comptime S.doTheTest();739 comptime try S.doTheTest();
740}740}
741741
742test "containers with single-field enums" {742test "containers with single-field enums" {
...@@ -746,21 +746,21 @@ test "containers with single-field enums" {...@@ -746,21 +746,21 @@ test "containers with single-field enums" {
746 const C = struct { a: A };746 const C = struct { a: A };
747 const D = struct { a: B };747 const D = struct { a: B };
748748
749 fn doTheTest() void {749 fn doTheTest() !void {
750 var array1 = [1]A{A{ .f1 = {} }};750 var array1 = [1]A{A{ .f1 = {} }};
751 var array2 = [1]B{B{ .f1 = {} }};751 var array2 = [1]B{B{ .f1 = {} }};
752 expect(array1[0] == .f1);752 try expect(array1[0] == .f1);
753 expect(array2[0] == .f1);753 try expect(array2[0] == .f1);
754754
755 var struct1 = C{ .a = A{ .f1 = {} } };755 var struct1 = C{ .a = A{ .f1 = {} } };
756 var struct2 = D{ .a = B{ .f1 = {} } };756 var struct2 = D{ .a = B{ .f1 = {} } };
757 expect(struct1.a == .f1);757 try expect(struct1.a == .f1);
758 expect(struct2.a == .f1);758 try expect(struct2.a == .f1);
759 }759 }
760 };760 };
761761
762 S.doTheTest();762 try S.doTheTest();
763 comptime S.doTheTest();763 comptime try S.doTheTest();
764}764}
765765
766test "@unionInit on union w/ tag but no fields" {766test "@unionInit on union w/ tag but no fields" {
...@@ -776,18 +776,18 @@ test "@unionInit on union w/ tag but no fields" {...@@ -776,18 +776,18 @@ test "@unionInit on union w/ tag but no fields" {
776 };776 };
777777
778 comptime {778 comptime {
779 expect(@sizeOf(Data) != 0);779 try expect(@sizeOf(Data) != 0);
780 }780 }
781781
782 fn doTheTest() void {782 fn doTheTest() !void {
783 var data: Data = .{ .no_op = .{} };783 var data: Data = .{ .no_op = .{} };
784 var o = Data.decode(&[_]u8{});784 var o = Data.decode(&[_]u8{});
785 expectEqual(Type.no_op, o);785 try expectEqual(Type.no_op, o);
786 }786 }
787 };787 };
788788
789 S.doTheTest();789 try S.doTheTest();
790 comptime S.doTheTest();790 comptime try S.doTheTest();
791}791}
792792
793test "union enum type gets a separate scope" {793test "union enum type gets a separate scope" {
...@@ -797,10 +797,10 @@ test "union enum type gets a separate scope" {...@@ -797,10 +797,10 @@ test "union enum type gets a separate scope" {
797 const foo = 1;797 const foo = 1;
798 };798 };
799799
800 fn doTheTest() void {800 fn doTheTest() !void {
801 expect(!@hasDecl(Tag(U), "foo"));801 try expect(!@hasDecl(Tag(U), "foo"));
802 }802 }
803 };803 };
804804
805 S.doTheTest();805 try S.doTheTest();
806}806}
test/behavior/usingnamespace.zig+3-3
...@@ -9,8 +9,8 @@ fn Foo(comptime T: type) type {...@@ -9,8 +9,8 @@ fn Foo(comptime T: type) type {
9test "usingnamespace inside a generic struct" {9test "usingnamespace inside a generic struct" {
10 const std2 = Foo(std);10 const std2 = Foo(std);
11 const testing2 = Foo(std.testing);11 const testing2 = Foo(std.testing);
12 std2.testing.expect(true);12 try std2.testing.expect(true);
13 testing2.expect(true);13 try testing2.expect(true);
14}14}
1515
16usingnamespace struct {16usingnamespace struct {
...@@ -18,5 +18,5 @@ usingnamespace struct {...@@ -18,5 +18,5 @@ usingnamespace struct {
18};18};
1919
20test "usingnamespace does not redeclare an imported variable" {20test "usingnamespace does not redeclare an imported variable" {
21 comptime std.testing.expect(foo == 42);21 comptime try std.testing.expect(foo == 42);
22}22}
test/behavior/var_args.zig+17-17
...@@ -12,9 +12,9 @@ fn add(args: anytype) i32 {...@@ -12,9 +12,9 @@ fn add(args: anytype) i32 {
12}12}
1313
14test "add arbitrary args" {14test "add arbitrary args" {
15 expect(add(.{ @as(i32, 1), @as(i32, 2), @as(i32, 3), @as(i32, 4) }) == 10);15 try expect(add(.{ @as(i32, 1), @as(i32, 2), @as(i32, 3), @as(i32, 4) }) == 10);
16 expect(add(.{@as(i32, 1234)}) == 1234);16 try expect(add(.{@as(i32, 1234)}) == 1234);
17 expect(add(.{}) == 0);17 try expect(add(.{}) == 0);
18}18}
1919
20fn readFirstVarArg(args: anytype) void {20fn readFirstVarArg(args: anytype) void {
...@@ -26,9 +26,9 @@ test "send void arg to var args" {...@@ -26,9 +26,9 @@ test "send void arg to var args" {
26}26}
2727
28test "pass args directly" {28test "pass args directly" {
29 expect(addSomeStuff(.{ @as(i32, 1), @as(i32, 2), @as(i32, 3), @as(i32, 4) }) == 10);29 try expect(addSomeStuff(.{ @as(i32, 1), @as(i32, 2), @as(i32, 3), @as(i32, 4) }) == 10);
30 expect(addSomeStuff(.{@as(i32, 1234)}) == 1234);30 try expect(addSomeStuff(.{@as(i32, 1234)}) == 1234);
31 expect(addSomeStuff(.{}) == 0);31 try expect(addSomeStuff(.{}) == 0);
32}32}
3333
34fn addSomeStuff(args: anytype) i32 {34fn addSomeStuff(args: anytype) i32 {
...@@ -36,23 +36,23 @@ fn addSomeStuff(args: anytype) i32 {...@@ -36,23 +36,23 @@ fn addSomeStuff(args: anytype) i32 {
36}36}
3737
38test "runtime parameter before var args" {38test "runtime parameter before var args" {
39 expect(extraFn(10, .{}) == 0);39 try expect((try extraFn(10, .{})) == 0);
40 expect(extraFn(10, .{false}) == 1);40 try expect((try extraFn(10, .{false})) == 1);
41 expect(extraFn(10, .{ false, true }) == 2);41 try expect((try extraFn(10, .{ false, true })) == 2);
4242
43 comptime {43 comptime {
44 expect(extraFn(10, .{}) == 0);44 try expect((try extraFn(10, .{})) == 0);
45 expect(extraFn(10, .{false}) == 1);45 try expect((try extraFn(10, .{false})) == 1);
46 expect(extraFn(10, .{ false, true }) == 2);46 try expect((try extraFn(10, .{ false, true })) == 2);
47 }47 }
48}48}
4949
50fn extraFn(extra: u32, args: anytype) usize {50fn extraFn(extra: u32, args: anytype) !usize {
51 if (args.len >= 1) {51 if (args.len >= 1) {
52 expect(args[0] == false);52 try expect(args[0] == false);
53 }53 }
54 if (args.len >= 2) {54 if (args.len >= 2) {
55 expect(args[1] == true);55 try expect(args[1] == true);
56 }56 }
57 return args.len;57 return args.len;
58}58}
...@@ -70,8 +70,8 @@ fn foo2(args: anytype) bool {...@@ -70,8 +70,8 @@ fn foo2(args: anytype) bool {
70}70}
7171
72test "array of var args functions" {72test "array of var args functions" {
73 expect(foos[0](.{}));73 try expect(foos[0](.{}));
74 expect(!foos[1](.{}));74 try expect(!foos[1](.{}));
75}75}
7676
77test "pass zero length array to var args param" {77test "pass zero length array to var args param" {
test/behavior/vector.zig+280-280
...@@ -9,104 +9,104 @@ const Vector = std.meta.Vector;...@@ -9,104 +9,104 @@ const Vector = std.meta.Vector;
99
10test "implicit cast vector to array - bool" {10test "implicit cast vector to array - bool" {
11 const S = struct {11 const S = struct {
12 fn doTheTest() void {12 fn doTheTest() !void {
13 const a: Vector(4, bool) = [_]bool{ true, false, true, false };13 const a: Vector(4, bool) = [_]bool{ true, false, true, false };
14 const result_array: [4]bool = a;14 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 }));
16 }16 }
17 };17 };
18 S.doTheTest();18 try S.doTheTest();
19 comptime S.doTheTest();19 comptime try S.doTheTest();
20}20}
2121
22test "vector wrap operators" {22test "vector wrap operators" {
23 const S = struct {23 const S = struct {
24 fn doTheTest() void {24 fn doTheTest() !void {
25 var v: Vector(4, i32) = [4]i32{ 2147483647, -2, 30, 40 };25 var v: Vector(4, i32) = [4]i32{ 2147483647, -2, 30, 40 };
26 var x: Vector(4, i32) = [4]i32{ 1, 2147483647, 3, 4 };26 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 }));27 try 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 }));28 try 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 }));29 try expect(mem.eql(i32, &@as([4]i32, v *% x), &[4]i32{ 2147483647, 2, 90, 160 }));
30 var z: Vector(4, i32) = [4]i32{ 1, 2, 3, -2147483648 };30 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 }));
32 }32 }
33 };33 };
34 S.doTheTest();34 try S.doTheTest();
35 comptime S.doTheTest();35 comptime try S.doTheTest();
36}36}
3737
38test "vector bin compares with mem.eql" {38test "vector bin compares with mem.eql" {
39 const S = struct {39 const S = struct {
40 fn doTheTest() void {40 fn doTheTest() !void {
41 var v: Vector(4, i32) = [4]i32{ 2147483647, -2, 30, 40 };41 var v: Vector(4, i32) = [4]i32{ 2147483647, -2, 30, 40 };
42 var x: Vector(4, i32) = [4]i32{ 1, 2147483647, 30, 4 };42 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 }));43 try 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 }));44 try 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 }));45 try 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 }));46 try 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 }));47 try 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 }));48 try expect(mem.eql(bool, &@as([4]bool, v >= x), &[4]bool{ true, false, true, true }));
49 }49 }
50 };50 };
51 S.doTheTest();51 try S.doTheTest();
52 comptime S.doTheTest();52 comptime try S.doTheTest();
53}53}
5454
55test "vector int operators" {55test "vector int operators" {
56 const S = struct {56 const S = struct {
57 fn doTheTest() void {57 fn doTheTest() !void {
58 var v: Vector(4, i32) = [4]i32{ 10, 20, 30, 40 };58 var v: Vector(4, i32) = [4]i32{ 10, 20, 30, 40 };
59 var x: Vector(4, i32) = [4]i32{ 1, 2, 3, 4 };59 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 }));60 try 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 }));61 try 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 }));62 try 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 }));63 try expect(mem.eql(i32, &@as([4]i32, -v), &[4]i32{ -10, -20, -30, -40 }));
64 }64 }
65 };65 };
66 S.doTheTest();66 try S.doTheTest();
67 comptime S.doTheTest();67 comptime try S.doTheTest();
68}68}
6969
70test "vector float operators" {70test "vector float operators" {
71 const S = struct {71 const S = struct {
72 fn doTheTest() void {72 fn doTheTest() !void {
73 var v: Vector(4, f32) = [4]f32{ 10, 20, 30, 40 };73 var v: Vector(4, f32) = [4]f32{ 10, 20, 30, 40 };
74 var x: Vector(4, f32) = [4]f32{ 1, 2, 3, 4 };74 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 }));75 try 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 }));76 try 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 }));77 try 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 }));78 try expect(mem.eql(f32, &@as([4]f32, -x), &[4]f32{ -1, -2, -3, -4 }));
79 }79 }
80 };80 };
81 S.doTheTest();81 try S.doTheTest();
82 comptime S.doTheTest();82 comptime try S.doTheTest();
83}83}
8484
85test "vector bit operators" {85test "vector bit operators" {
86 const S = struct {86 const S = struct {
87 fn doTheTest() void {87 fn doTheTest() !void {
88 var v: Vector(4, u8) = [4]u8{ 0b10101010, 0b10101010, 0b10101010, 0b10101010 };88 var v: Vector(4, u8) = [4]u8{ 0b10101010, 0b10101010, 0b10101010, 0b10101010 };
89 var x: Vector(4, u8) = [4]u8{ 0b11110000, 0b00001111, 0b10101010, 0b01010101 };89 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 }));90 try 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 }));91 try 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 }));92 try expect(mem.eql(u8, &@as([4]u8, v & x), &[4]u8{ 0b10100000, 0b00001010, 0b10101010, 0b00000000 }));
93 }93 }
94 };94 };
95 S.doTheTest();95 try S.doTheTest();
96 comptime S.doTheTest();96 comptime try S.doTheTest();
97}97}
9898
99test "implicit cast vector to array" {99test "implicit cast vector to array" {
100 const S = struct {100 const S = struct {
101 fn doTheTest() void {101 fn doTheTest() !void {
102 var a: Vector(4, i32) = [_]i32{ 1, 2, 3, 4 };102 var a: Vector(4, i32) = [_]i32{ 1, 2, 3, 4 };
103 var result_array: [4]i32 = a;103 var result_array: [4]i32 = a;
104 result_array = a;104 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 }));
106 }106 }
107 };107 };
108 S.doTheTest();108 try S.doTheTest();
109 comptime S.doTheTest();109 comptime try S.doTheTest();
110}110}
111111
112test "array to vector" {112test "array to vector" {
...@@ -120,141 +120,141 @@ test "vector casts of sizes not divisable by 8" {...@@ -120,141 +120,141 @@ test "vector casts of sizes not divisable by 8" {
120 if (std.Target.current.os.tag == .dragonfly) return error.SkipZigTest;120 if (std.Target.current.os.tag == .dragonfly) return error.SkipZigTest;
121121
122 const S = struct {122 const S = struct {
123 fn doTheTest() void {123 fn doTheTest() !void {
124 {124 {
125 var v: Vector(4, u3) = [4]u3{ 5, 2, 3, 0 };125 var v: Vector(4, u3) = [4]u3{ 5, 2, 3, 0 };
126 var x: [4]u3 = v;126 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)));
128 }128 }
129 {129 {
130 var v: Vector(4, u2) = [4]u2{ 1, 2, 3, 0 };130 var v: Vector(4, u2) = [4]u2{ 1, 2, 3, 0 };
131 var x: [4]u2 = v;131 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)));
133 }133 }
134 {134 {
135 var v: Vector(4, u1) = [4]u1{ 1, 0, 1, 0 };135 var v: Vector(4, u1) = [4]u1{ 1, 0, 1, 0 };
136 var x: [4]u1 = v;136 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)));
138 }138 }
139 {139 {
140 var v: Vector(4, bool) = [4]bool{ false, false, true, false };140 var v: Vector(4, bool) = [4]bool{ false, false, true, false };
141 var x: [4]bool = v;141 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)));
143 }143 }
144 }144 }
145 };145 };
146 S.doTheTest();146 try S.doTheTest();
147 comptime S.doTheTest();147 comptime try S.doTheTest();
148}148}
149149
150test "vector @splat" {150test "vector @splat" {
151 const S = struct {151 const S = struct {
152 fn testForT(comptime N: comptime_int, v: anytype) void {152 fn testForT(comptime N: comptime_int, v: anytype) !void {
153 const T = @TypeOf(v);153 const T = @TypeOf(v);
154 var vec = @splat(N, v);154 var vec = @splat(N, v);
155 expectEqual(Vector(N, T), @TypeOf(vec));155 try expectEqual(Vector(N, T), @TypeOf(vec));
156 var as_array = @as([N]T, vec);156 var as_array = @as([N]T, vec);
157 for (as_array) |elem| expectEqual(v, elem);157 for (as_array) |elem| try expectEqual(v, elem);
158 }158 }
159 fn doTheTest() void {159 fn doTheTest() !void {
160 // Splats with multiple-of-8 bit types that fill a 128bit vector.160 // Splats with multiple-of-8 bit types that fill a 128bit vector.
161 testForT(16, @as(u8, 0xEE));161 try testForT(16, @as(u8, 0xEE));
162 testForT(8, @as(u16, 0xBEEF));162 try testForT(8, @as(u16, 0xBEEF));
163 testForT(4, @as(u32, 0xDEADBEEF));163 try testForT(4, @as(u32, 0xDEADBEEF));
164 testForT(2, @as(u64, 0xCAFEF00DDEADBEEF));164 try testForT(2, @as(u64, 0xCAFEF00DDEADBEEF));
165165
166 testForT(8, @as(f16, 3.1415));166 try testForT(8, @as(f16, 3.1415));
167 testForT(4, @as(f32, 3.1415));167 try testForT(4, @as(f32, 3.1415));
168 testForT(2, @as(f64, 3.1415));168 try testForT(2, @as(f64, 3.1415));
169169
170 // Same but fill more than 128 bits.170 // Same but fill more than 128 bits.
171 testForT(16 * 2, @as(u8, 0xEE));171 try testForT(16 * 2, @as(u8, 0xEE));
172 testForT(8 * 2, @as(u16, 0xBEEF));172 try testForT(8 * 2, @as(u16, 0xBEEF));
173 testForT(4 * 2, @as(u32, 0xDEADBEEF));173 try testForT(4 * 2, @as(u32, 0xDEADBEEF));
174 testForT(2 * 2, @as(u64, 0xCAFEF00DDEADBEEF));174 try testForT(2 * 2, @as(u64, 0xCAFEF00DDEADBEEF));
175175
176 testForT(8 * 2, @as(f16, 3.1415));176 try testForT(8 * 2, @as(f16, 3.1415));
177 testForT(4 * 2, @as(f32, 3.1415));177 try testForT(4 * 2, @as(f32, 3.1415));
178 testForT(2 * 2, @as(f64, 3.1415));178 try testForT(2 * 2, @as(f64, 3.1415));
179 }179 }
180 };180 };
181 S.doTheTest();181 try S.doTheTest();
182 comptime S.doTheTest();182 comptime try S.doTheTest();
183}183}
184184
185test "load vector elements via comptime index" {185test "load vector elements via comptime index" {
186 const S = struct {186 const S = struct {
187 fn doTheTest() void {187 fn doTheTest() !void {
188 var v: Vector(4, i32) = [_]i32{ 1, 2, 3, undefined };188 var v: Vector(4, i32) = [_]i32{ 1, 2, 3, undefined };
189 expect(v[0] == 1);189 try expect(v[0] == 1);
190 expect(v[1] == 2);190 try expect(v[1] == 2);
191 expect(loadv(&v[2]) == 3);191 try expect(loadv(&v[2]) == 3);
192 }192 }
193 fn loadv(ptr: anytype) i32 {193 fn loadv(ptr: anytype) i32 {
194 return ptr.*;194 return ptr.*;
195 }195 }
196 };196 };
197197
198 S.doTheTest();198 try S.doTheTest();
199 comptime S.doTheTest();199 comptime try S.doTheTest();
200}200}
201201
202test "store vector elements via comptime index" {202test "store vector elements via comptime index" {
203 const S = struct {203 const S = struct {
204 fn doTheTest() void {204 fn doTheTest() !void {
205 var v: Vector(4, i32) = [_]i32{ 1, 5, 3, undefined };205 var v: Vector(4, i32) = [_]i32{ 1, 5, 3, undefined };
206206
207 v[2] = 42;207 v[2] = 42;
208 expect(v[1] == 5);208 try expect(v[1] == 5);
209 v[3] = -364;209 v[3] = -364;
210 expect(v[2] == 42);210 try expect(v[2] == 42);
211 expect(-364 == v[3]);211 try expect(-364 == v[3]);
212212
213 storev(&v[0], 100);213 storev(&v[0], 100);
214 expect(v[0] == 100);214 try expect(v[0] == 100);
215 }215 }
216 fn storev(ptr: anytype, x: i32) void {216 fn storev(ptr: anytype, x: i32) void {
217 ptr.* = x;217 ptr.* = x;
218 }218 }
219 };219 };
220220
221 S.doTheTest();221 try S.doTheTest();
222 comptime S.doTheTest();222 comptime try S.doTheTest();
223}223}
224224
225test "load vector elements via runtime index" {225test "load vector elements via runtime index" {
226 const S = struct {226 const S = struct {
227 fn doTheTest() void {227 fn doTheTest() !void {
228 var v: Vector(4, i32) = [_]i32{ 1, 2, 3, undefined };228 var v: Vector(4, i32) = [_]i32{ 1, 2, 3, undefined };
229 var i: u32 = 0;229 var i: u32 = 0;
230 expect(v[i] == 1);230 try expect(v[i] == 1);
231 i += 1;231 i += 1;
232 expect(v[i] == 2);232 try expect(v[i] == 2);
233 i += 1;233 i += 1;
234 expect(v[i] == 3);234 try expect(v[i] == 3);
235 }235 }
236 };236 };
237237
238 S.doTheTest();238 try S.doTheTest();
239 comptime S.doTheTest();239 comptime try S.doTheTest();
240}240}
241241
242test "store vector elements via runtime index" {242test "store vector elements via runtime index" {
243 const S = struct {243 const S = struct {
244 fn doTheTest() void {244 fn doTheTest() !void {
245 var v: Vector(4, i32) = [_]i32{ 1, 5, 3, undefined };245 var v: Vector(4, i32) = [_]i32{ 1, 5, 3, undefined };
246 var i: u32 = 2;246 var i: u32 = 2;
247 v[i] = 1;247 v[i] = 1;
248 expect(v[1] == 5);248 try expect(v[1] == 5);
249 expect(v[2] == 1);249 try expect(v[2] == 1);
250 i += 1;250 i += 1;
251 v[i] = -364;251 v[i] = -364;
252 expect(-364 == v[3]);252 try expect(-364 == v[3]);
253 }253 }
254 };254 };
255255
256 S.doTheTest();256 try S.doTheTest();
257 comptime S.doTheTest();257 comptime try S.doTheTest();
258}258}
259259
260test "initialize vector which is a struct field" {260test "initialize vector which is a struct field" {
...@@ -263,155 +263,155 @@ test "initialize vector which is a struct field" {...@@ -263,155 +263,155 @@ test "initialize vector which is a struct field" {
263 };263 };
264264
265 const S = struct {265 const S = struct {
266 fn doTheTest() void {266 fn doTheTest() !void {
267 var foo = Vec4Obj{267 var foo = Vec4Obj{
268 .data = [_]f32{ 1, 2, 3, 4 },268 .data = [_]f32{ 1, 2, 3, 4 },
269 };269 };
270 }270 }
271 };271 };
272 S.doTheTest();272 try S.doTheTest();
273 comptime S.doTheTest();273 comptime try S.doTheTest();
274}274}
275275
276test "vector comparison operators" {276test "vector comparison operators" {
277 const S = struct {277 const S = struct {
278 fn doTheTest() void {278 fn doTheTest() !void {
279 {279 {
280 const v1: Vector(4, bool) = [_]bool{ true, false, true, false };280 const v1: Vector(4, bool) = [_]bool{ true, false, true, false };
281 const v2: Vector(4, bool) = [_]bool{ false, true, false, true };281 const v2: Vector(4, bool) = [_]bool{ false, true, false, true };
282 expectEqual(@splat(4, true), v1 == v1);282 try expectEqual(@splat(4, true), v1 == v1);
283 expectEqual(@splat(4, false), v1 == v2);283 try expectEqual(@splat(4, false), v1 == v2);
284 expectEqual(@splat(4, true), v1 != v2);284 try expectEqual(@splat(4, true), v1 != v2);
285 expectEqual(@splat(4, false), v2 != v2);285 try expectEqual(@splat(4, false), v2 != v2);
286 }286 }
287 {287 {
288 const v1 = @splat(4, @as(u32, 0xc0ffeeee));288 const v1 = @splat(4, @as(u32, 0xc0ffeeee));
289 const v2: Vector(4, c_uint) = v1;289 const v2: Vector(4, c_uint) = v1;
290 const v3 = @splat(4, @as(u32, 0xdeadbeef));290 const v3 = @splat(4, @as(u32, 0xdeadbeef));
291 expectEqual(@splat(4, true), v1 == v2);291 try expectEqual(@splat(4, true), v1 == v2);
292 expectEqual(@splat(4, false), v1 == v3);292 try expectEqual(@splat(4, false), v1 == v3);
293 expectEqual(@splat(4, true), v1 != v3);293 try expectEqual(@splat(4, true), v1 != v3);
294 expectEqual(@splat(4, false), v1 != v2);294 try expectEqual(@splat(4, false), v1 != v2);
295 }295 }
296 {296 {
297 // Comptime-known LHS/RHS297 // Comptime-known LHS/RHS
298 var v1: @Vector(4, u32) = [_]u32{ 2, 1, 2, 1 };298 var v1: @Vector(4, u32) = [_]u32{ 2, 1, 2, 1 };
299 const v2 = @splat(4, @as(u32, 2));299 const v2 = @splat(4, @as(u32, 2));
300 const v3: @Vector(4, bool) = [_]bool{ true, false, true, false };300 const v3: @Vector(4, bool) = [_]bool{ true, false, true, false };
301 expectEqual(v3, v1 == v2);301 try expectEqual(v3, v1 == v2);
302 expectEqual(v3, v2 == v1);302 try expectEqual(v3, v2 == v1);
303 }303 }
304 }304 }
305 };305 };
306 S.doTheTest();306 try S.doTheTest();
307 comptime S.doTheTest();307 comptime try S.doTheTest();
308}308}
309309
310test "vector division operators" {310test "vector division operators" {
311 const S = struct {311 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 {
313 if (!comptime std.meta.trait.isSignedInt(T)) {313 if (!comptime std.meta.trait.isSignedInt(T)) {
314 const d0 = x / y;314 const d0 = x / y;
315 for (@as([4]T, d0)) |v, i| {315 for (@as([4]T, d0)) |v, i| {
316 expectEqual(x[i] / y[i], v);316 try expectEqual(x[i] / y[i], v);
317 }317 }
318 }318 }
319 const d1 = @divExact(x, y);319 const d1 = @divExact(x, y);
320 for (@as([4]T, d1)) |v, i| {320 for (@as([4]T, d1)) |v, i| {
321 expectEqual(@divExact(x[i], y[i]), v);321 try expectEqual(@divExact(x[i], y[i]), v);
322 }322 }
323 const d2 = @divFloor(x, y);323 const d2 = @divFloor(x, y);
324 for (@as([4]T, d2)) |v, i| {324 for (@as([4]T, d2)) |v, i| {
325 expectEqual(@divFloor(x[i], y[i]), v);325 try expectEqual(@divFloor(x[i], y[i]), v);
326 }326 }
327 const d3 = @divTrunc(x, y);327 const d3 = @divTrunc(x, y);
328 for (@as([4]T, d3)) |v, i| {328 for (@as([4]T, d3)) |v, i| {
329 expectEqual(@divTrunc(x[i], y[i]), v);329 try expectEqual(@divTrunc(x[i], y[i]), v);
330 }330 }
331 }331 }
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 {
334 if ((!comptime std.meta.trait.isSignedInt(T)) and @typeInfo(T) != .Float) {334 if ((!comptime std.meta.trait.isSignedInt(T)) and @typeInfo(T) != .Float) {
335 const r0 = x % y;335 const r0 = x % y;
336 for (@as([4]T, r0)) |v, i| {336 for (@as([4]T, r0)) |v, i| {
337 expectEqual(x[i] % y[i], v);337 try expectEqual(x[i] % y[i], v);
338 }338 }
339 }339 }
340 const r1 = @mod(x, y);340 const r1 = @mod(x, y);
341 for (@as([4]T, r1)) |v, i| {341 for (@as([4]T, r1)) |v, i| {
342 expectEqual(@mod(x[i], y[i]), v);342 try expectEqual(@mod(x[i], y[i]), v);
343 }343 }
344 const r2 = @rem(x, y);344 const r2 = @rem(x, y);
345 for (@as([4]T, r2)) |v, i| {345 for (@as([4]T, r2)) |v, i| {
346 expectEqual(@rem(x[i], y[i]), v);346 try expectEqual(@rem(x[i], y[i]), v);
347 }347 }
348 }348 }
349349
350 fn doTheTest() void {350 fn doTheTest() !void {
351 // https://github.com/ziglang/zig/issues/4952351 // https://github.com/ziglang/zig/issues/4952
352 if (builtin.target.os.tag != .windows) {352 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 });
354 }354 }
355355
356 doTheTestDiv(f32, [4]f32{ 4.0, -4.0, 4.0, -4.0 }, [4]f32{ 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 doTheTestDiv(f64, [4]f64{ 4.0, -4.0, 4.0, -4.0 }, [4]f64{ 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
359 // https://github.com/ziglang/zig/issues/4952359 // https://github.com/ziglang/zig/issues/4952
360 if (builtin.target.os.tag != .windows) {360 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 });
362 }362 }
363 doTheTestMod(f32, [4]f32{ 4.0, -4.0, 4.0, -4.0 }, [4]f32{ 1.0, 2.0, 0.5, 3.0 });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 doTheTestMod(f64, [4]f64{ 4.0, -4.0, 4.0, -4.0 }, [4]f64{ 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 });
365365
366 doTheTestDiv(i8, [4]i8{ 4, -4, 4, -4 }, [4]i8{ 1, 2, -1, -2 });366 try 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 });367 try 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 });368 try 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 });369 try doTheTestDiv(i64, [4]i64{ 4, -4, 4, -4 }, [4]i64{ 1, 2, -1, -2 });
370370
371 doTheTestMod(i8, [4]i8{ 4, -4, 4, -4 }, [4]i8{ 1, 2, 4, 8 });371 try 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 });372 try 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 });373 try 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 });374 try doTheTestMod(i64, [4]i64{ 4, -4, 4, -4 }, [4]i64{ 1, 2, 4, 8 });
375375
376 doTheTestDiv(u8, [4]u8{ 1, 2, 4, 8 }, [4]u8{ 1, 1, 2, 4 });376 try 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 });377 try 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 });378 try 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 });379 try doTheTestDiv(u64, [4]u64{ 1, 2, 4, 8 }, [4]u64{ 1, 1, 2, 4 });
380380
381 doTheTestMod(u8, [4]u8{ 1, 2, 4, 8 }, [4]u8{ 1, 1, 2, 4 });381 try 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 });382 try 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 });383 try 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 });384 try doTheTestMod(u64, [4]u64{ 1, 2, 4, 8 }, [4]u64{ 1, 1, 2, 4 });
385 }385 }
386 };386 };
387387
388 S.doTheTest();388 try S.doTheTest();
389 comptime S.doTheTest();389 comptime try S.doTheTest();
390}390}
391391
392test "vector bitwise not operator" {392test "vector bitwise not operator" {
393 const S = struct {393 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 {
395 var y = ~x;395 var y = ~x;
396 for (@as([4]T, y)) |v, i| {396 for (@as([4]T, y)) |v, i| {
397 expectEqual(~x[i], v);397 try expectEqual(~x[i], v);
398 }398 }
399 }399 }
400 fn doTheTest() void {400 fn doTheTest() !void {
401 doTheTestNot(u8, [_]u8{ 0, 2, 4, 255 });401 try doTheTestNot(u8, [_]u8{ 0, 2, 4, 255 });
402 doTheTestNot(u16, [_]u16{ 0, 2, 4, 255 });402 try doTheTestNot(u16, [_]u16{ 0, 2, 4, 255 });
403 doTheTestNot(u32, [_]u32{ 0, 2, 4, 255 });403 try doTheTestNot(u32, [_]u32{ 0, 2, 4, 255 });
404 doTheTestNot(u64, [_]u64{ 0, 2, 4, 255 });404 try doTheTestNot(u64, [_]u64{ 0, 2, 4, 255 });
405405
406 doTheTestNot(u8, [_]u8{ 0, 2, 4, 255 });406 try doTheTestNot(u8, [_]u8{ 0, 2, 4, 255 });
407 doTheTestNot(u16, [_]u16{ 0, 2, 4, 255 });407 try doTheTestNot(u16, [_]u16{ 0, 2, 4, 255 });
408 doTheTestNot(u32, [_]u32{ 0, 2, 4, 255 });408 try doTheTestNot(u32, [_]u32{ 0, 2, 4, 255 });
409 doTheTestNot(u64, [_]u64{ 0, 2, 4, 255 });409 try doTheTestNot(u64, [_]u64{ 0, 2, 4, 255 });
410 }410 }
411 };411 };
412412
413 S.doTheTest();413 try S.doTheTest();
414 comptime S.doTheTest();414 comptime try S.doTheTest();
415}415}
416416
417test "vector shift operators" {417test "vector shift operators" {
...@@ -419,7 +419,7 @@ test "vector shift operators" {...@@ -419,7 +419,7 @@ test "vector shift operators" {
419 if (builtin.target.os.tag == .wasi) return error.SkipZigTest;419 if (builtin.target.os.tag == .wasi) return error.SkipZigTest;
420420
421 const S = struct {421 const S = struct {
422 fn doTheTestShift(x: anytype, y: anytype) void {422 fn doTheTestShift(x: anytype, y: anytype) !void {
423 const N = @typeInfo(@TypeOf(x)).Array.len;423 const N = @typeInfo(@TypeOf(x)).Array.len;
424 const TX = @typeInfo(@TypeOf(x)).Array.child;424 const TX = @typeInfo(@TypeOf(x)).Array.child;
425 const TY = @typeInfo(@TypeOf(y)).Array.child;425 const TY = @typeInfo(@TypeOf(y)).Array.child;
...@@ -429,14 +429,14 @@ test "vector shift operators" {...@@ -429,14 +429,14 @@ test "vector shift operators" {
429429
430 var z0 = xv >> yv;430 var z0 = xv >> yv;
431 for (@as([N]TX, z0)) |v, i| {431 for (@as([N]TX, z0)) |v, i| {
432 expectEqual(x[i] >> y[i], v);432 try expectEqual(x[i] >> y[i], v);
433 }433 }
434 var z1 = xv << yv;434 var z1 = xv << yv;
435 for (@as([N]TX, z1)) |v, i| {435 for (@as([N]TX, z1)) |v, i| {
436 expectEqual(x[i] << y[i], v);436 try expectEqual(x[i] << y[i], v);
437 }437 }
438 }438 }
439 fn doTheTestShiftExact(x: anytype, y: anytype, dir: enum { Left, Right }) void {439 fn doTheTestShiftExact(x: anytype, y: anytype, dir: enum { Left, Right }) !void {
440 const N = @typeInfo(@TypeOf(x)).Array.len;440 const N = @typeInfo(@TypeOf(x)).Array.len;
441 const TX = @typeInfo(@TypeOf(x)).Array.child;441 const TX = @typeInfo(@TypeOf(x)).Array.child;
442 const TY = @typeInfo(@TypeOf(y)).Array.child;442 const TY = @typeInfo(@TypeOf(y)).Array.child;
...@@ -447,33 +447,33 @@ test "vector shift operators" {...@@ -447,33 +447,33 @@ test "vector shift operators" {
447 var z = if (dir == .Left) @shlExact(xv, yv) else @shrExact(xv, yv);447 var z = if (dir == .Left) @shlExact(xv, yv) else @shrExact(xv, yv);
448 for (@as([N]TX, z)) |v, i| {448 for (@as([N]TX, z)) |v, i| {
449 const check = if (dir == .Left) x[i] << y[i] else x[i] >> y[i];449 const check = if (dir == .Left) x[i] << y[i] else x[i] >> y[i];
450 expectEqual(check, v);450 try expectEqual(check, v);
451 }451 }
452 }452 }
453 fn doTheTest() void {453 fn doTheTest() !void {
454 doTheTestShift([_]u8{ 0, 2, 4, math.maxInt(u8) }, [_]u3{ 2, 0, 2, 7 });454 try 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 });455 try 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 });456 try 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 });457 try doTheTestShift([_]u32{ 0, 2, 4, math.maxInt(u32) }, [_]u5{ 2, 0, 2, 31 });
458 doTheTestShift([_]u64{ 0xfe, math.maxInt(u64) }, [_]u6{ 0, 63 });458 try doTheTestShift([_]u64{ 0xfe, math.maxInt(u64) }, [_]u6{ 0, 63 });
459459
460 doTheTestShift([_]i8{ 0, 2, 4, math.maxInt(i8) }, [_]u3{ 2, 0, 2, 7 });460 try 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 });461 try 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 });462 try 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 });463 try doTheTestShift([_]i32{ 0, 2, 4, math.maxInt(i32) }, [_]u5{ 2, 0, 2, 7 });
464 doTheTestShift([_]i64{ 0xfe, math.maxInt(i64) }, [_]u6{ 0, 63 });464 try doTheTestShift([_]i64{ 0xfe, math.maxInt(i64) }, [_]u6{ 0, 63 });
465465
466 doTheTestShiftExact([_]u8{ 0, 1, 1 << 7, math.maxInt(u8) ^ 1 }, [_]u3{ 4, 0, 7, 1 }, .Right);466 try 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);467 try 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);468 try 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);469 try 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);470 try doTheTestShiftExact([_]u64{ 1 << 63, 1 }, [_]u6{ 63, 0 }, .Right);
471471
472 doTheTestShiftExact([_]u8{ 0, 1, 1, math.maxInt(u8) ^ (1 << 7) }, [_]u3{ 4, 0, 7, 1 }, .Left);472 try 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);473 try 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);474 try 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);475 try 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);476 try doTheTestShiftExact([_]u64{ 1 << 63, 1 }, [_]u6{ 0, 63 }, .Left);
477 }477 }
478 };478 };
479479
...@@ -500,19 +500,19 @@ test "vector shift operators" {...@@ -500,19 +500,19 @@ test "vector shift operators" {
500 else => {},500 else => {},
501 }501 }
502502
503 S.doTheTest();503 try S.doTheTest();
504 comptime S.doTheTest();504 comptime try S.doTheTest();
505}505}
506506
507test "vector reduce operation" {507test "vector reduce operation" {
508 const S = struct {508 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 {
510 const N = @typeInfo(@TypeOf(x)).Array.len;510 const N = @typeInfo(@TypeOf(x)).Array.len;
511 const TX = @typeInfo(@TypeOf(x)).Array.child;511 const TX = @typeInfo(@TypeOf(x)).Array.child;
512512
513 var r = @reduce(op, @as(Vector(N, TX), x));513 var r = @reduce(op, @as(Vector(N, TX), x));
514 switch (@typeInfo(TX)) {514 switch (@typeInfo(TX)) {
515 .Int, .Bool => expectEqual(expected, r),515 .Int, .Bool => try expectEqual(expected, r),
516 .Float => {516 .Float => {
517 const expected_nan = math.isNan(expected);517 const expected_nan = math.isNan(expected);
518 const got_nan = math.isNan(r);518 const got_nan = math.isNan(r);
...@@ -521,120 +521,120 @@ test "vector reduce operation" {...@@ -521,120 +521,120 @@ test "vector reduce operation" {
521 // Do this check explicitly as two NaN values are never521 // Do this check explicitly as two NaN values are never
522 // equal.522 // equal.
523 } else {523 } else {
524 expectApproxEqRel(expected, r, math.sqrt(math.epsilon(TX)));524 try expectApproxEqRel(expected, r, math.sqrt(math.epsilon(TX)));
525 }525 }
526 },526 },
527 else => unreachable,527 else => unreachable,
528 }528 }
529 }529 }
530 fn doTheTest() void {530 fn doTheTest() !void {
531 doTheTestReduce(.Add, [4]i16{ -9, -99, -999, -9999 }, @as(i32, -11106));531 try doTheTestReduce(.Add, [4]i16{ -9, -99, -999, -9999 }, @as(i32, -11106));
532 doTheTestReduce(.Add, [4]u16{ 9, 99, 999, 9999 }, @as(u32, 11106));532 try doTheTestReduce(.Add, [4]u16{ 9, 99, 999, 9999 }, @as(u32, 11106));
533 doTheTestReduce(.Add, [4]i32{ -9, -99, -999, -9999 }, @as(i32, -11106));533 try doTheTestReduce(.Add, [4]i32{ -9, -99, -999, -9999 }, @as(i32, -11106));
534 doTheTestReduce(.Add, [4]u32{ 9, 99, 999, 9999 }, @as(u32, 11106));534 try doTheTestReduce(.Add, [4]u32{ 9, 99, 999, 9999 }, @as(u32, 11106));
535 doTheTestReduce(.Add, [4]i64{ -9, -99, -999, -9999 }, @as(i64, -11106));535 try doTheTestReduce(.Add, [4]i64{ -9, -99, -999, -9999 }, @as(i64, -11106));
536 doTheTestReduce(.Add, [4]u64{ 9, 99, 999, 9999 }, @as(u64, 11106));536 try doTheTestReduce(.Add, [4]u64{ 9, 99, 999, 9999 }, @as(u64, 11106));
537 doTheTestReduce(.Add, [4]i128{ -9, -99, -999, -9999 }, @as(i128, -11106));537 try doTheTestReduce(.Add, [4]i128{ -9, -99, -999, -9999 }, @as(i128, -11106));
538 doTheTestReduce(.Add, [4]u128{ 9, 99, 999, 9999 }, @as(u128, 11106));538 try 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));539 try 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));540 try 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));541 try doTheTestReduce(.Add, [4]f64{ -1.9, 5.1, -60.3, 100.0 }, @as(f64, 42.9));
542542
543 doTheTestReduce(.And, [4]bool{ true, false, true, true }, @as(bool, false));543 try doTheTestReduce(.And, [4]bool{ true, false, true, true }, @as(bool, false));
544 doTheTestReduce(.And, [4]u1{ 1, 0, 1, 1 }, @as(u1, 0));544 try doTheTestReduce(.And, [4]u1{ 1, 0, 1, 1 }, @as(u1, 0));
545 doTheTestReduce(.And, [4]u16{ 0xffff, 0xff55, 0xaaff, 0x1010 }, @as(u16, 0x10));545 try doTheTestReduce(.And, [4]u16{ 0xffff, 0xff55, 0xaaff, 0x1010 }, @as(u16, 0x10));
546 doTheTestReduce(.And, [4]u32{ 0xffffffff, 0xffff5555, 0xaaaaffff, 0x10101010 }, @as(u32, 0x1010));546 try doTheTestReduce(.And, [4]u32{ 0xffffffff, 0xffff5555, 0xaaaaffff, 0x10101010 }, @as(u32, 0x1010));
547 doTheTestReduce(.And, [4]u64{ 0xffffffff, 0xffff5555, 0xaaaaffff, 0x10101010 }, @as(u64, 0x1010));547 try doTheTestReduce(.And, [4]u64{ 0xffffffff, 0xffff5555, 0xaaaaffff, 0x10101010 }, @as(u64, 0x1010));
548548
549 doTheTestReduce(.Min, [4]i16{ -1, 2, 3, 4 }, @as(i16, -1));549 try doTheTestReduce(.Min, [4]i16{ -1, 2, 3, 4 }, @as(i16, -1));
550 doTheTestReduce(.Min, [4]u16{ 1, 2, 3, 4 }, @as(u16, 1));550 try doTheTestReduce(.Min, [4]u16{ 1, 2, 3, 4 }, @as(u16, 1));
551 doTheTestReduce(.Min, [4]i32{ 1234567, -386, 0, 3 }, @as(i32, -386));551 try doTheTestReduce(.Min, [4]i32{ 1234567, -386, 0, 3 }, @as(i32, -386));
552 doTheTestReduce(.Min, [4]u32{ 99, 9999, 9, 99999 }, @as(u32, 9));552 try doTheTestReduce(.Min, [4]u32{ 99, 9999, 9, 99999 }, @as(u32, 9));
553553
554 // LLVM 11 ERROR: Cannot select type554 // LLVM 11 ERROR: Cannot select type
555 // https://github.com/ziglang/zig/issues/7138555 // https://github.com/ziglang/zig/issues/7138
556 if (builtin.target.cpu.arch != .aarch64) {556 if (builtin.target.cpu.arch != .aarch64) {
557 doTheTestReduce(.Min, [4]i64{ 1234567, -386, 0, 3 }, @as(i64, -386));557 try doTheTestReduce(.Min, [4]i64{ 1234567, -386, 0, 3 }, @as(i64, -386));
558 doTheTestReduce(.Min, [4]u64{ 99, 9999, 9, 99999 }, @as(u64, 9));558 try doTheTestReduce(.Min, [4]u64{ 99, 9999, 9, 99999 }, @as(u64, 9));
559 }559 }
560560
561 doTheTestReduce(.Min, [4]i128{ 1234567, -386, 0, 3 }, @as(i128, -386));561 try doTheTestReduce(.Min, [4]i128{ 1234567, -386, 0, 3 }, @as(i128, -386));
562 doTheTestReduce(.Min, [4]u128{ 99, 9999, 9, 99999 }, @as(u128, 9));562 try 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));563 try 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));564 try 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));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));567 try doTheTestReduce(.Max, [4]i16{ -1, 2, 3, 4 }, @as(i16, 4));
568 doTheTestReduce(.Max, [4]u16{ 1, 2, 3, 4 }, @as(u16, 4));568 try doTheTestReduce(.Max, [4]u16{ 1, 2, 3, 4 }, @as(u16, 4));
569 doTheTestReduce(.Max, [4]i32{ 1234567, -386, 0, 3 }, @as(i32, 1234567));569 try doTheTestReduce(.Max, [4]i32{ 1234567, -386, 0, 3 }, @as(i32, 1234567));
570 doTheTestReduce(.Max, [4]u32{ 99, 9999, 9, 99999 }, @as(u32, 99999));570 try doTheTestReduce(.Max, [4]u32{ 99, 9999, 9, 99999 }, @as(u32, 99999));
571571
572 // LLVM 11 ERROR: Cannot select type572 // LLVM 11 ERROR: Cannot select type
573 // https://github.com/ziglang/zig/issues/7138573 // https://github.com/ziglang/zig/issues/7138
574 if (builtin.target.cpu.arch != .aarch64) {574 if (builtin.target.cpu.arch != .aarch64) {
575 doTheTestReduce(.Max, [4]i64{ 1234567, -386, 0, 3 }, @as(i64, 1234567));575 try doTheTestReduce(.Max, [4]i64{ 1234567, -386, 0, 3 }, @as(i64, 1234567));
576 doTheTestReduce(.Max, [4]u64{ 99, 9999, 9, 99999 }, @as(u64, 99999));576 try doTheTestReduce(.Max, [4]u64{ 99, 9999, 9, 99999 }, @as(u64, 99999));
577 }577 }
578578
579 doTheTestReduce(.Max, [4]i128{ 1234567, -386, 0, 3 }, @as(i128, 1234567));579 try doTheTestReduce(.Max, [4]i128{ 1234567, -386, 0, 3 }, @as(i128, 1234567));
580 doTheTestReduce(.Max, [4]u128{ 99, 9999, 9, 99999 }, @as(u128, 99999));580 try 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));581 try 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));582 try 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));583 try doTheTestReduce(.Max, [4]f64{ -10.3, 10.0e9, 13.0, -100.0 }, @as(f64, 10.0e9));
584584
585 doTheTestReduce(.Mul, [4]i16{ -1, 2, 3, 4 }, @as(i16, -24));585 try doTheTestReduce(.Mul, [4]i16{ -1, 2, 3, 4 }, @as(i16, -24));
586 doTheTestReduce(.Mul, [4]u16{ 1, 2, 3, 4 }, @as(u16, 24));586 try doTheTestReduce(.Mul, [4]u16{ 1, 2, 3, 4 }, @as(u16, 24));
587 doTheTestReduce(.Mul, [4]i32{ -9, -99, -999, 999 }, @as(i32, -889218891));587 try doTheTestReduce(.Mul, [4]i32{ -9, -99, -999, 999 }, @as(i32, -889218891));
588 doTheTestReduce(.Mul, [4]u32{ 1, 2, 3, 4 }, @as(u32, 24));588 try doTheTestReduce(.Mul, [4]u32{ 1, 2, 3, 4 }, @as(u32, 24));
589 doTheTestReduce(.Mul, [4]i64{ 9, 99, 999, 9999 }, @as(i64, 8900199891));589 try doTheTestReduce(.Mul, [4]i64{ 9, 99, 999, 9999 }, @as(i64, 8900199891));
590 doTheTestReduce(.Mul, [4]u64{ 9, 99, 999, 9999 }, @as(u64, 8900199891));590 try doTheTestReduce(.Mul, [4]u64{ 9, 99, 999, 9999 }, @as(u64, 8900199891));
591 doTheTestReduce(.Mul, [4]i128{ -9, -99, -999, 9999 }, @as(i128, -8900199891));591 try doTheTestReduce(.Mul, [4]i128{ -9, -99, -999, 9999 }, @as(i128, -8900199891));
592 doTheTestReduce(.Mul, [4]u128{ 9, 99, 999, 9999 }, @as(u128, 8900199891));592 try 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));593 try 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));594 try 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));595 try doTheTestReduce(.Mul, [4]f64{ -1.9, 5.1, -60.3, 100.0 }, @as(f64, 58430.7));
596596
597 doTheTestReduce(.Or, [4]bool{ false, true, false, false }, @as(bool, true));597 try doTheTestReduce(.Or, [4]bool{ false, true, false, false }, @as(bool, true));
598 doTheTestReduce(.Or, [4]u1{ 0, 1, 0, 0 }, @as(u1, 1));598 try doTheTestReduce(.Or, [4]u1{ 0, 1, 0, 0 }, @as(u1, 1));
599 doTheTestReduce(.Or, [4]u16{ 0xff00, 0xff00, 0xf0, 0xf }, ~@as(u16, 0));599 try doTheTestReduce(.Or, [4]u16{ 0xff00, 0xff00, 0xf0, 0xf }, ~@as(u16, 0));
600 doTheTestReduce(.Or, [4]u32{ 0xffff0000, 0xff00, 0xf0, 0xf }, ~@as(u32, 0));600 try doTheTestReduce(.Or, [4]u32{ 0xffff0000, 0xff00, 0xf0, 0xf }, ~@as(u32, 0));
601 doTheTestReduce(.Or, [4]u64{ 0xffff0000, 0xff00, 0xf0, 0xf }, @as(u64, 0xffffffff));601 try doTheTestReduce(.Or, [4]u64{ 0xffff0000, 0xff00, 0xf0, 0xf }, @as(u64, 0xffffffff));
602 doTheTestReduce(.Or, [4]u128{ 0xffff0000, 0xff00, 0xf0, 0xf }, @as(u128, 0xffffffff));602 try doTheTestReduce(.Or, [4]u128{ 0xffff0000, 0xff00, 0xf0, 0xf }, @as(u128, 0xffffffff));
603603
604 doTheTestReduce(.Xor, [4]bool{ true, true, true, false }, @as(bool, true));604 try doTheTestReduce(.Xor, [4]bool{ true, true, true, false }, @as(bool, true));
605 doTheTestReduce(.Xor, [4]u1{ 1, 1, 1, 0 }, @as(u1, 1));605 try doTheTestReduce(.Xor, [4]u1{ 1, 1, 1, 0 }, @as(u1, 1));
606 doTheTestReduce(.Xor, [4]u16{ 0x0000, 0x3333, 0x8888, 0x4444 }, ~@as(u16, 0));606 try doTheTestReduce(.Xor, [4]u16{ 0x0000, 0x3333, 0x8888, 0x4444 }, ~@as(u16, 0));
607 doTheTestReduce(.Xor, [4]u32{ 0x00000000, 0x33333333, 0x88888888, 0x44444444 }, ~@as(u32, 0));607 try doTheTestReduce(.Xor, [4]u32{ 0x00000000, 0x33333333, 0x88888888, 0x44444444 }, ~@as(u32, 0));
608 doTheTestReduce(.Xor, [4]u64{ 0x00000000, 0x33333333, 0x88888888, 0x44444444 }, @as(u64, 0xffffffff));608 try doTheTestReduce(.Xor, [4]u64{ 0x00000000, 0x33333333, 0x88888888, 0x44444444 }, @as(u64, 0xffffffff));
609 doTheTestReduce(.Xor, [4]u128{ 0x00000000, 0x33333333, 0x88888888, 0x44444444 }, @as(u128, 0xffffffff));609 try doTheTestReduce(.Xor, [4]u128{ 0x00000000, 0x33333333, 0x88888888, 0x44444444 }, @as(u128, 0xffffffff));
610610
611 // Test the reduction on vectors containing NaNs.611 // Test the reduction on vectors containing NaNs.
612 const f16_nan = math.nan(f16);612 const f16_nan = math.nan(f16);
613 const f32_nan = math.nan(f32);613 const f32_nan = math.nan(f32);
614 const f64_nan = math.nan(f64);614 const f64_nan = math.nan(f64);
615615
616 doTheTestReduce(.Add, [4]f16{ -1.9, 5.1, f16_nan, 100.0 }, f16_nan);616 try 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);617 try 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);618 try doTheTestReduce(.Add, [4]f64{ -1.9, 5.1, f64_nan, 100.0 }, f64_nan);
619619
620 // LLVM 11 ERROR: Cannot select type620 // LLVM 11 ERROR: Cannot select type
621 // https://github.com/ziglang/zig/issues/7138621 // https://github.com/ziglang/zig/issues/7138
622 if (false) {622 if (false) {
623 doTheTestReduce(.Min, [4]f16{ -1.9, 5.1, f16_nan, 100.0 }, f16_nan);623 try 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);624 try 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);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);627 try 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);628 try 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);629 try doTheTestReduce(.Max, [4]f64{ -1.9, 5.1, f64_nan, 100.0 }, f64_nan);
630 }630 }
631631
632 doTheTestReduce(.Mul, [4]f16{ -1.9, 5.1, f16_nan, 100.0 }, f16_nan);632 try 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);633 try 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);634 try doTheTestReduce(.Mul, [4]f64{ -1.9, 5.1, f64_nan, 100.0 }, f64_nan);
635 }635 }
636 };636 };
637637
638 S.doTheTest();638 try S.doTheTest();
639 comptime S.doTheTest();639 comptime try S.doTheTest();
640}640}
test/behavior/void.zig+3-3
...@@ -13,14 +13,14 @@ test "compare void with void compile time known" {...@@ -13,14 +13,14 @@ test "compare void with void compile time known" {
13 .b = 1,13 .b = 1,
14 .c = {},14 .c = {},
15 };15 };
16 expect(foo.a == {});16 try expect(foo.a == {});
17 }17 }
18}18}
1919
20test "iterate over a void slice" {20test "iterate over a void slice" {
21 var j: usize = 0;21 var j: usize = 0;
22 for (times(10)) |_, i| {22 for (times(10)) |_, i| {
23 expect(i == j);23 try expect(i == j);
24 j += 1;24 j += 1;
25 }25 }
26}26}
...@@ -31,7 +31,7 @@ fn times(n: usize) []const void {...@@ -31,7 +31,7 @@ fn times(n: usize) []const void {
3131
32test "void optional" {32test "void optional" {
33 var x: ?void = {};33 var x: ?void = {};
34 expect(x != null);34 try expect(x != null);
35}35}
3636
37test "void array as a local variable initializer" {37test "void array as a local variable initializer" {
test/behavior/wasm.zig+2-2
...@@ -3,6 +3,6 @@ const expect = std.testing.expect;...@@ -3,6 +3,6 @@ const expect = std.testing.expect;
33
4test "memory size and grow" {4test "memory size and grow" {
5 var prev = @wasmMemorySize(0);5 var prev = @wasmMemorySize(0);
6 expect(prev == @wasmMemoryGrow(0, 1));6 try expect(prev == @wasmMemoryGrow(0, 1));
7 expect(prev + 1 == @wasmMemorySize(0));7 try expect(prev + 1 == @wasmMemorySize(0));
8}8}
test/behavior/while.zig+45-51
...@@ -6,8 +6,8 @@ test "while loop" {...@@ -6,8 +6,8 @@ test "while loop" {
6 while (i < 4) {6 while (i < 4) {
7 i += 1;7 i += 1;
8 }8 }
9 expect(i == 4);9 try expect(i == 4);
10 expect(whileLoop1() == 1);10 try expect(whileLoop1() == 1);
11}11}
12fn whileLoop1() i32 {12fn whileLoop1() i32 {
13 return whileLoop2();13 return whileLoop2();
...@@ -19,7 +19,7 @@ fn whileLoop2() i32 {...@@ -19,7 +19,7 @@ fn whileLoop2() i32 {
19}19}
2020
21test "static eval while" {21test "static eval while" {
22 expect(static_eval_while_number == 1);22 try expect(static_eval_while_number == 1);
23}23}
24const static_eval_while_number = staticWhileLoop1();24const static_eval_while_number = staticWhileLoop1();
25fn staticWhileLoop1() i32 {25fn staticWhileLoop1() i32 {
...@@ -32,11 +32,11 @@ fn staticWhileLoop2() i32 {...@@ -32,11 +32,11 @@ fn staticWhileLoop2() i32 {
32}32}
3333
34test "continue and break" {34test "continue and break" {
35 runContinueAndBreakTest();35 try runContinueAndBreakTest();
36 expect(continue_and_break_counter == 8);36 try expect(continue_and_break_counter == 8);
37}37}
38var continue_and_break_counter: i32 = 0;38var continue_and_break_counter: i32 = 0;
39fn runContinueAndBreakTest() void {39fn runContinueAndBreakTest() !void {
40 var i: i32 = 0;40 var i: i32 = 0;
41 while (true) {41 while (true) {
42 continue_and_break_counter += 2;42 continue_and_break_counter += 2;
...@@ -46,7 +46,7 @@ fn runContinueAndBreakTest() void {...@@ -46,7 +46,7 @@ fn runContinueAndBreakTest() void {
46 }46 }
47 break;47 break;
48 }48 }
49 expect(i == 4);49 try expect(i == 4);
50}50}
5151
52test "return with implicit cast from while loop" {52test "return with implicit cast from while loop" {
...@@ -67,7 +67,7 @@ test "while with continue expression" {...@@ -67,7 +67,7 @@ test "while with continue expression" {
67 sum += i;67 sum += i;
68 }68 }
69 }69 }
70 expect(sum == 40);70 try expect(sum == 40);
71}71}
7272
73test "while with else" {73test "while with else" {
...@@ -79,8 +79,8 @@ test "while with else" {...@@ -79,8 +79,8 @@ test "while with else" {
79 } else {79 } else {
80 got_else += 1;80 got_else += 1;
81 }81 }
82 expect(sum == 10);82 try expect(sum == 10);
83 expect(got_else == 1);83 try expect(got_else == 1);
84}84}
8585
86test "while with optional as condition" {86test "while with optional as condition" {
...@@ -89,7 +89,7 @@ test "while with optional as condition" {...@@ -89,7 +89,7 @@ test "while with optional as condition" {
89 while (getNumberOrNull()) |value| {89 while (getNumberOrNull()) |value| {
90 sum += value;90 sum += value;
91 }91 }
92 expect(sum == 45);92 try expect(sum == 45);
93}93}
9494
95test "while with optional as condition with else" {95test "while with optional as condition with else" {
...@@ -98,12 +98,12 @@ test "while with optional as condition with else" {...@@ -98,12 +98,12 @@ test "while with optional as condition with else" {
98 var got_else: i32 = 0;98 var got_else: i32 = 0;
99 while (getNumberOrNull()) |value| {99 while (getNumberOrNull()) |value| {
100 sum += value;100 sum += value;
101 expect(got_else == 0);101 try expect(got_else == 0);
102 } else {102 } else {
103 got_else += 1;103 got_else += 1;
104 }104 }
105 expect(sum == 45);105 try expect(sum == 45);
106 expect(got_else == 1);106 try expect(got_else == 1);
107}107}
108108
109test "while with error union condition" {109test "while with error union condition" {
...@@ -113,11 +113,11 @@ test "while with error union condition" {...@@ -113,11 +113,11 @@ test "while with error union condition" {
113 while (getNumberOrErr()) |value| {113 while (getNumberOrErr()) |value| {
114 sum += value;114 sum += value;
115 } else |err| {115 } else |err| {
116 expect(err == error.OutOfNumbers);116 try expect(err == error.OutOfNumbers);
117 got_else += 1;117 got_else += 1;
118 }118 }
119 expect(sum == 45);119 try expect(sum == 45);
120 expect(got_else == 1);120 try expect(got_else == 1);
121}121}
122122
123var numbers_left: i32 = undefined;123var numbers_left: i32 = undefined;
...@@ -137,49 +137,43 @@ fn getNumberOrNull() ?i32 {...@@ -137,49 +137,43 @@ fn getNumberOrNull() ?i32 {
137test "while on optional with else result follow else prong" {137test "while on optional with else result follow else prong" {
138 const result = while (returnNull()) |value| {138 const result = while (returnNull()) |value| {
139 break value;139 break value;
140 } else140 } else @as(i32, 2);
141 @as(i32, 2);141 try expect(result == 2);
142 expect(result == 2);
143}142}
144143
145test "while on optional with else result follow break prong" {144test "while on optional with else result follow break prong" {
146 const result = while (returnOptional(10)) |value| {145 const result = while (returnOptional(10)) |value| {
147 break value;146 break value;
148 } else147 } else @as(i32, 2);
149 @as(i32, 2);148 try expect(result == 10);
150 expect(result == 10);
151}149}
152150
153test "while on error union with else result follow else prong" {151test "while on error union with else result follow else prong" {
154 const result = while (returnError()) |value| {152 const result = while (returnError()) |value| {
155 break value;153 break value;
156 } else |err|154 } else |err| @as(i32, 2);
157 @as(i32, 2);155 try expect(result == 2);
158 expect(result == 2);
159}156}
160157
161test "while on error union with else result follow break prong" {158test "while on error union with else result follow break prong" {
162 const result = while (returnSuccess(10)) |value| {159 const result = while (returnSuccess(10)) |value| {
163 break value;160 break value;
164 } else |err|161 } else |err| @as(i32, 2);
165 @as(i32, 2);162 try expect(result == 10);
166 expect(result == 10);
167}163}
168164
169test "while on bool with else result follow else prong" {165test "while on bool with else result follow else prong" {
170 const result = while (returnFalse()) {166 const result = while (returnFalse()) {
171 break @as(i32, 10);167 break @as(i32, 10);
172 } else168 } else @as(i32, 2);
173 @as(i32, 2);169 try expect(result == 2);
174 expect(result == 2);
175}170}
176171
177test "while on bool with else result follow break prong" {172test "while on bool with else result follow break prong" {
178 const result = while (returnTrue()) {173 const result = while (returnTrue()) {
179 break @as(i32, 10);174 break @as(i32, 10);
180 } else175 } else @as(i32, 2);
181 @as(i32, 2);176 try expect(result == 10);
182 expect(result == 10);
183}177}
184178
185test "break from outer while loop" {179test "break from outer while loop" {
...@@ -230,60 +224,60 @@ fn returnTrue() bool {...@@ -230,60 +224,60 @@ fn returnTrue() bool {
230224
231test "while bool 2 break statements and an else" {225test "while bool 2 break statements and an else" {
232 const S = struct {226 const S = struct {
233 fn entry(t: bool, f: bool) void {227 fn entry(t: bool, f: bool) !void {
234 var ok = false;228 var ok = false;
235 ok = while (t) {229 ok = while (t) {
236 if (f) break false;230 if (f) break false;
237 if (t) break true;231 if (t) break true;
238 } else false;232 } else false;
239 expect(ok);233 try expect(ok);
240 }234 }
241 };235 };
242 S.entry(true, false);236 try S.entry(true, false);
243 comptime S.entry(true, false);237 comptime try S.entry(true, false);
244}238}
245239
246test "while optional 2 break statements and an else" {240test "while optional 2 break statements and an else" {
247 const S = struct {241 const S = struct {
248 fn entry(opt_t: ?bool, f: bool) void {242 fn entry(opt_t: ?bool, f: bool) !void {
249 var ok = false;243 var ok = false;
250 ok = while (opt_t) |t| {244 ok = while (opt_t) |t| {
251 if (f) break false;245 if (f) break false;
252 if (t) break true;246 if (t) break true;
253 } else false;247 } else false;
254 expect(ok);248 try expect(ok);
255 }249 }
256 };250 };
257 S.entry(true, false);251 try S.entry(true, false);
258 comptime S.entry(true, false);252 comptime try S.entry(true, false);
259}253}
260254
261test "while error 2 break statements and an else" {255test "while error 2 break statements and an else" {
262 const S = struct {256 const S = struct {
263 fn entry(opt_t: anyerror!bool, f: bool) void {257 fn entry(opt_t: anyerror!bool, f: bool) !void {
264 var ok = false;258 var ok = false;
265 ok = while (opt_t) |t| {259 ok = while (opt_t) |t| {
266 if (f) break false;260 if (f) break false;
267 if (t) break true;261 if (t) break true;
268 } else |_| false;262 } else |_| false;
269 expect(ok);263 try expect(ok);
270 }264 }
271 };265 };
272 S.entry(true, false);266 try S.entry(true, false);
273 comptime S.entry(true, false);267 comptime try S.entry(true, false);
274}268}
275269
276test "while copies its payload" {270test "while copies its payload" {
277 const S = struct {271 const S = struct {
278 fn doTheTest() void {272 fn doTheTest() !void {
279 var tmp: ?i32 = 10;273 var tmp: ?i32 = 10;
280 while (tmp) |value| {274 while (tmp) |value| {
281 // Modify the original variable275 // Modify the original variable
282 tmp = null;276 tmp = null;
283 expect(value == 10);277 try expect(value == 10);
284 }278 }
285 }279 }
286 };280 };
287 S.doTheTest();281 try S.doTheTest();
288 comptime S.doTheTest();282 comptime try S.doTheTest();
289}283}
test/behavior/widening.zig+6-6
...@@ -9,13 +9,13 @@ test "integer widening" {...@@ -9,13 +9,13 @@ test "integer widening" {
9 var d: u64 = c;9 var d: u64 = c;
10 var e: u64 = d;10 var e: u64 = d;
11 var f: u128 = e;11 var f: u128 = e;
12 expect(f == a);12 try expect(f == a);
13}13}
1414
15test "implicit unsigned integer to signed integer" {15test "implicit unsigned integer to signed integer" {
16 var a: u8 = 250;16 var a: u8 = 250;
17 var b: i16 = a;17 var b: i16 = a;
18 expect(b == 250);18 try expect(b == 250);
19}19}
2020
21test "float widening" {21test "float widening" {
...@@ -23,9 +23,9 @@ test "float widening" {...@@ -23,9 +23,9 @@ test "float widening" {
23 var b: f32 = a;23 var b: f32 = a;
24 var c: f64 = b;24 var c: f64 = b;
25 var d: f128 = c;25 var d: f128 = c;
26 expect(a == b);26 try expect(a == b);
27 expect(b == c);27 try expect(b == c);
28 expect(c == d);28 try expect(c == d);
29}29}
3030
31test "float widening f16 to f128" {31test "float widening f16 to f128" {
...@@ -35,5 +35,5 @@ test "float widening f16 to f128" {...@@ -35,5 +35,5 @@ test "float widening f16 to f128" {
3535
36 var x: f16 = 12.34;36 var x: f16 = 12.34;
37 var y: f128 = x;37 var y: f128 = x;
38 expect(x == y);38 try expect(x == y);
39}39}
test/cli.zig+14-14
...@@ -29,7 +29,7 @@ pub fn main() !void {...@@ -29,7 +29,7 @@ pub fn main() !void {
2929
30 const dir_path = try fs.path.join(a, &[_][]const u8{ cache_root, "clitest" });30 const dir_path = try fs.path.join(a, &[_][]const u8{ cache_root, "clitest" });
31 defer fs.cwd().deleteTree(dir_path) catch {};31 defer fs.cwd().deleteTree(dir_path) catch {};
32 32
33 const TestFn = fn ([]const u8, []const u8) anyerror!void;33 const TestFn = fn ([]const u8, []const u8) anyerror!void;
34 const test_fns = [_]TestFn{34 const test_fns = [_]TestFn{
35 testZigInitLib,35 testZigInitLib,
...@@ -94,13 +94,13 @@ fn exec(cwd: []const u8, expect_0: bool, argv: []const []const u8) !ChildProcess...@@ -94,13 +94,13 @@ fn exec(cwd: []const u8, expect_0: bool, argv: []const []const u8) !ChildProcess
94fn testZigInitLib(zig_exe: []const u8, dir_path: []const u8) !void {94fn testZigInitLib(zig_exe: []const u8, dir_path: []const u8) !void {
95 _ = try exec(dir_path, true, &[_][]const u8{ zig_exe, "init-lib" });95 _ = try exec(dir_path, true, &[_][]const u8{ zig_exe, "init-lib" });
96 const test_result = try exec(dir_path, true, &[_][]const u8{ zig_exe, "build", "test" });96 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");
98}98}
9999
100fn testZigInitExe(zig_exe: []const u8, dir_path: []const u8) !void {100fn testZigInitExe(zig_exe: []const u8, dir_path: []const u8) !void {
101 _ = try exec(dir_path, true, &[_][]const u8{ zig_exe, "init-exe" });101 _ = try exec(dir_path, true, &[_][]const u8{ zig_exe, "init-exe" });
102 const run_result = try exec(dir_path, true, &[_][]const u8{ zig_exe, "build", "run" });102 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);
104}104}
105105
106fn testGodboltApi(zig_exe: []const u8, dir_path: []const u8) anyerror!void {106fn 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 {...@@ -136,9 +136,9 @@ fn testGodboltApi(zig_exe: []const u8, dir_path: []const u8) anyerror!void {
136 _ = try exec(dir_path, true, args.items);136 _ = try exec(dir_path, true, args.items);
137137
138 const out_asm = try std.fs.cwd().readFileAlloc(a, example_s_path, std.math.maxInt(usize));138 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);139 try testing.expect(std.mem.indexOf(u8, out_asm, "square:") != null);
140 testing.expect(std.mem.indexOf(u8, out_asm, "mov\teax, edi") != null);140 try 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);141 try testing.expect(std.mem.indexOf(u8, out_asm, "imul\teax, edi") != null);
142}142}
143143
144fn testMissingOutputPath(zig_exe: []const u8, dir_path: []const u8) !void {144fn 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 {...@@ -149,7 +149,7 @@ fn testMissingOutputPath(zig_exe: []const u8, dir_path: []const u8) !void {
149 const result = try exec(dir_path, false, &[_][]const u8{ zig_exe, "build-exe", source_path, output_arg });149 const result = try exec(dir_path, false, &[_][]const u8{ zig_exe, "build-exe", source_path, output_arg });
150 const s = std.fs.path.sep_str;150 const s = std.fs.path.sep_str;
151 const expected: []const u8 = "error: unable to open output directory 'does" ++ s ++ "not" ++ s ++ "exist': FileNotFound\n";151 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);
153}153}
154154
155fn testZigFmt(zig_exe: []const u8, dir_path: []const u8) !void {155fn 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 {...@@ -162,20 +162,20 @@ fn testZigFmt(zig_exe: []const u8, dir_path: []const u8) !void {
162162
163 const run_result1 = try exec(dir_path, true, &[_][]const u8{ zig_exe, "fmt", fmt1_zig_path });163 const run_result1 = try exec(dir_path, true, &[_][]const u8{ zig_exe, "fmt", fmt1_zig_path });
164 // stderr should be file path + \n164 // stderr should be file path + \n
165 testing.expect(std.mem.startsWith(u8, run_result1.stdout, fmt1_zig_path));165 try 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');166 try testing.expect(run_result1.stdout.len == fmt1_zig_path.len + 1 and run_result1.stdout[run_result1.stdout.len - 1] == '\n');
167167
168 const fmt2_zig_path = try fs.path.join(a, &[_][]const u8{ dir_path, "fmt2.zig" });168 const fmt2_zig_path = try fs.path.join(a, &[_][]const u8{ dir_path, "fmt2.zig" });
169 try fs.cwd().writeFile(fmt2_zig_path, unformatted_code);169 try fs.cwd().writeFile(fmt2_zig_path, unformatted_code);
170170
171 const run_result2 = try exec(dir_path, true, &[_][]const u8{ zig_exe, "fmt", dir_path });171 const run_result2 = try exec(dir_path, true, &[_][]const u8{ zig_exe, "fmt", dir_path });
172 // running it on the dir, only the new file should be changed172 // 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));173 try 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');174 try testing.expect(run_result2.stdout.len == fmt2_zig_path.len + 1 and run_result2.stdout[run_result2.stdout.len - 1] == '\n');
175175
176 const run_result3 = try exec(dir_path, true, &[_][]const u8{ zig_exe, "fmt", dir_path });176 const run_result3 = try exec(dir_path, true, &[_][]const u8{ zig_exe, "fmt", dir_path });
177 // both files have been formatted, nothing should change now177 // 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
180 // Check UTF-16 decoding180 // Check UTF-16 decoding
181 const fmt4_zig_path = try fs.path.join(a, &[_][]const u8{ dir_path, "fmt4.zig" });181 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 {...@@ -183,6 +183,6 @@ fn testZigFmt(zig_exe: []const u8, dir_path: []const u8) !void {
183 try fs.cwd().writeFile(fmt4_zig_path, unformatted_code_utf16);183 try fs.cwd().writeFile(fmt4_zig_path, unformatted_code_utf16);
184184
185 const run_result4 = try exec(dir_path, true, &[_][]const u8{ zig_exe, "fmt", dir_path });185 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));186 try 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');187 try testing.expect(run_result4.stdout.len == fmt4_zig_path.len + 1 and run_result4.stdout[run_result4.stdout.len - 1] == '\n');
188}188}
test/compile_errors.zig+1-1
...@@ -230,7 +230,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -230,7 +230,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
230230
231 cases.add("array in c exported function",231 cases.add("array in c exported function",
232 \\export fn zig_array(x: [10]u8) void {232 \\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"));
234 \\}234 \\}
235 \\235 \\
236 \\export fn zig_return_array() [10]u8 {236 \\export fn zig_return_array() [10]u8 {
test/stack_traces.zig+17-17
...@@ -5,13 +5,13 @@ const tests = @import("tests.zig");...@@ -5,13 +5,13 @@ const tests = @import("tests.zig");
5pub fn addCases(cases: *tests.StackTracesContext) void {5pub fn addCases(cases: *tests.StackTracesContext) void {
6 cases.addCase(.{6 cases.addCase(.{
7 .name = "return",7 .name = "return",
8 .source =8 .source =
9 \\pub fn main() !void {9 \\pub fn main() !void {
10 \\ return error.TheSkyIsFalling;10 \\ return error.TheSkyIsFalling;
11 \\}11 \\}
12 ,12 ,
13 .Debug = .{13 .Debug = .{
14 .expect =14 .expect =
15 \\error: TheSkyIsFalling15 \\error: TheSkyIsFalling
16 \\source.zig:2:5: [address] in main (test)16 \\source.zig:2:5: [address] in main (test)
17 \\ return error.TheSkyIsFalling;17 \\ return error.TheSkyIsFalling;
...@@ -23,7 +23,7 @@ pub fn addCases(cases: *tests.StackTracesContext) void {...@@ -23,7 +23,7 @@ pub fn addCases(cases: *tests.StackTracesContext) void {
23 .exclude_os = .{23 .exclude_os = .{
24 .windows, // segfault24 .windows, // segfault
25 },25 },
26 .expect =26 .expect =
27 \\error: TheSkyIsFalling27 \\error: TheSkyIsFalling
28 \\source.zig:2:5: [address] in [function]28 \\source.zig:2:5: [address] in [function]
29 \\ return error.TheSkyIsFalling;29 \\ return error.TheSkyIsFalling;
...@@ -32,13 +32,13 @@ pub fn addCases(cases: *tests.StackTracesContext) void {...@@ -32,13 +32,13 @@ pub fn addCases(cases: *tests.StackTracesContext) void {
32 ,32 ,
33 },33 },
34 .ReleaseFast = .{34 .ReleaseFast = .{
35 .expect =35 .expect =
36 \\error: TheSkyIsFalling36 \\error: TheSkyIsFalling
37 \\37 \\
38 ,38 ,
39 },39 },
40 .ReleaseSmall = .{40 .ReleaseSmall = .{
41 .expect =41 .expect =
42 \\error: TheSkyIsFalling42 \\error: TheSkyIsFalling
43 \\43 \\
44 ,44 ,
...@@ -47,7 +47,7 @@ pub fn addCases(cases: *tests.StackTracesContext) void {...@@ -47,7 +47,7 @@ pub fn addCases(cases: *tests.StackTracesContext) void {
4747
48 cases.addCase(.{48 cases.addCase(.{
49 .name = "try return",49 .name = "try return",
50 .source =50 .source =
51 \\fn foo() !void {51 \\fn foo() !void {
52 \\ return error.TheSkyIsFalling;52 \\ return error.TheSkyIsFalling;
53 \\}53 \\}
...@@ -57,7 +57,7 @@ pub fn addCases(cases: *tests.StackTracesContext) void {...@@ -57,7 +57,7 @@ pub fn addCases(cases: *tests.StackTracesContext) void {
57 \\}57 \\}
58 ,58 ,
59 .Debug = .{59 .Debug = .{
60 .expect =60 .expect =
61 \\error: TheSkyIsFalling61 \\error: TheSkyIsFalling
62 \\source.zig:2:5: [address] in foo (test)62 \\source.zig:2:5: [address] in foo (test)
63 \\ return error.TheSkyIsFalling;63 \\ return error.TheSkyIsFalling;
...@@ -72,7 +72,7 @@ pub fn addCases(cases: *tests.StackTracesContext) void {...@@ -72,7 +72,7 @@ pub fn addCases(cases: *tests.StackTracesContext) void {
72 .exclude_os = .{72 .exclude_os = .{
73 .windows, // segfault73 .windows, // segfault
74 },74 },
75 .expect =75 .expect =
76 \\error: TheSkyIsFalling76 \\error: TheSkyIsFalling
77 \\source.zig:2:5: [address] in [function]77 \\source.zig:2:5: [address] in [function]
78 \\ return error.TheSkyIsFalling;78 \\ return error.TheSkyIsFalling;
...@@ -84,13 +84,13 @@ pub fn addCases(cases: *tests.StackTracesContext) void {...@@ -84,13 +84,13 @@ pub fn addCases(cases: *tests.StackTracesContext) void {
84 ,84 ,
85 },85 },
86 .ReleaseFast = .{86 .ReleaseFast = .{
87 .expect =87 .expect =
88 \\error: TheSkyIsFalling88 \\error: TheSkyIsFalling
89 \\89 \\
90 ,90 ,
91 },91 },
92 .ReleaseSmall = .{92 .ReleaseSmall = .{
93 .expect =93 .expect =
94 \\error: TheSkyIsFalling94 \\error: TheSkyIsFalling
95 \\95 \\
96 ,96 ,
...@@ -99,7 +99,7 @@ pub fn addCases(cases: *tests.StackTracesContext) void {...@@ -99,7 +99,7 @@ pub fn addCases(cases: *tests.StackTracesContext) void {
9999
100 cases.addCase(.{100 cases.addCase(.{
101 .name = "try try return return",101 .name = "try try return return",
102 .source =102 .source =
103 \\fn foo() !void {103 \\fn foo() !void {
104 \\ try bar();104 \\ try bar();
105 \\}105 \\}
...@@ -117,7 +117,7 @@ pub fn addCases(cases: *tests.StackTracesContext) void {...@@ -117,7 +117,7 @@ pub fn addCases(cases: *tests.StackTracesContext) void {
117 \\}117 \\}
118 ,118 ,
119 .Debug = .{119 .Debug = .{
120 .expect =120 .expect =
121 \\error: TheSkyIsFalling121 \\error: TheSkyIsFalling
122 \\source.zig:10:5: [address] in make_error (test)122 \\source.zig:10:5: [address] in make_error (test)
123 \\ return error.TheSkyIsFalling;123 \\ return error.TheSkyIsFalling;
...@@ -138,7 +138,7 @@ pub fn addCases(cases: *tests.StackTracesContext) void {...@@ -138,7 +138,7 @@ pub fn addCases(cases: *tests.StackTracesContext) void {
138 .exclude_os = .{138 .exclude_os = .{
139 .windows, // segfault139 .windows, // segfault
140 },140 },
141 .expect =141 .expect =
142 \\error: TheSkyIsFalling142 \\error: TheSkyIsFalling
143 \\source.zig:10:5: [address] in [function]143 \\source.zig:10:5: [address] in [function]
144 \\ return error.TheSkyIsFalling;144 \\ return error.TheSkyIsFalling;
...@@ -156,13 +156,13 @@ pub fn addCases(cases: *tests.StackTracesContext) void {...@@ -156,13 +156,13 @@ pub fn addCases(cases: *tests.StackTracesContext) void {
156 ,156 ,
157 },157 },
158 .ReleaseFast = .{158 .ReleaseFast = .{
159 .expect =159 .expect =
160 \\error: TheSkyIsFalling160 \\error: TheSkyIsFalling
161 \\161 \\
162 ,162 ,
163 },163 },
164 .ReleaseSmall = .{164 .ReleaseSmall = .{
165 .expect =165 .expect =
166 \\error: TheSkyIsFalling166 \\error: TheSkyIsFalling
167 \\167 \\
168 ,168 ,
...@@ -174,7 +174,7 @@ pub fn addCases(cases: *tests.StackTracesContext) void {...@@ -174,7 +174,7 @@ pub fn addCases(cases: *tests.StackTracesContext) void {
174 .windows,174 .windows,
175 },175 },
176 .name = "dumpCurrentStackTrace",176 .name = "dumpCurrentStackTrace",
177 .source =177 .source =
178 \\const std = @import("std");178 \\const std = @import("std");
179 \\179 \\
180 \\fn bar() void {180 \\fn bar() void {
...@@ -189,7 +189,7 @@ pub fn addCases(cases: *tests.StackTracesContext) void {...@@ -189,7 +189,7 @@ pub fn addCases(cases: *tests.StackTracesContext) void {
189 \\}189 \\}
190 ,190 ,
191 .Debug = .{191 .Debug = .{
192 .expect =192 .expect =
193 \\source.zig:7:8: [address] in foo (test)193 \\source.zig:7:8: [address] in foo (test)
194 \\ bar();194 \\ bar();
195 \\ ^195 \\ ^
test/stage1/c_abi/main.zig+58-58
...@@ -24,11 +24,11 @@ extern fn c_i64(i64) void;...@@ -24,11 +24,11 @@ extern fn c_i64(i64) void;
24extern fn c_five_integers(i32, i32, i32, i32, i32) void;24extern fn c_five_integers(i32, i32, i32, i32, i32) void;
2525
26export fn zig_five_integers(a: i32, b: i32, c: i32, d: i32, e: i32) void {26export fn zig_five_integers(a: i32, b: i32, c: i32, d: i32, e: i32) void {
27 expect(a == 12);27 expect(a == 12) catch @panic("test failure");
28 expect(b == 34);28 expect(b == 34) catch @panic("test failure");
29 expect(c == 56);29 expect(c == 56) catch @panic("test failure");
30 expect(d == 78);30 expect(d == 78) catch @panic("test failure");
31 expect(e == 90);31 expect(e == 90) catch @panic("test failure");
32}32}
3333
34test "C ABI integers" {34test "C ABI integers" {
...@@ -45,28 +45,28 @@ test "C ABI integers" {...@@ -45,28 +45,28 @@ test "C ABI integers" {
45}45}
4646
47export fn zig_u8(x: u8) void {47export fn zig_u8(x: u8) void {
48 expect(x == 0xff);48 expect(x == 0xff) catch @panic("test failure");
49}49}
50export fn zig_u16(x: u16) void {50export fn zig_u16(x: u16) void {
51 expect(x == 0xfffe);51 expect(x == 0xfffe) catch @panic("test failure");
52}52}
53export fn zig_u32(x: u32) void {53export fn zig_u32(x: u32) void {
54 expect(x == 0xfffffffd);54 expect(x == 0xfffffffd) catch @panic("test failure");
55}55}
56export fn zig_u64(x: u64) void {56export fn zig_u64(x: u64) void {
57 expect(x == 0xfffffffffffffffc);57 expect(x == 0xfffffffffffffffc) catch @panic("test failure");
58}58}
59export fn zig_i8(x: i8) void {59export fn zig_i8(x: i8) void {
60 expect(x == -1);60 expect(x == -1) catch @panic("test failure");
61}61}
62export fn zig_i16(x: i16) void {62export fn zig_i16(x: i16) void {
63 expect(x == -2);63 expect(x == -2) catch @panic("test failure");
64}64}
65export fn zig_i32(x: i32) void {65export fn zig_i32(x: i32) void {
66 expect(x == -3);66 expect(x == -3) catch @panic("test failure");
67}67}
68export fn zig_i64(x: i64) void {68export fn zig_i64(x: i64) void {
69 expect(x == -4);69 expect(x == -4) catch @panic("test failure");
70}70}
7171
72extern fn c_f32(f32) void;72extern fn c_f32(f32) void;
...@@ -76,11 +76,11 @@ extern fn c_f64(f64) void;...@@ -76,11 +76,11 @@ extern fn c_f64(f64) void;
76extern fn c_five_floats(f32, f32, f32, f32, f32) void;76extern fn c_five_floats(f32, f32, f32, f32, f32) void;
7777
78export fn zig_five_floats(a: f32, b: f32, c: f32, d: f32, e: f32) void {78export fn zig_five_floats(a: f32, b: f32, c: f32, d: f32, e: f32) void {
79 expect(a == 1.0);79 expect(a == 1.0) catch @panic("test failure");
80 expect(b == 2.0);80 expect(b == 2.0) catch @panic("test failure");
81 expect(c == 3.0);81 expect(c == 3.0) catch @panic("test failure");
82 expect(d == 4.0);82 expect(d == 4.0) catch @panic("test failure");
83 expect(e == 5.0);83 expect(e == 5.0) catch @panic("test failure");
84}84}
8585
86test "C ABI floats" {86test "C ABI floats" {
...@@ -90,10 +90,10 @@ test "C ABI floats" {...@@ -90,10 +90,10 @@ test "C ABI floats" {
90}90}
9191
92export fn zig_f32(x: f32) void {92export fn zig_f32(x: f32) void {
93 expect(x == 12.34);93 expect(x == 12.34) catch @panic("test failure");
94}94}
95export fn zig_f64(x: f64) void {95export fn zig_f64(x: f64) void {
96 expect(x == 56.78);96 expect(x == 56.78) catch @panic("test failure");
97}97}
9898
99extern fn c_ptr(*c_void) void;99extern fn c_ptr(*c_void) void;
...@@ -103,7 +103,7 @@ test "C ABI pointer" {...@@ -103,7 +103,7 @@ test "C ABI pointer" {
103}103}
104104
105export fn zig_ptr(x: *c_void) void {105export fn zig_ptr(x: *c_void) void {
106 expect(@ptrToInt(x) == 0xdeadbeef);106 expect(@ptrToInt(x) == 0xdeadbeef) catch @panic("test failure");
107}107}
108108
109extern fn c_bool(bool) void;109extern fn c_bool(bool) void;
...@@ -113,7 +113,7 @@ test "C ABI bool" {...@@ -113,7 +113,7 @@ test "C ABI bool" {
113}113}
114114
115export fn zig_bool(x: bool) void {115export fn zig_bool(x: bool) void {
116 expect(x);116 expect(x) catch @panic("test failure");
117}117}
118118
119const BigStruct = extern struct {119const BigStruct = extern struct {
...@@ -137,11 +137,11 @@ test "C ABI big struct" {...@@ -137,11 +137,11 @@ test "C ABI big struct" {
137}137}
138138
139export fn zig_big_struct(x: BigStruct) void {139export fn zig_big_struct(x: BigStruct) void {
140 expect(x.a == 1);140 expect(x.a == 1) catch @panic("test failure");
141 expect(x.b == 2);141 expect(x.b == 2) catch @panic("test failure");
142 expect(x.c == 3);142 expect(x.c == 3) catch @panic("test failure");
143 expect(x.d == 4);143 expect(x.d == 4) catch @panic("test failure");
144 expect(x.e == 5);144 expect(x.e == 5) catch @panic("test failure");
145}145}
146146
147const BigUnion = extern union {147const BigUnion = extern union {
...@@ -163,11 +163,11 @@ test "C ABI big union" {...@@ -163,11 +163,11 @@ test "C ABI big union" {
163}163}
164164
165export fn zig_big_union(x: BigUnion) void {165export fn zig_big_union(x: BigUnion) void {
166 expect(x.a.a == 1);166 expect(x.a.a == 1) catch @panic("test failure");
167 expect(x.a.b == 2);167 expect(x.a.b == 2) catch @panic("test failure");
168 expect(x.a.c == 3);168 expect(x.a.c == 3) catch @panic("test failure");
169 expect(x.a.d == 4);169 expect(x.a.d == 4) catch @panic("test failure");
170 expect(x.a.e == 5);170 expect(x.a.e == 5) catch @panic("test failure");
171}171}
172172
173const SmallStructInts = extern struct {173const SmallStructInts = extern struct {
...@@ -189,10 +189,10 @@ test "C ABI small struct of ints" {...@@ -189,10 +189,10 @@ test "C ABI small struct of ints" {
189}189}
190190
191export fn zig_small_struct_ints(x: SmallStructInts) void {191export fn zig_small_struct_ints(x: SmallStructInts) void {
192 expect(x.a == 1);192 expect(x.a == 1) catch @panic("test failure");
193 expect(x.b == 2);193 expect(x.b == 2) catch @panic("test failure");
194 expect(x.c == 3);194 expect(x.c == 3) catch @panic("test failure");
195 expect(x.d == 4);195 expect(x.d == 4) catch @panic("test failure");
196}196}
197197
198const SplitStructInt = extern struct {198const SplitStructInt = extern struct {
...@@ -212,9 +212,9 @@ test "C ABI split struct of ints" {...@@ -212,9 +212,9 @@ test "C ABI split struct of ints" {
212}212}
213213
214export fn zig_split_struct_ints(x: SplitStructInt) void {214export fn zig_split_struct_ints(x: SplitStructInt) void {
215 expect(x.a == 1234);215 expect(x.a == 1234) catch @panic("test failure");
216 expect(x.b == 100);216 expect(x.b == 100) catch @panic("test failure");
217 expect(x.c == 1337);217 expect(x.c == 1337) catch @panic("test failure");
218}218}
219219
220extern fn c_big_struct_both(BigStruct) BigStruct;220extern fn c_big_struct_both(BigStruct) BigStruct;
...@@ -228,19 +228,19 @@ test "C ABI sret and byval together" {...@@ -228,19 +228,19 @@ test "C ABI sret and byval together" {
228 .e = 5,228 .e = 5,
229 };229 };
230 var y = c_big_struct_both(s);230 var y = c_big_struct_both(s);
231 expect(y.a == 10);231 try expect(y.a == 10);
232 expect(y.b == 11);232 try expect(y.b == 11);
233 expect(y.c == 12);233 try expect(y.c == 12);
234 expect(y.d == 13);234 try expect(y.d == 13);
235 expect(y.e == 14);235 try expect(y.e == 14);
236}236}
237237
238export fn zig_big_struct_both(x: BigStruct) BigStruct {238export fn zig_big_struct_both(x: BigStruct) BigStruct {
239 expect(x.a == 30);239 expect(x.a == 30) catch @panic("test failure");
240 expect(x.b == 31);240 expect(x.b == 31) catch @panic("test failure");
241 expect(x.c == 32);241 expect(x.c == 32) catch @panic("test failure");
242 expect(x.d == 33);242 expect(x.d == 33) catch @panic("test failure");
243 expect(x.e == 34);243 expect(x.e == 34) catch @panic("test failure");
244 var s = BigStruct{244 var s = BigStruct{
245 .a = 20,245 .a = 20,
246 .b = 21,246 .b = 21,
...@@ -324,15 +324,15 @@ extern fn c_ret_i32() i32;...@@ -324,15 +324,15 @@ extern fn c_ret_i32() i32;
324extern fn c_ret_i64() i64;324extern fn c_ret_i64() i64;
325325
326test "C ABI integer return types" {326test "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);329 try expect(c_ret_u8() == 0xff);
330 expect(c_ret_u16() == 0xffff);330 try expect(c_ret_u16() == 0xffff);
331 expect(c_ret_u32() == 0xffffffff);331 try expect(c_ret_u32() == 0xffffffff);
332 expect(c_ret_u64() == 0xffffffffffffffff);332 try expect(c_ret_u64() == 0xffffffffffffffff);
333333
334 expect(c_ret_i8() == -1);334 try expect(c_ret_i8() == -1);
335 expect(c_ret_i16() == -1);335 try expect(c_ret_i16() == -1);
336 expect(c_ret_i32() == -1);336 try expect(c_ret_i32() == -1);
337 expect(c_ret_i64() == -1);337 try expect(c_ret_i64() == -1);
338}338}
test/standalone/brace_expansion/main.zig+31-31
...@@ -241,52 +241,52 @@ pub fn main() !void {...@@ -241,52 +241,52 @@ pub fn main() !void {
241test "invalid inputs" {241test "invalid inputs" {
242 global_allocator = std.testing.allocator;242 global_allocator = std.testing.allocator;
243243
244 expectError("}ABC", error.InvalidInput);244 try expectError("}ABC", error.InvalidInput);
245 expectError("{ABC", error.InvalidInput);245 try expectError("{ABC", error.InvalidInput);
246 expectError("}{", error.InvalidInput);246 try expectError("}{", error.InvalidInput);
247 expectError("{}", error.InvalidInput);247 try expectError("{}", error.InvalidInput);
248 expectError("A,B,C", error.InvalidInput);248 try expectError("A,B,C", error.InvalidInput);
249 expectError("{A{B,C}", error.InvalidInput);249 try expectError("{A{B,C}", error.InvalidInput);
250 expectError("{A,}", error.InvalidInput);250 try expectError("{A,}", error.InvalidInput);
251251
252 expectError("\n", error.InvalidInput);252 try expectError("\n", error.InvalidInput);
253}253}
254254
255fn expectError(test_input: []const u8, expected_err: anyerror) void {255fn expectError(test_input: []const u8, expected_err: anyerror) !void {
256 var output_buf = ArrayList(u8).init(global_allocator);256 var output_buf = ArrayList(u8).init(global_allocator);
257 defer output_buf.deinit();257 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));
260}260}
261261
262test "valid inputs" {262test "valid inputs" {
263 global_allocator = std.testing.allocator;263 global_allocator = std.testing.allocator;
264264
265 expectExpansion("{x,y,z}", "x y z");265 try expectExpansion("{x,y,z}", "x y z");
266 expectExpansion("{A,B}{x,y}", "Ax Ay Bx By");266 try expectExpansion("{A,B}{x,y}", "Ax Ay Bx By");
267 expectExpansion("{A,B{x,y}}", "A Bx By");267 try expectExpansion("{A,B{x,y}}", "A Bx By");
268268
269 expectExpansion("{ABC}", "ABC");269 try expectExpansion("{ABC}", "ABC");
270 expectExpansion("{A,B,C}", "A B C");270 try expectExpansion("{A,B,C}", "A B C");
271 expectExpansion("ABC", "ABC");271 try expectExpansion("ABC", "ABC");
272272
273 expectExpansion("", "");273 try expectExpansion("", "");
274 expectExpansion("{A,B}{C,{x,y}}{g,h}", "ACg ACh Axg Axh Ayg Ayh BCg BCh Bxg Bxh Byg Byh");274 try 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");275 try 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");276 try expectExpansion("{A,B}a", "Aa Ba");
277 expectExpansion("{C,{x,y}}", "C x y");277 try expectExpansion("{C,{x,y}}", "C x y");
278 expectExpansion("z{C,{x,y}}", "zC zx zy");278 try expectExpansion("z{C,{x,y}}", "zC zx zy");
279 expectExpansion("a{b,c{d,e{f,g}}}", "ab acd acef aceg");279 try expectExpansion("a{b,c{d,e{f,g}}}", "ab acd acef aceg");
280 expectExpansion("a{x,y}b", "axb ayb");280 try expectExpansion("a{x,y}b", "axb ayb");
281 expectExpansion("z{{a,b}}", "za zb");281 try expectExpansion("z{{a,b}}", "za zb");
282 expectExpansion("a{b}", "ab");282 try expectExpansion("a{b}", "ab");
283}283}
284284
285fn expectExpansion(test_input: []const u8, expected_result: []const u8) void {285fn expectExpansion(test_input: []const u8, expected_result: []const u8) !void {
286 var result = ArrayList(u8).init(global_allocator);286 var result = ArrayList(u8).init(global_allocator);
287 defer result.deinit();287 defer result.deinit();
288288
289 expandString(test_input, &result) catch unreachable;289 expandString(test_input, &result) catch unreachable;
290290
291 testing.expectEqualSlices(u8, expected_result, result.items);291 try testing.expectEqualSlices(u8, expected_result, result.items);
292}292}
test/standalone/empty_env/main.zig+2-2
...@@ -1,6 +1,6 @@...@@ -1,6 +1,6 @@
1const std = @import("std");1const std = @import("std");
22
3pub fn main() void {3pub fn main() !void {
4 const env_map = std.process.getEnvMap(std.testing.allocator) catch @panic("unable to get env map");4 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);
6}6}
test/standalone/global_linkage/main.zig+2-2
...@@ -4,6 +4,6 @@ extern var obj1_integer: usize;...@@ -4,6 +4,6 @@ extern var obj1_integer: usize;
4extern var obj2_integer: usize;4extern var obj2_integer: usize;
55
6test "access the external integers" {6test "access the external integers" {
7 std.testing.expect(obj1_integer == 421);7 try std.testing.expect(obj1_integer == 421);
8 std.testing.expect(obj2_integer == 422);8 try std.testing.expect(obj2_integer == 422);
9}9}
test/standalone/issue_794/main.zig+1-1
...@@ -3,5 +3,5 @@ const std = @import("std");...@@ -3,5 +3,5 @@ const std = @import("std");
3const testing = std.testing;3const testing = std.testing;
44
5test "c import" {5test "c import" {
6 comptime testing.expect(c.NUMBER == 1234);6 comptime try testing.expect(c.NUMBER == 1234);
7}7}
test/standalone/link_interdependent_static_c_libs/main.zig+1-1
...@@ -4,5 +4,5 @@ const c = @cImport(@cInclude("b.h"));...@@ -4,5 +4,5 @@ const c = @cImport(@cInclude("b.h"));
44
5test "import C sub" {5test "import C sub" {
6 const result = c.sub(2, 1);6 const result = c.sub(2, 1);
7 expect(result == 1);7 try expect(result == 1);
8}8}
test/standalone/static_c_lib/foo.zig+2-2
...@@ -4,9 +4,9 @@ const c = @cImport(@cInclude("foo.h"));...@@ -4,9 +4,9 @@ const c = @cImport(@cInclude("foo.h"));
44
5test "C add" {5test "C add" {
6 const result = c.add(1, 2);6 const result = c.add(1, 2);
7 expect(result == 3);7 try expect(result == 3);
8}8}
99
10test "C extern variable" {10test "C extern variable" {
11 expect(c.foo == 12345);11 try expect(c.foo == 12345);
12}12}
test/standalone/use_alias/main.zig+1-1
...@@ -6,5 +6,5 @@ test "symbol exists" {...@@ -6,5 +6,5 @@ test "symbol exists" {
6 .a = 1,6 .a = 1,
7 .b = 1,7 .b = 1,
8 };8 };
9 expect(foo.a + foo.b == 2);9 try expect(foo.a + foo.b == 2);
10}10}